Filter Since 1.0.0 uncanny-learndash-groups

ulgm_includes_path_to

Filters the director path to the include file This can be used for template overrides by modifying the path to go to a directory in the theme or another plugin. Filters the include path to template files, allowing for theme or plugin overrides of plugin templates.

add_filter( 'ulgm_includes_path_to', $callback, 10, 2 );

Description

Allow theme or plugin developers to override the default path to plugin include files. Modify the path to point to template files within your theme's directory or another plugin for custom template rendering.


Usage

add_filter( 'ulgm_includes_path_to', 'your_function_name', 10, 2 );

Parameters

$templates_directory (string)
Path to the plugins template folder
$file_name (string)
The file name of the template file

Return Value

The filtered value.


Examples

<?php
/**
 * Example function to override the path to a plugin include file.
 *
 * This function demonstrates how to use the 'ulgm_includes_path_to' filter
 * to change the default directory where the plugin looks for its include files.
 * In this example, we're checking if a specific template file exists within
 * the theme's directory and, if so, prioritizing that custom template.
 *
 * @param string $templates_directory The default path to the plugin's template folder.
 * @param string $file_name           The name of the template file being requested.
 *
 * @return string The potentially modified path to the include file.
 */
add_filter( 'ulgm_includes_path_to', function( $templates_directory, $file_name ) {

	// Define a custom template directory within the theme.
	$custom_theme_templates_dir = trailingslashit( get_stylesheet_directory() ) . 'my-custom-plugin-templates/';

	// Construct the full path to the custom template.
	$custom_template_path = $custom_theme_templates_dir . $file_name;

	// Check if the custom template file exists in the theme's directory.
	if ( file_exists( $custom_template_path ) ) {
		// If it exists, return the path to the custom template.
		return $custom_theme_templates_dir;
	}

	// If the custom template doesn't exist, return the original plugin directory.
	return $templates_directory;

}, 10, 2 ); // 10 is the priority, 2 is the number of arguments accepted by the callback function.
?>

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/class-utilities.php:549

public static function get_include( $file_name ) {

		$includes_directory = ULGM_ABSPATH . 'src/includes' . DIRECTORY_SEPARATOR;

		/**
		 * Filters the director path to the include file
		 *
		 * This can be used for template overrides by modifying the path to go to a directory in the theme or another plugin.
		 *
		 * @param string $templates_directory Path to the plugins template folder
		 * @param string $file_name The file name of the template file
		 *
		 * @since 1.0.0
		 */
		$includes_directory = apply_filters( 'ulgm_includes_path_to', $includes_directory, $file_name );

		$asset_path = $includes_directory . $file_name;

		return $asset_path;
	}

Scroll to Top