/bp-core/bp-core-template.php

  1. <?php 
  2. /** 
  3. * Core component template tag functions. 
  4. * 
  5. * @package BuddyPress 
  6. * @subpackage TemplateFunctions 
  7. * @since 1.5.0 
  8. */ 
  9.  
  10. // Exit if accessed directly. 
  11. defined( 'ABSPATH' ) || exit; 
  12.  
  13. /** 
  14. * Output the "options nav", the secondary-level single item navigation menu. 
  15. * 
  16. * Uses the component's nav global to render out the sub navigation for the 
  17. * current component. Each component adds to its sub navigation array within 
  18. * its own setup_nav() function. 
  19. * 
  20. * This sub navigation array is the secondary level navigation, so for profile 
  21. * it contains: 
  22. * [Public, Edit Profile, Change Avatar] 
  23. * 
  24. * The function will also analyze the current action for the current component 
  25. * to determine whether or not to highlight a particular sub nav item. 
  26. * 
  27. * @since 1.0.0 
  28. * 
  29. * viewed user. 
  30. * 
  31. * @param string $parent_slug Options nav slug. 
  32. * @return string 
  33. */ 
  34. function bp_get_options_nav( $parent_slug = '' ) { 
  35. $bp = buddypress(); 
  36.  
  37. // If we are looking at a member profile, then the we can use the current 
  38. // component as an index. Otherwise we need to use the component's root_slug. 
  39. $component_index = !empty( $bp->displayed_user ) ? bp_current_component() : bp_get_root_slug( bp_current_component() ); 
  40. $selected_item = bp_current_action(); 
  41.  
  42. // Default to the Members nav. 
  43. if ( ! bp_is_single_item() ) { 
  44. // Set the parent slug, if not provided. 
  45. if ( empty( $parent_slug ) ) { 
  46. $parent_slug = $component_index; 
  47.  
  48. $secondary_nav_items = $bp->members->nav->get_secondary( array( 'parent_slug' => $parent_slug ) ); 
  49.  
  50. if ( ! $secondary_nav_items ) { 
  51. return false; 
  52.  
  53. // For a single item, try to use the component's nav. 
  54. } else { 
  55. $current_item = bp_current_item(); 
  56. $single_item_component = bp_current_component(); 
  57.  
  58. // Adjust the selected nav item for the current single item if needed. 
  59. if ( ! empty( $parent_slug ) ) { 
  60. $current_item = $parent_slug; 
  61. $selected_item = bp_action_variable( 0 ); 
  62.  
  63. // If the nav is not defined by the parent component, look in the Members nav. 
  64. if ( ! isset( $bp->{$single_item_component}->nav ) ) { 
  65. $secondary_nav_items = $bp->members->nav->get_secondary( array( 'parent_slug' => $current_item ) ); 
  66. } else { 
  67. $secondary_nav_items = $bp->{$single_item_component}->nav->get_secondary( array( 'parent_slug' => $current_item ) ); 
  68.  
  69. if ( ! $secondary_nav_items ) { 
  70. return false; 
  71.  
  72. // Loop through each navigation item. 
  73. foreach ( $secondary_nav_items as $subnav_item ) { 
  74. if ( empty( $subnav_item->user_has_access ) ) { 
  75. continue; 
  76.  
  77. // If the current action or an action variable matches the nav item id, then add a highlight CSS class. 
  78. if ( $subnav_item->slug === $selected_item ) { 
  79. $selected = ' class="current selected"'; 
  80. } else { 
  81. $selected = ''; 
  82.  
  83. // List type depends on our current component. 
  84. $list_type = bp_is_group() ? 'groups' : 'personal'; 
  85.  
  86. /** 
  87. * Filters the "options nav", the secondary-level single item navigation menu. 
  88. * 
  89. * This is a dynamic filter that is dependent on the provided css_id value. 
  90. * 
  91. * @since 1.1.0 
  92. * 
  93. * @param string $value HTML list item for the submenu item. 
  94. * @param array $subnav_item Submenu array item being displayed. 
  95. * @param string $selected_item Current action. 
  96. */ 
  97. echo apply_filters( 'bp_get_options_nav_' . $subnav_item->css_id, '<li id="' . esc_attr( $subnav_item->css_id . '-' . $list_type . '-li' ) . '" ' . $selected . '><a id="' . esc_attr( $subnav_item->css_id ) . '" href="' . esc_url( $subnav_item->link ) . '">' . $subnav_item->name . '</a></li>', $subnav_item, $selected_item ); 
  98.  
  99. /** 
  100. * Get the 'bp_options_title' property from the BP global. 
  101. * 
  102. * Not currently used in BuddyPress. 
  103. * 
  104. * @todo Deprecate. 
  105. */ 
  106. function bp_get_options_title() { 
  107. $bp = buddypress(); 
  108.  
  109. if ( empty( $bp->bp_options_title ) ) { 
  110. $bp->bp_options_title = __( 'Options', 'buddypress' ); 
  111.  
  112. echo apply_filters( 'bp_get_options_title', esc_attr( $bp->bp_options_title ) ); 
  113.  
  114. /** 
  115. * Get the directory title for a component. 
  116. * 
  117. * Used for the <title> element and the page header on the component directory 
  118. * page. 
  119. * 
  120. * @since 2.0.0 
  121. * 
  122. * @param string $component Component to get directory title for. 
  123. * @return string 
  124. */ 
  125. function bp_get_directory_title( $component = '' ) { 
  126. $title = ''; 
  127.  
  128. // Use the string provided by the component. 
  129. if ( ! empty( buddypress()->{$component}->directory_title ) ) { 
  130. $title = buddypress()->{$component}->directory_title; 
  131.  
  132. // If none is found, concatenate. 
  133. } elseif ( isset( buddypress()->{$component}->name ) ) { 
  134. $title = sprintf( __( '%s Directory', 'buddypress' ), buddypress()->{$component}->name ); 
  135.  
  136. /** 
  137. * Filters the directory title for a component. 
  138. * 
  139. * @since 2.0.0 
  140. * 
  141. * @param string $title Text to be used in <title> tag. 
  142. * @param string $component Current componet being displayed. 
  143. */ 
  144. return apply_filters( 'bp_get_directory_title', $title, $component ); 
  145.  
  146. /** Avatars *******************************************************************/ 
  147.  
  148. /** 
  149. * Check to see if there is an options avatar. 
  150. * 
  151. * An options avatar is an avatar for something like a group, or a friend. 
  152. * Basically an avatar that appears in the sub nav options bar. 
  153. * 
  154. * Not currently used in BuddyPress. 
  155. * 
  156. * @return bool $value Returns true if an options avatar has been set, otherwise false. 
  157. */ 
  158. function bp_has_options_avatar() { 
  159. return (bool) buddypress()->bp_options_avatar; 
  160.  
  161. /** 
  162. * Output the options avatar. 
  163. * 
  164. * Not currently used in BuddyPress. 
  165. * 
  166. * @todo Deprecate. 
  167. */ 
  168. function bp_get_options_avatar() { 
  169. echo apply_filters( 'bp_get_options_avatar', buddypress()->bp_options_avatar ); 
  170.  
  171. /** 
  172. * Output a comment author's avatar. 
  173. * 
  174. * Not currently used in BuddyPress. 
  175. */ 
  176. function bp_comment_author_avatar() { 
  177. global $comment; 
  178.  
  179. if ( function_exists( 'bp_core_fetch_avatar' ) ) { 
  180. echo apply_filters( 'bp_comment_author_avatar', bp_core_fetch_avatar( array( 
  181. 'item_id' => $comment->user_id,  
  182. 'type' => 'thumb',  
  183. 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), bp_core_get_user_displayname( $comment->user_id ) ) 
  184. ) ) ); 
  185. } elseif ( function_exists( 'get_avatar' ) ) { 
  186. get_avatar(); 
  187.  
  188. /** 
  189. * Output a post author's avatar. 
  190. * 
  191. * Not currently used in BuddyPress. 
  192. */ 
  193. function bp_post_author_avatar() { 
  194. global $post; 
  195.  
  196. if ( function_exists( 'bp_core_fetch_avatar' ) ) { 
  197. echo apply_filters( 'bp_post_author_avatar', bp_core_fetch_avatar( array( 
  198. 'item_id' => $post->post_author,  
  199. 'type' => 'thumb',  
  200. 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), bp_core_get_user_displayname( $post->post_author ) ) 
  201. ) ) ); 
  202. } elseif ( function_exists( 'get_avatar' ) ) { 
  203. get_avatar(); 
  204.  
  205. /** 
  206. * Output the current avatar upload step. 
  207. * 
  208. * @since 1.1.0 
  209. */ 
  210. function bp_avatar_admin_step() { 
  211. echo bp_get_avatar_admin_step(); 
  212. /** 
  213. * Return the current avatar upload step. 
  214. * 
  215. * @since 1.1.0 
  216. * 
  217. * @return string The current avatar upload step. Returns 'upload-image' 
  218. * if none is found. 
  219. */ 
  220. function bp_get_avatar_admin_step() { 
  221. $bp = buddypress(); 
  222. $step = isset( $bp->avatar_admin->step ) 
  223. ? $step = $bp->avatar_admin->step 
  224. : 'upload-image'; 
  225.  
  226. /** 
  227. * Filters the current avatar upload step. 
  228. * 
  229. * @since 1.1.0 
  230. * 
  231. * @param string $step The current avatar upload step. 
  232. */ 
  233. return apply_filters( 'bp_get_avatar_admin_step', $step ); 
  234.  
  235. /** 
  236. * Output the URL of the avatar to crop. 
  237. * 
  238. * @since 1.1.0 
  239. */ 
  240. function bp_avatar_to_crop() { 
  241. echo bp_get_avatar_to_crop(); 
  242. /** 
  243. * Return the URL of the avatar to crop. 
  244. * 
  245. * @since 1.1.0 
  246. * 
  247. * @return string URL of the avatar awaiting cropping. 
  248. */ 
  249. function bp_get_avatar_to_crop() { 
  250. $bp = buddypress(); 
  251. $url = isset( $bp->avatar_admin->image->url ) 
  252. ? $bp->avatar_admin->image->url 
  253. : ''; 
  254.  
  255. /** 
  256. * Filters the URL of the avatar to crop. 
  257. * 
  258. * @since 1.1.0 
  259. * 
  260. * @param string $url URL for the avatar. 
  261. */ 
  262. return apply_filters( 'bp_get_avatar_to_crop', $url ); 
  263.  
  264. /** 
  265. * Output the relative file path to the avatar to crop. 
  266. * 
  267. * @since 1.1.0 
  268. */ 
  269. function bp_avatar_to_crop_src() { 
  270. echo bp_get_avatar_to_crop_src(); 
  271. /** 
  272. * Return the relative file path to the avatar to crop. 
  273. * 
  274. * @since 1.1.0 
  275. * 
  276. * @return string Relative file path to the avatar. 
  277. */ 
  278. function bp_get_avatar_to_crop_src() { 
  279. $bp = buddypress(); 
  280. $src = isset( $bp->avatar_admin->image->dir ) 
  281. ? str_replace( WP_CONTENT_DIR, '', $bp->avatar_admin->image->dir ) 
  282. : ''; 
  283.  
  284. /** 
  285. * Filters the relative file path to the avatar to crop. 
  286. * 
  287. * @since 1.1.0 
  288. * 
  289. * @param string $src Relative file path for the avatar. 
  290. */ 
  291. return apply_filters( 'bp_get_avatar_to_crop_src', $src ); 
  292.  
  293. /** 
  294. * Output the avatar cropper <img> markup. 
  295. * 
  296. * No longer used in BuddyPress. 
  297. * 
  298. * @todo Deprecate. 
  299. */ 
  300. function bp_avatar_cropper() { 
  301. ?> 
  302. <img id="avatar-to-crop" class="avatar" src="<?php echo esc_url( buddypress()->avatar_admin->image ); ?>" /> 
  303. <?php 
  304.  
  305. /** 
  306. * Output the name of the BP site. Used in RSS headers. 
  307. * 
  308. * @since 1.0.0 
  309. */ 
  310. function bp_site_name() { 
  311. echo bp_get_site_name(); 
  312. /** 
  313. * Returns the name of the BP site. Used in RSS headers. 
  314. * 
  315. * @since 1.6.0 
  316. * 
  317. * @return string 
  318. */ 
  319. function bp_get_site_name() { 
  320.  
  321. /** 
  322. * Filters the name of the BP site. Used in RSS headers. 
  323. * 
  324. * @since 1.0.0 
  325. * 
  326. * @param string $value Current BP site name. 
  327. */ 
  328. return apply_filters( 'bp_site_name', get_bloginfo( 'name', 'display' ) ); 
  329.  
  330. /** 
  331. * Format a date based on a UNIX timestamp. 
  332. * 
  333. * This function can be used to turn a UNIX timestamp into a properly formatted 
  334. * (and possibly localized) string, userful for ouputting the date & time an 
  335. * action took place. 
  336. * 
  337. * Not to be confused with `bp_core_time_since()`, this function is best used 
  338. * for displaying a more exact date and time vs. a human-readable time. 
  339. * 
  340. * Note: This function may be improved or removed at a later date, as it is 
  341. * hardly used and adds an additional layer of complexity to calculating dates 
  342. * and times together with timezone offsets and i18n. 
  343. * 
  344. * @since 1.1.0 
  345. * 
  346. * @param int|string $time The UNIX timestamp to be formatted. 
  347. * @param bool $exclude_time Optional. True to return only the month + day, false 
  348. * to return month, day, and time. Default: false. 
  349. * @param bool $gmt Optional. True to display in local time, false to 
  350. * leave in GMT. Default: true. 
  351. * @return mixed A string representation of $time, in the format 
  352. * "March 18, 2014 at 2:00 pm" (or whatever your 
  353. * 'date_format' and 'time_format' settings are 
  354. * on your root blog). False on failure. 
  355. */ 
  356. function bp_format_time( $time = '', $exclude_time = false, $gmt = true ) { 
  357.  
  358. // Bail if time is empty or not numeric 
  359. // @todo We should output something smarter here. 
  360. if ( empty( $time ) || ! is_numeric( $time ) ) { 
  361. return false; 
  362.  
  363. // Get GMT offset from root blog. 
  364. if ( true === $gmt ) { 
  365.  
  366. // Use Timezone string if set. 
  367. $timezone_string = bp_get_option( 'timezone_string' ); 
  368. if ( ! empty( $timezone_string ) ) { 
  369. $timezone_object = timezone_open( $timezone_string ); 
  370. $datetime_object = date_create( "@{$time}" ); 
  371. $timezone_offset = timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS; 
  372.  
  373. // Fall back on less reliable gmt_offset. 
  374. } else { 
  375. $timezone_offset = bp_get_option( 'gmt_offset' ); 
  376.  
  377. // Calculate time based on the offset. 
  378. $calculated_time = $time + ( $timezone_offset * HOUR_IN_SECONDS ); 
  379.  
  380. // No localizing, so just use the time that was submitted. 
  381. } else { 
  382. $calculated_time = $time; 
  383.  
  384. // Formatted date: "March 18, 2014". 
  385. $formatted_date = date_i18n( bp_get_option( 'date_format' ), $calculated_time, $gmt ); 
  386.  
  387. // Should we show the time also? 
  388. if ( true !== $exclude_time ) { 
  389.  
  390. // Formatted time: "2:00 pm". 
  391. $formatted_time = date_i18n( bp_get_option( 'time_format' ), $calculated_time, $gmt ); 
  392.  
  393. // Return string formatted with date and time. 
  394. $formatted_date = sprintf( esc_html__( '%1$s at %2$s', 'buddypress' ), $formatted_date, $formatted_time ); 
  395.  
  396. /** 
  397. * Filters the date based on a UNIX timestamp. 
  398. * 
  399. * @since 1.0.0 
  400. * 
  401. * @param string $formatted_date Formatted date from the timestamp. 
  402. */ 
  403. return apply_filters( 'bp_format_time', $formatted_date ); 
  404.  
  405. /** 
  406. * Select between two dynamic strings, according to context. 
  407. * 
  408. * This function can be used in cases where a phrase used in a template will 
  409. * differ for a user looking at his own profile and a user looking at another 
  410. * user's profile (eg, "My Friends" and "Joe's Friends"). Pass both versions 
  411. * of the phrase, and bp_word_or_name() will detect which is appropriate, and 
  412. * do the necessary argument swapping for dynamic phrases. 
  413. * 
  414. * @since 1.0.0 
  415. * 
  416. * @param string $youtext The "you" version of the phrase (eg "Your Friends"). 
  417. * @param string $nametext The other-user version of the phrase. Should be in 
  418. * a format appropriate for sprintf() - use %s in place of the displayed 
  419. * user's name (eg "%'s Friends"). 
  420. * @param bool $capitalize Optional. Force into title case. Default: true. 
  421. * @param bool $echo Optional. True to echo the results, false to return them. 
  422. * Default: true. 
  423. * @return string|null $nametext If ! $echo, returns the appropriate string. 
  424. */ 
  425. function bp_word_or_name( $youtext, $nametext, $capitalize = true, $echo = true ) { 
  426.  
  427. if ( ! empty( $capitalize ) ) { 
  428. $youtext = bp_core_ucfirst( $youtext ); 
  429.  
  430. if ( bp_displayed_user_id() == bp_loggedin_user_id() ) { 
  431. if ( true == $echo ) { 
  432.  
  433. /** 
  434. * Filters the text used based on context of own profile or someone else's profile. 
  435. * 
  436. * @since 1.0.0 
  437. * 
  438. * @param string $youtext Context-determined string to display. 
  439. */ 
  440. echo apply_filters( 'bp_word_or_name', $youtext ); 
  441. } else { 
  442.  
  443. /** This filter is documented in bp-core/bp-core-template.php */ 
  444. return apply_filters( 'bp_word_or_name', $youtext ); 
  445. } else { 
  446. $fullname = bp_get_displayed_user_fullname(); 
  447. $fullname = (array) explode( ' ', $fullname ); 
  448. $nametext = sprintf( $nametext, $fullname[0] ); 
  449. if ( true == $echo ) { 
  450.  
  451. /** This filter is documented in bp-core/bp-core-template.php */ 
  452. echo apply_filters( 'bp_word_or_name', $nametext ); 
  453. } else { 
  454.  
  455. /** This filter is documented in bp-core/bp-core-template.php */ 
  456. return apply_filters( 'bp_word_or_name', $nametext ); 
  457.  
  458. /** 
  459. * Do the 'bp_styles' action, and call wp_print_styles(). 
  460. * 
  461. * No longer used in BuddyPress. 
  462. * 
  463. * @todo Deprecate. 
  464. */ 
  465. function bp_styles() { 
  466. do_action( 'bp_styles' ); 
  467. wp_print_styles(); 
  468.  
  469. /** Search Form ***************************************************************/ 
  470.  
  471. /** 
  472. * Return the "action" attribute for search forms. 
  473. * 
  474. * @since 1.0.0 
  475. * 
  476. * @return string URL action attribute for search forms, eg example.com/search/. 
  477. */ 
  478. function bp_search_form_action() { 
  479.  
  480. /** 
  481. * Filters the "action" attribute for search forms. 
  482. * 
  483. * @since 1.0.0 
  484. * 
  485. * @param string $value Search form action url. 
  486. */ 
  487. return apply_filters( 'bp_search_form_action', trailingslashit( bp_get_root_domain() . '/' . bp_get_search_slug() ) ); 
  488.  
  489. /** 
  490. * Generate the basic search form as used in BP-Default's header. 
  491. * 
  492. * @since 1.0.0 
  493. * 
  494. * @return string HTML <select> element. 
  495. */ 
  496. function bp_search_form_type_select() { 
  497.  
  498. $options = array(); 
  499.  
  500. if ( bp_is_active( 'xprofile' ) ) { 
  501. $options['members'] = _x( 'Members', 'search form', 'buddypress' ); 
  502.  
  503. if ( bp_is_active( 'groups' ) ) { 
  504. $options['groups'] = _x( 'Groups', 'search form', 'buddypress' ); 
  505.  
  506. if ( bp_is_active( 'blogs' ) && is_multisite() ) { 
  507. $options['blogs'] = _x( 'Blogs', 'search form', 'buddypress' ); 
  508.  
  509. if ( bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() && bp_forums_has_directory() ) { 
  510. $options['forums'] = _x( 'Forums', 'search form', 'buddypress' ); 
  511.  
  512. $options['posts'] = _x( 'Posts', 'search form', 'buddypress' ); 
  513.  
  514. // Eventually this won't be needed and a page will be built to integrate all search results. 
  515. $selection_box = '<label for="search-which" class="accessibly-hidden">' . _x( 'Search these:', 'search form', 'buddypress' ) . '</label>'; 
  516. $selection_box .= '<select name="search-which" id="search-which" style="width: auto">'; 
  517.  
  518. /** 
  519. * Filters all of the component options available for search scope. 
  520. * 
  521. * @since 1.5.0 
  522. * 
  523. * @param array $options Array of options to add to select field. 
  524. */ 
  525. $options = apply_filters( 'bp_search_form_type_select_options', $options ); 
  526. foreach( (array) $options as $option_value => $option_title ) { 
  527. $selection_box .= sprintf( '<option value="%s">%s</option>', $option_value, $option_title ); 
  528.  
  529. $selection_box .= '</select>'; 
  530.  
  531. /** 
  532. * Filters the complete <select> input used for search scope. 
  533. * 
  534. * @since 1.0.0 
  535. * 
  536. * @param string $selection_box <select> input for selecting search scope. 
  537. */ 
  538. return apply_filters( 'bp_search_form_type_select', $selection_box ); 
  539.  
  540. /** 
  541. * Output the 'name' attribute for search form input element. 
  542. * 
  543. * @since 2.7.0 
  544. * 
  545. * @param string $component See bp_get_search_input_name(). 
  546. */ 
  547. function bp_search_input_name( $component = '' ) { 
  548. echo esc_attr( bp_get_search_input_name( $component ) ); 
  549.  
  550. /** 
  551. * Get the 'name' attribute for the search form input element. 
  552. * 
  553. * @since 2.7.0 
  554. * 
  555. * @param string $component Component name. Defaults to current component. 
  556. * @return string Text for the 'name' attribute. 
  557. */ 
  558. function bp_get_search_input_name( $component = '' ) { 
  559. if ( ! $component ) { 
  560. $component = bp_current_component(); 
  561.  
  562. $bp = buddypress(); 
  563.  
  564. $name = ''; 
  565. if ( isset( $bp->{$component}->id ) ) { 
  566. $name = $bp->{$component}->id . '_search'; 
  567.  
  568. return $name; 
  569.  
  570. /** 
  571. * Output the placeholder text for the search box for a given component. 
  572. * 
  573. * @since 2.7.0 
  574. * 
  575. * @param string $component See bp_get_search_placeholder(). 
  576. */ 
  577. function bp_search_placeholder( $component = '' ) { 
  578. echo esc_attr( bp_get_search_placeholder( $component ) ); 
  579.  
  580. /** 
  581. * Get the placeholder text for the search box for a given component. 
  582. * 
  583. * @since 2.7.0 
  584. * 
  585. * @param string $component Component name. Defaults to current component. 
  586. * @return string Placeholder text for the search field. 
  587. */ 
  588. function bp_get_search_placeholder( $component = '' ) { 
  589. $query_arg = bp_core_get_component_search_query_arg( $component ); 
  590.  
  591. if ( $query_arg && ! empty( $_REQUEST[ $query_arg ] ) ) { 
  592. $placeholder = wp_unslash( $_REQUEST[ $query_arg ] ); 
  593. } else { 
  594. $placeholder = bp_get_search_default_text( $component ); 
  595.  
  596. return $placeholder; 
  597.  
  598. /** 
  599. * Output the default text for the search box for a given component. 
  600. * 
  601. * @since 1.5.0 
  602. * 
  603. * @see bp_get_search_default_text() 
  604. * 
  605. * @param string $component See {@link bp_get_search_default_text()}. 
  606. */ 
  607. function bp_search_default_text( $component = '' ) { 
  608. echo bp_get_search_default_text( $component ); 
  609. /** 
  610. * Return the default text for the search box for a given component. 
  611. * 
  612. * @since 1.5.0 
  613. * 
  614. * @param string $component Component name. Default: current component. 
  615. * @return string Placeholder text for search field. 
  616. */ 
  617. function bp_get_search_default_text( $component = '' ) { 
  618.  
  619. $bp = buddypress(); 
  620.  
  621. if ( empty( $component ) ) { 
  622. $component = bp_current_component(); 
  623.  
  624. $default_text = __( 'Search anything...', 'buddypress' ); 
  625.  
  626. // Most of the time, $component will be the actual component ID. 
  627. if ( !empty( $component ) ) { 
  628. if ( !empty( $bp->{$component}->search_string ) ) { 
  629. $default_text = $bp->{$component}->search_string; 
  630. } else { 
  631. // When the request comes through AJAX, we need to get the component 
  632. // name out of $bp->pages. 
  633. if ( !empty( $bp->pages->{$component}->slug ) ) { 
  634. $key = $bp->pages->{$component}->slug; 
  635. if ( !empty( $bp->{$key}->search_string ) ) { 
  636. $default_text = $bp->{$key}->search_string; 
  637.  
  638. /** 
  639. * Filters the default text for the search box for a given component. 
  640. * 
  641. * @since 1.5.0 
  642. * 
  643. * @param string $default_text Default text for search box. 
  644. * @param string $component Current component displayed. 
  645. */ 
  646. return apply_filters( 'bp_get_search_default_text', $default_text, $component ); 
  647.  
  648. /** 
  649. * Fire the 'bp_custom_profile_boxes' action. 
  650. * 
  651. * No longer used in BuddyPress. 
  652. * 
  653. * @todo Deprecate. 
  654. */ 
  655. function bp_custom_profile_boxes() { 
  656. do_action( 'bp_custom_profile_boxes' ); 
  657.  
  658. /** 
  659. * Fire the 'bp_custom_profile_sidebar_boxes' action. 
  660. * 
  661. * No longer used in BuddyPress. 
  662. * 
  663. * @todo Deprecate. 
  664. */ 
  665. function bp_custom_profile_sidebar_boxes() { 
  666. do_action( 'bp_custom_profile_sidebar_boxes' ); 
  667.  
  668. /** 
  669. * Output the attributes for a form field. 
  670. * 
  671. * @since 2.2.0 
  672. * 
  673. * @param string $name The field name to output attributes for. 
  674. * @param array $attributes Array of existing attributes to add. 
  675. */ 
  676. function bp_form_field_attributes( $name = '', $attributes = array() ) { 
  677. echo bp_get_form_field_attributes( $name, $attributes ); 
  678. /** 
  679. * Get the attributes for a form field. 
  680. * 
  681. * Primarily to add better support for touchscreen devices, but plugin devs 
  682. * can use the 'bp_get_form_field_extra_attributes' filter for further 
  683. * manipulation. 
  684. * 
  685. * @since 2.2.0 
  686. * 
  687. * @param string $name The field name to get attributes for. 
  688. * @param array $attributes Array of existing attributes to add. 
  689. * @return string 
  690. */ 
  691. function bp_get_form_field_attributes( $name = '', $attributes = array() ) { 
  692. $retval = ''; 
  693.  
  694. if ( empty( $attributes ) ) { 
  695. $attributes = array(); 
  696.  
  697. $name = strtolower( $name ); 
  698.  
  699. switch ( $name ) { 
  700. case 'username' : 
  701. case 'blogname' : 
  702. $attributes['autocomplete'] = 'off'; 
  703. $attributes['autocapitalize'] = 'none'; 
  704. break; 
  705.  
  706. case 'email' : 
  707. if ( wp_is_mobile() ) { 
  708. $attributes['autocapitalize'] = 'none'; 
  709. break; 
  710.  
  711. case 'password' : 
  712. $attributes['spellcheck'] = 'false'; 
  713. $attributes['autocomplete'] = 'off'; 
  714.  
  715. if ( wp_is_mobile() ) { 
  716. $attributes['autocorrect'] = 'false'; 
  717. $attributes['autocapitalize'] = 'none'; 
  718. break; 
  719.  
  720. /** 
  721. * Filter the attributes for a field before rendering output. 
  722. * 
  723. * @since 2.2.0 
  724. * 
  725. * @param array $attributes The field attributes. 
  726. * @param string $name The field name. 
  727. */ 
  728. $attributes = (array) apply_filters( 'bp_get_form_field_attributes', $attributes, $name ); 
  729.  
  730. foreach( $attributes as $attr => $value ) { 
  731. $retval .= sprintf( ' %s="%s"', sanitize_key( $attr ), esc_attr( $value ) ); 
  732.  
  733. return $retval; 
  734.  
  735. /** 
  736. * Create and output a button. 
  737. * 
  738. * @since 1.2.6 
  739. * 
  740. * @see bp_get_button() 
  741. * 
  742. * @param array|string $args See {@link BP_Button}. 
  743. */ 
  744. function bp_button( $args = '' ) { 
  745. echo bp_get_button( $args ); 
  746. /** 
  747. * Create and return a button. 
  748. * 
  749. * @since 1.2.6 
  750. * 
  751. * @see BP_Button for a description of arguments and return value. 
  752. * 
  753. * @param array|string $args See {@link BP_Button}. 
  754. * @return string HTML markup for the button. 
  755. */ 
  756. function bp_get_button( $args = '' ) { 
  757. $button = new BP_Button( $args ); 
  758.  
  759. /** 
  760. * Filters the requested button output. 
  761. * 
  762. * @since 1.2.6 
  763. * 
  764. * @param string $contents Button context to be used. 
  765. * @param array $args Array of args for the button. 
  766. * @param BP_Button $button BP_Button object. 
  767. */ 
  768. return apply_filters( 'bp_get_button', $button->contents, $args, $button ); 
  769.  
  770. /** 
  771. * Truncate text. 
  772. * 
  773. * Cuts a string to the length of $length and replaces the last characters 
  774. * with the ending if the text is longer than length. 
  775. * 
  776. * This function is borrowed from CakePHP v2.0, under the MIT license. See 
  777. * http://book.cakephp.org/view/1469/Text#truncate-1625 
  778. * 
  779. * @since 1.0.0 
  780. * @since 2.6.0 Added 'strip_tags' and 'remove_links' as $options args. 
  781. * 
  782. * @param string $text String to truncate. 
  783. * @param int $length Optional. Length of returned string, including ellipsis. 
  784. * Default: 225. 
  785. * @param array $options { 
  786. * An array of HTML attributes and options. Each item is optional. 
  787. * @type string $ending The string used after truncation. 
  788. * Default: ' […]'. 
  789. * @type bool $exact If true, $text will be trimmed to exactly $length. 
  790. * If false, $text will not be cut mid-word. Default: false. 
  791. * @type bool $html If true, don't include HTML tags when calculating 
  792. * excerpt length. Default: true. 
  793. * @type bool $filter_shortcodes If true, shortcodes will be stripped. 
  794. * Default: true. 
  795. * @type bool $strip_tags If true, HTML tags will be stripped. Default: false. 
  796. * Only applicable if $html is set to false. 
  797. * @type bool $remove_links If true, URLs will be stripped. Default: false. 
  798. * Only applicable if $html is set to false. 
  799. * } 
  800. * @return string Trimmed string. 
  801. */ 
  802. function bp_create_excerpt( $text, $length = 225, $options = array() ) { 
  803.  
  804. // Backward compatibility. The third argument used to be a boolean $filter_shortcodes. 
  805. $filter_shortcodes_default = is_bool( $options ) ? $options : true; 
  806.  
  807. $r = bp_parse_args( $options, array( 
  808. 'ending' => __( ' […]', 'buddypress' ),  
  809. 'exact' => false,  
  810. 'html' => true,  
  811. 'filter_shortcodes' => $filter_shortcodes_default,  
  812. 'strip_tags' => false,  
  813. 'remove_links' => false,  
  814. ), 'create_excerpt' ); 
  815.  
  816. // Save the original text, to be passed along to the filter. 
  817. $original_text = $text; 
  818.  
  819. /** 
  820. * Filters the excerpt length to trim text to. 
  821. * 
  822. * @since 1.5.0 
  823. * 
  824. * @param int $length Length of returned string, including ellipsis. 
  825. */ 
  826. $length = apply_filters( 'bp_excerpt_length', $length ); 
  827.  
  828. /** 
  829. * Filters the excerpt appended text value. 
  830. * 
  831. * @since 1.5.0 
  832. * 
  833. * @param string $value Text to append to the end of the excerpt. 
  834. */ 
  835. $ending = apply_filters( 'bp_excerpt_append_text', $r['ending'] ); 
  836.  
  837. // Remove shortcodes if necessary. 
  838. if ( ! empty( $r['filter_shortcodes'] ) ) { 
  839. $text = strip_shortcodes( $text ); 
  840.  
  841. // When $html is true, the excerpt should be created without including HTML tags in the 
  842. // excerpt length. 
  843. if ( ! empty( $r['html'] ) ) { 
  844.  
  845. // The text is short enough. No need to truncate. 
  846. if ( mb_strlen( preg_replace( '/<.*?>/', '', $text ) ) <= $length ) { 
  847. return $text; 
  848.  
  849. $totalLength = mb_strlen( strip_tags( $ending ) ); 
  850. $openTags = array(); 
  851. $truncate = ''; 
  852.  
  853. // Find all the tags and HTML comments and put them in a stack for later use. 
  854. preg_match_all( '/(<\/?([\w+!]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER ); 
  855.  
  856. foreach ( $tags as $tag ) { 
  857. // Process tags that need to be closed. 
  858. if ( !preg_match( '/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2] ) ) { 
  859. if ( preg_match( '/<[\w]+[^>]*>/s', $tag[0] ) ) { 
  860. array_unshift( $openTags, $tag[2] ); 
  861. } elseif ( preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag ) ) { 
  862. $pos = array_search( $closeTag[1], $openTags ); 
  863. if ( $pos !== false ) { 
  864. array_splice( $openTags, $pos, 1 ); 
  865.  
  866. $truncate .= $tag[1]; 
  867. $contentLength = mb_strlen( preg_replace( '/&[0-9a-z]{2, 8};|&#[0-9]{1, 7};|&#x[0-9a-f]{1, 6};/i', ' ', $tag[3] ) ); 
  868.  
  869. if ( $contentLength + $totalLength > $length ) { 
  870. $left = $length - $totalLength; 
  871. $entitiesLength = 0; 
  872. if ( preg_match_all( '/&[0-9a-z]{2, 8};|&#[0-9]{1, 7};|&#x[0-9a-f]{1, 6};/i', $tag[3], $entities, PREG_OFFSET_CAPTURE ) ) { 
  873. foreach ( $entities[0] as $entity ) { 
  874. if ( $entity[1] + 1 - $entitiesLength <= $left ) { 
  875. $left--; 
  876. $entitiesLength += mb_strlen( $entity[0] ); 
  877. } else { 
  878. break; 
  879.  
  880. $truncate .= mb_substr( $tag[3], 0 , $left + $entitiesLength ); 
  881. break; 
  882. } else { 
  883. $truncate .= $tag[3]; 
  884. $totalLength += $contentLength; 
  885. if ( $totalLength >= $length ) { 
  886. break; 
  887. } else { 
  888. // Strip HTML tags if necessary. 
  889. if ( ! empty( $r['strip_tags'] ) ) { 
  890. $text = strip_tags( $text ); 
  891.  
  892. // Remove links if necessary. 
  893. if ( ! empty( $r['remove_links'] ) ) { 
  894. $text = preg_replace( '#^\s*(https?://[^\s"]+)\s*$#im', '', $text ); 
  895.  
  896. if ( mb_strlen( $text ) <= $length ) { 
  897. /** 
  898. * Filters the final generated excerpt. 
  899. * 
  900. * @since 1.1.0 
  901. * 
  902. * @param string $truncate Generated excerpt. 
  903. * @param string $original_text Original text provided. 
  904. * @param int $length Length of returned string, including ellipsis. 
  905. * @param array $options Array of HTML attributes and options. 
  906. */ 
  907. return apply_filters( 'bp_create_excerpt', $text, $original_text, $length, $options ); 
  908. } else { 
  909. $truncate = mb_substr( $text, 0, $length - mb_strlen( $ending ) ); 
  910.  
  911. // If $exact is false, we can't break on words. 
  912. if ( empty( $r['exact'] ) ) { 
  913. // Find the position of the last space character not part of a tag. 
  914. preg_match_all( '/<[a-z\!\/][^>]*>/', $truncate, $_truncate_tags, PREG_OFFSET_CAPTURE ); 
  915.  
  916. // Rekey tags by the string index of their last character. 
  917. $truncate_tags = array(); 
  918. if ( ! empty( $_truncate_tags[0] ) ) { 
  919. foreach ( $_truncate_tags[0] as $_tt ) { 
  920. $_tt['start'] = $_tt[1]; 
  921. $_tt['end'] = $_tt[1] + strlen( $_tt[0] ); 
  922. $truncate_tags[ $_tt['end'] ] = $_tt; 
  923.  
  924. $truncate_length = mb_strlen( $truncate ); 
  925. $spacepos = $truncate_length + 1; 
  926. for ( $pos = $truncate_length - 1; $pos >= 0; $pos-- ) { 
  927. // Word boundaries are spaces and the close of HTML tags, when the tag is preceded by a space. 
  928. $is_word_boundary = ' ' === $truncate[ $pos ]; 
  929. if ( ! $is_word_boundary && isset( $truncate_tags[ $pos - 1 ] ) ) { 
  930. $preceding_tag = $truncate_tags[ $pos - 1 ]; 
  931. if ( ' ' === $truncate[ $preceding_tag['start'] - 1 ] ) { 
  932. $is_word_boundary = true; 
  933. break; 
  934.  
  935. if ( ! $is_word_boundary ) { 
  936. continue; 
  937.  
  938. // If there are no tags in the string, the first space found is the right one. 
  939. if ( empty( $truncate_tags ) ) { 
  940. $spacepos = $pos; 
  941. break; 
  942.  
  943. // Look at each tag to see if the space is inside of it. 
  944. $intag = false; 
  945. foreach ( $truncate_tags as $tt ) { 
  946. if ( $pos > $tt['start'] && $pos < $tt['end'] ) { 
  947. $intag = true; 
  948. break; 
  949.  
  950. if ( ! $intag ) { 
  951. $spacepos = $pos; 
  952. break; 
  953.  
  954. if ( $r['html'] ) { 
  955. $bits = mb_substr( $truncate, $spacepos ); 
  956. preg_match_all( '/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER ); 
  957. if ( !empty( $droppedTags ) ) { 
  958. foreach ( $droppedTags as $closingTag ) { 
  959. if ( !in_array( $closingTag[1], $openTags ) ) { 
  960. array_unshift( $openTags, $closingTag[1] ); 
  961.  
  962. $truncate = rtrim( mb_substr( $truncate, 0, $spacepos ) ); 
  963. $truncate .= $ending; 
  964.  
  965. if ( !empty( $r['html'] ) ) { 
  966. foreach ( $openTags as $tag ) { 
  967. $truncate .= '</' . $tag . '>'; 
  968.  
  969. /** This filter is documented in /bp-core/bp-core-template.php */ 
  970. return apply_filters( 'bp_create_excerpt', $truncate, $original_text, $length, $options ); 
  971. add_filter( 'bp_create_excerpt', 'stripslashes_deep' ); 
  972. add_filter( 'bp_create_excerpt', 'force_balance_tags' ); 
  973.  
  974. /** 
  975. * Output the total member count for the site. 
  976. * 
  977. * @since 1.2.0 
  978. */ 
  979. function bp_total_member_count() { 
  980. echo bp_get_total_member_count(); 
  981. /** 
  982. * Return the total member count in your BP instance. 
  983. * 
  984. * Since BuddyPress 1.6, this function has used bp_core_get_active_member_count(),  
  985. * which counts non-spam, non-deleted users who have last_activity. 
  986. * This value will correctly match the total member count number used 
  987. * for pagination on member directories. 
  988. * 
  989. * Before BuddyPress 1.6, this function used bp_core_get_total_member_count(),  
  990. * which did not take into account last_activity, and thus often 
  991. * resulted in higher counts than shown by member directory pagination. 
  992. * 
  993. * @since 1.2.0 
  994. * 
  995. * @return int Member count. 
  996. */ 
  997. function bp_get_total_member_count() { 
  998.  
  999. /** 
  1000. * Filters the total member count in your BP instance. 
  1001. * 
  1002. * @since 1.2.0 
  1003. * 
  1004. * @param int $value Member count. 
  1005. */ 
  1006. return apply_filters( 'bp_get_total_member_count', bp_core_get_active_member_count() ); 
  1007. add_filter( 'bp_get_total_member_count', 'bp_core_number_format' ); 
  1008.  
  1009. /** 
  1010. * Output whether blog signup is allowed. 
  1011. * 
  1012. * @todo Deprecate. It doesn't make any sense to echo a boolean. 
  1013. */ 
  1014. function bp_blog_signup_allowed() { 
  1015. echo bp_get_blog_signup_allowed(); 
  1016. /** 
  1017. * Is blog signup allowed? 
  1018. * 
  1019. * Returns true if is_multisite() and blog creation is enabled at 
  1020. * Network Admin > Settings. 
  1021. * 
  1022. * @since 1.2.0 
  1023. * 
  1024. * @return bool True if blog signup is allowed, otherwise false. 
  1025. */ 
  1026. function bp_get_blog_signup_allowed() { 
  1027.  
  1028. if ( ! is_multisite() ) { 
  1029. return false; 
  1030.  
  1031. $status = bp_core_get_root_option( 'registration' ); 
  1032. if ( ( 'none' !== $status ) && ( 'user' !== $status ) ) { 
  1033. return true; 
  1034.  
  1035. return false; 
  1036.  
  1037. /** 
  1038. * Check whether an activation has just been completed. 
  1039. * 
  1040. * @since 1.1.0 
  1041. * 
  1042. * @return bool True if the activation_complete global flag has been set,  
  1043. * otherwise false. 
  1044. */ 
  1045. function bp_account_was_activated() { 
  1046. $bp = buddypress(); 
  1047. $activation_complete = !empty( $bp->activation_complete ) 
  1048. ? $bp->activation_complete 
  1049. : false; 
  1050.  
  1051. return $activation_complete; 
  1052.  
  1053. /** 
  1054. * Check whether registrations require activation on this installation. 
  1055. * 
  1056. * On a normal BuddyPress installation, all registrations require email 
  1057. * activation. This filter exists so that customizations that omit activation 
  1058. * can remove certain notification text from the registration screen. 
  1059. * 
  1060. * @since 1.2.0 
  1061. * 
  1062. * @return bool True by default. 
  1063. */ 
  1064. function bp_registration_needs_activation() { 
  1065.  
  1066. /** 
  1067. * Filters whether registrations require activation on this installation. 
  1068. * 
  1069. * @since 1.2.0 
  1070. * 
  1071. * @param bool $value Whether registrations require activation. Default true. 
  1072. */ 
  1073. return apply_filters( 'bp_registration_needs_activation', true ); 
  1074.  
  1075. /** 
  1076. * Retrieve a client friendly version of the root blog name. 
  1077. * 
  1078. * The blogname option is escaped with esc_html on the way into the database in 
  1079. * sanitize_option, we want to reverse this for the plain text arena of emails. 
  1080. * 
  1081. * @since 1.7.0 
  1082. * @since 2.5.0 No longer used by BuddyPress, but not deprecated in case any existing plugins use it. 
  1083. * 
  1084. * @see https://buddypress.trac.wordpress.org/ticket/4401 
  1085. * 
  1086. * @param array $args { 
  1087. * Array of optional parameters. 
  1088. * @type string $before String to appear before the site name in the 
  1089. * email subject. Default: '['. 
  1090. * @type string $after String to appear after the site name in the 
  1091. * email subject. Default: ']'. 
  1092. * @type string $default The default site name, to be used when none is 
  1093. * found in the database. Default: 'Community'. 
  1094. * @type string $text Text to append to the site name (ie, the main text of 
  1095. * the email subject). 
  1096. * } 
  1097. * @return string Sanitized email subject. 
  1098. */ 
  1099. function bp_get_email_subject( $args = array() ) { 
  1100.  
  1101. $r = bp_parse_args( $args, array( 
  1102. 'before' => '[',  
  1103. 'after' => ']',  
  1104. 'default' => __( 'Community', 'buddypress' ),  
  1105. 'text' => '' 
  1106. ), 'get_email_subject' ); 
  1107.  
  1108. $subject = $r['before'] . wp_specialchars_decode( bp_get_option( 'blogname', $r['default'] ), ENT_QUOTES ) . $r['after'] . ' ' . $r['text']; 
  1109.  
  1110. /** 
  1111. * Filters a client friendly version of the root blog name. 
  1112. * 
  1113. * @since 1.7.0 
  1114. * 
  1115. * @param string $subject Client friendy version of the root blog name. 
  1116. * @param array $r Array of arguments for the email subject. 
  1117. */ 
  1118. return apply_filters( 'bp_get_email_subject', $subject, $r ); 
  1119.  
  1120. /** 
  1121. * Allow templates to pass parameters directly into the template loops via AJAX. 
  1122. * 
  1123. * For the most part this will be filtered in a theme's functions.php for 
  1124. * example in the default theme it is filtered via bp_dtheme_ajax_querystring(). 
  1125. * 
  1126. * By using this template tag in the templates it will stop them from showing 
  1127. * errors if someone copies the templates from the default theme into another 
  1128. * WordPress theme without coping the functions from functions.php. 
  1129. * 
  1130. * @since 1.2.0 
  1131. * 
  1132. * @param string|bool $object Current template component. 
  1133. * @return string The AJAX querystring. 
  1134. */ 
  1135. function bp_ajax_querystring( $object = false ) { 
  1136. $bp = buddypress(); 
  1137.  
  1138. if ( ! isset( $bp->ajax_querystring ) ) { 
  1139. $bp->ajax_querystring = ''; 
  1140.  
  1141. /** 
  1142. * Filters the template paramenters to be used in the query string. 
  1143. * 
  1144. * Allows templates to pass parameters into the template loops via AJAX. 
  1145. * 
  1146. * @since 1.2.0 
  1147. * 
  1148. * @param string $ajax_querystring Current query string. 
  1149. * @param string $object Current template component. 
  1150. */ 
  1151. return apply_filters( 'bp_ajax_querystring', $bp->ajax_querystring, $object ); 
  1152.  
  1153. /** Template Classes and _is functions ****************************************/ 
  1154.  
  1155. /** 
  1156. * Return the name of the current component. 
  1157. * 
  1158. * @since 1.0.0 
  1159. * 
  1160. * @return string Component name. 
  1161. */ 
  1162. function bp_current_component() { 
  1163. $bp = buddypress(); 
  1164. $current_component = !empty( $bp->current_component ) 
  1165. ? $bp->current_component 
  1166. : false; 
  1167.  
  1168. /** 
  1169. * Filters the name of the current component. 
  1170. * 
  1171. * @since 1.0.0 
  1172. * 
  1173. * @param string|bool $current_component Current component if available or false. 
  1174. */ 
  1175. return apply_filters( 'bp_current_component', $current_component ); 
  1176.  
  1177. /** 
  1178. * Return the name of the current action. 
  1179. * 
  1180. * @since 1.0.0 
  1181. * 
  1182. * @return string Action name. 
  1183. */ 
  1184. function bp_current_action() { 
  1185. $bp = buddypress(); 
  1186. $current_action = !empty( $bp->current_action ) 
  1187. ? $bp->current_action 
  1188. : ''; 
  1189.  
  1190. /** 
  1191. * Filters the name of the current action. 
  1192. * 
  1193. * @since 1.0.0 
  1194. * 
  1195. * @param string $current_action Current action. 
  1196. */ 
  1197. return apply_filters( 'bp_current_action', $current_action ); 
  1198.  
  1199. /** 
  1200. * Return the name of the current item. 
  1201. * 
  1202. * @since 1.1.0 
  1203. * 
  1204. * @return string|bool 
  1205. */ 
  1206. function bp_current_item() { 
  1207. $bp = buddypress(); 
  1208. $current_item = !empty( $bp->current_item ) 
  1209. ? $bp->current_item 
  1210. : false; 
  1211.  
  1212. /** 
  1213. * Filters the name of the current item. 
  1214. * 
  1215. * @since 1.1.0 
  1216. * 
  1217. * @param string|bool $current_item Current item if available or false. 
  1218. */ 
  1219. return apply_filters( 'bp_current_item', $current_item ); 
  1220.  
  1221. /** 
  1222. * Return the value of $bp->action_variables. 
  1223. * 
  1224. * @since 1.0.0 
  1225. * 
  1226. * @return array|bool $action_variables The action variables array, or false 
  1227. * if the array is empty. 
  1228. */ 
  1229. function bp_action_variables() { 
  1230. $bp = buddypress(); 
  1231. $action_variables = !empty( $bp->action_variables ) 
  1232. ? $bp->action_variables 
  1233. : false; 
  1234.  
  1235. /** 
  1236. * Filters the value of $bp->action_variables. 
  1237. * 
  1238. * @since 1.0.0 
  1239. * 
  1240. * @param array|bool $action_variables Available action variables. 
  1241. */ 
  1242. return apply_filters( 'bp_action_variables', $action_variables ); 
  1243.  
  1244. /** 
  1245. * Return the value of a given action variable. 
  1246. * 
  1247. * @since 1.5.0 
  1248. * 
  1249. * @param int $position The key of the action_variables array that you want. 
  1250. * @return string|bool $action_variable The value of that position in the 
  1251. * array, or false if not found. 
  1252. */ 
  1253. function bp_action_variable( $position = 0 ) { 
  1254. $action_variables = bp_action_variables(); 
  1255. $action_variable = isset( $action_variables[ $position ] ) 
  1256. ? $action_variables[ $position ] 
  1257. : false; 
  1258.  
  1259. /** 
  1260. * Filters the value of a given action variable. 
  1261. * 
  1262. * @since 1.5.0 
  1263. * 
  1264. * @param string|bool $action_variable Requested action variable based on position. 
  1265. * @param int $position The key of the action variable requested. 
  1266. */ 
  1267. return apply_filters( 'bp_action_variable', $action_variable, $position ); 
  1268.  
  1269. /** 
  1270. * Output the "root domain", the URL of the BP root blog. 
  1271. * 
  1272. * @since 1.1.0 
  1273. */ 
  1274. function bp_root_domain() { 
  1275. echo bp_get_root_domain(); 
  1276. /** 
  1277. * Return the "root domain", the URL of the BP root blog. 
  1278. * 
  1279. * @since 1.1.0 
  1280. * 
  1281. * @return string URL of the BP root blog. 
  1282. */ 
  1283. function bp_get_root_domain() { 
  1284. $bp = buddypress(); 
  1285.  
  1286. if ( ! empty( $bp->root_domain ) ) { 
  1287. $domain = $bp->root_domain; 
  1288. } else { 
  1289. $domain = bp_core_get_root_domain(); 
  1290. $bp->root_domain = $domain; 
  1291.  
  1292. /** 
  1293. * Filters the "root domain", the URL of the BP root blog. 
  1294. * 
  1295. * @since 1.2.4 
  1296. * 
  1297. * @param string $domain URL of the BP root blog. 
  1298. */ 
  1299. return apply_filters( 'bp_get_root_domain', $domain ); 
  1300.  
  1301. /** 
  1302. * Output the root slug for a given component. 
  1303. * 
  1304. * @since 1.5.0 
  1305. * 
  1306. * @param string $component The component name. 
  1307. */ 
  1308. function bp_root_slug( $component = '' ) { 
  1309. echo bp_get_root_slug( $component ); 
  1310. /** 
  1311. * Get the root slug for given component. 
  1312. * 
  1313. * The "root slug" is the string used when concatenating component 
  1314. * directory URLs. For example, on an installation where the Groups 
  1315. * component's directory is located at http://example.com/groups/, the 
  1316. * root slug for the Groups component is 'groups'. This string 
  1317. * generally corresponds to page_name of the component's directory 
  1318. * page. 
  1319. * 
  1320. * In order to maintain backward compatibility, the following procedure 
  1321. * is used: 
  1322. * 1) Use the short slug to get the canonical component name from the 
  1323. * active component array. 
  1324. * 2) Use the component name to get the root slug out of the 
  1325. * appropriate part of the $bp global. 
  1326. * 3) If nothing turns up, it probably means that $component is itself 
  1327. * a root slug. 
  1328. * 
  1329. * Example: If your groups directory is at /community/companies, this 
  1330. * function first uses the short slug 'companies' (ie the current 
  1331. * component) to look up the canonical name 'groups' in 
  1332. * $bp->active_components. Then it uses 'groups' to get the root slug,  
  1333. * from $bp->groups->root_slug. 
  1334. * 
  1335. * @since 1.5.0 
  1336. * 
  1337. * @param string $component Optional. Defaults to the current component. 
  1338. * @return string $root_slug The root slug. 
  1339. */ 
  1340. function bp_get_root_slug( $component = '' ) { 
  1341. $bp = buddypress(); 
  1342. $root_slug = ''; 
  1343.  
  1344. // Use current global component if none passed. 
  1345. if ( empty( $component ) ) { 
  1346. $component = bp_current_component(); 
  1347.  
  1348. // Component is active. 
  1349. if ( ! empty( $bp->active_components[ $component ] ) ) { 
  1350.  
  1351. // Backward compatibility: in legacy plugins, the canonical component id 
  1352. // was stored as an array value in $bp->active_components. 
  1353. $component_name = ( '1' == $bp->active_components[ $component ] ) 
  1354. ? $component 
  1355. : $bp->active_components[$component]; 
  1356.  
  1357. // Component has specific root slug. 
  1358. if ( ! empty( $bp->{$component_name}->root_slug ) ) { 
  1359. $root_slug = $bp->{$component_name}->root_slug; 
  1360.  
  1361. // No specific root slug, so fall back to component slug. 
  1362. if ( empty( $root_slug ) ) { 
  1363. $root_slug = $component; 
  1364.  
  1365. /** 
  1366. * Filters the root slug for given component. 
  1367. * 
  1368. * @since 1.5.0 
  1369. * 
  1370. * @param string $root_slug Root slug for given component. 
  1371. * @param string $component Current component. 
  1372. */ 
  1373. return apply_filters( 'bp_get_root_slug', $root_slug, $component ); 
  1374.  
  1375. /** 
  1376. * Return the component name based on a root slug. 
  1377. * 
  1378. * @since 1.5.0 
  1379. * 
  1380. * @param string $root_slug Needle to our active component haystack. 
  1381. * @return mixed False if none found, component name if found. 
  1382. */ 
  1383. function bp_get_name_from_root_slug( $root_slug = '' ) { 
  1384. $bp = buddypress(); 
  1385.  
  1386. // If no slug is passed, look at current_component. 
  1387. if ( empty( $root_slug ) ) { 
  1388. $root_slug = bp_current_component(); 
  1389.  
  1390. // No current component or root slug, so flee. 
  1391. if ( empty( $root_slug ) ) { 
  1392. return false; 
  1393.  
  1394. // Loop through active components and look for a match. 
  1395. foreach ( array_keys( $bp->active_components ) as $component ) { 
  1396. if ( ( ! empty( $bp->{$component}->slug ) && ( $bp->{$component}->slug == $root_slug ) ) || ( ! empty( $bp->{$component}->root_slug ) && ( $bp->{$component}->root_slug === $root_slug ) ) ) { 
  1397. return $bp->{$component}->name; 
  1398.  
  1399. return false; 
  1400.  
  1401. /** 
  1402. * Returns whether or not a user has access. 
  1403. * 
  1404. * @since 1.2.4 
  1405. * 
  1406. * @return bool 
  1407. */ 
  1408. function bp_user_has_access() { 
  1409. $has_access = bp_current_user_can( 'bp_moderate' ) || bp_is_my_profile(); 
  1410.  
  1411. /** 
  1412. * Filters whether or not a user has access. 
  1413. * 
  1414. * @since 1.2.4 
  1415. * 
  1416. * @param bool $has_access Whether or not user has access. 
  1417. */ 
  1418. return (bool) apply_filters( 'bp_user_has_access', $has_access ); 
  1419.  
  1420. /** 
  1421. * Output the search slug. 
  1422. * 
  1423. * @since 1.5.0 
  1424. * 
  1425. */ 
  1426. function bp_search_slug() { 
  1427. echo bp_get_search_slug(); 
  1428. /** 
  1429. * Return the search slug. 
  1430. * 
  1431. * @since 1.5.0 
  1432. * 
  1433. * @return string The search slug. Default: 'search'. 
  1434. */ 
  1435. function bp_get_search_slug() { 
  1436.  
  1437. /** 
  1438. * Filters the search slug. 
  1439. * 
  1440. * @since 1.5.0 
  1441. * 
  1442. * @const string BP_SEARCH_SLUG The search slug. Default "search". 
  1443. */ 
  1444. return apply_filters( 'bp_get_search_slug', BP_SEARCH_SLUG ); 
  1445.  
  1446. /** 
  1447. * Get the ID of the currently displayed user. 
  1448. * 
  1449. * @since 1.0.0 
  1450. * 
  1451. * @return int $id ID of the currently displayed user. 
  1452. */ 
  1453. function bp_displayed_user_id() { 
  1454. $bp = buddypress(); 
  1455. $id = !empty( $bp->displayed_user->id ) 
  1456. ? $bp->displayed_user->id 
  1457. : 0; 
  1458.  
  1459. /** 
  1460. * Filters the ID of the currently displayed user. 
  1461. * 
  1462. * @since 1.0.0 
  1463. * 
  1464. * @param int $id ID of the currently displayed user. 
  1465. */ 
  1466. return (int) apply_filters( 'bp_displayed_user_id', $id ); 
  1467.  
  1468. /** 
  1469. * Get the ID of the currently logged-in user. 
  1470. * 
  1471. * @since 1.0.0 
  1472. * 
  1473. * @return int ID of the logged-in user. 
  1474. */ 
  1475. function bp_loggedin_user_id() { 
  1476. $bp = buddypress(); 
  1477. $id = !empty( $bp->loggedin_user->id ) 
  1478. ? $bp->loggedin_user->id 
  1479. : 0; 
  1480.  
  1481. /** 
  1482. * Filters the ID of the currently logged-in user. 
  1483. * 
  1484. * @since 1.0.0 
  1485. * 
  1486. * @param int $id ID of the currently logged-in user. 
  1487. */ 
  1488. return (int) apply_filters( 'bp_loggedin_user_id', $id ); 
  1489.  
  1490. /** The is_() functions to determine the current page *****************************/ 
  1491.  
  1492. /** 
  1493. * Check to see whether the current page belongs to the specified component. 
  1494. * 
  1495. * This function is designed to be generous, accepting several different kinds 
  1496. * of value for the $component parameter. It checks $component_name against: 
  1497. * - the component's root_slug, which matches the page slug in $bp->pages. 
  1498. * - the component's regular slug. 
  1499. * - the component's id, or 'canonical' name. 
  1500. * 
  1501. * @since 1.5.0 
  1502. * 
  1503. * @param string $component Name of the component being checked. 
  1504. * @return bool Returns true if the component matches, or else false. 
  1505. */ 
  1506. function bp_is_current_component( $component = '' ) { 
  1507.  
  1508. // Default is no match. We'll check a few places for matches. 
  1509. $is_current_component = false; 
  1510.  
  1511. // Always return false if a null value is passed to the function. 
  1512. if ( empty( $component ) ) { 
  1513. return false; 
  1514.  
  1515. // Backward compatibility: 'xprofile' should be read as 'profile'. 
  1516. if ( 'xprofile' === $component ) { 
  1517. $component = 'profile'; 
  1518.  
  1519. $bp = buddypress(); 
  1520.  
  1521. // Only check if BuddyPress found a current_component. 
  1522. if ( ! empty( $bp->current_component ) ) { 
  1523.  
  1524. // First, check to see whether $component_name and the current 
  1525. // component are a simple match. 
  1526. if ( $bp->current_component == $component ) { 
  1527. $is_current_component = true; 
  1528.  
  1529. // Since the current component is based on the visible URL slug let's 
  1530. // check the component being passed and see if its root_slug matches. 
  1531. } elseif ( isset( $bp->{$component}->root_slug ) && $bp->{$component}->root_slug == $bp->current_component ) { 
  1532. $is_current_component = true; 
  1533.  
  1534. // Because slugs can differ from root_slugs, we should check them too. 
  1535. } elseif ( isset( $bp->{$component}->slug ) && $bp->{$component}->slug == $bp->current_component ) { 
  1536. $is_current_component = true; 
  1537.  
  1538. // Next, check to see whether $component is a canonical,  
  1539. // non-translatable component name. If so, we can return its 
  1540. // corresponding slug from $bp->active_components. 
  1541. } elseif ( $key = array_search( $component, $bp->active_components ) ) { 
  1542. if ( strstr( $bp->current_component, $key ) ) { 
  1543. $is_current_component = true; 
  1544.  
  1545. // If we haven't found a match yet, check against the root_slugs 
  1546. // created by $bp->pages, as well as the regular slugs. 
  1547. } else { 
  1548. foreach ( $bp->active_components as $id ) { 
  1549. // If the $component parameter does not match the current_component,  
  1550. // then move along, these are not the droids you are looking for. 
  1551. if ( empty( $bp->{$id}->root_slug ) || $bp->{$id}->root_slug != $bp->current_component ) { 
  1552. continue; 
  1553.  
  1554. if ( $id == $component ) { 
  1555. $is_current_component = true; 
  1556. break; 
  1557.  
  1558. /** 
  1559. * Filters whether the current page belongs to the specified component. 
  1560. * 
  1561. * @since 1.5.0 
  1562. * 
  1563. * @param bool $is_current_component Whether or not the current page belongs to specified component. 
  1564. * @param string $component Name of the component being checked. 
  1565. */ 
  1566. return apply_filters( 'bp_is_current_component', $is_current_component, $component ); 
  1567.  
  1568. /** 
  1569. * Check to see whether the current page matches a given action. 
  1570. * 
  1571. * Along with bp_is_current_component() and bp_is_action_variable(), this 
  1572. * function is mostly used to help determine when to use a given screen 
  1573. * function. 
  1574. * 
  1575. * In BP parlance, the current_action is the URL chunk that comes directly 
  1576. * after the current item slug. E.g., in 
  1577. * http://example.com/groups/my-group/members 
  1578. * the current_action is 'members'. 
  1579. * 
  1580. * @since 1.5.0 
  1581. * 
  1582. * @param string $action The action being tested against. 
  1583. * @return bool True if the current action matches $action. 
  1584. */ 
  1585. function bp_is_current_action( $action = '' ) { 
  1586. return (bool) ( $action === bp_current_action() ); 
  1587.  
  1588. /** 
  1589. * Check to see whether the current page matches a given action_variable. 
  1590. * 
  1591. * Along with bp_is_current_component() and bp_is_current_action(), this 
  1592. * function is mostly used to help determine when to use a given screen 
  1593. * function. 
  1594. * 
  1595. * In BP parlance, action_variables are an array made up of the URL chunks 
  1596. * appearing after the current_action in a URL. For example,  
  1597. * http://example.com/groups/my-group/admin/group-settings 
  1598. * $action_variables[0] is 'group-settings'. 
  1599. * 
  1600. * @since 1.5.0 
  1601. * 
  1602. * @param string $action_variable The action_variable being tested against. 
  1603. * @param int|bool $position Optional. The array key you're testing against. If you 
  1604. * don't provide a $position, the function will return true if the 
  1605. * $action_variable is found *anywhere* in the action variables array. 
  1606. * @return bool True if $action_variable matches at the $position provided. 
  1607. */ 
  1608. function bp_is_action_variable( $action_variable = '', $position = false ) { 
  1609. $is_action_variable = false; 
  1610.  
  1611. if ( false !== $position ) { 
  1612. // When a $position is specified, check that slot in the action_variables array. 
  1613. if ( $action_variable ) { 
  1614. $is_action_variable = $action_variable == bp_action_variable( $position ); 
  1615. } else { 
  1616. // If no $action_variable is provided, we are essentially checking to see 
  1617. // whether the slot is empty. 
  1618. $is_action_variable = !bp_action_variable( $position ); 
  1619. } else { 
  1620. // When no $position is specified, check the entire array. 
  1621. $is_action_variable = in_array( $action_variable, (array)bp_action_variables() ); 
  1622.  
  1623. /** 
  1624. * Filters whether the current page matches a given action_variable. 
  1625. * 
  1626. * @since 1.5.0 
  1627. * 
  1628. * @param bool $is_action_variable Whether the current page matches a given action_variable. 
  1629. * @param string $action_variable The action_variable being tested against. 
  1630. * @param int $position The array key tested against. 
  1631. */ 
  1632. return apply_filters( 'bp_is_action_variable', $is_action_variable, $action_variable, $position ); 
  1633.  
  1634. /** 
  1635. * Check against the current_item. 
  1636. * 
  1637. * @since 1.5.0 
  1638. * 
  1639. * @param string $item The item being checked. 
  1640. * @return bool True if $item is the current item. 
  1641. */ 
  1642. function bp_is_current_item( $item = '' ) { 
  1643. $retval = ( $item === bp_current_item() ); 
  1644.  
  1645. /** 
  1646. * Filters whether or not an item is the current item. 
  1647. * 
  1648. * @since 2.1.0 
  1649. * 
  1650. * @param bool $retval Whether or not an item is the current item. 
  1651. * @param string $item The item being checked. 
  1652. */ 
  1653. return (bool) apply_filters( 'bp_is_current_item', $retval, $item ); 
  1654.  
  1655. /** 
  1656. * Are we looking at a single item? (group, user, etc). 
  1657. * 
  1658. * @since 1.1.0 
  1659. * 
  1660. * @return bool True if looking at a single item, otherwise false. 
  1661. */ 
  1662. function bp_is_single_item() { 
  1663. $bp = buddypress(); 
  1664. $retval = false; 
  1665.  
  1666. if ( isset( $bp->is_single_item ) ) { 
  1667. $retval = $bp->is_single_item; 
  1668.  
  1669. /** 
  1670. * Filters whether or not an item is the a single item. (group, user, etc) 
  1671. * 
  1672. * @since 2.1.0 
  1673. * 
  1674. * @param bool $retval Whether or not an item is a single item. 
  1675. */ 
  1676. return (bool) apply_filters( 'bp_is_single_item', $retval ); 
  1677.  
  1678. /** 
  1679. * Is the logged-in user an admin for the current item? 
  1680. * 
  1681. * @since 1.5.0 
  1682. * 
  1683. * @return bool True if the current user is an admin for the current item,  
  1684. * otherwise false. 
  1685. */ 
  1686. function bp_is_item_admin() { 
  1687. $bp = buddypress(); 
  1688. $retval = false; 
  1689.  
  1690. if ( isset( $bp->is_item_admin ) ) { 
  1691. $retval = $bp->is_item_admin; 
  1692.  
  1693. /** 
  1694. * Filters whether or not the logged-in user is an admin for the current item. 
  1695. * 
  1696. * @since 2.1.0 
  1697. * 
  1698. * @param bool $retval Whether or not the logged-in user is an admin. 
  1699. */ 
  1700. return (bool) apply_filters( 'bp_is_item_admin', $retval ); 
  1701.  
  1702. /** 
  1703. * Is the logged-in user a mod for the current item? 
  1704. * 
  1705. * @since 1.5.0 
  1706. * 
  1707. * @return bool True if the current user is a mod for the current item,  
  1708. * otherwise false. 
  1709. */ 
  1710. function bp_is_item_mod() { 
  1711. $bp = buddypress(); 
  1712. $retval = false; 
  1713.  
  1714. if ( isset( $bp->is_item_mod ) ) { 
  1715. $retval = $bp->is_item_mod; 
  1716.  
  1717. /** 
  1718. * Filters whether or not the logged-in user is a mod for the current item. 
  1719. * 
  1720. * @since 2.1.0 
  1721. * 
  1722. * @param bool $retval Whether or not the logged-in user is a mod. 
  1723. */ 
  1724. return (bool) apply_filters( 'bp_is_item_mod', $retval ); 
  1725.  
  1726. /** 
  1727. * Is this a component directory page? 
  1728. * 
  1729. * @since 1.0.0 
  1730. * 
  1731. * @return bool True if the current page is a component directory, otherwise false. 
  1732. */ 
  1733. function bp_is_directory() { 
  1734. $bp = buddypress(); 
  1735. $retval = false; 
  1736.  
  1737. if ( isset( $bp->is_directory ) ) { 
  1738. $retval = $bp->is_directory; 
  1739.  
  1740. /** 
  1741. * Filters whether or not user is on a component directory page. 
  1742. * 
  1743. * @since 2.1.0 
  1744. * 
  1745. * @param bool $retval Whether or not user is on a component directory page. 
  1746. */ 
  1747. return (bool) apply_filters( 'bp_is_directory', $retval ); 
  1748.  
  1749. /** 
  1750. * Check to see if a component's URL should be in the root, not under a member page. 
  1751. * 
  1752. * - Yes ('groups' is root) : http://example.com/groups/the-group 
  1753. * - No ('groups' is not-root): http://example.com/members/andy/groups/the-group 
  1754. * 
  1755. * This function is on the chopping block. It's currently only used by a few 
  1756. * already deprecated functions. 
  1757. * 
  1758. * @since 1.5.0 
  1759. * 
  1760. * @param string $component_name Component name to check. 
  1761. * 
  1762. * @return bool True if root component, else false. 
  1763. */ 
  1764. function bp_is_root_component( $component_name = '' ) { 
  1765. $bp = buddypress(); 
  1766. $retval = false; 
  1767.  
  1768. // Default to the current component if none is passed. 
  1769. if ( empty( $component_name ) ) { 
  1770. $component_name = bp_current_component(); 
  1771.  
  1772. // Loop through active components and check for key/slug matches. 
  1773. if ( ! empty( $bp->active_components ) ) { 
  1774. foreach ( (array) $bp->active_components as $key => $slug ) { 
  1775. if ( ( $key === $component_name ) || ( $slug === $component_name ) ) { 
  1776. $retval = true; 
  1777. break; 
  1778.  
  1779. /** 
  1780. * Filters whether or not a component's URL should be in the root, not under a member page. 
  1781. * 
  1782. * @since 2.1.0 
  1783. * 
  1784. * @param bool $retval Whether or not URL should be in the root. 
  1785. */ 
  1786. return (bool) apply_filters( 'bp_is_root_component', $retval ); 
  1787.  
  1788. /** 
  1789. * Check if the specified BuddyPress component directory is set to be the front page. 
  1790. * 
  1791. * Corresponds to the setting in wp-admin's Settings > Reading screen. 
  1792. * 
  1793. * @since 1.5.0 
  1794. * 
  1795. * @global int $current_blog WordPress global for the current blog. 
  1796. * 
  1797. * @param string $component Optional. Name of the component to check for. 
  1798. * Default: current component. 
  1799. * @return bool True if the specified component is set to be the site's front 
  1800. * page, otherwise false. 
  1801. */ 
  1802. function bp_is_component_front_page( $component = '' ) { 
  1803. global $current_blog; 
  1804.  
  1805. $bp = buddypress(); 
  1806.  
  1807. // Default to the current component if none is passed. 
  1808. if ( empty( $component ) ) { 
  1809. $component = bp_current_component(); 
  1810.  
  1811. // Get the path for the current blog/site. 
  1812. $path = is_main_site() 
  1813. ? bp_core_get_site_path() 
  1814. : $current_blog->path; 
  1815.  
  1816. // Get the front page variables. 
  1817. $show_on_front = get_option( 'show_on_front' ); 
  1818. $page_on_front = get_option( 'page_on_front' ); 
  1819.  
  1820. if ( ( 'page' !== $show_on_front ) || empty( $component ) || empty( $bp->pages->{$component} ) || ( $_SERVER['REQUEST_URI'] !== $path ) ) { 
  1821. return false; 
  1822.  
  1823. /** 
  1824. * Filters whether or not the specified BuddyPress component directory is set to be the front page. 
  1825. * 
  1826. * @since 1.5.0 
  1827. * 
  1828. * @param bool $value Whether or not the specified component directory is set as front page. 
  1829. * @param string $component Current component being checked. 
  1830. */ 
  1831. return (bool) apply_filters( 'bp_is_component_front_page', ( $bp->pages->{$component}->id == $page_on_front ), $component ); 
  1832.  
  1833. /** 
  1834. * Is this a blog page, ie a non-BP page? 
  1835. * 
  1836. * You can tell if a page is displaying BP content by whether the 
  1837. * current_component has been defined. 
  1838. * 
  1839. * @since 1.0.0 
  1840. * 
  1841. * @return bool True if it's a non-BP page, false otherwise. 
  1842. */ 
  1843. function bp_is_blog_page() { 
  1844.  
  1845. $is_blog_page = false; 
  1846.  
  1847. // Generally, we can just check to see that there's no current component. 
  1848. // The one exception is single user home tabs, where $bp->current_component 
  1849. // is unset. Thus the addition of the bp_is_user() check. 
  1850. if ( ! bp_current_component() && ! bp_is_user() ) { 
  1851. $is_blog_page = true; 
  1852.  
  1853. /** 
  1854. * Filters whether or not current page is a blog page or not. 
  1855. * 
  1856. * @since 1.5.0 
  1857. * 
  1858. * @param bool $is_blog_page Whether or not current page is a blog page. 
  1859. */ 
  1860. return (bool) apply_filters( 'bp_is_blog_page', $is_blog_page ); 
  1861.  
  1862. /** 
  1863. * Is this a BuddyPress component? 
  1864. * 
  1865. * You can tell if a page is displaying BP content by whether the 
  1866. * current_component has been defined. 
  1867. * 
  1868. * Generally, we can just check to see that there's no current component. 
  1869. * The one exception is single user home tabs, where $bp->current_component 
  1870. * is unset. Thus the addition of the bp_is_user() check. 
  1871. * 
  1872. * @since 1.7.0 
  1873. * 
  1874. * @return bool True if it's a BuddyPress page, false otherwise. 
  1875. */ 
  1876. function is_buddypress() { 
  1877. $retval = (bool) ( bp_current_component() || bp_is_user() ); 
  1878.  
  1879. /** 
  1880. * Filters whether or not this is a BuddyPress component. 
  1881. * 
  1882. * @since 1.7.0 
  1883. * 
  1884. * @param bool $retval Whether or not this is a BuddyPress component. 
  1885. */ 
  1886. return apply_filters( 'is_buddypress', $retval ); 
  1887.  
  1888. /** Components ****************************************************************/ 
  1889.  
  1890. /** 
  1891. * Check whether a given component (or feature of a component) is active. 
  1892. * 
  1893. * @since 1.2.0 See r2539. 
  1894. * @since 2.3.0 Added $feature as a parameter. 
  1895. * 
  1896. * @param string $component The component name. 
  1897. * @param string $feature The feature name. 
  1898. * @return bool 
  1899. */ 
  1900. function bp_is_active( $component = '', $feature = '' ) { 
  1901. $retval = false; 
  1902.  
  1903. // Default to the current component if none is passed. 
  1904. if ( empty( $component ) ) { 
  1905. $component = bp_current_component(); 
  1906.  
  1907. // Is component in either the active or required components arrays. 
  1908. if ( isset( buddypress()->active_components[ $component ] ) || isset( buddypress()->required_components[ $component ] ) ) { 
  1909. $retval = true; 
  1910.  
  1911. // Is feature active? 
  1912. if ( ! empty( $feature ) ) { 
  1913. // The xProfile component is specific. 
  1914. if ( 'xprofile' === $component ) { 
  1915. $component = 'profile'; 
  1916.  
  1917. if ( empty( buddypress()->$component->features ) || false === in_array( $feature, buddypress()->$component->features, true ) ) { 
  1918. $retval = false; 
  1919.  
  1920. /** 
  1921. * Filters whether or not a given feature for a component is active. 
  1922. * 
  1923. * This is a variable filter that is based on the component and feature 
  1924. * that you are checking of active status of. 
  1925. * 
  1926. * @since 2.3.0 
  1927. * 
  1928. * @param bool $retval 
  1929. */ 
  1930. $retval = apply_filters( "bp_is_{$component}_{$feature}_active", $retval ); 
  1931.  
  1932. /** 
  1933. * Filters whether or not a given component has been activated by the admin. 
  1934. * 
  1935. * @since 2.1.0 
  1936. * 
  1937. * @param bool $retval Whether or not a given component has been activated by the admin. 
  1938. * @param string $component Current component being checked. 
  1939. */ 
  1940. return apply_filters( 'bp_is_active', $retval, $component ); 
  1941.  
  1942. /** 
  1943. * Check whether the current page is part of the Members component. 
  1944. * 
  1945. * @since 1.5.0 
  1946. * 
  1947. * @return bool True if the current page is part of the Members component. 
  1948. */ 
  1949. function bp_is_members_component() { 
  1950. return (bool) bp_is_current_component( 'members' ); 
  1951.  
  1952. /** 
  1953. * Check whether the current page is part of the Profile component. 
  1954. * 
  1955. * @since 1.1.0 
  1956. * 
  1957. * @return bool True if the current page is part of the Profile component. 
  1958. */ 
  1959. function bp_is_profile_component() { 
  1960. return (bool) bp_is_current_component( 'xprofile' ); 
  1961.  
  1962. /** 
  1963. * Check whether the current page is part of the Activity component. 
  1964. * 
  1965. * @since 1.1.0 
  1966. * 
  1967. * @return bool True if the current page is part of the Activity component. 
  1968. */ 
  1969. function bp_is_activity_component() { 
  1970. return (bool) bp_is_current_component( 'activity' ); 
  1971.  
  1972. /** 
  1973. * Check whether the current page is part of the Blogs component. 
  1974. * 
  1975. * @since 1.1.0 
  1976. * 
  1977. * @return bool True if the current page is part of the Blogs component. 
  1978. */ 
  1979. function bp_is_blogs_component() { 
  1980. return (bool) ( is_multisite() && bp_is_current_component( 'blogs' ) ); 
  1981.  
  1982. /** 
  1983. * Check whether the current page is part of the Messages component. 
  1984. * 
  1985. * @since 1.1.0 
  1986. * 
  1987. * @return bool True if the current page is part of the Messages component. 
  1988. */ 
  1989. function bp_is_messages_component() { 
  1990. return (bool) bp_is_current_component( 'messages' ); 
  1991.  
  1992. /** 
  1993. * Check whether the current page is part of the Friends component. 
  1994. * 
  1995. * @since 1.1.0 
  1996. * 
  1997. * @return bool True if the current page is part of the Friends component. 
  1998. */ 
  1999. function bp_is_friends_component() { 
  2000. return (bool) bp_is_current_component( 'friends' ); 
  2001.  
  2002. /** 
  2003. * Check whether the current page is part of the Groups component. 
  2004. * 
  2005. * @since 1.1.0 
  2006. * 
  2007. * @return bool True if the current page is part of the Groups component. 
  2008. */ 
  2009. function bp_is_groups_component() { 
  2010. return (bool) bp_is_current_component( 'groups' ); 
  2011.  
  2012. /** 
  2013. * Check whether the current page is part of the Forums component. 
  2014. * 
  2015. * @since 1.5.0 
  2016. * 
  2017. * @return bool True if the current page is part of the Forums component. 
  2018. */ 
  2019. function bp_is_forums_component() { 
  2020. return (bool) bp_is_current_component( 'forums' ); 
  2021.  
  2022. /** 
  2023. * Check whether the current page is part of the Notifications component. 
  2024. * 
  2025. * @since 1.9.0 
  2026. * 
  2027. * @return bool True if the current page is part of the Notifications component. 
  2028. */ 
  2029. function bp_is_notifications_component() { 
  2030. return (bool) bp_is_current_component( 'notifications' ); 
  2031.  
  2032. /** 
  2033. * Check whether the current page is part of the Settings component. 
  2034. * 
  2035. * @since 1.1.0 
  2036. * 
  2037. * @return bool True if the current page is part of the Settings component. 
  2038. */ 
  2039. function bp_is_settings_component() { 
  2040. return (bool) bp_is_current_component( 'settings' ); 
  2041.  
  2042. /** 
  2043. * Is the current component an active core component? 
  2044. * 
  2045. * Use this function when you need to check if the current component is an 
  2046. * active core component of BuddyPress. If the current component is inactive, it 
  2047. * will return false. If the current component is not part of BuddyPress core,  
  2048. * it will return false. If the current component is active, and is part of 
  2049. * BuddyPress core, it will return true. 
  2050. * 
  2051. * @since 1.7.0 
  2052. * 
  2053. * @return bool True if the current component is active and is one of BP's 
  2054. * packaged components. 
  2055. */ 
  2056. function bp_is_current_component_core() { 
  2057. $retval = false; 
  2058.  
  2059. foreach ( bp_core_get_packaged_component_ids() as $active_component ) { 
  2060. if ( bp_is_current_component( $active_component ) ) { 
  2061. $retval = true; 
  2062. break; 
  2063.  
  2064. return $retval; 
  2065.  
  2066. /** Activity ******************************************************************/ 
  2067.  
  2068. /** 
  2069. * Is the current page the activity directory? 
  2070. * 
  2071. * @since 2.0.0 
  2072. * 
  2073. * @return bool True if the current page is the activity directory. 
  2074. */ 
  2075. function bp_is_activity_directory() { 
  2076. if ( ! bp_displayed_user_id() && bp_is_activity_component() && ! bp_current_action() ) { 
  2077. return true; 
  2078.  
  2079. return false; 
  2080.  
  2081. /** 
  2082. * Is the current page a single activity item permalink? 
  2083. * 
  2084. * @since 1.5.0 
  2085. * 
  2086. * @return bool True if the current page is a single activity item permalink. 
  2087. */ 
  2088. function bp_is_single_activity() { 
  2089. return (bool) ( bp_is_activity_component() && is_numeric( bp_current_action() ) ); 
  2090.  
  2091. /** User **********************************************************************/ 
  2092.  
  2093. /** 
  2094. * Is the current page the members directory? 
  2095. * 
  2096. * @since 2.0.0 
  2097. * 
  2098. * @return bool True if the current page is the members directory. 
  2099. */ 
  2100. function bp_is_members_directory() { 
  2101. if ( ! bp_is_user() && bp_is_members_component() ) { 
  2102. return true; 
  2103.  
  2104. return false; 
  2105.  
  2106. /** 
  2107. * Is the current page part of the profile of the logged-in user? 
  2108. * 
  2109. * Will return true for any subpage of the logged-in user's profile, eg 
  2110. * http://example.com/members/joe/friends/. 
  2111. * 
  2112. * @since 1.2.0 
  2113. * 
  2114. * @return bool True if the current page is part of the profile of the logged-in user. 
  2115. */ 
  2116. function bp_is_my_profile() { 
  2117. if ( is_user_logged_in() && bp_loggedin_user_id() == bp_displayed_user_id() ) { 
  2118. $my_profile = true; 
  2119. } else { 
  2120. $my_profile = false; 
  2121.  
  2122. /** 
  2123. * Filters whether or not current page is part of the profile for the logged-in user. 
  2124. * 
  2125. * @since 1.2.4 
  2126. * 
  2127. * @param bool $my_profile Whether or not current page is part of the profile for the logged-in user. 
  2128. */ 
  2129. return apply_filters( 'bp_is_my_profile', $my_profile ); 
  2130.  
  2131. /** 
  2132. * Is the current page a user page? 
  2133. * 
  2134. * Will return true anytime there is a displayed user. 
  2135. * 
  2136. * @since 1.5.0 
  2137. * 
  2138. * @return bool True if the current page is a user page. 
  2139. */ 
  2140. function bp_is_user() { 
  2141. return (bool) bp_displayed_user_id(); 
  2142.  
  2143. /** 
  2144. * Is the current page a user custom front page? 
  2145. * 
  2146. * Will return true anytime there is a custom front page for the displayed user. 
  2147. * 
  2148. * @since 2.6.0 
  2149. * 
  2150. * @return bool True if the current page is a user custom front page. 
  2151. */ 
  2152. function bp_is_user_front() { 
  2153. return (bool) ( bp_is_user() && bp_is_current_component( 'front' ) ); 
  2154.  
  2155. /** 
  2156. * Is the current page a user's activity stream page? 
  2157. * 
  2158. * Eg http://example.com/members/joe/activity/ (or any subpages thereof). 
  2159. * 
  2160. * @since 1.1.0 
  2161. * 
  2162. * @return bool True if the current page is a user's activity stream page. 
  2163. */ 
  2164. function bp_is_user_activity() { 
  2165. return (bool) ( bp_is_user() && bp_is_activity_component() ); 
  2166.  
  2167. /** 
  2168. * Is the current page a user's Friends activity stream? 
  2169. * 
  2170. * Eg http://example.com/members/joe/friends/ 
  2171. * 
  2172. * @since 1.1.0 
  2173. * 
  2174. * @return bool True if the current page is a user's Friends activity stream. 
  2175. */ 
  2176. function bp_is_user_friends_activity() { 
  2177.  
  2178. if ( ! bp_is_active( 'friends' ) ) { 
  2179. return false; 
  2180.  
  2181. $slug = bp_get_friends_slug(); 
  2182.  
  2183. if ( empty( $slug ) ) { 
  2184. $slug = 'friends'; 
  2185.  
  2186. if ( bp_is_user_activity() && bp_is_current_action( $slug ) ) { 
  2187. return true; 
  2188.  
  2189. return false; 
  2190.  
  2191. /** 
  2192. * Is the current page a user's Groups activity stream? 
  2193. * 
  2194. * Eg http://example.com/members/joe/groups/ 
  2195. * 
  2196. * @since 1.5.0 
  2197. * 
  2198. * @return bool True if the current page is a user's Groups activity stream. 
  2199. */ 
  2200. function bp_is_user_groups_activity() { 
  2201.  
  2202. if ( ! bp_is_active( 'groups' ) ) { 
  2203. return false; 
  2204.  
  2205. $slug = ( bp_get_groups_slug() ) 
  2206. ? bp_get_groups_slug() 
  2207. : 'groups'; 
  2208.  
  2209. if ( bp_is_user_activity() && bp_is_current_action( $slug ) ) { 
  2210. return true; 
  2211.  
  2212. return false; 
  2213.  
  2214. /** 
  2215. * Is the current page part of a user's extended profile? 
  2216. * 
  2217. * Eg http://example.com/members/joe/profile/ (or a subpage thereof). 
  2218. * 
  2219. * @since 1.1.0 
  2220. * 
  2221. * @return bool True if the current page is part of a user's extended profile. 
  2222. */ 
  2223. function bp_is_user_profile() { 
  2224. return (bool) ( bp_is_profile_component() || bp_is_current_component( 'profile' ) ); 
  2225.  
  2226. /** 
  2227. * Is the current page part of a user's profile editing section? 
  2228. * 
  2229. * Eg http://example.com/members/joe/profile/edit/ (or a subpage thereof). 
  2230. * 
  2231. * @since 1.5.0 
  2232. * 
  2233. * @return bool True if the current page is a user's profile edit page. 
  2234. */ 
  2235. function bp_is_user_profile_edit() { 
  2236. return (bool) ( bp_is_profile_component() && bp_is_current_action( 'edit' ) ); 
  2237.  
  2238. /** 
  2239. * Is the current page part of a user's profile avatar editing section? 
  2240. * 
  2241. * Eg http://example.com/members/joe/profile/change-avatar/ (or a subpage thereof). 
  2242. * 
  2243. * @since 1.5.0 
  2244. * 
  2245. * @return bool True if the current page is the user's avatar edit page. 
  2246. */ 
  2247. function bp_is_user_change_avatar() { 
  2248. return (bool) ( bp_is_profile_component() && bp_is_current_action( 'change-avatar' ) ); 
  2249.  
  2250. /** 
  2251. * Is the current page the a user's change cover image profile page? 
  2252. * 
  2253. * Eg http://example.com/members/joe/profile/change-cover-image/ (or a subpage thereof). 
  2254. * 
  2255. * @since 2.4.0 
  2256. * 
  2257. * @return bool True if the current page is a user's profile edit cover image page. 
  2258. */ 
  2259. function bp_is_user_change_cover_image() { 
  2260. return (bool) ( bp_is_profile_component() && bp_is_current_action( 'change-cover-image' ) ); 
  2261.  
  2262. /** 
  2263. * Is this a user's forums page? 
  2264. * 
  2265. * Eg http://example.com/members/joe/forums/ (or a subpage thereof). 
  2266. * 
  2267. * @since 1.5.0 
  2268. * 
  2269. * @return bool True if the current page is a user's forums page. 
  2270. */ 
  2271. function bp_is_user_forums() { 
  2272.  
  2273. if ( ! bp_is_active( 'forums' ) ) { 
  2274. return false; 
  2275.  
  2276. if ( bp_is_user() && bp_is_forums_component() ) { 
  2277. return true; 
  2278.  
  2279. return false; 
  2280.  
  2281. /** 
  2282. * Is this a user's "Topics Started" page? 
  2283. * 
  2284. * Eg http://example.com/members/joe/forums/topics/. 
  2285. * 
  2286. * @since 1.5.0 
  2287. * 
  2288. * @return bool True if the current page is a user's Topics Started page. 
  2289. */ 
  2290. function bp_is_user_forums_started() { 
  2291. return (bool) ( bp_is_user_forums() && bp_is_current_action( 'topics' ) ); 
  2292.  
  2293. /** 
  2294. * Is this a user's "Replied To" page? 
  2295. * 
  2296. * Eg http://example.com/members/joe/forums/replies/. 
  2297. * 
  2298. * @since 1.5.0 
  2299. * 
  2300. * @return bool True if the current page is a user's Replied To forums page. 
  2301. */ 
  2302. function bp_is_user_forums_replied_to() { 
  2303. return (bool) ( bp_is_user_forums() && bp_is_current_action( 'replies' ) ); 
  2304.  
  2305. /** 
  2306. * Is the current page part of a user's Groups page? 
  2307. * 
  2308. * Eg http://example.com/members/joe/groups/ (or a subpage thereof). 
  2309. * 
  2310. * @since 1.1.0 
  2311. * 
  2312. * @return bool True if the current page is a user's Groups page. 
  2313. */ 
  2314. function bp_is_user_groups() { 
  2315. return (bool) ( bp_is_user() && bp_is_groups_component() ); 
  2316.  
  2317. /** 
  2318. * Is the current page part of a user's Blogs page? 
  2319. * 
  2320. * Eg http://example.com/members/joe/blogs/ (or a subpage thereof). 
  2321. * 
  2322. * @since 1.1.0 
  2323. * 
  2324. * @return bool True if the current page is a user's Blogs page. 
  2325. */ 
  2326. function bp_is_user_blogs() { 
  2327. return (bool) ( bp_is_user() && bp_is_blogs_component() ); 
  2328.  
  2329. /** 
  2330. * Is the current page a user's Recent Blog Posts page? 
  2331. * 
  2332. * Eg http://example.com/members/joe/blogs/recent-posts/. 
  2333. * 
  2334. * @since 1.1.0 
  2335. * 
  2336. * @return bool True if the current page is a user's Recent Blog Posts page. 
  2337. */ 
  2338. function bp_is_user_recent_posts() { 
  2339. return (bool) ( bp_is_user_blogs() && bp_is_current_action( 'recent-posts' ) ); 
  2340.  
  2341. /** 
  2342. * Is the current page a user's Recent Blog Comments page? 
  2343. * 
  2344. * Eg http://example.com/members/joe/blogs/recent-comments/. 
  2345. * 
  2346. * @since 1.1.0 
  2347. * 
  2348. * @return bool True if the current page is a user's Recent Blog Comments page. 
  2349. */ 
  2350. function bp_is_user_recent_commments() { 
  2351. return (bool) ( bp_is_user_blogs() && bp_is_current_action( 'recent-comments' ) ); 
  2352.  
  2353. /** 
  2354. * Is the current page a user's Friends page? 
  2355. * 
  2356. * Eg http://example.com/members/joe/blogs/friends/ (or a subpage thereof). 
  2357. * 
  2358. * @since 1.1.0 
  2359. * 
  2360. * @return bool True if the current page is a user's Friends page. 
  2361. */ 
  2362. function bp_is_user_friends() { 
  2363. return (bool) ( bp_is_user() && bp_is_friends_component() ); 
  2364.  
  2365. /** 
  2366. * Is the current page a user's Friend Requests page? 
  2367. * 
  2368. * Eg http://example.com/members/joe/friends/requests/. 
  2369. * 
  2370. * @since 1.5.0 
  2371. * 
  2372. * @return bool True if the current page is a user's Friends Requests page. 
  2373. */ 
  2374. function bp_is_user_friend_requests() { 
  2375. return (bool) ( bp_is_user_friends() && bp_is_current_action( 'requests' ) ); 
  2376.  
  2377. /** 
  2378. * Is this a user's notifications page? 
  2379. * 
  2380. * Eg http://example.com/members/joe/notifications/ (or a subpage thereof). 
  2381. * 
  2382. * @since 1.9.0 
  2383. * 
  2384. * @return bool True if the current page is a user's Notifications page. 
  2385. */ 
  2386. function bp_is_user_notifications() { 
  2387. return (bool) ( bp_is_user() && bp_is_notifications_component() ); 
  2388.  
  2389. /** 
  2390. * Is this a user's settings page? 
  2391. * 
  2392. * Eg http://example.com/members/joe/settings/ (or a subpage thereof). 
  2393. * 
  2394. * @since 1.5.0 
  2395. * 
  2396. * @return bool True if the current page is a user's Settings page. 
  2397. */ 
  2398. function bp_is_user_settings() { 
  2399. return (bool) ( bp_is_user() && bp_is_settings_component() ); 
  2400.  
  2401. /** 
  2402. * Is this a user's General Settings page? 
  2403. * 
  2404. * Eg http://example.com/members/joe/settings/general/. 
  2405. * 
  2406. * @since 1.5.0 
  2407. * 
  2408. * @return bool True if the current page is a user's General Settings page. 
  2409. */ 
  2410. function bp_is_user_settings_general() { 
  2411. return (bool) ( bp_is_user_settings() && bp_is_current_action( 'general' ) ); 
  2412.  
  2413. /** 
  2414. * Is this a user's Notification Settings page? 
  2415. * 
  2416. * Eg http://example.com/members/joe/settings/notifications/. 
  2417. * 
  2418. * @since 1.5.0 
  2419. * 
  2420. * @return bool True if the current page is a user's Notification Settings page. 
  2421. */ 
  2422. function bp_is_user_settings_notifications() { 
  2423. return (bool) ( bp_is_user_settings() && bp_is_current_action( 'notifications' ) ); 
  2424.  
  2425. /** 
  2426. * Is this a user's Account Deletion page? 
  2427. * 
  2428. * Eg http://example.com/members/joe/settings/delete-account/. 
  2429. * 
  2430. * @since 1.5.0 
  2431. * 
  2432. * @return bool True if the current page is a user's Delete Account page. 
  2433. */ 
  2434. function bp_is_user_settings_account_delete() { 
  2435. return (bool) ( bp_is_user_settings() && bp_is_current_action( 'delete-account' ) ); 
  2436.  
  2437. /** 
  2438. * Is this a user's profile settings? 
  2439. * 
  2440. * Eg http://example.com/members/joe/settings/profile/. 
  2441. * 
  2442. * @since 2.0.0 
  2443. * 
  2444. * @return bool True if the current page is a user's Profile Settings page. 
  2445. */ 
  2446. function bp_is_user_settings_profile() { 
  2447. return (bool) ( bp_is_user_settings() && bp_is_current_action( 'profile' ) ); 
  2448.  
  2449. /** Groups ********************************************************************/ 
  2450.  
  2451. /** 
  2452. * Is the current page the groups directory? 
  2453. * 
  2454. * @since 2.0.0 
  2455. * 
  2456. * @return True if the current page is the groups directory. 
  2457. */ 
  2458. function bp_is_groups_directory() { 
  2459. if ( bp_is_groups_component() && ! bp_is_group() && ( ! bp_current_action() || ( bp_action_variable() && bp_is_current_action( bp_get_groups_group_type_base() ) ) ) ) { 
  2460. return true; 
  2461.  
  2462. return false; 
  2463.  
  2464. /** 
  2465. * Does the current page belong to a single group? 
  2466. * 
  2467. * Will return true for any subpage of a single group. 
  2468. * 
  2469. * @since 1.2.0 
  2470. * 
  2471. * @return bool True if the current page is part of a single group. 
  2472. */ 
  2473. function bp_is_group() { 
  2474. $retval = bp_is_active( 'groups' ); 
  2475.  
  2476. if ( ! empty( $retval ) ) { 
  2477. $retval = bp_is_groups_component() && groups_get_current_group(); 
  2478.  
  2479. return (bool) $retval; 
  2480.  
  2481. /** 
  2482. * Is the current page a single group's home page? 
  2483. * 
  2484. * URL will vary depending on which group tab is set to be the "home". By 
  2485. * default, it's the group's recent activity. 
  2486. * 
  2487. * @since 1.1.0 
  2488. * 
  2489. * @return bool True if the current page is a single group's home page. 
  2490. */ 
  2491. function bp_is_group_home() { 
  2492. if ( bp_is_single_item() && bp_is_groups_component() && ( ! bp_current_action() || bp_is_current_action( 'home' ) ) ) { 
  2493. return true; 
  2494.  
  2495. return false; 
  2496.  
  2497. /** 
  2498. * Is the current page part of the group creation process? 
  2499. * 
  2500. * @since 1.1.0 
  2501. * 
  2502. * @return bool True if the current page is part of the group creation process. 
  2503. */ 
  2504. function bp_is_group_create() { 
  2505. return (bool) ( bp_is_groups_component() && bp_is_current_action( 'create' ) ); 
  2506.  
  2507. /** 
  2508. * Is the current page part of a single group's admin screens? 
  2509. * 
  2510. * Eg http://example.com/groups/mygroup/admin/settings/. 
  2511. * 
  2512. * @since 1.1.0 
  2513. * 
  2514. * @return bool True if the current page is part of a single group's admin. 
  2515. */ 
  2516. function bp_is_group_admin_page() { 
  2517. return (bool) ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'admin' ) ); 
  2518.  
  2519. /** 
  2520. * Is the current page a group's forum page? 
  2521. * 
  2522. * Only applies to legacy bbPress forums. 
  2523. * 
  2524. * @since 1.1.0 
  2525. * 
  2526. * @return bool True if the current page is a group forum page. 
  2527. */ 
  2528. function bp_is_group_forum() { 
  2529. $retval = false; 
  2530.  
  2531. // At a forum URL. 
  2532. if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'forum' ) ) { 
  2533. $retval = true; 
  2534.  
  2535. // If at a forum URL, set back to false if forums are inactive, or not 
  2536. // installed correctly. 
  2537. if ( ! bp_is_active( 'forums' ) || ! bp_forums_is_installed_correctly() ) { 
  2538. $retval = false; 
  2539.  
  2540. return $retval; 
  2541.  
  2542. /** 
  2543. * Is the current page a group's activity page? 
  2544. * 
  2545. * @since 1.2.1 
  2546. * 
  2547. * @return True if the current page is a group's activity page. 
  2548. */ 
  2549. function bp_is_group_activity() { 
  2550. $retval = false; 
  2551.  
  2552. if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'activity' ) ) { 
  2553. $retval = true; 
  2554.  
  2555. if ( bp_is_group_home() && bp_is_active( 'activity' ) && ! bp_is_group_custom_front() ) { 
  2556. $retval = true; 
  2557.  
  2558. return $retval; 
  2559.  
  2560. /** 
  2561. * Is the current page a group forum topic? 
  2562. * 
  2563. * Only applies to legacy bbPress (1.x) forums. 
  2564. * 
  2565. * @since 1.1.0 
  2566. * 
  2567. * @return bool True if the current page is part of a group forum topic. 
  2568. */ 
  2569. function bp_is_group_forum_topic() { 
  2570. return (bool) ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'forum' ) && bp_is_action_variable( 'topic', 0 ) ); 
  2571.  
  2572. /** 
  2573. * Is the current page a group forum topic edit page? 
  2574. * 
  2575. * Only applies to legacy bbPress (1.x) forums. 
  2576. * 
  2577. * @since 1.2.0 
  2578. * 
  2579. * @return bool True if the current page is part of a group forum topic edit page. 
  2580. */ 
  2581. function bp_is_group_forum_topic_edit() { 
  2582. return (bool) ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'forum' ) && bp_is_action_variable( 'topic', 0 ) && bp_is_action_variable( 'edit', 2 ) ); 
  2583.  
  2584. /** 
  2585. * Is the current page a group's Members page? 
  2586. * 
  2587. * Eg http://example.com/groups/mygroup/members/. 
  2588. * 
  2589. * @since 1.1.0 
  2590. * 
  2591. * @return bool True if the current page is part of a group's Members page. 
  2592. */ 
  2593. function bp_is_group_members() { 
  2594. $retval = false; 
  2595.  
  2596. if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'members' ) ) { 
  2597. $retval = true; 
  2598.  
  2599. if ( bp_is_group_home() && ! bp_is_active( 'activity' ) && ! bp_is_group_custom_front() ) { 
  2600. $retval = true; 
  2601.  
  2602. return $retval; 
  2603.  
  2604. /** 
  2605. * Is the current page a group's Invites page? 
  2606. * 
  2607. * Eg http://example.com/groups/mygroup/send-invites/. 
  2608. * 
  2609. * @since 1.1.0 
  2610. * 
  2611. * @return bool True if the current page is a group's Send Invites page. 
  2612. */ 
  2613. function bp_is_group_invites() { 
  2614. return (bool) ( bp_is_groups_component() && bp_is_current_action( 'send-invites' ) ); 
  2615.  
  2616. /** 
  2617. * Is the current page a group's Request Membership page? 
  2618. * 
  2619. * Eg http://example.com/groups/mygroup/request-membership/. 
  2620. * 
  2621. * @since 1.2.0 
  2622. * 
  2623. * @return bool True if the current page is a group's Request Membership page. 
  2624. */ 
  2625. function bp_is_group_membership_request() { 
  2626. return (bool) ( bp_is_groups_component() && bp_is_current_action( 'request-membership' ) ); 
  2627.  
  2628. /** 
  2629. * Is the current page a leave group attempt? 
  2630. * 
  2631. * @since 1.1.0 
  2632. * 
  2633. * @return bool True if the current page is a Leave Group attempt. 
  2634. */ 
  2635. function bp_is_group_leave() { 
  2636. return (bool) ( bp_is_groups_component() && bp_is_single_item() && bp_is_current_action( 'leave-group' ) ); 
  2637.  
  2638. /** 
  2639. * Is the current page part of a single group? 
  2640. * 
  2641. * Not currently used by BuddyPress. 
  2642. * 
  2643. * @todo How is this functionally different from bp_is_group()? 
  2644. * 
  2645. * @return bool True if the current page is part of a single group. 
  2646. */ 
  2647. function bp_is_group_single() { 
  2648. return (bool) ( bp_is_groups_component() && bp_is_single_item() ); 
  2649.  
  2650. /** 
  2651. * Is the current group page a custom front? 
  2652. * 
  2653. * @since 2.4.0 
  2654. * 
  2655. * @return bool True if the current group page is a custom front. 
  2656. */ 
  2657. function bp_is_group_custom_front() { 
  2658. $bp = buddypress(); 
  2659. return (bool) bp_is_group_home() && ! empty( $bp->groups->current_group->front_template ); 
  2660.  
  2661. /** 
  2662. * Is the current page the Create a Blog page? 
  2663. * 
  2664. * Eg http://example.com/sites/create/. 
  2665. * 
  2666. * @since 1.1.0 
  2667. * 
  2668. * @return bool True if the current page is the Create a Blog page. 
  2669. */ 
  2670. function bp_is_create_blog() { 
  2671. return (bool) ( bp_is_blogs_component() && bp_is_current_action( 'create' ) ); 
  2672.  
  2673. /** 
  2674. * Is the current page the blogs directory ? 
  2675. * 
  2676. * @since 2.0.0 
  2677. * 
  2678. * @return True if the current page is the blogs directory. 
  2679. */ 
  2680. function bp_is_blogs_directory() { 
  2681. if ( is_multisite() && bp_is_blogs_component() && ! bp_current_action() ) { 
  2682. return true; 
  2683.  
  2684. return false; 
  2685.  
  2686. /** Messages ******************************************************************/ 
  2687.  
  2688. /** 
  2689. * Is the current page part of a user's Messages pages? 
  2690. * 
  2691. * Eg http://example.com/members/joe/messages/ (or a subpage thereof). 
  2692. * 
  2693. * @since 1.2.0 
  2694. * 
  2695. * @return bool True if the current page is part of a user's Messages pages. 
  2696. */ 
  2697. function bp_is_user_messages() { 
  2698. return (bool) ( bp_is_user() && bp_is_messages_component() ); 
  2699.  
  2700. /** 
  2701. * Is the current page a user's Messages Inbox? 
  2702. * 
  2703. * Eg http://example.com/members/joe/messages/inbox/. 
  2704. * 
  2705. * @since 1.1.0 
  2706. * 
  2707. * @return bool True if the current page is a user's Messages Inbox. 
  2708. */ 
  2709. function bp_is_messages_inbox() { 
  2710. if ( bp_is_user_messages() && ( ! bp_current_action() || bp_is_current_action( 'inbox' ) ) ) { 
  2711. return true; 
  2712.  
  2713. return false; 
  2714.  
  2715. /** 
  2716. * Is the current page a user's Messages Sentbox? 
  2717. * 
  2718. * Eg http://example.com/members/joe/messages/sentbox/. 
  2719. * 
  2720. * @since 1.1.0 
  2721. * 
  2722. * @return bool True if the current page is a user's Messages Sentbox. 
  2723. */ 
  2724. function bp_is_messages_sentbox() { 
  2725. return (bool) ( bp_is_user_messages() && bp_is_current_action( 'sentbox' ) ); 
  2726.  
  2727. /** 
  2728. * Is the current page a user's Messages Compose screen?? 
  2729. * 
  2730. * Eg http://example.com/members/joe/messages/compose/. 
  2731. * 
  2732. * @since 1.1.0 
  2733. * 
  2734. * @return bool True if the current page is a user's Messages Compose screen. 
  2735. */ 
  2736. function bp_is_messages_compose_screen() { 
  2737. return (bool) ( bp_is_user_messages() && bp_is_current_action( 'compose' ) ); 
  2738.  
  2739. /** 
  2740. * Is the current page the Notices screen? 
  2741. * 
  2742. * Eg http://example.com/members/joe/messages/notices/. 
  2743. * 
  2744. * @since 1.1.0 
  2745. * 
  2746. * @return bool True if the current page is the Notices screen. 
  2747. */ 
  2748. function bp_is_notices() { 
  2749. return (bool) ( bp_is_user_messages() && bp_is_current_action( 'notices' ) ); 
  2750.  
  2751. /** 
  2752. * Is the current page a single Messages conversation thread? 
  2753. * 
  2754. * @since 1.6.0 
  2755. * 
  2756. * @return bool True if the current page a single Messages conversation thread? 
  2757. */ 
  2758. function bp_is_messages_conversation() { 
  2759. return (bool) ( bp_is_user_messages() && ( bp_is_current_action( 'view' ) ) ); 
  2760.  
  2761. /** 
  2762. * Not currently used by BuddyPress. 
  2763. * 
  2764. * @param string $component Current component to check for. 
  2765. * @param string $callback Callback to invoke. 
  2766. * @return bool 
  2767. */ 
  2768. function bp_is_single( $component, $callback ) { 
  2769. return (bool) ( bp_is_current_component( $component ) && ( true === call_user_func( $callback ) ) ); 
  2770.  
  2771. /** Registration **************************************************************/ 
  2772.  
  2773. /** 
  2774. * Is the current page the Activate page? 
  2775. * 
  2776. * Eg http://example.com/activate/. 
  2777. * 
  2778. * @since 1.1.0 
  2779. * 
  2780. * @return bool True if the current page is the Activate page. 
  2781. */ 
  2782. function bp_is_activation_page() { 
  2783. return (bool) bp_is_current_component( 'activate' ); 
  2784.  
  2785. /** 
  2786. * Is the current page the Register page? 
  2787. * 
  2788. * Eg http://example.com/register/. 
  2789. * 
  2790. * @since 1.1.0 
  2791. * 
  2792. * @return bool True if the current page is the Register page. 
  2793. */ 
  2794. function bp_is_register_page() { 
  2795. return (bool) bp_is_current_component( 'register' ); 
  2796.  
  2797. /** 
  2798. * Get the title parts of the BuddyPress displayed page 
  2799. * 
  2800. * @since 2.4.3 
  2801. * 
  2802. * @param string $seplocation Location for the separator. 
  2803. * @return array the title parts 
  2804. */ 
  2805. function bp_get_title_parts( $seplocation = 'right' ) { 
  2806. $bp = buddypress(); 
  2807.  
  2808. // Defaults to an empty array. 
  2809. $bp_title_parts = array(); 
  2810.  
  2811. // If this is not a BP page, return the empty array. 
  2812. if ( bp_is_blog_page() ) { 
  2813. return $bp_title_parts; 
  2814.  
  2815. // If this is a 404, return the empty array. 
  2816. if ( is_404() ) { 
  2817. return $bp_title_parts; 
  2818.  
  2819. // If this is the front page of the site, return the empty array. 
  2820. if ( is_front_page() || is_home() ) { 
  2821. return $bp_title_parts; 
  2822.  
  2823. // Return the empty array if not a BuddyPress page. 
  2824. if ( ! is_buddypress() ) { 
  2825. return $bp_title_parts; 
  2826.  
  2827. // Now we can build the BP Title Parts 
  2828. // Is there a displayed user, and do they have a name? 
  2829. $displayed_user_name = bp_get_displayed_user_fullname(); 
  2830.  
  2831. // Displayed user. 
  2832. if ( ! empty( $displayed_user_name ) && ! is_404() ) { 
  2833.  
  2834. // Get the component's ID to try and get its name. 
  2835. $component_id = $component_name = bp_current_component(); 
  2836.  
  2837. // Set empty subnav name. 
  2838. $component_subnav_name = ''; 
  2839.  
  2840. if ( ! empty( $bp->members->nav ) ) { 
  2841. $primary_nav_item = $bp->members->nav->get_primary( array( 'slug' => $component_id ), false ); 
  2842. $primary_nav_item = reset( $primary_nav_item ); 
  2843.  
  2844. // Use the component nav name. 
  2845. if ( ! empty( $primary_nav_item->name ) ) { 
  2846. $component_name = _bp_strip_spans_from_title( $primary_nav_item->name ); 
  2847.  
  2848. // Fall back on the component ID. 
  2849. } elseif ( ! empty( $bp->{$component_id}->id ) ) { 
  2850. $component_name = ucwords( $bp->{$component_id}->id ); 
  2851.  
  2852. if ( ! empty( $bp->members->nav ) ) { 
  2853. $secondary_nav_item = $bp->members->nav->get_secondary( array( 
  2854. 'parent_slug' => $component_id,  
  2855. 'slug' => bp_current_action() 
  2856. ), false ); 
  2857.  
  2858. if ( $secondary_nav_item ) { 
  2859. $secondary_nav_item = reset( $secondary_nav_item ); 
  2860.  
  2861. // Append action name if we're on a member component sub-page. 
  2862. if ( ! empty( $secondary_nav_item->name ) && ! empty( $bp->canonical_stack['action'] ) ) { 
  2863. $component_subnav_name = $secondary_nav_item->name; 
  2864.  
  2865. // If on the user profile's landing page, just use the fullname. 
  2866. if ( bp_is_current_component( $bp->default_component ) && ( bp_get_requested_url() === bp_displayed_user_domain() ) ) { 
  2867. $bp_title_parts[] = $displayed_user_name; 
  2868.  
  2869. // Use component name on member pages. 
  2870. } else { 
  2871. $bp_title_parts = array_merge( $bp_title_parts, array_map( 'strip_tags', array( 
  2872. $displayed_user_name,  
  2873. $component_name,  
  2874. ) ) ); 
  2875.  
  2876. // If we have a subnav name, add it separately for localization. 
  2877. if ( ! empty( $component_subnav_name ) ) { 
  2878. $bp_title_parts[] = strip_tags( $component_subnav_name ); 
  2879.  
  2880. // A single item from a component other than Members. 
  2881. } elseif ( bp_is_single_item() ) { 
  2882. $component_id = bp_current_component(); 
  2883.  
  2884. if ( ! empty( $bp->{$component_id}->nav ) ) { 
  2885. $secondary_nav_item = $bp->{$component_id}->nav->get_secondary( array( 
  2886. 'parent_slug' => bp_current_item(),  
  2887. 'slug' => bp_current_action() 
  2888. ), false ); 
  2889.  
  2890. if ( $secondary_nav_item ) { 
  2891. $secondary_nav_item = reset( $secondary_nav_item ); 
  2892.  
  2893. $single_item_subnav = ''; 
  2894.  
  2895. if ( ! empty( $secondary_nav_item->name ) ) { 
  2896. $single_item_subnav = $secondary_nav_item->name; 
  2897.  
  2898. $bp_title_parts = array( $bp->bp_options_title, $single_item_subnav ); 
  2899.  
  2900. // An index or directory. 
  2901. } elseif ( bp_is_directory() ) { 
  2902. $current_component = bp_current_component(); 
  2903.  
  2904. // No current component (when does this happen?). 
  2905. $bp_title_parts = array( _x( 'Directory', 'component directory title', 'buddypress' ) ); 
  2906.  
  2907. if ( ! empty( $current_component ) ) { 
  2908. $bp_title_parts = array( bp_get_directory_title( $current_component ) ); 
  2909.  
  2910. // Sign up page. 
  2911. } elseif ( bp_is_register_page() ) { 
  2912. $bp_title_parts = array( __( 'Create an Account', 'buddypress' ) ); 
  2913.  
  2914. // Activation page. 
  2915. } elseif ( bp_is_activation_page() ) { 
  2916. $bp_title_parts = array( __( 'Activate Your Account', 'buddypress' ) ); 
  2917.  
  2918. // Group creation page. 
  2919. } elseif ( bp_is_group_create() ) { 
  2920. $bp_title_parts = array( __( 'Create a Group', 'buddypress' ) ); 
  2921.  
  2922. // Blog creation page. 
  2923. } elseif ( bp_is_create_blog() ) { 
  2924. $bp_title_parts = array( __( 'Create a Site', 'buddypress' ) ); 
  2925.  
  2926. // Strip spans. 
  2927. $bp_title_parts = array_map( '_bp_strip_spans_from_title', $bp_title_parts ); 
  2928.  
  2929. // Sep on right, so reverse the order. 
  2930. if ( 'right' === $seplocation ) { 
  2931. $bp_title_parts = array_reverse( $bp_title_parts ); 
  2932.  
  2933. /** 
  2934. * Filter BuddyPress title parts before joining. 
  2935. * 
  2936. * @since 2.4.3 
  2937. * 
  2938. * @param array $bp_title_parts Current BuddyPress title parts. 
  2939. * @return array 
  2940. */ 
  2941. return (array) apply_filters( 'bp_get_title_parts', $bp_title_parts ); 
  2942.  
  2943. /** 
  2944. * Customize the body class, according to the currently displayed BP content. 
  2945. * 
  2946. * @since 1.1.0 
  2947. */ 
  2948. function bp_the_body_class() { 
  2949. echo bp_get_the_body_class(); 
  2950. /** 
  2951. * Customize the body class, according to the currently displayed BP content. 
  2952. * 
  2953. * Uses the above is_() functions to output a body class for each scenario. 
  2954. * 
  2955. * @since 1.1.0 
  2956. * 
  2957. * @param array $wp_classes The body classes coming from WP. 
  2958. * @param array|bool $custom_classes Classes that were passed to get_body_class(). 
  2959. * @return array $classes The BP-adjusted body classes. 
  2960. */ 
  2961. function bp_get_the_body_class( $wp_classes = array(), $custom_classes = false ) { 
  2962.  
  2963. $bp_classes = array(); 
  2964.  
  2965. /** Pages *************************************************************/ 
  2966.  
  2967. if ( is_front_page() ) { 
  2968. $bp_classes[] = 'home-page'; 
  2969.  
  2970. if ( bp_is_directory() ) { 
  2971. $bp_classes[] = 'directory'; 
  2972.  
  2973. if ( bp_is_single_item() ) { 
  2974. $bp_classes[] = 'single-item'; 
  2975.  
  2976. /** Components ********************************************************/ 
  2977.  
  2978. if ( ! bp_is_blog_page() ) { 
  2979. if ( bp_is_user_profile() ) { 
  2980. $bp_classes[] = 'xprofile'; 
  2981.  
  2982. if ( bp_is_activity_component() ) { 
  2983. $bp_classes[] = 'activity'; 
  2984.  
  2985. if ( bp_is_blogs_component() ) { 
  2986. $bp_classes[] = 'blogs'; 
  2987.  
  2988. if ( bp_is_messages_component() ) { 
  2989. $bp_classes[] = 'messages'; 
  2990.  
  2991. if ( bp_is_friends_component() ) { 
  2992. $bp_classes[] = 'friends'; 
  2993.  
  2994. if ( bp_is_groups_component() ) { 
  2995. $bp_classes[] = 'groups'; 
  2996.  
  2997. if ( bp_is_settings_component() ) { 
  2998. $bp_classes[] = 'settings'; 
  2999.  
  3000. /** User **************************************************************/ 
  3001.  
  3002. if ( bp_is_user() ) { 
  3003. $bp_classes[] = 'bp-user'; 
  3004.  
  3005. // Add current user member types. 
  3006. if ( $member_types = bp_get_member_type( bp_displayed_user_id(), false ) ) { 
  3007. foreach( $member_types as $member_type ) { 
  3008. $bp_classes[] = sprintf( 'member-type-%s', esc_attr( $member_type ) ); 
  3009.  
  3010. if ( ! bp_is_directory() ) { 
  3011. if ( bp_is_user_blogs() ) { 
  3012. $bp_classes[] = 'my-blogs'; 
  3013.  
  3014. if ( bp_is_user_groups() ) { 
  3015. $bp_classes[] = 'my-groups'; 
  3016.  
  3017. if ( bp_is_user_activity() ) { 
  3018. $bp_classes[] = 'my-activity'; 
  3019. } else { 
  3020. if ( bp_get_current_member_type() ) { 
  3021. $bp_classes[] = 'type'; 
  3022.  
  3023. if ( bp_is_my_profile() ) { 
  3024. $bp_classes[] = 'my-account'; 
  3025.  
  3026. if ( bp_is_user_profile() ) { 
  3027. $bp_classes[] = 'my-profile'; 
  3028.  
  3029. if ( bp_is_user_friends() ) { 
  3030. $bp_classes[] = 'my-friends'; 
  3031.  
  3032. if ( bp_is_user_messages() ) { 
  3033. $bp_classes[] = 'my-messages'; 
  3034.  
  3035. if ( bp_is_user_recent_commments() ) { 
  3036. $bp_classes[] = 'recent-comments'; 
  3037.  
  3038. if ( bp_is_user_recent_posts() ) { 
  3039. $bp_classes[] = 'recent-posts'; 
  3040.  
  3041. if ( bp_is_user_change_avatar() ) { 
  3042. $bp_classes[] = 'change-avatar'; 
  3043.  
  3044. if ( bp_is_user_profile_edit() ) { 
  3045. $bp_classes[] = 'profile-edit'; 
  3046.  
  3047. if ( bp_is_user_friends_activity() ) { 
  3048. $bp_classes[] = 'friends-activity'; 
  3049.  
  3050. if ( bp_is_user_groups_activity() ) { 
  3051. $bp_classes[] = 'groups-activity'; 
  3052.  
  3053. /** Messages **********************************************************/ 
  3054.  
  3055. if ( bp_is_messages_inbox() ) { 
  3056. $bp_classes[] = 'inbox'; 
  3057.  
  3058. if ( bp_is_messages_sentbox() ) { 
  3059. $bp_classes[] = 'sentbox'; 
  3060.  
  3061. if ( bp_is_messages_compose_screen() ) { 
  3062. $bp_classes[] = 'compose'; 
  3063.  
  3064. if ( bp_is_notices() ) { 
  3065. $bp_classes[] = 'notices'; 
  3066.  
  3067. if ( bp_is_user_friend_requests() ) { 
  3068. $bp_classes[] = 'friend-requests'; 
  3069.  
  3070. if ( bp_is_create_blog() ) { 
  3071. $bp_classes[] = 'create-blog'; 
  3072.  
  3073. /** Groups ************************************************************/ 
  3074.  
  3075. if ( bp_is_group() ) { 
  3076. $bp_classes[] = 'group-' . groups_get_current_group()->slug; 
  3077.  
  3078. // Add current group types. 
  3079. if ( $group_types = bp_groups_get_group_type( bp_get_current_group_id(), false ) ) { 
  3080. foreach ( $group_types as $group_type ) { 
  3081. $bp_classes[] = sprintf( 'group-type-%s', esc_attr( $group_type ) ); 
  3082.  
  3083. if ( bp_is_group_leave() ) { 
  3084. $bp_classes[] = 'leave-group'; 
  3085.  
  3086. if ( bp_is_group_invites() ) { 
  3087. $bp_classes[] = 'group-invites'; 
  3088.  
  3089. if ( bp_is_group_members() ) { 
  3090. $bp_classes[] = 'group-members'; 
  3091.  
  3092. if ( bp_is_group_forum_topic() ) { 
  3093. $bp_classes[] = 'group-forum-topic'; 
  3094.  
  3095. if ( bp_is_group_forum_topic_edit() ) { 
  3096. $bp_classes[] = 'group-forum-topic-edit'; 
  3097.  
  3098. if ( bp_is_group_forum() ) { 
  3099. $bp_classes[] = 'group-forum'; 
  3100.  
  3101. if ( bp_is_group_admin_page() ) { 
  3102. $bp_classes[] = 'group-admin'; 
  3103. $bp_classes[] = bp_get_group_current_admin_tab(); 
  3104.  
  3105. if ( bp_is_group_create() ) { 
  3106. $bp_classes[] = 'group-create'; 
  3107. $bp_classes[] = bp_get_groups_current_create_step(); 
  3108.  
  3109. if ( bp_is_group_home() ) { 
  3110. $bp_classes[] = 'group-home'; 
  3111.  
  3112. if ( bp_is_single_activity() ) { 
  3113. $bp_classes[] = 'activity-permalink'; 
  3114.  
  3115. /** Registration ******************************************************/ 
  3116.  
  3117. if ( bp_is_register_page() ) { 
  3118. $bp_classes[] = 'registration'; 
  3119.  
  3120. if ( bp_is_activation_page() ) { 
  3121. $bp_classes[] = 'activation'; 
  3122.  
  3123. /** Current Component & Action ****************************************/ 
  3124.  
  3125. if ( ! bp_is_blog_page() ) { 
  3126. $bp_classes[] = bp_current_component(); 
  3127. $bp_classes[] = bp_current_action(); 
  3128.  
  3129. /** Clean up ***********************************************************/ 
  3130.  
  3131. // Add BuddyPress class if we are within a BuddyPress page. 
  3132. if ( ! bp_is_blog_page() ) { 
  3133. $bp_classes[] = 'buddypress'; 
  3134.  
  3135. // Merge WP classes with BuddyPress classes and remove any duplicates. 
  3136. $classes = array_unique( array_merge( (array) $bp_classes, (array) $wp_classes ) ); 
  3137.  
  3138. /** 
  3139. * Filters the BuddyPress classes to be added to body_class() 
  3140. * 
  3141. * @since 1.1.0 
  3142. * 
  3143. * @param array $classes Array of body classes to add. 
  3144. * @param array $bp_classes Array of BuddyPress-based classes. 
  3145. * @param array $wp_classes Array of WordPress-based classes. 
  3146. * @param array $custom_classes Array of classes that were passed to get_body_class(). 
  3147. */ 
  3148. return apply_filters( 'bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes ); 
  3149. add_filter( 'body_class', 'bp_get_the_body_class', 10, 2 ); 
  3150.  
  3151. /** 
  3152. * Customizes the post CSS class according to BuddyPress content. 
  3153. * 
  3154. * Hooked to the 'post_class' filter. 
  3155. * 
  3156. * @since 2.1.0 
  3157. * 
  3158. * @param array $wp_classes The post classes coming from WordPress. 
  3159. * @return array 
  3160. */ 
  3161. function bp_get_the_post_class( $wp_classes = array() ) { 
  3162. // Don't do anything if we're not on a BP page. 
  3163. if ( ! is_buddypress() ) { 
  3164. return $wp_classes; 
  3165.  
  3166. $bp_classes = array(); 
  3167.  
  3168. if ( bp_is_user() || bp_is_single_activity() ) { 
  3169. $bp_classes[] = 'bp_members'; 
  3170.  
  3171. } elseif ( bp_is_group() ) { 
  3172. $bp_classes[] = 'bp_group'; 
  3173.  
  3174. } elseif ( bp_is_activity_component() ) { 
  3175. $bp_classes[] = 'bp_activity'; 
  3176.  
  3177. } elseif ( bp_is_blogs_component() ) { 
  3178. $bp_classes[] = 'bp_blogs'; 
  3179.  
  3180. } elseif ( bp_is_register_page() ) { 
  3181. $bp_classes[] = 'bp_register'; 
  3182.  
  3183. } elseif ( bp_is_activation_page() ) { 
  3184. $bp_classes[] = 'bp_activate'; 
  3185.  
  3186. } elseif ( bp_is_forums_component() && bp_is_directory() ) { 
  3187. $bp_classes[] = 'bp_forum'; 
  3188.  
  3189. if ( empty( $bp_classes ) ) { 
  3190. return $wp_classes; 
  3191.  
  3192. // Emulate post type css class. 
  3193. foreach ( $bp_classes as $bp_class ) { 
  3194. $bp_classes[] = "type-{$bp_class}"; 
  3195.  
  3196. // Okay let's merge! 
  3197. return array_unique( array_merge( $bp_classes, $wp_classes ) ); 
  3198. add_filter( 'post_class', 'bp_get_the_post_class' ); 
  3199.  
  3200. /** 
  3201. * Sort BuddyPress nav menu items by their position property. 
  3202. * 
  3203. * This is an internal convenience function and it will probably be removed in 
  3204. * a later release. Do not use. 
  3205. * 
  3206. * @access private 
  3207. * @since 1.7.0 
  3208. * 
  3209. * @param array $a First item. 
  3210. * @param array $b Second item. 
  3211. * @return int Returns an integer less than, equal to, or greater than zero if 
  3212. * the first argument is considered to be respectively less than,  
  3213. * equal to, or greater than the second. 
  3214. */ 
  3215. function _bp_nav_menu_sort( $a, $b ) { 
  3216. if ( $a['position'] == $b['position'] ) { 
  3217. return 0; 
  3218. } elseif ( $a['position'] < $b['position'] ) { 
  3219. return -1; 
  3220. } else { 
  3221. return 1; 
  3222.  
  3223. /** 
  3224. * Get the items registered in the primary and secondary BuddyPress navigation menus. 
  3225. * 
  3226. * @since 1.7.0 
  3227. * @since 2.6.0 Introduced the `$component` parameter. 
  3228. * 
  3229. * @param string $component Optional. Component whose nav items are being fetched. 
  3230. * @return array A multidimensional array of all navigation items. 
  3231. */ 
  3232. function bp_get_nav_menu_items( $component = 'members' ) { 
  3233. $bp = buddypress(); 
  3234. $menus = array(); 
  3235.  
  3236. if ( ! isset( $bp->{$component}->nav ) ) { 
  3237. return $menus; 
  3238.  
  3239. // Get the item nav and build the menus. 
  3240. foreach ( $bp->{$component}->nav->get_item_nav() as $nav_menu ) { 
  3241. // Get the correct menu link. See https://buddypress.trac.wordpress.org/ticket/4624. 
  3242. $link = bp_loggedin_user_domain() ? str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $nav_menu->link ) : trailingslashit( bp_displayed_user_domain() . $nav_menu->link ); 
  3243.  
  3244. // Add this menu. 
  3245. $menu = new stdClass; 
  3246. $menu->class = array( 'menu-parent' ); 
  3247. $menu->css_id = $nav_menu->css_id; 
  3248. $menu->link = $link; 
  3249. $menu->name = $nav_menu->name; 
  3250. $menu->parent = 0; 
  3251.  
  3252. if ( ! empty( $nav_menu->children ) ) { 
  3253. $submenus = array(); 
  3254.  
  3255. foreach( $nav_menu->children as $sub_menu ) { 
  3256. $submenu = new stdClass; 
  3257. $submenu->class = array( 'menu-child' ); 
  3258. $submenu->css_id = $sub_menu->css_id; 
  3259. $submenu->link = $sub_menu->link; 
  3260. $submenu->name = $sub_menu->name; 
  3261. $submenu->parent = $nav_menu->slug; 
  3262.  
  3263. // If we're viewing this item's screen, record that we need to mark its parent menu to be selected. 
  3264. if ( $sub_menu->slug == bp_current_action() ) { 
  3265. $menu->class[] = 'current-menu-parent'; 
  3266. $submenu->class[] = 'current-menu-item'; 
  3267.  
  3268. $submenus[] = $submenu; 
  3269.  
  3270. $menus[] = $menu; 
  3271.  
  3272. if ( ! empty( $submenus ) ) { 
  3273. $menus = array_merge( $menus, $submenus ); 
  3274.  
  3275. /** 
  3276. * Filters the items registered in the primary and secondary BuddyPress navigation menus. 
  3277. * 
  3278. * @since 1.7.0 
  3279. * 
  3280. * @param array $menus Array of items registered in the primary and secondary BuddyPress navigation. 
  3281. */ 
  3282. return apply_filters( 'bp_get_nav_menu_items', $menus ); 
  3283.  
  3284. /** 
  3285. * Display a navigation menu. 
  3286. * 
  3287. * @since 1.7.0 
  3288. * 
  3289. * @param string|array $args { 
  3290. * An array of optional arguments. 
  3291. * 
  3292. * @type string $after Text after the link text. Default: ''. 
  3293. * @type string $before Text before the link text. Default: ''. 
  3294. * @type string $container The name of the element to wrap the navigation 
  3295. * with. 'div' or 'nav'. Default: 'div'. 
  3296. * @type string $container_class The class that is applied to the container. 
  3297. * Default: 'menu-bp-container'. 
  3298. * @type string $container_id The ID that is applied to the container. 
  3299. * Default: ''. 
  3300. * @type int $depth How many levels of the hierarchy are to be included. 
  3301. * 0 means all. Default: 0. 
  3302. * @type bool $echo True to echo the menu, false to return it. 
  3303. * Default: true. 
  3304. * @type bool $fallback_cb If the menu doesn't exist, should a callback 
  3305. * function be fired? Default: false (no fallback). 
  3306. * @type string $items_wrap How the list items should be wrapped. Should be 
  3307. * in the form of a printf()-friendly string, using numbered 
  3308. * placeholders. Default: '<ul id="%1$s" class="%2$s">%3$s</ul>'. 
  3309. * @type string $link_after Text after the link. Default: ''. 
  3310. * @type string $link_before Text before the link. Default: ''. 
  3311. * @type string $menu_class CSS class to use for the <ul> element which 
  3312. * forms the menu. Default: 'menu'. 
  3313. * @type string $menu_id The ID that is applied to the <ul> element which 
  3314. * forms the menu. Default: 'menu-bp', incremented. 
  3315. * @type string $walker Allows a custom walker class to be specified. 
  3316. * Default: 'BP_Walker_Nav_Menu'. 
  3317. * } 
  3318. * @return string|null If $echo is false, returns a string containing the nav 
  3319. * menu markup. 
  3320. */ 
  3321. function bp_nav_menu( $args = array() ) { 
  3322. static $menu_id_slugs = array(); 
  3323.  
  3324. $defaults = array( 
  3325. 'after' => '',  
  3326. 'before' => '',  
  3327. 'container' => 'div',  
  3328. 'container_class' => '',  
  3329. 'container_id' => '',  
  3330. 'depth' => 0,  
  3331. 'echo' => true,  
  3332. 'fallback_cb' => false,  
  3333. 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',  
  3334. 'link_after' => '',  
  3335. 'link_before' => '',  
  3336. 'menu_class' => 'menu',  
  3337. 'menu_id' => '',  
  3338. 'walker' => '',  
  3339. ); 
  3340. $args = wp_parse_args( $args, $defaults ); 
  3341.  
  3342. /** 
  3343. * Filters the parsed bp_nav_menu arguments. 
  3344. * 
  3345. * @since 1.7.0 
  3346. * 
  3347. * @param array $args Array of parsed arguments. 
  3348. */ 
  3349. $args = apply_filters( 'bp_nav_menu_args', $args ); 
  3350. $args = (object) $args; 
  3351.  
  3352. $items = $nav_menu = ''; 
  3353. $show_container = false; 
  3354.  
  3355. // Create custom walker if one wasn't set. 
  3356. if ( empty( $args->walker ) ) { 
  3357. $args->walker = new BP_Walker_Nav_Menu; 
  3358.  
  3359. // Sanitise values for class and ID. 
  3360. $args->container_class = sanitize_html_class( $args->container_class ); 
  3361. $args->container_id = sanitize_html_class( $args->container_id ); 
  3362.  
  3363. // Whether to wrap the ul, and what to wrap it with. 
  3364. if ( $args->container ) { 
  3365.  
  3366. /** 
  3367. * Filters the allowed tags for the wp_nav_menu_container. 
  3368. * 
  3369. * @since 1.7.0 
  3370. * 
  3371. * @param array $value Array of allowed tags. Default 'div' and 'nav'. 
  3372. */ 
  3373. $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav', ) ); 
  3374.  
  3375. if ( in_array( $args->container, $allowed_tags ) ) { 
  3376. $show_container = true; 
  3377.  
  3378. $class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-bp-container"'; 
  3379. $id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : ''; 
  3380. $nav_menu .= '<' . $args->container . $id . $class . '>'; 
  3381.  
  3382. /** 
  3383. * Filters the BuddyPress menu objects. 
  3384. * 
  3385. * @since 1.7.0 
  3386. * 
  3387. * @param array $value Array of nav menu objects. 
  3388. * @param array $args Array of arguments for the menu. 
  3389. */ 
  3390. $menu_items = apply_filters( 'bp_nav_menu_objects', bp_get_nav_menu_items(), $args ); 
  3391. $items = walk_nav_menu_tree( $menu_items, $args->depth, $args ); 
  3392. unset( $menu_items ); 
  3393.  
  3394. // Set the ID that is applied to the ul element which forms the menu. 
  3395. if ( ! empty( $args->menu_id ) ) { 
  3396. $wrap_id = $args->menu_id; 
  3397.  
  3398. } else { 
  3399. $wrap_id = 'menu-bp'; 
  3400.  
  3401. // If a specific ID wasn't requested, and there are multiple menus on the same screen, make sure the autogenerated ID is unique. 
  3402. while ( in_array( $wrap_id, $menu_id_slugs ) ) { 
  3403. if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) ) { 
  3404. $wrap_id = preg_replace('#-(\d+)$#', '-' . ++$matches[1], $wrap_id ); 
  3405. } else { 
  3406. $wrap_id = $wrap_id . '-1'; 
  3407. $menu_id_slugs[] = $wrap_id; 
  3408.  
  3409. /** 
  3410. * Filters the BuddyPress menu items. 
  3411. * 
  3412. * Allow plugins to hook into the menu to add their own <li>'s 
  3413. * 
  3414. * @since 1.7.0 
  3415. * 
  3416. * @param array $items Array of nav menu items. 
  3417. * @param array $args Array of arguments for the menu. 
  3418. */ 
  3419. $items = apply_filters( 'bp_nav_menu_items', $items, $args ); 
  3420.  
  3421. // Build the output. 
  3422. $wrap_class = $args->menu_class ? $args->menu_class : ''; 
  3423. $nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items ); 
  3424. unset( $items ); 
  3425.  
  3426. // If we've wrapped the ul, close it. 
  3427. if ( ! empty( $show_container ) ) { 
  3428. $nav_menu .= '</' . $args->container . '>'; 
  3429.  
  3430. /** 
  3431. * Filters the final BuddyPress menu output. 
  3432. * 
  3433. * @since 1.7.0 
  3434. * 
  3435. * @param string $nav_menu Final nav menu output. 
  3436. * @param array $args Array of arguments for the menu. 
  3437. */ 
  3438. $nav_menu = apply_filters( 'bp_nav_menu', $nav_menu, $args ); 
  3439.  
  3440. if ( ! empty( $args->echo ) ) { 
  3441. echo $nav_menu; 
  3442. } else { 
  3443. return $nav_menu; 
  3444.  
  3445. /** 
  3446. * Prints the Recipient Salutation. 
  3447. * 
  3448. * @since 2.5.0 
  3449. * 
  3450. * @param array $settings Email Settings. 
  3451. */ 
  3452. function bp_email_the_salutation( $settings = array() ) { 
  3453. echo bp_email_get_salutation( $settings ); 
  3454.  
  3455. /** 
  3456. * Gets the Recipient Salutation. 
  3457. * 
  3458. * @since 2.5.0 
  3459. * 
  3460. * @param array $settings Email Settings. 
  3461. * @return string The Recipient Salutation. 
  3462. */ 
  3463. function bp_email_get_salutation( $settings = array() ) { 
  3464. $token = '{{recipient.name}}'; 
  3465.  
  3466. /** 
  3467. * Filters The Recipient Salutation inside the Email Template. 
  3468. * 
  3469. * @since 2.5.0 
  3470. * 
  3471. * @param string $value The Recipient Salutation. 
  3472. * @param array $settings Email Settings. 
  3473. * @param string $token The Recipient token. 
  3474. */ 
  3475. return apply_filters( 'bp_email_get_salutation', sprintf( _x( 'Hi %s, ', 'recipient salutation', 'buddypress' ), $token ), $settings, $token ); 
.