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

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