wppaste
WordPress

WP_AI_Client_Event_Dispatcher

Since
7.0.0
Source
wp-includes/ai-client/adapters/class-wp-ai-client-event-dispatcher.php:22
WordPress-specific PSR-14 event dispatcher for the AI Client.

Description

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

Compatibility

WordPress
since 7.0.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 2 of the 5 tracked releases, added in 7.0.0.

Hooks and filters fired · 1

Every hook that fires from inside WP_AI_Client_Event_Dispatcher, in the order it appears in the class, grouped by the method that fires it.

Methods · 2

Source code

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;	}}

Changelog

Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.

  1. 7.0.4
  2. 7.1.0

Signature, return type and hooks compared across 2 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/ai-client/adapters/class-wp-ai-client-event-dispatcher.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.