kimaai_user_access_tokens

When it fires

Whenever KimaAI checks what the current user may see: before the knowledge search, whose query asks only for chunks with one of the user’s tokens, for every hit afterwards, in the search answer and in the chatbot’s knowledge of the page the visitor is on. It runs once per user and request; KimaAI keeps the result for the rest of the request.

A user sees a post when they hold one of the post’s tokens (kimaai_content_access_tokens). KimaAI resolves public for everyone, role:<role> for each role of a logged-in user, and the tokens of MemberPress, Paid Memberships Pro and LearnDash when they are active. Add the tokens your own code grants. A user never holds deny: KimaAI removes it from what the filter returns. The search answer caches its answers per set of tokens, so users with other tokens never get each other’s answers.

Parameters

NameTypeDescription
tokensstring[]The tokens KimaAI resolved for the user. Always public; for a logged-in user also role:<role> per role and the tokens of the active membership plugins.
user_idintThe user’s ID, 0 for a visitor who is not logged in.

Returns

string[]: The tokens the user holds. deny is removed.

Example

add_filter(
  'kimaai_user_access_tokens',
  function (array $tokens, int $user_id): array {
    // The customer tier your CRM integration stores with the user.
    if ($user_id > 0 && get_user_meta($user_id, 'my_crm_tier', true) === 'gold') {
      $tokens[] = 'crm:gold';
    }

    return $tokens;
  },
  10,
  2
);
  • kimaai_content_access_tokens: the tokens that let a user see a post.

What are your feelings