wpseek.com
A WordPress-centric search engine for devs and theme authors



block_core_navigation_link_maybe_urldecode › WordPress Function

Since6.2.0
Deprecatedn/a
block_core_navigation_link_maybe_urldecode ( $url )
Parameters:
  • (string) $url The url to decode.
    Required: Yes
Returns:
  • (string) $url Returns the decoded url.
Defined at:
Codex:

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



Source

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