Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Switch network when switching site #118

Open
spacedmonkey opened this issue Apr 21, 2017 · 0 comments · May be fixed by #119
Open

Switch network when switching site #118

spacedmonkey opened this issue Apr 21, 2017 · 0 comments · May be fixed by #119

Comments

@spacedmonkey
Copy link
Contributor

Currently when using switch_to_blog, it doesn't also switch the network (site) id as well. Details of this issue can be found in a core ticket #25293. The issue is related to not wanting to add a database queries to the switching process. This is a valid problem. In core patch #40513, the switch_to_blog function will allow for WP_Site to be passed. This WP_Site will then be passed to 'switch_blog' action. This is a good for multi network. With the WP_Site we also get a property of network_id. A action could be added like this

function switch_blog_and_network( $new_blog, $prev_blog_id, $site_object ){
       if ( $site_object instanceof WP_Site && get_current_network_id() != $site_object->site_id ) {
              switch_to_network( $site_object->site_id );
       } else {
             restore_current_network();
       }
}
add_action( 'switch_blog', 'switch_blog_and_network', 10, 3 ); 

This would also switch network if different from current network.

@spacedmonkey spacedmonkey linked a pull request Apr 24, 2017 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant