• vrazer

    (@vrazer)


    During some testing, we noticed that for some server platforms, the $_SERVER[‘QUERY_STRING’] parameter might not be blank despite the fact that the URL of the actual page requested has no query string.

    In other words, it’s possible that the server architecture reports this:

    URL: http://somesite.com/some-slug
    $_SERVER[‘QUERY_STRING’] = ‘q=some-slug’ (or some other non-blank value)

    The current test for query string presence in line 429 of class/class-widget-context.php is:
    if ( ! empty( $_SERVER['QUERY_STRING'] ) )

    This will evaluate to a non-blank query string, update the complete URL in the following lines of code and then try to map the URL context list to the incorrect complete URL. This then creates a situation where the URL doesn’t match the context (when it should) and the widget is not displayed as it should be. You can sort of workaround this with the * wildcard value, but then you run into false positive matches because of similar URL slugs too.

    A more appropriate conditional check for the presence of a query string in the URL would be:
    if ( strpos ( $_SERVER['REQUEST_URI'], '?' ) !== false)

    This one code change fixes the context problem.

    And then it might be more appropriate to use the following code for generating a complete URL:

    $query = explode ( '?', $_SERVER['REQUEST_URI'] );
    $query = $query[1];
    $url_request .= '?' . $query;

    Of course, it’s probably a good idea to do some filtering on the $_SERVER vars. That isn’t happening at all right now in the current code.

    In any case, the biggest problem we have seen so far is in detecting whether there is a real query string or not.

    The provided code should fix that problem and increase compatibility with various server platforms.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Incorrect Context Results for Pages without Query Strings’ is closed to new replies.