PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / deprecated / classes / class-imagify-ngg-dynamic-thumbnails-background-process.php

class-imagify-ngg-dynamic-thumbnails-background-process.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at inc/deprecated/classes/class-imagify-ngg-dynamic-thumbnails-background-process.php

168 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
3
4 /**
5 * Class that handles background processing of thumbnails dynamically generated.
6 *
7 * @since 1.8
8 * @since 1.9 Deprecated
9 * @author Grégory Viguier
10 * @deprecated
11 */
12 class Imagify_NGG_Dynamic_Thumbnails_Background_Process extends Imagify_Abstract_Background_Process {
13
14 /**
15 * Class version.
16 *
17 * @var string
18 * @since 1.8
19 * @author Grégory Viguier
20 */
21 const VERSION = '1.1';
22
23 /**
24 * Action.
25 *
26 * @var string
27 * @since 1.8
28 * @access protected
29 * @author Grégory Viguier
30 */
31 protected $action = 'ngg_dynamic_thumbnails';
32
33 /**
34 * The single instance of the class.
35 *
36 * @var object
37 * @since 1.8
38 * @access protected
39 * @author Grégory Viguier
40 */
41 protected static $_instance;
42
43
44 /**
45 * Get the main Instance.
46 *
47 * @since 1.8
48 * @access public
49 * @author Grégory Viguier
50 *
51 * @return object Main instance.
52 */
53 public static function get_instance() {
54 if ( ! isset( self::$_instance ) ) {
55 self::$_instance = new self();
56 }
57
58 return self::$_instance;
59 }
60
61 /**
62 * Initiate new background process.
63 *
64 * @since 1.9
65 * @access public
66 * @author Grégory Viguier
67 */
68 public function __construct() {
69 imagify_deprecated_class( get_class( $this ), '1.9', '\\Imagify\\ThirdParty\\NGG\\DynamicThumbnails()' );
70
71 parent::__construct();
72 }
73
74
75 /** ----------------------------------------------------------------------------------------- */
76 /** BACKGROUND PROCESS ====================================================================== */
77 /** ----------------------------------------------------------------------------------------- */
78
79 /**
80 * Push to queue.
81 *
82 * @since 1.8
83 * @access public
84 * @author Grégory Viguier
85 *
86 * @param array $data {
87 * The data to push in queue.
88 *
89 * @type int $id The image ID. Required.
90 * @type string $size The thumbnail size. Required.
91 * }
92 * @return object Class instance.
93 */
94 public function push_to_queue( $data ) {
95 $key = $data['id'] . '|' . $data['size'];
96
97 $this->data[ $key ] = $data;
98
99 return $this;
100 }
101
102 /**
103 * Dispatch.
104 *
105 * @since 1.8
106 * @access public
107 * @author Grégory Viguier
108 *
109 * @return array|WP_Error
110 */
111 public function dispatch() {
112 if ( ! empty( $this->data ) ) {
113 return parent::dispatch();
114 }
115 }
116
117 /**
118 * Tell if a task is already in the queue.
119 *
120 * @since 1.8
121 * @access public
122 * @author Grégory Viguier
123 *
124 * @param array $data {
125 * The data to test against the queue.
126 *
127 * @type int $id The image ID. Required.
128 * @type string $size The thumbnail size. Required.
129 * }
130 * @return bool
131 */
132 public function is_in_queue( $data ) {
133 $key = $data['id'] . '|' . $data['size'];
134
135 return isset( $this->data[ $key ] );
136 }
137
138 /**
139 * Task: optimize the thumbnail.
140 *
141 * @since 1.8
142 * @access public
143 * @author Grégory Viguier
144 *
145 * @param array $item {
146 * The data to test against the queue.
147 *
148 * @type int $id The image ID. Required.
149 * @type string $size The thumbnail size. Required.
150 * }
151 * @return bool False to remove the item from the queue.
152 */
153 protected function task( $item ) {
154 $attachment_id = absint( $item['id'] );
155 $size = sanitize_text_field( $item['size'] );
156
157 if ( ! $attachment_id || ! $size ) {
158 return false;
159 }
160
161 $attachment = get_imagify_attachment( 'NGG', $attachment_id, 'ngg_optimize_dynamic_thumbnail' );
162
163 $attachment->optimize_new_thumbnail( $size );
164
165 return false;
166 }
167 }
168