WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#41224 new defect (bug)

WP strips query vars if post contains "wp-admin"

Reported by: khromov Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9
Component: Query Keywords: has-patch
Focuses: Cc:
PR Number:

Description

I'm running up against this rather obscure issue in the WP Query parser.

If a post name contains "wp-admin", the query vars are emptied which results in loading the front page instead of the post.

Repro steps:

  • Use built-in PHP web server to start a WP site.
  • Create a post or CPT called "test-wp-admin"
  • View the post, you will be redirected to the frontpage.

Here is the relevant code from class-wp.php

if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )
    unset( $perma_query_vars );

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp.php#L276

If you inspect $_SERVERPHP_SELF?, the resulting value is "/index.php/test-wp-admin/" which triggers the conditional.

It is not immediately clear to me why this is being done at all.

Attachments (1)

41224.patch (962 bytes) - added by Girishpanchal 2 years ago.
Patch added #41224

Download all attachments as: .zip

Change History (4)

#1 @Girishpanchal
2 years ago

  • Focuses accessibility administration added
  • Keywords has-patch added

I have added a patch for the above issue.

@Girishpanchal
2 years ago

Patch added #41224

#2 @tobifjellner
2 years ago

What if you instead of 'wp-admin/' would simply search for '/wp-admin/'?

#3 @SergeyBiryukov
2 years ago

  • Component changed from General to Query
  • Focuses accessibility administration removed

Related: #23478

Note: See TracTickets for help on using tickets.