PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.14
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.14
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / controllers / FrmAddonsController.php

FrmAddonsController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.0.14, at classes/controllers/FrmAddonsController.php

1,300 lines 35.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmAddonsController {
7
8 /**
9 * @var string $plugin
10 */
11 protected static $plugin;
12
13 public static function menu() {
14 if ( ! current_user_can( 'activate_plugins' ) ) {
15 return;
16 }
17
18 $label = __( 'Add-Ons', 'formidable' );
19 $label = '<span style="color:#fe5a1d">' . $label . '</span>';
20
21 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );
22
23 if ( ! FrmAppHelper::pro_is_installed() ) {
24 add_submenu_page(
25 'formidable',
26 'Formidable | ' . __( 'Upgrade', 'formidable' ),
27 '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>',
28 'frm_view_forms',
29 'formidable-pro-upgrade',
30 'FrmAddonsController::upgrade_to_pro'
31 );
32 } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) {
33 wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
34 exit;
35 }
36 }
37
38 public static function list_addons() {
39 FrmAppHelper::include_svg();
40 $installed_addons = apply_filters( 'frm_installed_addons', array() );
41 $license_type = '';
42
43 $addons = self::get_api_addons();
44 $errors = array();
45
46 if ( isset( $addons['error'] ) ) {
47 $api = new FrmFormApi();
48 $errors = $api->get_error_from_response( $addons );
49 $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : '';
50 unset( $addons['error'] );
51 }
52
53 $pro = array(
54 'pro' => array(
55 'title' => 'Formidable Forms Pro',
56 'slug' => 'formidable-pro',
57 'released' => '2011-02-05',
58 'docs' => 'knowledgebase/',
59 'excerpt' => 'Create calculators, surveys, smart forms, and data-driven applications. Build directories, real estate listings, job boards, and much more.',
60 ),
61 );
62 $addons = $pro + $addons;
63 self::prepare_addons( $addons );
64
65 $pricing = FrmAppHelper::admin_upgrade_link( 'addons' );
66
67 include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
68 }
69
70 public static function license_settings() {
71 $plugins = apply_filters( 'frm_installed_addons', array() );
72 if ( empty( $plugins ) ) {
73 esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
74
75 return;
76 }
77
78 ksort( $plugins );
79
80 include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
81 }
82
83 protected static function get_api_addons() {
84 $api = new FrmFormApi();
85 $addons = $api->get_api_info();
86
87 if ( empty( $addons ) ) {
88 $addons = self::fallback_plugin_list();
89 } else {
90 foreach ( $addons as $k => $addon ) {
91 if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
92 unset( $addons[ $k ] );
93 }
94 }
95 }
96
97 return $addons;
98 }
99
100 /**
101 * If the API is unable to connect, show something on the addons page
102 *
103 * @since 3.04.03
104 * @return array
105 */
106 protected static function fallback_plugin_list() {
107 $list = array(
108 'formidable-pro' => array(
109 'title' => 'Formidable Forms Pro',
110 'link' => 'pricing/',
111 'docs' => '',
112 'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
113 ),
114 'mailchimp' => array(
115 'title' => 'MailChimp Forms',
116 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a MailChimp mailing list when they submit forms and update their information along with the entry.',
117 ),
118 'registration' => array(
119 'title' => 'User Registration Forms',
120 'link' => 'downloads/user-registration/',
121 'excerpt' => 'Give new users access to your site as quickly and painlessly as possible. Allow users to register, edit and be able to login to their profiles on your site from the front end in a clean, customized registration form.',
122 ),
123 'paypal' => array(
124 'title' => 'PayPal Standard Forms',
125 'link' => 'downloads/paypal-standard/',
126 'excerpt' => 'Automate your business by collecting instant payments from your clients. Collect information, calculate a total, and send them on to PayPal. Require a payment before publishing content on your site.',
127 ),
128 'stripe' => array(
129 'title' => 'Stripe Forms',
130 'docs' => 'knowledgebase/stripe/',
131 'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.',
132 ),
133 'authorize-net' => array(
134 'title' => 'Authorize.net AIM Forms',
135 'link' => 'downloads/authorize-net-aim/',
136 'docs' => 'knowledgebase/authorize-net-aim/',
137 'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.',
138 ),
139 'woocommerce' => array(
140 'title' => 'WooCommerce Forms',
141 'excerpt' => 'Use a Formidable form on your WooCommerce product pages.',
142 ),
143 'autoresponder' => array(
144 'title' => 'Form Action Automation',
145 'docs' => 'knowledgebase/schedule-autoresponder/',
146 'excerpt' => 'Schedule email notifications, SMS messages, and API actions.',
147 ),
148 'modal' => array(
149 'title' => 'Bootstrap Modal Forms',
150 'link' => 'downloads/bootstrap-modal/',
151 'docs' => 'knowledgebase/bootstrap-modal/',
152 'excerpt' => 'Open a view or form in a Bootstrap popup.',
153 ),
154 'bootstrap' => array(
155 'title' => 'Bootstrap Style Forms',
156 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
157 ),
158 'zapier' => array(
159 'title' => 'Zapier Forms',
160 'excerpt' => 'Connect with hundreds of different applications through Zapier. Insert a new row in a Google docs spreadsheet, post on Twitter, or add a new Dropbox file with your form.',
161 ),
162 'signature' => array(
163 'title' => 'Digital Signature Forms',
164 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
165 ),
166 'api' => array(
167 'title' => 'Formidable Forms API',
168 'link' => 'downloads/formidable-api/',
169 'excerpt' => 'Send entry results to any other site that has a Rest API. This includes the option of sending entries from one Formidable site to another.',
170 ),
171 'twilio' => array(
172 'title' => 'Twilio SMS Forms',
173 'docs' => 'knowledgebase/twilio-add-on/',
174 'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.',
175 ),
176 'views' => array(
177 'title' => 'Formidable Views',
178 'excerpt' => 'Add the power of views to your Formidable Forms to display your form submissions in listings, tables, calendars, and more.',
179 ),
180 );
181
182 $defaults = array(
183 'released' => '',
184 );
185
186 foreach ( $list as $k => $info ) {
187 $info['slug'] = $k;
188 $list[ $k ] = array_merge( $defaults, $info );
189 }
190 return $list;
191 }
192
193 /**
194 * If Pro is missing but has been authenticated, include a download URL
195 *
196 * @since 3.04.03
197 * @return string
198 */
199 public static function get_pro_download_url() {
200 $license = self::get_pro_license();
201 $api = new FrmFormApi( $license );
202 $downloads = $api->get_api_info();
203 $pro = self::get_pro_from_addons( $downloads );
204
205 return isset( $pro['url'] ) ? $pro['url'] : '';
206 }
207
208 /**
209 * @since 4.08
210 */
211 public static function get_pro_license() {
212 $pro_cred_store = 'frmpro-credentials';
213 $pro_wpmu_store = 'frmpro-wpmu-sitewide';
214 if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
215 $creds = get_site_option( $pro_cred_store );
216 } else {
217 $creds = get_option( $pro_cred_store );
218 }
219
220 if ( empty( $creds ) || ! is_array( $creds ) || ! isset( $creds['license'] ) ) {
221 return '';
222 }
223
224 $license = $creds['license'];
225 if ( empty( $license ) ) {
226 return '';
227 }
228
229 if ( strpos( $license, '-' ) ) {
230 // this is a fix for licenses saved in the past
231 $license = strtoupper( $license );
232 }
233 return $license;
234 }
235
236 /**
237 * @since 4.08
238 */
239 protected static function get_pro_from_addons( $addons ) {
240 return isset( $addons['93790'] ) ? $addons['93790'] : array();
241 }
242
243 /**
244 * @since 4.06
245 */
246 public static function license_type() {
247 if ( is_callable( 'FrmProAddonsController::license_type' ) ) {
248 return FrmProAddonsController::license_type();
249 }
250
251 return 'free';
252 }
253
254 /**
255 * @since 4.0.01
256 */
257 public static function is_license_expired() {
258 $version_info = self::get_primary_license_info();
259 if ( ! isset( $version_info['error'] ) ) {
260 return false;
261 }
262
263 return $version_info['error'];
264 }
265
266 /**
267 * @since 4.08
268 *
269 * @return boolean|int false or the number of days until expiration.
270 */
271 public static function is_license_expiring() {
272 if ( is_callable( 'FrmProAddonsController::is_license_expiring' ) ) {
273 return FrmProAddonsController::is_license_expiring();
274 }
275
276 return false;
277 }
278
279 /**
280 * @since 4.08
281 */
282 protected static function get_primary_license_info() {
283 $installed_addons = apply_filters( 'frm_installed_addons', array() );
284 if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) {
285 return false;
286 }
287 $installed_addons = array(
288 'formidable_pro' => $installed_addons['formidable_pro'],
289 );
290
291 return self::fill_update_addon_info( $installed_addons );
292 }
293
294 /**
295 * @since 3.04.03
296 */
297 public static function check_update( $transient ) {
298 if ( ! FrmAppHelper::pro_is_installed() ) {
299 // Don't make any changes if only Lite is installed.
300 return $transient;
301 }
302
303 if ( ! is_object( $transient ) ) {
304 $transient = new stdClass();
305 }
306
307 $installed_addons = apply_filters( 'frm_installed_addons', array() );
308 if ( empty( $installed_addons ) ) {
309 return $transient;
310 }
311
312 $version_info = self::fill_update_addon_info( $installed_addons );
313
314 $transient->last_checked = time();
315
316 if ( ! function_exists( 'get_plugins' ) ) {
317 require_once ABSPATH . 'wp-admin/includes/plugin.php';
318 }
319 $wp_plugins = get_plugins();
320
321 foreach ( $version_info as $id => $plugin ) {
322 $plugin = (object) $plugin;
323
324 if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) {
325 continue;
326 }
327
328 $folder = $plugin->plugin;
329 if ( empty( $folder ) ) {
330 continue;
331 }
332
333 if ( ! self::is_installed( $folder ) ) {
334 // don't show an update if the plugin isn't installed
335 continue;
336 }
337
338 $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array();
339 $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
340
341 if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
342 $slug = explode( '/', $folder );
343 $plugin->slug = $slug[0];
344 $transient->response[ $folder ] = $plugin;
345 }
346
347 $transient->checked[ $folder ] = $wp_version;
348
349 }
350
351 return $transient;
352 }
353
354 /**
355 * Check if a plugin is installed before showing an update for it
356 *
357 * @since 3.05
358 *
359 * @param string $plugin - the folder/filename.php for a plugin
360 *
361 * @return bool - True if installed
362 */
363 protected static function is_installed( $plugin ) {
364 if ( ! function_exists( 'get_plugins' ) ) {
365 require_once ABSPATH . 'wp-admin/includes/plugin.php';
366 }
367
368 $all_plugins = get_plugins();
369
370 return isset( $all_plugins[ $plugin ] );
371 }
372
373 /**
374 * @since 3.04.03
375 *
376 * @param array $installed_addons
377 *
378 * @return array
379 */
380 protected static function fill_update_addon_info( $installed_addons ) {
381 $checked_licenses = array();
382 $version_info = array();
383
384 foreach ( $installed_addons as $addon ) {
385 if ( $addon->store_url !== 'https://formidableforms.com' ) {
386 // check if this is a third-party addon
387 continue;
388 }
389
390 $new_license = $addon->license;
391 if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) {
392 continue;
393 }
394
395 $checked_licenses[] = $new_license;
396
397 $api = new FrmFormApi( $new_license );
398 if ( empty( $version_info ) ) {
399 $version_info = $api->get_api_info();
400 continue;
401 }
402
403 $plugin = $api->get_addon_for_license( $addon, $version_info );
404 if ( empty( $plugin ) ) {
405 continue;
406 }
407
408 $download_id = isset( $plugin['id'] ) ? $plugin['id'] : 0;
409 if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) {
410 // if this addon is using its own license, get the update url
411 $addon_info = $api->get_api_info();
412
413 $version_info[ $download_id ] = $addon_info[ $download_id ];
414 if ( isset( $addon_info['error'] ) ) {
415 $version_info[ $download_id ]['error'] = array(
416 'message' => $addon_info['error']['message'],
417 'code' => $addon_info['error']['code'],
418 );
419 }
420 }
421 }
422
423 return $version_info;
424 }
425
426 /**
427 * Get the action link for an addon that isn't active.
428 *
429 * @since 3.06.03
430 * @param string $plugin The plugin slug
431 * @return array
432 */
433 public static function install_link( $plugin ) {
434 $link = array();
435 $addon = self::get_addon( $plugin );
436
437 if ( $addon ) {
438 if ( $addon['status']['type'] === 'installed' && ! empty( $addon['activate_url'] ) ) {
439 $link = array(
440 'url' => $addon['plugin'],
441 'class' => 'frm-activate-addon',
442 );
443 } elseif ( isset( $addon['url'] ) && ! empty( $addon['url'] ) ) {
444 $link = array(
445 'url' => $addon['url'],
446 'class' => 'frm-install-addon',
447 );
448 } elseif ( isset( $addon['categories'] ) && ! empty( $addon['categories'] ) ) {
449 $link = array(
450 'categories' => $addon['categories'],
451 );
452 }
453
454 if ( ! empty( $link ) ) {
455 $link['status'] = $addon['status']['type'];
456 }
457 }
458
459 return $link;
460 }
461
462 /**
463 * @since 4.09
464 * @param string $plugin The plugin slug
465 * @return array|false
466 */
467 protected static function get_addon( $plugin ) {
468 $addons = self::get_api_addons();
469 self::prepare_addons( $addons );
470 foreach ( $addons as $addon ) {
471 $slug = explode( '/', $addon['plugin'] );
472 if ( $slug[0] === 'formidable-' . $plugin ) {
473 return $addon;
474 }
475 }
476 return false;
477 }
478
479 /**
480 * @since 4.09
481 * @return string
482 */
483 protected static function get_license_type() {
484 $license_type = '';
485 $addons = self::get_api_addons();
486 if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) {
487 $license_type = $addons['error']['type'];
488 }
489 return $license_type;
490 }
491
492 /**
493 * @since 3.04.03
494 *
495 * @param array $addons
496 * @param object $license The FrmAddon object
497 *
498 * @return array
499 */
500 public static function get_addon_for_license( $addons, $license ) {
501 $download_id = $license->download_id;
502 $plugin = array();
503 if ( empty( $download_id ) && ! empty( $addons ) ) {
504 foreach ( $addons as $addon ) {
505 if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) {
506 return $addon;
507 }
508 }
509 } elseif ( isset( $addons[ $download_id ] ) ) {
510 $plugin = $addons[ $download_id ];
511 }
512
513 return $plugin;
514 }
515
516 protected static function prepare_addons( &$addons ) {
517 $activate_url = '';
518 if ( current_user_can( 'activate_plugins' ) ) {
519 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
520 }
521
522 $loop_addons = $addons;
523 foreach ( $loop_addons as $id => $addon ) {
524 if ( is_numeric( $id ) ) {
525 $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
526 $file_name = $addon['plugin'];
527 } else {
528 $slug = $id;
529 if ( isset( $addon['file'] ) ) {
530 $base_file = $addon['file'];
531 } else {
532 $base_file = 'formidable-' . $slug;
533 }
534 $file_name = $base_file . '/' . $base_file . '.php';
535 if ( ! isset( $addon['plugin'] ) ) {
536 $addon['plugin'] = $file_name;
537 }
538 }
539
540 $addon['installed'] = self::is_installed( $file_name );
541 if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) {
542 $active_views_version = self::get_active_views_version();
543 if ( false !== $active_views_version && $slug !== $active_views_version ) {
544 $addon['installed'] = false;
545 }
546 }
547
548 $addon['activate_url'] = '';
549
550 if ( $addon['installed'] && ! empty( $activate_url ) && ! self::is_plugin_active( $file_name, $slug ) ) {
551 $addon['activate_url'] = add_query_arg(
552 array(
553 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
554 'plugin' => $file_name,
555 ),
556 $activate_url
557 );
558 }
559
560 if ( ! isset( $addon['docs'] ) ) {
561 $addon['docs'] = 'knowledgebase/formidable-' . $slug . '/';
562 }
563 self::prepare_addon_link( $addon['docs'] );
564
565 if ( ! isset( $addon['link'] ) ) {
566 $addon['link'] = 'downloads/' . $slug . '/';
567 }
568 self::prepare_addon_link( $addon['link'] );
569
570 self::set_addon_status( $addon );
571 $addons[ $id ] = $addon;
572 }
573 }
574
575 private static function is_plugin_active( $file_name, $slug ) {
576 if ( 'formidable-views/formidable-views.php' === $file_name ) {
577 return self::get_active_views_version() === $slug;
578 }
579 return is_plugin_active( $file_name );
580 }
581
582 /**
583 * @return string|false either 'visual-views' or 'views', false if one is not found.
584 */
585 private static function get_active_views_version() {
586 if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) {
587 return false;
588 }
589 $plugin_version = FrmViewsAppHelper::plugin_version();
590 return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views';
591 }
592
593 /**
594 * @since 3.04.02
595 */
596 protected static function prepare_addon_link( &$link ) {
597 $site_url = 'https://formidableforms.com/';
598 if ( strpos( $link, 'http' ) !== 0 ) {
599 $link = $site_url . $link;
600 }
601 $link = FrmAppHelper::make_affiliate_url( $link );
602 $query_args = array(
603 'utm_source' => 'WordPress',
604 'utm_medium' => 'addons',
605 'utm_campaign' => 'liteplugin',
606 );
607 $link = add_query_arg( $query_args, $link );
608 }
609
610 /**
611 * Add the status to the addon array. Status options are:
612 * installed, active, not installed
613 *
614 * @since 3.04.02
615 */
616 protected static function set_addon_status( &$addon ) {
617 if ( ! empty( $addon['activate_url'] ) ) {
618 $addon['status'] = array(
619 'type' => 'installed',
620 'label' => __( 'Installed', 'formidable' ),
621 );
622 } elseif ( $addon['installed'] ) {
623 $addon['status'] = array(
624 'type' => 'active',
625 'label' => __( 'Active', 'formidable' ),
626 );
627 } else {
628 $addon['status'] = array(
629 'type' => 'not-installed',
630 'label' => __( 'Not Installed', 'formidable' ),
631 );
632 }
633 }
634
635 public static function upgrade_to_pro() {
636 FrmAppHelper::include_svg();
637
638 $link_parts = array(
639 'medium' => 'upgrade',
640 'content' => 'button',
641 );
642
643 $features = array(
644 'Display Entries' => array(
645 array(
646 'label' => 'Display form data with virtually limitless views',
647 'link' => array(
648 'content' => 'views',
649 'param' => 'views-display-form-data',
650 ),
651 'lite' => false,
652 ),
653 array(
654 'label' => 'Generate graphs and stats based on your submitted data',
655 'link' => array(
656 'content' => 'graphs',
657 'param' => 'statistics-graphs-wordpress-forms',
658 ),
659 'lite' => false,
660 ),
661 ),
662 'Entry Management' => array(
663 array(
664 'label' => 'Import entries from a CSV',
665 'link' => array(
666 'content' => 'import-entries',
667 'param' => 'importing-exporting-wordpress-forms',
668 ),
669 'lite' => false,
670 ),
671 array(
672 'label' => 'Logged-in users can save drafts and return later',
673 'link' => array(
674 'content' => 'save-drafts',
675 'param' => 'save-drafts-wordpress-form',
676 ),
677 'lite' => false,
678 ),
679 array(
680 'label' => 'Flexibly and powerfully view, edit, and delete entries from anywhere on your site',
681 'link' => array(
682 'content' => 'front-edit',
683 'param' => 'wordpress-front-end-editing',
684 ),
685 'lite' => false,
686 ),
687 array(
688 'label' => 'View form submissions from the back-end',
689 'lite' => true,
690 ),
691 array(
692 'label' => 'Export your entries to a CSV',
693 'lite' => true,
694 ),
695 ),
696 'Form Building' => array(
697 array(
698 'label' => 'Save a calculated value into a field',
699 'link' => array(
700 'content' => 'calculations',
701 'param' => 'field-calculations-wordpress-form',
702 ),
703 'lite' => false,
704 ),
705 array(
706 'label' => 'Allow multiple file uploads',
707 'link' => array(
708 'content' => 'file-uploads',
709 'param' => 'wordpress-multi-file-upload-fields',
710 ),
711 'lite' => false,
712 ),
713 array(
714 'label' => 'Repeat sections of fields',
715 'link' => array(
716 'content' => 'repeaters',
717 'param' => 'repeatable-sections-forms',
718 ),
719 'lite' => false,
720 ),
721 array(
722 'label' => 'Hide and show fields conditionally based on other fields or the user\'s role',
723 'link' => array(
724 'content' => 'conditional-logic',
725 'param' => 'conditional-logic-wordpress-forms',
726 ),
727 'lite' => false,
728 ),
729 array(
730 'label' => 'Confirmation fields',
731 'link' => array(
732 'content' => 'confirmation-fields',
733 'param' => 'confirmation-fields-wordpress-forms',
734 ),
735 'lite' => false,
736 ),
737 array(
738 'label' => 'Multi-paged forms',
739 'link' => array(
740 'content' => 'page-breaks',
741 'param' => 'wordpress-multi-page-forms',
742 ),
743 'lite' => false,
744 ),
745 array(
746 'label' => 'Include section headings, page breaks, rich text, dates, times, scales, star ratings, sliders, toggles, dynamic fields populated from other forms, passwords, and tags in advanced forms.',
747 'lite' => false,
748 ),
749 array(
750 'label' => 'Include text, email, url, paragraph text, radio, checkbox, dropdown fields, hidden fields, user ID fields, and HTML blocks in your form.',
751 'lite' => true,
752 ),
753 array(
754 'label' => 'Drag & Drop Form building',
755 'link' => array(
756 'content' => 'drag-drop',
757 'param' => 'drag-drop-forms',
758 ),
759 'lite' => true,
760 ),
761 array(
762 'label' => 'Create forms from Templates',
763 'link' => array(
764 'content' => 'form-templates',
765 'param' => 'wordpress-form-templates',
766 ),
767 'lite' => true,
768 ),
769 array(
770 'label' => 'Import and export forms with XML',
771 'link' => array(
772 'content' => 'import',
773 'param' => 'importing-exporting-wordpress-forms',
774 ),
775 'lite' => true,
776 ),
777 array(
778 'label' => 'Use input placeholder text in your fields that clear when typing starts.',
779 'lite' => true,
780 ),
781 ),
782 'Form Actions' => array(
783 array(
784 'label' => 'Conditionally send your email notifications based on values in your form',
785 'link' => array(
786 'content' => 'conditional-emails',
787 ),
788 'lite' => false,
789 ),
790 array(
791 'label' => 'Create and edit WordPress posts or custom posts from the front-end',
792 'link' => array(
793 'content' => 'create-posts',
794 'param' => 'create-posts-pages-wordpress-forms',
795 ),
796 'lite' => false,
797 ),
798 array(
799 'label' => 'Send multiple emails and autoresponders',
800 'link' => array(
801 'content' => 'multiple-emails',
802 'param' => 'virtually-unlimited-emails',
803 ),
804 'lite' => true,
805 ),
806 ),
807 'Form Appearance' => array(
808 array(
809 'label' => 'Create Multiple styles for different forms',
810 'link' => array(
811 'content' => 'multiple-styles',
812 'param' => 'wordpress-visual-form-styler',
813 ),
814 'lite' => false,
815 ),
816 array(
817 'label' => 'Customizable layout with CSS classes',
818 'link' => array(
819 'content' => 'form-layout',
820 'param' => 'wordpress-mobile-friendly-forms',
821 ),
822 'lite' => true,
823 ),
824 array(
825 'label' => 'Customize the HTML for your forms',
826 'link' => array(
827 'content' => 'custom-html',
828 'param' => 'customizable-html-wordpress-form',
829 ),
830 'lite' => true,
831 ),
832 array(
833 'label' => 'Style your form with the Visual Form Styler',
834 'lite' => true,
835 ),
836 ),
837 );
838
839 include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' );
840 }
841
842 /**
843 * Install Pro after connection with Formidable.
844 *
845 * @since 4.02.05
846 */
847 public static function connect_pro() {
848 FrmAppHelper::permission_check( 'install_plugins' );
849 check_ajax_referer( 'frm_ajax', 'nonce' );
850
851 $url = self::get_current_plugin();
852 if ( FrmAppHelper::pro_is_installed() || empty( $url ) ) {
853 wp_die();
854 }
855
856 $response = array();
857
858 // It's already installed and active.
859 $active = activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
860 if ( is_wp_error( $active ) ) {
861 // The plugin was installed, but not active. Download it now.
862 self::ajax_install_addon();
863 } else {
864 $response['active'] = true;
865 $response['success'] = true;
866 }
867
868 echo json_encode( $response );
869 wp_die();
870 }
871
872 /**
873 * @since 5.0.10
874 *
875 * @return string
876 */
877 protected static function get_current_plugin() {
878 if ( ! isset( self::$plugin ) ) {
879 self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' );
880 }
881 return self::$plugin;
882 }
883
884 /**
885 * @since 4.08
886 */
887 protected static function download_and_activate() {
888 // Set the current screen to avoid undefined notices.
889 if ( is_admin() ) {
890 global $hook_suffix;
891 set_current_screen();
892 }
893
894 self::maybe_show_cred_form();
895
896 $installed = self::install_addon();
897 if ( is_array( $installed ) && isset( $installed['message'] ) ) {
898 return $installed;
899 }
900 self::maybe_activate_addon( $installed );
901 }
902
903 /**
904 * @since 3.04.02
905 */
906 protected static function maybe_show_cred_form() {
907 if ( ! function_exists( 'request_filesystem_credentials' ) ) {
908 include_once( ABSPATH . 'wp-admin/includes/file.php' );
909 }
910
911 // Start output bufferring to catch the filesystem form if credentials are needed.
912 ob_start();
913
914 $show_form = false;
915 $method = '';
916 $url = add_query_arg( array( 'page' => 'formidable-settings' ), admin_url( 'admin.php' ) );
917 $url = esc_url_raw( $url );
918 $creds = request_filesystem_credentials( $url, $method, false, false, null );
919
920 if ( false === $creds ) {
921 $show_form = true;
922 } elseif ( ! WP_Filesystem( $creds ) ) {
923 request_filesystem_credentials( $url, $method, true, false, null );
924 $show_form = true;
925 }
926
927 if ( $show_form ) {
928 $form = ob_get_clean();
929 $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' );
930 $data = $form;
931 $response = array(
932 'success' => false,
933 'message' => $message,
934 'form' => $form,
935 );
936 wp_send_json( $response );
937 }
938
939 ob_end_clean();
940 }
941
942 /**
943 * We do not need any extra credentials if we have gotten this far,
944 * so let's install the plugin.
945 *
946 * @since 3.04.02
947 */
948 protected static function install_addon() {
949 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
950
951 $download_url = self::get_current_plugin();
952
953 // Create the plugin upgrader with our custom skin.
954 $installer = new Plugin_Upgrader( new FrmInstallerSkin() );
955 $installer->install( $download_url );
956
957 // Flush the cache and return the newly installed plugin basename.
958 wp_cache_flush();
959
960 $plugin = $installer->plugin_info();
961 if ( ! $plugin ) {
962 return array(
963 'message' => 'Plugin was not installed. ' . $installer->result,
964 'success' => false,
965 );
966 }
967 return $plugin;
968 }
969
970 /**
971 * @since 3.06.03
972 */
973 public static function ajax_activate_addon() {
974
975 self::install_addon_permissions();
976
977 // Set the current screen to avoid undefined notices.
978 global $hook_suffix;
979 set_current_screen();
980
981 $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
982 self::maybe_activate_addon( $plugin );
983
984 echo json_encode( self::get_addon_activation_response() );
985 wp_die();
986 }
987
988 /**
989 * @return array|string
990 */
991 private static function get_addon_activation_response() {
992 if ( self::activating_from_settings_page() ) {
993 $response = array(
994 'message' => __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ),
995 'saveAndReload' => 'settings',
996 );
997 } else {
998 $response = __( 'Your plugin has been activated. Please reload the page to see more options.', 'formidable' );
999 }
1000 return $response;
1001 }
1002
1003 /**
1004 * @return bool
1005 */
1006 private static function activating_from_settings_page() {
1007 return false !== strpos( FrmAppHelper::get_server_value( 'HTTP_REFERER' ), 'frm_action=settings' );
1008 }
1009
1010 /**
1011 * @since 3.04.02
1012 * @param string $installed The plugin folder name with file name
1013 */
1014 protected static function maybe_activate_addon( $installed ) {
1015 if ( ! $installed ) {
1016 return;
1017 }
1018
1019 $activate = activate_plugin( $installed );
1020 if ( is_wp_error( $activate ) ) {
1021 // Ignore the invalid header message that shows with nested plugins.
1022 if ( $activate->get_error_code() !== 'no_plugin_header' ) {
1023 if ( wp_doing_ajax() ) {
1024 echo json_encode( array( 'error' => $activate->get_error_message() ) );
1025 wp_die();
1026 }
1027 return array(
1028 'message' => $activate->get_error_message(),
1029 'success' => false,
1030 );
1031 }
1032 }
1033 }
1034
1035 /**
1036 * Run security checks before installing
1037 *
1038 * @since 3.04.02
1039 */
1040 protected static function install_addon_permissions() {
1041 check_ajax_referer( 'frm_ajax', 'nonce' );
1042
1043 if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) {
1044 echo json_encode( true );
1045 wp_die();
1046 }
1047 }
1048
1049 /**
1050 * @since 4.08
1051 */
1052 public static function connect_link() {
1053 $auth = get_option( 'frm_connect_token' );
1054 if ( empty( $auth ) ) {
1055 $auth = hash( 'sha512', wp_rand() );
1056 update_option( 'frm_connect_token', $auth );
1057 }
1058 $link = FrmAppHelper::admin_upgrade_link( 'connect', 'api-connect' );
1059 $args = array(
1060 'v' => 2,
1061 'siteurl' => FrmAppHelper::site_url(),
1062 'url' => get_rest_url(),
1063 'token' => $auth,
1064 'l' => self::get_pro_license(),
1065 );
1066
1067 return add_query_arg( $args, $link );
1068 }
1069
1070 /**
1071 * Check the auth value for install permission.
1072 *
1073 * @since 4.08
1074 *
1075 * @return bool
1076 */
1077 public static function can_install_addon_api() {
1078 // Verify params present (auth & download link).
1079 $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' );
1080 $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' );
1081
1082 if ( empty( $post_auth ) || empty( $post_url ) ) {
1083 return false;
1084 }
1085
1086 // Verify auth.
1087 $auth = get_option( 'frm_connect_token' );
1088 if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) {
1089 return false;
1090 }
1091
1092 return true;
1093 }
1094
1095 /**
1096 * Install and/or activate the add-on file.
1097 *
1098 * @since 4.08
1099 */
1100 public static function install_addon_api() {
1101 self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1102
1103 $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' );
1104
1105 // Delete so cannot replay.
1106 delete_option( 'frm_connect_token' );
1107
1108 // It's already installed and active.
1109 $active = activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1110 if ( is_wp_error( $active ) ) {
1111 // Download plugin now.
1112 $response = self::download_and_activate();
1113 if ( is_array( $response ) && isset( $response['success'] ) ) {
1114 return $response;
1115 }
1116 }
1117
1118 // If empty license, save it now.
1119 if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) {
1120 load_formidable_pro();
1121 $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) );
1122 if ( ! $license ) {
1123 return array(
1124 'success' => false,
1125 'error' => 'That site does not have a valid license key.',
1126 );
1127 }
1128
1129 $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' );
1130 if ( ! $response['success'] ) {
1131 // Could not activate license.
1132 return $response;
1133 }
1134 }
1135
1136 return array(
1137 'success' => true,
1138 );
1139 }
1140
1141 /**
1142 * Render a conditional action button for a specified plugin
1143 *
1144 * @param string $plugin
1145 * @param array|string $upgrade_link_args
1146 * @since 4.09
1147 */
1148 public static function conditional_action_button( $plugin, $upgrade_link_args ) {
1149 if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) {
1150 return FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args );
1151 }
1152
1153 $addon = self::get_addon( $plugin );
1154 $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args );
1155 self::addon_upgrade_link( $addon, $upgrade_link );
1156 }
1157
1158 /**
1159 * Render a conditional action button for an add on
1160 *
1161 * @since 4.09.01
1162 * @param array $addon
1163 * @param string|false $license_type
1164 * @param string $plan_required
1165 * @param string $upgrade_link
1166 */
1167 public static function show_conditional_action_button( $atts ) {
1168 if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) {
1169 return FrmProAddonsController::show_conditional_action_button( $atts );
1170 }
1171
1172 self::addon_upgrade_link( $atts['addon'], $atts['upgrade_link'] );
1173 }
1174
1175 /**
1176 * @since 4.09.01
1177 */
1178 protected static function addon_upgrade_link( $addon, $upgrade_link ) {
1179 if ( $addon ) {
1180 $upgrade_link .= '&utm_content=' . $addon['slug'];
1181 }
1182
1183 if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) {
1184 // Solutions will go to a separate page.
1185 $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1186 }
1187 ?>
1188 <a class="install-now button button-secondary frm-button-secondary" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>">
1189 <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
1190 </a>
1191 <?php
1192 }
1193
1194 /**
1195 * @since 3.04.02
1196 */
1197 public static function ajax_install_addon() {
1198 self::install_addon_permissions();
1199
1200 self::download_and_activate();
1201
1202 echo json_encode( self::get_addon_activation_response() );
1203 wp_die();
1204 }
1205
1206 /**
1207 * @since 4.06.02
1208 * @deprecated 4.09.01
1209 */
1210 public static function ajax_multiple_addons() {
1211 FrmDeprecated::ajax_multiple_addons();
1212 }
1213
1214 /**
1215 * @since 3.04.03
1216 * @deprecated 3.06
1217 * @codeCoverageIgnore
1218 * @return array
1219 */
1220 public static function error_for_license( $license ) {
1221 return FrmDeprecated::error_for_license( $license );
1222 }
1223
1224 /**
1225 * @since 3.04.03
1226 * @deprecated 3.06
1227 * @codeCoverageIgnore
1228 */
1229 public static function get_pro_updater() {
1230 return FrmDeprecated::get_pro_updater();
1231 }
1232
1233 /**
1234 * @since 3.04.03
1235 * @deprecated 3.06
1236 * @codeCoverageIgnore
1237 *
1238 * @return array
1239 */
1240 public static function get_addon_info( $license = '' ) {
1241 return FrmDeprecated::get_addon_info( $license );
1242 }
1243
1244 /**
1245 * @since 3.04.03
1246 * @deprecated 3.06
1247 * @codeCoverageIgnore
1248 *
1249 * @return string
1250 */
1251 public static function get_cache_key( $license ) {
1252 return FrmDeprecated::get_cache_key( $license );
1253 }
1254
1255 /**
1256 * @since 3.04.03
1257 * @deprecated 3.06
1258 * @codeCoverageIgnore
1259 */
1260 public static function reset_cached_addons( $license = '' ) {
1261 FrmDeprecated::reset_cached_addons( $license );
1262 }
1263
1264 /**
1265 * @since 2.03.08
1266 * @deprecated 3.04.03
1267 * @codeCoverageIgnore
1268 *
1269 * @param boolean $return
1270 * @param string $package
1271 *
1272 * @return boolean
1273 */
1274 public static function add_shorten_edd_filename_filter( $return, $package ) {
1275 return FrmDeprecated::add_shorten_edd_filename_filter( $return, $package );
1276 }
1277
1278 /**
1279 * @since 2.03.08
1280 * @deprecated 3.04.03
1281 * @codeCoverageIgnore
1282 *
1283 * @param string $filename
1284 * @param string $ext
1285 *
1286 * @return string
1287 */
1288 public static function shorten_edd_filename( $filename, $ext ) {
1289 return FrmDeprecated::shorten_edd_filename( $filename, $ext );
1290 }
1291
1292 /**
1293 * @deprecated 3.04.03
1294 * @codeCoverageIgnore
1295 */
1296 public static function get_licenses() {
1297 FrmDeprecated::get_licenses();
1298 }
1299 }
1300