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


Generated: Mon Sep 27 01:00:56 2021 Cross-referenced by PHPXref 0.7.1