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

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