| @@ -6,15 +6,15 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace SRFM\Admin; |
| 9 | 9 | |
| 10 | -use SRFM\Inc\Traits\Get_Instance; | |
| 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; |
| 13 | +use SRFM\Inc\Database\Tables\Entries; | |
| 12 | 14 | use SRFM\Inc\Helper; |
| 13 | -use SRFM\Admin\Views\Single_Entry; | |
| 14 | -use SRFM\Admin\Views\Entries_List_Table; | |
| 15 | 15 | use SRFM\Inc\Post_Types; |
| 16 | -use SRFM\Inc\Database\Tables\Entries; | |
| 16 | +use SRFM\Inc\Traits\Get_Instance; | |
| 17 | 17 | |
| 18 | 18 | if ( ! defined( 'ABSPATH' ) ) { |
| 19 | 19 | exit; // Exit if accessed directly. |
| 20 | 20 | } |
| @@ -23,9 +23,8 @@ | ||
| 23 | 23 | * |
| 24 | 24 | * @since 0.0.1 |
| 25 | 25 | */ |
| 26 | 26 | class Admin { |
| 27 | - | |
| 28 | 27 | use Get_Instance; |
| 29 | 28 | |
| 30 | 29 | /** |
| 31 | 30 | * Class constructor. |
| @@ -40,96 +39,22 @@ | ||
| 40 | 39 | add_action( 'admin_menu', [ $this, 'add_new_form' ] ); |
| 41 | 40 | add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 10, 2 ); |
| 42 | 41 | add_action( 'enqueue_block_assets', [ $this, 'enqueue_styles' ] ); |
| 43 | 42 | add_action( 'admin_head', [ $this, 'enqueue_header_styles' ] ); |
| 44 | - add_action( 'admin_body_class', [ $this, 'admin_template_picker_body_class' ] ); | |
| 43 | + add_filter( 'admin_body_class', [ $this, 'admin_template_picker_body_class' ] ); | |
| 45 | 44 | |
| 46 | 45 | // this action is used to restrict Spectra's quick action bar on SureForms CPTS. |
| 47 | 46 | add_action( 'uag_enable_quick_action_sidebar', [ $this, 'restrict_spectra_quick_action_bar' ] ); |
| 48 | 47 | |
| 49 | 48 | add_action( 'current_screen', [ $this, 'enable_gutenberg_for_sureforms' ], 100 ); |
| 49 | + add_action( 'admin_notices', [ $this, 'srfm_pro_version_compatibility' ] ); | |
| 50 | 50 | |
| 51 | 51 | // Handle entry actions. |
| 52 | 52 | add_action( 'admin_init', [ $this, 'handle_entry_actions' ] ); |
| 53 | - add_action( 'admin_notices', [ $this, 'entries_migration_notice' ] ); | |
| 54 | 53 | add_action( 'admin_notices', [ Entries_List_Table::class, 'display_bulk_action_notice' ] ); |
| 55 | 54 | } |
| 56 | 55 | |
| 57 | 56 | /** |
| 58 | - * Print notice to inform users about entries database migration. | |
| 59 | - * | |
| 60 | - * @since 0.0.13 | |
| 61 | - * @return void | |
| 62 | - */ | |
| 63 | - public function entries_migration_notice() { | |
| 64 | - if ( get_option( 'srfm_dismiss_entries_migration_notice', false ) ) { | |
| 65 | - return; | |
| 66 | - } | |
| 67 | - | |
| 68 | - if ( empty( get_posts( [ 'post_type' => SRFM_ENTRIES_POST_TYPE ] ) ) ) { | |
| 69 | - // Bail if we don't have legacy post type entries. | |
| 70 | - return; | |
| 71 | - } | |
| 72 | - | |
| 73 | - $ajaxurl = add_query_arg( | |
| 74 | - [ | |
| 75 | - 'action' => 'sureforms_dismiss_plugin_notice', | |
| 76 | - 'security' => wp_create_nonce( 'srfm_notice_dismiss_nonce' ), | |
| 77 | - ], | |
| 78 | - admin_url( 'admin-ajax.php' ) | |
| 79 | - ); | |
| 80 | - ?> | |
| 81 | - <!-- Adding this internal style to maintain notice styling without worrying about conditional loading of the css files. --> | |
| 82 | - <style> | |
| 83 | - .srfm-plugin-notice-container { | |
| 84 | - display: flex; | |
| 85 | - align-items: center; | |
| 86 | - gap: 20px; | |
| 87 | - padding: 10px 0; | |
| 88 | - } | |
| 89 | - .srfm-plugin-notice--logo svg { | |
| 90 | - width: 60px; | |
| 91 | - height: 60px; | |
| 92 | - } | |
| 93 | - .srfm-plugin-notice--content .srfm-plugin-notice--title { | |
| 94 | - margin: 0; | |
| 95 | - font-size: 20px; | |
| 96 | - line-height: 1.5; | |
| 97 | - } | |
| 98 | - .srfm-plugin-notice--content .srfm-plugin-notice--message { | |
| 99 | - margin-top: 4px; | |
| 100 | - padding: 0; | |
| 101 | - } | |
| 102 | - </style> | |
| 103 | - <div class="notice notice-warning is-dismissible srfm-plugin-notice"> | |
| 104 | - <div class="srfm-plugin-notice-container"> | |
| 105 | - <div class="srfm-plugin-notice--logo"> | |
| 106 | - <svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg"> | |
| 107 | - <path fill-rule="evenodd" clip-rule="evenodd" d="M250 500C388.072 500 500 388.071 500 250C500 111.929 388.072 0 250 0C111.929 0 0 111.929 0 250C0 388.071 111.929 500 250 500ZM251.076 125C231.002 125 203.224 136.48 189.028 150.641L150.477 189.103H342.635L406.887 125H251.076ZM310.648 349.359C296.454 363.52 268.673 375 248.599 375H92.7892L157.043 310.897H349.199L310.648 349.359ZM373.1 221.154H118.42L106.39 233.173C77.9043 258.814 86.3526 278.846 126.246 278.846H381.615L393.649 266.827C421.859 241.336 412.993 221.154 373.1 221.154Z" fill="#D54407"/> | |
| 108 | - </svg> | |
| 109 | - </div> | |
| 110 | - <div class="srfm-plugin-notice--content"> | |
| 111 | - <h3 class="srfm-plugin-notice--title"><?php esc_html_e( 'SureForms - Important Update Notice', 'sureforms' ); ?></h3> | |
| 112 | - <p class="srfm-plugin-notice--message"><strong><?php esc_html_e( "From version 0.0.13 we're migrating to a custom database to enhance SureForms' performance and features.", 'sureforms' ); ?></strong></p> | |
| 113 | - <p class="srfm-plugin-notice--message"><?php esc_html_e( 'This step is necessary and irreversible and your current existing entries will be lost. Thank you for your understanding!', 'sureforms' ); ?></p> | |
| 114 | - </div> | |
| 115 | - </div> | |
| 116 | - </div> | |
| 117 | - <script> | |
| 118 | - (function() { | |
| 119 | - window.addEventListener('load', function() { | |
| 120 | - const dismissNotice = document.querySelector('.is-dismissible.srfm-plugin-notice .notice-dismiss'); | |
| 121 | - | |
| 122 | - dismissNotice.addEventListener('click', function() { | |
| 123 | - fetch('<?php echo esc_url_raw( $ajaxurl ); ?>'); | |
| 124 | - }); | |
| 125 | - }); | |
| 126 | - }()); | |
| 127 | - </script> | |
| 128 | - <?php | |
| 129 | - } | |
| 130 | - | |
| 131 | - /** | |
| 132 | 57 | * Enable Gutenberg for SureForms associated post types. |
| 133 | 58 | * |
| 134 | 59 | * @since 0.0.10 |
| 135 | 60 | */ |
| @@ -147,9 +72,8 @@ | ||
| 147 | 72 | add_filter( 'gutenberg_can_edit_post_type', '__return_true', 110 ); |
| 148 | 73 | } |
| 149 | 74 | } |
| 150 | 75 | |
| 151 | - | |
| 152 | 76 | /** |
| 153 | 77 | * Sureforms editor header styles. |
| 154 | 78 | * |
| 155 | 79 | * @since 0.0.1 |
| @@ -190,9 +114,10 @@ | ||
| 190 | 114 | __( 'SureForms', 'sureforms' ), |
| 191 | 115 | __( 'SureForms', 'sureforms' ), |
| 192 | 116 | 'edit_others_posts', |
| 193 | 117 | $menu_slug, |
| 194 | - function () {}, | |
| 118 | + static function () { | |
| 119 | + }, | |
| 195 | 120 | 'data:image/svg+xml;base64,' . base64_encode( $logo ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
| 196 | 121 | 30 |
| 197 | 122 | ); |
| 198 | 123 | |
| @@ -273,9 +198,9 @@ | ||
| 273 | 198 | 'sureforms_menu', |
| 274 | 199 | __( 'Entries', 'sureforms' ), |
| 275 | 200 | __( 'Entries', 'sureforms' ), |
| 276 | 201 | 'edit_others_posts', |
| 277 | - 'sureforms_entries', | |
| 202 | + SRFM_ENTRIES, | |
| 278 | 203 | [ $this, 'render_entries' ], |
| 279 | 204 | 3 |
| 280 | 205 | ); |
| 281 | 206 | } |
| @@ -307,12 +232,12 @@ | ||
| 307 | 232 | |
| 308 | 233 | // Render all entries view. |
| 309 | 234 | $entries_table = new Entries_List_Table(); |
| 310 | 235 | $entries_table->prepare_items(); |
| 311 | - echo '<div class="wrap"><h1 class="wp-heading-inline">Entries</h1>'; | |
| 312 | - if ( 0 >= $entries_table->all_entries_count && 0 >= $entries_table->trash_count ) { | |
| 236 | + echo '<div class="wrap"><h1 class="wp-heading-inline">' . esc_html__( 'Entries', 'sureforms' ) . '</h1>'; | |
| 237 | + if ( empty( $entries_table->all_entries_count ) && empty( $entries_table->trash_entries_count ) ) { | |
| 313 | 238 | $instance = Post_Types::get_instance(); |
| 314 | - $instance->sureforms_render_blank_state( SRFM_ENTRIES_POST_TYPE ); | |
| 239 | + $instance->sureforms_render_blank_state( SRFM_ENTRIES ); | |
| 315 | 240 | $instance->get_blank_state_styles(); |
| 316 | 241 | return; |
| 317 | 242 | } |
| 318 | 243 | echo '<form method="get">'; |
| @@ -349,8 +274,9 @@ | ||
| 349 | 274 | * @since 0.0.1 |
| 350 | 275 | */ |
| 351 | 276 | public function enqueue_styles() { |
| 352 | 277 | $current_screen = get_current_screen(); |
| 278 | + global $wp_version; | |
| 353 | 279 | |
| 354 | 280 | $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min'; |
| 355 | 281 | $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; |
| 356 | 282 | |
| @@ -369,8 +295,16 @@ | ||
| 369 | 295 | wp_enqueue_style( SRFM_SLUG . '-intl', $vendor_css_uri . 'intl/intlTelInput-backend.min.css', [], SRFM_VER ); |
| 370 | 296 | wp_enqueue_style( SRFM_SLUG . '-common', $css_uri . 'common' . $file_prefix . '.css', [], SRFM_VER ); |
| 371 | 297 | wp_enqueue_style( SRFM_SLUG . '-reactQuill', $vendor_css_uri . 'quill/quill.snow.css', [], SRFM_VER ); |
| 372 | 298 | wp_enqueue_style( SRFM_SLUG . '-single-form-modal', $css_uri . 'single-form-setting' . $file_prefix . '.css', [], SRFM_VER ); |
| 299 | + | |
| 300 | + // if version is equal to or lower than 6.6.2 then add compatibility css. | |
| 301 | + if ( version_compare( $wp_version, '6.6.2', '<=' ) ) { | |
| 302 | + $srfm_inline_css = '.srfm-settings-modal .srfm-setting-modal-container .components-toggle-control .components-base-control__help{ | |
| 303 | + margin-left: 4em; | |
| 304 | + }'; | |
| 305 | + wp_add_inline_style( SRFM_SLUG . '-single-form-modal', $srfm_inline_css ); | |
| 306 | + } | |
| 373 | 307 | } |
| 374 | 308 | |
| 375 | 309 | wp_enqueue_style( SRFM_SLUG . '-form-selector', $css_uri . 'srfm-form-selector' . $file_prefix . '.css', [], SRFM_VER ); |
| 376 | 310 | wp_enqueue_style( SRFM_SLUG . '-common-editor', SRFM_URL . 'assets/build/common-editor.css', [], SRFM_VER, 'all' ); |
| @@ -417,13 +351,8 @@ | ||
| 417 | 351 | $breadcrumbs[] = [ |
| 418 | 352 | 'title' => 'Forms', |
| 419 | 353 | 'link' => '', |
| 420 | 354 | ]; |
| 421 | - } elseif ( $current_screen && 'sureforms_entry' === $current_screen->post_type ) { | |
| 422 | - $breadcrumbs[] = [ | |
| 423 | - 'title' => 'Entries', | |
| 424 | - 'link' => '', | |
| 425 | - ]; | |
| 426 | 355 | } else { |
| 427 | 356 | $breadcrumbs[] = [ |
| 428 | 357 | 'title' => '', |
| 429 | 358 | 'link' => '', |
| @@ -433,9 +362,8 @@ | ||
| 433 | 362 | |
| 434 | 363 | return $breadcrumbs; |
| 435 | 364 | } |
| 436 | 365 | |
| 437 | - | |
| 438 | 366 | /** |
| 439 | 367 | * Enqueue Admin Scripts. |
| 440 | 368 | * |
| 441 | 369 | * @return void |
| @@ -442,8 +370,9 @@ | ||
| 442 | 370 | * @since 0.0.1 |
| 443 | 371 | */ |
| 444 | 372 | public function enqueue_scripts() { |
| 445 | 373 | $current_screen = get_current_screen(); |
| 374 | + global $wp_version; | |
| 446 | 375 | |
| 447 | 376 | $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min'; |
| 448 | 377 | $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; |
| 449 | 378 | $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/'; |
| @@ -448,8 +377,13 @@ | ||
| 448 | 377 | $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; |
| 449 | 378 | $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/'; |
| 450 | 379 | $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/'; |
| 451 | 380 | |
| 381 | + /** | |
| 382 | + * List of the handles in which we need to add translation compatibility. | |
| 383 | + */ | |
| 384 | + $script_translations_handlers = []; | |
| 385 | + | |
| 452 | 386 | /* RTL */ |
| 453 | 387 | if ( is_rtl() ) { |
| 454 | 388 | $file_prefix .= '-rtl'; |
| 455 | 389 | } |
| @@ -461,20 +395,21 @@ | ||
| 461 | 395 | 'plugin_version' => SRFM_VER, |
| 462 | 396 | 'global_settings_nonce' => current_user_can( 'manage_options' ) ? wp_create_nonce( 'wp_rest' ) : '', |
| 463 | 397 | 'is_pro_active' => defined( 'SRFM_PRO_VER' ), |
| 464 | 398 | 'pro_plugin_version' => defined( 'SRFM_PRO_VER' ) ? SRFM_PRO_VER : '', |
| 399 | + 'pro_plugin_name' => defined( 'SRFM_PRO_VER' ) && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro', | |
| 465 | 400 | 'sureforms_pricing_page' => $this->get_sureforms_website_url( 'pricing' ), |
| 466 | 401 | 'field_spacing_vars' => Helper::get_css_vars(), |
| 402 | + 'is_ver_lower_than_6_7' => version_compare( $wp_version, '6.6.2', '<=' ), | |
| 467 | 403 | ]; |
| 468 | 404 | |
| 469 | - if ( class_exists( 'SRFM_PRO\Admin\Licensing' ) ) { | |
| 470 | - $license_active = \SRFM_PRO\Admin\Licensing::is_license_active(); | |
| 471 | - $localization_data['is_license_active'] = $license_active; | |
| 472 | - } | |
| 405 | + $is_screen_sureforms_menu = Helper::validate_request_context( 'sureforms_menu', 'page' ); | |
| 406 | + $is_screen_add_new_form = Helper::validate_request_context( 'add-new-form', 'page' ); | |
| 407 | + $is_screen_sureforms_form_settings = Helper::validate_request_context( 'sureforms_form_settings', 'page' ); | |
| 408 | + $is_screen_sureforms_entries = Helper::validate_request_context( SRFM_ENTRIES, 'page' ); | |
| 409 | + $is_post_type_sureforms_form = SRFM_FORMS_POST_TYPE === $current_screen->post_type; | |
| 473 | 410 | |
| 474 | - if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type || 'toplevel_page_sureforms_menu' === $current_screen->base || SRFM_ENTRIES_POST_TYPE === $current_screen->post_type | |
| 475 | - || 'sureforms_page_sureforms_form_settings' === $current_screen->id || 'sureforms_page_sureforms_entries' === $current_screen->id | |
| 476 | - ) { | |
| 411 | + if ( $is_screen_sureforms_menu || $is_post_type_sureforms_form || $is_screen_add_new_form || $is_screen_sureforms_form_settings || $is_screen_sureforms_entries ) { | |
| 477 | 412 | $asset_handle = '-dashboard'; |
| 478 | 413 | |
| 479 | 414 | wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER ); |
| 480 | 415 | |
| @@ -488,9 +423,24 @@ | ||
| 488 | 423 | wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/dashboard.js', $script_info['dependencies'], SRFM_VER, true ); |
| 489 | 424 | |
| 490 | 425 | wp_localize_script( SRFM_SLUG . $asset_handle, 'scIcons', [ 'path' => SRFM_URL . 'assets/build/icon-assets' ] ); |
| 491 | 426 | |
| 492 | - $localization_data['security_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' ); | |
| 427 | + $script_translations_handlers[] = SRFM_SLUG . $asset_handle; | |
| 428 | + | |
| 429 | + if ( class_exists( 'SRFM_PRO\Admin\Licensing' ) ) { | |
| 430 | + $license_active = \SRFM_PRO\Admin\Licensing::is_license_active(); | |
| 431 | + $localization_data['is_license_active'] = $license_active; | |
| 432 | + | |
| 433 | + // Updating current licensing status. | |
| 434 | + $srfm_pro_license_status = get_option( 'srfm_pro_license_status', '' ); | |
| 435 | + $current_license_status = $license_active ? 'licensed' : 'unlicensed'; | |
| 436 | + if ( $current_license_status !== $srfm_pro_license_status ) { | |
| 437 | + update_option( 'srfm_pro_license_status', $current_license_status ); | |
| 438 | + } | |
| 439 | + } | |
| 440 | + | |
| 441 | + $localization_data['security_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' ); | |
| 442 | + $localization_data['integration_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=integration-settings' ); | |
| 493 | 443 | wp_localize_script( |
| 494 | 444 | SRFM_SLUG . $asset_handle, |
| 495 | 445 | SRFM_SLUG . '_admin', |
| 496 | 446 | apply_filters( |
| @@ -501,23 +451,39 @@ | ||
| 501 | 451 | wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' ); |
| 502 | 452 | |
| 503 | 453 | } |
| 504 | 454 | |
| 505 | - if ( 'sureforms_page_sureforms_form_settings' === $current_screen->id ) { | |
| 455 | + if ( $is_screen_sureforms_form_settings ) { | |
| 506 | 456 | wp_enqueue_style( SRFM_SLUG . '-settings', $css_uri . 'backend/settings' . $file_prefix . '.css', [], SRFM_VER ); |
| 457 | + | |
| 458 | + // if version is equal to or lower than 6.6.2 then add compatibility css. | |
| 459 | + if ( version_compare( $wp_version, '6.6.2', '<=' ) ) { | |
| 460 | + $srfm_inline_css = ' | |
| 461 | + .srfm-settings-page-container | |
| 462 | + .components-toggle-control { | |
| 463 | + .components-base-control__help{ | |
| 464 | + margin-left: 4em; | |
| 465 | + } | |
| 466 | + } | |
| 467 | + } | |
| 468 | + '; | |
| 469 | + wp_add_inline_style( SRFM_SLUG . '-settings', $srfm_inline_css ); | |
| 470 | + } | |
| 507 | 471 | } |
| 508 | 472 | |
| 509 | 473 | // Enqueue styles for the entries page. |
| 510 | - if ( 'sureforms_page_sureforms_entries' === $current_screen->id ) { | |
| 474 | + if ( $is_screen_sureforms_entries ) { | |
| 511 | 475 | $asset_handle = '-entries'; |
| 512 | 476 | wp_enqueue_style( SRFM_SLUG . $asset_handle, $css_uri . 'backend/entries' . $file_prefix . '.css', [], SRFM_VER ); |
| 513 | 477 | wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/entries.js', $script_info['dependencies'], SRFM_VER, true ); |
| 478 | + | |
| 479 | + $script_translations_handlers[] = SRFM_SLUG . $asset_handle; | |
| 514 | 480 | } |
| 515 | 481 | |
| 516 | 482 | // Admin Submenu Styles. |
| 517 | 483 | wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . '.css', [], SRFM_VER ); |
| 518 | 484 | |
| 519 | - if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id || 'edit-' . SRFM_ENTRIES_POST_TYPE === $current_screen->id ) { | |
| 485 | + if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) { | |
| 520 | 486 | $asset_handle = 'page_header'; |
| 521 | 487 | |
| 522 | 488 | $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; |
| 523 | 489 | $script_info = file_exists( $script_asset_path ) |
| @@ -527,10 +493,13 @@ | ||
| 527 | 493 | 'version' => SRFM_VER, |
| 528 | 494 | ]; |
| 529 | 495 | wp_enqueue_script( SRFM_SLUG . '-form-page-header', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); |
| 530 | 496 | wp_enqueue_style( SRFM_SLUG . '-form-archive-styles', $css_uri . 'form-archive-styles' . $file_prefix . '.css', [], SRFM_VER ); |
| 497 | + | |
| 498 | + $script_translations_handlers[] = SRFM_SLUG . '-form-page-header'; | |
| 531 | 499 | } |
| 532 | - if ( 'sureforms_page_' . SRFM_FORMS_POST_TYPE . '_settings' === $current_screen->base ) { | |
| 500 | + | |
| 501 | + if ( $is_screen_sureforms_form_settings ) { | |
| 533 | 502 | $asset_handle = 'settings'; |
| 534 | 503 | |
| 535 | 504 | $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; |
| 536 | 505 | $script_info = file_exists( $script_asset_path ) |
| @@ -546,8 +515,10 @@ | ||
| 546 | 515 | SRFM_SLUG . '-settings', |
| 547 | 516 | SRFM_SLUG . '_admin', |
| 548 | 517 | $localization_data |
| 549 | 518 | ); |
| 519 | + | |
| 520 | + $script_translations_handlers[] = SRFM_SLUG . '-settings'; | |
| 550 | 521 | } |
| 551 | 522 | if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) { |
| 552 | 523 | wp_enqueue_script( SRFM_SLUG . '-form-archive', $js_uri . 'form-archive' . $file_prefix . '.js', [], SRFM_VER, true ); |
| 553 | 524 | wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [ 'wp-i18n' ], SRFM_VER, true ); |
| @@ -558,9 +529,9 @@ | ||
| 558 | 529 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 559 | 530 | 'srfm_export_nonce' => wp_create_nonce( 'export_form_nonce' ), |
| 560 | 531 | 'site_url' => get_site_url(), |
| 561 | 532 | 'srfm_import_endpoint' => '/wp-json/sureforms/v1/sureforms_import', |
| 562 | - 'import_form_nonce' => ( current_user_can( 'edit_posts' ) ) ? wp_create_nonce( 'wp_rest' ) : '', | |
| 533 | + 'import_form_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '', | |
| 563 | 534 | ] |
| 564 | 535 | ); |
| 565 | 536 | |
| 566 | 537 | wp_enqueue_script( SRFM_SLUG . '-backend', $js_uri . 'backend' . $file_prefix . '.js', [], SRFM_VER, true ); |
| @@ -571,12 +542,14 @@ | ||
| 571 | 542 | 'site_url' => get_site_url(), |
| 572 | 543 | ] |
| 573 | 544 | ); |
| 574 | 545 | |
| 546 | + $script_translations_handlers[] = SRFM_SLUG . '-form-archive'; | |
| 547 | + $script_translations_handlers[] = SRFM_SLUG . '-export'; | |
| 548 | + $script_translations_handlers[] = SRFM_SLUG . '-backend'; | |
| 575 | 549 | } |
| 576 | 550 | |
| 577 | - if ( 'sureforms_page_add-new-form' === $current_screen->id ) { | |
| 578 | - | |
| 551 | + if ( $is_screen_add_new_form ) { | |
| 579 | 552 | $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min'; |
| 580 | 553 | $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; |
| 581 | 554 | |
| 582 | 555 | $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/'; |
| @@ -616,8 +589,10 @@ | ||
| 616 | 589 | 'srfm_ai_auth_user_email' => get_option( 'srfm_ai_auth_user_email' ), |
| 617 | 590 | 'pricing_page_url' => $this->get_sureforms_website_url( 'pricing' ), |
| 618 | 591 | ] |
| 619 | 592 | ); |
| 593 | + | |
| 594 | + $script_translations_handlers[] = SRFM_SLUG . '-template-picker'; | |
| 620 | 595 | } |
| 621 | 596 | // Quick action sidebar. |
| 622 | 597 | $default_allowed_quick_sidebar_blocks = apply_filters( |
| 623 | 598 | 'srfm_quick_sidebar_allowed_blocks', |
| @@ -653,29 +628,65 @@ | ||
| 653 | 628 | 'srfm_ajax_url' => admin_url( 'admin-ajax.php' ), |
| 654 | 629 | ] |
| 655 | 630 | ); |
| 656 | 631 | |
| 632 | + $script_translations_handlers[] = SRFM_SLUG . '-quick-action-siderbar'; | |
| 633 | + | |
| 657 | 634 | /** |
| 658 | 635 | * Enqueuing SureTriggers Integration script. |
| 659 | 636 | * This script loads suretriggers iframe in Intergations tab. |
| 660 | 637 | */ |
| 661 | - if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type ) { | |
| 662 | - wp_enqueue_script( SRFM_SLUG . '-suretriggers-integration', SRFM_SURETRIGGERS_INTERGATION_BASE_URL . 'js/v2/embed.js', [], SRFM_VER, true ); | |
| 638 | + if ( $is_post_type_sureforms_form ) { | |
| 639 | + wp_enqueue_script( SRFM_SLUG . '-suretriggers-integration', SRFM_SURETRIGGERS_INTEGRATION_BASE_URL . 'js/v2/embed.js', [], SRFM_VER, true ); | |
| 663 | 640 | } |
| 641 | + | |
| 642 | + // Check $script_translations_handlers is not empty before calling the function. | |
| 643 | + if ( ! empty( $script_translations_handlers ) ) { | |
| 644 | + // Remove duplicates values from the array. | |
| 645 | + $script_translations_handlers = array_unique( $script_translations_handlers ); | |
| 646 | + | |
| 647 | + foreach ( $script_translations_handlers as $script_handle ) { | |
| 648 | + Helper::register_script_translations( $script_handle ); | |
| 649 | + } | |
| 650 | + } | |
| 664 | 651 | } |
| 665 | 652 | |
| 666 | 653 | /** |
| 667 | 654 | * Form Template Picker Admin Body Classes |
| 655 | + * WordPress sometimes translates class names in the admin body tag, which can result in | |
| 656 | + * incorrect or missing class names when rendering the admin pages. This function ensures | |
| 657 | + * that essential class names are manually added to the body tag to maintain proper functionality. | |
| 668 | 658 | * |
| 669 | 659 | * @since 0.0.1 |
| 670 | 660 | * @param string $classes Space separated class string. |
| 671 | 661 | */ |
| 672 | 662 | public function admin_template_picker_body_class( $classes = '' ) { |
| 673 | - $theme_builder_class = isset( $_GET['page'] ) && 'add-new-form' === $_GET['page'] ? 'srfm-template-picker' : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Fetching a $_GET value, no nonce available to validate. | |
| 674 | - $classes .= ' ' . $theme_builder_class . ' '; | |
| 663 | + // Define an associative array of class names and their corresponding conditions. | |
| 664 | + // Each condition checks whether a specific request context matches. | |
| 665 | + $srfm_classes = [ | |
| 666 | + 'sureforms_page_sureforms_entries' => Helper::validate_request_context( SRFM_ENTRIES, 'page' ), | |
| 667 | + 'sureforms_page_sureforms_form_settings' => Helper::validate_request_context( 'sureforms_form_settings', 'page' ), | |
| 668 | + 'srfm-template-picker' => Helper::validate_request_context( 'add-new-form', 'page' ), | |
| 669 | + ]; | |
| 675 | 670 | |
| 671 | + $add_srfm_classes = ''; | |
| 672 | + | |
| 673 | + // Loop through the defined classes and conditions. | |
| 674 | + foreach ( $srfm_classes as $class => $condition ) { | |
| 675 | + // Check if the condition evaluates to true. | |
| 676 | + if ( $condition ) { | |
| 677 | + // Append the class to the existing classes string, followed by a space. | |
| 678 | + $add_srfm_classes .= empty( $add_srfm_classes ) ? $class : ' ' . $class; | |
| 679 | + } | |
| 680 | + } | |
| 681 | + | |
| 682 | + // Append the new classes to the existing classes string. | |
| 683 | + if ( ! empty( $add_srfm_classes ) ) { | |
| 684 | + $classes .= ' ' . $add_srfm_classes; | |
| 685 | + } | |
| 686 | + | |
| 687 | + // Return the updated list of classes. | |
| 676 | 688 | return $classes; |
| 677 | - | |
| 678 | 689 | } |
| 679 | 690 | |
| 680 | 691 | /** |
| 681 | 692 | * Disable spectra's quick action bar in sureforms CPT. |
| @@ -717,15 +728,13 @@ | ||
| 717 | 728 | * @since 0.0.13 |
| 718 | 729 | * @return void |
| 719 | 730 | */ |
| 720 | 731 | public function handle_entry_actions() { |
| 721 | - if ( isset( $_GET['entry'] ) && isset( $_GET['action'] ) ) { | |
| 722 | - Entries_List_Table::process_bulk_actions(); | |
| 732 | + Entries_List_Table::process_bulk_actions(); | |
| 733 | + | |
| 734 | + if ( ! isset( $_GET['page'] ) || SRFM_ENTRIES !== $_GET['page'] ) { | |
| 723 | 735 | return; |
| 724 | 736 | } |
| 725 | - if ( ! isset( $_GET['page'] ) || 'sureforms_entries' !== $_GET['page'] ) { | |
| 726 | - return; | |
| 727 | - } | |
| 728 | 737 | if ( ! isset( $_GET['entry_id'] ) || ! isset( $_GET['action'] ) ) { |
| 729 | 738 | return; |
| 730 | 739 | } |
| 731 | 740 | if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'srfm_entries_action' ) ) { |
| @@ -741,8 +750,71 @@ | ||
| 741 | 750 | wp_die( esc_html__( 'You cannot view this entry because it is in trash.', 'sureforms' ) ); |
| 742 | 751 | } |
| 743 | 752 | } |
| 744 | 753 | Entries_List_Table::handle_entry_status( $entry_id, $action, $view ); |
| 754 | + } | |
| 755 | + } | |
| 756 | + | |
| 757 | + /** | |
| 758 | + * Admin Notice Callback if sureforms pro is out of date. | |
| 759 | + * | |
| 760 | + * Hooked - admin_notices | |
| 761 | + * | |
| 762 | + * @return void | |
| 763 | + * @since 1.0.4 | |
| 764 | + */ | |
| 765 | + public function srfm_pro_version_compatibility() { | |
| 766 | + $plugin_file = 'sureforms-pro/sureforms-pro.php'; | |
| 767 | + if ( ! is_plugin_active( $plugin_file ) || ! defined( 'SRFM_PRO_VER' ) ) { | |
| 768 | + return; | |
| 769 | + } | |
| 770 | + | |
| 771 | + if ( empty( get_current_screen() ) ) { | |
| 772 | + return; | |
| 773 | + } | |
| 774 | + | |
| 775 | + if ( ! current_user_can( 'update_plugins' ) ) { | |
| 776 | + return; | |
| 777 | + } | |
| 778 | + | |
| 779 | + $srfm_pro_license_status = get_option( 'srfm_pro_license_status', '' ); | |
| 780 | + /** | |
| 781 | + * If the license status is not set then get the license status and update the option accordingly. | |
| 782 | + * This will be executed only once. Subsequently, the option status is updated by the licensing class on license activation or deactivation. | |
| 783 | + */ | |
| 784 | + if ( empty( $srfm_pro_license_status ) && class_exists( 'SRFM_PRO\Admin\Licensing' ) ) { | |
| 785 | + $srfm_pro_license_status = \SRFM_PRO\Admin\Licensing::is_license_active() ? 'licensed' : 'unlicensed'; | |
| 786 | + update_option( 'srfm_pro_license_status', $srfm_pro_license_status ); | |
| 787 | + } | |
| 788 | + | |
| 789 | + $pro_plugin_name = defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro'; | |
| 790 | + $message = ''; | |
| 791 | + $url = admin_url( 'admin.php?page=sureforms_form_settings&tab=account-settings' ); | |
| 792 | + if ( 'unlicensed' === $srfm_pro_license_status ) { | |
| 793 | + $message = '<p>' . sprintf( | |
| 794 | + // translators: %1$s: Opening anchor tag with URL, %2$s: Closing anchor tag, %3$s: SureForms Pro Plugin Name. | |
| 795 | + esc_html__( 'Please %1$sactivate%2$s your copy of %3$s to get new features, access support, receive update notifications, and more.', 'sureforms' ), | |
| 796 | + '<a href="' . esc_url( $url ) . '">', | |
| 797 | + '</a>', | |
| 798 | + '<i>' . esc_html( $pro_plugin_name ) . '</i>' | |
| 799 | + ) . '</p>'; | |
| 800 | + } | |
| 801 | + | |
| 802 | + if ( ! version_compare( SRFM_PRO_VER, SRFM_PRO_RECOMMENDED_VER, '>=' ) ) { | |
| 803 | + $message .= '<p>' . sprintf( | |
| 804 | + // translators: %1$s: SureForms version, %2$s: SureForms Pro Plugin Name, %3$s: SureForms Pro Version, %4$s: Anchor tag open, %5$s: Closing anchor tag. | |
| 805 | + esc_html__( 'SureForms %1$s requires minimum %2$s %3$s to work properly. Please update to the latest version from %4$shere%5$s.', 'sureforms' ), | |
| 806 | + esc_html( SRFM_VER ), | |
| 807 | + esc_html( $pro_plugin_name ), | |
| 808 | + esc_html( SRFM_PRO_RECOMMENDED_VER ), | |
| 809 | + '<a href=' . esc_url( admin_url( 'update-core.php' ) ) . '>', | |
| 810 | + '</a>' | |
| 811 | + ) . '</p>'; | |
| 812 | + } | |
| 813 | + | |
| 814 | + if ( ! empty( $message ) ) { | |
| 815 | + // Phpcs ignore comment is required as $message variable is already escaped. | |
| 816 | + echo '<div class="notice notice-warning">' . $message . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 745 | 817 | } |
| 746 | 818 | } |
| 747 | 819 | |
| 748 | 820 | } |