BP_Notifications_Component::setup_nav( array $main_nav = array(), array $sub_nav = array() )
Set up component navigation.
Description
See also
- BP_Component::setup_nav(): for a description of arguments.
Parameters
- $main_nav
-
(Optional) See BP_Component::setup_nav() for description.
Default value: array()
- $sub_nav
-
(Optional) See BP_Component::setup_nav() for description.
Default value: array()
Source
File: bp-notifications/classes/class-bp-notifications-component.php
public function setup_nav( $main_nav = array(), $sub_nav = array() ) { // Determine user to use. if ( bp_displayed_user_domain() ) { $user_domain = bp_displayed_user_domain(); } elseif ( bp_loggedin_user_domain() ) { $user_domain = bp_loggedin_user_domain(); } else { return; } $access = bp_core_can_edit_settings(); $slug = bp_get_notifications_slug(); $notifications_link = trailingslashit( $user_domain . $slug ); // Only grab count if we're on a user page and current user has access. if ( bp_is_user() && bp_user_has_access() ) { $count = bp_notifications_get_unread_notification_count( bp_displayed_user_id() ); $class = ( 0 === $count ) ? 'no-count' : 'count'; $nav_name = sprintf( /* translators: %s: Unread notification count for the current user */ __( 'Notifications %s', 'buddyboss' ), sprintf( '<span class="%s">%s</span>', esc_attr( $class ), bp_core_number_format( $count ) ) ); } else { $nav_name = __( 'Notifications', 'buddyboss' ); } // Add 'Notifications' to the main navigation. $main_nav = array( 'name' => $nav_name, 'slug' => $slug, 'position' => 30, 'show_for_displayed_user' => $access, 'screen_function' => 'bp_notifications_screen_unread', 'default_subnav_slug' => 'unread', 'item_css_id' => $this->id, ); // Add the subnav items to the notifications nav item. $sub_nav[] = array( 'name' => __( 'Unread', 'buddyboss' ), 'slug' => 'unread', 'parent_url' => $notifications_link, 'parent_slug' => $slug, 'screen_function' => 'bp_notifications_screen_unread', 'position' => 10, 'item_css_id' => 'notifications-my-notifications', 'user_has_access' => $access, ); $sub_nav[] = array( 'name' => __( 'Read', 'buddyboss' ), 'slug' => 'read', 'parent_url' => $notifications_link, 'parent_slug' => $slug, 'screen_function' => 'bp_notifications_screen_read', 'position' => 20, 'user_has_access' => $access, ); parent::setup_nav( $main_nav, $sub_nav ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.9.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.