本文整理汇总了PHP中wp_cache_switch_to_blog函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_cache_switch_to_blog函数的具体用法?PHP wp_cache_switch_to_blog怎么用?PHP wp_cache_switch_to_blog使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_cache_switch_to_blog函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: switch_to_blog
/**
* Cache-safe switching in case any multi-site hiccups might occur.
* Clears the cache after switching to the given blog to avoid using
* another blog's cached values.
* See wp_cache_reset() in wp-includes/cache.php
* @see wp_cache_reset()
* @link http://core.trac.wordpress.org/ticket/14941
*
* @param int $blog_id
*/
public static function switch_to_blog($blog_id)
{
switch_to_blog($blog_id);
if (function_exists('wp_cache_switch_to_blog')) {
wp_cache_switch_to_blog($blog_id);
// introduced in WP 3.5.0
} else {
wp_cache_reset();
// deprecated in WP 3.5.0
}
}
示例2: wp_start_object_cache
/**
* Start the WordPress object cache.
*
* If an object-cache.php file exists in the wp-content directory,
* it uses that drop-in as an external object cache.
*
* @since 3.0.0
* @access private
*
* @global int $blog_id Blog ID.
*/
function wp_start_object_cache()
{
global $blog_id;
$first_init = false;
if (!function_exists('wp_cache_init')) {
if (file_exists(WP_CONTENT_DIR . '/object-cache.php')) {
require_once WP_CONTENT_DIR . '/object-cache.php';
if (function_exists('wp_cache_init')) {
wp_using_ext_object_cache(true);
}
}
$first_init = true;
} elseif (!wp_using_ext_object_cache() && file_exists(WP_CONTENT_DIR . '/object-cache.php')) {
/*
* Sometimes advanced-cache.php can load object-cache.php before
* it is loaded here. This breaks the function_exists check above
* and can result in `$_wp_using_ext_object_cache` being set
* incorrectly. Double check if an external cache exists.
*/
wp_using_ext_object_cache(true);
}
if (!wp_using_ext_object_cache()) {
require_once ABSPATH . WPINC . '/cache.php';
}
/*
* If cache supports reset, reset instead of init if already
* initialized. Reset signals to the cache that global IDs
* have changed and it may need to update keys and cleanup caches.
*/
if (!$first_init && function_exists('wp_cache_switch_to_blog')) {
wp_cache_switch_to_blog($blog_id);
} elseif (function_exists('wp_cache_init')) {
wp_cache_init();
}
if (function_exists('wp_cache_add_global_groups')) {
wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache'));
wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins'));
}
}
示例3: restore_current_blog
/**
* Restore the current blog, after calling switch_to_blog()
*
* @see switch_to_blog()
* @since MU
*
* @return bool True on success, false if we're already on the current blog
*/
function restore_current_blog()
{
global $wpdb, $wp_roles;
if (empty($GLOBALS['_wp_switched_stack'])) {
return false;
}
$blog = array_pop($GLOBALS['_wp_switched_stack']);
if ($GLOBALS['blog_id'] == $blog) {
/** This filter is documented in wp-includes/ms-blogs.php */
do_action('switch_blog', $blog, $blog);
// If we still have items in the switched stack, consider ourselves still 'switched'
$GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
return true;
}
$wpdb->set_blog_id($blog);
$prev_blog_id = $GLOBALS['blog_id'];
$GLOBALS['blog_id'] = $blog;
$GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
if (function_exists('wp_cache_switch_to_blog')) {
wp_cache_switch_to_blog($blog);
} else {
global $wp_object_cache;
if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
$global_groups = $wp_object_cache->global_groups;
} else {
$global_groups = false;
}
wp_cache_init();
if (function_exists('wp_cache_add_global_groups')) {
if (is_array($global_groups)) {
wp_cache_add_global_groups($global_groups);
} else {
wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache'));
}
wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins'));
}
}
if (did_action('init')) {
$wp_roles->reinit();
$current_user = wp_get_current_user();
$current_user->for_blog($blog);
}
/** This filter is documented in wp-includes/ms-blogs.php */
do_action('switch_blog', $blog, $prev_blog_id);
// If we still have items in the switched stack, consider ourselves still 'switched'
$GLOBALS['switched'] = !empty($GLOBALS['_wp_switched_stack']);
return true;
}
示例4: restore_current_blog
/**
* Restore the current blog, after calling switch_to_blog()
*
* @see switch_to_blog()
* @since MU
*
* @return bool True on success, False if we're already on the current blog
*/
function restore_current_blog()
{
global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
if (!$switched) {
return false;
}
if (!is_array($switched_stack)) {
return false;
}
$blog = array_pop($switched_stack);
if ($blog_id == $blog) {
do_action('switch_blog', $blog, $blog);
/* If we still have items in the switched stack, consider ourselves still 'switched' */
$switched = is_array($switched_stack) && count($switched_stack) > 0;
return true;
}
$wpdb->set_blog_id($blog);
$prev_blog_id = $blog_id;
$blog_id = $blog;
$table_prefix = $wpdb->prefix;
if (is_object($wp_roles)) {
$wpdb->suppress_errors();
if (method_exists($wp_roles, '_init')) {
$wp_roles->_init();
} elseif (method_exists($wp_roles, '__construct')) {
$wp_roles->__construct();
}
$wpdb->suppress_errors(false);
}
if (did_action('init')) {
$current_user = wp_get_current_user();
if (is_object($current_user)) {
$current_user->for_blog($blog_id);
}
}
if (function_exists('wp_cache_switch_to_blog')) {
wp_cache_switch_to_blog($blog_id);
} else {
if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) {
$global_groups = $wp_object_cache->global_groups;
} else {
$global_groups = false;
}
wp_cache_init();
if (function_exists('wp_cache_add_global_groups')) {
if (is_array($global_groups)) {
wp_cache_add_global_groups($global_groups);
} else {
wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts'));
}
wp_cache_add_non_persistent_groups(array('comment', 'counts', 'plugins'));
}
}
do_action('switch_blog', $blog_id, $prev_blog_id);
/* If we still have items in the switched stack, consider ourselves still 'switched' */
$switched = is_array($switched_stack) && count($switched_stack) > 0;
return true;
}