@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 2.6.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -47,69 +47,69 @@ discard block |
||
47 | 47 | * Order refunds actions. |
48 | 48 | */ |
49 | 49 | public function __construct() { |
50 | - add_filter( "woocommerce_rest_{$this->post_type}_trashable", '__return_false' ); |
|
51 | - add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'query_args' ), 10, 2 ); |
|
50 | + add_filter("woocommerce_rest_{$this->post_type}_trashable", '__return_false'); |
|
51 | + add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'query_args'), 10, 2); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Register the routes for order refunds. |
56 | 56 | */ |
57 | 57 | public function register_routes() { |
58 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
58 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
59 | 59 | 'args' => array( |
60 | 60 | 'order_id' => array( |
61 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
61 | + 'description' => __('The order ID.', 'woocommerce'), |
|
62 | 62 | 'type' => 'integer', |
63 | 63 | ), |
64 | 64 | ), |
65 | 65 | array( |
66 | 66 | 'methods' => WP_REST_Server::READABLE, |
67 | - 'callback' => array( $this, 'get_items' ), |
|
68 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
67 | + 'callback' => array($this, 'get_items'), |
|
68 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
69 | 69 | 'args' => $this->get_collection_params(), |
70 | 70 | ), |
71 | 71 | array( |
72 | 72 | 'methods' => WP_REST_Server::CREATABLE, |
73 | - 'callback' => array( $this, 'create_item' ), |
|
74 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
75 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
73 | + 'callback' => array($this, 'create_item'), |
|
74 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
75 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
76 | 76 | ), |
77 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
78 | - ) ); |
|
77 | + 'schema' => array($this, 'get_public_item_schema'), |
|
78 | + )); |
|
79 | 79 | |
80 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
80 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
81 | 81 | 'args' => array( |
82 | 82 | 'order_id' => array( |
83 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
83 | + 'description' => __('The order ID.', 'woocommerce'), |
|
84 | 84 | 'type' => 'integer', |
85 | 85 | ), |
86 | 86 | 'id' => array( |
87 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
87 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
88 | 88 | 'type' => 'integer', |
89 | 89 | ), |
90 | 90 | ), |
91 | 91 | array( |
92 | 92 | 'methods' => WP_REST_Server::READABLE, |
93 | - 'callback' => array( $this, 'get_item' ), |
|
94 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
93 | + 'callback' => array($this, 'get_item'), |
|
94 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
95 | 95 | 'args' => array( |
96 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
96 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
97 | 97 | ), |
98 | 98 | ), |
99 | 99 | array( |
100 | 100 | 'methods' => WP_REST_Server::DELETABLE, |
101 | - 'callback' => array( $this, 'delete_item' ), |
|
102 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
101 | + 'callback' => array($this, 'delete_item'), |
|
102 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
103 | 103 | 'args' => array( |
104 | 104 | 'force' => array( |
105 | 105 | 'default' => true, |
106 | 106 | 'type' => 'boolean', |
107 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
107 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
108 | 108 | ), |
109 | 109 | ), |
110 | 110 | ), |
111 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
112 | - ) ); |
|
111 | + 'schema' => array($this, 'get_public_item_schema'), |
|
112 | + )); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -120,38 +120,38 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return WP_Error|WP_REST_Response |
122 | 122 | */ |
123 | - public function prepare_item_for_response( $post, $request ) { |
|
124 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
123 | + public function prepare_item_for_response($post, $request) { |
|
124 | + $order = wc_get_order((int) $request['order_id']); |
|
125 | 125 | |
126 | - if ( ! $order ) { |
|
127 | - return new WP_Error( 'woocommerce_rest_invalid_order_id', __( 'Invalid order ID.', 'woocommerce' ), 404 ); |
|
126 | + if ( ! $order) { |
|
127 | + return new WP_Error('woocommerce_rest_invalid_order_id', __('Invalid order ID.', 'woocommerce'), 404); |
|
128 | 128 | } |
129 | 129 | |
130 | - $refund = wc_get_order( $post ); |
|
130 | + $refund = wc_get_order($post); |
|
131 | 131 | |
132 | - if ( ! $refund || $refund->get_parent_id() !== $order->get_id() ) { |
|
133 | - return new WP_Error( 'woocommerce_rest_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 404 ); |
|
132 | + if ( ! $refund || $refund->get_parent_id() !== $order->get_id()) { |
|
133 | + return new WP_Error('woocommerce_rest_invalid_order_refund_id', __('Invalid order refund ID.', 'woocommerce'), 404); |
|
134 | 134 | } |
135 | 135 | |
136 | - $dp = is_null( $request['dp'] ) ? wc_get_price_decimals() : absint( $request['dp'] ); |
|
136 | + $dp = is_null($request['dp']) ? wc_get_price_decimals() : absint($request['dp']); |
|
137 | 137 | |
138 | 138 | $data = array( |
139 | 139 | 'id' => $refund->get_id(), |
140 | - 'date_created' => wc_rest_prepare_date_response( $refund->get_date_created() ), |
|
141 | - 'amount' => wc_format_decimal( $refund->get_amount(), $dp ), |
|
140 | + 'date_created' => wc_rest_prepare_date_response($refund->get_date_created()), |
|
141 | + 'amount' => wc_format_decimal($refund->get_amount(), $dp), |
|
142 | 142 | 'reason' => $refund->get_reason(), |
143 | 143 | 'line_items' => array(), |
144 | 144 | ); |
145 | 145 | |
146 | 146 | // Add line items. |
147 | - foreach ( $refund->get_items() as $item_id => $item ) { |
|
148 | - $product = $refund->get_product_from_item( $item ); |
|
147 | + foreach ($refund->get_items() as $item_id => $item) { |
|
148 | + $product = $refund->get_product_from_item($item); |
|
149 | 149 | $product_id = 0; |
150 | 150 | $variation_id = 0; |
151 | 151 | $product_sku = null; |
152 | 152 | |
153 | 153 | // Check if the product exists. |
154 | - if ( is_object( $product ) ) { |
|
154 | + if (is_object($product)) { |
|
155 | 155 | $product_id = $item->get_product_id(); |
156 | 156 | $variation_id = $item->get_variation_id(); |
157 | 157 | $product_sku = $product->get_sku(); |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | |
162 | 162 | $hideprefix = 'true' === $request['all_item_meta'] ? null : '_'; |
163 | 163 | |
164 | - foreach ( $item->get_formatted_meta_data( $hideprefix, true ) as $meta_key => $formatted_meta ) { |
|
164 | + foreach ($item->get_formatted_meta_data($hideprefix, true) as $meta_key => $formatted_meta) { |
|
165 | 165 | $item_meta[] = array( |
166 | 166 | 'key' => $formatted_meta->key, |
167 | 167 | 'label' => $formatted_meta->display_key, |
168 | - 'value' => wc_clean( $formatted_meta->display_value ), |
|
168 | + 'value' => wc_clean($formatted_meta->display_value), |
|
169 | 169 | ); |
170 | 170 | } |
171 | 171 | |
@@ -175,47 +175,47 @@ discard block |
||
175 | 175 | 'sku' => $product_sku, |
176 | 176 | 'product_id' => (int) $product_id, |
177 | 177 | 'variation_id' => (int) $variation_id, |
178 | - 'quantity' => wc_stock_amount( $item['qty'] ), |
|
179 | - 'tax_class' => ! empty( $item['tax_class'] ) ? $item['tax_class'] : '', |
|
180 | - 'price' => wc_format_decimal( $refund->get_item_total( $item, false, false ), $dp ), |
|
181 | - 'subtotal' => wc_format_decimal( $refund->get_line_subtotal( $item, false, false ), $dp ), |
|
182 | - 'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $dp ), |
|
183 | - 'total' => wc_format_decimal( $refund->get_line_total( $item, false, false ), $dp ), |
|
184 | - 'total_tax' => wc_format_decimal( $item['line_tax'], $dp ), |
|
178 | + 'quantity' => wc_stock_amount($item['qty']), |
|
179 | + 'tax_class' => ! empty($item['tax_class']) ? $item['tax_class'] : '', |
|
180 | + 'price' => wc_format_decimal($refund->get_item_total($item, false, false), $dp), |
|
181 | + 'subtotal' => wc_format_decimal($refund->get_line_subtotal($item, false, false), $dp), |
|
182 | + 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), |
|
183 | + 'total' => wc_format_decimal($refund->get_line_total($item, false, false), $dp), |
|
184 | + 'total_tax' => wc_format_decimal($item['line_tax'], $dp), |
|
185 | 185 | 'taxes' => array(), |
186 | 186 | 'meta' => $item_meta, |
187 | 187 | ); |
188 | 188 | |
189 | - $item_line_taxes = maybe_unserialize( $item['line_tax_data'] ); |
|
190 | - if ( isset( $item_line_taxes['total'] ) ) { |
|
189 | + $item_line_taxes = maybe_unserialize($item['line_tax_data']); |
|
190 | + if (isset($item_line_taxes['total'])) { |
|
191 | 191 | $line_tax = array(); |
192 | 192 | |
193 | - foreach ( $item_line_taxes['total'] as $tax_rate_id => $tax ) { |
|
194 | - $line_tax[ $tax_rate_id ] = array( |
|
193 | + foreach ($item_line_taxes['total'] as $tax_rate_id => $tax) { |
|
194 | + $line_tax[$tax_rate_id] = array( |
|
195 | 195 | 'id' => $tax_rate_id, |
196 | 196 | 'total' => $tax, |
197 | 197 | 'subtotal' => '', |
198 | 198 | ); |
199 | 199 | } |
200 | 200 | |
201 | - foreach ( $item_line_taxes['subtotal'] as $tax_rate_id => $tax ) { |
|
202 | - $line_tax[ $tax_rate_id ]['subtotal'] = $tax; |
|
201 | + foreach ($item_line_taxes['subtotal'] as $tax_rate_id => $tax) { |
|
202 | + $line_tax[$tax_rate_id]['subtotal'] = $tax; |
|
203 | 203 | } |
204 | 204 | |
205 | - $line_item['taxes'] = array_values( $line_tax ); |
|
205 | + $line_item['taxes'] = array_values($line_tax); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | $data['line_items'][] = $line_item; |
209 | 209 | } |
210 | 210 | |
211 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
212 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
213 | - $data = $this->filter_response_by_context( $data, $context ); |
|
211 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
212 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
213 | + $data = $this->filter_response_by_context($data, $context); |
|
214 | 214 | |
215 | 215 | // Wrap the data in a response object. |
216 | - $response = rest_ensure_response( $data ); |
|
216 | + $response = rest_ensure_response($data); |
|
217 | 217 | |
218 | - $response->add_links( $this->prepare_links( $refund, $request ) ); |
|
218 | + $response->add_links($this->prepare_links($refund, $request)); |
|
219 | 219 | |
220 | 220 | /** |
221 | 221 | * Filter the data for a response. |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @param WP_Post $post Post object. |
228 | 228 | * @param WP_REST_Request $request Request object. |
229 | 229 | */ |
230 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request ); |
|
230 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -237,18 +237,18 @@ discard block |
||
237 | 237 | * @param WP_REST_Request $request Request object. |
238 | 238 | * @return array Links for the given order refund. |
239 | 239 | */ |
240 | - protected function prepare_links( $refund, $request ) { |
|
240 | + protected function prepare_links($refund, $request) { |
|
241 | 241 | $order_id = $refund->get_parent_id(); |
242 | - $base = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base ); |
|
242 | + $base = str_replace('(?P<order_id>[\d]+)', $order_id, $this->rest_base); |
|
243 | 243 | $links = array( |
244 | 244 | 'self' => array( |
245 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $refund->get_id() ) ), |
|
245 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $refund->get_id())), |
|
246 | 246 | ), |
247 | 247 | 'collection' => array( |
248 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
248 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
249 | 249 | ), |
250 | 250 | 'up' => array( |
251 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ), |
|
251 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order_id)), |
|
252 | 252 | ), |
253 | 253 | ); |
254 | 254 | |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | * @param WP_REST_Request $request Request object. |
263 | 263 | * @return array |
264 | 264 | */ |
265 | - public function query_args( $args, $request ) { |
|
266 | - $args['post_status'] = array_keys( wc_get_order_statuses() ); |
|
267 | - $args['post_parent__in'] = array( absint( $request['order_id'] ) ); |
|
265 | + public function query_args($args, $request) { |
|
266 | + $args['post_status'] = array_keys(wc_get_order_statuses()); |
|
267 | + $args['post_parent__in'] = array(absint($request['order_id'])); |
|
268 | 268 | |
269 | 269 | return $args; |
270 | 270 | } |
@@ -275,41 +275,41 @@ discard block |
||
275 | 275 | * @param WP_REST_Request $request Full details about the request. |
276 | 276 | * @return WP_Error|WP_REST_Response |
277 | 277 | */ |
278 | - public function create_item( $request ) { |
|
279 | - if ( ! empty( $request['id'] ) ) { |
|
278 | + public function create_item($request) { |
|
279 | + if ( ! empty($request['id'])) { |
|
280 | 280 | /* translators: %s: post type */ |
281 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
281 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
282 | 282 | } |
283 | 283 | |
284 | - $order_data = get_post( (int) $request['order_id'] ); |
|
284 | + $order_data = get_post((int) $request['order_id']); |
|
285 | 285 | |
286 | - if ( empty( $order_data ) ) { |
|
287 | - return new WP_Error( 'woocommerce_rest_invalid_order', __( 'Order is invalid', 'woocommerce' ), 400 ); |
|
286 | + if (empty($order_data)) { |
|
287 | + return new WP_Error('woocommerce_rest_invalid_order', __('Order is invalid', 'woocommerce'), 400); |
|
288 | 288 | } |
289 | 289 | |
290 | - if ( 0 > $request['amount'] ) { |
|
291 | - return new WP_Error( 'woocommerce_rest_invalid_order_refund', __( 'Refund amount must be greater than zero.', 'woocommerce' ), 400 ); |
|
290 | + if (0 > $request['amount']) { |
|
291 | + return new WP_Error('woocommerce_rest_invalid_order_refund', __('Refund amount must be greater than zero.', 'woocommerce'), 400); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | // Create the refund. |
295 | - $refund = wc_create_refund( array( |
|
295 | + $refund = wc_create_refund(array( |
|
296 | 296 | 'order_id' => $order_data->ID, |
297 | 297 | 'amount' => $request['amount'], |
298 | - 'reason' => empty( $request['reason'] ) ? null : $request['reason'], |
|
299 | - 'refund_payment' => is_bool( $request['api_refund'] ) ? $request['api_refund'] : true, |
|
298 | + 'reason' => empty($request['reason']) ? null : $request['reason'], |
|
299 | + 'refund_payment' => is_bool($request['api_refund']) ? $request['api_refund'] : true, |
|
300 | 300 | 'restock_items' => true, |
301 | - ) ); |
|
301 | + )); |
|
302 | 302 | |
303 | - if ( is_wp_error( $refund ) ) { |
|
304 | - return new WP_Error( 'woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500 ); |
|
303 | + if (is_wp_error($refund)) { |
|
304 | + return new WP_Error('woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500); |
|
305 | 305 | } |
306 | 306 | |
307 | - if ( ! $refund ) { |
|
308 | - return new WP_Error( 'woocommerce_rest_cannot_create_order_refund', __( 'Cannot create order refund, please try again.', 'woocommerce' ), 500 ); |
|
307 | + if ( ! $refund) { |
|
308 | + return new WP_Error('woocommerce_rest_cannot_create_order_refund', __('Cannot create order refund, please try again.', 'woocommerce'), 500); |
|
309 | 309 | } |
310 | 310 | |
311 | - $post = get_post( $refund->get_id() ); |
|
312 | - $this->update_additional_fields_for_object( $post, $request ); |
|
311 | + $post = get_post($refund->get_id()); |
|
312 | + $this->update_additional_fields_for_object($post, $request); |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * Fires after a single item is created or updated via the REST API. |
@@ -318,13 +318,13 @@ discard block |
||
318 | 318 | * @param WP_REST_Request $request Request object. |
319 | 319 | * @param boolean $creating True when creating item, false when updating. |
320 | 320 | */ |
321 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true ); |
|
321 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true); |
|
322 | 322 | |
323 | - $request->set_param( 'context', 'edit' ); |
|
324 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
325 | - $response = rest_ensure_response( $response ); |
|
326 | - $response->set_status( 201 ); |
|
327 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ) ); |
|
323 | + $request->set_param('context', 'edit'); |
|
324 | + $response = $this->prepare_item_for_response($post, $request); |
|
325 | + $response = rest_ensure_response($response); |
|
326 | + $response->set_status(201); |
|
327 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID))); |
|
328 | 328 | |
329 | 329 | return $response; |
330 | 330 | } |
@@ -341,160 +341,160 @@ discard block |
||
341 | 341 | 'type' => 'object', |
342 | 342 | 'properties' => array( |
343 | 343 | 'id' => array( |
344 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
344 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
345 | 345 | 'type' => 'integer', |
346 | - 'context' => array( 'view', 'edit' ), |
|
346 | + 'context' => array('view', 'edit'), |
|
347 | 347 | 'readonly' => true, |
348 | 348 | ), |
349 | 349 | 'date_created' => array( |
350 | - 'description' => __( "The date the order refund was created, in the site's timezone.", 'woocommerce' ), |
|
350 | + 'description' => __("The date the order refund was created, in the site's timezone.", 'woocommerce'), |
|
351 | 351 | 'type' => 'date-time', |
352 | - 'context' => array( 'view', 'edit' ), |
|
352 | + 'context' => array('view', 'edit'), |
|
353 | 353 | 'readonly' => true, |
354 | 354 | ), |
355 | 355 | 'amount' => array( |
356 | - 'description' => __( 'Refund amount.', 'woocommerce' ), |
|
356 | + 'description' => __('Refund amount.', 'woocommerce'), |
|
357 | 357 | 'type' => 'string', |
358 | - 'context' => array( 'view', 'edit' ), |
|
358 | + 'context' => array('view', 'edit'), |
|
359 | 359 | ), |
360 | 360 | 'reason' => array( |
361 | - 'description' => __( 'Reason for refund.', 'woocommerce' ), |
|
361 | + 'description' => __('Reason for refund.', 'woocommerce'), |
|
362 | 362 | 'type' => 'string', |
363 | - 'context' => array( 'view', 'edit' ), |
|
363 | + 'context' => array('view', 'edit'), |
|
364 | 364 | ), |
365 | 365 | 'line_items' => array( |
366 | - 'description' => __( 'Line items data.', 'woocommerce' ), |
|
366 | + 'description' => __('Line items data.', 'woocommerce'), |
|
367 | 367 | 'type' => 'array', |
368 | - 'context' => array( 'view', 'edit' ), |
|
368 | + 'context' => array('view', 'edit'), |
|
369 | 369 | 'readonly' => true, |
370 | 370 | 'items' => array( |
371 | 371 | 'type' => 'object', |
372 | 372 | 'properties' => array( |
373 | 373 | 'id' => array( |
374 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
374 | + 'description' => __('Item ID.', 'woocommerce'), |
|
375 | 375 | 'type' => 'integer', |
376 | - 'context' => array( 'view', 'edit' ), |
|
376 | + 'context' => array('view', 'edit'), |
|
377 | 377 | 'readonly' => true, |
378 | 378 | ), |
379 | 379 | 'name' => array( |
380 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
380 | + 'description' => __('Product name.', 'woocommerce'), |
|
381 | 381 | 'type' => 'mixed', |
382 | - 'context' => array( 'view', 'edit' ), |
|
382 | + 'context' => array('view', 'edit'), |
|
383 | 383 | 'readonly' => true, |
384 | 384 | ), |
385 | 385 | 'sku' => array( |
386 | - 'description' => __( 'Product SKU.', 'woocommerce' ), |
|
386 | + 'description' => __('Product SKU.', 'woocommerce'), |
|
387 | 387 | 'type' => 'string', |
388 | - 'context' => array( 'view', 'edit' ), |
|
388 | + 'context' => array('view', 'edit'), |
|
389 | 389 | 'readonly' => true, |
390 | 390 | ), |
391 | 391 | 'product_id' => array( |
392 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
392 | + 'description' => __('Product ID.', 'woocommerce'), |
|
393 | 393 | 'type' => 'mixed', |
394 | - 'context' => array( 'view', 'edit' ), |
|
394 | + 'context' => array('view', 'edit'), |
|
395 | 395 | 'readonly' => true, |
396 | 396 | ), |
397 | 397 | 'variation_id' => array( |
398 | - 'description' => __( 'Variation ID, if applicable.', 'woocommerce' ), |
|
398 | + 'description' => __('Variation ID, if applicable.', 'woocommerce'), |
|
399 | 399 | 'type' => 'integer', |
400 | - 'context' => array( 'view', 'edit' ), |
|
400 | + 'context' => array('view', 'edit'), |
|
401 | 401 | 'readonly' => true, |
402 | 402 | ), |
403 | 403 | 'quantity' => array( |
404 | - 'description' => __( 'Quantity ordered.', 'woocommerce' ), |
|
404 | + 'description' => __('Quantity ordered.', 'woocommerce'), |
|
405 | 405 | 'type' => 'integer', |
406 | - 'context' => array( 'view', 'edit' ), |
|
406 | + 'context' => array('view', 'edit'), |
|
407 | 407 | 'readonly' => true, |
408 | 408 | ), |
409 | 409 | 'tax_class' => array( |
410 | - 'description' => __( 'Tax class of product.', 'woocommerce' ), |
|
410 | + 'description' => __('Tax class of product.', 'woocommerce'), |
|
411 | 411 | 'type' => 'string', |
412 | - 'context' => array( 'view', 'edit' ), |
|
412 | + 'context' => array('view', 'edit'), |
|
413 | 413 | 'readonly' => true, |
414 | 414 | ), |
415 | 415 | 'price' => array( |
416 | - 'description' => __( 'Product price.', 'woocommerce' ), |
|
416 | + 'description' => __('Product price.', 'woocommerce'), |
|
417 | 417 | 'type' => 'string', |
418 | - 'context' => array( 'view', 'edit' ), |
|
418 | + 'context' => array('view', 'edit'), |
|
419 | 419 | 'readonly' => true, |
420 | 420 | ), |
421 | 421 | 'subtotal' => array( |
422 | - 'description' => __( 'Line subtotal (before discounts).', 'woocommerce' ), |
|
422 | + 'description' => __('Line subtotal (before discounts).', 'woocommerce'), |
|
423 | 423 | 'type' => 'string', |
424 | - 'context' => array( 'view', 'edit' ), |
|
424 | + 'context' => array('view', 'edit'), |
|
425 | 425 | 'readonly' => true, |
426 | 426 | ), |
427 | 427 | 'subtotal_tax' => array( |
428 | - 'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce' ), |
|
428 | + 'description' => __('Line subtotal tax (before discounts).', 'woocommerce'), |
|
429 | 429 | 'type' => 'string', |
430 | - 'context' => array( 'view', 'edit' ), |
|
430 | + 'context' => array('view', 'edit'), |
|
431 | 431 | 'readonly' => true, |
432 | 432 | ), |
433 | 433 | 'total' => array( |
434 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
434 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
435 | 435 | 'type' => 'string', |
436 | - 'context' => array( 'view', 'edit' ), |
|
436 | + 'context' => array('view', 'edit'), |
|
437 | 437 | 'readonly' => true, |
438 | 438 | ), |
439 | 439 | 'total_tax' => array( |
440 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
440 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
441 | 441 | 'type' => 'string', |
442 | - 'context' => array( 'view', 'edit' ), |
|
442 | + 'context' => array('view', 'edit'), |
|
443 | 443 | 'readonly' => true, |
444 | 444 | ), |
445 | 445 | 'taxes' => array( |
446 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
446 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
447 | 447 | 'type' => 'array', |
448 | - 'context' => array( 'view', 'edit' ), |
|
448 | + 'context' => array('view', 'edit'), |
|
449 | 449 | 'readonly' => true, |
450 | 450 | 'items' => array( |
451 | 451 | 'type' => 'object', |
452 | 452 | 'properties' => array( |
453 | 453 | 'id' => array( |
454 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
454 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
455 | 455 | 'type' => 'integer', |
456 | - 'context' => array( 'view', 'edit' ), |
|
456 | + 'context' => array('view', 'edit'), |
|
457 | 457 | 'readonly' => true, |
458 | 458 | ), |
459 | 459 | 'total' => array( |
460 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
460 | + 'description' => __('Tax total.', 'woocommerce'), |
|
461 | 461 | 'type' => 'string', |
462 | - 'context' => array( 'view', 'edit' ), |
|
462 | + 'context' => array('view', 'edit'), |
|
463 | 463 | 'readonly' => true, |
464 | 464 | ), |
465 | 465 | 'subtotal' => array( |
466 | - 'description' => __( 'Tax subtotal.', 'woocommerce' ), |
|
466 | + 'description' => __('Tax subtotal.', 'woocommerce'), |
|
467 | 467 | 'type' => 'string', |
468 | - 'context' => array( 'view', 'edit' ), |
|
468 | + 'context' => array('view', 'edit'), |
|
469 | 469 | 'readonly' => true, |
470 | 470 | ), |
471 | 471 | ), |
472 | 472 | ), |
473 | 473 | ), |
474 | 474 | 'meta' => array( |
475 | - 'description' => __( 'Line item meta data.', 'woocommerce' ), |
|
475 | + 'description' => __('Line item meta data.', 'woocommerce'), |
|
476 | 476 | 'type' => 'array', |
477 | - 'context' => array( 'view', 'edit' ), |
|
477 | + 'context' => array('view', 'edit'), |
|
478 | 478 | 'readonly' => true, |
479 | 479 | 'items' => array( |
480 | 480 | 'type' => 'object', |
481 | 481 | 'properties' => array( |
482 | 482 | 'key' => array( |
483 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
483 | + 'description' => __('Meta key.', 'woocommerce'), |
|
484 | 484 | 'type' => 'string', |
485 | - 'context' => array( 'view', 'edit' ), |
|
485 | + 'context' => array('view', 'edit'), |
|
486 | 486 | 'readonly' => true, |
487 | 487 | ), |
488 | 488 | 'label' => array( |
489 | - 'description' => __( 'Meta label.', 'woocommerce' ), |
|
489 | + 'description' => __('Meta label.', 'woocommerce'), |
|
490 | 490 | 'type' => 'string', |
491 | - 'context' => array( 'view', 'edit' ), |
|
491 | + 'context' => array('view', 'edit'), |
|
492 | 492 | 'readonly' => true, |
493 | 493 | ), |
494 | 494 | 'value' => array( |
495 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
495 | + 'description' => __('Meta value.', 'woocommerce'), |
|
496 | 496 | 'type' => 'mixed', |
497 | - 'context' => array( 'view', 'edit' ), |
|
497 | + 'context' => array('view', 'edit'), |
|
498 | 498 | 'readonly' => true, |
499 | 499 | ), |
500 | 500 | ), |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | ), |
507 | 507 | ); |
508 | 508 | |
509 | - return $this->add_additional_fields_schema( $schema ); |
|
509 | + return $this->add_additional_fields_schema($schema); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | |
520 | 520 | $params['dp'] = array( |
521 | 521 | 'default' => wc_get_price_decimals(), |
522 | - 'description' => __( 'Number of decimal points to use in each resource.', 'woocommerce' ), |
|
522 | + 'description' => __('Number of decimal points to use in each resource.', 'woocommerce'), |
|
523 | 523 | 'type' => 'integer', |
524 | 524 | 'sanitize_callback' => 'absint', |
525 | 525 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -40,87 +40,87 @@ discard block |
||
40 | 40 | * Register the routes for product reviews. |
41 | 41 | */ |
42 | 42 | public function register_routes() { |
43 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
43 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
44 | 44 | 'args' => array( |
45 | 45 | 'product_id' => array( |
46 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
46 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
47 | 47 | 'type' => 'integer', |
48 | 48 | ), |
49 | 49 | 'id' => array( |
50 | - 'description' => __( 'Unique identifier for the variation.', 'woocommerce' ), |
|
50 | + 'description' => __('Unique identifier for the variation.', 'woocommerce'), |
|
51 | 51 | 'type' => 'integer', |
52 | 52 | ), |
53 | 53 | ), |
54 | 54 | array( |
55 | 55 | 'methods' => WP_REST_Server::READABLE, |
56 | - 'callback' => array( $this, 'get_items' ), |
|
57 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
56 | + 'callback' => array($this, 'get_items'), |
|
57 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
58 | 58 | 'args' => $this->get_collection_params(), |
59 | 59 | ), |
60 | 60 | array( |
61 | 61 | 'methods' => WP_REST_Server::CREATABLE, |
62 | - 'callback' => array( $this, 'create_item' ), |
|
63 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
64 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
62 | + 'callback' => array($this, 'create_item'), |
|
63 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
64 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
65 | 65 | 'review' => array( |
66 | 66 | 'required' => true, |
67 | 67 | 'type' => 'string', |
68 | - 'description' => __( 'Review content.', 'woocommerce' ), |
|
68 | + 'description' => __('Review content.', 'woocommerce'), |
|
69 | 69 | ), |
70 | 70 | 'name' => array( |
71 | 71 | 'required' => true, |
72 | 72 | 'type' => 'string', |
73 | - 'description' => __( 'Name of the reviewer.', 'woocommerce' ), |
|
73 | + 'description' => __('Name of the reviewer.', 'woocommerce'), |
|
74 | 74 | ), |
75 | 75 | 'email' => array( |
76 | 76 | 'required' => true, |
77 | 77 | 'type' => 'string', |
78 | - 'description' => __( 'Email of the reviewer.', 'woocommerce' ), |
|
78 | + 'description' => __('Email of the reviewer.', 'woocommerce'), |
|
79 | 79 | ), |
80 | - ) ), |
|
80 | + )), |
|
81 | 81 | ), |
82 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
83 | - ) ); |
|
82 | + 'schema' => array($this, 'get_public_item_schema'), |
|
83 | + )); |
|
84 | 84 | |
85 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
85 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
86 | 86 | 'args' => array( |
87 | 87 | 'product_id' => array( |
88 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
88 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
89 | 89 | 'type' => 'integer', |
90 | 90 | ), |
91 | 91 | 'id' => array( |
92 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
92 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
93 | 93 | 'type' => 'integer', |
94 | 94 | ), |
95 | 95 | ), |
96 | 96 | array( |
97 | 97 | 'methods' => WP_REST_Server::READABLE, |
98 | - 'callback' => array( $this, 'get_item' ), |
|
99 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
98 | + 'callback' => array($this, 'get_item'), |
|
99 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
100 | 100 | 'args' => array( |
101 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
101 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
102 | 102 | ), |
103 | 103 | ), |
104 | 104 | array( |
105 | 105 | 'methods' => WP_REST_Server::EDITABLE, |
106 | - 'callback' => array( $this, 'update_item' ), |
|
107 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
108 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
106 | + 'callback' => array($this, 'update_item'), |
|
107 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
108 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
109 | 109 | ), |
110 | 110 | array( |
111 | 111 | 'methods' => WP_REST_Server::DELETABLE, |
112 | - 'callback' => array( $this, 'delete_item' ), |
|
113 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
112 | + 'callback' => array($this, 'delete_item'), |
|
113 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
114 | 114 | 'args' => array( |
115 | 115 | 'force' => array( |
116 | 116 | 'default' => false, |
117 | 117 | 'type' => 'boolean', |
118 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
118 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
119 | 119 | ), |
120 | 120 | ), |
121 | 121 | ), |
122 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
123 | - ) ); |
|
122 | + 'schema' => array($this, 'get_public_item_schema'), |
|
123 | + )); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | * @param WP_REST_Request $request Full details about the request. |
130 | 130 | * @return WP_Error|boolean |
131 | 131 | */ |
132 | - public function get_items_permissions_check( $request ) { |
|
133 | - if ( ! wc_rest_check_post_permissions( 'product', 'read' ) ) { |
|
134 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
132 | + public function get_items_permissions_check($request) { |
|
133 | + if ( ! wc_rest_check_post_permissions('product', 'read')) { |
|
134 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | return true; |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | * @param WP_REST_Request $request Full details about the request. |
144 | 144 | * @return WP_Error|boolean |
145 | 145 | */ |
146 | - public function get_item_permissions_check( $request ) { |
|
147 | - $post = get_post( (int) $request['product_id'] ); |
|
146 | + public function get_item_permissions_check($request) { |
|
147 | + $post = get_post((int) $request['product_id']); |
|
148 | 148 | |
149 | - if ( $post && ! wc_rest_check_post_permissions( 'product', 'read', $post->ID ) ) { |
|
150 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
149 | + if ($post && ! wc_rest_check_post_permissions('product', 'read', $post->ID)) { |
|
150 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | return true; |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | * @param WP_REST_Request $request Full details about the request. |
160 | 160 | * @return WP_Error|boolean |
161 | 161 | */ |
162 | - public function create_item_permissions_check( $request ) { |
|
163 | - $post = get_post( (int) $request['product_id'] ); |
|
164 | - if ( $post && ! wc_rest_check_post_permissions( 'product', 'create', $post->ID ) ) { |
|
165 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
162 | + public function create_item_permissions_check($request) { |
|
163 | + $post = get_post((int) $request['product_id']); |
|
164 | + if ($post && ! wc_rest_check_post_permissions('product', 'create', $post->ID)) { |
|
165 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
166 | 166 | } |
167 | 167 | return true; |
168 | 168 | } |
@@ -173,10 +173,10 @@ discard block |
||
173 | 173 | * @param WP_REST_Request $request Full details about the request. |
174 | 174 | * @return WP_Error|boolean |
175 | 175 | */ |
176 | - public function update_item_permissions_check( $request ) { |
|
177 | - $post = get_post( (int) $request['product_id'] ); |
|
178 | - if ( $post && ! wc_rest_check_post_permissions( 'product', 'edit', $post->ID ) ) { |
|
179 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
176 | + public function update_item_permissions_check($request) { |
|
177 | + $post = get_post((int) $request['product_id']); |
|
178 | + if ($post && ! wc_rest_check_post_permissions('product', 'edit', $post->ID)) { |
|
179 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
180 | 180 | } |
181 | 181 | return true; |
182 | 182 | } |
@@ -187,10 +187,10 @@ discard block |
||
187 | 187 | * @param WP_REST_Request $request Full details about the request. |
188 | 188 | * @return WP_Error|boolean |
189 | 189 | */ |
190 | - public function delete_item_permissions_check( $request ) { |
|
191 | - $post = get_post( (int) $request['product_id'] ); |
|
192 | - if ( $post && ! wc_rest_check_post_permissions( 'product', 'delete', $post->ID ) ) { |
|
193 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
190 | + public function delete_item_permissions_check($request) { |
|
191 | + $post = get_post((int) $request['product_id']); |
|
192 | + if ($post && ! wc_rest_check_post_permissions('product', 'delete', $post->ID)) { |
|
193 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
194 | 194 | } |
195 | 195 | return true; |
196 | 196 | } |
@@ -202,22 +202,22 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @return array|WP_Error |
204 | 204 | */ |
205 | - public function get_items( $request ) { |
|
205 | + public function get_items($request) { |
|
206 | 206 | $product_id = (int) $request['product_id']; |
207 | 207 | |
208 | - if ( 'product' !== get_post_type( $product_id ) ) { |
|
209 | - return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
208 | + if ('product' !== get_post_type($product_id)) { |
|
209 | + return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
210 | 210 | } |
211 | 211 | |
212 | - $reviews = get_approved_comments( $product_id ); |
|
212 | + $reviews = get_approved_comments($product_id); |
|
213 | 213 | $data = array(); |
214 | - foreach ( $reviews as $review_data ) { |
|
215 | - $review = $this->prepare_item_for_response( $review_data, $request ); |
|
216 | - $review = $this->prepare_response_for_collection( $review ); |
|
214 | + foreach ($reviews as $review_data) { |
|
215 | + $review = $this->prepare_item_for_response($review_data, $request); |
|
216 | + $review = $this->prepare_response_for_collection($review); |
|
217 | 217 | $data[] = $review; |
218 | 218 | } |
219 | 219 | |
220 | - return rest_ensure_response( $data ); |
|
220 | + return rest_ensure_response($data); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -226,22 +226,22 @@ discard block |
||
226 | 226 | * @param WP_REST_Request $request Full details about the request. |
227 | 227 | * @return WP_Error|WP_REST_Response |
228 | 228 | */ |
229 | - public function get_item( $request ) { |
|
229 | + public function get_item($request) { |
|
230 | 230 | $id = (int) $request['id']; |
231 | 231 | $product_id = (int) $request['product_id']; |
232 | 232 | |
233 | - if ( 'product' !== get_post_type( $product_id ) ) { |
|
234 | - return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
233 | + if ('product' !== get_post_type($product_id)) { |
|
234 | + return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
235 | 235 | } |
236 | 236 | |
237 | - $review = get_comment( $id ); |
|
237 | + $review = get_comment($id); |
|
238 | 238 | |
239 | - if ( empty( $id ) || empty( $review ) || intval( $review->comment_post_ID ) !== $product_id ) { |
|
240 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
239 | + if (empty($id) || empty($review) || intval($review->comment_post_ID) !== $product_id) { |
|
240 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
241 | 241 | } |
242 | 242 | |
243 | - $delivery = $this->prepare_item_for_response( $review, $request ); |
|
244 | - $response = rest_ensure_response( $delivery ); |
|
243 | + $delivery = $this->prepare_item_for_response($review, $request); |
|
244 | + $response = rest_ensure_response($delivery); |
|
245 | 245 | |
246 | 246 | return $response; |
247 | 247 | } |
@@ -253,14 +253,14 @@ discard block |
||
253 | 253 | * @param WP_REST_Request $request Full details about the request. |
254 | 254 | * @return WP_Error|WP_REST_Response |
255 | 255 | */ |
256 | - public function create_item( $request ) { |
|
256 | + public function create_item($request) { |
|
257 | 257 | $product_id = (int) $request['product_id']; |
258 | 258 | |
259 | - if ( 'product' !== get_post_type( $product_id ) ) { |
|
260 | - return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
259 | + if ('product' !== get_post_type($product_id)) { |
|
260 | + return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
261 | 261 | } |
262 | 262 | |
263 | - $prepared_review = $this->prepare_item_for_database( $request ); |
|
263 | + $prepared_review = $this->prepare_item_for_database($request); |
|
264 | 264 | |
265 | 265 | /** |
266 | 266 | * Filter a product review (comment) before it is inserted via the REST API. |
@@ -270,17 +270,17 @@ discard block |
||
270 | 270 | * @param array $prepared_review The prepared comment data for `wp_insert_comment`. |
271 | 271 | * @param WP_REST_Request $request Request used to insert the comment. |
272 | 272 | */ |
273 | - $prepared_review = apply_filters( 'rest_pre_insert_product_review', $prepared_review, $request ); |
|
273 | + $prepared_review = apply_filters('rest_pre_insert_product_review', $prepared_review, $request); |
|
274 | 274 | |
275 | - $product_review_id = wp_insert_comment( $prepared_review ); |
|
276 | - if ( ! $product_review_id ) { |
|
277 | - return new WP_Error( 'rest_product_review_failed_create', __( 'Creating product review failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
275 | + $product_review_id = wp_insert_comment($prepared_review); |
|
276 | + if ( ! $product_review_id) { |
|
277 | + return new WP_Error('rest_product_review_failed_create', __('Creating product review failed.', 'woocommerce'), array('status' => 500)); |
|
278 | 278 | } |
279 | 279 | |
280 | - update_comment_meta( $product_review_id, 'rating', ( ! empty( $request['rating'] ) ? $request['rating'] : '0' ) ); |
|
280 | + update_comment_meta($product_review_id, 'rating', ( ! empty($request['rating']) ? $request['rating'] : '0')); |
|
281 | 281 | |
282 | - $product_review = get_comment( $product_review_id ); |
|
283 | - $this->update_additional_fields_for_object( $product_review, $request ); |
|
282 | + $product_review = get_comment($product_review_id); |
|
283 | + $this->update_additional_fields_for_object($product_review, $request); |
|
284 | 284 | |
285 | 285 | /** |
286 | 286 | * Fires after a single item is created or updated via the REST API. |
@@ -289,14 +289,14 @@ discard block |
||
289 | 289 | * @param WP_REST_Request $request Request object. |
290 | 290 | * @param boolean $creating True when creating item, false when updating. |
291 | 291 | */ |
292 | - do_action( "woocommerce_rest_insert_product_review", $product_review, $request, true ); |
|
292 | + do_action("woocommerce_rest_insert_product_review", $product_review, $request, true); |
|
293 | 293 | |
294 | - $request->set_param( 'context', 'edit' ); |
|
295 | - $response = $this->prepare_item_for_response( $product_review, $request ); |
|
296 | - $response = rest_ensure_response( $response ); |
|
297 | - $response->set_status( 201 ); |
|
298 | - $base = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base ); |
|
299 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $product_review_id ) ) ); |
|
294 | + $request->set_param('context', 'edit'); |
|
295 | + $response = $this->prepare_item_for_response($product_review, $request); |
|
296 | + $response = rest_ensure_response($response); |
|
297 | + $response->set_status(201); |
|
298 | + $base = str_replace('(?P<product_id>[\d]+)', $product_id, $this->rest_base); |
|
299 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $product_review_id))); |
|
300 | 300 | |
301 | 301 | return $response; |
302 | 302 | } |
@@ -307,33 +307,33 @@ discard block |
||
307 | 307 | * @param WP_REST_Request $request Full details about the request. |
308 | 308 | * @return WP_Error|WP_REST_Response |
309 | 309 | */ |
310 | - public function update_item( $request ) { |
|
310 | + public function update_item($request) { |
|
311 | 311 | $product_review_id = (int) $request['id']; |
312 | 312 | $product_id = (int) $request['product_id']; |
313 | 313 | |
314 | - if ( 'product' !== get_post_type( $product_id ) ) { |
|
315 | - return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
314 | + if ('product' !== get_post_type($product_id)) { |
|
315 | + return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
316 | 316 | } |
317 | 317 | |
318 | - $review = get_comment( $product_review_id ); |
|
318 | + $review = get_comment($product_review_id); |
|
319 | 319 | |
320 | - if ( empty( $product_review_id ) || empty( $review ) || intval( $review->comment_post_ID ) !== $product_id ) { |
|
321 | - return new WP_Error( 'woocommerce_rest_product_review_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
320 | + if (empty($product_review_id) || empty($review) || intval($review->comment_post_ID) !== $product_id) { |
|
321 | + return new WP_Error('woocommerce_rest_product_review_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
322 | 322 | } |
323 | 323 | |
324 | - $prepared_review = $this->prepare_item_for_database( $request ); |
|
324 | + $prepared_review = $this->prepare_item_for_database($request); |
|
325 | 325 | |
326 | - $updated = wp_update_comment( $prepared_review ); |
|
327 | - if ( 0 === $updated ) { |
|
328 | - return new WP_Error( 'rest_product_review_failed_edit', __( 'Updating product review failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
326 | + $updated = wp_update_comment($prepared_review); |
|
327 | + if (0 === $updated) { |
|
328 | + return new WP_Error('rest_product_review_failed_edit', __('Updating product review failed.', 'woocommerce'), array('status' => 500)); |
|
329 | 329 | } |
330 | 330 | |
331 | - if ( ! empty( $request['rating'] ) ) { |
|
332 | - update_comment_meta( $product_review_id, 'rating', $request['rating'] ); |
|
331 | + if ( ! empty($request['rating'])) { |
|
332 | + update_comment_meta($product_review_id, 'rating', $request['rating']); |
|
333 | 333 | } |
334 | 334 | |
335 | - $product_review = get_comment( $product_review_id ); |
|
336 | - $this->update_additional_fields_for_object( $product_review, $request ); |
|
335 | + $product_review = get_comment($product_review_id); |
|
336 | + $this->update_additional_fields_for_object($product_review, $request); |
|
337 | 337 | |
338 | 338 | /** |
339 | 339 | * Fires after a single item is created or updated via the REST API. |
@@ -342,12 +342,12 @@ discard block |
||
342 | 342 | * @param WP_REST_Request $request Request object. |
343 | 343 | * @param boolean $creating True when creating item, false when updating. |
344 | 344 | */ |
345 | - do_action( "woocommerce_rest_insert_product_review", $product_review, $request, true ); |
|
345 | + do_action("woocommerce_rest_insert_product_review", $product_review, $request, true); |
|
346 | 346 | |
347 | - $request->set_param( 'context', 'edit' ); |
|
348 | - $response = $this->prepare_item_for_response( $product_review, $request ); |
|
347 | + $request->set_param('context', 'edit'); |
|
348 | + $response = $this->prepare_item_for_response($product_review, $request); |
|
349 | 349 | |
350 | - return rest_ensure_response( $response ); |
|
350 | + return rest_ensure_response($response); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -357,13 +357,13 @@ discard block |
||
357 | 357 | * |
358 | 358 | * @return bool|WP_Error|WP_REST_Response |
359 | 359 | */ |
360 | - public function delete_item( $request ) { |
|
361 | - $product_review_id = absint( is_array( $request['id'] ) ? $request['id']['id'] : $request['id'] ); |
|
362 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
360 | + public function delete_item($request) { |
|
361 | + $product_review_id = absint(is_array($request['id']) ? $request['id']['id'] : $request['id']); |
|
362 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
363 | 363 | |
364 | - $product_review = get_comment( $product_review_id ); |
|
365 | - if ( empty( $product_review_id ) || empty( $product_review->comment_ID ) || empty( $product_review->comment_post_ID ) ) { |
|
366 | - return new WP_Error( 'woocommerce_rest_product_review_invalid_id', __( 'Invalid product review ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
364 | + $product_review = get_comment($product_review_id); |
|
365 | + if (empty($product_review_id) || empty($product_review->comment_ID) || empty($product_review->comment_post_ID)) { |
|
366 | + return new WP_Error('woocommerce_rest_product_review_invalid_id', __('Invalid product review ID.', 'woocommerce'), array('status' => 404)); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
@@ -374,27 +374,27 @@ discard block |
||
374 | 374 | * @param boolean $supports_trash Whether the object supports trashing. |
375 | 375 | * @param WP_Post $product_review The object being considered for trashing support. |
376 | 376 | */ |
377 | - $supports_trash = apply_filters( 'rest_product_review_trashable', ( EMPTY_TRASH_DAYS > 0 ), $product_review ); |
|
377 | + $supports_trash = apply_filters('rest_product_review_trashable', (EMPTY_TRASH_DAYS > 0), $product_review); |
|
378 | 378 | |
379 | - $request->set_param( 'context', 'edit' ); |
|
380 | - $response = $this->prepare_item_for_response( $product_review, $request ); |
|
379 | + $request->set_param('context', 'edit'); |
|
380 | + $response = $this->prepare_item_for_response($product_review, $request); |
|
381 | 381 | |
382 | - if ( $force ) { |
|
383 | - $result = wp_delete_comment( $product_review_id, true ); |
|
382 | + if ($force) { |
|
383 | + $result = wp_delete_comment($product_review_id, true); |
|
384 | 384 | } else { |
385 | - if ( ! $supports_trash ) { |
|
386 | - return new WP_Error( 'rest_trash_not_supported', __( 'The product review does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
385 | + if ( ! $supports_trash) { |
|
386 | + return new WP_Error('rest_trash_not_supported', __('The product review does not support trashing.', 'woocommerce'), array('status' => 501)); |
|
387 | 387 | } |
388 | 388 | |
389 | - if ( 'trash' === $product_review->comment_approved ) { |
|
390 | - return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.', 'woocommerce' ), array( 'status' => 410 ) ); |
|
389 | + if ('trash' === $product_review->comment_approved) { |
|
390 | + return new WP_Error('rest_already_trashed', __('The comment has already been trashed.', 'woocommerce'), array('status' => 410)); |
|
391 | 391 | } |
392 | 392 | |
393 | - $result = wp_trash_comment( $product_review->comment_ID ); |
|
393 | + $result = wp_trash_comment($product_review->comment_ID); |
|
394 | 394 | } |
395 | 395 | |
396 | - if ( ! $result ) { |
|
397 | - return new WP_Error( 'rest_cannot_delete', __( 'The product review cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
396 | + if ( ! $result) { |
|
397 | + return new WP_Error('rest_cannot_delete', __('The product review cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | * @param WP_REST_Response $response The response data. |
405 | 405 | * @param WP_REST_Request $request The request sent to the API. |
406 | 406 | */ |
407 | - do_action( 'rest_delete_product_review', $product_review, $response, $request ); |
|
407 | + do_action('rest_delete_product_review', $product_review, $response, $request); |
|
408 | 408 | |
409 | 409 | return $response; |
410 | 410 | } |
@@ -416,25 +416,25 @@ discard block |
||
416 | 416 | * @param WP_REST_Request $request Request object. |
417 | 417 | * @return WP_REST_Response $response Response data. |
418 | 418 | */ |
419 | - public function prepare_item_for_response( $review, $request ) { |
|
419 | + public function prepare_item_for_response($review, $request) { |
|
420 | 420 | $data = array( |
421 | 421 | 'id' => (int) $review->comment_ID, |
422 | - 'date_created' => wc_rest_prepare_date_response( $review->comment_date_gmt ), |
|
422 | + 'date_created' => wc_rest_prepare_date_response($review->comment_date_gmt), |
|
423 | 423 | 'review' => $review->comment_content, |
424 | - 'rating' => (int) get_comment_meta( $review->comment_ID, 'rating', true ), |
|
424 | + 'rating' => (int) get_comment_meta($review->comment_ID, 'rating', true), |
|
425 | 425 | 'name' => $review->comment_author, |
426 | 426 | 'email' => $review->comment_author_email, |
427 | - 'verified' => wc_review_is_from_verified_owner( $review->comment_ID ), |
|
427 | + 'verified' => wc_review_is_from_verified_owner($review->comment_ID), |
|
428 | 428 | ); |
429 | 429 | |
430 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
431 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
432 | - $data = $this->filter_response_by_context( $data, $context ); |
|
430 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
431 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
432 | + $data = $this->filter_response_by_context($data, $context); |
|
433 | 433 | |
434 | 434 | // Wrap the data in a response object. |
435 | - $response = rest_ensure_response( $data ); |
|
435 | + $response = rest_ensure_response($data); |
|
436 | 436 | |
437 | - $response->add_links( $this->prepare_links( $review, $request ) ); |
|
437 | + $response->add_links($this->prepare_links($review, $request)); |
|
438 | 438 | |
439 | 439 | /** |
440 | 440 | * Filter product reviews object returned from the REST API. |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | * @param WP_Comment $review Product review object used to create response. |
444 | 444 | * @param WP_REST_Request $request Request object. |
445 | 445 | */ |
446 | - return apply_filters( 'woocommerce_rest_prepare_product_review', $response, $review, $request ); |
|
446 | + return apply_filters('woocommerce_rest_prepare_product_review', $response, $review, $request); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -452,38 +452,38 @@ discard block |
||
452 | 452 | * @param WP_REST_Request $request Request object. |
453 | 453 | * @return array|WP_Error $prepared_review |
454 | 454 | */ |
455 | - protected function prepare_item_for_database( $request ) { |
|
456 | - $prepared_review = array( 'comment_approved' => 1, 'comment_type' => 'review' ); |
|
455 | + protected function prepare_item_for_database($request) { |
|
456 | + $prepared_review = array('comment_approved' => 1, 'comment_type' => 'review'); |
|
457 | 457 | |
458 | - if ( isset( $request['id'] ) ) { |
|
458 | + if (isset($request['id'])) { |
|
459 | 459 | $prepared_review['comment_ID'] = (int) $request['id']; |
460 | 460 | } |
461 | 461 | |
462 | - if ( isset( $request['review'] ) ) { |
|
462 | + if (isset($request['review'])) { |
|
463 | 463 | $prepared_review['comment_content'] = $request['review']; |
464 | 464 | } |
465 | 465 | |
466 | - if ( isset( $request['product_id'] ) ) { |
|
466 | + if (isset($request['product_id'])) { |
|
467 | 467 | $prepared_review['comment_post_ID'] = (int) $request['product_id']; |
468 | 468 | } |
469 | 469 | |
470 | - if ( isset( $request['name'] ) ) { |
|
470 | + if (isset($request['name'])) { |
|
471 | 471 | $prepared_review['comment_author'] = $request['name']; |
472 | 472 | } |
473 | 473 | |
474 | - if ( isset( $request['email'] ) ) { |
|
474 | + if (isset($request['email'])) { |
|
475 | 475 | $prepared_review['comment_author_email'] = $request['email']; |
476 | 476 | } |
477 | 477 | |
478 | - if ( isset( $request['date_created'] ) ) { |
|
478 | + if (isset($request['date_created'])) { |
|
479 | 479 | $prepared_review['comment_date'] = $request['date_created']; |
480 | 480 | } |
481 | 481 | |
482 | - if ( isset( $request['date_created_gmt'] ) ) { |
|
482 | + if (isset($request['date_created_gmt'])) { |
|
483 | 483 | $prepared_review['comment_date_gmt'] = $request['date_created_gmt']; |
484 | 484 | } |
485 | 485 | |
486 | - return apply_filters( 'rest_preprocess_product_review', $prepared_review, $request ); |
|
486 | + return apply_filters('rest_preprocess_product_review', $prepared_review, $request); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,18 +493,18 @@ discard block |
||
493 | 493 | * @param WP_REST_Request $request Request object. |
494 | 494 | * @return array Links for the given product review. |
495 | 495 | */ |
496 | - protected function prepare_links( $review, $request ) { |
|
496 | + protected function prepare_links($review, $request) { |
|
497 | 497 | $product_id = (int) $request['product_id']; |
498 | - $base = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base ); |
|
498 | + $base = str_replace('(?P<product_id>[\d]+)', $product_id, $this->rest_base); |
|
499 | 499 | $links = array( |
500 | 500 | 'self' => array( |
501 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $review->comment_ID ) ), |
|
501 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $review->comment_ID)), |
|
502 | 502 | ), |
503 | 503 | 'collection' => array( |
504 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
504 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
505 | 505 | ), |
506 | 506 | 'up' => array( |
507 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product_id ) ), |
|
507 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product_id)), |
|
508 | 508 | ), |
509 | 509 | ); |
510 | 510 | |
@@ -523,46 +523,46 @@ discard block |
||
523 | 523 | 'type' => 'object', |
524 | 524 | 'properties' => array( |
525 | 525 | 'id' => array( |
526 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
526 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
527 | 527 | 'type' => 'integer', |
528 | - 'context' => array( 'view', 'edit' ), |
|
528 | + 'context' => array('view', 'edit'), |
|
529 | 529 | 'readonly' => true, |
530 | 530 | ), |
531 | 531 | 'review' => array( |
532 | - 'description' => __( 'The content of the review.', 'woocommerce' ), |
|
532 | + 'description' => __('The content of the review.', 'woocommerce'), |
|
533 | 533 | 'type' => 'string', |
534 | - 'context' => array( 'view', 'edit' ), |
|
534 | + 'context' => array('view', 'edit'), |
|
535 | 535 | ), |
536 | 536 | 'date_created' => array( |
537 | - 'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ), |
|
537 | + 'description' => __("The date the review was created, in the site's timezone.", 'woocommerce'), |
|
538 | 538 | 'type' => 'date-time', |
539 | - 'context' => array( 'view', 'edit' ), |
|
539 | + 'context' => array('view', 'edit'), |
|
540 | 540 | ), |
541 | 541 | 'rating' => array( |
542 | - 'description' => __( 'Review rating (0 to 5).', 'woocommerce' ), |
|
542 | + 'description' => __('Review rating (0 to 5).', 'woocommerce'), |
|
543 | 543 | 'type' => 'integer', |
544 | - 'context' => array( 'view', 'edit' ), |
|
544 | + 'context' => array('view', 'edit'), |
|
545 | 545 | ), |
546 | 546 | 'name' => array( |
547 | - 'description' => __( 'Reviewer name.', 'woocommerce' ), |
|
547 | + 'description' => __('Reviewer name.', 'woocommerce'), |
|
548 | 548 | 'type' => 'string', |
549 | - 'context' => array( 'view', 'edit' ), |
|
549 | + 'context' => array('view', 'edit'), |
|
550 | 550 | ), |
551 | 551 | 'email' => array( |
552 | - 'description' => __( 'Reviewer email.', 'woocommerce' ), |
|
552 | + 'description' => __('Reviewer email.', 'woocommerce'), |
|
553 | 553 | 'type' => 'string', |
554 | - 'context' => array( 'view', 'edit' ), |
|
554 | + 'context' => array('view', 'edit'), |
|
555 | 555 | ), |
556 | 556 | 'verified' => array( |
557 | - 'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ), |
|
557 | + 'description' => __('Shows if the reviewer bought the product or not.', 'woocommerce'), |
|
558 | 558 | 'type' => 'boolean', |
559 | - 'context' => array( 'view', 'edit' ), |
|
559 | + 'context' => array('view', 'edit'), |
|
560 | 560 | 'readonly' => true, |
561 | 561 | ), |
562 | 562 | ), |
563 | 563 | ); |
564 | 564 | |
565 | - return $this->add_additional_fields_schema( $schema ); |
|
565 | + return $this->add_additional_fields_schema($schema); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | */ |
573 | 573 | public function get_collection_params() { |
574 | 574 | return array( |
575 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
575 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
576 | 576 | ); |
577 | 577 | } |
578 | 578 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -41,43 +41,43 @@ discard block |
||
41 | 41 | * Register the routes for webhook deliveries. |
42 | 42 | */ |
43 | 43 | public function register_routes() { |
44 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
44 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
45 | 45 | 'args' => array( |
46 | 46 | 'webhook_id' => array( |
47 | - 'description' => __( 'Unique identifier for the webhook.', 'woocommerce' ), |
|
47 | + 'description' => __('Unique identifier for the webhook.', 'woocommerce'), |
|
48 | 48 | 'type' => 'integer', |
49 | 49 | ), |
50 | 50 | ), |
51 | 51 | array( |
52 | 52 | 'methods' => WP_REST_Server::READABLE, |
53 | - 'callback' => array( $this, 'get_items' ), |
|
54 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
53 | + 'callback' => array($this, 'get_items'), |
|
54 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
55 | 55 | 'args' => $this->get_collection_params(), |
56 | 56 | ), |
57 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
58 | - ) ); |
|
57 | + 'schema' => array($this, 'get_public_item_schema'), |
|
58 | + )); |
|
59 | 59 | |
60 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
60 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
61 | 61 | 'args' => array( |
62 | 62 | 'webhook_id' => array( |
63 | - 'description' => __( 'Unique identifier for the webhook.', 'woocommerce' ), |
|
63 | + 'description' => __('Unique identifier for the webhook.', 'woocommerce'), |
|
64 | 64 | 'type' => 'integer', |
65 | 65 | ), |
66 | 66 | 'id' => array( |
67 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
67 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
68 | 68 | 'type' => 'integer', |
69 | 69 | ), |
70 | 70 | ), |
71 | 71 | array( |
72 | 72 | 'methods' => WP_REST_Server::READABLE, |
73 | - 'callback' => array( $this, 'get_item' ), |
|
74 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
73 | + 'callback' => array($this, 'get_item'), |
|
74 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
75 | 75 | 'args' => array( |
76 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
76 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
77 | 77 | ), |
78 | 78 | ), |
79 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
80 | - ) ); |
|
79 | + 'schema' => array($this, 'get_public_item_schema'), |
|
80 | + )); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | * @param WP_REST_Request $request Full details about the request. |
87 | 87 | * @return WP_Error|boolean |
88 | 88 | */ |
89 | - public function get_items_permissions_check( $request ) { |
|
90 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) { |
|
91 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
89 | + public function get_items_permissions_check($request) { |
|
90 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) { |
|
91 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return true; |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @param WP_REST_Request $request Full details about the request. |
101 | 101 | * @return WP_Error|boolean |
102 | 102 | */ |
103 | - public function get_item_permissions_check( $request ) { |
|
104 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) { |
|
105 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
103 | + public function get_item_permissions_check($request) { |
|
104 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) { |
|
105 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return true; |
@@ -115,22 +115,22 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return array|WP_Error |
117 | 117 | */ |
118 | - public function get_items( $request ) { |
|
119 | - $webhook = wc_get_webhook( (int) $request['webhook_id'] ); |
|
118 | + public function get_items($request) { |
|
119 | + $webhook = wc_get_webhook((int) $request['webhook_id']); |
|
120 | 120 | |
121 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
122 | - return new WP_Error( 'woocommerce_rest_webhook_invalid_id', __( 'Invalid webhook ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
121 | + if (empty($webhook) || is_null($webhook)) { |
|
122 | + return new WP_Error('woocommerce_rest_webhook_invalid_id', __('Invalid webhook ID.', 'woocommerce'), array('status' => 404)); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $logs = array(); |
126 | 126 | $data = array(); |
127 | - foreach ( $logs as $log ) { |
|
128 | - $delivery = $this->prepare_item_for_response( (object) $log, $request ); |
|
129 | - $delivery = $this->prepare_response_for_collection( $delivery ); |
|
127 | + foreach ($logs as $log) { |
|
128 | + $delivery = $this->prepare_item_for_response((object) $log, $request); |
|
129 | + $delivery = $this->prepare_response_for_collection($delivery); |
|
130 | 130 | $data[] = $delivery; |
131 | 131 | } |
132 | 132 | |
133 | - return rest_ensure_response( $data ); |
|
133 | + return rest_ensure_response($data); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,22 +139,22 @@ discard block |
||
139 | 139 | * @param WP_REST_Request $request Full details about the request. |
140 | 140 | * @return WP_Error|WP_REST_Response |
141 | 141 | */ |
142 | - public function get_item( $request ) { |
|
142 | + public function get_item($request) { |
|
143 | 143 | $id = (int) $request['id']; |
144 | - $webhook = wc_get_webhook( (int) $request['webhook_id'] ); |
|
144 | + $webhook = wc_get_webhook((int) $request['webhook_id']); |
|
145 | 145 | |
146 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
147 | - return new WP_Error( 'woocommerce_rest_webhook_invalid_id', __( 'Invalid webhook ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
146 | + if (empty($webhook) || is_null($webhook)) { |
|
147 | + return new WP_Error('woocommerce_rest_webhook_invalid_id', __('Invalid webhook ID.', 'woocommerce'), array('status' => 404)); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | $log = array(); |
151 | 151 | |
152 | - if ( empty( $id ) || empty( $log ) ) { |
|
153 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
152 | + if (empty($id) || empty($log)) { |
|
153 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
154 | 154 | } |
155 | 155 | |
156 | - $delivery = $this->prepare_item_for_response( (object) $log, $request ); |
|
157 | - $response = rest_ensure_response( $delivery ); |
|
156 | + $delivery = $this->prepare_item_for_response((object) $log, $request); |
|
157 | + $response = rest_ensure_response($delivery); |
|
158 | 158 | |
159 | 159 | return $response; |
160 | 160 | } |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | * @param WP_REST_Request $request Request object. |
167 | 167 | * @return WP_REST_Response $response Response data. |
168 | 168 | */ |
169 | - public function prepare_item_for_response( $log, $request ) { |
|
169 | + public function prepare_item_for_response($log, $request) { |
|
170 | 170 | $data = (array) $log; |
171 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
172 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
173 | - $data = $this->filter_response_by_context( $data, $context ); |
|
171 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
172 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
173 | + $data = $this->filter_response_by_context($data, $context); |
|
174 | 174 | |
175 | 175 | // Wrap the data in a response object. |
176 | - $response = rest_ensure_response( $data ); |
|
176 | + $response = rest_ensure_response($data); |
|
177 | 177 | |
178 | - $response->add_links( $this->prepare_links( $log ) ); |
|
178 | + $response->add_links($this->prepare_links($log)); |
|
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Filter webhook delivery object returned from the REST API. |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @param stdClass $log Delivery log object used to create response. |
185 | 185 | * @param WP_REST_Request $request Request object. |
186 | 186 | */ |
187 | - return apply_filters( 'woocommerce_rest_prepare_webhook_delivery', $response, $log, $request ); |
|
187 | + return apply_filters('woocommerce_rest_prepare_webhook_delivery', $response, $log, $request); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -193,18 +193,18 @@ discard block |
||
193 | 193 | * @param stdClass $log Delivery log object. |
194 | 194 | * @return array Links for the given webhook delivery. |
195 | 195 | */ |
196 | - protected function prepare_links( $log ) { |
|
196 | + protected function prepare_links($log) { |
|
197 | 197 | $webhook_id = (int) $log->request_headers['X-WC-Webhook-ID']; |
198 | - $base = str_replace( '(?P<webhook_id>[\d]+)', $webhook_id, $this->rest_base ); |
|
198 | + $base = str_replace('(?P<webhook_id>[\d]+)', $webhook_id, $this->rest_base); |
|
199 | 199 | $links = array( |
200 | 200 | 'self' => array( |
201 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $log->id ) ), |
|
201 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $log->id)), |
|
202 | 202 | ), |
203 | 203 | 'collection' => array( |
204 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
204 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
205 | 205 | ), |
206 | 206 | 'up' => array( |
207 | - 'href' => rest_url( sprintf( '/%s/webhooks/%d', $this->namespace, $webhook_id ) ), |
|
207 | + 'href' => rest_url(sprintf('/%s/webhooks/%d', $this->namespace, $webhook_id)), |
|
208 | 208 | ), |
209 | 209 | ); |
210 | 210 | |
@@ -223,82 +223,82 @@ discard block |
||
223 | 223 | 'type' => 'object', |
224 | 224 | 'properties' => array( |
225 | 225 | 'id' => array( |
226 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
226 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
227 | 227 | 'type' => 'integer', |
228 | - 'context' => array( 'view' ), |
|
228 | + 'context' => array('view'), |
|
229 | 229 | 'readonly' => true, |
230 | 230 | ), |
231 | 231 | 'duration' => array( |
232 | - 'description' => __( 'The delivery duration, in seconds.', 'woocommerce' ), |
|
232 | + 'description' => __('The delivery duration, in seconds.', 'woocommerce'), |
|
233 | 233 | 'type' => 'string', |
234 | - 'context' => array( 'view' ), |
|
234 | + 'context' => array('view'), |
|
235 | 235 | 'readonly' => true, |
236 | 236 | ), |
237 | 237 | 'summary' => array( |
238 | - 'description' => __( 'A friendly summary of the response including the HTTP response code, message, and body.', 'woocommerce' ), |
|
238 | + 'description' => __('A friendly summary of the response including the HTTP response code, message, and body.', 'woocommerce'), |
|
239 | 239 | 'type' => 'string', |
240 | - 'context' => array( 'view' ), |
|
240 | + 'context' => array('view'), |
|
241 | 241 | 'readonly' => true, |
242 | 242 | ), |
243 | 243 | 'request_url' => array( |
244 | - 'description' => __( 'The URL where the webhook was delivered.', 'woocommerce' ), |
|
244 | + 'description' => __('The URL where the webhook was delivered.', 'woocommerce'), |
|
245 | 245 | 'type' => 'string', |
246 | 246 | 'format' => 'uri', |
247 | - 'context' => array( 'view' ), |
|
247 | + 'context' => array('view'), |
|
248 | 248 | 'readonly' => true, |
249 | 249 | ), |
250 | 250 | 'request_headers' => array( |
251 | - 'description' => __( 'Request headers.', 'woocommerce' ), |
|
251 | + 'description' => __('Request headers.', 'woocommerce'), |
|
252 | 252 | 'type' => 'array', |
253 | - 'context' => array( 'view' ), |
|
253 | + 'context' => array('view'), |
|
254 | 254 | 'readonly' => true, |
255 | 255 | 'items' => array( |
256 | 256 | 'type' => 'string', |
257 | 257 | ), |
258 | 258 | ), |
259 | 259 | 'request_body' => array( |
260 | - 'description' => __( 'Request body.', 'woocommerce' ), |
|
260 | + 'description' => __('Request body.', 'woocommerce'), |
|
261 | 261 | 'type' => 'string', |
262 | - 'context' => array( 'view' ), |
|
262 | + 'context' => array('view'), |
|
263 | 263 | 'readonly' => true, |
264 | 264 | ), |
265 | 265 | 'response_code' => array( |
266 | - 'description' => __( 'The HTTP response code from the receiving server.', 'woocommerce' ), |
|
266 | + 'description' => __('The HTTP response code from the receiving server.', 'woocommerce'), |
|
267 | 267 | 'type' => 'string', |
268 | - 'context' => array( 'view' ), |
|
268 | + 'context' => array('view'), |
|
269 | 269 | 'readonly' => true, |
270 | 270 | ), |
271 | 271 | 'response_message' => array( |
272 | - 'description' => __( 'The HTTP response message from the receiving server.', 'woocommerce' ), |
|
272 | + 'description' => __('The HTTP response message from the receiving server.', 'woocommerce'), |
|
273 | 273 | 'type' => 'string', |
274 | - 'context' => array( 'view' ), |
|
274 | + 'context' => array('view'), |
|
275 | 275 | 'readonly' => true, |
276 | 276 | ), |
277 | 277 | 'response_headers' => array( |
278 | - 'description' => __( 'Array of the response headers from the receiving server.', 'woocommerce' ), |
|
278 | + 'description' => __('Array of the response headers from the receiving server.', 'woocommerce'), |
|
279 | 279 | 'type' => 'array', |
280 | - 'context' => array( 'view' ), |
|
280 | + 'context' => array('view'), |
|
281 | 281 | 'readonly' => true, |
282 | 282 | 'items' => array( |
283 | 283 | 'type' => 'string', |
284 | 284 | ), |
285 | 285 | ), |
286 | 286 | 'response_body' => array( |
287 | - 'description' => __( 'The response body from the receiving server.', 'woocommerce' ), |
|
287 | + 'description' => __('The response body from the receiving server.', 'woocommerce'), |
|
288 | 288 | 'type' => 'string', |
289 | - 'context' => array( 'view' ), |
|
289 | + 'context' => array('view'), |
|
290 | 290 | 'readonly' => true, |
291 | 291 | ), |
292 | 292 | 'date_created' => array( |
293 | - 'description' => __( "The date the webhook delivery was logged, in the site's timezone.", 'woocommerce' ), |
|
293 | + 'description' => __("The date the webhook delivery was logged, in the site's timezone.", 'woocommerce'), |
|
294 | 294 | 'type' => 'date-time', |
295 | - 'context' => array( 'view', 'edit' ), |
|
295 | + 'context' => array('view', 'edit'), |
|
296 | 296 | 'readonly' => true, |
297 | 297 | ), |
298 | 298 | ), |
299 | 299 | ); |
300 | 300 | |
301 | - return $this->add_additional_fields_schema( $schema ); |
|
301 | + return $this->add_additional_fields_schema($schema); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function get_collection_params() { |
310 | 310 | return array( |
311 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
311 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
312 | 312 | ); |
313 | 313 | } |
314 | 314 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -40,89 +40,89 @@ discard block |
||
40 | 40 | * Register the routes for terms. |
41 | 41 | */ |
42 | 42 | public function register_routes() { |
43 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
43 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
44 | 44 | 'args' => array( |
45 | 45 | 'attribute_id' => array( |
46 | - 'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ), |
|
46 | + 'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'), |
|
47 | 47 | 'type' => 'integer', |
48 | 48 | ), |
49 | 49 | ), |
50 | 50 | array( |
51 | 51 | 'methods' => WP_REST_Server::READABLE, |
52 | - 'callback' => array( $this, 'get_items' ), |
|
53 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
52 | + 'callback' => array($this, 'get_items'), |
|
53 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
54 | 54 | 'args' => $this->get_collection_params(), |
55 | 55 | ), |
56 | 56 | array( |
57 | 57 | 'methods' => WP_REST_Server::CREATABLE, |
58 | - 'callback' => array( $this, 'create_item' ), |
|
59 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
60 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
58 | + 'callback' => array($this, 'create_item'), |
|
59 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
60 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
61 | 61 | 'name' => array( |
62 | 62 | 'type' => 'string', |
63 | - 'description' => __( 'Name for the resource.', 'woocommerce' ), |
|
63 | + 'description' => __('Name for the resource.', 'woocommerce'), |
|
64 | 64 | 'required' => true, |
65 | 65 | ), |
66 | - ) ), |
|
66 | + )), |
|
67 | 67 | ), |
68 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
68 | + 'schema' => array($this, 'get_public_item_schema'), |
|
69 | 69 | )); |
70 | 70 | |
71 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
71 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
72 | 72 | 'args' => array( |
73 | 73 | 'id' => array( |
74 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
74 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
75 | 75 | 'type' => 'integer', |
76 | 76 | ), |
77 | 77 | 'attribute_id' => array( |
78 | - 'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ), |
|
78 | + 'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'), |
|
79 | 79 | 'type' => 'integer', |
80 | 80 | ), |
81 | 81 | ), |
82 | 82 | array( |
83 | 83 | 'methods' => WP_REST_Server::READABLE, |
84 | - 'callback' => array( $this, 'get_item' ), |
|
85 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
84 | + 'callback' => array($this, 'get_item'), |
|
85 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
86 | 86 | 'args' => array( |
87 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
87 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
88 | 88 | ), |
89 | 89 | ), |
90 | 90 | array( |
91 | 91 | 'methods' => WP_REST_Server::EDITABLE, |
92 | - 'callback' => array( $this, 'update_item' ), |
|
93 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
94 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
92 | + 'callback' => array($this, 'update_item'), |
|
93 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
94 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
95 | 95 | ), |
96 | 96 | array( |
97 | 97 | 'methods' => WP_REST_Server::DELETABLE, |
98 | - 'callback' => array( $this, 'delete_item' ), |
|
99 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
98 | + 'callback' => array($this, 'delete_item'), |
|
99 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
100 | 100 | 'args' => array( |
101 | 101 | 'force' => array( |
102 | 102 | 'default' => false, |
103 | 103 | 'type' => 'boolean', |
104 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
104 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
105 | 105 | ), |
106 | 106 | ), |
107 | 107 | ), |
108 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
109 | - ) ); |
|
108 | + 'schema' => array($this, 'get_public_item_schema'), |
|
109 | + )); |
|
110 | 110 | |
111 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
111 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
112 | 112 | 'args' => array( |
113 | 113 | 'attribute_id' => array( |
114 | - 'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ), |
|
114 | + 'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'), |
|
115 | 115 | 'type' => 'integer', |
116 | 116 | ), |
117 | 117 | ), |
118 | 118 | array( |
119 | 119 | 'methods' => WP_REST_Server::EDITABLE, |
120 | - 'callback' => array( $this, 'batch_items' ), |
|
121 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
122 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
120 | + 'callback' => array($this, 'batch_items'), |
|
121 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
122 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
123 | 123 | ), |
124 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
125 | - ) ); |
|
124 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
125 | + )); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @param WP_REST_Request $request |
133 | 133 | * @return WP_REST_Response $response |
134 | 134 | */ |
135 | - public function prepare_item_for_response( $item, $request ) { |
|
135 | + public function prepare_item_for_response($item, $request) { |
|
136 | 136 | // Get term order. |
137 | - $menu_order = get_term_meta( $item->term_id, 'order_' . $this->taxonomy, true ); |
|
137 | + $menu_order = get_term_meta($item->term_id, 'order_' . $this->taxonomy, true); |
|
138 | 138 | |
139 | 139 | $data = array( |
140 | 140 | 'id' => (int) $item->term_id, |
@@ -145,13 +145,13 @@ discard block |
||
145 | 145 | 'count' => (int) $item->count, |
146 | 146 | ); |
147 | 147 | |
148 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
149 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
150 | - $data = $this->filter_response_by_context( $data, $context ); |
|
148 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
149 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
150 | + $data = $this->filter_response_by_context($data, $context); |
|
151 | 151 | |
152 | - $response = rest_ensure_response( $data ); |
|
152 | + $response = rest_ensure_response($data); |
|
153 | 153 | |
154 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
154 | + $response->add_links($this->prepare_links($item, $request)); |
|
155 | 155 | |
156 | 156 | /** |
157 | 157 | * Filter a term item returned from the API. |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param object $item The original term object. |
163 | 163 | * @param WP_REST_Request $request Request used to generate the response. |
164 | 164 | */ |
165 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
165 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,10 +172,10 @@ discard block |
||
172 | 172 | * @param WP_REST_Request $request |
173 | 173 | * @return bool|WP_Error |
174 | 174 | */ |
175 | - protected function update_term_meta_fields( $term, $request ) { |
|
175 | + protected function update_term_meta_fields($term, $request) { |
|
176 | 176 | $id = (int) $term->term_id; |
177 | 177 | |
178 | - update_term_meta( $id, 'order_' . $this->taxonomy, $request['menu_order'] ); |
|
178 | + update_term_meta($id, 'order_' . $this->taxonomy, $request['menu_order']); |
|
179 | 179 | |
180 | 180 | return true; |
181 | 181 | } |
@@ -192,49 +192,49 @@ discard block |
||
192 | 192 | 'type' => 'object', |
193 | 193 | 'properties' => array( |
194 | 194 | 'id' => array( |
195 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
195 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
196 | 196 | 'type' => 'integer', |
197 | - 'context' => array( 'view', 'edit' ), |
|
197 | + 'context' => array('view', 'edit'), |
|
198 | 198 | 'readonly' => true, |
199 | 199 | ), |
200 | 200 | 'name' => array( |
201 | - 'description' => __( 'Term name.', 'woocommerce' ), |
|
201 | + 'description' => __('Term name.', 'woocommerce'), |
|
202 | 202 | 'type' => 'string', |
203 | - 'context' => array( 'view', 'edit' ), |
|
203 | + 'context' => array('view', 'edit'), |
|
204 | 204 | 'arg_options' => array( |
205 | 205 | 'sanitize_callback' => 'sanitize_text_field', |
206 | 206 | ), |
207 | 207 | ), |
208 | 208 | 'slug' => array( |
209 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
209 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
210 | 210 | 'type' => 'string', |
211 | - 'context' => array( 'view', 'edit' ), |
|
211 | + 'context' => array('view', 'edit'), |
|
212 | 212 | 'arg_options' => array( |
213 | 213 | 'sanitize_callback' => 'sanitize_title', |
214 | 214 | ), |
215 | 215 | ), |
216 | 216 | 'description' => array( |
217 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
217 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
218 | 218 | 'type' => 'string', |
219 | - 'context' => array( 'view', 'edit' ), |
|
219 | + 'context' => array('view', 'edit'), |
|
220 | 220 | 'arg_options' => array( |
221 | 221 | 'sanitize_callback' => 'wp_filter_post_kses', |
222 | 222 | ), |
223 | 223 | ), |
224 | 224 | 'menu_order' => array( |
225 | - 'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ), |
|
225 | + 'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'), |
|
226 | 226 | 'type' => 'integer', |
227 | - 'context' => array( 'view', 'edit' ), |
|
227 | + 'context' => array('view', 'edit'), |
|
228 | 228 | ), |
229 | 229 | 'count' => array( |
230 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
230 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
231 | 231 | 'type' => 'integer', |
232 | - 'context' => array( 'view', 'edit' ), |
|
232 | + 'context' => array('view', 'edit'), |
|
233 | 233 | 'readonly' => true, |
234 | 234 | ), |
235 | 235 | ), |
236 | 236 | ); |
237 | 237 | |
238 | - return $this->add_additional_fields_schema( $schema ); |
|
238 | + return $this->add_additional_fields_schema($schema); |
|
239 | 239 | } |
240 | 240 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -47,80 +47,80 @@ discard block |
||
47 | 47 | * Coupons actions. |
48 | 48 | */ |
49 | 49 | public function __construct() { |
50 | - add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'query_args' ), 10, 2 ); |
|
50 | + add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'query_args'), 10, 2); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Register the routes for coupons. |
55 | 55 | */ |
56 | 56 | public function register_routes() { |
57 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
57 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
58 | 58 | array( |
59 | 59 | 'methods' => WP_REST_Server::READABLE, |
60 | - 'callback' => array( $this, 'get_items' ), |
|
61 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
60 | + 'callback' => array($this, 'get_items'), |
|
61 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
62 | 62 | 'args' => $this->get_collection_params(), |
63 | 63 | ), |
64 | 64 | array( |
65 | 65 | 'methods' => WP_REST_Server::CREATABLE, |
66 | - 'callback' => array( $this, 'create_item' ), |
|
67 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
68 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
66 | + 'callback' => array($this, 'create_item'), |
|
67 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
68 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
69 | 69 | 'code' => array( |
70 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
70 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
71 | 71 | 'required' => true, |
72 | 72 | 'type' => 'string', |
73 | 73 | ), |
74 | - ) ), |
|
74 | + )), |
|
75 | 75 | ), |
76 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
77 | - ) ); |
|
76 | + 'schema' => array($this, 'get_public_item_schema'), |
|
77 | + )); |
|
78 | 78 | |
79 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
79 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
80 | 80 | 'args' => array( |
81 | 81 | 'id' => array( |
82 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
82 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
83 | 83 | 'type' => 'integer', |
84 | 84 | ), |
85 | 85 | ), |
86 | 86 | array( |
87 | 87 | 'methods' => WP_REST_Server::READABLE, |
88 | - 'callback' => array( $this, 'get_item' ), |
|
89 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
88 | + 'callback' => array($this, 'get_item'), |
|
89 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
90 | 90 | 'args' => array( |
91 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
91 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
92 | 92 | ), |
93 | 93 | ), |
94 | 94 | array( |
95 | 95 | 'methods' => WP_REST_Server::EDITABLE, |
96 | - 'callback' => array( $this, 'update_item' ), |
|
97 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
98 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
96 | + 'callback' => array($this, 'update_item'), |
|
97 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
98 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
99 | 99 | ), |
100 | 100 | array( |
101 | 101 | 'methods' => WP_REST_Server::DELETABLE, |
102 | - 'callback' => array( $this, 'delete_item' ), |
|
103 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
102 | + 'callback' => array($this, 'delete_item'), |
|
103 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
104 | 104 | 'args' => array( |
105 | 105 | 'force' => array( |
106 | 106 | 'default' => false, |
107 | 107 | 'type' => 'boolean', |
108 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
108 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
109 | 109 | ), |
110 | 110 | ), |
111 | 111 | ), |
112 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
113 | - ) ); |
|
112 | + 'schema' => array($this, 'get_public_item_schema'), |
|
113 | + )); |
|
114 | 114 | |
115 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
115 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
116 | 116 | array( |
117 | 117 | 'methods' => WP_REST_Server::EDITABLE, |
118 | - 'callback' => array( $this, 'batch_items' ), |
|
119 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
120 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
118 | + 'callback' => array($this, 'batch_items'), |
|
119 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
120 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
121 | 121 | ), |
122 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
123 | - ) ); |
|
122 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
123 | + )); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -130,10 +130,10 @@ discard block |
||
130 | 130 | * @param WP_REST_Request $request Request data. |
131 | 131 | * @return array |
132 | 132 | */ |
133 | - public function query_args( $args, $request ) { |
|
134 | - if ( ! empty( $request['code'] ) ) { |
|
135 | - $id = wc_get_coupon_id_by_code( $request['code'] ); |
|
136 | - $args['post__in'] = array( $id ); |
|
133 | + public function query_args($args, $request) { |
|
134 | + if ( ! empty($request['code'])) { |
|
135 | + $id = wc_get_coupon_id_by_code($request['code']); |
|
136 | + $args['post__in'] = array($id); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $args; |
@@ -146,31 +146,31 @@ discard block |
||
146 | 146 | * @param WP_REST_Request $request Request object. |
147 | 147 | * @return WP_REST_Response $data |
148 | 148 | */ |
149 | - public function prepare_item_for_response( $post, $request ) { |
|
150 | - $coupon = new WC_Coupon( (int) $post->ID ); |
|
149 | + public function prepare_item_for_response($post, $request) { |
|
150 | + $coupon = new WC_Coupon((int) $post->ID); |
|
151 | 151 | $_data = $coupon->get_data(); |
152 | 152 | |
153 | - $format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' ); |
|
154 | - $format_date = array( 'date_created', 'date_modified' ); |
|
155 | - $format_date_utc = array( 'date_expires' ); |
|
156 | - $format_null = array( 'usage_limit', 'usage_limit_per_user' ); |
|
153 | + $format_decimal = array('amount', 'minimum_amount', 'maximum_amount'); |
|
154 | + $format_date = array('date_created', 'date_modified'); |
|
155 | + $format_date_utc = array('date_expires'); |
|
156 | + $format_null = array('usage_limit', 'usage_limit_per_user'); |
|
157 | 157 | |
158 | 158 | // Format decimal values. |
159 | - foreach ( $format_decimal as $key ) { |
|
160 | - $_data[ $key ] = wc_format_decimal( $_data[ $key ], 2 ); |
|
159 | + foreach ($format_decimal as $key) { |
|
160 | + $_data[$key] = wc_format_decimal($_data[$key], 2); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // Format date values. |
164 | - foreach ( $format_date as $key ) { |
|
165 | - $_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ], false ) : null; |
|
164 | + foreach ($format_date as $key) { |
|
165 | + $_data[$key] = $_data[$key] ? wc_rest_prepare_date_response($_data[$key], false) : null; |
|
166 | 166 | } |
167 | - foreach ( $format_date_utc as $key ) { |
|
168 | - $_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ] ) : null; |
|
167 | + foreach ($format_date_utc as $key) { |
|
168 | + $_data[$key] = $_data[$key] ? wc_rest_prepare_date_response($_data[$key]) : null; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Format null values. |
172 | - foreach ( $format_null as $key ) { |
|
173 | - $_data[ $key ] = $_data[ $key ] ? $_data[ $key ] : null; |
|
172 | + foreach ($format_null as $key) { |
|
173 | + $_data[$key] = $_data[$key] ? $_data[$key] : null; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | $data = array( |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | 'used_by' => $_data['used_by'], |
200 | 200 | ); |
201 | 201 | |
202 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
203 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
204 | - $data = $this->filter_response_by_context( $data, $context ); |
|
205 | - $response = rest_ensure_response( $data ); |
|
206 | - $response->add_links( $this->prepare_links( $post, $request ) ); |
|
202 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
203 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
204 | + $data = $this->filter_response_by_context($data, $context); |
|
205 | + $response = rest_ensure_response($data); |
|
206 | + $response->add_links($this->prepare_links($post, $request)); |
|
207 | 207 | |
208 | 208 | /** |
209 | 209 | * Filter the data for a response. |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @param WP_Post $post Post object. |
216 | 216 | * @param WP_REST_Request $request Request object. |
217 | 217 | */ |
218 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request ); |
|
218 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * @param array $schema |
224 | 224 | * @return bool |
225 | 225 | */ |
226 | - protected function filter_writable_props( $schema ) { |
|
227 | - return empty( $schema['readonly'] ); |
|
226 | + protected function filter_writable_props($schema) { |
|
227 | + return empty($schema['readonly']); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -233,53 +233,53 @@ discard block |
||
233 | 233 | * @param WP_REST_Request $request Request object. |
234 | 234 | * @return WP_Error|stdClass $data Post object. |
235 | 235 | */ |
236 | - protected function prepare_item_for_database( $request ) { |
|
237 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
238 | - $coupon = new WC_Coupon( $id ); |
|
236 | + protected function prepare_item_for_database($request) { |
|
237 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
238 | + $coupon = new WC_Coupon($id); |
|
239 | 239 | $schema = $this->get_item_schema(); |
240 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
240 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
241 | 241 | |
242 | 242 | // Update to schema to make compatible with CRUD schema. |
243 | - if ( $request['exclude_product_ids'] ) { |
|
243 | + if ($request['exclude_product_ids']) { |
|
244 | 244 | $request['excluded_product_ids'] = $request['exclude_product_ids']; |
245 | 245 | } |
246 | - if ( $request['expiry_date'] ) { |
|
246 | + if ($request['expiry_date']) { |
|
247 | 247 | $request['date_expires'] = $request['expiry_date']; |
248 | 248 | } |
249 | 249 | |
250 | 250 | // Validate required POST fields. |
251 | - if ( 'POST' === $request->get_method() && 0 === $coupon->get_id() ) { |
|
252 | - if ( empty( $request['code'] ) ) { |
|
253 | - return new WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) ); |
|
251 | + if ('POST' === $request->get_method() && 0 === $coupon->get_id()) { |
|
252 | + if (empty($request['code'])) { |
|
253 | + return new WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400)); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
257 | 257 | // Handle all writable props. |
258 | - foreach ( $data_keys as $key ) { |
|
259 | - $value = $request[ $key ]; |
|
258 | + foreach ($data_keys as $key) { |
|
259 | + $value = $request[$key]; |
|
260 | 260 | |
261 | - if ( ! is_null( $value ) ) { |
|
262 | - switch ( $key ) { |
|
261 | + if ( ! is_null($value)) { |
|
262 | + switch ($key) { |
|
263 | 263 | case 'code' : |
264 | - $coupon_code = wc_format_coupon_code( $value ); |
|
264 | + $coupon_code = wc_format_coupon_code($value); |
|
265 | 265 | $id = $coupon->get_id() ? $coupon->get_id() : 0; |
266 | - $id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id ); |
|
266 | + $id_from_code = wc_get_coupon_id_by_code($coupon_code, $id); |
|
267 | 267 | |
268 | - if ( $id_from_code ) { |
|
269 | - return new WP_Error( 'woocommerce_rest_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce' ), array( 'status' => 400 ) ); |
|
268 | + if ($id_from_code) { |
|
269 | + return new WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400)); |
|
270 | 270 | } |
271 | 271 | |
272 | - $coupon->set_code( $coupon_code ); |
|
272 | + $coupon->set_code($coupon_code); |
|
273 | 273 | break; |
274 | 274 | case 'description' : |
275 | - $coupon->set_description( wp_filter_post_kses( $value ) ); |
|
275 | + $coupon->set_description(wp_filter_post_kses($value)); |
|
276 | 276 | break; |
277 | 277 | case 'expiry_date' : |
278 | - $coupon->set_date_expires( $value ); |
|
278 | + $coupon->set_date_expires($value); |
|
279 | 279 | break; |
280 | 280 | default : |
281 | - if ( is_callable( array( $coupon, "set_{$key}" ) ) ) { |
|
282 | - $coupon->{"set_{$key}"}( $value ); |
|
281 | + if (is_callable(array($coupon, "set_{$key}"))) { |
|
282 | + $coupon->{"set_{$key}"}($value); |
|
283 | 283 | } |
284 | 284 | break; |
285 | 285 | } |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * @param WC_Coupon $coupon The coupon object. |
296 | 296 | * @param WP_REST_Request $request Request object. |
297 | 297 | */ |
298 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $coupon, $request ); |
|
298 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $coupon, $request); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -304,21 +304,21 @@ discard block |
||
304 | 304 | * @param WP_REST_Request $request Full details about the request. |
305 | 305 | * @return WP_Error|WP_REST_Response |
306 | 306 | */ |
307 | - public function create_item( $request ) { |
|
308 | - if ( ! empty( $request['id'] ) ) { |
|
307 | + public function create_item($request) { |
|
308 | + if ( ! empty($request['id'])) { |
|
309 | 309 | /* translators: %s: post type */ |
310 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
310 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
311 | 311 | } |
312 | 312 | |
313 | - $coupon_id = $this->save_coupon( $request ); |
|
314 | - if ( is_wp_error( $coupon_id ) ) { |
|
313 | + $coupon_id = $this->save_coupon($request); |
|
314 | + if (is_wp_error($coupon_id)) { |
|
315 | 315 | return $coupon_id; |
316 | 316 | } |
317 | 317 | |
318 | - $post = get_post( $coupon_id ); |
|
319 | - $this->update_additional_fields_for_object( $post, $request ); |
|
318 | + $post = get_post($coupon_id); |
|
319 | + $this->update_additional_fields_for_object($post, $request); |
|
320 | 320 | |
321 | - $this->add_post_meta_fields( $post, $request ); |
|
321 | + $this->add_post_meta_fields($post, $request); |
|
322 | 322 | |
323 | 323 | /** |
324 | 324 | * Fires after a single item is created or updated via the REST API. |
@@ -327,12 +327,12 @@ discard block |
||
327 | 327 | * @param WP_REST_Request $request Request object. |
328 | 328 | * @param boolean $creating True when creating item, false when updating. |
329 | 329 | */ |
330 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true ); |
|
331 | - $request->set_param( 'context', 'edit' ); |
|
332 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
333 | - $response = rest_ensure_response( $response ); |
|
334 | - $response->set_status( 201 ); |
|
335 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ) ); |
|
330 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true); |
|
331 | + $request->set_param('context', 'edit'); |
|
332 | + $response = $this->prepare_item_for_response($post, $request); |
|
333 | + $response = rest_ensure_response($response); |
|
334 | + $response->set_status(201); |
|
335 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID))); |
|
336 | 336 | |
337 | 337 | return $response; |
338 | 338 | } |
@@ -343,21 +343,21 @@ discard block |
||
343 | 343 | * @param WP_REST_Request $request Full details about the request. |
344 | 344 | * @return WP_Error|WP_REST_Response |
345 | 345 | */ |
346 | - public function update_item( $request ) { |
|
346 | + public function update_item($request) { |
|
347 | 347 | try { |
348 | 348 | $post_id = (int) $request['id']; |
349 | 349 | |
350 | - if ( empty( $post_id ) || get_post_type( $post_id ) !== $this->post_type ) { |
|
351 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
350 | + if (empty($post_id) || get_post_type($post_id) !== $this->post_type) { |
|
351 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
352 | 352 | } |
353 | 353 | |
354 | - $coupon_id = $this->save_coupon( $request ); |
|
355 | - if ( is_wp_error( $coupon_id ) ) { |
|
354 | + $coupon_id = $this->save_coupon($request); |
|
355 | + if (is_wp_error($coupon_id)) { |
|
356 | 356 | return $coupon_id; |
357 | 357 | } |
358 | 358 | |
359 | - $post = get_post( $coupon_id ); |
|
360 | - $this->update_additional_fields_for_object( $post, $request ); |
|
359 | + $post = get_post($coupon_id); |
|
360 | + $this->update_additional_fields_for_object($post, $request); |
|
361 | 361 | |
362 | 362 | /** |
363 | 363 | * Fires after a single item is created or updated via the REST API. |
@@ -366,13 +366,13 @@ discard block |
||
366 | 366 | * @param WP_REST_Request $request Request object. |
367 | 367 | * @param boolean $creating True when creating item, false when updating. |
368 | 368 | */ |
369 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, false ); |
|
370 | - $request->set_param( 'context', 'edit' ); |
|
371 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
372 | - return rest_ensure_response( $response ); |
|
369 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, false); |
|
370 | + $request->set_param('context', 'edit'); |
|
371 | + $response = $this->prepare_item_for_response($post, $request); |
|
372 | + return rest_ensure_response($response); |
|
373 | 373 | |
374 | - } catch ( Exception $e ) { |
|
375 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
374 | + } catch (Exception $e) { |
|
375 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
@@ -383,20 +383,20 @@ discard block |
||
383 | 383 | * @param WP_REST_Request $request Full details about the request. |
384 | 384 | * @return WP_Error|int |
385 | 385 | */ |
386 | - protected function save_coupon( $request ) { |
|
386 | + protected function save_coupon($request) { |
|
387 | 387 | try { |
388 | - $coupon = $this->prepare_item_for_database( $request ); |
|
388 | + $coupon = $this->prepare_item_for_database($request); |
|
389 | 389 | |
390 | - if ( is_wp_error( $coupon ) ) { |
|
390 | + if (is_wp_error($coupon)) { |
|
391 | 391 | return $coupon; |
392 | 392 | } |
393 | 393 | |
394 | 394 | $coupon->save(); |
395 | 395 | return $coupon->get_id(); |
396 | - } catch ( WC_Data_Exception $e ) { |
|
397 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
398 | - } catch ( WC_REST_Exception $e ) { |
|
399 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
396 | + } catch (WC_Data_Exception $e) { |
|
397 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData()); |
|
398 | + } catch (WC_REST_Exception $e) { |
|
399 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
@@ -412,152 +412,152 @@ discard block |
||
412 | 412 | 'type' => 'object', |
413 | 413 | 'properties' => array( |
414 | 414 | 'id' => array( |
415 | - 'description' => __( 'Unique identifier for the object.', 'woocommerce' ), |
|
415 | + 'description' => __('Unique identifier for the object.', 'woocommerce'), |
|
416 | 416 | 'type' => 'integer', |
417 | - 'context' => array( 'view', 'edit' ), |
|
417 | + 'context' => array('view', 'edit'), |
|
418 | 418 | 'readonly' => true, |
419 | 419 | ), |
420 | 420 | 'code' => array( |
421 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
421 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
422 | 422 | 'type' => 'string', |
423 | - 'context' => array( 'view', 'edit' ), |
|
423 | + 'context' => array('view', 'edit'), |
|
424 | 424 | ), |
425 | 425 | 'date_created' => array( |
426 | - 'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce' ), |
|
426 | + 'description' => __("The date the coupon was created, in the site's timezone.", 'woocommerce'), |
|
427 | 427 | 'type' => 'date-time', |
428 | - 'context' => array( 'view', 'edit' ), |
|
428 | + 'context' => array('view', 'edit'), |
|
429 | 429 | 'readonly' => true, |
430 | 430 | ), |
431 | 431 | 'date_modified' => array( |
432 | - 'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce' ), |
|
432 | + 'description' => __("The date the coupon was last modified, in the site's timezone.", 'woocommerce'), |
|
433 | 433 | 'type' => 'date-time', |
434 | - 'context' => array( 'view', 'edit' ), |
|
434 | + 'context' => array('view', 'edit'), |
|
435 | 435 | 'readonly' => true, |
436 | 436 | ), |
437 | 437 | 'description' => array( |
438 | - 'description' => __( 'Coupon description.', 'woocommerce' ), |
|
438 | + 'description' => __('Coupon description.', 'woocommerce'), |
|
439 | 439 | 'type' => 'string', |
440 | - 'context' => array( 'view', 'edit' ), |
|
440 | + 'context' => array('view', 'edit'), |
|
441 | 441 | ), |
442 | 442 | 'discount_type' => array( |
443 | - 'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ), |
|
443 | + 'description' => __('Determines the type of discount that will be applied.', 'woocommerce'), |
|
444 | 444 | 'type' => 'string', |
445 | 445 | 'default' => 'fixed_cart', |
446 | - 'enum' => array_keys( wc_get_coupon_types() ), |
|
447 | - 'context' => array( 'view', 'edit' ), |
|
446 | + 'enum' => array_keys(wc_get_coupon_types()), |
|
447 | + 'context' => array('view', 'edit'), |
|
448 | 448 | ), |
449 | 449 | 'amount' => array( |
450 | - 'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce' ), |
|
450 | + 'description' => __('The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce'), |
|
451 | 451 | 'type' => 'string', |
452 | - 'context' => array( 'view', 'edit' ), |
|
452 | + 'context' => array('view', 'edit'), |
|
453 | 453 | ), |
454 | 454 | 'expiry_date' => array( |
455 | - 'description' => __( 'UTC DateTime when the coupon expires.', 'woocommerce' ), |
|
455 | + 'description' => __('UTC DateTime when the coupon expires.', 'woocommerce'), |
|
456 | 456 | 'type' => 'string', |
457 | - 'context' => array( 'view', 'edit' ), |
|
457 | + 'context' => array('view', 'edit'), |
|
458 | 458 | ), |
459 | 459 | 'usage_count' => array( |
460 | - 'description' => __( 'Number of times the coupon has been used already.', 'woocommerce' ), |
|
460 | + 'description' => __('Number of times the coupon has been used already.', 'woocommerce'), |
|
461 | 461 | 'type' => 'integer', |
462 | - 'context' => array( 'view', 'edit' ), |
|
462 | + 'context' => array('view', 'edit'), |
|
463 | 463 | 'readonly' => true, |
464 | 464 | ), |
465 | 465 | 'individual_use' => array( |
466 | - 'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce' ), |
|
466 | + 'description' => __('If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce'), |
|
467 | 467 | 'type' => 'boolean', |
468 | 468 | 'default' => false, |
469 | - 'context' => array( 'view', 'edit' ), |
|
469 | + 'context' => array('view', 'edit'), |
|
470 | 470 | ), |
471 | 471 | 'product_ids' => array( |
472 | - 'description' => __( "List of product IDs the coupon can be used on.", 'woocommerce' ), |
|
472 | + 'description' => __("List of product IDs the coupon can be used on.", 'woocommerce'), |
|
473 | 473 | 'type' => 'array', |
474 | 474 | 'items' => array( |
475 | 475 | 'type' => 'integer', |
476 | 476 | ), |
477 | - 'context' => array( 'view', 'edit' ), |
|
477 | + 'context' => array('view', 'edit'), |
|
478 | 478 | ), |
479 | 479 | 'exclude_product_ids' => array( |
480 | - 'description' => __( "List of product IDs the coupon cannot be used on.", 'woocommerce' ), |
|
480 | + 'description' => __("List of product IDs the coupon cannot be used on.", 'woocommerce'), |
|
481 | 481 | 'type' => 'array', |
482 | 482 | 'items' => array( |
483 | 483 | 'type' => 'integer', |
484 | 484 | ), |
485 | - 'context' => array( 'view', 'edit' ), |
|
485 | + 'context' => array('view', 'edit'), |
|
486 | 486 | ), |
487 | 487 | 'usage_limit' => array( |
488 | - 'description' => __( 'How many times the coupon can be used in total.', 'woocommerce' ), |
|
488 | + 'description' => __('How many times the coupon can be used in total.', 'woocommerce'), |
|
489 | 489 | 'type' => 'integer', |
490 | - 'context' => array( 'view', 'edit' ), |
|
490 | + 'context' => array('view', 'edit'), |
|
491 | 491 | ), |
492 | 492 | 'usage_limit_per_user' => array( |
493 | - 'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce' ), |
|
493 | + 'description' => __('How many times the coupon can be used per customer.', 'woocommerce'), |
|
494 | 494 | 'type' => 'integer', |
495 | - 'context' => array( 'view', 'edit' ), |
|
495 | + 'context' => array('view', 'edit'), |
|
496 | 496 | ), |
497 | 497 | 'limit_usage_to_x_items' => array( |
498 | - 'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'woocommerce' ), |
|
498 | + 'description' => __('Max number of items in the cart the coupon can be applied to.', 'woocommerce'), |
|
499 | 499 | 'type' => 'integer', |
500 | - 'context' => array( 'view', 'edit' ), |
|
500 | + 'context' => array('view', 'edit'), |
|
501 | 501 | ), |
502 | 502 | 'free_shipping' => array( |
503 | - 'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce' ), |
|
503 | + 'description' => __('If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce'), |
|
504 | 504 | 'type' => 'boolean', |
505 | 505 | 'default' => false, |
506 | - 'context' => array( 'view', 'edit' ), |
|
506 | + 'context' => array('view', 'edit'), |
|
507 | 507 | ), |
508 | 508 | 'product_categories' => array( |
509 | - 'description' => __( "List of category IDs the coupon applies to.", 'woocommerce' ), |
|
509 | + 'description' => __("List of category IDs the coupon applies to.", 'woocommerce'), |
|
510 | 510 | 'type' => 'array', |
511 | 511 | 'items' => array( |
512 | 512 | 'type' => 'integer', |
513 | 513 | ), |
514 | - 'context' => array( 'view', 'edit' ), |
|
514 | + 'context' => array('view', 'edit'), |
|
515 | 515 | ), |
516 | 516 | 'excluded_product_categories' => array( |
517 | - 'description' => __( "List of category IDs the coupon does not apply to.", 'woocommerce' ), |
|
517 | + 'description' => __("List of category IDs the coupon does not apply to.", 'woocommerce'), |
|
518 | 518 | 'type' => 'array', |
519 | 519 | 'items' => array( |
520 | 520 | 'type' => 'integer', |
521 | 521 | ), |
522 | - 'context' => array( 'view', 'edit' ), |
|
522 | + 'context' => array('view', 'edit'), |
|
523 | 523 | ), |
524 | 524 | 'exclude_sale_items' => array( |
525 | - 'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'woocommerce' ), |
|
525 | + 'description' => __('If true, this coupon will not be applied to items that have sale prices.', 'woocommerce'), |
|
526 | 526 | 'type' => 'boolean', |
527 | 527 | 'default' => false, |
528 | - 'context' => array( 'view', 'edit' ), |
|
528 | + 'context' => array('view', 'edit'), |
|
529 | 529 | ), |
530 | 530 | 'minimum_amount' => array( |
531 | - 'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce' ), |
|
531 | + 'description' => __('Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce'), |
|
532 | 532 | 'type' => 'string', |
533 | - 'context' => array( 'view', 'edit' ), |
|
533 | + 'context' => array('view', 'edit'), |
|
534 | 534 | ), |
535 | 535 | 'maximum_amount' => array( |
536 | - 'description' => __( 'Maximum order amount allowed when using the coupon.', 'woocommerce' ), |
|
536 | + 'description' => __('Maximum order amount allowed when using the coupon.', 'woocommerce'), |
|
537 | 537 | 'type' => 'string', |
538 | - 'context' => array( 'view', 'edit' ), |
|
538 | + 'context' => array('view', 'edit'), |
|
539 | 539 | ), |
540 | 540 | 'email_restrictions' => array( |
541 | - 'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ), |
|
541 | + 'description' => __('List of email addresses that can use this coupon.', 'woocommerce'), |
|
542 | 542 | 'type' => 'array', |
543 | 543 | 'items' => array( |
544 | 544 | 'type' => 'string', |
545 | 545 | ), |
546 | - 'context' => array( 'view', 'edit' ), |
|
546 | + 'context' => array('view', 'edit'), |
|
547 | 547 | ), |
548 | 548 | 'used_by' => array( |
549 | - 'description' => __( 'List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce' ), |
|
549 | + 'description' => __('List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce'), |
|
550 | 550 | 'type' => 'array', |
551 | 551 | 'items' => array( |
552 | 552 | 'type' => 'integer', |
553 | 553 | ), |
554 | - 'context' => array( 'view', 'edit' ), |
|
554 | + 'context' => array('view', 'edit'), |
|
555 | 555 | 'readonly' => true, |
556 | 556 | ), |
557 | 557 | ), |
558 | 558 | ); |
559 | 559 | |
560 | - return $this->add_additional_fields_schema( $schema ); |
|
560 | + return $this->add_additional_fields_schema($schema); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | $params = parent::get_collection_params(); |
570 | 570 | |
571 | 571 | $params['code'] = array( |
572 | - 'description' => __( 'Limit result set to resources with a specific code.', 'woocommerce' ), |
|
572 | + 'description' => __('Limit result set to resources with a specific code.', 'woocommerce'), |
|
573 | 573 | 'type' => 'string', |
574 | 574 | 'sanitize_callback' => 'sanitize_text_field', |
575 | 575 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | * @param WP_REST_Request $request Request instance. |
51 | 51 | * @return WP_REST_Response |
52 | 52 | */ |
53 | - public function prepare_item_for_response( $item, $request ) { |
|
53 | + public function prepare_item_for_response($item, $request) { |
|
54 | 54 | // Get category display type. |
55 | - $display_type = get_term_meta( $item->term_id, 'display_type', true ); |
|
55 | + $display_type = get_term_meta($item->term_id, 'display_type', true); |
|
56 | 56 | |
57 | 57 | // Get category order. |
58 | - $menu_order = get_term_meta( $item->term_id, 'order', true ); |
|
58 | + $menu_order = get_term_meta($item->term_id, 'order', true); |
|
59 | 59 | |
60 | 60 | $data = array( |
61 | 61 | 'id' => (int) $item->term_id, |
@@ -70,27 +70,27 @@ discard block |
||
70 | 70 | ); |
71 | 71 | |
72 | 72 | // Get category image. |
73 | - $image_id = get_term_meta( $item->term_id, 'thumbnail_id', true ); |
|
74 | - if ( $image_id ) { |
|
75 | - $attachment = get_post( $image_id ); |
|
73 | + $image_id = get_term_meta($item->term_id, 'thumbnail_id', true); |
|
74 | + if ($image_id) { |
|
75 | + $attachment = get_post($image_id); |
|
76 | 76 | |
77 | 77 | $data['image'] = array( |
78 | 78 | 'id' => (int) $image_id, |
79 | - 'date_created' => wc_rest_prepare_date_response( $attachment->post_date_gmt ), |
|
80 | - 'date_modified' => wc_rest_prepare_date_response( $attachment->post_modified_gmt ), |
|
81 | - 'src' => wp_get_attachment_url( $image_id ), |
|
82 | - 'title' => get_the_title( $attachment ), |
|
83 | - 'alt' => get_post_meta( $image_id, '_wp_attachment_image_alt', true ), |
|
79 | + 'date_created' => wc_rest_prepare_date_response($attachment->post_date_gmt), |
|
80 | + 'date_modified' => wc_rest_prepare_date_response($attachment->post_modified_gmt), |
|
81 | + 'src' => wp_get_attachment_url($image_id), |
|
82 | + 'title' => get_the_title($attachment), |
|
83 | + 'alt' => get_post_meta($image_id, '_wp_attachment_image_alt', true), |
|
84 | 84 | ); |
85 | 85 | } |
86 | 86 | |
87 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
88 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
89 | - $data = $this->filter_response_by_context( $data, $context ); |
|
87 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
88 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
89 | + $data = $this->filter_response_by_context($data, $context); |
|
90 | 90 | |
91 | - $response = rest_ensure_response( $data ); |
|
91 | + $response = rest_ensure_response($data); |
|
92 | 92 | |
93 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
93 | + $response->add_links($this->prepare_links($item, $request)); |
|
94 | 94 | |
95 | 95 | /** |
96 | 96 | * Filter a term item returned from the API. |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param object $item The original term object. |
102 | 102 | * @param WP_REST_Request $request Request used to generate the response. |
103 | 103 | */ |
104 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
104 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -111,48 +111,48 @@ discard block |
||
111 | 111 | * @param WP_REST_Request $request Request instance. |
112 | 112 | * @return bool|WP_Error |
113 | 113 | */ |
114 | - protected function update_term_meta_fields( $term, $request ) { |
|
114 | + protected function update_term_meta_fields($term, $request) { |
|
115 | 115 | $id = (int) $term->term_id; |
116 | 116 | |
117 | - if ( isset( $request['display'] ) ) { |
|
118 | - update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] ); |
|
117 | + if (isset($request['display'])) { |
|
118 | + update_term_meta($id, 'display_type', 'default' === $request['display'] ? '' : $request['display']); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( isset( $request['menu_order'] ) ) { |
|
122 | - update_term_meta( $id, 'order', $request['menu_order'] ); |
|
121 | + if (isset($request['menu_order'])) { |
|
122 | + update_term_meta($id, 'order', $request['menu_order']); |
|
123 | 123 | } |
124 | 124 | |
125 | - if ( isset( $request['image'] ) ) { |
|
126 | - if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) { |
|
127 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) ); |
|
125 | + if (isset($request['image'])) { |
|
126 | + if (empty($request['image']['id']) && ! empty($request['image']['src'])) { |
|
127 | + $upload = wc_rest_upload_image_from_url(esc_url_raw($request['image']['src'])); |
|
128 | 128 | |
129 | - if ( is_wp_error( $upload ) ) { |
|
129 | + if (is_wp_error($upload)) { |
|
130 | 130 | return $upload; |
131 | 131 | } |
132 | 132 | |
133 | - $image_id = wc_rest_set_uploaded_image_as_attachment( $upload ); |
|
133 | + $image_id = wc_rest_set_uploaded_image_as_attachment($upload); |
|
134 | 134 | } else { |
135 | - $image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0; |
|
135 | + $image_id = isset($request['image']['id']) ? absint($request['image']['id']) : 0; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | // Check if image_id is a valid image attachment before updating the term meta. |
139 | - if ( $image_id && wp_attachment_is_image( $image_id ) ) { |
|
140 | - update_term_meta( $id, 'thumbnail_id', $image_id ); |
|
139 | + if ($image_id && wp_attachment_is_image($image_id)) { |
|
140 | + update_term_meta($id, 'thumbnail_id', $image_id); |
|
141 | 141 | |
142 | 142 | // Set the image alt. |
143 | - if ( ! empty( $request['image']['alt'] ) ) { |
|
144 | - update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) ); |
|
143 | + if ( ! empty($request['image']['alt'])) { |
|
144 | + update_post_meta($image_id, '_wp_attachment_image_alt', wc_clean($request['image']['alt'])); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | // Set the image title. |
148 | - if ( ! empty( $request['image']['title'] ) ) { |
|
149 | - wp_update_post( array( |
|
148 | + if ( ! empty($request['image']['title'])) { |
|
149 | + wp_update_post(array( |
|
150 | 150 | 'ID' => $image_id, |
151 | - 'post_title' => wc_clean( $request['image']['title'] ), |
|
152 | - ) ); |
|
151 | + 'post_title' => wc_clean($request['image']['title']), |
|
152 | + )); |
|
153 | 153 | } |
154 | 154 | } else { |
155 | - delete_term_meta( $id, 'thumbnail_id' ); |
|
155 | + delete_term_meta($id, 'thumbnail_id'); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
@@ -171,101 +171,101 @@ discard block |
||
171 | 171 | 'type' => 'object', |
172 | 172 | 'properties' => array( |
173 | 173 | 'id' => array( |
174 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
174 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
175 | 175 | 'type' => 'integer', |
176 | - 'context' => array( 'view', 'edit' ), |
|
176 | + 'context' => array('view', 'edit'), |
|
177 | 177 | 'readonly' => true, |
178 | 178 | ), |
179 | 179 | 'name' => array( |
180 | - 'description' => __( 'Category name.', 'woocommerce' ), |
|
180 | + 'description' => __('Category name.', 'woocommerce'), |
|
181 | 181 | 'type' => 'string', |
182 | - 'context' => array( 'view', 'edit' ), |
|
182 | + 'context' => array('view', 'edit'), |
|
183 | 183 | 'arg_options' => array( |
184 | 184 | 'sanitize_callback' => 'sanitize_text_field', |
185 | 185 | ), |
186 | 186 | ), |
187 | 187 | 'slug' => array( |
188 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
188 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
189 | 189 | 'type' => 'string', |
190 | - 'context' => array( 'view', 'edit' ), |
|
190 | + 'context' => array('view', 'edit'), |
|
191 | 191 | 'arg_options' => array( |
192 | 192 | 'sanitize_callback' => 'sanitize_title', |
193 | 193 | ), |
194 | 194 | ), |
195 | 195 | 'parent' => array( |
196 | - 'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ), |
|
196 | + 'description' => __('The ID for the parent of the resource.', 'woocommerce'), |
|
197 | 197 | 'type' => 'integer', |
198 | - 'context' => array( 'view', 'edit' ), |
|
198 | + 'context' => array('view', 'edit'), |
|
199 | 199 | ), |
200 | 200 | 'description' => array( |
201 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
201 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
202 | 202 | 'type' => 'string', |
203 | - 'context' => array( 'view', 'edit' ), |
|
203 | + 'context' => array('view', 'edit'), |
|
204 | 204 | 'arg_options' => array( |
205 | 205 | 'sanitize_callback' => 'wp_filter_post_kses', |
206 | 206 | ), |
207 | 207 | ), |
208 | 208 | 'display' => array( |
209 | - 'description' => __( 'Category archive display type.', 'woocommerce' ), |
|
209 | + 'description' => __('Category archive display type.', 'woocommerce'), |
|
210 | 210 | 'type' => 'string', |
211 | 211 | 'default' => 'default', |
212 | - 'enum' => array( 'default', 'products', 'subcategories', 'both' ), |
|
213 | - 'context' => array( 'view', 'edit' ), |
|
212 | + 'enum' => array('default', 'products', 'subcategories', 'both'), |
|
213 | + 'context' => array('view', 'edit'), |
|
214 | 214 | ), |
215 | 215 | 'image' => array( |
216 | - 'description' => __( 'Image data.', 'woocommerce' ), |
|
216 | + 'description' => __('Image data.', 'woocommerce'), |
|
217 | 217 | 'type' => 'object', |
218 | - 'context' => array( 'view', 'edit' ), |
|
218 | + 'context' => array('view', 'edit'), |
|
219 | 219 | 'properties' => array( |
220 | 220 | 'id' => array( |
221 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
221 | + 'description' => __('Image ID.', 'woocommerce'), |
|
222 | 222 | 'type' => 'integer', |
223 | - 'context' => array( 'view', 'edit' ), |
|
223 | + 'context' => array('view', 'edit'), |
|
224 | 224 | ), |
225 | 225 | 'date_created' => array( |
226 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
226 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
227 | 227 | 'type' => 'date-time', |
228 | - 'context' => array( 'view', 'edit' ), |
|
228 | + 'context' => array('view', 'edit'), |
|
229 | 229 | 'readonly' => true, |
230 | 230 | ), |
231 | 231 | 'date_modified' => array( |
232 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
232 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
233 | 233 | 'type' => 'date-time', |
234 | - 'context' => array( 'view', 'edit' ), |
|
234 | + 'context' => array('view', 'edit'), |
|
235 | 235 | 'readonly' => true, |
236 | 236 | ), |
237 | 237 | 'src' => array( |
238 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
238 | + 'description' => __('Image URL.', 'woocommerce'), |
|
239 | 239 | 'type' => 'string', |
240 | 240 | 'format' => 'uri', |
241 | - 'context' => array( 'view', 'edit' ), |
|
241 | + 'context' => array('view', 'edit'), |
|
242 | 242 | ), |
243 | 243 | 'title' => array( |
244 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
244 | + 'description' => __('Image name.', 'woocommerce'), |
|
245 | 245 | 'type' => 'string', |
246 | - 'context' => array( 'view', 'edit' ), |
|
246 | + 'context' => array('view', 'edit'), |
|
247 | 247 | ), |
248 | 248 | 'alt' => array( |
249 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
249 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
250 | 250 | 'type' => 'string', |
251 | - 'context' => array( 'view', 'edit' ), |
|
251 | + 'context' => array('view', 'edit'), |
|
252 | 252 | ), |
253 | 253 | ), |
254 | 254 | ), |
255 | 255 | 'menu_order' => array( |
256 | - 'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ), |
|
256 | + 'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'), |
|
257 | 257 | 'type' => 'integer', |
258 | - 'context' => array( 'view', 'edit' ), |
|
258 | + 'context' => array('view', 'edit'), |
|
259 | 259 | ), |
260 | 260 | 'count' => array( |
261 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
261 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
262 | 262 | 'type' => 'integer', |
263 | - 'context' => array( 'view', 'edit' ), |
|
263 | + 'context' => array('view', 'edit'), |
|
264 | 264 | 'readonly' => true, |
265 | 265 | ), |
266 | 266 | ), |
267 | 267 | ); |
268 | 268 | |
269 | - return $this->add_additional_fields_schema( $schema ); |
|
269 | + return $this->add_additional_fields_schema($schema); |
|
270 | 270 | } |
271 | 271 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API variations controller class. |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * Initialize product actions (parent). |
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | - add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'add_product_id' ), 9, 2 ); |
|
46 | + add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'add_product_id'), 9, 2); |
|
47 | 47 | parent::__construct(); |
48 | 48 | } |
49 | 49 | |
@@ -55,41 +55,41 @@ discard block |
||
55 | 55 | $this->namespace, '/' . $this->rest_base, array( |
56 | 56 | 'args' => array( |
57 | 57 | 'product_id' => array( |
58 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
58 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
59 | 59 | 'type' => 'integer', |
60 | 60 | ), |
61 | 61 | ), |
62 | 62 | array( |
63 | 63 | 'methods' => WP_REST_Server::READABLE, |
64 | - 'callback' => array( $this, 'get_items' ), |
|
65 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
64 | + 'callback' => array($this, 'get_items'), |
|
65 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
66 | 66 | 'args' => $this->get_collection_params(), |
67 | 67 | ), |
68 | 68 | array( |
69 | 69 | 'methods' => WP_REST_Server::CREATABLE, |
70 | - 'callback' => array( $this, 'create_item' ), |
|
71 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
72 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
70 | + 'callback' => array($this, 'create_item'), |
|
71 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
72 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
73 | 73 | ), |
74 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
74 | + 'schema' => array($this, 'get_public_item_schema'), |
|
75 | 75 | ) |
76 | 76 | ); |
77 | 77 | register_rest_route( |
78 | 78 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
79 | 79 | 'args' => array( |
80 | 80 | 'product_id' => array( |
81 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
81 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
82 | 82 | 'type' => 'integer', |
83 | 83 | ), |
84 | 84 | 'id' => array( |
85 | - 'description' => __( 'Unique identifier for the variation.', 'woocommerce' ), |
|
85 | + 'description' => __('Unique identifier for the variation.', 'woocommerce'), |
|
86 | 86 | 'type' => 'integer', |
87 | 87 | ), |
88 | 88 | ), |
89 | 89 | array( |
90 | 90 | 'methods' => WP_REST_Server::READABLE, |
91 | - 'callback' => array( $this, 'get_item' ), |
|
92 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
91 | + 'callback' => array($this, 'get_item'), |
|
92 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
93 | 93 | 'args' => array( |
94 | 94 | 'context' => $this->get_context_param( |
95 | 95 | array( |
@@ -100,40 +100,40 @@ discard block |
||
100 | 100 | ), |
101 | 101 | array( |
102 | 102 | 'methods' => WP_REST_Server::EDITABLE, |
103 | - 'callback' => array( $this, 'update_item' ), |
|
104 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
105 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
103 | + 'callback' => array($this, 'update_item'), |
|
104 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
105 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
106 | 106 | ), |
107 | 107 | array( |
108 | 108 | 'methods' => WP_REST_Server::DELETABLE, |
109 | - 'callback' => array( $this, 'delete_item' ), |
|
110 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
109 | + 'callback' => array($this, 'delete_item'), |
|
110 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
111 | 111 | 'args' => array( |
112 | 112 | 'force' => array( |
113 | 113 | 'default' => false, |
114 | 114 | 'type' => 'boolean', |
115 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
115 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
116 | 116 | ), |
117 | 117 | ), |
118 | 118 | ), |
119 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
119 | + 'schema' => array($this, 'get_public_item_schema'), |
|
120 | 120 | ) |
121 | 121 | ); |
122 | 122 | register_rest_route( |
123 | 123 | $this->namespace, '/' . $this->rest_base . '/batch', array( |
124 | 124 | 'args' => array( |
125 | 125 | 'product_id' => array( |
126 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
126 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
127 | 127 | 'type' => 'integer', |
128 | 128 | ), |
129 | 129 | ), |
130 | 130 | array( |
131 | 131 | 'methods' => WP_REST_Server::EDITABLE, |
132 | - 'callback' => array( $this, 'batch_items' ), |
|
133 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
134 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
132 | + 'callback' => array($this, 'batch_items'), |
|
133 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
134 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
135 | 135 | ), |
136 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
136 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | } |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | * @param int $id Object ID. |
146 | 146 | * @return WC_Data |
147 | 147 | */ |
148 | - protected function get_object( $id ) { |
|
149 | - return wc_get_product( $id ); |
|
148 | + protected function get_object($id) { |
|
149 | + return wc_get_product($id); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | * @param WP_REST_Request $request Full details about the request. |
156 | 156 | * @return WP_Error|boolean |
157 | 157 | */ |
158 | - public function update_item_permissions_check( $request ) { |
|
159 | - $object = $this->get_object( (int) $request['id'] ); |
|
158 | + public function update_item_permissions_check($request) { |
|
159 | + $object = $this->get_object((int) $request['id']); |
|
160 | 160 | |
161 | - if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) { |
|
162 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
161 | + if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'edit', $object->get_id())) { |
|
162 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // Check if variation belongs to the correct parent product. |
166 | - if ( $object && 0 !== $object->get_parent_id() && absint( $request['product_id'] ) !== $object->get_parent_id() ) { |
|
167 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Parent product does not match current variation.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
166 | + if ($object && 0 !== $object->get_parent_id() && absint($request['product_id']) !== $object->get_parent_id()) { |
|
167 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Parent product does not match current variation.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | return true; |
@@ -178,29 +178,29 @@ discard block |
||
178 | 178 | * @param WP_REST_Request $request Request object. |
179 | 179 | * @return WP_REST_Response |
180 | 180 | */ |
181 | - public function prepare_object_for_response( $object, $request ) { |
|
181 | + public function prepare_object_for_response($object, $request) { |
|
182 | 182 | $data = array( |
183 | 183 | 'id' => $object->get_id(), |
184 | - 'date_created' => wc_rest_prepare_date_response( $object->get_date_created(), false ), |
|
185 | - 'date_created_gmt' => wc_rest_prepare_date_response( $object->get_date_created() ), |
|
186 | - 'date_modified' => wc_rest_prepare_date_response( $object->get_date_modified(), false ), |
|
187 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $object->get_date_modified() ), |
|
188 | - 'description' => wc_format_content( $object->get_description() ), |
|
184 | + 'date_created' => wc_rest_prepare_date_response($object->get_date_created(), false), |
|
185 | + 'date_created_gmt' => wc_rest_prepare_date_response($object->get_date_created()), |
|
186 | + 'date_modified' => wc_rest_prepare_date_response($object->get_date_modified(), false), |
|
187 | + 'date_modified_gmt' => wc_rest_prepare_date_response($object->get_date_modified()), |
|
188 | + 'description' => wc_format_content($object->get_description()), |
|
189 | 189 | 'permalink' => $object->get_permalink(), |
190 | 190 | 'sku' => $object->get_sku(), |
191 | 191 | 'price' => $object->get_price(), |
192 | 192 | 'regular_price' => $object->get_regular_price(), |
193 | 193 | 'sale_price' => $object->get_sale_price(), |
194 | - 'date_on_sale_from' => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ), |
|
195 | - 'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ), |
|
196 | - 'date_on_sale_to' => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ), |
|
197 | - 'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ), |
|
194 | + 'date_on_sale_from' => wc_rest_prepare_date_response($object->get_date_on_sale_from(), false), |
|
195 | + 'date_on_sale_from_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_from()), |
|
196 | + 'date_on_sale_to' => wc_rest_prepare_date_response($object->get_date_on_sale_to(), false), |
|
197 | + 'date_on_sale_to_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_to()), |
|
198 | 198 | 'on_sale' => $object->is_on_sale(), |
199 | 199 | 'visible' => $object->is_visible(), |
200 | 200 | 'purchasable' => $object->is_purchasable(), |
201 | 201 | 'virtual' => $object->is_virtual(), |
202 | 202 | 'downloadable' => $object->is_downloadable(), |
203 | - 'downloads' => $this->get_downloads( $object ), |
|
203 | + 'downloads' => $this->get_downloads($object), |
|
204 | 204 | 'download_limit' => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1, |
205 | 205 | 'download_expiry' => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1, |
206 | 206 | 'tax_status' => $object->get_tax_status(), |
@@ -219,17 +219,17 @@ discard block |
||
219 | 219 | ), |
220 | 220 | 'shipping_class' => $object->get_shipping_class(), |
221 | 221 | 'shipping_class_id' => $object->get_shipping_class_id(), |
222 | - 'image' => current( $this->get_images( $object ) ), |
|
223 | - 'attributes' => $this->get_attributes( $object ), |
|
222 | + 'image' => current($this->get_images($object)), |
|
223 | + 'attributes' => $this->get_attributes($object), |
|
224 | 224 | 'menu_order' => $object->get_menu_order(), |
225 | 225 | 'meta_data' => $object->get_meta_data(), |
226 | 226 | ); |
227 | 227 | |
228 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
229 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
230 | - $data = $this->filter_response_by_context( $data, $context ); |
|
231 | - $response = rest_ensure_response( $data ); |
|
232 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
228 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
229 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
230 | + $data = $this->filter_response_by_context($data, $context); |
|
231 | + $response = rest_ensure_response($data); |
|
232 | + $response->add_links($this->prepare_links($object, $request)); |
|
233 | 233 | |
234 | 234 | /** |
235 | 235 | * Filter the data for a response. |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @param WC_Data $object Object data. |
242 | 242 | * @param WP_REST_Request $request Request object. |
243 | 243 | */ |
244 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
244 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * @param WP_REST_Request $request Full details about the request. |
252 | 252 | * @return array |
253 | 253 | */ |
254 | - protected function prepare_objects_query( $request ) { |
|
255 | - $args = parent::prepare_objects_query( $request ); |
|
254 | + protected function prepare_objects_query($request) { |
|
255 | + $args = parent::prepare_objects_query($request); |
|
256 | 256 | |
257 | 257 | $args['post_parent'] = $request['product_id']; |
258 | 258 | |
@@ -266,196 +266,196 @@ discard block |
||
266 | 266 | * @param bool $creating If is creating a new object. |
267 | 267 | * @return WP_Error|WC_Data |
268 | 268 | */ |
269 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
270 | - if ( isset( $request['id'] ) ) { |
|
271 | - $variation = wc_get_product( absint( $request['id'] ) ); |
|
269 | + protected function prepare_object_for_database($request, $creating = false) { |
|
270 | + if (isset($request['id'])) { |
|
271 | + $variation = wc_get_product(absint($request['id'])); |
|
272 | 272 | } else { |
273 | 273 | $variation = new WC_Product_Variation(); |
274 | 274 | } |
275 | 275 | |
276 | 276 | // Update parent ID just once. |
277 | - if ( 0 === $variation->get_parent_id() ) { |
|
278 | - $variation->set_parent_id( absint( $request['product_id'] ) ); |
|
277 | + if (0 === $variation->get_parent_id()) { |
|
278 | + $variation->set_parent_id(absint($request['product_id'])); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | // Status. |
282 | - if ( isset( $request['visible'] ) ) { |
|
283 | - $variation->set_status( false === $request['visible'] ? 'private' : 'publish' ); |
|
282 | + if (isset($request['visible'])) { |
|
283 | + $variation->set_status(false === $request['visible'] ? 'private' : 'publish'); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // SKU. |
287 | - if ( isset( $request['sku'] ) ) { |
|
288 | - $variation->set_sku( wc_clean( $request['sku'] ) ); |
|
287 | + if (isset($request['sku'])) { |
|
288 | + $variation->set_sku(wc_clean($request['sku'])); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | // Thumbnail. |
292 | - if ( isset( $request['image'] ) ) { |
|
293 | - if ( is_array( $request['image'] ) && ! empty( $request['image'] ) ) { |
|
292 | + if (isset($request['image'])) { |
|
293 | + if (is_array($request['image']) && ! empty($request['image'])) { |
|
294 | 294 | $image = $request['image']; |
295 | - if ( is_array( $image ) ) { |
|
295 | + if (is_array($image)) { |
|
296 | 296 | $image['position'] = 0; |
297 | 297 | } |
298 | 298 | |
299 | - $variation = $this->set_product_images( $variation, array( $image ) ); |
|
299 | + $variation = $this->set_product_images($variation, array($image)); |
|
300 | 300 | } else { |
301 | - $variation->set_image_id( '' ); |
|
301 | + $variation->set_image_id(''); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | 305 | // Virtual variation. |
306 | - if ( isset( $request['virtual'] ) ) { |
|
307 | - $variation->set_virtual( $request['virtual'] ); |
|
306 | + if (isset($request['virtual'])) { |
|
307 | + $variation->set_virtual($request['virtual']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // Downloadable variation. |
311 | - if ( isset( $request['downloadable'] ) ) { |
|
312 | - $variation->set_downloadable( $request['downloadable'] ); |
|
311 | + if (isset($request['downloadable'])) { |
|
312 | + $variation->set_downloadable($request['downloadable']); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | // Downloads. |
316 | - if ( $variation->get_downloadable() ) { |
|
316 | + if ($variation->get_downloadable()) { |
|
317 | 317 | // Downloadable files. |
318 | - if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) { |
|
319 | - $variation = $this->save_downloadable_files( $variation, $request['downloads'] ); |
|
318 | + if (isset($request['downloads']) && is_array($request['downloads'])) { |
|
319 | + $variation = $this->save_downloadable_files($variation, $request['downloads']); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | // Download limit. |
323 | - if ( isset( $request['download_limit'] ) ) { |
|
324 | - $variation->set_download_limit( $request['download_limit'] ); |
|
323 | + if (isset($request['download_limit'])) { |
|
324 | + $variation->set_download_limit($request['download_limit']); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | // Download expiry. |
328 | - if ( isset( $request['download_expiry'] ) ) { |
|
329 | - $variation->set_download_expiry( $request['download_expiry'] ); |
|
328 | + if (isset($request['download_expiry'])) { |
|
329 | + $variation->set_download_expiry($request['download_expiry']); |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 | |
333 | 333 | // Shipping data. |
334 | - $variation = $this->save_product_shipping_data( $variation, $request ); |
|
334 | + $variation = $this->save_product_shipping_data($variation, $request); |
|
335 | 335 | |
336 | 336 | // Stock handling. |
337 | - if ( isset( $request['manage_stock'] ) ) { |
|
338 | - if ( 'parent' === $request['manage_stock'] ) { |
|
339 | - $variation->set_manage_stock( false ); // This just indicates the variation does not manage stock, but the parent does. |
|
337 | + if (isset($request['manage_stock'])) { |
|
338 | + if ('parent' === $request['manage_stock']) { |
|
339 | + $variation->set_manage_stock(false); // This just indicates the variation does not manage stock, but the parent does. |
|
340 | 340 | } else { |
341 | - $variation->set_manage_stock( wc_string_to_bool( $request['manage_stock'] ) ); |
|
341 | + $variation->set_manage_stock(wc_string_to_bool($request['manage_stock'])); |
|
342 | 342 | } |
343 | 343 | } |
344 | 344 | |
345 | - if ( isset( $request['in_stock'] ) ) { |
|
346 | - $variation->set_stock_status( true === $request['in_stock'] ? 'instock' : 'outofstock' ); |
|
345 | + if (isset($request['in_stock'])) { |
|
346 | + $variation->set_stock_status(true === $request['in_stock'] ? 'instock' : 'outofstock'); |
|
347 | 347 | } |
348 | 348 | |
349 | - if ( isset( $request['backorders'] ) ) { |
|
350 | - $variation->set_backorders( $request['backorders'] ); |
|
349 | + if (isset($request['backorders'])) { |
|
350 | + $variation->set_backorders($request['backorders']); |
|
351 | 351 | } |
352 | 352 | |
353 | - if ( $variation->get_manage_stock() ) { |
|
354 | - if ( isset( $request['stock_quantity'] ) ) { |
|
355 | - $variation->set_stock_quantity( $request['stock_quantity'] ); |
|
356 | - } elseif ( isset( $request['inventory_delta'] ) ) { |
|
357 | - $stock_quantity = wc_stock_amount( $variation->get_stock_quantity() ); |
|
358 | - $stock_quantity += wc_stock_amount( $request['inventory_delta'] ); |
|
359 | - $variation->set_stock_quantity( $stock_quantity ); |
|
353 | + if ($variation->get_manage_stock()) { |
|
354 | + if (isset($request['stock_quantity'])) { |
|
355 | + $variation->set_stock_quantity($request['stock_quantity']); |
|
356 | + } elseif (isset($request['inventory_delta'])) { |
|
357 | + $stock_quantity = wc_stock_amount($variation->get_stock_quantity()); |
|
358 | + $stock_quantity += wc_stock_amount($request['inventory_delta']); |
|
359 | + $variation->set_stock_quantity($stock_quantity); |
|
360 | 360 | } |
361 | 361 | } else { |
362 | - $variation->set_backorders( 'no' ); |
|
363 | - $variation->set_stock_quantity( '' ); |
|
362 | + $variation->set_backorders('no'); |
|
363 | + $variation->set_stock_quantity(''); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | // Regular Price. |
367 | - if ( isset( $request['regular_price'] ) ) { |
|
368 | - $variation->set_regular_price( $request['regular_price'] ); |
|
367 | + if (isset($request['regular_price'])) { |
|
368 | + $variation->set_regular_price($request['regular_price']); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | // Sale Price. |
372 | - if ( isset( $request['sale_price'] ) ) { |
|
373 | - $variation->set_sale_price( $request['sale_price'] ); |
|
372 | + if (isset($request['sale_price'])) { |
|
373 | + $variation->set_sale_price($request['sale_price']); |
|
374 | 374 | } |
375 | 375 | |
376 | - if ( isset( $request['date_on_sale_from'] ) ) { |
|
377 | - $variation->set_date_on_sale_from( $request['date_on_sale_from'] ); |
|
376 | + if (isset($request['date_on_sale_from'])) { |
|
377 | + $variation->set_date_on_sale_from($request['date_on_sale_from']); |
|
378 | 378 | } |
379 | 379 | |
380 | - if ( isset( $request['date_on_sale_from_gmt'] ) ) { |
|
381 | - $variation->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null ); |
|
380 | + if (isset($request['date_on_sale_from_gmt'])) { |
|
381 | + $variation->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null); |
|
382 | 382 | } |
383 | 383 | |
384 | - if ( isset( $request['date_on_sale_to'] ) ) { |
|
385 | - $variation->set_date_on_sale_to( $request['date_on_sale_to'] ); |
|
384 | + if (isset($request['date_on_sale_to'])) { |
|
385 | + $variation->set_date_on_sale_to($request['date_on_sale_to']); |
|
386 | 386 | } |
387 | 387 | |
388 | - if ( isset( $request['date_on_sale_to_gmt'] ) ) { |
|
389 | - $variation->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null ); |
|
388 | + if (isset($request['date_on_sale_to_gmt'])) { |
|
389 | + $variation->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | // Tax class. |
393 | - if ( isset( $request['tax_class'] ) ) { |
|
394 | - $variation->set_tax_class( $request['tax_class'] ); |
|
393 | + if (isset($request['tax_class'])) { |
|
394 | + $variation->set_tax_class($request['tax_class']); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | // Description. |
398 | - if ( isset( $request['description'] ) ) { |
|
399 | - $variation->set_description( wp_kses_post( $request['description'] ) ); |
|
398 | + if (isset($request['description'])) { |
|
399 | + $variation->set_description(wp_kses_post($request['description'])); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | // Update taxonomies. |
403 | - if ( isset( $request['attributes'] ) ) { |
|
403 | + if (isset($request['attributes'])) { |
|
404 | 404 | $attributes = array(); |
405 | - $parent = wc_get_product( $variation->get_parent_id() ); |
|
405 | + $parent = wc_get_product($variation->get_parent_id()); |
|
406 | 406 | $parent_attributes = $parent->get_attributes(); |
407 | 407 | |
408 | - foreach ( $request['attributes'] as $attribute ) { |
|
408 | + foreach ($request['attributes'] as $attribute) { |
|
409 | 409 | $attribute_id = 0; |
410 | 410 | $attribute_name = ''; |
411 | 411 | |
412 | 412 | // Check ID for global attributes or name for product attributes. |
413 | - if ( ! empty( $attribute['id'] ) ) { |
|
414 | - $attribute_id = absint( $attribute['id'] ); |
|
415 | - $raw_attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
|
416 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
417 | - $raw_attribute_name = sanitize_title( $attribute['name'] ); |
|
413 | + if ( ! empty($attribute['id'])) { |
|
414 | + $attribute_id = absint($attribute['id']); |
|
415 | + $raw_attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id); |
|
416 | + } elseif ( ! empty($attribute['name'])) { |
|
417 | + $raw_attribute_name = sanitize_title($attribute['name']); |
|
418 | 418 | } |
419 | 419 | |
420 | - if ( ! $attribute_id && ! $raw_attribute_name ) { |
|
420 | + if ( ! $attribute_id && ! $raw_attribute_name) { |
|
421 | 421 | continue; |
422 | 422 | } |
423 | 423 | |
424 | - $attribute_name = sanitize_title( $raw_attribute_name ); |
|
424 | + $attribute_name = sanitize_title($raw_attribute_name); |
|
425 | 425 | |
426 | - if ( ! isset( $parent_attributes[ $attribute_name ] ) || ! $parent_attributes[ $attribute_name ]->get_variation() ) { |
|
426 | + if ( ! isset($parent_attributes[$attribute_name]) || ! $parent_attributes[$attribute_name]->get_variation()) { |
|
427 | 427 | continue; |
428 | 428 | } |
429 | 429 | |
430 | - $attribute_key = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() ); |
|
431 | - $attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
430 | + $attribute_key = sanitize_title($parent_attributes[$attribute_name]->get_name()); |
|
431 | + $attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : ''; |
|
432 | 432 | |
433 | - if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) { |
|
433 | + if ($parent_attributes[$attribute_name]->is_taxonomy()) { |
|
434 | 434 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
435 | - $term = get_term_by( 'name', $attribute_value, $raw_attribute_name ); // @codingStandardsIgnoreLine |
|
435 | + $term = get_term_by('name', $attribute_value, $raw_attribute_name); // @codingStandardsIgnoreLine |
|
436 | 436 | |
437 | - if ( $term && ! is_wp_error( $term ) ) { |
|
437 | + if ($term && ! is_wp_error($term)) { |
|
438 | 438 | $attribute_value = $term->slug; |
439 | 439 | } else { |
440 | - $attribute_value = sanitize_title( $attribute_value ); |
|
440 | + $attribute_value = sanitize_title($attribute_value); |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
444 | - $attributes[ $attribute_key ] = $attribute_value; |
|
444 | + $attributes[$attribute_key] = $attribute_value; |
|
445 | 445 | } |
446 | 446 | |
447 | - $variation->set_attributes( $attributes ); |
|
447 | + $variation->set_attributes($attributes); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | // Menu order. |
451 | - if ( $request['menu_order'] ) { |
|
452 | - $variation->set_menu_order( $request['menu_order'] ); |
|
451 | + if ($request['menu_order']) { |
|
452 | + $variation->set_menu_order($request['menu_order']); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | // Meta data. |
456 | - if ( is_array( $request['meta_data'] ) ) { |
|
457 | - foreach ( $request['meta_data'] as $meta ) { |
|
458 | - $variation->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
456 | + if (is_array($request['meta_data'])) { |
|
457 | + foreach ($request['meta_data'] as $meta) { |
|
458 | + $variation->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
459 | 459 | } |
460 | 460 | } |
461 | 461 | |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | * @param WP_REST_Request $request Request object. |
470 | 470 | * @param bool $creating If is creating a new object. |
471 | 471 | */ |
472 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating ); |
|
472 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
@@ -477,9 +477,9 @@ discard block |
||
477 | 477 | * |
478 | 478 | * @param WC_Data $object Object data. |
479 | 479 | */ |
480 | - public function clear_transients( $object ) { |
|
481 | - wc_delete_product_transients( $object->get_parent_id() ); |
|
482 | - wp_cache_delete( 'product-' . $object->get_parent_id(), 'products' ); |
|
480 | + public function clear_transients($object) { |
|
481 | + wc_delete_product_transients($object->get_parent_id()); |
|
482 | + wp_cache_delete('product-' . $object->get_parent_id(), 'products'); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | /** |
@@ -489,20 +489,20 @@ discard block |
||
489 | 489 | * |
490 | 490 | * @return bool|WP_Error|WP_REST_Response |
491 | 491 | */ |
492 | - public function delete_item( $request ) { |
|
492 | + public function delete_item($request) { |
|
493 | 493 | $force = (bool) $request['force']; |
494 | - $object = $this->get_object( (int) $request['id'] ); |
|
494 | + $object = $this->get_object((int) $request['id']); |
|
495 | 495 | $result = false; |
496 | 496 | |
497 | - if ( ! $object || 0 === $object->get_id() ) { |
|
497 | + if ( ! $object || 0 === $object->get_id()) { |
|
498 | 498 | return new WP_Error( |
499 | - "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( |
|
499 | + "woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array( |
|
500 | 500 | 'status' => 404, |
501 | 501 | ) |
502 | 502 | ); |
503 | 503 | } |
504 | 504 | |
505 | - $supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) ); |
|
505 | + $supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable(array($object, 'get_status')); |
|
506 | 506 | |
507 | 507 | /** |
508 | 508 | * Filter whether an object is trashable. |
@@ -512,41 +512,41 @@ discard block |
||
512 | 512 | * @param boolean $supports_trash Whether the object type support trashing. |
513 | 513 | * @param WC_Data $object The object being considered for trashing support. |
514 | 514 | */ |
515 | - $supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object ); |
|
515 | + $supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object); |
|
516 | 516 | |
517 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) { |
|
517 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) { |
|
518 | 518 | return new WP_Error( |
519 | 519 | /* translators: %s: post type */ |
520 | - "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( |
|
520 | + "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array( |
|
521 | 521 | 'status' => rest_authorization_required_code(), |
522 | 522 | ) |
523 | 523 | ); |
524 | 524 | } |
525 | 525 | |
526 | - $request->set_param( 'context', 'edit' ); |
|
527 | - $response = $this->prepare_object_for_response( $object, $request ); |
|
526 | + $request->set_param('context', 'edit'); |
|
527 | + $response = $this->prepare_object_for_response($object, $request); |
|
528 | 528 | |
529 | 529 | // If we're forcing, then delete permanently. |
530 | - if ( $force ) { |
|
531 | - $object->delete( true ); |
|
530 | + if ($force) { |
|
531 | + $object->delete(true); |
|
532 | 532 | $result = 0 === $object->get_id(); |
533 | 533 | } else { |
534 | 534 | // If we don't support trashing for this type, error out. |
535 | - if ( ! $supports_trash ) { |
|
535 | + if ( ! $supports_trash) { |
|
536 | 536 | return new WP_Error( |
537 | 537 | /* translators: %s: post type */ |
538 | - 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( |
|
538 | + 'woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array( |
|
539 | 539 | 'status' => 501, |
540 | 540 | ) |
541 | 541 | ); |
542 | 542 | } |
543 | 543 | |
544 | 544 | // Otherwise, only trash if we haven't already. |
545 | - if ( is_callable( array( $object, 'get_status' ) ) ) { |
|
546 | - if ( 'trash' === $object->get_status() ) { |
|
545 | + if (is_callable(array($object, 'get_status'))) { |
|
546 | + if ('trash' === $object->get_status()) { |
|
547 | 547 | return new WP_Error( |
548 | 548 | /* translators: %s: post type */ |
549 | - 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( |
|
549 | + 'woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array( |
|
550 | 550 | 'status' => 410, |
551 | 551 | ) |
552 | 552 | ); |
@@ -557,18 +557,18 @@ discard block |
||
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
560 | - if ( ! $result ) { |
|
560 | + if ( ! $result) { |
|
561 | 561 | return new WP_Error( |
562 | 562 | /* translators: %s: post type */ |
563 | - 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( |
|
563 | + 'woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array( |
|
564 | 564 | 'status' => 500, |
565 | 565 | ) |
566 | 566 | ); |
567 | 567 | } |
568 | 568 | |
569 | 569 | // Delete parent product transients. |
570 | - if ( 0 !== $object->get_parent_id() ) { |
|
571 | - wc_delete_product_transients( $object->get_parent_id() ); |
|
570 | + if (0 !== $object->get_parent_id()) { |
|
571 | + wc_delete_product_transients($object->get_parent_id()); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | * @param WP_REST_Response $response The response data. |
579 | 579 | * @param WP_REST_Request $request The request sent to the API. |
580 | 580 | */ |
581 | - do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request ); |
|
581 | + do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request); |
|
582 | 582 | |
583 | 583 | return $response; |
584 | 584 | } |
@@ -590,30 +590,30 @@ discard block |
||
590 | 590 | * @param WP_REST_Request $request Full details about the request. |
591 | 591 | * @return array Of WP_Error or WP_REST_Response. |
592 | 592 | */ |
593 | - public function batch_items( $request ) { |
|
594 | - $items = array_filter( $request->get_params() ); |
|
593 | + public function batch_items($request) { |
|
594 | + $items = array_filter($request->get_params()); |
|
595 | 595 | $params = $request->get_url_params(); |
596 | 596 | $product_id = $params['product_id']; |
597 | 597 | $body_params = array(); |
598 | 598 | |
599 | - foreach ( array( 'update', 'create', 'delete' ) as $batch_type ) { |
|
600 | - if ( ! empty( $items[ $batch_type ] ) ) { |
|
599 | + foreach (array('update', 'create', 'delete') as $batch_type) { |
|
600 | + if ( ! empty($items[$batch_type])) { |
|
601 | 601 | $injected_items = array(); |
602 | - foreach ( $items[ $batch_type ] as $item ) { |
|
603 | - $injected_items[] = is_array( $item ) ? array_merge( |
|
602 | + foreach ($items[$batch_type] as $item) { |
|
603 | + $injected_items[] = is_array($item) ? array_merge( |
|
604 | 604 | array( |
605 | 605 | 'product_id' => $product_id, |
606 | 606 | ), $item |
607 | 607 | ) : $item; |
608 | 608 | } |
609 | - $body_params[ $batch_type ] = $injected_items; |
|
609 | + $body_params[$batch_type] = $injected_items; |
|
610 | 610 | } |
611 | 611 | } |
612 | 612 | |
613 | - $request = new WP_REST_Request( $request->get_method() ); |
|
614 | - $request->set_body_params( $body_params ); |
|
613 | + $request = new WP_REST_Request($request->get_method()); |
|
614 | + $request->set_body_params($body_params); |
|
615 | 615 | |
616 | - return parent::batch_items( $request ); |
|
616 | + return parent::batch_items($request); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -623,18 +623,18 @@ discard block |
||
623 | 623 | * @param WP_REST_Request $request Request object. |
624 | 624 | * @return array Links for the given post. |
625 | 625 | */ |
626 | - protected function prepare_links( $object, $request ) { |
|
626 | + protected function prepare_links($object, $request) { |
|
627 | 627 | $product_id = (int) $request['product_id']; |
628 | - $base = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base ); |
|
628 | + $base = str_replace('(?P<product_id>[\d]+)', $product_id, $this->rest_base); |
|
629 | 629 | $links = array( |
630 | 630 | 'self' => array( |
631 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $object->get_id() ) ), |
|
631 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $object->get_id())), |
|
632 | 632 | ), |
633 | 633 | 'collection' => array( |
634 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
634 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
635 | 635 | ), |
636 | 636 | 'up' => array( |
637 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product_id ) ), |
|
637 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product_id)), |
|
638 | 638 | ), |
639 | 639 | ); |
640 | 640 | return $links; |
@@ -646,350 +646,350 @@ discard block |
||
646 | 646 | * @return array |
647 | 647 | */ |
648 | 648 | public function get_item_schema() { |
649 | - $weight_unit = get_option( 'woocommerce_weight_unit' ); |
|
650 | - $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
|
649 | + $weight_unit = get_option('woocommerce_weight_unit'); |
|
650 | + $dimension_unit = get_option('woocommerce_dimension_unit'); |
|
651 | 651 | $schema = array( |
652 | 652 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
653 | 653 | 'title' => $this->post_type, |
654 | 654 | 'type' => 'object', |
655 | 655 | 'properties' => array( |
656 | 656 | 'id' => array( |
657 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
657 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
658 | 658 | 'type' => 'integer', |
659 | - 'context' => array( 'view', 'edit' ), |
|
659 | + 'context' => array('view', 'edit'), |
|
660 | 660 | 'readonly' => true, |
661 | 661 | ), |
662 | 662 | 'date_created' => array( |
663 | - 'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ), |
|
663 | + 'description' => __("The date the variation was created, in the site's timezone.", 'woocommerce'), |
|
664 | 664 | 'type' => 'date-time', |
665 | - 'context' => array( 'view', 'edit' ), |
|
665 | + 'context' => array('view', 'edit'), |
|
666 | 666 | 'readonly' => true, |
667 | 667 | ), |
668 | 668 | 'date_modified' => array( |
669 | - 'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ), |
|
669 | + 'description' => __("The date the variation was last modified, in the site's timezone.", 'woocommerce'), |
|
670 | 670 | 'type' => 'date-time', |
671 | - 'context' => array( 'view', 'edit' ), |
|
671 | + 'context' => array('view', 'edit'), |
|
672 | 672 | 'readonly' => true, |
673 | 673 | ), |
674 | 674 | 'description' => array( |
675 | - 'description' => __( 'Variation description.', 'woocommerce' ), |
|
675 | + 'description' => __('Variation description.', 'woocommerce'), |
|
676 | 676 | 'type' => 'string', |
677 | - 'context' => array( 'view', 'edit' ), |
|
677 | + 'context' => array('view', 'edit'), |
|
678 | 678 | ), |
679 | 679 | 'permalink' => array( |
680 | - 'description' => __( 'Variation URL.', 'woocommerce' ), |
|
680 | + 'description' => __('Variation URL.', 'woocommerce'), |
|
681 | 681 | 'type' => 'string', |
682 | 682 | 'format' => 'uri', |
683 | - 'context' => array( 'view', 'edit' ), |
|
683 | + 'context' => array('view', 'edit'), |
|
684 | 684 | 'readonly' => true, |
685 | 685 | ), |
686 | 686 | 'sku' => array( |
687 | - 'description' => __( 'Unique identifier.', 'woocommerce' ), |
|
687 | + 'description' => __('Unique identifier.', 'woocommerce'), |
|
688 | 688 | 'type' => 'string', |
689 | - 'context' => array( 'view', 'edit' ), |
|
689 | + 'context' => array('view', 'edit'), |
|
690 | 690 | ), |
691 | 691 | 'price' => array( |
692 | - 'description' => __( 'Current variation price.', 'woocommerce' ), |
|
692 | + 'description' => __('Current variation price.', 'woocommerce'), |
|
693 | 693 | 'type' => 'string', |
694 | - 'context' => array( 'view', 'edit' ), |
|
694 | + 'context' => array('view', 'edit'), |
|
695 | 695 | 'readonly' => true, |
696 | 696 | ), |
697 | 697 | 'regular_price' => array( |
698 | - 'description' => __( 'Variation regular price.', 'woocommerce' ), |
|
698 | + 'description' => __('Variation regular price.', 'woocommerce'), |
|
699 | 699 | 'type' => 'string', |
700 | - 'context' => array( 'view', 'edit' ), |
|
700 | + 'context' => array('view', 'edit'), |
|
701 | 701 | ), |
702 | 702 | 'sale_price' => array( |
703 | - 'description' => __( 'Variation sale price.', 'woocommerce' ), |
|
703 | + 'description' => __('Variation sale price.', 'woocommerce'), |
|
704 | 704 | 'type' => 'string', |
705 | - 'context' => array( 'view', 'edit' ), |
|
705 | + 'context' => array('view', 'edit'), |
|
706 | 706 | ), |
707 | 707 | 'date_on_sale_from' => array( |
708 | - 'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ), |
|
708 | + 'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'), |
|
709 | 709 | 'type' => 'date-time', |
710 | - 'context' => array( 'view', 'edit' ), |
|
710 | + 'context' => array('view', 'edit'), |
|
711 | 711 | ), |
712 | 712 | 'date_on_sale_from_gmt' => array( |
713 | - 'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ), |
|
713 | + 'description' => __('Start date of sale price, as GMT.', 'woocommerce'), |
|
714 | 714 | 'type' => 'date-time', |
715 | - 'context' => array( 'view', 'edit' ), |
|
715 | + 'context' => array('view', 'edit'), |
|
716 | 716 | ), |
717 | 717 | 'date_on_sale_to' => array( |
718 | - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
|
718 | + 'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'), |
|
719 | 719 | 'type' => 'date-time', |
720 | - 'context' => array( 'view', 'edit' ), |
|
720 | + 'context' => array('view', 'edit'), |
|
721 | 721 | ), |
722 | 722 | 'date_on_sale_to_gmt' => array( |
723 | - 'description' => __( 'End date of sale price, as GMT.', 'woocommerce' ), |
|
723 | + 'description' => __('End date of sale price, as GMT.', 'woocommerce'), |
|
724 | 724 | 'type' => 'date-time', |
725 | - 'context' => array( 'view', 'edit' ), |
|
725 | + 'context' => array('view', 'edit'), |
|
726 | 726 | ), |
727 | 727 | 'on_sale' => array( |
728 | - 'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ), |
|
728 | + 'description' => __('Shows if the variation is on sale.', 'woocommerce'), |
|
729 | 729 | 'type' => 'boolean', |
730 | - 'context' => array( 'view', 'edit' ), |
|
730 | + 'context' => array('view', 'edit'), |
|
731 | 731 | 'readonly' => true, |
732 | 732 | ), |
733 | 733 | 'visible' => array( |
734 | - 'description' => __( "Define if the variation is visible on the product's page.", 'woocommerce' ), |
|
734 | + 'description' => __("Define if the variation is visible on the product's page.", 'woocommerce'), |
|
735 | 735 | 'type' => 'boolean', |
736 | 736 | 'default' => true, |
737 | - 'context' => array( 'view', 'edit' ), |
|
737 | + 'context' => array('view', 'edit'), |
|
738 | 738 | ), |
739 | 739 | 'purchasable' => array( |
740 | - 'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ), |
|
740 | + 'description' => __('Shows if the variation can be bought.', 'woocommerce'), |
|
741 | 741 | 'type' => 'boolean', |
742 | - 'context' => array( 'view', 'edit' ), |
|
742 | + 'context' => array('view', 'edit'), |
|
743 | 743 | 'readonly' => true, |
744 | 744 | ), |
745 | 745 | 'virtual' => array( |
746 | - 'description' => __( 'If the variation is virtual.', 'woocommerce' ), |
|
746 | + 'description' => __('If the variation is virtual.', 'woocommerce'), |
|
747 | 747 | 'type' => 'boolean', |
748 | 748 | 'default' => false, |
749 | - 'context' => array( 'view', 'edit' ), |
|
749 | + 'context' => array('view', 'edit'), |
|
750 | 750 | ), |
751 | 751 | 'downloadable' => array( |
752 | - 'description' => __( 'If the variation is downloadable.', 'woocommerce' ), |
|
752 | + 'description' => __('If the variation is downloadable.', 'woocommerce'), |
|
753 | 753 | 'type' => 'boolean', |
754 | 754 | 'default' => false, |
755 | - 'context' => array( 'view', 'edit' ), |
|
755 | + 'context' => array('view', 'edit'), |
|
756 | 756 | ), |
757 | 757 | 'downloads' => array( |
758 | - 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
|
758 | + 'description' => __('List of downloadable files.', 'woocommerce'), |
|
759 | 759 | 'type' => 'array', |
760 | - 'context' => array( 'view', 'edit' ), |
|
760 | + 'context' => array('view', 'edit'), |
|
761 | 761 | 'items' => array( |
762 | 762 | 'type' => 'object', |
763 | 763 | 'properties' => array( |
764 | 764 | 'id' => array( |
765 | - 'description' => __( 'File ID.', 'woocommerce' ), |
|
765 | + 'description' => __('File ID.', 'woocommerce'), |
|
766 | 766 | 'type' => 'string', |
767 | - 'context' => array( 'view', 'edit' ), |
|
767 | + 'context' => array('view', 'edit'), |
|
768 | 768 | ), |
769 | 769 | 'name' => array( |
770 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
770 | + 'description' => __('File name.', 'woocommerce'), |
|
771 | 771 | 'type' => 'string', |
772 | - 'context' => array( 'view', 'edit' ), |
|
772 | + 'context' => array('view', 'edit'), |
|
773 | 773 | ), |
774 | 774 | 'file' => array( |
775 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
775 | + 'description' => __('File URL.', 'woocommerce'), |
|
776 | 776 | 'type' => 'string', |
777 | - 'context' => array( 'view', 'edit' ), |
|
777 | + 'context' => array('view', 'edit'), |
|
778 | 778 | ), |
779 | 779 | ), |
780 | 780 | ), |
781 | 781 | ), |
782 | 782 | 'download_limit' => array( |
783 | - 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
|
783 | + 'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'), |
|
784 | 784 | 'type' => 'integer', |
785 | 785 | 'default' => -1, |
786 | - 'context' => array( 'view', 'edit' ), |
|
786 | + 'context' => array('view', 'edit'), |
|
787 | 787 | ), |
788 | 788 | 'download_expiry' => array( |
789 | - 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
|
789 | + 'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'), |
|
790 | 790 | 'type' => 'integer', |
791 | 791 | 'default' => -1, |
792 | - 'context' => array( 'view', 'edit' ), |
|
792 | + 'context' => array('view', 'edit'), |
|
793 | 793 | ), |
794 | 794 | 'tax_status' => array( |
795 | - 'description' => __( 'Tax status.', 'woocommerce' ), |
|
795 | + 'description' => __('Tax status.', 'woocommerce'), |
|
796 | 796 | 'type' => 'string', |
797 | 797 | 'default' => 'taxable', |
798 | - 'enum' => array( 'taxable', 'shipping', 'none' ), |
|
799 | - 'context' => array( 'view', 'edit' ), |
|
798 | + 'enum' => array('taxable', 'shipping', 'none'), |
|
799 | + 'context' => array('view', 'edit'), |
|
800 | 800 | ), |
801 | 801 | 'tax_class' => array( |
802 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
802 | + 'description' => __('Tax class.', 'woocommerce'), |
|
803 | 803 | 'type' => 'string', |
804 | - 'context' => array( 'view', 'edit' ), |
|
804 | + 'context' => array('view', 'edit'), |
|
805 | 805 | ), |
806 | 806 | 'manage_stock' => array( |
807 | - 'description' => __( 'Stock management at variation level.', 'woocommerce' ), |
|
807 | + 'description' => __('Stock management at variation level.', 'woocommerce'), |
|
808 | 808 | 'type' => 'mixed', |
809 | 809 | 'default' => false, |
810 | - 'context' => array( 'view', 'edit' ), |
|
810 | + 'context' => array('view', 'edit'), |
|
811 | 811 | ), |
812 | 812 | 'stock_quantity' => array( |
813 | - 'description' => __( 'Stock quantity.', 'woocommerce' ), |
|
813 | + 'description' => __('Stock quantity.', 'woocommerce'), |
|
814 | 814 | 'type' => 'integer', |
815 | - 'context' => array( 'view', 'edit' ), |
|
815 | + 'context' => array('view', 'edit'), |
|
816 | 816 | ), |
817 | 817 | 'in_stock' => array( |
818 | - 'description' => __( 'Controls whether or not the variation is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ), |
|
818 | + 'description' => __('Controls whether or not the variation is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce'), |
|
819 | 819 | 'type' => 'boolean', |
820 | 820 | 'default' => true, |
821 | - 'context' => array( 'view', 'edit' ), |
|
821 | + 'context' => array('view', 'edit'), |
|
822 | 822 | ), |
823 | 823 | 'backorders' => array( |
824 | - 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
|
824 | + 'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'), |
|
825 | 825 | 'type' => 'string', |
826 | 826 | 'default' => 'no', |
827 | - 'enum' => array( 'no', 'notify', 'yes' ), |
|
828 | - 'context' => array( 'view', 'edit' ), |
|
827 | + 'enum' => array('no', 'notify', 'yes'), |
|
828 | + 'context' => array('view', 'edit'), |
|
829 | 829 | ), |
830 | 830 | 'backorders_allowed' => array( |
831 | - 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
|
831 | + 'description' => __('Shows if backorders are allowed.', 'woocommerce'), |
|
832 | 832 | 'type' => 'boolean', |
833 | - 'context' => array( 'view', 'edit' ), |
|
833 | + 'context' => array('view', 'edit'), |
|
834 | 834 | 'readonly' => true, |
835 | 835 | ), |
836 | 836 | 'backordered' => array( |
837 | - 'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ), |
|
837 | + 'description' => __('Shows if the variation is on backordered.', 'woocommerce'), |
|
838 | 838 | 'type' => 'boolean', |
839 | - 'context' => array( 'view', 'edit' ), |
|
839 | + 'context' => array('view', 'edit'), |
|
840 | 840 | 'readonly' => true, |
841 | 841 | ), |
842 | 842 | 'weight' => array( |
843 | 843 | /* translators: %s: weight unit */ |
844 | - 'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ), |
|
844 | + 'description' => sprintf(__('Variation weight (%s).', 'woocommerce'), $weight_unit), |
|
845 | 845 | 'type' => 'string', |
846 | - 'context' => array( 'view', 'edit' ), |
|
846 | + 'context' => array('view', 'edit'), |
|
847 | 847 | ), |
848 | 848 | 'dimensions' => array( |
849 | - 'description' => __( 'Variation dimensions.', 'woocommerce' ), |
|
849 | + 'description' => __('Variation dimensions.', 'woocommerce'), |
|
850 | 850 | 'type' => 'object', |
851 | - 'context' => array( 'view', 'edit' ), |
|
851 | + 'context' => array('view', 'edit'), |
|
852 | 852 | 'properties' => array( |
853 | 853 | 'length' => array( |
854 | 854 | /* translators: %s: dimension unit */ |
855 | - 'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ), |
|
855 | + 'description' => sprintf(__('Variation length (%s).', 'woocommerce'), $dimension_unit), |
|
856 | 856 | 'type' => 'string', |
857 | - 'context' => array( 'view', 'edit' ), |
|
857 | + 'context' => array('view', 'edit'), |
|
858 | 858 | ), |
859 | 859 | 'width' => array( |
860 | 860 | /* translators: %s: dimension unit */ |
861 | - 'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ), |
|
861 | + 'description' => sprintf(__('Variation width (%s).', 'woocommerce'), $dimension_unit), |
|
862 | 862 | 'type' => 'string', |
863 | - 'context' => array( 'view', 'edit' ), |
|
863 | + 'context' => array('view', 'edit'), |
|
864 | 864 | ), |
865 | 865 | 'height' => array( |
866 | 866 | /* translators: %s: dimension unit */ |
867 | - 'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ), |
|
867 | + 'description' => sprintf(__('Variation height (%s).', 'woocommerce'), $dimension_unit), |
|
868 | 868 | 'type' => 'string', |
869 | - 'context' => array( 'view', 'edit' ), |
|
869 | + 'context' => array('view', 'edit'), |
|
870 | 870 | ), |
871 | 871 | ), |
872 | 872 | ), |
873 | 873 | 'shipping_class' => array( |
874 | - 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
|
874 | + 'description' => __('Shipping class slug.', 'woocommerce'), |
|
875 | 875 | 'type' => 'string', |
876 | - 'context' => array( 'view', 'edit' ), |
|
876 | + 'context' => array('view', 'edit'), |
|
877 | 877 | ), |
878 | 878 | 'shipping_class_id' => array( |
879 | - 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
|
879 | + 'description' => __('Shipping class ID.', 'woocommerce'), |
|
880 | 880 | 'type' => 'string', |
881 | - 'context' => array( 'view', 'edit' ), |
|
881 | + 'context' => array('view', 'edit'), |
|
882 | 882 | 'readonly' => true, |
883 | 883 | ), |
884 | 884 | 'image' => array( |
885 | - 'description' => __( 'Variation image data.', 'woocommerce' ), |
|
885 | + 'description' => __('Variation image data.', 'woocommerce'), |
|
886 | 886 | 'type' => 'object', |
887 | - 'context' => array( 'view', 'edit' ), |
|
887 | + 'context' => array('view', 'edit'), |
|
888 | 888 | 'properties' => array( |
889 | 889 | 'id' => array( |
890 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
890 | + 'description' => __('Image ID.', 'woocommerce'), |
|
891 | 891 | 'type' => 'integer', |
892 | - 'context' => array( 'view', 'edit' ), |
|
892 | + 'context' => array('view', 'edit'), |
|
893 | 893 | ), |
894 | 894 | 'date_created' => array( |
895 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
895 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
896 | 896 | 'type' => 'date-time', |
897 | - 'context' => array( 'view', 'edit' ), |
|
897 | + 'context' => array('view', 'edit'), |
|
898 | 898 | 'readonly' => true, |
899 | 899 | ), |
900 | 900 | 'date_created_gmt' => array( |
901 | - 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
|
901 | + 'description' => __('The date the image was created, as GMT.', 'woocommerce'), |
|
902 | 902 | 'type' => 'date-time', |
903 | - 'context' => array( 'view', 'edit' ), |
|
903 | + 'context' => array('view', 'edit'), |
|
904 | 904 | 'readonly' => true, |
905 | 905 | ), |
906 | 906 | 'date_modified' => array( |
907 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
907 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
908 | 908 | 'type' => 'date-time', |
909 | - 'context' => array( 'view', 'edit' ), |
|
909 | + 'context' => array('view', 'edit'), |
|
910 | 910 | 'readonly' => true, |
911 | 911 | ), |
912 | 912 | 'date_modified_gmt' => array( |
913 | - 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
|
913 | + 'description' => __('The date the image was last modified, as GMT.', 'woocommerce'), |
|
914 | 914 | 'type' => 'date-time', |
915 | - 'context' => array( 'view', 'edit' ), |
|
915 | + 'context' => array('view', 'edit'), |
|
916 | 916 | 'readonly' => true, |
917 | 917 | ), |
918 | 918 | 'src' => array( |
919 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
919 | + 'description' => __('Image URL.', 'woocommerce'), |
|
920 | 920 | 'type' => 'string', |
921 | 921 | 'format' => 'uri', |
922 | - 'context' => array( 'view', 'edit' ), |
|
922 | + 'context' => array('view', 'edit'), |
|
923 | 923 | ), |
924 | 924 | 'name' => array( |
925 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
925 | + 'description' => __('Image name.', 'woocommerce'), |
|
926 | 926 | 'type' => 'string', |
927 | - 'context' => array( 'view', 'edit' ), |
|
927 | + 'context' => array('view', 'edit'), |
|
928 | 928 | ), |
929 | 929 | 'alt' => array( |
930 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
930 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
931 | 931 | 'type' => 'string', |
932 | - 'context' => array( 'view', 'edit' ), |
|
932 | + 'context' => array('view', 'edit'), |
|
933 | 933 | ), |
934 | 934 | 'position' => array( |
935 | - 'description' => __( 'Image position. 0 means that the image is featured.', 'woocommerce' ), |
|
935 | + 'description' => __('Image position. 0 means that the image is featured.', 'woocommerce'), |
|
936 | 936 | 'type' => 'integer', |
937 | - 'context' => array( 'view', 'edit' ), |
|
937 | + 'context' => array('view', 'edit'), |
|
938 | 938 | ), |
939 | 939 | ), |
940 | 940 | ), |
941 | 941 | 'attributes' => array( |
942 | - 'description' => __( 'List of attributes.', 'woocommerce' ), |
|
942 | + 'description' => __('List of attributes.', 'woocommerce'), |
|
943 | 943 | 'type' => 'array', |
944 | - 'context' => array( 'view', 'edit' ), |
|
944 | + 'context' => array('view', 'edit'), |
|
945 | 945 | 'items' => array( |
946 | 946 | 'type' => 'object', |
947 | 947 | 'properties' => array( |
948 | 948 | 'id' => array( |
949 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
949 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
950 | 950 | 'type' => 'integer', |
951 | - 'context' => array( 'view', 'edit' ), |
|
951 | + 'context' => array('view', 'edit'), |
|
952 | 952 | ), |
953 | 953 | 'name' => array( |
954 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
954 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
955 | 955 | 'type' => 'string', |
956 | - 'context' => array( 'view', 'edit' ), |
|
956 | + 'context' => array('view', 'edit'), |
|
957 | 957 | ), |
958 | 958 | 'option' => array( |
959 | - 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
|
959 | + 'description' => __('Selected attribute term name.', 'woocommerce'), |
|
960 | 960 | 'type' => 'string', |
961 | - 'context' => array( 'view', 'edit' ), |
|
961 | + 'context' => array('view', 'edit'), |
|
962 | 962 | ), |
963 | 963 | ), |
964 | 964 | ), |
965 | 965 | ), |
966 | 966 | 'menu_order' => array( |
967 | - 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), |
|
967 | + 'description' => __('Menu order, used to custom sort products.', 'woocommerce'), |
|
968 | 968 | 'type' => 'integer', |
969 | - 'context' => array( 'view', 'edit' ), |
|
969 | + 'context' => array('view', 'edit'), |
|
970 | 970 | ), |
971 | 971 | 'meta_data' => array( |
972 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
972 | + 'description' => __('Meta data.', 'woocommerce'), |
|
973 | 973 | 'type' => 'array', |
974 | - 'context' => array( 'view', 'edit' ), |
|
974 | + 'context' => array('view', 'edit'), |
|
975 | 975 | 'items' => array( |
976 | 976 | 'type' => 'object', |
977 | 977 | 'properties' => array( |
978 | 978 | 'id' => array( |
979 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
979 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
980 | 980 | 'type' => 'integer', |
981 | - 'context' => array( 'view', 'edit' ), |
|
981 | + 'context' => array('view', 'edit'), |
|
982 | 982 | 'readonly' => true, |
983 | 983 | ), |
984 | 984 | 'key' => array( |
985 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
985 | + 'description' => __('Meta key.', 'woocommerce'), |
|
986 | 986 | 'type' => 'string', |
987 | - 'context' => array( 'view', 'edit' ), |
|
987 | + 'context' => array('view', 'edit'), |
|
988 | 988 | ), |
989 | 989 | 'value' => array( |
990 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
990 | + 'description' => __('Meta value.', 'woocommerce'), |
|
991 | 991 | 'type' => 'mixed', |
992 | - 'context' => array( 'view', 'edit' ), |
|
992 | + 'context' => array('view', 'edit'), |
|
993 | 993 | ), |
994 | 994 | ), |
995 | 995 | ), |
@@ -997,6 +997,6 @@ discard block |
||
997 | 997 | ), |
998 | 998 | ); |
999 | 999 | |
1000 | - return $this->add_additional_fields_schema( $schema ); |
|
1000 | + return $this->add_additional_fields_schema($schema); |
|
1001 | 1001 | } |
1002 | 1002 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Shipping Zone Methods class. |
@@ -26,30 +26,30 @@ discard block |
||
26 | 26 | $this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d]+)/methods', array( |
27 | 27 | 'args' => array( |
28 | 28 | 'zone_id' => array( |
29 | - 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), |
|
29 | + 'description' => __('Unique ID for the zone.', 'woocommerce'), |
|
30 | 30 | 'type' => 'integer', |
31 | 31 | ), |
32 | 32 | ), |
33 | 33 | array( |
34 | 34 | 'methods' => WP_REST_Server::READABLE, |
35 | - 'callback' => array( $this, 'get_items' ), |
|
36 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
35 | + 'callback' => array($this, 'get_items'), |
|
36 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
37 | 37 | ), |
38 | 38 | array( |
39 | 39 | 'methods' => WP_REST_Server::CREATABLE, |
40 | - 'callback' => array( $this, 'create_item' ), |
|
41 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
40 | + 'callback' => array($this, 'create_item'), |
|
41 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
42 | 42 | 'args' => array_merge( |
43 | - $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
43 | + $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
44 | 44 | 'method_id' => array( |
45 | 45 | 'required' => true, |
46 | 46 | 'readonly' => false, |
47 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
47 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
48 | 48 | ), |
49 | 49 | ) |
50 | 50 | ), |
51 | 51 | ), |
52 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
52 | + 'schema' => array($this, 'get_public_item_schema'), |
|
53 | 53 | ) |
54 | 54 | ); |
55 | 55 | |
@@ -57,38 +57,38 @@ discard block |
||
57 | 57 | $this->namespace, '/' . $this->rest_base . '/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', array( |
58 | 58 | 'args' => array( |
59 | 59 | 'zone_id' => array( |
60 | - 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), |
|
60 | + 'description' => __('Unique ID for the zone.', 'woocommerce'), |
|
61 | 61 | 'type' => 'integer', |
62 | 62 | ), |
63 | 63 | 'instance_id' => array( |
64 | - 'description' => __( 'Unique ID for the instance.', 'woocommerce' ), |
|
64 | + 'description' => __('Unique ID for the instance.', 'woocommerce'), |
|
65 | 65 | 'type' => 'integer', |
66 | 66 | ), |
67 | 67 | ), |
68 | 68 | array( |
69 | 69 | 'methods' => WP_REST_Server::READABLE, |
70 | - 'callback' => array( $this, 'get_item' ), |
|
71 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
70 | + 'callback' => array($this, 'get_item'), |
|
71 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
72 | 72 | ), |
73 | 73 | array( |
74 | 74 | 'methods' => WP_REST_Server::EDITABLE, |
75 | - 'callback' => array( $this, 'update_item' ), |
|
76 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
77 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
75 | + 'callback' => array($this, 'update_item'), |
|
76 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
77 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
78 | 78 | ), |
79 | 79 | array( |
80 | 80 | 'methods' => WP_REST_Server::DELETABLE, |
81 | - 'callback' => array( $this, 'delete_item' ), |
|
82 | - 'permission_callback' => array( $this, 'delete_items_permissions_check' ), |
|
81 | + 'callback' => array($this, 'delete_item'), |
|
82 | + 'permission_callback' => array($this, 'delete_items_permissions_check'), |
|
83 | 83 | 'args' => array( |
84 | 84 | 'force' => array( |
85 | 85 | 'default' => false, |
86 | 86 | 'type' => 'boolean', |
87 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
87 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
88 | 88 | ), |
89 | 89 | ), |
90 | 90 | ), |
91 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
91 | + 'schema' => array($this, 'get_public_item_schema'), |
|
92 | 92 | ) |
93 | 93 | ); |
94 | 94 | } |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | * @param WP_REST_Request $request Request data. |
100 | 100 | * @return WP_REST_Response|WP_Error |
101 | 101 | */ |
102 | - public function get_item( $request ) { |
|
103 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
102 | + public function get_item($request) { |
|
103 | + $zone = $this->get_zone($request['zone_id']); |
|
104 | 104 | |
105 | - if ( is_wp_error( $zone ) ) { |
|
105 | + if (is_wp_error($zone)) { |
|
106 | 106 | return $zone; |
107 | 107 | } |
108 | 108 | |
@@ -110,20 +110,20 @@ discard block |
||
110 | 110 | $methods = $zone->get_shipping_methods(); |
111 | 111 | $method = false; |
112 | 112 | |
113 | - foreach ( $methods as $method_obj ) { |
|
114 | - if ( $instance_id === $method_obj->instance_id ) { |
|
113 | + foreach ($methods as $method_obj) { |
|
114 | + if ($instance_id === $method_obj->instance_id) { |
|
115 | 115 | $method = $method_obj; |
116 | 116 | break; |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - if ( false === $method ) { |
|
121 | - return new WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
120 | + if (false === $method) { |
|
121 | + return new WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
122 | 122 | } |
123 | 123 | |
124 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
124 | + $data = $this->prepare_item_for_response($method, $request); |
|
125 | 125 | |
126 | - return rest_ensure_response( $data ); |
|
126 | + return rest_ensure_response($data); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -132,22 +132,22 @@ discard block |
||
132 | 132 | * @param WP_REST_Request $request Request data. |
133 | 133 | * @return WP_REST_Response|WP_Error |
134 | 134 | */ |
135 | - public function get_items( $request ) { |
|
136 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
135 | + public function get_items($request) { |
|
136 | + $zone = $this->get_zone($request['zone_id']); |
|
137 | 137 | |
138 | - if ( is_wp_error( $zone ) ) { |
|
138 | + if (is_wp_error($zone)) { |
|
139 | 139 | return $zone; |
140 | 140 | } |
141 | 141 | |
142 | 142 | $methods = $zone->get_shipping_methods(); |
143 | 143 | $data = array(); |
144 | 144 | |
145 | - foreach ( $methods as $method_obj ) { |
|
146 | - $method = $this->prepare_item_for_response( $method_obj, $request ); |
|
145 | + foreach ($methods as $method_obj) { |
|
146 | + $method = $this->prepare_item_for_response($method_obj, $request); |
|
147 | 147 | $data[] = $method; |
148 | 148 | } |
149 | 149 | |
150 | - return rest_ensure_response( $data ); |
|
150 | + return rest_ensure_response($data); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -156,34 +156,34 @@ discard block |
||
156 | 156 | * @param WP_REST_Request $request Full details about the request. |
157 | 157 | * @return WP_REST_Request|WP_Error |
158 | 158 | */ |
159 | - public function create_item( $request ) { |
|
159 | + public function create_item($request) { |
|
160 | 160 | $method_id = $request['method_id']; |
161 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
162 | - if ( is_wp_error( $zone ) ) { |
|
161 | + $zone = $this->get_zone($request['zone_id']); |
|
162 | + if (is_wp_error($zone)) { |
|
163 | 163 | return $zone; |
164 | 164 | } |
165 | 165 | |
166 | - $instance_id = $zone->add_shipping_method( $method_id ); |
|
166 | + $instance_id = $zone->add_shipping_method($method_id); |
|
167 | 167 | $methods = $zone->get_shipping_methods(); |
168 | 168 | $method = false; |
169 | - foreach ( $methods as $method_obj ) { |
|
170 | - if ( $instance_id === $method_obj->instance_id ) { |
|
169 | + foreach ($methods as $method_obj) { |
|
170 | + if ($instance_id === $method_obj->instance_id) { |
|
171 | 171 | $method = $method_obj; |
172 | 172 | break; |
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
176 | - if ( false === $method ) { |
|
177 | - return new WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( 'Resource cannot be created.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
176 | + if (false === $method) { |
|
177 | + return new WP_Error('woocommerce_rest_shipping_zone_not_created', __('Resource cannot be created.', 'woocommerce'), array('status' => 500)); |
|
178 | 178 | } |
179 | 179 | |
180 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
181 | - if ( is_wp_error( $method ) ) { |
|
180 | + $method = $this->update_fields($instance_id, $method, $request); |
|
181 | + if (is_wp_error($method)) { |
|
182 | 182 | return $method; |
183 | 183 | } |
184 | 184 | |
185 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
186 | - return rest_ensure_response( $data ); |
|
185 | + $data = $this->prepare_item_for_response($method, $request); |
|
186 | + return rest_ensure_response($data); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | * @param WP_REST_Request $request Full details about the request. |
193 | 193 | * @return WP_Error|boolean |
194 | 194 | */ |
195 | - public function delete_item( $request ) { |
|
196 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
197 | - if ( is_wp_error( $zone ) ) { |
|
195 | + public function delete_item($request) { |
|
196 | + $zone = $this->get_zone($request['zone_id']); |
|
197 | + if (is_wp_error($zone)) { |
|
198 | 198 | return $zone; |
199 | 199 | } |
200 | 200 | |
@@ -204,30 +204,30 @@ discard block |
||
204 | 204 | $methods = $zone->get_shipping_methods(); |
205 | 205 | $method = false; |
206 | 206 | |
207 | - foreach ( $methods as $method_obj ) { |
|
208 | - if ( $instance_id === $method_obj->instance_id ) { |
|
207 | + foreach ($methods as $method_obj) { |
|
208 | + if ($instance_id === $method_obj->instance_id) { |
|
209 | 209 | $method = $method_obj; |
210 | 210 | break; |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | - if ( false === $method ) { |
|
215 | - return new WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
214 | + if (false === $method) { |
|
215 | + return new WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
216 | 216 | } |
217 | 217 | |
218 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
219 | - if ( is_wp_error( $method ) ) { |
|
218 | + $method = $this->update_fields($instance_id, $method, $request); |
|
219 | + if (is_wp_error($method)) { |
|
220 | 220 | return $method; |
221 | 221 | } |
222 | 222 | |
223 | - $request->set_param( 'context', 'view' ); |
|
224 | - $response = $this->prepare_item_for_response( $method, $request ); |
|
223 | + $request->set_param('context', 'view'); |
|
224 | + $response = $this->prepare_item_for_response($method, $request); |
|
225 | 225 | |
226 | 226 | // Actually delete. |
227 | - if ( $force ) { |
|
228 | - $zone->delete_shipping_method( $instance_id ); |
|
227 | + if ($force) { |
|
228 | + $zone->delete_shipping_method($instance_id); |
|
229 | 229 | } else { |
230 | - return new WP_Error( 'rest_trash_not_supported', __( 'Shipping methods do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
230 | + return new WP_Error('rest_trash_not_supported', __('Shipping methods do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @param WP_REST_Response $response The response data. |
238 | 238 | * @param WP_REST_Request $request The request sent to the API. |
239 | 239 | */ |
240 | - do_action( 'rest_delete_product_review', $method, $response, $request ); |
|
240 | + do_action('rest_delete_product_review', $method, $response, $request); |
|
241 | 241 | |
242 | 242 | return $response; |
243 | 243 | } |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | * @param WP_REST_Request $request Request data. |
249 | 249 | * @return WP_REST_Response|WP_Error |
250 | 250 | */ |
251 | - public function update_item( $request ) { |
|
252 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
253 | - if ( is_wp_error( $zone ) ) { |
|
251 | + public function update_item($request) { |
|
252 | + $zone = $this->get_zone($request['zone_id']); |
|
253 | + if (is_wp_error($zone)) { |
|
254 | 254 | return $zone; |
255 | 255 | } |
256 | 256 | |
@@ -258,24 +258,24 @@ discard block |
||
258 | 258 | $methods = $zone->get_shipping_methods(); |
259 | 259 | $method = false; |
260 | 260 | |
261 | - foreach ( $methods as $method_obj ) { |
|
262 | - if ( $instance_id === $method_obj->instance_id ) { |
|
261 | + foreach ($methods as $method_obj) { |
|
262 | + if ($instance_id === $method_obj->instance_id) { |
|
263 | 263 | $method = $method_obj; |
264 | 264 | break; |
265 | 265 | } |
266 | 266 | } |
267 | 267 | |
268 | - if ( false === $method ) { |
|
269 | - return new WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
268 | + if (false === $method) { |
|
269 | + return new WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
270 | 270 | } |
271 | 271 | |
272 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
273 | - if ( is_wp_error( $method ) ) { |
|
272 | + $method = $this->update_fields($instance_id, $method, $request); |
|
273 | + if (is_wp_error($method)) { |
|
274 | 274 | return $method; |
275 | 275 | } |
276 | 276 | |
277 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
278 | - return rest_ensure_response( $data ); |
|
277 | + $data = $this->prepare_item_for_response($method, $request); |
|
278 | + return rest_ensure_response($data); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -287,47 +287,47 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @return WC_Shipping_Method |
289 | 289 | */ |
290 | - public function update_fields( $instance_id, $method, $request ) { |
|
290 | + public function update_fields($instance_id, $method, $request) { |
|
291 | 291 | global $wpdb; |
292 | 292 | |
293 | 293 | // Update settings if present. |
294 | - if ( isset( $request['settings'] ) ) { |
|
294 | + if (isset($request['settings'])) { |
|
295 | 295 | $method->init_instance_settings(); |
296 | 296 | $instance_settings = $method->instance_settings; |
297 | 297 | $errors_found = false; |
298 | - foreach ( $method->get_instance_form_fields() as $key => $field ) { |
|
299 | - if ( isset( $request['settings'][ $key ] ) ) { |
|
300 | - if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { |
|
301 | - $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); |
|
298 | + foreach ($method->get_instance_form_fields() as $key => $field) { |
|
299 | + if (isset($request['settings'][$key])) { |
|
300 | + if (is_callable(array($this, 'validate_setting_' . $field['type'] . '_field'))) { |
|
301 | + $value = $this->{'validate_setting_' . $field['type'] . '_field'}($request['settings'][$key], $field); |
|
302 | 302 | } else { |
303 | - $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); |
|
303 | + $value = $this->validate_setting_text_field($request['settings'][$key], $field); |
|
304 | 304 | } |
305 | - if ( is_wp_error( $value ) ) { |
|
305 | + if (is_wp_error($value)) { |
|
306 | 306 | $errors_found = true; |
307 | 307 | break; |
308 | 308 | } |
309 | - $instance_settings[ $key ] = $value; |
|
309 | + $instance_settings[$key] = $value; |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | - if ( $errors_found ) { |
|
314 | - return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
313 | + if ($errors_found) { |
|
314 | + return new WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
315 | 315 | } |
316 | 316 | |
317 | - update_option( $method->get_instance_option_key(), apply_filters( 'woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method ) ); |
|
317 | + update_option($method->get_instance_option_key(), apply_filters('woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method)); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | // Update order. |
321 | - if ( isset( $request['order'] ) ) { |
|
322 | - $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request['order'] ) ), array( 'instance_id' => absint( $instance_id ) ) ); |
|
323 | - $method->method_order = absint( $request['order'] ); |
|
321 | + if (isset($request['order'])) { |
|
322 | + $wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('method_order' => absint($request['order'])), array('instance_id' => absint($instance_id))); |
|
323 | + $method->method_order = absint($request['order']); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | // Update if this method is enabled or not. |
327 | - if ( isset( $request['enabled'] ) ) { |
|
328 | - if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request['enabled'] ), array( 'instance_id' => absint( $instance_id ) ) ) ) { |
|
329 | - do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled'] ); |
|
330 | - $method->enabled = ( true === $request['enabled'] ? 'yes' : 'no' ); |
|
327 | + if (isset($request['enabled'])) { |
|
328 | + if ($wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('is_enabled' => $request['enabled']), array('instance_id' => absint($instance_id)))) { |
|
329 | + do_action('woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled']); |
|
330 | + $method->enabled = (true === $request['enabled'] ? 'yes' : 'no'); |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
@@ -341,29 +341,29 @@ discard block |
||
341 | 341 | * @param WP_REST_Request $request Request object. |
342 | 342 | * @return WP_REST_Response $response |
343 | 343 | */ |
344 | - public function prepare_item_for_response( $item, $request ) { |
|
344 | + public function prepare_item_for_response($item, $request) { |
|
345 | 345 | $method = array( |
346 | 346 | 'id' => $item->instance_id, |
347 | 347 | 'instance_id' => $item->instance_id, |
348 | 348 | 'title' => $item->instance_settings['title'], |
349 | 349 | 'order' => $item->method_order, |
350 | - 'enabled' => ( 'yes' === $item->enabled ), |
|
350 | + 'enabled' => ('yes' === $item->enabled), |
|
351 | 351 | 'method_id' => $item->id, |
352 | 352 | 'method_title' => $item->method_title, |
353 | 353 | 'method_description' => $item->method_description, |
354 | - 'settings' => $this->get_settings( $item ), |
|
354 | + 'settings' => $this->get_settings($item), |
|
355 | 355 | ); |
356 | 356 | |
357 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
358 | - $data = $this->add_additional_fields_to_object( $method, $request ); |
|
359 | - $data = $this->filter_response_by_context( $data, $context ); |
|
357 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
358 | + $data = $this->add_additional_fields_to_object($method, $request); |
|
359 | + $data = $this->filter_response_by_context($data, $context); |
|
360 | 360 | |
361 | 361 | // Wrap the data in a response object. |
362 | - $response = rest_ensure_response( $data ); |
|
362 | + $response = rest_ensure_response($data); |
|
363 | 363 | |
364 | - $response->add_links( $this->prepare_links( $request['zone_id'], $item->instance_id ) ); |
|
364 | + $response->add_links($this->prepare_links($request['zone_id'], $item->instance_id)); |
|
365 | 365 | |
366 | - $response = $this->prepare_response_for_collection( $response ); |
|
366 | + $response = $this->prepare_response_for_collection($response); |
|
367 | 367 | |
368 | 368 | return $response; |
369 | 369 | } |
@@ -375,24 +375,24 @@ discard block |
||
375 | 375 | * |
376 | 376 | * @return array |
377 | 377 | */ |
378 | - public function get_settings( $item ) { |
|
378 | + public function get_settings($item) { |
|
379 | 379 | $item->init_instance_settings(); |
380 | 380 | $settings = array(); |
381 | - foreach ( $item->get_instance_form_fields() as $id => $field ) { |
|
381 | + foreach ($item->get_instance_form_fields() as $id => $field) { |
|
382 | 382 | $data = array( |
383 | 383 | 'id' => $id, |
384 | 384 | 'label' => $field['title'], |
385 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
385 | + 'description' => empty($field['description']) ? '' : $field['description'], |
|
386 | 386 | 'type' => $field['type'], |
387 | - 'value' => $item->instance_settings[ $id ], |
|
388 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
389 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
390 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
387 | + 'value' => $item->instance_settings[$id], |
|
388 | + 'default' => empty($field['default']) ? '' : $field['default'], |
|
389 | + 'tip' => empty($field['description']) ? '' : $field['description'], |
|
390 | + 'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'], |
|
391 | 391 | ); |
392 | - if ( ! empty( $field['options'] ) ) { |
|
392 | + if ( ! empty($field['options'])) { |
|
393 | 393 | $data['options'] = $field['options']; |
394 | 394 | } |
395 | - $settings[ $id ] = $data; |
|
395 | + $settings[$id] = $data; |
|
396 | 396 | } |
397 | 397 | return $settings; |
398 | 398 | } |
@@ -404,17 +404,17 @@ discard block |
||
404 | 404 | * @param int $instance_id Given Shipping Zone Method Instance ID. |
405 | 405 | * @return array Links for the given Shipping Zone Method. |
406 | 406 | */ |
407 | - protected function prepare_links( $zone_id, $instance_id ) { |
|
407 | + protected function prepare_links($zone_id, $instance_id) { |
|
408 | 408 | $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id; |
409 | 409 | $links = array( |
410 | 410 | 'self' => array( |
411 | - 'href' => rest_url( $base . '/methods/' . $instance_id ), |
|
411 | + 'href' => rest_url($base . '/methods/' . $instance_id), |
|
412 | 412 | ), |
413 | 413 | 'collection' => array( |
414 | - 'href' => rest_url( $base . '/methods' ), |
|
414 | + 'href' => rest_url($base . '/methods'), |
|
415 | 415 | ), |
416 | 416 | 'describes' => array( |
417 | - 'href' => rest_url( $base ), |
|
417 | + 'href' => rest_url($base), |
|
418 | 418 | ), |
419 | 419 | ); |
420 | 420 | |
@@ -433,102 +433,102 @@ discard block |
||
433 | 433 | 'type' => 'object', |
434 | 434 | 'properties' => array( |
435 | 435 | 'id' => array( |
436 | - 'description' => __( 'Shipping method instance ID.', 'woocommerce' ), |
|
436 | + 'description' => __('Shipping method instance ID.', 'woocommerce'), |
|
437 | 437 | 'type' => 'integer', |
438 | - 'context' => array( 'view', 'edit' ), |
|
438 | + 'context' => array('view', 'edit'), |
|
439 | 439 | 'readonly' => true, |
440 | 440 | ), |
441 | 441 | 'instance_id' => array( |
442 | - 'description' => __( 'Shipping method instance ID.', 'woocommerce' ), |
|
442 | + 'description' => __('Shipping method instance ID.', 'woocommerce'), |
|
443 | 443 | 'type' => 'integer', |
444 | - 'context' => array( 'view', 'edit' ), |
|
444 | + 'context' => array('view', 'edit'), |
|
445 | 445 | 'readonly' => true, |
446 | 446 | ), |
447 | 447 | 'title' => array( |
448 | - 'description' => __( 'Shipping method customer facing title.', 'woocommerce' ), |
|
448 | + 'description' => __('Shipping method customer facing title.', 'woocommerce'), |
|
449 | 449 | 'type' => 'string', |
450 | - 'context' => array( 'view', 'edit' ), |
|
450 | + 'context' => array('view', 'edit'), |
|
451 | 451 | 'readonly' => true, |
452 | 452 | ), |
453 | 453 | 'order' => array( |
454 | - 'description' => __( 'Shipping method sort order.', 'woocommerce' ), |
|
454 | + 'description' => __('Shipping method sort order.', 'woocommerce'), |
|
455 | 455 | 'type' => 'integer', |
456 | - 'context' => array( 'view', 'edit' ), |
|
456 | + 'context' => array('view', 'edit'), |
|
457 | 457 | ), |
458 | 458 | 'enabled' => array( |
459 | - 'description' => __( 'Shipping method enabled status.', 'woocommerce' ), |
|
459 | + 'description' => __('Shipping method enabled status.', 'woocommerce'), |
|
460 | 460 | 'type' => 'boolean', |
461 | - 'context' => array( 'view', 'edit' ), |
|
461 | + 'context' => array('view', 'edit'), |
|
462 | 462 | ), |
463 | 463 | 'method_id' => array( |
464 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
464 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
465 | 465 | 'type' => 'string', |
466 | - 'context' => array( 'view', 'edit' ), |
|
466 | + 'context' => array('view', 'edit'), |
|
467 | 467 | 'readonly' => true, |
468 | 468 | ), |
469 | 469 | 'method_title' => array( |
470 | - 'description' => __( 'Shipping method title.', 'woocommerce' ), |
|
470 | + 'description' => __('Shipping method title.', 'woocommerce'), |
|
471 | 471 | 'type' => 'string', |
472 | - 'context' => array( 'view', 'edit' ), |
|
472 | + 'context' => array('view', 'edit'), |
|
473 | 473 | 'readonly' => true, |
474 | 474 | ), |
475 | 475 | 'method_description' => array( |
476 | - 'description' => __( 'Shipping method description.', 'woocommerce' ), |
|
476 | + 'description' => __('Shipping method description.', 'woocommerce'), |
|
477 | 477 | 'type' => 'string', |
478 | - 'context' => array( 'view', 'edit' ), |
|
478 | + 'context' => array('view', 'edit'), |
|
479 | 479 | 'readonly' => true, |
480 | 480 | ), |
481 | 481 | 'settings' => array( |
482 | - 'description' => __( 'Shipping method settings.', 'woocommerce' ), |
|
482 | + 'description' => __('Shipping method settings.', 'woocommerce'), |
|
483 | 483 | 'type' => 'object', |
484 | - 'context' => array( 'view', 'edit' ), |
|
484 | + 'context' => array('view', 'edit'), |
|
485 | 485 | 'properties' => array( |
486 | 486 | 'id' => array( |
487 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
487 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
488 | 488 | 'type' => 'string', |
489 | - 'context' => array( 'view', 'edit' ), |
|
489 | + 'context' => array('view', 'edit'), |
|
490 | 490 | 'readonly' => true, |
491 | 491 | ), |
492 | 492 | 'label' => array( |
493 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
493 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
494 | 494 | 'type' => 'string', |
495 | - 'context' => array( 'view', 'edit' ), |
|
495 | + 'context' => array('view', 'edit'), |
|
496 | 496 | 'readonly' => true, |
497 | 497 | ), |
498 | 498 | 'description' => array( |
499 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
499 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
500 | 500 | 'type' => 'string', |
501 | - 'context' => array( 'view', 'edit' ), |
|
501 | + 'context' => array('view', 'edit'), |
|
502 | 502 | 'readonly' => true, |
503 | 503 | ), |
504 | 504 | 'type' => array( |
505 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
505 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
506 | 506 | 'type' => 'string', |
507 | - 'context' => array( 'view', 'edit' ), |
|
508 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ), |
|
507 | + 'context' => array('view', 'edit'), |
|
508 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'), |
|
509 | 509 | 'readonly' => true, |
510 | 510 | ), |
511 | 511 | 'value' => array( |
512 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
512 | + 'description' => __('Setting value.', 'woocommerce'), |
|
513 | 513 | 'type' => 'string', |
514 | - 'context' => array( 'view', 'edit' ), |
|
514 | + 'context' => array('view', 'edit'), |
|
515 | 515 | ), |
516 | 516 | 'default' => array( |
517 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
517 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
518 | 518 | 'type' => 'string', |
519 | - 'context' => array( 'view', 'edit' ), |
|
519 | + 'context' => array('view', 'edit'), |
|
520 | 520 | 'readonly' => true, |
521 | 521 | ), |
522 | 522 | 'tip' => array( |
523 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
523 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
524 | 524 | 'type' => 'string', |
525 | - 'context' => array( 'view', 'edit' ), |
|
525 | + 'context' => array('view', 'edit'), |
|
526 | 526 | 'readonly' => true, |
527 | 527 | ), |
528 | 528 | 'placeholder' => array( |
529 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
529 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
530 | 530 | 'type' => 'string', |
531 | - 'context' => array( 'view', 'edit' ), |
|
531 | + 'context' => array('view', 'edit'), |
|
532 | 532 | 'readonly' => true, |
533 | 533 | ), |
534 | 534 | ), |
@@ -536,6 +536,6 @@ discard block |
||
536 | 536 | ), |
537 | 537 | ); |
538 | 538 | |
539 | - return $this->add_additional_fields_schema( $schema ); |
|
539 | + return $this->add_additional_fields_schema($schema); |
|
540 | 540 | } |
541 | 541 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Product Attribute Terms controller class. |