Skip to:
Content

BuddyPress.org

Opened 2 years ago

Closed 2 years ago

#8592 closed defect (bug) (fixed)

bp_core_get_directory_page_ids ignores current multisite context

Reported by: thomaslhotta's profile thomaslhotta Owned by: imath's profile imath
Milestone: 10.0.0 Priority: normal
Severity: normal Version: 1.5
Component: Core Keywords: needs-patch
Cc:

Description

The bp_core_get_directory_page_ids function in src/bp-core/bp-core-functions.php is not aware on the current blog if running on a multisite setup. This can cause an issue with the following code in the foreach loop:

// Trashed pages should never appear in results.
if ( 'trash' == get_post_status( $page_id ) ) {
   unset( $page_ids[ $component_name ] );
}

It checks if a post with $page_id as ID is trashed, but does this in the context of the current blog. So if we are currently not on the main blog and there is a post of any type that has a trashed status, this will remove the page form the array. This happened to me with a customize_changeset post type that by coincidence had the same id.

I think that this is statement would have to be wrapped in something like this to work correctly:

// Trashed pages should never appear in results.
switch_to_blog( bp_get_root_blog_id() );
if ( 'trash' == get_post_status( $page_id ) ) {
        unset( $page_ids[ $component_name ] );
}
restore_current_blog();

Change History (2)

#1 @imath
2 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 10.0.0
  • Version changed from 9.1.1 to 1.5

Thanks for your report @thomaslhotta. The switch seems the right approach, I'd probably add a bp_is_root_blog() check before doing so because I believe there's a specific config where the directory pages are created on each blog of a network.

#2 @imath
2 years ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from new to closed

In 13159:

Make sure BP directory page IDs are not wrongly unset on multisite

In case a post of a different site of the multisite network has the same ID than one of the BP directory page IDs, the function can wrongly return an array in which the corresponding directory page ID is missing.

We need to make sure this function always run into the BP Root Blog context.

Props thomaslhotta

Fixes #8592

Note: See TracTickets for help on using tickets.