Test Failed
Push — master ( a5e4c3...7495fa )
by Mike
43:00
created
src/Controllers/Version4/AbstractPostsController.php 1 patch
Spacing   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\Controllers\Version4;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * POSTS Controller.
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	 * @param  \WP_REST_Request $request Full details about the request.
44 44
 	 * @return \WP_Error|boolean
45 45
 	 */
46
-	public function get_items_permissions_check( $request ) {
47
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) {
48
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
46
+	public function get_items_permissions_check($request) {
47
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) {
48
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
49 49
 		}
50 50
 
51 51
 		return true;
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 * @param  \WP_REST_Request $request Full details about the request.
58 58
 	 * @return \WP_Error|boolean
59 59
 	 */
60
-	public function create_item_permissions_check( $request ) {
61
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) {
62
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
60
+	public function create_item_permissions_check($request) {
61
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) {
62
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
63 63
 		}
64 64
 
65 65
 		return true;
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 	 * @param  \WP_REST_Request $request Full details about the request.
72 72
 	 * @return \WP_Error|boolean
73 73
 	 */
74
-	public function get_item_permissions_check( $request ) {
75
-		$post = get_post( (int) $request['id'] );
74
+	public function get_item_permissions_check($request) {
75
+		$post = get_post((int) $request['id']);
76 76
 
77
-		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) {
78
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
77
+		if ($post && ! wc_rest_check_post_permissions($this->post_type, 'read', $post->ID)) {
78
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
79 79
 		}
80 80
 
81 81
 		return true;
@@ -87,11 +87,11 @@  discard block
 block discarded – undo
87 87
 	 * @param  \WP_REST_Request $request Full details about the request.
88 88
 	 * @return \WP_Error|boolean
89 89
 	 */
90
-	public function update_item_permissions_check( $request ) {
91
-		$post = get_post( (int) $request['id'] );
90
+	public function update_item_permissions_check($request) {
91
+		$post = get_post((int) $request['id']);
92 92
 
93
-		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $post->ID ) ) {
94
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
93
+		if ($post && ! wc_rest_check_post_permissions($this->post_type, 'edit', $post->ID)) {
94
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
95 95
 		}
96 96
 
97 97
 		return true;
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
 	 * @param  \WP_REST_Request $request Full details about the request.
104 104
 	 * @return bool|\WP_Error
105 105
 	 */
106
-	public function delete_item_permissions_check( $request ) {
107
-		$post = get_post( (int) $request['id'] );
106
+	public function delete_item_permissions_check($request) {
107
+		$post = get_post((int) $request['id']);
108 108
 
109
-		if ( $post && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) {
110
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
109
+		if ($post && ! wc_rest_check_post_permissions($this->post_type, 'delete', $post->ID)) {
110
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
111 111
 		}
112 112
 
113 113
 		return true;
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 	 *
121 121
 	 * @return boolean|\WP_Error
122 122
 	 */
123
-	public function batch_items_permissions_check( $request ) {
124
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'batch' ) ) {
125
-			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() ) );
123
+	public function batch_items_permissions_check($request) {
124
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'batch')) {
125
+			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()));
126 126
 		}
127 127
 
128 128
 		return true;
@@ -134,21 +134,21 @@  discard block
 block discarded – undo
134 134
 	 * @param \WP_REST_Request $request Full details about the request.
135 135
 	 * @return \WP_Error\WP_REST_Response
136 136
 	 */
137
-	public function get_item( $request ) {
137
+	public function get_item($request) {
138 138
 		$id   = (int) $request['id'];
139
-		$post = get_post( $id );
139
+		$post = get_post($id);
140 140
 
141
-		if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) {
142
-			return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) );
143
-		} elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
144
-			return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
141
+		if ( ! empty($post->post_type) && 'product_variation' === $post->post_type && 'product' === $this->post_type) {
142
+			return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), array('status' => 404));
143
+		} elseif (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) {
144
+			return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
145 145
 		}
146 146
 
147
-		$data = $this->prepare_item_for_response( $post, $request );
148
-		$response = rest_ensure_response( $data );
147
+		$data = $this->prepare_item_for_response($post, $request);
148
+		$response = rest_ensure_response($data);
149 149
 
150
-		if ( $this->public ) {
151
-			$response->link_header( 'alternate', get_permalink( $id ), array( 'type' => 'text/html' ) );
150
+		if ($this->public) {
151
+			$response->link_header('alternate', get_permalink($id), array('type' => 'text/html'));
152 152
 		}
153 153
 
154 154
 		return $response;
@@ -160,39 +160,39 @@  discard block
 block discarded – undo
160 160
 	 * @param \WP_REST_Request $request Full details about the request.
161 161
 	 * @return \WP_Error\WP_REST_Response
162 162
 	 */
163
-	public function create_item( $request ) {
164
-		if ( ! empty( $request['id'] ) ) {
163
+	public function create_item($request) {
164
+		if ( ! empty($request['id'])) {
165 165
 			/* translators: %s: post type */
166
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
166
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
167 167
 		}
168 168
 
169
-		$post = $this->prepare_item_for_database( $request );
170
-		if ( is_wp_error( $post ) ) {
169
+		$post = $this->prepare_item_for_database($request);
170
+		if (is_wp_error($post)) {
171 171
 			return $post;
172 172
 		}
173 173
 
174 174
 		$post->post_type = $this->post_type;
175
-		$post_id         = wp_insert_post( $post, true );
175
+		$post_id         = wp_insert_post($post, true);
176 176
 
177
-		if ( is_wp_error( $post_id ) ) {
177
+		if (is_wp_error($post_id)) {
178 178
 
179
-			if ( in_array( $post_id->get_error_code(), array( 'db_insert_error' ) ) ) {
180
-				$post_id->add_data( array( 'status' => 500 ) );
179
+			if (in_array($post_id->get_error_code(), array('db_insert_error'))) {
180
+				$post_id->add_data(array('status' => 500));
181 181
 			} else {
182
-				$post_id->add_data( array( 'status' => 400 ) );
182
+				$post_id->add_data(array('status' => 400));
183 183
 			}
184 184
 			return $post_id;
185 185
 		}
186 186
 		$post->ID = $post_id;
187
-		$post     = get_post( $post_id );
187
+		$post     = get_post($post_id);
188 188
 
189
-		$this->update_additional_fields_for_object( $post, $request );
189
+		$this->update_additional_fields_for_object($post, $request);
190 190
 
191 191
 		// Add meta fields.
192
-		$meta_fields = $this->add_post_meta_fields( $post, $request );
193
-		if ( is_wp_error( $meta_fields ) ) {
192
+		$meta_fields = $this->add_post_meta_fields($post, $request);
193
+		if (is_wp_error($meta_fields)) {
194 194
 			// Remove post.
195
-			$this->delete_post( $post );
195
+			$this->delete_post($post);
196 196
 
197 197
 			return $meta_fields;
198 198
 		}
@@ -204,13 +204,13 @@  discard block
 block discarded – undo
204 204
 		 * @param \WP_REST_Request $request   Request object.
205 205
 		 * @param boolean         $creating  True when creating item, false when updating.
206 206
 		 */
207
-		do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true );
207
+		do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true);
208 208
 
209
-		$request->set_param( 'context', 'edit' );
210
-		$response = $this->prepare_item_for_response( $post, $request );
211
-		$response = rest_ensure_response( $response );
212
-		$response->set_status( 201 );
213
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post_id ) ) );
209
+		$request->set_param('context', 'edit');
210
+		$response = $this->prepare_item_for_response($post, $request);
211
+		$response = rest_ensure_response($response);
212
+		$response->set_status(201);
213
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post_id)));
214 214
 
215 215
 		return $response;
216 216
 	}
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 * @param \WP_REST_Request $request \WP_REST_Request Object.
223 223
 	 * @return bool|\WP_Error
224 224
 	 */
225
-	protected function add_post_meta_fields( $post, $request ) {
225
+	protected function add_post_meta_fields($post, $request) {
226 226
 		return true;
227 227
 	}
228 228
 
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
 	 *
232 232
 	 * @param WP_Post $post Post object.
233 233
 	 */
234
-	protected function delete_post( $post ) {
235
-		wp_delete_post( $post->ID, true );
234
+	protected function delete_post($post) {
235
+		wp_delete_post($post->ID, true);
236 236
 	}
237 237
 
238 238
 	/**
@@ -241,37 +241,37 @@  discard block
 block discarded – undo
241 241
 	 * @param \WP_REST_Request $request Full details about the request.
242 242
 	 * @return \WP_Error\WP_REST_Response
243 243
 	 */
244
-	public function update_item( $request ) {
244
+	public function update_item($request) {
245 245
 		$id   = (int) $request['id'];
246
-		$post = get_post( $id );
246
+		$post = get_post($id);
247 247
 
248
-		if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) {
249
-			return new \WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) );
250
-		} elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
251
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
248
+		if ( ! empty($post->post_type) && 'product_variation' === $post->post_type && 'product' === $this->post_type) {
249
+			return new \WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), array('status' => 404));
250
+		} elseif (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) {
251
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400));
252 252
 		}
253 253
 
254
-		$post = $this->prepare_item_for_database( $request );
255
-		if ( is_wp_error( $post ) ) {
254
+		$post = $this->prepare_item_for_database($request);
255
+		if (is_wp_error($post)) {
256 256
 			return $post;
257 257
 		}
258 258
 		// Convert the post object to an array, otherwise wp_update_post will expect non-escaped input.
259
-		$post_id = wp_update_post( (array) $post, true );
260
-		if ( is_wp_error( $post_id ) ) {
261
-			if ( in_array( $post_id->get_error_code(), array( 'db_update_error' ) ) ) {
262
-				$post_id->add_data( array( 'status' => 500 ) );
259
+		$post_id = wp_update_post((array) $post, true);
260
+		if (is_wp_error($post_id)) {
261
+			if (in_array($post_id->get_error_code(), array('db_update_error'))) {
262
+				$post_id->add_data(array('status' => 500));
263 263
 			} else {
264
-				$post_id->add_data( array( 'status' => 400 ) );
264
+				$post_id->add_data(array('status' => 400));
265 265
 			}
266 266
 			return $post_id;
267 267
 		}
268 268
 
269
-		$post = get_post( $post_id );
270
-		$this->update_additional_fields_for_object( $post, $request );
269
+		$post = get_post($post_id);
270
+		$this->update_additional_fields_for_object($post, $request);
271 271
 
272 272
 		// Update meta fields.
273
-		$meta_fields = $this->update_post_meta_fields( $post, $request );
274
-		if ( is_wp_error( $meta_fields ) ) {
273
+		$meta_fields = $this->update_post_meta_fields($post, $request);
274
+		if (is_wp_error($meta_fields)) {
275 275
 			return $meta_fields;
276 276
 		}
277 277
 
@@ -282,11 +282,11 @@  discard block
 block discarded – undo
282 282
 		 * @param \WP_REST_Request $request   Request object.
283 283
 		 * @param boolean         $creating  True when creating item, false when updating.
284 284
 		 */
285
-		do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, false );
285
+		do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, false);
286 286
 
287
-		$request->set_param( 'context', 'edit' );
288
-		$response = $this->prepare_item_for_response( $post, $request );
289
-		return rest_ensure_response( $response );
287
+		$request->set_param('context', 'edit');
288
+		$response = $this->prepare_item_for_response($post, $request);
289
+		return rest_ensure_response($response);
290 290
 	}
291 291
 
292 292
 	/**
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 	 * @param \WP_REST_Request $request Full details about the request.
296 296
 	 * @return \WP_Error\WP_REST_Response
297 297
 	 */
298
-	public function get_items( $request ) {
298
+	public function get_items($request) {
299 299
 		$args                         = array();
300 300
 		$args['offset']               = $request['offset'];
301 301
 		$args['order']                = $request['order'];
@@ -311,19 +311,19 @@  discard block
 block discarded – undo
311 311
 
312 312
 		$args['date_query'] = array();
313 313
 		// Set before into date query. Date query must be specified as an array of an array.
314
-		if ( isset( $request['before'] ) ) {
314
+		if (isset($request['before'])) {
315 315
 			$args['date_query'][0]['before'] = $request['before'];
316 316
 		}
317 317
 
318 318
 		// Set after into date query. Date query must be specified as an array of an array.
319
-		if ( isset( $request['after'] ) ) {
319
+		if (isset($request['after'])) {
320 320
 			$args['date_query'][0]['after'] = $request['after'];
321 321
 		}
322 322
 
323
-		if ( 'wc/v1' === $this->namespace ) {
324
-			if ( is_array( $request['filter'] ) ) {
325
-				$args = array_merge( $args, $request['filter'] );
326
-				unset( $args['filter'] );
323
+		if ('wc/v1' === $this->namespace) {
324
+			if (is_array($request['filter'])) {
325
+				$args = array_merge($args, $request['filter']);
326
+				unset($args['filter']);
327 327
 			}
328 328
 		}
329 329
 
@@ -339,59 +339,59 @@  discard block
 block discarded – undo
339 339
 		 * @param array           $args    Key value array of query var to query value.
340 340
 		 * @param \WP_REST_Request $request The request used.
341 341
 		 */
342
-		$args = apply_filters( "woocommerce_rest_{$this->post_type}_query", $args, $request );
343
-		$query_args = $this->prepare_items_query( $args, $request );
342
+		$args = apply_filters("woocommerce_rest_{$this->post_type}_query", $args, $request);
343
+		$query_args = $this->prepare_items_query($args, $request);
344 344
 
345 345
 		$posts_query = new \WP_Query();
346
-		$query_result = $posts_query->query( $query_args );
346
+		$query_result = $posts_query->query($query_args);
347 347
 
348 348
 		$posts = array();
349
-		foreach ( $query_result as $post ) {
350
-			if ( ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) {
349
+		foreach ($query_result as $post) {
350
+			if ( ! wc_rest_check_post_permissions($this->post_type, 'read', $post->ID)) {
351 351
 				continue;
352 352
 			}
353 353
 
354
-			$data = $this->prepare_item_for_response( $post, $request );
355
-			$posts[] = $this->prepare_response_for_collection( $data );
354
+			$data = $this->prepare_item_for_response($post, $request);
355
+			$posts[] = $this->prepare_response_for_collection($data);
356 356
 		}
357 357
 
358 358
 		$page = (int) $query_args['paged'];
359 359
 		$total_posts = $posts_query->found_posts;
360 360
 
361
-		if ( $total_posts < 1 ) {
361
+		if ($total_posts < 1) {
362 362
 			// Out-of-bounds, run the query again without LIMIT for total count.
363
-			unset( $query_args['paged'] );
363
+			unset($query_args['paged']);
364 364
 			$count_query = new \WP_Query();
365
-			$count_query->query( $query_args );
365
+			$count_query->query($query_args);
366 366
 			$total_posts = $count_query->found_posts;
367 367
 		}
368 368
 
369
-		$max_pages = ceil( $total_posts / (int) $query_args['posts_per_page'] );
369
+		$max_pages = ceil($total_posts / (int) $query_args['posts_per_page']);
370 370
 
371
-		$response = rest_ensure_response( $posts );
372
-		$response->header( 'X-WP-Total', (int) $total_posts );
373
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
371
+		$response = rest_ensure_response($posts);
372
+		$response->header('X-WP-Total', (int) $total_posts);
373
+		$response->header('X-WP-TotalPages', (int) $max_pages);
374 374
 
375 375
 		$request_params = $request->get_query_params();
376
-		if ( ! empty( $request_params['filter'] ) ) {
376
+		if ( ! empty($request_params['filter'])) {
377 377
 			// Normalize the pagination params.
378
-			unset( $request_params['filter']['posts_per_page'] );
379
-			unset( $request_params['filter']['paged'] );
378
+			unset($request_params['filter']['posts_per_page']);
379
+			unset($request_params['filter']['paged']);
380 380
 		}
381
-		$base = add_query_arg( $request_params, rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
381
+		$base = add_query_arg($request_params, rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
382 382
 
383
-		if ( $page > 1 ) {
383
+		if ($page > 1) {
384 384
 			$prev_page = $page - 1;
385
-			if ( $prev_page > $max_pages ) {
385
+			if ($prev_page > $max_pages) {
386 386
 				$prev_page = $max_pages;
387 387
 			}
388
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
389
-			$response->link_header( 'prev', $prev_link );
388
+			$prev_link = add_query_arg('page', $prev_page, $base);
389
+			$response->link_header('prev', $prev_link);
390 390
 		}
391
-		if ( $max_pages > $page ) {
391
+		if ($max_pages > $page) {
392 392
 			$next_page = $page + 1;
393
-			$next_link = add_query_arg( 'page', $next_page, $base );
394
-			$response->link_header( 'next', $next_link );
393
+			$next_link = add_query_arg('page', $next_page, $base);
394
+			$response->link_header('next', $next_link);
395 395
 		}
396 396
 
397 397
 		return $response;
@@ -403,13 +403,13 @@  discard block
 block discarded – undo
403 403
 	 * @param \WP_REST_Request $request Full details about the request.
404 404
 	 * @return \WP_REST_Response|\WP_Error
405 405
 	 */
406
-	public function delete_item( $request ) {
406
+	public function delete_item($request) {
407 407
 		$id    = (int) $request['id'];
408 408
 		$force = (bool) $request['force'];
409
-		$post  = get_post( $id );
409
+		$post  = get_post($id);
410 410
 
411
-		if ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) {
412
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 404 ) );
411
+		if (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) {
412
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 404));
413 413
 		}
414 414
 
415 415
 		$supports_trash = EMPTY_TRASH_DAYS > 0;
@@ -422,40 +422,40 @@  discard block
 block discarded – undo
422 422
 		 * @param boolean $supports_trash Whether the item type support trashing.
423 423
 		 * @param WP_Post $post           The Post object being considered for trashing support.
424 424
 		 */
425
-		$supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_trashable", $supports_trash, $post );
425
+		$supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_trashable", $supports_trash, $post);
426 426
 
427
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) {
427
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $post->ID)) {
428 428
 			/* translators: %s: post type */
429
-			return new \WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( 'status' => rest_authorization_required_code() ) );
429
+			return new \WP_Error("woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array('status' => rest_authorization_required_code()));
430 430
 		}
431 431
 
432
-		$request->set_param( 'context', 'edit' );
433
-		$response = $this->prepare_item_for_response( $post, $request );
432
+		$request->set_param('context', 'edit');
433
+		$response = $this->prepare_item_for_response($post, $request);
434 434
 
435 435
 		// If we're forcing, then delete permanently.
436
-		if ( $force ) {
437
-			$result = wp_delete_post( $id, true );
436
+		if ($force) {
437
+			$result = wp_delete_post($id, true);
438 438
 		} else {
439 439
 			// If we don't support trashing for this type, error out.
440
-			if ( ! $supports_trash ) {
440
+			if ( ! $supports_trash) {
441 441
 				/* translators: %s: post type */
442
-				return new \WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) );
442
+				return new \WP_Error('woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array('status' => 501));
443 443
 			}
444 444
 
445 445
 			// Otherwise, only trash if we haven't already.
446
-			if ( 'trash' === $post->post_status ) {
446
+			if ('trash' === $post->post_status) {
447 447
 				/* translators: %s: post type */
448
-				return new \WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) );
448
+				return new \WP_Error('woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array('status' => 410));
449 449
 			}
450 450
 
451 451
 			// (Note that internally this falls through to `wp_delete_post` if
452 452
 			// the trash is disabled.)
453
-			$result = wp_trash_post( $id );
453
+			$result = wp_trash_post($id);
454 454
 		}
455 455
 
456
-		if ( ! $result ) {
456
+		if ( ! $result) {
457 457
 			/* translators: %s: post type */
458
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
458
+			return new \WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500));
459 459
 		}
460 460
 
461 461
 		/**
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 		 * @param \WP_REST_Response $response The response data.
466 466
 		 * @param \WP_REST_Request  $request  The request sent to the API.
467 467
 		 */
468
-		do_action( "woocommerce_rest_delete_{$this->post_type}", $post, $response, $request );
468
+		do_action("woocommerce_rest_delete_{$this->post_type}", $post, $response, $request);
469 469
 
470 470
 		return $response;
471 471
 	}
@@ -477,13 +477,13 @@  discard block
 block discarded – undo
477 477
 	 * @param \WP_REST_Request $request Request object.
478 478
 	 * @return array Links for the given post.
479 479
 	 */
480
-	protected function prepare_links( $post, $request ) {
480
+	protected function prepare_links($post, $request) {
481 481
 		$links = array(
482 482
 			'self' => array(
483
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ),
483
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID)),
484 484
 			),
485 485
 			'collection' => array(
486
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
486
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
487 487
 			),
488 488
 		);
489 489
 
@@ -498,12 +498,12 @@  discard block
 block discarded – undo
498 498
 	 * @param \WP_REST_Request $request Request object.
499 499
 	 * @return array          $query_args
500 500
 	 */
501
-	protected function prepare_items_query( $prepared_args = array(), $request = null ) {
501
+	protected function prepare_items_query($prepared_args = array(), $request = null) {
502 502
 
503
-		$valid_vars = array_flip( $this->get_allowed_query_vars() );
503
+		$valid_vars = array_flip($this->get_allowed_query_vars());
504 504
 		$query_args = array();
505
-		foreach ( $valid_vars as $var => $index ) {
506
-			if ( isset( $prepared_args[ $var ] ) ) {
505
+		foreach ($valid_vars as $var => $index) {
506
+			if (isset($prepared_args[$var])) {
507 507
 				/**
508 508
 				 * Filter the query_vars used in `get_items` for the constructed query.
509 509
 				 *
@@ -511,17 +511,17 @@  discard block
 block discarded – undo
511 511
 				 *
512 512
 				 * @param mixed $prepared_args[ $var ] The query_var value.
513 513
 				 */
514
-				$query_args[ $var ] = apply_filters( "woocommerce_rest_query_var-{$var}", $prepared_args[ $var ] );
514
+				$query_args[$var] = apply_filters("woocommerce_rest_query_var-{$var}", $prepared_args[$var]);
515 515
 			}
516 516
 		}
517 517
 
518 518
 		$query_args['ignore_sticky_posts'] = true;
519 519
 
520
-		if ( 'include' === $query_args['orderby'] ) {
520
+		if ('include' === $query_args['orderby']) {
521 521
 			$query_args['orderby'] = 'post__in';
522
-		} elseif ( 'id' === $query_args['orderby'] ) {
522
+		} elseif ('id' === $query_args['orderby']) {
523 523
 			$query_args['orderby'] = 'ID'; // ID must be capitalized.
524
-		} elseif ( 'slug' === $query_args['orderby'] ) {
524
+		} elseif ('slug' === $query_args['orderby']) {
525 525
 			$query_args['orderby'] = 'name';
526 526
 		}
527 527
 
@@ -543,10 +543,10 @@  discard block
 block discarded – undo
543 543
 		 *
544 544
 		 * @param array  Array of allowed \WP_Query query vars.
545 545
 		 */
546
-		$valid_vars = apply_filters( 'query_vars', $wp->public_query_vars );
546
+		$valid_vars = apply_filters('query_vars', $wp->public_query_vars);
547 547
 
548
-		$post_type_obj = get_post_type_object( $this->post_type );
549
-		if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
548
+		$post_type_obj = get_post_type_object($this->post_type);
549
+		if (current_user_can($post_type_obj->cap->edit_posts)) {
550 550
 			/**
551 551
 			 * Filter the allowed 'private' query vars for authorized users.
552 552
 			 *
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 			 * @param array $private_query_vars Array of allowed query vars for authorized users.
561 561
 			 * }
562 562
 			 */
563
-			$private = apply_filters( 'woocommerce_rest_private_query_vars', $wp->private_query_vars );
564
-			$valid_vars = array_merge( $valid_vars, $private );
563
+			$private = apply_filters('woocommerce_rest_private_query_vars', $wp->private_query_vars);
564
+			$valid_vars = array_merge($valid_vars, $private);
565 565
 		}
566 566
 		// Define our own in addition to WP's normal vars.
567 567
 		$rest_valid = array(
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 			'meta_compare',
582 582
 			'meta_value_num',
583 583
 		);
584
-		$valid_vars = array_merge( $valid_vars, $rest_valid );
584
+		$valid_vars = array_merge($valid_vars, $rest_valid);
585 585
 
586 586
 		/**
587 587
 		 * Filter allowed query vars for the REST API.
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 		 *    @param string $allowed_query_var The query var to allow.
597 597
 		 * }
598 598
 		 */
599
-		$valid_vars = apply_filters( 'woocommerce_rest_query_vars', $valid_vars );
599
+		$valid_vars = apply_filters('woocommerce_rest_query_vars', $valid_vars);
600 600
 
601 601
 		return $valid_vars;
602 602
 	}
@@ -612,19 +612,19 @@  discard block
 block discarded – undo
612 612
 		$params['context']['default'] = 'view';
613 613
 
614 614
 		$params['after'] = array(
615
-			'description'        => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
615
+			'description'        => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
616 616
 			'type'               => 'string',
617 617
 			'format'             => 'date-time',
618 618
 			'validate_callback'  => 'rest_validate_request_arg',
619 619
 		);
620 620
 		$params['before'] = array(
621
-			'description'        => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
621
+			'description'        => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
622 622
 			'type'               => 'string',
623 623
 			'format'             => 'date-time',
624 624
 			'validate_callback'  => 'rest_validate_request_arg',
625 625
 		);
626 626
 		$params['exclude'] = array(
627
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
627
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
628 628
 			'type'              => 'array',
629 629
 			'items'             => array(
630 630
 				'type'          => 'integer',
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
 			'sanitize_callback' => 'wp_parse_id_list',
634 634
 		);
635 635
 		$params['include'] = array(
636
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
636
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
637 637
 			'type'              => 'array',
638 638
 			'items'             => array(
639 639
 				'type'          => 'integer',
@@ -642,20 +642,20 @@  discard block
 block discarded – undo
642 642
 			'sanitize_callback' => 'wp_parse_id_list',
643 643
 		);
644 644
 		$params['offset'] = array(
645
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
645
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
646 646
 			'type'               => 'integer',
647 647
 			'sanitize_callback'  => 'absint',
648 648
 			'validate_callback'  => 'rest_validate_request_arg',
649 649
 		);
650 650
 		$params['order'] = array(
651
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
651
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
652 652
 			'type'               => 'string',
653 653
 			'default'            => 'desc',
654
-			'enum'               => array( 'asc', 'desc' ),
654
+			'enum'               => array('asc', 'desc'),
655 655
 			'validate_callback'  => 'rest_validate_request_arg',
656 656
 		);
657 657
 		$params['orderby'] = array(
658
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
658
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
659 659
 			'type'               => 'string',
660 660
 			'default'            => 'date',
661 661
 			'enum'               => array(
@@ -668,11 +668,11 @@  discard block
 block discarded – undo
668 668
 			'validate_callback'  => 'rest_validate_request_arg',
669 669
 		);
670 670
 
671
-		$post_type_obj = get_post_type_object( $this->post_type );
671
+		$post_type_obj = get_post_type_object($this->post_type);
672 672
 
673
-		if ( isset( $post_type_obj->hierarchical ) && $post_type_obj->hierarchical ) {
673
+		if (isset($post_type_obj->hierarchical) && $post_type_obj->hierarchical) {
674 674
 			$params['parent'] = array(
675
-				'description'       => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
675
+				'description'       => __('Limit result set to those of particular parent IDs.', 'woocommerce'),
676 676
 				'type'              => 'array',
677 677
 				'items'             => array(
678 678
 					'type'          => 'integer',
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 				'default'           => array(),
682 682
 			);
683 683
 			$params['parent_exclude'] = array(
684
-				'description'       => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ),
684
+				'description'       => __('Limit result set to all items except those of a particular parent ID.', 'woocommerce'),
685 685
 				'type'              => 'array',
686 686
 				'items'             => array(
687 687
 					'type'          => 'integer',
@@ -691,10 +691,10 @@  discard block
 block discarded – undo
691 691
 			);
692 692
 		}
693 693
 
694
-		if ( 'wc/v1' === $this->namespace ) {
694
+		if ('wc/v1' === $this->namespace) {
695 695
 			$params['filter'] = array(
696 696
 				'type'        => 'object',
697
-				'description' => __( 'Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce' ),
697
+				'description' => __('Use WP Query arguments to modify the response; private query vars require appropriate authorization.', 'woocommerce'),
698 698
 			);
699 699
 		}
700 700
 
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 	 * @param \WP_REST_Request $request Request object.
709 709
 	 * @return bool|\WP_Error
710 710
 	 */
711
-	protected function update_post_meta_fields( $post, $request ) {
711
+	protected function update_post_meta_fields($post, $request) {
712 712
 		return true;
713 713
 	}
714 714
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/ShippingZoneMethods.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
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 Shipping Zone Methods class.
@@ -26,31 +26,31 @@  discard block
 block discarded – undo
26 26
 			array(
27 27
 				'args'   => array(
28 28
 					'zone_id' => array(
29
-						'description' => __( 'Unique ID for the zone.', 'woocommerce' ),
29
+						'description' => __('Unique ID for the zone.', 'woocommerce'),
30 30
 						'type'        => 'integer',
31 31
 					),
32 32
 				),
33 33
 				array(
34 34
 					'methods'             => \WP_REST_Server::READABLE,
35
-					'callback'            => array( $this, 'get_items' ),
36
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
35
+					'callback'            => array($this, 'get_items'),
36
+					'permission_callback' => array($this, 'get_items_permissions_check'),
37 37
 				),
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::CREATABLE,
40
-					'callback'            => array( $this, 'create_item' ),
41
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
40
+					'callback'            => array($this, 'create_item'),
41
+					'permission_callback' => array($this, 'create_item_permissions_check'),
42 42
 					'args'                => array_merge(
43
-						$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
43
+						$this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
44 44
 						array(
45 45
 							'method_id' => array(
46 46
 								'required'    => true,
47 47
 								'readonly'    => false,
48
-								'description' => __( 'Shipping method ID.', 'woocommerce' ),
48
+								'description' => __('Shipping method ID.', 'woocommerce'),
49 49
 							),
50 50
 						)
51 51
 					),
52 52
 				),
53
-				'schema' => array( $this, 'get_public_item_schema' ),
53
+				'schema' => array($this, 'get_public_item_schema'),
54 54
 			),
55 55
 			true
56 56
 		);
@@ -61,38 +61,38 @@  discard block
 block discarded – undo
61 61
 			array(
62 62
 				'args'   => array(
63 63
 					'zone_id'     => array(
64
-						'description' => __( 'Unique ID for the zone.', 'woocommerce' ),
64
+						'description' => __('Unique ID for the zone.', 'woocommerce'),
65 65
 						'type'        => 'integer',
66 66
 					),
67 67
 					'instance_id' => array(
68
-						'description' => __( 'Unique ID for the instance.', 'woocommerce' ),
68
+						'description' => __('Unique ID for the instance.', 'woocommerce'),
69 69
 						'type'        => 'integer',
70 70
 					),
71 71
 				),
72 72
 				array(
73 73
 					'methods'             => \WP_REST_Server::READABLE,
74
-					'callback'            => array( $this, 'get_item' ),
75
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
74
+					'callback'            => array($this, 'get_item'),
75
+					'permission_callback' => array($this, 'get_items_permissions_check'),
76 76
 				),
77 77
 				array(
78 78
 					'methods'             => \WP_REST_Server::EDITABLE,
79
-					'callback'            => array( $this, 'update_item' ),
80
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
81
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
79
+					'callback'            => array($this, 'update_item'),
80
+					'permission_callback' => array($this, 'update_items_permissions_check'),
81
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
82 82
 				),
83 83
 				array(
84 84
 					'methods'             => \WP_REST_Server::DELETABLE,
85
-					'callback'            => array( $this, 'delete_item' ),
86
-					'permission_callback' => array( $this, 'delete_items_permissions_check' ),
85
+					'callback'            => array($this, 'delete_item'),
86
+					'permission_callback' => array($this, 'delete_items_permissions_check'),
87 87
 					'args'                => array(
88 88
 						'force' => array(
89 89
 							'default'     => false,
90 90
 							'type'        => 'boolean',
91
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
91
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
92 92
 						),
93 93
 					),
94 94
 				),
95
-				'schema' => array( $this, 'get_public_item_schema' ),
95
+				'schema' => array($this, 'get_public_item_schema'),
96 96
 			),
97 97
 			true
98 98
 		);
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
 	 * @param \WP_REST_Request $request Request data.
105 105
 	 * @return \WP_REST_Response|\WP_Error
106 106
 	 */
107
-	public function get_item( $request ) {
108
-		$zone = $this->get_zone( $request['zone_id'] );
107
+	public function get_item($request) {
108
+		$zone = $this->get_zone($request['zone_id']);
109 109
 
110
-		if ( is_wp_error( $zone ) ) {
110
+		if (is_wp_error($zone)) {
111 111
 			return $zone;
112 112
 		}
113 113
 
@@ -115,20 +115,20 @@  discard block
 block discarded – undo
115 115
 		$methods     = $zone->get_shipping_methods();
116 116
 		$method      = false;
117 117
 
118
-		foreach ( $methods as $method_obj ) {
119
-			if ( $instance_id === $method_obj->instance_id ) {
118
+		foreach ($methods as $method_obj) {
119
+			if ($instance_id === $method_obj->instance_id) {
120 120
 				$method = $method_obj;
121 121
 				break;
122 122
 			}
123 123
 		}
124 124
 
125
-		if ( false === $method ) {
126
-			return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
125
+		if (false === $method) {
126
+			return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
127 127
 		}
128 128
 
129
-		$data = $this->prepare_item_for_response( $method, $request );
129
+		$data = $this->prepare_item_for_response($method, $request);
130 130
 
131
-		return rest_ensure_response( $data );
131
+		return rest_ensure_response($data);
132 132
 	}
133 133
 
134 134
 	/**
@@ -137,22 +137,22 @@  discard block
 block discarded – undo
137 137
 	 * @param \WP_REST_Request $request Request data.
138 138
 	 * @return \WP_REST_Response|\WP_Error
139 139
 	 */
140
-	public function get_items( $request ) {
141
-		$zone = $this->get_zone( $request['zone_id'] );
140
+	public function get_items($request) {
141
+		$zone = $this->get_zone($request['zone_id']);
142 142
 
143
-		if ( is_wp_error( $zone ) ) {
143
+		if (is_wp_error($zone)) {
144 144
 			return $zone;
145 145
 		}
146 146
 
147 147
 		$methods = $zone->get_shipping_methods();
148 148
 		$data    = array();
149 149
 
150
-		foreach ( $methods as $method_obj ) {
151
-			$method = $this->prepare_item_for_response( $method_obj, $request );
150
+		foreach ($methods as $method_obj) {
151
+			$method = $this->prepare_item_for_response($method_obj, $request);
152 152
 			$data[] = $method;
153 153
 		}
154 154
 
155
-		return rest_ensure_response( $data );
155
+		return rest_ensure_response($data);
156 156
 	}
157 157
 
158 158
 	/**
@@ -161,34 +161,34 @@  discard block
 block discarded – undo
161 161
 	 * @param \WP_REST_Request $request Full details about the request.
162 162
 	 * @return \WP_REST_Request|\WP_Error
163 163
 	 */
164
-	public function create_item( $request ) {
164
+	public function create_item($request) {
165 165
 		$method_id = $request['method_id'];
166
-		$zone      = $this->get_zone( $request['zone_id'] );
167
-		if ( is_wp_error( $zone ) ) {
166
+		$zone      = $this->get_zone($request['zone_id']);
167
+		if (is_wp_error($zone)) {
168 168
 			return $zone;
169 169
 		}
170 170
 
171
-		$instance_id = $zone->add_shipping_method( $method_id );
171
+		$instance_id = $zone->add_shipping_method($method_id);
172 172
 		$methods     = $zone->get_shipping_methods();
173 173
 		$method      = false;
174
-		foreach ( $methods as $method_obj ) {
175
-			if ( $instance_id === $method_obj->instance_id ) {
174
+		foreach ($methods as $method_obj) {
175
+			if ($instance_id === $method_obj->instance_id) {
176 176
 				$method = $method_obj;
177 177
 				break;
178 178
 			}
179 179
 		}
180 180
 
181
-		if ( false === $method ) {
182
-			return new \WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( 'Resource cannot be created.', 'woocommerce' ), array( 'status' => 500 ) );
181
+		if (false === $method) {
182
+			return new \WP_Error('woocommerce_rest_shipping_zone_not_created', __('Resource cannot be created.', 'woocommerce'), array('status' => 500));
183 183
 		}
184 184
 
185
-		$method = $this->update_fields( $instance_id, $method, $request );
186
-		if ( is_wp_error( $method ) ) {
185
+		$method = $this->update_fields($instance_id, $method, $request);
186
+		if (is_wp_error($method)) {
187 187
 			return $method;
188 188
 		}
189 189
 
190
-		$data = $this->prepare_item_for_response( $method, $request );
191
-		return rest_ensure_response( $data );
190
+		$data = $this->prepare_item_for_response($method, $request);
191
+		return rest_ensure_response($data);
192 192
 	}
193 193
 
194 194
 	/**
@@ -197,9 +197,9 @@  discard block
 block discarded – undo
197 197
 	 * @param \WP_REST_Request $request Full details about the request.
198 198
 	 * @return \WP_Error|boolean
199 199
 	 */
200
-	public function delete_item( $request ) {
201
-		$zone = $this->get_zone( $request['zone_id'] );
202
-		if ( is_wp_error( $zone ) ) {
200
+	public function delete_item($request) {
201
+		$zone = $this->get_zone($request['zone_id']);
202
+		if (is_wp_error($zone)) {
203 203
 			return $zone;
204 204
 		}
205 205
 
@@ -207,34 +207,34 @@  discard block
 block discarded – undo
207 207
 		$force       = $request['force'];
208 208
 
209 209
 		// We don't support trashing for this type, error out.
210
-		if ( ! $force ) {
211
-			return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Shipping methods do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
210
+		if ( ! $force) {
211
+			return new WP_Error('woocommerce_rest_trash_not_supported', __('Shipping methods do not support trashing.', 'woocommerce'), array('status' => 501));
212 212
 		}
213 213
 
214 214
 		$methods = $zone->get_shipping_methods();
215 215
 		$method  = false;
216 216
 
217
-		foreach ( $methods as $method_obj ) {
218
-			if ( $instance_id === $method_obj->instance_id ) {
217
+		foreach ($methods as $method_obj) {
218
+			if ($instance_id === $method_obj->instance_id) {
219 219
 				$method = $method_obj;
220 220
 				break;
221 221
 			}
222 222
 		}
223 223
 
224
-		if ( false === $method ) {
225
-			return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
224
+		if (false === $method) {
225
+			return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
226 226
 		}
227 227
 
228
-		$method = $this->update_fields( $instance_id, $method, $request );
229
-		if ( is_wp_error( $method ) ) {
228
+		$method = $this->update_fields($instance_id, $method, $request);
229
+		if (is_wp_error($method)) {
230 230
 			return $method;
231 231
 		}
232 232
 
233
-		$request->set_param( 'context', 'view' );
234
-		$previous = $this->prepare_item_for_response( $method, $request );
233
+		$request->set_param('context', 'view');
234
+		$previous = $this->prepare_item_for_response($method, $request);
235 235
 
236 236
 		// Actually delete.
237
-		$zone->delete_shipping_method( $instance_id );
237
+		$zone->delete_shipping_method($instance_id);
238 238
 		$response = new \WP_REST_Response();
239 239
 		$response->set_data(
240 240
 			array(
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 		 * @param \WP_REST_Response $response        The response data.
251 251
 		 * @param \WP_REST_Request  $request         The request sent to the API.
252 252
 		 */
253
-		do_action( 'woocommerce_rest_delete_shipping_zone_method', $method, $response, $request );
253
+		do_action('woocommerce_rest_delete_shipping_zone_method', $method, $response, $request);
254 254
 
255 255
 		return $response;
256 256
 	}
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
 	 * @param \WP_REST_Request $request Request data.
262 262
 	 * @return \WP_REST_Response|\WP_Error
263 263
 	 */
264
-	public function update_item( $request ) {
265
-		$zone = $this->get_zone( $request['zone_id'] );
266
-		if ( is_wp_error( $zone ) ) {
264
+	public function update_item($request) {
265
+		$zone = $this->get_zone($request['zone_id']);
266
+		if (is_wp_error($zone)) {
267 267
 			return $zone;
268 268
 		}
269 269
 
@@ -271,24 +271,24 @@  discard block
 block discarded – undo
271 271
 		$methods     = $zone->get_shipping_methods();
272 272
 		$method      = false;
273 273
 
274
-		foreach ( $methods as $method_obj ) {
275
-			if ( $instance_id === $method_obj->instance_id ) {
274
+		foreach ($methods as $method_obj) {
275
+			if ($instance_id === $method_obj->instance_id) {
276 276
 				$method = $method_obj;
277 277
 				break;
278 278
 			}
279 279
 		}
280 280
 
281
-		if ( false === $method ) {
282
-			return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
281
+		if (false === $method) {
282
+			return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
283 283
 		}
284 284
 
285
-		$method = $this->update_fields( $instance_id, $method, $request );
286
-		if ( is_wp_error( $method ) ) {
285
+		$method = $this->update_fields($instance_id, $method, $request);
286
+		if (is_wp_error($method)) {
287 287
 			return $method;
288 288
 		}
289 289
 
290
-		$data = $this->prepare_item_for_response( $method, $request );
291
-		return rest_ensure_response( $data );
290
+		$data = $this->prepare_item_for_response($method, $request);
291
+		return rest_ensure_response($data);
292 292
 	}
293 293
 
294 294
 	/**
@@ -300,47 +300,47 @@  discard block
 block discarded – undo
300 300
 	 *
301 301
 	 * @return WC_Shipping_Method
302 302
 	 */
303
-	public function update_fields( $instance_id, $method, $request ) {
303
+	public function update_fields($instance_id, $method, $request) {
304 304
 		global $wpdb;
305 305
 
306 306
 		// Update settings if present.
307
-		if ( isset( $request['settings'] ) ) {
307
+		if (isset($request['settings'])) {
308 308
 			$method->init_instance_settings();
309 309
 			$instance_settings = $method->instance_settings;
310 310
 			$errors_found      = false;
311
-			foreach ( $method->get_instance_form_fields() as $key => $field ) {
312
-				if ( isset( $request['settings'][ $key ] ) ) {
313
-					if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) {
314
-						$value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field );
311
+			foreach ($method->get_instance_form_fields() as $key => $field) {
312
+				if (isset($request['settings'][$key])) {
313
+					if (is_callable(array($this, 'validate_setting_' . $field['type'] . '_field'))) {
314
+						$value = $this->{'validate_setting_' . $field['type'] . '_field'}($request['settings'][$key], $field);
315 315
 					} else {
316
-						$value = $this->validate_setting_text_field( $request['settings'][ $key ], $field );
316
+						$value = $this->validate_setting_text_field($request['settings'][$key], $field);
317 317
 					}
318
-					if ( is_wp_error( $value ) ) {
318
+					if (is_wp_error($value)) {
319 319
 						$errors_found = true;
320 320
 						break;
321 321
 					}
322
-					$instance_settings[ $key ] = $value;
322
+					$instance_settings[$key] = $value;
323 323
 				}
324 324
 			}
325 325
 
326
-			if ( $errors_found ) {
327
-				return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
326
+			if ($errors_found) {
327
+				return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
328 328
 			}
329 329
 
330
-			update_option( $method->get_instance_option_key(), apply_filters( 'woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method ) );
330
+			update_option($method->get_instance_option_key(), apply_filters('woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method));
331 331
 		}
332 332
 
333 333
 		// Update order.
334
-		if ( isset( $request['order'] ) ) {
335
-			$wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request['order'] ) ), array( 'instance_id' => absint( $instance_id ) ) );
336
-			$method->method_order = absint( $request['order'] );
334
+		if (isset($request['order'])) {
335
+			$wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('method_order' => absint($request['order'])), array('instance_id' => absint($instance_id)));
336
+			$method->method_order = absint($request['order']);
337 337
 		}
338 338
 
339 339
 		// Update if this method is enabled or not.
340
-		if ( isset( $request['enabled'] ) ) {
341
-			if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request['enabled'] ), array( 'instance_id' => absint( $instance_id ) ) ) ) {
342
-				do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled'] );
343
-				$method->enabled = ( true === $request['enabled'] ? 'yes' : 'no' );
340
+		if (isset($request['enabled'])) {
341
+			if ($wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('is_enabled' => $request['enabled']), array('instance_id' => absint($instance_id)))) {
342
+				do_action('woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled']);
343
+				$method->enabled = (true === $request['enabled'] ? 'yes' : 'no');
344 344
 			}
345 345
 		}
346 346
 
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
 	 * @param \WP_REST_Request $request Request object.
355 355
 	 * @return \WP_REST_Response $response
356 356
 	 */
357
-	public function prepare_item_for_response( $item, $request ) {
357
+	public function prepare_item_for_response($item, $request) {
358 358
 		$method = array(
359 359
 			'id'                 => $item->instance_id,
360 360
 			'instance_id'        => $item->instance_id,
361 361
 			'title'              => $item->instance_settings['title'],
362 362
 			'order'              => $item->method_order,
363
-			'enabled'            => ( 'yes' === $item->enabled ),
363
+			'enabled'            => ('yes' === $item->enabled),
364 364
 			'method_id'          => $item->id,
365 365
 			'method_title'       => $item->method_title,
366 366
 			'method_description' => $item->method_description,
367
-			'settings'           => $this->get_settings( $item ),
367
+			'settings'           => $this->get_settings($item),
368 368
 		);
369 369
 
370
-		$context = empty( $request['context'] ) ? 'view' : $request['context'];
371
-		$data    = $this->add_additional_fields_to_object( $method, $request );
372
-		$data    = $this->filter_response_by_context( $data, $context );
370
+		$context = empty($request['context']) ? 'view' : $request['context'];
371
+		$data    = $this->add_additional_fields_to_object($method, $request);
372
+		$data    = $this->filter_response_by_context($data, $context);
373 373
 
374 374
 		// Wrap the data in a response object.
375
-		$response = rest_ensure_response( $data );
375
+		$response = rest_ensure_response($data);
376 376
 
377
-		$response->add_links( $this->prepare_links( $request['zone_id'], $item->instance_id ) );
377
+		$response->add_links($this->prepare_links($request['zone_id'], $item->instance_id));
378 378
 
379
-		$response = $this->prepare_response_for_collection( $response );
379
+		$response = $this->prepare_response_for_collection($response);
380 380
 
381 381
 		return $response;
382 382
 	}
@@ -388,24 +388,24 @@  discard block
 block discarded – undo
388 388
 	 *
389 389
 	 * @return array
390 390
 	 */
391
-	public function get_settings( $item ) {
391
+	public function get_settings($item) {
392 392
 		$item->init_instance_settings();
393 393
 		$settings = array();
394
-		foreach ( $item->get_instance_form_fields() as $id => $field ) {
394
+		foreach ($item->get_instance_form_fields() as $id => $field) {
395 395
 			$data = array(
396 396
 				'id'          => $id,
397 397
 				'label'       => $field['title'],
398
-				'description' => empty( $field['description'] ) ? '' : $field['description'],
398
+				'description' => empty($field['description']) ? '' : $field['description'],
399 399
 				'type'        => $field['type'],
400
-				'value'       => $item->instance_settings[ $id ],
401
-				'default'     => empty( $field['default'] ) ? '' : $field['default'],
402
-				'tip'         => empty( $field['description'] ) ? '' : $field['description'],
403
-				'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'],
400
+				'value'       => $item->instance_settings[$id],
401
+				'default'     => empty($field['default']) ? '' : $field['default'],
402
+				'tip'         => empty($field['description']) ? '' : $field['description'],
403
+				'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'],
404 404
 			);
405
-			if ( ! empty( $field['options'] ) ) {
405
+			if ( ! empty($field['options'])) {
406 406
 				$data['options'] = $field['options'];
407 407
 			}
408
-			$settings[ $id ] = $data;
408
+			$settings[$id] = $data;
409 409
 		}
410 410
 		return $settings;
411 411
 	}
@@ -417,17 +417,17 @@  discard block
 block discarded – undo
417 417
 	 * @param int $instance_id Given Shipping Zone Method Instance ID.
418 418
 	 * @return array Links for the given Shipping Zone Method.
419 419
 	 */
420
-	protected function prepare_links( $zone_id, $instance_id ) {
420
+	protected function prepare_links($zone_id, $instance_id) {
421 421
 		$base  = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id;
422 422
 		$links = array(
423 423
 			'self'       => array(
424
-				'href' => rest_url( $base . '/methods/' . $instance_id ),
424
+				'href' => rest_url($base . '/methods/' . $instance_id),
425 425
 			),
426 426
 			'collection' => array(
427
-				'href' => rest_url( $base . '/methods' ),
427
+				'href' => rest_url($base . '/methods'),
428 428
 			),
429 429
 			'describes'  => array(
430
-				'href' => rest_url( $base ),
430
+				'href' => rest_url($base),
431 431
 			),
432 432
 		);
433 433
 
@@ -446,102 +446,102 @@  discard block
 block discarded – undo
446 446
 			'type'       => 'object',
447 447
 			'properties' => array(
448 448
 				'id'                 => array(
449
-					'description' => __( 'Shipping method instance ID.', 'woocommerce' ),
449
+					'description' => __('Shipping method instance ID.', 'woocommerce'),
450 450
 					'type'        => 'integer',
451
-					'context'     => array( 'view', 'edit' ),
451
+					'context'     => array('view', 'edit'),
452 452
 					'readonly'    => true,
453 453
 				),
454 454
 				'instance_id'        => array(
455
-					'description' => __( 'Shipping method instance ID.', 'woocommerce' ),
455
+					'description' => __('Shipping method instance ID.', 'woocommerce'),
456 456
 					'type'        => 'integer',
457
-					'context'     => array( 'view', 'edit' ),
457
+					'context'     => array('view', 'edit'),
458 458
 					'readonly'    => true,
459 459
 				),
460 460
 				'title'              => array(
461
-					'description' => __( 'Shipping method customer facing title.', 'woocommerce' ),
461
+					'description' => __('Shipping method customer facing title.', 'woocommerce'),
462 462
 					'type'        => 'string',
463
-					'context'     => array( 'view', 'edit' ),
463
+					'context'     => array('view', 'edit'),
464 464
 					'readonly'    => true,
465 465
 				),
466 466
 				'order'              => array(
467
-					'description' => __( 'Shipping method sort order.', 'woocommerce' ),
467
+					'description' => __('Shipping method sort order.', 'woocommerce'),
468 468
 					'type'        => 'integer',
469
-					'context'     => array( 'view', 'edit' ),
469
+					'context'     => array('view', 'edit'),
470 470
 				),
471 471
 				'enabled'            => array(
472
-					'description' => __( 'Shipping method enabled status.', 'woocommerce' ),
472
+					'description' => __('Shipping method enabled status.', 'woocommerce'),
473 473
 					'type'        => 'boolean',
474
-					'context'     => array( 'view', 'edit' ),
474
+					'context'     => array('view', 'edit'),
475 475
 				),
476 476
 				'method_id'          => array(
477
-					'description' => __( 'Shipping method ID.', 'woocommerce' ),
477
+					'description' => __('Shipping method ID.', 'woocommerce'),
478 478
 					'type'        => 'string',
479
-					'context'     => array( 'view', 'edit' ),
479
+					'context'     => array('view', 'edit'),
480 480
 					'readonly'    => true,
481 481
 				),
482 482
 				'method_title'       => array(
483
-					'description' => __( 'Shipping method title.', 'woocommerce' ),
483
+					'description' => __('Shipping method title.', 'woocommerce'),
484 484
 					'type'        => 'string',
485
-					'context'     => array( 'view', 'edit' ),
485
+					'context'     => array('view', 'edit'),
486 486
 					'readonly'    => true,
487 487
 				),
488 488
 				'method_description' => array(
489
-					'description' => __( 'Shipping method description.', 'woocommerce' ),
489
+					'description' => __('Shipping method description.', 'woocommerce'),
490 490
 					'type'        => 'string',
491
-					'context'     => array( 'view', 'edit' ),
491
+					'context'     => array('view', 'edit'),
492 492
 					'readonly'    => true,
493 493
 				),
494 494
 				'settings'           => array(
495
-					'description' => __( 'Shipping method settings.', 'woocommerce' ),
495
+					'description' => __('Shipping method settings.', 'woocommerce'),
496 496
 					'type'        => 'object',
497
-					'context'     => array( 'view', 'edit' ),
497
+					'context'     => array('view', 'edit'),
498 498
 					'properties'  => array(
499 499
 						'id'          => array(
500
-							'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
500
+							'description' => __('A unique identifier for the setting.', 'woocommerce'),
501 501
 							'type'        => 'string',
502
-							'context'     => array( 'view', 'edit' ),
502
+							'context'     => array('view', 'edit'),
503 503
 							'readonly'    => true,
504 504
 						),
505 505
 						'label'       => array(
506
-							'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
506
+							'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'),
507 507
 							'type'        => 'string',
508
-							'context'     => array( 'view', 'edit' ),
508
+							'context'     => array('view', 'edit'),
509 509
 							'readonly'    => true,
510 510
 						),
511 511
 						'description' => array(
512
-							'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
512
+							'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'),
513 513
 							'type'        => 'string',
514
-							'context'     => array( 'view', 'edit' ),
514
+							'context'     => array('view', 'edit'),
515 515
 							'readonly'    => true,
516 516
 						),
517 517
 						'type'        => array(
518
-							'description' => __( 'Type of setting.', 'woocommerce' ),
518
+							'description' => __('Type of setting.', 'woocommerce'),
519 519
 							'type'        => 'string',
520
-							'context'     => array( 'view', 'edit' ),
521
-							'enum'        => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ),
520
+							'context'     => array('view', 'edit'),
521
+							'enum'        => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'),
522 522
 							'readonly'    => true,
523 523
 						),
524 524
 						'value'       => array(
525
-							'description' => __( 'Setting value.', 'woocommerce' ),
525
+							'description' => __('Setting value.', 'woocommerce'),
526 526
 							'type'        => 'string',
527
-							'context'     => array( 'view', 'edit' ),
527
+							'context'     => array('view', 'edit'),
528 528
 						),
529 529
 						'default'     => array(
530
-							'description' => __( 'Default value for the setting.', 'woocommerce' ),
530
+							'description' => __('Default value for the setting.', 'woocommerce'),
531 531
 							'type'        => 'string',
532
-							'context'     => array( 'view', 'edit' ),
532
+							'context'     => array('view', 'edit'),
533 533
 							'readonly'    => true,
534 534
 						),
535 535
 						'tip'         => array(
536
-							'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
536
+							'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'),
537 537
 							'type'        => 'string',
538
-							'context'     => array( 'view', 'edit' ),
538
+							'context'     => array('view', 'edit'),
539 539
 							'readonly'    => true,
540 540
 						),
541 541
 						'placeholder' => array(
542
-							'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ),
542
+							'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'),
543 543
 							'type'        => 'string',
544
-							'context'     => array( 'view', 'edit' ),
544
+							'context'     => array('view', 'edit'),
545 545
 							'readonly'    => true,
546 546
 						),
547 547
 					),
@@ -549,6 +549,6 @@  discard block
 block discarded – undo
549 549
 			),
550 550
 		);
551 551
 
552
-		return $this->add_additional_fields_schema( $schema );
552
+		return $this->add_additional_fields_schema($schema);
553 553
 	}
554 554
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/ProductAttributeTerms.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
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 Attribute Terms controller class.
@@ -33,32 +33,32 @@  discard block
 block discarded – undo
33 33
 			array(
34 34
 				'args' => array(
35 35
 					'attribute_id' => array(
36
-						'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
36
+						'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'),
37 37
 						'type'        => 'integer',
38 38
 					),
39 39
 				),
40 40
 				array(
41 41
 					'methods'             => \WP_REST_Server::READABLE,
42
-					'callback'            => array( $this, 'get_items' ),
43
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
42
+					'callback'            => array($this, 'get_items'),
43
+					'permission_callback' => array($this, 'get_items_permissions_check'),
44 44
 					'args'                => $this->get_collection_params(),
45 45
 				),
46 46
 				array(
47 47
 					'methods'             => \WP_REST_Server::CREATABLE,
48
-					'callback'            => array( $this, 'create_item' ),
49
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
48
+					'callback'            => array($this, 'create_item'),
49
+					'permission_callback' => array($this, 'create_item_permissions_check'),
50 50
 					'args'                => array_merge(
51
-						$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
51
+						$this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
52 52
 						array(
53 53
 							'name' => array(
54 54
 								'type'        => 'string',
55
-								'description' => __( 'Name for the resource.', 'woocommerce' ),
55
+								'description' => __('Name for the resource.', 'woocommerce'),
56 56
 								'required'    => true,
57 57
 							),
58 58
 						)
59 59
 					),
60 60
 				),
61
-				'schema' => array( $this, 'get_public_item_schema' ),
61
+				'schema' => array($this, 'get_public_item_schema'),
62 62
 			),
63 63
 			true
64 64
 		);
@@ -69,41 +69,41 @@  discard block
 block discarded – undo
69 69
 			array(
70 70
 				'args' => array(
71 71
 					'id' => array(
72
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
72
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
73 73
 						'type'        => 'integer',
74 74
 					),
75 75
 					'attribute_id' => array(
76
-						'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
76
+						'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'),
77 77
 						'type'        => 'integer',
78 78
 					),
79 79
 				),
80 80
 				array(
81 81
 					'methods'             => \WP_REST_Server::READABLE,
82
-					'callback'            => array( $this, 'get_item' ),
83
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
82
+					'callback'            => array($this, 'get_item'),
83
+					'permission_callback' => array($this, 'get_item_permissions_check'),
84 84
 					'args'                => array(
85
-						'context'         => $this->get_context_param( array( 'default' => 'view' ) ),
85
+						'context'         => $this->get_context_param(array('default' => 'view')),
86 86
 					),
87 87
 				),
88 88
 				array(
89 89
 					'methods'             => \WP_REST_Server::EDITABLE,
90
-					'callback'            => array( $this, 'update_item' ),
91
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
92
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
90
+					'callback'            => array($this, 'update_item'),
91
+					'permission_callback' => array($this, 'update_item_permissions_check'),
92
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
93 93
 				),
94 94
 				array(
95 95
 					'methods'             => \WP_REST_Server::DELETABLE,
96
-					'callback'            => array( $this, 'delete_item' ),
97
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
96
+					'callback'            => array($this, 'delete_item'),
97
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
98 98
 					'args'                => array(
99 99
 						'force' => array(
100 100
 							'default'     => false,
101 101
 							'type'        => 'boolean',
102
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
102
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
103 103
 						),
104 104
 					),
105 105
 				),
106
-				'schema' => array( $this, 'get_public_item_schema' ),
106
+				'schema' => array($this, 'get_public_item_schema'),
107 107
 			),
108 108
 			true
109 109
 		);
@@ -114,17 +114,17 @@  discard block
 block discarded – undo
114 114
 			array(
115 115
 				'args' => array(
116 116
 					'attribute_id' => array(
117
-						'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ),
117
+						'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'),
118 118
 						'type'        => 'integer',
119 119
 					),
120 120
 				),
121 121
 				array(
122 122
 					'methods'             => \WP_REST_Server::EDITABLE,
123
-					'callback'            => array( $this, 'batch_items' ),
124
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
125
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
123
+					'callback'            => array($this, 'batch_items'),
124
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
125
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
126 126
 				),
127
-				'schema' => array( $this, 'get_public_batch_schema' ),
127
+				'schema' => array($this, 'get_public_batch_schema'),
128 128
 			),
129 129
 			true
130 130
 		);
@@ -137,9 +137,9 @@  discard block
 block discarded – undo
137 137
 	 * @param \WP_REST_Request $request Request params.
138 138
 	 * @return \WP_REST_Response $response
139 139
 	 */
140
-	public function prepare_item_for_response( $item, $request ) {
140
+	public function prepare_item_for_response($item, $request) {
141 141
 		// Get term order.
142
-		$menu_order = get_term_meta( $item->term_id, 'order_' . $this->taxonomy, true );
142
+		$menu_order = get_term_meta($item->term_id, 'order_' . $this->taxonomy, true);
143 143
 
144 144
 		$data = array(
145 145
 			'id'          => (int) $item->term_id,
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 			'count'       => (int) $item->count,
151 151
 		);
152 152
 
153
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
154
-		$data    = $this->add_additional_fields_to_object( $data, $request );
155
-		$data    = $this->filter_response_by_context( $data, $context );
153
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
154
+		$data    = $this->add_additional_fields_to_object($data, $request);
155
+		$data    = $this->filter_response_by_context($data, $context);
156 156
 
157
-		$response = rest_ensure_response( $data );
157
+		$response = rest_ensure_response($data);
158 158
 
159
-		$response->add_links( $this->prepare_links( $item, $request ) );
159
+		$response->add_links($this->prepare_links($item, $request));
160 160
 
161 161
 		/**
162 162
 		 * Filter a term item returned from the API.
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 		 * @param object            $item      The original term object.
168 168
 		 * @param \WP_REST_Request   $request   Request used to generate the response.
169 169
 		 */
170
-		return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request );
170
+		return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request);
171 171
 	}
172 172
 
173 173
 	/**
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
 	 * @param \WP_REST_Request $request Request params.
178 178
 	 * @return bool|\WP_Error
179 179
 	 */
180
-	protected function update_term_meta_fields( $term, $request ) {
180
+	protected function update_term_meta_fields($term, $request) {
181 181
 		$id = (int) $term->term_id;
182 182
 
183
-		update_term_meta( $id, 'order_' . $this->taxonomy, $request['menu_order'] );
183
+		update_term_meta($id, 'order_' . $this->taxonomy, $request['menu_order']);
184 184
 
185 185
 		return true;
186 186
 	}
@@ -197,49 +197,49 @@  discard block
 block discarded – undo
197 197
 			'type'                 => 'object',
198 198
 			'properties'           => array(
199 199
 				'id' => array(
200
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
200
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
201 201
 					'type'        => 'integer',
202
-					'context'     => array( 'view', 'edit' ),
202
+					'context'     => array('view', 'edit'),
203 203
 					'readonly'    => true,
204 204
 				),
205 205
 				'name' => array(
206
-					'description' => __( 'Term name.', 'woocommerce' ),
206
+					'description' => __('Term name.', 'woocommerce'),
207 207
 					'type'        => 'string',
208
-					'context'     => array( 'view', 'edit' ),
208
+					'context'     => array('view', 'edit'),
209 209
 					'arg_options' => array(
210 210
 						'sanitize_callback' => 'sanitize_text_field',
211 211
 					),
212 212
 				),
213 213
 				'slug' => array(
214
-					'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ),
214
+					'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'),
215 215
 					'type'        => 'string',
216
-					'context'     => array( 'view', 'edit' ),
216
+					'context'     => array('view', 'edit'),
217 217
 					'arg_options' => array(
218 218
 						'sanitize_callback' => 'sanitize_title',
219 219
 					),
220 220
 				),
221 221
 				'description' => array(
222
-					'description' => __( 'HTML description of the resource.', 'woocommerce' ),
222
+					'description' => __('HTML description of the resource.', 'woocommerce'),
223 223
 					'type'        => 'string',
224
-					'context'     => array( 'view', 'edit' ),
224
+					'context'     => array('view', 'edit'),
225 225
 					'arg_options' => array(
226 226
 						'sanitize_callback' => 'wp_filter_post_kses',
227 227
 					),
228 228
 				),
229 229
 				'menu_order' => array(
230
-					'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ),
230
+					'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'),
231 231
 					'type'        => 'integer',
232
-					'context'     => array( 'view', 'edit' ),
232
+					'context'     => array('view', 'edit'),
233 233
 				),
234 234
 				'count' => array(
235
-					'description' => __( 'Number of published products for the resource.', 'woocommerce' ),
235
+					'description' => __('Number of published products for the resource.', 'woocommerce'),
236 236
 					'type'        => 'integer',
237
-					'context'     => array( 'view', 'edit' ),
237
+					'context'     => array('view', 'edit'),
238 238
 					'readonly'    => true,
239 239
 				),
240 240
 			),
241 241
 		);
242 242
 
243
-		return $this->add_additional_fields_schema( $schema );
243
+		return $this->add_additional_fields_schema($schema);
244 244
 	}
245 245
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/AbstractShippingZonesController.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
 namespace WooCommerce\RestApi\Controllers\Version4;
12 12
 
13
-defined( 'ABSPATH' ) || exit;
13
+defined('ABSPATH') || exit;
14 14
 
15 15
 /**
16 16
  * REST API Shipping Zones base class.
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	 * @param int $zone_id Shipping Zone ID.
34 34
 	 * @return WC_Shipping_Zone|\WP_Error
35 35
 	 */
36
-	protected function get_zone( $zone_id ) {
37
-		$zone = \WC_Shipping_Zones::get_zone_by( 'zone_id', $zone_id );
36
+	protected function get_zone($zone_id) {
37
+		$zone = \WC_Shipping_Zones::get_zone_by('zone_id', $zone_id);
38 38
 
39
-		if ( false === $zone ) {
40
-			return new \WP_Error( 'woocommerce_rest_shipping_zone_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
39
+		if (false === $zone) {
40
+			return new \WP_Error('woocommerce_rest_shipping_zone_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
41 41
 		}
42 42
 
43 43
 		return $zone;
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
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_shipping_enabled() ) {
54
-			return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) );
52
+	public function get_items_permissions_check($request) {
53
+		if ( ! wc_shipping_enabled()) {
54
+			return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404));
55 55
 		}
56 56
 
57
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
58
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
57
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
58
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
59 59
 		}
60 60
 
61 61
 		return true;
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
 	 * @param  \WP_REST_Request $request Full details about the request.
68 68
 	 * @return \WP_Error|boolean
69 69
 	 */
70
-	public function create_item_permissions_check( $request ) {
71
-		if ( ! wc_shipping_enabled() ) {
72
-			return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) );
70
+	public function create_item_permissions_check($request) {
71
+		if ( ! wc_shipping_enabled()) {
72
+			return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404));
73 73
 		}
74 74
 
75
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
76
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
75
+		if ( ! wc_rest_check_manager_permissions('settings', 'edit')) {
76
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
77 77
 		}
78 78
 
79 79
 		return true;
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
 	 * @param  \WP_REST_Request $request Full details about the request.
86 86
 	 * @return \WP_Error|boolean
87 87
 	 */
88
-	public function update_items_permissions_check( $request ) {
89
-		if ( ! wc_shipping_enabled() ) {
90
-			return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) );
88
+	public function update_items_permissions_check($request) {
89
+		if ( ! wc_shipping_enabled()) {
90
+			return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404));
91 91
 		}
92 92
 
93
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
94
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
93
+		if ( ! wc_rest_check_manager_permissions('settings', 'edit')) {
94
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
95 95
 		}
96 96
 
97 97
 		return true;
@@ -103,13 +103,13 @@  discard block
 block discarded – undo
103 103
 	 * @param  \WP_REST_Request $request Full details about the request.
104 104
 	 * @return \WP_Error|boolean
105 105
 	 */
106
-	public function delete_items_permissions_check( $request ) {
107
-		if ( ! wc_shipping_enabled() ) {
108
-			return new \WP_Error( 'rest_no_route', __( 'Shipping is disabled.', 'woocommerce' ), array( 'status' => 404 ) );
106
+	public function delete_items_permissions_check($request) {
107
+		if ( ! wc_shipping_enabled()) {
108
+			return new \WP_Error('rest_no_route', __('Shipping is disabled.', 'woocommerce'), array('status' => 404));
109 109
 		}
110 110
 
111
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) {
112
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
111
+		if ( ! wc_rest_check_manager_permissions('settings', 'delete')) {
112
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
113 113
 		}
114 114
 
115 115
 		return true;
Please login to merge, or discard this patch.
src/Controllers/Version4/Taxes.php 1 patch
Spacing   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
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 Taxes controller class.
@@ -33,17 +33,17 @@  discard block
 block discarded – undo
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 40
 				array(
41 41
 					'methods'             => \WP_REST_Server::CREATABLE,
42
-					'callback'            => array( $this, 'create_item' ),
43
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
44
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
42
+					'callback'            => array($this, 'create_item'),
43
+					'permission_callback' => array($this, 'create_item_permissions_check'),
44
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
45 45
 				),
46
-				'schema' => array( $this, 'get_public_item_schema' ),
46
+				'schema' => array($this, 'get_public_item_schema'),
47 47
 			),
48 48
 			true
49 49
 		);
@@ -54,37 +54,37 @@  discard block
 block discarded – undo
54 54
 			array(
55 55
 				'args' => array(
56 56
 					'id' => array(
57
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
57
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
58 58
 						'type'        => 'integer',
59 59
 					),
60 60
 				),
61 61
 				array(
62 62
 					'methods'             => \WP_REST_Server::READABLE,
63
-					'callback'            => array( $this, 'get_item' ),
64
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
63
+					'callback'            => array($this, 'get_item'),
64
+					'permission_callback' => array($this, 'get_item_permissions_check'),
65 65
 					'args'                => array(
66
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
66
+						'context' => $this->get_context_param(array('default' => 'view')),
67 67
 					),
68 68
 				),
69 69
 				array(
70 70
 					'methods'             => \WP_REST_Server::EDITABLE,
71
-					'callback'            => array( $this, 'update_item' ),
72
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
73
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
71
+					'callback'            => array($this, 'update_item'),
72
+					'permission_callback' => array($this, 'update_item_permissions_check'),
73
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
74 74
 				),
75 75
 				array(
76 76
 					'methods'             => \WP_REST_Server::DELETABLE,
77
-					'callback'            => array( $this, 'delete_item' ),
78
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
77
+					'callback'            => array($this, 'delete_item'),
78
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
79 79
 					'args'                => array(
80 80
 						'force' => array(
81 81
 							'default'     => false,
82 82
 							'type'        => 'boolean',
83
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
83
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
84 84
 						),
85 85
 					),
86 86
 				),
87
-				'schema' => array( $this, 'get_public_item_schema' ),
87
+				'schema' => array($this, 'get_public_item_schema'),
88 88
 			),
89 89
 			true
90 90
 		);
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
 			array(
96 96
 				array(
97 97
 					'methods'             => \WP_REST_Server::EDITABLE,
98
-					'callback'            => array( $this, 'batch_items' ),
99
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
100
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
98
+					'callback'            => array($this, 'batch_items'),
99
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
100
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
101 101
 				),
102
-				'schema' => array( $this, 'get_public_batch_schema' ),
102
+				'schema' => array($this, 'get_public_batch_schema'),
103 103
 			),
104 104
 			true
105 105
 		);
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 	 * @param  \WP_REST_Request $request Full details about the request.
112 112
 	 * @return \WP_Error|boolean
113 113
 	 */
114
-	public function get_items_permissions_check( $request ) {
115
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
116
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
114
+	public function get_items_permissions_check($request) {
115
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
116
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
117 117
 		}
118 118
 
119 119
 		return true;
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 	 *
127 127
 	 * @return bool|\WP_Error
128 128
 	 */
129
-	public function create_item_permissions_check( $request ) {
130
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) {
131
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
129
+	public function create_item_permissions_check($request) {
130
+		if ( ! wc_rest_check_manager_permissions('settings', 'create')) {
131
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
132 132
 		}
133 133
 
134 134
 		return true;
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 	 * @param  \WP_REST_Request $request Full details about the request.
141 141
 	 * @return \WP_Error|boolean
142 142
 	 */
143
-	public function get_item_permissions_check( $request ) {
144
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
145
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
143
+	public function get_item_permissions_check($request) {
144
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
145
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
146 146
 		}
147 147
 
148 148
 		return true;
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 	 *
156 156
 	 * @return bool|\WP_Error
157 157
 	 */
158
-	public function update_item_permissions_check( $request ) {
159
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
160
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
158
+	public function update_item_permissions_check($request) {
159
+		if ( ! wc_rest_check_manager_permissions('settings', 'edit')) {
160
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
161 161
 		}
162 162
 
163 163
 		return true;
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @return bool|\WP_Error
172 172
 	 */
173
-	public function delete_item_permissions_check( $request ) {
174
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) {
175
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
173
+	public function delete_item_permissions_check($request) {
174
+		if ( ! wc_rest_check_manager_permissions('settings', 'delete')) {
175
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
176 176
 		}
177 177
 
178 178
 		return true;
@@ -185,9 +185,9 @@  discard block
 block discarded – undo
185 185
 	 *
186 186
 	 * @return bool|\WP_Error
187 187
 	 */
188
-	public function batch_items_permissions_check( $request ) {
189
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'batch' ) ) {
190
-			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() ) );
188
+	public function batch_items_permissions_check($request) {
189
+		if ( ! wc_rest_check_manager_permissions('settings', 'batch')) {
190
+			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()));
191 191
 		}
192 192
 
193 193
 		return true;
@@ -199,22 +199,22 @@  discard block
 block discarded – undo
199 199
 	 * @param \WP_REST_Request $request Full details about the request.
200 200
 	 * @return \WP_Error\WP_REST_Response
201 201
 	 */
202
-	public function get_items( $request ) {
202
+	public function get_items($request) {
203 203
 		global $wpdb;
204 204
 
205 205
 		$prepared_args           = array();
206 206
 		$prepared_args['order']  = $request['order'];
207 207
 		$prepared_args['number'] = $request['per_page'];
208
-		if ( ! empty( $request['offset'] ) ) {
208
+		if ( ! empty($request['offset'])) {
209 209
 			$prepared_args['offset'] = $request['offset'];
210 210
 		} else {
211
-			$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
211
+			$prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number'];
212 212
 		}
213 213
 		$orderby_possibles        = array(
214 214
 			'id'    => 'tax_rate_id',
215 215
 			'order' => 'tax_rate_order',
216 216
 		);
217
-		$prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ];
217
+		$prepared_args['orderby'] = $orderby_possibles[$request['orderby']];
218 218
 		$prepared_args['class']   = $request['class'];
219 219
 		$prepared_args['code']    = $request['code'];
220 220
 		$prepared_args['include'] = $request['include'];
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 		 * @param array           $prepared_args Array of arguments for $wpdb->get_results().
226 226
 		 * @param \WP_REST_Request $request       The current request.
227 227
 		 */
228
-		$prepared_args = apply_filters( 'woocommerce_rest_tax_query', $prepared_args, $request );
228
+		$prepared_args = apply_filters('woocommerce_rest_tax_query', $prepared_args, $request);
229 229
 
230 230
 		$query = "
231 231
 			SELECT *
@@ -234,69 +234,69 @@  discard block
 block discarded – undo
234 234
 		";
235 235
 
236 236
 		// Filter by tax class.
237
-		if ( ! empty( $prepared_args['class'] ) ) {
238
-			$class  = 'standard' !== $prepared_args['class'] ? sanitize_title( $prepared_args['class'] ) : '';
237
+		if ( ! empty($prepared_args['class'])) {
238
+			$class  = 'standard' !== $prepared_args['class'] ? sanitize_title($prepared_args['class']) : '';
239 239
 			$query .= " AND tax_rate_class = '$class'";
240 240
 		}
241 241
 
242 242
 		// Filter by tax code.
243 243
 		$tax_code_search = $prepared_args['code'];
244
-		if ( $tax_code_search ) {
245
-			$tax_code_search = $wpdb->esc_like( $tax_code_search );
244
+		if ($tax_code_search) {
245
+			$tax_code_search = $wpdb->esc_like($tax_code_search);
246 246
 			$tax_code_search = ' \'%' . $tax_code_search . '%\'';
247 247
 			$query          .= ' AND CONCAT_WS( "-", NULLIF(tax_rate_country, ""), NULLIF(tax_rate_state, ""), NULLIF(tax_rate_name, ""), NULLIF(tax_rate_priority, "") ) LIKE ' . $tax_code_search;
248 248
 		}
249 249
 
250 250
 		// Filter by included tax rate IDs.
251 251
 		$included_taxes = $prepared_args['include'];
252
-		if ( ! empty( $included_taxes ) ) {
253
-			$included_taxes = implode( ',', $prepared_args['include'] );
252
+		if ( ! empty($included_taxes)) {
253
+			$included_taxes = implode(',', $prepared_args['include']);
254 254
 			$query         .= " AND tax_rate_id IN ({$included_taxes})";
255 255
 		}
256 256
 
257 257
 		// Order tax rates.
258
-		$order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args['orderby'] ) );
258
+		$order_by = sprintf(' ORDER BY %s', sanitize_key($prepared_args['orderby']));
259 259
 
260 260
 		// Pagination.
261
-		$pagination = sprintf( ' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number'] );
261
+		$pagination = sprintf(' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number']);
262 262
 
263 263
 		// Query taxes.
264
-		$results = $wpdb->get_results( $query . $order_by . $pagination ); // @codingStandardsIgnoreLine.
264
+		$results = $wpdb->get_results($query . $order_by . $pagination); // @codingStandardsIgnoreLine.
265 265
 
266 266
 		$taxes = array();
267
-		foreach ( $results as $tax ) {
268
-			$data    = $this->prepare_item_for_response( $tax, $request );
269
-			$taxes[] = $this->prepare_response_for_collection( $data );
267
+		foreach ($results as $tax) {
268
+			$data    = $this->prepare_item_for_response($tax, $request);
269
+			$taxes[] = $this->prepare_response_for_collection($data);
270 270
 		}
271 271
 
272
-		$response = rest_ensure_response( $taxes );
272
+		$response = rest_ensure_response($taxes);
273 273
 
274 274
 		// Store pagination values for headers then unset for count query.
275 275
 		$per_page = (int) $prepared_args['number'];
276
-		$page     = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
276
+		$page     = ceil((((int) $prepared_args['offset']) / $per_page) + 1);
277 277
 
278 278
 		// Query only for ids.
279
-		$wpdb->get_results( str_replace( 'SELECT *', 'SELECT tax_rate_id', $query ) ); // @codingStandardsIgnoreLine.
279
+		$wpdb->get_results(str_replace('SELECT *', 'SELECT tax_rate_id', $query)); // @codingStandardsIgnoreLine.
280 280
 
281 281
 		// Calculate totals.
282 282
 		$total_taxes = (int) $wpdb->num_rows;
283
-		$response->header( 'X-WP-Total', (int) $total_taxes );
284
-		$max_pages = ceil( $total_taxes / $per_page );
285
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
283
+		$response->header('X-WP-Total', (int) $total_taxes);
284
+		$max_pages = ceil($total_taxes / $per_page);
285
+		$response->header('X-WP-TotalPages', (int) $max_pages);
286 286
 
287
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
288
-		if ( $page > 1 ) {
287
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
288
+		if ($page > 1) {
289 289
 			$prev_page = $page - 1;
290
-			if ( $prev_page > $max_pages ) {
290
+			if ($prev_page > $max_pages) {
291 291
 				$prev_page = $max_pages;
292 292
 			}
293
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
294
-			$response->link_header( 'prev', $prev_link );
293
+			$prev_link = add_query_arg('page', $prev_page, $base);
294
+			$response->link_header('prev', $prev_link);
295 295
 		}
296
-		if ( $max_pages > $page ) {
296
+		if ($max_pages > $page) {
297 297
 			$next_page = $page + 1;
298
-			$next_link = add_query_arg( 'page', $next_page, $base );
299
-			$response->link_header( 'next', $next_link );
298
+			$next_link = add_query_arg('page', $next_page, $base);
299
+			$response->link_header('next', $next_link);
300 300
 		}
301 301
 
302 302
 		return $response;
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
 	 * @param stdClass|null   $current Existing tax object.
310 310
 	 * @return object
311 311
 	 */
312
-	protected function create_or_update_tax( $request, $current = null ) {
313
-		$id          = absint( isset( $request['id'] ) ? $request['id'] : 0 );
312
+	protected function create_or_update_tax($request, $current = null) {
313
+		$id          = absint(isset($request['id']) ? $request['id'] : 0);
314 314
 		$data        = array();
315 315
 		$fields      = array(
316 316
 			'tax_rate_country',
@@ -324,52 +324,52 @@  discard block
 block discarded – undo
324 324
 			'tax_rate_class',
325 325
 		);
326 326
 
327
-		foreach ( $fields as $field ) {
327
+		foreach ($fields as $field) {
328 328
 			// Keys via API differ from the stored names returned by _get_tax_rate.
329
-			$key = 'tax_rate' === $field ? 'rate' : str_replace( 'tax_rate_', '', $field );
329
+			$key = 'tax_rate' === $field ? 'rate' : str_replace('tax_rate_', '', $field);
330 330
 
331 331
 			// Remove data that was not posted.
332
-			if ( ! isset( $request[ $key ] ) ) {
332
+			if ( ! isset($request[$key])) {
333 333
 				continue;
334 334
 			}
335 335
 
336 336
 			// Test new data against current data.
337
-			if ( $current && $current->$field === $request[ $key ] ) {
337
+			if ($current && $current->$field === $request[$key]) {
338 338
 				continue;
339 339
 			}
340 340
 
341 341
 			// Add to data array.
342
-			switch ( $key ) {
342
+			switch ($key) {
343 343
 				case 'tax_rate_priority':
344 344
 				case 'tax_rate_compound':
345 345
 				case 'tax_rate_shipping':
346 346
 				case 'tax_rate_order':
347
-					$data[ $field ] = absint( $request[ $key ] );
347
+					$data[$field] = absint($request[$key]);
348 348
 					break;
349 349
 				case 'tax_rate_class':
350
-					$data[ $field ] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : '';
350
+					$data[$field] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : '';
351 351
 					break;
352 352
 				default:
353
-					$data[ $field ] = wc_clean( $request[ $key ] );
353
+					$data[$field] = wc_clean($request[$key]);
354 354
 					break;
355 355
 			}
356 356
 		}
357 357
 
358
-		if ( $id ) {
359
-			\WC_Tax::_update_tax_rate( $id, $data );
358
+		if ($id) {
359
+			\WC_Tax::_update_tax_rate($id, $data);
360 360
 		} else {
361
-			$id = \WC_Tax::_insert_tax_rate( $data );
361
+			$id = \WC_Tax::_insert_tax_rate($data);
362 362
 		}
363 363
 
364 364
 		// Add locales.
365
-		if ( ! empty( $request['postcode'] ) ) {
366
-			\WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request['postcode'] ) );
365
+		if ( ! empty($request['postcode'])) {
366
+			\WC_Tax::_update_tax_rate_postcodes($id, wc_clean($request['postcode']));
367 367
 		}
368
-		if ( ! empty( $request['city'] ) ) {
369
-			\WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request['city'] ) );
368
+		if ( ! empty($request['city'])) {
369
+			\WC_Tax::_update_tax_rate_cities($id, wc_clean($request['city']));
370 370
 		}
371 371
 
372
-		return \WC_Tax::_get_tax_rate( $id, OBJECT );
372
+		return \WC_Tax::_get_tax_rate($id, OBJECT);
373 373
 	}
374 374
 
375 375
 	/**
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
 	 * @param \WP_REST_Request $request Full details about the request.
379 379
 	 * @return \WP_Error\WP_REST_Response
380 380
 	 */
381
-	public function create_item( $request ) {
382
-		if ( ! empty( $request['id'] ) ) {
383
-			return new \WP_Error( 'woocommerce_rest_tax_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) );
381
+	public function create_item($request) {
382
+		if ( ! empty($request['id'])) {
383
+			return new \WP_Error('woocommerce_rest_tax_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400));
384 384
 		}
385 385
 
386
-		$tax = $this->create_or_update_tax( $request );
386
+		$tax = $this->create_or_update_tax($request);
387 387
 
388
-		$this->update_additional_fields_for_object( $tax, $request );
388
+		$this->update_additional_fields_for_object($tax, $request);
389 389
 
390 390
 		/**
391 391
 		 * Fires after a tax is created or updated via the REST API.
@@ -394,13 +394,13 @@  discard block
 block discarded – undo
394 394
 		 * @param \WP_REST_Request $request   Request object.
395 395
 		 * @param boolean         $creating  True when creating tax, false when updating tax.
396 396
 		 */
397
-		do_action( 'woocommerce_rest_insert_tax', $tax, $request, true );
397
+		do_action('woocommerce_rest_insert_tax', $tax, $request, true);
398 398
 
399
-		$request->set_param( 'context', 'edit' );
400
-		$response = $this->prepare_item_for_response( $tax, $request );
401
-		$response = rest_ensure_response( $response );
402
-		$response->set_status( 201 );
403
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ) );
399
+		$request->set_param('context', 'edit');
400
+		$response = $this->prepare_item_for_response($tax, $request);
401
+		$response = rest_ensure_response($response);
402
+		$response->set_status(201);
403
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id)));
404 404
 
405 405
 		return $response;
406 406
 	}
@@ -411,16 +411,16 @@  discard block
 block discarded – undo
411 411
 	 * @param \WP_REST_Request $request Full details about the request.
412 412
 	 * @return \WP_Error\WP_REST_Response
413 413
 	 */
414
-	public function get_item( $request ) {
414
+	public function get_item($request) {
415 415
 		$id      = (int) $request['id'];
416
-		$tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT );
416
+		$tax_obj = \WC_Tax::_get_tax_rate($id, OBJECT);
417 417
 
418
-		if ( empty( $id ) || empty( $tax_obj ) ) {
419
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
418
+		if (empty($id) || empty($tax_obj)) {
419
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
420 420
 		}
421 421
 
422
-		$tax      = $this->prepare_item_for_response( $tax_obj, $request );
423
-		$response = rest_ensure_response( $tax );
422
+		$tax      = $this->prepare_item_for_response($tax_obj, $request);
423
+		$response = rest_ensure_response($tax);
424 424
 
425 425
 		return $response;
426 426
 	}
@@ -431,17 +431,17 @@  discard block
 block discarded – undo
431 431
 	 * @param \WP_REST_Request $request Full details about the request.
432 432
 	 * @return \WP_Error\WP_REST_Response
433 433
 	 */
434
-	public function update_item( $request ) {
434
+	public function update_item($request) {
435 435
 		$id      = (int) $request['id'];
436
-		$tax_obj = \WC_Tax::_get_tax_rate( $id, OBJECT );
436
+		$tax_obj = \WC_Tax::_get_tax_rate($id, OBJECT);
437 437
 
438
-		if ( empty( $id ) || empty( $tax_obj ) ) {
439
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
438
+		if (empty($id) || empty($tax_obj)) {
439
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
440 440
 		}
441 441
 
442
-		$tax = $this->create_or_update_tax( $request, $tax_obj );
442
+		$tax = $this->create_or_update_tax($request, $tax_obj);
443 443
 
444
-		$this->update_additional_fields_for_object( $tax, $request );
444
+		$this->update_additional_fields_for_object($tax, $request);
445 445
 
446 446
 		/**
447 447
 		 * Fires after a tax is created or updated via the REST API.
@@ -450,11 +450,11 @@  discard block
 block discarded – undo
450 450
 		 * @param \WP_REST_Request $request   Request object.
451 451
 		 * @param boolean         $creating  True when creating tax, false when updating tax.
452 452
 		 */
453
-		do_action( 'woocommerce_rest_insert_tax', $tax, $request, false );
453
+		do_action('woocommerce_rest_insert_tax', $tax, $request, false);
454 454
 
455
-		$request->set_param( 'context', 'edit' );
456
-		$response = $this->prepare_item_for_response( $tax, $request );
457
-		$response = rest_ensure_response( $response );
455
+		$request->set_param('context', 'edit');
456
+		$response = $this->prepare_item_for_response($tax, $request);
457
+		$response = rest_ensure_response($response);
458 458
 
459 459
 		return $response;
460 460
 	}
@@ -465,30 +465,30 @@  discard block
 block discarded – undo
465 465
 	 * @param \WP_REST_Request $request Full details about the request.
466 466
 	 * @return \WP_Error\WP_REST_Response
467 467
 	 */
468
-	public function delete_item( $request ) {
468
+	public function delete_item($request) {
469 469
 		global $wpdb;
470 470
 
471 471
 		$id    = (int) $request['id'];
472
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
472
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
473 473
 
474 474
 		// We don't support trashing for this type, error out.
475
-		if ( ! $force ) {
476
-			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
475
+		if ( ! $force) {
476
+			return new \WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501));
477 477
 		}
478 478
 
479
-		$tax = \WC_Tax::_get_tax_rate( $id, OBJECT );
479
+		$tax = \WC_Tax::_get_tax_rate($id, OBJECT);
480 480
 
481
-		if ( empty( $id ) || empty( $tax ) ) {
482
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 400 ) );
481
+		if (empty($id) || empty($tax)) {
482
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 400));
483 483
 		}
484 484
 
485
-		$request->set_param( 'context', 'edit' );
486
-		$response = $this->prepare_item_for_response( $tax, $request );
485
+		$request->set_param('context', 'edit');
486
+		$response = $this->prepare_item_for_response($tax, $request);
487 487
 
488
-		\WC_Tax::_delete_tax_rate( $id );
488
+		\WC_Tax::_delete_tax_rate($id);
489 489
 
490
-		if ( 0 === $wpdb->rows_affected ) {
491
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
490
+		if (0 === $wpdb->rows_affected) {
491
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
492 492
 		}
493 493
 
494 494
 		/**
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
 		 * @param \WP_REST_Response $response The response returned from the API.
499 499
 		 * @param \WP_REST_Request  $request  The request sent to the API.
500 500
 		 */
501
-		do_action( 'woocommerce_rest_delete_tax', $tax, $response, $request );
501
+		do_action('woocommerce_rest_delete_tax', $tax, $response, $request);
502 502
 
503 503
 		return $response;
504 504
 	}
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 	 * @param \WP_REST_Request $request Request object.
511 511
 	 * @return \WP_REST_Response $response Response data.
512 512
 	 */
513
-	public function prepare_item_for_response( $tax, $request ) {
513
+	public function prepare_item_for_response($tax, $request) {
514 514
 		global $wpdb;
515 515
 
516 516
 		$id   = (int) $tax->tax_rate_id;
@@ -541,20 +541,20 @@  discard block
 block discarded – undo
541 541
 			)
542 542
 		);
543 543
 
544
-		if ( ! is_wp_error( $tax ) && ! is_null( $tax ) ) {
545
-			foreach ( $locales as $locale ) {
546
-				$data[ $locale->location_type ] = $locale->location_code;
544
+		if ( ! is_wp_error($tax) && ! is_null($tax)) {
545
+			foreach ($locales as $locale) {
546
+				$data[$locale->location_type] = $locale->location_code;
547 547
 			}
548 548
 		}
549 549
 
550
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
551
-		$data    = $this->add_additional_fields_to_object( $data, $request );
552
-		$data    = $this->filter_response_by_context( $data, $context );
550
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
551
+		$data    = $this->add_additional_fields_to_object($data, $request);
552
+		$data    = $this->filter_response_by_context($data, $context);
553 553
 
554 554
 		// Wrap the data in a response object.
555
-		$response = rest_ensure_response( $data );
555
+		$response = rest_ensure_response($data);
556 556
 
557
-		$response->add_links( $this->prepare_links( $tax ) );
557
+		$response->add_links($this->prepare_links($tax));
558 558
 
559 559
 		/**
560 560
 		 * Filter tax object returned from the REST API.
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
 		 * @param stdClass         $tax      Tax object used to create response.
564 564
 		 * @param \WP_REST_Request  $request  Request object.
565 565
 		 */
566
-		return apply_filters( 'woocommerce_rest_prepare_tax', $response, $tax, $request );
566
+		return apply_filters('woocommerce_rest_prepare_tax', $response, $tax, $request);
567 567
 	}
568 568
 
569 569
 	/**
@@ -572,13 +572,13 @@  discard block
 block discarded – undo
572 572
 	 * @param stdClass $tax Tax object.
573 573
 	 * @return array Links for the given tax.
574 574
 	 */
575
-	protected function prepare_links( $tax ) {
575
+	protected function prepare_links($tax) {
576 576
 		$links = array(
577 577
 			'self' => array(
578
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ),
578
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id)),
579 579
 			),
580 580
 			'collection' => array(
581
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
581
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
582 582
 			),
583 583
 		);
584 584
 
@@ -597,75 +597,75 @@  discard block
 block discarded – undo
597 597
 			'type'       => 'object',
598 598
 			'properties' => array(
599 599
 				'id' => array(
600
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
600
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
601 601
 					'type'        => 'integer',
602
-					'context'     => array( 'view', 'edit' ),
602
+					'context'     => array('view', 'edit'),
603 603
 					'readonly'    => true,
604 604
 				),
605 605
 				'country' => array(
606
-					'description' => __( 'Country ISO 3166 code.', 'woocommerce' ),
606
+					'description' => __('Country ISO 3166 code.', 'woocommerce'),
607 607
 					'type'        => 'string',
608
-					'context'     => array( 'view', 'edit' ),
608
+					'context'     => array('view', 'edit'),
609 609
 				),
610 610
 				'state' => array(
611
-					'description' => __( 'State code.', 'woocommerce' ),
611
+					'description' => __('State code.', 'woocommerce'),
612 612
 					'type'        => 'string',
613
-					'context'     => array( 'view', 'edit' ),
613
+					'context'     => array('view', 'edit'),
614 614
 				),
615 615
 				'postcode' => array(
616
-					'description' => __( 'Postcode / ZIP.', 'woocommerce' ),
616
+					'description' => __('Postcode / ZIP.', 'woocommerce'),
617 617
 					'type'        => 'string',
618
-					'context'     => array( 'view', 'edit' ),
618
+					'context'     => array('view', 'edit'),
619 619
 				),
620 620
 				'city' => array(
621
-					'description' => __( 'City name.', 'woocommerce' ),
621
+					'description' => __('City name.', 'woocommerce'),
622 622
 					'type'        => 'string',
623
-					'context'     => array( 'view', 'edit' ),
623
+					'context'     => array('view', 'edit'),
624 624
 				),
625 625
 				'rate' => array(
626
-					'description' => __( 'Tax rate.', 'woocommerce' ),
626
+					'description' => __('Tax rate.', 'woocommerce'),
627 627
 					'type'        => 'string',
628
-					'context'     => array( 'view', 'edit' ),
628
+					'context'     => array('view', 'edit'),
629 629
 				),
630 630
 				'name' => array(
631
-					'description' => __( 'Tax rate name.', 'woocommerce' ),
631
+					'description' => __('Tax rate name.', 'woocommerce'),
632 632
 					'type'        => 'string',
633
-					'context'     => array( 'view', 'edit' ),
633
+					'context'     => array('view', 'edit'),
634 634
 				),
635 635
 				'priority' => array(
636
-					'description' => __( 'Tax priority.', 'woocommerce' ),
636
+					'description' => __('Tax priority.', 'woocommerce'),
637 637
 					'type'        => 'integer',
638 638
 					'default'     => 1,
639
-					'context'     => array( 'view', 'edit' ),
639
+					'context'     => array('view', 'edit'),
640 640
 				),
641 641
 				'compound' => array(
642
-					'description' => __( 'Whether or not this is a compound rate.', 'woocommerce' ),
642
+					'description' => __('Whether or not this is a compound rate.', 'woocommerce'),
643 643
 					'type'        => 'boolean',
644 644
 					'default'     => false,
645
-					'context'     => array( 'view', 'edit' ),
645
+					'context'     => array('view', 'edit'),
646 646
 				),
647 647
 				'shipping' => array(
648
-					'description' => __( 'Whether or not this tax rate also gets applied to shipping.', 'woocommerce' ),
648
+					'description' => __('Whether or not this tax rate also gets applied to shipping.', 'woocommerce'),
649 649
 					'type'        => 'boolean',
650 650
 					'default'     => true,
651
-					'context'     => array( 'view', 'edit' ),
651
+					'context'     => array('view', 'edit'),
652 652
 				),
653 653
 				'order' => array(
654
-					'description' => __( 'Indicates the order that will appear in queries.', 'woocommerce' ),
654
+					'description' => __('Indicates the order that will appear in queries.', 'woocommerce'),
655 655
 					'type'        => 'integer',
656
-					'context'     => array( 'view', 'edit' ),
656
+					'context'     => array('view', 'edit'),
657 657
 				),
658 658
 				'class' => array(
659
-					'description' => __( 'Tax class.', 'woocommerce' ),
659
+					'description' => __('Tax class.', 'woocommerce'),
660 660
 					'type'        => 'string',
661 661
 					'default'     => 'standard',
662
-					'enum'        => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ),
663
-					'context'     => array( 'view', 'edit' ),
662
+					'enum'        => array_merge(array('standard'), \WC_Tax::get_tax_class_slugs()),
663
+					'context'     => array('view', 'edit'),
664 664
 				),
665 665
 			),
666 666
 		);
667 667
 
668
-		return $this->add_additional_fields_schema( $schema );
668
+		return $this->add_additional_fields_schema($schema);
669 669
 	}
670 670
 
671 671
 	/**
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
 		$params['context']['default'] = 'view';
680 680
 
681 681
 		$params['page'] = array(
682
-			'description'        => __( 'Current page of the collection.', 'woocommerce' ),
682
+			'description'        => __('Current page of the collection.', 'woocommerce'),
683 683
 			'type'               => 'integer',
684 684
 			'default'            => 1,
685 685
 			'sanitize_callback'  => 'absint',
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 			'minimum'            => 1,
688 688
 		);
689 689
 		$params['per_page'] = array(
690
-			'description'        => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
690
+			'description'        => __('Maximum number of items to be returned in result set.', 'woocommerce'),
691 691
 			'type'               => 'integer',
692 692
 			'default'            => 10,
693 693
 			'minimum'            => 1,
@@ -696,22 +696,22 @@  discard block
 block discarded – undo
696 696
 			'validate_callback'  => 'rest_validate_request_arg',
697 697
 		);
698 698
 		$params['offset'] = array(
699
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
699
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
700 700
 			'type'               => 'integer',
701 701
 			'sanitize_callback'  => 'absint',
702 702
 			'validate_callback'  => 'rest_validate_request_arg',
703 703
 		);
704 704
 		$params['order'] = array(
705 705
 			'default'            => 'asc',
706
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
707
-			'enum'               => array( 'asc', 'desc' ),
706
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
707
+			'enum'               => array('asc', 'desc'),
708 708
 			'sanitize_callback'  => 'sanitize_key',
709 709
 			'type'               => 'string',
710 710
 			'validate_callback'  => 'rest_validate_request_arg',
711 711
 		);
712 712
 		$params['orderby'] = array(
713 713
 			'default'            => 'order',
714
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
714
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
715 715
 			'enum'               => array(
716 716
 				'id',
717 717
 				'order',
@@ -721,19 +721,19 @@  discard block
 block discarded – undo
721 721
 			'validate_callback'  => 'rest_validate_request_arg',
722 722
 		);
723 723
 		$params['class'] = array(
724
-			'description'        => __( 'Sort by tax class.', 'woocommerce' ),
725
-			'enum'               => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ),
724
+			'description'        => __('Sort by tax class.', 'woocommerce'),
725
+			'enum'               => array_merge(array('standard'), \WC_Tax::get_tax_class_slugs()),
726 726
 			'sanitize_callback'  => 'sanitize_title',
727 727
 			'type'               => 'string',
728 728
 			'validate_callback'  => 'rest_validate_request_arg',
729 729
 		);
730
-		$params['code']    = array(
731
-			'description'       => __( 'Search by similar tax code.', 'woocommerce' ),
730
+		$params['code'] = array(
731
+			'description'       => __('Search by similar tax code.', 'woocommerce'),
732 732
 			'type'              => 'string',
733 733
 			'validate_callback' => 'rest_validate_request_arg',
734 734
 		);
735 735
 		$params['include'] = array(
736
-			'description'       => __( 'Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce' ),
736
+			'description'       => __('Limit result set to items that have the specified rate ID(s) assigned.', 'woocommerce'),
737 737
 			'type'              => 'array',
738 738
 			'items'             => array(
739 739
 				'type' => 'integer',
Please login to merge, or discard this patch.
src/Controllers/Version4/SettingsOptions.php 1 patch
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
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 Setting Options controller class.
@@ -35,16 +35,16 @@  discard block
 block discarded – undo
35 35
 			array(
36 36
 				'args'   => array(
37 37
 					'group' => array(
38
-						'description' => __( 'Settings group ID.', 'woocommerce' ),
38
+						'description' => __('Settings group ID.', 'woocommerce'),
39 39
 						'type'        => 'string',
40 40
 					),
41 41
 				),
42 42
 				array(
43 43
 					'methods'             => \WP_REST_Server::READABLE,
44
-					'callback'            => array( $this, 'get_items' ),
45
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
44
+					'callback'            => array($this, 'get_items'),
45
+					'permission_callback' => array($this, 'get_items_permissions_check'),
46 46
 				),
47
-				'schema' => array( $this, 'get_public_item_schema' ),
47
+				'schema' => array($this, 'get_public_item_schema'),
48 48
 			),
49 49
 			true
50 50
 		);
@@ -55,17 +55,17 @@  discard block
 block discarded – undo
55 55
 			array(
56 56
 				'args'   => array(
57 57
 					'group' => array(
58
-						'description' => __( 'Settings group ID.', 'woocommerce' ),
58
+						'description' => __('Settings group ID.', 'woocommerce'),
59 59
 						'type'        => 'string',
60 60
 					),
61 61
 				),
62 62
 				array(
63 63
 					'methods'             => \WP_REST_Server::EDITABLE,
64
-					'callback'            => array( $this, 'batch_items' ),
65
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
66
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
64
+					'callback'            => array($this, 'batch_items'),
65
+					'permission_callback' => array($this, 'update_items_permissions_check'),
66
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
67 67
 				),
68
-				'schema' => array( $this, 'get_public_batch_schema' ),
68
+				'schema' => array($this, 'get_public_batch_schema'),
69 69
 			),
70 70
 			true
71 71
 		);
@@ -76,26 +76,26 @@  discard block
 block discarded – undo
76 76
 			array(
77 77
 				'args'   => array(
78 78
 					'group' => array(
79
-						'description' => __( 'Settings group ID.', 'woocommerce' ),
79
+						'description' => __('Settings group ID.', 'woocommerce'),
80 80
 						'type'        => 'string',
81 81
 					),
82 82
 					'id'    => array(
83
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
83
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
84 84
 						'type'        => 'string',
85 85
 					),
86 86
 				),
87 87
 				array(
88 88
 					'methods'             => \WP_REST_Server::READABLE,
89
-					'callback'            => array( $this, 'get_item' ),
90
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
89
+					'callback'            => array($this, 'get_item'),
90
+					'permission_callback' => array($this, 'get_items_permissions_check'),
91 91
 				),
92 92
 				array(
93 93
 					'methods'             => \WP_REST_Server::EDITABLE,
94
-					'callback'            => array( $this, 'update_item' ),
95
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
96
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
94
+					'callback'            => array($this, 'update_item'),
95
+					'permission_callback' => array($this, 'update_items_permissions_check'),
96
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
97 97
 				),
98
-				'schema' => array( $this, 'get_public_item_schema' ),
98
+				'schema' => array($this, 'get_public_item_schema'),
99 99
 			),
100 100
 			true
101 101
 		);
@@ -108,16 +108,16 @@  discard block
 block discarded – undo
108 108
 	 * @param  \WP_REST_Request $request Request data.
109 109
 	 * @return \WP_Error\WP_REST_Response
110 110
 	 */
111
-	public function get_item( $request ) {
112
-		$setting = $this->get_setting( $request['group_id'], $request['id'] );
111
+	public function get_item($request) {
112
+		$setting = $this->get_setting($request['group_id'], $request['id']);
113 113
 
114
-		if ( is_wp_error( $setting ) ) {
114
+		if (is_wp_error($setting)) {
115 115
 			return $setting;
116 116
 		}
117 117
 
118
-		$response = $this->prepare_item_for_response( $setting, $request );
118
+		$response = $this->prepare_item_for_response($setting, $request);
119 119
 
120
-		return rest_ensure_response( $response );
120
+		return rest_ensure_response($response);
121 121
 	}
122 122
 
123 123
 	/**
@@ -127,24 +127,24 @@  discard block
 block discarded – undo
127 127
 	 * @param  \WP_REST_Request $request Request data.
128 128
 	 * @return \WP_Error\WP_REST_Response
129 129
 	 */
130
-	public function get_items( $request ) {
131
-		$settings = $this->get_group_settings( $request['group_id'] );
130
+	public function get_items($request) {
131
+		$settings = $this->get_group_settings($request['group_id']);
132 132
 
133
-		if ( is_wp_error( $settings ) ) {
133
+		if (is_wp_error($settings)) {
134 134
 			return $settings;
135 135
 		}
136 136
 
137 137
 		$data = array();
138 138
 
139
-		foreach ( $settings as $setting_obj ) {
140
-			$setting = $this->prepare_item_for_response( $setting_obj, $request );
141
-			$setting = $this->prepare_response_for_collection( $setting );
142
-			if ( $this->is_setting_type_valid( $setting['type'] ) ) {
139
+		foreach ($settings as $setting_obj) {
140
+			$setting = $this->prepare_item_for_response($setting_obj, $request);
141
+			$setting = $this->prepare_response_for_collection($setting);
142
+			if ($this->is_setting_type_valid($setting['type'])) {
143 143
 				$data[] = $setting;
144 144
 			}
145 145
 		}
146 146
 
147
-		return rest_ensure_response( $data );
147
+		return rest_ensure_response($data);
148 148
 	}
149 149
 
150 150
 	/**
@@ -153,39 +153,39 @@  discard block
 block discarded – undo
153 153
 	 * @param string $group_id Group ID.
154 154
 	 * @return array|\WP_Error
155 155
 	 */
156
-	public function get_group_settings( $group_id ) {
157
-		if ( empty( $group_id ) ) {
158
-			return new \WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
156
+	public function get_group_settings($group_id) {
157
+		if (empty($group_id)) {
158
+			return new \WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404));
159 159
 		}
160 160
 
161
-		$settings = apply_filters( 'woocommerce_settings-' . $group_id, array() ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
161
+		$settings = apply_filters('woocommerce_settings-' . $group_id, array()); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
162 162
 
163
-		if ( empty( $settings ) ) {
164
-			return new \WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
163
+		if (empty($settings)) {
164
+			return new \WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404));
165 165
 		}
166 166
 
167 167
 		$filtered_settings = array();
168
-		foreach ( $settings as $setting ) {
168
+		foreach ($settings as $setting) {
169 169
 			$option_key = $setting['option_key'];
170
-			$setting    = $this->filter_setting( $setting );
171
-			$default    = isset( $setting['default'] ) ? $setting['default'] : '';
170
+			$setting    = $this->filter_setting($setting);
171
+			$default    = isset($setting['default']) ? $setting['default'] : '';
172 172
 			// Get the option value.
173
-			if ( is_array( $option_key ) ) {
174
-				$option           = get_option( $option_key[0] );
175
-				$setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default;
173
+			if (is_array($option_key)) {
174
+				$option           = get_option($option_key[0]);
175
+				$setting['value'] = isset($option[$option_key[1]]) ? $option[$option_key[1]] : $default;
176 176
 			} else {
177
-				$admin_setting_value = \WC_Admin_Settings::get_option( $option_key, $default );
177
+				$admin_setting_value = \WC_Admin_Settings::get_option($option_key, $default);
178 178
 				$setting['value']    = $admin_setting_value;
179 179
 			}
180 180
 
181
-			if ( 'multi_select_countries' === $setting['type'] ) {
181
+			if ('multi_select_countries' === $setting['type']) {
182 182
 				$setting['options'] = WC()->countries->get_countries();
183 183
 				$setting['type']    = 'multiselect';
184
-			} elseif ( 'single_select_country' === $setting['type'] ) {
184
+			} elseif ('single_select_country' === $setting['type']) {
185 185
 				$setting['type']    = 'select';
186 186
 				$setting['options'] = $this->get_countries_and_states();
187
-			} elseif ( 'single_select_page' === $setting['type'] ) {
188
-				$pages   = get_pages(
187
+			} elseif ('single_select_page' === $setting['type']) {
188
+				$pages = get_pages(
189 189
 					array(
190 190
 						'sort_column'  => 'menu_order',
191 191
 						'sort_order'   => 'ASC',
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 					)
194 194
 				);
195 195
 				$options = array();
196
-				foreach ( $pages as $page ) {
197
-					$options[ $page->ID ] = ! empty( $page->post_title ) ? $page->post_title : '#' . $page->ID;
196
+				foreach ($pages as $page) {
197
+					$options[$page->ID] = ! empty($page->post_title) ? $page->post_title : '#' . $page->ID;
198 198
 				}
199 199
 				$setting['type']    = 'select';
200 200
 				$setting['options'] = $options;
@@ -214,19 +214,19 @@  discard block
 block discarded – undo
214 214
 	 */
215 215
 	private function get_countries_and_states() {
216 216
 		$countries = WC()->countries->get_countries();
217
-		if ( ! $countries ) {
217
+		if ( ! $countries) {
218 218
 			return array();
219 219
 		}
220 220
 		$output = array();
221
-		foreach ( $countries as $key => $value ) {
222
-			$states = WC()->countries->get_states( $key );
221
+		foreach ($countries as $key => $value) {
222
+			$states = WC()->countries->get_states($key);
223 223
 
224
-			if ( $states ) {
225
-				foreach ( $states as $state_key => $state_value ) {
226
-					$output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value;
224
+			if ($states) {
225
+				foreach ($states as $state_key => $state_value) {
226
+					$output[$key . ':' . $state_key] = $value . ' - ' . $state_value;
227 227
 				}
228 228
 			} else {
229
-				$output[ $key ] = $value;
229
+				$output[$key] = $value;
230 230
 			}
231 231
 		}
232 232
 		return $output;
@@ -240,30 +240,30 @@  discard block
 block discarded – undo
240 240
 	 * @param string $setting_id Setting ID.
241 241
 	 * @return stdClass|\WP_Error
242 242
 	 */
243
-	public function get_setting( $group_id, $setting_id ) {
244
-		if ( empty( $setting_id ) ) {
245
-			return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) );
243
+	public function get_setting($group_id, $setting_id) {
244
+		if (empty($setting_id)) {
245
+			return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404));
246 246
 		}
247 247
 
248
-		$settings = $this->get_group_settings( $group_id );
248
+		$settings = $this->get_group_settings($group_id);
249 249
 
250
-		if ( is_wp_error( $settings ) ) {
250
+		if (is_wp_error($settings)) {
251 251
 			return $settings;
252 252
 		}
253 253
 
254
-		$array_key = array_keys( wp_list_pluck( $settings, 'id' ), $setting_id );
254
+		$array_key = array_keys(wp_list_pluck($settings, 'id'), $setting_id);
255 255
 
256
-		if ( empty( $array_key ) ) {
257
-			return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) );
256
+		if (empty($array_key)) {
257
+			return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404));
258 258
 		}
259 259
 
260
-		$setting = $settings[ $array_key[0] ];
260
+		$setting = $settings[$array_key[0]];
261 261
 
262
-		if ( ! $this->is_setting_type_valid( $setting['type'] ) ) {
263
-			return new \WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) );
262
+		if ( ! $this->is_setting_type_valid($setting['type'])) {
263
+			return new \WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404));
264 264
 		}
265 265
 
266
-		if ( is_wp_error( $setting ) ) {
266
+		if (is_wp_error($setting)) {
267 267
 			return $setting;
268 268
 		}
269 269
 
@@ -279,24 +279,24 @@  discard block
 block discarded – undo
279 279
 	 * @param \WP_REST_Request $request Full details about the request.
280 280
 	 * @return array Of \WP_Error or \WP_REST_Response.
281 281
 	 */
282
-	public function batch_items( $request ) {
282
+	public function batch_items($request) {
283 283
 		// Get the request params.
284
-		$items = array_filter( $request->get_params() );
284
+		$items = array_filter($request->get_params());
285 285
 
286 286
 		/*
287 287
 		 * Since our batch settings update is group-specific and matches based on the route,
288 288
 		 * we inject the URL parameters (containing group) into the batch items
289 289
 		 */
290
-		if ( ! empty( $items['update'] ) ) {
290
+		if ( ! empty($items['update'])) {
291 291
 			$to_update = array();
292
-			foreach ( $items['update'] as $item ) {
293
-				$to_update[] = array_merge( $request->get_url_params(), $item );
292
+			foreach ($items['update'] as $item) {
293
+				$to_update[] = array_merge($request->get_url_params(), $item);
294 294
 			}
295
-			$request = new \WP_REST_Request( $request->get_method() );
296
-			$request->set_body_params( array( 'update' => $to_update ) );
295
+			$request = new \WP_REST_Request($request->get_method());
296
+			$request->set_body_params(array('update' => $to_update));
297 297
 		}
298 298
 
299
-		return parent::batch_items( $request );
299
+		return parent::batch_items($request);
300 300
 	}
301 301
 
302 302
 	/**
@@ -306,39 +306,39 @@  discard block
 block discarded – undo
306 306
 	 * @param  \WP_REST_Request $request Request data.
307 307
 	 * @return \WP_Error\WP_REST_Response
308 308
 	 */
309
-	public function update_item( $request ) {
310
-		$setting = $this->get_setting( $request['group_id'], $request['id'] );
309
+	public function update_item($request) {
310
+		$setting = $this->get_setting($request['group_id'], $request['id']);
311 311
 
312
-		if ( is_wp_error( $setting ) ) {
312
+		if (is_wp_error($setting)) {
313 313
 			return $setting;
314 314
 		}
315 315
 
316
-		if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) {
317
-			$value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting );
316
+		if (is_callable(array($this, 'validate_setting_' . $setting['type'] . '_field'))) {
317
+			$value = $this->{'validate_setting_' . $setting['type'] . '_field'}($request['value'], $setting);
318 318
 		} else {
319
-			$value = $this->validate_setting_text_field( $request['value'], $setting );
319
+			$value = $this->validate_setting_text_field($request['value'], $setting);
320 320
 		}
321 321
 
322
-		if ( is_wp_error( $value ) ) {
322
+		if (is_wp_error($value)) {
323 323
 			return $value;
324 324
 		}
325 325
 
326
-		if ( is_array( $setting['option_key'] ) ) {
326
+		if (is_array($setting['option_key'])) {
327 327
 			$setting['value']       = $value;
328 328
 			$option_key             = $setting['option_key'];
329
-			$prev                   = get_option( $option_key[0] );
330
-			$prev[ $option_key[1] ] = $request['value'];
331
-			update_option( $option_key[0], $prev );
329
+			$prev                   = get_option($option_key[0]);
330
+			$prev[$option_key[1]] = $request['value'];
331
+			update_option($option_key[0], $prev);
332 332
 		} else {
333 333
 			$update_data                           = array();
334
-			$update_data[ $setting['option_key'] ] = $value;
334
+			$update_data[$setting['option_key']] = $value;
335 335
 			$setting['value']                      = $value;
336
-			\WC_Admin_Settings::save_fields( array( $setting ), $update_data );
336
+			\WC_Admin_Settings::save_fields(array($setting), $update_data);
337 337
 		}
338 338
 
339
-		$response = $this->prepare_item_for_response( $setting, $request );
339
+		$response = $this->prepare_item_for_response($setting, $request);
340 340
 
341
-		return rest_ensure_response( $response );
341
+		return rest_ensure_response($response);
342 342
 	}
343 343
 
344 344
 	/**
@@ -349,13 +349,13 @@  discard block
 block discarded – undo
349 349
 	 * @param \WP_REST_Request $request Request object.
350 350
 	 * @return \WP_REST_Response $response Response data.
351 351
 	 */
352
-	public function prepare_item_for_response( $item, $request ) {
353
-		unset( $item['option_key'] );
354
-		$data     = $this->filter_setting( $item );
355
-		$data     = $this->add_additional_fields_to_object( $data, $request );
356
-		$data     = $this->filter_response_by_context( $data, empty( $request['context'] ) ? 'view' : $request['context'] );
357
-		$response = rest_ensure_response( $data );
358
-		$response->add_links( $this->prepare_links( $data['id'], $request['group_id'] ) );
352
+	public function prepare_item_for_response($item, $request) {
353
+		unset($item['option_key']);
354
+		$data     = $this->filter_setting($item);
355
+		$data     = $this->add_additional_fields_to_object($data, $request);
356
+		$data     = $this->filter_response_by_context($data, empty($request['context']) ? 'view' : $request['context']);
357
+		$response = rest_ensure_response($data);
358
+		$response->add_links($this->prepare_links($data['id'], $request['group_id']));
359 359
 		return $response;
360 360
 	}
361 361
 
@@ -367,14 +367,14 @@  discard block
 block discarded – undo
367 367
 	 * @param string $group_id Group ID.
368 368
 	 * @return array Links for the given setting.
369 369
 	 */
370
-	protected function prepare_links( $setting_id, $group_id ) {
371
-		$base  = str_replace( '(?P<group_id>[\w-]+)', $group_id, $this->rest_base );
370
+	protected function prepare_links($setting_id, $group_id) {
371
+		$base  = str_replace('(?P<group_id>[\w-]+)', $group_id, $this->rest_base);
372 372
 		$links = array(
373 373
 			'self'       => array(
374
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $setting_id ) ),
374
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $base, $setting_id)),
375 375
 			),
376 376
 			'collection' => array(
377
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
377
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)),
378 378
 			),
379 379
 		);
380 380
 
@@ -388,9 +388,9 @@  discard block
 block discarded – undo
388 388
 	 * @param \WP_REST_Request $request Full data about the request.
389 389
 	 * @return \WP_Error|boolean
390 390
 	 */
391
-	public function get_items_permissions_check( $request ) {
392
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
393
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
391
+	public function get_items_permissions_check($request) {
392
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
393
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
394 394
 		}
395 395
 
396 396
 		return true;
@@ -403,9 +403,9 @@  discard block
 block discarded – undo
403 403
 	 * @param \WP_REST_Request $request Full data about the request.
404 404
 	 * @return \WP_Error|boolean
405 405
 	 */
406
-	public function update_items_permissions_check( $request ) {
407
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
408
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
406
+	public function update_items_permissions_check($request) {
407
+		if ( ! wc_rest_check_manager_permissions('settings', 'edit')) {
408
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
409 409
 		}
410 410
 
411 411
 		return true;
@@ -419,18 +419,18 @@  discard block
 block discarded – undo
419 419
 	 * @param  array $setting Settings.
420 420
 	 * @return array
421 421
 	 */
422
-	public function filter_setting( $setting ) {
422
+	public function filter_setting($setting) {
423 423
 		$setting = array_intersect_key(
424 424
 			$setting,
425
-			array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) )
425
+			array_flip(array_filter(array_keys($setting), array($this, 'allowed_setting_keys')))
426 426
 		);
427 427
 
428
-		if ( empty( $setting['options'] ) ) {
429
-			unset( $setting['options'] );
428
+		if (empty($setting['options'])) {
429
+			unset($setting['options']);
430 430
 		}
431 431
 
432
-		if ( 'image_width' === $setting['type'] ) {
433
-			$setting = $this->cast_image_width( $setting );
432
+		if ('image_width' === $setting['type']) {
433
+			$setting = $this->cast_image_width($setting);
434 434
 		}
435 435
 
436 436
 		return $setting;
@@ -445,12 +445,12 @@  discard block
 block discarded – undo
445 445
 	 * @param  array $setting Settings.
446 446
 	 * @return array
447 447
 	 */
448
-	public function cast_image_width( $setting ) {
449
-		foreach ( array( 'default', 'value' ) as $key ) {
450
-			if ( isset( $setting[ $key ] ) ) {
451
-				$setting[ $key ]['width']  = intval( $setting[ $key ]['width'] );
452
-				$setting[ $key ]['height'] = intval( $setting[ $key ]['height'] );
453
-				$setting[ $key ]['crop']   = (bool) $setting[ $key ]['crop'];
448
+	public function cast_image_width($setting) {
449
+		foreach (array('default', 'value') as $key) {
450
+			if (isset($setting[$key])) {
451
+				$setting[$key]['width']  = intval($setting[$key]['width']);
452
+				$setting[$key]['height'] = intval($setting[$key]['height']);
453
+				$setting[$key]['crop']   = (bool) $setting[$key]['crop'];
454 454
 			}
455 455
 		}
456 456
 		return $setting;
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 	 * @param  string $key Key to check.
463 463
 	 * @return boolean
464 464
 	 */
465
-	public function allowed_setting_keys( $key ) {
465
+	public function allowed_setting_keys($key) {
466 466
 		return in_array(
467 467
 			$key, array(
468 468
 				'id',
@@ -487,20 +487,20 @@  discard block
 block discarded – undo
487 487
 	 * @param  string $type Type.
488 488
 	 * @return bool
489 489
 	 */
490
-	public function is_setting_type_valid( $type ) {
490
+	public function is_setting_type_valid($type) {
491 491
 		return in_array(
492 492
 			$type, array(
493
-				'text',         // Validates with validate_setting_text_field.
494
-				'email',        // Validates with validate_setting_text_field.
495
-				'number',       // Validates with validate_setting_text_field.
496
-				'color',        // Validates with validate_setting_text_field.
497
-				'password',     // Validates with validate_setting_text_field.
498
-				'textarea',     // Validates with validate_setting_textarea_field.
499
-				'select',       // Validates with validate_setting_select_field.
500
-				'multiselect',  // Validates with validate_setting_multiselect_field.
501
-				'radio',        // Validates with validate_setting_radio_field (-> validate_setting_select_field).
502
-				'checkbox',     // Validates with validate_setting_checkbox_field.
503
-				'image_width',  // Validates with validate_setting_image_width_field.
493
+				'text', // Validates with validate_setting_text_field.
494
+				'email', // Validates with validate_setting_text_field.
495
+				'number', // Validates with validate_setting_text_field.
496
+				'color', // Validates with validate_setting_text_field.
497
+				'password', // Validates with validate_setting_text_field.
498
+				'textarea', // Validates with validate_setting_textarea_field.
499
+				'select', // Validates with validate_setting_select_field.
500
+				'multiselect', // Validates with validate_setting_multiselect_field.
501
+				'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field).
502
+				'checkbox', // Validates with validate_setting_checkbox_field.
503
+				'image_width', // Validates with validate_setting_image_width_field.
504 504
 				'thumbnail_cropping', // Validates with validate_setting_text_field.
505 505
 			)
506 506
 		);
@@ -518,89 +518,89 @@  discard block
 block discarded – undo
518 518
 			'type'       => 'object',
519 519
 			'properties' => array(
520 520
 				'id'          => array(
521
-					'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
521
+					'description' => __('A unique identifier for the setting.', 'woocommerce'),
522 522
 					'type'        => 'string',
523 523
 					'arg_options' => array(
524 524
 						'sanitize_callback' => 'sanitize_title',
525 525
 					),
526
-					'context'     => array( 'view', 'edit' ),
526
+					'context'     => array('view', 'edit'),
527 527
 					'readonly'    => true,
528 528
 				),
529 529
 				'group_id'    => array(
530
-					'description' => __( 'An identifier for the group this setting belongs to.', 'woocommerce' ),
530
+					'description' => __('An identifier for the group this setting belongs to.', 'woocommerce'),
531 531
 					'type'        => 'string',
532 532
 					'arg_options' => array(
533 533
 						'sanitize_callback' => 'sanitize_title',
534 534
 					),
535
-					'context'     => array( 'view', 'edit' ),
535
+					'context'     => array('view', 'edit'),
536 536
 					'readonly'    => true,
537 537
 				),
538 538
 				'label'       => array(
539
-					'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
539
+					'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'),
540 540
 					'type'        => 'string',
541 541
 					'arg_options' => array(
542 542
 						'sanitize_callback' => 'sanitize_text_field',
543 543
 					),
544
-					'context'     => array( 'view', 'edit' ),
544
+					'context'     => array('view', 'edit'),
545 545
 					'readonly'    => true,
546 546
 				),
547 547
 				'description' => array(
548
-					'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
548
+					'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'),
549 549
 					'type'        => 'string',
550 550
 					'arg_options' => array(
551 551
 						'sanitize_callback' => 'sanitize_text_field',
552 552
 					),
553
-					'context'     => array( 'view', 'edit' ),
553
+					'context'     => array('view', 'edit'),
554 554
 					'readonly'    => true,
555 555
 				),
556 556
 				'value'       => array(
557
-					'description' => __( 'Setting value.', 'woocommerce' ),
557
+					'description' => __('Setting value.', 'woocommerce'),
558 558
 					'type'        => 'mixed',
559
-					'context'     => array( 'view', 'edit' ),
559
+					'context'     => array('view', 'edit'),
560 560
 				),
561 561
 				'default'     => array(
562
-					'description' => __( 'Default value for the setting.', 'woocommerce' ),
562
+					'description' => __('Default value for the setting.', 'woocommerce'),
563 563
 					'type'        => 'mixed',
564
-					'context'     => array( 'view', 'edit' ),
564
+					'context'     => array('view', 'edit'),
565 565
 					'readonly'    => true,
566 566
 				),
567 567
 				'tip'         => array(
568
-					'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
568
+					'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'),
569 569
 					'type'        => 'string',
570 570
 					'arg_options' => array(
571 571
 						'sanitize_callback' => 'sanitize_text_field',
572 572
 					),
573
-					'context'     => array( 'view', 'edit' ),
573
+					'context'     => array('view', 'edit'),
574 574
 					'readonly'    => true,
575 575
 				),
576 576
 				'placeholder' => array(
577
-					'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ),
577
+					'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'),
578 578
 					'type'        => 'string',
579 579
 					'arg_options' => array(
580 580
 						'sanitize_callback' => 'sanitize_text_field',
581 581
 					),
582
-					'context'     => array( 'view', 'edit' ),
582
+					'context'     => array('view', 'edit'),
583 583
 					'readonly'    => true,
584 584
 				),
585 585
 				'type'        => array(
586
-					'description' => __( 'Type of setting.', 'woocommerce' ),
586
+					'description' => __('Type of setting.', 'woocommerce'),
587 587
 					'type'        => 'string',
588 588
 					'arg_options' => array(
589 589
 						'sanitize_callback' => 'sanitize_text_field',
590 590
 					),
591
-					'context'     => array( 'view', 'edit' ),
592
-					'enum'        => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ),
591
+					'context'     => array('view', 'edit'),
592
+					'enum'        => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'),
593 593
 					'readonly'    => true,
594 594
 				),
595 595
 				'options'     => array(
596
-					'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ),
596
+					'description' => __('Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce'),
597 597
 					'type'        => 'object',
598
-					'context'     => array( 'view', 'edit' ),
598
+					'context'     => array('view', 'edit'),
599 599
 					'readonly'    => true,
600 600
 				),
601 601
 			),
602 602
 		);
603 603
 
604
-		return $this->add_additional_fields_schema( $schema );
604
+		return $this->add_additional_fields_schema($schema);
605 605
 	}
606 606
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/Data.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
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 Coupons controller class.
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 			array(
36 36
 				array(
37 37
 					'methods'             => \WP_REST_Server::READABLE,
38
-					'callback'            => array( $this, 'get_items' ),
39
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
38
+					'callback'            => array($this, 'get_items'),
39
+					'permission_callback' => array($this, 'get_items_permissions_check'),
40 40
 				),
41
-				'schema' => array( $this, 'get_public_item_schema' ),
41
+				'schema' => array($this, 'get_public_item_schema'),
42 42
 			),
43 43
 			true
44 44
 		);
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 	 * @param  \WP_REST_Request $request Full details about the request.
51 51
 	 * @return \WP_Error|boolean
52 52
 	 */
53
-	public function get_items_permissions_check( $request ) {
54
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
55
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
53
+	public function get_items_permissions_check($request) {
54
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
55
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
56 56
 		}
57 57
 
58 58
 		return true;
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	 * @param  \WP_REST_Request $request Full details about the request.
65 65
 	 * @return \WP_Error|boolean
66 66
 	 */
67
-	public function get_item_permissions_check( $request ) {
68
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
69
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
67
+	public function get_item_permissions_check($request) {
68
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
69
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
70 70
 		}
71 71
 
72 72
 		return true;
@@ -79,33 +79,33 @@  discard block
 block discarded – undo
79 79
 	 * @param  \WP_REST_Request $request Request data.
80 80
 	 * @return \WP_Error\WP_REST_Response
81 81
 	 */
82
-	public function get_items( $request ) {
82
+	public function get_items($request) {
83 83
 		$data      = array();
84 84
 		$resources = array(
85 85
 			array(
86 86
 				'slug'        => 'continents',
87
-				'description' => __( 'List of supported continents, countries, and states.', 'woocommerce' ),
87
+				'description' => __('List of supported continents, countries, and states.', 'woocommerce'),
88 88
 			),
89 89
 			array(
90 90
 				'slug'        => 'countries',
91
-				'description' => __( 'List of supported states in a given country.', 'woocommerce' ),
91
+				'description' => __('List of supported states in a given country.', 'woocommerce'),
92 92
 			),
93 93
 			array(
94 94
 				'slug'        => 'currencies',
95
-				'description' => __( 'List of supported currencies.', 'woocommerce' ),
95
+				'description' => __('List of supported currencies.', 'woocommerce'),
96 96
 			),
97 97
 			array(
98 98
 				'slug'        => 'download-ips',
99
-				'description' => __( 'An endpoint used for searching download logs for a specific IP address.', 'woocommerce' ),
99
+				'description' => __('An endpoint used for searching download logs for a specific IP address.', 'woocommerce'),
100 100
 			),
101 101
 		);
102 102
 
103
-		foreach ( $resources as $resource ) {
104
-			$item   = $this->prepare_item_for_response( (object) $resource, $request );
105
-			$data[] = $this->prepare_response_for_collection( $item );
103
+		foreach ($resources as $resource) {
104
+			$item   = $this->prepare_item_for_response((object) $resource, $request);
105
+			$data[] = $this->prepare_response_for_collection($item);
106 106
 		}
107 107
 
108
-		return rest_ensure_response( $data );
108
+		return rest_ensure_response($data);
109 109
 	}
110 110
 
111 111
 	/**
@@ -115,18 +115,18 @@  discard block
 block discarded – undo
115 115
 	 * @param \WP_REST_Request $request  Request object.
116 116
 	 * @return \WP_REST_Response $response Response data.
117 117
 	 */
118
-	public function prepare_item_for_response( $resource, $request ) {
118
+	public function prepare_item_for_response($resource, $request) {
119 119
 		$data = array(
120 120
 			'slug'        => $resource->slug,
121 121
 			'description' => $resource->description,
122 122
 		);
123 123
 
124
-		$data = $this->add_additional_fields_to_object( $data, $request );
125
-		$data = $this->filter_response_by_context( $data, 'view' );
124
+		$data = $this->add_additional_fields_to_object($data, $request);
125
+		$data = $this->filter_response_by_context($data, 'view');
126 126
 
127 127
 		// Wrap the data in a response object.
128
-		$response = rest_ensure_response( $data );
129
-		$response->add_links( $this->prepare_links( $resource ) );
128
+		$response = rest_ensure_response($data);
129
+		$response->add_links($this->prepare_links($resource));
130 130
 
131 131
 		return $response;
132 132
 	}
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
 	 * @param object $item Data object.
138 138
 	 * @return array Links for the given country.
139 139
 	 */
140
-	protected function prepare_links( $item ) {
140
+	protected function prepare_links($item) {
141 141
 		$links = array(
142 142
 			'self'       => array(
143
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug ) ),
143
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $item->slug)),
144 144
 			),
145 145
 			'collection' => array(
146
-				'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
146
+				'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)),
147 147
 			),
148 148
 		);
149 149
 
@@ -163,20 +163,20 @@  discard block
 block discarded – undo
163 163
 			'type'       => 'object',
164 164
 			'properties' => array(
165 165
 				'slug'        => array(
166
-					'description' => __( 'Data resource ID.', 'woocommerce' ),
166
+					'description' => __('Data resource ID.', 'woocommerce'),
167 167
 					'type'        => 'string',
168
-					'context'     => array( 'view' ),
168
+					'context'     => array('view'),
169 169
 					'readonly'    => true,
170 170
 				),
171 171
 				'description' => array(
172
-					'description' => __( 'Data resource description.', 'woocommerce' ),
172
+					'description' => __('Data resource description.', 'woocommerce'),
173 173
 					'type'        => 'string',
174
-					'context'     => array( 'view' ),
174
+					'context'     => array('view'),
175 175
 					'readonly'    => true,
176 176
 				),
177 177
 			),
178 178
 		);
179 179
 
180
-		return $this->add_additional_fields_schema( $schema );
180
+		return $this->add_additional_fields_schema($schema);
181 181
 	}
182 182
 }
Please login to merge, or discard this patch.
src/Controllers/Version4/PaymentGateways.php 1 patch
Spacing   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
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
  * Payment gateways controller class.
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
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,25 +47,25 @@  discard block
 block discarded – undo
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 62
 				array(
63 63
 					'methods'             => \WP_REST_Server::EDITABLE,
64
-					'callback'            => array( $this, 'update_item' ),
65
-					'permission_callback' => array( $this, 'update_items_permissions_check' ),
66
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
64
+					'callback'            => array($this, 'update_item'),
65
+					'permission_callback' => array($this, 'update_items_permissions_check'),
66
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
67 67
 				),
68
-				'schema' => array( $this, 'get_public_item_schema' ),
68
+				'schema' => array($this, 'get_public_item_schema'),
69 69
 			),
70 70
 			true
71 71
 		);
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
 	 * @param  \WP_REST_Request $request Full details about the request.
78 78
 	 * @return \WP_Error|boolean
79 79
 	 */
80
-	public function get_items_permissions_check( $request ) {
81
-		if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'read' ) ) {
82
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
80
+	public function get_items_permissions_check($request) {
81
+		if ( ! wc_rest_check_manager_permissions('payment_gateways', 'read')) {
82
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
83 83
 		}
84 84
 		return true;
85 85
 	}
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 	 * @param  \WP_REST_Request $request Full details about the request.
91 91
 	 * @return \WP_Error|boolean
92 92
 	 */
93
-	public function get_item_permissions_check( $request ) {
94
-		if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'read' ) ) {
95
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
93
+	public function get_item_permissions_check($request) {
94
+		if ( ! wc_rest_check_manager_permissions('payment_gateways', 'read')) {
95
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
96 96
 		}
97 97
 		return true;
98 98
 	}
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
 	 * @param  \WP_REST_Request $request Full details about the request.
104 104
 	 * @return \WP_Error|boolean
105 105
 	 */
106
-	public function update_items_permissions_check( $request ) {
107
-		if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'edit' ) ) {
108
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
106
+	public function update_items_permissions_check($request) {
107
+		if ( ! wc_rest_check_manager_permissions('payment_gateways', 'edit')) {
108
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
109 109
 		}
110 110
 		return true;
111 111
 	}
@@ -116,16 +116,16 @@  discard block
 block discarded – undo
116 116
 	 * @param \WP_REST_Request $request Full details about the request.
117 117
 	 * @return \WP_Error\WP_REST_Response
118 118
 	 */
119
-	public function get_items( $request ) {
119
+	public function get_items($request) {
120 120
 		$payment_gateways = WC()->payment_gateways->payment_gateways();
121 121
 		$response         = array();
122
-		foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) {
122
+		foreach ($payment_gateways as $payment_gateway_id => $payment_gateway) {
123 123
 			$payment_gateway->id = $payment_gateway_id;
124
-			$gateway             = $this->prepare_item_for_response( $payment_gateway, $request );
125
-			$gateway             = $this->prepare_response_for_collection( $gateway );
124
+			$gateway             = $this->prepare_item_for_response($payment_gateway, $request);
125
+			$gateway             = $this->prepare_response_for_collection($gateway);
126 126
 			$response[]          = $gateway;
127 127
 		}
128
-		return rest_ensure_response( $response );
128
+		return rest_ensure_response($response);
129 129
 	}
130 130
 
131 131
 	/**
@@ -134,15 +134,15 @@  discard block
 block discarded – undo
134 134
 	 * @param \WP_REST_Request $request Request data.
135 135
 	 * @return \WP_REST_Response|\WP_Error
136 136
 	 */
137
-	public function get_item( $request ) {
138
-		$gateway = $this->get_gateway( $request );
137
+	public function get_item($request) {
138
+		$gateway = $this->get_gateway($request);
139 139
 
140
-		if ( is_null( $gateway ) ) {
141
-			return new \WP_Error( 'woocommerce_rest_payment_gateway_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
140
+		if (is_null($gateway)) {
141
+			return new \WP_Error('woocommerce_rest_payment_gateway_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
142 142
 		}
143 143
 
144
-		$gateway = $this->prepare_item_for_response( $gateway, $request );
145
-		return rest_ensure_response( $gateway );
144
+		$gateway = $this->prepare_item_for_response($gateway, $request);
145
+		return rest_ensure_response($gateway);
146 146
 	}
147 147
 
148 148
 	/**
@@ -151,11 +151,11 @@  discard block
 block discarded – undo
151 151
 	 * @param \WP_REST_Request $request Request data.
152 152
 	 * @return \WP_REST_Response|\WP_Error
153 153
 	 */
154
-	public function update_item( $request ) {
155
-		$gateway = $this->get_gateway( $request );
154
+	public function update_item($request) {
155
+		$gateway = $this->get_gateway($request);
156 156
 
157
-		if ( is_null( $gateway ) ) {
158
-			return new \WP_Error( 'woocommerce_rest_payment_gateway_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
157
+		if (is_null($gateway)) {
158
+			return new \WP_Error('woocommerce_rest_payment_gateway_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
159 159
 		}
160 160
 
161 161
 		// Get settings.
@@ -163,60 +163,60 @@  discard block
 block discarded – undo
163 163
 		$settings = $gateway->settings;
164 164
 
165 165
 		// Update settings.
166
-		if ( isset( $request['settings'] ) ) {
166
+		if (isset($request['settings'])) {
167 167
 			$errors_found = false;
168
-			foreach ( $gateway->form_fields as $key => $field ) {
169
-				if ( isset( $request['settings'][ $key ] ) ) {
170
-					if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) {
171
-						$value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field );
168
+			foreach ($gateway->form_fields as $key => $field) {
169
+				if (isset($request['settings'][$key])) {
170
+					if (is_callable(array($this, 'validate_setting_' . $field['type'] . '_field'))) {
171
+						$value = $this->{'validate_setting_' . $field['type'] . '_field'}($request['settings'][$key], $field);
172 172
 					} else {
173
-						$value = $this->validate_setting_text_field( $request['settings'][ $key ], $field );
173
+						$value = $this->validate_setting_text_field($request['settings'][$key], $field);
174 174
 					}
175
-					if ( is_wp_error( $value ) ) {
175
+					if (is_wp_error($value)) {
176 176
 						$errors_found = true;
177 177
 						break;
178 178
 					}
179
-					$settings[ $key ] = $value;
179
+					$settings[$key] = $value;
180 180
 				}
181 181
 			}
182 182
 
183
-			if ( $errors_found ) {
184
-				return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) );
183
+			if ($errors_found) {
184
+				return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400));
185 185
 			}
186 186
 		}
187 187
 
188 188
 		// Update if this method is enabled or not.
189
-		if ( isset( $request['enabled'] ) ) {
190
-			$settings['enabled'] = wc_bool_to_string( $request['enabled'] );
189
+		if (isset($request['enabled'])) {
190
+			$settings['enabled'] = wc_bool_to_string($request['enabled']);
191 191
 			$gateway->enabled    = $settings['enabled'];
192 192
 		}
193 193
 
194 194
 		// Update title.
195
-		if ( isset( $request['title'] ) ) {
195
+		if (isset($request['title'])) {
196 196
 			$settings['title'] = $request['title'];
197 197
 			$gateway->title    = $settings['title'];
198 198
 		}
199 199
 
200 200
 		// Update description.
201
-		if ( isset( $request['description'] ) ) {
201
+		if (isset($request['description'])) {
202 202
 			$settings['description'] = $request['description'];
203 203
 			$gateway->description    = $settings['description'];
204 204
 		}
205 205
 
206 206
 		// Update options.
207 207
 		$gateway->settings = $settings;
208
-		update_option( $gateway->get_option_key(), apply_filters( 'woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway ) );
208
+		update_option($gateway->get_option_key(), apply_filters('woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway));
209 209
 
210 210
 		// Update order.
211
-		if ( isset( $request['order'] ) ) {
212
-			$order                 = (array) get_option( 'woocommerce_gateway_order' );
213
-			$order[ $gateway->id ] = $request['order'];
214
-			update_option( 'woocommerce_gateway_order', $order );
215
-			$gateway->order = absint( $request['order'] );
211
+		if (isset($request['order'])) {
212
+			$order                 = (array) get_option('woocommerce_gateway_order');
213
+			$order[$gateway->id] = $request['order'];
214
+			update_option('woocommerce_gateway_order', $order);
215
+			$gateway->order = absint($request['order']);
216 216
 		}
217 217
 
218
-		$gateway = $this->prepare_item_for_response( $gateway, $request );
219
-		return rest_ensure_response( $gateway );
218
+		$gateway = $this->prepare_item_for_response($gateway, $request);
219
+		return rest_ensure_response($gateway);
220 220
 	}
221 221
 
222 222
 	/**
@@ -225,11 +225,11 @@  discard block
 block discarded – undo
225 225
 	 * @param \WP_REST_Request $request Request data.
226 226
 	 * @return \WP_REST_Response|null
227 227
 	 */
228
-	public function get_gateway( $request ) {
228
+	public function get_gateway($request) {
229 229
 		$gateway          = null;
230 230
 		$payment_gateways = WC()->payment_gateways->payment_gateways();
231
-		foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) {
232
-			if ( $request['id'] !== $payment_gateway_id ) {
231
+		foreach ($payment_gateways as $payment_gateway_id => $payment_gateway) {
232
+			if ($request['id'] !== $payment_gateway_id) {
233 233
 				continue;
234 234
 			}
235 235
 			$payment_gateway->id = $payment_gateway_id;
@@ -245,26 +245,26 @@  discard block
 block discarded – undo
245 245
 	 * @param  \WP_REST_Request    $request    Request object.
246 246
 	 * @return \WP_REST_Response   $response   Response data.
247 247
 	 */
248
-	public function prepare_item_for_response( $gateway, $request ) {
249
-		$order = (array) get_option( 'woocommerce_gateway_order' );
248
+	public function prepare_item_for_response($gateway, $request) {
249
+		$order = (array) get_option('woocommerce_gateway_order');
250 250
 		$item  = array(
251 251
 			'id'                 => $gateway->id,
252 252
 			'title'              => $gateway->title,
253 253
 			'description'        => $gateway->description,
254
-			'order'              => isset( $order[ $gateway->id ] ) ? $order[ $gateway->id ] : '',
255
-			'enabled'            => ( 'yes' === $gateway->enabled ),
254
+			'order'              => isset($order[$gateway->id]) ? $order[$gateway->id] : '',
255
+			'enabled'            => ('yes' === $gateway->enabled),
256 256
 			'method_title'       => $gateway->get_method_title(),
257 257
 			'method_description' => $gateway->get_method_description(),
258 258
 			'method_supports'    => $gateway->supports,
259
-			'settings'           => $this->get_settings( $gateway ),
259
+			'settings'           => $this->get_settings($gateway),
260 260
 		);
261 261
 
262
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
263
-		$data    = $this->add_additional_fields_to_object( $item, $request );
264
-		$data    = $this->filter_response_by_context( $data, $context );
262
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
263
+		$data    = $this->add_additional_fields_to_object($item, $request);
264
+		$data    = $this->filter_response_by_context($data, $context);
265 265
 
266
-		$response = rest_ensure_response( $data );
267
-		$response->add_links( $this->prepare_links( $gateway, $request ) );
266
+		$response = rest_ensure_response($data);
267
+		$response->add_links($this->prepare_links($gateway, $request));
268 268
 
269 269
 		/**
270 270
 		 * Filter payment gateway objects returned from the REST API.
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 		 * @param WC_Payment_Gateway $gateway  Payment gateway object.
274 274
 		 * @param \WP_REST_Request    $request  Request object.
275 275
 		 */
276
-		return apply_filters( 'woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request );
276
+		return apply_filters('woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request);
277 277
 	}
278 278
 
279 279
 	/**
@@ -283,34 +283,34 @@  discard block
 block discarded – undo
283 283
 	 *
284 284
 	 * @return array
285 285
 	 */
286
-	public function get_settings( $gateway ) {
286
+	public function get_settings($gateway) {
287 287
 		$settings = array();
288 288
 		$gateway->init_form_fields();
289
-		foreach ( $gateway->form_fields as $id => $field ) {
289
+		foreach ($gateway->form_fields as $id => $field) {
290 290
 			// Make sure we at least have a title and type.
291
-			if ( empty( $field['title'] ) || empty( $field['type'] ) ) {
291
+			if (empty($field['title']) || empty($field['type'])) {
292 292
 				continue;
293 293
 			}
294 294
 
295 295
 			// Ignore 'enabled' and 'description' which get included elsewhere.
296
-			if ( in_array( $id, array( 'enabled', 'description' ), true ) ) {
296
+			if (in_array($id, array('enabled', 'description'), true)) {
297 297
 				continue;
298 298
 			}
299 299
 
300 300
 			$data = array(
301 301
 				'id'          => $id,
302
-				'label'       => empty( $field['label'] ) ? $field['title'] : $field['label'],
303
-				'description' => empty( $field['description'] ) ? '' : $field['description'],
302
+				'label'       => empty($field['label']) ? $field['title'] : $field['label'],
303
+				'description' => empty($field['description']) ? '' : $field['description'],
304 304
 				'type'        => $field['type'],
305
-				'value'       => empty( $gateway->settings[ $id ] ) ? '' : $gateway->settings[ $id ],
306
-				'default'     => empty( $field['default'] ) ? '' : $field['default'],
307
-				'tip'         => empty( $field['description'] ) ? '' : $field['description'],
308
-				'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'],
305
+				'value'       => empty($gateway->settings[$id]) ? '' : $gateway->settings[$id],
306
+				'default'     => empty($field['default']) ? '' : $field['default'],
307
+				'tip'         => empty($field['description']) ? '' : $field['description'],
308
+				'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'],
309 309
 			);
310
-			if ( ! empty( $field['options'] ) ) {
310
+			if ( ! empty($field['options'])) {
311 311
 				$data['options'] = $field['options'];
312 312
 			}
313
-			$settings[ $id ] = $data;
313
+			$settings[$id] = $data;
314 314
 		}
315 315
 		return $settings;
316 316
 	}
@@ -322,13 +322,13 @@  discard block
 block discarded – undo
322 322
 	 * @param  \WP_REST_Request    $request    Request object.
323 323
 	 * @return array
324 324
 	 */
325
-	protected function prepare_links( $gateway, $request ) {
325
+	protected function prepare_links($gateway, $request) {
326 326
 		$links = array(
327 327
 			'self'       => array(
328
-				'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $gateway->id ) ),
328
+				'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $gateway->id)),
329 329
 			),
330 330
 			'collection' => array(
331
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
331
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
332 332
 			),
333 333
 		);
334 334
 
@@ -347,106 +347,106 @@  discard block
 block discarded – undo
347 347
 			'type'       => 'object',
348 348
 			'properties' => array(
349 349
 				'id'                 => array(
350
-					'description' => __( 'Payment gateway ID.', 'woocommerce' ),
350
+					'description' => __('Payment gateway ID.', 'woocommerce'),
351 351
 					'type'        => 'string',
352
-					'context'     => array( 'view', 'edit' ),
352
+					'context'     => array('view', 'edit'),
353 353
 					'readonly'    => true,
354 354
 				),
355 355
 				'title'              => array(
356
-					'description' => __( 'Payment gateway title on checkout.', 'woocommerce' ),
356
+					'description' => __('Payment gateway title on checkout.', 'woocommerce'),
357 357
 					'type'        => 'string',
358
-					'context'     => array( 'view', 'edit' ),
358
+					'context'     => array('view', 'edit'),
359 359
 				),
360 360
 				'description'        => array(
361
-					'description' => __( 'Payment gateway description on checkout.', 'woocommerce' ),
361
+					'description' => __('Payment gateway description on checkout.', 'woocommerce'),
362 362
 					'type'        => 'string',
363
-					'context'     => array( 'view', 'edit' ),
363
+					'context'     => array('view', 'edit'),
364 364
 				),
365 365
 				'order'              => array(
366
-					'description' => __( 'Payment gateway sort order.', 'woocommerce' ),
366
+					'description' => __('Payment gateway sort order.', 'woocommerce'),
367 367
 					'type'        => 'integer',
368
-					'context'     => array( 'view', 'edit' ),
368
+					'context'     => array('view', 'edit'),
369 369
 					'arg_options' => array(
370 370
 						'sanitize_callback' => 'absint',
371 371
 					),
372 372
 				),
373 373
 				'enabled'            => array(
374
-					'description' => __( 'Payment gateway enabled status.', 'woocommerce' ),
374
+					'description' => __('Payment gateway enabled status.', 'woocommerce'),
375 375
 					'type'        => 'boolean',
376
-					'context'     => array( 'view', 'edit' ),
376
+					'context'     => array('view', 'edit'),
377 377
 				),
378 378
 				'method_title'       => array(
379
-					'description' => __( 'Payment gateway method title.', 'woocommerce' ),
379
+					'description' => __('Payment gateway method title.', 'woocommerce'),
380 380
 					'type'        => 'string',
381
-					'context'     => array( 'view', 'edit' ),
381
+					'context'     => array('view', 'edit'),
382 382
 					'readonly'    => true,
383 383
 				),
384 384
 				'method_description' => array(
385
-					'description' => __( 'Payment gateway method description.', 'woocommerce' ),
385
+					'description' => __('Payment gateway method description.', 'woocommerce'),
386 386
 					'type'        => 'string',
387
-					'context'     => array( 'view', 'edit' ),
387
+					'context'     => array('view', 'edit'),
388 388
 					'readonly'    => true,
389 389
 				),
390 390
 				'method_supports'    => array(
391
-					'description' => __( 'Supported features for this payment gateway.', 'woocommerce' ),
391
+					'description' => __('Supported features for this payment gateway.', 'woocommerce'),
392 392
 					'type'        => 'array',
393
-					'context'     => array( 'view', 'edit' ),
393
+					'context'     => array('view', 'edit'),
394 394
 					'readonly'    => true,
395 395
 					'items'       => array(
396 396
 						'type' => 'string',
397 397
 					),
398 398
 				),
399 399
 				'settings'           => array(
400
-					'description' => __( 'Payment gateway settings.', 'woocommerce' ),
400
+					'description' => __('Payment gateway settings.', 'woocommerce'),
401 401
 					'type'        => 'object',
402
-					'context'     => array( 'view', 'edit' ),
402
+					'context'     => array('view', 'edit'),
403 403
 					'properties'  => array(
404 404
 						'id'          => array(
405
-							'description' => __( 'A unique identifier for the setting.', 'woocommerce' ),
405
+							'description' => __('A unique identifier for the setting.', 'woocommerce'),
406 406
 							'type'        => 'string',
407
-							'context'     => array( 'view', 'edit' ),
407
+							'context'     => array('view', 'edit'),
408 408
 							'readonly'    => true,
409 409
 						),
410 410
 						'label'       => array(
411
-							'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ),
411
+							'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'),
412 412
 							'type'        => 'string',
413
-							'context'     => array( 'view', 'edit' ),
413
+							'context'     => array('view', 'edit'),
414 414
 							'readonly'    => true,
415 415
 						),
416 416
 						'description' => array(
417
-							'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ),
417
+							'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'),
418 418
 							'type'        => 'string',
419
-							'context'     => array( 'view', 'edit' ),
419
+							'context'     => array('view', 'edit'),
420 420
 							'readonly'    => true,
421 421
 						),
422 422
 						'type'        => array(
423
-							'description' => __( 'Type of setting.', 'woocommerce' ),
423
+							'description' => __('Type of setting.', 'woocommerce'),
424 424
 							'type'        => 'string',
425
-							'context'     => array( 'view', 'edit' ),
426
-							'enum'        => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ),
425
+							'context'     => array('view', 'edit'),
426
+							'enum'        => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'),
427 427
 							'readonly'    => true,
428 428
 						),
429 429
 						'value'       => array(
430
-							'description' => __( 'Setting value.', 'woocommerce' ),
430
+							'description' => __('Setting value.', 'woocommerce'),
431 431
 							'type'        => 'string',
432
-							'context'     => array( 'view', 'edit' ),
432
+							'context'     => array('view', 'edit'),
433 433
 						),
434 434
 						'default'     => array(
435
-							'description' => __( 'Default value for the setting.', 'woocommerce' ),
435
+							'description' => __('Default value for the setting.', 'woocommerce'),
436 436
 							'type'        => 'string',
437
-							'context'     => array( 'view', 'edit' ),
437
+							'context'     => array('view', 'edit'),
438 438
 							'readonly'    => true,
439 439
 						),
440 440
 						'tip'         => array(
441
-							'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ),
441
+							'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'),
442 442
 							'type'        => 'string',
443
-							'context'     => array( 'view', 'edit' ),
443
+							'context'     => array('view', 'edit'),
444 444
 							'readonly'    => true,
445 445
 						),
446 446
 						'placeholder' => array(
447
-							'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ),
447
+							'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'),
448 448
 							'type'        => 'string',
449
-							'context'     => array( 'view', 'edit' ),
449
+							'context'     => array('view', 'edit'),
450 450
 							'readonly'    => true,
451 451
 						),
452 452
 					),
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 			),
455 455
 		);
456 456
 
457
-		return $this->add_additional_fields_schema( $schema );
457
+		return $this->add_additional_fields_schema($schema);
458 458
 	}
459 459
 
460 460
 	/**
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 	 */
465 465
 	public function get_collection_params() {
466 466
 		return array(
467
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
467
+			'context' => $this->get_context_param(array('default' => 'view')),
468 468
 		);
469 469
 	}
470 470
 
Please login to merge, or discard this patch.
src/Controllers/Version4/ProductVariations.php 1 patch
Spacing   +358 added lines, -358 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
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 variations controller class.
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 * Initialize product actions (parent).
35 35
 	 */
36 36
 	public function __construct() {
37
-		add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'add_product_id' ), 9, 2 );
37
+		add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'add_product_id'), 9, 2);
38 38
 		parent::__construct();
39 39
 	}
40 40
 
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
 			array(
49 49
 				'args'   => array(
50 50
 					'product_id' => array(
51
-						'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
51
+						'description' => __('Unique identifier for the variable product.', 'woocommerce'),
52 52
 						'type'        => 'integer',
53 53
 					),
54 54
 				),
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
 		);
@@ -74,18 +74,18 @@  discard block
 block discarded – undo
74 74
 			array(
75 75
 				'args'   => array(
76 76
 					'product_id' => array(
77
-						'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
77
+						'description' => __('Unique identifier for the variable product.', 'woocommerce'),
78 78
 						'type'        => 'integer',
79 79
 					),
80 80
 					'id'         => array(
81
-						'description' => __( 'Unique identifier for the variation.', 'woocommerce' ),
81
+						'description' => __('Unique identifier for the variation.', 'woocommerce'),
82 82
 						'type'        => 'integer',
83 83
 					),
84 84
 				),
85 85
 				array(
86 86
 					'methods'             => \WP_REST_Server::READABLE,
87
-					'callback'            => array( $this, 'get_item' ),
88
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
87
+					'callback'            => array($this, 'get_item'),
88
+					'permission_callback' => array($this, 'get_item_permissions_check'),
89 89
 					'args'                => array(
90 90
 						'context' => $this->get_context_param(
91 91
 							array(
@@ -96,23 +96,23 @@  discard block
 block discarded – undo
96 96
 				),
97 97
 				array(
98 98
 					'methods'             => \WP_REST_Server::EDITABLE,
99
-					'callback'            => array( $this, 'update_item' ),
100
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
101
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
99
+					'callback'            => array($this, 'update_item'),
100
+					'permission_callback' => array($this, 'update_item_permissions_check'),
101
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
102 102
 				),
103 103
 				array(
104 104
 					'methods'             => \WP_REST_Server::DELETABLE,
105
-					'callback'            => array( $this, 'delete_item' ),
106
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
105
+					'callback'            => array($this, 'delete_item'),
106
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
107 107
 					'args'                => array(
108 108
 						'force' => array(
109 109
 							'default'     => false,
110 110
 							'type'        => 'boolean',
111
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
111
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
112 112
 						),
113 113
 					),
114 114
 				),
115
-				'schema' => array( $this, 'get_public_item_schema' ),
115
+				'schema' => array($this, 'get_public_item_schema'),
116 116
 			),
117 117
 			true
118 118
 		);
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
 			array(
122 122
 				'args'   => array(
123 123
 					'product_id' => array(
124
-						'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
124
+						'description' => __('Unique identifier for the variable product.', 'woocommerce'),
125 125
 						'type'        => 'integer',
126 126
 					),
127 127
 				),
128 128
 				array(
129 129
 					'methods'             => \WP_REST_Server::EDITABLE,
130
-					'callback'            => array( $this, 'batch_items' ),
131
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
132
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
130
+					'callback'            => array($this, 'batch_items'),
131
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
132
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
133 133
 				),
134
-				'schema' => array( $this, 'get_public_batch_schema' ),
134
+				'schema' => array($this, 'get_public_batch_schema'),
135 135
 			),
136 136
 			true
137 137
 		);
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 	 * @param  int $id Object ID.
145 145
 	 * @return WC_Data
146 146
 	 */
147
-	protected function get_object( $id ) {
148
-		return wc_get_product( $id );
147
+	protected function get_object($id) {
148
+		return wc_get_product($id);
149 149
 	}
150 150
 
151 151
 	/**
@@ -154,16 +154,16 @@  discard block
 block discarded – undo
154 154
 	 * @param  \WP_REST_Request $request Full details about the request.
155 155
 	 * @return \WP_Error|boolean
156 156
 	 */
157
-	public function update_item_permissions_check( $request ) {
158
-		$object = $this->get_object( (int) $request['id'] );
157
+	public function update_item_permissions_check($request) {
158
+		$object = $this->get_object((int) $request['id']);
159 159
 
160
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) {
161
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
160
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'edit', $object->get_id())) {
161
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
162 162
 		}
163 163
 
164 164
 		// Check if variation belongs to the correct parent product.
165
-		if ( $object && 0 !== $object->get_parent_id() && absint( $request['product_id'] ) !== $object->get_parent_id() ) {
166
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Parent product does not match current variation.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
165
+		if ($object && 0 !== $object->get_parent_id() && absint($request['product_id']) !== $object->get_parent_id()) {
166
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Parent product does not match current variation.', 'woocommerce'), array('status' => rest_authorization_required_code()));
167 167
 		}
168 168
 
169 169
 		return true;
@@ -176,33 +176,33 @@  discard block
 block discarded – undo
176 176
 	 * @param  \WP_REST_Request $request Request object.
177 177
 	 * @return \WP_REST_Response
178 178
 	 */
179
-	public function prepare_object_for_response( $object, $request ) {
180
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
179
+	public function prepare_object_for_response($object, $request) {
180
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
181 181
 		$data    = array(
182 182
 			'id'                    => $object->get_id(),
183
-			'name'                  => $object->get_name( $context ),
183
+			'name'                  => $object->get_name($context),
184 184
 			'type'                  => $object->get_type(),
185
-			'parent_id'             => $object->get_parent_id( $context ),
186
-			'date_created'          => wc_rest_prepare_date_response( $object->get_date_created(), false ),
187
-			'date_created_gmt'      => wc_rest_prepare_date_response( $object->get_date_created() ),
188
-			'date_modified'         => wc_rest_prepare_date_response( $object->get_date_modified(), false ),
189
-			'date_modified_gmt'     => wc_rest_prepare_date_response( $object->get_date_modified() ),
190
-			'description'           => wc_format_content( $object->get_description() ),
185
+			'parent_id'             => $object->get_parent_id($context),
186
+			'date_created'          => wc_rest_prepare_date_response($object->get_date_created(), false),
187
+			'date_created_gmt'      => wc_rest_prepare_date_response($object->get_date_created()),
188
+			'date_modified'         => wc_rest_prepare_date_response($object->get_date_modified(), false),
189
+			'date_modified_gmt'     => wc_rest_prepare_date_response($object->get_date_modified()),
190
+			'description'           => wc_format_content($object->get_description()),
191 191
 			'permalink'             => $object->get_permalink(),
192 192
 			'sku'                   => $object->get_sku(),
193 193
 			'price'                 => $object->get_price(),
194 194
 			'regular_price'         => $object->get_regular_price(),
195 195
 			'sale_price'            => $object->get_sale_price(),
196
-			'date_on_sale_from'     => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ),
197
-			'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ),
198
-			'date_on_sale_to'       => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ),
199
-			'date_on_sale_to_gmt'   => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ),
196
+			'date_on_sale_from'     => wc_rest_prepare_date_response($object->get_date_on_sale_from(), false),
197
+			'date_on_sale_from_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_from()),
198
+			'date_on_sale_to'       => wc_rest_prepare_date_response($object->get_date_on_sale_to(), false),
199
+			'date_on_sale_to_gmt'   => wc_rest_prepare_date_response($object->get_date_on_sale_to()),
200 200
 			'on_sale'               => $object->is_on_sale(),
201 201
 			'status'                => $object->get_status(),
202 202
 			'purchasable'           => $object->is_purchasable(),
203 203
 			'virtual'               => $object->is_virtual(),
204 204
 			'downloadable'          => $object->is_downloadable(),
205
-			'downloads'             => $this->get_downloads( $object ),
205
+			'downloads'             => $this->get_downloads($object),
206 206
 			'download_limit'        => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1,
207 207
 			'download_expiry'       => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1,
208 208
 			'tax_status'            => $object->get_tax_status(),
@@ -221,17 +221,17 @@  discard block
 block discarded – undo
221 221
 			),
222 222
 			'shipping_class'        => $object->get_shipping_class(),
223 223
 			'shipping_class_id'     => $object->get_shipping_class_id(),
224
-			'image'                 => $this->get_image( $object ),
225
-			'attributes'            => $this->get_attributes( $object ),
224
+			'image'                 => $this->get_image($object),
225
+			'attributes'            => $this->get_attributes($object),
226 226
 			'menu_order'            => $object->get_menu_order(),
227 227
 			'meta_data'             => $object->get_meta_data(),
228 228
 		);
229 229
 
230
-		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
231
-		$data     = $this->add_additional_fields_to_object( $data, $request );
232
-		$data     = $this->filter_response_by_context( $data, $context );
233
-		$response = rest_ensure_response( $data );
234
-		$response->add_links( $this->prepare_links( $object, $request ) );
230
+		$context  = ! empty($request['context']) ? $request['context'] : 'view';
231
+		$data     = $this->add_additional_fields_to_object($data, $request);
232
+		$data     = $this->filter_response_by_context($data, $context);
233
+		$response = rest_ensure_response($data);
234
+		$response->add_links($this->prepare_links($object, $request));
235 235
 
236 236
 		/**
237 237
 		 * Filter the data for a response.
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 		 * @param WC_Data          $object   Object data.
244 244
 		 * @param \WP_REST_Request  $request  Request object.
245 245
 		 */
246
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
246
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request);
247 247
 	}
248 248
 
249 249
 	/**
@@ -252,32 +252,32 @@  discard block
 block discarded – undo
252 252
 	 * @param WC_Product_Variation $variation Variation data.
253 253
 	 * @return array
254 254
 	 */
255
-	protected function get_image( $variation ) {
256
-		if ( ! $variation->get_image_id() ) {
255
+	protected function get_image($variation) {
256
+		if ( ! $variation->get_image_id()) {
257 257
 			return;
258 258
 		}
259 259
 
260 260
 		$attachment_id   = $variation->get_image_id();
261
-		$attachment_post = get_post( $attachment_id );
262
-		if ( is_null( $attachment_post ) ) {
261
+		$attachment_post = get_post($attachment_id);
262
+		if (is_null($attachment_post)) {
263 263
 			return;
264 264
 		}
265 265
 
266
-		$attachment = wp_get_attachment_image_src( $attachment_id, 'full' );
267
-		if ( ! is_array( $attachment ) ) {
266
+		$attachment = wp_get_attachment_image_src($attachment_id, 'full');
267
+		if ( ! is_array($attachment)) {
268 268
 			return;
269 269
 		}
270 270
 
271
-		if ( ! isset( $image ) ) {
271
+		if ( ! isset($image)) {
272 272
 			return array(
273 273
 				'id'                => (int) $attachment_id,
274
-				'date_created'      => wc_rest_prepare_date_response( $attachment_post->post_date, false ),
275
-				'date_created_gmt'  => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ),
276
-				'date_modified'     => wc_rest_prepare_date_response( $attachment_post->post_modified, false ),
277
-				'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ),
278
-				'src'               => current( $attachment ),
279
-				'name'              => get_the_title( $attachment_id ),
280
-				'alt'               => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
274
+				'date_created'      => wc_rest_prepare_date_response($attachment_post->post_date, false),
275
+				'date_created_gmt'  => wc_rest_prepare_date_response(strtotime($attachment_post->post_date_gmt)),
276
+				'date_modified'     => wc_rest_prepare_date_response($attachment_post->post_modified, false),
277
+				'date_modified_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_modified_gmt)),
278
+				'src'               => current($attachment),
279
+				'name'              => get_the_title($attachment_id),
280
+				'alt'               => get_post_meta($attachment_id, '_wp_attachment_image_alt', true),
281 281
 			);
282 282
 		}
283 283
 	}
@@ -291,35 +291,35 @@  discard block
 block discarded – undo
291 291
 	 * @param  array                 $image     Image data.
292 292
 	 * @return WC_Product_Variation
293 293
 	 */
294
-	protected function set_variation_image( $variation, $image ) {
295
-		$attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0;
294
+	protected function set_variation_image($variation, $image) {
295
+		$attachment_id = isset($image['id']) ? absint($image['id']) : 0;
296 296
 
297
-		if ( 0 === $attachment_id && isset( $image['src'] ) ) {
298
-			$upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) );
297
+		if (0 === $attachment_id && isset($image['src'])) {
298
+			$upload = wc_rest_upload_image_from_url(esc_url_raw($image['src']));
299 299
 
300
-			if ( is_wp_error( $upload ) ) {
301
-				if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array( $image ) ) ) {
302
-					throw new \WC_REST_Exception( 'woocommerce_variation_image_upload_error', $upload->get_error_message(), 400 );
300
+			if (is_wp_error($upload)) {
301
+				if ( ! apply_filters('woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array($image))) {
302
+					throw new \WC_REST_Exception('woocommerce_variation_image_upload_error', $upload->get_error_message(), 400);
303 303
 				}
304 304
 			}
305 305
 
306
-			$attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $variation->get_id() );
306
+			$attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $variation->get_id());
307 307
 		}
308 308
 
309
-		if ( ! wp_attachment_is_image( $attachment_id ) ) {
309
+		if ( ! wp_attachment_is_image($attachment_id)) {
310 310
 			/* translators: %s: attachment ID */
311
-			throw new \WC_REST_Exception( 'woocommerce_variation_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 );
311
+			throw new \WC_REST_Exception('woocommerce_variation_invalid_image_id', sprintf(__('#%s is an invalid image ID.', 'woocommerce'), $attachment_id), 400);
312 312
 		}
313 313
 
314
-		$variation->set_image_id( $attachment_id );
314
+		$variation->set_image_id($attachment_id);
315 315
 
316 316
 		// Set the image alt if present.
317
-		if ( ! empty( $image['alt'] ) ) {
318
-			update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) );
317
+		if ( ! empty($image['alt'])) {
318
+			update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt']));
319 319
 		}
320 320
 
321 321
 		// Set the image name if present.
322
-		if ( ! empty( $image['name'] ) ) {
322
+		if ( ! empty($image['name'])) {
323 323
 			wp_update_post(
324 324
 				array(
325 325
 					'ID'         => $attachment_id,
@@ -338,17 +338,17 @@  discard block
 block discarded – undo
338 338
 	 * @param  \WP_REST_Request $request Full details about the request.
339 339
 	 * @return array
340 340
 	 */
341
-	protected function prepare_objects_query( $request ) {
342
-		$args = parent::prepare_objects_query( $request );
341
+	protected function prepare_objects_query($request) {
342
+		$args = parent::prepare_objects_query($request);
343 343
 
344 344
 		// Set post_status.
345 345
 		$args['post_status'] = $request['status'];
346 346
 
347 347
 		// Filter by sku.
348
-		if ( ! empty( $request['sku'] ) ) {
349
-			$skus = explode( ',', $request['sku'] );
348
+		if ( ! empty($request['sku'])) {
349
+			$skus = explode(',', $request['sku']);
350 350
 			// Include the current string as a SKU too.
351
-			if ( 1 < count( $skus ) ) {
351
+			if (1 < count($skus)) {
352 352
 				$skus[] = $request['sku'];
353 353
 			}
354 354
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 		}
364 364
 
365 365
 		// Filter by tax class.
366
-		if ( ! empty( $request['tax_class'] ) ) {
366
+		if ( ! empty($request['tax_class'])) {
367 367
 			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
368 368
 				$args,
369 369
 				array(
@@ -374,12 +374,12 @@  discard block
 block discarded – undo
374 374
 		}
375 375
 
376 376
 		// Price filter.
377
-		if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) {
378
-			$args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) );  // WPCS: slow query ok.
377
+		if ( ! empty($request['min_price']) || ! empty($request['max_price'])) {
378
+			$args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request)); // WPCS: slow query ok.
379 379
 		}
380 380
 
381 381
 		// Filter product based on stock_status.
382
-		if ( ! empty( $request['stock_status'] ) ) {
382
+		if ( ! empty($request['stock_status'])) {
383 383
 			$args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok.
384 384
 				$args,
385 385
 				array(
@@ -390,28 +390,28 @@  discard block
 block discarded – undo
390 390
 		}
391 391
 
392 392
 		// Filter by on sale products.
393
-		if ( is_bool( $request['on_sale'] ) ) {
393
+		if (is_bool($request['on_sale'])) {
394 394
 			$on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in';
395 395
 			$on_sale_ids = wc_get_product_ids_on_sale();
396 396
 
397 397
 			// Use 0 when there's no on sale products to avoid return all products.
398
-			$on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids;
398
+			$on_sale_ids = empty($on_sale_ids) ? array(0) : $on_sale_ids;
399 399
 
400
-			$args[ $on_sale_key ] += $on_sale_ids;
400
+			$args[$on_sale_key] += $on_sale_ids;
401 401
 		}
402 402
 
403 403
 		// Force the post_type argument, since it's not a user input variable.
404
-		if ( ! empty( $request['sku'] ) ) {
405
-			$args['post_type'] = array( 'product', 'product_variation' );
404
+		if ( ! empty($request['sku'])) {
405
+			$args['post_type'] = array('product', 'product_variation');
406 406
 		} else {
407 407
 			$args['post_type'] = $this->post_type;
408 408
 		}
409 409
 
410 410
 		$args['post_parent'] = $request['product_id'];
411 411
 
412
-		if ( ! empty( $request['search'] ) ) {
412
+		if ( ! empty($request['search'])) {
413 413
 			$args['search'] = $request['search'];
414
-			unset( $args['s'] );
414
+			unset($args['s']);
415 415
 		}
416 416
 
417 417
 		return $args;
@@ -424,136 +424,136 @@  discard block
 block discarded – undo
424 424
 	 * @param  bool            $creating If is creating a new object.
425 425
 	 * @return \WP_Error|WC_Data
426 426
 	 */
427
-	protected function prepare_object_for_database( $request, $creating = false ) {
428
-		if ( isset( $request['id'] ) ) {
429
-			$variation = wc_get_product( absint( $request['id'] ) );
427
+	protected function prepare_object_for_database($request, $creating = false) {
428
+		if (isset($request['id'])) {
429
+			$variation = wc_get_product(absint($request['id']));
430 430
 		} else {
431 431
 			$variation = new \WC_Product_Variation();
432 432
 		}
433 433
 
434
-		$variation->set_parent_id( absint( $request['product_id'] ) );
434
+		$variation->set_parent_id(absint($request['product_id']));
435 435
 
436 436
 		// Status.
437
-		if ( isset( $request['status'] ) ) {
438
-			$variation->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' );
437
+		if (isset($request['status'])) {
438
+			$variation->set_status(get_post_status_object($request['status']) ? $request['status'] : 'draft');
439 439
 		}
440 440
 
441 441
 		// SKU.
442
-		if ( isset( $request['sku'] ) ) {
443
-			$variation->set_sku( wc_clean( $request['sku'] ) );
442
+		if (isset($request['sku'])) {
443
+			$variation->set_sku(wc_clean($request['sku']));
444 444
 		}
445 445
 
446 446
 		// Thumbnail.
447
-		if ( isset( $request['image'] ) ) {
448
-			if ( is_array( $request['image'] ) ) {
449
-				$variation = $this->set_variation_image( $variation, $request['image'] );
447
+		if (isset($request['image'])) {
448
+			if (is_array($request['image'])) {
449
+				$variation = $this->set_variation_image($variation, $request['image']);
450 450
 			} else {
451
-				$variation->set_image_id( '' );
451
+				$variation->set_image_id('');
452 452
 			}
453 453
 		}
454 454
 
455 455
 		// Virtual variation.
456
-		if ( isset( $request['virtual'] ) ) {
457
-			$variation->set_virtual( $request['virtual'] );
456
+		if (isset($request['virtual'])) {
457
+			$variation->set_virtual($request['virtual']);
458 458
 		}
459 459
 
460 460
 		// Downloadable variation.
461
-		if ( isset( $request['downloadable'] ) ) {
462
-			$variation->set_downloadable( $request['downloadable'] );
461
+		if (isset($request['downloadable'])) {
462
+			$variation->set_downloadable($request['downloadable']);
463 463
 		}
464 464
 
465 465
 		// Downloads.
466
-		if ( $variation->get_downloadable() ) {
466
+		if ($variation->get_downloadable()) {
467 467
 			// Downloadable files.
468
-			if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) {
469
-				$variation = $this->save_downloadable_files( $variation, $request['downloads'] );
468
+			if (isset($request['downloads']) && is_array($request['downloads'])) {
469
+				$variation = $this->save_downloadable_files($variation, $request['downloads']);
470 470
 			}
471 471
 
472 472
 			// Download limit.
473
-			if ( isset( $request['download_limit'] ) ) {
474
-				$variation->set_download_limit( $request['download_limit'] );
473
+			if (isset($request['download_limit'])) {
474
+				$variation->set_download_limit($request['download_limit']);
475 475
 			}
476 476
 
477 477
 			// Download expiry.
478
-			if ( isset( $request['download_expiry'] ) ) {
479
-				$variation->set_download_expiry( $request['download_expiry'] );
478
+			if (isset($request['download_expiry'])) {
479
+				$variation->set_download_expiry($request['download_expiry']);
480 480
 			}
481 481
 		}
482 482
 
483 483
 		// Shipping data.
484
-		$variation = $this->save_product_shipping_data( $variation, $request );
484
+		$variation = $this->save_product_shipping_data($variation, $request);
485 485
 
486 486
 		// Stock handling.
487
-		if ( isset( $request['manage_stock'] ) ) {
488
-			$variation->set_manage_stock( $request['manage_stock'] );
487
+		if (isset($request['manage_stock'])) {
488
+			$variation->set_manage_stock($request['manage_stock']);
489 489
 		}
490 490
 
491
-		if ( isset( $request['stock_status'] ) ) {
492
-			$variation->set_stock_status( $request['stock_status'] );
491
+		if (isset($request['stock_status'])) {
492
+			$variation->set_stock_status($request['stock_status']);
493 493
 		}
494 494
 
495
-		if ( isset( $request['backorders'] ) ) {
496
-			$variation->set_backorders( $request['backorders'] );
495
+		if (isset($request['backorders'])) {
496
+			$variation->set_backorders($request['backorders']);
497 497
 		}
498 498
 
499
-		if ( $variation->get_manage_stock() ) {
500
-			if ( isset( $request['stock_quantity'] ) ) {
501
-				$variation->set_stock_quantity( $request['stock_quantity'] );
502
-			} elseif ( isset( $request['inventory_delta'] ) ) {
503
-				$stock_quantity  = wc_stock_amount( $variation->get_stock_quantity() );
504
-				$stock_quantity += wc_stock_amount( $request['inventory_delta'] );
505
-				$variation->set_stock_quantity( $stock_quantity );
499
+		if ($variation->get_manage_stock()) {
500
+			if (isset($request['stock_quantity'])) {
501
+				$variation->set_stock_quantity($request['stock_quantity']);
502
+			} elseif (isset($request['inventory_delta'])) {
503
+				$stock_quantity  = wc_stock_amount($variation->get_stock_quantity());
504
+				$stock_quantity += wc_stock_amount($request['inventory_delta']);
505
+				$variation->set_stock_quantity($stock_quantity);
506 506
 			}
507 507
 		} else {
508
-			$variation->set_backorders( 'no' );
509
-			$variation->set_stock_quantity( '' );
508
+			$variation->set_backorders('no');
509
+			$variation->set_stock_quantity('');
510 510
 		}
511 511
 
512 512
 		// Regular Price.
513
-		if ( isset( $request['regular_price'] ) ) {
514
-			$variation->set_regular_price( $request['regular_price'] );
513
+		if (isset($request['regular_price'])) {
514
+			$variation->set_regular_price($request['regular_price']);
515 515
 		}
516 516
 
517 517
 		// Sale Price.
518
-		if ( isset( $request['sale_price'] ) ) {
519
-			$variation->set_sale_price( $request['sale_price'] );
518
+		if (isset($request['sale_price'])) {
519
+			$variation->set_sale_price($request['sale_price']);
520 520
 		}
521 521
 
522
-		if ( isset( $request['date_on_sale_from'] ) ) {
523
-			$variation->set_date_on_sale_from( $request['date_on_sale_from'] );
522
+		if (isset($request['date_on_sale_from'])) {
523
+			$variation->set_date_on_sale_from($request['date_on_sale_from']);
524 524
 		}
525 525
 
526
-		if ( isset( $request['date_on_sale_from_gmt'] ) ) {
527
-			$variation->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null );
526
+		if (isset($request['date_on_sale_from_gmt'])) {
527
+			$variation->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null);
528 528
 		}
529 529
 
530
-		if ( isset( $request['date_on_sale_to'] ) ) {
531
-			$variation->set_date_on_sale_to( $request['date_on_sale_to'] );
530
+		if (isset($request['date_on_sale_to'])) {
531
+			$variation->set_date_on_sale_to($request['date_on_sale_to']);
532 532
 		}
533 533
 
534
-		if ( isset( $request['date_on_sale_to_gmt'] ) ) {
535
-			$variation->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null );
534
+		if (isset($request['date_on_sale_to_gmt'])) {
535
+			$variation->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null);
536 536
 		}
537 537
 
538 538
 		// Tax class.
539
-		if ( isset( $request['tax_class'] ) ) {
540
-			$variation->set_tax_class( $request['tax_class'] );
539
+		if (isset($request['tax_class'])) {
540
+			$variation->set_tax_class($request['tax_class']);
541 541
 		}
542 542
 
543 543
 		// Description.
544
-		if ( isset( $request['description'] ) ) {
545
-			$variation->set_description( wp_kses_post( $request['description'] ) );
544
+		if (isset($request['description'])) {
545
+			$variation->set_description(wp_kses_post($request['description']));
546 546
 		}
547 547
 
548 548
 		// Update taxonomies.
549
-		if ( isset( $request['attributes'] ) ) {
549
+		if (isset($request['attributes'])) {
550 550
 			$attributes = array();
551
-			$parent     = wc_get_product( $variation->get_parent_id() );
551
+			$parent     = wc_get_product($variation->get_parent_id());
552 552
 
553
-			if ( ! $parent ) {
553
+			if ( ! $parent) {
554 554
 				return new \WP_Error(
555 555
 					// Translators: %d parent ID.
556
-					"woocommerce_rest_{$this->post_type}_invalid_parent", sprintf( __( 'Cannot set attributes due to invalid parent product.', 'woocommerce' ), $variation->get_parent_id() ), array(
556
+					"woocommerce_rest_{$this->post_type}_invalid_parent", sprintf(__('Cannot set attributes due to invalid parent product.', 'woocommerce'), $variation->get_parent_id()), array(
557 557
 						'status' => 404,
558 558
 					)
559 559
 				);
@@ -561,55 +561,55 @@  discard block
 block discarded – undo
561 561
 
562 562
 			$parent_attributes = $parent->get_attributes();
563 563
 
564
-			foreach ( $request['attributes'] as $attribute ) {
564
+			foreach ($request['attributes'] as $attribute) {
565 565
 				$attribute_id   = 0;
566 566
 				$attribute_name = '';
567 567
 
568 568
 				// Check ID for global attributes or name for product attributes.
569
-				if ( ! empty( $attribute['id'] ) ) {
570
-					$attribute_id   = absint( $attribute['id'] );
571
-					$attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id );
572
-				} elseif ( ! empty( $attribute['name'] ) ) {
573
-					$attribute_name = sanitize_title( $attribute['name'] );
569
+				if ( ! empty($attribute['id'])) {
570
+					$attribute_id   = absint($attribute['id']);
571
+					$attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id);
572
+				} elseif ( ! empty($attribute['name'])) {
573
+					$attribute_name = sanitize_title($attribute['name']);
574 574
 				}
575 575
 
576
-				if ( ! $attribute_id && ! $attribute_name ) {
576
+				if ( ! $attribute_id && ! $attribute_name) {
577 577
 					continue;
578 578
 				}
579 579
 
580
-				if ( ! isset( $parent_attributes[ $attribute_name ] ) || ! $parent_attributes[ $attribute_name ]->get_variation() ) {
580
+				if ( ! isset($parent_attributes[$attribute_name]) || ! $parent_attributes[$attribute_name]->get_variation()) {
581 581
 					continue;
582 582
 				}
583 583
 
584
-				$attribute_key   = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() );
585
-				$attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : '';
584
+				$attribute_key   = sanitize_title($parent_attributes[$attribute_name]->get_name());
585
+				$attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : '';
586 586
 
587
-				if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) {
587
+				if ($parent_attributes[$attribute_name]->is_taxonomy()) {
588 588
 					// If dealing with a taxonomy, we need to get the slug from the name posted to the API.
589
-					$term = get_term_by( 'name', $attribute_value, $attribute_name );
589
+					$term = get_term_by('name', $attribute_value, $attribute_name);
590 590
 
591
-					if ( $term && ! is_wp_error( $term ) ) {
591
+					if ($term && ! is_wp_error($term)) {
592 592
 						$attribute_value = $term->slug;
593 593
 					} else {
594
-						$attribute_value = sanitize_title( $attribute_value );
594
+						$attribute_value = sanitize_title($attribute_value);
595 595
 					}
596 596
 				}
597 597
 
598
-				$attributes[ $attribute_key ] = $attribute_value;
598
+				$attributes[$attribute_key] = $attribute_value;
599 599
 			}
600 600
 
601
-			$variation->set_attributes( $attributes );
601
+			$variation->set_attributes($attributes);
602 602
 		}
603 603
 
604 604
 		// Menu order.
605
-		if ( $request['menu_order'] ) {
606
-			$variation->set_menu_order( $request['menu_order'] );
605
+		if ($request['menu_order']) {
606
+			$variation->set_menu_order($request['menu_order']);
607 607
 		}
608 608
 
609 609
 		// Meta data.
610
-		if ( is_array( $request['meta_data'] ) ) {
611
-			foreach ( $request['meta_data'] as $meta ) {
612
-				$variation->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
610
+		if (is_array($request['meta_data'])) {
611
+			foreach ($request['meta_data'] as $meta) {
612
+				$variation->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
613 613
 			}
614 614
 		}
615 615
 
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
 		 * @param \WP_REST_Request $request   Request object.
624 624
 		 * @param bool            $creating  If is creating a new object.
625 625
 		 */
626
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating );
626
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating);
627 627
 	}
628 628
 
629 629
 	/**
@@ -631,9 +631,9 @@  discard block
 block discarded – undo
631 631
 	 *
632 632
 	 * @param WC_Data $object Object data.
633 633
 	 */
634
-	public function clear_transients( $object ) {
635
-		wc_delete_product_transients( $object->get_parent_id() );
636
-		wp_cache_delete( 'product-' . $object->get_parent_id(), 'products' );
634
+	public function clear_transients($object) {
635
+		wc_delete_product_transients($object->get_parent_id());
636
+		wp_cache_delete('product-' . $object->get_parent_id(), 'products');
637 637
 	}
638 638
 
639 639
 	/**
@@ -643,20 +643,20 @@  discard block
 block discarded – undo
643 643
 	 *
644 644
 	 * @return bool|\WP_Error\WP_REST_Response
645 645
 	 */
646
-	public function delete_item( $request ) {
646
+	public function delete_item($request) {
647 647
 		$force  = (bool) $request['force'];
648
-		$object = $this->get_object( (int) $request['id'] );
648
+		$object = $this->get_object((int) $request['id']);
649 649
 		$result = false;
650 650
 
651
-		if ( ! $object || 0 === $object->get_id() ) {
651
+		if ( ! $object || 0 === $object->get_id()) {
652 652
 			return new \WP_Error(
653
-				"woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array(
653
+				"woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array(
654 654
 					'status' => 404,
655 655
 				)
656 656
 			);
657 657
 		}
658 658
 
659
-		$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) );
659
+		$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable(array($object, 'get_status'));
660 660
 
661 661
 		/**
662 662
 		 * Filter whether an object is trashable.
@@ -666,24 +666,24 @@  discard block
 block discarded – undo
666 666
 		 * @param boolean $supports_trash Whether the object type support trashing.
667 667
 		 * @param WC_Data $object         The object being considered for trashing support.
668 668
 		 */
669
-		$supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object );
669
+		$supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object);
670 670
 
671
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
671
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) {
672 672
 			return new \WP_Error(
673 673
 				/* translators: %s: post type */
674
-				"woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array(
674
+				"woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array(
675 675
 					'status' => rest_authorization_required_code(),
676 676
 				)
677 677
 			);
678 678
 		}
679 679
 
680
-		$request->set_param( 'context', 'edit' );
680
+		$request->set_param('context', 'edit');
681 681
 
682 682
 		// If we're forcing, then delete permanently.
683
-		if ( $force ) {
684
-			$previous = $this->prepare_object_for_response( $object, $request );
683
+		if ($force) {
684
+			$previous = $this->prepare_object_for_response($object, $request);
685 685
 
686
-			$object->delete( true );
686
+			$object->delete(true);
687 687
 
688 688
 			$result   = 0 === $object->get_id();
689 689
 			$response = new \WP_REST_Response();
@@ -695,21 +695,21 @@  discard block
 block discarded – undo
695 695
 			);
696 696
 		} else {
697 697
 			// If we don't support trashing for this type, error out.
698
-			if ( ! $supports_trash ) {
698
+			if ( ! $supports_trash) {
699 699
 				return new \WP_Error(
700 700
 					/* translators: %s: post type */
701
-					'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array(
701
+					'woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array(
702 702
 						'status' => 501,
703 703
 					)
704 704
 				);
705 705
 			}
706 706
 
707 707
 			// Otherwise, only trash if we haven't already.
708
-			if ( is_callable( array( $object, 'get_status' ) ) ) {
709
-				if ( 'trash' === $object->get_status() ) {
708
+			if (is_callable(array($object, 'get_status'))) {
709
+				if ('trash' === $object->get_status()) {
710 710
 					return new \WP_Error(
711 711
 						/* translators: %s: post type */
712
-						'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array(
712
+						'woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array(
713 713
 							'status' => 410,
714 714
 						)
715 715
 					);
@@ -719,13 +719,13 @@  discard block
 block discarded – undo
719 719
 				$result = 'trash' === $object->get_status();
720 720
 			}
721 721
 
722
-			$response = $this->prepare_object_for_response( $object, $request );
722
+			$response = $this->prepare_object_for_response($object, $request);
723 723
 		}
724 724
 
725
-		if ( ! $result ) {
725
+		if ( ! $result) {
726 726
 			return new \WP_Error(
727 727
 				/* translators: %s: post type */
728
-				'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array(
728
+				'woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array(
729 729
 					'status' => 500,
730 730
 				)
731 731
 			);
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 		 * @param \WP_REST_Response $response The response data.
739 739
 		 * @param \WP_REST_Request  $request  The request sent to the API.
740 740
 		 */
741
-		do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );
741
+		do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request);
742 742
 
743 743
 		return $response;
744 744
 	}
@@ -750,30 +750,30 @@  discard block
 block discarded – undo
750 750
 	 * @param \WP_REST_Request $request Full details about the request.
751 751
 	 * @return array Of \WP_Error or \WP_REST_Response.
752 752
 	 */
753
-	public function batch_items( $request ) {
754
-		$items       = array_filter( $request->get_params() );
753
+	public function batch_items($request) {
754
+		$items       = array_filter($request->get_params());
755 755
 		$params      = $request->get_url_params();
756 756
 		$product_id  = $params['product_id'];
757 757
 		$body_params = array();
758 758
 
759
-		foreach ( array( 'update', 'create', 'delete' ) as $batch_type ) {
760
-			if ( ! empty( $items[ $batch_type ] ) ) {
759
+		foreach (array('update', 'create', 'delete') as $batch_type) {
760
+			if ( ! empty($items[$batch_type])) {
761 761
 				$injected_items = array();
762
-				foreach ( $items[ $batch_type ] as $item ) {
763
-					$injected_items[] = is_array( $item ) ? array_merge(
762
+				foreach ($items[$batch_type] as $item) {
763
+					$injected_items[] = is_array($item) ? array_merge(
764 764
 						array(
765 765
 							'product_id' => $product_id,
766 766
 						), $item
767 767
 					) : $item;
768 768
 				}
769
-				$body_params[ $batch_type ] = $injected_items;
769
+				$body_params[$batch_type] = $injected_items;
770 770
 			}
771 771
 		}
772 772
 
773
-		$request = new \WP_REST_Request( $request->get_method() );
774
-		$request->set_body_params( $body_params );
773
+		$request = new \WP_REST_Request($request->get_method());
774
+		$request->set_body_params($body_params);
775 775
 
776
-		return parent::batch_items( $request );
776
+		return parent::batch_items($request);
777 777
 	}
778 778
 
779 779
 	/**
@@ -783,18 +783,18 @@  discard block
 block discarded – undo
783 783
 	 * @param \WP_REST_Request $request Request object.
784 784
 	 * @return array                   Links for the given post.
785 785
 	 */
786
-	protected function prepare_links( $object, $request ) {
786
+	protected function prepare_links($object, $request) {
787 787
 		$product_id = (int) $request['product_id'];
788
-		$base       = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base );
788
+		$base       = str_replace('(?P<product_id>[\d]+)', $product_id, $this->rest_base);
789 789
 		$links      = array(
790 790
 			'self'       => array(
791
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $object->get_id() ) ),
791
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $object->get_id())),
792 792
 			),
793 793
 			'collection' => array(
794
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ),
794
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)),
795 795
 			),
796 796
 			'up'         => array(
797
-				'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product_id ) ),
797
+				'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product_id)),
798 798
 			),
799 799
 		);
800 800
 		return $links;
@@ -806,371 +806,371 @@  discard block
 block discarded – undo
806 806
 	 * @return array
807 807
 	 */
808 808
 	public function get_item_schema() {
809
-		$weight_unit    = get_option( 'woocommerce_weight_unit' );
810
-		$dimension_unit = get_option( 'woocommerce_dimension_unit' );
809
+		$weight_unit    = get_option('woocommerce_weight_unit');
810
+		$dimension_unit = get_option('woocommerce_dimension_unit');
811 811
 		$schema         = array(
812 812
 			'$schema'    => 'http://json-schema.org/draft-04/schema#',
813 813
 			'title'      => $this->post_type,
814 814
 			'type'       => 'object',
815 815
 			'properties' => array(
816 816
 				'id'                    => array(
817
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
817
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
818 818
 					'type'        => 'integer',
819
-					'context'     => array( 'view', 'edit' ),
819
+					'context'     => array('view', 'edit'),
820 820
 					'readonly'    => true,
821 821
 				),
822 822
 				'name'                  => array(
823
-					'description' => __( 'Product parent name.', 'woocommerce' ),
823
+					'description' => __('Product parent name.', 'woocommerce'),
824 824
 					'type'        => 'string',
825
-					'context'     => array( 'view', 'edit' ),
825
+					'context'     => array('view', 'edit'),
826 826
 				),
827 827
 				'type'                  => array(
828
-					'description' => __( 'Product type.', 'woocommerce' ),
828
+					'description' => __('Product type.', 'woocommerce'),
829 829
 					'type'        => 'string',
830 830
 					'default'     => 'variation',
831
-					'enum'        => array( 'variation' ),
832
-					'context'     => array( 'view', 'edit' ),
831
+					'enum'        => array('variation'),
832
+					'context'     => array('view', 'edit'),
833 833
 				),
834 834
 				'parent_id'             => array(
835
-					'description' => __( 'Product parent ID.', 'woocommerce' ),
835
+					'description' => __('Product parent ID.', 'woocommerce'),
836 836
 					'type'        => 'integer',
837
-					'context'     => array( 'view', 'edit' ),
837
+					'context'     => array('view', 'edit'),
838 838
 				),
839 839
 				'date_created'          => array(
840
-					'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ),
840
+					'description' => __("The date the variation was created, in the site's timezone.", 'woocommerce'),
841 841
 					'type'        => 'date-time',
842
-					'context'     => array( 'view', 'edit' ),
842
+					'context'     => array('view', 'edit'),
843 843
 					'readonly'    => true,
844 844
 				),
845 845
 				'date_modified'         => array(
846
-					'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ),
846
+					'description' => __("The date the variation was last modified, in the site's timezone.", 'woocommerce'),
847 847
 					'type'        => 'date-time',
848
-					'context'     => array( 'view', 'edit' ),
848
+					'context'     => array('view', 'edit'),
849 849
 					'readonly'    => true,
850 850
 				),
851 851
 				'description'           => array(
852
-					'description' => __( 'Variation description.', 'woocommerce' ),
852
+					'description' => __('Variation description.', 'woocommerce'),
853 853
 					'type'        => 'string',
854
-					'context'     => array( 'view', 'edit' ),
854
+					'context'     => array('view', 'edit'),
855 855
 				),
856 856
 				'permalink'             => array(
857
-					'description' => __( 'Variation URL.', 'woocommerce' ),
857
+					'description' => __('Variation URL.', 'woocommerce'),
858 858
 					'type'        => 'string',
859 859
 					'format'      => 'uri',
860
-					'context'     => array( 'view', 'edit' ),
860
+					'context'     => array('view', 'edit'),
861 861
 					'readonly'    => true,
862 862
 				),
863 863
 				'sku'                   => array(
864
-					'description' => __( 'Unique identifier.', 'woocommerce' ),
864
+					'description' => __('Unique identifier.', 'woocommerce'),
865 865
 					'type'        => 'string',
866
-					'context'     => array( 'view', 'edit' ),
866
+					'context'     => array('view', 'edit'),
867 867
 				),
868 868
 				'price'                 => array(
869
-					'description' => __( 'Current variation price.', 'woocommerce' ),
869
+					'description' => __('Current variation price.', 'woocommerce'),
870 870
 					'type'        => 'string',
871
-					'context'     => array( 'view', 'edit' ),
871
+					'context'     => array('view', 'edit'),
872 872
 					'readonly'    => true,
873 873
 				),
874 874
 				'regular_price'         => array(
875
-					'description' => __( 'Variation regular price.', 'woocommerce' ),
875
+					'description' => __('Variation regular price.', 'woocommerce'),
876 876
 					'type'        => 'string',
877
-					'context'     => array( 'view', 'edit' ),
877
+					'context'     => array('view', 'edit'),
878 878
 				),
879 879
 				'sale_price'            => array(
880
-					'description' => __( 'Variation sale price.', 'woocommerce' ),
880
+					'description' => __('Variation sale price.', 'woocommerce'),
881 881
 					'type'        => 'string',
882
-					'context'     => array( 'view', 'edit' ),
882
+					'context'     => array('view', 'edit'),
883 883
 				),
884 884
 				'date_on_sale_from'     => array(
885
-					'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ),
885
+					'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'),
886 886
 					'type'        => 'date-time',
887
-					'context'     => array( 'view', 'edit' ),
887
+					'context'     => array('view', 'edit'),
888 888
 				),
889 889
 				'date_on_sale_from_gmt' => array(
890
-					'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ),
890
+					'description' => __('Start date of sale price, as GMT.', 'woocommerce'),
891 891
 					'type'        => 'date-time',
892
-					'context'     => array( 'view', 'edit' ),
892
+					'context'     => array('view', 'edit'),
893 893
 				),
894 894
 				'date_on_sale_to'       => array(
895
-					'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
895
+					'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'),
896 896
 					'type'        => 'date-time',
897
-					'context'     => array( 'view', 'edit' ),
897
+					'context'     => array('view', 'edit'),
898 898
 				),
899 899
 				'date_on_sale_to_gmt'   => array(
900
-					'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ),
900
+					'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'),
901 901
 					'type'        => 'date-time',
902
-					'context'     => array( 'view', 'edit' ),
902
+					'context'     => array('view', 'edit'),
903 903
 				),
904 904
 				'on_sale'               => array(
905
-					'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ),
905
+					'description' => __('Shows if the variation is on sale.', 'woocommerce'),
906 906
 					'type'        => 'boolean',
907
-					'context'     => array( 'view', 'edit' ),
907
+					'context'     => array('view', 'edit'),
908 908
 					'readonly'    => true,
909 909
 				),
910 910
 				'status'                => array(
911
-					'description' => __( 'Variation status.', 'woocommerce' ),
911
+					'description' => __('Variation status.', 'woocommerce'),
912 912
 					'type'        => 'string',
913 913
 					'default'     => 'publish',
914
-					'enum'        => array_keys( get_post_statuses() ),
915
-					'context'     => array( 'view', 'edit' ),
914
+					'enum'        => array_keys(get_post_statuses()),
915
+					'context'     => array('view', 'edit'),
916 916
 				),
917 917
 				'purchasable'           => array(
918
-					'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ),
918
+					'description' => __('Shows if the variation can be bought.', 'woocommerce'),
919 919
 					'type'        => 'boolean',
920
-					'context'     => array( 'view', 'edit' ),
920
+					'context'     => array('view', 'edit'),
921 921
 					'readonly'    => true,
922 922
 				),
923 923
 				'virtual'               => array(
924
-					'description' => __( 'If the variation is virtual.', 'woocommerce' ),
924
+					'description' => __('If the variation is virtual.', 'woocommerce'),
925 925
 					'type'        => 'boolean',
926 926
 					'default'     => false,
927
-					'context'     => array( 'view', 'edit' ),
927
+					'context'     => array('view', 'edit'),
928 928
 				),
929 929
 				'downloadable'          => array(
930
-					'description' => __( 'If the variation is downloadable.', 'woocommerce' ),
930
+					'description' => __('If the variation is downloadable.', 'woocommerce'),
931 931
 					'type'        => 'boolean',
932 932
 					'default'     => false,
933
-					'context'     => array( 'view', 'edit' ),
933
+					'context'     => array('view', 'edit'),
934 934
 				),
935 935
 				'downloads'             => array(
936
-					'description' => __( 'List of downloadable files.', 'woocommerce' ),
936
+					'description' => __('List of downloadable files.', 'woocommerce'),
937 937
 					'type'        => 'array',
938
-					'context'     => array( 'view', 'edit' ),
938
+					'context'     => array('view', 'edit'),
939 939
 					'items'       => array(
940 940
 						'type'       => 'object',
941 941
 						'properties' => array(
942 942
 							'id'   => array(
943
-								'description' => __( 'File ID.', 'woocommerce' ),
943
+								'description' => __('File ID.', 'woocommerce'),
944 944
 								'type'        => 'string',
945
-								'context'     => array( 'view', 'edit' ),
945
+								'context'     => array('view', 'edit'),
946 946
 							),
947 947
 							'name' => array(
948
-								'description' => __( 'File name.', 'woocommerce' ),
948
+								'description' => __('File name.', 'woocommerce'),
949 949
 								'type'        => 'string',
950
-								'context'     => array( 'view', 'edit' ),
950
+								'context'     => array('view', 'edit'),
951 951
 							),
952 952
 							'file' => array(
953
-								'description' => __( 'File URL.', 'woocommerce' ),
953
+								'description' => __('File URL.', 'woocommerce'),
954 954
 								'type'        => 'string',
955
-								'context'     => array( 'view', 'edit' ),
955
+								'context'     => array('view', 'edit'),
956 956
 							),
957 957
 						),
958 958
 					),
959 959
 				),
960 960
 				'download_limit'        => array(
961
-					'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ),
961
+					'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'),
962 962
 					'type'        => 'integer',
963 963
 					'default'     => -1,
964
-					'context'     => array( 'view', 'edit' ),
964
+					'context'     => array('view', 'edit'),
965 965
 				),
966 966
 				'download_expiry'       => array(
967
-					'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ),
967
+					'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'),
968 968
 					'type'        => 'integer',
969 969
 					'default'     => -1,
970
-					'context'     => array( 'view', 'edit' ),
970
+					'context'     => array('view', 'edit'),
971 971
 				),
972 972
 				'tax_status'            => array(
973
-					'description' => __( 'Tax status.', 'woocommerce' ),
973
+					'description' => __('Tax status.', 'woocommerce'),
974 974
 					'type'        => 'string',
975 975
 					'default'     => 'taxable',
976
-					'enum'        => array( 'taxable', 'shipping', 'none' ),
977
-					'context'     => array( 'view', 'edit' ),
976
+					'enum'        => array('taxable', 'shipping', 'none'),
977
+					'context'     => array('view', 'edit'),
978 978
 				),
979 979
 				'tax_class'             => array(
980
-					'description' => __( 'Tax class.', 'woocommerce' ),
980
+					'description' => __('Tax class.', 'woocommerce'),
981 981
 					'type'        => 'string',
982
-					'context'     => array( 'view', 'edit' ),
982
+					'context'     => array('view', 'edit'),
983 983
 				),
984 984
 				'manage_stock'          => array(
985
-					'description' => __( 'Stock management at variation level.', 'woocommerce' ),
985
+					'description' => __('Stock management at variation level.', 'woocommerce'),
986 986
 					'type'        => 'boolean',
987 987
 					'default'     => false,
988
-					'context'     => array( 'view', 'edit' ),
988
+					'context'     => array('view', 'edit'),
989 989
 				),
990 990
 				'stock_quantity'        => array(
991
-					'description' => __( 'Stock quantity.', 'woocommerce' ),
991
+					'description' => __('Stock quantity.', 'woocommerce'),
992 992
 					'type'        => 'integer',
993
-					'context'     => array( 'view', 'edit' ),
993
+					'context'     => array('view', 'edit'),
994 994
 				),
995 995
 				'stock_status'          => array(
996
-					'description' => __( 'Controls the stock status of the product.', 'woocommerce' ),
996
+					'description' => __('Controls the stock status of the product.', 'woocommerce'),
997 997
 					'type'        => 'string',
998 998
 					'default'     => 'instock',
999
-					'enum'        => array_keys( wc_get_product_stock_status_options() ),
1000
-					'context'     => array( 'view', 'edit' ),
999
+					'enum'        => array_keys(wc_get_product_stock_status_options()),
1000
+					'context'     => array('view', 'edit'),
1001 1001
 				),
1002 1002
 				'backorders'            => array(
1003
-					'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ),
1003
+					'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'),
1004 1004
 					'type'        => 'string',
1005 1005
 					'default'     => 'no',
1006
-					'enum'        => array( 'no', 'notify', 'yes' ),
1007
-					'context'     => array( 'view', 'edit' ),
1006
+					'enum'        => array('no', 'notify', 'yes'),
1007
+					'context'     => array('view', 'edit'),
1008 1008
 				),
1009 1009
 				'backorders_allowed'    => array(
1010
-					'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ),
1010
+					'description' => __('Shows if backorders are allowed.', 'woocommerce'),
1011 1011
 					'type'        => 'boolean',
1012
-					'context'     => array( 'view', 'edit' ),
1012
+					'context'     => array('view', 'edit'),
1013 1013
 					'readonly'    => true,
1014 1014
 				),
1015 1015
 				'backordered'           => array(
1016
-					'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ),
1016
+					'description' => __('Shows if the variation is on backordered.', 'woocommerce'),
1017 1017
 					'type'        => 'boolean',
1018
-					'context'     => array( 'view', 'edit' ),
1018
+					'context'     => array('view', 'edit'),
1019 1019
 					'readonly'    => true,
1020 1020
 				),
1021 1021
 				'weight'                => array(
1022 1022
 					/* translators: %s: weight unit */
1023
-					'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ),
1023
+					'description' => sprintf(__('Variation weight (%s).', 'woocommerce'), $weight_unit),
1024 1024
 					'type'        => 'string',
1025
-					'context'     => array( 'view', 'edit' ),
1025
+					'context'     => array('view', 'edit'),
1026 1026
 				),
1027 1027
 				'dimensions'            => array(
1028
-					'description' => __( 'Variation dimensions.', 'woocommerce' ),
1028
+					'description' => __('Variation dimensions.', 'woocommerce'),
1029 1029
 					'type'        => 'object',
1030
-					'context'     => array( 'view', 'edit' ),
1030
+					'context'     => array('view', 'edit'),
1031 1031
 					'properties'  => array(
1032 1032
 						'length' => array(
1033 1033
 							/* translators: %s: dimension unit */
1034
-							'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ),
1034
+							'description' => sprintf(__('Variation length (%s).', 'woocommerce'), $dimension_unit),
1035 1035
 							'type'        => 'string',
1036
-							'context'     => array( 'view', 'edit' ),
1036
+							'context'     => array('view', 'edit'),
1037 1037
 						),
1038 1038
 						'width'  => array(
1039 1039
 							/* translators: %s: dimension unit */
1040
-							'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ),
1040
+							'description' => sprintf(__('Variation width (%s).', 'woocommerce'), $dimension_unit),
1041 1041
 							'type'        => 'string',
1042
-							'context'     => array( 'view', 'edit' ),
1042
+							'context'     => array('view', 'edit'),
1043 1043
 						),
1044 1044
 						'height' => array(
1045 1045
 							/* translators: %s: dimension unit */
1046
-							'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ),
1046
+							'description' => sprintf(__('Variation height (%s).', 'woocommerce'), $dimension_unit),
1047 1047
 							'type'        => 'string',
1048
-							'context'     => array( 'view', 'edit' ),
1048
+							'context'     => array('view', 'edit'),
1049 1049
 						),
1050 1050
 					),
1051 1051
 				),
1052 1052
 				'shipping_class'        => array(
1053
-					'description' => __( 'Shipping class slug.', 'woocommerce' ),
1053
+					'description' => __('Shipping class slug.', 'woocommerce'),
1054 1054
 					'type'        => 'string',
1055
-					'context'     => array( 'view', 'edit' ),
1055
+					'context'     => array('view', 'edit'),
1056 1056
 				),
1057 1057
 				'shipping_class_id'     => array(
1058
-					'description' => __( 'Shipping class ID.', 'woocommerce' ),
1058
+					'description' => __('Shipping class ID.', 'woocommerce'),
1059 1059
 					'type'        => 'string',
1060
-					'context'     => array( 'view', 'edit' ),
1060
+					'context'     => array('view', 'edit'),
1061 1061
 					'readonly'    => true,
1062 1062
 				),
1063 1063
 				'image'                 => array(
1064
-					'description' => __( 'Variation image data.', 'woocommerce' ),
1064
+					'description' => __('Variation image data.', 'woocommerce'),
1065 1065
 					'type'        => 'object',
1066
-					'context'     => array( 'view', 'edit' ),
1066
+					'context'     => array('view', 'edit'),
1067 1067
 					'properties'  => array(
1068 1068
 						'id'                => array(
1069
-							'description' => __( 'Image ID.', 'woocommerce' ),
1069
+							'description' => __('Image ID.', 'woocommerce'),
1070 1070
 							'type'        => 'integer',
1071
-							'context'     => array( 'view', 'edit' ),
1071
+							'context'     => array('view', 'edit'),
1072 1072
 						),
1073 1073
 						'date_created'      => array(
1074
-							'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ),
1074
+							'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'),
1075 1075
 							'type'        => 'date-time',
1076
-							'context'     => array( 'view', 'edit' ),
1076
+							'context'     => array('view', 'edit'),
1077 1077
 							'readonly'    => true,
1078 1078
 						),
1079 1079
 						'date_created_gmt'  => array(
1080
-							'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ),
1080
+							'description' => __('The date the image was created, as GMT.', 'woocommerce'),
1081 1081
 							'type'        => 'date-time',
1082
-							'context'     => array( 'view', 'edit' ),
1082
+							'context'     => array('view', 'edit'),
1083 1083
 							'readonly'    => true,
1084 1084
 						),
1085 1085
 						'date_modified'     => array(
1086
-							'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ),
1086
+							'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'),
1087 1087
 							'type'        => 'date-time',
1088
-							'context'     => array( 'view', 'edit' ),
1088
+							'context'     => array('view', 'edit'),
1089 1089
 							'readonly'    => true,
1090 1090
 						),
1091 1091
 						'date_modified_gmt' => array(
1092
-							'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ),
1092
+							'description' => __('The date the image was last modified, as GMT.', 'woocommerce'),
1093 1093
 							'type'        => 'date-time',
1094
-							'context'     => array( 'view', 'edit' ),
1094
+							'context'     => array('view', 'edit'),
1095 1095
 							'readonly'    => true,
1096 1096
 						),
1097 1097
 						'src'               => array(
1098
-							'description' => __( 'Image URL.', 'woocommerce' ),
1098
+							'description' => __('Image URL.', 'woocommerce'),
1099 1099
 							'type'        => 'string',
1100 1100
 							'format'      => 'uri',
1101
-							'context'     => array( 'view', 'edit' ),
1101
+							'context'     => array('view', 'edit'),
1102 1102
 						),
1103 1103
 						'name'              => array(
1104
-							'description' => __( 'Image name.', 'woocommerce' ),
1104
+							'description' => __('Image name.', 'woocommerce'),
1105 1105
 							'type'        => 'string',
1106
-							'context'     => array( 'view', 'edit' ),
1106
+							'context'     => array('view', 'edit'),
1107 1107
 						),
1108 1108
 						'alt'               => array(
1109
-							'description' => __( 'Image alternative text.', 'woocommerce' ),
1109
+							'description' => __('Image alternative text.', 'woocommerce'),
1110 1110
 							'type'        => 'string',
1111
-							'context'     => array( 'view', 'edit' ),
1111
+							'context'     => array('view', 'edit'),
1112 1112
 						),
1113 1113
 					),
1114 1114
 				),
1115 1115
 				'attributes'            => array(
1116
-					'description' => __( 'List of attributes.', 'woocommerce' ),
1116
+					'description' => __('List of attributes.', 'woocommerce'),
1117 1117
 					'type'        => 'array',
1118
-					'context'     => array( 'view', 'edit' ),
1118
+					'context'     => array('view', 'edit'),
1119 1119
 					'items'       => array(
1120 1120
 						'type'       => 'object',
1121 1121
 						'properties' => array(
1122 1122
 							'id'     => array(
1123
-								'description' => __( 'Attribute ID.', 'woocommerce' ),
1123
+								'description' => __('Attribute ID.', 'woocommerce'),
1124 1124
 								'type'        => 'integer',
1125
-								'context'     => array( 'view', 'edit' ),
1125
+								'context'     => array('view', 'edit'),
1126 1126
 							),
1127 1127
 							'name'   => array(
1128
-								'description' => __( 'Attribute name.', 'woocommerce' ),
1128
+								'description' => __('Attribute name.', 'woocommerce'),
1129 1129
 								'type'        => 'string',
1130
-								'context'     => array( 'view', 'edit' ),
1130
+								'context'     => array('view', 'edit'),
1131 1131
 							),
1132 1132
 							'option' => array(
1133
-								'description' => __( 'Selected attribute term name.', 'woocommerce' ),
1133
+								'description' => __('Selected attribute term name.', 'woocommerce'),
1134 1134
 								'type'        => 'string',
1135
-								'context'     => array( 'view', 'edit' ),
1135
+								'context'     => array('view', 'edit'),
1136 1136
 							),
1137 1137
 						),
1138 1138
 					),
1139 1139
 				),
1140 1140
 				'menu_order'            => array(
1141
-					'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ),
1141
+					'description' => __('Menu order, used to custom sort products.', 'woocommerce'),
1142 1142
 					'type'        => 'integer',
1143
-					'context'     => array( 'view', 'edit' ),
1143
+					'context'     => array('view', 'edit'),
1144 1144
 				),
1145 1145
 				'meta_data'             => array(
1146
-					'description' => __( 'Meta data.', 'woocommerce' ),
1146
+					'description' => __('Meta data.', 'woocommerce'),
1147 1147
 					'type'        => 'array',
1148
-					'context'     => array( 'view', 'edit' ),
1148
+					'context'     => array('view', 'edit'),
1149 1149
 					'items'       => array(
1150 1150
 						'type'       => 'object',
1151 1151
 						'properties' => array(
1152 1152
 							'id'    => array(
1153
-								'description' => __( 'Meta ID.', 'woocommerce' ),
1153
+								'description' => __('Meta ID.', 'woocommerce'),
1154 1154
 								'type'        => 'integer',
1155
-								'context'     => array( 'view', 'edit' ),
1155
+								'context'     => array('view', 'edit'),
1156 1156
 								'readonly'    => true,
1157 1157
 							),
1158 1158
 							'key'   => array(
1159
-								'description' => __( 'Meta key.', 'woocommerce' ),
1159
+								'description' => __('Meta key.', 'woocommerce'),
1160 1160
 								'type'        => 'string',
1161
-								'context'     => array( 'view', 'edit' ),
1161
+								'context'     => array('view', 'edit'),
1162 1162
 							),
1163 1163
 							'value' => array(
1164
-								'description' => __( 'Meta value.', 'woocommerce' ),
1164
+								'description' => __('Meta value.', 'woocommerce'),
1165 1165
 								'type'        => 'mixed',
1166
-								'context'     => array( 'view', 'edit' ),
1166
+								'context'     => array('view', 'edit'),
1167 1167
 							),
1168 1168
 						),
1169 1169
 					),
1170 1170
 				),
1171 1171
 			),
1172 1172
 		);
1173
-		return $this->add_additional_fields_schema( $schema );
1173
+		return $this->add_additional_fields_schema($schema);
1174 1174
 	}
1175 1175
 
1176 1176
 	/**
@@ -1193,15 +1193,15 @@  discard block
 block discarded – undo
1193 1193
 		);
1194 1194
 
1195 1195
 		$params['stock_status'] = array(
1196
-			'description'       => __( 'Limit result set to products with specified stock status.', 'woocommerce' ),
1196
+			'description'       => __('Limit result set to products with specified stock status.', 'woocommerce'),
1197 1197
 			'type'              => 'string',
1198
-			'enum'              => array_keys( wc_get_product_stock_status_options() ),
1198
+			'enum'              => array_keys(wc_get_product_stock_status_options()),
1199 1199
 			'sanitize_callback' => 'sanitize_text_field',
1200 1200
 			'validate_callback' => 'rest_validate_request_arg',
1201 1201
 		);
1202 1202
 
1203 1203
 		$params['search'] = array(
1204
-			'description'       => __( 'Search by similar product name or sku.', 'woocommerce' ),
1204
+			'description'       => __('Search by similar product name or sku.', 'woocommerce'),
1205 1205
 			'type'              => 'string',
1206 1206
 			'validate_callback' => 'rest_validate_request_arg',
1207 1207
 		);
@@ -1215,14 +1215,14 @@  discard block
 block discarded – undo
1215 1215
 	 * @param \WP_REST_Request $request Full details about the request.
1216 1216
 	 * @return \WP_Error\WP_REST_Response
1217 1217
 	 */
1218
-	public function get_items( $request ) {
1219
-		add_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10, 2 );
1220
-		add_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10, 2 );
1221
-		add_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10, 2 );
1222
-		$response = parent::get_items( $request );
1223
-		remove_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10 );
1224
-		remove_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10 );
1225
-		remove_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10 );
1218
+	public function get_items($request) {
1219
+		add_filter('posts_where', array(__CLASS__, 'add_wp_query_filter'), 10, 2);
1220
+		add_filter('posts_join', array(__CLASS__, 'add_wp_query_join'), 10, 2);
1221
+		add_filter('posts_groupby', array(__CLASS__, 'add_wp_query_group_by'), 10, 2);
1222
+		$response = parent::get_items($request);
1223
+		remove_filter('posts_where', array(__CLASS__, 'add_wp_query_filter'), 10);
1224
+		remove_filter('posts_join', array(__CLASS__, 'add_wp_query_join'), 10);
1225
+		remove_filter('posts_groupby', array(__CLASS__, 'add_wp_query_group_by'), 10);
1226 1226
 		return $response;
1227 1227
 	}
1228 1228
 }
Please login to merge, or discard this patch.