Multisite: Move site-specific metadata integrations from the wrapper functions to the low-level Meta API functions.
This complements the work in [43729] and prepares site metadata for future REST API support. Props spacedmonkey. Fixes #45091. See #44467. Built from https://develop.svn.wordpress.org/trunk@44468 git-svn-id: http://core.svn.wordpress.org/trunk@44299 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
035877708d
commit
321bdfbacf
|
@ -1329,5 +1329,5 @@ function populate_site_meta( $site_id, array $meta = array() ) {
|
||||||
|
|
||||||
$wpdb->query( "INSERT INTO $wpdb->blogmeta ( blog_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
$wpdb->query( "INSERT INTO $wpdb->blogmeta ( blog_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||||
|
|
||||||
wp_cache_set( 'last_changed', microtime(), 'sites' );
|
wp_cache_set_sites_last_changed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -756,10 +756,6 @@ function update_site_cache( $sites, $update_meta_cache = true ) {
|
||||||
* @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
|
* @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
|
||||||
*/
|
*/
|
||||||
function update_sitemeta_cache( $site_ids ) {
|
function update_sitemeta_cache( $site_ids ) {
|
||||||
if ( ! is_site_meta_supported() ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return update_meta_cache( 'blog', $site_ids );
|
return update_meta_cache( 'blog', $site_ids );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1475,21 +1471,7 @@ function update_blog_option( $id, $option, $value, $deprecated = null ) {
|
||||||
* @return int|false Meta ID on success, false on failure.
|
* @return int|false Meta ID on success, false on failure.
|
||||||
*/
|
*/
|
||||||
function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
|
function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
|
||||||
// Bail if site meta table is not installed.
|
return add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
|
||||||
if ( ! is_site_meta_supported() ) {
|
|
||||||
/* translators: %s: database table name */
|
|
||||||
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
|
|
||||||
|
|
||||||
// Bust site query cache.
|
|
||||||
if ( $added ) {
|
|
||||||
wp_cache_set( 'last_changed', microtime(), 'sites' );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $added;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1508,21 +1490,7 @@ function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
|
||||||
* @return bool True on success, false on failure.
|
* @return bool True on success, false on failure.
|
||||||
*/
|
*/
|
||||||
function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
|
function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
|
||||||
// Bail if site meta table is not installed.
|
return delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
|
||||||
if ( ! is_site_meta_supported() ) {
|
|
||||||
/* translators: %s: database table name */
|
|
||||||
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
|
|
||||||
|
|
||||||
// Bust site query cache.
|
|
||||||
if ( $deleted ) {
|
|
||||||
wp_cache_set( 'last_changed', microtime(), 'sites' );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $deleted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1538,13 +1506,6 @@ function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
|
||||||
* field if $single is true.
|
* field if $single is true.
|
||||||
*/
|
*/
|
||||||
function get_site_meta( $site_id, $key = '', $single = false ) {
|
function get_site_meta( $site_id, $key = '', $single = false ) {
|
||||||
// Bail if site meta table is not installed.
|
|
||||||
if ( ! is_site_meta_supported() ) {
|
|
||||||
/* translators: %s: database table name */
|
|
||||||
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return get_metadata( 'blog', $site_id, $key, $single );
|
return get_metadata( 'blog', $site_id, $key, $single );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1567,21 +1528,7 @@ function get_site_meta( $site_id, $key = '', $single = false ) {
|
||||||
* false on failure.
|
* false on failure.
|
||||||
*/
|
*/
|
||||||
function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) {
|
function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) {
|
||||||
// Bail if site meta table is not installed.
|
return update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
|
||||||
if ( ! is_site_meta_supported() ) {
|
|
||||||
/* translators: %s: database table name */
|
|
||||||
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
|
|
||||||
|
|
||||||
// Bust site query cache.
|
|
||||||
if ( $updated ) {
|
|
||||||
wp_cache_set( 'last_changed', microtime(), 'sites' );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $updated;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1593,21 +1540,7 @@ function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' )
|
||||||
* @return bool Whether the site meta key was deleted from the database.
|
* @return bool Whether the site meta key was deleted from the database.
|
||||||
*/
|
*/
|
||||||
function delete_site_meta_by_key( $meta_key ) {
|
function delete_site_meta_by_key( $meta_key ) {
|
||||||
// Bail if site meta table is not installed.
|
return delete_metadata( 'blog', null, $meta_key, '', true );
|
||||||
if ( ! is_site_meta_supported() ) {
|
|
||||||
/* translators: %s: database table name */
|
|
||||||
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$deleted = delete_metadata( 'blog', null, $meta_key, '', true );
|
|
||||||
|
|
||||||
// Bust site query cache.
|
|
||||||
if ( $deleted ) {
|
|
||||||
wp_cache_set( 'last_changed', microtime(), 'sites' );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $deleted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2309,3 +2242,32 @@ function wp_update_blog_public_option_on_site_update( $site_id, $public ) {
|
||||||
|
|
||||||
update_blog_option( $site_id, 'blog_public', $public );
|
update_blog_option( $site_id, 'blog_public', $public );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the last changed time for the 'sites' cache group.
|
||||||
|
*
|
||||||
|
* @since 5.1.0
|
||||||
|
*/
|
||||||
|
function wp_cache_set_sites_last_changed() {
|
||||||
|
wp_cache_set( 'last_changed', microtime(), 'sites' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aborts calls to site meta if it is not supported.
|
||||||
|
*
|
||||||
|
* @since 5.1.0
|
||||||
|
*
|
||||||
|
* @global wpdb $wpdb WordPress database abstraction object.
|
||||||
|
*
|
||||||
|
* @param mixed $check Skip-value for whether to proceed site meta function execution.
|
||||||
|
* @return mixed Original value of $check, or false if site meta is not supported.
|
||||||
|
*/
|
||||||
|
function wp_check_site_meta_support_prefilter( $check ) {
|
||||||
|
if ( ! is_site_meta_supported() ) {
|
||||||
|
/* translators: %s: database table name */
|
||||||
|
_doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.1.0' );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $check;
|
||||||
|
}
|
||||||
|
|
|
@ -53,6 +53,19 @@ add_action( 'wp_initialize_site', 'newblog_notify_siteadmin', 100, 1 );
|
||||||
add_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10, 1 );
|
add_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10, 1 );
|
||||||
add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 );
|
add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 );
|
||||||
|
|
||||||
|
// Site meta
|
||||||
|
add_action( 'added_blog_meta', 'wp_cache_set_sites_last_changed' );
|
||||||
|
add_action( 'updated_blog_meta', 'wp_cache_set_sites_last_changed' );
|
||||||
|
add_action( 'deleted_blog_meta', 'wp_cache_set_sites_last_changed' );
|
||||||
|
add_filter( 'get_blog_metadata', 'wp_check_site_meta_support_prefilter' );
|
||||||
|
add_filter( 'add_blog_metadata', 'wp_check_site_meta_support_prefilter' );
|
||||||
|
add_filter( 'update_blog_metadata', 'wp_check_site_meta_support_prefilter' );
|
||||||
|
add_filter( 'delete_blog_metadata', 'wp_check_site_meta_support_prefilter' );
|
||||||
|
add_filter( 'get_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
|
||||||
|
add_filter( 'update_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
|
||||||
|
add_filter( 'delete_blog_metadata_by_mid', 'wp_check_site_meta_support_prefilter' );
|
||||||
|
add_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' );
|
||||||
|
|
||||||
// Register Nonce
|
// Register Nonce
|
||||||
add_action( 'signup_hidden_fields', 'signup_nonce_fields' );
|
add_action( 'signup_hidden_fields', 'signup_nonce_fields' );
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.1-alpha-44467';
|
$wp_version = '5.1-alpha-44468';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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