Filter
uncanny-automator
automator_should_load_automator
Load Automator on/off Filters whether Automator should load, allowing you to conditionally disable it.
add_filter( 'automator_should_load_automator', $callback, 10, 1 );
Description
Filters whether Automator should load. By default, Automator loads. Developers can return `false` to prevent Automator from loading, which can be useful for debugging or specific integrations. This filter fires early in the WordPress loading process.
Usage
add_filter( 'automator_should_load_automator', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Conditionally load Automator based on user role.
*
* This filter allows developers to prevent Automator from loading for specific user roles,
* for example, if it's only intended for administrators or specific custom roles.
*
* @param bool $load Whether to load Automator. Default is true.
* @return bool Whether to load Automator.
*/
function my_conditional_automator_load( $load ) {
// Ensure we are running in the WordPress admin environment.
if ( is_admin() ) {
// Get the current logged-in user.
$current_user = wp_get_current_user();
// Define roles for which Automator should NOT load.
$restricted_roles = array( 'subscriber', 'contributor' );
// Check if the current user has any of the restricted roles.
if ( ! empty( array_intersect( $restricted_roles, $current_user->roles ) ) ) {
// If the user has a restricted role, prevent Automator from loading.
return false;
}
}
// For all other cases (frontend or users without restricted roles), allow loading.
return $load;
}
add_filter( 'automator_should_load_automator', 'my_conditional_automator_load', 10, 1 );
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/globals.php:36
define( 'AUTOMATOR_DEBUG_MODE', apply_filters( 'automator_should_enable_debug_mode', false ) );
}
if ( ! defined( 'LOAD_AUTOMATOR' ) ) {
/**
* Load Automator on/off
*/
define( 'LOAD_AUTOMATOR', apply_filters( 'automator_should_load_automator', true ) );
}
if ( ! defined( 'UA_DEBUG_LOGS_DIR' ) ) {
/**
* Automator ABSPATH for automator logs directory
*/
define( 'UA_DEBUG_LOGS_DIR', trailingslashit( UA_ABSPATH ) . 'logs' . DIRECTORY_SEPARATOR );
Internal Usage
Found in src/class-automator-load.php:418:
add_filter( 'automator_should_load_automator', array( $this, 'should_load_automator' ) );