Opened 3 years ago
Closed 3 years ago
#8592 closed defect (bug) (fixed)
bp_core_get_directory_page_ids ignores current multisite context
Reported by: | thomaslhotta | Owned by: | 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();
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.