钩子文档

wp_roles_init

💡 云策文档标注

概述

wp_roles_init 是一个 WordPress 动作钩子,在角色初始化后触发,允许插件添加自定义角色。

关键要点

  • 触发时机:在 WP_Roles 对象初始化所有可用角色后执行
  • 主要用途:插件开发者可以利用此钩子添加或修改角色
  • 参数:传递 $wp_roles 参数,即 WP_Roles 对象的引用
  • 版本:从 WordPress 4.7.0 版本开始引入

代码示例

do_action( 'wp_roles_init', $this );

注意事项

  • 此钩子位于 WP_Roles::init_roles() 方法中,用于初始化角色
  • 相关文件:wp-includes/class-wp-roles.php

📄 原文内容

Fires after the roles have been initialized, allowing plugins to add their own roles.

Parameters

$wp_rolesWP_Roles
A reference to the WP_Roles object.

Source

do_action( 'wp_roles_init', $this );

Changelog

Version Description
4.7.0 Introduced.