admin.php
| 1 | <?php |
| 2 | /** |
| 3 | * Admin Class. |
| 4 | * |
| 5 | * @package sureforms. |
| 6 | */ |
| 7 | |
| 8 | namespace SRFM\Admin; |
| 9 | |
| 10 | use SRFM\Admin\Views\Entries_List_Table; |
| 11 | use SRFM\Admin\Views\Single_Entry; |
| 12 | use SRFM\Inc\AI_Form_Builder\AI_Helper; |
| 13 | use SRFM\Inc\Database\Tables\Entries; |
| 14 | use SRFM\Inc\Helper; |
| 15 | use SRFM\Inc\Post_Types; |
| 16 | use SRFM\Inc\Traits\Get_Instance; |
| 17 | |
| 18 | if ( ! defined( 'ABSPATH' ) ) { |
| 19 | exit; // Exit if accessed directly. |
| 20 | } |
| 21 | /** |
| 22 | * Admin handler class. |
| 23 | * |
| 24 | * @since 0.0.1 |
| 25 | */ |
| 26 | class Admin { |
| 27 | use Get_Instance; |
| 28 | |
| 29 | /** |
| 30 | * Class constructor. |
| 31 | * |
| 32 | * @return void |
| 33 | * @since 0.0.1 |
| 34 | */ |
| 35 | public function __construct() { |
| 36 | add_action( 'admin_menu', [ $this, 'add_menu_page' ], 9 ); |
| 37 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 38 | add_action( 'admin_menu', [ $this, 'settings_page' ] ); |
| 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 | |
| 46 | add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 10, 2 ); |
| 47 | add_action( 'enqueue_block_assets', [ $this, 'enqueue_styles' ] ); |
| 48 | add_action( 'admin_head', [ $this, 'enqueue_header_styles' ] ); |
| 49 | add_filter( 'admin_body_class', [ $this, 'admin_template_picker_body_class' ] ); |
| 50 | |
| 51 | // this action is used to restrict Spectra's quick action bar on SureForms CPTS. |
| 52 | add_action( 'uag_enable_quick_action_sidebar', [ $this, 'restrict_spectra_quick_action_bar' ] ); |
| 53 | |
| 54 | add_action( 'current_screen', [ $this, 'enable_gutenberg_for_sureforms' ], 100 ); |
| 55 | add_action( 'admin_notices', [ $this, 'srfm_pro_version_compatibility' ] ); |
| 56 | |
| 57 | // Handle entry actions. |
| 58 | add_action( 'admin_init', [ $this, 'handle_entry_actions' ] ); |
| 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 ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Show action on plugin page. |
| 80 | * |
| 81 | * @param array $links links. |
| 82 | * @return array |
| 83 | * @since 1.4.2 |
| 84 | */ |
| 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>'; |
| 95 | } |
| 96 | |
| 97 | return $links; |
| 98 | } |
| 99 | |
| 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; |
| 110 | } |
| 111 | return $use_block_editor; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Enable Gutenberg for SureForms associated post types. |
| 116 | * |
| 117 | * @since 0.0.10 |
| 118 | */ |
| 119 | public function enable_gutenberg_for_sureforms() { |
| 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' ) ) { |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | $srfm_post_types = apply_filters( 'srfm_enable_gutenberg_post_types', [ SRFM_FORMS_POST_TYPE ] ); |
| 128 | |
| 129 | if ( in_array( get_current_screen()->post_type, $srfm_post_types, true ) ) { |
| 130 | add_filter( 'use_block_editor_for_post_type', '__return_true', 110 ); |
| 131 | add_filter( 'gutenberg_can_edit_post_type', '__return_true', 110 ); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Sureforms editor header styles. |
| 137 | * |
| 138 | * @since 0.0.1 |
| 139 | */ |
| 140 | public function enqueue_header_styles() { |
| 141 | $current_screen = get_current_screen(); |
| 142 | $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min'; |
| 143 | $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; |
| 144 | |
| 145 | $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/'; |
| 146 | |
| 147 | /* RTL */ |
| 148 | if ( is_rtl() ) { |
| 149 | $file_prefix .= '-rtl'; |
| 150 | } |
| 151 | |
| 152 | if ( 'sureforms_form' === $current_screen->id ) { |
| 153 | wp_enqueue_style( SRFM_SLUG . '-editor-header-styles', $css_uri . 'header-styles' . $file_prefix . '.css', [], SRFM_VER ); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Add menu page. |
| 159 | * |
| 160 | * @return void |
| 161 | * @since 0.0.1 |
| 162 | */ |
| 163 | public function add_menu_page() { |
| 164 | if ( ! current_user_can( 'manage_options' ) ) { |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | $capability = 'manage_options'; |
| 169 | $menu_slug = 'sureforms_menu'; |
| 170 | |
| 171 | $logo = file_get_contents( plugin_dir_path( SRFM_FILE ) . 'images/icon.svg' ); |
| 172 | add_menu_page( |
| 173 | __( 'SureForms', 'sureforms' ), |
| 174 | __( 'SureForms', 'sureforms' ), |
| 175 | 'edit_others_posts', |
| 176 | $menu_slug, |
| 177 | static function () { |
| 178 | }, |
| 179 | 'data:image/svg+xml;base64,' . base64_encode( $logo ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode |
| 180 | 30 |
| 181 | ); |
| 182 | |
| 183 | // Add the Dashboard Submenu. |
| 184 | add_submenu_page( |
| 185 | $menu_slug, |
| 186 | __( 'Dashboard', 'sureforms' ), |
| 187 | __( 'Dashboard', 'sureforms' ), |
| 188 | $capability, |
| 189 | $menu_slug, |
| 190 | [ $this, 'render_dashboard' ] |
| 191 | ); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Add Settings page. |
| 196 | * |
| 197 | * @return void |
| 198 | * @since 0.0.1 |
| 199 | */ |
| 200 | public function settings_page() { |
| 201 | $callback = [ $this, 'settings_page_callback' ]; |
| 202 | add_submenu_page( |
| 203 | 'sureforms_menu', |
| 204 | __( 'Settings', 'sureforms' ), |
| 205 | __( 'Settings', 'sureforms' ), |
| 206 | 'edit_others_posts', |
| 207 | 'sureforms_form_settings', |
| 208 | $callback |
| 209 | ); |
| 210 | |
| 211 | // Get the current submenu page. |
| 212 | $submenu_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- $_GET['page'] does not provide nonce. |
| 213 | |
| 214 | if ( ! isset( $_GET['tab'] ) && 'sureforms_form_settings' === $submenu_page ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- $_GET['page'] does not provide nonce. |
| 215 | wp_safe_redirect( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) ); |
| 216 | exit; |
| 217 | } |
| 218 | } |
| 219 | |
| 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 | /** |
| 307 | * Render Admin Dashboard. |
| 308 | * |
| 309 | * @return void |
| 310 | * @since 0.0.1 |
| 311 | */ |
| 312 | public function render_dashboard() { |
| 313 | echo '<div id="srfm-dashboard-container" class="srfm-admin-wrapper"></div>'; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Settings page callback. |
| 318 | * |
| 319 | * @return void |
| 320 | * @since 0.0.1 |
| 321 | */ |
| 322 | public function settings_page_callback() { |
| 323 | echo '<div id="srfm-settings-container" class="srfm-admin-wrapper"></div>'; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Add new form menu item. |
| 328 | * |
| 329 | * @return void |
| 330 | * @since 0.0.1 |
| 331 | */ |
| 332 | public function add_new_form() { |
| 333 | add_submenu_page( |
| 334 | 'sureforms_menu', |
| 335 | __( 'New Form', 'sureforms' ), |
| 336 | __( 'New Form', 'sureforms' ), |
| 337 | 'edit_others_posts', |
| 338 | 'add-new-form', |
| 339 | [ $this, 'add_new_form_callback' ], |
| 340 | 2 |
| 341 | ); |
| 342 | add_submenu_page( |
| 343 | 'sureforms_menu', |
| 344 | __( 'Entries', 'sureforms' ), |
| 345 | __( 'Entries', 'sureforms' ), |
| 346 | 'edit_others_posts', |
| 347 | SRFM_ENTRIES, |
| 348 | [ $this, 'render_entries' ], |
| 349 | 3 |
| 350 | ); |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Add new form mentu item callback. |
| 355 | * |
| 356 | * @return void |
| 357 | * @since 0.0.1 |
| 358 | */ |
| 359 | public function add_new_form_callback() { |
| 360 | echo '<div id="srfm-add-new-form-container" class="srfm-admin-wrapper"></div>'; |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Entries page callback. |
| 365 | * |
| 366 | * @since 0.0.13 |
| 367 | * @return void |
| 368 | */ |
| 369 | public function render_entries() { |
| 370 | // Render single entry view. |
| 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. |
| 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. |
| 373 | $single_entry_view = new Single_Entry(); |
| 374 | $single_entry_view->render(); |
| 375 | return; |
| 376 | } |
| 377 | |
| 378 | // Render all entries view. |
| 379 | $entries_table = new Entries_List_Table(); |
| 380 | $entries_table->prepare_items(); |
| 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 ) ) { |
| 383 | $instance = Post_Types::get_instance(); |
| 384 | $instance->sureforms_render_blank_state( SRFM_ENTRIES ); |
| 385 | $instance->get_blank_state_styles(); |
| 386 | return; |
| 387 | } |
| 388 | echo '<form method="get">'; |
| 389 | echo '<input type="hidden" name="page" value="sureforms_entries">'; |
| 390 | $entries_table->display(); |
| 391 | echo '</form>'; |
| 392 | echo '</div>'; |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Adds a settings link to the plugin action links on the plugins page. |
| 397 | * |
| 398 | * @param array $links An array of plugin action links. |
| 399 | * @param string $file The plugin file path. |
| 400 | * @return array The updated array of plugin action links. |
| 401 | * @since 0.0.1 |
| 402 | */ |
| 403 | public function add_settings_link( $links, $file ) { |
| 404 | if ( 'sureforms/sureforms.php' === $file ) { |
| 405 | $plugin_links = apply_filters( |
| 406 | 'sureforms_plugin_action_links', |
| 407 | [ |
| 408 | 'sureforms_settings' => '<a href="' . esc_url( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) ) . '">' . esc_html__( 'Settings', 'sureforms' ) . '</a>', |
| 409 | ] |
| 410 | ); |
| 411 | $links = array_merge( $plugin_links, $links ); |
| 412 | } |
| 413 | return $links; |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Sureforms block editor styles. |
| 418 | * |
| 419 | * @since 0.0.1 |
| 420 | */ |
| 421 | public function enqueue_styles() { |
| 422 | $current_screen = get_current_screen(); |
| 423 | global $wp_version; |
| 424 | |
| 425 | $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min'; |
| 426 | $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified'; |
| 427 | |
| 428 | $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/'; |
| 429 | $vendor_css_uri = SRFM_URL . 'assets/css/minified/deps/'; |
| 430 | |
| 431 | /* RTL */ |
| 432 | if ( is_rtl() ) { |
| 433 | $file_prefix .= '-rtl'; |
| 434 | } |
| 435 | |
| 436 | // Enqueue editor styles for post and page. |
| 437 | if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type ) { |
| 438 | wp_enqueue_style( SRFM_SLUG . '-editor', $css_uri . 'backend/editor' . $file_prefix . '.css', [], SRFM_VER ); |
| 439 | wp_enqueue_style( SRFM_SLUG . '-backend-blocks', $css_uri . 'blocks/default/backend' . $file_prefix . '.css', [], SRFM_VER ); |
| 440 | wp_enqueue_style( SRFM_SLUG . '-intl', $vendor_css_uri . 'intl/intlTelInput-backend.min.css', [], SRFM_VER ); |
| 441 | wp_enqueue_style( SRFM_SLUG . '-common', $css_uri . 'common' . $file_prefix . '.css', [], SRFM_VER ); |
| 442 | wp_enqueue_style( SRFM_SLUG . '-reactQuill', $vendor_css_uri . 'quill/quill.snow.css', [], SRFM_VER ); |
| 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 | } |
| 452 | } |
| 453 | |
| 454 | wp_enqueue_style( SRFM_SLUG . '-form-selector', $css_uri . 'srfm-form-selector' . $file_prefix . '.css', [], SRFM_VER ); |
| 455 | wp_enqueue_style( SRFM_SLUG . '-common-editor', SRFM_URL . 'assets/build/common-editor.css', [], SRFM_VER, 'all' ); |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Get Breadcrumbs for current page. |
| 460 | * |
| 461 | * @since 0.0.1 |
| 462 | * @return array Breadcrumbs Array. |
| 463 | */ |
| 464 | public function get_breadcrumbs_for_current_page() { |
| 465 | global $post, $pagenow; |
| 466 | $breadcrumbs = []; |
| 467 | |
| 468 | if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We don't need nonce verification here. |
| 469 | $page_title = get_admin_page_title(); |
| 470 | $breadcrumbs[] = [ |
| 471 | 'title' => $page_title, |
| 472 | 'link' => '', |
| 473 | ]; |
| 474 | } elseif ( $post && in_array( $pagenow, [ 'post.php', 'post-new.php', 'edit.php' ], true ) ) { |
| 475 | $post_type_obj = get_post_type_object( get_post_type() ); |
| 476 | if ( $post_type_obj ) { |
| 477 | $post_type_plural = $post_type_obj->labels->name; |
| 478 | $breadcrumbs[] = [ |
| 479 | 'title' => $post_type_plural, |
| 480 | 'link' => admin_url( 'edit.php?post_type=' . $post_type_obj->name ), |
| 481 | ]; |
| 482 | |
| 483 | if ( 'edit.php' === $pagenow && ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We don't need nonce verification here. |
| 484 | $breadcrumbs[ count( $breadcrumbs ) - 1 ]['link'] = ''; |
| 485 | } else { |
| 486 | $breadcrumbs[] = [ |
| 487 | /* Translators: Post Title. */ |
| 488 | 'title' => sprintf( __( 'Edit %1$s', 'sureforms' ), get_the_title() ), |
| 489 | 'link' => get_edit_post_link( $post->ID ), |
| 490 | ]; |
| 491 | } |
| 492 | } |
| 493 | } else { |
| 494 | $current_screen = get_current_screen(); |
| 495 | if ( $current_screen && 'sureforms_form' === $current_screen->post_type ) { |
| 496 | $breadcrumbs[] = [ |
| 497 | 'title' => 'Forms', |
| 498 | 'link' => '', |
| 499 | ]; |
| 500 | } else { |
| 501 | $breadcrumbs[] = [ |
| 502 | 'title' => '', |
| 503 | 'link' => '', |
| 504 | ]; |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | return $breadcrumbs; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Enqueue Admin Scripts. |
| 513 | * |
| 514 | * @return void |
| 515 | * @since 0.0.1 |
| 516 | */ |
| 517 | public function enqueue_scripts() { |
| 518 | $current_screen = get_current_screen(); |
| 519 | global $wp_version; |
| 520 | |
| 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' : ''; |
| 527 | |
| 528 | /** |
| 529 | * List of the handles in which we need to add translation compatibility. |
| 530 | */ |
| 531 | $script_translations_handlers = []; |
| 532 | |
| 533 | $localization_data = [ |
| 534 | 'site_url' => get_site_url(), |
| 535 | 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(), |
| 536 | 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ), |
| 537 | 'plugin_version' => SRFM_VER, |
| 538 | 'global_settings_nonce' => current_user_can( 'manage_options' ) ? wp_create_nonce( 'wp_rest' ) : '', |
| 539 | 'is_pro_active' => defined( 'SRFM_PRO_VER' ), |
| 540 | 'pro_plugin_version' => defined( 'SRFM_PRO_VER' ) ? SRFM_PRO_VER : '', |
| 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' ), |
| 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, |
| 555 | ]; |
| 556 | |
| 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; |
| 562 | |
| 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 ) { |
| 564 | $asset_handle = '-dashboard'; |
| 565 | |
| 566 | wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER ); |
| 567 | |
| 568 | $script_asset_path = SRFM_DIR . 'assets/build/dashboard.asset.php'; |
| 569 | $script_info = file_exists( $script_asset_path ) |
| 570 | ? include $script_asset_path |
| 571 | : [ |
| 572 | 'dependencies' => [], |
| 573 | 'version' => SRFM_VER, |
| 574 | ]; |
| 575 | wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/dashboard.js', $script_info['dependencies'], SRFM_VER, true ); |
| 576 | |
| 577 | wp_localize_script( SRFM_SLUG . $asset_handle, 'scIcons', [ 'path' => SRFM_URL . 'assets/build/icon-assets' ] ); |
| 578 | |
| 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' ); |
| 595 | wp_localize_script( |
| 596 | SRFM_SLUG . $asset_handle, |
| 597 | SRFM_SLUG . '_admin', |
| 598 | apply_filters( |
| 599 | SRFM_SLUG . '_admin_filter', |
| 600 | $localization_data |
| 601 | ) |
| 602 | ); |
| 603 | wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' ); |
| 604 | |
| 605 | } |
| 606 | |
| 607 | if ( $is_screen_sureforms_form_settings ) { |
| 608 | wp_enqueue_style( SRFM_SLUG . '-settings', $css_uri . 'backend/settings' . $file_prefix . $rtl . '.css', [], SRFM_VER ); |
| 609 | } |
| 610 | |
| 611 | // Enqueue styles for the entries page. |
| 612 | if ( $is_screen_sureforms_entries ) { |
| 613 | $asset_handle = '-entries'; |
| 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; |
| 617 | } |
| 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 | |
| 659 | // Admin Submenu Styles. |
| 660 | wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . $rtl . '.css', [], SRFM_VER ); |
| 661 | |
| 662 | if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) { |
| 663 | $asset_handle = 'page_header'; |
| 664 | |
| 665 | $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; |
| 666 | $script_info = file_exists( $script_asset_path ) |
| 667 | ? include $script_asset_path |
| 668 | : [ |
| 669 | 'dependencies' => [], |
| 670 | 'version' => SRFM_VER, |
| 671 | ]; |
| 672 | wp_enqueue_script( SRFM_SLUG . '-form-page-header', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); |
| 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'; |
| 676 | } |
| 677 | |
| 678 | if ( $is_screen_sureforms_form_settings ) { |
| 679 | $asset_handle = 'settings'; |
| 680 | |
| 681 | $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php'; |
| 682 | $script_info = file_exists( $script_asset_path ) |
| 683 | ? include $script_asset_path |
| 684 | : [ |
| 685 | 'dependencies' => [], |
| 686 | 'version' => SRFM_VER, |
| 687 | ]; |
| 688 | |
| 689 | wp_enqueue_script( SRFM_SLUG . '-settings', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true ); |
| 690 | wp_enqueue_style( SRFM_SLUG . '-setting-styles', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [ 'wp-components' ], SRFM_VER, 'all' ); |
| 691 | wp_localize_script( |
| 692 | SRFM_SLUG . '-settings', |
| 693 | SRFM_SLUG . '_admin', |
| 694 | $localization_data |
| 695 | ); |
| 696 | |
| 697 | $script_translations_handlers[] = SRFM_SLUG . '-settings'; |
| 698 | } |
| 699 | if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) { |
| 700 | wp_enqueue_script( SRFM_SLUG . '-form-archive', $js_uri . 'form-archive' . $file_prefix . '.js', [], SRFM_VER, true ); |
| 701 | wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [ 'wp-i18n' ], SRFM_VER, true ); |
| 702 | wp_localize_script( |
| 703 | SRFM_SLUG . '-export', |
| 704 | SRFM_SLUG . '_export', |
| 705 | [ |
| 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' ), |
| 711 | ] |
| 712 | ); |
| 713 | |
| 714 | wp_enqueue_script( SRFM_SLUG . '-backend', $js_uri . 'backend' . $file_prefix . '.js', [], SRFM_VER, true ); |
| 715 | wp_localize_script( |
| 716 | SRFM_SLUG . '-backend', |
| 717 | SRFM_SLUG . '_backend', |
| 718 | [ |
| 719 | 'site_url' => get_site_url(), |
| 720 | ] |
| 721 | ); |
| 722 | |
| 723 | $script_translations_handlers[] = SRFM_SLUG . '-form-archive'; |
| 724 | $script_translations_handlers[] = SRFM_SLUG . '-export'; |
| 725 | $script_translations_handlers[] = SRFM_SLUG . '-backend'; |
| 726 | } |
| 727 | |
| 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 ); |
| 730 | |
| 731 | $sureforms_admin = 'templatePicker'; |
| 732 | |
| 733 | $script_asset_path = SRFM_DIR . 'assets/build/' . $sureforms_admin . '.asset.php'; |
| 734 | $script_info = file_exists( $script_asset_path ) |
| 735 | ? include $script_asset_path |
| 736 | : [ |
| 737 | 'dependencies' => [], |
| 738 | 'version' => SRFM_VER, |
| 739 | ]; |
| 740 | wp_enqueue_script( SRFM_SLUG . '-template-picker', SRFM_URL . 'assets/build/' . $sureforms_admin . '.js', $script_info['dependencies'], SRFM_VER, true ); |
| 741 | |
| 742 | wp_localize_script( |
| 743 | SRFM_SLUG . '-template-picker', |
| 744 | SRFM_SLUG . '_admin', |
| 745 | [ |
| 746 | 'site_url' => get_site_url(), |
| 747 | 'plugin_url' => SRFM_URL, |
| 748 | 'preview_images_url' => SRFM_URL . 'images/template-previews/', |
| 749 | 'admin_url' => admin_url( 'admin.php' ), |
| 750 | 'new_template_picker_base_url' => admin_url( 'post-new.php?post_type=sureforms_form' ), |
| 751 | 'capability' => current_user_can( 'edit_posts' ), |
| 752 | 'template_picker_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '', |
| 753 | 'is_pro_active' => defined( 'SRFM_PRO_VER' ), |
| 754 | 'srfm_ai_usage_details' => AI_Helper::get_current_usage_details(), |
| 755 | 'is_pro_license_active' => AI_Helper::is_pro_license_active(), |
| 756 | 'srfm_ai_auth_user_email' => get_option( 'srfm_ai_auth_user_email' ), |
| 757 | 'pricing_page_url' => Helper::get_sureforms_website_url( 'pricing' ), |
| 758 | ] |
| 759 | ); |
| 760 | |
| 761 | $script_translations_handlers[] = SRFM_SLUG . '-template-picker'; |
| 762 | } |
| 763 | // Quick action sidebar. |
| 764 | $default_allowed_quick_sidebar_blocks = apply_filters( |
| 765 | 'srfm_quick_sidebar_allowed_blocks', |
| 766 | [ |
| 767 | 'srfm/input', |
| 768 | 'srfm/email', |
| 769 | 'srfm/textarea', |
| 770 | 'srfm/checkbox', |
| 771 | 'srfm/number', |
| 772 | 'srfm/inline-button', |
| 773 | 'srfm/advanced-heading', |
| 774 | ] |
| 775 | ); |
| 776 | if ( ! is_array( $default_allowed_quick_sidebar_blocks ) ) { |
| 777 | $default_allowed_quick_sidebar_blocks = []; |
| 778 | } |
| 779 | |
| 780 | $srfm_enable_quick_action_sidebar = get_option( 'srfm_enable_quick_action_sidebar' ); |
| 781 | if ( ! $srfm_enable_quick_action_sidebar ) { |
| 782 | $srfm_enable_quick_action_sidebar = 'disabled'; |
| 783 | } |
| 784 | $quick_sidebar_allowed_blocks = get_option( 'srfm_quick_sidebar_allowed_blocks' ); |
| 785 | $quick_sidebar_allowed_blocks = ! empty( $quick_sidebar_allowed_blocks ) && is_array( $quick_sidebar_allowed_blocks ) ? $quick_sidebar_allowed_blocks : $default_allowed_quick_sidebar_blocks; |
| 786 | $srfm_ajax_nonce = wp_create_nonce( 'srfm_ajax_nonce' ); |
| 787 | wp_enqueue_script( SRFM_SLUG . '-quick-action-siderbar', SRFM_URL . 'assets/build/quickActionSidebar.js', [], SRFM_VER, true ); |
| 788 | wp_localize_script( |
| 789 | SRFM_SLUG . '-quick-action-siderbar', |
| 790 | SRFM_SLUG . '_quick_sidebar_blocks', |
| 791 | [ |
| 792 | 'allowed_blocks' => $quick_sidebar_allowed_blocks, |
| 793 | 'srfm_enable_quick_action_sidebar' => $srfm_enable_quick_action_sidebar, |
| 794 | 'srfm_ajax_nonce' => $srfm_ajax_nonce, |
| 795 | 'srfm_ajax_url' => admin_url( 'admin-ajax.php' ), |
| 796 | ] |
| 797 | ); |
| 798 | |
| 799 | $script_translations_handlers[] = SRFM_SLUG . '-quick-action-siderbar'; |
| 800 | |
| 801 | /** |
| 802 | * Enqueuing SureTriggers Integration script. |
| 803 | * This script loads suretriggers iframe in Intergations tab. |
| 804 | */ |
| 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 ); |
| 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 | } |
| 818 | } |
| 819 | |
| 820 | /** |
| 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. |
| 825 | * |
| 826 | * @since 0.0.1 |
| 827 | * @param string $classes Space separated class string. |
| 828 | */ |
| 829 | public function admin_template_picker_body_class( $classes = '' ) { |
| 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 | ]; |
| 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. |
| 855 | return $classes; |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * Disable spectra's quick action bar in sureforms CPT. |
| 860 | * |
| 861 | * @param string $status current status of the quick action bar. |
| 862 | * @since 0.0.2 |
| 863 | * @return string |
| 864 | */ |
| 865 | public function restrict_spectra_quick_action_bar( $status ) { |
| 866 | $screen = get_current_screen(); |
| 867 | if ( 'disabled' !== $status && isset( $screen->id ) && 'sureforms_form' === $screen->id ) { |
| 868 | $status = 'disabled'; |
| 869 | } |
| 870 | |
| 871 | return $status; |
| 872 | } |
| 873 | |
| 874 | // Entries methods. |
| 875 | |
| 876 | /** |
| 877 | * Handle entry actions. |
| 878 | * |
| 879 | * @since 0.0.13 |
| 880 | * @return void |
| 881 | */ |
| 882 | public function handle_entry_actions() { |
| 883 | Entries_List_Table::process_bulk_actions(); |
| 884 | |
| 885 | if ( ! isset( $_GET['page'] ) || SRFM_ENTRIES !== $_GET['page'] ) { |
| 886 | return; |
| 887 | } |
| 888 | if ( ! isset( $_GET['entry_id'] ) || ! isset( $_GET['action'] ) ) { |
| 889 | return; |
| 890 | } |
| 891 | if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'srfm_entries_action' ) ) { |
| 892 | wp_die( esc_html__( 'Nonce verification failed.', 'sureforms' ) ); |
| 893 | } |
| 894 | $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; |
| 895 | $entry_id = Helper::get_integer_value( sanitize_text_field( wp_unslash( $_GET['entry_id'] ) ) ); |
| 896 | $view = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : ''; |
| 897 | if ( $entry_id > 0 ) { |
| 898 | if ( 'read' === $action && 'details' === $view ) { |
| 899 | $entry_status = Entries::get( $entry_id )['status']; |
| 900 | if ( 'trash' === $entry_status ) { |
| 901 | wp_die( esc_html__( 'You cannot view this entry because it is in trash.', 'sureforms' ) ); |
| 902 | } |
| 903 | } |
| 904 | Entries_List_Table::handle_entry_status( $entry_id, $action, $view ); |
| 905 | } |
| 906 | } |
| 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 | } |
| 994 | } |
| 995 |