| @@ -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.7 | |
| 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() |
| @@ -119,35 +117,17 @@ | ||
| 119 | 117 | } |
| 120 | 118 | |
| 121 | 119 | if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
| 122 | 120 | |
| 123 | - $no_update = false; | |
| 124 | 121 | if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
| 125 | 122 | |
| 126 | 123 | $_transient_data->response[ $this->name ] = $version_info; |
| 127 | 124 | |
| 128 | - // Make sure the plugin property is set to the plugin's name/location. See issue 1463 on Software Licensing's GitHub repo. | |
| 129 | - $_transient_data->response[ $this->name ]->plugin = $this->name; | |
| 130 | - | |
| 131 | - } else { | |
| 132 | - $no_update = new stdClass(); | |
| 133 | - $no_update->id = ''; | |
| 134 | - $no_update->slug = $this->slug; | |
| 135 | - $no_update->plugin = $this->name; | |
| 136 | - $no_update->new_version = $version_info->new_version; | |
| 137 | - $no_update->url = $version_info->homepage; | |
| 138 | - $no_update->package = isset( $version_info->package ) ? $version_info->package : ''; #modified# | |
| 139 | - $no_update->icons = $version_info->icons; | |
| 140 | - $no_update->banners = $version_info->banners; | |
| 141 | - $no_update->banners_rtl = array(); | |
| 142 | 125 | } |
| 143 | 126 | |
| 144 | 127 | $_transient_data->last_checked = time(); |
| 145 | 128 | $_transient_data->checked[ $this->name ] = $this->version; |
| 146 | 129 | |
| 147 | - if ( $no_update ) { | |
| 148 | - $_transient_data->no_update[ $this->name ] = $no_update; | |
| 149 | - } | |
| 150 | 130 | } |
| 151 | 131 | |
| 152 | 132 | return $_transient_data; |
| 153 | 133 | } |
| @@ -189,29 +169,8 @@ | ||
| 189 | 169 | |
| 190 | 170 | if ( false === $version_info ) { |
| 191 | 171 | $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) ); |
| 192 | 172 | |
| 193 | - // Since we disabled our filter for the transient, we aren't running our object conversion on banners, sections, or icons. Do this now: | |
| 194 | - if ( isset( $version_info->banners ) && ! is_array( $version_info->banners ) ) { | |
| 195 | - $version_info->banners = $this->convert_object_to_array( $version_info->banners ); | |
| 196 | - } | |
| 197 | - | |
| 198 | - if ( isset( $version_info->sections ) && ! is_array( $version_info->sections ) ) { | |
| 199 | - $version_info->sections = $this->convert_object_to_array( $version_info->sections ); | |
| 200 | - } | |
| 201 | - | |
| 202 | - if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) { | |
| 203 | - $version_info->icons = $this->convert_object_to_array( $version_info->icons ); | |
| 204 | - } | |
| 205 | - | |
| 206 | - if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) { | |
| 207 | - $version_info->icons = $this->convert_object_to_array( $version_info->icons ); | |
| 208 | - } | |
| 209 | - | |
| 210 | - if ( isset( $version_info->contributors ) && ! is_array( $version_info->contributors ) ) { | |
| 211 | - $version_info->contributors = $this->convert_object_to_array( $version_info->contributors ); | |
| 212 | - } | |
| 213 | - | |
| 214 | 173 | $this->set_version_info_cache( $version_info ); |
| 215 | 174 | } |
| 216 | 175 | |
| 217 | 176 | if ( ! is_object( $version_info ) ) { |
| @@ -217,31 +176,16 @@ | ||
| 217 | 176 | if ( ! is_object( $version_info ) ) { |
| 218 | 177 | return; |
| 219 | 178 | } |
| 220 | 179 | |
| 221 | - $no_update = false; | |
| 222 | 180 | if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
| 223 | 181 | |
| 224 | 182 | $update_cache->response[ $this->name ] = $version_info; |
| 225 | 183 | |
| 226 | - } else { | |
| 227 | - $no_update = new stdClass(); | |
| 228 | - $no_update->id = ''; | |
| 229 | - $no_update->slug = $this->slug; | |
| 230 | - $no_update->plugin = $this->name; | |
| 231 | - $no_update->new_version = $version_info->new_version; | |
| 232 | - $no_update->url = $version_info->homepage; | |
| 233 | - $no_update->package = isset( $version_info->package ) ? $version_info->package : ''; #modified# | |
| 234 | - $no_update->icons = $version_info->icons; | |
| 235 | - $no_update->banners = $version_info->banners; | |
| 236 | - $no_update->banners_rtl = array(); | |
| 237 | 184 | } |
| 238 | 185 | |
| 239 | - $update_cache->last_checked = time(); | |
| 186 | + $update_cache->last_checked = time(); | |
| 240 | 187 | $update_cache->checked[ $this->name ] = $this->version; |
| 241 | - if ( $no_update ) { | |
| 242 | - $update_cache->no_update[ $this->name ] = $no_update; | |
| 243 | - } | |
| 244 | 188 | |
| 245 | 189 | set_site_transient( 'update_plugins', $update_cache ); |
| 246 | 190 | |
| 247 | 191 | } else { |
| @@ -320,10 +264,9 @@ | ||
| 320 | 264 | 'slug' => $this->slug, |
| 321 | 265 | 'is_ssl' => is_ssl(), |
| 322 | 266 | 'fields' => array( |
| 323 | 267 | 'banners' => array(), |
| 324 | - 'reviews' => false, | |
| 325 | - 'icons' => array(), | |
| 268 | + 'reviews' => false | |
| 326 | 269 | ) |
| 327 | 270 | ); |
| 328 | 271 | |
| 329 | 272 | $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ); |
| @@ -348,55 +291,30 @@ | ||
| 348 | 291 | } |
| 349 | 292 | |
| 350 | 293 | // Convert sections into an associative array, since we're getting an object, but Core expects an array. |
| 351 | 294 | if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) { |
| 352 | - $_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; | |
| 353 | 301 | } |
| 354 | 302 | |
| 355 | 303 | // Convert banners into an associative array, since we're getting an object, but Core expects an array. |
| 356 | 304 | if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) { |
| 357 | - $_data->banners = $this->convert_object_to_array( $_data->banners ); | |
| 358 | - } | |
| 305 | + $new_banners = array(); | |
| 306 | + foreach ( $_data->banners as $key => $value ) { | |
| 307 | + $new_banners[ $key ] = $value; | |
| 308 | + } | |
| 359 | 309 | |
| 360 | - // Convert icons into an associative array, since we're getting an object, but Core expects an array. | |
| 361 | - if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) { | |
| 362 | - $_data->icons = $this->convert_object_to_array( $_data->icons ); | |
| 310 | + $_data->banners = $new_banners; | |
| 363 | 311 | } |
| 364 | 312 | |
| 365 | - // Convert contributors into an associative array, since we're getting an object, but Core expects an array. | |
| 366 | - if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) { | |
| 367 | - $_data->contributors = $this->convert_object_to_array( $_data->contributors ); | |
| 368 | - } | |
| 369 | - | |
| 370 | - if( ! isset( $_data->plugin ) ) { | |
| 371 | - $_data->plugin = $this->name; | |
| 372 | - } | |
| 373 | - | |
| 374 | 313 | return $_data; |
| 375 | 314 | } |
| 376 | 315 | |
| 377 | 316 | /** |
| 378 | - * Convert some objects to arrays when injecting data into the update API | |
| 379 | - * | |
| 380 | - * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON | |
| 381 | - * decoding, they are objects. This method allows us to pass in the object and return an associative array. | |
| 382 | - * | |
| 383 | - * @since 3.6.5 | |
| 384 | - * | |
| 385 | - * @param stdClass $data | |
| 386 | - * | |
| 387 | - * @return array | |
| 388 | - */ | |
| 389 | - private function convert_object_to_array( $data ) { | |
| 390 | - $new_data = array(); | |
| 391 | - foreach ( $data as $key => $value ) { | |
| 392 | - $new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value; | |
| 393 | - } | |
| 394 | - | |
| 395 | - return $new_data; | |
| 396 | - } | |
| 397 | - | |
| 398 | - /** | |
| 399 | 317 | * Disable SSL verification in order to prevent download update failures |
| 400 | 318 | * |
| 401 | 319 | * @param array $args |
| 402 | 320 | * @param string $url |
| @@ -424,34 +342,10 @@ | ||
| 424 | 342 | * @return false|object |
| 425 | 343 | */ |
| 426 | 344 | private function api_request( $_action, $_data ) { |
| 427 | 345 | |
| 428 | - global $wp_version, $edd_plugin_url_available; | |
| 346 | + global $wp_version; | |
| 429 | 347 | |
| 430 | - $verify_ssl = $this->verify_ssl(); | |
| 431 | - | |
| 432 | - // Do a quick status check on this domain if we haven't already checked it. | |
| 433 | - $store_hash = md5( $this->api_url ); | |
| 434 | - if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) { | |
| 435 | - $test_url_parts = parse_url( $this->api_url ); | |
| 436 | - | |
| 437 | - $scheme = ! empty( $test_url_parts['scheme'] ) ? $test_url_parts['scheme'] : 'http'; | |
| 438 | - $host = ! empty( $test_url_parts['host'] ) ? $test_url_parts['host'] : ''; | |
| 439 | - $port = ! empty( $test_url_parts['port'] ) ? ':' . $test_url_parts['port'] : ''; | |
| 440 | - | |
| 441 | - if ( empty( $host ) ) { | |
| 442 | - $edd_plugin_url_available[ $store_hash ] = false; | |
| 443 | - } else { | |
| 444 | - $test_url = $scheme . '://' . $host . $port; | |
| 445 | - $response = wp_remote_get( $test_url, array( 'timeout' => $this->health_check_timeout, 'sslverify' => $verify_ssl ) ); | |
| 446 | - $edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true; | |
| 447 | - } | |
| 448 | - } | |
| 449 | - | |
| 450 | - if ( false === $edd_plugin_url_available[ $store_hash ] ) { | |
| 451 | - return; | |
| 452 | - } | |
| 453 | - | |
| 454 | 348 | $data = array_merge( $this->api_data, $_data ); |
| 455 | 349 | |
| 456 | 350 | if ( $data['slug'] != $this->slug ) { |
| 457 | 351 | return; |
| @@ -456,9 +350,9 @@ | ||
| 456 | 350 | if ( $data['slug'] != $this->slug ) { |
| 457 | 351 | return; |
| 458 | 352 | } |
| 459 | 353 | |
| 460 | - if( $this->api_url == trailingslashit ( home_url() ) ) { | |
| 354 | + if( $this->api_url == trailingslashit (home_url() ) ) { | |
| 461 | 355 | return false; // Don't allow a plugin to ping itself |
| 462 | 356 | } |
| 463 | 357 | |
| 464 | 358 | $api_params = array( |
| @@ -472,8 +366,9 @@ | ||
| 472 | 366 | 'url' => home_url(), |
| 473 | 367 | 'beta' => ! empty( $data['beta'] ), |
| 474 | 368 | ); |
| 475 | 369 | |
| 370 | + $verify_ssl = $this->verify_ssl(); | |
| 476 | 371 | $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) ); |
| 477 | 372 | |
| 478 | 373 | if ( ! is_wp_error( $request ) ) { |
| 479 | 374 | $request = json_decode( wp_remote_retrieve_body( $request ) ); |
| @@ -488,12 +383,8 @@ | ||
| 488 | 383 | if ( $request && isset( $request->banners ) ) { |
| 489 | 384 | $request->banners = maybe_unserialize( $request->banners ); |
| 490 | 385 | } |
| 491 | 386 | |
| 492 | - if ( $request && isset( $request->icons ) ) { | |
| 493 | - $request->icons = maybe_unserialize( $request->icons ); | |
| 494 | - } | |
| 495 | - | |
| 496 | 387 | if( ! empty( $request->sections ) ) { |
| 497 | 388 | foreach( $request->sections as $key => $section ) { |
| 498 | 389 | $request->$key = (array) $section; |
| 499 | 390 | } |
| @@ -581,15 +472,9 @@ | ||
| 581 | 472 | if( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) { |
| 582 | 473 | return false; // Cache is expired |
| 583 | 474 | } |
| 584 | 475 | |
| 585 | - // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point. | |
| 586 | - $cache['value'] = json_decode( $cache['value'] ); | |
| 587 | - if ( ! empty( $cache['value']->icons ) ) { | |
| 588 | - $cache['value']->icons = (array) $cache['value']->icons; | |
| 589 | - } | |
| 590 | - | |
| 591 | - return $cache['value']; | |
| 476 | + return json_decode( $cache['value'] ); | |
| 592 | 477 | |
| 593 | 478 | } |
| 594 | 479 | |
| 595 | 480 | public function set_version_info_cache( $value = '', $cache_key = '' ) { |