class-rio-folder-processing.php
5 months ago
class-rio-media-processing-avif.php
3 months ago
class-rio-media-processing-webp.php
3 months ago
class-rio-media-processing.php
3 months ago
class-rio-nextgen-processing.php
5 months ago
class-rio-processing.php
5 months ago
class-rio-media-processing.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | use WBCR\Factory_Processing_759\WP_Background_Process; |
| 4 | |
| 5 | // Exit if accessed directly |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | exit; |
| 8 | } |
| 9 | |
| 10 | /** |
| 11 | * Класс для работы оптимизации в фоне |
| 12 | * |
| 13 | * @version 1.0 |
| 14 | */ |
| 15 | class WRIO_Media_Processing extends WRIO_Processing { |
| 16 | |
| 17 | /** |
| 18 | * @param array $attachment_ids |
| 19 | * |
| 20 | * @return int Count of pushed queue |
| 21 | */ |
| 22 | public function push_items( $attachment_ids = [] ) { |
| 23 | if ( empty( $attachment_ids ) && $this->scope === 'media-library' ) { |
| 24 | $media_library = WRIO_Media_Library::get_instance(); |
| 25 | $attachment_ids = $media_library->getUnoptimizedImages(); |
| 26 | } |
| 27 | |
| 28 | foreach ( $attachment_ids as $attachment_id ) { |
| 29 | $this->push_to_queue( $attachment_id ); |
| 30 | } |
| 31 | |
| 32 | return $this->count_queue(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Метод оптимизирует изображения при выполнении задачи |
| 37 | * |
| 38 | * @param int $image |
| 39 | * |
| 40 | * @return bool |
| 41 | */ |
| 42 | protected function task( $image ) { |
| 43 | if ( $image ) { |
| 44 | WRIO_Plugin::app()->logger->info( sprintf( 'Start optimize attachment: %s', $image ) ); |
| 45 | $media_library = WRIO_Media_Library::get_instance(); |
| 46 | |
| 47 | try { |
| 48 | if ( 'media-library' === $this->scope ) { |
| 49 | $media_library->optimizeAttachment( $image ); |
| 50 | } |
| 51 | } catch ( Throwable $throwable ) { |
| 52 | $wio_attachment = $media_library->getAttachment( $image ); |
| 53 | $wio_attachment->mark_and_log_failure( $throwable, 'background-processing' ); |
| 54 | } |
| 55 | |
| 56 | WRIO_Plugin::app()->logger->info( sprintf( 'End optimize attachment: %s', $image ) ); |
| 57 | } |
| 58 | |
| 59 | return false; |
| 60 | } |
| 61 | } |
| 62 |