Skip to content

Commit

Permalink
Switch to BP root blog to migrate directoriers if necessary
Browse files Browse the repository at this point in the history
Eg: when the BP root blog is not the same as the main blog of a multisite network.
  • Loading branch information
imath committed Dec 28, 2023
1 parent 8e8ec62 commit e349e9c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions inc/migrate.php
Expand Up @@ -22,6 +22,11 @@
* @param string $post_type The name of the post type to use for directory pages.
*/
function bp_classic_switch_directory_post_type( $post_type = '' ) {
$needs_switch = is_multisite() && ! bp_is_root_blog();
if ( $needs_switch ) {
switch_to_blog( bp_get_root_blog_id() );
}

$directory_page_ids = bp_core_get_directory_page_ids( 'all' );
$nav_menu_item_ids = array();
$old_post_type = 'buddypress';
Expand Down Expand Up @@ -96,6 +101,10 @@ function bp_classic_switch_directory_post_type( $post_type = '' ) {
);
}
}

if ( $needs_switch ) {
restore_current_blog();
}
}

/**
Expand Down

0 comments on commit e349e9c

Please sign in to comment.