Context
A context tells the Agent which kind of screen it is
on: a normal admin screen, the block editor, or a page builder. The Agent
looks for the context of the page on the right whenever that page changes,
offers the modes whose detection names it, and remembers the mode you chose
for each context.
A context and a mode are different things. The context is found from the page and you do not choose it; the mode is what you choose, and it decides what the Agent knows and can do.
Built-in contexts
| Context | Recognised by |
|---|---|
wp-admin |
The wp-admin class on the page’s body. |
block-editor |
The block-editor-page class on the page’s body. |
bricks, breakdance, beaver, elementor, etch |
The page builder’s editor, when the Agent is opened in it. |
A screen that matches no context counts as wp-admin.
Registering a context
Agent::registerContext() adds a context for a screen of your own, so that a
mode can be detected there:
add_action('sleekAi/init', function () {
\SleekAi\Agent\Agent::registerContext([
'id' => 'my-plugin-admin',
'selector' => [
'bodyClass' => 'my-plugin-admin-page',
],
]);
});
selector.bodyClass matches a class of the page’s body, and
selector.element a CSS selector of an element on the page. A mode then names
the context in its detection, and the Agent offers it only where the
context’s selector matches:
'detection' => ['context' => 'my-plugin-admin'],
The Agent decides the screen’s own context, which chooses the default mode,
from the contexts in the order they were registered, trying wp-admin last
because every admin screen matches it. A context you register therefore
becomes the screen’s context wherever its selector matches, and the Agent
opens there in your mode.
A context may also carry styling rules, which earlier versions used to fit
the admin screen around the Agent panel. The Agent now shows the page in a
frame beside its own column, so it keeps those rules but does not apply them.