Thank you. I wasn’t able to get it to work with the following code in child theme’s functions.php. It still shows the original sort order it had. Not sure what I missed.
//sort notifications order in main nav
function bp_sortnotifications_toolbar_menu() {
global $wp_admin_bar;
if ( ! is_user_logged_in() ) {
return false;
}
$notifications = bp_notifications_get_notifications_for_user( bp_loggedin_user_id(), 'object' );
$count = ! empty( $notifications ) ? count( $notifications ) : 0;
$alert_class = (int) $count > 0 ? 'pending-count alert' : 'count no-alert';
$menu_title = '<span id="ab-pending-notifications" class="' . $alert_class . '">' . number_format_i18n( $count ) . '</span>';
$menu_link = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() );
// Add the top-level Notifications button.
$wp_admin_bar->add_menu( array(
'parent' => 'top-secondary',
'id' => 'bp-notifications',
'title' => $menu_title,
'href' => $menu_link,
) );
if ( ! empty( $notifications ) ) {
foreach ( (array) $notifications as $notification ) {
$wp_admin_bar->add_menu( array(
'user_id' => 0,
'item_id' => 0,
'secondary_item_id' => 0,
'component_name' => '',
'component_action' => '',
'date_notified' => bp_core_current_time(),
'is_new' => 1,
'allow_duplicate' => false,
), 'notifications_add_notification' );;
// Check for existing duplicate notifications.
if ( ! $r['allow_duplicate'] ) {
// Date_notified, allow_duplicate don't count toward
// duplicate status.
$existing = BP_Notifications_Notification::get( array(
'user_id' => $r['user_id'],
'item_id' => $r['item_id'],
'secondary_item_id' => $r['secondary_item_id'],
'component_name' => $r['component_name'],
'component_action' => $r['component_action'],
'is_new' => $r['is_new'],
) );
if ( ! empty( $existing ) ) {
return false;
}
}
// Setup the new notification.
$notification = new BP_Notifications_Notification;
$notification->user_id = $r['user_id'];
$notification->item_id = $r['item_id'];
$notification->secondary_item_id = $r['secondary_item_id'];
$notification->component_name = $r['component_name'];
$notification->component_action = $r['component_action'];
$notification->date_notified = $r['date_notified'];
$notification->is_new = $r['is_new'];
// Save the new notification.
return $notification->save();
}
} else {
$wp_admin_bar->add_menu( array(
'parent' => 'bp-notifications',
'id' => 'no-notifications',
'title' => __( 'No new notifications', 'buddypress' ),
'href' => $menu_link,
) );
}
return;
}
add_action( 'admin_bar_menu', 'bp_members_admin_bar_notifications_menu', 90 );