[wp-trac] [WordPress Trac] #62600: fatal error on capabilities.
WordPress Trac
noreply at wordpress.org
Wed Mar 5 16:42:49 UTC 2025
#62600: fatal error on capabilities.
----------------------------------------+-----------------------------
Reporter: neo2k23 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: Role/Capability | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-unit-tests | Focuses:
----------------------------------------+-----------------------------
Changes (by johnbillion):
* keywords: has-patch => has-patch needs-unit-tests
* version: 6.7.1 =>
* component: General => Role/Capability
* milestone: Awaiting Review => Future Release
Old description:
> I ran in to a weird issue in a client website claiming it was the theme
> causing it. I got a fatal error in every page on the author meta box
> when using the classic editor layout.
>
> Fatal error: Uncaught TypeError: array_filter(): Argument #1 ($array)
> must be of type array, null given in /home/wp-includes/class-wp-user-
> query.php:485 Stack trace:
> #0 /home/wp-includes/class-wp-user-query.php(485): array_filter(NULL)
> #1 /home/wp-includes/class-wp-user-query.php(79):
> WP_User_Query->prepare_query(Array)
> #2 /home/wp-includes/user.php(807): WP_User_Query->__construct(Array)
> #3 /home/wp-includes/user.php(1715): get_users(Array)
> #4 /home/wp-admin/includes/meta-boxes.php(976): wp_dropdown_users(Array)
> #5 /home/wp-admin/includes/template.php(1456):
> post_author_meta_box(Object(WP_Post), Array)
> #6 /home/wp-admin/edit-form-advanced.php(722):
> do_meta_boxes(Object(WP_Screen), 'normal', Object(WP_Post))
> #7 /home/wp-admin/post.php(206): require('/home/...')
> #8 {main} thrown in /home/wp-includes/class-wp-user-query.php on line 485
>
> It appeared that he some how in the past had a plugin that created user
> roles with capabilties, but also some without.
>
> He stopped using the plugin. And now he updated to the latest wp version
> he got fatals in every page.
>
> My request is to change class-wp-user-query.php on line 485 and check if
> the capabilities key isset to avoid fatal errors.
>
> Please change class-wp-user-query.php line 485 from
>
> {{{#!php
> <?php
> $role_caps = array_keys( array_filter(
> $role_data['capabilities'] ) );
> }}}
>
> to
>
> {{{#!php
> <?php
> $role_caps = array();
> if ( isset( $role_data['capabilities'] ) )
> $role_caps = array_keys( array_filter( $role_data['capabilities'] ) );
> }}}
>
> That would have prevented the fatal error on missing capabilty array key
>
> Thank you
New description:
I ran in to a weird issue in a client website claiming it was the theme
causing it. I got a fatal error in every page on the author meta box when
using the classic editor layout.
{{{
Fatal error: Uncaught TypeError: array_filter(): Argument #1 ($array) must
be of type array, null given in /home/wp-includes/class-wp-user-
query.php:485 Stack trace:
#0 /home/wp-includes/class-wp-user-query.php(485): array_filter(NULL)
#1 /home/wp-includes/class-wp-user-query.php(79):
WP_User_Query->prepare_query(Array)
#2 /home/wp-includes/user.php(807): WP_User_Query->__construct(Array)
#3 /home/wp-includes/user.php(1715): get_users(Array)
#4 /home/wp-admin/includes/meta-boxes.php(976): wp_dropdown_users(Array)
#5 /home/wp-admin/includes/template.php(1456):
post_author_meta_box(Object(WP_Post), Array)
#6 /home/wp-admin/edit-form-advanced.php(722):
do_meta_boxes(Object(WP_Screen), 'normal', Object(WP_Post))
#7 /home/wp-admin/post.php(206): require('/home/...')
#8 {main} thrown in /home/wp-includes/class-wp-user-query.php on line 485
}}}
It appeared that he some how in the past had a plugin that created user
roles with capabilties, but also some without.
He stopped using the plugin. And now he updated to the latest wp version
he got fatals in every page.
My request is to change class-wp-user-query.php on line 485 and check if
the capabilities key isset to avoid fatal errors.
Please change class-wp-user-query.php line 485 from
{{{#!php
<?php
$role_caps = array_keys( array_filter( $role_data['capabilities'] ) );
}}}
to
{{{#!php
<?php
$role_caps = array();
if ( isset( $role_data['capabilities'] ) ) $role_caps = array_keys(
array_filter( $role_data['capabilities'] ) );
}}}
That would have prevented the fatal error on missing capabilty array key
Thank you
--
Comment:
This change will need some unit test coverage.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62600#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list