WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 5 weeks ago

#41196 new defect (bug)

add _doing_it_wrong to get_query_var and prevent fatal errors

Reported by: netweblogic Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Query Keywords: has-patch
Focuses: Cc:

Description

The following scenario will throw a fatal error:

<?php
function parse_query_fail_test(){
        get_query_var('some_var_name', false);
}
add_action('parse_query', 'parse_query_fail_test');

function parse_query_fail_trigger(){
        get_posts();
}
add_action('plugins_loaded', 'parse_query_fail_trigger');

this could easily be avoided with a check and _doing_it_wrong function, similar to functions further down such as is_tax();

I would argue that the same could be done for get_queried_object(), get_queried_object_id() and set_query_var()

Attachments (2)

query.php.patch (503 bytes) - added by netweblogic 6 months ago.
Suggested patch for get_query_var
41196.patch (665 bytes) - added by nileshdudakiya94 6 months ago.
has-patch has-unit-tests added

Download all attachments as: .zip

Change History (3)

@netweblogic
6 months ago

Suggested patch for get_query_var

@nileshdudakiya94
6 months ago

has-patch has-unit-tests added

#1 @ocean90
5 weeks ago

  • Keywords has-patch added
  • Version 4.9 deleted

@nileshdudakiya94 Your patch doesn't include a unit test, should it?

Related: #14729

Note: See TracTickets for help on using tickets.