Make WordPress Core

Ticket #37923: 37923.13.diff

File 37923.13.diff, 15.2 KB (added by spacedmonkey, 7 years ago)
  • src/wp-admin/includes/ms.php

     
    135135                        $wpdb->query( "DROP TABLE IF EXISTS `$table`" );
    136136                }
    137137
     138                if ( is_site_meta_supported() ) {
     139                        $blog_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->blogmeta WHERE blog_id = %d ", $blog_id ) );
     140                        foreach ( $blog_meta_ids as $mid ) {
     141                                delete_metadata_by_mid( 'blog', $mid );
     142                        }
     143                }
     144
    138145                $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
    139146
    140147                /**
  • src/wp-admin/includes/schema.php

     
    267267  PRIMARY KEY  (blog_id),
    268268  KEY db_version (db_version)
    269269) $charset_collate;
     270CREATE TABLE $wpdb->blogmeta (
     271  meta_id bigint(20) unsigned NOT NULL auto_increment,
     272  blog_id bigint(20) signed NOT NULL default '0',
     273  meta_key varchar(255) default NULL,
     274  meta_value longtext,
     275  PRIMARY KEY  (meta_id),
     276  KEY term_id (term_id),
     277  KEY meta_key (meta_key($max_index_length))
     278) $charset_collate;
    270279CREATE TABLE $wpdb->registration_log (
    271280  ID bigint(20) NOT NULL auto_increment,
    272281  email varchar(255) NOT NULL default '',
  • src/wp-admin/includes/upgrade.php

     
    21332133                        }
    21342134                }
    21352135        }
     2136
     2137        // 4.9
     2138        if ( $wp_current_db_version < 40001 ) {
     2139                $network_id = get_main_network_id();
     2140                delete_network_option( $network_id, 'site_meta_supported' );
     2141                is_site_meta_supported();
     2142        }
    21362143}
    21372144
    21382145//
  • src/wp-includes/class-wp-site-query.php

     
    288288
    289289                // Prime site network caches.
    290290                if ( $this->query_vars['update_site_cache'] ) {
    291                         _prime_site_caches( $site_ids );
     291                        _prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache'] );
    292292                }
    293293
    294294                // Fetch full site objects from the primed cache.
  • src/wp-includes/functions.php

     
    47044704}
    47054705
    47064706/**
     4707 * Determines whether site meta is enabled.
     4708 *
     4709 * This function checks whether the 'blogmeta' database table exists. The result is saved as
     4710 * a setting for the main network, making it essentially a global setting. Subsequent requests
     4711 * will refer to this setting instead of running the query. The $force parameter can be used
     4712 * to bypass the setting, and reset it accordingly, however this is not recommended.
     4713 *
     4714 * The 'is_site_meta_supported' filter can be used to bypass the database checks completely.
     4715 *
     4716 * @since 4.9.0
     4717 *
     4718 * @global wpdb $wpdb WordPress database abstraction object.
     4719 *
     4720 * @return bool True if site meta is supported, false otherwise.
     4721 */
     4722function is_site_meta_supported() {
     4723        global $wpdb;
     4724
     4725        if ( ! is_multisite() ) {
     4726                return false;
     4727        }
     4728
     4729        $network_id = get_main_network_id();
     4730
     4731        if ( false === ( $supported = get_network_option( $network_id, 'site_meta_supported', false ) ) ) {
     4732                $supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0;
     4733
     4734                update_network_option( $network_id, 'site_meta_supported', $supported );
     4735        }
     4736
     4737        return (bool) $supported;
     4738}
     4739
     4740/**
    47074741 * gmt_offset modification for smart timezone handling.
    47084742 *
    47094743 * Overrides the gmt_offset option if we have a timezone_string available.
  • src/wp-includes/load.php

     
    567567        }
    568568
    569569        if ( function_exists( 'wp_cache_add_global_groups' ) ) {
    570                 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
     570                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'blog_meta' ) );
    571571                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    572572        }
    573573}
  • src/wp-includes/ms-blogs.php

     
    474474        wp_cache_delete( $domain_path_key, 'blog-id-cache' );
    475475        wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
    476476        wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
     477        wp_cache_delete( $blog_id, 'blog_meta' );
    477478
    478479        /**
    479480         * Fires immediately after a site has been removed from the object cache.
     
    585586 *
    586587 * @param array $sites Array of site objects.
    587588 */
    588 function update_site_cache( $sites ) {
     589function update_site_cache( $sites, $update_meta_cache = true ) {
    589590        if ( ! $sites ) {
    590591                return;
    591592        }
    592 
     593        $site_ids = array();
    593594        foreach ( $sites as $site ) {
     595                $site_ids[] = $site->blog_id;
    594596                wp_cache_add( $site->blog_id, $site, 'sites' );
    595597                wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' );
    596598        }
     599
     600        if ( $update_meta_cache ) {
     601                update_sitemeta_cache( $site_ids );
     602        }
     603}
     604
     605/**
     606 * Updates metadata cache for list of site IDs.
     607 *
     608 * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache.
     609 * Subsequent calls to `get_site_meta()` will not need to query the database.
     610 *
     611 * @since 4.9.0
     612 *
     613 * @param array $site_ids List of site IDs.
     614 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
     615 */
     616function update_sitemeta_cache( $site_ids ) {
     617        if ( ! is_site_meta_supported() ) {
     618                return false;
     619        }
     620
     621        return update_meta_cache( 'blog', $site_ids );
    597622}
    598623
    599624/**
     
    658683        return $query->query( $args );
    659684}
    660685
     686
    661687/**
    662688 * Retrieve option value for a given blog id based on name of option.
    663689 *
     
    796822        return $return;
    797823}
    798824
     825
     826
     827/**
     828 * Add meta data field to a site.
     829 *
     830 * Site meta data is called "Custom Fields" on the Administration Screen.
     831 *
     832 * @since 4.9.0
     833 *
     834 * @param int    $site_id    Site ID.
     835 * @param string $meta_key   Metadata name.
     836 * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
     837 * @param bool   $unique     Optional. Whether the same key should not be added.
     838 *                           Default false.
     839 * @return int|false Meta ID on success, false on failure.
     840 */
     841function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
     842        // Bail if site meta table is not installed.
     843        if ( ! is_site_meta_supported() ) {
     844                return false;
     845        }
     846
     847        $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
     848
     849        // Bust site query cache.
     850        if ( $added ) {
     851                // @todo use clean_blog_cache here
     852                wp_cache_set( 'last_changed', microtime(), 'sites' );
     853        }
     854
     855        return $added;
     856}
     857
     858/**
     859 * Remove metadata matching criteria from a site.
     860 *
     861 * You can match based on the key, or key and value. Removing based on key and
     862 * value, will keep from removing duplicate metadata with the same key. It also
     863 * allows removing all metadata matching key, if needed.
     864 *
     865 * @since 4.9.0
     866 *
     867 * @param int    $site_id    Site ID.
     868 * @param string $meta_key   Metadata name.
     869 * @param mixed  $meta_value Optional. Metadata value. Must be serializable if
     870 *                           non-scalar. Default empty.
     871 * @return bool True on success, false on failure.
     872 */
     873function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
     874        // Bail if site meta table is not installed.
     875        if ( ! is_site_meta_supported() ) {
     876                return false;
     877        }
     878
     879        $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
     880
     881        // Bust site query cache.
     882        if ( $deleted ) {
     883                // @todo use clean_blog_cache here
     884                wp_cache_set( 'last_changed', microtime(), 'sites' );
     885        }
     886
     887        return $deleted;
     888}
     889
     890/**
     891 * Retrieve site meta field for a site.
     892 *
     893 * @since 4.9.0
     894 *
     895 * @param int    $site_id Site ID.
     896 * @param string $key     Optional. The meta key to retrieve. By default, returns
     897 *                        data for all keys. Default empty.
     898 * @param bool   $single  Optional. Whether to return a single value. Default false.
     899 * @return mixed Will be an array if $single is false. Will be value of meta data
     900 *               field if $single is true.
     901 */
     902function get_site_meta( $site_id, $key = '', $single = false ) {
     903        // Bail if site meta table is not installed.
     904        if ( ! is_site_meta_supported() ) {
     905                return false;
     906        }
     907
     908        return get_metadata( 'blog', $site_id, $key, $single );
     909}
     910
     911/**
     912 * Update site meta field based on site ID.
     913 *
     914 * Use the $prev_value parameter to differentiate between meta fields with the
     915 * same key and site ID.
     916 *
     917 * If the meta field for the site does not exist, it will be added.
     918 *
     919 * @since 4.9.0
     920 *
     921 * @param int    $site_id    Site ID.
     922 * @param string $meta_key   Metadata key.
     923 * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
     924 * @param mixed  $prev_value Optional. Previous value to check before removing.
     925 *                           Default empty.
     926 * @return int|bool Meta ID if the key didn't exist, true on successful update,
     927 *                  false on failure.
     928 */
     929function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) {
     930        // Bail if site meta table is not installed.
     931        if ( ! is_site_meta_supported() ) {
     932                return false;
     933        }
     934
     935        $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
     936
     937        // Bust site query cache.
     938        if ( $updated ) {
     939                // @todo use clean_blog_cache here
     940                wp_cache_set( 'last_changed', microtime(), 'sites' );
     941        }
     942
     943        return $updated;
     944}
     945
     946/**
     947 * Delete everything from site meta matching meta key.
     948 *
     949 * @since 4.9.0
     950 *
     951 * @param string $meta_key Metadata key to search for when deleting.
     952 * @return bool Whether the site meta key was deleted from the database.
     953 */
     954function delete_site_meta_by_key( $meta_key ) {
     955        // Bail if site meta table is not installed.
     956        if ( ! is_site_meta_supported() ) {
     957                return false;
     958        }
     959
     960        $deleted = delete_metadata( 'blog', null, $meta_key, '', true );
     961
     962        // Bust site query cache.
     963        if ( $deleted ) {
     964                // @todo use clean_blog_cache here
     965                wp_cache_set( 'last_changed', microtime(), 'sites' );
     966        }
     967
     968        return $deleted;
     969}
     970
    799971/**
    800972 * Switch the current blog.
    801973 *
     
    8691041                        if ( is_array( $global_groups ) ) {
    8701042                                wp_cache_add_global_groups( $global_groups );
    8711043                        } else {
    872                                 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );
     1044                                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
    8731045                        }
    8741046                        wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    8751047                }
     
    9371109                        if ( is_array( $global_groups ) ) {
    9381110                                wp_cache_add_global_groups( $global_groups );
    9391111                        } else {
    940                                 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );
     1112                                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
    9411113                        }
    9421114                        wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    9431115                }
  • src/wp-includes/version.php

     
    1111 *
    1212 * @global int $wp_db_version
    1313 */
    14 $wp_db_version = 38590;
     14$wp_db_version = 40001;
    1515
    1616/**
    1717 * Holds the TinyMCE version
  • src/wp-includes/wp-db.php

     
    400400        public $blogs;
    401401
    402402        /**
     403         * Multisite Blog Metadata table
     404         *
     405         * @since 4.9.0
     406         * @var string
     407         */
     408        public $blogmeta;
     409
     410        /**
    403411         * Multisite Blog Versions table
    404412         *
    405413         * @since 3.0.0
  • src/wp-settings.php

     
    9595// Load early WordPress files.
    9696require( ABSPATH . WPINC . '/compat.php' );
    9797require( ABSPATH . WPINC . '/class-wp-list-util.php' );
     98require( ABSPATH . WPINC . '/formatting.php' );
     99require( ABSPATH . WPINC . '/meta.php' );
    98100require( ABSPATH . WPINC . '/functions.php' );
    99101require( ABSPATH . WPINC . '/class-wp-matchesmapregex.php' );
    100102require( ABSPATH . WPINC . '/class-wp.php' );
     
    143145// Load most of WordPress.
    144146require( ABSPATH . WPINC . '/class-wp-walker.php' );
    145147require( ABSPATH . WPINC . '/class-wp-ajax-response.php' );
    146 require( ABSPATH . WPINC . '/formatting.php' );
    147148require( ABSPATH . WPINC . '/capabilities.php' );
    148149require( ABSPATH . WPINC . '/class-wp-roles.php' );
    149150require( ABSPATH . WPINC . '/class-wp-role.php' );
     
    158159require( ABSPATH . WPINC . '/class-wp-user-query.php' );
    159160require( ABSPATH . WPINC . '/class-wp-session-tokens.php' );
    160161require( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' );
    161 require( ABSPATH . WPINC . '/meta.php' );
    162162require( ABSPATH . WPINC . '/class-wp-meta-query.php' );
    163163require( ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php' );
    164164require( ABSPATH . WPINC . '/general-template.php' );
  • tests/phpunit/includes/testcase.php

     
    328328                        $wp_object_cache->__remoteset();
    329329                }
    330330                wp_cache_flush();
    331                 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );
     331                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details', 'blog_meta' ) );
    332332                wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
    333333        }
    334334