PluginProbe
Polylang / 2.6.3
Polylang v2.6.3
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 +14 -74 2.82.6.3 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 // Exit if accessed directly
7 4 if ( ! defined( 'ABSPATH' ) ) {
8 5 exit;
@@ -12,9 +9,9 @@
12 9 * Allows plugins to use their own update API.
13 10 * Modified version with 'polylang' text domain and comments for translators
14 11 *
15 12 * @author Easy Digital Downloads
16 - * @version 1.7.1
13 + * @version 1.6.18
17 14 */
18 15 class PLL_Plugin_Updater {
19 16
20 17 private $api_url = '';
@@ -122,9 +119,8 @@
122 119 }
123 120
124 121 if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
125 122
126 - $no_update = false;
127 123 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
128 124
129 125 $_transient_data->response[ $this->name ] = $version_info;
130 126
@@ -130,27 +126,13 @@
130 126
131 127 // Make sure the plugin property is set to the plugin's name/location. See issue 1463 on Software Licensing's GitHub repo.
132 128 $_transient_data->response[ $this->name ]->plugin = $this->name;
133 129
134 - } else {
135 - $no_update = new stdClass();
136 - $no_update->id = '';
137 - $no_update->slug = $this->slug;
138 - $no_update->plugin = $this->name;
139 - $no_update->new_version = $version_info->new_version;
140 - $no_update->url = $version_info->homepage;
141 - $no_update->package = isset( $version_info->package ) ? $version_info->package : ''; #modified#
142 - $no_update->icons = $version_info->icons;
143 - $no_update->banners = $version_info->banners;
144 - $no_update->banners_rtl = array();
145 130 }
146 131
147 132 $_transient_data->last_checked = time();
148 133 $_transient_data->checked[ $this->name ] = $this->version;
149 134
150 - if ( $no_update ) {
151 - $_transient_data->no_update[ $this->name ] = $no_update;
152 - }
153 135 }
154 136
155 137 return $_transient_data;
156 138 }
@@ -205,12 +187,8 @@
205 187 if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) {
206 188 $version_info->icons = $this->convert_object_to_array( $version_info->icons );
207 189 }
208 190
209 - if ( isset( $version_info->contributors ) && ! is_array( $version_info->contributors ) ) {
210 - $version_info->contributors = $this->convert_object_to_array( $version_info->contributors );
211 - }
212 -
213 191 $this->set_version_info_cache( $version_info );
214 192 }
215 193
216 194 if ( ! is_object( $version_info ) ) {
@@ -216,31 +194,16 @@
216 194 if ( ! is_object( $version_info ) ) {
217 195 return;
218 196 }
219 197
220 - $no_update = false;
221 198 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
222 199
223 200 $update_cache->response[ $this->name ] = $version_info;
224 201
225 - } else {
226 - $no_update = new stdClass();
227 - $no_update->id = '';
228 - $no_update->slug = $this->slug;
229 - $no_update->plugin = $this->name;
230 - $no_update->new_version = $version_info->new_version;
231 - $no_update->url = $version_info->homepage;
232 - $no_update->package = isset( $version_info->package ) ? $version_info->package : ''; #modified#
233 - $no_update->icons = $version_info->icons;
234 - $no_update->banners = $version_info->banners;
235 - $no_update->banners_rtl = array();
236 202 }
237 203
238 - $update_cache->last_checked = time();
204 + $update_cache->last_checked = time();
239 205 $update_cache->checked[ $this->name ] = $this->version;
240 - if ( $no_update ) {
241 - $update_cache->no_update[ $this->name ] = $no_update;
242 - }
243 206
244 207 set_site_transient( 'update_plugins', $update_cache );
245 208
246 209 } else {
@@ -324,10 +287,12 @@
324 287 'icons' => array(),
325 288 )
326 289 );
327 290
291 + $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
292 +
328 293 // Get the transient where we store the api request for this plugin for 24 hours
329 - $edd_api_request_transient = $this->get_cached_version_info();
294 + $edd_api_request_transient = $this->get_cached_version_info( $cache_key );
330 295
331 296 //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now.
332 297 if ( empty( $edd_api_request_transient ) ) {
333 298
@@ -333,9 +298,9 @@
333 298
334 299 $api_response = $this->api_request( 'plugin_information', $to_send );
335 300
336 301 // Expires in 3 hours
337 - $this->set_version_info_cache( $api_response );
302 + $this->set_version_info_cache( $api_response, $cache_key );
338 303
339 304 if ( false !== $api_response ) {
340 305 $_data = $api_response;
341 306 }
@@ -358,13 +323,8 @@
358 323 if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
359 324 $_data->icons = $this->convert_object_to_array( $_data->icons );
360 325 }
361 326
362 - // Convert contributors into an associative array, since we're getting an object, but Core expects an array.
363 - if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) {
364 - $_data->contributors = $this->convert_object_to_array( $_data->contributors );
365 - }
366 -
367 327 if( ! isset( $_data->plugin ) ) {
368 328 $_data->plugin = $this->name;
369 329 }
370 330
@@ -385,9 +345,9 @@
385 345 */
386 346 private function convert_object_to_array( $data ) {
387 347 $new_data = array();
388 348 foreach ( $data as $key => $value ) {
389 - $new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value;
349 + $new_data[ $key ] = $value;
390 350 }
391 351
392 352 return $new_data;
393 353 }
@@ -498,11 +458,8 @@
498 458
499 459 return $request;
500 460 }
501 461
502 - /**
503 - * If available, show the changelog for sites in a multisite install.
504 - */
505 462 public function show_changelog() {
506 463
507 464 global $edd_plugin_data;
508 465
@@ -522,9 +479,11 @@
522 479 wp_die( __( 'You do not have permission to install plugin updates', 'polylang' ), __( 'Error', 'polylang' ), array( 'response' => 403 ) );
523 480 }
524 481
525 482 $data = $edd_plugin_data[ $_REQUEST['slug'] ];
526 - $version_info = $this->get_cached_version_info();
483 + $beta = ! empty( $data['beta'] ) ? true : false;
484 + $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' );
485 + $version_info = $this->get_cached_version_info( $cache_key );
527 486
528 487 if( false === $version_info ) {
529 488
530 489 $api_params = array(
@@ -543,8 +502,9 @@
543 502 if ( ! is_wp_error( $request ) ) {
544 503 $version_info = json_decode( wp_remote_retrieve_body( $request ) );
545 504 }
546 505
506 +
547 507 if ( ! empty( $version_info ) && isset( $version_info->sections ) ) {
548 508 $version_info->sections = maybe_unserialize( $version_info->sections );
549 509 } else {
550 510 $version_info = false;
@@ -555,30 +515,19 @@
555 515 $version_info->$key = (array) $section;
556 516 }
557 517 }
558 518
559 - $this->set_version_info_cache( $version_info );
519 + $this->set_version_info_cache( $version_info, $cache_key );
560 520
561 - // Delete the unneeded option
562 - delete_option( md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $this->beta . '_version_info' ) );
563 521 }
564 522
565 - if ( isset( $version_info->sections ) ) {
566 - $sections = $this->convert_object_to_array( $version_info->sections );
567 - if ( ! empty( $sections['changelog'] ) ) {
568 - echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections['changelog'] ) . '</div>';
569 - }
523 + if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
524 + echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
570 525 }
571 526
572 527 exit;
573 528 }
574 529
575 - /**
576 - * Gets the plugin's cached version information from the database.
577 - *
578 - * @param string $cache_key
579 - * @return boolean|string
580 - */
581 530 public function get_cached_version_info( $cache_key = '' ) {
582 531
583 532 if( empty( $cache_key ) ) {
584 533 $cache_key = $this->cache_key;
@@ -599,14 +548,8 @@
599 548 return $cache['value'];
600 549
601 550 }
602 551
603 - /**
604 - * Adds the plugin version information to the database.
605 - *
606 - * @param string $value
607 - * @param string $cache_key
608 - */
609 552 public function set_version_info_cache( $value = '', $cache_key = '' ) {
610 553
611 554 if( empty( $cache_key ) ) {
612 555 $cache_key = $this->cache_key;
@@ -618,10 +561,8 @@
618 561 );
619 562
620 563 update_option( $cache_key, $data, 'no' );
621 564
622 - // Delete the duplicate option
623 - delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) );
624 565 }
625 566
626 567 /**
627 568 * Returns if the SSL of the store should be verified.
@@ -633,5 +574,4 @@
633 574 return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
634 575 }
635 576
636 577 }
637 -