wp_connectors_parse_application_password_credentials()WP 7.1.0

Parses a username:password credentials string.

Splits on the first colon, matching the HTTP Basic authentication userinfo format, so passwords may contain colons.

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Returns

array{username: string, password: string}. Parsed credentials. Both values are empty when the string is malformed.

Usage

wp_connectors_parse_application_password_credentials( $value ): array;
$value(string) (required)
The raw credentials string.

Changelog

Since 7.1.0 Introduced.

wp_connectors_parse_application_password_credentials() code WP 7.1

function wp_connectors_parse_application_password_credentials( string $value ): array {
	$separator = strpos( $value, ':' );
	// Trim so surrounding whitespace or a trailing newline (common when the
	// value comes from a file or `.env`) does not become part of the credentials.
	$username = false === $separator ? '' : trim( substr( $value, 0, $separator ) );
	$password = false === $separator ? '' : trim( substr( $value, $separator + 1 ) );

	if ( '' === $username || '' === $password ) {
		return array(
			'username' => '',
			'password' => '',
		);
	}

	return array(
		'username' => $username,
		'password' => $password,
	);
}