WP_AI_Client_Event_Dispatcher::get_hook_name_portion_for_event │ private │ WP 7.0.0

Converts an event object class name to a WordPress action hook name portion.

Метод класса: WP_AI_Client_Event_Dispatcher{}

Хуков нет.

Возвращает

string. The hook name portion derived from the event class name.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_hook_name_portion_for_event( $event ): string;
$event(объект) (обязательный)
The event object.

Список изменений

С версии 7.0.0 Введена.

Код WP_AI_Client_Event_Dispatcher::get_hook_name_portion_for_event() WP 7.1.2

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