Automattic\WooCommerce\Internal\Abilities

AbilitiesTracking::add_event │ private │ WC 1.0

Queue a finished invocation as an ability_called event.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->add_event( $frame, $outcome, $has_duration ): void;
$frame(array{name: string, channel: string, rest_namespace: string, external_client: string, start: float, executing: bool}) (обязательный)
The invocation.
$outcome(true|WP_Error|null) (обязательный)
True for success, a WP_Error for a known failure, null for an unknown failure.
$has_duration(true|false) (обязательный)
Whether the duration is known.

Код AbilitiesTracking::add_event() WC 11.3.0

private function add_event( array $frame, $outcome, bool $has_duration ): void {
	$error_code = self::NONE;
	if ( $outcome instanceof WP_Error ) {
		$error_code = self::get_error_code( $outcome );
	} elseif ( null === $outcome ) {
		$error_code = 'unknown';
	}

	$event = array(
		'ability_name'    => self::get_event_ability_name( $frame['name'] ),
		'outcome'         => true === $outcome ? 'success' : 'error',
		'error_code'      => $error_code,
		'channel'         => $frame['channel'],
		'rest_namespace'  => $frame['rest_namespace'],
		'external_client' => $frame['external_client'],
	);
	if ( $has_duration ) {
		$event['duration_ms'] = (int) round( ( microtime( true ) - $frame['start'] ) * 1000 );
	}

	// Unknown failures are recorded later than the call (WordPress 7.0 has no hook for them), so they keep the call's
	// start time. Site and user are still read now; they differ only if the request switched them since.
	$this->queue_event( self::EVENT_NAME, $event, null === $outcome ? $frame['start'] : null );
}