---
name: kimaai_admin_assistant_gate
type: filter
since: 1.5.0
tier: free
feature: admin-assistant
area: admin-assistant
summary: Blocks an administrator's message to the admin assistant before anything is sent to the AI provider.
parameters:
  - name: allowed
    type: true|string|WP_Error
    description: True to answer. A message or a WP_Error blocks the request; its message is what the administrator sees.
  - name: prompt
    type: mixed
    description: The administrator's message after kimaai_admin_assistant_prompt.
  - name: payload
    type: array
    description: The normalised request payload, with prompt, postId (always 0), lang and chatbot_settings, which holds the admin assistant's runtime settings.
  - name: data
    type: array
    description: The request's JSON body.
  - name: request
    type: WP_REST_Request
    description: The REST request.
returns:
  type: true|string|WP_Error
  description: True to go on; anything else blocks.
surfaces: [admin_assistant]
---

# kimaai_admin_assistant_gate

## When it fires

In every admin assistant request (`POST /wp-json/kimaai/v1/admin-assistant`), right after `kimaai_admin_assistant_prompt` and before the session is resolved, the daily limit is counted and the setup workflows read the message. WordPress has already checked that the user may manage options, so the gate is the place for your own rules on top of that, by user or by content. KimaAI does not hook it itself: the banned words and IP addresses of the chatbot settings do not apply to the admin assistant.

Only `true` lets the request go on. A string or a `WP_Error` blocks it: the administrator gets its message with status 403, `kimaai_admin_assistant_blocked` fires, and nothing reaches the AI provider or the assistant's history. Any other value blocks it with a general message. Return `$allowed` unchanged when it is not `true`, so another callback's refusal stands.

The admin assistant is not released yet: its panel and its routes are switched off in this release, so these requests are not sent.

## Example

```php
add_filter(
  'kimaai_admin_assistant_gate',
  function ($allowed) {
    if ($allowed !== true) {
      return $allowed;
    }

    // Only the administrators your role editor gave this capability use the assistant.
    if (!current_user_can('use_kimaai_assistant')) {
      return new WP_Error('my_plugin_assistant', __('Ask the site owner for access to the AI assistant.', 'my-plugin'));
    }

    return $allowed;
  }
);
```

## Related

- `kimaai_admin_assistant_blocked`: fires when the gate blocks a message.
- `kimaai_admin_assistant_prompt`: changes the message before the gate sees it.
- `kimaai_chatbot_gate`: the same filter for the chatbot.
