钩子文档

add_user_role

💡 云策文档标注

概述

add_user_role 是一个 WordPress 动作钩子,在用户被赋予新角色后立即触发,用于开发者执行自定义操作。

关键要点

  • 触发时机:用户获得新角色后立即执行
  • 参数:$user_id(用户ID,整数类型)和 $role(新角色,字符串类型)
  • 相关函数:与 WP_User::add_role() 和 WP_User::set_role() 关联
  • 版本历史:从 WordPress 4.3.0 版本引入

📄 原文内容

Fires immediately after the user has been given a new role.

Parameters

$user_idint
The user ID.
$rolestring
The new role.

Source

do_action( 'add_user_role', $this->ID, $role );

Changelog

Version Description
4.3.0 Introduced.