is_user_member_of_blog()确定用户是否属于本博客(多站点)

目录

描述

Find out whether a user is a member of a given blog.

is_user_member_of_blog() 描述

用法

<?php is_user_member_of_blog$user_id$blog_id ); ?>

is_user_member_of_blog() 用法

参数

$user_id

(integer) (可选) User ID to check membership

默认值: current user

$blog_id

(integer) (可选) Blog ID to check membership

默认值: current blog

is_user_member_of_blog() 参数

示例

Check if the current user is a member of blog 5:

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

<?php

$user_id = get_current_user_id();
$blog_id = 5;

if ( is_user_member_of_blog( $user_id, $blog_id ) ) {

   /*
    * The user is a member of the blog with ID 5.
    * We could do stuff here, like show them a link, etc.
    */
}

?>

is_user_member_of_blog() 示例

历史

添加于 版本: MU

is_user_member_of_blog() 历史

源文件

is_user_member_of_blog() 函数的代码位于 wp-includes/user.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Find out whether a user is a member of a given blog.
 *
 * @since MU 1.1
 *
 * @param int $user_id Optional. The unique ID of the user. Defaults to the current user.
 * @param int $blog_id Optional. ID of the blog to check. Defaults to the current site.
 * @return bool
 */
function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) {
	$user_id = (int) $user_id;
	$blog_id = (int) $blog_id;

	if ( empty( $user_id ) )
		$user_id = get_current_user_id();

	if ( empty( $blog_id ) )
		$blog_id = get_current_blog_id();

	$blogs = get_blogs_of_user( $user_id );
	return array_key_exists( $blog_id, $blogs );
}

is_user_member_of_blog() 源文件

相关