[wp-trac] [WordPress Trac] #62600: fatal error on capabilities.

WordPress Trac noreply at wordpress.org
Thu Nov 28 11:16:36 UTC 2024


#62600: fatal error on capabilities.
--------------------------+-----------------------------
 Reporter:  neo2k23       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  6.7.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 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

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62600>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list