WPSEO_Sitemaps_Router::needs_sitemap_index_redirect
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_queryCurrent query.
Код WPSEO_Sitemaps_Router::needs_sitemap_index_redirect() WPSEO Sitemaps Router::needs sitemap index redirect Yoast 27.3
public function needs_sitemap_index_redirect() {
global $wp_query;
$protocol = 'http://';
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( ! empty( $_SERVER['HTTPS'] ) && strtolower( $_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 );
}