[wp-trac] [WordPress Trac] #43420: Individual role array is $wp_roles->roles does not contain role slug

WordPress Trac noreply at wordpress.org
Mon Feb 26 15:52:12 UTC 2018


#43420: Individual role array is $wp_roles->roles does not contain role slug
------------------------------+-----------------------------
 Reporter:  subrataemfluence  |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Role/Capability   |    Version:  4.9.4
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 I don't find role in dump using the following


 {{{
 global $wp_roles;
 $roles = $wp_roles->roles;

 foreach( $roles as $role ) {
    var_dump( $role );
 }
 }}}


 `var_dump( $roll )` shows this:


 {{{
 array(2) { ["name"]=> string(11) "News Editor" ["capabilities"]=> array(3)
 { ["read"]=> bool(true) ["edit_posts"]=> bool(true) ["publish_posts"]=>
 bool(true) } }
 }}}


 On the other hand `var_dump( get_role( 'news-editor' ) );` retrieves the
 `WP_Role` object for the specified role dump comes up with the slug (news-
 editor).

 Question is why each role array inside `$wp_roles->roles` does not include
 the slug. If I have to iterate through all roles and do something with
 respective slug part of each role WordPress doesn't provide it for me.
 There could be many cases where I cannot directly use `get_role`.

 Can the `role_objects` array in `init_roles` function be generated with
 slug value of each role?


 {{{
 foreach ( array_keys( $this->roles ) as $role ) {
     $this->role_objects[ $role ] = new WP_Role( $role, $this->roles[ $role
 ]['capabilities'] );
     $this->role_names[ $role ] = $this->roles[ $role ]['name'];
 }
 }}}


 May be this has done intentionally, but getting role slug inside array
 might be helpful.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/43420>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list