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

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