Skip to content
29 changes: 27 additions & 2 deletions classes/controllers/FrmAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
4 changes: 1 addition & 3 deletions classes/controllers/FrmDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
Expand Down
9 changes: 3 additions & 6 deletions classes/controllers/FrmEntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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';
}

/**
Expand Down
25 changes: 3 additions & 22 deletions classes/helpers/FrmEntriesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
10 changes: 2 additions & 8 deletions stripe/controllers/FrmTransLiteListsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down