Opened 8 years ago
Last modified 3 years ago
#40513 new enhancement
switch_to_blog should accept a WP_site as param
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Networks and Sites | Keywords: | has-patch needs-unit-tests needs-refresh |
Focuses: | multisite | Cc: |
Description
The switch_to_blog function currently only accepts a blog id. By passing a WP_Site object where available, it means switch has more context. The WP_site object has all the site information, including the network id.
Attachments (3)
Change History (13)
#2
@
8 years ago
40513.2.diff has some examples of where we can use this change in core. #40511 will help.
#3
@
8 years ago
+1
We should have a close look at the parameter names and documentation in order to clarify that $site_object
may not actually contain a site object. I have to admit that appears a bit confusing.
Maybe this is a good time to introduce a new switch_site
action and only run it if an object is passed. If a plugin developer then wants to do something with the site object, they'd need to use the switch_site
action. If we ever introduce a function switch_to_site()
or so, we could then have it require an object - this is of course future stuff, but such an action would bring something like forward compatibility. :)
#4
@
8 years ago
I agree. Naming of variables and docs do need work here. @DrewAPicture is the best man to look at this.
I don't agree about a new action. The switch_blog action is fired in switch_to_blog and in the restore. In 40513.3.diff I now pass $current_blog in the restore function. If doing this is going to be useful, we have to pass it to the switch_blog action.
This ticket was mentioned in Slack in #core-multisite by spacedmonkey. View the logs.
8 years ago
This ticket was mentioned in Slack in #core-multisite by spacedmonkey. View the logs.
8 years ago
#7
@
8 years ago
- Keywords 2nd-opinion removed
Hi, sorry missed the ping. Yeah, I'd probably just simplify it down to $site
or $new_site
. Separately, I think I'd probably recommend doing the get_site()
call inside of switch_to_blog()
as it can already accept an object or int – and it would follow with core style on similar usage, such as with how get_post()
is used inside of functions all the time.
Hi, this seems nice.