Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordpres.../src/initiali...
File: disable-core-sitemaps.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Initializers;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Conditionals\No_Conditionals;
[4] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[5] Fix | Delete
use Yoast\WP\SEO\Helpers\Redirect_Helper;
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Disables the WP core sitemaps.
[9] Fix | Delete
*/
[10] Fix | Delete
class Disable_Core_Sitemaps implements Initializer_Interface {
[11] Fix | Delete
[12] Fix | Delete
use No_Conditionals;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* The options helper.
[16] Fix | Delete
*
[17] Fix | Delete
* @var Options_Helper
[18] Fix | Delete
*/
[19] Fix | Delete
private $options;
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* The redirect helper.
[23] Fix | Delete
*
[24] Fix | Delete
* @var Redirect_Helper
[25] Fix | Delete
*/
[26] Fix | Delete
private $redirect;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Sitemaps_Enabled_Conditional constructor.
[30] Fix | Delete
*
[31] Fix | Delete
* @codeCoverageIgnore
[32] Fix | Delete
*
[33] Fix | Delete
* @param Options_Helper $options The options helper.
[34] Fix | Delete
* @param Redirect_Helper $redirect The redirect helper.
[35] Fix | Delete
*/
[36] Fix | Delete
public function __construct( Options_Helper $options, Redirect_Helper $redirect ) {
[37] Fix | Delete
$this->options = $options;
[38] Fix | Delete
$this->redirect = $redirect;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Disable the WP core XML sitemaps.
[43] Fix | Delete
*
[44] Fix | Delete
* @return void
[45] Fix | Delete
*/
[46] Fix | Delete
public function initialize() {
[47] Fix | Delete
// This needs to be on priority 15 as that is after our options initialize.
[48] Fix | Delete
\add_action( 'plugins_loaded', [ $this, 'maybe_disable_core_sitemaps' ], 15 );
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Disables the core sitemaps if Yoast SEO sitemaps are enabled.
[53] Fix | Delete
*
[54] Fix | Delete
* @return void
[55] Fix | Delete
*/
[56] Fix | Delete
public function maybe_disable_core_sitemaps() {
[57] Fix | Delete
if ( $this->options->get( 'enable_xml_sitemap' ) ) {
[58] Fix | Delete
\add_filter( 'wp_sitemaps_enabled', '__return_false' );
[59] Fix | Delete
[60] Fix | Delete
\add_action( 'template_redirect', [ $this, 'template_redirect' ], 0 );
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Redirects requests to the WordPress sitemap to the Yoast sitemap.
[66] Fix | Delete
*
[67] Fix | Delete
* @return void
[68] Fix | Delete
*/
[69] Fix | Delete
public function template_redirect() {
[70] Fix | Delete
// If there is no path, nothing to do.
[71] Fix | Delete
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
[72] Fix | Delete
return;
[73] Fix | Delete
}
[74] Fix | Delete
$path = \sanitize_text_field( \wp_unslash( $_SERVER['REQUEST_URI'] ) );
[75] Fix | Delete
[76] Fix | Delete
// If it's not a wp-sitemap request, nothing to do.
[77] Fix | Delete
if ( \substr( $path, 0, 11 ) !== '/wp-sitemap' ) {
[78] Fix | Delete
return;
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
$redirect = $this->get_redirect_url( $path );
[82] Fix | Delete
[83] Fix | Delete
if ( ! $redirect ) {
[84] Fix | Delete
return;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
$this->redirect->do_safe_redirect( \home_url( $redirect ), 301 );
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Returns the relative sitemap URL to redirect to.
[92] Fix | Delete
*
[93] Fix | Delete
* @param string $path The original path.
[94] Fix | Delete
*
[95] Fix | Delete
* @return string|false The path to redirct to. False if no redirect should be done.
[96] Fix | Delete
*/
[97] Fix | Delete
private function get_redirect_url( $path ) {
[98] Fix | Delete
// Start with the simple string comparison so we avoid doing unnecessary regexes.
[99] Fix | Delete
if ( $path === '/wp-sitemap.xml' ) {
[100] Fix | Delete
return '/sitemap_index.xml';
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
if ( \preg_match( '/^\/wp-sitemap-(posts|taxonomies)-(\w+)-(\d+)\.xml$/', $path, $matches ) ) {
[104] Fix | Delete
$index = ( (int) $matches[3] - 1 );
[105] Fix | Delete
$index = ( $index === 0 ) ? '' : (string) $index;
[106] Fix | Delete
[107] Fix | Delete
return '/' . $matches[2] . '-sitemap' . $index . '.xml';
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
if ( \preg_match( '/^\/wp-sitemap-users-(\d+)\.xml$/', $path, $matches ) ) {
[111] Fix | Delete
$index = ( (int) $matches[1] - 1 );
[112] Fix | Delete
$index = ( $index === 0 ) ? '' : (string) $index;
[113] Fix | Delete
[114] Fix | Delete
return '/author-sitemap' . $index . '.xml';
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
return false;
[118] Fix | Delete
}
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function