automator_view_path
Filters the directory path to the view file This can be used for view overrides by modifying the path to go to a directory in the theme or another plugin. Filters the directory path for view files, allowing for theme or plugin overrides of template locations.
add_filter( 'automator_view_path', $callback, 10, 1 );
Description
Filters the directory path for view files. Developers can use this hook to override default plugin views by pointing to a custom directory within their theme or another plugin. This allows for extensive customization of how plugin views are rendered.
Usage
add_filter( 'automator_view_path', 'your_function_name', 10, 1 );
Parameters
-
$views_directory(mixed) - - **$file_name** `mixed`
Return Value
The filtered value.
Examples
/**
* Override the default view path for the 'user_registered' template.
*
* This filter allows us to point to a custom template file within the theme
* for the 'user_registered' view, enabling theme-specific customizations
* without modifying plugin files directly.
*
* @param string $views_directory The default directory path for views.
* @param string $file_name The name of the view file being requested.
* @return string The modified directory path.
*/
function my_automator_override_user_registered_view( $views_directory, $file_name ) {
// Check if the requested file is the 'user_registered' template.
if ( 'user_registered.php' === $file_name ) {
// Construct the path to the custom template within the theme's 'automator' folder.
// Ensure the 'automator' directory exists in your theme.
$theme_template_path = get_stylesheet_directory() . '/automator/';
// Check if the custom template file exists in the theme.
if ( file_exists( $theme_template_path . $file_name ) ) {
return $theme_template_path;
}
}
// If it's not the 'user_registered' file or the custom file doesn't exist,
// return the original directory path.
return $views_directory;
}
add_filter( 'automator_view_path', 'my_automator_override_user_registered_view', 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:355
public static function automator_get_view( $file_name ) {
$views_directory = UA_ABSPATH . 'src' . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR;
// Replace separator in the file name
$file_name = str_replace( '/', DIRECTORY_SEPARATOR, $file_name );
/**
* Filters the directory path to the view file
*
* This can be used for view overrides by modifying the path to go to a directory in the theme or another plugin.
*
* @param $views_directory Path to the plugins view folder
* @param $file_name The file name of the view file
*
* @since 1.0.0
*/
$views_directory = apply_filters( 'automator_view_path', $views_directory, $file_name );
return $views_directory . $file_name;
}
Internal Usage
Found in src/core/classes/class-usage-reports.php:84:
add_action( 'automator_view_path', array( $this, 'count_integrations_view' ), 10, 2 );