bp_core_menu_highlight_parent_page( array $retval, WP_Post $page )
Adds current page CSS classes to the parent BP page in a WP Page Menu.
Description Description
Because BuddyPress primarily uses virtual pages, we need a way to highlight the BP parent page during WP menu generation. This function checks the current BP component against the current page in the WP menu to see if we should highlight the WP page.
Parameters Parameters
- $retval
-
(Required) CSS classes for the current menu page in the menu.
- $page
-
(Required) The page properties for the current menu item.
Return Return
(array)
Source Source
File: bp-core/bp-core-filters.php
function bp_core_menu_highlight_parent_page( $retval, $page ) { if ( ! is_buddypress() ) { return $retval; } $page_id = false; // Loop against all BP component pages. foreach ( (array) buddypress()->pages as $component => $bp_page ) { // Handles the majority of components. if ( bp_is_current_component( $component ) ) { $page_id = (int) $bp_page->id; } // Stop if not on a user page. if ( ! bp_is_user() && ! empty( $page_id ) ) { break; } // Members component requires an explicit check due to overlapping components. if ( bp_is_user() && 'members' === $component ) { $page_id = (int) $bp_page->id; break; } } // Duplicate some logic from Walker_Page::start_el() to highlight menu items. if ( ! empty( $page_id ) ) { $_bp_page = get_post( $page_id ); if ( in_array( $page->ID, $_bp_page->ancestors, true ) ) { $retval[] = 'current_page_ancestor'; } if ( $page->ID === $page_id ) { $retval[] = 'current_page_item'; } elseif ( $_bp_page && $page->ID === $_bp_page->post_parent ) { $retval[] = 'current_page_parent'; } } $retval = array_unique( $retval ); return $retval; }
Changelog Changelog
Version | Description |
---|---|
2.2.0 | Introduced. |