Changeset 10356 for trunk/src/bp-core/bp-core-template.php
- Timestamp:
- 11/15/2015 07:57:03 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-template.php
r10209 r10356 27 27 * viewed user. 28 28 * 29 * @param string $parent_slug 30 * 29 * @param string $parent_slug Options nav slug. 31 30 * @return string 32 31 */ … … 35 34 36 35 // If we are looking at a member profile, then the we can use the current 37 // component as an index. Otherwise we need to use the component's root_slug 36 // component as an index. Otherwise we need to use the component's root_slug. 38 37 $component_index = !empty( $bp->displayed_user ) ? bp_current_component() : bp_get_root_slug( bp_current_component() ); 39 38 $selected_item = bp_current_action(); … … 60 59 } 61 60 62 // Loop through each navigation item 61 // Loop through each navigation item. 63 62 foreach ( (array) $bp->bp_options_nav[$the_index] as $subnav_item ) { 64 63 if ( empty( $subnav_item['user_has_access'] ) ) { … … 73 72 } 74 73 75 // List type depends on our current component 74 // List type depends on our current component. 76 75 $list_type = bp_is_group() ? 'groups' : 'personal'; 77 76 … … 95 94 * 96 95 * Not currently used in BuddyPress. 96 * 97 97 * @todo Deprecate. 98 98 */ … … 115 115 * @since 2.0.0 116 116 * 117 * @param string $component 118 * 117 * @param string $component Component to get directory title for. 119 118 * @return string 120 119 */ … … 122 121 $title = ''; 123 122 124 // Use the string provided by the component 123 // Use the string provided by the component. 125 124 if ( ! empty( buddypress()->{$component}->directory_title ) ) { 126 125 $title = buddypress()->{$component}->directory_title; 127 126 128 // If none is found, concatenate 127 // If none is found, concatenate. 129 128 } elseif ( isset( buddypress()->{$component}->name ) ) { 130 129 $title = sprintf( __( '%s Directory', 'buddypress' ), buddypress()->{$component}->name ); … … 341 340 * @since 1.1.0 342 341 * 343 * @param int|string 344 * @param bool 345 * 346 * @param bool 342 * @param int|string $time The UNIX timestamp to be formatted. 343 * @param bool $exclude_time Optional. True to return only the month + day, false 344 * to return month, day, and time. Default: false. 345 * @param bool $gmt Optional. True to display in local time, false to 347 346 * leave in GMT. Default: true. 348 *349 347 * @return mixed A string representation of $time, in the format 350 348 * "March 18, 2014 at 2:00 pm" (or whatever your … … 355 353 356 354 // Bail if time is empty or not numeric 357 // @todo We should output something smarter here 355 // @todo We should output something smarter here. 358 356 if ( empty( $time ) || ! is_numeric( $time ) ) { 359 357 return false; 360 358 } 361 359 362 // Get GMT offset from root blog 360 // Get GMT offset from root blog. 363 361 if ( true === $gmt ) { 364 362 365 // Use Timezone string if set 363 // Use Timezone string if set. 366 364 $timezone_string = bp_get_option( 'timezone_string' ); 367 365 if ( ! empty( $timezone_string ) ) { … … 370 368 $timezone_offset = timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS; 371 369 372 // Fall back on less reliable gmt_offset 370 // Fall back on less reliable gmt_offset. 373 371 } else { 374 372 $timezone_offset = bp_get_option( 'gmt_offset' ); 375 373 } 376 374 377 // Calculate time based on the offset 375 // Calculate time based on the offset. 378 376 $calculated_time = $time + ( $timezone_offset * HOUR_IN_SECONDS ); 379 377 380 // No localizing, so just use the time that was submitted 378 // No localizing, so just use the time that was submitted. 381 379 } else { 382 380 $calculated_time = $time; 383 381 } 384 382 385 // Formatted date: "March 18, 2014" 383 // Formatted date: "March 18, 2014". 386 384 $formatted_date = date_i18n( bp_get_option( 'date_format' ), $calculated_time, $gmt ); 387 385 … … 389 387 if ( true !== $exclude_time ) { 390 388 391 // Formatted time: "2:00 pm" 389 // Formatted time: "2:00 pm". 392 390 $formatted_time = date_i18n( bp_get_option( 'time_format' ), $calculated_time, $gmt ); 393 391 394 // Return string formatted with date and time 392 // Return string formatted with date and time. 395 393 $formatted_date = sprintf( esc_html__( '%1$s at %2$s', 'buddypress' ), $formatted_date, $formatted_time ); 396 394 } … … 415 413 * do the necessary argument swapping for dynamic phrases. 416 414 * 417 * @param string $youtext The "you" version of the phrase (eg "Your Friends"). 418 * @param string $nametext The other-user version of the phrase. Should be in 419 * a format appropriate for sprintf() - use %s in place of the displayed 420 * user's name (eg "%'s Friends"). 421 * @param bool $capitalize Optional. Force into title case. Default: true. 422 * @param bool $echo Optional. True to echo the results, false to return them. 423 * Default: true. 424 * 415 * @param string $youtext The "you" version of the phrase (eg "Your Friends"). 416 * @param string $nametext The other-user version of the phrase. Should be in 417 * a format appropriate for sprintf() - use %s in place of the displayed 418 * user's name (eg "%'s Friends"). 419 * @param bool $capitalize Optional. Force into title case. Default: true. 420 * @param bool $echo Optional. True to echo the results, false to return them. 421 * Default: true. 425 422 * @return string|null $nametext If ! $echo, returns the appropriate string. 426 423 */ … … 569 566 * 570 567 * @param string $component Component name. Default: current component. 571 *572 568 * @return string Placeholder text for search field. 573 569 */ … … 582 578 $default_text = __( 'Search anything...', 'buddypress' ); 583 579 584 // Most of the time, $component will be the actual component ID 580 // Most of the time, $component will be the actual component ID. 585 581 if ( !empty( $component ) ) { 586 582 if ( !empty( $bp->{$component}->search_string ) ) { … … 588 584 } else { 589 585 // When the request comes through AJAX, we need to get the component 590 // name out of $bp->pages 586 // name out of $bp->pages. 591 587 if ( !empty( $bp->pages->{$component}->slug ) ) { 592 588 $key = $bp->pages->{$component}->slug; … … 757 753 * @param int $length Optional. Length of returned string, including ellipsis. 758 754 * Default: 225. 759 * @param array $options {755 * @param array $options { 760 756 * An array of HTML attributes and options. Each item is optional. 761 757 * @type string $ending The string used after truncation. … … 772 768 function bp_create_excerpt( $text, $length = 225, $options = array() ) { 773 769 774 // Backward compatibility. The third argument used to be a boolean $filter_shortcodes 770 // Backward compatibility. The third argument used to be a boolean $filter_shortcodes. 775 771 $filter_shortcodes_default = is_bool( $options ) ? $options : true; 776 772 … … 782 778 ), 'create_excerpt' ); 783 779 784 // Save the original text, to be passed along to the filter 780 // Save the original text, to be passed along to the filter. 785 781 $original_text = $text; 786 782 … … 803 799 $ending = apply_filters( 'bp_excerpt_append_text', $r['ending'] ); 804 800 805 // Remove shortcodes if necessary 801 // Remove shortcodes if necessary. 806 802 if ( ! empty( $r['filter_shortcodes'] ) ) { 807 803 $text = strip_shortcodes( $text ); … … 809 805 810 806 // When $html is true, the excerpt should be created without including HTML tags in the 811 // excerpt length 807 // excerpt length. 812 808 if ( ! empty( $r['html'] ) ) { 813 809 814 // The text is short enough. No need to truncate 810 // The text is short enough. No need to truncate. 815 811 if ( mb_strlen( preg_replace( '/<.*?>/', '', $text ) ) <= $length ) { 816 812 return $text; … … 821 817 $truncate = ''; 822 818 823 // Find all the tags and HTML comments and put them in a stack for later use 819 // Find all the tags and HTML comments and put them in a stack for later use. 824 820 preg_match_all( '/(<\/?([\w+!]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER ); 825 821 826 822 foreach ( $tags as $tag ) { 827 // Process tags that need to be closed 823 // Process tags that need to be closed. 828 824 if ( !preg_match( '/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2] ) ) { 829 825 if ( preg_match( '/<[\w]+[^>]*>/s', $tag[0] ) ) { … … 872 868 } 873 869 874 // If $exact is false, we can't break on words 870 // If $exact is false, we can't break on words. 875 871 if ( empty( $r['exact'] ) ) { 876 872 // Find the position of the last space character not part of a tag. … … 1116 1112 * WordPress theme without coping the functions from functions.php. 1117 1113 * 1118 * @param string|bool $object 1119 * 1114 * @param string|bool $object Current template component. 1120 1115 * @return string The AJAX querystring. 1121 1116 */ … … 1233 1228 * 1234 1229 * @param int $position The key of the action_variables array that you want. 1235 *1236 1230 * @return string|bool $action_variable The value of that position in the 1237 1231 * array, or false if not found. … … 1323 1317 * 1324 1318 * @param string $component Optional. Defaults to the current component. 1325 *1326 1319 * @return string $root_slug The root slug. 1327 1320 */ … … 1330 1323 $root_slug = ''; 1331 1324 1332 // Use current global component if none passed 1325 // Use current global component if none passed. 1333 1326 if ( empty( $component ) ) { 1334 1327 $component = bp_current_component(); 1335 1328 } 1336 1329 1337 // Component is active 1330 // Component is active. 1338 1331 if ( ! empty( $bp->active_components[ $component ] ) ) { 1339 1332 1340 1333 // Backward compatibility: in legacy plugins, the canonical component id 1341 // was stored as an array value in $bp->active_components 1334 // was stored as an array value in $bp->active_components. 1342 1335 $component_name = ( '1' == $bp->active_components[ $component ] ) 1343 1336 ? $component 1344 1337 : $bp->active_components[$component]; 1345 1338 1346 // Component has specific root slug 1339 // Component has specific root slug. 1347 1340 if ( ! empty( $bp->{$component_name}->root_slug ) ) { 1348 1341 $root_slug = $bp->{$component_name}->root_slug; … … 1350 1343 } 1351 1344 1352 // No specific root slug, so fall back to component slug 1345 // No specific root slug, so fall back to component slug. 1353 1346 if ( empty( $root_slug ) ) { 1354 1347 $root_slug = $component; … … 1372 1365 * 1373 1366 * @param string $root_slug Needle to our active component haystack. 1374 *1375 1367 * @return mixed False if none found, component name if found. 1376 1368 */ … … 1378 1370 $bp = buddypress(); 1379 1371 1380 // If no slug is passed, look at current_component 1372 // If no slug is passed, look at current_component. 1381 1373 if ( empty( $root_slug ) ) { 1382 1374 $root_slug = bp_current_component(); 1383 1375 } 1384 1376 1385 // No current component or root slug, so flee 1377 // No current component or root slug, so flee. 1386 1378 if ( empty( $root_slug ) ) { 1387 1379 return false; 1388 1380 } 1389 1381 1390 // Loop through active components and look for a match 1382 // Loop through active components and look for a match. 1391 1383 foreach ( array_keys( $bp->active_components ) as $component ) { 1392 1384 if ( ( ! empty( $bp->{$component}->slug ) && ( $bp->{$component}->slug == $root_slug ) ) || ( ! empty( $bp->{$component}->root_slug ) && ( $bp->{$component}->root_slug === $root_slug ) ) ) { … … 1486 1478 } 1487 1479 1488 /** is_() functions to determine the current page *****************************/1480 /** The is_() functions to determine the current page *****************************/ 1489 1481 1490 1482 /** … … 1500 1492 * 1501 1493 * @param string $component Name of the component being checked. 1502 *1503 1494 * @return bool Returns true if the component matches, or else false. 1504 1495 */ 1505 1496 function bp_is_current_component( $component = '' ) { 1506 1497 1507 // Default is no match. We'll check a few places for matches 1498 // Default is no match. We'll check a few places for matches. 1508 1499 $is_current_component = false; 1509 1500 1510 // Always return false if a null value is passed to the function 1501 // Always return false if a null value is passed to the function. 1511 1502 if ( empty( $component ) ) { 1512 1503 return false; 1513 1504 } 1514 1505 1515 // Backward compatibility: 'xprofile' should be read as 'profile' 1506 // Backward compatibility: 'xprofile' should be read as 'profile'. 1516 1507 if ( 'xprofile' === $component ) { 1517 1508 $component = 'profile'; … … 1520 1511 $bp = buddypress(); 1521 1512 1522 // Only check if BuddyPress found a current_component 1513 // Only check if BuddyPress found a current_component. 1523 1514 if ( ! empty( $bp->current_component ) ) { 1524 1515 1525 1516 // First, check to see whether $component_name and the current 1526 // component are a simple match 1517 // component are a simple match. 1527 1518 if ( $bp->current_component == $component ) { 1528 1519 $is_current_component = true; 1529 1520 1530 1521 // Since the current component is based on the visible URL slug let's 1531 // check the component being passed and see if its root_slug matches 1522 // check the component being passed and see if its root_slug matches. 1532 1523 } elseif ( isset( $bp->{$component}->root_slug ) && $bp->{$component}->root_slug == $bp->current_component ) { 1533 1524 $is_current_component = true; 1534 1525 1535 // Because slugs can differ from root_slugs, we should check them too 1526 // Because slugs can differ from root_slugs, we should check them too. 1536 1527 } elseif ( isset( $bp->{$component}->slug ) && $bp->{$component}->slug == $bp->current_component ) { 1537 1528 $is_current_component = true; … … 1546 1537 1547 1538 // If we haven't found a match yet, check against the root_slugs 1548 // created by $bp->pages, as well as the regular slugs 1539 // created by $bp->pages, as well as the regular slugs. 1549 1540 } else { 1550 1541 foreach ( $bp->active_components as $id ) { 1551 1542 // If the $component parameter does not match the current_component, 1552 // then move along, these are not the droids you are looking for 1543 // then move along, these are not the droids you are looking for. 1553 1544 if ( empty( $bp->{$id}->root_slug ) || $bp->{$id}->root_slug != $bp->current_component ) { 1554 1545 continue; … … 1589 1580 * 1590 1581 * @param string $action The action being tested against. 1591 *1592 1582 * @return bool True if the current action matches $action. 1593 1583 */ … … 1614 1604 * don't provide a $position, the function will return true if the 1615 1605 * $action_variable is found *anywhere* in the action variables array. 1616 *1617 1606 * @return bool True if $action_variable matches at the $position provided. 1618 1607 */ … … 1621 1610 1622 1611 if ( false !== $position ) { 1623 // When a $position is specified, check that slot in the action_variables array 1612 // When a $position is specified, check that slot in the action_variables array. 1624 1613 if ( $action_variable ) { 1625 1614 $is_action_variable = $action_variable == bp_action_variable( $position ); 1626 1615 } else { 1627 1616 // If no $action_variable is provided, we are essentially checking to see 1628 // whether the slot is empty 1617 // whether the slot is empty. 1629 1618 $is_action_variable = !bp_action_variable( $position ); 1630 1619 } 1631 1620 } else { 1632 // When no $position is specified, check the entire array 1621 // When no $position is specified, check the entire array. 1633 1622 $is_action_variable = in_array( $action_variable, (array)bp_action_variables() ); 1634 1623 } … … 1650 1639 * 1651 1640 * @param string $item The item being checked. 1652 *1653 1641 * @return bool True if $item is the current item. 1654 1642 */ … … 1668 1656 1669 1657 /** 1670 * Are we looking at a single item? (group, user, etc) 1658 * Are we looking at a single item? (group, user, etc). 1671 1659 * 1672 1660 * @return bool True if looking at a single item, otherwise false. … … 1770 1758 * already deprecated functions. 1771 1759 * 1772 * @param string $component_name 1760 * @param string $component_name Component name to check. 1773 1761 * 1774 1762 * @return bool True if root component, else false. … … 1778 1766 $retval = false; 1779 1767 1780 // Default to the current component if none is passed 1768 // Default to the current component if none is passed. 1781 1769 if ( empty( $component_name ) ) { 1782 1770 $component_name = bp_current_component(); 1783 1771 } 1784 1772 1785 // Loop through active components and check for key/slug matches 1773 // Loop through active components and check for key/slug matches. 1786 1774 if ( ! empty( $bp->active_components ) ) { 1787 1775 foreach ( (array) $bp->active_components as $key => $slug ) { … … 1814 1802 * @param string $component Optional. Name of the component to check for. 1815 1803 * Default: current component. 1816 *1817 1804 * @return bool True if the specified component is set to be the site's front 1818 1805 * page, otherwise false. … … 1823 1810 $bp = buddypress(); 1824 1811 1825 // Default to the current component if none is passed 1812 // Default to the current component if none is passed. 1826 1813 if ( empty( $component ) ) { 1827 1814 $component = bp_current_component(); 1828 1815 } 1829 1816 1830 // Get the path for the current blog/site 1817 // Get the path for the current blog/site. 1831 1818 $path = is_main_site() 1832 1819 ? bp_core_get_site_path() 1833 1820 : $current_blog->path; 1834 1821 1835 // Get the front page variables 1822 // Get the front page variables. 1836 1823 $show_on_front = get_option( 'show_on_front' ); 1837 1824 $page_on_front = get_option( 'page_on_front' ); … … 1918 1905 * @param string $component The component name. 1919 1906 * @param string $feature The feature name. 1920 *1921 1907 * @return bool 1922 1908 */ … … 1924 1910 $retval = false; 1925 1911 1926 // Default to the current component if none is passed 1912 // Default to the current component if none is passed. 1927 1913 if ( empty( $component ) ) { 1928 1914 $component = bp_current_component(); 1929 1915 } 1930 1916 1931 // Is component in either the active or required components arrays 1917 // Is component in either the active or required components arrays. 1932 1918 if ( isset( buddypress()->active_components[ $component ] ) || isset( buddypress()->required_components[ $component ] ) ) { 1933 1919 $retval = true; … … 1935 1921 // Is feature active? 1936 1922 if ( ! empty( $feature ) ) { 1937 // The xProfile component is specific 1923 // The xProfile component is specific. 1938 1924 if ( 'xprofile' === $component ) { 1939 1925 $component = 'profile'; … … 2093 2079 * @since 2.0.0 2094 2080 * 2095 * @return True if the current page is the activity directory.2081 * @return bool True if the current page is the activity directory. 2096 2082 */ 2097 2083 function bp_is_activity_directory() { … … 2106 2092 * Is the current page a single activity item permalink? 2107 2093 * 2108 * @return True if the current page is a single activity item permalink.2094 * @return bool True if the current page is a single activity item permalink. 2109 2095 */ 2110 2096 function bp_is_single_activity() { … … 2119 2105 * @since 2.0.0 2120 2106 * 2121 * @return True if the current page is the members directory.2107 * @return bool True if the current page is the members directory. 2122 2108 */ 2123 2109 function bp_is_members_directory() { … … 2135 2121 * http://example.com/members/joe/friends/. 2136 2122 * 2137 * @return True if the current page is part of the profile of the logged-in user.2123 * @return bool True if the current page is part of the profile of the logged-in user. 2138 2124 */ 2139 2125 function bp_is_my_profile() { … … 2159 2145 * Will return true anytime there is a displayed user. 2160 2146 * 2161 * @return True if the current page is a user page.2147 * @return bool True if the current page is a user page. 2162 2148 */ 2163 2149 function bp_is_user() { … … 2170 2156 * Eg http://example.com/members/joe/activity/ (or any subpages thereof). 2171 2157 * 2172 * @return True if the current page is a user's activity stream page.2158 * @return bool True if the current page is a user's activity stream page. 2173 2159 */ 2174 2160 function bp_is_user_activity() { … … 2181 2167 * Eg http://example.com/members/joe/friends/ 2182 2168 * 2183 * @return True if the current page is a user's Friends activity stream.2169 * @return bool True if the current page is a user's Friends activity stream. 2184 2170 */ 2185 2171 function bp_is_user_friends_activity() { … … 2207 2193 * Eg http://example.com/members/joe/groups/ 2208 2194 * 2209 * @return True if the current page is a user's Groups activity stream.2195 * @return bool True if the current page is a user's Groups activity stream. 2210 2196 */ 2211 2197 function bp_is_user_groups_activity() { … … 2231 2217 * Eg http://example.com/members/joe/profile/ (or a subpage thereof). 2232 2218 * 2233 * @return True if the current page is part of a user's extended profile.2219 * @return bool True if the current page is part of a user's extended profile. 2234 2220 */ 2235 2221 function bp_is_user_profile() { … … 2242 2228 * Eg http://example.com/members/joe/profile/edit/ (or a subpage thereof). 2243 2229 * 2244 * @return True if the current page is a user's profile edit page.2230 * @return bool True if the current page is a user's profile edit page. 2245 2231 */ 2246 2232 function bp_is_user_profile_edit() { … … 2259 2245 * @since 2.4.0 2260 2246 * 2261 * @return True if the current page is a user's profile edit cover image page.2247 * @return bool True if the current page is a user's profile edit cover image page. 2262 2248 */ 2263 2249 function bp_is_user_change_cover_image() { … … 2456 2442 2457 2443 /** 2458 * Is the current page the groups directory 2444 * Is the current page the groups directory? 2459 2445 * 2460 2446 * @since 2.0.0 … … 2533 2519 $retval = false; 2534 2520 2535 // At a forum URL 2521 // At a forum URL. 2536 2522 if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'forum' ) ) { 2537 2523 $retval = true; … … 2766 2752 * @param string $component Current component to check for. 2767 2753 * @param string $callback Callback to invoke. 2768 *2769 2754 * @return bool 2770 2755 */ … … 2810 2795 * @param array $wp_classes The body classes coming from WP. 2811 2796 * @param array|bool $custom_classes Classes that were passed to get_body_class(). 2812 *2813 2797 * @return array $classes The BP-adjusted body classes. 2814 2798 */ … … 2817 2801 $bp_classes = array(); 2818 2802 2819 /* *Pages *************************************************************/2803 /* Pages *************************************************************/ 2820 2804 2821 2805 if ( is_front_page() ) { … … 2831 2815 } 2832 2816 2833 /* *Components ********************************************************/2817 /* Components ********************************************************/ 2834 2818 2835 2819 if ( ! bp_is_blog_page() ) { … … 2863 2847 } 2864 2848 2865 /* *User **************************************************************/2849 /* User **************************************************************/ 2866 2850 2867 2851 if ( bp_is_user() ) { … … 2923 2907 } 2924 2908 2925 /* *Messages **********************************************************/2909 /* Messages **********************************************************/ 2926 2910 2927 2911 if ( bp_is_messages_inbox() ) { … … 2949 2933 } 2950 2934 2951 /* *Groups ************************************************************/2935 /* Groups ************************************************************/ 2952 2936 2953 2937 if ( bp_is_group() ) { … … 2997 2981 } 2998 2982 2999 /* *Registration ******************************************************/2983 /* Registration ******************************************************/ 3000 2984 3001 2985 if ( bp_is_register_page() ) { … … 3007 2991 } 3008 2992 3009 /* *Current Component & Action ****************************************/2993 /* Current Component & Action ****************************************/ 3010 2994 3011 2995 if ( ! bp_is_blog_page() ) { … … 3014 2998 } 3015 2999 3016 /* *Clean up ***********************************************************/3017 3018 // Add BuddyPress class if we are within a BuddyPress page 3000 /* Clean up ***********************************************************/ 3001 3002 // Add BuddyPress class if we are within a BuddyPress page. 3019 3003 if ( ! bp_is_blog_page() ) { 3020 3004 $bp_classes[] = 'buddypress'; 3021 3005 } 3022 3006 3023 // Merge WP classes with BuddyPress classes and remove any duplicates 3007 // Merge WP classes with BuddyPress classes and remove any duplicates. 3024 3008 $classes = array_unique( array_merge( (array) $bp_classes, (array) $wp_classes ) ); 3025 3009 … … 3046 3030 * 3047 3031 * @param array $wp_classes The post classes coming from WordPress. 3048 *3049 3032 * @return array 3050 3033 */ 3051 3034 function bp_get_the_post_class( $wp_classes = array() ) { 3052 // don't do anything if we're not on a BP page3035 // Don't do anything if we're not on a BP page. 3053 3036 if ( ! is_buddypress() ) { 3054 3037 return $wp_classes; … … 3083 3066 } 3084 3067 3085 // emulate post type css class3068 // Emulate post type css class. 3086 3069 foreach ( $bp_classes as $bp_class ) { 3087 3070 $bp_classes[] = "type-{$bp_class}"; 3088 3071 } 3089 3072 3090 // okay let's merge!3073 // Okay let's merge! 3091 3074 return array_unique( array_merge( $bp_classes, $wp_classes ) ); 3092 3075 } … … 3104 3087 * @param array $a First item. 3105 3088 * @param array $b Second item. 3106 *3107 3089 * @return int Returns an integer less than, equal to, or greater than zero if 3108 3090 * the first argument is considered to be respectively less than, … … 3129 3111 $menus = $selected_menus = array(); 3130 3112 3131 // Get the second level menus 3113 // Get the second level menus. 3132 3114 foreach ( (array) buddypress()->bp_options_nav as $parent_menu => $sub_menus ) { 3133 3115 … … 3137 3119 } 3138 3120 3139 // Sort the items in this menu's navigation by their position property 3121 // Sort the items in this menu's navigation by their position property. 3140 3122 $second_level_menus = (array) $sub_menus; 3141 3123 usort( $second_level_menus, '_bp_nav_menu_sort' ); 3142 3124 3143 // Iterate through the second level menus 3125 // Iterate through the second level menus. 3144 3126 foreach( $second_level_menus as $sub_nav ) { 3145 3127 3146 // Skip items we don't have access to 3128 // Skip items we don't have access to. 3147 3129 if ( empty( $sub_nav['user_has_access'] ) ) { 3148 3130 continue; 3149 3131 } 3150 3132 3151 // Add this menu 3133 // Add this menu. 3152 3134 $menu = new stdClass; 3153 3135 $menu->class = array( 'menu-child' ); … … 3155 3137 $menu->link = $sub_nav['link']; 3156 3138 $menu->name = $sub_nav['name']; 3157 $menu->parent = $parent_menu; // Associate this sub nav with a top-level menu 3158 3159 // If we're viewing this item's screen, record that we need to mark its parent menu to be selected 3139 $menu->parent = $parent_menu; // Associate this sub nav with a top-level menu. 3140 3141 // If we're viewing this item's screen, record that we need to mark its parent menu to be selected. 3160 3142 if ( $sub_nav['slug'] == bp_current_action() ) { 3161 3143 $menu->class[] = 'current-menu-item'; … … 3167 3149 } 3168 3150 3169 // Get the top-level menu parts (Friends, Groups, etc) and sort by their position property 3151 // Get the top-level menu parts (Friends, Groups, etc) and sort by their position property. 3170 3152 $top_level_menus = (array) buddypress()->bp_nav; 3171 3153 usort( $top_level_menus, '_bp_nav_menu_sort' ); 3172 3154 3173 // Iterate through the top-level menus 3155 // Iterate through the top-level menus. 3174 3156 foreach ( $top_level_menus as $nav ) { 3175 3157 3176 // Skip items marked as user-specific if you're not on your own profile 3158 // Skip items marked as user-specific if you're not on your own profile. 3177 3159 if ( empty( $nav['show_for_displayed_user'] ) && ! bp_core_can_edit_settings() ) { 3178 3160 continue; 3179 3161 } 3180 3162 3181 // Get the correct menu link. See https://buddypress.trac.wordpress.org/ticket/4624 3163 // Get the correct menu link. See https://buddypress.trac.wordpress.org/ticket/4624. 3182 3164 $link = bp_loggedin_user_domain() ? str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $nav['link'] ) : trailingslashit( bp_displayed_user_domain() . $nav['link'] ); 3183 3165 3184 // Add this menu 3166 // Add this menu. 3185 3167 $menu = new stdClass; 3186 3168 $menu->class = array( 'menu-parent' ); … … 3190 3172 $menu->parent = 0; 3191 3173 3192 // Check if we need to mark this menu as selected 3174 // Check if we need to mark this menu as selected. 3193 3175 if ( in_array( $nav['css_id'], $selected_menus ) ) { 3194 3176 $menu->class[] = 'current-menu-parent'; … … 3242 3224 * Default: 'BP_Walker_Nav_Menu'. 3243 3225 * } 3244 *3245 3226 * @return string|null If $echo is false, returns a string containing the nav 3246 3227 * menu markup. … … 3280 3261 $show_container = false; 3281 3262 3282 // Create custom walker if one wasn't set 3263 // Create custom walker if one wasn't set. 3283 3264 if ( empty( $args->walker ) ) { 3284 3265 $args->walker = new BP_Walker_Nav_Menu; 3285 3266 } 3286 3267 3287 // Sanitise values for class and ID 3268 // Sanitise values for class and ID. 3288 3269 $args->container_class = sanitize_html_class( $args->container_class ); 3289 3270 $args->container_id = sanitize_html_class( $args->container_id ); 3290 3271 3291 // Whether to wrap the ul, and what to wrap it with 3272 // Whether to wrap the ul, and what to wrap it with. 3292 3273 if ( $args->container ) { 3293 3274 … … 3329 3310 $wrap_id = 'menu-bp'; 3330 3311 3331 // If a specific ID wasn't requested, and there are multiple menus on the same screen, make sure the autogenerated ID is unique 3312 // If a specific ID wasn't requested, and there are multiple menus on the same screen, make sure the autogenerated ID is unique. 3332 3313 while ( in_array( $wrap_id, $menu_id_slugs ) ) { 3333 3314 if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) ) { … … 3352 3333 $items = apply_filters( 'bp_nav_menu_items', $items, $args ); 3353 3334 3354 // Build the output 3335 // Build the output. 3355 3336 $wrap_class = $args->menu_class ? $args->menu_class : ''; 3356 3337 $nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items ); 3357 3338 unset( $items ); 3358 3339 3359 // If we've wrapped the ul, close it 3340 // If we've wrapped the ul, close it. 3360 3341 if ( ! empty( $show_container ) ) { 3361 3342 $nav_menu .= '</' . $args->container . '>';
Note: See TracChangeset
for help on using the changeset viewer.