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-regenerate-thumbnails-deprecated.php

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

161 lines 4.6 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 * Deprecated class that handles compatibility with Regenerate Thumbnails plugin.
6 *
7 * @since 1.9
8 * @author Grégory Viguier
9 * @deprecated
10 */
11 class Imagify_Regenerate_Thumbnails_Deprecated {
12
13 /**
14 * Action used for the ajax callback.
15 *
16 * @var string
17 * @since 1.7.1
18 * @since 1.9 Deprecated.
19 * @author Grégory Viguier
20 * @deprecated
21 */
22 const ACTION = 'imagify_regenerate_thumbnails';
23
24 /**
25 * List of the attachments to regenerate.
26 *
27 * @var array An array of Imagify attachments. The array keys are the attachment IDs.
28 * @since 1.7.1
29 * @since 1.9 Deprecated.
30 * @access protected
31 * @author Grégory Viguier
32 * @deprecated
33 */
34 protected $attachments = [];
35
36 /**
37 * Optimize the newly regenerated thumbnails.
38 *
39 * @since 1.7.1
40 * @since 1.9 Deprecated.
41 * @access public
42 * @author Grégory Viguier
43 * @deprecated
44 */
45 public function regenerate_thumbnails_callback() {
46 _deprecated_function( get_class( $this ) . '::' . __FUNCTION__ . '()', '1.9' );
47
48 if ( empty( $_POST['_ajax_nonce'] ) || empty( $_POST['attachment_id'] ) || empty( $_POST['context'] ) ) { // WPCS: CSRF ok.
49 imagify_die( __( 'Invalid request', 'imagify' ) );
50 }
51
52 if ( empty( $_POST['sizes'] ) || ! is_array( $_POST['sizes'] ) ) { // WPCS: CSRF ok.
53 imagify_die( __( 'No thumbnail sizes selected', 'imagify' ) );
54 }
55
56 $attachment_id = absint( $_POST['attachment_id'] );
57 $context = imagify_sanitize_context( $_POST['context'] ); // WPCS: CSRF ok.
58
59 imagify_check_nonce( static::get_nonce_name( $attachment_id, $context ) );
60 imagify_check_user_capacity( 'manual-optimize', $attachment_id );
61
62 $attachment = get_imagify_attachment( $context, $attachment_id, static::ACTION );
63
64 if ( ! $attachment->is_valid() || ! $attachment->is_image() ) {
65 wp_send_json_error();
66 }
67
68 // Optimize.
69 $attachment->reoptimize_thumbnails( wp_unslash( $_POST['sizes'] ) );
70
71 // Put the optimized original file back.
72 $this->put_optimized_file_back( $attachment_id );
73
74 wp_send_json_success();
75 }
76
77 /**
78 * Set the Imagify attachment.
79 *
80 * @since 1.7.1
81 * @since 1.9 Deprecated.
82 * @access protected
83 * @author Grégory Viguier
84 * @deprecated
85 *
86 * @param int $attachment_id Attachment ID.
87 * @return object|false An Imagify attachment object. False on failure.
88 */
89 protected function set_attachment( $attachment_id ) {
90 _deprecated_function( get_class( $this ) . '::' . __FUNCTION__ . '()', '1.9', '\\Imagify\\ThirdParty\\RegenerateThumbnails\\Main::get_instance()->set_process()' );
91
92 if ( ! $attachment_id || ! Imagify_Requirements::is_api_key_valid() ) {
93 return false;
94 }
95
96 $attachment = get_imagify_attachment( 'wp', $attachment_id, 'regenerate_thumbnails' );
97
98 if ( ! $attachment->is_valid() || ! $attachment->is_image() || ! $attachment->is_optimized() ) {
99 return false;
100 }
101
102 // This attachment can be optimized.
103 $this->attachments[ $attachment_id ] = $attachment;
104 return $this->attachments[ $attachment_id ];
105 }
106
107 /**
108 * Unset the Imagify attachment.
109 *
110 * @since 1.7.1
111 * @since 1.9 Deprecated.
112 * @access protected
113 * @author Grégory Viguier
114 * @deprecated
115 *
116 * @param int $attachment_id Attachment ID.
117 */
118 protected function unset_attachment( $attachment_id ) {
119 _deprecated_function( get_class( $this ) . '::' . __FUNCTION__ . '()', '1.9', '\\Imagify\\ThirdParty\\RegenerateThumbnails\\Main::get_instance()->unset_process()' );
120
121 unset( $this->attachments[ $attachment_id ] );
122 }
123
124 /**
125 * Get the Imagify attachment.
126 *
127 * @since 1.7.1
128 * @since 1.9 Deprecated.
129 * @access protected
130 * @author Grégory Viguier
131 * @deprecated
132 *
133 * @param int $attachment_id Attachment ID.
134 * @return object|false An Imagify attachment object. False on failure.
135 */
136 protected function get_attachment( $attachment_id ) {
137 _deprecated_function( get_class( $this ) . '::' . __FUNCTION__ . '()', '1.9', '\\Imagify\\ThirdParty\\RegenerateThumbnails\\Main::get_instance()->get_process()' );
138
139 return ! empty( $this->attachments[ $attachment_id ] ) ? $this->attachments[ $attachment_id ] : false;
140 }
141
142 /**
143 * Get the name of the nonce used for the ajax callback.
144 *
145 * @since 1.7.1
146 * @since 1.9 Deprecated.
147 * @access public
148 * @author Grégory Viguier
149 * @deprecated
150 *
151 * @param int $media_id The media ID.
152 * @param string $context The context.
153 * @return string
154 */
155 public static function get_nonce_name( $media_id, $context ) {
156 _deprecated_function( get_called_class() . '::' . __FUNCTION__ . '()', '1.9' );
157
158 return static::ACTION . '-' . $media_id . '-' . $context;
159 }
160 }
161