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
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
- $retval
-
(Required) CSS classes for the current menu page in the menu.
- $page
-
(Required) The page properties for the current menu item.
Return
(array)
Source
File: bp-core/bp-core-filters.php
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | 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 ( isset( $page ->ID ) && in_array( $page ->ID, $_bp_page ->ancestors, true ) ) { $retval [] = 'current_page_ancestor' ; } if ( isset( $page ->ID ) && $page ->ID === $page_id ) { $retval [] = 'current_page_item' ; } elseif ( isset( $page ->ID ) && $_bp_page && $page ->ID === $_bp_page ->post_parent ) { $retval [] = 'current-menu-item' ; $retval [] = 'current_page_parent' ; } } $retval = array_unique ( $retval ); return $retval ; } |
Changelog
Version | Description |
---|---|
BuddyPress 2.2.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.