From bc2543d1444a393b5f0a7c35cdb67a7af46e6d7a Mon Sep 17 00:00:00 2001 From: nrgyapp <108645799+nrgyapp@users.noreply.github.com> Date: Tue, 30 Jul 2024 17:50:19 +1000 Subject: [PATCH] Update APIClient.php // Corrected part: Check if $result is an array and has the 'returnvalue' key In order to avoid: Warning: Undefined array key "returnvalue" in /public_html/wp-content/plugins/wp-rocket/inc/Engine/Common/JobManager/APIHandler/APIClient.php on line 138 --- .../JobManager/APIHandler/APIClient.php | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/inc/Engine/Common/JobManager/APIHandler/APIClient.php b/inc/Engine/Common/JobManager/APIHandler/APIClient.php index 47181d6e41..474424d89d 100644 --- a/inc/Engine/Common/JobManager/APIHandler/APIClient.php +++ b/inc/Engine/Common/JobManager/APIHandler/APIClient.php @@ -108,37 +108,39 @@ public function add_to_queue( string $url, array $options ): array { * @return array */ public function get_queue_job_status( $job_id, $queue_name, $is_home = false ) { - $args = [ - 'body' => [ - 'id' => $job_id, - 'force_queue' => $queue_name, - 'is_home' => $is_home, - ], - 'timeout' => 5, - ]; - - if ( ! $this->handle_get( $args ) ) { - return [ - 'code' => $this->response_code, - 'message' => $this->error_message, - ]; - } - - $default = [ - 'code' => 400, - 'status' => 'failed', - 'message' => 'No message. Defaulted in get_queue_job_status', - 'contents' => [ - 'success' => false, - 'shakedCSS' => '', - 'above_the_fold_result' => [ - 'lcp' => [], - 'images_above_fold' => [], - ], - ], - ]; - - $result = json_decode( $this->response_body, true ); - return (array) wp_parse_args( ( $result && $result['returnvalue'] ) ? (array) $result['returnvalue'] : [], $default ); + $args = [ + 'body' => [ + 'id' => $job_id, + 'force_queue' => $queue_name, + 'is_home' => $is_home, + ], + 'timeout' => 5, + ]; + + if ( ! $this->handle_get( $args ) ) { + return [ + 'code' => $this->response_code, + 'message' => $this->error_message, + ]; + } + + $default = [ + 'code' => 400, + 'status' => 'failed', + 'message' => 'No message. Defaulted in get_queue_job_status', + 'contents' => [ + 'success' => false, + 'shakedCSS' => '', + 'above_the_fold_result' => [ + 'lcp' => [], + 'images_above_fold' => [], + ], + ], + ]; + + $result = json_decode( $this->response_body, true ); + + // Corrected part: Check if $result is an array and has the 'returnvalue' key + return (array) wp_parse_args( ( is_array($result) && isset( $result['returnvalue'] ) ) ? (array) $result['returnvalue'] : [], $default ); } }