PluginProbe
Polylang / 2.5
Polylang v2.5
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | install/plugin-updater.php +17 -89 2.72.5 View file →
@@ -9,9 +9,9 @@
9 9 * Allows plugins to use their own update API.
10 10 * Modified version with 'polylang' text domain and comments for translators
11 11 *
12 12 * @author Easy Digital Downloads
13 - * @version 1.6.18
13 + * @version 1.6.16
14 14 */
15 15 class PLL_Plugin_Updater {
16 16
17 17 private $api_url = '';
@@ -21,10 +21,8 @@
21 21 private $version = '';
22 22 private $wp_override = false;
23 23 private $cache_key = '';
24 24
25 - private $health_check_timeout = 5;
26 -
27 25 /**
28 26 * Class constructor.
29 27 *
30 28 * @uses plugin_basename()
@@ -123,11 +121,8 @@
123 121 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
124 122
125 123 $_transient_data->response[ $this->name ] = $version_info;
126 124
127 - // Make sure the plugin property is set to the plugin's name/location. See issue 1463 on Software Licensing's GitHub repo.
128 - $_transient_data->response[ $this->name ]->plugin = $this->name;
129 -
130 125 }
131 126
132 127 $_transient_data->last_checked = time();
133 128 $_transient_data->checked[ $this->name ] = $this->version;
@@ -174,21 +169,8 @@
174 169
175 170 if ( false === $version_info ) {
176 171 $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
177 172
178 - // Since we disabled our filter for the transient, we aren't running our object conversion on banners, sections, or icons. Do this now:
179 - if ( isset( $version_info->banners ) && ! is_array( $version_info->banners ) ) {
180 - $version_info->banners = $this->convert_object_to_array( $version_info->banners );
181 - }
182 -
183 - if ( isset( $version_info->sections ) && ! is_array( $version_info->sections ) ) {
184 - $version_info->sections = $this->convert_object_to_array( $version_info->sections );
185 - }
186 -
187 - if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) {
188 - $version_info->icons = $this->convert_object_to_array( $version_info->icons );
189 - }
190 -
191 173 $this->set_version_info_cache( $version_info );
192 174 }
193 175
194 176 if ( ! is_object( $version_info ) ) {
@@ -282,10 +264,9 @@
282 264 'slug' => $this->slug,
283 265 'is_ssl' => is_ssl(),
284 266 'fields' => array(
285 267 'banners' => array(),
286 - 'reviews' => false,
287 - 'icons' => array(),
268 + 'reviews' => false
288 269 )
289 270 );
290 271
291 272 $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
@@ -310,50 +291,30 @@
310 291 }
311 292
312 293 // Convert sections into an associative array, since we're getting an object, but Core expects an array.
313 294 if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
314 - $_data->sections = $this->convert_object_to_array( $_data->sections );
295 + $new_sections = array();
296 + foreach ( $_data->sections as $key => $value ) {
297 + $new_sections[ $key ] = $value;
298 + }
299 +
300 + $_data->sections = $new_sections;
315 301 }
316 302
317 303 // Convert banners into an associative array, since we're getting an object, but Core expects an array.
318 304 if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
319 - $_data->banners = $this->convert_object_to_array( $_data->banners );
320 - }
305 + $new_banners = array();
306 + foreach ( $_data->banners as $key => $value ) {
307 + $new_banners[ $key ] = $value;
308 + }
321 309
322 - // Convert icons into an associative array, since we're getting an object, but Core expects an array.
323 - if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
324 - $_data->icons = $this->convert_object_to_array( $_data->icons );
310 + $_data->banners = $new_banners;
325 311 }
326 312
327 - if( ! isset( $_data->plugin ) ) {
328 - $_data->plugin = $this->name;
329 - }
330 -
331 313 return $_data;
332 314 }
333 315
334 316 /**
335 - * Convert some objects to arrays when injecting data into the update API
336 - *
337 - * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON
338 - * decoding, they are objects. This method allows us to pass in the object and return an associative array.
339 - *
340 - * @since 3.6.5
341 - *
342 - * @param stdClass $data
343 - *
344 - * @return array
345 - */
346 - private function convert_object_to_array( $data ) {
347 - $new_data = array();
348 - foreach ( $data as $key => $value ) {
349 - $new_data[ $key ] = $value;
350 - }
351 -
352 - return $new_data;
353 - }
354 -
355 - /**
356 317 * Disable SSL verification in order to prevent download update failures
357 318 *
358 319 * @param array $args
359 320 * @param string $url
@@ -381,34 +342,10 @@
381 342 * @return false|object
382 343 */
383 344 private function api_request( $_action, $_data ) {
384 345
385 - global $wp_version, $edd_plugin_url_available;
346 + global $wp_version;
386 347
387 - $verify_ssl = $this->verify_ssl();
388 -
389 - // Do a quick status check on this domain if we haven't already checked it.
390 - $store_hash = md5( $this->api_url );
391 - if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) {
392 - $test_url_parts = parse_url( $this->api_url );
393 -
394 - $scheme = ! empty( $test_url_parts['scheme'] ) ? $test_url_parts['scheme'] : 'http';
395 - $host = ! empty( $test_url_parts['host'] ) ? $test_url_parts['host'] : '';
396 - $port = ! empty( $test_url_parts['port'] ) ? ':' . $test_url_parts['port'] : '';
397 -
398 - if ( empty( $host ) ) {
399 - $edd_plugin_url_available[ $store_hash ] = false;
400 - } else {
401 - $test_url = $scheme . '://' . $host . $port;
402 - $response = wp_remote_get( $test_url, array( 'timeout' => $this->health_check_timeout, 'sslverify' => $verify_ssl ) );
403 - $edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true;
404 - }
405 - }
406 -
407 - if ( false === $edd_plugin_url_available[ $store_hash ] ) {
408 - return;
409 - }
410 -
411 348 $data = array_merge( $this->api_data, $_data );
412 349
413 350 if ( $data['slug'] != $this->slug ) {
414 351 return;
@@ -413,9 +350,9 @@
413 350 if ( $data['slug'] != $this->slug ) {
414 351 return;
415 352 }
416 353
417 - if( $this->api_url == trailingslashit ( home_url() ) ) {
354 + if( $this->api_url == trailingslashit (home_url() ) ) {
418 355 return false; // Don't allow a plugin to ping itself
419 356 }
420 357
421 358 $api_params = array(
@@ -429,8 +366,9 @@
429 366 'url' => home_url(),
430 367 'beta' => ! empty( $data['beta'] ),
431 368 );
432 369
370 + $verify_ssl = $this->verify_ssl();
433 371 $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
434 372
435 373 if ( ! is_wp_error( $request ) ) {
436 374 $request = json_decode( wp_remote_retrieve_body( $request ) );
@@ -445,12 +383,8 @@
445 383 if ( $request && isset( $request->banners ) ) {
446 384 $request->banners = maybe_unserialize( $request->banners );
447 385 }
448 386
449 - if ( $request && isset( $request->icons ) ) {
450 - $request->icons = maybe_unserialize( $request->icons );
451 - }
452 -
453 387 if( ! empty( $request->sections ) ) {
454 388 foreach( $request->sections as $key => $section ) {
455 389 $request->$key = (array) $section;
456 390 }
@@ -538,15 +472,9 @@
538 472 if( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) {
539 473 return false; // Cache is expired
540 474 }
541 475
542 - // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point.
543 - $cache['value'] = json_decode( $cache['value'] );
544 - if ( ! empty( $cache['value']->icons ) ) {
545 - $cache['value']->icons = (array) $cache['value']->icons;
546 - }
547 -
548 - return $cache['value'];
476 + return json_decode( $cache['value'] );
549 477
550 478 }
551 479
552 480 public function set_version_info_cache( $value = '', $cache_key = '' ) {