wp_load_core_site_options

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

Description

wp_load_core_site_options( (null) $site_id = null ); 

Parameters (1)

0. $site_id — Optional. (null) => null
Site ID for which to query the options. Defaults to the current site.

Usage

  1. if ( !function_exists( 'wp_load_core_site_options' ) ) { 
  2. require_once ABSPATH . WPINC . '/option.php'; 
  3.  
  4. // Optional site ID for which to query the options. Defaults to the current site. 
  5. $site_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_load_core_site_options($site_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/option.php  
  1. function wp_load_core_site_options( $site_id = null ) { 
  2. global $wpdb; 
  3.  
  4. return; 
  5.  
  6. if ( empty($site_id) ) 
  7. $site_id = $wpdb->siteid; 
  8.  
  9. $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' ); 
  10.  
  11. $core_options_in = "'" . implode("', '", $core_options) . "'"; 
  12. $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) ); 
  13.  
  14. foreach ( $options as $option ) { 
  15. $key = $option->meta_key; 
  16. $cache_key = "{$site_id}:$key"; 
  17. $option->meta_value = maybe_unserialize( $option->meta_value ); 
  18.  
  19. wp_cache_set( $cache_key, $option->meta_value, 'site-options' );