WordPress.org

Make WordPress Core

#37218 closed enhancement (fixed)

get_main_network_id should use WP_Network_Query

Reported by: spacedmonkey Owned by: jeremyfelt
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.6
Component: Networks and Sites Keywords: has-patch
Focuses: multisite Cc:

Description

The get_main_network_id is used in the bootstrap process to load the network object. With the new WP_Network_Query class, we should use that to load the network id. Using WP_Network_Query we gain filters and caching.

Attachments (2)

37218.3.diff (1.0 KB) - added by spacedmonkey 16 months ago.
37218.4.diff (1.0 KB) - added by jeremyfelt 14 months ago.

Download all attachments as: .zip

Change History (6)

#1 @spacedmonkey
16 months ago

  • Keywords has-patch needs-unit-tests added

#2 @flixos90
14 months ago

  • Keywords needs-unit-tests removed
  • Milestone changed from Awaiting Review to 4.7

Patch looks good to me. +1 for getting rid of the cache key. One thing I don't think we need is the ! empty( $_networks ) check. That kind of check hasn't been in place before and shouldn't be required since every Multisite has at least one network.

About unit tests, I don't think these are necessary here since that part of get_main_network_id() is already covered (https://core.trac.wordpress.org/browser/trunk/tests/phpunit/tests/multisite/network.php#L66 would fail if we broke it).

@jeremyfelt
14 months ago

#3 @jeremyfelt
14 months ago

  • Owner set to jeremyfelt
  • Status changed from new to reviewing

Replying to flixos90:

One thing I don't think we need is the ! empty( $_networks ) check. That kind of check hasn't been in place before and shouldn't be required since every Multisite has at least one network.

Agreed. I don't believe there's a way to hit that condition unless something has gone very wrong. I think we're okay without it. I've added 37218.4.diff, which makes that change.

About unit tests, I don't think these are necessary here since that part of get_main_network_id() is already covered (https://core.trac.wordpress.org/browser/trunk/tests/phpunit/tests/multisite/network.php#L66 would fail if we broke it).

+1

#4 @jeremyfelt
13 months ago

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

In 38632:

Multisite: Use get_networks() in get_main_network_id().

The manual query for the main network ID can now be replaced with a cached get_networks() query. This allows us to eliminate the primary_network_id cache key entirely.

Props spacedmonkey.
Fixes #37218.

Note: See TracTickets for help on using tickets.