| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wp-content/plugins/wordpress-seo/src/initializers/ |
Upload File : |
<?php
namespace Yoast\WP\SEO\Initializers;
use Yoast\WP\SEO\Conditionals\No_Conditionals;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Redirect_Helper;
/**
* Disables the WP core sitemaps.
*/
class Disable_Core_Sitemaps implements Initializer_Interface {
use No_Conditionals;
/**
* The options helper.
*
* @var Options_Helper
*/
private $options;
/**
* The redirect helper.
*
* @var Redirect_Helper
*/
private $redirect;
/**
* Sitemaps_Enabled_Conditional constructor.
*
* @codeCoverageIgnore
*
* @param Options_Helper $options The options helper.
* @param Redirect_Helper $redirect The redirect helper.
*/
public function __construct( Options_Helper $options, Redirect_Helper $redirect ) {
$this->options = $options;
$this->redirect = $redirect;
}
/**
* Disable the WP core XML sitemaps.
*
* @return void
*/
public function initialize() {
// This needs to be on priority 15 as that is after our options initialize.
\add_action( 'plugins_loaded', [ $this, 'maybe_disable_core_sitemaps' ], 15 );
}
/**
* Disables the core sitemaps if Yoast SEO sitemaps are enabled.
*
* @return void
*/
public function maybe_disable_core_sitemaps() {
if ( $this->options->get( 'enable_xml_sitemap' ) ) {
\add_filter( 'wp_sitemaps_enabled', '__return_false' );
\add_action( 'template_redirect', [ $this, 'template_redirect' ], 0 );
}
}
/**
* Redirects requests to the WordPress sitemap to the Yoast sitemap.
*
* @return void
*/
public function template_redirect() {
// If there is no path, nothing to do.
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
return;
}
$path = \sanitize_text_field( \wp_unslash( $_SERVER['REQUEST_URI'] ) );
// If it's not a wp-sitemap request, nothing to do.
if ( \substr( $path, 0, 11 ) !== '/wp-sitemap' ) {
return;
}
$redirect = $this->get_redirect_url( $path );
if ( ! $redirect ) {
return;
}
$this->redirect->do_safe_redirect( \home_url( $redirect ), 301 );
}
/**
* Returns the relative sitemap URL to redirect to.
*
* @param string $path The original path.
*
* @return string|false The path to redirct to. False if no redirect should be done.
*/
private function get_redirect_url( $path ) {
// Start with the simple string comparison so we avoid doing unnecessary regexes.
if ( $path === '/wp-sitemap.xml' ) {
return '/sitemap_index.xml';
}
if ( \preg_match( '/^\/wp-sitemap-(posts|taxonomies)-(\w+)-(\d+)\.xml$/', $path, $matches ) ) {
$index = ( (int) $matches[3] - 1 );
$index = ( $index === 0 ) ? '' : (string) $index;
return '/' . $matches[2] . '-sitemap' . $index . '.xml';
}
if ( \preg_match( '/^\/wp-sitemap-users-(\d+)\.xml$/', $path, $matches ) ) {
$index = ( (int) $matches[1] - 1 );
$index = ( $index === 0 ) ? '' : (string) $index;
return '/author-sitemap' . $index . '.xml';
}
return false;
}
}