PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.21.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.21.1
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 +77 -142 6.276.21.1 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
@@ -107,9 +105,8 @@
107 105 remove_submenu_page( 'formidable', 'formidable' );
108 106
109 107 if ( ! FrmAppHelper::pro_is_installed() ) {
110 108 $cta_text = FrmSalesApi::get_best_sale_value( 'menu_cta_text' );
111 -
112 109 if ( ! $cta_text ) {
113 110 $cta_text = __( 'Upgrade', 'formidable' );
114 111 }
115 112
@@ -145,9 +142,9 @@
145 142
146 143 if ( isset( $addons['error'] ) ) {
147 144 $api = new FrmFormApi();
148 145 $errors = $api->get_error_from_response( $addons );
149 - $license_type = $addons['error']['type'] ?? '';
146 + $license_type = isset( $addons['error']['type'] ) ? $addons['error']['type'] : '';
150 147 unset( $addons['error'] );
151 148 }
152 149
153 150 $pro = array(
@@ -198,9 +195,8 @@
198 195 }
199 196 }
200 197
201 198 $special_categories = array();
202 -
203 199 if ( 'elite' !== self::license_type() ) {
204 200 $special_categories['available-addons'] = array(
205 201 'name' => __( 'Available', 'formidable' ),
206 202 // To be assigned via JavaScript.
@@ -232,9 +228,8 @@
232 228 *
233 229 * @since 6.15
234 230 *
235 231 * @param array $addon The addon array that will be modified by reference.
236 - *
237 232 * @return void
238 233 */
239 234 protected static function set_categories( &$addon ) {
240 235 if ( ! isset( $addon['categories'] ) ) {
@@ -265,11 +260,11 @@
265 260 * @return void
266 261 */
267 262 public static function license_settings() {
268 263 $plugins = apply_filters( 'frm_installed_addons', array() );
264 + if ( empty( $plugins ) ) {
265 + esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
269 266
270 - if ( ! $plugins ) {
271 - esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
272 267 return;
273 268 }
274 269
275 270 ksort( $plugins );
@@ -283,9 +278,9 @@
283 278 protected static function get_api_addons() {
284 279 $api = new FrmFormApi();
285 280 $addons = $api->get_api_info();
286 281
287 - if ( ! $addons ) {
282 + if ( empty( $addons ) ) {
288 283 $addons = self::fallback_plugin_list();
289 284 } else {
290 285 foreach ( $addons as $k => $addon ) {
291 286 if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
@@ -305,8 +300,9 @@
305 300 * @return int Count of addons.
306 301 */
307 302 public static function get_addons_count() {
308 303 $addons = self::get_api_addons();
304 +
309 305 return count( $addons );
310 306 }
311 307
312 308 /**
@@ -312,9 +308,8 @@
312 308 /**
313 309 * If the API is unable to connect, show something on the addons page
314 310 *
315 311 * @since 3.04.03
316 - *
317 312 * @return array
318 313 */
319 314 protected static function fallback_plugin_list() {
320 315 $list = array(
@@ -325,19 +320,19 @@
325 320 '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 321 ),
327 322 'mailchimp' => array(
328 323 '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
324 + '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 325 ),
331 326 'registration' => array(
332 327 'title' => 'User Registration Forms',
333 328 '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
329 + '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 330 ),
336 331 'paypal' => array(
337 332 'title' => 'PayPal Standard Forms',
338 333 '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
334 + '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 335 ),
341 336 'stripe' => array(
342 337 'title' => 'Stripe Forms',
343 338 'docs' => 'knowledgebase/stripe/',
@@ -369,9 +364,9 @@
369 364 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
370 365 ),
371 366 'zapier' => array(
372 367 '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
368 + '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 369 ),
375 370 'signature' => array(
376 371 'title' => 'Digital Signature Forms',
377 372 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
@@ -404,9 +399,8 @@
404 399 foreach ( $list as $k => $info ) {
405 400 $info['slug'] = $k;
406 401 $list[ $k ] = array_merge( $defaults, $info );
407 402 }
408 -
409 403 return $list;
410 404 }
411 405
412 406 /**
@@ -412,9 +406,8 @@
412 406 /**
413 407 * If Pro is missing but has been authenticated, include a download URL
414 408 *
415 409 * @since 3.04.03
416 - *
417 410 * @return string
418 411 */
419 412 public static function get_pro_download_url() {
420 413 $license = self::get_pro_license();
@@ -421,20 +414,17 @@
421 414 $api = new FrmFormApi( $license );
422 415 $downloads = $api->get_api_info();
423 416 $pro = self::get_pro_from_addons( $downloads );
424 417
425 - return $pro['url'] ?? '';
418 + return isset( $pro['url'] ) ? $pro['url'] : '';
426 419 }
427 420
428 421 /**
429 422 * @since 4.08
430 - *
431 - * @return string
432 423 */
433 424 public static function get_pro_license() {
434 425 $pro_cred_store = 'frmpro-credentials';
435 426 $pro_wpmu_store = 'frmpro-wpmu-sitewide';
436 -
437 427 if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
438 428 $creds = get_site_option( $pro_cred_store );
439 429 } else {
440 430 $creds = get_option( $pro_cred_store );
@@ -444,18 +434,16 @@
444 434 return '';
445 435 }
446 436
447 437 $license = $creds['license'];
448 -
449 - if ( ! $license ) {
438 + if ( empty( $license ) ) {
450 439 return '';
451 440 }
452 441
453 - if ( str_contains( $license, '-' ) ) {
442 + if ( strpos( $license, '-' ) ) {
454 443 // this is a fix for licenses saved in the past
455 444 $license = strtoupper( $license );
456 445 }
457 -
458 446 return $license;
459 447 }
460 448
461 449 /**
@@ -461,19 +449,16 @@
461 449 /**
462 450 * @since 4.08
463 451 *
464 452 * @param array $addons
465 - *
466 453 * @return array
467 454 */
468 455 protected static function get_pro_from_addons( $addons ) {
469 - return $addons['93790'] ?? array();
456 + return isset( $addons['93790'] ) ? $addons['93790'] : array();
470 457 }
471 458
472 459 /**
473 460 * @since 4.06
474 - *
475 - * @return string
476 461 */
477 462 public static function license_type() {
478 463 if ( is_callable( 'FrmProAddonsController::license_type' ) ) {
479 464 return FrmProAddonsController::license_type();
@@ -488,21 +473,18 @@
488 473 * @return bool
489 474 */
490 475 public static function is_license_expired() {
491 476 $version_info = self::get_primary_license_info();
492 -
493 477 if ( ! isset( $version_info['error'] ) ) {
494 478 return false;
495 479 }
496 480
497 - $expires = $version_info['error']['expires'] ?? 0;
498 -
499 - if ( ! $expires || $expires > time() ) {
481 + $expires = isset( $version_info['error']['expires'] ) ? $version_info['error']['expires'] : 0;
482 + if ( empty( $expires ) || $expires > time() ) {
500 483 return false;
501 484 }
502 485
503 486 $rate_limited = ! empty( $version_info['response_code'] ) && 429 === (int) $version_info['response_code'];
504 -
505 487 if ( $rate_limited ) {
506 488 // Do not return false positives for rate limited responses.
507 489 return false;
508 490 }
@@ -517,13 +499,11 @@
517 499 * @return array|false
518 500 */
519 501 public static function get_primary_license_info() {
520 502 $installed_addons = apply_filters( 'frm_installed_addons', array() );
521 -
522 - if ( ! $installed_addons || ! isset( $installed_addons['formidable_pro'] ) ) {
503 + if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) {
523 504 return false;
524 505 }
525 -
526 506 $installed_addons = array(
527 507 'formidable_pro' => $installed_addons['formidable_pro'],
528 508 );
529 509
@@ -531,12 +511,8 @@
531 511 }
532 512
533 513 /**
534 514 * @since 3.04.03
535 - *
536 - * @param mixed $transient
537 - *
538 - * @return object
539 515 */
540 516 public static function check_update( $transient ) {
541 517 if ( ! FrmAppHelper::pro_is_installed() ) {
542 518 // Don't make any changes if only Lite is installed.
@@ -547,10 +523,9 @@
547 523 $transient = new stdClass();
548 524 }
549 525
550 526 $installed_addons = apply_filters( 'frm_installed_addons', array() );
551 -
552 - if ( ! $installed_addons ) {
527 + if ( empty( $installed_addons ) ) {
553 528 return $transient;
554 529 }
555 530
556 531 $version_info = self::fill_update_addon_info( $installed_addons );
@@ -564,10 +539,9 @@
564 539 continue;
565 540 }
566 541
567 542 $folder = $plugin->plugin;
568 -
569 - if ( ! $folder ) {
543 + if ( empty( $folder ) ) {
570 544 continue;
571 545 }
572 546
573 547 if ( ! self::is_installed( $folder ) ) {
@@ -574,10 +548,10 @@
574 548 // don't show an update if the plugin isn't installed
575 549 continue;
576 550 }
577 551
578 - $wp_plugin = $wp_plugins[ $folder ] ?? array();
579 - $wp_version = $wp_plugin['Version'] ?? '1.0';
552 + $wp_plugin = isset( $wp_plugins[ $folder ] ) ? $wp_plugins[ $folder ] : array();
553 + $wp_version = isset( $wp_plugin['Version'] ) ? $wp_plugin['Version'] : '1.0';
580 554 $plugin->slug = explode( '/', $folder )[0];
581 555
582 556 if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
583 557 $transient->response[ $folder ] = $plugin;
@@ -597,9 +571,8 @@
597 571 * Because this gets called on "pre_set_site_transient_update_plugins" an old version of FrmAppHelper may be loaded on plugin update.
598 572 * 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 573 *
600 574 * @since 5.5.2
601 - *
602 575 * @return array
603 576 */
604 577 protected static function get_plugins() {
605 578 if ( ! function_exists( 'get_plugins' ) ) {
@@ -639,16 +612,15 @@
639 612 continue;
640 613 }
641 614
642 615 $new_license = $addon->license;
643 -
644 - if ( ! $new_license || in_array( $new_license, $checked_licenses, true ) ) {
616 + if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) {
645 617 continue;
646 618 }
647 619
648 620 $checked_licenses[] = $new_license;
649 - $api = new FrmFormApi( $new_license );
650 621
622 + $api = new FrmFormApi( $new_license );
651 623 if ( empty( $version_info ) ) {
652 624 $version_info = $api->get_api_info();
653 625 continue;
654 626 }
@@ -653,21 +625,18 @@
653 625 continue;
654 626 }
655 627
656 628 $plugin = $api->get_addon_for_license( $addon, $version_info );
657 -
658 - if ( ! $plugin ) {
629 + if ( empty( $plugin ) ) {
659 630 continue;
660 631 }
661 632
662 - $download_id = $plugin['id'] ?? 0;
663 -
664 - if ( $download_id && ! isset( $version_info[ $download_id ]['package'] ) ) {
633 + $download_id = isset( $plugin['id'] ) ? $plugin['id'] : 0;
634 + if ( ! empty( $download_id ) && ! isset( $version_info[ $download_id ]['package'] ) ) {
665 635 // if this addon is using its own license, get the update url
666 636 $addon_info = $api->get_api_info();
667 637
668 638 $version_info[ $download_id ] = $addon_info[ $download_id ];
669 -
670 639 if ( isset( $addon_info['error'] ) ) {
671 640 $version_info[ $download_id ]['error'] = array(
672 641 'message' => $addon_info['error']['message'],
673 642 'code' => $addon_info['error']['code'],
@@ -682,11 +651,9 @@
682 651 /**
683 652 * Get the action link for an addon that isn't active.
684 653 *
685 654 * @since 3.06.03
686 - *
687 655 * @param string $plugin The plugin slug.
688 - *
689 656 * @return array
690 657 */
691 658 public static function install_link( $plugin ) {
692 659 $link = array();
@@ -708,9 +675,9 @@
708 675 'categories' => $addon['categories'],
709 676 );
710 677 }
711 678
712 - if ( $link ) {
679 + if ( ! empty( $link ) ) {
713 680 $link['status'] = $addon['status']['type'];
714 681 }
715 682 } elseif ( current_user_can( 'activate_plugins' ) && self::is_installed( 'formidable-' . $plugin . '/formidable-' . $plugin . '.php' ) ) {
716 683 $link = array(
@@ -723,41 +690,33 @@
723 690 }
724 691
725 692 /**
726 693 * @since 4.09
727 - *
728 694 * @param string $plugin The plugin slug.
729 - *
730 695 * @return array|false
731 696 */
732 697 public static function get_addon( $plugin ) {
733 698 $addons = self::get_api_addons();
734 699 self::prepare_addons( $addons );
735 -
736 700 foreach ( $addons as $addon ) {
737 701 $slug = explode( '/', $addon['plugin'] );
738 -
739 702 if ( $slug[0] === 'formidable-' . $plugin ) {
740 703 return $addon;
741 704 }
742 705 }
743 -
744 706 return false;
745 707 }
746 708
747 709 /**
748 710 * @since 4.09
749 - *
750 711 * @return string
751 712 */
752 713 protected static function get_license_type() {
753 714 $license_type = '';
754 715 $addons = self::get_api_addons();
755 -
756 716 if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) {
757 717 $license_type = $addons['error']['type'];
758 718 }
759 -
760 719 return $license_type;
761 720 }
762 721
763 722 /**
@@ -770,10 +729,9 @@
770 729 */
771 730 public static function get_addon_for_license( $addons, $license ) {
772 731 $download_id = $license->download_id;
773 732 $plugin = array();
774 -
775 - if ( ! $download_id && ! empty( $addons ) ) {
733 + if ( empty( $download_id ) && ! empty( $addons ) ) {
776 734 foreach ( $addons as $addon ) {
777 735 if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) {
778 736 return $addon;
779 737 }
@@ -785,33 +743,29 @@
785 743 return $plugin;
786 744 }
787 745
788 746 /**
789 - * @param array $addons
790 - *
791 747 * @return void
792 748 */
793 749 protected static function prepare_addons( &$addons ) {
794 - // Reset categories to prevent count accumulation across multiple calls.
795 - self::$categories = array();
796 -
797 750 $activate_url = '';
798 -
799 751 if ( current_user_can( 'activate_plugins' ) ) {
800 752 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
801 753 }
802 754
803 755 $loop_addons = $addons;
804 -
805 756 foreach ( $loop_addons as $id => $addon ) {
806 757 if ( is_numeric( $id ) ) {
807 758 $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
808 759 $file_name = $addon['plugin'];
809 760 } else {
810 - $slug = $id;
811 - $base_file = $addon['file'] ?? 'formidable-' . $slug;
761 + $slug = $id;
762 + if ( isset( $addon['file'] ) ) {
763 + $base_file = $addon['file'];
764 + } else {
765 + $base_file = 'formidable-' . $slug;
766 + }
812 767 $file_name = $base_file . '/' . $base_file . '.php';
813 -
814 768 if ( ! isset( $addon['plugin'] ) ) {
815 769 $addon['plugin'] = $file_name;
816 770 }
817 771 }
@@ -816,12 +770,10 @@
816 770 }
817 771 }
818 772
819 773 $addon['installed'] = self::is_installed( $file_name );
820 -
821 774 if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) {
822 775 $active_views_version = self::get_active_views_version();
823 -
824 776 if ( false !== $active_views_version && $slug !== $active_views_version ) {
825 777 $addon['installed'] = false;
826 778 }
827 779 }
@@ -827,9 +779,9 @@
827 779 }
828 780
829 781 $addon['activate_url'] = '';
830 782
831 - if ( $addon['installed'] && $activate_url && ! self::is_plugin_active( $file_name, $slug ) ) {
783 + if ( $addon['installed'] && ! empty( $activate_url ) && ! self::is_plugin_active( $file_name, $slug ) ) {
832 784 $addon['activate_url'] = add_query_arg(
833 785 array(
834 786 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
835 787 'plugin' => $file_name,
@@ -855,11 +807,8 @@
855 807 }//end foreach
856 808 }
857 809
858 810 /**
859 - * @param string $file_name
860 - * @param string $slug
861 - *
862 811 * @return bool
863 812 */
864 813 private static function is_plugin_active( $file_name, $slug ) {
865 814 if ( 'formidable-views/formidable-views.php' === $file_name ) {
@@ -874,9 +823,8 @@
874 823 private static function get_active_views_version() {
875 824 if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) {
876 825 return false;
877 826 }
878 -
879 827 $plugin_version = FrmViewsAppHelper::plugin_version();
880 828 return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views';
881 829 }
882 830
@@ -882,25 +830,22 @@
882 830
883 831 /**
884 832 * @since 3.04.02
885 833 *
886 - * @param string $link
887 - *
888 834 * @return void
889 835 */
890 836 protected static function prepare_addon_link( &$link ) {
891 837 $site_url = 'https://formidableforms.com/';
892 -
893 - if ( ! str_starts_with( $link, 'http' ) ) {
838 + if ( strpos( $link, 'http' ) !== 0 ) {
894 839 $link = $site_url . $link;
895 840 }
896 -
897 - $link = FrmAppHelper::make_affiliate_url( $link );
898 -
899 - $utm = array(
900 - 'campaign' => 'addons',
841 + $link = FrmAppHelper::make_affiliate_url( $link );
842 + $query_args = array(
843 + 'utm_source' => 'WordPress',
844 + 'utm_medium' => 'addons',
845 + 'utm_campaign' => 'liteplugin',
901 846 );
902 - $link = FrmAppHelper::maybe_add_missing_utm( $link, $utm );
847 + $link = add_query_arg( $query_args, $link );
903 848 }
904 849
905 850 /**
906 851 * Add the status to the addon array. Status options are:
@@ -907,10 +852,8 @@
907 852 * installed, active, not installed
908 853 *
909 854 * @since 3.04.02
910 855 *
911 - * @param array $addon
912 - *
913 856 * @return void
914 857 */
915 858 protected static function set_addon_status( &$addon ) {
916 859 if ( ! empty( $addon['activate_url'] ) ) {
@@ -937,9 +880,8 @@
937 880 * @param string $plugin
938 881 * @param string $redirect
939 882 * @param bool $network_wide
940 883 * @param bool $silent
941 - *
942 884 * @return WP_Error|null Null on success, WP_Error on invalid file.
943 885 */
944 886 protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
945 887 if ( ! function_exists( 'activate_plugin' ) ) {
@@ -954,9 +896,8 @@
954 896 * @since 6.8
955 897 *
956 898 * @param string $plugin
957 899 * @param bool $silent
958 - *
959 900 * @return void
960 901 */
961 902 protected static function deactivate_plugin( $plugin, $silent = false ) {
962 903 if ( ! function_exists( 'deactivate_plugins' ) ) {
@@ -970,9 +911,8 @@
970 911 *
971 912 * @since 6.8
972 913 *
973 914 * @param string $plugin
974 - *
975 915 * @return true|WP_Error True on success, WP_Error on invalid file.
976 916 */
977 917 protected static function uninstall_plugin( $plugin ) {
978 918 if ( ! current_user_can( 'delete_plugins' ) ) {
@@ -985,9 +925,13 @@
985 925
986 926 self::deactivate_plugin( $plugin, true );
987 927 $result = delete_plugins( array( $plugin ) );
988 928
989 - return is_wp_error( $result ) ? $result : true;
929 + if ( is_wp_error( $result ) ) {
930 + return $result;
931 + }
932 +
933 + return true;
990 934 }
991 935
992 936 /**
993 937 * @since 5.0.10
@@ -1003,9 +947,9 @@
1003 947
1004 948 /**
1005 949 * @since 4.08
1006 950 *
1007 - * @return mixed[]|null
951 + * @return array|void
1008 952 */
1009 953 protected static function download_and_activate() {
1010 954 if ( is_admin() ) {
1011 955 FrmAppHelper::set_current_screen_and_hook_suffix();
@@ -1013,14 +957,12 @@
1013 957
1014 958 self::maybe_show_cred_form();
1015 959
1016 960 $installed = self::install_addon();
1017 -
1018 961 if ( is_array( $installed ) && isset( $installed['message'] ) ) {
1019 962 return $installed;
1020 963 }
1021 964 self::handle_addon_action( $installed, 'activate' );
1022 - return null;
1023 965 }
1024 966
1025 967 /**
1026 968 * @since 3.04.02
@@ -1031,9 +973,9 @@
1031 973 if ( ! function_exists( 'request_filesystem_credentials' ) ) {
1032 974 include_once ABSPATH . 'wp-admin/includes/file.php';
1033 975 }
1034 976
1035 - // Start output buffering to catch the filesystem form if credentials are needed.
977 + // Start output bufferring to catch the filesystem form if credentials are needed.
1036 978 ob_start();
1037 979
1038 980 $show_form = false;
1039 981 $method = '';
@@ -1050,8 +992,9 @@
1050 992
1051 993 if ( $show_form ) {
1052 994 $form = ob_get_clean();
1053 995 $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' );
996 + $data = $form;
1054 997 $response = array(
1055 998 'success' => false,
1056 999 'message' => $message,
1057 1000 'form' => $form,
@@ -1079,10 +1022,8 @@
1079 1022 * We do not need any extra credentials if we have gotten this far,
1080 1023 * so let's install the plugin.
1081 1024 *
1082 1025 * @since 3.04.02
1083 - *
1084 - * @return array|string
1085 1026 */
1086 1027 protected static function install_addon() {
1087 1028 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1088 1029
@@ -1102,9 +1043,8 @@
1102 1043 // Flush the cache and return the newly installed plugin basename.
1103 1044 wp_cache_flush();
1104 1045
1105 1046 $plugin = $installer->plugin_info();
1106 -
1107 1047 if ( ! $plugin ) {
1108 1048 return array(
1109 1049 'message' => 'Plugin was not installed. ' . $installer->result,
1110 1050 'success' => false,
@@ -1109,9 +1049,8 @@
1109 1049 'message' => 'Plugin was not installed. ' . $installer->result,
1110 1050 'success' => false,
1111 1051 );
1112 1052 }
1113 -
1114 1053 return $plugin;
1115 1054 }
1116 1055
1117 1056 /**
@@ -1175,9 +1114,8 @@
1175 1114 * @since 6.8
1176 1115 *
1177 1116 * @param callable $action_callback The specific add-on action to be executed.
1178 1117 * @param callable|null $response_callback Optional. The response handling callback. Default null.
1179 - *
1180 1118 * @return void
1181 1119 */
1182 1120 private static function process_addon_action( $action_callback, $response_callback = null ) {
1183 1121 self::install_addon_permissions();
@@ -1200,14 +1138,13 @@
1200 1138 * @since 6.8
1201 1139 *
1202 1140 * @param string $installed The plugin folder name with file name.
1203 1141 * @param string $action The action type ('activate', 'deactivate', 'uninstall').
1204 - *
1205 - * @return mixed[]|null
1142 + * @return array|void
1206 1143 */
1207 1144 protected static function handle_addon_action( $installed, $action ) {
1208 1145 if ( ! $installed || ! $action ) {
1209 - return null;
1146 + return;
1210 1147 }
1211 1148
1212 1149 $result = null;
1213 1150 switch ( $action ) {
@@ -1227,9 +1164,8 @@
1227 1164 if ( $result->get_error_code() !== 'no_plugin_header' ) {
1228 1165 if ( wp_doing_ajax() ) {
1229 1166 wp_send_json_error( array( 'error' => $result->get_error_message() ) );
1230 1167 }
1231 -
1232 1168 return array(
1233 1169 'message' => $result->get_error_message(),
1234 1170 'success' => false,
1235 1171 );
@@ -1243,14 +1179,17 @@
1243 1179 * @return array
1244 1180 */
1245 1181 private static function get_addon_activation_response() {
1246 1182 $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 1183
1249 - return array(
1184 + $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' );
1185 +
1186 + $response = array(
1250 1187 'message' => $message,
1251 1188 'saveAndReload' => $activating_page,
1252 1189 );
1190 +
1191 + return $response;
1253 1192 }
1254 1193
1255 1194 /**
1256 1195 * Return a string that reflects the page from which the addon is being activated on,
@@ -1259,14 +1198,17 @@
1259 1198 * @return string
1260 1199 */
1261 1200 private static function get_activating_page() {
1262 1201 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1202 + if ( false !== strpos( $referer, 'frm_action=settings' ) ) {
1203 + return 'settings';
1204 + }
1263 1205
1264 - if ( str_contains( $referer, 'frm_action=settings' ) ) {
1265 - return 'settings';
1206 + if ( false !== strpos( $referer, 'frm_action=edit' ) ) {
1207 + return 'form_builder';
1266 1208 }
1267 1209
1268 - return str_contains( $referer, 'frm_action=edit' ) ? 'form_builder' : '';
1210 + return '';
1269 1211 }
1270 1212
1271 1213 /**
1272 1214 * Run security checks before installing
@@ -1290,14 +1232,12 @@
1290 1232 * @return string
1291 1233 */
1292 1234 public static function connect_link() {
1293 1235 $auth = get_option( 'frm_connect_token' );
1294 -
1295 - if ( ! $auth ) {
1236 + if ( empty( $auth ) ) {
1296 1237 $auth = hash( 'sha512', wp_rand() );
1297 1238 update_option( 'frm_connect_token', $auth, 'no' );
1298 1239 }
1299 -
1300 1240 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title', 'formidable-settings' );
1301 1241 $link = 'https://formidableforms.com/api-connect/';
1302 1242 $args = array(
1303 1243 'v' => 2,
@@ -1325,10 +1265,9 @@
1325 1265 $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' );
1326 1266
1327 1267 // The download link is not required if already installed.
1328 1268 $is_installed = FrmAppHelper::pro_is_included();
1329 - $file_missing = ! $is_installed && ! $post_url;
1330 -
1269 + $file_missing = ! $is_installed && empty( $post_url );
1331 1270 if ( ! $post_auth || $file_missing ) {
1332 1271 return false;
1333 1272 }
1334 1273
@@ -1333,9 +1272,13 @@
1333 1272 }
1334 1273
1335 1274 // Verify auth.
1336 1275 $auth = get_option( 'frm_connect_token' );
1337 - return $auth && hash_equals( $auth, $post_auth );
1276 + if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) {
1277 + return false;
1278 + }
1279 +
1280 + return true;
1338 1281 }
1339 1282
1340 1283 /**
1341 1284 * Install and/or activate the add-on file.
@@ -1346,17 +1289,17 @@
1346 1289 */
1347 1290 public static function install_addon_api() {
1348 1291 self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1349 1292
1293 + $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' );
1294 +
1350 1295 // Delete so cannot replay.
1351 1296 delete_option( 'frm_connect_token' );
1352 1297
1353 1298 // It's already installed and active.
1354 1299 $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1355 -
1356 1300 if ( is_wp_error( $active ) ) {
1357 1301 $response = self::maybe_download_and_activate();
1358 -
1359 1302 if ( is_array( $response ) ) {
1360 1303 // The download failed.
1361 1304 return $response;
1362 1305 }
@@ -1365,9 +1308,8 @@
1365 1308 // If empty license, save it now.
1366 1309 if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) {
1367 1310 load_formidable_pro();
1368 1311 $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) );
1369 -
1370 1312 if ( ! $license ) {
1371 1313 return array(
1372 1314 'success' => false,
1373 1315 'error' => 'That site does not have a valid license key.',
@@ -1374,9 +1316,8 @@
1374 1316 );
1375 1317 }
1376 1318
1377 1319 $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' );
1378 -
1379 1320 if ( ! $response['success'] ) {
1380 1321 // Could not activate license.
1381 1322 return $response;
1382 1323 }
@@ -1401,9 +1342,8 @@
1401 1342 }
1402 1343
1403 1344 // Download plugin now.
1404 1345 $response = self::download_and_activate();
1405 -
1406 1346 if ( is_array( $response ) && isset( $response['success'] ) ) {
1407 1347 // The download failed.
1408 1348 return $response;
1409 1349 }
@@ -1417,9 +1357,8 @@
1417 1357 * @since 4.09
1418 1358 *
1419 1359 * @param string $plugin
1420 1360 * @param array|string $upgrade_link_args
1421 - *
1422 1361 * @return void
1423 1362 */
1424 1363 public static function conditional_action_button( $plugin, $upgrade_link_args ) {
1425 1364 if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) {
@@ -1454,9 +1393,8 @@
1454 1393 * @type false|string $license_type
1455 1394 * @type string $plan_required
1456 1395 * @type string $upgrade_link
1457 1396 * }
1458 - *
1459 1397 * @return void
1460 1398 */
1461 1399 public static function show_conditional_action_button( $atts ) {
1462 1400 if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) {
@@ -1489,14 +1427,13 @@
1489 1427 $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1490 1428 }
1491 1429
1492 1430 $class = ! empty( $atts['class'] ) ? $atts['class'] : '';
1493 -
1494 - if ( ! str_contains( $class, 'frm-button' ) ) {
1431 + if ( strpos( $class, 'frm-button' ) === false ) {
1495 1432 $class .= ' frm-button-secondary frm-button-sm';
1496 1433 }
1497 1434 ?>
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 ?>
1435 + <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' ); ?>">
1499 1436 <?php echo esc_html( $text ); ?>
1500 1437 </a>
1501 1438 <?php
1502 1439 }
@@ -1509,9 +1446,8 @@
1509 1446 public static function ajax_install_addon() {
1510 1447 self::install_addon_permissions();
1511 1448
1512 1449 $result = self::download_and_activate();
1513 -
1514 1450 if ( isset( $result['success'] ) && ! $result['success'] ) {
1515 1451 echo json_encode( $result );
1516 1452 wp_die();
1517 1453 }
@@ -1544,8 +1480,9 @@
1544 1480 $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list );
1545 1481
1546 1482 if ( ! is_array( $allowed_url_list ) ) {
1547 1483 _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' );
1484 +
1548 1485 return array();
1549 1486 }
1550 1487
1551 1488 return $allowed_url_list;
@@ -1554,10 +1491,8 @@
1554 1491 /**
1555 1492 * Gets required plan for an addon.
1556 1493 *
1557 1494 * @since 6.4.2
1558 - *
1559 - * @param int|string $addon_id
1560 1495 *
1561 1496 * @return string Empty string if no plan is required for active license.
1562 1497 */
1563 1498 public static function get_addon_required_plan( $addon_id ) {