WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 6 months ago

#21432 reopened defect (bug)

Deprecate *_blog_option()

Reported by: ryan Owned by: ryan
Milestone: Future Release Priority: normal
Severity: normal Version: 3.4.1
Component: Options, Meta APIs Keywords: 2nd-opinion
Focuses: Cc:

Description (last modified by ryan)

Deprecate get_blog_option(), add_blog_option(), update_blog_option(), and delete_blog_option(). The regular *_option() functions wrapped with switch_to_blog() and restore_current_blog() should be used instead.

Previous discussion:

http://core.trac.wordpress.org/ticket/21270#comment:11

Attachments (4)

21432.diff (12.1 KB) - added by ryan 2 years ago.
Incomplete and untested
21432.2.diff (17.7 KB) - added by ryan 2 years ago.
21432.3.diff (19.3 KB) - added by ryan 2 years ago.
21432.4.diff (1.1 KB) - added by ryan 2 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 ryan2 years ago

  • Description modified (diff)

comment:2 ryan2 years ago

  • Description modified (diff)

ryan2 years ago

Incomplete and untested

ryan2 years ago

ryan2 years ago

comment:3 ryan2 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [21414]:

Deprecate get_blog_option(), add_blog_option(), update_blog_option(), and delete_blog_option().

Use the regular option functions wrapped in switch_to_blog() and restore_current_blog() instead.

Group multiple operations within a single switch where possible.

fixes #21432

comment:4 johnbillion2 years ago

Might be an idea to pass the phrase "the regular option functions wrapped in switch_to_blog() and restore_current_blog()" to the $replacement parameter of _deprecated_function().

comment:5 dd322 years ago

While this change makes sense to me, I don't see any need to stop using *_blog_option and/or deprecating them.

As they stand, these functions perform a very specific task, Grab another site's option without extra code required by the calling functions.

Although it may be more efficient to use switch_to_blog() when multiple options are being requested, it doesn't seem like enough of a reason to deprecate the functions, especially when it seemingly doesn't provide anything extra to the calling function, let alone changing the semantics of the actual operation ("Get blog xyz's option blah" vs "Switch to the other blog, grab the option, then come home again") - that's low-level stuff that the calling function shouldn't care about:

foreach ( $blogs as $blog_id )
   $sites[ $blog_id ] = get_blog_option( $blog_id, 'some_option' );

vs

foreach ( $blogs as $blog_id ) {
   switch_to_blog( $blog_id );
   $sites[ $blog_id ] = get_option( 'some_option' );
   restore_current_blog();
}

comment:6 ryan2 years ago

In [21480]:

Undeprecate *_blog_option() by popular demand. Put them back in ms-blogs.php since direct inclusion of ms-blogs.php/ms-functions.php is unforntunately common.

see #21432

comment:7 ryan2 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened
PHP Fatal error:  Call to undefined function get_current_blog_id() in /.../wp-includes/ms-blogs.php on line 340

Looks like the blog option functions are being called before general-template.php is loaded. Alternatives are to go back to using the blog_id global or perhaps moving get_current_blog_id() to load.php.

ryan2 years ago

comment:8 scribu2 years ago

  • Cc scribu added

comment:9 ryan2 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In [21484]:

Move get_current_blog_id() to load.php so it is available during multisite bootstrap. fixes #21432

comment:10 nacin2 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

ryan and I would still lean toward deprecating _blog_option(). We'd just have to leave them in ms-blogs.php, which is fine with me.

Deprecating them emphasizes that they are not more performant than switch_to_blog() (which they were, hypothetically, under earlier versions, albeit with caching issues), and that switch_to_blog() should be used if you have more than one operation.

I'm willing to suggest a deprecation of current_user_can_for_blog() as well, for the same reasons.

comment:11 nacin2 years ago

  • Keywords 2nd-opinion added

comment:12 scribu2 years ago

I, for one, agree with the deprecation; having two ways of doing essentially the same thing is confusing.

comment:13 nacin22 months ago

We still need to figure out whether options filters should be skipped (or alternative ones should run) when we are switched. I guess we'll find out soon what kind of breakage we might be looking at.

We should also re-deprecate _blog_option(). See also #21459 where I mention current_user_can_for_blog() should go too.

Last edited 22 months ago by nacin (previous) (diff)

comment:14 ryan21 months ago

  • Milestone changed from 3.5 to Future Release

comment:15 nacin6 months ago

  • Component changed from General to Options and Meta
Note: See TracTickets for help on using tickets.