Fixed PHPCS violations on REST API
This commit is contained in:
parent
e8017e985b
commit
f0d37ff4f5
|
@ -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,7 +234,7 @@ 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();
|
||||
|
||||
|
@ -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 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 ) {
|
||||
|
@ -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,7 +493,7 @@ 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 ) {
|
||||
|
|
|
@ -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.
|
||||
|
@ -250,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 ) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
@ -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 );
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
*
|
||||
* Handles requests to the /orders endpoint.
|
||||
*
|
||||
* @author WooThemes
|
||||
* @category API
|
||||
* @package WooCommerce/API
|
||||
* @since 2.6.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* REST API Orders controller class.
|
||||
|
@ -144,7 +140,7 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
/**
|
||||
* Expands an order item to get its data.
|
||||
*
|
||||
* @param WC_Order_item $item
|
||||
* @param WC_Order_item $item Order item data.
|
||||
* @return array
|
||||
*/
|
||||
protected function get_order_item_data( $item ) {
|
||||
|
@ -364,7 +360,7 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
|
||||
if ( isset( $request['customer'] ) ) {
|
||||
if ( ! empty( $args['meta_query'] ) ) {
|
||||
$args['meta_query'] = array();
|
||||
$args['meta_query'] = array(); // WPCS: slow query ok.
|
||||
}
|
||||
|
||||
$args['meta_query'][] = array(
|
||||
|
@ -419,7 +415,7 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
/**
|
||||
* Only return writable props from schema.
|
||||
*
|
||||
* @param array $schema
|
||||
* @param array $schema Schema.
|
||||
* @return bool
|
||||
*/
|
||||
protected function filter_writable_props( $schema ) {
|
||||
|
@ -501,6 +497,7 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
* Save an object data.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @throws WC_REST_Exception But all errors are validated before returning any data.
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @param bool $creating If is creating a new object.
|
||||
* @return WC_Data|WP_Error
|
||||
|
@ -561,9 +558,9 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
/**
|
||||
* Update address.
|
||||
*
|
||||
* @param WC_Order $order
|
||||
* @param array $posted
|
||||
* @param string $type
|
||||
* @param WC_Order $order Order data.
|
||||
* @param array $posted Posted data.
|
||||
* @param string $type Address type.
|
||||
*/
|
||||
protected function update_address( $order, $posted, $type = 'billing' ) {
|
||||
foreach ( $posted as $key => $value ) {
|
||||
|
@ -576,10 +573,9 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
/**
|
||||
* Gets the product ID from the SKU or posted ID.
|
||||
*
|
||||
* @param array $posted Request data
|
||||
*
|
||||
* @throws WC_REST_Exception When SKU or ID is not valid.
|
||||
* @param array $posted Request data.
|
||||
* @return int
|
||||
* @throws WC_REST_Exception
|
||||
*/
|
||||
protected function get_product_id( $posted ) {
|
||||
if ( ! empty( $posted['sku'] ) ) {
|
||||
|
@ -597,8 +593,8 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
/**
|
||||
* Maybe set an item prop if the value was posted.
|
||||
*
|
||||
* @param WC_Order_Item $item
|
||||
* @param string $prop
|
||||
* @param WC_Order_Item $item Order item.
|
||||
* @param string $prop Order property.
|
||||
* @param array $posted Request data.
|
||||
*/
|
||||
protected function maybe_set_item_prop( $item, $prop, $posted ) {
|
||||
|
@ -610,8 +606,8 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
/**
|
||||
* Maybe set item props if the values were posted.
|
||||
*
|
||||
* @param WC_Order_Item $item
|
||||
* @param string[] $props
|
||||
* @param WC_Order_Item $item Order item data.
|
||||
* @param string[] $props Properties.
|
||||
* @param array $posted Request data.
|
||||
*/
|
||||
protected function maybe_set_item_props( $item, $props, $posted ) {
|
||||
|
@ -623,7 +619,7 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
|||
/**
|
||||
* Maybe set item meta if posted.
|
||||
*
|
||||
* @param WC_Order_Item $item
|
||||
* @param WC_Order_Item $item Order item data.
|
||||
* @param array $posted Request data.
|
||||
*/
|
||||
protected function maybe_set_item_meta_data( $item, $posted ) {
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -136,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 ) {
|
||||
|
@ -153,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 ) {
|
||||
|
@ -192,24 +190,27 @@ 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[ $gateway->id ] = $request['order'];
|
||||
|
@ -224,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 ) {
|
||||
|
@ -280,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
|
||||
*/
|
||||
|
@ -288,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(
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
@ -107,7 +105,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
* 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 ) {
|
||||
|
@ -126,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 ) {
|
||||
|
@ -172,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;
|
||||
|
@ -210,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;
|
||||
}
|
||||
|
@ -287,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 ) {
|
||||
|
@ -400,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 ) {
|
||||
|
@ -426,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 ) {
|
||||
|
@ -444,7 +443,7 @@ 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 ) {
|
||||
|
@ -468,7 +467,7 @@ class WC_REST_Setting_Options_Controller extends WC_REST_Controller {
|
|||
* 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 ) {
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
@ -56,7 +54,7 @@ class WC_REST_Settings_Controller extends WC_REST_Controller {
|
|||
* 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 ) {
|
||||
|
@ -132,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 ) {
|
||||
|
@ -146,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 ) {
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -116,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 ) {
|
||||
|
|
|
@ -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.
|
||||
|
@ -53,7 +49,7 @@ class WC_REST_Shipping_Zone_Locations_Controller extends WC_REST_Shipping_Zones_
|
|||
/**
|
||||
* 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 ) {
|
||||
|
@ -78,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 ) {
|
||||
|
|
|
@ -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.
|
||||
|
@ -100,7 +96,7 @@ class WC_REST_Shipping_Zone_Methods_Controller extends WC_REST_Shipping_Zones_Co
|
|||
/**
|
||||
* 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 ) {
|
||||
|
@ -133,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 ) {
|
||||
|
@ -193,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 ) {
|
||||
|
@ -227,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 {
|
||||
|
@ -249,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 ) {
|
||||
|
@ -285,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;
|
||||
|
@ -321,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'] );
|
||||
|
@ -375,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
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
|
@ -90,7 +86,7 @@ class WC_REST_Shipping_Zones_Controller extends WC_REST_Shipping_Zones_Controlle
|
|||
/**
|
||||
* 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 ) {
|
||||
|
@ -110,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 ) {
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -222,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 ) {
|
||||
|
@ -246,7 +248,7 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
/**
|
||||
* 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 ) {
|
||||
|
@ -363,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 ) {
|
||||
|
@ -390,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 ) {
|
||||
|
@ -407,14 +409,13 @@ 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(
|
||||
// Delete orphans.
|
||||
$result = absint(
|
||||
$wpdb->query(
|
||||
"DELETE products
|
||||
FROM {$wpdb->posts} products
|
||||
|
@ -422,11 +423,12 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
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.
|
||||
*/
|
||||
|
@ -438,14 +440,15 @@ 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' );
|
||||
|
@ -471,8 +474,9 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
|||
|
||||
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;
|
||||
|
||||
|
@ -509,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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue