When it fires
Whenever KimaAI decides whether a post’s content may go into an answer: in a sync of the knowledge base, where the tokens are stored with each chunk, and before every hit is used, in the knowledge search (vector and keyword), the search answer and the chatbot’s knowledge of the page the visitor is on. A user sees the post when they hold one of its tokens (kimaai_user_access_tokens).
KimaAI resolves the tokens first: public for a published post, deny for a draft, a private or a password-protected post, and the rules of MemberPress (mepr:<id>), Paid Memberships Pro (pmpro:<level>) and LearnDash (ld_course:<id>) when they are active. An attachment follows the post it belongs to. Return your own tokens for posts that your code protects, role:<role> for a WordPress role, and keep deny: a callback that turns deny into a token would let a draft into answers.
A post without public is members-only: it enters the knowledge base only with “Include members-only content” (Members-only knowledge, Pro), and deny keeps it out and removes what an earlier sync stored. The tokens stored with the chunks change with the next sync of the post. Until then each hit is still checked with the current tokens, so a callback that narrows access works at once, and one that opens a post to more users reaches the knowledge search after the sync.
Parameters
| Name | Type | Description |
|---|---|---|
tokens | string[] | The tokens KimaAI resolved for the post. A user who holds any of them sees it. |
post_id | int | The post’s ID. |
post | WP_Post|null | The post, or null when it does not exist. |
Returns
string[]: The tokens. An empty list or one with deny hides the post from everyone.
Example
add_filter(
'kimaai_content_access_tokens',
function (array $tokens, int $post_id, ?WP_Post $post): array {
// Price lists are for gold customers only; drafts stay hidden.
if ($post && $post->post_type === 'price_list' && !in_array('deny', $tokens, true)) {
return ['crm:gold'];
}
return $tokens;
},
10,
3
);
The token crm:gold is your own; kimaai_user_access_tokens gives it to the users who may see these posts.
Related
kimaai_user_access_tokens: the tokens a user holds.kimaai_kb_search_meta_filter: narrows the knowledge search, but cannot widen what a user may see.