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

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