| @@ -708,9 +708,9 @@ | ||
| 708 | 708 | public function poll_optimized_images( WP_REST_Request $request ) { |
| 709 | 709 | $api_key = $request->get_param( 'api_key' ); |
| 710 | 710 | $request = new Optml_Api(); |
| 711 | 711 | $images = $request->get_optimized_images( $api_key ); |
| 712 | - if ( ! isset( $images['list'] ) || empty( $images['list'] ) ) { | |
| 712 | + if ( is_wp_error( $images ) || ! is_array( $images ) || empty( $images['list'] ) ) { | |
| 713 | 713 | return $this->response( [] ); |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | $final_images = array_splice( $images['list'], 0, 10 ); |
| @@ -964,8 +964,9 @@ | ||
| 964 | 964 | return $this->response( 'Missing required parameters', 'error' ); |
| 965 | 965 | } |
| 966 | 966 | // save just the first 6 images, see https://github.com/Codeinwp/optimole-service/issues/1588#issuecomment-3357110865 |
| 967 | 967 | $above_fold_images = array_slice( $above_fold_images, 0, 6 ); |
| 968 | + $above_fold_images = array_values( array_map( 'intval', array_filter( $above_fold_images, 'is_numeric' ) ) ); | |
| 968 | 969 | if ( count( $bg_selectors ) > 100 ) { |
| 969 | 970 | return $this->response( 'Background selectors limit exceeded', 'error' ); |
| 970 | 971 | } |
| 971 | 972 | if ( $url === Profile::PLACEHOLDER ) { |