uo_drip_template
Filters the file path used to render drip templates, allowing customization of template locations.
add_filter( 'uo_drip_template', $callback, 10, 1 );
Description
Filters the file path for Uncanny Automator drip templates. Allows developers to customize the template file used for drip content, especially for legacy LearnDash themes or when custom template locations are needed.
Usage
add_filter( 'uo_drip_template', 'your_function_name', 10, 1 );
Parameters
-
$filepath(mixed) - This parameter contains the file path to the template that will be rendered.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'uo_drip_template' filter to conditionally load a custom template
* based on the current user's role.
*/
add_filter( 'uo_drip_template', 'my_custom_drip_template_by_role', 10, 1 );
function my_custom_drip_template_by_role( $filepath ) {
// Check if the current user has the 'administrator' role.
// You can replace 'administrator' with any other role slug.
if ( current_user_can( 'administrator' ) ) {
// If the user is an administrator, override the default filepath
// with the path to our custom template.
// Replace 'path/to/your/custom-drip-template.php' with the actual path.
$custom_template_path = get_stylesheet_directory() . '/templates/custom-drip-template.php';
// Ensure the custom template file actually exists before returning its path.
if ( file_exists( $custom_template_path ) ) {
$filepath = $custom_template_path;
}
}
// Always return the $filepath, whether it's the original one or our custom one.
return $filepath;
}
// Ensure the add_filter call is wrapped in a function that only runs when appropriate,
// e.g., within a plugin's activation hook or an initialization function.
// For demonstration purposes, this is shown directly. In a real plugin,
// you would likely enqueue this within your main plugin file or an admin setup function.
// Example of how the filter might be applied internally (as seen in your provided context):
// $filepath = apply_filters( 'uo_drip_template', $filepath );
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-topics-by-group.php:1127
src/classes/uncanny-drip-lessons-by-group.php:1114
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-topic-template_legacy.php', dirname( dirname( __FILE__ ) ) . '/src' );
$filepath = apply_filters( 'uo_drip_template', $filepath );
}
}
if ( 'learndash_course_topic_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_topic_not_available_legacy.php', dirname( dirname( __FILE__ ) ) . '/src' );
$filepath = apply_filters( 'uo_learndash_course_topic_not_available', $filepath );
}
}
return $filepath;
}