kimaai_loaded

When it fires

Once per request, on plugins_loaded (priority 10), right after kimaai_register_addons and after every registered add-on’s register() ran. KimaAI has built its services and registered its own hooks by then; WordPress’s init has not run yet. It does not fire when KimaAI is not active, so code inside the callback runs only with KimaAI.

It suits an integration that needs no add-on class: a few hooks that only make sense with KimaAI, or classes of your plugin that use KimaAI’s. Add the callback when your plugin’s main file loads, not in a plugins_loaded callback of your own, which may run after KimaAI’s.

Parameters

NameTypeDescription
mainMainKimaAI’s main object (KimaAI\Main).
classesClassesSurfaceAccess to KimaAI’s services (KimaAI\Surfaces\ClassesSurface).
managerAddonManagerKimaAI’s add-on manager (KimaAI\Addons\AddonManager), after it started the add-ons.

Example

add_action(
  'kimaai_loaded',
  function (): void {
    add_filter(
      'kimaai_chatbot_instructions',
      function (string $instructions): string {
        return $instructions . "\nOur support line is open Monday to Friday, 9:00 to 17:00.";
      }
    );
  },
  10,
  0
);

The callback adds a line to the chatbot’s instructions, and only on sites where KimaAI runs.

More examples

did_action('kimaai_loaded') tells later code whether KimaAI is running, for example to ask for it in the admin:

add_action(
  'admin_notices',
  function (): void {
    if (did_action('kimaai_loaded') || !current_user_can('activate_plugins')) {
      return;
    }

    echo '<div class="notice notice-warning"><p>' . esc_html__('My add-on needs KimaAI. Install and activate KimaAI to use it.', 'my-addon') . '</p></div>';
  }
);
  • kimaai_register_addons: registers an add-on class, which KimaAI starts before this action.

What are your feelings