# LifterLMS: Dashboard Widget Listing the Latest Graduates

> Keeps a short log of the latest LifterLMS course completions and shows it as a dashboard widget for admins and instructors.

- Type: PHP
- Runs: Run everywhere
- Category: [Courses & Community](https://wpide.com/library/category/learning/)
- Tags: lifterlms, dashboard, reporting
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/lifterlms-recent-completions-widget/

## Code

```php
if ( ! function_exists( 'llms_get_student' ) ) {
    return;
}

add_action( 'lifterlms_course_completed', function ( $user_id, $course_id ) {
    $log = (array) get_option( 'wpide_llms_completions', array() );
    array_unshift( $log, array( 'user' => (int) $user_id, 'course' => (int) $course_id, 'time' => time() ) );
    update_option( 'wpide_llms_completions', array_slice( $log, 0, 15 ), false );
}, 10, 2 );

add_action( 'wp_dashboard_setup', function () {
    if ( ! current_user_can( 'edit_posts' ) ) {
        return;
    }

    wp_add_dashboard_widget( 'wpide_llms_completions', 'Recent course completions', function () {
        $log = array_filter( (array) get_option( 'wpide_llms_completions', array() ), 'is_array' );

        if ( ! $log ) {
            echo '<p>No completions recorded yet.</p>';
            return;
        }

        echo '<ul>';

        foreach ( $log as $row ) {
            $user = get_userdata( $row['user'] );
            printf(
                '<li><strong>%1$s</strong> completed %2$s <span style="color:#646970">%3$s ago</span></li>',
                esc_html( $user ? $user->display_name : 'Deleted user' ),
                esc_html( get_the_title( $row['course'] ) ),
                esc_html( human_time_diff( (int) $row['time'] ) )
            );
        }

        echo '</ul>';
    } );
} );
```

## Notes

The log starts when you activate the snippet and holds the last 15 completions.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LifterLMS: Dashboard Widget Listing the Latest Graduates" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
