Multisite: Ensure a consistent `WP_Site` return from `get_site_by_path()`.
It is possible to short circuit `get_site_by_path()` using the `pre_get_site_by_path` filter. When this happens and a standard site object is provided, we can make sure it is upgraded to a proper `WP_Site` object before passing it on. Props flixos90. Fixes #37053. Built from https://develop.svn.wordpress.org/trunk@38681 git-svn-id: http://core.svn.wordpress.org/trunk@38624 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0dc18d3ffb
commit
5c038aefb3
|
@ -137,13 +137,14 @@ function get_network_by_path( $domain, $path, $segments = null ) {
|
||||||
* Retrieve a site object by its domain and path.
|
* Retrieve a site object by its domain and path.
|
||||||
*
|
*
|
||||||
* @since 3.9.0
|
* @since 3.9.0
|
||||||
|
* @since 4.7.0 Updated to always return a `WP_Site` object.
|
||||||
*
|
*
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
* @global wpdb $wpdb WordPress database abstraction object.
|
||||||
*
|
*
|
||||||
* @param string $domain Domain to check.
|
* @param string $domain Domain to check.
|
||||||
* @param string $path Path to check.
|
* @param string $path Path to check.
|
||||||
* @param int|null $segments Path segments to use. Defaults to null, or the full path.
|
* @param int|null $segments Path segments to use. Defaults to null, or the full path.
|
||||||
* @return object|false Site object if successful. False when no site is found.
|
* @return WP_Site|false Site object if successful. False when no site is found.
|
||||||
*/
|
*/
|
||||||
function get_site_by_path( $domain, $path, $segments = null ) {
|
function get_site_by_path( $domain, $path, $segments = null ) {
|
||||||
$path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );
|
$path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );
|
||||||
|
@ -186,15 +187,18 @@ function get_site_by_path( $domain, $path, $segments = null ) {
|
||||||
*
|
*
|
||||||
* @since 3.9.0
|
* @since 3.9.0
|
||||||
*
|
*
|
||||||
* @param null|bool|object $site Site value to return by path.
|
* @param null|bool|WP_Site $site Site value to return by path.
|
||||||
* @param string $domain The requested domain.
|
* @param string $domain The requested domain.
|
||||||
* @param string $path The requested path, in full.
|
* @param string $path The requested path, in full.
|
||||||
* @param int|null $segments The suggested number of paths to consult.
|
* @param int|null $segments The suggested number of paths to consult.
|
||||||
* Default null, meaning the entire path was to be consulted.
|
* Default null, meaning the entire path was to be consulted.
|
||||||
* @param array $paths The paths to search for, based on $path and $segments.
|
* @param array $paths The paths to search for, based on $path and $segments.
|
||||||
*/
|
*/
|
||||||
$pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths );
|
$pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths );
|
||||||
if ( null !== $pre ) {
|
if ( null !== $pre ) {
|
||||||
|
if ( false !== $pre && ! $pre instanceof WP_Site ) {
|
||||||
|
$pre = new WP_Site( $pre );
|
||||||
|
}
|
||||||
return $pre;
|
return $pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7-alpha-38680';
|
$wp_version = '4.7-alpha-38681';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue