Skip to content

Commit

Permalink
QTS: add comments for filter_request
Browse files Browse the repository at this point in the history
  • Loading branch information
spleen1981 committed May 16, 2022
1 parent 58593e1 commit 3e954f6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions modules/slugs/includes/class-qtranslate-slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ function filter_request( $query ) {
global $q_config;
global $wp;

/* As $wp->matched_query filters the query including slugs mudule custom rewrite rules, it provides all necessary data to reach the intended resource.
* However discarding completely $query arg and using only $wp->matched_query would result in losing possible custom query vars.
* Hence $query and $wp->matched_query are merged and unneeded/conflictual keys (e.g. 'error') from $query are removed.
*/

if ( isset( $wp->matched_query ) ) {
if ( isset( $query['error'] ) ){
unset( $query['error'] );
Expand All @@ -372,6 +377,9 @@ function filter_request( $query ) {

// -> page
elseif ( isset( $query['pagename'] ) || isset( $query['page_id'] ) ):
/* 'name' key from passed $query var is removed if 'pagename' key is present in $wp->matched_query.
* Both keys causes conflict between posts and pages as 'name' is used for posts, resulting in 404 error.
*/
if ( isset( $query['name'] ) ) {
unset($query['name']);
}
Expand Down Expand Up @@ -421,6 +429,8 @@ function filter_request( $query ) {

else:

// If none of the conditions above are matched, specific tests to identify custom post types and taxonomies are performed here.

// -> 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 Down Expand Up @@ -465,6 +475,12 @@ function filter_request( $query ) {
}
endforeach;

/* As 'name' key is present also at least both for pages and custom post types, this condition alone cannot be used to identify uniquely the posts.
* For pages and custom post types specific tests can be and are performed earlier but no additional specific condition seems to be applicable for posts.
* Given the above, the following test needs to be placed after the custom post types one, and is it positive if 'name' key is there and no other match is found earlier.
* If a specific condition was found to uniquely identify posts, this block should be placed in the main if block.
*/

// -> 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');
Expand Down

0 comments on commit 3e954f6

Please sign in to comment.