PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.9
Code Manager v1.0.9
1.0.48 1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / freemius / templates / account / partials / addon.php
code-manager / freemius / templates / account / partials Last commit date
activate-license-button.php 4 years ago addon.php 4 years ago deactivate-license-button.php 4 years ago index.php 4 years ago site.php 4 years ago
addon.php
446 lines
1 <?php
2 /**
3 * @var array $VARS
4 * @var Freemius $fs
5 */
6 $fs = $VARS['parent_fs'];
7 $addon_id = $VARS['addon_id'];
8 $odd = $VARS['odd'];
9 $slug = $fs->get_slug();
10
11 $fs_blog_id = $VARS['fs_blog_id'];
12
13 $active_plugins_directories_map = $VARS['active_plugins_directories_map'];
14
15 $addon_info = $VARS['addon_info'];
16 $is_addon_activated = $fs->is_addon_activated( $addon_id );
17 $is_addon_connected = $addon_info['is_connected'];
18 $is_addon_installed = $VARS['is_addon_installed'];
19
20 $fs_addon = ( $is_addon_connected && $is_addon_installed ) ?
21 freemius( $addon_id ) :
22 false;
23
24 // Aliases.
25 $download_latest_text = fs_text_x_inline( 'Download Latest', 'as download latest version', 'download-latest', $slug );
26 $downgrading_plan_text = fs_text_inline( 'Downgrading your plan', 'downgrading-plan', $slug );
27 $cancelling_subscription_text = fs_text_inline( 'Cancelling the subscription', 'cancelling-subscription', $slug );
28 /* translators: %1$s: Either 'Downgrading your plan' or 'Cancelling the subscription' */
29 $downgrade_x_confirm_text = fs_text_inline( '%1$s will immediately stop all future recurring payments and your %s plan license will expire in %s.', 'downgrade-x-confirm', $slug );
30 $prices_increase_text = fs_text_inline( 'Please note that we will not be able to grandfather outdated pricing for renewals/new subscriptions after a cancellation. If you choose to renew the subscription manually in the future, after a price increase, which typically occurs once a year, you will be charged the updated price.', 'pricing-increase-warning', $slug );
31 $cancel_trial_confirm_text = fs_text_inline( 'Cancelling the trial will immediately block access to all premium features. Are you sure?', 'cancel-trial-confirm', $slug );
32 $after_downgrade_non_blocking_text = fs_text_inline( 'You can still enjoy all %s features but you will not have access to %s security & feature updates, nor support.', 'after-downgrade-non-blocking', $slug );
33 $after_downgrade_blocking_text = fs_text_inline( 'Once your license expires you can still use the Free version but you will NOT have access to the %s features.', 'after-downgrade-blocking', $slug );
34 /* translators: %s: Plan title (e.g. "Professional") */
35 $activate_plan_text = fs_text_inline( 'Activate %s Plan', 'activate-x-plan', $slug );
36 $version_text = fs_text_x_inline( 'Version', 'product version', 'version', $slug );
37 /* translators: %s: Time period (e.g. Auto renews in "2 months") */
38 $renews_in_text = fs_text_inline( 'Auto renews in %s', 'renews-in', $slug );
39 /* translators: %s: Time period (e.g. Expires in "2 months") */
40 $expires_in_text = fs_text_inline( 'Expires in %s', 'expires-in', $slug );
41 $cancel_trial_text = fs_text_inline( 'Cancel Trial', 'cancel-trial', $slug );
42 $change_plan_text = fs_text_inline( 'Change Plan', 'change-plan', $slug );
43 $upgrade_text = fs_text_x_inline( 'Upgrade', 'verb', 'upgrade', $slug );
44 $addons_text = fs_text_inline( 'Add-Ons', 'add-ons', $slug );
45 $downgrade_text = fs_text_x_inline( 'Downgrade', 'verb', 'downgrade', $slug );
46 $trial_text = fs_text_x_inline( 'Trial', 'trial period', 'trial', $slug );
47 $free_text = fs_text_inline( 'Free', 'free', $slug );
48 $activate_text = fs_text_inline( 'Activate', 'activate', $slug );
49 $plan_text = fs_text_x_inline( 'Plan', 'as product pricing plan', 'plan', $slug );
50
51 // Defaults.
52 $plan = null;
53 $is_paid_trial = false;
54 /**
55 * @var FS_Plugin_License $license
56 */
57 $license = null;
58 $site = null;
59 $is_active_subscription = false;
60 $subscription = null;
61 $is_paying = false;
62 $show_upgrade = false;
63 $is_whitelabeled = $VARS['is_whitelabeled'];
64
65 if ( is_object( $fs_addon ) ) {
66 $is_paying = $fs_addon->is_paying();
67 $user = $fs_addon->get_user();
68 $site = $fs_addon->get_site();
69 $license = $fs_addon->_get_license();
70 $subscription = ( is_object( $license ) ?
71 $fs_addon->_get_subscription( $license->id ) :
72 null );
73 $plan = $fs_addon->get_plan();
74 $plan_name = $plan->name;
75 $plan_title = $plan->title;
76 $is_paid_trial = $fs_addon->is_paid_trial();
77 $version = $fs_addon->get_plugin_version();
78 $is_whitelabeled = (
79 $fs_addon->is_whitelabeled( true ) &&
80 ! $fs_addon->get_parent_instance()->is_data_debug_mode()
81 );
82 $show_upgrade = (
83 ! $is_whitelabeled &&
84 $fs_addon->has_paid_plan() &&
85 ! $is_paying &&
86 ! $is_paid_trial &&
87 ! $fs_addon->_has_premium_license()
88 );
89 } else if ( $is_addon_connected ) {
90 if (
91 empty( $addon_info ) ||
92 ! isset( $addon_info['site'] )
93 ) {
94 $is_addon_connected = false;
95 } else {
96 /**
97 * @var FS_Site $site
98 */
99 $site = $addon_info['site'];
100 $version = $addon_info['version'];
101
102 $plan_name = isset( $addon_info['plan_name'] ) ?
103 $addon_info['plan_name'] :
104 '';
105
106 $plan_title = isset( $addon_info['plan_title'] ) ?
107 $addon_info['plan_title'] :
108 '';
109
110 if ( isset( $addon_info['license'] ) ) {
111 $license = $addon_info['license'];
112 }
113
114 if ( isset( $addon_info['subscription'] ) ) {
115 $subscription = $addon_info['subscription'];
116 }
117
118 $has_valid_and_active_license = (
119 is_object( $license ) &&
120 $license->is_active() &&
121 $license->is_valid()
122 );
123
124 $is_paid_trial = (
125 $site->is_trial() &&
126 $has_valid_and_active_license &&
127 ( $site->trial_plan_id == $license->plan_id )
128 );
129
130 $is_whitelabeled = $addon_info['is_whitelabeled'];
131 }
132 }
133
134 $has_feature_enabled_license = (
135 is_object( $license ) &&
136 $license->is_features_enabled()
137 );
138
139 $is_active_subscription = ( is_object( $subscription ) && $subscription->is_active() );
140
141 $show_delete_install_button = ( ! $is_paying && WP_FS__DEV_MODE && ! $is_whitelabeled );
142 ?>
143 <tr<?php if ( $odd ) {
144 echo ' class="alternate"';
145 } ?>>
146 <td>
147 <!-- Title -->
148 <?php echo $addon_info['title'] ?>
149 </td>
150 <?php if ( $is_addon_connected ) : ?>
151 <!-- ID -->
152 <td><?php echo $site->id ?></td>
153 <!--/ ID -->
154
155 <!-- Version -->
156 <td><?php echo $version ?></td>
157 <!--/ Version -->
158
159 <!-- Plan Title -->
160 <td><?php echo strtoupper( is_string( $plan_name ) ? $plan_title : $free_text ) ?></td>
161 <!--/ Plan Title -->
162
163 <!-- Expiration -->
164 <td>
165 <?php if ( $site->is_trial() || is_object( $license ) ) : ?>
166 <?php
167 $tags = array();
168
169 if ( $site->is_trial() ) {
170 $tags[] = array( 'label' => $trial_text, 'type' => 'success' );
171
172 $tags[] = array(
173 'label' => sprintf(
174 ( $is_paid_trial ?
175 $renews_in_text :
176 $expires_in_text ),
177 human_time_diff( time(), strtotime( $site->trial_ends ) )
178 ),
179 'type' => ( $is_paid_trial ? 'success' : 'warn' )
180 );
181 } else {
182 if ( is_object( $license ) ) {
183 if ( $license->is_cancelled ) {
184 $tags[] = array(
185 'label' => fs_text_inline( 'Cancelled', 'cancelled', $slug ),
186 'type' => 'error'
187 );
188 } else if ( $license->is_expired() ) {
189 $tags[] = array(
190 'label' => fs_text_inline( 'Expired', 'expired', $slug ),
191 'type' => 'error'
192 );
193 } else if ( $license->is_lifetime() ) {
194 $tags[] = array(
195 'label' => fs_text_inline( 'No expiration', 'no-expiration', $slug ),
196 'type' => 'success'
197 );
198 } else if ( ! $is_active_subscription && ! $license->is_first_payment_pending() ) {
199 $tags[] = array(
200 'label' => sprintf( $expires_in_text, human_time_diff( time(), strtotime( $license->expiration ) ) ),
201 'type' => 'warn'
202 );
203 } else if ( $is_active_subscription && ! $subscription->is_first_payment_pending() ) {
204 $tags[] = array(
205 'label' => sprintf( $renews_in_text, human_time_diff( time(), strtotime( $subscription->next_payment ) ) ),
206 'type' => 'success'
207 );
208 }
209 }
210 }
211
212 foreach ( $tags as $t ) {
213 printf( '<label class="fs-tag fs-%s">%s</label>' . "\n", $t['type'], $t['label'] );
214 }
215 ?>
216 <?php endif ?>
217 </td>
218 <!--/ Expiration -->
219
220 <?php
221 $buttons = array();
222 $is_license_activation_added = false;
223
224 if ( $is_addon_activated ) {
225 if ( ! $is_whitelabeled ) {
226 if ( $is_paying ) {
227 $buttons[] = fs_ui_get_action_button(
228 $fs->get_id(),
229 'account',
230 'deactivate_license',
231 fs_text_inline( 'Deactivate License', 'deactivate-license', $slug ),
232 '',
233 array( 'plugin_id' => $addon_id ),
234 false,
235 true
236 );
237
238 $human_readable_license_expiration = human_time_diff( time(), strtotime( $license->expiration ) );
239 $downgrade_confirmation_message = sprintf(
240 $downgrade_x_confirm_text,
241 ( $fs_addon->is_only_premium() ? $cancelling_subscription_text : $downgrading_plan_text ),
242 $plan->title,
243 $human_readable_license_expiration
244 );
245
246 $after_downgrade_message = ! $license->is_block_features ?
247 sprintf( $after_downgrade_non_blocking_text, $plan->title, $fs_addon->get_module_label( true ) ) :
248 sprintf( $after_downgrade_blocking_text, $plan->title );
249
250 if ( ! $license->is_lifetime() && $is_active_subscription ) {
251 $buttons[] = fs_ui_get_action_button(
252 $fs->get_id(),
253 'account',
254 'downgrade_account',
255 esc_html( $fs_addon->is_only_premium() ? fs_text_inline( 'Cancel Subscription', 'cancel-subscription', $slug ) : $downgrade_text ),
256 '',
257 array( 'plugin_id' => $addon_id ),
258 false,
259 false,
260 false,
261 ( $downgrade_confirmation_message . ' ' . $after_downgrade_message . ' ' . $prices_increase_text ),
262 'POST'
263 );
264 }
265 } else if ( $is_paid_trial ) {
266 $buttons[] = fs_ui_get_action_button(
267 $fs->get_id(),
268 'account',
269 'cancel_trial',
270 esc_html( $cancel_trial_text ),
271 '',
272 array( 'plugin_id' => $addon_id ),
273 false,
274 false,
275 'dashicons dashicons-download',
276 $cancel_trial_confirm_text,
277 'POST'
278 );
279 } else if ( ! $has_feature_enabled_license ) {
280 $premium_licenses = $fs_addon->get_available_premium_licenses();
281
282 if ( ! empty( $premium_licenses ) ) {
283 $premium_license = $premium_licenses[0];
284 $has_multiple_premium_licenses = ( 1 < count( $premium_licenses ) );
285
286 if ( ! $has_multiple_premium_licenses ) {
287 $premium_plan = $fs_addon->_get_plan_by_id( $premium_license->plan_id );
288 $site = $fs_addon->get_site();
289
290 $buttons[] = fs_ui_get_action_button(
291 $fs->get_id(),
292 'account',
293 'activate_license',
294 esc_html( sprintf( $activate_plan_text, $premium_plan->title, ( $site->is_localhost() && $premium_license->is_free_localhost ) ? '[localhost]' : ( 1 < $premium_license->left() ? $premium_license->left() . ' left' : '' ) ) ),
295 ($has_multiple_premium_licenses ?
296 'activate-license-trigger ' . $fs_addon->get_unique_affix() :
297 ''),
298 array(
299 'plugin_id' => $addon_id,
300 'license_id' => $premium_license->id,
301 ),
302 true,
303 true
304 );
305
306 $is_license_activation_added = true;
307 }
308 }
309 }
310 }
311
312 // if ( 0 == count( $buttons ) ) {
313 if ( $fs_addon->is_premium() && ! $is_license_activation_added ) {
314 $fs_addon->_add_license_activation_dialog_box();
315
316 $buttons[] = fs_ui_get_action_button(
317 $fs->get_id(),
318 'account',
319 'activate_license',
320 ( ! $has_feature_enabled_license ) ?
321 fs_esc_html_inline( 'Activate License', 'activate-license', $slug ) :
322 fs_esc_html_inline( 'Change License', 'change-license', $slug ),
323 'activate-license-trigger ' . $fs_addon->get_unique_affix(),
324 array(
325 'plugin_id' => $addon_id,
326 ),
327 (! $has_feature_enabled_license),
328 true
329 );
330
331 $is_license_activation_added = true;
332 }
333
334 if ( $fs_addon->has_paid_plan() ) {
335 // Add sync license only if non of the other CTAs are visible.
336 $buttons[] = fs_ui_get_action_button(
337 $fs->get_id(),
338 'account',
339 $fs->get_unique_affix() . '_sync_license',
340 fs_esc_html_x_inline( 'Sync', 'as synchronize', 'sync', $slug ),
341 '',
342 array( 'plugin_id' => $addon_id ),
343 false,
344 true
345 );
346 }
347 // }
348 } else if ( ! $show_upgrade ) {
349 if ( $fs->is_addon_installed( $addon_id ) ) {
350 $addon_file = $fs->get_addon_basename( $addon_id );
351
352 if ( ! isset( $active_plugins_directories_map[ dirname( $addon_file ) ] ) ) {
353 $buttons[] = sprintf(
354 '<a class="button button-primary edit" href="%s" title="%s">%s</a>',
355 wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $addon_file, 'activate-plugin_' . $addon_file ),
356 fs_esc_attr_inline( 'Activate this add-on', 'activate-this-addon', $slug ),
357 $activate_text
358 );
359 }
360 } else {
361 if ( $fs->is_allowed_to_install() ) {
362 $buttons[] = sprintf(
363 '<a class="button button-primary edit" href="%s">%s</a>',
364 wp_nonce_url( self_admin_url( 'update.php?' . ( ( isset( $addon_info['has_paid_plan'] ) && $addon_info['has_paid_plan'] ) ? 'fs_allow_updater_and_dialog=true&' : '' ) . 'action=install-plugin&plugin=' . $addon_info['slug'] ), 'install-plugin_' . $addon_info['slug'] ),
365 fs_text_inline( 'Install Now', 'install-now', $slug )
366 );
367 } else {
368 $buttons[] = sprintf(
369 '<a target="_blank" rel="noopener" class="button button-primary edit" href="%s">%s</a>',
370 $fs->_get_latest_download_local_url( $addon_id ),
371 esc_html( $download_latest_text )
372 );
373 }
374 }
375 }
376
377 if ( $show_upgrade ) {
378 $buttons[] = sprintf( '<a href="%s" class="thickbox button button-small button-primary" aria-label="%s" data-title="%s"><i class="dashicons dashicons-cart"></i> %s</a>',
379 esc_url( network_admin_url( 'plugin-install.php?fs_allow_updater_and_dialog=true' . ( ! empty( $fs_blog_id ) ? '&fs_blog_id=' . $fs_blog_id : '' ) . '&tab=plugin-information&parent_plugin_id=' . $fs->get_id() . '&plugin=' . $addon_info['slug'] .
380 '&TB_iframe=true&width=600&height=550' ) ),
381 esc_attr( sprintf( fs_text_inline( 'More information about %s', 'more-information-about-x', $slug ), $addon_info['title'] ) ),
382 esc_attr( $addon_info['title'] ),
383 ( $fs_addon->has_free_plan() ?
384 $upgrade_text :
385 fs_text_x_inline( 'Purchase', 'verb', 'purchase', $slug ) )
386 );
387 }
388
389 $buttons_count = count( $buttons );
390 ?>
391
392 <!-- Actions -->
393 <td><?php if ( $buttons_count > 1 ) : ?>
394 <div class="button-group"><?php endif ?>
395 <?php foreach ( $buttons as $button ) {
396 echo $button;
397 } ?>
398 <?php if ( $buttons_count > 1 ) : ?></div><?php endif ?></td>
399 <!--/ Actions -->
400
401 <?php else : ?>
402 <?php // Add-on NOT Installed or was never connected.
403 $is_addon_installed_by_filesystem = $fs->is_addon_installed( $addon_id );
404 ?>
405 <!-- Action -->
406 <td colspan="<?php echo ( $is_addon_installed_by_filesystem || $show_delete_install_button ) ? '5' : '4' ?>">
407 <?php if ( $is_addon_installed_by_filesystem ) : ?>
408 <?php $addon_file = $fs->get_addon_basename( $addon_id ) ?>
409 <?php if ( ! isset( $active_plugins_directories_map[ dirname( $addon_file ) ] ) ) : ?>
410 <a class="button button-primary"
411 href="<?php echo wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $addon_file, 'activate-plugin_' . $addon_file ) ?>"
412 title="<?php fs_esc_attr_echo_inline( 'Activate this add-on', 'activate-this-addon', $slug ) ?>"
413 class="edit"><?php echo esc_html( $activate_text ) ?></a>
414 <?php endif ?>
415 <?php else : ?>
416 <?php if ( $fs->is_allowed_to_install() ) : ?>
417 <a class="button button-primary"
418 href="<?php echo wp_nonce_url( self_admin_url( 'update.php?' . ( ( isset( $addon_info['has_paid_plan'] ) && $addon_info['has_paid_plan'] ) ? 'fs_allow_updater_and_dialog=true&' : '' ) . 'action=install-plugin&plugin=' . $addon_info['slug'] ), 'install-plugin_' . $addon_info['slug'] ) ?>"><?php fs_esc_html_echo_inline( 'Install Now', 'install-now', $slug ) ?></a>
419 <?php else : ?>
420 <a target="_blank" rel="noopener" class="button button-primary"
421 href="<?php echo $fs->_get_latest_download_local_url( $addon_id ) ?>"><?php echo esc_html( $download_latest_text ) ?></a>
422 <?php endif ?>
423 <?php endif ?>
424 </td>
425 <!--/ Action -->
426 <?php endif ?>
427 <?php if ( $show_delete_install_button ) : ?>
428 <!-- Optional Delete Action -->
429 <td>
430 <?php
431 if ( $is_addon_activated ) {
432 fs_ui_action_button(
433 $fs->get_id(), 'account',
434 'delete_account',
435 fs_text_x_inline( 'Delete', 'verb', 'delete', $slug ),
436 '',
437 array( 'plugin_id' => $addon_id ),
438 false,
439 $show_upgrade
440 );
441 }
442 ?>
443 </td>
444 <!--/ Optional Delete Action -->
445 <?php endif ?>
446 </tr>