wp_connectors_parse_application_password_credentials( string $value ): array{username:

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Parses a username:password credentials string.

Description

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

Parameters

$valuestringrequired
The raw credentials string.

Return

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

Source

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

Changelog

VersionDescription
7.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.