/bp-members/bp-members-template.php

  1. <?php 
  2. /** 
  3. * BuddyPress Member Template Tags. 
  4. * 
  5. * Functions that are safe to use inside your template files and themes. 
  6. * 
  7. * @package BuddyPress 
  8. * @subpackage Members 
  9. * @since 1.5.0 
  10. */ 
  11.  
  12. // Exit if accessed directly. 
  13. defined( 'ABSPATH' ) || exit; 
  14.  
  15. if ( ! buddypress()->do_autoload ) { 
  16. require dirname( __FILE__ ) . '/classes/class-bp-core-members-template.php'; 
  17.  
  18. /** 
  19. * Output the profile component slug. 
  20. * 
  21. * @since 2.4.0 
  22. * 
  23. */ 
  24. function bp_profile_slug() { 
  25. echo bp_get_profile_slug(); 
  26. /** 
  27. * Return the profile component slug. 
  28. * 
  29. * @since 2.4.0 
  30. * 
  31. * @return string 
  32. */ 
  33. function bp_get_profile_slug() { 
  34.  
  35. /** 
  36. * Filters the profile component slug. 
  37. * 
  38. * @since 2.4.0 
  39. * 
  40. * @param string $slug Profile component slug. 
  41. */ 
  42. return apply_filters( 'bp_get_profile_slug', buddypress()->profile->slug ); 
  43.  
  44. /** 
  45. * Output the members component slug. 
  46. * 
  47. * @since 1.5.0 
  48. * 
  49. */ 
  50. function bp_members_slug() { 
  51. echo bp_get_members_slug(); 
  52. /** 
  53. * Return the members component slug. 
  54. * 
  55. * @since 1.5.0 
  56. * 
  57. * @return string 
  58. */ 
  59. function bp_get_members_slug() { 
  60.  
  61. /** 
  62. * Filters the Members component slug. 
  63. * 
  64. * @since 1.5.0 
  65. * 
  66. * @param string $slug Members component slug. 
  67. */ 
  68. return apply_filters( 'bp_get_members_slug', buddypress()->members->slug ); 
  69.  
  70. /** 
  71. * Output the members component root slug. 
  72. * 
  73. * @since 1.5.0 
  74. * 
  75. */ 
  76. function bp_members_root_slug() { 
  77. echo bp_get_members_root_slug(); 
  78. /** 
  79. * Return the members component root slug. 
  80. * 
  81. * @since 1.5.0 
  82. * 
  83. * @return string 
  84. */ 
  85. function bp_get_members_root_slug() { 
  86.  
  87. /** 
  88. * Filters the Members component root slug. 
  89. * 
  90. * @since 1.5.0 
  91. * 
  92. * @param string $slug Members component root slug. 
  93. */ 
  94. return apply_filters( 'bp_get_members_root_slug', buddypress()->members->root_slug ); 
  95.  
  96. /** 
  97. * Output the member type base slug. 
  98. * 
  99. * @since 2.5.0 
  100. */ 
  101. function bp_members_member_type_base() { 
  102. echo esc_url( bp_get_members_member_type_base() ); 
  103. /** 
  104. * Get the member type base slug. 
  105. * 
  106. * The base slug is the string used as the base prefix when generating member type directory URLs. 
  107. * For example, in example.com/members/type/foo/, 'foo' is the member type and 'type' is the 
  108. * base slug. 
  109. * 
  110. * @since 2.5.0 
  111. * 
  112. * @return string 
  113. */ 
  114. function bp_get_members_member_type_base() { 
  115. /** 
  116. * Filters the member type URL base. 
  117. * 
  118. * @since 2.3.0 
  119. * 
  120. * @param string $base 
  121. */ 
  122. return apply_filters( 'bp_members_member_type_base', _x( 'type', 'member type URL base', 'buddypress' ) ); 
  123.  
  124. /** 
  125. * Output member directory permalink. 
  126. * 
  127. * @since 1.5.0 
  128. * 
  129. */ 
  130. function bp_members_directory_permalink() { 
  131. echo esc_url( bp_get_members_directory_permalink() ); 
  132. /** 
  133. * Return member directory permalink. 
  134. * 
  135. * @since 1.5.0 
  136. * 
  137. * @return string 
  138. */ 
  139. function bp_get_members_directory_permalink() { 
  140.  
  141. /** 
  142. * Filters the member directory permalink. 
  143. * 
  144. * @since 1.5.0 
  145. * 
  146. * @param string $value Members directory permalink. 
  147. */ 
  148. return apply_filters( 'bp_get_members_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ) ); 
  149.  
  150. /** 
  151. * Output member type directory permalink. 
  152. * 
  153. * @since 2.5.0 
  154. * 
  155. * @param string $member_type Optional. Member type. 
  156. */ 
  157. function bp_member_type_directory_permalink( $member_type = '' ) { 
  158. echo esc_url( bp_get_member_type_directory_permalink( $member_type ) ); 
  159. /** 
  160. * Return member type directory permalink. 
  161. * 
  162. * @since 2.5.0 
  163. * 
  164. * @param string $member_type Optional. Member type. Defaults to current member type. 
  165. * @return string Member type directory URL on success, an empty string on failure. 
  166. */ 
  167. function bp_get_member_type_directory_permalink( $member_type = '' ) { 
  168.  
  169. if ( $member_type ) { 
  170. $_member_type = $member_type; 
  171. } else { 
  172. // Fall back on the current member type. 
  173. $_member_type = bp_get_current_member_type(); 
  174.  
  175. $type = bp_get_member_type_object( $_member_type ); 
  176.  
  177. // Bail when member type is not found or has no directory. 
  178. if ( ! $type || ! $type->has_directory ) { 
  179. return ''; 
  180.  
  181. /** 
  182. * Filters the member type directory permalink. 
  183. * 
  184. * @since 2.5.0 
  185. * 
  186. * @param string $value Member type directory permalink. 
  187. * @param object $type Member type object. 
  188. * @param string $member_type Member type name, as passed to the function. 
  189. */ 
  190. return apply_filters( 'bp_get_member_type_directory_permalink', trailingslashit( bp_get_members_directory_permalink() . bp_get_members_member_type_base() . '/' . $type->directory_slug ), $type, $member_type ); 
  191.  
  192. /** 
  193. * Output the sign-up slug. 
  194. * 
  195. * @since 1.5.0 
  196. * 
  197. */ 
  198. function bp_signup_slug() { 
  199. echo bp_get_signup_slug(); 
  200. /** 
  201. * Return the sign-up slug. 
  202. * 
  203. * @since 1.5.0 
  204. * 
  205. * @return string 
  206. */ 
  207. function bp_get_signup_slug() { 
  208. $bp = buddypress(); 
  209.  
  210. if ( !empty( $bp->pages->register->slug ) ) { 
  211. $slug = $bp->pages->register->slug; 
  212. } elseif ( defined( 'BP_REGISTER_SLUG' ) ) { 
  213. $slug = BP_REGISTER_SLUG; 
  214. } else { 
  215. $slug = 'register'; 
  216.  
  217. /** 
  218. * Filters the sign-up slug. 
  219. * 
  220. * @since 1.5.0 
  221. * 
  222. * @param string $slug Sign-up slug. 
  223. */ 
  224. return apply_filters( 'bp_get_signup_slug', $slug ); 
  225.  
  226. /** 
  227. * Output the activation slug. 
  228. * 
  229. * @since 1.5.0 
  230. * 
  231. */ 
  232. function bp_activate_slug() { 
  233. echo bp_get_activate_slug(); 
  234. /** 
  235. * Return the activation slug. 
  236. * 
  237. * @since 1.5.0 
  238. * 
  239. * @return string 
  240. */ 
  241. function bp_get_activate_slug() { 
  242. $bp = buddypress(); 
  243.  
  244. if ( !empty( $bp->pages->activate->slug ) ) { 
  245. $slug = $bp->pages->activate->slug; 
  246. } elseif ( defined( 'BP_ACTIVATION_SLUG' ) ) { 
  247. $slug = BP_ACTIVATION_SLUG; 
  248. } else { 
  249. $slug = 'activate'; 
  250.  
  251. /** 
  252. * Filters the activation slug. 
  253. * 
  254. * @since 1.5.0 
  255. * 
  256. * @param string $slug Activation slug. 
  257. */ 
  258. return apply_filters( 'bp_get_activate_slug', $slug ); 
  259.  
  260. /** 
  261. * Initialize the members loop. 
  262. * 
  263. * Based on the $args passed, bp_has_members() populates the $members_template 
  264. * global, enabling the use of BuddyPress templates and template functions to 
  265. * display a list of members. 
  266. * 
  267. * @since 1.2.0 
  268. * 
  269. * @global object $members_template {@link BP_Members_Template} 
  270. * 
  271. * @param array|string $args { 
  272. * Arguments for limiting the contents of the members loop. Most arguments 
  273. * are in the same format as {@link BP_User_Query}. However, because 
  274. * the format of the arguments accepted here differs in a number of ways,  
  275. * and because bp_has_members() determines some default arguments in a 
  276. * dynamic fashion, we list all accepted arguments here as well. 
  277. * 
  278. * Arguments can be passed as an associative array, or as a URL query 
  279. * string (eg, 'user_id=4&per_page=3'). 
  280. * 
  281. * @type int $type Sort order. Accepts 'active', 'random', 'newest', 'popular',  
  282. * 'online', 'alphabetical'. Default: 'active'. 
  283. * @type int|bool $page Page of results to display. Default: 1. 
  284. * @type int|bool $per_page Number of results per page. Default: 20. 
  285. * @type int|bool $max Maximum number of results to return. Default: false (unlimited). 
  286. * @type string $page_arg The string used as a query parameter in pagination links. 
  287. * Default: 'bpage'. 
  288. * @type array|int|string|bool $include Limit results by a list of user IDs. Accepts an array, a 
  289. * single integer, a comma-separated list of IDs, or false (to 
  290. * disable this limiting). Accepts 'active', 'alphabetical',  
  291. * 'newest', or 'random'. Default: false. 
  292. * @type array|int|string|bool $exclude Exclude users from results by ID. Accepts an array, a single 
  293. * integer, a comma-separated list of IDs, or false (to disable 
  294. * this limiting). Default: false. 
  295. * @type int $user_id If provided, results are limited to the friends of the specified 
  296. * user. When on a user's Friends page, defaults to the ID of the 
  297. * displayed user. Otherwise defaults to 0. 
  298. * @type string|array $member_type Array or comma-separated list of member types to limit 
  299. * results to. 
  300. * @type string|array $member_type__in Array or comma-separated list of member types to limit 
  301. * results to. 
  302. * @type string|array $member_type__not_in Array or comma-separated list of member types to exclude 
  303. * from results. 
  304. * @type string $search_terms Limit results by a search term. Default: value of 
  305. * `$_REQUEST['members_search']` or `$_REQUEST['s']`, if present. 
  306. * Otherwise false. 
  307. * @type string $meta_key Limit results by the presence of a usermeta key. 
  308. * Default: false. 
  309. * @type mixed $meta_value When used with meta_key, limits results by the a matching 
  310. * usermeta value. Default: false. 
  311. * @type bool $populate_extras Whether to fetch optional data, such as friend counts. 
  312. * Default: true. 
  313. * } 
  314. * @return bool Returns true when blogs are found, otherwise false. 
  315. */ 
  316. function bp_has_members( $args = '' ) { 
  317. global $members_template; 
  318.  
  319. // Default user ID. 
  320. $user_id = 0; 
  321.  
  322. // User filtering. 
  323. if ( bp_is_user_friends() && ! bp_is_user_friend_requests() ) { 
  324. $user_id = bp_displayed_user_id(); 
  325.  
  326. $member_type = bp_get_current_member_type(); 
  327. if ( ! $member_type && ! empty( $_GET['member_type'] ) ) { 
  328. if ( is_array( $_GET['member_type'] ) ) { 
  329. $member_type = $_GET['member_type']; 
  330. } else { 
  331. // Can be a comma-separated list. 
  332. $member_type = explode( ', ', $_GET['member_type'] ); 
  333.  
  334. $search_terms_default = null; 
  335. $search_query_arg = bp_core_get_component_search_query_arg( 'members' ); 
  336. if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) { 
  337. $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] ); 
  338.  
  339. // Type: active ( default ) | random | newest | popular | online | alphabetical. 
  340. $r = bp_parse_args( $args, array( 
  341. 'type' => 'active',  
  342. 'page' => 1,  
  343. 'per_page' => 20,  
  344. 'max' => false,  
  345.  
  346. 'page_arg' => 'upage', // See https://buddypress.trac.wordpress.org/ticket/3679. 
  347.  
  348. 'include' => false, // Pass a user_id or a list (comma-separated or array) of user_ids to only show these users. 
  349. 'exclude' => false, // Pass a user_id or a list (comma-separated or array) of user_ids to exclude these users. 
  350.  
  351. 'user_id' => $user_id, // Pass a user_id to only show friends of this user. 
  352. 'member_type' => $member_type,  
  353. 'member_type__in' => '',  
  354. 'member_type__not_in' => '',  
  355. 'search_terms' => $search_terms_default,  
  356.  
  357. 'meta_key' => false, // Only return users with this usermeta. 
  358. 'meta_value' => false, // Only return users where the usermeta value matches. Requires meta_key. 
  359.  
  360. 'populate_extras' => true // Fetch usermeta? Friend count, last active etc. 
  361. ), 'has_members' ); 
  362.  
  363. // Pass a filter if ?s= is set. 
  364. if ( is_null( $r['search_terms'] ) ) { 
  365. if ( !empty( $_REQUEST['s'] ) ) { 
  366. $r['search_terms'] = $_REQUEST['s']; 
  367. } else { 
  368. $r['search_terms'] = false; 
  369.  
  370. // Set per_page to max if max is larger than per_page. 
  371. if ( !empty( $r['max'] ) && ( $r['per_page'] > $r['max'] ) ) { 
  372. $r['per_page'] = $r['max']; 
  373.  
  374. // Query for members and populate $members_template global. 
  375. $members_template = new BP_Core_Members_Template( 
  376. $r['type'],  
  377. $r['page'],  
  378. $r['per_page'],  
  379. $r['max'],  
  380. $r['user_id'],  
  381. $r['search_terms'],  
  382. $r['include'],  
  383. $r['populate_extras'],  
  384. $r['exclude'],  
  385. $r['meta_key'],  
  386. $r['meta_value'],  
  387. $r['page_arg'],  
  388. $r['member_type'],  
  389. $r['member_type__in'],  
  390. $r['member_type__not_in'] 
  391. ); 
  392.  
  393. /** 
  394. * Filters whether or not BuddyPress has members to iterate over. 
  395. * 
  396. * @since 1.2.4 
  397. * @since 2.6.0 Added the `$r` parameter 
  398. * 
  399. * @param bool $value Whether or not there are members to iterate over. 
  400. * @param array $members_template Populated $members_template global. 
  401. * @param array $r Array of arguments passed into the BP_Core_Members_Template class. 
  402. */ 
  403. return apply_filters( 'bp_has_members', $members_template->has_members(), $members_template, $r ); 
  404.  
  405. /** 
  406. * Set up the current member inside the loop. 
  407. * 
  408. * @since 1.2.0 
  409. * 
  410. * @return object 
  411. */ 
  412. function bp_the_member() { 
  413. global $members_template; 
  414. return $members_template->the_member(); 
  415.  
  416. /** 
  417. * Check whether there are more members to iterate over. 
  418. * 
  419. * @since 1.2.0 
  420. * 
  421. * @return bool 
  422. */ 
  423. function bp_members() { 
  424. global $members_template; 
  425. return $members_template->members(); 
  426.  
  427. /** 
  428. * Output the members pagination count. 
  429. * 
  430. * @since 1.2.0 
  431. */ 
  432. function bp_members_pagination_count() { 
  433. echo bp_get_members_pagination_count(); 
  434. /** 
  435. * Generate the members pagination count. 
  436. * 
  437. * @since 1.5.0 
  438. * 
  439. * @return string 
  440. */ 
  441. function bp_get_members_pagination_count() { 
  442. global $members_template; 
  443.  
  444. if ( empty( $members_template->type ) ) 
  445. $members_template->type = ''; 
  446.  
  447. $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1; 
  448. $from_num = bp_core_number_format( $start_num ); 
  449. $to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) ); 
  450. $total = bp_core_number_format( $members_template->total_member_count ); 
  451.  
  452. if ( 'active' == $members_template->type ) { 
  453. if ( 1 == $members_template->total_member_count ) { 
  454. $pag = __( 'Viewing 1 active member', 'buddypress' ); 
  455. } else { 
  456. $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s active member', 'Viewing %1$s - %2$s of %3$s active members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 
  457. } elseif ( 'popular' == $members_template->type ) { 
  458. if ( 1 == $members_template->total_member_count ) { 
  459. $pag = __( 'Viewing 1 member with friends', 'buddypress' ); 
  460. } else { 
  461. $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s member with friends', 'Viewing %1$s - %2$s of %3$s members with friends', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 
  462. } elseif ( 'online' == $members_template->type ) { 
  463. if ( 1 == $members_template->total_member_count ) { 
  464. $pag = __( 'Viewing 1 online member', 'buddypress' ); 
  465. } else { 
  466. $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s online member', 'Viewing %1$s - %2$s of %3$s online members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 
  467. } else { 
  468. if ( 1 == $members_template->total_member_count ) { 
  469. $pag = __( 'Viewing 1 member', 'buddypress' ); 
  470. } else { 
  471. $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s member', 'Viewing %1$s - %2$s of %3$s members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total ); 
  472.  
  473. /** 
  474. * Filters the members pagination count. 
  475. * 
  476. * @since 1.5.0 
  477. * 
  478. * @param string $pag Pagination count string. 
  479. */ 
  480. return apply_filters( 'bp_members_pagination_count', $pag ); 
  481.  
  482. /** 
  483. * Output the members pagination links. 
  484. * 
  485. * @since 1.2.0 
  486. */ 
  487. function bp_members_pagination_links() { 
  488. echo bp_get_members_pagination_links(); 
  489. /** 
  490. * Fetch the members pagination links. 
  491. * 
  492. * @since 1.2.0 
  493. * 
  494. * @return string 
  495. */ 
  496. function bp_get_members_pagination_links() { 
  497. global $members_template; 
  498.  
  499. /** 
  500. * Filters the members pagination link. 
  501. * 
  502. * @since 1.2.0 
  503. * 
  504. * @param string $pag_links HTML markup for pagination links. 
  505. */ 
  506. return apply_filters( 'bp_get_members_pagination_links', $members_template->pag_links ); 
  507.  
  508. /** 
  509. * Output the ID of the current member in the loop. 
  510. * 
  511. * @since 1.2.0 
  512. * 
  513. */ 
  514. function bp_member_user_id() { 
  515. echo bp_get_member_user_id(); 
  516. /** 
  517. * Get the ID of the current member in the loop. 
  518. * 
  519. * @since 1.2.0 
  520. * 
  521. * @return string Member ID. 
  522. */ 
  523. function bp_get_member_user_id() { 
  524. global $members_template; 
  525. $member_id = isset( $members_template->member->id ) ? (int) $members_template->member->id : false; 
  526.  
  527. /** 
  528. * Filters the ID of the current member in the loop. 
  529. * 
  530. * @since 1.2.0 
  531. * 
  532. * @param int $member_id ID of the member being iterated over. 
  533. */ 
  534. return apply_filters( 'bp_get_member_user_id', $member_id ); 
  535.  
  536. /** 
  537. * Output the row class of the current member in the loop. 
  538. * 
  539. * @since 1.7.0 
  540. * 
  541. * @param array $classes Array of custom classes. 
  542. */ 
  543. function bp_member_class( $classes = array() ) { 
  544. echo bp_get_member_class( $classes ); 
  545. /** 
  546. * Return the row class of the current member in the loop. 
  547. * 
  548. * @since 1.7.0 
  549. * 
  550. * @param array $classes Array of custom classes. 
  551. * @return string Row class of the member 
  552. */ 
  553. function bp_get_member_class( $classes = array() ) { 
  554. global $members_template; 
  555.  
  556. // Add even/odd classes, but only if there's more than 1 member. 
  557. if ( $members_template->member_count > 1 ) { 
  558. $pos_in_loop = (int) $members_template->current_member; 
  559. $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd'; 
  560.  
  561. // If we've only one member in the loop, don't bother with odd and even. 
  562. } else { 
  563. $classes[] = 'bp-single-member'; 
  564.  
  565. // Maybe add 'is-online' class. 
  566. if ( ! empty( $members_template->member->last_activity ) ) { 
  567.  
  568. // Calculate some times. 
  569. $current_time = bp_core_current_time( true, 'timestamp' ); 
  570. $last_activity = strtotime( $members_template->member->last_activity ); 
  571. $still_online = strtotime( '+5 minutes', $last_activity ); 
  572.  
  573. // Has the user been active recently? 
  574. if ( $current_time <= $still_online ) { 
  575. $classes[] = 'is-online'; 
  576.  
  577. // Add current user class. 
  578. if ( bp_loggedin_user_id() === (int) $members_template->member->id ) { 
  579. $classes[] = 'is-current-user'; 
  580.  
  581. // Add current user member types. 
  582. if ( $member_types = bp_get_member_type( $members_template->member->id, false ) ) { 
  583. foreach ( $member_types as $member_type ) { 
  584. $classes[] = sprintf( 'member-type-%s', esc_attr( $member_type ) ); 
  585.  
  586. /** 
  587. * Filters the determined classes to add to the HTML element. 
  588. * 
  589. * @since 1.7.0 
  590. * 
  591. * @param string $classes Classes to be added to the HTML element. 
  592. */ 
  593. $classes = apply_filters( 'bp_get_member_class', $classes ); 
  594. $classes = array_merge( $classes, array() ); 
  595. $retval = 'class="' . join( ' ', $classes ) . '"'; 
  596.  
  597. return $retval; 
  598.  
  599. /** 
  600. * Output nicename of current member in the loop. 
  601. * 
  602. * @since 1.2.5 
  603. */ 
  604. function bp_member_user_nicename() { 
  605. echo bp_get_member_user_nicename(); 
  606. /** 
  607. * Get the nicename of the current member in the loop. 
  608. * 
  609. * @since 1.2.5 
  610. * 
  611. * @return string Members nicename. 
  612. */ 
  613. function bp_get_member_user_nicename() { 
  614. global $members_template; 
  615.  
  616. /** 
  617. * Filters the nicename of the current member in the loop. 
  618. * 
  619. * @since 1.2.5 
  620. * 
  621. * @param string $user_nicename Nicename for the current member. 
  622. */ 
  623. return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename ); 
  624.  
  625. /** 
  626. * Output login for current member in the loop. 
  627. * 
  628. * @since 1.2.5 
  629. */ 
  630. function bp_member_user_login() { 
  631. echo bp_get_member_user_login(); 
  632. /** 
  633. * Get the login of the current member in the loop. 
  634. * 
  635. * @since 1.2.5 
  636. * 
  637. * @return string Member's login. 
  638. */ 
  639. function bp_get_member_user_login() { 
  640. global $members_template; 
  641.  
  642. /** 
  643. * Filters the login of the current member in the loop. 
  644. * 
  645. * @since 1.2.5 
  646. * 
  647. * @param string $user_login Login for the current member. 
  648. */ 
  649. return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login ); 
  650.  
  651. /** 
  652. * Output the email address for the current member in the loop. 
  653. * 
  654. * @since 1.2.5 
  655. */ 
  656. function bp_member_user_email() { 
  657. echo bp_get_member_user_email(); 
  658. /** 
  659. * Get the email address of the current member in the loop. 
  660. * 
  661. * @since 1.2.5 
  662. * 
  663. * @return string Member's email address. 
  664. */ 
  665. function bp_get_member_user_email() { 
  666. global $members_template; 
  667.  
  668. /** 
  669. * Filters the email address of the current member in the loop. 
  670. * 
  671. * @since 1.2.5 
  672. * 
  673. * @param string $user_email Email address for the current member. 
  674. */ 
  675. return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email ); 
  676.  
  677. /** 
  678. * Check whether the current member in the loop is the logged-in user. 
  679. * 
  680. * @since 1.2.5 
  681. * 
  682. * @return bool 
  683. */ 
  684. function bp_member_is_loggedin_user() { 
  685. global $members_template; 
  686.  
  687. /** 
  688. * Filters whether the current member in the loop is the logged-in user. 
  689. * 
  690. * @since 1.2.5 
  691. * 
  692. * @param bool $value Whether current member in the loop is logged in. 
  693. */ 
  694. return apply_filters( 'bp_member_is_loggedin_user', bp_loggedin_user_id() == $members_template->member->id ? true : false ); 
  695.  
  696. /** 
  697. * Output a member's avatar. 
  698. * 
  699. * @since 1.2.0 
  700. * 
  701. * @see bp_get_member_avatar() for description of arguments. 
  702. * 
  703. * @param array|string $args See {@link bp_get_member_avatar()}. 
  704. */ 
  705. function bp_member_avatar( $args = '' ) { 
  706.  
  707. /** 
  708. * Filters a members avatar. 
  709. * 
  710. * @since 1.2.0 
  711. * @since 2.6.0 Added the `$args` parameter. 
  712. * 
  713. * @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg. 
  714. * @param array|string $args See {@link bp_get_member_avatar()}. 
  715. */ 
  716. echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ), $args ); 
  717. /** 
  718. * Get a member's avatar. 
  719. * 
  720. * @since 1.2.0 
  721. * 
  722. * @see bp_core_fetch_avatar() For a description of arguments and 
  723. * return values. 
  724. * 
  725. * @param array|string $args { 
  726. * Arguments are listed here with an explanation of their defaults. 
  727. * For more information about the arguments, see 
  728. * {@link bp_core_fetch_avatar()}. 
  729. * @type string $alt Default: 'Profile picture of [user name]'. 
  730. * @type string $class Default: 'avatar'. 
  731. * @type string $type Default: 'thumb'. 
  732. * @type int|bool $width Default: false. 
  733. * @type int|bool $height Default: false. 
  734. * @type bool $id Currently unused. 
  735. * @type bool $no_grav Default: false. 
  736. * } 
  737. * @return string User avatar string. 
  738. */ 
  739. function bp_get_member_avatar( $args = '' ) { 
  740. global $members_template; 
  741.  
  742. $fullname = !empty( $members_template->member->fullname ) ? $members_template->member->fullname : $members_template->member->display_name; 
  743.  
  744. $defaults = array( 
  745. 'type' => 'thumb',  
  746. 'width' => false,  
  747. 'height' => false,  
  748. 'class' => 'avatar',  
  749. 'id' => false,  
  750. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname ) 
  751. ); 
  752.  
  753. $r = wp_parse_args( $args, $defaults ); 
  754. extract( $r, EXTR_SKIP ); 
  755.  
  756. /** 
  757. * Filters a members avatar. 
  758. * 
  759. * @since 1.2.0 
  760. * @since 2.6.0 Added the `$r` parameter. 
  761. * 
  762. * @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg. 
  763. * @param array $r Array of parsed arguments. See {@link bp_get_member_avatar()}. 
  764. */ 
  765. return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ), $r ); 
  766.  
  767. /** 
  768. * Output the permalink for the current member in the loop. 
  769. * 
  770. * @since 1.2.0 
  771. */ 
  772. function bp_member_permalink() { 
  773. echo esc_url( bp_get_member_permalink() ); 
  774. /** 
  775. * Get the permalink for the current member in the loop. 
  776. * 
  777. * @since 1.2.0 
  778. * 
  779. * @return string 
  780. */ 
  781. function bp_get_member_permalink() { 
  782. global $members_template; 
  783.  
  784. /** 
  785. * Filters the permalink for the current member in the loop. 
  786. * 
  787. * @since 1.2.0 
  788. * 
  789. * @param string $value Permalink for the current member in the loop. 
  790. */ 
  791. return apply_filters( 'bp_get_member_permalink', bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) ); 
  792.  
  793. /** 
  794. * Alias of {@link bp_member_permalink()}. 
  795. * 
  796. * @since 1.2.0 
  797. */ 
  798. function bp_member_link() { echo esc_url( bp_get_member_permalink() ); } 
  799.  
  800. /** 
  801. * Alias of {@link bp_get_member_permalink()}. 
  802. * 
  803. * @since 1.2.0 
  804. */ 
  805. function bp_get_member_link() { return bp_get_member_permalink(); } 
  806.  
  807. /** 
  808. * Output display name of current member in the loop. 
  809. * 
  810. * @since 1.2.0 
  811. */ 
  812. function bp_member_name() { 
  813.  
  814. /** 
  815. * Filters the display name of current member in the loop. 
  816. * 
  817. * @since 1.2.0 
  818. * 
  819. * @param string $value Display name for current member. 
  820. */ 
  821. echo apply_filters( 'bp_member_name', bp_get_member_name() ); 
  822. /** 
  823. * Get the display name of the current member in the loop. 
  824. * 
  825. * Full name is, by default, pulled from xprofile's Full Name field. 
  826. * When this field is empty, we try to get an alternative name from the 
  827. * WP users table, in the following order of preference: display_name,  
  828. * user_nicename, user_login. 
  829. * 
  830. * @since 1.2.0 
  831. * 
  832. * @return string The user's fullname for display. 
  833. */ 
  834. function bp_get_member_name() { 
  835. global $members_template; 
  836.  
  837. // Generally, this only fires when xprofile is disabled. 
  838. if ( empty( $members_template->member->fullname ) ) { 
  839. // Our order of preference for alternative fullnames. 
  840. $name_stack = array( 
  841. 'display_name',  
  842. 'user_nicename',  
  843. 'user_login' 
  844. ); 
  845.  
  846. foreach ( $name_stack as $source ) { 
  847. if ( !empty( $members_template->member->{$source} ) ) { 
  848. // When a value is found, set it as fullname and be done with it. 
  849. $members_template->member->fullname = $members_template->member->{$source}; 
  850. break; 
  851.  
  852. /** 
  853. * Filters the display name of current member in the loop. 
  854. * 
  855. * @since 1.2.0 
  856. * 
  857. * @param string $fullname Display name for current member. 
  858. */ 
  859. return apply_filters( 'bp_get_member_name', $members_template->member->fullname ); 
  860. add_filter( 'bp_get_member_name', 'wp_filter_kses' ); 
  861. add_filter( 'bp_get_member_name', 'stripslashes' ); 
  862. add_filter( 'bp_get_member_name', 'strip_tags' ); 
  863. add_filter( 'bp_get_member_name', 'esc_html' ); 
  864.  
  865. /** 
  866. * Output the current member's last active time. 
  867. * 
  868. * @since 1.2.0 
  869. * 
  870. * @param array $args {@see bp_get_member_last_active()}. 
  871. */ 
  872. function bp_member_last_active( $args = array() ) { 
  873. echo bp_get_member_last_active( $args ); 
  874. /** 
  875. * Return the current member's last active time. 
  876. * 
  877. * @since 1.2.0 
  878. * @since 2.7.0 Added 'relative' as a parameter to $args. 
  879. * 
  880. * @param array $args { 
  881. * Array of optional arguments. 
  882. * @type mixed $active_format If true, formatted "active 5 minutes ago". If false, formatted "5 minutes 
  883. * ago". If string, should be sprintf'able like 'last seen %s ago'. 
  884. * @type bool $relative If true, will return relative time "5 minutes ago". If false, will return 
  885. * date from database. Default: true. 
  886. * } 
  887. * @return string 
  888. */ 
  889. function bp_get_member_last_active( $args = array() ) { 
  890. global $members_template; 
  891.  
  892. // Parse the activity format. 
  893. $r = bp_parse_args( $args, array( 
  894. 'active_format' => true,  
  895. 'relative' => true,  
  896. ) ); 
  897.  
  898. // Backwards compatibility for anyone forcing a 'true' active_format. 
  899. if ( true === $r['active_format'] ) { 
  900. $r['active_format'] = __( 'active %s', 'buddypress' ); 
  901.  
  902. // Member has logged in at least one time. 
  903. if ( isset( $members_template->member->last_activity ) ) { 
  904. // We do not want relative time, so return now. 
  905. // @todo Should the 'bp_member_last_active' filter be applied here? 
  906. if ( ! $r['relative'] ) { 
  907. return esc_attr( $members_template->member->last_activity ); 
  908.  
  909. // Backwards compatibility for pre 1.5 'ago' strings. 
  910. $last_activity = ! empty( $r['active_format'] ) 
  911. ? bp_core_get_last_activity( $members_template->member->last_activity, $r['active_format'] ) 
  912. : bp_core_time_since( $members_template->member->last_activity ); 
  913.  
  914. // Member has never logged in or been active. 
  915. } else { 
  916. $last_activity = __( 'Never active', 'buddypress' ); 
  917.  
  918. /** 
  919. * Filters the current members last active time. 
  920. * 
  921. * @since 1.2.0 
  922. * 
  923. * @param string $last_activity Formatted time since last activity. 
  924. * @param array $r Array of parsed arguments for query. 
  925. */ 
  926. return apply_filters( 'bp_member_last_active', $last_activity, $r ); 
  927.  
  928. /** 
  929. * Output the latest update of the current member in the loop. 
  930. * 
  931. * @since 1.2.0 
  932. * 
  933. * @param array|string $args Array of arguments for latest update. 
  934. */ 
  935. function bp_member_latest_update( $args = '' ) { 
  936. echo bp_get_member_latest_update( $args ); 
  937. /** 
  938. * Get the latest update from the current member in the loop. 
  939. * 
  940. * @since 1.2.0 
  941. * 
  942. * @param array|string $args { 
  943. * Array of optional arguments. 
  944. * @type int $length Truncation length. Default: 225. 
  945. * @type bool $view_link Whether to provide a 'View' link for 
  946. * truncated entries. Default: false. 
  947. * } 
  948. * @return string 
  949. */ 
  950. function bp_get_member_latest_update( $args = '' ) { 
  951. global $members_template; 
  952.  
  953. $defaults = array( 
  954. 'length' => 225,  
  955. 'view_link' => true 
  956. ); 
  957.  
  958. $r = wp_parse_args( $args, $defaults ); 
  959. extract( $r ); 
  960.  
  961. if ( !bp_is_active( 'activity' ) || empty( $members_template->member->latest_update ) || !$update = maybe_unserialize( $members_template->member->latest_update ) ) 
  962. return false; 
  963.  
  964. /** 
  965. * Filters the excerpt of the latest update for current member in the loop. 
  966. * 
  967. * @since 1.2.5 
  968. * @since 2.6.0 Added the `$r` parameter. 
  969. * 
  970. * @param string $value Excerpt of the latest update for current member in the loop. 
  971. * @param array $r Array of parsed arguments. 
  972. */ 
  973. $update_content = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], $length ) ) ), $r ); 
  974.  
  975. $update_content = sprintf( _x( '- "%s"', 'member latest update in member directory', 'buddypress' ), $update_content ); 
  976.  
  977. // If $view_link is true and the text returned by bp_create_excerpt() is different from the original text (ie it's 
  978. // been truncated), add the "View" link. 
  979. if ( $view_link && ( $update_content != $update['content'] ) ) { 
  980. $view = __( 'View', 'buddypress' ); 
  981.  
  982. $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_permalink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>'; 
  983.  
  984. /** 
  985. * Filters the latest update from the current member in the loop. 
  986. * 
  987. * @since 1.2.0 
  988. * @since 2.6.0 Added the `$r` parameter. 
  989. * 
  990. * @param string $update_content Formatted latest update for current member. 
  991. * @param array $r Array of parsed arguments. 
  992. */ 
  993. return apply_filters( 'bp_get_member_latest_update', $update_content, $r ); 
  994.  
  995. /** 
  996. * Output a piece of user profile data. 
  997. * 
  998. * @since 1.2.0 
  999. * 
  1000. * @see bp_get_member_profile_data() for a description of params. 
  1001. * 
  1002. * @param array|string $args See {@link bp_get_member_profile_data()}. 
  1003. */ 
  1004. function bp_member_profile_data( $args = '' ) { 
  1005. echo bp_get_member_profile_data( $args ); 
  1006. /** 
  1007. * Get a piece of user profile data. 
  1008. * 
  1009. * When used in a bp_has_members() loop, this function will attempt 
  1010. * to fetch profile data cached in the template global. It is also safe 
  1011. * to use outside of the loop. 
  1012. * 
  1013. * @since 1.2.0 
  1014. * 
  1015. * @param array|string $args { 
  1016. * Array of config parameters. 
  1017. * @type string $field Name of the profile field. 
  1018. * @type int $user_id ID of the user whose data is being fetched. 
  1019. * Defaults to the current member in the loop, or if not 
  1020. * present, to the currently displayed user. 
  1021. * } 
  1022. * @return string|bool Profile data if found, otherwise false. 
  1023. */ 
  1024. function bp_get_member_profile_data( $args = '' ) { 
  1025. global $members_template; 
  1026.  
  1027. if ( ! bp_is_active( 'xprofile' ) ) { 
  1028. return false; 
  1029.  
  1030. // Declare local variables. 
  1031. $data = false; 
  1032.  
  1033. // Guess at default $user_id. 
  1034. $default_user_id = 0; 
  1035. if ( ! empty( $members_template->member->id ) ) { 
  1036. $default_user_id = $members_template->member->id; 
  1037. } elseif ( bp_displayed_user_id() ) { 
  1038. $default_user_id = bp_displayed_user_id(); 
  1039.  
  1040. $defaults = array( 
  1041. 'field' => false,  
  1042. 'user_id' => $default_user_id,  
  1043. ); 
  1044.  
  1045. $r = wp_parse_args( $args, $defaults ); 
  1046.  
  1047. // If we're in a members loop, get the data from the global. 
  1048. if ( ! empty( $members_template->member->profile_data ) ) { 
  1049. $profile_data = $members_template->member->profile_data; 
  1050.  
  1051. // Otherwise query for the data. 
  1052. if ( empty( $profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) ) { 
  1053. $profile_data = BP_XProfile_ProfileData::get_all_for_user( $r['user_id'] ); 
  1054.  
  1055. // If we're in the members loop, but the profile data has not 
  1056. // been loaded into the global, cache it there for later use. 
  1057. if ( ! empty( $members_template->member ) && empty( $members_template->member->profile_data ) ) { 
  1058. $members_template->member->profile_data = $profile_data; 
  1059.  
  1060. // Get the data for the specific field requested. 
  1061. if ( ! empty( $profile_data ) && ! empty( $profile_data[ $r['field'] ]['field_type'] ) && ! empty( $profile_data[ $r['field'] ]['field_data'] ) ) { 
  1062. $data = xprofile_format_profile_field( $profile_data[ $r['field'] ]['field_type'], $profile_data[ $r['field'] ]['field_data'] ); 
  1063.  
  1064. /** 
  1065. * Filters resulting piece of member profile data. 
  1066. * 
  1067. * @since 1.2.0 
  1068. * @since 2.6.0 Added the `$r` parameter. 
  1069. * 
  1070. * @param string|bool $data Profile data if found, otherwise false. 
  1071. * @param array $r Array of parsed arguments. 
  1072. */ 
  1073. $data = apply_filters( 'bp_get_member_profile_data', $data, $r ); 
  1074.  
  1075. /** 
  1076. * Filters the resulting piece of member profile data by field type. 
  1077. * 
  1078. * This is a dynamic filter based on field type of the current field requested. 
  1079. * 
  1080. * @since 2.7.0 
  1081. * 
  1082. * @param string|bool $data Profile data if found, otherwise false. 
  1083. * @param array $r Array of parsed arguments. 
  1084. */ 
  1085. $data = apply_filters( 'bp_get_member_profile_data_' . $profile_data[ $r['field'] ]['field_type'], $data, $r ); 
  1086.  
  1087. return $data; 
  1088.  
  1089. /** 
  1090. * Output the 'registered [x days ago]' string for the current member. 
  1091. * 
  1092. * @since 1.2.0 
  1093. * @since 2.7.0 Added $args as a parameter. 
  1094. * 
  1095. * @param array $args Optional. {@see bp_get_member_registered()} 
  1096. */ 
  1097. function bp_member_registered( $args = array() ) { 
  1098. echo bp_get_member_registered( $args ); 
  1099. /** 
  1100. * Get the 'registered [x days ago]' string for the current member. 
  1101. * 
  1102. * @since 1.2.0 
  1103. * @since 2.7.0 Added $args as a parameter. 
  1104. * 
  1105. * @param array $args { 
  1106. * Array of optional parameters. 
  1107. * 
  1108. * @type bool $relative Optional. If true, returns relative registered date. eg. registered 5 months ago. 
  1109. * If false, returns registered date value from database. 
  1110. * } 
  1111. * 
  1112. * @return string 
  1113. */ 
  1114. function bp_get_member_registered( $args = array() ) { 
  1115. global $members_template; 
  1116.  
  1117. $r = wp_parse_args( $args, array( 
  1118. 'relative' => true,  
  1119. ) ); 
  1120.  
  1121. // We do not want relative time, so return now. 
  1122. // @todo Should the 'bp_member_registered' filter be applied here? 
  1123. if ( ! $r['relative'] ) { 
  1124. return esc_attr( $members_template->member->user_registered ); 
  1125.  
  1126. $registered = esc_attr( bp_core_get_last_activity( $members_template->member->user_registered, _x( 'registered %s', 'Records the timestamp that the user registered into the activity stream', 'buddypress' ) ) ); 
  1127.  
  1128. /** 
  1129. * Filters the 'registered [x days ago]' string for the current member. 
  1130. * 
  1131. * @since 2.1.0 
  1132. * 
  1133. * @param string $registered The 'registered [x days ago]' string. 
  1134. */ 
  1135. return apply_filters( 'bp_member_registered', $registered ); 
  1136.  
  1137. /** 
  1138. * Output a random piece of profile data for the current member in the loop. 
  1139. * 
  1140. * @since 1.2.0 
  1141. */ 
  1142. function bp_member_random_profile_data() { 
  1143. global $members_template; 
  1144.  
  1145. if ( bp_is_active( 'xprofile' ) ) { ?> 
  1146. <?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?> 
  1147. <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong> 
  1148. <?php echo wp_filter_kses( $random_data[0]->value ) ?> 
  1149. <?php } 
  1150.  
  1151. /** 
  1152. * Output hidden input for preserving member search params on form submit. 
  1153. * 
  1154. * @since 1.2.0 
  1155. */ 
  1156. function bp_member_hidden_fields() { 
  1157. $query_arg = bp_core_get_component_search_query_arg( 'members' ); 
  1158.  
  1159. if ( isset( $_REQUEST[ $query_arg ] ) ) { 
  1160. echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST[ $query_arg ] ) . '" name="search_terms" />'; 
  1161.  
  1162. if ( isset( $_REQUEST['letter'] ) ) { 
  1163. echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />'; 
  1164.  
  1165. if ( isset( $_REQUEST['members_search'] ) ) { 
  1166. echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['members_search'] ) . '" name="search_terms" />'; 
  1167.  
  1168. /** 
  1169. * Output the Members directory search form. 
  1170. * 
  1171. * @since 1.0.0 
  1172. */ 
  1173. function bp_directory_members_search_form() { 
  1174.  
  1175. $query_arg = bp_core_get_component_search_query_arg( 'members' ); 
  1176.  
  1177. if ( ! empty( $_REQUEST[ $query_arg ] ) ) { 
  1178. $search_value = stripslashes( $_REQUEST[ $query_arg ] ); 
  1179. } else { 
  1180. $search_value = bp_get_search_default_text( 'members' ); 
  1181.  
  1182. $search_form_html = '<form action="" method="get" id="search-members-form"> 
  1183. <label for="members_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="members_search" placeholder="'. esc_attr( $search_value ) .'" /></label> 
  1184. <input type="submit" id="members_search_submit" name="members_search_submit" value="' . __( 'Search', 'buddypress' ) . '" /> 
  1185. </form>'; 
  1186.  
  1187. /** 
  1188. * Filters the Members component search form. 
  1189. * 
  1190. * @since 1.9.0 
  1191. * 
  1192. * @param string $search_form_html HTML markup for the member search form. 
  1193. */ 
  1194. echo apply_filters( 'bp_directory_members_search_form', $search_form_html ); 
  1195.  
  1196. /** 
  1197. * Output the total member count. 
  1198. * 
  1199. * @since 1.2.0 
  1200. */ 
  1201. function bp_total_site_member_count() { 
  1202. echo bp_get_total_site_member_count(); 
  1203. /** 
  1204. * Get the total site member count. 
  1205. * 
  1206. * @since 1.2.0 
  1207. * 
  1208. * @return int 
  1209. */ 
  1210. function bp_get_total_site_member_count() { 
  1211.  
  1212. /** 
  1213. * Filters the total site member count. 
  1214. * 
  1215. * @since 1.2.0 
  1216. * 
  1217. * @param int $value Number-formatted total site member count. 
  1218. */ 
  1219. return apply_filters( 'bp_get_total_site_member_count', bp_core_number_format( bp_core_get_total_member_count() ) ); 
  1220.  
  1221. /** Navigation and other misc template tags ***********************************/ 
  1222.  
  1223. /** 
  1224. * Render the navigation markup for the logged-in user. 
  1225. * 
  1226. * Each component adds to this navigation array within its own 
  1227. * [component_name]setup_nav() function. 
  1228. * 
  1229. * This navigation array is the top level navigation, so it contains items such as: 
  1230. * [Blog, Profile, Messages, Groups, Friends] ... 
  1231. * 
  1232. * The function will also analyze the current component the user is in, to 
  1233. * determine whether or not to highlight a particular nav item. 
  1234. * 
  1235. * @since 1.1.0 
  1236. * 
  1237. * @todo Move to a back-compat file? 
  1238. * @deprecated Does not seem to be called anywhere in BP core. 
  1239. */ 
  1240. function bp_get_loggedin_user_nav() { 
  1241. $bp = buddypress(); 
  1242.  
  1243. // Loop through each navigation item. 
  1244. foreach ( (array) $bp->members->nav->get_primary() as $nav_item ) { 
  1245.  
  1246. $selected = ''; 
  1247.  
  1248. // If the current component matches the nav item id, then add a highlight CSS class. 
  1249. if ( ! bp_is_directory() && ! empty( $bp->active_components[ bp_current_component() ] ) && $bp->active_components[ bp_current_component() ] == $nav_item->css_id ) { 
  1250. $selected = ' class="current selected"'; 
  1251.  
  1252. // If we are viewing another person (current_userid does not equal 
  1253. // loggedin_user->id then check to see if the two users are friends. 
  1254. // if they are, add a highlight CSS class to the friends nav item 
  1255. // if it exists. 
  1256. if ( !bp_is_my_profile() && bp_displayed_user_id() ) { 
  1257. $selected = ''; 
  1258.  
  1259. if ( bp_is_active( 'friends' ) ) { 
  1260. if ( $nav_item->css_id == $bp->friends->id ) { 
  1261. if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) { 
  1262. $selected = ' class="current selected"'; 
  1263.  
  1264. // Echo out the final list item. 
  1265. echo apply_filters_ref_array( 'bp_get_loggedin_user_nav_' . $nav_item->css_id, array( '<li id="li-nav-' . $nav_item->css_id . '" ' . $selected . '><a id="my-' . $nav_item->css_id . '" href="' . $nav_item->link . '">' . $nav_item->name . '</a></li>', &$nav_item ) ); 
  1266.  
  1267. // Always add a log out list item to the end of the navigation. 
  1268. $logout_link = '<li><a id="wp-logout" href="' . wp_logout_url( bp_get_root_domain() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>'; 
  1269.  
  1270. echo apply_filters( 'bp_logout_nav_link', $logout_link ); 
  1271.  
  1272. /** 
  1273. * Output the contents of the current user's home page. 
  1274. * 
  1275. * @since 2.6.0 
  1276. */ 
  1277. function bp_displayed_user_front_template_part() { 
  1278. $located = bp_displayed_user_get_front_template(); 
  1279.  
  1280. if ( false !== $located ) { 
  1281. $slug = str_replace( '.php', '', $located ); 
  1282. $name = null; 
  1283.  
  1284. /** 
  1285. * Let plugins adding an action to bp_get_template_part get it from here 
  1286. * 
  1287. * @param string $slug Template part slug requested. 
  1288. * @param string $name Template part name requested. 
  1289. */ 
  1290. do_action( 'get_template_part_' . $slug, $slug, $name ); 
  1291.  
  1292. load_template( $located, true ); 
  1293.  
  1294. return $located; 
  1295.  
  1296. /** 
  1297. * Locate a custom user front template if it exists. 
  1298. * 
  1299. * @since 2.6.0 
  1300. * 
  1301. * @param object|null $displayed_user Optional. Falls back to current user if not passed. 
  1302. * @return string|bool Path to front template on success; boolean false on failure. 
  1303. */ 
  1304. function bp_displayed_user_get_front_template( $displayed_user = null ) { 
  1305. if ( ! is_object( $displayed_user ) || empty( $displayed_user->id ) ) { 
  1306. $displayed_user = bp_get_displayed_user(); 
  1307.  
  1308. if ( ! isset( $displayed_user->id ) ) { 
  1309. return false; 
  1310.  
  1311. if ( isset( $displayed_user->front_template ) ) { 
  1312. return $displayed_user->front_template; 
  1313.  
  1314. // Init the hierarchy 
  1315. $template_names = array( 
  1316. 'members/single/front-id-' . sanitize_file_name( $displayed_user->id ) . '.php',  
  1317. 'members/single/front-nicename-' . sanitize_file_name( $displayed_user->userdata->user_nicename ) . '.php',  
  1318. ); 
  1319.  
  1320. /** 
  1321. * Check for member types and add it to the hierarchy 
  1322. * 
  1323. * Make sure to register your member 
  1324. * type using the hook 'bp_register_member_types' 
  1325. */ 
  1326. if ( bp_get_member_types() ) { 
  1327. $displayed_user_member_type = bp_get_member_type( $displayed_user->id ); 
  1328. if ( ! $displayed_user_member_type ) { 
  1329. $displayed_user_member_type = 'none'; 
  1330.  
  1331. $template_names[] = 'members/single/front-member-type-' . sanitize_file_name( $displayed_user_member_type ) . '.php'; 
  1332.  
  1333. // Add The generic template to the end of the hierarchy 
  1334. $template_names[] = 'members/single/front.php'; 
  1335.  
  1336. /** 
  1337. * Filters the hierarchy of user front templates corresponding to a specific user. 
  1338. * 
  1339. * @since 2.6.0 
  1340. * 
  1341. * @param array $template_names Array of template paths. 
  1342. */ 
  1343. return bp_locate_template( apply_filters( 'bp_displayed_user_get_front_template', $template_names ), false, true ); 
  1344.  
  1345. /** 
  1346. * Check if the displayed user has a custom front template. 
  1347. * 
  1348. * @since 2.6.0 
  1349. */ 
  1350. function bp_displayed_user_has_front_template() { 
  1351. $displayed_user = bp_get_displayed_user(); 
  1352.  
  1353. return ! empty( $displayed_user->front_template ); 
  1354.  
  1355. /** 
  1356. * Render the navigation markup for the displayed user. 
  1357. * 
  1358. * @since 1.1.0 
  1359. */ 
  1360. function bp_get_displayed_user_nav() { 
  1361. $bp = buddypress(); 
  1362.  
  1363. foreach ( $bp->members->nav->get_primary() as $user_nav_item ) { 
  1364. if ( empty( $user_nav_item->show_for_displayed_user ) && ! bp_is_my_profile() ) { 
  1365. continue; 
  1366.  
  1367. $selected = ''; 
  1368. if ( bp_is_current_component( $user_nav_item->slug ) ) { 
  1369. $selected = ' class="current selected"'; 
  1370.  
  1371. if ( bp_loggedin_user_domain() ) { 
  1372. $link = str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $user_nav_item->link ); 
  1373. } else { 
  1374. $link = trailingslashit( bp_displayed_user_domain() . $user_nav_item->link ); 
  1375.  
  1376. /** 
  1377. * Filters the navigation markup for the displayed user. 
  1378. * 
  1379. * This is a dynamic filter that is dependent on the navigation tab component being rendered. 
  1380. * 
  1381. * @since 1.1.0 
  1382. * 
  1383. * @param string $value Markup for the tab list item including link. 
  1384. * @param array $user_nav_item Array holding parts used to construct tab list item. 
  1385. * Passed by reference. 
  1386. */ 
  1387. echo apply_filters_ref_array( 'bp_get_displayed_user_nav_' . $user_nav_item->css_id, array( '<li id="' . $user_nav_item->css_id . '-personal-li" ' . $selected . '><a id="user-' . $user_nav_item->css_id . '" href="' . $link . '">' . $user_nav_item->name . '</a></li>', &$user_nav_item ) ); 
  1388.  
  1389. /** Cover image ***************************************************************/ 
  1390.  
  1391. /** 
  1392. * Should we use the cover image header 
  1393. * 
  1394. * @since 2.4.0 
  1395. * 
  1396. * @return bool True if the displayed user has a cover image,  
  1397. * False otherwise 
  1398. */ 
  1399. function bp_displayed_user_use_cover_image_header() { 
  1400. return (bool) bp_is_active( 'xprofile', 'cover_image' ) && ! bp_disable_cover_image_uploads() && bp_attachments_is_wp_version_supported(); 
  1401.  
  1402. /** Avatars *******************************************************************/ 
  1403.  
  1404. /** 
  1405. * Output the logged-in user's avatar. 
  1406. * 
  1407. * @since 1.1.0 
  1408. * 
  1409. * @see bp_get_loggedin_user_avatar() for a description of params. 
  1410. * 
  1411. * @param array|string $args Array of arguments for logged in user avatar. 
  1412. */ 
  1413. function bp_loggedin_user_avatar( $args = '' ) { 
  1414. echo bp_get_loggedin_user_avatar( $args ); 
  1415. /** 
  1416. * Get the logged-in user's avatar. 
  1417. * 
  1418. * @since 1.1.0 
  1419. * 
  1420. * @see bp_core_fetch_avatar() For a description of arguments and 
  1421. * return values. 
  1422. * 
  1423. * @param array|string $args { 
  1424. * Arguments are listed here with an explanation of their defaults. 
  1425. * For more information about the arguments, see 
  1426. * {@link bp_core_fetch_avatar()}. 
  1427. * @type string $alt Default: 'Profile picture of [user name]'. 
  1428. * @type bool $html Default: true. 
  1429. * @type string $type Default: 'thumb'. 
  1430. * @type int|bool $width Default: false. 
  1431. * @type int|bool $height Default: false. 
  1432. * } 
  1433. * @return string User avatar string. 
  1434. */ 
  1435. function bp_get_loggedin_user_avatar( $args = '' ) { 
  1436.  
  1437. $r = wp_parse_args( $args, array( 
  1438. 'item_id' => bp_loggedin_user_id(),  
  1439. 'type' => 'thumb',  
  1440. 'width' => false,  
  1441. 'height' => false,  
  1442. 'html' => true,  
  1443. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_loggedin_user_fullname() ) 
  1444. ) ); 
  1445.  
  1446. /** 
  1447. * Filters the logged in user's avatar. 
  1448. * 
  1449. * @since 1.1.0 
  1450. * 
  1451. * @param string $value User avatar string. 
  1452. * @param array $r Array of parsed arguments. 
  1453. * @param array $args Array of initial arguments. 
  1454. */ 
  1455. return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( $r ), $r, $args ); 
  1456.  
  1457. /** 
  1458. * Output the displayed user's avatar. 
  1459. * 
  1460. * @since 1.1.0 
  1461. * 
  1462. * @see bp_get_displayed_user_avatar() for a description of params. 
  1463. * 
  1464. * @param array|string $args Array of arguments for displayed user avatar. 
  1465. */ 
  1466. function bp_displayed_user_avatar( $args = '' ) { 
  1467. echo bp_get_displayed_user_avatar( $args ); 
  1468. /** 
  1469. * Get the displayed user's avatar. 
  1470. * 
  1471. * @since 1.1.0 
  1472. * 
  1473. * @see bp_core_fetch_avatar() For a description of arguments and 
  1474. * return values. 
  1475. * 
  1476. * @param array|string $args { 
  1477. * Arguments are listed here with an explanation of their defaults. 
  1478. * For more information about the arguments, see 
  1479. * {@link bp_core_fetch_avatar()}. 
  1480. * @type string $alt Default: 'Profile picture of [user name]'. 
  1481. * @type bool $html Default: true. 
  1482. * @type string $type Default: 'thumb'. 
  1483. * @type int|bool $width Default: false. 
  1484. * @type int|bool $height Default: false. 
  1485. * } 
  1486. * @return string User avatar string. 
  1487. */ 
  1488. function bp_get_displayed_user_avatar( $args = '' ) { 
  1489.  
  1490. $r = wp_parse_args( $args, array( 
  1491. 'item_id' => bp_displayed_user_id(),  
  1492. 'type' => 'thumb',  
  1493. 'width' => false,  
  1494. 'height' => false,  
  1495. 'html' => true,  
  1496. 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 
  1497. ) ); 
  1498.  
  1499. /** 
  1500. * Filters the displayed user's avatar. 
  1501. * 
  1502. * @since 1.1.0 
  1503. * 
  1504. * @param string $value User avatar string. 
  1505. * @param array $r Array of parsed arguments. 
  1506. * @param array $args Array of initial arguments. 
  1507. */ 
  1508. return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( $r ), $r, $args ); 
  1509.  
  1510. /** 
  1511. * Output the email address of the displayed user. 
  1512. * 
  1513. * @since 1.5.0 
  1514. */ 
  1515. function bp_displayed_user_email() { 
  1516. echo bp_get_displayed_user_email(); 
  1517. /** 
  1518. * Get the email address of the displayed user. 
  1519. * 
  1520. * @since 1.5.0 
  1521. * 
  1522. * @return string 
  1523. */ 
  1524. function bp_get_displayed_user_email() { 
  1525. $bp = buddypress(); 
  1526.  
  1527. // If displayed user exists, return email address. 
  1528. if ( isset( $bp->displayed_user->userdata->user_email ) ) 
  1529. $retval = $bp->displayed_user->userdata->user_email; 
  1530. else 
  1531. $retval = ''; 
  1532.  
  1533. /** 
  1534. * Filters the email address of the displayed user. 
  1535. * 
  1536. * @since 1.5.0 
  1537. * 
  1538. * @param string $retval Email address for displayed user. 
  1539. */ 
  1540. return apply_filters( 'bp_get_displayed_user_email', esc_attr( $retval ) ); 
  1541.  
  1542. /** 
  1543. * Output the "active [x days ago]" string for a user. 
  1544. * 
  1545. * @since 1.0.0 
  1546. * 
  1547. * @see bp_get_last_activity() for a description of parameters. 
  1548. * 
  1549. * @param int $user_id See {@link bp_get_last_activity()}. 
  1550. */ 
  1551. function bp_last_activity( $user_id = 0 ) { 
  1552.  
  1553. /** 
  1554. * Filters the 'active [x days ago]' string for a user. 
  1555. * 
  1556. * @since 1.0.0 
  1557. * 
  1558. * @param string $value Formatted 'active [x days ago]' string. 
  1559. */ 
  1560. echo apply_filters( 'bp_last_activity', bp_get_last_activity( $user_id ) ); 
  1561. /** 
  1562. * Get the "active [x days ago]" string for a user. 
  1563. * 
  1564. * @since 1.5.0 
  1565. * 
  1566. * @param int $user_id ID of the user. Default: displayed user ID. 
  1567. * @return string 
  1568. */ 
  1569. function bp_get_last_activity( $user_id = 0 ) { 
  1570.  
  1571. if ( empty( $user_id ) ) 
  1572. $user_id = bp_displayed_user_id(); 
  1573.  
  1574. $last_activity = bp_core_get_last_activity( bp_get_user_last_activity( $user_id ), __('active %s', 'buddypress') ); 
  1575.  
  1576. /** 
  1577. * Filters the 'active [x days ago]' string for a user. 
  1578. * 
  1579. * @since 1.5.0 
  1580. * @since 2.6.0 Added the `$user_id` parameter. 
  1581. * 
  1582. * @param string $value Formatted 'active [x days ago]' string. 
  1583. * @param int $user_id ID of the user. 
  1584. */ 
  1585. return apply_filters( 'bp_get_last_activity', $last_activity, $user_id ); 
  1586.  
  1587. /** 
  1588. * Output the calculated first name of the displayed or logged-in user. 
  1589. * 
  1590. * @since 1.2.0 
  1591. */ 
  1592. function bp_user_firstname() { 
  1593. echo bp_get_user_firstname(); 
  1594. /** 
  1595. * Output the first name of a user. 
  1596. * 
  1597. * Simply takes all the characters before the first space in a name. 
  1598. * 
  1599. * @since 1.2.0 
  1600. * 
  1601. * @param string|bool $name Full name to use when generating first name. 
  1602. * Defaults to displayed user's first name, or to 
  1603. * logged-in user's first name if it's unavailable. 
  1604. * @return string 
  1605. */ 
  1606. function bp_get_user_firstname( $name = false ) { 
  1607.  
  1608. // Try to get displayed user. 
  1609. if ( empty( $name ) ) 
  1610. $name = bp_get_displayed_user_fullname(); 
  1611.  
  1612. // Fall back on logged in user. 
  1613. if ( empty( $name ) ) 
  1614. $name = bp_get_loggedin_user_fullname(); 
  1615.  
  1616. $fullname = (array) explode( ' ', $name ); 
  1617.  
  1618. /** 
  1619. * Filters the first name of a user. 
  1620. * 
  1621. * @since 1.2.0 
  1622. * 
  1623. * @param string $value First name of user. 
  1624. * @param string $fullname Full name of user. 
  1625. */ 
  1626. return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname ); 
  1627.  
  1628. /** 
  1629. * Output the link for the logged-in user's profile. 
  1630. * 
  1631. * @since 1.2.4 
  1632. */ 
  1633. function bp_loggedin_user_link() { 
  1634. echo esc_url( bp_get_loggedin_user_link() ); 
  1635. /** 
  1636. * Get the link for the logged-in user's profile. 
  1637. * 
  1638. * @since 1.0.0 
  1639. * 
  1640. * @return string 
  1641. */ 
  1642. function bp_get_loggedin_user_link() { 
  1643.  
  1644. /** 
  1645. * Filters the link for the logged-in user's profile. 
  1646. * 
  1647. * @since 1.2.4 
  1648. * 
  1649. * @param string $value Link for the logged-in user's profile. 
  1650. */ 
  1651. return apply_filters( 'bp_get_loggedin_user_link', bp_loggedin_user_domain() ); 
  1652.  
  1653. /** 
  1654. * Output the link for the displayed user's profile. 
  1655. * 
  1656. * @since 1.2.4 
  1657. */ 
  1658. function bp_displayed_user_link() { 
  1659. echo esc_url( bp_get_displayed_user_link() ); 
  1660. /** 
  1661. * Get the link for the displayed user's profile. 
  1662. * 
  1663. * @since 1.0.0 
  1664. * 
  1665. * @return string 
  1666. */ 
  1667. function bp_get_displayed_user_link() { 
  1668.  
  1669. /** 
  1670. * Filters the link for the displayed user's profile. 
  1671. * 
  1672. * @since 1.2.4 
  1673. * 
  1674. * @param string $value Link for the displayed user's profile. 
  1675. */ 
  1676. return apply_filters( 'bp_get_displayed_user_link', bp_displayed_user_domain() ); 
  1677.  
  1678. /** 
  1679. * Alias of {@link bp_displayed_user_domain()}. 
  1680. * 
  1681. * @deprecated 
  1682. */ 
  1683. function bp_user_link() { bp_displayed_user_domain(); } 
  1684.  
  1685. /** 
  1686. * Alias of {@link bp_displayed_user_id()}. 
  1687. * 
  1688. * @since 1.0.0 
  1689. */ 
  1690. function bp_current_user_id() { return bp_displayed_user_id(); } 
  1691.  
  1692. /** 
  1693. * Generate the link for the displayed user's profile. 
  1694. * 
  1695. * @since 1.0.0 
  1696. * 
  1697. * @return string 
  1698. */ 
  1699. function bp_displayed_user_domain() { 
  1700. $bp = buddypress(); 
  1701.  
  1702. /** 
  1703. * Filters the generated link for the displayed user's profile. 
  1704. * 
  1705. * @since 1.0.0 
  1706. * 
  1707. * @param string $value Generated link for the displayed user's profile. 
  1708. */ 
  1709. return apply_filters( 'bp_displayed_user_domain', isset( $bp->displayed_user->domain ) ? $bp->displayed_user->domain : '' ); 
  1710.  
  1711. /** 
  1712. * Generate the link for the logged-in user's profile. 
  1713. * 
  1714. * @since 1.0.0 
  1715. * 
  1716. * @return string 
  1717. */ 
  1718. function bp_loggedin_user_domain() { 
  1719. $bp = buddypress(); 
  1720.  
  1721. /** 
  1722. * Filters the generated link for the logged-in user's profile. 
  1723. * 
  1724. * @since 1.0.0 
  1725. * 
  1726. * @param string $value Generated link for the logged-in user's profile. 
  1727. */ 
  1728. return apply_filters( 'bp_loggedin_user_domain', isset( $bp->loggedin_user->domain ) ? $bp->loggedin_user->domain : '' ); 
  1729.  
  1730. /** 
  1731. * Output the displayed user's display name. 
  1732. * 
  1733. * @since 1.0.0 
  1734. */ 
  1735. function bp_displayed_user_fullname() { 
  1736. echo bp_get_displayed_user_fullname(); 
  1737. /** 
  1738. * Get the displayed user's display name. 
  1739. * 
  1740. * @since 1.2.0 
  1741. * 
  1742. * @return string 
  1743. */ 
  1744. function bp_get_displayed_user_fullname() { 
  1745. $bp = buddypress(); 
  1746.  
  1747. /** 
  1748. * Filters the displayed user's display name. 
  1749. * 
  1750. * @since 1.2.0 
  1751. * 
  1752. * @param string $value Displayed user's display name. 
  1753. */ 
  1754. return apply_filters( 'bp_displayed_user_fullname', isset( $bp->displayed_user->fullname ) ? $bp->displayed_user->fullname : '' ); 
  1755.  
  1756. /** 
  1757. * Alias of {@link bp_get_displayed_user_fullname()}. 
  1758. * 
  1759. * @since 1.0.0 
  1760. */ 
  1761. function bp_user_fullname() { echo bp_get_displayed_user_fullname(); } 
  1762.  
  1763.  
  1764. /** 
  1765. * Output the logged-in user's display name. 
  1766. * 
  1767. * @since 1.0.0 
  1768. */ 
  1769. function bp_loggedin_user_fullname() { 
  1770. echo bp_get_loggedin_user_fullname(); 
  1771. /** 
  1772. * Get the logged-in user's display name. 
  1773. * 
  1774. * @since 1.0.0 
  1775. * 
  1776. * @return string 
  1777. */ 
  1778. function bp_get_loggedin_user_fullname() { 
  1779. $bp = buddypress(); 
  1780.  
  1781. /** 
  1782. * Filters the logged-in user's display name. 
  1783. * 
  1784. * @since 1.0.0 
  1785. * 
  1786. * @param string $value Logged-in user's display name. 
  1787. */ 
  1788. return apply_filters( 'bp_get_loggedin_user_fullname', isset( $bp->loggedin_user->fullname ) ? $bp->loggedin_user->fullname : '' ); 
  1789.  
  1790. /** 
  1791. * Output the username of the displayed user. 
  1792. * 
  1793. * @since 1.2.0 
  1794. */ 
  1795. function bp_displayed_user_username() { 
  1796. echo bp_get_displayed_user_username(); 
  1797. /** 
  1798. * Get the username of the displayed user. 
  1799. * 
  1800. * @since 1.2.0 
  1801. * 
  1802. * @return string 
  1803. */ 
  1804. function bp_get_displayed_user_username() { 
  1805. $bp = buddypress(); 
  1806.  
  1807. if ( bp_displayed_user_id() ) { 
  1808. $username = bp_core_get_username( bp_displayed_user_id(), $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ); 
  1809. } else { 
  1810. $username = ''; 
  1811.  
  1812. /** 
  1813. * Filters the username of the displayed user. 
  1814. * 
  1815. * @since 1.2.0 
  1816. * 
  1817. * @param string $username Username of the displayed user. 
  1818. */ 
  1819. return apply_filters( 'bp_get_displayed_user_username', $username ); 
  1820.  
  1821. /** 
  1822. * Output the username of the logged-in user. 
  1823. * 
  1824. * @since 1.2.0 
  1825. */ 
  1826. function bp_loggedin_user_username() { 
  1827. echo bp_get_loggedin_user_username(); 
  1828. /** 
  1829. * Get the username of the logged-in user. 
  1830. * 
  1831. * @since 1.2.0 
  1832. * 
  1833. * @return string 
  1834. */ 
  1835. function bp_get_loggedin_user_username() { 
  1836. $bp = buddypress(); 
  1837.  
  1838. if ( bp_loggedin_user_id() ) { 
  1839. $username = bp_core_get_username( bp_loggedin_user_id(), $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ); 
  1840. } else { 
  1841. $username = ''; 
  1842.  
  1843. /** 
  1844. * Filters the username of the logged-in user. 
  1845. * 
  1846. * @since 1.2.0 
  1847. * 
  1848. * @param string $username Username of the logged-in user. 
  1849. */ 
  1850. return apply_filters( 'bp_get_loggedin_user_username', $username ); 
  1851.  
  1852. /** 
  1853. * Echo the current member type message. 
  1854. * 
  1855. * @since 2.3.0 
  1856. */ 
  1857. function bp_current_member_type_message() { 
  1858. echo bp_get_current_member_type_message(); 
  1859. /** 
  1860. * Generate the current member type message. 
  1861. * 
  1862. * @since 2.3.0 
  1863. * 
  1864. * @return string 
  1865. */ 
  1866. function bp_get_current_member_type_message() { 
  1867. $type_object = bp_get_member_type_object( bp_get_current_member_type() ); 
  1868.  
  1869. $message = sprintf( __( 'Viewing members of the type: %s', 'buddypress' ), '<strong>' . $type_object->labels['singular_name'] . '</strong>' ); 
  1870.  
  1871. /** 
  1872. * Filters the current member type message. 
  1873. * 
  1874. * @since 2.3.0 
  1875. * 
  1876. * @param string $message Message to filter. 
  1877. */ 
  1878. return apply_filters( 'bp_get_current_member_type_message', $message ); 
  1879.  
  1880. /** Signup Form ***************************************************************/ 
  1881.  
  1882. /** 
  1883. * Do we have a working custom sign up page? 
  1884. * 
  1885. * @since 1.5.0 
  1886. * 
  1887. * @return bool True if page and template exist, false if not. 
  1888. */ 
  1889. function bp_has_custom_signup_page() { 
  1890. static $has_page = false; 
  1891.  
  1892. if ( empty( $has_page ) ) 
  1893. $has_page = bp_get_signup_slug() && bp_locate_template( array( 'registration/register.php', 'members/register.php', 'register.php' ), false ); 
  1894.  
  1895. return (bool) $has_page; 
  1896.  
  1897. /** 
  1898. * Output the URL to the signup page. 
  1899. * 
  1900. * @since 1.0.0 
  1901. */ 
  1902. function bp_signup_page() { 
  1903. echo esc_url( bp_get_signup_page() ); 
  1904. /** 
  1905. * Get the URL to the signup page. 
  1906. * 
  1907. * @since 1.1.0 
  1908. * 
  1909. * @return string 
  1910. */ 
  1911. function bp_get_signup_page() { 
  1912. if ( bp_has_custom_signup_page() ) { 
  1913. $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_signup_slug() ); 
  1914. } else { 
  1915. $page = bp_get_root_domain() . '/wp-signup.php'; 
  1916.  
  1917. /** 
  1918. * Filters the URL to the signup page. 
  1919. * 
  1920. * @since 1.1.0 
  1921. * 
  1922. * @param string $page URL to the signup page. 
  1923. */ 
  1924. return apply_filters( 'bp_get_signup_page', $page ); 
  1925.  
  1926. /** 
  1927. * Do we have a working custom activation page? 
  1928. * 
  1929. * @since 1.5.0 
  1930. * 
  1931. * @return boolean True if page and template exist, false if not. 
  1932. */ 
  1933. function bp_has_custom_activation_page() { 
  1934. static $has_page = false; 
  1935.  
  1936. if ( empty( $has_page ) ) 
  1937. $has_page = bp_get_activate_slug() && bp_locate_template( array( 'registration/activate.php', 'members/activate.php', 'activate.php' ), false ); 
  1938.  
  1939. return (bool) $has_page; 
  1940.  
  1941. /** 
  1942. * Output the URL of the activation page. 
  1943. * 
  1944. * @since 1.0.0 
  1945. */ 
  1946. function bp_activation_page() { 
  1947. echo esc_url( bp_get_activation_page() ); 
  1948. /** 
  1949. * Get the URL of the activation page. 
  1950. * 
  1951. * @since 1.2.0 
  1952. * 
  1953. * @return string 
  1954. */ 
  1955. function bp_get_activation_page() { 
  1956. if ( bp_has_custom_activation_page() ) { 
  1957. $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_activate_slug() ); 
  1958. } else { 
  1959. $page = trailingslashit( bp_get_root_domain() ) . 'wp-activate.php'; 
  1960.  
  1961. /** 
  1962. * Filters the URL of the activation page. 
  1963. * 
  1964. * @since 1.2.0 
  1965. * 
  1966. * @param string $page URL to the activation page. 
  1967. */ 
  1968. return apply_filters( 'bp_get_activation_page', $page ); 
  1969.  
  1970. /** 
  1971. * Output the username submitted during signup. 
  1972. * 
  1973. * @since 1.1.0 
  1974. */ 
  1975. function bp_signup_username_value() { 
  1976. echo bp_get_signup_username_value(); 
  1977. /** 
  1978. * Get the username submitted during signup. 
  1979. * 
  1980. * @since 1.1.0 
  1981. * 
  1982. * @todo This should be properly escaped. 
  1983. * 
  1984. * @return string 
  1985. */ 
  1986. function bp_get_signup_username_value() { 
  1987. $value = ''; 
  1988. if ( isset( $_POST['signup_username'] ) ) 
  1989. $value = $_POST['signup_username']; 
  1990.  
  1991. /** 
  1992. * Filters the username submitted during signup. 
  1993. * 
  1994. * @since 1.1.0 
  1995. * 
  1996. * @param string $value Username submitted during signup. 
  1997. */ 
  1998. return apply_filters( 'bp_get_signup_username_value', $value ); 
  1999.  
  2000. /** 
  2001. * Output the user email address submitted during signup. 
  2002. * 
  2003. * @since 1.1.0 
  2004. */ 
  2005. function bp_signup_email_value() { 
  2006. echo bp_get_signup_email_value(); 
  2007. /** 
  2008. * Get the email address submitted during signup. 
  2009. * 
  2010. * @since 1.1.0 
  2011. * 
  2012. * @todo This should be properly escaped. 
  2013. * 
  2014. * @return string 
  2015. */ 
  2016. function bp_get_signup_email_value() { 
  2017. $value = ''; 
  2018. if ( isset( $_POST['signup_email'] ) ) 
  2019. $value = $_POST['signup_email']; 
  2020.  
  2021. /** 
  2022. * Filters the email address submitted during signup. 
  2023. * 
  2024. * @since 1.1.0 
  2025. * 
  2026. * @param string $value Email address submitted during signup. 
  2027. */ 
  2028. return apply_filters( 'bp_get_signup_email_value', $value ); 
  2029.  
  2030. /** 
  2031. * Output the 'signup_with_blog' value submitted during signup. 
  2032. * 
  2033. * @since 1.1.0 
  2034. */ 
  2035. function bp_signup_with_blog_value() { 
  2036. echo bp_get_signup_with_blog_value(); 
  2037. /** 
  2038. * Get the 'signup_with_blog' value submitted during signup. 
  2039. * 
  2040. * @since 1.1.0 
  2041. * 
  2042. * @return string 
  2043. */ 
  2044. function bp_get_signup_with_blog_value() { 
  2045. $value = ''; 
  2046. if ( isset( $_POST['signup_with_blog'] ) ) 
  2047. $value = $_POST['signup_with_blog']; 
  2048.  
  2049. /** 
  2050. * Filters the 'signup_with_blog' value submitted during signup. 
  2051. * 
  2052. * @since 1.1.0 
  2053. * 
  2054. * @param string $value 'signup_with_blog' value submitted during signup. 
  2055. */ 
  2056. return apply_filters( 'bp_get_signup_with_blog_value', $value ); 
  2057.  
  2058. /** 
  2059. * Output the 'signup_blog_url' value submitted at signup. 
  2060. * 
  2061. * @since 1.1.0 
  2062. */ 
  2063. function bp_signup_blog_url_value() { 
  2064. echo bp_get_signup_blog_url_value(); 
  2065. /** 
  2066. * Get the 'signup_blog_url' value submitted at signup. 
  2067. * 
  2068. * @since 1.1.0 
  2069. * 
  2070. * @todo Should be properly escaped. 
  2071. * 
  2072. * @return string 
  2073. */ 
  2074. function bp_get_signup_blog_url_value() { 
  2075. $value = ''; 
  2076. if ( isset( $_POST['signup_blog_url'] ) ) 
  2077. $value = $_POST['signup_blog_url']; 
  2078.  
  2079. /** 
  2080. * Filters the 'signup_blog_url' value submitted during signup. 
  2081. * 
  2082. * @since 1.1.0 
  2083. * 
  2084. * @param string $value 'signup_blog_url' value submitted during signup. 
  2085. */ 
  2086. return apply_filters( 'bp_get_signup_blog_url_value', $value ); 
  2087.  
  2088. /** 
  2089. * Output the base URL for subdomain installations of WordPress Multisite. 
  2090. * 
  2091. * @since 2.1.0 
  2092. */ 
  2093. function bp_signup_subdomain_base() { 
  2094. echo bp_signup_get_subdomain_base(); 
  2095. /** 
  2096. * Return the base URL for subdomain installations of WordPress Multisite. 
  2097. * 
  2098. * Replaces bp_blogs_get_subdomain_base() 
  2099. * 
  2100. * @since 2.1.0 
  2101. * 
  2102. * @return string The base URL - eg, 'example.com' for site_url() example.com or www.example.com. 
  2103. */ 
  2104. function bp_signup_get_subdomain_base() { 
  2105. global $current_site; 
  2106.  
  2107. // In case plugins are still using this filter. 
  2108. $subdomain_base = apply_filters( 'bp_blogs_subdomain_base', preg_replace( '|^www\.|', '', $current_site->domain ) . $current_site->path ); 
  2109.  
  2110. /** 
  2111. * Filters the base URL for subdomain installations of WordPress Multisite. 
  2112. * 
  2113. * @since 2.1.0 
  2114. * 
  2115. * @param string $subdomain_base The base URL - eg, 'example.com' for 
  2116. * site_url() example.com or www.example.com. 
  2117. */ 
  2118. return apply_filters( 'bp_signup_subdomain_base', $subdomain_base ); 
  2119.  
  2120. /** 
  2121. * Output the 'signup_blog_titl' value submitted at signup. 
  2122. * 
  2123. * @since 1.1.0 
  2124. */ 
  2125. function bp_signup_blog_title_value() { 
  2126. echo bp_get_signup_blog_title_value(); 
  2127. /** 
  2128. * Get the 'signup_blog_title' value submitted at signup. 
  2129. * 
  2130. * @since 1.1.0 
  2131. * 
  2132. * @todo Should be properly escaped. 
  2133. * 
  2134. * @return string 
  2135. */ 
  2136. function bp_get_signup_blog_title_value() { 
  2137. $value = ''; 
  2138. if ( isset( $_POST['signup_blog_title'] ) ) 
  2139. $value = $_POST['signup_blog_title']; 
  2140.  
  2141. /** 
  2142. * Filters the 'signup_blog_title' value submitted during signup. 
  2143. * 
  2144. * @since 1.1.0 
  2145. * 
  2146. * @param string $value 'signup_blog_title' value submitted during signup. 
  2147. */ 
  2148. return apply_filters( 'bp_get_signup_blog_title_value', $value ); 
  2149.  
  2150. /** 
  2151. * Output the 'signup_blog_privacy' value submitted at signup. 
  2152. * 
  2153. * @since 1.1.0 
  2154. */ 
  2155. function bp_signup_blog_privacy_value() { 
  2156. echo bp_get_signup_blog_privacy_value(); 
  2157. /** 
  2158. * Get the 'signup_blog_privacy' value submitted at signup. 
  2159. * 
  2160. * @since 1.1.0 
  2161. * 
  2162. * @todo Should be properly escaped. 
  2163. * 
  2164. * @return string 
  2165. */ 
  2166. function bp_get_signup_blog_privacy_value() { 
  2167. $value = ''; 
  2168. if ( isset( $_POST['signup_blog_privacy'] ) ) 
  2169. $value = $_POST['signup_blog_privacy']; 
  2170.  
  2171. /** 
  2172. * Filters the 'signup_blog_privacy' value submitted during signup. 
  2173. * 
  2174. * @since 1.1.0 
  2175. * 
  2176. * @param string $value 'signup_blog_privacy' value submitted during signup. 
  2177. */ 
  2178. return apply_filters( 'bp_get_signup_blog_privacy_value', $value ); 
  2179.  
  2180. /** 
  2181. * Output the avatar dir used during signup. 
  2182. * 
  2183. * @since 1.1.0 
  2184. */ 
  2185. function bp_signup_avatar_dir_value() { 
  2186. echo bp_get_signup_avatar_dir_value(); 
  2187. /** 
  2188. * Get the avatar dir used during signup. 
  2189. * 
  2190. * @since 1.1.0 
  2191. * 
  2192. * @return string 
  2193. */ 
  2194. function bp_get_signup_avatar_dir_value() { 
  2195. $bp = buddypress(); 
  2196.  
  2197. // Check if signup_avatar_dir is passed. 
  2198. if ( !empty( $_POST['signup_avatar_dir'] ) ) 
  2199. $signup_avatar_dir = $_POST['signup_avatar_dir']; 
  2200.  
  2201. // If not, check if global is set. 
  2202. elseif ( !empty( $bp->signup->avatar_dir ) ) 
  2203. $signup_avatar_dir = $bp->signup->avatar_dir; 
  2204.  
  2205. // If not, set false. 
  2206. else 
  2207. $signup_avatar_dir = false; 
  2208.  
  2209. /** 
  2210. * Filters the avatar dir used during signup. 
  2211. * 
  2212. * @since 1.1.0 
  2213. * 
  2214. * @param string|bool $signup_avatar_dir Avatar dir used during signup or false. 
  2215. */ 
  2216. return apply_filters( 'bp_get_signup_avatar_dir_value', $signup_avatar_dir ); 
  2217.  
  2218. /** 
  2219. * Output the current signup step. 
  2220. * 
  2221. * @since 1.1.0 
  2222. */ 
  2223. function bp_current_signup_step() { 
  2224. echo bp_get_current_signup_step(); 
  2225. /** 
  2226. * Get the current signup step. 
  2227. * 
  2228. * @since 1.1.0 
  2229. * 
  2230. * @return string 
  2231. */ 
  2232. function bp_get_current_signup_step() { 
  2233. return buddypress()->signup->step; 
  2234.  
  2235. /** 
  2236. * Output the user avatar during signup. 
  2237. * 
  2238. * @since 1.1.0 
  2239. * 
  2240. * @see bp_get_signup_avatar() for description of arguments. 
  2241. * 
  2242. * @param array|string $args See {@link bp_get_signup_avatar(}. 
  2243. */ 
  2244. function bp_signup_avatar( $args = '' ) { 
  2245. echo bp_get_signup_avatar( $args ); 
  2246. /** 
  2247. * Get the user avatar during signup. 
  2248. * 
  2249. * @since 1.1.0 
  2250. * 
  2251. * @see bp_core_fetch_avatar() for description of arguments. 
  2252. * 
  2253. * @param array|string $args { 
  2254. * Array of optional arguments. 
  2255. * @type int $size Height/weight in pixels. Default: value of 
  2256. * bp_core_avatar_full_width(). 
  2257. * @type string $class CSS class. Default: 'avatar'. 
  2258. * @type string $alt HTML 'alt' attribute. Default: 'Your Avatar'. 
  2259. * } 
  2260. * @return string 
  2261. */ 
  2262. function bp_get_signup_avatar( $args = '' ) { 
  2263. $bp = buddypress(); 
  2264.  
  2265. $defaults = array( 
  2266. 'size' => bp_core_avatar_full_width(),  
  2267. 'class' => 'avatar',  
  2268. 'alt' => __( 'Your Profile Photo', 'buddypress' ) 
  2269. ); 
  2270.  
  2271. $r = wp_parse_args( $args, $defaults ); 
  2272. extract( $r, EXTR_SKIP ); 
  2273.  
  2274. // Avatar DIR is found. 
  2275. if ( $signup_avatar_dir = bp_get_signup_avatar_dir_value() ) { 
  2276. $gravatar_img = bp_core_fetch_avatar( array( 
  2277. 'item_id' => $signup_avatar_dir,  
  2278. 'object' => 'signup',  
  2279. 'avatar_dir' => 'avatars/signups',  
  2280. 'type' => 'full',  
  2281. 'width' => $size,  
  2282. 'height' => $size,  
  2283. 'alt' => $alt,  
  2284. 'class' => $class 
  2285. ) ); 
  2286.  
  2287. // No avatar DIR was found. 
  2288. } else { 
  2289.  
  2290. // Set default gravatar type. 
  2291. if ( empty( $bp->grav_default->user ) ) 
  2292. $default_grav = 'wavatar'; 
  2293. elseif ( 'mystery' == $bp->grav_default->user ) 
  2294. $default_grav = $bp->plugin_url . 'bp-core/images/mystery-man.jpg'; 
  2295. else 
  2296. $default_grav = $bp->grav_default->user; 
  2297.  
  2298. /** 
  2299. * Filters the base Gravatar url used for signup avatars when no avatar dir found. 
  2300. * 
  2301. * @since 1.0.2 
  2302. * 
  2303. * @param string $value Gravatar url to use. 
  2304. */ 
  2305. $gravatar_url = apply_filters( 'bp_gravatar_url', '//www.gravatar.com/avatar/' ); 
  2306. $md5_lcase_email = md5( strtolower( bp_get_signup_email_value() ) ); 
  2307. $gravatar_img = '<img src="' . $gravatar_url . $md5_lcase_email . '?d=' . $default_grav . '&s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />'; 
  2308.  
  2309. /** 
  2310. * Filters the user avatar during signup. 
  2311. * 
  2312. * @since 1.1.0 
  2313. * 
  2314. * @param string $gravatar_img Avatar HTML image tag. 
  2315. * @param array $args Array of parsed args for avatar query. 
  2316. */ 
  2317. return apply_filters( 'bp_get_signup_avatar', $gravatar_img, $args ); 
  2318.  
  2319. /** 
  2320. * Output whether signup is allowed. 
  2321. * 
  2322. * @since 1.1.0 
  2323. * 
  2324. * @todo Remove this function. Echoing a bool is pointless. 
  2325. */ 
  2326. function bp_signup_allowed() { 
  2327. echo bp_get_signup_allowed(); 
  2328. /** 
  2329. * Is user signup allowed? 
  2330. * 
  2331. * @since 1.1.0 
  2332. * 
  2333. * @return bool 
  2334. */ 
  2335. function bp_get_signup_allowed() { 
  2336. /** 
  2337. * Filters whether or not new signups are allowed. 
  2338. * 
  2339. * @since 1.5.0 
  2340. * 
  2341. * @param bool $signup_allowed Whether or not new signups are allowed. 
  2342. */ 
  2343. return apply_filters( 'bp_get_signup_allowed', (bool) bp_get_option( 'users_can_register' ) ); 
  2344.  
  2345. /** 
  2346. * Hook member activity feed to <head>. 
  2347. * 
  2348. * @since 1.5.0 
  2349. */ 
  2350. function bp_members_activity_feed() { 
  2351. if ( !bp_is_active( 'activity' ) || !bp_is_user() ) 
  2352. return; ?> 
  2353.  
  2354. <link rel="alternate" type="application/rss+xml" title="<?php bloginfo( 'name' ) ?> | <?php bp_displayed_user_fullname() ?> | <?php _e( 'Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_member_activity_feed_link() ?>" /> 
  2355.  
  2356. <?php 
  2357. add_action( 'bp_head', 'bp_members_activity_feed' ); 
  2358.  
  2359. /** 
  2360. * Output a link to a members component subpage. 
  2361. * 
  2362. * @since 1.5.0 
  2363. * 
  2364. * @see bp_get_members_component_link() for description of parameters. 
  2365. * 
  2366. * @param string $component See {@bp_get_members_component_link()}. 
  2367. * @param string $action See {@bp_get_members_component_link()}. 
  2368. * @param string $query_args See {@bp_get_members_component_link()}. 
  2369. * @param string|bool $nonce See {@bp_get_members_component_link()}. 
  2370. */ 
  2371. function bp_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) { 
  2372. echo esc_url( bp_get_members_component_link( $component, $action, $query_args, $nonce ) ); 
  2373. /** 
  2374. * Generate a link to a members component subpage. 
  2375. * 
  2376. * @since 1.5.0 
  2377. * 
  2378. * @param string $component ID of the component (eg 'friends'). 
  2379. * @param string $action Optional. 'action' slug (eg 'invites'). 
  2380. * @param array|string $query_args Optional. Array of URL params to add to the 
  2381. * URL. See {@link add_query_arg()} for format. 
  2382. * @param array|bool $nonce Optional. If provided, the URL will be passed 
  2383. * through wp_nonce_url() with $nonce as the 
  2384. * action string. 
  2385. * @return string 
  2386. */ 
  2387. function bp_get_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) { 
  2388.  
  2389. // Must be displayed user. 
  2390. if ( !bp_displayed_user_id() ) 
  2391. return; 
  2392.  
  2393. $bp = buddypress(); 
  2394.  
  2395. // Append $action to $url if there is no $type. 
  2396. if ( !empty( $action ) ) 
  2397. $url = bp_displayed_user_domain() . $bp->{$component}->slug . '/' . $action; 
  2398. else 
  2399. $url = bp_displayed_user_domain() . $bp->{$component}->slug; 
  2400.  
  2401. // Add a slash at the end of our user url. 
  2402. $url = trailingslashit( $url ); 
  2403.  
  2404. // Add possible query arg. 
  2405. if ( !empty( $query_args ) && is_array( $query_args ) ) 
  2406. $url = add_query_arg( $query_args, $url ); 
  2407.  
  2408. // To nonce, or not to nonce... 
  2409. if ( true === $nonce ) 
  2410. $url = wp_nonce_url( $url ); 
  2411. elseif ( is_string( $nonce ) ) 
  2412. $url = wp_nonce_url( $url, $nonce ); 
  2413.  
  2414. // Return the url, if there is one. 
  2415. if ( !empty( $url ) ) 
  2416. return $url; 
.