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 +106 -645 2.9.02.3.0 View file →
@@ -6,26 +6,19 @@
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 -use SRFM\Inc\Global_Settings\Global_Settings;
14 12 use SRFM\Inc\Helper;
15 13 use SRFM\Inc\Onboarding;
16 14 use SRFM\Inc\Payments\Payment_Helper;
17 15 use SRFM\Inc\Payments\Stripe\Stripe_Helper;
18 -use SRFM\Inc\Smart_Tags;
19 16 use SRFM\Inc\Traits\Get_Instance;
20 17
21 18 if ( ! defined( 'ABSPATH' ) ) {
22 19 exit; // Exit if accessed directly.
23 20 }
24 -
25 -if ( ! class_exists( 'BSF_Admin_Notices' ) ) {
26 - require_once SRFM_DIR . 'inc/lib/astra-notices/class-bsf-admin-notices.php';
27 -}
28 21 /**
29 22 * Admin handler class.
30 23 *
31 24 * @since 0.0.1
@@ -33,15 +26,8 @@
33 26 class Admin {
34 27 use Get_Instance;
35 28
36 29 /**
37 - * Minimum number of forms or entries required to show the rating notice.
38 - *
39 - * @since 2.5.2
40 - */
41 - public const RATING_NOTICE_THRESHOLD = 3;
42 -
43 - /**
44 30 * Dashboard widget entries data.
45 31 *
46 32 * @var array
47 33 * @since 1.9.1
@@ -48,16 +34,8 @@
48 34 */
49 35 private $dashboard_widget_data = [];
50 36
51 37 /**
52 - * Cached result for whether the rating notice should display.
53 - *
54 - * @var bool|null
55 - * @since 2.5.2
56 - */
57 - private $should_show_rating = null;
58 -
59 - /**
60 38 * SureForms Page Default permission.
61 39 *
62 40 * @var string
63 41 * @since 1.12.2
@@ -73,15 +51,11 @@
73 51 public function __construct() {
74 52 add_action( 'admin_menu', [ $this, 'add_menu_page' ], 9 );
75 53 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
76 54 add_action( 'admin_menu', [ $this, 'settings_page' ] );
77 - add_action( 'admin_menu', [ $this, 'add_learn_page' ] );
78 55 add_action( 'admin_menu', [ $this, 'add_new_form' ] );
79 56 add_action( 'admin_menu', [ $this, 'add_suremail_page' ] );
80 57 if ( ! Helper::has_pro() ) {
81 - add_action( 'admin_menu', [ $this, 'add_quiz_page' ] );
82 - add_action( 'admin_menu', [ $this, 'add_survey_reports_page' ] );
83 - add_action( 'admin_menu', [ $this, 'add_partial_entries_page' ] );
84 58 add_action( 'admin_menu', [ $this, 'add_upgrade_to_pro' ] );
85 59 add_action( 'admin_footer', [ $this, 'add_upgrade_to_pro_target_attr' ] );
86 60 }
87 61
@@ -93,13 +67,19 @@
93 67 // this action is used to restrict Spectra's quick action bar on SureForms CPTS.
94 68 add_action( 'uag_enable_quick_action_sidebar', [ $this, 'restrict_spectra_quick_action_bar' ] );
95 69
96 70 add_action( 'current_screen', [ $this, 'enable_gutenberg_for_sureforms' ], 100 );
97 - // Register notices early for React pages (before admin_enqueue_scripts).
98 - add_action( 'admin_init', [ $this, 'register_pro_compatibility_notices' ], 5 );
99 - // Display notices on traditional WordPress admin pages.
100 71 add_action( 'admin_notices', [ $this, 'srfm_pro_version_compatibility' ] );
101 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 + );
102 82 // Enfold theme compatibility to enable block editor for SureForms post type.
103 83 add_filter( 'avf_use_block_editor_for_post', [ $this, 'enable_block_editor_in_enfold_theme' ] );
104 84
105 85 // Add action links to the plugin page.
@@ -111,8 +91,10 @@
111 91 if ( $admin_notification_on ) {
112 92 add_action( 'admin_menu', [ $this, 'maybe_add_entries_badge' ], 99 );
113 93 }
114 94
95 + add_action( 'admin_menu', [ $this, 'add_payments_badge' ], 99 );
96 +
115 97 add_filter( 'wpforms_current_user_can', [ $this, 'disable_wpforms_capabilities' ], 10, 3 );
116 98
117 99 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_pointer' ] );
118 100 // Ajax callbacks for wp-pointer functionality.
@@ -118,9 +100,8 @@
118 100 // Ajax callbacks for wp-pointer functionality.
119 101 add_action( 'wp_ajax_should_show_pointer', [ $this, 'pointer_should_show' ] );
120 102 add_action( 'wp_ajax_sureforms_dismiss_pointer', [ $this, 'pointer_dismissed' ] );
121 103 add_action( 'wp_ajax_sureforms_accept_cta', [ $this, 'pointer_accepted_cta' ] );
122 - add_action( 'wp_ajax_srfm_notice_response', [ $this, 'handle_notice_response' ] );
123 104
124 105 // Register dashboard widget only if there are recent entries.
125 106 add_action( 'admin_init', [ $this, 'maybe_register_dashboard_widget' ] );
126 107
@@ -125,10 +106,8 @@
125 106 add_action( 'admin_init', [ $this, 'maybe_register_dashboard_widget' ] );
126 107
127 108 // Save first form creation time stamp.
128 109 add_action( 'admin_init', [ $this, 'save_first_form_creation_time_stamp' ] );
129 - add_action( 'admin_notices', [ $this, 'display_srfm_rating_notice' ] );
130 - add_action( 'admin_notices', [ $this, 'display_srfm_getting_started_notice' ] );
131 110 }
132 111
133 112 /**
134 113 * Get the first form creation time stamp.
@@ -232,9 +211,14 @@
232 211 */
233 212 public function add_action_links( $links ) {
234 213 if ( ! Helper::has_pro() ) {
235 214 // Display upsell link if SureForms Pro is not installed.
236 - $upsell_link = Helper::get_sureforms_website_url( 'pricing', [ 'utm_medium' => 'plugin-list' ] );
215 + $upsell_link = add_query_arg(
216 + [
217 + 'utm_medium' => 'plugin-list',
218 + ],
219 + Helper::get_sureforms_website_url( 'pricing' )
220 + );
237 221
238 222 ob_start();
239 223 ?>
240 224 <a href="<?php echo esc_url( $upsell_link ); ?>" target="_blank" rel="noreferrer" class="sureforms-plugins-go-pro">
@@ -394,9 +378,14 @@
394 378 */
395 379 public function add_upgrade_to_pro() {
396 380 // The url used here is used as a selector for css to style the upgrade to pro submenu.
397 381 // If you are changing this url, please make sure to update the css as well.
398 - $upgrade_url = Helper::get_sureforms_website_url( 'upgrade', [ 'utm_medium' => 'submenu_link_upgrade' ] );
382 + $upgrade_url = add_query_arg(
383 + [
384 + 'utm_medium' => 'submenu_link_upgrade',
385 + ],
386 + Helper::get_sureforms_website_url( 'upgrade' )
387 + );
399 388
400 389 add_submenu_page(
401 390 'sureforms_menu',
402 391 __( 'Upgrade', 'sureforms' ),
@@ -406,107 +395,8 @@
406 395 );
407 396 }
408 397
409 398 /**
410 - * Add Quiz empty state submenu page for free users.
411 - *
412 - * @return void
413 - * @since 2.7.0
414 - */
415 - public function add_quiz_page() {
416 - add_submenu_page(
417 - 'sureforms_menu',
418 - __( 'Quiz Entries', 'sureforms' ),
419 - __( 'Quizzes', 'sureforms' ) .
420 - ' <span style="color:#4ADE80;font-size:9px;font-weight:600;">' .
421 - esc_html__( 'New', 'sureforms' ) .
422 - '</span>',
423 - self::$sureforms_page_default_capability,
424 - 'sureforms_quiz_entries',
425 - [ $this, 'render_quiz_empty_state' ],
426 - 5
427 - );
428 - }
429 -
430 - /**
431 - * Quiz empty state page callback.
432 - *
433 - * @return void
434 - * @since 2.7.0
435 - */
436 - public function render_quiz_empty_state() {
437 - ?>
438 - <div id="srfm-quiz-entries-root" class="srfm-admin-wrapper"></div>
439 - <?php
440 - }
441 -
442 - /**
443 - * Add Survey Reports promotional submenu page for free users.
444 - *
445 - * @return void
446 - * @since 2.8.0
447 - */
448 - public function add_survey_reports_page() {
449 - add_submenu_page(
450 - 'sureforms_menu',
451 - __( 'Survey Reports', 'sureforms' ),
452 - __( 'Survey Reports', 'sureforms' ) .
453 - ' <span style="color:#4ADE80;font-size:9px;font-weight:600;">' .
454 - esc_html__( 'New', 'sureforms' ) .
455 - '</span>',
456 - self::$sureforms_page_default_capability,
457 - 'sureforms_survey_reports',
458 - [ $this, 'render_survey_empty_state' ],
459 - 6
460 - );
461 - }
462 -
463 - /**
464 - * Survey empty state page callback.
465 - *
466 - * @return void
467 - * @since 2.8.0
468 - */
469 - public function render_survey_empty_state() {
470 - ?>
471 - <div id="srfm-survey-empty-state-root" class="srfm-admin-wrapper"></div>
472 - <?php
473 - }
474 -
475 - /**
476 - * Add Partial Entries promotional submenu page for free users.
477 - *
478 - * @return void
479 - * @since 2.9.0
480 - */
481 - public function add_partial_entries_page() {
482 - add_submenu_page(
483 - 'sureforms_menu',
484 - __( 'Partial Entries', 'sureforms' ),
485 - __( 'Partial Entries', 'sureforms' ) .
486 - ' <span style="color:#4ADE80;font-size:9px;font-weight:600;">' .
487 - esc_html__( 'New', 'sureforms' ) .
488 - '</span>',
489 - self::$sureforms_page_default_capability,
490 - 'sureforms_partial_entries',
491 - [ $this, 'render_partial_entries_empty_state' ],
492 - 7
493 - );
494 - }
495 -
496 - /**
497 - * Partial Entries empty state page callback.
498 - *
499 - * @return void
500 - * @since 2.9.0
501 - */
502 - public function render_partial_entries_empty_state() {
503 - ?>
504 - <div id="srfm-partial-entries-empty-state-root" class="srfm-admin-wrapper"></div>
505 - <?php
506 - }
507 -
508 - /**
509 399 * Add SMTP promotional submenu page.
510 400 *
511 401 * @return void
512 402 * @since 1.7.1
@@ -568,37 +458,8 @@
568 458 <?php
569 459 }
570 460
571 461 /**
572 - * Add Learn submenu page.
573 - *
574 - * @return void
575 - * @since 2.5.2
576 - */
577 - public function add_learn_page() {
578 - add_submenu_page(
579 - 'sureforms_menu',
580 - __( 'Learn', 'sureforms' ),
581 - __( 'Learn', 'sureforms' ),
582 - self::$sureforms_page_default_capability,
583 - 'sureforms_learn',
584 - [ $this, 'render_learn' ]
585 - );
586 - }
587 -
588 - /**
589 - * Learn page callback.
590 - *
591 - * @return void
592 - * @since 2.5.2
593 - */
594 - public function render_learn() {
595 - ?>
596 - <div id="srfm-learn-root" class="srfm-admin-wrapper"></div>
597 - <?php
598 - }
599 -
600 - /**
601 462 * Add new form menu item.
602 463 *
603 464 * @return void
604 465 * @since 0.0.1
@@ -752,8 +613,36 @@
752 613 }
753 614 }
754 615
755 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 + /**
756 645 * Mark the user's visit to the entries page.
757 646 *
758 647 * @since 1.7.3
759 648 * @return void
@@ -909,89 +798,59 @@
909 798 * List of the handles in which we need to add translation compatibility.
910 799 */
911 800 $script_translations_handlers = [];
912 801 $onboarding_instance = Onboarding::get_instance();
913 - $current_user = wp_get_current_user();
914 802
915 803 $localization_data = [
916 - 'site_url' => get_site_url(),
917 - 'current_user_login' => $current_user->user_login ?? '',
918 - 'website_lead_details' => [
919 - 'first_name' => $current_user->first_name ?? '',
920 - 'last_name' => $current_user->last_name ?? '',
921 - '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(),
922 843 ],
923 - 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
924 - 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
925 - 'plugin_version' => SRFM_VER,
926 - 'global_settings_nonce' => Helper::current_user_can() ? wp_create_nonce( 'wp_rest' ) : '',
927 - 'is_pro_active' => Helper::has_pro(),
928 - 'is_first_form_created' => self::is_first_form_created(),
929 - 'check_three_days_threshold' => self::check_first_form_creation_threshold(),
930 - 'check_eight_days_threshold' => self::check_first_form_creation_threshold( 8 ),
931 - 'pro_plugin_version' => Helper::has_pro() ? SRFM_PRO_VER : '',
932 - 'pro_plugin_name' => Helper::has_pro() && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro',
933 - 'sureforms_pricing_page' => Helper::get_sureforms_website_url( 'pricing' ),
934 - 'field_spacing_vars' => Helper::get_css_vars(),
935 - 'is_ver_lower_than_6_7' => version_compare( $wp_version, '6.6.2', '<=' ),
936 - 'integrations' => Helper::sureforms_get_integration(),
937 - 'rotating_plugin_banner' => Helper::get_rotating_plugin_banner(),
938 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
939 - 'sf_plugin_manager_nonce' => wp_create_nonce( 'sf_plugin_manager_nonce' ),
940 - 'plugin_installer_nonce' => wp_create_nonce( 'updates' ),
941 - 'plugin_activating_text' => __( 'Activating...', 'sureforms' ),
942 - 'plugin_activated_text' => __( 'Activated', 'sureforms' ),
943 - 'plugin_activate_text' => __( 'Activate', 'sureforms' ),
944 - 'plugin_installing_text' => __( 'Installing...', 'sureforms' ),
945 - 'plugin_installed_text' => __( 'Installed', 'sureforms' ),
946 - 'privacy_policy_url' => Helper::get_sureforms_website_url( 'privacy-policy/' ),
947 - 'is_rtl' => $is_rtl,
948 - 'onboarding_completed' => method_exists( $onboarding_instance, 'get_onboarding_status' ) ? $onboarding_instance->get_onboarding_status() : false,
949 - 'onboarding_redirect' => isset( $_GET['srfm-activation-redirect'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required for the activation redirection.
950 - 'pointer_nonce' => wp_create_nonce( 'sureforms_pointer_action' ),
951 - 'general_settings_url' => admin_url( '/options-general.php' ),
952 - 'additional_header_nav_items' => [],
953 - // Smart tags for the Global Defaults email notification fields.
954 - // srfm_block_data is only available in the block editor; these keys
955 - // make the same data accessible on the settings page via srfm_admin.
956 - 'smart_tags_array' => Smart_Tags::smart_tag_list(),
957 - 'smart_tags_array_email' => Smart_Tags::email_smart_tag_list(),
958 - // Default confirmation message HTML (icon + heading + text) used as
959 - // the initial React state before the settings API response arrives.
960 - 'default_confirmation_message' => Global_Settings::get_default_confirmation_message(),
961 - 'payments' => apply_filters(
962 - 'srfm_admin_localize_payments_data',
963 - [
964 - 'stripe_connected' => Stripe_Helper::is_stripe_connected(),
965 - 'stripe_mode' => Stripe_Helper::get_stripe_mode(),
966 - 'stripe_connect_url' => Stripe_Helper::get_stripe_settings_url(),
967 - 'currencies_data' => Payment_Helper::get_all_currencies_data(),
968 - 'zero_decimal_currencies' => Payment_Helper::get_zero_decimal_currencies(),
969 - 'webhook_url' => Stripe_Helper::get_webhook_url(),
970 - 'webhook_test_connected' => Stripe_Helper::is_webhook_configured( 'test', true ),
971 - 'webhook_live_connected' => Stripe_Helper::is_webhook_configured( 'live', true ),
972 - 'is_transaction_present' => Stripe_Helper::is_transaction_present(),
973 - 'payment_currency' => Payment_Helper::get_currency(),
974 - 'currency_sign_position' => Payment_Helper::get_currency_sign_position(),
975 - ]
976 - ),
977 - 'mcp_adapter_status' => file_exists( WP_PLUGIN_DIR . '/mcp-adapter/mcp-adapter.php' )
978 - ? ( is_plugin_active( 'mcp-adapter/mcp-adapter.php' ) ? 'active' : 'installed' )
979 - : 'not_installed',
980 - 'mcp_endpoint_url' => esc_url_raw( rest_url( 'sureforms/v1/mcp' ) ),
981 844 ];
982 845
983 - $is_screen_sureforms_menu = Helper::validate_request_context( 'sureforms_menu', 'page' );
984 - $is_screen_add_new_form = Helper::validate_request_context( 'add-new-form', 'page' );
985 - $is_screen_sureforms_forms = Helper::validate_request_context( 'sureforms_forms', 'page' );
986 - $is_screen_sureforms_form_settings = Helper::validate_request_context( 'sureforms_form_settings', 'page' );
987 - $is_screen_sureforms_payments = Helper::validate_request_context( 'sureforms_payments', 'page' );
988 - $is_screen_sureforms_entries = Helper::validate_request_context( SRFM_ENTRIES, 'page' );
989 - $is_screen_sureforms_learn = Helper::validate_request_context( 'sureforms_learn', 'page' );
990 - $is_screen_quiz_empty_state = Helper::validate_request_context( 'sureforms_quiz_entries', 'page' );
991 - $is_screen_survey_empty_state = Helper::validate_request_context( 'sureforms_survey_reports', 'page' );
992 - $is_screen_partial_entries_empty_state = Helper::validate_request_context( 'sureforms_partial_entries', 'page' );
993 - $is_post_type_sureforms_form = SRFM_FORMS_POST_TYPE === $current_screen->post_type;
846 + $is_screen_sureforms_menu = Helper::validate_request_context( 'sureforms_menu', 'page' );
847 + $is_screen_add_new_form = Helper::validate_request_context( 'add-new-form', 'page' );
848 + $is_screen_sureforms_forms = Helper::validate_request_context( 'sureforms_forms', 'page' );
849 + $is_screen_sureforms_form_settings = Helper::validate_request_context( 'sureforms_form_settings', 'page' );
850 + $is_screen_sureforms_payments = Helper::validate_request_context( 'sureforms_payments', 'page' );
851 + $is_screen_sureforms_entries = Helper::validate_request_context( SRFM_ENTRIES, 'page' );
852 + $is_post_type_sureforms_form = SRFM_FORMS_POST_TYPE === $current_screen->post_type;
994 853
995 854 /**
996 855 * Check if the current screen is the SureForms Menu and AI Auth Email is present then we will add user type as registered.
997 856 * Compatibility with existing UI code that checks for this condition.
@@ -1002,39 +861,9 @@
1002 861 'type' => ! empty( get_option( 'srfm_ai_auth_user_email' ) ) ? 'registered' : 'non-registered',
1003 862 ];
1004 863 }
1005 864
1006 - // Add the Quizzes and Survey Reports nav items when pro is not active.
1007 - if ( ! Helper::has_pro() ) {
1008 - $localization_data['additional_header_nav_items'][] = [
1009 - 'slug' => 'sureforms_quiz_entries',
1010 - 'text' => __( 'Quizzes', 'sureforms' ),
1011 - 'link' => admin_url( 'admin.php?page=sureforms_quiz_entries' ),
1012 - ];
1013 - $localization_data['additional_header_nav_items'][] = [
1014 - 'slug' => 'sureforms_survey_reports',
1015 - 'text' => __( 'Survey Reports', 'sureforms' ),
1016 - 'link' => admin_url( 'admin.php?page=sureforms_survey_reports' ),
1017 - ];
1018 - $localization_data['additional_header_nav_items'][] = [
1019 - 'slug' => 'sureforms_partial_entries',
1020 - 'text' => __( 'Partial Entries', 'sureforms' ),
1021 - 'link' => admin_url( 'admin.php?page=sureforms_partial_entries' ),
1022 - ];
1023 - }
1024 -
1025 - $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 || $is_screen_partial_entries_empty_state;
1026 -
1027 - /**
1028 - * Filter to allow extending the SureForms dashboard screen check.
1029 - *
1030 - * @since 2.6.0
1031 - *
1032 - * @param bool $is_sureforms_screen Whether the current screen is a SureForms dashboard screen.
1033 - */
1034 - $is_sureforms_screen = apply_filters( 'srfm_is_dashboard_screen', $is_sureforms_screen );
1035 -
1036 - 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 ) {
1037 866 $asset_handle = '-dashboard';
1038 867
1039 868 wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER );
1040 869
@@ -1084,35 +913,11 @@
1084 913 if ( $is_screen_sureforms_entries ) {
1085 914 $asset_handle = '-entries';
1086 915 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/entries.js', $script_info['dependencies'], SRFM_VER, true );
1087 916
1088 - wp_localize_script(
1089 - SRFM_SLUG . $asset_handle,
1090 - SRFM_SLUG . '_admin',
1091 - apply_filters(
1092 - SRFM_SLUG . '_admin_filter',
1093 - $localization_data
1094 - )
1095 - );
1096 917 $script_translations_handlers[] = SRFM_SLUG . $asset_handle;
1097 918 }
1098 919
1099 - // Enqueue scripts for the learn page.
1100 - if ( $is_screen_sureforms_learn ) {
1101 - $asset_handle = '-learn';
1102 - wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/learn.js', $script_info['dependencies'], SRFM_VER, true );
1103 -
1104 - wp_localize_script(
1105 - SRFM_SLUG . $asset_handle,
1106 - SRFM_SLUG . '_admin',
1107 - apply_filters(
1108 - SRFM_SLUG . '_admin_filter',
1109 - $localization_data
1110 - )
1111 - );
1112 - $script_translations_handlers[] = SRFM_SLUG . $asset_handle;
1113 - }
1114 -
1115 920 // Enqueue scripts for the forms page.
1116 921 if ( $is_screen_sureforms_forms ) {
1117 922 $asset_handle = '-forms';
1118 923
@@ -1127,12 +932,9 @@
1127 932 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/forms.js', $script_info['dependencies'], SRFM_VER, true );
1128 933 wp_localize_script(
1129 934 SRFM_SLUG . $asset_handle,
1130 935 SRFM_SLUG . '_admin',
1131 - apply_filters(
1132 - SRFM_SLUG . '_admin_filter',
1133 - $localization_data
1134 - )
936 + $localization_data
1135 937 );
1136 938 wp_enqueue_style( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/forms.css', [], SRFM_VER, 'all' );
1137 939
1138 940 $script_translations_handlers[] = SRFM_SLUG . $asset_handle;
@@ -1177,62 +979,8 @@
1177 979
1178 980 $script_translations_handlers[] = SRFM_SLUG . '-suremail';
1179 981 }
1180 982
1181 - // Enqueue scripts for the Quiz empty state page (free users only).
1182 - if ( $is_screen_quiz_empty_state && ! Helper::has_pro() ) {
1183 - $asset_handle = 'quizEmptyState';
1184 -
1185 - $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
1186 - $script_info = file_exists( $script_asset_path )
1187 - ? include $script_asset_path
1188 - : [
1189 - 'dependencies' => [],
1190 - 'version' => SRFM_VER,
1191 - ];
1192 -
1193 - wp_enqueue_script( SRFM_SLUG . '-quiz-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
1194 - wp_enqueue_style( SRFM_SLUG . '-quiz-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [], SRFM_VER, 'all' );
1195 -
1196 - $script_translations_handlers[] = SRFM_SLUG . '-quiz-empty-state';
1197 - }
1198 -
1199 - // Enqueue scripts for the Survey Reports empty state page (free users only).
1200 - if ( $is_screen_survey_empty_state && ! Helper::has_pro() ) {
1201 - $asset_handle = 'surveyEmptyState';
1202 -
1203 - $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
1204 - $script_info = file_exists( $script_asset_path )
1205 - ? include $script_asset_path
1206 - : [
1207 - 'dependencies' => [],
1208 - 'version' => SRFM_VER,
1209 - ];
1210 -
1211 - wp_enqueue_script( SRFM_SLUG . '-survey-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
1212 - wp_enqueue_style( SRFM_SLUG . '-survey-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [], SRFM_VER, 'all' );
1213 -
1214 - $script_translations_handlers[] = SRFM_SLUG . '-survey-empty-state';
1215 - }
1216 -
1217 - // Enqueue scripts for the Partial Entries empty state page (free users only).
1218 - if ( $is_screen_partial_entries_empty_state && ! Helper::has_pro() ) {
1219 - $asset_handle = 'partialEntriesEmptyState';
1220 -
1221 - $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
1222 - $script_info = file_exists( $script_asset_path )
1223 - ? include $script_asset_path
1224 - : [
1225 - 'dependencies' => [],
1226 - 'version' => SRFM_VER,
1227 - ];
1228 -
1229 - wp_enqueue_script( SRFM_SLUG . '-partial-entries-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
1230 - wp_enqueue_style( SRFM_SLUG . '-partial-entries-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [], SRFM_VER, 'all' );
1231 -
1232 - $script_translations_handlers[] = SRFM_SLUG . '-partial-entries-empty-state';
1233 - }
1234 -
1235 983 // Admin Submenu Styles.
1236 984 wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . $rtl . '.css', [], SRFM_VER );
1237 985
1238 986 if ( $is_screen_sureforms_form_settings ) {
@@ -1249,18 +997,11 @@
1249 997 wp_enqueue_script( SRFM_SLUG . '-settings', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
1250 998 wp_localize_script(
1251 999 SRFM_SLUG . '-settings',
1252 1000 SRFM_SLUG . '_admin',
1253 - apply_filters(
1254 - SRFM_SLUG . '_admin_filter',
1255 - $localization_data
1256 - )
1001 + $localization_data
1257 1002 );
1258 1003
1259 - // Enqueue Tailwind and Quill editor styles for the settings page.
1260 - wp_enqueue_style( SRFM_SLUG . '-settings-build', SRFM_URL . 'assets/build/settings.css', [], SRFM_VER, 'all' );
1261 - wp_enqueue_style( SRFM_SLUG . '-reactQuill', SRFM_URL . 'assets/css/minified/deps/quill/quill.snow.css', [], SRFM_VER );
1262 -
1263 1004 $script_translations_handlers[] = SRFM_SLUG . '-settings';
1264 1005 }
1265 1006
1266 1007 if ( $is_screen_add_new_form ) {
@@ -1413,55 +1154,8 @@
1413 1154 return $status;
1414 1155 }
1415 1156
1416 1157 /**
1417 - * Register Pro compatibility notices early for React pages.
1418 - *
1419 - * This method runs on admin_init (priority 5) to ensure notices are
1420 - * registered BEFORE admin_enqueue_scripts, so they're available when
1421 - * wp_localize_script runs.
1422 - *
1423 - * Hooked - admin_init (priority 5)
1424 - *
1425 - * @return void
1426 - * @since 2.5.0
1427 - */
1428 - public function register_pro_compatibility_notices() {
1429 - // Early exit if Pro is not active, user lacks permissions, or Notice_Manager is unavailable.
1430 - if ( ! Helper::has_pro() || ! Helper::current_user_can() || ! class_exists( 'SRFM\Admin\Notice_Manager' ) ) {
1431 - return;
1432 - }
1433 -
1434 - // Register version outdated notice for React pages.
1435 - if ( ! version_compare( SRFM_PRO_VER, SRFM_PRO_RECOMMENDED_VER, '>=' ) ) {
1436 - $pro_plugin_name = defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro';
1437 - $react_outdated_message = sprintf(
1438 - // translators: %1$s: SureForms version, %2$s: SureForms Pro Plugin Name, %3$s: SureForms Pro Version.
1439 - esc_html__( 'SureForms %1$s requires minimum %2$s %3$s to work properly. Please update to the latest version.', 'sureforms' ),
1440 - esc_html( SRFM_VER ),
1441 - esc_html( $pro_plugin_name ),
1442 - esc_html( SRFM_PRO_RECOMMENDED_VER )
1443 - );
1444 -
1445 - \SRFM\Admin\Notice_Manager::register_notice(
1446 - [
1447 - 'id' => 'sureforms-pro-version-outdated',
1448 - 'variant' => 'warning',
1449 - 'message' => $react_outdated_message,
1450 - 'actions' => [
1451 - [
1452 - 'label' => esc_html__( 'Update Now', 'sureforms' ),
1453 - 'url' => admin_url( 'update-core.php' ),
1454 - 'variant' => 'primary',
1455 - ],
1456 - ],
1457 - 'pages' => [ 'all' ],
1458 - ]
1459 - );
1460 - }
1461 - }
1462 -
1463 - /**
1464 1158 * Admin Notice Callback if sureforms pro is out of date.
1465 1159 *
1466 1160 * Hooked - admin_notices
1467 1161 *
@@ -1540,168 +1234,8 @@
1540 1234 }
1541 1235 }
1542 1236
1543 1237 /**
1544 - * Display a notice to the user about providing a review.
1545 - *
1546 - * @since 2.5.2
1547 - * @return void
1548 - */
1549 - public function display_srfm_rating_notice() {
1550 - // Only show to admins.
1551 - if ( ! Helper::current_user_can() ) {
1552 - return;
1553 - }
1554 -
1555 - // Allow the notice to be disabled.
1556 - if ( ! apply_filters( 'srfm_show_rating_notice', true ) ) {
1557 - return;
1558 - }
1559 -
1560 - Astra_Notices::add_notice(
1561 - [
1562 - 'id' => 'srfm-plugin-review-notice',
1563 - 'type' => '',
1564 - 'message' => $this->build_notice_markup(
1565 - esc_html__( 'Amazing! SureForms is powering your forms and submissions - let\'s keep growing together!', 'sureforms' ),
1566 - esc_html__( 'If SureForms has been helpful, would you mind taking a moment to leave a 5-star review on WordPress.org?', 'sureforms' ),
1567 - esc_url( 'https://wordpress.org/support/plugin/sureforms/reviews/?filter=5#new-post' ),
1568 - esc_html__( 'Rate SureForms', 'sureforms' ),
1569 - esc_html__( 'Maybe later', 'sureforms' ),
1570 - esc_html__( 'I already did', 'sureforms' ),
1571 - WEEK_IN_SECONDS,
1572 - true
1573 - ),
1574 - 'repeat-notice-after' => WEEK_IN_SECONDS,
1575 - 'show_if' => $this->maybe_display_rating_notice(),
1576 - 'display-with-other-notices' => true,
1577 - ]
1578 - );
1579 -
1580 - add_action( 'astra_notice_after_markup_srfm-plugin-review-notice', [ $this, 'enqueue_notice_response_script' ] );
1581 - }
1582 -
1583 - /**
1584 - * Display a "Getting Started" admin notice for new users who haven't yet
1585 - * reached the rating-notice milestone (3+ forms or 3+ entries).
1586 - *
1587 - * The Astra Notices library handles the 7-day delay via the
1588 - * `display-notice-after` parameter.
1589 - *
1590 - * @since 2.5.2
1591 - * @return void
1592 - */
1593 - public function display_srfm_getting_started_notice() {
1594 - // Only show to admins.
1595 - if ( ! Helper::current_user_can() ) {
1596 - return;
1597 - }
1598 -
1599 - // Allow the notice to be disabled programmatically.
1600 - if ( ! apply_filters( 'srfm_show_getting_started_notice', true ) ) {
1601 - return;
1602 - }
1603 -
1604 - Astra_Notices::add_notice(
1605 - [
1606 - 'id' => 'srfm-getting-started-notice',
1607 - 'type' => '',
1608 - 'message' => $this->build_notice_markup(
1609 - esc_html__( 'SureForms is ready to power your forms — explore what\'s possible!', 'sureforms' ),
1610 - esc_html__( 'Manage your forms, track submissions, and discover features like AI Form Builder, payment integrations, and more from the SureForms dashboard.', 'sureforms' ),
1611 - esc_url( admin_url( 'admin.php?page=sureforms_menu' ) ),
1612 - esc_html__( 'Go to Dashboard', 'sureforms' ),
1613 - esc_html__( 'Maybe later', 'sureforms' ),
1614 - esc_html__( 'I already know', 'sureforms' ),
1615 - WEEK_IN_SECONDS
1616 - ),
1617 - 'repeat-notice-after' => WEEK_IN_SECONDS,
1618 - 'show_if' => ! $this->maybe_display_rating_notice(),
1619 - 'display-notice-after' => WEEK_IN_SECONDS,
1620 - 'display-with-other-notices' => true,
1621 - ]
1622 - );
1623 -
1624 - add_action( 'astra_notice_after_markup_srfm-getting-started-notice', [ $this, 'enqueue_notice_response_script' ] );
1625 - }
1626 -
1627 - /**
1628 - * Enqueue the notice response analytics script.
1629 - *
1630 - * Called via the astra_notice_after_markup_{id} hook so the script
1631 - * only loads when a SureForms notice is actually rendered.
1632 - *
1633 - * @since 2.5.2
1634 - * @return void
1635 - */
1636 - public function enqueue_notice_response_script() {
1637 - if ( wp_script_is( 'srfm-notice-response', 'enqueued' ) ) {
1638 - return;
1639 - }
1640 -
1641 - wp_enqueue_script(
1642 - 'srfm-notice-response',
1643 - SRFM_URL . 'admin/assets/js/notice-response.js',
1644 - [],
1645 - SRFM_VER,
1646 - true
1647 - );
1648 -
1649 - wp_localize_script(
1650 - 'srfm-notice-response',
1651 - 'srfmNoticeResponse',
1652 - [
1653 - 'ajaxurl' => admin_url( 'admin-ajax.php' ),
1654 - 'nonce' => wp_create_nonce( 'srfm_notice_response' ),
1655 - ]
1656 - );
1657 - }
1658 -
1659 - /**
1660 - * Handle the notice response AJAX request.
1661 - *
1662 - * Validates the request and records the analytics event
1663 - * for the notice button that was clicked.
1664 - *
1665 - * @since 2.5.2
1666 - * @return void
1667 - */
1668 - public function handle_notice_response() {
1669 - if ( ! check_ajax_referer( 'srfm_notice_response', 'nonce', false ) ) {
1670 - wp_send_json_error( [ 'message' => __( 'Invalid nonce.', 'sureforms' ) ], 403 );
1671 - }
1672 -
1673 - if ( ! Helper::current_user_can() ) {
1674 - wp_send_json_error( [ 'message' => __( 'Unauthorized user.', 'sureforms' ) ], 403 );
1675 - }
1676 -
1677 - $notice_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : '';
1678 - $button = isset( $_POST['button'] ) ? sanitize_text_field( wp_unslash( $_POST['button'] ) ) : '';
1679 -
1680 - $valid = [
1681 - 'srfm-getting-started-notice' => [
1682 - 'go_to_dashboard' => 'getting_started_notice_cta',
1683 - 'maybe_later' => 'getting_started_notice_snooze',
1684 - 'dismissed' => 'getting_started_notice_dismiss',
1685 - ],
1686 - 'srfm-plugin-review-notice' => [
1687 - 'rate_sureforms' => 'rating_notice_cta',
1688 - 'maybe_later' => 'rating_notice_snooze',
1689 - 'dismissed' => 'rating_notice_dismiss',
1690 - ],
1691 - ];
1692 -
1693 - if ( ! isset( $valid[ $notice_id ][ $button ] ) ) {
1694 - wp_send_json_error( [ 'message' => __( 'Invalid parameters.', 'sureforms' ) ], 400 );
1695 - }
1696 -
1697 - $event_name = $valid[ $notice_id ][ $button ];
1698 - Analytics::events()->track( $event_name, $button );
1699 -
1700 - wp_send_json_success();
1701 - }
1702 -
1703 - /**
1704 1238 * Disables the capabilities for WPForms to avoid conflicts when enqueueing
1705 1239 * scripts and styles for WPForms.
1706 1240 *
1707 1241 * This function is intended to prevent any potential conflicts that may arise
@@ -1931,86 +1465,8 @@
1931 1465 <?php
1932 1466 }
1933 1467
1934 1468 /**
1935 - * Build the shared HTML markup for admin notices.
1936 - *
1937 - * @since 2.5.2
1938 - *
1939 - * All text parameters must be pre-escaped by the caller (e.g. via esc_html__()).
1940 - * URL parameters must be pre-escaped via esc_url().
1941 - *
1942 - * @param string $heading The notice heading text (pre-escaped).
1943 - * @param string $message The notice body text (pre-escaped).
1944 - * @param string $cta_url The primary CTA URL (pre-escaped).
1945 - * @param string $cta_text The primary CTA button text (pre-escaped).
1946 - * @param string $snooze_text The snooze button text (pre-escaped).
1947 - * @param string $dismiss_text The dismiss button text (pre-escaped).
1948 - * @param int $snooze_duration Snooze duration in seconds for the data-repeat-notice-after attribute.
1949 - * @param bool $external_cta Whether the CTA opens in a new tab and also dismisses the notice
1950 - * via the astra-notice-close class. Default false.
1951 - * @return string The notice HTML markup.
1952 - */
1953 - private function build_notice_markup( $heading, $message, $cta_url, $cta_text, $snooze_text, $dismiss_text, $snooze_duration, $external_cta = false ) {
1954 - $image_path = esc_url( SRFM_URL . 'admin/assets/sureforms-logo.png' );
1955 - $cta_class = $external_cta ? 'astra-notice-close button-primary' : 'button-primary';
1956 - $cta_attrs = $external_cta ? ' target="_blank" rel="noopener noreferrer"' : '';
1957 -
1958 - return sprintf(
1959 - '<div class="notice-image">
1960 - <img src="%1$s" class="custom-logo" alt="SureForms" itemprop="logo">
1961 - </div>
1962 - <div class="notice-content">
1963 - <div class="notice-heading">
1964 - %2$s
1965 - </div>
1966 - %3$s<br />
1967 - <div class="astra-review-notice-container">
1968 - <a href="%4$s" class="%5$s"%6$s>
1969 - %7$s
1970 - </a>
1971 - <span class="dashicons dashicons-clock" aria-hidden="true"></span>
1972 - <a href="#" data-repeat-notice-after="%8$s" class="astra-notice-close">
1973 - %9$s
1974 - </a>
1975 - <span class="dashicons dashicons-smiley" aria-hidden="true"></span>
1976 - <a href="#" class="astra-notice-close">
1977 - %10$s
1978 - </a>
1979 - </div>
1980 - </div>',
1981 - $image_path,
1982 - $heading,
1983 - $message,
1984 - $cta_url,
1985 - esc_attr( $cta_class ),
1986 - $cta_attrs,
1987 - $cta_text,
1988 - $snooze_duration,
1989 - $snooze_text,
1990 - $dismiss_text
1991 - );
1992 - }
1993 -
1994 - /**
1995 - * Callback for displaying the rating notice conditionally.
1996 - *
1997 - * Returns true if the user has 3 or more published forms or 3 or more form entries.
1998 - *
1999 - * @since 2.5.2
2000 - * @return bool
2001 - */
2002 - private function maybe_display_rating_notice() {
2003 - if ( null === $this->should_show_rating ) {
2004 - $entries_count = Entries::get_total_entries_by_status( 'all' );
2005 - $form_count = wp_count_posts( SRFM_FORMS_POST_TYPE );
2006 - $this->should_show_rating = $entries_count >= self::RATING_NOTICE_THRESHOLD || Helper::get_integer_value( $form_count->publish ?? 0 ) >= self::RATING_NOTICE_THRESHOLD;
2007 - }
2008 -
2009 - return $this->should_show_rating;
2010 - }
2011 -
2012 - /**
2013 1469 * Get random premium feature text.
2014 1470 *
2015 1471 * @return string Random feature text.
2016 1472 * @since 1.9.1
@@ -2072,9 +1528,14 @@
2072 1528 </svg>
2073 1529 <span><?php echo esc_html( $this->get_random_premium_feature_text() ); ?></span>
2074 1530 </div>
2075 1531 <?php
2076 - $upgrade_url = Helper::get_sureforms_website_url( 'pricing', [ 'utm_medium' => 'dashboard-widget' ] );
1532 + $upgrade_url = add_query_arg(
1533 + [
1534 + 'utm_medium' => 'dashboard-widget',
1535 + ],
1536 + Helper::get_sureforms_website_url( 'pricing' )
1537 + );
2077 1538 ?>
2078 1539 <a href="<?php echo esc_url( $upgrade_url ); ?>" class="srfm-upgrade-link" target="_blank">
2079 1540 <?php esc_html_e( 'Upgrade', 'sureforms' ); ?>
2080 1541 </a>