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

Set up navigation for user pages.

Description

Parameters

$main_nav

(Optional) See {BP_Component::setup_nav()} for details.

Default value: array()

$sub_nav

(Optional) See {BP_Component::setup_nav()} for details.

Default value: array()

Source

File: bp-messages/classes/class-bp-messages-component.php

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
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_messages_slug();
    $messages_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_get_total_unread_messages_count( bp_displayed_user_id() );
        $class    = ( 0 === $count ) ? 'no-count' : 'count';
        $nav_name = sprintf(
            /* translators: %s: Unread message count for the current user */
            __( 'Messages %s', 'buddyboss' ),
            sprintf(
                '<span class="%s">%s</span>',
                esc_attr( $class ),
                bp_core_number_format( $count )
            )
        );
    } else {
        $nav_name = __( 'Messages', 'buddyboss' );
    }
 
    // Add 'Messages' to the main navigation.
    $main_nav = array(
        'name'                    => $nav_name,
        'slug'                    => $slug,
        'position'                => 50,
        'show_for_displayed_user' => $access,
        'screen_function'         => 'messages_screen_inbox',
        'default_subnav_slug'     => 'inbox',
        'item_css_id'             => $this->id
    );
 
    // Add the subnav items to the profile.
    $sub_nav[] = array(
        'name'            => __( 'Messages', 'buddyboss' ),
        'slug'            => 'inbox',
        'parent_url'      => $messages_link,
        'parent_slug'     => $slug,
        'screen_function' => 'messages_screen_inbox',
        'position'        => 10,
        'user_has_access' => $access
    );
 
    // Show certain screens only if the current user is the displayed user.
    if ( bp_is_my_profile() ) {
 
        // Show "Compose" on the logged-in user's profile only.
        $sub_nav[] = array(
            'name'            => __( 'New Message', 'buddyboss' ),
            'slug'            => 'compose',
            'parent_url'      => $messages_link,
            'parent_slug'     => $slug,
            'screen_function' => 'messages_screen_compose',
            'position'        => 30,
            'user_has_access' => $access
        );
 
        /*
         * Show "Notices" on the logged-in user's profile only
         * and then only if the user can create notices.
         */
        if ( bp_current_user_can( 'bp_moderate' ) ) {
            $sub_nav[] = array(
                'name'            => __( 'Notices', 'buddyboss' ),
                'slug'            => 'notices',
                'parent_url'      => $messages_link,
                'parent_slug'     => $slug,
                'screen_function' => 'messages_screen_notices',
                'position'        => 90,
                'user_has_access' => true
            );
        }
    }
 
    parent::setup_nav( $main_nav, $sub_nav );
}

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.