mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-16 10:34:26 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@38681 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -208,9 +208,32 @@ class Tests_Multisite_Bootstrap extends WP_UnitTestCase {
|
||||
$this->assertEqualSetsWithIndex( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37053
|
||||
*/
|
||||
public function test_get_site_by_path_returns_wp_site() {
|
||||
add_filter( 'pre_get_site_by_path', array( $this, 'filter_pre_get_site_by_path' ), 10, 3 );
|
||||
|
||||
$site = get_site_by_path( 'example.com', '/foo/' );
|
||||
|
||||
remove_filter( 'pre_get_site_by_path', array( $this, 'filter_pre_get_site_by_path' ), 10 );
|
||||
|
||||
$this->assertInstanceOf( 'WP_Site', $site );
|
||||
}
|
||||
|
||||
public function filter_path_segments_to_two() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function filter_pre_get_site_by_path( $site, $domain, $path ) {
|
||||
$site = new stdClass();
|
||||
$site->blog_id = 100;
|
||||
$site->domain = $domain;
|
||||
$site->path = $path;
|
||||
$site->site_id = 1;
|
||||
|
||||
return $site;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
Reference in New Issue
Block a user