Align variables
This commit is contained in:
parent
8df7723895
commit
bf64942b28
|
@ -231,7 +231,7 @@ abstract class WC_REST_Posts_Controller extends WP_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$id = (int) $request['id'];
|
||||
$id = (int) $request['id'];
|
||||
$post = get_post( $id );
|
||||
|
||||
if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
|
||||
|
@ -391,10 +391,9 @@ abstract class WC_REST_Posts_Controller extends WP_REST_Controller {
|
|||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function delete_item( $request ) {
|
||||
$id = (int) $request['id'];
|
||||
$id = (int) $request['id'];
|
||||
$force = (bool) $request['force'];
|
||||
|
||||
$post = get_post( $id );
|
||||
$post = get_post( $id );
|
||||
|
||||
if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
|
||||
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid post id.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
|
@ -473,7 +472,6 @@ abstract class WC_REST_Posts_Controller extends WP_REST_Controller {
|
|||
return $links;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the allowed query_vars for a get_items() response and
|
||||
* prepare for WP_Query.
|
||||
|
|
|
@ -187,8 +187,7 @@ abstract class WC_REST_Terms_Controller extends WP_REST_Controller {
|
|||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$taxonomy = $this->get_taxonomy( $request );
|
||||
|
||||
$taxonomy = $this->get_taxonomy( $request );
|
||||
$prepared_args = array(
|
||||
'exclude' => $request['exclude'],
|
||||
'include' => $request['include'],
|
||||
|
@ -300,8 +299,8 @@ abstract class WC_REST_Terms_Controller extends WP_REST_Controller {
|
|||
$taxonomy = $this->get_taxonomy( $request );
|
||||
$name = $request['name'];
|
||||
$args = array();
|
||||
$schema = $this->get_item_schema();
|
||||
|
||||
$schema = $this->get_item_schema();
|
||||
if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) {
|
||||
$args['description'] = $request['description'];
|
||||
}
|
||||
|
|
|
@ -187,8 +187,7 @@ class WC_REST_Authentication {
|
|||
* @return null|WP_Error
|
||||
*/
|
||||
private function check_oauth_signature( $user, $params ) {
|
||||
$http_method = strtoupper( $_SERVER['REQUEST_METHOD'] );
|
||||
|
||||
$http_method = strtoupper( $_SERVER['REQUEST_METHOD'] );
|
||||
$request_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
|
||||
$wp_base = get_home_url( null, '/', 'relative' );
|
||||
if ( substr( $request_path, 0, strlen( $wp_base ) ) === $wp_base ) {
|
||||
|
@ -206,7 +205,7 @@ class WC_REST_Authentication {
|
|||
}
|
||||
|
||||
// Normalize parameter key/values.
|
||||
$params = $this->normalize_parameters( $params );
|
||||
$params = $this->normalize_parameters( $params );
|
||||
$query_parameters = array();
|
||||
foreach ( $params as $param_key => $param_value ) {
|
||||
if ( is_array( $param_value ) ) {
|
||||
|
@ -217,8 +216,7 @@ class WC_REST_Authentication {
|
|||
$query_parameters[] = $param_key . '%3D' . $param_value; // Join with equals sign.
|
||||
}
|
||||
}
|
||||
$query_string = implode( '%26', $query_parameters ); // Join with ampersand.
|
||||
|
||||
$query_string = implode( '%26', $query_parameters ); // Join with ampersand.
|
||||
$string_to_sign = $http_method . '&' . $base_request_uri . '&' . $query_string;
|
||||
|
||||
if ( $params['oauth_signature_method'] !== 'HMAC-SHA1' && $params['oauth_signature_method'] !== 'HMAC-SHA256' ) {
|
||||
|
@ -226,9 +224,8 @@ class WC_REST_Authentication {
|
|||
}
|
||||
|
||||
$hash_algorithm = strtolower( str_replace( 'HMAC-', '', $params['oauth_signature_method'] ) );
|
||||
|
||||
$secret = $user->consumer_secret . '&';
|
||||
$signature = base64_encode( hash_hmac( $hash_algorithm, $string_to_sign, $secret, true ) );
|
||||
$secret = $user->consumer_secret . '&';
|
||||
$signature = base64_encode( hash_hmac( $hash_algorithm, $string_to_sign, $secret, true ) );
|
||||
|
||||
if ( ! hash_equals( $signature, $consumer_signature ) ) {
|
||||
return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Invalid Signature - provided signature does not match.', 'woocommerce' ), array( 'status' => 401 ) );
|
||||
|
@ -257,8 +254,8 @@ class WC_REST_Authentication {
|
|||
* @return array Normalized parameters.
|
||||
*/
|
||||
private function normalize_parameters( $parameters ) {
|
||||
$keys = wc_rest_urlencode_rfc3986( array_keys( $parameters ) );
|
||||
$values = wc_rest_urlencode_rfc3986( array_values( $parameters ) );
|
||||
$keys = wc_rest_urlencode_rfc3986( array_keys( $parameters ) );
|
||||
$values = wc_rest_urlencode_rfc3986( array_values( $parameters ) );
|
||||
$parameters = array_combine( $keys, $values );
|
||||
|
||||
return $parameters;
|
||||
|
|
|
@ -99,7 +99,7 @@ class WC_REST_Customer_Downloads_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function prepare_item_for_response( $download, $request ) {
|
||||
$data = (array) $download;
|
||||
$data['access_expires'] = $data['access_expires'] ? wc_rest_prepare_date_response( $data['access_expires'] ) : 'never';
|
||||
$data['access_expires'] = $data['access_expires'] ? wc_rest_prepare_date_response( $data['access_expires'] ) : 'never';
|
||||
$data['downloads_remaining'] = '' === $data['downloads_remaining'] ? 'unlimited' : $data['downloads_remaining'];
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
|
@ -129,8 +129,7 @@ class WC_REST_Customer_Downloads_Controller extends WP_REST_Controller {
|
|||
* @return array Links for the given customer download.
|
||||
*/
|
||||
protected function prepare_links( $download, $request ) {
|
||||
$base = str_replace( '(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base );
|
||||
|
||||
$base = str_replace( '(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base );
|
||||
$links = array(
|
||||
'collection' => array(
|
||||
'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
|
||||
|
|
|
@ -214,7 +214,7 @@ class WC_REST_Customers_Controller extends WP_REST_Controller {
|
|||
|
||||
// Filter by email.
|
||||
if ( ! empty( $request['email'] ) ) {
|
||||
$prepared_args['search'] = $request['email'];
|
||||
$prepared_args['search'] = $request['email'];
|
||||
$prepared_args['search_columns'] = array( 'user_email' );
|
||||
}
|
||||
|
||||
|
@ -354,9 +354,9 @@ class WC_REST_Customers_Controller extends WP_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response
|
||||
*/
|
||||
public function update_item( $request ) {
|
||||
$id = (int) $request['id'];
|
||||
|
||||
$id = (int) $request['id'];
|
||||
$customer = get_userdata( $id );
|
||||
|
||||
if ( ! $customer ) {
|
||||
return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
|
|
@ -344,8 +344,7 @@ class WC_REST_Order_Notes_Controller extends WP_REST_Controller {
|
|||
protected function prepare_links( $note ) {
|
||||
$order_id = (int) $note->comment_post_ID;
|
||||
$base = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base );
|
||||
|
||||
$links = array(
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $note->comment_ID ) ),
|
||||
),
|
||||
|
|
|
@ -196,14 +196,6 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Posts_Controller {
|
|||
$line_item['taxes'] = array_values( $line_tax );
|
||||
}
|
||||
|
||||
// if ( in_array( 'products', $expand ) ) {
|
||||
// $_product_data = WC()->api->WC_API_Products->get_product( $product_id );
|
||||
|
||||
// if ( isset( $_product_data['product'] ) ) {
|
||||
// $line_item['product_data'] = $_product_data['product'];
|
||||
// }
|
||||
// }
|
||||
|
||||
$data['line_items'][] = $line_item;
|
||||
}
|
||||
|
||||
|
@ -237,9 +229,8 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Posts_Controller {
|
|||
*/
|
||||
protected function prepare_links( $refund ) {
|
||||
$order_id = $refund->post->post_parent;
|
||||
$base = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base );
|
||||
|
||||
$links = array(
|
||||
$base = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base );
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $refund->id ) ),
|
||||
),
|
||||
|
|
|
@ -187,8 +187,7 @@ class WC_REST_Product_Attributes_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function get_items( $request ) {
|
||||
$attributes = wc_get_attribute_taxonomies();
|
||||
|
||||
$data = array();
|
||||
$data = array();
|
||||
foreach ( $attributes as $attribute_obj ) {
|
||||
$attribute = $this->prepare_item_for_response( $attribute_obj, $request );
|
||||
$attribute = $this->prepare_response_for_collection( $attribute );
|
||||
|
@ -475,8 +474,7 @@ class WC_REST_Product_Attributes_Controller extends WP_REST_Controller {
|
|||
* @return array Links for the given attribute.
|
||||
*/
|
||||
protected function prepare_links( $attribute ) {
|
||||
$base = '/' . $this->namespace . '/' . $this->rest_base;
|
||||
|
||||
$base = '/' . $this->namespace . '/' . $this->rest_base;
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'href' => rest_url( trailingslashit( $base ) . $attribute->attribute_id ),
|
||||
|
|
|
@ -107,8 +107,7 @@ class WC_REST_Product_Reviews_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
$reviews = get_approved_comments( $product->ID );
|
||||
|
||||
$data = array();
|
||||
$data = array();
|
||||
foreach ( $reviews as $review_data ) {
|
||||
$review = $this->prepare_item_for_response( $review_data, $request );
|
||||
$review = $this->prepare_response_for_collection( $review );
|
||||
|
@ -191,8 +190,7 @@ class WC_REST_Product_Reviews_Controller extends WP_REST_Controller {
|
|||
protected function prepare_links( $review, $request ) {
|
||||
$product_id = (int) $request['product_id'];
|
||||
$base = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base );
|
||||
|
||||
$links = array(
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $review->comment_ID ) ),
|
||||
),
|
||||
|
|
|
@ -503,8 +503,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
|
|||
*/
|
||||
public function prepare_item_for_response( $post, $request ) {
|
||||
$product = wc_get_product( $post );
|
||||
|
||||
$data = $this->get_product_data( $product );
|
||||
$data = $this->get_product_data( $product );
|
||||
|
||||
// Add variations to variable products.
|
||||
if ( $product->is_type( 'variable' ) && $product->has_child() ) {
|
||||
|
|
|
@ -188,8 +188,7 @@ class WC_REST_Webhook_Deliveries_Controller extends WP_REST_Controller {
|
|||
protected function prepare_links( $log ) {
|
||||
$webhook_id = (int) $log->request_headers['X-WC-Webhook-ID'];
|
||||
$base = str_replace( '(?P<webhook_id>[\d]+)', $webhook_id, $this->rest_base );
|
||||
|
||||
$links = array(
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $log->id ) ),
|
||||
),
|
||||
|
|
|
@ -387,8 +387,7 @@ class WC_REST_Webhooks_Controller extends WC_REST_Posts_Controller {
|
|||
public function prepare_item_for_response( $post, $request ) {
|
||||
$id = (int) $post->ID;
|
||||
$webhook = new WC_Webhook( $id );
|
||||
|
||||
$data = array(
|
||||
$data = array(
|
||||
'id' => $webhook->id,
|
||||
'name' => $webhook->get_name(),
|
||||
'status' => $webhook->get_status(),
|
||||
|
|
Loading…
Reference in New Issue