Automattic\WooCommerce\Internal\PushNotifications\Validators

PushTokenValidator::validate_idprivate staticWC 10.6.0

Validates ID.

Method of the class: PushTokenValidator{}

No Hooks.

Returns

true|false|WP_Error.

Usage

$result = PushTokenValidator::validate_id( $value, ?array $context );
$value(mixed) (required)
The value to validate.
?array $context
.
Default: array()

Changelog

Since 10.6.0 Introduced.

PushTokenValidator::validate_id() code WC 10.8.1

private static function validate_id( $value, ?array $context = array() ) {
	if ( is_null( $value ) ) {
		return new WP_Error( self::ERROR_CODE, 'ID is required.' );
	}

	if ( ! is_numeric( $value ) ) {
		return new WP_Error( self::ERROR_CODE, 'ID must be numeric.' );
	}

	if ( $value <= 0 ) {
		return new WP_Error( self::ERROR_CODE, 'ID must be a positive integer.' );
	}

	return true;
}