Opened 7 weeks ago
#62600 new defect (bug)
fatal error on capabilities.
Reported by: | neo2k23 | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.7.1 |
Component: | General | Keywords: | |
Focuses: | Cc: |
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 $role_caps = array_keys( array_filter( $role_data['capabilities'] ) );
to
<?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
Added condition to prevent the fatal error on missing capabilities in array.