# "Mark as Complete" Button for Lesson Posts (No LMS Needed)

> Adds a [wpide_mark_complete] shortcode that lets logged-in readers tick off a post or page as done, turning a plain blog series into a simple course without an LMS plugin.

- Type: PHP
- Runs: Run everywhere
- Category: [Courses & Community](https://wpide.com/library/category/learning/)
- Tags: lessons, progress, shortcode
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/lesson-mark-complete-button/

## Code

```php
add_action( 'template_redirect', function () {
    if ( empty( $_POST['wpide_complete_nonce'] ) || ! is_user_logged_in() ) {
        return;
    }

    $post_id = isset( $_POST['wpide_lesson'] ) ? absint( $_POST['wpide_lesson'] ) : 0;

    if ( ! $post_id || ! wp_verify_nonce( sanitize_key( $_POST['wpide_complete_nonce'] ), 'wpide_complete_' . $post_id ) || 'publish' !== get_post_status( $post_id ) ) {
        return;
    }

    $done = array_map( 'intval', (array) get_user_meta( get_current_user_id(), 'wpide_completed_lessons', true ) );

    if ( in_array( $post_id, $done, true ) ) {
        $done = array_diff( $done, array( $post_id ) );
    } else {
        $done[] = $post_id;
    }

    update_user_meta( get_current_user_id(), 'wpide_completed_lessons', array_values( array_unique( $done ) ) );

    wp_safe_redirect( get_permalink( $post_id ) );
    exit;
} );

add_shortcode( 'wpide_mark_complete', function () {
    $post_id = get_the_ID();

    if ( ! $post_id ) {
        return '';
    }

    if ( ! is_user_logged_in() ) {
        return '<p class="wpide-complete"><a href="' . esc_url( wp_login_url( get_permalink() ) ) . '">Log in</a> to track your progress.</p>';
    }

    $done = in_array( $post_id, array_map( 'intval', (array) get_user_meta( get_current_user_id(), 'wpide_completed_lessons', true ) ), true );

    return '<form method="post" class="wpide-complete' . ( $done ? ' is-done' : '' ) . '">'
        . wp_nonce_field( 'wpide_complete_' . $post_id, 'wpide_complete_nonce', true, false )
        . '<input type="hidden" name="wpide_lesson" value="' . (int) $post_id . '">'
        . '<button type="submit" aria-pressed="' . ( $done ? 'true' : 'false' ) . '">' . ( $done ? '&#10003; Completed (undo)' : 'Mark as complete' ) . '</button></form>';
} );
```

## Notes

Completed lessons are stored per user in the wpide_completed_lessons user meta. Pair it with the "Series Progress" snippet to show overall progress.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Mark as Complete" Button for Lesson Posts (No LMS Needed)" 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/
