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