Multisite: After [37918] add support for retrieving custom site properties set by the site_details
filter.
The behaviour was previously possible with the `blog_details` filter and `get_blog_details()` function. The former is deprecated since [38936]. This change adjusts the magic methods of `WP_Site` to also check if `$key` exists in `WP_Site::get_details()`. Fixes #40458. git-svn-id: https://develop.svn.wordpress.org/trunk@40478 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
43d7215a5c
commit
94ad421722
@ -240,11 +240,15 @@ final class WP_Site {
|
||||
case 'siteurl':
|
||||
case 'post_count':
|
||||
case 'home':
|
||||
default: // Custom properties added by 'site_details' filter.
|
||||
if ( ! did_action( 'ms_loaded' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$details = $this->get_details();
|
||||
return $details->$key;
|
||||
if ( isset( $details->$key ) ) {
|
||||
return $details->$key;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -275,6 +279,15 @@ final class WP_Site {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
default: // Custom properties added by 'site_details' filter.
|
||||
if ( ! did_action( 'ms_loaded' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$details = $this->get_details();
|
||||
if ( isset( $details->$key ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -144,6 +144,49 @@ class Tests_Multisite_Site_Details extends WP_UnitTestCase {
|
||||
|
||||
$this->assertNotFalse( $cached_details );
|
||||
}
|
||||
|
||||
public function test_site_details_filter_with_blogname() {
|
||||
add_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
|
||||
$site = get_site();
|
||||
$blogname = $site->blogname;
|
||||
remove_filter( 'site_details', array( $this, '_filter_site_details_blogname' ) );
|
||||
|
||||
$this->assertSame( 'Foo Bar', $blogname );
|
||||
}
|
||||
|
||||
public function _filter_site_details_blogname( $details ) {
|
||||
$details->blogname = 'Foo Bar';
|
||||
return $details;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40458
|
||||
*/
|
||||
public function test_site_details_filter_with_custom_value_isetter() {
|
||||
add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
|
||||
$site = get_site();
|
||||
$custom_value_isset = isset( $site->custom_value );
|
||||
remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
|
||||
|
||||
$this->assertTrue( $custom_value_isset );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 40458
|
||||
*/
|
||||
public function test_site_details_filter_with_custom_value_getter() {
|
||||
add_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
|
||||
$site = get_site();
|
||||
$custom_value = $site->custom_value;
|
||||
remove_filter( 'site_details', array( $this, '_filter_site_details_custom_value' ) );
|
||||
|
||||
$this->assertSame( 'foo', $custom_value );
|
||||
}
|
||||
|
||||
public function _filter_site_details_custom_value( $details ) {
|
||||
$details->custom_value = 'foo';
|
||||
return $details;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
Loading…
Reference in New Issue
Block a user