@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Webhooks controller class. |
@@ -40,31 +40,31 @@ discard block |
||
40 | 40 | array( |
41 | 41 | array( |
42 | 42 | 'methods' => \WP_REST_Server::READABLE, |
43 | - 'callback' => array( $this, 'get_items' ), |
|
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
43 | + 'callback' => array($this, 'get_items'), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | 45 | 'args' => $this->get_collection_params(), |
46 | 46 | ), |
47 | 47 | array( |
48 | 48 | 'methods' => \WP_REST_Server::CREATABLE, |
49 | - 'callback' => array( $this, 'create_item' ), |
|
50 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
49 | + 'callback' => array($this, 'create_item'), |
|
50 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
51 | 51 | 'args' => array_merge( |
52 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
52 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
53 | 53 | array( |
54 | 54 | 'topic' => array( |
55 | 55 | 'required' => true, |
56 | 56 | 'type' => 'string', |
57 | - 'description' => __( 'Webhook topic.', 'woocommerce' ), |
|
57 | + 'description' => __('Webhook topic.', 'woocommerce'), |
|
58 | 58 | ), |
59 | 59 | 'delivery_url' => array( |
60 | 60 | 'required' => true, |
61 | 61 | 'type' => 'string', |
62 | - 'description' => __( 'Webhook delivery URL.', 'woocommerce' ), |
|
62 | + 'description' => __('Webhook delivery URL.', 'woocommerce'), |
|
63 | 63 | ), |
64 | 64 | ) |
65 | 65 | ), |
66 | 66 | ), |
67 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
67 | + 'schema' => array($this, 'get_public_item_schema'), |
|
68 | 68 | ), |
69 | 69 | true |
70 | 70 | ); |
@@ -75,37 +75,37 @@ discard block |
||
75 | 75 | array( |
76 | 76 | 'args' => array( |
77 | 77 | 'id' => array( |
78 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
78 | + 'description' => __('Unique identifier for the resource.', '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' ), |
|
108 | + 'schema' => array($this, 'get_public_item_schema'), |
|
109 | 109 | ), |
110 | 110 | true |
111 | 111 | ); |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | array( |
117 | 117 | array( |
118 | 118 | 'methods' => \WP_REST_Server::EDITABLE, |
119 | - 'callback' => array( $this, 'batch_items' ), |
|
120 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
121 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
119 | + 'callback' => array($this, 'batch_items'), |
|
120 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
121 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
122 | 122 | ), |
123 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
123 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
124 | 124 | ), |
125 | 125 | true |
126 | 126 | ); |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @param \WP_REST_Request $request Full details about the request. |
133 | 133 | * @return \WP_Error|boolean |
134 | 134 | */ |
135 | - public function get_items_permissions_check( $request ) { |
|
136 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) { |
|
137 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
135 | + public function get_items_permissions_check($request) { |
|
136 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) { |
|
137 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return true; |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @return bool|\WP_Error |
149 | 149 | */ |
150 | - public function create_item_permissions_check( $request ) { |
|
151 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'create' ) ) { |
|
152 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
150 | + public function create_item_permissions_check($request) { |
|
151 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'create')) { |
|
152 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | return true; |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | * @param \WP_REST_Request $request Full details about the request. |
162 | 162 | * @return \WP_Error|boolean |
163 | 163 | */ |
164 | - public function get_item_permissions_check( $request ) { |
|
165 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) { |
|
166 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
164 | + public function get_item_permissions_check($request) { |
|
165 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) { |
|
166 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | return true; |
@@ -176,9 +176,9 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @return bool|\WP_Error |
178 | 178 | */ |
179 | - public function update_item_permissions_check( $request ) { |
|
180 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'edit' ) ) { |
|
181 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
179 | + public function update_item_permissions_check($request) { |
|
180 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'edit')) { |
|
181 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | return true; |
@@ -191,9 +191,9 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return bool|\WP_Error |
193 | 193 | */ |
194 | - public function delete_item_permissions_check( $request ) { |
|
195 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'delete' ) ) { |
|
196 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
194 | + public function delete_item_permissions_check($request) { |
|
195 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'delete')) { |
|
196 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | return true; |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @return bool|\WP_Error |
208 | 208 | */ |
209 | - public function batch_items_permissions_check( $request ) { |
|
210 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'batch' ) ) { |
|
211 | - return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
209 | + public function batch_items_permissions_check($request) { |
|
210 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'batch')) { |
|
211 | + return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | return true; |
@@ -230,20 +230,20 @@ discard block |
||
230 | 230 | * @param \WP_REST_Request $request Full details about the request. |
231 | 231 | * @return \WP_Error\WP_REST_Response |
232 | 232 | */ |
233 | - public function get_items( $request ) { |
|
233 | + public function get_items($request) { |
|
234 | 234 | $args = array(); |
235 | 235 | $args['order'] = $request['order']; |
236 | 236 | $args['orderby'] = $request['orderby']; |
237 | 237 | $args['status'] = 'all' === $request['status'] ? '' : $request['status']; |
238 | - $args['include'] = implode( ',', $request['include'] ); |
|
239 | - $args['exclude'] = implode( ',', $request['exclude'] ); |
|
238 | + $args['include'] = implode(',', $request['include']); |
|
239 | + $args['exclude'] = implode(',', $request['exclude']); |
|
240 | 240 | $args['limit'] = $request['per_page']; |
241 | 241 | $args['search'] = $request['search']; |
242 | 242 | $args['before'] = $request['before']; |
243 | 243 | $args['after'] = $request['after']; |
244 | 244 | |
245 | - if ( empty( $request['offset'] ) ) { |
|
246 | - $args['offset'] = 1 < $request['page'] ? ( $request['page'] - 1 ) * $args['limit'] : 0; |
|
245 | + if (empty($request['offset'])) { |
|
246 | + $args['offset'] = 1 < $request['page'] ? ($request['page'] - 1) * $args['limit'] : 0; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -252,43 +252,43 @@ discard block |
||
252 | 252 | * @param array $args Array of arguments for $wpdb->get_results(). |
253 | 253 | * @param \WP_REST_Request $request The current request. |
254 | 254 | */ |
255 | - $prepared_args = apply_filters( 'woocommerce_rest_webhook_query', $args, $request ); |
|
256 | - unset( $prepared_args['page'] ); |
|
255 | + $prepared_args = apply_filters('woocommerce_rest_webhook_query', $args, $request); |
|
256 | + unset($prepared_args['page']); |
|
257 | 257 | $prepared_args['paginate'] = true; |
258 | 258 | |
259 | 259 | // Get the webhooks. |
260 | 260 | $webhooks = array(); |
261 | - $data_store = \WC_Data_Store::load( 'webhook' ); |
|
262 | - $results = $data_store->search_webhooks( $prepared_args ); |
|
261 | + $data_store = \WC_Data_Store::load('webhook'); |
|
262 | + $results = $data_store->search_webhooks($prepared_args); |
|
263 | 263 | $webhook_ids = $results->webhooks; |
264 | 264 | |
265 | - foreach ( $webhook_ids as $webhook_id ) { |
|
266 | - $data = $this->prepare_item_for_response( $webhook_id, $request ); |
|
267 | - $webhooks[] = $this->prepare_response_for_collection( $data ); |
|
265 | + foreach ($webhook_ids as $webhook_id) { |
|
266 | + $data = $this->prepare_item_for_response($webhook_id, $request); |
|
267 | + $webhooks[] = $this->prepare_response_for_collection($data); |
|
268 | 268 | } |
269 | 269 | |
270 | - $response = rest_ensure_response( $webhooks ); |
|
270 | + $response = rest_ensure_response($webhooks); |
|
271 | 271 | $per_page = (int) $prepared_args['limit']; |
272 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
272 | + $page = ceil((((int) $prepared_args['offset']) / $per_page) + 1); |
|
273 | 273 | $total_webhooks = $results->total; |
274 | 274 | $max_pages = $results->max_num_pages; |
275 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
275 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
276 | 276 | |
277 | - $response->header( 'X-WP-Total', $total_webhooks ); |
|
278 | - $response->header( 'X-WP-TotalPages', $max_pages ); |
|
277 | + $response->header('X-WP-Total', $total_webhooks); |
|
278 | + $response->header('X-WP-TotalPages', $max_pages); |
|
279 | 279 | |
280 | - if ( $page > 1 ) { |
|
280 | + if ($page > 1) { |
|
281 | 281 | $prev_page = $page - 1; |
282 | - if ( $prev_page > $max_pages ) { |
|
282 | + if ($prev_page > $max_pages) { |
|
283 | 283 | $prev_page = $max_pages; |
284 | 284 | } |
285 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
286 | - $response->link_header( 'prev', $prev_link ); |
|
285 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
286 | + $response->link_header('prev', $prev_link); |
|
287 | 287 | } |
288 | - if ( $max_pages > $page ) { |
|
288 | + if ($max_pages > $page) { |
|
289 | 289 | $next_page = $page + 1; |
290 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
291 | - $response->link_header( 'next', $next_link ); |
|
290 | + $next_link = add_query_arg('page', $next_page, $base); |
|
291 | + $response->link_header('next', $next_link); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | return $response; |
@@ -300,15 +300,15 @@ discard block |
||
300 | 300 | * @param \WP_REST_Request $request Full details about the request. |
301 | 301 | * @return \WP_Error\WP_REST_Response |
302 | 302 | */ |
303 | - public function get_item( $request ) { |
|
303 | + public function get_item($request) { |
|
304 | 304 | $id = (int) $request['id']; |
305 | 305 | |
306 | - if ( empty( $id ) ) { |
|
307 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
306 | + if (empty($id)) { |
|
307 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404)); |
|
308 | 308 | } |
309 | 309 | |
310 | - $data = $this->prepare_item_for_response( $id, $request ); |
|
311 | - $response = rest_ensure_response( $data ); |
|
310 | + $data = $this->prepare_item_for_response($id, $request); |
|
311 | + $response = rest_ensure_response($data); |
|
312 | 312 | |
313 | 313 | return $response; |
314 | 314 | } |
@@ -319,38 +319,38 @@ discard block |
||
319 | 319 | * @param \WP_REST_Request $request Full details about the request. |
320 | 320 | * @return \WP_Error\WP_REST_Response |
321 | 321 | */ |
322 | - public function create_item( $request ) { |
|
323 | - if ( ! empty( $request['id'] ) ) { |
|
322 | + public function create_item($request) { |
|
323 | + if ( ! empty($request['id'])) { |
|
324 | 324 | /* translators: %s: post type */ |
325 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
325 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // Validate topic. |
329 | - if ( empty( $request['topic'] ) || ! wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) { |
|
330 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic is required and must be valid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
329 | + if (empty($request['topic']) || ! wc_is_webhook_valid_topic(strtolower($request['topic']))) { |
|
330 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic is required and must be valid.', 'woocommerce'), array('status' => 400)); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | // Validate delivery URL. |
334 | - if ( empty( $request['delivery_url'] ) || ! wc_is_valid_url( $request['delivery_url'] ) ) { |
|
335 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
334 | + if (empty($request['delivery_url']) || ! wc_is_valid_url($request['delivery_url'])) { |
|
335 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400)); |
|
336 | 336 | } |
337 | 337 | |
338 | - $post = $this->prepare_item_for_database( $request ); |
|
339 | - if ( is_wp_error( $post ) ) { |
|
338 | + $post = $this->prepare_item_for_database($request); |
|
339 | + if (is_wp_error($post)) { |
|
340 | 340 | return $post; |
341 | 341 | } |
342 | 342 | |
343 | 343 | $webhook = new \WC_Webhook(); |
344 | - $webhook->set_name( $post->post_title ); |
|
345 | - $webhook->set_user_id( $post->post_author ); |
|
346 | - $webhook->set_status( 'publish' === $post->post_status ? 'active' : 'disabled' ); |
|
347 | - $webhook->set_topic( $request['topic'] ); |
|
348 | - $webhook->set_delivery_url( $request['delivery_url'] ); |
|
349 | - $webhook->set_secret( ! empty( $request['secret'] ) ? $request['secret'] : wp_generate_password( 50, true, true ) ); |
|
350 | - $webhook->set_api_version( $this->get_default_api_version() ); |
|
344 | + $webhook->set_name($post->post_title); |
|
345 | + $webhook->set_user_id($post->post_author); |
|
346 | + $webhook->set_status('publish' === $post->post_status ? 'active' : 'disabled'); |
|
347 | + $webhook->set_topic($request['topic']); |
|
348 | + $webhook->set_delivery_url($request['delivery_url']); |
|
349 | + $webhook->set_secret( ! empty($request['secret']) ? $request['secret'] : wp_generate_password(50, true, true)); |
|
350 | + $webhook->set_api_version($this->get_default_api_version()); |
|
351 | 351 | $webhook->save(); |
352 | 352 | |
353 | - $this->update_additional_fields_for_object( $webhook, $request ); |
|
353 | + $this->update_additional_fields_for_object($webhook, $request); |
|
354 | 354 | |
355 | 355 | /** |
356 | 356 | * Fires after a single item is created or updated via the REST API. |
@@ -359,13 +359,13 @@ discard block |
||
359 | 359 | * @param \WP_REST_Request $request Request object. |
360 | 360 | * @param bool $creating True when creating item, false when updating. |
361 | 361 | */ |
362 | - do_action( 'woocommerce_rest_insert_webhook_object', $webhook, $request, true ); |
|
362 | + do_action('woocommerce_rest_insert_webhook_object', $webhook, $request, true); |
|
363 | 363 | |
364 | - $request->set_param( 'context', 'edit' ); |
|
365 | - $response = $this->prepare_item_for_response( $webhook->get_id(), $request ); |
|
366 | - $response = rest_ensure_response( $response ); |
|
367 | - $response->set_status( 201 ); |
|
368 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $webhook->get_id() ) ) ); |
|
364 | + $request->set_param('context', 'edit'); |
|
365 | + $response = $this->prepare_item_for_response($webhook->get_id(), $request); |
|
366 | + $response = rest_ensure_response($response); |
|
367 | + $response->set_status(201); |
|
368 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $webhook->get_id()))); |
|
369 | 369 | |
370 | 370 | // Send ping. |
371 | 371 | $webhook->deliver_ping(); |
@@ -379,58 +379,58 @@ discard block |
||
379 | 379 | * @param \WP_REST_Request $request Full details about the request. |
380 | 380 | * @return \WP_Error\WP_REST_Response |
381 | 381 | */ |
382 | - public function update_item( $request ) { |
|
382 | + public function update_item($request) { |
|
383 | 383 | $id = (int) $request['id']; |
384 | - $webhook = wc_get_webhook( $id ); |
|
384 | + $webhook = wc_get_webhook($id); |
|
385 | 385 | |
386 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
387 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
386 | + if (empty($webhook) || is_null($webhook)) { |
|
387 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | // Update topic. |
391 | - if ( ! empty( $request['topic'] ) ) { |
|
392 | - if ( wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) { |
|
393 | - $webhook->set_topic( $request['topic'] ); |
|
391 | + if ( ! empty($request['topic'])) { |
|
392 | + if (wc_is_webhook_valid_topic(strtolower($request['topic']))) { |
|
393 | + $webhook->set_topic($request['topic']); |
|
394 | 394 | } else { |
395 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic must be valid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
395 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic must be valid.', 'woocommerce'), array('status' => 400)); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | |
399 | 399 | // Update delivery URL. |
400 | - if ( ! empty( $request['delivery_url'] ) ) { |
|
401 | - if ( wc_is_valid_url( $request['delivery_url'] ) ) { |
|
402 | - $webhook->set_delivery_url( $request['delivery_url'] ); |
|
400 | + if ( ! empty($request['delivery_url'])) { |
|
401 | + if (wc_is_valid_url($request['delivery_url'])) { |
|
402 | + $webhook->set_delivery_url($request['delivery_url']); |
|
403 | 403 | } else { |
404 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
404 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400)); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
408 | 408 | // Update secret. |
409 | - if ( ! empty( $request['secret'] ) ) { |
|
410 | - $webhook->set_secret( $request['secret'] ); |
|
409 | + if ( ! empty($request['secret'])) { |
|
410 | + $webhook->set_secret($request['secret']); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | // Update status. |
414 | - if ( ! empty( $request['status'] ) ) { |
|
415 | - if ( wc_is_webhook_valid_status( strtolower( $request['status'] ) ) ) { |
|
416 | - $webhook->set_status( $request['status'] ); |
|
414 | + if ( ! empty($request['status'])) { |
|
415 | + if (wc_is_webhook_valid_status(strtolower($request['status']))) { |
|
416 | + $webhook->set_status($request['status']); |
|
417 | 417 | } else { |
418 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_status", __( 'Webhook status must be valid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
418 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_status", __('Webhook status must be valid.', 'woocommerce'), array('status' => 400)); |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | |
422 | - $post = $this->prepare_item_for_database( $request ); |
|
423 | - if ( is_wp_error( $post ) ) { |
|
422 | + $post = $this->prepare_item_for_database($request); |
|
423 | + if (is_wp_error($post)) { |
|
424 | 424 | return $post; |
425 | 425 | } |
426 | 426 | |
427 | - if ( isset( $post->post_title ) ) { |
|
428 | - $webhook->set_name( $post->post_title ); |
|
427 | + if (isset($post->post_title)) { |
|
428 | + $webhook->set_name($post->post_title); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | $webhook->save(); |
432 | 432 | |
433 | - $this->update_additional_fields_for_object( $webhook, $request ); |
|
433 | + $this->update_additional_fields_for_object($webhook, $request); |
|
434 | 434 | |
435 | 435 | /** |
436 | 436 | * Fires after a single item is created or updated via the REST API. |
@@ -439,12 +439,12 @@ discard block |
||
439 | 439 | * @param \WP_REST_Request $request Request object. |
440 | 440 | * @param bool $creating True when creating item, false when updating. |
441 | 441 | */ |
442 | - do_action( 'woocommerce_rest_insert_webhook_object', $webhook, $request, false ); |
|
442 | + do_action('woocommerce_rest_insert_webhook_object', $webhook, $request, false); |
|
443 | 443 | |
444 | - $request->set_param( 'context', 'edit' ); |
|
445 | - $response = $this->prepare_item_for_response( $webhook->get_id(), $request ); |
|
444 | + $request->set_param('context', 'edit'); |
|
445 | + $response = $this->prepare_item_for_response($webhook->get_id(), $request); |
|
446 | 446 | |
447 | - return rest_ensure_response( $response ); |
|
447 | + return rest_ensure_response($response); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -453,27 +453,27 @@ discard block |
||
453 | 453 | * @param \WP_REST_Request $request Full details about the request. |
454 | 454 | * @return \WP_REST_Response|\WP_Error |
455 | 455 | */ |
456 | - public function delete_item( $request ) { |
|
456 | + public function delete_item($request) { |
|
457 | 457 | $id = (int) $request['id']; |
458 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
458 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
459 | 459 | |
460 | 460 | // We don't support trashing for this type, error out. |
461 | - if ( ! $force ) { |
|
462 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
461 | + if ( ! $force) { |
|
462 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
463 | 463 | } |
464 | 464 | |
465 | - $webhook = wc_get_webhook( $id ); |
|
465 | + $webhook = wc_get_webhook($id); |
|
466 | 466 | |
467 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
468 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
467 | + if (empty($webhook) || is_null($webhook)) { |
|
468 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404)); |
|
469 | 469 | } |
470 | 470 | |
471 | - $request->set_param( 'context', 'edit' ); |
|
472 | - $previous = $this->prepare_item_for_response( $webhook, $request ); |
|
473 | - $result = $webhook->delete( true ); |
|
474 | - if ( ! $result ) { |
|
471 | + $request->set_param('context', 'edit'); |
|
472 | + $previous = $this->prepare_item_for_response($webhook, $request); |
|
473 | + $result = $webhook->delete(true); |
|
474 | + if ( ! $result) { |
|
475 | 475 | /* translators: %s: post type */ |
476 | - return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) ); |
|
476 | + return new WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500)); |
|
477 | 477 | } |
478 | 478 | $response = new \WP_REST_Response(); |
479 | 479 | $response->set_data( |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | * @param \WP_REST_Response $response The response data. |
491 | 491 | * @param \WP_REST_Request $request The request sent to the API. |
492 | 492 | */ |
493 | - do_action( 'woocommerce_rest_delete_webhook_object', $webhook, $response, $request ); |
|
493 | + do_action('woocommerce_rest_delete_webhook_object', $webhook, $response, $request); |
|
494 | 494 | |
495 | 495 | return $response; |
496 | 496 | } |
@@ -501,17 +501,17 @@ discard block |
||
501 | 501 | * @param \WP_REST_Request $request Request object. |
502 | 502 | * @return \WP_Error|stdClass $data Post object. |
503 | 503 | */ |
504 | - protected function prepare_item_for_database( $request ) { |
|
504 | + protected function prepare_item_for_database($request) { |
|
505 | 505 | $data = new \stdClass(); |
506 | 506 | |
507 | 507 | // Post ID. |
508 | - if ( isset( $request['id'] ) ) { |
|
509 | - $data->ID = absint( $request['id'] ); |
|
508 | + if (isset($request['id'])) { |
|
509 | + $data->ID = absint($request['id']); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | // Validate required POST fields. |
513 | - if ( 'POST' === $request->get_method() && empty( $data->ID ) ) { |
|
514 | - $data->post_title = ! empty( $request['name'] ) ? $request['name'] : sprintf( __( 'Webhook created on %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce' ) ) ); // @codingStandardsIgnoreLine |
|
513 | + if ('POST' === $request->get_method() && empty($data->ID)) { |
|
514 | + $data->post_title = ! empty($request['name']) ? $request['name'] : sprintf(__('Webhook created on %s', 'woocommerce'), strftime(_x('%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce'))); // @codingStandardsIgnoreLine |
|
515 | 515 | |
516 | 516 | // Post author. |
517 | 517 | $data->post_author = get_current_user_id(); |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | } else { |
525 | 525 | |
526 | 526 | // Allow edit post title. |
527 | - if ( ! empty( $request['name'] ) ) { |
|
527 | + if ( ! empty($request['name'])) { |
|
528 | 528 | $data->post_title = $request['name']; |
529 | 529 | } |
530 | 530 | } |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | * for inserting or updating the database. |
546 | 546 | * @param \WP_REST_Request $request Request object. |
547 | 547 | */ |
548 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $data, $request ); |
|
548 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $data, $request); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | /** |
@@ -555,11 +555,11 @@ discard block |
||
555 | 555 | * @param \WP_REST_Request $request Request object. |
556 | 556 | * @return \WP_REST_Response $response |
557 | 557 | */ |
558 | - public function prepare_item_for_response( $id, $request ) { |
|
559 | - $webhook = wc_get_webhook( $id ); |
|
558 | + public function prepare_item_for_response($id, $request) { |
|
559 | + $webhook = wc_get_webhook($id); |
|
560 | 560 | |
561 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
562 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
561 | + if (empty($webhook) || is_null($webhook)) { |
|
562 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | $data = array( |
@@ -571,20 +571,20 @@ discard block |
||
571 | 571 | 'event' => $webhook->get_event(), |
572 | 572 | 'hooks' => $webhook->get_hooks(), |
573 | 573 | 'delivery_url' => $webhook->get_delivery_url(), |
574 | - 'date_created' => wc_rest_prepare_date_response( $webhook->get_date_created(), false ), |
|
575 | - 'date_created_gmt' => wc_rest_prepare_date_response( $webhook->get_date_created() ), |
|
576 | - 'date_modified' => wc_rest_prepare_date_response( $webhook->get_date_modified(), false ), |
|
577 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $webhook->get_date_modified() ), |
|
574 | + 'date_created' => wc_rest_prepare_date_response($webhook->get_date_created(), false), |
|
575 | + 'date_created_gmt' => wc_rest_prepare_date_response($webhook->get_date_created()), |
|
576 | + 'date_modified' => wc_rest_prepare_date_response($webhook->get_date_modified(), false), |
|
577 | + 'date_modified_gmt' => wc_rest_prepare_date_response($webhook->get_date_modified()), |
|
578 | 578 | ); |
579 | 579 | |
580 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
581 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
582 | - $data = $this->filter_response_by_context( $data, $context ); |
|
580 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
581 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
582 | + $data = $this->filter_response_by_context($data, $context); |
|
583 | 583 | |
584 | 584 | // Wrap the data in a response object. |
585 | - $response = rest_ensure_response( $data ); |
|
585 | + $response = rest_ensure_response($data); |
|
586 | 586 | |
587 | - $response->add_links( $this->prepare_links( $webhook->get_id(), $request ) ); |
|
587 | + $response->add_links($this->prepare_links($webhook->get_id(), $request)); |
|
588 | 588 | |
589 | 589 | /** |
590 | 590 | * Filter webhook object returned from the REST API. |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | * @param WC_Webhook $webhook Webhook object used to create response. |
594 | 594 | * @param \WP_REST_Request $request Request object. |
595 | 595 | */ |
596 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request ); |
|
596 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -602,13 +602,13 @@ discard block |
||
602 | 602 | * @param int $id Webhook ID. |
603 | 603 | * @return array |
604 | 604 | */ |
605 | - protected function prepare_links( $id ) { |
|
605 | + protected function prepare_links($id) { |
|
606 | 606 | $links = array( |
607 | 607 | 'self' => array( |
608 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $id ) ), |
|
608 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $id)), |
|
609 | 609 | ), |
610 | 610 | 'collection' => array( |
611 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
611 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
612 | 612 | ), |
613 | 613 | ); |
614 | 614 | |
@@ -627,89 +627,89 @@ discard block |
||
627 | 627 | 'type' => 'object', |
628 | 628 | 'properties' => array( |
629 | 629 | 'id' => array( |
630 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
630 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
631 | 631 | 'type' => 'integer', |
632 | - 'context' => array( 'view', 'edit' ), |
|
632 | + 'context' => array('view', 'edit'), |
|
633 | 633 | 'readonly' => true, |
634 | 634 | ), |
635 | 635 | 'name' => array( |
636 | - 'description' => __( 'A friendly name for the webhook.', 'woocommerce' ), |
|
636 | + 'description' => __('A friendly name for the webhook.', 'woocommerce'), |
|
637 | 637 | 'type' => 'string', |
638 | - 'context' => array( 'view', 'edit' ), |
|
638 | + 'context' => array('view', 'edit'), |
|
639 | 639 | ), |
640 | 640 | 'status' => array( |
641 | - 'description' => __( 'Webhook status.', 'woocommerce' ), |
|
641 | + 'description' => __('Webhook status.', 'woocommerce'), |
|
642 | 642 | 'type' => 'string', |
643 | 643 | 'default' => 'active', |
644 | - 'enum' => array_keys( wc_get_webhook_statuses() ), |
|
645 | - 'context' => array( 'view', 'edit' ), |
|
644 | + 'enum' => array_keys(wc_get_webhook_statuses()), |
|
645 | + 'context' => array('view', 'edit'), |
|
646 | 646 | ), |
647 | 647 | 'topic' => array( |
648 | - 'description' => __( 'Webhook topic.', 'woocommerce' ), |
|
648 | + 'description' => __('Webhook topic.', 'woocommerce'), |
|
649 | 649 | 'type' => 'string', |
650 | - 'context' => array( 'view', 'edit' ), |
|
650 | + 'context' => array('view', 'edit'), |
|
651 | 651 | ), |
652 | 652 | 'resource' => array( |
653 | - 'description' => __( 'Webhook resource.', 'woocommerce' ), |
|
653 | + 'description' => __('Webhook resource.', 'woocommerce'), |
|
654 | 654 | 'type' => 'string', |
655 | - 'context' => array( 'view', 'edit' ), |
|
655 | + 'context' => array('view', 'edit'), |
|
656 | 656 | 'readonly' => true, |
657 | 657 | ), |
658 | 658 | 'event' => array( |
659 | - 'description' => __( 'Webhook event.', 'woocommerce' ), |
|
659 | + 'description' => __('Webhook event.', 'woocommerce'), |
|
660 | 660 | 'type' => 'string', |
661 | - 'context' => array( 'view', 'edit' ), |
|
661 | + 'context' => array('view', 'edit'), |
|
662 | 662 | 'readonly' => true, |
663 | 663 | ), |
664 | 664 | 'hooks' => array( |
665 | - 'description' => __( 'WooCommerce action names associated with the webhook.', 'woocommerce' ), |
|
665 | + 'description' => __('WooCommerce action names associated with the webhook.', 'woocommerce'), |
|
666 | 666 | 'type' => 'array', |
667 | - 'context' => array( 'view', 'edit' ), |
|
667 | + 'context' => array('view', 'edit'), |
|
668 | 668 | 'readonly' => true, |
669 | 669 | 'items' => array( |
670 | 670 | 'type' => 'string', |
671 | 671 | ), |
672 | 672 | ), |
673 | 673 | 'delivery_url' => array( |
674 | - 'description' => __( 'The URL where the webhook payload is delivered.', 'woocommerce' ), |
|
674 | + 'description' => __('The URL where the webhook payload is delivered.', 'woocommerce'), |
|
675 | 675 | 'type' => 'string', |
676 | 676 | 'format' => 'uri', |
677 | - 'context' => array( 'view', 'edit' ), |
|
677 | + 'context' => array('view', 'edit'), |
|
678 | 678 | 'readonly' => true, |
679 | 679 | ), |
680 | 680 | 'secret' => array( |
681 | - 'description' => __( "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce' ), |
|
681 | + 'description' => __("Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce'), |
|
682 | 682 | 'type' => 'string', |
683 | - 'context' => array( 'edit' ), |
|
683 | + 'context' => array('edit'), |
|
684 | 684 | ), |
685 | 685 | 'date_created' => array( |
686 | - 'description' => __( "The date the webhook was created, in the site's timezone.", 'woocommerce' ), |
|
686 | + 'description' => __("The date the webhook was created, in the site's timezone.", 'woocommerce'), |
|
687 | 687 | 'type' => 'date-time', |
688 | - 'context' => array( 'view', 'edit' ), |
|
688 | + 'context' => array('view', 'edit'), |
|
689 | 689 | 'readonly' => true, |
690 | 690 | ), |
691 | 691 | 'date_created_gmt' => array( |
692 | - 'description' => __( 'The date the webhook was created, as GMT.', 'woocommerce' ), |
|
692 | + 'description' => __('The date the webhook was created, as GMT.', 'woocommerce'), |
|
693 | 693 | 'type' => 'date-time', |
694 | - 'context' => array( 'view', 'edit' ), |
|
694 | + 'context' => array('view', 'edit'), |
|
695 | 695 | 'readonly' => true, |
696 | 696 | ), |
697 | 697 | 'date_modified' => array( |
698 | - 'description' => __( "The date the webhook was last modified, in the site's timezone.", 'woocommerce' ), |
|
698 | + 'description' => __("The date the webhook was last modified, in the site's timezone.", 'woocommerce'), |
|
699 | 699 | 'type' => 'date-time', |
700 | - 'context' => array( 'view', 'edit' ), |
|
700 | + 'context' => array('view', 'edit'), |
|
701 | 701 | 'readonly' => true, |
702 | 702 | ), |
703 | 703 | 'date_modified_gmt' => array( |
704 | - 'description' => __( 'The date the webhook was last modified, as GMT.', 'woocommerce' ), |
|
704 | + 'description' => __('The date the webhook was last modified, as GMT.', 'woocommerce'), |
|
705 | 705 | 'type' => 'date-time', |
706 | - 'context' => array( 'view', 'edit' ), |
|
706 | + 'context' => array('view', 'edit'), |
|
707 | 707 | 'readonly' => true, |
708 | 708 | ), |
709 | 709 | ), |
710 | 710 | ); |
711 | 711 | |
712 | - return $this->add_additional_fields_schema( $schema ); |
|
712 | + return $this->add_additional_fields_schema($schema); |
|
713 | 713 | } |
714 | 714 | |
715 | 715 | /** |
@@ -722,20 +722,20 @@ discard block |
||
722 | 722 | |
723 | 723 | $params['context']['default'] = 'view'; |
724 | 724 | |
725 | - $params['after'] = array( |
|
726 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
725 | + $params['after'] = array( |
|
726 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
727 | 727 | 'type' => 'string', |
728 | 728 | 'format' => 'date-time', |
729 | 729 | 'validate_callback' => 'rest_validate_request_arg', |
730 | 730 | ); |
731 | - $params['before'] = array( |
|
732 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
731 | + $params['before'] = array( |
|
732 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
733 | 733 | 'type' => 'string', |
734 | 734 | 'format' => 'date-time', |
735 | 735 | 'validate_callback' => 'rest_validate_request_arg', |
736 | 736 | ); |
737 | 737 | $params['exclude'] = array( |
738 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
738 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
739 | 739 | 'type' => 'array', |
740 | 740 | 'items' => array( |
741 | 741 | 'type' => 'integer', |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | 'sanitize_callback' => 'wp_parse_id_list', |
745 | 745 | ); |
746 | 746 | $params['include'] = array( |
747 | - 'description' => __( 'Limit result set to specific ids.', 'woocommerce' ), |
|
747 | + 'description' => __('Limit result set to specific ids.', 'woocommerce'), |
|
748 | 748 | 'type' => 'array', |
749 | 749 | 'items' => array( |
750 | 750 | 'type' > 'integer', |
@@ -752,21 +752,21 @@ discard block |
||
752 | 752 | 'default' => array(), |
753 | 753 | 'sanitize_callback' => 'wp_parse_id_list', |
754 | 754 | ); |
755 | - $params['offset'] = array( |
|
756 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
755 | + $params['offset'] = array( |
|
756 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
757 | 757 | 'type' => 'integer', |
758 | 758 | 'sanitize_callback' => 'absint', |
759 | 759 | 'validate_callback' => 'rest_validate_request_arg', |
760 | 760 | ); |
761 | - $params['order'] = array( |
|
762 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
761 | + $params['order'] = array( |
|
762 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
763 | 763 | 'type' => 'string', |
764 | 764 | 'default' => 'desc', |
765 | - 'enum' => array( 'asc', 'desc' ), |
|
765 | + 'enum' => array('asc', 'desc'), |
|
766 | 766 | 'validate_callback' => 'rest_validate_request_arg', |
767 | 767 | ); |
768 | 768 | $params['orderby'] = array( |
769 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
769 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
770 | 770 | 'type' => 'string', |
771 | 771 | 'default' => 'date', |
772 | 772 | 'enum' => array( |
@@ -776,11 +776,11 @@ discard block |
||
776 | 776 | ), |
777 | 777 | 'validate_callback' => 'rest_validate_request_arg', |
778 | 778 | ); |
779 | - $params['status'] = array( |
|
779 | + $params['status'] = array( |
|
780 | 780 | 'default' => 'all', |
781 | - 'description' => __( 'Limit result set to webhooks assigned a specific status.', 'woocommerce' ), |
|
781 | + 'description' => __('Limit result set to webhooks assigned a specific status.', 'woocommerce'), |
|
782 | 782 | 'type' => 'string', |
783 | - 'enum' => array( 'all', 'active', 'paused', 'disabled' ), |
|
783 | + 'enum' => array('all', 'active', 'paused', 'disabled'), |
|
784 | 784 | 'sanitize_callback' => 'sanitize_key', |
785 | 785 | 'validate_callback' => 'rest_validate_request_arg', |
786 | 786 | ); |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Orders controller class. |
@@ -54,17 +54,17 @@ discard block |
||
54 | 54 | array( |
55 | 55 | array( |
56 | 56 | 'methods' => \WP_REST_Server::READABLE, |
57 | - 'callback' => array( $this, 'get_items' ), |
|
58 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
57 | + 'callback' => array($this, 'get_items'), |
|
58 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
59 | 59 | 'args' => $this->get_collection_params(), |
60 | 60 | ), |
61 | 61 | array( |
62 | 62 | 'methods' => \WP_REST_Server::CREATABLE, |
63 | - 'callback' => array( $this, 'create_item' ), |
|
64 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
65 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
63 | + 'callback' => array($this, 'create_item'), |
|
64 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
65 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
66 | 66 | ), |
67 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
67 | + 'schema' => array($this, 'get_public_item_schema'), |
|
68 | 68 | ), |
69 | 69 | true |
70 | 70 | ); |
@@ -75,37 +75,37 @@ discard block |
||
75 | 75 | array( |
76 | 76 | 'args' => array( |
77 | 77 | 'id' => array( |
78 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
78 | + 'description' => __('Unique identifier for the resource.', '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' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
104 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
105 | 105 | ), |
106 | 106 | ), |
107 | 107 | ), |
108 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
108 | + 'schema' => array($this, 'get_public_item_schema'), |
|
109 | 109 | ), |
110 | 110 | true |
111 | 111 | ); |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | array( |
117 | 117 | array( |
118 | 118 | 'methods' => \WP_REST_Server::EDITABLE, |
119 | - 'callback' => array( $this, 'batch_items' ), |
|
120 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
121 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
119 | + 'callback' => array($this, 'batch_items'), |
|
120 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
121 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
122 | 122 | ), |
123 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
123 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
124 | 124 | ), |
125 | 125 | true |
126 | 126 | ); |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | * @param int $id Object ID. |
134 | 134 | * @return WC_Data|bool |
135 | 135 | */ |
136 | - protected function get_object( $id ) { |
|
137 | - $order = wc_get_order( $id ); |
|
136 | + protected function get_object($id) { |
|
137 | + $order = wc_get_order($id); |
|
138 | 138 | // In case id is a refund's id (or it's not an order at all), don't expose it via /orders/ path. |
139 | - if ( ! $order || 'shop_order_refund' === $order->get_type() ) { |
|
139 | + if ( ! $order || 'shop_order_refund' === $order->get_type()) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | |
@@ -149,47 +149,47 @@ discard block |
||
149 | 149 | * @param WC_Order_item $item Order item data. |
150 | 150 | * @return array |
151 | 151 | */ |
152 | - protected function get_order_item_data( $item ) { |
|
152 | + protected function get_order_item_data($item) { |
|
153 | 153 | $data = $item->get_data(); |
154 | - $format_decimal = array( 'subtotal', 'subtotal_tax', 'total', 'total_tax', 'tax_total', 'shipping_tax_total' ); |
|
154 | + $format_decimal = array('subtotal', 'subtotal_tax', 'total', 'total_tax', 'tax_total', 'shipping_tax_total'); |
|
155 | 155 | |
156 | 156 | // Format decimal values. |
157 | - foreach ( $format_decimal as $key ) { |
|
158 | - if ( isset( $data[ $key ] ) ) { |
|
159 | - $data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] ); |
|
157 | + foreach ($format_decimal as $key) { |
|
158 | + if (isset($data[$key])) { |
|
159 | + $data[$key] = wc_format_decimal($data[$key], $this->request['dp']); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Add SKU and PRICE to products. |
164 | - if ( is_callable( array( $item, 'get_product' ) ) ) { |
|
164 | + if (is_callable(array($item, 'get_product'))) { |
|
165 | 165 | $data['sku'] = $item->get_product() ? $item->get_product()->get_sku() : null; |
166 | 166 | $data['price'] = $item->get_quantity() ? $item->get_total() / $item->get_quantity() : 0; |
167 | 167 | } |
168 | 168 | |
169 | 169 | // Format taxes. |
170 | - if ( ! empty( $data['taxes']['total'] ) ) { |
|
170 | + if ( ! empty($data['taxes']['total'])) { |
|
171 | 171 | $taxes = array(); |
172 | 172 | |
173 | - foreach ( $data['taxes']['total'] as $tax_rate_id => $tax ) { |
|
173 | + foreach ($data['taxes']['total'] as $tax_rate_id => $tax) { |
|
174 | 174 | $taxes[] = array( |
175 | 175 | 'id' => $tax_rate_id, |
176 | 176 | 'total' => $tax, |
177 | - 'subtotal' => isset( $data['taxes']['subtotal'][ $tax_rate_id ] ) ? $data['taxes']['subtotal'][ $tax_rate_id ] : '', |
|
177 | + 'subtotal' => isset($data['taxes']['subtotal'][$tax_rate_id]) ? $data['taxes']['subtotal'][$tax_rate_id] : '', |
|
178 | 178 | ); |
179 | 179 | } |
180 | 180 | $data['taxes'] = $taxes; |
181 | - } elseif ( isset( $data['taxes'] ) ) { |
|
181 | + } elseif (isset($data['taxes'])) { |
|
182 | 182 | $data['taxes'] = array(); |
183 | 183 | } |
184 | 184 | |
185 | 185 | // Remove names for coupons, taxes and shipping. |
186 | - if ( isset( $data['code'] ) || isset( $data['rate_code'] ) || isset( $data['method_title'] ) ) { |
|
187 | - unset( $data['name'] ); |
|
186 | + if (isset($data['code']) || isset($data['rate_code']) || isset($data['method_title'])) { |
|
187 | + unset($data['name']); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | // Remove props we don't want to expose. |
191 | - unset( $data['order_id'] ); |
|
192 | - unset( $data['type'] ); |
|
191 | + unset($data['order_id']); |
|
192 | + unset($data['type']); |
|
193 | 193 | |
194 | 194 | return $data; |
195 | 195 | } |
@@ -201,45 +201,45 @@ discard block |
||
201 | 201 | * @param WC_Data $object WC_Data instance. |
202 | 202 | * @return array |
203 | 203 | */ |
204 | - protected function get_formatted_item_data( $object ) { |
|
204 | + protected function get_formatted_item_data($object) { |
|
205 | 205 | $data = $object->get_data(); |
206 | - $format_decimal = array( 'discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax' ); |
|
207 | - $format_date = array( 'date_created', 'date_modified', 'date_completed', 'date_paid' ); |
|
208 | - $format_line_items = array( 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines' ); |
|
206 | + $format_decimal = array('discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax'); |
|
207 | + $format_date = array('date_created', 'date_modified', 'date_completed', 'date_paid'); |
|
208 | + $format_line_items = array('line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines'); |
|
209 | 209 | |
210 | 210 | // Format decimal values. |
211 | - foreach ( $format_decimal as $key ) { |
|
212 | - $data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] ); |
|
211 | + foreach ($format_decimal as $key) { |
|
212 | + $data[$key] = wc_format_decimal($data[$key], $this->request['dp']); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | // Format date values. |
216 | - foreach ( $format_date as $key ) { |
|
217 | - $datetime = $data[ $key ]; |
|
218 | - $data[ $key ] = wc_rest_prepare_date_response( $datetime, false ); |
|
219 | - $data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime ); |
|
216 | + foreach ($format_date as $key) { |
|
217 | + $datetime = $data[$key]; |
|
218 | + $data[$key] = wc_rest_prepare_date_response($datetime, false); |
|
219 | + $data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | // Format the order status. |
223 | - $data['status'] = 'wc-' === substr( $data['status'], 0, 3 ) ? substr( $data['status'], 3 ) : $data['status']; |
|
223 | + $data['status'] = 'wc-' === substr($data['status'], 0, 3) ? substr($data['status'], 3) : $data['status']; |
|
224 | 224 | |
225 | 225 | // Format line items. |
226 | - foreach ( $format_line_items as $key ) { |
|
227 | - $data[ $key ] = array_values( array_map( array( $this, 'get_order_item_data' ), $data[ $key ] ) ); |
|
226 | + foreach ($format_line_items as $key) { |
|
227 | + $data[$key] = array_values(array_map(array($this, 'get_order_item_data'), $data[$key])); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // Refunds. |
231 | 231 | $data['refunds'] = array(); |
232 | - foreach ( $object->get_refunds() as $refund ) { |
|
232 | + foreach ($object->get_refunds() as $refund) { |
|
233 | 233 | $data['refunds'][] = array( |
234 | 234 | 'id' => $refund->get_id(), |
235 | 235 | 'reason' => $refund->get_reason() ? $refund->get_reason() : '', |
236 | - 'total' => '-' . wc_format_decimal( $refund->get_amount(), $this->request['dp'] ), |
|
236 | + 'total' => '-' . wc_format_decimal($refund->get_amount(), $this->request['dp']), |
|
237 | 237 | ); |
238 | 238 | } |
239 | 239 | |
240 | 240 | // Currency symbols. |
241 | - $currency_symbol = get_woocommerce_currency_symbol( $data['currency'] ); |
|
242 | - $data['currency_symbol'] = html_entity_decode( $currency_symbol ); |
|
241 | + $currency_symbol = get_woocommerce_currency_symbol($data['currency']); |
|
242 | + $data['currency_symbol'] = html_entity_decode($currency_symbol); |
|
243 | 243 | |
244 | 244 | return array( |
245 | 245 | 'id' => $object->get_id(), |
@@ -295,15 +295,15 @@ discard block |
||
295 | 295 | * @param \WP_REST_Request $request Request object. |
296 | 296 | * @return \WP_REST_Response |
297 | 297 | */ |
298 | - public function prepare_object_for_response( $object, $request ) { |
|
298 | + public function prepare_object_for_response($object, $request) { |
|
299 | 299 | $this->request = $request; |
300 | - $this->request['dp'] = is_null( $this->request['dp'] ) ? wc_get_price_decimals() : absint( $this->request['dp'] ); |
|
301 | - $data = $this->get_formatted_item_data( $object ); |
|
302 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
303 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
304 | - $data = $this->filter_response_by_context( $data, $context ); |
|
305 | - $response = rest_ensure_response( $data ); |
|
306 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
300 | + $this->request['dp'] = is_null($this->request['dp']) ? wc_get_price_decimals() : absint($this->request['dp']); |
|
301 | + $data = $this->get_formatted_item_data($object); |
|
302 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
303 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
304 | + $data = $this->filter_response_by_context($data, $context); |
|
305 | + $response = rest_ensure_response($data); |
|
306 | + $response->add_links($this->prepare_links($object, $request)); |
|
307 | 307 | |
308 | 308 | /** |
309 | 309 | * Filter the data for a response. |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | * @param WC_Data $object Object data. |
316 | 316 | * @param \WP_REST_Request $request Request object. |
317 | 317 | */ |
318 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
318 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -325,25 +325,25 @@ discard block |
||
325 | 325 | * @param \WP_REST_Request $request Request object. |
326 | 326 | * @return array Links for the given post. |
327 | 327 | */ |
328 | - protected function prepare_links( $object, $request ) { |
|
328 | + protected function prepare_links($object, $request) { |
|
329 | 329 | $links = array( |
330 | 330 | 'self' => array( |
331 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ), |
|
331 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())), |
|
332 | 332 | ), |
333 | 333 | 'collection' => array( |
334 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
334 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
335 | 335 | ), |
336 | 336 | ); |
337 | 337 | |
338 | - if ( 0 !== (int) $object->get_customer_id() ) { |
|
338 | + if (0 !== (int) $object->get_customer_id()) { |
|
339 | 339 | $links['customer'] = array( |
340 | - 'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $object->get_customer_id() ) ), |
|
340 | + 'href' => rest_url(sprintf('/%s/customers/%d', $this->namespace, $object->get_customer_id())), |
|
341 | 341 | ); |
342 | 342 | } |
343 | 343 | |
344 | - if ( 0 !== (int) $object->get_parent_id() ) { |
|
344 | + if (0 !== (int) $object->get_parent_id()) { |
|
345 | 345 | $links['up'] = array( |
346 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $object->get_parent_id() ) ), |
|
346 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $object->get_parent_id())), |
|
347 | 347 | ); |
348 | 348 | } |
349 | 349 | |
@@ -357,19 +357,19 @@ discard block |
||
357 | 357 | * @param \WP_REST_Request $request Full details about the request. |
358 | 358 | * @return array |
359 | 359 | */ |
360 | - protected function prepare_objects_query( $request ) { |
|
360 | + protected function prepare_objects_query($request) { |
|
361 | 361 | global $wpdb; |
362 | 362 | |
363 | 363 | // This is needed to get around an array to string notice in \WC_REST_Orders_V2_Controller::prepare_objects_query. |
364 | 364 | $statuses = $request['status']; |
365 | - unset( $request['status'] ); |
|
366 | - $args = parent::prepare_objects_query( $request ); |
|
365 | + unset($request['status']); |
|
366 | + $args = parent::prepare_objects_query($request); |
|
367 | 367 | |
368 | 368 | $args['post_status'] = array(); |
369 | - foreach ( $statuses as $status ) { |
|
370 | - if ( in_array( $status, $this->get_order_statuses(), true ) ) { |
|
369 | + foreach ($statuses as $status) { |
|
370 | + if (in_array($status, $this->get_order_statuses(), true)) { |
|
371 | 371 | $args['post_status'][] = 'wc-' . $status; |
372 | - } elseif ( 'any' === $status ) { |
|
372 | + } elseif ('any' === $status) { |
|
373 | 373 | // Set status to "any" and short-circuit out. |
374 | 374 | $args['post_status'] = 'any'; |
375 | 375 | break; |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | $request['status'] = $statuses; |
383 | 383 | |
384 | 384 | // Customer. |
385 | - if ( isset( $request['customer'] ) ) { |
|
386 | - if ( ! empty( $args['meta_query'] ) ) { |
|
385 | + if (isset($request['customer'])) { |
|
386 | + if ( ! empty($args['meta_query'])) { |
|
387 | 387 | $args['meta_query'] = array(); // WPCS: slow query ok. |
388 | 388 | } |
389 | 389 | |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | } |
396 | 396 | |
397 | 397 | // Search by product. |
398 | - if ( ! empty( $request['product'] ) ) { |
|
398 | + if ( ! empty($request['product'])) { |
|
399 | 399 | $order_ids = $wpdb->get_col( |
400 | 400 | $wpdb->prepare( |
401 | 401 | "SELECT order_id |
@@ -407,25 +407,25 @@ discard block |
||
407 | 407 | ); |
408 | 408 | |
409 | 409 | // Force WP_Query return empty if don't found any order. |
410 | - $order_ids = ! empty( $order_ids ) ? $order_ids : array( 0 ); |
|
410 | + $order_ids = ! empty($order_ids) ? $order_ids : array(0); |
|
411 | 411 | |
412 | 412 | $args['post__in'] = $order_ids; |
413 | 413 | } |
414 | 414 | |
415 | 415 | // Search. |
416 | - if ( ! empty( $args['s'] ) ) { |
|
417 | - $order_ids = wc_order_search( $args['s'] ); |
|
416 | + if ( ! empty($args['s'])) { |
|
417 | + $order_ids = wc_order_search($args['s']); |
|
418 | 418 | |
419 | - if ( ! empty( $order_ids ) ) { |
|
420 | - unset( $args['s'] ); |
|
421 | - $args['post__in'] = array_merge( $order_ids, array( 0 ) ); |
|
419 | + if ( ! empty($order_ids)) { |
|
420 | + unset($args['s']); |
|
421 | + $args['post__in'] = array_merge($order_ids, array(0)); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | 425 | // Search by partial order number. |
426 | - if ( ! empty( $request['number'] ) ) { |
|
427 | - $partial_number = trim( $request['number'] ); |
|
428 | - $limit = intval( $args['posts_per_page'] ); |
|
426 | + if ( ! empty($request['number'])) { |
|
427 | + $partial_number = trim($request['number']); |
|
428 | + $limit = intval($args['posts_per_page']); |
|
429 | 429 | $order_ids = $wpdb->get_col( |
430 | 430 | $wpdb->prepare( |
431 | 431 | "SELECT ID |
@@ -433,13 +433,13 @@ discard block |
||
433 | 433 | WHERE post_type = 'shop_order' |
434 | 434 | AND ID LIKE %s |
435 | 435 | LIMIT %d", |
436 | - $wpdb->esc_like( absint( $partial_number ) ) . '%', |
|
436 | + $wpdb->esc_like(absint($partial_number)) . '%', |
|
437 | 437 | $limit |
438 | 438 | ) |
439 | 439 | ); |
440 | 440 | |
441 | 441 | // Force \WP_Query return empty if don't found any order. |
442 | - $order_ids = empty( $order_ids ) ? array( 0 ) : $order_ids; |
|
442 | + $order_ids = empty($order_ids) ? array(0) : $order_ids; |
|
443 | 443 | $args['post__in'] = $order_ids; |
444 | 444 | } |
445 | 445 | |
@@ -452,8 +452,8 @@ discard block |
||
452 | 452 | * @param array $schema Schema. |
453 | 453 | * @return bool |
454 | 454 | */ |
455 | - protected function filter_writable_props( $schema ) { |
|
456 | - return empty( $schema['readonly'] ); |
|
455 | + protected function filter_writable_props($schema) { |
|
456 | + return empty($schema['readonly']); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | |
@@ -465,51 +465,51 @@ discard block |
||
465 | 465 | * @param bool $creating If is creating a new object. |
466 | 466 | * @return \WP_Error|WC_Data |
467 | 467 | */ |
468 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
469 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
470 | - $order = new \WC_Order( $id ); |
|
468 | + protected function prepare_object_for_database($request, $creating = false) { |
|
469 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
470 | + $order = new \WC_Order($id); |
|
471 | 471 | $schema = $this->get_item_schema(); |
472 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
472 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
473 | 473 | |
474 | 474 | // Handle all writable props. |
475 | - foreach ( $data_keys as $key ) { |
|
476 | - $value = $request[ $key ]; |
|
475 | + foreach ($data_keys as $key) { |
|
476 | + $value = $request[$key]; |
|
477 | 477 | |
478 | - if ( ! is_null( $value ) ) { |
|
479 | - switch ( $key ) { |
|
478 | + if ( ! is_null($value)) { |
|
479 | + switch ($key) { |
|
480 | 480 | case 'coupon_lines': |
481 | 481 | case 'status': |
482 | 482 | // Change should be done later so transitions have new data. |
483 | 483 | break; |
484 | 484 | case 'billing': |
485 | 485 | case 'shipping': |
486 | - $this->update_address( $order, $value, $key ); |
|
486 | + $this->update_address($order, $value, $key); |
|
487 | 487 | break; |
488 | 488 | case 'line_items': |
489 | 489 | case 'shipping_lines': |
490 | 490 | case 'fee_lines': |
491 | - if ( is_array( $value ) ) { |
|
492 | - foreach ( $value as $item ) { |
|
493 | - if ( is_array( $item ) ) { |
|
494 | - if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) { |
|
495 | - $order->remove_item( $item['id'] ); |
|
491 | + if (is_array($value)) { |
|
492 | + foreach ($value as $item) { |
|
493 | + if (is_array($item)) { |
|
494 | + if ($this->item_is_null($item) || (isset($item['quantity']) && 0 === $item['quantity'])) { |
|
495 | + $order->remove_item($item['id']); |
|
496 | 496 | } else { |
497 | - $this->set_item( $order, $key, $item ); |
|
497 | + $this->set_item($order, $key, $item); |
|
498 | 498 | } |
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
502 | 502 | break; |
503 | 503 | case 'meta_data': |
504 | - if ( is_array( $value ) ) { |
|
505 | - foreach ( $value as $meta ) { |
|
506 | - $order->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
504 | + if (is_array($value)) { |
|
505 | + foreach ($value as $meta) { |
|
506 | + $order->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
507 | 507 | } |
508 | 508 | } |
509 | 509 | break; |
510 | 510 | default: |
511 | - if ( is_callable( array( $order, "set_{$key}" ) ) ) { |
|
512 | - $order->{"set_{$key}"}( $value ); |
|
511 | + if (is_callable(array($order, "set_{$key}"))) { |
|
512 | + $order->{"set_{$key}"}($value); |
|
513 | 513 | } |
514 | 514 | break; |
515 | 515 | } |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | * @param \WP_REST_Request $request Request object. |
527 | 527 | * @param bool $creating If is creating a new object. |
528 | 528 | */ |
529 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating ); |
|
529 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | /** |
@@ -537,62 +537,62 @@ discard block |
||
537 | 537 | * @return WC_Data|\WP_Error |
538 | 538 | * @throws \WC_REST_Exception But all errors are validated before returning any data. |
539 | 539 | */ |
540 | - protected function save_object( $request, $creating = false ) { |
|
540 | + protected function save_object($request, $creating = false) { |
|
541 | 541 | try { |
542 | - $object = $this->prepare_object_for_database( $request, $creating ); |
|
542 | + $object = $this->prepare_object_for_database($request, $creating); |
|
543 | 543 | |
544 | - if ( is_wp_error( $object ) ) { |
|
544 | + if (is_wp_error($object)) { |
|
545 | 545 | return $object; |
546 | 546 | } |
547 | 547 | |
548 | 548 | // Make sure gateways are loaded so hooks from gateways fire on save/create. |
549 | 549 | WC()->payment_gateways(); |
550 | 550 | |
551 | - if ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] ) { |
|
551 | + if ( ! is_null($request['customer_id']) && 0 !== $request['customer_id']) { |
|
552 | 552 | // Make sure customer exists. |
553 | - if ( false === get_user_by( 'id', $request['customer_id'] ) ) { |
|
554 | - throw new \WC_REST_Exception( 'woocommerce_rest_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce' ), 400 ); |
|
553 | + if (false === get_user_by('id', $request['customer_id'])) { |
|
554 | + throw new \WC_REST_Exception('woocommerce_rest_invalid_customer_id', __('Customer ID is invalid.', 'woocommerce'), 400); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | // Make sure customer is part of blog. |
558 | - if ( is_multisite() && ! is_user_member_of_blog( $request['customer_id'] ) ) { |
|
559 | - add_user_to_blog( get_current_blog_id(), $request['customer_id'], 'customer' ); |
|
558 | + if (is_multisite() && ! is_user_member_of_blog($request['customer_id'])) { |
|
559 | + add_user_to_blog(get_current_blog_id(), $request['customer_id'], 'customer'); |
|
560 | 560 | } |
561 | 561 | } |
562 | 562 | |
563 | - if ( $creating ) { |
|
564 | - $object->set_created_via( 'rest-api' ); |
|
565 | - $object->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) ); |
|
563 | + if ($creating) { |
|
564 | + $object->set_created_via('rest-api'); |
|
565 | + $object->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax')); |
|
566 | 566 | $object->calculate_totals(); |
567 | 567 | } else { |
568 | 568 | // If items have changed, recalculate order totals. |
569 | - if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) { |
|
570 | - $object->calculate_totals( true ); |
|
569 | + if (isset($request['billing']) || isset($request['shipping']) || isset($request['line_items']) || isset($request['shipping_lines']) || isset($request['fee_lines']) || isset($request['coupon_lines'])) { |
|
570 | + $object->calculate_totals(true); |
|
571 | 571 | } |
572 | 572 | } |
573 | 573 | |
574 | 574 | // Set coupons. |
575 | - $this->calculate_coupons( $request, $object ); |
|
575 | + $this->calculate_coupons($request, $object); |
|
576 | 576 | |
577 | 577 | // Set status. |
578 | - if ( ! empty( $request['status'] ) ) { |
|
579 | - $object->set_status( $request['status'] ); |
|
578 | + if ( ! empty($request['status'])) { |
|
579 | + $object->set_status($request['status']); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | $object->save(); |
583 | 583 | |
584 | 584 | // Actions for after the order is saved. |
585 | - if ( true === $request['set_paid'] ) { |
|
586 | - if ( $creating || $object->needs_payment() ) { |
|
587 | - $object->payment_complete( $request['transaction_id'] ); |
|
585 | + if (true === $request['set_paid']) { |
|
586 | + if ($creating || $object->needs_payment()) { |
|
587 | + $object->payment_complete($request['transaction_id']); |
|
588 | 588 | } |
589 | 589 | } |
590 | 590 | |
591 | - return $this->get_object( $object->get_id() ); |
|
592 | - } catch ( \WC_Data_Exception $e ) { |
|
593 | - return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
594 | - } catch ( \WC_REST_Exception $e ) { |
|
595 | - return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
591 | + return $this->get_object($object->get_id()); |
|
592 | + } catch (\WC_Data_Exception $e) { |
|
593 | + return new \WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData()); |
|
594 | + } catch (\WC_REST_Exception $e) { |
|
595 | + return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
596 | 596 | } |
597 | 597 | } |
598 | 598 | |
@@ -603,10 +603,10 @@ discard block |
||
603 | 603 | * @param array $posted Posted data. |
604 | 604 | * @param string $type Address type. |
605 | 605 | */ |
606 | - protected function update_address( $order, $posted, $type = 'billing' ) { |
|
607 | - foreach ( $posted as $key => $value ) { |
|
608 | - if ( is_callable( array( $order, "set_{$type}_{$key}" ) ) ) { |
|
609 | - $order->{"set_{$type}_{$key}"}( $value ); |
|
606 | + protected function update_address($order, $posted, $type = 'billing') { |
|
607 | + foreach ($posted as $key => $value) { |
|
608 | + if (is_callable(array($order, "set_{$type}_{$key}"))) { |
|
609 | + $order->{"set_{$type}_{$key}"}($value); |
|
610 | 610 | } |
611 | 611 | } |
612 | 612 | } |
@@ -618,15 +618,15 @@ discard block |
||
618 | 618 | * @return int |
619 | 619 | * @throws \WC_REST_Exception When SKU or ID is not valid. |
620 | 620 | */ |
621 | - protected function get_product_id( $posted ) { |
|
622 | - if ( ! empty( $posted['sku'] ) ) { |
|
623 | - $product_id = (int) wc_get_product_id_by_sku( $posted['sku'] ); |
|
624 | - } elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) { |
|
621 | + protected function get_product_id($posted) { |
|
622 | + if ( ! empty($posted['sku'])) { |
|
623 | + $product_id = (int) wc_get_product_id_by_sku($posted['sku']); |
|
624 | + } elseif ( ! empty($posted['product_id']) && empty($posted['variation_id'])) { |
|
625 | 625 | $product_id = (int) $posted['product_id']; |
626 | - } elseif ( ! empty( $posted['variation_id'] ) ) { |
|
626 | + } elseif ( ! empty($posted['variation_id'])) { |
|
627 | 627 | $product_id = (int) $posted['variation_id']; |
628 | 628 | } else { |
629 | - throw new \WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce' ), 400 ); |
|
629 | + throw new \WC_REST_Exception('woocommerce_rest_required_product_reference', __('Product ID or SKU is required.', 'woocommerce'), 400); |
|
630 | 630 | } |
631 | 631 | return $product_id; |
632 | 632 | } |
@@ -638,9 +638,9 @@ discard block |
||
638 | 638 | * @param string $prop Order property. |
639 | 639 | * @param array $posted Request data. |
640 | 640 | */ |
641 | - protected function maybe_set_item_prop( $item, $prop, $posted ) { |
|
642 | - if ( isset( $posted[ $prop ] ) ) { |
|
643 | - $item->{"set_$prop"}( $posted[ $prop ] ); |
|
641 | + protected function maybe_set_item_prop($item, $prop, $posted) { |
|
642 | + if (isset($posted[$prop])) { |
|
643 | + $item->{"set_$prop"}($posted[$prop]); |
|
644 | 644 | } |
645 | 645 | } |
646 | 646 | |
@@ -651,9 +651,9 @@ discard block |
||
651 | 651 | * @param string[] $props Properties. |
652 | 652 | * @param array $posted Request data. |
653 | 653 | */ |
654 | - protected function maybe_set_item_props( $item, $props, $posted ) { |
|
655 | - foreach ( $props as $prop ) { |
|
656 | - $this->maybe_set_item_prop( $item, $prop, $posted ); |
|
654 | + protected function maybe_set_item_props($item, $props, $posted) { |
|
655 | + foreach ($props as $prop) { |
|
656 | + $this->maybe_set_item_prop($item, $prop, $posted); |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | |
@@ -663,12 +663,12 @@ discard block |
||
663 | 663 | * @param WC_Order_Item $item Order item data. |
664 | 664 | * @param array $posted Request data. |
665 | 665 | */ |
666 | - protected function maybe_set_item_meta_data( $item, $posted ) { |
|
667 | - if ( ! empty( $posted['meta_data'] ) && is_array( $posted['meta_data'] ) ) { |
|
668 | - foreach ( $posted['meta_data'] as $meta ) { |
|
669 | - if ( isset( $meta['key'] ) ) { |
|
670 | - $value = isset( $meta['value'] ) ? $meta['value'] : null; |
|
671 | - $item->update_meta_data( $meta['key'], $value, isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
666 | + protected function maybe_set_item_meta_data($item, $posted) { |
|
667 | + if ( ! empty($posted['meta_data']) && is_array($posted['meta_data'])) { |
|
668 | + foreach ($posted['meta_data'] as $meta) { |
|
669 | + if (isset($meta['key'])) { |
|
670 | + $value = isset($meta['value']) ? $meta['value'] : null; |
|
671 | + $item->update_meta_data($meta['key'], $value, isset($meta['id']) ? $meta['id'] : ''); |
|
672 | 672 | } |
673 | 673 | } |
674 | 674 | } |
@@ -683,23 +683,23 @@ discard block |
||
683 | 683 | * @return WC_Order_Item_Product |
684 | 684 | * @throws WC_REST_Exception Invalid data, server error. |
685 | 685 | */ |
686 | - protected function prepare_line_items( $posted, $action = 'create', $item = null ) { |
|
687 | - $item = is_null( $item ) ? new \WC_Order_Item_Product( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
688 | - $product = wc_get_product( $this->get_product_id( $posted ) ); |
|
689 | - |
|
690 | - if ( $product !== $item->get_product() ) { |
|
691 | - $item->set_product( $product ); |
|
692 | - |
|
693 | - if ( 'create' === $action ) { |
|
694 | - $quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1; |
|
695 | - $total = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) ); |
|
696 | - $item->set_total( $total ); |
|
697 | - $item->set_subtotal( $total ); |
|
686 | + protected function prepare_line_items($posted, $action = 'create', $item = null) { |
|
687 | + $item = is_null($item) ? new \WC_Order_Item_Product( ! empty($posted['id']) ? $posted['id'] : '') : $item; |
|
688 | + $product = wc_get_product($this->get_product_id($posted)); |
|
689 | + |
|
690 | + if ($product !== $item->get_product()) { |
|
691 | + $item->set_product($product); |
|
692 | + |
|
693 | + if ('create' === $action) { |
|
694 | + $quantity = isset($posted['quantity']) ? $posted['quantity'] : 1; |
|
695 | + $total = wc_get_price_excluding_tax($product, array('qty' => $quantity)); |
|
696 | + $item->set_total($total); |
|
697 | + $item->set_subtotal($total); |
|
698 | 698 | } |
699 | 699 | } |
700 | 700 | |
701 | - $this->maybe_set_item_props( $item, array( 'name', 'quantity', 'total', 'subtotal', 'tax_class' ), $posted ); |
|
702 | - $this->maybe_set_item_meta_data( $item, $posted ); |
|
701 | + $this->maybe_set_item_props($item, array('name', 'quantity', 'total', 'subtotal', 'tax_class'), $posted); |
|
702 | + $this->maybe_set_item_meta_data($item, $posted); |
|
703 | 703 | |
704 | 704 | return $item; |
705 | 705 | } |
@@ -713,17 +713,17 @@ discard block |
||
713 | 713 | * @return WC_Order_Item_Shipping |
714 | 714 | * @throws WC_REST_Exception Invalid data, server error. |
715 | 715 | */ |
716 | - protected function prepare_shipping_lines( $posted, $action = 'create', $item = null ) { |
|
717 | - $item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
716 | + protected function prepare_shipping_lines($posted, $action = 'create', $item = null) { |
|
717 | + $item = is_null($item) ? new \WC_Order_Item_Shipping( ! empty($posted['id']) ? $posted['id'] : '') : $item; |
|
718 | 718 | |
719 | - if ( 'create' === $action ) { |
|
720 | - if ( empty( $posted['method_id'] ) ) { |
|
721 | - throw new \WC_REST_Exception( 'woocommerce_rest_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce' ), 400 ); |
|
719 | + if ('create' === $action) { |
|
720 | + if (empty($posted['method_id'])) { |
|
721 | + throw new \WC_REST_Exception('woocommerce_rest_invalid_shipping_item', __('Shipping method ID is required.', 'woocommerce'), 400); |
|
722 | 722 | } |
723 | 723 | } |
724 | 724 | |
725 | - $this->maybe_set_item_props( $item, array( 'method_id', 'method_title', 'total' ), $posted ); |
|
726 | - $this->maybe_set_item_meta_data( $item, $posted ); |
|
725 | + $this->maybe_set_item_props($item, array('method_id', 'method_title', 'total'), $posted); |
|
726 | + $this->maybe_set_item_meta_data($item, $posted); |
|
727 | 727 | |
728 | 728 | return $item; |
729 | 729 | } |
@@ -737,17 +737,17 @@ discard block |
||
737 | 737 | * @return WC_Order_Item_Fee |
738 | 738 | * @throws WC_REST_Exception Invalid data, server error. |
739 | 739 | */ |
740 | - protected function prepare_fee_lines( $posted, $action = 'create', $item = null ) { |
|
741 | - $item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
740 | + protected function prepare_fee_lines($posted, $action = 'create', $item = null) { |
|
741 | + $item = is_null($item) ? new \WC_Order_Item_Fee( ! empty($posted['id']) ? $posted['id'] : '') : $item; |
|
742 | 742 | |
743 | - if ( 'create' === $action ) { |
|
744 | - if ( empty( $posted['name'] ) ) { |
|
745 | - throw new \WC_REST_Exception( 'woocommerce_rest_invalid_fee_item', __( 'Fee name is required.', 'woocommerce' ), 400 ); |
|
743 | + if ('create' === $action) { |
|
744 | + if (empty($posted['name'])) { |
|
745 | + throw new \WC_REST_Exception('woocommerce_rest_invalid_fee_item', __('Fee name is required.', 'woocommerce'), 400); |
|
746 | 746 | } |
747 | 747 | } |
748 | 748 | |
749 | - $this->maybe_set_item_props( $item, array( 'name', 'tax_class', 'tax_status', 'total' ), $posted ); |
|
750 | - $this->maybe_set_item_meta_data( $item, $posted ); |
|
749 | + $this->maybe_set_item_props($item, array('name', 'tax_class', 'tax_status', 'total'), $posted); |
|
750 | + $this->maybe_set_item_meta_data($item, $posted); |
|
751 | 751 | |
752 | 752 | return $item; |
753 | 753 | } |
@@ -761,17 +761,17 @@ discard block |
||
761 | 761 | * @return WC_Order_Item_Coupon |
762 | 762 | * @throws WC_REST_Exception Invalid data, server error. |
763 | 763 | */ |
764 | - protected function prepare_coupon_lines( $posted, $action = 'create', $item = null ) { |
|
765 | - $item = is_null( $item ) ? new \WC_Order_Item_Coupon( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item; |
|
764 | + protected function prepare_coupon_lines($posted, $action = 'create', $item = null) { |
|
765 | + $item = is_null($item) ? new \WC_Order_Item_Coupon( ! empty($posted['id']) ? $posted['id'] : '') : $item; |
|
766 | 766 | |
767 | - if ( 'create' === $action ) { |
|
768 | - if ( empty( $posted['code'] ) ) { |
|
769 | - throw new \WC_REST_Exception( 'woocommerce_rest_invalid_coupon_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 ); |
|
767 | + if ('create' === $action) { |
|
768 | + if (empty($posted['code'])) { |
|
769 | + throw new \WC_REST_Exception('woocommerce_rest_invalid_coupon_coupon', __('Coupon code is required.', 'woocommerce'), 400); |
|
770 | 770 | } |
771 | 771 | } |
772 | 772 | |
773 | - $this->maybe_set_item_props( $item, array( 'code', 'discount' ), $posted ); |
|
774 | - $this->maybe_set_item_meta_data( $item, $posted ); |
|
773 | + $this->maybe_set_item_props($item, array('code', 'discount'), $posted); |
|
774 | + $this->maybe_set_item_meta_data($item, $posted); |
|
775 | 775 | |
776 | 776 | return $item; |
777 | 777 | } |
@@ -786,10 +786,10 @@ discard block |
||
786 | 786 | * @param array $posted item provided in the request body. |
787 | 787 | * @throws WC_REST_Exception If item ID is not associated with order. |
788 | 788 | */ |
789 | - protected function set_item( $order, $item_type, $posted ) { |
|
789 | + protected function set_item($order, $item_type, $posted) { |
|
790 | 790 | global $wpdb; |
791 | 791 | |
792 | - if ( ! empty( $posted['id'] ) ) { |
|
792 | + if ( ! empty($posted['id'])) { |
|
793 | 793 | $action = 'update'; |
794 | 794 | } else { |
795 | 795 | $action = 'create'; |
@@ -799,22 +799,22 @@ discard block |
||
799 | 799 | $item = null; |
800 | 800 | |
801 | 801 | // Verify provided line item ID is associated with order. |
802 | - if ( 'update' === $action ) { |
|
803 | - $item = $order->get_item( absint( $posted['id'] ), false ); |
|
802 | + if ('update' === $action) { |
|
803 | + $item = $order->get_item(absint($posted['id']), false); |
|
804 | 804 | |
805 | - if ( ! $item ) { |
|
806 | - throw new \WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 ); |
|
805 | + if ( ! $item) { |
|
806 | + throw new \WC_REST_Exception('woocommerce_rest_invalid_item_id', __('Order item ID provided is not associated with order.', 'woocommerce'), 400); |
|
807 | 807 | } |
808 | 808 | } |
809 | 809 | |
810 | 810 | // Prepare item data. |
811 | - $item = $this->$method( $posted, $action, $item ); |
|
811 | + $item = $this->$method($posted, $action, $item); |
|
812 | 812 | |
813 | - do_action( 'woocommerce_rest_set_order_item', $item, $posted ); |
|
813 | + do_action('woocommerce_rest_set_order_item', $item, $posted); |
|
814 | 814 | |
815 | 815 | // If creating the order, add the item to it. |
816 | - if ( 'create' === $action ) { |
|
817 | - $order->add_item( $item ); |
|
816 | + if ('create' === $action) { |
|
817 | + $order->add_item($item); |
|
818 | 818 | } else { |
819 | 819 | $item->save(); |
820 | 820 | } |
@@ -827,11 +827,11 @@ discard block |
||
827 | 827 | * @param array $item Item provided in the request body. |
828 | 828 | * @return bool True if the item resource ID is null, false otherwise. |
829 | 829 | */ |
830 | - protected function item_is_null( $item ) { |
|
831 | - $keys = array( 'product_id', 'method_id', 'method_title', 'name', 'code' ); |
|
830 | + protected function item_is_null($item) { |
|
831 | + $keys = array('product_id', 'method_id', 'method_title', 'name', 'code'); |
|
832 | 832 | |
833 | - foreach ( $keys as $key ) { |
|
834 | - if ( array_key_exists( $key, $item ) && is_null( $item[ $key ] ) ) { |
|
833 | + foreach ($keys as $key) { |
|
834 | + if (array_key_exists($key, $item) && is_null($item[$key])) { |
|
835 | 835 | return true; |
836 | 836 | } |
837 | 837 | } |
@@ -847,8 +847,8 @@ discard block |
||
847 | 847 | protected function get_order_statuses() { |
848 | 848 | $order_statuses = array(); |
849 | 849 | |
850 | - foreach ( array_keys( wc_get_order_statuses() ) as $status ) { |
|
851 | - $order_statuses[] = str_replace( 'wc-', '', $status ); |
|
850 | + foreach (array_keys(wc_get_order_statuses()) as $status) { |
|
851 | + $order_statuses[] = str_replace('wc-', '', $status); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | return $order_statuses; |
@@ -866,543 +866,543 @@ discard block |
||
866 | 866 | 'type' => 'object', |
867 | 867 | 'properties' => array( |
868 | 868 | 'id' => array( |
869 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
869 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
870 | 870 | 'type' => 'integer', |
871 | - 'context' => array( 'view', 'edit' ), |
|
871 | + 'context' => array('view', 'edit'), |
|
872 | 872 | 'readonly' => true, |
873 | 873 | ), |
874 | 874 | 'parent_id' => array( |
875 | - 'description' => __( 'Parent order ID.', 'woocommerce' ), |
|
875 | + 'description' => __('Parent order ID.', 'woocommerce'), |
|
876 | 876 | 'type' => 'integer', |
877 | - 'context' => array( 'view', 'edit' ), |
|
877 | + 'context' => array('view', 'edit'), |
|
878 | 878 | ), |
879 | 879 | 'number' => array( |
880 | - 'description' => __( 'Order number.', 'woocommerce' ), |
|
880 | + 'description' => __('Order number.', 'woocommerce'), |
|
881 | 881 | 'type' => 'string', |
882 | - 'context' => array( 'view', 'edit' ), |
|
882 | + 'context' => array('view', 'edit'), |
|
883 | 883 | 'readonly' => true, |
884 | 884 | ), |
885 | 885 | 'order_key' => array( |
886 | - 'description' => __( 'Order key.', 'woocommerce' ), |
|
886 | + 'description' => __('Order key.', 'woocommerce'), |
|
887 | 887 | 'type' => 'string', |
888 | - 'context' => array( 'view', 'edit' ), |
|
888 | + 'context' => array('view', 'edit'), |
|
889 | 889 | 'readonly' => true, |
890 | 890 | ), |
891 | 891 | 'created_via' => array( |
892 | - 'description' => __( 'Shows where the order was created.', 'woocommerce' ), |
|
892 | + 'description' => __('Shows where the order was created.', 'woocommerce'), |
|
893 | 893 | 'type' => 'string', |
894 | - 'context' => array( 'view', 'edit' ), |
|
894 | + 'context' => array('view', 'edit'), |
|
895 | 895 | 'readonly' => true, |
896 | 896 | ), |
897 | 897 | 'version' => array( |
898 | - 'description' => __( 'Version of WooCommerce which last updated the order.', 'woocommerce' ), |
|
898 | + 'description' => __('Version of WooCommerce which last updated the order.', 'woocommerce'), |
|
899 | 899 | 'type' => 'integer', |
900 | - 'context' => array( 'view', 'edit' ), |
|
900 | + 'context' => array('view', 'edit'), |
|
901 | 901 | 'readonly' => true, |
902 | 902 | ), |
903 | 903 | 'status' => array( |
904 | - 'description' => __( 'Order status.', 'woocommerce' ), |
|
904 | + 'description' => __('Order status.', 'woocommerce'), |
|
905 | 905 | 'type' => 'string', |
906 | 906 | 'default' => 'pending', |
907 | 907 | 'enum' => $this->get_order_statuses(), |
908 | - 'context' => array( 'view', 'edit' ), |
|
908 | + 'context' => array('view', 'edit'), |
|
909 | 909 | ), |
910 | 910 | 'currency' => array( |
911 | - 'description' => __( 'Currency the order was created with, in ISO format.', 'woocommerce' ), |
|
911 | + 'description' => __('Currency the order was created with, in ISO format.', 'woocommerce'), |
|
912 | 912 | 'type' => 'string', |
913 | 913 | 'default' => get_woocommerce_currency(), |
914 | - 'enum' => array_keys( get_woocommerce_currencies() ), |
|
915 | - 'context' => array( 'view', 'edit' ), |
|
914 | + 'enum' => array_keys(get_woocommerce_currencies()), |
|
915 | + 'context' => array('view', 'edit'), |
|
916 | 916 | ), |
917 | 917 | 'currency_symbol' => array( |
918 | - 'description' => __( 'Currency symbol.', 'woocommerce' ), |
|
918 | + 'description' => __('Currency symbol.', 'woocommerce'), |
|
919 | 919 | 'type' => 'string', |
920 | - 'context' => array( 'view', 'edit' ), |
|
920 | + 'context' => array('view', 'edit'), |
|
921 | 921 | 'readonly' => true, |
922 | 922 | ), |
923 | 923 | 'date_created' => array( |
924 | - 'description' => __( "The date the order was created, in the site's timezone.", 'woocommerce' ), |
|
924 | + 'description' => __("The date the order was created, in the site's timezone.", 'woocommerce'), |
|
925 | 925 | 'type' => 'date-time', |
926 | - 'context' => array( 'view', 'edit' ), |
|
926 | + 'context' => array('view', 'edit'), |
|
927 | 927 | 'readonly' => true, |
928 | 928 | ), |
929 | 929 | 'date_created_gmt' => array( |
930 | - 'description' => __( 'The date the order was created, as GMT.', 'woocommerce' ), |
|
930 | + 'description' => __('The date the order was created, as GMT.', 'woocommerce'), |
|
931 | 931 | 'type' => 'date-time', |
932 | - 'context' => array( 'view', 'edit' ), |
|
932 | + 'context' => array('view', 'edit'), |
|
933 | 933 | 'readonly' => true, |
934 | 934 | ), |
935 | 935 | 'date_modified' => array( |
936 | - 'description' => __( "The date the order was last modified, in the site's timezone.", 'woocommerce' ), |
|
936 | + 'description' => __("The date the order was last modified, in the site's timezone.", 'woocommerce'), |
|
937 | 937 | 'type' => 'date-time', |
938 | - 'context' => array( 'view', 'edit' ), |
|
938 | + 'context' => array('view', 'edit'), |
|
939 | 939 | 'readonly' => true, |
940 | 940 | ), |
941 | 941 | 'date_modified_gmt' => array( |
942 | - 'description' => __( 'The date the order was last modified, as GMT.', 'woocommerce' ), |
|
942 | + 'description' => __('The date the order was last modified, as GMT.', 'woocommerce'), |
|
943 | 943 | 'type' => 'date-time', |
944 | - 'context' => array( 'view', 'edit' ), |
|
944 | + 'context' => array('view', 'edit'), |
|
945 | 945 | 'readonly' => true, |
946 | 946 | ), |
947 | 947 | 'discount_total' => array( |
948 | - 'description' => __( 'Total discount amount for the order.', 'woocommerce' ), |
|
948 | + 'description' => __('Total discount amount for the order.', 'woocommerce'), |
|
949 | 949 | 'type' => 'string', |
950 | - 'context' => array( 'view', 'edit' ), |
|
950 | + 'context' => array('view', 'edit'), |
|
951 | 951 | 'readonly' => true, |
952 | 952 | ), |
953 | 953 | 'discount_tax' => array( |
954 | - 'description' => __( 'Total discount tax amount for the order.', 'woocommerce' ), |
|
954 | + 'description' => __('Total discount tax amount for the order.', 'woocommerce'), |
|
955 | 955 | 'type' => 'string', |
956 | - 'context' => array( 'view', 'edit' ), |
|
956 | + 'context' => array('view', 'edit'), |
|
957 | 957 | 'readonly' => true, |
958 | 958 | ), |
959 | 959 | 'shipping_total' => array( |
960 | - 'description' => __( 'Total shipping amount for the order.', 'woocommerce' ), |
|
960 | + 'description' => __('Total shipping amount for the order.', 'woocommerce'), |
|
961 | 961 | 'type' => 'string', |
962 | - 'context' => array( 'view', 'edit' ), |
|
962 | + 'context' => array('view', 'edit'), |
|
963 | 963 | 'readonly' => true, |
964 | 964 | ), |
965 | 965 | 'shipping_tax' => array( |
966 | - 'description' => __( 'Total shipping tax amount for the order.', 'woocommerce' ), |
|
966 | + 'description' => __('Total shipping tax amount for the order.', 'woocommerce'), |
|
967 | 967 | 'type' => 'string', |
968 | - 'context' => array( 'view', 'edit' ), |
|
968 | + 'context' => array('view', 'edit'), |
|
969 | 969 | 'readonly' => true, |
970 | 970 | ), |
971 | 971 | 'cart_tax' => array( |
972 | - 'description' => __( 'Sum of line item taxes only.', 'woocommerce' ), |
|
972 | + 'description' => __('Sum of line item taxes only.', 'woocommerce'), |
|
973 | 973 | 'type' => 'string', |
974 | - 'context' => array( 'view', 'edit' ), |
|
974 | + 'context' => array('view', 'edit'), |
|
975 | 975 | 'readonly' => true, |
976 | 976 | ), |
977 | 977 | 'total' => array( |
978 | - 'description' => __( 'Grand total.', 'woocommerce' ), |
|
978 | + 'description' => __('Grand total.', 'woocommerce'), |
|
979 | 979 | 'type' => 'string', |
980 | - 'context' => array( 'view', 'edit' ), |
|
980 | + 'context' => array('view', 'edit'), |
|
981 | 981 | 'readonly' => true, |
982 | 982 | ), |
983 | 983 | 'total_tax' => array( |
984 | - 'description' => __( 'Sum of all taxes.', 'woocommerce' ), |
|
984 | + 'description' => __('Sum of all taxes.', 'woocommerce'), |
|
985 | 985 | 'type' => 'string', |
986 | - 'context' => array( 'view', 'edit' ), |
|
986 | + 'context' => array('view', 'edit'), |
|
987 | 987 | 'readonly' => true, |
988 | 988 | ), |
989 | 989 | 'prices_include_tax' => array( |
990 | - 'description' => __( 'True the prices included tax during checkout.', 'woocommerce' ), |
|
990 | + 'description' => __('True the prices included tax during checkout.', 'woocommerce'), |
|
991 | 991 | 'type' => 'boolean', |
992 | - 'context' => array( 'view', 'edit' ), |
|
992 | + 'context' => array('view', 'edit'), |
|
993 | 993 | 'readonly' => true, |
994 | 994 | ), |
995 | 995 | 'customer_id' => array( |
996 | - 'description' => __( 'User ID who owns the order. 0 for guests.', 'woocommerce' ), |
|
996 | + 'description' => __('User ID who owns the order. 0 for guests.', 'woocommerce'), |
|
997 | 997 | 'type' => 'integer', |
998 | 998 | 'default' => 0, |
999 | - 'context' => array( 'view', 'edit' ), |
|
999 | + 'context' => array('view', 'edit'), |
|
1000 | 1000 | ), |
1001 | 1001 | 'customer_ip_address' => array( |
1002 | - 'description' => __( "Customer's IP address.", 'woocommerce' ), |
|
1002 | + 'description' => __("Customer's IP address.", 'woocommerce'), |
|
1003 | 1003 | 'type' => 'string', |
1004 | - 'context' => array( 'view', 'edit' ), |
|
1004 | + 'context' => array('view', 'edit'), |
|
1005 | 1005 | 'readonly' => true, |
1006 | 1006 | ), |
1007 | 1007 | 'customer_user_agent' => array( |
1008 | - 'description' => __( 'User agent of the customer.', 'woocommerce' ), |
|
1008 | + 'description' => __('User agent of the customer.', 'woocommerce'), |
|
1009 | 1009 | 'type' => 'string', |
1010 | - 'context' => array( 'view', 'edit' ), |
|
1010 | + 'context' => array('view', 'edit'), |
|
1011 | 1011 | 'readonly' => true, |
1012 | 1012 | ), |
1013 | 1013 | 'customer_note' => array( |
1014 | - 'description' => __( 'Note left by customer during checkout.', 'woocommerce' ), |
|
1014 | + 'description' => __('Note left by customer during checkout.', 'woocommerce'), |
|
1015 | 1015 | 'type' => 'string', |
1016 | - 'context' => array( 'view', 'edit' ), |
|
1016 | + 'context' => array('view', 'edit'), |
|
1017 | 1017 | ), |
1018 | 1018 | 'billing' => array( |
1019 | - 'description' => __( 'Billing address.', 'woocommerce' ), |
|
1019 | + 'description' => __('Billing address.', 'woocommerce'), |
|
1020 | 1020 | 'type' => 'object', |
1021 | - 'context' => array( 'view', 'edit' ), |
|
1021 | + 'context' => array('view', 'edit'), |
|
1022 | 1022 | 'properties' => array( |
1023 | 1023 | 'first_name' => array( |
1024 | - 'description' => __( 'First name.', 'woocommerce' ), |
|
1024 | + 'description' => __('First name.', 'woocommerce'), |
|
1025 | 1025 | 'type' => 'string', |
1026 | - 'context' => array( 'view', 'edit' ), |
|
1026 | + 'context' => array('view', 'edit'), |
|
1027 | 1027 | ), |
1028 | 1028 | 'last_name' => array( |
1029 | - 'description' => __( 'Last name.', 'woocommerce' ), |
|
1029 | + 'description' => __('Last name.', 'woocommerce'), |
|
1030 | 1030 | 'type' => 'string', |
1031 | - 'context' => array( 'view', 'edit' ), |
|
1031 | + 'context' => array('view', 'edit'), |
|
1032 | 1032 | ), |
1033 | 1033 | 'company' => array( |
1034 | - 'description' => __( 'Company name.', 'woocommerce' ), |
|
1034 | + 'description' => __('Company name.', 'woocommerce'), |
|
1035 | 1035 | 'type' => 'string', |
1036 | - 'context' => array( 'view', 'edit' ), |
|
1036 | + 'context' => array('view', 'edit'), |
|
1037 | 1037 | ), |
1038 | 1038 | 'address_1' => array( |
1039 | - 'description' => __( 'Address line 1', 'woocommerce' ), |
|
1039 | + 'description' => __('Address line 1', 'woocommerce'), |
|
1040 | 1040 | 'type' => 'string', |
1041 | - 'context' => array( 'view', 'edit' ), |
|
1041 | + 'context' => array('view', 'edit'), |
|
1042 | 1042 | ), |
1043 | 1043 | 'address_2' => array( |
1044 | - 'description' => __( 'Address line 2', 'woocommerce' ), |
|
1044 | + 'description' => __('Address line 2', 'woocommerce'), |
|
1045 | 1045 | 'type' => 'string', |
1046 | - 'context' => array( 'view', 'edit' ), |
|
1046 | + 'context' => array('view', 'edit'), |
|
1047 | 1047 | ), |
1048 | 1048 | 'city' => array( |
1049 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
1049 | + 'description' => __('City name.', 'woocommerce'), |
|
1050 | 1050 | 'type' => 'string', |
1051 | - 'context' => array( 'view', 'edit' ), |
|
1051 | + 'context' => array('view', 'edit'), |
|
1052 | 1052 | ), |
1053 | 1053 | 'state' => array( |
1054 | - 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
|
1054 | + 'description' => __('ISO code or name of the state, province or district.', 'woocommerce'), |
|
1055 | 1055 | 'type' => 'string', |
1056 | - 'context' => array( 'view', 'edit' ), |
|
1056 | + 'context' => array('view', 'edit'), |
|
1057 | 1057 | ), |
1058 | 1058 | 'postcode' => array( |
1059 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
1059 | + 'description' => __('Postal code.', 'woocommerce'), |
|
1060 | 1060 | 'type' => 'string', |
1061 | - 'context' => array( 'view', 'edit' ), |
|
1061 | + 'context' => array('view', 'edit'), |
|
1062 | 1062 | ), |
1063 | 1063 | 'country' => array( |
1064 | - 'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ), |
|
1064 | + 'description' => __('Country code in ISO 3166-1 alpha-2 format.', 'woocommerce'), |
|
1065 | 1065 | 'type' => 'string', |
1066 | - 'context' => array( 'view', 'edit' ), |
|
1066 | + 'context' => array('view', 'edit'), |
|
1067 | 1067 | ), |
1068 | 1068 | 'email' => array( |
1069 | - 'description' => __( 'Email address.', 'woocommerce' ), |
|
1069 | + 'description' => __('Email address.', 'woocommerce'), |
|
1070 | 1070 | 'type' => 'string', |
1071 | 1071 | 'format' => 'email', |
1072 | - 'context' => array( 'view', 'edit' ), |
|
1072 | + 'context' => array('view', 'edit'), |
|
1073 | 1073 | ), |
1074 | 1074 | 'phone' => array( |
1075 | - 'description' => __( 'Phone number.', 'woocommerce' ), |
|
1075 | + 'description' => __('Phone number.', 'woocommerce'), |
|
1076 | 1076 | 'type' => 'string', |
1077 | - 'context' => array( 'view', 'edit' ), |
|
1077 | + 'context' => array('view', 'edit'), |
|
1078 | 1078 | ), |
1079 | 1079 | ), |
1080 | 1080 | ), |
1081 | 1081 | 'shipping' => array( |
1082 | - 'description' => __( 'Shipping address.', 'woocommerce' ), |
|
1082 | + 'description' => __('Shipping address.', 'woocommerce'), |
|
1083 | 1083 | 'type' => 'object', |
1084 | - 'context' => array( 'view', 'edit' ), |
|
1084 | + 'context' => array('view', 'edit'), |
|
1085 | 1085 | 'properties' => array( |
1086 | 1086 | 'first_name' => array( |
1087 | - 'description' => __( 'First name.', 'woocommerce' ), |
|
1087 | + 'description' => __('First name.', 'woocommerce'), |
|
1088 | 1088 | 'type' => 'string', |
1089 | - 'context' => array( 'view', 'edit' ), |
|
1089 | + 'context' => array('view', 'edit'), |
|
1090 | 1090 | ), |
1091 | 1091 | 'last_name' => array( |
1092 | - 'description' => __( 'Last name.', 'woocommerce' ), |
|
1092 | + 'description' => __('Last name.', 'woocommerce'), |
|
1093 | 1093 | 'type' => 'string', |
1094 | - 'context' => array( 'view', 'edit' ), |
|
1094 | + 'context' => array('view', 'edit'), |
|
1095 | 1095 | ), |
1096 | 1096 | 'company' => array( |
1097 | - 'description' => __( 'Company name.', 'woocommerce' ), |
|
1097 | + 'description' => __('Company name.', 'woocommerce'), |
|
1098 | 1098 | 'type' => 'string', |
1099 | - 'context' => array( 'view', 'edit' ), |
|
1099 | + 'context' => array('view', 'edit'), |
|
1100 | 1100 | ), |
1101 | 1101 | 'address_1' => array( |
1102 | - 'description' => __( 'Address line 1', 'woocommerce' ), |
|
1102 | + 'description' => __('Address line 1', 'woocommerce'), |
|
1103 | 1103 | 'type' => 'string', |
1104 | - 'context' => array( 'view', 'edit' ), |
|
1104 | + 'context' => array('view', 'edit'), |
|
1105 | 1105 | ), |
1106 | 1106 | 'address_2' => array( |
1107 | - 'description' => __( 'Address line 2', 'woocommerce' ), |
|
1107 | + 'description' => __('Address line 2', 'woocommerce'), |
|
1108 | 1108 | 'type' => 'string', |
1109 | - 'context' => array( 'view', 'edit' ), |
|
1109 | + 'context' => array('view', 'edit'), |
|
1110 | 1110 | ), |
1111 | 1111 | 'city' => array( |
1112 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
1112 | + 'description' => __('City name.', 'woocommerce'), |
|
1113 | 1113 | 'type' => 'string', |
1114 | - 'context' => array( 'view', 'edit' ), |
|
1114 | + 'context' => array('view', 'edit'), |
|
1115 | 1115 | ), |
1116 | 1116 | 'state' => array( |
1117 | - 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
|
1117 | + 'description' => __('ISO code or name of the state, province or district.', 'woocommerce'), |
|
1118 | 1118 | 'type' => 'string', |
1119 | - 'context' => array( 'view', 'edit' ), |
|
1119 | + 'context' => array('view', 'edit'), |
|
1120 | 1120 | ), |
1121 | 1121 | 'postcode' => array( |
1122 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
1122 | + 'description' => __('Postal code.', 'woocommerce'), |
|
1123 | 1123 | 'type' => 'string', |
1124 | - 'context' => array( 'view', 'edit' ), |
|
1124 | + 'context' => array('view', 'edit'), |
|
1125 | 1125 | ), |
1126 | 1126 | 'country' => array( |
1127 | - 'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ), |
|
1127 | + 'description' => __('Country code in ISO 3166-1 alpha-2 format.', 'woocommerce'), |
|
1128 | 1128 | 'type' => 'string', |
1129 | - 'context' => array( 'view', 'edit' ), |
|
1129 | + 'context' => array('view', 'edit'), |
|
1130 | 1130 | ), |
1131 | 1131 | ), |
1132 | 1132 | ), |
1133 | 1133 | 'payment_method' => array( |
1134 | - 'description' => __( 'Payment method ID.', 'woocommerce' ), |
|
1134 | + 'description' => __('Payment method ID.', 'woocommerce'), |
|
1135 | 1135 | 'type' => 'string', |
1136 | - 'context' => array( 'view', 'edit' ), |
|
1136 | + 'context' => array('view', 'edit'), |
|
1137 | 1137 | ), |
1138 | 1138 | 'payment_method_title' => array( |
1139 | - 'description' => __( 'Payment method title.', 'woocommerce' ), |
|
1139 | + 'description' => __('Payment method title.', 'woocommerce'), |
|
1140 | 1140 | 'type' => 'string', |
1141 | - 'context' => array( 'view', 'edit' ), |
|
1141 | + 'context' => array('view', 'edit'), |
|
1142 | 1142 | 'arg_options' => array( |
1143 | 1143 | 'sanitize_callback' => 'sanitize_text_field', |
1144 | 1144 | ), |
1145 | 1145 | ), |
1146 | 1146 | 'transaction_id' => array( |
1147 | - 'description' => __( 'Unique transaction ID.', 'woocommerce' ), |
|
1147 | + 'description' => __('Unique transaction ID.', 'woocommerce'), |
|
1148 | 1148 | 'type' => 'string', |
1149 | - 'context' => array( 'view', 'edit' ), |
|
1149 | + 'context' => array('view', 'edit'), |
|
1150 | 1150 | ), |
1151 | 1151 | 'date_paid' => array( |
1152 | - 'description' => __( "The date the order was paid, in the site's timezone.", 'woocommerce' ), |
|
1152 | + 'description' => __("The date the order was paid, in the site's timezone.", 'woocommerce'), |
|
1153 | 1153 | 'type' => 'date-time', |
1154 | - 'context' => array( 'view', 'edit' ), |
|
1154 | + 'context' => array('view', 'edit'), |
|
1155 | 1155 | 'readonly' => true, |
1156 | 1156 | ), |
1157 | 1157 | 'date_paid_gmt' => array( |
1158 | - 'description' => __( 'The date the order was paid, as GMT.', 'woocommerce' ), |
|
1158 | + 'description' => __('The date the order was paid, as GMT.', 'woocommerce'), |
|
1159 | 1159 | 'type' => 'date-time', |
1160 | - 'context' => array( 'view', 'edit' ), |
|
1160 | + 'context' => array('view', 'edit'), |
|
1161 | 1161 | 'readonly' => true, |
1162 | 1162 | ), |
1163 | 1163 | 'date_completed' => array( |
1164 | - 'description' => __( "The date the order was completed, in the site's timezone.", 'woocommerce' ), |
|
1164 | + 'description' => __("The date the order was completed, in the site's timezone.", 'woocommerce'), |
|
1165 | 1165 | 'type' => 'date-time', |
1166 | - 'context' => array( 'view', 'edit' ), |
|
1166 | + 'context' => array('view', 'edit'), |
|
1167 | 1167 | 'readonly' => true, |
1168 | 1168 | ), |
1169 | 1169 | 'date_completed_gmt' => array( |
1170 | - 'description' => __( 'The date the order was completed, as GMT.', 'woocommerce' ), |
|
1170 | + 'description' => __('The date the order was completed, as GMT.', 'woocommerce'), |
|
1171 | 1171 | 'type' => 'date-time', |
1172 | - 'context' => array( 'view', 'edit' ), |
|
1172 | + 'context' => array('view', 'edit'), |
|
1173 | 1173 | 'readonly' => true, |
1174 | 1174 | ), |
1175 | 1175 | 'cart_hash' => array( |
1176 | - 'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ), |
|
1176 | + 'description' => __('MD5 hash of cart items to ensure orders are not modified.', 'woocommerce'), |
|
1177 | 1177 | 'type' => 'string', |
1178 | - 'context' => array( 'view', 'edit' ), |
|
1178 | + 'context' => array('view', 'edit'), |
|
1179 | 1179 | 'readonly' => true, |
1180 | 1180 | ), |
1181 | 1181 | 'meta_data' => array( |
1182 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
1182 | + 'description' => __('Meta data.', 'woocommerce'), |
|
1183 | 1183 | 'type' => 'array', |
1184 | - 'context' => array( 'view', 'edit' ), |
|
1184 | + 'context' => array('view', 'edit'), |
|
1185 | 1185 | 'items' => array( |
1186 | 1186 | 'type' => 'object', |
1187 | 1187 | 'properties' => array( |
1188 | 1188 | 'id' => array( |
1189 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
1189 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
1190 | 1190 | 'type' => 'integer', |
1191 | - 'context' => array( 'view', 'edit' ), |
|
1191 | + 'context' => array('view', 'edit'), |
|
1192 | 1192 | 'readonly' => true, |
1193 | 1193 | ), |
1194 | 1194 | 'key' => array( |
1195 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
1195 | + 'description' => __('Meta key.', 'woocommerce'), |
|
1196 | 1196 | 'type' => 'string', |
1197 | - 'context' => array( 'view', 'edit' ), |
|
1197 | + 'context' => array('view', 'edit'), |
|
1198 | 1198 | ), |
1199 | 1199 | 'value' => array( |
1200 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
1200 | + 'description' => __('Meta value.', 'woocommerce'), |
|
1201 | 1201 | 'type' => 'mixed', |
1202 | - 'context' => array( 'view', 'edit' ), |
|
1202 | + 'context' => array('view', 'edit'), |
|
1203 | 1203 | ), |
1204 | 1204 | ), |
1205 | 1205 | ), |
1206 | 1206 | ), |
1207 | 1207 | 'line_items' => array( |
1208 | - 'description' => __( 'Line items data.', 'woocommerce' ), |
|
1208 | + 'description' => __('Line items data.', 'woocommerce'), |
|
1209 | 1209 | 'type' => 'array', |
1210 | - 'context' => array( 'view', 'edit' ), |
|
1210 | + 'context' => array('view', 'edit'), |
|
1211 | 1211 | 'items' => array( |
1212 | 1212 | 'type' => 'object', |
1213 | 1213 | 'properties' => array( |
1214 | 1214 | 'id' => array( |
1215 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
1215 | + 'description' => __('Item ID.', 'woocommerce'), |
|
1216 | 1216 | 'type' => 'integer', |
1217 | - 'context' => array( 'view', 'edit' ), |
|
1217 | + 'context' => array('view', 'edit'), |
|
1218 | 1218 | 'readonly' => true, |
1219 | 1219 | ), |
1220 | 1220 | 'name' => array( |
1221 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
1221 | + 'description' => __('Product name.', 'woocommerce'), |
|
1222 | 1222 | 'type' => 'mixed', |
1223 | - 'context' => array( 'view', 'edit' ), |
|
1223 | + 'context' => array('view', 'edit'), |
|
1224 | 1224 | ), |
1225 | 1225 | 'product_id' => array( |
1226 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
1226 | + 'description' => __('Product ID.', 'woocommerce'), |
|
1227 | 1227 | 'type' => 'mixed', |
1228 | - 'context' => array( 'view', 'edit' ), |
|
1228 | + 'context' => array('view', 'edit'), |
|
1229 | 1229 | ), |
1230 | 1230 | 'variation_id' => array( |
1231 | - 'description' => __( 'Variation ID, if applicable.', 'woocommerce' ), |
|
1231 | + 'description' => __('Variation ID, if applicable.', 'woocommerce'), |
|
1232 | 1232 | 'type' => 'integer', |
1233 | - 'context' => array( 'view', 'edit' ), |
|
1233 | + 'context' => array('view', 'edit'), |
|
1234 | 1234 | ), |
1235 | 1235 | 'quantity' => array( |
1236 | - 'description' => __( 'Quantity ordered.', 'woocommerce' ), |
|
1236 | + 'description' => __('Quantity ordered.', 'woocommerce'), |
|
1237 | 1237 | 'type' => 'integer', |
1238 | - 'context' => array( 'view', 'edit' ), |
|
1238 | + 'context' => array('view', 'edit'), |
|
1239 | 1239 | ), |
1240 | 1240 | 'tax_class' => array( |
1241 | - 'description' => __( 'Tax class of product.', 'woocommerce' ), |
|
1241 | + 'description' => __('Tax class of product.', 'woocommerce'), |
|
1242 | 1242 | 'type' => 'string', |
1243 | - 'context' => array( 'view', 'edit' ), |
|
1243 | + 'context' => array('view', 'edit'), |
|
1244 | 1244 | ), |
1245 | 1245 | 'subtotal' => array( |
1246 | - 'description' => __( 'Line subtotal (before discounts).', 'woocommerce' ), |
|
1246 | + 'description' => __('Line subtotal (before discounts).', 'woocommerce'), |
|
1247 | 1247 | 'type' => 'string', |
1248 | - 'context' => array( 'view', 'edit' ), |
|
1248 | + 'context' => array('view', 'edit'), |
|
1249 | 1249 | ), |
1250 | 1250 | 'subtotal_tax' => array( |
1251 | - 'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce' ), |
|
1251 | + 'description' => __('Line subtotal tax (before discounts).', 'woocommerce'), |
|
1252 | 1252 | 'type' => 'string', |
1253 | - 'context' => array( 'view', 'edit' ), |
|
1253 | + 'context' => array('view', 'edit'), |
|
1254 | 1254 | 'readonly' => true, |
1255 | 1255 | ), |
1256 | 1256 | 'total' => array( |
1257 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
1257 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
1258 | 1258 | 'type' => 'string', |
1259 | - 'context' => array( 'view', 'edit' ), |
|
1259 | + 'context' => array('view', 'edit'), |
|
1260 | 1260 | ), |
1261 | 1261 | 'total_tax' => array( |
1262 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
1262 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
1263 | 1263 | 'type' => 'string', |
1264 | - 'context' => array( 'view', 'edit' ), |
|
1264 | + 'context' => array('view', 'edit'), |
|
1265 | 1265 | 'readonly' => true, |
1266 | 1266 | ), |
1267 | 1267 | 'taxes' => array( |
1268 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
1268 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
1269 | 1269 | 'type' => 'array', |
1270 | - 'context' => array( 'view', 'edit' ), |
|
1270 | + 'context' => array('view', 'edit'), |
|
1271 | 1271 | 'readonly' => true, |
1272 | 1272 | 'items' => array( |
1273 | 1273 | 'type' => 'object', |
1274 | 1274 | 'properties' => array( |
1275 | 1275 | 'id' => array( |
1276 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
1276 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
1277 | 1277 | 'type' => 'integer', |
1278 | - 'context' => array( 'view', 'edit' ), |
|
1278 | + 'context' => array('view', 'edit'), |
|
1279 | 1279 | ), |
1280 | 1280 | 'total' => array( |
1281 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
1281 | + 'description' => __('Tax total.', 'woocommerce'), |
|
1282 | 1282 | 'type' => 'string', |
1283 | - 'context' => array( 'view', 'edit' ), |
|
1283 | + 'context' => array('view', 'edit'), |
|
1284 | 1284 | ), |
1285 | 1285 | 'subtotal' => array( |
1286 | - 'description' => __( 'Tax subtotal.', 'woocommerce' ), |
|
1286 | + 'description' => __('Tax subtotal.', 'woocommerce'), |
|
1287 | 1287 | 'type' => 'string', |
1288 | - 'context' => array( 'view', 'edit' ), |
|
1288 | + 'context' => array('view', 'edit'), |
|
1289 | 1289 | ), |
1290 | 1290 | ), |
1291 | 1291 | ), |
1292 | 1292 | ), |
1293 | 1293 | 'meta_data' => array( |
1294 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
1294 | + 'description' => __('Meta data.', 'woocommerce'), |
|
1295 | 1295 | 'type' => 'array', |
1296 | - 'context' => array( 'view', 'edit' ), |
|
1296 | + 'context' => array('view', 'edit'), |
|
1297 | 1297 | 'items' => array( |
1298 | 1298 | 'type' => 'object', |
1299 | 1299 | 'properties' => array( |
1300 | 1300 | 'id' => array( |
1301 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
1301 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
1302 | 1302 | 'type' => 'integer', |
1303 | - 'context' => array( 'view', 'edit' ), |
|
1303 | + 'context' => array('view', 'edit'), |
|
1304 | 1304 | 'readonly' => true, |
1305 | 1305 | ), |
1306 | 1306 | 'key' => array( |
1307 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
1307 | + 'description' => __('Meta key.', 'woocommerce'), |
|
1308 | 1308 | 'type' => 'string', |
1309 | - 'context' => array( 'view', 'edit' ), |
|
1309 | + 'context' => array('view', 'edit'), |
|
1310 | 1310 | ), |
1311 | 1311 | 'value' => array( |
1312 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
1312 | + 'description' => __('Meta value.', 'woocommerce'), |
|
1313 | 1313 | 'type' => 'mixed', |
1314 | - 'context' => array( 'view', 'edit' ), |
|
1314 | + 'context' => array('view', 'edit'), |
|
1315 | 1315 | ), |
1316 | 1316 | ), |
1317 | 1317 | ), |
1318 | 1318 | ), |
1319 | 1319 | 'sku' => array( |
1320 | - 'description' => __( 'Product SKU.', 'woocommerce' ), |
|
1320 | + 'description' => __('Product SKU.', 'woocommerce'), |
|
1321 | 1321 | 'type' => 'string', |
1322 | - 'context' => array( 'view', 'edit' ), |
|
1322 | + 'context' => array('view', 'edit'), |
|
1323 | 1323 | 'readonly' => true, |
1324 | 1324 | ), |
1325 | 1325 | 'price' => array( |
1326 | - 'description' => __( 'Product price.', 'woocommerce' ), |
|
1326 | + 'description' => __('Product price.', 'woocommerce'), |
|
1327 | 1327 | 'type' => 'number', |
1328 | - 'context' => array( 'view', 'edit' ), |
|
1328 | + 'context' => array('view', 'edit'), |
|
1329 | 1329 | 'readonly' => true, |
1330 | 1330 | ), |
1331 | 1331 | ), |
1332 | 1332 | ), |
1333 | 1333 | ), |
1334 | 1334 | 'tax_lines' => array( |
1335 | - 'description' => __( 'Tax lines data.', 'woocommerce' ), |
|
1335 | + 'description' => __('Tax lines data.', 'woocommerce'), |
|
1336 | 1336 | 'type' => 'array', |
1337 | - 'context' => array( 'view', 'edit' ), |
|
1337 | + 'context' => array('view', 'edit'), |
|
1338 | 1338 | 'readonly' => true, |
1339 | 1339 | 'items' => array( |
1340 | 1340 | 'type' => 'object', |
1341 | 1341 | 'properties' => array( |
1342 | 1342 | 'id' => array( |
1343 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
1343 | + 'description' => __('Item ID.', 'woocommerce'), |
|
1344 | 1344 | 'type' => 'integer', |
1345 | - 'context' => array( 'view', 'edit' ), |
|
1345 | + 'context' => array('view', 'edit'), |
|
1346 | 1346 | 'readonly' => true, |
1347 | 1347 | ), |
1348 | 1348 | 'rate_code' => array( |
1349 | - 'description' => __( 'Tax rate code.', 'woocommerce' ), |
|
1349 | + 'description' => __('Tax rate code.', 'woocommerce'), |
|
1350 | 1350 | 'type' => 'string', |
1351 | - 'context' => array( 'view', 'edit' ), |
|
1351 | + 'context' => array('view', 'edit'), |
|
1352 | 1352 | 'readonly' => true, |
1353 | 1353 | ), |
1354 | 1354 | 'rate_id' => array( |
1355 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
1355 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
1356 | 1356 | 'type' => 'string', |
1357 | - 'context' => array( 'view', 'edit' ), |
|
1357 | + 'context' => array('view', 'edit'), |
|
1358 | 1358 | 'readonly' => true, |
1359 | 1359 | ), |
1360 | 1360 | 'label' => array( |
1361 | - 'description' => __( 'Tax rate label.', 'woocommerce' ), |
|
1361 | + 'description' => __('Tax rate label.', 'woocommerce'), |
|
1362 | 1362 | 'type' => 'string', |
1363 | - 'context' => array( 'view', 'edit' ), |
|
1363 | + 'context' => array('view', 'edit'), |
|
1364 | 1364 | 'readonly' => true, |
1365 | 1365 | ), |
1366 | 1366 | 'compound' => array( |
1367 | - 'description' => __( 'Show if is a compound tax rate.', 'woocommerce' ), |
|
1367 | + 'description' => __('Show if is a compound tax rate.', 'woocommerce'), |
|
1368 | 1368 | 'type' => 'boolean', |
1369 | - 'context' => array( 'view', 'edit' ), |
|
1369 | + 'context' => array('view', 'edit'), |
|
1370 | 1370 | 'readonly' => true, |
1371 | 1371 | ), |
1372 | 1372 | 'tax_total' => array( |
1373 | - 'description' => __( 'Tax total (not including shipping taxes).', 'woocommerce' ), |
|
1373 | + 'description' => __('Tax total (not including shipping taxes).', 'woocommerce'), |
|
1374 | 1374 | 'type' => 'string', |
1375 | - 'context' => array( 'view', 'edit' ), |
|
1375 | + 'context' => array('view', 'edit'), |
|
1376 | 1376 | 'readonly' => true, |
1377 | 1377 | ), |
1378 | 1378 | 'shipping_tax_total' => array( |
1379 | - 'description' => __( 'Shipping tax total.', 'woocommerce' ), |
|
1379 | + 'description' => __('Shipping tax total.', 'woocommerce'), |
|
1380 | 1380 | 'type' => 'string', |
1381 | - 'context' => array( 'view', 'edit' ), |
|
1381 | + 'context' => array('view', 'edit'), |
|
1382 | 1382 | 'readonly' => true, |
1383 | 1383 | ), |
1384 | 1384 | 'meta_data' => array( |
1385 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
1385 | + 'description' => __('Meta data.', 'woocommerce'), |
|
1386 | 1386 | 'type' => 'array', |
1387 | - 'context' => array( 'view', 'edit' ), |
|
1387 | + 'context' => array('view', 'edit'), |
|
1388 | 1388 | 'items' => array( |
1389 | 1389 | 'type' => 'object', |
1390 | 1390 | 'properties' => array( |
1391 | 1391 | 'id' => array( |
1392 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
1392 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
1393 | 1393 | 'type' => 'integer', |
1394 | - 'context' => array( 'view', 'edit' ), |
|
1394 | + 'context' => array('view', 'edit'), |
|
1395 | 1395 | 'readonly' => true, |
1396 | 1396 | ), |
1397 | 1397 | 'key' => array( |
1398 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
1398 | + 'description' => __('Meta key.', 'woocommerce'), |
|
1399 | 1399 | 'type' => 'string', |
1400 | - 'context' => array( 'view', 'edit' ), |
|
1400 | + 'context' => array('view', 'edit'), |
|
1401 | 1401 | ), |
1402 | 1402 | 'value' => array( |
1403 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
1403 | + 'description' => __('Meta value.', 'woocommerce'), |
|
1404 | 1404 | 'type' => 'mixed', |
1405 | - 'context' => array( 'view', 'edit' ), |
|
1405 | + 'context' => array('view', 'edit'), |
|
1406 | 1406 | ), |
1407 | 1407 | ), |
1408 | 1408 | ), |
@@ -1411,89 +1411,89 @@ discard block |
||
1411 | 1411 | ), |
1412 | 1412 | ), |
1413 | 1413 | 'shipping_lines' => array( |
1414 | - 'description' => __( 'Shipping lines data.', 'woocommerce' ), |
|
1414 | + 'description' => __('Shipping lines data.', 'woocommerce'), |
|
1415 | 1415 | 'type' => 'array', |
1416 | - 'context' => array( 'view', 'edit' ), |
|
1416 | + 'context' => array('view', 'edit'), |
|
1417 | 1417 | 'items' => array( |
1418 | 1418 | 'type' => 'object', |
1419 | 1419 | 'properties' => array( |
1420 | 1420 | 'id' => array( |
1421 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
1421 | + 'description' => __('Item ID.', 'woocommerce'), |
|
1422 | 1422 | 'type' => 'integer', |
1423 | - 'context' => array( 'view', 'edit' ), |
|
1423 | + 'context' => array('view', 'edit'), |
|
1424 | 1424 | 'readonly' => true, |
1425 | 1425 | ), |
1426 | 1426 | 'method_title' => array( |
1427 | - 'description' => __( 'Shipping method name.', 'woocommerce' ), |
|
1427 | + 'description' => __('Shipping method name.', 'woocommerce'), |
|
1428 | 1428 | 'type' => 'mixed', |
1429 | - 'context' => array( 'view', 'edit' ), |
|
1429 | + 'context' => array('view', 'edit'), |
|
1430 | 1430 | ), |
1431 | 1431 | 'method_id' => array( |
1432 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
1432 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
1433 | 1433 | 'type' => 'mixed', |
1434 | - 'context' => array( 'view', 'edit' ), |
|
1434 | + 'context' => array('view', 'edit'), |
|
1435 | 1435 | ), |
1436 | 1436 | 'instance_id' => array( |
1437 | - 'description' => __( 'Shipping instance ID.', 'woocommerce' ), |
|
1437 | + 'description' => __('Shipping instance ID.', 'woocommerce'), |
|
1438 | 1438 | 'type' => 'string', |
1439 | - 'context' => array( 'view', 'edit' ), |
|
1439 | + 'context' => array('view', 'edit'), |
|
1440 | 1440 | ), |
1441 | 1441 | 'total' => array( |
1442 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
1442 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
1443 | 1443 | 'type' => 'string', |
1444 | - 'context' => array( 'view', 'edit' ), |
|
1444 | + 'context' => array('view', 'edit'), |
|
1445 | 1445 | ), |
1446 | 1446 | 'total_tax' => array( |
1447 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
1447 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
1448 | 1448 | 'type' => 'string', |
1449 | - 'context' => array( 'view', 'edit' ), |
|
1449 | + 'context' => array('view', 'edit'), |
|
1450 | 1450 | 'readonly' => true, |
1451 | 1451 | ), |
1452 | 1452 | 'taxes' => array( |
1453 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
1453 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
1454 | 1454 | 'type' => 'array', |
1455 | - 'context' => array( 'view', 'edit' ), |
|
1455 | + 'context' => array('view', 'edit'), |
|
1456 | 1456 | 'readonly' => true, |
1457 | 1457 | 'items' => array( |
1458 | 1458 | 'type' => 'object', |
1459 | 1459 | 'properties' => array( |
1460 | 1460 | 'id' => array( |
1461 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
1461 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
1462 | 1462 | 'type' => 'integer', |
1463 | - 'context' => array( 'view', 'edit' ), |
|
1463 | + 'context' => array('view', 'edit'), |
|
1464 | 1464 | 'readonly' => true, |
1465 | 1465 | ), |
1466 | 1466 | 'total' => array( |
1467 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
1467 | + 'description' => __('Tax total.', 'woocommerce'), |
|
1468 | 1468 | 'type' => 'string', |
1469 | - 'context' => array( 'view', 'edit' ), |
|
1469 | + 'context' => array('view', 'edit'), |
|
1470 | 1470 | 'readonly' => true, |
1471 | 1471 | ), |
1472 | 1472 | ), |
1473 | 1473 | ), |
1474 | 1474 | ), |
1475 | 1475 | 'meta_data' => array( |
1476 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
1476 | + 'description' => __('Meta data.', 'woocommerce'), |
|
1477 | 1477 | 'type' => 'array', |
1478 | - 'context' => array( 'view', 'edit' ), |
|
1478 | + 'context' => array('view', 'edit'), |
|
1479 | 1479 | 'items' => array( |
1480 | 1480 | 'type' => 'object', |
1481 | 1481 | 'properties' => array( |
1482 | 1482 | 'id' => array( |
1483 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
1483 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
1484 | 1484 | 'type' => 'integer', |
1485 | - 'context' => array( 'view', 'edit' ), |
|
1485 | + 'context' => array('view', 'edit'), |
|
1486 | 1486 | 'readonly' => true, |
1487 | 1487 | ), |
1488 | 1488 | 'key' => array( |
1489 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
1489 | + 'description' => __('Meta key.', 'woocommerce'), |
|
1490 | 1490 | 'type' => 'string', |
1491 | - 'context' => array( 'view', 'edit' ), |
|
1491 | + 'context' => array('view', 'edit'), |
|
1492 | 1492 | ), |
1493 | 1493 | 'value' => array( |
1494 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
1494 | + 'description' => __('Meta value.', 'woocommerce'), |
|
1495 | 1495 | 'type' => 'mixed', |
1496 | - 'context' => array( 'view', 'edit' ), |
|
1496 | + 'context' => array('view', 'edit'), |
|
1497 | 1497 | ), |
1498 | 1498 | ), |
1499 | 1499 | ), |
@@ -1502,96 +1502,96 @@ discard block |
||
1502 | 1502 | ), |
1503 | 1503 | ), |
1504 | 1504 | 'fee_lines' => array( |
1505 | - 'description' => __( 'Fee lines data.', 'woocommerce' ), |
|
1505 | + 'description' => __('Fee lines data.', 'woocommerce'), |
|
1506 | 1506 | 'type' => 'array', |
1507 | - 'context' => array( 'view', 'edit' ), |
|
1507 | + 'context' => array('view', 'edit'), |
|
1508 | 1508 | 'items' => array( |
1509 | 1509 | 'type' => 'object', |
1510 | 1510 | 'properties' => array( |
1511 | 1511 | 'id' => array( |
1512 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
1512 | + 'description' => __('Item ID.', 'woocommerce'), |
|
1513 | 1513 | 'type' => 'integer', |
1514 | - 'context' => array( 'view', 'edit' ), |
|
1514 | + 'context' => array('view', 'edit'), |
|
1515 | 1515 | 'readonly' => true, |
1516 | 1516 | ), |
1517 | 1517 | 'name' => array( |
1518 | - 'description' => __( 'Fee name.', 'woocommerce' ), |
|
1518 | + 'description' => __('Fee name.', 'woocommerce'), |
|
1519 | 1519 | 'type' => 'mixed', |
1520 | - 'context' => array( 'view', 'edit' ), |
|
1520 | + 'context' => array('view', 'edit'), |
|
1521 | 1521 | ), |
1522 | 1522 | 'tax_class' => array( |
1523 | - 'description' => __( 'Tax class of fee.', 'woocommerce' ), |
|
1523 | + 'description' => __('Tax class of fee.', 'woocommerce'), |
|
1524 | 1524 | 'type' => 'string', |
1525 | - 'context' => array( 'view', 'edit' ), |
|
1525 | + 'context' => array('view', 'edit'), |
|
1526 | 1526 | ), |
1527 | 1527 | 'tax_status' => array( |
1528 | - 'description' => __( 'Tax status of fee.', 'woocommerce' ), |
|
1528 | + 'description' => __('Tax status of fee.', 'woocommerce'), |
|
1529 | 1529 | 'type' => 'string', |
1530 | - 'context' => array( 'view', 'edit' ), |
|
1531 | - 'enum' => array( 'taxable', 'none' ), |
|
1530 | + 'context' => array('view', 'edit'), |
|
1531 | + 'enum' => array('taxable', 'none'), |
|
1532 | 1532 | ), |
1533 | 1533 | 'total' => array( |
1534 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
1534 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
1535 | 1535 | 'type' => 'string', |
1536 | - 'context' => array( 'view', 'edit' ), |
|
1536 | + 'context' => array('view', 'edit'), |
|
1537 | 1537 | ), |
1538 | 1538 | 'total_tax' => array( |
1539 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
1539 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
1540 | 1540 | 'type' => 'string', |
1541 | - 'context' => array( 'view', 'edit' ), |
|
1541 | + 'context' => array('view', 'edit'), |
|
1542 | 1542 | 'readonly' => true, |
1543 | 1543 | ), |
1544 | 1544 | 'taxes' => array( |
1545 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
1545 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
1546 | 1546 | 'type' => 'array', |
1547 | - 'context' => array( 'view', 'edit' ), |
|
1547 | + 'context' => array('view', 'edit'), |
|
1548 | 1548 | 'readonly' => true, |
1549 | 1549 | 'items' => array( |
1550 | 1550 | 'type' => 'object', |
1551 | 1551 | 'properties' => array( |
1552 | 1552 | 'id' => array( |
1553 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
1553 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
1554 | 1554 | 'type' => 'integer', |
1555 | - 'context' => array( 'view', 'edit' ), |
|
1555 | + 'context' => array('view', 'edit'), |
|
1556 | 1556 | 'readonly' => true, |
1557 | 1557 | ), |
1558 | 1558 | 'total' => array( |
1559 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
1559 | + 'description' => __('Tax total.', 'woocommerce'), |
|
1560 | 1560 | 'type' => 'string', |
1561 | - 'context' => array( 'view', 'edit' ), |
|
1561 | + 'context' => array('view', 'edit'), |
|
1562 | 1562 | 'readonly' => true, |
1563 | 1563 | ), |
1564 | 1564 | 'subtotal' => array( |
1565 | - 'description' => __( 'Tax subtotal.', 'woocommerce' ), |
|
1565 | + 'description' => __('Tax subtotal.', 'woocommerce'), |
|
1566 | 1566 | 'type' => 'string', |
1567 | - 'context' => array( 'view', 'edit' ), |
|
1567 | + 'context' => array('view', 'edit'), |
|
1568 | 1568 | 'readonly' => true, |
1569 | 1569 | ), |
1570 | 1570 | ), |
1571 | 1571 | ), |
1572 | 1572 | ), |
1573 | 1573 | 'meta_data' => array( |
1574 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
1574 | + 'description' => __('Meta data.', 'woocommerce'), |
|
1575 | 1575 | 'type' => 'array', |
1576 | - 'context' => array( 'view', 'edit' ), |
|
1576 | + 'context' => array('view', 'edit'), |
|
1577 | 1577 | 'items' => array( |
1578 | 1578 | 'type' => 'object', |
1579 | 1579 | 'properties' => array( |
1580 | 1580 | 'id' => array( |
1581 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
1581 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
1582 | 1582 | 'type' => 'integer', |
1583 | - 'context' => array( 'view', 'edit' ), |
|
1583 | + 'context' => array('view', 'edit'), |
|
1584 | 1584 | 'readonly' => true, |
1585 | 1585 | ), |
1586 | 1586 | 'key' => array( |
1587 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
1587 | + 'description' => __('Meta key.', 'woocommerce'), |
|
1588 | 1588 | 'type' => 'string', |
1589 | - 'context' => array( 'view', 'edit' ), |
|
1589 | + 'context' => array('view', 'edit'), |
|
1590 | 1590 | ), |
1591 | 1591 | 'value' => array( |
1592 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
1592 | + 'description' => __('Meta value.', 'woocommerce'), |
|
1593 | 1593 | 'type' => 'mixed', |
1594 | - 'context' => array( 'view', 'edit' ), |
|
1594 | + 'context' => array('view', 'edit'), |
|
1595 | 1595 | ), |
1596 | 1596 | ), |
1597 | 1597 | ), |
@@ -1600,57 +1600,57 @@ discard block |
||
1600 | 1600 | ), |
1601 | 1601 | ), |
1602 | 1602 | 'coupon_lines' => array( |
1603 | - 'description' => __( 'Coupons line data.', 'woocommerce' ), |
|
1603 | + 'description' => __('Coupons line data.', 'woocommerce'), |
|
1604 | 1604 | 'type' => 'array', |
1605 | - 'context' => array( 'view', 'edit' ), |
|
1605 | + 'context' => array('view', 'edit'), |
|
1606 | 1606 | 'items' => array( |
1607 | 1607 | 'type' => 'object', |
1608 | 1608 | 'properties' => array( |
1609 | 1609 | 'id' => array( |
1610 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
1610 | + 'description' => __('Item ID.', 'woocommerce'), |
|
1611 | 1611 | 'type' => 'integer', |
1612 | - 'context' => array( 'view', 'edit' ), |
|
1612 | + 'context' => array('view', 'edit'), |
|
1613 | 1613 | 'readonly' => true, |
1614 | 1614 | ), |
1615 | 1615 | 'code' => array( |
1616 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
1616 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
1617 | 1617 | 'type' => 'mixed', |
1618 | - 'context' => array( 'view', 'edit' ), |
|
1618 | + 'context' => array('view', 'edit'), |
|
1619 | 1619 | ), |
1620 | 1620 | 'discount' => array( |
1621 | - 'description' => __( 'Discount total.', 'woocommerce' ), |
|
1621 | + 'description' => __('Discount total.', 'woocommerce'), |
|
1622 | 1622 | 'type' => 'string', |
1623 | - 'context' => array( 'view', 'edit' ), |
|
1623 | + 'context' => array('view', 'edit'), |
|
1624 | 1624 | 'readonly' => true, |
1625 | 1625 | ), |
1626 | 1626 | 'discount_tax' => array( |
1627 | - 'description' => __( 'Discount total tax.', 'woocommerce' ), |
|
1627 | + 'description' => __('Discount total tax.', 'woocommerce'), |
|
1628 | 1628 | 'type' => 'string', |
1629 | - 'context' => array( 'view', 'edit' ), |
|
1629 | + 'context' => array('view', 'edit'), |
|
1630 | 1630 | 'readonly' => true, |
1631 | 1631 | ), |
1632 | 1632 | 'meta_data' => array( |
1633 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
1633 | + 'description' => __('Meta data.', 'woocommerce'), |
|
1634 | 1634 | 'type' => 'array', |
1635 | - 'context' => array( 'view', 'edit' ), |
|
1635 | + 'context' => array('view', 'edit'), |
|
1636 | 1636 | 'items' => array( |
1637 | 1637 | 'type' => 'object', |
1638 | 1638 | 'properties' => array( |
1639 | 1639 | 'id' => array( |
1640 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
1640 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
1641 | 1641 | 'type' => 'integer', |
1642 | - 'context' => array( 'view', 'edit' ), |
|
1642 | + 'context' => array('view', 'edit'), |
|
1643 | 1643 | 'readonly' => true, |
1644 | 1644 | ), |
1645 | 1645 | 'key' => array( |
1646 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
1646 | + 'description' => __('Meta key.', 'woocommerce'), |
|
1647 | 1647 | 'type' => 'string', |
1648 | - 'context' => array( 'view', 'edit' ), |
|
1648 | + 'context' => array('view', 'edit'), |
|
1649 | 1649 | ), |
1650 | 1650 | 'value' => array( |
1651 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
1651 | + 'description' => __('Meta value.', 'woocommerce'), |
|
1652 | 1652 | 'type' => 'mixed', |
1653 | - 'context' => array( 'view', 'edit' ), |
|
1653 | + 'context' => array('view', 'edit'), |
|
1654 | 1654 | ), |
1655 | 1655 | ), |
1656 | 1656 | ), |
@@ -1659,44 +1659,44 @@ discard block |
||
1659 | 1659 | ), |
1660 | 1660 | ), |
1661 | 1661 | 'refunds' => array( |
1662 | - 'description' => __( 'List of refunds.', 'woocommerce' ), |
|
1662 | + 'description' => __('List of refunds.', 'woocommerce'), |
|
1663 | 1663 | 'type' => 'array', |
1664 | - 'context' => array( 'view', 'edit' ), |
|
1664 | + 'context' => array('view', 'edit'), |
|
1665 | 1665 | 'readonly' => true, |
1666 | 1666 | 'items' => array( |
1667 | 1667 | 'type' => 'object', |
1668 | 1668 | 'properties' => array( |
1669 | 1669 | 'id' => array( |
1670 | - 'description' => __( 'Refund ID.', 'woocommerce' ), |
|
1670 | + 'description' => __('Refund ID.', 'woocommerce'), |
|
1671 | 1671 | 'type' => 'integer', |
1672 | - 'context' => array( 'view', 'edit' ), |
|
1672 | + 'context' => array('view', 'edit'), |
|
1673 | 1673 | 'readonly' => true, |
1674 | 1674 | ), |
1675 | 1675 | 'reason' => array( |
1676 | - 'description' => __( 'Refund reason.', 'woocommerce' ), |
|
1676 | + 'description' => __('Refund reason.', 'woocommerce'), |
|
1677 | 1677 | 'type' => 'string', |
1678 | - 'context' => array( 'view', 'edit' ), |
|
1678 | + 'context' => array('view', 'edit'), |
|
1679 | 1679 | 'readonly' => true, |
1680 | 1680 | ), |
1681 | 1681 | 'total' => array( |
1682 | - 'description' => __( 'Refund total.', 'woocommerce' ), |
|
1682 | + 'description' => __('Refund total.', 'woocommerce'), |
|
1683 | 1683 | 'type' => 'string', |
1684 | - 'context' => array( 'view', 'edit' ), |
|
1684 | + 'context' => array('view', 'edit'), |
|
1685 | 1685 | 'readonly' => true, |
1686 | 1686 | ), |
1687 | 1687 | ), |
1688 | 1688 | ), |
1689 | 1689 | ), |
1690 | 1690 | 'set_paid' => array( |
1691 | - 'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce' ), |
|
1691 | + 'description' => __('Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce'), |
|
1692 | 1692 | 'type' => 'boolean', |
1693 | 1693 | 'default' => false, |
1694 | - 'context' => array( 'edit' ), |
|
1694 | + 'context' => array('edit'), |
|
1695 | 1695 | ), |
1696 | 1696 | ), |
1697 | 1697 | ); |
1698 | 1698 | |
1699 | - return $this->add_additional_fields_schema( $schema ); |
|
1699 | + return $this->add_additional_fields_schema($schema); |
|
1700 | 1700 | } |
1701 | 1701 | |
1702 | 1702 | /** |
@@ -1709,36 +1709,36 @@ discard block |
||
1709 | 1709 | |
1710 | 1710 | $params['status'] = array( |
1711 | 1711 | 'default' => 'any', |
1712 | - 'description' => __( 'Limit result set to orders which have specific statuses.', 'woocommerce' ), |
|
1712 | + 'description' => __('Limit result set to orders which have specific statuses.', 'woocommerce'), |
|
1713 | 1713 | 'type' => 'array', |
1714 | 1714 | 'items' => array( |
1715 | 1715 | 'type' => 'string', |
1716 | - 'enum' => array_merge( array( 'any', 'trash' ), $this->get_order_statuses() ), |
|
1716 | + 'enum' => array_merge(array('any', 'trash'), $this->get_order_statuses()), |
|
1717 | 1717 | ), |
1718 | 1718 | 'validate_callback' => 'rest_validate_request_arg', |
1719 | 1719 | ); |
1720 | 1720 | $params['customer'] = array( |
1721 | - 'description' => __( 'Limit result set to orders assigned a specific customer.', 'woocommerce' ), |
|
1721 | + 'description' => __('Limit result set to orders assigned a specific customer.', 'woocommerce'), |
|
1722 | 1722 | 'type' => 'integer', |
1723 | 1723 | 'sanitize_callback' => 'absint', |
1724 | 1724 | 'validate_callback' => 'rest_validate_request_arg', |
1725 | 1725 | ); |
1726 | - $params['product'] = array( |
|
1727 | - 'description' => __( 'Limit result set to orders assigned a specific product.', 'woocommerce' ), |
|
1726 | + $params['product'] = array( |
|
1727 | + 'description' => __('Limit result set to orders assigned a specific product.', 'woocommerce'), |
|
1728 | 1728 | 'type' => 'integer', |
1729 | 1729 | 'sanitize_callback' => 'absint', |
1730 | 1730 | 'validate_callback' => 'rest_validate_request_arg', |
1731 | 1731 | ); |
1732 | - $params['dp'] = array( |
|
1732 | + $params['dp'] = array( |
|
1733 | 1733 | 'default' => wc_get_price_decimals(), |
1734 | - 'description' => __( 'Number of decimal points to use in each resource.', 'woocommerce' ), |
|
1734 | + 'description' => __('Number of decimal points to use in each resource.', 'woocommerce'), |
|
1735 | 1735 | 'type' => 'integer', |
1736 | 1736 | 'sanitize_callback' => 'absint', |
1737 | 1737 | 'validate_callback' => 'rest_validate_request_arg', |
1738 | 1738 | ); |
1739 | 1739 | // This needs to remain a string to support extensions that filter Order Number. |
1740 | 1740 | $params['number'] = array( |
1741 | - 'description' => __( 'Limit result set to orders matching part of an order number.', 'woocommerce' ), |
|
1741 | + 'description' => __('Limit result set to orders matching part of an order number.', 'woocommerce'), |
|
1742 | 1742 | 'type' => 'string', |
1743 | 1743 | 'validate_callback' => 'rest_validate_request_arg', |
1744 | 1744 | ); |
@@ -1755,27 +1755,27 @@ discard block |
||
1755 | 1755 | * @param \WC_Order $order Order data. |
1756 | 1756 | * @return bool |
1757 | 1757 | */ |
1758 | - protected function calculate_coupons( $request, $order ) { |
|
1759 | - if ( ! isset( $request['coupon_lines'] ) || ! is_array( $request['coupon_lines'] ) ) { |
|
1758 | + protected function calculate_coupons($request, $order) { |
|
1759 | + if ( ! isset($request['coupon_lines']) || ! is_array($request['coupon_lines'])) { |
|
1760 | 1760 | return false; |
1761 | 1761 | } |
1762 | 1762 | |
1763 | 1763 | // Remove all coupons first to ensure calculation is correct. |
1764 | - foreach ( $order->get_items( 'coupon' ) as $coupon ) { |
|
1765 | - $order->remove_coupon( $coupon->get_code() ); |
|
1764 | + foreach ($order->get_items('coupon') as $coupon) { |
|
1765 | + $order->remove_coupon($coupon->get_code()); |
|
1766 | 1766 | } |
1767 | 1767 | |
1768 | - foreach ( $request['coupon_lines'] as $item ) { |
|
1769 | - if ( is_array( $item ) ) { |
|
1770 | - if ( empty( $item['id'] ) ) { |
|
1771 | - if ( empty( $item['code'] ) ) { |
|
1772 | - throw new \WC_REST_Exception( 'woocommerce_rest_invalid_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 ); |
|
1768 | + foreach ($request['coupon_lines'] as $item) { |
|
1769 | + if (is_array($item)) { |
|
1770 | + if (empty($item['id'])) { |
|
1771 | + if (empty($item['code'])) { |
|
1772 | + throw new \WC_REST_Exception('woocommerce_rest_invalid_coupon', __('Coupon code is required.', 'woocommerce'), 400); |
|
1773 | 1773 | } |
1774 | 1774 | |
1775 | - $results = $order->apply_coupon( wc_clean( $item['code'] ) ); |
|
1775 | + $results = $order->apply_coupon(wc_clean($item['code'])); |
|
1776 | 1776 | |
1777 | - if ( is_wp_error( $results ) ) { |
|
1778 | - throw new \WC_REST_Exception( 'woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400 ); |
|
1777 | + if (is_wp_error($results)) { |
|
1778 | + throw new \WC_REST_Exception('woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400); |
|
1779 | 1779 | } |
1780 | 1780 | } |
1781 | 1781 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * Shipping methods controller class. |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | array( |
34 | 34 | array( |
35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
36 | - 'callback' => array( $this, 'get_items' ), |
|
37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'get_items'), |
|
37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
38 | 38 | 'args' => $this->get_collection_params(), |
39 | 39 | ), |
40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
41 | 41 | ), |
42 | 42 | true |
43 | 43 | ); |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | array( |
48 | 48 | 'args' => array( |
49 | 49 | 'id' => array( |
50 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
50 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
51 | 51 | 'type' => 'string', |
52 | 52 | ), |
53 | 53 | ), |
54 | 54 | array( |
55 | 55 | 'methods' => \WP_REST_Server::READABLE, |
56 | - 'callback' => array( $this, 'get_item' ), |
|
57 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
56 | + 'callback' => array($this, 'get_item'), |
|
57 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
58 | 58 | 'args' => array( |
59 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
59 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
60 | 60 | ), |
61 | 61 | ), |
62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
62 | + 'schema' => array($this, 'get_public_item_schema'), |
|
63 | 63 | ), |
64 | 64 | true |
65 | 65 | ); |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * @param \WP_REST_Request $request Full details about the request. |
72 | 72 | * @return \WP_Error|boolean |
73 | 73 | */ |
74 | - public function get_items_permissions_check( $request ) { |
|
75 | - if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { |
|
76 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
74 | + public function get_items_permissions_check($request) { |
|
75 | + if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) { |
|
76 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
77 | 77 | } |
78 | 78 | return true; |
79 | 79 | } |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * @param \WP_REST_Request $request Full details about the request. |
85 | 85 | * @return \WP_Error|boolean |
86 | 86 | */ |
87 | - public function get_item_permissions_check( $request ) { |
|
88 | - if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { |
|
89 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
87 | + public function get_item_permissions_check($request) { |
|
88 | + if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) { |
|
89 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
90 | 90 | } |
91 | 91 | return true; |
92 | 92 | } |
@@ -97,15 +97,15 @@ discard block |
||
97 | 97 | * @param \WP_REST_Request $request Full details about the request. |
98 | 98 | * @return \WP_Error\WP_REST_Response |
99 | 99 | */ |
100 | - public function get_items( $request ) { |
|
100 | + public function get_items($request) { |
|
101 | 101 | $wc_shipping = \WC_Shipping::instance(); |
102 | 102 | $response = array(); |
103 | - foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) { |
|
104 | - $method = $this->prepare_item_for_response( $shipping_method, $request ); |
|
105 | - $method = $this->prepare_response_for_collection( $method ); |
|
103 | + foreach ($wc_shipping->get_shipping_methods() as $id => $shipping_method) { |
|
104 | + $method = $this->prepare_item_for_response($shipping_method, $request); |
|
105 | + $method = $this->prepare_response_for_collection($method); |
|
106 | 106 | $response[] = $method; |
107 | 107 | } |
108 | - return rest_ensure_response( $response ); |
|
108 | + return rest_ensure_response($response); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -114,17 +114,17 @@ discard block |
||
114 | 114 | * @param \WP_REST_Request $request Request data. |
115 | 115 | * @return \WP_REST_Response|\WP_Error |
116 | 116 | */ |
117 | - public function get_item( $request ) { |
|
117 | + public function get_item($request) { |
|
118 | 118 | $wc_shipping = \WC_Shipping::instance(); |
119 | 119 | $methods = $wc_shipping->get_shipping_methods(); |
120 | - if ( empty( $methods[ $request['id'] ] ) ) { |
|
121 | - return new \WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
120 | + if (empty($methods[$request['id']])) { |
|
121 | + return new \WP_Error('woocommerce_rest_shipping_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
122 | 122 | } |
123 | 123 | |
124 | - $method = $methods[ $request['id'] ]; |
|
125 | - $response = $this->prepare_item_for_response( $method, $request ); |
|
124 | + $method = $methods[$request['id']]; |
|
125 | + $response = $this->prepare_item_for_response($method, $request); |
|
126 | 126 | |
127 | - return rest_ensure_response( $response ); |
|
127 | + return rest_ensure_response($response); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -134,21 +134,21 @@ discard block |
||
134 | 134 | * @param \WP_REST_Request $request Request object. |
135 | 135 | * @return \WP_REST_Response $response Response data. |
136 | 136 | */ |
137 | - public function prepare_item_for_response( $method, $request ) { |
|
137 | + public function prepare_item_for_response($method, $request) { |
|
138 | 138 | $data = array( |
139 | 139 | 'id' => $method->id, |
140 | 140 | 'title' => $method->method_title, |
141 | 141 | 'description' => $method->method_description, |
142 | 142 | ); |
143 | 143 | |
144 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
145 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
146 | - $data = $this->filter_response_by_context( $data, $context ); |
|
144 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
145 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
146 | + $data = $this->filter_response_by_context($data, $context); |
|
147 | 147 | |
148 | 148 | // Wrap the data in a response object. |
149 | - $response = rest_ensure_response( $data ); |
|
149 | + $response = rest_ensure_response($data); |
|
150 | 150 | |
151 | - $response->add_links( $this->prepare_links( $method, $request ) ); |
|
151 | + $response->add_links($this->prepare_links($method, $request)); |
|
152 | 152 | |
153 | 153 | /** |
154 | 154 | * Filter shipping methods object returned from the REST API. |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param WC_Shipping_Method $method Shipping method object used to create response. |
158 | 158 | * @param \WP_REST_Request $request Request object. |
159 | 159 | */ |
160 | - return apply_filters( 'woocommerce_rest_prepare_shipping_method', $response, $method, $request ); |
|
160 | + return apply_filters('woocommerce_rest_prepare_shipping_method', $response, $method, $request); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -167,13 +167,13 @@ discard block |
||
167 | 167 | * @param \WP_REST_Request $request Request object. |
168 | 168 | * @return array |
169 | 169 | */ |
170 | - protected function prepare_links( $method, $request ) { |
|
170 | + protected function prepare_links($method, $request) { |
|
171 | 171 | $links = array( |
172 | 172 | 'self' => array( |
173 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $method->id ) ), |
|
173 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $method->id)), |
|
174 | 174 | ), |
175 | 175 | 'collection' => array( |
176 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
176 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
177 | 177 | ), |
178 | 178 | ); |
179 | 179 | |
@@ -192,27 +192,27 @@ discard block |
||
192 | 192 | 'type' => 'object', |
193 | 193 | 'properties' => array( |
194 | 194 | 'id' => array( |
195 | - 'description' => __( 'Method ID.', 'woocommerce' ), |
|
195 | + 'description' => __('Method ID.', 'woocommerce'), |
|
196 | 196 | 'type' => 'string', |
197 | - 'context' => array( 'view' ), |
|
197 | + 'context' => array('view'), |
|
198 | 198 | 'readonly' => true, |
199 | 199 | ), |
200 | 200 | 'title' => array( |
201 | - 'description' => __( 'Shipping method title.', 'woocommerce' ), |
|
201 | + 'description' => __('Shipping method title.', 'woocommerce'), |
|
202 | 202 | 'type' => 'string', |
203 | - 'context' => array( 'view' ), |
|
203 | + 'context' => array('view'), |
|
204 | 204 | 'readonly' => true, |
205 | 205 | ), |
206 | 206 | 'description' => array( |
207 | - 'description' => __( 'Shipping method description.', 'woocommerce' ), |
|
207 | + 'description' => __('Shipping method description.', 'woocommerce'), |
|
208 | 208 | 'type' => 'string', |
209 | - 'context' => array( 'view' ), |
|
209 | + 'context' => array('view'), |
|
210 | 210 | 'readonly' => true, |
211 | 211 | ), |
212 | 212 | ), |
213 | 213 | ); |
214 | 214 | |
215 | - return $this->add_additional_fields_schema( $schema ); |
|
215 | + return $this->add_additional_fields_schema($schema); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function get_collection_params() { |
224 | 224 | return array( |
225 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
225 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
226 | 226 | ); |
227 | 227 | } |
228 | 228 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | namespace WooCommerce\RestApi\Controllers\Version4; |
17 | 17 | |
18 | -defined( 'ABSPATH' ) || exit; |
|
18 | +defined('ABSPATH') || exit; |
|
19 | 19 | |
20 | 20 | use \WP_REST_Controller; |
21 | 21 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - protected function add_additional_fields_schema( $schema ) { |
|
55 | - if ( empty( $schema['title'] ) ) { |
|
54 | + protected function add_additional_fields_schema($schema) { |
|
55 | + if (empty($schema['title'])) { |
|
56 | 56 | return $schema; |
57 | 57 | } |
58 | 58 | |
@@ -61,17 +61,17 @@ discard block |
||
61 | 61 | */ |
62 | 62 | $object_type = $schema['title']; |
63 | 63 | |
64 | - $additional_fields = $this->get_additional_fields( $object_type ); |
|
64 | + $additional_fields = $this->get_additional_fields($object_type); |
|
65 | 65 | |
66 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
67 | - if ( ! $field_options['schema'] ) { |
|
66 | + foreach ($additional_fields as $field_name => $field_options) { |
|
67 | + if ( ! $field_options['schema']) { |
|
68 | 68 | continue; |
69 | 69 | } |
70 | 70 | |
71 | - $schema['properties'][ $field_name ] = $field_options['schema']; |
|
71 | + $schema['properties'][$field_name] = $field_options['schema']; |
|
72 | 72 | } |
73 | 73 | |
74 | - $schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] ); |
|
74 | + $schema['properties'] = apply_filters('woocommerce_rest_' . $object_type . '_schema', $schema['properties']); |
|
75 | 75 | |
76 | 76 | return $schema; |
77 | 77 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @return string |
83 | 83 | */ |
84 | 84 | protected function get_normalized_rest_base() { |
85 | - return preg_replace( '/\(.*\)\//i', '', $this->rest_base ); |
|
85 | + return preg_replace('/\(.*\)\//i', '', $this->rest_base); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -91,25 +91,25 @@ discard block |
||
91 | 91 | * @param array $items Request items. |
92 | 92 | * @return bool|\WP_Error |
93 | 93 | */ |
94 | - protected function check_batch_limit( $items ) { |
|
95 | - $limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() ); |
|
94 | + protected function check_batch_limit($items) { |
|
95 | + $limit = apply_filters('woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base()); |
|
96 | 96 | $total = 0; |
97 | 97 | |
98 | - if ( ! empty( $items['create'] ) ) { |
|
99 | - $total += count( $items['create'] ); |
|
98 | + if ( ! empty($items['create'])) { |
|
99 | + $total += count($items['create']); |
|
100 | 100 | } |
101 | 101 | |
102 | - if ( ! empty( $items['update'] ) ) { |
|
103 | - $total += count( $items['update'] ); |
|
102 | + if ( ! empty($items['update'])) { |
|
103 | + $total += count($items['update']); |
|
104 | 104 | } |
105 | 105 | |
106 | - if ( ! empty( $items['delete'] ) ) { |
|
107 | - $total += count( $items['delete'] ); |
|
106 | + if ( ! empty($items['delete'])) { |
|
107 | + $total += count($items['delete']); |
|
108 | 108 | } |
109 | 109 | |
110 | - if ( $total > $limit ) { |
|
110 | + if ($total > $limit) { |
|
111 | 111 | /* translators: %s: items limit */ |
112 | - return new \WP_Error( 'woocommerce_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'woocommerce' ), $limit ), array( 'status' => 413 ) ); |
|
112 | + return new \WP_Error('woocommerce_rest_request_entity_too_large', sprintf(__('Unable to accept more than %s items for this request.', 'woocommerce'), $limit), array('status' => 413)); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return true; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param \WP_REST_Request $request Full details about the request. |
122 | 122 | * @return array Of \WP_Error or \WP_REST_Response. |
123 | 123 | */ |
124 | - public function batch_items( $request ) { |
|
124 | + public function batch_items($request) { |
|
125 | 125 | /** |
126 | 126 | * REST Server |
127 | 127 | * |
@@ -130,34 +130,34 @@ discard block |
||
130 | 130 | global $wp_rest_server; |
131 | 131 | |
132 | 132 | // Get the request params. |
133 | - $items = array_filter( $request->get_params() ); |
|
133 | + $items = array_filter($request->get_params()); |
|
134 | 134 | $response = array(); |
135 | 135 | |
136 | 136 | // Check batch limit. |
137 | - $limit = $this->check_batch_limit( $items ); |
|
138 | - if ( is_wp_error( $limit ) ) { |
|
137 | + $limit = $this->check_batch_limit($items); |
|
138 | + if (is_wp_error($limit)) { |
|
139 | 139 | return $limit; |
140 | 140 | } |
141 | 141 | |
142 | - if ( ! empty( $items['create'] ) ) { |
|
143 | - foreach ( $items['create'] as $item ) { |
|
144 | - $_item = new \WP_REST_Request( 'POST' ); |
|
142 | + if ( ! empty($items['create'])) { |
|
143 | + foreach ($items['create'] as $item) { |
|
144 | + $_item = new \WP_REST_Request('POST'); |
|
145 | 145 | |
146 | 146 | // Default parameters. |
147 | 147 | $defaults = array(); |
148 | 148 | $schema = $this->get_public_item_schema(); |
149 | - foreach ( $schema['properties'] as $arg => $options ) { |
|
150 | - if ( isset( $options['default'] ) ) { |
|
151 | - $defaults[ $arg ] = $options['default']; |
|
149 | + foreach ($schema['properties'] as $arg => $options) { |
|
150 | + if (isset($options['default'])) { |
|
151 | + $defaults[$arg] = $options['default']; |
|
152 | 152 | } |
153 | 153 | } |
154 | - $_item->set_default_params( $defaults ); |
|
154 | + $_item->set_default_params($defaults); |
|
155 | 155 | |
156 | 156 | // Set request parameters. |
157 | - $_item->set_body_params( $item ); |
|
158 | - $_response = $this->create_item( $_item ); |
|
157 | + $_item->set_body_params($item); |
|
158 | + $_response = $this->create_item($_item); |
|
159 | 159 | |
160 | - if ( is_wp_error( $_response ) ) { |
|
160 | + if (is_wp_error($_response)) { |
|
161 | 161 | $response['create'][] = array( |
162 | 162 | 'id' => 0, |
163 | 163 | 'error' => array( |
@@ -167,18 +167,18 @@ discard block |
||
167 | 167 | ), |
168 | 168 | ); |
169 | 169 | } else { |
170 | - $response['create'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
170 | + $response['create'][] = $wp_rest_server->response_to_data($_response, ''); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | - if ( ! empty( $items['update'] ) ) { |
|
176 | - foreach ( $items['update'] as $item ) { |
|
177 | - $_item = new \WP_REST_Request( 'PUT' ); |
|
178 | - $_item->set_body_params( $item ); |
|
179 | - $_response = $this->update_item( $_item ); |
|
175 | + if ( ! empty($items['update'])) { |
|
176 | + foreach ($items['update'] as $item) { |
|
177 | + $_item = new \WP_REST_Request('PUT'); |
|
178 | + $_item->set_body_params($item); |
|
179 | + $_response = $this->update_item($_item); |
|
180 | 180 | |
181 | - if ( is_wp_error( $_response ) ) { |
|
181 | + if (is_wp_error($_response)) { |
|
182 | 182 | $response['update'][] = array( |
183 | 183 | 'id' => $item['id'], |
184 | 184 | 'error' => array( |
@@ -188,29 +188,29 @@ discard block |
||
188 | 188 | ), |
189 | 189 | ); |
190 | 190 | } else { |
191 | - $response['update'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
191 | + $response['update'][] = $wp_rest_server->response_to_data($_response, ''); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - if ( ! empty( $items['delete'] ) ) { |
|
197 | - foreach ( $items['delete'] as $id ) { |
|
196 | + if ( ! empty($items['delete'])) { |
|
197 | + foreach ($items['delete'] as $id) { |
|
198 | 198 | $id = (int) $id; |
199 | 199 | |
200 | - if ( 0 === $id ) { |
|
200 | + if (0 === $id) { |
|
201 | 201 | continue; |
202 | 202 | } |
203 | 203 | |
204 | - $_item = new \WP_REST_Request( 'DELETE' ); |
|
204 | + $_item = new \WP_REST_Request('DELETE'); |
|
205 | 205 | $_item->set_query_params( |
206 | 206 | array( |
207 | 207 | 'id' => $id, |
208 | 208 | 'force' => true, |
209 | 209 | ) |
210 | 210 | ); |
211 | - $_response = $this->delete_item( $_item ); |
|
211 | + $_response = $this->delete_item($_item); |
|
212 | 212 | |
213 | - if ( is_wp_error( $_response ) ) { |
|
213 | + if (is_wp_error($_response)) { |
|
214 | 214 | $response['delete'][] = array( |
215 | 215 | 'id' => $id, |
216 | 216 | 'error' => array( |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | ), |
221 | 221 | ); |
222 | 222 | } else { |
223 | - $response['delete'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
223 | + $response['delete'][] = $wp_rest_server->response_to_data($_response, ''); |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | } |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | * @param array $setting Setting. |
237 | 237 | * @return string |
238 | 238 | */ |
239 | - public function validate_setting_text_field( $value, $setting ) { |
|
240 | - $value = is_null( $value ) ? '' : $value; |
|
241 | - return wp_kses_post( trim( stripslashes( $value ) ) ); |
|
239 | + public function validate_setting_text_field($value, $setting) { |
|
240 | + $value = is_null($value) ? '' : $value; |
|
241 | + return wp_kses_post(trim(stripslashes($value))); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -249,11 +249,11 @@ discard block |
||
249 | 249 | * @param array $setting Setting. |
250 | 250 | * @return string|\WP_Error |
251 | 251 | */ |
252 | - public function validate_setting_select_field( $value, $setting ) { |
|
253 | - if ( array_key_exists( $value, $setting['options'] ) ) { |
|
252 | + public function validate_setting_select_field($value, $setting) { |
|
253 | + if (array_key_exists($value, $setting['options'])) { |
|
254 | 254 | return $value; |
255 | 255 | } else { |
256 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
256 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
@@ -265,18 +265,18 @@ discard block |
||
265 | 265 | * @param array $setting Setting. |
266 | 266 | * @return array|\WP_Error |
267 | 267 | */ |
268 | - public function validate_setting_multiselect_field( $values, $setting ) { |
|
269 | - if ( empty( $values ) ) { |
|
268 | + public function validate_setting_multiselect_field($values, $setting) { |
|
269 | + if (empty($values)) { |
|
270 | 270 | return array(); |
271 | 271 | } |
272 | 272 | |
273 | - if ( ! is_array( $values ) ) { |
|
274 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
273 | + if ( ! is_array($values)) { |
|
274 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | $final_values = array(); |
278 | - foreach ( $values as $value ) { |
|
279 | - if ( array_key_exists( $value, $setting['options'] ) ) { |
|
278 | + foreach ($values as $value) { |
|
279 | + if (array_key_exists($value, $setting['options'])) { |
|
280 | 280 | $final_values[] = $value; |
281 | 281 | } |
282 | 282 | } |
@@ -292,19 +292,19 @@ discard block |
||
292 | 292 | * @param array $setting Setting. |
293 | 293 | * @return string|\WP_Error |
294 | 294 | */ |
295 | - public function validate_setting_image_width_field( $values, $setting ) { |
|
296 | - if ( ! is_array( $values ) ) { |
|
297 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
295 | + public function validate_setting_image_width_field($values, $setting) { |
|
296 | + if ( ! is_array($values)) { |
|
297 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | $current = $setting['value']; |
301 | - if ( isset( $values['width'] ) ) { |
|
302 | - $current['width'] = intval( $values['width'] ); |
|
301 | + if (isset($values['width'])) { |
|
302 | + $current['width'] = intval($values['width']); |
|
303 | 303 | } |
304 | - if ( isset( $values['height'] ) ) { |
|
305 | - $current['height'] = intval( $values['height'] ); |
|
304 | + if (isset($values['height'])) { |
|
305 | + $current['height'] = intval($values['height']); |
|
306 | 306 | } |
307 | - if ( isset( $values['crop'] ) ) { |
|
307 | + if (isset($values['crop'])) { |
|
308 | 308 | $current['crop'] = (bool) $values['crop']; |
309 | 309 | } |
310 | 310 | return $current; |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | * @param array $setting Setting. |
319 | 319 | * @return string|\WP_Error |
320 | 320 | */ |
321 | - public function validate_setting_radio_field( $value, $setting ) { |
|
322 | - return $this->validate_setting_select_field( $value, $setting ); |
|
321 | + public function validate_setting_radio_field($value, $setting) { |
|
322 | + return $this->validate_setting_select_field($value, $setting); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -330,14 +330,14 @@ discard block |
||
330 | 330 | * @param array $setting Setting. |
331 | 331 | * @return string|\WP_Error |
332 | 332 | */ |
333 | - public function validate_setting_checkbox_field( $value, $setting ) { |
|
334 | - if ( in_array( $value, array( 'yes', 'no' ) ) ) { |
|
333 | + public function validate_setting_checkbox_field($value, $setting) { |
|
334 | + if (in_array($value, array('yes', 'no'))) { |
|
335 | 335 | return $value; |
336 | - } elseif ( empty( $value ) ) { |
|
337 | - $value = isset( $setting['default'] ) ? $setting['default'] : 'no'; |
|
336 | + } elseif (empty($value)) { |
|
337 | + $value = isset($setting['default']) ? $setting['default'] : 'no'; |
|
338 | 338 | return $value; |
339 | 339 | } else { |
340 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
340 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
@@ -349,10 +349,10 @@ discard block |
||
349 | 349 | * @param array $setting Setting. |
350 | 350 | * @return string |
351 | 351 | */ |
352 | - public function validate_setting_textarea_field( $value, $setting ) { |
|
353 | - $value = is_null( $value ) ? '' : $value; |
|
352 | + public function validate_setting_textarea_field($value, $setting) { |
|
353 | + $value = is_null($value) ? '' : $value; |
|
354 | 354 | return wp_kses( |
355 | - trim( stripslashes( $value ) ), |
|
355 | + trim(stripslashes($value)), |
|
356 | 356 | array_merge( |
357 | 357 | array( |
358 | 358 | 'iframe' => array( |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | 'class' => true, |
363 | 363 | ), |
364 | 364 | ), |
365 | - wp_kses_allowed_html( 'post' ) |
|
365 | + wp_kses_allowed_html('post') |
|
366 | 366 | ) |
367 | 367 | ); |
368 | 368 | } |
@@ -375,8 +375,8 @@ discard block |
||
375 | 375 | * @param array $meta_query Meta query. |
376 | 376 | * @return array |
377 | 377 | */ |
378 | - protected function add_meta_query( $args, $meta_query ) { |
|
379 | - if ( empty( $args['meta_query'] ) ) { |
|
378 | + protected function add_meta_query($args, $meta_query) { |
|
379 | + if (empty($args['meta_query'])) { |
|
380 | 380 | $args['meta_query'] = array(); |
381 | 381 | } |
382 | 382 | |
@@ -397,25 +397,25 @@ discard block |
||
397 | 397 | 'type' => 'object', |
398 | 398 | 'properties' => array( |
399 | 399 | 'create' => array( |
400 | - 'description' => __( 'List of created resources.', 'woocommerce' ), |
|
400 | + 'description' => __('List of created resources.', 'woocommerce'), |
|
401 | 401 | 'type' => 'array', |
402 | - 'context' => array( 'view', 'edit' ), |
|
402 | + 'context' => array('view', 'edit'), |
|
403 | 403 | 'items' => array( |
404 | 404 | 'type' => 'object', |
405 | 405 | ), |
406 | 406 | ), |
407 | 407 | 'update' => array( |
408 | - 'description' => __( 'List of updated resources.', 'woocommerce' ), |
|
408 | + 'description' => __('List of updated resources.', 'woocommerce'), |
|
409 | 409 | 'type' => 'array', |
410 | - 'context' => array( 'view', 'edit' ), |
|
410 | + 'context' => array('view', 'edit'), |
|
411 | 411 | 'items' => array( |
412 | 412 | 'type' => 'object', |
413 | 413 | ), |
414 | 414 | ), |
415 | 415 | 'delete' => array( |
416 | - 'description' => __( 'List of delete resources.', 'woocommerce' ), |
|
416 | + 'description' => __('List of delete resources.', 'woocommerce'), |
|
417 | 417 | 'type' => 'array', |
418 | - 'context' => array( 'view', 'edit' ), |
|
418 | + 'context' => array('view', 'edit'), |
|
419 | 419 | 'items' => array( |
420 | 420 | 'type' => 'integer', |
421 | 421 | ), |
@@ -435,32 +435,32 @@ discard block |
||
435 | 435 | * @param \WP_REST_Request $request Full details about the request. |
436 | 436 | * @return array Fields to be included in the response. |
437 | 437 | */ |
438 | - public function get_fields_for_response( $request ) { |
|
438 | + public function get_fields_for_response($request) { |
|
439 | 439 | $schema = $this->get_item_schema(); |
440 | - $fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array(); |
|
440 | + $fields = isset($schema['properties']) ? array_keys($schema['properties']) : array(); |
|
441 | 441 | |
442 | 442 | $additional_fields = $this->get_additional_fields(); |
443 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
443 | + foreach ($additional_fields as $field_name => $field_options) { |
|
444 | 444 | // For back-compat, include any field with an empty schema |
445 | 445 | // because it won't be present in $this->get_item_schema(). |
446 | - if ( is_null( $field_options['schema'] ) ) { |
|
446 | + if (is_null($field_options['schema'])) { |
|
447 | 447 | $fields[] = $field_name; |
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | - if ( ! isset( $request['_fields'] ) ) { |
|
451 | + if ( ! isset($request['_fields'])) { |
|
452 | 452 | return $fields; |
453 | 453 | } |
454 | - $requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] ); |
|
455 | - if ( 0 === count( $requested_fields ) ) { |
|
454 | + $requested_fields = is_array($request['_fields']) ? $request['_fields'] : preg_split('/[\s,]+/', $request['_fields']); |
|
455 | + if (0 === count($requested_fields)) { |
|
456 | 456 | return $fields; |
457 | 457 | } |
458 | 458 | // Trim off outside whitespace from the comma delimited list. |
459 | - $requested_fields = array_map( 'trim', $requested_fields ); |
|
459 | + $requested_fields = array_map('trim', $requested_fields); |
|
460 | 460 | // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
461 | - if ( in_array( 'id', $fields, true ) ) { |
|
461 | + if (in_array('id', $fields, true)) { |
|
462 | 462 | $requested_fields[] = 'id'; |
463 | 463 | } |
464 | - return array_intersect( $fields, $requested_fields ); |
|
464 | + return array_intersect($fields, $requested_fields); |
|
465 | 465 | } |
466 | 466 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API reports controller class. |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | array( |
34 | 34 | array( |
35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
36 | - 'callback' => array( $this, 'get_items' ), |
|
37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'get_items'), |
|
37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
38 | 38 | 'args' => $this->get_collection_params(), |
39 | 39 | ), |
40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
41 | 41 | ), |
42 | 42 | true |
43 | 43 | ); |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | * @param \WP_REST_Request $request Full details about the request. |
50 | 50 | * @return \WP_Error|boolean |
51 | 51 | */ |
52 | - public function get_items_permissions_check( $request ) { |
|
53 | - if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) { |
|
54 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
52 | + public function get_items_permissions_check($request) { |
|
53 | + if ( ! wc_rest_check_manager_permissions('reports', 'read')) { |
|
54 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | return true; |
@@ -64,66 +64,66 @@ discard block |
||
64 | 64 | * @param \WP_REST_Request $request Request data. |
65 | 65 | * @return array|\WP_Error |
66 | 66 | */ |
67 | - public function get_items( $request ) { |
|
67 | + public function get_items($request) { |
|
68 | 68 | $data = []; |
69 | 69 | $reports = []; |
70 | - if ( class_exists( 'WC_Admin_Reports_Sync' ) ) { |
|
70 | + if (class_exists('WC_Admin_Reports_Sync')) { |
|
71 | 71 | $reports = array( |
72 | 72 | array( |
73 | 73 | 'slug' => 'performance-indicators', |
74 | - 'description' => __( 'Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce' ), |
|
74 | + 'description' => __('Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce'), |
|
75 | 75 | ), |
76 | 76 | array( |
77 | 77 | 'slug' => 'revenue/stats', |
78 | - 'description' => __( 'Stats about revenue.', 'woocommerce' ), |
|
78 | + 'description' => __('Stats about revenue.', 'woocommerce'), |
|
79 | 79 | ), |
80 | 80 | array( |
81 | 81 | 'slug' => 'orders/stats', |
82 | - 'description' => __( 'Stats about orders.', 'woocommerce' ), |
|
82 | + 'description' => __('Stats about orders.', 'woocommerce'), |
|
83 | 83 | ), |
84 | 84 | array( |
85 | 85 | 'slug' => 'products', |
86 | - 'description' => __( 'Products detailed reports.', 'woocommerce' ), |
|
86 | + 'description' => __('Products detailed reports.', 'woocommerce'), |
|
87 | 87 | ), |
88 | 88 | array( |
89 | 89 | 'slug' => 'products/stats', |
90 | - 'description' => __( 'Stats about products.', 'woocommerce' ), |
|
90 | + 'description' => __('Stats about products.', 'woocommerce'), |
|
91 | 91 | ), |
92 | 92 | array( |
93 | 93 | 'slug' => 'categories', |
94 | - 'description' => __( 'Product categories detailed reports.', 'woocommerce' ), |
|
94 | + 'description' => __('Product categories detailed reports.', 'woocommerce'), |
|
95 | 95 | ), |
96 | 96 | array( |
97 | 97 | 'slug' => 'categories/stats', |
98 | - 'description' => __( 'Stats about product categories.', 'woocommerce' ), |
|
98 | + 'description' => __('Stats about product categories.', 'woocommerce'), |
|
99 | 99 | ), |
100 | 100 | array( |
101 | 101 | 'slug' => 'coupons', |
102 | - 'description' => __( 'Coupons detailed reports.', 'woocommerce' ), |
|
102 | + 'description' => __('Coupons detailed reports.', 'woocommerce'), |
|
103 | 103 | ), |
104 | 104 | array( |
105 | 105 | 'slug' => 'coupons/stats', |
106 | - 'description' => __( 'Stats about coupons.', 'woocommerce' ), |
|
106 | + 'description' => __('Stats about coupons.', 'woocommerce'), |
|
107 | 107 | ), |
108 | 108 | array( |
109 | 109 | 'slug' => 'taxes', |
110 | - 'description' => __( 'Taxes detailed reports.', 'woocommerce' ), |
|
110 | + 'description' => __('Taxes detailed reports.', 'woocommerce'), |
|
111 | 111 | ), |
112 | 112 | array( |
113 | 113 | 'slug' => 'taxes/stats', |
114 | - 'description' => __( 'Stats about taxes.', 'woocommerce' ), |
|
114 | + 'description' => __('Stats about taxes.', 'woocommerce'), |
|
115 | 115 | ), |
116 | 116 | array( |
117 | 117 | 'slug' => 'downloads', |
118 | - 'description' => __( 'Product downloads detailed reports.', 'woocommerce' ), |
|
118 | + 'description' => __('Product downloads detailed reports.', 'woocommerce'), |
|
119 | 119 | ), |
120 | 120 | array( |
121 | 121 | 'slug' => 'downloads/stats', |
122 | - 'description' => __( 'Stats about product downloads.', 'woocommerce' ), |
|
122 | + 'description' => __('Stats about product downloads.', 'woocommerce'), |
|
123 | 123 | ), |
124 | 124 | array( |
125 | 125 | 'slug' => 'customers', |
126 | - 'description' => __( 'Customers detailed reports.', 'woocommerce' ), |
|
126 | + 'description' => __('Customers detailed reports.', 'woocommerce'), |
|
127 | 127 | ), |
128 | 128 | ); |
129 | 129 | } |
@@ -135,22 +135,22 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @param array $endpoints The list of allowed reports.. |
137 | 137 | */ |
138 | - $reports = apply_filters( 'woocommerce_admin_reports', $reports ); |
|
138 | + $reports = apply_filters('woocommerce_admin_reports', $reports); |
|
139 | 139 | |
140 | - foreach ( $reports as $report ) { |
|
141 | - if ( empty( $report['slug'] ) ) { |
|
140 | + foreach ($reports as $report) { |
|
141 | + if (empty($report['slug'])) { |
|
142 | 142 | continue; |
143 | 143 | } |
144 | 144 | |
145 | - if ( empty( $report['path'] ) ) { |
|
145 | + if (empty($report['path'])) { |
|
146 | 146 | $report['path'] = '/' . $this->namespace . '/reports/' . $report['slug']; |
147 | 147 | } |
148 | 148 | |
149 | 149 | // Allows a different admin page to be loaded here, |
150 | 150 | // or allows an empty url if no report exists for a set of performance indicators. |
151 | - if ( ! isset( $report['url'] ) ) { |
|
152 | - if ( '/stats' === substr( $report['slug'], -6 ) ) { |
|
153 | - $url_slug = substr( $report['slug'], 0, -6 ); |
|
151 | + if ( ! isset($report['url'])) { |
|
152 | + if ('/stats' === substr($report['slug'], -6)) { |
|
153 | + $url_slug = substr($report['slug'], 0, -6); |
|
154 | 154 | } else { |
155 | 155 | $url_slug = $report['slug']; |
156 | 156 | } |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | $report['url'] = '/analytics/' . $url_slug; |
159 | 159 | } |
160 | 160 | |
161 | - $item = $this->prepare_item_for_response( (object) $report, $request ); |
|
162 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
161 | + $item = $this->prepare_item_for_response((object) $report, $request); |
|
162 | + $data[] = $this->prepare_response_for_collection($item); |
|
163 | 163 | } |
164 | 164 | |
165 | - return rest_ensure_response( $data ); |
|
165 | + return rest_ensure_response($data); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,14 +172,14 @@ discard block |
||
172 | 172 | * @param int $order_id Order ID. |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - public function get_order_number( $order_id ) { |
|
176 | - $order = wc_get_order( $order_id ); |
|
175 | + public function get_order_number($order_id) { |
|
176 | + $order = wc_get_order($order_id); |
|
177 | 177 | |
178 | - if ( 'shop_order_refund' === $order->get_type() ) { |
|
179 | - $order = wc_get_order( $order->get_parent_id() ); |
|
178 | + if ('shop_order_refund' === $order->get_type()) { |
|
179 | + $order = wc_get_order($order->get_parent_id()); |
|
180 | 180 | } |
181 | 181 | |
182 | - if ( ! has_filter( 'woocommerce_order_number' ) ) { |
|
182 | + if ( ! has_filter('woocommerce_order_number')) { |
|
183 | 183 | return $order->get_id(); |
184 | 184 | } |
185 | 185 | |
@@ -193,29 +193,29 @@ discard block |
||
193 | 193 | * @param \WP_REST_Request $request Request object. |
194 | 194 | * @return \WP_REST_Response |
195 | 195 | */ |
196 | - public function prepare_item_for_response( $report, $request ) { |
|
196 | + public function prepare_item_for_response($report, $request) { |
|
197 | 197 | $data = array( |
198 | 198 | 'slug' => $report->slug, |
199 | 199 | 'description' => $report->description, |
200 | 200 | 'path' => $report->path, |
201 | 201 | ); |
202 | 202 | |
203 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
204 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
205 | - $data = $this->filter_response_by_context( $data, $context ); |
|
203 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
204 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
205 | + $data = $this->filter_response_by_context($data, $context); |
|
206 | 206 | |
207 | 207 | // Wrap the data in a response object. |
208 | - $response = rest_ensure_response( $data ); |
|
208 | + $response = rest_ensure_response($data); |
|
209 | 209 | $response->add_links( |
210 | 210 | array( |
211 | 211 | 'self' => array( |
212 | - 'href' => rest_url( $report->path ), |
|
212 | + 'href' => rest_url($report->path), |
|
213 | 213 | ), |
214 | 214 | 'report' => array( |
215 | 215 | 'href' => $report->url, |
216 | 216 | ), |
217 | 217 | 'collection' => array( |
218 | - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), |
|
218 | + 'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)), |
|
219 | 219 | ), |
220 | 220 | ) |
221 | 221 | ); |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @param object $report The original report object. |
230 | 230 | * @param \WP_REST_Request $request Request used to generate the response. |
231 | 231 | */ |
232 | - return apply_filters( 'woocommerce_rest_prepare_report', $response, $report, $request ); |
|
232 | + return apply_filters('woocommerce_rest_prepare_report', $response, $report, $request); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -244,27 +244,27 @@ discard block |
||
244 | 244 | 'type' => 'object', |
245 | 245 | 'properties' => array( |
246 | 246 | 'slug' => array( |
247 | - 'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ), |
|
247 | + 'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'), |
|
248 | 248 | 'type' => 'string', |
249 | - 'context' => array( 'view' ), |
|
249 | + 'context' => array('view'), |
|
250 | 250 | 'readonly' => true, |
251 | 251 | ), |
252 | 252 | 'description' => array( |
253 | - 'description' => __( 'A human-readable description of the resource.', 'woocommerce' ), |
|
253 | + 'description' => __('A human-readable description of the resource.', 'woocommerce'), |
|
254 | 254 | 'type' => 'string', |
255 | - 'context' => array( 'view' ), |
|
255 | + 'context' => array('view'), |
|
256 | 256 | 'readonly' => true, |
257 | 257 | ), |
258 | 258 | 'path' => array( |
259 | - 'description' => __( 'API path.', 'woocommerce' ), |
|
259 | + 'description' => __('API path.', 'woocommerce'), |
|
260 | 260 | 'type' => 'string', |
261 | - 'context' => array( 'view' ), |
|
261 | + 'context' => array('view'), |
|
262 | 262 | 'readonly' => true, |
263 | 263 | ), |
264 | 264 | ), |
265 | 265 | ); |
266 | 266 | |
267 | - return $this->add_additional_fields_schema( $schema ); |
|
267 | + return $this->add_additional_fields_schema($schema); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | */ |
275 | 275 | public function get_collection_params() { |
276 | 276 | return array( |
277 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
277 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
278 | 278 | ); |
279 | 279 | } |
280 | 280 | |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | public function get_order_statuses() { |
287 | 287 | $order_statuses = array(); |
288 | 288 | |
289 | - foreach ( array_keys( wc_get_order_statuses() ) as $status ) { |
|
290 | - $order_statuses[] = str_replace( 'wc-', '', $status ); |
|
289 | + foreach (array_keys(wc_get_order_statuses()) as $status) { |
|
290 | + $order_statuses[] = str_replace('wc-', '', $status); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | return $order_statuses; |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Product Attributes controller class. |
@@ -40,26 +40,26 @@ discard block |
||
40 | 40 | array( |
41 | 41 | array( |
42 | 42 | 'methods' => \WP_REST_Server::READABLE, |
43 | - 'callback' => array( $this, 'get_items' ), |
|
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
43 | + 'callback' => array($this, 'get_items'), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | 45 | 'args' => $this->get_collection_params(), |
46 | 46 | ), |
47 | 47 | array( |
48 | 48 | 'methods' => \WP_REST_Server::CREATABLE, |
49 | - 'callback' => array( $this, 'create_item' ), |
|
50 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
49 | + 'callback' => array($this, 'create_item'), |
|
50 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
51 | 51 | 'args' => array_merge( |
52 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
52 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
53 | 53 | array( |
54 | 54 | 'name' => array( |
55 | - 'description' => __( 'Name for the resource.', 'woocommerce' ), |
|
55 | + 'description' => __('Name for the resource.', 'woocommerce'), |
|
56 | 56 | 'type' => 'string', |
57 | 57 | 'required' => true, |
58 | 58 | ), |
59 | 59 | ) |
60 | 60 | ), |
61 | 61 | ), |
62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
62 | + 'schema' => array($this, 'get_public_item_schema'), |
|
63 | 63 | ), |
64 | 64 | true |
65 | 65 | ); |
@@ -70,37 +70,37 @@ discard block |
||
70 | 70 | array( |
71 | 71 | 'args' => array( |
72 | 72 | 'id' => array( |
73 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
73 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
74 | 74 | 'type' => 'integer', |
75 | 75 | ), |
76 | 76 | ), |
77 | 77 | array( |
78 | 78 | 'methods' => \WP_REST_Server::READABLE, |
79 | - 'callback' => array( $this, 'get_item' ), |
|
80 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
79 | + 'callback' => array($this, 'get_item'), |
|
80 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
81 | 81 | 'args' => array( |
82 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
82 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
83 | 83 | ), |
84 | 84 | ), |
85 | 85 | array( |
86 | 86 | 'methods' => \WP_REST_Server::EDITABLE, |
87 | - 'callback' => array( $this, 'update_item' ), |
|
88 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
89 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
87 | + 'callback' => array($this, 'update_item'), |
|
88 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
89 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
90 | 90 | ), |
91 | 91 | array( |
92 | 92 | 'methods' => \WP_REST_Server::DELETABLE, |
93 | - 'callback' => array( $this, 'delete_item' ), |
|
94 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
93 | + 'callback' => array($this, 'delete_item'), |
|
94 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
95 | 95 | 'args' => array( |
96 | 96 | 'force' => array( |
97 | 97 | 'default' => true, |
98 | 98 | 'type' => 'boolean', |
99 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
99 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
100 | 100 | ), |
101 | 101 | ), |
102 | 102 | ), |
103 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
103 | + 'schema' => array($this, 'get_public_item_schema'), |
|
104 | 104 | ), |
105 | 105 | true |
106 | 106 | ); |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | array( |
112 | 112 | array( |
113 | 113 | 'methods' => \WP_REST_Server::EDITABLE, |
114 | - 'callback' => array( $this, 'batch_items' ), |
|
115 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
116 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
114 | + 'callback' => array($this, 'batch_items'), |
|
115 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
116 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
117 | 117 | ), |
118 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
118 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
119 | 119 | ), |
120 | 120 | true |
121 | 121 | ); |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * @param \WP_REST_Request $request Full details about the request. |
128 | 128 | * @return \WP_Error|boolean |
129 | 129 | */ |
130 | - public function get_items_permissions_check( $request ) { |
|
131 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) { |
|
132 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
130 | + public function get_items_permissions_check($request) { |
|
131 | + if ( ! wc_rest_check_manager_permissions('attributes', 'read')) { |
|
132 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | return true; |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @param \WP_REST_Request $request Full details about the request. |
142 | 142 | * @return \WP_Error|boolean |
143 | 143 | */ |
144 | - public function create_item_permissions_check( $request ) { |
|
145 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'create' ) ) { |
|
146 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you cannot create new resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
144 | + public function create_item_permissions_check($request) { |
|
145 | + if ( ! wc_rest_check_manager_permissions('attributes', 'create')) { |
|
146 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you cannot create new resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return true; |
@@ -155,13 +155,13 @@ 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 get_item_permissions_check( $request ) { |
|
159 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
160 | - return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
158 | + public function get_item_permissions_check($request) { |
|
159 | + if ( ! $this->get_taxonomy($request)) { |
|
160 | + return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
161 | 161 | } |
162 | 162 | |
163 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) { |
|
164 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
163 | + if ( ! wc_rest_check_manager_permissions('attributes', 'read')) { |
|
164 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | return true; |
@@ -173,13 +173,13 @@ 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 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
178 | - return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
176 | + public function update_item_permissions_check($request) { |
|
177 | + if ( ! $this->get_taxonomy($request)) { |
|
178 | + return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'edit' ) ) { |
|
182 | - return new \WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
181 | + if ( ! wc_rest_check_manager_permissions('attributes', 'edit')) { |
|
182 | + return new \WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return true; |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | * @param \WP_REST_Request $request Full details about the request. |
192 | 192 | * @return \WP_Error|boolean |
193 | 193 | */ |
194 | - public function delete_item_permissions_check( $request ) { |
|
195 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
196 | - return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
194 | + public function delete_item_permissions_check($request) { |
|
195 | + if ( ! $this->get_taxonomy($request)) { |
|
196 | + return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'delete' ) ) { |
|
200 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
199 | + if ( ! wc_rest_check_manager_permissions('attributes', 'delete')) { |
|
200 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | return true; |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @return bool|\WP_Error |
212 | 212 | */ |
213 | - public function batch_items_permissions_check( $request ) { |
|
214 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'batch' ) ) { |
|
215 | - return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
213 | + public function batch_items_permissions_check($request) { |
|
214 | + if ( ! wc_rest_check_manager_permissions('attributes', 'batch')) { |
|
215 | + return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | return true; |
@@ -224,16 +224,16 @@ discard block |
||
224 | 224 | * @param \WP_REST_Request $request Request params. |
225 | 225 | * @return array |
226 | 226 | */ |
227 | - public function get_items( $request ) { |
|
227 | + public function get_items($request) { |
|
228 | 228 | $attributes = wc_get_attribute_taxonomies(); |
229 | 229 | $data = array(); |
230 | - foreach ( $attributes as $attribute_obj ) { |
|
231 | - $attribute = $this->prepare_item_for_response( $attribute_obj, $request ); |
|
232 | - $attribute = $this->prepare_response_for_collection( $attribute ); |
|
230 | + foreach ($attributes as $attribute_obj) { |
|
231 | + $attribute = $this->prepare_item_for_response($attribute_obj, $request); |
|
232 | + $attribute = $this->prepare_response_for_collection($attribute); |
|
233 | 233 | $data[] = $attribute; |
234 | 234 | } |
235 | 235 | |
236 | - return rest_ensure_response( $data ); |
|
236 | + return rest_ensure_response($data); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -242,31 +242,31 @@ discard block |
||
242 | 242 | * @param \WP_REST_Request $request Full details about the request. |
243 | 243 | * @return \WP_REST_Request|\WP_Error |
244 | 244 | */ |
245 | - public function create_item( $request ) { |
|
245 | + public function create_item($request) { |
|
246 | 246 | global $wpdb; |
247 | 247 | |
248 | 248 | $id = wc_create_attribute( |
249 | 249 | array( |
250 | 250 | 'name' => $request['name'], |
251 | - 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), |
|
252 | - 'type' => ! empty( $request['type'] ) ? $request['type'] : 'select', |
|
253 | - 'order_by' => ! empty( $request['order_by'] ) ? $request['order_by'] : 'menu_order', |
|
251 | + 'slug' => wc_sanitize_taxonomy_name(stripslashes($request['slug'])), |
|
252 | + 'type' => ! empty($request['type']) ? $request['type'] : 'select', |
|
253 | + 'order_by' => ! empty($request['order_by']) ? $request['order_by'] : 'menu_order', |
|
254 | 254 | 'has_archives' => true === $request['has_archives'], |
255 | 255 | ) |
256 | 256 | ); |
257 | 257 | |
258 | 258 | // Checks for errors. |
259 | - if ( is_wp_error( $id ) ) { |
|
260 | - return new \WP_Error( 'woocommerce_rest_cannot_create', $id->get_error_message(), array( 'status' => 400 ) ); |
|
259 | + if (is_wp_error($id)) { |
|
260 | + return new \WP_Error('woocommerce_rest_cannot_create', $id->get_error_message(), array('status' => 400)); |
|
261 | 261 | } |
262 | 262 | |
263 | - $attribute = $this->get_attribute( $id ); |
|
263 | + $attribute = $this->get_attribute($id); |
|
264 | 264 | |
265 | - if ( is_wp_error( $attribute ) ) { |
|
265 | + if (is_wp_error($attribute)) { |
|
266 | 266 | return $attribute; |
267 | 267 | } |
268 | 268 | |
269 | - $this->update_additional_fields_for_object( $attribute, $request ); |
|
269 | + $this->update_additional_fields_for_object($attribute, $request); |
|
270 | 270 | |
271 | 271 | /** |
272 | 272 | * Fires after a single product attribute is created or updated via the REST API. |
@@ -275,13 +275,13 @@ discard block |
||
275 | 275 | * @param \WP_REST_Request $request Request object. |
276 | 276 | * @param boolean $creating True when creating attribute, false when updating. |
277 | 277 | */ |
278 | - do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, true ); |
|
278 | + do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, true); |
|
279 | 279 | |
280 | - $request->set_param( 'context', 'edit' ); |
|
281 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
282 | - $response = rest_ensure_response( $response ); |
|
283 | - $response->set_status( 201 ); |
|
284 | - $response->header( 'Location', rest_url( '/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id ) ); |
|
280 | + $request->set_param('context', 'edit'); |
|
281 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
282 | + $response = rest_ensure_response($response); |
|
283 | + $response->set_status(201); |
|
284 | + $response->header('Location', rest_url('/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id)); |
|
285 | 285 | |
286 | 286 | return $response; |
287 | 287 | } |
@@ -292,16 +292,16 @@ discard block |
||
292 | 292 | * @param \WP_REST_Request $request Full details about the request. |
293 | 293 | * @return \WP_REST_Request|\WP_Error |
294 | 294 | */ |
295 | - public function get_item( $request ) { |
|
296 | - $attribute = $this->get_attribute( (int) $request['id'] ); |
|
295 | + public function get_item($request) { |
|
296 | + $attribute = $this->get_attribute((int) $request['id']); |
|
297 | 297 | |
298 | - if ( is_wp_error( $attribute ) ) { |
|
298 | + if (is_wp_error($attribute)) { |
|
299 | 299 | return $attribute; |
300 | 300 | } |
301 | 301 | |
302 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
302 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
303 | 303 | |
304 | - return rest_ensure_response( $response ); |
|
304 | + return rest_ensure_response($response); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * @param \WP_REST_Request $request Full details about the request. |
311 | 311 | * @return \WP_REST_Request|\WP_Error |
312 | 312 | */ |
313 | - public function update_item( $request ) { |
|
313 | + public function update_item($request) { |
|
314 | 314 | global $wpdb; |
315 | 315 | |
316 | 316 | $id = (int) $request['id']; |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | $id, |
319 | 319 | array( |
320 | 320 | 'name' => $request['name'], |
321 | - 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), |
|
321 | + 'slug' => wc_sanitize_taxonomy_name(stripslashes($request['slug'])), |
|
322 | 322 | 'type' => $request['type'], |
323 | 323 | 'order_by' => $request['order_by'], |
324 | 324 | 'has_archives' => $request['has_archives'], |
@@ -326,17 +326,17 @@ discard block |
||
326 | 326 | ); |
327 | 327 | |
328 | 328 | // Checks for errors. |
329 | - if ( is_wp_error( $edited ) ) { |
|
330 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', $edited->get_error_message(), array( 'status' => 400 ) ); |
|
329 | + if (is_wp_error($edited)) { |
|
330 | + return new \WP_Error('woocommerce_rest_cannot_edit', $edited->get_error_message(), array('status' => 400)); |
|
331 | 331 | } |
332 | 332 | |
333 | - $attribute = $this->get_attribute( $id ); |
|
333 | + $attribute = $this->get_attribute($id); |
|
334 | 334 | |
335 | - if ( is_wp_error( $attribute ) ) { |
|
335 | + if (is_wp_error($attribute)) { |
|
336 | 336 | return $attribute; |
337 | 337 | } |
338 | 338 | |
339 | - $this->update_additional_fields_for_object( $attribute, $request ); |
|
339 | + $this->update_additional_fields_for_object($attribute, $request); |
|
340 | 340 | |
341 | 341 | /** |
342 | 342 | * Fires after a single product attribute is created or updated via the REST API. |
@@ -345,12 +345,12 @@ discard block |
||
345 | 345 | * @param \WP_REST_Request $request Request object. |
346 | 346 | * @param boolean $creating True when creating attribute, false when updating. |
347 | 347 | */ |
348 | - do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, false ); |
|
348 | + do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, false); |
|
349 | 349 | |
350 | - $request->set_param( 'context', 'edit' ); |
|
351 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
350 | + $request->set_param('context', 'edit'); |
|
351 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
352 | 352 | |
353 | - return rest_ensure_response( $response ); |
|
353 | + return rest_ensure_response($response); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -359,26 +359,26 @@ discard block |
||
359 | 359 | * @param \WP_REST_Request $request Full details about the request. |
360 | 360 | * @return \WP_REST_Response|\WP_Error |
361 | 361 | */ |
362 | - public function delete_item( $request ) { |
|
363 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
362 | + public function delete_item($request) { |
|
363 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
364 | 364 | |
365 | 365 | // We don't support trashing for this type, error out. |
366 | - if ( ! $force ) { |
|
367 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
366 | + if ( ! $force) { |
|
367 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Resource does not support trashing.', 'woocommerce'), array('status' => 501)); |
|
368 | 368 | } |
369 | 369 | |
370 | - $attribute = $this->get_attribute( (int) $request['id'] ); |
|
370 | + $attribute = $this->get_attribute((int) $request['id']); |
|
371 | 371 | |
372 | - if ( is_wp_error( $attribute ) ) { |
|
372 | + if (is_wp_error($attribute)) { |
|
373 | 373 | return $attribute; |
374 | 374 | } |
375 | 375 | |
376 | - $request->set_param( 'context', 'edit' ); |
|
377 | - $previous = $this->prepare_item_for_response( $attribute, $request ); |
|
378 | - $deleted = wc_delete_attribute( $attribute->attribute_id ); |
|
376 | + $request->set_param('context', 'edit'); |
|
377 | + $previous = $this->prepare_item_for_response($attribute, $request); |
|
378 | + $deleted = wc_delete_attribute($attribute->attribute_id); |
|
379 | 379 | |
380 | - if ( false === $deleted ) { |
|
381 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
380 | + if (false === $deleted) { |
|
381 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | $response = new \WP_REST_Response(); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * @param \WP_REST_Response $response The response data. |
397 | 397 | * @param \WP_REST_Request $request The request sent to the API. |
398 | 398 | */ |
399 | - do_action( 'woocommerce_rest_delete_product_attribute', $attribute, $response, $request ); |
|
399 | + do_action('woocommerce_rest_delete_product_attribute', $attribute, $response, $request); |
|
400 | 400 | |
401 | 401 | return $response; |
402 | 402 | } |
@@ -408,23 +408,23 @@ discard block |
||
408 | 408 | * @param \WP_REST_Request $request Request params. |
409 | 409 | * @return \WP_REST_Response $response |
410 | 410 | */ |
411 | - public function prepare_item_for_response( $item, $request ) { |
|
411 | + public function prepare_item_for_response($item, $request) { |
|
412 | 412 | $data = array( |
413 | 413 | 'id' => (int) $item->attribute_id, |
414 | 414 | 'name' => $item->attribute_label, |
415 | - 'slug' => wc_attribute_taxonomy_name( $item->attribute_name ), |
|
415 | + 'slug' => wc_attribute_taxonomy_name($item->attribute_name), |
|
416 | 416 | 'type' => $item->attribute_type, |
417 | 417 | 'order_by' => $item->attribute_orderby, |
418 | 418 | 'has_archives' => (bool) $item->attribute_public, |
419 | 419 | ); |
420 | 420 | |
421 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
422 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
423 | - $data = $this->filter_response_by_context( $data, $context ); |
|
421 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
422 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
423 | + $data = $this->filter_response_by_context($data, $context); |
|
424 | 424 | |
425 | - $response = rest_ensure_response( $data ); |
|
425 | + $response = rest_ensure_response($data); |
|
426 | 426 | |
427 | - $response->add_links( $this->prepare_links( $item ) ); |
|
427 | + $response->add_links($this->prepare_links($item)); |
|
428 | 428 | |
429 | 429 | /** |
430 | 430 | * Filter a attribute item returned from the API. |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | * @param object $item The original attribute object. |
436 | 436 | * @param \WP_REST_Request $request Request used to generate the response. |
437 | 437 | */ |
438 | - return apply_filters( 'woocommerce_rest_prepare_product_attribute', $response, $item, $request ); |
|
438 | + return apply_filters('woocommerce_rest_prepare_product_attribute', $response, $item, $request); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -444,14 +444,14 @@ discard block |
||
444 | 444 | * @param object $attribute Attribute object. |
445 | 445 | * @return array Links for the given attribute. |
446 | 446 | */ |
447 | - protected function prepare_links( $attribute ) { |
|
447 | + protected function prepare_links($attribute) { |
|
448 | 448 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
449 | 449 | $links = array( |
450 | 450 | 'self' => array( |
451 | - 'href' => rest_url( trailingslashit( $base ) . $attribute->attribute_id ), |
|
451 | + 'href' => rest_url(trailingslashit($base) . $attribute->attribute_id), |
|
452 | 452 | ), |
453 | 453 | 'collection' => array( |
454 | - 'href' => rest_url( $base ), |
|
454 | + 'href' => rest_url($base), |
|
455 | 455 | ), |
456 | 456 | ); |
457 | 457 | |
@@ -470,51 +470,51 @@ discard block |
||
470 | 470 | 'type' => 'object', |
471 | 471 | 'properties' => array( |
472 | 472 | 'id' => array( |
473 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
473 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
474 | 474 | 'type' => 'integer', |
475 | - 'context' => array( 'view', 'edit' ), |
|
475 | + 'context' => array('view', 'edit'), |
|
476 | 476 | 'readonly' => true, |
477 | 477 | ), |
478 | 478 | 'name' => array( |
479 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
479 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
480 | 480 | 'type' => 'string', |
481 | - 'context' => array( 'view', 'edit' ), |
|
481 | + 'context' => array('view', 'edit'), |
|
482 | 482 | 'arg_options' => array( |
483 | 483 | 'sanitize_callback' => 'sanitize_text_field', |
484 | 484 | ), |
485 | 485 | ), |
486 | 486 | 'slug' => array( |
487 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
487 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
488 | 488 | 'type' => 'string', |
489 | - 'context' => array( 'view', 'edit' ), |
|
489 | + 'context' => array('view', 'edit'), |
|
490 | 490 | 'arg_options' => array( |
491 | 491 | 'sanitize_callback' => 'sanitize_title', |
492 | 492 | ), |
493 | 493 | ), |
494 | 494 | 'type' => array( |
495 | - 'description' => __( 'Type of attribute.', 'woocommerce' ), |
|
495 | + 'description' => __('Type of attribute.', 'woocommerce'), |
|
496 | 496 | 'type' => 'string', |
497 | 497 | 'default' => 'select', |
498 | - 'enum' => array_keys( wc_get_attribute_types() ), |
|
499 | - 'context' => array( 'view', 'edit' ), |
|
498 | + 'enum' => array_keys(wc_get_attribute_types()), |
|
499 | + 'context' => array('view', 'edit'), |
|
500 | 500 | ), |
501 | 501 | 'order_by' => array( |
502 | - 'description' => __( 'Default sort order.', 'woocommerce' ), |
|
502 | + 'description' => __('Default sort order.', 'woocommerce'), |
|
503 | 503 | 'type' => 'string', |
504 | 504 | 'default' => 'menu_order', |
505 | - 'enum' => array( 'menu_order', 'name', 'name_num', 'id' ), |
|
506 | - 'context' => array( 'view', 'edit' ), |
|
505 | + 'enum' => array('menu_order', 'name', 'name_num', 'id'), |
|
506 | + 'context' => array('view', 'edit'), |
|
507 | 507 | ), |
508 | 508 | 'has_archives' => array( |
509 | - 'description' => __( 'Enable/Disable attribute archives.', 'woocommerce' ), |
|
509 | + 'description' => __('Enable/Disable attribute archives.', 'woocommerce'), |
|
510 | 510 | 'type' => 'boolean', |
511 | 511 | 'default' => false, |
512 | - 'context' => array( 'view', 'edit' ), |
|
512 | + 'context' => array('view', 'edit'), |
|
513 | 513 | ), |
514 | 514 | ), |
515 | 515 | ); |
516 | 516 | |
517 | - return $this->add_additional_fields_schema( $schema ); |
|
517 | + return $this->add_additional_fields_schema($schema); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | */ |
525 | 525 | public function get_collection_params() { |
526 | 526 | $params = array(); |
527 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
527 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
528 | 528 | |
529 | 529 | return $params; |
530 | 530 | } |
@@ -535,13 +535,13 @@ discard block |
||
535 | 535 | * @param \WP_REST_Request $request Full details about the request. |
536 | 536 | * @return string |
537 | 537 | */ |
538 | - protected function get_taxonomy( $request ) { |
|
539 | - if ( '' !== $this->attribute ) { |
|
538 | + protected function get_taxonomy($request) { |
|
539 | + if ('' !== $this->attribute) { |
|
540 | 540 | return $this->attribute; |
541 | 541 | } |
542 | 542 | |
543 | - if ( $request['id'] ) { |
|
544 | - $name = wc_attribute_taxonomy_name_by_id( (int) $request['id'] ); |
|
543 | + if ($request['id']) { |
|
544 | + $name = wc_attribute_taxonomy_name_by_id((int) $request['id']); |
|
545 | 545 | |
546 | 546 | $this->attribute = $name; |
547 | 547 | } |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | * @param int $id Attribute ID. |
556 | 556 | * @return stdClass|\WP_Error |
557 | 557 | */ |
558 | - protected function get_attribute( $id ) { |
|
558 | + protected function get_attribute($id) { |
|
559 | 559 | global $wpdb; |
560 | 560 | |
561 | 561 | $attribute = $wpdb->get_row( |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | ) |
570 | 570 | ); |
571 | 571 | |
572 | - if ( is_wp_error( $attribute ) || is_null( $attribute ) ) { |
|
573 | - return new \WP_Error( 'woocommerce_rest_attribute_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
572 | + if (is_wp_error($attribute) || is_null($attribute)) { |
|
573 | + return new \WP_Error('woocommerce_rest_attribute_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | return $attribute; |
@@ -584,16 +584,16 @@ discard block |
||
584 | 584 | * @param bool $new_data Is the data new or old. |
585 | 585 | * @return bool|\WP_Error |
586 | 586 | */ |
587 | - protected function validate_attribute_slug( $slug, $new_data = true ) { |
|
588 | - if ( strlen( $slug ) >= 28 ) { |
|
587 | + protected function validate_attribute_slug($slug, $new_data = true) { |
|
588 | + if (strlen($slug) >= 28) { |
|
589 | 589 | /* Translators: %s slug. */ |
590 | - return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf( __( 'Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
591 | - } elseif ( wc_check_if_attribute_name_is_reserved( $slug ) ) { |
|
590 | + return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf(__('Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
591 | + } elseif (wc_check_if_attribute_name_is_reserved($slug)) { |
|
592 | 592 | /* Translators: %s slug. */ |
593 | - return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
594 | - } elseif ( $new_data && taxonomy_exists( wc_attribute_taxonomy_name( $slug ) ) ) { |
|
593 | + return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf(__('Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
594 | + } elseif ($new_data && taxonomy_exists(wc_attribute_taxonomy_name($slug))) { |
|
595 | 595 | /* Translators: %s slug. */ |
596 | - return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
596 | + return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf(__('Slug "%s" is already in use. Change it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | return true; |
@@ -606,6 +606,6 @@ discard block |
||
606 | 606 | * @since 3.0.0 |
607 | 607 | */ |
608 | 608 | protected function flush_rewrite_rules() { |
609 | - wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' ); |
|
609 | + wp_schedule_single_event(time(), 'woocommerce_flush_rewrite_rules'); |
|
610 | 610 | } |
611 | 611 | } |