[wp-trac] [WordPress Trac] #25293: Switch_to_blog not switching the siteid

WordPress Trac noreply at wordpress.org
Thu Sep 12 16:18:57 UTC 2013


#25293: Switch_to_blog not switching the siteid
--------------------------+------------------------------
 Reporter:  Rahe          |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Multisite     |     Version:  3.0
 Severity:  minor         |  Resolution:
 Keywords:                |
--------------------------+------------------------------
Changes (by jeremyfelt):

 * version:  3.6.1 => 3.0


Comment:

 One of the great things about `switch_to_blog()` is that it requires no
 database operation to succeed. It is passed a `$blog_id` (which should be
 named `$site_id`), which it sets to the `$_GLOBALS['blog_id']`, it
 performs `$wpdb->set_blog_id()` to get the correct table prefixes setup
 for when queries are made, and it loads in the user's capabilities for the
 new `$blog_id`.

 I don't think we want to introduce a database call to find the site's
 network ID from the `$blog_id` that was passed. It would be interesting to
 have `switch_to_blog()` accept another parameter for `$network_id` so that
 the caller could explicitly determine what site and network should be
 available. The deprecated parameter that is there now was `$validate`
 until [13125] it looks like.

 More refreshing would be a new `switch_to_site( $site_id, $network_id )`
 function that wraps `switch_to_blog()` and a `switch_to_network(
 $network_id )` function to try and limit some of the confusion at the code
 level. Even then, it may be that passing `$network_id` is a decision left
 to the developer as the one who knows whether a network level lookup will
 be needed.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/25293#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list