| @@ -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. |
| @@ -37,96 +36,80 @@ | ||
| 37 | 36 | add_action( 'admin_menu', [ $this, 'add_menu_page' ], 9 ); |
| 38 | 37 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 39 | 38 | add_action( 'admin_menu', [ $this, 'settings_page' ] ); |
| 40 | 39 | add_action( 'admin_menu', [ $this, 'add_new_form' ] ); |
| 40 | + add_action( 'admin_menu', [ $this, 'add_suremail_page' ] ); | |
| 41 | + if ( ! defined( 'SRFM_PRO_VER' ) ) { | |
| 42 | + add_action( 'admin_menu', [ $this, 'add_upgrade_to_pro' ] ); | |
| 43 | + add_action( 'admin_footer', [ $this, 'add_upgrade_to_pro_target_attr' ] ); | |
| 44 | + } | |
| 45 | + | |
| 41 | 46 | add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 10, 2 ); |
| 42 | 47 | add_action( 'enqueue_block_assets', [ $this, 'enqueue_styles' ] ); |
| 43 | 48 | add_action( 'admin_head', [ $this, 'enqueue_header_styles' ] ); |
| 44 | - add_action( 'admin_body_class', [ $this, 'admin_template_picker_body_class' ] ); | |
| 49 | + add_filter( 'admin_body_class', [ $this, 'admin_template_picker_body_class' ] ); | |
| 45 | 50 | |
| 46 | 51 | // this action is used to restrict Spectra's quick action bar on SureForms CPTS. |
| 47 | 52 | add_action( 'uag_enable_quick_action_sidebar', [ $this, 'restrict_spectra_quick_action_bar' ] ); |
| 48 | 53 | |
| 49 | 54 | add_action( 'current_screen', [ $this, 'enable_gutenberg_for_sureforms' ], 100 ); |
| 55 | + add_action( 'admin_notices', [ $this, 'srfm_pro_version_compatibility' ] ); | |
| 50 | 56 | |
| 51 | 57 | // Handle entry actions. |
| 52 | 58 | add_action( 'admin_init', [ $this, 'handle_entry_actions' ] ); |
| 53 | - add_action( 'admin_notices', [ $this, 'entries_migration_notice' ] ); | |
| 54 | 59 | add_action( 'admin_notices', [ Entries_List_Table::class, 'display_bulk_action_notice' ] ); |
| 60 | + | |
| 61 | + // This action enqueues translations for NPS Survey library. | |
| 62 | + // A better solution will be required from library to resolve plugin conflict. | |
| 63 | + add_action( | |
| 64 | + 'admin_footer', | |
| 65 | + static function() { | |
| 66 | + Helper::register_script_translations( 'nps-survey-script' ); | |
| 67 | + }, | |
| 68 | + 1000 | |
| 69 | + ); | |
| 70 | + // Enfold theme compatibility to enable block editor for SureForms post type. | |
| 71 | + add_filter( 'avf_use_block_editor_for_post', [ $this, 'enable_block_editor_in_enfold_theme' ] ); | |
| 72 | + | |
| 73 | + // Add action links to the plugin page. | |
| 74 | + add_filter( 'plugin_action_links_' . SRFM_BASENAME, [ $this, 'add_action_links' ] ); | |
| 75 | + add_filter( 'wpforms_current_user_can', [ $this, 'disable_wpforms_capabilities' ], 10, 3 ); | |
| 55 | 76 | } |
| 56 | 77 | |
| 57 | 78 | /** |
| 58 | - * Print notice to inform users about entries database migration. | |
| 79 | + * Show action on plugin page. | |
| 59 | 80 | * |
| 60 | - * @since 0.0.13 | |
| 61 | - * @return void | |
| 81 | + * @param array $links links. | |
| 82 | + * @return array | |
| 83 | + * @since 1.4.2 | |
| 62 | 84 | */ |
| 63 | - public function entries_migration_notice() { | |
| 64 | - if ( get_option( 'srfm_dismiss_entries_migration_notice', false ) ) { | |
| 65 | - return; | |
| 85 | + public function add_action_links( $links ) { | |
| 86 | + if ( ! defined( 'SRFM_PRO_FILE' ) && ! file_exists( WP_PLUGIN_DIR . '/sureforms-pro/sureforms-pro.php' ) ) { | |
| 87 | + // Display upsell link if SureForms Pro is not installed. | |
| 88 | + $upsell_link = add_query_arg( | |
| 89 | + [ | |
| 90 | + 'utm_medium' => 'plugin-list', | |
| 91 | + ], | |
| 92 | + Helper::get_sureforms_website_url( 'pricing' ) | |
| 93 | + ); | |
| 94 | + $links[] = '<a href="' . esc_url( $upsell_link ) . '" target="_blank" rel="noreferrer" class="sureforms-plugins-go-pro">' . esc_html__( 'Get SureForms Pro', 'sureforms' ) . '</a>'; | |
| 66 | 95 | } |
| 67 | 96 | |
| 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 | - } | |
| 97 | + return $links; | |
| 98 | + } | |
| 72 | 99 | |
| 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; | |
| 100 | + /** | |
| 101 | + * Enable block editor in Enfold theme for SureForms post type. | |
| 102 | + * | |
| 103 | + * @param bool $use_block_editor Whether to use block editor. | |
| 104 | + * @since 1.3.1 | |
| 105 | + */ | |
| 106 | + public function enable_block_editor_in_enfold_theme( $use_block_editor ) { | |
| 107 | + // if SureForms form post type then return true. | |
| 108 | + if ( SRFM_FORMS_POST_TYPE === get_current_screen()->post_type ) { | |
| 109 | + return true; | |
| 88 | 110 | } |
| 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 | |
| 111 | + return $use_block_editor; | |
| 129 | 112 | } |
| 130 | 113 | |
| 131 | 114 | /** |
| 132 | 115 | * Enable Gutenberg for SureForms associated post types. |
| @@ -133,11 +116,12 @@ | ||
| 133 | 116 | * |
| 134 | 117 | * @since 0.0.10 |
| 135 | 118 | */ |
| 136 | 119 | public function enable_gutenberg_for_sureforms() { |
| 137 | - | |
| 138 | - // Check if the Classic Editor plugin is active and if it is set to replace the block editor. | |
| 139 | - if ( ! class_exists( 'Classic_Editor' ) || 'block' === get_option( 'classic-editor-replace' ) ) { | |
| 120 | + /** | |
| 121 | + * Check if the classic editor is enabled from Classic Editor plugin settings or Divi settings. | |
| 122 | + */ | |
| 123 | + if ( 'block' === get_option( 'classic-editor-replace' ) || 'on' === get_option( 'et_enable_classic_editor' ) ) { | |
| 140 | 124 | return; |
| 141 | 125 | } |
| 142 | 126 | |
| 143 | 127 | $srfm_post_types = apply_filters( 'srfm_enable_gutenberg_post_types', [ SRFM_FORMS_POST_TYPE ] ); |
| @@ -147,9 +131,8 @@ | ||
| 147 | 131 | add_filter( 'gutenberg_can_edit_post_type', '__return_true', 110 ); |
| 148 | 132 | } |
| 149 | 133 | } |
| 150 | 134 | |
| 151 | - | |
| 152 | 135 | /** |
| 153 | 136 | * Sureforms editor header styles. |
| 154 | 137 | * |
| 155 | 138 | * @since 0.0.1 |
| @@ -190,9 +173,10 @@ | ||
| 190 | 173 | __( 'SureForms', 'sureforms' ), |
| 191 | 174 | __( 'SureForms', 'sureforms' ), |
| 192 | 175 | 'edit_others_posts', |
| 193 | 176 | $menu_slug, |
| 194 | - function () {}, | |
| 177 | + static function () { | |
| 178 | + }, | |
| 195 | 179 | 'data:image/svg+xml;base64,' . base64_encode( $logo ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
| 196 | 180 | 30 |
| 197 | 181 | ); |
| 198 | 182 | |
| @@ -233,8 +217,94 @@ | ||
| 233 | 217 | } |
| 234 | 218 | } |
| 235 | 219 | |
| 236 | 220 | /** |
| 221 | + * Open to Upgrade to Pro submenu link in new tab. | |
| 222 | + * | |
| 223 | + * @return void | |
| 224 | + * @since 1.6.1 | |
| 225 | + */ | |
| 226 | + public function add_upgrade_to_pro_target_attr() { | |
| 227 | + ?> | |
| 228 | + <script type="text/javascript"> | |
| 229 | + document.addEventListener('DOMContentLoaded', function () { | |
| 230 | + // Upgrade link handler. | |
| 231 | + // IMPORTANT: If this URL changes, also update it in the `add_upgrade_to_pro` function. | |
| 232 | + const upgradeLink = document.querySelector('a[href*="https://sureforms.com/upgrade"]'); | |
| 233 | + if (upgradeLink) { | |
| 234 | + upgradeLink.addEventListener('click', e => { | |
| 235 | + e.preventDefault(); | |
| 236 | + window.open(upgradeLink.href, '_blank'); | |
| 237 | + }); | |
| 238 | + } | |
| 239 | + }); | |
| 240 | + </script> | |
| 241 | + <?php | |
| 242 | + } | |
| 243 | + | |
| 244 | + /** | |
| 245 | + * Add Upgrade to pro menu item. | |
| 246 | + * | |
| 247 | + * @return void | |
| 248 | + * @since 1.6.1 | |
| 249 | + */ | |
| 250 | + public function add_upgrade_to_pro() { | |
| 251 | + // The url used here is used as a selector for css to style the upgrade to pro submenu. | |
| 252 | + // If you are changing this url, please make sure to update the css as well. | |
| 253 | + $upgrade_url = add_query_arg( | |
| 254 | + [ | |
| 255 | + 'utm_medium' => 'submenu_link_upgrade', | |
| 256 | + ], | |
| 257 | + Helper::get_sureforms_website_url( 'upgrade' ) | |
| 258 | + ); | |
| 259 | + | |
| 260 | + add_submenu_page( | |
| 261 | + 'sureforms_menu', | |
| 262 | + __( 'Upgrade', 'sureforms' ), | |
| 263 | + __( 'Upgrade', 'sureforms' ), | |
| 264 | + 'edit_others_posts', | |
| 265 | + $upgrade_url | |
| 266 | + ); | |
| 267 | + } | |
| 268 | + | |
| 269 | + /** | |
| 270 | + * Add SMTP promotional submenu page. | |
| 271 | + * | |
| 272 | + * @return void | |
| 273 | + * @since 1.7.1 | |
| 274 | + */ | |
| 275 | + public function add_suremail_page() { | |
| 276 | + add_submenu_page( | |
| 277 | + 'sureforms_menu', | |
| 278 | + __( 'SMTP', 'sureforms' ), | |
| 279 | + __( 'SMTP', 'sureforms' ), | |
| 280 | + 'edit_others_posts', | |
| 281 | + 'sureforms_smtp', | |
| 282 | + [ $this, 'suremail_page_callback' ] | |
| 283 | + ); | |
| 284 | + | |
| 285 | + // Get the current submenu page. | |
| 286 | + $submenu_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- $_GET['page'] does not provide nonce. | |
| 287 | + | |
| 288 | + // Check if SureMail is installed and active. | |
| 289 | + if ( 'sureforms_smtp' === $submenu_page && file_exists( WP_PLUGIN_DIR . '/suremails/suremails.php' ) && is_plugin_active( 'suremails/suremails.php' ) ) { | |
| 290 | + // Plugin is installed and active - redirect to SureMail dashboard. | |
| 291 | + wp_safe_redirect( admin_url( 'options-general.php?page=suremail#/dashboard' ) ); | |
| 292 | + exit; | |
| 293 | + } | |
| 294 | + } | |
| 295 | + | |
| 296 | + /** | |
| 297 | + * SMTP promotional page callback. | |
| 298 | + * | |
| 299 | + * @return void | |
| 300 | + * @since 1.7.1 | |
| 301 | + */ | |
| 302 | + public function suremail_page_callback() { | |
| 303 | + echo '<div id="srfm-suremail-container" class="srfm-admin-wrapper"></div>'; | |
| 304 | + } | |
| 305 | + | |
| 306 | + /** | |
| 237 | 307 | * Render Admin Dashboard. |
| 238 | 308 | * |
| 239 | 309 | * @return void |
| 240 | 310 | * @since 0.0.1 |
| @@ -239,9 +309,9 @@ | ||
| 239 | 309 | * @return void |
| 240 | 310 | * @since 0.0.1 |
| 241 | 311 | */ |
| 242 | 312 | public function render_dashboard() { |
| 243 | - echo '<div id="srfm-dashboard-container"></div>'; | |
| 313 | + echo '<div id="srfm-dashboard-container" class="srfm-admin-wrapper"></div>'; | |
| 244 | 314 | } |
| 245 | 315 | |
| 246 | 316 | /** |
| 247 | 317 | * Settings page callback. |
| @@ -249,9 +319,9 @@ | ||
| 249 | 319 | * @return void |
| 250 | 320 | * @since 0.0.1 |
| 251 | 321 | */ |
| 252 | 322 | public function settings_page_callback() { |
| 253 | - echo '<div id="srfm-settings-container"></div>'; | |
| 323 | + echo '<div id="srfm-settings-container" class="srfm-admin-wrapper"></div>'; | |
| 254 | 324 | } |
| 255 | 325 | |
| 256 | 326 | /** |
| 257 | 327 | * Add new form menu item. |
| @@ -273,9 +343,9 @@ | ||
| 273 | 343 | 'sureforms_menu', |
| 274 | 344 | __( 'Entries', 'sureforms' ), |
| 275 | 345 | __( 'Entries', 'sureforms' ), |
| 276 | 346 | 'edit_others_posts', |
| 277 | - 'sureforms_entries', | |
| 347 | + SRFM_ENTRIES, | |
| 278 | 348 | [ $this, 'render_entries' ], |
| 279 | 349 | 3 |
| 280 | 350 | ); |
| 281 | 351 | } |
| @@ -286,9 +356,9 @@ | ||
| 286 | 356 | * @return void |
| 287 | 357 | * @since 0.0.1 |
| 288 | 358 | */ |
| 289 | 359 | public function add_new_form_callback() { |
| 290 | - echo '<div id="srfm-add-new-form-container"></div>'; | |
| 360 | + echo '<div id="srfm-add-new-form-container" class="srfm-admin-wrapper"></div>'; | |
| 291 | 361 | } |
| 292 | 362 | |
| 293 | 363 | /** |
| 294 | 364 | * Entries page callback. |
| @@ -298,9 +368,9 @@ | ||
| 298 | 368 | */ |
| 299 | 369 | public function render_entries() { |
| 300 | 370 | // Render single entry view. |
| 301 | 371 | // Adding the phpcs ignore nonce verification as no database operations are performed in this function, it is used to display the single entry view. |
| 302 | - if ( isset( $_GET['entry_id'] ) && is_numeric( $_GET['entry_id'] ) && isset( $_GET['view'] ) && 'details' === $_GET['view'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 372 | + 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. | |
| 303 | 373 | $single_entry_view = new Single_Entry(); |
| 304 | 374 | $single_entry_view->render(); |
| 305 | 375 | return; |
| 306 | 376 | } |
| @@ -307,12 +377,12 @@ | ||
| 307 | 377 | |
| 308 | 378 | // Render all entries view. |
| 309 | 379 | $entries_table = new Entries_List_Table(); |
| 310 | 380 | $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 ) { | |
| 381 | + echo '<div class="wrap"><h1 class="wp-heading-inline">' . esc_html__( 'Entries', 'sureforms' ) . '</h1>'; | |
| 382 | + if ( empty( $entries_table->all_entries_count ) && empty( $entries_table->trash_entries_count ) ) { | |
| 313 | 383 | $instance = Post_Types::get_instance(); |
| 314 | - $instance->sureforms_render_blank_state( SRFM_ENTRIES_POST_TYPE ); | |
| 384 | + $instance->sureforms_render_blank_state( SRFM_ENTRIES ); | |
| 315 | 385 | $instance->get_blank_state_styles(); |
| 316 | 386 | return; |
| 317 | 387 | } |
| 318 | 388 | echo '<form method="get">'; |
| @@ -349,8 +419,9 @@ | ||
| 349 | 419 | * @since 0.0.1 |
| 350 | 420 | */ |
| 351 | 421 | public function enqueue_styles() { |
| 352 | 422 | $current_screen = get_current_screen(); |
| 423 | + global $wp_version; | |
| 353 | 424 | |
| 354 | 425 | $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min'; |
| 355 | 426 | $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; |
| 356 | 427 | |
| @@ -369,8 +440,16 @@ | ||
| 369 | 440 | wp_enqueue_style( SRFM_SLUG . '-intl', $vendor_css_uri . 'intl/intlTelInput-backend.min.css', [], SRFM_VER ); |
| 370 | 441 | wp_enqueue_style( SRFM_SLUG . '-common', $css_uri . 'common' . $file_prefix . '.css', [], SRFM_VER ); |
| 371 | 442 | wp_enqueue_style( SRFM_SLUG . '-reactQuill', $vendor_css_uri . 'quill/quill.snow.css', [], SRFM_VER ); |
| 372 | 443 | wp_enqueue_style( SRFM_SLUG . '-single-form-modal', $css_uri . 'single-form-setting' . $file_prefix . '.css', [], SRFM_VER ); |
| 444 | + | |
| 445 | + // if version is equal to or lower than 6.6.2 then add compatibility css. | |
| 446 | + if ( version_compare( $wp_version, '6.6.2', '<=' ) ) { | |
| 447 | + $srfm_inline_css = '.srfm-settings-modal .srfm-setting-modal-container .components-toggle-control .components-base-control__help{ | |
| 448 | + margin-left: 4em; | |
| 449 | + }'; | |
| 450 | + wp_add_inline_style( SRFM_SLUG . '-single-form-modal', $srfm_inline_css ); | |
| 451 | + } | |
| 373 | 452 | } |
| 374 | 453 | |
| 375 | 454 | wp_enqueue_style( SRFM_SLUG . '-form-selector', $css_uri . 'srfm-form-selector' . $file_prefix . '.css', [], SRFM_VER ); |
| 376 | 455 | wp_enqueue_style( SRFM_SLUG . '-common-editor', SRFM_URL . 'assets/build/common-editor.css', [], SRFM_VER, 'all' ); |
| @@ -385,9 +464,9 @@ | ||
| 385 | 464 | public function get_breadcrumbs_for_current_page() { |
| 386 | 465 | global $post, $pagenow; |
| 387 | 466 | $breadcrumbs = []; |
| 388 | 467 | |
| 389 | - if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 468 | + if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We don't need nonce verification here. | |
| 390 | 469 | $page_title = get_admin_page_title(); |
| 391 | 470 | $breadcrumbs[] = [ |
| 392 | 471 | 'title' => $page_title, |
| 393 | 472 | 'link' => '', |
| @@ -400,9 +479,9 @@ | ||
| 400 | 479 | 'title' => $post_type_plural, |
| 401 | 480 | 'link' => admin_url( 'edit.php?post_type=' . $post_type_obj->name ), |
| 402 | 481 | ]; |
| 403 | 482 | |
| 404 | - if ( 'edit.php' === $pagenow && ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 483 | + if ( 'edit.php' === $pagenow && ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We don't need nonce verification here. | |
| 405 | 484 | $breadcrumbs[ count( $breadcrumbs ) - 1 ]['link'] = ''; |
| 406 | 485 | } else { |
| 407 | 486 | $breadcrumbs[] = [ |
| 408 | 487 | /* Translators: Post Title. */ |
| @@ -417,13 +496,8 @@ | ||
| 417 | 496 | $breadcrumbs[] = [ |
| 418 | 497 | 'title' => 'Forms', |
| 419 | 498 | 'link' => '', |
| 420 | 499 | ]; |
| 421 | - } elseif ( $current_screen && 'sureforms_entry' === $current_screen->post_type ) { | |
| 422 | - $breadcrumbs[] = [ | |
| 423 | - 'title' => 'Entries', | |
| 424 | - 'link' => '', | |
| 425 | - ]; | |
| 426 | 500 | } else { |
| 427 | 501 | $breadcrumbs[] = [ |
| 428 | 502 | 'title' => '', |
| 429 | 503 | 'link' => '', |
| @@ -433,9 +507,8 @@ | ||
| 433 | 507 | |
| 434 | 508 | return $breadcrumbs; |
| 435 | 509 | } |
| 436 | 510 | |
| 437 | - | |
| 438 | 511 | /** |
| 439 | 512 | * Enqueue Admin Scripts. |
| 440 | 513 | * |
| 441 | 514 | * @return void |
| @@ -442,18 +515,21 @@ | ||
| 442 | 515 | * @since 0.0.1 |
| 443 | 516 | */ |
| 444 | 517 | public function enqueue_scripts() { |
| 445 | 518 | $current_screen = get_current_screen(); |
| 519 | + global $wp_version; | |
| 446 | 520 | |
| 447 | - $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min'; | |
| 448 | - $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; | |
| 449 | - $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/'; | |
| 450 | - $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/'; | |
| 521 | + $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min'; | |
| 522 | + $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; | |
| 523 | + $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/'; | |
| 524 | + $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/'; | |
| 525 | + $is_rtl = is_rtl(); | |
| 526 | + $rtl = $is_rtl ? '-rtl' : ''; | |
| 451 | 527 | |
| 452 | - /* RTL */ | |
| 453 | - if ( is_rtl() ) { | |
| 454 | - $file_prefix .= '-rtl'; | |
| 455 | - } | |
| 528 | + /** | |
| 529 | + * List of the handles in which we need to add translation compatibility. | |
| 530 | + */ | |
| 531 | + $script_translations_handlers = []; | |
| 456 | 532 | |
| 457 | 533 | $localization_data = [ |
| 458 | 534 | 'site_url' => get_site_url(), |
| 459 | 535 | 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(), |
| @@ -461,20 +537,31 @@ | ||
| 461 | 537 | 'plugin_version' => SRFM_VER, |
| 462 | 538 | 'global_settings_nonce' => current_user_can( 'manage_options' ) ? wp_create_nonce( 'wp_rest' ) : '', |
| 463 | 539 | 'is_pro_active' => defined( 'SRFM_PRO_VER' ), |
| 464 | 540 | 'pro_plugin_version' => defined( 'SRFM_PRO_VER' ) ? SRFM_PRO_VER : '', |
| 465 | - 'sureforms_pricing_page' => $this->get_sureforms_website_url( 'pricing' ), | |
| 541 | + 'pro_plugin_name' => defined( 'SRFM_PRO_VER' ) && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro', | |
| 542 | + 'sureforms_pricing_page' => Helper::get_sureforms_website_url( 'pricing' ), | |
| 466 | 543 | 'field_spacing_vars' => Helper::get_css_vars(), |
| 544 | + 'is_ver_lower_than_6_7' => version_compare( $wp_version, '6.6.2', '<=' ), | |
| 545 | + 'integrations' => Helper::sureforms_get_integration(), | |
| 546 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 547 | + 'sf_plugin_manager_nonce' => wp_create_nonce( 'sf_plugin_manager_nonce' ), | |
| 548 | + 'plugin_installer_nonce' => wp_create_nonce( 'updates' ), | |
| 549 | + 'plugin_activating_text' => __( 'Activating...', 'sureforms' ), | |
| 550 | + 'plugin_activated_text' => __( 'Activated', 'sureforms' ), | |
| 551 | + 'plugin_activate_text' => __( 'Activate', 'sureforms' ), | |
| 552 | + 'plugin_installing_text' => __( 'Installing...', 'sureforms' ), | |
| 553 | + 'plugin_installed_text' => __( 'Installed', 'sureforms' ), | |
| 554 | + 'is_rtl' => $is_rtl, | |
| 467 | 555 | ]; |
| 468 | 556 | |
| 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 | - } | |
| 557 | + $is_screen_sureforms_menu = Helper::validate_request_context( 'sureforms_menu', 'page' ); | |
| 558 | + $is_screen_add_new_form = Helper::validate_request_context( 'add-new-form', 'page' ); | |
| 559 | + $is_screen_sureforms_form_settings = Helper::validate_request_context( 'sureforms_form_settings', 'page' ); | |
| 560 | + $is_screen_sureforms_entries = Helper::validate_request_context( SRFM_ENTRIES, 'page' ); | |
| 561 | + $is_post_type_sureforms_form = SRFM_FORMS_POST_TYPE === $current_screen->post_type; | |
| 473 | 562 | |
| 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 | - ) { | |
| 563 | + 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 | 564 | $asset_handle = '-dashboard'; |
| 478 | 565 | |
| 479 | 566 | wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER ); |
| 480 | 567 | |
| @@ -488,9 +575,24 @@ | ||
| 488 | 575 | wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/dashboard.js', $script_info['dependencies'], SRFM_VER, true ); |
| 489 | 576 | |
| 490 | 577 | wp_localize_script( SRFM_SLUG . $asset_handle, 'scIcons', [ 'path' => SRFM_URL . 'assets/build/icon-assets' ] ); |
| 491 | 578 | |
| 492 | - $localization_data['security_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' ); | |
| 579 | + $script_translations_handlers[] = SRFM_SLUG . $asset_handle; | |
| 580 | + | |
| 581 | + if ( class_exists( 'SRFM_PRO\Admin\Licensing' ) ) { | |
| 582 | + $license_active = \SRFM_PRO\Admin\Licensing::is_license_active(); | |
| 583 | + $localization_data['is_license_active'] = $license_active; | |
| 584 | + | |
| 585 | + // Updating current licensing status. | |
| 586 | + $srfm_pro_license_status = get_option( 'srfm_pro_license_status', '' ); | |
| 587 | + $current_license_status = $license_active ? 'licensed' : 'unlicensed'; | |
| 588 | + if ( $current_license_status !== $srfm_pro_license_status ) { | |
| 589 | + update_option( 'srfm_pro_license_status', $current_license_status ); | |
| 590 | + } | |
| 591 | + } | |
| 592 | + | |
| 593 | + $localization_data['security_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' ); | |
| 594 | + $localization_data['integration_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=integration-settings' ); | |
| 493 | 595 | wp_localize_script( |
| 494 | 596 | SRFM_SLUG . $asset_handle, |
| 495 | 597 | SRFM_SLUG . '_admin', |
| 496 | 598 | apply_filters( |
| @@ -501,23 +603,64 @@ | ||
| 501 | 603 | wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' ); |
| 502 | 604 | |
| 503 | 605 | } |
| 504 | 606 | |
| 505 | - if ( 'sureforms_page_sureforms_form_settings' === $current_screen->id ) { | |
| 506 | - wp_enqueue_style( SRFM_SLUG . '-settings', $css_uri . 'backend/settings' . $file_prefix . '.css', [], SRFM_VER ); | |
| 607 | + if ( $is_screen_sureforms_form_settings ) { | |
| 608 | + wp_enqueue_style( SRFM_SLUG . '-settings', $css_uri . 'backend/settings' . $file_prefix . $rtl . '.css', [], SRFM_VER ); | |
| 507 | 609 | } |
| 508 | 610 | |
| 509 | 611 | // Enqueue styles for the entries page. |
| 510 | - if ( 'sureforms_page_sureforms_entries' === $current_screen->id ) { | |
| 612 | + if ( $is_screen_sureforms_entries ) { | |
| 511 | 613 | $asset_handle = '-entries'; |
| 512 | - wp_enqueue_style( SRFM_SLUG . $asset_handle, $css_uri . 'backend/entries' . $file_prefix . '.css', [], SRFM_VER ); | |
| 513 | 614 | wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/entries.js', $script_info['dependencies'], SRFM_VER, true ); |
| 615 | + | |
| 616 | + $script_translations_handlers[] = SRFM_SLUG . $asset_handle; | |
| 514 | 617 | } |
| 515 | 618 | |
| 619 | + // Enqueue scripts for the SureMail promotional page. | |
| 620 | + $is_screen_sureforms_smtp = Helper::validate_request_context( 'sureforms_smtp', 'page' ); | |
| 621 | + if ( $is_screen_sureforms_smtp ) { | |
| 622 | + $asset_handle = 'suremail'; | |
| 623 | + | |
| 624 | + $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; | |
| 625 | + $script_info = file_exists( $script_asset_path ) | |
| 626 | + ? include $script_asset_path | |
| 627 | + : [ | |
| 628 | + 'dependencies' => [], | |
| 629 | + 'version' => SRFM_VER, | |
| 630 | + ]; | |
| 631 | + | |
| 632 | + wp_enqueue_script( SRFM_SLUG . '-suremail', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); | |
| 633 | + wp_enqueue_style( SRFM_SLUG . '-suremail', SRFM_URL . 'assets/build/suremail.css', [], SRFM_VER, 'all' ); | |
| 634 | + | |
| 635 | + // Localize script for SureMail page. | |
| 636 | + $suremail_localization_data = [ | |
| 637 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 638 | + 'admin_url' => admin_url(), | |
| 639 | + 'suremail_url' => 'https://sureforms.com/suremail/', | |
| 640 | + 'plugin_installer_nonce' => wp_create_nonce( 'updates' ), | |
| 641 | + 'sfPluginManagerNonce' => wp_create_nonce( 'sf_plugin_manager_nonce' ), | |
| 642 | + 'suremail_status' => file_exists( WP_PLUGIN_DIR . '/suremails/suremails.php' ) | |
| 643 | + ? ( is_plugin_active( 'suremails/suremails.php' ) ? 'active' : 'installed' ) | |
| 644 | + : 'not_installed', | |
| 645 | + ]; | |
| 646 | + | |
| 647 | + wp_localize_script( | |
| 648 | + SRFM_SLUG . '-suremail', | |
| 649 | + SRFM_SLUG . '_admin', | |
| 650 | + apply_filters( | |
| 651 | + SRFM_SLUG . '_suremail_admin_filter', | |
| 652 | + $suremail_localization_data | |
| 653 | + ) | |
| 654 | + ); | |
| 655 | + | |
| 656 | + $script_translations_handlers[] = SRFM_SLUG . '-suremail'; | |
| 657 | + } | |
| 658 | + | |
| 516 | 659 | // Admin Submenu Styles. |
| 517 | - wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . '.css', [], SRFM_VER ); | |
| 660 | + wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . $rtl . '.css', [], SRFM_VER ); | |
| 518 | 661 | |
| 519 | - if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id || 'edit-' . SRFM_ENTRIES_POST_TYPE === $current_screen->id ) { | |
| 662 | + if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) { | |
| 520 | 663 | $asset_handle = 'page_header'; |
| 521 | 664 | |
| 522 | 665 | $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; |
| 523 | 666 | $script_info = file_exists( $script_asset_path ) |
| @@ -526,11 +669,14 @@ | ||
| 526 | 669 | 'dependencies' => [], |
| 527 | 670 | 'version' => SRFM_VER, |
| 528 | 671 | ]; |
| 529 | 672 | wp_enqueue_script( SRFM_SLUG . '-form-page-header', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); |
| 530 | - wp_enqueue_style( SRFM_SLUG . '-form-archive-styles', $css_uri . 'form-archive-styles' . $file_prefix . '.css', [], SRFM_VER ); | |
| 673 | + wp_enqueue_style( SRFM_SLUG . '-form-archive-styles', $css_uri . 'form-archive-styles' . $file_prefix . $rtl . '.css', [], SRFM_VER ); | |
| 674 | + | |
| 675 | + $script_translations_handlers[] = SRFM_SLUG . '-form-page-header'; | |
| 531 | 676 | } |
| 532 | - if ( 'sureforms_page_' . SRFM_FORMS_POST_TYPE . '_settings' === $current_screen->base ) { | |
| 677 | + | |
| 678 | + if ( $is_screen_sureforms_form_settings ) { | |
| 533 | 679 | $asset_handle = 'settings'; |
| 534 | 680 | |
| 535 | 681 | $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; |
| 536 | 682 | $script_info = file_exists( $script_asset_path ) |
| @@ -546,8 +692,10 @@ | ||
| 546 | 692 | SRFM_SLUG . '-settings', |
| 547 | 693 | SRFM_SLUG . '_admin', |
| 548 | 694 | $localization_data |
| 549 | 695 | ); |
| 696 | + | |
| 697 | + $script_translations_handlers[] = SRFM_SLUG . '-settings'; | |
| 550 | 698 | } |
| 551 | 699 | if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) { |
| 552 | 700 | wp_enqueue_script( SRFM_SLUG . '-form-archive', $js_uri . 'form-archive' . $file_prefix . '.js', [], SRFM_VER, true ); |
| 553 | 701 | wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [ 'wp-i18n' ], SRFM_VER, true ); |
| @@ -554,13 +702,13 @@ | ||
| 554 | 702 | wp_localize_script( |
| 555 | 703 | SRFM_SLUG . '-export', |
| 556 | 704 | SRFM_SLUG . '_export', |
| 557 | 705 | [ |
| 558 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 559 | - 'srfm_export_nonce' => wp_create_nonce( 'export_form_nonce' ), | |
| 560 | - 'site_url' => get_site_url(), | |
| 561 | - 'srfm_import_endpoint' => '/wp-json/sureforms/v1/sureforms_import', | |
| 562 | - 'import_form_nonce' => ( current_user_can( 'edit_posts' ) ) ? wp_create_nonce( 'wp_rest' ) : '', | |
| 706 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), | |
| 707 | + 'srfm_export_nonce' => wp_create_nonce( 'export_form_nonce' ), | |
| 708 | + 'site_url' => get_site_url(), | |
| 709 | + 'import_form_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '', | |
| 710 | + 'import_btn_string' => __( 'Import Form', 'sureforms' ), | |
| 563 | 711 | ] |
| 564 | 712 | ); |
| 565 | 713 | |
| 566 | 714 | wp_enqueue_script( SRFM_SLUG . '-backend', $js_uri . 'backend' . $file_prefix . '.js', [], SRFM_VER, true ); |
| @@ -571,24 +719,16 @@ | ||
| 571 | 719 | 'site_url' => get_site_url(), |
| 572 | 720 | ] |
| 573 | 721 | ); |
| 574 | 722 | |
| 723 | + $script_translations_handlers[] = SRFM_SLUG . '-form-archive'; | |
| 724 | + $script_translations_handlers[] = SRFM_SLUG . '-export'; | |
| 725 | + $script_translations_handlers[] = SRFM_SLUG . '-backend'; | |
| 575 | 726 | } |
| 576 | 727 | |
| 577 | - if ( 'sureforms_page_add-new-form' === $current_screen->id ) { | |
| 728 | + if ( $is_screen_add_new_form ) { | |
| 729 | + wp_enqueue_style( SRFM_SLUG . '-template-picker', $css_uri . 'template-picker' . $file_prefix . $rtl . '.css', [], SRFM_VER ); | |
| 578 | 730 | |
| 579 | - $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min'; | |
| 580 | - $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; | |
| 581 | - | |
| 582 | - $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/'; | |
| 583 | - | |
| 584 | - /* RTL */ | |
| 585 | - if ( is_rtl() ) { | |
| 586 | - $file_prefix .= '-rtl'; | |
| 587 | - } | |
| 588 | - | |
| 589 | - wp_enqueue_style( SRFM_SLUG . '-template-picker', $css_uri . 'template-picker' . $file_prefix . '.css', [], SRFM_VER ); | |
| 590 | - | |
| 591 | 731 | $sureforms_admin = 'templatePicker'; |
| 592 | 732 | |
| 593 | 733 | $script_asset_path = SRFM_DIR . 'assets/build/' . $sureforms_admin . '.asset.php'; |
| 594 | 734 | $script_info = file_exists( $script_asset_path ) |
| @@ -613,11 +753,13 @@ | ||
| 613 | 753 | 'is_pro_active' => defined( 'SRFM_PRO_VER' ), |
| 614 | 754 | 'srfm_ai_usage_details' => AI_Helper::get_current_usage_details(), |
| 615 | 755 | 'is_pro_license_active' => AI_Helper::is_pro_license_active(), |
| 616 | 756 | 'srfm_ai_auth_user_email' => get_option( 'srfm_ai_auth_user_email' ), |
| 617 | - 'pricing_page_url' => $this->get_sureforms_website_url( 'pricing' ), | |
| 757 | + 'pricing_page_url' => Helper::get_sureforms_website_url( 'pricing' ), | |
| 618 | 758 | ] |
| 619 | 759 | ); |
| 760 | + | |
| 761 | + $script_translations_handlers[] = SRFM_SLUG . '-template-picker'; | |
| 620 | 762 | } |
| 621 | 763 | // Quick action sidebar. |
| 622 | 764 | $default_allowed_quick_sidebar_blocks = apply_filters( |
| 623 | 765 | 'srfm_quick_sidebar_allowed_blocks', |
| @@ -653,29 +795,65 @@ | ||
| 653 | 795 | 'srfm_ajax_url' => admin_url( 'admin-ajax.php' ), |
| 654 | 796 | ] |
| 655 | 797 | ); |
| 656 | 798 | |
| 799 | + $script_translations_handlers[] = SRFM_SLUG . '-quick-action-siderbar'; | |
| 800 | + | |
| 657 | 801 | /** |
| 658 | 802 | * Enqueuing SureTriggers Integration script. |
| 659 | 803 | * This script loads suretriggers iframe in Intergations tab. |
| 660 | 804 | */ |
| 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 ); | |
| 805 | + if ( $is_post_type_sureforms_form ) { | |
| 806 | + wp_enqueue_script( SRFM_SLUG . '-suretriggers-integration', SRFM_SURETRIGGERS_INTEGRATION_BASE_URL . 'js/v2/embed.js', [], SRFM_VER, true ); | |
| 663 | 807 | } |
| 808 | + | |
| 809 | + // Check $script_translations_handlers is not empty before calling the function. | |
| 810 | + if ( ! empty( $script_translations_handlers ) ) { | |
| 811 | + // Remove duplicates values from the array. | |
| 812 | + $script_translations_handlers = array_unique( $script_translations_handlers ); | |
| 813 | + | |
| 814 | + foreach ( $script_translations_handlers as $script_handle ) { | |
| 815 | + Helper::register_script_translations( $script_handle ); | |
| 816 | + } | |
| 817 | + } | |
| 664 | 818 | } |
| 665 | 819 | |
| 666 | 820 | /** |
| 667 | 821 | * Form Template Picker Admin Body Classes |
| 822 | + * WordPress sometimes translates class names in the admin body tag, which can result in | |
| 823 | + * incorrect or missing class names when rendering the admin pages. This function ensures | |
| 824 | + * that essential class names are manually added to the body tag to maintain proper functionality. | |
| 668 | 825 | * |
| 669 | 826 | * @since 0.0.1 |
| 670 | 827 | * @param string $classes Space separated class string. |
| 671 | 828 | */ |
| 672 | 829 | 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 . ' '; | |
| 830 | + // Define an associative array of class names and their corresponding conditions. | |
| 831 | + // Each condition checks whether a specific request context matches. | |
| 832 | + $srfm_classes = [ | |
| 833 | + 'sureforms_page_sureforms_entries' => Helper::validate_request_context( SRFM_ENTRIES, 'page' ), | |
| 834 | + 'sureforms_page_sureforms_form_settings' => Helper::validate_request_context( 'sureforms_form_settings', 'page' ), | |
| 835 | + 'srfm-template-picker' => Helper::validate_request_context( 'add-new-form', 'page' ), | |
| 836 | + ]; | |
| 675 | 837 | |
| 838 | + $add_srfm_classes = ''; | |
| 839 | + | |
| 840 | + // Loop through the defined classes and conditions. | |
| 841 | + foreach ( $srfm_classes as $class => $condition ) { | |
| 842 | + // Check if the condition evaluates to true. | |
| 843 | + if ( $condition ) { | |
| 844 | + // Append the class to the existing classes string, followed by a space. | |
| 845 | + $add_srfm_classes .= empty( $add_srfm_classes ) ? $class : ' ' . $class; | |
| 846 | + } | |
| 847 | + } | |
| 848 | + | |
| 849 | + // Append the new classes to the existing classes string. | |
| 850 | + if ( ! empty( $add_srfm_classes ) ) { | |
| 851 | + $classes .= ' ' . $add_srfm_classes; | |
| 852 | + } | |
| 853 | + | |
| 854 | + // Return the updated list of classes. | |
| 676 | 855 | return $classes; |
| 677 | - | |
| 678 | 856 | } |
| 679 | 857 | |
| 680 | 858 | /** |
| 681 | 859 | * Disable spectra's quick action bar in sureforms CPT. |
| @@ -692,24 +870,8 @@ | ||
| 692 | 870 | |
| 693 | 871 | return $status; |
| 694 | 872 | } |
| 695 | 873 | |
| 696 | - /** | |
| 697 | - * Get SureForms Website URL. | |
| 698 | - * | |
| 699 | - * @param string $trail The URL trail to append to SureForms website URL. The parameter should not include a leading slash as the base URL already ends with a trailing slash. | |
| 700 | - * @since 0.0.7 | |
| 701 | - * @return string | |
| 702 | - */ | |
| 703 | - public static function get_sureforms_website_url( $trail ) { | |
| 704 | - $url = SRFM_WEBSITE; | |
| 705 | - if ( ! empty( $trail ) && is_string( $trail ) ) { | |
| 706 | - $url = SRFM_WEBSITE . $trail; | |
| 707 | - } | |
| 708 | - | |
| 709 | - return esc_url( $url ); | |
| 710 | - } | |
| 711 | - | |
| 712 | 874 | // Entries methods. |
| 713 | 875 | |
| 714 | 876 | /** |
| 715 | 877 | * Handle entry actions. |
| @@ -717,15 +879,13 @@ | ||
| 717 | 879 | * @since 0.0.13 |
| 718 | 880 | * @return void |
| 719 | 881 | */ |
| 720 | 882 | public function handle_entry_actions() { |
| 721 | - if ( isset( $_GET['entry'] ) && isset( $_GET['action'] ) ) { | |
| 722 | - Entries_List_Table::process_bulk_actions(); | |
| 883 | + Entries_List_Table::process_bulk_actions(); | |
| 884 | + | |
| 885 | + if ( ! isset( $_GET['page'] ) || SRFM_ENTRIES !== $_GET['page'] ) { | |
| 723 | 886 | return; |
| 724 | 887 | } |
| 725 | - if ( ! isset( $_GET['page'] ) || 'sureforms_entries' !== $_GET['page'] ) { | |
| 726 | - return; | |
| 727 | - } | |
| 728 | 888 | if ( ! isset( $_GET['entry_id'] ) || ! isset( $_GET['action'] ) ) { |
| 729 | 889 | return; |
| 730 | 890 | } |
| 731 | 891 | if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'srfm_entries_action' ) ) { |
| @@ -744,5 +904,91 @@ | ||
| 744 | 904 | Entries_List_Table::handle_entry_status( $entry_id, $action, $view ); |
| 745 | 905 | } |
| 746 | 906 | } |
| 747 | 907 | |
| 908 | + /** | |
| 909 | + * Admin Notice Callback if sureforms pro is out of date. | |
| 910 | + * | |
| 911 | + * Hooked - admin_notices | |
| 912 | + * | |
| 913 | + * @return void | |
| 914 | + * @since 1.0.4 | |
| 915 | + */ | |
| 916 | + public function srfm_pro_version_compatibility() { | |
| 917 | + $plugin_file = 'sureforms-pro/sureforms-pro.php'; | |
| 918 | + if ( ! is_plugin_active( $plugin_file ) || ! defined( 'SRFM_PRO_VER' ) ) { | |
| 919 | + return; | |
| 920 | + } | |
| 921 | + | |
| 922 | + if ( empty( get_current_screen() ) ) { | |
| 923 | + return; | |
| 924 | + } | |
| 925 | + | |
| 926 | + if ( ! current_user_can( 'update_plugins' ) ) { | |
| 927 | + return; | |
| 928 | + } | |
| 929 | + | |
| 930 | + $srfm_pro_license_status = get_option( 'srfm_pro_license_status', '' ); | |
| 931 | + /** | |
| 932 | + * If the license status is not set then get the license status and update the option accordingly. | |
| 933 | + * This will be executed only once. Subsequently, the option status is updated by the licensing class on license activation or deactivation. | |
| 934 | + */ | |
| 935 | + if ( empty( $srfm_pro_license_status ) && class_exists( 'SRFM_PRO\Admin\Licensing' ) ) { | |
| 936 | + $srfm_pro_license_status = \SRFM_PRO\Admin\Licensing::is_license_active() ? 'licensed' : 'unlicensed'; | |
| 937 | + update_option( 'srfm_pro_license_status', $srfm_pro_license_status ); | |
| 938 | + } | |
| 939 | + | |
| 940 | + $pro_plugin_name = defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro'; | |
| 941 | + $message = ''; | |
| 942 | + $url = admin_url( 'admin.php?page=sureforms_form_settings&tab=account-settings' ); | |
| 943 | + if ( 'unlicensed' === $srfm_pro_license_status ) { | |
| 944 | + $message = '<p>' . sprintf( | |
| 945 | + // translators: %1$s: Opening anchor tag with URL, %2$s: Closing anchor tag, %3$s: SureForms Pro Plugin Name. | |
| 946 | + esc_html__( 'Please %1$sactivate%2$s your copy of %3$s to get new features, access support, receive update notifications, and more.', 'sureforms' ), | |
| 947 | + '<a href="' . esc_url( $url ) . '">', | |
| 948 | + '</a>', | |
| 949 | + '<i>' . esc_html( $pro_plugin_name ) . '</i>' | |
| 950 | + ) . '</p>'; | |
| 951 | + } | |
| 952 | + | |
| 953 | + if ( ! version_compare( SRFM_PRO_VER, SRFM_PRO_RECOMMENDED_VER, '>=' ) ) { | |
| 954 | + $message .= '<p>' . sprintf( | |
| 955 | + // 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. | |
| 956 | + 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' ), | |
| 957 | + esc_html( SRFM_VER ), | |
| 958 | + esc_html( $pro_plugin_name ), | |
| 959 | + esc_html( SRFM_PRO_RECOMMENDED_VER ), | |
| 960 | + '<a href=' . esc_url( admin_url( 'update-core.php' ) ) . '>', | |
| 961 | + '</a>' | |
| 962 | + ) . '</p>'; | |
| 963 | + } | |
| 964 | + | |
| 965 | + if ( ! empty( $message ) ) { | |
| 966 | + // Phpcs ignore comment is required as $message variable is already escaped. | |
| 967 | + echo '<div class="notice notice-warning">' . wp_kses_post( $message ) . '</div>'; | |
| 968 | + } | |
| 969 | + } | |
| 970 | + | |
| 971 | + /** | |
| 972 | + * Disables the capabilities for WPForms to avoid conflicts when enqueueing | |
| 973 | + * scripts and styles for WPForms. | |
| 974 | + * | |
| 975 | + * This function is intended to prevent any potential conflicts that may arise | |
| 976 | + * when WPForms scripts and styles are enqueued. By disabling certain capabilities, | |
| 977 | + * it ensures that WPForms does not interfere with other functionalities. | |
| 978 | + * | |
| 979 | + * @param bool $user_can A boolean indicating whether the user has the capability. | |
| 980 | + * @return bool Returns true if the capabilities are successfully disabled, false otherwise. | |
| 981 | + * @since 1.4.2 | |
| 982 | + */ | |
| 983 | + public function disable_wpforms_capabilities( $user_can ) { | |
| 984 | + // Note: Nonce verification is intentionally omitted here as no database operations are performed. | |
| 985 | + // The values of the $_REQUEST variables are strictly validated, ensuring security without the need for nonce verification. | |
| 986 | + | |
| 987 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 988 | + $post_id = ! empty( $_REQUEST['post'] ) && ! empty( $_REQUEST['action'] ) ? absint( $_REQUEST['post'] ) : 0; | |
| 989 | + | |
| 990 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 991 | + $post_type = $post_id ? get_post_type( $post_id ) : sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ?? '' ) ); | |
| 992 | + return SRFM_FORMS_POST_TYPE === $post_type ? false : $user_can; | |
| 993 | + } | |
| 748 | 994 | } |