Move get() and set() methods from WP_Query to WP_Object_Query. See #15032
git-svn-id: https://develop.svn.wordpress.org/trunk@16018 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
9cc035e926
commit
174c0acfb4
@ -534,6 +534,44 @@ class WP {
|
|||||||
*/
|
*/
|
||||||
class WP_Object_Query {
|
class WP_Object_Query {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query vars, after parsing
|
||||||
|
*
|
||||||
|
* @since 3.1.0
|
||||||
|
* @access public
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $query_vars;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve query variable.
|
||||||
|
*
|
||||||
|
* @since 3.1.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param string $query_var Query variable key.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function get( $query_var ) {
|
||||||
|
if ( isset( $this->query_vars[$query_var] ) )
|
||||||
|
return $this->query_vars[$query_var];
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set query variable.
|
||||||
|
*
|
||||||
|
* @since 3.1.0
|
||||||
|
* @access public
|
||||||
|
*
|
||||||
|
* @param string $query_var Query variable key.
|
||||||
|
* @param mixed $value Query variable value.
|
||||||
|
*/
|
||||||
|
function set( $query_var, $value ) {
|
||||||
|
$this->query_vars[ $query_var ] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Populates the $meta_query property
|
* Populates the $meta_query property
|
||||||
*
|
*
|
||||||
|
@ -192,9 +192,22 @@ function get_comments( $args = '' ) {
|
|||||||
return $query->query( $args );
|
return $query->query( $args );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WordPress Comment Query class.
|
||||||
|
*
|
||||||
|
* @since 3.1.0
|
||||||
|
*/
|
||||||
class WP_Comment_Query extends WP_Object_Query {
|
class WP_Comment_Query extends WP_Object_Query {
|
||||||
|
|
||||||
function query( $args ) {
|
/**
|
||||||
|
* Execute the query
|
||||||
|
*
|
||||||
|
* @since 3.1.0
|
||||||
|
*
|
||||||
|
* @param string|array $query_vars
|
||||||
|
* @return int|array
|
||||||
|
*/
|
||||||
|
function query( $query_vars ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
@ -215,8 +228,9 @@ class WP_Comment_Query extends WP_Object_Query {
|
|||||||
'count' => false
|
'count' => false
|
||||||
);
|
);
|
||||||
|
|
||||||
$args = wp_parse_args( $args, $defaults );
|
$this->query_vars = wp_parse_args( $query_vars, $defaults );
|
||||||
extract( $args, EXTR_SKIP );
|
|
||||||
|
extract( $this->query_vars, EXTR_SKIP );
|
||||||
|
|
||||||
// $args can be whatever, only use the args defined in defaults to compute the key
|
// $args can be whatever, only use the args defined in defaults to compute the key
|
||||||
$key = md5( serialize( compact(array_keys($defaults)) ) );
|
$key = md5( serialize( compact(array_keys($defaults)) ) );
|
||||||
|
@ -658,9 +658,8 @@ function the_comment() {
|
|||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
class WP_Query extends WP_Object_Query {
|
class WP_Query extends WP_Object_Query {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query vars set by the user
|
* Initial query vars
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
* @access public
|
* @access public
|
||||||
@ -668,15 +667,6 @@ class WP_Query extends WP_Object_Query {
|
|||||||
*/
|
*/
|
||||||
var $query;
|
var $query;
|
||||||
|
|
||||||
/**
|
|
||||||
* Query vars, after parsing
|
|
||||||
*
|
|
||||||
* @since 1.5.0
|
|
||||||
* @access public
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
var $query_vars = array();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the data for a single object that is queried.
|
* Holds the data for a single object that is queried.
|
||||||
*
|
*
|
||||||
@ -1581,35 +1571,6 @@ class WP_Query extends WP_Object_Query {
|
|||||||
$this->is_feed = $is_feed;
|
$this->is_feed = $is_feed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve query variable.
|
|
||||||
*
|
|
||||||
* @since 1.5.0
|
|
||||||
* @access public
|
|
||||||
*
|
|
||||||
* @param string $query_var Query variable key.
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
function get($query_var) {
|
|
||||||
if ( isset($this->query_vars[$query_var]) )
|
|
||||||
return $this->query_vars[$query_var];
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set query variable.
|
|
||||||
*
|
|
||||||
* @since 1.5.0
|
|
||||||
* @access public
|
|
||||||
*
|
|
||||||
* @param string $query_var Query variable key.
|
|
||||||
* @param mixed $value Query variable value.
|
|
||||||
*/
|
|
||||||
function set($query_var, $value) {
|
|
||||||
$this->query_vars[$query_var] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the posts based on query variables.
|
* Retrieve the posts based on query variables.
|
||||||
*
|
*
|
||||||
|
@ -374,12 +374,18 @@ class WP_User_Query extends WP_Object_Query {
|
|||||||
function __construct( $query = null ) {
|
function __construct( $query = null ) {
|
||||||
if ( !empty( $query ) ) {
|
if ( !empty( $query ) ) {
|
||||||
$this->query_vars = wp_parse_args( $query, array(
|
$this->query_vars = wp_parse_args( $query, array(
|
||||||
'role' => '', 'blog_id' => $GLOBALS['blog_id'],
|
'blog_id' => $GLOBALS['blog_id'],
|
||||||
'meta_key' => '', 'meta_value' => '', 'meta_compare' => '',
|
'role' => '',
|
||||||
'include' => array(), 'exclude' => array(),
|
'meta_key' => '',
|
||||||
|
'meta_value' => '',
|
||||||
|
'meta_compare' => '',
|
||||||
|
'include' => array(),
|
||||||
|
'exclude' => array(),
|
||||||
'search' => '',
|
'search' => '',
|
||||||
'orderby' => 'login', 'order' => 'ASC',
|
'orderby' => 'login',
|
||||||
'offset' => '', 'number' => '', 'count_total' => true,
|
'order' => 'ASC',
|
||||||
|
'offset' => '', 'number' => '',
|
||||||
|
'count_total' => true,
|
||||||
'fields' => 'all',
|
'fields' => 'all',
|
||||||
) );
|
) );
|
||||||
|
|
||||||
@ -1521,4 +1527,4 @@ function _wp_get_user_contactmethods( $user = null ) {
|
|||||||
return apply_filters( 'user_contactmethods', $user_contactmethods, $user );
|
return apply_filters( 'user_contactmethods', $user_contactmethods, $user );
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user