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
File: class-rewrite.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Frontend
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* This code handles the category rewrites.
[8] Fix | Delete
*/
[9] Fix | Delete
class WPSEO_Rewrite {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Class constructor.
[13] Fix | Delete
*/
[14] Fix | Delete
public function __construct() {
[15] Fix | Delete
add_filter( 'query_vars', [ $this, 'query_vars' ] );
[16] Fix | Delete
add_filter( 'term_link', [ $this, 'no_category_base' ], 10, 3 );
[17] Fix | Delete
add_filter( 'request', [ $this, 'request' ] );
[18] Fix | Delete
add_filter( 'category_rewrite_rules', [ $this, 'category_rewrite_rules' ] );
[19] Fix | Delete
[20] Fix | Delete
add_action( 'created_category', [ $this, 'schedule_flush' ] );
[21] Fix | Delete
add_action( 'edited_category', [ $this, 'schedule_flush' ] );
[22] Fix | Delete
add_action( 'delete_category', [ $this, 'schedule_flush' ] );
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Trigger a rewrite_rule flush on shutdown.
[27] Fix | Delete
*
[28] Fix | Delete
* @since 1.2.8
[29] Fix | Delete
*
[30] Fix | Delete
* @return void
[31] Fix | Delete
*/
[32] Fix | Delete
public function schedule_flush() {
[33] Fix | Delete
add_action( 'shutdown', 'flush_rewrite_rules' );
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Override the category link to remove the category base.
[38] Fix | Delete
*
[39] Fix | Delete
* @param string $link Term link, overridden by the function for categories.
[40] Fix | Delete
* @param WP_Term $term Unused, term object.
[41] Fix | Delete
* @param string $taxonomy Taxonomy slug.
[42] Fix | Delete
*
[43] Fix | Delete
* @return string
[44] Fix | Delete
*/
[45] Fix | Delete
public function no_category_base( $link, $term, $taxonomy ) {
[46] Fix | Delete
if ( $taxonomy !== 'category' ) {
[47] Fix | Delete
return $link;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
$category_base = get_option( 'category_base' );
[51] Fix | Delete
[52] Fix | Delete
if ( empty( $category_base ) ) {
[53] Fix | Delete
$category_base = 'category';
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/*
[57] Fix | Delete
* Remove initial slash, if there is one (we remove the trailing slash
[58] Fix | Delete
* in the regex replacement and don't want to end up short a slash).
[59] Fix | Delete
*/
[60] Fix | Delete
if ( substr( $category_base, 0, 1 ) === '/' ) {
[61] Fix | Delete
$category_base = substr( $category_base, 1 );
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
$category_base .= '/';
[65] Fix | Delete
[66] Fix | Delete
return preg_replace( '`' . preg_quote( $category_base, '`' ) . '`u', '', $link, 1 );
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* Update the query vars with the redirect var when stripcategorybase is active.
[71] Fix | Delete
*
[72] Fix | Delete
* @param array<string> $query_vars Main query vars to filter.
[73] Fix | Delete
*
[74] Fix | Delete
* @return array<string> The query vars.
[75] Fix | Delete
*/
[76] Fix | Delete
public function query_vars( $query_vars ) {
[77] Fix | Delete
if ( WPSEO_Options::get( 'stripcategorybase' ) === true ) {
[78] Fix | Delete
$query_vars[] = 'wpseo_category_redirect';
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
return $query_vars;
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Checks whether the redirect needs to be created.
[86] Fix | Delete
*
[87] Fix | Delete
* @param array<string> $query_vars Query vars to check for existence of redirect var.
[88] Fix | Delete
*
[89] Fix | Delete
* @return array<string> The query vars.
[90] Fix | Delete
*/
[91] Fix | Delete
public function request( $query_vars ) {
[92] Fix | Delete
if ( ! isset( $query_vars['wpseo_category_redirect'] ) ) {
[93] Fix | Delete
return $query_vars;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
$this->redirect( $query_vars['wpseo_category_redirect'] );
[97] Fix | Delete
return [];
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* This function taken and only slightly adapted from WP No Category Base plugin by Saurabh Gupta.
[102] Fix | Delete
*
[103] Fix | Delete
* @return array<string> The category rewrite rules.
[104] Fix | Delete
*/
[105] Fix | Delete
public function category_rewrite_rules() {
[106] Fix | Delete
global $wp_rewrite;
[107] Fix | Delete
[108] Fix | Delete
$category_rewrite = [];
[109] Fix | Delete
[110] Fix | Delete
$taxonomy = get_taxonomy( 'category' );
[111] Fix | Delete
$permalink_structure = get_option( 'permalink_structure' );
[112] Fix | Delete
[113] Fix | Delete
$blog_prefix = '';
[114] Fix | Delete
if ( strpos( $permalink_structure, '/blog/' ) === 0 ) {
[115] Fix | Delete
if ( ( is_multisite() && ! is_subdomain_install() ) || is_main_site() || is_main_network() ) {
[116] Fix | Delete
$blog_prefix = 'blog/';
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
$categories = get_categories( [ 'hide_empty' => false ] );
[121] Fix | Delete
if ( is_array( $categories ) && $categories !== [] ) {
[122] Fix | Delete
foreach ( $categories as $category ) {
[123] Fix | Delete
$category_nicename = $category->slug;
[124] Fix | Delete
if ( $category->parent === $category->cat_ID ) {
[125] Fix | Delete
// Recursive recursion.
[126] Fix | Delete
$category->parent = 0;
[127] Fix | Delete
}
[128] Fix | Delete
elseif ( $taxonomy->rewrite['hierarchical'] !== false && $category->parent !== 0 ) {
[129] Fix | Delete
$parents = get_category_parents( $category->parent, false, '/', true );
[130] Fix | Delete
if ( ! is_wp_error( $parents ) ) {
[131] Fix | Delete
$category_nicename = $parents . $category_nicename;
[132] Fix | Delete
}
[133] Fix | Delete
unset( $parents );
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
$category_rewrite = $this->add_category_rewrites( $category_rewrite, $category_nicename, $blog_prefix, $wp_rewrite->pagination_base );
[137] Fix | Delete
[138] Fix | Delete
// Adds rules for the uppercase encoded URIs.
[139] Fix | Delete
$category_nicename_filtered = $this->convert_encoded_to_upper( $category_nicename );
[140] Fix | Delete
[141] Fix | Delete
if ( $category_nicename_filtered !== $category_nicename ) {
[142] Fix | Delete
$category_rewrite = $this->add_category_rewrites( $category_rewrite, $category_nicename_filtered, $blog_prefix, $wp_rewrite->pagination_base );
[143] Fix | Delete
}
[144] Fix | Delete
}
[145] Fix | Delete
unset( $categories, $category, $category_nicename, $category_nicename_filtered );
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
// Redirect support from Old Category Base.
[149] Fix | Delete
$old_base = $wp_rewrite->get_category_permastruct();
[150] Fix | Delete
$old_base = str_replace( '%category%', '(.+)', $old_base );
[151] Fix | Delete
$old_base = trim( $old_base, '/' );
[152] Fix | Delete
$category_rewrite[ $old_base . '$' ] = 'index.php?wpseo_category_redirect=$matches[1]';
[153] Fix | Delete
[154] Fix | Delete
return $category_rewrite;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Adds required category rewrites rules.
[159] Fix | Delete
*
[160] Fix | Delete
* @param array<string> $rewrites The current set of rules.
[161] Fix | Delete
* @param string $category_name Category nicename.
[162] Fix | Delete
* @param string $blog_prefix Multisite blog prefix.
[163] Fix | Delete
* @param string $pagination_base WP_Query pagination base.
[164] Fix | Delete
*
[165] Fix | Delete
* @return array<string> The added set of rules.
[166] Fix | Delete
*/
[167] Fix | Delete
protected function add_category_rewrites( $rewrites, $category_name, $blog_prefix, $pagination_base ) {
[168] Fix | Delete
$rewrite_name = $blog_prefix . '(' . $category_name . ')';
[169] Fix | Delete
[170] Fix | Delete
global $wp_rewrite;
[171] Fix | Delete
$feed_regex = '(' . implode( '|', $wp_rewrite->feeds ) . ')';
[172] Fix | Delete
[173] Fix | Delete
$rewrites[ $rewrite_name . '/(?:feed/)?' . $feed_regex . '/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
[174] Fix | Delete
$rewrites[ $rewrite_name . '/' . $pagination_base . '/?([0-9]{1,})/?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
[175] Fix | Delete
$rewrites[ $rewrite_name . '/?$' ] = 'index.php?category_name=$matches[1]';
[176] Fix | Delete
[177] Fix | Delete
return $rewrites;
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* Walks through category nicename and convert encoded parts
[182] Fix | Delete
* into uppercase using $this->encode_to_upper().
[183] Fix | Delete
*
[184] Fix | Delete
* @param string $name The encoded category URI string.
[185] Fix | Delete
*
[186] Fix | Delete
* @return string The convered URI string.
[187] Fix | Delete
*/
[188] Fix | Delete
protected function convert_encoded_to_upper( $name ) {
[189] Fix | Delete
// Checks if name has any encoding in it.
[190] Fix | Delete
if ( strpos( $name, '%' ) === false ) {
[191] Fix | Delete
return $name;
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
$names = explode( '/', $name );
[195] Fix | Delete
$names = array_map( [ $this, 'encode_to_upper' ], $names );
[196] Fix | Delete
[197] Fix | Delete
return implode( '/', $names );
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Converts the encoded URI string to uppercase.
[202] Fix | Delete
*
[203] Fix | Delete
* @param string $encoded The encoded string.
[204] Fix | Delete
*
[205] Fix | Delete
* @return string The uppercased string.
[206] Fix | Delete
*/
[207] Fix | Delete
public function encode_to_upper( $encoded ) {
[208] Fix | Delete
if ( strpos( $encoded, '%' ) === false ) {
[209] Fix | Delete
return $encoded;
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
return strtoupper( $encoded );
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* Redirect the "old" category URL to the new one.
[217] Fix | Delete
*
[218] Fix | Delete
* @codeCoverageIgnore
[219] Fix | Delete
*
[220] Fix | Delete
* @param string $category_redirect The category page to redirect to.
[221] Fix | Delete
* @return void
[222] Fix | Delete
*/
[223] Fix | Delete
protected function redirect( $category_redirect ) {
[224] Fix | Delete
$catlink = trailingslashit( get_option( 'home' ) ) . user_trailingslashit( $category_redirect, 'category' );
[225] Fix | Delete
[226] Fix | Delete
wp_safe_redirect( $catlink, 301, 'Yoast SEO' );
[227] Fix | Delete
exit;
[228] Fix | Delete
}
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function