uo_learndash_course_lesson_not_available
Filters the filepath of the lesson not available notice template when a course or lesson is inaccessible.
add_filter( 'uo_learndash_course_lesson_not_available', $callback, 10, 1 );
Description
Filters the filepath for the LearnDash course template. Developers can use this to conditionally alter the template loaded for a course, potentially for custom drip content display or alternative course layouts. This hook is specifically for LearnDash's core templating system.
Usage
add_filter( 'uo_learndash_course_lesson_not_available', 'your_function_name', 10, 1 );
Parameters
-
$filepath(mixed) - This parameter contains the file path of the template being loaded.
Return Value
The filtered value.
Examples
/**
* Filter hook: uo_learndash_course_lesson_not_available
*
* This filter allows developers to modify the file path for the "course lesson not available" template.
* It's useful for conditionally loading different template files based on certain criteria,
* such as the user's role or specific course settings.
*
* @param string $filepath The original file path to the template.
*
* @return string The modified file path to the template.
*/
add_filter( 'uo_learndash_course_lesson_not_available', function( $filepath ) {
// Example: If the current user has the 'administrator' role,
// load a custom template file for unavailable lessons.
if ( current_user_can( 'administrator' ) ) {
// Define a custom template path. In a real scenario, this would likely
// point to a file within your theme or a custom plugin.
$custom_template_path = get_stylesheet_directory() . '/templates/learndash/custom-lesson-not-available.php';
// Check if the custom template file exists before returning its path.
if ( file_exists( $custom_template_path ) ) {
return $custom_template_path;
}
}
// If the condition is not met or the custom template doesn't exist,
// return the original file path.
return $filepath;
}, 10, 1 ); // 10 is the default priority, 1 is the number of accepted arguments.
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/uncanny-drip-lessons-by-group.php:1129
public static function learndash_template( $filepath, $name, $args, $echo, $return_file_path ) {
if ( 'course' === $name ) {
if ( ! class_exists( 'LearnDash_Theme_Register' ) ||
(
class_exists( 'LearnDash_Theme_Register' ) &&
'legacy' === LearnDash_Theme_Register::get_active_theme_key()
)
) {
$filepath = self::get_template( 'drip-template_legacy.php', dirname( dirname( __FILE__ ) ) . '/src' );
$filepath = apply_filters( 'uo_drip_template', $filepath );
}
}
if ( 'learndash_course_lesson_not_available' === $name ) {
if ( ! class_exists( 'LearnDash_Theme_Register' ) ||
(
class_exists( 'LearnDash_Theme_Register' ) &&
'legacy' === LearnDash_Theme_Register::get_active_theme_key()
)
) {
$filepath = self::get_template( 'learndash_course_lesson_not_available_legacy.php', dirname( dirname( __FILE__ ) ) . '/src' );
$filepath = apply_filters( 'uo_learndash_course_lesson_not_available', $filepath );
}
}
return $filepath;
}