/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 wp_nonce_field( 'bp_messages_mark_messages_read', 'mark-messages-read-nonce', false ); ?> 
  886. <?php wp_nonce_field( 'bp_messages_mark_messages_unread', 'mark-messages-unread-nonce', false ); ?> 
  887.  
  888. <?php endif; ?> 
  889.  
  890. <a href="#" id="delete_<?php echo bp_current_action(); ?>_messages"><?php _e( 'Delete Selected', 'buddypress' ); ?></a>   
  891. <?php wp_nonce_field( 'bp_messages_delete_selected', 'delete-selected-nonce', false ); ?> 
  892. <?php 
  893.  
  894. /** 
  895. * Output the dropdown for bulk management of messages. 
  896. * 
  897. * @since 2.2.0 
  898. */ 
  899. function bp_messages_bulk_management_dropdown() { 
  900. ?> 
  901. <label class="bp-screen-reader-text" for="messages-select"><?php 
  902. _e( 'Select Bulk Action', 'buddypress' ); 
  903. ?></label> 
  904. <select name="messages_bulk_action" id="messages-select"> 
  905. <option value="" selected="selected"><?php _e( 'Bulk Actions', 'buddypress' ); ?></option> 
  906. <option value="read"><?php _e( 'Mark read', 'buddypress' ); ?></option> 
  907. <option value="unread"><?php _e( 'Mark unread', 'buddypress' ); ?></option> 
  908. <option value="delete"><?php _e( 'Delete', 'buddypress' ); ?></option> 
  909. <?php 
  910. /** 
  911. * Action to add additional options to the messages bulk management dropdown. 
  912. * 
  913. * @since 2.3.0 
  914. */ 
  915. do_action( 'bp_messages_bulk_management_dropdown' ); 
  916. ?> 
  917. </select> 
  918. <input type="submit" id="messages-bulk-manage" class="button action" value="<?php esc_attr_e( 'Apply', 'buddypress' ); ?>"> 
  919. <?php 
  920.  
  921. /** 
  922. * Return whether or not the notice is currently active. 
  923. * 
  924. * @since 1.6.0 
  925. * 
  926. * @return bool 
  927. */ 
  928. function bp_messages_is_active_notice() { 
  929. global $messages_template; 
  930.  
  931. $retval = ! empty( $messages_template->thread->is_active ) 
  932. ? true 
  933. : false; 
  934.  
  935. /** 
  936. * Filters whether or not the notice is currently active. 
  937. * 
  938. * @since 2.1.0 
  939. * 
  940. * @param bool $retval Whether or not the notice is currently active. 
  941. */ 
  942. return apply_filters( 'bp_messages_is_active_notice', $retval ); 
  943.  
  944. /** 
  945. * Output a string for the active notice. 
  946. * 
  947. * Since 1.6 this function has been deprecated in favor of text in the theme. 
  948. * 
  949. * @since 1.0.0 
  950. * @deprecated 1.6.0 
  951. * @return bool 
  952. */ 
  953. function bp_message_is_active_notice() { 
  954. echo bp_get_message_is_active_notice(); 
  955. /** 
  956. * Returns a string for the active notice. 
  957. * 
  958. * Since 1.6 this function has been deprecated in favor of text in the 
  959. * theme. 
  960. * 
  961. * @since 1.0.0 
  962. * @deprecated 1.6.0 
  963. */ 
  964. function bp_get_message_is_active_notice() { 
  965.  
  966. $string = bp_messages_is_active_notice() 
  967. ? __( 'Currently Active', 'buddypress' ) 
  968. : ''; 
  969.  
  970. return apply_filters( 'bp_get_message_is_active_notice', $string ); 
  971.  
  972. /** 
  973. * Output the ID of the current notice in the loop. 
  974. */ 
  975. function bp_message_notice_id() { 
  976. echo (int) bp_get_message_notice_id(); 
  977. /** 
  978. * Get the ID of the current notice in the loop. 
  979. * 
  980. * @return int 
  981. */ 
  982. function bp_get_message_notice_id() { 
  983. global $messages_template; 
  984.  
  985. /** 
  986. * Filters the ID of the current notice in the loop. 
  987. * 
  988. * @since 1.5.0 
  989. * 
  990. * @param int $id ID of the current notice in the loop. 
  991. */ 
  992. return apply_filters( 'bp_get_message_notice_id', $messages_template->thread->id ); 
  993.  
  994. /** 
  995. * Output the post date of the current notice in the loop. 
  996. */ 
  997. function bp_message_notice_post_date() { 
  998. echo bp_get_message_notice_post_date(); 
  999. /** 
  1000. * Get the post date of the current notice in the loop. 
  1001. * 
  1002. * @return string 
  1003. */ 
  1004. function bp_get_message_notice_post_date() { 
  1005. global $messages_template; 
  1006.  
  1007. /** 
  1008. * Filters the post date of the current notice in the loop. 
  1009. * 
  1010. * @since 1.0.0 
  1011. * 
  1012. * @param string $value Formatted post date of the current notice in the loop. 
  1013. */ 
  1014. return apply_filters( 'bp_get_message_notice_post_date', bp_format_time( strtotime( $messages_template->thread->date_sent ) ) ); 
  1015.  
  1016. /** 
  1017. * Output the subject of the current notice in the loop. 
  1018. */ 
  1019. function bp_message_notice_subject() { 
  1020. echo bp_get_message_notice_subject(); 
  1021. /** 
  1022. * Get the subject of the current notice in the loop. 
  1023. * 
  1024. * @return string 
  1025. */ 
  1026. function bp_get_message_notice_subject() { 
  1027. global $messages_template; 
  1028.  
  1029. /** 
  1030. * Filters the subject of the current notice in the loop. 
  1031. * 
  1032. * @since 1.0.0 
  1033. * 
  1034. * @param string $subject Subject of the current notice in the loop. 
  1035. */ 
  1036. return apply_filters( 'bp_get_message_notice_subject', $messages_template->thread->subject ); 
  1037.  
  1038. /** 
  1039. * Output the text of the current notice in the loop. 
  1040. */ 
  1041. function bp_message_notice_text() { 
  1042. echo bp_get_message_notice_text(); 
  1043. /** 
  1044. * Get the text of the current notice in the loop. 
  1045. * 
  1046. * @return string 
  1047. */ 
  1048. function bp_get_message_notice_text() { 
  1049. global $messages_template; 
  1050.  
  1051. /** 
  1052. * Filters the text of the current notice in the loop. 
  1053. * 
  1054. * @since 1.0.0 
  1055. * 
  1056. * @param string $message Text for the current notice in the loop. 
  1057. */ 
  1058. return apply_filters( 'bp_get_message_notice_text', $messages_template->thread->message ); 
  1059.  
  1060. /** 
  1061. * Output the URL for deleting the current notice. 
  1062. */ 
  1063. function bp_message_notice_delete_link() { 
  1064. echo esc_url( bp_get_message_notice_delete_link() ); 
  1065. /** 
  1066. * Get the URL for deleting the current notice. 
  1067. * 
  1068. * @return string Delete URL. 
  1069. */ 
  1070. function bp_get_message_notice_delete_link() { 
  1071. global $messages_template; 
  1072.  
  1073. /** 
  1074. * Filters the URL for deleting the current notice. 
  1075. * 
  1076. * @since 1.0.0 
  1077. * 
  1078. * @param string $value URL for deleting the current notice. 
  1079. * @param string $value Text indicating action being executed. 
  1080. */ 
  1081. 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' ) ); 
  1082.  
  1083. /** 
  1084. * Output the URL for deactivating the current notice. 
  1085. */ 
  1086. function bp_message_activate_deactivate_link() { 
  1087. echo esc_url( bp_get_message_activate_deactivate_link() ); 
  1088. /** 
  1089. * Get the URL for deactivating the current notice. 
  1090. * 
  1091. * @return string 
  1092. */ 
  1093. function bp_get_message_activate_deactivate_link() { 
  1094. global $messages_template; 
  1095.  
  1096. if ( 1 === (int) $messages_template->thread->is_active ) { 
  1097. $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/deactivate/' . $messages_template->thread->id ), 'messages_deactivate_notice' ); 
  1098. } else { 
  1099. $link = wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices/activate/' . $messages_template->thread->id ), 'messages_activate_notice' ); 
  1100.  
  1101. /** 
  1102. * Filters the URL for deactivating the current notice. 
  1103. * 
  1104. * @since 1.0.0 
  1105. * 
  1106. * @param string $link URL for deactivating the current notice. 
  1107. */ 
  1108. return apply_filters( 'bp_get_message_activate_deactivate_link', $link ); 
  1109.  
  1110. /** 
  1111. * Output the Deactivate/Activate text for the notice action link. 
  1112. */ 
  1113. function bp_message_activate_deactivate_text() { 
  1114. echo esc_html( bp_get_message_activate_deactivate_text() ); 
  1115. /** 
  1116. * Generate the text ('Deactivate' or 'Activate') for the notice action link. 
  1117. * 
  1118. * @return string 
  1119. */ 
  1120. function bp_get_message_activate_deactivate_text() { 
  1121. global $messages_template; 
  1122.  
  1123. if ( 1 === (int) $messages_template->thread->is_active ) { 
  1124. $text = __('Deactivate', 'buddypress'); 
  1125. } else { 
  1126. $text = __('Activate', 'buddypress'); 
  1127.  
  1128. /** 
  1129. * Filters the "Deactivate" or "Activate" text for notice action links. 
  1130. * 
  1131. * @since 1.0.0 
  1132. * 
  1133. * @param string $text Text used for notice action links. 
  1134. */ 
  1135. return apply_filters( 'bp_message_activate_deactivate_text', $text ); 
  1136.  
  1137. /** 
  1138. * Output the messages component slug. 
  1139. * 
  1140. * @since 1.5.0 
  1141. * 
  1142. */ 
  1143. function bp_messages_slug() { 
  1144. echo bp_get_messages_slug(); 
  1145. /** 
  1146. * Return the messages component slug. 
  1147. * 
  1148. * @since 1.5.0 
  1149. * 
  1150. * @return string 
  1151. */ 
  1152. function bp_get_messages_slug() { 
  1153.  
  1154. /** 
  1155. * Filters the messages component slug. 
  1156. * 
  1157. * @since 1.5.0 
  1158. * 
  1159. * @param string $slug Messages component slug. 
  1160. */ 
  1161. return apply_filters( 'bp_get_messages_slug', buddypress()->messages->slug ); 
  1162.  
  1163. /** 
  1164. * Generate markup for currently active notices. 
  1165. */ 
  1166. function bp_message_get_notices() { 
  1167. $notice = BP_Messages_Notice::get_active(); 
  1168.  
  1169. if ( empty( $notice ) ) { 
  1170. return false; 
  1171.  
  1172. $closed_notices = bp_get_user_meta( bp_loggedin_user_id(), 'closed_notices', true ); 
  1173.  
  1174. if ( empty( $closed_notices ) ) { 
  1175. $closed_notices = array(); 
  1176.  
  1177. if ( is_array( $closed_notices ) ) { 
  1178. if ( !in_array( $notice->id, $closed_notices ) && $notice->id ) { 
  1179. ?> 
  1180. <div id="message" class="info notice" rel="n-<?php echo esc_attr( $notice->id ); ?>"> 
  1181. <p> 
  1182. <strong><?php echo stripslashes( wp_filter_kses( $notice->subject ) ) ?></strong><br /> 
  1183. <?php echo stripslashes( wp_filter_kses( $notice->message) ) ?> 
  1184. <a href="#" id="close-notice"><?php _e( 'Close', 'buddypress' ) ?></a> 
  1185. <?php wp_nonce_field( 'bp_messages_close_notice', 'close-notice-nonce' ); ?> 
  1186. </p> 
  1187. </div> 
  1188. <?php 
  1189.  
  1190. /** 
  1191. * Output the URL for the Private Message link in member profile headers. 
  1192. */ 
  1193. function bp_send_private_message_link() { 
  1194. echo esc_url( bp_get_send_private_message_link() ); 
  1195. /** 
  1196. * Generate the URL for the Private Message link in member profile headers. 
  1197. * 
  1198. * @return bool|string False on failure, otherwise the URL. 
  1199. */ 
  1200. function bp_get_send_private_message_link() { 
  1201.  
  1202. if ( bp_is_my_profile() || ! is_user_logged_in() ) { 
  1203. return false; 
  1204.  
  1205. /** 
  1206. * Filters the URL for the Private Message link in member profile headers. 
  1207. * 
  1208. * @since 1.2.10 
  1209. * 
  1210. * @param string $value URL for the Private Message link in member profile headers. 
  1211. */ 
  1212. 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() ) ) ); 
  1213.  
  1214. /** 
  1215. * Output the 'Private Message' button for member profile headers. 
  1216. * 
  1217. * Explicitly named function to avoid confusion with public messages. 
  1218. * 
  1219. * @since 1.2.6 
  1220. * 
  1221. */ 
  1222. function bp_send_private_message_button() { 
  1223. echo bp_get_send_message_button(); 
  1224.  
  1225. /** 
  1226. * Output the 'Private Message' button for member profile headers. 
  1227. */ 
  1228. function bp_send_message_button() { 
  1229. echo bp_get_send_message_button(); 
  1230. /** 
  1231. * Generate the 'Private Message' button for member profile headers. 
  1232. * 
  1233. * @return string 
  1234. */ 
  1235. function bp_get_send_message_button() { 
  1236. // Note: 'bp_get_send_message_button' is a legacy filter. Use 
  1237. // 'bp_get_send_message_button_args' instead. See #4536. 
  1238. return apply_filters( 'bp_get_send_message_button',  
  1239.  
  1240. /** 
  1241. * Filters the "Private Message" button for member profile headers. 
  1242. * 
  1243. * @since 1.8.0 
  1244. * 
  1245. * @param array $value See {@link BP_Button}. 
  1246. */ 
  1247. bp_get_button( apply_filters( 'bp_get_send_message_button_args', array( 
  1248. 'id' => 'private_message',  
  1249. 'component' => 'messages',  
  1250. 'must_be_logged_in' => true,  
  1251. 'block_self' => true,  
  1252. 'wrapper_id' => 'send-private-message',  
  1253. 'link_href' => bp_get_send_private_message_link(),  
  1254. 'link_text' => __( 'Private Message', 'buddypress' ),  
  1255. 'link_class' => 'send-message',  
  1256. ) ) ) 
  1257. ); 
  1258.  
  1259. /** 
  1260. * Output the URL of the Messages AJAX loader gif. 
  1261. */ 
  1262. function bp_message_loading_image_src() { 
  1263. echo esc_url( bp_get_message_loading_image_src() ); 
  1264. /** 
  1265. * Get the URL of the Messages AJAX loader gif. 
  1266. * 
  1267. * @return string 
  1268. */ 
  1269. function bp_get_message_loading_image_src() { 
  1270.  
  1271. /** 
  1272. * Filters the URL of the Messages AJAX loader gif. 
  1273. * 
  1274. * @since 1.0.0 
  1275. * 
  1276. * @param string $value URL of the Messages AJAX loader gif. 
  1277. */ 
  1278. return apply_filters( 'bp_get_message_loading_image_src', buddypress()->messages->image_base . '/ajax-loader.gif' ); 
  1279.  
  1280. /** 
  1281. * Output the markup for the message recipient tabs. 
  1282. */ 
  1283. function bp_message_get_recipient_tabs() { 
  1284. $recipients = explode( ' ', bp_get_message_get_recipient_usernames() ); 
  1285.  
  1286. foreach ( $recipients as $recipient ) { 
  1287.  
  1288. $user_id = bp_is_username_compatibility_mode() 
  1289. ? bp_core_get_userid( $recipient ) 
  1290. : bp_core_get_userid_from_nicename( $recipient ); 
  1291.  
  1292. if ( ! empty( $user_id ) ) : ?> 
  1293.  
  1294. <li id="un-<?php echo esc_attr( $recipient ); ?>" class="friend-tab"> 
  1295. <span><?php 
  1296. echo bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15 ) ); 
  1297. echo bp_core_get_userlink( $user_id ); 
  1298. ?></span> 
  1299. </li> 
  1300.  
  1301. <?php endif; 
  1302.  
  1303. /** 
  1304. * Output recipient usernames for prefilling the 'To' field on the Compose screen. 
  1305. */ 
  1306. function bp_message_get_recipient_usernames() { 
  1307. echo esc_attr( bp_get_message_get_recipient_usernames() ); 
  1308. /** 
  1309. * Get the recipient usernames for prefilling the 'To' field on the Compose screen. 
  1310. * 
  1311. * @return string 
  1312. */ 
  1313. function bp_get_message_get_recipient_usernames() { 
  1314.  
  1315. // Sanitized in bp-messages-filters.php. 
  1316. $recipients = isset( $_GET['r'] ) 
  1317. ? $_GET['r'] 
  1318. : ''; 
  1319.  
  1320. /** 
  1321. * Filters the recipients usernames for prefilling the 'To' field on the Compose screen. 
  1322. * 
  1323. * @since 1.0.0 
  1324. * 
  1325. * @param string $recipients Recipients usernames for 'To' field prefilling. 
  1326. */ 
  1327. return apply_filters( 'bp_get_message_get_recipient_usernames', $recipients ); 
  1328.  
  1329. /** 
  1330. * Initialize the messages template loop for a specific thread. 
  1331. * 
  1332. * @param array|string $args { 
  1333. * Array of arguments. All are optional. 
  1334. * @type int $thread_id ID of the thread whose messages you are displaying. 
  1335. * Default: if viewing a thread, the thread ID will be parsed from 
  1336. * the URL (bp_action_variable( 0 )). 
  1337. * @type string $order 'ASC' or 'DESC'. Default: 'ASC'. 
  1338. * @type bool $update_meta_cache Whether to pre-fetch metadata for 
  1339. * queried message items. Default: true. 
  1340. * } 
  1341. * @return bool True if there are messages to display, otherwise false. 
  1342. */ 
  1343. function bp_thread_has_messages( $args = '' ) { 
  1344. global $thread_template; 
  1345.  
  1346. $r = bp_parse_args( $args, array( 
  1347. 'thread_id' => false,  
  1348. 'order' => 'ASC',  
  1349. 'update_meta_cache' => true,  
  1350. ), 'thread_has_messages' ); 
  1351.  
  1352. if ( empty( $r['thread_id'] ) && bp_is_messages_component() && bp_is_current_action( 'view' ) ) { 
  1353. $r['thread_id'] = (int) bp_action_variable( 0 ); 
  1354.  
  1355. // Set up extra args. 
  1356. $extra_args = $r; 
  1357. unset( $extra_args['thread_id'], $extra_args['order'] ); 
  1358.  
  1359. $thread_template = new BP_Messages_Thread_Template( $r['thread_id'], $r['order'], $extra_args ); 
  1360.  
  1361. return $thread_template->has_messages(); 
  1362.  
  1363. /** 
  1364. * Output the 'ASC' or 'DESC' messages order string for this loop. 
  1365. */ 
  1366. function bp_thread_messages_order() { 
  1367. echo esc_attr( bp_get_thread_messages_order() ); 
  1368. /** 
  1369. * Get the 'ASC' or 'DESC' messages order string for this loop. 
  1370. * 
  1371. * @return string 
  1372. */ 
  1373. function bp_get_thread_messages_order() { 
  1374. global $thread_template; 
  1375. return $thread_template->thread->messages_order; 
  1376.  
  1377. /** 
  1378. * Check whether there are more messages to iterate over. 
  1379. * 
  1380. * @return bool 
  1381. */ 
  1382. function bp_thread_messages() { 
  1383. global $thread_template; 
  1384.  
  1385. return $thread_template->messages(); 
  1386.  
  1387. /** 
  1388. * Set up the current thread inside the loop. 
  1389. * 
  1390. * @return object 
  1391. */ 
  1392. function bp_thread_the_message() { 
  1393. global $thread_template; 
  1394.  
  1395. return $thread_template->the_message(); 
  1396.  
  1397. /** 
  1398. * Output the ID of the thread that the current loop belongs to. 
  1399. */ 
  1400. function bp_the_thread_id() { 
  1401. echo (int) bp_get_the_thread_id(); 
  1402. /** 
  1403. * Get the ID of the thread that the current loop belongs to. 
  1404. * 
  1405. * @return int 
  1406. */ 
  1407. function bp_get_the_thread_id() { 
  1408. global $thread_template; 
  1409.  
  1410. /** 
  1411. * Filters the ID of the thread that the current loop belongs to. 
  1412. * 
  1413. * @since 1.1.0 
  1414. * 
  1415. * @param int $thread_id ID of the thread. 
  1416. */ 
  1417. return apply_filters( 'bp_get_the_thread_id', $thread_template->thread->thread_id ); 
  1418.  
  1419. /** 
  1420. * Output the subject of the thread currently being iterated over. 
  1421. */ 
  1422. function bp_the_thread_subject() { 
  1423. echo bp_get_the_thread_subject(); 
  1424. /** 
  1425. * Get the subject of the thread currently being iterated over. 
  1426. * 
  1427. * @return string 
  1428. */ 
  1429. function bp_get_the_thread_subject() { 
  1430. global $thread_template; 
  1431.  
  1432. /** 
  1433. * Filters the subject of the thread currently being iterated over. 
  1434. * 
  1435. * @since 1.1.0 
  1436. * 
  1437. * @return string $last_message_subject Subject of the thread currently being iterated over. 
  1438. */ 
  1439. return apply_filters( 'bp_get_the_thread_subject', $thread_template->thread->last_message_subject ); 
  1440.  
  1441. /** 
  1442. * Get a list of thread recipients or a "x recipients" string. 
  1443. * 
  1444. * In BuddyPress 2.2.0, this parts of this functionality were moved into the 
  1445. * members/single/messages/single.php template. This function is no longer used 
  1446. * by BuddyPress. 
  1447. * 
  1448. * @return string 
  1449. */ 
  1450. function bp_get_the_thread_recipients() { 
  1451. if ( 5 <= bp_get_thread_recipients_count() ) { 
  1452. $recipients = sprintf( __( '%s recipients', 'buddypress' ), number_format_i18n( bp_get_thread_recipients_count() ) ); 
  1453. } else { 
  1454. $recipients = bp_get_thread_recipients_list(); 
  1455.  
  1456. return apply_filters( 'bp_get_the_thread_recipients', $recipients ); 
  1457.  
  1458. /** 
  1459. * Get the number of recipients in the current thread. 
  1460. * 
  1461. * @since 2.2.0 
  1462. * 
  1463. * @return int 
  1464. */ 
  1465. function bp_get_thread_recipients_count() { 
  1466. global $thread_template; 
  1467. /** 
  1468. * Filters the total number of recipients in a thread. 
  1469. * 
  1470. * @since 2.8.0 
  1471. * 
  1472. * @param int $count Total recipients number. 
  1473. */ 
  1474. return (int) apply_filters( 'bp_get_thread_recipients_count', count( $thread_template->thread->recipients ) ); 
  1475.  
  1476. /** 
  1477. * Get the max number of recipients to list in the 'Conversation between...' gloss. 
  1478. * 
  1479. * @since 2.3.0 
  1480. * 
  1481. * @return int 
  1482. */ 
  1483. function bp_get_max_thread_recipients_to_list() { 
  1484. /** 
  1485. * Filters the max number of recipients to list in the 'Conversation between...' gloss. 
  1486. * 
  1487. * @since 2.3.0 
  1488. * 
  1489. * @param int $count Recipient count. Default: 5. 
  1490. */ 
  1491. return (int) apply_filters( 'bp_get_max_thread_recipients_to_list', 5 ); 
  1492.  
  1493. /** 
  1494. * Output HTML links to recipients in the current thread. 
  1495. * 
  1496. * @since 2.2.0 
  1497. */ 
  1498. function bp_the_thread_recipients_list() { 
  1499. echo bp_get_thread_recipients_list(); 
  1500. /** 
  1501. * Generate HTML links to the profiles of recipients in the current thread. 
  1502. * 
  1503. * @since 2.2.0 
  1504. * 
  1505. * @return string 
  1506. */ 
  1507. function bp_get_thread_recipients_list() { 
  1508. global $thread_template; 
  1509.  
  1510. $recipient_links = array(); 
  1511.  
  1512. foreach( (array) $thread_template->thread->recipients as $recipient ) { 
  1513. if ( (int) $recipient->user_id !== bp_loggedin_user_id() ) { 
  1514. $recipient_link = bp_core_get_userlink( $recipient->user_id ); 
  1515.  
  1516. if ( empty( $recipient_link ) ) { 
  1517. $recipient_link = __( 'Deleted User', 'buddypress' ); 
  1518.  
  1519. $recipient_links[] = $recipient_link; 
  1520.  
  1521. /** 
  1522. * Filters the HTML links to the profiles of recipients in the current thread. 
  1523. * 
  1524. * @since 2.2.0 
  1525. * 
  1526. * @param string $value Comma-separated list of recipient HTML links for current thread. 
  1527. */ 
  1528. return apply_filters( 'bp_get_the_thread_recipients_list', implode( ', ', $recipient_links ) ); 
  1529.  
  1530. /** 
  1531. * Echo the ID of the current message in the thread. 
  1532. * 
  1533. * @since 1.9.0 
  1534. */ 
  1535. function bp_the_thread_message_id() { 
  1536. echo (int) bp_get_the_thread_message_id(); 
  1537. /** 
  1538. * Get the ID of the current message in the thread. 
  1539. * 
  1540. * @since 1.9.0 
  1541. * 
  1542. * @return int 
  1543. */ 
  1544. function bp_get_the_thread_message_id() { 
  1545. global $thread_template; 
  1546.  
  1547. $thread_message_id = isset( $thread_template->message->id ) 
  1548. ? (int) $thread_template->message->id 
  1549. : null; 
  1550.  
  1551. /** 
  1552. * Filters the ID of the current message in the thread. 
  1553. * 
  1554. * @since 1.9.0 
  1555. * 
  1556. * @param int $thread_message_id ID of the current message in the thread. 
  1557. */ 
  1558. return apply_filters( 'bp_get_the_thread_message_id', $thread_message_id ); 
  1559.  
  1560. /** 
  1561. * Output the CSS classes for messages within a single thread. 
  1562. * 
  1563. * @since 2.1.0 
  1564. */ 
  1565. function bp_the_thread_message_css_class() { 
  1566. echo esc_attr( bp_get_the_thread_message_css_class() ); 
  1567. /** 
  1568. * Generate the CSS classes for messages within a single thread. 
  1569. * 
  1570. * @since 2.1.0 
  1571. * 
  1572. * @return string 
  1573. */ 
  1574. function bp_get_the_thread_message_css_class() { 
  1575. global $thread_template; 
  1576.  
  1577. $classes = array(); 
  1578.  
  1579. // Zebra-striping. 
  1580. $classes[] = bp_get_the_thread_message_alt_class(); 
  1581.  
  1582. // ID of the sender. 
  1583. $classes[] = 'sent-by-' . intval( $thread_template->message->sender_id ); 
  1584.  
  1585. // Whether the sender is the same as the logged-in user. 
  1586. if ( bp_loggedin_user_id() == $thread_template->message->sender_id ) { 
  1587. $classes[] = 'sent-by-me'; 
  1588.  
  1589. /** 
  1590. * Filters the CSS classes for messages within a single thread. 
  1591. * 
  1592. * @since 2.1.0 
  1593. * 
  1594. * @param array $classes Array of classes to add to the HTML class attribute. 
  1595. */ 
  1596. $classes = apply_filters( 'bp_get_the_thread_message_css_class', $classes ); 
  1597.  
  1598. return implode( ' ', $classes ); 
  1599.  
  1600. /** 
  1601. * Output the CSS class used for message zebra striping. 
  1602. */ 
  1603. function bp_the_thread_message_alt_class() { 
  1604. echo esc_attr( bp_get_the_thread_message_alt_class() ); 
  1605. /** 
  1606. * Get the CSS class used for message zebra striping. 
  1607. * 
  1608. * @return string 
  1609. */ 
  1610. function bp_get_the_thread_message_alt_class() { 
  1611. global $thread_template; 
  1612.  
  1613. if ( $thread_template->current_message % 2 == 1 ) { 
  1614. $class = 'even alt'; 
  1615. } else { 
  1616. $class = 'odd'; 
  1617.  
  1618. /** 
  1619. * Filters the CSS class used for message zebra striping. 
  1620. * 
  1621. * @since 1.1.0 
  1622. * 
  1623. * @param string $class Class determined to be next for zebra striping effect. 
  1624. */ 
  1625. return apply_filters( 'bp_get_the_thread_message_alt_class', $class ); 
  1626.  
  1627. /** 
  1628. * Output the ID for message sender within a single thread. 
  1629. * 
  1630. * @since 2.1.0 
  1631. */ 
  1632. function bp_the_thread_message_sender_id() { 
  1633. echo (int) bp_get_the_thread_message_sender_id(); 
  1634. /** 
  1635. * Return the ID for message sender within a single thread. 
  1636. * 
  1637. * @since 2.1.0 
  1638. * 
  1639. * @return string 
  1640. */ 
  1641. function bp_get_the_thread_message_sender_id() { 
  1642. global $thread_template; 
  1643.  
  1644. $user_id = ! empty( $thread_template->message->sender_id ) 
  1645. ? $thread_template->message->sender_id 
  1646. : 0; 
  1647.  
  1648. /** 
  1649. * Filters the ID for message sender within a single thread. 
  1650. * 
  1651. * @since 2.1.0 
  1652. * 
  1653. * @param int $user_id ID of the message sender. 
  1654. */ 
  1655. return (int) apply_filters( 'bp_get_the_thread_message_sender_id', (int) $user_id ); 
  1656.  
  1657. /** 
  1658. * Output the avatar for the current message sender. 
  1659. * 
  1660. * @param array|string $args See {@link bp_get_the_thread_message_sender_avatar_thumb()} 
  1661. * for a description. 
  1662. */ 
  1663. function bp_the_thread_message_sender_avatar( $args = '' ) { 
  1664. echo bp_get_the_thread_message_sender_avatar_thumb( $args ); 
  1665. /** 
  1666. * Get the avatar for the current message sender. 
  1667. * 
  1668. * @param array|string $args { 
  1669. * Array of arguments. See {@link bp_core_fetch_avatar()} for more 
  1670. * complete details. All arguments are optional. 
  1671. * @type string $type Avatar type. Default: 'thumb'. 
  1672. * @type int $width Avatar width. Default: default for your $type. 
  1673. * @type int $height Avatar height. Default: default for your $type. 
  1674. * } 
  1675. * @return string <img> tag containing the avatar. 
  1676. */ 
  1677. function bp_get_the_thread_message_sender_avatar_thumb( $args = '' ) { 
  1678. global $thread_template; 
  1679.  
  1680. $r = bp_parse_args( $args, array( 
  1681. 'type' => 'thumb',  
  1682. 'width' => false,  
  1683. 'height' => false,  
  1684. ) ); 
  1685.  
  1686. /** 
  1687. * Filters the avatar for the current message sender. 
  1688. * 
  1689. * @since 1.1.0 
  1690. * @since 2.6.0 Added the `$r` parameter. 
  1691. * 
  1692. * @param string $value <img> tag containing the avatar value. 
  1693. * @param array $r Array of parsed arguments. 
  1694. */ 
  1695. return apply_filters( 'bp_get_the_thread_message_sender_avatar_thumb', bp_core_fetch_avatar( array( 
  1696. 'item_id' => $thread_template->message->sender_id,  
  1697. 'type' => $r['type'],  
  1698. 'width' => $r['width'],  
  1699. 'height' => $r['height'],  
  1700. 'alt' => bp_core_get_user_displayname( $thread_template->message->sender_id ) 
  1701. ) ), $r ); 
  1702.  
  1703. /** 
  1704. * Output a link to the sender of the current message. 
  1705. * 
  1706. * @since 1.1.0 
  1707. */ 
  1708. function bp_the_thread_message_sender_link() { 
  1709. echo esc_url( bp_get_the_thread_message_sender_link() ); 
  1710. /** 
  1711. * Get a link to the sender of the current message. 
  1712. * 
  1713. * @since 1.1.0 
  1714. * 
  1715. * @return string 
  1716. */ 
  1717. function bp_get_the_thread_message_sender_link() { 
  1718. global $thread_template; 
  1719.  
  1720. /** 
  1721. * Filters the link to the sender of the current message. 
  1722. * 
  1723. * @since 1.1.0 
  1724. * 
  1725. * @param string $value Link to the sender of the current message. 
  1726. */ 
  1727. return apply_filters( 'bp_get_the_thread_message_sender_link', bp_core_get_userlink( $thread_template->message->sender_id, false, true ) ); 
  1728.  
  1729. /** 
  1730. * Output the display name of the sender of the current message. 
  1731. * 
  1732. * @since 1.1.0 
  1733. */ 
  1734. function bp_the_thread_message_sender_name() { 
  1735. echo esc_html( bp_get_the_thread_message_sender_name() ); 
  1736. /** 
  1737. * Get the display name of the sender of the current message. 
  1738. * 
  1739. * @since 1.1.0 
  1740. * 
  1741. * @return string 
  1742. */ 
  1743. function bp_get_the_thread_message_sender_name() { 
  1744. global $thread_template; 
  1745.  
  1746. $display_name = bp_core_get_user_displayname( $thread_template->message->sender_id ); 
  1747.  
  1748. if ( empty( $display_name ) ) { 
  1749. $display_name = __( 'Deleted User', 'buddypress' ); 
  1750.  
  1751. /** 
  1752. * Filters the display name of the sender of the current message. 
  1753. * 
  1754. * @since 1.1.0 
  1755. * 
  1756. * @param string $display_name Display name of the sender of the current message. 
  1757. */ 
  1758. return apply_filters( 'bp_get_the_thread_message_sender_name', $display_name ); 
  1759.  
  1760. /** 
  1761. * Output the URL for deleting the current thread. 
  1762. * 
  1763. * @since 1.5.0 
  1764. */ 
  1765. function bp_the_thread_delete_link() { 
  1766. echo esc_url( bp_get_the_thread_delete_link() ); 
  1767. /** 
  1768. * Get the URL for deleting the current thread. 
  1769. * 
  1770. * @since 1.5.0 
  1771. * 
  1772. * @return string URL 
  1773. */ 
  1774. function bp_get_the_thread_delete_link() { 
  1775.  
  1776. /** 
  1777. * Filters the URL for deleting the current thread. 
  1778. * 
  1779. * @since 1.0.0 
  1780. * 
  1781. * @param string $value URL for deleting the current thread. 
  1782. * @param string $value Text indicating action being executed. 
  1783. */ 
  1784. 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' ) ); 
  1785.  
  1786. /** 
  1787. * Output the 'Sent x hours ago' string for the current message. 
  1788. * 
  1789. * @since 1.1.0 
  1790. */ 
  1791. function bp_the_thread_message_time_since() { 
  1792. echo bp_get_the_thread_message_time_since(); 
  1793. /** 
  1794. * Generate the 'Sent x hours ago' string for the current message. 
  1795. * 
  1796. * @since 1.1.0 
  1797. * 
  1798. * @return string 
  1799. */ 
  1800. function bp_get_the_thread_message_time_since() { 
  1801.  
  1802. /** 
  1803. * Filters the 'Sent x hours ago' string for the current message. 
  1804. * 
  1805. * @since 1.1.0 
  1806. * 
  1807. * @param string $value Default text of 'Sent x hours ago'. 
  1808. */ 
  1809. 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() ) ) ); 
  1810.  
  1811. /** 
  1812. * Output the timestamp for the current message. 
  1813. * 
  1814. * @since 2.1.0 
  1815. */ 
  1816. function bp_the_thread_message_date_sent() { 
  1817. echo bp_get_the_thread_message_date_sent(); 
  1818. /** 
  1819. * Generate the 'Sent x hours ago' string for the current message. 
  1820. * 
  1821. * @since 2.1.0 
  1822. * 
  1823. * 
  1824. * @return int 
  1825. */ 
  1826. function bp_get_the_thread_message_date_sent() { 
  1827. global $thread_template; 
  1828.  
  1829. /** 
  1830. * Filters the date sent value for the current message as a timestamp. 
  1831. * 
  1832. * @since 2.1.0 
  1833. * 
  1834. * @param string $value Timestamp of the date sent value for the current message. 
  1835. */ 
  1836. return apply_filters( 'bp_get_the_thread_message_date_sent', strtotime( $thread_template->message->date_sent ) ); 
  1837.  
  1838. /** 
  1839. * Output the content of the current message in the loop. 
  1840. * 
  1841. * @since 1.1.0 
  1842. */ 
  1843. function bp_the_thread_message_content() { 
  1844. echo bp_get_the_thread_message_content(); 
  1845. /** 
  1846. * Get the content of the current message in the loop. 
  1847. * 
  1848. * @since 1.1.0 
  1849. * 
  1850. * @return string 
  1851. */ 
  1852. function bp_get_the_thread_message_content() { 
  1853. global $thread_template; 
  1854.  
  1855. /** 
  1856. * Filters the content of the current message in the loop. 
  1857. * 
  1858. * @since 1.1.0 
  1859. * 
  1860. * @param string $message The content of the current message in the loop. 
  1861. */ 
  1862. return apply_filters( 'bp_get_the_thread_message_content', $thread_template->message->message ); 
  1863.  
  1864. /** Embeds *******************************************************************/ 
  1865.  
  1866. /** 
  1867. * Enable oEmbed support for Messages. 
  1868. * 
  1869. * @since 1.5.0 
  1870. * 
  1871. * @see BP_Embed 
  1872. */ 
  1873. function bp_messages_embed() { 
  1874. add_filter( 'embed_post_id', 'bp_get_the_thread_message_id' ); 
  1875. add_filter( 'bp_embed_get_cache', 'bp_embed_message_cache', 10, 3 ); 
  1876. add_action( 'bp_embed_update_cache', 'bp_embed_message_save_cache', 10, 3 ); 
  1877. add_action( 'thread_loop_start', 'bp_messages_embed' ); 
  1878.  
  1879. /** 
  1880. * Fetch a private message item's cached embeds. 
  1881. * 
  1882. * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}. 
  1883. * 
  1884. * @since 2.2.0 
  1885. * 
  1886. * @param string $cache An empty string passed by BP_Embed::parse_oembed() for 
  1887. * functions like this one to filter. 
  1888. * @param int $id The ID of the message item. 
  1889. * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). 
  1890. * @return mixed The cached embeds for this message item. 
  1891. */ 
  1892. function bp_embed_message_cache( $cache, $id, $cachekey ) { 
  1893. return bp_messages_get_meta( $id, $cachekey ); 
  1894.  
  1895. /** 
  1896. * Set a private message item's embed cache. 
  1897. * 
  1898. * Used during {@link BP_Embed::parse_oembed()} via {@link bp_messages_embed()}. 
  1899. * 
  1900. * @since 2.2.0 
  1901. * 
  1902. * @param string $cache An empty string passed by BP_Embed::parse_oembed() for 
  1903. * functions like this one to filter. 
  1904. * @param string $cachekey The cache key generated in BP_Embed::parse_oembed(). 
  1905. * @param int $id The ID of the message item. 
  1906. */ 
  1907. function bp_embed_message_save_cache( $cache, $cachekey, $id ) { 
  1908. bp_messages_update_meta( $id, $cachekey, $cache ); 
.