Merge pull request #19274 from woocommerce/update/api-phpcs
Fixed PHPCS violations on includes/api
This commit is contained in:
commit
9f918cacc6
|
@ -2,16 +2,15 @@
|
|||
/**
|
||||
* REST API Authentication
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API authentication class.
|
||||
*/
|
||||
class WC_REST_Authentication {
|
||||
|
||||
/**
|
||||
|
@ -58,10 +57,10 @@ class WC_REST_Authentication {
|
|||
$rest_prefix = trailingslashit( rest_get_url_prefix() );
|
||||
|
||||
// Check if our endpoint.
|
||||
$woocommerce = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix . 'wc/' ) );
|
||||
$woocommerce = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix . 'wc/' ) ); // @codingStandardsIgnoreLine
|
||||
|
||||
// Allow third party plugins use our authentication methods.
|
||||
$third_party = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix . 'wc-' ) );
|
||||
$third_party = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix . 'wc-' ) ); // @codingStandardsIgnoreLine
|
||||
|
||||
return apply_filters( 'woocommerce_rest_is_request_to_rest_api', $woocommerce || $third_party );
|
||||
}
|
||||
|
@ -88,7 +87,7 @@ class WC_REST_Authentication {
|
|||
/**
|
||||
* Check for authentication error.
|
||||
*
|
||||
* @param WP_Error|null|bool $error
|
||||
* @param WP_Error|null|bool $error Error data.
|
||||
* @return WP_Error|null|bool
|
||||
*/
|
||||
public function check_authentication_error( $error ) {
|
||||
|
@ -138,14 +137,14 @@ class WC_REST_Authentication {
|
|||
|
||||
// If the $_GET parameters are present, use those first.
|
||||
if ( ! empty( $_GET['consumer_key'] ) && ! empty( $_GET['consumer_secret'] ) ) {
|
||||
$consumer_key = $_GET['consumer_key'];
|
||||
$consumer_secret = $_GET['consumer_secret'];
|
||||
$consumer_key = $_GET['consumer_key']; // WPCS: sanitization ok.
|
||||
$consumer_secret = $_GET['consumer_secret']; // WPCS: sanitization ok.
|
||||
}
|
||||
|
||||
// If the above is not present, we will do full basic auth.
|
||||
if ( ! $consumer_key && ! empty( $_SERVER['PHP_AUTH_USER'] ) && ! empty( $_SERVER['PHP_AUTH_PW'] ) ) {
|
||||
$consumer_key = $_SERVER['PHP_AUTH_USER'];
|
||||
$consumer_secret = $_SERVER['PHP_AUTH_PW'];
|
||||
$consumer_key = $_SERVER['PHP_AUTH_USER']; // WPCS: sanitization ok.
|
||||
$consumer_secret = $_SERVER['PHP_AUTH_PW']; // WPCS: sanitization ok.
|
||||
}
|
||||
|
||||
// Stop if don't have any key.
|
||||
|
@ -160,7 +159,7 @@ class WC_REST_Authentication {
|
|||
}
|
||||
|
||||
// Validate user secret.
|
||||
if ( ! hash_equals( $this->user->consumer_secret, $consumer_secret ) ) {
|
||||
if ( ! hash_equals( $this->user->consumer_secret, $consumer_secret ) ) { // @codingStandardsIgnoreLine
|
||||
$this->set_error( new WP_Error( 'woocommerce_rest_authentication_error', __( 'Consumer secret is invalid.', 'woocommerce' ), array( 'status' => 401 ) ) );
|
||||
|
||||
return false;
|
||||
|
@ -211,7 +210,7 @@ class WC_REST_Authentication {
|
|||
*/
|
||||
public function get_authorization_header() {
|
||||
if ( ! empty( $_SERVER['HTTP_AUTHORIZATION'] ) ) {
|
||||
return wp_unslash( $_SERVER['HTTP_AUTHORIZATION'] );
|
||||
return wp_unslash( $_SERVER['HTTP_AUTHORIZATION'] ); // WPCS: sanitization ok.
|
||||
}
|
||||
|
||||
if ( function_exists( 'getallheaders' ) ) {
|
||||
|
@ -235,13 +234,13 @@ class WC_REST_Authentication {
|
|||
* @return array|WP_Error
|
||||
*/
|
||||
public function get_oauth_parameters() {
|
||||
$params = array_merge( $_GET, $_POST );
|
||||
$params = array_merge( $_GET, $_POST ); // WPCS: CSRF ok.
|
||||
$params = wp_unslash( $params );
|
||||
$header = $this->get_authorization_header();
|
||||
|
||||
if ( ! empty( $header ) ) {
|
||||
// Trim leading spaces.
|
||||
$header = trim( $header );
|
||||
$header = trim( $header );
|
||||
$header_params = $this->parse_header( $header );
|
||||
|
||||
if ( ! empty( $header_params ) ) {
|
||||
|
@ -278,6 +277,7 @@ class WC_REST_Authentication {
|
|||
// then it's a failed authentication.
|
||||
if ( ! empty( $errors ) ) {
|
||||
$message = sprintf(
|
||||
/* translators: %s: amount of errors */
|
||||
_n( 'Missing OAuth parameter %s', 'Missing OAuth parameters %s', count( $errors ), 'woocommerce' ),
|
||||
implode( ', ', $errors )
|
||||
);
|
||||
|
@ -343,13 +343,13 @@ class WC_REST_Authentication {
|
|||
* Verify that the consumer-provided request signature matches our generated signature,
|
||||
* this ensures the consumer has a valid key/secret.
|
||||
*
|
||||
* @param stdClass $user
|
||||
* @param array $params The request parameters.
|
||||
* @param stdClass $user User data.
|
||||
* @param array $params The request parameters.
|
||||
* @return true|WP_Error
|
||||
*/
|
||||
private function check_oauth_signature( $user, $params ) {
|
||||
$http_method = strtoupper( $_SERVER['REQUEST_METHOD'] );
|
||||
$request_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
|
||||
$http_method = isset( $_SERVER['REQUEST_METHOD'] ) ? strtoupper( $_SERVER['REQUEST_METHOD'] ) : ''; // WPCS: sanitization ok.
|
||||
$request_path = isset( $_SERVER['REQUEST_URI'] ) ? parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) : ''; // WPCS: sanitization ok.
|
||||
$wp_base = get_home_url( null, '/', 'relative' );
|
||||
if ( substr( $request_path, 0, strlen( $wp_base ) ) === $wp_base ) {
|
||||
$request_path = substr( $request_path, strlen( $wp_base ) );
|
||||
|
@ -378,7 +378,7 @@ class WC_REST_Authentication {
|
|||
$secret = $user->consumer_secret . '&';
|
||||
$signature = base64_encode( hash_hmac( $hash_algorithm, $string_to_sign, $secret, true ) );
|
||||
|
||||
if ( ! hash_equals( $signature, $consumer_signature ) ) {
|
||||
if ( ! hash_equals( $signature, $consumer_signature ) ) { // @codingStandardsIgnoreLine
|
||||
return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Invalid signature - provided signature does not match.', 'woocommerce' ), array( 'status' => 401 ) );
|
||||
}
|
||||
|
||||
|
@ -390,8 +390,8 @@ class WC_REST_Authentication {
|
|||
*
|
||||
* @param array $params Array of parameters to convert.
|
||||
* @param array $query_params Array to extend.
|
||||
* @param string $key Optional Array key to append
|
||||
* @return string Array of urlencoded strings
|
||||
* @param string $key Optional Array key to append.
|
||||
* @return string Array of urlencoded strings.
|
||||
*/
|
||||
private function join_with_equals_sign( $params, $query_params = array(), $key = '' ) {
|
||||
foreach ( $params as $param_key => $param_value ) {
|
||||
|
@ -402,7 +402,7 @@ class WC_REST_Authentication {
|
|||
if ( is_array( $param_value ) ) {
|
||||
$query_params = $this->join_with_equals_sign( $param_value, $query_params, $param_key );
|
||||
} else {
|
||||
$string = $param_key . '=' . $param_value; // Join with equals sign.
|
||||
$string = $param_key . '=' . $param_value; // Join with equals sign.
|
||||
$query_params[] = wc_rest_urlencode_rfc3986( $string );
|
||||
}
|
||||
}
|
||||
|
@ -444,9 +444,9 @@ class WC_REST_Authentication {
|
|||
* - A timestamp is valid if it is within 15 minutes of now.
|
||||
* - A nonce is valid if it has not been used within the last 15 minutes.
|
||||
*
|
||||
* @param stdClass $user
|
||||
* @param int $timestamp the unix timestamp for when the request was made
|
||||
* @param string $nonce a unique (for the given user) 32 alphanumeric string, consumer-generated
|
||||
* @param stdClass $user User data.
|
||||
* @param int $timestamp The unix timestamp for when the request was made.
|
||||
* @param string $nonce A unique (for the given user) 32 alphanumeric string, consumer-generated.
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
private function check_oauth_timestamp_and_nonce( $user, $timestamp, $nonce ) {
|
||||
|
@ -493,18 +493,22 @@ class WC_REST_Authentication {
|
|||
/**
|
||||
* Return the user data for the given consumer_key.
|
||||
*
|
||||
* @param string $consumer_key
|
||||
* @param string $consumer_key Consumer key.
|
||||
* @return array
|
||||
*/
|
||||
private function get_user_data_by_consumer_key( $consumer_key ) {
|
||||
global $wpdb;
|
||||
|
||||
$consumer_key = wc_api_hash( sanitize_text_field( $consumer_key ) );
|
||||
$user = $wpdb->get_row( $wpdb->prepare( "
|
||||
$user = $wpdb->get_row(
|
||||
$wpdb->prepare(
|
||||
"
|
||||
SELECT key_id, user_id, permissions, consumer_key, consumer_secret, nonces
|
||||
FROM {$wpdb->prefix}woocommerce_api_keys
|
||||
WHERE consumer_key = %s
|
||||
", $consumer_key ) );
|
||||
", $consumer_key
|
||||
)
|
||||
);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
@ -519,24 +523,24 @@ class WC_REST_Authentication {
|
|||
$permissions = $this->user->permissions;
|
||||
|
||||
switch ( $method ) {
|
||||
case 'HEAD' :
|
||||
case 'GET' :
|
||||
case 'HEAD':
|
||||
case 'GET':
|
||||
if ( 'read' !== $permissions && 'read_write' !== $permissions ) {
|
||||
return new WP_Error( 'woocommerce_rest_authentication_error', __( 'The API key provided does not have read permissions.', 'woocommerce' ), array( 'status' => 401 ) );
|
||||
}
|
||||
break;
|
||||
case 'POST' :
|
||||
case 'PUT' :
|
||||
case 'PATCH' :
|
||||
case 'DELETE' :
|
||||
case 'POST':
|
||||
case 'PUT':
|
||||
case 'PATCH':
|
||||
case 'DELETE':
|
||||
if ( 'write' !== $permissions && 'read_write' !== $permissions ) {
|
||||
return new WP_Error( 'woocommerce_rest_authentication_error', __( 'The API key provided does not have write permissions.', 'woocommerce' ), array( 'status' => 401 ) );
|
||||
}
|
||||
break;
|
||||
case 'OPTIONS' :
|
||||
case 'OPTIONS':
|
||||
return true;
|
||||
|
||||
default :
|
||||
default:
|
||||
return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Unknown request method.', 'woocommerce' ), array( 'status' => 401 ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /coupons endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Coupons controller class.
|
||||
|
@ -47,73 +43,81 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
* Register the routes for coupons.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
|
||||
'code' => array(
|
||||
'description' => __( 'Coupon code.', 'woocommerce' ),
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
),
|
||||
) ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'default' => false,
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => array_merge(
|
||||
$this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
|
||||
'code' => array(
|
||||
'description' => __( 'Coupon code.', 'woocommerce' ),
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'batch_items' ),
|
||||
'permission_callback' => array( $this, 'batch_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_batch_schema' ),
|
||||
) );
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'default' => false,
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/batch', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'batch_items' ),
|
||||
'permission_callback' => array( $this, 'batch_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_batch_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,9 +152,9 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
|
||||
// Format date values.
|
||||
foreach ( $format_date as $key ) {
|
||||
$datetime = $data[ $key ];
|
||||
$data[ $key ] = wc_rest_prepare_date_response( $datetime, false );
|
||||
$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
|
||||
$datetime = $data[ $key ];
|
||||
$data[ $key ] = wc_rest_prepare_date_response( $datetime, false );
|
||||
$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
|
||||
}
|
||||
|
||||
// Format null values.
|
||||
|
@ -198,7 +202,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
* @return WP_REST_Response
|
||||
*/
|
||||
public function prepare_object_for_response( $object, $request ) {
|
||||
$data = $this->get_formatted_item_data( $object );
|
||||
$data = $this->get_formatted_item_data( $object );
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
@ -229,7 +233,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
$args = parent::prepare_objects_query( $request );
|
||||
|
||||
if ( ! empty( $request['code'] ) ) {
|
||||
$id = wc_get_coupon_id_by_code( $request['code'] );
|
||||
$id = wc_get_coupon_id_by_code( $request['code'] );
|
||||
$args['post__in'] = array( $id );
|
||||
}
|
||||
|
||||
|
@ -242,7 +246,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
/**
|
||||
* Only return writable props from schema.
|
||||
*
|
||||
* @param array $schema
|
||||
* @param array $schema Schema.
|
||||
* @return bool
|
||||
*/
|
||||
protected function filter_writable_props( $schema ) {
|
||||
|
@ -273,7 +277,7 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
|
||||
if ( ! is_null( $value ) ) {
|
||||
switch ( $key ) {
|
||||
case 'code' :
|
||||
case 'code':
|
||||
$coupon_code = wc_format_coupon_code( $value );
|
||||
$id = $coupon->get_id() ? $coupon->get_id() : 0;
|
||||
$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id );
|
||||
|
@ -284,17 +288,17 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
|
||||
$coupon->set_code( $coupon_code );
|
||||
break;
|
||||
case 'meta_data' :
|
||||
case 'meta_data':
|
||||
if ( is_array( $value ) ) {
|
||||
foreach ( $value as $meta ) {
|
||||
$coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'description' :
|
||||
case 'description':
|
||||
$coupon->set_description( wp_filter_post_kses( $value ) );
|
||||
break;
|
||||
default :
|
||||
default:
|
||||
if ( is_callable( array( $coupon, "set_{$key}" ) ) ) {
|
||||
$coupon->{"set_{$key}"}( $value );
|
||||
}
|
||||
|
@ -327,180 +331,180 @@ class WC_REST_Coupons_Controller extends WC_REST_Legacy_Coupons_Controller {
|
|||
'title' => $this->post_type,
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'code' => array(
|
||||
'code' => array(
|
||||
'description' => __( 'Coupon code.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'amount' => array(
|
||||
'amount' => array(
|
||||
'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_created' => array(
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( 'The date the coupon was created, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified_gmt' => array(
|
||||
'date_modified_gmt' => array(
|
||||
'description' => __( 'The date the coupon was last modified, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'discount_type' => array(
|
||||
'discount_type' => array(
|
||||
'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'default' => 'fixed_cart',
|
||||
'enum' => array_keys( wc_get_coupon_types() ),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'description' => array(
|
||||
'description' => array(
|
||||
'description' => __( 'Coupon description.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_expires' => array(
|
||||
'date_expires' => array(
|
||||
'description' => __( "The date the coupon expires, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_expires_gmt' => array(
|
||||
'description' => __( "The date the coupon expires, as GMT.", 'woocommerce' ),
|
||||
'date_expires_gmt' => array(
|
||||
'description' => __( 'The date the coupon expires, as GMT.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'usage_count' => array(
|
||||
'usage_count' => array(
|
||||
'description' => __( 'Number of times the coupon has been used already.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'individual_use' => array(
|
||||
'individual_use' => array(
|
||||
'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'product_ids' => array(
|
||||
'description' => __( "List of product IDs the coupon can be used on.", 'woocommerce' ),
|
||||
'product_ids' => array(
|
||||
'description' => __( 'List of product IDs the coupon can be used on.', 'woocommerce' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'excluded_product_ids' => array(
|
||||
'description' => __( "List of product IDs the coupon cannot be used on.", 'woocommerce' ),
|
||||
'excluded_product_ids' => array(
|
||||
'description' => __( 'List of product IDs the coupon cannot be used on.', 'woocommerce' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'usage_limit' => array(
|
||||
'usage_limit' => array(
|
||||
'description' => __( 'How many times the coupon can be used in total.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'usage_limit_per_user' => array(
|
||||
'usage_limit_per_user' => array(
|
||||
'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'limit_usage_to_x_items' => array(
|
||||
'limit_usage_to_x_items' => array(
|
||||
'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'free_shipping' => array(
|
||||
'free_shipping' => array(
|
||||
'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'product_categories' => array(
|
||||
'description' => __( "List of category IDs the coupon applies to.", 'woocommerce' ),
|
||||
'product_categories' => array(
|
||||
'description' => __( 'List of category IDs the coupon applies to.', 'woocommerce' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'excluded_product_categories' => array(
|
||||
'description' => __( "List of category IDs the coupon does not apply to.", 'woocommerce' ),
|
||||
'description' => __( 'List of category IDs the coupon does not apply to.', 'woocommerce' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'exclude_sale_items' => array(
|
||||
'exclude_sale_items' => array(
|
||||
'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'minimum_amount' => array(
|
||||
'minimum_amount' => array(
|
||||
'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'maximum_amount' => array(
|
||||
'maximum_amount' => array(
|
||||
'description' => __( 'Maximum order amount allowed when using the coupon.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'email_restrictions' => array(
|
||||
'email_restrictions' => array(
|
||||
'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'used_by' => array(
|
||||
'used_by' => array(
|
||||
'description' => __( 'List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'meta_data' => array(
|
||||
'meta_data' => array(
|
||||
'description' => __( 'Meta data.', 'woocommerce' ),
|
||||
'type' => 'array',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'items' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Meta ID.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'key' => array(
|
||||
'key' => array(
|
||||
'description' => __( 'Meta key.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /customers/<customer_id>/downloads endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Customers controller class.
|
||||
|
@ -32,7 +28,7 @@ class WC_REST_Customer_Downloads_Controller extends WC_REST_Customer_Downloads_V
|
|||
/**
|
||||
* Prepare a single download output for response.
|
||||
*
|
||||
* @param stdClass $download Download object.
|
||||
* @param stdClass $download Download object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
|
@ -81,43 +77,43 @@ class WC_REST_Customer_Downloads_Controller extends WC_REST_Customer_Downloads_V
|
|||
'title' => 'customer_download',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'download_id' => array(
|
||||
'download_id' => array(
|
||||
'description' => __( 'Download ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'download_url' => array(
|
||||
'download_url' => array(
|
||||
'description' => __( 'Download file URL.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'product_id' => array(
|
||||
'product_id' => array(
|
||||
'description' => __( 'Downloadable product ID.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'product_name' => array(
|
||||
'product_name' => array(
|
||||
'description' => __( 'Product name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'download_name' => array(
|
||||
'download_name' => array(
|
||||
'description' => __( 'Downloadable file name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'order_id' => array(
|
||||
'order_id' => array(
|
||||
'description' => __( 'Order ID.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'order_key' => array(
|
||||
'order_key' => array(
|
||||
'description' => __( 'Order key.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
|
@ -129,24 +125,24 @@ class WC_REST_Customer_Downloads_Controller extends WC_REST_Customer_Downloads_V
|
|||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'access_expires' => array(
|
||||
'access_expires' => array(
|
||||
'description' => __( "The date when download access expires, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'access_expires_gmt' => array(
|
||||
'description' => __( "The date when download access expires, as GMT.", 'woocommerce' ),
|
||||
'access_expires_gmt' => array(
|
||||
'description' => __( 'The date when download access expires, as GMT.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'file' => array(
|
||||
'file' => array(
|
||||
'description' => __( 'File details.', 'woocommerce' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
'properties' => array(
|
||||
'properties' => array(
|
||||
'name' => array(
|
||||
'description' => __( 'File name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /customers endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Customers controller class.
|
||||
|
@ -71,17 +67,17 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_Controller {
|
|||
/**
|
||||
* Prepare a single customer output for response.
|
||||
*
|
||||
* @param WP_User $user_data User object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @param WP_User $user_data User object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
public function prepare_item_for_response( $user_data, $request ) {
|
||||
$customer = new WC_Customer( $user_data->ID );
|
||||
$data = $this->get_formatted_item_data( $customer );
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
$response = rest_ensure_response( $data );
|
||||
$customer = new WC_Customer( $user_data->ID );
|
||||
$data = $this->get_formatted_item_data( $customer );
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
$response = rest_ensure_response( $data );
|
||||
$response->add_links( $this->prepare_links( $user_data ) );
|
||||
|
||||
/**
|
||||
|
@ -97,8 +93,8 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_Controller {
|
|||
/**
|
||||
* Update customer meta fields.
|
||||
*
|
||||
* @param WC_Customer $customer
|
||||
* @param WP_REST_Request $request
|
||||
* @param WC_Customer $customer Cusotmer data.
|
||||
* @param WP_REST_Request $request Request data.
|
||||
*/
|
||||
protected function update_customer_meta_fields( $customer, $request ) {
|
||||
parent::update_customer_meta_fields( $customer, $request );
|
||||
|
@ -124,43 +120,43 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_Controller {
|
|||
'title' => 'customer',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created' => array(
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the customer was created, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( 'The date the order was created, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the customer was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified_gmt' => array(
|
||||
'date_modified_gmt' => array(
|
||||
'description' => __( 'The date the customer was last modified, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'email' => array(
|
||||
'email' => array(
|
||||
'description' => __( 'The email address for the customer.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'format' => 'email',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'first_name' => array(
|
||||
'first_name' => array(
|
||||
'description' => __( 'Customer first name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -168,7 +164,7 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_Controller {
|
|||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'last_name' => array(
|
||||
'last_name' => array(
|
||||
'description' => __( 'Customer last name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -176,13 +172,13 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_Controller {
|
|||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'role' => array(
|
||||
'role' => array(
|
||||
'description' => __( 'Customer role.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'username' => array(
|
||||
'username' => array(
|
||||
'description' => __( 'Customer login name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -190,120 +186,120 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_Controller {
|
|||
'sanitize_callback' => 'sanitize_user',
|
||||
),
|
||||
),
|
||||
'password' => array(
|
||||
'password' => array(
|
||||
'description' => __( 'Customer password.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
),
|
||||
'billing' => array(
|
||||
'billing' => array(
|
||||
'description' => __( 'List of billing address data.', 'woocommerce' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'properties' => array(
|
||||
'properties' => array(
|
||||
'first_name' => array(
|
||||
'description' => __( 'First name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'last_name' => array(
|
||||
'last_name' => array(
|
||||
'description' => __( 'Last name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'company' => array(
|
||||
'company' => array(
|
||||
'description' => __( 'Company name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'address_1' => array(
|
||||
'address_1' => array(
|
||||
'description' => __( 'Address line 1', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'address_2' => array(
|
||||
'address_2' => array(
|
||||
'description' => __( 'Address line 2', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'city' => array(
|
||||
'city' => array(
|
||||
'description' => __( 'City name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'state' => array(
|
||||
'state' => array(
|
||||
'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'postcode' => array(
|
||||
'postcode' => array(
|
||||
'description' => __( 'Postal code.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'country' => array(
|
||||
'country' => array(
|
||||
'description' => __( 'ISO code of the country.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'email' => array(
|
||||
'email' => array(
|
||||
'description' => __( 'Email address.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'format' => 'email',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'phone' => array(
|
||||
'phone' => array(
|
||||
'description' => __( 'Phone number.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'shipping' => array(
|
||||
'shipping' => array(
|
||||
'description' => __( 'List of shipping address data.', 'woocommerce' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'properties' => array(
|
||||
'properties' => array(
|
||||
'first_name' => array(
|
||||
'description' => __( 'First name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'last_name' => array(
|
||||
'last_name' => array(
|
||||
'description' => __( 'Last name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'company' => array(
|
||||
'company' => array(
|
||||
'description' => __( 'Company name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'address_1' => array(
|
||||
'address_1' => array(
|
||||
'description' => __( 'Address line 1', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'address_2' => array(
|
||||
'address_2' => array(
|
||||
'description' => __( 'Address line 2', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'city' => array(
|
||||
'city' => array(
|
||||
'description' => __( 'City name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'state' => array(
|
||||
'state' => array(
|
||||
'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'postcode' => array(
|
||||
'postcode' => array(
|
||||
'description' => __( 'Postal code.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'country' => array(
|
||||
'country' => array(
|
||||
'description' => __( 'ISO code of the country.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -316,38 +312,38 @@ class WC_REST_Customers_Controller extends WC_REST_Customers_V1_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'orders_count' => array(
|
||||
'orders_count' => array(
|
||||
'description' => __( 'Quantity of orders made by the customer.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'total_spent' => array(
|
||||
'total_spent' => array(
|
||||
'description' => __( 'Total amount spent.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'avatar_url' => array(
|
||||
'avatar_url' => array(
|
||||
'description' => __( 'Avatar URL.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'meta_data' => array(
|
||||
'meta_data' => array(
|
||||
'description' => __( 'Meta data.', 'woocommerce' ),
|
||||
'type' => 'array',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'items' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Meta ID.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'key' => array(
|
||||
'key' => array(
|
||||
'description' => __( 'Meta key.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Extends Exception to provide additional data.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WC_REST_Exception class.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /orders/network endpoint
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 3.3
|
||||
* @since 3.4.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Network Orders controller class.
|
||||
|
@ -27,15 +23,17 @@ class WC_REST_Network_Orders_Controller extends WC_REST_Orders_Controller {
|
|||
*/
|
||||
public function register_routes() {
|
||||
if ( is_multisite() ) {
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/network', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'network_orders' ),
|
||||
'permission_callback' => array( $this, 'network_orders_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/network', array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'network_orders' ),
|
||||
'permission_callback' => array( $this, 'network_orders_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,25 +47,25 @@ class WC_REST_Network_Orders_Controller extends WC_REST_Orders_Controller {
|
|||
public function get_public_item_schema() {
|
||||
$schema = parent::get_public_item_schema();
|
||||
|
||||
$schema['properties']['blog'] = array(
|
||||
$schema['properties']['blog'] = array(
|
||||
'description' => __( 'Blog id of the record on the multisite.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
);
|
||||
$schema['properties']['edit_url'] = array(
|
||||
$schema['properties']['edit_url'] = array(
|
||||
'description' => __( 'URL to edit the order', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
);
|
||||
$schema['properties']['customer'][] = array(
|
||||
$schema['properties']['customer'][] = array(
|
||||
'description' => __( 'Name of the customer for the order', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
);
|
||||
$schema['properties']['status_name'][] = array(
|
||||
$schema['properties']['status_name'][] = array(
|
||||
'description' => __( 'Order Status', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
|
@ -123,11 +121,11 @@ class WC_REST_Network_Orders_Controller extends WC_REST_Orders_Controller {
|
|||
foreach ( $items->data as &$current_order ) {
|
||||
$order = wc_get_order( $current_order['id'] );
|
||||
|
||||
$current_order['blog'] = get_blog_details( get_current_blog_id() );
|
||||
$current_order['blog'] = get_blog_details( get_current_blog_id() );
|
||||
$current_order['edit_url'] = get_admin_url( $blog_id, 'post.php?post=' . absint( $order->get_id() ) . '&action=edit' );
|
||||
/* translators: 1: first name 2: last name */
|
||||
$current_order['customer'] = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) );
|
||||
$current_order['status_name'] = wc_get_order_status_name( $order->get_status() );
|
||||
$current_order['customer'] = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) );
|
||||
$current_order['status_name'] = wc_get_order_status_name( $order->get_status() );
|
||||
$current_order['formatted_total'] = $order->get_formatted_order_total();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /orders/<order_id>/notes endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Order Notes controller class.
|
||||
|
@ -32,7 +28,7 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Order_Notes_V1_Controller {
|
|||
/**
|
||||
* Get order notes from an order.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
|
@ -51,7 +47,7 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Order_Notes_V1_Controller {
|
|||
|
||||
// Allow filter by order note type.
|
||||
if ( 'customer' === $request['type'] ) {
|
||||
$args['meta_query'] = array(
|
||||
$args['meta_query'] = array( // WPCS: slow query ok.
|
||||
array(
|
||||
'key' => 'is_customer_note',
|
||||
'value' => 1,
|
||||
|
@ -59,7 +55,7 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Order_Notes_V1_Controller {
|
|||
),
|
||||
);
|
||||
} elseif ( 'internal' === $request['type'] ) {
|
||||
$args['meta_query'] = array(
|
||||
$args['meta_query'] = array( // WPCS: slow query ok.
|
||||
array(
|
||||
'key' => 'is_customer_note',
|
||||
'compare' => 'NOT EXISTS',
|
||||
|
@ -86,7 +82,7 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Order_Notes_V1_Controller {
|
|||
/**
|
||||
* Prepare a single order note output for response.
|
||||
*
|
||||
* @param WP_Comment $note Order note object.
|
||||
* @param WP_Comment $note Order note object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
|
@ -129,30 +125,30 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Order_Notes_V1_Controller {
|
|||
'title' => 'order_note',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created' => array(
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the order note was created, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the order note was created, as GMT.", 'woocommerce' ),
|
||||
'description' => __( 'The date the order note was created, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'note' => array(
|
||||
'note' => array(
|
||||
'description' => __( 'Order note content.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'customer_note' => array(
|
||||
'customer_note' => array(
|
||||
'description' => __( 'If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
|
|
|
@ -4,13 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /orders/<order_id>/refunds endpoint.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Order Refunds controller class.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,17 +4,15 @@
|
|||
*
|
||||
* Handles requests to the /payment_gateways endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Paymenga gateways controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Controller
|
||||
*/
|
||||
|
@ -38,38 +36,42 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
* Register the route for /payment_gateways and /payment_gateways/<id>
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,7 +134,7 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Get a single payment gateway.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
|
@ -149,7 +151,7 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Update A Single Payment Method.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
|
@ -188,26 +190,29 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
|
||||
// Update if this method is enabled or not.
|
||||
if ( isset( $request['enabled'] ) ) {
|
||||
$gateway->enabled = $settings['enabled'] = wc_bool_to_string( $request['enabled'] );
|
||||
$settings['enabled'] = wc_bool_to_string( $request['enabled'] );
|
||||
$gateway->enabled = $settings['enabled'];
|
||||
}
|
||||
|
||||
// Update title.
|
||||
if ( isset( $request['title'] ) ) {
|
||||
$gateway->title = $settings['title'] = $request['title'];
|
||||
$settings['title'] = $request['title'];
|
||||
$gateway->title = $settings['title'];
|
||||
}
|
||||
|
||||
// Update description.
|
||||
if ( isset( $request['description'] ) ) {
|
||||
$gateway->description = $settings['description'] = $request['description'];
|
||||
$settings['description'] = $request['description'];
|
||||
$gateway->description = $settings['description'];
|
||||
}
|
||||
|
||||
// Update options.
|
||||
$gateway->settings = $settings;
|
||||
update_option( $gateway->get_option_key(), apply_filters( 'woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway ) );
|
||||
|
||||
// Update order
|
||||
// Update order.
|
||||
if ( isset( $request['order'] ) ) {
|
||||
$order = (array) get_option( 'woocommerce_gateway_order' );
|
||||
$order = (array) get_option( 'woocommerce_gateway_order' );
|
||||
$order[ $gateway->id ] = $request['order'];
|
||||
update_option( 'woocommerce_gateway_order', $order );
|
||||
$gateway->order = absint( $request['order'] );
|
||||
|
@ -220,7 +225,7 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Get a gateway based on the current request object.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response|null
|
||||
*/
|
||||
public function get_gateway( $request ) {
|
||||
|
@ -244,8 +249,8 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
public function prepare_item_for_response( $gateway, $request ) {
|
||||
$order = (array) get_option( 'woocommerce_gateway_order' );
|
||||
$item = array(
|
||||
$order = (array) get_option( 'woocommerce_gateway_order' );
|
||||
$item = array(
|
||||
'id' => $gateway->id,
|
||||
'title' => $gateway->title,
|
||||
'description' => $gateway->description,
|
||||
|
@ -276,7 +281,7 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Return settings associated with this payment gateway.
|
||||
*
|
||||
* @param WC_Payment_Gateway $gateway
|
||||
* @param WC_Payment_Gateway $gateway Gateway data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@ -284,16 +289,16 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
$settings = array();
|
||||
$gateway->init_form_fields();
|
||||
foreach ( $gateway->form_fields as $id => $field ) {
|
||||
// Make sure we at least have a title and type
|
||||
// Make sure we at least have a title and type.
|
||||
if ( empty( $field['title'] ) || empty( $field['type'] ) ) {
|
||||
continue;
|
||||
}
|
||||
// Ignore 'title' settings/fields -- they are UI only
|
||||
// Ignore 'title' settings/fields -- they are UI only.
|
||||
if ( 'title' === $field['type'] ) {
|
||||
continue;
|
||||
}
|
||||
// Ignore 'enabled' and 'description' which get included elsewhere.
|
||||
if ( in_array( $id, array( 'enabled', 'description' ) ) ) {
|
||||
if ( in_array( $id, array( 'enabled', 'description' ), true ) ) {
|
||||
continue;
|
||||
}
|
||||
$data = array(
|
||||
|
@ -322,8 +327,8 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
* @return array
|
||||
*/
|
||||
protected function prepare_links( $gateway, $request ) {
|
||||
$links = array(
|
||||
'self' => array(
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $gateway->id ) ),
|
||||
),
|
||||
'collection' => array(
|
||||
|
@ -334,7 +339,7 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get the payment gateway schema, conforming to JSON Schema.
|
||||
*
|
||||
* @return array
|
||||
|
@ -345,23 +350,23 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
'title' => 'payment_gateway',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Payment gateway ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'title' => array(
|
||||
'title' => array(
|
||||
'description' => __( 'Payment gateway title on checkout.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'description' => array(
|
||||
'description' => array(
|
||||
'description' => __( 'Payment gateway description on checkout.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'order' => array(
|
||||
'order' => array(
|
||||
'description' => __( 'Payment gateway sort order.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -369,12 +374,12 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
'sanitize_callback' => 'absint',
|
||||
),
|
||||
),
|
||||
'enabled' => array(
|
||||
'enabled' => array(
|
||||
'description' => __( 'Payment gateway enabled status.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'method_title' => array(
|
||||
'method_title' => array(
|
||||
'description' => __( 'Payment gateway method title.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -386,18 +391,18 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'settings' => array(
|
||||
'settings' => array(
|
||||
'description' => __( 'Payment gateway settings.', 'woocommerce' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'label' => array(
|
||||
'label' => array(
|
||||
'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -409,25 +414,25 @@ class WC_REST_Payment_Gateways_Controller extends WC_REST_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'type' => array(
|
||||
'type' => array(
|
||||
'description' => __( 'Type of setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'value' => array(
|
||||
'value' => array(
|
||||
'description' => __( 'Setting value.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'default' => array(
|
||||
'default' => array(
|
||||
'description' => __( 'Default value for the setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'tip' => array(
|
||||
'tip' => array(
|
||||
'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the products/attributes/<attribute_id>/terms endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Product Attribute Terms controller class.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the products/attributes endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Product Attributes controller class.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the products/categories endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Product Categories controller class.
|
||||
|
@ -99,17 +95,17 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Product_Categories_V
|
|||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => $this->taxonomy,
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => $this->taxonomy,
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'name' => array(
|
||||
'description' => __( 'Category name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -117,7 +113,7 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Product_Categories_V
|
|||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'slug' => array(
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -125,7 +121,7 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Product_Categories_V
|
|||
'sanitize_callback' => 'sanitize_title',
|
||||
),
|
||||
),
|
||||
'parent' => array(
|
||||
'parent' => array(
|
||||
'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -138,36 +134,36 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Product_Categories_V
|
|||
'sanitize_callback' => 'wp_filter_post_kses',
|
||||
),
|
||||
),
|
||||
'display' => array(
|
||||
'display' => array(
|
||||
'description' => __( 'Category archive display type.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'default' => 'default',
|
||||
'enum' => array( 'default', 'products', 'subcategories', 'both' ),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'image' => array(
|
||||
'image' => array(
|
||||
'description' => __( 'Image data.', 'woocommerce' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Image ID.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_created' => array(
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_modified' => array(
|
||||
'date_modified' => array(
|
||||
'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -179,30 +175,30 @@ class WC_REST_Product_Categories_Controller extends WC_REST_Product_Categories_V
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'src' => array(
|
||||
'src' => array(
|
||||
'description' => __( 'Image URL.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'title' => array(
|
||||
'title' => array(
|
||||
'description' => __( 'Image name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'alt' => array(
|
||||
'alt' => array(
|
||||
'description' => __( 'Image alternative text.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'menu_order' => array(
|
||||
'menu_order' => array(
|
||||
'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'count' => array(
|
||||
'count' => array(
|
||||
'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to /products/<product_id>/reviews.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Product Reviews Controller Class.
|
||||
|
@ -42,21 +38,23 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Product_Reviews_V1_Cont
|
|||
public function register_routes() {
|
||||
parent::register_routes();
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
|
||||
'args' => array(
|
||||
'product_id' => array(
|
||||
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/batch', array(
|
||||
'args' => array(
|
||||
'product_id' => array(
|
||||
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'batch_items' ),
|
||||
'permission_callback' => array( $this, 'batch_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_batch_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'batch_items' ),
|
||||
'permission_callback' => array( $this, 'batch_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_batch_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,7 +73,7 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Product_Reviews_V1_Cont
|
|||
/**
|
||||
* Prepare a single product review output for response.
|
||||
*
|
||||
* @param WP_Comment $review Product review object.
|
||||
* @param WP_Comment $review Product review object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
|
@ -151,43 +149,43 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Product_Reviews_V1_Cont
|
|||
'title' => 'product_review',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'review' => array(
|
||||
'review' => array(
|
||||
'description' => __( 'The content of the review.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_created' => array(
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'date_created_gmt' => array(
|
||||
'description' => __( "The date the review was created, as GMT.", 'woocommerce' ),
|
||||
'description' => __( 'The date the review was created, as GMT.', 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'rating' => array(
|
||||
'rating' => array(
|
||||
'description' => __( 'Review rating (0 to 5).', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'name' => array(
|
||||
'name' => array(
|
||||
'description' => __( 'Reviewer name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'email' => array(
|
||||
'email' => array(
|
||||
'description' => __( 'Reviewer email.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'verified' => array(
|
||||
'verified' => array(
|
||||
'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the products/shipping_classes endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Product Shipping Classes controller class.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the products/tags endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Product Tags controller class.
|
||||
|
|
|
@ -4,13 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /products/<product_id>/variations endpoints.
|
||||
*
|
||||
* @package WooCommerce\API
|
||||
* @since 3.0.0
|
||||
* @package WooCommerce\API
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API variations controller class.
|
||||
|
|
|
@ -8,9 +8,7 @@
|
|||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Products controller class.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the reports/sales endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Report Sales controller class.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the reports/top_sellers endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Report Top Sellers controller class.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the reports endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Reports controller class.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /settings/$group/$setting endpoints.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Setting Options controller class.
|
||||
|
@ -24,6 +20,8 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
|
||||
/**
|
||||
* WP REST API namespace/version.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v2';
|
||||
|
||||
|
@ -40,68 +38,74 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
* @since 3.0.0
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
'args' => array(
|
||||
'group' => array(
|
||||
'description' => __( 'Settings group ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base, array(
|
||||
'args' => array(
|
||||
'group' => array(
|
||||
'description' => __( 'Settings group ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
|
||||
'args' => array(
|
||||
'group' => array(
|
||||
'description' => __( 'Settings group ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/batch', array(
|
||||
'args' => array(
|
||||
'group' => array(
|
||||
'description' => __( 'Settings group ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'batch_items' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_batch_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'batch_items' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_batch_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'group' => array(
|
||||
'description' => __( 'Settings group ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'group' => array(
|
||||
'description' => __( 'Settings group ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a single setting.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
|
@ -120,7 +124,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
* Return all settings in a group.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
|
@ -136,7 +140,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
$setting = $this->prepare_item_for_response( $setting_obj, $request );
|
||||
$setting = $this->prepare_response_for_collection( $setting );
|
||||
if ( $this->is_setting_type_valid( $setting['type'] ) ) {
|
||||
$data[] = $setting;
|
||||
$data[] = $setting;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,7 +170,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
$option_key = $setting['option_key'];
|
||||
$setting = $this->filter_setting( $setting );
|
||||
$default = isset( $setting['default'] ) ? $setting['default'] : '';
|
||||
// Get the option value
|
||||
// Get the option value.
|
||||
if ( is_array( $option_key ) ) {
|
||||
$option = get_option( $option_key[0] );
|
||||
$setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default;
|
||||
|
@ -204,7 +208,8 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
$output = array();
|
||||
|
||||
foreach ( $countries as $key => $value ) {
|
||||
if ( $states = WC()->countries->get_states( $key ) ) {
|
||||
$states = WC()->countries->get_states( $key );
|
||||
if ( $states ) {
|
||||
foreach ( $states as $state_key => $state_value ) {
|
||||
$output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value;
|
||||
}
|
||||
|
@ -281,7 +286,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
* Update a single setting in a group.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
|
@ -308,7 +313,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
$prev[ $option_key[1] ] = $request['value'];
|
||||
update_option( $option_key[0], $prev );
|
||||
} else {
|
||||
$update_data = array();
|
||||
$update_data = array();
|
||||
$update_data[ $setting['option_key'] ] = $value;
|
||||
$setting['value'] = $value;
|
||||
WC_Admin_Settings::save_fields( array( $setting ), $update_data );
|
||||
|
@ -323,7 +328,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
* Prepare a single setting object for response.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param object $item Setting object.
|
||||
* @param object $item Setting object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
|
@ -346,9 +351,9 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
* @return array Links for the given setting.
|
||||
*/
|
||||
protected function prepare_links( $setting_id, $group_id ) {
|
||||
$base = str_replace( '(?P<group_id>[\w-]+)', $group_id, $this->rest_base );
|
||||
$base = str_replace( '(?P<group_id>[\w-]+)', $group_id, $this->rest_base );
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'self' => array(
|
||||
'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $setting_id ) ),
|
||||
),
|
||||
'collection' => array(
|
||||
|
@ -394,7 +399,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
* only return known values via the API.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param array $setting
|
||||
* @param array $setting Settings.
|
||||
* @return array
|
||||
*/
|
||||
public function filter_setting( $setting ) {
|
||||
|
@ -420,7 +425,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
*
|
||||
* @todo remove in 4.0
|
||||
* @since 3.0.0
|
||||
* @param array $setting
|
||||
* @param array $setting Settings.
|
||||
* @return array
|
||||
*/
|
||||
public function cast_image_width( $setting ) {
|
||||
|
@ -438,46 +443,50 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
* Callback for allowed keys for each setting response.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param string $key Key to check
|
||||
* @param string $key Key to check.
|
||||
* @return boolean
|
||||
*/
|
||||
public function allowed_setting_keys( $key ) {
|
||||
return in_array( $key, array(
|
||||
'id',
|
||||
'label',
|
||||
'description',
|
||||
'default',
|
||||
'tip',
|
||||
'placeholder',
|
||||
'type',
|
||||
'options',
|
||||
'value',
|
||||
'option_key',
|
||||
) );
|
||||
return in_array(
|
||||
$key, array(
|
||||
'id',
|
||||
'label',
|
||||
'description',
|
||||
'default',
|
||||
'tip',
|
||||
'placeholder',
|
||||
'type',
|
||||
'options',
|
||||
'value',
|
||||
'option_key',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Boolean for if a setting type is a valid supported setting type.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param string $type
|
||||
* @param string $type Type.
|
||||
* @return bool
|
||||
*/
|
||||
public function is_setting_type_valid( $type ) {
|
||||
return in_array( $type, array(
|
||||
'text', // Validates with validate_setting_text_field.
|
||||
'email', // Validates with validate_setting_text_field.
|
||||
'number', // Validates with validate_setting_text_field.
|
||||
'color', // Validates with validate_setting_text_field.
|
||||
'password', // Validates with validate_setting_text_field.
|
||||
'textarea', // Validates with validate_setting_textarea_field.
|
||||
'select', // Validates with validate_setting_select_field.
|
||||
'multiselect', // Validates with validate_setting_multiselect_field.
|
||||
'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field).
|
||||
'checkbox', // Validates with validate_setting_checkbox_field.
|
||||
'image_width', // Validates with validate_setting_image_width_field.
|
||||
'thumbnail_cropping', // Validates with validate_setting_text_field.
|
||||
) );
|
||||
return in_array(
|
||||
$type, array(
|
||||
'text', // Validates with validate_setting_text_field.
|
||||
'email', // Validates with validate_setting_text_field.
|
||||
'number', // Validates with validate_setting_text_field.
|
||||
'color', // Validates with validate_setting_text_field.
|
||||
'password', // Validates with validate_setting_text_field.
|
||||
'textarea', // Validates with validate_setting_textarea_field.
|
||||
'select', // Validates with validate_setting_select_field.
|
||||
'multiselect', // Validates with validate_setting_multiselect_field.
|
||||
'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field).
|
||||
'checkbox', // Validates with validate_setting_checkbox_field.
|
||||
'image_width', // Validates with validate_setting_image_width_field.
|
||||
'thumbnail_cropping', // Validates with validate_setting_text_field.
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -488,77 +497,77 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'setting',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'setting',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_title',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'label' => array(
|
||||
'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'label' => array(
|
||||
'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'description' => array(
|
||||
'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'value' => array(
|
||||
'description' => __( 'Setting value.', 'woocommerce' ),
|
||||
'type' => 'mixed',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'value' => array(
|
||||
'description' => __( 'Setting value.', 'woocommerce' ),
|
||||
'type' => 'mixed',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'default' => array(
|
||||
'description' => __( 'Default value for the setting.', 'woocommerce' ),
|
||||
'type' => 'mixed',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'default' => array(
|
||||
'description' => __( 'Default value for the setting.', 'woocommerce' ),
|
||||
'type' => 'mixed',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'tip' => array(
|
||||
'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'tip' => array(
|
||||
'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'placeholder' => array(
|
||||
'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'placeholder' => array(
|
||||
'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __( 'Type of setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'type' => array(
|
||||
'description' => __( 'Type of setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'thumbnail_cropping' ),
|
||||
'readonly' => true,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'thumbnail_cropping' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'options' => array(
|
||||
'options' => array(
|
||||
'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /settings endpoints.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Settings controller class.
|
||||
|
@ -24,6 +20,8 @@ class WC_REST_Settings_Controller extends WC_REST_Controller {
|
|||
|
||||
/**
|
||||
* WP REST API namespace/version.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'wc/v2';
|
||||
|
||||
|
@ -40,21 +38,23 @@ class WC_REST_Settings_Controller extends WC_REST_Controller {
|
|||
* @since 3.0.0
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all settings groups items.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
|
@ -109,7 +109,7 @@ class WC_REST_Settings_Controller extends WC_REST_Controller {
|
|||
* Prepare a report sales object for serialization.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param array $item Group object.
|
||||
* @param array $item Group object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
*/
|
||||
|
@ -130,7 +130,7 @@ class WC_REST_Settings_Controller extends WC_REST_Controller {
|
|||
* only return known values via the API.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param array $group
|
||||
* @param array $group Group.
|
||||
* @return array
|
||||
*/
|
||||
public function filter_group( $group ) {
|
||||
|
@ -144,7 +144,7 @@ class WC_REST_Settings_Controller extends WC_REST_Controller {
|
|||
* Callback for allowed keys for each group response.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param string $key Key to check
|
||||
* @param string $key Key to check.
|
||||
* @return boolean
|
||||
*/
|
||||
public function allowed_group_keys( $key ) {
|
||||
|
@ -194,13 +194,13 @@ class WC_REST_Settings_Controller extends WC_REST_Controller {
|
|||
'title' => 'setting_group',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'A unique identifier that can be used to link settings together.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'label' => array(
|
||||
'label' => array(
|
||||
'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
|
@ -212,13 +212,13 @@ class WC_REST_Settings_Controller extends WC_REST_Controller {
|
|||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'parent_id' => array(
|
||||
'parent_id' => array(
|
||||
'description' => __( 'ID of parent grouping.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'sub_groups' => array(
|
||||
'sub_groups' => array(
|
||||
'description' => __( 'IDs for settings sub groups.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
|
|
|
@ -4,17 +4,15 @@
|
|||
*
|
||||
* Handles requests to the /shipping_methods endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Shipping methods controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Controller
|
||||
*/
|
||||
|
@ -38,32 +36,36 @@ class WC_REST_Shipping_Methods_Controller extends WC_REST_Controller {
|
|||
* Register the route for /shipping_methods and /shipping_methods/<method>
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -102,8 +104,8 @@ class WC_REST_Shipping_Methods_Controller extends WC_REST_Controller {
|
|||
$wc_shipping = WC_Shipping::instance();
|
||||
$response = array();
|
||||
foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) {
|
||||
$method = $this->prepare_item_for_response( $shipping_method, $request );
|
||||
$method = $this->prepare_response_for_collection( $method );
|
||||
$method = $this->prepare_item_for_response( $shipping_method, $request );
|
||||
$method = $this->prepare_response_for_collection( $method );
|
||||
$response[] = $method;
|
||||
}
|
||||
return rest_ensure_response( $response );
|
||||
|
@ -112,7 +114,7 @@ class WC_REST_Shipping_Methods_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Get a single Shipping Method.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
|
@ -137,9 +139,9 @@ class WC_REST_Shipping_Methods_Controller extends WC_REST_Controller {
|
|||
*/
|
||||
public function prepare_item_for_response( $method, $request ) {
|
||||
$data = array(
|
||||
'id' => $method->id,
|
||||
'title' => $method->method_title,
|
||||
'description' => $method->method_description,
|
||||
'id' => $method->id,
|
||||
'title' => $method->method_title,
|
||||
'description' => $method->method_description,
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
|
@ -165,12 +167,12 @@ class WC_REST_Shipping_Methods_Controller extends WC_REST_Controller {
|
|||
* Prepare links for the request.
|
||||
*
|
||||
* @param WC_Shipping_Method $method Shipping method object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return array
|
||||
*/
|
||||
protected function prepare_links( $method, $request ) {
|
||||
$links = array(
|
||||
'self' => array(
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $method->id ) ),
|
||||
),
|
||||
'collection' => array(
|
||||
|
@ -192,13 +194,13 @@ class WC_REST_Shipping_Methods_Controller extends WC_REST_Controller {
|
|||
'title' => 'shipping_method',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Method ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'title' => array(
|
||||
'title' => array(
|
||||
'description' => __( 'Shipping method title.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /shipping/zones/<id>/locations endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Shipping Zone Locations class.
|
||||
|
@ -26,32 +22,34 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
|
|||
* Register the routes for Shipping Zone Locations.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)/locations', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique ID for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)/locations', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique ID for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_items' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_items' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Shipping Zone Locations.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
|
@ -76,7 +74,7 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
|
|||
/**
|
||||
* Update all Shipping Zone Locations.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function update_items( $request ) {
|
||||
|
@ -87,7 +85,7 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
|
|||
}
|
||||
|
||||
if ( 0 === $zone->get_id() ) {
|
||||
return new WP_Error( "woocommerce_rest_shipping_zone_locations_invalid_zone", __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) );
|
||||
return new WP_Error( 'woocommerce_rest_shipping_zone_locations_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) );
|
||||
}
|
||||
|
||||
$raw_locations = $request->get_json_params();
|
||||
|
@ -119,7 +117,7 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
|
|||
/**
|
||||
* Prepare the Shipping Zone Location for the REST response.
|
||||
*
|
||||
* @param array $item Shipping Zone Location.
|
||||
* @param array $item Shipping Zone Location.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response
|
||||
*/
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /shipping/zones/<id>/methods endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Shipping Zone Methods class.
|
||||
|
@ -26,75 +22,81 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
* Register the routes for Shipping Zone Methods.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d]+)/methods', array(
|
||||
'args' => array(
|
||||
'zone_id' => array(
|
||||
'description' => __( 'Unique ID for the zone.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
|
||||
'method_id' => array(
|
||||
'required' => true,
|
||||
'readonly' => false,
|
||||
'description' => __( 'Shipping method ID.', 'woocommerce' ),
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d]+)/methods', array(
|
||||
'args' => array(
|
||||
'zone_id' => array(
|
||||
'description' => __( 'Unique ID for the zone.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
) ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => array_merge(
|
||||
$this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
|
||||
'method_id' => array(
|
||||
'required' => true,
|
||||
'readonly' => false,
|
||||
'description' => __( 'Shipping method ID.', 'woocommerce' ),
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', array(
|
||||
'args' => array(
|
||||
'zone_id' => array(
|
||||
'description' => __( 'Unique ID for the zone.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
'instance_id' => array(
|
||||
'description' => __( 'Unique ID for the instance.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_items_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'default' => false,
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', array(
|
||||
'args' => array(
|
||||
'zone_id' => array(
|
||||
'description' => __( 'Unique ID for the zone.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
'instance_id' => array(
|
||||
'description' => __( 'Unique ID for the instance.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_items_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'default' => false,
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single Shipping Zone Method.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
|
@ -127,7 +129,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
/**
|
||||
* Get all Shipping Zone Methods.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
|
@ -187,7 +189,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
/**
|
||||
* Delete a shipping method instance.
|
||||
*
|
||||
* @param WP_REST_Request $request Full details about the request
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
public function delete_item( $request ) {
|
||||
|
@ -199,8 +201,8 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
$instance_id = (int) $request['instance_id'];
|
||||
$force = $request['force'];
|
||||
|
||||
$methods = $zone->get_shipping_methods();
|
||||
$method = false;
|
||||
$methods = $zone->get_shipping_methods();
|
||||
$method = false;
|
||||
|
||||
foreach ( $methods as $method_obj ) {
|
||||
if ( $instance_id === $method_obj->instance_id ) {
|
||||
|
@ -221,7 +223,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
$request->set_param( 'context', 'view' );
|
||||
$response = $this->prepare_item_for_response( $method, $request );
|
||||
|
||||
// Actually delete
|
||||
// Actually delete.
|
||||
if ( $force ) {
|
||||
$zone->delete_shipping_method( $instance_id );
|
||||
} else {
|
||||
|
@ -243,7 +245,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
/**
|
||||
* Update A Single Shipping Zone Method.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
|
@ -279,16 +281,16 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
/**
|
||||
* Updates settings, order, and enabled status on create.
|
||||
*
|
||||
* @param int $instance_id integer
|
||||
* @param WC_Shipping_Method $method
|
||||
* @param WP_REST_Request $request
|
||||
* @param int $instance_id Instance ID.
|
||||
* @param WC_Shipping_Method $method Shipping method data.
|
||||
* @param WP_REST_Request $request Request data.
|
||||
*
|
||||
* @return WC_Shipping_Method
|
||||
*/
|
||||
public function update_fields( $instance_id, $method, $request ) {
|
||||
global $wpdb;
|
||||
|
||||
// Update settings if present
|
||||
// Update settings if present.
|
||||
if ( isset( $request['settings'] ) ) {
|
||||
$method->init_instance_settings();
|
||||
$instance_settings = $method->instance_settings;
|
||||
|
@ -315,7 +317,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
update_option( $method->get_instance_option_key(), apply_filters( 'woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method ) );
|
||||
}
|
||||
|
||||
// Update order
|
||||
// Update order.
|
||||
if ( isset( $request['order'] ) ) {
|
||||
$wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request['order'] ) ), array( 'instance_id' => absint( $instance_id ) ) );
|
||||
$method->method_order = absint( $request['order'] );
|
||||
|
@ -335,7 +337,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
/**
|
||||
* Prepare the Shipping Zone Method for the REST response.
|
||||
*
|
||||
* @param array $item Shipping Zone Method.
|
||||
* @param array $item Shipping Zone Method.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response
|
||||
*/
|
||||
|
@ -369,7 +371,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
/**
|
||||
* Return settings associated with this shipping zone method instance.
|
||||
*
|
||||
* @param WC_Shipping_Method $item
|
||||
* @param WC_Shipping_Method $item Shipping method data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@ -405,7 +407,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
protected function prepare_links( $zone_id, $instance_id ) {
|
||||
$base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id;
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'self' => array(
|
||||
'href' => rest_url( $base . '/methods/' . $instance_id ),
|
||||
),
|
||||
'collection' => array(
|
||||
|
@ -430,41 +432,41 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
'title' => 'shipping_zone_method',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Shipping method instance ID.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'instance_id' => array(
|
||||
'instance_id' => array(
|
||||
'description' => __( 'Shipping method instance ID.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'title' => array(
|
||||
'title' => array(
|
||||
'description' => __( 'Shipping method customer facing title.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'order' => array(
|
||||
'order' => array(
|
||||
'description' => __( 'Shipping method sort order.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'enabled' => array(
|
||||
'enabled' => array(
|
||||
'description' => __( 'Shipping method enabled status.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'method_id' => array(
|
||||
'method_id' => array(
|
||||
'description' => __( 'Shipping method ID.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'method_title' => array(
|
||||
'method_title' => array(
|
||||
'description' => __( 'Shipping method title.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -476,18 +478,18 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'settings' => array(
|
||||
'settings' => array(
|
||||
'description' => __( 'Shipping method settings.', 'woocommerce' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'label' => array(
|
||||
'label' => array(
|
||||
'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -499,25 +501,25 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'type' => array(
|
||||
'type' => array(
|
||||
'description' => __( 'Type of setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'value' => array(
|
||||
'value' => array(
|
||||
'description' => __( 'Setting value.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'default' => array(
|
||||
'default' => array(
|
||||
'description' => __( 'Default value for the setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'tip' => array(
|
||||
'tip' => array(
|
||||
'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /shipping/zones endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Shipping Zones class.
|
||||
|
@ -26,65 +22,71 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle
|
|||
* Register the routes for Shipping Zones.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
|
||||
'name' => array(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'description' => __( 'Shipping zone name.', 'woocommerce' ),
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => array_merge(
|
||||
$this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
|
||||
'name' => array(
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'description' => __( 'Shipping zone name.', 'woocommerce' ),
|
||||
),
|
||||
)
|
||||
),
|
||||
) ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d-]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique ID for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_items_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'default' => false,
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<id>[\d-]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique ID for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_items_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_items_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'default' => false,
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single Shipping Zone.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
|
@ -104,7 +106,7 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle
|
|||
/**
|
||||
* Get all Shipping Zones.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
|
@ -112,7 +114,7 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle
|
|||
|
||||
$zones = WC_Shipping_Zones::get_zones();
|
||||
array_unshift( $zones, $rest_of_the_world->get_data() );
|
||||
$data = array();
|
||||
$data = array();
|
||||
|
||||
foreach ( $zones as $zone_obj ) {
|
||||
$zone = $this->prepare_item_for_response( $zone_obj, $request );
|
||||
|
@ -167,7 +169,7 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle
|
|||
}
|
||||
|
||||
if ( 0 === $zone->get_id() ) {
|
||||
return new WP_Error( "woocommerce_rest_shipping_zone_invalid_zone", __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) );
|
||||
return new WP_Error( 'woocommerce_rest_shipping_zone_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) );
|
||||
}
|
||||
|
||||
$zone_changed = false;
|
||||
|
@ -218,7 +220,7 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle
|
|||
/**
|
||||
* Prepare the Shipping Zone for the REST response.
|
||||
*
|
||||
* @param array $item Shipping Zone.
|
||||
* @param array $item Shipping Zone.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response
|
||||
*/
|
||||
|
@ -250,10 +252,10 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle
|
|||
protected function prepare_links( $zone_id ) {
|
||||
$base = '/' . $this->namespace . '/' . $this->rest_base;
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'self' => array(
|
||||
'href' => rest_url( trailingslashit( $base ) . $zone_id ),
|
||||
),
|
||||
'collection' => array(
|
||||
'collection' => array(
|
||||
'href' => rest_url( $base ),
|
||||
),
|
||||
'describedby' => array(
|
||||
|
@ -275,13 +277,13 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle
|
|||
'title' => 'shipping_zone',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'name' => array(
|
||||
'description' => __( 'Shipping zone name.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
|
|
@ -4,17 +4,15 @@
|
|||
*
|
||||
* Handles requests to the /system_status endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* System status controller class.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Controller
|
||||
*/
|
||||
|
@ -569,13 +567,13 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
$curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
|
||||
}
|
||||
|
||||
// WP memory limit
|
||||
// WP memory limit.
|
||||
$wp_memory_limit = wc_let_to_num( WP_MEMORY_LIMIT );
|
||||
if ( function_exists( 'memory_get_usage' ) ) {
|
||||
$wp_memory_limit = max( $wp_memory_limit, wc_let_to_num( @ini_get( 'memory_limit' ) ) );
|
||||
}
|
||||
|
||||
// Test POST requests
|
||||
// Test POST requests.
|
||||
$post_response = wp_safe_remote_post(
|
||||
'https://www.paypal.com/cgi-bin/webscr',
|
||||
array(
|
||||
|
@ -592,7 +590,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
$post_response_successful = true;
|
||||
}
|
||||
|
||||
// Test GET requests
|
||||
// Test GET requests.
|
||||
$get_response = wp_safe_remote_get( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite() ? '1' : '0' ) );
|
||||
$get_response_successful = false;
|
||||
if ( ! is_wp_error( $post_response ) && $post_response['response']['code'] >= 200 && $post_response['response']['code'] < 300 ) {
|
||||
|
@ -613,7 +611,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
|
||||
'language' => get_locale(),
|
||||
'external_object_cache' => wp_using_ext_object_cache(),
|
||||
'server_info' => $_SERVER['SERVER_SOFTWARE'],
|
||||
'server_info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? wc_clean( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '',
|
||||
'php_version' => phpversion(),
|
||||
'php_post_max_size' => wc_let_to_num( ini_get( 'post_max_size' ) ),
|
||||
'php_max_execution_time' => ini_get( 'max_execution_time' ),
|
||||
|
@ -638,7 +636,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Add prefix to table.
|
||||
*
|
||||
* @param string $table table name
|
||||
* @param string $table Table name.
|
||||
* @return stromg
|
||||
*/
|
||||
protected function add_db_table_prefix( $table ) {
|
||||
|
@ -667,7 +665,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
)
|
||||
);
|
||||
|
||||
// WC Core tables to check existence of
|
||||
// WC Core tables to check existence of.
|
||||
$core_tables = apply_filters(
|
||||
'woocommerce_database_tables',
|
||||
array(
|
||||
|
@ -762,7 +760,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
return array();
|
||||
}
|
||||
|
||||
// Get both site plugins and network plugins
|
||||
// Get both site plugins and network plugins.
|
||||
$active_plugins = (array) get_option( 'active_plugins', array() );
|
||||
if ( is_multisite() ) {
|
||||
$network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
|
||||
|
@ -781,7 +779,8 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
$slug = $slug[0];
|
||||
|
||||
if ( 'woocommerce' !== $slug && ( strstr( $data['PluginURI'], 'woothemes.com' ) || strstr( $data['PluginURI'], 'woocommerce.com' ) ) ) {
|
||||
if ( false === ( $version_data = get_transient( md5( $plugin ) . '_version_data' ) ) ) {
|
||||
$version_data = get_transient( md5( $plugin ) . '_version_data' );
|
||||
if ( false === $version_data ) {
|
||||
$changelog = wp_safe_remote_get( 'http://dzv365zjfbd8v.cloudfront.net/changelogs/' . $dirname . '/changelog.txt' );
|
||||
$cl_lines = explode( "\n", wp_remote_retrieve_body( $changelog ) );
|
||||
if ( ! empty( $cl_lines ) ) {
|
||||
|
@ -835,10 +834,10 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
// Get parent theme info if this theme is a child theme, otherwise
|
||||
// pass empty info in the response.
|
||||
if ( is_child_theme() ) {
|
||||
$parent_theme = wp_get_theme( $active_theme->Template );
|
||||
$parent_theme = wp_get_theme( $active_theme->template );
|
||||
$parent_theme_info = array(
|
||||
'parent_name' => $parent_theme->Name,
|
||||
'parent_version' => $parent_theme->Version,
|
||||
'parent_name' => $parent_theme->name,
|
||||
'parent_version' => $parent_theme->version,
|
||||
'parent_version_latest' => WC_Admin_Status::get_latest_theme_version( $parent_theme ),
|
||||
'parent_author_url' => $parent_theme->{'Author URI'},
|
||||
);
|
||||
|
@ -892,8 +891,8 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
}
|
||||
|
||||
$active_theme_info = array(
|
||||
'name' => $active_theme->Name,
|
||||
'version' => $active_theme->Version,
|
||||
'name' => $active_theme->name,
|
||||
'version' => $active_theme->version,
|
||||
'version_latest' => WC_Admin_Status::get_latest_theme_version( $active_theme ),
|
||||
'author_url' => esc_url_raw( $active_theme->{'Author URI'} ),
|
||||
'is_child_theme' => is_child_theme(),
|
||||
|
@ -913,7 +912,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
// Get a list of terms used for product/order taxonomies
|
||||
// Get a list of terms used for product/order taxonomies.
|
||||
$term_response = array();
|
||||
$terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
|
||||
foreach ( $terms as $term ) {
|
||||
|
@ -963,7 +962,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
* @return array
|
||||
*/
|
||||
public function get_pages() {
|
||||
// WC pages to check against
|
||||
// WC pages to check against.
|
||||
$check_pages = array(
|
||||
_x( 'Shop base', 'Page setting', 'woocommerce' ) => array(
|
||||
'option' => 'woocommerce_shop_page_id',
|
||||
|
@ -989,11 +988,14 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
|
||||
$pages_output = array();
|
||||
foreach ( $check_pages as $page_name => $values ) {
|
||||
$page_id = get_option( $values['option'] );
|
||||
$page_set = $page_exists = $page_visible = false;
|
||||
$shortcode_present = $shortcode_required = false;
|
||||
$page_id = get_option( $values['option'] );
|
||||
$page_set = false;
|
||||
$page_exists = false;
|
||||
$page_visible = false;
|
||||
$shortcode_present = false;
|
||||
$shortcode_required = false;
|
||||
|
||||
// Page checks
|
||||
// Page checks.
|
||||
if ( $page_id ) {
|
||||
$page_set = true;
|
||||
}
|
||||
|
@ -1004,7 +1006,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
$page_visible = true;
|
||||
}
|
||||
|
||||
// Shortcode checks
|
||||
// Shortcode checks.
|
||||
if ( $values['shortcode'] && get_post( $page_id ) ) {
|
||||
$shortcode_required = true;
|
||||
$page = get_post( $page_id );
|
||||
|
@ -1013,7 +1015,7 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
// Wrap up our findings into an output array
|
||||
// Wrap up our findings into an output array.
|
||||
$pages_output[] = array(
|
||||
'page_name' => $page_name,
|
||||
'page_id' => $page_id,
|
||||
|
@ -1043,9 +1045,9 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Prepare the system status response
|
||||
*
|
||||
* @param array $system_status
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response $response Response data.
|
||||
* @param array $system_status System status data.
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function prepare_item_for_response( $system_status, $request ) {
|
||||
$data = $this->add_additional_fields_to_object( $system_status, $request );
|
||||
|
|
|
@ -4,13 +4,15 @@
|
|||
*
|
||||
* Handles requests to the /system_status/tools/* endpoints.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
* @package WooCommerce/API
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* System status tools controller.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @extends WC_REST_Controller
|
||||
*/
|
||||
|
@ -34,36 +36,40 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
* Register the routes for /system_status/tools/*.
|
||||
*/
|
||||
public function register_routes() {
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base, array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
$this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,7 +185,7 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
'name' => __( 'Regenerate shop thumbnails', 'woocommerce' ),
|
||||
'button' => __( 'Regenerate', 'woocommerce' ),
|
||||
'desc' => __( 'This will regenerate all shop thumbnails to match your theme and/or image settings.', 'woocommerce' ),
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
// Jetpack does the image resizing heavy lifting so you don't have to.
|
||||
|
@ -199,12 +205,16 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
public function get_items( $request ) {
|
||||
$tools = array();
|
||||
foreach ( $this->get_tools() as $id => $tool ) {
|
||||
$tools[] = $this->prepare_response_for_collection( $this->prepare_item_for_response( array(
|
||||
'id' => $id,
|
||||
'name' => $tool['name'],
|
||||
'action' => $tool['button'],
|
||||
'description' => $tool['desc'],
|
||||
), $request ) );
|
||||
$tools[] = $this->prepare_response_for_collection(
|
||||
$this->prepare_item_for_response(
|
||||
array(
|
||||
'id' => $id,
|
||||
'name' => $tool['name'],
|
||||
'action' => $tool['button'],
|
||||
'description' => $tool['desc'],
|
||||
), $request
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$response = rest_ensure_response( $tools );
|
||||
|
@ -214,7 +224,7 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Return a single tool.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
|
@ -223,18 +233,22 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
return new WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
}
|
||||
$tool = $tools[ $request['id'] ];
|
||||
return rest_ensure_response( $this->prepare_item_for_response( array(
|
||||
'id' => $request['id'],
|
||||
'name' => $tool['name'],
|
||||
'action' => $tool['button'],
|
||||
'description' => $tool['desc'],
|
||||
), $request ) );
|
||||
return rest_ensure_response(
|
||||
$this->prepare_item_for_response(
|
||||
array(
|
||||
'id' => $request['id'],
|
||||
'name' => $tool['name'],
|
||||
'action' => $tool['button'],
|
||||
'description' => $tool['desc'],
|
||||
), $request
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update (execute) a tool.
|
||||
*
|
||||
* @param WP_REST_Request $request
|
||||
* @param WP_REST_Request $request Request data.
|
||||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
|
@ -351,7 +365,7 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* Prepare links for the request.
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $id ID.
|
||||
* @return array
|
||||
*/
|
||||
protected function prepare_links( $id ) {
|
||||
|
@ -378,9 +392,9 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* Actually executes a a tool.
|
||||
* Actually executes a tool.
|
||||
*
|
||||
* @param string $tool
|
||||
* @param string $tool Tool.
|
||||
* @return array
|
||||
*/
|
||||
public function execute_tool( $tool ) {
|
||||
|
@ -395,22 +409,26 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
break;
|
||||
|
||||
case 'clear_expired_transients':
|
||||
/* translators: %d: amount of expired transients */
|
||||
$message = sprintf( __( '%d transients rows cleared', 'woocommerce' ), wc_delete_expired_transients() );
|
||||
break;
|
||||
|
||||
case 'delete_orphaned_variations':
|
||||
/**
|
||||
* Delete orphans
|
||||
*/
|
||||
$result = absint( $wpdb->query( "DELETE products
|
||||
// Delete orphans.
|
||||
$result = absint(
|
||||
$wpdb->query(
|
||||
"DELETE products
|
||||
FROM {$wpdb->posts} products
|
||||
LEFT JOIN {$wpdb->posts} wp ON wp.ID = products.post_parent
|
||||
WHERE wp.ID IS NULL AND products.post_type = 'product_variation';" ) );
|
||||
WHERE wp.ID IS NULL AND products.post_type = 'product_variation';"
|
||||
)
|
||||
);
|
||||
/* translators: %d: amount of orphaned variations */
|
||||
$message = sprintf( __( '%d orphaned variations deleted', 'woocommerce' ), $result );
|
||||
break;
|
||||
|
||||
case 'add_order_indexes':
|
||||
/**
|
||||
/*
|
||||
* Add billing and shipping address indexes containing the customer name for orders
|
||||
* that don't have address indexes yet.
|
||||
*/
|
||||
|
@ -422,37 +440,43 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
WHERE post_id NOT IN ( SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='%s' )
|
||||
AND post_id IN ( SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='%s' ) )
|
||||
GROUP BY post_id";
|
||||
$rows = $wpdb->query( $wpdb->prepare( $sql, '_billing_address_index', '_billing_first_name', '_billing_last_name', '_billing_address_index', '_billing_last_name' ) );
|
||||
$rows += $wpdb->query( $wpdb->prepare( $sql, '_shipping_address_index', '_shipping_first_name', '_shipping_last_name', '_shipping_address_index', '_shipping_last_name' ) );
|
||||
$rows = $wpdb->query( $wpdb->prepare( $sql, '_billing_address_index', '_billing_first_name', '_billing_last_name', '_billing_address_index', '_billing_last_name' ) ); // WPCS: unprepared SQL ok.
|
||||
$rows += $wpdb->query( $wpdb->prepare( $sql, '_shipping_address_index', '_shipping_first_name', '_shipping_last_name', '_shipping_address_index', '_shipping_last_name' ) ); // WPCS: unprepared SQL ok.
|
||||
|
||||
/* translators: %d: amount of indexes */
|
||||
$message = sprintf( __( '%d indexes added', 'woocommerce' ), $rows );
|
||||
break;
|
||||
|
||||
case 'reset_roles':
|
||||
// Remove then re-add caps and roles
|
||||
// Remove then re-add caps and roles.
|
||||
WC_Install::remove_roles();
|
||||
WC_Install::create_roles();
|
||||
$message = __( 'Roles successfully reset', 'woocommerce' );
|
||||
break;
|
||||
|
||||
case 'recount_terms':
|
||||
$product_cats = get_terms( 'product_cat', array(
|
||||
'hide_empty' => false,
|
||||
'fields' => 'id=>parent',
|
||||
) );
|
||||
$product_cats = get_terms(
|
||||
'product_cat', array(
|
||||
'hide_empty' => false,
|
||||
'fields' => 'id=>parent',
|
||||
)
|
||||
);
|
||||
_wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), true, false );
|
||||
$product_tags = get_terms( 'product_tag', array(
|
||||
'hide_empty' => false,
|
||||
'fields' => 'id=>parent',
|
||||
) );
|
||||
$product_tags = get_terms(
|
||||
'product_tag', array(
|
||||
'hide_empty' => false,
|
||||
'fields' => 'id=>parent',
|
||||
)
|
||||
);
|
||||
_wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), true, false );
|
||||
$message = __( 'Terms successfully recounted', 'woocommerce' );
|
||||
break;
|
||||
|
||||
case 'clear_sessions':
|
||||
$wpdb->query( "TRUNCATE {$wpdb->prefix}woocommerce_sessions" );
|
||||
$result = absint( $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';" ) );
|
||||
$result = absint( $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';" ) ); // WPCS: unprepared SQL ok.
|
||||
wp_cache_flush();
|
||||
/* translators: %d: amount of sessions */
|
||||
$message = sprintf( __( 'Deleted all active sessions, and %d saved carts.', 'woocommerce' ), absint( $result ) );
|
||||
break;
|
||||
|
||||
|
@ -489,7 +513,8 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
} elseif ( false === $return ) {
|
||||
$callback_string = is_array( $callback ) ? get_class( $callback[0] ) . '::' . $callback[1] : $callback;
|
||||
$ran = false;
|
||||
$message = sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string );
|
||||
/* translators: %s: callback string */
|
||||
$message = sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string );
|
||||
} else {
|
||||
$message = __( 'Tool ran.', 'woocommerce' );
|
||||
}
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /taxes/classes endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Tax Classes controller class.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /taxes endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Taxes controller class.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /webhooks/<webhook_id>/deliveries endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Webhook Deliveries controller class.
|
||||
|
@ -70,47 +66,47 @@ class WC_REST_Webhook_Deliveries_Controller extends WC_REST_Webhook_Deliveries_V
|
|||
'title' => 'webhook_delivery',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'duration' => array(
|
||||
'duration' => array(
|
||||
'description' => __( 'The delivery duration, in seconds.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'summary' => array(
|
||||
'summary' => array(
|
||||
'description' => __( 'A friendly summary of the response including the HTTP response code, message, and body.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'request_url' => array(
|
||||
'request_url' => array(
|
||||
'description' => __( 'The URL where the webhook was delivered.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'request_headers' => array(
|
||||
'request_headers' => array(
|
||||
'description' => __( 'Request headers.', 'woocommerce' ),
|
||||
'type' => 'array',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
'request_body' => array(
|
||||
'request_body' => array(
|
||||
'description' => __( 'Request body.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'response_code' => array(
|
||||
'response_code' => array(
|
||||
'description' => __( 'The HTTP response code from the receiving server.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
|
@ -128,16 +124,16 @@ class WC_REST_Webhook_Deliveries_Controller extends WC_REST_Webhook_Deliveries_V
|
|||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
'response_body' => array(
|
||||
'response_body' => array(
|
||||
'description' => __( 'The response body from the receiving server.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_created' => array(
|
||||
'date_created' => array(
|
||||
'description' => __( "The date the webhook delivery was logged, in the site's timezone.", 'woocommerce' ),
|
||||
'type' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
|
|
@ -4,13 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /webhooks endpoint.
|
||||
*
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Webhooks controller class.
|
||||
|
@ -41,7 +39,7 @@ class WC_REST_Webhooks_Controller extends WC_REST_Webhooks_V1_Controller {
|
|||
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
$data = array(
|
||||
$data = array(
|
||||
'id' => $webhook->get_id(),
|
||||
'name' => $webhook->get_name(),
|
||||
'status' => $webhook->get_status(),
|
||||
|
|
Loading…
Reference in New Issue