Completed
Push — master ( c2e4d5...99a09c )
by Mike
124:30 queued 79:29
created
src/RestApi/Version4/Controllers/SystemStatus.php 1 patch
Spacing   +288 added lines, -288 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API System Status 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
 		);
@@ -49,9 +49,9 @@  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_rest_check_manager_permissions( 'system_status', 'read' ) ) {
54
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
52
+	public function get_items_permissions_check($request) {
53
+		if ( ! wc_rest_check_manager_permissions('system_status', 'read')) {
54
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
55 55
 		}
56 56
 		return true;
57 57
 	}
@@ -62,24 +62,24 @@  discard block
 block discarded – undo
62 62
 	 * @param \WP_REST_Request $request Full details about the request.
63 63
 	 * @return \WP_Error\WP_REST_Response
64 64
 	 */
65
-	public function get_items( $request ) {
65
+	public function get_items($request) {
66 66
 		$schema   = $this->get_item_schema();
67 67
 		$mappings = $this->get_item_mappings();
68 68
 		$response = array();
69 69
 
70
-		foreach ( $mappings as $section => $values ) {
71
-			foreach ( $values as $key => $value ) {
72
-				if ( isset( $schema['properties'][ $section ]['properties'][ $key ]['type'] ) ) {
73
-					settype( $values[ $key ], $schema['properties'][ $section ]['properties'][ $key ]['type'] );
70
+		foreach ($mappings as $section => $values) {
71
+			foreach ($values as $key => $value) {
72
+				if (isset($schema['properties'][$section]['properties'][$key]['type'])) {
73
+					settype($values[$key], $schema['properties'][$section]['properties'][$key]['type']);
74 74
 				}
75 75
 			}
76
-			settype( $values, $schema['properties'][ $section ]['type'] );
77
-			$response[ $section ] = $values;
76
+			settype($values, $schema['properties'][$section]['type']);
77
+			$response[$section] = $values;
78 78
 		}
79 79
 
80
-		$response = $this->prepare_item_for_response( $response, $request );
80
+		$response = $this->prepare_item_for_response($response, $request);
81 81
 
82
-		return rest_ensure_response( $response );
82
+		return rest_ensure_response($response);
83 83
 	}
84 84
 
85 85
 	/**
@@ -94,229 +94,229 @@  discard block
 block discarded – undo
94 94
 			'type'       => 'object',
95 95
 			'properties' => array(
96 96
 				'environment'    => array(
97
-					'description' => __( 'Environment.', 'woocommerce' ),
97
+					'description' => __('Environment.', 'woocommerce'),
98 98
 					'type'        => 'object',
99
-					'context'     => array( 'view' ),
99
+					'context'     => array('view'),
100 100
 					'readonly'    => true,
101 101
 					'properties'  => array(
102 102
 						'home_url'                  => array(
103
-							'description' => __( 'Home URL.', 'woocommerce' ),
103
+							'description' => __('Home URL.', 'woocommerce'),
104 104
 							'type'        => 'string',
105 105
 							'format'      => 'uri',
106
-							'context'     => array( 'view' ),
106
+							'context'     => array('view'),
107 107
 							'readonly'    => true,
108 108
 						),
109 109
 						'site_url'                  => array(
110
-							'description' => __( 'Site URL.', 'woocommerce' ),
110
+							'description' => __('Site URL.', 'woocommerce'),
111 111
 							'type'        => 'string',
112 112
 							'format'      => 'uri',
113
-							'context'     => array( 'view' ),
113
+							'context'     => array('view'),
114 114
 							'readonly'    => true,
115 115
 						),
116 116
 						'wc_version'                => array(
117
-							'description' => __( 'WooCommerce version.', 'woocommerce' ),
117
+							'description' => __('WooCommerce version.', 'woocommerce'),
118 118
 							'type'        => 'string',
119
-							'context'     => array( 'view' ),
119
+							'context'     => array('view'),
120 120
 							'readonly'    => true,
121 121
 						),
122 122
 						'log_directory'             => array(
123
-							'description' => __( 'Log directory.', 'woocommerce' ),
123
+							'description' => __('Log directory.', 'woocommerce'),
124 124
 							'type'        => 'string',
125
-							'context'     => array( 'view' ),
125
+							'context'     => array('view'),
126 126
 							'readonly'    => true,
127 127
 						),
128 128
 						'log_directory_writable'    => array(
129
-							'description' => __( 'Is log directory writable?', 'woocommerce' ),
129
+							'description' => __('Is log directory writable?', 'woocommerce'),
130 130
 							'type'        => 'boolean',
131
-							'context'     => array( 'view' ),
131
+							'context'     => array('view'),
132 132
 							'readonly'    => true,
133 133
 						),
134 134
 						'wp_version'                => array(
135
-							'description' => __( 'WordPress version.', 'woocommerce' ),
135
+							'description' => __('WordPress version.', 'woocommerce'),
136 136
 							'type'        => 'string',
137
-							'context'     => array( 'view' ),
137
+							'context'     => array('view'),
138 138
 							'readonly'    => true,
139 139
 						),
140 140
 						'wp_multisite'              => array(
141
-							'description' => __( 'Is WordPress multisite?', 'woocommerce' ),
141
+							'description' => __('Is WordPress multisite?', 'woocommerce'),
142 142
 							'type'        => 'boolean',
143
-							'context'     => array( 'view' ),
143
+							'context'     => array('view'),
144 144
 							'readonly'    => true,
145 145
 						),
146 146
 						'wp_memory_limit'           => array(
147
-							'description' => __( 'WordPress memory limit.', 'woocommerce' ),
147
+							'description' => __('WordPress memory limit.', 'woocommerce'),
148 148
 							'type'        => 'integer',
149
-							'context'     => array( 'view' ),
149
+							'context'     => array('view'),
150 150
 							'readonly'    => true,
151 151
 						),
152 152
 						'wp_debug_mode'             => array(
153
-							'description' => __( 'Is WordPress debug mode active?', 'woocommerce' ),
153
+							'description' => __('Is WordPress debug mode active?', 'woocommerce'),
154 154
 							'type'        => 'boolean',
155
-							'context'     => array( 'view' ),
155
+							'context'     => array('view'),
156 156
 							'readonly'    => true,
157 157
 						),
158 158
 						'wp_cron'                   => array(
159
-							'description' => __( 'Are WordPress cron jobs enabled?', 'woocommerce' ),
159
+							'description' => __('Are WordPress cron jobs enabled?', 'woocommerce'),
160 160
 							'type'        => 'boolean',
161
-							'context'     => array( 'view' ),
161
+							'context'     => array('view'),
162 162
 							'readonly'    => true,
163 163
 						),
164 164
 						'language'                  => array(
165
-							'description' => __( 'WordPress language.', 'woocommerce' ),
165
+							'description' => __('WordPress language.', 'woocommerce'),
166 166
 							'type'        => 'string',
167
-							'context'     => array( 'view' ),
167
+							'context'     => array('view'),
168 168
 							'readonly'    => true,
169 169
 						),
170 170
 						'server_info'               => array(
171
-							'description' => __( 'Server info.', 'woocommerce' ),
171
+							'description' => __('Server info.', 'woocommerce'),
172 172
 							'type'        => 'string',
173
-							'context'     => array( 'view' ),
173
+							'context'     => array('view'),
174 174
 							'readonly'    => true,
175 175
 						),
176 176
 						'php_version'               => array(
177
-							'description' => __( 'PHP version.', 'woocommerce' ),
177
+							'description' => __('PHP version.', 'woocommerce'),
178 178
 							'type'        => 'string',
179
-							'context'     => array( 'view' ),
179
+							'context'     => array('view'),
180 180
 							'readonly'    => true,
181 181
 						),
182 182
 						'php_post_max_size'         => array(
183
-							'description' => __( 'PHP post max size.', 'woocommerce' ),
183
+							'description' => __('PHP post max size.', 'woocommerce'),
184 184
 							'type'        => 'integer',
185
-							'context'     => array( 'view' ),
185
+							'context'     => array('view'),
186 186
 							'readonly'    => true,
187 187
 						),
188 188
 						'php_max_execution_time'    => array(
189
-							'description' => __( 'PHP max execution time.', 'woocommerce' ),
189
+							'description' => __('PHP max execution time.', 'woocommerce'),
190 190
 							'type'        => 'integer',
191
-							'context'     => array( 'view' ),
191
+							'context'     => array('view'),
192 192
 							'readonly'    => true,
193 193
 						),
194 194
 						'php_max_input_vars'        => array(
195
-							'description' => __( 'PHP max input vars.', 'woocommerce' ),
195
+							'description' => __('PHP max input vars.', 'woocommerce'),
196 196
 							'type'        => 'integer',
197
-							'context'     => array( 'view' ),
197
+							'context'     => array('view'),
198 198
 							'readonly'    => true,
199 199
 						),
200 200
 						'curl_version'              => array(
201
-							'description' => __( 'cURL version.', 'woocommerce' ),
201
+							'description' => __('cURL version.', 'woocommerce'),
202 202
 							'type'        => 'string',
203
-							'context'     => array( 'view' ),
203
+							'context'     => array('view'),
204 204
 							'readonly'    => true,
205 205
 						),
206 206
 						'suhosin_installed'         => array(
207
-							'description' => __( 'Is SUHOSIN installed?', 'woocommerce' ),
207
+							'description' => __('Is SUHOSIN installed?', 'woocommerce'),
208 208
 							'type'        => 'boolean',
209
-							'context'     => array( 'view' ),
209
+							'context'     => array('view'),
210 210
 							'readonly'    => true,
211 211
 						),
212 212
 						'max_upload_size'           => array(
213
-							'description' => __( 'Max upload size.', 'woocommerce' ),
213
+							'description' => __('Max upload size.', 'woocommerce'),
214 214
 							'type'        => 'integer',
215
-							'context'     => array( 'view' ),
215
+							'context'     => array('view'),
216 216
 							'readonly'    => true,
217 217
 						),
218 218
 						'mysql_version'             => array(
219
-							'description' => __( 'MySQL version.', 'woocommerce' ),
219
+							'description' => __('MySQL version.', 'woocommerce'),
220 220
 							'type'        => 'string',
221
-							'context'     => array( 'view' ),
221
+							'context'     => array('view'),
222 222
 							'readonly'    => true,
223 223
 						),
224 224
 						'mysql_version_string'             => array(
225
-							'description' => __( 'MySQL version string.', 'woocommerce' ),
225
+							'description' => __('MySQL version string.', 'woocommerce'),
226 226
 							'type'        => 'string',
227
-							'context'     => array( 'view' ),
227
+							'context'     => array('view'),
228 228
 							'readonly'    => true,
229 229
 						),
230 230
 						'default_timezone'          => array(
231
-							'description' => __( 'Default timezone.', 'woocommerce' ),
231
+							'description' => __('Default timezone.', 'woocommerce'),
232 232
 							'type'        => 'string',
233
-							'context'     => array( 'view' ),
233
+							'context'     => array('view'),
234 234
 							'readonly'    => true,
235 235
 						),
236 236
 						'fsockopen_or_curl_enabled' => array(
237
-							'description' => __( 'Is fsockopen/cURL enabled?', 'woocommerce' ),
237
+							'description' => __('Is fsockopen/cURL enabled?', 'woocommerce'),
238 238
 							'type'        => 'boolean',
239
-							'context'     => array( 'view' ),
239
+							'context'     => array('view'),
240 240
 							'readonly'    => true,
241 241
 						),
242 242
 						'soapclient_enabled'        => array(
243
-							'description' => __( 'Is SoapClient class enabled?', 'woocommerce' ),
243
+							'description' => __('Is SoapClient class enabled?', 'woocommerce'),
244 244
 							'type'        => 'boolean',
245
-							'context'     => array( 'view' ),
245
+							'context'     => array('view'),
246 246
 							'readonly'    => true,
247 247
 						),
248 248
 						'domdocument_enabled'       => array(
249
-							'description' => __( 'Is DomDocument class enabled?', 'woocommerce' ),
249
+							'description' => __('Is DomDocument class enabled?', 'woocommerce'),
250 250
 							'type'        => 'boolean',
251
-							'context'     => array( 'view' ),
251
+							'context'     => array('view'),
252 252
 							'readonly'    => true,
253 253
 						),
254 254
 						'gzip_enabled'              => array(
255
-							'description' => __( 'Is GZip enabled?', 'woocommerce' ),
255
+							'description' => __('Is GZip enabled?', 'woocommerce'),
256 256
 							'type'        => 'boolean',
257
-							'context'     => array( 'view' ),
257
+							'context'     => array('view'),
258 258
 							'readonly'    => true,
259 259
 						),
260 260
 						'mbstring_enabled'          => array(
261
-							'description' => __( 'Is mbstring enabled?', 'woocommerce' ),
261
+							'description' => __('Is mbstring enabled?', 'woocommerce'),
262 262
 							'type'        => 'boolean',
263
-							'context'     => array( 'view' ),
263
+							'context'     => array('view'),
264 264
 							'readonly'    => true,
265 265
 						),
266 266
 						'remote_post_successful'    => array(
267
-							'description' => __( 'Remote POST successful?', 'woocommerce' ),
267
+							'description' => __('Remote POST successful?', 'woocommerce'),
268 268
 							'type'        => 'boolean',
269
-							'context'     => array( 'view' ),
269
+							'context'     => array('view'),
270 270
 							'readonly'    => true,
271 271
 						),
272 272
 						'remote_post_response'      => array(
273
-							'description' => __( 'Remote POST response.', 'woocommerce' ),
273
+							'description' => __('Remote POST response.', 'woocommerce'),
274 274
 							'type'        => 'string',
275
-							'context'     => array( 'view' ),
275
+							'context'     => array('view'),
276 276
 							'readonly'    => true,
277 277
 						),
278 278
 						'remote_get_successful'     => array(
279
-							'description' => __( 'Remote GET successful?', 'woocommerce' ),
279
+							'description' => __('Remote GET successful?', 'woocommerce'),
280 280
 							'type'        => 'boolean',
281
-							'context'     => array( 'view' ),
281
+							'context'     => array('view'),
282 282
 							'readonly'    => true,
283 283
 						),
284 284
 						'remote_get_response'       => array(
285
-							'description' => __( 'Remote GET response.', 'woocommerce' ),
285
+							'description' => __('Remote GET response.', 'woocommerce'),
286 286
 							'type'        => 'string',
287
-							'context'     => array( 'view' ),
287
+							'context'     => array('view'),
288 288
 							'readonly'    => true,
289 289
 						),
290 290
 					),
291 291
 				),
292 292
 				'database'       => array(
293
-					'description' => __( 'Database.', 'woocommerce' ),
293
+					'description' => __('Database.', 'woocommerce'),
294 294
 					'type'        => 'object',
295
-					'context'     => array( 'view' ),
295
+					'context'     => array('view'),
296 296
 					'readonly'    => true,
297 297
 					'properties'  => array(
298 298
 						'wc_database_version'    => array(
299
-							'description' => __( 'WC database version.', 'woocommerce' ),
299
+							'description' => __('WC database version.', 'woocommerce'),
300 300
 							'type'        => 'string',
301
-							'context'     => array( 'view' ),
301
+							'context'     => array('view'),
302 302
 							'readonly'    => true,
303 303
 						),
304 304
 						'database_prefix'        => array(
305
-							'description' => __( 'Database prefix.', 'woocommerce' ),
305
+							'description' => __('Database prefix.', 'woocommerce'),
306 306
 							'type'        => 'string',
307
-							'context'     => array( 'view' ),
307
+							'context'     => array('view'),
308 308
 							'readonly'    => true,
309 309
 						),
310 310
 						'maxmind_geoip_database' => array(
311
-							'description' => __( 'MaxMind GeoIP database.', 'woocommerce' ),
311
+							'description' => __('MaxMind GeoIP database.', 'woocommerce'),
312 312
 							'type'        => 'string',
313
-							'context'     => array( 'view' ),
313
+							'context'     => array('view'),
314 314
 							'readonly'    => true,
315 315
 						),
316 316
 						'database_tables'        => array(
317
-							'description' => __( 'Database tables.', 'woocommerce' ),
317
+							'description' => __('Database tables.', 'woocommerce'),
318 318
 							'type'        => 'array',
319
-							'context'     => array( 'view' ),
319
+							'context'     => array('view'),
320 320
 							'readonly'    => true,
321 321
 							'items'       => array(
322 322
 								'type' => 'string',
@@ -325,190 +325,190 @@  discard block
 block discarded – undo
325 325
 					),
326 326
 				),
327 327
 				'active_plugins' => array(
328
-					'description' => __( 'Active plugins.', 'woocommerce' ),
328
+					'description' => __('Active plugins.', 'woocommerce'),
329 329
 					'type'        => 'array',
330
-					'context'     => array( 'view' ),
330
+					'context'     => array('view'),
331 331
 					'readonly'    => true,
332 332
 					'items'       => array(
333 333
 						'type' => 'string',
334 334
 					),
335 335
 				),
336 336
 				'inactive_plugins' => array(
337
-					'description' => __( 'Inactive plugins.', 'woocommerce' ),
337
+					'description' => __('Inactive plugins.', 'woocommerce'),
338 338
 					'type'        => 'array',
339
-					'context'     => array( 'view' ),
339
+					'context'     => array('view'),
340 340
 					'readonly'    => true,
341 341
 					'items'       => array(
342 342
 						'type' => 'string',
343 343
 					),
344 344
 				),
345 345
 				'dropins_mu_plugins' => array(
346
-					'description' => __( 'Dropins & MU plugins.', 'woocommerce' ),
346
+					'description' => __('Dropins & MU plugins.', 'woocommerce'),
347 347
 					'type'        => 'array',
348
-					'context'     => array( 'view' ),
348
+					'context'     => array('view'),
349 349
 					'readonly'    => true,
350 350
 					'items'       => array(
351 351
 						'type' => 'string',
352 352
 					),
353 353
 				),
354 354
 				'theme'          => array(
355
-					'description' => __( 'Theme.', 'woocommerce' ),
355
+					'description' => __('Theme.', 'woocommerce'),
356 356
 					'type'        => 'object',
357
-					'context'     => array( 'view' ),
357
+					'context'     => array('view'),
358 358
 					'readonly'    => true,
359 359
 					'properties'  => array(
360 360
 						'name'                    => array(
361
-							'description' => __( 'Theme name.', 'woocommerce' ),
361
+							'description' => __('Theme name.', 'woocommerce'),
362 362
 							'type'        => 'string',
363
-							'context'     => array( 'view' ),
363
+							'context'     => array('view'),
364 364
 							'readonly'    => true,
365 365
 						),
366 366
 						'version'                 => array(
367
-							'description' => __( 'Theme version.', 'woocommerce' ),
367
+							'description' => __('Theme version.', 'woocommerce'),
368 368
 							'type'        => 'string',
369
-							'context'     => array( 'view' ),
369
+							'context'     => array('view'),
370 370
 							'readonly'    => true,
371 371
 						),
372 372
 						'version_latest'          => array(
373
-							'description' => __( 'Latest version of theme.', 'woocommerce' ),
373
+							'description' => __('Latest version of theme.', 'woocommerce'),
374 374
 							'type'        => 'string',
375
-							'context'     => array( 'view' ),
375
+							'context'     => array('view'),
376 376
 							'readonly'    => true,
377 377
 						),
378 378
 						'author_url'              => array(
379
-							'description' => __( 'Theme author URL.', 'woocommerce' ),
379
+							'description' => __('Theme author URL.', 'woocommerce'),
380 380
 							'type'        => 'string',
381 381
 							'format'      => 'uri',
382
-							'context'     => array( 'view' ),
382
+							'context'     => array('view'),
383 383
 							'readonly'    => true,
384 384
 						),
385 385
 						'is_child_theme'          => array(
386
-							'description' => __( 'Is this theme a child theme?', 'woocommerce' ),
386
+							'description' => __('Is this theme a child theme?', 'woocommerce'),
387 387
 							'type'        => 'boolean',
388
-							'context'     => array( 'view' ),
388
+							'context'     => array('view'),
389 389
 							'readonly'    => true,
390 390
 						),
391 391
 						'has_woocommerce_support' => array(
392
-							'description' => __( 'Does the theme declare WooCommerce support?', 'woocommerce' ),
392
+							'description' => __('Does the theme declare WooCommerce support?', 'woocommerce'),
393 393
 							'type'        => 'boolean',
394
-							'context'     => array( 'view' ),
394
+							'context'     => array('view'),
395 395
 							'readonly'    => true,
396 396
 						),
397 397
 						'has_woocommerce_file'    => array(
398
-							'description' => __( 'Does the theme have a woocommerce.php file?', 'woocommerce' ),
398
+							'description' => __('Does the theme have a woocommerce.php file?', 'woocommerce'),
399 399
 							'type'        => 'boolean',
400
-							'context'     => array( 'view' ),
400
+							'context'     => array('view'),
401 401
 							'readonly'    => true,
402 402
 						),
403 403
 						'has_outdated_templates'  => array(
404
-							'description' => __( 'Does this theme have outdated templates?', 'woocommerce' ),
404
+							'description' => __('Does this theme have outdated templates?', 'woocommerce'),
405 405
 							'type'        => 'boolean',
406
-							'context'     => array( 'view' ),
406
+							'context'     => array('view'),
407 407
 							'readonly'    => true,
408 408
 						),
409 409
 						'overrides'               => array(
410
-							'description' => __( 'Template overrides.', 'woocommerce' ),
410
+							'description' => __('Template overrides.', 'woocommerce'),
411 411
 							'type'        => 'array',
412
-							'context'     => array( 'view' ),
412
+							'context'     => array('view'),
413 413
 							'readonly'    => true,
414 414
 							'items'       => array(
415 415
 								'type' => 'string',
416 416
 							),
417 417
 						),
418 418
 						'parent_name'             => array(
419
-							'description' => __( 'Parent theme name.', 'woocommerce' ),
419
+							'description' => __('Parent theme name.', 'woocommerce'),
420 420
 							'type'        => 'string',
421
-							'context'     => array( 'view' ),
421
+							'context'     => array('view'),
422 422
 							'readonly'    => true,
423 423
 						),
424 424
 						'parent_version'          => array(
425
-							'description' => __( 'Parent theme version.', 'woocommerce' ),
425
+							'description' => __('Parent theme version.', 'woocommerce'),
426 426
 							'type'        => 'string',
427
-							'context'     => array( 'view' ),
427
+							'context'     => array('view'),
428 428
 							'readonly'    => true,
429 429
 						),
430 430
 						'parent_author_url'       => array(
431
-							'description' => __( 'Parent theme author URL.', 'woocommerce' ),
431
+							'description' => __('Parent theme author URL.', 'woocommerce'),
432 432
 							'type'        => 'string',
433 433
 							'format'      => 'uri',
434
-							'context'     => array( 'view' ),
434
+							'context'     => array('view'),
435 435
 							'readonly'    => true,
436 436
 						),
437 437
 					),
438 438
 				),
439 439
 				'settings'       => array(
440
-					'description' => __( 'Settings.', 'woocommerce' ),
440
+					'description' => __('Settings.', 'woocommerce'),
441 441
 					'type'        => 'object',
442
-					'context'     => array( 'view' ),
442
+					'context'     => array('view'),
443 443
 					'readonly'    => true,
444 444
 					'properties'  => array(
445 445
 						'api_enabled'              => array(
446
-							'description' => __( 'REST API enabled?', 'woocommerce' ),
446
+							'description' => __('REST API enabled?', 'woocommerce'),
447 447
 							'type'        => 'boolean',
448
-							'context'     => array( 'view' ),
448
+							'context'     => array('view'),
449 449
 							'readonly'    => true,
450 450
 						),
451 451
 						'force_ssl'                => array(
452
-							'description' => __( 'SSL forced?', 'woocommerce' ),
452
+							'description' => __('SSL forced?', 'woocommerce'),
453 453
 							'type'        => 'boolean',
454
-							'context'     => array( 'view' ),
454
+							'context'     => array('view'),
455 455
 							'readonly'    => true,
456 456
 						),
457 457
 						'currency'                 => array(
458
-							'description' => __( 'Currency.', 'woocommerce' ),
458
+							'description' => __('Currency.', 'woocommerce'),
459 459
 							'type'        => 'string',
460
-							'context'     => array( 'view' ),
460
+							'context'     => array('view'),
461 461
 							'readonly'    => true,
462 462
 						),
463 463
 						'currency_symbol'          => array(
464
-							'description' => __( 'Currency symbol.', 'woocommerce' ),
464
+							'description' => __('Currency symbol.', 'woocommerce'),
465 465
 							'type'        => 'string',
466
-							'context'     => array( 'view' ),
466
+							'context'     => array('view'),
467 467
 							'readonly'    => true,
468 468
 						),
469 469
 						'currency_position'        => array(
470
-							'description' => __( 'Currency position.', 'woocommerce' ),
470
+							'description' => __('Currency position.', 'woocommerce'),
471 471
 							'type'        => 'string',
472
-							'context'     => array( 'view' ),
472
+							'context'     => array('view'),
473 473
 							'readonly'    => true,
474 474
 						),
475 475
 						'thousand_separator'       => array(
476
-							'description' => __( 'Thousand separator.', 'woocommerce' ),
476
+							'description' => __('Thousand separator.', 'woocommerce'),
477 477
 							'type'        => 'string',
478
-							'context'     => array( 'view' ),
478
+							'context'     => array('view'),
479 479
 							'readonly'    => true,
480 480
 						),
481 481
 						'decimal_separator'        => array(
482
-							'description' => __( 'Decimal separator.', 'woocommerce' ),
482
+							'description' => __('Decimal separator.', 'woocommerce'),
483 483
 							'type'        => 'string',
484
-							'context'     => array( 'view' ),
484
+							'context'     => array('view'),
485 485
 							'readonly'    => true,
486 486
 						),
487 487
 						'number_of_decimals'       => array(
488
-							'description' => __( 'Number of decimals.', 'woocommerce' ),
488
+							'description' => __('Number of decimals.', 'woocommerce'),
489 489
 							'type'        => 'integer',
490
-							'context'     => array( 'view' ),
490
+							'context'     => array('view'),
491 491
 							'readonly'    => true,
492 492
 						),
493 493
 						'geolocation_enabled'      => array(
494
-							'description' => __( 'Geolocation enabled?', 'woocommerce' ),
494
+							'description' => __('Geolocation enabled?', 'woocommerce'),
495 495
 							'type'        => 'boolean',
496
-							'context'     => array( 'view' ),
496
+							'context'     => array('view'),
497 497
 							'readonly'    => true,
498 498
 						),
499 499
 						'taxonomies'               => array(
500
-							'description' => __( 'Taxonomy terms for product/order statuses.', 'woocommerce' ),
500
+							'description' => __('Taxonomy terms for product/order statuses.', 'woocommerce'),
501 501
 							'type'        => 'array',
502
-							'context'     => array( 'view' ),
502
+							'context'     => array('view'),
503 503
 							'readonly'    => true,
504 504
 							'items'       => array(
505 505
 								'type' => 'string',
506 506
 							),
507 507
 						),
508 508
 						'product_visibility_terms' => array(
509
-							'description' => __( 'Terms in the product visibility taxonomy.', 'woocommerce' ),
509
+							'description' => __('Terms in the product visibility taxonomy.', 'woocommerce'),
510 510
 							'type'        => 'array',
511
-							'context'     => array( 'view' ),
511
+							'context'     => array('view'),
512 512
 							'readonly'    => true,
513 513
 							'items'       => array(
514 514
 								'type' => 'string',
@@ -517,38 +517,38 @@  discard block
 block discarded – undo
517 517
 					),
518 518
 				),
519 519
 				'security'       => array(
520
-					'description' => __( 'Security.', 'woocommerce' ),
520
+					'description' => __('Security.', 'woocommerce'),
521 521
 					'type'        => 'object',
522
-					'context'     => array( 'view' ),
522
+					'context'     => array('view'),
523 523
 					'readonly'    => true,
524 524
 					'properties'  => array(
525 525
 						'secure_connection' => array(
526
-							'description' => __( 'Is the connection to your store secure?', 'woocommerce' ),
526
+							'description' => __('Is the connection to your store secure?', 'woocommerce'),
527 527
 							'type'        => 'boolean',
528
-							'context'     => array( 'view' ),
528
+							'context'     => array('view'),
529 529
 							'readonly'    => true,
530 530
 						),
531 531
 						'hide_errors'       => array(
532
-							'description' => __( 'Hide errors from visitors?', 'woocommerce' ),
532
+							'description' => __('Hide errors from visitors?', 'woocommerce'),
533 533
 							'type'        => 'boolean',
534
-							'context'     => array( 'view' ),
534
+							'context'     => array('view'),
535 535
 							'readonly'    => true,
536 536
 						),
537 537
 					),
538 538
 				),
539 539
 				'pages'          => array(
540
-					'description' => __( 'WooCommerce pages.', 'woocommerce' ),
540
+					'description' => __('WooCommerce pages.', 'woocommerce'),
541 541
 					'type'        => 'array',
542
-					'context'     => array( 'view' ),
542
+					'context'     => array('view'),
543 543
 					'readonly'    => true,
544 544
 					'items'       => array(
545 545
 						'type' => 'string',
546 546
 					),
547 547
 				),
548 548
 				'post_type_counts' => array(
549
-					'description' => __( 'Post type counts.', 'woocommerce' ),
549
+					'description' => __('Post type counts.', 'woocommerce'),
550 550
 					'type'        => 'array',
551
-					'context'     => array( 'view' ),
551
+					'context'     => array('view'),
552 552
 					'readonly'    => true,
553 553
 					'items'       => array(
554 554
 						'type' => 'string',
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
 			),
558 558
 		);
559 559
 
560
-		return $this->add_additional_fields_schema( $schema );
560
+		return $this->add_additional_fields_schema($schema);
561 561
 	}
562 562
 
563 563
 	/**
@@ -591,23 +591,23 @@  discard block
 block discarded – undo
591 591
 
592 592
 		// Figure out cURL version, if installed.
593 593
 		$curl_version = '';
594
-		if ( function_exists( 'curl_version' ) ) {
594
+		if (function_exists('curl_version')) {
595 595
 			$curl_version = curl_version();
596 596
 			$curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
597
-		} elseif ( extension_loaded( 'curl' ) ) {
598
-			$curl_version = __( 'cURL installed but unable to retrieve version.', 'woocommerce' );
597
+		} elseif (extension_loaded('curl')) {
598
+			$curl_version = __('cURL installed but unable to retrieve version.', 'woocommerce');
599 599
 		}
600 600
 
601 601
 		// WP memory limit.
602
-		$wp_memory_limit = wc_let_to_num( WP_MEMORY_LIMIT );
603
-		if ( function_exists( 'memory_get_usage' ) ) {
604
-			$wp_memory_limit = max( $wp_memory_limit, wc_let_to_num( @ini_get( 'memory_limit' ) ) );
602
+		$wp_memory_limit = wc_let_to_num(WP_MEMORY_LIMIT);
603
+		if (function_exists('memory_get_usage')) {
604
+			$wp_memory_limit = max($wp_memory_limit, wc_let_to_num(@ini_get('memory_limit')));
605 605
 		}
606 606
 
607 607
 		// Test POST requests.
608
-		$post_response_code = get_transient( 'woocommerce_test_remote_post' );
608
+		$post_response_code = get_transient('woocommerce_test_remote_post');
609 609
 
610
-		if ( false === $post_response_code || is_wp_error( $post_response_code ) ) {
610
+		if (false === $post_response_code || is_wp_error($post_response_code)) {
611 611
 			$response = wp_safe_remote_post(
612 612
 				'https://www.paypal.com/cgi-bin/webscr',
613 613
 				array(
@@ -619,63 +619,63 @@  discard block
 block discarded – undo
619 619
 					),
620 620
 				)
621 621
 			);
622
-			if ( ! is_wp_error( $response ) ) {
622
+			if ( ! is_wp_error($response)) {
623 623
 				$post_response_code = $response['response']['code'];
624 624
 			}
625
-			set_transient( 'woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS );
625
+			set_transient('woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS);
626 626
 		}
627 627
 
628
-		$post_response_successful = ! is_wp_error( $post_response_code ) && $post_response_code >= 200 && $post_response_code < 300;
628
+		$post_response_successful = ! is_wp_error($post_response_code) && $post_response_code >= 200 && $post_response_code < 300;
629 629
 
630 630
 		// Test GET requests.
631
-		$get_response_code = get_transient( 'woocommerce_test_remote_get' );
631
+		$get_response_code = get_transient('woocommerce_test_remote_get');
632 632
 
633
-		if ( false === $get_response_code || is_wp_error( $get_response_code ) ) {
634
-			$response = wp_safe_remote_get( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite() ? '1' : '0' ) );
635
-			if ( ! is_wp_error( $response ) ) {
633
+		if (false === $get_response_code || is_wp_error($get_response_code)) {
634
+			$response = wp_safe_remote_get('https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . (is_multisite() ? '1' : '0'));
635
+			if ( ! is_wp_error($response)) {
636 636
 				$get_response_code = $response['response']['code'];
637 637
 			}
638
-			set_transient( 'woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS );
638
+			set_transient('woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS);
639 639
 		}
640 640
 
641
-		$get_response_successful = ! is_wp_error( $get_response_code ) && $get_response_code >= 200 && $get_response_code < 300;
641
+		$get_response_successful = ! is_wp_error($get_response_code) && $get_response_code >= 200 && $get_response_code < 300;
642 642
 
643 643
 		$database_version = wc_get_server_database_version();
644 644
 
645 645
 		// Return all environment info. Described by JSON Schema.
646 646
 		return array(
647
-			'home_url'                  => get_option( 'home' ),
648
-			'site_url'                  => get_option( 'siteurl' ),
647
+			'home_url'                  => get_option('home'),
648
+			'site_url'                  => get_option('siteurl'),
649 649
 			'version'                   => WC()->version,
650 650
 			'log_directory'             => WC_LOG_DIR,
651
-			'log_directory_writable'    => (bool) @fopen( WC_LOG_DIR . 'test-log.log', 'a' ),
652
-			'wp_version'                => get_bloginfo( 'version' ),
651
+			'log_directory_writable'    => (bool) @fopen(WC_LOG_DIR . 'test-log.log', 'a'),
652
+			'wp_version'                => get_bloginfo('version'),
653 653
 			'wp_multisite'              => is_multisite(),
654 654
 			'wp_memory_limit'           => $wp_memory_limit,
655
-			'wp_debug_mode'             => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
656
-			'wp_cron'                   => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
655
+			'wp_debug_mode'             => (defined('WP_DEBUG') && WP_DEBUG),
656
+			'wp_cron'                   => ! (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON),
657 657
 			'language'                  => get_locale(),
658 658
 			'external_object_cache'     => wp_using_ext_object_cache(),
659
-			'server_info'               => isset( $_SERVER['SERVER_SOFTWARE'] ) ? wc_clean( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '',
659
+			'server_info'               => isset($_SERVER['SERVER_SOFTWARE']) ? wc_clean(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : '',
660 660
 			'php_version'               => phpversion(),
661
-			'php_post_max_size'         => wc_let_to_num( ini_get( 'post_max_size' ) ),
662
-			'php_max_execution_time'    => ini_get( 'max_execution_time' ),
663
-			'php_max_input_vars'        => ini_get( 'max_input_vars' ),
661
+			'php_post_max_size'         => wc_let_to_num(ini_get('post_max_size')),
662
+			'php_max_execution_time'    => ini_get('max_execution_time'),
663
+			'php_max_input_vars'        => ini_get('max_input_vars'),
664 664
 			'curl_version'              => $curl_version,
665
-			'suhosin_installed'         => extension_loaded( 'suhosin' ),
665
+			'suhosin_installed'         => extension_loaded('suhosin'),
666 666
 			'max_upload_size'           => wp_max_upload_size(),
667 667
 			'mysql_version'             => $database_version['number'],
668 668
 			'mysql_version_string'      => $database_version['string'],
669 669
 			'default_timezone'          => date_default_timezone_get(),
670
-			'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ),
671
-			'soapclient_enabled'        => class_exists( 'SoapClient' ),
672
-			'domdocument_enabled'       => class_exists( 'DOMDocument' ),
673
-			'gzip_enabled'              => is_callable( 'gzopen' ),
674
-			'mbstring_enabled'          => extension_loaded( 'mbstring' ),
670
+			'fsockopen_or_curl_enabled' => (function_exists('fsockopen') || function_exists('curl_init')),
671
+			'soapclient_enabled'        => class_exists('SoapClient'),
672
+			'domdocument_enabled'       => class_exists('DOMDocument'),
673
+			'gzip_enabled'              => is_callable('gzopen'),
674
+			'mbstring_enabled'          => extension_loaded('mbstring'),
675 675
 			'remote_post_successful'    => $post_response_successful,
676
-			'remote_post_response'      => is_wp_error( $post_response_code ) ? $post_response_code->get_error_message() : $post_response_code,
676
+			'remote_post_response'      => is_wp_error($post_response_code) ? $post_response_code->get_error_message() : $post_response_code,
677 677
 			'remote_get_successful'     => $get_response_successful,
678
-			'remote_get_response'       => is_wp_error( $get_response_code ) ? $get_response_code->get_error_message() : $get_response_code,
678
+			'remote_get_response'       => is_wp_error($get_response_code) ? $get_response_code->get_error_message() : $get_response_code,
679 679
 		);
680 680
 	}
681 681
 
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
 	 * @param string $table Table name.
686 686
 	 * @return stromg
687 687
 	 */
688
-	protected function add_db_table_prefix( $table ) {
688
+	protected function add_db_table_prefix($table) {
689 689
 		global $wpdb;
690 690
 		return $wpdb->prefix . $table;
691 691
 	}
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 		 *
739 739
 		 * If we changed the tables above to include the prefix, then any filters against that table could break.
740 740
 		 */
741
-		$core_tables = array_map( array( $this, 'add_db_table_prefix' ), $core_tables );
741
+		$core_tables = array_map(array($this, 'add_db_table_prefix'), $core_tables);
742 742
 
743 743
 		/**
744 744
 		 * Organize WooCommerce and non-WooCommerce tables separately for display purposes later.
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 		 * To ensure we include all WC tables, even if they do not exist, pre-populate the WC array with all the tables.
747 747
 		 */
748 748
 		$tables = array(
749
-			'woocommerce' => array_fill_keys( $core_tables, false ),
749
+			'woocommerce' => array_fill_keys($core_tables, false),
750 750
 			'other'       => array(),
751 751
 		);
752 752
 
@@ -755,16 +755,16 @@  discard block
 block discarded – undo
755 755
 			'index' => 0,
756 756
 		);
757 757
 
758
-		$site_tables_prefix = $wpdb->get_blog_prefix( get_current_blog_id() );
759
-		$global_tables      = $wpdb->tables( 'global', true );
760
-		foreach ( $database_table_information as $table ) {
758
+		$site_tables_prefix = $wpdb->get_blog_prefix(get_current_blog_id());
759
+		$global_tables      = $wpdb->tables('global', true);
760
+		foreach ($database_table_information as $table) {
761 761
 			// Only include tables matching the prefix of the current site, this is to prevent displaying all tables on a MS install not relating to the current.
762
-			if ( is_multisite() && 0 !== strpos( $table->name, $site_tables_prefix ) && ! in_array( $table->name, $global_tables, true ) ) {
762
+			if (is_multisite() && 0 !== strpos($table->name, $site_tables_prefix) && ! in_array($table->name, $global_tables, true)) {
763 763
 				continue;
764 764
 			}
765
-			$table_type = in_array( $table->name, $core_tables, true ) ? 'woocommerce' : 'other';
765
+			$table_type = in_array($table->name, $core_tables, true) ? 'woocommerce' : 'other';
766 766
 
767
-			$tables[ $table_type ][ $table->name ] = array(
767
+			$tables[$table_type][$table->name] = array(
768 768
 				'data'   => $table->data,
769 769
 				'index'  => $table->index,
770 770
 				'engine' => $table->engine,
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
 
777 777
 		// Return all database info. Described by JSON Schema.
778 778
 		return array(
779
-			'wc_database_version'    => get_option( 'woocommerce_db_version' ),
779
+			'wc_database_version'    => get_option('woocommerce_db_version'),
780 780
 			'database_prefix'        => $wpdb->prefix,
781 781
 			'maxmind_geoip_database' => \WC_Geolocation::get_local_database_path(),
782 782
 			'database_tables'        => $tables,
@@ -792,9 +792,9 @@  discard block
 block discarded – undo
792 792
 	public function get_post_type_counts() {
793 793
 		global $wpdb;
794 794
 
795
-		$post_type_counts = $wpdb->get_results( "SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;" );
795
+		$post_type_counts = $wpdb->get_results("SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;");
796 796
 
797
-		return is_array( $post_type_counts ) ? $post_type_counts : array();
797
+		return is_array($post_type_counts) ? $post_type_counts : array();
798 798
 	}
799 799
 
800 800
 	/**
@@ -805,21 +805,21 @@  discard block
 block discarded – undo
805 805
 	public function get_active_plugins() {
806 806
 		require_once ABSPATH . 'wp-admin/includes/plugin.php';
807 807
 
808
-		if ( ! function_exists( 'get_plugin_data' ) ) {
808
+		if ( ! function_exists('get_plugin_data')) {
809 809
 			return array();
810 810
 		}
811 811
 
812
-		$active_plugins = (array) get_option( 'active_plugins', array() );
813
-		if ( is_multisite() ) {
814
-			$network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
815
-			$active_plugins            = array_merge( $active_plugins, $network_activated_plugins );
812
+		$active_plugins = (array) get_option('active_plugins', array());
813
+		if (is_multisite()) {
814
+			$network_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array()));
815
+			$active_plugins            = array_merge($active_plugins, $network_activated_plugins);
816 816
 		}
817 817
 
818 818
 		$active_plugins_data = array();
819 819
 
820
-		foreach ( $active_plugins as $plugin ) {
821
-			$data                  = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
822
-			$active_plugins_data[] = $this->format_plugin_data( $plugin, $data );
820
+		foreach ($active_plugins as $plugin) {
821
+			$data                  = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
822
+			$active_plugins_data[] = $this->format_plugin_data($plugin, $data);
823 823
 		}
824 824
 
825 825
 		return $active_plugins_data;
@@ -833,25 +833,25 @@  discard block
 block discarded – undo
833 833
 	public function get_inactive_plugins() {
834 834
 		require_once ABSPATH . 'wp-admin/includes/plugin.php';
835 835
 
836
-		if ( ! function_exists( 'get_plugins' ) ) {
836
+		if ( ! function_exists('get_plugins')) {
837 837
 			return array();
838 838
 		}
839 839
 
840 840
 		$plugins        = get_plugins();
841
-		$active_plugins = (array) get_option( 'active_plugins', array() );
841
+		$active_plugins = (array) get_option('active_plugins', array());
842 842
 
843
-		if ( is_multisite() ) {
844
-			$network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
845
-			$active_plugins            = array_merge( $active_plugins, $network_activated_plugins );
843
+		if (is_multisite()) {
844
+			$network_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array()));
845
+			$active_plugins            = array_merge($active_plugins, $network_activated_plugins);
846 846
 		}
847 847
 
848 848
 		$plugins_data = array();
849 849
 
850
-		foreach ( $plugins as $plugin => $data ) {
851
-			if ( in_array( $plugin, $active_plugins, true ) ) {
850
+		foreach ($plugins as $plugin => $data) {
851
+			if (in_array($plugin, $active_plugins, true)) {
852 852
 				continue;
853 853
 			}
854
-			$plugins_data[] = $this->format_plugin_data( $plugin, $data );
854
+			$plugins_data[] = $this->format_plugin_data($plugin, $data);
855 855
 		}
856 856
 
857 857
 		return $plugins_data;
@@ -865,23 +865,23 @@  discard block
 block discarded – undo
865 865
 	 * @param array  $data Plugin data from WP.
866 866
 	 * @return array Formatted data.
867 867
 	 */
868
-	protected function format_plugin_data( $plugin, $data ) {
868
+	protected function format_plugin_data($plugin, $data) {
869 869
 		require_once ABSPATH . 'wp-admin/includes/update.php';
870 870
 
871
-		if ( ! function_exists( 'get_plugin_updates' ) ) {
871
+		if ( ! function_exists('get_plugin_updates')) {
872 872
 			return array();
873 873
 		}
874 874
 
875 875
 		// Use WP API to lookup latest updates for plugins. WC_Helper injects updates for premium plugins.
876
-		if ( empty( $this->available_updates ) ) {
876
+		if (empty($this->available_updates)) {
877 877
 			$this->available_updates = get_plugin_updates();
878 878
 		}
879 879
 
880 880
 		$version_latest = $data['Version'];
881 881
 
882 882
 		// Find latest version.
883
-		if ( isset( $this->available_updates[ $plugin ]->update->new_version ) ) {
884
-			$version_latest = $this->available_updates[ $plugin ]->update->new_version;
883
+		if (isset($this->available_updates[$plugin]->update->new_version)) {
884
+			$version_latest = $this->available_updates[$plugin]->update->new_version;
885 885
 		}
886 886
 
887 887
 		return array(
@@ -891,7 +891,7 @@  discard block
 block discarded – undo
891 891
 			'version_latest'    => $version_latest,
892 892
 			'url'               => $data['PluginURI'],
893 893
 			'author_name'       => $data['AuthorName'],
894
-			'author_url'        => esc_url_raw( $data['AuthorURI'] ),
894
+			'author_url'        => esc_url_raw($data['AuthorURI']),
895 895
 			'network_activated' => $data['Network'],
896 896
 		);
897 897
 	}
@@ -908,7 +908,7 @@  discard block
 block discarded – undo
908 908
 			'dropins'    => array(),
909 909
 			'mu_plugins' => array(),
910 910
 		);
911
-		foreach ( $dropins as $key => $dropin ) {
911
+		foreach ($dropins as $key => $dropin) {
912 912
 			$plugins['dropins'][] = array(
913 913
 				'plugin' => $key,
914 914
 				'name'   => $dropin['Name'],
@@ -916,14 +916,14 @@  discard block
 block discarded – undo
916 916
 		}
917 917
 
918 918
 		$mu_plugins = get_mu_plugins();
919
-		foreach ( $mu_plugins as $plugin => $mu_plugin ) {
919
+		foreach ($mu_plugins as $plugin => $mu_plugin) {
920 920
 			$plugins['mu_plugins'][] = array(
921 921
 				'plugin'      => $plugin,
922 922
 				'name'        => $mu_plugin['Name'],
923 923
 				'version'     => $mu_plugin['Version'],
924 924
 				'url'         => $mu_plugin['PluginURI'],
925 925
 				'author_name' => $mu_plugin['AuthorName'],
926
-				'author_url'  => esc_url_raw( $mu_plugin['AuthorURI'] ),
926
+				'author_url'  => esc_url_raw($mu_plugin['AuthorURI']),
927 927
 			);
928 928
 		}
929 929
 		return $plugins;
@@ -940,12 +940,12 @@  discard block
 block discarded – undo
940 940
 
941 941
 		// Get parent theme info if this theme is a child theme, otherwise
942 942
 		// pass empty info in the response.
943
-		if ( is_child_theme() ) {
944
-			$parent_theme      = wp_get_theme( $active_theme->template );
943
+		if (is_child_theme()) {
944
+			$parent_theme      = wp_get_theme($active_theme->template);
945 945
 			$parent_theme_info = array(
946 946
 				'parent_name'           => $parent_theme->name,
947 947
 				'parent_version'        => $parent_theme->version,
948
-				'parent_version_latest' => \WC_Admin_Status::get_latest_theme_version( $parent_theme ),
948
+				'parent_version_latest' => \WC_Admin_Status::get_latest_theme_version($parent_theme),
949 949
 				'parent_author_url'     => $parent_theme->{'Author URI'},
950 950
 			);
951 951
 		} else {
@@ -963,34 +963,34 @@  discard block
 block discarded – undo
963 963
 		 */
964 964
 		$override_files     = array();
965 965
 		$outdated_templates = false;
966
-		$scan_files         = \WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates/' );
967
-		foreach ( $scan_files as $file ) {
968
-			$located = apply_filters( 'wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/' );
966
+		$scan_files         = \WC_Admin_Status::scan_template_files(WC()->plugin_path() . '/templates/');
967
+		foreach ($scan_files as $file) {
968
+			$located = apply_filters('wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/');
969 969
 
970
-			if ( file_exists( $located ) ) {
970
+			if (file_exists($located)) {
971 971
 				$theme_file = $located;
972
-			} elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
972
+			} elseif (file_exists(get_stylesheet_directory() . '/' . $file)) {
973 973
 				$theme_file = get_stylesheet_directory() . '/' . $file;
974
-			} elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) {
974
+			} elseif (file_exists(get_stylesheet_directory() . '/' . WC()->template_path() . $file)) {
975 975
 				$theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file;
976
-			} elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
976
+			} elseif (file_exists(get_template_directory() . '/' . $file)) {
977 977
 				$theme_file = get_template_directory() . '/' . $file;
978
-			} elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) {
978
+			} elseif (file_exists(get_template_directory() . '/' . WC()->template_path() . $file)) {
979 979
 				$theme_file = get_template_directory() . '/' . WC()->template_path() . $file;
980 980
 			} else {
981 981
 				$theme_file = false;
982 982
 			}
983 983
 
984
-			if ( ! empty( $theme_file ) ) {
985
-				$core_version  = \WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file );
986
-				$theme_version = \WC_Admin_Status::get_file_version( $theme_file );
987
-				if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) {
988
-					if ( ! $outdated_templates ) {
984
+			if ( ! empty($theme_file)) {
985
+				$core_version  = \WC_Admin_Status::get_file_version(WC()->plugin_path() . '/templates/' . $file);
986
+				$theme_version = \WC_Admin_Status::get_file_version($theme_file);
987
+				if ($core_version && (empty($theme_version) || version_compare($theme_version, $core_version, '<'))) {
988
+					if ( ! $outdated_templates) {
989 989
 						$outdated_templates = true;
990 990
 					}
991 991
 				}
992 992
 				$override_files[] = array(
993
-					'file'         => str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ),
993
+					'file'         => str_replace(WP_CONTENT_DIR . '/themes/', '', $theme_file),
994 994
 					'version'      => $theme_version,
995 995
 					'core_version' => $core_version,
996 996
 				);
@@ -1000,16 +1000,16 @@  discard block
 block discarded – undo
1000 1000
 		$active_theme_info = array(
1001 1001
 			'name'                    => $active_theme->name,
1002 1002
 			'version'                 => $active_theme->version,
1003
-			'version_latest'          => \WC_Admin_Status::get_latest_theme_version( $active_theme ),
1004
-			'author_url'              => esc_url_raw( $active_theme->{'Author URI'} ),
1003
+			'version_latest'          => \WC_Admin_Status::get_latest_theme_version($active_theme),
1004
+			'author_url'              => esc_url_raw($active_theme->{'Author URI'} ),
1005 1005
 			'is_child_theme'          => is_child_theme(),
1006
-			'has_woocommerce_support' => current_theme_supports( 'woocommerce' ),
1007
-			'has_woocommerce_file'    => ( file_exists( get_stylesheet_directory() . '/woocommerce.php' ) || file_exists( get_template_directory() . '/woocommerce.php' ) ),
1006
+			'has_woocommerce_support' => current_theme_supports('woocommerce'),
1007
+			'has_woocommerce_file'    => (file_exists(get_stylesheet_directory() . '/woocommerce.php') || file_exists(get_template_directory() . '/woocommerce.php')),
1008 1008
 			'has_outdated_templates'  => $outdated_templates,
1009 1009
 			'overrides'               => $override_files,
1010 1010
 		);
1011 1011
 
1012
-		return array_merge( $active_theme_info, $parent_theme_info );
1012
+		return array_merge($active_theme_info, $parent_theme_info);
1013 1013
 	}
1014 1014
 
1015 1015
 	/**
@@ -1021,36 +1021,36 @@  discard block
 block discarded – undo
1021 1021
 	public function get_settings() {
1022 1022
 		// Get a list of terms used for product/order taxonomies.
1023 1023
 		$term_response = array();
1024
-		$terms         = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
1025
-		foreach ( $terms as $term ) {
1026
-			$term_response[ $term->slug ] = strtolower( $term->name );
1024
+		$terms         = get_terms('product_type', array('hide_empty' => 0));
1025
+		foreach ($terms as $term) {
1026
+			$term_response[$term->slug] = strtolower($term->name);
1027 1027
 		}
1028 1028
 
1029 1029
 		// Get a list of terms used for product visibility.
1030 1030
 		$product_visibility_terms = array();
1031
-		$terms                    = get_terms( 'product_visibility', array( 'hide_empty' => 0 ) );
1032
-		foreach ( $terms as $term ) {
1033
-			$product_visibility_terms[ $term->slug ] = strtolower( $term->name );
1031
+		$terms                    = get_terms('product_visibility', array('hide_empty' => 0));
1032
+		foreach ($terms as $term) {
1033
+			$product_visibility_terms[$term->slug] = strtolower($term->name);
1034 1034
 		}
1035 1035
 
1036 1036
 		// Check if WooCommerce.com account is connected.
1037 1037
 		$woo_com_connected = 'no';
1038
-		$helper_options    = get_option( 'woocommerce_helper_data', array() );
1039
-		if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) {
1038
+		$helper_options    = get_option('woocommerce_helper_data', array());
1039
+		if (array_key_exists('auth', $helper_options) && ! empty($helper_options['auth'])) {
1040 1040
 			$woo_com_connected = 'yes';
1041 1041
 		}
1042 1042
 
1043 1043
 		// Return array of useful settings for debugging.
1044 1044
 		return array(
1045
-			'api_enabled'               => 'yes' === get_option( 'woocommerce_api_enabled' ),
1046
-			'force_ssl'                 => 'yes' === get_option( 'woocommerce_force_ssl_checkout' ),
1045
+			'api_enabled'               => 'yes' === get_option('woocommerce_api_enabled'),
1046
+			'force_ssl'                 => 'yes' === get_option('woocommerce_force_ssl_checkout'),
1047 1047
 			'currency'                  => get_woocommerce_currency(),
1048 1048
 			'currency_symbol'           => get_woocommerce_currency_symbol(),
1049
-			'currency_position'         => get_option( 'woocommerce_currency_pos' ),
1049
+			'currency_position'         => get_option('woocommerce_currency_pos'),
1050 1050
 			'thousand_separator'        => wc_get_price_thousand_separator(),
1051 1051
 			'decimal_separator'         => wc_get_price_decimal_separator(),
1052 1052
 			'number_of_decimals'        => wc_get_price_decimals(),
1053
-			'geolocation_enabled'       => in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation' ) ),
1053
+			'geolocation_enabled'       => in_array(get_option('woocommerce_default_customer_address'), array('geolocation_ajax', 'geolocation')),
1054 1054
 			'taxonomies'                => $term_response,
1055 1055
 			'product_visibility_terms'  => $product_visibility_terms,
1056 1056
 			'woocommerce_com_connected' => $woo_com_connected,
@@ -1063,10 +1063,10 @@  discard block
 block discarded – undo
1063 1063
 	 * @return array
1064 1064
 	 */
1065 1065
 	public function get_security_info() {
1066
-		$check_page = wc_get_page_permalink( 'shop' );
1066
+		$check_page = wc_get_page_permalink('shop');
1067 1067
 		return array(
1068
-			'secure_connection' => 'https' === substr( $check_page, 0, 5 ),
1069
-			'hide_errors'       => ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ),
1068
+			'secure_connection' => 'https' === substr($check_page, 0, 5),
1069
+			'hide_errors'       => ! (defined('WP_DEBUG') && defined('WP_DEBUG_DISPLAY') && WP_DEBUG && WP_DEBUG_DISPLAY) || 0 === intval(ini_get('display_errors')),
1070 1070
 		);
1071 1071
 	}
1072 1072
 
@@ -1079,31 +1079,31 @@  discard block
 block discarded – undo
1079 1079
 	public function get_pages() {
1080 1080
 		// WC pages to check against.
1081 1081
 		$check_pages = array(
1082
-			_x( 'Shop base', 'Page setting', 'woocommerce' ) => array(
1082
+			_x('Shop base', 'Page setting', 'woocommerce') => array(
1083 1083
 				'option'    => 'woocommerce_shop_page_id',
1084 1084
 				'shortcode' => '',
1085 1085
 			),
1086
-			_x( 'Cart', 'Page setting', 'woocommerce' ) => array(
1086
+			_x('Cart', 'Page setting', 'woocommerce') => array(
1087 1087
 				'option'    => 'woocommerce_cart_page_id',
1088
-				'shortcode' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']',
1088
+				'shortcode' => '[' . apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart') . ']',
1089 1089
 			),
1090
-			_x( 'Checkout', 'Page setting', 'woocommerce' ) => array(
1090
+			_x('Checkout', 'Page setting', 'woocommerce') => array(
1091 1091
 				'option'    => 'woocommerce_checkout_page_id',
1092
-				'shortcode' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']',
1092
+				'shortcode' => '[' . apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout') . ']',
1093 1093
 			),
1094
-			_x( 'My account', 'Page setting', 'woocommerce' ) => array(
1094
+			_x('My account', 'Page setting', 'woocommerce') => array(
1095 1095
 				'option'    => 'woocommerce_myaccount_page_id',
1096
-				'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']',
1096
+				'shortcode' => '[' . apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account') . ']',
1097 1097
 			),
1098
-			_x( 'Terms and conditions', 'Page setting', 'woocommerce' ) => array(
1098
+			_x('Terms and conditions', 'Page setting', 'woocommerce') => array(
1099 1099
 				'option'    => 'woocommerce_terms_page_id',
1100 1100
 				'shortcode' => '',
1101 1101
 			),
1102 1102
 		);
1103 1103
 
1104 1104
 		$pages_output = array();
1105
-		foreach ( $check_pages as $page_name => $values ) {
1106
-			$page_id            = get_option( $values['option'] );
1105
+		foreach ($check_pages as $page_name => $values) {
1106
+			$page_id            = get_option($values['option']);
1107 1107
 			$page_set           = false;
1108 1108
 			$page_exists        = false;
1109 1109
 			$page_visible       = false;
@@ -1111,21 +1111,21 @@  discard block
 block discarded – undo
1111 1111
 			$shortcode_required = false;
1112 1112
 
1113 1113
 			// Page checks.
1114
-			if ( $page_id ) {
1114
+			if ($page_id) {
1115 1115
 				$page_set = true;
1116 1116
 			}
1117
-			if ( get_post( $page_id ) ) {
1117
+			if (get_post($page_id)) {
1118 1118
 				$page_exists = true;
1119 1119
 			}
1120
-			if ( 'publish' === get_post_status( $page_id ) ) {
1120
+			if ('publish' === get_post_status($page_id)) {
1121 1121
 				$page_visible = true;
1122 1122
 			}
1123 1123
 
1124 1124
 			// Shortcode checks.
1125
-			if ( $values['shortcode'] && get_post( $page_id ) ) {
1125
+			if ($values['shortcode'] && get_post($page_id)) {
1126 1126
 				$shortcode_required = true;
1127
-				$page               = get_post( $page_id );
1128
-				if ( strstr( $page->post_content, $values['shortcode'] ) ) {
1127
+				$page               = get_post($page_id);
1128
+				if (strstr($page->post_content, $values['shortcode'])) {
1129 1129
 					$shortcode_present = true;
1130 1130
 				}
1131 1131
 			}
@@ -1153,7 +1153,7 @@  discard block
 block discarded – undo
1153 1153
 	 */
1154 1154
 	public function get_collection_params() {
1155 1155
 		return array(
1156
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
1156
+			'context' => $this->get_context_param(array('default' => 'view')),
1157 1157
 		);
1158 1158
 	}
1159 1159
 
@@ -1164,11 +1164,11 @@  discard block
 block discarded – undo
1164 1164
 	 * @param  \WP_REST_Request $request       Request object.
1165 1165
 	 * @return \WP_REST_Response
1166 1166
 	 */
1167
-	public function prepare_item_for_response( $system_status, $request ) {
1168
-		$data = $this->add_additional_fields_to_object( $system_status, $request );
1169
-		$data = $this->filter_response_by_context( $data, 'view' );
1167
+	public function prepare_item_for_response($system_status, $request) {
1168
+		$data = $this->add_additional_fields_to_object($system_status, $request);
1169
+		$data = $this->filter_response_by_context($data, 'view');
1170 1170
 
1171
-		$response = rest_ensure_response( $data );
1171
+		$response = rest_ensure_response($data);
1172 1172
 
1173 1173
 		/**
1174 1174
 		 * Filter the system status returned from the REST API.
@@ -1177,6 +1177,6 @@  discard block
 block discarded – undo
1177 1177
 		 * @param mixed              $system_status System status
1178 1178
 		 * @param \WP_REST_Request    $request  Request object.
1179 1179
 		 */
1180
-		return apply_filters( 'woocommerce_rest_prepare_system_status', $response, $system_status, $request );
1180
+		return apply_filters('woocommerce_rest_prepare_system_status', $response, $system_status, $request);
1181 1181
 	}
1182 1182
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Leaderboards.php 1 patch
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Leaderboards class.
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	 * Register routes.
28 28
 	 */
29 29
 	public function register_routes() {
30
-		if ( ! class_exists( 'WC_Admin_Reports_Coupons_Data_Store' ) ) {
30
+		if ( ! class_exists('WC_Admin_Reports_Coupons_Data_Store')) {
31 31
 			return;
32 32
 		}
33 33
 
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 			array(
38 38
 				array(
39 39
 					'methods'             => \WP_REST_Server::READABLE,
40
-					'callback'            => array( $this, 'get_items' ),
41
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
40
+					'callback'            => array($this, 'get_items'),
41
+					'permission_callback' => array($this, 'get_items_permissions_check'),
42 42
 					'args'                => $this->get_collection_params(),
43 43
 				),
44
-				'schema' => array( $this, 'get_public_item_schema' ),
44
+				'schema' => array($this, 'get_public_item_schema'),
45 45
 			),
46 46
 			true
47 47
 		);
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
 			array(
53 53
 				array(
54 54
 					'methods'             => \WP_REST_Server::READABLE,
55
-					'callback'            => array( $this, 'get_allowed_items' ),
56
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
55
+					'callback'            => array($this, 'get_allowed_items'),
56
+					'permission_callback' => array($this, 'get_items_permissions_check'),
57 57
 				),
58
-				'schema' => array( $this, 'get_public_allowed_item_schema' ),
58
+				'schema' => array($this, 'get_public_allowed_item_schema'),
59 59
 			),
60 60
 			true
61 61
 		);
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @param string $before Items before date.
70 70
 	 * @param string $persisted_query URL query string.
71 71
 	 */
72
-	public function get_coupons_leaderboard( $per_page, $after, $before, $persisted_query ) {
72
+	public function get_coupons_leaderboard($per_page, $after, $before, $persisted_query) {
73 73
 		$coupons_data_store = new \WC_Admin_Reports_Coupons_Data_Store();
74 74
 		$coupons_data       = $per_page > 0 ? $coupons_data_store->get_data(
75 75
 			array(
@@ -83,27 +83,27 @@  discard block
 block discarded – undo
83 83
 		)->data : array();
84 84
 
85 85
 		$rows = array();
86
-		foreach ( $coupons_data as $coupon ) {
87
-			$url_query   = wp_parse_args(
86
+		foreach ($coupons_data as $coupon) {
87
+			$url_query = wp_parse_args(
88 88
 				array(
89 89
 					'filter'  => 'single_coupon',
90 90
 					'coupons' => $coupon['coupon_id'],
91 91
 				),
92 92
 				$persisted_query
93 93
 			);
94
-			$coupon_url  = wc_admin_url( 'analytics/coupons', $url_query );
95
-			$coupon_code = isset( $coupon['extended_info'] ) && isset( $coupon['extended_info']['code'] ) ? $coupon['extended_info']['code'] : '';
94
+			$coupon_url  = wc_admin_url('analytics/coupons', $url_query);
95
+			$coupon_code = isset($coupon['extended_info']) && isset($coupon['extended_info']['code']) ? $coupon['extended_info']['code'] : '';
96 96
 			$rows[]      = array(
97 97
 				array(
98 98
 					'display' => "<a href='{$coupon_url}'>{$coupon_code}</a>",
99 99
 					'value'   => $coupon_code,
100 100
 				),
101 101
 				array(
102
-					'display' => wc_admin_number_format( $coupon['orders_count'] ),
102
+					'display' => wc_admin_number_format($coupon['orders_count']),
103 103
 					'value'   => $coupon['orders_count'],
104 104
 				),
105 105
 				array(
106
-					'display' => wc_price( $coupon['amount'] ),
106
+					'display' => wc_price($coupon['amount']),
107 107
 					'value'   => $coupon['amount'],
108 108
 				),
109 109
 			);
@@ -111,16 +111,16 @@  discard block
 block discarded – undo
111 111
 
112 112
 		return array(
113 113
 			'id'      => 'coupons',
114
-			'label'   => __( 'Top Coupons - Number of Orders', 'woocommerce' ),
114
+			'label'   => __('Top Coupons - Number of Orders', 'woocommerce'),
115 115
 			'headers' => array(
116 116
 				array(
117
-					'label' => __( 'Coupon Code', 'woocommerce' ),
117
+					'label' => __('Coupon Code', 'woocommerce'),
118 118
 				),
119 119
 				array(
120
-					'label' => __( 'Orders', 'woocommerce' ),
120
+					'label' => __('Orders', 'woocommerce'),
121 121
 				),
122 122
 				array(
123
-					'label' => __( 'Amount Discounted', 'woocommerce' ),
123
+					'label' => __('Amount Discounted', 'woocommerce'),
124 124
 				),
125 125
 			),
126 126
 			'rows'    => $rows,
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	 * @param string $before Items before date.
136 136
 	 * @param string $persisted_query URL query string.
137 137
 	 */
138
-	public function get_categories_leaderboard( $per_page, $after, $before, $persisted_query ) {
138
+	public function get_categories_leaderboard($per_page, $after, $before, $persisted_query) {
139 139
 		$categories_data_store = new \WC_Admin_Reports_Categories_Data_Store();
140 140
 		$categories_data       = $per_page > 0 ? $categories_data_store->get_data(
141 141
 			array(
@@ -149,27 +149,27 @@  discard block
 block discarded – undo
149 149
 		)->data : array();
150 150
 
151 151
 		$rows = array();
152
-		foreach ( $categories_data as $category ) {
153
-			$url_query     = wp_parse_args(
152
+		foreach ($categories_data as $category) {
153
+			$url_query = wp_parse_args(
154 154
 				array(
155 155
 					'filter'     => 'single_category',
156 156
 					'categories' => $category['category_id'],
157 157
 				),
158 158
 				$persisted_query
159 159
 			);
160
-			$category_url  = wc_admin_url( 'analytics/categories', $url_query );
161
-			$category_name = isset( $category['extended_info'] ) && isset( $category['extended_info']['name'] ) ? $category['extended_info']['name'] : '';
160
+			$category_url  = wc_admin_url('analytics/categories', $url_query);
161
+			$category_name = isset($category['extended_info']) && isset($category['extended_info']['name']) ? $category['extended_info']['name'] : '';
162 162
 			$rows[]        = array(
163 163
 				array(
164 164
 					'display' => "<a href='{$category_url}'>{$category_name}</a>",
165 165
 					'value'   => $category_name,
166 166
 				),
167 167
 				array(
168
-					'display' => wc_admin_number_format( $category['items_sold'] ),
168
+					'display' => wc_admin_number_format($category['items_sold']),
169 169
 					'value'   => $category['items_sold'],
170 170
 				),
171 171
 				array(
172
-					'display' => wc_price( $category['net_revenue'] ),
172
+					'display' => wc_price($category['net_revenue']),
173 173
 					'value'   => $category['net_revenue'],
174 174
 				),
175 175
 			);
@@ -177,16 +177,16 @@  discard block
 block discarded – undo
177 177
 
178 178
 		return array(
179 179
 			'id'      => 'categories',
180
-			'label'   => __( 'Top Categories - Items Sold', 'woocommerce' ),
180
+			'label'   => __('Top Categories - Items Sold', 'woocommerce'),
181 181
 			'headers' => array(
182 182
 				array(
183
-					'label' => __( 'Category', 'woocommerce' ),
183
+					'label' => __('Category', 'woocommerce'),
184 184
 				),
185 185
 				array(
186
-					'label' => __( 'Items Sold', 'woocommerce' ),
186
+					'label' => __('Items Sold', 'woocommerce'),
187 187
 				),
188 188
 				array(
189
-					'label' => __( 'Net Revenue', 'woocommerce' ),
189
+					'label' => __('Net Revenue', 'woocommerce'),
190 190
 				),
191 191
 			),
192 192
 			'rows'    => $rows,
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 * @param string $before Items before date.
202 202
 	 * @param string $persisted_query URL query string.
203 203
 	 */
204
-	public function get_customers_leaderboard( $per_page, $after, $before, $persisted_query ) {
204
+	public function get_customers_leaderboard($per_page, $after, $before, $persisted_query) {
205 205
 		$customers_data_store = new \WC_Admin_Reports_Customers_Data_Store();
206 206
 		$customers_data       = $per_page > 0 ? $customers_data_store->get_data(
207 207
 			array(
@@ -214,26 +214,26 @@  discard block
 block discarded – undo
214 214
 		)->data : array();
215 215
 
216 216
 		$rows = array();
217
-		foreach ( $customers_data as $customer ) {
218
-			$url_query    = wp_parse_args(
217
+		foreach ($customers_data as $customer) {
218
+			$url_query = wp_parse_args(
219 219
 				array(
220 220
 					'filter'    => 'single_customer',
221 221
 					'customers' => $customer['id'],
222 222
 				),
223 223
 				$persisted_query
224 224
 			);
225
-			$customer_url = wc_admin_url( 'analytics/customers', $url_query );
225
+			$customer_url = wc_admin_url('analytics/customers', $url_query);
226 226
 			$rows[]       = array(
227 227
 				array(
228 228
 					'display' => "<a href='{$customer_url}'>{$customer['name']}</a>",
229 229
 					'value'   => $customer['name'],
230 230
 				),
231 231
 				array(
232
-					'display' => wc_admin_number_format( $customer['orders_count'] ),
232
+					'display' => wc_admin_number_format($customer['orders_count']),
233 233
 					'value'   => $customer['orders_count'],
234 234
 				),
235 235
 				array(
236
-					'display' => wc_price( $customer['total_spend'] ),
236
+					'display' => wc_price($customer['total_spend']),
237 237
 					'value'   => $customer['total_spend'],
238 238
 				),
239 239
 			);
@@ -241,16 +241,16 @@  discard block
 block discarded – undo
241 241
 
242 242
 		return array(
243 243
 			'id'      => 'customers',
244
-			'label'   => __( 'Top Customers - Total Spend', 'woocommerce' ),
244
+			'label'   => __('Top Customers - Total Spend', 'woocommerce'),
245 245
 			'headers' => array(
246 246
 				array(
247
-					'label' => __( 'Customer Name', 'woocommerce' ),
247
+					'label' => __('Customer Name', 'woocommerce'),
248 248
 				),
249 249
 				array(
250
-					'label' => __( 'Orders', 'woocommerce' ),
250
+					'label' => __('Orders', 'woocommerce'),
251 251
 				),
252 252
 				array(
253
-					'label' => __( 'Total Spend', 'woocommerce' ),
253
+					'label' => __('Total Spend', 'woocommerce'),
254 254
 				),
255 255
 			),
256 256
 			'rows'    => $rows,
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 	 * @param string $before Items before date.
266 266
 	 * @param string $persisted_query URL query string.
267 267
 	 */
268
-	public function get_products_leaderboard( $per_page, $after, $before, $persisted_query ) {
268
+	public function get_products_leaderboard($per_page, $after, $before, $persisted_query) {
269 269
 		$products_data_store = new \WC_Admin_Reports_Products_Data_Store();
270 270
 		$products_data       = $per_page > 0 ? $products_data_store->get_data(
271 271
 			array(
@@ -279,27 +279,27 @@  discard block
 block discarded – undo
279 279
 		)->data : array();
280 280
 
281 281
 		$rows = array();
282
-		foreach ( $products_data as $product ) {
283
-			$url_query    = wp_parse_args(
282
+		foreach ($products_data as $product) {
283
+			$url_query = wp_parse_args(
284 284
 				array(
285 285
 					'filter'   => 'single_product',
286 286
 					'products' => $product['product_id'],
287 287
 				),
288 288
 				$persisted_query
289 289
 			);
290
-			$product_url  = wc_admin_url( 'analytics/products', $url_query );
291
-			$product_name = isset( $product['extended_info'] ) && isset( $product['extended_info']['name'] ) ? $product['extended_info']['name'] : '';
290
+			$product_url  = wc_admin_url('analytics/products', $url_query);
291
+			$product_name = isset($product['extended_info']) && isset($product['extended_info']['name']) ? $product['extended_info']['name'] : '';
292 292
 			$rows[]       = array(
293 293
 				array(
294 294
 					'display' => "<a href='{$product_url}'>{$product_name}</a>",
295 295
 					'value'   => $product_name,
296 296
 				),
297 297
 				array(
298
-					'display' => wc_admin_number_format( $product['items_sold'] ),
298
+					'display' => wc_admin_number_format($product['items_sold']),
299 299
 					'value'   => $product['items_sold'],
300 300
 				),
301 301
 				array(
302
-					'display' => wc_price( $product['net_revenue'] ),
302
+					'display' => wc_price($product['net_revenue']),
303 303
 					'value'   => $product['net_revenue'],
304 304
 				),
305 305
 			);
@@ -307,16 +307,16 @@  discard block
 block discarded – undo
307 307
 
308 308
 		return array(
309 309
 			'id'      => 'products',
310
-			'label'   => __( 'Top Products - Items Sold', 'woocommerce' ),
310
+			'label'   => __('Top Products - Items Sold', 'woocommerce'),
311 311
 			'headers' => array(
312 312
 				array(
313
-					'label' => __( 'Product', 'woocommerce' ),
313
+					'label' => __('Product', 'woocommerce'),
314 314
 				),
315 315
 				array(
316
-					'label' => __( 'Items Sold', 'woocommerce' ),
316
+					'label' => __('Items Sold', 'woocommerce'),
317 317
 				),
318 318
 				array(
319
-					'label' => __( 'Net Revenue', 'woocommerce' ),
319
+					'label' => __('Net Revenue', 'woocommerce'),
320 320
 				),
321 321
 			),
322 322
 			'rows'    => $rows,
@@ -332,15 +332,15 @@  discard block
 block discarded – undo
332 332
 	 * @param string $persisted_query URL query string.
333 333
 	 * @return array
334 334
 	 */
335
-	public function get_leaderboards( $per_page, $after, $before, $persisted_query ) {
335
+	public function get_leaderboards($per_page, $after, $before, $persisted_query) {
336 336
 		$leaderboards = array(
337
-			$this->get_customers_leaderboard( $per_page, $after, $before, $persisted_query ),
338
-			$this->get_coupons_leaderboard( $per_page, $after, $before, $persisted_query ),
339
-			$this->get_categories_leaderboard( $per_page, $after, $before, $persisted_query ),
340
-			$this->get_products_leaderboard( $per_page, $after, $before, $persisted_query ),
337
+			$this->get_customers_leaderboard($per_page, $after, $before, $persisted_query),
338
+			$this->get_coupons_leaderboard($per_page, $after, $before, $persisted_query),
339
+			$this->get_categories_leaderboard($per_page, $after, $before, $persisted_query),
340
+			$this->get_products_leaderboard($per_page, $after, $before, $persisted_query),
341 341
 		);
342 342
 
343
-		return apply_filters( 'woocommerce_leaderboards', $leaderboards, $per_page, $after, $before, $persisted_query );
343
+		return apply_filters('woocommerce_leaderboards', $leaderboards, $per_page, $after, $before, $persisted_query);
344 344
 	}
345 345
 
346 346
 	/**
@@ -349,19 +349,19 @@  discard block
 block discarded – undo
349 349
 	 * @param  \WP_REST_Request $request Request data.
350 350
 	 * @return \WP_Error\WP_REST_Response
351 351
 	 */
352
-	public function get_items( $request ) {
353
-		$persisted_query = json_decode( $request['persisted_query'], true );
354
-		$leaderboards    = $this->get_leaderboards( $request['per_page'], $request['after'], $request['before'], $persisted_query );
352
+	public function get_items($request) {
353
+		$persisted_query = json_decode($request['persisted_query'], true);
354
+		$leaderboards    = $this->get_leaderboards($request['per_page'], $request['after'], $request['before'], $persisted_query);
355 355
 		$data            = array();
356 356
 
357
-		if ( ! empty( $leaderboards ) ) {
358
-			foreach ( $leaderboards as $leaderboard ) {
359
-				$response = $this->prepare_item_for_response( $leaderboard, $request );
360
-				$data[]   = $this->prepare_response_for_collection( $response );
357
+		if ( ! empty($leaderboards)) {
358
+			foreach ($leaderboards as $leaderboard) {
359
+				$response = $this->prepare_item_for_response($leaderboard, $request);
360
+				$data[]   = $this->prepare_response_for_collection($response);
361 361
 			}
362 362
 		}
363 363
 
364
-		return rest_ensure_response( $data );
364
+		return rest_ensure_response($data);
365 365
 	}
366 366
 
367 367
 	/**
@@ -370,11 +370,11 @@  discard block
 block discarded – undo
370 370
 	 * @param  \WP_REST_Request $request Request data.
371 371
 	 * @return array|\WP_Error
372 372
 	 */
373
-	public function get_allowed_items( $request ) {
374
-		$leaderboards = $this->get_leaderboards( 0, null, null, null );
373
+	public function get_allowed_items($request) {
374
+		$leaderboards = $this->get_leaderboards(0, null, null, null);
375 375
 
376 376
 		$data = array();
377
-		foreach ( $leaderboards as $leaderboard ) {
377
+		foreach ($leaderboards as $leaderboard) {
378 378
 			$data[] = (object) array(
379 379
 				'id'      => $leaderboard['id'],
380 380
 				'label'   => $leaderboard['label'],
@@ -383,16 +383,16 @@  discard block
 block discarded – undo
383 383
 		}
384 384
 
385 385
 		$objects = array();
386
-		foreach ( $data as $item ) {
387
-			$prepared  = $this->prepare_item_for_response( $item, $request );
388
-			$objects[] = $this->prepare_response_for_collection( $prepared );
386
+		foreach ($data as $item) {
387
+			$prepared  = $this->prepare_item_for_response($item, $request);
388
+			$objects[] = $this->prepare_response_for_collection($prepared);
389 389
 		}
390 390
 
391
-		$response = rest_ensure_response( $objects );
392
-		$response->header( 'X-WP-Total', count( $data ) );
393
-		$response->header( 'X-WP-TotalPages', 1 );
391
+		$response = rest_ensure_response($objects);
392
+		$response->header('X-WP-Total', count($data));
393
+		$response->header('X-WP-TotalPages', 1);
394 394
 
395
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
395
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
396 396
 
397 397
 		return $response;
398 398
 	}
@@ -404,10 +404,10 @@  discard block
 block discarded – undo
404 404
 	 * @param \WP_REST_Request $request Request object.
405 405
 	 * @return \WP_REST_Response $response Response data.
406 406
 	 */
407
-	public function prepare_item_for_response( $item, $request ) {
408
-		$data     = $this->add_additional_fields_to_object( $item, $request );
409
-		$data     = $this->filter_response_by_context( $data, 'view' );
410
-		$response = rest_ensure_response( $data );
407
+	public function prepare_item_for_response($item, $request) {
408
+		$data     = $this->add_additional_fields_to_object($item, $request);
409
+		$data     = $this->filter_response_by_context($data, 'view');
410
+		$response = rest_ensure_response($data);
411 411
 
412 412
 		/**
413 413
 		 * Filter the list returned from the API.
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 		 * @param array            $item     The original item.
417 417
 		 * @param \WP_REST_Request  $request  Request used to generate the response.
418 418
 		 */
419
-		return apply_filters( 'woocommerce_rest_prepare_leaderboard', $response, $item, $request );
419
+		return apply_filters('woocommerce_rest_prepare_leaderboard', $response, $item, $request);
420 420
 	}
421 421
 
422 422
 	/**
@@ -427,15 +427,15 @@  discard block
 block discarded – undo
427 427
 	public function get_collection_params() {
428 428
 		$params                    = array();
429 429
 		$params['page']            = array(
430
-			'description'       => __( 'Current page of the collection.', 'woocommerce' ),
430
+			'description'       => __('Current page of the collection.', 'woocommerce'),
431 431
 			'type'              => 'integer',
432 432
 			'default'           => 1,
433 433
 			'sanitize_callback' => 'absint',
434 434
 			'validate_callback' => 'rest_validate_request_arg',
435 435
 			'minimum'           => 1,
436 436
 		);
437
-		$params['per_page']        = array(
438
-			'description'       => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
437
+		$params['per_page'] = array(
438
+			'description'       => __('Maximum number of items to be returned in result set.', 'woocommerce'),
439 439
 			'type'              => 'integer',
440 440
 			'default'           => 5,
441 441
 			'minimum'           => 1,
@@ -443,20 +443,20 @@  discard block
 block discarded – undo
443 443
 			'sanitize_callback' => 'absint',
444 444
 			'validate_callback' => 'rest_validate_request_arg',
445 445
 		);
446
-		$params['after']           = array(
447
-			'description'       => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
446
+		$params['after'] = array(
447
+			'description'       => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
448 448
 			'type'              => 'string',
449 449
 			'format'            => 'date-time',
450 450
 			'validate_callback' => 'rest_validate_request_arg',
451 451
 		);
452
-		$params['before']          = array(
453
-			'description'       => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
452
+		$params['before'] = array(
453
+			'description'       => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
454 454
 			'type'              => 'string',
455 455
 			'format'            => 'date-time',
456 456
 			'validate_callback' => 'rest_validate_request_arg',
457 457
 		);
458 458
 		$params['persisted_query'] = array(
459
-			'description'       => __( 'URL query to persist across links.', 'woocommerce' ),
459
+			'description'       => __('URL query to persist across links.', 'woocommerce'),
460 460
 			'type'              => 'string',
461 461
 			'validate_callback' => 'rest_validate_request_arg',
462 462
 		);
@@ -476,28 +476,28 @@  discard block
 block discarded – undo
476 476
 			'properties' => array(
477 477
 				'id'      => array(
478 478
 					'type'        => 'string',
479
-					'description' => __( 'Leaderboard ID.', 'woocommerce' ),
480
-					'context'     => array( 'view' ),
479
+					'description' => __('Leaderboard ID.', 'woocommerce'),
480
+					'context'     => array('view'),
481 481
 					'readonly'    => true,
482 482
 				),
483 483
 				'label'   => array(
484 484
 					'type'        => 'string',
485
-					'description' => __( 'Displayed title for the leaderboard.', 'woocommerce' ),
486
-					'context'     => array( 'view' ),
485
+					'description' => __('Displayed title for the leaderboard.', 'woocommerce'),
486
+					'context'     => array('view'),
487 487
 					'readonly'    => true,
488 488
 				),
489 489
 				'headers' => array(
490 490
 					'type'        => 'array',
491
-					'description' => __( 'Table headers.', 'woocommerce' ),
492
-					'context'     => array( 'view' ),
491
+					'description' => __('Table headers.', 'woocommerce'),
492
+					'context'     => array('view'),
493 493
 					'readonly'    => true,
494 494
 					'items'       => array(
495 495
 						'type'       => 'array',
496 496
 						'properties' => array(
497 497
 							'label' => array(
498
-								'description' => __( 'Table column header.', 'woocommerce' ),
498
+								'description' => __('Table column header.', 'woocommerce'),
499 499
 								'type'        => 'string',
500
-								'context'     => array( 'view', 'edit' ),
500
+								'context'     => array('view', 'edit'),
501 501
 								'readonly'    => true,
502 502
 							),
503 503
 						),
@@ -505,22 +505,22 @@  discard block
 block discarded – undo
505 505
 				),
506 506
 				'rows'    => array(
507 507
 					'type'        => 'array',
508
-					'description' => __( 'Table rows.', 'woocommerce' ),
509
-					'context'     => array( 'view' ),
508
+					'description' => __('Table rows.', 'woocommerce'),
509
+					'context'     => array('view'),
510 510
 					'readonly'    => true,
511 511
 					'items'       => array(
512 512
 						'type'       => 'array',
513 513
 						'properties' => array(
514 514
 							'display' => array(
515
-								'description' => __( 'Table cell display.', 'woocommerce' ),
515
+								'description' => __('Table cell display.', 'woocommerce'),
516 516
 								'type'        => 'string',
517
-								'context'     => array( 'view', 'edit' ),
517
+								'context'     => array('view', 'edit'),
518 518
 								'readonly'    => true,
519 519
 							),
520 520
 							'value'   => array(
521
-								'description' => __( 'Table cell value.', 'woocommerce' ),
521
+								'description' => __('Table cell value.', 'woocommerce'),
522 522
 								'type'        => 'string',
523
-								'context'     => array( 'view', 'edit' ),
523
+								'context'     => array('view', 'edit'),
524 524
 								'readonly'    => true,
525 525
 							),
526 526
 						),
@@ -529,7 +529,7 @@  discard block
 block discarded – undo
529 529
 			),
530 530
 		);
531 531
 
532
-		return $this->add_additional_fields_schema( $schema );
532
+		return $this->add_additional_fields_schema($schema);
533 533
 	}
534 534
 
535 535
 	/**
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 	 */
540 540
 	public function get_public_allowed_item_schema() {
541 541
 		$schema = $this->get_public_item_schema();
542
-		unset( $schema['properties']['rows'] );
542
+		unset($schema['properties']['rows']);
543 543
 		return $schema;
544 544
 	}
545 545
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Coupons.php 1 patch
Spacing   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Coupons controller class.
@@ -40,26 +40,26 @@  discard block
 block discarded – undo
40 40
 			array(
41 41
 				array(
42 42
 					'methods'             => \WP_REST_Server::READABLE,
43
-					'callback'            => array( $this, 'get_items' ),
44
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
43
+					'callback'            => array($this, 'get_items'),
44
+					'permission_callback' => array($this, 'get_items_permissions_check'),
45 45
 					'args'                => $this->get_collection_params(),
46 46
 				),
47 47
 				array(
48 48
 					'methods'             => \WP_REST_Server::CREATABLE,
49
-					'callback'            => array( $this, 'create_item' ),
50
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
49
+					'callback'            => array($this, 'create_item'),
50
+					'permission_callback' => array($this, 'create_item_permissions_check'),
51 51
 					'args'                => array_merge(
52
-						$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
52
+						$this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
53 53
 						array(
54 54
 							'code' => array(
55
-								'description' => __( 'Coupon code.', 'woocommerce' ),
55
+								'description' => __('Coupon code.', 'woocommerce'),
56 56
 								'required'    => true,
57 57
 								'type'        => 'string',
58 58
 							),
59 59
 						)
60 60
 					),
61 61
 				),
62
-				'schema' => array( $this, 'get_public_item_schema' ),
62
+				'schema' => array($this, 'get_public_item_schema'),
63 63
 			),
64 64
 			true
65 65
 		);
@@ -70,37 +70,37 @@  discard block
 block discarded – undo
70 70
 			array(
71 71
 				'args'   => array(
72 72
 					'id' => array(
73
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
73
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
74 74
 						'type'        => 'integer',
75 75
 					),
76 76
 				),
77 77
 				array(
78 78
 					'methods'             => \WP_REST_Server::READABLE,
79
-					'callback'            => array( $this, 'get_item' ),
80
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
79
+					'callback'            => array($this, 'get_item'),
80
+					'permission_callback' => array($this, 'get_item_permissions_check'),
81 81
 					'args'                => array(
82
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
82
+						'context' => $this->get_context_param(array('default' => 'view')),
83 83
 					),
84 84
 				),
85 85
 				array(
86 86
 					'methods'             => \WP_REST_Server::EDITABLE,
87
-					'callback'            => array( $this, 'update_item' ),
88
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
89
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
87
+					'callback'            => array($this, 'update_item'),
88
+					'permission_callback' => array($this, 'update_item_permissions_check'),
89
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
90 90
 				),
91 91
 				array(
92 92
 					'methods'             => \WP_REST_Server::DELETABLE,
93
-					'callback'            => array( $this, 'delete_item' ),
94
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
93
+					'callback'            => array($this, 'delete_item'),
94
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
95 95
 					'args'                => array(
96 96
 						'force' => array(
97 97
 							'default'     => false,
98 98
 							'type'        => 'boolean',
99
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
99
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
100 100
 						),
101 101
 					),
102 102
 				),
103
-				'schema' => array( $this, 'get_public_item_schema' ),
103
+				'schema' => array($this, 'get_public_item_schema'),
104 104
 			),
105 105
 			true
106 106
 		);
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 			array(
112 112
 				array(
113 113
 					'methods'             => \WP_REST_Server::EDITABLE,
114
-					'callback'            => array( $this, 'batch_items' ),
115
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
116
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
114
+					'callback'            => array($this, 'batch_items'),
115
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
116
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
117 117
 				),
118
-				'schema' => array( $this, 'get_public_batch_schema' ),
118
+				'schema' => array($this, 'get_public_batch_schema'),
119 119
 			),
120 120
 			true
121 121
 		);
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * @param  int $id Object ID.
129 129
 	 * @return WC_Data
130 130
 	 */
131
-	protected function get_object( $id ) {
132
-		return new \WC_Coupon( $id );
131
+	protected function get_object($id) {
132
+		return new \WC_Coupon($id);
133 133
 	}
134 134
 
135 135
 	/**
@@ -139,28 +139,28 @@  discard block
 block discarded – undo
139 139
 	 * @param  WC_Data $object WC_Data instance.
140 140
 	 * @return array
141 141
 	 */
142
-	protected function get_formatted_item_data( $object ) {
142
+	protected function get_formatted_item_data($object) {
143 143
 		$data = $object->get_data();
144 144
 
145
-		$format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' );
146
-		$format_date    = array( 'date_created', 'date_modified', 'date_expires' );
147
-		$format_null    = array( 'usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items' );
145
+		$format_decimal = array('amount', 'minimum_amount', 'maximum_amount');
146
+		$format_date    = array('date_created', 'date_modified', 'date_expires');
147
+		$format_null    = array('usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items');
148 148
 
149 149
 		// Format decimal values.
150
-		foreach ( $format_decimal as $key ) {
151
-			$data[ $key ] = wc_format_decimal( $data[ $key ], 2 );
150
+		foreach ($format_decimal as $key) {
151
+			$data[$key] = wc_format_decimal($data[$key], 2);
152 152
 		}
153 153
 
154 154
 		// Format date values.
155
-		foreach ( $format_date as $key ) {
156
-			$datetime              = $data[ $key ];
157
-			$data[ $key ]          = wc_rest_prepare_date_response( $datetime, false );
158
-			$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
155
+		foreach ($format_date as $key) {
156
+			$datetime              = $data[$key];
157
+			$data[$key]          = wc_rest_prepare_date_response($datetime, false);
158
+			$data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime);
159 159
 		}
160 160
 
161 161
 		// Format null values.
162
-		foreach ( $format_null as $key ) {
163
-			$data[ $key ] = $data[ $key ] ? $data[ $key ] : null;
162
+		foreach ($format_null as $key) {
163
+			$data[$key] = $data[$key] ? $data[$key] : null;
164 164
 		}
165 165
 
166 166
 		return array(
@@ -202,13 +202,13 @@  discard block
 block discarded – undo
202 202
 	 * @param  \WP_REST_Request $request Request object.
203 203
 	 * @return \WP_REST_Response
204 204
 	 */
205
-	public function prepare_object_for_response( $object, $request ) {
206
-		$data     = $this->get_formatted_item_data( $object );
207
-		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
208
-		$data     = $this->add_additional_fields_to_object( $data, $request );
209
-		$data     = $this->filter_response_by_context( $data, $context );
210
-		$response = rest_ensure_response( $data );
211
-		$response->add_links( $this->prepare_links( $object, $request ) );
205
+	public function prepare_object_for_response($object, $request) {
206
+		$data     = $this->get_formatted_item_data($object);
207
+		$context  = ! empty($request['context']) ? $request['context'] : 'view';
208
+		$data     = $this->add_additional_fields_to_object($data, $request);
209
+		$data     = $this->filter_response_by_context($data, $context);
210
+		$response = rest_ensure_response($data);
211
+		$response->add_links($this->prepare_links($object, $request));
212 212
 
213 213
 		/**
214 214
 		 * Filter the data for a response.
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 		 * @param WC_Data          $object   Object data.
221 221
 		 * @param \WP_REST_Request  $request  Request object.
222 222
 		 */
223
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
223
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request);
224 224
 	}
225 225
 
226 226
 	/**
@@ -230,15 +230,15 @@  discard block
 block discarded – undo
230 230
 	 * @param  \WP_REST_Request $request Full details about the request.
231 231
 	 * @return array
232 232
 	 */
233
-	protected function prepare_objects_query( $request ) {
234
-		$args = parent::prepare_objects_query( $request );
233
+	protected function prepare_objects_query($request) {
234
+		$args = parent::prepare_objects_query($request);
235 235
 
236
-		if ( ! empty( $request['code'] ) ) {
237
-			$id               = wc_get_coupon_id_by_code( $request['code'] );
238
-			$args['post__in'] = array( $id );
236
+		if ( ! empty($request['code'])) {
237
+			$id               = wc_get_coupon_id_by_code($request['code']);
238
+			$args['post__in'] = array($id);
239 239
 		}
240 240
 
241
-		if ( ! empty( $request['search'] ) ) {
241
+		if ( ! empty($request['search'])) {
242 242
 			$args['search'] = $request['search'];
243 243
 			$args['s']      = false;
244 244
 		}
@@ -253,47 +253,47 @@  discard block
 block discarded – undo
253 253
 	 * @param  bool             $creating If is creating a new object.
254 254
 	 * @return \WP_Error|WC_Data
255 255
 	 */
256
-	protected function prepare_object_for_database( $request, $creating = false ) {
257
-		$id        = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
258
-		$coupon    = new \WC_Coupon( $id );
256
+	protected function prepare_object_for_database($request, $creating = false) {
257
+		$id        = isset($request['id']) ? absint($request['id']) : 0;
258
+		$coupon    = new \WC_Coupon($id);
259 259
 		$schema    = $this->get_item_schema();
260
-		$data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );
260
+		$data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props')));
261 261
 
262 262
 		// Validate required POST fields.
263
-		if ( $creating && empty( $request['code'] ) ) {
264
-			return new \WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) );
263
+		if ($creating && empty($request['code'])) {
264
+			return new \WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400));
265 265
 		}
266 266
 
267 267
 		// Handle all writable props.
268
-		foreach ( $data_keys as $key ) {
269
-			$value = $request[ $key ];
268
+		foreach ($data_keys as $key) {
269
+			$value = $request[$key];
270 270
 
271
-			if ( ! is_null( $value ) ) {
272
-				switch ( $key ) {
271
+			if ( ! is_null($value)) {
272
+				switch ($key) {
273 273
 					case 'code':
274
-						$coupon_code  = wc_format_coupon_code( $value );
274
+						$coupon_code  = wc_format_coupon_code($value);
275 275
 						$id           = $coupon->get_id() ? $coupon->get_id() : 0;
276
-						$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id );
276
+						$id_from_code = wc_get_coupon_id_by_code($coupon_code, $id);
277 277
 
278
-						if ( $id_from_code ) {
279
-							return new \WP_Error( 'woocommerce_rest_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce' ), array( 'status' => 400 ) );
278
+						if ($id_from_code) {
279
+							return new \WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400));
280 280
 						}
281 281
 
282
-						$coupon->set_code( $coupon_code );
282
+						$coupon->set_code($coupon_code);
283 283
 						break;
284 284
 					case 'meta_data':
285
-						if ( is_array( $value ) ) {
286
-							foreach ( $value as $meta ) {
287
-								$coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
285
+						if (is_array($value)) {
286
+							foreach ($value as $meta) {
287
+								$coupon->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
288 288
 							}
289 289
 						}
290 290
 						break;
291 291
 					case 'description':
292
-						$coupon->set_description( wp_filter_post_kses( $value ) );
292
+						$coupon->set_description(wp_filter_post_kses($value));
293 293
 						break;
294 294
 					default:
295
-						if ( is_callable( array( $coupon, "set_{$key}" ) ) ) {
296
-							$coupon->{"set_{$key}"}( $value );
295
+						if (is_callable(array($coupon, "set_{$key}"))) {
296
+							$coupon->{"set_{$key}"}($value);
297 297
 						}
298 298
 						break;
299 299
 				}
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 		 * @param \WP_REST_Request $request  Request object.
311 311
 		 * @param bool            $creating If is creating a new object.
312 312
 		 */
313
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating );
313
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating);
314 314
 	}
315 315
 
316 316
 	/**
@@ -325,194 +325,194 @@  discard block
 block discarded – undo
325 325
 			'type'       => 'object',
326 326
 			'properties' => array(
327 327
 				'id'                          => array(
328
-					'description' => __( 'Unique identifier for the object.', 'woocommerce' ),
328
+					'description' => __('Unique identifier for the object.', 'woocommerce'),
329 329
 					'type'        => 'integer',
330
-					'context'     => array( 'view', 'edit' ),
330
+					'context'     => array('view', 'edit'),
331 331
 					'readonly'    => true,
332 332
 				),
333 333
 				'code'                        => array(
334
-					'description' => __( 'Coupon code.', 'woocommerce' ),
334
+					'description' => __('Coupon code.', 'woocommerce'),
335 335
 					'type'        => 'string',
336
-					'context'     => array( 'view', 'edit' ),
336
+					'context'     => array('view', 'edit'),
337 337
 				),
338 338
 				'amount'                      => array(
339
-					'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce' ),
339
+					'description' => __('The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce'),
340 340
 					'type'        => 'string',
341
-					'context'     => array( 'view', 'edit' ),
341
+					'context'     => array('view', 'edit'),
342 342
 				),
343 343
 				'date_created'                => array(
344
-					'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce' ),
344
+					'description' => __("The date the coupon was created, in the site's timezone.", 'woocommerce'),
345 345
 					'type'        => 'date-time',
346
-					'context'     => array( 'view', 'edit' ),
346
+					'context'     => array('view', 'edit'),
347 347
 					'readonly'    => true,
348 348
 				),
349 349
 				'date_created_gmt'            => array(
350
-					'description' => __( 'The date the coupon was created, as GMT.', 'woocommerce' ),
350
+					'description' => __('The date the coupon was created, as GMT.', 'woocommerce'),
351 351
 					'type'        => 'date-time',
352
-					'context'     => array( 'view', 'edit' ),
352
+					'context'     => array('view', 'edit'),
353 353
 					'readonly'    => true,
354 354
 				),
355 355
 				'date_modified'               => array(
356
-					'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce' ),
356
+					'description' => __("The date the coupon was last modified, in the site's timezone.", 'woocommerce'),
357 357
 					'type'        => 'date-time',
358
-					'context'     => array( 'view', 'edit' ),
358
+					'context'     => array('view', 'edit'),
359 359
 					'readonly'    => true,
360 360
 				),
361 361
 				'date_modified_gmt'           => array(
362
-					'description' => __( 'The date the coupon was last modified, as GMT.', 'woocommerce' ),
362
+					'description' => __('The date the coupon was last modified, as GMT.', 'woocommerce'),
363 363
 					'type'        => 'date-time',
364
-					'context'     => array( 'view', 'edit' ),
364
+					'context'     => array('view', 'edit'),
365 365
 					'readonly'    => true,
366 366
 				),
367 367
 				'discount_type'               => array(
368
-					'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ),
368
+					'description' => __('Determines the type of discount that will be applied.', 'woocommerce'),
369 369
 					'type'        => 'string',
370 370
 					'default'     => 'fixed_cart',
371
-					'enum'        => array_keys( wc_get_coupon_types() ),
372
-					'context'     => array( 'view', 'edit' ),
371
+					'enum'        => array_keys(wc_get_coupon_types()),
372
+					'context'     => array('view', 'edit'),
373 373
 				),
374 374
 				'description'                 => array(
375
-					'description' => __( 'Coupon description.', 'woocommerce' ),
375
+					'description' => __('Coupon description.', 'woocommerce'),
376 376
 					'type'        => 'string',
377
-					'context'     => array( 'view', 'edit' ),
377
+					'context'     => array('view', 'edit'),
378 378
 				),
379 379
 				'date_expires'                => array(
380
-					'description' => __( "The date the coupon expires, in the site's timezone.", 'woocommerce' ),
380
+					'description' => __("The date the coupon expires, in the site's timezone.", 'woocommerce'),
381 381
 					'type'        => 'string',
382
-					'context'     => array( 'view', 'edit' ),
382
+					'context'     => array('view', 'edit'),
383 383
 				),
384 384
 				'date_expires_gmt'            => array(
385
-					'description' => __( 'The date the coupon expires, as GMT.', 'woocommerce' ),
385
+					'description' => __('The date the coupon expires, as GMT.', 'woocommerce'),
386 386
 					'type'        => 'string',
387
-					'context'     => array( 'view', 'edit' ),
387
+					'context'     => array('view', 'edit'),
388 388
 				),
389 389
 				'usage_count'                 => array(
390
-					'description' => __( 'Number of times the coupon has been used already.', 'woocommerce' ),
390
+					'description' => __('Number of times the coupon has been used already.', 'woocommerce'),
391 391
 					'type'        => 'integer',
392
-					'context'     => array( 'view', 'edit' ),
392
+					'context'     => array('view', 'edit'),
393 393
 					'readonly'    => true,
394 394
 				),
395 395
 				'individual_use'              => array(
396
-					'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce' ),
396
+					'description' => __('If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce'),
397 397
 					'type'        => 'boolean',
398 398
 					'default'     => false,
399
-					'context'     => array( 'view', 'edit' ),
399
+					'context'     => array('view', 'edit'),
400 400
 				),
401 401
 				'product_ids'                 => array(
402
-					'description' => __( 'List of product IDs the coupon can be used on.', 'woocommerce' ),
402
+					'description' => __('List of product IDs the coupon can be used on.', 'woocommerce'),
403 403
 					'type'        => 'array',
404 404
 					'items'       => array(
405 405
 						'type' => 'integer',
406 406
 					),
407
-					'context'     => array( 'view', 'edit' ),
407
+					'context'     => array('view', 'edit'),
408 408
 				),
409 409
 				'excluded_product_ids'        => array(
410
-					'description' => __( 'List of product IDs the coupon cannot be used on.', 'woocommerce' ),
410
+					'description' => __('List of product IDs the coupon cannot be used on.', 'woocommerce'),
411 411
 					'type'        => 'array',
412 412
 					'items'       => array(
413 413
 						'type' => 'integer',
414 414
 					),
415
-					'context'     => array( 'view', 'edit' ),
415
+					'context'     => array('view', 'edit'),
416 416
 				),
417 417
 				'usage_limit'                 => array(
418
-					'description' => __( 'How many times the coupon can be used in total.', 'woocommerce' ),
418
+					'description' => __('How many times the coupon can be used in total.', 'woocommerce'),
419 419
 					'type'        => 'integer',
420
-					'context'     => array( 'view', 'edit' ),
420
+					'context'     => array('view', 'edit'),
421 421
 				),
422 422
 				'usage_limit_per_user'        => array(
423
-					'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce' ),
423
+					'description' => __('How many times the coupon can be used per customer.', 'woocommerce'),
424 424
 					'type'        => 'integer',
425
-					'context'     => array( 'view', 'edit' ),
425
+					'context'     => array('view', 'edit'),
426 426
 				),
427 427
 				'limit_usage_to_x_items'      => array(
428
-					'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'woocommerce' ),
428
+					'description' => __('Max number of items in the cart the coupon can be applied to.', 'woocommerce'),
429 429
 					'type'        => 'integer',
430
-					'context'     => array( 'view', 'edit' ),
430
+					'context'     => array('view', 'edit'),
431 431
 				),
432 432
 				'free_shipping'               => array(
433
-					'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce' ),
433
+					'description' => __('If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce'),
434 434
 					'type'        => 'boolean',
435 435
 					'default'     => false,
436
-					'context'     => array( 'view', 'edit' ),
436
+					'context'     => array('view', 'edit'),
437 437
 				),
438 438
 				'product_categories'          => array(
439
-					'description' => __( 'List of category IDs the coupon applies to.', 'woocommerce' ),
439
+					'description' => __('List of category IDs the coupon applies to.', 'woocommerce'),
440 440
 					'type'        => 'array',
441 441
 					'items'       => array(
442 442
 						'type' => 'integer',
443 443
 					),
444
-					'context'     => array( 'view', 'edit' ),
444
+					'context'     => array('view', 'edit'),
445 445
 				),
446 446
 				'excluded_product_categories' => array(
447
-					'description' => __( 'List of category IDs the coupon does not apply to.', 'woocommerce' ),
447
+					'description' => __('List of category IDs the coupon does not apply to.', 'woocommerce'),
448 448
 					'type'        => 'array',
449 449
 					'items'       => array(
450 450
 						'type' => 'integer',
451 451
 					),
452
-					'context'     => array( 'view', 'edit' ),
452
+					'context'     => array('view', 'edit'),
453 453
 				),
454 454
 				'exclude_sale_items'          => array(
455
-					'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'woocommerce' ),
455
+					'description' => __('If true, this coupon will not be applied to items that have sale prices.', 'woocommerce'),
456 456
 					'type'        => 'boolean',
457 457
 					'default'     => false,
458
-					'context'     => array( 'view', 'edit' ),
458
+					'context'     => array('view', 'edit'),
459 459
 				),
460 460
 				'minimum_amount'              => array(
461
-					'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce' ),
461
+					'description' => __('Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce'),
462 462
 					'type'        => 'string',
463
-					'context'     => array( 'view', 'edit' ),
463
+					'context'     => array('view', 'edit'),
464 464
 				),
465 465
 				'maximum_amount'              => array(
466
-					'description' => __( 'Maximum order amount allowed when using the coupon.', 'woocommerce' ),
466
+					'description' => __('Maximum order amount allowed when using the coupon.', 'woocommerce'),
467 467
 					'type'        => 'string',
468
-					'context'     => array( 'view', 'edit' ),
468
+					'context'     => array('view', 'edit'),
469 469
 				),
470 470
 				'email_restrictions'          => array(
471
-					'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ),
471
+					'description' => __('List of email addresses that can use this coupon.', 'woocommerce'),
472 472
 					'type'        => 'array',
473 473
 					'items'       => array(
474 474
 						'type' => 'string',
475 475
 					),
476
-					'context'     => array( 'view', 'edit' ),
476
+					'context'     => array('view', 'edit'),
477 477
 				),
478 478
 				'used_by'                     => array(
479
-					'description' => __( 'List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce' ),
479
+					'description' => __('List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce'),
480 480
 					'type'        => 'array',
481 481
 					'items'       => array(
482 482
 						'type' => 'integer',
483 483
 					),
484
-					'context'     => array( 'view', 'edit' ),
484
+					'context'     => array('view', 'edit'),
485 485
 					'readonly'    => true,
486 486
 				),
487 487
 				'meta_data'                   => array(
488
-					'description' => __( 'Meta data.', 'woocommerce' ),
488
+					'description' => __('Meta data.', 'woocommerce'),
489 489
 					'type'        => 'array',
490
-					'context'     => array( 'view', 'edit' ),
490
+					'context'     => array('view', 'edit'),
491 491
 					'items'       => array(
492 492
 						'type'       => 'object',
493 493
 						'properties' => array(
494 494
 							'id'    => array(
495
-								'description' => __( 'Meta ID.', 'woocommerce' ),
495
+								'description' => __('Meta ID.', 'woocommerce'),
496 496
 								'type'        => 'integer',
497
-								'context'     => array( 'view', 'edit' ),
497
+								'context'     => array('view', 'edit'),
498 498
 								'readonly'    => true,
499 499
 							),
500 500
 							'key'   => array(
501
-								'description' => __( 'Meta key.', 'woocommerce' ),
501
+								'description' => __('Meta key.', 'woocommerce'),
502 502
 								'type'        => 'string',
503
-								'context'     => array( 'view', 'edit' ),
503
+								'context'     => array('view', 'edit'),
504 504
 							),
505 505
 							'value' => array(
506
-								'description' => __( 'Meta value.', 'woocommerce' ),
506
+								'description' => __('Meta value.', 'woocommerce'),
507 507
 								'type'        => 'mixed',
508
-								'context'     => array( 'view', 'edit' ),
508
+								'context'     => array('view', 'edit'),
509 509
 							),
510 510
 						),
511 511
 					),
512 512
 				),
513 513
 			),
514 514
 		);
515
-		return $this->add_additional_fields_schema( $schema );
515
+		return $this->add_additional_fields_schema($schema);
516 516
 	}
517 517
 
518 518
 	/**
@@ -524,14 +524,14 @@  discard block
 block discarded – undo
524 524
 		$params = parent::get_collection_params();
525 525
 
526 526
 		$params['code'] = array(
527
-			'description'       => __( 'Limit result set to resources with a specific code.', 'woocommerce' ),
527
+			'description'       => __('Limit result set to resources with a specific code.', 'woocommerce'),
528 528
 			'type'              => 'string',
529 529
 			'sanitize_callback' => 'sanitize_text_field',
530 530
 			'validate_callback' => 'rest_validate_request_arg',
531 531
 		);
532 532
 
533 533
 		$params['search'] = array(
534
-			'description'       => __( 'Limit results to coupons with codes matching a given string.', 'woocommerce' ),
534
+			'description'       => __('Limit results to coupons with codes matching a given string.', 'woocommerce'),
535 535
 			'type'              => 'string',
536 536
 			'validate_callback' => 'rest_validate_request_arg',
537 537
 		);
@@ -545,8 +545,8 @@  discard block
 block discarded – undo
545 545
 	 * @param  array $schema Schema array.
546 546
 	 * @return bool
547 547
 	 */
548
-	protected function filter_writable_props( $schema ) {
549
-		return empty( $schema['readonly'] );
548
+	protected function filter_writable_props($schema) {
549
+		return empty($schema['readonly']);
550 550
 	}
551 551
 
552 552
 	/**
@@ -555,10 +555,10 @@  discard block
 block discarded – undo
555 555
 	 * @param \WP_REST_Request $request Full details about the request.
556 556
 	 * @return \WP_Error\WP_REST_Response
557 557
 	 */
558
-	public function get_items( $request ) {
559
-		add_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10, 2 );
560
-		$response = parent::get_items( $request );
561
-		remove_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10 );
558
+	public function get_items($request) {
559
+		add_filter('posts_where', array($this, 'add_wp_query_search_code_filter'), 10, 2);
560
+		$response = parent::get_items($request);
561
+		remove_filter('posts_where', array($this, 'add_wp_query_search_code_filter'), 10);
562 562
 		return $response;
563 563
 	}
564 564
 
@@ -569,12 +569,12 @@  discard block
 block discarded – undo
569 569
 	 * @param object $wp_query \WP_Query object.
570 570
 	 * @return string
571 571
 	 */
572
-	public function add_wp_query_search_code_filter( $where, $wp_query ) {
572
+	public function add_wp_query_search_code_filter($where, $wp_query) {
573 573
 		global $wpdb;
574 574
 
575
-		$search = $wp_query->get( 'search' );
576
-		if ( $search ) {
577
-			$search = $wpdb->esc_like( $search );
575
+		$search = $wp_query->get('search');
576
+		if ($search) {
577
+			$search = $wpdb->esc_like($search);
578 578
 			$search = "'%" . $search . "%'";
579 579
 			$where .= ' AND ' . $wpdb->posts . '.post_title LIKE ' . $search;
580 580
 		}
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Orders.php 1 patch
Spacing   +505 added lines, -505 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Orders controller class.
@@ -54,17 +54,17 @@  discard block
 block discarded – undo
54 54
 			array(
55 55
 				array(
56 56
 					'methods'             => \WP_REST_Server::READABLE,
57
-					'callback'            => array( $this, 'get_items' ),
58
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
57
+					'callback'            => array($this, 'get_items'),
58
+					'permission_callback' => array($this, 'get_items_permissions_check'),
59 59
 					'args'                => $this->get_collection_params(),
60 60
 				),
61 61
 				array(
62 62
 					'methods'             => \WP_REST_Server::CREATABLE,
63
-					'callback'            => array( $this, 'create_item' ),
64
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
65
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
63
+					'callback'            => array($this, 'create_item'),
64
+					'permission_callback' => array($this, 'create_item_permissions_check'),
65
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
66 66
 				),
67
-				'schema' => array( $this, 'get_public_item_schema' ),
67
+				'schema' => array($this, 'get_public_item_schema'),
68 68
 			),
69 69
 			true
70 70
 		);
@@ -75,37 +75,37 @@  discard block
 block discarded – undo
75 75
 			array(
76 76
 				'args'   => array(
77 77
 					'id' => array(
78
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
78
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
79 79
 						'type'        => 'integer',
80 80
 					),
81 81
 				),
82 82
 				array(
83 83
 					'methods'             => \WP_REST_Server::READABLE,
84
-					'callback'            => array( $this, 'get_item' ),
85
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
84
+					'callback'            => array($this, 'get_item'),
85
+					'permission_callback' => array($this, 'get_item_permissions_check'),
86 86
 					'args'                => array(
87
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
87
+						'context' => $this->get_context_param(array('default' => 'view')),
88 88
 					),
89 89
 				),
90 90
 				array(
91 91
 					'methods'             => \WP_REST_Server::EDITABLE,
92
-					'callback'            => array( $this, 'update_item' ),
93
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
94
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
92
+					'callback'            => array($this, 'update_item'),
93
+					'permission_callback' => array($this, 'update_item_permissions_check'),
94
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
95 95
 				),
96 96
 				array(
97 97
 					'methods'             => \WP_REST_Server::DELETABLE,
98
-					'callback'            => array( $this, 'delete_item' ),
99
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
98
+					'callback'            => array($this, 'delete_item'),
99
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
100 100
 					'args'                => array(
101 101
 						'force' => array(
102 102
 							'default'     => false,
103 103
 							'type'        => 'boolean',
104
-							'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
104
+							'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'),
105 105
 						),
106 106
 					),
107 107
 				),
108
-				'schema' => array( $this, 'get_public_item_schema' ),
108
+				'schema' => array($this, 'get_public_item_schema'),
109 109
 			),
110 110
 			true
111 111
 		);
@@ -116,11 +116,11 @@  discard block
 block discarded – undo
116 116
 			array(
117 117
 				array(
118 118
 					'methods'             => \WP_REST_Server::EDITABLE,
119
-					'callback'            => array( $this, 'batch_items' ),
120
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
121
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
119
+					'callback'            => array($this, 'batch_items'),
120
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
121
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
122 122
 				),
123
-				'schema' => array( $this, 'get_public_batch_schema' ),
123
+				'schema' => array($this, 'get_public_batch_schema'),
124 124
 			),
125 125
 			true
126 126
 		);
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 	 * @param  int $id Object ID.
134 134
 	 * @return WC_Data|bool
135 135
 	 */
136
-	protected function get_object( $id ) {
137
-		$order = wc_get_order( $id );
136
+	protected function get_object($id) {
137
+		$order = wc_get_order($id);
138 138
 		// In case id is a refund's id (or it's not an order at all), don't expose it via /orders/ path.
139
-		if ( ! $order || 'shop_order_refund' === $order->get_type() ) {
139
+		if ( ! $order || 'shop_order_refund' === $order->get_type()) {
140 140
 			return false;
141 141
 		}
142 142
 
@@ -149,47 +149,47 @@  discard block
 block discarded – undo
149 149
 	 * @param WC_Order_item $item Order item data.
150 150
 	 * @return array
151 151
 	 */
152
-	protected function get_order_item_data( $item ) {
152
+	protected function get_order_item_data($item) {
153 153
 		$data           = $item->get_data();
154
-		$format_decimal = array( 'subtotal', 'subtotal_tax', 'total', 'total_tax', 'tax_total', 'shipping_tax_total' );
154
+		$format_decimal = array('subtotal', 'subtotal_tax', 'total', 'total_tax', 'tax_total', 'shipping_tax_total');
155 155
 
156 156
 		// Format decimal values.
157
-		foreach ( $format_decimal as $key ) {
158
-			if ( isset( $data[ $key ] ) ) {
159
-				$data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] );
157
+		foreach ($format_decimal as $key) {
158
+			if (isset($data[$key])) {
159
+				$data[$key] = wc_format_decimal($data[$key], $this->request['dp']);
160 160
 			}
161 161
 		}
162 162
 
163 163
 		// Add SKU and PRICE to products.
164
-		if ( is_callable( array( $item, 'get_product' ) ) ) {
164
+		if (is_callable(array($item, 'get_product'))) {
165 165
 			$data['sku']   = $item->get_product() ? $item->get_product()->get_sku() : null;
166 166
 			$data['price'] = $item->get_quantity() ? $item->get_total() / $item->get_quantity() : 0;
167 167
 		}
168 168
 
169 169
 		// Format taxes.
170
-		if ( ! empty( $data['taxes']['total'] ) ) {
170
+		if ( ! empty($data['taxes']['total'])) {
171 171
 			$taxes = array();
172 172
 
173
-			foreach ( $data['taxes']['total'] as $tax_rate_id => $tax ) {
173
+			foreach ($data['taxes']['total'] as $tax_rate_id => $tax) {
174 174
 				$taxes[] = array(
175 175
 					'id'       => $tax_rate_id,
176 176
 					'total'    => $tax,
177
-					'subtotal' => isset( $data['taxes']['subtotal'][ $tax_rate_id ] ) ? $data['taxes']['subtotal'][ $tax_rate_id ] : '',
177
+					'subtotal' => isset($data['taxes']['subtotal'][$tax_rate_id]) ? $data['taxes']['subtotal'][$tax_rate_id] : '',
178 178
 				);
179 179
 			}
180 180
 			$data['taxes'] = $taxes;
181
-		} elseif ( isset( $data['taxes'] ) ) {
181
+		} elseif (isset($data['taxes'])) {
182 182
 			$data['taxes'] = array();
183 183
 		}
184 184
 
185 185
 		// Remove names for coupons, taxes and shipping.
186
-		if ( isset( $data['code'] ) || isset( $data['rate_code'] ) || isset( $data['method_title'] ) ) {
187
-			unset( $data['name'] );
186
+		if (isset($data['code']) || isset($data['rate_code']) || isset($data['method_title'])) {
187
+			unset($data['name']);
188 188
 		}
189 189
 
190 190
 		// Remove props we don't want to expose.
191
-		unset( $data['order_id'] );
192
-		unset( $data['type'] );
191
+		unset($data['order_id']);
192
+		unset($data['type']);
193 193
 
194 194
 		return $data;
195 195
 	}
@@ -201,45 +201,45 @@  discard block
 block discarded – undo
201 201
 	 * @param  WC_Data $object WC_Data instance.
202 202
 	 * @return array
203 203
 	 */
204
-	protected function get_formatted_item_data( $object ) {
204
+	protected function get_formatted_item_data($object) {
205 205
 		$data              = $object->get_data();
206
-		$format_decimal    = array( 'discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax' );
207
-		$format_date       = array( 'date_created', 'date_modified', 'date_completed', 'date_paid' );
208
-		$format_line_items = array( 'line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines' );
206
+		$format_decimal    = array('discount_total', 'discount_tax', 'shipping_total', 'shipping_tax', 'shipping_total', 'shipping_tax', 'cart_tax', 'total', 'total_tax');
207
+		$format_date       = array('date_created', 'date_modified', 'date_completed', 'date_paid');
208
+		$format_line_items = array('line_items', 'tax_lines', 'shipping_lines', 'fee_lines', 'coupon_lines');
209 209
 
210 210
 		// Format decimal values.
211
-		foreach ( $format_decimal as $key ) {
212
-			$data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] );
211
+		foreach ($format_decimal as $key) {
212
+			$data[$key] = wc_format_decimal($data[$key], $this->request['dp']);
213 213
 		}
214 214
 
215 215
 		// Format date values.
216
-		foreach ( $format_date as $key ) {
217
-			$datetime              = $data[ $key ];
218
-			$data[ $key ]          = wc_rest_prepare_date_response( $datetime, false );
219
-			$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
216
+		foreach ($format_date as $key) {
217
+			$datetime              = $data[$key];
218
+			$data[$key]          = wc_rest_prepare_date_response($datetime, false);
219
+			$data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime);
220 220
 		}
221 221
 
222 222
 		// Format the order status.
223
-		$data['status'] = 'wc-' === substr( $data['status'], 0, 3 ) ? substr( $data['status'], 3 ) : $data['status'];
223
+		$data['status'] = 'wc-' === substr($data['status'], 0, 3) ? substr($data['status'], 3) : $data['status'];
224 224
 
225 225
 		// Format line items.
226
-		foreach ( $format_line_items as $key ) {
227
-			$data[ $key ] = array_values( array_map( array( $this, 'get_order_item_data' ), $data[ $key ] ) );
226
+		foreach ($format_line_items as $key) {
227
+			$data[$key] = array_values(array_map(array($this, 'get_order_item_data'), $data[$key]));
228 228
 		}
229 229
 
230 230
 		// Refunds.
231 231
 		$data['refunds'] = array();
232
-		foreach ( $object->get_refunds() as $refund ) {
232
+		foreach ($object->get_refunds() as $refund) {
233 233
 			$data['refunds'][] = array(
234 234
 				'id'     => $refund->get_id(),
235 235
 				'reason' => $refund->get_reason() ? $refund->get_reason() : '',
236
-				'total'  => '-' . wc_format_decimal( $refund->get_amount(), $this->request['dp'] ),
236
+				'total'  => '-' . wc_format_decimal($refund->get_amount(), $this->request['dp']),
237 237
 			);
238 238
 		}
239 239
 
240 240
 		// Currency symbols.
241
-		$currency_symbol         = get_woocommerce_currency_symbol( $data['currency'] );
242
-		$data['currency_symbol'] = html_entity_decode( $currency_symbol );
241
+		$currency_symbol         = get_woocommerce_currency_symbol($data['currency']);
242
+		$data['currency_symbol'] = html_entity_decode($currency_symbol);
243 243
 
244 244
 		return array(
245 245
 			'id'                   => $object->get_id(),
@@ -295,15 +295,15 @@  discard block
 block discarded – undo
295 295
 	 * @param  \WP_REST_Request $request Request object.
296 296
 	 * @return \WP_REST_Response
297 297
 	 */
298
-	public function prepare_object_for_response( $object, $request ) {
298
+	public function prepare_object_for_response($object, $request) {
299 299
 		$this->request       = $request;
300
-		$this->request['dp'] = is_null( $this->request['dp'] ) ? wc_get_price_decimals() : absint( $this->request['dp'] );
301
-		$data                = $this->get_formatted_item_data( $object );
302
-		$context             = ! empty( $request['context'] ) ? $request['context'] : 'view';
303
-		$data                = $this->add_additional_fields_to_object( $data, $request );
304
-		$data                = $this->filter_response_by_context( $data, $context );
305
-		$response            = rest_ensure_response( $data );
306
-		$response->add_links( $this->prepare_links( $object, $request ) );
300
+		$this->request['dp'] = is_null($this->request['dp']) ? wc_get_price_decimals() : absint($this->request['dp']);
301
+		$data                = $this->get_formatted_item_data($object);
302
+		$context             = ! empty($request['context']) ? $request['context'] : 'view';
303
+		$data                = $this->add_additional_fields_to_object($data, $request);
304
+		$data                = $this->filter_response_by_context($data, $context);
305
+		$response            = rest_ensure_response($data);
306
+		$response->add_links($this->prepare_links($object, $request));
307 307
 
308 308
 		/**
309 309
 		 * Filter the data for a response.
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 		 * @param WC_Data          $object   Object data.
316 316
 		 * @param \WP_REST_Request  $request  Request object.
317 317
 		 */
318
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
318
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request);
319 319
 	}
320 320
 
321 321
 	/**
@@ -325,25 +325,25 @@  discard block
 block discarded – undo
325 325
 	 * @param \WP_REST_Request $request Request object.
326 326
 	 * @return array                   Links for the given post.
327 327
 	 */
328
-	protected function prepare_links( $object, $request ) {
328
+	protected function prepare_links($object, $request) {
329 329
 		$links = array(
330 330
 			'self'       => array(
331
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ),
331
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())),
332 332
 			),
333 333
 			'collection' => array(
334
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
334
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
335 335
 			),
336 336
 		);
337 337
 
338
-		if ( 0 !== (int) $object->get_customer_id() ) {
338
+		if (0 !== (int) $object->get_customer_id()) {
339 339
 			$links['customer'] = array(
340
-				'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $object->get_customer_id() ) ),
340
+				'href' => rest_url(sprintf('/%s/customers/%d', $this->namespace, $object->get_customer_id())),
341 341
 			);
342 342
 		}
343 343
 
344
-		if ( 0 !== (int) $object->get_parent_id() ) {
344
+		if (0 !== (int) $object->get_parent_id()) {
345 345
 			$links['up'] = array(
346
-				'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $object->get_parent_id() ) ),
346
+				'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $object->get_parent_id())),
347 347
 			);
348 348
 		}
349 349
 
@@ -357,19 +357,19 @@  discard block
 block discarded – undo
357 357
 	 * @param  \WP_REST_Request $request Full details about the request.
358 358
 	 * @return array
359 359
 	 */
360
-	protected function prepare_objects_query( $request ) {
360
+	protected function prepare_objects_query($request) {
361 361
 		global $wpdb;
362 362
 
363 363
 		// This is needed to get around an array to string notice in \WC_REST_Orders_V2_Controller::prepare_objects_query.
364 364
 		$statuses = $request['status'];
365
-		unset( $request['status'] );
366
-		$args = parent::prepare_objects_query( $request );
365
+		unset($request['status']);
366
+		$args = parent::prepare_objects_query($request);
367 367
 
368 368
 		$args['post_status'] = array();
369
-		foreach ( $statuses as $status ) {
370
-			if ( in_array( $status, $this->get_order_statuses(), true ) ) {
369
+		foreach ($statuses as $status) {
370
+			if (in_array($status, $this->get_order_statuses(), true)) {
371 371
 				$args['post_status'][] = 'wc-' . $status;
372
-			} elseif ( 'any' === $status ) {
372
+			} elseif ('any' === $status) {
373 373
 				// Set status to "any" and short-circuit out.
374 374
 				$args['post_status'] = 'any';
375 375
 				break;
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
 		$request['status'] = $statuses;
383 383
 
384 384
 		// Customer.
385
-		if ( isset( $request['customer'] ) ) {
386
-			if ( ! empty( $args['meta_query'] ) ) {
385
+		if (isset($request['customer'])) {
386
+			if ( ! empty($args['meta_query'])) {
387 387
 				$args['meta_query'] = array(); // WPCS: slow query ok.
388 388
 			}
389 389
 
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 		}
396 396
 
397 397
 		// Search by product.
398
-		if ( ! empty( $request['product'] ) ) {
398
+		if ( ! empty($request['product'])) {
399 399
 			$order_ids = $wpdb->get_col(
400 400
 				$wpdb->prepare(
401 401
 					"SELECT order_id
@@ -407,25 +407,25 @@  discard block
 block discarded – undo
407 407
 			);
408 408
 
409 409
 			// Force WP_Query return empty if don't found any order.
410
-			$order_ids = ! empty( $order_ids ) ? $order_ids : array( 0 );
410
+			$order_ids = ! empty($order_ids) ? $order_ids : array(0);
411 411
 
412 412
 			$args['post__in'] = $order_ids;
413 413
 		}
414 414
 
415 415
 		// Search.
416
-		if ( ! empty( $args['s'] ) ) {
417
-			$order_ids = wc_order_search( $args['s'] );
416
+		if ( ! empty($args['s'])) {
417
+			$order_ids = wc_order_search($args['s']);
418 418
 
419
-			if ( ! empty( $order_ids ) ) {
420
-				unset( $args['s'] );
421
-				$args['post__in'] = array_merge( $order_ids, array( 0 ) );
419
+			if ( ! empty($order_ids)) {
420
+				unset($args['s']);
421
+				$args['post__in'] = array_merge($order_ids, array(0));
422 422
 			}
423 423
 		}
424 424
 
425 425
 		// Search by partial order number.
426
-		if ( ! empty( $request['number'] ) ) {
427
-			$partial_number = trim( $request['number'] );
428
-			$limit          = intval( $args['posts_per_page'] );
426
+		if ( ! empty($request['number'])) {
427
+			$partial_number = trim($request['number']);
428
+			$limit          = intval($args['posts_per_page']);
429 429
 			$order_ids      = $wpdb->get_col(
430 430
 				$wpdb->prepare(
431 431
 					"SELECT ID
@@ -433,13 +433,13 @@  discard block
 block discarded – undo
433 433
 					WHERE post_type = 'shop_order'
434 434
 					AND ID LIKE %s
435 435
 					LIMIT %d",
436
-					$wpdb->esc_like( absint( $partial_number ) ) . '%',
436
+					$wpdb->esc_like(absint($partial_number)) . '%',
437 437
 					$limit
438 438
 				)
439 439
 			);
440 440
 
441 441
 			// Force \WP_Query return empty if don't found any order.
442
-			$order_ids        = empty( $order_ids ) ? array( 0 ) : $order_ids;
442
+			$order_ids        = empty($order_ids) ? array(0) : $order_ids;
443 443
 			$args['post__in'] = $order_ids;
444 444
 		}
445 445
 
@@ -452,8 +452,8 @@  discard block
 block discarded – undo
452 452
 	 * @param  array $schema Schema.
453 453
 	 * @return bool
454 454
 	 */
455
-	protected function filter_writable_props( $schema ) {
456
-		return empty( $schema['readonly'] );
455
+	protected function filter_writable_props($schema) {
456
+		return empty($schema['readonly']);
457 457
 	}
458 458
 
459 459
 
@@ -465,51 +465,51 @@  discard block
 block discarded – undo
465 465
 	 * @param  bool             $creating If is creating a new object.
466 466
 	 * @return \WP_Error|WC_Data
467 467
 	 */
468
-	protected function prepare_object_for_database( $request, $creating = false ) {
469
-		$id        = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
470
-		$order     = new \WC_Order( $id );
468
+	protected function prepare_object_for_database($request, $creating = false) {
469
+		$id        = isset($request['id']) ? absint($request['id']) : 0;
470
+		$order     = new \WC_Order($id);
471 471
 		$schema    = $this->get_item_schema();
472
-		$data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );
472
+		$data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props')));
473 473
 
474 474
 		// Handle all writable props.
475
-		foreach ( $data_keys as $key ) {
476
-			$value = $request[ $key ];
475
+		foreach ($data_keys as $key) {
476
+			$value = $request[$key];
477 477
 
478
-			if ( ! is_null( $value ) ) {
479
-				switch ( $key ) {
478
+			if ( ! is_null($value)) {
479
+				switch ($key) {
480 480
 					case 'coupon_lines':
481 481
 					case 'status':
482 482
 						// Change should be done later so transitions have new data.
483 483
 						break;
484 484
 					case 'billing':
485 485
 					case 'shipping':
486
-						$this->update_address( $order, $value, $key );
486
+						$this->update_address($order, $value, $key);
487 487
 						break;
488 488
 					case 'line_items':
489 489
 					case 'shipping_lines':
490 490
 					case 'fee_lines':
491
-						if ( is_array( $value ) ) {
492
-							foreach ( $value as $item ) {
493
-								if ( is_array( $item ) ) {
494
-									if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) {
495
-										$order->remove_item( $item['id'] );
491
+						if (is_array($value)) {
492
+							foreach ($value as $item) {
493
+								if (is_array($item)) {
494
+									if ($this->item_is_null($item) || (isset($item['quantity']) && 0 === $item['quantity'])) {
495
+										$order->remove_item($item['id']);
496 496
 									} else {
497
-										$this->set_item( $order, $key, $item );
497
+										$this->set_item($order, $key, $item);
498 498
 									}
499 499
 								}
500 500
 							}
501 501
 						}
502 502
 						break;
503 503
 					case 'meta_data':
504
-						if ( is_array( $value ) ) {
505
-							foreach ( $value as $meta ) {
506
-								$order->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
504
+						if (is_array($value)) {
505
+							foreach ($value as $meta) {
506
+								$order->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
507 507
 							}
508 508
 						}
509 509
 						break;
510 510
 					default:
511
-						if ( is_callable( array( $order, "set_{$key}" ) ) ) {
512
-							$order->{"set_{$key}"}( $value );
511
+						if (is_callable(array($order, "set_{$key}"))) {
512
+							$order->{"set_{$key}"}($value);
513 513
 						}
514 514
 						break;
515 515
 				}
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
 		 * @param \WP_REST_Request $request  Request object.
527 527
 		 * @param bool            $creating If is creating a new object.
528 528
 		 */
529
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating );
529
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $order, $request, $creating);
530 530
 	}
531 531
 
532 532
 	/**
@@ -537,62 +537,62 @@  discard block
 block discarded – undo
537 537
 	 * @return WC_Data|\WP_Error
538 538
 	 * @throws \WC_REST_Exception But all errors are validated before returning any data.
539 539
 	 */
540
-	protected function save_object( $request, $creating = false ) {
540
+	protected function save_object($request, $creating = false) {
541 541
 		try {
542
-			$object = $this->prepare_object_for_database( $request, $creating );
542
+			$object = $this->prepare_object_for_database($request, $creating);
543 543
 
544
-			if ( is_wp_error( $object ) ) {
544
+			if (is_wp_error($object)) {
545 545
 				return $object;
546 546
 			}
547 547
 
548 548
 			// Make sure gateways are loaded so hooks from gateways fire on save/create.
549 549
 			WC()->payment_gateways();
550 550
 
551
-			if ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] ) {
551
+			if ( ! is_null($request['customer_id']) && 0 !== $request['customer_id']) {
552 552
 				// Make sure customer exists.
553
-				if ( false === get_user_by( 'id', $request['customer_id'] ) ) {
554
-					throw new \WC_REST_Exception( 'woocommerce_rest_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce' ), 400 );
553
+				if (false === get_user_by('id', $request['customer_id'])) {
554
+					throw new \WC_REST_Exception('woocommerce_rest_invalid_customer_id', __('Customer ID is invalid.', 'woocommerce'), 400);
555 555
 				}
556 556
 
557 557
 				// Make sure customer is part of blog.
558
-				if ( is_multisite() && ! is_user_member_of_blog( $request['customer_id'] ) ) {
559
-					add_user_to_blog( get_current_blog_id(), $request['customer_id'], 'customer' );
558
+				if (is_multisite() && ! is_user_member_of_blog($request['customer_id'])) {
559
+					add_user_to_blog(get_current_blog_id(), $request['customer_id'], 'customer');
560 560
 				}
561 561
 			}
562 562
 
563
-			if ( $creating ) {
564
-				$object->set_created_via( 'rest-api' );
565
-				$object->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
563
+			if ($creating) {
564
+				$object->set_created_via('rest-api');
565
+				$object->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax'));
566 566
 				$object->calculate_totals();
567 567
 			} else {
568 568
 				// If items have changed, recalculate order totals.
569
-				if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) {
570
-					$object->calculate_totals( true );
569
+				if (isset($request['billing']) || isset($request['shipping']) || isset($request['line_items']) || isset($request['shipping_lines']) || isset($request['fee_lines']) || isset($request['coupon_lines'])) {
570
+					$object->calculate_totals(true);
571 571
 				}
572 572
 			}
573 573
 
574 574
 			// Set coupons.
575
-			$this->calculate_coupons( $request, $object );
575
+			$this->calculate_coupons($request, $object);
576 576
 
577 577
 			// Set status.
578
-			if ( ! empty( $request['status'] ) ) {
579
-				$object->set_status( $request['status'] );
578
+			if ( ! empty($request['status'])) {
579
+				$object->set_status($request['status']);
580 580
 			}
581 581
 
582 582
 			$object->save();
583 583
 
584 584
 			// Actions for after the order is saved.
585
-			if ( true === $request['set_paid'] ) {
586
-				if ( $creating || $object->needs_payment() ) {
587
-					$object->payment_complete( $request['transaction_id'] );
585
+			if (true === $request['set_paid']) {
586
+				if ($creating || $object->needs_payment()) {
587
+					$object->payment_complete($request['transaction_id']);
588 588
 				}
589 589
 			}
590 590
 
591
-			return $this->get_object( $object->get_id() );
592
-		} catch ( \WC_Data_Exception $e ) {
593
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
594
-		} catch ( \WC_REST_Exception $e ) {
595
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
591
+			return $this->get_object($object->get_id());
592
+		} catch (\WC_Data_Exception $e) {
593
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
594
+		} catch (\WC_REST_Exception $e) {
595
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
596 596
 		}
597 597
 	}
598 598
 
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
 	 * @param array    $posted Posted data.
604 604
 	 * @param string   $type   Address type.
605 605
 	 */
606
-	protected function update_address( $order, $posted, $type = 'billing' ) {
607
-		foreach ( $posted as $key => $value ) {
608
-			if ( is_callable( array( $order, "set_{$type}_{$key}" ) ) ) {
609
-				$order->{"set_{$type}_{$key}"}( $value );
606
+	protected function update_address($order, $posted, $type = 'billing') {
607
+		foreach ($posted as $key => $value) {
608
+			if (is_callable(array($order, "set_{$type}_{$key}"))) {
609
+				$order->{"set_{$type}_{$key}"}($value);
610 610
 			}
611 611
 		}
612 612
 	}
@@ -618,15 +618,15 @@  discard block
 block discarded – undo
618 618
 	 * @return int
619 619
 	 * @throws \WC_REST_Exception When SKU or ID is not valid.
620 620
 	 */
621
-	protected function get_product_id( $posted ) {
622
-		if ( ! empty( $posted['sku'] ) ) {
623
-			$product_id = (int) wc_get_product_id_by_sku( $posted['sku'] );
624
-		} elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) {
621
+	protected function get_product_id($posted) {
622
+		if ( ! empty($posted['sku'])) {
623
+			$product_id = (int) wc_get_product_id_by_sku($posted['sku']);
624
+		} elseif ( ! empty($posted['product_id']) && empty($posted['variation_id'])) {
625 625
 			$product_id = (int) $posted['product_id'];
626
-		} elseif ( ! empty( $posted['variation_id'] ) ) {
626
+		} elseif ( ! empty($posted['variation_id'])) {
627 627
 			$product_id = (int) $posted['variation_id'];
628 628
 		} else {
629
-			throw new \WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce' ), 400 );
629
+			throw new \WC_REST_Exception('woocommerce_rest_required_product_reference', __('Product ID or SKU is required.', 'woocommerce'), 400);
630 630
 		}
631 631
 		return $product_id;
632 632
 	}
@@ -638,9 +638,9 @@  discard block
 block discarded – undo
638 638
 	 * @param string        $prop   Order property.
639 639
 	 * @param array         $posted Request data.
640 640
 	 */
641
-	protected function maybe_set_item_prop( $item, $prop, $posted ) {
642
-		if ( isset( $posted[ $prop ] ) ) {
643
-			$item->{"set_$prop"}( $posted[ $prop ] );
641
+	protected function maybe_set_item_prop($item, $prop, $posted) {
642
+		if (isset($posted[$prop])) {
643
+			$item->{"set_$prop"}($posted[$prop]);
644 644
 		}
645 645
 	}
646 646
 
@@ -651,9 +651,9 @@  discard block
 block discarded – undo
651 651
 	 * @param string[]      $props  Properties.
652 652
 	 * @param array         $posted Request data.
653 653
 	 */
654
-	protected function maybe_set_item_props( $item, $props, $posted ) {
655
-		foreach ( $props as $prop ) {
656
-			$this->maybe_set_item_prop( $item, $prop, $posted );
654
+	protected function maybe_set_item_props($item, $props, $posted) {
655
+		foreach ($props as $prop) {
656
+			$this->maybe_set_item_prop($item, $prop, $posted);
657 657
 		}
658 658
 	}
659 659
 
@@ -663,12 +663,12 @@  discard block
 block discarded – undo
663 663
 	 * @param WC_Order_Item $item   Order item data.
664 664
 	 * @param array         $posted Request data.
665 665
 	 */
666
-	protected function maybe_set_item_meta_data( $item, $posted ) {
667
-		if ( ! empty( $posted['meta_data'] ) && is_array( $posted['meta_data'] ) ) {
668
-			foreach ( $posted['meta_data'] as $meta ) {
669
-				if ( isset( $meta['key'] ) ) {
670
-					$value = isset( $meta['value'] ) ? $meta['value'] : null;
671
-					$item->update_meta_data( $meta['key'], $value, isset( $meta['id'] ) ? $meta['id'] : '' );
666
+	protected function maybe_set_item_meta_data($item, $posted) {
667
+		if ( ! empty($posted['meta_data']) && is_array($posted['meta_data'])) {
668
+			foreach ($posted['meta_data'] as $meta) {
669
+				if (isset($meta['key'])) {
670
+					$value = isset($meta['value']) ? $meta['value'] : null;
671
+					$item->update_meta_data($meta['key'], $value, isset($meta['id']) ? $meta['id'] : '');
672 672
 				}
673 673
 			}
674 674
 		}
@@ -683,23 +683,23 @@  discard block
 block discarded – undo
683 683
 	 * @return WC_Order_Item_Product
684 684
 	 * @throws WC_REST_Exception Invalid data, server error.
685 685
 	 */
686
-	protected function prepare_line_items( $posted, $action = 'create', $item = null ) {
687
-		$item    = is_null( $item ) ? new \WC_Order_Item_Product( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
688
-		$product = wc_get_product( $this->get_product_id( $posted ) );
689
-
690
-		if ( $product !== $item->get_product() ) {
691
-			$item->set_product( $product );
692
-
693
-			if ( 'create' === $action ) {
694
-				$quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1;
695
-				$total    = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) );
696
-				$item->set_total( $total );
697
-				$item->set_subtotal( $total );
686
+	protected function prepare_line_items($posted, $action = 'create', $item = null) {
687
+		$item    = is_null($item) ? new \WC_Order_Item_Product( ! empty($posted['id']) ? $posted['id'] : '') : $item;
688
+		$product = wc_get_product($this->get_product_id($posted));
689
+
690
+		if ($product !== $item->get_product()) {
691
+			$item->set_product($product);
692
+
693
+			if ('create' === $action) {
694
+				$quantity = isset($posted['quantity']) ? $posted['quantity'] : 1;
695
+				$total    = wc_get_price_excluding_tax($product, array('qty' => $quantity));
696
+				$item->set_total($total);
697
+				$item->set_subtotal($total);
698 698
 			}
699 699
 		}
700 700
 
701
-		$this->maybe_set_item_props( $item, array( 'name', 'quantity', 'total', 'subtotal', 'tax_class' ), $posted );
702
-		$this->maybe_set_item_meta_data( $item, $posted );
701
+		$this->maybe_set_item_props($item, array('name', 'quantity', 'total', 'subtotal', 'tax_class'), $posted);
702
+		$this->maybe_set_item_meta_data($item, $posted);
703 703
 
704 704
 		return $item;
705 705
 	}
@@ -713,17 +713,17 @@  discard block
 block discarded – undo
713 713
 	 * @return WC_Order_Item_Shipping
714 714
 	 * @throws WC_REST_Exception Invalid data, server error.
715 715
 	 */
716
-	protected function prepare_shipping_lines( $posted, $action = 'create', $item = null ) {
717
-		$item = is_null( $item ) ? new \WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
716
+	protected function prepare_shipping_lines($posted, $action = 'create', $item = null) {
717
+		$item = is_null($item) ? new \WC_Order_Item_Shipping( ! empty($posted['id']) ? $posted['id'] : '') : $item;
718 718
 
719
-		if ( 'create' === $action ) {
720
-			if ( empty( $posted['method_id'] ) ) {
721
-				throw new \WC_REST_Exception( 'woocommerce_rest_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce' ), 400 );
719
+		if ('create' === $action) {
720
+			if (empty($posted['method_id'])) {
721
+				throw new \WC_REST_Exception('woocommerce_rest_invalid_shipping_item', __('Shipping method ID is required.', 'woocommerce'), 400);
722 722
 			}
723 723
 		}
724 724
 
725
-		$this->maybe_set_item_props( $item, array( 'method_id', 'method_title', 'total' ), $posted );
726
-		$this->maybe_set_item_meta_data( $item, $posted );
725
+		$this->maybe_set_item_props($item, array('method_id', 'method_title', 'total'), $posted);
726
+		$this->maybe_set_item_meta_data($item, $posted);
727 727
 
728 728
 		return $item;
729 729
 	}
@@ -737,17 +737,17 @@  discard block
 block discarded – undo
737 737
 	 * @return WC_Order_Item_Fee
738 738
 	 * @throws WC_REST_Exception Invalid data, server error.
739 739
 	 */
740
-	protected function prepare_fee_lines( $posted, $action = 'create', $item = null ) {
741
-		$item = is_null( $item ) ? new \WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
740
+	protected function prepare_fee_lines($posted, $action = 'create', $item = null) {
741
+		$item = is_null($item) ? new \WC_Order_Item_Fee( ! empty($posted['id']) ? $posted['id'] : '') : $item;
742 742
 
743
-		if ( 'create' === $action ) {
744
-			if ( empty( $posted['name'] ) ) {
745
-				throw new \WC_REST_Exception( 'woocommerce_rest_invalid_fee_item', __( 'Fee name is required.', 'woocommerce' ), 400 );
743
+		if ('create' === $action) {
744
+			if (empty($posted['name'])) {
745
+				throw new \WC_REST_Exception('woocommerce_rest_invalid_fee_item', __('Fee name is required.', 'woocommerce'), 400);
746 746
 			}
747 747
 		}
748 748
 
749
-		$this->maybe_set_item_props( $item, array( 'name', 'tax_class', 'tax_status', 'total' ), $posted );
750
-		$this->maybe_set_item_meta_data( $item, $posted );
749
+		$this->maybe_set_item_props($item, array('name', 'tax_class', 'tax_status', 'total'), $posted);
750
+		$this->maybe_set_item_meta_data($item, $posted);
751 751
 
752 752
 		return $item;
753 753
 	}
@@ -761,17 +761,17 @@  discard block
 block discarded – undo
761 761
 	 * @return WC_Order_Item_Coupon
762 762
 	 * @throws WC_REST_Exception Invalid data, server error.
763 763
 	 */
764
-	protected function prepare_coupon_lines( $posted, $action = 'create', $item = null ) {
765
-		$item = is_null( $item ) ? new \WC_Order_Item_Coupon( ! empty( $posted['id'] ) ? $posted['id'] : '' ) : $item;
764
+	protected function prepare_coupon_lines($posted, $action = 'create', $item = null) {
765
+		$item = is_null($item) ? new \WC_Order_Item_Coupon( ! empty($posted['id']) ? $posted['id'] : '') : $item;
766 766
 
767
-		if ( 'create' === $action ) {
768
-			if ( empty( $posted['code'] ) ) {
769
-				throw new \WC_REST_Exception( 'woocommerce_rest_invalid_coupon_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 );
767
+		if ('create' === $action) {
768
+			if (empty($posted['code'])) {
769
+				throw new \WC_REST_Exception('woocommerce_rest_invalid_coupon_coupon', __('Coupon code is required.', 'woocommerce'), 400);
770 770
 			}
771 771
 		}
772 772
 
773
-		$this->maybe_set_item_props( $item, array( 'code', 'discount' ), $posted );
774
-		$this->maybe_set_item_meta_data( $item, $posted );
773
+		$this->maybe_set_item_props($item, array('code', 'discount'), $posted);
774
+		$this->maybe_set_item_meta_data($item, $posted);
775 775
 
776 776
 		return $item;
777 777
 	}
@@ -786,10 +786,10 @@  discard block
 block discarded – undo
786 786
 	 * @param array    $posted item provided in the request body.
787 787
 	 * @throws WC_REST_Exception If item ID is not associated with order.
788 788
 	 */
789
-	protected function set_item( $order, $item_type, $posted ) {
789
+	protected function set_item($order, $item_type, $posted) {
790 790
 		global $wpdb;
791 791
 
792
-		if ( ! empty( $posted['id'] ) ) {
792
+		if ( ! empty($posted['id'])) {
793 793
 			$action = 'update';
794 794
 		} else {
795 795
 			$action = 'create';
@@ -799,22 +799,22 @@  discard block
 block discarded – undo
799 799
 		$item   = null;
800 800
 
801 801
 		// Verify provided line item ID is associated with order.
802
-		if ( 'update' === $action ) {
803
-			$item = $order->get_item( absint( $posted['id'] ), false );
802
+		if ('update' === $action) {
803
+			$item = $order->get_item(absint($posted['id']), false);
804 804
 
805
-			if ( ! $item ) {
806
-				throw new \WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 );
805
+			if ( ! $item) {
806
+				throw new \WC_REST_Exception('woocommerce_rest_invalid_item_id', __('Order item ID provided is not associated with order.', 'woocommerce'), 400);
807 807
 			}
808 808
 		}
809 809
 
810 810
 		// Prepare item data.
811
-		$item = $this->$method( $posted, $action, $item );
811
+		$item = $this->$method($posted, $action, $item);
812 812
 
813
-		do_action( 'woocommerce_rest_set_order_item', $item, $posted );
813
+		do_action('woocommerce_rest_set_order_item', $item, $posted);
814 814
 
815 815
 		// If creating the order, add the item to it.
816
-		if ( 'create' === $action ) {
817
-			$order->add_item( $item );
816
+		if ('create' === $action) {
817
+			$order->add_item($item);
818 818
 		} else {
819 819
 			$item->save();
820 820
 		}
@@ -827,11 +827,11 @@  discard block
 block discarded – undo
827 827
 	 * @param array $item Item provided in the request body.
828 828
 	 * @return bool True if the item resource ID is null, false otherwise.
829 829
 	 */
830
-	protected function item_is_null( $item ) {
831
-		$keys = array( 'product_id', 'method_id', 'method_title', 'name', 'code' );
830
+	protected function item_is_null($item) {
831
+		$keys = array('product_id', 'method_id', 'method_title', 'name', 'code');
832 832
 
833
-		foreach ( $keys as $key ) {
834
-			if ( array_key_exists( $key, $item ) && is_null( $item[ $key ] ) ) {
833
+		foreach ($keys as $key) {
834
+			if (array_key_exists($key, $item) && is_null($item[$key])) {
835 835
 				return true;
836 836
 			}
837 837
 		}
@@ -847,8 +847,8 @@  discard block
 block discarded – undo
847 847
 	protected function get_order_statuses() {
848 848
 		$order_statuses = array();
849 849
 
850
-		foreach ( array_keys( wc_get_order_statuses() ) as $status ) {
851
-			$order_statuses[] = str_replace( 'wc-', '', $status );
850
+		foreach (array_keys(wc_get_order_statuses()) as $status) {
851
+			$order_statuses[] = str_replace('wc-', '', $status);
852 852
 		}
853 853
 
854 854
 		return $order_statuses;
@@ -866,543 +866,543 @@  discard block
 block discarded – undo
866 866
 			'type'       => 'object',
867 867
 			'properties' => array(
868 868
 				'id'                   => array(
869
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
869
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
870 870
 					'type'        => 'integer',
871
-					'context'     => array( 'view', 'edit' ),
871
+					'context'     => array('view', 'edit'),
872 872
 					'readonly'    => true,
873 873
 				),
874 874
 				'parent_id'            => array(
875
-					'description' => __( 'Parent order ID.', 'woocommerce' ),
875
+					'description' => __('Parent order ID.', 'woocommerce'),
876 876
 					'type'        => 'integer',
877
-					'context'     => array( 'view', 'edit' ),
877
+					'context'     => array('view', 'edit'),
878 878
 				),
879 879
 				'number'               => array(
880
-					'description' => __( 'Order number.', 'woocommerce' ),
880
+					'description' => __('Order number.', 'woocommerce'),
881 881
 					'type'        => 'string',
882
-					'context'     => array( 'view', 'edit' ),
882
+					'context'     => array('view', 'edit'),
883 883
 					'readonly'    => true,
884 884
 				),
885 885
 				'order_key'            => array(
886
-					'description' => __( 'Order key.', 'woocommerce' ),
886
+					'description' => __('Order key.', 'woocommerce'),
887 887
 					'type'        => 'string',
888
-					'context'     => array( 'view', 'edit' ),
888
+					'context'     => array('view', 'edit'),
889 889
 					'readonly'    => true,
890 890
 				),
891 891
 				'created_via'          => array(
892
-					'description' => __( 'Shows where the order was created.', 'woocommerce' ),
892
+					'description' => __('Shows where the order was created.', 'woocommerce'),
893 893
 					'type'        => 'string',
894
-					'context'     => array( 'view', 'edit' ),
894
+					'context'     => array('view', 'edit'),
895 895
 					'readonly'    => true,
896 896
 				),
897 897
 				'version'              => array(
898
-					'description' => __( 'Version of WooCommerce which last updated the order.', 'woocommerce' ),
898
+					'description' => __('Version of WooCommerce which last updated the order.', 'woocommerce'),
899 899
 					'type'        => 'integer',
900
-					'context'     => array( 'view', 'edit' ),
900
+					'context'     => array('view', 'edit'),
901 901
 					'readonly'    => true,
902 902
 				),
903 903
 				'status'               => array(
904
-					'description' => __( 'Order status.', 'woocommerce' ),
904
+					'description' => __('Order status.', 'woocommerce'),
905 905
 					'type'        => 'string',
906 906
 					'default'     => 'pending',
907 907
 					'enum'        => $this->get_order_statuses(),
908
-					'context'     => array( 'view', 'edit' ),
908
+					'context'     => array('view', 'edit'),
909 909
 				),
910 910
 				'currency'             => array(
911
-					'description' => __( 'Currency the order was created with, in ISO format.', 'woocommerce' ),
911
+					'description' => __('Currency the order was created with, in ISO format.', 'woocommerce'),
912 912
 					'type'        => 'string',
913 913
 					'default'     => get_woocommerce_currency(),
914
-					'enum'        => array_keys( get_woocommerce_currencies() ),
915
-					'context'     => array( 'view', 'edit' ),
914
+					'enum'        => array_keys(get_woocommerce_currencies()),
915
+					'context'     => array('view', 'edit'),
916 916
 				),
917 917
 				'currency_symbol'      => array(
918
-					'description' => __( 'Currency symbol.', 'woocommerce' ),
918
+					'description' => __('Currency symbol.', 'woocommerce'),
919 919
 					'type'        => 'string',
920
-					'context'     => array( 'view', 'edit' ),
920
+					'context'     => array('view', 'edit'),
921 921
 					'readonly'    => true,
922 922
 				),
923 923
 				'date_created'         => array(
924
-					'description' => __( "The date the order was created, in the site's timezone.", 'woocommerce' ),
924
+					'description' => __("The date the order was created, in the site's timezone.", 'woocommerce'),
925 925
 					'type'        => 'date-time',
926
-					'context'     => array( 'view', 'edit' ),
926
+					'context'     => array('view', 'edit'),
927 927
 					'readonly'    => true,
928 928
 				),
929 929
 				'date_created_gmt'     => array(
930
-					'description' => __( 'The date the order was created, as GMT.', 'woocommerce' ),
930
+					'description' => __('The date the order was created, as GMT.', 'woocommerce'),
931 931
 					'type'        => 'date-time',
932
-					'context'     => array( 'view', 'edit' ),
932
+					'context'     => array('view', 'edit'),
933 933
 					'readonly'    => true,
934 934
 				),
935 935
 				'date_modified'        => array(
936
-					'description' => __( "The date the order was last modified, in the site's timezone.", 'woocommerce' ),
936
+					'description' => __("The date the order was last modified, in the site's timezone.", 'woocommerce'),
937 937
 					'type'        => 'date-time',
938
-					'context'     => array( 'view', 'edit' ),
938
+					'context'     => array('view', 'edit'),
939 939
 					'readonly'    => true,
940 940
 				),
941 941
 				'date_modified_gmt'    => array(
942
-					'description' => __( 'The date the order was last modified, as GMT.', 'woocommerce' ),
942
+					'description' => __('The date the order was last modified, as GMT.', 'woocommerce'),
943 943
 					'type'        => 'date-time',
944
-					'context'     => array( 'view', 'edit' ),
944
+					'context'     => array('view', 'edit'),
945 945
 					'readonly'    => true,
946 946
 				),
947 947
 				'discount_total'       => array(
948
-					'description' => __( 'Total discount amount for the order.', 'woocommerce' ),
948
+					'description' => __('Total discount amount for the order.', 'woocommerce'),
949 949
 					'type'        => 'string',
950
-					'context'     => array( 'view', 'edit' ),
950
+					'context'     => array('view', 'edit'),
951 951
 					'readonly'    => true,
952 952
 				),
953 953
 				'discount_tax'         => array(
954
-					'description' => __( 'Total discount tax amount for the order.', 'woocommerce' ),
954
+					'description' => __('Total discount tax amount for the order.', 'woocommerce'),
955 955
 					'type'        => 'string',
956
-					'context'     => array( 'view', 'edit' ),
956
+					'context'     => array('view', 'edit'),
957 957
 					'readonly'    => true,
958 958
 				),
959 959
 				'shipping_total'       => array(
960
-					'description' => __( 'Total shipping amount for the order.', 'woocommerce' ),
960
+					'description' => __('Total shipping amount for the order.', 'woocommerce'),
961 961
 					'type'        => 'string',
962
-					'context'     => array( 'view', 'edit' ),
962
+					'context'     => array('view', 'edit'),
963 963
 					'readonly'    => true,
964 964
 				),
965 965
 				'shipping_tax'         => array(
966
-					'description' => __( 'Total shipping tax amount for the order.', 'woocommerce' ),
966
+					'description' => __('Total shipping tax amount for the order.', 'woocommerce'),
967 967
 					'type'        => 'string',
968
-					'context'     => array( 'view', 'edit' ),
968
+					'context'     => array('view', 'edit'),
969 969
 					'readonly'    => true,
970 970
 				),
971 971
 				'cart_tax'             => array(
972
-					'description' => __( 'Sum of line item taxes only.', 'woocommerce' ),
972
+					'description' => __('Sum of line item taxes only.', 'woocommerce'),
973 973
 					'type'        => 'string',
974
-					'context'     => array( 'view', 'edit' ),
974
+					'context'     => array('view', 'edit'),
975 975
 					'readonly'    => true,
976 976
 				),
977 977
 				'total'                => array(
978
-					'description' => __( 'Grand total.', 'woocommerce' ),
978
+					'description' => __('Grand total.', 'woocommerce'),
979 979
 					'type'        => 'string',
980
-					'context'     => array( 'view', 'edit' ),
980
+					'context'     => array('view', 'edit'),
981 981
 					'readonly'    => true,
982 982
 				),
983 983
 				'total_tax'            => array(
984
-					'description' => __( 'Sum of all taxes.', 'woocommerce' ),
984
+					'description' => __('Sum of all taxes.', 'woocommerce'),
985 985
 					'type'        => 'string',
986
-					'context'     => array( 'view', 'edit' ),
986
+					'context'     => array('view', 'edit'),
987 987
 					'readonly'    => true,
988 988
 				),
989 989
 				'prices_include_tax'   => array(
990
-					'description' => __( 'True the prices included tax during checkout.', 'woocommerce' ),
990
+					'description' => __('True the prices included tax during checkout.', 'woocommerce'),
991 991
 					'type'        => 'boolean',
992
-					'context'     => array( 'view', 'edit' ),
992
+					'context'     => array('view', 'edit'),
993 993
 					'readonly'    => true,
994 994
 				),
995 995
 				'customer_id'          => array(
996
-					'description' => __( 'User ID who owns the order. 0 for guests.', 'woocommerce' ),
996
+					'description' => __('User ID who owns the order. 0 for guests.', 'woocommerce'),
997 997
 					'type'        => 'integer',
998 998
 					'default'     => 0,
999
-					'context'     => array( 'view', 'edit' ),
999
+					'context'     => array('view', 'edit'),
1000 1000
 				),
1001 1001
 				'customer_ip_address'  => array(
1002
-					'description' => __( "Customer's IP address.", 'woocommerce' ),
1002
+					'description' => __("Customer's IP address.", 'woocommerce'),
1003 1003
 					'type'        => 'string',
1004
-					'context'     => array( 'view', 'edit' ),
1004
+					'context'     => array('view', 'edit'),
1005 1005
 					'readonly'    => true,
1006 1006
 				),
1007 1007
 				'customer_user_agent'  => array(
1008
-					'description' => __( 'User agent of the customer.', 'woocommerce' ),
1008
+					'description' => __('User agent of the customer.', 'woocommerce'),
1009 1009
 					'type'        => 'string',
1010
-					'context'     => array( 'view', 'edit' ),
1010
+					'context'     => array('view', 'edit'),
1011 1011
 					'readonly'    => true,
1012 1012
 				),
1013 1013
 				'customer_note'        => array(
1014
-					'description' => __( 'Note left by customer during checkout.', 'woocommerce' ),
1014
+					'description' => __('Note left by customer during checkout.', 'woocommerce'),
1015 1015
 					'type'        => 'string',
1016
-					'context'     => array( 'view', 'edit' ),
1016
+					'context'     => array('view', 'edit'),
1017 1017
 				),
1018 1018
 				'billing'              => array(
1019
-					'description' => __( 'Billing address.', 'woocommerce' ),
1019
+					'description' => __('Billing address.', 'woocommerce'),
1020 1020
 					'type'        => 'object',
1021
-					'context'     => array( 'view', 'edit' ),
1021
+					'context'     => array('view', 'edit'),
1022 1022
 					'properties'  => array(
1023 1023
 						'first_name' => array(
1024
-							'description' => __( 'First name.', 'woocommerce' ),
1024
+							'description' => __('First name.', 'woocommerce'),
1025 1025
 							'type'        => 'string',
1026
-							'context'     => array( 'view', 'edit' ),
1026
+							'context'     => array('view', 'edit'),
1027 1027
 						),
1028 1028
 						'last_name'  => array(
1029
-							'description' => __( 'Last name.', 'woocommerce' ),
1029
+							'description' => __('Last name.', 'woocommerce'),
1030 1030
 							'type'        => 'string',
1031
-							'context'     => array( 'view', 'edit' ),
1031
+							'context'     => array('view', 'edit'),
1032 1032
 						),
1033 1033
 						'company'    => array(
1034
-							'description' => __( 'Company name.', 'woocommerce' ),
1034
+							'description' => __('Company name.', 'woocommerce'),
1035 1035
 							'type'        => 'string',
1036
-							'context'     => array( 'view', 'edit' ),
1036
+							'context'     => array('view', 'edit'),
1037 1037
 						),
1038 1038
 						'address_1'  => array(
1039
-							'description' => __( 'Address line 1', 'woocommerce' ),
1039
+							'description' => __('Address line 1', 'woocommerce'),
1040 1040
 							'type'        => 'string',
1041
-							'context'     => array( 'view', 'edit' ),
1041
+							'context'     => array('view', 'edit'),
1042 1042
 						),
1043 1043
 						'address_2'  => array(
1044
-							'description' => __( 'Address line 2', 'woocommerce' ),
1044
+							'description' => __('Address line 2', 'woocommerce'),
1045 1045
 							'type'        => 'string',
1046
-							'context'     => array( 'view', 'edit' ),
1046
+							'context'     => array('view', 'edit'),
1047 1047
 						),
1048 1048
 						'city'       => array(
1049
-							'description' => __( 'City name.', 'woocommerce' ),
1049
+							'description' => __('City name.', 'woocommerce'),
1050 1050
 							'type'        => 'string',
1051
-							'context'     => array( 'view', 'edit' ),
1051
+							'context'     => array('view', 'edit'),
1052 1052
 						),
1053 1053
 						'state'      => array(
1054
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
1054
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
1055 1055
 							'type'        => 'string',
1056
-							'context'     => array( 'view', 'edit' ),
1056
+							'context'     => array('view', 'edit'),
1057 1057
 						),
1058 1058
 						'postcode'   => array(
1059
-							'description' => __( 'Postal code.', 'woocommerce' ),
1059
+							'description' => __('Postal code.', 'woocommerce'),
1060 1060
 							'type'        => 'string',
1061
-							'context'     => array( 'view', 'edit' ),
1061
+							'context'     => array('view', 'edit'),
1062 1062
 						),
1063 1063
 						'country'    => array(
1064
-							'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ),
1064
+							'description' => __('Country code in ISO 3166-1 alpha-2 format.', 'woocommerce'),
1065 1065
 							'type'        => 'string',
1066
-							'context'     => array( 'view', 'edit' ),
1066
+							'context'     => array('view', 'edit'),
1067 1067
 						),
1068 1068
 						'email'      => array(
1069
-							'description' => __( 'Email address.', 'woocommerce' ),
1069
+							'description' => __('Email address.', 'woocommerce'),
1070 1070
 							'type'        => 'string',
1071 1071
 							'format'      => 'email',
1072
-							'context'     => array( 'view', 'edit' ),
1072
+							'context'     => array('view', 'edit'),
1073 1073
 						),
1074 1074
 						'phone'      => array(
1075
-							'description' => __( 'Phone number.', 'woocommerce' ),
1075
+							'description' => __('Phone number.', 'woocommerce'),
1076 1076
 							'type'        => 'string',
1077
-							'context'     => array( 'view', 'edit' ),
1077
+							'context'     => array('view', 'edit'),
1078 1078
 						),
1079 1079
 					),
1080 1080
 				),
1081 1081
 				'shipping'             => array(
1082
-					'description' => __( 'Shipping address.', 'woocommerce' ),
1082
+					'description' => __('Shipping address.', 'woocommerce'),
1083 1083
 					'type'        => 'object',
1084
-					'context'     => array( 'view', 'edit' ),
1084
+					'context'     => array('view', 'edit'),
1085 1085
 					'properties'  => array(
1086 1086
 						'first_name' => array(
1087
-							'description' => __( 'First name.', 'woocommerce' ),
1087
+							'description' => __('First name.', 'woocommerce'),
1088 1088
 							'type'        => 'string',
1089
-							'context'     => array( 'view', 'edit' ),
1089
+							'context'     => array('view', 'edit'),
1090 1090
 						),
1091 1091
 						'last_name'  => array(
1092
-							'description' => __( 'Last name.', 'woocommerce' ),
1092
+							'description' => __('Last name.', 'woocommerce'),
1093 1093
 							'type'        => 'string',
1094
-							'context'     => array( 'view', 'edit' ),
1094
+							'context'     => array('view', 'edit'),
1095 1095
 						),
1096 1096
 						'company'    => array(
1097
-							'description' => __( 'Company name.', 'woocommerce' ),
1097
+							'description' => __('Company name.', 'woocommerce'),
1098 1098
 							'type'        => 'string',
1099
-							'context'     => array( 'view', 'edit' ),
1099
+							'context'     => array('view', 'edit'),
1100 1100
 						),
1101 1101
 						'address_1'  => array(
1102
-							'description' => __( 'Address line 1', 'woocommerce' ),
1102
+							'description' => __('Address line 1', 'woocommerce'),
1103 1103
 							'type'        => 'string',
1104
-							'context'     => array( 'view', 'edit' ),
1104
+							'context'     => array('view', 'edit'),
1105 1105
 						),
1106 1106
 						'address_2'  => array(
1107
-							'description' => __( 'Address line 2', 'woocommerce' ),
1107
+							'description' => __('Address line 2', 'woocommerce'),
1108 1108
 							'type'        => 'string',
1109
-							'context'     => array( 'view', 'edit' ),
1109
+							'context'     => array('view', 'edit'),
1110 1110
 						),
1111 1111
 						'city'       => array(
1112
-							'description' => __( 'City name.', 'woocommerce' ),
1112
+							'description' => __('City name.', 'woocommerce'),
1113 1113
 							'type'        => 'string',
1114
-							'context'     => array( 'view', 'edit' ),
1114
+							'context'     => array('view', 'edit'),
1115 1115
 						),
1116 1116
 						'state'      => array(
1117
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
1117
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
1118 1118
 							'type'        => 'string',
1119
-							'context'     => array( 'view', 'edit' ),
1119
+							'context'     => array('view', 'edit'),
1120 1120
 						),
1121 1121
 						'postcode'   => array(
1122
-							'description' => __( 'Postal code.', 'woocommerce' ),
1122
+							'description' => __('Postal code.', 'woocommerce'),
1123 1123
 							'type'        => 'string',
1124
-							'context'     => array( 'view', 'edit' ),
1124
+							'context'     => array('view', 'edit'),
1125 1125
 						),
1126 1126
 						'country'    => array(
1127
-							'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ),
1127
+							'description' => __('Country code in ISO 3166-1 alpha-2 format.', 'woocommerce'),
1128 1128
 							'type'        => 'string',
1129
-							'context'     => array( 'view', 'edit' ),
1129
+							'context'     => array('view', 'edit'),
1130 1130
 						),
1131 1131
 					),
1132 1132
 				),
1133 1133
 				'payment_method'       => array(
1134
-					'description' => __( 'Payment method ID.', 'woocommerce' ),
1134
+					'description' => __('Payment method ID.', 'woocommerce'),
1135 1135
 					'type'        => 'string',
1136
-					'context'     => array( 'view', 'edit' ),
1136
+					'context'     => array('view', 'edit'),
1137 1137
 				),
1138 1138
 				'payment_method_title' => array(
1139
-					'description' => __( 'Payment method title.', 'woocommerce' ),
1139
+					'description' => __('Payment method title.', 'woocommerce'),
1140 1140
 					'type'        => 'string',
1141
-					'context'     => array( 'view', 'edit' ),
1141
+					'context'     => array('view', 'edit'),
1142 1142
 					'arg_options' => array(
1143 1143
 						'sanitize_callback' => 'sanitize_text_field',
1144 1144
 					),
1145 1145
 				),
1146 1146
 				'transaction_id'       => array(
1147
-					'description' => __( 'Unique transaction ID.', 'woocommerce' ),
1147
+					'description' => __('Unique transaction ID.', 'woocommerce'),
1148 1148
 					'type'        => 'string',
1149
-					'context'     => array( 'view', 'edit' ),
1149
+					'context'     => array('view', 'edit'),
1150 1150
 				),
1151 1151
 				'date_paid'            => array(
1152
-					'description' => __( "The date the order was paid, in the site's timezone.", 'woocommerce' ),
1152
+					'description' => __("The date the order was paid, in the site's timezone.", 'woocommerce'),
1153 1153
 					'type'        => 'date-time',
1154
-					'context'     => array( 'view', 'edit' ),
1154
+					'context'     => array('view', 'edit'),
1155 1155
 					'readonly'    => true,
1156 1156
 				),
1157 1157
 				'date_paid_gmt'        => array(
1158
-					'description' => __( 'The date the order was paid, as GMT.', 'woocommerce' ),
1158
+					'description' => __('The date the order was paid, as GMT.', 'woocommerce'),
1159 1159
 					'type'        => 'date-time',
1160
-					'context'     => array( 'view', 'edit' ),
1160
+					'context'     => array('view', 'edit'),
1161 1161
 					'readonly'    => true,
1162 1162
 				),
1163 1163
 				'date_completed'       => array(
1164
-					'description' => __( "The date the order was completed, in the site's timezone.", 'woocommerce' ),
1164
+					'description' => __("The date the order was completed, in the site's timezone.", 'woocommerce'),
1165 1165
 					'type'        => 'date-time',
1166
-					'context'     => array( 'view', 'edit' ),
1166
+					'context'     => array('view', 'edit'),
1167 1167
 					'readonly'    => true,
1168 1168
 				),
1169 1169
 				'date_completed_gmt'   => array(
1170
-					'description' => __( 'The date the order was completed, as GMT.', 'woocommerce' ),
1170
+					'description' => __('The date the order was completed, as GMT.', 'woocommerce'),
1171 1171
 					'type'        => 'date-time',
1172
-					'context'     => array( 'view', 'edit' ),
1172
+					'context'     => array('view', 'edit'),
1173 1173
 					'readonly'    => true,
1174 1174
 				),
1175 1175
 				'cart_hash'            => array(
1176
-					'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ),
1176
+					'description' => __('MD5 hash of cart items to ensure orders are not modified.', 'woocommerce'),
1177 1177
 					'type'        => 'string',
1178
-					'context'     => array( 'view', 'edit' ),
1178
+					'context'     => array('view', 'edit'),
1179 1179
 					'readonly'    => true,
1180 1180
 				),
1181 1181
 				'meta_data'            => array(
1182
-					'description' => __( 'Meta data.', 'woocommerce' ),
1182
+					'description' => __('Meta data.', 'woocommerce'),
1183 1183
 					'type'        => 'array',
1184
-					'context'     => array( 'view', 'edit' ),
1184
+					'context'     => array('view', 'edit'),
1185 1185
 					'items'       => array(
1186 1186
 						'type'       => 'object',
1187 1187
 						'properties' => array(
1188 1188
 							'id'    => array(
1189
-								'description' => __( 'Meta ID.', 'woocommerce' ),
1189
+								'description' => __('Meta ID.', 'woocommerce'),
1190 1190
 								'type'        => 'integer',
1191
-								'context'     => array( 'view', 'edit' ),
1191
+								'context'     => array('view', 'edit'),
1192 1192
 								'readonly'    => true,
1193 1193
 							),
1194 1194
 							'key'   => array(
1195
-								'description' => __( 'Meta key.', 'woocommerce' ),
1195
+								'description' => __('Meta key.', 'woocommerce'),
1196 1196
 								'type'        => 'string',
1197
-								'context'     => array( 'view', 'edit' ),
1197
+								'context'     => array('view', 'edit'),
1198 1198
 							),
1199 1199
 							'value' => array(
1200
-								'description' => __( 'Meta value.', 'woocommerce' ),
1200
+								'description' => __('Meta value.', 'woocommerce'),
1201 1201
 								'type'        => 'mixed',
1202
-								'context'     => array( 'view', 'edit' ),
1202
+								'context'     => array('view', 'edit'),
1203 1203
 							),
1204 1204
 						),
1205 1205
 					),
1206 1206
 				),
1207 1207
 				'line_items'           => array(
1208
-					'description' => __( 'Line items data.', 'woocommerce' ),
1208
+					'description' => __('Line items data.', 'woocommerce'),
1209 1209
 					'type'        => 'array',
1210
-					'context'     => array( 'view', 'edit' ),
1210
+					'context'     => array('view', 'edit'),
1211 1211
 					'items'       => array(
1212 1212
 						'type'       => 'object',
1213 1213
 						'properties' => array(
1214 1214
 							'id'           => array(
1215
-								'description' => __( 'Item ID.', 'woocommerce' ),
1215
+								'description' => __('Item ID.', 'woocommerce'),
1216 1216
 								'type'        => 'integer',
1217
-								'context'     => array( 'view', 'edit' ),
1217
+								'context'     => array('view', 'edit'),
1218 1218
 								'readonly'    => true,
1219 1219
 							),
1220 1220
 							'name'         => array(
1221
-								'description' => __( 'Product name.', 'woocommerce' ),
1221
+								'description' => __('Product name.', 'woocommerce'),
1222 1222
 								'type'        => 'mixed',
1223
-								'context'     => array( 'view', 'edit' ),
1223
+								'context'     => array('view', 'edit'),
1224 1224
 							),
1225 1225
 							'product_id'   => array(
1226
-								'description' => __( 'Product ID.', 'woocommerce' ),
1226
+								'description' => __('Product ID.', 'woocommerce'),
1227 1227
 								'type'        => 'mixed',
1228
-								'context'     => array( 'view', 'edit' ),
1228
+								'context'     => array('view', 'edit'),
1229 1229
 							),
1230 1230
 							'variation_id' => array(
1231
-								'description' => __( 'Variation ID, if applicable.', 'woocommerce' ),
1231
+								'description' => __('Variation ID, if applicable.', 'woocommerce'),
1232 1232
 								'type'        => 'integer',
1233
-								'context'     => array( 'view', 'edit' ),
1233
+								'context'     => array('view', 'edit'),
1234 1234
 							),
1235 1235
 							'quantity'     => array(
1236
-								'description' => __( 'Quantity ordered.', 'woocommerce' ),
1236
+								'description' => __('Quantity ordered.', 'woocommerce'),
1237 1237
 								'type'        => 'integer',
1238
-								'context'     => array( 'view', 'edit' ),
1238
+								'context'     => array('view', 'edit'),
1239 1239
 							),
1240 1240
 							'tax_class'    => array(
1241
-								'description' => __( 'Tax class of product.', 'woocommerce' ),
1241
+								'description' => __('Tax class of product.', 'woocommerce'),
1242 1242
 								'type'        => 'string',
1243
-								'context'     => array( 'view', 'edit' ),
1243
+								'context'     => array('view', 'edit'),
1244 1244
 							),
1245 1245
 							'subtotal'     => array(
1246
-								'description' => __( 'Line subtotal (before discounts).', 'woocommerce' ),
1246
+								'description' => __('Line subtotal (before discounts).', 'woocommerce'),
1247 1247
 								'type'        => 'string',
1248
-								'context'     => array( 'view', 'edit' ),
1248
+								'context'     => array('view', 'edit'),
1249 1249
 							),
1250 1250
 							'subtotal_tax' => array(
1251
-								'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce' ),
1251
+								'description' => __('Line subtotal tax (before discounts).', 'woocommerce'),
1252 1252
 								'type'        => 'string',
1253
-								'context'     => array( 'view', 'edit' ),
1253
+								'context'     => array('view', 'edit'),
1254 1254
 								'readonly'    => true,
1255 1255
 							),
1256 1256
 							'total'        => array(
1257
-								'description' => __( 'Line total (after discounts).', 'woocommerce' ),
1257
+								'description' => __('Line total (after discounts).', 'woocommerce'),
1258 1258
 								'type'        => 'string',
1259
-								'context'     => array( 'view', 'edit' ),
1259
+								'context'     => array('view', 'edit'),
1260 1260
 							),
1261 1261
 							'total_tax'    => array(
1262
-								'description' => __( 'Line total tax (after discounts).', 'woocommerce' ),
1262
+								'description' => __('Line total tax (after discounts).', 'woocommerce'),
1263 1263
 								'type'        => 'string',
1264
-								'context'     => array( 'view', 'edit' ),
1264
+								'context'     => array('view', 'edit'),
1265 1265
 								'readonly'    => true,
1266 1266
 							),
1267 1267
 							'taxes'        => array(
1268
-								'description' => __( 'Line taxes.', 'woocommerce' ),
1268
+								'description' => __('Line taxes.', 'woocommerce'),
1269 1269
 								'type'        => 'array',
1270
-								'context'     => array( 'view', 'edit' ),
1270
+								'context'     => array('view', 'edit'),
1271 1271
 								'readonly'    => true,
1272 1272
 								'items'       => array(
1273 1273
 									'type'       => 'object',
1274 1274
 									'properties' => array(
1275 1275
 										'id'       => array(
1276
-											'description' => __( 'Tax rate ID.', 'woocommerce' ),
1276
+											'description' => __('Tax rate ID.', 'woocommerce'),
1277 1277
 											'type'        => 'integer',
1278
-											'context'     => array( 'view', 'edit' ),
1278
+											'context'     => array('view', 'edit'),
1279 1279
 										),
1280 1280
 										'total'    => array(
1281
-											'description' => __( 'Tax total.', 'woocommerce' ),
1281
+											'description' => __('Tax total.', 'woocommerce'),
1282 1282
 											'type'        => 'string',
1283
-											'context'     => array( 'view', 'edit' ),
1283
+											'context'     => array('view', 'edit'),
1284 1284
 										),
1285 1285
 										'subtotal' => array(
1286
-											'description' => __( 'Tax subtotal.', 'woocommerce' ),
1286
+											'description' => __('Tax subtotal.', 'woocommerce'),
1287 1287
 											'type'        => 'string',
1288
-											'context'     => array( 'view', 'edit' ),
1288
+											'context'     => array('view', 'edit'),
1289 1289
 										),
1290 1290
 									),
1291 1291
 								),
1292 1292
 							),
1293 1293
 							'meta_data'    => array(
1294
-								'description' => __( 'Meta data.', 'woocommerce' ),
1294
+								'description' => __('Meta data.', 'woocommerce'),
1295 1295
 								'type'        => 'array',
1296
-								'context'     => array( 'view', 'edit' ),
1296
+								'context'     => array('view', 'edit'),
1297 1297
 								'items'       => array(
1298 1298
 									'type'       => 'object',
1299 1299
 									'properties' => array(
1300 1300
 										'id'    => array(
1301
-											'description' => __( 'Meta ID.', 'woocommerce' ),
1301
+											'description' => __('Meta ID.', 'woocommerce'),
1302 1302
 											'type'        => 'integer',
1303
-											'context'     => array( 'view', 'edit' ),
1303
+											'context'     => array('view', 'edit'),
1304 1304
 											'readonly'    => true,
1305 1305
 										),
1306 1306
 										'key'   => array(
1307
-											'description' => __( 'Meta key.', 'woocommerce' ),
1307
+											'description' => __('Meta key.', 'woocommerce'),
1308 1308
 											'type'        => 'string',
1309
-											'context'     => array( 'view', 'edit' ),
1309
+											'context'     => array('view', 'edit'),
1310 1310
 										),
1311 1311
 										'value' => array(
1312
-											'description' => __( 'Meta value.', 'woocommerce' ),
1312
+											'description' => __('Meta value.', 'woocommerce'),
1313 1313
 											'type'        => 'mixed',
1314
-											'context'     => array( 'view', 'edit' ),
1314
+											'context'     => array('view', 'edit'),
1315 1315
 										),
1316 1316
 									),
1317 1317
 								),
1318 1318
 							),
1319 1319
 							'sku'          => array(
1320
-								'description' => __( 'Product SKU.', 'woocommerce' ),
1320
+								'description' => __('Product SKU.', 'woocommerce'),
1321 1321
 								'type'        => 'string',
1322
-								'context'     => array( 'view', 'edit' ),
1322
+								'context'     => array('view', 'edit'),
1323 1323
 								'readonly'    => true,
1324 1324
 							),
1325 1325
 							'price'        => array(
1326
-								'description' => __( 'Product price.', 'woocommerce' ),
1326
+								'description' => __('Product price.', 'woocommerce'),
1327 1327
 								'type'        => 'number',
1328
-								'context'     => array( 'view', 'edit' ),
1328
+								'context'     => array('view', 'edit'),
1329 1329
 								'readonly'    => true,
1330 1330
 							),
1331 1331
 						),
1332 1332
 					),
1333 1333
 				),
1334 1334
 				'tax_lines'            => array(
1335
-					'description' => __( 'Tax lines data.', 'woocommerce' ),
1335
+					'description' => __('Tax lines data.', 'woocommerce'),
1336 1336
 					'type'        => 'array',
1337
-					'context'     => array( 'view', 'edit' ),
1337
+					'context'     => array('view', 'edit'),
1338 1338
 					'readonly'    => true,
1339 1339
 					'items'       => array(
1340 1340
 						'type'       => 'object',
1341 1341
 						'properties' => array(
1342 1342
 							'id'                 => array(
1343
-								'description' => __( 'Item ID.', 'woocommerce' ),
1343
+								'description' => __('Item ID.', 'woocommerce'),
1344 1344
 								'type'        => 'integer',
1345
-								'context'     => array( 'view', 'edit' ),
1345
+								'context'     => array('view', 'edit'),
1346 1346
 								'readonly'    => true,
1347 1347
 							),
1348 1348
 							'rate_code'          => array(
1349
-								'description' => __( 'Tax rate code.', 'woocommerce' ),
1349
+								'description' => __('Tax rate code.', 'woocommerce'),
1350 1350
 								'type'        => 'string',
1351
-								'context'     => array( 'view', 'edit' ),
1351
+								'context'     => array('view', 'edit'),
1352 1352
 								'readonly'    => true,
1353 1353
 							),
1354 1354
 							'rate_id'            => array(
1355
-								'description' => __( 'Tax rate ID.', 'woocommerce' ),
1355
+								'description' => __('Tax rate ID.', 'woocommerce'),
1356 1356
 								'type'        => 'string',
1357
-								'context'     => array( 'view', 'edit' ),
1357
+								'context'     => array('view', 'edit'),
1358 1358
 								'readonly'    => true,
1359 1359
 							),
1360 1360
 							'label'              => array(
1361
-								'description' => __( 'Tax rate label.', 'woocommerce' ),
1361
+								'description' => __('Tax rate label.', 'woocommerce'),
1362 1362
 								'type'        => 'string',
1363
-								'context'     => array( 'view', 'edit' ),
1363
+								'context'     => array('view', 'edit'),
1364 1364
 								'readonly'    => true,
1365 1365
 							),
1366 1366
 							'compound'           => array(
1367
-								'description' => __( 'Show if is a compound tax rate.', 'woocommerce' ),
1367
+								'description' => __('Show if is a compound tax rate.', 'woocommerce'),
1368 1368
 								'type'        => 'boolean',
1369
-								'context'     => array( 'view', 'edit' ),
1369
+								'context'     => array('view', 'edit'),
1370 1370
 								'readonly'    => true,
1371 1371
 							),
1372 1372
 							'tax_total'          => array(
1373
-								'description' => __( 'Tax total (not including shipping taxes).', 'woocommerce' ),
1373
+								'description' => __('Tax total (not including shipping taxes).', 'woocommerce'),
1374 1374
 								'type'        => 'string',
1375
-								'context'     => array( 'view', 'edit' ),
1375
+								'context'     => array('view', 'edit'),
1376 1376
 								'readonly'    => true,
1377 1377
 							),
1378 1378
 							'shipping_tax_total' => array(
1379
-								'description' => __( 'Shipping tax total.', 'woocommerce' ),
1379
+								'description' => __('Shipping tax total.', 'woocommerce'),
1380 1380
 								'type'        => 'string',
1381
-								'context'     => array( 'view', 'edit' ),
1381
+								'context'     => array('view', 'edit'),
1382 1382
 								'readonly'    => true,
1383 1383
 							),
1384 1384
 							'meta_data'          => array(
1385
-								'description' => __( 'Meta data.', 'woocommerce' ),
1385
+								'description' => __('Meta data.', 'woocommerce'),
1386 1386
 								'type'        => 'array',
1387
-								'context'     => array( 'view', 'edit' ),
1387
+								'context'     => array('view', 'edit'),
1388 1388
 								'items'       => array(
1389 1389
 									'type'       => 'object',
1390 1390
 									'properties' => array(
1391 1391
 										'id'    => array(
1392
-											'description' => __( 'Meta ID.', 'woocommerce' ),
1392
+											'description' => __('Meta ID.', 'woocommerce'),
1393 1393
 											'type'        => 'integer',
1394
-											'context'     => array( 'view', 'edit' ),
1394
+											'context'     => array('view', 'edit'),
1395 1395
 											'readonly'    => true,
1396 1396
 										),
1397 1397
 										'key'   => array(
1398
-											'description' => __( 'Meta key.', 'woocommerce' ),
1398
+											'description' => __('Meta key.', 'woocommerce'),
1399 1399
 											'type'        => 'string',
1400
-											'context'     => array( 'view', 'edit' ),
1400
+											'context'     => array('view', 'edit'),
1401 1401
 										),
1402 1402
 										'value' => array(
1403
-											'description' => __( 'Meta value.', 'woocommerce' ),
1403
+											'description' => __('Meta value.', 'woocommerce'),
1404 1404
 											'type'        => 'mixed',
1405
-											'context'     => array( 'view', 'edit' ),
1405
+											'context'     => array('view', 'edit'),
1406 1406
 										),
1407 1407
 									),
1408 1408
 								),
@@ -1411,89 +1411,89 @@  discard block
 block discarded – undo
1411 1411
 					),
1412 1412
 				),
1413 1413
 				'shipping_lines'       => array(
1414
-					'description' => __( 'Shipping lines data.', 'woocommerce' ),
1414
+					'description' => __('Shipping lines data.', 'woocommerce'),
1415 1415
 					'type'        => 'array',
1416
-					'context'     => array( 'view', 'edit' ),
1416
+					'context'     => array('view', 'edit'),
1417 1417
 					'items'       => array(
1418 1418
 						'type'       => 'object',
1419 1419
 						'properties' => array(
1420 1420
 							'id'           => array(
1421
-								'description' => __( 'Item ID.', 'woocommerce' ),
1421
+								'description' => __('Item ID.', 'woocommerce'),
1422 1422
 								'type'        => 'integer',
1423
-								'context'     => array( 'view', 'edit' ),
1423
+								'context'     => array('view', 'edit'),
1424 1424
 								'readonly'    => true,
1425 1425
 							),
1426 1426
 							'method_title' => array(
1427
-								'description' => __( 'Shipping method name.', 'woocommerce' ),
1427
+								'description' => __('Shipping method name.', 'woocommerce'),
1428 1428
 								'type'        => 'mixed',
1429
-								'context'     => array( 'view', 'edit' ),
1429
+								'context'     => array('view', 'edit'),
1430 1430
 							),
1431 1431
 							'method_id'    => array(
1432
-								'description' => __( 'Shipping method ID.', 'woocommerce' ),
1432
+								'description' => __('Shipping method ID.', 'woocommerce'),
1433 1433
 								'type'        => 'mixed',
1434
-								'context'     => array( 'view', 'edit' ),
1434
+								'context'     => array('view', 'edit'),
1435 1435
 							),
1436 1436
 							'instance_id'  => array(
1437
-								'description' => __( 'Shipping instance ID.', 'woocommerce' ),
1437
+								'description' => __('Shipping instance ID.', 'woocommerce'),
1438 1438
 								'type'        => 'string',
1439
-								'context'     => array( 'view', 'edit' ),
1439
+								'context'     => array('view', 'edit'),
1440 1440
 							),
1441 1441
 							'total'        => array(
1442
-								'description' => __( 'Line total (after discounts).', 'woocommerce' ),
1442
+								'description' => __('Line total (after discounts).', 'woocommerce'),
1443 1443
 								'type'        => 'string',
1444
-								'context'     => array( 'view', 'edit' ),
1444
+								'context'     => array('view', 'edit'),
1445 1445
 							),
1446 1446
 							'total_tax'    => array(
1447
-								'description' => __( 'Line total tax (after discounts).', 'woocommerce' ),
1447
+								'description' => __('Line total tax (after discounts).', 'woocommerce'),
1448 1448
 								'type'        => 'string',
1449
-								'context'     => array( 'view', 'edit' ),
1449
+								'context'     => array('view', 'edit'),
1450 1450
 								'readonly'    => true,
1451 1451
 							),
1452 1452
 							'taxes'        => array(
1453
-								'description' => __( 'Line taxes.', 'woocommerce' ),
1453
+								'description' => __('Line taxes.', 'woocommerce'),
1454 1454
 								'type'        => 'array',
1455
-								'context'     => array( 'view', 'edit' ),
1455
+								'context'     => array('view', 'edit'),
1456 1456
 								'readonly'    => true,
1457 1457
 								'items'       => array(
1458 1458
 									'type'       => 'object',
1459 1459
 									'properties' => array(
1460 1460
 										'id'    => array(
1461
-											'description' => __( 'Tax rate ID.', 'woocommerce' ),
1461
+											'description' => __('Tax rate ID.', 'woocommerce'),
1462 1462
 											'type'        => 'integer',
1463
-											'context'     => array( 'view', 'edit' ),
1463
+											'context'     => array('view', 'edit'),
1464 1464
 											'readonly'    => true,
1465 1465
 										),
1466 1466
 										'total' => array(
1467
-											'description' => __( 'Tax total.', 'woocommerce' ),
1467
+											'description' => __('Tax total.', 'woocommerce'),
1468 1468
 											'type'        => 'string',
1469
-											'context'     => array( 'view', 'edit' ),
1469
+											'context'     => array('view', 'edit'),
1470 1470
 											'readonly'    => true,
1471 1471
 										),
1472 1472
 									),
1473 1473
 								),
1474 1474
 							),
1475 1475
 							'meta_data'    => array(
1476
-								'description' => __( 'Meta data.', 'woocommerce' ),
1476
+								'description' => __('Meta data.', 'woocommerce'),
1477 1477
 								'type'        => 'array',
1478
-								'context'     => array( 'view', 'edit' ),
1478
+								'context'     => array('view', 'edit'),
1479 1479
 								'items'       => array(
1480 1480
 									'type'       => 'object',
1481 1481
 									'properties' => array(
1482 1482
 										'id'    => array(
1483
-											'description' => __( 'Meta ID.', 'woocommerce' ),
1483
+											'description' => __('Meta ID.', 'woocommerce'),
1484 1484
 											'type'        => 'integer',
1485
-											'context'     => array( 'view', 'edit' ),
1485
+											'context'     => array('view', 'edit'),
1486 1486
 											'readonly'    => true,
1487 1487
 										),
1488 1488
 										'key'   => array(
1489
-											'description' => __( 'Meta key.', 'woocommerce' ),
1489
+											'description' => __('Meta key.', 'woocommerce'),
1490 1490
 											'type'        => 'string',
1491
-											'context'     => array( 'view', 'edit' ),
1491
+											'context'     => array('view', 'edit'),
1492 1492
 										),
1493 1493
 										'value' => array(
1494
-											'description' => __( 'Meta value.', 'woocommerce' ),
1494
+											'description' => __('Meta value.', 'woocommerce'),
1495 1495
 											'type'        => 'mixed',
1496
-											'context'     => array( 'view', 'edit' ),
1496
+											'context'     => array('view', 'edit'),
1497 1497
 										),
1498 1498
 									),
1499 1499
 								),
@@ -1502,96 +1502,96 @@  discard block
 block discarded – undo
1502 1502
 					),
1503 1503
 				),
1504 1504
 				'fee_lines'            => array(
1505
-					'description' => __( 'Fee lines data.', 'woocommerce' ),
1505
+					'description' => __('Fee lines data.', 'woocommerce'),
1506 1506
 					'type'        => 'array',
1507
-					'context'     => array( 'view', 'edit' ),
1507
+					'context'     => array('view', 'edit'),
1508 1508
 					'items'       => array(
1509 1509
 						'type'       => 'object',
1510 1510
 						'properties' => array(
1511 1511
 							'id'         => array(
1512
-								'description' => __( 'Item ID.', 'woocommerce' ),
1512
+								'description' => __('Item ID.', 'woocommerce'),
1513 1513
 								'type'        => 'integer',
1514
-								'context'     => array( 'view', 'edit' ),
1514
+								'context'     => array('view', 'edit'),
1515 1515
 								'readonly'    => true,
1516 1516
 							),
1517 1517
 							'name'       => array(
1518
-								'description' => __( 'Fee name.', 'woocommerce' ),
1518
+								'description' => __('Fee name.', 'woocommerce'),
1519 1519
 								'type'        => 'mixed',
1520
-								'context'     => array( 'view', 'edit' ),
1520
+								'context'     => array('view', 'edit'),
1521 1521
 							),
1522 1522
 							'tax_class'  => array(
1523
-								'description' => __( 'Tax class of fee.', 'woocommerce' ),
1523
+								'description' => __('Tax class of fee.', 'woocommerce'),
1524 1524
 								'type'        => 'string',
1525
-								'context'     => array( 'view', 'edit' ),
1525
+								'context'     => array('view', 'edit'),
1526 1526
 							),
1527 1527
 							'tax_status' => array(
1528
-								'description' => __( 'Tax status of fee.', 'woocommerce' ),
1528
+								'description' => __('Tax status of fee.', 'woocommerce'),
1529 1529
 								'type'        => 'string',
1530
-								'context'     => array( 'view', 'edit' ),
1531
-								'enum'        => array( 'taxable', 'none' ),
1530
+								'context'     => array('view', 'edit'),
1531
+								'enum'        => array('taxable', 'none'),
1532 1532
 							),
1533 1533
 							'total'      => array(
1534
-								'description' => __( 'Line total (after discounts).', 'woocommerce' ),
1534
+								'description' => __('Line total (after discounts).', 'woocommerce'),
1535 1535
 								'type'        => 'string',
1536
-								'context'     => array( 'view', 'edit' ),
1536
+								'context'     => array('view', 'edit'),
1537 1537
 							),
1538 1538
 							'total_tax'  => array(
1539
-								'description' => __( 'Line total tax (after discounts).', 'woocommerce' ),
1539
+								'description' => __('Line total tax (after discounts).', 'woocommerce'),
1540 1540
 								'type'        => 'string',
1541
-								'context'     => array( 'view', 'edit' ),
1541
+								'context'     => array('view', 'edit'),
1542 1542
 								'readonly'    => true,
1543 1543
 							),
1544 1544
 							'taxes'      => array(
1545
-								'description' => __( 'Line taxes.', 'woocommerce' ),
1545
+								'description' => __('Line taxes.', 'woocommerce'),
1546 1546
 								'type'        => 'array',
1547
-								'context'     => array( 'view', 'edit' ),
1547
+								'context'     => array('view', 'edit'),
1548 1548
 								'readonly'    => true,
1549 1549
 								'items'       => array(
1550 1550
 									'type'       => 'object',
1551 1551
 									'properties' => array(
1552 1552
 										'id'       => array(
1553
-											'description' => __( 'Tax rate ID.', 'woocommerce' ),
1553
+											'description' => __('Tax rate ID.', 'woocommerce'),
1554 1554
 											'type'        => 'integer',
1555
-											'context'     => array( 'view', 'edit' ),
1555
+											'context'     => array('view', 'edit'),
1556 1556
 											'readonly'    => true,
1557 1557
 										),
1558 1558
 										'total'    => array(
1559
-											'description' => __( 'Tax total.', 'woocommerce' ),
1559
+											'description' => __('Tax total.', 'woocommerce'),
1560 1560
 											'type'        => 'string',
1561
-											'context'     => array( 'view', 'edit' ),
1561
+											'context'     => array('view', 'edit'),
1562 1562
 											'readonly'    => true,
1563 1563
 										),
1564 1564
 										'subtotal' => array(
1565
-											'description' => __( 'Tax subtotal.', 'woocommerce' ),
1565
+											'description' => __('Tax subtotal.', 'woocommerce'),
1566 1566
 											'type'        => 'string',
1567
-											'context'     => array( 'view', 'edit' ),
1567
+											'context'     => array('view', 'edit'),
1568 1568
 											'readonly'    => true,
1569 1569
 										),
1570 1570
 									),
1571 1571
 								),
1572 1572
 							),
1573 1573
 							'meta_data'  => array(
1574
-								'description' => __( 'Meta data.', 'woocommerce' ),
1574
+								'description' => __('Meta data.', 'woocommerce'),
1575 1575
 								'type'        => 'array',
1576
-								'context'     => array( 'view', 'edit' ),
1576
+								'context'     => array('view', 'edit'),
1577 1577
 								'items'       => array(
1578 1578
 									'type'       => 'object',
1579 1579
 									'properties' => array(
1580 1580
 										'id'    => array(
1581
-											'description' => __( 'Meta ID.', 'woocommerce' ),
1581
+											'description' => __('Meta ID.', 'woocommerce'),
1582 1582
 											'type'        => 'integer',
1583
-											'context'     => array( 'view', 'edit' ),
1583
+											'context'     => array('view', 'edit'),
1584 1584
 											'readonly'    => true,
1585 1585
 										),
1586 1586
 										'key'   => array(
1587
-											'description' => __( 'Meta key.', 'woocommerce' ),
1587
+											'description' => __('Meta key.', 'woocommerce'),
1588 1588
 											'type'        => 'string',
1589
-											'context'     => array( 'view', 'edit' ),
1589
+											'context'     => array('view', 'edit'),
1590 1590
 										),
1591 1591
 										'value' => array(
1592
-											'description' => __( 'Meta value.', 'woocommerce' ),
1592
+											'description' => __('Meta value.', 'woocommerce'),
1593 1593
 											'type'        => 'mixed',
1594
-											'context'     => array( 'view', 'edit' ),
1594
+											'context'     => array('view', 'edit'),
1595 1595
 										),
1596 1596
 									),
1597 1597
 								),
@@ -1600,57 +1600,57 @@  discard block
 block discarded – undo
1600 1600
 					),
1601 1601
 				),
1602 1602
 				'coupon_lines'         => array(
1603
-					'description' => __( 'Coupons line data.', 'woocommerce' ),
1603
+					'description' => __('Coupons line data.', 'woocommerce'),
1604 1604
 					'type'        => 'array',
1605
-					'context'     => array( 'view', 'edit' ),
1605
+					'context'     => array('view', 'edit'),
1606 1606
 					'items'       => array(
1607 1607
 						'type'       => 'object',
1608 1608
 						'properties' => array(
1609 1609
 							'id'           => array(
1610
-								'description' => __( 'Item ID.', 'woocommerce' ),
1610
+								'description' => __('Item ID.', 'woocommerce'),
1611 1611
 								'type'        => 'integer',
1612
-								'context'     => array( 'view', 'edit' ),
1612
+								'context'     => array('view', 'edit'),
1613 1613
 								'readonly'    => true,
1614 1614
 							),
1615 1615
 							'code'         => array(
1616
-								'description' => __( 'Coupon code.', 'woocommerce' ),
1616
+								'description' => __('Coupon code.', 'woocommerce'),
1617 1617
 								'type'        => 'mixed',
1618
-								'context'     => array( 'view', 'edit' ),
1618
+								'context'     => array('view', 'edit'),
1619 1619
 							),
1620 1620
 							'discount'     => array(
1621
-								'description' => __( 'Discount total.', 'woocommerce' ),
1621
+								'description' => __('Discount total.', 'woocommerce'),
1622 1622
 								'type'        => 'string',
1623
-								'context'     => array( 'view', 'edit' ),
1623
+								'context'     => array('view', 'edit'),
1624 1624
 								'readonly'    => true,
1625 1625
 							),
1626 1626
 							'discount_tax' => array(
1627
-								'description' => __( 'Discount total tax.', 'woocommerce' ),
1627
+								'description' => __('Discount total tax.', 'woocommerce'),
1628 1628
 								'type'        => 'string',
1629
-								'context'     => array( 'view', 'edit' ),
1629
+								'context'     => array('view', 'edit'),
1630 1630
 								'readonly'    => true,
1631 1631
 							),
1632 1632
 							'meta_data'    => array(
1633
-								'description' => __( 'Meta data.', 'woocommerce' ),
1633
+								'description' => __('Meta data.', 'woocommerce'),
1634 1634
 								'type'        => 'array',
1635
-								'context'     => array( 'view', 'edit' ),
1635
+								'context'     => array('view', 'edit'),
1636 1636
 								'items'       => array(
1637 1637
 									'type'       => 'object',
1638 1638
 									'properties' => array(
1639 1639
 										'id'    => array(
1640
-											'description' => __( 'Meta ID.', 'woocommerce' ),
1640
+											'description' => __('Meta ID.', 'woocommerce'),
1641 1641
 											'type'        => 'integer',
1642
-											'context'     => array( 'view', 'edit' ),
1642
+											'context'     => array('view', 'edit'),
1643 1643
 											'readonly'    => true,
1644 1644
 										),
1645 1645
 										'key'   => array(
1646
-											'description' => __( 'Meta key.', 'woocommerce' ),
1646
+											'description' => __('Meta key.', 'woocommerce'),
1647 1647
 											'type'        => 'string',
1648
-											'context'     => array( 'view', 'edit' ),
1648
+											'context'     => array('view', 'edit'),
1649 1649
 										),
1650 1650
 										'value' => array(
1651
-											'description' => __( 'Meta value.', 'woocommerce' ),
1651
+											'description' => __('Meta value.', 'woocommerce'),
1652 1652
 											'type'        => 'mixed',
1653
-											'context'     => array( 'view', 'edit' ),
1653
+											'context'     => array('view', 'edit'),
1654 1654
 										),
1655 1655
 									),
1656 1656
 								),
@@ -1659,44 +1659,44 @@  discard block
 block discarded – undo
1659 1659
 					),
1660 1660
 				),
1661 1661
 				'refunds'              => array(
1662
-					'description' => __( 'List of refunds.', 'woocommerce' ),
1662
+					'description' => __('List of refunds.', 'woocommerce'),
1663 1663
 					'type'        => 'array',
1664
-					'context'     => array( 'view', 'edit' ),
1664
+					'context'     => array('view', 'edit'),
1665 1665
 					'readonly'    => true,
1666 1666
 					'items'       => array(
1667 1667
 						'type'       => 'object',
1668 1668
 						'properties' => array(
1669 1669
 							'id'     => array(
1670
-								'description' => __( 'Refund ID.', 'woocommerce' ),
1670
+								'description' => __('Refund ID.', 'woocommerce'),
1671 1671
 								'type'        => 'integer',
1672
-								'context'     => array( 'view', 'edit' ),
1672
+								'context'     => array('view', 'edit'),
1673 1673
 								'readonly'    => true,
1674 1674
 							),
1675 1675
 							'reason' => array(
1676
-								'description' => __( 'Refund reason.', 'woocommerce' ),
1676
+								'description' => __('Refund reason.', 'woocommerce'),
1677 1677
 								'type'        => 'string',
1678
-								'context'     => array( 'view', 'edit' ),
1678
+								'context'     => array('view', 'edit'),
1679 1679
 								'readonly'    => true,
1680 1680
 							),
1681 1681
 							'total'  => array(
1682
-								'description' => __( 'Refund total.', 'woocommerce' ),
1682
+								'description' => __('Refund total.', 'woocommerce'),
1683 1683
 								'type'        => 'string',
1684
-								'context'     => array( 'view', 'edit' ),
1684
+								'context'     => array('view', 'edit'),
1685 1685
 								'readonly'    => true,
1686 1686
 							),
1687 1687
 						),
1688 1688
 					),
1689 1689
 				),
1690 1690
 				'set_paid'             => array(
1691
-					'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce' ),
1691
+					'description' => __('Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce'),
1692 1692
 					'type'        => 'boolean',
1693 1693
 					'default'     => false,
1694
-					'context'     => array( 'edit' ),
1694
+					'context'     => array('edit'),
1695 1695
 				),
1696 1696
 			),
1697 1697
 		);
1698 1698
 
1699
-		return $this->add_additional_fields_schema( $schema );
1699
+		return $this->add_additional_fields_schema($schema);
1700 1700
 	}
1701 1701
 
1702 1702
 	/**
@@ -1709,36 +1709,36 @@  discard block
 block discarded – undo
1709 1709
 
1710 1710
 		$params['status'] = array(
1711 1711
 			'default'           => 'any',
1712
-			'description'       => __( 'Limit result set to orders which have specific statuses.', 'woocommerce' ),
1712
+			'description'       => __('Limit result set to orders which have specific statuses.', 'woocommerce'),
1713 1713
 			'type'              => 'array',
1714 1714
 			'items'             => array(
1715 1715
 				'type' => 'string',
1716
-				'enum' => array_merge( array( 'any', 'trash' ), $this->get_order_statuses() ),
1716
+				'enum' => array_merge(array('any', 'trash'), $this->get_order_statuses()),
1717 1717
 			),
1718 1718
 			'validate_callback' => 'rest_validate_request_arg',
1719 1719
 		);
1720 1720
 		$params['customer'] = array(
1721
-			'description'       => __( 'Limit result set to orders assigned a specific customer.', 'woocommerce' ),
1721
+			'description'       => __('Limit result set to orders assigned a specific customer.', 'woocommerce'),
1722 1722
 			'type'              => 'integer',
1723 1723
 			'sanitize_callback' => 'absint',
1724 1724
 			'validate_callback' => 'rest_validate_request_arg',
1725 1725
 		);
1726
-		$params['product']  = array(
1727
-			'description'       => __( 'Limit result set to orders assigned a specific product.', 'woocommerce' ),
1726
+		$params['product'] = array(
1727
+			'description'       => __('Limit result set to orders assigned a specific product.', 'woocommerce'),
1728 1728
 			'type'              => 'integer',
1729 1729
 			'sanitize_callback' => 'absint',
1730 1730
 			'validate_callback' => 'rest_validate_request_arg',
1731 1731
 		);
1732
-		$params['dp']       = array(
1732
+		$params['dp'] = array(
1733 1733
 			'default'           => wc_get_price_decimals(),
1734
-			'description'       => __( 'Number of decimal points to use in each resource.', 'woocommerce' ),
1734
+			'description'       => __('Number of decimal points to use in each resource.', 'woocommerce'),
1735 1735
 			'type'              => 'integer',
1736 1736
 			'sanitize_callback' => 'absint',
1737 1737
 			'validate_callback' => 'rest_validate_request_arg',
1738 1738
 		);
1739 1739
 		// This needs to remain a string to support extensions that filter Order Number.
1740 1740
 		$params['number'] = array(
1741
-			'description'       => __( 'Limit result set to orders matching part of an order number.', 'woocommerce' ),
1741
+			'description'       => __('Limit result set to orders matching part of an order number.', 'woocommerce'),
1742 1742
 			'type'              => 'string',
1743 1743
 			'validate_callback' => 'rest_validate_request_arg',
1744 1744
 		);
@@ -1755,27 +1755,27 @@  discard block
 block discarded – undo
1755 1755
 	 * @param \WC_Order        $order   Order data.
1756 1756
 	 * @return bool
1757 1757
 	 */
1758
-	protected function calculate_coupons( $request, $order ) {
1759
-		if ( ! isset( $request['coupon_lines'] ) || ! is_array( $request['coupon_lines'] ) ) {
1758
+	protected function calculate_coupons($request, $order) {
1759
+		if ( ! isset($request['coupon_lines']) || ! is_array($request['coupon_lines'])) {
1760 1760
 			return false;
1761 1761
 		}
1762 1762
 
1763 1763
 		// Remove all coupons first to ensure calculation is correct.
1764
-		foreach ( $order->get_items( 'coupon' ) as $coupon ) {
1765
-			$order->remove_coupon( $coupon->get_code() );
1764
+		foreach ($order->get_items('coupon') as $coupon) {
1765
+			$order->remove_coupon($coupon->get_code());
1766 1766
 		}
1767 1767
 
1768
-		foreach ( $request['coupon_lines'] as $item ) {
1769
-			if ( is_array( $item ) ) {
1770
-				if ( empty( $item['id'] ) ) {
1771
-					if ( empty( $item['code'] ) ) {
1772
-						throw new \WC_REST_Exception( 'woocommerce_rest_invalid_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 );
1768
+		foreach ($request['coupon_lines'] as $item) {
1769
+			if (is_array($item)) {
1770
+				if (empty($item['id'])) {
1771
+					if (empty($item['code'])) {
1772
+						throw new \WC_REST_Exception('woocommerce_rest_invalid_coupon', __('Coupon code is required.', 'woocommerce'), 400);
1773 1773
 					}
1774 1774
 
1775
-					$results = $order->apply_coupon( wc_clean( $item['code'] ) );
1775
+					$results = $order->apply_coupon(wc_clean($item['code']));
1776 1776
 
1777
-					if ( is_wp_error( $results ) ) {
1778
-						throw new \WC_REST_Exception( 'woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400 );
1777
+					if (is_wp_error($results)) {
1778
+						throw new \WC_REST_Exception('woocommerce_rest_' . $results->get_error_code(), $results->get_error_message(), 400);
1779 1779
 					}
1780 1780
 				}
1781 1781
 			}
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/TaxClasses.php 1 patch
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Tax Class 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,23 +54,23 @@  discard block
 block discarded – undo
54 54
 			array(
55 55
 				'args' => array(
56 56
 					'slug' => array(
57
-						'description' => __( 'Unique slug for the resource.', 'woocommerce' ),
57
+						'description' => __('Unique slug for the resource.', 'woocommerce'),
58 58
 						'type'        => 'string',
59 59
 					),
60 60
 				),
61 61
 				array(
62 62
 					'methods'             => \WP_REST_Server::DELETABLE,
63
-					'callback'            => array( $this, 'delete_item' ),
64
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
63
+					'callback'            => array($this, 'delete_item'),
64
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
65 65
 					'args'                => array(
66 66
 						'force' => array(
67 67
 							'default'     => false,
68 68
 							'type'        => 'boolean',
69
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
69
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
70 70
 						),
71 71
 					),
72 72
 				),
73
-				'schema' => array( $this, 'get_public_item_schema' ),
73
+				'schema' => array($this, 'get_public_item_schema'),
74 74
 			),
75 75
 			true
76 76
 		);
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 	 * @param  \WP_REST_Request $request Full details about the request.
83 83
 	 * @return \WP_Error|boolean
84 84
 	 */
85
-	public function get_items_permissions_check( $request ) {
86
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
87
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
85
+	public function get_items_permissions_check($request) {
86
+		if ( ! wc_rest_check_manager_permissions('settings', 'read')) {
87
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
88 88
 		}
89 89
 
90 90
 		return true;
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
 	 *
98 98
 	 * @return bool|\WP_Error
99 99
 	 */
100
-	public function create_item_permissions_check( $request ) {
101
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) {
102
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
100
+	public function create_item_permissions_check($request) {
101
+		if ( ! wc_rest_check_manager_permissions('settings', 'create')) {
102
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
103 103
 		}
104 104
 
105 105
 		return true;
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @return bool|\WP_Error
114 114
 	 */
115
-	public function delete_item_permissions_check( $request ) {
116
-		if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) {
117
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
115
+	public function delete_item_permissions_check($request) {
116
+		if ( ! wc_rest_check_manager_permissions('settings', 'delete')) {
117
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
118 118
 		}
119 119
 
120 120
 		return true;
@@ -126,32 +126,32 @@  discard block
 block discarded – undo
126 126
 	 * @param \WP_REST_Request $request Request params.
127 127
 	 * @return array
128 128
 	 */
129
-	public function get_items( $request ) {
129
+	public function get_items($request) {
130 130
 		$tax_classes = array();
131 131
 
132 132
 		// Add standard class.
133 133
 		$tax_classes[] = array(
134 134
 			'slug' => 'standard',
135
-			'name' => __( 'Standard rate', 'woocommerce' ),
135
+			'name' => __('Standard rate', 'woocommerce'),
136 136
 		);
137 137
 
138 138
 		$classes = \WC_Tax::get_tax_classes();
139 139
 
140
-		foreach ( $classes as $class ) {
140
+		foreach ($classes as $class) {
141 141
 			$tax_classes[] = array(
142
-				'slug' => sanitize_title( $class ),
142
+				'slug' => sanitize_title($class),
143 143
 				'name' => $class,
144 144
 			);
145 145
 		}
146 146
 
147 147
 		$data = array();
148
-		foreach ( $tax_classes as $tax_class ) {
149
-			$class  = $this->prepare_item_for_response( $tax_class, $request );
150
-			$class  = $this->prepare_response_for_collection( $class );
148
+		foreach ($tax_classes as $tax_class) {
149
+			$class  = $this->prepare_item_for_response($tax_class, $request);
150
+			$class  = $this->prepare_response_for_collection($class);
151 151
 			$data[] = $class;
152 152
 		}
153 153
 
154
-		return rest_ensure_response( $data );
154
+		return rest_ensure_response($data);
155 155
 	}
156 156
 
157 157
 	/**
@@ -160,33 +160,33 @@  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 ) {
163
+	public function create_item($request) {
164 164
 		$exists    = false;
165 165
 		$classes   = \WC_Tax::get_tax_classes();
166 166
 		$tax_class = array(
167
-			'slug' => sanitize_title( $request['name'] ),
167
+			'slug' => sanitize_title($request['name']),
168 168
 			'name' => $request['name'],
169 169
 		);
170 170
 
171 171
 		// Check if class exists.
172
-		foreach ( $classes as $key => $class ) {
173
-			if ( sanitize_title( $class ) === $tax_class['slug'] ) {
172
+		foreach ($classes as $key => $class) {
173
+			if (sanitize_title($class) === $tax_class['slug']) {
174 174
 				$exists = true;
175 175
 				break;
176 176
 			}
177 177
 		}
178 178
 
179 179
 		// Return error if tax class already exists.
180
-		if ( $exists ) {
181
-			return new \WP_Error( 'woocommerce_rest_tax_class_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) );
180
+		if ($exists) {
181
+			return new \WP_Error('woocommerce_rest_tax_class_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400));
182 182
 		}
183 183
 
184 184
 		// Add the new class.
185 185
 		$classes[] = $tax_class['name'];
186 186
 
187
-		update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) );
187
+		update_option('woocommerce_tax_classes', implode("\n", $classes));
188 188
 
189
-		$this->update_additional_fields_for_object( $tax_class, $request );
189
+		$this->update_additional_fields_for_object($tax_class, $request);
190 190
 
191 191
 		/**
192 192
 		 * Fires after a tax class is created or updated via the REST API.
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
 		 * @param \WP_REST_Request $request   Request object.
196 196
 		 * @param boolean         $creating  True when creating tax class, false when updating tax class.
197 197
 		 */
198
-		do_action( 'woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true );
198
+		do_action('woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true);
199 199
 
200
-		$request->set_param( 'context', 'edit' );
201
-		$response = $this->prepare_item_for_response( $tax_class, $request );
202
-		$response = rest_ensure_response( $response );
203
-		$response->set_status( 201 );
204
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug'] ) ) );
200
+		$request->set_param('context', 'edit');
201
+		$response = $this->prepare_item_for_response($tax_class, $request);
202
+		$response = rest_ensure_response($response);
203
+		$response->set_status(201);
204
+		$response->header('Location', rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug'])));
205 205
 
206 206
 		return $response;
207 207
 	}
@@ -212,40 +212,40 @@  discard block
 block discarded – undo
212 212
 	 * @param \WP_REST_Request $request Full details about the request.
213 213
 	 * @return \WP_Error\WP_REST_Response
214 214
 	 */
215
-	public function delete_item( $request ) {
215
+	public function delete_item($request) {
216 216
 		global $wpdb;
217 217
 
218
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
218
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
219 219
 
220 220
 		// We don't support trashing for this type, error out.
221
-		if ( ! $force ) {
222
-			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
221
+		if ( ! $force) {
222
+			return new \WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501));
223 223
 		}
224 224
 
225 225
 		$tax_class = array(
226
-			'slug' => sanitize_title( $request['slug'] ),
226
+			'slug' => sanitize_title($request['slug']),
227 227
 			'name' => '',
228 228
 		);
229 229
 		$classes = \WC_Tax::get_tax_classes();
230 230
 		$deleted = false;
231 231
 
232
-		foreach ( $classes as $key => $class ) {
233
-			if ( sanitize_title( $class ) === $tax_class['slug'] ) {
232
+		foreach ($classes as $key => $class) {
233
+			if (sanitize_title($class) === $tax_class['slug']) {
234 234
 				$tax_class['name'] = $class;
235
-				unset( $classes[ $key ] );
235
+				unset($classes[$key]);
236 236
 				$deleted = true;
237 237
 				break;
238 238
 			}
239 239
 		}
240 240
 
241
-		if ( ! $deleted ) {
242
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) );
241
+		if ( ! $deleted) {
242
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400));
243 243
 		}
244 244
 
245
-		$request->set_param( 'context', 'edit' );
246
-		$previous = $this->prepare_item_for_response( $tax_class, $request );
245
+		$request->set_param('context', 'edit');
246
+		$previous = $this->prepare_item_for_response($tax_class, $request);
247 247
 
248
-		update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) );
248
+		update_option('woocommerce_tax_classes', implode("\n", $classes));
249 249
 
250 250
 		// Delete tax rate locations locations from the selected class.
251 251
 		$wpdb->query(
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 		);
264 264
 
265 265
 		// Delete tax rates in the selected class.
266
-		$wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class['slug'] ), array( '%s' ) );
266
+		$wpdb->delete($wpdb->prefix . 'woocommerce_tax_rates', array('tax_rate_class' => $tax_class['slug']), array('%s'));
267 267
 
268 268
 		$response = new \WP_REST_Response();
269 269
 		$response->set_data(
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 		 * @param \WP_REST_Response $response  The response returned from the API.
281 281
 		 * @param \WP_REST_Request  $request   The request sent to the API.
282 282
 		 */
283
-		do_action( 'woocommerce_rest_delete_tax', (object) $tax_class, $response, $request );
283
+		do_action('woocommerce_rest_delete_tax', (object) $tax_class, $response, $request);
284 284
 
285 285
 		return $response;
286 286
 	}
@@ -292,17 +292,17 @@  discard block
 block discarded – undo
292 292
 	 * @param \WP_REST_Request $request Request object.
293 293
 	 * @return \WP_REST_Response $response Response data.
294 294
 	 */
295
-	public function prepare_item_for_response( $tax_class, $request ) {
295
+	public function prepare_item_for_response($tax_class, $request) {
296 296
 		$data = $tax_class;
297 297
 
298
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
299
-		$data    = $this->add_additional_fields_to_object( $data, $request );
300
-		$data    = $this->filter_response_by_context( $data, $context );
298
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
299
+		$data    = $this->add_additional_fields_to_object($data, $request);
300
+		$data    = $this->filter_response_by_context($data, $context);
301 301
 
302 302
 		// Wrap the data in a response object.
303
-		$response = rest_ensure_response( $data );
303
+		$response = rest_ensure_response($data);
304 304
 
305
-		$response->add_links( $this->prepare_links() );
305
+		$response->add_links($this->prepare_links());
306 306
 
307 307
 		/**
308 308
 		 * Filter tax object returned from the REST API.
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 		 * @param stdClass         $tax_class Tax object used to create response.
312 312
 		 * @param \WP_REST_Request  $request   Request object.
313 313
 		 */
314
-		return apply_filters( 'woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request );
314
+		return apply_filters('woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request);
315 315
 	}
316 316
 
317 317
 	/**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	protected function prepare_links() {
323 323
 		$links = array(
324 324
 			'collection' => array(
325
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
325
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
326 326
 			),
327 327
 		);
328 328
 
@@ -341,15 +341,15 @@  discard block
 block discarded – undo
341 341
 			'type'       => 'object',
342 342
 			'properties' => array(
343 343
 				'slug' => array(
344
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
344
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
345 345
 					'type'        => 'string',
346
-					'context'     => array( 'view', 'edit' ),
346
+					'context'     => array('view', 'edit'),
347 347
 					'readonly'    => true,
348 348
 				),
349 349
 				'name' => array(
350
-					'description' => __( 'Tax class name.', 'woocommerce' ),
350
+					'description' => __('Tax class name.', 'woocommerce'),
351 351
 					'type'        => 'string',
352
-					'context'     => array( 'view', 'edit' ),
352
+					'context'     => array('view', 'edit'),
353 353
 					'required'    => true,
354 354
 					'arg_options' => array(
355 355
 						'sanitize_callback' => 'sanitize_text_field',
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 			),
359 359
 		);
360 360
 
361
-		return $this->add_additional_fields_schema( $schema );
361
+		return $this->add_additional_fields_schema($schema);
362 362
 	}
363 363
 
364 364
 	/**
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 */
369 369
 	public function get_collection_params() {
370 370
 		return array(
371
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
371
+			'context' => $this->get_context_param(array('default' => 'view')),
372 372
 		);
373 373
 	}
374 374
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/AbstractTermsContoller.php 1 patch
Spacing   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\Version4\Controllers;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * Terms controller class.
@@ -38,26 +38,26 @@  discard block
 block discarded – undo
38 38
 			array(
39 39
 				array(
40 40
 					'methods'             => \WP_REST_Server::READABLE,
41
-					'callback'            => array( $this, 'get_items' ),
42
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
41
+					'callback'            => array($this, 'get_items'),
42
+					'permission_callback' => array($this, 'get_items_permissions_check'),
43 43
 					'args'                => $this->get_collection_params(),
44 44
 				),
45 45
 				array(
46 46
 					'methods'             => \WP_REST_Server::CREATABLE,
47
-					'callback'            => array( $this, 'create_item' ),
48
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
47
+					'callback'            => array($this, 'create_item'),
48
+					'permission_callback' => array($this, 'create_item_permissions_check'),
49 49
 					'args'                => array_merge(
50
-						$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
50
+						$this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
51 51
 						array(
52 52
 							'name' => array(
53 53
 								'type'        => 'string',
54
-								'description' => __( 'Name for the resource.', 'woocommerce' ),
54
+								'description' => __('Name for the resource.', 'woocommerce'),
55 55
 								'required'    => true,
56 56
 							),
57 57
 						)
58 58
 					),
59 59
 				),
60
-				'schema' => array( $this, 'get_public_item_schema' ),
60
+				'schema' => array($this, 'get_public_item_schema'),
61 61
 			),
62 62
 			true
63 63
 		);
@@ -68,37 +68,37 @@  discard block
 block discarded – undo
68 68
 			array(
69 69
 				'args'   => array(
70 70
 					'id' => array(
71
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
71
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
72 72
 						'type'        => 'integer',
73 73
 					),
74 74
 				),
75 75
 				array(
76 76
 					'methods'             => \WP_REST_Server::READABLE,
77
-					'callback'            => array( $this, 'get_item' ),
78
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
77
+					'callback'            => array($this, 'get_item'),
78
+					'permission_callback' => array($this, 'get_item_permissions_check'),
79 79
 					'args'                => array(
80
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
80
+						'context' => $this->get_context_param(array('default' => 'view')),
81 81
 					),
82 82
 				),
83 83
 				array(
84 84
 					'methods'             => \WP_REST_Server::EDITABLE,
85
-					'callback'            => array( $this, 'update_item' ),
86
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
87
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
85
+					'callback'            => array($this, 'update_item'),
86
+					'permission_callback' => array($this, 'update_item_permissions_check'),
87
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
88 88
 				),
89 89
 				array(
90 90
 					'methods'             => \WP_REST_Server::DELETABLE,
91
-					'callback'            => array( $this, 'delete_item' ),
92
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
91
+					'callback'            => array($this, 'delete_item'),
92
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
93 93
 					'args'                => array(
94 94
 						'force' => array(
95 95
 							'default'     => false,
96 96
 							'type'        => 'boolean',
97
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
97
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
98 98
 						),
99 99
 					),
100 100
 				),
101
-				'schema' => array( $this, 'get_public_item_schema' ),
101
+				'schema' => array($this, 'get_public_item_schema'),
102 102
 			),
103 103
 			true
104 104
 		);
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 			array(
110 110
 				array(
111 111
 					'methods'             => \WP_REST_Server::EDITABLE,
112
-					'callback'            => array( $this, 'batch_items' ),
113
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
114
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
112
+					'callback'            => array($this, 'batch_items'),
113
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
114
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
115 115
 				),
116
-				'schema' => array( $this, 'get_public_batch_schema' ),
116
+				'schema' => array($this, 'get_public_batch_schema'),
117 117
 			),
118 118
 			true
119 119
 		);
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
 	 * @param  \WP_REST_Request $request Full details about the request.
126 126
 	 * @return \WP_Error|boolean
127 127
 	 */
128
-	public function get_items_permissions_check( $request ) {
129
-		$permissions = $this->check_permissions( $request, 'read' );
130
-		if ( is_wp_error( $permissions ) ) {
128
+	public function get_items_permissions_check($request) {
129
+		$permissions = $this->check_permissions($request, 'read');
130
+		if (is_wp_error($permissions)) {
131 131
 			return $permissions;
132 132
 		}
133 133
 
134
-		if ( ! $permissions ) {
135
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
134
+		if ( ! $permissions) {
135
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
136 136
 		}
137 137
 
138 138
 		return true;
@@ -144,14 +144,14 @@  discard block
 block discarded – undo
144 144
 	 * @param  \WP_REST_Request $request Full details about the request.
145 145
 	 * @return \WP_Error|boolean
146 146
 	 */
147
-	public function create_item_permissions_check( $request ) {
148
-		$permissions = $this->check_permissions( $request, 'create' );
149
-		if ( is_wp_error( $permissions ) ) {
147
+	public function create_item_permissions_check($request) {
148
+		$permissions = $this->check_permissions($request, 'create');
149
+		if (is_wp_error($permissions)) {
150 150
 			return $permissions;
151 151
 		}
152 152
 
153
-		if ( ! $permissions ) {
154
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
153
+		if ( ! $permissions) {
154
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
155 155
 		}
156 156
 
157 157
 		return true;
@@ -163,14 +163,14 @@  discard block
 block discarded – undo
163 163
 	 * @param  \WP_REST_Request $request Full details about the request.
164 164
 	 * @return \WP_Error|boolean
165 165
 	 */
166
-	public function get_item_permissions_check( $request ) {
167
-		$permissions = $this->check_permissions( $request, 'read' );
168
-		if ( is_wp_error( $permissions ) ) {
166
+	public function get_item_permissions_check($request) {
167
+		$permissions = $this->check_permissions($request, 'read');
168
+		if (is_wp_error($permissions)) {
169 169
 			return $permissions;
170 170
 		}
171 171
 
172
-		if ( ! $permissions ) {
173
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
172
+		if ( ! $permissions) {
173
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
174 174
 		}
175 175
 
176 176
 		return true;
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 	 * @param  \WP_REST_Request $request Full details about the request.
183 183
 	 * @return \WP_Error|boolean
184 184
 	 */
185
-	public function update_item_permissions_check( $request ) {
186
-		$permissions = $this->check_permissions( $request, 'edit' );
187
-		if ( is_wp_error( $permissions ) ) {
185
+	public function update_item_permissions_check($request) {
186
+		$permissions = $this->check_permissions($request, 'edit');
187
+		if (is_wp_error($permissions)) {
188 188
 			return $permissions;
189 189
 		}
190 190
 
191
-		if ( ! $permissions ) {
192
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
191
+		if ( ! $permissions) {
192
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
193 193
 		}
194 194
 
195 195
 		return true;
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
 	 * @param  \WP_REST_Request $request Full details about the request.
202 202
 	 * @return \WP_Error|boolean
203 203
 	 */
204
-	public function delete_item_permissions_check( $request ) {
205
-		$permissions = $this->check_permissions( $request, 'delete' );
206
-		if ( is_wp_error( $permissions ) ) {
204
+	public function delete_item_permissions_check($request) {
205
+		$permissions = $this->check_permissions($request, 'delete');
206
+		if (is_wp_error($permissions)) {
207 207
 			return $permissions;
208 208
 		}
209 209
 
210
-		if ( ! $permissions ) {
211
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
210
+		if ( ! $permissions) {
211
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
212 212
 		}
213 213
 
214 214
 		return true;
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
 	 * @param  \WP_REST_Request $request Full details about the request.
221 221
 	 * @return boolean|\WP_Error
222 222
 	 */
223
-	public function batch_items_permissions_check( $request ) {
224
-		$permissions = $this->check_permissions( $request, 'batch' );
225
-		if ( is_wp_error( $permissions ) ) {
223
+	public function batch_items_permissions_check($request) {
224
+		$permissions = $this->check_permissions($request, 'batch');
225
+		if (is_wp_error($permissions)) {
226 226
 			return $permissions;
227 227
 		}
228 228
 
229
-		if ( ! $permissions ) {
230
-			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() ) );
229
+		if ( ! $permissions) {
230
+			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()));
231 231
 		}
232 232
 
233 233
 		return true;
@@ -240,26 +240,26 @@  discard block
 block discarded – undo
240 240
 	 * @param string          $context Request context.
241 241
 	 * @return bool|\WP_Error
242 242
 	 */
243
-	protected function check_permissions( $request, $context = 'read' ) {
243
+	protected function check_permissions($request, $context = 'read') {
244 244
 		// Get taxonomy.
245
-		$taxonomy = $this->get_taxonomy( $request );
246
-		if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) {
247
-			return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
245
+		$taxonomy = $this->get_taxonomy($request);
246
+		if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) {
247
+			return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Taxonomy does not exist.', 'woocommerce'), array('status' => 404));
248 248
 		}
249 249
 
250 250
 		// Check permissions for a single term.
251
-		$id = intval( $request['id'] );
252
-		if ( $id ) {
253
-			$term = get_term( $id, $taxonomy );
251
+		$id = intval($request['id']);
252
+		if ($id) {
253
+			$term = get_term($id, $taxonomy);
254 254
 
255
-			if ( is_wp_error( $term ) || ! $term || $term->taxonomy !== $taxonomy ) {
256
-				return new \WP_Error( 'woocommerce_rest_term_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) );
255
+			if (is_wp_error($term) || ! $term || $term->taxonomy !== $taxonomy) {
256
+				return new \WP_Error('woocommerce_rest_term_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404));
257 257
 			}
258 258
 
259
-			return wc_rest_check_product_term_permissions( $taxonomy, $context, $term->term_id );
259
+			return wc_rest_check_product_term_permissions($taxonomy, $context, $term->term_id);
260 260
 		}
261 261
 
262
-		return wc_rest_check_product_term_permissions( $taxonomy, $context );
262
+		return wc_rest_check_product_term_permissions($taxonomy, $context);
263 263
 	}
264 264
 
265 265
 	/**
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 	 * @param \WP_REST_Request $request Full details about the request.
269 269
 	 * @return \WP_REST_Response|\WP_Error
270 270
 	 */
271
-	public function get_items( $request ) {
272
-		$taxonomy      = $this->get_taxonomy( $request );
271
+	public function get_items($request) {
272
+		$taxonomy      = $this->get_taxonomy($request);
273 273
 		$prepared_args = array(
274 274
 			'exclude'    => $request['exclude'],
275 275
 			'include'    => $request['include'],
@@ -282,20 +282,20 @@  discard block
 block discarded – undo
282 282
 			'slug'       => $request['slug'],
283 283
 		);
284 284
 
285
-		if ( ! empty( $request['offset'] ) ) {
285
+		if ( ! empty($request['offset'])) {
286 286
 			$prepared_args['offset'] = $request['offset'];
287 287
 		} else {
288
-			$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
288
+			$prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number'];
289 289
 		}
290 290
 
291
-		$taxonomy_obj = get_taxonomy( $taxonomy );
291
+		$taxonomy_obj = get_taxonomy($taxonomy);
292 292
 
293
-		if ( $taxonomy_obj->hierarchical && isset( $request['parent'] ) ) {
294
-			if ( 0 === $request['parent'] ) {
293
+		if ($taxonomy_obj->hierarchical && isset($request['parent'])) {
294
+			if (0 === $request['parent']) {
295 295
 				// Only query top-level terms.
296 296
 				$prepared_args['parent'] = 0;
297 297
 			} else {
298
-				if ( $request['parent'] ) {
298
+				if ($request['parent']) {
299 299
 					$prepared_args['parent'] = $request['parent'];
300 300
 				}
301 301
 			}
@@ -313,60 +313,60 @@  discard block
 block discarded – undo
313 313
 		 *                                       passed to get_terms.
314 314
 		 * @param \WP_REST_Request $request       The current request.
315 315
 		 */
316
-		$prepared_args = apply_filters( "woocommerce_rest_{$taxonomy}_query", $prepared_args, $request );
316
+		$prepared_args = apply_filters("woocommerce_rest_{$taxonomy}_query", $prepared_args, $request);
317 317
 
318
-		if ( ! empty( $prepared_args['product'] ) ) {
319
-			$query_result = $this->get_terms_for_product( $prepared_args, $request );
318
+		if ( ! empty($prepared_args['product'])) {
319
+			$query_result = $this->get_terms_for_product($prepared_args, $request);
320 320
 			$total_terms  = $this->total_terms;
321 321
 		} else {
322
-			$query_result = get_terms( $taxonomy, $prepared_args );
322
+			$query_result = get_terms($taxonomy, $prepared_args);
323 323
 
324 324
 			$count_args = $prepared_args;
325
-			unset( $count_args['number'] );
326
-			unset( $count_args['offset'] );
327
-			$total_terms = wp_count_terms( $taxonomy, $count_args );
325
+			unset($count_args['number']);
326
+			unset($count_args['offset']);
327
+			$total_terms = wp_count_terms($taxonomy, $count_args);
328 328
 
329 329
 			// Ensure we don't return results when offset is out of bounds.
330 330
 			// See https://core.trac.wordpress.org/ticket/35935.
331
-			if ( $prepared_args['offset'] && $prepared_args['offset'] >= $total_terms ) {
331
+			if ($prepared_args['offset'] && $prepared_args['offset'] >= $total_terms) {
332 332
 				$query_result = array();
333 333
 			}
334 334
 
335 335
 			// wp_count_terms can return a falsy value when the term has no children.
336
-			if ( ! $total_terms ) {
336
+			if ( ! $total_terms) {
337 337
 				$total_terms = 0;
338 338
 			}
339 339
 		}
340 340
 		$response = array();
341
-		foreach ( $query_result as $term ) {
342
-			$data       = $this->prepare_item_for_response( $term, $request );
343
-			$response[] = $this->prepare_response_for_collection( $data );
341
+		foreach ($query_result as $term) {
342
+			$data       = $this->prepare_item_for_response($term, $request);
343
+			$response[] = $this->prepare_response_for_collection($data);
344 344
 		}
345 345
 
346
-		$response = rest_ensure_response( $response );
346
+		$response = rest_ensure_response($response);
347 347
 
348 348
 		// Store pagination values for headers then unset for count query.
349 349
 		$per_page = (int) $prepared_args['number'];
350
-		$page     = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
350
+		$page     = ceil((((int) $prepared_args['offset']) / $per_page) + 1);
351 351
 
352
-		$response->header( 'X-WP-Total', (int) $total_terms );
353
-		$max_pages = ceil( $total_terms / $per_page );
354
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
352
+		$response->header('X-WP-Total', (int) $total_terms);
353
+		$max_pages = ceil($total_terms / $per_page);
354
+		$response->header('X-WP-TotalPages', (int) $max_pages);
355 355
 
356
-		$base  = str_replace( '(?P<attribute_id>[\d]+)', $request['attribute_id'], $this->rest_base );
357
-		$base = add_query_arg( $request->get_query_params(), rest_url( '/' . $this->namespace . '/' . $base ) );
358
-		if ( $page > 1 ) {
356
+		$base = str_replace('(?P<attribute_id>[\d]+)', $request['attribute_id'], $this->rest_base);
357
+		$base = add_query_arg($request->get_query_params(), rest_url('/' . $this->namespace . '/' . $base));
358
+		if ($page > 1) {
359 359
 			$prev_page = $page - 1;
360
-			if ( $prev_page > $max_pages ) {
360
+			if ($prev_page > $max_pages) {
361 361
 				$prev_page = $max_pages;
362 362
 			}
363
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
364
-			$response->link_header( 'prev', $prev_link );
363
+			$prev_link = add_query_arg('page', $prev_page, $base);
364
+			$response->link_header('prev', $prev_link);
365 365
 		}
366
-		if ( $max_pages > $page ) {
366
+		if ($max_pages > $page) {
367 367
 			$next_page = $page + 1;
368
-			$next_link = add_query_arg( 'page', $next_page, $base );
369
-			$response->link_header( 'next', $next_link );
368
+			$next_link = add_query_arg('page', $next_page, $base);
369
+			$response->link_header('next', $next_link);
370 370
 		}
371 371
 
372 372
 		return $response;
@@ -378,47 +378,47 @@  discard block
 block discarded – undo
378 378
 	 * @param \WP_REST_Request $request Full details about the request.
379 379
 	 * @return \WP_REST_Request|\WP_Error
380 380
 	 */
381
-	public function create_item( $request ) {
382
-		$taxonomy = $this->get_taxonomy( $request );
381
+	public function create_item($request) {
382
+		$taxonomy = $this->get_taxonomy($request);
383 383
 		$name     = $request['name'];
384 384
 		$args     = array();
385 385
 		$schema   = $this->get_item_schema();
386 386
 
387
-		if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) {
387
+		if ( ! empty($schema['properties']['description']) && isset($request['description'])) {
388 388
 			$args['description'] = $request['description'];
389 389
 		}
390
-		if ( isset( $request['slug'] ) ) {
390
+		if (isset($request['slug'])) {
391 391
 			$args['slug'] = $request['slug'];
392 392
 		}
393
-		if ( isset( $request['parent'] ) ) {
394
-			if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
395
-				return new \WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) );
393
+		if (isset($request['parent'])) {
394
+			if ( ! is_taxonomy_hierarchical($taxonomy)) {
395
+				return new \WP_Error('woocommerce_rest_taxonomy_not_hierarchical', __('Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce'), array('status' => 400));
396 396
 			}
397 397
 			$args['parent'] = $request['parent'];
398 398
 		}
399 399
 
400
-		$term = wp_insert_term( $name, $taxonomy, $args );
401
-		if ( is_wp_error( $term ) ) {
402
-			$error_data = array( 'status' => 400 );
400
+		$term = wp_insert_term($name, $taxonomy, $args);
401
+		if (is_wp_error($term)) {
402
+			$error_data = array('status' => 400);
403 403
 
404 404
 			// If we're going to inform the client that the term exists,
405 405
 			// give them the identifier they can actually use.
406
-			$term_id = $term->get_error_data( 'term_exists' );
407
-			if ( $term_id ) {
406
+			$term_id = $term->get_error_data('term_exists');
407
+			if ($term_id) {
408 408
 				$error_data['resource_id'] = $term_id;
409 409
 			}
410 410
 
411
-			return new \WP_Error( $term->get_error_code(), $term->get_error_message(), $error_data );
411
+			return new \WP_Error($term->get_error_code(), $term->get_error_message(), $error_data);
412 412
 		}
413 413
 
414
-		$term = get_term( $term['term_id'], $taxonomy );
414
+		$term = get_term($term['term_id'], $taxonomy);
415 415
 
416
-		$this->update_additional_fields_for_object( $term, $request );
416
+		$this->update_additional_fields_for_object($term, $request);
417 417
 
418 418
 		// Add term data.
419
-		$meta_fields = $this->update_term_meta_fields( $term, $request );
420
-		if ( is_wp_error( $meta_fields ) ) {
421
-			wp_delete_term( $term->term_id, $taxonomy );
419
+		$meta_fields = $this->update_term_meta_fields($term, $request);
420
+		if (is_wp_error($meta_fields)) {
421
+			wp_delete_term($term->term_id, $taxonomy);
422 422
 
423 423
 			return $meta_fields;
424 424
 		}
@@ -430,19 +430,19 @@  discard block
 block discarded – undo
430 430
 		 * @param \WP_REST_Request $request   Request object.
431 431
 		 * @param boolean         $creating  True when creating term, false when updating.
432 432
 		 */
433
-		do_action( "woocommerce_rest_insert_{$taxonomy}", $term, $request, true );
433
+		do_action("woocommerce_rest_insert_{$taxonomy}", $term, $request, true);
434 434
 
435
-		$request->set_param( 'context', 'edit' );
436
-		$response = $this->prepare_item_for_response( $term, $request );
437
-		$response = rest_ensure_response( $response );
438
-		$response->set_status( 201 );
435
+		$request->set_param('context', 'edit');
436
+		$response = $this->prepare_item_for_response($term, $request);
437
+		$response = rest_ensure_response($response);
438
+		$response->set_status(201);
439 439
 
440 440
 		$base = '/' . $this->namespace . '/' . $this->rest_base;
441
-		if ( ! empty( $request['attribute_id'] ) ) {
442
-			$base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base );
441
+		if ( ! empty($request['attribute_id'])) {
442
+			$base = str_replace('(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base);
443 443
 		}
444 444
 
445
-		$response->header( 'Location', rest_url( $base . '/' . $term->term_id ) );
445
+		$response->header('Location', rest_url($base . '/' . $term->term_id));
446 446
 
447 447
 		return $response;
448 448
 	}
@@ -453,17 +453,17 @@  discard block
 block discarded – undo
453 453
 	 * @param \WP_REST_Request $request Full details about the request.
454 454
 	 * @return \WP_REST_Request|\WP_Error
455 455
 	 */
456
-	public function get_item( $request ) {
457
-		$taxonomy = $this->get_taxonomy( $request );
458
-		$term     = get_term( (int) $request['id'], $taxonomy );
456
+	public function get_item($request) {
457
+		$taxonomy = $this->get_taxonomy($request);
458
+		$term     = get_term((int) $request['id'], $taxonomy);
459 459
 
460
-		if ( is_wp_error( $term ) ) {
460
+		if (is_wp_error($term)) {
461 461
 			return $term;
462 462
 		}
463 463
 
464
-		$response = $this->prepare_item_for_response( $term, $request );
464
+		$response = $this->prepare_item_for_response($term, $request);
465 465
 
466
-		return rest_ensure_response( $response );
466
+		return rest_ensure_response($response);
467 467
 	}
468 468
 
469 469
 	/**
@@ -472,43 +472,43 @@  discard block
 block discarded – undo
472 472
 	 * @param \WP_REST_Request $request Full details about the request.
473 473
 	 * @return \WP_REST_Request|\WP_Error
474 474
 	 */
475
-	public function update_item( $request ) {
476
-		$taxonomy      = $this->get_taxonomy( $request );
477
-		$term          = get_term( (int) $request['id'], $taxonomy );
475
+	public function update_item($request) {
476
+		$taxonomy      = $this->get_taxonomy($request);
477
+		$term          = get_term((int) $request['id'], $taxonomy);
478 478
 		$schema        = $this->get_item_schema();
479 479
 		$prepared_args = array();
480 480
 
481
-		if ( isset( $request['name'] ) ) {
481
+		if (isset($request['name'])) {
482 482
 			$prepared_args['name'] = $request['name'];
483 483
 		}
484
-		if ( ! empty( $schema['properties']['description'] ) && isset( $request['description'] ) ) {
484
+		if ( ! empty($schema['properties']['description']) && isset($request['description'])) {
485 485
 			$prepared_args['description'] = $request['description'];
486 486
 		}
487
-		if ( isset( $request['slug'] ) ) {
487
+		if (isset($request['slug'])) {
488 488
 			$prepared_args['slug'] = $request['slug'];
489 489
 		}
490
-		if ( isset( $request['parent'] ) ) {
491
-			if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
492
-				return new \WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) );
490
+		if (isset($request['parent'])) {
491
+			if ( ! is_taxonomy_hierarchical($taxonomy)) {
492
+				return new \WP_Error('woocommerce_rest_taxonomy_not_hierarchical', __('Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce'), array('status' => 400));
493 493
 			}
494 494
 			$prepared_args['parent'] = $request['parent'];
495 495
 		}
496 496
 
497 497
 		// Only update the term if we haz something to update.
498
-		if ( ! empty( $prepared_args ) ) {
499
-			$update = wp_update_term( $term->term_id, $term->taxonomy, $prepared_args );
500
-			if ( is_wp_error( $update ) ) {
498
+		if ( ! empty($prepared_args)) {
499
+			$update = wp_update_term($term->term_id, $term->taxonomy, $prepared_args);
500
+			if (is_wp_error($update)) {
501 501
 				return $update;
502 502
 			}
503 503
 		}
504 504
 
505
-		$term = get_term( (int) $request['id'], $taxonomy );
505
+		$term = get_term((int) $request['id'], $taxonomy);
506 506
 
507
-		$this->update_additional_fields_for_object( $term, $request );
507
+		$this->update_additional_fields_for_object($term, $request);
508 508
 
509 509
 		// Update term data.
510
-		$meta_fields = $this->update_term_meta_fields( $term, $request );
511
-		if ( is_wp_error( $meta_fields ) ) {
510
+		$meta_fields = $this->update_term_meta_fields($term, $request);
511
+		if (is_wp_error($meta_fields)) {
512 512
 			return $meta_fields;
513 513
 		}
514 514
 
@@ -519,11 +519,11 @@  discard block
 block discarded – undo
519 519
 		 * @param \WP_REST_Request $request   Request object.
520 520
 		 * @param boolean         $creating  True when creating term, false when updating.
521 521
 		 */
522
-		do_action( "woocommerce_rest_insert_{$taxonomy}", $term, $request, false );
522
+		do_action("woocommerce_rest_insert_{$taxonomy}", $term, $request, false);
523 523
 
524
-		$request->set_param( 'context', 'edit' );
525
-		$response = $this->prepare_item_for_response( $term, $request );
526
-		return rest_ensure_response( $response );
524
+		$request->set_param('context', 'edit');
525
+		$response = $this->prepare_item_for_response($term, $request);
526
+		return rest_ensure_response($response);
527 527
 	}
528 528
 
529 529
 	/**
@@ -532,30 +532,30 @@  discard block
 block discarded – undo
532 532
 	 * @param \WP_REST_Request $request Full details about the request.
533 533
 	 * @return \WP_REST_Response|\WP_Error
534 534
 	 */
535
-	public function delete_item( $request ) {
536
-		$taxonomy = $this->get_taxonomy( $request );
537
-		$force    = isset( $request['force'] ) ? (bool) $request['force'] : false;
535
+	public function delete_item($request) {
536
+		$taxonomy = $this->get_taxonomy($request);
537
+		$force    = isset($request['force']) ? (bool) $request['force'] : false;
538 538
 
539 539
 		// We don't support trashing for this type, error out.
540
-		if ( ! $force ) {
541
-			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
540
+		if ( ! $force) {
541
+			return new \WP_Error('woocommerce_rest_trash_not_supported', __('Resource does not support trashing.', 'woocommerce'), array('status' => 501));
542 542
 		}
543 543
 
544
-		$term = get_term( (int) $request['id'], $taxonomy );
544
+		$term = get_term((int) $request['id'], $taxonomy);
545 545
 		// Get default category id.
546
-		$default_category_id = absint( get_option( 'default_product_cat', 0 ) );
546
+		$default_category_id = absint(get_option('default_product_cat', 0));
547 547
 
548 548
 		// Prevent deleting the default product category.
549
-		if ( $default_category_id === (int) $request['id'] ) {
550
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Default product category cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
549
+		if ($default_category_id === (int) $request['id']) {
550
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Default product category cannot be deleted.', 'woocommerce'), array('status' => 500));
551 551
 		}
552 552
 
553
-		$request->set_param( 'context', 'edit' );
554
-		$response = $this->prepare_item_for_response( $term, $request );
553
+		$request->set_param('context', 'edit');
554
+		$response = $this->prepare_item_for_response($term, $request);
555 555
 
556
-		$retval = wp_delete_term( $term->term_id, $term->taxonomy );
557
-		if ( ! $retval ) {
558
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
556
+		$retval = wp_delete_term($term->term_id, $term->taxonomy);
557
+		if ( ! $retval) {
558
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
559 559
 		}
560 560
 
561 561
 		/**
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 		 * @param \WP_REST_Response $response The response data.
566 566
 		 * @param \WP_REST_Request  $request  The request sent to the API.
567 567
 		 */
568
-		do_action( "woocommerce_rest_delete_{$taxonomy}", $term, $response, $request );
568
+		do_action("woocommerce_rest_delete_{$taxonomy}", $term, $response, $request);
569 569
 
570 570
 		return $response;
571 571
 	}
@@ -577,27 +577,27 @@  discard block
 block discarded – undo
577 577
 	 * @param \WP_REST_Request $request Full details about the request.
578 578
 	 * @return array Links for the given term.
579 579
 	 */
580
-	protected function prepare_links( $term, $request ) {
580
+	protected function prepare_links($term, $request) {
581 581
 		$base = '/' . $this->namespace . '/' . $this->rest_base;
582 582
 
583
-		if ( ! empty( $request['attribute_id'] ) ) {
584
-			$base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base );
583
+		if ( ! empty($request['attribute_id'])) {
584
+			$base = str_replace('(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base);
585 585
 		}
586 586
 
587 587
 		$links = array(
588 588
 			'self'       => array(
589
-				'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
589
+				'href' => rest_url(trailingslashit($base) . $term->term_id),
590 590
 			),
591 591
 			'collection' => array(
592
-				'href' => rest_url( $base ),
592
+				'href' => rest_url($base),
593 593
 			),
594 594
 		);
595 595
 
596
-		if ( $term->parent ) {
597
-			$parent_term = get_term( (int) $term->parent, $term->taxonomy );
598
-			if ( $parent_term ) {
596
+		if ($term->parent) {
597
+			$parent_term = get_term((int) $term->parent, $term->taxonomy);
598
+			if ($parent_term) {
599 599
 				$links['up'] = array(
600
-					'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ),
600
+					'href' => rest_url(trailingslashit($base) . $parent_term->term_id),
601 601
 				);
602 602
 			}
603 603
 		}
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 	 * @param \WP_REST_Request $request Full details about the request.
613 613
 	 * @return bool|\WP_Error
614 614
 	 */
615
-	protected function update_term_meta_fields( $term, $request ) {
615
+	protected function update_term_meta_fields($term, $request) {
616 616
 		return true;
617 617
 	}
618 618
 
@@ -628,19 +628,19 @@  discard block
 block discarded – undo
628 628
 	 * @param \WP_REST_Request $request       Full details about the request.
629 629
 	 * @return array List of term objects. (Total count in `$this->total_terms`).
630 630
 	 */
631
-	protected function get_terms_for_product( $prepared_args, $request ) {
632
-		$taxonomy = $this->get_taxonomy( $request );
631
+	protected function get_terms_for_product($prepared_args, $request) {
632
+		$taxonomy = $this->get_taxonomy($request);
633 633
 
634
-		$query_result = get_the_terms( $prepared_args['product'], $taxonomy );
635
-		if ( empty( $query_result ) ) {
634
+		$query_result = get_the_terms($prepared_args['product'], $taxonomy);
635
+		if (empty($query_result)) {
636 636
 			$this->total_terms = 0;
637 637
 			return array();
638 638
 		}
639 639
 
640 640
 		// get_items() verifies that we don't have `include` set, and default.
641 641
 		// ordering is by `name`.
642
-		if ( ! in_array( $prepared_args['orderby'], array( 'name', 'none', 'include' ), true ) ) {
643
-			switch ( $prepared_args['orderby'] ) {
642
+		if ( ! in_array($prepared_args['orderby'], array('name', 'none', 'include'), true)) {
643
+			switch ($prepared_args['orderby']) {
644 644
 				case 'id':
645 645
 					$this->sort_column = 'term_id';
646 646
 					break;
@@ -651,15 +651,15 @@  discard block
 block discarded – undo
651 651
 					$this->sort_column = $prepared_args['orderby'];
652 652
 					break;
653 653
 			}
654
-			usort( $query_result, array( $this, 'compare_terms' ) );
654
+			usort($query_result, array($this, 'compare_terms'));
655 655
 		}
656
-		if ( strtolower( $prepared_args['order'] ) !== 'asc' ) {
657
-			$query_result = array_reverse( $query_result );
656
+		if (strtolower($prepared_args['order']) !== 'asc') {
657
+			$query_result = array_reverse($query_result);
658 658
 		}
659 659
 
660 660
 		// Pagination.
661
-		$this->total_terms = count( $query_result );
662
-		$query_result      = array_slice( $query_result, $prepared_args['offset'], $prepared_args['number'] );
661
+		$this->total_terms = count($query_result);
662
+		$query_result      = array_slice($query_result, $prepared_args['offset'], $prepared_args['number']);
663 663
 
664 664
 		return $query_result;
665 665
 	}
@@ -673,16 +673,16 @@  discard block
 block discarded – undo
673 673
 	 * @param stdClass $right Term object.
674 674
 	 * @return int <0 if left is higher "priority" than right, 0 if equal, >0 if right is higher "priority" than left.
675 675
 	 */
676
-	protected function compare_terms( $left, $right ) {
676
+	protected function compare_terms($left, $right) {
677 677
 		$col       = $this->sort_column;
678 678
 		$left_val  = $left->$col;
679 679
 		$right_val = $right->$col;
680 680
 
681
-		if ( is_int( $left_val ) && is_int( $right_val ) ) {
681
+		if (is_int($left_val) && is_int($right_val)) {
682 682
 			return $left_val - $right_val;
683 683
 		}
684 684
 
685
-		return strcmp( $left_val, $right_val );
685
+		return strcmp($left_val, $right_val);
686 686
 	}
687 687
 
688 688
 	/**
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
 	public function get_collection_params() {
694 694
 		$params = parent::get_collection_params();
695 695
 
696
-		if ( '' !== $this->taxonomy && taxonomy_exists( $this->taxonomy ) ) {
697
-			$taxonomy = get_taxonomy( $this->taxonomy );
696
+		if ('' !== $this->taxonomy && taxonomy_exists($this->taxonomy)) {
697
+			$taxonomy = get_taxonomy($this->taxonomy);
698 698
 		} else {
699 699
 			$taxonomy               = new \stdClass();
700 700
 			$taxonomy->hierarchical = true;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 		$params['context']['default'] = 'view';
704 704
 
705 705
 		$params['exclude'] = array(
706
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
706
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
707 707
 			'type'              => 'array',
708 708
 			'items'             => array(
709 709
 				'type' => 'integer',
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
 			'sanitize_callback' => 'wp_parse_id_list',
713 713
 		);
714 714
 		$params['include'] = array(
715
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
715
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
716 716
 			'type'              => 'array',
717 717
 			'items'             => array(
718 718
 				'type' => 'integer',
@@ -720,16 +720,16 @@  discard block
 block discarded – undo
720 720
 			'default'           => array(),
721 721
 			'sanitize_callback' => 'wp_parse_id_list',
722 722
 		);
723
-		if ( ! $taxonomy->hierarchical ) {
723
+		if ( ! $taxonomy->hierarchical) {
724 724
 			$params['offset'] = array(
725
-				'description'       => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
725
+				'description'       => __('Offset the result set by a specific number of items.', 'woocommerce'),
726 726
 				'type'              => 'integer',
727 727
 				'sanitize_callback' => 'absint',
728 728
 				'validate_callback' => 'rest_validate_request_arg',
729 729
 			);
730 730
 		}
731
-		$params['order']      = array(
732
-			'description'       => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
731
+		$params['order'] = array(
732
+			'description'       => __('Order sort attribute ascending or descending.', 'woocommerce'),
733 733
 			'type'              => 'string',
734 734
 			'sanitize_callback' => 'sanitize_key',
735 735
 			'default'           => 'asc',
@@ -739,8 +739,8 @@  discard block
 block discarded – undo
739 739
 			),
740 740
 			'validate_callback' => 'rest_validate_request_arg',
741 741
 		);
742
-		$params['orderby']    = array(
743
-			'description'       => __( 'Sort collection by resource attribute.', 'woocommerce' ),
742
+		$params['orderby'] = array(
743
+			'description'       => __('Sort collection by resource attribute.', 'woocommerce'),
744 744
 			'type'              => 'string',
745 745
 			'sanitize_callback' => 'sanitize_key',
746 746
 			'default'           => 'name',
@@ -756,27 +756,27 @@  discard block
 block discarded – undo
756 756
 			'validate_callback' => 'rest_validate_request_arg',
757 757
 		);
758 758
 		$params['hide_empty'] = array(
759
-			'description'       => __( 'Whether to hide resources not assigned to any products.', 'woocommerce' ),
759
+			'description'       => __('Whether to hide resources not assigned to any products.', 'woocommerce'),
760 760
 			'type'              => 'boolean',
761 761
 			'default'           => false,
762 762
 			'validate_callback' => 'rest_validate_request_arg',
763 763
 		);
764
-		if ( $taxonomy->hierarchical ) {
764
+		if ($taxonomy->hierarchical) {
765 765
 			$params['parent'] = array(
766
-				'description'       => __( 'Limit result set to resources assigned to a specific parent.', 'woocommerce' ),
766
+				'description'       => __('Limit result set to resources assigned to a specific parent.', 'woocommerce'),
767 767
 				'type'              => 'integer',
768 768
 				'sanitize_callback' => 'absint',
769 769
 				'validate_callback' => 'rest_validate_request_arg',
770 770
 			);
771 771
 		}
772 772
 		$params['product'] = array(
773
-			'description'       => __( 'Limit result set to resources assigned to a specific product.', 'woocommerce' ),
773
+			'description'       => __('Limit result set to resources assigned to a specific product.', 'woocommerce'),
774 774
 			'type'              => 'integer',
775 775
 			'default'           => null,
776 776
 			'validate_callback' => 'rest_validate_request_arg',
777 777
 		);
778
-		$params['slug']    = array(
779
-			'description'       => __( 'Limit result set to resources with a specific slug.', 'woocommerce' ),
778
+		$params['slug'] = array(
779
+			'description'       => __('Limit result set to resources with a specific slug.', 'woocommerce'),
780 780
 			'type'              => 'string',
781 781
 			'validate_callback' => 'rest_validate_request_arg',
782 782
 		);
@@ -790,15 +790,15 @@  discard block
 block discarded – undo
790 790
 	 * @param \WP_REST_Request $request Full details about the request.
791 791
 	 * @return int|\WP_Error
792 792
 	 */
793
-	protected function get_taxonomy( $request ) {
793
+	protected function get_taxonomy($request) {
794 794
 		// Check if taxonomy is defined.
795 795
 		// Prevents check for attribute taxonomy more than one time for each query.
796
-		if ( '' !== $this->taxonomy ) {
796
+		if ('' !== $this->taxonomy) {
797 797
 			return $this->taxonomy;
798 798
 		}
799 799
 
800
-		if ( ! empty( $request['attribute_id'] ) ) {
801
-			$taxonomy = wc_attribute_taxonomy_name_by_id( (int) $request['attribute_id'] );
800
+		if ( ! empty($request['attribute_id'])) {
801
+			$taxonomy = wc_attribute_taxonomy_name_by_id((int) $request['attribute_id']);
802 802
 
803 803
 			$this->taxonomy = $taxonomy;
804 804
 		}
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Webhooks.php 1 patch
Spacing   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 /**
15 15
  * REST API Webhooks controller class.
@@ -39,28 +39,28 @@  discard block
 block discarded – undo
39 39
 			array(
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' ),
50
-					'args'                => array_merge( $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), array(
48
+					'callback'            => array($this, 'create_item'),
49
+					'permission_callback' => array($this, 'create_item_permissions_check'),
50
+					'args'                => array_merge($this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), array(
51 51
 						'topic' => array(
52 52
 							'required'    => true,
53 53
 							'type'        => 'string',
54
-							'description' => __( 'Webhook topic.', 'woocommerce' ),
54
+							'description' => __('Webhook topic.', 'woocommerce'),
55 55
 						),
56 56
 						'delivery_url' => array(
57 57
 							'required'    => true,
58 58
 							'type'        => 'string',
59
-							'description' => __( 'Webhook delivery URL.', 'woocommerce' ),
59
+							'description' => __('Webhook delivery URL.', 'woocommerce'),
60 60
 						),
61
-					) ),
61
+					)),
62 62
 				),
63
-				'schema' => array( $this, 'get_public_item_schema' ),
63
+				'schema' => array($this, 'get_public_item_schema'),
64 64
 			),
65 65
 			true
66 66
 		);
@@ -70,37 +70,37 @@  discard block
 block discarded – undo
70 70
 			array(
71 71
 				'args' => array(
72 72
 					'id' => array(
73
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
73
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
74 74
 						'type'        => 'integer',
75 75
 					),
76 76
 				),
77 77
 				array(
78 78
 					'methods'             => \WP_REST_Server::READABLE,
79
-					'callback'            => array( $this, 'get_item' ),
80
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
79
+					'callback'            => array($this, 'get_item'),
80
+					'permission_callback' => array($this, 'get_item_permissions_check'),
81 81
 					'args'                => array(
82
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
82
+						'context' => $this->get_context_param(array('default' => 'view')),
83 83
 					),
84 84
 				),
85 85
 				array(
86 86
 					'methods'             => \WP_REST_Server::EDITABLE,
87
-					'callback'            => array( $this, 'update_item' ),
88
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
89
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
87
+					'callback'            => array($this, 'update_item'),
88
+					'permission_callback' => array($this, 'update_item_permissions_check'),
89
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
90 90
 				),
91 91
 				array(
92 92
 					'methods'             => \WP_REST_Server::DELETABLE,
93
-					'callback'            => array( $this, 'delete_item' ),
94
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
93
+					'callback'            => array($this, 'delete_item'),
94
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
95 95
 					'args'                => array(
96 96
 						'force' => array(
97 97
 							'default'     => false,
98 98
 							'type'        => 'boolean',
99
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
99
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
100 100
 						),
101 101
 					),
102 102
 				),
103
-				'schema' => array( $this, 'get_public_item_schema' ),
103
+				'schema' => array($this, 'get_public_item_schema'),
104 104
 			),
105 105
 			true
106 106
 		);
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
 			array(
111 111
 				array(
112 112
 					'methods'             => \WP_REST_Server::EDITABLE,
113
-					'callback'            => array( $this, 'batch_items' ),
114
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
115
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
113
+					'callback'            => array($this, 'batch_items'),
114
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
115
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
116 116
 				),
117
-				'schema' => array( $this, 'get_public_batch_schema' ),
117
+				'schema' => array($this, 'get_public_batch_schema'),
118 118
 			),
119 119
 			true
120 120
 		);
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 	 * @param  \WP_REST_Request $request Full details about the request.
127 127
 	 * @return \WP_Error|boolean
128 128
 	 */
129
-	public function get_items_permissions_check( $request ) {
130
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) {
131
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
129
+	public function get_items_permissions_check($request) {
130
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) {
131
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
132 132
 		}
133 133
 
134 134
 		return true;
@@ -141,9 +141,9 @@  discard block
 block discarded – undo
141 141
 	 *
142 142
 	 * @return bool|\WP_Error
143 143
 	 */
144
-	public function create_item_permissions_check( $request ) {
145
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'create' ) ) {
146
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
144
+	public function create_item_permissions_check($request) {
145
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'create')) {
146
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
147 147
 		}
148 148
 
149 149
 		return true;
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 	 * @param  \WP_REST_Request $request Full details about the request.
156 156
 	 * @return \WP_Error|boolean
157 157
 	 */
158
-	public function get_item_permissions_check( $request ) {
159
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) {
160
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
158
+	public function get_item_permissions_check($request) {
159
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) {
160
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view 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 update_item_permissions_check( $request ) {
174
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'edit' ) ) {
175
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
173
+	public function update_item_permissions_check($request) {
174
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'edit')) {
175
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit 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 delete_item_permissions_check( $request ) {
189
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'delete' ) ) {
190
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
188
+	public function delete_item_permissions_check($request) {
189
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'delete')) {
190
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
191 191
 		}
192 192
 
193 193
 		return true;
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
 	 *
201 201
 	 * @return bool|\WP_Error
202 202
 	 */
203
-	public function batch_items_permissions_check( $request ) {
204
-		if ( ! wc_rest_check_manager_permissions( 'webhooks', 'batch' ) ) {
205
-			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() ) );
203
+	public function batch_items_permissions_check($request) {
204
+		if ( ! wc_rest_check_manager_permissions('webhooks', 'batch')) {
205
+			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()));
206 206
 		}
207 207
 
208 208
 		return true;
@@ -224,20 +224,20 @@  discard block
 block discarded – undo
224 224
 	 * @param \WP_REST_Request $request Full details about the request.
225 225
 	 * @return \WP_Error\WP_REST_Response
226 226
 	 */
227
-	public function get_items( $request ) {
227
+	public function get_items($request) {
228 228
 		$args            = array();
229 229
 		$args['order']   = $request['order'];
230 230
 		$args['orderby'] = $request['orderby'];
231 231
 		$args['status']  = 'all' === $request['status'] ? '' : $request['status'];
232
-		$args['include'] = implode( ',', $request['include'] );
233
-		$args['exclude'] = implode( ',', $request['exclude'] );
232
+		$args['include'] = implode(',', $request['include']);
233
+		$args['exclude'] = implode(',', $request['exclude']);
234 234
 		$args['limit']   = $request['per_page'];
235 235
 		$args['search']  = $request['search'];
236 236
 		$args['before']  = $request['before'];
237 237
 		$args['after']   = $request['after'];
238 238
 
239
-		if ( empty( $request['offset'] ) ) {
240
-			$args['offset'] = 1 < $request['page'] ? ( $request['page'] - 1 ) * $args['limit'] : 0;
239
+		if (empty($request['offset'])) {
240
+			$args['offset'] = 1 < $request['page'] ? ($request['page'] - 1) * $args['limit'] : 0;
241 241
 		}
242 242
 
243 243
 		/**
@@ -246,43 +246,43 @@  discard block
 block discarded – undo
246 246
 		 * @param array           $args    Array of arguments for $wpdb->get_results().
247 247
 		 * @param \WP_REST_Request $request The current request.
248 248
 		 */
249
-		$prepared_args = apply_filters( 'woocommerce_rest_webhook_query', $args, $request );
250
-		unset( $prepared_args['page'] );
249
+		$prepared_args = apply_filters('woocommerce_rest_webhook_query', $args, $request);
250
+		unset($prepared_args['page']);
251 251
 		$prepared_args['paginate'] = true;
252 252
 
253 253
 		// Get the webhooks.
254 254
 		$webhooks       = array();
255
-		$data_store     = \WC_Data_Store::load( 'webhook' );
256
-		$results        = $data_store->search_webhooks( $prepared_args );
255
+		$data_store     = \WC_Data_Store::load('webhook');
256
+		$results        = $data_store->search_webhooks($prepared_args);
257 257
 		$webhook_ids    = $results->webhooks;
258 258
 
259
-		foreach ( $webhook_ids as $webhook_id ) {
260
-			$data = $this->prepare_item_for_response( $webhook_id, $request );
261
-			$webhooks[] = $this->prepare_response_for_collection( $data );
259
+		foreach ($webhook_ids as $webhook_id) {
260
+			$data = $this->prepare_item_for_response($webhook_id, $request);
261
+			$webhooks[] = $this->prepare_response_for_collection($data);
262 262
 		}
263 263
 
264
-		$response       = rest_ensure_response( $webhooks );
264
+		$response       = rest_ensure_response($webhooks);
265 265
 		$per_page       = (int) $prepared_args['limit'];
266
-		$page           = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
266
+		$page           = ceil((((int) $prepared_args['offset']) / $per_page) + 1);
267 267
 		$total_webhooks = $results->total;
268 268
 		$max_pages      = $results->max_num_pages;
269
-		$base           = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
269
+		$base           = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
270 270
 
271
-		$response->header( 'X-WP-Total', $total_webhooks );
272
-		$response->header( 'X-WP-TotalPages', $max_pages );
271
+		$response->header('X-WP-Total', $total_webhooks);
272
+		$response->header('X-WP-TotalPages', $max_pages);
273 273
 
274
-		if ( $page > 1 ) {
274
+		if ($page > 1) {
275 275
 			$prev_page = $page - 1;
276
-			if ( $prev_page > $max_pages ) {
276
+			if ($prev_page > $max_pages) {
277 277
 				$prev_page = $max_pages;
278 278
 			}
279
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
280
-			$response->link_header( 'prev', $prev_link );
279
+			$prev_link = add_query_arg('page', $prev_page, $base);
280
+			$response->link_header('prev', $prev_link);
281 281
 		}
282
-		if ( $max_pages > $page ) {
282
+		if ($max_pages > $page) {
283 283
 			$next_page = $page + 1;
284
-			$next_link = add_query_arg( 'page', $next_page, $base );
285
-			$response->link_header( 'next', $next_link );
284
+			$next_link = add_query_arg('page', $next_page, $base);
285
+			$response->link_header('next', $next_link);
286 286
 		}
287 287
 
288 288
 		return $response;
@@ -294,15 +294,15 @@  discard block
 block discarded – undo
294 294
 	 * @param \WP_REST_Request $request Full details about the request.
295 295
 	 * @return \WP_Error\WP_REST_Response
296 296
 	 */
297
-	public function get_item( $request ) {
297
+	public function get_item($request) {
298 298
 		$id = (int) $request['id'];
299 299
 
300
-		if ( empty( $id ) ) {
301
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
300
+		if (empty($id)) {
301
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
302 302
 		}
303 303
 
304
-		$data     = $this->prepare_item_for_response( $id, $request );
305
-		$response = rest_ensure_response( $data );
304
+		$data     = $this->prepare_item_for_response($id, $request);
305
+		$response = rest_ensure_response($data);
306 306
 
307 307
 		return $response;
308 308
 	}
@@ -313,38 +313,38 @@  discard block
 block discarded – undo
313 313
 	 * @param \WP_REST_Request $request Full details about the request.
314 314
 	 * @return \WP_Error\WP_REST_Response
315 315
 	 */
316
-	public function create_item( $request ) {
317
-		if ( ! empty( $request['id'] ) ) {
316
+	public function create_item($request) {
317
+		if ( ! empty($request['id'])) {
318 318
 			/* translators: %s: post type */
319
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
319
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
320 320
 		}
321 321
 
322 322
 		// Validate topic.
323
-		if ( empty( $request['topic'] ) || ! wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) {
324
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic is required and must be valid.', 'woocommerce' ), array( 'status' => 400 ) );
323
+		if (empty($request['topic']) || ! wc_is_webhook_valid_topic(strtolower($request['topic']))) {
324
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic is required and must be valid.', 'woocommerce'), array('status' => 400));
325 325
 		}
326 326
 
327 327
 		// Validate delivery URL.
328
-		if ( empty( $request['delivery_url'] ) || ! wc_is_valid_url( $request['delivery_url'] ) ) {
329
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) );
328
+		if (empty($request['delivery_url']) || ! wc_is_valid_url($request['delivery_url'])) {
329
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400));
330 330
 		}
331 331
 
332
-		$post = $this->prepare_item_for_database( $request );
333
-		if ( is_wp_error( $post ) ) {
332
+		$post = $this->prepare_item_for_database($request);
333
+		if (is_wp_error($post)) {
334 334
 			return $post;
335 335
 		}
336 336
 
337 337
 		$webhook = new \WC_Webhook();
338
-		$webhook->set_name( $post->post_title );
339
-		$webhook->set_user_id( $post->post_author );
340
-		$webhook->set_status( 'publish' === $post->post_status ? 'active' : 'disabled' );
341
-		$webhook->set_topic( $request['topic'] );
342
-		$webhook->set_delivery_url( $request['delivery_url'] );
343
-		$webhook->set_secret( ! empty( $request['secret'] ) ? $request['secret'] : wp_generate_password( 50, true, true ) );
344
-		$webhook->set_api_version( $this->get_default_api_version() );
338
+		$webhook->set_name($post->post_title);
339
+		$webhook->set_user_id($post->post_author);
340
+		$webhook->set_status('publish' === $post->post_status ? 'active' : 'disabled');
341
+		$webhook->set_topic($request['topic']);
342
+		$webhook->set_delivery_url($request['delivery_url']);
343
+		$webhook->set_secret( ! empty($request['secret']) ? $request['secret'] : wp_generate_password(50, true, true));
344
+		$webhook->set_api_version($this->get_default_api_version());
345 345
 		$webhook->save();
346 346
 
347
-		$this->update_additional_fields_for_object( $webhook, $request );
347
+		$this->update_additional_fields_for_object($webhook, $request);
348 348
 
349 349
 		/**
350 350
 		 * Fires after a single item is created or updated via the REST API.
@@ -353,13 +353,13 @@  discard block
 block discarded – undo
353 353
 		 * @param \WP_REST_Request $request  Request object.
354 354
 		 * @param bool            $creating True when creating item, false when updating.
355 355
 		 */
356
-		do_action( "woocommerce_rest_insert_webhook_object", $webhook, $request, true );
356
+		do_action("woocommerce_rest_insert_webhook_object", $webhook, $request, true);
357 357
 
358
-		$request->set_param( 'context', 'edit' );
359
-		$response = $this->prepare_item_for_response( $webhook->get_id(), $request );
360
-		$response = rest_ensure_response( $response );
361
-		$response->set_status( 201 );
362
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $webhook->get_id() ) ) );
358
+		$request->set_param('context', 'edit');
359
+		$response = $this->prepare_item_for_response($webhook->get_id(), $request);
360
+		$response = rest_ensure_response($response);
361
+		$response->set_status(201);
362
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $webhook->get_id())));
363 363
 
364 364
 		// Send ping.
365 365
 		$webhook->deliver_ping();
@@ -373,58 +373,58 @@  discard block
 block discarded – undo
373 373
 	 * @param \WP_REST_Request $request Full details about the request.
374 374
 	 * @return \WP_Error\WP_REST_Response
375 375
 	 */
376
-	public function update_item( $request ) {
376
+	public function update_item($request) {
377 377
 		$id      = (int) $request['id'];
378
-		$webhook = wc_get_webhook( $id );
378
+		$webhook = wc_get_webhook($id);
379 379
 
380
-		if ( empty( $webhook ) || is_null( $webhook ) ) {
381
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
380
+		if (empty($webhook) || is_null($webhook)) {
381
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400));
382 382
 		}
383 383
 
384 384
 		// Update topic.
385
-		if ( ! empty( $request['topic'] ) ) {
386
-			if ( wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) {
387
-				$webhook->set_topic( $request['topic'] );
385
+		if ( ! empty($request['topic'])) {
386
+			if (wc_is_webhook_valid_topic(strtolower($request['topic']))) {
387
+				$webhook->set_topic($request['topic']);
388 388
 			} else {
389
-				return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic must be valid.', 'woocommerce' ), array( 'status' => 400 ) );
389
+				return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic must be valid.', 'woocommerce'), array('status' => 400));
390 390
 			}
391 391
 		}
392 392
 
393 393
 		// Update delivery URL.
394
-		if ( ! empty( $request['delivery_url'] ) ) {
395
-			if ( wc_is_valid_url( $request['delivery_url'] ) ) {
396
-				$webhook->set_delivery_url( $request['delivery_url'] );
394
+		if ( ! empty($request['delivery_url'])) {
395
+			if (wc_is_valid_url($request['delivery_url'])) {
396
+				$webhook->set_delivery_url($request['delivery_url']);
397 397
 			} else {
398
-				return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) );
398
+				return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400));
399 399
 			}
400 400
 		}
401 401
 
402 402
 		// Update secret.
403
-		if ( ! empty( $request['secret'] ) ) {
404
-			$webhook->set_secret( $request['secret'] );
403
+		if ( ! empty($request['secret'])) {
404
+			$webhook->set_secret($request['secret']);
405 405
 		}
406 406
 
407 407
 		// Update status.
408
-		if ( ! empty( $request['status'] ) ) {
409
-			if ( wc_is_webhook_valid_status( strtolower( $request['status'] ) ) ) {
410
-				$webhook->set_status( $request['status'] );
408
+		if ( ! empty($request['status'])) {
409
+			if (wc_is_webhook_valid_status(strtolower($request['status']))) {
410
+				$webhook->set_status($request['status']);
411 411
 			} else {
412
-				return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_status", __( 'Webhook status must be valid.', 'woocommerce' ), array( 'status' => 400 ) );
412
+				return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_status", __('Webhook status must be valid.', 'woocommerce'), array('status' => 400));
413 413
 			}
414 414
 		}
415 415
 
416
-		$post = $this->prepare_item_for_database( $request );
417
-		if ( is_wp_error( $post ) ) {
416
+		$post = $this->prepare_item_for_database($request);
417
+		if (is_wp_error($post)) {
418 418
 			return $post;
419 419
 		}
420 420
 
421
-		if ( isset( $post->post_title ) ) {
422
-			$webhook->set_name( $post->post_title );
421
+		if (isset($post->post_title)) {
422
+			$webhook->set_name($post->post_title);
423 423
 		}
424 424
 
425 425
 		$webhook->save();
426 426
 
427
-		$this->update_additional_fields_for_object( $webhook, $request );
427
+		$this->update_additional_fields_for_object($webhook, $request);
428 428
 
429 429
 		/**
430 430
 		 * Fires after a single item is created or updated via the REST API.
@@ -433,12 +433,12 @@  discard block
 block discarded – undo
433 433
 		 * @param \WP_REST_Request $request  Request object.
434 434
 		 * @param bool            $creating True when creating item, false when updating.
435 435
 		 */
436
-		do_action( "woocommerce_rest_insert_webhook_object", $webhook, $request, false );
436
+		do_action("woocommerce_rest_insert_webhook_object", $webhook, $request, false);
437 437
 
438
-		$request->set_param( 'context', 'edit' );
439
-		$response = $this->prepare_item_for_response( $webhook->get_id(), $request );
438
+		$request->set_param('context', 'edit');
439
+		$response = $this->prepare_item_for_response($webhook->get_id(), $request);
440 440
 
441
-		return rest_ensure_response( $response );
441
+		return rest_ensure_response($response);
442 442
 	}
443 443
 
444 444
 	/**
@@ -447,27 +447,27 @@  discard block
 block discarded – undo
447 447
 	 * @param \WP_REST_Request $request Full details about the request.
448 448
 	 * @return \WP_REST_Response|\WP_Error
449 449
 	 */
450
-	public function delete_item( $request ) {
450
+	public function delete_item($request) {
451 451
 		$id    = (int) $request['id'];
452
-		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;
452
+		$force = isset($request['force']) ? (bool) $request['force'] : false;
453 453
 
454 454
 		// We don't support trashing for this type, error out.
455
-		if ( ! $force ) {
456
-			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
455
+		if ( ! $force) {
456
+			return new \WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501));
457 457
 		}
458 458
 
459
-		$webhook = wc_get_webhook( $id );
459
+		$webhook = wc_get_webhook($id);
460 460
 
461
-		if ( empty( $webhook ) || is_null( $webhook ) ) {
462
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
461
+		if (empty($webhook) || is_null($webhook)) {
462
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
463 463
 		}
464 464
 
465
-		$request->set_param( 'context', 'edit' );
466
-		$previous = $this->prepare_item_for_response( $webhook, $request );
467
-		$result   = $webhook->delete( true );
468
-		if ( ! $result ) {
465
+		$request->set_param('context', 'edit');
466
+		$previous = $this->prepare_item_for_response($webhook, $request);
467
+		$result   = $webhook->delete(true);
468
+		if ( ! $result) {
469 469
 			/* translators: %s: post type */
470
-			return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
470
+			return new WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500));
471 471
 		}
472 472
 		$response = new \WP_REST_Response();
473 473
 		$response->set_data(
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 		 * @param \WP_REST_Response $response The response data.
485 485
 		 * @param \WP_REST_Request  $request  The request sent to the API.
486 486
 		 */
487
-		do_action( 'woocommerce_rest_delete_webhook_object', $webhook, $response, $request );
487
+		do_action('woocommerce_rest_delete_webhook_object', $webhook, $response, $request);
488 488
 
489 489
 		return $response;
490 490
 	}
@@ -495,17 +495,17 @@  discard block
 block discarded – undo
495 495
 	 * @param \WP_REST_Request $request Request object.
496 496
 	 * @return \WP_Error|stdClass $data Post object.
497 497
 	 */
498
-	protected function prepare_item_for_database( $request ) {
498
+	protected function prepare_item_for_database($request) {
499 499
 		$data = new \stdClass;
500 500
 
501 501
 		// Post ID.
502
-		if ( isset( $request['id'] ) ) {
503
-			$data->ID = absint( $request['id'] );
502
+		if (isset($request['id'])) {
503
+			$data->ID = absint($request['id']);
504 504
 		}
505 505
 
506 506
 		// Validate required POST fields.
507
-		if ( 'POST' === $request->get_method() && empty( $data->ID ) ) {
508
-			$data->post_title = ! empty( $request['name'] ) ? $request['name'] : sprintf( __( 'Webhook created on %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce' ) ) ); // @codingStandardsIgnoreLine
507
+		if ('POST' === $request->get_method() && empty($data->ID)) {
508
+			$data->post_title = ! empty($request['name']) ? $request['name'] : sprintf(__('Webhook created on %s', 'woocommerce'), strftime(_x('%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce'))); // @codingStandardsIgnoreLine
509 509
 
510 510
 			// Post author.
511 511
 			$data->post_author = get_current_user_id();
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
 		} else {
519 519
 
520 520
 			// Allow edit post title.
521
-			if ( ! empty( $request['name'] ) ) {
521
+			if ( ! empty($request['name'])) {
522 522
 				$data->post_title = $request['name'];
523 523
 			}
524 524
 		}
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 		 *                                       for inserting or updating the database.
540 540
 		 * @param \WP_REST_Request $request       Request object.
541 541
 		 */
542
-		return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $data, $request );
542
+		return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $data, $request);
543 543
 	}
544 544
 
545 545
 	/**
@@ -549,11 +549,11 @@  discard block
 block discarded – undo
549 549
 	 * @param \WP_REST_Request $request  Request object.
550 550
 	 * @return \WP_REST_Response $response
551 551
 	 */
552
-	public function prepare_item_for_response( $id, $request ) {
553
-		$webhook = wc_get_webhook( $id );
552
+	public function prepare_item_for_response($id, $request) {
553
+		$webhook = wc_get_webhook($id);
554 554
 
555
-		if ( empty( $webhook ) || is_null( $webhook ) ) {
556
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
555
+		if (empty($webhook) || is_null($webhook)) {
556
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400));
557 557
 		}
558 558
 
559 559
 		$data = array(
@@ -565,20 +565,20 @@  discard block
 block discarded – undo
565 565
 			'event'             => $webhook->get_event(),
566 566
 			'hooks'             => $webhook->get_hooks(),
567 567
 			'delivery_url'      => $webhook->get_delivery_url(),
568
-			'date_created'      => wc_rest_prepare_date_response( $webhook->get_date_created(), false ),
569
-			'date_created_gmt'  => wc_rest_prepare_date_response( $webhook->get_date_created() ),
570
-			'date_modified'     => wc_rest_prepare_date_response( $webhook->get_date_modified(), false ),
571
-			'date_modified_gmt' => wc_rest_prepare_date_response( $webhook->get_date_modified() ),
568
+			'date_created'      => wc_rest_prepare_date_response($webhook->get_date_created(), false),
569
+			'date_created_gmt'  => wc_rest_prepare_date_response($webhook->get_date_created()),
570
+			'date_modified'     => wc_rest_prepare_date_response($webhook->get_date_modified(), false),
571
+			'date_modified_gmt' => wc_rest_prepare_date_response($webhook->get_date_modified()),
572 572
 		);
573 573
 
574
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
575
-		$data    = $this->add_additional_fields_to_object( $data, $request );
576
-		$data    = $this->filter_response_by_context( $data, $context );
574
+		$context = ! empty($request['context']) ? $request['context'] : 'view';
575
+		$data    = $this->add_additional_fields_to_object($data, $request);
576
+		$data    = $this->filter_response_by_context($data, $context);
577 577
 
578 578
 		// Wrap the data in a response object.
579
-		$response = rest_ensure_response( $data );
579
+		$response = rest_ensure_response($data);
580 580
 
581
-		$response->add_links( $this->prepare_links( $webhook->get_id(), $request ) );
581
+		$response->add_links($this->prepare_links($webhook->get_id(), $request));
582 582
 
583 583
 		/**
584 584
 		 * Filter webhook object returned from the REST API.
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
 		 * @param WC_Webhook       $webhook  Webhook object used to create response.
588 588
 		 * @param \WP_REST_Request  $request  Request object.
589 589
 		 */
590
-		return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request );
590
+		return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request);
591 591
 	}
592 592
 
593 593
 	/**
@@ -596,13 +596,13 @@  discard block
 block discarded – undo
596 596
 	 * @param int $id Webhook ID.
597 597
 	 * @return array
598 598
 	 */
599
-	protected function prepare_links( $id ) {
599
+	protected function prepare_links($id) {
600 600
 		$links = array(
601 601
 			'self' => array(
602
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $id ) ),
602
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $id)),
603 603
 			),
604 604
 			'collection' => array(
605
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
605
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
606 606
 			),
607 607
 		);
608 608
 
@@ -621,89 +621,89 @@  discard block
 block discarded – undo
621 621
 			'type'       => 'object',
622 622
 			'properties' => array(
623 623
 				'id'                => array(
624
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
624
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
625 625
 					'type'        => 'integer',
626
-					'context'     => array( 'view', 'edit' ),
626
+					'context'     => array('view', 'edit'),
627 627
 					'readonly'    => true,
628 628
 				),
629 629
 				'name'              => array(
630
-					'description' => __( 'A friendly name for the webhook.', 'woocommerce' ),
630
+					'description' => __('A friendly name for the webhook.', 'woocommerce'),
631 631
 					'type'        => 'string',
632
-					'context'     => array( 'view', 'edit' ),
632
+					'context'     => array('view', 'edit'),
633 633
 				),
634 634
 				'status'            => array(
635
-					'description' => __( 'Webhook status.', 'woocommerce' ),
635
+					'description' => __('Webhook status.', 'woocommerce'),
636 636
 					'type'        => 'string',
637 637
 					'default'     => 'active',
638
-					'enum'        => array_keys( wc_get_webhook_statuses() ),
639
-					'context'     => array( 'view', 'edit' ),
638
+					'enum'        => array_keys(wc_get_webhook_statuses()),
639
+					'context'     => array('view', 'edit'),
640 640
 				),
641 641
 				'topic'             => array(
642
-					'description' => __( 'Webhook topic.', 'woocommerce' ),
642
+					'description' => __('Webhook topic.', 'woocommerce'),
643 643
 					'type'        => 'string',
644
-					'context'     => array( 'view', 'edit' ),
644
+					'context'     => array('view', 'edit'),
645 645
 				),
646 646
 				'resource'          => array(
647
-					'description' => __( 'Webhook resource.', 'woocommerce' ),
647
+					'description' => __('Webhook resource.', 'woocommerce'),
648 648
 					'type'        => 'string',
649
-					'context'     => array( 'view', 'edit' ),
649
+					'context'     => array('view', 'edit'),
650 650
 					'readonly'    => true,
651 651
 				),
652 652
 				'event'             => array(
653
-					'description' => __( 'Webhook event.', 'woocommerce' ),
653
+					'description' => __('Webhook event.', 'woocommerce'),
654 654
 					'type'        => 'string',
655
-					'context'     => array( 'view', 'edit' ),
655
+					'context'     => array('view', 'edit'),
656 656
 					'readonly'    => true,
657 657
 				),
658 658
 				'hooks'             => array(
659
-					'description' => __( 'WooCommerce action names associated with the webhook.', 'woocommerce' ),
659
+					'description' => __('WooCommerce action names associated with the webhook.', 'woocommerce'),
660 660
 					'type'        => 'array',
661
-					'context'     => array( 'view', 'edit' ),
661
+					'context'     => array('view', 'edit'),
662 662
 					'readonly'    => true,
663 663
 					'items'       => array(
664 664
 						'type' => 'string',
665 665
 					),
666 666
 				),
667 667
 				'delivery_url'      => array(
668
-					'description' => __( 'The URL where the webhook payload is delivered.', 'woocommerce' ),
668
+					'description' => __('The URL where the webhook payload is delivered.', 'woocommerce'),
669 669
 					'type'        => 'string',
670 670
 					'format'      => 'uri',
671
-					'context'     => array( 'view', 'edit' ),
671
+					'context'     => array('view', 'edit'),
672 672
 					'readonly'    => true,
673 673
 				),
674 674
 				'secret'            => array(
675
-					'description' => __( "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce' ),
675
+					'description' => __("Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce'),
676 676
 					'type'        => 'string',
677
-					'context'     => array( 'edit' ),
677
+					'context'     => array('edit'),
678 678
 				),
679 679
 				'date_created'      => array(
680
-					'description' => __( "The date the webhook was created, in the site's timezone.", 'woocommerce' ),
680
+					'description' => __("The date the webhook was created, in the site's timezone.", 'woocommerce'),
681 681
 					'type'        => 'date-time',
682
-					'context'     => array( 'view', 'edit' ),
682
+					'context'     => array('view', 'edit'),
683 683
 					'readonly'    => true,
684 684
 				),
685 685
 				'date_created_gmt'  => array(
686
-					'description' => __( 'The date the webhook was created, as GMT.', 'woocommerce' ),
686
+					'description' => __('The date the webhook was created, as GMT.', 'woocommerce'),
687 687
 					'type'        => 'date-time',
688
-					'context'     => array( 'view', 'edit' ),
688
+					'context'     => array('view', 'edit'),
689 689
 					'readonly'    => true,
690 690
 				),
691 691
 				'date_modified'     => array(
692
-					'description' => __( "The date the webhook was last modified, in the site's timezone.", 'woocommerce' ),
692
+					'description' => __("The date the webhook was last modified, in the site's timezone.", 'woocommerce'),
693 693
 					'type'        => 'date-time',
694
-					'context'     => array( 'view', 'edit' ),
694
+					'context'     => array('view', 'edit'),
695 695
 					'readonly'    => true,
696 696
 				),
697 697
 				'date_modified_gmt' => array(
698
-					'description' => __( 'The date the webhook was last modified, as GMT.', 'woocommerce' ),
698
+					'description' => __('The date the webhook was last modified, as GMT.', 'woocommerce'),
699 699
 					'type'        => 'date-time',
700
-					'context'     => array( 'view', 'edit' ),
700
+					'context'     => array('view', 'edit'),
701 701
 					'readonly'    => true,
702 702
 				),
703 703
 			),
704 704
 		);
705 705
 
706
-		return $this->add_additional_fields_schema( $schema );
706
+		return $this->add_additional_fields_schema($schema);
707 707
 	}
708 708
 
709 709
 	/**
@@ -717,19 +717,19 @@  discard block
 block discarded – undo
717 717
 		$params['context']['default'] = 'view';
718 718
 
719 719
 		$params['after'] = array(
720
-			'description'        => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
720
+			'description'        => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
721 721
 			'type'               => 'string',
722 722
 			'format'             => 'date-time',
723 723
 			'validate_callback'  => 'rest_validate_request_arg',
724 724
 		);
725 725
 		$params['before'] = array(
726
-			'description'        => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
726
+			'description'        => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
727 727
 			'type'               => 'string',
728 728
 			'format'             => 'date-time',
729 729
 			'validate_callback'  => 'rest_validate_request_arg',
730 730
 		);
731 731
 		$params['exclude'] = array(
732
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
732
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
733 733
 			'type'              => 'array',
734 734
 			'items'             => array(
735 735
 				'type'          => 'integer',
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 			'sanitize_callback' => 'wp_parse_id_list',
739 739
 		);
740 740
 		$params['include'] = array(
741
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
741
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
742 742
 			'type'              => 'array',
743 743
 			'items'             => array(
744 744
 				'type'          => 'integer',
@@ -747,20 +747,20 @@  discard block
 block discarded – undo
747 747
 			'sanitize_callback' => 'wp_parse_id_list',
748 748
 		);
749 749
 		$params['offset'] = array(
750
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
750
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
751 751
 			'type'               => 'integer',
752 752
 			'sanitize_callback'  => 'absint',
753 753
 			'validate_callback'  => 'rest_validate_request_arg',
754 754
 		);
755 755
 		$params['order'] = array(
756
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
756
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
757 757
 			'type'               => 'string',
758 758
 			'default'            => 'desc',
759
-			'enum'               => array( 'asc', 'desc' ),
759
+			'enum'               => array('asc', 'desc'),
760 760
 			'validate_callback'  => 'rest_validate_request_arg',
761 761
 		);
762 762
 		$params['orderby'] = array(
763
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
763
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
764 764
 			'type'               => 'string',
765 765
 			'default'            => 'date',
766 766
 			'enum'               => array(
@@ -772,9 +772,9 @@  discard block
 block discarded – undo
772 772
 		);
773 773
 		$params['status'] = array(
774 774
 			'default'           => 'all',
775
-			'description'       => __( 'Limit result set to webhooks assigned a specific status.', 'woocommerce' ),
775
+			'description'       => __('Limit result set to webhooks assigned a specific status.', 'woocommerce'),
776 776
 			'type'              => 'string',
777
-			'enum'              => array( 'all', 'active', 'paused', 'disabled' ),
777
+			'enum'              => array('all', 'active', 'paused', 'disabled'),
778 778
 			'sanitize_callback' => 'sanitize_key',
779 779
 			'validate_callback' => 'rest_validate_request_arg',
780 780
 		);
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/AbstractObjectsController.php 1 patch
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 
8 8
 namespace WooCommerce\RestApi\Version4\Controllers;
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * CRUD Object Controller.
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 	 * @param  int $id Object ID.
28 28
 	 * @return object WC_Data object or \WP_Error object.
29 29
 	 */
30
-	protected function get_object( $id ) {
30
+	protected function get_object($id) {
31 31
 		// translators: %s: Class method name.
32
-		return new \WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
32
+		return new \WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce'), __METHOD__), array('status' => 405));
33 33
 	}
34 34
 
35 35
 	/**
@@ -38,11 +38,11 @@  discard block
 block discarded – undo
38 38
 	 * @param  \WP_REST_Request $request Full details about the request.
39 39
 	 * @return \WP_Error|boolean
40 40
 	 */
41
-	public function get_item_permissions_check( $request ) {
42
-		$object = $this->get_object( (int) $request['id'] );
41
+	public function get_item_permissions_check($request) {
42
+		$object = $this->get_object((int) $request['id']);
43 43
 
44
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'read', $object->get_id() ) ) {
45
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
44
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'read', $object->get_id())) {
45
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
46 46
 		}
47 47
 
48 48
 		return true;
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 	 * @param  \WP_REST_Request $request Full details about the request.
55 55
 	 * @return \WP_Error|boolean
56 56
 	 */
57
-	public function update_item_permissions_check( $request ) {
58
-		$object = $this->get_object( (int) $request['id'] );
57
+	public function update_item_permissions_check($request) {
58
+		$object = $this->get_object((int) $request['id']);
59 59
 
60
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) {
61
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
60
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'edit', $object->get_id())) {
61
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
62 62
 		}
63 63
 
64 64
 		return true;
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
 	 * @param  \WP_REST_Request $request Full details about the request.
71 71
 	 * @return bool|\WP_Error
72 72
 	 */
73
-	public function delete_item_permissions_check( $request ) {
74
-		$object = $this->get_object( (int) $request['id'] );
73
+	public function delete_item_permissions_check($request) {
74
+		$object = $this->get_object((int) $request['id']);
75 75
 
76
-		if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
77
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
76
+		if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) {
77
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
78 78
 		}
79 79
 
80 80
 		return true;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 * @param  object $object Object.
87 87
 	 * @return string
88 88
 	 */
89
-	protected function get_permalink( $object ) {
89
+	protected function get_permalink($object) {
90 90
 		return '';
91 91
 	}
92 92
 
@@ -98,9 +98,9 @@  discard block
 block discarded – undo
98 98
 	 * @param  \WP_REST_Request $request Request object.
99 99
 	 * @return \WP_Error|\WP_REST_Response Response object on success, or \WP_Error object on failure.
100 100
 	 */
101
-	protected function prepare_object_for_response( $object, $request ) {
101
+	protected function prepare_object_for_response($object, $request) {
102 102
 		// translators: %s: Class method name.
103
-		return new \WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
103
+		return new \WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce'), __METHOD__), array('status' => 405));
104 104
 	}
105 105
 
106 106
 	/**
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 	 * @param  bool            $creating If is creating a new object.
112 112
 	 * @return \WP_Error|WC_Data The prepared item, or \WP_Error object on failure.
113 113
 	 */
114
-	protected function prepare_object_for_database( $request, $creating = false ) {
114
+	protected function prepare_object_for_database($request, $creating = false) {
115 115
 		// translators: %s: Class method name.
116
-		return new \WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce' ), __METHOD__ ), array( 'status' => 405 ) );
116
+		return new \WP_Error('invalid-method', sprintf(__("Method '%s' not implemented. Must be overridden in subclass.", 'woocommerce'), __METHOD__), array('status' => 405));
117 117
 	}
118 118
 
119 119
 	/**
@@ -122,18 +122,18 @@  discard block
 block discarded – undo
122 122
 	 * @param \WP_REST_Request $request Full details about the request.
123 123
 	 * @return \WP_Error|\WP_REST_Response
124 124
 	 */
125
-	public function get_item( $request ) {
126
-		$object = $this->get_object( (int) $request['id'] );
125
+	public function get_item($request) {
126
+		$object = $this->get_object((int) $request['id']);
127 127
 
128
-		if ( ! $object || 0 === $object->get_id() ) {
129
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
128
+		if ( ! $object || 0 === $object->get_id()) {
129
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
130 130
 		}
131 131
 
132
-		$data     = $this->prepare_object_for_response( $object, $request );
133
-		$response = rest_ensure_response( $data );
132
+		$data     = $this->prepare_object_for_response($object, $request);
133
+		$response = rest_ensure_response($data);
134 134
 
135
-		if ( $this->public ) {
136
-			$response->link_header( 'alternate', $this->get_permalink( $object ), array( 'type' => 'text/html' ) );
135
+		if ($this->public) {
136
+			$response->link_header('alternate', $this->get_permalink($object), array('type' => 'text/html'));
137 137
 		}
138 138
 
139 139
 		return $response;
@@ -147,21 +147,21 @@  discard block
 block discarded – undo
147 147
 	 * @param  bool            $creating If is creating a new object.
148 148
 	 * @return WC_Data|\WP_Error
149 149
 	 */
150
-	protected function save_object( $request, $creating = false ) {
150
+	protected function save_object($request, $creating = false) {
151 151
 		try {
152
-			$object = $this->prepare_object_for_database( $request, $creating );
152
+			$object = $this->prepare_object_for_database($request, $creating);
153 153
 
154
-			if ( is_wp_error( $object ) ) {
154
+			if (is_wp_error($object)) {
155 155
 				return $object;
156 156
 			}
157 157
 
158 158
 			$object->save();
159 159
 
160
-			return $this->get_object( $object->get_id() );
161
-		} catch ( \WC_Data_Exception $e ) {
162
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
163
-		} catch ( \WC_REST_Exception $e ) {
164
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
160
+			return $this->get_object($object->get_id());
161
+		} catch (\WC_Data_Exception $e) {
162
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
163
+		} catch (\WC_REST_Exception $e) {
164
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
165 165
 		}
166 166
 	}
167 167
 
@@ -171,26 +171,26 @@  discard block
 block discarded – undo
171 171
 	 * @param \WP_REST_Request $request Full details about the request.
172 172
 	 * @return \WP_Error\WP_REST_Response
173 173
 	 */
174
-	public function create_item( $request ) {
175
-		if ( ! empty( $request['id'] ) ) {
174
+	public function create_item($request) {
175
+		if ( ! empty($request['id'])) {
176 176
 			/* translators: %s: post type */
177
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) );
177
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400));
178 178
 		}
179 179
 
180
-		$object = $this->save_object( $request, true );
180
+		$object = $this->save_object($request, true);
181 181
 
182
-		if ( is_wp_error( $object ) ) {
182
+		if (is_wp_error($object)) {
183 183
 			return $object;
184 184
 		}
185 185
 
186 186
 		try {
187
-			$this->update_additional_fields_for_object( $object, $request );
188
-		} catch ( \WC_Data_Exception $e ) {
187
+			$this->update_additional_fields_for_object($object, $request);
188
+		} catch (\WC_Data_Exception $e) {
189 189
 			$object->delete();
190
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
191
-		} catch ( \WC_REST_Exception $e ) {
190
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
191
+		} catch (\WC_REST_Exception $e) {
192 192
 			$object->delete();
193
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
193
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
194 194
 		}
195 195
 
196 196
 		/**
@@ -200,13 +200,13 @@  discard block
 block discarded – undo
200 200
 		 * @param \WP_REST_Request $request   Request object.
201 201
 		 * @param boolean         $creating  True when creating object, false when updating.
202 202
 		 */
203
-		do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, true );
203
+		do_action("woocommerce_rest_insert_{$this->post_type}_object", $object, $request, true);
204 204
 
205
-		$request->set_param( 'context', 'edit' );
206
-		$response = $this->prepare_object_for_response( $object, $request );
207
-		$response = rest_ensure_response( $response );
208
-		$response->set_status( 201 );
209
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ) );
205
+		$request->set_param('context', 'edit');
206
+		$response = $this->prepare_object_for_response($object, $request);
207
+		$response = rest_ensure_response($response);
208
+		$response->set_status(201);
209
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())));
210 210
 
211 211
 		return $response;
212 212
 	}
@@ -217,25 +217,25 @@  discard block
 block discarded – undo
217 217
 	 * @param \WP_REST_Request $request Full details about the request.
218 218
 	 * @return \WP_Error\WP_REST_Response
219 219
 	 */
220
-	public function update_item( $request ) {
221
-		$object = $this->get_object( (int) $request['id'] );
220
+	public function update_item($request) {
221
+		$object = $this->get_object((int) $request['id']);
222 222
 
223
-		if ( ! $object || 0 === $object->get_id() ) {
224
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
223
+		if ( ! $object || 0 === $object->get_id()) {
224
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
225 225
 		}
226 226
 
227
-		$object = $this->save_object( $request, false );
227
+		$object = $this->save_object($request, false);
228 228
 
229
-		if ( is_wp_error( $object ) ) {
229
+		if (is_wp_error($object)) {
230 230
 			return $object;
231 231
 		}
232 232
 
233 233
 		try {
234
-			$this->update_additional_fields_for_object( $object, $request );
235
-		} catch ( \WC_Data_Exception $e ) {
236
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
237
-		} catch ( \WC_REST_Exception $e ) {
238
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
234
+			$this->update_additional_fields_for_object($object, $request);
235
+		} catch (\WC_Data_Exception $e) {
236
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData());
237
+		} catch (\WC_REST_Exception $e) {
238
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
239 239
 		}
240 240
 
241 241
 		/**
@@ -245,11 +245,11 @@  discard block
 block discarded – undo
245 245
 		 * @param \WP_REST_Request $request   Request object.
246 246
 		 * @param boolean         $creating  True when creating object, false when updating.
247 247
 		 */
248
-		do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, false );
248
+		do_action("woocommerce_rest_insert_{$this->post_type}_object", $object, $request, false);
249 249
 
250
-		$request->set_param( 'context', 'edit' );
251
-		$response = $this->prepare_object_for_response( $object, $request );
252
-		return rest_ensure_response( $response );
250
+		$request->set_param('context', 'edit');
251
+		$response = $this->prepare_object_for_response($object, $request);
252
+		return rest_ensure_response($response);
253 253
 	}
254 254
 
255 255
 	/**
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 * @param  \WP_REST_Request $request Full details about the request.
260 260
 	 * @return array
261 261
 	 */
262
-	protected function prepare_objects_query( $request ) {
262
+	protected function prepare_objects_query($request) {
263 263
 		$args                        = array();
264 264
 		$args['offset']              = $request['offset'];
265 265
 		$args['order']               = $request['order'];
@@ -274,18 +274,18 @@  discard block
 block discarded – undo
274 274
 		$args['s']                   = $request['search'];
275 275
 		$args['fields']              = 'ids';
276 276
 
277
-		if ( 'date' === $args['orderby'] ) {
277
+		if ('date' === $args['orderby']) {
278 278
 			$args['orderby'] = 'date ID';
279 279
 		}
280 280
 
281 281
 		$args['date_query'] = array();
282 282
 		// Set before into date query. Date query must be specified as an array of an array.
283
-		if ( isset( $request['before'] ) ) {
283
+		if (isset($request['before'])) {
284 284
 			$args['date_query'][0]['before'] = $request['before'];
285 285
 		}
286 286
 
287 287
 		// Set after into date query. Date query must be specified as an array of an array.
288
-		if ( isset( $request['after'] ) ) {
288
+		if (isset($request['after'])) {
289 289
 			$args['date_query'][0]['after'] = $request['after'];
290 290
 		}
291 291
 
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
 		 * @param array           $args    Key value array of query var to query value.
302 302
 		 * @param \WP_REST_Request $request The request used.
303 303
 		 */
304
-		$args = apply_filters( "woocommerce_rest_{$this->post_type}_object_query", $args, $request );
304
+		$args = apply_filters("woocommerce_rest_{$this->post_type}_object_query", $args, $request);
305 305
 
306
-		return $this->prepare_items_query( $args, $request );
306
+		return $this->prepare_items_query($args, $request);
307 307
 	}
308 308
 
309 309
 	/**
@@ -313,23 +313,23 @@  discard block
 block discarded – undo
313 313
 	 * @param  array $query_args Query args.
314 314
 	 * @return array
315 315
 	 */
316
-	protected function get_objects( $query_args ) {
316
+	protected function get_objects($query_args) {
317 317
 		$query  = new \WP_Query();
318
-		$result = $query->query( $query_args );
318
+		$result = $query->query($query_args);
319 319
 
320 320
 		$total_posts = $query->found_posts;
321
-		if ( $total_posts < 1 ) {
321
+		if ($total_posts < 1) {
322 322
 			// Out-of-bounds, run the query again without LIMIT for total count.
323
-			unset( $query_args['paged'] );
323
+			unset($query_args['paged']);
324 324
 			$count_query = new \WP_Query();
325
-			$count_query->query( $query_args );
325
+			$count_query->query($query_args);
326 326
 			$total_posts = $count_query->found_posts;
327 327
 		}
328 328
 
329 329
 		return array(
330
-			'objects' => array_map( array( $this, 'get_object' ), $result ),
330
+			'objects' => array_map(array($this, 'get_object'), $result),
331 331
 			'total'   => (int) $total_posts,
332
-			'pages'   => (int) ceil( $total_posts / (int) $query->query_vars['posts_per_page'] ),
332
+			'pages'   => (int) ceil($total_posts / (int) $query->query_vars['posts_per_page']),
333 333
 		);
334 334
 	}
335 335
 
@@ -339,55 +339,55 @@  discard block
 block discarded – undo
339 339
 	 * @param \WP_REST_Request $request Full details about the request.
340 340
 	 * @return \WP_Error\WP_REST_Response
341 341
 	 */
342
-	public function get_items( $request ) {
343
-		$query_args    = $this->prepare_objects_query( $request );
344
-		$query_results = $this->get_objects( $query_args );
342
+	public function get_items($request) {
343
+		$query_args    = $this->prepare_objects_query($request);
344
+		$query_results = $this->get_objects($query_args);
345 345
 
346 346
 		$objects = array();
347
-		foreach ( $query_results['objects'] as $object ) {
348
-			if ( ! wc_rest_check_post_permissions( $this->post_type, 'read', $object->get_id() ) ) {
347
+		foreach ($query_results['objects'] as $object) {
348
+			if ( ! wc_rest_check_post_permissions($this->post_type, 'read', $object->get_id())) {
349 349
 				continue;
350 350
 			}
351 351
 
352
-			$data      = $this->prepare_object_for_response( $object, $request );
353
-			$objects[] = $this->prepare_response_for_collection( $data );
352
+			$data      = $this->prepare_object_for_response($object, $request);
353
+			$objects[] = $this->prepare_response_for_collection($data);
354 354
 		}
355 355
 
356 356
 		$page      = (int) $query_args['paged'];
357 357
 		$max_pages = $query_results['pages'];
358 358
 
359
-		$response = rest_ensure_response( $objects );
360
-		$response->header( 'X-WP-Total', $query_results['total'] );
361
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
359
+		$response = rest_ensure_response($objects);
360
+		$response->header('X-WP-Total', $query_results['total']);
361
+		$response->header('X-WP-TotalPages', (int) $max_pages);
362 362
 
363 363
 		$base          = $this->rest_base;
364 364
 		$attrib_prefix = '(?P<';
365
-		if ( strpos( $base, $attrib_prefix ) !== false ) {
365
+		if (strpos($base, $attrib_prefix) !== false) {
366 366
 			$attrib_names = array();
367
-			preg_match( '/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE );
368
-			foreach ( $attrib_names as $attrib_name_match ) {
369
-				$beginning_offset = strlen( $attrib_prefix );
370
-				$attrib_name_end  = strpos( $attrib_name_match[0], '>', $attrib_name_match[1] );
371
-				$attrib_name      = substr( $attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset );
372
-				if ( isset( $request[ $attrib_name ] ) ) {
373
-					$base  = str_replace( "(?P<$attrib_name>[\d]+)", $request[ $attrib_name ], $base );
367
+			preg_match('/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE);
368
+			foreach ($attrib_names as $attrib_name_match) {
369
+				$beginning_offset = strlen($attrib_prefix);
370
+				$attrib_name_end  = strpos($attrib_name_match[0], '>', $attrib_name_match[1]);
371
+				$attrib_name      = substr($attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset);
372
+				if (isset($request[$attrib_name])) {
373
+					$base = str_replace("(?P<$attrib_name>[\d]+)", $request[$attrib_name], $base);
374 374
 				}
375 375
 			}
376 376
 		}
377
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ) );
377
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $base)));
378 378
 
379
-		if ( $page > 1 ) {
379
+		if ($page > 1) {
380 380
 			$prev_page = $page - 1;
381
-			if ( $prev_page > $max_pages ) {
381
+			if ($prev_page > $max_pages) {
382 382
 				$prev_page = $max_pages;
383 383
 			}
384
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
385
-			$response->link_header( 'prev', $prev_link );
384
+			$prev_link = add_query_arg('page', $prev_page, $base);
385
+			$response->link_header('prev', $prev_link);
386 386
 		}
387
-		if ( $max_pages > $page ) {
387
+		if ($max_pages > $page) {
388 388
 			$next_page = $page + 1;
389
-			$next_link = add_query_arg( 'page', $next_page, $base );
390
-			$response->link_header( 'next', $next_link );
389
+			$next_link = add_query_arg('page', $next_page, $base);
390
+			$response->link_header('next', $next_link);
391 391
 		}
392 392
 
393 393
 		return $response;
@@ -399,49 +399,49 @@  discard block
 block discarded – undo
399 399
 	 * @param \WP_REST_Request $request Full details about the request.
400 400
 	 * @return \WP_REST_Response|\WP_Error
401 401
 	 */
402
-	public function delete_item( $request ) {
402
+	public function delete_item($request) {
403 403
 		$force  = (bool) $request['force'];
404
-		$object = $this->get_object( (int) $request['id'] );
404
+		$object = $this->get_object((int) $request['id']);
405 405
 		$result = false;
406 406
 
407
-		if ( ! $object || 0 === $object->get_id() ) {
408
-			return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
407
+		if ( ! $object || 0 === $object->get_id()) {
408
+			return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
409 409
 		}
410 410
 
411
-		$supports_trash = $this->supports_trash( $object );
411
+		$supports_trash = $this->supports_trash($object);
412 412
 
413
-		if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
413
+		if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) {
414 414
 			/* translators: %s: post type */
415
-			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() ) );
415
+			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()));
416 416
 		}
417 417
 
418
-		$request->set_param( 'context', 'edit' );
419
-		$previous = $this->prepare_object_for_response( $object, $request );
418
+		$request->set_param('context', 'edit');
419
+		$previous = $this->prepare_object_for_response($object, $request);
420 420
 
421 421
 		// If we're forcing, then delete permanently.
422
-		if ( $force ) {
423
-			$object->delete( true );
422
+		if ($force) {
423
+			$object->delete(true);
424 424
 			$result = 0 === $object->get_id();
425 425
 		} else {
426 426
 			// If we don't support trashing for this type, error out.
427
-			if ( ! $supports_trash ) {
427
+			if ( ! $supports_trash) {
428 428
 				/* translators: %s: post type */
429
-				return new \WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) );
429
+				return new \WP_Error('woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array('status' => 501));
430 430
 			}
431 431
 
432 432
 			// Otherwise, only trash if we haven't already.
433
-			if ( is_callable( array( $object, 'get_status' ) ) && 'trash' === $object->get_status() ) {
433
+			if (is_callable(array($object, 'get_status')) && 'trash' === $object->get_status()) {
434 434
 				/* translators: %s: post type */
435
-				return new \WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) );
435
+				return new \WP_Error('woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array('status' => 410));
436 436
 			} else {
437 437
 				$object->delete();
438
-				$result = is_callable( array( $object, 'get_status' ) ) ? 'trash' === $object->get_status() : true;
438
+				$result = is_callable(array($object, 'get_status')) ? 'trash' === $object->get_status() : true;
439 439
 			}
440 440
 		}
441 441
 
442
-		if ( ! $result ) {
442
+		if ( ! $result) {
443 443
 			/* translators: %s: post type */
444
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
444
+			return new \WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500));
445 445
 		}
446 446
 
447 447
 		$response = new \WP_REST_Response();
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 		 * @param \WP_REST_Response $response The response data.
460 460
 		 * @param \WP_REST_Request  $request  The request sent to the API.
461 461
 		 */
462
-		do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request );
462
+		do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request);
463 463
 
464 464
 		return $response;
465 465
 	}
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 	 * @oaram  object $object Object to check.
471 471
 	 * @return boolean
472 472
 	 */
473
-	protected function supports_trash( $object ) {
473
+	protected function supports_trash($object) {
474 474
 		$supports_trash = EMPTY_TRASH_DAYS > 0;
475 475
 
476 476
 		/**
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
 		 * @param boolean $supports_trash Whether the object type support trashing.
482 482
 		 * @param WC_Data $object         The object being considered for trashing support.
483 483
 		 */
484
-		return apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object );
484
+		return apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object);
485 485
 	}
486 486
 
487 487
 	/**
@@ -491,13 +491,13 @@  discard block
 block discarded – undo
491 491
 	 * @param \WP_REST_Request $request Request object.
492 492
 	 * @return array                   Links for the given post.
493 493
 	 */
494
-	protected function prepare_links( $object, $request ) {
494
+	protected function prepare_links($object, $request) {
495 495
 		$links = array(
496 496
 			'self' => array(
497
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ),
497
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())),
498 498
 			),
499 499
 			'collection' => array(
500
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
500
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
501 501
 			),
502 502
 		);
503 503
 
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 		$params['context']['default'] = 'view';
516 516
 
517 517
 		$params['page'] = array(
518
-			'description'        => __( 'Current page of the collection.', 'woocommerce' ),
518
+			'description'        => __('Current page of the collection.', 'woocommerce'),
519 519
 			'type'               => 'integer',
520 520
 			'default'            => 1,
521 521
 			'sanitize_callback'  => 'absint',
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
 			'minimum'            => 1,
524 524
 		);
525 525
 		$params['per_page'] = array(
526
-			'description'        => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ),
526
+			'description'        => __('Maximum number of items to be returned in result set.', 'woocommerce'),
527 527
 			'type'               => 'integer',
528 528
 			'default'            => 10,
529 529
 			'minimum'            => 1,
@@ -532,25 +532,25 @@  discard block
 block discarded – undo
532 532
 			'validate_callback'  => 'rest_validate_request_arg',
533 533
 		);
534 534
 		$params['search'] = array(
535
-			'description'        => __( 'Limit results to those matching a string.', 'woocommerce' ),
535
+			'description'        => __('Limit results to those matching a string.', 'woocommerce'),
536 536
 			'type'               => 'string',
537 537
 			'sanitize_callback'  => 'sanitize_text_field',
538 538
 			'validate_callback'  => 'rest_validate_request_arg',
539 539
 		);
540 540
 		$params['after'] = array(
541
-			'description'        => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ),
541
+			'description'        => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'),
542 542
 			'type'               => 'string',
543 543
 			'format'             => 'date-time',
544 544
 			'validate_callback'  => 'rest_validate_request_arg',
545 545
 		);
546 546
 		$params['before'] = array(
547
-			'description'        => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ),
547
+			'description'        => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'),
548 548
 			'type'               => 'string',
549 549
 			'format'             => 'date-time',
550 550
 			'validate_callback'  => 'rest_validate_request_arg',
551 551
 		);
552 552
 		$params['exclude'] = array(
553
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
553
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
554 554
 			'type'              => 'array',
555 555
 			'items'             => array(
556 556
 				'type'          => 'integer',
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 			'sanitize_callback' => 'wp_parse_id_list',
560 560
 		);
561 561
 		$params['include'] = array(
562
-			'description'       => __( 'Limit result set to specific ids.', 'woocommerce' ),
562
+			'description'       => __('Limit result set to specific ids.', 'woocommerce'),
563 563
 			'type'              => 'array',
564 564
 			'items'             => array(
565 565
 				'type'          => 'integer',
@@ -568,20 +568,20 @@  discard block
 block discarded – undo
568 568
 			'sanitize_callback' => 'wp_parse_id_list',
569 569
 		);
570 570
 		$params['offset'] = array(
571
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
571
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
572 572
 			'type'               => 'integer',
573 573
 			'sanitize_callback'  => 'absint',
574 574
 			'validate_callback'  => 'rest_validate_request_arg',
575 575
 		);
576 576
 		$params['order'] = array(
577
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
577
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
578 578
 			'type'               => 'string',
579 579
 			'default'            => 'desc',
580
-			'enum'               => array( 'asc', 'desc' ),
580
+			'enum'               => array('asc', 'desc'),
581 581
 			'validate_callback'  => 'rest_validate_request_arg',
582 582
 		);
583 583
 		$params['orderby'] = array(
584
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
584
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
585 585
 			'type'               => 'string',
586 586
 			'default'            => 'date',
587 587
 			'enum'               => array(
@@ -594,9 +594,9 @@  discard block
 block discarded – undo
594 594
 			'validate_callback'  => 'rest_validate_request_arg',
595 595
 		);
596 596
 
597
-		if ( $this->hierarchical ) {
597
+		if ($this->hierarchical) {
598 598
 			$params['parent'] = array(
599
-				'description'       => __( 'Limit result set to those of particular parent IDs.', 'woocommerce' ),
599
+				'description'       => __('Limit result set to those of particular parent IDs.', 'woocommerce'),
600 600
 				'type'              => 'array',
601 601
 				'items'             => array(
602 602
 					'type'          => 'integer',
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 				'default'           => array(),
606 606
 			);
607 607
 			$params['parent_exclude'] = array(
608
-				'description'       => __( 'Limit result set to all items except those of a particular parent ID.', 'woocommerce' ),
608
+				'description'       => __('Limit result set to all items except those of a particular parent ID.', 'woocommerce'),
609 609
 				'type'              => 'array',
610 610
 				'items'             => array(
611 611
 					'type'          => 'integer',
@@ -628,6 +628,6 @@  discard block
 block discarded – undo
628 628
 		 * @param array        $query_params JSON Schema-formatted collection parameters.
629 629
 		 * @param WP_Post_Type $post_type    Post type object.
630 630
 		 */
631
-		return apply_filters( "rest_{$this->post_type}_collection_params", $params, $this->post_type );
631
+		return apply_filters("rest_{$this->post_type}_collection_params", $params, $this->post_type);
632 632
 	}
633 633
 }
Please login to merge, or discard this patch.
src/RestApi/Version4/Controllers/Customers.php 1 patch
Spacing   +269 added lines, -269 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 namespace WooCommerce\RestApi\Version4\Controllers;
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 use \WP_REST_Server;
15 15
 
@@ -35,36 +35,36 @@  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
 					'args'                => $this->get_collection_params(),
41 41
 				),
42 42
 				array(
43 43
 					'methods'             => \WP_REST_Server::CREATABLE,
44
-					'callback'            => array( $this, 'create_item' ),
45
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
44
+					'callback'            => array($this, 'create_item'),
45
+					'permission_callback' => array($this, 'create_item_permissions_check'),
46 46
 					'args'                => array_merge(
47
-						$this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ),
47
+						$this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
48 48
 						array(
49 49
 							'email' => array(
50 50
 								'required' => true,
51 51
 								'type'     => 'string',
52
-								'description' => __( 'New user email address.', 'woocommerce' ),
52
+								'description' => __('New user email address.', 'woocommerce'),
53 53
 							),
54 54
 							'username' => array(
55
-								'required' => 'no' === get_option( 'woocommerce_registration_generate_username', 'yes' ),
56
-								'description' => __( 'New user username.', 'woocommerce' ),
55
+								'required' => 'no' === get_option('woocommerce_registration_generate_username', 'yes'),
56
+								'description' => __('New user username.', 'woocommerce'),
57 57
 								'type'     => 'string',
58 58
 							),
59 59
 							'password' => array(
60
-								'required' => 'no' === get_option( 'woocommerce_registration_generate_password', 'no' ),
61
-								'description' => __( 'New user password.', 'woocommerce' ),
60
+								'required' => 'no' === get_option('woocommerce_registration_generate_password', 'no'),
61
+								'description' => __('New user password.', 'woocommerce'),
62 62
 								'type'     => 'string',
63 63
 							),
64 64
 						)
65 65
 					),
66 66
 				),
67
-				'schema' => array( $this, 'get_public_item_schema' ),
67
+				'schema' => array($this, 'get_public_item_schema'),
68 68
 			),
69 69
 			true
70 70
 		);
@@ -75,42 +75,42 @@  discard block
 block discarded – undo
75 75
 			array(
76 76
 				'args' => array(
77 77
 					'id' => array(
78
-						'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
78
+						'description' => __('Unique identifier for the resource.', 'woocommerce'),
79 79
 						'type'        => 'integer',
80 80
 					),
81 81
 				),
82 82
 				array(
83 83
 					'methods'             => \WP_REST_Server::READABLE,
84
-					'callback'            => array( $this, 'get_item' ),
85
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
84
+					'callback'            => array($this, 'get_item'),
85
+					'permission_callback' => array($this, 'get_item_permissions_check'),
86 86
 					'args'                => array(
87
-						'context' => $this->get_context_param( array( 'default' => 'view' ) ),
87
+						'context' => $this->get_context_param(array('default' => 'view')),
88 88
 					),
89 89
 				),
90 90
 				array(
91 91
 					'methods'             => \WP_REST_Server::EDITABLE,
92
-					'callback'            => array( $this, 'update_item' ),
93
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
94
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
92
+					'callback'            => array($this, 'update_item'),
93
+					'permission_callback' => array($this, 'update_item_permissions_check'),
94
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
95 95
 				),
96 96
 				array(
97 97
 					'methods'             => \WP_REST_Server::DELETABLE,
98
-					'callback'            => array( $this, 'delete_item' ),
99
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
98
+					'callback'            => array($this, 'delete_item'),
99
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
100 100
 					'args'                => array(
101 101
 						'force' => array(
102 102
 							'default'     => false,
103 103
 							'type'        => 'boolean',
104
-							'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
104
+							'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'),
105 105
 						),
106 106
 						'reassign' => array(
107 107
 							'default'     => 0,
108 108
 							'type'        => 'integer',
109
-							'description' => __( 'ID to reassign posts to.', 'woocommerce' ),
109
+							'description' => __('ID to reassign posts to.', 'woocommerce'),
110 110
 						),
111 111
 					),
112 112
 				),
113
-				'schema' => array( $this, 'get_public_item_schema' ),
113
+				'schema' => array($this, 'get_public_item_schema'),
114 114
 			),
115 115
 			true
116 116
 		);
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
 			array(
122 122
 				array(
123 123
 					'methods'             => \WP_REST_Server::EDITABLE,
124
-					'callback'            => array( $this, 'batch_items' ),
125
-					'permission_callback' => array( $this, 'batch_items_permissions_check' ),
126
-					'args'                => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ),
124
+					'callback'            => array($this, 'batch_items'),
125
+					'permission_callback' => array($this, 'batch_items_permissions_check'),
126
+					'args'                => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE),
127 127
 				),
128
-				'schema' => array( $this, 'get_public_batch_schema' ),
128
+				'schema' => array($this, 'get_public_batch_schema'),
129 129
 			),
130 130
 			true
131 131
 		);
@@ -137,9 +137,9 @@  discard block
 block discarded – undo
137 137
 	 * @param  \WP_REST_Request $request Full details about the request.
138 138
 	 * @return \WP_Error|boolean
139 139
 	 */
140
-	public function get_items_permissions_check( $request ) {
141
-		if ( ! wc_rest_check_user_permissions( 'read' ) ) {
142
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
140
+	public function get_items_permissions_check($request) {
141
+		if ( ! wc_rest_check_user_permissions('read')) {
142
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
143 143
 		}
144 144
 
145 145
 		return true;
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 * @return bool|\WP_Error
154 154
 	 */
155
-	public function create_item_permissions_check( $request ) {
156
-		if ( ! wc_rest_check_user_permissions( 'create' ) ) {
157
-			return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
155
+	public function create_item_permissions_check($request) {
156
+		if ( ! wc_rest_check_user_permissions('create')) {
157
+			return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code()));
158 158
 		}
159 159
 
160 160
 		return true;
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 	 * @param  \WP_REST_Request $request Full details about the request.
167 167
 	 * @return \WP_Error|boolean
168 168
 	 */
169
-	public function get_item_permissions_check( $request ) {
169
+	public function get_item_permissions_check($request) {
170 170
 		$id = (int) $request['id'];
171 171
 
172
-		if ( ! wc_rest_check_user_permissions( 'read', $id ) ) {
173
-			return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
172
+		if ( ! wc_rest_check_user_permissions('read', $id)) {
173
+			return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
174 174
 		}
175 175
 
176 176
 		return true;
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @return bool|\WP_Error
185 185
 	 */
186
-	public function update_item_permissions_check( $request ) {
186
+	public function update_item_permissions_check($request) {
187 187
 		$id = (int) $request['id'];
188 188
 
189
-		if ( ! wc_rest_check_user_permissions( 'edit', $id ) ) {
190
-			return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
189
+		if ( ! wc_rest_check_user_permissions('edit', $id)) {
190
+			return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
191 191
 		}
192 192
 
193 193
 		return true;
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 	 *
201 201
 	 * @return bool|\WP_Error
202 202
 	 */
203
-	public function delete_item_permissions_check( $request ) {
203
+	public function delete_item_permissions_check($request) {
204 204
 		$id = (int) $request['id'];
205 205
 
206
-		if ( ! wc_rest_check_user_permissions( 'delete', $id ) ) {
207
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
206
+		if ( ! wc_rest_check_user_permissions('delete', $id)) {
207
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code()));
208 208
 		}
209 209
 
210 210
 		return true;
@@ -217,9 +217,9 @@  discard block
 block discarded – undo
217 217
 	 *
218 218
 	 * @return bool|\WP_Error
219 219
 	 */
220
-	public function batch_items_permissions_check( $request ) {
221
-		if ( ! wc_rest_check_user_permissions( 'batch' ) ) {
222
-			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() ) );
220
+	public function batch_items_permissions_check($request) {
221
+		if ( ! wc_rest_check_user_permissions('batch')) {
222
+			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()));
223 223
 		}
224 224
 
225 225
 		return true;
@@ -233,16 +233,16 @@  discard block
 block discarded – undo
233 233
 	 * @since  3.0.0
234 234
 	 * @return array
235 235
 	 */
236
-	protected function get_formatted_item_data( $object ) {
236
+	protected function get_formatted_item_data($object) {
237 237
 		$data        = $object->get_data();
238
-		$format_date = array( 'date_created', 'date_modified' );
238
+		$format_date = array('date_created', 'date_modified');
239 239
 
240 240
 		// Format date values.
241
-		foreach ( $format_date as $key ) {
241
+		foreach ($format_date as $key) {
242 242
 			// Date created is stored UTC, date modified is stored WP local time.
243
-			$datetime              = 'date_created' === $key ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $data[ $key ]->getTimestamp() ) ) : $data[ $key ];
244
-			$data[ $key ]          = wc_rest_prepare_date_response( $datetime, false );
245
-			$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
243
+			$datetime              = 'date_created' === $key ? get_date_from_gmt(gmdate('Y-m-d H:i:s', $data[$key]->getTimestamp())) : $data[$key];
244
+			$data[$key]          = wc_rest_prepare_date_response($datetime, false);
245
+			$data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime);
246 246
 		}
247 247
 
248 248
 		return array(
@@ -270,16 +270,16 @@  discard block
 block discarded – undo
270 270
 	 * @param \WP_REST_Request $request Full details about the request.
271 271
 	 * @return \WP_Error\WP_REST_Response
272 272
 	 */
273
-	public function get_items( $request ) {
273
+	public function get_items($request) {
274 274
 		$prepared_args = array();
275 275
 		$prepared_args['exclude'] = $request['exclude'];
276 276
 		$prepared_args['include'] = $request['include'];
277 277
 		$prepared_args['order']   = $request['order'];
278 278
 		$prepared_args['number']  = $request['per_page'];
279
-		if ( ! empty( $request['offset'] ) ) {
279
+		if ( ! empty($request['offset'])) {
280 280
 			$prepared_args['offset'] = $request['offset'];
281 281
 		} else {
282
-			$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
282
+			$prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number'];
283 283
 		}
284 284
 		$orderby_possibles = array(
285 285
 			'id'              => 'ID',
@@ -287,21 +287,21 @@  discard block
 block discarded – undo
287 287
 			'name'            => 'display_name',
288 288
 			'registered_date' => 'registered',
289 289
 		);
290
-		$prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ];
290
+		$prepared_args['orderby'] = $orderby_possibles[$request['orderby']];
291 291
 		$prepared_args['search']  = $request['search'];
292 292
 
293
-		if ( '' !== $prepared_args['search'] ) {
293
+		if ('' !== $prepared_args['search']) {
294 294
 			$prepared_args['search'] = '*' . $prepared_args['search'] . '*';
295 295
 		}
296 296
 
297 297
 		// Filter by email.
298
-		if ( ! empty( $request['email'] ) ) {
298
+		if ( ! empty($request['email'])) {
299 299
 			$prepared_args['search']         = $request['email'];
300
-			$prepared_args['search_columns'] = array( 'user_email' );
300
+			$prepared_args['search_columns'] = array('user_email');
301 301
 		}
302 302
 
303 303
 		// Filter by role.
304
-		if ( 'all' !== $request['role'] ) {
304
+		if ('all' !== $request['role']) {
305 305
 			$prepared_args['role'] = $request['role'];
306 306
 		}
307 307
 
@@ -313,49 +313,49 @@  discard block
 block discarded – undo
313 313
 		 * @param array           $prepared_args Array of arguments for \ WP_User_Query.
314 314
 		 * @param \WP_REST_Request $request       The current request.
315 315
 		 */
316
-		$prepared_args = apply_filters( 'woocommerce_rest_customer_query', $prepared_args, $request );
316
+		$prepared_args = apply_filters('woocommerce_rest_customer_query', $prepared_args, $request);
317 317
 
318
-		$query = new \ WP_User_Query( $prepared_args );
318
+		$query = new \ WP_User_Query($prepared_args);
319 319
 
320 320
 		$users = array();
321
-		foreach ( $query->results as $user ) {
322
-			$data = $this->prepare_item_for_response( $user, $request );
323
-			$users[] = $this->prepare_response_for_collection( $data );
321
+		foreach ($query->results as $user) {
322
+			$data = $this->prepare_item_for_response($user, $request);
323
+			$users[] = $this->prepare_response_for_collection($data);
324 324
 		}
325 325
 
326
-		$response = rest_ensure_response( $users );
326
+		$response = rest_ensure_response($users);
327 327
 
328 328
 		// Store pagination values for headers then unset for count query.
329 329
 		$per_page = (int) $prepared_args['number'];
330
-		$page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 );
330
+		$page = ceil((((int) $prepared_args['offset']) / $per_page) + 1);
331 331
 
332 332
 		$prepared_args['fields'] = 'ID';
333 333
 
334 334
 		$total_users = $query->get_total();
335
-		if ( $total_users < 1 ) {
335
+		if ($total_users < 1) {
336 336
 			// Out-of-bounds, run the query again without LIMIT for total count.
337
-			unset( $prepared_args['number'] );
338
-			unset( $prepared_args['offset'] );
339
-			$count_query = new \ WP_User_Query( $prepared_args );
337
+			unset($prepared_args['number']);
338
+			unset($prepared_args['offset']);
339
+			$count_query = new \ WP_User_Query($prepared_args);
340 340
 			$total_users = $count_query->get_total();
341 341
 		}
342
-		$response->header( 'X-WP-Total', (int) $total_users );
343
-		$max_pages = ceil( $total_users / $per_page );
344
-		$response->header( 'X-WP-TotalPages', (int) $max_pages );
342
+		$response->header('X-WP-Total', (int) $total_users);
343
+		$max_pages = ceil($total_users / $per_page);
344
+		$response->header('X-WP-TotalPages', (int) $max_pages);
345 345
 
346
-		$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );
347
-		if ( $page > 1 ) {
346
+		$base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
347
+		if ($page > 1) {
348 348
 			$prev_page = $page - 1;
349
-			if ( $prev_page > $max_pages ) {
349
+			if ($prev_page > $max_pages) {
350 350
 				$prev_page = $max_pages;
351 351
 			}
352
-			$prev_link = add_query_arg( 'page', $prev_page, $base );
353
-			$response->link_header( 'prev', $prev_link );
352
+			$prev_link = add_query_arg('page', $prev_page, $base);
353
+			$response->link_header('prev', $prev_link);
354 354
 		}
355
-		if ( $max_pages > $page ) {
355
+		if ($max_pages > $page) {
356 356
 			$next_page = $page + 1;
357
-			$next_link = add_query_arg( 'page', $next_page, $base );
358
-			$response->link_header( 'next', $next_link );
357
+			$next_link = add_query_arg('page', $next_page, $base);
358
+			$response->link_header('next', $next_link);
359 359
 		}
360 360
 
361 361
 		return $response;
@@ -368,32 +368,32 @@  discard block
 block discarded – undo
368 368
 	 * @param \WP_REST_Request $request Full details about the request.
369 369
 	 * @return \WP_Error\WP_REST_Response
370 370
 	 */
371
-	public function create_item( $request ) {
371
+	public function create_item($request) {
372 372
 		try {
373
-			if ( ! empty( $request['id'] ) ) {
374
-				throw new \WC_REST_Exception( 'woocommerce_rest_customer_exists', __( 'Cannot create existing resource.', 'woocommerce' ), 400 );
373
+			if ( ! empty($request['id'])) {
374
+				throw new \WC_REST_Exception('woocommerce_rest_customer_exists', __('Cannot create existing resource.', 'woocommerce'), 400);
375 375
 			}
376 376
 
377 377
 			// Sets the username.
378
-			$request['username'] = ! empty( $request['username'] ) ? $request['username'] : '';
378
+			$request['username'] = ! empty($request['username']) ? $request['username'] : '';
379 379
 
380 380
 			// Sets the password.
381
-			$request['password'] = ! empty( $request['password'] ) ? $request['password'] : '';
381
+			$request['password'] = ! empty($request['password']) ? $request['password'] : '';
382 382
 
383 383
 			// Create customer.
384 384
 			$customer = new \WC_Customer();
385
-			$customer->set_username( $request['username'] );
386
-			$customer->set_password( $request['password'] );
387
-			$customer->set_email( $request['email'] );
388
-			$this->update_customer_meta_fields( $customer, $request );
385
+			$customer->set_username($request['username']);
386
+			$customer->set_password($request['password']);
387
+			$customer->set_email($request['email']);
388
+			$this->update_customer_meta_fields($customer, $request);
389 389
 			$customer->save();
390 390
 
391
-			if ( ! $customer->get_id() ) {
392
-				throw new \WC_REST_Exception( 'woocommerce_rest_cannot_create', __( 'This resource cannot be created.', 'woocommerce' ), 400 );
391
+			if ( ! $customer->get_id()) {
392
+				throw new \WC_REST_Exception('woocommerce_rest_cannot_create', __('This resource cannot be created.', 'woocommerce'), 400);
393 393
 			}
394 394
 
395
-			$user_data = get_userdata( $customer->get_id() );
396
-			$this->update_additional_fields_for_object( $user_data, $request );
395
+			$user_data = get_userdata($customer->get_id());
396
+			$this->update_additional_fields_for_object($user_data, $request);
397 397
 
398 398
 			/**
399 399
 			 * Fires after a customer is created or updated via the REST API.
@@ -402,17 +402,17 @@  discard block
 block discarded – undo
402 402
 			 * @param \WP_REST_Request $request   Request object.
403 403
 			 * @param boolean         $creating  True when creating customer, false when updating customer.
404 404
 			 */
405
-			do_action( 'woocommerce_rest_insert_customer', $user_data, $request, true );
405
+			do_action('woocommerce_rest_insert_customer', $user_data, $request, true);
406 406
 
407
-			$request->set_param( 'context', 'edit' );
408
-			$response = $this->prepare_item_for_response( $user_data, $request );
409
-			$response = rest_ensure_response( $response );
410
-			$response->set_status( 201 );
411
-			$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $customer->get_id() ) ) );
407
+			$request->set_param('context', 'edit');
408
+			$response = $this->prepare_item_for_response($user_data, $request);
409
+			$response = rest_ensure_response($response);
410
+			$response->set_status(201);
411
+			$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $customer->get_id())));
412 412
 
413 413
 			return $response;
414
-		} catch ( \Exception $e ) {
415
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
414
+		} catch (\Exception $e) {
415
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
416 416
 		}
417 417
 	}
418 418
 
@@ -422,16 +422,16 @@  discard block
 block discarded – undo
422 422
 	 * @param \WP_REST_Request $request Full details about the request.
423 423
 	 * @return \WP_Error\WP_REST_Response
424 424
 	 */
425
-	public function get_item( $request ) {
425
+	public function get_item($request) {
426 426
 		$id        = (int) $request['id'];
427
-		$user_data = get_userdata( $id );
427
+		$user_data = get_userdata($id);
428 428
 
429
-		if ( empty( $id ) || empty( $user_data->ID ) ) {
430
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) );
429
+		if (empty($id) || empty($user_data->ID)) {
430
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404));
431 431
 		}
432 432
 
433
-		$customer = $this->prepare_item_for_response( $user_data, $request );
434
-		$response = rest_ensure_response( $customer );
433
+		$customer = $this->prepare_item_for_response($user_data, $request);
434
+		$response = rest_ensure_response($customer);
435 435
 
436 436
 		return $response;
437 437
 	}
@@ -444,41 +444,41 @@  discard block
 block discarded – undo
444 444
 	 * @param \WP_REST_Request $request Full details about the request.
445 445
 	 * @return \WP_Error\WP_REST_Response
446 446
 	 */
447
-	public function update_item( $request ) {
447
+	public function update_item($request) {
448 448
 		try {
449 449
 			$id       = (int) $request['id'];
450
-			$customer = new \WC_Customer( $id );
450
+			$customer = new \WC_Customer($id);
451 451
 
452
-			if ( ! $customer->get_id() ) {
453
-				throw new \WC_REST_Exception( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), 400 );
452
+			if ( ! $customer->get_id()) {
453
+				throw new \WC_REST_Exception('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), 400);
454 454
 			}
455 455
 
456
-			if ( ! empty( $request['email'] ) && email_exists( $request['email'] ) && $request['email'] !== $customer->get_email() ) {
457
-				throw new \WC_REST_Exception( 'woocommerce_rest_customer_invalid_email', __( 'Email address is invalid.', 'woocommerce' ), 400 );
456
+			if ( ! empty($request['email']) && email_exists($request['email']) && $request['email'] !== $customer->get_email()) {
457
+				throw new \WC_REST_Exception('woocommerce_rest_customer_invalid_email', __('Email address is invalid.', 'woocommerce'), 400);
458 458
 			}
459 459
 
460
-			if ( ! empty( $request['username'] ) && $request['username'] !== $customer->get_username() ) {
461
-				throw new \WC_REST_Exception( 'woocommerce_rest_customer_invalid_argument', __( "Username isn't editable.", 'woocommerce' ), 400 );
460
+			if ( ! empty($request['username']) && $request['username'] !== $customer->get_username()) {
461
+				throw new \WC_REST_Exception('woocommerce_rest_customer_invalid_argument', __("Username isn't editable.", 'woocommerce'), 400);
462 462
 			}
463 463
 
464 464
 			// Customer email.
465
-			if ( isset( $request['email'] ) ) {
466
-				$customer->set_email( sanitize_email( $request['email'] ) );
465
+			if (isset($request['email'])) {
466
+				$customer->set_email(sanitize_email($request['email']));
467 467
 			}
468 468
 
469 469
 			// Customer password.
470
-			if ( isset( $request['password'] ) ) {
471
-				$customer->set_password( $request['password'] );
470
+			if (isset($request['password'])) {
471
+				$customer->set_password($request['password']);
472 472
 			}
473 473
 
474
-			$this->update_customer_meta_fields( $customer, $request );
474
+			$this->update_customer_meta_fields($customer, $request);
475 475
 			$customer->save();
476 476
 
477
-			$user_data = get_userdata( $customer->get_id() );
478
-			$this->update_additional_fields_for_object( $user_data, $request );
477
+			$user_data = get_userdata($customer->get_id());
478
+			$this->update_additional_fields_for_object($user_data, $request);
479 479
 
480
-			if ( ! is_user_member_of_blog( $user_data->ID ) ) {
481
-				$user_data->add_role( 'customer' );
480
+			if ( ! is_user_member_of_blog($user_data->ID)) {
481
+				$user_data->add_role('customer');
482 482
 			}
483 483
 
484 484
 			/**
@@ -488,14 +488,14 @@  discard block
 block discarded – undo
488 488
 			 * @param \WP_REST_Request $request   Request object.
489 489
 			 * @param boolean         $creating  True when creating customer, false when updating customer.
490 490
 			 */
491
-			do_action( 'woocommerce_rest_insert_customer', $user_data, $request, false );
491
+			do_action('woocommerce_rest_insert_customer', $user_data, $request, false);
492 492
 
493
-			$request->set_param( 'context', 'edit' );
494
-			$response = $this->prepare_item_for_response( $user_data, $request );
495
-			$response = rest_ensure_response( $response );
493
+			$request->set_param('context', 'edit');
494
+			$response = $this->prepare_item_for_response($user_data, $request);
495
+			$response = rest_ensure_response($response);
496 496
 			return $response;
497
-		} catch ( Exception $e ) {
498
-			return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
497
+		} catch (Exception $e) {
498
+			return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
499 499
 		}
500 500
 	}
501 501
 
@@ -505,43 +505,43 @@  discard block
 block discarded – undo
505 505
 	 * @param \WP_REST_Request $request Full details about the request.
506 506
 	 * @return \WP_Error\WP_REST_Response
507 507
 	 */
508
-	public function delete_item( $request ) {
508
+	public function delete_item($request) {
509 509
 		$id       = (int) $request['id'];
510
-		$reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null;
511
-		$force    = isset( $request['force'] ) ? (bool) $request['force'] : false;
510
+		$reassign = isset($request['reassign']) ? absint($request['reassign']) : null;
511
+		$force    = isset($request['force']) ? (bool) $request['force'] : false;
512 512
 
513 513
 		// We don't support trashing for this type, error out.
514
-		if ( ! $force ) {
515
-			return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Customers do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) );
514
+		if ( ! $force) {
515
+			return new \WP_Error('woocommerce_rest_trash_not_supported', __('Customers do not support trashing.', 'woocommerce'), array('status' => 501));
516 516
 		}
517 517
 
518
-		$user_data = get_userdata( $id );
519
-		if ( ! $user_data ) {
520
-			return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) );
518
+		$user_data = get_userdata($id);
519
+		if ( ! $user_data) {
520
+			return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400));
521 521
 		}
522 522
 
523
-		if ( ! empty( $reassign ) ) {
524
-			if ( $reassign === $id || ! get_userdata( $reassign ) ) {
525
-				return new \WP_Error( 'woocommerce_rest_customer_invalid_reassign', __( 'Invalid resource id for reassignment.', 'woocommerce' ), array( 'status' => 400 ) );
523
+		if ( ! empty($reassign)) {
524
+			if ($reassign === $id || ! get_userdata($reassign)) {
525
+				return new \WP_Error('woocommerce_rest_customer_invalid_reassign', __('Invalid resource id for reassignment.', 'woocommerce'), array('status' => 400));
526 526
 			}
527 527
 		}
528 528
 
529
-		$request->set_param( 'context', 'edit' );
530
-		$response = $this->prepare_item_for_response( $user_data, $request );
529
+		$request->set_param('context', 'edit');
530
+		$response = $this->prepare_item_for_response($user_data, $request);
531 531
 
532 532
 		/** Include admin customer functions to get access to wp_delete_user() */
533 533
 		require_once ABSPATH . 'wp-admin/includes/user.php';
534 534
 
535
-		$customer = new \WC_Customer( $id );
535
+		$customer = new \WC_Customer($id);
536 536
 
537
-		if ( ! is_null( $reassign ) ) {
538
-			$result = $customer->delete_and_reassign( $reassign );
537
+		if ( ! is_null($reassign)) {
538
+			$result = $customer->delete_and_reassign($reassign);
539 539
 		} else {
540 540
 			$result = $customer->delete();
541 541
 		}
542 542
 
543
-		if ( ! $result ) {
544
-			return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) );
543
+		if ( ! $result) {
544
+			return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500));
545 545
 		}
546 546
 
547 547
 		/**
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 		 * @param \WP_REST_Response $response  The response returned from the API.
552 552
 		 * @param \WP_REST_Request  $request   The request sent to the API.
553 553
 		 */
554
-		do_action( 'woocommerce_rest_delete_customer', $user_data, $response, $request );
554
+		do_action('woocommerce_rest_delete_customer', $user_data, $response, $request);
555 555
 
556 556
 		return $response;
557 557
 	}
@@ -563,14 +563,14 @@  discard block
 block discarded – undo
563 563
 	 * @param  \WP_REST_Request $request   Request object.
564 564
 	 * @return \WP_REST_Response $response  Response data.
565 565
 	 */
566
-	public function prepare_item_for_response( $user_data, $request ) {
567
-		$customer = new \WC_Customer( $user_data->ID );
568
-		$data     = $this->get_formatted_item_data( $customer );
569
-		$context  = ! empty( $request['context'] ) ? $request['context'] : 'view';
570
-		$data     = $this->add_additional_fields_to_object( $data, $request );
571
-		$data     = $this->filter_response_by_context( $data, $context );
572
-		$response = rest_ensure_response( $data );
573
-		$response->add_links( $this->prepare_links( $user_data ) );
566
+	public function prepare_item_for_response($user_data, $request) {
567
+		$customer = new \WC_Customer($user_data->ID);
568
+		$data     = $this->get_formatted_item_data($customer);
569
+		$context  = ! empty($request['context']) ? $request['context'] : 'view';
570
+		$data     = $this->add_additional_fields_to_object($data, $request);
571
+		$data     = $this->filter_response_by_context($data, $context);
572
+		$response = rest_ensure_response($data);
573
+		$response->add_links($this->prepare_links($user_data));
574 574
 
575 575
 		/**
576 576
 		 * Filter customer data returned from the REST API.
@@ -579,7 +579,7 @@  discard block
 block discarded – undo
579 579
 		 * @param WP_User          $user_data  User object used to create response.
580 580
 		 * @param \WP_REST_Request  $request    Request object.
581 581
 		 */
582
-		return apply_filters( 'woocommerce_rest_prepare_customer', $response, $user_data, $request );
582
+		return apply_filters('woocommerce_rest_prepare_customer', $response, $user_data, $request);
583 583
 	}
584 584
 
585 585
 	/**
@@ -588,42 +588,42 @@  discard block
 block discarded – undo
588 588
 	 * @param WC_Customer     $customer Customer being updated.
589 589
 	 * @param \WP_REST_Request $request Request params.
590 590
 	 */
591
-	protected function update_customer_meta_fields( $customer, $request ) {
591
+	protected function update_customer_meta_fields($customer, $request) {
592 592
 		$schema = $this->get_item_schema();
593 593
 
594 594
 		// Customer first name.
595
-		if ( isset( $request['first_name'] ) ) {
596
-			$customer->set_first_name( wc_clean( $request['first_name'] ) );
595
+		if (isset($request['first_name'])) {
596
+			$customer->set_first_name(wc_clean($request['first_name']));
597 597
 		}
598 598
 
599 599
 		// Customer last name.
600
-		if ( isset( $request['last_name'] ) ) {
601
-			$customer->set_last_name( wc_clean( $request['last_name'] ) );
600
+		if (isset($request['last_name'])) {
601
+			$customer->set_last_name(wc_clean($request['last_name']));
602 602
 		}
603 603
 
604 604
 		// Customer billing address.
605
-		if ( isset( $request['billing'] ) ) {
606
-			foreach ( array_keys( $schema['properties']['billing']['properties'] ) as $field ) {
607
-				if ( isset( $request['billing'][ $field ] ) && is_callable( array( $customer, "set_billing_{$field}" ) ) ) {
608
-					$customer->{"set_billing_{$field}"}( $request['billing'][ $field ] );
605
+		if (isset($request['billing'])) {
606
+			foreach (array_keys($schema['properties']['billing']['properties']) as $field) {
607
+				if (isset($request['billing'][$field]) && is_callable(array($customer, "set_billing_{$field}"))) {
608
+					$customer->{"set_billing_{$field}"}($request['billing'][$field]);
609 609
 				}
610 610
 			}
611 611
 		}
612 612
 
613 613
 		// Customer shipping address.
614
-		if ( isset( $request['shipping'] ) ) {
615
-			foreach ( array_keys( $schema['properties']['shipping']['properties'] ) as $field ) {
616
-				if ( isset( $request['shipping'][ $field ] ) && is_callable( array( $customer, "set_shipping_{$field}" ) ) ) {
617
-					$customer->{"set_shipping_{$field}"}( $request['shipping'][ $field ] );
614
+		if (isset($request['shipping'])) {
615
+			foreach (array_keys($schema['properties']['shipping']['properties']) as $field) {
616
+				if (isset($request['shipping'][$field]) && is_callable(array($customer, "set_shipping_{$field}"))) {
617
+					$customer->{"set_shipping_{$field}"}($request['shipping'][$field]);
618 618
 				}
619 619
 			}
620 620
 		}
621 621
 
622 622
 		// Meta data.
623
-		if ( isset( $request['meta_data'] ) ) {
624
-			if ( is_array( $request['meta_data'] ) ) {
625
-				foreach ( $request['meta_data'] as $meta ) {
626
-					$customer->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
623
+		if (isset($request['meta_data'])) {
624
+			if (is_array($request['meta_data'])) {
625
+				foreach ($request['meta_data'] as $meta) {
626
+					$customer->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
627 627
 				}
628 628
 			}
629 629
 		}
@@ -635,13 +635,13 @@  discard block
 block discarded – undo
635 635
 	 * @param WP_User $customer Customer object.
636 636
 	 * @return array Links for the given customer.
637 637
 	 */
638
-	protected function prepare_links( $customer ) {
638
+	protected function prepare_links($customer) {
639 639
 		$links = array(
640 640
 			'self' => array(
641
-				'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $customer->ID ) ),
641
+				'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $customer->ID)),
642 642
 			),
643 643
 			'collection' => array(
644
-				'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
644
+				'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
645 645
 			),
646 646
 		);
647 647
 
@@ -660,225 +660,225 @@  discard block
 block discarded – undo
660 660
 			'type'       => 'object',
661 661
 			'properties' => array(
662 662
 				'id'                 => array(
663
-					'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
663
+					'description' => __('Unique identifier for the resource.', 'woocommerce'),
664 664
 					'type'        => 'integer',
665
-					'context'     => array( 'view', 'edit' ),
665
+					'context'     => array('view', 'edit'),
666 666
 					'readonly'    => true,
667 667
 				),
668 668
 				'date_created'       => array(
669
-					'description' => __( "The date the customer was created, in the site's timezone.", 'woocommerce' ),
669
+					'description' => __("The date the customer was created, in the site's timezone.", 'woocommerce'),
670 670
 					'type'        => 'date-time',
671
-					'context'     => array( 'view', 'edit' ),
671
+					'context'     => array('view', 'edit'),
672 672
 					'readonly'    => true,
673 673
 				),
674 674
 				'date_created_gmt'   => array(
675
-					'description' => __( 'The date the customer was created, as GMT.', 'woocommerce' ),
675
+					'description' => __('The date the customer was created, as GMT.', 'woocommerce'),
676 676
 					'type'        => 'date-time',
677
-					'context'     => array( 'view', 'edit' ),
677
+					'context'     => array('view', 'edit'),
678 678
 					'readonly'    => true,
679 679
 				),
680 680
 				'date_modified'      => array(
681
-					'description' => __( "The date the customer was last modified, in the site's timezone.", 'woocommerce' ),
681
+					'description' => __("The date the customer was last modified, in the site's timezone.", 'woocommerce'),
682 682
 					'type'        => 'date-time',
683
-					'context'     => array( 'view', 'edit' ),
683
+					'context'     => array('view', 'edit'),
684 684
 					'readonly'    => true,
685 685
 				),
686 686
 				'date_modified_gmt'  => array(
687
-					'description' => __( 'The date the customer was last modified, as GMT.', 'woocommerce' ),
687
+					'description' => __('The date the customer was last modified, as GMT.', 'woocommerce'),
688 688
 					'type'        => 'date-time',
689
-					'context'     => array( 'view', 'edit' ),
689
+					'context'     => array('view', 'edit'),
690 690
 					'readonly'    => true,
691 691
 				),
692 692
 				'email'              => array(
693
-					'description' => __( 'The email address for the customer.', 'woocommerce' ),
693
+					'description' => __('The email address for the customer.', 'woocommerce'),
694 694
 					'type'        => 'string',
695 695
 					'format'      => 'email',
696
-					'context'     => array( 'view', 'edit' ),
696
+					'context'     => array('view', 'edit'),
697 697
 				),
698 698
 				'first_name'         => array(
699
-					'description' => __( 'Customer first name.', 'woocommerce' ),
699
+					'description' => __('Customer first name.', 'woocommerce'),
700 700
 					'type'        => 'string',
701
-					'context'     => array( 'view', 'edit' ),
701
+					'context'     => array('view', 'edit'),
702 702
 					'arg_options' => array(
703 703
 						'sanitize_callback' => 'sanitize_text_field',
704 704
 					),
705 705
 				),
706 706
 				'last_name'          => array(
707
-					'description' => __( 'Customer last name.', 'woocommerce' ),
707
+					'description' => __('Customer last name.', 'woocommerce'),
708 708
 					'type'        => 'string',
709
-					'context'     => array( 'view', 'edit' ),
709
+					'context'     => array('view', 'edit'),
710 710
 					'arg_options' => array(
711 711
 						'sanitize_callback' => 'sanitize_text_field',
712 712
 					),
713 713
 				),
714 714
 				'role'               => array(
715
-					'description' => __( 'Customer role.', 'woocommerce' ),
715
+					'description' => __('Customer role.', 'woocommerce'),
716 716
 					'type'        => 'string',
717
-					'context'     => array( 'view', 'edit' ),
717
+					'context'     => array('view', 'edit'),
718 718
 					'readonly'    => true,
719 719
 				),
720 720
 				'username'           => array(
721
-					'description' => __( 'Customer login name.', 'woocommerce' ),
721
+					'description' => __('Customer login name.', 'woocommerce'),
722 722
 					'type'        => 'string',
723
-					'context'     => array( 'view', 'edit' ),
723
+					'context'     => array('view', 'edit'),
724 724
 					'arg_options' => array(
725 725
 						'sanitize_callback' => 'sanitize_user',
726 726
 					),
727 727
 				),
728 728
 				'password'           => array(
729
-					'description' => __( 'Customer password.', 'woocommerce' ),
729
+					'description' => __('Customer password.', 'woocommerce'),
730 730
 					'type'        => 'string',
731
-					'context'     => array( 'edit' ),
731
+					'context'     => array('edit'),
732 732
 				),
733 733
 				'billing'            => array(
734
-					'description' => __( 'List of billing address data.', 'woocommerce' ),
734
+					'description' => __('List of billing address data.', 'woocommerce'),
735 735
 					'type'        => 'object',
736
-					'context'     => array( 'view', 'edit' ),
736
+					'context'     => array('view', 'edit'),
737 737
 					'properties'  => array(
738 738
 						'first_name' => array(
739
-							'description' => __( 'First name.', 'woocommerce' ),
739
+							'description' => __('First name.', 'woocommerce'),
740 740
 							'type'        => 'string',
741
-							'context'     => array( 'view', 'edit' ),
741
+							'context'     => array('view', 'edit'),
742 742
 						),
743 743
 						'last_name'  => array(
744
-							'description' => __( 'Last name.', 'woocommerce' ),
744
+							'description' => __('Last name.', 'woocommerce'),
745 745
 							'type'        => 'string',
746
-							'context'     => array( 'view', 'edit' ),
746
+							'context'     => array('view', 'edit'),
747 747
 						),
748 748
 						'company'    => array(
749
-							'description' => __( 'Company name.', 'woocommerce' ),
749
+							'description' => __('Company name.', 'woocommerce'),
750 750
 							'type'        => 'string',
751
-							'context'     => array( 'view', 'edit' ),
751
+							'context'     => array('view', 'edit'),
752 752
 						),
753 753
 						'address_1'  => array(
754
-							'description' => __( 'Address line 1', 'woocommerce' ),
754
+							'description' => __('Address line 1', 'woocommerce'),
755 755
 							'type'        => 'string',
756
-							'context'     => array( 'view', 'edit' ),
756
+							'context'     => array('view', 'edit'),
757 757
 						),
758 758
 						'address_2'  => array(
759
-							'description' => __( 'Address line 2', 'woocommerce' ),
759
+							'description' => __('Address line 2', 'woocommerce'),
760 760
 							'type'        => 'string',
761
-							'context'     => array( 'view', 'edit' ),
761
+							'context'     => array('view', 'edit'),
762 762
 						),
763 763
 						'city'       => array(
764
-							'description' => __( 'City name.', 'woocommerce' ),
764
+							'description' => __('City name.', 'woocommerce'),
765 765
 							'type'        => 'string',
766
-							'context'     => array( 'view', 'edit' ),
766
+							'context'     => array('view', 'edit'),
767 767
 						),
768 768
 						'state'      => array(
769
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
769
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
770 770
 							'type'        => 'string',
771
-							'context'     => array( 'view', 'edit' ),
771
+							'context'     => array('view', 'edit'),
772 772
 						),
773 773
 						'postcode'   => array(
774
-							'description' => __( 'Postal code.', 'woocommerce' ),
774
+							'description' => __('Postal code.', 'woocommerce'),
775 775
 							'type'        => 'string',
776
-							'context'     => array( 'view', 'edit' ),
776
+							'context'     => array('view', 'edit'),
777 777
 						),
778 778
 						'country'    => array(
779
-							'description' => __( 'ISO code of the country.', 'woocommerce' ),
779
+							'description' => __('ISO code of the country.', 'woocommerce'),
780 780
 							'type'        => 'string',
781
-							'context'     => array( 'view', 'edit' ),
781
+							'context'     => array('view', 'edit'),
782 782
 						),
783 783
 						'email'      => array(
784
-							'description' => __( 'Email address.', 'woocommerce' ),
784
+							'description' => __('Email address.', 'woocommerce'),
785 785
 							'type'        => 'string',
786 786
 							'format'      => 'email',
787
-							'context'     => array( 'view', 'edit' ),
787
+							'context'     => array('view', 'edit'),
788 788
 						),
789 789
 						'phone'      => array(
790
-							'description' => __( 'Phone number.', 'woocommerce' ),
790
+							'description' => __('Phone number.', 'woocommerce'),
791 791
 							'type'        => 'string',
792
-							'context'     => array( 'view', 'edit' ),
792
+							'context'     => array('view', 'edit'),
793 793
 						),
794 794
 					),
795 795
 				),
796 796
 				'shipping'           => array(
797
-					'description' => __( 'List of shipping address data.', 'woocommerce' ),
797
+					'description' => __('List of shipping address data.', 'woocommerce'),
798 798
 					'type'        => 'object',
799
-					'context'     => array( 'view', 'edit' ),
799
+					'context'     => array('view', 'edit'),
800 800
 					'properties'  => array(
801 801
 						'first_name' => array(
802
-							'description' => __( 'First name.', 'woocommerce' ),
802
+							'description' => __('First name.', 'woocommerce'),
803 803
 							'type'        => 'string',
804
-							'context'     => array( 'view', 'edit' ),
804
+							'context'     => array('view', 'edit'),
805 805
 						),
806 806
 						'last_name'  => array(
807
-							'description' => __( 'Last name.', 'woocommerce' ),
807
+							'description' => __('Last name.', 'woocommerce'),
808 808
 							'type'        => 'string',
809
-							'context'     => array( 'view', 'edit' ),
809
+							'context'     => array('view', 'edit'),
810 810
 						),
811 811
 						'company'    => array(
812
-							'description' => __( 'Company name.', 'woocommerce' ),
812
+							'description' => __('Company name.', 'woocommerce'),
813 813
 							'type'        => 'string',
814
-							'context'     => array( 'view', 'edit' ),
814
+							'context'     => array('view', 'edit'),
815 815
 						),
816 816
 						'address_1'  => array(
817
-							'description' => __( 'Address line 1', 'woocommerce' ),
817
+							'description' => __('Address line 1', 'woocommerce'),
818 818
 							'type'        => 'string',
819
-							'context'     => array( 'view', 'edit' ),
819
+							'context'     => array('view', 'edit'),
820 820
 						),
821 821
 						'address_2'  => array(
822
-							'description' => __( 'Address line 2', 'woocommerce' ),
822
+							'description' => __('Address line 2', 'woocommerce'),
823 823
 							'type'        => 'string',
824
-							'context'     => array( 'view', 'edit' ),
824
+							'context'     => array('view', 'edit'),
825 825
 						),
826 826
 						'city'       => array(
827
-							'description' => __( 'City name.', 'woocommerce' ),
827
+							'description' => __('City name.', 'woocommerce'),
828 828
 							'type'        => 'string',
829
-							'context'     => array( 'view', 'edit' ),
829
+							'context'     => array('view', 'edit'),
830 830
 						),
831 831
 						'state'      => array(
832
-							'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ),
832
+							'description' => __('ISO code or name of the state, province or district.', 'woocommerce'),
833 833
 							'type'        => 'string',
834
-							'context'     => array( 'view', 'edit' ),
834
+							'context'     => array('view', 'edit'),
835 835
 						),
836 836
 						'postcode'   => array(
837
-							'description' => __( 'Postal code.', 'woocommerce' ),
837
+							'description' => __('Postal code.', 'woocommerce'),
838 838
 							'type'        => 'string',
839
-							'context'     => array( 'view', 'edit' ),
839
+							'context'     => array('view', 'edit'),
840 840
 						),
841 841
 						'country'    => array(
842
-							'description' => __( 'ISO code of the country.', 'woocommerce' ),
842
+							'description' => __('ISO code of the country.', 'woocommerce'),
843 843
 							'type'        => 'string',
844
-							'context'     => array( 'view', 'edit' ),
844
+							'context'     => array('view', 'edit'),
845 845
 						),
846 846
 					),
847 847
 				),
848 848
 				'is_paying_customer' => array(
849
-					'description' => __( 'Is the customer a paying customer?', 'woocommerce' ),
849
+					'description' => __('Is the customer a paying customer?', 'woocommerce'),
850 850
 					'type'        => 'bool',
851
-					'context'     => array( 'view', 'edit' ),
851
+					'context'     => array('view', 'edit'),
852 852
 					'readonly'    => true,
853 853
 				),
854 854
 				'avatar_url'         => array(
855
-					'description' => __( 'Avatar URL.', 'woocommerce' ),
855
+					'description' => __('Avatar URL.', 'woocommerce'),
856 856
 					'type'        => 'string',
857
-					'context'     => array( 'view', 'edit' ),
857
+					'context'     => array('view', 'edit'),
858 858
 					'readonly'    => true,
859 859
 				),
860 860
 				'meta_data'          => array(
861
-					'description' => __( 'Meta data.', 'woocommerce' ),
861
+					'description' => __('Meta data.', 'woocommerce'),
862 862
 					'type'        => 'array',
863
-					'context'     => array( 'view', 'edit' ),
863
+					'context'     => array('view', 'edit'),
864 864
 					'items'       => array(
865 865
 						'type'       => 'object',
866 866
 						'properties' => array(
867 867
 							'id'    => array(
868
-								'description' => __( 'Meta ID.', 'woocommerce' ),
868
+								'description' => __('Meta ID.', 'woocommerce'),
869 869
 								'type'        => 'integer',
870
-								'context'     => array( 'view', 'edit' ),
870
+								'context'     => array('view', 'edit'),
871 871
 								'readonly'    => true,
872 872
 							),
873 873
 							'key'   => array(
874
-								'description' => __( 'Meta key.', 'woocommerce' ),
874
+								'description' => __('Meta key.', 'woocommerce'),
875 875
 								'type'        => 'string',
876
-								'context'     => array( 'view', 'edit' ),
876
+								'context'     => array('view', 'edit'),
877 877
 							),
878 878
 							'value' => array(
879
-								'description' => __( 'Meta value.', 'woocommerce' ),
879
+								'description' => __('Meta value.', 'woocommerce'),
880 880
 								'type'        => 'mixed',
881
-								'context'     => array( 'view', 'edit' ),
881
+								'context'     => array('view', 'edit'),
882 882
 							),
883 883
 						),
884 884
 					),
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 			),
887 887
 		);
888 888
 
889
-		return $this->add_additional_fields_schema( $schema );
889
+		return $this->add_additional_fields_schema($schema);
890 890
 	}
891 891
 
892 892
 	/**
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 	protected function get_role_names() {
898 898
 		global $wp_roles;
899 899
 
900
-		return array_keys( $wp_roles->role_names );
900
+		return array_keys($wp_roles->role_names);
901 901
 	}
902 902
 
903 903
 	/**
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
 		$params['context']['default'] = 'view';
912 912
 
913 913
 		$params['exclude'] = array(
914
-			'description'       => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ),
914
+			'description'       => __('Ensure result set excludes specific IDs.', 'woocommerce'),
915 915
 			'type'              => 'array',
916 916
 			'items'             => array(
917 917
 				'type'          => 'integer',
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
 			'sanitize_callback' => 'wp_parse_id_list',
921 921
 		);
922 922
 		$params['include'] = array(
923
-			'description'       => __( 'Limit result set to specific IDs.', 'woocommerce' ),
923
+			'description'       => __('Limit result set to specific IDs.', 'woocommerce'),
924 924
 			'type'              => 'array',
925 925
 			'items'             => array(
926 926
 				'type'          => 'integer',
@@ -929,22 +929,22 @@  discard block
 block discarded – undo
929 929
 			'sanitize_callback' => 'wp_parse_id_list',
930 930
 		);
931 931
 		$params['offset'] = array(
932
-			'description'        => __( 'Offset the result set by a specific number of items.', 'woocommerce' ),
932
+			'description'        => __('Offset the result set by a specific number of items.', 'woocommerce'),
933 933
 			'type'               => 'integer',
934 934
 			'sanitize_callback'  => 'absint',
935 935
 			'validate_callback'  => 'rest_validate_request_arg',
936 936
 		);
937 937
 		$params['order'] = array(
938 938
 			'default'            => 'asc',
939
-			'description'        => __( 'Order sort attribute ascending or descending.', 'woocommerce' ),
940
-			'enum'               => array( 'asc', 'desc' ),
939
+			'description'        => __('Order sort attribute ascending or descending.', 'woocommerce'),
940
+			'enum'               => array('asc', 'desc'),
941 941
 			'sanitize_callback'  => 'sanitize_key',
942 942
 			'type'               => 'string',
943 943
 			'validate_callback'  => 'rest_validate_request_arg',
944 944
 		);
945 945
 		$params['orderby'] = array(
946 946
 			'default'            => 'name',
947
-			'description'        => __( 'Sort collection by object attribute.', 'woocommerce' ),
947
+			'description'        => __('Sort collection by object attribute.', 'woocommerce'),
948 948
 			'enum'               => array(
949 949
 				'id',
950 950
 				'include',
@@ -956,16 +956,16 @@  discard block
 block discarded – undo
956 956
 			'validate_callback'  => 'rest_validate_request_arg',
957 957
 		);
958 958
 		$params['email'] = array(
959
-			'description'        => __( 'Limit result set to resources with a specific email.', 'woocommerce' ),
959
+			'description'        => __('Limit result set to resources with a specific email.', 'woocommerce'),
960 960
 			'type'               => 'string',
961 961
 			'format'             => 'email',
962 962
 			'validate_callback'  => 'rest_validate_request_arg',
963 963
 		);
964 964
 		$params['role'] = array(
965
-			'description'        => __( 'Limit result set to resources with a specific role.', 'woocommerce' ),
965
+			'description'        => __('Limit result set to resources with a specific role.', 'woocommerce'),
966 966
 			'type'               => 'string',
967 967
 			'default'            => 'customer',
968
-			'enum'               => array_merge( array( 'all' ), $this->get_role_names() ),
968
+			'enum'               => array_merge(array('all'), $this->get_role_names()),
969 969
 			'validate_callback'  => 'rest_validate_request_arg',
970 970
 		);
971 971
 		return $params;
Please login to merge, or discard this patch.