Make WordPress Core

Opened 5 months ago

Last modified 5 months ago

#60931 assigned defect (bug)

The 'get_users' function triggers a fatal error if a role is added without any capability assigned.

Reported by: nazsabuz's profile nazsabuz Owned by: nazsabuz's profile nazsabuz
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.0
Component: Users Keywords: has-patch
Focuses: Cc:

Description

Steps to reproduce

  1. Add a custom user role, and pass null to the capabilities argument. e.g.
    <?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
    $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

Change History (4)

This ticket was mentioned in PR #6361 on WordPress/wordpress-develop by @nazsabuz.


5 months ago
#1

  • Keywords has-patch added; needs-patch removed

#2 @jorbin
5 months ago

  • Keywords needs-patch added; has-patch removed
  • Version changed from 6.5 to 2.0

If you are calling add_role with null $capabilities you are doing it wrong and I don't think this is something that should be hidden. I think causing add_role to fail in this situation is a better solution.

Changing the milestone to 2.0 since that is when add_role was added.

This ticket was mentioned in PR #6367 on WordPress/wordpress-develop by @nazsabuz.


5 months ago
#3

  • Keywords has-patch added; needs-patch removed

#4 @nazsabuz
5 months ago

Got it, a new PR has been created.

Note: See TracTickets for help on using tickets.