| @@ -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.7.1 | |
| 13 | + * @version 1.8.0 | |
| 17 | 14 | */ |
| 18 | 15 | class PLL_Plugin_Updater { |
| 19 | 16 | |
| 20 | 17 | private $api_url = ''; |
| @@ -111,49 +108,52 @@ | ||
| 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 | - $version_info = $this->get_cached_version_info(); | |
| 116 | - | |
| 117 | - if ( false === $version_info ) { | |
| 118 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) ); | |
| 119 | - | |
| 120 | - $this->set_version_info_cache( $version_info ); | |
| 121 | - | |
| 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 | + } | |
| 122 | 120 | } |
| 121 | + $_transient_data->last_checked = time(); | |
| 122 | + $_transient_data->checked[ $this->name ] = $this->version; | |
| 123 | 123 | |
| 124 | - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { | |
| 124 | + return $_transient_data; | |
| 125 | + } | |
| 125 | 126 | |
| 126 | - $no_update = false; | |
| 127 | - 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(); | |
| 128 | 135 | |
| 129 | - $_transient_data->response[ $this->name ] = $version_info; | |
| 130 | - | |
| 131 | - // Make sure the plugin property is set to the plugin's name/location. See issue 1463 on Software Licensing's GitHub repo. | |
| 132 | - $_transient_data->response[ $this->name ]->plugin = $this->name; | |
| 133 | - | |
| 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(); | |
| 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; | |
| 145 | 146 | } |
| 146 | 147 | |
| 147 | - $_transient_data->last_checked = time(); | |
| 148 | - $_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; | |
| 149 | 151 | |
| 150 | - if ( $no_update ) { | |
| 151 | - $_transient_data->no_update[ $this->name ] = $no_update; | |
| 152 | - } | |
| 152 | + $this->set_version_info_cache( $version_info ); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - return $_transient_data; | |
| 155 | + return $version_info; | |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
| 159 | 159 | * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! |
| @@ -187,9 +187,9 @@ | ||
| 187 | 187 | $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass(); |
| 188 | 188 | |
| 189 | 189 | if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { |
| 190 | 190 | |
| 191 | - $version_info = $this->get_cached_version_info(); | |
| 191 | + $version_info = $this->get_repo_api_data(); | |
| 192 | 192 | |
| 193 | 193 | if ( false === $version_info ) { |
| 194 | 194 | $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) ); |
| 195 | 195 | |
| @@ -216,31 +216,16 @@ | ||
| 216 | 216 | if ( ! is_object( $version_info ) ) { |
| 217 | 217 | return; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - $no_update = false; | |
| 221 | 220 | if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
| 222 | - | |
| 223 | 221 | $update_cache->response[ $this->name ] = $version_info; |
| 224 | - | |
| 225 | 222 | } 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(); | |
| 223 | + $update_cache->no_update[ $this->name ] = $version_info; | |
| 236 | 224 | } |
| 237 | 225 | |
| 238 | 226 | $update_cache->last_checked = time(); |
| 239 | 227 | $update_cache->checked[ $this->name ] = $this->version; |
| 240 | - if ( $no_update ) { | |
| 241 | - $update_cache->no_update[ $this->name ] = $no_update; | |
| 242 | - } | |
| 243 | 228 | |
| 244 | 229 | set_site_transient( 'update_plugins', $update_cache ); |
| 245 | 230 | |
| 246 | 231 | } else { |
| @@ -444,18 +429,18 @@ | ||
| 444 | 429 | } |
| 445 | 430 | } |
| 446 | 431 | |
| 447 | 432 | if ( false === $edd_plugin_url_available[ $store_hash ] ) { |
| 448 | - return; | |
| 433 | + return false; | |
| 449 | 434 | } |
| 450 | 435 | |
| 451 | 436 | $data = array_merge( $this->api_data, $_data ); |
| 452 | 437 | |
| 453 | 438 | if ( $data['slug'] != $this->slug ) { |
| 454 | - return; | |
| 439 | + return false; | |
| 455 | 440 | } |
| 456 | 441 | |
| 457 | - if( $this->api_url == trailingslashit ( home_url() ) ) { | |
| 442 | + if ( $this->api_url == trailingslashit ( home_url() ) ) { | |
| 458 | 443 | return false; // Don't allow a plugin to ping itself |
| 459 | 444 | } |
| 460 | 445 | |
| 461 | 446 | $api_params = array( |
| @@ -489,9 +474,9 @@ | ||
| 489 | 474 | if ( $request && isset( $request->icons ) ) { |
| 490 | 475 | $request->icons = maybe_unserialize( $request->icons ); |
| 491 | 476 | } |
| 492 | 477 | |
| 493 | - if( ! empty( $request->sections ) ) { | |
| 478 | + if ( ! empty( $request->sections ) ) { | |
| 494 | 479 | foreach( $request->sections as $key => $section ) { |
| 495 | 480 | $request->$key = (array) $section; |
| 496 | 481 | } |
| 497 | 482 | } |
| @@ -633,5 +618,4 @@ | ||
| 633 | 618 | return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this ); |
| 634 | 619 | } |
| 635 | 620 | |
| 636 | 621 | } |
| 637 | - | |