diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index 033306435a..598e61106c 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -17,11 +17,36 @@ public static function menu() { $menu_name = FrmAppHelper::get_menu_name(); + add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() ); + + // Add the badge after `add_menu_page` to keep WP screen IDs stable they use `sanitize_title( $menu_title )`. if ( in_array( $menu_name, array( 'Formidable', 'Forms' ), true ) ) { - $menu_name .= wp_kses_post( FrmInboxController::get_notice_count() ); + self::add_menu_badge(); } + } - add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() ); + /** + * Add the inbox count badge to the Formidable menu. + * + * @since x.x + * + * @return void + */ + public static function add_menu_badge() { + global $menu; + + $badge = wp_kses_post( FrmInboxController::get_notice_count() ); + + if ( ! $badge ) { + return; + } + + $menu_item = wp_list_filter( $menu, array( 2 => 'formidable' ) ); + + if ( $menu_item ) { + // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Standard pattern for adding menu badges. + $menu[ key( $menu_item ) ][0] .= $badge; + } } /** diff --git a/classes/controllers/FrmDashboardController.php b/classes/controllers/FrmDashboardController.php index 3c269f38ff..a7dd837e15 100644 --- a/classes/controllers/FrmDashboardController.php +++ b/classes/controllers/FrmDashboardController.php @@ -44,9 +44,7 @@ public static function load_page() { self::remove_admin_notices_on_dashboard(); self::load_assets(); - $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count(); - - add_filter( 'manage_' . sanitize_title( FrmAppHelper::get_menu_name() ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-dashboard_columns', 'FrmDashboardController::entries_columns' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong + add_filter( 'manage_' . sanitize_title( FrmAppHelper::get_menu_name() ) . '_page_formidable-dashboard_columns', 'FrmDashboardController::entries_columns' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong add_filter( 'frm_show_footer_links', '__return_false' ); add_filter( 'screen_options_show_screen', '__return_false' ); } diff --git a/classes/controllers/FrmEntriesController.php b/classes/controllers/FrmEntriesController.php index fc2ed5297a..41f82085a1 100644 --- a/classes/controllers/FrmEntriesController.php +++ b/classes/controllers/FrmEntriesController.php @@ -150,10 +150,9 @@ public static function route() { * @return bool */ public static function remove_screen_options( $show_screen, $screen ) { - $menu_name = sanitize_title( FrmAppHelper::get_menu_name() ); - $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count(); + $menu_name = sanitize_title( FrmAppHelper::get_menu_name() ); - if ( $screen->id === $menu_name . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries' ) { + if ( $screen->id === $menu_name . '_page_formidable-entries' ) { $show_screen = false; } @@ -440,9 +439,7 @@ private static function base_column_key( $menu_name = '' ) { $menu_name = FrmAppHelper::get_menu_name(); } - $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count(); - - return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries'; + return sanitize_title( $menu_name ) . '_page_formidable-entries'; } /** diff --git a/classes/helpers/FrmEntriesHelper.php b/classes/helpers/FrmEntriesHelper.php index 082bdef5ee..c54c821579 100644 --- a/classes/helpers/FrmEntriesHelper.php +++ b/classes/helpers/FrmEntriesHelper.php @@ -947,31 +947,12 @@ public static function get_entry_statuses() { /** * @since 6.17 + * @deprecated x.x * * @return int */ public static function get_visible_unread_inbox_count() { - $menu_name = FrmAppHelper::get_menu_name(); - - if ( ! in_array( $menu_name, array( 'Formidable', 'Forms' ), true ) ) { - return 0; - } - - $inbox = new FrmInbox(); - $inbox_count = count( $inbox->unread() ); - - if ( ! $inbox_count ) { - return 0; - } - - if ( is_callable( 'FrmProSettingsController::inbox_badge' ) ) { - $inbox_count = FrmProSettingsController::inbox_badge( $inbox_count ); - - if ( ! $inbox_count ) { - return 0; - } - } - - return $inbox_count; + _deprecated_function( __METHOD__, 'x.x' ); + return 0; } } diff --git a/stripe/controllers/FrmTransLiteListsController.php b/stripe/controllers/FrmTransLiteListsController.php index f4022d8b0f..b71dcccd17 100755 --- a/stripe/controllers/FrmTransLiteListsController.php +++ b/stripe/controllers/FrmTransLiteListsController.php @@ -9,8 +9,7 @@ class FrmTransLiteListsController { * @return void */ public static function add_list_hooks() { - $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count(); - $hook_name = 'manage_' . sanitize_title( FrmAppHelper::get_menu_name() ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-payments_columns'; + $hook_name = 'manage_' . sanitize_title( FrmAppHelper::get_menu_name() ) . '_page_formidable-payments_columns'; add_filter( $hook_name, self::class . '::payment_columns' ); add_filter( 'screen_options_show_screen', self::class . '::remove_screen_options', 10, 2 ); @@ -92,12 +91,7 @@ public static function remove_screen_options( $show_screen, $screen ) { return $show_screen; } - $menu_name = sanitize_title( FrmAppHelper::get_menu_name() ); - $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count(); - - if ( $unread_count ) { - $menu_name .= '-' . $unread_count; - } + $menu_name = sanitize_title( FrmAppHelper::get_menu_name() ); if ( $screen->id === $menu_name . '_page_formidable-payments' ) { $show_screen = false;