Edit File by line
/home/barbar84/public_h.../wp-inclu...
File: ms-site.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Site API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Multisite
[5] Fix | Delete
* @since 5.1.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Inserts a new site into the database.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 5.1.0
[12] Fix | Delete
*
[13] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[14] Fix | Delete
*
[15] Fix | Delete
* @param array $data {
[16] Fix | Delete
* Data for the new site that should be inserted.
[17] Fix | Delete
*
[18] Fix | Delete
* @type string $domain Site domain. Default empty string.
[19] Fix | Delete
* @type string $path Site path. Default '/'.
[20] Fix | Delete
* @type int $network_id The site's network ID. Default is the current network ID.
[21] Fix | Delete
* @type string $registered When the site was registered, in SQL datetime format. Default is
[22] Fix | Delete
* the current time.
[23] Fix | Delete
* @type string $last_updated When the site was last updated, in SQL datetime format. Default is
[24] Fix | Delete
* the value of $registered.
[25] Fix | Delete
* @type int $public Whether the site is public. Default 1.
[26] Fix | Delete
* @type int $archived Whether the site is archived. Default 0.
[27] Fix | Delete
* @type int $mature Whether the site is mature. Default 0.
[28] Fix | Delete
* @type int $spam Whether the site is spam. Default 0.
[29] Fix | Delete
* @type int $deleted Whether the site is deleted. Default 0.
[30] Fix | Delete
* @type int $lang_id The site's language ID. Currently unused. Default 0.
[31] Fix | Delete
* @type int $user_id User ID for the site administrator. Passed to the
[32] Fix | Delete
* `wp_initialize_site` hook.
[33] Fix | Delete
* @type string $title Site title. Default is 'Site %d' where %d is the site ID. Passed
[34] Fix | Delete
* to the `wp_initialize_site` hook.
[35] Fix | Delete
* @type array $options Custom option $key => $value pairs to use. Default empty array. Passed
[36] Fix | Delete
* to the `wp_initialize_site` hook.
[37] Fix | Delete
* @type array $meta Custom site metadata $key => $value pairs to use. Default empty array.
[38] Fix | Delete
* Passed to the `wp_initialize_site` hook.
[39] Fix | Delete
* }
[40] Fix | Delete
* @return int|WP_Error The new site's ID on success, or error object on failure.
[41] Fix | Delete
*/
[42] Fix | Delete
function wp_insert_site( array $data ) {
[43] Fix | Delete
global $wpdb;
[44] Fix | Delete
[45] Fix | Delete
$now = current_time( 'mysql', true );
[46] Fix | Delete
[47] Fix | Delete
$defaults = array(
[48] Fix | Delete
'domain' => '',
[49] Fix | Delete
'path' => '/',
[50] Fix | Delete
'network_id' => get_current_network_id(),
[51] Fix | Delete
'registered' => $now,
[52] Fix | Delete
'last_updated' => $now,
[53] Fix | Delete
'public' => 1,
[54] Fix | Delete
'archived' => 0,
[55] Fix | Delete
'mature' => 0,
[56] Fix | Delete
'spam' => 0,
[57] Fix | Delete
'deleted' => 0,
[58] Fix | Delete
'lang_id' => 0,
[59] Fix | Delete
);
[60] Fix | Delete
[61] Fix | Delete
$prepared_data = wp_prepare_site_data( $data, $defaults );
[62] Fix | Delete
if ( is_wp_error( $prepared_data ) ) {
[63] Fix | Delete
return $prepared_data;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
if ( false === $wpdb->insert( $wpdb->blogs, $prepared_data ) ) {
[67] Fix | Delete
return new WP_Error( 'db_insert_error', __( 'Could not insert site into the database.' ), $wpdb->last_error );
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
$site_id = (int) $wpdb->insert_id;
[71] Fix | Delete
[72] Fix | Delete
clean_blog_cache( $site_id );
[73] Fix | Delete
[74] Fix | Delete
$new_site = get_site( $site_id );
[75] Fix | Delete
[76] Fix | Delete
if ( ! $new_site ) {
[77] Fix | Delete
return new WP_Error( 'get_site_error', __( 'Could not retrieve site data.' ) );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Fires once a site has been inserted into the database.
[82] Fix | Delete
*
[83] Fix | Delete
* @since 5.1.0
[84] Fix | Delete
*
[85] Fix | Delete
* @param WP_Site $new_site New site object.
[86] Fix | Delete
*/
[87] Fix | Delete
do_action( 'wp_insert_site', $new_site );
[88] Fix | Delete
[89] Fix | Delete
// Extract the passed arguments that may be relevant for site initialization.
[90] Fix | Delete
$args = array_diff_key( $data, $defaults );
[91] Fix | Delete
if ( isset( $args['site_id'] ) ) {
[92] Fix | Delete
unset( $args['site_id'] );
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Fires when a site's initialization routine should be executed.
[97] Fix | Delete
*
[98] Fix | Delete
* @since 5.1.0
[99] Fix | Delete
*
[100] Fix | Delete
* @param WP_Site $new_site New site object.
[101] Fix | Delete
* @param array $args Arguments for the initialization.
[102] Fix | Delete
*/
[103] Fix | Delete
do_action( 'wp_initialize_site', $new_site, $args );
[104] Fix | Delete
[105] Fix | Delete
// Only compute extra hook parameters if the deprecated hook is actually in use.
[106] Fix | Delete
if ( has_action( 'wpmu_new_blog' ) ) {
[107] Fix | Delete
$user_id = ! empty( $args['user_id'] ) ? $args['user_id'] : 0;
[108] Fix | Delete
$meta = ! empty( $args['options'] ) ? $args['options'] : array();
[109] Fix | Delete
[110] Fix | Delete
// WPLANG was passed with `$meta` to the `wpmu_new_blog` hook prior to 5.1.0.
[111] Fix | Delete
if ( ! array_key_exists( 'WPLANG', $meta ) ) {
[112] Fix | Delete
$meta['WPLANG'] = get_network_option( $new_site->network_id, 'WPLANG' );
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
// Rebuild the data expected by the `wpmu_new_blog` hook prior to 5.1.0 using allowed keys.
[116] Fix | Delete
// The `$allowed_data_fields` matches the one used in `wpmu_create_blog()`.
[117] Fix | Delete
$allowed_data_fields = array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' );
[118] Fix | Delete
$meta = array_merge( array_intersect_key( $data, array_flip( $allowed_data_fields ) ), $meta );
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Fires immediately after a new site is created.
[122] Fix | Delete
*
[123] Fix | Delete
* @since MU (3.0.0)
[124] Fix | Delete
* @deprecated 5.1.0 Use {@see 'wp_insert_site'} instead.
[125] Fix | Delete
*
[126] Fix | Delete
* @param int $site_id Site ID.
[127] Fix | Delete
* @param int $user_id User ID.
[128] Fix | Delete
* @param string $domain Site domain.
[129] Fix | Delete
* @param string $path Site path.
[130] Fix | Delete
* @param int $network_id Network ID. Only relevant on multi-network installations.
[131] Fix | Delete
* @param array $meta Meta data. Used to set initial site options.
[132] Fix | Delete
*/
[133] Fix | Delete
do_action_deprecated(
[134] Fix | Delete
'wpmu_new_blog',
[135] Fix | Delete
array( $new_site->id, $user_id, $new_site->domain, $new_site->path, $new_site->network_id, $meta ),
[136] Fix | Delete
'5.1.0',
[137] Fix | Delete
'wp_insert_site'
[138] Fix | Delete
);
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
return (int) $new_site->id;
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Updates a site in the database.
[146] Fix | Delete
*
[147] Fix | Delete
* @since 5.1.0
[148] Fix | Delete
*
[149] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[150] Fix | Delete
*
[151] Fix | Delete
* @param int $site_id ID of the site that should be updated.
[152] Fix | Delete
* @param array $data Site data to update. See {@see wp_insert_site()} for the list of supported keys.
[153] Fix | Delete
* @return int|WP_Error The updated site's ID on success, or error object on failure.
[154] Fix | Delete
*/
[155] Fix | Delete
function wp_update_site( $site_id, array $data ) {
[156] Fix | Delete
global $wpdb;
[157] Fix | Delete
[158] Fix | Delete
if ( empty( $site_id ) ) {
[159] Fix | Delete
return new WP_Error( 'site_empty_id', __( 'Site ID must not be empty.' ) );
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
$old_site = get_site( $site_id );
[163] Fix | Delete
if ( ! $old_site ) {
[164] Fix | Delete
return new WP_Error( 'site_not_exist', __( 'Site does not exist.' ) );
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
$defaults = $old_site->to_array();
[168] Fix | Delete
$defaults['network_id'] = (int) $defaults['site_id'];
[169] Fix | Delete
$defaults['last_updated'] = current_time( 'mysql', true );
[170] Fix | Delete
unset( $defaults['blog_id'], $defaults['site_id'] );
[171] Fix | Delete
[172] Fix | Delete
$data = wp_prepare_site_data( $data, $defaults, $old_site );
[173] Fix | Delete
if ( is_wp_error( $data ) ) {
[174] Fix | Delete
return $data;
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
if ( false === $wpdb->update( $wpdb->blogs, $data, array( 'blog_id' => $old_site->id ) ) ) {
[178] Fix | Delete
return new WP_Error( 'db_update_error', __( 'Could not update site in the database.' ), $wpdb->last_error );
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
clean_blog_cache( $old_site );
[182] Fix | Delete
[183] Fix | Delete
$new_site = get_site( $old_site->id );
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Fires once a site has been updated in the database.
[187] Fix | Delete
*
[188] Fix | Delete
* @since 5.1.0
[189] Fix | Delete
*
[190] Fix | Delete
* @param WP_Site $new_site New site object.
[191] Fix | Delete
* @param WP_Site $old_site Old site object.
[192] Fix | Delete
*/
[193] Fix | Delete
do_action( 'wp_update_site', $new_site, $old_site );
[194] Fix | Delete
[195] Fix | Delete
return (int) $new_site->id;
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Deletes a site from the database.
[200] Fix | Delete
*
[201] Fix | Delete
* @since 5.1.0
[202] Fix | Delete
*
[203] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[204] Fix | Delete
*
[205] Fix | Delete
* @param int $site_id ID of the site that should be deleted.
[206] Fix | Delete
* @return WP_Site|WP_Error The deleted site object on success, or error object on failure.
[207] Fix | Delete
*/
[208] Fix | Delete
function wp_delete_site( $site_id ) {
[209] Fix | Delete
global $wpdb;
[210] Fix | Delete
[211] Fix | Delete
if ( empty( $site_id ) ) {
[212] Fix | Delete
return new WP_Error( 'site_empty_id', __( 'Site ID must not be empty.' ) );
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
$old_site = get_site( $site_id );
[216] Fix | Delete
if ( ! $old_site ) {
[217] Fix | Delete
return new WP_Error( 'site_not_exist', __( 'Site does not exist.' ) );
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
$errors = new WP_Error();
[221] Fix | Delete
[222] Fix | Delete
/**
[223] Fix | Delete
* Fires before a site should be deleted from the database.
[224] Fix | Delete
*
[225] Fix | Delete
* Plugins should amend the `$errors` object via its `WP_Error::add()` method. If any errors
[226] Fix | Delete
* are present, the site will not be deleted.
[227] Fix | Delete
*
[228] Fix | Delete
* @since 5.1.0
[229] Fix | Delete
*
[230] Fix | Delete
* @param WP_Error $errors Error object to add validation errors to.
[231] Fix | Delete
* @param WP_Site $old_site The site object to be deleted.
[232] Fix | Delete
*/
[233] Fix | Delete
do_action( 'wp_validate_site_deletion', $errors, $old_site );
[234] Fix | Delete
[235] Fix | Delete
if ( ! empty( $errors->errors ) ) {
[236] Fix | Delete
return $errors;
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
/**
[240] Fix | Delete
* Fires before a site is deleted.
[241] Fix | Delete
*
[242] Fix | Delete
* @since MU (3.0.0)
[243] Fix | Delete
* @deprecated 5.1.0
[244] Fix | Delete
*
[245] Fix | Delete
* @param int $site_id The site ID.
[246] Fix | Delete
* @param bool $drop True if site's table should be dropped. Default false.
[247] Fix | Delete
*/
[248] Fix | Delete
do_action_deprecated( 'delete_blog', array( $old_site->id, true ), '5.1.0' );
[249] Fix | Delete
[250] Fix | Delete
/**
[251] Fix | Delete
* Fires when a site's uninitialization routine should be executed.
[252] Fix | Delete
*
[253] Fix | Delete
* @since 5.1.0
[254] Fix | Delete
*
[255] Fix | Delete
* @param WP_Site $old_site Deleted site object.
[256] Fix | Delete
*/
[257] Fix | Delete
do_action( 'wp_uninitialize_site', $old_site );
[258] Fix | Delete
[259] Fix | Delete
if ( is_site_meta_supported() ) {
[260] Fix | Delete
$blog_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->blogmeta WHERE blog_id = %d ", $old_site->id ) );
[261] Fix | Delete
foreach ( $blog_meta_ids as $mid ) {
[262] Fix | Delete
delete_metadata_by_mid( 'blog', $mid );
[263] Fix | Delete
}
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
if ( false === $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $old_site->id ) ) ) {
[267] Fix | Delete
return new WP_Error( 'db_delete_error', __( 'Could not delete site from the database.' ), $wpdb->last_error );
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
clean_blog_cache( $old_site );
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Fires once a site has been deleted from the database.
[274] Fix | Delete
*
[275] Fix | Delete
* @since 5.1.0
[276] Fix | Delete
*
[277] Fix | Delete
* @param WP_Site $old_site Deleted site object.
[278] Fix | Delete
*/
[279] Fix | Delete
do_action( 'wp_delete_site', $old_site );
[280] Fix | Delete
[281] Fix | Delete
/**
[282] Fix | Delete
* Fires after the site is deleted from the network.
[283] Fix | Delete
*
[284] Fix | Delete
* @since 4.8.0
[285] Fix | Delete
* @deprecated 5.1.0
[286] Fix | Delete
*
[287] Fix | Delete
* @param int $site_id The site ID.
[288] Fix | Delete
* @param bool $drop True if site's tables should be dropped. Default false.
[289] Fix | Delete
*/
[290] Fix | Delete
do_action_deprecated( 'deleted_blog', array( $old_site->id, true ), '5.1.0' );
[291] Fix | Delete
[292] Fix | Delete
return $old_site;
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
/**
[296] Fix | Delete
* Retrieves site data given a site ID or site object.
[297] Fix | Delete
*
[298] Fix | Delete
* Site data will be cached and returned after being passed through a filter.
[299] Fix | Delete
* If the provided site is empty, the current site global will be used.
[300] Fix | Delete
*
[301] Fix | Delete
* @since 4.6.0
[302] Fix | Delete
*
[303] Fix | Delete
* @param WP_Site|int|null $site Optional. Site to retrieve. Default is the current site.
[304] Fix | Delete
* @return WP_Site|null The site object or null if not found.
[305] Fix | Delete
*/
[306] Fix | Delete
function get_site( $site = null ) {
[307] Fix | Delete
if ( empty( $site ) ) {
[308] Fix | Delete
$site = get_current_blog_id();
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
if ( $site instanceof WP_Site ) {
[312] Fix | Delete
$_site = $site;
[313] Fix | Delete
} elseif ( is_object( $site ) ) {
[314] Fix | Delete
$_site = new WP_Site( $site );
[315] Fix | Delete
} else {
[316] Fix | Delete
$_site = WP_Site::get_instance( $site );
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
if ( ! $_site ) {
[320] Fix | Delete
return null;
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
/**
[324] Fix | Delete
* Fires after a site is retrieved.
[325] Fix | Delete
*
[326] Fix | Delete
* @since 4.6.0
[327] Fix | Delete
*
[328] Fix | Delete
* @param WP_Site $_site Site data.
[329] Fix | Delete
*/
[330] Fix | Delete
$_site = apply_filters( 'get_site', $_site );
[331] Fix | Delete
[332] Fix | Delete
return $_site;
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
/**
[336] Fix | Delete
* Adds any sites from the given IDs to the cache that do not already exist in cache.
[337] Fix | Delete
*
[338] Fix | Delete
* @since 4.6.0
[339] Fix | Delete
* @since 5.1.0 Introduced the `$update_meta_cache` parameter.
[340] Fix | Delete
* @access private
[341] Fix | Delete
*
[342] Fix | Delete
* @see update_site_cache()
[343] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[344] Fix | Delete
*
[345] Fix | Delete
* @param array $ids ID list.
[346] Fix | Delete
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true.
[347] Fix | Delete
*/
[348] Fix | Delete
function _prime_site_caches( $ids, $update_meta_cache = true ) {
[349] Fix | Delete
global $wpdb;
[350] Fix | Delete
[351] Fix | Delete
$non_cached_ids = _get_non_cached_ids( $ids, 'sites' );
[352] Fix | Delete
if ( ! empty( $non_cached_ids ) ) {
[353] Fix | Delete
$fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
[354] Fix | Delete
[355] Fix | Delete
update_site_cache( $fresh_sites, $update_meta_cache );
[356] Fix | Delete
}
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
/**
[360] Fix | Delete
* Updates sites in cache.
[361] Fix | Delete
*
[362] Fix | Delete
* @since 4.6.0
[363] Fix | Delete
* @since 5.1.0 Introduced the `$update_meta_cache` parameter.
[364] Fix | Delete
*
[365] Fix | Delete
* @param array $sites Array of site objects.
[366] Fix | Delete
* @param bool $update_meta_cache Whether to update site meta cache. Default true.
[367] Fix | Delete
*/
[368] Fix | Delete
function update_site_cache( $sites, $update_meta_cache = true ) {
[369] Fix | Delete
if ( ! $sites ) {
[370] Fix | Delete
return;
[371] Fix | Delete
}
[372] Fix | Delete
$site_ids = array();
[373] Fix | Delete
foreach ( $sites as $site ) {
[374] Fix | Delete
$site_ids[] = $site->blog_id;
[375] Fix | Delete
wp_cache_add( $site->blog_id, $site, 'sites' );
[376] Fix | Delete
wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' );
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
if ( $update_meta_cache ) {
[380] Fix | Delete
update_sitemeta_cache( $site_ids );
[381] Fix | Delete
}
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
/**
[385] Fix | Delete
* Updates metadata cache for list of site IDs.
[386] Fix | Delete
*
[387] Fix | Delete
* Performs SQL query to retrieve all metadata for the sites matching `$site_ids` and stores them in the cache.
[388] Fix | Delete
* Subsequent calls to `get_site_meta()` will not need to query the database.
[389] Fix | Delete
*
[390] Fix | Delete
* @since 5.1.0
[391] Fix | Delete
*
[392] Fix | Delete
* @param array $site_ids List of site IDs.
[393] Fix | Delete
* @return array|false An array of metadata on success, false if there is nothing to update.
[394] Fix | Delete
*/
[395] Fix | Delete
function update_sitemeta_cache( $site_ids ) {
[396] Fix | Delete
// Ensure this filter is hooked in even if the function is called early.
[397] Fix | Delete
if ( ! has_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' ) ) {
[398] Fix | Delete
add_filter( 'update_blog_metadata_cache', 'wp_check_site_meta_support_prefilter' );
[399] Fix | Delete
}
[400] Fix | Delete
return update_meta_cache( 'blog', $site_ids );
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
/**
[404] Fix | Delete
* Retrieves a list of sites matching requested arguments.
[405] Fix | Delete
*
[406] Fix | Delete
* @since 4.6.0
[407] Fix | Delete
* @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
[408] Fix | Delete
*
[409] Fix | Delete
* @see WP_Site_Query::parse_query()
[410] Fix | Delete
*
[411] Fix | Delete
* @param string|array $args {
[412] Fix | Delete
* Optional. Array or query string of site query parameters. Default empty.
[413] Fix | Delete
*
[414] Fix | Delete
* @type int[] $site__in Array of site IDs to include. Default empty.
[415] Fix | Delete
* @type int[] $site__not_in Array of site IDs to exclude. Default empty.
[416] Fix | Delete
* @type bool $count Whether to return a site count (true) or array of site objects.
[417] Fix | Delete
* Default false.
[418] Fix | Delete
* @type array $date_query Date query clauses to limit sites by. See WP_Date_Query.
[419] Fix | Delete
* Default null.
[420] Fix | Delete
* @type string $fields Site fields to return. Accepts 'ids' (returns an array of site IDs)
[421] Fix | Delete
* or empty (returns an array of complete site objects). Default empty.
[422] Fix | Delete
* @type int $ID A site ID to only return that site. Default empty.
[423] Fix | Delete
* @type int $number Maximum number of sites to retrieve. Default 100.
[424] Fix | Delete
* @type int $offset Number of sites to offset the query. Used to build LIMIT clause.
[425] Fix | Delete
* Default 0.
[426] Fix | Delete
* @type bool $no_found_rows Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
[427] Fix | Delete
* @type string|array $orderby Site status or array of statuses. Accepts 'id', 'domain', 'path',
[428] Fix | Delete
* 'network_id', 'last_updated', 'registered', 'domain_length',
[429] Fix | Delete
* 'path_length', 'site__in' and 'network__in'. Also accepts false,
[430] Fix | Delete
* an empty array, or 'none' to disable `ORDER BY` clause.
[431] Fix | Delete
* Default 'id'.
[432] Fix | Delete
* @type string $order How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
[433] Fix | Delete
* @type int $network_id Limit results to those affiliated with a given network ID. If 0,
[434] Fix | Delete
* include all networks. Default 0.
[435] Fix | Delete
* @type int[] $network__in Array of network IDs to include affiliated sites for. Default empty.
[436] Fix | Delete
* @type int[] $network__not_in Array of network IDs to exclude affiliated sites for. Default empty.
[437] Fix | Delete
* @type string $domain Limit results to those affiliated with a given domain. Default empty.
[438] Fix | Delete
* @type string[] $domain__in Array of domains to include affiliated sites for. Default empty.
[439] Fix | Delete
* @type string[] $domain__not_in Array of domains to exclude affiliated sites for. Default empty.
[440] Fix | Delete
* @type string $path Limit results to those affiliated with a given path. Default empty.
[441] Fix | Delete
* @type string[] $path__in Array of paths to include affiliated sites for. Default empty.
[442] Fix | Delete
* @type string[] $path__not_in Array of paths to exclude affiliated sites for. Default empty.
[443] Fix | Delete
* @type int $public Limit results to public sites. Accepts '1' or '0'. Default empty.
[444] Fix | Delete
* @type int $archived Limit results to archived sites. Accepts '1' or '0'. Default empty.
[445] Fix | Delete
* @type int $mature Limit results to mature sites. Accepts '1' or '0'. Default empty.
[446] Fix | Delete
* @type int $spam Limit results to spam sites. Accepts '1' or '0'. Default empty.
[447] Fix | Delete
* @type int $deleted Limit results to deleted sites. Accepts '1' or '0'. Default empty.
[448] Fix | Delete
* @type int $lang_id Limit results to a language ID. Default empty.
[449] Fix | Delete
* @type string[] $lang__in Array of language IDs to include affiliated sites for. Default empty.
[450] Fix | Delete
* @type string[] $lang__not_in Array of language IDs to exclude affiliated sites for. Default empty.
[451] Fix | Delete
* @type string $search Search term(s) to retrieve matching sites for. Default empty.
[452] Fix | Delete
* @type string[] $search_columns Array of column names to be searched. Accepts 'domain' and 'path'.
[453] Fix | Delete
* Default empty array.
[454] Fix | Delete
* @type bool $update_site_cache Whether to prime the cache for found sites. Default true.
[455] Fix | Delete
* }
[456] Fix | Delete
* @return array|int List of WP_Site objects, a list of site IDs when 'fields' is set to 'ids',
[457] Fix | Delete
* or the number of sites when 'count' is passed as a query var.
[458] Fix | Delete
*/
[459] Fix | Delete
function get_sites( $args = array() ) {
[460] Fix | Delete
$query = new WP_Site_Query();
[461] Fix | Delete
[462] Fix | Delete
return $query->query( $args );
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
/**
[466] Fix | Delete
* Prepares site data for insertion or update in the database.
[467] Fix | Delete
*
[468] Fix | Delete
* @since 5.1.0
[469] Fix | Delete
*
[470] Fix | Delete
* @param array $data Associative array of site data passed to the respective function.
[471] Fix | Delete
* See {@see wp_insert_site()} for the possibly included data.
[472] Fix | Delete
* @param array $defaults Site data defaults to parse $data against.
[473] Fix | Delete
* @param WP_Site|null $old_site Optional. Old site object if an update, or null if an insertion.
[474] Fix | Delete
* Default null.
[475] Fix | Delete
* @return array|WP_Error Site data ready for a database transaction, or WP_Error in case a validation
[476] Fix | Delete
* error occurred.
[477] Fix | Delete
*/
[478] Fix | Delete
function wp_prepare_site_data( $data, $defaults, $old_site = null ) {
[479] Fix | Delete
[480] Fix | Delete
// Maintain backward-compatibility with `$site_id` as network ID.
[481] Fix | Delete
if ( isset( $data['site_id'] ) ) {
[482] Fix | Delete
if ( ! empty( $data['site_id'] ) && empty( $data['network_id'] ) ) {
[483] Fix | Delete
$data['network_id'] = $data['site_id'];
[484] Fix | Delete
}
[485] Fix | Delete
unset( $data['site_id'] );
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
/**
[489] Fix | Delete
* Filters passed site data in order to normalize it.
[490] Fix | Delete
*
[491] Fix | Delete
* @since 5.1.0
[492] Fix | Delete
*
[493] Fix | Delete
* @param array $data Associative array of site data passed to the respective function.
[494] Fix | Delete
* See {@see wp_insert_site()} for the possibly included data.
[495] Fix | Delete
*/
[496] Fix | Delete
$data = apply_filters( 'wp_normalize_site_data', $data );
[497] Fix | Delete
[498] Fix | Delete
$allowed_data_fields = array( 'domain', 'path', 'network_id', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' );
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function