返回介绍

update_blog_details()

发布于 2017-09-11 11:02:04 字数 5392 浏览 1003 评论 0 收藏 0

update_blog_details( int $blog_id,  array $details = array() )

Update the details for a blog. Updates the blogs table for a given blog id.


description


参数

$blog_id

(int) (Required) Blog ID

$details

(array) (Optional) Array of details keyed by blogs table field names.

Default value: array()


返回值

(bool) True if update succeeds, false otherwise.


源代码

File: wp-includes/ms-blogs.php

function update_blog_details( $blog_id, $details = array() ) {
	global $wpdb;

	if ( empty($details) )
		return false;

	if ( is_object($details) )
		$details = get_object_vars($details);

	$current_details = get_site( $blog_id );
	if ( empty($current_details) )
		return false;

	$current_details = get_object_vars($current_details);

	$details = array_merge($current_details, $details);
	$details['last_updated'] = current_time('mysql', true);

	$update_details = array();
	$fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
	foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) {
		if ( 'path' === $field ) {
			$details[ $field ] = trailingslashit( '/' . trim( $details[ $field ], '/' ) );
		}

		$update_details[ $field ] = $details[ $field ];
	}

	$result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );

	if ( false === $result )
		return false;

	// If spam status changed, issue actions.
	if ( $details['spam'] != $current_details['spam'] ) {
		if ( $details['spam'] == 1 ) {
			/**
			 * Fires when the 'spam' status is added to a blog.
			 *
			 * @since MU
			 *
			 * @param int $blog_id Blog ID.
			 */
			do_action( 'make_spam_blog', $blog_id );
		} else {
			/**
			 * Fires when the 'spam' status is removed from a blog.
			 *
			 * @since MU
			 *
			 * @param int $blog_id Blog ID.
			 */
			do_action( 'make_ham_blog', $blog_id );
		}
	}

	// If mature status changed, issue actions.
	if ( $details['mature'] != $current_details['mature'] ) {
		if ( $details['mature'] == 1 ) {
			/**
			 * Fires when the 'mature' status is added to a blog.
			 *
			 * @since 3.1.0
			 *
			 * @param int $blog_id Blog ID.
			 */
			do_action( 'mature_blog', $blog_id );
		} else {
			/**
			 * Fires when the 'mature' status is removed from a blog.
			 *
			 * @since 3.1.0
			 *
			 * @param int $blog_id Blog ID.
			 */
			do_action( 'unmature_blog', $blog_id );
		}
	}

	// If archived status changed, issue actions.
	if ( $details['archived'] != $current_details['archived'] ) {
		if ( $details['archived'] == 1 ) {
			/**
			 * Fires when the 'archived' status is added to a blog.
			 *
			 * @since MU
			 *
			 * @param int $blog_id Blog ID.
			 */
			do_action( 'archive_blog', $blog_id );
		} else {
			/**
			 * Fires when the 'archived' status is removed from a blog.
			 *
			 * @since MU
			 *
			 * @param int $blog_id Blog ID.
			 */
			do_action( 'unarchive_blog', $blog_id );
		}
	}

	// If deleted status changed, issue actions.
	if ( $details['deleted'] != $current_details['deleted'] ) {
		if ( $details['deleted'] == 1 ) {
			/**
			 * Fires when the 'deleted' status is added to a blog.
			 *
			 * @since 3.5.0
			 *
			 * @param int $blog_id Blog ID.
			 */
			do_action( 'make_delete_blog', $blog_id );
		} else {
			/**
			 * Fires when the 'deleted' status is removed from a blog.
			 *
			 * @since 3.5.0
			 *
			 * @param int $blog_id Blog ID.
			 */
			do_action( 'make_undelete_blog', $blog_id );
		}
	}

	if ( isset( $details['public'] ) ) {
		switch_to_blog( $blog_id );
		update_option( 'blog_public', $details['public'] );
		restore_current_blog();
	}

	refresh_blog_details($blog_id);

	return true;
}

更新日志

Versiondescription
MUIntroduced.

相关函数

Uses

  • wp-includes/ms-blogs.php: get_site()
  • wp-includes/formatting.php: trailingslashit()
  • wp-includes/functions.php: current_time()
  • wp-includes/plugin.php: do_action()
  • wp-includes/option.php: update_option()
  • wp-includes/ms-blogs.php: switch_to_blog()
  • wp-includes/ms-blogs.php: restore_current_blog()
  • wp-includes/ms-blogs.php: refresh_blog_details()
  • wp-includes/ms-blogs.php: make_spam_blog
  • wp-includes/ms-blogs.php: make_ham_blog
  • wp-includes/ms-blogs.php: mature_blog
  • wp-includes/ms-blogs.php: unmature_blog
  • wp-includes/ms-blogs.php: archive_blog
  • wp-includes/ms-blogs.php: unarchive_blog
  • wp-includes/ms-blogs.php: make_delete_blog
  • wp-includes/ms-blogs.php: make_undelete_blog
  • wp-includes/wp-db.php: wpdb::update()
  • Show 12 more uses Hide more uses

Used By

  • wp-includes/ms-blogs.php: wpmu_update_blogs_date()

User Contributed Notes

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

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

发布评论

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