454
455
wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
455
456
wp_cache_delete( 'get_id_from_blogname_' . trim( $blog->path, '/' ), 'blog-details' );
456
457
wp_cache_delete( $domain_path_key, 'blog-id-cache' );
460
* Fires immediately after a site has been removed from the object cache.
464
* @param int $id Blog ID.
465
* @param WP_Site $blog Site object.
466
* @param string $domain_path_key md5 hash of domain and path.
468
do_action( 'clean_site_cache', $blog_id, $blog, $domain_path_key );
470
wp_cache_set( 'last_changed', microtime(), 'sites' );
474
* Retrieves site data given a site ID or site object.
476
* Site data will be cached and returned after being passed through a filter.
477
* If the provided site is empty, the current site global will be used.
481
* @param WP_Site|int|null $site Optional. Site to retrieve. Default is the current site.
482
* @return WP_Site|null The site object or null if not found.
484
function get_site( $site = null ) {
485
if ( empty( $site ) ) {
486
$site = get_current_blog_id();
489
if ( $site instanceof WP_Site ) {
491
} elseif ( is_object( $site ) ) {
492
$_site = new WP_Site( $site );
494
$_site = WP_Site::get_instance( $site );
502
* Fires after a site is retrieved.
506
* @param WP_Site $_site Site data.
508
$_site = apply_filters( 'get_site', $_site );
514
* Adds any sites from the given ids to the cache that do not already exist in cache.
519
* @see update_site_cache()
520
* @global wpdb $wpdb WordPress database abstraction object.
522
* @param array $ids ID list.
524
function _prime_site_caches( $ids ) {
527
$non_cached_ids = _get_non_cached_ids( $ids, 'sites' );
528
if ( ! empty( $non_cached_ids ) ) {
529
$fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
531
update_site_cache( $fresh_sites );
536
* Updates sites in cache.
540
* @param array $sites Array of site objects.
542
function update_site_cache( $sites ) {
547
foreach ( $sites as $site ) {
548
wp_cache_add( $site->blog_id, $site, 'sites' );
549
wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' );
554
* Retrieves a list of sites matching requested arguments.
558
* @see WP_Site_Query::parse_query()
560
* @param string|array $args {
561
* Optional. Array or query string of site query parameters. Default empty.
563
* @type array $site__in Array of site IDs to include. Default empty.
564
* @type array $site__not_in Array of site IDs to exclude. Default empty.
565
* @type bool $count Whether to return a site count (true) or array of site objects.
567
* @type array $date_query Date query clauses to limit sites by. See WP_Date_Query.
569
* @type string $fields Site fields to return. Accepts 'ids' for site IDs only or empty
570
* for all fields. Default empty.
571
* @type int $ID A site ID to only return that site. Default empty.
572
* @type int $number Maximum number of sites to retrieve. Default null (no limit).
573
* @type int $offset Number of sites to offset the query. Used to build LIMIT clause.
575
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
576
* @type string|array $orderby Site status or array of statuses. Accepts 'id', 'domain', 'path',
577
* 'network_id', 'last_updated', 'registered', 'domain_length',
578
* 'path_length', 'site__in' and 'network__in'. Also accepts false,
579
* an empty array, or 'none' to disable `ORDER BY` clause.
581
* @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
582
* @type int $network_id Limit results to those affiliated with a given network ID.
583
* Default current network ID.
584
* @type array $network__in Array of network IDs to include affiliated sites for. Default empty.
585
* @type array $network__not_in Array of network IDs to exclude affiliated sites for. Default empty.
586
* @type string $domain Limit results to those affiliated with a given domain.
588
* @type array $domain__in Array of domains to include affiliated sites for. Default empty.
589
* @type array $domain__not_in Array of domains to exclude affiliated sites for. Default empty.
590
* @type string $path Limit results to those affiliated with a given path.
592
* @type array $path__in Array of paths to include affiliated sites for. Default empty.
593
* @type array $path__not_in Array of paths to exclude affiliated sites for. Default empty.
594
* @type int $public Limit results to public sites. Accepts '1' or '0'. Default empty.
595
* @type int $archived Limit results to archived sites. Accepts '1' or '0'. Default empty.
596
* @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty.
597
* @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty.
598
* @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty.
599
* @type string $search Search term(s) to retrieve matching sites for. Default empty.
600
* @type bool $update_site_cache Whether to prime the cache for found sites. Default false.
602
* @return array List of sites.
604
function get_sites( $args = array() ) {
605
$query = new WP_Site_Query();
607
return $query->query( $args );
660
811
if ( is_array( $global_groups ) ) {
661
812
wp_cache_add_global_groups( $global_groups );
663
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
814
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );
665
wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
816
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
731
882
if ( is_array( $global_groups ) ) {
732
883
wp_cache_add_global_groups( $global_groups );
734
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
885
wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );
736
wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
887
wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
1064
* Retrieves a list of networks.
1068
* @param string|array $args Optional. Array or string of arguments. See WP_Network_Query::parse_query()
1069
* for information on accepted arguments. Default empty array.
1070
* @return int|array List of networks or number of found networks if `$count` argument is true.
1072
function get_networks( $args = array() ) {
1073
$query = new WP_Network_Query();
1075
return $query->query( $args );
1079
* Retrieves network data given a network ID or network object.
1081
* Network data will be cached and returned after being passed through a filter.
1082
* If the provided network is empty, the current network global will be used.
1086
* @global WP_Network $current_site
1088
* @param WP_Network|int|null $network Optional. Network to retrieve. Default is the current network.
1089
* @return WP_Network|null The network object or null if not found.
1091
function get_network( $network = null ) {
1092
global $current_site;
1093
if ( empty( $network ) && isset( $current_site ) ) {
1094
$network = $current_site;
1097
if ( $network instanceof WP_Network ) {
1098
$_network = $network;
1099
} elseif ( is_object( $network ) ) {
1100
$_network = new WP_Network( $network );
1102
$_network = WP_Network::get_instance( $network );
1105
if ( ! $_network ) {
1110
* Fires after a network is retrieved.
1114
* @param WP_Network $_network Network data.
1116
$_network = apply_filters( 'get_network', $_network );
1122
* Removes a network from the object cache.
1126
* @param int|array $ids Network ID or an array of network IDs to remove from cache.
1128
function clean_network_cache( $ids ) {
1129
foreach ( (array) $ids as $id ) {
1130
wp_cache_delete( $id, 'networks' );
1133
* Fires immediately after a network has been removed from the object cache.
1137
* @param int $id Network ID.
1139
do_action( 'clean_network_cache', $id );
1142
wp_cache_set( 'last_changed', microtime(), 'networks' );
1146
* Updates the network cache of given networks.
1148
* Will add the networks in $networks to the cache. If network ID already exists
1149
* in the network cache then it will not be updated. The network is added to the
1150
* cache using the network group with the key using the ID of the networks.
1154
* @param array $networks Array of network row objects.
1156
function update_network_cache( $networks ) {
1157
foreach ( (array) $networks as $network ) {
1158
wp_cache_add( $network->id, $network, 'networks' );
1163
* Adds any networks from the given IDs to the cache that do not already exist in cache.
1168
* @see update_network_cache()
1169
* @global wpdb $wpdb WordPress database abstraction object.
1171
* @param array $network_ids Array of network IDs.
1173
function _prime_network_caches( $network_ids ) {
1176
$non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' );
1177
if ( !empty( $non_cached_ids ) ) {
1178
$fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
1180
update_network_cache( $fresh_networks );
913
1185
* Handler for updating the blog date when a post is published or an already published post is changed.