| @@ -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 ); |
| @@ -717,9 +717,9 @@ | ||
| 717 | 717 | |
| 718 | 718 | foreach ( $final_images as $index => $value ) { |
| 719 | 719 | $final_images[ $index ]['url'] = Optml_Media_Offload::instance()->get_media_optimized_url( |
| 720 | 720 | $value['url'], |
| 721 | - $value['key'], | |
| 721 | + strtolower( $value['key'] ), | |
| 722 | 722 | 140, |
| 723 | 723 | 140, |
| 724 | 724 | [ |
| 725 | 725 | 'type' => ResizeTypeProperty::FILL, |
| @@ -843,10 +843,16 @@ | ||
| 843 | 843 | * |
| 844 | 844 | * @return WP_REST_Response |
| 845 | 845 | */ |
| 846 | 846 | public function clear_offload_errors( WP_REST_Request $request ) { |
| 847 | - $delete_count = Optml_Media_Offload::clear_offload_errors_meta(); | |
| 847 | + $action = $request->get_param( 'action' ); | |
| 848 | 848 | |
| 849 | + if ( 'rollback_images' === $action ) { | |
| 850 | + $delete_count = Optml_Media_Offload::clear_rollback_errors_meta(); | |
| 851 | + } else { | |
| 852 | + $delete_count = Optml_Media_Offload::clear_offload_errors_meta(); | |
| 853 | + } | |
| 854 | + | |
| 849 | 855 | return $this->response( [ 'success' => $delete_count ] ); |
| 850 | 856 | } |
| 851 | 857 | |
| 852 | 858 | /** |
| @@ -958,8 +964,9 @@ | ||
| 958 | 964 | return $this->response( 'Missing required parameters', 'error' ); |
| 959 | 965 | } |
| 960 | 966 | // save just the first 6 images, see https://github.com/Codeinwp/optimole-service/issues/1588#issuecomment-3357110865 |
| 961 | 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' ) ) ); | |
| 962 | 969 | if ( count( $bg_selectors ) > 100 ) { |
| 963 | 970 | return $this->response( 'Background selectors limit exceeded', 'error' ); |
| 964 | 971 | } |
| 965 | 972 | if ( $url === Profile::PLACEHOLDER ) { |