BP_Members_Component::setup_nav( array $main_nav = array(), array $sub_nav = array() )
Set up fall-back component navigation if XProfile is inactive.
Description
See also
- BP_Component::setup_nav(): for a description of arguments.
Parameters
- $main_nav
-
(Optional) See BP_Component::setup_nav() for description.
Default value: array()
- $sub_nav
-
(Optional) See BP_Component::setup_nav() for description.
Default value: array()
Source
File: bp-members/classes/class-bp-members-component.php
public function setup_nav( $main_nav = array(), $sub_nav = array() ) { // Don't set up navigation if there's no member. if ( ! is_user_logged_in() && ! bp_is_user() ) { return; } $is_xprofile_active = bp_is_active( 'xprofile' ); // Bail if XProfile component is active and there's no custom front page for the user. if ( ! bp_displayed_user_has_front_template() && $is_xprofile_active ) { return; } // Determine user to use. if ( bp_displayed_user_domain() ) { $user_domain = bp_displayed_user_domain(); } elseif ( bp_loggedin_user_domain() ) { $user_domain = bp_loggedin_user_domain(); } else { return; } // Set slug to profile in case the xProfile component is not active $slug = bp_get_profile_slug(); // Defaults to empty navs $this->main_nav = array(); $this->sub_nav = array(); if ( ! $is_xprofile_active ) { $this->main_nav = array( 'name' => __( 'Profile', 'buddyboss' ), 'slug' => $slug, 'position' => 10, 'screen_function' => 'bp_members_screen_display_profile', 'default_subnav_slug' => 'public', 'item_css_id' => buddypress()->profile->id ); } /** * Setup the subnav items for the member profile. * * This is required in case there's a custom front or in case the xprofile component * is not active. */ $this->sub_nav = array( 'name' => __( 'View', 'buddyboss' ), 'slug' => 'public', 'parent_url' => trailingslashit( $user_domain . $slug ), 'parent_slug' => $slug, 'screen_function' => 'bp_members_screen_display_profile', 'position' => 10 ); /** * If there's a front template the members component nav * will be there to display the user's front page. */ if ( bp_displayed_user_has_front_template() ) { $main_nav = array( 'name' => __( 'Dashboard', 'buddyboss' ), 'slug' => 'front', 'position' => 5, 'screen_function' => 'bp_members_screen_display_profile', 'default_subnav_slug' => 'public', ); // We need a dummy subnav for the front page to load. $front_subnav = $this->sub_nav; $front_subnav['parent_slug'] = 'front'; // In case the subnav is displayed in the front template $front_subnav['parent_url'] = trailingslashit( $user_domain . 'front' ); // Set the subnav $sub_nav[] = $front_subnav; /** * If the profile component is not active, we need to create a new * nav to display the WordPress profile. */ if ( ! $is_xprofile_active ) { add_action( 'bp_members_setup_nav', array( $this, 'setup_profile_nav' ) ); } /** * If there's no front template and xProfile is not active, the members * component nav will be there to display the WordPress profile */ } else { $main_nav = $this->main_nav; $sub_nav[] = $this->sub_nav; } parent::setup_nav( $main_nav, $sub_nav ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.5.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.