PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.3.0
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.3.0
2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 All 96 releases
← All changes | admin/admin.php +81 -562 2.8.02.3.0 View file →
@@ -6,9 +6,8 @@
6 6 */
7 7
8 8 namespace SRFM\Admin;
9 9
10 -use Astra_Notices;
11 10 use SRFM\Inc\AI_Form_Builder\AI_Helper;
12 11 use SRFM\Inc\Database\Tables\Entries;
13 12 use SRFM\Inc\Helper;
14 13 use SRFM\Inc\Onboarding;
@@ -18,12 +17,8 @@
18 17
19 18 if ( ! defined( 'ABSPATH' ) ) {
20 19 exit; // Exit if accessed directly.
21 20 }
22 -
23 -if ( ! class_exists( 'Astra_Notices' ) ) {
24 - require_once SRFM_DIR . 'inc/lib/astra-notices/class-astra-notices.php';
25 -}
26 21 /**
27 22 * Admin handler class.
28 23 *
29 24 * @since 0.0.1
@@ -31,15 +26,8 @@
31 26 class Admin {
32 27 use Get_Instance;
33 28
34 29 /**
35 - * Minimum number of forms or entries required to show the rating notice.
36 - *
37 - * @since 2.5.2
38 - */
39 - public const RATING_NOTICE_THRESHOLD = 3;
40 -
41 - /**
42 30 * Dashboard widget entries data.
43 31 *
44 32 * @var array
45 33 * @since 1.9.1
@@ -46,16 +34,8 @@
46 34 */
47 35 private $dashboard_widget_data = [];
48 36
49 37 /**
50 - * Cached result for whether the rating notice should display.
51 - *
52 - * @var bool|null
53 - * @since 2.5.2
54 - */
55 - private $should_show_rating = null;
56 -
57 - /**
58 38 * SureForms Page Default permission.
59 39 *
60 40 * @var string
61 41 * @since 1.12.2
@@ -71,14 +51,11 @@
71 51 public function __construct() {
72 52 add_action( 'admin_menu', [ $this, 'add_menu_page' ], 9 );
73 53 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
74 54 add_action( 'admin_menu', [ $this, 'settings_page' ] );
75 - add_action( 'admin_menu', [ $this, 'add_learn_page' ] );
76 55 add_action( 'admin_menu', [ $this, 'add_new_form' ] );
77 56 add_action( 'admin_menu', [ $this, 'add_suremail_page' ] );
78 57 if ( ! Helper::has_pro() ) {
79 - add_action( 'admin_menu', [ $this, 'add_quiz_page' ] );
80 - add_action( 'admin_menu', [ $this, 'add_survey_reports_page' ] );
81 58 add_action( 'admin_menu', [ $this, 'add_upgrade_to_pro' ] );
82 59 add_action( 'admin_footer', [ $this, 'add_upgrade_to_pro_target_attr' ] );
83 60 }
84 61
@@ -90,13 +67,19 @@
90 67 // this action is used to restrict Spectra's quick action bar on SureForms CPTS.
91 68 add_action( 'uag_enable_quick_action_sidebar', [ $this, 'restrict_spectra_quick_action_bar' ] );
92 69
93 70 add_action( 'current_screen', [ $this, 'enable_gutenberg_for_sureforms' ], 100 );
94 - // Register notices early for React pages (before admin_enqueue_scripts).
95 - add_action( 'admin_init', [ $this, 'register_pro_compatibility_notices' ], 5 );
96 - // Display notices on traditional WordPress admin pages.
97 71 add_action( 'admin_notices', [ $this, 'srfm_pro_version_compatibility' ] );
98 72
73 + // This action enqueues translations for NPS Survey library.
74 + // A better solution will be required from library to resolve plugin conflict.
75 + add_action(
76 + 'admin_footer',
77 + static function() {
78 + Helper::register_script_translations( 'nps-survey-script' );
79 + },
80 + 1000
81 + );
99 82 // Enfold theme compatibility to enable block editor for SureForms post type.
100 83 add_filter( 'avf_use_block_editor_for_post', [ $this, 'enable_block_editor_in_enfold_theme' ] );
101 84
102 85 // Add action links to the plugin page.
@@ -108,8 +91,10 @@
108 91 if ( $admin_notification_on ) {
109 92 add_action( 'admin_menu', [ $this, 'maybe_add_entries_badge' ], 99 );
110 93 }
111 94
95 + add_action( 'admin_menu', [ $this, 'add_payments_badge' ], 99 );
96 +
112 97 add_filter( 'wpforms_current_user_can', [ $this, 'disable_wpforms_capabilities' ], 10, 3 );
113 98
114 99 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_pointer' ] );
115 100 // Ajax callbacks for wp-pointer functionality.
@@ -115,9 +100,8 @@
115 100 // Ajax callbacks for wp-pointer functionality.
116 101 add_action( 'wp_ajax_should_show_pointer', [ $this, 'pointer_should_show' ] );
117 102 add_action( 'wp_ajax_sureforms_dismiss_pointer', [ $this, 'pointer_dismissed' ] );
118 103 add_action( 'wp_ajax_sureforms_accept_cta', [ $this, 'pointer_accepted_cta' ] );
119 - add_action( 'wp_ajax_srfm_notice_response', [ $this, 'handle_notice_response' ] );
120 104
121 105 // Register dashboard widget only if there are recent entries.
122 106 add_action( 'admin_init', [ $this, 'maybe_register_dashboard_widget' ] );
123 107
@@ -122,10 +106,8 @@
122 106 add_action( 'admin_init', [ $this, 'maybe_register_dashboard_widget' ] );
123 107
124 108 // Save first form creation time stamp.
125 109 add_action( 'admin_init', [ $this, 'save_first_form_creation_time_stamp' ] );
126 - add_action( 'admin_notices', [ $this, 'display_srfm_rating_notice' ] );
127 - add_action( 'admin_notices', [ $this, 'display_srfm_getting_started_notice' ] );
128 110 }
129 111
130 112 /**
131 113 * Get the first form creation time stamp.
@@ -413,74 +395,8 @@
413 395 );
414 396 }
415 397
416 398 /**
417 - * Add Quiz empty state submenu page for free users.
418 - *
419 - * @return void
420 - * @since 2.7.0
421 - */
422 - public function add_quiz_page() {
423 - add_submenu_page(
424 - 'sureforms_menu',
425 - __( 'Quiz Entries', 'sureforms' ),
426 - __( 'Quizzes', 'sureforms' ) .
427 - ' <span style="color:#4ADE80;font-size:9px;font-weight:600;">' .
428 - esc_html__( 'New', 'sureforms' ) .
429 - '</span>',
430 - self::$sureforms_page_default_capability,
431 - 'sureforms_quiz_entries',
432 - [ $this, 'render_quiz_empty_state' ],
433 - 5
434 - );
435 - }
436 -
437 - /**
438 - * Quiz empty state page callback.
439 - *
440 - * @return void
441 - * @since 2.7.0
442 - */
443 - public function render_quiz_empty_state() {
444 - ?>
445 - <div id="srfm-quiz-entries-root" class="srfm-admin-wrapper"></div>
446 - <?php
447 - }
448 -
449 - /**
450 - * Add Survey Reports promotional submenu page for free users.
451 - *
452 - * @return void
453 - * @since 2.8.0
454 - */
455 - public function add_survey_reports_page() {
456 - add_submenu_page(
457 - 'sureforms_menu',
458 - __( 'Survey Reports', 'sureforms' ),
459 - __( 'Survey Reports', 'sureforms' ) .
460 - ' <span style="color:#4ADE80;font-size:9px;font-weight:600;">' .
461 - esc_html__( 'New', 'sureforms' ) .
462 - '</span>',
463 - self::$sureforms_page_default_capability,
464 - 'sureforms_survey_reports',
465 - [ $this, 'render_survey_empty_state' ],
466 - 6
467 - );
468 - }
469 -
470 - /**
471 - * Survey empty state page callback.
472 - *
473 - * @return void
474 - * @since 2.8.0
475 - */
476 - public function render_survey_empty_state() {
477 - ?>
478 - <div id="srfm-survey-empty-state-root" class="srfm-admin-wrapper"></div>
479 - <?php
480 - }
481 -
482 - /**
483 399 * Add SMTP promotional submenu page.
484 400 *
485 401 * @return void
486 402 * @since 1.7.1
@@ -542,37 +458,8 @@
542 458 <?php
543 459 }
544 460
545 461 /**
546 - * Add Learn submenu page.
547 - *
548 - * @return void
549 - * @since 2.5.2
550 - */
551 - public function add_learn_page() {
552 - add_submenu_page(
553 - 'sureforms_menu',
554 - __( 'Learn', 'sureforms' ),
555 - __( 'Learn', 'sureforms' ),
556 - self::$sureforms_page_default_capability,
557 - 'sureforms_learn',
558 - [ $this, 'render_learn' ]
559 - );
560 - }
561 -
562 - /**
563 - * Learn page callback.
564 - *
565 - * @return void
566 - * @since 2.5.2
567 - */
568 - public function render_learn() {
569 - ?>
570 - <div id="srfm-learn-root" class="srfm-admin-wrapper"></div>
571 - <?php
572 - }
573 -
574 - /**
575 462 * Add new form menu item.
576 463 *
577 464 * @return void
578 465 * @since 0.0.1
@@ -726,8 +613,36 @@
726 613 }
727 614 }
728 615
729 616 /**
617 + * Summary of add_payments_badge
618 + *
619 + * @since 2.0.0
620 + * @return void
621 + */
622 + public function add_payments_badge() {
623 + if ( ! Helper::current_user_can() ) {
624 + return;
625 + }
626 +
627 + global $submenu;
628 + if ( isset( $submenu['sureforms_menu'] ) ) {
629 + foreach ( $submenu['sureforms_menu'] as $index => $sub_item ) {
630 + if ( isset( $sub_item[2] ) && SRFM_PAYMENTS === $sub_item[2] ) {
631 + ob_start();
632 + ?>
633 + <span style="color: #4ADE80;font-size: 9px;font-weight: 600;"><?php echo esc_html__( 'New', 'sureforms' ); ?></span>
634 + <?php
635 + $new_badge_html = ob_get_clean();
636 + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Adding notifications for submenu item.
637 + $submenu['sureforms_menu'][ $index ][0] .= $new_badge_html;
638 + break;
639 + }
640 + }
641 + }
642 + }
643 +
644 + /**
730 645 * Mark the user's visit to the entries page.
731 646 *
732 647 * @since 1.7.3
733 648 * @return void
@@ -883,67 +798,50 @@
883 798 * List of the handles in which we need to add translation compatibility.
884 799 */
885 800 $script_translations_handlers = [];
886 801 $onboarding_instance = Onboarding::get_instance();
887 - $current_user = wp_get_current_user();
888 802
889 803 $localization_data = [
890 - 'site_url' => get_site_url(),
891 - 'current_user_login' => $current_user->user_login ?? '',
892 - 'website_lead_details' => [
893 - 'first_name' => $current_user->first_name ?? '',
894 - 'last_name' => $current_user->last_name ?? '',
895 - 'email' => $current_user->user_email ?? '',
804 + 'site_url' => get_site_url(),
805 + 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
806 + 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
807 + 'plugin_version' => SRFM_VER,
808 + 'global_settings_nonce' => Helper::current_user_can() ? wp_create_nonce( 'wp_rest' ) : '',
809 + 'is_pro_active' => Helper::has_pro(),
810 + 'is_first_form_created' => self::is_first_form_created(),
811 + 'check_three_days_threshold' => self::check_first_form_creation_threshold(),
812 + 'check_eight_days_threshold' => self::check_first_form_creation_threshold( 8 ),
813 + 'pro_plugin_version' => Helper::has_pro() ? SRFM_PRO_VER : '',
814 + 'pro_plugin_name' => Helper::has_pro() && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro',
815 + 'sureforms_pricing_page' => Helper::get_sureforms_website_url( 'pricing' ),
816 + 'field_spacing_vars' => Helper::get_css_vars(),
817 + 'is_ver_lower_than_6_7' => version_compare( $wp_version, '6.6.2', '<=' ),
818 + 'integrations' => Helper::sureforms_get_integration(),
819 + 'rotating_plugin_banner' => Helper::get_rotating_plugin_banner(),
820 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
821 + 'sf_plugin_manager_nonce' => wp_create_nonce( 'sf_plugin_manager_nonce' ),
822 + 'plugin_installer_nonce' => wp_create_nonce( 'updates' ),
823 + 'plugin_activating_text' => __( 'Activating...', 'sureforms' ),
824 + 'plugin_activated_text' => __( 'Activated', 'sureforms' ),
825 + 'plugin_activate_text' => __( 'Activate', 'sureforms' ),
826 + 'plugin_installing_text' => __( 'Installing...', 'sureforms' ),
827 + 'plugin_installed_text' => __( 'Installed', 'sureforms' ),
828 + 'is_rtl' => $is_rtl,
829 + 'onboarding_completed' => method_exists( $onboarding_instance, 'get_onboarding_status' ) ? $onboarding_instance->get_onboarding_status() : false,
830 + 'onboarding_redirect' => isset( $_GET['srfm-activation-redirect'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required for the activation redirection.
831 + 'pointer_nonce' => wp_create_nonce( 'sureforms_pointer_action' ),
832 + 'general_settings_url' => admin_url( '/options-general.php' ),
833 + 'payments' => [
834 + 'stripe_connected' => Stripe_Helper::is_stripe_connected(),
835 + 'stripe_mode' => Stripe_Helper::get_stripe_mode(),
836 + 'stripe_connect_url' => Stripe_Helper::get_stripe_settings_url(),
837 + 'currencies_data' => Payment_Helper::get_all_currencies_data(),
838 + 'zero_decimal_currencies' => Payment_Helper::get_zero_decimal_currencies(),
839 + 'webhook_url' => Stripe_Helper::get_webhook_url(),
840 + 'webhook_test_connected' => Stripe_Helper::is_webhook_configured( 'test', true ),
841 + 'webhook_live_connected' => Stripe_Helper::is_webhook_configured( 'live', true ),
842 + 'is_transaction_present' => Stripe_Helper::is_transaction_present(),
896 843 ],
897 - 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
898 - 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
899 - 'plugin_version' => SRFM_VER,
900 - 'global_settings_nonce' => Helper::current_user_can() ? wp_create_nonce( 'wp_rest' ) : '',
901 - 'is_pro_active' => Helper::has_pro(),
902 - 'is_first_form_created' => self::is_first_form_created(),
903 - 'check_three_days_threshold' => self::check_first_form_creation_threshold(),
904 - 'check_eight_days_threshold' => self::check_first_form_creation_threshold( 8 ),
905 - 'pro_plugin_version' => Helper::has_pro() ? SRFM_PRO_VER : '',
906 - 'pro_plugin_name' => Helper::has_pro() && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro',
907 - 'sureforms_pricing_page' => Helper::get_sureforms_website_url( 'pricing' ),
908 - 'field_spacing_vars' => Helper::get_css_vars(),
909 - 'is_ver_lower_than_6_7' => version_compare( $wp_version, '6.6.2', '<=' ),
910 - 'integrations' => Helper::sureforms_get_integration(),
911 - 'rotating_plugin_banner' => Helper::get_rotating_plugin_banner(),
912 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
913 - 'sf_plugin_manager_nonce' => wp_create_nonce( 'sf_plugin_manager_nonce' ),
914 - 'plugin_installer_nonce' => wp_create_nonce( 'updates' ),
915 - 'plugin_activating_text' => __( 'Activating...', 'sureforms' ),
916 - 'plugin_activated_text' => __( 'Activated', 'sureforms' ),
917 - 'plugin_activate_text' => __( 'Activate', 'sureforms' ),
918 - 'plugin_installing_text' => __( 'Installing...', 'sureforms' ),
919 - 'plugin_installed_text' => __( 'Installed', 'sureforms' ),
920 - 'privacy_policy_url' => Helper::get_sureforms_website_url( 'privacy-policy/' ),
921 - 'is_rtl' => $is_rtl,
922 - 'onboarding_completed' => method_exists( $onboarding_instance, 'get_onboarding_status' ) ? $onboarding_instance->get_onboarding_status() : false,
923 - 'onboarding_redirect' => isset( $_GET['srfm-activation-redirect'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required for the activation redirection.
924 - 'pointer_nonce' => wp_create_nonce( 'sureforms_pointer_action' ),
925 - 'general_settings_url' => admin_url( '/options-general.php' ),
926 - 'additional_header_nav_items' => [],
927 - 'payments' => apply_filters(
928 - 'srfm_admin_localize_payments_data',
929 - [
930 - 'stripe_connected' => Stripe_Helper::is_stripe_connected(),
931 - 'stripe_mode' => Stripe_Helper::get_stripe_mode(),
932 - 'stripe_connect_url' => Stripe_Helper::get_stripe_settings_url(),
933 - 'currencies_data' => Payment_Helper::get_all_currencies_data(),
934 - 'zero_decimal_currencies' => Payment_Helper::get_zero_decimal_currencies(),
935 - 'webhook_url' => Stripe_Helper::get_webhook_url(),
936 - 'webhook_test_connected' => Stripe_Helper::is_webhook_configured( 'test', true ),
937 - 'webhook_live_connected' => Stripe_Helper::is_webhook_configured( 'live', true ),
938 - 'is_transaction_present' => Stripe_Helper::is_transaction_present(),
939 - 'payment_currency' => Payment_Helper::get_currency(),
940 - 'currency_sign_position' => Payment_Helper::get_currency_sign_position(),
941 - ]
942 - ),
943 - 'mcp_adapter_status' => file_exists( WP_PLUGIN_DIR . '/mcp-adapter/mcp-adapter.php' )
944 - ? ( is_plugin_active( 'mcp-adapter/mcp-adapter.php' ) ? 'active' : 'installed' )
945 - : 'not_installed',
946 844 ];
947 845
948 846 $is_screen_sureforms_menu = Helper::validate_request_context( 'sureforms_menu', 'page' );
949 847 $is_screen_add_new_form = Helper::validate_request_context( 'add-new-form', 'page' );
@@ -950,11 +848,8 @@
950 848 $is_screen_sureforms_forms = Helper::validate_request_context( 'sureforms_forms', 'page' );
951 849 $is_screen_sureforms_form_settings = Helper::validate_request_context( 'sureforms_form_settings', 'page' );
952 850 $is_screen_sureforms_payments = Helper::validate_request_context( 'sureforms_payments', 'page' );
953 851 $is_screen_sureforms_entries = Helper::validate_request_context( SRFM_ENTRIES, 'page' );
954 - $is_screen_sureforms_learn = Helper::validate_request_context( 'sureforms_learn', 'page' );
955 - $is_screen_quiz_empty_state = Helper::validate_request_context( 'sureforms_quiz_entries', 'page' );
956 - $is_screen_survey_empty_state = Helper::validate_request_context( 'sureforms_survey_reports', 'page' );
957 852 $is_post_type_sureforms_form = SRFM_FORMS_POST_TYPE === $current_screen->post_type;
958 853
959 854 /**
960 855 * Check if the current screen is the SureForms Menu and AI Auth Email is present then we will add user type as registered.
@@ -966,34 +861,9 @@
966 861 'type' => ! empty( get_option( 'srfm_ai_auth_user_email' ) ) ? 'registered' : 'non-registered',
967 862 ];
968 863 }
969 864
970 - // Add the Quizzes and Survey Reports nav items when pro is not active.
971 - if ( ! Helper::has_pro() ) {
972 - $localization_data['additional_header_nav_items'][] = [
973 - 'slug' => 'sureforms_quiz_entries',
974 - 'text' => __( 'Quizzes', 'sureforms' ),
975 - 'link' => admin_url( 'admin.php?page=sureforms_quiz_entries' ),
976 - ];
977 - $localization_data['additional_header_nav_items'][] = [
978 - 'slug' => 'sureforms_survey_reports',
979 - 'text' => __( 'Survey Reports', 'sureforms' ),
980 - 'link' => admin_url( 'admin.php?page=sureforms_survey_reports' ),
981 - ];
982 - }
983 -
984 - $is_sureforms_screen = $is_screen_sureforms_menu || $is_post_type_sureforms_form || $is_screen_add_new_form || $is_screen_sureforms_forms || $is_screen_sureforms_form_settings || $is_screen_sureforms_entries || $is_screen_sureforms_payments || $is_screen_sureforms_learn || $is_screen_quiz_empty_state || $is_screen_survey_empty_state;
985 -
986 - /**
987 - * Filter to allow extending the SureForms dashboard screen check.
988 - *
989 - * @since 2.6.0
990 - *
991 - * @param bool $is_sureforms_screen Whether the current screen is a SureForms dashboard screen.
992 - */
993 - $is_sureforms_screen = apply_filters( 'srfm_is_dashboard_screen', $is_sureforms_screen );
994 -
995 - if ( $is_sureforms_screen ) {
865 + if ( $is_screen_sureforms_menu || $is_post_type_sureforms_form || $is_screen_add_new_form || $is_screen_sureforms_forms || $is_screen_sureforms_form_settings || $is_screen_sureforms_entries || $is_screen_sureforms_payments ) {
996 866 $asset_handle = '-dashboard';
997 867
998 868 wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER );
999 869
@@ -1043,35 +913,11 @@
1043 913 if ( $is_screen_sureforms_entries ) {
1044 914 $asset_handle = '-entries';
1045 915 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/entries.js', $script_info['dependencies'], SRFM_VER, true );
1046 916
1047 - wp_localize_script(
1048 - SRFM_SLUG . $asset_handle,
1049 - SRFM_SLUG . '_admin',
1050 - apply_filters(
1051 - SRFM_SLUG . '_admin_filter',
1052 - $localization_data
1053 - )
1054 - );
1055 917 $script_translations_handlers[] = SRFM_SLUG . $asset_handle;
1056 918 }
1057 919
1058 - // Enqueue scripts for the learn page.
1059 - if ( $is_screen_sureforms_learn ) {
1060 - $asset_handle = '-learn';
1061 - wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/learn.js', $script_info['dependencies'], SRFM_VER, true );
1062 -
1063 - wp_localize_script(
1064 - SRFM_SLUG . $asset_handle,
1065 - SRFM_SLUG . '_admin',
1066 - apply_filters(
1067 - SRFM_SLUG . '_admin_filter',
1068 - $localization_data
1069 - )
1070 - );
1071 - $script_translations_handlers[] = SRFM_SLUG . $asset_handle;
1072 - }
1073 -
1074 920 // Enqueue scripts for the forms page.
1075 921 if ( $is_screen_sureforms_forms ) {
1076 922 $asset_handle = '-forms';
1077 923
@@ -1086,12 +932,9 @@
1086 932 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/forms.js', $script_info['dependencies'], SRFM_VER, true );
1087 933 wp_localize_script(
1088 934 SRFM_SLUG . $asset_handle,
1089 935 SRFM_SLUG . '_admin',
1090 - apply_filters(
1091 - SRFM_SLUG . '_admin_filter',
1092 - $localization_data
1093 - )
936 + $localization_data
1094 937 );
1095 938 wp_enqueue_style( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/forms.css', [], SRFM_VER, 'all' );
1096 939
1097 940 $script_translations_handlers[] = SRFM_SLUG . $asset_handle;
@@ -1136,44 +979,8 @@
1136 979
1137 980 $script_translations_handlers[] = SRFM_SLUG . '-suremail';
1138 981 }
1139 982
1140 - // Enqueue scripts for the Quiz empty state page (free users only).
1141 - if ( $is_screen_quiz_empty_state && ! Helper::has_pro() ) {
1142 - $asset_handle = 'quizEmptyState';
1143 -
1144 - $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
1145 - $script_info = file_exists( $script_asset_path )
1146 - ? include $script_asset_path
1147 - : [
1148 - 'dependencies' => [],
1149 - 'version' => SRFM_VER,
1150 - ];
1151 -
1152 - wp_enqueue_script( SRFM_SLUG . '-quiz-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
1153 - wp_enqueue_style( SRFM_SLUG . '-quiz-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [], SRFM_VER, 'all' );
1154 -
1155 - $script_translations_handlers[] = SRFM_SLUG . '-quiz-empty-state';
1156 - }
1157 -
1158 - // Enqueue scripts for the Survey Reports empty state page (free users only).
1159 - if ( $is_screen_survey_empty_state && ! Helper::has_pro() ) {
1160 - $asset_handle = 'surveyEmptyState';
1161 -
1162 - $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
1163 - $script_info = file_exists( $script_asset_path )
1164 - ? include $script_asset_path
1165 - : [
1166 - 'dependencies' => [],
1167 - 'version' => SRFM_VER,
1168 - ];
1169 -
1170 - wp_enqueue_script( SRFM_SLUG . '-survey-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
1171 - wp_enqueue_style( SRFM_SLUG . '-survey-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [], SRFM_VER, 'all' );
1172 -
1173 - $script_translations_handlers[] = SRFM_SLUG . '-survey-empty-state';
1174 - }
1175 -
1176 983 // Admin Submenu Styles.
1177 984 wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . $rtl . '.css', [], SRFM_VER );
1178 985
1179 986 if ( $is_screen_sureforms_form_settings ) {
@@ -1190,12 +997,9 @@
1190 997 wp_enqueue_script( SRFM_SLUG . '-settings', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
1191 998 wp_localize_script(
1192 999 SRFM_SLUG . '-settings',
1193 1000 SRFM_SLUG . '_admin',
1194 - apply_filters(
1195 - SRFM_SLUG . '_admin_filter',
1196 - $localization_data
1197 - )
1001 + $localization_data
1198 1002 );
1199 1003
1200 1004 $script_translations_handlers[] = SRFM_SLUG . '-settings';
1201 1005 }
@@ -1350,55 +1154,8 @@
1350 1154 return $status;
1351 1155 }
1352 1156
1353 1157 /**
1354 - * Register Pro compatibility notices early for React pages.
1355 - *
1356 - * This method runs on admin_init (priority 5) to ensure notices are
1357 - * registered BEFORE admin_enqueue_scripts, so they're available when
1358 - * wp_localize_script runs.
1359 - *
1360 - * Hooked - admin_init (priority 5)
1361 - *
1362 - * @return void
1363 - * @since 2.5.0
1364 - */
1365 - public function register_pro_compatibility_notices() {
1366 - // Early exit if Pro is not active, user lacks permissions, or Notice_Manager is unavailable.
1367 - if ( ! Helper::has_pro() || ! Helper::current_user_can() || ! class_exists( 'SRFM\Admin\Notice_Manager' ) ) {
1368 - return;
1369 - }
1370 -
1371 - // Register version outdated notice for React pages.
1372 - if ( ! version_compare( SRFM_PRO_VER, SRFM_PRO_RECOMMENDED_VER, '>=' ) ) {
1373 - $pro_plugin_name = defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro';
1374 - $react_outdated_message = sprintf(
1375 - // translators: %1$s: SureForms version, %2$s: SureForms Pro Plugin Name, %3$s: SureForms Pro Version.
1376 - esc_html__( 'SureForms %1$s requires minimum %2$s %3$s to work properly. Please update to the latest version.', 'sureforms' ),
1377 - esc_html( SRFM_VER ),
1378 - esc_html( $pro_plugin_name ),
1379 - esc_html( SRFM_PRO_RECOMMENDED_VER )
1380 - );
1381 -
1382 - \SRFM\Admin\Notice_Manager::register_notice(
1383 - [
1384 - 'id' => 'sureforms-pro-version-outdated',
1385 - 'variant' => 'warning',
1386 - 'message' => $react_outdated_message,
1387 - 'actions' => [
1388 - [
1389 - 'label' => esc_html__( 'Update Now', 'sureforms' ),
1390 - 'url' => admin_url( 'update-core.php' ),
1391 - 'variant' => 'primary',
1392 - ],
1393 - ],
1394 - 'pages' => [ 'all' ],
1395 - ]
1396 - );
1397 - }
1398 - }
1399 -
1400 - /**
1401 1158 * Admin Notice Callback if sureforms pro is out of date.
1402 1159 *
1403 1160 * Hooked - admin_notices
1404 1161 *
@@ -1477,168 +1234,8 @@
1477 1234 }
1478 1235 }
1479 1236
1480 1237 /**
1481 - * Display a notice to the user about providing a review.
1482 - *
1483 - * @since 2.5.2
1484 - * @return void
1485 - */
1486 - public function display_srfm_rating_notice() {
1487 - // Only show to admins.
1488 - if ( ! Helper::current_user_can() ) {
1489 - return;
1490 - }
1491 -
1492 - // Allow the notice to be disabled.
1493 - if ( ! apply_filters( 'srfm_show_rating_notice', true ) ) {
1494 - return;
1495 - }
1496 -
1497 - Astra_Notices::add_notice(
1498 - [
1499 - 'id' => 'srfm-plugin-review-notice',
1500 - 'type' => '',
1501 - 'message' => $this->build_notice_markup(
1502 - esc_html__( 'Amazing! SureForms is powering your forms and submissions - let\'s keep growing together!', 'sureforms' ),
1503 - esc_html__( 'If SureForms has been helpful, would you mind taking a moment to leave a 5-star review on WordPress.org?', 'sureforms' ),
1504 - esc_url( 'https://wordpress.org/support/plugin/sureforms/reviews/?filter=5#new-post' ),
1505 - esc_html__( 'Rate SureForms', 'sureforms' ),
1506 - esc_html__( 'Maybe later', 'sureforms' ),
1507 - esc_html__( 'I already did', 'sureforms' ),
1508 - WEEK_IN_SECONDS,
1509 - true
1510 - ),
1511 - 'repeat-notice-after' => WEEK_IN_SECONDS,
1512 - 'show_if' => $this->maybe_display_rating_notice(),
1513 - 'display-with-other-notices' => true,
1514 - ]
1515 - );
1516 -
1517 - add_action( 'astra_notice_after_markup_srfm-plugin-review-notice', [ $this, 'enqueue_notice_response_script' ] );
1518 - }
1519 -
1520 - /**
1521 - * Display a "Getting Started" admin notice for new users who haven't yet
1522 - * reached the rating-notice milestone (3+ forms or 3+ entries).
1523 - *
1524 - * The Astra Notices library handles the 7-day delay via the
1525 - * `display-notice-after` parameter.
1526 - *
1527 - * @since 2.5.2
1528 - * @return void
1529 - */
1530 - public function display_srfm_getting_started_notice() {
1531 - // Only show to admins.
1532 - if ( ! Helper::current_user_can() ) {
1533 - return;
1534 - }
1535 -
1536 - // Allow the notice to be disabled programmatically.
1537 - if ( ! apply_filters( 'srfm_show_getting_started_notice', true ) ) {
1538 - return;
1539 - }
1540 -
1541 - Astra_Notices::add_notice(
1542 - [
1543 - 'id' => 'srfm-getting-started-notice',
1544 - 'type' => '',
1545 - 'message' => $this->build_notice_markup(
1546 - esc_html__( 'SureForms is ready to power your forms — explore what\'s possible!', 'sureforms' ),
1547 - esc_html__( 'Manage your forms, track submissions, and discover features like AI Form Builder, payment integrations, and more from the SureForms dashboard.', 'sureforms' ),
1548 - esc_url( admin_url( 'admin.php?page=sureforms_menu' ) ),
1549 - esc_html__( 'Go to Dashboard', 'sureforms' ),
1550 - esc_html__( 'Maybe later', 'sureforms' ),
1551 - esc_html__( 'I already know', 'sureforms' ),
1552 - WEEK_IN_SECONDS
1553 - ),
1554 - 'repeat-notice-after' => WEEK_IN_SECONDS,
1555 - 'show_if' => ! $this->maybe_display_rating_notice(),
1556 - 'display-notice-after' => WEEK_IN_SECONDS,
1557 - 'display-with-other-notices' => true,
1558 - ]
1559 - );
1560 -
1561 - add_action( 'astra_notice_after_markup_srfm-getting-started-notice', [ $this, 'enqueue_notice_response_script' ] );
1562 - }
1563 -
1564 - /**
1565 - * Enqueue the notice response analytics script.
1566 - *
1567 - * Called via the astra_notice_after_markup_{id} hook so the script
1568 - * only loads when a SureForms notice is actually rendered.
1569 - *
1570 - * @since 2.5.2
1571 - * @return void
1572 - */
1573 - public function enqueue_notice_response_script() {
1574 - if ( wp_script_is( 'srfm-notice-response', 'enqueued' ) ) {
1575 - return;
1576 - }
1577 -
1578 - wp_enqueue_script(
1579 - 'srfm-notice-response',
1580 - SRFM_URL . 'admin/assets/js/notice-response.js',
1581 - [],
1582 - SRFM_VER,
1583 - true
1584 - );
1585 -
1586 - wp_localize_script(
1587 - 'srfm-notice-response',
1588 - 'srfmNoticeResponse',
1589 - [
1590 - 'ajaxurl' => admin_url( 'admin-ajax.php' ),
1591 - 'nonce' => wp_create_nonce( 'srfm_notice_response' ),
1592 - ]
1593 - );
1594 - }
1595 -
1596 - /**
1597 - * Handle the notice response AJAX request.
1598 - *
1599 - * Validates the request and records the analytics event
1600 - * for the notice button that was clicked.
1601 - *
1602 - * @since 2.5.2
1603 - * @return void
1604 - */
1605 - public function handle_notice_response() {
1606 - if ( ! check_ajax_referer( 'srfm_notice_response', 'nonce', false ) ) {
1607 - wp_send_json_error( [ 'message' => __( 'Invalid nonce.', 'sureforms' ) ], 403 );
1608 - }
1609 -
1610 - if ( ! Helper::current_user_can() ) {
1611 - wp_send_json_error( [ 'message' => __( 'Unauthorized user.', 'sureforms' ) ], 403 );
1612 - }
1613 -
1614 - $notice_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : '';
1615 - $button = isset( $_POST['button'] ) ? sanitize_text_field( wp_unslash( $_POST['button'] ) ) : '';
1616 -
1617 - $valid = [
1618 - 'srfm-getting-started-notice' => [
1619 - 'go_to_dashboard' => 'getting_started_notice_cta',
1620 - 'maybe_later' => 'getting_started_notice_snooze',
1621 - 'dismissed' => 'getting_started_notice_dismiss',
1622 - ],
1623 - 'srfm-plugin-review-notice' => [
1624 - 'rate_sureforms' => 'rating_notice_cta',
1625 - 'maybe_later' => 'rating_notice_snooze',
1626 - 'dismissed' => 'rating_notice_dismiss',
1627 - ],
1628 - ];
1629 -
1630 - if ( ! isset( $valid[ $notice_id ][ $button ] ) ) {
1631 - wp_send_json_error( [ 'message' => __( 'Invalid parameters.', 'sureforms' ) ], 400 );
1632 - }
1633 -
1634 - $event_name = $valid[ $notice_id ][ $button ];
1635 - Analytics::events()->track( $event_name, $button );
1636 -
1637 - wp_send_json_success();
1638 - }
1639 -
1640 - /**
1641 1238 * Disables the capabilities for WPForms to avoid conflicts when enqueueing
1642 1239 * scripts and styles for WPForms.
1643 1240 *
1644 1241 * This function is intended to prevent any potential conflicts that may arise
@@ -1865,86 +1462,8 @@
1865 1462 $this->render_dashboard_widget_footer( $entries_data );
1866 1463 ?>
1867 1464 </div>
1868 1465 <?php
1869 - }
1870 -
1871 - /**
1872 - * Build the shared HTML markup for admin notices.
1873 - *
1874 - * @since 2.5.2
1875 - *
1876 - * All text parameters must be pre-escaped by the caller (e.g. via esc_html__()).
1877 - * URL parameters must be pre-escaped via esc_url().
1878 - *
1879 - * @param string $heading The notice heading text (pre-escaped).
1880 - * @param string $message The notice body text (pre-escaped).
1881 - * @param string $cta_url The primary CTA URL (pre-escaped).
1882 - * @param string $cta_text The primary CTA button text (pre-escaped).
1883 - * @param string $snooze_text The snooze button text (pre-escaped).
1884 - * @param string $dismiss_text The dismiss button text (pre-escaped).
1885 - * @param int $snooze_duration Snooze duration in seconds for the data-repeat-notice-after attribute.
1886 - * @param bool $external_cta Whether the CTA opens in a new tab and also dismisses the notice
1887 - * via the astra-notice-close class. Default false.
1888 - * @return string The notice HTML markup.
1889 - */
1890 - private function build_notice_markup( $heading, $message, $cta_url, $cta_text, $snooze_text, $dismiss_text, $snooze_duration, $external_cta = false ) {
1891 - $image_path = esc_url( SRFM_URL . 'admin/assets/sureforms-logo.png' );
1892 - $cta_class = $external_cta ? 'astra-notice-close button-primary' : 'button-primary';
1893 - $cta_attrs = $external_cta ? ' target="_blank" rel="noopener noreferrer"' : '';
1894 -
1895 - return sprintf(
1896 - '<div class="notice-image">
1897 - <img src="%1$s" class="custom-logo" alt="SureForms" itemprop="logo">
1898 - </div>
1899 - <div class="notice-content">
1900 - <div class="notice-heading">
1901 - %2$s
1902 - </div>
1903 - %3$s<br />
1904 - <div class="astra-review-notice-container">
1905 - <a href="%4$s" class="%5$s"%6$s>
1906 - %7$s
1907 - </a>
1908 - <span class="dashicons dashicons-clock" aria-hidden="true"></span>
1909 - <a href="#" data-repeat-notice-after="%8$s" class="astra-notice-close">
1910 - %9$s
1911 - </a>
1912 - <span class="dashicons dashicons-smiley" aria-hidden="true"></span>
1913 - <a href="#" class="astra-notice-close">
1914 - %10$s
1915 - </a>
1916 - </div>
1917 - </div>',
1918 - $image_path,
1919 - $heading,
1920 - $message,
1921 - $cta_url,
1922 - esc_attr( $cta_class ),
1923 - $cta_attrs,
1924 - $cta_text,
1925 - $snooze_duration,
1926 - $snooze_text,
1927 - $dismiss_text
1928 - );
1929 - }
1930 -
1931 - /**
1932 - * Callback for displaying the rating notice conditionally.
1933 - *
1934 - * Returns true if the user has 3 or more published forms or 3 or more form entries.
1935 - *
1936 - * @since 2.5.2
1937 - * @return bool
1938 - */
1939 - private function maybe_display_rating_notice() {
1940 - if ( null === $this->should_show_rating ) {
1941 - $entries_count = Entries::get_total_entries_by_status( 'all' );
1942 - $form_count = wp_count_posts( SRFM_FORMS_POST_TYPE );
1943 - $this->should_show_rating = $entries_count >= self::RATING_NOTICE_THRESHOLD || Helper::get_integer_value( $form_count->publish ?? 0 ) >= self::RATING_NOTICE_THRESHOLD;
1944 - }
1945 -
1946 - return $this->should_show_rating;
1947 1466 }
1948 1467
1949 1468 /**
1950 1469 * Get random premium feature text.