Wrong condition in your code causing fatal error Illegal offset type in isset
-
When browing to a user edit page in admin, I get this error in PHP log (paths cleaned) :
PHP Fatal error: Uncaught TypeError: Illegal offset type in isset or empty in wp-includes/capabilities.php:801 Stack trace: #0 wp-includes/class-wp-user.php(778): map_meta_cap() #1 wp-includes/capabilities.php(981): WP_User->has_cap() #2 wp-includes/capabilities.php(873): user_can() #3 wp-content/plugins/the-paste/include/ThePaste/Admin/User.php(59): current_user_can() #4 wp-includes/class-wp-hook.php(308): ThePaste\Admin\User->personal_options() #5 wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters() #6 wp-includes/plugin.php(517): WP_Hook->do_action() #7 wp-admin/user-edit.php(394): do_action() #8 {main} thrown in wp-includes/capabilities.php on line 801
wp-includes/capabilities.php on line 801 reads :
if ( isset( $post_type_meta_caps[ $cap ] ) ) {
When failing, $cap contains a full WP_User object.
In the backtrace I reach yourpersonal_options()
method in wp-content\plugins\the-paste\include\ThePaste\Admin\User.php on line 59, which reads :$can_edit = user_can( $profile_user, 'edit_posts' ) || current_user_can( $profile_user, 'edit_pages' );
The user I enter the edit page does not have the
edit_posts
capability, and your code is failing oncurrent_user_can()
condition.There’s something abnormal in your condition checks : see user_can and current_user_can in docs
You can’t use$profile_user
(which holds a WP_User instance) as 1st parameter forcurrent_user_can()
, it has to be a string.Thanks in advanced for the fix
- The topic ‘Wrong condition in your code causing fatal error Illegal offset type in isset’ is closed to new replies.