Skip to content

Commit

Permalink
QTS: fix conflict pages/posts in filter_request
Browse files Browse the repository at this point in the history
  • Loading branch information
spleen1981 authored May 15, 2022
1 parent c894fbd commit 58593e1
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions modules/slugs/includes/class-qtranslate-slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,10 @@ function filter_request( $query ) {
global $q_config;
global $wp;

if ( isset( $query['error'] ) && isset( $wp->matched_query ) ) {
unset( $query['error'] );
if ( isset( $wp->matched_query ) ) {
if ( isset( $query['error'] ) ){
unset( $query['error'] );
}
$query = array_merge( wp_parse_args( $wp->matched_query ), $query );
}

Expand All @@ -370,6 +372,9 @@ function filter_request( $query ) {

// -> page
elseif ( isset( $query['pagename'] ) || isset( $query['page_id'] ) ):
if ( isset( $query['name'] ) ) {
unset($query['name']);
}
$page = wp_cache_get( 'qts_page_request' );
if ( ! $page ) {
$page = isset( $query['page_id'] ) ? get_post( $query['page_id'] ) : $this->get_page_by_path( $query['pagename'] );
Expand All @@ -384,18 +389,6 @@ function filter_request( $query ) {
$query['pagename'] = get_page_uri( $page );
$function = 'get_page_link';

// -> post
elseif ( isset( $query['name'] ) || isset( $query['p'] ) ):
$post = isset( $query['p'] ) ? get_post( $query['p'] ) : $this->get_page_by_path( $query['name'], OBJECT, 'post' );
if ( ! $post ) {
return $query;
}
$query['name'] = $post->post_name;
$id = $post->ID;
$cache_array = array( $post );
update_post_caches( $cache_array );
$function = 'get_permalink';

// -> category
elseif ( ( isset( $query['category_name'] ) || isset( $query['cat'] ) ) ):
if ( isset( $query['category_name'] ) ) {
Expand Down Expand Up @@ -427,6 +420,7 @@ function filter_request( $query ) {
$function = 'get_tag_link';

else:

// -> custom post type
foreach ( $this->get_public_post_types() as $post_type ) {
if ( array_key_exists( $post_type->name, $query ) && ! in_array( $post_type->name, array(
Expand All @@ -437,7 +431,6 @@ function filter_request( $query ) {
break;
}
}

if ( isset( $query['post_type'] ) ) {
if ( count( $query ) == 1 ) {
$function = 'get_post_type_archive_link';
Expand Down Expand Up @@ -471,6 +464,19 @@ function filter_request( $query ) {
$function = 'get_term_link';
}
endforeach;

// -> post
if ( ! $function && ( isset($query['name']) || isset($query['p'] ) ) ) {
$post = isset($query['p']) ? get_post($query['p']) : $this->get_page_by_path($query['name'], OBJECT, 'post');
if (!$post) {
return $query;
}
$query['name'] = $post->post_name;
$id = $post->ID;
$cache_array = array($post);
update_post_caches($cache_array);
$function = 'get_permalink';
}
endif;

if ( isset( $function ) ) {
Expand Down

0 comments on commit 58593e1

Please sign in to comment.