WPSEO_Sitemaps_Router::needs_sitemap_index_redirect() public Yoast 1.0
Checks whether the current request needs to be redirected to sitemap_index.xml.
{} Это метод класса: WPSEO_Sitemaps_Router{}
Хуков нет.
Возвращает
true/false. True if redirect is needed, false otherwise.
Использование
$WPSEO_Sitemaps_Router = new WPSEO_Sitemaps_Router(); $WPSEO_Sitemaps_Router->needs_sitemap_index_redirect();
Заметки
- Global. WP_Query. $wp_query Current query.
Код WPSEO_Sitemaps_Router::needs_sitemap_index_redirect() WPSEO Sitemaps Router::needs sitemap index redirect Yoast 15.9.1
public function needs_sitemap_index_redirect() {
global $wp_query;
$protocol = 'http://';
if ( ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) {
$protocol = 'https://';
}
$domain = '';
if ( isset( $_SERVER['SERVER_NAME'] ) ) {
$domain = sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) );
}
$path = '';
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
$path = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) );
}
// Due to different environment configurations, we need to check both SERVER_NAME and HTTP_HOST.
$check_urls = [ $protocol . $domain . $path ];
if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
$check_urls[] = $protocol . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . $path;
}
return $wp_query->is_404 && in_array( home_url( '/sitemap.xml' ), $check_urls, true );
}