Make WordPress Core

Opened 5 months ago

Last modified 6 weeks ago

#62600 new defect (bug)

fatal error on capabilities.

Reported by: neo2k23's profile neo2k23 Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Role/Capability Keywords: has-patch needs-unit-tests
Focuses: Cc:

Description (last modified by johnbillion)

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

Attachments (1)

62600.diff (644 bytes) - added by kadiwala 4 months ago.
Added condition to prevent the fatal error on missing capabilities in array.

Download all attachments as: .zip

Change History (5)

@kadiwala
4 months ago

Added condition to prevent the fatal error on missing capabilities in array.

#1 @neo2k23
2 months ago

@kadiwala sorry to ask is this adjustment accepted into the latest build as i do not see it back in the latest beta release

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


2 months ago
#2

  • Keywords has-patch added

This PR addresses a fatal error in WP_User_Query that occurs when a user role is missing the capabilities key. This issue is typically caused by third-party plugins that create roles without properly setting capabilities. When such roles exist, calls to array_filter() on null trigger a fatal error.

Trac ticket: https://core.trac.wordpress.org/ticket/62600

#3 @johnbillion
7 weeks ago

  • Component changed from General to Role/Capability
  • Description modified (diff)
  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
  • Version 6.7.1 deleted

This change will need some unit test coverage.

#4 @neo2k23
6 weeks ago

wrong ticket. sorry

Last edited 6 weeks ago by neo2k23 (previous) (diff)
Note: See TracTickets for help on using tickets.