get_params(); $pages = empty( $params['data'] ) || ! is_array( $params['data'] ) ? array() : $params['data']; $api_successful = array( 'success' => true ); // If success is false, the whole LCP generation process failed. if ( empty( $params['success'] ) ) { if ( empty( $params['message'] ) || ! is_string( $params['message'] ) ) { $error = __( 'An unknown error occurred', 'jetpack-boost' ); } else { $error = $params['message']; } $state->set_error( $error ); $state->save(); return $api_successful; } foreach ( $pages as $entry ) { if ( $entry['success'] ) { $state->set_page_success( $entry['key'] ); } else { $errors = array(); foreach ( $entry['reports'] as $report ) { if ( isset( $report['success'] ) && false === $report['success'] && ! empty( $report['data'] ) ) { $errors[] = $report['data']; } } $state->set_page_errors( $entry['key'], $errors ); } // Store the LCP data for this page. $storage->store_lcp( $entry['key'], $entry['reports'] ); // Failures must have an array of urls. // @TODO: figure out what to do with failures. } // Save the state changes. $state->save(); return $api_successful; } public function permissions() { return array( new Signed_With_Blog_Token(), ); } }