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.../inc/sitemaps
File: class-sitemaps-router.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\XML_Sitemaps
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
use Yoast\WP\SEO\Conditionals\Deactivating_Yoast_Seo_Conditional;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Rewrite setup and handling for sitemaps functionality.
[10] Fix | Delete
*/
[11] Fix | Delete
class WPSEO_Sitemaps_Router {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Sets up init logic.
[15] Fix | Delete
*/
[16] Fix | Delete
public function __construct() {
[17] Fix | Delete
// If we add rewrite rules during the plugin's deactivation, the flush_rewrite_rules that we perform afterwards won't properly flush those new rules.
[18] Fix | Delete
if ( YoastSEO()->classes->get( Deactivating_Yoast_Seo_Conditional::class )->is_met() ) {
[19] Fix | Delete
return;
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
add_action( 'yoast_add_dynamic_rewrite_rules', [ $this, 'add_rewrite_rules' ] );
[23] Fix | Delete
add_filter( 'query_vars', [ $this, 'add_query_vars' ] );
[24] Fix | Delete
[25] Fix | Delete
add_filter( 'redirect_canonical', [ $this, 'redirect_canonical' ] );
[26] Fix | Delete
add_action( 'template_redirect', [ $this, 'template_redirect' ], 0 );
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Adds rewrite routes for sitemaps.
[31] Fix | Delete
*
[32] Fix | Delete
* @param Yoast_Dynamic_Rewrites $dynamic_rewrites Dynamic rewrites handler instance.
[33] Fix | Delete
*
[34] Fix | Delete
* @return void
[35] Fix | Delete
*/
[36] Fix | Delete
public function add_rewrite_rules( $dynamic_rewrites ) {
[37] Fix | Delete
$dynamic_rewrites->add_rule( 'sitemap_index\.xml$', 'index.php?sitemap=1', 'top' );
[38] Fix | Delete
$dynamic_rewrites->add_rule( '([^/]+?)-sitemap([0-9]+)?\.xml$', 'index.php?sitemap=$matches[1]&sitemap_n=$matches[2]', 'top' );
[39] Fix | Delete
$dynamic_rewrites->add_rule( '([a-z]+)?-?sitemap\.xsl$', 'index.php?yoast-sitemap-xsl=$matches[1]', 'top' );
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Adds query variables for sitemaps.
[44] Fix | Delete
*
[45] Fix | Delete
* @param array<string> $query_vars List of query variables to filter.
[46] Fix | Delete
*
[47] Fix | Delete
* @return array<string> Filtered query variables.
[48] Fix | Delete
*/
[49] Fix | Delete
public function add_query_vars( $query_vars ) {
[50] Fix | Delete
$query_vars[] = 'sitemap';
[51] Fix | Delete
$query_vars[] = 'sitemap_n';
[52] Fix | Delete
$query_vars[] = 'yoast-sitemap-xsl';
[53] Fix | Delete
[54] Fix | Delete
return $query_vars;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Sets up rewrite rules.
[59] Fix | Delete
*
[60] Fix | Delete
* @deprecated 21.8
[61] Fix | Delete
* @codeCoverageIgnore
[62] Fix | Delete
*
[63] Fix | Delete
* @return void
[64] Fix | Delete
*/
[65] Fix | Delete
public function init() {
[66] Fix | Delete
_deprecated_function( __METHOD__, 'Yoast SEO 21.8' );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Stop trailing slashes on sitemap.xml URLs.
[71] Fix | Delete
*
[72] Fix | Delete
* @param string $redirect The redirect URL currently determined.
[73] Fix | Delete
*
[74] Fix | Delete
* @return bool|string
[75] Fix | Delete
*/
[76] Fix | Delete
public function redirect_canonical( $redirect ) {
[77] Fix | Delete
[78] Fix | Delete
if ( get_query_var( 'sitemap' ) || get_query_var( 'yoast-sitemap-xsl' ) ) {
[79] Fix | Delete
return false;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
return $redirect;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Redirects sitemap.xml to sitemap_index.xml.
[87] Fix | Delete
*
[88] Fix | Delete
* @return void
[89] Fix | Delete
*/
[90] Fix | Delete
public function template_redirect() {
[91] Fix | Delete
if ( ! $this->needs_sitemap_index_redirect() ) {
[92] Fix | Delete
return;
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
YoastSEO()->helpers->redirect->do_safe_redirect( home_url( '/sitemap_index.xml' ), 301, 'Yoast SEO' );
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Checks whether the current request needs to be redirected to sitemap_index.xml.
[100] Fix | Delete
*
[101] Fix | Delete
* @global WP_Query $wp_query Current query.
[102] Fix | Delete
*
[103] Fix | Delete
* @return bool True if redirect is needed, false otherwise.
[104] Fix | Delete
*/
[105] Fix | Delete
public function needs_sitemap_index_redirect() {
[106] Fix | Delete
global $wp_query;
[107] Fix | Delete
[108] Fix | Delete
$protocol = 'http://';
[109] Fix | Delete
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
[110] Fix | Delete
if ( ! empty( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) === 'on' ) {
[111] Fix | Delete
$protocol = 'https://';
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$domain = '';
[115] Fix | Delete
if ( isset( $_SERVER['SERVER_NAME'] ) ) {
[116] Fix | Delete
$domain = sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) );
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
$path = '';
[120] Fix | Delete
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
[121] Fix | Delete
$path = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) );
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
// Due to different environment configurations, we need to check both SERVER_NAME and HTTP_HOST.
[125] Fix | Delete
$check_urls = [ $protocol . $domain . $path ];
[126] Fix | Delete
if ( ! empty( $_SERVER['HTTP_HOST'] ) ) {
[127] Fix | Delete
$check_urls[] = $protocol . sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) . $path;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
return $wp_query->is_404 && in_array( home_url( '/sitemap.xml' ), $check_urls, true );
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* Create base URL for the sitemap.
[135] Fix | Delete
*
[136] Fix | Delete
* @param string $page Page to append to the base URL.
[137] Fix | Delete
*
[138] Fix | Delete
* @return string base URL (incl page)
[139] Fix | Delete
*/
[140] Fix | Delete
public static function get_base_url( $page ) {
[141] Fix | Delete
[142] Fix | Delete
global $wp_rewrite;
[143] Fix | Delete
[144] Fix | Delete
$base = $wp_rewrite->using_index_permalinks() ? 'index.php/' : '/';
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Filter the base URL of the sitemaps.
[148] Fix | Delete
*
[149] Fix | Delete
* @param string $base The string that should be added to home_url() to make the full base URL.
[150] Fix | Delete
*/
[151] Fix | Delete
$base = apply_filters( 'wpseo_sitemaps_base_url', $base );
[152] Fix | Delete
[153] Fix | Delete
/*
[154] Fix | Delete
* Get the scheme from the configured home URL instead of letting WordPress
[155] Fix | Delete
* determine the scheme based on the requested URI.
[156] Fix | Delete
*/
[157] Fix | Delete
return home_url( $base . $page, wp_parse_url( get_option( 'home' ), PHP_URL_SCHEME ) );
[158] Fix | Delete
}
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function