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