Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Add course page that the user created
- add_action( 'bp_setup_nav', 'wbcom_learndash_profile_instructor' );
- function wbcom_learndash_profile_instructor() {
- // Don't set up navigation if there's no member.
- if ( ! is_user_logged_in() && ! bp_is_user() ) {
- return;
- }
- $disabled_user = get_userdata( bp_displayed_user_id() );
- $disabled_user_role = $disabled_user->roles;
- if( is_array( $disabled_user_role ) && ( in_array( 'ld_instructor', $disabled_user_role ) || in_array( 'administrator', $disabled_user_role ) ) ) {
- $create_courses_name = sprintf( 'My %s', \LearnDash_Custom_Label::get_label( 'courses' ) );
- $create_courses_slug = apply_filters( 'wbcom_learndash_profile_instructor_slug', 'courses' );
- $course_access = bp_core_can_edit_settings();
- $bp_displayed_user_id = bp_displayed_user_id();
- $bp_loggedin_user_id = bp_loggedin_user_id();
- $user_same = ( $bp_displayed_user_id == $bp_loggedin_user_id ? true : false );
- // Set slug to profile in case the xProfile component is not active
- $slug = bp_get_profile_slug();
- bp_core_new_nav_item(
- array(
- 'name' => $create_courses_name,
- 'slug' => $create_courses_slug,
- 'screen_function' => 'wbcom_learndash_instructor_course_page',
- 'position' => 76,
- 'default_subnav_slug' => $create_courses_name,
- 'show_for_displayed_user' => $course_access,
- )
- );
- }
- }
- function wbcom_learndash_instructor_course_page() {
- add_action( 'bp_template_content', 'wbcom_learndash_instructor_course_page_content' );
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
- }
- function wbcom_learndash_instructor_course_page_content() {
- $user_id = bp_displayed_user_id();
- $myCourse_args = array(
- 'post_type' => 'sfwd-courses',
- 'post_status' => 'publish',
- 'author' => $user_id,
- 'order' => 'DESC',
- 'orderby' => 'date',
- );
- $myCourses = new WP_Query( $myCourse_args );
- if( $myCourses->have_posts() ) {
- $view_to_render = isset( $_COOKIE['learnmate_course_view'] ) ? $_COOKIE['learnmate_course_view'] : 'lm-grid-view';
- echo '<div id="lm-course-archive-data" class="' . $view_to_render . '">';
- while( $myCourses->have_posts() ):
- $myCourses->the_post();
- learnmate_get_template( 'ld-template-parts/course-list-view.php' );
- endwhile;
- echo '</div>';
- echo '<div class="lm-course-pagination-section">';
- the_posts_pagination( array(
- 'prev_text' => __( '<i class="far fa-angle-double-left"></i>', 'reign-learndash-addon' ),
- 'next_text' => __( '<i class="far fa-angle-double-right"></i>', 'reign-learndash-addon' ),
- 'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'reign-learndash-addon' ) . ' </span>',
- ) );
- echo '</div>';
- } else {
- get_template_part( 'template-parts/content', 'none' );
- }
- wp_reset_postdata();
- }
- // Remove default course tab form profile for instructor and admin
- function wbcom_learndash_remove_course_nav() {
- $disabled_user = get_userdata( bp_displayed_user_id() );
- $disabled_user_role = $disabled_user->roles;
- if( is_array( $disabled_user_role ) && ( in_array( 'ld_instructor', $disabled_user_role ) || in_array( 'administrator', $disabled_user_role ) ) ) {
- bp_core_remove_nav_item( 'rla-courses', 'members' );
- }
- }
- add_action( 'wp', 'wbcom_learndash_remove_course_nav' );
Add Comment
Please, Sign In to add comment