wp_set_current_user()
wp_set_current_user( int $id, string $name = ” ) 按ID或名称…
wp_set_current_user( int $id, string $name = ” )
按ID或名称更改当前用户。
Changes the current user by ID or name.
按ID或名称更改当前用户。
Changes the current user by ID or name.
目录锚点:#说明#参数#源码#笔记
说明(Description)
如果不知道用户的id,请将$id设置为null并指定一个名称。某些WordPress功能基于当前用户,而不是基于已登录用户。因此,它打开了对未登录的用户进行编辑和执行操作的功能。
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $id | (int) | 用户ID |
| $name | (string) | 用户的用户名 |
源码(Source)
/**
* Changes the current user by ID or name.
*
* Set $id to null and specify a name if you do not know a user's ID.
*
* Some WordPress functionality is based on the current user and not based on
* the signed in user. Therefore, it opens the ability to edit and perform
* actions on users who aren't signed in.
*
* @since 2.0.3
* @global WP_User $current_user The current user object which holds the user data.
*
* @param int $id User ID
* @param string $name User's username
* @return WP_User Current user User object
*/
function wp_set_current_user($id, $name = '') {
global $current_user;
if ( isset( $current_user ) && ( $current_user instanceof WP_User ) && ( $id == $current_user->ID ) )
return $current_user;
$current_user = new WP_User( $id, $name );
setup_userdata( $current_user->ID );
/**
* Fires after the current user is set.
*
* @since 2.0.1
*/
do_action( 'set_current_user' );
return $current_user;
}
endif;
if ( !function_exists('wp_get_current_user') ) :| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.0.3 | wp-includes/pluggable.php | 17 | 20 |
笔记(Notes)
注意!
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!