diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index d148a9603d..97b6292cf1 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -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 - wp_cache_set( 'last_changed', microtime(), 'sites' ); + wp_cache_set_sites_last_changed(); } diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index 66380f0970..6a2709f2f9 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -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. */ function update_sitemeta_cache( $site_ids ) { - if ( ! is_site_meta_supported() ) { - return false; - } - 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. */ function add_site_meta( $site_id, $meta_key, $meta_value, $unique = 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; - } - - $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; + return add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique ); } /** @@ -1508,21 +1490,7 @@ function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) { * @return bool True on success, false on failure. */ function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) { - // 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; - } - - $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; + return delete_metadata( 'blog', $site_id, $meta_key, $meta_value ); } /** @@ -1538,13 +1506,6 @@ function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) { * field if $single is true. */ 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 ); } @@ -1567,21 +1528,7 @@ function get_site_meta( $site_id, $key = '', $single = false ) { * false on failure. */ function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) { - // 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; - } - - $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; + return update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value ); } /** @@ -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. */ function delete_site_meta_by_key( $meta_key ) { - // 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; - } - - $deleted = delete_metadata( 'blog', null, $meta_key, '', true ); - - // Bust site query cache. - if ( $deleted ) { - wp_cache_set( 'last_changed', microtime(), 'sites' ); - } - - return $deleted; + return delete_metadata( 'blog', null, $meta_key, '', true ); } /** @@ -2309,3 +2242,32 @@ function wp_update_blog_public_option_on_site_update( $site_id, $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; +} diff --git a/wp-includes/ms-default-filters.php b/wp-includes/ms-default-filters.php index 93fbca193c..a9658398be 100644 --- a/wp-includes/ms-default-filters.php +++ b/wp-includes/ms-default-filters.php @@ -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( '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 add_action( 'signup_hidden_fields', 'signup_nonce_fields' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 67cd576980..7fc128613d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @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.