Skip to content

PHP filters and actions

OG AI Core's own hooks start with ogaie_. The built-in modules and the add-ons keep their own prefixes. Check the argument list at the call site in the plugin before you rely on a hook: many receive extra parameters.

Chatbots and discussions

ogaie_chatbot_params, ogaie_chatbot_query, ogaie_chatbot_reply, ogaie_chatbot_texts, ogaie_chatbot_actions, ogaie_chatbot_blocks, ogaie_chatbot_shortcuts, ogaie_chatbot_takeover, ogaie_internal_chatbot, ogaie_admin_only_bots.

ogaie_discussion_format_messages, ogaie_discussion_user_name, ogaie_discussion_metadata_start_date, ogaie_discussion_metadata_last_update, ogaie_discussion_metadata_message_count, ogaie_discussions_title_prompt, ogaie_discussions_refresh_interval, ogaie_discussions_retention_days, ogaie_discussions_ui_exclude.

  • ogaie_chatbot_params receives the chatbot's parameters (shortcode attributes merged with the saved chatbot).
  • ogaie_chatbot_takeover and ogaie_form_takeover receive null, the query and the parameters. Return a string to answer without calling the AI.
  • ogaie_discussions_ui_exclude receives [], the user ID and the chatbot ID. Return discussion IDs (chat IDs) to hide from that user's own chat list without deleting them. Discussions and Insights still show them.

  • ogaie_chatbot_reply receives the reply text, the reply object, the chatbot parameters and extra data. Use $reply->query for the query. Return the text.

  • ogaie_chatbot_texts receives the chatbot's interface messages, keyed by their English text.
  • ogaie_admin_only_bots returns the chatbot IDs that only administrators may use (default [ 'admin-bot' ]).

Forms (Pro)

ogaie_form_params, ogaie_form_reply, ogaie_form_takeover, ogaie_forms_field_params, ogaie_forms_output_params, ogaie_forms_submit_params, ogaie_forms_upload_params, ogaie_form_reset_params.

AI requests

ogaie_ai_query, ogaie_ai_embeddings_query, ogaie_ai_feedback_query, ogaie_ai_reply, ogaie_ai_feedback, ogaie_ai_instructions, ogaie_ai_context, ogaie_ai_allowed, ogaie_ai_exception, ogaie_ai_mcp_servers, ogaie_placeholders, ogaie_context_search, ogaie_context_framing, ogaie_estimate_tokens, ogaie_estimate_tokens_text, ogaie_request_timeout, ogaie_reply_truncated_notice, ogaie_public_error_message.

  • ogaie_ai_mcp_servers receives the resolved external MCP servers and the query.
  • ogaie_public_error_message receives the message shown to visitors and the exception.

Arguments of the main request hooks:

Hook Arguments Return
ogaie_ai_query $query The query, changed or not. Runs before every text query.
ogaie_ai_embeddings_query, ogaie_ai_feedback_query $query The same, for embeddings and function-call follow-ups.
ogaie_ai_allowed true, $query, array $limits true to allow, or a message or WP_Error to refuse the query.
ogaie_ai_reply $reply, $query The reply.
ogaie_ai_feedback null, $needFeedback, $reply A function result, to answer a function call yourself.
ogaie_ai_exception string $message The error message.
ogaie_ai_context, ogaie_ai_instructions string $instructions, $query The instructions sent to the model.
ogaie_context_search array [], $query, array [ 'embeddingsEnvId', 'streamCallback' ] The context found for the query (Knowledge uses this filter).
ogaie_context_framing string $framing, $context The text that introduces the context.
ogaie_placeholders array $placeholders Placeholders available in instructions.
ogaie_stream_push $data, $query The data streamed to the browser.

Provider fallback

OG AI Core can run a query once on a backup environment when the first one fails. These hooks are answered by the Dynamic API add-on; without it nothing changes.

Hook Arguments Use
ogaie_ai_route null, $query Before sending. Return [ 'envId' => ..., 'model' => ... ] to go to a backup straight away (the first provider is known to be down).
ogaie_ai_failover null, $query, string $message After the provider refused the query. Return the same array to try the backup.
ogaie_ai_fallback_used (action) $query, $backup, string $why, string $message The backup answered. $why is route or failover.
ogaie_ai_fallback_failed (action) $query, $backup, string $why, string $error The backup failed too.

The backup runs on a copy of the query without the first provider's key, only once, never after part of a reply was streamed, and never for a function-calling round.

Knowledge rerank (Pro)

Answered by the Rerank add-on.

Filter Arguments Return
ogaie_context_rerank_pool int 0, array [ 'envId', 'botId' ] How many matches to fetch first (0 = the usual number).
ogaie_context_rerank null, array $matches, array [ 'query', 'minScore', 'maxSelect', 'envId', 'embeddings', 'botId' ] The matches, best first, or null to keep the order.

Engines and models

ogaie_engines, ogaie_engine_models, ogaie_init_engine, ogaie_openai_models, ogaie_anthropic_models, ogaie_perplexity_models, ogaie_xai_models.

Endpoints and request bodies per provider: ogaie_openai_endpoint, ogaie_anthropic_endpoint, ogaie_anthropic_body, ogaie_mistral_endpoint, ogaie_openrouter_endpoint, ogaie_openrouter_body, ogaie_openrouter_site_name, ogaie_openrouter_site_url, ogaie_openrouter_web_plugin, ogaie_ovh_endpoint, ogaie_perplexity_endpoint, ogaie_replicate_endpoint, ogaie_xai_endpoint, ogaie_custom_endpoint, ogaie_google_interactions_body, ogaie_azure_realtime_default_region.

Streaming: ogaie_stream_push, ogaie_stream_keepalive_interval.

Knowledge and embeddings (Pro)

ogaie_embeddings_sync_post, ogaie_embeddings_sync_batch_limit, ogaie_embeddings_sync_time_budget, ogaie_embeddings_sync_remote_files, ogaie_embeddings_vector_metadata, ogaie_embeddings_query_vectors, ogaie_embeddings_add_vector, ogaie_embeddings_get_vector, ogaie_embeddings_list_vectors, ogaie_embeddings_delete_vectors, ogaie_embeddings_upload_file, ogaie_embeddings_refresh_status, ogaie_embeddings_qdrant_vector_size, ogaie_chroma_generate_embedding, ogaie_embedding_max_tokens, ogaie_contentaware_content, ogaie_post_content, ogaie_pre_post_content.

Prompt sections used when the AI rewrites a search: ogaie_embeddings_rewrite_prompt, ogaie_embeddings_task_section, ogaie_embeddings_rules_section, ogaie_embeddings_examples_section, ogaie_embeddings_output_section, ogaie_embeddings_conversation_context_section.

Content tools

Copilot prompts. Each receives the default prompt text and the arguments:

ogaie_prompt_correctText, ogaie_prompt_enhanceText, ogaie_prompt_longerText, ogaie_prompt_shorterText, ogaie_prompt_translateText, ogaie_prompt_translateSection, ogaie_prompt_suggestSynonyms, ogaie_prompt_suggestExcerpts, ogaie_prompt_suggestTitles, ogaie_prompt_generateImage.

add_filter( 'ogaie_prompt_correctText', function ( $prompt, $arguments ) {
    return $prompt . "\nUse British English spelling.";
}, 10, 2 );

ogaie_magic_wand_{action} is a dynamic filter: {action} is the magic wand action. It receives '' and the request data.

ogaie_languages filters the language list.

Functions and MCP

ogaie_functions_list, ogaie_function_call_max_depth, ogaie_mcp_tools, ogaie_mcp_abilities, ogaie_mcp_callback, ogaie_mcp_stream_max_time, ogaie_mcp_self_test_sslverify, ogaie_mcp_oauth_user_can_authorize, ogaie_workspace_self_test_sslverify.

  • ogaie_mcp_callback receives null, the tool name, the arguments, the request ID and the server. Return a result to handle the tool.
  • ogaie_mcp_oauth_user_can_authorize receives the default answer and the user ID.
  • ogaie_mcp_tools receives the list of tool definitions. Each tool has name, description, inputSchema, optional category, annotations and accessLevel (read, write or admin; default admin). See MCP tools.
  • ogaie_mcp_abilities receives the WordPress abilities about to be offered as tools.

Provider balances: ogaie_openrouter_balance_key (the key used to read the credit balance) and ogaie_anthropic_cost_divisor (default 100: the provider reports cost in cents).

Public MCP: ogaie_public_mcp_can_share receives true and a post. Return false to keep that post out of the public server.

Access

ogaie_allow_setup (settings screens and admin routes), ogaie_allow_usage (editor features), ogaie_allow_session, ogaie_allow_public_api, ogaie_allow_mcp, ogaie_rest_authorized, ogaie_blocked_rest_params.

  • ogaie_allow_public_api receives whether the user is logged in, the feature name and extra data.
  • ogaie_allow_mcp receives whether the user can manage_options and the request.
  • ogaie_rest_authorized receives the nonce check result and the request.

Usage and statistics (Pro)

ogaie_stats_credits, ogaie_stats_coins, ogaie_stats_coins_limit, ogaie_stats_logs_list, ogaie_stats_logs_meta, ogaie_stats_logs_delete, ogaie_stats_logs_activity, ogaie_stats_logs_activity_daily, ogaie_stats_logs_activity_daily_by_model, ogaie_statistics_retention_days, ogaie_realtime_count_exchanges, ogaie_seo_stats.

Tasks, files and add-ons

  • ogaie_task_{name} is a dynamic filter for a background task named {name}. It receives null and the job. When nothing answers it, ogaie_task_run gets the same arguments.
  • ogaie_ffmpeg_path receives ''. Return the full path to ffmpeg when it is not on the server's path. It is used to take a frame from a video for AI vision.
  • ogaie_files_delete.
  • ogaie_addon_catalogue receives the list of add-ons that Manage add-ons can install.
  • ogaie_addons receives the cards shown in Settings > Add-ons.

Actions

Action When it fires
ogaie_addons_loaded After the add-ons in wp-content/og-ai-addons are loaded. Receives the loaded add-ons.
ogaie_mcp_tool_called After an MCP tool call, also when it was refused or failed. Receives one array (tool, arguments, result, status, duration and client).
ogaie_mcp_post_changed When an MCP tool changes a post. Receives the post ID and a context.
ogaie_mcp_mutate After an MCP tool that changes data. Receives the tool, arguments and result.
ogaie_mcp_purge_discovery_urls When the MCP discovery addresses should be purged from caches. Receives the URLs.
ogaie_tasks_run When background tasks run.
ogaie_ai_fallback_used, ogaie_ai_fallback_failed When a query switched to a backup environment, and whether it worked. See Provider fallback.
ogaie_lead_capture Call it to save a lead to the Pro Leads screen. Receives one array (source, form, form_id, page_url, page_title, name, email, message, fields, reply, user_id, created_at).

Built-in module hooks

  • CoreMail: ogmail_allow_setup, ogmail_return_path, ogmail_alert_webhook, ogmail_run_phpmailer_init, ogmail_stored_attachment_days, ogmail_stored_attachment_limit.
  • Contact Form: ogcfb_atts, ogcfb_form_html, ogcfb_form_info, ogcfb_form_read_data, ogcfb_form_after_name, ogcfb_form_after_email, ogcfb_form_after_message, ogcfb_validate, ogcfb_redirect_url, ogcfb_client_ip, ogcfb_fill_template, ogcfb_email_to, ogcfb_email_subject, ogcfb_email_content, ogcfb_email_headers, ogcfb_email_placeholders; action ogcfb_form_sent.
  • RSS Images: rfi_rss_image_size.
  • Leads (Pro): ogaie_leads_form_label ($label, $scope, $form_id, $params), ogaie_leads_staff_domains ($domains, default your site's domain); action ogaie_lead_capture. See Leads.
  • Woo Basics (Pro): ogaiwoo_allow_setup, ogaiwoo_allow_usage.
  • Workflow (Pro): ogflow_allow_setup, ogflow_register_integration, ogflow_pass_budget_seconds, ogflow_stall_seconds, ogflow_webhook_rate_limit; actions ogflow_run_done and ogflow_run_failed ($run_id, $flow_id, $error, $mode).

Each module page lists its hooks with their arguments: CoreMail, Contact Form, Workflow.

Add-on hooks

Add-on Hooks
Better Links ogbl_fix_links, ogbl_items, ogbl_related_label, ogbl_thumbnail_cards, ogbl_ssl_verify; action ogbl_links_checked
Content Parser ogcp_parsers, ogcp_output
Custom Model ogcm_allow_setup, ogcm_endpoint, ogcm_request_body, ogcm_discovered_models, ogcm_limit_embedding_tokens, ogcm_mcp_servers, ogcm_mcp_tools_cache_seconds, ogcm_mcp_max_tools, ogcm_mcp_max_result_chars, ogcm_mcp_tool_allowed, ogcm_mcp_call_allowed, ogcm_mcp_call_arguments
Dynamic API ogda_error_kind, ogda_engine_uses_query_key; answers ogaie_ai_route and ogaie_ai_failover
Rerank Answers ogaie_context_rerank_pool, ogaie_context_rerank and ogaie_rerank_texts
Notification Engine ogne_should_send, ogne_email_to, ogne_email_subject, ogne_email_body, ogne_email_headers, ogne_email_attachments, ogne_reply_to, ogne_placeholders, ogne_admin_url, ogne_visitor_key, ogne_trusted_proxies; actions ogne_sent, ogne_failed
User Memory ogaimem_allow_setup, ogaimem_allow_usage, ogaimem_allow_global_memory_write
Web Search ogaiweb_allow_setup, ogaiweb_allow_usage, ogaiweb_google_api_key, ogaiweb_google_search_engine, ogaiweb_tavily_api_key
WooAi ogwa_guest_lookup_limit, ogwa_client_address, ogwa_order_id_from_number, ogwa_order_tracking

Dynamic API:

  • ogda_error_kind receives the kind found by the built-in patterns and the raw error message. Return rate_limit, quota or auth to make the key cool down; anything else only counts the failure.
  • ogda_engine_uses_query_key receives the built-in answer, the environment type and the query type. Return true when an engine sends the per-query key.

Example

add_filter( 'ogaie_chatbot_texts', function ( $texts ) {
    $texts['Connection failed'] = 'We could not reach the assistant. Please try again.';
    return $texts;
} );