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/wp-conte.../plugins/sitepres.../inc/absolute...
File: absolute-links.class.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class AbsoluteLinks {
[2] Fix | Delete
/** @var array */
[3] Fix | Delete
public $custom_post_query_vars = [];
[4] Fix | Delete
[5] Fix | Delete
/** @var array */
[6] Fix | Delete
public $taxonomies_query_vars = [];
[7] Fix | Delete
[8] Fix | Delete
/** @var array */
[9] Fix | Delete
private $active_languages;
[10] Fix | Delete
[11] Fix | Delete
public function __construct() {
[12] Fix | Delete
if ( did_action( 'init' ) ) {
[13] Fix | Delete
$this->init_query_vars();
[14] Fix | Delete
} else {
[15] Fix | Delete
// init_query_vars is using $wp_taxonomies.
[16] Fix | Delete
// We have to change priority of our action
[17] Fix | Delete
// to make sure that all custom taxonomies are already registered.
[18] Fix | Delete
add_action( 'init', [ $this, 'init_query_vars' ], 1000 );
[19] Fix | Delete
}
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
public function init_query_vars() {
[23] Fix | Delete
global $wp_post_types, $wp_taxonomies;
[24] Fix | Delete
[25] Fix | Delete
// Custom posts query vars.
[26] Fix | Delete
foreach ( $wp_post_types as $k => $v ) {
[27] Fix | Delete
if ( 'post' === $k || 'page' === $k ) {
[28] Fix | Delete
continue;
[29] Fix | Delete
}
[30] Fix | Delete
if ( $v->query_var ) {
[31] Fix | Delete
$this->custom_post_query_vars[ $k ] = $v->query_var;
[32] Fix | Delete
}
[33] Fix | Delete
}
[34] Fix | Delete
// Taxonomies query vars.
[35] Fix | Delete
foreach ( $wp_taxonomies as $k => $v ) {
[36] Fix | Delete
if ( 'category' === $k ) {
[37] Fix | Delete
continue;
[38] Fix | Delete
}
[39] Fix | Delete
if ( 'post_tag' === $k && ! $v->query_var ) {
[40] Fix | Delete
$tag_base = get_option( 'tag_base', 'tag' );
[41] Fix | Delete
$v->query_var = $tag_base;
[42] Fix | Delete
}
[43] Fix | Delete
if ( $v->query_var ) {
[44] Fix | Delete
$this->taxonomies_query_vars[ $k ] = $v->query_var;
[45] Fix | Delete
}
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
public function _process_generic_text( $source_text, &$alp_broken_links ) {
[51] Fix | Delete
global $wpdb, $wp_rewrite, $sitepress, $sitepress_settings;
[52] Fix | Delete
$sitepress_settings = $sitepress->get_settings();
[53] Fix | Delete
[54] Fix | Delete
$default_language = $sitepress->get_default_language();
[55] Fix | Delete
$current_language = $sitepress->get_current_language();
[56] Fix | Delete
[57] Fix | Delete
$cache_key_args = [
[58] Fix | Delete
$default_language,
[59] Fix | Delete
$current_language,
[60] Fix | Delete
md5( $source_text ),
[61] Fix | Delete
md5( implode( '', $alp_broken_links ) ),
[62] Fix | Delete
];
[63] Fix | Delete
$cache_key = md5( wp_json_encode( $cache_key_args ) );
[64] Fix | Delete
$cache_group = '_process_generic_text';
[65] Fix | Delete
$found = false;
[66] Fix | Delete
[67] Fix | Delete
$text = WPML_Non_Persistent_Cache::get( $cache_key, $cache_group, $found );
[68] Fix | Delete
[69] Fix | Delete
if ( $found ) {
[70] Fix | Delete
return $text;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
$filtered_icl_post_language = filter_input( INPUT_POST, 'icl_post_language', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
[74] Fix | Delete
[75] Fix | Delete
$block_protector = new \WPML\AbsoluteLinks\BlockProtector();
[76] Fix | Delete
[77] Fix | Delete
$text = $block_protector->protect( $source_text );
[78] Fix | Delete
[79] Fix | Delete
// We need to loop over each language so we create sticky links for all languages.
[80] Fix | Delete
$this->active_languages = array_keys( $sitepress->get_active_languages() );
[81] Fix | Delete
$current_language = empty( $filtered_icl_post_language ) ? $current_language : $filtered_icl_post_language;
[82] Fix | Delete
if ( ! empty( $current_language ) ) {
[83] Fix | Delete
$key = array_search( $current_language, $this->active_languages, true );
[84] Fix | Delete
if ( false !== $key ) {
[85] Fix | Delete
unset( $this->active_languages[ $key ] );
[86] Fix | Delete
}
[87] Fix | Delete
array_unshift( $this->active_languages, $current_language );
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
$blacklist_requests = new WPML_Absolute_Links_Blacklist(
[91] Fix | Delete
apply_filters( 'wpml_sl_blacklist_requests', [], $sitepress )
[92] Fix | Delete
);
[93] Fix | Delete
[94] Fix | Delete
foreach ( $this->active_languages as $test_language ) {
[95] Fix | Delete
$rewrite = $this->initialize_rewrite( $current_language, $default_language, $sitepress );
[96] Fix | Delete
[97] Fix | Delete
$home_url = $sitepress->language_url( $test_language );
[98] Fix | Delete
[99] Fix | Delete
if ( 3 === $sitepress_settings['language_negotiation_type'] ) {
[100] Fix | Delete
$home_url = preg_replace( '#\?lang=([a-z-]+)#i', '', $home_url );
[101] Fix | Delete
}
[102] Fix | Delete
$home_url = str_replace( '?', '\?', $home_url );
[103] Fix | Delete
[104] Fix | Delete
if ( $sitepress_settings['urls']['directory_for_default_language'] && $test_language === $default_language ) {
[105] Fix | Delete
$home_url = str_replace( $default_language . '/', '', $home_url );
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
$int1 = preg_match_all( '@<a([^>]*)href="((' . rtrim( $home_url, '/' ) . ')?/([^"^>^\[^\]]+))"([^>]*)>@i', $text, $alp_matches1 );
[109] Fix | Delete
$int2 = preg_match_all( '@<a([^>]*)href=\'((' . rtrim( $home_url, '/' ) . ')?/([^\'^>^\[^\]]+))\'([^>]*)>@i', $text, $alp_matches2 );
[110] Fix | Delete
[111] Fix | Delete
$alp_matches = [];
[112] Fix | Delete
for ( $i = 0; $i < 6; $i ++ ) {
[113] Fix | Delete
$alp_matches[ $i ] = array_merge( (array) $alp_matches1[ $i ], (array) $alp_matches2[ $i ] );
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
if ( $int1 || $int2 ) {
[117] Fix | Delete
$def_url = [];
[118] Fix | Delete
$url_parts = wp_parse_url( $this->get_home_url_with_no_lang_directory() );
[119] Fix | Delete
$url_parts['path'] = isset( $url_parts['path'] ) ? $url_parts['path'] : '';
[120] Fix | Delete
foreach ( $alp_matches[4] as $k => $dir_path ) {
[121] Fix | Delete
if ( 0 === strpos( $dir_path, 'wp-content' ) ) {
[122] Fix | Delete
continue;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
list( $lang, $dir_path ) = $this->extract_lang_from_path( $sitepress_settings, $default_language, $dir_path );
[126] Fix | Delete
[127] Fix | Delete
$req_uri = '/' . $dir_path;
[128] Fix | Delete
$req_uri_array = explode( '?', $req_uri );
[129] Fix | Delete
$req_uri = $req_uri_array[0];
[130] Fix | Delete
$req_uri_params = '';
[131] Fix | Delete
if ( isset( $req_uri_array[1] ) ) {
[132] Fix | Delete
$req_uri_params = $req_uri_array[1];
[133] Fix | Delete
}
[134] Fix | Delete
// Separate anchor.
[135] Fix | Delete
$req_uri_array = explode( '#', $req_uri );
[136] Fix | Delete
$req_uri = $req_uri_array[0];
[137] Fix | Delete
[138] Fix | Delete
$anchor_output = isset( $req_uri_array[1] ) ? '#' . $req_uri_array[1] : '';
[139] Fix | Delete
[140] Fix | Delete
$home_path = wp_parse_url( get_home_url() );
[141] Fix | Delete
if ( isset( $home_path['path'] ) ) {
[142] Fix | Delete
$home_path = $home_path['path'];
[143] Fix | Delete
} else {
[144] Fix | Delete
$home_path = '';
[145] Fix | Delete
}
[146] Fix | Delete
$home_path = trim( $home_path, '/' );
[147] Fix | Delete
[148] Fix | Delete
$pathinfo = '';
[149] Fix | Delete
$req_uri = str_replace( $pathinfo, '', rawurldecode( $req_uri ) );
[150] Fix | Delete
$req_uri = trim( $req_uri, '/' );
[151] Fix | Delete
$req_uri = preg_replace( "|^$home_path|", '', $req_uri );
[152] Fix | Delete
$req_uri = trim( $req_uri, '/' );
[153] Fix | Delete
$pathinfo = trim( $pathinfo, '/' );
[154] Fix | Delete
$pathinfo = preg_replace( "|^$home_path|", '', $pathinfo );
[155] Fix | Delete
$pathinfo = trim( $pathinfo, '/' );
[156] Fix | Delete
[157] Fix | Delete
[158] Fix | Delete
if ( ! empty( $pathinfo ) && ! preg_match( '|^.*' . $wp_rewrite->index . '$|', $pathinfo ) ) {
[159] Fix | Delete
$request = $pathinfo;
[160] Fix | Delete
} else {
[161] Fix | Delete
// If the request uri is the index, blank it out so that we don't try to match it against a rule.
[162] Fix | Delete
if ( $req_uri === $wp_rewrite->index ) {
[163] Fix | Delete
$req_uri = '';
[164] Fix | Delete
}
[165] Fix | Delete
$request = $req_uri;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
if ( ! $request || $blacklist_requests->is_blacklisted( $request ) ) {
[169] Fix | Delete
continue;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
$request_match = $request;
[173] Fix | Delete
[174] Fix | Delete
$permalink_query_vars = [];
[175] Fix | Delete
[176] Fix | Delete
foreach ( (array) $rewrite as $match => $query ) {
[177] Fix | Delete
// If the requesting file is the anchor of the match, prepend it to the path info.
[178] Fix | Delete
if ( ( ! empty( $req_uri ) ) && ( strpos( $match, $req_uri ) === 0 ) && ( $req_uri !== $request ) ) {
[179] Fix | Delete
$request_match = $req_uri . '/' . $request;
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
if ( preg_match( "!^$match!", $request_match, $matches ) || preg_match( "!^$match!", urldecode( $request_match ), $matches ) ) {
[183] Fix | Delete
// Got a match.
[184] Fix | Delete
[185] Fix | Delete
// Trim the query of everything up to the '?'.
[186] Fix | Delete
$query = preg_replace( '!^.+\?!', '', $query );
[187] Fix | Delete
[188] Fix | Delete
// Substitute the substring matches into the query.
[189] Fix | Delete
$query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) );
[190] Fix | Delete
[191] Fix | Delete
// Parse the query.
[192] Fix | Delete
parse_str( $query, $permalink_query_vars );
[193] Fix | Delete
[194] Fix | Delete
break;
[195] Fix | Delete
}
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
$post_name = false;
[199] Fix | Delete
$category_name = false;
[200] Fix | Delete
$tax_name = false;
[201] Fix | Delete
[202] Fix | Delete
if ( isset( $permalink_query_vars['pagename'] ) ) {
[203] Fix | Delete
$get_page_by_path = new WPML_Get_Page_By_Path( $wpdb, $sitepress, new WPML_Debug_BackTrace( null, 7 ) );
[204] Fix | Delete
$page_by_path = $get_page_by_path->get( $permalink_query_vars['pagename'], $test_language );
[205] Fix | Delete
[206] Fix | Delete
$post_name = $permalink_query_vars['pagename'];
[207] Fix | Delete
if ( ! empty( $page_by_path->post_type ) ) {
[208] Fix | Delete
$post_type = 'page';
[209] Fix | Delete
} else {
[210] Fix | Delete
$post_type = 'post';
[211] Fix | Delete
}
[212] Fix | Delete
} elseif ( isset( $permalink_query_vars['name'] ) ) {
[213] Fix | Delete
$post_name = $permalink_query_vars['name'];
[214] Fix | Delete
$post_type = 'post';
[215] Fix | Delete
} elseif ( isset( $permalink_query_vars['category_name'] ) ) {
[216] Fix | Delete
$category_name = $permalink_query_vars['category_name'];
[217] Fix | Delete
} elseif ( isset( $permalink_query_vars['p'] ) ) { // Case or /archives/%post_id.
[218] Fix | Delete
list( $post_type, $post_name ) = $wpdb->get_row(
[219] Fix | Delete
$wpdb->prepare( "SELECT post_type, post_name FROM {$wpdb->posts} WHERE id=%d", $permalink_query_vars['p'] ),
[220] Fix | Delete
ARRAY_N
[221] Fix | Delete
);
[222] Fix | Delete
} else {
[223] Fix | Delete
if ( empty( $this->custom_post_query_vars ) || empty( $this->taxonomies_query_vars ) ) {
[224] Fix | Delete
$this->init_query_vars();
[225] Fix | Delete
}
[226] Fix | Delete
foreach ( $this->custom_post_query_vars as $query_vars_key => $query_vars_value ) {
[227] Fix | Delete
if ( isset( $permalink_query_vars[ $query_vars_value ] ) ) {
[228] Fix | Delete
$post_name = $permalink_query_vars[ $query_vars_value ];
[229] Fix | Delete
$post_type = $query_vars_key;
[230] Fix | Delete
break;
[231] Fix | Delete
}
[232] Fix | Delete
}
[233] Fix | Delete
foreach ( $this->taxonomies_query_vars as $query_vars_value ) {
[234] Fix | Delete
if ( isset( $permalink_query_vars[ $query_vars_value ] ) ) {
[235] Fix | Delete
$tax_name = $permalink_query_vars[ $query_vars_value ];
[236] Fix | Delete
$tax_type = $query_vars_value;
[237] Fix | Delete
break;
[238] Fix | Delete
}
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
if ( $post_name && isset( $post_type ) ) {
[243] Fix | Delete
$get_page_by_path = new WPML_Get_Page_By_Path( $wpdb, $sitepress, new WPML_Debug_BackTrace( null, 7 ) );
[244] Fix | Delete
$p = $get_page_by_path->get( $post_name, $test_language, OBJECT, $post_type );
[245] Fix | Delete
[246] Fix | Delete
if ( empty( $p ) ) { // Fail safe.
[247] Fix | Delete
$post_id = url_to_postid( $home_path . '/' . $post_name );
[248] Fix | Delete
if ( $post_id ) {
[249] Fix | Delete
$p = get_post( $post_id );
[250] Fix | Delete
}
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
if ( $p ) {
[254] Fix | Delete
$offsite_url = get_post_meta( $p->ID, '_cms_nav_offsite_url', true );
[255] Fix | Delete
if ( 'page' === $p->post_type && $offsite_url ) {
[256] Fix | Delete
$def_url = $this->get_regex_replacement_offline(
[257] Fix | Delete
$def_url,
[258] Fix | Delete
$offsite_url,
[259] Fix | Delete
$sitepress_settings['language_negotiation_type'],
[260] Fix | Delete
$lang,
[261] Fix | Delete
$dir_path,
[262] Fix | Delete
$home_url,
[263] Fix | Delete
$anchor_output
[264] Fix | Delete
);
[265] Fix | Delete
} else {
[266] Fix | Delete
$def_url = $this->get_regex_replacement(
[267] Fix | Delete
$def_url,
[268] Fix | Delete
'page' === $p->post_type ? 'page_id' : 'p',
[269] Fix | Delete
$p->ID,
[270] Fix | Delete
$sitepress_settings['language_negotiation_type'],
[271] Fix | Delete
$lang,
[272] Fix | Delete
$dir_path,
[273] Fix | Delete
$home_url,
[274] Fix | Delete
$url_parts,
[275] Fix | Delete
$req_uri_params,
[276] Fix | Delete
$anchor_output
[277] Fix | Delete
);
[278] Fix | Delete
}
[279] Fix | Delete
} else {
[280] Fix | Delete
$alp_broken_links[ $alp_matches[2][ $k ] ] = [];
[281] Fix | Delete
[282] Fix | Delete
$name = wpml_like_escape( $post_name );
[283] Fix | Delete
$p = $this->_get_ids_and_post_types( $name );
[284] Fix | Delete
if ( $p ) {
[285] Fix | Delete
foreach ( $p as $post_suggestion ) {
[286] Fix | Delete
if ( 'page' === $post_suggestion->post_type ) {
[287] Fix | Delete
$qvid = 'page_id';
[288] Fix | Delete
} else {
[289] Fix | Delete
$qvid = 'p';
[290] Fix | Delete
}
[291] Fix | Delete
$alp_broken_links[ $alp_matches[2][ $k ] ]['suggestions'][] = [
[292] Fix | Delete
'absolute' => '/' . ltrim( $url_parts['path'], '/' ) . '?' . $qvid . '=' . $post_suggestion->ID,
[293] Fix | Delete
'perma' => '/' . ltrim( str_replace( site_url(), '', get_permalink( $post_suggestion->ID ) ), '/' ),
[294] Fix | Delete
];
[295] Fix | Delete
}
[296] Fix | Delete
}
[297] Fix | Delete
}
[298] Fix | Delete
} elseif ( $category_name ) {
[299] Fix | Delete
if ( false !== strpos( $category_name, '/' ) ) {
[300] Fix | Delete
$splits = explode( '/', $category_name );
[301] Fix | Delete
$category_name = array_pop( $splits );
[302] Fix | Delete
$category_parent = array_pop( $splits );
[303] Fix | Delete
$category_parent_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM {$wpdb->terms} WHERE slug=%s", $category_parent ) );
[304] Fix | Delete
$c = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON x.term_id=t.term_id AND x.taxonomy='category' AND x.parent=%d AND t.slug=%s", $category_parent_id, $category_name ) );
[305] Fix | Delete
} else {
[306] Fix | Delete
$c = $wpdb->get_row( $wpdb->prepare( "SELECT term_id FROM {$wpdb->terms} WHERE slug=%s", $category_name ) );
[307] Fix | Delete
}
[308] Fix | Delete
if ( $c ) {
[309] Fix | Delete
$def_url = $this->get_regex_replacement(
[310] Fix | Delete
$def_url,
[311] Fix | Delete
'cat_ID',
[312] Fix | Delete
$c->term_id,
[313] Fix | Delete
$sitepress_settings['language_negotiation_type'],
[314] Fix | Delete
$lang,
[315] Fix | Delete
$dir_path,
[316] Fix | Delete
$home_url,
[317] Fix | Delete
$url_parts,
[318] Fix | Delete
$req_uri_params,
[319] Fix | Delete
$anchor_output
[320] Fix | Delete
);
[321] Fix | Delete
} elseif ( isset( $name ) ) {
[322] Fix | Delete
$alp_broken_links[ $alp_matches[2][ $k ] ] = [];
[323] Fix | Delete
[324] Fix | Delete
$c = $wpdb->get_results(
[325] Fix | Delete
$wpdb->prepare( "SELECT term_id FROM {$wpdb->terms} WHERE slug LIKE %s", [ $name . '%' ] )
[326] Fix | Delete
);
[327] Fix | Delete
if ( $c ) {
[328] Fix | Delete
foreach ( $c as $cat_suggestion ) {
[329] Fix | Delete
$perma = '/' . ltrim( str_replace( get_home_url(), '', get_category_link( $cat_suggestion->term_id ) ), '/' );
[330] Fix | Delete
[331] Fix | Delete
$alp_broken_links[ $alp_matches[2][ $k ] ]['suggestions'][] = [
[332] Fix | Delete
'absolute' => '?cat_ID=' . $cat_suggestion->term_id,
[333] Fix | Delete
'perma' => $perma,
[334] Fix | Delete
];
[335] Fix | Delete
}
[336] Fix | Delete
}
[337] Fix | Delete
}
[338] Fix | Delete
} elseif ( $tax_name && isset( $tax_type ) ) {
[339] Fix | Delete
$def_url = $this->get_regex_replacement(
[340] Fix | Delete
$def_url,
[341] Fix | Delete
$tax_type,
[342] Fix | Delete
$tax_name,
[343] Fix | Delete
$sitepress_settings['language_negotiation_type'],
[344] Fix | Delete
$lang,
[345] Fix | Delete
$dir_path,
[346] Fix | Delete
$home_url,
[347] Fix | Delete
$url_parts,
[348] Fix | Delete
$req_uri_params,
[349] Fix | Delete
$anchor_output
[350] Fix | Delete
);
[351] Fix | Delete
}
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
if ( ! empty( $def_url ) ) {
[355] Fix | Delete
$text = preg_replace( array_keys( $def_url ), array_values( $def_url ), $text );
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
$tx_qvs = ! empty( $this->taxonomies_query_vars ) && is_array( $this->taxonomies_query_vars ) ? '|' . join( '|', $this->taxonomies_query_vars ) : '';
[359] Fix | Delete
$post_qvs = ! empty( $this->custom_posts_query_vars ) && is_array( $this->custom_posts_query_vars ) ? '|' . join( '|', $this->custom_posts_query_vars ) : '';
[360] Fix | Delete
$int = preg_match_all( '@href=[\'"](' . rtrim( get_home_url(), '/' ) . '/?\?(p|page_id' . $tx_qvs . $post_qvs . ')=([0-9a-z-]+)(#.+)?)[\'"]@i', $text, $matches2 );
[361] Fix | Delete
if ( $int ) {
[362] Fix | Delete
$url_parts = wp_parse_url( rtrim( get_home_url(), '/' ) . '/' );
[363] Fix | Delete
$text = preg_replace( '@href=[\'"](' . rtrim( get_home_url(), '/' ) . '/?\?(p|page_id' . $tx_qvs . $post_qvs . ')=([0-9a-z-]+)(#.+)?)[\'"]@i', 'href="/' . ltrim( $url_parts['path'], '/' ) . '?$2=$3$4"', $text );
[364] Fix | Delete
}
[365] Fix | Delete
}
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
$text = $block_protector->unProtect( $text );
[369] Fix | Delete
[370] Fix | Delete
WPML_Non_Persistent_Cache::set( $cache_key, $text, $cache_group );
[371] Fix | Delete
[372] Fix | Delete
return $text;
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
private function get_home_url_with_no_lang_directory() {
[376] Fix | Delete
global $sitepress, $sitepress_settings;
[377] Fix | Delete
$sitepress_settings = $sitepress->get_settings();
[378] Fix | Delete
[379] Fix | Delete
$home_url = rtrim( get_home_url(), '/' );
[380] Fix | Delete
if ( 1 === $sitepress_settings['language_negotiation_type'] ) {
[381] Fix | Delete
// Strip lang directory from end if it's there.
[382] Fix | Delete
$exp = explode( '/', $home_url );
[383] Fix | Delete
$lang = end( $exp );
[384] Fix | Delete
[385] Fix | Delete
if ( $this->does_lang_exist( $lang ) ) {
[386] Fix | Delete
$home_url = substr( $home_url, 0, strlen( $home_url ) - strlen( $lang ) );
[387] Fix | Delete
}
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
return $home_url;
[391] Fix | Delete
}
[392] Fix | Delete
[393] Fix | Delete
private function does_lang_exist( $lang ) {
[394] Fix | Delete
return in_array( $lang, $this->active_languages, true );
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
public function _get_ids_and_post_types( $name ) {
[398] Fix | Delete
global $wpdb;
[399] Fix | Delete
static $cache = [];
[400] Fix | Delete
[401] Fix | Delete
$name = rawurlencode( $name );
[402] Fix | Delete
if ( ! isset( $cache[ $name ] ) ) {
[403] Fix | Delete
$cache[ $name ] = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_type FROM {$wpdb->posts} WHERE post_name LIKE %s AND post_type IN('post','page')", $name . '%' ) );
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
return $cache[ $name ];
[407] Fix | Delete
}
[408] Fix | Delete
[409] Fix | Delete
private function initialize_rewrite( $current_language, $default_language, $sitepress ) {
[410] Fix | Delete
global $wp_rewrite;
[411] Fix | Delete
[412] Fix | Delete
$key = $current_language . $default_language;
[413] Fix | Delete
$found = false;
[414] Fix | Delete
$rewrite = WPML_Non_Persistent_Cache::get( $key, __CLASS__, $found );
[415] Fix | Delete
if ( $found ) {
[416] Fix | Delete
return $rewrite;
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
if ( ! isset( $wp_rewrite ) ) {
[420] Fix | Delete
require_once ABSPATH . WPINC . '/rewrite.php';
[421] Fix | Delete
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
[422] Fix | Delete
$wp_rewrite = new WP_Rewrite();
[423] Fix | Delete
}
[424] Fix | Delete
[425] Fix | Delete
if ( $current_language === $default_language ) {
[426] Fix | Delete
$rewrite = $wp_rewrite->wp_rewrite_rules();
[427] Fix | Delete
} else {
[428] Fix | Delete
remove_filter( 'option_rewrite_rules', [ $sitepress, 'rewrite_rules_filter' ] );
[429] Fix | Delete
if ( class_exists( 'WPML_Slug_Translation' ) ) {
[430] Fix | Delete
remove_filter( 'option_rewrite_rules', [ 'WPML_Slug_Translation', 'rewrite_rules_filter' ], 1 );
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
$rewrite = $wp_rewrite->wp_rewrite_rules();
[434] Fix | Delete
[435] Fix | Delete
if ( class_exists( 'WPML_Slug_Translation' ) ) {
[436] Fix | Delete
add_filter( 'option_rewrite_rules', [ 'WPML_Slug_Translation', 'rewrite_rules_filter' ], 1, 1 );
[437] Fix | Delete
}
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
$rewrite = $this->all_rewrite_rules( $rewrite );
[441] Fix | Delete
WPML_Non_Persistent_Cache::set( $key, $rewrite, __CLASS__ );
[442] Fix | Delete
[443] Fix | Delete
return $rewrite;
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
public function all_rewrite_rules( $rewrite ) {
[447] Fix | Delete
global $sitepress;
[448] Fix | Delete
[449] Fix | Delete
if ( ! class_exists( 'WPML\ST\SlugTranslation\Hooks\Hooks' ) ) {
[450] Fix | Delete
return $rewrite;
[451] Fix | Delete
}
[452] Fix | Delete
[453] Fix | Delete
$active_languages = $sitepress->get_active_languages();
[454] Fix | Delete
$current_language = $sitepress->get_current_language();
[455] Fix | Delete
$default_language = $sitepress->get_default_language();
[456] Fix | Delete
[457] Fix | Delete
$cache_keys = [ $current_language, $default_language ];
[458] Fix | Delete
$cache_keys[] = md5( wp_json_encode( $active_languages ) );
[459] Fix | Delete
$cache_keys[] = md5( wp_json_encode( $rewrite ) );
[460] Fix | Delete
$cache_key = implode( ':', $cache_keys );
[461] Fix | Delete
$cache_group = 'all_rewrite_rules';
[462] Fix | Delete
$cache_found = false;
[463] Fix | Delete
[464] Fix | Delete
$final_rules = WPML_Non_Persistent_Cache::get( $cache_key, $cache_group, $cache_found );
[465] Fix | Delete
[466] Fix | Delete
if ( $cache_found ) {
[467] Fix | Delete
return $final_rules;
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
$final_rules = $rewrite;
[471] Fix | Delete
[472] Fix | Delete
foreach ( $active_languages as $next_language ) {
[473] Fix | Delete
[474] Fix | Delete
if ( $next_language['code'] === $default_language ) {
[475] Fix | Delete
continue;
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
$sitepress->switch_lang( $next_language['code'] );
[479] Fix | Delete
[480] Fix | Delete
$translated_rules = ( new \WPML\ST\SlugTranslation\Hooks\HooksFactory() )->create()->filter( $final_rules );
[481] Fix | Delete
[482] Fix | Delete
if ( is_array( $translated_rules ) && is_array( $final_rules ) ) {
[483] Fix | Delete
$new_rules = array_diff_assoc( $translated_rules, $final_rules );
[484] Fix | Delete
[485] Fix | Delete
$final_rules = array_merge( $new_rules, $final_rules );
[486] Fix | Delete
}
[487] Fix | Delete
}
[488] Fix | Delete
[489] Fix | Delete
$sitepress->switch_lang( $current_language );
[490] Fix | Delete
[491] Fix | Delete
WPML_Non_Persistent_Cache::set( $cache_key, $final_rules, $cache_group );
[492] Fix | Delete
[493] Fix | Delete
return $final_rules;
[494] Fix | Delete
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
private function get_regex_replacement(
[498] Fix | Delete
$def_url,
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function