[wp-trac] [WordPress Trac] #31304: Add wrapper function to check if a given role exists

WordPress Trac noreply at wordpress.org
Thu Feb 12 09:47:11 UTC 2015


#31304: Add wrapper function to check if a given role exists
-----------------------------+----------------------
 Reporter:  hlashbrooke      |       Owner:
     Type:  enhancement      |      Status:  closed
 Priority:  normal           |   Milestone:
Component:  Role/Capability  |     Version:  trunk
 Severity:  normal           |  Resolution:  invalid
 Keywords:                   |     Focuses:
-----------------------------+----------------------

Comment (by F J Kaiser):

 In case this ticket awakes again, here's a summary from
 [https://wordpress.slack.com/archives/core/p1423720561004010 the
 discussion in the Slack Channel].

 1. Return strict and just the result as it evaluates to `bool` anyway.
 2. Use `\WP_Roles::is_role( $role )`

 Example:

 {{{#!php
 /**
  * @param string $role
  * @return bool TRUE if the role exists
  */
 function role_exists( $role )
 {
     /** @var \WP_Roles $wp_roles */
     global $wp_roles;
     return $wp_roles->is_role( $role );
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/31304#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list