返回介绍

get_editable_roles()

发布于 2017-09-10 23:16:41 字数 2800 浏览 1098 评论 0 收藏 0

get_editable_roles()

Fetch a filtered list of user roles that the current user is allowed to edit.


description

Simple function who’s main purpose is to allow filtering of the list of roles in the $wp_roles object so that plugins can remove inappropriate ones depending on the situation or user making edits. Specifically because without filtering anyone with the edit_users capability can edit others to be administrators, even if they are only editors or authors. This filter allows admins to delegate user management.


返回值

(array)


源代码

File: wp-admin/includes/user.php

function get_editable_roles() {
	$all_roles = wp_roles()->roles;

	/**
	 * Filters the list of editable roles.
	 *
	 * @since 2.8.0
	 *
	 * @param array $all_roles List of roles.
	 */
	$editable_roles = apply_filters( 'editable_roles', $all_roles );

	return $editable_roles;
}

更新日志

Versiondescription
2.8.0Introduced.

相关函数

Uses

  • wp-includes/capabilities.php: wp_roles()
  • wp-admin/includes/user.php: editable_roles
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php: WP_REST_Users_Controller::check_role_update()
  • wp-admin/includes/user.php: edit_user()
  • wp-admin/includes/template.php: wp_dropdown_roles()
  • wp-admin/includes/user.php: admin_created_user_email()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Example

    Currently, you can assign the following roles:

    
    <dl>
      <?php foreach (get_editable_roles() as $role_name => $role_info): ?>
        <dt><?php echo $role_name ?></dt>
        <dd>
          <ul>
            <?php foreach ($role_info['capabilities'] as $capability => $_): ?>
              <li><?php echo $capability ?></li>
            <?php endforeach; ?>
          </ul>
        </dd>
      <?php endforeach; ?>
    </dl>
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文