Make sure query vars are set before use. Props Alex King. fixes #3154
git-svn-id: http://svn.automattic.com/wordpress/trunk@4205 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ac8805dbef
commit
07a02852ef
|
@ -330,6 +330,44 @@ class WP_Query {
|
||||||
$this->parse_query('');
|
$this->parse_query('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fill_query_vars($array) {
|
||||||
|
$keys = array(
|
||||||
|
'error'
|
||||||
|
, 'm'
|
||||||
|
, 'p'
|
||||||
|
, 'subpost'
|
||||||
|
, 'subpost_id'
|
||||||
|
, 'attachment'
|
||||||
|
, 'attachment_id'
|
||||||
|
, 'name'
|
||||||
|
, 'hour'
|
||||||
|
, 'static'
|
||||||
|
, 'pagename'
|
||||||
|
, 'page_id'
|
||||||
|
, 'second'
|
||||||
|
, 'minute'
|
||||||
|
, 'hour'
|
||||||
|
, 'day'
|
||||||
|
, 'monthnum'
|
||||||
|
, 'year'
|
||||||
|
, 'w'
|
||||||
|
, 'category_name'
|
||||||
|
, 'author_name'
|
||||||
|
, 'feed'
|
||||||
|
, 'tb'
|
||||||
|
, 'paged'
|
||||||
|
, 'comments_popup'
|
||||||
|
, 'preview'
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
if ( !isset($array[$key]))
|
||||||
|
$array[$key] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse a query string and set query type booleans.
|
// Parse a query string and set query type booleans.
|
||||||
function parse_query ($query) {
|
function parse_query ($query) {
|
||||||
if ( !empty($query) || !isset($this->query) ) {
|
if ( !empty($query) || !isset($this->query) ) {
|
||||||
|
@ -342,6 +380,8 @@ class WP_Query {
|
||||||
$this->query_vars = $qv;
|
$this->query_vars = $qv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$qv = $this->fill_query_vars($qv);
|
||||||
|
|
||||||
if ( ! empty($qv['robots']) ) {
|
if ( ! empty($qv['robots']) ) {
|
||||||
$this->is_robots = true;
|
$this->is_robots = true;
|
||||||
return;
|
return;
|
||||||
|
@ -531,6 +571,8 @@ class WP_Query {
|
||||||
// Shorthand.
|
// Shorthand.
|
||||||
$q = &$this->query_vars;
|
$q = &$this->query_vars;
|
||||||
|
|
||||||
|
$q = $this->fill_query_vars($q);
|
||||||
|
|
||||||
// First let's clear some variables
|
// First let's clear some variables
|
||||||
$distinct = '';
|
$distinct = '';
|
||||||
$whichcat = '';
|
$whichcat = '';
|
||||||
|
@ -540,6 +582,7 @@ class WP_Query {
|
||||||
$where = '';
|
$where = '';
|
||||||
$limits = '';
|
$limits = '';
|
||||||
$join = '';
|
$join = '';
|
||||||
|
$search = '';
|
||||||
|
|
||||||
if ( !isset($q['post_type']) )
|
if ( !isset($q['post_type']) )
|
||||||
$q['post_type'] = 'post';
|
$q['post_type'] = 'post';
|
||||||
|
@ -909,12 +952,12 @@ class WP_Query {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($q['what_to_show'] == 'posts')) {
|
if (($q['what_to_show'] == 'posts')) {
|
||||||
$q['offset'] = abs(intval($q['offset']));
|
|
||||||
if ( empty($q['offset']) ) {
|
if ( empty($q['offset']) ) {
|
||||||
$pgstrt = '';
|
$pgstrt = '';
|
||||||
$pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', ';
|
$pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', ';
|
||||||
$limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
|
$limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
|
||||||
} else { // we're ignoring $page and using 'offset'
|
} else { // we're ignoring $page and using 'offset'
|
||||||
|
$q['offset'] = abs(intval($q['offset']));
|
||||||
$pgstrt = $q['offset'] . ', ';
|
$pgstrt = $q['offset'] . ', ';
|
||||||
$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
|
$limits = 'LIMIT ' . $pgstrt . $q['posts_per_page'];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue