PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.0.3
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.0.3
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 +185 -34 0.0.21.0.3 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.
@@ -38,11 +43,37 @@
38 43 add_action( '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 +
50 + // Handle entry actions.
51 + add_action( 'admin_init', [ $this, 'handle_entry_actions' ] );
52 + add_action( 'admin_notices', [ Entries_List_Table::class, 'display_bulk_action_notice' ] );
42 53 }
43 54
44 55 /**
56 + * Enable Gutenberg for SureForms associated post types.
57 + *
58 + * @since 0.0.10
59 + */
60 + public function enable_gutenberg_for_sureforms() {
61 +
62 + // Check if the Classic Editor plugin is active and if it is set to replace the block editor.
63 + if ( ! class_exists( 'Classic_Editor' ) || 'block' === get_option( 'classic-editor-replace' ) ) {
64 + return;
65 + }
66 +
67 + $srfm_post_types = apply_filters( 'srfm_enable_gutenberg_post_types', [ SRFM_FORMS_POST_TYPE ] );
68 +
69 + if ( in_array( get_current_screen()->post_type, $srfm_post_types, true ) ) {
70 + add_filter( 'use_block_editor_for_post_type', '__return_true', 110 );
71 + add_filter( 'gutenberg_can_edit_post_type', '__return_true', 110 );
72 + }
73 + }
74 +
75 + /**
45 76 * Sureforms editor header styles.
46 77 *
47 78 * @since 0.0.1
48 79 */
@@ -82,9 +113,10 @@
82 113 __( 'SureForms', 'sureforms' ),
83 114 __( 'SureForms', 'sureforms' ),
84 115 'edit_others_posts',
85 116 $menu_slug,
86 - function () {},
117 + static function () {
118 + },
87 119 'data:image/svg+xml;base64,' . base64_encode( $logo ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
88 120 30
89 121 );
90 122
@@ -160,8 +192,17 @@
160 192 'add-new-form',
161 193 [ $this, 'add_new_form_callback' ],
162 194 2
163 195 );
196 + add_submenu_page(
197 + 'sureforms_menu',
198 + __( 'Entries', 'sureforms' ),
199 + __( 'Entries', 'sureforms' ),
200 + 'edit_others_posts',
201 + SRFM_ENTRIES,
202 + [ $this, 'render_entries' ],
203 + 3
204 + );
164 205 }
165 206
166 207 /**
167 208 * Add new form mentu item callback.
@@ -173,8 +214,40 @@
173 214 echo '<div id="srfm-add-new-form-container"></div>';
174 215 }
175 216
176 217 /**
218 + * Entries page callback.
219 + *
220 + * @since 0.0.13
221 + * @return void
222 + */
223 + public function render_entries() {
224 + // Render single entry view.
225 + // Adding the phpcs ignore nonce verification as no database operations are performed in this function, it is used to display the single entry view.
226 + if ( isset( $_GET['entry_id'] ) && is_numeric( $_GET['entry_id'] ) && isset( $_GET['view'] ) && 'details' === $_GET['view'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
227 + $single_entry_view = new Single_Entry();
228 + $single_entry_view->render();
229 + return;
230 + }
231 +
232 + // Render all entries view.
233 + $entries_table = new Entries_List_Table();
234 + $entries_table->prepare_items();
235 + echo '<div class="wrap"><h1 class="wp-heading-inline">Entries</h1>';
236 + if ( empty( $entries_table->all_entries_count ) && empty( $entries_table->trash_entries_count ) ) {
237 + $instance = Post_Types::get_instance();
238 + $instance->sureforms_render_blank_state( SRFM_ENTRIES );
239 + $instance->get_blank_state_styles();
240 + return;
241 + }
242 + echo '<form method="get">';
243 + echo '<input type="hidden" name="page" value="sureforms_entries">';
244 + $entries_table->display();
245 + echo '</form>';
246 + echo '</div>';
247 + }
248 +
249 + /**
177 250 * Adds a settings link to the plugin action links on the plugins page.
178 251 *
179 252 * @param array $links An array of plugin action links.
180 253 * @param string $file The plugin file path.
@@ -182,10 +255,15 @@
182 255 * @since 0.0.1
183 256 */
184 257 public function add_settings_link( $links, $file ) {
185 258 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 );
259 + $plugin_links = apply_filters(
260 + 'sureforms_plugin_action_links',
261 + [
262 + 'sureforms_settings' => '<a href="' . esc_url( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) ) . '">' . esc_html__( 'Settings', 'sureforms' ) . '</a>',
263 + ]
264 + );
265 + $links = array_merge( $plugin_links, $links );
188 266 }
189 267 return $links;
190 268 }
191 269
@@ -214,8 +292,9 @@
214 292 wp_enqueue_style( SRFM_SLUG . '-backend-blocks', $css_uri . 'blocks/default/backend' . $file_prefix . '.css', [], SRFM_VER );
215 293 wp_enqueue_style( SRFM_SLUG . '-intl', $vendor_css_uri . 'intl/intlTelInput-backend.min.css', [], SRFM_VER );
216 294 wp_enqueue_style( SRFM_SLUG . '-common', $css_uri . 'common' . $file_prefix . '.css', [], SRFM_VER );
217 295 wp_enqueue_style( SRFM_SLUG . '-reactQuill', $vendor_css_uri . 'quill/quill.snow.css', [], SRFM_VER );
296 + wp_enqueue_style( SRFM_SLUG . '-single-form-modal', $css_uri . 'single-form-setting' . $file_prefix . '.css', [], SRFM_VER );
218 297 }
219 298
220 299 wp_enqueue_style( SRFM_SLUG . '-form-selector', $css_uri . 'srfm-form-selector' . $file_prefix . '.css', [], SRFM_VER );
221 300 wp_enqueue_style( SRFM_SLUG . '-common-editor', SRFM_URL . 'assets/build/common-editor.css', [], SRFM_VER, 'all' );
@@ -262,13 +341,8 @@
262 341 $breadcrumbs[] = [
263 342 'title' => 'Forms',
264 343 'link' => '',
265 344 ];
266 - } elseif ( $current_screen && 'sureforms_entry' === $current_screen->post_type ) {
267 - $breadcrumbs[] = [
268 - 'title' => 'Entries',
269 - 'link' => '',
270 - ];
271 345 } else {
272 346 $breadcrumbs[] = [
273 347 'title' => '',
274 348 'link' => '',
@@ -278,9 +352,8 @@
278 352
279 353 return $breadcrumbs;
280 354 }
281 355
282 -
283 356 /**
284 357 * Enqueue Admin Scripts.
285 358 *
286 359 * @return void
@@ -298,11 +371,27 @@
298 371 if ( is_rtl() ) {
299 372 $file_prefix .= '-rtl';
300 373 }
301 374
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 - ) {
375 + $localization_data = [
376 + 'site_url' => get_site_url(),
377 + 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
378 + 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
379 + 'plugin_version' => SRFM_VER,
380 + 'global_settings_nonce' => current_user_can( 'manage_options' ) ? wp_create_nonce( 'wp_rest' ) : '',
381 + 'is_pro_active' => defined( 'SRFM_PRO_VER' ),
382 + 'pro_plugin_version' => defined( 'SRFM_PRO_VER' ) ? SRFM_PRO_VER : '',
383 + 'pro_plugin_name' => defined( 'SRFM_PRO_VER' ) && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro',
384 + 'sureforms_pricing_page' => $this->get_sureforms_website_url( 'pricing' ),
385 + 'field_spacing_vars' => Helper::get_css_vars(),
386 + ];
387 +
388 + if ( class_exists( 'SRFM_PRO\Admin\Licensing' ) ) {
389 + $license_active = \SRFM_PRO\Admin\Licensing::is_license_active();
390 + $localization_data['is_license_active'] = $license_active;
391 + }
392 +
393 + if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type || 'toplevel_page_sureforms_menu' === $current_screen->base || 'sureforms_page_sureforms_form_settings' === $current_screen->id || 'sureforms_page_' . SRFM_ENTRIES === $current_screen->id ) {
305 394 $asset_handle = '-dashboard';
306 395
307 396 wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER );
308 397
@@ -315,21 +404,16 @@
315 404 ];
316 405 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/dashboard.js', $script_info['dependencies'], SRFM_VER, true );
317 406
318 407 wp_localize_script( SRFM_SLUG . $asset_handle, 'scIcons', [ 'path' => SRFM_URL . 'assets/build/icon-assets' ] );
408 +
409 + $localization_data['security_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' );
319 410 wp_localize_script(
320 411 SRFM_SLUG . $asset_handle,
321 412 SRFM_SLUG . '_admin',
322 413 apply_filters(
323 414 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 - ]
415 + $localization_data
332 416 )
333 417 );
334 418 wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' );
335 419
@@ -338,13 +422,19 @@
338 422 if ( 'sureforms_page_sureforms_form_settings' === $current_screen->id ) {
339 423 wp_enqueue_style( SRFM_SLUG . '-settings', $css_uri . 'backend/settings' . $file_prefix . '.css', [], SRFM_VER );
340 424 }
341 425
426 + // Enqueue styles for the entries page.
427 + if ( 'sureforms_page_' . SRFM_ENTRIES === $current_screen->id ) {
428 + $asset_handle = '-entries';
429 + wp_enqueue_style( SRFM_SLUG . $asset_handle, $css_uri . 'backend/entries' . $file_prefix . '.css', [], SRFM_VER );
430 + wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/entries.js', $script_info['dependencies'], SRFM_VER, true );
431 + }
432 +
342 433 // Admin Submenu Styles.
343 434 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 435
346 - if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id || 'edit-' . SRFM_ENTRIES_POST_TYPE === $current_screen->id ) {
436 + if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) {
347 437 $asset_handle = 'page_header';
348 438
349 439 $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
350 440 $script_info = file_exists( $script_asset_path )
@@ -365,25 +455,20 @@
365 455 : [
366 456 'dependencies' => [],
367 457 'version' => SRFM_VER,
368 458 ];
459 +
369 460 wp_enqueue_script( SRFM_SLUG . '-settings', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
370 461 wp_enqueue_style( SRFM_SLUG . '-setting-styles', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [ 'wp-components' ], SRFM_VER, 'all' );
371 462 wp_localize_script(
372 463 SRFM_SLUG . '-settings',
373 464 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 - ]
465 + $localization_data
381 466 );
382 467 }
383 468 if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) {
384 469 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 );
470 + wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [ 'wp-i18n' ], SRFM_VER, true );
386 471 wp_localize_script(
387 472 SRFM_SLUG . '-export',
388 473 SRFM_SLUG . '_export',
389 474 [
@@ -390,9 +475,9 @@
390 475 'ajaxurl' => admin_url( 'admin-ajax.php' ),
391 476 'srfm_export_nonce' => wp_create_nonce( 'export_form_nonce' ),
392 477 'site_url' => get_site_url(),
393 478 'srfm_import_endpoint' => '/wp-json/sureforms/v1/sureforms_import',
394 - 'import_form_nonce' => ( current_user_can( 'edit_posts' ) ) ? wp_create_nonce( 'wp_rest' ) : '',
479 + 'import_form_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '',
395 480 ]
396 481 );
397 482
398 483 wp_enqueue_script( SRFM_SLUG . '-backend', $js_uri . 'backend' . $file_prefix . '.js', [], SRFM_VER, true );
@@ -442,8 +527,12 @@
442 527 'new_template_picker_base_url' => admin_url( 'post-new.php?post_type=sureforms_form' ),
443 528 'capability' => current_user_can( 'edit_posts' ),
444 529 'template_picker_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '',
445 530 'is_pro_active' => defined( 'SRFM_PRO_VER' ),
531 + 'srfm_ai_usage_details' => AI_Helper::get_current_usage_details(),
532 + 'is_pro_license_active' => AI_Helper::is_pro_license_active(),
533 + 'srfm_ai_auth_user_email' => get_option( 'srfm_ai_auth_user_email' ),
534 + 'pricing_page_url' => $this->get_sureforms_website_url( 'pricing' ),
446 535 ]
447 536 );
448 537 }
449 538 // Quick action sidebar.
@@ -452,10 +541,12 @@
452 541 [
453 542 'srfm/input',
454 543 'srfm/email',
455 544 'srfm/textarea',
545 + 'srfm/checkbox',
456 546 'srfm/number',
457 - 'srfm/address',
547 + 'srfm/inline-button',
548 + 'srfm/advanced-heading',
458 549 ]
459 550 );
460 551 if ( ! is_array( $default_allowed_quick_sidebar_blocks ) ) {
461 552 $default_allowed_quick_sidebar_blocks = [];
@@ -478,8 +569,16 @@
478 569 'srfm_ajax_nonce' => $srfm_ajax_nonce,
479 570 'srfm_ajax_url' => admin_url( 'admin-ajax.php' ),
480 571 ]
481 572 );
573 +
574 + /**
575 + * Enqueuing SureTriggers Integration script.
576 + * This script loads suretriggers iframe in Intergations tab.
577 + */
578 + if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type ) {
579 + wp_enqueue_script( SRFM_SLUG . '-suretriggers-integration', SRFM_SURETRIGGERS_INTEGRATION_BASE_URL . 'js/v2/embed.js', [], SRFM_VER, true );
580 + }
482 581 }
483 582
484 583 /**
485 584 * Form Template Picker Admin Body Classes
@@ -491,9 +590,8 @@
491 590 $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 591 $classes .= ' ' . $theme_builder_class . ' ';
493 592
494 593 return $classes;
495 -
496 594 }
497 595
498 596 /**
499 597 * Disable spectra's quick action bar in sureforms CPT.
@@ -509,5 +607,58 @@
509 607 }
510 608
511 609 return $status;
512 610 }
611 +
612 + /**
613 + * Get SureForms Website URL.
614 + *
615 + * @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.
616 + * @since 0.0.7
617 + * @return string
618 + */
619 + public static function get_sureforms_website_url( $trail ) {
620 + $url = SRFM_WEBSITE;
621 + if ( ! empty( $trail ) && is_string( $trail ) ) {
622 + $url = SRFM_WEBSITE . $trail;
623 + }
624 +
625 + return esc_url( $url );
626 + }
627 +
628 + // Entries methods.
629 +
630 + /**
631 + * Handle entry actions.
632 + *
633 + * @since 0.0.13
634 + * @return void
635 + */
636 + public function handle_entry_actions() {
637 + if ( isset( $_GET['entry'] ) && isset( $_GET['action'] ) ) {
638 + Entries_List_Table::process_bulk_actions();
639 + return;
640 + }
641 + if ( ! isset( $_GET['page'] ) || SRFM_ENTRIES !== $_GET['page'] ) {
642 + return;
643 + }
644 + if ( ! isset( $_GET['entry_id'] ) || ! isset( $_GET['action'] ) ) {
645 + return;
646 + }
647 + if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'srfm_entries_action' ) ) {
648 + wp_die( esc_html__( 'Nonce verification failed.', 'sureforms' ) );
649 + }
650 + $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
651 + $entry_id = Helper::get_integer_value( sanitize_text_field( wp_unslash( $_GET['entry_id'] ) ) );
652 + $view = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : '';
653 + if ( $entry_id > 0 ) {
654 + if ( 'read' === $action && 'details' === $view ) {
655 + $entry_status = Entries::get( $entry_id )['status'];
656 + if ( 'trash' === $entry_status ) {
657 + wp_die( esc_html__( 'You cannot view this entry because it is in trash.', 'sureforms' ) );
658 + }
659 + }
660 + Entries_List_Table::handle_entry_status( $entry_id, $action, $view );
661 + }
662 + }
663 +
513 664 }