Make WordPress Core

Ticket #37923: 37923.16.diff

File 37923.16.diff, 34.6 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) 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 < 42125 ) {
     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 comments.
     142         *                                                Default true.
    140143         * }
    141144         */
    142145        public function __construct( $query = '' ) {
    143146                $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,
     147                        'fields'                 => '',
     148                        'ID'                     => '',
     149                        'site__in'               => '',
     150                        'site__not_in'           => '',
     151                        'number'                 => 100,
     152                        'offset'                 => '',
     153                        'no_found_rows'          => true,
     154                        'orderby'                => 'id',
     155                        'order'                  => 'ASC',
     156                        'network_id'             => 0,
     157                        'network__in'            => '',
     158                        'network__not_in'        => '',
     159                        'domain'                 => '',
     160                        'domain__in'             => '',
     161                        'domain__not_in'         => '',
     162                        'path'                   => '',
     163                        'path__in'               => '',
     164                        'path__not_in'           => '',
     165                        'public'                 => null,
     166                        'archived'               => null,
     167                        'mature'                 => null,
     168                        'spam'                   => null,
     169                        'deleted'                => null,
     170                        'lang_id'                => null,
     171                        'lang__in'               => '',
     172                        'lang__not_in'           => '',
     173                        'search'                 => '',
     174                        'search_columns'         => array(),
     175                        'count'                  => false,
     176                        'date_query'             => null, // See WP_Date_Query
     177                        'update_site_cache'      => true,
     178                        'update_site_meta_cache' => true,
    175179                );
    176180
    177181                if ( ! empty( $query ) ) {
     
    288292
    289293                // Prime site network caches.
    290294                if ( $this->query_vars['update_site_cache'] ) {
    291                         _prime_site_caches( $site_ids );
     295                        _prime_site_caches( $site_ids, $this->query_vars['update_site_meta_cache'] );
    292296                }
    293297
    294298                // Fetch full site objects from the primed cache.
  • src/wp-includes/functions.php

     
    47174717}
    47184718
    47194719/**
     4720 * Determines whether site meta is enabled.
     4721 *
     4722 * This function checks whether the 'blogmeta' database table exists. The result is saved as
     4723 * a setting for the main network, making it essentially a global setting. Subsequent requests
     4724 * will refer to this setting instead of running the query. The $force parameter can be used
     4725 * to bypass the setting, and reset it accordingly, however this is not recommended.
     4726 *
     4727 * The 'is_site_meta_supported' filter can be used to bypass the database checks completely.
     4728 *
     4729 * @since 4.9.0
     4730 *
     4731 * @global wpdb $wpdb WordPress database abstraction object.
     4732 *
     4733 * @return bool True if site meta is supported, false otherwise.
     4734 */
     4735function is_site_meta_supported() {
     4736        global $wpdb;
     4737
     4738        if ( ! is_multisite() ) {
     4739                return false;
     4740        }
     4741
     4742        $network_id = get_main_network_id();
     4743
     4744        if ( false === ( $supported = get_network_option( $network_id, 'site_meta_supported', false ) ) ) {
     4745                $supported = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->blogmeta}'" ) ? 1 : 0;
     4746
     4747                update_network_option( $network_id, 'site_meta_supported', $supported );
     4748        }
     4749
     4750        return (bool) $supported;
     4751}
     4752
     4753/**
    47204754 * gmt_offset modification for smart timezone handling.
    47214755 *
    47224756 * 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.
     
    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 *
    568570 * @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/**
     
    658687        return $query->query( $args );
    659688}
    660689
     690
    661691/**
    662692 * Retrieve option value for a given blog id based on name of option.
    663693 *
     
    796826        return $return;
    797827}
    798828
     829
     830
     831/**
     832 * Add meta data field to a site.
     833 *
     834 * Site meta data is called "Custom Fields" on the Administration Screen.
     835 *
     836 * @since 5.0.0
     837 *
     838 * @param int    $site_id    Site ID.
     839 * @param string $meta_key   Metadata name.
     840 * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
     841 * @param bool   $unique     Optional. Whether the same key should not be added.
     842 *                           Default false.
     843 * @return int|false Meta ID on success, false on failure.
     844 */
     845function add_site_meta( $site_id, $meta_key, $meta_value, $unique = false ) {
     846        // Bail if site meta table is not installed.
     847        if ( ! is_site_meta_supported() ) {
     848                _doing_it_wrong( __FUNCTION__, __( 'Site meta table is not installed. Please run database upgrade.' ), '5.0.0' );
     849
     850                return false;
     851        }
     852
     853        $added = add_metadata( 'blog', $site_id, $meta_key, $meta_value, $unique );
     854
     855        // Bust site query cache.
     856        if ( $added ) {
     857                // @todo use clean_blog_cache here
     858                wp_cache_set( 'last_changed', microtime(), 'sites' );
     859        }
     860
     861        return $added;
     862}
     863
     864/**
     865 * Remove metadata matching criteria from a site.
     866 *
     867 * You can match based on the key, or key and value. Removing based on key and
     868 * value, will keep from removing duplicate metadata with the same key. It also
     869 * allows removing all metadata matching key, if needed.
     870 *
     871 * @since 5.0.0
     872 *
     873 * @param int    $site_id    Site ID.
     874 * @param string $meta_key   Metadata name.
     875 * @param mixed  $meta_value Optional. Metadata value. Must be serializable if
     876 *                           non-scalar. Default empty.
     877 * @return bool True on success, false on failure.
     878 */
     879function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
     880        // Bail if site meta table is not installed.
     881        if ( ! is_site_meta_supported() ) {
     882                _doing_it_wrong( __FUNCTION__, __( 'Site meta table is not installed. Please run database upgrade.' ), '5.0.0' );
     883
     884                return false;
     885        }
     886
     887        $deleted = delete_metadata( 'blog', $site_id, $meta_key, $meta_value );
     888
     889        // Bust site query cache.
     890        if ( $deleted ) {
     891                // @todo use clean_blog_cache here
     892                wp_cache_set( 'last_changed', microtime(), 'sites' );
     893        }
     894
     895        return $deleted;
     896}
     897
     898/**
     899 * Retrieve site meta field for a site.
     900 *
     901 * @since 5.0.0
     902 *
     903 * @param int    $site_id Site ID.
     904 * @param string $key     Optional. The meta key to retrieve. By default, returns
     905 *                        data for all keys. Default empty.
     906 * @param bool   $single  Optional. Whether to return a single value. Default false.
     907 * @return mixed Will be an array if $single is false. Will be value of meta data
     908 *               field if $single is true.
     909 */
     910function get_site_meta( $site_id, $key = '', $single = false ) {
     911        // Bail if site meta table is not installed.
     912        if ( ! is_site_meta_supported() ) {
     913                _doing_it_wrong( __FUNCTION__, __( 'Site meta table is not installed. Please run database upgrade.' ), '5.0.0' );
     914
     915                return false;
     916        }
     917
     918        return get_metadata( 'blog', $site_id, $key, $single );
     919}
     920
     921/**
     922 * Update site meta field based on site ID.
     923 *
     924 * Use the $prev_value parameter to differentiate between meta fields with the
     925 * same key and site ID.
     926 *
     927 * If the meta field for the site does not exist, it will be added.
     928 *
     929 * @since 5.0.0
     930 *
     931 * @param int    $site_id    Site ID.
     932 * @param string $meta_key   Metadata key.
     933 * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
     934 * @param mixed  $prev_value Optional. Previous value to check before removing.
     935 *                           Default empty.
     936 * @return int|bool Meta ID if the key didn't exist, true on successful update,
     937 *                  false on failure.
     938 */
     939function update_site_meta( $site_id, $meta_key, $meta_value, $prev_value = '' ) {
     940        // Bail if site meta table is not installed.
     941        if ( ! is_site_meta_supported() ) {
     942                _doing_it_wrong( __FUNCTION__, __( 'Site meta table is not installed. Please run database upgrade.' ), '5.0.0' );
     943
     944                return false;
     945        }
     946
     947        $updated = update_metadata( 'blog', $site_id, $meta_key, $meta_value, $prev_value );
     948
     949        // Bust site query cache.
     950        if ( $updated ) {
     951                // @todo use clean_blog_cache here
     952                wp_cache_set( 'last_changed', microtime(), 'sites' );
     953        }
     954
     955        return $updated;
     956}
     957
     958/**
     959 * Delete everything from site meta matching meta key.
     960 *
     961 * @since 5.0.0
     962 *
     963 * @param string $meta_key Metadata key to search for when deleting.
     964 * @return bool Whether the site meta key was deleted from the database.
     965 */
     966function delete_site_meta_by_key( $meta_key ) {
     967        // Bail if site meta table is not installed.
     968        if ( ! is_site_meta_supported() ) {
     969                _doing_it_wrong( __FUNCTION__, __( 'Site meta table is not installed. Please run database upgrade.' ), '5.0.0' );
     970
     971                return false;
     972        }
     973
     974        $deleted = delete_metadata( 'blog', null, $meta_key, '', true );
     975
     976        // Bust site query cache.
     977        if ( $deleted ) {
     978                // @todo use clean_blog_cache here
     979                wp_cache_set( 'last_changed', microtime(), 'sites' );
     980        }
     981
     982        return $deleted;
     983}
     984
    799985/**
    800986 * Switch the current blog.
    801987 *
     
    8691055                        if ( is_array( $global_groups ) ) {
    8701056                                wp_cache_add_global_groups( $global_groups );
    8711057                        } 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' ) );
     1058                                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' ) );
    8731059                        }
    8741060                        wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    8751061                }
     
    9371123                        if ( is_array( $global_groups ) ) {
    9381124                                wp_cache_add_global_groups( $global_groups );
    9391125                        } 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' ) );
     1126                                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' ) );
    9411127                        }
    9421128                        wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
    9431129                }
  • src/wp-includes/version.php

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

     
    283283         */
    284284        var $ms_global_tables = array(
    285285                'blogs',
     286                'blogmeta',
    286287                'signups',
    287288                'site',
    288289                'sitemeta',
     
    400401        public $blogs;
    401402
    402403        /**
     404         * Multisite Blog Metadata table
     405         *
     406         * @since 5.0.0
     407         * @var string
     408         */
     409        public $blogmeta;
     410
     411        /**
    403412         * Multisite Blog Versions table
    404413         *
    405414         * @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 site-meta
     9         * @group meta
     10         * @ticket 37923
     11         */
     12        class Tests_Multisite_Site_Meta extends WP_UnitTestCase {
     13                protected static $site_id;
     14                protected static $site_id2;
     15                protected static $flag_was_set;
     16
     17                public static function wpSetUpBeforeClass( $factory ) {
     18                        self::$site_id  = $factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/' ) );
     19                        self::$site_id2 = $factory->blog->create( array( 'domain' => 'wordpress.org', 'path' => '/foo/' ) );
     20
     21                        // Populate the main network flag as necessary.
     22                        self::$flag_was_set = true;
     23                        if ( false === get_network_option( get_main_network_id(), 'site_meta_supported', false ) ) {
     24                                self::$flag_was_set = false;
     25                                is_site_meta_supported();
     26                        }
     27                }
     28
     29                public static function wpTearDownAfterClass() {
     30                        // Delete the possibly previously populated main network flag.
     31                        if ( ! self::$flag_was_set ) {
     32                                delete_network_option( get_main_network_id(), 'site_meta_supported' );
     33                        }
     34
     35                        wpmu_delete_blog( self::$site_id, true );
     36                        wpmu_delete_blog( self::$site_id2, true );
     37
     38                        wp_update_network_site_counts();
     39                }
     40
     41                public function test_is_site_meta_supported() {
     42                        $setting = get_network_option( get_main_network_id(), 'site_meta_supported' );
     43                        $this->assertTrue( is_site_meta_supported() );
     44                        $this->assertSame( $setting, '1' );
     45                }
     46
     47                public function test_is_site_meta_supported_filtered() {
     48                        add_filter('pre_site_option_site_meta_supported', '__return_zero');
     49                        $setting = get_network_option( get_main_network_id(), 'site_meta_supported' );
     50                        $this->assertFalse( is_site_meta_supported() );
     51                        $this->assertSame( $setting, 0 );
     52                        remove_filter('pre_site_option_site_meta_supported', '__return_zero');
     53                }
     54
     55                public function test_add() {
     56                        $key   = 'foo';
     57                        $value = 'bar';
     58                        $this->assertNotEmpty( add_site_meta( self::$site_id, $key, $value ) );
     59                        $this->assertSame( get_site_meta( self::$site_id, $key, true ), $value );
     60                }
     61
     62                public function test_add_unique() {
     63
     64                        $this->assertNotEmpty( add_site_meta( self::$site_id, 'foo', 'bar' ) );
     65                        $this->assertFalse( add_site_meta( self::$site_id, 'foo', 'bar', true ) );
     66                }
     67
     68                public function test_delete() {
     69
     70                        add_site_meta( self::$site_id, 'foo', 'bar' );
     71
     72                        $this->assertTrue( delete_site_meta( self::$site_id, 'foo' ) );
     73                }
     74
     75                public function test_delete_with_invalid_meta_key_should_return_false() {
     76
     77                        $this->assertFalse( delete_site_meta( self::$site_id, 'foo' ) );
     78                }
     79
     80                public function test_delete_should_respect_meta_value() {
     81
     82                        add_site_meta( self::$site_id, 'foo', 'bar' );
     83                        add_site_meta( self::$site_id, 'foo', 'baz' );
     84
     85                        $this->assertTrue( delete_site_meta( self::$site_id, 'foo', 'bar' ) );
     86
     87                        $metas = get_site_meta( self::$site_id, 'foo', false );
     88                        $this->assertSame( array( 'baz' ), $metas );
     89                }
     90
     91                public function test_get_with_no_key_should_fetch_all_keys() {
     92
     93                        add_site_meta( self::$site_id, 'foo', 'bar' );
     94                        add_site_meta( self::$site_id, 'foo1', 'baz' );
     95
     96                        $found    = get_site_meta( self::$site_id );
     97                        $expected = array(
     98                                'foo'  => array( 'bar' ),
     99                                'foo1' => array( 'baz' ),
     100                        );
     101
     102                        $this->assertEqualSets( $expected, $found );
     103                }
     104
     105                public function test_get_with_key_should_fetch_all_for_key() {
     106
     107                        add_site_meta( self::$site_id, 'foo', 'bar' );
     108                        add_site_meta( self::$site_id, 'foo', 'baz' );
     109                        add_site_meta( self::$site_id, 'foo1', 'baz' );
     110
     111                        $found    = get_site_meta( self::$site_id, 'foo' );
     112                        $expected = array( 'bar', 'baz' );
     113
     114                        $this->assertEqualSets( $expected, $found );
     115                }
     116
     117                public function test_get_should_respect_single_true() {
     118
     119                        add_site_meta( self::$site_id, 'foo', 'bar' );
     120                        add_site_meta( self::$site_id, 'foo', 'baz' );
     121
     122                        $found = get_site_meta( self::$site_id, 'foo', true );
     123                        $this->assertEquals( 'bar', $found );
     124                }
     125
     126                public function test_update_should_pass_to_add_when_no_value_exists_for_key() {
     127
     128                        $actual = update_site_meta( self::$site_id, 'foo', 'bar' );
     129                        $this->assertInternalType( 'int', $actual );
     130                        $this->assertNotEmpty( $actual );
     131
     132                        $meta = get_site_meta( self::$site_id, 'foo', true );
     133                        $this->assertSame( 'bar', $meta );
     134                }
     135
     136                public function test_update_should_return_true_when_updating_existing_value_for_key() {
     137
     138                        add_site_meta( self::$site_id, 'foo', 'bar' );
     139
     140                        $actual = update_site_meta( self::$site_id, 'foo', 'baz' );
     141                        $this->assertTrue( $actual );
     142
     143                        $meta = get_site_meta( self::$site_id, 'foo', true );
     144                        $this->assertSame( 'baz', $meta );
     145                }
     146
     147                public function test_delete_by_key() {
     148
     149                        add_site_meta( self::$site_id, 'unique_delete_by_key', 'value', true );
     150                        add_site_meta( self::$site_id2, 'unique_delete_by_key', 'value', true );
     151
     152                        $this->assertEquals( 'value', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
     153                        $this->assertEquals( 'value', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
     154
     155                        $this->assertTrue( delete_site_meta_by_key( 'unique_delete_by_key' ) );
     156
     157                        $this->assertEquals( '', get_site_meta( self::$site_id, 'unique_delete_by_key', true ) );
     158                        $this->assertEquals( '', get_site_meta( self::$site_id2, 'unique_delete_by_key', true ) );
     159                }
     160
     161                public function test_site_meta_should_be_deleted_when_site_is_deleted() {
     162
     163                        $site_id = self::factory()->blog->create( array( 'domain' => 'foo.org', 'path' => '/' ) );
     164
     165                        add_site_meta( $site_id, 'foo', 'bar' );
     166                        add_site_meta( $site_id, 'foo1', 'bar' );
     167
     168                        $this->assertSame( 'bar', get_site_meta( $site_id, 'foo', true ) );
     169                        $this->assertSame( 'bar', get_site_meta( $site_id, 'foo1', true ) );
     170
     171                        wpmu_delete_blog( $site_id, true );
     172
     173                        $this->assertSame( '', get_site_meta( $site_id, 'foo', true ) );
     174                        $this->assertSame( '', get_site_meta( $site_id, 'foo1', true ) );
     175                }
     176        }
     177
     178endif;