WPSEO_Sitemaps::redirect
Hijack requests for potential sitemaps and XSL files.
Метод класса: WPSEO_Sitemaps{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$WPSEO_Sitemaps = new WPSEO_Sitemaps(); $WPSEO_Sitemaps->redirect( $query );
- $query(WP_Query) (обязательный)
- Main query instance.
Код WPSEO_Sitemaps::redirect() WPSEO Sitemaps::redirect Yoast 28.3
public function redirect( $query ) {
if ( ! $query->is_main_query() ) {
return;
}
$yoast_sitemap_xsl = get_query_var( 'yoast-sitemap-xsl' );
if ( ! empty( $yoast_sitemap_xsl ) ) {
/*
* This is a method to provide the XSL via the home_url.
* Needed when the site_url and home_url are not the same.
* Loading the XSL needs to come from the same domain, protocol and port as the XML.
*
* Whenever home_url and site_url are the same, the file can be loaded directly.
*/
$this->xsl_output( $yoast_sitemap_xsl );
$this->sitemap_close();
return;
}
$type = get_query_var( 'sitemap' );
if ( empty( $type ) ) {
return;
}
if ( get_query_var( 'sitemap_n' ) === '1' || get_query_var( 'sitemap_n' ) === '0' ) {
wp_safe_redirect( home_url( "/$type-sitemap.xml" ), 301, 'Yoast SEO' );
exit();
}
$this->set_n( get_query_var( 'sitemap_n' ) );
if ( ! $this->get_sitemap_from_cache( $type, $this->current_page ) ) {
$this->build_sitemap( $type );
}
if ( $this->bad_sitemap ) {
$query->set_404();
status_header( 404 );
return;
}
$this->output();
$this->sitemap_close();
}