mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-22 08:11:52 +01:00
Move get() and set() methods from WP_Query to WP_Object_Query. See #15032
git-svn-id: http://svn.automattic.com/wordpress/trunk@16018 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8a95232377
commit
9bb5485853
@ -534,6 +534,44 @@ class WP {
|
||||
*/
|
||||
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
|
||||
*
|
||||
|
@ -192,9 +192,22 @@ function get_comments( $args = '' ) {
|
||||
return $query->query( $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* WordPress Comment Query class.
|
||||
*
|
||||
* @since 3.1.0
|
||||
*/
|
||||
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;
|
||||
|
||||
$defaults = array(
|
||||
@ -215,8 +228,9 @@ class WP_Comment_Query extends WP_Object_Query {
|
||||
'count' => false
|
||||
);
|
||||
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
extract( $args, EXTR_SKIP );
|
||||
$this->query_vars = wp_parse_args( $query_vars, $defaults );
|
||||
|
||||
extract( $this->query_vars, EXTR_SKIP );
|
||||
|
||||
// $args can be whatever, only use the args defined in defaults to compute the key
|
||||
$key = md5( serialize( compact(array_keys($defaults)) ) );
|
||||
|
@ -658,9 +658,8 @@ function the_comment() {
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class WP_Query extends WP_Object_Query {
|
||||
|
||||
/**
|
||||
* Query vars set by the user
|
||||
* Initial query vars
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @access public
|
||||
@ -668,15 +667,6 @@ class WP_Query extends WP_Object_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.
|
||||
*
|
||||
@ -1581,35 +1571,6 @@ class WP_Query extends WP_Object_Query {
|
||||
$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.
|
||||
*
|
||||
|
@ -374,12 +374,18 @@ class WP_User_Query extends WP_Object_Query {
|
||||
function __construct( $query = null ) {
|
||||
if ( !empty( $query ) ) {
|
||||
$this->query_vars = wp_parse_args( $query, array(
|
||||
'role' => '', 'blog_id' => $GLOBALS['blog_id'],
|
||||
'meta_key' => '', 'meta_value' => '', 'meta_compare' => '',
|
||||
'include' => array(), 'exclude' => array(),
|
||||
'blog_id' => $GLOBALS['blog_id'],
|
||||
'role' => '',
|
||||
'meta_key' => '',
|
||||
'meta_value' => '',
|
||||
'meta_compare' => '',
|
||||
'include' => array(),
|
||||
'exclude' => array(),
|
||||
'search' => '',
|
||||
'orderby' => 'login', 'order' => 'ASC',
|
||||
'offset' => '', 'number' => '', 'count_total' => true,
|
||||
'orderby' => 'login',
|
||||
'order' => 'ASC',
|
||||
'offset' => '', 'number' => '',
|
||||
'count_total' => true,
|
||||
'fields' => 'all',
|
||||
) );
|
||||
|
||||
@ -1521,4 +1527,4 @@ function _wp_get_user_contactmethods( $user = null ) {
|
||||
return apply_filters( 'user_contactmethods', $user_contactmethods, $user );
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user