[wp-trac] [WordPress Trac] #40646: Move code from `ms-settings.php` into functions
WordPress Trac
noreply at wordpress.org
Wed May 3 12:56:00 UTC 2017
#40646: Move code from `ms-settings.php` into functions
----------------------------------------+------------------------------
Reporter: flixos90 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Networks and Sites | Version:
Severity: normal | Resolution:
Keywords: needs-unit-tests has-patch | Focuses: multisite
----------------------------------------+------------------------------
Changes (by flixos90):
* keywords: needs-patch needs-unit-tests => needs-unit-tests has-patch
Comment:
[attachment:40646.diff] introduces the following functions, all of which
handle part of what is currently procedural code in `ms-settings.php`:
* `ms_detect_current_site_and_network()`: Calls
`ms_load_current_site_and_network()`, but gets the current domain and path
before. If `$current_blog` and `$current_site` have already been populated
prior (for example through a custom `sunrise.php`), the function ensures
the two are `WP_Site`/`WP_Network` objects and simply returns true.
Question: Do we need to make `$domain` and `$path` global (since they
implicitly were before)?
* `ms_get_request_domain()`: Utility function to get the current domain to
detect the site and network from.
* `ms_get_request_path()`: Utility function to get the current path to
detect the site and network from.
* `ms_handle_bootstrap_result()`: Accepts the result of
`ms_detect_current_site_and_network()`, and dies if false, or redirects if
it is a string (redirect URL). This is the only function that's not
testable.
* `ms_setup_vars()`: Accepts a `WP_Site` and `WP_Network` object (usually
the current site and network) and populates further global variables
accordingly. Database and cache are also initialized.
The procedural code in `ms-settings.php` is now a lot simpler as it only
calls the above functions (plus a few that existed prior and are not
testable as they're setting constants) and runs the `ms_loaded` hook.
While there are a few things that now happen in a slightly different
order, I particularly paid attention not to change things around that one
could somehow intercept (and thus run into possible BC issues). Probably
the most important change is that the forced conversion to `WP_Site` and
`WP_Network` happens a bit earlier, furthermore it doesn't happen when
calling Core's `ms_load_current_site_and_network()`, since it instantiates
those objects anyway.
Also some code that was previously in the `if ( ! isset( $current_site )
|| ! isset( $current_blog ) )` clause now runs regardless of that check
(particularly setting some globals such as `$blog_id`), but those
variables are only set if they aren't set prior, so it will work the same
way. Plus it makes the job easier for custom `sunrise.php`s, since they
don't need to manually write `$blog_id = $current_blog->id` anymore.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40646#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list