restore_current_blog()
restore_current_blog() 调用switch_to_blog()后还原当前日志。Restor…
restore_current_blog()
调用switch_to_blog()后还原当前日志。
Restore the current blog, after calling switch_to_blog().
目录锚点:#说明#返回#源码
说明(Description)
另见函数 switch_to_blog()
返回(Return)
(bool)成功时为真,如果我们已经在当前博客上,则为假。
源码(Source)
/** * Restore the current blog, after calling switch_to_blog() * * @see switch_to_blog() * @since MU * * @global wpdb $wpdb * @global array $_wp_switched_stack * @global int $blog_id * @global bool $switched * @global string $table_prefix * @global WP_Object_Cache $wp_object_cache * * @return bool True on success, false if we're already on the current blog */ function restore_current_blog() { global $wpdb; 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', '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' ) ); } } 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; }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
MU (3.0.0) | wp-includes/ms-blogs.php:571 | 34 | 9 |
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!