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

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