woocommerce/includes/abstracts/abstract-wc-object-query.php

108 lines
2.5 KiB
PHP
Raw Normal View History

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
*/
public $query_vars = array();
/**
* 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() );
}
/**
* 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 ) {
$this->query_vars[$query_var] = $value;
}
/**
* Get the default, unset allowed query vars.
* @return array
*/
protected function get_default_query_vars() {
return array(
2017-04-24 23:28:13 +00:00
'tax_query' => array(),
'meta_query' => array(),
'date_query' => array(),
'p' => '',
'name' => '',
'parent' => '',
'parent__in' => array(),
'parent__not_in' => array(),
'in' => array(),
'not_in' => array(),
'has_password' => null,
'password' => '',
'status' => array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit' ),
2017-04-25 21:52:17 +00:00
'per_page' => -1,
'nopaging' => '',
'page' => '',
'offset' => '',
2017-04-24 23:28:13 +00:00
'order' => 'DESC',
'orderby' => 'date',
'year' => '',
'monthnum' => '',
'w' => '',
'day' => '',
'hour' => '',
'minute' => '',
'second' => '',
'm' => '',
'meta_key' => '',
'meta_value' => '',
'meta_value_num' => '',
2017-04-25 21:52:17 +00:00
'meta_compare' => '',
2017-04-24 23:28:13 +00:00
's' => '',
2017-04-25 21:52:17 +00:00
'exact' => '',
2017-04-24 23:28:13 +00:00
'sentence' => '',
'fields' => '',
2017-04-24 18:33:17 +00:00
);
}
}