# Tutor LMS: Recent Course Completions Dashboard Widget

> Keeps a log of the latest Tutor LMS course completions and shows them in a dashboard widget with student names and dates.

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

## Code

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

add_action( 'tutor_course_complete_after', function ( $course_id, $user_id = 0 ) {
    $log = (array) get_option( 'wpide_tutor_completions', array() );
    array_unshift( $log, array( 'user' => $user_id ? (int) $user_id : get_current_user_id(), 'course' => (int) $course_id, 'time' => time() ) );
    update_option( 'wpide_tutor_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_tutor_completions', 'Recent course completions', function () {
        $log = array_filter( (array) get_option( 'wpide_tutor_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</span></li>',
                esc_html( $user ? $user->display_name : 'Deleted user' ),
                esc_html( get_the_title( $row['course'] ) ),
                esc_html( wp_date( get_option( 'date_format' ), (int) $row['time'] ) )
            );
        }
        echo '</ul>';
    } );
} );
```

## Notes

Keeps the 15 most recent completions, starting from activation.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Tutor LMS: Recent Course Completions Dashboard Widget" 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/
