[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-notifications/ -> bp-notifications-template.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Notifications Template Functions.
   4   *
   5   * @package BuddyPress
   6   * @subpackage TonificationsTemplate
   7   * @since 1.9.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Output the notifications component slug.
  15   *
  16   * @since 1.9.0
  17   */
  18  function bp_notifications_slug() {
  19      echo bp_get_notifications_slug();
  20  }
  21      /**
  22       * Return the notifications component slug.
  23       *
  24       * @since 1.9.0
  25       *
  26       * @return string Slug of the Notifications component.
  27       */
  28  	function bp_get_notifications_slug() {
  29  
  30          /**
  31           * Filters the notifications component slug.
  32           *
  33           * @since 1.9.0
  34           *
  35           * @param string $slug Notifications component slug.
  36           */
  37          return apply_filters( 'bp_get_notifications_slug', buddypress()->notifications->slug );
  38      }
  39  
  40  /**
  41   * Output the notifications permalink for a user.
  42   *
  43   * @since 1.9.0
  44   * @since 2.6.0 Added $user_id as a parameter.
  45   *
  46   * @param int $user_id The user ID.
  47   */
  48  function bp_notifications_permalink( $user_id = 0 ) {
  49      echo bp_get_notifications_permalink( $user_id );
  50  }
  51      /**
  52       * Return the notifications permalink.
  53       *
  54       * @since 1.9.0
  55       * @since 2.6.0 Added $user_id as a parameter.
  56       *
  57       * @param int $user_id The user ID.
  58       * @return string Notifications permalink.
  59       */
  60  	function bp_get_notifications_permalink( $user_id = 0 ) {
  61          if ( 0 === $user_id ) {
  62              $user_id = bp_loggedin_user_id();
  63              $domain  = bp_loggedin_user_domain();
  64          } else {
  65              $domain = bp_core_get_user_domain( (int) $user_id );
  66          }
  67  
  68          $retval = trailingslashit( $domain . bp_get_notifications_slug() );
  69  
  70          /**
  71           * Filters the notifications permalink.
  72           *
  73           * @since 1.9.0
  74           * @since 2.6.0 Added $user_id as a parameter.
  75           *
  76           * @param string $retval  Permalink for the notifications.
  77           * @param int    $user_id The user ID.
  78           */
  79          return apply_filters( 'bp_get_notifications_permalink', $retval, $user_id );
  80      }
  81  
  82  /**
  83   * Output the unread notifications permalink for a user.
  84   *
  85   * @since 1.9.0
  86   * @since 2.6.0 Added $user_id as a parameter.
  87   *
  88   * @param int $user_id The user ID.
  89   */
  90  function bp_notifications_unread_permalink( $user_id = 0 ) {
  91      echo bp_get_notifications_unread_permalink( $user_id );
  92  }
  93      /**
  94       * Return the unread notifications permalink.
  95       *
  96       * @since 2.6.0 Added $user_id as a parameter.
  97       *
  98       * @param int $user_id The user ID.
  99       * @return string Unread notifications permalink.
 100       */
 101  	function bp_get_notifications_unread_permalink( $user_id = 0 ) {
 102          if ( 0 === $user_id ) {
 103              $user_id = bp_loggedin_user_id();
 104              $domain  = bp_loggedin_user_domain();
 105          } else {
 106              $domain = bp_core_get_user_domain( (int) $user_id );
 107          }
 108  
 109          $retval = trailingslashit( $domain . bp_get_notifications_slug() . '/unread' );
 110  
 111          /**
 112           * Filters the unread notifications permalink.
 113           *
 114           * @since 1.9.0
 115           * @since 2.6.0 Added $user_id as a parameter.
 116           *
 117           * @param string $retval  Permalink for the unread notifications.
 118           * @param int    $user_id The user ID.
 119           */
 120          return apply_filters( 'bp_get_notifications_unread_permalink', $retval, $user_id );
 121      }
 122  
 123  /**
 124   * Output the read notifications permalink for a user.
 125   *
 126   * @since 1.9.0
 127   * @since 2.6.0 Added $user_id as a parameter.
 128   *
 129   * @param int $user_id The user ID.
 130   */
 131  function bp_notifications_read_permalink( $user_id = 0 ) {
 132      echo bp_get_notifications_read_permalink( $user_id );
 133  }
 134      /**
 135       * Return the read notifications permalink.
 136       *
 137       * @since 1.9.0
 138       *
 139       * @return string Read notifications permalink.
 140       */
 141  	function bp_get_notifications_read_permalink( $user_id = 0 ) {
 142          if ( 0 === $user_id ) {
 143              $user_id = bp_loggedin_user_id();
 144              $domain  = bp_loggedin_user_domain();
 145          } else {
 146              $domain = bp_core_get_user_domain( (int) $user_id );
 147          }
 148  
 149          $retval = trailingslashit( $domain . bp_get_notifications_slug() . '/read' );
 150  
 151          /**
 152           * Filters the read notifications permalink.
 153           *
 154           * @since 1.9.0
 155           * @since 2.6.0 Added $user_id as a parameter.
 156           *
 157           * @param string $retval  Permalink for the read notifications.
 158           * @param int    $user_id The user ID.
 159           */
 160          return apply_filters( 'bp_get_notifications_unread_permalink', $retval, $user_id );
 161      }
 162  
 163  /** The Loop ******************************************************************/
 164  
 165  /**
 166   * Initialize the notifications loop.
 167   *
 168   * Based on the $args passed, bp_has_notifications() populates
 169   * buddypress()->notifications->query_loop global, enabling the use of BP
 170   * templates and template functions to display a list of notifications.
 171   *
 172   * @since 1.9.0
 173   *
 174   * @param array|string $args {
 175   *     Arguments for limiting the contents of the notifications loop. Can be
 176   *     passed as an associative array, or as a URL query string.
 177   *
 178   *     See {@link BP_Notifications_Notification::get()} for detailed
 179   *     information on the arguments.  In addition, also supports:
 180   *
 181   *     @type int    $max      Optional. Max items to display. Default: false.
 182   *     @type string $page_arg URL argument to use for pagination.
 183   *                            Default: 'npage'.
 184   * }
 185   * @return bool
 186   */
 187  function bp_has_notifications( $args = '' ) {
 188  
 189      // Get the default is_new argument.
 190      if ( bp_is_current_action( 'unread' ) ) {
 191          $is_new = 1;
 192      } elseif ( bp_is_current_action( 'read' ) ) {
 193          $is_new = 0;
 194  
 195      // Not on a notifications page? default to fetch new notifications.
 196      } else {
 197          $is_new = 1;
 198      }
 199  
 200      // Get the user ID.
 201      if ( bp_displayed_user_id() ) {
 202          $user_id = bp_displayed_user_id();
 203      } else {
 204          $user_id = bp_loggedin_user_id();
 205      }
 206  
 207      // Set the component action (by default false to get all actions)
 208      $component_action = false;
 209  
 210      if ( isset( $_REQUEST['type'] ) ) {
 211          $component_action = sanitize_key( $_REQUEST['type'] );
 212      }
 213  
 214      // Set the search terms (by default an empty string to get all notifications)
 215      $search_terms = '';
 216  
 217      if ( isset( $_REQUEST['s'] ) ) {
 218          $search_terms = stripslashes( $_REQUEST['s'] );
 219      }
 220  
 221      // Parse the args.
 222      $r = bp_parse_args( $args, array(
 223          'id'                => false,
 224          'user_id'           => $user_id,
 225          'secondary_item_id' => false,
 226          'component_name'    => bp_notifications_get_registered_components(),
 227          'component_action'  => $component_action,
 228          'is_new'            => $is_new,
 229          'search_terms'      => $search_terms,
 230          'order_by'          => 'date_notified',
 231          'sort_order'        => 'DESC',
 232          'meta_query'        => false,
 233          'date_query'        => false,
 234          'page'              => 1,
 235          'per_page'          => 25,
 236  
 237          // These are additional arguments that are not available in
 238          // BP_Notifications_Notification::get().
 239          'max'               => false,
 240          'page_arg'          => 'npage',
 241      ), 'has_notifications' );
 242  
 243      // Get the notifications.
 244      $query_loop = new BP_Notifications_Template( $r );
 245  
 246      // Setup the global query loop.
 247      buddypress()->notifications->query_loop = $query_loop;
 248  
 249      /**
 250       * Filters whether or not the user has notifications to display.
 251       *
 252       * @since 1.9.0
 253       * @since 2.6.0 Added the `$r` parameter.
 254       *
 255       * @param bool                      $value      Whether or not there are notifications to display.
 256       * @param BP_Notifications_Template $query_loop BP_Notifications_Template object instance.
 257       * @param array                     $r          Array of arguments passed into the BP_Notifications_Template class.
 258       */
 259      return apply_filters( 'bp_has_notifications', $query_loop->has_notifications(), $query_loop, $r );
 260  }
 261  
 262  /**
 263   * Get the notifications returned by the template loop.
 264   *
 265   * @since 1.9.0
 266   *
 267   * @return array List of notifications.
 268   */
 269  function bp_the_notifications() {
 270      return buddypress()->notifications->query_loop->notifications();
 271  }
 272  
 273  /**
 274   * Get the current notification object in the loop.
 275   *
 276   * @since 1.9.0
 277   *
 278   * @return object The current notification within the loop.
 279   */
 280  function bp_the_notification() {
 281      return buddypress()->notifications->query_loop->the_notification();
 282  }
 283  
 284  /** Loop Output ***************************************************************/
 285  
 286  /**
 287   * Output the ID of the notification currently being iterated on.
 288   *
 289   * @since 1.9.0
 290   */
 291  function bp_the_notification_id() {
 292      echo bp_get_the_notification_id();
 293  }
 294      /**
 295       * Return the ID of the notification currently being iterated on.
 296       *
 297       * @since 1.9.0
 298       *
 299       * @return int ID of the current notification.
 300       */
 301  	function bp_get_the_notification_id() {
 302  
 303          /**
 304           * Filters the ID of the notification currently being iterated on.
 305           *
 306           * @since 1.9.0
 307           *
 308           * @param int $id ID of the notification being iterated on.
 309           */
 310          return apply_filters( 'bp_get_the_notification_id', buddypress()->notifications->query_loop->notification->id );
 311      }
 312  
 313  /**
 314   * Output the associated item ID of the notification currently being iterated on.
 315   *
 316   * @since 1.9.0
 317   */
 318  function bp_the_notification_item_id() {
 319      echo bp_get_the_notification_item_id();
 320  }
 321      /**
 322       * Return the associated item ID of the notification currently being iterated on.
 323       *
 324       * @since 1.9.0
 325       *
 326       * @return int ID of the item associated with the current notification.
 327       */
 328  	function bp_get_the_notification_item_id() {
 329  
 330          /**
 331           * Filters the associated item ID of the notification currently being iterated on.
 332           *
 333           * @since 1.9.0
 334           *
 335           * @param int $item_id ID of the associated item.
 336           */
 337          return apply_filters( 'bp_get_the_notification_item_id', buddypress()->notifications->query_loop->notification->item_id );
 338      }
 339  
 340  /**
 341   * Output the secondary associated item ID of the notification currently being iterated on.
 342   *
 343   * @since 1.9.0
 344   */
 345  function bp_the_notification_secondary_item_id() {
 346      echo bp_get_the_notification_secondary_item_id();
 347  }
 348      /**
 349       * Return the secondary associated item ID of the notification currently being iterated on.
 350       *
 351       * @since 1.9.0
 352       *
 353       * @return int ID of the secondary item associated with the current notification.
 354       */
 355  	function bp_get_the_notification_secondary_item_id() {
 356  
 357          /**
 358           * Filters the secondary associated item ID of the notification currently being iterated on.
 359           *
 360           * @since 1.9.0
 361           *
 362           * @param int $secondary_item_id ID of the secondary associated item.
 363           */
 364          return apply_filters( 'bp_get_the_notification_secondary_item_id', buddypress()->notifications->query_loop->notification->secondary_item_id );
 365      }
 366  
 367  /**
 368   * Output the name of the component associated with the notification currently being iterated on.
 369   *
 370   * @since 1.9.0
 371   */
 372  function bp_the_notification_component_name() {
 373      echo bp_get_the_notification_component_name();
 374  }
 375      /**
 376       * Return the name of the component associated with the notification currently being iterated on.
 377       *
 378       * @since 1.9.0
 379       *
 380       * @return int Name of the component associated with the current notification.
 381       */
 382  	function bp_get_the_notification_component_name() {
 383  
 384          /**
 385           * Filters the name of the component associated with the notification currently being iterated on.
 386           *
 387           * @since 1.9.0
 388           *
 389           * @param int $component_name Name of the component associated with the current notification.
 390           */
 391          return apply_filters( 'bp_get_the_notification_component_name', buddypress()->notifications->query_loop->notification->component_name );
 392      }
 393  
 394  /**
 395   * Output the name of the action associated with the notification currently being iterated on.
 396   *
 397   * @since 1.9.0
 398   */
 399  function bp_the_notification_component_action() {
 400      echo bp_get_the_notification_component_action();
 401  }
 402      /**
 403       * Return the name of the action associated with the notification currently being iterated on.
 404       *
 405       * @since 1.9.0
 406       *
 407       * @return int Name of the action associated with the current notification.
 408       */
 409  	function bp_get_the_notification_component_action() {
 410  
 411          /**
 412           * Filters the name of the action associated with the notification currently being iterated on.
 413           *
 414           * @since 1.9.0
 415           *
 416           * @param int $component_action Name of the action associated with the current notification.
 417           */
 418          return apply_filters( 'bp_get_the_notification_component_action', buddypress()->notifications->query_loop->notification->component_action );
 419      }
 420  
 421  /**
 422   * Output the timestamp of the current notification.
 423   *
 424   * @since 1.9.0
 425   */
 426  function bp_the_notification_date_notified() {
 427      echo bp_get_the_notification_date_notified();
 428  }
 429      /**
 430       * Return the timestamp of the current notification.
 431       *
 432       * @since 1.9.0
 433       *
 434       * @return string Timestamp of the current notification.
 435       */
 436  	function bp_get_the_notification_date_notified() {
 437  
 438          /**
 439           * Filters the timestamp of the current notification.
 440           *
 441           * @since 1.9.0
 442           *
 443           * @param string $date_notified Timestamp of the current notification.
 444           */
 445          return apply_filters( 'bp_get_the_notification_date_notified', buddypress()->notifications->query_loop->notification->date_notified );
 446      }
 447  
 448  /**
 449   * Output the timestamp of the current notification.
 450   *
 451   * @since 1.9.0
 452   */
 453  function bp_the_notification_time_since() {
 454      echo bp_get_the_notification_time_since();
 455  }
 456      /**
 457       * Return the timestamp of the current notification.
 458       *
 459       * @since 1.9.0
 460       *
 461       * @return string Timestamp of the current notification.
 462       */
 463  	function bp_get_the_notification_time_since() {
 464  
 465          // Get the notified date.
 466          $date_notified = bp_get_the_notification_date_notified();
 467  
 468          // Notified date has legitimate data.
 469          if ( '0000-00-00 00:00:00' !== $date_notified ) {
 470              $retval = bp_core_time_since( $date_notified );
 471  
 472          // Notified date is empty, so return a fun string.
 473          } else {
 474              $retval = __( 'Date not found', 'buddypress' );
 475          }
 476  
 477          /**
 478           * Filters the time since value of the current notification.
 479           *
 480           * @since 1.9.0
 481           *
 482           * @param string $retval Time since value for current notification.
 483           */
 484          return apply_filters( 'bp_get_the_notification_time_since', $retval );
 485      }
 486  
 487  /**
 488   * Output full-text description for a specific notification.
 489   *
 490   * @since 1.9.0
 491   */
 492  function bp_the_notification_description() {
 493      echo bp_get_the_notification_description();
 494  }
 495  
 496      /**
 497       * Get full-text description for a specific notification.
 498       *
 499       * @since 1.9.0
 500       *
 501       * @return string
 502       */
 503  	function bp_get_the_notification_description() {
 504          $bp           = buddypress();
 505          $notification = $bp->notifications->query_loop->notification;
 506  
 507          // Callback function exists.
 508          if ( isset( $bp->{ $notification->component_name }->notification_callback ) && is_callable( $bp->{ $notification->component_name }->notification_callback ) ) {
 509              $description = call_user_func( $bp->{ $notification->component_name }->notification_callback, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->id );
 510  
 511          // @deprecated format_notification_function - 1.5
 512          } elseif ( isset( $bp->{ $notification->component_name }->format_notification_function ) && function_exists( $bp->{ $notification->component_name }->format_notification_function ) ) {
 513              $description = call_user_func( $bp->{ $notification->component_name }->format_notification_function, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 );
 514  
 515          // Allow non BuddyPress components to hook in.
 516          } else {
 517  
 518              /** This filter is documented in bp-notifications/bp-notifications-functions.php */
 519              $description = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', array( $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->component_action, $notification->component_name, $notification->id ) );
 520          }
 521  
 522          /**
 523           * Filters the full-text description for a specific notification.
 524           *
 525           * @since 1.9.0
 526           * @since 2.3.0 Added the `$notification` parameter.
 527           *
 528           * @param string $description  Full-text description for a specific notification.
 529           * @param object $notification Notification object.
 530           */
 531          return apply_filters( 'bp_get_the_notification_description', $description, $notification );
 532      }
 533  
 534  /**
 535   * Output the mark read link for the current notification.
 536   *
 537   * @since 1.9.0
 538   * @since 2.6.0 Added $user_id as a parameter.
 539   *
 540   * @param int $user_id The user ID.
 541   */
 542  function bp_the_notification_mark_read_link( $user_id = 0 ) {
 543      echo bp_get_the_notification_mark_read_link( $user_id );
 544  }
 545      /**
 546       * Return the mark read link for the current notification.
 547       *
 548       * @since 1.9.0
 549       * @since 2.6.0 Added $user_id as a parameter.
 550       *
 551       * @param int $user_id The user ID.
 552       * @return string
 553       */
 554  	function bp_get_the_notification_mark_read_link( $user_id = 0 ) {
 555          // Set default user ID to use.
 556          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 557  
 558          $retval = sprintf( '<a href="%1$s" class="mark-read primary">%2$s</a>', esc_url( bp_get_the_notification_mark_read_url( $user_id ) ), __( 'Read', 'buddypress' ) );
 559  
 560          /**
 561           * Filters the mark read link for the current notification.
 562           *
 563           * @since 1.9.0
 564           * @since 2.6.0 Added $user_id as a parameter.
 565           *
 566           * @param string $retval  HTML for the mark read link for the current notification.
 567           * @param int    $user_id The user ID.
 568           */
 569          return apply_filters( 'bp_get_the_notification_mark_read_link', $retval, $user_id );
 570      }
 571  
 572  /**
 573   * Output the URL used for marking a single notification as read.
 574   *
 575   * Since this function directly outputs a URL, it is escaped.
 576   *
 577   * @since 2.1.0
 578   * @since 2.6.0 Added $user_id as a parameter.
 579   *
 580   * @param int $user_id The user ID.
 581   */
 582  function bp_the_notification_mark_read_url( $user_id = 0 ) {
 583      echo esc_url( bp_get_the_notification_mark_read_url( $user_id ) );
 584  }
 585      /**
 586       * Return the URL used for marking a single notification as read.
 587       *
 588       * @since 2.1.0
 589       * @since 2.6.0 Added $user_id as a parameter.
 590       *
 591       * @param int $user_id The user ID.
 592       * @return string
 593       */
 594  	function bp_get_the_notification_mark_read_url( $user_id = 0 ) {
 595  
 596          // Get the notification ID.
 597          $id   = bp_get_the_notification_id();
 598  
 599          // Get the args to add to the URL.
 600          $args = array(
 601              'action'          => 'read',
 602              'notification_id' => $id
 603          );
 604  
 605          // Set default user ID to use.
 606          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 607  
 608          // Add the args to the URL.
 609          $url = add_query_arg( $args, bp_get_notifications_unread_permalink( $user_id ) );
 610  
 611          // Add the nonce.
 612          $url = wp_nonce_url( $url, 'bp_notification_mark_read_' . $id );
 613  
 614          /**
 615           * Filters the URL used for marking a single notification as read.
 616           *
 617           * @since 2.1.0
 618           * @since 2.6.0 Added $user_id as a parameter.
 619           *
 620           * @param string $url     URL to use for marking the single notification as read.
 621           * @param int    $user_id The user ID.
 622           */
 623          return apply_filters( 'bp_get_the_notification_mark_read_url', $url, $user_id );
 624      }
 625  
 626  /**
 627   * Output the mark unread link for the current notification.
 628   *
 629   * @since 1.9.0
 630   * @since 2.6.0 Added $user_id as a parameter.
 631   *
 632   * @param int $user_id The user ID.
 633   */
 634  function bp_the_notification_mark_unread_link( $user_id = 0 ) {
 635      echo bp_get_the_notification_mark_unread_link( $user_id );
 636  }
 637      /**
 638       * Return the mark unread link for the current notification.
 639       *
 640       * @since 1.9.0
 641       * @since 2.6.0 Added $user_id as a parameter.
 642       *
 643       * @param int $user_id The user ID.
 644       * @return string
 645       */
 646  	function bp_get_the_notification_mark_unread_link( $user_id = 0 ) {
 647          // Set default user ID to use.
 648          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 649  
 650          $retval = sprintf( '<a href="%1$s" class="mark-unread primary bp-tooltip">%2$s</a>', esc_url( bp_get_the_notification_mark_unread_url( $user_id ) ), __( 'Unread', 'buddypress' ) );
 651  
 652          /**
 653           * Filters the link used for marking a single notification as unread.
 654           *
 655           * @since 1.9.0
 656           * @since 2.6.0 Added $user_id as a parameter.
 657           *
 658           * @param string $retval  HTML for the mark unread link for the current notification.
 659           * @param int    $user_id The user ID.
 660           */
 661          return apply_filters( 'bp_get_the_notification_mark_unread_link', $retval, $user_id );
 662      }
 663  
 664  /**
 665   * Output the URL used for marking a single notification as unread.
 666   *
 667   * Since this function directly outputs a URL, it is escaped.
 668   *
 669   * @since 2.1.0
 670   * @since 2.6.0 Added $user_id as a parameter.
 671   *
 672   * @param int $user_id The user ID.
 673   */
 674  function bp_the_notification_mark_unread_url( $user_id = 0 ) {
 675      echo esc_url( bp_get_the_notification_mark_unread_url( $user_id ) );
 676  }
 677      /**
 678       * Return the URL used for marking a single notification as unread.
 679       *
 680       * @since 2.1.0
 681       * @since 2.6.0 Added $user_id as a parameter.
 682       *
 683       * @param int $user_id The user ID.
 684       * @return string
 685       */
 686  	function bp_get_the_notification_mark_unread_url( $user_id = 0 ) {
 687  
 688          // Get the notification ID.
 689          $id   = bp_get_the_notification_id();
 690  
 691          // Get the args to add to the URL.
 692          $args = array(
 693              'action'          => 'unread',
 694              'notification_id' => $id
 695          );
 696  
 697          // Set default user ID to use.
 698          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 699  
 700          // Add the args to the URL.
 701          $url = add_query_arg( $args, bp_get_notifications_read_permalink( $user_id ) );
 702  
 703          // Add the nonce.
 704          $url = wp_nonce_url( $url, 'bp_notification_mark_unread_' . $id );
 705  
 706          /**
 707           * Filters the URL used for marking a single notification as unread.
 708           *
 709           * @since 2.1.0
 710           * @since 2.6.0 Added $user_id as a parameter.
 711           *
 712           * @param string $url     URL to use for marking the single notification as unread.
 713           * @param int    $user_id The user ID.
 714           */
 715          return apply_filters( 'bp_get_the_notification_mark_unread_url', $url, $user_id );
 716      }
 717  
 718  /**
 719   * Output the mark link for the current notification.
 720   *
 721   * @since 1.9.0
 722   * @since 2.6.0 Added $user_id as a parameter.
 723   *
 724   * @param int $user_id The user ID.
 725   */
 726  function bp_the_notification_mark_link( $user_id = 0 ) {
 727      echo bp_get_the_notification_mark_link( $user_id );
 728  }
 729      /**
 730       * Return the mark link for the current notification.
 731       *
 732       * @since 1.9.0
 733       * @since 2.6.0 Added $user_id as a parameter.
 734       *
 735       * @param int $user_id The user ID.
 736       * @return string
 737       */
 738  	function bp_get_the_notification_mark_link( $user_id = 0 ) {
 739          // Set default user ID to use.
 740          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 741  
 742          if ( bp_is_current_action( 'read' ) ) {
 743              $retval = bp_get_the_notification_mark_unread_link( $user_id );
 744          } else {
 745              $retval = bp_get_the_notification_mark_read_link( $user_id );
 746          }
 747  
 748          /**
 749           * Filters the mark link for the current notification.
 750           *
 751           * @since 1.9.0
 752           * @since 2.6.0 Added $user_id as a parameter.
 753           *
 754           * @param string $retval  The mark link for the current notification.
 755           * @param int    $user_id The user ID.
 756           */
 757          return apply_filters( 'bp_get_the_notification_mark_link', $retval, $user_id );
 758      }
 759  
 760  /**
 761   * Output the delete link for the current notification.
 762   *
 763   * @since 1.9.0
 764   * @since 2.6.0 Added $user_id as a parameter.
 765   *
 766   * @param int $user_id The user ID.
 767   */
 768  function bp_the_notification_delete_link( $user_id = 0 ) {
 769      echo bp_get_the_notification_delete_link( $user_id );
 770  }
 771      /**
 772       * Return the delete link for the current notification.
 773       *
 774       * @since 1.9.0
 775       * @since 2.6.0 Added $user_id as a parameter.
 776       *
 777       * @param int $user_id The user ID.
 778       * @return string
 779       */
 780  	function bp_get_the_notification_delete_link( $user_id = 0 ) {
 781          // Set default user ID to use.
 782          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 783  
 784          $retval = sprintf( '<a href="%1$s" class="delete secondary confirm bp-tooltip">%2$s</a>', esc_url( bp_get_the_notification_delete_url( $user_id ) ), __( 'Delete', 'buddypress' ) );
 785  
 786          /**
 787           * Filters the delete link for the current notification.
 788           *
 789           * @since 1.9.0
 790           * @since 2.6.0 Added $user_id as a parameter.
 791           *
 792           * @param string $retval  HTML for the delete link for the current notification.
 793           * @param int    $user_id The user ID.
 794           */
 795          return apply_filters( 'bp_get_the_notification_delete_link', $retval, $user_id );
 796      }
 797  
 798  /**
 799   * Output the URL used for deleting a single notification.
 800   *
 801   * Since this function directly outputs a URL, it is escaped.
 802   *
 803   * @since 2.1.0
 804   * @since 2.6.0 Added $user_id as a parameter.
 805   *
 806   * @param int $user_id The user ID.
 807   */
 808  function bp_the_notification_delete_url( $user_id = 0 ) {
 809      echo esc_url( bp_get_the_notification_delete_url( $user_id ) );
 810  }
 811      /**
 812       * Return the URL used for deleting a single notification.
 813       *
 814       * @since 2.1.0
 815       * @since 2.6.0 Added $user_id as a parameter.
 816       *
 817       * @param int $user_id The user ID.
 818       * @return string
 819       */
 820  	function bp_get_the_notification_delete_url( $user_id = 0 ) {
 821          // Set default user ID to use.
 822          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 823  
 824          // URL to add nonce to.
 825          if ( bp_is_current_action( 'unread' ) ) {
 826              $link = bp_get_notifications_unread_permalink( $user_id );
 827          } elseif ( bp_is_current_action( 'read' ) ) {
 828              $link = bp_get_notifications_read_permalink( $user_id );
 829          }
 830  
 831          // Get the ID.
 832          $id = bp_get_the_notification_id();
 833  
 834          // Get the args to add to the URL.
 835          $args = array(
 836              'action'          => 'delete',
 837              'notification_id' => $id
 838          );
 839  
 840          // Add the args.
 841          $url = add_query_arg( $args, $link );
 842  
 843          // Add the nonce.
 844          $url = wp_nonce_url( $url, 'bp_notification_delete_' . $id );
 845  
 846          /**
 847           * Filters the URL used for deleting a single notification.
 848           *
 849           * @since 2.1.0
 850           * @since 2.6.0 Added $user_id as a parameter.
 851           *
 852           * @param string $url     URL used for deleting a single notification.
 853           * @param int    $user_id The user ID.
 854           */
 855          return apply_filters( 'bp_get_the_notification_delete_url', $url, $user_id );
 856      }
 857  
 858  /**
 859   * Output the action links for the current notification.
 860   *
 861   * @since 1.9.0
 862   * @since 2.6.0 Added $user_id as a parameter to $args.
 863   *
 864   * @param array|string $args Array of arguments.
 865   */
 866  function bp_the_notification_action_links( $args = '' ) {
 867      echo bp_get_the_notification_action_links( $args );
 868  }
 869      /**
 870       * Return the action links for the current notification.
 871       *
 872       * @since 1.9.0
 873       * @since 2.6.0 Added $user_id as a parameter to $args.
 874       *
 875       * @param array|string $args {
 876       *     @type string $before  HTML before the links.
 877       *     @type string $after   HTML after the links.
 878       *     @type string $sep     HTML between the links.
 879       *     @type array  $links   Array of links to implode by 'sep'.
 880       *     @type int    $user_id User ID to fetch action links for. Defaults to displayed user ID.
 881       * }
 882       * @return string HTML links for actions to take on single notifications.
 883       */
 884  	function bp_get_the_notification_action_links( $args = '' ) {
 885          // Set default user ID to use.
 886          $user_id = isset( $args['user_id'] ) ? $args['user_id'] : bp_displayed_user_id();
 887  
 888          // Parse.
 889          $r = wp_parse_args( $args, array(
 890              'before' => '',
 891              'after'  => '',
 892              'sep'    => ' | ',
 893              'links'  => array(
 894                  bp_get_the_notification_mark_link( $user_id ),
 895                  bp_get_the_notification_delete_link( $user_id )
 896              )
 897          ) );
 898  
 899          // Build the links.
 900          $retval = $r['before'] . implode( $r['links'], $r['sep'] ) . $r['after'];
 901  
 902          /**
 903           * Filters the action links for the current notification.
 904           *
 905           * @since 1.9.0
 906           * @since 2.6.0 Added the `$r` parameter.
 907           *
 908           * @param string $retval HTML links for actions to take on single notifications.
 909           * @param array  $r      Array of parsed arguments.
 910           */
 911          return apply_filters( 'bp_get_the_notification_action_links', $retval, $r );
 912      }
 913  
 914  /**
 915   * Output the pagination count for the current notification loop.
 916   *
 917   * @since 1.9.0
 918   */
 919  function bp_notifications_pagination_count() {
 920      echo bp_get_notifications_pagination_count();
 921  }
 922      /**
 923       * Return the pagination count for the current notification loop.
 924       *
 925       * @since 1.9.0
 926       *
 927       * @return string HTML for the pagination count.
 928       */
 929  	function bp_get_notifications_pagination_count() {
 930          $query_loop = buddypress()->notifications->query_loop;
 931          $start_num  = intval( ( $query_loop->pag_page - 1 ) * $query_loop->pag_num ) + 1;
 932          $from_num   = bp_core_number_format( $start_num );
 933          $to_num     = bp_core_number_format( ( $start_num + ( $query_loop->pag_num - 1 ) > $query_loop->total_notification_count ) ? $query_loop->total_notification_count : $start_num + ( $query_loop->pag_num - 1 ) );
 934          $total      = bp_core_number_format( $query_loop->total_notification_count );
 935  
 936          if ( 1 == $query_loop->total_notification_count ) {
 937              $pag = __( 'Viewing 1 notification', 'buddypress' );
 938          } else {
 939              $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s notification', 'Viewing %1$s - %2$s of %3$s notifications', $query_loop->total_notification_count, 'buddypress' ), $from_num, $to_num, $total );
 940          }
 941  
 942          /**
 943           * Filters the pagination count for the current notification loop.
 944           *
 945           * @since 1.9.0
 946           *
 947           * @param string $pag HTML for the pagination count.
 948           */
 949          return apply_filters( 'bp_notifications_pagination_count', $pag );
 950      }
 951  
 952  /**
 953   * Output the pagination links for the current notification loop.
 954   *
 955   * @since 1.9.0
 956   */
 957  function bp_notifications_pagination_links() {
 958      echo bp_get_notifications_pagination_links();
 959  }
 960      /**
 961       * Return the pagination links for the current notification loop.
 962       *
 963       * @since 1.9.0
 964       *
 965       * @return string HTML for the pagination links.
 966       */
 967  	function bp_get_notifications_pagination_links() {
 968  
 969          /**
 970           * Filters the pagination links for the current notification loop.
 971           *
 972           * @since 1.9.0
 973           *
 974           * @param string $pag_links HTML for the pagination links.
 975           */
 976          return apply_filters( 'bp_get_notifications_pagination_links', buddypress()->notifications->query_loop->pag_links );
 977      }
 978  
 979  /** Form Helpers **************************************************************/
 980  
 981  /**
 982   * Output the form for changing the sort order of notifications.
 983   *
 984   * @since 1.9.0
 985   */
 986  function bp_notifications_sort_order_form() {
 987  
 988      // Setup local variables.
 989      $orders   = array( 'DESC', 'ASC' );
 990      $selected = 'DESC';
 991  
 992      // Check for a custom sort_order.
 993      if ( !empty( $_REQUEST['sort_order'] ) ) {
 994          if ( in_array( $_REQUEST['sort_order'], $orders ) ) {
 995              $selected = $_REQUEST['sort_order'];
 996          }
 997      } ?>
 998  
 999      <form action="" method="get" id="notifications-sort-order">
1000          <label for="notifications-sort-order-list"><?php esc_html_e( 'Order By:', 'buddypress' ); ?></label>
1001  
1002          <select id="notifications-sort-order-list" name="sort_order" onchange="this.form.submit();">
1003              <option value="DESC" <?php selected( $selected, 'DESC' ); ?>><?php _e( 'Newest First', 'buddypress' ); ?></option>
1004              <option value="ASC"  <?php selected( $selected, 'ASC'  ); ?>><?php _e( 'Oldest First', 'buddypress' ); ?></option>
1005          </select>
1006  
1007          <noscript>
1008              <input id="submit" type="submit" name="form-submit" class="submit" value="<?php esc_attr_e( 'Go', 'buddypress' ); ?>" />
1009          </noscript>
1010      </form>
1011  
1012  <?php
1013  }
1014  
1015  /**
1016   * Output the dropdown for bulk management of notifications.
1017   *
1018   * @since 2.2.0
1019   */
1020  function bp_notifications_bulk_management_dropdown() {
1021      ?>
1022      <label class="bp-screen-reader-text" for="notification-select"><?php
1023          /* translators: accessibility text */
1024          _e( 'Select Bulk Action', 'buddypress' );
1025      ?></label>
1026      <select name="notification_bulk_action" id="notification-select">
1027          <option value="" selected="selected"><?php _e( 'Bulk Actions', 'buddypress' ); ?></option>
1028  
1029          <?php if ( bp_is_current_action( 'unread' ) ) : ?>
1030              <option value="read"><?php _e( 'Mark read', 'buddypress' ); ?></option>
1031          <?php elseif ( bp_is_current_action( 'read' ) ) : ?>
1032              <option value="unread"><?php _e( 'Mark unread', 'buddypress' ); ?></option>
1033          <?php endif; ?>
1034          <option value="delete"><?php _e( 'Delete', 'buddypress' ); ?></option>
1035      </select>
1036      <input type="submit" id="notification-bulk-manage" class="button action" value="<?php esc_attr_e( 'Apply', 'buddypress' ); ?>">
1037      <?php
1038  }


Generated: Thu Sep 19 01:01:39 2019 Cross-referenced by PHPXref 0.7.1