PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.2.0
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.2.0
2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 All 96 releases
← All changes | admin/admin.php +346 -41 0.0.21.2.0 View file →
@@ -6,8 +6,14 @@
6 6 */
7 7
8 8 namespace SRFM\Admin;
9 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;
10 16 use SRFM\Inc\Traits\Get_Instance;
11 17
12 18 if ( ! defined( 'ABSPATH' ) ) {
13 19 exit; // Exit if accessed directly.
@@ -17,9 +23,8 @@
17 23 *
18 24 * @since 0.0.1
19 25 */
20 26 class Admin {
21 -
22 27 use Get_Instance;
23 28
24 29 /**
25 30 * Class constructor.
@@ -34,15 +39,42 @@
34 39 add_action( 'admin_menu', [ $this, 'add_new_form' ] );
35 40 add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 10, 2 );
36 41 add_action( 'enqueue_block_assets', [ $this, 'enqueue_styles' ] );
37 42 add_action( 'admin_head', [ $this, 'enqueue_header_styles' ] );
38 - add_action( 'admin_body_class', [ $this, 'admin_template_picker_body_class' ] );
43 + add_filter( 'admin_body_class', [ $this, 'admin_template_picker_body_class' ] );
39 44
40 45 // this action is used to restrict Spectra's quick action bar on SureForms CPTS.
41 46 add_action( 'uag_enable_quick_action_sidebar', [ $this, 'restrict_spectra_quick_action_bar' ] );
47 +
48 + add_action( 'current_screen', [ $this, 'enable_gutenberg_for_sureforms' ], 100 );
49 + add_action( 'admin_notices', [ $this, 'srfm_pro_version_compatibility' ] );
50 +
51 + // Handle entry actions.
52 + add_action( 'admin_init', [ $this, 'handle_entry_actions' ] );
53 + add_action( 'admin_notices', [ Entries_List_Table::class, 'display_bulk_action_notice' ] );
42 54 }
43 55
44 56 /**
57 + * Enable Gutenberg for SureForms associated post types.
58 + *
59 + * @since 0.0.10
60 + */
61 + public function enable_gutenberg_for_sureforms() {
62 +
63 + // Check if the Classic Editor plugin is active and if it is set to replace the block editor.
64 + if ( ! class_exists( 'Classic_Editor' ) || 'block' === get_option( 'classic-editor-replace' ) ) {
65 + return;
66 + }
67 +
68 + $srfm_post_types = apply_filters( 'srfm_enable_gutenberg_post_types', [ SRFM_FORMS_POST_TYPE ] );
69 +
70 + if ( in_array( get_current_screen()->post_type, $srfm_post_types, true ) ) {
71 + add_filter( 'use_block_editor_for_post_type', '__return_true', 110 );
72 + add_filter( 'gutenberg_can_edit_post_type', '__return_true', 110 );
73 + }
74 + }
75 +
76 + /**
45 77 * Sureforms editor header styles.
46 78 *
47 79 * @since 0.0.1
48 80 */
@@ -82,9 +114,10 @@
82 114 __( 'SureForms', 'sureforms' ),
83 115 __( 'SureForms', 'sureforms' ),
84 116 'edit_others_posts',
85 117 $menu_slug,
86 - function () {},
118 + static function () {
119 + },
87 120 'data:image/svg+xml;base64,' . base64_encode( $logo ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
88 121 30
89 122 );
90 123
@@ -160,8 +193,17 @@
160 193 'add-new-form',
161 194 [ $this, 'add_new_form_callback' ],
162 195 2
163 196 );
197 + add_submenu_page(
198 + 'sureforms_menu',
199 + __( 'Entries', 'sureforms' ),
200 + __( 'Entries', 'sureforms' ),
201 + 'edit_others_posts',
202 + SRFM_ENTRIES,
203 + [ $this, 'render_entries' ],
204 + 3
205 + );
164 206 }
165 207
166 208 /**
167 209 * Add new form mentu item callback.
@@ -173,8 +215,40 @@
173 215 echo '<div id="srfm-add-new-form-container"></div>';
174 216 }
175 217
176 218 /**
219 + * Entries page callback.
220 + *
221 + * @since 0.0.13
222 + * @return void
223 + */
224 + public function render_entries() {
225 + // Render single entry view.
226 + // Adding the phpcs ignore nonce verification as no database operations are performed in this function, it is used to display the single entry view.
227 + if ( isset( $_GET['entry_id'] ) && is_numeric( $_GET['entry_id'] ) && isset( $_GET['view'] ) && 'details' === $_GET['view'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
228 + $single_entry_view = new Single_Entry();
229 + $single_entry_view->render();
230 + return;
231 + }
232 +
233 + // Render all entries view.
234 + $entries_table = new Entries_List_Table();
235 + $entries_table->prepare_items();
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 ) ) {
238 + $instance = Post_Types::get_instance();
239 + $instance->sureforms_render_blank_state( SRFM_ENTRIES );
240 + $instance->get_blank_state_styles();
241 + return;
242 + }
243 + echo '<form method="get">';
244 + echo '<input type="hidden" name="page" value="sureforms_entries">';
245 + $entries_table->display();
246 + echo '</form>';
247 + echo '</div>';
248 + }
249 +
250 + /**
177 251 * Adds a settings link to the plugin action links on the plugins page.
178 252 *
179 253 * @param array $links An array of plugin action links.
180 254 * @param string $file The plugin file path.
@@ -182,10 +256,15 @@
182 256 * @since 0.0.1
183 257 */
184 258 public function add_settings_link( $links, $file ) {
185 259 if ( 'sureforms/sureforms.php' === $file ) {
186 - $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) ) . '">' . esc_html__( 'Settings', 'sureforms' ) . '</a>';
187 - array_push( $links, $settings_link );
260 + $plugin_links = apply_filters(
261 + 'sureforms_plugin_action_links',
262 + [
263 + 'sureforms_settings' => '<a href="' . esc_url( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) ) . '">' . esc_html__( 'Settings', 'sureforms' ) . '</a>',
264 + ]
265 + );
266 + $links = array_merge( $plugin_links, $links );
188 267 }
189 268 return $links;
190 269 }
191 270
@@ -195,8 +274,9 @@
195 274 * @since 0.0.1
196 275 */
197 276 public function enqueue_styles() {
198 277 $current_screen = get_current_screen();
278 + global $wp_version;
199 279
200 280 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
201 281 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
202 282
@@ -214,8 +294,17 @@
214 294 wp_enqueue_style( SRFM_SLUG . '-backend-blocks', $css_uri . 'blocks/default/backend' . $file_prefix . '.css', [], SRFM_VER );
215 295 wp_enqueue_style( SRFM_SLUG . '-intl', $vendor_css_uri . 'intl/intlTelInput-backend.min.css', [], SRFM_VER );
216 296 wp_enqueue_style( SRFM_SLUG . '-common', $css_uri . 'common' . $file_prefix . '.css', [], SRFM_VER );
217 297 wp_enqueue_style( SRFM_SLUG . '-reactQuill', $vendor_css_uri . 'quill/quill.snow.css', [], SRFM_VER );
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 + }
218 307 }
219 308
220 309 wp_enqueue_style( SRFM_SLUG . '-form-selector', $css_uri . 'srfm-form-selector' . $file_prefix . '.css', [], SRFM_VER );
221 310 wp_enqueue_style( SRFM_SLUG . '-common-editor', SRFM_URL . 'assets/build/common-editor.css', [], SRFM_VER, 'all' );
@@ -262,13 +351,8 @@
262 351 $breadcrumbs[] = [
263 352 'title' => 'Forms',
264 353 'link' => '',
265 354 ];
266 - } elseif ( $current_screen && 'sureforms_entry' === $current_screen->post_type ) {
267 - $breadcrumbs[] = [
268 - 'title' => 'Entries',
269 - 'link' => '',
270 - ];
271 355 } else {
272 356 $breadcrumbs[] = [
273 357 'title' => '',
274 358 'link' => '',
@@ -278,9 +362,8 @@
278 362
279 363 return $breadcrumbs;
280 364 }
281 365
282 -
283 366 /**
284 367 * Enqueue Admin Scripts.
285 368 *
286 369 * @return void
@@ -287,8 +370,9 @@
287 370 * @since 0.0.1
288 371 */
289 372 public function enqueue_scripts() {
290 373 $current_screen = get_current_screen();
374 + global $wp_version;
291 375
292 376 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
293 377 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
294 378 $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/';
@@ -293,16 +377,39 @@
293 377 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
294 378 $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/';
295 379 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
296 380
381 + /**
382 + * List of the handles in which we need to add translation compatibility.
383 + */
384 + $script_translations_handlers = [];
385 +
297 386 /* RTL */
298 387 if ( is_rtl() ) {
299 388 $file_prefix .= '-rtl';
300 389 }
301 390
302 - if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type || 'toplevel_page_sureforms_menu' === $current_screen->base || SRFM_ENTRIES_POST_TYPE === $current_screen->post_type
303 - || 'sureforms_page_sureforms_form_settings' === $current_screen->id
304 - ) {
391 + $localization_data = [
392 + 'site_url' => get_site_url(),
393 + 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
394 + 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
395 + 'plugin_version' => SRFM_VER,
396 + 'global_settings_nonce' => current_user_can( 'manage_options' ) ? wp_create_nonce( 'wp_rest' ) : '',
397 + 'is_pro_active' => defined( 'SRFM_PRO_VER' ),
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',
400 + 'sureforms_pricing_page' => $this->get_sureforms_website_url( 'pricing' ),
401 + 'field_spacing_vars' => Helper::get_css_vars(),
402 + 'is_ver_lower_than_6_7' => version_compare( $wp_version, '6.6.2', '<=' ),
403 + ];
404 +
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;
410 +
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 ) {
305 412 $asset_handle = '-dashboard';
306 413
307 414 wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER );
308 415
@@ -315,21 +422,31 @@
315 422 ];
316 423 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/dashboard.js', $script_info['dependencies'], SRFM_VER, true );
317 424
318 425 wp_localize_script( SRFM_SLUG . $asset_handle, 'scIcons', [ 'path' => SRFM_URL . 'assets/build/icon-assets' ] );
426 +
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' );
319 443 wp_localize_script(
320 444 SRFM_SLUG . $asset_handle,
321 445 SRFM_SLUG . '_admin',
322 446 apply_filters(
323 447 SRFM_SLUG . '_admin_filter',
324 - [
325 - 'site_url' => get_site_url(),
326 - 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
327 - 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
328 - 'plugin_version' => SRFM_VER,
329 - 'global_settings_nonce' => ( current_user_can( 'manage_options' ) ) ? wp_create_nonce( 'wp_rest' ) : '',
330 - 'security_settings_url' => admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' ),
331 - ]
448 + $localization_data
332 449 )
333 450 );
334 451 wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' );
335 452
@@ -334,17 +451,39 @@
334 451 wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' );
335 452
336 453 }
337 454
338 - if ( 'sureforms_page_sureforms_form_settings' === $current_screen->id ) {
455 + if ( $is_screen_sureforms_form_settings ) {
339 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 + }
340 471 }
341 472
473 + // Enqueue styles for the entries page.
474 + if ( $is_screen_sureforms_entries ) {
475 + $asset_handle = '-entries';
476 + wp_enqueue_style( SRFM_SLUG . $asset_handle, $css_uri . 'backend/entries' . $file_prefix . '.css', [], SRFM_VER );
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;
480 + }
481 +
342 482 // Admin Submenu Styles.
343 483 wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . '.css', [], SRFM_VER );
344 - wp_enqueue_style( SRFM_SLUG . '-single-form-modal', $css_uri . 'single-form-setting' . $file_prefix . '.css', [], SRFM_VER );
345 484
346 - 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 ) {
347 486 $asset_handle = 'page_header';
348 487
349 488 $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
350 489 $script_info = file_exists( $script_asset_path )
@@ -354,10 +493,13 @@
354 493 'version' => SRFM_VER,
355 494 ];
356 495 wp_enqueue_script( SRFM_SLUG . '-form-page-header', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
357 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';
358 499 }
359 - if ( 'sureforms_page_' . SRFM_FORMS_POST_TYPE . '_settings' === $current_screen->base ) {
500 +
501 + if ( $is_screen_sureforms_form_settings ) {
360 502 $asset_handle = 'settings';
361 503
362 504 $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
363 505 $script_info = file_exists( $script_asset_path )
@@ -365,25 +507,22 @@
365 507 : [
366 508 'dependencies' => [],
367 509 'version' => SRFM_VER,
368 510 ];
511 +
369 512 wp_enqueue_script( SRFM_SLUG . '-settings', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
370 513 wp_enqueue_style( SRFM_SLUG . '-setting-styles', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [ 'wp-components' ], SRFM_VER, 'all' );
371 514 wp_localize_script(
372 515 SRFM_SLUG . '-settings',
373 516 SRFM_SLUG . '_admin',
374 - [
375 - 'site_url' => get_site_url(),
376 - 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
377 - 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
378 - 'plugin_version' => SRFM_VER,
379 - 'global_settings_nonce' => current_user_can( 'manage_options' ) ? wp_create_nonce( 'wp_rest' ) : '',
380 - ]
517 + $localization_data
381 518 );
519 +
520 + $script_translations_handlers[] = SRFM_SLUG . '-settings';
382 521 }
383 522 if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) {
384 523 wp_enqueue_script( SRFM_SLUG . '-form-archive', $js_uri . 'form-archive' . $file_prefix . '.js', [], SRFM_VER, true );
385 - wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [], SRFM_VER, true );
524 + wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [ 'wp-i18n' ], SRFM_VER, true );
386 525 wp_localize_script(
387 526 SRFM_SLUG . '-export',
388 527 SRFM_SLUG . '_export',
389 528 [
@@ -390,9 +529,9 @@
390 529 'ajaxurl' => admin_url( 'admin-ajax.php' ),
391 530 'srfm_export_nonce' => wp_create_nonce( 'export_form_nonce' ),
392 531 'site_url' => get_site_url(),
393 532 'srfm_import_endpoint' => '/wp-json/sureforms/v1/sureforms_import',
394 - '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' ) : '',
395 534 ]
396 535 );
397 536
398 537 wp_enqueue_script( SRFM_SLUG . '-backend', $js_uri . 'backend' . $file_prefix . '.js', [], SRFM_VER, true );
@@ -403,12 +542,14 @@
403 542 'site_url' => get_site_url(),
404 543 ]
405 544 );
406 545
546 + $script_translations_handlers[] = SRFM_SLUG . '-form-archive';
547 + $script_translations_handlers[] = SRFM_SLUG . '-export';
548 + $script_translations_handlers[] = SRFM_SLUG . '-backend';
407 549 }
408 550
409 - if ( 'sureforms_page_add-new-form' === $current_screen->id ) {
410 -
551 + if ( $is_screen_add_new_form ) {
411 552 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
412 553 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
413 554
414 555 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
@@ -442,10 +583,16 @@
442 583 'new_template_picker_base_url' => admin_url( 'post-new.php?post_type=sureforms_form' ),
443 584 'capability' => current_user_can( 'edit_posts' ),
444 585 'template_picker_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '',
445 586 'is_pro_active' => defined( 'SRFM_PRO_VER' ),
587 + 'srfm_ai_usage_details' => AI_Helper::get_current_usage_details(),
588 + 'is_pro_license_active' => AI_Helper::is_pro_license_active(),
589 + 'srfm_ai_auth_user_email' => get_option( 'srfm_ai_auth_user_email' ),
590 + 'pricing_page_url' => $this->get_sureforms_website_url( 'pricing' ),
446 591 ]
447 592 );
593 +
594 + $script_translations_handlers[] = SRFM_SLUG . '-template-picker';
448 595 }
449 596 // Quick action sidebar.
450 597 $default_allowed_quick_sidebar_blocks = apply_filters(
451 598 'srfm_quick_sidebar_allowed_blocks',
@@ -452,10 +599,12 @@
452 599 [
453 600 'srfm/input',
454 601 'srfm/email',
455 602 'srfm/textarea',
603 + 'srfm/checkbox',
456 604 'srfm/number',
457 - 'srfm/address',
605 + 'srfm/inline-button',
606 + 'srfm/advanced-heading',
458 607 ]
459 608 );
460 609 if ( ! is_array( $default_allowed_quick_sidebar_blocks ) ) {
461 610 $default_allowed_quick_sidebar_blocks = [];
@@ -478,22 +627,66 @@
478 627 'srfm_ajax_nonce' => $srfm_ajax_nonce,
479 628 'srfm_ajax_url' => admin_url( 'admin-ajax.php' ),
480 629 ]
481 630 );
631 +
632 + $script_translations_handlers[] = SRFM_SLUG . '-quick-action-siderbar';
633 +
634 + /**
635 + * Enqueuing SureTriggers Integration script.
636 + * This script loads suretriggers iframe in Intergations tab.
637 + */
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 );
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 + }
482 651 }
483 652
484 653 /**
485 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.
486 658 *
487 659 * @since 0.0.1
488 660 * @param string $classes Space separated class string.
489 661 */
490 662 public function admin_template_picker_body_class( $classes = '' ) {
491 - $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.
492 - $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 + ];
493 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.
494 688 return $classes;
495 -
496 689 }
497 690
498 691 /**
499 692 * Disable spectra's quick action bar in sureforms CPT.
@@ -509,5 +702,117 @@
509 702 }
510 703
511 704 return $status;
512 705 }
706 +
707 + /**
708 + * Get SureForms Website URL.
709 + *
710 + * @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.
711 + * @since 0.0.7
712 + * @return string
713 + */
714 + public static function get_sureforms_website_url( $trail ) {
715 + $url = SRFM_WEBSITE;
716 + if ( ! empty( $trail ) && is_string( $trail ) ) {
717 + $url = SRFM_WEBSITE . $trail;
718 + }
719 +
720 + return esc_url( $url );
721 + }
722 +
723 + // Entries methods.
724 +
725 + /**
726 + * Handle entry actions.
727 + *
728 + * @since 0.0.13
729 + * @return void
730 + */
731 + public function handle_entry_actions() {
732 + Entries_List_Table::process_bulk_actions();
733 +
734 + if ( ! isset( $_GET['page'] ) || SRFM_ENTRIES !== $_GET['page'] ) {
735 + return;
736 + }
737 + if ( ! isset( $_GET['entry_id'] ) || ! isset( $_GET['action'] ) ) {
738 + return;
739 + }
740 + if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'srfm_entries_action' ) ) {
741 + wp_die( esc_html__( 'Nonce verification failed.', 'sureforms' ) );
742 + }
743 + $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
744 + $entry_id = Helper::get_integer_value( sanitize_text_field( wp_unslash( $_GET['entry_id'] ) ) );
745 + $view = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : '';
746 + if ( $entry_id > 0 ) {
747 + if ( 'read' === $action && 'details' === $view ) {
748 + $entry_status = Entries::get( $entry_id )['status'];
749 + if ( 'trash' === $entry_status ) {
750 + wp_die( esc_html__( 'You cannot view this entry because it is in trash.', 'sureforms' ) );
751 + }
752 + }
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.', 'sureforms' ),
806 + esc_html( SRFM_VER ),
807 + esc_html( $pro_plugin_name ),
808 + esc_html( SRFM_PRO_RECOMMENDED_VER ),
809 + ) . '</p>';
810 + }
811 +
812 + if ( ! empty( $message ) ) {
813 + // Phpcs ignore comment is required as $message variable is already escaped.
814 + echo '<div class="notice notice-warning">' . $message . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
815 + }
816 + }
817 +
513 818 }