get_editable_roles() - WordPress 函数参考中文文档

返回介绍

get_editable_roles()

发布于 2017-09-10 字数2800 浏览 975 评论 0

get_editable_roles()

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


描述

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;
}

更新日志

Version 描述
2.8.0 Introduced.

相关函数

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>
    

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!