[wp-trac] [WordPress Trac] #60931: The 'get_users' function triggers a fatal error if a role is added without any capability assigned.

WordPress Trac noreply at wordpress.org
Thu Apr 4 21:52:51 UTC 2024


#60931: The 'get_users' function triggers a fatal error if a role is added without
any capability assigned.
--------------------------+-----------------------------
 Reporter:  nazsabuz      |      Owner:  nazsabuz
     Type:  defect (bug)  |     Status:  assigned
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Users         |    Version:  6.5
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 **Steps to reproduce**
 1. Add a custom user role, and pass null to the capabilities argument.
 e.g.
 {{{#!php
 <?php
 function add_custom_role_without_capabilities() {
         add_role( 'ola', 'Ola', null );
 }
 add_action( 'init', 'add_custom_role_without_capabilities' );
 }}}
 2. Now, call the get_users function with 'capability' args. e.g.
 {{{#!php
 <?php
 $users = get_users( [
         'capability' => [ 'edit_posts' ],
 ] );
 }}}

 You should see a fatal error.


 {{{
 Uncaught Error: array_filter(): Argument #1 ($array) must be of type
 array, null given in /wp/wp-includes/class-wp-user-query.php on line 487
 }}}

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


More information about the wp-trac mailing list