#14976 closed defect (bug) (fixed)
WP_Query's init() and init_query_flags() do not do thorough resets
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | minor | Version: | 3.0.1 |
Component: | Query | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
Despite WP_Query's init()
documented claim that it "initiates object properties and sets default values" and that init_query_flags()
"resets query flags to false", both are not thorough in their tasks. This likely stems from these functions not always being kept in sync with changes made to WP_Query.
For init()
, the following variables, as defined in the class, are not reset:
var $request; var $post; var $comments; var $comment_count = 0; var $current_comment = -1; var $comment; var $found_posts = 0; var $max_num_pages = 0; var $max_num_comment_pages = 0;
For init_query_flags()
, the following query flags, as defined in the class, are not reset:
var $is_preview = false; var $is_comments_popup = false;
The attached patch fixes those functions to unset/reset all the above object variables.
And one additional minor thing: the class variable $is_paged
was not explicitly defined as a class variable unlike all the other class variables, so the patch does so.
Attachments (1)
Change History (7)
#5
@
13 years ago
- Keywords dev-feedback added
I suggest an additional init_something subroutine for those values directly reset in init() to easier understand the init function.
Next to that I assume that it's not wanted to unset public properties but to set them to null or better to say, their default value. Unsetting the properties means to remove them from the class which I assume is not intended.
#6
@
13 years ago
I agree that the unsetting of the public properties was a bit unusual. I personally would have set them to null. However, the existing convention in the function was to unset properties that were defined but not given an initial value, otherwise re-initialize those that were assigned an initial value. I figured the existing convention warranted a separate discussion, so I rolled with what was there. But I with you on that count.
You would also have to reset the newly introduced $tax_query and $meta_query.