Filter uncanny-automator

automator_should_enable_debug_mode

Automator debug mode on/off Filters whether Automator debug mode is enabled on or off.

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

Description

Filters whether Automator's debug mode should be enabled. Developers can return `true` to activate debug mode, aiding in troubleshooting. This hook fires early in the plugin's loading process. Ensure your logic correctly determines the need for debugging.


Usage

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

Return Value

The filtered value.


Examples

<?php
/**
 * Example of enabling debug mode based on a specific user role.
 *
 * This function will enable Automator's debug mode if the current user
 * has the 'administrator' role.
 *
 * @param bool $default The default value for the debug mode (false).
 * @return bool True if debug mode should be enabled, false otherwise.
 */
function my_automator_enable_debug_for_admins( $default ) {
	// Check if the current user is logged in.
	if ( is_user_logged_in() ) {
		$current_user = wp_get_current_user();

		// Check if the user has the 'administrator' role.
		if ( in_array( 'administrator', (array) $current_user->roles ) ) {
			return true; // Enable debug mode for administrators.
		}
	}

	// Otherwise, return the default value (which is false if no other filters change it).
	return $default;
}

// Add the filter to the automator_should_enable_debug_mode hook.
// We are accepting only the default argument (0 or omitted).
add_filter( 'automator_should_enable_debug_mode', 'my_automator_enable_debug_for_admins', 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:29

namespace Uncanny_Automator;

if ( ! defined( 'AUTOMATOR_DEBUG_MODE' ) ) {
	/**
	 * Automator debug mode on/off
	 */
	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 ) );


Internal Usage

Found in src/class-automator-load.php:417:

add_filter( 'automator_should_enable_debug_mode', array( $this, 'should_enable_debug_mode_handler' ) );
Scroll to Top