@return void|never */ public function setContext( $type, $fileName = 'sitemap', $indexName = 'root', $pageNumber = 0 ) { $indexesEnabled = aioseo()->options->sitemap->{$type}->indexes; aioseo()->sitemap->type = $type; aioseo()->sitemap->filename = $fileName; aioseo()->sitemap->indexes = $indexesEnabled; aioseo()->sitemap->indexName = $indexName; aioseo()->sitemap->linksPerIndex = aioseo()->options->sitemap->{$type}->linksPerIndex <= 50000 ? aioseo()->options->sitemap->{$type}->linksPerIndex : 50000; aioseo()->sitemap->pageNumber = $pageNumber >= 1 ? $pageNumber - 1 : 0; aioseo()->sitemap->offset = aioseo()->sitemap->linksPerIndex * aioseo()->sitemap->pageNumber; aioseo()->sitemap->isStatic = false; } /** * Redirects or alters the current request if: * 1. The request includes our deprecated "aiosp_sitemap_path" URL param. * 2. The request is for one of our sitemaps, but has a trailing slash. * 3. The request is for the first index of a type, but has a page number. * 4. The request is for a sitemap from WordPress Core/other plugin. * * @since 4.2.1 */ protected function maybeRedirect() { if ( $this->checkedForRedirects ) { return; } $this->checkedForRedirects = true; // The request includes our deprecated "aiosp_sitemap_path" URL param. if ( preg_match( '/^\/\?aiosp_sitemap_path=root/i', $_SERVER['REQUEST_URI'] ) ) { wp_safe_redirect( home_url( 'sitemap.xml' ) ); exit; } // The request is for one of our sitemaps, but has a trailing slash. if ( preg_match( '/\/(.*sitemap[0-9]*?\.xml(\.gz)?|.*sitemap(\.latest)?\.rss)\/$/i', $_SERVER['REQUEST_URI'] ) ) { wp_safe_redirect( home_url() . untrailingslashit( $_SERVER['REQUEST_URI'] ) ); exit; } // The request is for the first index of a type, but has a page number. if ( preg_match( '/.*sitemap(0|1){1}?\.xml(\.gz)?$/i', $_SERVER['REQUEST_URI'] ) ) { $pathWithoutNumber = preg_replace( '/(.*sitemap)(0|1){1}?(\.xml(\.gz)?)$/i', '$1$3', $_SERVER['REQUEST_URI'] ); wp_safe_redirect( home_url() . $pathWithoutNumber ); exit; } // The request is for a sitemap from WordPress Core/other plugin, but the general sitemap is enabled. if ( ! aioseo()->options->sitemap->general->enable ) { return; } $sitemapPatterns = [ 'general' => [ 'sitemap\.txt', 'sitemaps\.xml', 'sitemap-xml\.xml', 'sitemap[0-9]+\.xml', 'sitemap(|[-_\/])?index[0-9]*\.xml', 'wp-sitemap\.xml', ], 'rss' => [ 'rss[0-9]*\.xml', ] ]; $addonSitemapPatterns = aioseo()->addons->doAddonFunction( 'helpers', 'getOtherSitemapPatterns' ); if ( ! empty( $addonSitemapPatterns ) ) { $sitemapPatterns = array_merge( $sitemapPatterns, $addonSitemapPatterns ); } foreach ( $sitemapPatterns as $type => $patterns ) { foreach ( $patterns as $pattern ) { if ( preg_match( "/^$pattern$/i", $this->slug ) ) { wp_safe_redirect( aioseo()->sitemap->helpers->getUrl( $type ) ); exit; } } } } }