Title: WP_AI_Client_Event_Dispatcher
Published: May 20, 2026

---

# class WP_AI_Client_Event_Dispatcher {}

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/?output_format=md#description)
 * [Methods](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/?output_format=md#wp--skip-link--target)

This class’s access is marked private. This means it is not intended for use by 
plugin or theme developers, only by core. It is listed here for completeness.

WordPress-specific PSR-14 event dispatcher for the AI Client.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/?output_format=md#description)󠁿

Bridges PSR-14 events to WordPress action hooks, enabling plugins to hook into AI
client lifecycle events.

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/?output_format=md#methods)󠁿

| Name | Description | 
| [WP_AI_Client_Event_Dispatcher::dispatch](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/dispatch/) | Dispatches an event to WordPress action hooks. | 
| [WP_AI_Client_Event_Dispatcher::get_hook_name_portion_for_event](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/get_hook_name_portion_for_event/) | Converts an event object class name to a WordPress action hook name portion. |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/?output_format=md#source)󠁿

    ```php
    class WP_AI_Client_Event_Dispatcher implements EventDispatcherInterface {

    	/**
    	 * Dispatches an event to WordPress action hooks.
    	 *
    	 * Converts the event class name to a WordPress action hook name and fires it.
    	 * For example, BeforeGenerateResultEvent becomes wp_ai_client_before_generate_result.
    	 *
    	 * @since 7.0.0
    	 *
    	 * @param object $event The event object to dispatch.
    	 * @return object The same event object, potentially modified by listeners.
    	 */
    	public function dispatch( object $event ): object {
    		$event_name = $this->get_hook_name_portion_for_event( $event );

    		/**
    		 * Fires when an AI client event is dispatched.
    		 *
    		 * The dynamic portion of the hook name, `$event_name`, refers to the
    		 * snake_case version of the event class name, without the `_event` suffix.
    		 *
    		 * For example, an event class named `BeforeGenerateResultEvent` will fire the
    		 * `wp_ai_client_before_generate_result` action hook.
    		 *
    		 * In practice, the available action hook names are:
    		 *
    		 * - wp_ai_client_before_generate_result
    		 * - wp_ai_client_after_generate_result
    		 *
    		 * @since 7.0.0
    		 *
    		 * @param object $event The event object.
    		 */
    		do_action( "wp_ai_client_{$event_name}", $event );

    		return $event;
    	}

    	/**
    	 * Converts an event object class name to a WordPress action hook name portion.
    	 *
    	 * @since 7.0.0
    	 *
    	 * @param object $event The event object.
    	 * @return string The hook name portion derived from the event class name.
    	 */
    	private function get_hook_name_portion_for_event( object $event ): string {
    		$class_name = get_class( $event );
    		$pos        = strrpos( $class_name, '\\' );
    		$short_name = false !== $pos ? substr( $class_name, $pos + 1 ) : $class_name;

    		// Convert PascalCase to snake_case.
    		$snake_case = strtolower( (string) preg_replace( '/([a-z])([A-Z])/', '$1_$2', $short_name ) );

    		// Strip '_event' suffix if present.
    		if ( str_ends_with( $snake_case, '_event' ) ) {
    			$snake_case = (string) substr( $snake_case, 0, -6 );
    		}

    		return $snake_case;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ai-client/adapters/class-wp-ai-client-event-dispatcher.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/ai-client/adapters/class-wp-ai-client-event-dispatcher.php#L22)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/ai-client/adapters/class-wp-ai-client-event-dispatcher.php#L22-L84)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_ai_client_event_dispatcher/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_ai_client_event_dispatcher%2F)
before being able to contribute a note or feedback.