LifterLMS: Students Column on the Courses Screen
Adds a "Students" column to the LifterLMS Courses list showing how many students are currently enrolled, cached for speed.
Opens WPIDE on
Code
if ( ! function_exists( 'llms_get_enrolled_students' ) ) {
return;
}
add_filter( 'manage_course_posts_columns', function ( $columns ) {
$columns['wpide_llms_students'] = 'Students';
return $columns;
} );
add_action( 'manage_course_posts_custom_column', function ( $column, $course_id ) {
if ( 'wpide_llms_students' !== $column ) {
return;
}
$key = 'wpide_llms_students_' . $course_id;
$count = get_transient( $key );
if ( false === $count ) {
$count = count( (array) llms_get_enrolled_students( $course_id, 'enrolled', 10000, 0 ) );
set_transient( $key, $count, 6 * HOUR_IN_SECONDS );
}
echo esc_html( number_format_i18n( (int) $count ) );
}, 10, 2 );
$wpide_llms_flush_students = function ( $user_id, $course_id ) {
delete_transient( 'wpide_llms_students_' . (int) $course_id );
};
add_action( 'llms_user_enrolled_in_course', $wpide_llms_flush_students, 10, 2 );
add_action( 'llms_user_removed_from_course', $wpide_llms_flush_students, 10, 2 );
Notes
Counts refresh every 6 hours and whenever someone enrolls or is removed.
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.