| @@ -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,26 +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 | - * Inline CSS for Quill 1.x (react-quill) list markers. | |
| 45 | - * | |
| 46 | - * Quill 1.x renders bullet/numbered list markers via CSS ::before pseudo-elements, | |
| 47 | - * whereas the vendor quill.snow.css targets .ql-ui child elements (Quill 2.x approach). | |
| 48 | - * This constant is shared by enqueue_styles() and enqueue_scripts() to prevent drift. | |
| 49 | - * | |
| 50 | - * @since 2.5.2 | |
| 51 | - */ | |
| 52 | - public const QUILL_1X_INLINE_CSS = '.ql-editor ul,.ql-editor ol{padding-left:1.5em}.ql-editor ul>li,.ql-editor ol>li{list-style-type:none}.ql-editor ol li:not(.ql-direction-rtl),.ql-editor ul li:not(.ql-direction-rtl){padding-left:1.5em}.ql-editor ol li.ql-direction-rtl,.ql-editor ul li.ql-direction-rtl{padding-right:1.5em}.ql-editor ul>li::before{content:"\2022"}.ql-editor li::before{display:inline-block;white-space:nowrap;width:1.2em}.ql-editor li:not(.ql-direction-rtl)::before{margin-left:-1.5em;margin-right:.3em;text-align:right}.ql-editor li.ql-direction-rtl::before{margin-left:.3em;margin-right:-1.5em}.ql-editor ol li{counter-reset:list-1 list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9;counter-increment:list-0}.ql-editor ol li::before{content:counter(list-0,decimal) ". "}.ql-editor ol li.ql-indent-1{counter-increment:list-1;counter-reset:list-2 list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-editor ol li.ql-indent-1::before{content:counter(list-1,lower-alpha) ". "}.ql-editor ol li.ql-indent-2{counter-increment:list-2;counter-reset:list-3 list-4 list-5 list-6 list-7 list-8 list-9}.ql-editor ol li.ql-indent-2::before{content:counter(list-2,lower-roman) ". "}.ql-editor ol li.ql-indent-3{counter-increment:list-3;counter-reset:list-4 list-5 list-6 list-7 list-8 list-9}.ql-editor ol li.ql-indent-3::before{content:counter(list-3,decimal) ". "}.ql-editor ol li.ql-indent-4{counter-increment:list-4;counter-reset:list-5 list-6 list-7 list-8 list-9}.ql-editor ol li.ql-indent-4::before{content:counter(list-4,lower-alpha) ". "}.ql-editor ol li.ql-indent-5{counter-increment:list-5;counter-reset:list-6 list-7 list-8 list-9}.ql-editor ol li.ql-indent-5::before{content:counter(list-5,lower-roman) ". "}.ql-editor ol li.ql-indent-6{counter-increment:list-6;counter-reset:list-7 list-8 list-9}.ql-editor ol li.ql-indent-6::before{content:counter(list-6,decimal) ". "}.ql-editor ol li.ql-indent-7{counter-increment:list-7;counter-reset:list-8 list-9}.ql-editor ol li.ql-indent-7::before{content:counter(list-7,lower-alpha) ". "}.ql-editor ol li.ql-indent-8{counter-increment:list-8;counter-reset:list-9}.ql-editor ol li.ql-indent-8::before{content:counter(list-8,lower-roman) ". "}.ql-editor ol li.ql-indent-9{counter-increment:list-9}.ql-editor ol li.ql-indent-9::before{content:counter(list-9,decimal) ". "}'; | |
| 53 | - | |
| 54 | - /** | |
| 55 | 30 | * Dashboard widget entries data. |
| 56 | 31 | * |
| 57 | 32 | * @var array |
| 58 | 33 | * @since 1.9.1 |
| @@ -59,16 +34,8 @@ | ||
| 59 | 34 | */ |
| 60 | 35 | private $dashboard_widget_data = []; |
| 61 | 36 | |
| 62 | 37 | /** |
| 63 | - * Cached result for whether the rating notice should display. | |
| 64 | - * | |
| 65 | - * @var bool|null | |
| 66 | - * @since 2.5.2 | |
| 67 | - */ | |
| 68 | - private $should_show_rating = null; | |
| 69 | - | |
| 70 | - /** | |
| 71 | 38 | * SureForms Page Default permission. |
| 72 | 39 | * |
| 73 | 40 | * @var string |
| 74 | 41 | * @since 1.12.2 |
| @@ -84,15 +51,11 @@ | ||
| 84 | 51 | public function __construct() { |
| 85 | 52 | add_action( 'admin_menu', [ $this, 'add_menu_page' ], 9 ); |
| 86 | 53 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 87 | 54 | add_action( 'admin_menu', [ $this, 'settings_page' ] ); |
| 88 | - add_action( 'admin_menu', [ $this, 'add_learn_page' ] ); | |
| 89 | 55 | add_action( 'admin_menu', [ $this, 'add_new_form' ] ); |
| 90 | 56 | add_action( 'admin_menu', [ $this, 'add_suremail_page' ] ); |
| 91 | 57 | if ( ! Helper::has_pro() ) { |
| 92 | - add_action( 'admin_menu', [ $this, 'add_quiz_page' ] ); | |
| 93 | - add_action( 'admin_menu', [ $this, 'add_survey_reports_page' ] ); | |
| 94 | - add_action( 'admin_menu', [ $this, 'add_partial_entries_page' ] ); | |
| 95 | 58 | add_action( 'admin_menu', [ $this, 'add_upgrade_to_pro' ] ); |
| 96 | 59 | add_action( 'admin_footer', [ $this, 'add_upgrade_to_pro_target_attr' ] ); |
| 97 | 60 | } |
| 98 | 61 | |
| @@ -104,13 +67,19 @@ | ||
| 104 | 67 | // this action is used to restrict Spectra's quick action bar on SureForms CPTS. |
| 105 | 68 | add_action( 'uag_enable_quick_action_sidebar', [ $this, 'restrict_spectra_quick_action_bar' ] ); |
| 106 | 69 | |
| 107 | 70 | add_action( 'current_screen', [ $this, 'enable_gutenberg_for_sureforms' ], 100 ); |
| 108 | - // Register notices early for React pages (before admin_enqueue_scripts). | |
| 109 | - add_action( 'admin_init', [ $this, 'register_pro_compatibility_notices' ], 5 ); | |
| 110 | - // Display notices on traditional WordPress admin pages. | |
| 111 | 71 | add_action( 'admin_notices', [ $this, 'srfm_pro_version_compatibility' ] ); |
| 112 | 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 | + ); | |
| 113 | 82 | // Enfold theme compatibility to enable block editor for SureForms post type. |
| 114 | 83 | add_filter( 'avf_use_block_editor_for_post', [ $this, 'enable_block_editor_in_enfold_theme' ] ); |
| 115 | 84 | |
| 116 | 85 | // Add action links to the plugin page. |
| @@ -122,8 +91,10 @@ | ||
| 122 | 91 | if ( $admin_notification_on ) { |
| 123 | 92 | add_action( 'admin_menu', [ $this, 'maybe_add_entries_badge' ], 99 ); |
| 124 | 93 | } |
| 125 | 94 | |
| 95 | + add_action( 'admin_menu', [ $this, 'add_payments_badge' ], 99 ); | |
| 96 | + | |
| 126 | 97 | add_filter( 'wpforms_current_user_can', [ $this, 'disable_wpforms_capabilities' ], 10, 3 ); |
| 127 | 98 | |
| 128 | 99 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_pointer' ] ); |
| 129 | 100 | // Ajax callbacks for wp-pointer functionality. |
| @@ -129,97 +100,17 @@ | ||
| 129 | 100 | // Ajax callbacks for wp-pointer functionality. |
| 130 | 101 | add_action( 'wp_ajax_should_show_pointer', [ $this, 'pointer_should_show' ] ); |
| 131 | 102 | add_action( 'wp_ajax_sureforms_dismiss_pointer', [ $this, 'pointer_dismissed' ] ); |
| 132 | 103 | add_action( 'wp_ajax_sureforms_accept_cta', [ $this, 'pointer_accepted_cta' ] ); |
| 133 | - add_action( 'wp_ajax_srfm_notice_response', [ $this, 'handle_notice_response' ] ); | |
| 134 | - add_action( 'wp_ajax_srfm_ai_widget_usage', [ $this, 'track_ai_widget_usage' ] ); | |
| 135 | 104 | |
| 136 | 105 | // Register dashboard widget only if there are recent entries. |
| 137 | 106 | add_action( 'admin_init', [ $this, 'maybe_register_dashboard_widget' ] ); |
| 138 | 107 | |
| 139 | - // Enqueue the AI quick draft widget script on the dashboard screen. | |
| 140 | - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_ai_dashboard_widget_assets' ] ); | |
| 141 | - | |
| 142 | 108 | // Save first form creation time stamp. |
| 143 | 109 | add_action( 'admin_init', [ $this, 'save_first_form_creation_time_stamp' ] ); |
| 144 | - add_action( 'admin_notices', [ $this, 'display_srfm_rating_notice' ] ); | |
| 145 | - add_action( 'admin_notices', [ $this, 'display_srfm_getting_started_notice' ] ); | |
| 146 | - | |
| 147 | - /** | |
| 148 | - * Suppress foreign (third-party) admin notices on SureForms admin screens. | |
| 149 | - * | |
| 150 | - * Some plugins (e.g. Ninja Forms) print large promotional banners on every | |
| 151 | - * admin page via the admin_notices / all_admin_notices / network_admin_notices | |
| 152 | - * hooks. These bleed onto SureForms' own React admin screens and break the UI. | |
| 153 | - * We run at the EARLIEST priority on each notice hook (all third-party | |
| 154 | - * callbacks are registered before these hooks fire, during admin_init / | |
| 155 | - * plugin load) and strip the foreign ones before they are echoed, while | |
| 156 | - * preserving SureForms' own notices. Scoped strictly to SureForms screens. | |
| 157 | - */ | |
| 158 | - add_action( 'admin_notices', [ $this, 'suppress_foreign_admin_notices' ], PHP_INT_MIN ); | |
| 159 | - add_action( 'all_admin_notices', [ $this, 'suppress_foreign_admin_notices' ], PHP_INT_MIN ); | |
| 160 | - add_action( 'network_admin_notices', [ $this, 'suppress_foreign_admin_notices' ], PHP_INT_MIN ); | |
| 161 | 110 | } |
| 162 | 111 | |
| 163 | 112 | /** |
| 164 | - * Remove third-party admin notices on SureForms admin screens. | |
| 165 | - * | |
| 166 | - * Iterates over the callbacks registered on the admin notice hooks and | |
| 167 | - * removes any that are not owned by SureForms. A callback is considered | |
| 168 | - * owned by SureForms when it belongs to a class in the `SRFM` / `SRFM_PRO` | |
| 169 | - * namespaces or to the bundled `BSF_Admin_Notices` / `Astra_Notices` | |
| 170 | - * notices library. SureForms' own notices are therefore preserved while | |
| 171 | - * foreign promotional banners are suppressed. | |
| 172 | - * | |
| 173 | - * This callback is hooked at `PHP_INT_MIN` so that it runs first on each | |
| 174 | - * notice hook and removes the foreign callbacks before WordPress echoes | |
| 175 | - * them (WP_Hook honours removals made during iteration). It is strictly | |
| 176 | - * scoped to SureForms admin screens via {@see Helper::is_sureforms_admin_page()} | |
| 177 | - * so no other admin page is affected. | |
| 178 | - * | |
| 179 | - * @since 2.10.0 | |
| 180 | - * @return void | |
| 181 | - */ | |
| 182 | - public function suppress_foreign_admin_notices() { | |
| 183 | - // Bail early if we are not on a SureForms admin screen. This keeps the | |
| 184 | - // suppression strictly scoped and avoids touching any other admin page. | |
| 185 | - // is_sureforms_admin_page() covers the core screens (dashboard, add-new, | |
| 186 | - // settings, entries, the form CPT); we additionally match any admin page | |
| 187 | - // whose `page` slug is SureForms-owned (sureforms_* / srfm_*) so the | |
| 188 | - // suppression also applies to the payments/quiz/survey/learn/SMTP screens. | |
| 189 | - if ( ! Helper::is_sureforms_admin_page() && ! $this->is_sureforms_owned_admin_page() ) { | |
| 190 | - return; | |
| 191 | - } | |
| 192 | - | |
| 193 | - global $wp_filter; | |
| 194 | - | |
| 195 | - // The hook currently being fired (admin_notices, all_admin_notices or network_admin_notices). | |
| 196 | - $current_hook = current_action(); | |
| 197 | - | |
| 198 | - if ( empty( $current_hook ) || empty( $wp_filter[ $current_hook ] ) || ! ( $wp_filter[ $current_hook ] instanceof \WP_Hook ) ) { | |
| 199 | - return; | |
| 200 | - } | |
| 201 | - | |
| 202 | - foreach ( $wp_filter[ $current_hook ]->callbacks as $priority => $callbacks ) { | |
| 203 | - foreach ( $callbacks as $callback ) { | |
| 204 | - $function = $callback['function'] ?? null; | |
| 205 | - | |
| 206 | - // Never remove our own suppression callback. | |
| 207 | - if ( is_array( $function ) && isset( $function[0] ) && $function[0] === $this && 'suppress_foreign_admin_notices' === $function[1] ) { | |
| 208 | - continue; | |
| 209 | - } | |
| 210 | - | |
| 211 | - // Preserve SureForms-owned notices, remove everything else. | |
| 212 | - if ( $this->is_sureforms_owned_notice_callback( $function ) ) { | |
| 213 | - continue; | |
| 214 | - } | |
| 215 | - | |
| 216 | - remove_action( $current_hook, $function, $priority ); | |
| 217 | - } | |
| 218 | - } | |
| 219 | - } | |
| 220 | - | |
| 221 | - /** | |
| 222 | 113 | * Get the first form creation time stamp. |
| 223 | 114 | * |
| 224 | 115 | * @since 1.10.1 |
| 225 | 116 | * @return int|false |
| @@ -320,9 +211,14 @@ | ||
| 320 | 211 | */ |
| 321 | 212 | public function add_action_links( $links ) { |
| 322 | 213 | if ( ! Helper::has_pro() ) { |
| 323 | 214 | // Display upsell link if SureForms Pro is not installed. |
| 324 | - $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 | + ); | |
| 325 | 221 | |
| 326 | 222 | ob_start(); |
| 327 | 223 | ?> |
| 328 | 224 | <a href="<?php echo esc_url( $upsell_link ); ?>" target="_blank" rel="noreferrer" class="sureforms-plugins-go-pro"> |
| @@ -482,9 +378,14 @@ | ||
| 482 | 378 | */ |
| 483 | 379 | public function add_upgrade_to_pro() { |
| 484 | 380 | // The url used here is used as a selector for css to style the upgrade to pro submenu. |
| 485 | 381 | // If you are changing this url, please make sure to update the css as well. |
| 486 | - $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 | + ); | |
| 487 | 388 | |
| 488 | 389 | add_submenu_page( |
| 489 | 390 | 'sureforms_menu', |
| 490 | 391 | __( 'Upgrade', 'sureforms' ), |
| @@ -494,107 +395,8 @@ | ||
| 494 | 395 | ); |
| 495 | 396 | } |
| 496 | 397 | |
| 497 | 398 | /** |
| 498 | - * Add Quiz empty state submenu page for free users. | |
| 499 | - * | |
| 500 | - * @return void | |
| 501 | - * @since 2.7.0 | |
| 502 | - */ | |
| 503 | - public function add_quiz_page() { | |
| 504 | - add_submenu_page( | |
| 505 | - 'sureforms_menu', | |
| 506 | - __( 'Quiz Entries', 'sureforms' ), | |
| 507 | - __( 'Quizzes', 'sureforms' ) . | |
| 508 | - ' <span style="color:#4ADE80;font-size:9px;font-weight:600;">' . | |
| 509 | - esc_html__( 'New', 'sureforms' ) . | |
| 510 | - '</span>', | |
| 511 | - self::$sureforms_page_default_capability, | |
| 512 | - 'sureforms_quiz_entries', | |
| 513 | - [ $this, 'render_quiz_empty_state' ], | |
| 514 | - 5 | |
| 515 | - ); | |
| 516 | - } | |
| 517 | - | |
| 518 | - /** | |
| 519 | - * Quiz empty state page callback. | |
| 520 | - * | |
| 521 | - * @return void | |
| 522 | - * @since 2.7.0 | |
| 523 | - */ | |
| 524 | - public function render_quiz_empty_state() { | |
| 525 | - ?> | |
| 526 | - <div id="srfm-quiz-entries-root" class="srfm-admin-wrapper"></div> | |
| 527 | - <?php | |
| 528 | - } | |
| 529 | - | |
| 530 | - /** | |
| 531 | - * Add Survey Reports promotional submenu page for free users. | |
| 532 | - * | |
| 533 | - * @return void | |
| 534 | - * @since 2.8.0 | |
| 535 | - */ | |
| 536 | - public function add_survey_reports_page() { | |
| 537 | - add_submenu_page( | |
| 538 | - 'sureforms_menu', | |
| 539 | - __( 'Survey Reports', 'sureforms' ), | |
| 540 | - __( 'Survey Reports', 'sureforms' ) . | |
| 541 | - ' <span style="color:#4ADE80;font-size:9px;font-weight:600;">' . | |
| 542 | - esc_html__( 'New', 'sureforms' ) . | |
| 543 | - '</span>', | |
| 544 | - self::$sureforms_page_default_capability, | |
| 545 | - 'sureforms_survey_reports', | |
| 546 | - [ $this, 'render_survey_empty_state' ], | |
| 547 | - 6 | |
| 548 | - ); | |
| 549 | - } | |
| 550 | - | |
| 551 | - /** | |
| 552 | - * Survey empty state page callback. | |
| 553 | - * | |
| 554 | - * @return void | |
| 555 | - * @since 2.8.0 | |
| 556 | - */ | |
| 557 | - public function render_survey_empty_state() { | |
| 558 | - ?> | |
| 559 | - <div id="srfm-survey-empty-state-root" class="srfm-admin-wrapper"></div> | |
| 560 | - <?php | |
| 561 | - } | |
| 562 | - | |
| 563 | - /** | |
| 564 | - * Add Partial Entries promotional submenu page for free users. | |
| 565 | - * | |
| 566 | - * @return void | |
| 567 | - * @since 2.9.0 | |
| 568 | - */ | |
| 569 | - public function add_partial_entries_page() { | |
| 570 | - add_submenu_page( | |
| 571 | - 'sureforms_menu', | |
| 572 | - __( 'Partial Entries', 'sureforms' ), | |
| 573 | - __( 'Partial Entries', 'sureforms' ) . | |
| 574 | - ' <span style="color:#4ADE80;font-size:9px;font-weight:600;">' . | |
| 575 | - esc_html__( 'New', 'sureforms' ) . | |
| 576 | - '</span>', | |
| 577 | - self::$sureforms_page_default_capability, | |
| 578 | - 'sureforms_partial_entries', | |
| 579 | - [ $this, 'render_partial_entries_empty_state' ], | |
| 580 | - 7 | |
| 581 | - ); | |
| 582 | - } | |
| 583 | - | |
| 584 | - /** | |
| 585 | - * Partial Entries empty state page callback. | |
| 586 | - * | |
| 587 | - * @return void | |
| 588 | - * @since 2.9.0 | |
| 589 | - */ | |
| 590 | - public function render_partial_entries_empty_state() { | |
| 591 | - ?> | |
| 592 | - <div id="srfm-partial-entries-empty-state-root" class="srfm-admin-wrapper"></div> | |
| 593 | - <?php | |
| 594 | - } | |
| 595 | - | |
| 596 | - /** | |
| 597 | 399 | * Add SMTP promotional submenu page. |
| 598 | 400 | * |
| 599 | 401 | * @return void |
| 600 | 402 | * @since 1.7.1 |
| @@ -656,37 +458,8 @@ | ||
| 656 | 458 | <?php |
| 657 | 459 | } |
| 658 | 460 | |
| 659 | 461 | /** |
| 660 | - * Add Learn submenu page. | |
| 661 | - * | |
| 662 | - * @return void | |
| 663 | - * @since 2.5.2 | |
| 664 | - */ | |
| 665 | - public function add_learn_page() { | |
| 666 | - add_submenu_page( | |
| 667 | - 'sureforms_menu', | |
| 668 | - __( 'Learn', 'sureforms' ), | |
| 669 | - __( 'Learn', 'sureforms' ), | |
| 670 | - self::$sureforms_page_default_capability, | |
| 671 | - 'sureforms_learn', | |
| 672 | - [ $this, 'render_learn' ] | |
| 673 | - ); | |
| 674 | - } | |
| 675 | - | |
| 676 | - /** | |
| 677 | - * Learn page callback. | |
| 678 | - * | |
| 679 | - * @return void | |
| 680 | - * @since 2.5.2 | |
| 681 | - */ | |
| 682 | - public function render_learn() { | |
| 683 | - ?> | |
| 684 | - <div id="srfm-learn-root" class="srfm-admin-wrapper"></div> | |
| 685 | - <?php | |
| 686 | - } | |
| 687 | - | |
| 688 | - /** | |
| 689 | 462 | * Add new form menu item. |
| 690 | 463 | * |
| 691 | 464 | * @return void |
| 692 | 465 | * @since 0.0.1 |
| @@ -840,8 +613,36 @@ | ||
| 840 | 613 | } |
| 841 | 614 | } |
| 842 | 615 | |
| 843 | 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 | + /** | |
| 844 | 645 | * Mark the user's visit to the entries page. |
| 845 | 646 | * |
| 846 | 647 | * @since 1.7.3 |
| 847 | 648 | * @return void |
| @@ -908,9 +709,8 @@ | ||
| 908 | 709 | wp_enqueue_style( SRFM_SLUG . '-backend-blocks', $css_uri . 'blocks/default/backend' . $file_prefix . '.css', [], SRFM_VER ); |
| 909 | 710 | wp_enqueue_style( SRFM_SLUG . '-intl', $vendor_css_uri . 'intl/intlTelInput-backend.min.css', [], SRFM_VER ); |
| 910 | 711 | wp_enqueue_style( SRFM_SLUG . '-common', $css_uri . 'common' . $file_prefix . '.css', [], SRFM_VER ); |
| 911 | 712 | wp_enqueue_style( SRFM_SLUG . '-reactQuill', $vendor_css_uri . 'quill/quill.snow.css', [], SRFM_VER ); |
| 912 | - wp_add_inline_style( SRFM_SLUG . '-reactQuill', self::QUILL_1X_INLINE_CSS ); | |
| 913 | 713 | wp_enqueue_style( SRFM_SLUG . '-single-form-modal', $css_uri . 'single-form-setting' . $file_prefix . '.css', [], SRFM_VER ); |
| 914 | 714 | |
| 915 | 715 | // if version is equal to or lower than 6.6.2 then add compatibility css. |
| 916 | 716 | if ( version_compare( $wp_version, '6.6.2', '<=' ) ) { |
| @@ -998,91 +798,59 @@ | ||
| 998 | 798 | * List of the handles in which we need to add translation compatibility. |
| 999 | 799 | */ |
| 1000 | 800 | $script_translations_handlers = []; |
| 1001 | 801 | $onboarding_instance = Onboarding::get_instance(); |
| 1002 | - $current_user = wp_get_current_user(); | |
| 1003 | 802 | |
| 1004 | 803 | $localization_data = [ |
| 1005 | - 'site_url' => get_site_url(), | |
| 1006 | - 'current_user_login' => $current_user->user_login ?? '', | |
| 1007 | - 'website_lead_details' => [ | |
| 1008 | - 'first_name' => $current_user->first_name ?? '', | |
| 1009 | - 'last_name' => $current_user->last_name ?? '', | |
| 1010 | - '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(), | |
| 1011 | 843 | ], |
| 1012 | - 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(), | |
| 1013 | - 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ), | |
| 1014 | - 'plugin_version' => SRFM_VER, | |
| 1015 | - 'global_settings_nonce' => Helper::current_user_can() ? wp_create_nonce( 'wp_rest' ) : '', | |
| 1016 | - 'is_pro_active' => Helper::has_pro(), | |
| 1017 | - 'is_first_form_created' => self::is_first_form_created(), | |
| 1018 | - 'check_three_days_threshold' => self::check_first_form_creation_threshold(), | |
| 1019 | - 'check_eight_days_threshold' => self::check_first_form_creation_threshold( 8 ), | |
| 1020 | - 'pro_plugin_version' => Helper::has_pro() ? SRFM_PRO_VER : '', | |
| 1021 | - 'pro_plugin_name' => Helper::has_pro() && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro', | |
| 1022 | - 'sureforms_pricing_page' => Helper::get_sureforms_website_url( 'pricing' ), | |
| 1023 | - 'field_spacing_vars' => Helper::get_css_vars(), | |
| 1024 | - 'is_ver_lower_than_6_7' => version_compare( $wp_version, '6.6.2', '<=' ), | |
| 1025 | - 'integrations' => Helper::sureforms_get_integration(), | |
| 1026 | - 'rotating_plugin_banner' => Helper::get_rotating_plugin_banner(), | |
| 1027 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 1028 | - 'sf_plugin_manager_nonce' => wp_create_nonce( 'sf_plugin_manager_nonce' ), | |
| 1029 | - 'plugin_installer_nonce' => wp_create_nonce( 'updates' ), | |
| 1030 | - 'plugin_activating_text' => __( 'Activating...', 'sureforms' ), | |
| 1031 | - 'plugin_activated_text' => __( 'Activated', 'sureforms' ), | |
| 1032 | - 'plugin_activate_text' => __( 'Activate', 'sureforms' ), | |
| 1033 | - 'plugin_installing_text' => __( 'Installing...', 'sureforms' ), | |
| 1034 | - 'plugin_installed_text' => __( 'Installed', 'sureforms' ), | |
| 1035 | - 'privacy_policy_url' => Helper::get_sureforms_website_url( 'privacy-policy/' ), | |
| 1036 | - 'is_rtl' => $is_rtl, | |
| 1037 | - 'onboarding_completed' => method_exists( $onboarding_instance, 'get_onboarding_status' ) ? $onboarding_instance->get_onboarding_status() : false, | |
| 1038 | - 'migration_banner_dismissed' => method_exists( $onboarding_instance, 'is_migration_banner_dismissed' ) ? $onboarding_instance->is_migration_banner_dismissed() : false, | |
| 1039 | - 'migration_settings_url' => admin_url( 'admin.php?page=sureforms_form_settings&tab=migration-settings' ), | |
| 1040 | - 'onboarding_redirect' => isset( $_GET['srfm-activation-redirect'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required for the activation redirection. | |
| 1041 | - 'pointer_nonce' => wp_create_nonce( 'sureforms_pointer_action' ), | |
| 1042 | - 'general_settings_url' => admin_url( '/options-general.php' ), | |
| 1043 | - 'additional_header_nav_items' => [], | |
| 1044 | - // Smart tags for the Global Defaults email notification fields. | |
| 1045 | - // srfm_block_data is only available in the block editor; these keys | |
| 1046 | - // make the same data accessible on the settings page via srfm_admin. | |
| 1047 | - 'smart_tags_array' => Smart_Tags::smart_tag_list(), | |
| 1048 | - 'smart_tags_array_email' => Smart_Tags::email_smart_tag_list(), | |
| 1049 | - // Default confirmation message HTML (icon + heading + text) used as | |
| 1050 | - // the initial React state before the settings API response arrives. | |
| 1051 | - 'default_confirmation_message' => Global_Settings::get_default_confirmation_message(), | |
| 1052 | - 'payments' => apply_filters( | |
| 1053 | - 'srfm_admin_localize_payments_data', | |
| 1054 | - [ | |
| 1055 | - 'stripe_connected' => Stripe_Helper::is_stripe_connected(), | |
| 1056 | - 'stripe_mode' => Stripe_Helper::get_stripe_mode(), | |
| 1057 | - 'stripe_connect_url' => Stripe_Helper::get_stripe_settings_url(), | |
| 1058 | - 'currencies_data' => Payment_Helper::get_all_currencies_data(), | |
| 1059 | - 'zero_decimal_currencies' => Payment_Helper::get_zero_decimal_currencies(), | |
| 1060 | - 'webhook_url' => Stripe_Helper::get_webhook_url(), | |
| 1061 | - 'webhook_test_connected' => Stripe_Helper::is_webhook_configured( 'test', true ), | |
| 1062 | - 'webhook_live_connected' => Stripe_Helper::is_webhook_configured( 'live', true ), | |
| 1063 | - 'is_transaction_present' => Stripe_Helper::is_transaction_present(), | |
| 1064 | - 'payment_currency' => Payment_Helper::get_currency(), | |
| 1065 | - 'currency_sign_position' => Payment_Helper::get_currency_sign_position(), | |
| 1066 | - ] | |
| 1067 | - ), | |
| 1068 | - 'mcp_adapter_status' => file_exists( WP_PLUGIN_DIR . '/mcp-adapter/mcp-adapter.php' ) | |
| 1069 | - ? ( is_plugin_active( 'mcp-adapter/mcp-adapter.php' ) ? 'active' : 'installed' ) | |
| 1070 | - : 'not_installed', | |
| 1071 | - 'mcp_endpoint_url' => esc_url_raw( rest_url( 'sureforms/v1/mcp' ) ), | |
| 1072 | 844 | ]; |
| 1073 | 845 | |
| 1074 | - $is_screen_sureforms_menu = Helper::validate_request_context( 'sureforms_menu', 'page' ); | |
| 1075 | - $is_screen_add_new_form = Helper::validate_request_context( 'add-new-form', 'page' ); | |
| 1076 | - $is_screen_sureforms_forms = Helper::validate_request_context( 'sureforms_forms', 'page' ); | |
| 1077 | - $is_screen_sureforms_form_settings = Helper::validate_request_context( 'sureforms_form_settings', 'page' ); | |
| 1078 | - $is_screen_sureforms_payments = Helper::validate_request_context( 'sureforms_payments', 'page' ); | |
| 1079 | - $is_screen_sureforms_entries = Helper::validate_request_context( SRFM_ENTRIES, 'page' ); | |
| 1080 | - $is_screen_sureforms_learn = Helper::validate_request_context( 'sureforms_learn', 'page' ); | |
| 1081 | - $is_screen_quiz_empty_state = Helper::validate_request_context( 'sureforms_quiz_entries', 'page' ); | |
| 1082 | - $is_screen_survey_empty_state = Helper::validate_request_context( 'sureforms_survey_reports', 'page' ); | |
| 1083 | - $is_screen_partial_entries_empty_state = Helper::validate_request_context( 'sureforms_partial_entries', 'page' ); | |
| 1084 | - $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; | |
| 1085 | 853 | |
| 1086 | 854 | /** |
| 1087 | 855 | * Check if the current screen is the SureForms Menu and AI Auth Email is present then we will add user type as registered. |
| 1088 | 856 | * Compatibility with existing UI code that checks for this condition. |
| @@ -1093,39 +861,9 @@ | ||
| 1093 | 861 | 'type' => ! empty( get_option( 'srfm_ai_auth_user_email' ) ) ? 'registered' : 'non-registered', |
| 1094 | 862 | ]; |
| 1095 | 863 | } |
| 1096 | 864 | |
| 1097 | - // Add the Quizzes and Survey Reports nav items when pro is not active. | |
| 1098 | - if ( ! Helper::has_pro() ) { | |
| 1099 | - $localization_data['additional_header_nav_items'][] = [ | |
| 1100 | - 'slug' => 'sureforms_quiz_entries', | |
| 1101 | - 'text' => __( 'Quizzes', 'sureforms' ), | |
| 1102 | - 'link' => admin_url( 'admin.php?page=sureforms_quiz_entries' ), | |
| 1103 | - ]; | |
| 1104 | - $localization_data['additional_header_nav_items'][] = [ | |
| 1105 | - 'slug' => 'sureforms_survey_reports', | |
| 1106 | - 'text' => __( 'Survey Reports', 'sureforms' ), | |
| 1107 | - 'link' => admin_url( 'admin.php?page=sureforms_survey_reports' ), | |
| 1108 | - ]; | |
| 1109 | - $localization_data['additional_header_nav_items'][] = [ | |
| 1110 | - 'slug' => 'sureforms_partial_entries', | |
| 1111 | - 'text' => __( 'Partial Entries', 'sureforms' ), | |
| 1112 | - 'link' => admin_url( 'admin.php?page=sureforms_partial_entries' ), | |
| 1113 | - ]; | |
| 1114 | - } | |
| 1115 | - | |
| 1116 | - $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; | |
| 1117 | - | |
| 1118 | - /** | |
| 1119 | - * Filter to allow extending the SureForms dashboard screen check. | |
| 1120 | - * | |
| 1121 | - * @since 2.6.0 | |
| 1122 | - * | |
| 1123 | - * @param bool $is_sureforms_screen Whether the current screen is a SureForms dashboard screen. | |
| 1124 | - */ | |
| 1125 | - $is_sureforms_screen = apply_filters( 'srfm_is_dashboard_screen', $is_sureforms_screen ); | |
| 1126 | - | |
| 1127 | - 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 ) { | |
| 1128 | 866 | $asset_handle = '-dashboard'; |
| 1129 | 867 | |
| 1130 | 868 | wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER ); |
| 1131 | 869 | |
| @@ -1175,35 +913,11 @@ | ||
| 1175 | 913 | if ( $is_screen_sureforms_entries ) { |
| 1176 | 914 | $asset_handle = '-entries'; |
| 1177 | 915 | wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/entries.js', $script_info['dependencies'], SRFM_VER, true ); |
| 1178 | 916 | |
| 1179 | - wp_localize_script( | |
| 1180 | - SRFM_SLUG . $asset_handle, | |
| 1181 | - SRFM_SLUG . '_admin', | |
| 1182 | - apply_filters( | |
| 1183 | - SRFM_SLUG . '_admin_filter', | |
| 1184 | - $localization_data | |
| 1185 | - ) | |
| 1186 | - ); | |
| 1187 | 917 | $script_translations_handlers[] = SRFM_SLUG . $asset_handle; |
| 1188 | 918 | } |
| 1189 | 919 | |
| 1190 | - // Enqueue scripts for the learn page. | |
| 1191 | - if ( $is_screen_sureforms_learn ) { | |
| 1192 | - $asset_handle = '-learn'; | |
| 1193 | - wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/learn.js', $script_info['dependencies'], SRFM_VER, true ); | |
| 1194 | - | |
| 1195 | - wp_localize_script( | |
| 1196 | - SRFM_SLUG . $asset_handle, | |
| 1197 | - SRFM_SLUG . '_admin', | |
| 1198 | - apply_filters( | |
| 1199 | - SRFM_SLUG . '_admin_filter', | |
| 1200 | - $localization_data | |
| 1201 | - ) | |
| 1202 | - ); | |
| 1203 | - $script_translations_handlers[] = SRFM_SLUG . $asset_handle; | |
| 1204 | - } | |
| 1205 | - | |
| 1206 | 920 | // Enqueue scripts for the forms page. |
| 1207 | 921 | if ( $is_screen_sureforms_forms ) { |
| 1208 | 922 | $asset_handle = '-forms'; |
| 1209 | 923 | |
| @@ -1218,12 +932,9 @@ | ||
| 1218 | 932 | wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/forms.js', $script_info['dependencies'], SRFM_VER, true ); |
| 1219 | 933 | wp_localize_script( |
| 1220 | 934 | SRFM_SLUG . $asset_handle, |
| 1221 | 935 | SRFM_SLUG . '_admin', |
| 1222 | - apply_filters( | |
| 1223 | - SRFM_SLUG . '_admin_filter', | |
| 1224 | - $localization_data | |
| 1225 | - ) | |
| 936 | + $localization_data | |
| 1226 | 937 | ); |
| 1227 | 938 | wp_enqueue_style( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/forms.css', [], SRFM_VER, 'all' ); |
| 1228 | 939 | |
| 1229 | 940 | $script_translations_handlers[] = SRFM_SLUG . $asset_handle; |
| @@ -1268,62 +979,8 @@ | ||
| 1268 | 979 | |
| 1269 | 980 | $script_translations_handlers[] = SRFM_SLUG . '-suremail'; |
| 1270 | 981 | } |
| 1271 | 982 | |
| 1272 | - // Enqueue scripts for the Quiz empty state page (free users only). | |
| 1273 | - if ( $is_screen_quiz_empty_state && ! Helper::has_pro() ) { | |
| 1274 | - $asset_handle = 'quizEmptyState'; | |
| 1275 | - | |
| 1276 | - $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; | |
| 1277 | - $script_info = file_exists( $script_asset_path ) | |
| 1278 | - ? include $script_asset_path | |
| 1279 | - : [ | |
| 1280 | - 'dependencies' => [], | |
| 1281 | - 'version' => SRFM_VER, | |
| 1282 | - ]; | |
| 1283 | - | |
| 1284 | - wp_enqueue_script( SRFM_SLUG . '-quiz-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); | |
| 1285 | - wp_enqueue_style( SRFM_SLUG . '-quiz-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [], SRFM_VER, 'all' ); | |
| 1286 | - | |
| 1287 | - $script_translations_handlers[] = SRFM_SLUG . '-quiz-empty-state'; | |
| 1288 | - } | |
| 1289 | - | |
| 1290 | - // Enqueue scripts for the Survey Reports empty state page (free users only). | |
| 1291 | - if ( $is_screen_survey_empty_state && ! Helper::has_pro() ) { | |
| 1292 | - $asset_handle = 'surveyEmptyState'; | |
| 1293 | - | |
| 1294 | - $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; | |
| 1295 | - $script_info = file_exists( $script_asset_path ) | |
| 1296 | - ? include $script_asset_path | |
| 1297 | - : [ | |
| 1298 | - 'dependencies' => [], | |
| 1299 | - 'version' => SRFM_VER, | |
| 1300 | - ]; | |
| 1301 | - | |
| 1302 | - wp_enqueue_script( SRFM_SLUG . '-survey-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); | |
| 1303 | - wp_enqueue_style( SRFM_SLUG . '-survey-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [], SRFM_VER, 'all' ); | |
| 1304 | - | |
| 1305 | - $script_translations_handlers[] = SRFM_SLUG . '-survey-empty-state'; | |
| 1306 | - } | |
| 1307 | - | |
| 1308 | - // Enqueue scripts for the Partial Entries empty state page (free users only). | |
| 1309 | - if ( $is_screen_partial_entries_empty_state && ! Helper::has_pro() ) { | |
| 1310 | - $asset_handle = 'partialEntriesEmptyState'; | |
| 1311 | - | |
| 1312 | - $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; | |
| 1313 | - $script_info = file_exists( $script_asset_path ) | |
| 1314 | - ? include $script_asset_path | |
| 1315 | - : [ | |
| 1316 | - 'dependencies' => [], | |
| 1317 | - 'version' => SRFM_VER, | |
| 1318 | - ]; | |
| 1319 | - | |
| 1320 | - wp_enqueue_script( SRFM_SLUG . '-partial-entries-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); | |
| 1321 | - wp_enqueue_style( SRFM_SLUG . '-partial-entries-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [], SRFM_VER, 'all' ); | |
| 1322 | - | |
| 1323 | - $script_translations_handlers[] = SRFM_SLUG . '-partial-entries-empty-state'; | |
| 1324 | - } | |
| 1325 | - | |
| 1326 | 983 | // Admin Submenu Styles. |
| 1327 | 984 | wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . $rtl . '.css', [], SRFM_VER ); |
| 1328 | 985 | |
| 1329 | 986 | if ( $is_screen_sureforms_form_settings ) { |
| @@ -1340,19 +997,11 @@ | ||
| 1340 | 997 | wp_enqueue_script( SRFM_SLUG . '-settings', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); |
| 1341 | 998 | wp_localize_script( |
| 1342 | 999 | SRFM_SLUG . '-settings', |
| 1343 | 1000 | SRFM_SLUG . '_admin', |
| 1344 | - apply_filters( | |
| 1345 | - SRFM_SLUG . '_admin_filter', | |
| 1346 | - $localization_data | |
| 1347 | - ) | |
| 1001 | + $localization_data | |
| 1348 | 1002 | ); |
| 1349 | 1003 | |
| 1350 | - // Enqueue Tailwind and Quill editor styles for the settings page. | |
| 1351 | - wp_enqueue_style( SRFM_SLUG . '-settings-build', SRFM_URL . 'assets/build/settings.css', [], SRFM_VER, 'all' ); | |
| 1352 | - wp_enqueue_style( SRFM_SLUG . '-reactQuill', SRFM_URL . 'assets/css/minified/deps/quill/quill.snow.css', [], SRFM_VER ); | |
| 1353 | - wp_add_inline_style( SRFM_SLUG . '-reactQuill', self::QUILL_1X_INLINE_CSS ); | |
| 1354 | - | |
| 1355 | 1004 | $script_translations_handlers[] = SRFM_SLUG . '-settings'; |
| 1356 | 1005 | } |
| 1357 | 1006 | |
| 1358 | 1007 | if ( $is_screen_add_new_form ) { |
| @@ -1505,55 +1154,8 @@ | ||
| 1505 | 1154 | return $status; |
| 1506 | 1155 | } |
| 1507 | 1156 | |
| 1508 | 1157 | /** |
| 1509 | - * Register Pro compatibility notices early for React pages. | |
| 1510 | - * | |
| 1511 | - * This method runs on admin_init (priority 5) to ensure notices are | |
| 1512 | - * registered BEFORE admin_enqueue_scripts, so they're available when | |
| 1513 | - * wp_localize_script runs. | |
| 1514 | - * | |
| 1515 | - * Hooked - admin_init (priority 5) | |
| 1516 | - * | |
| 1517 | - * @return void | |
| 1518 | - * @since 2.5.0 | |
| 1519 | - */ | |
| 1520 | - public function register_pro_compatibility_notices() { | |
| 1521 | - // Early exit if Pro is not active, user lacks permissions, or Notice_Manager is unavailable. | |
| 1522 | - if ( ! Helper::has_pro() || ! Helper::current_user_can() || ! class_exists( 'SRFM\Admin\Notice_Manager' ) ) { | |
| 1523 | - return; | |
| 1524 | - } | |
| 1525 | - | |
| 1526 | - // Register version outdated notice for React pages. | |
| 1527 | - if ( ! version_compare( SRFM_PRO_VER, SRFM_PRO_RECOMMENDED_VER, '>=' ) ) { | |
| 1528 | - $pro_plugin_name = defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro'; | |
| 1529 | - $react_outdated_message = sprintf( | |
| 1530 | - // translators: %1$s: SureForms version, %2$s: SureForms Pro Plugin Name, %3$s: SureForms Pro Version. | |
| 1531 | - esc_html__( 'SureForms %1$s requires minimum %2$s %3$s to work properly. Please update to the latest version.', 'sureforms' ), | |
| 1532 | - esc_html( SRFM_VER ), | |
| 1533 | - esc_html( $pro_plugin_name ), | |
| 1534 | - esc_html( SRFM_PRO_RECOMMENDED_VER ) | |
| 1535 | - ); | |
| 1536 | - | |
| 1537 | - \SRFM\Admin\Notice_Manager::register_notice( | |
| 1538 | - [ | |
| 1539 | - 'id' => 'sureforms-pro-version-outdated', | |
| 1540 | - 'variant' => 'warning', | |
| 1541 | - 'message' => $react_outdated_message, | |
| 1542 | - 'actions' => [ | |
| 1543 | - [ | |
| 1544 | - 'label' => esc_html__( 'Update Now', 'sureforms' ), | |
| 1545 | - 'url' => admin_url( 'update-core.php' ), | |
| 1546 | - 'variant' => 'primary', | |
| 1547 | - ], | |
| 1548 | - ], | |
| 1549 | - 'pages' => [ 'all' ], | |
| 1550 | - ] | |
| 1551 | - ); | |
| 1552 | - } | |
| 1553 | - } | |
| 1554 | - | |
| 1555 | - /** | |
| 1556 | 1158 | * Admin Notice Callback if sureforms pro is out of date. |
| 1557 | 1159 | * |
| 1558 | 1160 | * Hooked - admin_notices |
| 1559 | 1161 | * |
| @@ -1632,168 +1234,8 @@ | ||
| 1632 | 1234 | } |
| 1633 | 1235 | } |
| 1634 | 1236 | |
| 1635 | 1237 | /** |
| 1636 | - * Display a notice to the user about providing a review. | |
| 1637 | - * | |
| 1638 | - * @since 2.5.2 | |
| 1639 | - * @return void | |
| 1640 | - */ | |
| 1641 | - public function display_srfm_rating_notice() { | |
| 1642 | - // Only show to admins. | |
| 1643 | - if ( ! Helper::current_user_can() ) { | |
| 1644 | - return; | |
| 1645 | - } | |
| 1646 | - | |
| 1647 | - // Allow the notice to be disabled. | |
| 1648 | - if ( ! apply_filters( 'srfm_show_rating_notice', true ) ) { | |
| 1649 | - return; | |
| 1650 | - } | |
| 1651 | - | |
| 1652 | - Astra_Notices::add_notice( | |
| 1653 | - [ | |
| 1654 | - 'id' => 'srfm-plugin-review-notice', | |
| 1655 | - 'type' => '', | |
| 1656 | - 'message' => $this->build_notice_markup( | |
| 1657 | - esc_html__( 'Amazing! SureForms is powering your forms and submissions - let\'s keep growing together!', 'sureforms' ), | |
| 1658 | - esc_html__( 'If SureForms has been helpful, would you mind taking a moment to leave a 5-star review on WordPress.org?', 'sureforms' ), | |
| 1659 | - esc_url( 'https://wordpress.org/support/plugin/sureforms/reviews/' ), | |
| 1660 | - esc_html__( 'Rate SureForms', 'sureforms' ), | |
| 1661 | - esc_html__( 'Maybe later', 'sureforms' ), | |
| 1662 | - esc_html__( 'I already did', 'sureforms' ), | |
| 1663 | - WEEK_IN_SECONDS, | |
| 1664 | - true | |
| 1665 | - ), | |
| 1666 | - 'repeat-notice-after' => WEEK_IN_SECONDS, | |
| 1667 | - 'show_if' => $this->maybe_display_rating_notice(), | |
| 1668 | - 'display-with-other-notices' => true, | |
| 1669 | - ] | |
| 1670 | - ); | |
| 1671 | - | |
| 1672 | - add_action( 'astra_notice_after_markup_srfm-plugin-review-notice', [ $this, 'enqueue_notice_response_script' ] ); | |
| 1673 | - } | |
| 1674 | - | |
| 1675 | - /** | |
| 1676 | - * Display a "Getting Started" admin notice for new users who haven't yet | |
| 1677 | - * reached the rating-notice milestone (3+ forms or 3+ entries). | |
| 1678 | - * | |
| 1679 | - * The Astra Notices library handles the 7-day delay via the | |
| 1680 | - * `display-notice-after` parameter. | |
| 1681 | - * | |
| 1682 | - * @since 2.5.2 | |
| 1683 | - * @return void | |
| 1684 | - */ | |
| 1685 | - public function display_srfm_getting_started_notice() { | |
| 1686 | - // Only show to admins. | |
| 1687 | - if ( ! Helper::current_user_can() ) { | |
| 1688 | - return; | |
| 1689 | - } | |
| 1690 | - | |
| 1691 | - // Allow the notice to be disabled programmatically. | |
| 1692 | - if ( ! apply_filters( 'srfm_show_getting_started_notice', true ) ) { | |
| 1693 | - return; | |
| 1694 | - } | |
| 1695 | - | |
| 1696 | - Astra_Notices::add_notice( | |
| 1697 | - [ | |
| 1698 | - 'id' => 'srfm-getting-started-notice', | |
| 1699 | - 'type' => '', | |
| 1700 | - 'message' => $this->build_notice_markup( | |
| 1701 | - esc_html__( 'SureForms is ready to power your forms — explore what\'s possible!', 'sureforms' ), | |
| 1702 | - esc_html__( 'Manage your forms, track submissions, and discover features like AI Form Builder, payment integrations, and more from the SureForms dashboard.', 'sureforms' ), | |
| 1703 | - esc_url( admin_url( 'admin.php?page=sureforms_menu' ) ), | |
| 1704 | - esc_html__( 'Go to Dashboard', 'sureforms' ), | |
| 1705 | - esc_html__( 'Maybe later', 'sureforms' ), | |
| 1706 | - esc_html__( 'I already know', 'sureforms' ), | |
| 1707 | - WEEK_IN_SECONDS | |
| 1708 | - ), | |
| 1709 | - 'repeat-notice-after' => WEEK_IN_SECONDS, | |
| 1710 | - 'show_if' => ! $this->maybe_display_rating_notice(), | |
| 1711 | - 'display-notice-after' => WEEK_IN_SECONDS, | |
| 1712 | - 'display-with-other-notices' => true, | |
| 1713 | - ] | |
| 1714 | - ); | |
| 1715 | - | |
| 1716 | - add_action( 'astra_notice_after_markup_srfm-getting-started-notice', [ $this, 'enqueue_notice_response_script' ] ); | |
| 1717 | - } | |
| 1718 | - | |
| 1719 | - /** | |
| 1720 | - * Enqueue the notice response analytics script. | |
| 1721 | - * | |
| 1722 | - * Called via the astra_notice_after_markup_{id} hook so the script | |
| 1723 | - * only loads when a SureForms notice is actually rendered. | |
| 1724 | - * | |
| 1725 | - * @since 2.5.2 | |
| 1726 | - * @return void | |
| 1727 | - */ | |
| 1728 | - public function enqueue_notice_response_script() { | |
| 1729 | - if ( wp_script_is( 'srfm-notice-response', 'enqueued' ) ) { | |
| 1730 | - return; | |
| 1731 | - } | |
| 1732 | - | |
| 1733 | - wp_enqueue_script( | |
| 1734 | - 'srfm-notice-response', | |
| 1735 | - SRFM_URL . 'admin/assets/js/notice-response.js', | |
| 1736 | - [], | |
| 1737 | - SRFM_VER, | |
| 1738 | - true | |
| 1739 | - ); | |
| 1740 | - | |
| 1741 | - wp_localize_script( | |
| 1742 | - 'srfm-notice-response', | |
| 1743 | - 'srfmNoticeResponse', | |
| 1744 | - [ | |
| 1745 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 1746 | - 'nonce' => wp_create_nonce( 'srfm_notice_response' ), | |
| 1747 | - ] | |
| 1748 | - ); | |
| 1749 | - } | |
| 1750 | - | |
| 1751 | - /** | |
| 1752 | - * Handle the notice response AJAX request. | |
| 1753 | - * | |
| 1754 | - * Validates the request and records the analytics event | |
| 1755 | - * for the notice button that was clicked. | |
| 1756 | - * | |
| 1757 | - * @since 2.5.2 | |
| 1758 | - * @return void | |
| 1759 | - */ | |
| 1760 | - public function handle_notice_response() { | |
| 1761 | - if ( ! check_ajax_referer( 'srfm_notice_response', 'nonce', false ) ) { | |
| 1762 | - wp_send_json_error( [ 'message' => __( 'Invalid nonce.', 'sureforms' ) ], 403 ); | |
| 1763 | - } | |
| 1764 | - | |
| 1765 | - if ( ! Helper::current_user_can() ) { | |
| 1766 | - wp_send_json_error( [ 'message' => __( 'Unauthorized user.', 'sureforms' ) ], 403 ); | |
| 1767 | - } | |
| 1768 | - | |
| 1769 | - $notice_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : ''; | |
| 1770 | - $button = isset( $_POST['button'] ) ? sanitize_text_field( wp_unslash( $_POST['button'] ) ) : ''; | |
| 1771 | - | |
| 1772 | - $valid = [ | |
| 1773 | - 'srfm-getting-started-notice' => [ | |
| 1774 | - 'go_to_dashboard' => 'getting_started_notice_cta', | |
| 1775 | - 'maybe_later' => 'getting_started_notice_snooze', | |
| 1776 | - 'dismissed' => 'getting_started_notice_dismiss', | |
| 1777 | - ], | |
| 1778 | - 'srfm-plugin-review-notice' => [ | |
| 1779 | - 'rate_sureforms' => 'rating_notice_cta', | |
| 1780 | - 'maybe_later' => 'rating_notice_snooze', | |
| 1781 | - 'dismissed' => 'rating_notice_dismiss', | |
| 1782 | - ], | |
| 1783 | - ]; | |
| 1784 | - | |
| 1785 | - if ( ! isset( $valid[ $notice_id ][ $button ] ) ) { | |
| 1786 | - wp_send_json_error( [ 'message' => __( 'Invalid parameters.', 'sureforms' ) ], 400 ); | |
| 1787 | - } | |
| 1788 | - | |
| 1789 | - $event_name = $valid[ $notice_id ][ $button ]; | |
| 1790 | - Analytics::events()->track( $event_name, $button ); | |
| 1791 | - | |
| 1792 | - wp_send_json_success(); | |
| 1793 | - } | |
| 1794 | - | |
| 1795 | - /** | |
| 1796 | 1238 | * Disables the capabilities for WPForms to avoid conflicts when enqueueing |
| 1797 | 1239 | * scripts and styles for WPForms. |
| 1798 | 1240 | * |
| 1799 | 1241 | * This function is intended to prevent any potential conflicts that may arise |
| @@ -1937,11 +1379,8 @@ | ||
| 1937 | 1379 | if ( ! Helper::current_user_can() ) { |
| 1938 | 1380 | return; |
| 1939 | 1381 | } |
| 1940 | 1382 | |
| 1941 | - // Register the AI quick draft widget for capable users (the capability gate above applies); unlike the recent-entries widget below, it is not conditional on having entries. | |
| 1942 | - add_action( 'wp_dashboard_setup', [ $this, 'register_ai_dashboard_widget' ] ); | |
| 1943 | - | |
| 1944 | 1383 | // Quick check if there are any entries in the last 7 days. |
| 1945 | 1384 | $seven_days_ago = strtotime( '-7 days' ); |
| 1946 | 1385 | $total_entries = Entries::get_entries_count_after( $seven_days_ago ); |
| 1947 | 1386 | |
| @@ -1976,180 +1415,8 @@ | ||
| 1976 | 1415 | ); |
| 1977 | 1416 | } |
| 1978 | 1417 | |
| 1979 | 1418 | /** |
| 1980 | - * Register the AI quick draft dashboard widget. | |
| 1981 | - * | |
| 1982 | - * @return void | |
| 1983 | - * @since 2.12.1 | |
| 1984 | - */ | |
| 1985 | - public function register_ai_dashboard_widget() { | |
| 1986 | - wp_add_dashboard_widget( | |
| 1987 | - 'sureforms_ai_quick_draft', | |
| 1988 | - __( 'SureForms AI Quick Draft', 'sureforms' ), | |
| 1989 | - [ $this, 'render_ai_dashboard_widget' ], | |
| 1990 | - null, | |
| 1991 | - null, | |
| 1992 | - 'normal', | |
| 1993 | - 'high' | |
| 1994 | - ); | |
| 1995 | - } | |
| 1996 | - | |
| 1997 | - /** | |
| 1998 | - * Render AI quick draft dashboard widget content. | |
| 1999 | - * | |
| 2000 | - * @return void | |
| 2001 | - * @since 2.12.1 | |
| 2002 | - */ | |
| 2003 | - public function render_ai_dashboard_widget() { | |
| 2004 | - ?> | |
| 2005 | - <div class="srfm-ai-dashboard-widget"> | |
| 2006 | - <p> | |
| 2007 | - <?php esc_html_e( 'Describe the form and let SureForms AI generate it for you.', 'sureforms' ); ?> | |
| 2008 | - </p> | |
| 2009 | - <label for="srfm-ai-dashboard-prompt" class="screen-reader-text"> | |
| 2010 | - <?php esc_html_e( 'Describe your form', 'sureforms' ); ?> | |
| 2011 | - </label> | |
| 2012 | - <textarea | |
| 2013 | - id="srfm-ai-dashboard-prompt" | |
| 2014 | - class="widefat" | |
| 2015 | - rows="5" | |
| 2016 | - maxlength="2000" | |
| 2017 | - placeholder="<?php esc_attr_e( 'Example: Create a contact form with name, email, phone, and message fields.', 'sureforms' ); ?>" | |
| 2018 | - ></textarea> | |
| 2019 | - <p style="margin-top:10px;margin-bottom:0;display:flex;align-items:center;gap:10px;"> | |
| 2020 | - <button type="button" class="button button-primary" id="srfm-ai-dashboard-generate" disabled> | |
| 2021 | - <?php esc_html_e( 'Create New Form', 'sureforms' ); ?> | |
| 2022 | - </button> | |
| 2023 | - <span id="srfm-ai-dashboard-char-count" style="color:#646970;">0/2000</span> | |
| 2024 | - </p> | |
| 2025 | - </div> | |
| 2026 | - <?php | |
| 2027 | - } | |
| 2028 | - | |
| 2029 | - /** | |
| 2030 | - * Enqueue the AI quick draft dashboard widget script on the dashboard screen. | |
| 2031 | - * | |
| 2032 | - * The widget's behavior lives here (attached via wp_add_inline_script) rather than as an | |
| 2033 | - * inline <script> in the render callback, so it passes Plugin Check and keeps server values | |
| 2034 | - * out of the markup. Server values are passed through wp_localize_script. | |
| 2035 | - * | |
| 2036 | - * @param string $hook_suffix The current admin page hook suffix. | |
| 2037 | - * @return void | |
| 2038 | - * @since 2.12.1 | |
| 2039 | - */ | |
| 2040 | - public function enqueue_ai_dashboard_widget_assets( $hook_suffix ) { | |
| 2041 | - // Only on the main dashboard, and only for capable users (matches the widget gate). | |
| 2042 | - if ( 'index.php' !== $hook_suffix || ! Helper::current_user_can() ) { | |
| 2043 | - return; | |
| 2044 | - } | |
| 2045 | - | |
| 2046 | - // Register an inline-only handle (empty src) — the WordPress-core pattern for attaching | |
| 2047 | - // localized data plus an inline script without shipping a separate asset file. | |
| 2048 | - wp_register_script( 'srfm-ai-dashboard-widget', '', [], SRFM_VER, true ); | |
| 2049 | - wp_enqueue_script( 'srfm-ai-dashboard-widget' ); | |
| 2050 | - | |
| 2051 | - wp_localize_script( | |
| 2052 | - 'srfm-ai-dashboard-widget', | |
| 2053 | - 'srfmAiDashboardWidget', | |
| 2054 | - [ | |
| 2055 | - 'redirectUrl' => admin_url( 'admin.php?page=add-new-form' ), | |
| 2056 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 2057 | - 'nonce' => wp_create_nonce( 'srfm_ai_widget_usage' ), | |
| 2058 | - 'redirectingTxt' => __( 'Redirecting...', 'sureforms' ), | |
| 2059 | - ] | |
| 2060 | - ); | |
| 2061 | - | |
| 2062 | - $inline_script = <<<'JS' | |
| 2063 | -( function () { | |
| 2064 | - const config = window.srfmAiDashboardWidget || {}; | |
| 2065 | - const generateButton = document.getElementById( 'srfm-ai-dashboard-generate' ); | |
| 2066 | - const promptField = document.getElementById( 'srfm-ai-dashboard-prompt' ); | |
| 2067 | - const charCount = document.getElementById( 'srfm-ai-dashboard-char-count' ); | |
| 2068 | - if ( ! generateButton || ! promptField ) { | |
| 2069 | - return; | |
| 2070 | - } | |
| 2071 | - | |
| 2072 | - const updateWidgetState = function () { | |
| 2073 | - const promptValue = promptField.value.trim(); | |
| 2074 | - generateButton.disabled = ! promptValue; | |
| 2075 | - if ( charCount ) { | |
| 2076 | - charCount.textContent = `${ promptField.value.length }/2000`; | |
| 2077 | - } | |
| 2078 | - }; | |
| 2079 | - | |
| 2080 | - const triggerGeneration = function () { | |
| 2081 | - const prompt = promptField.value.trim(); | |
| 2082 | - if ( ! prompt ) { | |
| 2083 | - promptField.focus(); | |
| 2084 | - return; | |
| 2085 | - } | |
| 2086 | - | |
| 2087 | - generateButton.disabled = true; | |
| 2088 | - generateButton.textContent = config.redirectingTxt; | |
| 2089 | - | |
| 2090 | - const redirectUrl = new URL( config.redirectUrl, window.location.origin ); | |
| 2091 | - redirectUrl.searchParams.set( 'srfm_ai_dashboard_prompt', prompt ); | |
| 2092 | - | |
| 2093 | - const requestBody = new URLSearchParams(); | |
| 2094 | - requestBody.append( 'action', 'srfm_ai_widget_usage' ); | |
| 2095 | - requestBody.append( 'nonce', config.nonce ); | |
| 2096 | - | |
| 2097 | - fetch( config.ajaxUrl, { | |
| 2098 | - method: 'POST', | |
| 2099 | - credentials: 'same-origin', | |
| 2100 | - headers: { | |
| 2101 | - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | |
| 2102 | - }, | |
| 2103 | - body: requestBody.toString(), | |
| 2104 | - } ).finally( function () { | |
| 2105 | - window.location.href = redirectUrl.toString(); | |
| 2106 | - } ); | |
| 2107 | - }; | |
| 2108 | - | |
| 2109 | - promptField.addEventListener( 'input', updateWidgetState ); | |
| 2110 | - generateButton.addEventListener( 'click', triggerGeneration ); | |
| 2111 | - promptField.addEventListener( 'keydown', function ( event ) { | |
| 2112 | - if ( event.key === 'Enter' && ( event.metaKey || event.ctrlKey ) ) { | |
| 2113 | - event.preventDefault(); | |
| 2114 | - triggerGeneration(); | |
| 2115 | - } | |
| 2116 | - } ); | |
| 2117 | - | |
| 2118 | - updateWidgetState(); | |
| 2119 | -}() ); | |
| 2120 | -JS; | |
| 2121 | - | |
| 2122 | - wp_add_inline_script( 'srfm-ai-dashboard-widget', $inline_script ); | |
| 2123 | - } | |
| 2124 | - | |
| 2125 | - /** | |
| 2126 | - * Track AI dashboard widget usage. | |
| 2127 | - * | |
| 2128 | - * @return void | |
| 2129 | - * @since 2.12.1 | |
| 2130 | - */ | |
| 2131 | - public function track_ai_widget_usage() { | |
| 2132 | - if ( ! check_ajax_referer( 'srfm_ai_widget_usage', 'nonce', false ) ) { | |
| 2133 | - wp_send_json_error( [ 'message' => __( 'Invalid nonce.', 'sureforms' ) ], 403 ); | |
| 2134 | - } | |
| 2135 | - | |
| 2136 | - if ( ! Helper::current_user_can() ) { | |
| 2137 | - wp_send_json_error( [ 'message' => __( 'Unauthorized user.', 'sureforms' ) ], 403 ); | |
| 2138 | - } | |
| 2139 | - | |
| 2140 | - $current_count = (int) Helper::get_srfm_option( 'ai_dashboard_widget_uses', 0 ) + 1; | |
| 2141 | - Helper::update_srfm_option( 'ai_dashboard_widget_uses', $current_count ); | |
| 2142 | - | |
| 2143 | - // Emit an analytics event so usage lands in the warehouse via events_record. | |
| 2144 | - // $force = true because this is a cumulative counter, not a one-time event — | |
| 2145 | - // it must re-send the latest count each cycle (bypasses one-time dedup). | |
| 2146 | - Analytics::events()->track( 'ai_dashboard_widget_used', (string) $current_count, [], true ); | |
| 2147 | - | |
| 2148 | - wp_send_json_success(); | |
| 2149 | - } | |
| 2150 | - | |
| 2151 | - /** | |
| 2152 | 1419 | * Render the dashboard widget content. |
| 2153 | 1420 | * |
| 2154 | 1421 | * @return void |
| 2155 | 1422 | * @since 1.9.1 |
| @@ -2198,143 +1465,8 @@ | ||
| 2198 | 1465 | <?php |
| 2199 | 1466 | } |
| 2200 | 1467 | |
| 2201 | 1468 | /** |
| 2202 | - * Determine whether a notice callback is owned by SureForms. | |
| 2203 | - * | |
| 2204 | - * Recognises object methods on classes in the `SRFM` / `SRFM_PRO` namespaces | |
| 2205 | - * as well as the bundled notices libraries (`BSF_Admin_Notices` and the | |
| 2206 | - * legacy `Astra_Notices` alias). Everything else is treated as foreign. | |
| 2207 | - * | |
| 2208 | - * @param callable|array|string|null $function The registered callback function. | |
| 2209 | - * @since 2.10.0 | |
| 2210 | - * @return bool True when the callback belongs to SureForms, false otherwise. | |
| 2211 | - */ | |
| 2212 | - private function is_sureforms_owned_notice_callback( $function ) { | |
| 2213 | - $class_name = ''; | |
| 2214 | - | |
| 2215 | - if ( is_array( $function ) && isset( $function[0] ) ) { | |
| 2216 | - // Object or static method callback represented as an array. The first | |
| 2217 | - // element is either the object instance or the fully qualified class name. | |
| 2218 | - $class_name = is_object( $function[0] ) ? get_class( $function[0] ) : (string) $function[0]; | |
| 2219 | - } elseif ( is_string( $function ) && false !== strpos( $function, '::' ) ) { | |
| 2220 | - // Static method passed as "Class::method". | |
| 2221 | - $class_name = strstr( $function, '::', true ); | |
| 2222 | - } | |
| 2223 | - | |
| 2224 | - if ( '' === $class_name ) { | |
| 2225 | - // Plain function callbacks are never owned by SureForms. | |
| 2226 | - return false; | |
| 2227 | - } | |
| 2228 | - | |
| 2229 | - // SureForms (free and pro) namespaced classes. Pro's real namespace is | |
| 2230 | - // `SRFM_Pro\` (case-sensitive) — not the all-caps `SRFM_PRO_` constant | |
| 2231 | - // prefix — so match it case-insensitively to be safe. | |
| 2232 | - if ( 0 === strpos( $class_name, 'SRFM\\' ) || 0 === stripos( $class_name, 'SRFM_Pro\\' ) ) { | |
| 2233 | - return true; | |
| 2234 | - } | |
| 2235 | - | |
| 2236 | - // Bundled notices library shipped with SureForms. | |
| 2237 | - return in_array( $class_name, [ 'BSF_Admin_Notices', 'Astra_Notices' ], true ); | |
| 2238 | - } | |
| 2239 | - | |
| 2240 | - /** | |
| 2241 | - * Whether the current admin page is a SureForms-owned screen identified by a | |
| 2242 | - * `sureforms_*` / `srfm_*` `page` query slug. Complements | |
| 2243 | - * {@see Helper::is_sureforms_admin_page()} so foreign-notice suppression also | |
| 2244 | - * covers the payments / quiz / survey / learn / SMTP / partial-entries screens | |
| 2245 | - * that the core helper does not enumerate. Read-only screen check. | |
| 2246 | - * | |
| 2247 | - * @since 2.10.0 | |
| 2248 | - * @return bool | |
| 2249 | - */ | |
| 2250 | - private function is_sureforms_owned_admin_page() { | |
| 2251 | - if ( ! is_admin() || empty( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only screen detection, no state change. | |
| 2252 | - return false; | |
| 2253 | - } | |
| 2254 | - $page = sanitize_key( wp_unslash( $_GET['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only screen detection, no state change. | |
| 2255 | - return 0 === strpos( $page, 'sureforms' ) || 0 === strpos( $page, 'srfm' ); | |
| 2256 | - } | |
| 2257 | - | |
| 2258 | - /** | |
| 2259 | - * Build the shared HTML markup for admin notices. | |
| 2260 | - * | |
| 2261 | - * @since 2.5.2 | |
| 2262 | - * | |
| 2263 | - * All text parameters must be pre-escaped by the caller (e.g. via esc_html__()). | |
| 2264 | - * URL parameters must be pre-escaped via esc_url(). | |
| 2265 | - * | |
| 2266 | - * @param string $heading The notice heading text (pre-escaped). | |
| 2267 | - * @param string $message The notice body text (pre-escaped). | |
| 2268 | - * @param string $cta_url The primary CTA URL (pre-escaped). | |
| 2269 | - * @param string $cta_text The primary CTA button text (pre-escaped). | |
| 2270 | - * @param string $snooze_text The snooze button text (pre-escaped). | |
| 2271 | - * @param string $dismiss_text The dismiss button text (pre-escaped). | |
| 2272 | - * @param int $snooze_duration Snooze duration in seconds for the data-repeat-notice-after attribute. | |
| 2273 | - * @param bool $external_cta Whether the CTA opens in a new tab and also dismisses the notice | |
| 2274 | - * via the astra-notice-close class. Default false. | |
| 2275 | - * @return string The notice HTML markup. | |
| 2276 | - */ | |
| 2277 | - private function build_notice_markup( $heading, $message, $cta_url, $cta_text, $snooze_text, $dismiss_text, $snooze_duration, $external_cta = false ) { | |
| 2278 | - $image_path = esc_url( SRFM_URL . 'admin/assets/sureforms-logo.png' ); | |
| 2279 | - $cta_class = $external_cta ? 'astra-notice-close button-primary' : 'button-primary'; | |
| 2280 | - $cta_attrs = $external_cta ? ' target="_blank" rel="noopener noreferrer"' : ''; | |
| 2281 | - | |
| 2282 | - return sprintf( | |
| 2283 | - '<div class="notice-image"> | |
| 2284 | - <img src="%1$s" class="custom-logo" alt="SureForms" itemprop="logo"> | |
| 2285 | - </div> | |
| 2286 | - <div class="notice-content"> | |
| 2287 | - <div class="notice-heading"> | |
| 2288 | - %2$s | |
| 2289 | - </div> | |
| 2290 | - %3$s<br /> | |
| 2291 | - <div class="astra-review-notice-container"> | |
| 2292 | - <a href="%4$s" class="%5$s"%6$s> | |
| 2293 | - %7$s | |
| 2294 | - </a> | |
| 2295 | - <span class="dashicons dashicons-clock" aria-hidden="true"></span> | |
| 2296 | - <a href="#" data-repeat-notice-after="%8$s" class="astra-notice-close"> | |
| 2297 | - %9$s | |
| 2298 | - </a> | |
| 2299 | - <span class="dashicons dashicons-smiley" aria-hidden="true"></span> | |
| 2300 | - <a href="#" class="astra-notice-close"> | |
| 2301 | - %10$s | |
| 2302 | - </a> | |
| 2303 | - </div> | |
| 2304 | - </div>', | |
| 2305 | - $image_path, | |
| 2306 | - $heading, | |
| 2307 | - $message, | |
| 2308 | - $cta_url, | |
| 2309 | - esc_attr( $cta_class ), | |
| 2310 | - $cta_attrs, | |
| 2311 | - $cta_text, | |
| 2312 | - $snooze_duration, | |
| 2313 | - $snooze_text, | |
| 2314 | - $dismiss_text | |
| 2315 | - ); | |
| 2316 | - } | |
| 2317 | - | |
| 2318 | - /** | |
| 2319 | - * Callback for displaying the rating notice conditionally. | |
| 2320 | - * | |
| 2321 | - * Returns true if the user has 3 or more published forms or 3 or more form entries. | |
| 2322 | - * | |
| 2323 | - * @since 2.5.2 | |
| 2324 | - * @return bool | |
| 2325 | - */ | |
| 2326 | - private function maybe_display_rating_notice() { | |
| 2327 | - if ( null === $this->should_show_rating ) { | |
| 2328 | - $entries_count = Entries::get_total_entries_by_status( 'all' ); | |
| 2329 | - $form_count = wp_count_posts( SRFM_FORMS_POST_TYPE ); | |
| 2330 | - $this->should_show_rating = $entries_count >= self::RATING_NOTICE_THRESHOLD || Helper::get_integer_value( $form_count->publish ?? 0 ) >= self::RATING_NOTICE_THRESHOLD; | |
| 2331 | - } | |
| 2332 | - | |
| 2333 | - return $this->should_show_rating; | |
| 2334 | - } | |
| 2335 | - | |
| 2336 | - /** | |
| 2337 | 1469 | * Get random premium feature text. |
| 2338 | 1470 | * |
| 2339 | 1471 | * @return string Random feature text. |
| 2340 | 1472 | * @since 1.9.1 |
| @@ -2396,9 +1528,14 @@ | ||
| 2396 | 1528 | </svg> |
| 2397 | 1529 | <span><?php echo esc_html( $this->get_random_premium_feature_text() ); ?></span> |
| 2398 | 1530 | </div> |
| 2399 | 1531 | <?php |
| 2400 | - $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 | + ); | |
| 2401 | 1538 | ?> |
| 2402 | 1539 | <a href="<?php echo esc_url( $upgrade_url ); ?>" class="srfm-upgrade-link" target="_blank"> |
| 2403 | 1540 | <?php esc_html_e( 'Upgrade', 'sureforms' ); ?> |
| 2404 | 1541 | </a> |