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