wp_load_core_site_options

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

WordPress Version: 6.3

/**
 * Loads and primes caches of certain often requested network options if is_multisite().
 *
 * @since 3.0.0
 * @since 6.3.0 Also prime caches for network options when persistent object cache is enabled.
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int $network_id Optional. Network ID of network for which to prime network options cache. Defaults to current network.
 */
function wp_load_core_site_options($network_id = null)
{
    global $wpdb;
    if (!is_multisite() || wp_installing()) {
        return;
    }
    if (empty($network_id)) {
        $network_id = get_current_network_id();
    }
    $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting');
    if (wp_using_ext_object_cache()) {
        $cache_keys = array();
        foreach ($core_options as $option) {
            $cache_keys[] = "{$network_id}:{$option}";
        }
        wp_cache_get_multiple($cache_keys, 'site-options');
        return;
    }
    $core_options_in = "'" . implode("', '", $core_options) . "'";
    $options = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$core_options_in}) AND site_id = %d", $network_id));
    $data = array();
    foreach ($options as $option) {
        $key = $option->meta_key;
        $cache_key = "{$network_id}:{$key}";
        $option->meta_value = maybe_unserialize($option->meta_value);
        $data[$cache_key] = $option->meta_value;
    }
    wp_cache_set_multiple($data, 'site-options');
}

WordPress Version: 6.1

/**
 * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
 *
 * @since 3.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int $network_id Optional site ID for which to query the options. Defaults to the current site.
 */
function wp_load_core_site_options($network_id = null)
{
    global $wpdb;
    if (!is_multisite() || wp_using_ext_object_cache() || wp_installing()) {
        return;
    }
    if (empty($network_id)) {
        $network_id = get_current_network_id();
    }
    $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting');
    $core_options_in = "'" . implode("', '", $core_options) . "'";
    $options = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$core_options_in}) AND site_id = %d", $network_id));
    $data = array();
    foreach ($options as $option) {
        $key = $option->meta_key;
        $cache_key = "{$network_id}:{$key}";
        $option->meta_value = maybe_unserialize($option->meta_value);
        $data[$cache_key] = $option->meta_value;
    }
    wp_cache_set_multiple($data, 'site-options');
}

WordPress Version: 4.9

/**
 * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
 *
 * @since 3.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int $network_id Optional site ID for which to query the options. Defaults to the current site.
 */
function wp_load_core_site_options($network_id = null)
{
    global $wpdb;
    if (!is_multisite() || wp_using_ext_object_cache() || wp_installing()) {
        return;
    }
    if (empty($network_id)) {
        $network_id = get_current_network_id();
    }
    $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting');
    $core_options_in = "'" . implode("', '", $core_options) . "'";
    $options = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$core_options_in}) AND site_id = %d", $network_id));
    foreach ($options as $option) {
        $key = $option->meta_key;
        $cache_key = "{$network_id}:{$key}";
        $option->meta_value = maybe_unserialize($option->meta_value);
        wp_cache_set($cache_key, $option->meta_value, 'site-options');
    }
}

WordPress Version: 4.4

/**
 * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
 *
 * @since 3.0.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int $site_id Optional site ID for which to query the options. Defaults to the current site.
 */
function wp_load_core_site_options($site_id = null)
{
    global $wpdb;
    if (!is_multisite() || wp_using_ext_object_cache() || wp_installing()) {
        return;
    }
    if (empty($site_id)) {
        $site_id = $wpdb->siteid;
    }
    $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting');
    $core_options_in = "'" . implode("', '", $core_options) . "'";
    $options = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$core_options_in}) AND site_id = %d", $site_id));
    foreach ($options as $option) {
        $key = $option->meta_key;
        $cache_key = "{$site_id}:{$key}";
        $option->meta_value = maybe_unserialize($option->meta_value);
        wp_cache_set($cache_key, $option->meta_value, 'site-options');
    }
}

WordPress Version: 4.3

/**
 * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
 *
 * @since 3.0.0
 *
 * @global wpdb $wpdb
 *
 * @param int $site_id Optional site ID for which to query the options. Defaults to the current site.
 */
function wp_load_core_site_options($site_id = null)
{
    global $wpdb;
    if (!is_multisite() || wp_using_ext_object_cache() || defined('WP_INSTALLING')) {
        return;
    }
    if (empty($site_id)) {
        $site_id = $wpdb->siteid;
    }
    $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting');
    $core_options_in = "'" . implode("', '", $core_options) . "'";
    $options = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$core_options_in}) AND site_id = %d", $site_id));
    foreach ($options as $option) {
        $key = $option->meta_key;
        $cache_key = "{$site_id}:{$key}";
        $option->meta_value = maybe_unserialize($option->meta_value);
        wp_cache_set($cache_key, $option->meta_value, 'site-options');
    }
}

WordPress Version: 3.9

/**
 * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
 *
 * @since 3.0.0
 *
 * @param int $site_id Optional site ID for which to query the options. Defaults to the current site.
 */
function wp_load_core_site_options($site_id = null)
{
    global $wpdb;
    if (!is_multisite() || wp_using_ext_object_cache() || defined('WP_INSTALLING')) {
        return;
    }
    if (empty($site_id)) {
        $site_id = $wpdb->siteid;
    }
    $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting');
    $core_options_in = "'" . implode("', '", $core_options) . "'";
    $options = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$core_options_in}) AND site_id = %d", $site_id));
    foreach ($options as $option) {
        $key = $option->meta_key;
        $cache_key = "{$site_id}:{$key}";
        $option->meta_value = maybe_unserialize($option->meta_value);
        wp_cache_set($cache_key, $option->meta_value, 'site-options');
    }
}

WordPress Version: 3.7

/**
 * Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.
 *
 * @since 3.0.0
 * @package WordPress
 * @subpackage Option
 *
 * @param int $site_id Optional site ID for which to query the options. Defaults to the current site.
 */
function wp_load_core_site_options($site_id = null)
{
    global $wpdb;
    if (!is_multisite() || wp_using_ext_object_cache() || defined('WP_INSTALLING')) {
        return;
    }
    if (empty($site_id)) {
        $site_id = $wpdb->siteid;
    }
    $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting');
    $core_options_in = "'" . implode("', '", $core_options) . "'";
    $options = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$core_options_in}) AND site_id = %d", $site_id));
    foreach ($options as $option) {
        $key = $option->meta_key;
        $cache_key = "{$site_id}:{$key}";
        $option->meta_value = maybe_unserialize($option->meta_value);
        wp_cache_set($cache_key, $option->meta_value, 'site-options');
    }
}