Filter Since 1.0.0 uncanny-automator

automator_includes_path_to

Filters the director path to the include file This can be used for include overrides by modifying the path to go to a directory in the theme or another plugin. Filters the include file path before it's loaded, allowing theme or plugin overrides for custom logic.

add_filter( 'automator_includes_path_to', $callback, 10, 1 );

Description

Allows developers to modify the include file path. This hook is useful for overriding default include files by pointing to a custom directory within your theme or another plugin, ensuring flexibility and theme-specific customizations.


Usage

add_filter( 'automator_includes_path_to', 'your_function_name', 10, 1 );

Parameters

$includes_directory (mixed)
- **$file_name** `mixed`

Return Value

The filtered value.


Examples

/**
 * Example of how to override the default include path for AutomatorWP files.
 * This function will check if a specific file exists in the theme's 'automator-includes'
 * directory and, if so, will return that path instead of the plugin's default.
 *
 * @param string $includes_directory The default include directory path.
 * @param string $file_name The name of the file being included.
 * @return string The modified include directory path.
 */
add_filter( 'automator_includes_path_to', function( $includes_directory, $file_name ) {

    // Define the directory within the theme to look for custom includes.
    $theme_custom_includes_dir = 'automator-includes/';

    // Construct the potential path in the theme's directory.
    $theme_path = trailingslashit( get_stylesheet_directory() ) . $theme_custom_includes_dir . $file_name;

    // Check if the file exists in the theme's custom includes directory.
    if ( file_exists( $theme_path ) ) {
        // If it exists, return the theme's path.
        return trailingslashit( get_stylesheet_directory() ) . $theme_custom_includes_dir;
    }

    // Otherwise, return the original default includes directory.
    return $includes_directory;

}, 10, 2 );

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

public static function automator_get_include( $file_name ) {

		$includes_directory = UA_ABSPATH . 'src' . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR;

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

		return $includes_directory . $file_name;
	}

Scroll to Top