PluginProbe
Tiered Pricing Table for WooCommerce / 2.1.2
Tiered Pricing Table for WooCommerce v2.1.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
← All changes | freemius/includes/class-fs-plugin-updater.php +91 -358 8.0.2 → 2.1.2 View file →
@@ -36,10 +36,8 @@
36 36 private $_translation_updates;
37 37
38 38 private static $_upgrade_basename = null;
39 39
40 - const UPDATES_CHECK_CACHE_EXPIRATION = ( WP_FS__TIME_24_HOURS_IN_SEC / 24 );
41 -
42 40 #--------------------------------------------------------------------------------
43 41 #region Singleton
44 42 #--------------------------------------------------------------------------------
45 43
@@ -103,13 +101,9 @@
103 101 &$this,
104 102 'edit_and_echo_plugin_update_row'
105 103 ), 11, 2 );
106 104
107 - if ( ! $this->_fs->has_any_active_valid_license() ) {
108 - add_action( 'admin_head', array( &$this, 'catch_plugin_information_dialog_contents' ) );
109 - } else {
110 - add_action( 'admin_footer', array( &$this, '_add_fs_allow_updater_and_dialog_request_param' ) );
111 - }
105 + add_action( 'admin_head', array( &$this, 'catch_plugin_information_dialog_contents' ) );
112 106
113 107 if ( ! WP_FS__IS_PRODUCTION_MODE ) {
114 108 add_filter( 'http_request_host_is_external', array(
115 109 $this,
@@ -132,48 +126,15 @@
132 126 }
133 127
134 128 /**
135 129 * @author Leo Fajardo (@leorw)
136 - * @since 2.7.4
137 - */
138 - function _add_fs_allow_updater_and_dialog_request_param() {
139 - if ( ! $this->is_plugin_information_dialog_for_plugin() ) {
140 - return;
141 - }
142 - ?>
143 - <script type="text/javascript">
144 - if ( typeof jQuery !== 'undefined' ) {
145 - jQuery( document ).on( 'wp-plugin-updating', function( event, args ) {
146 - if ( typeof args === 'object' && args.slug && typeof args.slug === 'string' ) {
147 - if ( <?php echo json_encode( $this->_fs->get_slug() ) ?> === args.slug ) {
148 - args.fs_allow_updater_and_dialog = true;
149 - }
150 - }
151 - } );
152 - }
153 - </script>
154 - <?php
155 - }
156 -
157 - /**
158 - * @author Leo Fajardo (@leorw)
159 - * @since 2.7.4
160 - *
161 - * @return bool
162 - */
163 - private function is_plugin_information_dialog_for_plugin() {
164 - return (
165 - 'plugin-information' === fs_request_get( 'tab', false ) &&
166 - $this->_fs->get_slug() === fs_request_get_raw( 'plugin', false )
167 - );
168 - }
169 -
170 - /**
171 - * @author Leo Fajardo (@leorw)
172 130 * @since 2.1.4
173 131 */
174 132 function catch_plugin_information_dialog_contents() {
175 - if ( ! $this->is_plugin_information_dialog_for_plugin() ) {
133 + if (
134 + 'plugin-information' !== fs_request_get( 'tab', false ) ||
135 + $this->_fs->get_slug() !== fs_request_get( 'plugin', false )
136 + ) {
176 137 return;
177 138 }
178 139
179 140 add_action( 'admin_footer', array( &$this, 'edit_and_echo_plugin_information_dialog_contents' ), 0, 1 );
@@ -189,9 +150,9 @@
189 150 */
190 151 function edit_and_echo_plugin_information_dialog_contents( $hook_suffix ) {
191 152 if (
192 153 'plugin-information' !== fs_request_get( 'tab', false ) ||
193 - $this->_fs->get_slug() !== fs_request_get_raw( 'plugin', false )
154 + $this->_fs->get_slug() !== fs_request_get( 'plugin', false )
194 155 ) {
195 156 return;
196 157 }
197 158
@@ -202,78 +163,35 @@
202 163 null;
203 164
204 165 $contents = ob_get_clean();
205 166
206 - $install_or_update_button_id_attribute_pos = strpos( $contents, 'id="plugin_install_from_iframe"' );
207 -
208 - if ( false === $install_or_update_button_id_attribute_pos ) {
209 - $install_or_update_button_id_attribute_pos = strpos( $contents, 'id="plugin_update_from_iframe"' );
210 - }
211 -
212 - if ( false !== $install_or_update_button_id_attribute_pos ) {
213 - $install_or_update_button_start_pos = strrpos(
214 - substr( $contents, 0, $install_or_update_button_id_attribute_pos ),
215 - '<a'
216 - );
217 -
218 - $install_or_update_button_end_pos = ( strpos( $contents, '</a>', $install_or_update_button_id_attribute_pos ) + strlen( '</a>' ) );
219 -
220 - /**
221 - * The part of the contents without the update button.
222 - *
223 - * @author Leo Fajardo (@leorw)
224 - * @since 2.2.5
225 - */
226 - $modified_contents = substr( $contents, 0, $install_or_update_button_start_pos );
227 -
228 - $install_or_update_button = substr( $contents, $install_or_update_button_start_pos, ( $install_or_update_button_end_pos - $install_or_update_button_start_pos ) );
229 -
230 - /**
231 - * Replace the plugin information dialog's "Install Update Now" button's text and URL. If there's a license,
232 - * the text will be "Renew license" and will link to the checkout page with the license's billing cycle
233 - * and quota. If there's no license, the text will be "Buy license" and will link to the pricing page.
234 - */
235 - $install_or_update_button = preg_replace(
236 - '/(\<a.+)(id="plugin_(install|update)_from_iframe")(.+href=")([^\s]+)(".*\>)(.+)(\<\/a>)/is',
237 - is_object( $license ) ?
238 - sprintf(
239 - '$1$4%s$6%s$8',
240 - $this->_fs->checkout_url(
241 - is_object( $subscription ) ?
242 - ( 1 == $subscription->billing_cycle ? WP_FS__PERIOD_MONTHLY : WP_FS__PERIOD_ANNUALLY ) :
243 - WP_FS__PERIOD_LIFETIME,
244 - false,
245 - array( 'licenses' => $license->quota )
246 - ),
247 - fs_text_inline( 'Renew license', 'renew-license', $this->_fs->get_slug() )
248 - ) :
249 - sprintf(
250 - '$1$4%s$6%s$8',
251 - $this->_fs->pricing_url(),
252 - fs_text_inline( 'Buy license', 'buy-license', $this->_fs->get_slug() )
167 + /**
168 + * Replace the plugin information dialog's "Install Update Now" button's text and URL. If there's a license,
169 + * the text will be "Renew license" and will link to the checkout page with the license's billing cycle
170 + * and quota. If there's no license, the text will be "Buy license" and will link to the pricing page.
171 + */
172 + $contents = preg_replace(
173 + '/(.+\<a.+)(id="plugin_update_from_iframe")(.+href=")([^\s]+)(".+\>)(.+)(\<\/a.+)/is',
174 + is_object( $license ) ?
175 + sprintf(
176 + '$1$3%s$5%s$7',
177 + $this->_fs->checkout_url(
178 + is_object( $subscription ) ?
179 + ( 1 == $subscription->billing_cycle ? WP_FS__PERIOD_MONTHLY : WP_FS__PERIOD_ANNUALLY ) :
180 + WP_FS__PERIOD_LIFETIME,
181 + false,
182 + array( 'licenses' => $license->quota )
253 183 ),
254 - $install_or_update_button
255 - );
184 + fs_text_inline( 'Renew license', 'renew-license', $this->_fs->get_slug() )
185 + ) :
186 + sprintf(
187 + '$1$3%s$5%s$7',
188 + $this->_fs->pricing_url(),
189 + fs_text_inline( 'Buy license', 'buy-license', $this->_fs->get_slug() )
190 + ),
191 + $contents
192 + );
256 193
257 - /**
258 - * Append the modified button.
259 - *
260 - * @author Leo Fajardo (@leorw)
261 - * @since 2.2.5
262 - */
263 - $modified_contents .= $install_or_update_button;
264 -
265 - /**
266 - * Append the remaining part of the contents after the update button.
267 - *
268 - * @author Leo Fajardo (@leorw)
269 - * @since 2.2.5
270 - */
271 - $modified_contents .= substr( $contents, $install_or_update_button_end_pos );
272 -
273 - $contents = $modified_contents;
274 - }
275 -
276 194 echo $contents;
277 195 }
278 196
279 197 /**
@@ -280,18 +198,8 @@
280 198 * @author Vova Feldman (@svovaf)
281 199 * @since 2.0.0
282 200 */
283 201 private function add_transient_filters() {
284 - if (
285 - $this->_fs->is_premium() &&
286 - $this->_fs->is_registered() &&
287 - ! FS_Permission_Manager::instance( $this->_fs )->is_essentials_tracking_allowed()
288 - ) {
289 - $this->_logger->log( 'Opted out sites cannot receive automatic software updates.' );
290 -
291 - return;
292 - }
293 -
294 202 add_filter( 'pre_set_site_transient_update_plugins', array(
295 203 &$this,
296 204 'pre_set_site_transient_update_plugins_filter'
297 205 ) );
@@ -348,42 +256,9 @@
348 256 }
349 257
350 258 $r = $current->response[ $file ];
351 259
352 - $has_beta_update = $this->_fs->has_beta_update();
353 -
354 - if ( $this->_fs->has_any_active_valid_license() ) {
355 - if ( $has_beta_update ) {
356 - /**
357 - * Turn the "new version" text into "new Beta version".
358 - *
359 - * Sample input:
360 - * There is a new version of Awesome Plugin available. <a href="...>View version x.y.z details</a> or <a href="...>update now</a>.
361 - * Output:
362 - * There is a new Beta version of Awesome Plugin available. <a href="...>View version x.y.z details</a> or <a href="...>update now</a>.
363 - *
364 - * @author Leo Fajardo (@leorw)
365 - * @since 2.3.0
366 - */
367 - $plugin_update_row = preg_replace(
368 - '/(\<div.+>)(.+)(\<a.+href="([^\s]+)"([^\<]+)\>.+\<a.+)(\<\/div\>)/is',
369 - (
370 - '$1' .
371 - sprintf(
372 - fs_text_inline( 'There is a %s of %s available.', 'new-version-available', $this->_fs->get_slug() ),
373 - $has_beta_update ?
374 - fs_text_inline( 'new Beta version', 'new-beta-version', $this->_fs->get_slug() ) :
375 - fs_text_inline( 'new version', 'new-version', $this->_fs->get_slug() ),
376 - $this->_fs->get_plugin_title()
377 - ) .
378 - ' ' .
379 - '$3' .
380 - '$6'
381 - ),
382 - $plugin_update_row
383 - );
384 - }
385 - } else {
260 + if ( ! $this->_fs->has_any_active_valid_license() ) {
386 261 /**
387 262 * Turn the "new version" text into a link that opens the plugin information dialog when clicked and
388 263 * make the "View version x details" text link to the checkout page instead of opening the plugin
389 264 * information dialog when clicked.
@@ -391,10 +266,8 @@
391 266 * Sample input:
392 267 * There is a new version of Awesome Plugin available. <a href="...>View version x.y.z details</a> or <a href="...>update now</a>.
393 268 * Output:
394 269 * There is a <a href="...>new version</a> of Awesome Plugin available. <a href="...>Buy a license now</a> to access version x.y.z security & feature updates, and support.
395 - * OR
396 - * There is a <a href="...>new Beta version</a> of Awesome Plugin available. <a href="...>Buy a license now</a> to access version x.y.z security & feature updates, and support.
397 270 *
398 271 * @author Leo Fajardo (@leorw)
399 272 */
400 273 $plugin_update_row = preg_replace(
@@ -405,11 +278,9 @@
405 278 fs_text_inline( 'There is a %s of %s available.', 'new-version-available', $this->_fs->get_slug() ),
406 279 sprintf(
407 280 '<a href="$4"%s>%s</a>',
408 281 '$5',
409 - $has_beta_update ?
410 - fs_text_inline( 'new Beta version', 'new-beta-version', $this->_fs->get_slug() ) :
411 - fs_text_inline( 'new version', 'new-version', $this->_fs->get_slug() )
282 + fs_text_inline( 'new version', 'new-version', $this->_fs->get_slug() )
412 283 ),
413 284 $this->_fs->get_plugin_title()
414 285 ) .
415 286 ' ' .
@@ -427,9 +298,9 @@
427 298 ) {
428 299 $slug = $this->_fs->get_slug();
429 300
430 301 $upgrade_notice_html = sprintf(
431 - '<p class="notice fs-upgrade-notice fs-slug-%1$s fs-type-%2$s" data-slug="%1$s" data-type="%2$s"><strong>%3$s</strong> %4$s</p>',
302 + '<p class="notice fs-upgrade-notice fs-slug-%1s fs-type-%2s" data-slug="%1s" data-type="%2s"><strong>%3s</strong> %4s</p>',
432 303 $slug,
433 304 $this->_fs->get_module_type(),
434 305 fs_text_inline( 'Important Upgrade Notice:', 'upgrade_notice', $slug ),
435 306 esc_html( $r->upgrade_notice )
@@ -457,9 +328,9 @@
457 328 }
458 329
459 330 $themes_update = get_site_transient( 'update_themes' );
460 331 if ( ! isset( $themes_update->response[ $theme_basename ] ) ||
461 - empty( $themes_update->response[ $theme_basename ]['package'] )
332 + empty( $themes_update->response[ $theme_basename ]['package'] )
462 333 ) {
463 334 return $prepared_themes;
464 335 }
465 336
@@ -539,44 +410,20 @@
539 410 ) {
540 411 return $transient_data;
541 412 }
542 413
543 - // Alias.
544 - $basename = $this->_fs->premium_plugin_basename();
545 -
546 - global $wp_current_filter;
547 -
548 - /**
549 - * During bulk updates, avoid re-injecting update data for the plugin itself once it has already been updated.
550 - *
551 - * If the custom package is re-added to the transient after the plugin update, WordPress may detect the package again and incorrectly report "The plugin is at the latest version" for a pending update, since the custom package version matches the currently installed version.
552 - *
553 - * Behavior differs depending on how the bulk update is triggered. Please refer to the inline comments for each flow below for details.
554 - */
555 - if (
556 - ! empty( $wp_current_filter ) && (
557 - /**
558 - * update-core.php and other upgrader pages:
559 - * The `upgrader_process_complete` action fires only once after all updates have finished. In this case, it is the current action (`$wp_current_filter[0]`), while `self::$_upgrade_basename` may contain any plugin basename.
560 - */
561 - 'upgrader_process_complete' === $wp_current_filter[0] ||
562 - /**
563 - * AJAX bulk updates (e.g., from the Plugins page):
564 - * The `upgrader_process_complete` action fires multiple times — once for each plugin after it finishes updating. In this flow, it is not the current action (`$wp_current_filter[0]`) because it is triggered from another action. Instead, we compare `self::$_upgrade_basename` with the basename of the plugin currently being updated, since the `upgrader_process_complete` action runs separately for each plugin.
565 - */
566 - ( in_array( 'upgrader_process_complete', $wp_current_filter ) && self::$_upgrade_basename === $basename )
567 - )
568 - ) {
569 - return $transient_data;
570 - }
571 -
572 414 if ( ! isset( $this->_update_details ) ) {
573 415 // Get plugin's newest update.
574 - $new_version = $this->_fs->get_update( false, fs_request_get_bool( 'force-check' ) );
416 + $new_version = $this->_fs->get_update(
417 + false,
418 + fs_request_get_bool( 'force-check' ),
419 + WP_FS__TIME_24_HOURS_IN_SEC / 24,
420 + $this->_fs->get_plugin_version()
421 + );
575 422
576 423 $this->_update_details = false;
577 424
578 - if ( is_object( $new_version ) && $this->is_new_version_premium( $new_version ) ) {
425 + if ( is_object( $new_version ) ) {
579 426 $this->_logger->log( 'Found newer plugin version ' . $new_version->version );
580 427
581 428 /**
582 429 * Cache plugin details locally since set_site_transient( 'update_plugins' )
@@ -589,75 +436,25 @@
589 436 }
590 437 }
591 438
592 439 if ( is_object( $this->_update_details ) ) {
593 - if ( isset( $transient_data->no_update ) ) {
594 - unset( $transient_data->no_update[ $basename ] );
595 - }
596 -
597 - if ( ! isset( $transient_data->response ) ) {
598 - $transient_data->response = array();
599 - }
600 -
601 440 // Add plugin to transient data.
602 - $transient_data->response[ $basename ] = $this->_fs->is_plugin() ?
441 + $transient_data->response[ $this->_fs->get_plugin_basename() ] = $this->_fs->is_plugin() ?
603 442 $this->_update_details :
604 443 (array) $this->_update_details;
605 - } else {
606 - if ( isset( $transient_data->response ) ) {
607 - /**
608 - * Ensure that there's no update data for the plugin to prevent upgrading the premium version to the latest free version.
609 - *
610 - * @author Leo Fajardo (@leorw)
611 - * @since 2.3.0
612 - */
613 - unset( $transient_data->response[ $basename ] );
614 - }
615 -
616 - if ( ! isset( $transient_data->no_update ) ) {
617 - $transient_data->no_update = array();
618 - }
619 -
620 - /**
621 - * Add product to no_update transient data to properly integrate with WP 5.5 auto-updates UI.
622 - *
623 - * @since 2.4.1
624 - * @link https://make.wordpress.org/core/2020/07/30/recommended-usage-of-the-updates-api-to-support-the-auto-updates-ui-for-plugins-and-themes-in-wordpress-5-5/
625 - */
626 - $transient_data->no_update[ $basename ] = $this->_fs->is_plugin() ?
627 - (object) array(
628 - 'id' => $basename,
629 - 'slug' => $this->_fs->get_slug(),
630 - 'plugin' => $basename,
631 - 'new_version' => $this->_fs->get_plugin_version(),
632 - 'url' => '',
633 - 'package' => '',
634 - 'icons' => array(),
635 - 'banners' => array(),
636 - 'banners_rtl' => array(),
637 - 'tested' => '',
638 - 'requires_php' => '',
639 - 'compatibility' => new stdClass(),
640 - ) :
641 - array(
642 - 'theme' => $basename,
643 - 'new_version' => $this->_fs->get_plugin_version(),
644 - 'url' => '',
645 - 'package' => '',
646 - 'requires' => '',
647 - 'requires_php' => '',
648 - );
649 444 }
650 445
651 446 $slug = $this->_fs->get_slug();
652 447
653 - if ( $this->can_fetch_data_from_wp_org() ) {
448 + if ( $this->_fs->is_org_repo_compliant() && $this->_fs->is_freemium() ) {
654 449 if ( ! isset( $this->_translation_updates ) ) {
655 450 $this->_translation_updates = array();
656 451
657 - $translation_updates = $this->fetch_wp_org_module_translation_updates( $module_type, $slug );
658 - if ( ! empty( $translation_updates ) ) {
659 - $this->_translation_updates = $translation_updates;
452 + if ( current_user_can( 'update_languages' ) ) {
453 + $translation_updates = $this->fetch_wp_org_module_translation_updates( $module_type, $slug );
454 + if ( ! empty( $translation_updates ) ) {
455 + $this->_translation_updates = $translation_updates;
456 + }
660 457 }
661 458 }
662 459
663 460 if ( ! empty( $this->_translation_updates ) ) {
@@ -675,9 +472,9 @@
675 472
676 473 foreach ( $this->_translation_updates as $translation_update ) {
677 474 $lang = $translation_update['language'];
678 475 if ( ! isset( $current_plugin_translation_updates_map[ $lang ] ) ||
679 - version_compare( $translation_update['version'], $current_plugin_translation_updates_map[ $lang ]['version'], '>' )
476 + version_compare( $translation_update['version'], $current_plugin_translation_updates_map[ $lang ]['version'], '>' )
680 477 ) {
681 478 $current_plugin_translation_updates_map[ $lang ] = $translation_update;
682 479 }
683 480 }
@@ -689,9 +486,9 @@
689 486 return $transient_data;
690 487 }
691 488
692 489 /**
693 - * Get module's required data for the updates' mechanism.
490 + * Get module's required data for the updates mechanism.
694 491 *
695 492 * @author Vova Feldman (@svovaf)
696 493 * @since 2.0.0
697 494 *
@@ -699,16 +496,15 @@
699 496 *
700 497 * @return object
701 498 */
702 499 function get_update_details( FS_Plugin_Tag $new_version ) {
703 - $update = new stdClass();
704 - $update->slug = $this->_fs->get_slug();
705 - $update->new_version = $new_version->version;
706 - $update->url = WP_FS__ADDRESS;
707 - $update->package = $new_version->url;
708 - $update->tested = self::get_tested_wp_version( $new_version->tested_up_to_version );
709 - $update->requires = $new_version->requires_platform_version;
710 - $update->requires_php = $new_version->requires_programming_language_version;
500 + $update = new stdClass();
501 + $update->slug = $this->_fs->get_slug();
502 + $update->new_version = $new_version->version;
503 + $update->url = WP_FS__ADDRESS;
504 + $update->package = $new_version->url;
505 + $update->tested = $new_version->tested_up_to_version;
506 + $update->requires = $new_version->requires_platform_version;
711 507
712 508 $icon = $this->_fs->get_local_icon_url();
713 509
714 510 if ( ! empty( $icon ) ) {
@@ -718,10 +514,18 @@
718 514 'default' => $icon,
719 515 );
720 516 }
721 517
722 - if ( $this->_fs->is_premium() && ! empty( $new_version->upgrade_notice ) ) {
723 - $update->upgrade_notice = $new_version->upgrade_notice;
518 + if ( $this->_fs->is_premium() ) {
519 + $latest_tag = $this->_fs->_fetch_latest_version( $this->_fs->get_id(), false );
520 +
521 + if (
522 + isset( $latest_tag->readme ) &&
523 + isset( $latest_tag->readme->upgrade_notice ) &&
524 + ! empty( $latest_tag->readme->upgrade_notice )
525 + ) {
526 + $update->upgrade_notice = $latest_tag->readme->upgrade_notice;
527 + }
724 528 }
725 529
726 530 $update->{$this->_fs->get_module_type()} = $this->_fs->get_plugin_basename();
727 531
@@ -728,22 +532,8 @@
728 532 return $update;
729 533 }
730 534
731 535 /**
732 - * @author Leo Fajardo (@leorw)
733 - * @since 2.3.0
734 - *
735 - * @param FS_Plugin_Tag $new_version
736 - *
737 - * @return bool
738 - */
739 - private function is_new_version_premium( FS_Plugin_Tag $new_version ) {
740 - $params = fs_parse_url_params( $new_version->url );
741 -
742 - return ( isset( $params['is_premium'] ) && 'true' == $params['is_premium'] );
743 - }
744 -
745 - /**
746 536 * Update the updates transient with the module's update information.
747 537 *
748 538 * This method is required for multisite environment.
749 539 * If a module is site activated (not network) and not on the main site,
@@ -759,12 +549,8 @@
759 549 */
760 550 function set_update_data( FS_Plugin_Tag $new_version ) {
761 551 $this->_logger->entrance();
762 552
763 - if ( ! $this->is_new_version_premium( $new_version ) ) {
764 - return;
765 - }
766 -
767 553 $transient_key = "update_{$this->_fs->get_module_type()}s";
768 554
769 555 $transient_data = get_site_transient( $transient_key );
770 556
@@ -835,11 +621,11 @@
835 621 // Alias
836 622 $basename = $this->_fs->get_plugin_basename();
837 623
838 624 if ( ! is_object( $transient_data ) ||
839 - ! isset( $transient_data->response ) ||
625 + ! isset( $transient_data->response ) ||
840 626 ! is_array( $transient_data->response ) ||
841 - empty( $transient_data->response[ $basename ] )
627 + empty( $transient_data->response[ $basename ] )
842 628 ) {
843 629 return;
844 630 }
845 631
@@ -864,36 +650,30 @@
864 650 *
865 651 * @return bool|mixed
866 652 */
867 653 static function _fetch_plugin_info_from_repository( $action, $args ) {
868 - $url = $http_url = 'http://api.wordpress.org/plugins/info/1.2/';
869 - $url = add_query_arg(
870 - array(
654 + $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
655 + if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
656 + $url = set_url_scheme( $url, 'https' );
657 + }
658 +
659 + $args = array(
660 + 'timeout' => 15,
661 + 'body' => array(
871 662 'action' => $action,
872 - 'request' => $args,
873 - ),
874 - $url
663 + 'request' => serialize( $args )
664 + )
875 665 );
876 666
877 - if ( wp_http_supports( array( 'ssl' ) ) ) {
878 - $url = set_url_scheme( $url, 'https' );
879 - }
667 + $request = wp_remote_post( $url, $args );
880 668
881 - // The new endpoint version serves only GET requests.
882 - $request = wp_remote_get( $url, array( 'timeout' => 15 ) );
883 -
884 669 if ( is_wp_error( $request ) ) {
885 670 return false;
886 671 }
887 672
888 - $res = json_decode( wp_remote_retrieve_body( $request ), true );
673 + $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
889 674
890 - if ( is_array( $res ) ) {
891 - // Object casting is required in order to match the info/1.0 format. We are not decoding directly into an object as we need some fields to remain an array (e.g., $res->sections).
892 - $res = (object) $res;
893 - }
894 -
895 - if ( ! is_object( $res ) || isset( $res->error ) ) {
675 + if ( ! is_object( $res ) && ! is_array( $res ) ) {
896 676 return false;
897 677 }
898 678
899 679 return $res;
@@ -899,18 +679,8 @@
899 679 return $res;
900 680 }
901 681
902 682 /**
903 - * Returns true if the product can fetch data from WordPress.org.
904 - *
905 - * @author Leo Fajardo (@leorw)
906 - * @since 2.7.4
907 - */
908 - private function can_fetch_data_from_wp_org() {
909 - return ( $this->_fs->is_org_repo_compliant() && $this->_fs->is_freemium() );
910 - }
911 -
912 - /**
913 683 * Fetches module translation updates from wordpress.org.
914 684 *
915 685 * @author Leo Fajardo (@leorw)
916 686 * @since 2.1.2
@@ -1063,11 +833,10 @@
1063 833 ) {
1064 834 return $data;
1065 835 }
1066 836
1067 - $addon = false;
1068 - $is_addon = false;
1069 - $addon_version = false;
837 + $addon = false;
838 + $is_addon = false;
1070 839
1071 840 if ( $this->_fs->get_slug() !== $args->slug ) {
1072 841 $addon = $this->_fs->get_addon_by_slug( $args->slug );
1073 842
@@ -1074,27 +843,13 @@
1074 843 if ( ! is_object( $addon ) ) {
1075 844 return $data;
1076 845 }
1077 846
1078 - if ( $this->_fs->is_addon_activated( $addon->id ) ) {
1079 - $addon_version = $this->_fs->get_addon_instance( $addon->id )->get_plugin_version();
1080 - } else if ( $this->_fs->is_addon_installed( $addon->id ) ) {
1081 - $addon_plugin_data = get_plugin_data(
1082 - ( WP_PLUGIN_DIR . '/' . $this->_fs->get_addon_basename( $addon->id ) ),
1083 - false,
1084 - false
1085 - );
1086 -
1087 - if ( ! empty( $addon_plugin_data ) ) {
1088 - $addon_version = $addon_plugin_data['Version'];
1089 - }
1090 - }
1091 -
1092 847 $is_addon = true;
1093 848 }
1094 849
1095 850 $plugin_in_repo = false;
1096 - if ( ! $is_addon && $this->can_fetch_data_from_wp_org() ) {
851 + if ( ! $is_addon ) {
1097 852 // Try to fetch info from .org repository.
1098 853 $data = self::_fetch_plugin_info_from_repository( $action, $args );
1099 854
1100 855 $plugin_in_repo = ( false !== $data );
@@ -1118,11 +873,9 @@
1118 873 $data = $info;
1119 874 }*/
1120 875 }
1121 876
1122 - $plugin_version = $is_addon ?
1123 - $addon_version :
1124 - $this->_fs->get_plugin_version();
877 + $plugin_version = $this->_fs->get_plugin_version();
1125 878
1126 879 // Get plugin's newest update.
1127 880 $new_version = $this->get_latest_download_details( $is_addon ? $addon->id : false, $plugin_version );
1128 881
@@ -1138,9 +891,8 @@
1138 891
1139 892 if ( ! $plugin_in_repo ) {
1140 893 $data->last_updated = ! is_null( $new_version->updated ) ? $new_version->updated : $new_version->created;
1141 894 $data->requires = $new_version->requires_platform_version;
1142 - $data->requires_php = $new_version->requires_programming_language_version;
1143 895 $data->tested = $new_version->tested_up_to_version;
1144 896 }
1145 897
1146 898 $data->version = $new_version->version;
@@ -1192,31 +944,12 @@
1192 944 $data = $new_version_readme_data;
1193 945 }
1194 946 }
1195 947
1196 - if ( ! empty( $data->tested ) ) {
1197 - $data->tested = self::get_tested_wp_version( $data->tested );
1198 - }
1199 -
1200 948 return $data;
1201 949 }
1202 950
1203 951 /**
1204 - * @since 2.5.3 If the current WordPress version is a patch of the tested version (e.g., 6.1.2 is a patch of 6.1), then override the tested version with the patch so developers won't need to release a new version just to bump the latest supported WP version.
1205 - *
1206 - * @param string|null $tested_up_to
1207 - *
1208 - * @return string|null
1209 - */
1210 - private static function get_tested_wp_version( $tested_up_to ) {
1211 - $current_wp_version = get_bloginfo( 'version' );
1212 -
1213 - return ( ! empty($tested_up_to) && fs_starts_with( $current_wp_version, $tested_up_to . '.' ) ) ?
1214 - $current_wp_version :
1215 - $tested_up_to;
1216 - }
1217 -
1218 - /**
1219 952 * @author Vova Feldman (@svovaf)
1220 953 * @since 1.2.1.7
1221 954 *
1222 955 * @param number|bool $addon_id
@@ -1225,9 +958,9 @@
1225 958 *
1226 959 * @return object
1227 960 */
1228 961 private function get_latest_download_details( $addon_id = false, $newer_than = false, $fetch_readme = true ) {
1229 - return $this->_fs->_fetch_latest_version( $addon_id, true, FS_Plugin_Updater::UPDATES_CHECK_CACHE_EXPIRATION, $newer_than, $fetch_readme );
962 + return $this->_fs->_fetch_latest_version( $addon_id, true, WP_FS__TIME_24_HOURS_IN_SEC, $newer_than, $fetch_readme );
1230 963 }
1231 964
1232 965 /**
1233 966 * Checks if a given basename has a matching folder name
@@ -1268,10 +1001,10 @@
1268 1001 }
1269 1002
1270 1003 $active_plugins_basenames = get_option( 'active_plugins' );
1271 1004
1272 - foreach ( $active_plugins_basenames as $key => $active_plugin_basename ) {
1273 - if ( $basename === $active_plugin_basename ) {
1005 + for ( $i = 0, $len = count( $active_plugins_basenames ); $i < $len; $i ++ ) {
1006 + if ( $basename === $active_plugins_basenames[ $i ] ) {
1274 1007 // Get filename including extension.
1275 1008 $filename = basename( $basename );
1276 1009
1277 1010 $new_basename = plugin_basename(
@@ -1281,9 +1014,9 @@
1281 1014
1282 1015 // Verify that the expected correct path exists.
1283 1016 if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $new_basename ) ) ) {
1284 1017 // Override active plugin name.
1285 - $active_plugins_basenames[ $key ] = $new_basename;
1018 + $active_plugins_basenames[ $i ] = $new_basename;
1286 1019 update_option( 'active_plugins', $active_plugins_basenames );
1287 1020 }
1288 1021
1289 1022 break;