block_core_navigation_link_maybe_urldecode()WP 6.2.0

Decodes a url if it's encoded, returning the same url if not.

Хуков нет.

Возвращает

Строку. $url Returns the decoded url.

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

block_core_navigation_link_maybe_urldecode( $url );
$url(строка) (обязательный)
The url to decode.

Список изменений

С версии 6.2.0 Введена.

Код block_core_navigation_link_maybe_urldecode() WP 6.6

function block_core_navigation_link_maybe_urldecode( $url ) {
	$is_url_encoded = false;
	$query          = parse_url( $url, PHP_URL_QUERY );
	$query_params   = wp_parse_args( $query );

	foreach ( $query_params as $query_param ) {
		$can_query_param_be_encoded = is_string( $query_param ) && ! empty( $query_param );
		if ( ! $can_query_param_be_encoded ) {
			continue;
		}
		if ( rawurldecode( $query_param ) !== $query_param ) {
			$is_url_encoded = true;
			break;
		}
	}

	if ( $is_url_encoded ) {
		return rawurldecode( $url );
	}

	return $url;
}