Core::setup_nav()

Add Course tab in profile menu

Description

Source

File: bp-integrations/learndash/core/Core.php

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
public function setup_nav() {
    $this->course_name              = \LearnDash_Custom_Label::get_label( 'courses' );
    $this->my_courses_name          = sprintf( __( 'My %s', 'buddyboss' ), $this->course_name );
    $this->create_courses_name      = sprintf( __( 'Create a %s', 'buddyboss' ), $this->course_name );
    $this->create_courses_slug      = apply_filters( 'bp_learndash_profile_create_courses_slug', 'create-courses' );
    $this->course_slug              = apply_filters( 'bp_learndash_profile_courses_slug', \LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Section_Permalinks', 'courses' ) );
    $this->my_courses_slug          = apply_filters( 'bp_learndash_profile_courses_slug', 'my-courses' );
    $this->course_access            = bp_core_can_edit_settings();
    $this->certificates_enables     = bp_core_learndash_certificates_enables();
    $this->my_certificates_tab_name = apply_filters( 'bp_learndash_profile_certificates_tab_name', __( 'My Certificates', 'buddyboss' ) );
    $this->certificates_tab_name    = apply_filters( 'bp_learndash_profile_certificates_tab_name', __( 'Certificates', 'buddyboss' ) );
    $this->certificates_tab_slug    = apply_filters( 'bp_learndash_profile_certificates_slug', 'certificates' );
 
    $this->bp_displayed_user_id = bp_displayed_user_id();
    $this->bp_loggedin_user_id  = bp_loggedin_user_id();
    $this->user_same            = ( $this->bp_displayed_user_id == $this->bp_loggedin_user_id ? true : false );
 
    $atts         = apply_filters( 'bp_learndash_user_courses_atts', array() );
    $user_courses = apply_filters( 'bp_learndash_user_courses', ld_get_mycourses( $this->bp_displayed_user_id, $atts ) );
 
    $user_courses_count = is_array( $user_courses ) ? count( $user_courses ) : 0;
 
    // Only grab count if we're on a user page.
    if ( bp_is_user() ) {
        $class = ( 0 === $user_courses_count ) ? 'no-count' : 'count';
 
        $nav_name = sprintf(
        /* translators: %s: Group count for the current user */
            __( '%s %s', 'buddyboss' ),
            $this->course_name,
            sprintf(
                '<span class="%s">%s</span>',
                esc_attr( $class ),
                $user_courses_count
            )
        );
    } else {
        $nav_name = $this->course_name;
    }
 
    bp_core_new_nav_item( array(
        'name'                    => $nav_name,
        'slug'                    => $this->course_slug,
        'screen_function'         => array( $this, 'course_page' ),
        'position'                => 75,
        'default_subnav_slug'     => $this->my_courses_slug,
        'show_for_displayed_user' => $this->course_access,
    ) );
 
    $all_subnav_items = array(
        array(
            'name'            => empty( $this->user_same ) ? $this->course_name : $this->my_courses_name,
            'slug'            => $this->my_courses_slug,
            'parent_url'      => $this->get_nav_link( $this->course_slug ),
            'parent_slug'     => $this->course_slug,
            'screen_function' => array( $this, 'course_page' ),
            'position'        => 75,
            'user_has_access' => $this->course_access,
        ),
    );
 
    if ( $this->certificates_enables ) {
        $all_subnav_items[] = array(
            'name'            => empty( $this->user_same ) ? $this->certificates_tab_name : $this->my_certificates_tab_name,
            'slug'            => $this->certificates_tab_slug,
            'parent_url'      => $this->get_nav_link( $this->course_slug ),
            'parent_slug'     => $this->course_slug,
            'screen_function' => array( $this, 'certificates_page' ),
            'user_has_access' => $this->course_access,
        );
    }
 
    foreach ( $all_subnav_items as $all_subnav_item ) {
        bp_core_new_subnav_item( $all_subnav_item );
    }
 
}

Changelog

Changelog
Version Description
BuddyBoss 1.2.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.