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