PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.20
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.20
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 +116 -234 6.296.20 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(
@@ -193,18 +188,15 @@
193 188 );
194 189
195 190 // Extract the elements to move
196 191 foreach ( $plans as $plan ) {
197 - if ( ! isset( self::$categories[ $plan ] ) ) {
198 - continue;
192 + if ( isset( self::$categories[ $plan ] ) ) {
193 + $bottom_categories[ $plan ] = self::$categories[ $plan ];
194 + unset( self::$categories[ $plan ] );
199 195 }
200 -
201 - $bottom_categories[ $plan ] = self::$categories[ $plan ];
202 - unset( self::$categories[ $plan ] );
203 196 }
204 197
205 198 $special_categories = array();
206 -
207 199 if ( 'elite' !== self::license_type() ) {
208 200 $special_categories['available-addons'] = array(
209 201 'name' => __( 'Available', 'formidable' ),
210 202 // To be assigned via JavaScript.
@@ -236,9 +228,8 @@
236 228 *
237 229 * @since 6.15
238 230 *
239 231 * @param array $addon The addon array that will be modified by reference.
240 - *
241 232 * @return void
242 233 */
243 234 protected static function set_categories( &$addon ) {
244 235 if ( ! isset( $addon['categories'] ) ) {
@@ -269,11 +260,11 @@
269 260 * @return void
270 261 */
271 262 public static function license_settings() {
272 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' );
273 266
274 - if ( ! $plugins ) {
275 - esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
276 267 return;
277 268 }
278 269
279 270 ksort( $plugins );
@@ -287,15 +278,15 @@
287 278 protected static function get_api_addons() {
288 279 $api = new FrmFormApi();
289 280 $addons = $api->get_api_info();
290 281
291 - if ( ! $addons ) {
292 - return self::fallback_plugin_list();
293 - }
294 -
295 - foreach ( $addons as $k => $addon ) {
296 - if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
297 - unset( $addons[ $k ] );
282 + if ( empty( $addons ) ) {
283 + $addons = self::fallback_plugin_list();
284 + } else {
285 + foreach ( $addons as $k => $addon ) {
286 + if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
287 + unset( $addons[ $k ] );
288 + }
298 289 }
299 290 }
300 291
301 292 return $addons;
@@ -309,8 +300,9 @@
309 300 * @return int Count of addons.
310 301 */
311 302 public static function get_addons_count() {
312 303 $addons = self::get_api_addons();
304 +
313 305 return count( $addons );
314 306 }
315 307
316 308 /**
@@ -316,9 +308,8 @@
316 308 /**
317 309 * If the API is unable to connect, show something on the addons page
318 310 *
319 311 * @since 3.04.03
320 - *
321 312 * @return array
322 313 */
323 314 protected static function fallback_plugin_list() {
324 315 $list = array(
@@ -329,19 +320,19 @@
329 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.',
330 321 ),
331 322 'mailchimp' => array(
332 323 'title' => 'Mailchimp Forms',
333 - '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.',
334 325 ),
335 326 'registration' => array(
336 327 'title' => 'User Registration Forms',
337 328 'link' => 'downloads/user-registration/',
338 - '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.',
339 330 ),
340 331 'paypal' => array(
341 332 'title' => 'PayPal Standard Forms',
342 333 'link' => 'downloads/paypal-standard/',
343 - '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.',
344 335 ),
345 336 'stripe' => array(
346 337 'title' => 'Stripe Forms',
347 338 'docs' => 'knowledgebase/stripe/',
@@ -373,9 +364,9 @@
373 364 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
374 365 ),
375 366 'zapier' => array(
376 367 'title' => 'Zapier Forms',
377 - '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.',
378 369 ),
379 370 'signature' => array(
380 371 'title' => 'Digital Signature Forms',
381 372 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
@@ -408,9 +399,8 @@
408 399 foreach ( $list as $k => $info ) {
409 400 $info['slug'] = $k;
410 401 $list[ $k ] = array_merge( $defaults, $info );
411 402 }
412 -
413 403 return $list;
414 404 }
415 405
416 406 /**
@@ -416,9 +406,8 @@
416 406 /**
417 407 * If Pro is missing but has been authenticated, include a download URL
418 408 *
419 409 * @since 3.04.03
420 - *
421 410 * @return string
422 411 */
423 412 public static function get_pro_download_url() {
424 413 $license = self::get_pro_license();
@@ -425,20 +414,17 @@
425 414 $api = new FrmFormApi( $license );
426 415 $downloads = $api->get_api_info();
427 416 $pro = self::get_pro_from_addons( $downloads );
428 417
429 - return $pro['url'] ?? '';
418 + return isset( $pro['url'] ) ? $pro['url'] : '';
430 419 }
431 420
432 421 /**
433 422 * @since 4.08
434 - *
435 - * @return string
436 423 */
437 424 public static function get_pro_license() {
438 425 $pro_cred_store = 'frmpro-credentials';
439 426 $pro_wpmu_store = 'frmpro-wpmu-sitewide';
440 -
441 427 if ( is_multisite() && get_site_option( $pro_wpmu_store ) ) {
442 428 $creds = get_site_option( $pro_cred_store );
443 429 } else {
444 430 $creds = get_option( $pro_cred_store );
@@ -448,18 +434,16 @@
448 434 return '';
449 435 }
450 436
451 437 $license = $creds['license'];
452 -
453 - if ( ! $license ) {
438 + if ( empty( $license ) ) {
454 439 return '';
455 440 }
456 441
457 - if ( str_contains( $license, '-' ) ) {
458 - // This is a fix for licenses saved in the past
459 - return strtoupper( $license );
442 + if ( strpos( $license, '-' ) ) {
443 + // this is a fix for licenses saved in the past
444 + $license = strtoupper( $license );
460 445 }
461 -
462 446 return $license;
463 447 }
464 448
465 449 /**
@@ -465,19 +449,16 @@
465 449 /**
466 450 * @since 4.08
467 451 *
468 452 * @param array $addons
469 - *
470 453 * @return array
471 454 */
472 455 protected static function get_pro_from_addons( $addons ) {
473 - return $addons['93790'] ?? array();
456 + return isset( $addons['93790'] ) ? $addons['93790'] : array();
474 457 }
475 458
476 459 /**
477 460 * @since 4.06
478 - *
479 - * @return string
480 461 */
481 462 public static function license_type() {
482 463 if ( is_callable( 'FrmProAddonsController::license_type' ) ) {
483 464 return FrmProAddonsController::license_type();
@@ -492,21 +473,18 @@
492 473 * @return bool
493 474 */
494 475 public static function is_license_expired() {
495 476 $version_info = self::get_primary_license_info();
496 -
497 477 if ( ! isset( $version_info['error'] ) ) {
498 478 return false;
499 479 }
500 480
501 - $expires = $version_info['error']['expires'] ?? 0;
502 -
503 - if ( ! $expires || $expires > time() ) {
481 + $expires = isset( $version_info['error']['expires'] ) ? $version_info['error']['expires'] : 0;
482 + if ( empty( $expires ) || $expires > time() ) {
504 483 return false;
505 484 }
506 485
507 486 $rate_limited = ! empty( $version_info['response_code'] ) && 429 === (int) $version_info['response_code'];
508 -
509 487 if ( $rate_limited ) {
510 488 // Do not return false positives for rate limited responses.
511 489 return false;
512 490 }
@@ -521,13 +499,11 @@
521 499 * @return array|false
522 500 */
523 501 public static function get_primary_license_info() {
524 502 $installed_addons = apply_filters( 'frm_installed_addons', array() );
525 -
526 - if ( ! $installed_addons || ! isset( $installed_addons['formidable_pro'] ) ) {
503 + if ( empty( $installed_addons ) || ! isset( $installed_addons['formidable_pro'] ) ) {
527 504 return false;
528 505 }
529 -
530 506 $installed_addons = array(
531 507 'formidable_pro' => $installed_addons['formidable_pro'],
532 508 );
533 509
@@ -535,12 +511,8 @@
535 511 }
536 512
537 513 /**
538 514 * @since 3.04.03
539 - *
540 - * @param mixed $transient
541 - *
542 - * @return object
543 515 */
544 516 public static function check_update( $transient ) {
545 517 if ( ! FrmAppHelper::pro_is_installed() ) {
546 518 // Don't make any changes if only Lite is installed.
@@ -551,10 +523,9 @@
551 523 $transient = new stdClass();
552 524 }
553 525
554 526 $installed_addons = apply_filters( 'frm_installed_addons', array() );
555 -
556 - if ( ! $installed_addons ) {
527 + if ( empty( $installed_addons ) ) {
557 528 return $transient;
558 529 }
559 530
560 531 $version_info = self::fill_update_addon_info( $installed_addons );
@@ -568,20 +539,19 @@
568 539 continue;
569 540 }
570 541
571 542 $folder = $plugin->plugin;
572 -
573 - if ( ! $folder ) {
543 + if ( empty( $folder ) ) {
574 544 continue;
575 545 }
576 546
577 547 if ( ! self::is_installed( $folder ) ) {
578 - // Don't show an update if the plugin isn't installed
548 + // don't show an update if the plugin isn't installed
579 549 continue;
580 550 }
581 551
582 - $wp_plugin = $wp_plugins[ $folder ] ?? array();
583 - $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';
584 554 $plugin->slug = explode( '/', $folder )[0];
585 555
586 556 if ( version_compare( $wp_version, $plugin->new_version, '<' ) ) {
587 557 $transient->response[ $folder ] = $plugin;
@@ -589,8 +559,9 @@
589 559 $transient->no_update[ $folder ] = $plugin;
590 560 }
591 561
592 562 $transient->checked[ $folder ] = $wp_version;
563 +
593 564 }//end foreach
594 565
595 566 return $transient;
596 567 }
@@ -600,9 +571,8 @@
600 571 * Because this gets called on "pre_set_site_transient_update_plugins" an old version of FrmAppHelper may be loaded on plugin update.
601 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.
602 573 *
603 574 * @since 5.5.2
604 - *
605 575 * @return array
606 576 */
607 577 protected static function get_plugins() {
608 578 if ( ! function_exists( 'get_plugins' ) ) {
@@ -637,49 +607,43 @@
637 607 $version_info = array();
638 608
639 609 foreach ( $installed_addons as $addon ) {
640 610 if ( $addon->store_url !== 'https://formidableforms.com' ) {
641 - // Check if this is a third-party addon
611 + // check if this is a third-party addon
642 612 continue;
643 613 }
644 614
645 615 $new_license = $addon->license;
646 -
647 - if ( ! $new_license || in_array( $new_license, $checked_licenses, true ) ) {
616 + if ( empty( $new_license ) || in_array( $new_license, $checked_licenses ) ) {
648 617 continue;
649 618 }
650 619
651 620 $checked_licenses[] = $new_license;
652 - $api = new FrmFormApi( $new_license );
653 621
654 - if ( ! $version_info ) {
622 + $api = new FrmFormApi( $new_license );
623 + if ( empty( $version_info ) ) {
655 624 $version_info = $api->get_api_info();
656 625 continue;
657 626 }
658 627
659 628 $plugin = $api->get_addon_for_license( $addon, $version_info );
660 -
661 - if ( ! $plugin ) {
629 + if ( empty( $plugin ) ) {
662 630 continue;
663 631 }
664 632
665 - $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();
666 637
667 - if ( ! $download_id || isset( $version_info[ $download_id ]['package'] ) ) {
668 - 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 + }
669 645 }
670 -
671 - // If this addon is using its own license, get the update url
672 - $addon_info = $api->get_api_info();
673 -
674 - $version_info[ $download_id ] = $addon_info[ $download_id ];
675 -
676 - if ( isset( $addon_info['error'] ) ) {
677 - $version_info[ $download_id ]['error'] = array(
678 - 'message' => $addon_info['error']['message'],
679 - 'code' => $addon_info['error']['code'],
680 - );
681 - }
682 646 }//end foreach
683 647
684 648 return $version_info;
685 649 }
@@ -687,11 +651,9 @@
687 651 /**
688 652 * Get the action link for an addon that isn't active.
689 653 *
690 654 * @since 3.06.03
691 - *
692 655 * @param string $plugin The plugin slug.
693 - *
694 656 * @return array
695 657 */
696 658 public static function install_link( $plugin ) {
697 659 $link = array();
@@ -713,9 +675,9 @@
713 675 'categories' => $addon['categories'],
714 676 );
715 677 }
716 678
717 - if ( $link ) {
679 + if ( ! empty( $link ) ) {
718 680 $link['status'] = $addon['status']['type'];
719 681 }
720 682 } elseif ( current_user_can( 'activate_plugins' ) && self::is_installed( 'formidable-' . $plugin . '/formidable-' . $plugin . '.php' ) ) {
721 683 $link = array(
@@ -727,81 +689,34 @@
727 689 return $link;
728 690 }
729 691
730 692 /**
731 - * Get the JSON-encoded install data for a plugin update.
732 - *
733 - * @since 6.29
734 - *
735 - * @param string $addon_slug The addon slug (e.g. 'pro', 'dates').
736 - *
737 - * @return string JSON-encoded install data, or empty string if no URL is available.
738 - */
739 - public static function get_update_install_data( $addon_slug ) {
740 - $upgrading = self::install_link( $addon_slug );
741 -
742 - if ( isset( $upgrading['class'] ) && 'frm-install-addon' === $upgrading['class'] ) {
743 - return (string) json_encode( $upgrading );
744 - }
745 -
746 - if ( 'pro' === $addon_slug ) {
747 - $download_url = self::get_pro_download_url();
748 - $plugin_file = 'formidable-pro/formidable-pro.php';
749 - } else {
750 - $addon_data = self::get_addon( $addon_slug );
751 - $download_url = $addon_data && ! empty( $addon_data['url'] ) ? $addon_data['url'] : '';
752 - $plugin_file = $addon_data && ! empty( $addon_data['plugin'] ) ? $addon_data['plugin'] : 'formidable-' . $addon_slug . '/formidable-' . $addon_slug . '.php';
753 - }
754 -
755 - if ( ! $download_url ) {
756 - $update_plugins = get_site_transient( 'update_plugins' );
757 - $plugin_update = $update_plugins->response[ $plugin_file ] ?? null;
758 - $download_url = $plugin_update && ! empty( $plugin_update->package ) ? $plugin_update->package : '';
759 - }
760 -
761 - return $download_url ? (string) json_encode(
762 - array(
763 - 'url' => $download_url,
764 - 'class' => 'frm-install-addon',
765 - )
766 - ) : '';
767 - }
768 -
769 - /**
770 693 * @since 4.09
771 - *
772 694 * @param string $plugin The plugin slug.
773 - *
774 695 * @return array|false
775 696 */
776 697 public static function get_addon( $plugin ) {
777 698 $addons = self::get_api_addons();
778 699 self::prepare_addons( $addons );
779 -
780 700 foreach ( $addons as $addon ) {
781 701 $slug = explode( '/', $addon['plugin'] );
782 -
783 702 if ( $slug[0] === 'formidable-' . $plugin ) {
784 703 return $addon;
785 704 }
786 705 }
787 -
788 706 return false;
789 707 }
790 708
791 709 /**
792 710 * @since 4.09
793 - *
794 711 * @return string
795 712 */
796 713 protected static function get_license_type() {
797 714 $license_type = '';
798 715 $addons = self::get_api_addons();
799 -
800 716 if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) {
801 - return $addons['error']['type'];
717 + $license_type = $addons['error']['type'];
802 718 }
803 -
804 719 return $license_type;
805 720 }
806 721
807 722 /**
@@ -814,12 +729,11 @@
814 729 */
815 730 public static function get_addon_for_license( $addons, $license ) {
816 731 $download_id = $license->download_id;
817 732 $plugin = array();
818 -
819 - if ( ! $download_id && $addons ) {
733 + if ( empty( $download_id ) && ! empty( $addons ) ) {
820 734 foreach ( $addons as $addon ) {
821 - if ( 0 === strcasecmp( $license->plugin_name, $addon['title'] ) ) {
735 + if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) {
822 736 return $addon;
823 737 }
824 738 }
825 739 } elseif ( isset( $addons[ $download_id ] ) ) {
@@ -829,33 +743,29 @@
829 743 return $plugin;
830 744 }
831 745
832 746 /**
833 - * @param array $addons
834 - *
835 747 * @return void
836 748 */
837 749 protected static function prepare_addons( &$addons ) {
838 - // Reset categories to prevent count accumulation across multiple calls.
839 - self::$categories = array();
840 -
841 750 $activate_url = '';
842 -
843 751 if ( current_user_can( 'activate_plugins' ) ) {
844 752 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
845 753 }
846 754
847 755 $loop_addons = $addons;
848 -
849 756 foreach ( $loop_addons as $id => $addon ) {
850 757 if ( is_numeric( $id ) ) {
851 758 $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
852 759 $file_name = $addon['plugin'];
853 760 } else {
854 - $slug = $id;
855 - $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 + }
856 767 $file_name = $base_file . '/' . $base_file . '.php';
857 -
858 768 if ( ! isset( $addon['plugin'] ) ) {
859 769 $addon['plugin'] = $file_name;
860 770 }
861 771 }
@@ -860,17 +770,10 @@
860 770 }
861 771 }
862 772
863 773 $addon['installed'] = self::is_installed( $file_name );
864 -
865 - if ( 'highrise' === $slug && ! $addon['installed'] ) {
866 - unset( $addons[ $id ] );
867 - continue;
868 - }
869 -
870 774 if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) {
871 775 $active_views_version = self::get_active_views_version();
872 -
873 776 if ( false !== $active_views_version && $slug !== $active_views_version ) {
874 777 $addon['installed'] = false;
875 778 }
876 779 }
@@ -876,9 +779,9 @@
876 779 }
877 780
878 781 $addon['activate_url'] = '';
879 782
880 - 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 ) ) {
881 784 $addon['activate_url'] = add_query_arg(
882 785 array(
883 786 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
884 787 'plugin' => $file_name,
@@ -904,11 +807,8 @@
904 807 }//end foreach
905 808 }
906 809
907 810 /**
908 - * @param string $file_name
909 - * @param string $slug
910 - *
911 811 * @return bool
912 812 */
913 813 private static function is_plugin_active( $file_name, $slug ) {
914 814 if ( 'formidable-views/formidable-views.php' === $file_name ) {
@@ -923,9 +823,8 @@
923 823 private static function get_active_views_version() {
924 824 if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) {
925 825 return false;
926 826 }
927 -
928 827 $plugin_version = FrmViewsAppHelper::plugin_version();
929 828 return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views';
930 829 }
931 830
@@ -931,25 +830,22 @@
931 830
932 831 /**
933 832 * @since 3.04.02
934 833 *
935 - * @param string $link
936 - *
937 834 * @return void
938 835 */
939 836 protected static function prepare_addon_link( &$link ) {
940 837 $site_url = 'https://formidableforms.com/';
941 -
942 - if ( ! str_starts_with( $link, 'http' ) ) {
838 + if ( strpos( $link, 'http' ) !== 0 ) {
943 839 $link = $site_url . $link;
944 840 }
945 -
946 - $link = FrmAppHelper::make_affiliate_url( $link );
947 -
948 - $utm = array(
949 - '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',
950 846 );
951 - $link = FrmAppHelper::maybe_add_missing_utm( $link, $utm );
847 + $link = add_query_arg( $query_args, $link );
952 848 }
953 849
954 850 /**
955 851 * Add the status to the addon array. Status options are:
@@ -956,10 +852,8 @@
956 852 * installed, active, not installed
957 853 *
958 854 * @since 3.04.02
959 855 *
960 - * @param array $addon
961 - *
962 856 * @return void
963 857 */
964 858 protected static function set_addon_status( &$addon ) {
965 859 if ( ! empty( $addon['activate_url'] ) ) {
@@ -986,9 +880,8 @@
986 880 * @param string $plugin
987 881 * @param string $redirect
988 882 * @param bool $network_wide
989 883 * @param bool $silent
990 - *
991 884 * @return WP_Error|null Null on success, WP_Error on invalid file.
992 885 */
993 886 protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
994 887 if ( ! function_exists( 'activate_plugin' ) ) {
@@ -1003,9 +896,8 @@
1003 896 * @since 6.8
1004 897 *
1005 898 * @param string $plugin
1006 899 * @param bool $silent
1007 - *
1008 900 * @return void
1009 901 */
1010 902 protected static function deactivate_plugin( $plugin, $silent = false ) {
1011 903 if ( ! function_exists( 'deactivate_plugins' ) ) {
@@ -1019,9 +911,8 @@
1019 911 *
1020 912 * @since 6.8
1021 913 *
1022 914 * @param string $plugin
1023 - *
1024 915 * @return true|WP_Error True on success, WP_Error on invalid file.
1025 916 */
1026 917 protected static function uninstall_plugin( $plugin ) {
1027 918 if ( ! current_user_can( 'delete_plugins' ) ) {
@@ -1034,9 +925,13 @@
1034 925
1035 926 self::deactivate_plugin( $plugin, true );
1036 927 $result = delete_plugins( array( $plugin ) );
1037 928
1038 - return is_wp_error( $result ) ? $result : true;
929 + if ( is_wp_error( $result ) ) {
930 + return $result;
931 + }
932 +
933 + return true;
1039 934 }
1040 935
1041 936 /**
1042 937 * @since 5.0.10
@@ -1043,9 +938,9 @@
1043 938 *
1044 939 * @return string
1045 940 */
1046 941 protected static function get_current_plugin() {
1047 - if ( ! self::$plugin ) {
942 + if ( empty( self::$plugin ) ) {
1048 943 self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' );
1049 944 }
1050 945 return self::$plugin;
1051 946 }
@@ -1052,9 +947,9 @@
1052 947
1053 948 /**
1054 949 * @since 4.08
1055 950 *
1056 - * @return mixed[]|null
951 + * @return array|void
1057 952 */
1058 953 protected static function download_and_activate() {
1059 954 if ( is_admin() ) {
1060 955 FrmAppHelper::set_current_screen_and_hook_suffix();
@@ -1062,14 +957,12 @@
1062 957
1063 958 self::maybe_show_cred_form();
1064 959
1065 960 $installed = self::install_addon();
1066 -
1067 961 if ( is_array( $installed ) && isset( $installed['message'] ) ) {
1068 962 return $installed;
1069 963 }
1070 964 self::handle_addon_action( $installed, 'activate' );
1071 - return null;
1072 965 }
1073 966
1074 967 /**
1075 968 * @since 3.04.02
@@ -1080,9 +973,9 @@
1080 973 if ( ! function_exists( 'request_filesystem_credentials' ) ) {
1081 974 include_once ABSPATH . 'wp-admin/includes/file.php';
1082 975 }
1083 976
1084 - // 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.
1085 978 ob_start();
1086 979
1087 980 $show_form = false;
1088 981 $method = '';
@@ -1099,8 +992,9 @@
1099 992
1100 993 if ( $show_form ) {
1101 994 $form = ob_get_clean();
1102 995 $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' );
996 + $data = $form;
1103 997 $response = array(
1104 998 'success' => false,
1105 999 'message' => $message,
1106 1000 'form' => $form,
@@ -1128,10 +1022,8 @@
1128 1022 * We do not need any extra credentials if we have gotten this far,
1129 1023 * so let's install the plugin.
1130 1024 *
1131 1025 * @since 3.04.02
1132 - *
1133 - * @return array|string
1134 1026 */
1135 1027 protected static function install_addon() {
1136 1028 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1137 1029
@@ -1145,15 +1037,14 @@
1145 1037 }
1146 1038
1147 1039 // Create the plugin upgrader with our custom skin.
1148 1040 $installer = new Plugin_Upgrader( new FrmInstallerSkin() );
1149 - $installer->install( $download_url, array( 'overwrite_package' => true ) );
1041 + $installer->install( $download_url );
1150 1042
1151 1043 // Flush the cache and return the newly installed plugin basename.
1152 1044 wp_cache_flush();
1153 1045
1154 1046 $plugin = $installer->plugin_info();
1155 -
1156 1047 if ( ! $plugin ) {
1157 1048 return array(
1158 1049 'message' => 'Plugin was not installed. ' . $installer->result,
1159 1050 'success' => false,
@@ -1158,9 +1049,8 @@
1158 1049 'message' => 'Plugin was not installed. ' . $installer->result,
1159 1050 'success' => false,
1160 1051 );
1161 1052 }
1162 -
1163 1053 return $plugin;
1164 1054 }
1165 1055
1166 1056 /**
@@ -1224,9 +1114,8 @@
1224 1114 * @since 6.8
1225 1115 *
1226 1116 * @param callable $action_callback The specific add-on action to be executed.
1227 1117 * @param callable|null $response_callback Optional. The response handling callback. Default null.
1228 - *
1229 1118 * @return void
1230 1119 */
1231 1120 private static function process_addon_action( $action_callback, $response_callback = null ) {
1232 1121 self::install_addon_permissions();
@@ -1249,14 +1138,13 @@
1249 1138 * @since 6.8
1250 1139 *
1251 1140 * @param string $installed The plugin folder name with file name.
1252 1141 * @param string $action The action type ('activate', 'deactivate', 'uninstall').
1253 - *
1254 - * @return mixed[]|null
1142 + * @return array|void
1255 1143 */
1256 1144 protected static function handle_addon_action( $installed, $action ) {
1257 1145 if ( ! $installed || ! $action ) {
1258 - return null;
1146 + return;
1259 1147 }
1260 1148
1261 1149 $result = null;
1262 1150 switch ( $action ) {
@@ -1276,9 +1164,8 @@
1276 1164 if ( $result->get_error_code() !== 'no_plugin_header' ) {
1277 1165 if ( wp_doing_ajax() ) {
1278 1166 wp_send_json_error( array( 'error' => $result->get_error_message() ) );
1279 1167 }
1280 -
1281 1168 return array(
1282 1169 'message' => $result->get_error_message(),
1283 1170 'success' => false,
1284 1171 );
@@ -1292,14 +1179,17 @@
1292 1179 * @return array
1293 1180 */
1294 1181 private static function get_addon_activation_response() {
1295 1182 $activating_page = self::get_activating_page();
1296 - $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
1297 1183
1298 - 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(
1299 1187 'message' => $message,
1300 1188 'saveAndReload' => $activating_page,
1301 1189 );
1190 +
1191 + return $response;
1302 1192 }
1303 1193
1304 1194 /**
1305 1195 * Return a string that reflects the page from which the addon is being activated on,
@@ -1308,14 +1198,17 @@
1308 1198 * @return string
1309 1199 */
1310 1200 private static function get_activating_page() {
1311 1201 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1202 + if ( false !== strpos( $referer, 'frm_action=settings' ) ) {
1203 + return 'settings';
1204 + }
1312 1205
1313 - if ( str_contains( $referer, 'frm_action=settings' ) ) {
1314 - return 'settings';
1206 + if ( false !== strpos( $referer, 'frm_action=edit' ) ) {
1207 + return 'form_builder';
1315 1208 }
1316 1209
1317 - return str_contains( $referer, 'frm_action=edit' ) ? 'form_builder' : '';
1210 + return '';
1318 1211 }
1319 1212
1320 1213 /**
1321 1214 * Run security checks before installing
@@ -1326,14 +1219,12 @@
1326 1219 */
1327 1220 protected static function install_addon_permissions() {
1328 1221 check_ajax_referer( 'frm_ajax', 'nonce' );
1329 1222
1330 - if ( current_user_can( 'activate_plugins' ) && self::get_current_plugin() ) {
1331 - return;
1223 + if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) {
1224 + echo json_encode( true );
1225 + wp_die();
1332 1226 }
1333 -
1334 - echo json_encode( true );
1335 - wp_die();
1336 1227 }
1337 1228
1338 1229 /**
1339 1230 * @since 4.08
@@ -1341,14 +1232,12 @@
1341 1232 * @return string
1342 1233 */
1343 1234 public static function connect_link() {
1344 1235 $auth = get_option( 'frm_connect_token' );
1345 -
1346 - if ( ! $auth ) {
1236 + if ( empty( $auth ) ) {
1347 1237 $auth = hash( 'sha512', wp_rand() );
1348 - update_option( 'frm_connect_token', $auth, false );
1238 + update_option( 'frm_connect_token', $auth, 'no' );
1349 1239 }
1350 -
1351 1240 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title', 'formidable-settings' );
1352 1241 $link = 'https://formidableforms.com/api-connect/';
1353 1242 $args = array(
1354 1243 'v' => 2,
@@ -1376,10 +1265,9 @@
1376 1265 $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' );
1377 1266
1378 1267 // The download link is not required if already installed.
1379 1268 $is_installed = FrmAppHelper::pro_is_included();
1380 - $file_missing = ! $is_installed && ! $post_url;
1381 -
1269 + $file_missing = ! $is_installed && empty( $post_url );
1382 1270 if ( ! $post_auth || $file_missing ) {
1383 1271 return false;
1384 1272 }
1385 1273
@@ -1384,9 +1272,13 @@
1384 1272 }
1385 1273
1386 1274 // Verify auth.
1387 1275 $auth = get_option( 'frm_connect_token' );
1388 - return $auth && hash_equals( $auth, $post_auth );
1276 + if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) {
1277 + return false;
1278 + }
1279 +
1280 + return true;
1389 1281 }
1390 1282
1391 1283 /**
1392 1284 * Install and/or activate the add-on file.
@@ -1397,17 +1289,17 @@
1397 1289 */
1398 1290 public static function install_addon_api() {
1399 1291 self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1400 1292
1293 + $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' );
1294 +
1401 1295 // Delete so cannot replay.
1402 1296 delete_option( 'frm_connect_token' );
1403 1297
1404 1298 // It's already installed and active.
1405 1299 $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1406 -
1407 1300 if ( is_wp_error( $active ) ) {
1408 1301 $response = self::maybe_download_and_activate();
1409 -
1410 1302 if ( is_array( $response ) ) {
1411 1303 // The download failed.
1412 1304 return $response;
1413 1305 }
@@ -1413,12 +1305,11 @@
1413 1305 }
1414 1306 }
1415 1307
1416 1308 // If empty license, save it now.
1417 - if ( ! self::get_pro_license() && function_exists( 'load_formidable_pro' ) ) {
1309 + if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) {
1418 1310 load_formidable_pro();
1419 1311 $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) );
1420 -
1421 1312 if ( ! $license ) {
1422 1313 return array(
1423 1314 'success' => false,
1424 1315 'error' => 'That site does not have a valid license key.',
@@ -1425,9 +1316,8 @@
1425 1316 );
1426 1317 }
1427 1318
1428 1319 $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' );
1429 -
1430 1320 if ( ! $response['success'] ) {
1431 1321 // Could not activate license.
1432 1322 return $response;
1433 1323 }
@@ -1452,9 +1342,8 @@
1452 1342 }
1453 1343
1454 1344 // Download plugin now.
1455 1345 $response = self::download_and_activate();
1456 -
1457 1346 if ( is_array( $response ) && isset( $response['success'] ) ) {
1458 1347 // The download failed.
1459 1348 return $response;
1460 1349 }
@@ -1468,9 +1357,8 @@
1468 1357 * @since 4.09
1469 1358 *
1470 1359 * @param string $plugin
1471 1360 * @param array|string $upgrade_link_args
1472 - *
1473 1361 * @return void
1474 1362 */
1475 1363 public static function conditional_action_button( $plugin, $upgrade_link_args ) {
1476 1364 if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) {
@@ -1505,9 +1393,8 @@
1505 1393 * @type false|string $license_type
1506 1394 * @type string $plan_required
1507 1395 * @type string $upgrade_link
1508 1396 * }
1509 - *
1510 1397 * @return void
1511 1398 */
1512 1399 public static function show_conditional_action_button( $atts ) {
1513 1400 if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) {
@@ -1540,19 +1427,16 @@
1540 1427 $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1541 1428 }
1542 1429
1543 1430 $class = ! empty( $atts['class'] ) ? $atts['class'] : '';
1544 -
1545 - if ( ! str_contains( $class, 'frm-button' ) ) {
1431 + if ( strpos( $class, 'frm-button' ) === false ) {
1546 1432 $class .= ' frm-button-secondary frm-button-sm';
1547 1433 }
1548 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1549 1434 ?>
1550 - <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' ); ?>">
1551 1436 <?php echo esc_html( $text ); ?>
1552 1437 </a>
1553 1438 <?php
1554 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1555 1439 }
1556 1440
1557 1441 /**
1558 1442 * @since 3.04.02
@@ -1562,9 +1446,8 @@
1562 1446 public static function ajax_install_addon() {
1563 1447 self::install_addon_permissions();
1564 1448
1565 1449 $result = self::download_and_activate();
1566 -
1567 1450 if ( isset( $result['success'] ) && ! $result['success'] ) {
1568 1451 echo json_encode( $result );
1569 1452 wp_die();
1570 1453 }
@@ -1597,8 +1480,9 @@
1597 1480 $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list );
1598 1481
1599 1482 if ( ! is_array( $allowed_url_list ) ) {
1600 1483 _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' );
1484 +
1601 1485 return array();
1602 1486 }
1603 1487
1604 1488 return $allowed_url_list;
@@ -1608,10 +1492,8 @@
1608 1492 * Gets required plan for an addon.
1609 1493 *
1610 1494 * @since 6.4.2
1611 1495 *
1612 - * @param int|string $addon_id
1613 - *
1614 1496 * @return string Empty string if no plan is required for active license.
1615 1497 */
1616 1498 public static function get_addon_required_plan( $addon_id ) {
1617 1499 $api = new FrmFormApi();
@@ -1622,9 +1504,9 @@
1622 1504 $requires = FrmFormsHelper::get_plan_required( $dates );
1623 1505 }
1624 1506
1625 1507 if ( ! isset( $requires ) || ! is_string( $requires ) ) {
1626 - return '';
1508 + $requires = '';
1627 1509 }
1628 1510
1629 1511 return $requires;
1630 1512 }