# LearnDash: Recent Course Completions Dashboard Widget

> Keeps a short log of the latest course completions and shows it in a dashboard widget with student names, courses and how long ago.

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

## Code

```php
if ( ! defined( 'LEARNDASH_VERSION' ) ) {
    return;
}

add_action( 'learndash_course_completed', function ( $data ) {
    if ( empty( $data['user'] ) || empty( $data['course'] ) ) {
        return;
    }

    $log = (array) get_option( 'wpide_ld_completions', array() );
    array_unshift( $log, array( 'user' => (int) $data['user']->ID, 'course' => (int) $data['course']->ID, 'time' => time() ) );
    update_option( 'wpide_ld_completions', array_slice( $log, 0, 15 ), false );
} );

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

    wp_add_dashboard_widget( 'wpide_ld_completions', 'Recent course completions', function () {
        $log = array_filter( (array) get_option( 'wpide_ld_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 <a href="%2$s">%3$s</a> <span style="color:#646970">%4$s ago</span></li>',
                esc_html( $user ? $user->display_name : 'Deleted user' ),
                esc_url( get_edit_post_link( $row['course'] ) ),
                esc_html( get_the_title( $row['course'] ) ),
                esc_html( human_time_diff( (int) $row['time'] ) )
            );
        }

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

## Notes

The log starts when the snippet is activated and keeps the 15 most recent completions in one small option.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "LearnDash: 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/
