wp_load_core_site_options()
云策文档标注
概述
wp_load_core_site_options() 函数用于在多站点环境中加载和预缓存核心网络选项,以提高性能。它仅在 is_multisite() 返回 true 且不在安装模式下时执行。
关键要点
- 函数仅在多站点环境且非安装模式下运行,否则直接返回。
- 预缓存的核心选项包括 site_name、siteurl、active_sitewide_plugins 等常用网络设置。
- 通过调用 wp_prime_network_option_caches() 实现选项缓存,减少数据库查询。
- 可选参数 $network_id 指定网络 ID,默认为当前网络。
代码示例
function wp_load_core_site_options( $network_id = null ) {
if ( ! is_multisite() || wp_installing() ) {
return;
}
$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', 'WPLANG' );
wp_prime_network_option_caches( $network_id, $core_options );
}注意事项
- 此函数主要用于内部优化,开发者通常无需直接调用,但了解其机制有助于性能调优。
- 在启用持久对象缓存时,从 WordPress 6.3.0 版本起也支持预缓存网络选项。
原文内容
Loads and primes caches of certain often requested network options if is_multisite() .
Parameters
$network_idintoptional-
Network ID of network for which to prime network options cache. Defaults to current network.
Default:
null
Source
function wp_load_core_site_options( $network_id = null ) {
if ( ! is_multisite() || wp_installing() ) {
return;
}
$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', 'WPLANG' );
wp_prime_network_option_caches( $network_id, $core_options );
}
Changelog
| Version | Description |
|---|---|
| 6.6.0 | Uses wp_prime_network_option_caches() . |
| 6.3.0 | Also prime caches for network options when persistent object cache is enabled. |
| 3.0.0 | Introduced. |