[wp-trac] [WordPress Trac] #40279: switch_to_blog() and restore_current_blog() gives a fatal error in a multisite

WordPress Trac noreply at wordpress.org
Mon Mar 27 19:23:02 UTC 2017


#40279: switch_to_blog() and restore_current_blog() gives a fatal error in a
multisite
--------------------------------+------------------------
 Reporter:  KestutisIT          |       Owner:
     Type:  defect (bug)        |      Status:  reopened
 Priority:  normal              |   Milestone:
Component:  Networks and Sites  |     Version:
 Severity:  normal              |  Resolution:
 Keywords:                      |     Focuses:  multisite
--------------------------------+------------------------
Changes (by KestutisIT):

 * status:  closed => reopened
 * resolution:  invalid =>


Comment:

 Replying to [comment:1 ocean90]:
 > Hello @KestutisIT, thanks for your report.
 >
 > `switch_to_blog()` is defined in `wp-includes/ms-blogs.php` which is
 only loaded if the current install is a multisite install.
 > If you have a plugin that is only useful for multisite installs you
 should check that appropriately and prevent an activation.
 No, my plugin works in both ways, but it should work with multisite
 disable, you SHOULD NOT have to write different code if multisite is
 enabled, otherwise it breaks the logic of PHP, OOP, and whatever. It just
 a design error. At least no action blank function should be made for that.
 My plugin is made to have blog_id column in tables, and it allows easily
 manage cross-side data, but if the multisite is disabled, it just have "1"
 saved there, and all WP functions works, except that switch_to_blog. So
 that has to be fixed. I'm sure.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40279#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list