bp_core_menu_highlight_parent_page

Adds current page CSS classes to the parent BP page in a WP Page Menu.

Description

(array) bp_core_menu_highlight_parent_page( (array) $retval, (WP_Post) $page ); 

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.

Returns (array)

Parameters (2)

0. $retval (array)
CSS classes for the current menu page in the menu.
1. $page (WP_Post)
The page properties for the current menu item.

Usage

  1. if ( !function_exists( 'bp_core_menu_highlight_parent_page' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-filters.php'; 
  3.  
  4. // CSS classes for the current menu page in the menu. 
  5. $retval = array(); 
  6.  
  7. // The page properties for the current menu item. 
  8. $page = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_core_menu_highlight_parent_page($retval, $page); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-filters.php  
  1. function bp_core_menu_highlight_parent_page( $retval, $page ) { 
  2. if ( ! is_buddypress() ) { 
  3. return $retval; 
  4.  
  5. $page_id = false; 
  6.  
  7. // Loop against all BP component pages. 
  8. foreach ( (array)buddypress)->pages as $component => $bp_page ) { 
  9. // Handles the majority of components. 
  10. if ( bp_is_current_component( $component ) ) { 
  11. $page_id = (int) $bp_page->id; 
  12.  
  13. // Stop if not on a user page. 
  14. if ( ! bp_is_user() && ! empty( $page_id ) ) { 
  15. break; 
  16.  
  17. // Members component requires an explicit check due to overlapping components. 
  18. if ( bp_is_user() && 'members' === $component ) { 
  19. $page_id = (int) $bp_page->id; 
  20. break; 
  21.  
  22. // Duplicate some logic from Walker_Page::start_el() to highlight menu items. 
  23. if ( ! empty( $page_id ) ) { 
  24. $_bp_page = get_post( $page_id ); 
  25. if ( in_array( $page->ID, $_bp_page->ancestors, true ) ) { 
  26. $retval[] = 'current_page_ancestor'; 
  27. if ( $page->ID === $page_id ) { 
  28. $retval[] = 'current_page_item'; 
  29. } elseif ( $_bp_page && $page->ID === $_bp_page->post_parent ) { 
  30. $retval[] = 'current_page_parent'; 
  31.  
  32. $retval = array_unique( $retval ); 
  33.  
  34. return $retval;