Make WordPress Core

Ticket #37923: 37923.17.diff

File 37923.17.diff, 37.0 KB (added by flixos90, 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) NOT NULL default '0',
     273  meta_key varchar(255) default NULL,
     274  meta_value longtext,
     275  PRIMARY KEY  (meta_id),
     276  KEY meta_key (meta_key($max_index_length)),
     277  KEY blog_id (blog_id)
     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        // 5.0
     2138        if ( $wp_current_db_version < 42836 ) {
     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

     
    9292         *
    9393         * @since 4.6.0
    9494         * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
     95         * @since 5.0.0 Introduced the 'update_site_meta_cache' parameter.
    9596         *
    9697         * @param string|array $query {
    9798         *     Optional. Array or query string of site query parameters. Default empty.
    9899         *
    99          *     @type array        $site__in          Array of site IDs to include. Default empty.
    100          *     @type array        $site__not_in      Array of site IDs to exclude. Default empty.
    101          *     @type bool         $count             Whether to return a site count (true) or array of site objects.
    102          *                                           Default false.
    103          *     @type array        $date_query        Date query clauses to limit sites by. See WP_Date_Query.
    104          *                                           Default null.
    105          *     @type string       $fields            Site fields to return. Accepts 'ids' (returns an array of site IDs)
    106          *                                           or empty (returns an array of complete site objects). Default empty.
    107          *     @type int          $ID                A site ID to only return that site. Default empty.
    108          *     @type int          $number            Maximum number of sites to retrieve. Default 100.
    109          *     @type int          $offset            Number of sites to offset the query. Used to build LIMIT clause.
    110          *                                           Default 0.
    111          *     @type bool         $no_found_rows     Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
    112          *     @type string|array $orderby           Site status or array of statuses. Accepts 'id', 'domain', 'path',
    113          *                                           'network_id', 'last_updated', 'registered', 'domain_length',
    114          *                                           'path_length', 'site__in' and 'network__in'. Also accepts false,
    115          *                                           an empty array, or 'none' to disable `ORDER BY` clause.
    116          *                                           Default 'id'.
    117          *     @type string       $order             How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
    118          *     @type int          $network_id        Limit results to those affiliated with a given network ID. If 0,
    119          *                                           include all networks. Default 0.
    120          *     @type array        $network__in       Array of network IDs to include affiliated sites for. Default empty.
    121          *     @type array        $network__not_in   Array of network IDs to exclude affiliated sites for. Default empty.
    122          *     @type string       $domain            Limit results to those affiliated with a given domain. Default empty.
    123          *     @type array        $domain__in        Array of domains to include affiliated sites for. Default empty.
    124          *     @type array        $domain__not_in    Array of domains to exclude affiliated sites for. Default empty.
    125          *     @type string       $path              Limit results to those affiliated with a given path. Default empty.
    126          *     @type array        $path__in          Array of paths to include affiliated sites for. Default empty.
    127          *     @type array        $path__not_in      Array of paths to exclude affiliated sites for. Default empty.
    128          *     @type int          $public            Limit results to public sites. Accepts '1' or '0'. Default empty.
    129          *     @type int          $archived          Limit results to archived sites. Accepts '1' or '0'. Default empty.
    130          *     @type int          $mature            Limit results to mature sites. Accepts '1' or '0'. Default empty.
    131          *     @type int          $spam              Limit results to spam sites. Accepts '1' or '0'. Default empty.
    132          *     @type int          $deleted           Limit results to deleted sites. Accepts '1' or '0'. Default empty.
    133          *     @type int          $lang_id           Limit results to a language ID. Default empty.
    134          *     @type array        $lang__in          Array of language IDs to include affiliated sites for. Default empty.
    135          *     @type array        $lang__not_in      Array of language IDs to exclude affiliated sites for. Default empty.
    136          *     @type string       $search            Search term(s) to retrieve matching sites for. Default empty.
    137          *     @type array        $search_columns    Array of column names to be searched. Accepts 'domain' and 'path'.
    138          *                                           Default empty array.
    139          *     @type bool         $update_site_cache Whether to prime the cache for found sites. Default true.
     100         *     @type array        $site__in               Array of site IDs to include. Default empty.
     101         *     @type array        $site__not_in           Array of site IDs to exclude. Default empty.
     102         *     @type bool         $count                  Whether to return a site count (true) or array of site objects.
     103         *                                                Default false.
     104         *     @type array        $date_query             Date query clauses to limit sites by. See WP_Date_Query.
     105         *                                                Default null.
     106         *     @type string       $fields                 Site fields to return. Accepts 'ids' (returns an array of site IDs)
     107         *                                                or empty (returns an array of complete site objects). Default empty.
     108         *     @type int          $ID                     A site ID to only return that site. Default empty.
     109         *     @type int          $number                 Maximum number of sites to retrieve. Default 100.
     110         *     @type int          $offset                 Number of sites to offset the query. Used to build LIMIT clause.
     111         *                                                Default 0.
     112         *     @type bool         $no_found_rows          Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
     113         *     @type string|array $orderby                Site status or array of statuses. Accepts 'id', 'domain', 'path',
     114         *                                                'network_id', 'last_updated', 'registered', 'domain_length',
     115         *                                                'path_length', 'site__in' and 'network__in'. Also accepts false,
     116         *                                                an empty array, or 'none' to disable `ORDER BY` clause.
     117         *                                                Default 'id'.
     118         *     @type string       $order                  How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
     119         *     @type int          $network_id             Limit results to those affiliated with a given network ID. If 0,
     120         *                                                include all networks. Default 0.
     121         *     @type array        $network__in            Array of network IDs to include affiliated sites for. Default empty.
     122         *     @type array        $network__not_in        Array of network IDs to exclude affiliated sites for. Default empty.
     123         *     @type string       $domain                 Limit results to those affiliated with a given domain. Default empty.
     124         *     @type array        $domain__in             Array of domains to include affiliated sites for. Default empty.
     125         *     @type array        $domain__not_in         Array of domains to exclude affiliated sites for. Default empty.
     126         *     @type string       $path                   Limit results to those affiliated with a given path. Default empty.
     127         *     @type array        $path__in               Array of paths to include affiliated sites for. Default empty.
     128         *     @type array        $path__not_in           Array of paths to exclude affiliated sites for. Default empty.
     129         *     @type int          $public                 Limit results to public sites. Accepts '1' or '0'. Default empty.
     130         *     @type int          $archived               Limit results to archived sites. Accepts '1' or '0'. Default empty.
     131         *     @type int          $mature                 Limit results to mature sites. Accepts '1' or '0'. Default empty.
     132         *     @type int          $spam                   Limit results to spam sites. Accepts '1' or '0'. Default empty.
     133         *     @type int          $deleted                Limit results to deleted sites. Accepts '1' or '0'. Default empty.
     134         *     @type int          $lang_id                Limit results to a language ID. Default empty.
     135         *     @type array        $lang__in               Array of language IDs to include affiliated sites for. Default empty.
     136         *     @type array        $lang__not_in           Array of language IDs to exclude affiliated sites for. Default empty.
     137         *     @type string       $search                 Search term(s) to retrieve matching sites for. Default empty.
     138         *     @type array        $search_columns         Array of column names to be searched. Accepts 'domain' and 'path'.
     139         *                                                Default empty array.
     140         *     @type bool         $update_site_cache      Whether to prime the cache for found sites. Default true.
     141         *     @type bool         $update_site_meta_cache Whether to prime the metadata cache for found sites. Default true.
    140142         * }
    141143         */
    142144        public function __construct( $query = '' ) {
    143145                $this->query_var_defaults = array(
    144                         'fields'            => '',
    145                         'ID'                => '',
    146                         'site__in'          => '',
    147                         'site__not_in'      => '',
    148                         'number'            => 100,
    149                         'offset'            => '',
    150                         'no_found_rows'     => true,
    151                         'orderby'           => 'id',
    152                         'order'             => 'ASC',
    153                         'network_id'        => 0,
    154                         'network__in'       => '',
    155                         'network__not_in'   => '',
    156                         'domain'            => '',
    157                         'domain__in'        => '',
    158                         'domain__not_in'    => '',
    159                         'path'              => '',
    160                         'path__in'          => '',
    161                         'path__not_in'      => '',
    162                         'public'            => null,
    163                         'archived'          => null,
    164                         'mature'            => null,
    165                         'spam'              => null,
    166                         'deleted'           => null,
    167                         'lang_id'           => null,
    168                         'lang__in'          => '',
    169                         'lang__not_in'      => '',
    170                         'search'            => '',
    171                         'search_columns'    => array(),
    172                         'count'             => false,
    173                         'date_query'        => null, // See WP_Date_Query
    174                         'update_site_cache' => true,
     146                        'fields'                 => '',
     147                        'ID'                     => '',
     148                        'site__in'               => '',
     149                        'site__not_in'           => '',
     150                        'number'                 => 100,
     151                        'offset'                 => '',
     152                        'no_found_rows'          => true,
     153                        'orderby'                => 'id',
     154                        'order'                  => 'ASC',
     155                        'network_id'             => 0,
     156                        'network__in'            => '',
     157                        'network__not_in'        => '',
     158                        'domain'                 => '',
     159                        'domain__in'             => '',
     160                        'domain__not_in'         => '',
     161                        'path'                   => '',
     162                        'path__in'               => '',
     163                        'path__not_in'           => '',
     164                        'public'                 => null,
     165                        'archived'               => null,
     166                        'mature'                 => null,
     167                        'spam'                   => null,
     168                        'deleted'                => null,
     169                        'lang_id'                => null,
     170                        'lang__in'               => '',
     171                        'lang__not_in'           => '',
     172                        'search'                 => '',
     173                        'search_columns'         => array(),
     174                        'count'                  => false,
     175                        'date_query'             => null, // See WP_Date_Query
     176                        'update_site_cache'      => true,
     177                        'update_site_meta_cache' => true,
    175178                );
    176179
    177180                if ( ! empty( $query ) ) {
     
    288291
    289292                // Prime site network caches.
    290293                if ( $this->query_vars['update_site_cache'] ) {
    291                         _prime_site_caches( $site_ids );
     294                        _prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache'] );
    292295                }
    293296
    294297                // Fetch full site objects from the primed cache.
  • src/wp-includes/functions.php

     
    47274727}
    47284728
    47294729/**
     4730 * Determines whether site meta is enabled.
     4731 *
     4732 * This function checks whether the 'blogmeta' database table exists. The result is saved as
     4733 * a setting for the main network, making it essentially a global setting. Subsequent requests
     4734 * will refer to this setting instead of running the query.
     4735 *
     4736 * @since 5.0.0
     4737 *
     4738 * @global wpdb $wpdb WordPress database abstraction object.
     4739 *
     4740 * @return bool True if site meta is supported, false otherwise.
     4741 */
     4742function is_site_meta_supported() {
     4743        global $wpdb;
     4744
     4745        if ( ! is_multisite() ) {
     4746                return false;
     4747        }
     4748
     4749        $network_id = get_main_network_id();
     4750
     4751        $supported = get_network_option( $network_id, 'site_meta_supported', false );
     4752        if ( false === $supported ) {
     4753                $supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0;
     4754
     4755                update_network_option( $network_id, 'site_meta_supported', $supported );
     4756        }
     4757
     4758        return (bool) $supported;
     4759}
     4760
     4761/**
    47304762 * gmt_offset modification for smart timezone handling.
    47314763 *
    47324764 * Overrides the gmt_offset option if we have a timezone_string available.
  • src/wp-includes/load.php

     
    581581        }
    582582
    583583        if ( function_exists( 'wp_cache_add_global_groups' ) ) {
    584                 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' ) );
     584                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' ) );
    585585                wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    586586        }
    587587
  • 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.
     
    560561 * Adds any sites from the given ids to the cache that do not already exist in cache.
    561562 *
    562563 * @since 4.6.0
     564 * @since 5.0.0 Introduced the `$update_meta_cache` parameter.
    563565 * @access private
    564566 *
    565567 * @see update_site_cache()
    566568 * @global wpdb $wpdb WordPress database abstraction object.
    567569 *
    568  * @param array $ids ID list.
     570 * @param array $ids               ID list.
     571 * @param bool  $update_meta_cache Optional. Whether to update the meta cache. Default true.
    569572 */
    570 function _prime_site_caches( $ids ) {
     573function _prime_site_caches( $ids, $update_meta_cache = true ) {
    571574        global $wpdb;
    572575
    573576        $non_cached_ids = _get_non_cached_ids( $ids, 'sites' );
    574577        if ( ! empty( $non_cached_ids ) ) {
    575578                $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) );
    576579
    577                 update_site_cache( $fresh_sites );
     580                update_site_cache( $fresh_sites, $update_meta_cache );
    578581        }
    579582}
    580583
     
    582585 * Updates sites in cache.
    583586 *
    584587 * @since 4.6.0
     588 * @since 5.0.0 Introduced the `$update_meta_cache` parameter.
    585589 *
    586  * @param array $sites Array of site objects.
     590 * @param array $sites             Array of site objects.
     591 * @param bool  $update_meta_cache Whether to update site meta cache. Default true.
    587592 */
    588 function update_site_cache( $sites ) {
     593function update_site_cache( $sites, $update_meta_cache = true ) {
    589594        if ( ! $sites ) {
    590595                return;
    591596        }
    592 
     597        $site_ids = array();
    593598        foreach ( $sites as $site ) {
     599                $site_ids[] = $site->blog_id;
    594600                wp_cache_add( $site->blog_id, $site, 'sites' );
    595601                wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' );
    596602        }
     603
     604        if ( $update_meta_cache ) {
     605                update_sitemeta_cache( $site_ids );
     606        }
     607}
     608
     609/**
     610 * Updates metadata cache for list of site IDs.
     611 *
     612 * Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache.
     613 * Subsequent calls to `get_site_meta()` will not need to query the database.
     614 *
     615 * @since 5.0.0
     616 *
     617 * @param array $site_ids List of site IDs.
     618 * @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
     619 */
     620function update_sitemeta_cache( $site_ids ) {
     621        if ( ! is_site_meta_supported() ) {
     622                return false;
     623        }
     624
     625        return update_meta_cache( 'blog', $site_ids );
    597626}
    598627
    599628/**
     
    797826}
    798827
    799828/**
     829 * Adds metadata to a site.
     830 *
     831 * @since 5.0.0
     832 *
     833 * @param int    $site_id    Site ID.
     834 * @param string $meta_key   Metadata name.
     835 * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
     836 * @param bool   $unique     Optional. Whether the same key should not be added.
     837 *                           Default false.
     838 * @return int|false Meta ID on success, false on failure.
     839 */
     840function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
     841        // Bail if site meta table is not installed.
     842        if ( ! is_site_meta_supported() ) {
     843                /* translators: %s: database table name */
     844                _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
     845                return false;
     846        }
     847
     848        $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
     849
     850        // Bust site query cache.
     851        if ( $added ) {
     852                wp_cache_set( 'last_changed', microtime(), 'sites' );
     853        }
     854
     855        return $added;
     856}
     857
     858/**
     859 * Removes 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 5.0.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                /* translators: %s: database table name */
     877                _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
     878                return false;
     879        }
     880
     881        $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
     882
     883        // Bust site query cache.
     884        if ( $deleted ) {
     885                wp_cache_set( 'last_changed', microtime(), 'sites' );
     886        }
     887
     888        return $deleted;
     889}
     890
     891/**
     892 * Retrieves metadata for a site.
     893 *
     894 * @since 5.0.0
     895 *
     896 * @param int    $site_id Site ID.
     897 * @param string $key     Optional. The meta key to retrieve. By default, returns
     898 *                        data for all keys. Default empty.
     899 * @param bool   $single  Optional. Whether to return a single value. Default false.
     900 * @return mixed Will be an array if $single is false. Will be value of meta data
     901 *               field if $single is true.
     902 */
     903function get_site_meta( $site_id, $key = '', $single = false ) {
     904        // Bail if site meta table is not installed.
     905        if ( ! is_site_meta_supported() ) {
     906                /* translators: %s: database table name */
     907                _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
     908                return false;
     909        }
     910
     911        return get_metadata( 'blog', $site_id, $key, $single );
     912}
     913
     914/**
     915 * Updates metadata for a site.
     916 *
     917 * Use the $prev_value parameter to differentiate between meta fields with the
     918 * same key and site ID.
     919 *
     920 * If the meta field for the site does not exist, it will be added.
     921 *
     922 * @since 5.0.0
     923 *
     924 * @param int    $site_id    Site ID.
     925 * @param string $meta_key   Metadata key.
     926 * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
     927 * @param mixed  $prev_value Optional. Previous value to check before removing.
     928 *                           Default empty.
     929 * @return int|bool Meta ID if the key didn't exist, true on successful update,
     930 *                  false on failure.
     931 */
     932function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) {
     933        // Bail if site meta table is not installed.
     934        if ( ! is_site_meta_supported() ) {
     935                /* translators: %s: database table name */
     936                _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
     937                return false;
     938        }
     939
     940        $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
     941
     942        // Bust site query cache.
     943        if ( $updated ) {
     944                wp_cache_set( 'last_changed', microtime(), 'sites' );
     945        }
     946
     947        return $updated;
     948}
     949
     950/**
     951 * Deletes everything from site meta matching meta key.
     952 *
     953 * @since 5.0.0
     954 *
     955 * @param string $meta_key Metadata key to search for when deleting.
     956 * @return bool Whether the site meta key was deleted from the database.
     957 */
     958function delete_site_meta_by_key( $meta_key ) {
     959        // Bail if site meta table is not installed.
     960        if ( ! is_site_meta_supported() ) {
     961                /* translators: %s: database table name */
     962                _doing_it_wrong( __FUNCTION__, sprintf( __( 'The %s table is not installed. Please run the network database upgrade.' ), $GLOBALS['wpdb']->blogmeta ), '5.0.0' );
     963                return false;
     964        }
     965
     966        $deleted = delete_metadata( 'blog', null, $meta_key, '', true );
     967
     968        // Bust site query cache.
     969        if ( $deleted ) {
     970                wp_cache_set( 'last_changed', microtime(), 'sites' );
     971        }
     972
     973        return $deleted;
     974}
     975
     976/**
    800977 * Switch the current blog.
    801978 *
    802979 * This function is useful if you need to pull posts, or other information,
     
    8691046                        if ( is_array( $global_groups ) ) {
    8701047                                wp_cache_add_global_groups( $global_groups );
    8711048                        } 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' ) );
     1049                                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' ) );
    8731050                        }
    8741051                        wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    8751052                }
     
    9371114                        if ( is_array( $global_groups ) ) {
    9381115                                wp_cache_add_global_groups( $global_groups );
    9391116                        } 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' ) );
     1117                                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' ) );
    9411118                        }
    9421119                        wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    9431120                }
  • src/wp-includes/version.php

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

     
    297297         */
    298298        var $ms_global_tables = array(
    299299                'blogs',
     300                'blogmeta',
    300301                'signups',
    301302                'site',
    302303                'sitemeta',
     
    414415        public $blogs;
    415416
    416417        /**
     418         * Multisite Blog Metadata table
     419         *
     420         * @since 5.0.0
     421         * @var string
     422         */
     423        public $blogmeta;
     424
     425        /**
    417426         * Multisite Blog Versions table
    418427         *
    419428         * @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
  • tests/phpunit/tests/multisite/siteMeta.php

     
     1<?php
     2
     3if ( is_multisite() ) :
     4
     5/**
     6 * @group ms-site
     7 * @group multisite
     8 * @group meta
     9 * @ticket 37923
     10 */
     11class Tests_Multisite_Site_Meta extends WP_UnitTestCase {
     12        protected static $site_id;
     13        protected static $site_id2;
     14        protected static $flag_was_set;
     15
     16        public static function wpSetUpBeforeClass( $factory ) {
     17                self::$site_id = $factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/' ) );
     18                self::$site_id2 = $factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/foo/' ) );
     19
     20                // Populate the main network flag as necessary.
     21                self::$flag_was_set = true;
     22                if ( false === get_network_option( get_main_network_id(), 'site_meta_supported', false ) ) {
     23                        self::$flag_was_set = false;
     24                        is_site_meta_supported();
     25                }
     26        }
     27
     28        public static function wpTearDownAfterClass() {
     29                // Delete the possibly previously populated main network flag.
     30                if ( ! self::$flag_was_set ) {
     31                        delete_network_option( get_main_network_id(), 'site_meta_supported' );
     32                }
     33
     34                wpmu_delete_blog( self::$site_id, true );
     35                wpmu_delete_blog( self::$site_id2, true );
     36
     37                wp_update_network_site_counts();
     38        }
     39
     40        public function test_is_site_meta_supported() {
     41                $this->assertTrue( is_site_meta_supported() );
     42        }
     43
     44        public function test_is_site_meta_supported_filtered() {
     45                add_filter( 'pre_site_option_site_meta_supported', '__return_zero' );
     46                $this->assertFalse( is_site_meta_supported() );
     47        }
     48
     49        public function test_add() {
     50                if ( ! is_site_meta_supported() ) {
     51                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     52                }
     53
     54                $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
     55                $this->assertSame( 'bar', get_site_meta( self::$site_id, 'foo', true ) );
     56        }
     57
     58        public function test_add_unique() {
     59                if ( ! is_site_meta_supported() ) {
     60                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     61                }
     62
     63                $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
     64                $this->assertFalse( add_site_meta( self::$site_id, 'foo', 'bar', true ) );
     65        }
     66
     67        public function test_delete() {
     68                if ( ! is_site_meta_supported() ) {
     69                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     70                }
     71
     72                add_site_meta( self::$site_id, 'foo', 'bar' );
     73
     74                $this->assertTrue( delete_site_meta( self::$site_id, 'foo' ) );
     75                $this->assertEmpty( get_site_meta( self::$site_id, 'foo', true ) );
     76        }
     77
     78        public function test_delete_with_invalid_meta_key_should_return_false() {
     79                if ( ! is_site_meta_supported() ) {
     80                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     81                }
     82
     83                $this->assertFalse( delete_site_meta( self::$site_id, 'foo' ) );
     84        }
     85
     86        public function test_delete_should_respect_meta_value() {
     87                if ( ! is_site_meta_supported() ) {
     88                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     89                }
     90
     91                add_site_meta( self::$site_id, 'foo', 'bar' );
     92                add_site_meta( self::$site_id, 'foo', 'baz' );
     93
     94                $this->assertTrue( delete_site_meta( self::$site_id, 'foo', 'bar' ) );
     95
     96                $metas = get_site_meta( self::$site_id, 'foo' );
     97                $this->assertSame( array( 'baz' ), $metas );
     98        }
     99
     100        public function test_get_with_no_key_should_fetch_all_keys() {
     101                if ( ! is_site_meta_supported() ) {
     102                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     103                }
     104
     105                add_site_meta( self::$site_id, 'foo', 'bar' );
     106                add_site_meta( self::$site_id, 'foo1', 'baz' );
     107
     108                $found = get_site_meta( self::$site_id );
     109                $expected = array(
     110                        'foo'  => array( 'bar' ),
     111                        'foo1' => array( 'baz' ),
     112                );
     113
     114                $this->assertEqualSets( $expected, $found );
     115        }
     116
     117        public function test_get_with_key_should_fetch_all_for_key() {
     118                if ( ! is_site_meta_supported() ) {
     119                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     120                }
     121
     122                add_site_meta( self::$site_id, 'foo', 'bar' );
     123                add_site_meta( self::$site_id, 'foo', 'baz' );
     124                add_site_meta( self::$site_id, 'foo1', 'baz' );
     125
     126                $found = get_site_meta( self::$site_id, 'foo' );
     127                $expected = array( 'bar', 'baz' );
     128
     129                $this->assertEqualSets( $expected, $found );
     130        }
     131
     132        public function test_get_should_respect_single_true() {
     133                if ( ! is_site_meta_supported() ) {
     134                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     135                }
     136
     137                add_site_meta( self::$site_id, 'foo', 'bar' );
     138                add_site_meta( self::$site_id, 'foo', 'baz' );
     139
     140                $found = get_site_meta( self::$site_id, 'foo', true );
     141                $this->assertSame( 'bar', $found );
     142        }
     143
     144        public function test_update_should_pass_to_add_when_no_value_exists_for_key() {
     145                if ( ! is_site_meta_supported() ) {
     146                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     147                }
     148
     149                $actual = update_site_meta( self::$site_id, 'foo', 'bar' );
     150                $this->assertInternalType( 'int', $actual );
     151                $this->assertNotEmpty( $actual );
     152
     153                $meta = get_site_meta( self::$site_id, 'foo', true );
     154                $this->assertSame( 'bar', $meta );
     155        }
     156
     157        public function test_update_should_return_true_when_updating_existing_value_for_key() {
     158                if ( ! is_site_meta_supported() ) {
     159                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     160                }
     161
     162                add_site_meta( self::$site_id, 'foo', 'bar' );
     163
     164                $actual = update_site_meta( self::$site_id, 'foo', 'baz' );
     165                $this->assertTrue( $actual );
     166
     167                $meta = get_site_meta( self::$site_id, 'foo', true );
     168                $this->assertSame( 'baz', $meta );
     169        }
     170
     171        public function test_delete_by_key() {
     172                if ( ! is_site_meta_supported() ) {
     173                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     174                }
     175
     176                add_site_meta( self::$site_id, 'unique_delete_by_key', 'value', true );
     177                add_site_meta( self::$site_id2, 'unique_delete_by_key', 'value', true );
     178
     179                $this->assertEquals( 'value', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
     180                $this->assertEquals( 'value', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
     181
     182                $this->assertTrue( delete_site_meta_by_key( 'unique_delete_by_key' ) );
     183
     184                $this->assertEquals( '', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
     185                $this->assertEquals( '', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
     186        }
     187
     188        public function test_site_meta_should_be_deleted_when_site_is_deleted() {
     189                if ( ! is_site_meta_supported() ) {
     190                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     191                }
     192
     193                $site_id = self::factory()->blog->create( array( 'domain' => 'foo.org', 'path' => '/' ) );
     194
     195                add_site_meta( $site_id, 'foo', 'bar' );
     196                add_site_meta( $site_id, 'foo1', 'bar' );
     197
     198                $this->assertSame( 'bar', get_site_meta( $site_id, 'foo', true ) );
     199                $this->assertSame( 'bar', get_site_meta( $site_id, 'foo1', true ) );
     200
     201                wpmu_delete_blog( $site_id, true );
     202
     203                $this->assertSame( '', get_site_meta( $site_id, 'foo', true ) );
     204                $this->assertSame( '', get_site_meta( $site_id, 'foo1', true ) );
     205        }
     206
     207        public function test_update_site_meta_cache() {
     208                global $wpdb;
     209
     210                if ( ! is_site_meta_supported() ) {
     211                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     212                }
     213
     214                update_site_meta( self::$site_id, 'foo', 'bar' );
     215                update_sitemeta_cache( array( self::$site_id ) );
     216
     217                $num_queries = $wpdb->num_queries;
     218                get_site_meta( self::$site_id, 'foo', true );
     219                $this->assertSame( $num_queries, $wpdb->num_queries);
     220        }
     221
     222        public function test_query_update_site_meta_cache_true() {
     223                global $wpdb;
     224
     225                if ( ! is_site_meta_supported() ) {
     226                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     227                }
     228
     229                update_site_meta( self::$site_id, 'foo', 'bar' );
     230
     231                // Do not include 'update_site_meta_cache' as true as its the default.
     232                new WP_Site_Query( array(
     233                        'ID' => self::$site_id,
     234                ) );
     235
     236                $num_queries = $wpdb->num_queries;
     237                get_site_meta( self::$site_id, 'foo', true );
     238                $this->assertSame( $num_queries, $wpdb->num_queries);
     239        }
     240
     241        public function test_query_update_site_meta_cache_false() {
     242                global $wpdb;
     243
     244                if ( ! is_site_meta_supported() ) {
     245                        $this->markTestSkipped( 'Tests only runs with the blogmeta database table installed' );
     246                }
     247
     248                update_site_meta( self::$site_id, 'foo', 'bar' );
     249
     250                new WP_Site_Query( array(
     251                        'ID'                     => self::$site_id,
     252                        'update_site_meta_cache' => false,
     253                ) );
     254
     255                $num_queries = $wpdb->num_queries;
     256                get_site_meta( self::$site_id, 'foo', true );
     257                $this->assertSame( $num_queries + 1, $wpdb->num_queries);
     258        }
     259}
     260
     261endif;