返回介绍

restore_current_blog()

发布于 2017-09-11 10:10:07 字数 5972 浏览 1104 评论 0 收藏 0

restore_current_blog()

Restore the current blog, after calling switch_to_blog()


description


返回值

(bool) True on success, false if we're already on the current blog


源代码

File: wp-includes/ms-blogs.php

function restore_current_blog() {
	global $wpdb, $wp_roles;

	if ( empty( $GLOBALS['_wp_switched_stack'] ) ) {
		return false;
	}

	$blog = array_pop( $GLOBALS['_wp_switched_stack'] );
	$blog_id = get_current_blog_id();

	if ( $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 = $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', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) );
			}
			wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
		}
	}

	if ( did_action( 'init' ) ) {
		$wp_roles = new WP_Roles();
		$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;
}

更新日志

Versiondescription
MUIntroduced.

相关函数

Uses

  • wp-includes/class-wp-roles.php: WP_Roles::__construct()
  • wp-includes/cache.php: wp_cache_switch_to_blog()
  • wp-includes/cache.php: wp_cache_init()
  • wp-includes/cache.php: wp_cache_add_global_groups()
  • wp-includes/cache.php: wp_cache_add_non_persistent_groups()
  • wp-includes/pluggable.php: wp_get_current_user()
  • wp-includes/load.php: get_current_blog_id()
  • wp-includes/plugin.php: do_action()
  • wp-includes/plugin.php: did_action()
  • wp-includes/ms-blogs.php: switch_blog
  • wp-includes/wp-db.php: wpdb::set_blog_id()
  • wp-includes/wp-db.php: wpdb::get_blog_prefix()
  • Show 7 more uses Hide more uses

Used By

  • wp-includes/class-wp-site.php: WP_Site::get_details()
  • wp-includes/general-template.php: has_custom_logo()
  • wp-includes/general-template.php: get_custom_logo()
  • wp-includes/general-template.php: get_site_icon_url()
  • wp-admin/includes/class-wp-ms-sites-list-table.php: WP_MS_Sites_List_Table::column_blogname()
  • wp-signup.php: confirm_another_blog_signup()
  • wp-admin/includes/ms.php: wpmu_delete_user()
  • wp-admin/includes/ms.php: upload_space_setting()
  • wp-admin/includes/ms.php: wpmu_delete_blog()
  • wp-admin/includes/class-wp-users-list-table.php: WP_Users_List_Table::get_views()
  • wp-includes/capabilities.php: current_user_can_for_blog()
  • wp-includes/class-wp-theme.php: WP_Theme::get_allowed_on_site()
  • wp-includes/link-template.php: get_home_url()
  • wp-includes/link-template.php: get_site_url()
  • wp-includes/admin-bar.php: wp_admin_bar_my_sites_menu()
  • wp-includes/ms-functions.php: wpmu_create_blog()
  • wp-includes/ms-functions.php: newblog_notify_siteadmin()
  • wp-includes/ms-functions.php: get_blog_post()
  • wp-includes/ms-functions.php: add_user_to_blog()
  • wp-includes/ms-functions.php: remove_user_from_blog()
  • wp-includes/ms-deprecated.php: create_empty_blog()
  • wp-includes/ms-functions.php: get_blog_permalink()
  • wp-includes/ms-blogs.php: update_blog_details()
  • wp-includes/ms-blogs.php: get_blog_option()
  • wp-includes/ms-blogs.php: add_blog_option()
  • wp-includes/ms-blogs.php: delete_blog_option()
  • wp-includes/ms-blogs.php: update_blog_option()
  • wp-includes/ms-blogs.php: get_blog_details()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getUsersBlogs()
  • Show 24 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex
    
    switch_to_blog( 5 );
    
    /* Do stuff */
    
    restore_current_blog();
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文