Tutor LMS: Enrolled Student Count in the Courses Admin List
Adds a "Students" column to the Tutor LMS courses list in wp-admin showing how many students are enrolled in each course.
Opens WPIDE on
Code
if ( ! function_exists( 'tutor_utils' ) ) {
return;
}
add_filter( 'manage_courses_posts_columns', function ( $columns ) {
$columns['wpide_tutor_students'] = 'Students';
return $columns;
} );
add_action( 'manage_courses_posts_custom_column', function ( $column, $course_id ) {
if ( 'wpide_tutor_students' !== $column ) {
return;
}
$key = 'wpide_tutor_students_' . $course_id;
$count = get_transient( $key );
if ( false === $count ) {
$count = (int) tutor_utils()->count_enrolled_users_by_course( $course_id );
set_transient( $key, $count, 6 * HOUR_IN_SECONDS );
}
echo esc_html( number_format_i18n( (int) $count ) );
}, 10, 2 );
add_action( 'tutor_after_enrolled', function ( $course_id ) {
delete_transient( 'wpide_tutor_students_' . (int) $course_id );
} );
Notes
Counts are cached for 6 hours and refreshed when someone enrolls.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.