bp_ps_learndash_get_users_for_course( int $course_id, array $query_args = array(), bool $exclude_admin = true )
Get all the users who are enrolled in the course.
Description
Parameters
- $course_id
-
(Required)
- $query_args
-
(Optional)
Default value: array()
- $exclude_admin
-
(Optional)
Default value: true
Return
(array|WP_User_Query)
Source
File: bp-core/profile-search/bps-xprofile.php
function bp_ps_learndash_get_users_for_course( $course_id = 0, $query_args = array(), $exclude_admin = true ) { $course_user_ids = array(); if ( empty( $course_id ) ) { return $course_user_ids; } $defaults = array( // By default WP_User_Query will return ALL users. Strange. 'fields' => 'ID', ); $query_args = wp_parse_args( $query_args, $defaults ); if ( $exclude_admin == true ) { $query_args['role__not_in'] = array( 'administrator' ); } $course_access_list = get_course_meta_setting( $course_id, 'course_access_list' ); $course_user_ids = array_merge( $course_user_ids, $course_access_list ); $course_access_users = get_course_users_access_from_meta( $course_id ); $course_user_ids = array_merge( $course_user_ids, $course_access_users ); $course_groups_users = get_course_groups_users_access( $course_id ); $course_user_ids = array_merge( $course_user_ids, $course_groups_users ); if ( ! empty( $course_user_ids ) ) { $course_user_ids = array_unique( $course_user_ids ); } $course_expired_access_users = get_course_expired_access_from_meta( $course_id ); if ( ! empty( $course_expired_access_users ) ) { $course_user_ids = array_diff( $course_access_list, $course_expired_access_users ); } if ( ! empty( $course_user_ids ) ) { $query_args['include'] = $course_user_ids; $user_query = new WP_User_Query( $query_args ); //$course_user_ids = $user_query->get_results(); return $user_query; } }
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.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.