learndash_lesson_available_from_text
Filters the text displayed when a lesson becomes available, allowing customization of the availability message.
add_filter( 'learndash_lesson_available_from_text', $callback, 10, 3 );
Description
Filters the "Available on" text displayed for lessons. Developers can modify this message to customize when a lesson becomes accessible, for instance, to dynamically set dates or add conditional logic. The hook passes the current message, lesson data, and the calculated available date for customization.
Usage
add_filter( 'learndash_lesson_available_from_text', 'your_function_name', 10, 3 );
Parameters
-
$message(mixed) - This parameter contains the text of the message that is displayed when a lesson is not yet available.
-
$lesson(mixed) - This parameter contains the HTML or plain text message that indicates when a lesson will become available.
-
$available_on(mixed) - This parameter contains the lesson object, which provides access to all lesson-related data.
Return Value
The filtered value.
Examples
/**
* Modify the "Available on" text for lessons.
*
* This function is an example of how to use the 'learndash_lesson_available_from_text'
* filter to customize the message displayed when a lesson is not yet available.
*
* @param string $message The default "Available on" message.
* @param WP_Post $lesson_post The WP_Post object for the lesson.
* @param string $available_on The date the lesson becomes available.
* @return string The modified "Available on" message.
*/
function my_learndash_customize_lesson_available_text( $message, $lesson_post, $available_on ) {
// Ensure we have valid data before proceeding.
if ( ! is_a( $lesson_post, 'WP_Post' ) || empty( $available_on ) ) {
return $message; // Return original message if data is not as expected.
}
// Example: Add a prefix to the "Available on" text.
$prefix = sprintf(
__( 'This lesson will unlock on: <span class="ld-display-date">%s</span>', 'your-text-domain' ),
learndash_adjust_date_time_display( $available_on )
);
// You can also use the $lesson_post object to add lesson-specific logic.
// For instance, if you wanted to change the message for a specific lesson ID.
// if ( $lesson_post->ID === 123 ) {
// $prefix = sprintf(
// __( 'Get ready! This lesson becomes available on %s.', 'your-text-domain' ),
// learndash_adjust_date_time_display( $available_on )
// );
// }
return $prefix;
}
add_filter( 'learndash_lesson_available_from_text', 'my_learndash_customize_lesson_available_text', 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/classes/learn-dash-my-courses.php:996
src/templates/learndash_course_lesson_not_available_legacy.php:42
src/classes/uncanny-drip-lessons-by-group.php:1215
$available_on = null;
$available_on_message = '';
if ( ! empty( $lesson['lesson_access_from'] ) ) {
$is_available = false;
$available_on = $lesson['lesson_access_from'];
$message = sprintf( wp_kses_post( __( '<span class="ld-display-label">Available on:</span> <span class="ld-display-date">%s</span>', 'learndash' ) ), learndash_adjust_date_time_display( $available_on ) );
$available_on_message = apply_filters( 'learndash_lesson_available_from_text', $message, get_post( $lesson['post']->ID ), $available_on );
}
$courses[ $course_id ]->sections[ $current_section->ID ]->lessons[ $lesson['post']->ID ] =
(object) [
'id' => $lesson['post']->ID, // int
'title' => $lesson['post']->post_title, // string