/bp-friends/bp-friends-template.php

  1. <?php 
  2. /** 
  3. * BuddyPress Friends Template Functions. 
  4. * 
  5. * @package BuddyPress 
  6. * @subpackage FriendsTemplate 
  7. * @since 1.5.0 
  8. */ 
  9.  
  10. // Exit if accessed directly. 
  11. defined( 'ABSPATH' ) || exit; 
  12.  
  13. /** 
  14. * Output the friends component slug. 
  15. * 
  16. * @since 1.5.0 
  17. * 
  18. */ 
  19. function bp_friends_slug() { 
  20. echo bp_get_friends_slug(); 
  21. /** 
  22. * Return the friends component slug. 
  23. * 
  24. * @since 1.5.0 
  25. * 
  26. * @return string 
  27. */ 
  28. function bp_get_friends_slug() { 
  29.  
  30. /** 
  31. * Filters the friends component slug. 
  32. * 
  33. * @since 1.5.0 
  34. * 
  35. * @param string $value Friends component slug. 
  36. */ 
  37. return apply_filters( 'bp_get_friends_slug', buddypress()->friends->slug ); 
  38.  
  39. /** 
  40. * Output the friends component root slug. 
  41. * 
  42. * @since 1.5.0 
  43. * 
  44. */ 
  45. function bp_friends_root_slug() { 
  46. echo bp_get_friends_root_slug(); 
  47. /** 
  48. * Return the friends component root slug. 
  49. * 
  50. * @since 1.5.0 
  51. * 
  52. * @return string 
  53. */ 
  54. function bp_get_friends_root_slug() { 
  55.  
  56. /** 
  57. * Filters the friends component root slug. 
  58. * 
  59. * @since 1.5.0 
  60. * 
  61. * @param string $value Friends component root slug. 
  62. */ 
  63. return apply_filters( 'bp_get_friends_root_slug', buddypress()->friends->root_slug ); 
  64.  
  65. /** 
  66. * Output a block of random friends. 
  67. * 
  68. * No longer used in BuddyPress. 
  69. * 
  70. * @todo Deprecate 
  71. */ 
  72. function bp_friends_random_friends() { 
  73.  
  74. if ( !$friend_ids = wp_cache_get( 'friends_friend_ids_' . bp_displayed_user_id(), 'bp' ) ) { 
  75. $friend_ids = BP_Friends_Friendship::get_random_friends( bp_displayed_user_id() ); 
  76. wp_cache_set( 'friends_friend_ids_' . bp_displayed_user_id(), $friend_ids, 'bp' ); 
  77. } ?> 
  78.  
  79. <div class="info-group"> 
  80. <h4><?php bp_word_or_name( __( "My Friends", 'buddypress' ), __( "%s's Friends", 'buddypress' ) ) ?> (<?php echo BP_Friends_Friendship::total_friend_count( bp_displayed_user_id() ) ?>) <span><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() ) ?>"><?php _e('See All', 'buddypress') ?></a></span></h4> 
  81.  
  82. <?php if ( $friend_ids ) { ?> 
  83.  
  84. <ul class="horiz-gallery"> 
  85.  
  86. <?php for ( $i = 0, $count = count( $friend_ids ); $i < $count; ++$i ) { ?> 
  87.  
  88. <li> 
  89. <a href="<?php echo bp_core_get_user_domain( $friend_ids[$i] ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $friend_ids[$i], 'type' => 'thumb' ) ) ?></a> 
  90. <h5><?php echo bp_core_get_userlink($friend_ids[$i]) ?></h5> 
  91. </li> 
  92.  
  93. <?php } ?> 
  94.  
  95. </ul> 
  96.  
  97. <?php } else { ?> 
  98.  
  99. <div id="message" class="info"> 
  100. <p><?php bp_word_or_name( __( "You haven't added any friend connections yet.", 'buddypress' ), __( "%s hasn't created any friend connections yet.", 'buddypress' ) ) ?></p> 
  101. </div> 
  102.  
  103. <?php } ?> 
  104.  
  105. <div class="clear"></div> 
  106. </div> 
  107.  
  108. <?php 
  109.  
  110. /** 
  111. * Pull up a group of random members, and display some profile data about them. 
  112. * 
  113. * This function is no longer used by BuddyPress core. 
  114. * 
  115. * @todo Deprecate 
  116. * 
  117. * @param int $total_members The number of members to retrieve. 
  118. */ 
  119. function bp_friends_random_members( $total_members = 5 ) { 
  120.  
  121. if ( !$user_ids = wp_cache_get( 'friends_random_users', 'bp' ) ) { 
  122. $user_ids = BP_Core_User::get_users( 'random', $total_members ); 
  123. wp_cache_set( 'friends_random_users', $user_ids, 'bp' ); 
  124.  
  125. ?> 
  126.  
  127. <?php if ( $user_ids['users'] ) { ?> 
  128.  
  129. <ul class="item-list" id="random-members-list"> 
  130.  
  131. <?php for ( $i = 0, $count = count( $user_ids['users'] ); $i < $count; ++$i ) { ?> 
  132.  
  133. <li> 
  134. <a href="<?php echo bp_core_get_user_domain( $user_ids['users'][$i]->id ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $user_ids['users'][$i]->id, 'type' => 'thumb' ) ) ?></a> 
  135. <h5><?php echo bp_core_get_userlink( $user_ids['users'][$i]->id ) ?></h5> 
  136.  
  137. <?php if ( bp_is_active( 'xprofile' ) ) { ?> 
  138.  
  139. <?php $random_data = xprofile_get_random_profile_data( $user_ids['users'][$i]->id, true ); ?> 
  140.  
  141. <div class="profile-data"> 
  142. <p class="field-name"><?php echo $random_data[0]->name ?></p> 
  143.  
  144. <?php echo $random_data[0]->value ?> 
  145.  
  146. </div> 
  147.  
  148. <?php } ?> 
  149.  
  150. <div class="action"> 
  151.  
  152. <?php if ( bp_is_active( 'friends' ) ) { ?> 
  153.  
  154. <?php bp_add_friend_button( $user_ids['users'][$i]->id ) ?> 
  155.  
  156. <?php } ?> 
  157.  
  158. </div> 
  159. </li> 
  160.  
  161. <?php } ?> 
  162.  
  163. </ul> 
  164.  
  165. <?php } else { ?> 
  166.  
  167. <div id="message" class="info"> 
  168. <p><?php _e( "There aren't enough site members to show a random sample just yet.", 'buddypress' ) ?></p> 
  169. </div> 
  170.  
  171. <?php } ?> 
  172. <?php 
  173.  
  174. /** 
  175. * Display a Friends search form. 
  176. * 
  177. * No longer used in BuddyPress. 
  178. * 
  179. * @todo Deprecate 
  180. */ 
  181. function bp_friend_search_form() { 
  182.  
  183. $action = bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/search/'; 
  184. $label = __( 'Filter Friends', 'buddypress' ); ?> 
  185.  
  186. <form action="<?php echo $action ?>" id="friend-search-form" method="post"> 
  187.  
  188. <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label> 
  189. <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> /> 
  190.  
  191. <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?> 
  192.  
  193. <input type="hidden" name="initiator" id="initiator" value="<?php echo esc_attr( bp_displayed_user_id() ) ?>" /> 
  194.  
  195. </form> 
  196.  
  197. <?php 
  198.  
  199. /** 
  200. * Output the "Add Friend" button in the member loop. 
  201. * 
  202. * @since 1.2.6 
  203. */ 
  204. function bp_member_add_friend_button() { 
  205. bp_add_friend_button( bp_get_member_user_id() ); 
  206. add_action( 'bp_directory_members_actions', 'bp_member_add_friend_button' ); 
  207.  
  208. /** 
  209. * Output the friend count for the current member in the loop. 
  210. * 
  211. * @since 1.2.0 
  212. */ 
  213. function bp_member_total_friend_count() { 
  214. echo bp_get_member_total_friend_count(); 
  215. /** 
  216. * Return the friend count for the current member in the loop. 
  217. * 
  218. * Return value is a string of the form "x friends". 
  219. * 
  220. * @since 1.2.0 
  221. * 
  222. * @return string A string of the form "x friends". 
  223. */ 
  224. function bp_get_member_total_friend_count() { 
  225. global $members_template; 
  226.  
  227. if ( 1 == (int) $members_template->member->total_friend_count ) { 
  228.  
  229. /** 
  230. * Filters text used to denote total friend count. 
  231. * 
  232. * @since 1.2.0 
  233. * 
  234. * @param string $value String of the form "x friends". 
  235. * @param int $value Total friend count for current member in the loop. 
  236. */ 
  237. return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friend', 'buddypress' ), (int) $members_template->member->total_friend_count ) ); 
  238. } else { 
  239.  
  240. /** This filter is documented in bp-friends/bp-friends-template.php */ 
  241. return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friends', 'buddypress' ), (int) $members_template->member->total_friend_count ) ); 
  242.  
  243. /** 
  244. * Output the ID of the current user in the friend request loop. 
  245. * 
  246. * @since 1.2.6 
  247. * 
  248. * @see bp_get_potential_friend_id() for a description of arguments. 
  249. * 
  250. * @param int $user_id See {@link bp_get_potential_friend_id()}. 
  251. */ 
  252. function bp_potential_friend_id( $user_id = 0 ) { 
  253. echo bp_get_potential_friend_id( $user_id ); 
  254. /** 
  255. * Return the ID of current user in the friend request loop. 
  256. * 
  257. * @since 1.2.6 
  258. * 
  259. * @global object $friends_template 
  260. * 
  261. * @param int $user_id Optional. If provided, the function will simply 
  262. * return this value. 
  263. * @return int ID of potential friend. 
  264. */ 
  265. function bp_get_potential_friend_id( $user_id = 0 ) { 
  266. global $friends_template; 
  267.  
  268. if ( empty( $user_id ) && isset( $friends_template->friendship->friend ) ) 
  269. $user_id = $friends_template->friendship->friend->id; 
  270. elseif ( empty( $user_id ) && !isset( $friends_template->friendship->friend ) ) 
  271. $user_id = bp_displayed_user_id(); 
  272.  
  273. /** 
  274. * Filters the ID of current user in the friend request loop. 
  275. * 
  276. * @since 1.2.10 
  277. * 
  278. * @param int $user_id ID of current user in the friend request loop. 
  279. */ 
  280. return apply_filters( 'bp_get_potential_friend_id', (int) $user_id ); 
  281.  
  282. /** 
  283. * Check whether a given user is a friend of the logged-in user. 
  284. * 
  285. * Returns - 'is_friend', 'not_friends', 'pending'. 
  286. * 
  287. * @since 1.2.6 
  288. * 
  289. * @param int $user_id ID of the potential friend. Default: the value of 
  290. * {@link bp_get_potential_friend_id()}. 
  291. * @return string 'is_friend', 'not_friends', or 'pending'. 
  292. */ 
  293. function bp_is_friend( $user_id = 0 ) { 
  294.  
  295. if ( !is_user_logged_in() ) 
  296. return false; 
  297.  
  298. if ( empty( $user_id ) ) 
  299. $user_id = bp_get_potential_friend_id( $user_id ); 
  300.  
  301. if ( bp_loggedin_user_id() == $user_id ) 
  302. return false; 
  303.  
  304. /** 
  305. * Filters the status of friendship between logged in user and given user. 
  306. * 
  307. * @since 1.2.10 
  308. * 
  309. * @param string $value String status of friendship. Possible values are 'is_friend', 'not_friends', 'pending'. 
  310. */ 
  311. return apply_filters( 'bp_is_friend', friends_check_friendship_status( bp_loggedin_user_id(), $user_id ), $user_id ); 
  312.  
  313. /** 
  314. * Output the Add Friend button. 
  315. * 
  316. * @since 1.0.0 
  317. * 
  318. * @see bp_get_add_friend_button() for information on arguments. 
  319. * 
  320. * @param int $potential_friend_id See {@link bp_get_add_friend_button()}. 
  321. * @param int|bool $friend_status See {@link bp_get_add_friend_button()}. 
  322. */ 
  323. function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false ) { 
  324. echo bp_get_add_friend_button( $potential_friend_id, $friend_status ); 
  325. /** 
  326. * Create the Add Friend button. 
  327. * 
  328. * @since 1.1.0 
  329. * 
  330. * @param int $potential_friend_id ID of the user to whom the button 
  331. * applies. Default: value of {@link bp_get_potential_friend_id()}. 
  332. * @param bool $friend_status Not currently used. 
  333. * @return string HTML for the Add Friend button. 
  334. */ 
  335. function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) { 
  336.  
  337. if ( empty( $potential_friend_id ) ) 
  338. $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id ); 
  339.  
  340. $is_friend = bp_is_friend( $potential_friend_id ); 
  341.  
  342. if ( empty( $is_friend ) ) 
  343. return false; 
  344.  
  345. switch ( $is_friend ) { 
  346. case 'pending' : 
  347. $button = array( 
  348. 'id' => 'pending',  
  349. 'component' => 'friends',  
  350. 'must_be_logged_in' => true,  
  351. 'block_self' => true,  
  352. 'wrapper_class' => 'friendship-button pending_friend',  
  353. 'wrapper_id' => 'friendship-button-' . $potential_friend_id,  
  354. 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' ),  
  355. 'link_text' => __( 'Cancel Friendship Request', 'buddypress' ),  
  356. 'link_id' => 'friend-' . $potential_friend_id,  
  357. 'link_rel' => 'remove',  
  358. 'link_class' => 'friendship-button pending_friend requested' 
  359. ); 
  360. break; 
  361.  
  362. case 'awaiting_response' : 
  363. $button = array( 
  364. 'id' => 'awaiting_response',  
  365. 'component' => 'friends',  
  366. 'must_be_logged_in' => true,  
  367. 'block_self' => true,  
  368. 'wrapper_class' => 'friendship-button awaiting_response_friend',  
  369. 'wrapper_id' => 'friendship-button-' . $potential_friend_id,  
  370. 'link_href' => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/',  
  371. 'link_text' => __( 'Friendship Requested', 'buddypress' ),  
  372. 'link_id' => 'friend-' . $potential_friend_id,  
  373. 'link_rel' => 'remove',  
  374. 'link_class' => 'friendship-button awaiting_response_friend requested' 
  375. ); 
  376. break; 
  377.  
  378. case 'is_friend' : 
  379. $button = array( 
  380. 'id' => 'is_friend',  
  381. 'component' => 'friends',  
  382. 'must_be_logged_in' => true,  
  383. 'block_self' => false,  
  384. 'wrapper_class' => 'friendship-button is_friend',  
  385. 'wrapper_id' => 'friendship-button-' . $potential_friend_id,  
  386. 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ),  
  387. 'link_text' => __( 'Cancel Friendship', 'buddypress' ),  
  388. 'link_id' => 'friend-' . $potential_friend_id,  
  389. 'link_rel' => 'remove',  
  390. 'link_class' => 'friendship-button is_friend remove' 
  391. ); 
  392. break; 
  393.  
  394. default: 
  395. $button = array( 
  396. 'id' => 'not_friends',  
  397. 'component' => 'friends',  
  398. 'must_be_logged_in' => true,  
  399. 'block_self' => true,  
  400. 'wrapper_class' => 'friendship-button not_friends',  
  401. 'wrapper_id' => 'friendship-button-' . $potential_friend_id,  
  402. 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ),  
  403. 'link_text' => __( 'Add Friend', 'buddypress' ),  
  404. 'link_id' => 'friend-' . $potential_friend_id,  
  405. 'link_rel' => 'add',  
  406. 'link_class' => 'friendship-button not_friends add' 
  407. ); 
  408. break; 
  409.  
  410. /** 
  411. * Filters the HTML for the add friend button. 
  412. * 
  413. * @since 1.1.0 
  414. * 
  415. * @param string $button HTML markup for add friend button. 
  416. */ 
  417. return bp_get_button( apply_filters( 'bp_get_add_friend_button', $button ) ); 
  418.  
  419. /** 
  420. * Get a comma-separated list of IDs of a user's friends. 
  421. * 
  422. * @since 1.2.0 
  423. * 
  424. * @param int $user_id Optional. Default: the displayed user's ID, or the 
  425. * logged-in user's ID. 
  426. * @return string|bool A comma-separated list of friend IDs if any are found,  
  427. * otherwise false. 
  428. */ 
  429. function bp_get_friend_ids( $user_id = 0 ) { 
  430.  
  431. if ( empty( $user_id ) ) 
  432. $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id(); 
  433.  
  434. $friend_ids = friends_get_friend_user_ids( $user_id ); 
  435.  
  436. if ( empty( $friend_ids ) ) 
  437. return false; 
  438.  
  439. return implode( ', ', friends_get_friend_user_ids( $user_id ) ); 
  440.  
  441. /** 
  442. * Get a user's friendship requests. 
  443. * 
  444. * Note that we return a 0 if no pending requests are found. This is necessary 
  445. * because of the structure of the $include parameter in bp_has_members(). 
  446. * 
  447. * @since 1.2.0 
  448. * 
  449. * @param int $user_id ID of the user whose requests are being retrieved. 
  450. * Defaults to displayed user. 
  451. * @return array|int An array of user IDs if found, or a 0 if none are found. 
  452. */ 
  453. function bp_get_friendship_requests( $user_id = 0 ) { 
  454. if ( !$user_id ) { 
  455. $user_id = bp_displayed_user_id(); 
  456.  
  457. if ( !$user_id ) { 
  458. return 0; 
  459.  
  460. $requests = friends_get_friendship_request_user_ids( $user_id ); 
  461.  
  462. if ( !empty( $requests ) ) { 
  463. $requests = implode( ', ', (array) $requests ); 
  464. } else { 
  465. $requests = 0; 
  466.  
  467. /** 
  468. * Filters the total pending friendship requests for a user. 
  469. * 
  470. * @since 1.2.0 
  471. * @since 2.6.0 Added the `$user_id` parameter. 
  472. * 
  473. * @param array|int $requests An array of user IDs if found, or a 0 if none are found. 
  474. * @param int $user_id ID of the queried user. 
  475. */ 
  476. return apply_filters( 'bp_get_friendship_requests', $requests, $user_id ); 
  477.  
  478. /** 
  479. * Output the ID of the friendship between the logged-in user and the current user in the loop. 
  480. * 
  481. * @since 1.2.0 
  482. */ 
  483. function bp_friend_friendship_id() { 
  484. echo bp_get_friend_friendship_id(); 
  485. /** 
  486. * Return the ID of the friendship between the logged-in user and the current user in the loop. 
  487. * 
  488. * @since 1.2.0 
  489. * 
  490. * @return int ID of the friendship. 
  491. */ 
  492. function bp_get_friend_friendship_id() { 
  493. global $members_template; 
  494.  
  495. if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) { 
  496. $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() ); 
  497. wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' ); 
  498.  
  499. /** 
  500. * Filters the ID of the friendship between the logged in user and the current user in the loop. 
  501. * 
  502. * @since 1.2.0 
  503. * 
  504. * @param int $friendship_id ID of the friendship. 
  505. */ 
  506. return apply_filters( 'bp_get_friend_friendship_id', $friendship_id ); 
  507.  
  508. /** 
  509. * Output the URL for accepting the current friendship request in the loop. 
  510. * 
  511. * @since 1.0.0 
  512. */ 
  513. function bp_friend_accept_request_link() { 
  514. echo bp_get_friend_accept_request_link(); 
  515. /** 
  516. * Return the URL for accepting the current friendship request in the loop. 
  517. * 
  518. * @since 1.0.0 
  519. * 
  520. * @return string accept-friendship URL. 
  521. */ 
  522. function bp_get_friend_accept_request_link() { 
  523. global $members_template; 
  524.  
  525. if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) { 
  526. $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() ); 
  527. wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' ); 
  528.  
  529. /** 
  530. * Filters the URL for accepting the current friendship request in the loop. 
  531. * 
  532. * @since 1.0.0 
  533. * @since 2.6.0 Added the `$friendship_id` parameter. 
  534. * 
  535. * @param string $value Accept-friendship URL. 
  536. * @param int $friendship_id ID of the friendship. 
  537. */ 
  538. return apply_filters( 'bp_get_friend_accept_request_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/accept/' . $friendship_id, 'friends_accept_friendship' ), $friendship_id ); 
  539.  
  540. /** 
  541. * Output the URL for rejecting the current friendship request in the loop. 
  542. * 
  543. * @since 1.0.0 
  544. */ 
  545. function bp_friend_reject_request_link() { 
  546. echo bp_get_friend_reject_request_link(); 
  547. /** 
  548. * Return the URL for rejecting the current friendship request in the loop. 
  549. * 
  550. * @since 1.0.0 
  551. * 
  552. * @return string reject-friendship URL. 
  553. */ 
  554. function bp_get_friend_reject_request_link() { 
  555. global $members_template; 
  556.  
  557. if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) { 
  558. $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() ); 
  559. wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' ); 
  560.  
  561. /** 
  562. * Filters the URL for rejecting the current friendship request in the loop. 
  563. * 
  564. * @since 1.0.0 
  565. * @since 2.6.0 Added the `$friendship_id` parameter. 
  566. * 
  567. * @param string $value Reject-friendship URL. 
  568. * @param int $friendship_id ID of the friendship. 
  569. */ 
  570. return apply_filters( 'bp_get_friend_reject_request_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/reject/' . $friendship_id, 'friends_reject_friendship' ), $friendship_id ); 
  571.  
  572. /** 
  573. * Output the total friend count for a given user. 
  574. * 
  575. * @since 1.2.0 
  576. * 
  577. * @param int $user_id See {@link friends_get_total_friend_count()}. 
  578. */ 
  579. function bp_total_friend_count( $user_id = 0 ) { 
  580. echo bp_get_total_friend_count( $user_id ); 
  581. /** 
  582. * Return the total friend count for a given user. 
  583. * 
  584. * @since 1.2.0 
  585. * 
  586. * @param int $user_id See {@link friends_get_total_friend_count()}. 
  587. * @return int Total friend count. 
  588. */ 
  589. function bp_get_total_friend_count( $user_id = 0 ) { 
  590.  
  591. /** 
  592. * Filters the total friend count for a given user. 
  593. * 
  594. * @since 1.2.0 
  595. * @since 2.6.0 Added the `$user_id` parameter. 
  596. * 
  597. * @param int $value Total friend count. 
  598. * @param int $user_id ID of the queried user. 
  599. */ 
  600. return apply_filters( 'bp_get_total_friend_count', friends_get_total_friend_count( $user_id ), $user_id ); 
  601. add_filter( 'bp_get_total_friend_count', 'bp_core_number_format' ); 
  602.  
  603. /** 
  604. * Output the total friendship request count for a given user. 
  605. * 
  606. * @since 1.2.0 
  607. * 
  608. * @see bp_friend_get_total_requests_count() for description of arguments. 
  609. * 
  610. * @param int $user_id See {@link bp_friend_get_total_requests_count(). 
  611. */ 
  612. function bp_friend_total_requests_count( $user_id = 0 ) { 
  613. echo bp_friend_get_total_requests_count( $user_id ); 
  614. /** 
  615. * Return the total friendship request count for a given user. 
  616. * 
  617. * @since 1.2.0 
  618. * 
  619. * @param int $user_id ID of the user whose requests are being counted. 
  620. * Default: ID of the logged-in user. 
  621. * @return int Friend count. 
  622. */ 
  623. function bp_friend_get_total_requests_count( $user_id = 0 ) { 
  624. if ( empty( $user_id ) ) 
  625. $user_id = bp_loggedin_user_id(); 
  626.  
  627. /** 
  628. * Filters the total friendship request count for a given user. 
  629. * 
  630. * @since 1.2.0 
  631. * @since 2.6.0 Added the `$user_id` parameter. 
  632. * 
  633. * @param int $value Friendship request count. 
  634. * @param int $user_id ID of the queried user. 
  635. */ 
  636. return apply_filters( 'bp_friend_get_total_requests_count', count( BP_Friends_Friendship::get_friend_user_ids( $user_id, true ) ), $user_id ); 
  637.  
  638. /** Stats **********************************************************************/ 
  639.  
  640. /** 
  641. * Display the number of friends in user's profile. 
  642. * 
  643. * @since 2.0.0 
  644. * 
  645. * @param array|string $args before|after|user_id. 
  646. */ 
  647. function bp_friends_profile_stats( $args = '' ) { 
  648. echo bp_friends_get_profile_stats( $args ); 
  649. add_action( 'bp_members_admin_user_stats', 'bp_friends_profile_stats', 7, 1 ); 
  650.  
  651. /** 
  652. * Return the number of friends in user's profile. 
  653. * 
  654. * @since 2.0.0 
  655. * 
  656. * @param array|string $args before|after|user_id. 
  657. * @return string HTML for stats output. 
  658. */ 
  659. function bp_friends_get_profile_stats( $args = '' ) { 
  660.  
  661. // Parse the args. 
  662. $r = bp_parse_args( $args, array( 
  663. 'before' => '<li class="bp-friends-profile-stats">',  
  664. 'after' => '</li>',  
  665. 'user_id' => bp_displayed_user_id(),  
  666. 'friends' => 0,  
  667. 'output' => '' 
  668. ), 'friends_get_profile_stats' ); 
  669.  
  670. // Allow completely overloaded output. 
  671. if ( empty( $r['output'] ) ) { 
  672.  
  673. // Only proceed if a user ID was passed. 
  674. if ( ! empty( $r['user_id'] ) ) { 
  675.  
  676. // Get the user's friends. 
  677. if ( empty( $r['friends'] ) ) { 
  678. $r['friends'] = absint( friends_get_total_friend_count( $r['user_id'] ) ); 
  679.  
  680. // If friends exist, show some formatted output. 
  681. $r['output'] = $r['before'] . sprintf( _n( '%s friend', '%s friends', $r['friends'], 'buddypress' ), '<strong>' . $r['friends'] . '</strong>' ) . $r['after']; 
  682.  
  683. /** 
  684. * Filters the number of friends in user's profile. 
  685. * 
  686. * @since 2.0.0 
  687. * 
  688. * @param string $value Formatted string displaying total friends count. 
  689. * @param array $r Array of arguments for string formatting and output. 
  690. */ 
  691. return apply_filters( 'bp_friends_get_profile_stats', $r['output'], $r ); 
.