WPSEO_Sitemaps_Renderer::encode_and_escape
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():
- esc_url() schema-relative URLs alone, while according to the sitemap specs,
the URL must always begin with a protocol.
- 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() WPSEO Sitemaps Renderer::encode and escape Yoast 27.3
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;
}