[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Messages Template Tags.
   4   *
   5   * @package BuddyPress
   6   * @subpackage MessagesTemplate
   7   * @since 1.5.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Retrieve private message threads for display in inbox/sentbox/notices.
  15   *
  16   * Similar to WordPress's have_posts() function, this function is responsible
  17   * for querying the database and retrieving private messages for display inside
  18   * the theme via individual template parts for a member's inbox/sentbox/notices.
  19   *
  20   * @since 1.0.0
  21   *
  22   * @global BP_Messages_Box_Template $messages_template
  23   *
  24   * @param array|string $args {
  25   *     Array of arguments. All are optional.
  26   *     @type int    $user_id      ID of the user whose threads are being loaded.
  27   *                                Default: ID of the logged-in user.
  28   *     @type string $box          Current "box" view. If not provided here, the current
  29   *                                view will be inferred from the URL.
  30   *     @type int    $per_page     Number of results to return per page. Default: 10.
  31   *     @type int    $max          Max results to return. Default: false.
  32   *     @type string $type         Type of messages to return. Values: 'all', 'read', 'unread'
  33   *                                Default: 'all'
  34   *     @type string $search_terms Terms to which to limit results. Default:
  35   *                                the value of $_REQUEST['s'].
  36   *     @type string $page_arg     URL argument used for the pagination param.
  37   *                                Default: 'mpage'.
  38   *     @type array  $meta_query   Meta query arguments. Only applicable if $box is
  39   *                                not 'notices'. See WP_Meta_Query more details.
  40   * }
  41   * @return bool True if there are threads to display, otherwise false.
  42   */
  43  function bp_has_message_threads( $args = array() ) {
  44      global $messages_template;
  45  
  46      // The default box the user is looking at.
  47      $current_action = bp_current_action();
  48      switch ( $current_action ) {
  49          case 'sentbox' :
  50          case 'notices' :
  51          case 'inbox'   :
  52              $default_box = $current_action;
  53              break;
  54          default :
  55              $default_box = 'inbox';
  56              break;
  57      }
  58  
  59      // User ID
  60      // @todo displayed user for moderators that get this far?
  61      $user_id = bp_displayed_user_id();
  62  
  63      // Search Terms.
  64      $search_terms = isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
  65  
  66      // Parse the arguments.
  67      $r = bp_parse_args( $args, array(
  68          'user_id'      => $user_id,
  69          'box'          => $default_box,
  70          'per_page'     => 10,
  71          'max'          => false,
  72          'type'         => 'all',
  73          'search_terms' => $search_terms,
  74          'page_arg'     => 'mpage', // See https://buddypress.trac.wordpress.org/ticket/3679.
  75          'meta_query'   => array()
  76      ), 'has_message_threads' );
  77  
  78      // Load the messages loop global up with messages.
  79      $messages_template = new BP_Messages_Box_Template( $r );
  80  
  81      /**
  82       * Filters if there are any message threads to display in inbox/sentbox/notices.
  83       *
  84       * @since 1.1.0
  85       *
  86       * @param bool                     $value             Whether or not the message has threads.
  87       * @param BP_Messages_Box_Template $messages_template Current message box template object.
  88       * @param array                    $r                 Array of parsed arguments passed into function.
  89       */
  90      return apply_filters( 'bp_has_message_threads', $messages_template->has_threads(), $messages_template, $r );
  91  }
  92  
  93  /**
  94   * Check whether there are more threads to iterate over.
  95   *
  96   * @return bool
  97   */
  98  function bp_message_threads() {
  99      global $messages_template;
 100      return $messages_template->message_threads();
 101  }
 102  
 103  /**
 104   * Set up the current thread inside the loop.
 105   *
 106   * @return object
 107   */
 108  function bp_message_thread() {
 109      global $messages_template;
 110      return $messages_template->the_message_thread();
 111  }
 112  
 113  /**
 114   * Output the ID of the current thread in the loop.
 115   */
 116  function bp_message_thread_id() {
 117      echo bp_get_message_thread_id();
 118  }
 119      /**
 120       * Get the ID of the current thread in the loop.
 121       *
 122       * @return int
 123       */
 124  	function bp_get_message_thread_id() {
 125          global $messages_template;
 126  
 127          /**
 128           * Filters the ID of the current thread in the loop.
 129           *
 130           * @since 1.0.0
 131           *
 132           * @param int $thread_id ID of the current thread in the loop.
 133           */
 134          return apply_filters( 'bp_get_message_thread_id', $messages_template->thread->thread_id );
 135      }
 136  
 137  /**
 138   * Output the subject of the current thread in the loop.
 139   */
 140  function bp_message_thread_subject() {
 141      echo bp_get_message_thread_subject();
 142  }
 143      /**
 144       * Get the subject of the current thread in the loop.
 145       *
 146       * @return string
 147       */
 148  	function bp_get_message_thread_subject() {
 149          global $messages_template;
 150  
 151          /**
 152           * Filters the subject of the current thread in the loop.
 153           *
 154           * @since 1.1.0
 155           *
 156           * @param string $value Subject of the current thread in the loop.
 157           */
 158          return apply_filters( 'bp_get_message_thread_subject', $messages_template->thread->last_message_subject );
 159      }
 160  
 161  /**
 162   * Output an excerpt from the current message in the loop.
 163   */
 164  function bp_message_thread_excerpt() {
 165      echo bp_get_message_thread_excerpt();
 166  }
 167      /**
 168       * Generate an excerpt from the current message in the loop.
 169       *
 170       * @return string
 171       */
 172  	function bp_get_message_thread_excerpt() {
 173          global $messages_template;
 174  
 175          /**
 176           * Filters the excerpt of the current thread in the loop.
 177           *
 178           * @since 1.0.0
 179           *
 180           * @param string $value Excerpt of the current thread in the loop.
 181           */
 182          return apply_filters( 'bp_get_message_thread_excerpt', strip_tags( bp_create_excerpt( $messages_template->thread->last_message_content, 75 ) ) );
 183      }
 184  
 185  /**
 186   * Output the thread's last message content.
 187   *
 188   * When viewing your Inbox, the last message is the most recent message in
 189   * the thread of which you are *not* the author.
 190   *
 191   * When viewing your Sentbox, last message is the most recent message in
 192   * the thread of which you *are* the member.
 193   *
 194   * @since 2.0.0
 195   */
 196  function bp_message_thread_content() {
 197      echo bp_get_message_thread_content();
 198  }
 199      /**
 200       * Return the thread's last message content.
 201       *
 202       * When viewing your Inbox, the last message is the most recent message in
 203       * the thread of which you are *not* the author.
 204       *
 205       * When viewing your Sentbox, last message is the most recent message in
 206       * the thread of which you *are* the member.
 207       *
 208       * @since 2.0.0
 209       *
 210       * @return string The raw content of the last message in the thread.
 211       */
 212  	function bp_get_message_thread_content() {
 213          global $messages_template;
 214  
 215          /**
 216           * Filters the content of the last message in the thread.
 217           *
 218           * @since 2.0.0
 219           *
 220           * @param string $last_message_content Content of the last message in the thread.
 221           */
 222          return apply_filters( 'bp_get_message_thread_content', $messages_template->thread->last_message_content );
 223      }
 224  
 225  /**
 226   * Output a link to the page of the current thread's last author.
 227   */
 228  function bp_message_thread_from() {
 229      echo bp_get_message_thread_from();
 230  }
 231      /**
 232       * Get a link to the page of the current thread's last author.
 233       *
 234       * @return string
 235       */
 236  	function bp_get_message_thread_from() {
 237          global $messages_template;
 238  
 239          /**
 240           * Filters the link to the page of the current thread's last author.
 241           *
 242           * @since 1.0.0
 243           *
 244           * @param string $value Link to the page of the current thread's last author.
 245           */
 246          return apply_filters( 'bp_get_message_thread_from', bp_core_get_userlink( $messages_template->thread->last_sender_id ) );
 247      }
 248  
 249  /**
 250   * Output links to the pages of the current thread's recipients.
 251   */
 252  function bp_message_thread_to() {
 253      echo bp_get_message_thread_to();
 254  }
 255      /**
 256       * Generate HTML links to the pages of the current thread's recipients.
 257       *
 258       * @return string
 259       */
 260  	function bp_get_message_thread_to() {
 261          global $messages_template;
 262  
 263          /**
 264           * Filters the HTML links to the pages of the current thread's recipients.
 265           *
 266           * @since 1.0.0
 267           *
 268           * @param string $value HTML links to the pages of the current thread's recipients.
 269           */
 270          return apply_filters( 'bp_message_thread_to', BP_Messages_Thread::get_recipient_links($messages_template->thread->recipients ) );
 271      }
 272  
 273  /**
 274   * Output the permalink for a particular thread.
 275   *
 276   * @since 2.9.0 Introduced `$user_id` parameter.
 277   *
 278   * @param int $thread_id Optional. ID of the thread. Default: current thread
 279   *                       being iterated on in the loop.
 280   * @param int $user_id   Optional. ID of the user relative to whom the link
 281   *                       should be generated. Default: ID of logged-in user.
 282   */
 283  function bp_message_thread_view_link( $thread_id = 0, $user_id = null ) {
 284      echo bp_get_message_thread_view_link( $thread_id, $user_id );
 285  }
 286      /**
 287       * Get the permalink of a particular thread.
 288       *
 289       * @since 2.9.0 Introduced `$user_id` parameter.
 290       *
 291       * @param int $thread_id Optional. ID of the thread. Default: current
 292       *                       thread being iterated on in the loop.
 293       * @param int $user_id   Optional. ID of the user relative to whom the link
 294       *                       should be generated. Default: ID of logged-in user.
 295       * @return string
 296       */
 297  	function bp_get_message_thread_view_link( $thread_id = 0, $user_id = null ) {
 298          global $messages_template;
 299  
 300          if ( empty( $messages_template ) && (int) $thread_id > 0 ) {
 301              $thread_id = (int) $thread_id;
 302          } elseif ( ! empty( $messages_template->thread->thread_id ) ) {
 303              $thread_id = $messages_template->thread->thread_id;
 304          }
 305  
 306          if ( null === $user_id ) {
 307              $user_id = bp_loggedin_user_id();
 308          }
 309  
 310          $domain = bp_core_get_user_domain( $user_id );
 311  
 312          /**
 313           * Filters the permalink of a particular thread.
 314           *
 315           * @since 1.0.0
 316           * @since 2.6.0 Added the `$thread_id` parameter.
 317           * @since 2.9.0 Added the `$user_id` parameter.
 318           *
 319           * @param string $value     Permalink of a particular thread.
 320           * @param int    $thread_id ID of the thread.
 321           * @param int    $user_id   ID of the user.
 322           */
 323          return apply_filters( 'bp_get_message_thread_view_link', trailingslashit( $domain . bp_get_messages_slug() . '/view/' . $thread_id ), $thread_id, $user_id );
 324      }
 325  
 326  /**
 327   * Output the URL for deleting the current thread.
 328   *
 329   * @since 2.9.0 Introduced `$user_id` parameter.
 330   *
 331   * @param int $user_id Optional. ID of the user relative to whom the link
 332   *                     should be generated. Default: ID of logged-in user.
 333   */
 334  function bp_message_thread_delete_link( $user_id = null ) {
 335      echo esc_url( bp_get_message_thread_delete_link( $user_id ) );
 336  }
 337      /**
 338       * Generate the URL for deleting the current thread.
 339       *
 340       * @since 2.9.0 Introduced `$user_id` parameter.
 341       *
 342       * @param int $user_id Optional. ID of the user relative to whom the link
 343       *                     should be generated. Default: ID of logged-in user.
 344       * @return string
 345       */
 346  	function bp_get_message_thread_delete_link( $user_id = null ) {
 347          global $messages_template;
 348  
 349          if ( null === $user_id ) {
 350              $user_id = bp_loggedin_user_id();
 351          }
 352  
 353          $domain = bp_core_get_user_domain( $user_id );
 354  
 355          /**
 356           * Filters the URL for deleting the current thread.
 357           *
 358           * @since 1.0.0
 359           *
 360           * @param string $value   URL for deleting the current thread.
 361           * @param int    $user_id ID of the user relative to whom the link should be generated.
 362           */
 363          return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( trailingslashit( $domain . bp_get_messages_slug() . '/' . bp_current_action() . '/delete/' . $messages_template->thread->thread_id ), 'messages_delete_thread' ), $user_id );
 364      }
 365  
 366  /**
 367   * Output the URL used for marking a single message thread as unread.
 368   *
 369   * Since this function directly outputs a URL, it is escaped.
 370   *
 371   * @since 2.2.0
 372   * @since 2.9.0 Introduced `$user_id` parameter.
 373   *
 374   * @param int $user_id Optional. ID of the user relative to whom the link
 375   *                     should be generated. Default: ID of logged-in user.
 376   */
 377  function bp_the_message_thread_mark_unread_url( $user_id = null ) {
 378      echo esc_url( bp_get_the_message_thread_mark_unread_url( $user_id ) );
 379  }
 380      /**
 381       * Return the URL used for marking a single message thread as unread.
 382       *
 383       * @since 2.2.0
 384       * @since 2.9.0 Introduced `$user_id` parameter.
 385       *
 386       * @param int $user_id Optional. ID of the user relative to whom the link
 387       *                     should be generated. Default: ID of logged-in user.
 388       * @return string
 389       */
 390  	function bp_get_the_message_thread_mark_unread_url( $user_id = null ) {
 391  
 392          // Get the message ID.
 393          $id = bp_get_message_thread_id();
 394  
 395          // Get the args to add to the URL.
 396          $args = array(
 397              'action'     => 'unread',
 398              'message_id' => $id
 399          );
 400  
 401          if ( null === $user_id ) {
 402              $user_id = bp_loggedin_user_id();
 403          }
 404  
 405          $domain = bp_core_get_user_domain( $user_id );
 406  
 407          // Base unread URL.
 408          $url = trailingslashit( $domain . bp_get_messages_slug() . '/' . bp_current_action() . '/unread' );
 409  
 410          // Add the args to the URL.
 411          $url = add_query_arg( $args, $url );
 412  
 413          // Add the nonce.
 414          $url = wp_nonce_url( $url, 'bp_message_thread_mark_unread_' . $id );
 415  
 416          /**
 417           * Filters the URL used for marking a single message thread as unread.
 418           *
 419           * @since 2.2.0
 420           * @since 2.9.0 Added `$user_id` parameter.
 421           *
 422           * @param string $url     URL used for marking a single message thread as unread.
 423           * @param int    $user_id ID of the user relative to whom the link should be generated.
 424           */
 425          return apply_filters( 'bp_get_the_message_thread_mark_unread_url', $url, $user_id );
 426      }
 427  
 428  /**
 429   * Output the URL used for marking a single message thread as read.
 430   *
 431   * Since this function directly outputs a URL, it is escaped.
 432   *
 433   * @since 2.2.0
 434   * @since 2.9.0 Introduced `$user_id` parameter.
 435   *
 436   * @param int $user_id Optional. ID of the user relative to whom the link
 437   *                     should be generated. Default: ID of logged-in user.
 438   */
 439  function bp_the_message_thread_mark_read_url( $user_id = null ) {
 440      echo esc_url( bp_get_the_message_thread_mark_read_url( $user_id ) );
 441  }
 442      /**
 443       * Return the URL used for marking a single message thread as read.
 444       *
 445       * @since 2.2.0
 446       * @since 2.9.0 Introduced `$user_id` parameter.
 447       *
 448       * @param int $user_id Optional. ID of the user relative to whom the link
 449       *                     should be generated. Default: ID of logged-in user.
 450       * @return string
 451       */
 452  	function bp_get_the_message_thread_mark_read_url( $user_id = null ) {
 453  
 454          // Get the message ID.
 455          $id = bp_get_message_thread_id();
 456  
 457          // Get the args to add to the URL.
 458          $args = array(
 459              'action'     => 'read',
 460              'message_id' => $id
 461          );
 462  
 463          if ( null === $user_id ) {
 464              $user_id = bp_loggedin_user_id();
 465          }
 466  
 467          $domain = bp_core_get_user_domain( $user_id );
 468  
 469          // Base read URL.
 470          $url = trailingslashit( $domain . bp_get_messages_slug() . '/' . bp_current_action() . '/read' );
 471  
 472          // Add the args to the URL.
 473          $url = add_query_arg( $args, $url );
 474  
 475          // Add the nonce.
 476          $url = wp_nonce_url( $url, 'bp_message_thread_mark_read_' . $id );
 477  
 478          /**
 479           * Filters the URL used for marking a single message thread as read.
 480           *
 481           * @since 2.2.0
 482           *
 483           * @param string $url     URL used for marking a single message thread as read.
 484           * @param int    $user_id ID of the user relative to whom the link should be generated.
 485           */
 486          return apply_filters( 'bp_get_the_message_thread_mark_read_url', $url );
 487      }
 488  
 489  /**
 490   * Output the CSS class for the current thread.
 491   */
 492  function bp_message_css_class() {
 493      echo esc_attr( bp_get_message_css_class() );
 494  }
 495      /**
 496       * Generate the CSS class for the current thread.
 497       *
 498       * @return string
 499       */
 500  	function bp_get_message_css_class() {
 501          global $messages_template;
 502  
 503          $class = false;
 504  
 505          if ( $messages_template->current_thread % 2 == 1 ) {
 506              $class .= 'alt';
 507          }
 508  
 509          /**
 510           * Filters the CSS class for the current thread.
 511           *
 512           * @since 1.2.10
 513           *
 514           * @param string $class Class string to be added to the list of classes.
 515           */
 516          return apply_filters( 'bp_get_message_css_class', trim( $class ) );
 517      }
 518  
 519  /**
 520   * Check whether the current thread has unread items.
 521   *
 522   * @return bool True if there are unread items, otherwise false.
 523   */
 524  function bp_message_thread_has_unread() {
 525      global $messages_template;
 526  
 527      $retval = ! empty( $messages_template->thread->unread_count )
 528          ? true
 529          : false;
 530  
 531      /**
 532       * Filters whether or not a message thread has unread items.
 533       *
 534       * @since 2.1.0
 535       *
 536       * @param bool $retval Whether or not a message thread has unread items.
 537       */
 538      return apply_filters( 'bp_message_thread_has_unread', $retval );
 539  }
 540  
 541  /**
 542   * Output the current thread's unread count.
 543   */
 544  function bp_message_thread_unread_count() {
 545      echo esc_html( bp_get_message_thread_unread_count() );
 546  }
 547      /**
 548       * Get the current thread's unread count.
 549       *
 550       * @return int
 551       */
 552  	function bp_get_message_thread_unread_count() {
 553          global $messages_template;
 554  
 555          $count = ! empty( $messages_template->thread->unread_count )
 556              ? (int) $messages_template->thread->unread_count
 557              : false;
 558  
 559          /**
 560           * Filters the current thread's unread count.
 561           *
 562           * @since 1.0.0
 563           *
 564           * @param int $count Current thread unread count.
 565           */
 566          return apply_filters( 'bp_get_message_thread_unread_count', $count );
 567      }
 568  
 569  /**
 570   * Output a thread's total message count.
 571   *
 572   * @since 2.2.0
 573   *
 574   * @param int|bool $thread_id Optional. ID of the thread. Defaults to current thread ID.
 575   */
 576  function bp_message_thread_total_count( $thread_id = false ) {
 577      echo bp_get_message_thread_total_count( $thread_id );
 578  }
 579      /**
 580       * Get the current thread's total message count.
 581       *
 582       * @since 2.2.0
 583       *
 584       * @param int|bool $thread_id Optional. ID of the thread.
 585       *                            Defaults to current thread ID.
 586       * @return int
 587       */
 588  	function bp_get_message_thread_total_count( $thread_id = false ) {
 589          if ( false === $thread_id ) {
 590              $thread_id = bp_get_message_thread_id();
 591          }
 592  
 593          $thread_template = new BP_Messages_Thread_Template( $thread_id, 'ASC', array(
 594              'update_meta_cache' => false
 595          ) );
 596  
 597          $count = 0;
 598          if ( ! empty( $thread_template->message_count ) ) {
 599              $count = intval( $thread_template->message_count );
 600          }
 601  
 602          /**
 603           * Filters the current thread's total message count.
 604           *
 605           * @since 2.2.0
 606           * @since 2.6.0 Added the `$thread_id` parameter.
 607           *
 608           * @param int $count     Current thread total message count.
 609           * @param int $thread_id ID of the queried thread.
 610           */
 611          return apply_filters( 'bp_get_message_thread_total_count', $count, $thread_id );
 612      }
 613  
 614  /**
 615   * Output markup for the current thread's total and unread count.
 616   *
 617   * @since 2.2.0
 618   *
 619   * @param int|bool $thread_id Optional. ID of the thread. Default: current thread ID.
 620   */
 621  function bp_message_thread_total_and_unread_count( $thread_id = false ) {
 622      echo bp_get_message_thread_total_and_unread_count( $thread_id );
 623  }
 624      /**
 625       * Get markup for the current thread's total and unread count.
 626       *
 627       * @param int|bool $thread_id Optional. ID of the thread. Default: current thread ID.
 628       * @return string Markup displaying the total and unread count for the thread.
 629       */
 630  	function bp_get_message_thread_total_and_unread_count( $thread_id = false ) {
 631          if ( false === $thread_id ) {
 632              $thread_id = bp_get_message_thread_id();
 633          }
 634  
 635          $total  = bp_get_message_thread_total_count( $thread_id );
 636          $unread = bp_get_message_thread_unread_count( $thread_id );
 637  
 638          return sprintf(
 639              /* translators: 1: total number, 2: accessibility text: number of unread messages */
 640              '<span class="thread-count">(%1$s)</span> <span class="bp-screen-reader-text">%2$s</span>',
 641              number_format_i18n( $total ),
 642              /* translators: %d: number of unread messages */
 643              sprintf( _n( '%d unread', '%d unread', $unread, 'buddypress' ), number_format_i18n( $unread ) )
 644          );
 645      }
 646  
 647  /**
 648   * Output the unformatted date of the last post in the current thread.
 649   */
 650  function bp_message_thread_last_post_date_raw() {
 651      echo bp_get_message_thread_last_post_date_raw();
 652  }
 653      /**
 654       * Get the unformatted date of the last post in the current thread.
 655       *
 656       * @return string
 657       */
 658  	function bp_get_message_thread_last_post_date_raw() {
 659          global $messages_template;
 660  
 661          /**
 662           * Filters the unformatted date of the last post in the current thread.
 663           *
 664           * @since 2.1.0
 665           *
 666           * @param string $last_message_date Unformatted date of the last post in the current thread.
 667           */
 668          return apply_filters( 'bp_get_message_thread_last_message_date', $messages_template->thread->last_message_date );
 669      }
 670  
 671  /**
 672   * Output the nicely formatted date of the last post in the current thread.
 673   */
 674  function bp_message_thread_last_post_date() {
 675      echo bp_get_message_thread_last_post_date();
 676  }
 677      /**
 678       * Get the nicely formatted date of the last post in the current thread.
 679       *
 680       * @return string
 681       */
 682  	function bp_get_message_thread_last_post_date() {
 683  
 684          /**
 685           * Filters the nicely formatted date of the last post in the current thread.
 686           *
 687           * @since 2.1.0
 688           *
 689           * @param string $value Formatted date of the last post in the current thread.
 690           */
 691          return apply_filters( 'bp_get_message_thread_last_post_date', bp_format_time( strtotime( bp_get_message_thread_last_post_date_raw() ) ) );
 692      }
 693  
 694  /**
 695   * Output the avatar for the last sender in the current message thread.
 696   *
 697   * @see bp_get_message_thread_avatar() for a description of arguments.
 698   *
 699   * @param array|string $args See {@link bp_get_message_thread_avatar()}.
 700   */
 701  function bp_message_thread_avatar( $args = '' ) {
 702      echo bp_get_message_thread_avatar( $args );
 703  }
 704      /**
 705       * Return the avatar for the last sender in the current message thread.
 706       *
 707       * @see bp_core_fetch_avatar() For a description of arguments and
 708       *      return values.
 709       *
 710       * @param array|string $args {
 711       *     Arguments are listed here with an explanation of their defaults.
 712       *     For more information about the arguments, see
 713       *     {@link bp_core_fetch_avatar()}.
 714       *     @type string      $type   Default: 'thumb'.
 715       *     @type int|bool    $width  Default: false.
 716       *     @type int|bool    $height Default: false.
 717       *     @type string      $class  Default: 'avatar'.
 718       *     @type string|bool $id     Default: false.
 719       *     @type string      $alt    Default: 'Profile picture of [display name]'.
 720       * }
 721       * @return string User avatar string.
 722       */
 723  	function bp_get_message_thread_avatar( $args = '' ) {
 724          global $messages_template;
 725  
 726          $fullname = bp_core_get_user_displayname( $messages_template->thread->last_sender_id );
 727          $alt      = sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname );
 728  
 729          $r = bp_parse_args( $args, array(
 730              'type'   => 'thumb',
 731              'width'  => false,
 732              'height' => false,
 733              'class'  => 'avatar',
 734              'id'     => false,
 735              'alt'    => $alt
 736          ) );
 737  
 738          /**
 739           * Filters the avatar for the last sender in the current message thread.
 740           *
 741           * @since 1.0.0
 742           * @since 2.6.0 Added the `$r` parameter.
 743           *
 744           * @param string $value User avatar string.
 745           * @param array  $r     Array of parsed arguments.
 746           */
 747          return apply_filters( 'bp_get_message_thread_avatar', bp_core_fetch_avatar( array(
 748              'item_id' => $messages_template->thread->last_sender_id,
 749              'type'    => $r['type'],
 750              'alt'     => $r['alt'],
 751              'css_id'  => $r['id'],
 752              'class'   => $r['class'],
 753              'width'   => $r['width'],
 754              'height'  => $r['height'],
 755          ) ), $r );
 756      }
 757  
 758  /**
 759   * Output the unread messages count for the current inbox.
 760   *
 761   * @since 2.6.x Added $user_id argument.
 762   *
 763   * @param int $user_id The user ID.
 764   *
 765   * @return int $unread_count Total inbox unread count for user.
 766   */
 767  function bp_total_unread_messages_count( $user_id = 0 ) {
 768      echo bp_get_total_unread_messages_count( $user_id );
 769  }
 770      /**
 771       * Get the unread messages count for the current inbox.
 772       *
 773       * @since 2.6.x Added $user_id argument.
 774       *
 775       * @param int $user_id The user ID.
 776       *
 777       * @return int $unread_count Total inbox unread count for user.
 778       */
 779  	function bp_get_total_unread_messages_count( $user_id = 0 ) {
 780  
 781          /**
 782           * Filters the unread messages count for the current inbox.
 783           *
 784           * @since 1.0.0
 785           *
 786           * @param int $value Unread messages count for the current inbox.
 787           */
 788          return apply_filters( 'bp_get_total_unread_messages_count', BP_Messages_Thread::get_inbox_count( $user_id ) );
 789      }
 790  
 791  /**
 792   * Output the pagination HTML for the current thread loop.
 793   */
 794  function bp_messages_pagination() {
 795      echo bp_get_messages_pagination();
 796  }
 797      /**
 798       * Get the pagination HTML for the current thread loop.
 799       *
 800       * @return string
 801       */
 802  	function bp_get_messages_pagination() {
 803          global $messages_template;
 804  
 805          /**
 806           * Filters the pagination HTML for the current thread loop.
 807           *
 808           * @since 1.0.0
 809           *
 810           * @param int $pag_links Pagination HTML for the current thread loop.
 811           */
 812          return apply_filters( 'bp_get_messages_pagination', $messages_template->pag_links );
 813      }
 814  
 815  /**
 816   * Generate the "Viewing message x to y (of z messages)" string for a loop.
 817   */
 818  function bp_messages_pagination_count() {
 819      global $messages_template;
 820  
 821      $start_num = intval( ( $messages_template->pag_page - 1 ) * $messages_template->pag_num ) + 1;
 822      $from_num  = bp_core_number_format( $start_num );
 823      $to_num    = bp_core_number_format( ( $start_num + ( $messages_template->pag_num - 1 ) > $messages_template->total_thread_count ) ? $messages_template->total_thread_count : $start_num + ( $messages_template->pag_num - 1 ) );
 824      $total     = bp_core_number_format( $messages_template->total_thread_count );
 825  
 826      if ( 1 == $messages_template->total_thread_count ) {
 827          $message = __( 'Viewing 1 message', 'buddypress' );
 828      } else {
 829          /* translators: 1: message from number. 2: message to number. 3: total messages. */
 830          $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s message', 'Viewing %1$s - %2$s of %3$s messages', $messages_template->total_thread_count, 'buddypress' ), $from_num, $to_num, $total );
 831      }
 832  
 833      echo esc_html( $message );
 834  }
 835  
 836  /**
 837   * Output the Private Message search form.
 838   *
 839   * @todo  Move markup to template part in: /members/single/messages/search.php
 840   * @since 1.6.0
 841   */
 842  function bp_message_search_form() {
 843  
 844      // Get the default search text.
 845      $default_search_value = bp_get_search_default_text( 'messages' );
 846  
 847      // Setup a few values based on what's being searched for.
 848      $search_submitted     = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value;
 849      $search_placeholder   = ( $search_submitted === $default_search_value ) ? ' placeholder="' .  esc_attr( $search_submitted ) . '"' : '';
 850      $search_value         = ( $search_submitted !== $default_search_value ) ? ' value="'       .  esc_attr( $search_submitted ) . '"' : '';
 851  
 852      // Start the output buffer, so form can be filtered.
 853      ob_start(); ?>
 854  
 855      <form action="" method="get" id="search-message-form">
 856          <label for="messages_search" class="bp-screen-reader-text"><?php
 857              /* translators: accessibility text */
 858              esc_html_e( 'Search Messages', 'buddypress' );
 859          ?></label>
 860          <input type="text" name="s" id="messages_search"<?php echo $search_placeholder . $search_value; ?> />
 861          <input type="submit" class="button" id="messages_search_submit" name="messages_search_submit" value="<?php esc_html_e( 'Search', 'buddypress' ); ?>" />
 862      </form>
 863  
 864      <?php
 865  
 866      // Get the search form from the above output buffer.
 867      $search_form_html = ob_get_clean();
 868  
 869      /**
 870       * Filters the private message component search form.
 871       *
 872       * @since 2.2.0
 873       *
 874       * @param string $search_form_html HTML markup for the message search form.
 875       */
 876      echo apply_filters( 'bp_message_search_form', $search_form_html );
 877  }
 878  
 879  /**
 880   * Echo the form action for Messages HTML forms.
 881   */
 882  function bp_messages_form_action() {
 883      echo esc_url( bp_get_messages_form_action() );
 884  }
 885      /**
 886       * Return the form action for Messages HTML forms.
 887       *
 888       * @return string The form action.
 889       */
 890  	function bp_get_messages_form_action() {
 891  
 892          /**
 893           * Filters the form action for Messages HTML forms.
 894           *
 895           * @since 1.0.0
 896           *
 897           * @param string $value The form action.
 898           */
 899          return apply_filters( 'bp_get_messages_form_action', trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() . '/' . bp_current_action() . '/' . bp_action_variable( 0 ) ) );
 900      }
 901  
 902  /**
 903   * Output the default username for the recipient box.
 904   */
 905  function bp_messages_username_value() {
 906      echo esc_attr( bp_get_messages_username_value() );
 907  }
 908      /**
 909       * Get the default username for the recipient box.
 910       *
 911       * @return string
 912       */
 913  	function bp_get_messages_username_value() {
 914          if ( isset( $_COOKIE['bp_messages_send_to'] ) ) {
 915  
 916              /**
 917               * Filters the default username for the recipient box.
 918               *
 919               * Value passed into filter is dependent on if the 'bp_messages_send_to'
 920               * cookie or 'r' $_GET parameter is set.
 921               *
 922               * @since 1.0.0
 923               *
 924               * @param string $value Default user name.
 925               */
 926              return apply_filters( 'bp_get_messages_username_value', $_COOKIE['bp_messages_send_to'] );
 927          } elseif ( isset( $_GET['r'] ) && !isset( $_COOKIE['bp_messages_send_to'] ) ) {
 928              /** This filter is documented in bp-messages-template.php */
 929              return apply_filters( 'bp_get_messages_username_value', $_GET['r'] );
 930          }
 931      }
 932  
 933  /**
 934   * Output the default value for the Subject field.
 935   */
 936  function bp_messages_subject_value() {
 937      echo esc_attr( bp_get_messages_subject_value() );
 938  }
 939      /**
 940       * Get the default value for the Subject field.
 941       *
 942       * Will get a value out of $_POST['subject'] if available (ie after a
 943       * failed submission).
 944       *
 945       * @return string
 946       */
 947  	function bp_get_messages_subject_value() {
 948  
 949          // Sanitized in bp-messages-filters.php.
 950          $subject = ! empty( $_POST['subject'] )
 951              ? $_POST['subject']
 952              : '';
 953  
 954          /**
 955           * Filters the default value for the subject field.
 956           *
 957           * @since 1.0.0
 958           *
 959           * @param string $subject The default value for the subject field.
 960           */
 961          return apply_filters( 'bp_get_messages_subject_value', $subject );
 962      }
 963  
 964  /**
 965   * Output the default value for the Compose content field.
 966   */
 967  function bp_messages_content_value() {
 968      echo esc_textarea( bp_get_messages_content_value() );
 969  }
 970      /**
 971       * Get the default value fo the Compose content field.
 972       *
 973       * Will get a value out of $_POST['content'] if available (ie after a
 974       * failed submission).
 975       *
 976       * @return string
 977       */
 978  	function bp_get_messages_content_value() {
 979  
 980          // Sanitized in bp-messages-filters.php.
 981          $content = ! empty( $_POST['content'] )
 982              ? $_POST['content']
 983              : '';
 984  
 985          /**
 986           * Filters the default value for the content field.
 987           *
 988           * @since 1.0.0
 989           *
 990           * @param string $content The default value for the content field.
 991           */
 992          return apply_filters( 'bp_get_messages_content_value', $content );
 993      }
 994  
 995  /**
 996   * Output the markup for the message type dropdown.
 997   */
 998  function bp_messages_options() {
 999  ?>
1000  
1001      <label for="message-type-select" class="bp-screen-reader-text"><?php
1002          /* translators: accessibility text */
1003          _e( 'Select:', 'buddypress' );
1004      ?></label>
1005      <select name="message-type-select" id="message-type-select">
1006          <option value=""><?php _e( 'Select', 'buddypress' ); ?></option>
1007          <option value="read"><?php _ex('Read', 'Message dropdown filter', 'buddypress') ?></option>
1008          <option value="unread"><?php _ex('Unread', 'Message dropdown filter', 'buddypress') ?></option>
1009          <option value="all"><?php _ex('All', 'Message dropdown filter', 'buddypress') ?></option>
1010      </select> &nbsp;
1011  
1012      <?php if ( ! bp_is_current_action( 'sentbox' ) && ! bp_is_current_action( 'notices' ) ) : ?>
1013  
1014          <a href="#" id="mark_as_read"><?php _ex('Mark as Read', 'Message management markup', 'buddypress') ?></a> &nbsp;
1015          <a href="#" id="mark_as_unread"><?php _ex('Mark as Unread', 'Message management markup', 'buddypress') ?></a> &nbsp;
1016  
1017          <?php wp_nonce_field( 'bp_messages_mark_messages_read', 'mark-messages-read-nonce', false ); ?>
1018          <?php wp_nonce_field( 'bp_messages_mark_messages_unread', 'mark-messages-unread-nonce', false ); ?>
1019  
1020      <?php endif; ?>
1021  
1022      <a href="#" id="delete_<?php echo bp_current_action(); ?>_messages"><?php _e( 'Delete Selected', 'buddypress' ); ?></a> &nbsp;
1023      <?php wp_nonce_field( 'bp_messages_delete_selected', 'delete-selected-nonce', false ); ?>
1024  <?php
1025  }
1026  
1027  /**
1028   * Output the dropdown for bulk management of messages.
1029   *
1030   * @since 2.2.0
1031   */
1032  function bp_messages_bulk_management_dropdown() {
1033      ?>
1034      <label class="bp-screen-reader-text" for="messages-select"><?php
1035          _e( 'Select Bulk Action', 'buddypress' );
1036      ?></label>
1037      <select name="messages_bulk_action" id="messages-select">
1038          <option value="" selected="selected"><?php _e( 'Bulk Actions', 'buddypress' ); ?></option>
1039          <option value="read"><?php _e( 'Mark read', 'buddypress' ); ?></option>
1040          <option value="unread"><?php _e( 'Mark unread', 'buddypress' ); ?></option>
1041          <option value="delete"><?php _e( 'Delete', 'buddypress' ); ?></option>
1042          <?php
1043              /**
1044               * Action to add additional options to the messages bulk management dropdown.
1045               *
1046               * @since 2.3.0
1047               */
1048              do_action( 'bp_messages_bulk_management_dropdown' );
1049          ?>
1050      </select>
1051      <input type="submit" id="messages-bulk-manage" class="button action" value="<?php esc_attr_e( 'Apply', 'buddypress' ); ?>">
1052      <?php
1053  }
1054  
1055  /**
1056   * Return whether or not the notice is currently active.
1057   *
1058   * @since 1.6.0
1059   *
1060   * @return bool
1061   */
1062  function bp_messages_is_active_notice() {
1063      global $messages_template;
1064  
1065      $retval = ! empty( $messages_template->thread->is_active )
1066          ? true
1067          : false;
1068  
1069      /**
1070       * Filters whether or not the notice is currently active.
1071       *
1072       * @since 2.1.0
1073       *
1074       * @param bool $retval Whether or not the notice is currently active.
1075       */
1076      return apply_filters( 'bp_messages_is_active_notice', $retval );
1077  }
1078  
1079  /**
1080   * Output a string for the active notice.
1081   *
1082   * Since 1.6 this function has been deprecated in favor of text in the theme.
1083   *
1084   * @since 1.0.0
1085   * @deprecated 1.6.0
1086   * @return bool
1087   */
1088  function bp_message_is_active_notice() {
1089      echo bp_get_message_is_active_notice();
1090  }
1091      /**
1092       * Returns a string for the active notice.
1093       *
1094       * Since 1.6 this function has been deprecated in favor of text in the
1095       * theme.
1096       *
1097       * @since 1.0.0
1098       * @deprecated 1.6.0
1099       * @return string
1100       */
1101  	function bp_get_message_is_active_notice() {
1102  
1103          $string = bp_messages_is_active_notice()
1104              ? __( 'Currently Active', 'buddypress' )
1105              : '';
1106  
1107          return apply_filters( 'bp_get_message_is_active_notice', $string );
1108      }
1109  
1110  /**
1111   * Output the ID of the current notice in the loop.
1112   */
1113  function bp_message_notice_id() {
1114      echo (int) bp_get_message_notice_id();
1115  }
1116      /**
1117       * Get the ID of the current notice in the loop.
1118       *
1119       * @return int
1120       */
1121  	function bp_get_message_notice_id() {
1122          global $messages_template;
1123  
1124          /**
1125           * Filters the ID of the current notice in the loop.
1126           *
1127           * @since 1.5.0
1128           *
1129           * @param int $id ID of the current notice in the loop.
1130           */
1131          return apply_filters( 'bp_get_message_notice_id', $messages_template->thread->id );
1132      }
1133  
1134  /**
1135   * Output the post date of the current notice in the loop.
1136   */
1137  function bp_message_notice_post_date() {
1138      echo bp_get_message_notice_post_date();
1139  }
1140      /**
1141       * Get the post date of the current notice in the loop.
1142       *
1143       * @return string
1144       */
1145  	function bp_get_message_notice_post_date() {
1146          global $messages_template;
1147  
1148          /**
1149           * Filters the post date of the current notice in the loop.
1150           *
1151           * @since 1.0.0
1152           *
1153           * @param string $value Formatted post date of the current notice in the loop.
1154           */
1155          return apply_filters( 'bp_get_message_notice_post_date', bp_format_time( strtotime( $messages_template->thread->date_sent ) ) );
1156      }
1157  
1158  /**
1159   * Output the subject of the current notice in the loop.
1160   *
1161   * @since 5.0.0 The $notice parameter has been added.
1162   *
1163   * @param BP_Messages_Notice $notice The notice object.
1164   */
1165  function bp_message_notice_subject( $notice = null ) {
1166      echo bp_get_message_notice_subject( $notice );
1167  }
1168      /**
1169       * Get the subject of the current notice in the loop.
1170       *
1171       * @since 5.0.0 The $notice parameter has been added.
1172       *
1173       * @param BP_Messages_Notice $notice The notice object.
1174       * @return string
1175       */
1176  	function bp_get_message_notice_subject( $notice = null ) {
1177          global $messages_template;
1178  
1179          if ( ! isset( $notice->subject ) ) {
1180              $notice =& $messages_template->thread;
1181          }
1182  
1183          /**
1184           * Filters the subject of the current notice in the loop.
1185           *
1186           * @since 1.0.0
1187           *
1188           * @param string $subject Subject of the current notice in the loop.
1189           */
1190          return apply_filters( 'bp_get_message_notice_subject', $notice->subject );
1191      }
1192  
1193  /**
1194   * Output the text of the current notice in the loop.
1195   *
1196   * @since 5.0.0 The $notice parameter has been added.
1197   *
1198   * @param BP_Messages_Notice $notice The notice object.
1199   */
1200  function bp_message_notice_text( $notice = null ) {
1201      echo bp_get_message_notice_text( $notice );
1202  }
1203      /**
1204       * Get the text of the current notice in the loop.
1205       *
1206       * @since 5.0.0 The $notice parameter has been added.
1207       *
1208       * @param BP_Messages_Notice $notice The notice object.
1209       * @return string
1210       */
1211  	function bp_get_message_notice_text( $notice = null ) {
1212          global $messages_template;
1213  
1214          if ( ! isset( $notice->subject ) ) {
1215              $notice =& $messages_template->thread;
1216          }
1217  
1218          /**
1219           * Filters the text of the current notice in the loop.
1220           *
1221           * @since 1.0.0
1222           *
1223           * @param string $message Text for the current notice in the loop.
1224           */
1225          return apply_filters( 'bp_get_message_notice_text', $notice->message );
1226      }
1227  
1228  /**
1229   * Output the URL for deleting the current notice.
1230   */
1231  function bp_message_notice_delete_link() {
1232      echo esc_url( bp_get_message_notice_delete_link() );
1233  }
1234      /**
1235       * Get the URL for deleting the current notice.
1236       *
1237       * @return string Delete URL.
1238       */
1239  	function bp_get_message_notice_delete_link() {
1240          global $messages_template;
1241  
1242          /**
1243           * Filters the URL for deleting the current notice.
1244           *
1245           * @since 1.0.0
1246           *
1247           * @param string $value URL for deleting the current notice.
1248           * @param string $value Text indicating action being executed.
1249           */
1250          return apply_filters( 'bp_get_message_notice_delete_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/delete/' . $messages_template->thread->id ), 'messages_delete_notice' ) );
1251      }
1252  
1253  /**
1254   * Output the URL for deactivating the current notice.
1255   */
1256  function bp_message_activate_deactivate_link() {
1257      echo esc_url( bp_get_message_activate_deactivate_link() );
1258  }
1259      /**
1260       * Get the URL for deactivating the current notice.
1261       *
1262       * @return string
1263       */
1264  	function bp_get_message_activate_deactivate_link() {
1265          global $messages_template;
1266  
1267          if ( 1 === (int) $messages_template->thread->is_active ) {
1268              $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' );
1269          } else {
1270              $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' );
1271          }
1272  
1273          /**
1274           * Filters the URL for deactivating the current notice.
1275           *
1276           * @since 1.0.0
1277           *
1278           * @param string $link URL for deactivating the current notice.
1279           */
1280          return apply_filters( 'bp_get_message_activate_deactivate_link', $link );
1281      }
1282  
1283  /**
1284   * Output the Deactivate/Activate text for the notice action link.
1285   */
1286  function bp_message_activate_deactivate_text() {
1287      echo esc_html( bp_get_message_activate_deactivate_text() );
1288  }
1289      /**
1290       * Generate the text ('Deactivate' or 'Activate') for the notice action link.
1291       *
1292       * @return string
1293       */
1294  	function bp_get_message_activate_deactivate_text() {
1295          global $messages_template;
1296  
1297          if ( 1 === (int) $messages_template->thread->is_active  ) {
1298              $text = __('Deactivate', 'buddypress');
1299          } else {
1300              $text = __('Activate', 'buddypress');
1301          }
1302  
1303          /**
1304           * Filters the "Deactivate" or "Activate" text for notice action links.
1305           *
1306           * @since 1.0.0
1307           *
1308           * @param string $text Text used for notice action links.
1309           */
1310          return apply_filters( 'bp_message_activate_deactivate_text', $text );
1311      }
1312  
1313  /**
1314   * Output the messages component slug.
1315   *
1316   * @since 1.5.0
1317   *
1318   */
1319  function bp_messages_slug() {
1320      echo bp_get_messages_slug();
1321  }
1322      /**
1323       * Return the messages component slug.
1324       *
1325       * @since 1.5.0
1326       *
1327       * @return string
1328       */
1329  	function bp_get_messages_slug() {
1330  
1331          /**
1332           * Filters the messages component slug.
1333           *
1334           * @since 1.5.0
1335           *
1336           * @param string $slug Messages component slug.
1337           */
1338          return apply_filters( 'bp_get_messages_slug', buddypress()->messages->slug );
1339      }
1340  
1341  /**
1342   * Generate markup for currently active notices.
1343   */
1344  function bp_message_get_notices() {
1345      $notice = BP_Messages_Notice::get_active();
1346  
1347      if ( empty( $notice ) ) {
1348          return false;
1349      }
1350  
1351      $closed_notices = bp_get_user_meta( bp_loggedin_user_id(), 'closed_notices', true );
1352  
1353      if ( empty( $closed_notices ) ) {
1354          $closed_notices = array();
1355      }
1356  
1357      if ( is_array( $closed_notices ) ) {
1358          if ( !in_array( $notice->id, $closed_notices ) && $notice->id ) {
1359              ?>
1360              <div id="message" class="info notice" rel="n-<?php echo esc_attr( $notice->id ); ?>">
1361                  <strong><?php bp_message_notice_subject( $notice ); ?></strong>
1362                  <button type="button" id="close-notice" class="bp-tooltip" data-bp-tooltip="<?php esc_attr_e( 'Dismiss this notice', 'buddypress' ) ?>"><span class="bp-screen-reader-text"><?php _e( 'Dismiss this notice', 'buddypress' ) ?></span> <span aria-hidden="true">&Chi;</span></button>
1363                  <?php bp_message_notice_text( $notice ); ?>
1364                  <?php wp_nonce_field( 'bp_messages_close_notice', 'close-notice-nonce' ); ?>
1365              </div>
1366              <?php
1367          }
1368      }
1369  }
1370  
1371  /**
1372   * Output the URL for the Private Message link in member profile headers.
1373   */
1374  function bp_send_private_message_link() {
1375      echo esc_url( bp_get_send_private_message_link() );
1376  }
1377      /**
1378       * Generate the URL for the Private Message link in member profile headers.
1379       *
1380       * @return bool|string False on failure, otherwise the URL.
1381       */
1382  	function bp_get_send_private_message_link() {
1383  
1384          if ( bp_is_my_profile() || ! is_user_logged_in() ) {
1385              return false;
1386          }
1387  
1388          /**
1389           * Filters the URL for the Private Message link in member profile headers.
1390           *
1391           * @since 1.2.10
1392           *
1393           * @param string $value URL for the Private Message link in member profile headers.
1394           */
1395          return apply_filters( 'bp_get_send_private_message_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_messages_slug() . '/compose/?r=' . bp_core_get_username( bp_displayed_user_id() ) ) );
1396      }
1397  
1398  /**
1399   * Output the 'Private Message' button for member profile headers.
1400   *
1401   * Explicitly named function to avoid confusion with public messages.
1402   *
1403   * @since 1.2.6
1404   *
1405   */
1406  function bp_send_private_message_button() {
1407      echo bp_get_send_message_button();
1408  }
1409  
1410  /**
1411   * Output the 'Private Message' button for member profile headers.
1412   *
1413   * @since 1.2.0
1414   * @since 3.0.0 Added `$args` parameter.
1415   *
1416   * @param array|string $args See {@link bp_get_send_message_button()}.
1417   */
1418  function bp_send_message_button( $args = '' ) {
1419      echo bp_get_send_message_button( $args );
1420  }
1421      /**
1422       * Generate the 'Private Message' button for member profile headers.
1423       *
1424       * @since 1.2.0
1425       * @since 3.0.0 Added `$args` parameter.
1426       *
1427       * @param array|string $args {
1428       *     All arguments are optional. See {@link BP_Button} for complete
1429       *     descriptions.
1430       *     @type string $id                Default: 'private_message'.
1431       *     @type string $component         Default: 'messages'.
1432       *     @type bool   $must_be_logged_in Default: true.
1433       *     @type bool   $block_self        Default: true.
1434       *     @type string $wrapper_id        Default: 'send-private-message'.
1435       *     @type string $link_href         Default: the private message link for
1436       *                                     the current member in the loop.
1437       *     @type string $link_text         Default: 'Private Message'.
1438       *     @type string $link_class        Default: 'send-message'.
1439       * }
1440       * @return string
1441       */
1442  	function bp_get_send_message_button( $args = '' ) {
1443  
1444          $r = bp_parse_args( $args, array(
1445              'id'                => 'private_message',
1446              'component'         => 'messages',
1447              'must_be_logged_in' => true,
1448              'block_self'        => true,
1449              'wrapper_id'        => 'send-private-message',
1450              'link_href'         => bp_get_send_private_message_link(),
1451              'link_text'         => __( 'Private Message', 'buddypress' ),
1452              'link_class'        => 'send-message',
1453          ) );
1454  
1455  
1456          // Note: 'bp_get_send_message_button' is a legacy filter. Use
1457          // 'bp_get_send_message_button_args' instead. See #4536.
1458          return apply_filters( 'bp_get_send_message_button',
1459  
1460              /**
1461               * Filters the "Private Message" button for member profile headers.
1462               *
1463               * @since 1.8.0
1464               *
1465               * @param array $value See {@link BP_Button}.
1466               */
1467              bp_get_button( apply_filters( 'bp_get_send_message_button_args', $r ) )
1468          );
1469      }
1470  
1471  /**
1472   * Output the URL of the Messages AJAX loader gif.
1473   */
1474  function bp_message_loading_image_src() {
1475      echo esc_url( bp_get_message_loading_image_src() );
1476  }
1477      /**
1478       * Get the URL of the Messages AJAX loader gif.
1479       *
1480       * @return string
1481       */
1482  	function bp_get_message_loading_image_src() {
1483  
1484          /**
1485           * Filters the URL of the Messages AJAX loader gif.
1486           *
1487           * @since 1.0.0
1488           *
1489           * @param string $value URL of the Messages AJAX loader gif.
1490           */
1491          return apply_filters( 'bp_get_message_loading_image_src', buddypress()->messages->image_base . '/ajax-loader.gif' );
1492      }
1493  
1494  /**
1495   * Output the markup for the message recipient tabs.
1496   */
1497  function bp_message_get_recipient_tabs() {
1498      $recipients = explode( ' ', bp_get_message_get_recipient_usernames() );
1499  
1500      foreach ( $recipients as $recipient ) {
1501  
1502          $user_id = bp_is_username_compatibility_mode()
1503              ? bp_core_get_userid( $recipient )
1504              : bp_core_get_userid_from_nicename( $recipient );
1505  
1506          if ( ! empty( $user_id ) ) : ?>
1507  
1508              <li id="un-<?php echo esc_attr( $recipient ); ?>" class="friend-tab">
1509                  <span><?php
1510                      echo bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15 ) );
1511                      echo bp_core_get_userlink( $user_id );
1512                  ?></span>
1513              </li>
1514  
1515          <?php endif;
1516      }
1517  }
1518  
1519  /**
1520   * Output recipient usernames for prefilling the 'To' field on the Compose screen.
1521   */
1522  function bp_message_get_recipient_usernames() {
1523      echo esc_attr( bp_get_message_get_recipient_usernames() );
1524  }
1525      /**
1526       * Get the recipient usernames for prefilling the 'To' field on the Compose screen.
1527       *
1528       * @return string
1529       */
1530  	function bp_get_message_get_recipient_usernames() {
1531  
1532          // Sanitized in bp-messages-filters.php.
1533          $recipients = isset( $_GET['r'] )
1534              ? $_GET['r']
1535              : '';
1536  
1537          /**
1538           * Filters the recipients usernames for prefilling the 'To' field on the Compose screen.
1539           *
1540           * @since 1.0.0
1541           *
1542           * @param string $recipients Recipients usernames for 'To' field prefilling.
1543           */
1544          return apply_filters( 'bp_get_message_get_recipient_usernames', $recipients );
1545      }
1546  
1547  /**
1548   * Initialize the messages template loop for a specific thread.
1549   *
1550   * @param array|string $args {
1551   *     Array of arguments. All are optional.
1552   *     @type int    $thread_id         ID of the thread whose messages you are displaying.
1553   *                                     Default: if viewing a thread, the thread ID will be parsed from
1554   *                                     the URL (bp_action_variable( 0 )).
1555   *     @type string $order             'ASC' or 'DESC'. Default: 'ASC'.
1556   *     @type bool   $update_meta_cache Whether to pre-fetch metadata for
1557   *                                     queried message items. Default: true.
1558   * }
1559   * @return bool True if there are messages to display, otherwise false.
1560   */
1561  function bp_thread_has_messages( $args = '' ) {
1562      global $thread_template;
1563  
1564      $r = bp_parse_args( $args, array(
1565          'thread_id'         => false,
1566          'order'             => 'ASC',
1567          'update_meta_cache' => true,
1568      ), 'thread_has_messages' );
1569  
1570      if ( empty( $r['thread_id'] ) && bp_is_messages_component() && bp_is_current_action( 'view' ) ) {
1571          $r['thread_id'] = (int) bp_action_variable( 0 );
1572      }
1573  
1574      // Set up extra args.
1575      $extra_args = $r;
1576      unset( $extra_args['thread_id'], $extra_args['order'] );
1577  
1578      $thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'], $extra_args );
1579  
1580      return $thread_template->has_messages();
1581  }
1582  
1583  /**
1584   * Output the 'ASC' or 'DESC' messages order string for this loop.
1585   */
1586  function bp_thread_messages_order() {
1587      echo esc_attr( bp_get_thread_messages_order() );
1588  }
1589      /**
1590       * Get the 'ASC' or 'DESC' messages order string for this loop.
1591       *
1592       * @return string
1593       */
1594  	function bp_get_thread_messages_order() {
1595          global $thread_template;
1596          return $thread_template->thread->messages_order;
1597      }
1598  
1599  /**
1600   * Check whether there are more messages to iterate over.
1601   *
1602   * @return bool
1603   */
1604  function bp_thread_messages() {
1605      global $thread_template;
1606  
1607      return $thread_template->messages();
1608  }
1609  
1610  /**
1611   * Set up the current thread inside the loop.
1612   *
1613   * @return object
1614   */
1615  function bp_thread_the_message() {
1616      global $thread_template;
1617  
1618      return $thread_template->the_message();
1619  }
1620  
1621  /**
1622   * Output the ID of the thread that the current loop belongs to.
1623   */
1624  function bp_the_thread_id() {
1625      echo (int) bp_get_the_thread_id();
1626  }
1627      /**
1628       * Get the ID of the thread that the current loop belongs to.
1629       *
1630       * @return int
1631       */
1632  	function bp_get_the_thread_id() {
1633          global $thread_template;
1634  
1635          /**
1636           * Filters the ID of the thread that the current loop belongs to.
1637           *
1638           * @since 1.1.0
1639           *
1640           * @param int $thread_id ID of the thread.
1641           */
1642          return apply_filters( 'bp_get_the_thread_id', $thread_template->thread->thread_id );
1643      }
1644  
1645  /**
1646   * Output the subject of the thread currently being iterated over.
1647   */
1648  function bp_the_thread_subject() {
1649      echo bp_get_the_thread_subject();
1650  }
1651      /**
1652       * Get the subject of the thread currently being iterated over.
1653       *
1654       * @return string
1655       */
1656  	function bp_get_the_thread_subject() {
1657          global $thread_template;
1658  
1659          /**
1660           * Filters the subject of the thread currently being iterated over.
1661           *
1662           * @since 1.1.0
1663           *
1664           * @return string $last_message_subject Subject of the thread currently being iterated over.
1665           */
1666          return apply_filters( 'bp_get_the_thread_subject', $thread_template->thread->last_message_subject );
1667      }
1668  
1669  /**
1670   * Get a list of thread recipients or a "x recipients" string.
1671   *
1672   * In BuddyPress 2.2.0, this parts of this functionality were moved into the
1673   * members/single/messages/single.php template. This function is no longer used
1674   * by BuddyPress.
1675   *
1676   * @return string
1677   */
1678  function bp_get_the_thread_recipients() {
1679      if ( 5 <= bp_get_thread_recipients_count() ) {
1680          /* translators: %s: number of message recipients */
1681          $recipients = sprintf( __( '%s recipients', 'buddypress' ), number_format_i18n( bp_get_thread_recipients_count() ) );
1682      } else {
1683          $recipients = bp_get_thread_recipients_list();
1684      }
1685  
1686      return apply_filters( 'bp_get_the_thread_recipients', $recipients );
1687  }
1688  
1689  /**
1690   * Get the number of recipients in the current thread.
1691   *
1692   * @since 2.2.0
1693   *
1694   * @return int
1695   */
1696  function bp_get_thread_recipients_count() {
1697      global $thread_template;
1698      /**
1699       * Filters the total number of recipients in a thread.
1700       *
1701       * @since 2.8.0
1702       *
1703       * @param int $count Total recipients number.
1704       */
1705      return (int) apply_filters( 'bp_get_thread_recipients_count', count( $thread_template->thread->recipients ) );
1706  }
1707  
1708  /**
1709   * Get the max number of recipients to list in the 'Conversation between...' gloss.
1710   *
1711   * @since 2.3.0
1712   *
1713   * @return int
1714   */
1715  function bp_get_max_thread_recipients_to_list() {
1716      /**
1717       * Filters the max number of recipients to list in the 'Conversation between...' gloss.
1718       *
1719       * @since 2.3.0
1720       *
1721       * @param int $count Recipient count. Default: 5.
1722       */
1723      return (int) apply_filters( 'bp_get_max_thread_recipients_to_list', 5 );
1724  }
1725  
1726  /**
1727   * Output HTML links to recipients in the current thread.
1728   *
1729   * @since 2.2.0
1730   */
1731  function bp_the_thread_recipients_list() {
1732      echo bp_get_thread_recipients_list();
1733  }
1734      /**
1735       * Generate HTML links to the profiles of recipients in the current thread.
1736       *
1737       * @since 2.2.0
1738       *
1739       * @return string
1740       */
1741  	function bp_get_thread_recipients_list() {
1742          global $thread_template;
1743  
1744          $recipient_links = array();
1745  
1746          foreach( (array) $thread_template->thread->recipients as $recipient ) {
1747              if ( (int) $recipient->user_id !== bp_loggedin_user_id() ) {
1748                  $recipient_link = bp_core_get_userlink( $recipient->user_id );
1749  
1750                  if ( empty( $recipient_link ) ) {
1751                      $recipient_link = __( 'Deleted User', 'buddypress' );
1752                  }
1753  
1754                  $recipient_links[] = $recipient_link;
1755              } else {
1756                  $recipient_links[] = __( 'you', 'buddypress' );
1757              }
1758          }
1759  
1760          // Concatenate to natural language string.
1761          $recipient_links = wp_sprintf_l( '%l', $recipient_links );
1762  
1763          /**
1764           * Filters the HTML links to the profiles of recipients in the current thread.
1765           *
1766           * @since 2.2.0
1767           *
1768           * @param string $value Comma-separated list of recipient HTML links for current thread.
1769           */
1770          return apply_filters( 'bp_get_the_thread_recipients_list', $recipient_links );
1771      }
1772  
1773  /**
1774   * Echo the ID of the current message in the thread.
1775   *
1776   * @since 1.9.0
1777   */
1778  function bp_the_thread_message_id() {
1779      echo (int) bp_get_the_thread_message_id();
1780  }
1781      /**
1782       * Get the ID of the current message in the thread.
1783       *
1784       * @since 1.9.0
1785       *
1786       * @return int
1787       */
1788  	function bp_get_the_thread_message_id() {
1789          global $thread_template;
1790  
1791          $thread_message_id = isset( $thread_template->message->id )
1792              ? (int) $thread_template->message->id
1793              : null;
1794  
1795          /**
1796           * Filters the ID of the current message in the thread.
1797           *
1798           * @since 1.9.0
1799           *
1800           * @param int $thread_message_id ID of the current message in the thread.
1801           */
1802          return apply_filters( 'bp_get_the_thread_message_id', $thread_message_id );
1803      }
1804  
1805  /**
1806   * Output the CSS classes for messages within a single thread.
1807   *
1808   * @since 2.1.0
1809   */
1810  function bp_the_thread_message_css_class() {
1811      echo esc_attr( bp_get_the_thread_message_css_class() );
1812  }
1813      /**
1814       * Generate the CSS classes for messages within a single thread.
1815       *
1816       * @since 2.1.0
1817       *
1818       * @return string
1819       */
1820  	function bp_get_the_thread_message_css_class() {
1821          global $thread_template;
1822  
1823          $classes = array();
1824  
1825          // Zebra-striping.
1826          $classes[] = bp_get_the_thread_message_alt_class();
1827  
1828          // ID of the sender.
1829          $classes[] = 'sent-by-' . intval( $thread_template->message->sender_id );
1830  
1831          // Whether the sender is the same as the logged-in user.
1832          if ( bp_loggedin_user_id() == $thread_template->message->sender_id ) {
1833              $classes[] = 'sent-by-me';
1834          }
1835  
1836          /**
1837           * Filters the CSS classes for messages within a single thread.
1838           *
1839           * @since 2.1.0
1840           *
1841           * @param array $classes Array of classes to add to the HTML class attribute.
1842           */
1843          $classes = apply_filters( 'bp_get_the_thread_message_css_class', $classes );
1844  
1845          return implode( ' ', $classes );
1846      }
1847  
1848  /**
1849   * Output the CSS class used for message zebra striping.
1850   */
1851  function bp_the_thread_message_alt_class() {
1852      echo esc_attr( bp_get_the_thread_message_alt_class() );
1853  }
1854      /**
1855       * Get the CSS class used for message zebra striping.
1856       *
1857       * @return string
1858       */
1859  	function bp_get_the_thread_message_alt_class() {
1860          global $thread_template;
1861  
1862          if ( $thread_template->current_message % 2 == 1 ) {
1863              $class = 'even alt';
1864          } else {
1865              $class = 'odd';
1866          }
1867  
1868          /**
1869           * Filters the CSS class used for message zebra striping.
1870           *
1871           * @since 1.1.0
1872           *
1873           * @param string $class Class determined to be next for zebra striping effect.
1874           */
1875          return apply_filters( 'bp_get_the_thread_message_alt_class', $class );
1876      }
1877  
1878  /**
1879   * Output the ID for message sender within a single thread.
1880   *
1881   * @since 2.1.0
1882   */
1883  function bp_the_thread_message_sender_id() {
1884      echo (int) bp_get_the_thread_message_sender_id();
1885  }
1886      /**
1887       * Return the ID for message sender within a single thread.
1888       *
1889       * @since 2.1.0
1890       *
1891       * @return int
1892       */
1893  	function bp_get_the_thread_message_sender_id() {
1894          global $thread_template;
1895  
1896          $user_id = ! empty( $thread_template->message->sender_id )
1897              ? $thread_template->message->sender_id
1898              : 0;
1899  
1900          /**
1901           * Filters the ID for message sender within a single thread.
1902           *
1903           * @since 2.1.0
1904           *
1905           * @param int $user_id ID of the message sender.
1906           */
1907          return (int) apply_filters( 'bp_get_the_thread_message_sender_id', (int) $user_id );
1908      }
1909  
1910  /**
1911   * Output the avatar for the current message sender.
1912   *
1913   * @param array|string $args See {@link bp_get_the_thread_message_sender_avatar_thumb()}
1914   *                           for a description.
1915   */
1916  function bp_the_thread_message_sender_avatar( $args = '' ) {
1917      echo bp_get_the_thread_message_sender_avatar_thumb( $args );
1918  }
1919      /**
1920       * Get the avatar for the current message sender.
1921       *
1922       * @param array|string $args {
1923       *     Array of arguments. See {@link bp_core_fetch_avatar()} for more
1924       *     complete details. All arguments are optional.
1925       *     @type string $type   Avatar type. Default: 'thumb'.
1926       *     @type int    $width  Avatar width. Default: default for your $type.
1927       *     @type int    $height Avatar height. Default: default for your $type.
1928       * }
1929       * @return string <img> tag containing the avatar.
1930       */
1931  	function bp_get_the_thread_message_sender_avatar_thumb( $args = '' ) {
1932          global $thread_template;
1933  
1934          $r = bp_parse_args( $args, array(
1935              'type'   => 'thumb',
1936              'width'  => false,
1937              'height' => false,
1938          ) );
1939  
1940          /**
1941           * Filters the avatar for the current message sender.
1942           *
1943           * @since 1.1.0
1944           * @since 2.6.0 Added the `$r` parameter.
1945           *
1946           * @param string $value <img> tag containing the avatar value.
1947           * @param array  $r     Array of parsed arguments.
1948           */
1949          return apply_filters( 'bp_get_the_thread_message_sender_avatar_thumb', bp_core_fetch_avatar( array(
1950              'item_id' => $thread_template->message->sender_id,
1951              'type'    => $r['type'],
1952              'width'   => $r['width'],
1953              'height'  => $r['height'],
1954              'alt'     => bp_core_get_user_displayname( $thread_template->message->sender_id )
1955          ) ), $r );
1956      }
1957  
1958  /**
1959   * Output a link to the sender of the current message.
1960   *
1961   * @since 1.1.0
1962   */
1963  function bp_the_thread_message_sender_link() {
1964      echo esc_url( bp_get_the_thread_message_sender_link() );
1965  }
1966      /**
1967       * Get a link to the sender of the current message.
1968       *
1969       * @since 1.1.0
1970       *
1971       * @return string
1972       */
1973  	function bp_get_the_thread_message_sender_link() {
1974          global $thread_template;
1975  
1976          /**
1977           * Filters the link to the sender of the current message.
1978           *
1979           * @since 1.1.0
1980           *
1981           * @param string $value Link to the sender of the current message.
1982           */
1983          return apply_filters( 'bp_get_the_thread_message_sender_link', bp_core_get_userlink( $thread_template->message->sender_id, false, true ) );
1984      }
1985  
1986  /**
1987   * Output the display name of the sender of the current message.
1988   *
1989   * @since 1.1.0
1990   */
1991  function bp_the_thread_message_sender_name() {
1992      echo esc_html( bp_get_the_thread_message_sender_name() );
1993  }
1994      /**
1995       * Get the display name of the sender of the current message.
1996       *
1997       * @since 1.1.0
1998       *
1999       * @return string
2000       */
2001  	function bp_get_the_thread_message_sender_name() {
2002          global $thread_template;
2003  
2004          $display_name = bp_core_get_user_displayname( $thread_template->message->sender_id );
2005  
2006          if ( empty( $display_name ) ) {
2007              $display_name = __( 'Deleted User', 'buddypress' );
2008          }
2009  
2010          /**
2011           * Filters the display name of the sender of the current message.
2012           *
2013           * @since 1.1.0
2014           *
2015           * @param string $display_name Display name of the sender of the current message.
2016           */
2017          return apply_filters( 'bp_get_the_thread_message_sender_name', $display_name );
2018      }
2019  
2020  /**
2021   * Output the URL for deleting the current thread.
2022   *
2023   * @since 1.5.0
2024   */
2025  function bp_the_thread_delete_link() {
2026      echo esc_url( bp_get_the_thread_delete_link() );
2027  }
2028      /**
2029       * Get the URL for deleting the current thread.
2030       *
2031       * @since 1.5.0
2032       *
2033       * @return string URL
2034       */
2035  	function bp_get_the_thread_delete_link() {
2036  
2037          /**
2038           * Filters the URL for deleting the current thread.
2039           *
2040           * @since 1.0.0
2041           *
2042           * @param string $value URL for deleting the current thread.
2043           * @param string $value Text indicating action being executed.
2044           */
2045          return apply_filters( 'bp_get_message_thread_delete_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_messages_slug() . '/inbox/delete/' . bp_get_the_thread_id(), 'messages_delete_thread' ) );
2046      }
2047  
2048  /**
2049   * Output the 'Sent x hours ago' string for the current message.
2050   *
2051   * @since 1.1.0
2052   */
2053  function bp_the_thread_message_time_since() {
2054      echo bp_get_the_thread_message_time_since();
2055  }
2056      /**
2057       * Generate the 'Sent x hours ago' string for the current message.
2058       *
2059       * @since 1.1.0
2060       *
2061       * @return string
2062       */
2063  	function bp_get_the_thread_message_time_since() {
2064  
2065          /**
2066           * Filters the 'Sent x hours ago' string for the current message.
2067           *
2068           * @since 1.1.0
2069           *
2070           * @param string $value Default text of 'Sent x hours ago'.
2071           */
2072          return apply_filters(
2073              'bp_get_the_thread_message_time_since',
2074              sprintf(
2075                  /* translators: %s: last activity timestamp (e.g. "active 1 hour ago") */
2076                  __( 'Sent %s', 'buddypress' ),
2077                  bp_core_time_since( bp_get_the_thread_message_date_sent() )
2078              )
2079          );
2080      }
2081  
2082  /**
2083   * Output the timestamp for the current message.
2084   *
2085   * @since 2.1.0
2086   */
2087  function bp_the_thread_message_date_sent() {
2088      echo bp_get_the_thread_message_date_sent();
2089  }
2090      /**
2091       * Generate the 'Sent x hours ago' string for the current message.
2092       *
2093       * @since 2.1.0
2094       *
2095       *
2096       * @return int
2097       */
2098  	function bp_get_the_thread_message_date_sent() {
2099          global $thread_template;
2100  
2101          /**
2102           * Filters the date sent value for the current message as a timestamp.
2103           *
2104           * @since 2.1.0
2105           *
2106           * @param string $value Timestamp of the date sent value for the current message.
2107           */
2108          return apply_filters( 'bp_get_the_thread_message_date_sent', strtotime( $thread_template->message->date_sent ) );
2109      }
2110  
2111  /**
2112   * Output the content of the current message in the loop.
2113   *
2114   * @since 1.1.0
2115   */
2116  function bp_the_thread_message_content() {
2117      echo bp_get_the_thread_message_content();
2118  }
2119      /**
2120       * Get the content of the current message in the loop.
2121       *
2122       * @since 1.1.0
2123       *
2124       * @return string
2125       */
2126  	function bp_get_the_thread_message_content() {
2127          global $thread_template;
2128  
2129          $content = $thread_template->message->message;
2130  
2131          // If user was deleted, mark content as deleted.
2132          if ( false === bp_core_get_core_userdata( bp_get_the_thread_message_sender_id() ) ) {
2133              $content = esc_html__( '[deleted]', 'buddypress' );
2134          }
2135  
2136          /**
2137           * Filters the content of the current message in the loop.
2138           *
2139           * @since 1.1.0
2140           *
2141           * @param string $message The content of the current message in the loop.
2142           */
2143          return apply_filters( 'bp_get_the_thread_message_content', $content );
2144      }
2145  
2146  /** Embeds *******************************************************************/
2147  
2148  /**
2149   * Enable oEmbed support for Messages.
2150   *
2151   * @since 1.5.0
2152   *
2153   * @see BP_Embed
2154   */
2155  function bp_messages_embed() {
2156      add_filter( 'embed_post_id',         'bp_get_the_thread_message_id' );
2157      add_filter( 'bp_embed_get_cache',    'bp_embed_message_cache',      10, 3 );
2158      add_action( 'bp_embed_update_cache', 'bp_embed_message_save_cache', 10, 3 );
2159  }
2160  add_action( 'thread_loop_start', 'bp_messages_embed' );
2161  
2162  /**
2163   * Fetch a private message item's cached embeds.
2164   *
2165   * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}.
2166   *
2167   * @since 2.2.0
2168   *
2169   * @param string $cache    An empty string passed by BP_Embed::parse_oembed() for
2170   *                         functions like this one to filter.
2171   * @param int    $id       The ID of the message item.
2172   * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
2173   * @return mixed The cached embeds for this message item.
2174   */
2175  function bp_embed_message_cache( $cache, $id, $cachekey ) {
2176      return bp_messages_get_meta( $id, $cachekey );
2177  }
2178  
2179  /**
2180   * Set a private message item's embed cache.
2181   *
2182   * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}.
2183   *
2184   * @since 2.2.0
2185   *
2186   * @param string $cache    An empty string passed by BP_Embed::parse_oembed() for
2187   *                         functions like this one to filter.
2188   * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
2189   * @param int    $id       The ID of the message item.
2190   */
2191  function bp_embed_message_save_cache( $cache, $cachekey, $id ) {
2192      bp_messages_update_meta( $id, $cachekey, $cache );
2193  }


Generated: Thu Apr 9 01:01:38 2020 Cross-referenced by PHPXref 0.7.1