PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.15
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.15
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
← All changes | classes/controllers/FrmAddonsController.php +320 -157 6.276.15 View file →
@@ -26,19 +26,17 @@
26 26 protected static $plugin;
27 27
28 28 /**
29 29 * @since 6.15
30 - *
31 - * @return void
32 30 */
33 31 public static function load_admin_hooks() {
34 - add_action( 'admin_menu', self::class . '::menu', 100 );
35 - add_filter( 'pre_set_site_transient_update_plugins', self::class . '::check_update' );
32 + add_action( 'admin_menu', __CLASS__ . '::menu', 100 );
33 + add_filter( 'pre_set_site_transient_update_plugins', __CLASS__ . '::check_update' );
36 34
37 35 if ( FrmAppHelper::is_admin_page( 'formidable-addons' ) ) {
38 36 self::$request_addon_url = 'https://connect.formidableforms.com/add-on-request/';
39 37
40 - add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 );
38 + add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_assets', 15 );
41 39 add_filter( 'frm_show_footer_links', '__return_false' );
42 40 }
43 41 }
44 42
@@ -70,9 +68,8 @@
70 68 // Register and enqueue Add-Ons page script.
71 69 wp_register_script( self::SCRIPT_HANDLE, $plugin_url . '/js/addons-page.js', $js_dependencies, $version, true );
72 70 wp_localize_script( self::SCRIPT_HANDLE, 'frmAddonsVars', self::get_js_variables() );
73 71 wp_enqueue_script( self::SCRIPT_HANDLE );
74 - wp_set_script_translations( self::SCRIPT_HANDLE, 'formidable' );
75 72
76 73 FrmAppHelper::dequeue_extra_global_scripts();
77 74 }
78 75
@@ -98,9 +95,9 @@
98 95 return;
99 96 }
100 97
101 98 $label = __( 'Add-Ons', 'formidable' );
102 - $label = '<span style="color:#3FCA89">' . esc_html( $label ) . '</span>';
99 + $label = '<span style="color:#3FCA89">' . $label . '</span>';
103 100
104 101 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Add-Ons', 'formidable' ), $label, 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );
105 102
106 103 // remove default created subpage, make the page with highest priority as default.
@@ -106,29 +103,20 @@
106 103 // remove default created subpage, make the page with highest priority as default.
107 104 remove_submenu_page( 'formidable', 'formidable' );
108 105
109 106 if ( ! FrmAppHelper::pro_is_installed() ) {
110 - $cta_text = FrmSalesApi::get_best_sale_value( 'menu_cta_text' );
111 -
112 - if ( ! $cta_text ) {
113 - $cta_text = __( 'Upgrade', 'formidable' );
114 - }
115 -
116 107 add_submenu_page(
117 108 'formidable',
118 109 'Formidable | ' . __( 'Upgrade', 'formidable' ),
119 - '<span class="frm-upgrade-submenu">' . esc_html( $cta_text ) . '</span>',
110 + '<span class="frm-upgrade-submenu">' . __( 'Upgrade', 'formidable' ) . '</span>',
120 111 'frm_view_forms',
121 112 'formidable-pro-upgrade',
122 - function () {
123 - // This function doesn't need to do anything.
124 - // The redirect is handled earlier to avoid issues with the headers being sent.
125 - }
113 + 'FrmAddonsController::upgrade_to_pro'
126 114 );
127 115 } elseif ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) ) {
128 116 wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
129 117 exit;
130 - }//end if
118 + }
131 119 }
132 120
133 121 /**
134 122 * @return void
@@ -145,9 +133,9 @@
145 133
146 134 if ( isset( $addons['error'] ) ) {
147 135 $api = new FrmFormApi();
148 136 $errors = $api->get_error_from_response( $addons );
149 - $license_type = $addons['error']['type'] ?? '';
137 + $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : '';
150 138 unset( $addons['error'] );
151 139 }
152 140
153 141 $pro = array(
@@ -198,9 +186,8 @@
198 186 }
199 187 }
200 188
201 189 $special_categories = array();
202 -
203 190 if ( 'elite' !== self::license_type() ) {
204 191 $special_categories['available-addons'] = array(
205 192 'name' => __( 'Available', 'formidable' ),
206 193 // To be assigned via JavaScript.
@@ -232,9 +219,8 @@
232 219 *
233 220 * @since 6.15
234 221 *
235 222 * @param array $addon The addon array that will be modified by reference.
236 - *
237 223 * @return void
238 224 */
239 225 protected static function set_categories( &$addon ) {
240 226 if ( ! isset( $addon['categories'] ) ) {
@@ -265,11 +251,11 @@
265 251 * @return void
266 252 */
267 253 public static function license_settings() {
268 254 $plugins = apply_filters( 'frm_installed_addons', array() );
255 + if ( empty( $plugins ) ) {
256 + esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
269 257
270 - if ( ! $plugins ) {
271 - esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
272 258 return;
273 259 }
274 260
275 261 ksort( $plugins );
@@ -283,9 +269,9 @@
283 269 protected static function get_api_addons() {
284 270 $api = new FrmFormApi();
285 271 $addons = $api->get_api_info();
286 272
287 - if ( ! $addons ) {
273 + if ( empty( $addons ) ) {
288 274 $addons = self::fallback_plugin_list();
289 275 } else {
290 276 foreach ( $addons as $k => $addon ) {
291 277 if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
@@ -305,8 +291,9 @@
305 291 * @return int Count of addons.
306 292 */
307 293 public static function get_addons_count() {
308 294 $addons = self::get_api_addons();
295 +
309 296 return count( $addons );
310 297 }
311 298
312 299 /**
@@ -312,9 +299,8 @@
312 299 /**
313 300 * If the API is unable to connect, show something on the addons page
314 301 *
315 302 * @since 3.04.03
316 - *
317 303 * @return array
318 304 */
319 305 protected static function fallback_plugin_list() {
320 306 $list = array(
@@ -325,19 +311,19 @@
325 311 'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
326 312 ),
327 313 'mailchimp' => array(
328 314 'title' => 'Mailchimp Forms',
329 - '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.', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
315 + '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.',
330 316 ),
331 317 'registration' => array(
332 318 'title' => 'User Registration Forms',
333 319 'link' => 'downloads/user-registration/',
334 - '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.', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
320 + '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.',
335 321 ),
336 322 'paypal' => array(
337 323 'title' => 'PayPal Standard Forms',
338 324 'link' => 'downloads/paypal-standard/',
339 - '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.', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
325 + '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.',
340 326 ),
341 327 'stripe' => array(
342 328 'title' => 'Stripe Forms',
343 329 'docs' => 'knowledgebase/stripe/',
@@ -369,9 +355,9 @@
369 355 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
370 356 ),
371 357 'zapier' => array(
372 358 'title' => 'Zapier Forms',
373 - '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.', // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
359 + '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.',
374 360 ),
375 361 'signature' => array(
376 362 'title' => 'Digital Signature Forms',
377 363 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
@@ -404,9 +390,8 @@
404 390 foreach ( $list as $k => $info ) {
405 391 $info['slug'] = $k;
406 392 $list[ $k ] = array_merge( $defaults, $info );
407 393 }
408 -
409 394 return $list;
410 395 }
411 396
412 397 /**
@@ -412,9 +397,8 @@
412 397 /**
413 398 * If Pro is missing but has been authenticated, include a download URL
414 399 *
415 400 * @since 3.04.03
416 - *
417 401 * @return string
418 402 */
419 403 public static function get_pro_download_url() {
420 404 $license = self::get_pro_license();
@@ -421,20 +405,17 @@
421 405 $api = new FrmFormApi( $license );
422 406 $downloads = $api->get_api_info();
423 407 $pro = self::get_pro_from_addons( $downloads );
424 408
425 - return $pro['url'] ?? '';
409 + return isset( $pro['url'] ) ? $pro['url'] : '';
426 410 }
427 411
428 412 /**
429 413 * @since 4.08
430 - *
431 - * @return string
432 414 */
433 415 public static function get_pro_license() {
434 416 $pro_cred_store = 'frmpro-credentials';
435 417 $pro_wpmu_store = 'frmpro-wpmu-sitewide';
436 -
437 418 if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
438 419 $creds = get_site_option( $pro_cred_store );
439 420 } else {
440 421 $creds = get_option( $pro_cred_store );
@@ -444,18 +425,16 @@
444 425 return '';
445 426 }
446 427
447 428 $license = $creds['license'];
448 -
449 - if ( ! $license ) {
429 + if ( empty( $license ) ) {
450 430 return '';
451 431 }
452 432
453 - if ( str_contains( $license, '-' ) ) {
433 + if ( strpos( $license, '-' ) ) {
454 434 // this is a fix for licenses saved in the past
455 435 $license = strtoupper( $license );
456 436 }
457 -
458 437 return $license;
459 438 }
460 439
461 440 /**
@@ -461,19 +440,16 @@
461 440 /**
462 441 * @since 4.08
463 442 *
464 443 * @param array $addons
465 - *
466 444 * @return array
467 445 */
468 446 protected static function get_pro_from_addons( $addons ) {
469 - return $addons['93790'] ?? array();
447 + return isset( $addons['93790'] ) ? $addons['93790'] : array();
470 448 }
471 449
472 450 /**
473 451 * @since 4.06
474 - *
475 - * @return string
476 452 */
477 453 public static function license_type() {
478 454 if ( is_callable( 'FrmProAddonsController::license_type' ) ) {
479 455 return FrmProAddonsController::license_type();
@@ -488,21 +464,18 @@
488 464 * @return bool
489 465 */
490 466 public static function is_license_expired() {
491 467 $version_info = self::get_primary_license_info();
492 -
493 468 if ( ! isset( $version_info['error'] ) ) {
494 469 return false;
495 470 }
496 471
497 - $expires = $version_info['error']['expires'] ?? 0;
498 -
499 - if ( ! $expires || $expires > time() ) {
472 + $expires = isset( $version_info['error']['expires'] ) ? $version_info['error']['expires'] : 0;
473 + if ( empty( $expires ) || $expires > time() ) {
500 474 return false;
501 475 }
502 476
503 477 $rate_limited = ! empty( $version_info['response_code'] ) && 429 === (int) $version_info['response_code'];
504 -
505 478 if ( $rate_limited ) {
506 479 // Do not return false positives for rate limited responses.
507 480 return false;
508 481 }
@@ -517,13 +490,11 @@
517 490 * @return array|false
518 491 */
519 492 public static function get_primary_license_info() {
520 493 $installed_addons = apply_filters( 'frm_installed_addons', array() );
521 -
522 - if ( ! $installed_addons || ! isset( $installed_addons['formidable_pro'] ) ) {
494 + if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) {
523 495 return false;
524 496 }
525 -
526 497 $installed_addons = array(
527 498 'formidable_pro' => $installed_addons['formidable_pro'],
528 499 );
529 500
@@ -531,12 +502,8 @@
531 502 }
532 503
533 504 /**
534 505 * @since 3.04.03
535 - *
536 - * @param mixed $transient
537 - *
538 - * @return object
539 506 */
540 507 public static function check_update( $transient ) {
541 508 if ( ! FrmAppHelper::pro_is_installed() ) {
542 509 // Don't make any changes if only Lite is installed.
@@ -547,10 +514,9 @@
547 514 $transient = new stdClass();
548 515 }
549 516
550 517 $installed_addons = apply_filters( 'frm_installed_addons', array() );
551 -
552 - if ( ! $installed_addons ) {
518 + if ( empty( $installed_addons ) ) {
553 519 return $transient;
554 520 }
555 521
556 522 $version_info = self::fill_update_addon_info( $installed_addons );
@@ -564,10 +530,9 @@
564 530 continue;
565 531 }
566 532
567 533 $folder = $plugin->plugin;
568 -
569 - if ( ! $folder ) {
534 + if ( empty( $folder ) ) {
570 535 continue;
571 536 }
572 537
573 538 if ( ! self::is_installed( $folder ) ) {
@@ -574,10 +539,10 @@
574 539 // don't show an update if the plugin isn't installed
575 540 continue;
576 541 }
577 542
578 - $wp_plugin = $wp_plugins[ $folder ] ?? array();
579 - $wp_version = $wp_plugin['Version'] ?? '1.0';
543 + $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array();
544 + $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
580 545 $plugin->slug = explode( '/', $folder )[0];
581 546
582 547 if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
583 548 $transient->response[ $folder ] = $plugin;
@@ -597,9 +562,8 @@
597 562 * Because this gets called on "pre_set_site_transient_update_plugins" an old version of FrmAppHelper may be loaded on plugin update.
598 563 * This means that trying to access FrmAppHelper::get_plugins when upgrading from a Lite version before v5.5 results in a one-off error.
599 564 *
600 565 * @since 5.5.2
601 - *
602 566 * @return array
603 567 */
604 568 protected static function get_plugins() {
605 569 if ( ! function_exists( 'get_plugins' ) ) {
@@ -639,16 +603,15 @@
639 603 continue;
640 604 }
641 605
642 606 $new_license = $addon->license;
643 -
644 - if ( ! $new_license || in_array( $new_license, $checked_licenses, true ) ) {
607 + if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) {
645 608 continue;
646 609 }
647 610
648 611 $checked_licenses[] = $new_license;
649 - $api = new FrmFormApi( $new_license );
650 612
613 + $api = new FrmFormApi( $new_license );
651 614 if ( empty( $version_info ) ) {
652 615 $version_info = $api->get_api_info();
653 616 continue;
654 617 }
@@ -653,21 +616,18 @@
653 616 continue;
654 617 }
655 618
656 619 $plugin = $api->get_addon_for_license( $addon, $version_info );
657 -
658 - if ( ! $plugin ) {
620 + if ( empty( $plugin ) ) {
659 621 continue;
660 622 }
661 623
662 - $download_id = $plugin['id'] ?? 0;
663 -
664 - if ( $download_id && ! isset( $version_info[ $download_id ]['package'] ) ) {
624 + $download_id = isset( $plugin['id'] ) ? $plugin['id'] : 0;
625 + if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) {
665 626 // if this addon is using its own license, get the update url
666 627 $addon_info = $api->get_api_info();
667 628
668 629 $version_info[ $download_id ] = $addon_info[ $download_id ];
669 -
670 630 if ( isset( $addon_info['error'] ) ) {
671 631 $version_info[ $download_id ]['error'] = array(
672 632 'message' => $addon_info['error']['message'],
673 633 'code' => $addon_info['error']['code'],
@@ -682,11 +642,9 @@
682 642 /**
683 643 * Get the action link for an addon that isn't active.
684 644 *
685 645 * @since 3.06.03
686 - *
687 646 * @param string $plugin The plugin slug.
688 - *
689 647 * @return array
690 648 */
691 649 public static function install_link( $plugin ) {
692 650 $link = array();
@@ -708,9 +666,9 @@
708 666 'categories' => $addon['categories'],
709 667 );
710 668 }
711 669
712 - if ( $link ) {
670 + if ( ! empty( $link ) ) {
713 671 $link['status'] = $addon['status']['type'];
714 672 }
715 673 } elseif ( current_user_can( 'activate_plugins' ) && self::is_installed( 'formidable-' . $plugin . '/formidable-' . $plugin . '.php' ) ) {
716 674 $link = array(
@@ -723,41 +681,33 @@
723 681 }
724 682
725 683 /**
726 684 * @since 4.09
727 - *
728 685 * @param string $plugin The plugin slug.
729 - *
730 686 * @return array|false
731 687 */
732 688 public static function get_addon( $plugin ) {
733 689 $addons = self::get_api_addons();
734 690 self::prepare_addons( $addons );
735 -
736 691 foreach ( $addons as $addon ) {
737 692 $slug = explode( '/', $addon['plugin'] );
738 -
739 693 if ( $slug[0] === 'formidable-' . $plugin ) {
740 694 return $addon;
741 695 }
742 696 }
743 -
744 697 return false;
745 698 }
746 699
747 700 /**
748 701 * @since 4.09
749 - *
750 702 * @return string
751 703 */
752 704 protected static function get_license_type() {
753 705 $license_type = '';
754 706 $addons = self::get_api_addons();
755 -
756 707 if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) {
757 708 $license_type = $addons['error']['type'];
758 709 }
759 -
760 710 return $license_type;
761 711 }
762 712
763 713 /**
@@ -770,10 +720,9 @@
770 720 */
771 721 public static function get_addon_for_license( $addons, $license ) {
772 722 $download_id = $license->download_id;
773 723 $plugin = array();
774 -
775 - if ( ! $download_id && ! empty( $addons ) ) {
724 + if ( empty( $download_id ) && ! empty( $addons ) ) {
776 725 foreach ( $addons as $addon ) {
777 726 if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) {
778 727 return $addon;
779 728 }
@@ -785,33 +734,29 @@
785 734 return $plugin;
786 735 }
787 736
788 737 /**
789 - * @param array $addons
790 - *
791 738 * @return void
792 739 */
793 740 protected static function prepare_addons( &$addons ) {
794 - // Reset categories to prevent count accumulation across multiple calls.
795 - self::$categories = array();
796 -
797 741 $activate_url = '';
798 -
799 742 if ( current_user_can( 'activate_plugins' ) ) {
800 743 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
801 744 }
802 745
803 746 $loop_addons = $addons;
804 -
805 747 foreach ( $loop_addons as $id => $addon ) {
806 748 if ( is_numeric( $id ) ) {
807 749 $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
808 750 $file_name = $addon['plugin'];
809 751 } else {
810 - $slug = $id;
811 - $base_file = $addon['file'] ?? 'formidable-' . $slug;
752 + $slug = $id;
753 + if ( isset( $addon['file'] ) ) {
754 + $base_file = $addon['file'];
755 + } else {
756 + $base_file = 'formidable-' . $slug;
757 + }
812 758 $file_name = $base_file . '/' . $base_file . '.php';
813 -
814 759 if ( ! isset( $addon['plugin'] ) ) {
815 760 $addon['plugin'] = $file_name;
816 761 }
817 762 }
@@ -816,12 +761,10 @@
816 761 }
817 762 }
818 763
819 764 $addon['installed'] = self::is_installed( $file_name );
820 -
821 765 if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) {
822 766 $active_views_version = self::get_active_views_version();
823 -
824 767 if ( false !== $active_views_version && $slug !== $active_views_version ) {
825 768 $addon['installed'] = false;
826 769 }
827 770 }
@@ -827,9 +770,9 @@
827 770 }
828 771
829 772 $addon['activate_url'] = '';
830 773
831 - if ( $addon['installed'] && $activate_url && ! self::is_plugin_active( $file_name, $slug ) ) {
774 + if ( $addon['installed'] && ! empty( $activate_url ) && ! self::is_plugin_active( $file_name, $slug ) ) {
832 775 $addon['activate_url'] = add_query_arg(
833 776 array(
834 777 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
835 778 'plugin' => $file_name,
@@ -855,11 +798,8 @@
855 798 }//end foreach
856 799 }
857 800
858 801 /**
859 - * @param string $file_name
860 - * @param string $slug
861 - *
862 802 * @return bool
863 803 */
864 804 private static function is_plugin_active( $file_name, $slug ) {
865 805 if ( 'formidable-views/formidable-views.php' === $file_name ) {
@@ -874,9 +814,8 @@
874 814 private static function get_active_views_version() {
875 815 if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) {
876 816 return false;
877 817 }
878 -
879 818 $plugin_version = FrmViewsAppHelper::plugin_version();
880 819 return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views';
881 820 }
882 821
@@ -882,25 +821,22 @@
882 821
883 822 /**
884 823 * @since 3.04.02
885 824 *
886 - * @param string $link
887 - *
888 825 * @return void
889 826 */
890 827 protected static function prepare_addon_link( &$link ) {
891 828 $site_url = 'https://formidableforms.com/';
892 -
893 - if ( ! str_starts_with( $link, 'http' ) ) {
829 + if ( strpos( $link, 'http' ) !== 0 ) {
894 830 $link = $site_url . $link;
895 831 }
896 -
897 - $link = FrmAppHelper::make_affiliate_url( $link );
898 -
899 - $utm = array(
900 - 'campaign' => 'addons',
832 + $link = FrmAppHelper::make_affiliate_url( $link );
833 + $query_args = array(
834 + 'utm_source' => 'WordPress',
835 + 'utm_medium' => 'addons',
836 + 'utm_campaign' => 'liteplugin',
901 837 );
902 - $link = FrmAppHelper::maybe_add_missing_utm( $link, $utm );
838 + $link = add_query_arg( $query_args, $link );
903 839 }
904 840
905 841 /**
906 842 * Add the status to the addon array. Status options are:
@@ -907,10 +843,8 @@
907 843 * installed, active, not installed
908 844 *
909 845 * @since 3.04.02
910 846 *
911 - * @param array $addon
912 - *
913 847 * @return void
914 848 */
915 849 protected static function set_addon_status( &$addon ) {
916 850 if ( ! empty( $addon['activate_url'] ) ) {
@@ -931,8 +865,218 @@
931 865 }
932 866 }
933 867
934 868 /**
869 + * @return void
870 + */
871 + public static function upgrade_to_pro() {
872 + FrmAppHelper::include_svg();
873 +
874 + $link_parts = array(
875 + 'medium' => 'upgrade',
876 + 'content' => 'button',
877 + );
878 +
879 + $features = array(
880 + 'Display Entries' => array(
881 + array(
882 + 'label' => 'Display form data with virtually limitless views',
883 + 'link' => array(
884 + 'content' => 'views',
885 + 'param' => 'views-display-form-data',
886 + ),
887 + 'lite' => false,
888 + ),
889 + array(
890 + 'label' => 'Generate graphs and stats based on your submitted data',
891 + 'link' => array(
892 + 'content' => 'graphs',
893 + 'param' => 'statistics-graphs-wordpress-forms',
894 + ),
895 + 'lite' => false,
896 + ),
897 + ),
898 + 'Entry Management' => array(
899 + array(
900 + 'label' => 'Import entries from a CSV',
901 + 'link' => array(
902 + 'content' => 'import-entries',
903 + 'param' => 'importing-exporting-wordpress-forms',
904 + ),
905 + 'lite' => false,
906 + ),
907 + array(
908 + 'label' => 'Logged-in users can save drafts and return later',
909 + 'link' => array(
910 + 'content' => 'save-drafts',
911 + 'param' => 'save-drafts-wordpress-form',
912 + ),
913 + 'lite' => false,
914 + ),
915 + array(
916 + 'label' => 'Flexibly and powerfully view, edit, and delete entries from anywhere on your site',
917 + 'link' => array(
918 + 'content' => 'front-edit',
919 + 'param' => 'wordpress-front-end-editing',
920 + ),
921 + 'lite' => false,
922 + ),
923 + array(
924 + 'label' => 'View form submissions from the back-end',
925 + 'lite' => true,
926 + ),
927 + array(
928 + 'label' => 'Export your entries to a CSV',
929 + 'lite' => true,
930 + ),
931 + ),
932 + 'Form Building' => array(
933 + array(
934 + 'label' => 'Save a calculated value into a field',
935 + 'link' => array(
936 + 'content' => 'calculations',
937 + 'param' => 'field-calculations-wordpress-form',
938 + ),
939 + 'lite' => false,
940 + ),
941 + array(
942 + 'label' => 'Allow multiple file uploads',
943 + 'link' => array(
944 + 'content' => 'file-uploads',
945 + 'param' => 'wordpress-multi-file-upload-fields',
946 + ),
947 + 'lite' => false,
948 + ),
949 + array(
950 + 'label' => 'Repeat sections of fields',
951 + 'link' => array(
952 + 'content' => 'repeaters',
953 + 'param' => 'repeatable-sections-forms',
954 + ),
955 + 'lite' => false,
956 + ),
957 + array(
958 + 'label' => 'Hide and show fields conditionally based on other fields or the user\'s role',
959 + 'link' => array(
960 + 'content' => 'conditional-logic',
961 + 'param' => 'conditional-logic-wordpress-forms',
962 + ),
963 + 'lite' => false,
964 + ),
965 + array(
966 + 'label' => 'Confirmation fields',
967 + 'link' => array(
968 + 'content' => 'confirmation-fields',
969 + 'param' => 'confirmation-fields-wordpress-forms',
970 + ),
971 + 'lite' => false,
972 + ),
973 + array(
974 + 'label' => 'Multi-paged forms',
975 + 'link' => array(
976 + 'content' => 'page-breaks',
977 + 'param' => 'wordpress-multi-page-forms',
978 + ),
979 + 'lite' => false,
980 + ),
981 + array(
982 + '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.',
983 + 'lite' => false,
984 + ),
985 + array(
986 + 'label' => 'Include text, email, url, paragraph text, radio, checkbox, dropdown fields, hidden fields, user ID fields, and HTML blocks in your form.',
987 + 'lite' => true,
988 + ),
989 + array(
990 + 'label' => 'Drag & Drop Form building',
991 + 'link' => array(
992 + 'content' => 'drag-drop',
993 + 'param' => 'drag-drop-forms',
994 + ),
995 + 'lite' => true,
996 + ),
997 + array(
998 + 'label' => 'Create forms from Templates',
999 + 'link' => array(
1000 + 'content' => 'form-templates',
1001 + 'param' => 'wordpress-form-templates',
1002 + ),
1003 + 'lite' => true,
1004 + ),
1005 + array(
1006 + 'label' => 'Import and export forms with XML',
1007 + 'link' => array(
1008 + 'content' => 'import',
1009 + 'param' => 'importing-exporting-wordpress-forms',
1010 + ),
1011 + 'lite' => true,
1012 + ),
1013 + array(
1014 + 'label' => 'Use input placeholder text in your fields that clear when typing starts.',
1015 + 'lite' => true,
1016 + ),
1017 + ),
1018 + 'Form Actions' => array(
1019 + array(
1020 + 'label' => 'Conditionally send your email notifications based on values in your form',
1021 + 'link' => array(
1022 + 'content' => 'conditional-emails',
1023 + ),
1024 + 'lite' => false,
1025 + ),
1026 + array(
1027 + 'label' => 'Create and edit WordPress posts or custom posts from the front-end',
1028 + 'link' => array(
1029 + 'content' => 'create-posts',
1030 + 'param' => 'create-posts-pages-wordpress-forms',
1031 + ),
1032 + 'lite' => false,
1033 + ),
1034 + array(
1035 + 'label' => 'Send multiple emails and autoresponders',
1036 + 'link' => array(
1037 + 'content' => 'multiple-emails',
1038 + 'param' => 'virtually-unlimited-emails',
1039 + ),
1040 + 'lite' => true,
1041 + ),
1042 + ),
1043 + 'Form Appearance' => array(
1044 + array(
1045 + 'label' => 'Create Multiple styles for different forms',
1046 + 'link' => array(
1047 + 'content' => 'multiple-styles',
1048 + 'param' => 'wordpress-visual-form-styler',
1049 + ),
1050 + 'lite' => false,
1051 + ),
1052 + array(
1053 + 'label' => 'Customizable layout with CSS classes',
1054 + 'link' => array(
1055 + 'content' => 'form-layout',
1056 + 'param' => 'wordpress-mobile-friendly-forms',
1057 + ),
1058 + 'lite' => true,
1059 + ),
1060 + array(
1061 + 'label' => 'Customize the HTML for your forms',
1062 + 'link' => array(
1063 + 'content' => 'custom-html',
1064 + 'param' => 'customizable-html-wordpress-form',
1065 + ),
1066 + 'lite' => true,
1067 + ),
1068 + array(
1069 + 'label' => 'Style your form with the Visual Form Styler',
1070 + 'lite' => true,
1071 + ),
1072 + ),
1073 + );
1074 +
1075 + include FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php';
1076 + }
1077 +
1078 + /**
935 1079 * @since 5.5.2
936 1080 *
937 1081 * @param string $plugin
938 1082 * @param string $redirect
@@ -937,9 +1081,8 @@
937 1081 * @param string $plugin
938 1082 * @param string $redirect
939 1083 * @param bool $network_wide
940 1084 * @param bool $silent
941 - *
942 1085 * @return WP_Error|null Null on success, WP_Error on invalid file.
943 1086 */
944 1087 protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
945 1088 if ( ! function_exists( 'activate_plugin' ) ) {
@@ -954,9 +1097,8 @@
954 1097 * @since 6.8
955 1098 *
956 1099 * @param string $plugin
957 1100 * @param bool $silent
958 - *
959 1101 * @return void
960 1102 */
961 1103 protected static function deactivate_plugin( $plugin, $silent = false ) {
962 1104 if ( ! function_exists( 'deactivate_plugins' ) ) {
@@ -970,9 +1112,8 @@
970 1112 *
971 1113 * @since 6.8
972 1114 *
973 1115 * @param string $plugin
974 - *
975 1116 * @return true|WP_Error True on success, WP_Error on invalid file.
976 1117 */
977 1118 protected static function uninstall_plugin( $plugin ) {
978 1119 if ( ! current_user_can( 'delete_plugins' ) ) {
@@ -985,9 +1126,13 @@
985 1126
986 1127 self::deactivate_plugin( $plugin, true );
987 1128 $result = delete_plugins( array( $plugin ) );
988 1129
989 - return is_wp_error( $result ) ? $result : true;
1130 + if ( is_wp_error( $result ) ) {
1131 + return $result;
1132 + }
1133 +
1134 + return true;
990 1135 }
991 1136
992 1137 /**
993 1138 * @since 5.0.10
@@ -1003,9 +1148,9 @@
1003 1148
1004 1149 /**
1005 1150 * @since 4.08
1006 1151 *
1007 - * @return mixed[]|null
1152 + * @return array|void
1008 1153 */
1009 1154 protected static function download_and_activate() {
1010 1155 if ( is_admin() ) {
1011 1156 FrmAppHelper::set_current_screen_and_hook_suffix();
@@ -1013,14 +1158,12 @@
1013 1158
1014 1159 self::maybe_show_cred_form();
1015 1160
1016 1161 $installed = self::install_addon();
1017 -
1018 1162 if ( is_array( $installed ) && isset( $installed['message'] ) ) {
1019 1163 return $installed;
1020 1164 }
1021 1165 self::handle_addon_action( $installed, 'activate' );
1022 - return null;
1023 1166 }
1024 1167
1025 1168 /**
1026 1169 * @since 3.04.02
@@ -1031,9 +1174,9 @@
1031 1174 if ( ! function_exists( 'request_filesystem_credentials' ) ) {
1032 1175 include_once ABSPATH . 'wp-admin/includes/file.php';
1033 1176 }
1034 1177
1035 - // Start output buffering to catch the filesystem form if credentials are needed.
1178 + // Start output bufferring to catch the filesystem form if credentials are needed.
1036 1179 ob_start();
1037 1180
1038 1181 $show_form = false;
1039 1182 $method = '';
@@ -1050,8 +1193,9 @@
1050 1193
1051 1194 if ( $show_form ) {
1052 1195 $form = ob_get_clean();
1053 1196 $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' );
1197 + $data = $form;
1054 1198 $response = array(
1055 1199 'success' => false,
1056 1200 'message' => $message,
1057 1201 'form' => $form,
@@ -1079,10 +1223,8 @@
1079 1223 * We do not need any extra credentials if we have gotten this far,
1080 1224 * so let's install the plugin.
1081 1225 *
1082 1226 * @since 3.04.02
1083 - *
1084 - * @return array|string
1085 1227 */
1086 1228 protected static function install_addon() {
1087 1229 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1088 1230
@@ -1102,9 +1244,8 @@
1102 1244 // Flush the cache and return the newly installed plugin basename.
1103 1245 wp_cache_flush();
1104 1246
1105 1247 $plugin = $installer->plugin_info();
1106 -
1107 1248 if ( ! $plugin ) {
1108 1249 return array(
1109 1250 'message' => 'Plugin was not installed. ' . $installer->result,
1110 1251 'success' => false,
@@ -1109,9 +1250,8 @@
1109 1250 'message' => 'Plugin was not installed. ' . $installer->result,
1110 1251 'success' => false,
1111 1252 );
1112 1253 }
1113 -
1114 1254 return $plugin;
1115 1255 }
1116 1256
1117 1257 /**
@@ -1175,9 +1315,8 @@
1175 1315 * @since 6.8
1176 1316 *
1177 1317 * @param callable $action_callback The specific add-on action to be executed.
1178 1318 * @param callable|null $response_callback Optional. The response handling callback. Default null.
1179 - *
1180 1319 * @return void
1181 1320 */
1182 1321 private static function process_addon_action( $action_callback, $response_callback = null ) {
1183 1322 self::install_addon_permissions();
@@ -1200,14 +1339,13 @@
1200 1339 * @since 6.8
1201 1340 *
1202 1341 * @param string $installed The plugin folder name with file name.
1203 1342 * @param string $action The action type ('activate', 'deactivate', 'uninstall').
1204 - *
1205 - * @return mixed[]|null
1343 + * @return array|void
1206 1344 */
1207 1345 protected static function handle_addon_action( $installed, $action ) {
1208 1346 if ( ! $installed || ! $action ) {
1209 - return null;
1347 + return;
1210 1348 }
1211 1349
1212 1350 $result = null;
1213 1351 switch ( $action ) {
@@ -1227,9 +1365,8 @@
1227 1365 if ( $result->get_error_code() !== 'no_plugin_header' ) {
1228 1366 if ( wp_doing_ajax() ) {
1229 1367 wp_send_json_error( array( 'error' => $result->get_error_message() ) );
1230 1368 }
1231 -
1232 1369 return array(
1233 1370 'message' => $result->get_error_message(),
1234 1371 'success' => false,
1235 1372 );
@@ -1243,14 +1380,17 @@
1243 1380 * @return array
1244 1381 */
1245 1382 private static function get_addon_activation_response() {
1246 1383 $activating_page = self::get_activating_page();
1247 - $message = $activating_page ? __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ) : __( 'Your plugin has been activated.', 'formidable' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1248 1384
1249 - return array(
1385 + $message = $activating_page ? __( 'Your plugin has been activated. Would you like to save and reload the page now?', 'formidable' ) : __( 'Your plugin has been activated.', 'formidable' );
1386 +
1387 + $response = array(
1250 1388 'message' => $message,
1251 1389 'saveAndReload' => $activating_page,
1252 1390 );
1391 +
1392 + return $response;
1253 1393 }
1254 1394
1255 1395 /**
1256 1396 * Return a string that reflects the page from which the addon is being activated on,
@@ -1259,14 +1399,17 @@
1259 1399 * @return string
1260 1400 */
1261 1401 private static function get_activating_page() {
1262 1402 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1403 + if ( false !== strpos( $referer, 'frm_action=settings' ) ) {
1404 + return 'settings';
1405 + }
1263 1406
1264 - if ( str_contains( $referer, 'frm_action=settings' ) ) {
1265 - return 'settings';
1407 + if ( false !== strpos( $referer, 'frm_action=edit' ) ) {
1408 + return 'form_builder';
1266 1409 }
1267 1410
1268 - return str_contains( $referer, 'frm_action=edit' ) ? 'form_builder' : '';
1411 + return '';
1269 1412 }
1270 1413
1271 1414 /**
1272 1415 * Run security checks before installing
@@ -1290,14 +1433,12 @@
1290 1433 * @return string
1291 1434 */
1292 1435 public static function connect_link() {
1293 1436 $auth = get_option( 'frm_connect_token' );
1294 -
1295 - if ( ! $auth ) {
1437 + if ( empty( $auth ) ) {
1296 1438 $auth = hash( 'sha512', wp_rand() );
1297 1439 update_option( 'frm_connect_token', $auth, 'no' );
1298 1440 }
1299 -
1300 1441 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title', 'formidable-settings' );
1301 1442 $link = 'https://formidableforms.com/api-connect/';
1302 1443 $args = array(
1303 1444 'v' => 2,
@@ -1325,10 +1466,9 @@
1325 1466 $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' );
1326 1467
1327 1468 // The download link is not required if already installed.
1328 1469 $is_installed = FrmAppHelper::pro_is_included();
1329 - $file_missing = ! $is_installed && ! $post_url;
1330 -
1470 + $file_missing = ! $is_installed && empty( $post_url );
1331 1471 if ( ! $post_auth || $file_missing ) {
1332 1472 return false;
1333 1473 }
1334 1474
@@ -1333,9 +1473,13 @@
1333 1473 }
1334 1474
1335 1475 // Verify auth.
1336 1476 $auth = get_option( 'frm_connect_token' );
1337 - return $auth && hash_equals( $auth, $post_auth );
1477 + if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) {
1478 + return false;
1479 + }
1480 +
1481 + return true;
1338 1482 }
1339 1483
1340 1484 /**
1341 1485 * Install and/or activate the add-on file.
@@ -1346,17 +1490,17 @@
1346 1490 */
1347 1491 public static function install_addon_api() {
1348 1492 self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1349 1493
1494 + $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' );
1495 +
1350 1496 // Delete so cannot replay.
1351 1497 delete_option( 'frm_connect_token' );
1352 1498
1353 1499 // It's already installed and active.
1354 1500 $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1355 -
1356 1501 if ( is_wp_error( $active ) ) {
1357 1502 $response = self::maybe_download_and_activate();
1358 -
1359 1503 if ( is_array( $response ) ) {
1360 1504 // The download failed.
1361 1505 return $response;
1362 1506 }
@@ -1365,9 +1509,8 @@
1365 1509 // If empty license, save it now.
1366 1510 if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) {
1367 1511 load_formidable_pro();
1368 1512 $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) );
1369 -
1370 1513 if ( ! $license ) {
1371 1514 return array(
1372 1515 'success' => false,
1373 1516 'error' => 'That site does not have a valid license key.',
@@ -1374,9 +1517,8 @@
1374 1517 );
1375 1518 }
1376 1519
1377 1520 $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' );
1378 -
1379 1521 if ( ! $response['success'] ) {
1380 1522 // Could not activate license.
1381 1523 return $response;
1382 1524 }
@@ -1401,9 +1543,8 @@
1401 1543 }
1402 1544
1403 1545 // Download plugin now.
1404 1546 $response = self::download_and_activate();
1405 -
1406 1547 if ( is_array( $response ) && isset( $response['success'] ) ) {
1407 1548 // The download failed.
1408 1549 return $response;
1409 1550 }
@@ -1417,9 +1558,8 @@
1417 1558 * @since 4.09
1418 1559 *
1419 1560 * @param string $plugin
1420 1561 * @param array|string $upgrade_link_args
1421 - *
1422 1562 * @return void
1423 1563 */
1424 1564 public static function conditional_action_button( $plugin, $upgrade_link_args ) {
1425 1565 if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) {
@@ -1454,9 +1594,8 @@
1454 1594 * @type false|string $license_type
1455 1595 * @type string $plan_required
1456 1596 * @type string $upgrade_link
1457 1597 * }
1458 - *
1459 1598 * @return void
1460 1599 */
1461 1600 public static function show_conditional_action_button( $atts ) {
1462 1601 if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) {
@@ -1477,9 +1616,8 @@
1477 1616 */
1478 1617 public static function addon_upgrade_link( $addon, $upgrade_link ) {
1479 1618 $atts = is_array( $upgrade_link ) ? $upgrade_link : array();
1480 1619 $upgrade_link = is_array( $upgrade_link ) ? $upgrade_link['link'] : $upgrade_link;
1481 - $text = ! empty( $atts['text'] ) ? $atts['text'] : __( 'Upgrade Now', 'formidable' );
1482 1620
1483 1621 if ( $addon ) {
1484 1622 $upgrade_link .= '&utm_content=' . $addon['slug'];
1485 1623 }
@@ -1489,15 +1627,14 @@
1489 1627 $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1490 1628 }
1491 1629
1492 1630 $class = ! empty( $atts['class'] ) ? $atts['class'] : '';
1493 -
1494 - if ( ! str_contains( $class, 'frm-button' ) ) {
1631 + if ( strpos( $class, 'frm-button' ) === false ) {
1495 1632 $class .= ' frm-button-secondary frm-button-sm';
1496 1633 }
1497 1634 ?>
1498 - <a class="install-now button <?php echo esc_attr( $class ); ?>" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
1499 - <?php echo esc_html( $text ); ?>
1635 + <a class="install-now button <?php echo esc_attr( $class ); ?>" href="<?php echo esc_url( $upgrade_link ); ?>" target="_blank" rel="noopener" aria-label="<?php esc_attr_e( 'Upgrade Now', 'formidable' ); ?>">
1636 + <?php esc_html_e( 'Upgrade Now', 'formidable' ); ?>
1500 1637 </a>
1501 1638 <?php
1502 1639 }
1503 1640
@@ -1509,9 +1646,8 @@
1509 1646 public static function ajax_install_addon() {
1510 1647 self::install_addon_permissions();
1511 1648
1512 1649 $result = self::download_and_activate();
1513 -
1514 1650 if ( isset( $result['success'] ) && ! $result['success'] ) {
1515 1651 echo json_encode( $result );
1516 1652 wp_die();
1517 1653 }
@@ -1544,8 +1680,9 @@
1544 1680 $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list );
1545 1681
1546 1682 if ( ! is_array( $allowed_url_list ) ) {
1547 1683 _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' );
1684 +
1548 1685 return array();
1549 1686 }
1550 1687
1551 1688 return $allowed_url_list;
@@ -1555,10 +1692,8 @@
1555 1692 * Gets required plan for an addon.
1556 1693 *
1557 1694 * @since 6.4.2
1558 1695 *
1559 - * @param int|string $addon_id
1560 - *
1561 1696 * @return string Empty string if no plan is required for active license.
1562 1697 */
1563 1698 public static function get_addon_required_plan( $addon_id ) {
1564 1699 $api = new FrmFormApi();
@@ -1573,6 +1708,34 @@
1573 1708 $requires = '';
1574 1709 }
1575 1710
1576 1711 return $requires;
1712 + }
1713 +
1714 + /**
1715 + * @since 4.02.05
1716 + * @deprecated 6.8.3
1717 + *
1718 + * @codeCoverageIgnore
1719 + *
1720 + * @return void
1721 + */
1722 + public static function connect_pro() {
1723 + _deprecated_function( __METHOD__, '6.8.3' );
1724 + }
1725 +
1726 + /**
1727 + * @since 4.08
1728 + * @deprecated 6.11.1
1729 + *
1730 + * @return bool|int false or the number of days until expiration.
1731 + */
1732 + public static function is_license_expiring() {
1733 + _deprecated_function( __METHOD__, '6.11.1', 'FrmProAddonsController::is_license_expiring' );
1734 +
1735 + if ( is_callable( 'FrmProAddonsController::is_license_expiring' ) ) {
1736 + return FrmProAddonsController::is_license_expiring();
1737 + }
1738 +
1739 + return false;
1577 1740 }
1578 1741 }