PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | includes/class-re-smush-it-task.php +29 -20 3.2.5 → 4.7.0 View file →
@@ -7,15 +7,26 @@
7 7
8 8 if (!class_exists('Re_Smush_It_Task')) :
9 9
10 10 class Re_Smush_It_Task extends Updraft_Smush_Task {
11 -
11 +
12 + /**
13 + * Task name
14 + *
15 + * @var string
16 + */
12 17 public $label = 're-smush-it';
13 18
19 + /**
20 + * Maximum filesize
21 + */
14 22 const MAX_FILESIZE = 5242880;
23 +
24 + /**
25 + * API URL
26 + */
27 + const API_URL = 'https://api.resmush.it/';
15 28
16 - const API_URL = 'http://api.resmush.it/';
17 -
18 29 /**
19 30 * Checks if the server is online
20 31 *
21 32 * @return boolean - true if yes, false otherwise
@@ -23,9 +34,9 @@
23 34 public static function is_server_online() {
24 35
25 36 global $wp_version;
26 37 $test_image = WPO_PLUGIN_MAIN_PATH . 'images/icon/wpo.png';
27 - $boundary = wp_generate_password(12);
38 + $boundary = wp_generate_password();
28 39 $file_name = basename($test_image);
29 40
30 41 $body = "--$boundary";
31 42 $body .= "\r\n";
@@ -67,15 +78,17 @@
67 78
68 79 /**
69 80 * Prepares the image as part of the post data for the specific implementation
70 81 *
71 - * @param String $local_file - The image to e optimised
82 + * @param string $local_file - The image to e optimised
72 83 * @param array $options - Eventual options
84 + *
85 + * @return array
73 86 */
74 87 public function prepare_post_request($local_file, $options) {
75 88 global $wp_version;
76 89
77 - $boundary = wp_generate_password(12);
90 + $boundary = wp_generate_password();
78 91 $headers = array( "content-type" => "multipart/form-data; boundary=$boundary" );
79 92
80 93 $lossy = $this->get_option('lossy_compression');
81 94
@@ -81,14 +94,13 @@
81 94
82 95 if ($lossy) {
83 96 $quality = $this->get_option('image_quality');
84 97 } else {
85 - $quality = 100;
98 + $quality = 92;
86 99 }
87 100
88 101 if (isset($options['quality']) && is_int($options['quality']) && 0 < $options['quality']) $quality = $options['quality'];
89 102
90 - $this->log($quality);
91 103 $post_fields = array(
92 104 'qlty' => $quality,
93 105 'exif' => $this->get_option('preserve_exif', false)
94 106 );
@@ -93,9 +105,9 @@
93 105 'exif' => $this->get_option('preserve_exif', false)
94 106 );
95 107 $payload = '';
96 108 $file_name = basename($local_file);
97 -
109 +
98 110 foreach ($post_fields as $name => $value) {
99 111 $payload .= "--$boundary";
100 112 $payload .= "\r\n";
101 113 $payload .= "Content-Disposition: form-data; name='$name' \r\n\r\n $value";
@@ -118,14 +130,13 @@
118 130 );
119 131 }
120 132
121 133 /**
122 - * Processes the response recieved from the remote server
134 + * Processes the response received from the remote server
123 135 *
124 - * @param String $response - The response object
136 + * @param mixed $response - The response object
125 137 */
126 138 public function process_server_response($response) {
127 - global $http_response_header;
128 139
129 140 $response = parent::process_server_response($response);
130 141 $data = json_decode(wp_remote_retrieve_body($response));
131 142
@@ -140,9 +151,9 @@
140 151 }
141 152
142 153 if (!property_exists($data, 'dest')) {
143 154 $this->fail("invalid_response", "The response does not contain the compressed file URL");
144 - $this->log("data: ".json_encode($data));
155 + $this->log("data: ".wp_json_encode($data));
145 156 return false;
146 157 }
147 158
148 159 $compressed_image_response = wp_remote_get($data->dest);
@@ -156,12 +167,10 @@
156 167 return false;
157 168 }
158 169 } else {
159 170 $this->fail("invalid_response", "The compression apparently succeeded, but WP-Optimize could not retrieve the compressed image from the remote server.");
160 - $this->log("data: ".json_encode($data));
161 - if (!empty($http_response_header) && is_array($http_response_header)) {
162 - $this->log("headers: ".implode("\n", $http_response_header));
163 - }
171 + $this->log("data: ".wp_json_encode($data));
172 + $this->log("error: ".$compressed_image_response->get_error_message());
164 173 return false;
165 174 }
166 175 }
167 176
@@ -167,9 +176,9 @@
167 176
168 177 /**
169 178 * Retrieve features for this service
170 179 *
171 - * @return Array - an array of options
180 + * @return array - an array of options
172 181 */
173 182 public static function get_features() {
174 183 return array(
175 184 'max_filesize' => self::MAX_FILESIZE,
@@ -180,9 +189,9 @@
180 189
181 190 /**
182 191 * Retrieve default options for this task type.
183 192 *
184 - * @return Array - an array of options
193 + * @return array - an array of options
185 194 */
186 195 public function get_default_options() {
187 196 return array(
188 197 'allowed_file_types' => array('gif', 'png', 'jpg', 'tif', 'jpeg'),
@@ -188,9 +197,9 @@
188 197 'allowed_file_types' => array('gif', 'png', 'jpg', 'tif', 'jpeg'),
189 198 'request_timeout' => 30,
190 199 'keep_original' => true,
191 200 'preserve_exif' => false,
192 - 'image_quality' => 98,
201 + 'image_quality' => 92,
193 202 'api_endpoint' => self::API_URL,
194 203 'max_filesize' => self::MAX_FILESIZE,
195 204 'version' => '0.1.13',
196 205 'backup_prefix' => '-updraft-pre-smush-original.'