PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.10
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.10
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 / 3rd-party.php

3rd-party.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.10, at inc/deprecated/3rd-party.php

332 lines 10.7 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 if ( class_exists( 'C_NextGEN_Bootstrap' ) && class_exists( 'Mixin' ) && get_site_option( 'ngg_options' ) ) :
5
6 /**
7 * Create the Imagify table needed for NGG compatibility.
8 *
9 * @since 1.5
10 * @since 1.7 Deprecated.
11 * @author Jonathan Buttigieg
12 * @deprecated
13 */
14 function _imagify_create_ngg_table() {
15 _deprecated_function( __FUNCTION__ . '()', '1.7', '\\Imagify\\ThirdParty\\NGG\\DB::get_instance()->maybe_upgrade_table()' );
16
17 \Imagify\ThirdParty\NGG\DB::get_instance()->maybe_upgrade_table();
18 }
19
20 /**
21 * Update all Imagify stats for NGG Bulk Optimization.
22 *
23 * @since 1.5
24 * @since 1.7 Deprecated.
25 * @author Jonathan Buttigieg
26 * @deprecated
27 */
28 function _imagify_ngg_update_bulk_stats() {
29 _deprecated_function( __FUNCTION__ . '()', '1.7', 'imagify_ngg_bulk_page_data()' );
30
31 if ( empty( $_GET['page'] ) || imagify_get_ngg_bulk_screen_slug() !== $_GET['page'] ) { // WPCS: CSRF ok.
32 return;
33 }
34
35 add_filter( 'imagify_count_attachments' , 'imagify_ngg_count_attachments' );
36 add_filter( 'imagify_count_optimized_attachments' , 'imagify_ngg_count_optimized_attachments' );
37 add_filter( 'imagify_count_error_attachments' , 'imagify_ngg_count_error_attachments' );
38 add_filter( 'imagify_count_unoptimized_attachments' , 'imagify_ngg_count_unoptimized_attachments' );
39 add_filter( 'imagify_percent_optimized_attachments' , 'imagify_ngg_percent_optimized_attachments' );
40 add_filter( 'imagify_count_saving_data' , 'imagify_ngg_count_saving_data', 8 );
41 }
42
43 /**
44 * Prepare the data that goes back with the Heartbeat API.
45 *
46 * @since 1.5
47 * @since 1.7.1 Deprecated.
48 * @deprecated
49 *
50 * @param array $response The Heartbeat response.
51 * @param array $data The $_POST data sent.
52 * @return array
53 */
54 function _imagify_ngg_heartbeat_received( $response, $data ) {
55 _deprecated_function( __FUNCTION__ . '()', '1.7.1' );
56
57 if ( ! isset( $data['imagify_heartbeat'] ) || 'update_ngg_bulk_data' !== $data['imagify_heartbeat'] ) {
58 return $response;
59 }
60
61 add_filter( 'imagify_count_saving_data', 'imagify_ngg_count_saving_data', 8 );
62 $saving_data = imagify_count_saving_data();
63 $user = new Imagify_User();
64
65 $response['imagify_bulk_data'] = array(
66 // User account.
67 'unconsumed_quota' => is_wp_error( $user ) ? 0 : $user->get_percent_unconsumed_quota(),
68 // Global chart.
69 'optimized_attachments_percent' => imagify_ngg_percent_optimized_attachments(),
70 'unoptimized_attachments' => imagify_ngg_count_unoptimized_attachments(),
71 'optimized_attachments' => imagify_ngg_count_optimized_attachments(),
72 'errors_attachments' => imagify_ngg_count_error_attachments(),
73 // Stats block.
74 'already_optimized_attachments' => number_format_i18n( $saving_data['count'] ),
75 'original_human' => imagify_size_format( $saving_data['original_size'], 1 ),
76 'optimized_human' => imagify_size_format( $saving_data['optimized_size'], 1 ),
77 'optimized_percent' => $saving_data['percent'],
78 );
79
80 return $response;
81 }
82
83 /**
84 * Filter the current user capability to operate Imagify.
85 *
86 * @since 1.6.11
87 * @since 1.9 Deprecated.
88 * @see imagify_get_capacity()
89 * @author Grégory Viguier
90 * @deprecated
91 *
92 * @param bool $user_can Tell if the current user has the required capacity to operate Imagify.
93 * @param string $capacity The user capacity.
94 * @param string $describer Capacity describer. See imagify_get_capacity() for possible values. Can also be a "real" user capacity.
95 * @param int $post_id A post ID (a gallery ID for NGG).
96 * @return bool
97 */
98 function imagify_ngg_current_user_can( $user_can, $capacity, $describer, $post_id ) {
99 static $user_can_per_gallery = array();
100
101 _deprecated_function( __FUNCTION__ . '()', '1.9' );
102
103 if ( ! $user_can || ! $post_id || 'NextGEN Manage gallery' !== $capacity ) {
104 return $user_can;
105 }
106
107 $image = nggdb::find_image( $post_id );
108
109 if ( isset( $user_can_per_gallery[ $image->galleryid ] ) ) {
110 return $user_can_per_gallery[ $image->galleryid ];
111 }
112
113 $gallery_mapper = C_Gallery_Mapper::get_instance();
114 $gallery = $gallery_mapper->find( $image->galleryid, false );
115
116 if ( get_current_user_id() === $gallery->author || current_user_can( 'NextGEN Manage others gallery' ) ) {
117 // The user created this gallery or can edit others galleries.
118 $user_can_per_gallery[ $image->galleryid ] = true;
119 return $user_can_per_gallery[ $image->galleryid ];
120 }
121
122 // The user can't edit this gallery.
123 $user_can_per_gallery[ $image->galleryid ] = false;
124 return $user_can_per_gallery[ $image->galleryid ];
125 }
126
127 /**
128 * Get user capacity to operate Imagify within NGG galleries.
129 * It is meant to be used to filter 'imagify_capacity'.
130 *
131 * @since 1.6.11
132 * @since 1.9 Deprecated.
133 * @see imagify_get_capacity()
134 * @author Grégory Viguier
135 * @deprecated
136 *
137 * @param string $capacity The user capacity.
138 * @param string $describer Capacity describer. See imagify_get_capacity() for possible values. Can also be a "real" user capacity.
139 * @return string
140 */
141 function imagify_get_ngg_capacity( $capacity = 'edit_post', $describer = 'manual-optimize' ) {
142 if ( 'manual-optimize' === $describer ) {
143 return 'NextGEN Manage gallery';
144 }
145
146 return $capacity;
147 }
148
149 /**
150 * Dispatch the optimization process.
151 *
152 * @since 1.8
153 * @since 1.9 Deprecated.
154 * @author Grégory Viguier
155 * @deprecated
156 */
157 function imagify_ngg_dispatch_dynamic_thumbnail_background_process() {
158 _deprecated_function( __FUNCTION__ . '()', '1.9' );
159
160 Imagify_NGG_Dynamic_Thumbnails_Background_Process::get_instance()->save()->dispatch();
161 }
162
163 /**
164 * On manual optimization, manual re-optimization, and manual restoration, filter the user capacity to operate Imagify within NGG.
165 *
166 * @since 1.6.11
167 * @since 1.9 Deprecated.
168 * @author Grégory Viguier
169 * @deprecated
170 */
171 function _do_admin_post_imagify_ngg_user_capacity() {
172 _deprecated_function( __FUNCTION__ . '()', '1.9' );
173
174 if ( ! empty( $_GET['context'] ) && 'NGG' === $_GET['context'] ) { // WPCS: CSRF ok.
175 add_filter( 'imagify_capacity', 'imagify_get_ngg_capacity', 10, 2 );
176 }
177 }
178
179 /**
180 * Get all unoptimized attachment ids.
181 *
182 * @since 1.0
183 * @since 1.9 Deprecated
184 * @author Jonathan Buttigieg
185 * @deprecated
186 */
187 function _do_wp_ajax_imagify_ngg_get_unoptimized_attachment_ids() {
188 _deprecated_function( __FUNCTION__ . '()', '1.9', '\\Imagify\\ThirdParty\\NGG\\AdminAjaxPost::get_instance()->get_media_ids()' );
189
190 \Imagify\ThirdParty\NGG\AdminAjaxPost::get_instance()->get_media_ids();
191 }
192
193 /**
194 * Provide custom folder type data.
195 *
196 * @since 1.7
197 * @since 1.9 Deprecated
198 * @author Grégory Viguier
199 * @deprecated
200 *
201 * @param array $data An array with keys corresponding to cell classes, and values formatted with HTML.
202 * @param string $context A context.
203 * @return array
204 */
205 function imagify_ngg_get_folder_type_data( $data, $context ) {
206 _deprecated_function( __FUNCTION__ . '()', '1.9' );
207
208 if ( 'ngg' !== $context ) {
209 return $data;
210 }
211
212 // Already filtered in imagify_ngg_bulk_page_data().
213 $total_saving_data = imagify_count_saving_data();
214
215 return [
216 'images-optimized' => imagify_ngg_count_optimized_attachments(),
217 'errors' => imagify_ngg_count_error_attachments(),
218 'optimized' => $total_saving_data['optimized_size'],
219 'original' => $total_saving_data['original_size'],
220 'errors_url' => admin_url( 'admin.php?page=nggallery-manage-gallery' ),
221 ];
222 }
223
224 endif;
225
226 if ( function_exists( 'wr2x_delete_attachment' ) ) :
227
228 /**
229 * Remove all retina versions if they exist.
230 *
231 * @since 1.0
232 * @since 1.8 Deprecated.
233 * @deprecated
234 *
235 * @param int $attachment_id An attachment ID.
236 */
237 function _imagify_wr2x_delete_attachment_on_restore( $attachment_id ) {
238 _deprecated_function( __FUNCTION__ . '()', '1.8' );
239
240 wr2x_delete_attachment( $attachment_id );
241 }
242
243 /**
244 * Regenerate all retina versions.
245 *
246 * @since 1.0
247 * @since 1.8 Deprecated.
248 * @deprecated
249 *
250 * @param int $attachment_id An attachment ID.
251 */
252 function _imagify_wr2x_generate_images_on_restore( $attachment_id ) {
253 _deprecated_function( __FUNCTION__ . '()', '1.8' );
254
255 wr2x_delete_attachment( $attachment_id );
256 wr2x_generate_images( wp_get_attachment_metadata( $attachment_id ) );
257 }
258
259 /**
260 * Filter the optimization data of each thumbnail.
261 *
262 * @since 1.0
263 * @since 1.8 Deprecated.
264 * @deprecated
265 *
266 * @param array $data The statistics data.
267 * @param object $response The API response.
268 * @param int $id The attachment ID.
269 * @param string $path The attachment path.
270 * @param string $url The attachment URL.
271 * @param string $size_key The attachment size key.
272 * @param bool $optimization_level The optimization level.
273 * @return array $data The new optimization data.
274 */
275 function _imagify_optimize_wr2x( $data, $response, $id, $path, $url, $size_key, $optimization_level ) {
276 _deprecated_function( __FUNCTION__ . '()', '1.8', 'Imagify_WP_Retina_2x::optimize_retina_version()' );
277
278 /**
279 * Allow to optimize the retina version generated by WP Retina x2.
280 *
281 * @since 1.0
282 *
283 * @param bool $do_retina True will force the optimization.
284 */
285 $do_retina = apply_filters( 'do_imagify_optimize_retina', true );
286 $retina_path = wr2x_get_retina( $path );
287
288 if ( empty( $retina_path ) || ! $do_retina ) {
289 return $data;
290 }
291
292 $response = do_imagify( $retina_path, array(
293 'backup' => false,
294 'optimization_level' => $optimization_level,
295 'context' => 'wp-retina',
296 ) );
297 $attachment = get_imagify_attachment( 'wp', $id, 'imagify_fill_thumbnail_data' );
298
299 return $attachment->fill_data( $data, $response, $size_key . '@2x' );
300 }
301
302 endif;
303
304 if ( defined( 'WP_ROCKET_VERSION' ) ) :
305
306 /**
307 * Don't load Imagify CSS & JS files on WP Rocket options screen to avoid conflict with older version of SweetAlert.
308 * Since 1.6.10 they should be enqueued only if one of our notices displays here.
309 *
310 * @since 1.6.9.1
311 * @since 1.6.10 Use the new class Imagify_Assets.
312 * @since 1.9.3 Deprecated.
313 * @author Jonathan Buttigieg
314 * @author Grégory Viguier
315 * @deprecated
316 */
317 function imagify_dequeue_sweetalert_wprocket() {
318 _deprecated_function( __FUNCTION__ . '()', '1.9.3', '\\Imagify\\ThirdParty\\WPRocket\\Main::dequeue_sweetalert()' );
319
320 if ( ! defined( 'WP_ROCKET_PLUGIN_SLUG' ) ) {
321 return;
322 }
323
324 if ( ! imagify_is_screen( 'settings_page_' . WP_ROCKET_PLUGIN_SLUG ) && ! imagify_is_screen( 'settings_page_' . WP_ROCKET_PLUGIN_SLUG . '-network' ) ) {
325 return;
326 }
327
328 Imagify_Assets::get_instance()->dequeue_script( array( 'sweetalert-core', 'sweetalert', 'notices' ) );
329 }
330
331 endif;
332