PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.2.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.2.01
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.2.01, at classes/controllers/FrmAddonsController.php

1,301 lines 35.3 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 } elseif ( current_user_can( 'activate_plugins' ) && self::is_installed( 'formidable-' . $plugin . '/formidable-' . $plugin . '.php' ) ) {
458 $link = array(
459 'url' => 'formidable-' . $plugin . '/formidable-' . $plugin . '.php',
460 'class' => 'frm-activate-addon',
461 );
462 }
463
464 return $link;
465 }
466
467 /**
468 * @since 4.09
469 * @param string $plugin The plugin slug
470 * @return array|false
471 */
472 protected static function get_addon( $plugin ) {
473 $addons = self::get_api_addons();
474 self::prepare_addons( $addons );
475 foreach ( $addons as $addon ) {
476 $slug = explode( '/', $addon['plugin'] );
477 if ( $slug[0] === 'formidable-' . $plugin ) {
478 return $addon;
479 }
480 }
481 return false;
482 }
483
484 /**
485 * @since 4.09
486 * @return string
487 */
488 protected static function get_license_type() {
489 $license_type = '';
490 $addons = self::get_api_addons();
491 if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) {
492 $license_type = $addons['error']['type'];
493 }
494 return $license_type;
495 }
496
497 /**
498 * @since 3.04.03
499 *
500 * @param array $addons
501 * @param object $license The FrmAddon object
502 *
503 * @return array
504 */
505 public static function get_addon_for_license( $addons, $license ) {
506 $download_id = $license->download_id;
507 $plugin = array();
508 if ( empty( $download_id ) && ! empty( $addons ) ) {
509 foreach ( $addons as $addon ) {
510 if ( strtolower( $license->plugin_name ) == strtolower( $addon['title'] ) ) {
511 return $addon;
512 }
513 }
514 } elseif ( isset( $addons[ $download_id ] ) ) {
515 $plugin = $addons[ $download_id ];
516 }
517
518 return $plugin;
519 }
520
521 protected static function prepare_addons( &$addons ) {
522 $activate_url = '';
523 if ( current_user_can( 'activate_plugins' ) ) {
524 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
525 }
526
527 $loop_addons = $addons;
528 foreach ( $loop_addons as $id => $addon ) {
529 if ( is_numeric( $id ) ) {
530 $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
531 $file_name = $addon['plugin'];
532 } else {
533 $slug = $id;
534 if ( isset( $addon['file'] ) ) {
535 $base_file = $addon['file'];
536 } else {
537 $base_file = 'formidable-' . $slug;
538 }
539 $file_name = $base_file . '/' . $base_file . '.php';
540 if ( ! isset( $addon['plugin'] ) ) {
541 $addon['plugin'] = $file_name;
542 }
543 }
544
545 $addon['installed'] = self::is_installed( $file_name );
546 if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) {
547 $active_views_version = self::get_active_views_version();
548 if ( false !== $active_views_version && $slug !== $active_views_version ) {
549 $addon['installed'] = false;
550 }
551 }
552
553 $addon['activate_url'] = '';
554
555 if ( $addon['installed'] && ! empty( $activate_url ) && ! self::is_plugin_active( $file_name, $slug ) ) {
556 $addon['activate_url'] = add_query_arg(
557 array(
558 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
559 'plugin' => $file_name,
560 ),
561 $activate_url
562 );
563 }
564
565 if ( ! isset( $addon['docs'] ) ) {
566 $addon['docs'] = 'knowledgebase/formidable-' . $slug . '/';
567 }
568 self::prepare_addon_link( $addon['docs'] );
569
570 if ( ! isset( $addon['link'] ) ) {
571 $addon['link'] = 'downloads/' . $slug . '/';
572 }
573 self::prepare_addon_link( $addon['link'] );
574
575 self::set_addon_status( $addon );
576 $addons[ $id ] = $addon;
577 }
578 }
579
580 private static function is_plugin_active( $file_name, $slug ) {
581 if ( 'formidable-views/formidable-views.php' === $file_name ) {
582 return self::get_active_views_version() === $slug;
583 }
584 return is_plugin_active( $file_name );
585 }
586
587 /**
588 * @return string|false either 'visual-views' or 'views', false if one is not found.
589 */
590 private static function get_active_views_version() {
591 if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) {
592 return false;
593 }
594 $plugin_version = FrmViewsAppHelper::plugin_version();
595 return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views';
596 }
597
598 /**
599 * @since 3.04.02
600 */
601 protected static function prepare_addon_link( &$link ) {
602 $site_url = 'https://formidableforms.com/';
603 if ( strpos( $link, 'http' ) !== 0 ) {
604 $link = $site_url . $link;
605 }
606 $link = FrmAppHelper::make_affiliate_url( $link );
607 $query_args = array(
608 'utm_source' => 'WordPress',
609 'utm_medium' => 'addons',
610 'utm_campaign' => 'liteplugin',
611 );
612 $link = add_query_arg( $query_args, $link );
613 }
614
615 /**
616 * Add the status to the addon array. Status options are:
617 * installed, active, not installed
618 *
619 * @since 3.04.02
620 */
621 protected static function set_addon_status( &$addon ) {
622 if ( ! empty( $addon['activate_url'] ) ) {
623 $addon['status'] = array(
624 'type' => 'installed',
625 'label' => __( 'Installed', 'formidable' ),
626 );
627 } elseif ( $addon['installed'] ) {
628 $addon['status'] = array(
629 'type' => 'active',
630 'label' => __( 'Active', 'formidable' ),
631 );
632 } else {
633 $addon['status'] = array(
634 'type' => 'not-installed',
635 'label' => __( 'Not Installed', 'formidable' ),
636 );
637 }
638 }
639
640 public static function upgrade_to_pro() {
641 FrmAppHelper::include_svg();
642
643 $link_parts = array(
644 'medium' => 'upgrade',
645 'content' => 'button',
646 );
647
648 $features = array(
649 'Display Entries' => array(
650 array(
651 'label' => 'Display form data with virtually limitless views',
652 'link' => array(
653 'content' => 'views',
654 'param' => 'views-display-form-data',
655 ),
656 'lite' => false,
657 ),
658 array(
659 'label' => 'Generate graphs and stats based on your submitted data',
660 'link' => array(
661 'content' => 'graphs',
662 'param' => 'statistics-graphs-wordpress-forms',
663 ),
664 'lite' => false,
665 ),
666 ),
667 'Entry Management' => array(
668 array(
669 'label' => 'Import entries from a CSV',
670 'link' => array(
671 'content' => 'import-entries',
672 'param' => 'importing-exporting-wordpress-forms',
673 ),
674 'lite' => false,
675 ),
676 array(
677 'label' => 'Logged-in users can save drafts and return later',
678 'link' => array(
679 'content' => 'save-drafts',
680 'param' => 'save-drafts-wordpress-form',
681 ),
682 'lite' => false,
683 ),
684 array(
685 'label' => 'Flexibly and powerfully view, edit, and delete entries from anywhere on your site',
686 'link' => array(
687 'content' => 'front-edit',
688 'param' => 'wordpress-front-end-editing',
689 ),
690 'lite' => false,
691 ),
692 array(
693 'label' => 'View form submissions from the back-end',
694 'lite' => true,
695 ),
696 array(
697 'label' => 'Export your entries to a CSV',
698 'lite' => true,
699 ),
700 ),
701 'Form Building' => array(
702 array(
703 'label' => 'Save a calculated value into a field',
704 'link' => array(
705 'content' => 'calculations',
706 'param' => 'field-calculations-wordpress-form',
707 ),
708 'lite' => false,
709 ),
710 array(
711 'label' => 'Allow multiple file uploads',
712 'link' => array(
713 'content' => 'file-uploads',
714 'param' => 'wordpress-multi-file-upload-fields',
715 ),
716 'lite' => false,
717 ),
718 array(
719 'label' => 'Repeat sections of fields',
720 'link' => array(
721 'content' => 'repeaters',
722 'param' => 'repeatable-sections-forms',
723 ),
724 'lite' => false,
725 ),
726 array(
727 'label' => 'Hide and show fields conditionally based on other fields or the user\'s role',
728 'link' => array(
729 'content' => 'conditional-logic',
730 'param' => 'conditional-logic-wordpress-forms',
731 ),
732 'lite' => false,
733 ),
734 array(
735 'label' => 'Confirmation fields',
736 'link' => array(
737 'content' => 'confirmation-fields',
738 'param' => 'confirmation-fields-wordpress-forms',
739 ),
740 'lite' => false,
741 ),
742 array(
743 'label' => 'Multi-paged forms',
744 'link' => array(
745 'content' => 'page-breaks',
746 'param' => 'wordpress-multi-page-forms',
747 ),
748 'lite' => false,
749 ),
750 array(
751 '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.',
752 'lite' => false,
753 ),
754 array(
755 'label' => 'Include text, email, url, paragraph text, radio, checkbox, dropdown fields, hidden fields, user ID fields, and HTML blocks in your form.',
756 'lite' => true,
757 ),
758 array(
759 'label' => 'Drag & Drop Form building',
760 'link' => array(
761 'content' => 'drag-drop',
762 'param' => 'drag-drop-forms',
763 ),
764 'lite' => true,
765 ),
766 array(
767 'label' => 'Create forms from Templates',
768 'link' => array(
769 'content' => 'form-templates',
770 'param' => 'wordpress-form-templates',
771 ),
772 'lite' => true,
773 ),
774 array(
775 'label' => 'Import and export forms with XML',
776 'link' => array(
777 'content' => 'import',
778 'param' => 'importing-exporting-wordpress-forms',
779 ),
780 'lite' => true,
781 ),
782 array(
783 'label' => 'Use input placeholder text in your fields that clear when typing starts.',
784 'lite' => true,
785 ),
786 ),
787 'Form Actions' => array(
788 array(
789 'label' => 'Conditionally send your email notifications based on values in your form',
790 'link' => array(
791 'content' => 'conditional-emails',
792 ),
793 'lite' => false,
794 ),
795 array(
796 'label' => 'Create and edit WordPress posts or custom posts from the front-end',
797 'link' => array(
798 'content' => 'create-posts',
799 'param' => 'create-posts-pages-wordpress-forms',
800 ),
801 'lite' => false,
802 ),
803 array(
804 'label' => 'Send multiple emails and autoresponders',
805 'link' => array(
806 'content' => 'multiple-emails',
807 'param' => 'virtually-unlimited-emails',
808 ),
809 'lite' => true,
810 ),
811 ),
812 'Form Appearance' => array(
813 array(
814 'label' => 'Create Multiple styles for different forms',
815 'link' => array(
816 'content' => 'multiple-styles',
817 'param' => 'wordpress-visual-form-styler',
818 ),
819 'lite' => false,
820 ),
821 array(
822 'label' => 'Customizable layout with CSS classes',
823 'link' => array(
824 'content' => 'form-layout',
825 'param' => 'wordpress-mobile-friendly-forms',
826 ),
827 'lite' => true,
828 ),
829 array(
830 'label' => 'Customize the HTML for your forms',
831 'link' => array(
832 'content' => 'custom-html',
833 'param' => 'customizable-html-wordpress-form',
834 ),
835 'lite' => true,
836 ),
837 array(
838 'label' => 'Style your form with the Visual Form Styler',
839 'lite' => true,
840 ),
841 ),
842 );
843
844 include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' );
845 }
846
847 /**
848 * Install Pro after connection with Formidable.
849 *
850 * @since 4.02.05
851 */
852 public static function connect_pro() {
853 FrmAppHelper::permission_check( 'install_plugins' );
854 check_ajax_referer( 'frm_ajax', 'nonce' );
855
856 $url = self::get_current_plugin();
857 if ( FrmAppHelper::pro_is_installed() || empty( $url ) ) {
858 wp_die();
859 }
860
861 $response = array();
862
863 // It's already installed and active.
864 $active = activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
865 if ( is_wp_error( $active ) ) {
866 // The plugin was installed, but not active. Download it now.
867 self::ajax_install_addon();
868 } else {
869 $response['active'] = true;
870 $response['success'] = true;
871 }
872
873 echo json_encode( $response );
874 wp_die();
875 }
876
877 /**
878 * @since 5.0.10
879 *
880 * @return string
881 */
882 protected static function get_current_plugin() {
883 if ( ! isset( self::$plugin ) ) {
884 self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' );
885 }
886 return self::$plugin;
887 }
888
889 /**
890 * @since 4.08
891 */
892 protected static function download_and_activate() {
893 if ( is_admin() ) {
894 FrmAppHelper::set_current_screen_and_hook_suffix();
895 }
896
897 self::maybe_show_cred_form();
898
899 $installed = self::install_addon();
900 if ( is_array( $installed ) && isset( $installed['message'] ) ) {
901 return $installed;
902 }
903 self::maybe_activate_addon( $installed );
904 }
905
906 /**
907 * @since 3.04.02
908 */
909 protected static function maybe_show_cred_form() {
910 if ( ! function_exists( 'request_filesystem_credentials' ) ) {
911 include_once( ABSPATH . 'wp-admin/includes/file.php' );
912 }
913
914 // Start output bufferring to catch the filesystem form if credentials are needed.
915 ob_start();
916
917 $show_form = false;
918 $method = '';
919 $url = add_query_arg( array( 'page' => 'formidable-settings' ), admin_url( 'admin.php' ) );
920 $url = esc_url_raw( $url );
921 $creds = request_filesystem_credentials( $url, $method, false, false, null );
922
923 if ( false === $creds ) {
924 $show_form = true;
925 } elseif ( ! WP_Filesystem( $creds ) ) {
926 request_filesystem_credentials( $url, $method, true, false, null );
927 $show_form = true;
928 }
929
930 if ( $show_form ) {
931 $form = ob_get_clean();
932 $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' );
933 $data = $form;
934 $response = array(
935 'success' => false,
936 'message' => $message,
937 'form' => $form,
938 );
939 wp_send_json( $response );
940 }
941
942 ob_end_clean();
943 }
944
945 /**
946 * We do not need any extra credentials if we have gotten this far,
947 * so let's install the plugin.
948 *
949 * @since 3.04.02
950 */
951 protected static function install_addon() {
952 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
953
954 $download_url = self::get_current_plugin();
955
956 // Create the plugin upgrader with our custom skin.
957 $installer = new Plugin_Upgrader( new FrmInstallerSkin() );
958 $installer->install( $download_url );
959
960 // Flush the cache and return the newly installed plugin basename.
961 wp_cache_flush();
962
963 $plugin = $installer->plugin_info();
964 if ( ! $plugin ) {
965 return array(
966 'message' => 'Plugin was not installed. ' . $installer->result,
967 'success' => false,
968 );
969 }
970 return $plugin;
971 }
972
973 /**
974 * @since 3.06.03
975 */
976 public static function ajax_activate_addon() {
977
978 self::install_addon_permissions();
979
980 FrmAppHelper::set_current_screen_and_hook_suffix();
981
982 $plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'sanitize_text_field' );
983 self::maybe_activate_addon( $plugin );
984
985 echo json_encode( self::get_addon_activation_response() );
986 wp_die();
987 }
988
989 /**
990 * @return array|string
991 */
992 private static function get_addon_activation_response() {
993 if ( self::activating_from_settings_page() ) {
994 $response = array(
995 'message' => __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ),
996 'saveAndReload' => 'settings',
997 );
998 } else {
999 $response = __( 'Your plugin has been activated. Please reload the page to see more options.', 'formidable' );
1000 }
1001 return $response;
1002 }
1003
1004 /**
1005 * @return bool
1006 */
1007 private static function activating_from_settings_page() {
1008 return false !== strpos( FrmAppHelper::get_server_value( 'HTTP_REFERER' ), 'frm_action=settings' );
1009 }
1010
1011 /**
1012 * @since 3.04.02
1013 * @param string $installed The plugin folder name with file name
1014 */
1015 protected static function maybe_activate_addon( $installed ) {
1016 if ( ! $installed ) {
1017 return;
1018 }
1019
1020 $activate = activate_plugin( $installed );
1021 if ( is_wp_error( $activate ) ) {
1022 // Ignore the invalid header message that shows with nested plugins.
1023 if ( $activate->get_error_code() !== 'no_plugin_header' ) {
1024 if ( wp_doing_ajax() ) {
1025 echo json_encode( array( 'error' => $activate->get_error_message() ) );
1026 wp_die();
1027 }
1028 return array(
1029 'message' => $activate->get_error_message(),
1030 'success' => false,
1031 );
1032 }
1033 }
1034 }
1035
1036 /**
1037 * Run security checks before installing
1038 *
1039 * @since 3.04.02
1040 */
1041 protected static function install_addon_permissions() {
1042 check_ajax_referer( 'frm_ajax', 'nonce' );
1043
1044 if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) {
1045 echo json_encode( true );
1046 wp_die();
1047 }
1048 }
1049
1050 /**
1051 * @since 4.08
1052 */
1053 public static function connect_link() {
1054 $auth = get_option( 'frm_connect_token' );
1055 if ( empty( $auth ) ) {
1056 $auth = hash( 'sha512', wp_rand() );
1057 update_option( 'frm_connect_token', $auth );
1058 }
1059 $link = FrmAppHelper::admin_upgrade_link( 'connect', 'api-connect' );
1060 $args = array(
1061 'v' => 2,
1062 'siteurl' => FrmAppHelper::site_url(),
1063 'url' => get_rest_url(),
1064 'token' => $auth,
1065 'l' => self::get_pro_license(),
1066 );
1067
1068 return add_query_arg( $args, $link );
1069 }
1070
1071 /**
1072 * Check the auth value for install permission.
1073 *
1074 * @since 4.08
1075 *
1076 * @return bool
1077 */
1078 public static function can_install_addon_api() {
1079 // Verify params present (auth & download link).
1080 $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' );
1081 $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' );
1082
1083 if ( empty( $post_auth ) || empty( $post_url ) ) {
1084 return false;
1085 }
1086
1087 // Verify auth.
1088 $auth = get_option( 'frm_connect_token' );
1089 if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) {
1090 return false;
1091 }
1092
1093 return true;
1094 }
1095
1096 /**
1097 * Install and/or activate the add-on file.
1098 *
1099 * @since 4.08
1100 */
1101 public static function install_addon_api() {
1102 self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1103
1104 $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' );
1105
1106 // Delete so cannot replay.
1107 delete_option( 'frm_connect_token' );
1108
1109 // It's already installed and active.
1110 $active = activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1111 if ( is_wp_error( $active ) ) {
1112 // Download plugin now.
1113 $response = self::download_and_activate();
1114 if ( is_array( $response ) && isset( $response['success'] ) ) {
1115 return $response;
1116 }
1117 }
1118
1119 // If empty license, save it now.
1120 if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) {
1121 load_formidable_pro();
1122 $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) );
1123 if ( ! $license ) {
1124 return array(
1125 'success' => false,
1126 'error' => 'That site does not have a valid license key.',
1127 );
1128 }
1129
1130 $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' );
1131 if ( ! $response['success'] ) {
1132 // Could not activate license.
1133 return $response;
1134 }
1135 }
1136
1137 return array(
1138 'success' => true,
1139 );
1140 }
1141
1142 /**
1143 * Render a conditional action button for a specified plugin
1144 *
1145 * @param string $plugin
1146 * @param array|string $upgrade_link_args
1147 * @since 4.09
1148 */
1149 public static function conditional_action_button( $plugin, $upgrade_link_args ) {
1150 if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) {
1151 return FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args );
1152 }
1153
1154 $addon = self::get_addon( $plugin );
1155 $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args );
1156 self::addon_upgrade_link( $addon, $upgrade_link );
1157 }
1158
1159 /**
1160 * Render a conditional action button for an add on
1161 *
1162 * @since 4.09.01
1163 * @param array $addon
1164 * @param string|false $license_type
1165 * @param string $plan_required
1166 * @param string $upgrade_link
1167 */
1168 public static function show_conditional_action_button( $atts ) {
1169 if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) {
1170 return FrmProAddonsController::show_conditional_action_button( $atts );
1171 }
1172
1173 self::addon_upgrade_link( $atts['addon'], $atts['upgrade_link'] );
1174 }
1175
1176 /**
1177 * @since 4.09.01
1178 */
1179 protected static function addon_upgrade_link( $addon, $upgrade_link ) {
1180 if ( $addon ) {
1181 $upgrade_link .= '&utm_content=' . $addon['slug'];
1182 }
1183
1184 if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) {
1185 // Solutions will go to a separate page.
1186 $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1187 }
1188 ?>
1189 <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' ); ?>">
1190 <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
1191 </a>
1192 <?php
1193 }
1194
1195 /**
1196 * @since 3.04.02
1197 */
1198 public static function ajax_install_addon() {
1199 self::install_addon_permissions();
1200
1201 self::download_and_activate();
1202
1203 echo json_encode( self::get_addon_activation_response() );
1204 wp_die();
1205 }
1206
1207 /**
1208 * @since 4.06.02
1209 * @deprecated 4.09.01
1210 */
1211 public static function ajax_multiple_addons() {
1212 FrmDeprecated::ajax_multiple_addons();
1213 }
1214
1215 /**
1216 * @since 3.04.03
1217 * @deprecated 3.06
1218 * @codeCoverageIgnore
1219 * @return array
1220 */
1221 public static function error_for_license( $license ) {
1222 return FrmDeprecated::error_for_license( $license );
1223 }
1224
1225 /**
1226 * @since 3.04.03
1227 * @deprecated 3.06
1228 * @codeCoverageIgnore
1229 */
1230 public static function get_pro_updater() {
1231 return FrmDeprecated::get_pro_updater();
1232 }
1233
1234 /**
1235 * @since 3.04.03
1236 * @deprecated 3.06
1237 * @codeCoverageIgnore
1238 *
1239 * @return array
1240 */
1241 public static function get_addon_info( $license = '' ) {
1242 return FrmDeprecated::get_addon_info( $license );
1243 }
1244
1245 /**
1246 * @since 3.04.03
1247 * @deprecated 3.06
1248 * @codeCoverageIgnore
1249 *
1250 * @return string
1251 */
1252 public static function get_cache_key( $license ) {
1253 return FrmDeprecated::get_cache_key( $license );
1254 }
1255
1256 /**
1257 * @since 3.04.03
1258 * @deprecated 3.06
1259 * @codeCoverageIgnore
1260 */
1261 public static function reset_cached_addons( $license = '' ) {
1262 FrmDeprecated::reset_cached_addons( $license );
1263 }
1264
1265 /**
1266 * @since 2.03.08
1267 * @deprecated 3.04.03
1268 * @codeCoverageIgnore
1269 *
1270 * @param boolean $return
1271 * @param string $package
1272 *
1273 * @return boolean
1274 */
1275 public static function add_shorten_edd_filename_filter( $return, $package ) {
1276 return FrmDeprecated::add_shorten_edd_filename_filter( $return, $package );
1277 }
1278
1279 /**
1280 * @since 2.03.08
1281 * @deprecated 3.04.03
1282 * @codeCoverageIgnore
1283 *
1284 * @param string $filename
1285 * @param string $ext
1286 *
1287 * @return string
1288 */
1289 public static function shorten_edd_filename( $filename, $ext ) {
1290 return FrmDeprecated::shorten_edd_filename( $filename, $ext );
1291 }
1292
1293 /**
1294 * @deprecated 3.04.03
1295 * @codeCoverageIgnore
1296 */
1297 public static function get_licenses() {
1298 FrmDeprecated::get_licenses();
1299 }
1300 }
1301