Skip to content

Instantly share code, notes, and snippets.

@spacedmonkey
Created September 8, 2017 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spacedmonkey/0edaa7e31e11f957c2fb16bf4d11c97a to your computer and use it in GitHub Desktop.
Save spacedmonkey/0edaa7e31e11f957c2fb16bf4d11c97a to your computer and use it in GitHub Desktop.
$properties = array( 'blogname', 'siteurl', 'post_count', 'home' );
foreach ( $properties as $property ) {
add_action("add_option_".$property,"add_option_site_meta" 99, 2);
add_action("delete_option_".$property,"delete_option_site_meta" 99, 1);
add_action("update_option_".$property,"update_option_site_meta" 99, 3);
}
function delete_option_site_meta( $option ){
delete_site_meta(get_current_blog_id(), $option);
}
function add_option_site_meta($option, $value){
add_site_meta(get_current_blog_id(), $option, $value);
}
function update_option_site_meta($option,$old_value, $value){
update_site_meta(get_current_blog_id(), $option, $value);
}
private function get_details() {
$properties = array( 'blogname', 'siteurl', 'post_count', 'home' );
$details = new stdClass();
if ( is_site_meta_supported() ) {
foreach ( $properties as $property ) {
if ( false === ( $value = get_site_meta( $this->blog_id, $property, true ) ) ) {
switch_to_blog( $this->blog_id );
$value = get_option( $property );
restore_current_blog();
add_site_meta( $this->blog_id, $property, $value );
}
$details->$property = $value;
}
} else {
$details = wp_cache_get( $this->blog_id, 'site-details' );
if ( false === $details ) {
switch_to_blog( $this->blog_id );
// Create a raw copy of the object for backwards compatibility with the filter below.
foreach ( get_object_vars( $this ) as $key => $value ) {
$details->$key = $value;
}
foreach ( $properties as $property ) {
$details->$property = get_option( $property );
}
restore_current_blog();
wp_cache_set( $this->blog_id, $details, 'site-details' );
}
}
/** This filter is documented in wp-includes/ms-blogs.php */
$details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' );
/**
* Filters a site's extended properties.
*
* @since 4.6.0
*
* @param stdClass $details The site details.
*/
$details = apply_filters( 'site_details', $details );
return $details;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment