Code is using admin_notices as array, but it’s stdClass
-
[17-Jan-2023 09:58:08 UTC] PHP Fatal error: Uncaught Error: Cannot use object of type stdClass as array in /homepages/42/123/htdocs/abc/wp-content/plugins/learnpress/inc/rest-api/v1/admin/class-lp-admin-rest-tools-controller.php:261 Stack trace: #0 /homepages/42/123/htdocs/abc/wp-includes/rest-api/class-wp-rest-server.php(1171): LP_REST_Admin_Tools_Controller->admin_notices(Object(WP_REST_Request)) #1 /homepages/42/123/htdocs/abc/wp-includes/rest-api/class-wp-rest-server.php(1018): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/lp/v1/admin/to...', Array, NULL) #2 /homepages/42/123/htdocs/abc/wp-includes/rest-api/class-wp-rest-server.php(442): WP_REST_Server->dispatch(Object(WP_REST_Request)) #3 /homepages/42/123/htdocs/abc/wp-includes/rest-api.php(410): WP_REST_Server->serve_request('/lp/v1/admin/to...') #4 /homepages/42/123/htdocs/abc/wp-includes/class-wp-hook.php(308): rest_api_loaded(Object(WP)) #5 /homepages/42/123/htdocs/abc/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(N in /homepages/42/123/htdocs/abc/wp-content/plugins/learnpress/inc/rest-api/v1/admin/class-lp-admin-rest-tools-controller.php on line 261
This is the line from your code:
$admin_notices = ! empty( $_COOKIE['lp_admin_notices_dismiss'] ) ? json_decode( wp_unslash( $_COOKIE['lp_admin_notices_dismiss'] ) ) : [];
as you can see, the json_decode is not using the second parameter. Some servers will return an object instead on an array. It’s better to set the second param to true:
$admin_notices = ! empty( $_COOKIE['lp_admin_notices_dismiss'] ) ? json_decode( wp_unslash( $_COOKIE['lp_admin_notices_dismiss'] ), true ) : [];
because your code is expecting an array.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Code is using admin_notices as array, but it’s stdClass’ is closed to new replies.