wp_is_site_initialized

The timeline below displays how wordpress function wp_is_site_initialized has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.4

/**
 * Checks whether a site is initialized.
 *
 * A site is considered initialized when its database tables are present.
 *
 * @since 5.1.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|WP_Site $site_id Site ID or object.
 * @return bool True if the site is initialized, false otherwise.
 */
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;
}

WordPress Version: 5.1

/**
 * Checks whether a site is initialized.
 *
 * A site is considered initialized when its database tables are present.
 *
 * @since 5.1.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|WP_Site $site_id Site ID or object.
 * @return bool True if the site is initialized, false otherwise.
 */
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, if not null.
     * @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;
}