PluginProbe
Polylang / 2.0.12
Polylang v2.0.12
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 +59 -253 2.72.0.12 View file →
@@ -1,6 +1,9 @@
1 1 <?php
2 2
3 +// uncomment this line for testing
4 +//set_site_transient( 'update_plugins', null );
5 +
3 6 // Exit if accessed directly
4 7 if ( ! defined( 'ABSPATH' ) ) {
5 8 exit;
6 9 }
@@ -8,23 +11,18 @@
8 11 /**
9 12 * Allows plugins to use their own update API.
10 13 * Modified version with 'polylang' text domain and comments for translators
11 14 *
12 - * @author Easy Digital Downloads
13 - * @version 1.6.18
15 + * @author Pippin Williamson
16 + * @version 1.6.3
14 17 */
15 18 class PLL_Plugin_Updater {
19 + private $api_url = '';
20 + private $api_data = array();
21 + private $name = '';
22 + private $slug = '';
23 + private $version = '';
16 24
17 - private $api_url = '';
18 - private $api_data = array();
19 - private $name = '';
20 - private $slug = '';
21 - private $version = '';
22 - private $wp_override = false;
23 - private $cache_key = '';
24 -
25 - private $health_check_timeout = 5;
26 -
27 25 /**
28 26 * Class constructor.
29 27 *
30 28 * @uses plugin_basename()
@@ -37,28 +35,16 @@
37 35 public function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
38 36
39 37 global $edd_plugin_data;
40 38
41 - $this->api_url = trailingslashit( $_api_url );
42 - $this->api_data = $_api_data;
43 - $this->name = plugin_basename( $_plugin_file );
44 - $this->slug = basename( $_plugin_file, '.php' );
45 - $this->version = $_api_data['version'];
46 - $this->wp_override = isset( $_api_data['wp_override'] ) ? (bool) $_api_data['wp_override'] : false;
47 - $this->beta = ! empty( $this->api_data['beta'] ) ? true : false;
48 - $this->cache_key = 'edd_sl_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
39 + $this->api_url = trailingslashit( $_api_url );
40 + $this->api_data = $_api_data;
41 + $this->name = plugin_basename( $_plugin_file );
42 + $this->slug = basename( $_plugin_file, '.php' );
43 + $this->version = $_api_data['version'];
49 44
50 45 $edd_plugin_data[ $this->slug ] = $this->api_data;
51 46
52 - /**
53 - * Fires after the $edd_plugin_data is setup.
54 - *
55 - * @since x.x.x
56 - *
57 - * @param array $edd_plugin_data Array of EDD SL plugin data.
58 - */
59 - do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data );
60 -
61 47 // Set up hooks.
62 48 $this->init();
63 49
64 50 }
@@ -73,9 +59,9 @@
73 59 public function init() {
74 60
75 61 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
76 62 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
77 - remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10 );
63 + remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10, 2 );
78 64 add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 );
79 65 add_action( 'admin_init', array( $this, 'show_changelog' ) );
80 66
81 67 }
@@ -104,35 +90,25 @@
104 90 if ( 'plugins.php' == $pagenow && is_multisite() ) {
105 91 return $_transient_data;
106 92 }
107 93
108 - if ( ! empty( $_transient_data->response ) && ! empty( $_transient_data->response[ $this->name ] ) && false === $this->wp_override ) {
109 - return $_transient_data;
110 - }
94 + if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) {
111 95
112 - $version_info = $this->get_cached_version_info();
96 + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
113 97
114 - if ( false === $version_info ) {
115 - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
98 + if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
116 99
117 - $this->set_version_info_cache( $version_info );
100 + if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
118 101
119 - }
102 + $_transient_data->response[ $this->name ] = $version_info;
120 103
121 - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) {
104 + }
122 105
123 - if ( version_compare( $this->version, $version_info->new_version, '<' ) ) {
106 + $_transient_data->last_checked = time();
107 + $_transient_data->checked[ $this->name ] = $this->version;
124 108
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 -
130 109 }
131 110
132 - $_transient_data->last_checked = time();
133 - $_transient_data->checked[ $this->name ] = $this->version;
134 -
135 111 }
136 112
137 113 return $_transient_data;
138 114 }
@@ -144,20 +120,16 @@
144 120 * @param array $plugin
145 121 */
146 122 public function show_update_notification( $file, $plugin ) {
147 123
148 - if ( is_network_admin() ) {
124 + if ( ! current_user_can( 'update_plugins' ) ) {
149 125 return;
150 126 }
151 127
152 - if( ! current_user_can( 'update_plugins' ) ) {
128 + if ( ! is_multisite() ) {
153 129 return;
154 130 }
155 131
156 - if( ! is_multisite() ) {
157 - return;
158 - }
159 -
160 132 if ( $this->name != $file ) {
161 133 return;
162 134 }
163 135
@@ -169,27 +141,16 @@
169 141 $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass();
170 142
171 143 if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) {
172 144
173 - $version_info = $this->get_cached_version_info();
145 + $cache_key = md5( 'edd_plugin_' . sanitize_key( $this->name ) . '_version_info' );
146 + $version_info = get_transient( $cache_key );
174 147
175 148 if ( false === $version_info ) {
176 - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) );
177 149
178 - // Since we disabled our filter for the transient, we aren't running our object conversion on banners, sections, or icons. Do this now:
179 - if ( isset( $version_info->banners ) && ! is_array( $version_info->banners ) ) {
180 - $version_info->banners = $this->convert_object_to_array( $version_info->banners );
181 - }
150 + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) );
182 151
183 - if ( isset( $version_info->sections ) && ! is_array( $version_info->sections ) ) {
184 - $version_info->sections = $this->convert_object_to_array( $version_info->sections );
185 - }
186 -
187 - if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) {
188 - $version_info->icons = $this->convert_object_to_array( $version_info->icons );
189 - }
190 -
191 - $this->set_version_info_cache( $version_info );
152 + set_transient( $cache_key, $version_info, 3600 );
192 153 }
193 154
194 155 if ( ! is_object( $version_info ) ) {
195 156 return;
@@ -218,19 +179,16 @@
218 179 if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) {
219 180
220 181 // build a plugin list row, with update notification
221 182 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
222 - # <tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
223 - echo '<tr class="plugin-update-tr" id="' . $this->slug . '-update" data-slug="' . $this->slug . '" data-plugin="' . $this->slug . '/' . $file . '">';
224 - echo '<td colspan="3" class="plugin-update colspanchange">';
225 - echo '<div class="update-message notice inline notice-warning notice-alt">';
183 + echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">';
226 184
227 185 $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' );
228 186
229 187 if ( empty( $version_info->download_link ) ) {
230 188 printf(
231 - /* translators: %1$s plugin name, %3$s plugin version, %2$s is link start tag, %4$s is link end tag. */
232 - __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'polylang' ),
189 + /* translators: %1$s plugin name, %3$s plugin version, %2$s and %4$s are html tags */
190 + esc_html__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'polylang' ),
233 191 esc_html( $version_info->name ),
234 192 '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
235 193 esc_html( $version_info->new_version ),
236 194 '</a>'
@@ -236,10 +194,10 @@
236 194 '</a>'
237 195 );
238 196 } else {
239 197 printf(
240 - /* translators: %1$s plugin name, %3$s plugin version, %2$s and %5$s are link start tags, %4$s and %6$s are link end tags. */
241 - __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'polylang' ),
198 + /* translators: %1$s plugin name, %3$s plugin version, %2$s, %4$s, %5$s and %6$s are html tags */
199 + esc_html__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'polylang' ),
242 200 esc_html( $version_info->name ),
243 201 '<a target="_blank" class="thickbox" href="' . esc_url( $changelog_link ) . '">',
244 202 esc_html( $version_info->new_version ),
245 203 '</a>',
@@ -253,8 +211,9 @@
253 211 echo '</div></td></tr>';
254 212 }
255 213 }
256 214
215 +
257 216 /**
258 217 * Updates information on the "View version x.x details" page with custom data.
259 218 *
260 219 * @uses api_request()
@@ -265,8 +224,9 @@
265 224 * @return object $_data
266 225 */
267 226 public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
268 227
228 +
269 229 if ( $_action != 'plugin_information' ) {
270 230
271 231 return $_data;
272 232
@@ -281,78 +241,23 @@
281 241 $to_send = array(
282 242 'slug' => $this->slug,
283 243 'is_ssl' => is_ssl(),
284 244 'fields' => array(
285 - 'banners' => array(),
286 - 'reviews' => false,
287 - 'icons' => array(),
245 + 'banners' => false, // These will be supported soon hopefully
246 + 'reviews' => false
288 247 )
289 248 );
290 249
291 - $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) );
250 + $api_response = $this->api_request( 'plugin_information', $to_send );
292 251
293 - // 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 );
295 -
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.
297 - if ( empty( $edd_api_request_transient ) ) {
298 -
299 - $api_response = $this->api_request( 'plugin_information', $to_send );
300 -
301 - // Expires in 3 hours
302 - $this->set_version_info_cache( $api_response, $cache_key );
303 -
304 - if ( false !== $api_response ) {
305 - $_data = $api_response;
306 - }
307 -
308 - } else {
309 - $_data = $edd_api_request_transient;
252 + if ( false !== $api_response ) {
253 + $_data = $api_response;
310 254 }
311 255
312 - // Convert sections into an associative array, since we're getting an object, but Core expects an array.
313 - if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) {
314 - $_data->sections = $this->convert_object_to_array( $_data->sections );
315 - }
316 -
317 - // Convert banners into an associative array, since we're getting an object, but Core expects an array.
318 - if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) {
319 - $_data->banners = $this->convert_object_to_array( $_data->banners );
320 - }
321 -
322 - // Convert icons into an associative array, since we're getting an object, but Core expects an array.
323 - if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) {
324 - $_data->icons = $this->convert_object_to_array( $_data->icons );
325 - }
326 -
327 - if( ! isset( $_data->plugin ) ) {
328 - $_data->plugin = $this->name;
329 - }
330 -
331 256 return $_data;
332 257 }
333 258
334 - /**
335 - * Convert some objects to arrays when injecting data into the update API
336 - *
337 - * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON
338 - * decoding, they are objects. This method allows us to pass in the object and return an associative array.
339 - *
340 - * @since 3.6.5
341 - *
342 - * @param stdClass $data
343 - *
344 - * @return array
345 - */
346 - private function convert_object_to_array( $data ) {
347 - $new_data = array();
348 - foreach ( $data as $key => $value ) {
349 - $new_data[ $key ] = $value;
350 - }
351 259
352 - return $new_data;
353 - }
354 -
355 260 /**
356 261 * Disable SSL verification in order to prevent download update failures
357 262 *
358 263 * @param array $args
@@ -359,15 +264,13 @@
359 264 * @param string $url
360 265 * @return object $array
361 266 */
362 267 public function http_request_args( $args, $url ) {
363 -
364 - $verify_ssl = $this->verify_ssl();
268 + // If it is an https request and we are performing a package download, disable ssl verification
365 269 if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
366 - $args['sslverify'] = $verify_ssl;
270 + $args['sslverify'] = false;
367 271 }
368 272 return $args;
369 -
370 273 }
371 274
372 275 /**
373 276 * Calls the API and, if successfull, returns the object delivered by the API.
@@ -381,34 +284,10 @@
381 284 * @return false|object
382 285 */
383 286 private function api_request( $_action, $_data ) {
384 287
385 - global $wp_version, $edd_plugin_url_available;
288 + global $wp_version;
386 289
387 - $verify_ssl = $this->verify_ssl();
388 -
389 - // Do a quick status check on this domain if we haven't already checked it.
390 - $store_hash = md5( $this->api_url );
391 - if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) {
392 - $test_url_parts = parse_url( $this->api_url );
393 -
394 - $scheme = ! empty( $test_url_parts['scheme'] ) ? $test_url_parts['scheme'] : 'http';
395 - $host = ! empty( $test_url_parts['host'] ) ? $test_url_parts['host'] : '';
396 - $port = ! empty( $test_url_parts['port'] ) ? ':' . $test_url_parts['port'] : '';
397 -
398 - if ( empty( $host ) ) {
399 - $edd_plugin_url_available[ $store_hash ] = false;
400 - } else {
401 - $test_url = $scheme . '://' . $host . $port;
402 - $response = wp_remote_get( $test_url, array( 'timeout' => $this->health_check_timeout, 'sslverify' => $verify_ssl ) );
403 - $edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true;
404 - }
405 - }
406 -
407 - if ( false === $edd_plugin_url_available[ $store_hash ] ) {
408 - return;
409 - }
410 -
411 290 $data = array_merge( $this->api_data, $_data );
412 291
413 292 if ( $data['slug'] != $this->slug ) {
414 293 return;
@@ -413,9 +292,9 @@
413 292 if ( $data['slug'] != $this->slug ) {
414 293 return;
415 294 }
416 295
417 - if( $this->api_url == trailingslashit ( home_url() ) ) {
296 + if ( $this->api_url == home_url() ) {
418 297 return false; // Don't allow a plugin to ping itself
419 298 }
420 299
421 300 $api_params = array(
@@ -422,16 +301,14 @@
422 301 'edd_action' => 'get_version',
423 302 'license' => ! empty( $data['license'] ) ? $data['license'] : '',
424 303 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
425 304 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
426 - 'version' => isset( $data['version'] ) ? $data['version'] : false,
427 305 'slug' => $data['slug'],
428 306 'author' => $data['author'],
429 - 'url' => home_url(),
430 - 'beta' => ! empty( $data['beta'] ),
307 + 'url' => home_url()
431 308 );
432 309
433 - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
310 + $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
434 311
435 312 if ( ! is_wp_error( $request ) ) {
436 313 $request = json_decode( wp_remote_retrieve_body( $request ) );
437 314 }
@@ -441,22 +318,8 @@
441 318 } else {
442 319 $request = false;
443 320 }
444 321
445 - if ( $request && isset( $request->banners ) ) {
446 - $request->banners = maybe_unserialize( $request->banners );
447 - }
448 -
449 - if ( $request && isset( $request->icons ) ) {
450 - $request->icons = maybe_unserialize( $request->icons );
451 - }
452 -
453 - if( ! empty( $request->sections ) ) {
454 - foreach( $request->sections as $key => $section ) {
455 - $request->$key = (array) $section;
456 - }
457 - }
458 -
459 322 return $request;
460 323 }
461 324
462 325 public function show_changelog() {
@@ -462,30 +325,29 @@
462 325 public function show_changelog() {
463 326
464 327 global $edd_plugin_data;
465 328
466 - if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
329 + if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) {
467 330 return;
468 331 }
469 332
470 - if( empty( $_REQUEST['plugin'] ) ) {
333 + if ( empty( $_REQUEST['plugin'] ) ) {
471 334 return;
472 335 }
473 336
474 - if( empty( $_REQUEST['slug'] ) ) {
337 + if ( empty( $_REQUEST['slug'] ) ) {
475 338 return;
476 339 }
477 340
478 - if( ! current_user_can( 'update_plugins' ) ) {
341 + if ( ! current_user_can( 'update_plugins' ) ) {
479 342 wp_die( __( 'You do not have permission to install plugin updates', 'polylang' ), __( 'Error', 'polylang' ), array( 'response' => 403 ) );
480 343 }
481 344
482 345 $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 );
346 + $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_version_info' );
347 + $version_info = get_transient( $cache_key );
486 348
487 - if( false === $version_info ) {
349 + if ( false === $version_info ) {
488 350
489 351 $api_params = array(
490 352 'edd_action' => 'get_version',
491 353 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
@@ -491,20 +353,17 @@
491 353 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false,
492 354 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false,
493 355 'slug' => $_REQUEST['slug'],
494 356 'author' => $data['author'],
495 - 'url' => home_url(),
496 - 'beta' => ! empty( $data['beta'] )
357 + 'url' => home_url()
497 358 );
498 359
499 - $verify_ssl = $this->verify_ssl();
500 - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) );
360 + $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
501 361
502 362 if ( ! is_wp_error( $request ) ) {
503 363 $version_info = json_decode( wp_remote_retrieve_body( $request ) );
504 364 }
505 365
506 -
507 366 if ( ! empty( $version_info ) && isset( $version_info->sections ) ) {
508 367 $version_info->sections = maybe_unserialize( $version_info->sections );
509 368 } else {
510 369 $version_info = false;
@@ -509,69 +368,16 @@
509 368 } else {
510 369 $version_info = false;
511 370 }
512 371
513 - if( ! empty( $version_info ) ) {
514 - foreach( $version_info->sections as $key => $section ) {
515 - $version_info->$key = (array) $section;
516 - }
517 - }
372 + set_transient( $cache_key, $version_info, 3600 );
518 373
519 - $this->set_version_info_cache( $version_info, $cache_key );
520 -
521 374 }
522 375
523 - if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
376 + if ( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) {
524 377 echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>';
525 378 }
526 379
527 380 exit;
528 - }
529 -
530 - public function get_cached_version_info( $cache_key = '' ) {
531 -
532 - if( empty( $cache_key ) ) {
533 - $cache_key = $this->cache_key;
534 - }
535 -
536 - $cache = get_option( $cache_key );
537 -
538 - if( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) {
539 - return false; // Cache is expired
540 - }
541 -
542 - // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point.
543 - $cache['value'] = json_decode( $cache['value'] );
544 - if ( ! empty( $cache['value']->icons ) ) {
545 - $cache['value']->icons = (array) $cache['value']->icons;
546 - }
547 -
548 - return $cache['value'];
549 -
550 - }
551 -
552 - public function set_version_info_cache( $value = '', $cache_key = '' ) {
553 -
554 - if( empty( $cache_key ) ) {
555 - $cache_key = $this->cache_key;
556 - }
557 -
558 - $data = array(
559 - 'timeout' => strtotime( '+3 hours', time() ),
560 - 'value' => json_encode( $value )
561 - );
562 -
563 - update_option( $cache_key, $data, 'no' );
564 -
565 - }
566 -
567 - /**
568 - * Returns if the SSL of the store should be verified.
569 - *
570 - * @since 1.6.13
571 - * @return bool
572 - */
573 - private function verify_ssl() {
574 - return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this );
575 381 }
576 382
577 383 }