Make WordPress Core


Ignore:
Timestamp:
03/16/2018 02:14:04 AM (7 years ago)
Author:
flixos90
Message:

Multisite: Introduce metadata for sites.

A new global multisite table wp_blogmeta is added to the database schema, and a set of *_site_meta() API functions are introduced.

The implementation fails gracefully when the new table is not yet available, which may happen especially shortly after the core update, before the network has been upgraded to the new database schema. The presence of the table is detected once and stored as a global setting on the main network.

Core does not yet use site metadata, but there are several use-cases to be implemented or explored in the near future, and it allows plugins to extend sites with arbitrary data, which will come in particularly handy with the upcoming REST API endpoint for sites.

Props spacedmonkey, johnjamesjacoby, jeremyfelt, flixos90.
Fixes #37923.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-site-query.php

    r42343 r42836  
    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
     
    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
Note: See TracChangeset for help on using the changeset viewer.