[wp-trac] [WordPress Trac] #29684: Add get_main_site() function
WordPress Trac
noreply at wordpress.org
Fri Jul 14 22:30:16 UTC 2017
#29684: Add get_main_site() function
-------------------------------------------------+-------------------------
Reporter: rmccue | Owner: jeremyfelt
Type: enhancement | Status: reviewing
Priority: normal | Milestone: 4.9
Component: Networks and Sites | Version: 3.9
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests dev- | Focuses: multisite
feedback |
-------------------------------------------------+-------------------------
Changes (by flixos90):
* keywords: has-patch needs-unit-tests => has-patch has-unit-tests dev-
feedback
* milestone: Future Release => 4.9
Comment:
[attachment:29684.2.diff] is a new take on the `get_main_site_id()`
function.
* It introduces `get_main_site_id( $network_id = null )`.
* If not multisite, it returns 1.
* If invalid network parameter passed, it returns 0.
* The actual lookup logic is the same that was previously located at
the bottom of `ms_load_current_site_and_network()` with the exception that
it now uses `WP_Site_Query` for improved performance. In case this lookup
fails (which can only happen in case of a "broken" network without a
matching site), the function returns 0.
* It introduces a filter inside that function called `get_main_site_id`
that receives the detected `$main_site_id` and the `$network_id` that it
was detected for.
* `is_main_site()` has been adjusted to use `get_main_site_id()` instead
of only looking at the current network. In addition, it now supports an
optional `$network_id` parameter as well that is simply forwarded to
`get_main_site_id()`.
* The relevant code bit from `ms_load_current_site_and_network()` that was
moved to the new function has been replaced by a call to that function.
* Several unit tests have been added to ensure the new function works
correctly. An additional unit test for `is_main_site()` with the
`$network_id` parameter provided has been added too.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29684#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list