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

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

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