| @@ -71,8 +71,15 @@ | ||
| 71 | 71 | add_filter( 'avf_use_block_editor_for_post', [ $this, 'enable_block_editor_in_enfold_theme' ] ); |
| 72 | 72 | |
| 73 | 73 | // Add action links to the plugin page. |
| 74 | 74 | add_filter( 'plugin_action_links_' . SRFM_BASENAME, [ $this, 'add_action_links' ] ); |
| 75 | + // Check if admin notification is enabled and add entries badge. | |
| 76 | + $general_options = get_option( 'srfm_general_settings_options', [] ); | |
| 77 | + $admin_notification_on = isset( $general_options['srfm_admin_notification'] ) ? (bool) $general_options['srfm_admin_notification'] : true; | |
| 78 | + | |
| 79 | + if ( $admin_notification_on ) { | |
| 80 | + add_action( 'admin_menu', [ $this, 'maybe_add_entries_badge' ], 99 ); | |
| 81 | + } | |
| 75 | 82 | add_filter( 'wpforms_current_user_can', [ $this, 'disable_wpforms_capabilities' ], 10, 3 ); |
| 76 | 83 | } |
| 77 | 84 | |
| 78 | 85 | /** |
| @@ -338,9 +345,9 @@ | ||
| 338 | 345 | 'add-new-form', |
| 339 | 346 | [ $this, 'add_new_form_callback' ], |
| 340 | 347 | 2 |
| 341 | 348 | ); |
| 342 | - add_submenu_page( | |
| 349 | + $entries_hook = add_submenu_page( | |
| 343 | 350 | 'sureforms_menu', |
| 344 | 351 | __( 'Entries', 'sureforms' ), |
| 345 | 352 | __( 'Entries', 'sureforms' ), |
| 346 | 353 | 'edit_others_posts', |
| @@ -347,8 +354,12 @@ | ||
| 347 | 354 | SRFM_ENTRIES, |
| 348 | 355 | [ $this, 'render_entries' ], |
| 349 | 356 | 3 |
| 350 | 357 | ); |
| 358 | + | |
| 359 | + if ( $entries_hook ) { | |
| 360 | + add_action( 'load-' . $entries_hook, [ $this, 'mark_entries_page_visit' ] ); | |
| 361 | + } | |
| 351 | 362 | } |
| 352 | 363 | |
| 353 | 364 | /** |
| 354 | 365 | * Add new form mentu item callback. |
| @@ -392,8 +403,72 @@ | ||
| 392 | 403 | echo '</div>'; |
| 393 | 404 | } |
| 394 | 405 | |
| 395 | 406 | /** |
| 407 | + * Add notification badge to SureForms menu when there are new entries. | |
| 408 | + * | |
| 409 | + * @since 1.7.3 | |
| 410 | + * @return void | |
| 411 | + */ | |
| 412 | + public function maybe_add_entries_badge() { | |
| 413 | + if ( ! current_user_can( 'edit_others_posts' ) ) { | |
| 414 | + return; | |
| 415 | + } | |
| 416 | + | |
| 417 | + // If currently viewing the entries listing page, mark it as visited and skip the badge. | |
| 418 | + if ( isset( $_GET['page'] ) && SRFM_ENTRIES === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only checking the page slug. | |
| 419 | + $this->mark_entries_page_visit(); | |
| 420 | + return; | |
| 421 | + } | |
| 422 | + | |
| 423 | + $srfm_options = get_option( 'srfm_options', [] ); | |
| 424 | + $last_visit = isset( $srfm_options['entries_last_visited'] ) ? absint( $srfm_options['entries_last_visited'] ) : 0; | |
| 425 | + $new_entries = Entries::get_entries_count_after( $last_visit ); | |
| 426 | + | |
| 427 | + if ( $new_entries <= 0 ) { | |
| 428 | + return; | |
| 429 | + } | |
| 430 | + | |
| 431 | + global $menu; | |
| 432 | + foreach ( $menu as $index => $item ) { | |
| 433 | + if ( isset( $item[2] ) && 'sureforms_menu' === $item[2] ) { | |
| 434 | + $menu[ $index ][0] .= sprintf( // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Adding notifications for menu item. | |
| 435 | + ' <span class="update-plugins count-%1$d"><span class="plugin-count">%1$d</span></span>', | |
| 436 | + absint( $new_entries ) | |
| 437 | + ); | |
| 438 | + break; | |
| 439 | + } | |
| 440 | + } | |
| 441 | + | |
| 442 | + global $submenu; | |
| 443 | + if ( isset( $submenu['sureforms_menu'] ) ) { | |
| 444 | + foreach ( $submenu['sureforms_menu'] as $index => $sub_item ) { | |
| 445 | + if ( isset( $sub_item[2] ) && SRFM_ENTRIES === $sub_item[2] ) { | |
| 446 | + $submenu['sureforms_menu'][ $index ][0] .= sprintf( // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Adding notifications for submenu item. | |
| 447 | + ' <span class="update-plugins count-%1$d"><span class="plugin-count">%1$d</span></span>', | |
| 448 | + absint( $new_entries ) | |
| 449 | + ); | |
| 450 | + break; | |
| 451 | + } | |
| 452 | + } | |
| 453 | + } | |
| 454 | + } | |
| 455 | + | |
| 456 | + /** | |
| 457 | + * Mark the user's visit to the entries page. | |
| 458 | + * | |
| 459 | + * @since 1.7.3 | |
| 460 | + * @return void | |
| 461 | + */ | |
| 462 | + public function mark_entries_page_visit() { | |
| 463 | + if ( current_user_can( 'edit_others_posts' ) ) { | |
| 464 | + $srfm_options = get_option( 'srfm_options', [] ); | |
| 465 | + $srfm_options['entries_last_visited'] = time(); | |
| 466 | + \SRFM\Inc\Helper::update_admin_settings_option( 'srfm_options', $srfm_options ); | |
| 467 | + } | |
| 468 | + } | |
| 469 | + | |
| 470 | + /** | |
| 396 | 471 | * Adds a settings link to the plugin action links on the plugins page. |
| 397 | 472 | * |
| 398 | 473 | * @param array $links An array of plugin action links. |
| 399 | 474 | * @param string $file The plugin file path. |
| @@ -686,9 +761,8 @@ | ||
| 686 | 761 | 'version' => SRFM_VER, |
| 687 | 762 | ]; |
| 688 | 763 | |
| 689 | 764 | 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 | 765 | wp_localize_script( |
| 692 | 766 | SRFM_SLUG . '-settings', |
| 693 | 767 | SRFM_SLUG . '_admin', |
| 694 | 768 | $localization_data |