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