Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Make sure the primary nav is set before resetting it
Browse files Browse the repository at this point in the history
  • Loading branch information
imath committed May 28, 2022
1 parent e724512 commit cd8f6db
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 24 deletions.
10 changes: 8 additions & 2 deletions src/bp-activity/classes/class-activity-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,20 @@ public function reset_nav() {
remove_action( 'bp_' . $this->id . '_setup_nav', array( $this, 'reset_nav' ), 20 );

// Get the main nav.
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );
$activity_slug = bp_get_activity_slug();
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );

// Make sure the main navigation was built the right way.
if ( ! is_array( $main_nav ) || ! isset( $main_nav[ $activity_slug ] ) ) {
return;
}

// Set the main nav slug.
$main_nav = reset( $main_nav );
$slug = $main_nav['slug'];

// Set the main nav `rewrite_id` property.
$rewrite_id = sprintf( 'bp_member_%s', bp_get_activity_slug() );
$rewrite_id = sprintf( 'bp_member_%s', $activity_slug );
$main_nav['rewrite_id'] = $rewrite_id;

// Reset the link using BP Rewrites.
Expand Down
10 changes: 8 additions & 2 deletions src/bp-blogs/classes/class-blogs-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,20 @@ public function reset_nav() {
remove_action( 'bp_' . $this->id . '_setup_nav', array( $this, 'reset_nav' ), 20 );

// Get the main nav.
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );
$blogs_slug = bp_get_blogs_slug();
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );

// Make sure the main navigation was built the right way.
if ( ! is_array( $main_nav ) || ! isset( $main_nav[ $blogs_slug ] ) ) {
return;
}

// Set the main nav slug.
$main_nav = reset( $main_nav );
$slug = $main_nav['slug'];

// Set the main nav `rewrite_id` property.
$rewrite_id = sprintf( 'bp_member_%s', bp_get_blogs_slug() );
$rewrite_id = sprintf( 'bp_member_%s', $blogs_slug );
$main_nav['rewrite_id'] = $rewrite_id;

// Reset the link using BP Rewrites.
Expand Down
2 changes: 1 addition & 1 deletion src/bp-core/bp-core-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function _was_called_too_early( $function, $bp_global ) {
$is_xmlrpc = defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST;

// `bp_parse_query` is not fired in WP Admin.
if ( did_action( 'bp_parse_query' ) || $is_admin || $is_login || $is_rest || $is_xmlrpc ) {
if ( did_action( 'bp_parse_query' ) || $is_admin || $is_login || $is_rest || $is_xmlrpc || wp_doing_cron() ) {
return $retval;
}

Expand Down
11 changes: 11 additions & 0 deletions src/bp-core/classes/class-core-nav-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ public function get_primary( $args = array(), $sort = true ) {
return $this->nav[ $slug ];
}

/**
* Prevents a notice when the secondary nav wasn't set the right way.
*
* @since 1.2.0
*
* @return null
*/
public function get_secondary() {
return null;
}

/**
* Restores problematic nav items.
*
Expand Down
10 changes: 8 additions & 2 deletions src/bp-friends/classes/class-friends-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ public function reset_nav() {
remove_action( 'bp_' . $this->id . '_setup_nav', array( $this, 'reset_nav' ), 20 );

// Get the main nav.
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );
$friends_slug = bp_get_friends_slug();
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );

// Make sure the main navigation was built the right way.
if ( ! is_array( $main_nav ) || ! isset( $main_nav[ $friends_slug ] ) ) {
return;
}

// Set the main nav slug.
$main_nav = reset( $main_nav );
$slug = $main_nav['slug'];

// Set the main nav `rewrite_id` property.
$rewrite_id = sprintf( 'bp_member_%s', bp_get_friends_slug() );
$rewrite_id = sprintf( 'bp_member_%s', $friends_slug );
$main_nav['rewrite_id'] = $rewrite_id;

// Reset the link using BP Rewrites.
Expand Down
10 changes: 8 additions & 2 deletions src/bp-groups/classes/class-groups-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,20 @@ public function reset_nav() {
$bp = buddypress();

// Get the main nav.
$main_nav = $bp->members->nav->get_primary( array( 'component_id' => $this->id ), false );
$groups_slug = bp_get_groups_slug();
$main_nav = $bp->members->nav->get_primary( array( 'component_id' => $this->id ), false );

// Make sure the main navigation was built the right way.
if ( ! is_array( $main_nav ) || ! isset( $main_nav[ $groups_slug ] ) ) {
return;
}

// Set the main nav slug.
$main_nav = reset( $main_nav );
$slug = $main_nav['slug'];

// Set the main nav `rewrite_id` property.
$rewrite_id = sprintf( 'bp_member_%s', bp_get_groups_slug() );
$rewrite_id = sprintf( 'bp_member_%s', $groups_slug );
$main_nav['rewrite_id'] = $rewrite_id;

// Reset the link using BP Rewrites.
Expand Down
21 changes: 13 additions & 8 deletions src/bp-members/classes/class-members-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,25 @@ public function reset_nav() {
remove_action( 'bp_' . $this->id . '_setup_nav', array( $this, 'reset_nav' ), 20 );

// Get the main nav.
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );
$members_slug = bp_get_profile_slug();
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );

if ( bp_displayed_user_has_front_template() ) {
$members_slug = 'front';
}

// Make sure the main navigation was built the right way.
if ( ! is_array( $main_nav ) || ! isset( $main_nav[ $members_slug ] ) ) {
return;
}

// Set the main nav slug.
$main_nav = reset( $main_nav );
$slug = $main_nav['slug'];

if ( bp_get_profile_slug() === $slug ) {
$main_nav['rewrite_id'] = 'bp_member_profile';
} elseif ( 'front' === $slug ) {
$main_nav['rewrite_id'] = 'bp_member_front';
}

// Set the main nav `rewrite_id` property.
$rewrite_id = $main_nav['rewrite_id'];
$rewrite_id = sprintf( 'bp_member_%s', $members_slug );
$main_nav['rewrite_id'] = $rewrite_id;

// Reset the link using BP Rewrites.
$main_nav['link'] = bp_members_rewrites_get_nav_url(
Expand Down
10 changes: 8 additions & 2 deletions src/bp-messages/classes/class-messages-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ public function reset_nav() {
remove_action( 'bp_' . $this->id . '_setup_nav', array( $this, 'reset_nav' ), 20 );

// Get the main nav.
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );
$messages_slug = bp_get_messages_slug();
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );

// Make sure the main navigation was built the right way.
if ( ! is_array( $main_nav ) || ! isset( $main_nav[ $messages_slug ] ) ) {
return;
}

// Set the main nav slug.
$main_nav = reset( $main_nav );
$slug = $main_nav['slug'];

// Set the main nav `rewrite_id` property.
$rewrite_id = sprintf( 'bp_member_%s', bp_get_messages_slug() );
$rewrite_id = sprintf( 'bp_member_%s', $messages_slug );
$main_nav['rewrite_id'] = $rewrite_id;

// Reset the link using BP Rewrites.
Expand Down
10 changes: 8 additions & 2 deletions src/bp-notifications/classes/class-notifications-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ public function reset_nav() {
remove_action( 'bp_' . $this->id . '_setup_nav', array( $this, 'reset_nav' ), 20 );

// Get the main nav.
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );
$notifications_slug = bp_get_notifications_slug();
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );

// Make sure the main navigation was built the right way.
if ( ! is_array( $main_nav ) || ! isset( $main_nav[ $notifications_slug ] ) ) {
return;
}

// Set the main nav slug.
$main_nav = reset( $main_nav );
$slug = $main_nav['slug'];

// Set the main nav`rewrite_id` property.
$rewrite_id = sprintf( 'bp_member_%s', bp_get_notifications_slug() );
$rewrite_id = sprintf( 'bp_member_%s', $notifications_slug );
$main_nav['rewrite_id'] = $rewrite_id;

// Reset the link using BP Rewrites.
Expand Down
10 changes: 8 additions & 2 deletions src/bp-settings/classes/class-settings-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,20 @@ public function reset_nav() {
remove_action( 'bp_' . $this->id . '_setup_nav', array( $this, 'reset_nav' ), 20 );

// Get the main nav.
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );
$settings_slug = bp_get_settings_slug();
$main_nav = buddypress()->members->nav->get_primary( array( 'component_id' => $this->id ), false );

// Make sure the main navigation was built the right way.
if ( ! is_array( $main_nav ) || ! isset( $main_nav[ $settings_slug ] ) ) {
return;
}

// Set the main nav slug.
$main_nav = reset( $main_nav );
$slug = $main_nav['slug'];

// Set the main nav`rewrite_id` property.
$rewrite_id = sprintf( 'bp_member_%s', bp_get_settings_slug() );
$rewrite_id = sprintf( 'bp_member_%s', $settings_slug );
$main_nav['rewrite_id'] = $rewrite_id;

// Reset the link using BP Rewrites.
Expand Down
8 changes: 7 additions & 1 deletion src/bp-xprofile/classes/class-xprofile-component.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ public function reset_nav() {
remove_action( 'bp_' . $this->id . '_setup_nav', array( $this, 'reset_nav' ), 20 );

// Get the main nav.
$main_nav = buddypress()->members->nav->get_primary( array( 'slug' => bp_get_profile_slug() ), false );
$xprofile_slug = bp_get_profile_slug();
$main_nav = buddypress()->members->nav->get_primary( array( 'slug' => $xprofile_slug ), false );

// Make sure the main navigation was built the right way.
if ( ! is_array( $main_nav ) || ! isset( $main_nav[ $xprofile_slug ] ) ) {
return;
}

// Set the main nav slug.
$main_nav = reset( $main_nav );
Expand Down

0 comments on commit cd8f6db

Please sign in to comment.