add_new_user_to_blog()添加一个新用户到博客(多站点)

目录

描述

Add a newly created user to the appropriate blog.

add_new_user_to_blog() 描述

用法

<?php add_new_user_to_blog$user_id$email$meta ?>

add_new_user_to_blog() 用法

参数

$user_id

(integer) (必填) The new user ID

默认值: None

$email

(string) (必填) New user's email

默认值: None

$meta

(array) (必填) Sign-up meta for a user. The 'add_to_blog' and 'new_role' fields are used.

默认值: None

add_new_user_to_blog() 参数

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

add_new_user_to_blog() 示例

注意

add_new_user_to_blog() 注意

历史

添加于 版本: MU (3.0.0)

add_new_user_to_blog() 历史

源文件

add_new_user_to_blog() 函数的代码位于 wp-includes/ms-functions.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Add a newly created user to the appropriate blog
 *
 * To add a user in general, use add_user_to_blog(). This function
 * is specifically hooked into the wpmu_activate_user action.
 *
 * @since MU
 * @see add_user_to_blog()
 *
 * @param int   $user_id
 * @param mixed $password Ignored.
 * @param array $meta
 */
function add_new_user_to_blog( $user_id, $password, $meta ) {
	if ( !empty( $meta[ 'add_to_blog' ] ) ) {
		$blog_id = $meta[ 'add_to_blog' ];
		$role = $meta[ 'new_role' ];
		remove_user_from_blog($user_id, get_current_site()->blog_id); // remove user from main blog.
		add_user_to_blog( $blog_id, $user_id, $role );
		update_user_meta( $user_id, 'primary_blog', $blog_id );
	}
}

add_new_user_to_blog() 源文件

相关