| @@ -6,24 +6,20 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace SRFM\Admin; |
| 9 | 9 | |
| 10 | -use Astra_Notices; | |
| 10 | +use SRFM\Admin\Views\Entries_List_Table; | |
| 11 | +use SRFM\Admin\Views\Single_Entry; | |
| 11 | 12 | use SRFM\Inc\AI_Form_Builder\AI_Helper; |
| 12 | 13 | use SRFM\Inc\Database\Tables\Entries; |
| 13 | 14 | use SRFM\Inc\Helper; |
| 14 | 15 | use SRFM\Inc\Onboarding; |
| 15 | -use SRFM\Inc\Payments\Payment_Helper; | |
| 16 | -use SRFM\Inc\Payments\Stripe\Stripe_Helper; | |
| 16 | +use SRFM\Inc\Post_Types; | |
| 17 | 17 | use SRFM\Inc\Traits\Get_Instance; |
| 18 | 18 | |
| 19 | 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | 20 | exit; // Exit if accessed directly. |
| 21 | 21 | } |
| 22 | - | |
| 23 | -if ( ! class_exists( 'Astra_Notices' ) ) { | |
| 24 | - require_once SRFM_DIR . 'inc/lib/astra-notices/class-astra-notices.php'; | |
| 25 | -} | |
| 26 | 22 | /** |
| 27 | 23 | * Admin handler class. |
| 28 | 24 | * |
| 29 | 25 | * @since 0.0.1 |
| @@ -31,15 +27,8 @@ | ||
| 31 | 27 | class Admin { |
| 32 | 28 | use Get_Instance; |
| 33 | 29 | |
| 34 | 30 | /** |
| 35 | - * Minimum number of forms or entries required to show the rating notice. | |
| 36 | - * | |
| 37 | - * @since 2.5.2 | |
| 38 | - */ | |
| 39 | - public const RATING_NOTICE_THRESHOLD = 3; | |
| 40 | - | |
| 41 | - /** | |
| 42 | 31 | * Dashboard widget entries data. |
| 43 | 32 | * |
| 44 | 33 | * @var array |
| 45 | 34 | * @since 1.9.1 |
| @@ -46,16 +35,8 @@ | ||
| 46 | 35 | */ |
| 47 | 36 | private $dashboard_widget_data = []; |
| 48 | 37 | |
| 49 | 38 | /** |
| 50 | - * Cached result for whether the rating notice should display. | |
| 51 | - * | |
| 52 | - * @var bool|null | |
| 53 | - * @since 2.5.2 | |
| 54 | - */ | |
| 55 | - private $should_show_rating = null; | |
| 56 | - | |
| 57 | - /** | |
| 58 | 39 | * SureForms Page Default permission. |
| 59 | 40 | * |
| 60 | 41 | * @var string |
| 61 | 42 | * @since 1.12.2 |
| @@ -71,14 +52,11 @@ | ||
| 71 | 52 | public function __construct() { |
| 72 | 53 | add_action( 'admin_menu', [ $this, 'add_menu_page' ], 9 ); |
| 73 | 54 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 74 | 55 | add_action( 'admin_menu', [ $this, 'settings_page' ] ); |
| 75 | - add_action( 'admin_menu', [ $this, 'add_learn_page' ] ); | |
| 76 | 56 | add_action( 'admin_menu', [ $this, 'add_new_form' ] ); |
| 77 | 57 | add_action( 'admin_menu', [ $this, 'add_suremail_page' ] ); |
| 78 | - if ( ! Helper::has_pro() ) { | |
| 79 | - add_action( 'admin_menu', [ $this, 'add_quiz_page' ] ); | |
| 80 | - add_action( 'admin_menu', [ $this, 'add_survey_reports_page' ] ); | |
| 58 | + if ( ! Helper::has_pro() && self::is_first_form_created() ) { | |
| 81 | 59 | add_action( 'admin_menu', [ $this, 'add_upgrade_to_pro' ] ); |
| 82 | 60 | add_action( 'admin_footer', [ $this, 'add_upgrade_to_pro_target_attr' ] ); |
| 83 | 61 | } |
| 84 | 62 | |
| @@ -90,13 +68,23 @@ | ||
| 90 | 68 | // this action is used to restrict Spectra's quick action bar on SureForms CPTS. |
| 91 | 69 | add_action( 'uag_enable_quick_action_sidebar', [ $this, 'restrict_spectra_quick_action_bar' ] ); |
| 92 | 70 | |
| 93 | 71 | add_action( 'current_screen', [ $this, 'enable_gutenberg_for_sureforms' ], 100 ); |
| 94 | - // Register notices early for React pages (before admin_enqueue_scripts). | |
| 95 | - add_action( 'admin_init', [ $this, 'register_pro_compatibility_notices' ], 5 ); | |
| 96 | - // Display notices on traditional WordPress admin pages. | |
| 97 | 72 | add_action( 'admin_notices', [ $this, 'srfm_pro_version_compatibility' ] ); |
| 98 | 73 | |
| 74 | + // Handle entry actions. | |
| 75 | + add_action( 'admin_init', [ $this, 'handle_entry_actions' ] ); | |
| 76 | + add_action( 'admin_notices', [ Entries_List_Table::class, 'display_bulk_action_notice' ] ); | |
| 77 | + | |
| 78 | + // This action enqueues translations for NPS Survey library. | |
| 79 | + // A better solution will be required from library to resolve plugin conflict. | |
| 80 | + add_action( | |
| 81 | + 'admin_footer', | |
| 82 | + static function() { | |
| 83 | + Helper::register_script_translations( 'nps-survey-script' ); | |
| 84 | + }, | |
| 85 | + 1000 | |
| 86 | + ); | |
| 99 | 87 | // Enfold theme compatibility to enable block editor for SureForms post type. |
| 100 | 88 | add_filter( 'avf_use_block_editor_for_post', [ $this, 'enable_block_editor_in_enfold_theme' ] ); |
| 101 | 89 | |
| 102 | 90 | // Add action links to the plugin page. |
| @@ -107,9 +95,8 @@ | ||
| 107 | 95 | |
| 108 | 96 | if ( $admin_notification_on ) { |
| 109 | 97 | add_action( 'admin_menu', [ $this, 'maybe_add_entries_badge' ], 99 ); |
| 110 | 98 | } |
| 111 | - | |
| 112 | 99 | add_filter( 'wpforms_current_user_can', [ $this, 'disable_wpforms_capabilities' ], 10, 3 ); |
| 113 | 100 | |
| 114 | 101 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_pointer' ] ); |
| 115 | 102 | // Ajax callbacks for wp-pointer functionality. |
| @@ -115,9 +102,8 @@ | ||
| 115 | 102 | // Ajax callbacks for wp-pointer functionality. |
| 116 | 103 | add_action( 'wp_ajax_should_show_pointer', [ $this, 'pointer_should_show' ] ); |
| 117 | 104 | add_action( 'wp_ajax_sureforms_dismiss_pointer', [ $this, 'pointer_dismissed' ] ); |
| 118 | 105 | add_action( 'wp_ajax_sureforms_accept_cta', [ $this, 'pointer_accepted_cta' ] ); |
| 119 | - add_action( 'wp_ajax_srfm_notice_response', [ $this, 'handle_notice_response' ] ); | |
| 120 | 106 | |
| 121 | 107 | // Register dashboard widget only if there are recent entries. |
| 122 | 108 | add_action( 'admin_init', [ $this, 'maybe_register_dashboard_widget' ] ); |
| 123 | 109 | |
| @@ -122,10 +108,8 @@ | ||
| 122 | 108 | add_action( 'admin_init', [ $this, 'maybe_register_dashboard_widget' ] ); |
| 123 | 109 | |
| 124 | 110 | // Save first form creation time stamp. |
| 125 | 111 | add_action( 'admin_init', [ $this, 'save_first_form_creation_time_stamp' ] ); |
| 126 | - add_action( 'admin_notices', [ $this, 'display_srfm_rating_notice' ] ); | |
| 127 | - add_action( 'admin_notices', [ $this, 'display_srfm_getting_started_notice' ] ); | |
| 128 | 112 | } |
| 129 | 113 | |
| 130 | 114 | /** |
| 131 | 115 | * Get the first form creation time stamp. |
| @@ -370,8 +354,14 @@ | ||
| 370 | 354 | * @return void |
| 371 | 355 | * @since 1.6.1 |
| 372 | 356 | */ |
| 373 | 357 | public function add_upgrade_to_pro_target_attr() { |
| 358 | + | |
| 359 | + // only add if first form was created more than 8 days ago. | |
| 360 | + if ( ! self::check_first_form_creation_threshold( 8 ) ) { | |
| 361 | + return; | |
| 362 | + } | |
| 363 | + | |
| 374 | 364 | ?> |
| 375 | 365 | <script type="text/javascript"> |
| 376 | 366 | document.addEventListener('DOMContentLoaded', function () { |
| 377 | 367 | // Upgrade link handler. |
| @@ -394,8 +384,14 @@ | ||
| 394 | 384 | * @return void |
| 395 | 385 | * @since 1.6.1 |
| 396 | 386 | */ |
| 397 | 387 | public function add_upgrade_to_pro() { |
| 388 | + | |
| 389 | + // only add if first form was created more than 8 days ago. | |
| 390 | + if ( ! self::check_first_form_creation_threshold( 8 ) ) { | |
| 391 | + return; | |
| 392 | + } | |
| 393 | + | |
| 398 | 394 | // The url used here is used as a selector for css to style the upgrade to pro submenu. |
| 399 | 395 | // If you are changing this url, please make sure to update the css as well. |
| 400 | 396 | $upgrade_url = add_query_arg( |
| 401 | 397 | [ |
| @@ -413,74 +409,8 @@ | ||
| 413 | 409 | ); |
| 414 | 410 | } |
| 415 | 411 | |
| 416 | 412 | /** |
| 417 | - * Add Quiz empty state submenu page for free users. | |
| 418 | - * | |
| 419 | - * @return void | |
| 420 | - * @since 2.7.0 | |
| 421 | - */ | |
| 422 | - public function add_quiz_page() { | |
| 423 | - add_submenu_page( | |
| 424 | - 'sureforms_menu', | |
| 425 | - __( 'Quiz Entries', 'sureforms' ), | |
| 426 | - __( 'Quizzes', 'sureforms' ) . | |
| 427 | - ' <span style="color:#4ADE80;font-size:9px;font-weight:600;">' . | |
| 428 | - esc_html__( 'New', 'sureforms' ) . | |
| 429 | - '</span>', | |
| 430 | - self::$sureforms_page_default_capability, | |
| 431 | - 'sureforms_quiz_entries', | |
| 432 | - [ $this, 'render_quiz_empty_state' ], | |
| 433 | - 5 | |
| 434 | - ); | |
| 435 | - } | |
| 436 | - | |
| 437 | - /** | |
| 438 | - * Quiz empty state page callback. | |
| 439 | - * | |
| 440 | - * @return void | |
| 441 | - * @since 2.7.0 | |
| 442 | - */ | |
| 443 | - public function render_quiz_empty_state() { | |
| 444 | - ?> | |
| 445 | - <div id="srfm-quiz-entries-root" class="srfm-admin-wrapper"></div> | |
| 446 | - <?php | |
| 447 | - } | |
| 448 | - | |
| 449 | - /** | |
| 450 | - * Add Survey Reports promotional submenu page for free users. | |
| 451 | - * | |
| 452 | - * @return void | |
| 453 | - * @since 2.8.0 | |
| 454 | - */ | |
| 455 | - public function add_survey_reports_page() { | |
| 456 | - add_submenu_page( | |
| 457 | - 'sureforms_menu', | |
| 458 | - __( 'Survey Reports', 'sureforms' ), | |
| 459 | - __( 'Survey Reports', 'sureforms' ) . | |
| 460 | - ' <span style="color:#4ADE80;font-size:9px;font-weight:600;">' . | |
| 461 | - esc_html__( 'New', 'sureforms' ) . | |
| 462 | - '</span>', | |
| 463 | - self::$sureforms_page_default_capability, | |
| 464 | - 'sureforms_survey_reports', | |
| 465 | - [ $this, 'render_survey_empty_state' ], | |
| 466 | - 6 | |
| 467 | - ); | |
| 468 | - } | |
| 469 | - | |
| 470 | - /** | |
| 471 | - * Survey empty state page callback. | |
| 472 | - * | |
| 473 | - * @return void | |
| 474 | - * @since 2.8.0 | |
| 475 | - */ | |
| 476 | - public function render_survey_empty_state() { | |
| 477 | - ?> | |
| 478 | - <div id="srfm-survey-empty-state-root" class="srfm-admin-wrapper"></div> | |
| 479 | - <?php | |
| 480 | - } | |
| 481 | - | |
| 482 | - /** | |
| 483 | 413 | * Add SMTP promotional submenu page. |
| 484 | 414 | * |
| 485 | 415 | * @return void |
| 486 | 416 | * @since 1.7.1 |
| @@ -542,37 +472,8 @@ | ||
| 542 | 472 | <?php |
| 543 | 473 | } |
| 544 | 474 | |
| 545 | 475 | /** |
| 546 | - * Add Learn submenu page. | |
| 547 | - * | |
| 548 | - * @return void | |
| 549 | - * @since 2.5.2 | |
| 550 | - */ | |
| 551 | - public function add_learn_page() { | |
| 552 | - add_submenu_page( | |
| 553 | - 'sureforms_menu', | |
| 554 | - __( 'Learn', 'sureforms' ), | |
| 555 | - __( 'Learn', 'sureforms' ), | |
| 556 | - self::$sureforms_page_default_capability, | |
| 557 | - 'sureforms_learn', | |
| 558 | - [ $this, 'render_learn' ] | |
| 559 | - ); | |
| 560 | - } | |
| 561 | - | |
| 562 | - /** | |
| 563 | - * Learn page callback. | |
| 564 | - * | |
| 565 | - * @return void | |
| 566 | - * @since 2.5.2 | |
| 567 | - */ | |
| 568 | - public function render_learn() { | |
| 569 | - ?> | |
| 570 | - <div id="srfm-learn-root" class="srfm-admin-wrapper"></div> | |
| 571 | - <?php | |
| 572 | - } | |
| 573 | - | |
| 574 | - /** | |
| 575 | 476 | * Add new form menu item. |
| 576 | 477 | * |
| 577 | 478 | * @return void |
| 578 | 479 | * @since 0.0.1 |
| @@ -579,17 +480,8 @@ | ||
| 579 | 480 | */ |
| 580 | 481 | public function add_new_form() { |
| 581 | 482 | add_submenu_page( |
| 582 | 483 | 'sureforms_menu', |
| 583 | - __( 'Forms', 'sureforms' ), | |
| 584 | - __( 'Forms', 'sureforms' ), | |
| 585 | - self::$sureforms_page_default_capability, | |
| 586 | - 'sureforms_forms', | |
| 587 | - [ $this, 'render_forms' ], | |
| 588 | - 1 | |
| 589 | - ); | |
| 590 | - add_submenu_page( | |
| 591 | - 'sureforms_menu', | |
| 592 | 484 | __( 'New Form', 'sureforms' ), |
| 593 | 485 | __( 'New Form', 'sureforms' ), |
| 594 | 486 | self::$sureforms_page_default_capability, |
| 595 | 487 | 'add-new-form', |
| @@ -605,18 +497,8 @@ | ||
| 605 | 497 | [ $this, 'render_entries' ], |
| 606 | 498 | 3 |
| 607 | 499 | ); |
| 608 | 500 | |
| 609 | - add_submenu_page( | |
| 610 | - 'sureforms_menu', | |
| 611 | - __( 'Payments', 'sureforms' ), | |
| 612 | - __( 'Payments', 'sureforms' ), | |
| 613 | - self::$sureforms_page_default_capability, | |
| 614 | - SRFM_PAYMENTS, | |
| 615 | - [ $this, 'render_payments' ], | |
| 616 | - 4 | |
| 617 | - ); | |
| 618 | - | |
| 619 | 501 | if ( $entries_hook ) { |
| 620 | 502 | add_action( 'load-' . $entries_hook, [ $this, 'mark_entries_page_visit' ] ); |
| 621 | 503 | } |
| 622 | 504 | } |
| @@ -621,20 +503,8 @@ | ||
| 621 | 503 | } |
| 622 | 504 | } |
| 623 | 505 | |
| 624 | 506 | /** |
| 625 | - * Payments page callback. | |
| 626 | - * | |
| 627 | - * @return void | |
| 628 | - * @since 2.0.0 | |
| 629 | - */ | |
| 630 | - public function render_payments() { | |
| 631 | - ?> | |
| 632 | - <div id="srfm-payments-react-container" class="srfm-admin-wrapper"></div> | |
| 633 | - <?php | |
| 634 | - } | |
| 635 | - | |
| 636 | - /** | |
| 637 | 507 | * Add new form mentu item callback. |
| 638 | 508 | * |
| 639 | 509 | * @return void |
| 640 | 510 | * @since 0.0.1 |
| @@ -645,28 +515,42 @@ | ||
| 645 | 515 | <?php |
| 646 | 516 | } |
| 647 | 517 | |
| 648 | 518 | /** |
| 649 | - * Forms page callback. | |
| 650 | - * | |
| 651 | - * @return void | |
| 652 | - * @since 2.0.0 | |
| 653 | - */ | |
| 654 | - public function render_forms() { | |
| 655 | - ?> | |
| 656 | - <div id="srfm-forms-root" class="srfm-admin-wrapper"></div> | |
| 657 | - <?php | |
| 658 | - } | |
| 659 | - | |
| 660 | - /** | |
| 661 | 519 | * Entries page callback. |
| 662 | 520 | * |
| 663 | 521 | * @since 0.0.13 |
| 664 | - * @since 2.0.0 - Updated the entries UI and the function definition. | |
| 665 | 522 | * @return void |
| 666 | 523 | */ |
| 667 | 524 | public function render_entries() { |
| 668 | - echo '<div id="srfm-entries-root"></div>'; | |
| 525 | + // Render single entry view. | |
| 526 | + // Adding the phpcs ignore nonce verification as no database operations are performed in this function, it is used to display the single entry view. | |
| 527 | + if ( isset( $_GET['entry_id'] ) && is_numeric( $_GET['entry_id'] ) && isset( $_GET['view'] ) && 'details' === $_GET['view'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not needed here and explained in the comments above as well. | |
| 528 | + $single_entry_view = new Single_Entry(); | |
| 529 | + $single_entry_view->render(); | |
| 530 | + return; | |
| 531 | + } | |
| 532 | + | |
| 533 | + // Render all entries view. | |
| 534 | + $entries_table = new Entries_List_Table(); | |
| 535 | + $entries_table->prepare_items(); | |
| 536 | + ?> | |
| 537 | + <div class="wrap"> | |
| 538 | + <h1 class="wp-heading-inline"><?php echo esc_html__( 'Entries', 'sureforms' ); ?></h1> | |
| 539 | + <?php | |
| 540 | + if ( empty( $entries_table->all_entries_count ) && empty( $entries_table->trash_entries_count ) ) { | |
| 541 | + $instance = Post_Types::get_instance(); | |
| 542 | + $instance->sureforms_render_blank_state( SRFM_ENTRIES ); | |
| 543 | + $instance->get_blank_state_styles(); | |
| 544 | + return; | |
| 545 | + } | |
| 546 | + ?> | |
| 547 | + <form method="get"> | |
| 548 | + <input type="hidden" name="page" value="sureforms_entries"> | |
| 549 | + <?php $entries_table->display(); ?> | |
| 550 | + </form> | |
| 551 | + </div> | |
| 552 | + <?php | |
| 669 | 553 | } |
| 670 | 554 | |
| 671 | 555 | /** |
| 672 | 556 | * Add notification badge to SureForms menu when there are new entries. |
| @@ -874,8 +758,9 @@ | ||
| 874 | 758 | global $wp_version; |
| 875 | 759 | |
| 876 | 760 | $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min'; |
| 877 | 761 | $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; |
| 762 | + $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/'; | |
| 878 | 763 | $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/'; |
| 879 | 764 | $is_rtl = is_rtl(); |
| 880 | 765 | $rtl = $is_rtl ? '-rtl' : ''; |
| 881 | 766 | |
| @@ -883,78 +768,44 @@ | ||
| 883 | 768 | * List of the handles in which we need to add translation compatibility. |
| 884 | 769 | */ |
| 885 | 770 | $script_translations_handlers = []; |
| 886 | 771 | $onboarding_instance = Onboarding::get_instance(); |
| 887 | - $current_user = wp_get_current_user(); | |
| 888 | 772 | |
| 889 | 773 | $localization_data = [ |
| 890 | - 'site_url' => get_site_url(), | |
| 891 | - 'current_user_login' => $current_user->user_login ?? '', | |
| 892 | - 'website_lead_details' => [ | |
| 893 | - 'first_name' => $current_user->first_name ?? '', | |
| 894 | - 'last_name' => $current_user->last_name ?? '', | |
| 895 | - 'email' => $current_user->user_email ?? '', | |
| 896 | - ], | |
| 897 | - 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(), | |
| 898 | - 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ), | |
| 899 | - 'plugin_version' => SRFM_VER, | |
| 900 | - 'global_settings_nonce' => Helper::current_user_can() ? wp_create_nonce( 'wp_rest' ) : '', | |
| 901 | - 'is_pro_active' => Helper::has_pro(), | |
| 902 | - 'is_first_form_created' => self::is_first_form_created(), | |
| 903 | - 'check_three_days_threshold' => self::check_first_form_creation_threshold(), | |
| 904 | - 'check_eight_days_threshold' => self::check_first_form_creation_threshold( 8 ), | |
| 905 | - 'pro_plugin_version' => Helper::has_pro() ? SRFM_PRO_VER : '', | |
| 906 | - 'pro_plugin_name' => Helper::has_pro() && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro', | |
| 907 | - 'sureforms_pricing_page' => Helper::get_sureforms_website_url( 'pricing' ), | |
| 908 | - 'field_spacing_vars' => Helper::get_css_vars(), | |
| 909 | - 'is_ver_lower_than_6_7' => version_compare( $wp_version, '6.6.2', '<=' ), | |
| 910 | - 'integrations' => Helper::sureforms_get_integration(), | |
| 911 | - 'rotating_plugin_banner' => Helper::get_rotating_plugin_banner(), | |
| 912 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 913 | - 'sf_plugin_manager_nonce' => wp_create_nonce( 'sf_plugin_manager_nonce' ), | |
| 914 | - 'plugin_installer_nonce' => wp_create_nonce( 'updates' ), | |
| 915 | - 'plugin_activating_text' => __( 'Activating...', 'sureforms' ), | |
| 916 | - 'plugin_activated_text' => __( 'Activated', 'sureforms' ), | |
| 917 | - 'plugin_activate_text' => __( 'Activate', 'sureforms' ), | |
| 918 | - 'plugin_installing_text' => __( 'Installing...', 'sureforms' ), | |
| 919 | - 'plugin_installed_text' => __( 'Installed', 'sureforms' ), | |
| 920 | - 'privacy_policy_url' => Helper::get_sureforms_website_url( 'privacy-policy/' ), | |
| 921 | - 'is_rtl' => $is_rtl, | |
| 922 | - 'onboarding_completed' => method_exists( $onboarding_instance, 'get_onboarding_status' ) ? $onboarding_instance->get_onboarding_status() : false, | |
| 923 | - 'onboarding_redirect' => isset( $_GET['srfm-activation-redirect'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required for the activation redirection. | |
| 924 | - 'pointer_nonce' => wp_create_nonce( 'sureforms_pointer_action' ), | |
| 925 | - 'general_settings_url' => admin_url( '/options-general.php' ), | |
| 926 | - 'additional_header_nav_items' => [], | |
| 927 | - 'payments' => apply_filters( | |
| 928 | - 'srfm_admin_localize_payments_data', | |
| 929 | - [ | |
| 930 | - 'stripe_connected' => Stripe_Helper::is_stripe_connected(), | |
| 931 | - 'stripe_mode' => Stripe_Helper::get_stripe_mode(), | |
| 932 | - 'stripe_connect_url' => Stripe_Helper::get_stripe_settings_url(), | |
| 933 | - 'currencies_data' => Payment_Helper::get_all_currencies_data(), | |
| 934 | - 'zero_decimal_currencies' => Payment_Helper::get_zero_decimal_currencies(), | |
| 935 | - 'webhook_url' => Stripe_Helper::get_webhook_url(), | |
| 936 | - 'webhook_test_connected' => Stripe_Helper::is_webhook_configured( 'test', true ), | |
| 937 | - 'webhook_live_connected' => Stripe_Helper::is_webhook_configured( 'live', true ), | |
| 938 | - 'is_transaction_present' => Stripe_Helper::is_transaction_present(), | |
| 939 | - 'payment_currency' => Payment_Helper::get_currency(), | |
| 940 | - 'currency_sign_position' => Payment_Helper::get_currency_sign_position(), | |
| 941 | - ] | |
| 942 | - ), | |
| 943 | - 'mcp_adapter_status' => file_exists( WP_PLUGIN_DIR . '/mcp-adapter/mcp-adapter.php' ) | |
| 944 | - ? ( is_plugin_active( 'mcp-adapter/mcp-adapter.php' ) ? 'active' : 'installed' ) | |
| 945 | - : 'not_installed', | |
| 774 | + 'site_url' => get_site_url(), | |
| 775 | + 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(), | |
| 776 | + 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ), | |
| 777 | + 'plugin_version' => SRFM_VER, | |
| 778 | + 'global_settings_nonce' => Helper::current_user_can() ? wp_create_nonce( 'wp_rest' ) : '', | |
| 779 | + 'is_pro_active' => Helper::has_pro(), | |
| 780 | + 'is_first_form_created' => self::is_first_form_created(), | |
| 781 | + 'check_three_days_threshold' => self::check_first_form_creation_threshold(), | |
| 782 | + 'check_eight_days_threshold' => self::check_first_form_creation_threshold( 8 ), | |
| 783 | + 'pro_plugin_version' => Helper::has_pro() ? SRFM_PRO_VER : '', | |
| 784 | + 'pro_plugin_name' => Helper::has_pro() && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro', | |
| 785 | + 'sureforms_pricing_page' => Helper::get_sureforms_website_url( 'pricing' ), | |
| 786 | + 'field_spacing_vars' => Helper::get_css_vars(), | |
| 787 | + 'is_ver_lower_than_6_7' => version_compare( $wp_version, '6.6.2', '<=' ), | |
| 788 | + 'integrations' => Helper::sureforms_get_integration(), | |
| 789 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 790 | + 'sf_plugin_manager_nonce' => wp_create_nonce( 'sf_plugin_manager_nonce' ), | |
| 791 | + 'plugin_installer_nonce' => wp_create_nonce( 'updates' ), | |
| 792 | + 'plugin_activating_text' => __( 'Activating...', 'sureforms' ), | |
| 793 | + 'plugin_activated_text' => __( 'Activated', 'sureforms' ), | |
| 794 | + 'plugin_activate_text' => __( 'Activate', 'sureforms' ), | |
| 795 | + 'plugin_installing_text' => __( 'Installing...', 'sureforms' ), | |
| 796 | + 'plugin_installed_text' => __( 'Installed', 'sureforms' ), | |
| 797 | + 'is_rtl' => $is_rtl, | |
| 798 | + 'onboarding_completed' => method_exists( $onboarding_instance, 'get_onboarding_status' ) ? $onboarding_instance->get_onboarding_status() : false, | |
| 799 | + 'onboarding_redirect' => isset( $_GET['srfm-activation-redirect'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is not required for the activation redirection. | |
| 800 | + 'pointer_nonce' => wp_create_nonce( 'sureforms_pointer_action' ), | |
| 801 | + 'general_settings_url' => admin_url( '/options-general.php' ), | |
| 946 | 802 | ]; |
| 947 | 803 | |
| 948 | 804 | $is_screen_sureforms_menu = Helper::validate_request_context( 'sureforms_menu', 'page' ); |
| 949 | 805 | $is_screen_add_new_form = Helper::validate_request_context( 'add-new-form', 'page' ); |
| 950 | - $is_screen_sureforms_forms = Helper::validate_request_context( 'sureforms_forms', 'page' ); | |
| 951 | 806 | $is_screen_sureforms_form_settings = Helper::validate_request_context( 'sureforms_form_settings', 'page' ); |
| 952 | - $is_screen_sureforms_payments = Helper::validate_request_context( 'sureforms_payments', 'page' ); | |
| 953 | 807 | $is_screen_sureforms_entries = Helper::validate_request_context( SRFM_ENTRIES, 'page' ); |
| 954 | - $is_screen_sureforms_learn = Helper::validate_request_context( 'sureforms_learn', 'page' ); | |
| 955 | - $is_screen_quiz_empty_state = Helper::validate_request_context( 'sureforms_quiz_entries', 'page' ); | |
| 956 | - $is_screen_survey_empty_state = Helper::validate_request_context( 'sureforms_survey_reports', 'page' ); | |
| 957 | 808 | $is_post_type_sureforms_form = SRFM_FORMS_POST_TYPE === $current_screen->post_type; |
| 958 | 809 | |
| 959 | 810 | /** |
| 960 | 811 | * Check if the current screen is the SureForms Menu and AI Auth Email is present then we will add user type as registered. |
| @@ -966,34 +817,9 @@ | ||
| 966 | 817 | 'type' => ! empty( get_option( 'srfm_ai_auth_user_email' ) ) ? 'registered' : 'non-registered', |
| 967 | 818 | ]; |
| 968 | 819 | } |
| 969 | 820 | |
| 970 | - // Add the Quizzes and Survey Reports nav items when pro is not active. | |
| 971 | - if ( ! Helper::has_pro() ) { | |
| 972 | - $localization_data['additional_header_nav_items'][] = [ | |
| 973 | - 'slug' => 'sureforms_quiz_entries', | |
| 974 | - 'text' => __( 'Quizzes', 'sureforms' ), | |
| 975 | - 'link' => admin_url( 'admin.php?page=sureforms_quiz_entries' ), | |
| 976 | - ]; | |
| 977 | - $localization_data['additional_header_nav_items'][] = [ | |
| 978 | - 'slug' => 'sureforms_survey_reports', | |
| 979 | - 'text' => __( 'Survey Reports', 'sureforms' ), | |
| 980 | - 'link' => admin_url( 'admin.php?page=sureforms_survey_reports' ), | |
| 981 | - ]; | |
| 982 | - } | |
| 983 | - | |
| 984 | - $is_sureforms_screen = $is_screen_sureforms_menu || $is_post_type_sureforms_form || $is_screen_add_new_form || $is_screen_sureforms_forms || $is_screen_sureforms_form_settings || $is_screen_sureforms_entries || $is_screen_sureforms_payments || $is_screen_sureforms_learn || $is_screen_quiz_empty_state || $is_screen_survey_empty_state; | |
| 985 | - | |
| 986 | - /** | |
| 987 | - * Filter to allow extending the SureForms dashboard screen check. | |
| 988 | - * | |
| 989 | - * @since 2.6.0 | |
| 990 | - * | |
| 991 | - * @param bool $is_sureforms_screen Whether the current screen is a SureForms dashboard screen. | |
| 992 | - */ | |
| 993 | - $is_sureforms_screen = apply_filters( 'srfm_is_dashboard_screen', $is_sureforms_screen ); | |
| 994 | - | |
| 995 | - if ( $is_sureforms_screen ) { | |
| 821 | + if ( $is_screen_sureforms_menu || $is_post_type_sureforms_form || $is_screen_add_new_form || $is_screen_sureforms_form_settings || $is_screen_sureforms_entries ) { | |
| 996 | 822 | $asset_handle = '-dashboard'; |
| 997 | 823 | |
| 998 | 824 | wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER ); |
| 999 | 825 | |
| @@ -1021,9 +847,9 @@ | ||
| 1021 | 847 | update_option( 'srfm_pro_license_status', $current_license_status ); |
| 1022 | 848 | } |
| 1023 | 849 | } |
| 1024 | 850 | |
| 1025 | - $localization_data['security_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings&subpage=recaptcha' ); | |
| 851 | + $localization_data['security_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' ); | |
| 1026 | 852 | $localization_data['integration_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=integration-settings' ); |
| 1027 | 853 | wp_localize_script( |
| 1028 | 854 | SRFM_SLUG . $asset_handle, |
| 1029 | 855 | SRFM_SLUG . '_admin', |
| @@ -1032,11 +858,12 @@ | ||
| 1032 | 858 | $localization_data |
| 1033 | 859 | ) |
| 1034 | 860 | ); |
| 1035 | 861 | wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' ); |
| 862 | + | |
| 1036 | 863 | } |
| 1037 | 864 | |
| 1038 | - if ( $is_screen_sureforms_form_settings || $is_screen_sureforms_forms ) { | |
| 865 | + if ( $is_screen_sureforms_form_settings ) { | |
| 1039 | 866 | wp_enqueue_style( SRFM_SLUG . '-settings', $css_uri . 'backend/settings' . $file_prefix . $rtl . '.css', [], SRFM_VER ); |
| 1040 | 867 | } |
| 1041 | 868 | |
| 1042 | 869 | // Enqueue styles for the entries page. |
| @@ -1043,61 +870,11 @@ | ||
| 1043 | 870 | if ( $is_screen_sureforms_entries ) { |
| 1044 | 871 | $asset_handle = '-entries'; |
| 1045 | 872 | wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/entries.js', $script_info['dependencies'], SRFM_VER, true ); |
| 1046 | 873 | |
| 1047 | - wp_localize_script( | |
| 1048 | - SRFM_SLUG . $asset_handle, | |
| 1049 | - SRFM_SLUG . '_admin', | |
| 1050 | - apply_filters( | |
| 1051 | - SRFM_SLUG . '_admin_filter', | |
| 1052 | - $localization_data | |
| 1053 | - ) | |
| 1054 | - ); | |
| 1055 | 874 | $script_translations_handlers[] = SRFM_SLUG . $asset_handle; |
| 1056 | 875 | } |
| 1057 | 876 | |
| 1058 | - // Enqueue scripts for the learn page. | |
| 1059 | - if ( $is_screen_sureforms_learn ) { | |
| 1060 | - $asset_handle = '-learn'; | |
| 1061 | - wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/learn.js', $script_info['dependencies'], SRFM_VER, true ); | |
| 1062 | - | |
| 1063 | - wp_localize_script( | |
| 1064 | - SRFM_SLUG . $asset_handle, | |
| 1065 | - SRFM_SLUG . '_admin', | |
| 1066 | - apply_filters( | |
| 1067 | - SRFM_SLUG . '_admin_filter', | |
| 1068 | - $localization_data | |
| 1069 | - ) | |
| 1070 | - ); | |
| 1071 | - $script_translations_handlers[] = SRFM_SLUG . $asset_handle; | |
| 1072 | - } | |
| 1073 | - | |
| 1074 | - // Enqueue scripts for the forms page. | |
| 1075 | - if ( $is_screen_sureforms_forms ) { | |
| 1076 | - $asset_handle = '-forms'; | |
| 1077 | - | |
| 1078 | - $script_asset_path = SRFM_DIR . 'assets/build/forms.asset.php'; | |
| 1079 | - $script_info = file_exists( $script_asset_path ) | |
| 1080 | - ? include $script_asset_path | |
| 1081 | - : [ | |
| 1082 | - 'dependencies' => [], | |
| 1083 | - 'version' => SRFM_VER, | |
| 1084 | - ]; | |
| 1085 | - | |
| 1086 | - wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/forms.js', $script_info['dependencies'], SRFM_VER, true ); | |
| 1087 | - wp_localize_script( | |
| 1088 | - SRFM_SLUG . $asset_handle, | |
| 1089 | - SRFM_SLUG . '_admin', | |
| 1090 | - apply_filters( | |
| 1091 | - SRFM_SLUG . '_admin_filter', | |
| 1092 | - $localization_data | |
| 1093 | - ) | |
| 1094 | - ); | |
| 1095 | - wp_enqueue_style( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/forms.css', [], SRFM_VER, 'all' ); | |
| 1096 | - | |
| 1097 | - $script_translations_handlers[] = SRFM_SLUG . $asset_handle; | |
| 1098 | - } | |
| 1099 | - | |
| 1100 | 877 | // Enqueue scripts for the SureMail promotional page. |
| 1101 | 878 | $is_screen_sureforms_smtp = Helper::validate_request_context( 'sureforms_smtp', 'page' ); |
| 1102 | 879 | if ( $is_screen_sureforms_smtp ) { |
| 1103 | 880 | $asset_handle = 'suremail'; |
| @@ -1136,47 +913,27 @@ | ||
| 1136 | 913 | |
| 1137 | 914 | $script_translations_handlers[] = SRFM_SLUG . '-suremail'; |
| 1138 | 915 | } |
| 1139 | 916 | |
| 1140 | - // Enqueue scripts for the Quiz empty state page (free users only). | |
| 1141 | - if ( $is_screen_quiz_empty_state && ! Helper::has_pro() ) { | |
| 1142 | - $asset_handle = 'quizEmptyState'; | |
| 917 | + // Admin Submenu Styles. | |
| 918 | + wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . $rtl . '.css', [], SRFM_VER ); | |
| 1143 | 919 | |
| 1144 | - $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; | |
| 1145 | - $script_info = file_exists( $script_asset_path ) | |
| 1146 | - ? include $script_asset_path | |
| 1147 | - : [ | |
| 1148 | - 'dependencies' => [], | |
| 1149 | - 'version' => SRFM_VER, | |
| 1150 | - ]; | |
| 920 | + if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) { | |
| 921 | + $asset_handle = 'page_header'; | |
| 1151 | 922 | |
| 1152 | - wp_enqueue_script( SRFM_SLUG . '-quiz-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); | |
| 1153 | - wp_enqueue_style( SRFM_SLUG . '-quiz-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [], SRFM_VER, 'all' ); | |
| 1154 | - | |
| 1155 | - $script_translations_handlers[] = SRFM_SLUG . '-quiz-empty-state'; | |
| 1156 | - } | |
| 1157 | - | |
| 1158 | - // Enqueue scripts for the Survey Reports empty state page (free users only). | |
| 1159 | - if ( $is_screen_survey_empty_state && ! Helper::has_pro() ) { | |
| 1160 | - $asset_handle = 'surveyEmptyState'; | |
| 1161 | - | |
| 1162 | 923 | $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; |
| 1163 | 924 | $script_info = file_exists( $script_asset_path ) |
| 1164 | - ? include $script_asset_path | |
| 1165 | - : [ | |
| 1166 | - 'dependencies' => [], | |
| 1167 | - 'version' => SRFM_VER, | |
| 1168 | - ]; | |
| 925 | + ? include $script_asset_path | |
| 926 | + : [ | |
| 927 | + 'dependencies' => [], | |
| 928 | + 'version' => SRFM_VER, | |
| 929 | + ]; | |
| 930 | + wp_enqueue_script( SRFM_SLUG . '-form-page-header', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); | |
| 931 | + wp_enqueue_style( SRFM_SLUG . '-form-archive-styles', $css_uri . 'form-archive-styles' . $file_prefix . $rtl . '.css', [], SRFM_VER ); | |
| 1169 | 932 | |
| 1170 | - wp_enqueue_script( SRFM_SLUG . '-survey-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); | |
| 1171 | - wp_enqueue_style( SRFM_SLUG . '-survey-empty-state', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [], SRFM_VER, 'all' ); | |
| 1172 | - | |
| 1173 | - $script_translations_handlers[] = SRFM_SLUG . '-survey-empty-state'; | |
| 933 | + $script_translations_handlers[] = SRFM_SLUG . '-form-page-header'; | |
| 1174 | 934 | } |
| 1175 | 935 | |
| 1176 | - // Admin Submenu Styles. | |
| 1177 | - wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . $rtl . '.css', [], SRFM_VER ); | |
| 1178 | - | |
| 1179 | 936 | if ( $is_screen_sureforms_form_settings ) { |
| 1180 | 937 | $asset_handle = 'settings'; |
| 1181 | 938 | |
| 1182 | 939 | $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; |
| @@ -1190,17 +947,42 @@ | ||
| 1190 | 947 | wp_enqueue_script( SRFM_SLUG . '-settings', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); |
| 1191 | 948 | wp_localize_script( |
| 1192 | 949 | SRFM_SLUG . '-settings', |
| 1193 | 950 | SRFM_SLUG . '_admin', |
| 1194 | - apply_filters( | |
| 1195 | - SRFM_SLUG . '_admin_filter', | |
| 1196 | - $localization_data | |
| 1197 | - ) | |
| 951 | + $localization_data | |
| 1198 | 952 | ); |
| 1199 | 953 | |
| 1200 | 954 | $script_translations_handlers[] = SRFM_SLUG . '-settings'; |
| 1201 | 955 | } |
| 956 | + if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) { | |
| 957 | + wp_enqueue_script( SRFM_SLUG . '-form-archive', $js_uri . 'form-archive' . $file_prefix . '.js', [], SRFM_VER, true ); | |
| 958 | + wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [ 'wp-i18n' ], SRFM_VER, true ); | |
| 959 | + wp_localize_script( | |
| 960 | + SRFM_SLUG . '-export', | |
| 961 | + SRFM_SLUG . '_export', | |
| 962 | + [ | |
| 963 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 964 | + 'srfm_export_nonce' => wp_create_nonce( 'export_form_nonce' ), | |
| 965 | + 'site_url' => get_site_url(), | |
| 966 | + 'import_form_nonce' => Helper::current_user_can() ? wp_create_nonce( 'wp_rest' ) : '', | |
| 967 | + 'import_btn_string' => __( 'Import Form', 'sureforms' ), | |
| 968 | + ] | |
| 969 | + ); | |
| 1202 | 970 | |
| 971 | + wp_enqueue_script( SRFM_SLUG . '-backend', $js_uri . 'backend' . $file_prefix . '.js', [], SRFM_VER, true ); | |
| 972 | + wp_localize_script( | |
| 973 | + SRFM_SLUG . '-backend', | |
| 974 | + SRFM_SLUG . '_backend', | |
| 975 | + [ | |
| 976 | + 'site_url' => get_site_url(), | |
| 977 | + ] | |
| 978 | + ); | |
| 979 | + | |
| 980 | + $script_translations_handlers[] = SRFM_SLUG . '-form-archive'; | |
| 981 | + $script_translations_handlers[] = SRFM_SLUG . '-export'; | |
| 982 | + $script_translations_handlers[] = SRFM_SLUG . '-backend'; | |
| 983 | + } | |
| 984 | + | |
| 1203 | 985 | if ( $is_screen_add_new_form ) { |
| 1204 | 986 | wp_enqueue_style( SRFM_SLUG . '-template-picker', $css_uri . 'template-picker' . $file_prefix . $rtl . '.css', [], SRFM_VER ); |
| 1205 | 987 | |
| 1206 | 988 | $sureforms_admin = 'templatePicker'; |
| @@ -1245,9 +1027,8 @@ | ||
| 1245 | 1027 | 'srfm/checkbox', |
| 1246 | 1028 | 'srfm/number', |
| 1247 | 1029 | 'srfm/inline-button', |
| 1248 | 1030 | 'srfm/advanced-heading', |
| 1249 | - 'srfm/payment', | |
| 1250 | 1031 | ] |
| 1251 | 1032 | ); |
| 1252 | 1033 | if ( ! is_array( $default_allowed_quick_sidebar_blocks ) ) { |
| 1253 | 1034 | $default_allowed_quick_sidebar_blocks = []; |
| @@ -1259,25 +1040,22 @@ | ||
| 1259 | 1040 | } |
| 1260 | 1041 | $quick_sidebar_allowed_blocks = get_option( 'srfm_quick_sidebar_allowed_blocks' ); |
| 1261 | 1042 | $quick_sidebar_allowed_blocks = ! empty( $quick_sidebar_allowed_blocks ) && is_array( $quick_sidebar_allowed_blocks ) ? $quick_sidebar_allowed_blocks : $default_allowed_quick_sidebar_blocks; |
| 1262 | 1043 | $srfm_ajax_nonce = wp_create_nonce( 'srfm_ajax_nonce' ); |
| 1044 | + wp_enqueue_script( SRFM_SLUG . '-quick-action-siderbar', SRFM_URL . 'assets/build/quickActionSidebar.js', [], SRFM_VER, true ); | |
| 1045 | + wp_localize_script( | |
| 1046 | + SRFM_SLUG . '-quick-action-siderbar', | |
| 1047 | + SRFM_SLUG . '_quick_sidebar_blocks', | |
| 1048 | + [ | |
| 1049 | + 'allowed_blocks' => $quick_sidebar_allowed_blocks, | |
| 1050 | + 'srfm_enable_quick_action_sidebar' => $srfm_enable_quick_action_sidebar, | |
| 1051 | + 'srfm_ajax_nonce' => $srfm_ajax_nonce, | |
| 1052 | + 'srfm_ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 1053 | + ] | |
| 1054 | + ); | |
| 1263 | 1055 | |
| 1264 | - if ( Helper::is_sureforms_admin_page() ) { | |
| 1265 | - wp_enqueue_script( SRFM_SLUG . '-quick-action-siderbar', SRFM_URL . 'assets/build/quickActionSidebar.js', [], SRFM_VER, true ); | |
| 1266 | - wp_localize_script( | |
| 1267 | - SRFM_SLUG . '-quick-action-siderbar', | |
| 1268 | - SRFM_SLUG . '_quick_sidebar_blocks', | |
| 1269 | - [ | |
| 1270 | - 'allowed_blocks' => $quick_sidebar_allowed_blocks, | |
| 1271 | - 'srfm_enable_quick_action_sidebar' => $srfm_enable_quick_action_sidebar, | |
| 1272 | - 'srfm_ajax_nonce' => $srfm_ajax_nonce, | |
| 1273 | - 'srfm_ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 1274 | - ] | |
| 1275 | - ); | |
| 1056 | + $script_translations_handlers[] = SRFM_SLUG . '-quick-action-siderbar'; | |
| 1276 | 1057 | |
| 1277 | - $script_translations_handlers[] = SRFM_SLUG . '-quick-action-siderbar'; | |
| 1278 | - } | |
| 1279 | - | |
| 1280 | 1058 | /** |
| 1281 | 1059 | * Enqueuing SureTriggers Integration script. |
| 1282 | 1060 | * This script loads suretriggers iframe in Intergations tab. |
| 1283 | 1061 | */ |
| @@ -1349,53 +1127,40 @@ | ||
| 1349 | 1127 | |
| 1350 | 1128 | return $status; |
| 1351 | 1129 | } |
| 1352 | 1130 | |
| 1131 | + // Entries methods. | |
| 1132 | + | |
| 1353 | 1133 | /** |
| 1354 | - * Register Pro compatibility notices early for React pages. | |
| 1134 | + * Handle entry actions. | |
| 1355 | 1135 | * |
| 1356 | - * This method runs on admin_init (priority 5) to ensure notices are | |
| 1357 | - * registered BEFORE admin_enqueue_scripts, so they're available when | |
| 1358 | - * wp_localize_script runs. | |
| 1359 | - * | |
| 1360 | - * Hooked - admin_init (priority 5) | |
| 1361 | - * | |
| 1136 | + * @since 0.0.13 | |
| 1362 | 1137 | * @return void |
| 1363 | - * @since 2.5.0 | |
| 1364 | 1138 | */ |
| 1365 | - public function register_pro_compatibility_notices() { | |
| 1366 | - // Early exit if Pro is not active, user lacks permissions, or Notice_Manager is unavailable. | |
| 1367 | - if ( ! Helper::has_pro() || ! Helper::current_user_can() || ! class_exists( 'SRFM\Admin\Notice_Manager' ) ) { | |
| 1139 | + public function handle_entry_actions() { | |
| 1140 | + Entries_List_Table::process_bulk_actions(); | |
| 1141 | + | |
| 1142 | + if ( ! isset( $_GET['page'] ) || SRFM_ENTRIES !== $_GET['page'] ) { | |
| 1368 | 1143 | return; |
| 1369 | 1144 | } |
| 1370 | - | |
| 1371 | - // Register version outdated notice for React pages. | |
| 1372 | - if ( ! version_compare( SRFM_PRO_VER, SRFM_PRO_RECOMMENDED_VER, '>=' ) ) { | |
| 1373 | - $pro_plugin_name = defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro'; | |
| 1374 | - $react_outdated_message = sprintf( | |
| 1375 | - // translators: %1$s: SureForms version, %2$s: SureForms Pro Plugin Name, %3$s: SureForms Pro Version. | |
| 1376 | - esc_html__( 'SureForms %1$s requires minimum %2$s %3$s to work properly. Please update to the latest version.', 'sureforms' ), | |
| 1377 | - esc_html( SRFM_VER ), | |
| 1378 | - esc_html( $pro_plugin_name ), | |
| 1379 | - esc_html( SRFM_PRO_RECOMMENDED_VER ) | |
| 1380 | - ); | |
| 1381 | - | |
| 1382 | - \SRFM\Admin\Notice_Manager::register_notice( | |
| 1383 | - [ | |
| 1384 | - 'id' => 'sureforms-pro-version-outdated', | |
| 1385 | - 'variant' => 'warning', | |
| 1386 | - 'message' => $react_outdated_message, | |
| 1387 | - 'actions' => [ | |
| 1388 | - [ | |
| 1389 | - 'label' => esc_html__( 'Update Now', 'sureforms' ), | |
| 1390 | - 'url' => admin_url( 'update-core.php' ), | |
| 1391 | - 'variant' => 'primary', | |
| 1392 | - ], | |
| 1393 | - ], | |
| 1394 | - 'pages' => [ 'all' ], | |
| 1395 | - ] | |
| 1396 | - ); | |
| 1145 | + if ( ! isset( $_GET['entry_id'] ) || ! isset( $_GET['action'] ) ) { | |
| 1146 | + return; | |
| 1397 | 1147 | } |
| 1148 | + if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'srfm_entries_action' ) ) { | |
| 1149 | + wp_die( esc_html__( 'Nonce verification failed.', 'sureforms' ) ); | |
| 1150 | + } | |
| 1151 | + $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; | |
| 1152 | + $entry_id = Helper::get_integer_value( sanitize_text_field( wp_unslash( $_GET['entry_id'] ) ) ); | |
| 1153 | + $view = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : ''; | |
| 1154 | + if ( $entry_id > 0 ) { | |
| 1155 | + if ( 'read' === $action && 'details' === $view ) { | |
| 1156 | + $entry_status = Entries::get( $entry_id )['status']; | |
| 1157 | + if ( 'trash' === $entry_status ) { | |
| 1158 | + wp_die( esc_html__( 'You cannot view this entry because it is in trash.', 'sureforms' ) ); | |
| 1159 | + } | |
| 1160 | + } | |
| 1161 | + Entries_List_Table::handle_entry_status( $entry_id, $action, $view ); | |
| 1162 | + } | |
| 1398 | 1163 | } |
| 1399 | 1164 | |
| 1400 | 1165 | /** |
| 1401 | 1166 | * Admin Notice Callback if sureforms pro is out of date. |
| @@ -1477,168 +1242,8 @@ | ||
| 1477 | 1242 | } |
| 1478 | 1243 | } |
| 1479 | 1244 | |
| 1480 | 1245 | /** |
| 1481 | - * Display a notice to the user about providing a review. | |
| 1482 | - * | |
| 1483 | - * @since 2.5.2 | |
| 1484 | - * @return void | |
| 1485 | - */ | |
| 1486 | - public function display_srfm_rating_notice() { | |
| 1487 | - // Only show to admins. | |
| 1488 | - if ( ! Helper::current_user_can() ) { | |
| 1489 | - return; | |
| 1490 | - } | |
| 1491 | - | |
| 1492 | - // Allow the notice to be disabled. | |
| 1493 | - if ( ! apply_filters( 'srfm_show_rating_notice', true ) ) { | |
| 1494 | - return; | |
| 1495 | - } | |
| 1496 | - | |
| 1497 | - Astra_Notices::add_notice( | |
| 1498 | - [ | |
| 1499 | - 'id' => 'srfm-plugin-review-notice', | |
| 1500 | - 'type' => '', | |
| 1501 | - 'message' => $this->build_notice_markup( | |
| 1502 | - esc_html__( 'Amazing! SureForms is powering your forms and submissions - let\'s keep growing together!', 'sureforms' ), | |
| 1503 | - esc_html__( 'If SureForms has been helpful, would you mind taking a moment to leave a 5-star review on WordPress.org?', 'sureforms' ), | |
| 1504 | - esc_url( 'https://wordpress.org/support/plugin/sureforms/reviews/?filter=5#new-post' ), | |
| 1505 | - esc_html__( 'Rate SureForms', 'sureforms' ), | |
| 1506 | - esc_html__( 'Maybe later', 'sureforms' ), | |
| 1507 | - esc_html__( 'I already did', 'sureforms' ), | |
| 1508 | - WEEK_IN_SECONDS, | |
| 1509 | - true | |
| 1510 | - ), | |
| 1511 | - 'repeat-notice-after' => WEEK_IN_SECONDS, | |
| 1512 | - 'show_if' => $this->maybe_display_rating_notice(), | |
| 1513 | - 'display-with-other-notices' => true, | |
| 1514 | - ] | |
| 1515 | - ); | |
| 1516 | - | |
| 1517 | - add_action( 'astra_notice_after_markup_srfm-plugin-review-notice', [ $this, 'enqueue_notice_response_script' ] ); | |
| 1518 | - } | |
| 1519 | - | |
| 1520 | - /** | |
| 1521 | - * Display a "Getting Started" admin notice for new users who haven't yet | |
| 1522 | - * reached the rating-notice milestone (3+ forms or 3+ entries). | |
| 1523 | - * | |
| 1524 | - * The Astra Notices library handles the 7-day delay via the | |
| 1525 | - * `display-notice-after` parameter. | |
| 1526 | - * | |
| 1527 | - * @since 2.5.2 | |
| 1528 | - * @return void | |
| 1529 | - */ | |
| 1530 | - public function display_srfm_getting_started_notice() { | |
| 1531 | - // Only show to admins. | |
| 1532 | - if ( ! Helper::current_user_can() ) { | |
| 1533 | - return; | |
| 1534 | - } | |
| 1535 | - | |
| 1536 | - // Allow the notice to be disabled programmatically. | |
| 1537 | - if ( ! apply_filters( 'srfm_show_getting_started_notice', true ) ) { | |
| 1538 | - return; | |
| 1539 | - } | |
| 1540 | - | |
| 1541 | - Astra_Notices::add_notice( | |
| 1542 | - [ | |
| 1543 | - 'id' => 'srfm-getting-started-notice', | |
| 1544 | - 'type' => '', | |
| 1545 | - 'message' => $this->build_notice_markup( | |
| 1546 | - esc_html__( 'SureForms is ready to power your forms — explore what\'s possible!', 'sureforms' ), | |
| 1547 | - esc_html__( 'Manage your forms, track submissions, and discover features like AI Form Builder, payment integrations, and more from the SureForms dashboard.', 'sureforms' ), | |
| 1548 | - esc_url( admin_url( 'admin.php?page=sureforms_menu' ) ), | |
| 1549 | - esc_html__( 'Go to Dashboard', 'sureforms' ), | |
| 1550 | - esc_html__( 'Maybe later', 'sureforms' ), | |
| 1551 | - esc_html__( 'I already know', 'sureforms' ), | |
| 1552 | - WEEK_IN_SECONDS | |
| 1553 | - ), | |
| 1554 | - 'repeat-notice-after' => WEEK_IN_SECONDS, | |
| 1555 | - 'show_if' => ! $this->maybe_display_rating_notice(), | |
| 1556 | - 'display-notice-after' => WEEK_IN_SECONDS, | |
| 1557 | - 'display-with-other-notices' => true, | |
| 1558 | - ] | |
| 1559 | - ); | |
| 1560 | - | |
| 1561 | - add_action( 'astra_notice_after_markup_srfm-getting-started-notice', [ $this, 'enqueue_notice_response_script' ] ); | |
| 1562 | - } | |
| 1563 | - | |
| 1564 | - /** | |
| 1565 | - * Enqueue the notice response analytics script. | |
| 1566 | - * | |
| 1567 | - * Called via the astra_notice_after_markup_{id} hook so the script | |
| 1568 | - * only loads when a SureForms notice is actually rendered. | |
| 1569 | - * | |
| 1570 | - * @since 2.5.2 | |
| 1571 | - * @return void | |
| 1572 | - */ | |
| 1573 | - public function enqueue_notice_response_script() { | |
| 1574 | - if ( wp_script_is( 'srfm-notice-response', 'enqueued' ) ) { | |
| 1575 | - return; | |
| 1576 | - } | |
| 1577 | - | |
| 1578 | - wp_enqueue_script( | |
| 1579 | - 'srfm-notice-response', | |
| 1580 | - SRFM_URL . 'admin/assets/js/notice-response.js', | |
| 1581 | - [], | |
| 1582 | - SRFM_VER, | |
| 1583 | - true | |
| 1584 | - ); | |
| 1585 | - | |
| 1586 | - wp_localize_script( | |
| 1587 | - 'srfm-notice-response', | |
| 1588 | - 'srfmNoticeResponse', | |
| 1589 | - [ | |
| 1590 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 1591 | - 'nonce' => wp_create_nonce( 'srfm_notice_response' ), | |
| 1592 | - ] | |
| 1593 | - ); | |
| 1594 | - } | |
| 1595 | - | |
| 1596 | - /** | |
| 1597 | - * Handle the notice response AJAX request. | |
| 1598 | - * | |
| 1599 | - * Validates the request and records the analytics event | |
| 1600 | - * for the notice button that was clicked. | |
| 1601 | - * | |
| 1602 | - * @since 2.5.2 | |
| 1603 | - * @return void | |
| 1604 | - */ | |
| 1605 | - public function handle_notice_response() { | |
| 1606 | - if ( ! check_ajax_referer( 'srfm_notice_response', 'nonce', false ) ) { | |
| 1607 | - wp_send_json_error( [ 'message' => __( 'Invalid nonce.', 'sureforms' ) ], 403 ); | |
| 1608 | - } | |
| 1609 | - | |
| 1610 | - if ( ! Helper::current_user_can() ) { | |
| 1611 | - wp_send_json_error( [ 'message' => __( 'Unauthorized user.', 'sureforms' ) ], 403 ); | |
| 1612 | - } | |
| 1613 | - | |
| 1614 | - $notice_id = isset( $_POST['notice_id'] ) ? sanitize_text_field( wp_unslash( $_POST['notice_id'] ) ) : ''; | |
| 1615 | - $button = isset( $_POST['button'] ) ? sanitize_text_field( wp_unslash( $_POST['button'] ) ) : ''; | |
| 1616 | - | |
| 1617 | - $valid = [ | |
| 1618 | - 'srfm-getting-started-notice' => [ | |
| 1619 | - 'go_to_dashboard' => 'getting_started_notice_cta', | |
| 1620 | - 'maybe_later' => 'getting_started_notice_snooze', | |
| 1621 | - 'dismissed' => 'getting_started_notice_dismiss', | |
| 1622 | - ], | |
| 1623 | - 'srfm-plugin-review-notice' => [ | |
| 1624 | - 'rate_sureforms' => 'rating_notice_cta', | |
| 1625 | - 'maybe_later' => 'rating_notice_snooze', | |
| 1626 | - 'dismissed' => 'rating_notice_dismiss', | |
| 1627 | - ], | |
| 1628 | - ]; | |
| 1629 | - | |
| 1630 | - if ( ! isset( $valid[ $notice_id ][ $button ] ) ) { | |
| 1631 | - wp_send_json_error( [ 'message' => __( 'Invalid parameters.', 'sureforms' ) ], 400 ); | |
| 1632 | - } | |
| 1633 | - | |
| 1634 | - $event_name = $valid[ $notice_id ][ $button ]; | |
| 1635 | - Analytics::events()->track( $event_name, $button ); | |
| 1636 | - | |
| 1637 | - wp_send_json_success(); | |
| 1638 | - } | |
| 1639 | - | |
| 1640 | - /** | |
| 1641 | 1246 | * Disables the capabilities for WPForms to avoid conflicts when enqueueing |
| 1642 | 1247 | * scripts and styles for WPForms. |
| 1643 | 1248 | * |
| 1644 | 1249 | * This function is intended to prevent any potential conflicts that may arise |
| @@ -1865,86 +1470,8 @@ | ||
| 1865 | 1470 | $this->render_dashboard_widget_footer( $entries_data ); |
| 1866 | 1471 | ?> |
| 1867 | 1472 | </div> |
| 1868 | 1473 | <?php |
| 1869 | - } | |
| 1870 | - | |
| 1871 | - /** | |
| 1872 | - * Build the shared HTML markup for admin notices. | |
| 1873 | - * | |
| 1874 | - * @since 2.5.2 | |
| 1875 | - * | |
| 1876 | - * All text parameters must be pre-escaped by the caller (e.g. via esc_html__()). | |
| 1877 | - * URL parameters must be pre-escaped via esc_url(). | |
| 1878 | - * | |
| 1879 | - * @param string $heading The notice heading text (pre-escaped). | |
| 1880 | - * @param string $message The notice body text (pre-escaped). | |
| 1881 | - * @param string $cta_url The primary CTA URL (pre-escaped). | |
| 1882 | - * @param string $cta_text The primary CTA button text (pre-escaped). | |
| 1883 | - * @param string $snooze_text The snooze button text (pre-escaped). | |
| 1884 | - * @param string $dismiss_text The dismiss button text (pre-escaped). | |
| 1885 | - * @param int $snooze_duration Snooze duration in seconds for the data-repeat-notice-after attribute. | |
| 1886 | - * @param bool $external_cta Whether the CTA opens in a new tab and also dismisses the notice | |
| 1887 | - * via the astra-notice-close class. Default false. | |
| 1888 | - * @return string The notice HTML markup. | |
| 1889 | - */ | |
| 1890 | - private function build_notice_markup( $heading, $message, $cta_url, $cta_text, $snooze_text, $dismiss_text, $snooze_duration, $external_cta = false ) { | |
| 1891 | - $image_path = esc_url( SRFM_URL . 'admin/assets/sureforms-logo.png' ); | |
| 1892 | - $cta_class = $external_cta ? 'astra-notice-close button-primary' : 'button-primary'; | |
| 1893 | - $cta_attrs = $external_cta ? ' target="_blank" rel="noopener noreferrer"' : ''; | |
| 1894 | - | |
| 1895 | - return sprintf( | |
| 1896 | - '<div class="notice-image"> | |
| 1897 | - <img src="%1$s" class="custom-logo" alt="SureForms" itemprop="logo"> | |
| 1898 | - </div> | |
| 1899 | - <div class="notice-content"> | |
| 1900 | - <div class="notice-heading"> | |
| 1901 | - %2$s | |
| 1902 | - </div> | |
| 1903 | - %3$s<br /> | |
| 1904 | - <div class="astra-review-notice-container"> | |
| 1905 | - <a href="%4$s" class="%5$s"%6$s> | |
| 1906 | - %7$s | |
| 1907 | - </a> | |
| 1908 | - <span class="dashicons dashicons-clock" aria-hidden="true"></span> | |
| 1909 | - <a href="#" data-repeat-notice-after="%8$s" class="astra-notice-close"> | |
| 1910 | - %9$s | |
| 1911 | - </a> | |
| 1912 | - <span class="dashicons dashicons-smiley" aria-hidden="true"></span> | |
| 1913 | - <a href="#" class="astra-notice-close"> | |
| 1914 | - %10$s | |
| 1915 | - </a> | |
| 1916 | - </div> | |
| 1917 | - </div>', | |
| 1918 | - $image_path, | |
| 1919 | - $heading, | |
| 1920 | - $message, | |
| 1921 | - $cta_url, | |
| 1922 | - esc_attr( $cta_class ), | |
| 1923 | - $cta_attrs, | |
| 1924 | - $cta_text, | |
| 1925 | - $snooze_duration, | |
| 1926 | - $snooze_text, | |
| 1927 | - $dismiss_text | |
| 1928 | - ); | |
| 1929 | - } | |
| 1930 | - | |
| 1931 | - /** | |
| 1932 | - * Callback for displaying the rating notice conditionally. | |
| 1933 | - * | |
| 1934 | - * Returns true if the user has 3 or more published forms or 3 or more form entries. | |
| 1935 | - * | |
| 1936 | - * @since 2.5.2 | |
| 1937 | - * @return bool | |
| 1938 | - */ | |
| 1939 | - private function maybe_display_rating_notice() { | |
| 1940 | - if ( null === $this->should_show_rating ) { | |
| 1941 | - $entries_count = Entries::get_total_entries_by_status( 'all' ); | |
| 1942 | - $form_count = wp_count_posts( SRFM_FORMS_POST_TYPE ); | |
| 1943 | - $this->should_show_rating = $entries_count >= self::RATING_NOTICE_THRESHOLD || Helper::get_integer_value( $form_count->publish ?? 0 ) >= self::RATING_NOTICE_THRESHOLD; | |
| 1944 | - } | |
| 1945 | - | |
| 1946 | - return $this->should_show_rating; | |
| 1947 | 1474 | } |
| 1948 | 1475 | |
| 1949 | 1476 | /** |
| 1950 | 1477 | * Get random premium feature text. |