WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 2 months ago

#43598 reviewing enhancement

site-options notoption only queried and never set in not multisite wordpress installs

Reported by: Grzegorz.Janoszka Owned by: SergeyBiryukov
Milestone: 5.0 Priority: normal
Severity: normal Version: 4.9.5
Component: Options, Meta APIs Keywords: has-patch dev-feedback
Focuses: Cc:

Description

We have notoptions mechanism that works well. WordPress core does also query $network_id:notoptions regardless of multiste. However, such option is set only in multisite installs. As a result, if you are not running multisite, you are only querying for $network_id:notoptions and you never set it. It beats the idea of notoptions - we read it, but we never set it - what's the point?

Possible solutions:

  • read $network_id:notoptions only in multisite installs
  • set $network_id:notoptions also in not multisite installs

Attachments (1)

43598.diff (2.3 KB) - added by soulseekah 3 months ago.

Download all attachments as: .zip

Change History (3)

@soulseekah
3 months ago

#1 @soulseekah
3 months ago

  • Keywords has-patch dev-feedback added

Hey, welcome back @Grzegorz.Janoszka!

Thank you for your ticket!

get_network_option is an alias for get_site_option, which is called in core in many places. In non-multisite installs, $network_id is set to 1 by default.

These calls are absolutely valid, and $network_id:notoptions is indeed not being set. There's a is_multisite() condition which prevents the $network_id:notoptions logic, directs the call to plain old get_options which stores non-existing options in the plain old notoptions cache.

In single-site setups the multisite code bits are never called apart from wp_cache_get which is deterministic there. It seems safe to omit the wp_cache_get call since it's never being set to anything useful but called multiple times from core. It does set wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); to an empty array in single-site installs, which is also useless, since it will always remain as such.

43599.diff stubs these calls out. Might need unit-tests to make sure that notoptions caching works in multisite mode as it is supposed to, and that it's always empty in single-sites. Or we can risk it :)

#2 @SergeyBiryukov
2 months ago

  • Milestone changed from Awaiting Review to 5.0
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing
Note: See TracTickets for help on using tickets.