PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16
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 +152 -246 6.306.16 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(
@@ -193,18 +183,15 @@
193 183 );
194 184
195 185 // Extract the elements to move
196 186 foreach ( $plans as $plan ) {
197 - if ( ! isset( self::$categories[ $plan ] ) ) {
198 - continue;
187 + if ( isset( self::$categories[ $plan ] ) ) {
188 + $bottom_categories[ $plan ] = self::$categories[ $plan ];
189 + unset( self::$categories[ $plan ] );
199 190 }
200 -
201 - $bottom_categories[ $plan ] = self::$categories[ $plan ];
202 - unset( self::$categories[ $plan ] );
203 191 }
204 192
205 193 $special_categories = array();
206 -
207 194 if ( 'elite' !== self::license_type() ) {
208 195 $special_categories['available-addons'] = array(
209 196 'name' => __( 'Available', 'formidable' ),
210 197 // To be assigned via JavaScript.
@@ -236,9 +223,8 @@
236 223 *
237 224 * @since 6.15
238 225 *
239 226 * @param array $addon The addon array that will be modified by reference.
240 - *
241 227 * @return void
242 228 */
243 229 protected static function set_categories( &$addon ) {
244 230 if ( ! isset( $addon['categories'] ) ) {
@@ -269,11 +255,11 @@
269 255 * @return void
270 256 */
271 257 public static function license_settings() {
272 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' );
273 261
274 - if ( ! $plugins ) {
275 - esc_html_e( 'There are no plugins on your site that require a license', 'formidable' );
276 262 return;
277 263 }
278 264
279 265 ksort( $plugins );
@@ -287,15 +273,15 @@
287 273 protected static function get_api_addons() {
288 274 $api = new FrmFormApi();
289 275 $addons = $api->get_api_info();
290 276
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 ] );
277 + if ( empty( $addons ) ) {
278 + $addons = self::fallback_plugin_list();
279 + } else {
280 + foreach ( $addons as $k => $addon ) {
281 + if ( empty( $addon['excerpt'] ) && $k !== 'error' ) {
282 + unset( $addons[ $k ] );
283 + }
298 284 }
299 285 }
300 286
301 287 return $addons;
@@ -308,9 +294,11 @@
308 294 *
309 295 * @return int Count of addons.
310 296 */
311 297 public static function get_addons_count() {
312 - return count( self::get_api_addons() );
298 + $addons = self::get_api_addons();
299 +
300 + return count( $addons );
313 301 }
314 302
315 303 /**
316 304 * If the API is unable to connect, show something on the addons page
@@ -315,9 +303,8 @@
315 303 /**
316 304 * If the API is unable to connect, show something on the addons page
317 305 *
318 306 * @since 3.04.03
319 - *
320 307 * @return array
321 308 */
322 309 protected static function fallback_plugin_list() {
323 310 $list = array(
@@ -328,19 +315,19 @@
328 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.',
329 316 ),
330 317 'mailchimp' => array(
331 318 '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
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.',
333 320 ),
334 321 'registration' => array(
335 322 'title' => 'User Registration Forms',
336 323 '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
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.',
338 325 ),
339 326 'paypal' => array(
340 327 'title' => 'PayPal Standard Forms',
341 328 '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
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.',
343 330 ),
344 331 'stripe' => array(
345 332 'title' => 'Stripe Forms',
346 333 'docs' => 'knowledgebase/stripe/',
@@ -372,9 +359,9 @@
372 359 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
373 360 ),
374 361 'zapier' => array(
375 362 '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
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.',
377 364 ),
378 365 'signature' => array(
379 366 'title' => 'Digital Signature Forms',
380 367 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
@@ -407,9 +394,8 @@
407 394 foreach ( $list as $k => $info ) {
408 395 $info['slug'] = $k;
409 396 $list[ $k ] = array_merge( $defaults, $info );
410 397 }
411 -
412 398 return $list;
413 399 }
414 400
415 401 /**
@@ -415,28 +401,25 @@
415 401 /**
416 402 * If Pro is missing but has been authenticated, include a download URL
417 403 *
418 404 * @since 3.04.03
419 - *
420 405 * @return string
421 406 */
422 407 public static function get_pro_download_url() {
423 - $api = new FrmFormApi( self::get_pro_license() );
408 + $license = self::get_pro_license();
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(
@@ -725,81 +684,34 @@
725 684 return $link;
726 685 }
727 686
728 687 /**
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 688 * @since 4.09
769 - *
770 689 * @param string $plugin The plugin slug.
771 - *
772 690 * @return array|false
773 691 */
774 692 public static function get_addon( $plugin ) {
775 693 $addons = self::get_api_addons();
776 694 self::prepare_addons( $addons );
777 -
778 695 foreach ( $addons as $addon ) {
779 696 $slug = explode( '/', $addon['plugin'] );
780 -
781 697 if ( $slug[0] === 'formidable-' . $plugin ) {
782 698 return $addon;
783 699 }
784 700 }
785 -
786 701 return false;
787 702 }
788 703
789 704 /**
790 705 * @since 4.09
791 - *
792 706 * @return string
793 707 */
794 708 protected static function get_license_type() {
795 709 $license_type = '';
796 710 $addons = self::get_api_addons();
797 -
798 711 if ( isset( $addons['error'] ) && isset( $addons['error']['type'] ) ) {
799 - return $addons['error']['type'];
712 + $license_type = $addons['error']['type'];
800 713 }
801 -
802 714 return $license_type;
803 715 }
804 716
805 717 /**
@@ -812,12 +724,11 @@
812 724 */
813 725 public static function get_addon_for_license( $addons, $license ) {
814 726 $download_id = $license->download_id;
815 727 $plugin = array();
816 -
817 - if ( ! $download_id && $addons ) {
728 + if ( empty( $download_id ) && ! empty( $addons ) ) {
818 729 foreach ( $addons as $addon ) {
819 - if ( 0 === strcasecmp( $license->plugin_name, $addon['title'] ) ) {
730 + if ( strtolower( $license->plugin_name ) === strtolower( $addon['title'] ) ) {
820 731 return $addon;
821 732 }
822 733 }
823 734 } elseif ( isset( $addons[ $download_id ] ) ) {
@@ -827,33 +738,29 @@
827 738 return $plugin;
828 739 }
829 740
830 741 /**
831 - * @param array $addons
832 - *
833 742 * @return void
834 743 */
835 744 protected static function prepare_addons( &$addons ) {
836 - // Reset categories to prevent count accumulation across multiple calls.
837 - self::$categories = array();
838 -
839 745 $activate_url = '';
840 -
841 746 if ( current_user_can( 'activate_plugins' ) ) {
842 747 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
843 748 }
844 749
845 750 $loop_addons = $addons;
846 -
847 751 foreach ( $loop_addons as $id => $addon ) {
848 752 if ( is_numeric( $id ) ) {
849 753 $slug = str_replace( array( '-wordpress-plugin', '-wordpress' ), '', $addon['slug'] );
850 754 $file_name = $addon['plugin'];
851 755 } else {
852 - $slug = $id;
853 - $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 + }
854 762 $file_name = $base_file . '/' . $base_file . '.php';
855 -
856 763 if ( ! isset( $addon['plugin'] ) ) {
857 764 $addon['plugin'] = $file_name;
858 765 }
859 766 }
@@ -858,17 +765,10 @@
858 765 }
859 766 }
860 767
861 768 $addon['installed'] = self::is_installed( $file_name );
862 -
863 - if ( 'highrise' === $slug && ! $addon['installed'] ) {
864 - unset( $addons[ $id ] );
865 - continue;
866 - }
867 -
868 769 if ( $addon['installed'] && 'formidable-views/formidable-views.php' === $file_name ) {
869 770 $active_views_version = self::get_active_views_version();
870 -
871 771 if ( false !== $active_views_version && $slug !== $active_views_version ) {
872 772 $addon['installed'] = false;
873 773 }
874 774 }
@@ -874,9 +774,9 @@
874 774 }
875 775
876 776 $addon['activate_url'] = '';
877 777
878 - 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 ) ) {
879 779 $addon['activate_url'] = add_query_arg(
880 780 array(
881 781 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
882 782 'plugin' => $file_name,
@@ -902,11 +802,8 @@
902 802 }//end foreach
903 803 }
904 804
905 805 /**
906 - * @param string $file_name
907 - * @param string $slug
908 - *
909 806 * @return bool
910 807 */
911 808 private static function is_plugin_active( $file_name, $slug ) {
912 809 if ( 'formidable-views/formidable-views.php' === $file_name ) {
@@ -921,9 +818,8 @@
921 818 private static function get_active_views_version() {
922 819 if ( ! is_callable( 'FrmViewsAppHelper::plugin_version' ) ) {
923 820 return false;
924 821 }
925 -
926 822 $plugin_version = FrmViewsAppHelper::plugin_version();
927 823 return version_compare( $plugin_version, '5.0', '>=' ) ? 'visual-views' : 'views';
928 824 }
929 825
@@ -929,25 +825,22 @@
929 825
930 826 /**
931 827 * @since 3.04.02
932 828 *
933 - * @param string $link
934 - *
935 829 * @return void
936 830 */
937 831 protected static function prepare_addon_link( &$link ) {
938 832 $site_url = 'https://formidableforms.com/';
939 -
940 - if ( ! str_starts_with( $link, 'http' ) ) {
833 + if ( strpos( $link, 'http' ) !== 0 ) {
941 834 $link = $site_url . $link;
942 835 }
943 -
944 - $link = FrmAppHelper::make_affiliate_url( $link );
945 -
946 - $utm = array(
947 - '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',
948 841 );
949 - $link = FrmAppHelper::maybe_add_missing_utm( $link, $utm );
842 + $link = add_query_arg( $query_args, $link );
950 843 }
951 844
952 845 /**
953 846 * Add the status to the addon array. Status options are:
@@ -954,10 +847,8 @@
954 847 * installed, active, not installed
955 848 *
956 849 * @since 3.04.02
957 850 *
958 - * @param array $addon
959 - *
960 851 * @return void
961 852 */
962 853 protected static function set_addon_status( &$addon ) {
963 854 if ( ! empty( $addon['activate_url'] ) ) {
@@ -984,9 +875,8 @@
984 875 * @param string $plugin
985 876 * @param string $redirect
986 877 * @param bool $network_wide
987 878 * @param bool $silent
988 - *
989 879 * @return WP_Error|null Null on success, WP_Error on invalid file.
990 880 */
991 881 protected static function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
992 882 if ( ! function_exists( 'activate_plugin' ) ) {
@@ -1001,9 +891,8 @@
1001 891 * @since 6.8
1002 892 *
1003 893 * @param string $plugin
1004 894 * @param bool $silent
1005 - *
1006 895 * @return void
1007 896 */
1008 897 protected static function deactivate_plugin( $plugin, $silent = false ) {
1009 898 if ( ! function_exists( 'deactivate_plugins' ) ) {
@@ -1017,9 +906,8 @@
1017 906 *
1018 907 * @since 6.8
1019 908 *
1020 909 * @param string $plugin
1021 - *
1022 910 * @return true|WP_Error True on success, WP_Error on invalid file.
1023 911 */
1024 912 protected static function uninstall_plugin( $plugin ) {
1025 913 if ( ! current_user_can( 'delete_plugins' ) ) {
@@ -1032,9 +920,13 @@
1032 920
1033 921 self::deactivate_plugin( $plugin, true );
1034 922 $result = delete_plugins( array( $plugin ) );
1035 923
1036 - return is_wp_error( $result ) ? $result : true;
924 + if ( is_wp_error( $result ) ) {
925 + return $result;
926 + }
927 +
928 + return true;
1037 929 }
1038 930
1039 931 /**
1040 932 * @since 5.0.10
@@ -1041,9 +933,9 @@
1041 933 *
1042 934 * @return string
1043 935 */
1044 936 protected static function get_current_plugin() {
1045 - if ( ! self::$plugin ) {
937 + if ( empty( self::$plugin ) ) {
1046 938 self::$plugin = FrmAppHelper::get_param( 'plugin', '', 'post', 'esc_url_raw' );
1047 939 }
1048 940 return self::$plugin;
1049 941 }
@@ -1050,9 +942,9 @@
1050 942
1051 943 /**
1052 944 * @since 4.08
1053 945 *
1054 - * @return mixed[]|null
946 + * @return array|void
1055 947 */
1056 948 protected static function download_and_activate() {
1057 949 if ( is_admin() ) {
1058 950 FrmAppHelper::set_current_screen_and_hook_suffix();
@@ -1060,14 +952,12 @@
1060 952
1061 953 self::maybe_show_cred_form();
1062 954
1063 955 $installed = self::install_addon();
1064 -
1065 956 if ( is_array( $installed ) && isset( $installed['message'] ) ) {
1066 957 return $installed;
1067 958 }
1068 959 self::handle_addon_action( $installed, 'activate' );
1069 - return null;
1070 960 }
1071 961
1072 962 /**
1073 963 * @since 3.04.02
@@ -1078,9 +968,9 @@
1078 968 if ( ! function_exists( 'request_filesystem_credentials' ) ) {
1079 969 include_once ABSPATH . 'wp-admin/includes/file.php';
1080 970 }
1081 971
1082 - // 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.
1083 973 ob_start();
1084 974
1085 975 $show_form = false;
1086 976 $method = '';
@@ -1097,8 +987,9 @@
1097 987
1098 988 if ( $show_form ) {
1099 989 $form = ob_get_clean();
1100 990 $message = __( 'Sorry, your site requires FTP authentication. Please download plugins from FormidableForms.com and install them manually.', 'formidable' );
991 + $data = $form;
1101 992 $response = array(
1102 993 'success' => false,
1103 994 'message' => $message,
1104 995 'form' => $form,
@@ -1126,10 +1017,8 @@
1126 1017 * We do not need any extra credentials if we have gotten this far,
1127 1018 * so let's install the plugin.
1128 1019 *
1129 1020 * @since 3.04.02
1130 - *
1131 - * @return array|string
1132 1021 */
1133 1022 protected static function install_addon() {
1134 1023 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
1135 1024
@@ -1143,15 +1032,14 @@
1143 1032 }
1144 1033
1145 1034 // Create the plugin upgrader with our custom skin.
1146 1035 $installer = new Plugin_Upgrader( new FrmInstallerSkin() );
1147 - $installer->install( $download_url, array( 'overwrite_package' => true ) );
1036 + $installer->install( $download_url );
1148 1037
1149 1038 // Flush the cache and return the newly installed plugin basename.
1150 1039 wp_cache_flush();
1151 1040
1152 1041 $plugin = $installer->plugin_info();
1153 -
1154 1042 if ( ! $plugin ) {
1155 1043 return array(
1156 1044 'message' => 'Plugin was not installed. ' . $installer->result,
1157 1045 'success' => false,
@@ -1156,9 +1044,8 @@
1156 1044 'message' => 'Plugin was not installed. ' . $installer->result,
1157 1045 'success' => false,
1158 1046 );
1159 1047 }
1160 -
1161 1048 return $plugin;
1162 1049 }
1163 1050
1164 1051 /**
@@ -1222,9 +1109,8 @@
1222 1109 * @since 6.8
1223 1110 *
1224 1111 * @param callable $action_callback The specific add-on action to be executed.
1225 1112 * @param callable|null $response_callback Optional. The response handling callback. Default null.
1226 - *
1227 1113 * @return void
1228 1114 */
1229 1115 private static function process_addon_action( $action_callback, $response_callback = null ) {
1230 1116 self::install_addon_permissions();
@@ -1247,14 +1133,13 @@
1247 1133 * @since 6.8
1248 1134 *
1249 1135 * @param string $installed The plugin folder name with file name.
1250 1136 * @param string $action The action type ('activate', 'deactivate', 'uninstall').
1251 - *
1252 - * @return mixed[]|null
1137 + * @return array|void
1253 1138 */
1254 1139 protected static function handle_addon_action( $installed, $action ) {
1255 1140 if ( ! $installed || ! $action ) {
1256 - return null;
1141 + return;
1257 1142 }
1258 1143
1259 1144 $result = null;
1260 1145 switch ( $action ) {
@@ -1274,9 +1159,8 @@
1274 1159 if ( $result->get_error_code() !== 'no_plugin_header' ) {
1275 1160 if ( wp_doing_ajax() ) {
1276 1161 wp_send_json_error( array( 'error' => $result->get_error_message() ) );
1277 1162 }
1278 -
1279 1163 return array(
1280 1164 'message' => $result->get_error_message(),
1281 1165 'success' => false,
1282 1166 );
@@ -1290,14 +1174,17 @@
1290 1174 * @return array
1291 1175 */
1292 1176 private static function get_addon_activation_response() {
1293 1177 $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 1178
1296 - 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(
1297 1182 'message' => $message,
1298 1183 'saveAndReload' => $activating_page,
1299 1184 );
1185 +
1186 + return $response;
1300 1187 }
1301 1188
1302 1189 /**
1303 1190 * Return a string that reflects the page from which the addon is being activated on,
@@ -1306,14 +1193,17 @@
1306 1193 * @return string
1307 1194 */
1308 1195 private static function get_activating_page() {
1309 1196 $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1197 + if ( false !== strpos( $referer, 'frm_action=settings' ) ) {
1198 + return 'settings';
1199 + }
1310 1200
1311 - if ( str_contains( $referer, 'frm_action=settings' ) ) {
1312 - return 'settings';
1201 + if ( false !== strpos( $referer, 'frm_action=edit' ) ) {
1202 + return 'form_builder';
1313 1203 }
1314 1204
1315 - return str_contains( $referer, 'frm_action=edit' ) ? 'form_builder' : '';
1205 + return '';
1316 1206 }
1317 1207
1318 1208 /**
1319 1209 * Run security checks before installing
@@ -1324,14 +1214,12 @@
1324 1214 */
1325 1215 protected static function install_addon_permissions() {
1326 1216 check_ajax_referer( 'frm_ajax', 'nonce' );
1327 1217
1328 - if ( current_user_can( 'activate_plugins' ) && self::get_current_plugin() ) {
1329 - return;
1218 + if ( ! current_user_can( 'activate_plugins' ) || ! self::get_current_plugin() ) {
1219 + echo json_encode( true );
1220 + wp_die();
1330 1221 }
1331 -
1332 - echo json_encode( true );
1333 - wp_die();
1334 1222 }
1335 1223
1336 1224 /**
1337 1225 * @since 4.08
@@ -1339,14 +1227,12 @@
1339 1227 * @return string
1340 1228 */
1341 1229 public static function connect_link() {
1342 1230 $auth = get_option( 'frm_connect_token' );
1343 -
1344 - if ( ! $auth ) {
1231 + if ( empty( $auth ) ) {
1345 1232 $auth = hash( 'sha512', wp_rand() );
1346 - update_option( 'frm_connect_token', $auth, false );
1233 + update_option( 'frm_connect_token', $auth, 'no' );
1347 1234 }
1348 -
1349 1235 $page = FrmAppHelper::simple_get( 'page', 'sanitize_title', 'formidable-settings' );
1350 1236 $link = 'https://formidableforms.com/api-connect/';
1351 1237 $args = array(
1352 1238 'v' => 2,
@@ -1374,10 +1260,9 @@
1374 1260 $post_url = FrmAppHelper::get_param( 'file_url', '', 'request', 'sanitize_text_field' );
1375 1261
1376 1262 // The download link is not required if already installed.
1377 1263 $is_installed = FrmAppHelper::pro_is_included();
1378 - $file_missing = ! $is_installed && ! $post_url;
1379 -
1264 + $file_missing = ! $is_installed && empty( $post_url );
1380 1265 if ( ! $post_auth || $file_missing ) {
1381 1266 return false;
1382 1267 }
1383 1268
@@ -1382,9 +1267,13 @@
1382 1267 }
1383 1268
1384 1269 // Verify auth.
1385 1270 $auth = get_option( 'frm_connect_token' );
1386 - return $auth && hash_equals( $auth, $post_auth );
1271 + if ( empty( $auth ) || ! hash_equals( $auth, $post_auth ) ) {
1272 + return false;
1273 + }
1274 +
1275 + return true;
1387 1276 }
1388 1277
1389 1278 /**
1390 1279 * Install and/or activate the add-on file.
@@ -1395,17 +1284,17 @@
1395 1284 */
1396 1285 public static function install_addon_api() {
1397 1286 self::$plugin = FrmAppHelper::get_param( 'file_url', '', 'request', 'esc_url_raw' );
1398 1287
1288 + $error = esc_html__( 'Could not install an upgrade. Please download from formidableforms.com and install manually.', 'formidable' );
1289 +
1399 1290 // Delete so cannot replay.
1400 1291 delete_option( 'frm_connect_token' );
1401 1292
1402 1293 // It's already installed and active.
1403 1294 $active = self::activate_plugin( 'formidable-pro/formidable-pro.php', false, false, true );
1404 -
1405 1295 if ( is_wp_error( $active ) ) {
1406 1296 $response = self::maybe_download_and_activate();
1407 -
1408 1297 if ( is_array( $response ) ) {
1409 1298 // The download failed.
1410 1299 return $response;
1411 1300 }
@@ -1411,12 +1300,11 @@
1411 1300 }
1412 1301 }
1413 1302
1414 1303 // If empty license, save it now.
1415 - if ( ! self::get_pro_license() && function_exists( 'load_formidable_pro' ) ) {
1304 + if ( empty( self::get_pro_license() ) && function_exists( 'load_formidable_pro' ) ) {
1416 1305 load_formidable_pro();
1417 1306 $license = stripslashes( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) );
1418 -
1419 1307 if ( ! $license ) {
1420 1308 return array(
1421 1309 'success' => false,
1422 1310 'error' => 'That site does not have a valid license key.',
@@ -1423,9 +1311,8 @@
1423 1311 );
1424 1312 }
1425 1313
1426 1314 $response = FrmAddon::activate_license_for_plugin( $license, 'formidable_pro' );
1427 -
1428 1315 if ( ! $response['success'] ) {
1429 1316 // Could not activate license.
1430 1317 return $response;
1431 1318 }
@@ -1450,9 +1337,8 @@
1450 1337 }
1451 1338
1452 1339 // Download plugin now.
1453 1340 $response = self::download_and_activate();
1454 -
1455 1341 if ( is_array( $response ) && isset( $response['success'] ) ) {
1456 1342 // The download failed.
1457 1343 return $response;
1458 1344 }
@@ -1466,9 +1352,8 @@
1466 1352 * @since 4.09
1467 1353 *
1468 1354 * @param string $plugin
1469 1355 * @param array|string $upgrade_link_args
1470 - *
1471 1356 * @return void
1472 1357 */
1473 1358 public static function conditional_action_button( $plugin, $upgrade_link_args ) {
1474 1359 if ( is_callable( 'FrmProAddonsController::conditional_action_button' ) ) {
@@ -1503,9 +1388,8 @@
1503 1388 * @type false|string $license_type
1504 1389 * @type string $plan_required
1505 1390 * @type string $upgrade_link
1506 1391 * }
1507 - *
1508 1392 * @return void
1509 1393 */
1510 1394 public static function show_conditional_action_button( $atts ) {
1511 1395 if ( is_callable( 'FrmProAddonsController::show_conditional_action_button' ) ) {
@@ -1526,9 +1410,8 @@
1526 1410 */
1527 1411 public static function addon_upgrade_link( $addon, $upgrade_link ) {
1528 1412 $atts = is_array( $upgrade_link ) ? $upgrade_link : array();
1529 1413 $upgrade_link = is_array( $upgrade_link ) ? $upgrade_link['link'] : $upgrade_link;
1530 - $text = ! empty( $atts['text'] ) ? $atts['text'] : __( 'Upgrade Now', 'formidable' );
1531 1414
1532 1415 if ( $addon ) {
1533 1416 $upgrade_link .= '&utm_content=' . $addon['slug'];
1534 1417 }
@@ -1538,19 +1421,16 @@
1538 1421 $upgrade_link = FrmAppHelper::admin_upgrade_link( 'addons', $addon['link'] );
1539 1422 }
1540 1423
1541 1424 $class = ! empty( $atts['class'] ) ? $atts['class'] : '';
1542 -
1543 - if ( ! str_contains( $class, 'frm-button' ) ) {
1425 + if ( strpos( $class, 'frm-button' ) === false ) {
1544 1426 $class .= ' frm-button-secondary frm-button-sm';
1545 1427 }
1546 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1547 1428 ?>
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 ?>
1549 - <?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' ); ?>
1550 1431 </a>
1551 1432 <?php
1552 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1553 1433 }
1554 1434
1555 1435 /**
1556 1436 * @since 3.04.02
@@ -1560,9 +1440,8 @@
1560 1440 public static function ajax_install_addon() {
1561 1441 self::install_addon_permissions();
1562 1442
1563 1443 $result = self::download_and_activate();
1564 -
1565 1444 if ( isset( $result['success'] ) && ! $result['success'] ) {
1566 1445 echo json_encode( $result );
1567 1446 wp_die();
1568 1447 }
@@ -1595,8 +1474,9 @@
1595 1474 $allowed_url_list = apply_filters( 'frm_allowed_external_urls', $allowed_url_list );
1596 1475
1597 1476 if ( ! is_array( $allowed_url_list ) ) {
1598 1477 _doing_it_wrong( __METHOD__, 'Only an array of URLs could be used within this filter.', '6.3.1' );
1478 +
1599 1479 return array();
1600 1480 }
1601 1481
1602 1482 return $allowed_url_list;
@@ -1606,10 +1486,8 @@
1606 1486 * Gets required plan for an addon.
1607 1487 *
1608 1488 * @since 6.4.2
1609 1489 *
1610 - * @param int|string $addon_id
1611 - *
1612 1490 * @return string Empty string if no plan is required for active license.
1613 1491 */
1614 1492 public static function get_addon_required_plan( $addon_id ) {
1615 1493 $api = new FrmFormApi();
@@ -1620,10 +1498,38 @@
1620 1498 $requires = FrmFormsHelper::get_plan_required( $dates );
1621 1499 }
1622 1500
1623 1501 if ( ! isset( $requires ) || ! is_string( $requires ) ) {
1624 - return '';
1502 + $requires = '';
1625 1503 }
1626 1504
1627 1505 return $requires;
1506 + }
1507 +
1508 + /**
1509 + * @since 4.02.05
1510 + * @deprecated 6.8.3
1511 + *
1512 + * @codeCoverageIgnore
1513 + *
1514 + * @return void
1515 + */
1516 + public static function connect_pro() {
1517 + _deprecated_function( __METHOD__, '6.8.3' );
1518 + }
1519 +
1520 + /**
1521 + * @since 4.08
1522 + * @deprecated 6.11.1
1523 + *
1524 + * @return bool|int false or the number of days until expiration.
1525 + */
1526 + public static function is_license_expiring() {
1527 + _deprecated_function( __METHOD__, '6.11.1', 'FrmProAddonsController::is_license_expiring' );
1528 +
1529 + if ( is_callable( 'FrmProAddonsController::is_license_expiring' ) ) {
1530 + return FrmProAddonsController::is_license_expiring();
1531 + }
1532 +
1533 + return false;
1628 1534 }
1629 1535 }