learndash-course-expand-after
Fires after the course content expand button. Fires after the LearnDash course content expand button, providing course and user IDs for customization.
add_action( 'learndash-course-expand-after', $callback, 10, 2 );
Description
Fires after the course content expand button is rendered, providing the current course and user IDs. Developers can leverage this hook to add custom content, modify the UI, or trigger actions immediately after the expand button's display, offering fine-grained control over the course page's expand functionality.
Usage
add_action( 'learndash-course-expand-after', 'your_function_name', 10, 2 );
Parameters
-
$course_id(int) - Course ID.
-
$user_id(int) - User ID.
Examples
add_action( 'learndash-course-expand-after', 'my_learndash_course_expand_after_handler', 10, 2 );
/**
* Example handler for the learndash-course-expand-after action hook.
* This function demonstrates how to access the course ID and user ID
* after the course content expand button is shown and then potentially
* log some information or perform a custom action.
*
* @param int $course_id The ID of the course.
* @param int $user_id The ID of the user.
*/
function my_learndash_course_expand_after_handler( $course_id, $user_id ) {
// Check if the user is logged in before proceeding.
if ( ! is_user_logged_in() ) {
return;
}
// Get current user object if they are logged in.
$current_user = wp_get_current_user();
// Retrieve course object for more detailed information if needed.
$course = get_post( $course_id );
// Example: Log a message to the WordPress debug log.
// This is useful for debugging and understanding when the action fires.
error_log( sprintf(
'learndash-course-expand-after fired for Course ID: %d, User ID: %d (%s). Course title: "%s".',
$course_id,
$user_id,
$current_user->user_login,
$course ? $course->post_title : 'N/A'
) );
// Example: Conditionally display a custom message to the user.
// This could be based on user meta, course progress, etc.
if ( user_can( $user_id, 'access_course', $course_id ) && $current_user->ID === $user_id ) {
echo '<p class="my-custom-message" style="color: green; margin-top: 15px;">You have successfully accessed the course content!</p>';
}
// Example: Trigger another custom action or filter based on this event.
// do_action( 'my_custom_learndash_event', $course_id, $user_id, $current_user );
}
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-course.php:217
* Fires after the course content expand button.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-course-expand-after', $course_id, $user_id );
?>
</div> <!--/.ld-item-list-actions-->
</div> <!--/.ld-section-heading-->
<?php
/**