Opened 2 years ago
Last modified 2 years 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 | Owned by: | nazsabuz |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Users | Version: | 2.0 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
Steps to reproduce
- 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' );
- 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.
2 years ago
#1
- Keywords has-patch added; needs-patch removed
#2
@
2 years ago
- Keywords needs-patch added; has-patch removed
- Version 6.5 → 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.
2 years ago
#3
- Keywords has-patch added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/60931
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: https://core.trac.wordpress.org/ticket/60931