On this page
wp_is_site_initialized( int|WP_Site $site_id ): bool
Checks whether a site is initialized.
Description
A site is considered initialized when its database tables are present.
Parameters
$site_idint|WP_Site Required-
Site ID or object.
Return
bool True if the site is initialized, false otherwise.
Source
File: wp-includes/ms-site.php. View all references
function wp_is_site_initialized( $site_id ) {
global $wpdb;
if ( is_object( $site_id ) ) {
$site_id = $site_id->blog_id;
}
$site_id = (int) $site_id;
/**
* Filters the check for whether a site is initialized before the database is accessed.
*
* Returning a non-null value will effectively short-circuit the function, returning
* that value instead.
*
* @since 5.1.0
*
* @param bool|null $pre The value to return instead. Default null
* to continue with the check.
* @param int $site_id The site ID that is being checked.
*/
$pre = apply_filters( 'pre_wp_is_site_initialized', null, $site_id );
if ( null !== $pre ) {
return (bool) $pre;
}
$switch = false;
if ( get_current_blog_id() !== $site_id ) {
$switch = true;
remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 );
switch_to_blog( $site_id );
}
$suppress = $wpdb->suppress_errors();
$result = (bool) $wpdb->get_results( "DESCRIBE {$wpdb->posts}" );
$wpdb->suppress_errors( $suppress );
if ( $switch ) {
restore_current_blog();
add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 );
}
return $result;
}
Hooks
- apply_filters( 'pre_wp_is_site_initialized',
bool|null $pre ,int $site_id ) -
Filters the check for whether a site is initialized before the database is accessed.
Related
Uses
| Uses | Description |
|---|---|
| remove_action() wp-includes/plugin.php | Removes a callback function from an action hook. |
| switch_to_blog() wp-includes/ms-blogs.php | Switch the current blog. |
| restore_current_blog() wp-includes/ms-blogs.php | Restore the current blog, after calling switch_to_blog() . |
| wpdb::suppress_errors() wp-includes/class-wpdb.php | Enables or disables suppressing of database errors. |
| get_current_blog_id() wp-includes/load.php | Retrieve the current site ID. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| add_action() wp-includes/plugin.php | Adds a callback function to an action hook. |
| wpdb::get_results() wp-includes/class-wpdb.php | Retrieves an entire SQL result set from the database (i.e., many rows). |
Used By
| Used By | Description |
|---|---|
| wp_update_blog_public_option_on_site_update() wp-includes/ms-site.php | Updates the |
| wp_initialize_site() wp-includes/ms-site.php | Runs the initialization routine for a given site. |
| wp_uninitialize_site() wp-includes/ms-site.php | Runs the uninitialization routine for a given site. |
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_is_site_initialized