/bp-messages/bp-messages-template.php

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