PluginProbe
Tiered Pricing Table for WooCommerce / 2.2.3
Tiered Pricing Table for WooCommerce v2.2.3
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 +164 -36 2.2.1 → 2.2.3 View file →
@@ -163,35 +163,74 @@
163 163 null;
164 164
165 165 $contents = ob_get_clean();
166 166
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 )
167 + $update_button_id_attribute_pos = strpos( $contents, 'id="plugin_update_from_iframe"' );
168 +
169 + if ( false !== $update_button_id_attribute_pos ) {
170 + $update_button_start_pos = strrpos(
171 + substr( $contents, 0, $update_button_id_attribute_pos ),
172 + '<a'
173 + );
174 +
175 + $update_button_end_pos = ( strpos( $contents, '</a>', $update_button_id_attribute_pos ) + strlen( '</a>' ) );
176 +
177 + /**
178 + * The part of the contents without the update button.
179 + *
180 + * @author Leo Fajardo (@leorw)
181 + * @since 2.2.5
182 + */
183 + $modified_contents = substr( $contents, 0, $update_button_start_pos );
184 +
185 + $update_button = substr( $contents, $update_button_start_pos, ( $update_button_end_pos - $update_button_start_pos ) );
186 +
187 + /**
188 + * Replace the plugin information dialog's "Install Update Now" button's text and URL. If there's a license,
189 + * the text will be "Renew license" and will link to the checkout page with the license's billing cycle
190 + * and quota. If there's no license, the text will be "Buy license" and will link to the pricing page.
191 + */
192 + $update_button = preg_replace(
193 + '/(\<a.+)(id="plugin_update_from_iframe")(.+href=")([^\s]+)(".*\>)(.+)(\<\/a>)/is',
194 + is_object( $license ) ?
195 + sprintf(
196 + '$1$3%s$5%s$7',
197 + $this->_fs->checkout_url(
198 + is_object( $subscription ) ?
199 + ( 1 == $subscription->billing_cycle ? WP_FS__PERIOD_MONTHLY : WP_FS__PERIOD_ANNUALLY ) :
200 + WP_FS__PERIOD_LIFETIME,
201 + false,
202 + array( 'licenses' => $license->quota )
203 + ),
204 + fs_text_inline( 'Renew license', 'renew-license', $this->_fs->get_slug() )
205 + ) :
206 + sprintf(
207 + '$1$3%s$5%s$7',
208 + $this->_fs->pricing_url(),
209 + fs_text_inline( 'Buy license', 'buy-license', $this->_fs->get_slug() )
183 210 ),
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 - );
211 + $update_button
212 + );
193 213
214 + /**
215 + * Append the modified button.
216 + *
217 + * @author Leo Fajardo (@leorw)
218 + * @since 2.2.5
219 + */
220 + $modified_contents .= $update_button;
221 +
222 + /**
223 + * Append the remaining part of the contents after the update button.
224 + *
225 + * @author Leo Fajardo (@leorw)
226 + * @since 2.2.5
227 + */
228 + $modified_contents .= substr( $contents, $update_button_end_pos );
229 +
230 + $contents = $modified_contents;
231 + }
232 +
194 233 echo $contents;
195 234 }
196 235
197 236 /**
@@ -256,9 +295,42 @@
256 295 }
257 296
258 297 $r = $current->response[ $file ];
259 298
260 - if ( ! $this->_fs->has_any_active_valid_license() ) {
299 + $has_beta_update = $this->_fs->has_beta_update();
300 +
301 + if ( $this->_fs->has_any_active_valid_license() ) {
302 + if ( $has_beta_update ) {
303 + /**
304 + * Turn the "new version" text into "new Beta version".
305 + *
306 + * Sample input:
307 + * There is a new version of Awesome Plugin available. <a href="...>View version x.y.z details</a> or <a href="...>update now</a>.
308 + * Output:
309 + * 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>.
310 + *
311 + * @author Leo Fajardo (@leorw)
312 + * @since 2.3.0
313 + */
314 + $plugin_update_row = preg_replace(
315 + '/(\<div.+>)(.+)(\<a.+href="([^\s]+)"([^\<]+)\>.+\<a.+)(\<\/div\>)/is',
316 + (
317 + '$1' .
318 + sprintf(
319 + fs_text_inline( 'There is a %s of %s available.', 'new-version-available', $this->_fs->get_slug() ),
320 + $has_beta_update ?
321 + fs_text_inline( 'new Beta version', 'new-beta-version', $this->_fs->get_slug() ) :
322 + fs_text_inline( 'new version', 'new-version', $this->_fs->get_slug() ),
323 + $this->_fs->get_plugin_title()
324 + ) .
325 + ' ' .
326 + '$3' .
327 + '$6'
328 + ),
329 + $plugin_update_row
330 + );
331 + }
332 + } else {
261 333 /**
262 334 * Turn the "new version" text into a link that opens the plugin information dialog when clicked and
263 335 * make the "View version x details" text link to the checkout page instead of opening the plugin
264 336 * information dialog when clicked.
@@ -266,8 +338,10 @@
266 338 * Sample input:
267 339 * There is a new version of Awesome Plugin available. <a href="...>View version x.y.z details</a> or <a href="...>update now</a>.
268 340 * Output:
269 341 * 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.
342 + * OR
343 + * 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.
270 344 *
271 345 * @author Leo Fajardo (@leorw)
272 346 */
273 347 $plugin_update_row = preg_replace(
@@ -278,9 +352,11 @@
278 352 fs_text_inline( 'There is a %s of %s available.', 'new-version-available', $this->_fs->get_slug() ),
279 353 sprintf(
280 354 '<a href="$4"%s>%s</a>',
281 355 '$5',
282 - fs_text_inline( 'new version', 'new-version', $this->_fs->get_slug() )
356 + $has_beta_update ?
357 + fs_text_inline( 'new Beta version', 'new-beta-version', $this->_fs->get_slug() ) :
358 + fs_text_inline( 'new version', 'new-version', $this->_fs->get_slug() )
283 359 ),
284 360 $this->_fs->get_plugin_title()
285 361 ) .
286 362 ' ' .
@@ -298,9 +374,9 @@
298 374 ) {
299 375 $slug = $this->_fs->get_slug();
300 376
301 377 $upgrade_notice_html = sprintf(
302 - '<p class="notice fs-upgrade-notice fs-slug-%1s fs-type-%2s" data-slug="%1s" data-type="%2s"><strong>%3s</strong> %4s</p>',
378 + '<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>',
303 379 $slug,
304 380 $this->_fs->get_module_type(),
305 381 fs_text_inline( 'Important Upgrade Notice:', 'upgrade_notice', $slug ),
306 382 esc_html( $r->upgrade_notice )
@@ -421,9 +497,9 @@
421 497 );
422 498
423 499 $this->_update_details = false;
424 500
425 - if ( is_object( $new_version ) ) {
501 + if ( is_object( $new_version ) && $this->is_new_version_premium( $new_version ) ) {
426 502 $this->_logger->log( 'Found newer plugin version ' . $new_version->version );
427 503
428 504 /**
429 505 * Cache plugin details locally since set_site_transient( 'update_plugins' )
@@ -436,12 +512,24 @@
436 512 }
437 513 }
438 514
439 515 if ( is_object( $this->_update_details ) ) {
516 + if ( ! isset( $transient_data->response ) ) {
517 + $transient_data->response = array();
518 + }
519 +
440 520 // Add plugin to transient data.
441 - $transient_data->response[ $this->_fs->get_plugin_basename() ] = $this->_fs->is_plugin() ?
521 + $transient_data->response[ $this->_fs->premium_plugin_basename() ] = $this->_fs->is_plugin() ?
442 522 $this->_update_details :
443 523 (array) $this->_update_details;
524 + } else if ( isset( $transient_data->response ) ) {
525 + /**
526 + * Ensure that there's no update data for the plugin to prevent upgrading the premium version to the latest free version.
527 + *
528 + * @author Leo Fajardo (@leorw)
529 + * @since 2.3.0
530 + */
531 + unset( $transient_data->response[ $this->_fs->premium_plugin_basename() ] );
444 532 }
445 533
446 534 $slug = $this->_fs->get_slug();
447 535
@@ -532,8 +620,27 @@
532 620 return $update;
533 621 }
534 622
535 623 /**
624 + * @author Leo Fajardo (@leorw)
625 + * @since 2.3.0
626 + *
627 + * @param FS_Plugin_Tag $new_version
628 + *
629 + * @return bool
630 + */
631 + private function is_new_version_premium( FS_Plugin_Tag $new_version ) {
632 + $query_str = parse_url( $new_version->url, PHP_URL_QUERY );
633 + if ( empty( $query_str ) ) {
634 + return false;
635 + }
636 +
637 + parse_str( $query_str, $params );
638 +
639 + return ( isset( $params['is_premium'] ) && 'true' == $params['is_premium'] );
640 + }
641 +
642 + /**
536 643 * Update the updates transient with the module's update information.
537 644 *
538 645 * This method is required for multisite environment.
539 646 * If a module is site activated (not network) and not on the main site,
@@ -549,8 +656,12 @@
549 656 */
550 657 function set_update_data( FS_Plugin_Tag $new_version ) {
551 658 $this->_logger->entrance();
552 659
660 + if ( ! $this->is_new_version_premium( $new_version ) ) {
661 + return;
662 + }
663 +
553 664 $transient_key = "update_{$this->_fs->get_module_type()}s";
554 665
555 666 $transient_data = get_site_transient( $transient_key );
556 667
@@ -833,10 +944,11 @@
833 944 ) {
834 945 return $data;
835 946 }
836 947
837 - $addon = false;
838 - $is_addon = false;
948 + $addon = false;
949 + $is_addon = false;
950 + $addon_version = false;
839 951
840 952 if ( $this->_fs->get_slug() !== $args->slug ) {
841 953 $addon = $this->_fs->get_addon_by_slug( $args->slug );
842 954
@@ -843,8 +955,22 @@
843 955 if ( ! is_object( $addon ) ) {
844 956 return $data;
845 957 }
846 958
959 + if ( $this->_fs->is_addon_activated( $addon->id ) ) {
960 + $addon_version = $this->_fs->get_addon_instance( $addon->id )->get_plugin_version();
961 + } else if ( $this->_fs->is_addon_installed( $addon->id ) ) {
962 + $addon_plugin_data = get_plugin_data(
963 + ( WP_PLUGIN_DIR . '/' . $this->_fs->get_addon_basename( $addon->id ) ),
964 + false,
965 + false
966 + );
967 +
968 + if ( ! empty( $addon_plugin_data ) ) {
969 + $addon_version = $addon_plugin_data['Version'];
970 + }
971 + }
972 +
847 973 $is_addon = true;
848 974 }
849 975
850 976 $plugin_in_repo = false;
@@ -873,9 +999,11 @@
873 999 $data = $info;
874 1000 }*/
875 1001 }
876 1002
877 - $plugin_version = $this->_fs->get_plugin_version();
1003 + $plugin_version = $is_addon ?
1004 + $addon_version :
1005 + $this->_fs->get_plugin_version();
878 1006
879 1007 // Get plugin's newest update.
880 1008 $new_version = $this->get_latest_download_details( $is_addon ? $addon->id : false, $plugin_version );
881 1009
@@ -1001,10 +1129,10 @@
1001 1129 }
1002 1130
1003 1131 $active_plugins_basenames = get_option( 'active_plugins' );
1004 1132
1005 - for ( $i = 0, $len = count( $active_plugins_basenames ); $i < $len; $i ++ ) {
1006 - if ( $basename === $active_plugins_basenames[ $i ] ) {
1133 + foreach ( $active_plugins_basenames as $key => $active_plugin_basename ) {
1134 + if ( $basename === $active_plugin_basename ) {
1007 1135 // Get filename including extension.
1008 1136 $filename = basename( $basename );
1009 1137
1010 1138 $new_basename = plugin_basename(
@@ -1014,9 +1142,9 @@
1014 1142
1015 1143 // Verify that the expected correct path exists.
1016 1144 if ( file_exists( fs_normalize_path( WP_PLUGIN_DIR . '/' . $new_basename ) ) ) {
1017 1145 // Override active plugin name.
1018 - $active_plugins_basenames[ $i ] = $new_basename;
1146 + $active_plugins_basenames[ $key ] = $new_basename;
1019 1147 update_option( 'active_plugins', $active_plugins_basenames );
1020 1148 }
1021 1149
1022 1150 break;