Make WordPress Core

Ticket #40647: 40647.diff

File 40647.diff, 23.8 KB (added by flixos90, 8 years ago)
  • src/wp-includes/ms-blogs.php

     
    88 * @since MU
    99 */
    1010
     11require_once( ABSPATH . WPINC . '/ms-site.php' );
     12require_once( ABSPATH . WPINC . '/ms-network.php' );
     13
    1114/**
    1215 * Update the last_updated field for the current site.
    1316 *
     
    439442}
    440443
    441444/**
    442  * Clean the blog cache
    443  *
    444  * @since 3.5.0
    445  *
    446  * @global bool $_wp_suspend_cache_invalidation
    447  *
    448  * @param WP_Site $blog The site object to be cleared from cache.
    449  */
    450 function clean_blog_cache( $blog ) {
    451         global $_wp_suspend_cache_invalidation;
    452 
    453         if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
    454                 return;
    455         }
    456 
    457         $blog_id = $blog->blog_id;
    458         $domain_path_key = md5( $blog->domain . $blog->path );
    459 
    460         wp_cache_delete( $blog_id, 'sites' );
    461         wp_cache_delete( $blog_id, 'site-details' );
    462         wp_cache_delete( $blog_id, 'blog-details' );
    463         wp_cache_delete( $blog_id . 'short' , 'blog-details' );
    464         wp_cache_delete( $domain_path_key, 'blog-lookup' );
    465         wp_cache_delete( $domain_path_key, 'blog-id-cache' );
    466         wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
    467         wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
    468 
    469         /**
    470          * Fires immediately after a site has been removed from the object cache.
    471          *
    472          * @since 4.6.0
    473          *
    474          * @param int     $id              Blog ID.
    475          * @param WP_Site $blog            Site object.
    476          * @param string  $domain_path_key md5 hash of domain and path.
    477          */
    478         do_action( 'clean_site_cache', $blog_id, $blog, $domain_path_key );
    479 
    480         wp_cache_set( 'last_changed', microtime(), 'sites' );
    481 }
    482 
    483 /**
    484445 * Cleans the site details cache for a site.
    485446 *
    486447 * @since 4.7.4
     
    498459}
    499460
    500461/**
    501  * Retrieves site data given a site ID or site object.
    502  *
    503  * Site data will be cached and returned after being passed through a filter.
    504  * If the provided site is empty, the current site global will be used.
    505  *
    506  * @since 4.6.0
    507  *
    508  * @param WP_Site|int|null $site Optional. Site to retrieve. Default is the current site.
    509  * @return WP_Site|null The site object or null if not found.
    510  */
    511 function get_site( $site = null ) {
    512         if ( empty( $site ) ) {
    513                 $site = get_current_blog_id();
    514         }
    515 
    516         if ( $site instanceof WP_Site ) {
    517                 $_site = $site;
    518         } elseif ( is_object( $site ) ) {
    519                 $_site = new WP_Site( $site );
    520         } else {
    521                 $_site = WP_Site::get_instance( $site );
    522         }
    523 
    524         if ( ! $_site ) {
    525                 return null;
    526         }
    527 
    528         /**
    529          * Fires after a site is retrieved.
    530          *
    531          * @since 4.6.0
    532          *
    533          * @param WP_Site $_site Site data.
    534          */
    535         $_site = apply_filters( 'get_site', $_site );
    536 
    537         return $_site;
    538 }
    539 
    540 /**
    541  * Adds any sites from the given ids to the cache that do not already exist in cache.
    542  *
    543  * @since 4.6.0
    544  * @access private
    545  *
    546  * @see update_site_cache()
    547  * @global wpdb $wpdb WordPress database abstraction object.
    548  *
    549  * @param array $ids ID list.
    550  */
    551 function _prime_site_caches( $ids ) {
    552         global $wpdb;
    553 
    554         $non_cached_ids = _get_non_cached_ids( $ids, 'sites' );
    555         if ( ! empty( $non_cached_ids ) ) {
    556                 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
    557 
    558                 update_site_cache( $fresh_sites );
    559         }
    560 }
    561 
    562 /**
    563  * Updates sites in cache.
    564  *
    565  * @since 4.6.0
    566  *
    567  * @param array $sites Array of site objects.
    568  */
    569 function update_site_cache( $sites ) {
    570         if ( ! $sites ) {
    571                 return;
    572         }
    573 
    574         foreach ( $sites as $site ) {
    575                 wp_cache_add( $site->blog_id, $site, 'sites' );
    576                 wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' );
    577         }
    578 }
    579 
    580 /**
    581  * Retrieves a list of sites matching requested arguments.
    582  *
    583  * @since 4.6.0
    584  * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
    585  *
    586  * @see WP_Site_Query::parse_query()
    587  *
    588  * @param string|array $args {
    589  *     Optional. Array or query string of site query parameters. Default empty.
    590  *
    591  *     @type array        $site__in          Array of site IDs to include. Default empty.
    592  *     @type array        $site__not_in      Array of site IDs to exclude. Default empty.
    593  *     @type bool         $count             Whether to return a site count (true) or array of site objects.
    594  *                                           Default false.
    595  *     @type array        $date_query        Date query clauses to limit sites by. See WP_Date_Query.
    596  *                                           Default null.
    597  *     @type string       $fields            Site fields to return. Accepts 'ids' (returns an array of site IDs)
    598  *                                           or empty (returns an array of complete site objects). Default empty.
    599  *     @type int          $ID                A site ID to only return that site. Default empty.
    600  *     @type int          $number            Maximum number of sites to retrieve. Default 100.
    601  *     @type int          $offset            Number of sites to offset the query. Used to build LIMIT clause.
    602  *                                           Default 0.
    603  *     @type bool         $no_found_rows     Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
    604  *     @type string|array $orderby           Site status or array of statuses. Accepts 'id', 'domain', 'path',
    605  *                                           'network_id', 'last_updated', 'registered', 'domain_length',
    606  *                                           'path_length', 'site__in' and 'network__in'. Also accepts false,
    607  *                                           an empty array, or 'none' to disable `ORDER BY` clause.
    608  *                                           Default 'id'.
    609  *     @type string       $order             How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
    610  *     @type int          $network_id        Limit results to those affiliated with a given network ID. If 0,
    611  *                                           include all networks. Default 0.
    612  *     @type array        $network__in       Array of network IDs to include affiliated sites for. Default empty.
    613  *     @type array        $network__not_in   Array of network IDs to exclude affiliated sites for. Default empty.
    614  *     @type string       $domain            Limit results to those affiliated with a given domain. Default empty.
    615  *     @type array        $domain__in        Array of domains to include affiliated sites for. Default empty.
    616  *     @type array        $domain__not_in    Array of domains to exclude affiliated sites for. Default empty.
    617  *     @type string       $path              Limit results to those affiliated with a given path. Default empty.
    618  *     @type array        $path__in          Array of paths to include affiliated sites for. Default empty.
    619  *     @type array        $path__not_in      Array of paths to exclude affiliated sites for. Default empty.
    620  *     @type int          $public            Limit results to public sites. Accepts '1' or '0'. Default empty.
    621  *     @type int          $archived          Limit results to archived sites. Accepts '1' or '0'. Default empty.
    622  *     @type int          $mature            Limit results to mature sites. Accepts '1' or '0'. Default empty.
    623  *     @type int          $spam              Limit results to spam sites. Accepts '1' or '0'. Default empty.
    624  *     @type int          $deleted           Limit results to deleted sites. Accepts '1' or '0'. Default empty.
    625  *     @type int          $lang_id           Limit results to a language ID. Default empty.
    626  *     @type array        $lang__in          Array of language IDs to include affiliated sites for. Default empty.
    627  *     @type array        $lang__not_in      Array of language IDs to exclude affiliated sites for. Default empty.
    628  *     @type string       $search            Search term(s) to retrieve matching sites for. Default empty.
    629  *     @type array        $search_columns    Array of column names to be searched. Accepts 'domain' and 'path'.
    630  *                                           Default empty array.
    631  *     @type bool         $update_site_cache Whether to prime the cache for found sites. Default false.
    632  * }
    633  * @return array List of sites.
    634  */
    635 function get_sites( $args = array() ) {
    636         $query = new WP_Site_Query();
    637 
    638         return $query->query( $args );
    639 }
    640 
    641 /**
    642462 * Retrieve option value for a given blog id based on name of option.
    643463 *
    644464 * If the option does not exist or does not have a value, then the return value
     
    1095915}
    1096916
    1097917/**
    1098  * Retrieves a list of networks.
    1099  *
    1100  * @since 4.6.0
    1101  *
    1102  * @param string|array $args Optional. Array or string of arguments. See WP_Network_Query::parse_query()
    1103  *                           for information on accepted arguments. Default empty array.
    1104  * @return int|array List of networks or number of found networks if `$count` argument is true.
    1105  */
    1106 function get_networks( $args = array() ) {
    1107         $query = new WP_Network_Query();
    1108 
    1109         return $query->query( $args );
    1110 }
    1111 
    1112 /**
    1113  * Retrieves network data given a network ID or network object.
    1114  *
    1115  * Network data will be cached and returned after being passed through a filter.
    1116  * If the provided network is empty, the current network global will be used.
    1117  *
    1118  * @since 4.6.0
    1119  *
    1120  * @global WP_Network $current_site
    1121  *
    1122  * @param WP_Network|int|null $network Optional. Network to retrieve. Default is the current network.
    1123  * @return WP_Network|null The network object or null if not found.
    1124  */
    1125 function get_network( $network = null ) {
    1126         global $current_site;
    1127         if ( empty( $network ) && isset( $current_site ) ) {
    1128                 $network = $current_site;
    1129         }
    1130 
    1131         if ( $network instanceof WP_Network ) {
    1132                 $_network = $network;
    1133         } elseif ( is_object( $network ) ) {
    1134                 $_network = new WP_Network( $network );
    1135         } else {
    1136                 $_network = WP_Network::get_instance( $network );
    1137         }
    1138 
    1139         if ( ! $_network ) {
    1140                 return null;
    1141         }
    1142 
    1143         /**
    1144          * Fires after a network is retrieved.
    1145          *
    1146          * @since 4.6.0
    1147          *
    1148          * @param WP_Network $_network Network data.
    1149          */
    1150         $_network = apply_filters( 'get_network', $_network );
    1151 
    1152         return $_network;
    1153 }
    1154 
    1155 /**
    1156  * Removes a network from the object cache.
    1157  *
    1158  * @since 4.6.0
    1159  *
    1160  * @global bool $_wp_suspend_cache_invalidation
    1161  *
    1162  * @param int|array $ids Network ID or an array of network IDs to remove from cache.
    1163  */
    1164 function clean_network_cache( $ids ) {
    1165         global $_wp_suspend_cache_invalidation;
    1166 
    1167         if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
    1168                 return;
    1169         }
    1170 
    1171         foreach ( (array) $ids as $id ) {
    1172                 wp_cache_delete( $id, 'networks' );
    1173 
    1174                 /**
    1175                  * Fires immediately after a network has been removed from the object cache.
    1176                  *
    1177                  * @since 4.6.0
    1178                  *
    1179                  * @param int $id Network ID.
    1180                  */
    1181                 do_action( 'clean_network_cache', $id );
    1182         }
    1183 
    1184         wp_cache_set( 'last_changed', microtime(), 'networks' );
    1185 }
    1186 
    1187 /**
    1188  * Updates the network cache of given networks.
    1189  *
    1190  * Will add the networks in $networks to the cache. If network ID already exists
    1191  * in the network cache then it will not be updated. The network is added to the
    1192  * cache using the network group with the key using the ID of the networks.
    1193  *
    1194  * @since 4.6.0
    1195  *
    1196  * @param array $networks Array of network row objects.
    1197  */
    1198 function update_network_cache( $networks ) {
    1199         foreach ( (array) $networks as $network ) {
    1200                 wp_cache_add( $network->id, $network, 'networks' );
    1201         }
    1202 }
    1203 
    1204 /**
    1205  * Adds any networks from the given IDs to the cache that do not already exist in cache.
    1206  *
    1207  * @since 4.6.0
    1208  * @access private
    1209  *
    1210  * @see update_network_cache()
    1211  * @global wpdb $wpdb WordPress database abstraction object.
    1212  *
    1213  * @param array $network_ids Array of network IDs.
    1214  */
    1215 function _prime_network_caches( $network_ids ) {
    1216         global $wpdb;
    1217 
    1218         $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' );
    1219         if ( !empty( $non_cached_ids ) ) {
    1220                 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
    1221 
    1222                 update_network_cache( $fresh_networks );
    1223         }
    1224 }
    1225 
    1226 /**
    1227918 * Handler for updating the blog date when a post is published or an already published post is changed.
    1228919 *
    1229920 * @since 3.3.0
  • src/wp-includes/ms-network.php

     
     1<?php
     2/**
     3 * Network API
     4 *
     5 * @package WordPress
     6 * @subpackage Multisite
     7 * @since 4.8.0
     8 */
     9
     10/**
     11 * Retrieves a list of networks.
     12 *
     13 * @since 4.6.0
     14 *
     15 * @param string|array $args Optional. Array or string of arguments. See WP_Network_Query::parse_query()
     16 *                           for information on accepted arguments. Default empty array.
     17 * @return int|array List of networks or number of found networks if `$count` argument is true.
     18 */
     19function get_networks( $args = array() ) {
     20        $query = new WP_Network_Query();
     21
     22        return $query->query( $args );
     23}
     24
     25/**
     26 * Retrieves network data given a network ID or network object.
     27 *
     28 * Network data will be cached and returned after being passed through a filter.
     29 * If the provided network is empty, the current network global will be used.
     30 *
     31 * @since 4.6.0
     32 *
     33 * @global WP_Network $current_site
     34 *
     35 * @param WP_Network|int|null $network Optional. Network to retrieve. Default is the current network.
     36 * @return WP_Network|null The network object or null if not found.
     37 */
     38function get_network( $network = null ) {
     39        global $current_site;
     40        if ( empty( $network ) && isset( $current_site ) ) {
     41                $network = $current_site;
     42        }
     43
     44        if ( $network instanceof WP_Network ) {
     45                $_network = $network;
     46        } elseif ( is_object( $network ) ) {
     47                $_network = new WP_Network( $network );
     48        } else {
     49                $_network = WP_Network::get_instance( $network );
     50        }
     51
     52        if ( ! $_network ) {
     53                return null;
     54        }
     55
     56        /**
     57         * Fires after a network is retrieved.
     58         *
     59         * @since 4.6.0
     60         *
     61         * @param WP_Network $_network Network data.
     62         */
     63        $_network = apply_filters( 'get_network', $_network );
     64
     65        return $_network;
     66}
     67
     68/**
     69 * Removes a network from the object cache.
     70 *
     71 * @since 4.6.0
     72 *
     73 * @global bool $_wp_suspend_cache_invalidation
     74 *
     75 * @param int|array $ids Network ID or an array of network IDs to remove from cache.
     76 */
     77function clean_network_cache( $ids ) {
     78        global $_wp_suspend_cache_invalidation;
     79
     80        if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
     81                return;
     82        }
     83
     84        foreach ( (array) $ids as $id ) {
     85                wp_cache_delete( $id, 'networks' );
     86
     87                /**
     88                 * Fires immediately after a network has been removed from the object cache.
     89                 *
     90                 * @since 4.6.0
     91                 *
     92                 * @param int $id Network ID.
     93                 */
     94                do_action( 'clean_network_cache', $id );
     95        }
     96
     97        wp_cache_set( 'last_changed', microtime(), 'networks' );
     98}
     99
     100/**
     101 * Updates the network cache of given networks.
     102 *
     103 * Will add the networks in $networks to the cache. If network ID already exists
     104 * in the network cache then it will not be updated. The network is added to the
     105 * cache using the network group with the key using the ID of the networks.
     106 *
     107 * @since 4.6.0
     108 *
     109 * @param array $networks Array of network row objects.
     110 */
     111function update_network_cache( $networks ) {
     112        foreach ( (array) $networks as $network ) {
     113                wp_cache_add( $network->id, $network, 'networks' );
     114        }
     115}
     116
     117/**
     118 * Adds any networks from the given IDs to the cache that do not already exist in cache.
     119 *
     120 * @since 4.6.0
     121 * @access private
     122 *
     123 * @see update_network_cache()
     124 * @global wpdb $wpdb WordPress database abstraction object.
     125 *
     126 * @param array $network_ids Array of network IDs.
     127 */
     128function _prime_network_caches( $network_ids ) {
     129        global $wpdb;
     130
     131        $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' );
     132        if ( !empty( $non_cached_ids ) ) {
     133                $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
     134
     135                update_network_cache( $fresh_networks );
     136        }
     137}
  • src/wp-includes/ms-site.php

     
     1<?php
     2/**
     3 * Site API
     4 *
     5 * @package WordPress
     6 * @subpackage Multisite
     7 * @since 4.8.0
     8 */
     9
     10/**
     11 * Retrieves a list of sites matching requested arguments.
     12 *
     13 * @since 4.6.0
     14 * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
     15 *
     16 * @see WP_Site_Query::parse_query()
     17 *
     18 * @param string|array $args {
     19 *     Optional. Array or query string of site query parameters. Default empty.
     20 *
     21 *     @type array        $site__in          Array of site IDs to include. Default empty.
     22 *     @type array        $site__not_in      Array of site IDs to exclude. Default empty.
     23 *     @type bool         $count             Whether to return a site count (true) or array of site objects.
     24 *                                           Default false.
     25 *     @type array        $date_query        Date query clauses to limit sites by. See WP_Date_Query.
     26 *                                           Default null.
     27 *     @type string       $fields            Site fields to return. Accepts 'ids' (returns an array of site IDs)
     28 *                                           or empty (returns an array of complete site objects). Default empty.
     29 *     @type int          $ID                A site ID to only return that site. Default empty.
     30 *     @type int          $number            Maximum number of sites to retrieve. Default 100.
     31 *     @type int          $offset            Number of sites to offset the query. Used to build LIMIT clause.
     32 *                                           Default 0.
     33 *     @type bool         $no_found_rows     Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
     34 *     @type string|array $orderby           Site status or array of statuses. Accepts 'id', 'domain', 'path',
     35 *                                           'network_id', 'last_updated', 'registered', 'domain_length',
     36 *                                           'path_length', 'site__in' and 'network__in'. Also accepts false,
     37 *                                           an empty array, or 'none' to disable `ORDER BY` clause.
     38 *                                           Default 'id'.
     39 *     @type string       $order             How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
     40 *     @type int          $network_id        Limit results to those affiliated with a given network ID. If 0,
     41 *                                           include all networks. Default 0.
     42 *     @type array        $network__in       Array of network IDs to include affiliated sites for. Default empty.
     43 *     @type array        $network__not_in   Array of network IDs to exclude affiliated sites for. Default empty.
     44 *     @type string       $domain            Limit results to those affiliated with a given domain. Default empty.
     45 *     @type array        $domain__in        Array of domains to include affiliated sites for. Default empty.
     46 *     @type array        $domain__not_in    Array of domains to exclude affiliated sites for. Default empty.
     47 *     @type string       $path              Limit results to those affiliated with a given path. Default empty.
     48 *     @type array        $path__in          Array of paths to include affiliated sites for. Default empty.
     49 *     @type array        $path__not_in      Array of paths to exclude affiliated sites for. Default empty.
     50 *     @type int          $public            Limit results to public sites. Accepts '1' or '0'. Default empty.
     51 *     @type int          $archived          Limit results to archived sites. Accepts '1' or '0'. Default empty.
     52 *     @type int          $mature            Limit results to mature sites. Accepts '1' or '0'. Default empty.
     53 *     @type int          $spam              Limit results to spam sites. Accepts '1' or '0'. Default empty.
     54 *     @type int          $deleted           Limit results to deleted sites. Accepts '1' or '0'. Default empty.
     55 *     @type int          $lang_id           Limit results to a language ID. Default empty.
     56 *     @type array        $lang__in          Array of language IDs to include affiliated sites for. Default empty.
     57 *     @type array        $lang__not_in      Array of language IDs to exclude affiliated sites for. Default empty.
     58 *     @type string       $search            Search term(s) to retrieve matching sites for. Default empty.
     59 *     @type array        $search_columns    Array of column names to be searched. Accepts 'domain' and 'path'.
     60 *                                           Default empty array.
     61 *     @type bool         $update_site_cache Whether to prime the cache for found sites. Default false.
     62 * }
     63 * @return array List of sites.
     64 */
     65function get_sites( $args = array() ) {
     66        $query = new WP_Site_Query();
     67
     68        return $query->query( $args );
     69}
     70
     71/**
     72 * Retrieves site data given a site ID or site object.
     73 *
     74 * Site data will be cached and returned after being passed through a filter.
     75 * If the provided site is empty, the current site global will be used.
     76 *
     77 * @since 4.6.0
     78 *
     79 * @param WP_Site|int|null $site Optional. Site to retrieve. Default is the current site.
     80 * @return WP_Site|null The site object or null if not found.
     81 */
     82function get_site( $site = null ) {
     83        if ( empty( $site ) ) {
     84                $site = get_current_blog_id();
     85        }
     86
     87        if ( $site instanceof WP_Site ) {
     88                $_site = $site;
     89        } elseif ( is_object( $site ) ) {
     90                $_site = new WP_Site( $site );
     91        } else {
     92                $_site = WP_Site::get_instance( $site );
     93        }
     94
     95        if ( ! $_site ) {
     96                return null;
     97        }
     98
     99        /**
     100         * Fires after a site is retrieved.
     101         *
     102         * @since 4.6.0
     103         *
     104         * @param WP_Site $_site Site data.
     105         */
     106        $_site = apply_filters( 'get_site', $_site );
     107
     108        return $_site;
     109}
     110
     111/**
     112 * Clean the blog cache
     113 *
     114 * @since 3.5.0
     115 *
     116 * @global bool $_wp_suspend_cache_invalidation
     117 *
     118 * @param WP_Site $blog The site object to be cleared from cache.
     119 */
     120function clean_blog_cache( $blog ) {
     121        global $_wp_suspend_cache_invalidation;
     122
     123        if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
     124                return;
     125        }
     126
     127        $blog_id = $blog->blog_id;
     128        $domain_path_key = md5( $blog->domain . $blog->path );
     129
     130        wp_cache_delete( $blog_id, 'sites' );
     131        wp_cache_delete( $blog_id, 'site-details' );
     132        wp_cache_delete( $blog_id, 'blog-details' );
     133        wp_cache_delete( $blog_id . 'short' , 'blog-details' );
     134        wp_cache_delete( $domain_path_key, 'blog-lookup' );
     135        wp_cache_delete( $domain_path_key, 'blog-id-cache' );
     136        wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
     137        wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
     138
     139        /**
     140         * Fires immediately after a site has been removed from the object cache.
     141         *
     142         * @since 4.6.0
     143         *
     144         * @param int     $id              Blog ID.
     145         * @param WP_Site $blog            Site object.
     146         * @param string  $domain_path_key md5 hash of domain and path.
     147         */
     148        do_action( 'clean_site_cache', $blog_id, $blog, $domain_path_key );
     149
     150        wp_cache_set( 'last_changed', microtime(), 'sites' );
     151}
     152
     153/**
     154 * Updates sites in cache.
     155 *
     156 * @since 4.6.0
     157 *
     158 * @param array $sites Array of site objects.
     159 */
     160function update_site_cache( $sites ) {
     161        if ( ! $sites ) {
     162                return;
     163        }
     164
     165        foreach ( $sites as $site ) {
     166                wp_cache_add( $site->blog_id, $site, 'sites' );
     167                wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' );
     168        }
     169}
     170
     171/**
     172 * Adds any sites from the given ids to the cache that do not already exist in cache.
     173 *
     174 * @since 4.6.0
     175 * @access private
     176 *
     177 * @see update_site_cache()
     178 * @global wpdb $wpdb WordPress database abstraction object.
     179 *
     180 * @param array $ids ID list.
     181 */
     182function _prime_site_caches( $ids ) {
     183        global $wpdb;
     184
     185        $non_cached_ids = _get_non_cached_ids( $ids, 'sites' );
     186        if ( ! empty( $non_cached_ids ) ) {
     187                $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
     188
     189                update_site_cache( $fresh_sites );
     190        }
     191}