WC_Tracks_Event::validate_and_sanitize()public staticWC 1.0

Annotate the event with all relevant info.

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

Хуков нет.

Возвращает

true|false|WP_Error. True on success, WP_Error on failure.

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

$result = WC_Tracks_Event::validate_and_sanitize( $event );
$event(массив) (обязательный)
Event arguments.

Код WC_Tracks_Event::validate_and_sanitize() WC 8.7.0

public static function validate_and_sanitize( $event ) {
	$event = (object) $event;

	// Required.
	if ( ! $event->_en ) {
		return new WP_Error( 'invalid_event', 'A valid event must be specified via `_en`', 400 );
	}

	// Delete non-routable addresses otherwise geoip will discard the record entirely.
	if ( property_exists( $event, '_via_ip' ) && preg_match( '/^192\.168|^10\./', $event->_via_ip ) ) {
		unset( $event->_via_ip );
	}

	$validated = array(
		'browser_type' => WC_Tracks_Client::BROWSER_TYPE,
	);

	$_event = (object) array_merge( (array) $event, $validated );

	// If you want to block property names, do it here.
	// Make sure we have an event timestamp.
	if ( ! isset( $_event->_ts ) ) {
		$_event->_ts = WC_Tracks_Client::build_timestamp();
	}

	if ( ! self::event_name_is_valid( $_event->_en ) ) {
		return new WP_Error( 'invalid_event_name', __( 'A valid event name must be specified.', 'woocommerce' ) );
	}

	foreach ( array_keys( (array) $_event ) as $key ) {
		if ( ! self::prop_name_is_valid( $key ) && '_en' !== $key ) {
			return new WP_Error( 'invalid_prop_name', __( 'A valid prop name must be specified', 'woocommerce' ) );
		}
	}

	return $_event;
}