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

1,312 lines 35.5 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 /**
14 * @return void
15 */
16 public static function menu() {
17 if ( ! current_user_can( 'activate_plugins' ) ) {
18 return;
19 }
20
21 $label = __( 'Add-Ons', 'formidable' );
22 $label = '<span style="color:#fe5a1d">' . $label . '</span>';
23
24 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );
25
26 if ( ! FrmAppHelper::pro_is_installed() ) {
27 add_submenu_page(
28 'formidable',
29 'Formidable | ' . __( 'Upgrade', 'formidable' ),
30 '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>',
31 'frm_view_forms',
32 'formidable-pro-upgrade',
33 'FrmAddonsController::upgrade_to_pro'
34 );
35 } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) {
36 wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
37 exit;
38 }
39 }
40
41 public static function list_addons() {
42 FrmAppHelper::include_svg();
43 $installed_addons = apply_filters( 'frm_installed_addons', array() );
44 $license_type = '';
45
46 $addons = self::get_api_addons();
47 $errors = array();
48
49 if ( isset( $addons['error'] ) ) {
50 $api = new FrmFormApi();
51 $errors = $api->get_error_from_response( $addons );
52 $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : '';
53 unset( $addons['error'] );
54 }
55
56 $pro = array(
57 'pro' => array(
58 'title' => 'Formidable Forms Pro',
59 'slug' => 'formidable-pro',
60 'released' => '2011-02-05',
61 'docs' => 'knowledgebase/',
62 'excerpt' => 'Create calculators, surveys, smart forms, and data-driven applications. Build directories, real estate listings, job boards, and much more.',
63 ),
64 );
65 $addons = $pro + $addons;
66 self::prepare_addons( $addons );
67
68 $pricing = FrmAppHelper::admin_upgrade_link( 'addons' );
69
70 include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
71 }
72
73 public static function license_settings() {
74 $plugins = apply_filters( 'frm_installed_addons', array() );
75 if ( empty( $plugins ) ) {
76 esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
77
78 return;
79 }
80
81 ksort( $plugins );
82
83 include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
84 }
85
86 protected static function get_api_addons() {
87 $api = new FrmFormApi();
88 $addons = $api->get_api_info();
89
90 if ( empty( $addons ) ) {
91 $addons = self::fallback_plugin_list();
92 } else {
93 foreach ( $addons as $k => $addon ) {
94 if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
95 unset( $addons[ $k ] );
96 }
97 }
98 }
99
100 return $addons;
101 }
102
103 /**
104 * If the API is unable to connect, show something on the addons page
105 *
106 * @since 3.04.03
107 * @return array
108 */
109 protected static function fallback_plugin_list() {
110 $list = array(
111 'formidable-pro' => array(
112 'title' => 'Formidable Forms Pro',
113 'link' => 'pricing/',
114 'docs' => '',
115 'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
116 ),
117 'mailchimp' => array(
118 'title' => 'MailChimp Forms',
119 '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.',
120 ),
121 'registration' => array(
122 'title' => 'User Registration Forms',
123 'link' => 'downloads/user-registration/',
124 '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.',
125 ),
126 'paypal' => array(
127 'title' => 'PayPal Standard Forms',
128 'link' => 'downloads/paypal-standard/',
129 '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.',
130 ),
131 'stripe' => array(
132 'title' => 'Stripe Forms',
133 'docs' => 'knowledgebase/stripe/',
134 'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.',
135 ),
136 'authorize-net' => array(
137 'title' => 'Authorize.net AIM Forms',
138 'link' => 'downloads/authorize-net-aim/',
139 'docs' => 'knowledgebase/authorize-net-aim/',
140 'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.',
141 ),
142 'woocommerce' => array(
143 'title' => 'WooCommerce Forms',
144 'excerpt' => 'Use a Formidable form on your WooCommerce product pages.',
145 ),
146 'autoresponder' => array(
147 'title' => 'Form Action Automation',
148 'docs' => 'knowledgebase/schedule-autoresponder/',
149 'excerpt' => 'Schedule email notifications, SMS messages, and API actions.',
150 ),
151 'modal' => array(
152 'title' => 'Bootstrap Modal Forms',
153 'link' => 'downloads/bootstrap-modal/',
154 'docs' => 'knowledgebase/bootstrap-modal/',
155 'excerpt' => 'Open a view or form in a Bootstrap popup.',
156 ),
157 'bootstrap' => array(
158 'title' => 'Bootstrap Style Forms',
159 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
160 ),
161 'zapier' => array(
162 'title' => 'Zapier Forms',
163 '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.',
164 ),
165 'signature' => array(
166 'title' => 'Digital Signature Forms',
167 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
168 ),
169 'api' => array(
170 'title' => 'Formidable Forms API',
171 'link' => 'downloads/formidable-api/',
172 '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.',
173 ),
174 'twilio' => array(
175 'title' => 'Twilio SMS Forms',
176 'docs' => 'knowledgebase/twilio-add-on/',
177 'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.',
178 ),
179 'views' => array(
180 'title' => 'Formidable Views',
181 'excerpt' => 'Add the power of views to your Formidable Forms to display your form submissions in listings, tables, calendars, and more.',
182 ),
183 'quiz_maker' => array(
184 'title' => 'Quiz Maker',
185 'link' => 'downloads/quiz-maker/',
186 'excerpt' => 'Make quizzes, automatically score them and show user scores.',
187 ),
188 );
189
190 $defaults = array(
191 'released' => '',
192 );
193
194 foreach ( $list as $k => $info ) {
195 $info['slug'] = $k;
196 $list[ $k ] = array_merge( $defaults, $info );
197 }
198 return $list;
199 }
200
201 /**
202 * If Pro is missing but has been authenticated, include a download URL
203 *
204 * @since 3.04.03
205 * @return string
206 */
207 public static function get_pro_download_url() {
208 $license = self::get_pro_license();
209 $api = new FrmFormApi( $license );
210 $downloads = $api->get_api_info();
211 $pro = self::get_pro_from_addons( $downloads );
212
213 return isset( $pro['url'] ) ? $pro['url'] : '';
214 }
215
216 /**
217 * @since 4.08
218 */
219 public static function get_pro_license() {
220 $pro_cred_store = 'frmpro-credentials';
221 $pro_wpmu_store = 'frmpro-wpmu-sitewide';
222 if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
223 $creds = get_site_option( $pro_cred_store );
224 } else {
225 $creds = get_option( $pro_cred_store );
226 }
227
228 if ( empty( $creds ) || ! is_array( $creds ) || ! isset( $creds['license'] ) ) {
229 return '';
230 }
231
232 $license = $creds['license'];
233 if ( empty( $license ) ) {
234 return '';
235 }
236
237 if ( strpos( $license, '-' ) ) {
238 // this is a fix for licenses saved in the past
239 $license = strtoupper( $license );
240 }
241 return $license;
242 }
243
244 /**
245 * @since 4.08
246 */
247 protected static function get_pro_from_addons( $addons ) {
248 return isset( $addons['93790'] ) ? $addons['93790'] : array();
249 }
250
251 /**
252 * @since 4.06
253 */
254 public static function license_type() {
255 if ( is_callable( 'FrmProAddonsController::license_type' ) ) {
256 return FrmProAddonsController::license_type();
257 }
258
259 return 'free';
260 }
261
262 /**
263 * @since 4.0.01
264 */
265 public static function is_license_expired() {
266 $version_info = self::get_primary_license_info();
267 if ( ! isset( $version_info['error'] ) ) {
268 return false;
269 }
270
271 return $version_info['error'];
272 }
273
274 /**
275 * @since 4.08
276 *
277 * @return boolean|int false or the number of days until expiration.
278 */
279 public static function is_license_expiring() {
280 if ( is_callable( 'FrmProAddonsController::is_license_expiring' ) ) {
281 return FrmProAddonsController::is_license_expiring();
282 }
283
284 return false;
285 }
286
287 /**
288 * @since 4.08
289 */
290 protected static function get_primary_license_info() {
291 $installed_addons = apply_filters( 'frm_installed_addons', array() );
292 if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) {
293 return false;
294 }
295 $installed_addons = array(
296 'formidable_pro' => $installed_addons['formidable_pro'],
297 );
298
299 return self::fill_update_addon_info( $installed_addons );
300 }
301
302 /**
303 * @since 3.04.03
304 */
305 public static function check_update( $transient ) {
306 if ( ! FrmAppHelper::pro_is_installed() ) {
307 // Don't make any changes if only Lite is installed.
308 return $transient;
309 }
310
311 if ( ! is_object( $transient ) ) {
312 $transient = new stdClass();
313 }
314
315 $installed_addons = apply_filters( 'frm_installed_addons', array() );
316 if ( empty( $installed_addons ) ) {
317 return $transient;
318 }
319
320 $version_info = self::fill_update_addon_info( $installed_addons );
321
322 $transient->last_checked = time();
323
324 $wp_plugins = FrmAppHelper::get_plugins();
325
326 foreach ( $version_info as $id => $plugin ) {
327 $plugin = (object) $plugin;
328
329 if ( ! isset( $plugin->new_version ) || ! isset( $plugin->package ) ) {
330 continue;
331 }
332
333 $folder = $plugin->plugin;
334 if ( empty( $folder ) ) {
335 continue;
336 }
337
338 if ( ! self::is_installed( $folder ) ) {
339 // don't show an update if the plugin isn't installed
340 continue;
341 }
342
343 $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array();
344 $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
345
346 if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
347 $slug = explode( '/', $folder );
348 $plugin->slug = $slug[0];
349 $transient->response[ $folder ] = $plugin;
350 }
351
352 $transient->checked[ $folder ] = $wp_version;
353
354 }
355
356 return $transient;
357 }
358
359 /**
360 * Check if a plugin is installed before showing an update for it
361 *
362 * @since 3.05
363 *
364 * @param string $plugin - the folder/filename.php for a plugin
365 *
366 * @return bool - True if installed
367 */
368 protected static function is_installed( $plugin ) {
369 $all_plugins = FrmAppHelper::get_plugins();
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 $activating_page = self::get_activating_page();
994
995 $response = array(
996 'message' => __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ),
997 'saveAndReload' => $activating_page,
998 );
999
1000 return $response;
1001 }
1002
1003 /**
1004 * Return a string that reflects the page from which the addon is being activated on,
1005 * if it is from settings or form builder, otherwise return empty string.
1006 *
1007 * @return string
1008 */
1009 private static function get_activating_page() {
1010 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1011 if ( false !== strpos( $referer, 'frm_action=settings' ) ) {
1012 return 'settings';
1013 }
1014
1015 if ( false !== strpos( $referer, 'frm_action=edit' ) ) {
1016 return 'form_builder';
1017 }
1018
1019 return '';
1020 }
1021
1022 /**
1023 * @since 3.04.02
1024 * @param string $installed The plugin folder name with file name
1025 */
1026 protected static function maybe_activate_addon( $installed ) {
1027 if ( ! $installed ) {
1028 return;
1029 }
1030
1031 $activate = activate_plugin( $installed );
1032 if ( is_wp_error( $activate ) ) {
1033 // Ignore the invalid header message that shows with nested plugins.
1034 if ( $activate->get_error_code() !== 'no_plugin_header' ) {
1035 if ( wp_doing_ajax() ) {
1036 echo json_encode( array( 'error' => $activate->get_error_message() ) );
1037 wp_die();
1038 }
1039 return array(
1040 'message' => $activate->get_error_message(),
1041 'success' => false,
1042 );
1043 }
1044 }
1045 }
1046
1047 /**
1048 * Run security checks before installing
1049 *
1050 * @since 3.04.02
1051 */
1052 protected static function install_addon_permissions() {
1053 check_ajax_referer( 'frm_ajax', 'nonce' );
1054
1055 if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) {
1056 echo json_encode( true );
1057 wp_die();
1058 }
1059 }
1060
1061 /**
1062 * @since 4.08
1063 */
1064 public static function connect_link() {
1065 $auth = get_option( 'frm_connect_token' );
1066 if ( empty( $auth ) ) {
1067 $auth = hash( 'sha512', wp_rand() );
1068 update_option( 'frm_connect_token', $auth );
1069 }
1070 $link = FrmAppHelper::admin_upgrade_link( 'connect', 'api-connect' );
1071 $args = array(
1072 'v' => 2,
1073 'siteurl' => FrmAppHelper::site_url(),
1074 'url' => get_rest_url(),
1075 'token' => $auth,
1076 'l' => self::get_pro_license(),
1077 );
1078
1079 return add_query_arg( $args, $link );
1080 }
1081
1082 /**
1083 * Check the auth value for install permission.
1084 *
1085 * @since 4.08
1086 *
1087 * @return bool
1088 */
1089 public static function can_install_addon_api() {
1090 // Verify params present (auth & download link).
1091 $post_auth = FrmAppHelper::get_param( 'token', '', 'request', 'sanitize_text_field' );
1092 $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' );
1093
1094 if ( empty( $post_auth ) || empty( $post_url ) ) {
1095 return false;
1096 }
1097
1098 // Verify auth.
1099 $auth = get_option( 'frm_connect_token' );
1100 if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) {
1101 return false;
1102 }
1103
1104 return true;
1105 }
1106
1107 /**
1108 * Install and/or activate the add-on file.
1109 *
1110 * @since 4.08
1111 */
1112 public static function install_addon_api() {
1113 self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1114
1115 $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' );
1116
1117 // Delete so cannot replay.
1118 delete_option( 'frm_connect_token' );
1119
1120 // It's already installed and active.
1121 $active = activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1122 if ( is_wp_error( $active ) ) {
1123 // Download plugin now.
1124 $response = self::download_and_activate();
1125 if ( is_array( $response ) && isset( $response['success'] ) ) {
1126 return $response;
1127 }
1128 }
1129
1130 // If empty license, save it now.
1131 if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) {
1132 load_formidable_pro();
1133 $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) );
1134 if ( ! $license ) {
1135 return array(
1136 'success' => false,
1137 'error' => 'That site does not have a valid license key.',
1138 );
1139 }
1140
1141 $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' );
1142 if ( ! $response['success'] ) {
1143 // Could not activate license.
1144 return $response;
1145 }
1146 }
1147
1148 return array(
1149 'success' => true,
1150 );
1151 }
1152
1153 /**
1154 * Render a conditional action button for a specified plugin
1155 *
1156 * @param string $plugin
1157 * @param array|string $upgrade_link_args
1158 * @since 4.09
1159 */
1160 public static function conditional_action_button( $plugin, $upgrade_link_args ) {
1161 if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) {
1162 return FrmProAddonsController::conditional_action_button( $plugin, $upgrade_link_args );
1163 }
1164
1165 $addon = self::get_addon( $plugin );
1166 $upgrade_link = FrmAppHelper::admin_upgrade_link( $upgrade_link_args );
1167 self::addon_upgrade_link( $addon, $upgrade_link );
1168 }
1169
1170 /**
1171 * Render a conditional action button for an add on
1172 *
1173 * @since 4.09.01
1174 * @param array $addon
1175 * @param string|false $license_type
1176 * @param string $plan_required
1177 * @param string $upgrade_link
1178 */
1179 public static function show_conditional_action_button( $atts ) {
1180 if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) {
1181 return FrmProAddonsController::show_conditional_action_button( $atts );
1182 }
1183
1184 self::addon_upgrade_link( $atts['addon'], $atts['upgrade_link'] );
1185 }
1186
1187 /**
1188 * @since 4.09.01
1189 */
1190 protected static function addon_upgrade_link( $addon, $upgrade_link ) {
1191 if ( $addon ) {
1192 $upgrade_link .= '&utm_content=' . $addon['slug'];
1193 }
1194
1195 if ( $addon && isset( $addon['categories'] ) && in_array( 'Solution', $addon['categories'], true ) ) {
1196 // Solutions will go to a separate page.
1197 $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1198 }
1199 ?>
1200 <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' ); ?>">
1201 <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
1202 </a>
1203 <?php
1204 }
1205
1206 /**
1207 * @since 3.04.02
1208 */
1209 public static function ajax_install_addon() {
1210 self::install_addon_permissions();
1211
1212 self::download_and_activate();
1213
1214 echo json_encode( self::get_addon_activation_response() );
1215 wp_die();
1216 }
1217
1218 /**
1219 * @since 4.06.02
1220 * @deprecated 4.09.01
1221 */
1222 public static function ajax_multiple_addons() {
1223 FrmDeprecated::ajax_multiple_addons();
1224 }
1225
1226 /**
1227 * @since 3.04.03
1228 * @deprecated 3.06
1229 * @codeCoverageIgnore
1230 * @return array
1231 */
1232 public static function error_for_license( $license ) {
1233 return FrmDeprecated::error_for_license( $license );
1234 }
1235
1236 /**
1237 * @since 3.04.03
1238 * @deprecated 3.06
1239 * @codeCoverageIgnore
1240 */
1241 public static function get_pro_updater() {
1242 return FrmDeprecated::get_pro_updater();
1243 }
1244
1245 /**
1246 * @since 3.04.03
1247 * @deprecated 3.06
1248 * @codeCoverageIgnore
1249 *
1250 * @return array
1251 */
1252 public static function get_addon_info( $license = '' ) {
1253 return FrmDeprecated::get_addon_info( $license );
1254 }
1255
1256 /**
1257 * @since 3.04.03
1258 * @deprecated 3.06
1259 * @codeCoverageIgnore
1260 *
1261 * @return string
1262 */
1263 public static function get_cache_key( $license ) {
1264 return FrmDeprecated::get_cache_key( $license );
1265 }
1266
1267 /**
1268 * @since 3.04.03
1269 * @deprecated 3.06
1270 * @codeCoverageIgnore
1271 */
1272 public static function reset_cached_addons( $license = '' ) {
1273 FrmDeprecated::reset_cached_addons( $license );
1274 }
1275
1276 /**
1277 * @since 2.03.08
1278 * @deprecated 3.04.03
1279 * @codeCoverageIgnore
1280 *
1281 * @param boolean $return
1282 * @param string $package
1283 *
1284 * @return boolean
1285 */
1286 public static function add_shorten_edd_filename_filter( $return, $package ) {
1287 return FrmDeprecated::add_shorten_edd_filename_filter( $return, $package );
1288 }
1289
1290 /**
1291 * @since 2.03.08
1292 * @deprecated 3.04.03
1293 * @codeCoverageIgnore
1294 *
1295 * @param string $filename
1296 * @param string $ext
1297 *
1298 * @return string
1299 */
1300 public static function shorten_edd_filename( $filename, $ext ) {
1301 return FrmDeprecated::shorten_edd_filename( $filename, $ext );
1302 }
1303
1304 /**
1305 * @deprecated 3.04.03
1306 * @codeCoverageIgnore
1307 */
1308 public static function get_licenses() {
1309 FrmDeprecated::get_licenses();
1310 }
1311 }
1312