wp_load_core_site_options() WordPress Function

This function loads the site options for the current site. If the site options are not cached, they will be retrieved from the database and cached. This function is typically called during the loading of a site.

wp_load_core_site_options( int $network_id = null ) #

Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.


Parameters

$network_id

(int)(Optional)site ID for which to query the options. Defaults to the current site.

Default value: null


Top ↑

Source

File: wp-includes/option.php

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' );
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More