Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#37218 closed enhancement (fixed)

get_main_network_id should use WP_Network_Query

Reported by: spacedmonkey's profile spacedmonkey Owned by: jeremyfelt's profile 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 8 years ago.
37218.4.diff (1.0 KB) - added by jeremyfelt 8 years ago.

Download all attachments as: .zip

Change History (6)

@spacedmonkey
8 years ago

#1 @spacedmonkey
8 years ago

  • Keywords has-patch needs-unit-tests added

#2 @flixos90
8 years 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
8 years ago

#3 @jeremyfelt
8 years 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
8 years 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.