WPSEO_Sitemaps_Renderer::encode_and_escape()protectedYoast 1.0

Ensure the URL is encoded per RFC3986 and correctly escaped for use in an XML sitemap.

This method works around a two quirks in esc_url():

  1. esc_url() schema-relative URLs alone, while according to the sitemap specs,
    the URL must always begin with a protocol.
  2. esc_url() ampersands as & instead of the more common &.
    According to the specs, `&` should be used, and even though this shouldn't
    really make a difference in practice, to quote Jono: "I'd be nervous about &
    given how many weird and wonderful things eat sitemaps", so better safe than sorry.

Метод класса: WPSEO_Sitemaps_Renderer{}

Хуков нет.




// protected - в коде основоного (родительского) или дочернего класса
$result = $this->encode_and_escape( $url );
$url(строка) (обязательный)
URL to encode and escape.

Код WPSEO_Sitemaps_Renderer::encode_and_escape() Yoast 20.0

protected function encode_and_escape( $url ) {
	$url = $this->encode_url_rfc3986( $url );
	$url = esc_url( $url );
	$url = str_replace( '&', '&', $url );
	$url = str_replace( ''', ''', $url );

	if ( strpos( $url, '//' ) === 0 ) {
		// Schema-relative URL for which esc_url() does not add a scheme.
		$url = 'http:' . $url;

	return $url;