BP_Notifications_Component::setup_nav( array $main_nav = array(), array $sub_nav = array() )

Set up component navigation.

Description

See also

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

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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

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.