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