Filter uncanny-automator

automator_agent_banned_actions

Filters the list of actions that are considered banned by the API integration.

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

Description

Filters the list of actions considered banned by the API agent. Developers can modify this array to explicitly ban or unban specific actions, controlling their execution through API calls. This filter fires before an action is checked for being banned, allowing for dynamic adjustment of restrictions.


Usage

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

Return Value

The filtered value.


Examples

// Prevent specific actions from being executed by the automator agent.
// For example, we might want to ban actions that could potentially cause
// irreversible data loss or interfere with critical WordPress processes.
add_filter( 'automator_agent_banned_actions', function( $banned_actions ) {

    // Example: Ban a hypothetical action code 'delete_all_users' and provide a reason.
    // This is a dangerous action and should ideally not be exposed directly to automation.
    $banned_actions['delete_all_users'] = __( 'This action is too dangerous to be automated and could lead to irreversible data loss.', 'your-text-domain' );

    // Example: Ban another action, perhaps related to core file modification.
    $banned_actions['modify_wp_config'] = __( 'Modifying wp-config.php via automation is a security risk.', 'your-text-domain' );

    // You can add more banned actions here as needed.
    // The structure of $banned_actions is expected to be an associative array
    // where keys are action codes (strings) and values are the reasons (strings).

    return $banned_actions;
}, 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/api/application/sub_tooling/class-action-executor.php:227

private function check_action_banned( string $action_code ) {

		// Allow filtering of banned actions for extensibility.
		$banned_actions = apply_filters( 'automator_agent_banned_actions', self::BANNED_ACTIONS );

		if ( ! isset( $banned_actions[ $action_code ] ) ) {
			return true;
		}

		$reason = $banned_actions[ $action_code ];

		// Build a helpful error message for the AI.
		$message = sprintf(
			/* translators: 1: Action code, 2: Reason for restriction */
			"Action '%s' is not available for AI execution. %s If you need to perform this operation, please guide the user to do it manually in WordPress admin or use a recipe instead.",
			$action_code,
			$reason
		);

		return new WP_Error( 'action_banned', $message );
	}

Scroll to Top