PluginProbe
Polylang / 3.1.4
Polylang v3.1.4
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 +83 -39 2.7.13.1.4 View file →
@@ -6,12 +6,12 @@
6 6 }
7 7
8 8 /**
9 9 * Allows plugins to use their own update API.
10 - * Modified version with 'polylang' text domain and comments for translators
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.8.0
14 14 */
15 15 class PLL_Plugin_Updater {
16 16
17 17 private $api_url = '';
@@ -108,34 +108,52 @@
108 108 if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
109 109 return $_transient_data;
110 110 }
111 111
112 - $version_info = $this->get_cached_version_info();
113 -
114 - if ( false === $version_info ) {
115 - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
116 -
117 - $this->set_version_info_cache( $version_info );
118 -
112 + $current = $this->get_repo_api_data();
113 + if ( false !== $current && is_object( $current ) && isset( $current->new_version ) ) {
114 + if ( version_compare( $this->version, $current->new_version, '<' ) ) {
115 + $_transient_data->response[ $this->name ] = $current;
116 + } else {
117 + // Populating the no_update information is required to support auto-updates in WordPress 5.5.
118 + $_transient_data->no_update[ $this->name ] = $current;
119 + }
119 120 }
121 + $_transient_data->last_checked = time();
122 + $_transient_data->checked[ $this->name ] = $this->version;
120 123
121 - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
124 + return $_transient_data;
125 + }
122 126
123 - if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
127 + /**
128 + * Get repo API data from store.
129 + * Save to cache.
130 + *
131 + * @return \stdClass
132 + */
133 + public function get_repo_api_data() {
134 + $version_info = $this->get_cached_version_info();
124 135
125 - $_transient_data->response[ $this->name ] = $version_info;
126 -
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 -
136 + if ( false === $version_info ) {
137 + $version_info = $this->api_request(
138 + 'plugin_latest_version',
139 + array(
140 + 'slug' => $this->slug,
141 + 'beta' => $this->beta,
142 + )
143 + );
144 + if ( ! $version_info ) {
145 + return false;
130 146 }
131 147
132 - $_transient_data->last_checked = time();
133 - $_transient_data->checked[ $this->name ] = $this->version;
148 + // This is required for your plugin to support auto-updates in WordPress 5.5.
149 + $version_info->plugin = $this->name;
150 + $version_info->id = $this->name;
134 151
152 + $this->set_version_info_cache( $version_info );
135 153 }
136 154
137 - return $_transient_data;
155 + return $version_info;
138 156 }
139 157
140 158 /**
141 159 * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise!
@@ -169,9 +187,9 @@
169 187 $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass();
170 188
171 189 if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
172 190
173 - $version_info = $this->get_cached_version_info();
191 + $version_info = $this->get_repo_api_data();
174 192
175 193 if ( false === $version_info ) {
176 194 $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
177 195
@@ -187,8 +205,12 @@
187 205 if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) {
188 206 $version_info->icons = $this->convert_object_to_array( $version_info->icons );
189 207 }
190 208
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 +
191 213 $this->set_version_info_cache( $version_info );
192 214 }
193 215
194 216 if ( ! is_object( $version_info ) ) {
@@ -195,14 +217,14 @@
195 217 return;
196 218 }
197 219
198 220 if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
199 -
200 221 $update_cache->response[ $this->name ] = $version_info;
201 -
222 + } else {
223 + $update_cache->no_update[ $this->name ] = $version_info;
202 224 }
203 225
204 - $update_cache->last_checked = time();
226 + $update_cache->last_checked = time();
205 227 $update_cache->checked[ $this->name ] = $this->version;
206 228
207 229 set_site_transient( 'update_plugins', $update_cache );
208 230
@@ -287,12 +309,10 @@
287 309 'icons' => array(),
288 310 )
289 311 );
290 312
291 - $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
292 -
293 313 // Get the transient where we store the api request for this plugin for 24 hours
294 - $edd_api_request_transient = $this->get_cached_version_info( $cache_key );
314 + $edd_api_request_transient = $this->get_cached_version_info();
295 315
296 316 //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.
297 317 if ( empty( $edd_api_request_transient ) ) {
298 318
@@ -298,9 +318,9 @@
298 318
299 319 $api_response = $this->api_request( 'plugin_information', $to_send );
300 320
301 321 // Expires in 3 hours
302 - $this->set_version_info_cache( $api_response, $cache_key );
322 + $this->set_version_info_cache( $api_response );
303 323
304 324 if ( false !== $api_response ) {
305 325 $_data = $api_response;
306 326 }
@@ -323,8 +343,13 @@
323 343 if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
324 344 $_data->icons = $this->convert_object_to_array( $_data->icons );
325 345 }
326 346
347 + // Convert contributors into an associative array, since we're getting an object, but Core expects an array.
348 + if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) {
349 + $_data->contributors = $this->convert_object_to_array( $_data->contributors );
350 + }
351 +
327 352 if( ! isset( $_data->plugin ) ) {
328 353 $_data->plugin = $this->name;
329 354 }
330 355
@@ -345,9 +370,9 @@
345 370 */
346 371 private function convert_object_to_array( $data ) {
347 372 $new_data = array();
348 373 foreach ( $data as $key => $value ) {
349 - $new_data[ $key ] = $value;
374 + $new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value;
350 375 }
351 376
352 377 return $new_data;
353 378 }
@@ -404,18 +429,18 @@
404 429 }
405 430 }
406 431
407 432 if ( false === $edd_plugin_url_available[ $store_hash ] ) {
408 - return;
433 + return false;
409 434 }
410 435
411 436 $data = array_merge( $this->api_data, $_data );
412 437
413 438 if ( $data['slug'] != $this->slug ) {
414 - return;
439 + return false;
415 440 }
416 441
417 - if( $this->api_url == trailingslashit ( home_url() ) ) {
442 + if ( $this->api_url == trailingslashit ( home_url() ) ) {
418 443 return false; // Don't allow a plugin to ping itself
419 444 }
420 445
421 446 $api_params = array(
@@ -449,9 +474,9 @@
449 474 if ( $request && isset( $request->icons ) ) {
450 475 $request->icons = maybe_unserialize( $request->icons );
451 476 }
452 477
453 - if( ! empty( $request->sections ) ) {
478 + if ( ! empty( $request->sections ) ) {
454 479 foreach( $request->sections as $key => $section ) {
455 480 $request->$key = (array) $section;
456 481 }
457 482 }
@@ -458,8 +483,11 @@
458 483
459 484 return $request;
460 485 }
461 486
487 + /**
488 + * If available, show the changelog for sites in a multisite install.
489 + */
462 490 public function show_changelog() {
463 491
464 492 global $edd_plugin_data;
465 493
@@ -479,11 +507,9 @@
479 507 wp_die( __( 'You do not have permission to install plugin updates', 'polylang' ), __( 'Error', 'polylang' ), array( 'response' => 403 ) );
480 508 }
481 509
482 510 $data = $edd_plugin_data[ $_REQUEST['slug'] ];
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 );
511 + $version_info = $this->get_cached_version_info();
486 512
487 513 if( false === $version_info ) {
488 514
489 515 $api_params = array(
@@ -502,9 +528,8 @@
502 528 if ( ! is_wp_error( $request ) ) {
503 529 $version_info = json_decode( wp_remote_retrieve_body( $request ) );
504 530 }
505 531
506 -
507 532 if ( ! empty( $version_info ) && isset( $version_info->sections ) ) {
508 533 $version_info->sections = maybe_unserialize( $version_info->sections );
509 534 } else {
510 535 $version_info = false;
@@ -515,19 +540,30 @@
515 540 $version_info->$key = (array) $section;
516 541 }
517 542 }
518 543
519 - $this->set_version_info_cache( $version_info, $cache_key );
544 + $this->set_version_info_cache( $version_info );
520 545
546 + // Delete the unneeded option
547 + delete_option( md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $this->beta . '_version_info' ) );
521 548 }
522 549
523 - if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
524 - echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
550 + if ( isset( $version_info->sections ) ) {
551 + $sections = $this->convert_object_to_array( $version_info->sections );
552 + if ( ! empty( $sections['changelog'] ) ) {
553 + echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections['changelog'] ) . '</div>';
554 + }
525 555 }
526 556
527 557 exit;
528 558 }
529 559
560 + /**
561 + * Gets the plugin's cached version information from the database.
562 + *
563 + * @param string $cache_key
564 + * @return boolean|string
565 + */
530 566 public function get_cached_version_info( $cache_key = '' ) {
531 567
532 568 if( empty( $cache_key ) ) {
533 569 $cache_key = $this->cache_key;
@@ -548,8 +584,14 @@
548 584 return $cache['value'];
549 585
550 586 }
551 587
588 + /**
589 + * Adds the plugin version information to the database.
590 + *
591 + * @param string $value
592 + * @param string $cache_key
593 + */
552 594 public function set_version_info_cache( $value = '', $cache_key = '' ) {
553 595
554 596 if( empty( $cache_key ) ) {
555 597 $cache_key = $this->cache_key;
@@ -561,8 +603,10 @@
561 603 );
562 604
563 605 update_option( $cache_key, $data, 'no' );
564 606
607 + // Delete the duplicate option
608 + delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) );
565 609 }
566 610
567 611 /**
568 612 * Returns if the SSL of the store should be verified.