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