Action Since 3.0 uncanny-toolkit-pro

learndash-lesson-after

Action to add custom content after the lesson Fires after a LearnDash lesson is displayed, allowing custom content injection with lesson and course IDs.

add_action( 'learndash-lesson-after', $callback, 10, 1 );

Description

Fires after the LearnDash lesson content has been displayed. This hook allows developers to inject custom content or logic directly below the lesson. It passes the current lesson ID, course ID, and user ID as parameters.


Usage

add_action( 'learndash-lesson-after', 'your_function_name', 10, 1 );

Parameters

$course_id (mixed)
- **$user_id** `mixed`

Examples

<?php
/**
 * Adds a custom notification to the admin area after a LearnDash lesson is displayed.
 * This could be used to log lesson completion for specific users, or trigger an internal notification system.
 *
 * @param int $lesson_id The ID of the current lesson.
 * @param int $course_id The ID of the course the lesson belongs to.
 * @param int $user_id   The ID of the user viewing the lesson.
 */
function my_learndash_lesson_after_notification( $lesson_id, $course_id, $user_id ) {
	// Check if the current user is an administrator.
	if ( current_user_can( 'manage_options' ) ) {
		// Get lesson and course titles for the notification message.
		$lesson_title = get_the_title( $lesson_id );
		$course_title = get_the_title( $course_id );
		$user_info    = get_userdata( $user_id );
		$user_login   = $user_info ? $user_info->user_login : 'Unknown User';

		// Construct the notification message.
		$message = sprintf(
			__( 'LearnDash Lesson "%s" in Course "%s" was displayed to user "%s" (ID: %d).', 'my-text-domain' ),
			esc_html( $lesson_title ),
			esc_html( $course_title ),
			esc_html( $user_login ),
			absint( $user_id )
		);

		// In a real-world scenario, you might log this to a custom table, send an email,
		// or add it to a WordPress admin notice. For this example, we'll just use a placeholder.
		// Example: Log to WordPress debug log.
		error_log( '[LearnDash Lesson After Notification] ' . $message );

		// You could also store this in a custom post type, user meta, or trigger an external API call.
	}
}
add_action( 'learndash-lesson-after', 'my_learndash_lesson_after_notification', 10, 3 );
?>

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/templates/single-ld30-lesson.php:260

);

	/**
	 * Action to add custom content after the lesson
	 *
	 * @since 3.0
	 */
	do_action( 'learndash-lesson-after', get_the_ID(), $course_id, $user_id );
	?>

</div> <!--/.learndash-wrapper-->


Scroll to Top