2017-04-24 18:33:17 +00:00
|
|
|
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract WC Object Query Class
|
|
|
|
*
|
|
|
|
* Extended by classes to provide a query abstraction layer for safe object searching.
|
|
|
|
*
|
|
|
|
* @version 3.1.0
|
|
|
|
* @package WooCommerce/Abstracts
|
|
|
|
* @category Abstract Class
|
|
|
|
* @author Automattic
|
|
|
|
*/
|
|
|
|
abstract class WC_Object_Query {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores query data.
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-04-27 18:07:03 +00:00
|
|
|
protected $query_vars = array();
|
2017-04-24 18:33:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new query.
|
|
|
|
* @param array $args Criteria to query on in a format similar to WP_Query.
|
|
|
|
*/
|
|
|
|
public function __construct( $args = array() ) {
|
|
|
|
$this->query_vars = wp_parse_args( $args, $this->get_default_query_vars() );
|
|
|
|
}
|
|
|
|
|
2017-04-28 16:55:49 +00:00
|
|
|
/**
|
|
|
|
* Get the current query vars.
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-04-27 21:09:10 +00:00
|
|
|
public function get_query_vars() {
|
|
|
|
return $this->query_vars;
|
|
|
|
}
|
|
|
|
|
2017-04-24 18:33:17 +00:00
|
|
|
/**
|
|
|
|
* Get the value of a query variable.
|
|
|
|
* @param string $query_var Query variable to get value for.
|
|
|
|
* @param mixed $default Default value if query variable is not set.
|
|
|
|
* @return mixed Query variable value if set, otherwise default.
|
|
|
|
*/
|
|
|
|
public function get( $query_var, $default = '' ) {
|
|
|
|
if ( isset( $this->query_vars[ $query_var ] ) ) {
|
|
|
|
return $this->query_vars[ $query_var ];
|
|
|
|
}
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a query variable.
|
|
|
|
* @param string $query_var Query variable to set.
|
|
|
|
* @param mixed $value Value to set for query variable.
|
|
|
|
*/
|
|
|
|
public function set( $query_var, $value ) {
|
2017-04-27 15:38:18 +00:00
|
|
|
$this->query_vars[ $query_var ] = $value;
|
2017-04-24 18:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-26 18:04:28 +00:00
|
|
|
* Get the default allowed query vars.
|
2017-04-24 18:33:17 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function get_default_query_vars() {
|
|
|
|
|
|
|
|
return array(
|
2017-04-24 23:28:13 +00:00
|
|
|
'name' => '',
|
|
|
|
'parent' => '',
|
2017-04-27 21:09:10 +00:00
|
|
|
'parent_exclude' => '',
|
|
|
|
'exclude' => '',
|
2017-04-24 23:28:13 +00:00
|
|
|
|
2017-05-12 18:45:01 +00:00
|
|
|
'limit' => get_option( 'posts_per_page' ),
|
|
|
|
'page' => 1,
|
2017-04-25 21:52:17 +00:00
|
|
|
'offset' => '',
|
2017-04-28 02:14:48 +00:00
|
|
|
'paginate' => false,
|
2017-04-24 23:28:13 +00:00
|
|
|
|
|
|
|
'order' => 'DESC',
|
|
|
|
'orderby' => 'date',
|
|
|
|
|
2017-04-27 15:38:18 +00:00
|
|
|
'return' => 'objects',
|
2017-04-24 18:33:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|