@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.5.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Data continents controller class. |
@@ -42,26 +42,26 @@ discard block |
||
42 | 42 | $this->namespace, '/' . $this->rest_base, array( |
43 | 43 | array( |
44 | 44 | 'methods' => WP_REST_Server::READABLE, |
45 | - 'callback' => array( $this, 'get_items' ), |
|
46 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
45 | + 'callback' => array($this, 'get_items'), |
|
46 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
47 | 47 | ), |
48 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
48 | + 'schema' => array($this, 'get_public_item_schema'), |
|
49 | 49 | ) |
50 | 50 | ); |
51 | 51 | register_rest_route( |
52 | 52 | $this->namespace, '/' . $this->rest_base . '/(?P<location>[\w-]+)', array( |
53 | 53 | array( |
54 | 54 | 'methods' => WP_REST_Server::READABLE, |
55 | - 'callback' => array( $this, 'get_item' ), |
|
56 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
55 | + 'callback' => array($this, 'get_item'), |
|
56 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
57 | 57 | 'args' => array( |
58 | 58 | 'continent' => array( |
59 | - 'description' => __( '2 character continent code.', 'woocommerce' ), |
|
59 | + 'description' => __('2 character continent code.', 'woocommerce'), |
|
60 | 60 | 'type' => 'string', |
61 | 61 | ), |
62 | 62 | ), |
63 | 63 | ), |
64 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
64 | + 'schema' => array($this, 'get_public_item_schema'), |
|
65 | 65 | ) |
66 | 66 | ); |
67 | 67 | } |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | * @param WP_REST_Request $request Request data. |
75 | 75 | * @return array|mixed Response data, ready for insertion into collection data. |
76 | 76 | */ |
77 | - public function get_continent( $continent_code = false, $request ) { |
|
77 | + public function get_continent($continent_code = false, $request) { |
|
78 | 78 | $continents = WC()->countries->get_continents(); |
79 | 79 | $countries = WC()->countries->get_countries(); |
80 | 80 | $states = WC()->countries->get_states(); |
81 | 81 | $locale_info = include WC()->plugin_path() . '/i18n/locale-info.php'; |
82 | 82 | $data = array(); |
83 | 83 | |
84 | - if ( ! array_key_exists( $continent_code, $continents ) ) { |
|
84 | + if ( ! array_key_exists($continent_code, $continents)) { |
|
85 | 85 | return false; |
86 | 86 | } |
87 | 87 | |
88 | - $continent_list = $continents[ $continent_code ]; |
|
88 | + $continent_list = $continents[$continent_code]; |
|
89 | 89 | |
90 | 90 | $continent = array( |
91 | 91 | 'code' => $continent_code, |
@@ -93,18 +93,18 @@ discard block |
||
93 | 93 | ); |
94 | 94 | |
95 | 95 | $local_countries = array(); |
96 | - foreach ( $continent_list['countries'] as $country_code ) { |
|
97 | - if ( isset( $countries[ $country_code ] ) ) { |
|
96 | + foreach ($continent_list['countries'] as $country_code) { |
|
97 | + if (isset($countries[$country_code])) { |
|
98 | 98 | $country = array( |
99 | 99 | 'code' => $country_code, |
100 | - 'name' => $countries[ $country_code ], |
|
100 | + 'name' => $countries[$country_code], |
|
101 | 101 | ); |
102 | 102 | |
103 | 103 | // If we have detailed locale information include that in the response. |
104 | - if ( array_key_exists( $country_code, $locale_info ) ) { |
|
104 | + if (array_key_exists($country_code, $locale_info)) { |
|
105 | 105 | // Defensive programming against unexpected changes in locale-info.php. |
106 | 106 | $country_data = wp_parse_args( |
107 | - $locale_info[ $country_code ], array( |
|
107 | + $locale_info[$country_code], array( |
|
108 | 108 | 'currency_code' => 'USD', |
109 | 109 | 'currency_pos' => 'left', |
110 | 110 | 'decimal_sep' => '.', |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | ) |
116 | 116 | ); |
117 | 117 | |
118 | - $country = array_merge( $country, $country_data ); |
|
118 | + $country = array_merge($country, $country_data); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | $local_states = array(); |
122 | - if ( isset( $states[ $country_code ] ) ) { |
|
123 | - foreach ( $states[ $country_code ] as $state_code => $state_name ) { |
|
122 | + if (isset($states[$country_code])) { |
|
123 | + foreach ($states[$country_code] as $state_code => $state_name) { |
|
124 | 124 | $local_states[] = array( |
125 | 125 | 'code' => $state_code, |
126 | 126 | 'name' => $state_name, |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | 'thousand_sep', |
143 | 143 | 'weight_unit', |
144 | 144 | ); |
145 | - $country = array_intersect_key( $country, array_flip( $allowed ) ); |
|
145 | + $country = array_intersect_key($country, array_flip($allowed)); |
|
146 | 146 | |
147 | 147 | $local_countries[] = $country; |
148 | 148 | } |
@@ -159,17 +159,17 @@ discard block |
||
159 | 159 | * @param WP_REST_Request $request Request data. |
160 | 160 | * @return WP_Error|WP_REST_Response |
161 | 161 | */ |
162 | - public function get_items( $request ) { |
|
162 | + public function get_items($request) { |
|
163 | 163 | $continents = WC()->countries->get_continents(); |
164 | 164 | $data = array(); |
165 | 165 | |
166 | - foreach ( array_keys( $continents ) as $continent_code ) { |
|
167 | - $continent = $this->get_continent( $continent_code, $request ); |
|
168 | - $response = $this->prepare_item_for_response( $continent, $request ); |
|
169 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
166 | + foreach (array_keys($continents) as $continent_code) { |
|
167 | + $continent = $this->get_continent($continent_code, $request); |
|
168 | + $response = $this->prepare_item_for_response($continent, $request); |
|
169 | + $data[] = $this->prepare_response_for_collection($response); |
|
170 | 170 | } |
171 | 171 | |
172 | - return rest_ensure_response( $data ); |
|
172 | + return rest_ensure_response($data); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | * @param WP_REST_Request $request Request data. |
180 | 180 | * @return WP_Error|WP_REST_Response |
181 | 181 | */ |
182 | - public function get_item( $request ) { |
|
183 | - $data = $this->get_continent( strtoupper( $request['location'] ), $request ); |
|
184 | - if ( empty( $data ) ) { |
|
185 | - return new WP_Error( 'woocommerce_rest_data_invalid_location', __( 'There are no locations matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
182 | + public function get_item($request) { |
|
183 | + $data = $this->get_continent(strtoupper($request['location']), $request); |
|
184 | + if (empty($data)) { |
|
185 | + return new WP_Error('woocommerce_rest_data_invalid_location', __('There are no locations matching these parameters.', 'woocommerce'), array('status' => 404)); |
|
186 | 186 | } |
187 | - return $this->prepare_item_for_response( $data, $request ); |
|
187 | + return $this->prepare_item_for_response($data, $request); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | * @param WP_REST_Request $request Request object. |
196 | 196 | * @return WP_REST_Response $response Response data. |
197 | 197 | */ |
198 | - public function prepare_item_for_response( $item, $request ) { |
|
199 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
200 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
201 | - $response = rest_ensure_response( $data ); |
|
198 | + public function prepare_item_for_response($item, $request) { |
|
199 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
200 | + $data = $this->filter_response_by_context($data, 'view'); |
|
201 | + $response = rest_ensure_response($data); |
|
202 | 202 | |
203 | - $response->add_links( $this->prepare_links( $item ) ); |
|
203 | + $response->add_links($this->prepare_links($item)); |
|
204 | 204 | |
205 | 205 | /** |
206 | 206 | * Filter the location list returned from the API. |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | * @param array $item The original list of continent(s), countries, and states. |
212 | 212 | * @param WP_REST_Request $request Request used to generate the response. |
213 | 213 | */ |
214 | - return apply_filters( 'woocommerce_rest_prepare_data_continent', $response, $item, $request ); |
|
214 | + return apply_filters('woocommerce_rest_prepare_data_continent', $response, $item, $request); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -220,14 +220,14 @@ discard block |
||
220 | 220 | * @param object $item Data object. |
221 | 221 | * @return array Links for the given continent. |
222 | 222 | */ |
223 | - protected function prepare_links( $item ) { |
|
224 | - $continent_code = strtolower( $item['code'] ); |
|
223 | + protected function prepare_links($item) { |
|
224 | + $continent_code = strtolower($item['code']); |
|
225 | 225 | $links = array( |
226 | 226 | 'self' => array( |
227 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $continent_code ) ), |
|
227 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $continent_code)), |
|
228 | 228 | ), |
229 | 229 | 'collection' => array( |
230 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
230 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
231 | 231 | ), |
232 | 232 | ); |
233 | 233 | return $links; |
@@ -247,88 +247,88 @@ discard block |
||
247 | 247 | 'properties' => array( |
248 | 248 | 'code' => array( |
249 | 249 | 'type' => 'string', |
250 | - 'description' => __( '2 character continent code.', 'woocommerce' ), |
|
251 | - 'context' => array( 'view' ), |
|
250 | + 'description' => __('2 character continent code.', 'woocommerce'), |
|
251 | + 'context' => array('view'), |
|
252 | 252 | 'readonly' => true, |
253 | 253 | ), |
254 | 254 | 'name' => array( |
255 | 255 | 'type' => 'string', |
256 | - 'description' => __( 'Full name of continent.', 'woocommerce' ), |
|
257 | - 'context' => array( 'view' ), |
|
256 | + 'description' => __('Full name of continent.', 'woocommerce'), |
|
257 | + 'context' => array('view'), |
|
258 | 258 | 'readonly' => true, |
259 | 259 | ), |
260 | 260 | 'countries' => array( |
261 | 261 | 'type' => 'array', |
262 | - 'description' => __( 'List of countries on this continent.', 'woocommerce' ), |
|
263 | - 'context' => array( 'view' ), |
|
262 | + 'description' => __('List of countries on this continent.', 'woocommerce'), |
|
263 | + 'context' => array('view'), |
|
264 | 264 | 'readonly' => true, |
265 | 265 | 'items' => array( |
266 | 266 | 'type' => 'object', |
267 | - 'context' => array( 'view' ), |
|
267 | + 'context' => array('view'), |
|
268 | 268 | 'readonly' => true, |
269 | 269 | 'properties' => array( |
270 | 270 | 'code' => array( |
271 | 271 | 'type' => 'string', |
272 | - 'description' => __( 'ISO3166 alpha-2 country code.', 'woocommerce' ), |
|
273 | - 'context' => array( 'view' ), |
|
272 | + 'description' => __('ISO3166 alpha-2 country code.', 'woocommerce'), |
|
273 | + 'context' => array('view'), |
|
274 | 274 | 'readonly' => true, |
275 | 275 | ), |
276 | 276 | 'currency_code' => array( |
277 | 277 | 'type' => 'string', |
278 | - 'description' => __( 'Default ISO4127 alpha-3 currency code for the country.', 'woocommerce' ), |
|
279 | - 'context' => array( 'view' ), |
|
278 | + 'description' => __('Default ISO4127 alpha-3 currency code for the country.', 'woocommerce'), |
|
279 | + 'context' => array('view'), |
|
280 | 280 | 'readonly' => true, |
281 | 281 | ), |
282 | 282 | 'currency_pos' => array( |
283 | 283 | 'type' => 'string', |
284 | - 'description' => __( 'Currency symbol position for this country.', 'woocommerce' ), |
|
285 | - 'context' => array( 'view' ), |
|
284 | + 'description' => __('Currency symbol position for this country.', 'woocommerce'), |
|
285 | + 'context' => array('view'), |
|
286 | 286 | 'readonly' => true, |
287 | 287 | ), |
288 | 288 | 'decimal_sep' => array( |
289 | 289 | 'type' => 'string', |
290 | - 'description' => __( 'Decimal separator for displayed prices for this country.', 'woocommerce' ), |
|
291 | - 'context' => array( 'view' ), |
|
290 | + 'description' => __('Decimal separator for displayed prices for this country.', 'woocommerce'), |
|
291 | + 'context' => array('view'), |
|
292 | 292 | 'readonly' => true, |
293 | 293 | ), |
294 | 294 | 'dimension_unit' => array( |
295 | 295 | 'type' => 'string', |
296 | - 'description' => __( 'The unit lengths are defined in for this country.', 'woocommerce' ), |
|
297 | - 'context' => array( 'view' ), |
|
296 | + 'description' => __('The unit lengths are defined in for this country.', 'woocommerce'), |
|
297 | + 'context' => array('view'), |
|
298 | 298 | 'readonly' => true, |
299 | 299 | ), |
300 | 300 | 'name' => array( |
301 | 301 | 'type' => 'string', |
302 | - 'description' => __( 'Full name of country.', 'woocommerce' ), |
|
303 | - 'context' => array( 'view' ), |
|
302 | + 'description' => __('Full name of country.', 'woocommerce'), |
|
303 | + 'context' => array('view'), |
|
304 | 304 | 'readonly' => true, |
305 | 305 | ), |
306 | 306 | 'num_decimals' => array( |
307 | 307 | 'type' => 'integer', |
308 | - 'description' => __( 'Number of decimal points shown in displayed prices for this country.', 'woocommerce' ), |
|
309 | - 'context' => array( 'view' ), |
|
308 | + 'description' => __('Number of decimal points shown in displayed prices for this country.', 'woocommerce'), |
|
309 | + 'context' => array('view'), |
|
310 | 310 | 'readonly' => true, |
311 | 311 | ), |
312 | 312 | 'states' => array( |
313 | 313 | 'type' => 'array', |
314 | - 'description' => __( 'List of states in this country.', 'woocommerce' ), |
|
315 | - 'context' => array( 'view' ), |
|
314 | + 'description' => __('List of states in this country.', 'woocommerce'), |
|
315 | + 'context' => array('view'), |
|
316 | 316 | 'readonly' => true, |
317 | 317 | 'items' => array( |
318 | 318 | 'type' => 'object', |
319 | - 'context' => array( 'view' ), |
|
319 | + 'context' => array('view'), |
|
320 | 320 | 'readonly' => true, |
321 | 321 | 'properties' => array( |
322 | 322 | 'code' => array( |
323 | 323 | 'type' => 'string', |
324 | - 'description' => __( 'State code.', 'woocommerce' ), |
|
325 | - 'context' => array( 'view' ), |
|
324 | + 'description' => __('State code.', 'woocommerce'), |
|
325 | + 'context' => array('view'), |
|
326 | 326 | 'readonly' => true, |
327 | 327 | ), |
328 | 328 | 'name' => array( |
329 | 329 | 'type' => 'string', |
330 | - 'description' => __( 'Full name of state.', 'woocommerce' ), |
|
331 | - 'context' => array( 'view' ), |
|
330 | + 'description' => __('Full name of state.', 'woocommerce'), |
|
331 | + 'context' => array('view'), |
|
332 | 332 | 'readonly' => true, |
333 | 333 | ), |
334 | 334 | ), |
@@ -336,14 +336,14 @@ discard block |
||
336 | 336 | ), |
337 | 337 | 'thousand_sep' => array( |
338 | 338 | 'type' => 'string', |
339 | - 'description' => __( 'Thousands separator for displayed prices in this country.', 'woocommerce' ), |
|
340 | - 'context' => array( 'view' ), |
|
339 | + 'description' => __('Thousands separator for displayed prices in this country.', 'woocommerce'), |
|
340 | + 'context' => array('view'), |
|
341 | 341 | 'readonly' => true, |
342 | 342 | ), |
343 | 343 | 'weight_unit' => array( |
344 | 344 | 'type' => 'string', |
345 | - 'description' => __( 'The unit weights are defined in for this country.', 'woocommerce' ), |
|
346 | - 'context' => array( 'view' ), |
|
345 | + 'description' => __('The unit weights are defined in for this country.', 'woocommerce'), |
|
346 | + 'context' => array('view'), |
|
347 | 347 | 'readonly' => true, |
348 | 348 | ), |
349 | 349 | ), |
@@ -352,6 +352,6 @@ discard block |
||
352 | 352 | ), |
353 | 353 | ); |
354 | 354 | |
355 | - return $this->add_additional_fields_schema( $schema ); |
|
355 | + return $this->add_additional_fields_schema($schema); |
|
356 | 356 | } |
357 | 357 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Product Attributes controller class. |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.5.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Product Reviews Controller Class. |
@@ -40,40 +40,40 @@ discard block |
||
40 | 40 | $this->namespace, '/' . $this->rest_base, 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 ), array( |
|
52 | + $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
53 | 53 | 'product_id' => array( |
54 | 54 | 'required' => true, |
55 | - 'description' => __( 'Unique identifier for the product.', 'woocommerce' ), |
|
55 | + 'description' => __('Unique identifier for the product.', 'woocommerce'), |
|
56 | 56 | 'type' => 'integer', |
57 | 57 | ), |
58 | 58 | 'review' => array( |
59 | 59 | 'required' => true, |
60 | 60 | 'type' => 'string', |
61 | - 'description' => __( 'Review content.', 'woocommerce' ), |
|
61 | + 'description' => __('Review content.', 'woocommerce'), |
|
62 | 62 | ), |
63 | 63 | 'reviewer' => array( |
64 | 64 | 'required' => true, |
65 | 65 | 'type' => 'string', |
66 | - 'description' => __( 'Name of the reviewer.', 'woocommerce' ), |
|
66 | + 'description' => __('Name of the reviewer.', 'woocommerce'), |
|
67 | 67 | ), |
68 | 68 | 'reviewer_email' => array( |
69 | 69 | 'required' => true, |
70 | 70 | 'type' => 'string', |
71 | - 'description' => __( 'Email of the reviewer.', 'woocommerce' ), |
|
71 | + 'description' => __('Email of the reviewer.', 'woocommerce'), |
|
72 | 72 | ), |
73 | 73 | ) |
74 | 74 | ), |
75 | 75 | ), |
76 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
76 | + 'schema' => array($this, 'get_public_item_schema'), |
|
77 | 77 | ) |
78 | 78 | ); |
79 | 79 | |
@@ -81,37 +81,37 @@ discard block |
||
81 | 81 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
82 | 82 | 'args' => array( |
83 | 83 | 'id' => array( |
84 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
84 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
85 | 85 | 'type' => 'integer', |
86 | 86 | ), |
87 | 87 | ), |
88 | 88 | array( |
89 | 89 | 'methods' => WP_REST_Server::READABLE, |
90 | - 'callback' => array( $this, 'get_item' ), |
|
91 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
90 | + 'callback' => array($this, 'get_item'), |
|
91 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
92 | 92 | 'args' => array( |
93 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
93 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
94 | 94 | ), |
95 | 95 | ), |
96 | 96 | array( |
97 | 97 | 'methods' => WP_REST_Server::EDITABLE, |
98 | - 'callback' => array( $this, 'update_item' ), |
|
99 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
100 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
98 | + 'callback' => array($this, 'update_item'), |
|
99 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
100 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
101 | 101 | ), |
102 | 102 | array( |
103 | 103 | 'methods' => WP_REST_Server::DELETABLE, |
104 | - 'callback' => array( $this, 'delete_item' ), |
|
105 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
104 | + 'callback' => array($this, 'delete_item'), |
|
105 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
106 | 106 | 'args' => array( |
107 | 107 | 'force' => array( |
108 | 108 | 'default' => false, |
109 | 109 | 'type' => 'boolean', |
110 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
110 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
111 | 111 | ), |
112 | 112 | ), |
113 | 113 | ), |
114 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
114 | + 'schema' => array($this, 'get_public_item_schema'), |
|
115 | 115 | ) |
116 | 116 | ); |
117 | 117 | |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | $this->namespace, '/' . $this->rest_base . '/batch', array( |
120 | 120 | array( |
121 | 121 | 'methods' => WP_REST_Server::EDITABLE, |
122 | - 'callback' => array( $this, 'batch_items' ), |
|
123 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
124 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
122 | + 'callback' => array($this, 'batch_items'), |
|
123 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
124 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
125 | 125 | ), |
126 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
126 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
127 | 127 | ) |
128 | 128 | ); |
129 | 129 | } |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | * @param WP_REST_Request $request Full details about the request. |
135 | 135 | * @return WP_Error|boolean |
136 | 136 | */ |
137 | - public function get_items_permissions_check( $request ) { |
|
138 | - if ( ! wc_rest_check_product_reviews_permissions( 'read' ) ) { |
|
139 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
137 | + public function get_items_permissions_check($request) { |
|
138 | + if ( ! wc_rest_check_product_reviews_permissions('read')) { |
|
139 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | return true; |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | * @param WP_REST_Request $request Full details about the request. |
149 | 149 | * @return WP_Error|boolean |
150 | 150 | */ |
151 | - public function get_item_permissions_check( $request ) { |
|
151 | + public function get_item_permissions_check($request) { |
|
152 | 152 | $id = (int) $request['id']; |
153 | - $review = get_comment( $id ); |
|
153 | + $review = get_comment($id); |
|
154 | 154 | |
155 | - if ( $review && ! wc_rest_check_product_reviews_permissions( 'read', $review->comment_ID ) ) { |
|
156 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
155 | + if ($review && ! wc_rest_check_product_reviews_permissions('read', $review->comment_ID)) { |
|
156 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | return true; |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | * @param WP_REST_Request $request Full details about the request. |
166 | 166 | * @return WP_Error|boolean |
167 | 167 | */ |
168 | - public function create_item_permissions_check( $request ) { |
|
169 | - if ( ! wc_rest_check_product_reviews_permissions( 'create' ) ) { |
|
170 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
168 | + public function create_item_permissions_check($request) { |
|
169 | + if ( ! wc_rest_check_product_reviews_permissions('create')) { |
|
170 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | return true; |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | * @param WP_REST_Request $request Full details about the request. |
180 | 180 | * @return WP_Error|boolean |
181 | 181 | */ |
182 | - public function update_item_permissions_check( $request ) { |
|
182 | + public function update_item_permissions_check($request) { |
|
183 | 183 | $id = (int) $request['id']; |
184 | - $review = get_comment( $id ); |
|
184 | + $review = get_comment($id); |
|
185 | 185 | |
186 | - if ( $review && ! wc_rest_check_product_reviews_permissions( 'edit', $review->comment_ID ) ) { |
|
187 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
186 | + if ($review && ! wc_rest_check_product_reviews_permissions('edit', $review->comment_ID)) { |
|
187 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | return true; |
@@ -196,12 +196,12 @@ discard block |
||
196 | 196 | * @param WP_REST_Request $request Full details about the request. |
197 | 197 | * @return WP_Error|boolean |
198 | 198 | */ |
199 | - public function delete_item_permissions_check( $request ) { |
|
199 | + public function delete_item_permissions_check($request) { |
|
200 | 200 | $id = (int) $request['id']; |
201 | - $review = get_comment( $id ); |
|
201 | + $review = get_comment($id); |
|
202 | 202 | |
203 | - if ( $review && ! wc_rest_check_product_reviews_permissions( 'delete', $review->comment_ID ) ) { |
|
204 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
203 | + if ($review && ! wc_rest_check_product_reviews_permissions('delete', $review->comment_ID)) { |
|
204 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return true; |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | * @param WP_REST_Request $request Full details about the request. |
214 | 214 | * @return boolean|WP_Error |
215 | 215 | */ |
216 | - public function batch_items_permissions_check( $request ) { |
|
217 | - if ( ! wc_rest_check_product_reviews_permissions( 'create' ) ) { |
|
218 | - return new WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
216 | + public function batch_items_permissions_check($request) { |
|
217 | + if ( ! wc_rest_check_product_reviews_permissions('create')) { |
|
218 | + 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())); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | return true; |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @param WP_REST_Request $request Full details about the request. |
228 | 228 | * @return array|WP_Error |
229 | 229 | */ |
230 | - public function get_items( $request ) { |
|
230 | + public function get_items($request) { |
|
231 | 231 | // Retrieve the list of registered collection query parameters. |
232 | 232 | $registered = $this->get_collection_params(); |
233 | 233 | |
@@ -257,24 +257,24 @@ discard block |
||
257 | 257 | * For each known parameter which is both registered and present in the request, |
258 | 258 | * set the parameter's value on the query $prepared_args. |
259 | 259 | */ |
260 | - foreach ( $parameter_mappings as $api_param => $wp_param ) { |
|
261 | - if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) { |
|
262 | - $prepared_args[ $wp_param ] = $request[ $api_param ]; |
|
260 | + foreach ($parameter_mappings as $api_param => $wp_param) { |
|
261 | + if (isset($registered[$api_param], $request[$api_param])) { |
|
262 | + $prepared_args[$wp_param] = $request[$api_param]; |
|
263 | 263 | } |
264 | 264 | } |
265 | 265 | |
266 | 266 | // Ensure certain parameter values default to empty strings. |
267 | - foreach ( array( 'author_email', 'search' ) as $param ) { |
|
268 | - if ( ! isset( $prepared_args[ $param ] ) ) { |
|
269 | - $prepared_args[ $param ] = ''; |
|
267 | + foreach (array('author_email', 'search') as $param) { |
|
268 | + if ( ! isset($prepared_args[$param])) { |
|
269 | + $prepared_args[$param] = ''; |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
273 | - if ( isset( $registered['orderby'] ) ) { |
|
274 | - $prepared_args['orderby'] = $this->normalize_query_param( $request['orderby'] ); |
|
273 | + if (isset($registered['orderby'])) { |
|
274 | + $prepared_args['orderby'] = $this->normalize_query_param($request['orderby']); |
|
275 | 275 | } |
276 | 276 | |
277 | - if ( isset( $prepared_args['status'] ) ) { |
|
277 | + if (isset($prepared_args['status'])) { |
|
278 | 278 | $prepared_args['status'] = 'approved' === $prepared_args['status'] ? 'approve' : $prepared_args['status']; |
279 | 279 | } |
280 | 280 | |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | $prepared_args['date_query'] = array(); |
283 | 283 | |
284 | 284 | // Set before into date query. Date query must be specified as an array of an array. |
285 | - if ( isset( $registered['before'], $request['before'] ) ) { |
|
285 | + if (isset($registered['before'], $request['before'])) { |
|
286 | 286 | $prepared_args['date_query'][0]['before'] = $request['before']; |
287 | 287 | } |
288 | 288 | |
289 | 289 | // Set after into date query. Date query must be specified as an array of an array. |
290 | - if ( isset( $registered['after'], $request['after'] ) ) { |
|
290 | + if (isset($registered['after'], $request['after'])) { |
|
291 | 291 | $prepared_args['date_query'][0]['after'] = $request['after']; |
292 | 292 | } |
293 | 293 | |
294 | - if ( isset( $registered['page'] ) && empty( $request['offset'] ) ) { |
|
295 | - $prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 ); |
|
294 | + if (isset($registered['page']) && empty($request['offset'])) { |
|
295 | + $prepared_args['offset'] = $prepared_args['number'] * (absint($request['page']) - 1); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -303,61 +303,61 @@ discard block |
||
303 | 303 | * @param array $prepared_args Array of arguments for WP_Comment_Query. |
304 | 304 | * @param WP_REST_Request $request The current request. |
305 | 305 | */ |
306 | - $prepared_args = apply_filters( 'woocommerce_rest_product_review_query', $prepared_args, $request ); |
|
306 | + $prepared_args = apply_filters('woocommerce_rest_product_review_query', $prepared_args, $request); |
|
307 | 307 | |
308 | 308 | // Make sure that returns only reviews. |
309 | 309 | $prepared_args['type'] = 'review'; |
310 | 310 | |
311 | 311 | // Query reviews. |
312 | 312 | $query = new WP_Comment_Query(); |
313 | - $query_result = $query->query( $prepared_args ); |
|
313 | + $query_result = $query->query($prepared_args); |
|
314 | 314 | $reviews = array(); |
315 | 315 | |
316 | - foreach ( $query_result as $review ) { |
|
317 | - if ( ! wc_rest_check_product_reviews_permissions( 'read', $review->comment_ID ) ) { |
|
316 | + foreach ($query_result as $review) { |
|
317 | + if ( ! wc_rest_check_product_reviews_permissions('read', $review->comment_ID)) { |
|
318 | 318 | continue; |
319 | 319 | } |
320 | 320 | |
321 | - $data = $this->prepare_item_for_response( $review, $request ); |
|
322 | - $reviews[] = $this->prepare_response_for_collection( $data ); |
|
321 | + $data = $this->prepare_item_for_response($review, $request); |
|
322 | + $reviews[] = $this->prepare_response_for_collection($data); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | $total_reviews = (int) $query->found_comments; |
326 | 326 | $max_pages = (int) $query->max_num_pages; |
327 | 327 | |
328 | - if ( $total_reviews < 1 ) { |
|
328 | + if ($total_reviews < 1) { |
|
329 | 329 | // Out-of-bounds, run the query again without LIMIT for total count. |
330 | - unset( $prepared_args['number'], $prepared_args['offset'] ); |
|
330 | + unset($prepared_args['number'], $prepared_args['offset']); |
|
331 | 331 | |
332 | 332 | $query = new WP_Comment_Query(); |
333 | 333 | $prepared_args['count'] = true; |
334 | 334 | |
335 | - $total_reviews = $query->query( $prepared_args ); |
|
336 | - $max_pages = ceil( $total_reviews / $request['per_page'] ); |
|
335 | + $total_reviews = $query->query($prepared_args); |
|
336 | + $max_pages = ceil($total_reviews / $request['per_page']); |
|
337 | 337 | } |
338 | 338 | |
339 | - $response = rest_ensure_response( $reviews ); |
|
340 | - $response->header( 'X-WP-Total', $total_reviews ); |
|
341 | - $response->header( 'X-WP-TotalPages', $max_pages ); |
|
339 | + $response = rest_ensure_response($reviews); |
|
340 | + $response->header('X-WP-Total', $total_reviews); |
|
341 | + $response->header('X-WP-TotalPages', $max_pages); |
|
342 | 342 | |
343 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
343 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base))); |
|
344 | 344 | |
345 | - if ( $request['page'] > 1 ) { |
|
345 | + if ($request['page'] > 1) { |
|
346 | 346 | $prev_page = $request['page'] - 1; |
347 | 347 | |
348 | - if ( $prev_page > $max_pages ) { |
|
348 | + if ($prev_page > $max_pages) { |
|
349 | 349 | $prev_page = $max_pages; |
350 | 350 | } |
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 | 355 | |
356 | - if ( $max_pages > $request['page'] ) { |
|
356 | + if ($max_pages > $request['page']) { |
|
357 | 357 | $next_page = $request['page'] + 1; |
358 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
358 | + $next_link = add_query_arg('page', $next_page, $base); |
|
359 | 359 | |
360 | - $response->link_header( 'next', $next_link ); |
|
360 | + $response->link_header('next', $next_link); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | return $response; |
@@ -369,19 +369,19 @@ discard block |
||
369 | 369 | * @param WP_REST_Request $request Full details about the request. |
370 | 370 | * @return WP_Error|WP_REST_Response |
371 | 371 | */ |
372 | - public function create_item( $request ) { |
|
373 | - if ( ! empty( $request['id'] ) ) { |
|
374 | - return new WP_Error( 'woocommerce_rest_review_exists', __( 'Cannot create existing product review.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
372 | + public function create_item($request) { |
|
373 | + if ( ! empty($request['id'])) { |
|
374 | + return new WP_Error('woocommerce_rest_review_exists', __('Cannot create existing product review.', 'woocommerce'), array('status' => 400)); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | $product_id = (int) $request['product_id']; |
378 | 378 | |
379 | - if ( 'product' !== get_post_type( $product_id ) ) { |
|
380 | - return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
379 | + if ('product' !== get_post_type($product_id)) { |
|
380 | + return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
381 | 381 | } |
382 | 382 | |
383 | - $prepared_review = $this->prepare_item_for_database( $request ); |
|
384 | - if ( is_wp_error( $prepared_review ) ) { |
|
383 | + $prepared_review = $this->prepare_item_for_database($request); |
|
384 | + if (is_wp_error($prepared_review)) { |
|
385 | 385 | return $prepared_review; |
386 | 386 | } |
387 | 387 | |
@@ -390,49 +390,49 @@ discard block |
||
390 | 390 | /* |
391 | 391 | * Do not allow a comment to be created with missing or empty comment_content. See wp_handle_comment_submission(). |
392 | 392 | */ |
393 | - if ( empty( $prepared_review['comment_content'] ) ) { |
|
394 | - return new WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
393 | + if (empty($prepared_review['comment_content'])) { |
|
394 | + return new WP_Error('woocommerce_rest_review_content_invalid', __('Invalid review content.', 'woocommerce'), array('status' => 400)); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | // Setting remaining values before wp_insert_comment so we can use wp_allow_comment(). |
398 | - if ( ! isset( $prepared_review['comment_date_gmt'] ) ) { |
|
399 | - $prepared_review['comment_date_gmt'] = current_time( 'mysql', true ); |
|
398 | + if ( ! isset($prepared_review['comment_date_gmt'])) { |
|
399 | + $prepared_review['comment_date_gmt'] = current_time('mysql', true); |
|
400 | 400 | } |
401 | 401 | |
402 | - if ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) ) { // WPCS: input var ok, sanitization ok. |
|
403 | - $prepared_review['comment_author_IP'] = wc_clean( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); // WPCS: input var ok. |
|
402 | + if ( ! empty($_SERVER['REMOTE_ADDR']) && rest_is_ip_address(wp_unslash($_SERVER['REMOTE_ADDR']))) { // WPCS: input var ok, sanitization ok. |
|
403 | + $prepared_review['comment_author_IP'] = wc_clean(wp_unslash($_SERVER['REMOTE_ADDR'])); // WPCS: input var ok. |
|
404 | 404 | } else { |
405 | 405 | $prepared_review['comment_author_IP'] = '127.0.0.1'; |
406 | 406 | } |
407 | 407 | |
408 | - if ( ! empty( $request['author_user_agent'] ) ) { |
|
408 | + if ( ! empty($request['author_user_agent'])) { |
|
409 | 409 | $prepared_review['comment_agent'] = $request['author_user_agent']; |
410 | - } elseif ( $request->get_header( 'user_agent' ) ) { |
|
411 | - $prepared_review['comment_agent'] = $request->get_header( 'user_agent' ); |
|
410 | + } elseif ($request->get_header('user_agent')) { |
|
411 | + $prepared_review['comment_agent'] = $request->get_header('user_agent'); |
|
412 | 412 | } else { |
413 | 413 | $prepared_review['comment_agent'] = ''; |
414 | 414 | } |
415 | 415 | |
416 | - $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_review ); |
|
417 | - if ( is_wp_error( $check_comment_lengths ) ) { |
|
418 | - $error_code = str_replace( array( 'comment_author', 'comment_content' ), array( 'reviewer', 'review_content' ), $check_comment_lengths->get_error_code() ); |
|
419 | - return new WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
416 | + $check_comment_lengths = wp_check_comment_data_max_lengths($prepared_review); |
|
417 | + if (is_wp_error($check_comment_lengths)) { |
|
418 | + $error_code = str_replace(array('comment_author', 'comment_content'), array('reviewer', 'review_content'), $check_comment_lengths->get_error_code()); |
|
419 | + return new WP_Error('woocommerce_rest_' . $error_code, __('Product review field exceeds maximum length allowed.', 'woocommerce'), array('status' => 400)); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | $prepared_review['comment_parent'] = 0; |
423 | 423 | $prepared_review['comment_author_url'] = ''; |
424 | - $prepared_review['comment_approved'] = wp_allow_comment( $prepared_review, true ); |
|
424 | + $prepared_review['comment_approved'] = wp_allow_comment($prepared_review, true); |
|
425 | 425 | |
426 | - if ( is_wp_error( $prepared_review['comment_approved'] ) ) { |
|
426 | + if (is_wp_error($prepared_review['comment_approved'])) { |
|
427 | 427 | $error_code = $prepared_review['comment_approved']->get_error_code(); |
428 | 428 | $error_message = $prepared_review['comment_approved']->get_error_message(); |
429 | 429 | |
430 | - if ( 'comment_duplicate' === $error_code ) { |
|
431 | - return new WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 409 ) ); |
|
430 | + if ('comment_duplicate' === $error_code) { |
|
431 | + return new WP_Error('woocommerce_rest_' . $error_code, $error_message, array('status' => 409)); |
|
432 | 432 | } |
433 | 433 | |
434 | - if ( 'comment_flood' === $error_code ) { |
|
435 | - return new WP_Error( 'woocommerce_rest_' . $error_code, $error_message, array( 'status' => 400 ) ); |
|
434 | + if ('comment_flood' === $error_code) { |
|
435 | + return new WP_Error('woocommerce_rest_' . $error_code, $error_message, array('status' => 400)); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | return $prepared_review['comment_approved']; |
@@ -449,24 +449,24 @@ discard block |
||
449 | 449 | * @param array|WP_Error $prepared_review The prepared review data for wp_insert_comment(). |
450 | 450 | * @param WP_REST_Request $request Request used to insert the review. |
451 | 451 | */ |
452 | - $prepared_review = apply_filters( 'woocommerce_rest_pre_insert_product_review', $prepared_review, $request ); |
|
453 | - if ( is_wp_error( $prepared_review ) ) { |
|
452 | + $prepared_review = apply_filters('woocommerce_rest_pre_insert_product_review', $prepared_review, $request); |
|
453 | + if (is_wp_error($prepared_review)) { |
|
454 | 454 | return $prepared_review; |
455 | 455 | } |
456 | 456 | |
457 | - $review_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_review ) ) ); |
|
457 | + $review_id = wp_insert_comment(wp_filter_comment(wp_slash((array) $prepared_review))); |
|
458 | 458 | |
459 | - if ( ! $review_id ) { |
|
460 | - return new WP_Error( 'woocommerce_rest_review_failed_create', __( 'Creating product review failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
459 | + if ( ! $review_id) { |
|
460 | + return new WP_Error('woocommerce_rest_review_failed_create', __('Creating product review failed.', 'woocommerce'), array('status' => 500)); |
|
461 | 461 | } |
462 | 462 | |
463 | - if ( isset( $request['status'] ) ) { |
|
464 | - $this->handle_status_param( $request['status'], $review_id ); |
|
463 | + if (isset($request['status'])) { |
|
464 | + $this->handle_status_param($request['status'], $review_id); |
|
465 | 465 | } |
466 | 466 | |
467 | - update_comment_meta( $review_id, 'rating', ! empty( $request['rating'] ) ? $request['rating'] : '0' ); |
|
467 | + update_comment_meta($review_id, 'rating', ! empty($request['rating']) ? $request['rating'] : '0'); |
|
468 | 468 | |
469 | - $review = get_comment( $review_id ); |
|
469 | + $review = get_comment($review_id); |
|
470 | 470 | |
471 | 471 | /** |
472 | 472 | * Fires after a comment is created or updated via the REST API. |
@@ -475,21 +475,21 @@ discard block |
||
475 | 475 | * @param WP_REST_Request $request Request object. |
476 | 476 | * @param bool $creating True when creating a comment, false when updating. |
477 | 477 | */ |
478 | - do_action( 'woocommerce_rest_insert_product_review', $review, $request, true ); |
|
478 | + do_action('woocommerce_rest_insert_product_review', $review, $request, true); |
|
479 | 479 | |
480 | - $fields_update = $this->update_additional_fields_for_object( $review, $request ); |
|
481 | - if ( is_wp_error( $fields_update ) ) { |
|
480 | + $fields_update = $this->update_additional_fields_for_object($review, $request); |
|
481 | + if (is_wp_error($fields_update)) { |
|
482 | 482 | return $fields_update; |
483 | 483 | } |
484 | 484 | |
485 | - $context = current_user_can( 'moderate_comments' ) ? 'edit' : 'view'; |
|
486 | - $request->set_param( 'context', $context ); |
|
485 | + $context = current_user_can('moderate_comments') ? 'edit' : 'view'; |
|
486 | + $request->set_param('context', $context); |
|
487 | 487 | |
488 | - $response = $this->prepare_item_for_response( $review, $request ); |
|
489 | - $response = rest_ensure_response( $response ); |
|
488 | + $response = $this->prepare_item_for_response($review, $request); |
|
489 | + $response = rest_ensure_response($response); |
|
490 | 490 | |
491 | - $response->set_status( 201 ); |
|
492 | - $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $review_id ) ) ); |
|
491 | + $response->set_status(201); |
|
492 | + $response->header('Location', rest_url(sprintf('%s/%s/%d', $this->namespace, $this->rest_base, $review_id))); |
|
493 | 493 | |
494 | 494 | return $response; |
495 | 495 | } |
@@ -500,14 +500,14 @@ discard block |
||
500 | 500 | * @param WP_REST_Request $request Full details about the request. |
501 | 501 | * @return WP_Error|WP_REST_Response |
502 | 502 | */ |
503 | - public function get_item( $request ) { |
|
504 | - $review = $this->get_review( $request['id'] ); |
|
505 | - if ( is_wp_error( $review ) ) { |
|
503 | + public function get_item($request) { |
|
504 | + $review = $this->get_review($request['id']); |
|
505 | + if (is_wp_error($review)) { |
|
506 | 506 | return $review; |
507 | 507 | } |
508 | 508 | |
509 | - $data = $this->prepare_item_for_response( $review, $request ); |
|
510 | - $response = rest_ensure_response( $data ); |
|
509 | + $data = $this->prepare_item_for_response($review, $request); |
|
510 | + $response = rest_ensure_response($data); |
|
511 | 511 | |
512 | 512 | return $response; |
513 | 513 | } |
@@ -518,84 +518,84 @@ discard block |
||
518 | 518 | * @param WP_REST_Request $request Full details about the request. |
519 | 519 | * @return WP_Error|WP_REST_Response Response object on success, or error object on failure. |
520 | 520 | */ |
521 | - public function update_item( $request ) { |
|
522 | - $review = $this->get_review( $request['id'] ); |
|
523 | - if ( is_wp_error( $review ) ) { |
|
521 | + public function update_item($request) { |
|
522 | + $review = $this->get_review($request['id']); |
|
523 | + if (is_wp_error($review)) { |
|
524 | 524 | return $review; |
525 | 525 | } |
526 | 526 | |
527 | 527 | $id = (int) $review->comment_ID; |
528 | 528 | |
529 | - if ( isset( $request['type'] ) && 'review' !== get_comment_type( $id ) ) { |
|
530 | - return new WP_Error( 'woocommerce_rest_review_invalid_type', __( 'Sorry, you are not allowed to change the comment type.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
529 | + if (isset($request['type']) && 'review' !== get_comment_type($id)) { |
|
530 | + return new WP_Error('woocommerce_rest_review_invalid_type', __('Sorry, you are not allowed to change the comment type.', 'woocommerce'), array('status' => 404)); |
|
531 | 531 | } |
532 | 532 | |
533 | - $prepared_args = $this->prepare_item_for_database( $request ); |
|
534 | - if ( is_wp_error( $prepared_args ) ) { |
|
533 | + $prepared_args = $this->prepare_item_for_database($request); |
|
534 | + if (is_wp_error($prepared_args)) { |
|
535 | 535 | return $prepared_args; |
536 | 536 | } |
537 | 537 | |
538 | - if ( ! empty( $prepared_args['comment_post_ID'] ) ) { |
|
539 | - if ( 'product' !== get_post_type( (int) $prepared_args['comment_post_ID'] ) ) { |
|
540 | - return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
538 | + if ( ! empty($prepared_args['comment_post_ID'])) { |
|
539 | + if ('product' !== get_post_type((int) $prepared_args['comment_post_ID'])) { |
|
540 | + return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
541 | 541 | } |
542 | 542 | } |
543 | 543 | |
544 | - if ( empty( $prepared_args ) && isset( $request['status'] ) ) { |
|
544 | + if (empty($prepared_args) && isset($request['status'])) { |
|
545 | 545 | // Only the comment status is being changed. |
546 | - $change = $this->handle_status_param( $request['status'], $id ); |
|
546 | + $change = $this->handle_status_param($request['status'], $id); |
|
547 | 547 | |
548 | - if ( ! $change ) { |
|
549 | - return new WP_Error( 'woocommerce_rest_review_failed_edit', __( 'Updating review status failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
548 | + if ( ! $change) { |
|
549 | + return new WP_Error('woocommerce_rest_review_failed_edit', __('Updating review status failed.', 'woocommerce'), array('status' => 500)); |
|
550 | 550 | } |
551 | - } elseif ( ! empty( $prepared_args ) ) { |
|
552 | - if ( is_wp_error( $prepared_args ) ) { |
|
551 | + } elseif ( ! empty($prepared_args)) { |
|
552 | + if (is_wp_error($prepared_args)) { |
|
553 | 553 | return $prepared_args; |
554 | 554 | } |
555 | 555 | |
556 | - if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { |
|
557 | - return new WP_Error( 'woocommerce_rest_review_content_invalid', __( 'Invalid review content.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
556 | + if (isset($prepared_args['comment_content']) && empty($prepared_args['comment_content'])) { |
|
557 | + return new WP_Error('woocommerce_rest_review_content_invalid', __('Invalid review content.', 'woocommerce'), array('status' => 400)); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | $prepared_args['comment_ID'] = $id; |
561 | 561 | |
562 | - $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); |
|
563 | - if ( is_wp_error( $check_comment_lengths ) ) { |
|
564 | - $error_code = str_replace( array( 'comment_author', 'comment_content' ), array( 'reviewer', 'review_content' ), $check_comment_lengths->get_error_code() ); |
|
565 | - return new WP_Error( 'woocommerce_rest_' . $error_code, __( 'Product review field exceeds maximum length allowed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
562 | + $check_comment_lengths = wp_check_comment_data_max_lengths($prepared_args); |
|
563 | + if (is_wp_error($check_comment_lengths)) { |
|
564 | + $error_code = str_replace(array('comment_author', 'comment_content'), array('reviewer', 'review_content'), $check_comment_lengths->get_error_code()); |
|
565 | + return new WP_Error('woocommerce_rest_' . $error_code, __('Product review field exceeds maximum length allowed.', 'woocommerce'), array('status' => 400)); |
|
566 | 566 | } |
567 | 567 | |
568 | - $updated = wp_update_comment( wp_slash( (array) $prepared_args ) ); |
|
568 | + $updated = wp_update_comment(wp_slash((array) $prepared_args)); |
|
569 | 569 | |
570 | - if ( false === $updated ) { |
|
571 | - return new WP_Error( 'woocommerce_rest_comment_failed_edit', __( 'Updating review failed.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
570 | + if (false === $updated) { |
|
571 | + return new WP_Error('woocommerce_rest_comment_failed_edit', __('Updating review failed.', 'woocommerce'), array('status' => 500)); |
|
572 | 572 | } |
573 | 573 | |
574 | - if ( isset( $request['status'] ) ) { |
|
575 | - $this->handle_status_param( $request['status'], $id ); |
|
574 | + if (isset($request['status'])) { |
|
575 | + $this->handle_status_param($request['status'], $id); |
|
576 | 576 | } |
577 | 577 | } |
578 | 578 | |
579 | - if ( ! empty( $request['rating'] ) ) { |
|
580 | - update_comment_meta( $id, 'rating', $request['rating'] ); |
|
579 | + if ( ! empty($request['rating'])) { |
|
580 | + update_comment_meta($id, 'rating', $request['rating']); |
|
581 | 581 | } |
582 | 582 | |
583 | - $review = get_comment( $id ); |
|
583 | + $review = get_comment($id); |
|
584 | 584 | |
585 | 585 | /** This action is documented in includes/api/class-wc-rest-product-reviews-controller.php */ |
586 | - do_action( 'woocommerce_rest_insert_product_review', $review, $request, false ); |
|
586 | + do_action('woocommerce_rest_insert_product_review', $review, $request, false); |
|
587 | 587 | |
588 | - $fields_update = $this->update_additional_fields_for_object( $review, $request ); |
|
588 | + $fields_update = $this->update_additional_fields_for_object($review, $request); |
|
589 | 589 | |
590 | - if ( is_wp_error( $fields_update ) ) { |
|
590 | + if (is_wp_error($fields_update)) { |
|
591 | 591 | return $fields_update; |
592 | 592 | } |
593 | 593 | |
594 | - $request->set_param( 'context', 'edit' ); |
|
594 | + $request->set_param('context', 'edit'); |
|
595 | 595 | |
596 | - $response = $this->prepare_item_for_response( $review, $request ); |
|
596 | + $response = $this->prepare_item_for_response($review, $request); |
|
597 | 597 | |
598 | - return rest_ensure_response( $response ); |
|
598 | + return rest_ensure_response($response); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | /** |
@@ -604,13 +604,13 @@ discard block |
||
604 | 604 | * @param WP_REST_Request $request Full details about the request. |
605 | 605 | * @return WP_Error|WP_REST_Response Response object on success, or error object on failure. |
606 | 606 | */ |
607 | - public function delete_item( $request ) { |
|
608 | - $review = $this->get_review( $request['id'] ); |
|
609 | - if ( is_wp_error( $review ) ) { |
|
607 | + public function delete_item($request) { |
|
608 | + $review = $this->get_review($request['id']); |
|
609 | + if (is_wp_error($review)) { |
|
610 | 610 | return $review; |
611 | 611 | } |
612 | 612 | |
613 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
613 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
614 | 614 | |
615 | 615 | /** |
616 | 616 | * Filters whether a review can be trashed. |
@@ -621,13 +621,13 @@ discard block |
||
621 | 621 | * @param bool $supports_trash Whether the post type support trashing. |
622 | 622 | * @param WP_Comment $review The review object being considered for trashing support. |
623 | 623 | */ |
624 | - $supports_trash = apply_filters( 'woocommerce_rest_product_review_trashable', ( EMPTY_TRASH_DAYS > 0 ), $review ); |
|
624 | + $supports_trash = apply_filters('woocommerce_rest_product_review_trashable', (EMPTY_TRASH_DAYS > 0), $review); |
|
625 | 625 | |
626 | - $request->set_param( 'context', 'edit' ); |
|
626 | + $request->set_param('context', 'edit'); |
|
627 | 627 | |
628 | - if ( $force ) { |
|
629 | - $previous = $this->prepare_item_for_response( $review, $request ); |
|
630 | - $result = wp_delete_comment( $review->comment_ID, true ); |
|
628 | + if ($force) { |
|
629 | + $previous = $this->prepare_item_for_response($review, $request); |
|
630 | + $result = wp_delete_comment($review->comment_ID, true); |
|
631 | 631 | $response = new WP_REST_Response(); |
632 | 632 | $response->set_data( |
633 | 633 | array( |
@@ -637,22 +637,22 @@ discard block |
||
637 | 637 | ); |
638 | 638 | } else { |
639 | 639 | // If this type doesn't support trashing, error out. |
640 | - if ( ! $supports_trash ) { |
|
640 | + if ( ! $supports_trash) { |
|
641 | 641 | /* translators: %s: force=true */ |
642 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( "The object does not support trashing. Set '%s' to delete.", 'woocommerce' ), 'force=true' ), array( 'status' => 501 ) ); |
|
642 | + return new WP_Error('woocommerce_rest_trash_not_supported', sprintf(__("The object does not support trashing. Set '%s' to delete.", 'woocommerce'), 'force=true'), array('status' => 501)); |
|
643 | 643 | } |
644 | 644 | |
645 | - if ( 'trash' === $review->comment_approved ) { |
|
646 | - return new WP_Error( 'woocommerce_rest_already_trashed', __( 'The object has already been trashed.', 'woocommerce' ), array( 'status' => 410 ) ); |
|
645 | + if ('trash' === $review->comment_approved) { |
|
646 | + return new WP_Error('woocommerce_rest_already_trashed', __('The object has already been trashed.', 'woocommerce'), array('status' => 410)); |
|
647 | 647 | } |
648 | 648 | |
649 | - $result = wp_trash_comment( $review->comment_ID ); |
|
650 | - $review = get_comment( $review->comment_ID ); |
|
651 | - $response = $this->prepare_item_for_response( $review, $request ); |
|
649 | + $result = wp_trash_comment($review->comment_ID); |
|
650 | + $review = get_comment($review->comment_ID); |
|
651 | + $response = $this->prepare_item_for_response($review, $request); |
|
652 | 652 | } |
653 | 653 | |
654 | - if ( ! $result ) { |
|
655 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'The object cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
654 | + if ( ! $result) { |
|
655 | + return new WP_Error('woocommerce_rest_cannot_delete', __('The object cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | /** |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | * @param WP_REST_Response $response The response returned from the API. |
663 | 663 | * @param WP_REST_Request $request The request sent to the API. |
664 | 664 | */ |
665 | - do_action( 'woocommerce_rest_delete_review', $review, $response, $request ); |
|
665 | + do_action('woocommerce_rest_delete_review', $review, $response, $request); |
|
666 | 666 | |
667 | 667 | return $response; |
668 | 668 | } |
@@ -674,52 +674,52 @@ discard block |
||
674 | 674 | * @param WP_REST_Request $request Request object. |
675 | 675 | * @return WP_REST_Response $response Response data. |
676 | 676 | */ |
677 | - public function prepare_item_for_response( $review, $request ) { |
|
678 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
679 | - $fields = $this->get_fields_for_response( $request ); |
|
677 | + public function prepare_item_for_response($review, $request) { |
|
678 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
679 | + $fields = $this->get_fields_for_response($request); |
|
680 | 680 | $data = array(); |
681 | 681 | |
682 | - if ( in_array( 'id', $fields, true ) ) { |
|
682 | + if (in_array('id', $fields, true)) { |
|
683 | 683 | $data['id'] = (int) $review->comment_ID; |
684 | 684 | } |
685 | - if ( in_array( 'date_created', $fields, true ) ) { |
|
686 | - $data['date_created'] = wc_rest_prepare_date_response( $review->comment_date ); |
|
685 | + if (in_array('date_created', $fields, true)) { |
|
686 | + $data['date_created'] = wc_rest_prepare_date_response($review->comment_date); |
|
687 | 687 | } |
688 | - if ( in_array( 'date_created_gmt', $fields, true ) ) { |
|
689 | - $data['date_created_gmt'] = wc_rest_prepare_date_response( $review->comment_date_gmt ); |
|
688 | + if (in_array('date_created_gmt', $fields, true)) { |
|
689 | + $data['date_created_gmt'] = wc_rest_prepare_date_response($review->comment_date_gmt); |
|
690 | 690 | } |
691 | - if ( in_array( 'product_id', $fields, true ) ) { |
|
691 | + if (in_array('product_id', $fields, true)) { |
|
692 | 692 | $data['product_id'] = (int) $review->comment_post_ID; |
693 | 693 | } |
694 | - if ( in_array( 'status', $fields, true ) ) { |
|
695 | - $data['status'] = $this->prepare_status_response( (string) $review->comment_approved ); |
|
694 | + if (in_array('status', $fields, true)) { |
|
695 | + $data['status'] = $this->prepare_status_response((string) $review->comment_approved); |
|
696 | 696 | } |
697 | - if ( in_array( 'reviewer', $fields, true ) ) { |
|
697 | + if (in_array('reviewer', $fields, true)) { |
|
698 | 698 | $data['reviewer'] = $review->comment_author; |
699 | 699 | } |
700 | - if ( in_array( 'reviewer_email', $fields, true ) ) { |
|
700 | + if (in_array('reviewer_email', $fields, true)) { |
|
701 | 701 | $data['reviewer_email'] = $review->comment_author_email; |
702 | 702 | } |
703 | - if ( in_array( 'review', $fields, true ) ) { |
|
704 | - $data['review'] = 'view' === $context ? wpautop( $review->comment_content ) : $review->comment_content; |
|
703 | + if (in_array('review', $fields, true)) { |
|
704 | + $data['review'] = 'view' === $context ? wpautop($review->comment_content) : $review->comment_content; |
|
705 | 705 | } |
706 | - if ( in_array( 'rating', $fields, true ) ) { |
|
707 | - $data['rating'] = (int) get_comment_meta( $review->comment_ID, 'rating', true ); |
|
706 | + if (in_array('rating', $fields, true)) { |
|
707 | + $data['rating'] = (int) get_comment_meta($review->comment_ID, 'rating', true); |
|
708 | 708 | } |
709 | - if ( in_array( 'verified', $fields, true ) ) { |
|
710 | - $data['verified'] = wc_review_is_from_verified_owner( $review->comment_ID ); |
|
709 | + if (in_array('verified', $fields, true)) { |
|
710 | + $data['verified'] = wc_review_is_from_verified_owner($review->comment_ID); |
|
711 | 711 | } |
712 | - if ( in_array( 'reviewer_avatar_urls', $fields, true ) ) { |
|
713 | - $data['reviewer_avatar_urls'] = rest_get_avatar_urls( $review->comment_author_email ); |
|
712 | + if (in_array('reviewer_avatar_urls', $fields, true)) { |
|
713 | + $data['reviewer_avatar_urls'] = rest_get_avatar_urls($review->comment_author_email); |
|
714 | 714 | } |
715 | 715 | |
716 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
717 | - $data = $this->filter_response_by_context( $data, $context ); |
|
716 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
717 | + $data = $this->filter_response_by_context($data, $context); |
|
718 | 718 | |
719 | 719 | // Wrap the data in a response object. |
720 | - $response = rest_ensure_response( $data ); |
|
720 | + $response = rest_ensure_response($data); |
|
721 | 721 | |
722 | - $response->add_links( $this->prepare_links( $review ) ); |
|
722 | + $response->add_links($this->prepare_links($review)); |
|
723 | 723 | |
724 | 724 | /** |
725 | 725 | * Filter product reviews object returned from the REST API. |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | * @param WP_Comment $review Product review object used to create response. |
729 | 729 | * @param WP_REST_Request $request Request object. |
730 | 730 | */ |
731 | - return apply_filters( 'woocommerce_rest_prepare_product_review', $response, $review, $request ); |
|
731 | + return apply_filters('woocommerce_rest_prepare_product_review', $response, $review, $request); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | /** |
@@ -737,38 +737,38 @@ discard block |
||
737 | 737 | * @param WP_REST_Request $request Request object. |
738 | 738 | * @return array|WP_Error $prepared_review |
739 | 739 | */ |
740 | - protected function prepare_item_for_database( $request ) { |
|
741 | - if ( isset( $request['id'] ) ) { |
|
740 | + protected function prepare_item_for_database($request) { |
|
741 | + if (isset($request['id'])) { |
|
742 | 742 | $prepared_review['comment_ID'] = (int) $request['id']; |
743 | 743 | } |
744 | 744 | |
745 | - if ( isset( $request['review'] ) ) { |
|
745 | + if (isset($request['review'])) { |
|
746 | 746 | $prepared_review['comment_content'] = $request['review']; |
747 | 747 | } |
748 | 748 | |
749 | - if ( isset( $request['product_id'] ) ) { |
|
749 | + if (isset($request['product_id'])) { |
|
750 | 750 | $prepared_review['comment_post_ID'] = (int) $request['product_id']; |
751 | 751 | } |
752 | 752 | |
753 | - if ( isset( $request['reviewer'] ) ) { |
|
753 | + if (isset($request['reviewer'])) { |
|
754 | 754 | $prepared_review['comment_author'] = $request['reviewer']; |
755 | 755 | } |
756 | 756 | |
757 | - if ( isset( $request['reviewer_email'] ) ) { |
|
757 | + if (isset($request['reviewer_email'])) { |
|
758 | 758 | $prepared_review['comment_author_email'] = $request['reviewer_email']; |
759 | 759 | } |
760 | 760 | |
761 | - if ( ! empty( $request['date_created'] ) ) { |
|
762 | - $date_data = rest_get_date_with_gmt( $request['date_created'] ); |
|
761 | + if ( ! empty($request['date_created'])) { |
|
762 | + $date_data = rest_get_date_with_gmt($request['date_created']); |
|
763 | 763 | |
764 | - if ( ! empty( $date_data ) ) { |
|
765 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
764 | + if ( ! empty($date_data)) { |
|
765 | + list($prepared_review['comment_date'], $prepared_review['comment_date_gmt']) = $date_data; |
|
766 | 766 | } |
767 | - } elseif ( ! empty( $request['date_created_gmt'] ) ) { |
|
768 | - $date_data = rest_get_date_with_gmt( $request['date_created_gmt'], true ); |
|
767 | + } elseif ( ! empty($request['date_created_gmt'])) { |
|
768 | + $date_data = rest_get_date_with_gmt($request['date_created_gmt'], true); |
|
769 | 769 | |
770 | - if ( ! empty( $date_data ) ) { |
|
771 | - list( $prepared_review['comment_date'], $prepared_review['comment_date_gmt'] ) = $date_data; |
|
770 | + if ( ! empty($date_data)) { |
|
771 | + list($prepared_review['comment_date'], $prepared_review['comment_date_gmt']) = $date_data; |
|
772 | 772 | } |
773 | 773 | } |
774 | 774 | |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | * @param array $prepared_review The prepared review data for `wp_insert_comment`. |
782 | 782 | * @param WP_REST_Request $request The current request. |
783 | 783 | */ |
784 | - return apply_filters( 'woocommerce_rest_preprocess_product_review', $prepared_review, $request ); |
|
784 | + return apply_filters('woocommerce_rest_preprocess_product_review', $prepared_review, $request); |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | /** |
@@ -790,25 +790,25 @@ discard block |
||
790 | 790 | * @param WP_Comment $review Product review object. |
791 | 791 | * @return array Links for the given product review. |
792 | 792 | */ |
793 | - protected function prepare_links( $review ) { |
|
793 | + protected function prepare_links($review) { |
|
794 | 794 | $links = array( |
795 | 795 | 'self' => array( |
796 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $review->comment_ID ) ), |
|
796 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $review->comment_ID)), |
|
797 | 797 | ), |
798 | 798 | 'collection' => array( |
799 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
799 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
800 | 800 | ), |
801 | 801 | ); |
802 | 802 | |
803 | - if ( 0 !== (int) $review->comment_post_ID ) { |
|
803 | + if (0 !== (int) $review->comment_post_ID) { |
|
804 | 804 | $links['up'] = array( |
805 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $review->comment_post_ID ) ), |
|
805 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $review->comment_post_ID)), |
|
806 | 806 | ); |
807 | 807 | } |
808 | 808 | |
809 | - if ( 0 !== (int) $review->user_id ) { |
|
809 | + if (0 !== (int) $review->user_id) { |
|
810 | 810 | $links['reviewer'] = array( |
811 | - 'href' => rest_url( 'wp/v2/users/' . $review->user_id ), |
|
811 | + 'href' => rest_url('wp/v2/users/' . $review->user_id), |
|
812 | 812 | 'embeddable' => true, |
813 | 813 | ); |
814 | 814 | } |
@@ -828,91 +828,91 @@ discard block |
||
828 | 828 | 'type' => 'object', |
829 | 829 | 'properties' => array( |
830 | 830 | 'id' => array( |
831 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
831 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
832 | 832 | 'type' => 'integer', |
833 | - 'context' => array( 'view', 'edit' ), |
|
833 | + 'context' => array('view', 'edit'), |
|
834 | 834 | 'readonly' => true, |
835 | 835 | ), |
836 | 836 | 'date_created' => array( |
837 | - 'description' => __( "The date the review was created, in the site's timezone.", 'woocommerce' ), |
|
837 | + 'description' => __("The date the review was created, in the site's timezone.", 'woocommerce'), |
|
838 | 838 | 'type' => 'date-time', |
839 | - 'context' => array( 'view', 'edit' ), |
|
839 | + 'context' => array('view', 'edit'), |
|
840 | 840 | 'readonly' => true, |
841 | 841 | ), |
842 | 842 | 'date_created_gmt' => array( |
843 | - 'description' => __( 'The date the review was created, as GMT.', 'woocommerce' ), |
|
843 | + 'description' => __('The date the review was created, as GMT.', 'woocommerce'), |
|
844 | 844 | 'type' => 'date-time', |
845 | - 'context' => array( 'view', 'edit' ), |
|
845 | + 'context' => array('view', 'edit'), |
|
846 | 846 | 'readonly' => true, |
847 | 847 | ), |
848 | 848 | 'product_id' => array( |
849 | - 'description' => __( 'Unique identifier for the product that the review belongs to.', 'woocommerce' ), |
|
849 | + 'description' => __('Unique identifier for the product that the review belongs to.', 'woocommerce'), |
|
850 | 850 | 'type' => 'integer', |
851 | - 'context' => array( 'view', 'edit' ), |
|
851 | + 'context' => array('view', 'edit'), |
|
852 | 852 | ), |
853 | 853 | 'status' => array( |
854 | - 'description' => __( 'Status of the review.', 'woocommerce' ), |
|
854 | + 'description' => __('Status of the review.', 'woocommerce'), |
|
855 | 855 | 'type' => 'string', |
856 | 856 | 'default' => 'approved', |
857 | - 'enum' => array( 'approved', 'hold', 'spam', 'unspam', 'trash', 'untrash' ), |
|
858 | - 'context' => array( 'view', 'edit' ), |
|
857 | + 'enum' => array('approved', 'hold', 'spam', 'unspam', 'trash', 'untrash'), |
|
858 | + 'context' => array('view', 'edit'), |
|
859 | 859 | ), |
860 | 860 | 'reviewer' => array( |
861 | - 'description' => __( 'Reviewer name.', 'woocommerce' ), |
|
861 | + 'description' => __('Reviewer name.', 'woocommerce'), |
|
862 | 862 | 'type' => 'string', |
863 | - 'context' => array( 'view', 'edit' ), |
|
863 | + 'context' => array('view', 'edit'), |
|
864 | 864 | ), |
865 | 865 | 'reviewer_email' => array( |
866 | - 'description' => __( 'Reviewer email.', 'woocommerce' ), |
|
866 | + 'description' => __('Reviewer email.', 'woocommerce'), |
|
867 | 867 | 'type' => 'string', |
868 | 868 | 'format' => 'email', |
869 | - 'context' => array( 'view', 'edit' ), |
|
869 | + 'context' => array('view', 'edit'), |
|
870 | 870 | ), |
871 | 871 | 'review' => array( |
872 | - 'description' => __( 'The content of the review.', 'woocommerce' ), |
|
872 | + 'description' => __('The content of the review.', 'woocommerce'), |
|
873 | 873 | 'type' => 'string', |
874 | - 'context' => array( 'view', 'edit' ), |
|
874 | + 'context' => array('view', 'edit'), |
|
875 | 875 | 'arg_options' => array( |
876 | 876 | 'sanitize_callback' => 'wp_filter_post_kses', |
877 | 877 | ), |
878 | 878 | ), |
879 | 879 | 'rating' => array( |
880 | - 'description' => __( 'Review rating (0 to 5).', 'woocommerce' ), |
|
880 | + 'description' => __('Review rating (0 to 5).', 'woocommerce'), |
|
881 | 881 | 'type' => 'integer', |
882 | - 'context' => array( 'view', 'edit' ), |
|
882 | + 'context' => array('view', 'edit'), |
|
883 | 883 | ), |
884 | 884 | 'verified' => array( |
885 | - 'description' => __( 'Shows if the reviewer bought the product or not.', 'woocommerce' ), |
|
885 | + 'description' => __('Shows if the reviewer bought the product or not.', 'woocommerce'), |
|
886 | 886 | 'type' => 'boolean', |
887 | - 'context' => array( 'view', 'edit' ), |
|
887 | + 'context' => array('view', 'edit'), |
|
888 | 888 | 'readonly' => true, |
889 | 889 | ), |
890 | 890 | ), |
891 | 891 | ); |
892 | 892 | |
893 | - if ( get_option( 'show_avatars' ) ) { |
|
893 | + if (get_option('show_avatars')) { |
|
894 | 894 | $avatar_properties = array(); |
895 | 895 | $avatar_sizes = rest_get_avatar_sizes(); |
896 | 896 | |
897 | - foreach ( $avatar_sizes as $size ) { |
|
898 | - $avatar_properties[ $size ] = array( |
|
897 | + foreach ($avatar_sizes as $size) { |
|
898 | + $avatar_properties[$size] = array( |
|
899 | 899 | /* translators: %d: avatar image size in pixels */ |
900 | - 'description' => sprintf( __( 'Avatar URL with image size of %d pixels.', 'woocommerce' ), $size ), |
|
900 | + 'description' => sprintf(__('Avatar URL with image size of %d pixels.', 'woocommerce'), $size), |
|
901 | 901 | 'type' => 'string', |
902 | 902 | 'format' => 'uri', |
903 | - 'context' => array( 'embed', 'view', 'edit' ), |
|
903 | + 'context' => array('embed', 'view', 'edit'), |
|
904 | 904 | ); |
905 | 905 | } |
906 | 906 | $schema['properties']['reviewer_avatar_urls'] = array( |
907 | - 'description' => __( 'Avatar URLs for the object reviewer.', 'woocommerce' ), |
|
907 | + 'description' => __('Avatar URLs for the object reviewer.', 'woocommerce'), |
|
908 | 908 | 'type' => 'object', |
909 | - 'context' => array( 'view', 'edit' ), |
|
909 | + 'context' => array('view', 'edit'), |
|
910 | 910 | 'readonly' => true, |
911 | 911 | 'properties' => $avatar_properties, |
912 | 912 | ); |
913 | 913 | } |
914 | 914 | |
915 | - return $this->add_additional_fields_schema( $schema ); |
|
915 | + return $this->add_additional_fields_schema($schema); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | /** |
@@ -925,38 +925,38 @@ discard block |
||
925 | 925 | |
926 | 926 | $params['context']['default'] = 'view'; |
927 | 927 | |
928 | - $params['after'] = array( |
|
929 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
928 | + $params['after'] = array( |
|
929 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
930 | 930 | 'type' => 'string', |
931 | 931 | 'format' => 'date-time', |
932 | 932 | ); |
933 | - $params['before'] = array( |
|
934 | - 'description' => __( 'Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
933 | + $params['before'] = array( |
|
934 | + 'description' => __('Limit response to reviews published before a given ISO8601 compliant date.', 'woocommerce'), |
|
935 | 935 | 'type' => 'string', |
936 | 936 | 'format' => 'date-time', |
937 | 937 | ); |
938 | - $params['exclude'] = array( |
|
939 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
938 | + $params['exclude'] = array( |
|
939 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
940 | 940 | 'type' => 'array', |
941 | 941 | 'items' => array( |
942 | 942 | 'type' => 'integer', |
943 | 943 | ), |
944 | 944 | 'default' => array(), |
945 | 945 | ); |
946 | - $params['include'] = array( |
|
947 | - 'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ), |
|
946 | + $params['include'] = array( |
|
947 | + 'description' => __('Limit result set to specific IDs.', 'woocommerce'), |
|
948 | 948 | 'type' => 'array', |
949 | 949 | 'items' => array( |
950 | 950 | 'type' => 'integer', |
951 | 951 | ), |
952 | 952 | 'default' => array(), |
953 | 953 | ); |
954 | - $params['offset'] = array( |
|
955 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
954 | + $params['offset'] = array( |
|
955 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
956 | 956 | 'type' => 'integer', |
957 | 957 | ); |
958 | - $params['order'] = array( |
|
959 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
958 | + $params['order'] = array( |
|
959 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
960 | 960 | 'type' => 'string', |
961 | 961 | 'default' => 'desc', |
962 | 962 | 'enum' => array( |
@@ -964,8 +964,8 @@ discard block |
||
964 | 964 | 'desc', |
965 | 965 | ), |
966 | 966 | ); |
967 | - $params['orderby'] = array( |
|
968 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
967 | + $params['orderby'] = array( |
|
968 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
969 | 969 | 'type' => 'string', |
970 | 970 | 'default' => 'date_gmt', |
971 | 971 | 'enum' => array( |
@@ -976,37 +976,37 @@ discard block |
||
976 | 976 | 'product', |
977 | 977 | ), |
978 | 978 | ); |
979 | - $params['reviewer'] = array( |
|
980 | - 'description' => __( 'Limit result set to reviews assigned to specific user IDs.', 'woocommerce' ), |
|
979 | + $params['reviewer'] = array( |
|
980 | + 'description' => __('Limit result set to reviews assigned to specific user IDs.', 'woocommerce'), |
|
981 | 981 | 'type' => 'array', |
982 | 982 | 'items' => array( |
983 | 983 | 'type' => 'integer', |
984 | 984 | ), |
985 | 985 | ); |
986 | 986 | $params['reviewer_exclude'] = array( |
987 | - 'description' => __( 'Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce' ), |
|
987 | + 'description' => __('Ensure result set excludes reviews assigned to specific user IDs.', 'woocommerce'), |
|
988 | 988 | 'type' => 'array', |
989 | 989 | 'items' => array( |
990 | 990 | 'type' => 'integer', |
991 | 991 | ), |
992 | 992 | ); |
993 | - $params['reviewer_email'] = array( |
|
993 | + $params['reviewer_email'] = array( |
|
994 | 994 | 'default' => null, |
995 | - 'description' => __( 'Limit result set to that from a specific author email.', 'woocommerce' ), |
|
995 | + 'description' => __('Limit result set to that from a specific author email.', 'woocommerce'), |
|
996 | 996 | 'format' => 'email', |
997 | 997 | 'type' => 'string', |
998 | 998 | ); |
999 | - $params['product'] = array( |
|
999 | + $params['product'] = array( |
|
1000 | 1000 | 'default' => array(), |
1001 | - 'description' => __( 'Limit result set to reviews assigned to specific product IDs.', 'woocommerce' ), |
|
1001 | + 'description' => __('Limit result set to reviews assigned to specific product IDs.', 'woocommerce'), |
|
1002 | 1002 | 'type' => 'array', |
1003 | 1003 | 'items' => array( |
1004 | 1004 | 'type' => 'integer', |
1005 | 1005 | ), |
1006 | 1006 | ); |
1007 | - $params['status'] = array( |
|
1007 | + $params['status'] = array( |
|
1008 | 1008 | 'default' => 'approved', |
1009 | - 'description' => __( 'Limit result set to reviews assigned a specific status.', 'woocommerce' ), |
|
1009 | + 'description' => __('Limit result set to reviews assigned a specific status.', 'woocommerce'), |
|
1010 | 1010 | 'sanitize_callback' => 'sanitize_key', |
1011 | 1011 | 'type' => 'string', |
1012 | 1012 | 'enum' => array( |
@@ -1028,7 +1028,7 @@ discard block |
||
1028 | 1028 | * @since 3.5.0 |
1029 | 1029 | * @param array $params JSON Schema-formatted collection parameters. |
1030 | 1030 | */ |
1031 | - return apply_filters( 'woocommerce_rest_product_review_collection_params', $params ); |
|
1031 | + return apply_filters('woocommerce_rest_product_review_collection_params', $params); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | /** |
@@ -1038,24 +1038,24 @@ discard block |
||
1038 | 1038 | * @param int $id Supplied ID. |
1039 | 1039 | * @return WP_Comment|WP_Error Comment object if ID is valid, WP_Error otherwise. |
1040 | 1040 | */ |
1041 | - protected function get_review( $id ) { |
|
1041 | + protected function get_review($id) { |
|
1042 | 1042 | $id = (int) $id; |
1043 | - $error = new WP_Error( 'woocommerce_rest_review_invalid_id', __( 'Invalid review ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
1043 | + $error = new WP_Error('woocommerce_rest_review_invalid_id', __('Invalid review ID.', 'woocommerce'), array('status' => 404)); |
|
1044 | 1044 | |
1045 | - if ( 0 >= $id ) { |
|
1045 | + if (0 >= $id) { |
|
1046 | 1046 | return $error; |
1047 | 1047 | } |
1048 | 1048 | |
1049 | - $review = get_comment( $id ); |
|
1050 | - if ( empty( $review ) ) { |
|
1049 | + $review = get_comment($id); |
|
1050 | + if (empty($review)) { |
|
1051 | 1051 | return $error; |
1052 | 1052 | } |
1053 | 1053 | |
1054 | - if ( ! empty( $review->comment_post_ID ) ) { |
|
1055 | - $post = get_post( (int) $review->comment_post_ID ); |
|
1054 | + if ( ! empty($review->comment_post_ID)) { |
|
1055 | + $post = get_post((int) $review->comment_post_ID); |
|
1056 | 1056 | |
1057 | - if ( 'product' !== get_post_type( (int) $review->comment_post_ID ) ) { |
|
1058 | - return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
1057 | + if ('product' !== get_post_type((int) $review->comment_post_ID)) { |
|
1058 | + return new WP_Error('woocommerce_rest_product_invalid_id', __('Invalid product ID.', 'woocommerce'), array('status' => 404)); |
|
1059 | 1059 | } |
1060 | 1060 | } |
1061 | 1061 | |
@@ -1069,10 +1069,10 @@ discard block |
||
1069 | 1069 | * @param string $query_param Query parameter. |
1070 | 1070 | * @return string |
1071 | 1071 | */ |
1072 | - protected function normalize_query_param( $query_param ) { |
|
1072 | + protected function normalize_query_param($query_param) { |
|
1073 | 1073 | $prefix = 'comment_'; |
1074 | 1074 | |
1075 | - switch ( $query_param ) { |
|
1075 | + switch ($query_param) { |
|
1076 | 1076 | case 'id': |
1077 | 1077 | $normalized = $prefix . 'ID'; |
1078 | 1078 | break; |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @param string|int $comment_approved comment status. |
1098 | 1098 | * @return string Comment status. |
1099 | 1099 | */ |
1100 | - protected function prepare_status_response( $comment_approved ) { |
|
1101 | - switch ( $comment_approved ) { |
|
1100 | + protected function prepare_status_response($comment_approved) { |
|
1101 | + switch ($comment_approved) { |
|
1102 | 1102 | case 'hold': |
1103 | 1103 | case '0': |
1104 | 1104 | $status = 'hold'; |
@@ -1125,34 +1125,34 @@ discard block |
||
1125 | 1125 | * @param int $id Review ID. |
1126 | 1126 | * @return bool Whether the status was changed. |
1127 | 1127 | */ |
1128 | - protected function handle_status_param( $new_status, $id ) { |
|
1129 | - $old_status = wp_get_comment_status( $id ); |
|
1128 | + protected function handle_status_param($new_status, $id) { |
|
1129 | + $old_status = wp_get_comment_status($id); |
|
1130 | 1130 | |
1131 | - if ( $new_status === $old_status ) { |
|
1131 | + if ($new_status === $old_status) { |
|
1132 | 1132 | return false; |
1133 | 1133 | } |
1134 | 1134 | |
1135 | - switch ( $new_status ) { |
|
1135 | + switch ($new_status) { |
|
1136 | 1136 | case 'approved': |
1137 | 1137 | case 'approve': |
1138 | 1138 | case '1': |
1139 | - $changed = wp_set_comment_status( $id, 'approve' ); |
|
1139 | + $changed = wp_set_comment_status($id, 'approve'); |
|
1140 | 1140 | break; |
1141 | 1141 | case 'hold': |
1142 | 1142 | case '0': |
1143 | - $changed = wp_set_comment_status( $id, 'hold' ); |
|
1143 | + $changed = wp_set_comment_status($id, 'hold'); |
|
1144 | 1144 | break; |
1145 | 1145 | case 'spam': |
1146 | - $changed = wp_spam_comment( $id ); |
|
1146 | + $changed = wp_spam_comment($id); |
|
1147 | 1147 | break; |
1148 | 1148 | case 'unspam': |
1149 | - $changed = wp_unspam_comment( $id ); |
|
1149 | + $changed = wp_unspam_comment($id); |
|
1150 | 1150 | break; |
1151 | 1151 | case 'trash': |
1152 | - $changed = wp_trash_comment( $id ); |
|
1152 | + $changed = wp_trash_comment($id); |
|
1153 | 1153 | break; |
1154 | 1154 | case 'untrash': |
1155 | - $changed = wp_untrash_comment( $id ); |
|
1155 | + $changed = wp_untrash_comment($id); |
|
1156 | 1156 | break; |
1157 | 1157 | default: |
1158 | 1158 | $changed = false; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Settings controller class. |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function register_routes() { |
32 | 32 | parent::register_routes(); |
33 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
33 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
34 | 34 | array( |
35 | 35 | 'methods' => WP_REST_Server::EDITABLE, |
36 | - 'callback' => array( $this, 'batch_items' ), |
|
37 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'batch_items'), |
|
37 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
38 | 38 | ), |
39 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
40 | - ) ); |
|
39 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
40 | + )); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * @param WP_REST_Request $request Full data about the request. |
47 | 47 | * @return WP_Error|bool |
48 | 48 | */ |
49 | - public function update_items_permissions_check( $request ) { |
|
50 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
51 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
49 | + public function update_items_permissions_check($request) { |
|
50 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
51 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | return true; |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | * @param WP_REST_Request $request Request data. |
61 | 61 | * @return WP_Error|WP_REST_Response |
62 | 62 | */ |
63 | - public function update_item( $request ) { |
|
63 | + public function update_item($request) { |
|
64 | 64 | $options_controller = new WC_REST_Setting_Options_Controller(); |
65 | - $response = $options_controller->update_item( $request ); |
|
65 | + $response = $options_controller->update_item($request); |
|
66 | 66 | |
67 | 67 | return $response; |
68 | 68 | } |
@@ -80,33 +80,33 @@ discard block |
||
80 | 80 | 'type' => 'object', |
81 | 81 | 'properties' => array( |
82 | 82 | 'id' => array( |
83 | - 'description' => __( 'A unique identifier that can be used to link settings together.', 'woocommerce' ), |
|
83 | + 'description' => __('A unique identifier that can be used to link settings together.', 'woocommerce'), |
|
84 | 84 | 'type' => 'string', |
85 | - 'context' => array( 'view', 'edit' ), |
|
85 | + 'context' => array('view', 'edit'), |
|
86 | 86 | ), |
87 | 87 | 'label' => array( |
88 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
88 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
89 | 89 | 'type' => 'string', |
90 | - 'context' => array( 'view', 'edit' ), |
|
90 | + 'context' => array('view', 'edit'), |
|
91 | 91 | ), |
92 | 92 | 'description' => array( |
93 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
93 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
94 | 94 | 'type' => 'string', |
95 | - 'context' => array( 'view', 'edit' ), |
|
95 | + 'context' => array('view', 'edit'), |
|
96 | 96 | ), |
97 | 97 | 'parent_id' => array( |
98 | - 'description' => __( 'ID of parent grouping.', 'woocommerce' ), |
|
98 | + 'description' => __('ID of parent grouping.', 'woocommerce'), |
|
99 | 99 | 'type' => 'string', |
100 | - 'context' => array( 'view', 'edit' ), |
|
100 | + 'context' => array('view', 'edit'), |
|
101 | 101 | ), |
102 | 102 | 'sub_groups' => array( |
103 | - 'description' => __( 'IDs for settings sub groups.', 'woocommerce' ), |
|
103 | + 'description' => __('IDs for settings sub groups.', 'woocommerce'), |
|
104 | 104 | 'type' => 'string', |
105 | - 'context' => array( 'view', 'edit' ), |
|
105 | + 'context' => array('view', 'edit'), |
|
106 | 106 | ), |
107 | 107 | ), |
108 | 108 | ); |
109 | 109 | |
110 | - return $this->add_additional_fields_schema( $schema ); |
|
110 | + return $this->add_additional_fields_schema($schema); |
|
111 | 111 | } |
112 | 112 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API variations controller class. |
@@ -32,29 +32,29 @@ discard block |
||
32 | 32 | * @param WP_REST_Request $request Request object. |
33 | 33 | * @return WP_REST_Response |
34 | 34 | */ |
35 | - public function prepare_object_for_response( $object, $request ) { |
|
35 | + public function prepare_object_for_response($object, $request) { |
|
36 | 36 | $data = array( |
37 | 37 | 'id' => $object->get_id(), |
38 | - 'date_created' => wc_rest_prepare_date_response( $object->get_date_created(), false ), |
|
39 | - 'date_created_gmt' => wc_rest_prepare_date_response( $object->get_date_created() ), |
|
40 | - 'date_modified' => wc_rest_prepare_date_response( $object->get_date_modified(), false ), |
|
41 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $object->get_date_modified() ), |
|
42 | - 'description' => wc_format_content( $object->get_description() ), |
|
38 | + 'date_created' => wc_rest_prepare_date_response($object->get_date_created(), false), |
|
39 | + 'date_created_gmt' => wc_rest_prepare_date_response($object->get_date_created()), |
|
40 | + 'date_modified' => wc_rest_prepare_date_response($object->get_date_modified(), false), |
|
41 | + 'date_modified_gmt' => wc_rest_prepare_date_response($object->get_date_modified()), |
|
42 | + 'description' => wc_format_content($object->get_description()), |
|
43 | 43 | 'permalink' => $object->get_permalink(), |
44 | 44 | 'sku' => $object->get_sku(), |
45 | 45 | 'price' => $object->get_price(), |
46 | 46 | 'regular_price' => $object->get_regular_price(), |
47 | 47 | 'sale_price' => $object->get_sale_price(), |
48 | - 'date_on_sale_from' => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ), |
|
49 | - 'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ), |
|
50 | - 'date_on_sale_to' => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ), |
|
51 | - 'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ), |
|
48 | + 'date_on_sale_from' => wc_rest_prepare_date_response($object->get_date_on_sale_from(), false), |
|
49 | + 'date_on_sale_from_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_from()), |
|
50 | + 'date_on_sale_to' => wc_rest_prepare_date_response($object->get_date_on_sale_to(), false), |
|
51 | + 'date_on_sale_to_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_to()), |
|
52 | 52 | 'on_sale' => $object->is_on_sale(), |
53 | 53 | 'status' => $object->get_status(), |
54 | 54 | 'purchasable' => $object->is_purchasable(), |
55 | 55 | 'virtual' => $object->is_virtual(), |
56 | 56 | 'downloadable' => $object->is_downloadable(), |
57 | - 'downloads' => $this->get_downloads( $object ), |
|
57 | + 'downloads' => $this->get_downloads($object), |
|
58 | 58 | 'download_limit' => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1, |
59 | 59 | 'download_expiry' => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1, |
60 | 60 | 'tax_status' => $object->get_tax_status(), |
@@ -73,17 +73,17 @@ discard block |
||
73 | 73 | ), |
74 | 74 | 'shipping_class' => $object->get_shipping_class(), |
75 | 75 | 'shipping_class_id' => $object->get_shipping_class_id(), |
76 | - 'image' => $this->get_image( $object ), |
|
77 | - 'attributes' => $this->get_attributes( $object ), |
|
76 | + 'image' => $this->get_image($object), |
|
77 | + 'attributes' => $this->get_attributes($object), |
|
78 | 78 | 'menu_order' => $object->get_menu_order(), |
79 | 79 | 'meta_data' => $object->get_meta_data(), |
80 | 80 | ); |
81 | 81 | |
82 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
83 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
84 | - $data = $this->filter_response_by_context( $data, $context ); |
|
85 | - $response = rest_ensure_response( $data ); |
|
86 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
82 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
83 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
84 | + $data = $this->filter_response_by_context($data, $context); |
|
85 | + $response = rest_ensure_response($data); |
|
86 | + $response->add_links($this->prepare_links($object, $request)); |
|
87 | 87 | |
88 | 88 | /** |
89 | 89 | * Filter the data for a response. |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param WC_Data $object Object data. |
96 | 96 | * @param WP_REST_Request $request Request object. |
97 | 97 | */ |
98 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
98 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -105,136 +105,136 @@ discard block |
||
105 | 105 | * @param bool $creating If is creating a new object. |
106 | 106 | * @return WP_Error|WC_Data |
107 | 107 | */ |
108 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
109 | - if ( isset( $request['id'] ) ) { |
|
110 | - $variation = wc_get_product( absint( $request['id'] ) ); |
|
108 | + protected function prepare_object_for_database($request, $creating = false) { |
|
109 | + if (isset($request['id'])) { |
|
110 | + $variation = wc_get_product(absint($request['id'])); |
|
111 | 111 | } else { |
112 | 112 | $variation = new WC_Product_Variation(); |
113 | 113 | } |
114 | 114 | |
115 | - $variation->set_parent_id( absint( $request['product_id'] ) ); |
|
115 | + $variation->set_parent_id(absint($request['product_id'])); |
|
116 | 116 | |
117 | 117 | // Status. |
118 | - if ( isset( $request['status'] ) ) { |
|
119 | - $variation->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' ); |
|
118 | + if (isset($request['status'])) { |
|
119 | + $variation->set_status(get_post_status_object($request['status']) ? $request['status'] : 'draft'); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | // SKU. |
123 | - if ( isset( $request['sku'] ) ) { |
|
124 | - $variation->set_sku( wc_clean( $request['sku'] ) ); |
|
123 | + if (isset($request['sku'])) { |
|
124 | + $variation->set_sku(wc_clean($request['sku'])); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | // Thumbnail. |
128 | - if ( isset( $request['image'] ) ) { |
|
129 | - if ( is_array( $request['image'] ) ) { |
|
130 | - $variation = $this->set_variation_image( $variation, $request['image'] ); |
|
128 | + if (isset($request['image'])) { |
|
129 | + if (is_array($request['image'])) { |
|
130 | + $variation = $this->set_variation_image($variation, $request['image']); |
|
131 | 131 | } else { |
132 | - $variation->set_image_id( '' ); |
|
132 | + $variation->set_image_id(''); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Virtual variation. |
137 | - if ( isset( $request['virtual'] ) ) { |
|
138 | - $variation->set_virtual( $request['virtual'] ); |
|
137 | + if (isset($request['virtual'])) { |
|
138 | + $variation->set_virtual($request['virtual']); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | // Downloadable variation. |
142 | - if ( isset( $request['downloadable'] ) ) { |
|
143 | - $variation->set_downloadable( $request['downloadable'] ); |
|
142 | + if (isset($request['downloadable'])) { |
|
143 | + $variation->set_downloadable($request['downloadable']); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | // Downloads. |
147 | - if ( $variation->get_downloadable() ) { |
|
147 | + if ($variation->get_downloadable()) { |
|
148 | 148 | // Downloadable files. |
149 | - if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) { |
|
150 | - $variation = $this->save_downloadable_files( $variation, $request['downloads'] ); |
|
149 | + if (isset($request['downloads']) && is_array($request['downloads'])) { |
|
150 | + $variation = $this->save_downloadable_files($variation, $request['downloads']); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Download limit. |
154 | - if ( isset( $request['download_limit'] ) ) { |
|
155 | - $variation->set_download_limit( $request['download_limit'] ); |
|
154 | + if (isset($request['download_limit'])) { |
|
155 | + $variation->set_download_limit($request['download_limit']); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | // Download expiry. |
159 | - if ( isset( $request['download_expiry'] ) ) { |
|
160 | - $variation->set_download_expiry( $request['download_expiry'] ); |
|
159 | + if (isset($request['download_expiry'])) { |
|
160 | + $variation->set_download_expiry($request['download_expiry']); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | 164 | // Shipping data. |
165 | - $variation = $this->save_product_shipping_data( $variation, $request ); |
|
165 | + $variation = $this->save_product_shipping_data($variation, $request); |
|
166 | 166 | |
167 | 167 | // Stock handling. |
168 | - if ( isset( $request['manage_stock'] ) ) { |
|
169 | - $variation->set_manage_stock( $request['manage_stock'] ); |
|
168 | + if (isset($request['manage_stock'])) { |
|
169 | + $variation->set_manage_stock($request['manage_stock']); |
|
170 | 170 | } |
171 | 171 | |
172 | - if ( isset( $request['stock_status'] ) ) { |
|
173 | - $variation->set_stock_status( $request['stock_status'] ); |
|
172 | + if (isset($request['stock_status'])) { |
|
173 | + $variation->set_stock_status($request['stock_status']); |
|
174 | 174 | } |
175 | 175 | |
176 | - if ( isset( $request['backorders'] ) ) { |
|
177 | - $variation->set_backorders( $request['backorders'] ); |
|
176 | + if (isset($request['backorders'])) { |
|
177 | + $variation->set_backorders($request['backorders']); |
|
178 | 178 | } |
179 | 179 | |
180 | - if ( $variation->get_manage_stock() ) { |
|
181 | - if ( isset( $request['stock_quantity'] ) ) { |
|
182 | - $variation->set_stock_quantity( $request['stock_quantity'] ); |
|
183 | - } elseif ( isset( $request['inventory_delta'] ) ) { |
|
184 | - $stock_quantity = wc_stock_amount( $variation->get_stock_quantity() ); |
|
185 | - $stock_quantity += wc_stock_amount( $request['inventory_delta'] ); |
|
186 | - $variation->set_stock_quantity( $stock_quantity ); |
|
180 | + if ($variation->get_manage_stock()) { |
|
181 | + if (isset($request['stock_quantity'])) { |
|
182 | + $variation->set_stock_quantity($request['stock_quantity']); |
|
183 | + } elseif (isset($request['inventory_delta'])) { |
|
184 | + $stock_quantity = wc_stock_amount($variation->get_stock_quantity()); |
|
185 | + $stock_quantity += wc_stock_amount($request['inventory_delta']); |
|
186 | + $variation->set_stock_quantity($stock_quantity); |
|
187 | 187 | } |
188 | 188 | } else { |
189 | - $variation->set_backorders( 'no' ); |
|
190 | - $variation->set_stock_quantity( '' ); |
|
189 | + $variation->set_backorders('no'); |
|
190 | + $variation->set_stock_quantity(''); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // Regular Price. |
194 | - if ( isset( $request['regular_price'] ) ) { |
|
195 | - $variation->set_regular_price( $request['regular_price'] ); |
|
194 | + if (isset($request['regular_price'])) { |
|
195 | + $variation->set_regular_price($request['regular_price']); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | // Sale Price. |
199 | - if ( isset( $request['sale_price'] ) ) { |
|
200 | - $variation->set_sale_price( $request['sale_price'] ); |
|
199 | + if (isset($request['sale_price'])) { |
|
200 | + $variation->set_sale_price($request['sale_price']); |
|
201 | 201 | } |
202 | 202 | |
203 | - if ( isset( $request['date_on_sale_from'] ) ) { |
|
204 | - $variation->set_date_on_sale_from( $request['date_on_sale_from'] ); |
|
203 | + if (isset($request['date_on_sale_from'])) { |
|
204 | + $variation->set_date_on_sale_from($request['date_on_sale_from']); |
|
205 | 205 | } |
206 | 206 | |
207 | - if ( isset( $request['date_on_sale_from_gmt'] ) ) { |
|
208 | - $variation->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null ); |
|
207 | + if (isset($request['date_on_sale_from_gmt'])) { |
|
208 | + $variation->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null); |
|
209 | 209 | } |
210 | 210 | |
211 | - if ( isset( $request['date_on_sale_to'] ) ) { |
|
212 | - $variation->set_date_on_sale_to( $request['date_on_sale_to'] ); |
|
211 | + if (isset($request['date_on_sale_to'])) { |
|
212 | + $variation->set_date_on_sale_to($request['date_on_sale_to']); |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( isset( $request['date_on_sale_to_gmt'] ) ) { |
|
216 | - $variation->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null ); |
|
215 | + if (isset($request['date_on_sale_to_gmt'])) { |
|
216 | + $variation->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | // Tax class. |
220 | - if ( isset( $request['tax_class'] ) ) { |
|
221 | - $variation->set_tax_class( $request['tax_class'] ); |
|
220 | + if (isset($request['tax_class'])) { |
|
221 | + $variation->set_tax_class($request['tax_class']); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | // Description. |
225 | - if ( isset( $request['description'] ) ) { |
|
226 | - $variation->set_description( wp_kses_post( $request['description'] ) ); |
|
225 | + if (isset($request['description'])) { |
|
226 | + $variation->set_description(wp_kses_post($request['description'])); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | // Update taxonomies. |
230 | - if ( isset( $request['attributes'] ) ) { |
|
230 | + if (isset($request['attributes'])) { |
|
231 | 231 | $attributes = array(); |
232 | - $parent = wc_get_product( $variation->get_parent_id() ); |
|
232 | + $parent = wc_get_product($variation->get_parent_id()); |
|
233 | 233 | |
234 | - if ( ! $parent ) { |
|
234 | + if ( ! $parent) { |
|
235 | 235 | return new WP_Error( |
236 | 236 | // Translators: %d parent ID. |
237 | - "woocommerce_rest_{$this->post_type}_invalid_parent", sprintf( __( 'Cannot set attributes due to invalid parent product.', 'woocommerce' ), $variation->get_parent_id() ), array( |
|
237 | + "woocommerce_rest_{$this->post_type}_invalid_parent", sprintf(__('Cannot set attributes due to invalid parent product.', 'woocommerce'), $variation->get_parent_id()), array( |
|
238 | 238 | 'status' => 404, |
239 | 239 | ) |
240 | 240 | ); |
@@ -242,55 +242,55 @@ discard block |
||
242 | 242 | |
243 | 243 | $parent_attributes = $parent->get_attributes(); |
244 | 244 | |
245 | - foreach ( $request['attributes'] as $attribute ) { |
|
245 | + foreach ($request['attributes'] as $attribute) { |
|
246 | 246 | $attribute_id = 0; |
247 | 247 | $attribute_name = ''; |
248 | 248 | |
249 | 249 | // Check ID for global attributes or name for product attributes. |
250 | - if ( ! empty( $attribute['id'] ) ) { |
|
251 | - $attribute_id = absint( $attribute['id'] ); |
|
252 | - $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
|
253 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
254 | - $attribute_name = sanitize_title( $attribute['name'] ); |
|
250 | + if ( ! empty($attribute['id'])) { |
|
251 | + $attribute_id = absint($attribute['id']); |
|
252 | + $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id); |
|
253 | + } elseif ( ! empty($attribute['name'])) { |
|
254 | + $attribute_name = sanitize_title($attribute['name']); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( ! $attribute_id && ! $attribute_name ) { |
|
257 | + if ( ! $attribute_id && ! $attribute_name) { |
|
258 | 258 | continue; |
259 | 259 | } |
260 | 260 | |
261 | - if ( ! isset( $parent_attributes[ $attribute_name ] ) || ! $parent_attributes[ $attribute_name ]->get_variation() ) { |
|
261 | + if ( ! isset($parent_attributes[$attribute_name]) || ! $parent_attributes[$attribute_name]->get_variation()) { |
|
262 | 262 | continue; |
263 | 263 | } |
264 | 264 | |
265 | - $attribute_key = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() ); |
|
266 | - $attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
265 | + $attribute_key = sanitize_title($parent_attributes[$attribute_name]->get_name()); |
|
266 | + $attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : ''; |
|
267 | 267 | |
268 | - if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) { |
|
268 | + if ($parent_attributes[$attribute_name]->is_taxonomy()) { |
|
269 | 269 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
270 | - $term = get_term_by( 'name', $attribute_value, $attribute_name ); |
|
270 | + $term = get_term_by('name', $attribute_value, $attribute_name); |
|
271 | 271 | |
272 | - if ( $term && ! is_wp_error( $term ) ) { |
|
272 | + if ($term && ! is_wp_error($term)) { |
|
273 | 273 | $attribute_value = $term->slug; |
274 | 274 | } else { |
275 | - $attribute_value = sanitize_title( $attribute_value ); |
|
275 | + $attribute_value = sanitize_title($attribute_value); |
|
276 | 276 | } |
277 | 277 | } |
278 | 278 | |
279 | - $attributes[ $attribute_key ] = $attribute_value; |
|
279 | + $attributes[$attribute_key] = $attribute_value; |
|
280 | 280 | } |
281 | 281 | |
282 | - $variation->set_attributes( $attributes ); |
|
282 | + $variation->set_attributes($attributes); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | // Menu order. |
286 | - if ( $request['menu_order'] ) { |
|
287 | - $variation->set_menu_order( $request['menu_order'] ); |
|
286 | + if ($request['menu_order']) { |
|
287 | + $variation->set_menu_order($request['menu_order']); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | // Meta data. |
291 | - if ( is_array( $request['meta_data'] ) ) { |
|
292 | - foreach ( $request['meta_data'] as $meta ) { |
|
293 | - $variation->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
291 | + if (is_array($request['meta_data'])) { |
|
292 | + foreach ($request['meta_data'] as $meta) { |
|
293 | + $variation->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | * @param WP_REST_Request $request Request object. |
305 | 305 | * @param bool $creating If is creating a new object. |
306 | 306 | */ |
307 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating ); |
|
307 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -313,32 +313,32 @@ discard block |
||
313 | 313 | * @param WC_Product_Variation $variation Variation data. |
314 | 314 | * @return array |
315 | 315 | */ |
316 | - protected function get_image( $variation ) { |
|
317 | - if ( ! $variation->get_image_id() ) { |
|
316 | + protected function get_image($variation) { |
|
317 | + if ( ! $variation->get_image_id()) { |
|
318 | 318 | return; |
319 | 319 | } |
320 | 320 | |
321 | 321 | $attachment_id = $variation->get_image_id(); |
322 | - $attachment_post = get_post( $attachment_id ); |
|
323 | - if ( is_null( $attachment_post ) ) { |
|
322 | + $attachment_post = get_post($attachment_id); |
|
323 | + if (is_null($attachment_post)) { |
|
324 | 324 | return; |
325 | 325 | } |
326 | 326 | |
327 | - $attachment = wp_get_attachment_image_src( $attachment_id, 'full' ); |
|
328 | - if ( ! is_array( $attachment ) ) { |
|
327 | + $attachment = wp_get_attachment_image_src($attachment_id, 'full'); |
|
328 | + if ( ! is_array($attachment)) { |
|
329 | 329 | return; |
330 | 330 | } |
331 | 331 | |
332 | - if ( ! isset( $image ) ) { |
|
332 | + if ( ! isset($image)) { |
|
333 | 333 | return array( |
334 | 334 | 'id' => (int) $attachment_id, |
335 | - 'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date, false ), |
|
336 | - 'date_created_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ), |
|
337 | - 'date_modified' => wc_rest_prepare_date_response( $attachment_post->post_modified, false ), |
|
338 | - 'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ), |
|
339 | - 'src' => current( $attachment ), |
|
340 | - 'name' => get_the_title( $attachment_id ), |
|
341 | - 'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ), |
|
335 | + 'date_created' => wc_rest_prepare_date_response($attachment_post->post_date, false), |
|
336 | + 'date_created_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_date_gmt)), |
|
337 | + 'date_modified' => wc_rest_prepare_date_response($attachment_post->post_modified, false), |
|
338 | + 'date_modified_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_modified_gmt)), |
|
339 | + 'src' => current($attachment), |
|
340 | + 'name' => get_the_title($attachment_id), |
|
341 | + 'alt' => get_post_meta($attachment_id, '_wp_attachment_image_alt', true), |
|
342 | 342 | ); |
343 | 343 | } |
344 | 344 | } |
@@ -351,35 +351,35 @@ discard block |
||
351 | 351 | * @param array $image Image data. |
352 | 352 | * @return WC_Product_Variation |
353 | 353 | */ |
354 | - protected function set_variation_image( $variation, $image ) { |
|
355 | - $attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0; |
|
354 | + protected function set_variation_image($variation, $image) { |
|
355 | + $attachment_id = isset($image['id']) ? absint($image['id']) : 0; |
|
356 | 356 | |
357 | - if ( 0 === $attachment_id && isset( $image['src'] ) ) { |
|
358 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) ); |
|
357 | + if (0 === $attachment_id && isset($image['src'])) { |
|
358 | + $upload = wc_rest_upload_image_from_url(esc_url_raw($image['src'])); |
|
359 | 359 | |
360 | - if ( is_wp_error( $upload ) ) { |
|
361 | - if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array( $image ) ) ) { |
|
362 | - throw new WC_REST_Exception( 'woocommerce_variation_image_upload_error', $upload->get_error_message(), 400 ); |
|
360 | + if (is_wp_error($upload)) { |
|
361 | + if ( ! apply_filters('woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array($image))) { |
|
362 | + throw new WC_REST_Exception('woocommerce_variation_image_upload_error', $upload->get_error_message(), 400); |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | |
366 | - $attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $variation->get_id() ); |
|
366 | + $attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $variation->get_id()); |
|
367 | 367 | } |
368 | 368 | |
369 | - if ( ! wp_attachment_is_image( $attachment_id ) ) { |
|
369 | + if ( ! wp_attachment_is_image($attachment_id)) { |
|
370 | 370 | /* translators: %s: attachment ID */ |
371 | - throw new WC_REST_Exception( 'woocommerce_variation_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 ); |
|
371 | + throw new WC_REST_Exception('woocommerce_variation_invalid_image_id', sprintf(__('#%s is an invalid image ID.', 'woocommerce'), $attachment_id), 400); |
|
372 | 372 | } |
373 | 373 | |
374 | - $variation->set_image_id( $attachment_id ); |
|
374 | + $variation->set_image_id($attachment_id); |
|
375 | 375 | |
376 | 376 | // Set the image alt if present. |
377 | - if ( ! empty( $image['alt'] ) ) { |
|
378 | - update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) ); |
|
377 | + if ( ! empty($image['alt'])) { |
|
378 | + update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt'])); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | // Set the image name if present. |
382 | - if ( ! empty( $image['name'] ) ) { |
|
382 | + if ( ! empty($image['name'])) { |
|
383 | 383 | wp_update_post( |
384 | 384 | array( |
385 | 385 | 'ID' => $attachment_id, |
@@ -397,354 +397,354 @@ discard block |
||
397 | 397 | * @return array |
398 | 398 | */ |
399 | 399 | public function get_item_schema() { |
400 | - $weight_unit = get_option( 'woocommerce_weight_unit' ); |
|
401 | - $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
|
400 | + $weight_unit = get_option('woocommerce_weight_unit'); |
|
401 | + $dimension_unit = get_option('woocommerce_dimension_unit'); |
|
402 | 402 | $schema = array( |
403 | 403 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
404 | 404 | 'title' => $this->post_type, |
405 | 405 | 'type' => 'object', |
406 | 406 | 'properties' => array( |
407 | 407 | 'id' => array( |
408 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
408 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
409 | 409 | 'type' => 'integer', |
410 | - 'context' => array( 'view', 'edit' ), |
|
410 | + 'context' => array('view', 'edit'), |
|
411 | 411 | 'readonly' => true, |
412 | 412 | ), |
413 | 413 | 'date_created' => array( |
414 | - 'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ), |
|
414 | + 'description' => __("The date the variation was created, in the site's timezone.", 'woocommerce'), |
|
415 | 415 | 'type' => 'date-time', |
416 | - 'context' => array( 'view', 'edit' ), |
|
416 | + 'context' => array('view', 'edit'), |
|
417 | 417 | 'readonly' => true, |
418 | 418 | ), |
419 | 419 | 'date_modified' => array( |
420 | - 'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ), |
|
420 | + 'description' => __("The date the variation was last modified, in the site's timezone.", 'woocommerce'), |
|
421 | 421 | 'type' => 'date-time', |
422 | - 'context' => array( 'view', 'edit' ), |
|
422 | + 'context' => array('view', 'edit'), |
|
423 | 423 | 'readonly' => true, |
424 | 424 | ), |
425 | 425 | 'description' => array( |
426 | - 'description' => __( 'Variation description.', 'woocommerce' ), |
|
426 | + 'description' => __('Variation description.', 'woocommerce'), |
|
427 | 427 | 'type' => 'string', |
428 | - 'context' => array( 'view', 'edit' ), |
|
428 | + 'context' => array('view', 'edit'), |
|
429 | 429 | ), |
430 | 430 | 'permalink' => array( |
431 | - 'description' => __( 'Variation URL.', 'woocommerce' ), |
|
431 | + 'description' => __('Variation URL.', 'woocommerce'), |
|
432 | 432 | 'type' => 'string', |
433 | 433 | 'format' => 'uri', |
434 | - 'context' => array( 'view', 'edit' ), |
|
434 | + 'context' => array('view', 'edit'), |
|
435 | 435 | 'readonly' => true, |
436 | 436 | ), |
437 | 437 | 'sku' => array( |
438 | - 'description' => __( 'Unique identifier.', 'woocommerce' ), |
|
438 | + 'description' => __('Unique identifier.', 'woocommerce'), |
|
439 | 439 | 'type' => 'string', |
440 | - 'context' => array( 'view', 'edit' ), |
|
440 | + 'context' => array('view', 'edit'), |
|
441 | 441 | ), |
442 | 442 | 'price' => array( |
443 | - 'description' => __( 'Current variation price.', 'woocommerce' ), |
|
443 | + 'description' => __('Current variation price.', 'woocommerce'), |
|
444 | 444 | 'type' => 'string', |
445 | - 'context' => array( 'view', 'edit' ), |
|
445 | + 'context' => array('view', 'edit'), |
|
446 | 446 | 'readonly' => true, |
447 | 447 | ), |
448 | 448 | 'regular_price' => array( |
449 | - 'description' => __( 'Variation regular price.', 'woocommerce' ), |
|
449 | + 'description' => __('Variation regular price.', 'woocommerce'), |
|
450 | 450 | 'type' => 'string', |
451 | - 'context' => array( 'view', 'edit' ), |
|
451 | + 'context' => array('view', 'edit'), |
|
452 | 452 | ), |
453 | 453 | 'sale_price' => array( |
454 | - 'description' => __( 'Variation sale price.', 'woocommerce' ), |
|
454 | + 'description' => __('Variation sale price.', 'woocommerce'), |
|
455 | 455 | 'type' => 'string', |
456 | - 'context' => array( 'view', 'edit' ), |
|
456 | + 'context' => array('view', 'edit'), |
|
457 | 457 | ), |
458 | 458 | 'date_on_sale_from' => array( |
459 | - 'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ), |
|
459 | + 'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'), |
|
460 | 460 | 'type' => 'date-time', |
461 | - 'context' => array( 'view', 'edit' ), |
|
461 | + 'context' => array('view', 'edit'), |
|
462 | 462 | ), |
463 | 463 | 'date_on_sale_from_gmt' => array( |
464 | - 'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ), |
|
464 | + 'description' => __('Start date of sale price, as GMT.', 'woocommerce'), |
|
465 | 465 | 'type' => 'date-time', |
466 | - 'context' => array( 'view', 'edit' ), |
|
466 | + 'context' => array('view', 'edit'), |
|
467 | 467 | ), |
468 | 468 | 'date_on_sale_to' => array( |
469 | - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
|
469 | + 'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'), |
|
470 | 470 | 'type' => 'date-time', |
471 | - 'context' => array( 'view', 'edit' ), |
|
471 | + 'context' => array('view', 'edit'), |
|
472 | 472 | ), |
473 | 473 | 'date_on_sale_to_gmt' => array( |
474 | - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
|
474 | + 'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'), |
|
475 | 475 | 'type' => 'date-time', |
476 | - 'context' => array( 'view', 'edit' ), |
|
476 | + 'context' => array('view', 'edit'), |
|
477 | 477 | ), |
478 | 478 | 'on_sale' => array( |
479 | - 'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ), |
|
479 | + 'description' => __('Shows if the variation is on sale.', 'woocommerce'), |
|
480 | 480 | 'type' => 'boolean', |
481 | - 'context' => array( 'view', 'edit' ), |
|
481 | + 'context' => array('view', 'edit'), |
|
482 | 482 | 'readonly' => true, |
483 | 483 | ), |
484 | 484 | 'status' => array( |
485 | - 'description' => __( 'Variation status.', 'woocommerce' ), |
|
485 | + 'description' => __('Variation status.', 'woocommerce'), |
|
486 | 486 | 'type' => 'string', |
487 | 487 | 'default' => 'publish', |
488 | - 'enum' => array_keys( get_post_statuses() ), |
|
489 | - 'context' => array( 'view', 'edit' ), |
|
488 | + 'enum' => array_keys(get_post_statuses()), |
|
489 | + 'context' => array('view', 'edit'), |
|
490 | 490 | ), |
491 | 491 | 'purchasable' => array( |
492 | - 'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ), |
|
492 | + 'description' => __('Shows if the variation can be bought.', 'woocommerce'), |
|
493 | 493 | 'type' => 'boolean', |
494 | - 'context' => array( 'view', 'edit' ), |
|
494 | + 'context' => array('view', 'edit'), |
|
495 | 495 | 'readonly' => true, |
496 | 496 | ), |
497 | 497 | 'virtual' => array( |
498 | - 'description' => __( 'If the variation is virtual.', 'woocommerce' ), |
|
498 | + 'description' => __('If the variation is virtual.', 'woocommerce'), |
|
499 | 499 | 'type' => 'boolean', |
500 | 500 | 'default' => false, |
501 | - 'context' => array( 'view', 'edit' ), |
|
501 | + 'context' => array('view', 'edit'), |
|
502 | 502 | ), |
503 | 503 | 'downloadable' => array( |
504 | - 'description' => __( 'If the variation is downloadable.', 'woocommerce' ), |
|
504 | + 'description' => __('If the variation is downloadable.', 'woocommerce'), |
|
505 | 505 | 'type' => 'boolean', |
506 | 506 | 'default' => false, |
507 | - 'context' => array( 'view', 'edit' ), |
|
507 | + 'context' => array('view', 'edit'), |
|
508 | 508 | ), |
509 | 509 | 'downloads' => array( |
510 | - 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
|
510 | + 'description' => __('List of downloadable files.', 'woocommerce'), |
|
511 | 511 | 'type' => 'array', |
512 | - 'context' => array( 'view', 'edit' ), |
|
512 | + 'context' => array('view', 'edit'), |
|
513 | 513 | 'items' => array( |
514 | 514 | 'type' => 'object', |
515 | 515 | 'properties' => array( |
516 | 516 | 'id' => array( |
517 | - 'description' => __( 'File ID.', 'woocommerce' ), |
|
517 | + 'description' => __('File ID.', 'woocommerce'), |
|
518 | 518 | 'type' => 'string', |
519 | - 'context' => array( 'view', 'edit' ), |
|
519 | + 'context' => array('view', 'edit'), |
|
520 | 520 | ), |
521 | 521 | 'name' => array( |
522 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
522 | + 'description' => __('File name.', 'woocommerce'), |
|
523 | 523 | 'type' => 'string', |
524 | - 'context' => array( 'view', 'edit' ), |
|
524 | + 'context' => array('view', 'edit'), |
|
525 | 525 | ), |
526 | 526 | 'file' => array( |
527 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
527 | + 'description' => __('File URL.', 'woocommerce'), |
|
528 | 528 | 'type' => 'string', |
529 | - 'context' => array( 'view', 'edit' ), |
|
529 | + 'context' => array('view', 'edit'), |
|
530 | 530 | ), |
531 | 531 | ), |
532 | 532 | ), |
533 | 533 | ), |
534 | 534 | 'download_limit' => array( |
535 | - 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
|
535 | + 'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'), |
|
536 | 536 | 'type' => 'integer', |
537 | 537 | 'default' => -1, |
538 | - 'context' => array( 'view', 'edit' ), |
|
538 | + 'context' => array('view', 'edit'), |
|
539 | 539 | ), |
540 | 540 | 'download_expiry' => array( |
541 | - 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
|
541 | + 'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'), |
|
542 | 542 | 'type' => 'integer', |
543 | 543 | 'default' => -1, |
544 | - 'context' => array( 'view', 'edit' ), |
|
544 | + 'context' => array('view', 'edit'), |
|
545 | 545 | ), |
546 | 546 | 'tax_status' => array( |
547 | - 'description' => __( 'Tax status.', 'woocommerce' ), |
|
547 | + 'description' => __('Tax status.', 'woocommerce'), |
|
548 | 548 | 'type' => 'string', |
549 | 549 | 'default' => 'taxable', |
550 | - 'enum' => array( 'taxable', 'shipping', 'none' ), |
|
551 | - 'context' => array( 'view', 'edit' ), |
|
550 | + 'enum' => array('taxable', 'shipping', 'none'), |
|
551 | + 'context' => array('view', 'edit'), |
|
552 | 552 | ), |
553 | 553 | 'tax_class' => array( |
554 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
554 | + 'description' => __('Tax class.', 'woocommerce'), |
|
555 | 555 | 'type' => 'string', |
556 | - 'context' => array( 'view', 'edit' ), |
|
556 | + 'context' => array('view', 'edit'), |
|
557 | 557 | ), |
558 | 558 | 'manage_stock' => array( |
559 | - 'description' => __( 'Stock management at variation level.', 'woocommerce' ), |
|
559 | + 'description' => __('Stock management at variation level.', 'woocommerce'), |
|
560 | 560 | 'type' => 'boolean', |
561 | 561 | 'default' => false, |
562 | - 'context' => array( 'view', 'edit' ), |
|
562 | + 'context' => array('view', 'edit'), |
|
563 | 563 | ), |
564 | 564 | 'stock_quantity' => array( |
565 | - 'description' => __( 'Stock quantity.', 'woocommerce' ), |
|
565 | + 'description' => __('Stock quantity.', 'woocommerce'), |
|
566 | 566 | 'type' => 'integer', |
567 | - 'context' => array( 'view', 'edit' ), |
|
567 | + 'context' => array('view', 'edit'), |
|
568 | 568 | ), |
569 | 569 | 'stock_status' => array( |
570 | - 'description' => __( 'Controls the stock status of the product.', 'woocommerce' ), |
|
570 | + 'description' => __('Controls the stock status of the product.', 'woocommerce'), |
|
571 | 571 | 'type' => 'string', |
572 | 572 | 'default' => 'instock', |
573 | - 'enum' => array_keys( wc_get_product_stock_status_options() ), |
|
574 | - 'context' => array( 'view', 'edit' ), |
|
573 | + 'enum' => array_keys(wc_get_product_stock_status_options()), |
|
574 | + 'context' => array('view', 'edit'), |
|
575 | 575 | ), |
576 | 576 | 'backorders' => array( |
577 | - 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
|
577 | + 'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'), |
|
578 | 578 | 'type' => 'string', |
579 | 579 | 'default' => 'no', |
580 | - 'enum' => array( 'no', 'notify', 'yes' ), |
|
581 | - 'context' => array( 'view', 'edit' ), |
|
580 | + 'enum' => array('no', 'notify', 'yes'), |
|
581 | + 'context' => array('view', 'edit'), |
|
582 | 582 | ), |
583 | 583 | 'backorders_allowed' => array( |
584 | - 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
|
584 | + 'description' => __('Shows if backorders are allowed.', 'woocommerce'), |
|
585 | 585 | 'type' => 'boolean', |
586 | - 'context' => array( 'view', 'edit' ), |
|
586 | + 'context' => array('view', 'edit'), |
|
587 | 587 | 'readonly' => true, |
588 | 588 | ), |
589 | 589 | 'backordered' => array( |
590 | - 'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ), |
|
590 | + 'description' => __('Shows if the variation is on backordered.', 'woocommerce'), |
|
591 | 591 | 'type' => 'boolean', |
592 | - 'context' => array( 'view', 'edit' ), |
|
592 | + 'context' => array('view', 'edit'), |
|
593 | 593 | 'readonly' => true, |
594 | 594 | ), |
595 | 595 | 'weight' => array( |
596 | 596 | /* translators: %s: weight unit */ |
597 | - 'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ), |
|
597 | + 'description' => sprintf(__('Variation weight (%s).', 'woocommerce'), $weight_unit), |
|
598 | 598 | 'type' => 'string', |
599 | - 'context' => array( 'view', 'edit' ), |
|
599 | + 'context' => array('view', 'edit'), |
|
600 | 600 | ), |
601 | 601 | 'dimensions' => array( |
602 | - 'description' => __( 'Variation dimensions.', 'woocommerce' ), |
|
602 | + 'description' => __('Variation dimensions.', 'woocommerce'), |
|
603 | 603 | 'type' => 'object', |
604 | - 'context' => array( 'view', 'edit' ), |
|
604 | + 'context' => array('view', 'edit'), |
|
605 | 605 | 'properties' => array( |
606 | 606 | 'length' => array( |
607 | 607 | /* translators: %s: dimension unit */ |
608 | - 'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ), |
|
608 | + 'description' => sprintf(__('Variation length (%s).', 'woocommerce'), $dimension_unit), |
|
609 | 609 | 'type' => 'string', |
610 | - 'context' => array( 'view', 'edit' ), |
|
610 | + 'context' => array('view', 'edit'), |
|
611 | 611 | ), |
612 | 612 | 'width' => array( |
613 | 613 | /* translators: %s: dimension unit */ |
614 | - 'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ), |
|
614 | + 'description' => sprintf(__('Variation width (%s).', 'woocommerce'), $dimension_unit), |
|
615 | 615 | 'type' => 'string', |
616 | - 'context' => array( 'view', 'edit' ), |
|
616 | + 'context' => array('view', 'edit'), |
|
617 | 617 | ), |
618 | 618 | 'height' => array( |
619 | 619 | /* translators: %s: dimension unit */ |
620 | - 'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ), |
|
620 | + 'description' => sprintf(__('Variation height (%s).', 'woocommerce'), $dimension_unit), |
|
621 | 621 | 'type' => 'string', |
622 | - 'context' => array( 'view', 'edit' ), |
|
622 | + 'context' => array('view', 'edit'), |
|
623 | 623 | ), |
624 | 624 | ), |
625 | 625 | ), |
626 | 626 | 'shipping_class' => array( |
627 | - 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
|
627 | + 'description' => __('Shipping class slug.', 'woocommerce'), |
|
628 | 628 | 'type' => 'string', |
629 | - 'context' => array( 'view', 'edit' ), |
|
629 | + 'context' => array('view', 'edit'), |
|
630 | 630 | ), |
631 | 631 | 'shipping_class_id' => array( |
632 | - 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
|
632 | + 'description' => __('Shipping class ID.', 'woocommerce'), |
|
633 | 633 | 'type' => 'string', |
634 | - 'context' => array( 'view', 'edit' ), |
|
634 | + 'context' => array('view', 'edit'), |
|
635 | 635 | 'readonly' => true, |
636 | 636 | ), |
637 | 637 | 'image' => array( |
638 | - 'description' => __( 'Variation image data.', 'woocommerce' ), |
|
638 | + 'description' => __('Variation image data.', 'woocommerce'), |
|
639 | 639 | 'type' => 'object', |
640 | - 'context' => array( 'view', 'edit' ), |
|
640 | + 'context' => array('view', 'edit'), |
|
641 | 641 | 'properties' => array( |
642 | 642 | 'id' => array( |
643 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
643 | + 'description' => __('Image ID.', 'woocommerce'), |
|
644 | 644 | 'type' => 'integer', |
645 | - 'context' => array( 'view', 'edit' ), |
|
645 | + 'context' => array('view', 'edit'), |
|
646 | 646 | ), |
647 | 647 | 'date_created' => array( |
648 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
648 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
649 | 649 | 'type' => 'date-time', |
650 | - 'context' => array( 'view', 'edit' ), |
|
650 | + 'context' => array('view', 'edit'), |
|
651 | 651 | 'readonly' => true, |
652 | 652 | ), |
653 | 653 | 'date_created_gmt' => array( |
654 | - 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
|
654 | + 'description' => __('The date the image was created, as GMT.', 'woocommerce'), |
|
655 | 655 | 'type' => 'date-time', |
656 | - 'context' => array( 'view', 'edit' ), |
|
656 | + 'context' => array('view', 'edit'), |
|
657 | 657 | 'readonly' => true, |
658 | 658 | ), |
659 | 659 | 'date_modified' => array( |
660 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
660 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
661 | 661 | 'type' => 'date-time', |
662 | - 'context' => array( 'view', 'edit' ), |
|
662 | + 'context' => array('view', 'edit'), |
|
663 | 663 | 'readonly' => true, |
664 | 664 | ), |
665 | 665 | 'date_modified_gmt' => array( |
666 | - 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
|
666 | + 'description' => __('The date the image was last modified, as GMT.', 'woocommerce'), |
|
667 | 667 | 'type' => 'date-time', |
668 | - 'context' => array( 'view', 'edit' ), |
|
668 | + 'context' => array('view', 'edit'), |
|
669 | 669 | 'readonly' => true, |
670 | 670 | ), |
671 | 671 | 'src' => array( |
672 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
672 | + 'description' => __('Image URL.', 'woocommerce'), |
|
673 | 673 | 'type' => 'string', |
674 | 674 | 'format' => 'uri', |
675 | - 'context' => array( 'view', 'edit' ), |
|
675 | + 'context' => array('view', 'edit'), |
|
676 | 676 | ), |
677 | 677 | 'name' => array( |
678 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
678 | + 'description' => __('Image name.', 'woocommerce'), |
|
679 | 679 | 'type' => 'string', |
680 | - 'context' => array( 'view', 'edit' ), |
|
680 | + 'context' => array('view', 'edit'), |
|
681 | 681 | ), |
682 | 682 | 'alt' => array( |
683 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
683 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
684 | 684 | 'type' => 'string', |
685 | - 'context' => array( 'view', 'edit' ), |
|
685 | + 'context' => array('view', 'edit'), |
|
686 | 686 | ), |
687 | 687 | ), |
688 | 688 | ), |
689 | 689 | 'attributes' => array( |
690 | - 'description' => __( 'List of attributes.', 'woocommerce' ), |
|
690 | + 'description' => __('List of attributes.', 'woocommerce'), |
|
691 | 691 | 'type' => 'array', |
692 | - 'context' => array( 'view', 'edit' ), |
|
692 | + 'context' => array('view', 'edit'), |
|
693 | 693 | 'items' => array( |
694 | 694 | 'type' => 'object', |
695 | 695 | 'properties' => array( |
696 | 696 | 'id' => array( |
697 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
697 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
698 | 698 | 'type' => 'integer', |
699 | - 'context' => array( 'view', 'edit' ), |
|
699 | + 'context' => array('view', 'edit'), |
|
700 | 700 | ), |
701 | 701 | 'name' => array( |
702 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
702 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
703 | 703 | 'type' => 'string', |
704 | - 'context' => array( 'view', 'edit' ), |
|
704 | + 'context' => array('view', 'edit'), |
|
705 | 705 | ), |
706 | 706 | 'option' => array( |
707 | - 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
|
707 | + 'description' => __('Selected attribute term name.', 'woocommerce'), |
|
708 | 708 | 'type' => 'string', |
709 | - 'context' => array( 'view', 'edit' ), |
|
709 | + 'context' => array('view', 'edit'), |
|
710 | 710 | ), |
711 | 711 | ), |
712 | 712 | ), |
713 | 713 | ), |
714 | 714 | 'menu_order' => array( |
715 | - 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), |
|
715 | + 'description' => __('Menu order, used to custom sort products.', 'woocommerce'), |
|
716 | 716 | 'type' => 'integer', |
717 | - 'context' => array( 'view', 'edit' ), |
|
717 | + 'context' => array('view', 'edit'), |
|
718 | 718 | ), |
719 | 719 | 'meta_data' => array( |
720 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
720 | + 'description' => __('Meta data.', 'woocommerce'), |
|
721 | 721 | 'type' => 'array', |
722 | - 'context' => array( 'view', 'edit' ), |
|
722 | + 'context' => array('view', 'edit'), |
|
723 | 723 | 'items' => array( |
724 | 724 | 'type' => 'object', |
725 | 725 | 'properties' => array( |
726 | 726 | 'id' => array( |
727 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
727 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
728 | 728 | 'type' => 'integer', |
729 | - 'context' => array( 'view', 'edit' ), |
|
729 | + 'context' => array('view', 'edit'), |
|
730 | 730 | 'readonly' => true, |
731 | 731 | ), |
732 | 732 | 'key' => array( |
733 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
733 | + 'description' => __('Meta key.', 'woocommerce'), |
|
734 | 734 | 'type' => 'string', |
735 | - 'context' => array( 'view', 'edit' ), |
|
735 | + 'context' => array('view', 'edit'), |
|
736 | 736 | ), |
737 | 737 | 'value' => array( |
738 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
738 | + 'description' => __('Meta value.', 'woocommerce'), |
|
739 | 739 | 'type' => 'mixed', |
740 | - 'context' => array( 'view', 'edit' ), |
|
740 | + 'context' => array('view', 'edit'), |
|
741 | 741 | ), |
742 | 742 | ), |
743 | 743 | ), |
744 | 744 | ), |
745 | 745 | ), |
746 | 746 | ); |
747 | - return $this->add_additional_fields_schema( $schema ); |
|
747 | + return $this->add_additional_fields_schema($schema); |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | /** |
@@ -754,17 +754,17 @@ discard block |
||
754 | 754 | * @param WP_REST_Request $request Full details about the request. |
755 | 755 | * @return array |
756 | 756 | */ |
757 | - protected function prepare_objects_query( $request ) { |
|
758 | - $args = WC_REST_CRUD_Controller::prepare_objects_query( $request ); |
|
757 | + protected function prepare_objects_query($request) { |
|
758 | + $args = WC_REST_CRUD_Controller::prepare_objects_query($request); |
|
759 | 759 | |
760 | 760 | // Set post_status. |
761 | 761 | $args['post_status'] = $request['status']; |
762 | 762 | |
763 | 763 | // Filter by sku. |
764 | - if ( ! empty( $request['sku'] ) ) { |
|
765 | - $skus = explode( ',', $request['sku'] ); |
|
764 | + if ( ! empty($request['sku'])) { |
|
765 | + $skus = explode(',', $request['sku']); |
|
766 | 766 | // Include the current string as a SKU too. |
767 | - if ( 1 < count( $skus ) ) { |
|
767 | + if (1 < count($skus)) { |
|
768 | 768 | $skus[] = $request['sku']; |
769 | 769 | } |
770 | 770 | |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | } |
780 | 780 | |
781 | 781 | // Filter by tax class. |
782 | - if ( ! empty( $request['tax_class'] ) ) { |
|
782 | + if ( ! empty($request['tax_class'])) { |
|
783 | 783 | $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
784 | 784 | $args, |
785 | 785 | array( |
@@ -790,12 +790,12 @@ discard block |
||
790 | 790 | } |
791 | 791 | |
792 | 792 | // Price filter. |
793 | - if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) { |
|
794 | - $args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) ); // WPCS: slow query ok. |
|
793 | + if ( ! empty($request['min_price']) || ! empty($request['max_price'])) { |
|
794 | + $args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request)); // WPCS: slow query ok. |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | // Filter product based on stock_status. |
798 | - if ( ! empty( $request['stock_status'] ) ) { |
|
798 | + if ( ! empty($request['stock_status'])) { |
|
799 | 799 | $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
800 | 800 | $args, |
801 | 801 | array( |
@@ -806,19 +806,19 @@ discard block |
||
806 | 806 | } |
807 | 807 | |
808 | 808 | // Filter by on sale products. |
809 | - if ( is_bool( $request['on_sale'] ) ) { |
|
809 | + if (is_bool($request['on_sale'])) { |
|
810 | 810 | $on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in'; |
811 | 811 | $on_sale_ids = wc_get_product_ids_on_sale(); |
812 | 812 | |
813 | 813 | // Use 0 when there's no on sale products to avoid return all products. |
814 | - $on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids; |
|
814 | + $on_sale_ids = empty($on_sale_ids) ? array(0) : $on_sale_ids; |
|
815 | 815 | |
816 | - $args[ $on_sale_key ] += $on_sale_ids; |
|
816 | + $args[$on_sale_key] += $on_sale_ids; |
|
817 | 817 | } |
818 | 818 | |
819 | 819 | // Force the post_type argument, since it's not a user input variable. |
820 | - if ( ! empty( $request['sku'] ) ) { |
|
821 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
820 | + if ( ! empty($request['sku'])) { |
|
821 | + $args['post_type'] = array('product', 'product_variation'); |
|
822 | 822 | } else { |
823 | 823 | $args['post_type'] = $this->post_type; |
824 | 824 | } |
@@ -848,9 +848,9 @@ discard block |
||
848 | 848 | ); |
849 | 849 | |
850 | 850 | $params['stock_status'] = array( |
851 | - 'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce' ), |
|
851 | + 'description' => __('Limit result set to products with specified stock status.', 'woocommerce'), |
|
852 | 852 | 'type' => 'string', |
853 | - 'enum' => array_keys( wc_get_product_stock_status_options() ), |
|
853 | + 'enum' => array_keys(wc_get_product_stock_status_options()), |
|
854 | 854 | 'sanitize_callback' => 'sanitize_text_field', |
855 | 855 | 'validate_callback' => 'rest_validate_request_arg', |
856 | 856 | ); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Order Notes controller class. |
@@ -32,24 +32,24 @@ discard block |
||
32 | 32 | * @param WP_REST_Request $request Request object. |
33 | 33 | * @return WP_REST_Response $response Response data. |
34 | 34 | */ |
35 | - public function prepare_item_for_response( $note, $request ) { |
|
35 | + public function prepare_item_for_response($note, $request) { |
|
36 | 36 | $data = array( |
37 | 37 | 'id' => (int) $note->comment_ID, |
38 | - 'author' => __( 'WooCommerce', 'woocommerce' ) === $note->comment_author ? 'system' : $note->comment_author, |
|
39 | - 'date_created' => wc_rest_prepare_date_response( $note->comment_date ), |
|
40 | - 'date_created_gmt' => wc_rest_prepare_date_response( $note->comment_date_gmt ), |
|
38 | + 'author' => __('WooCommerce', 'woocommerce') === $note->comment_author ? 'system' : $note->comment_author, |
|
39 | + 'date_created' => wc_rest_prepare_date_response($note->comment_date), |
|
40 | + 'date_created_gmt' => wc_rest_prepare_date_response($note->comment_date_gmt), |
|
41 | 41 | 'note' => $note->comment_content, |
42 | - 'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ), |
|
42 | + 'customer_note' => (bool) get_comment_meta($note->comment_ID, 'is_customer_note', true), |
|
43 | 43 | ); |
44 | 44 | |
45 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
46 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
47 | - $data = $this->filter_response_by_context( $data, $context ); |
|
45 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
46 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
47 | + $data = $this->filter_response_by_context($data, $context); |
|
48 | 48 | |
49 | 49 | // Wrap the data in a response object. |
50 | - $response = rest_ensure_response( $data ); |
|
50 | + $response = rest_ensure_response($data); |
|
51 | 51 | |
52 | - $response->add_links( $this->prepare_links( $note ) ); |
|
52 | + $response->add_links($this->prepare_links($note)); |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Filter order note object returned from the REST API. |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param WP_Comment $note Order note object used to create response. |
59 | 59 | * @param WP_REST_Request $request Request object. |
60 | 60 | */ |
61 | - return apply_filters( 'woocommerce_rest_prepare_order_note', $response, $note, $request ); |
|
61 | + return apply_filters('woocommerce_rest_prepare_order_note', $response, $note, $request); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -67,27 +67,27 @@ discard block |
||
67 | 67 | * @param WP_REST_Request $request Full details about the request. |
68 | 68 | * @return WP_Error|WP_REST_Response |
69 | 69 | */ |
70 | - public function create_item( $request ) { |
|
71 | - if ( ! empty( $request['id'] ) ) { |
|
70 | + public function create_item($request) { |
|
71 | + if ( ! empty($request['id'])) { |
|
72 | 72 | /* translators: %s: post type */ |
73 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
73 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
74 | 74 | } |
75 | 75 | |
76 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
76 | + $order = wc_get_order((int) $request['order_id']); |
|
77 | 77 | |
78 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
79 | - return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
78 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
79 | + return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | // Create the note. |
83 | - $note_id = $order->add_order_note( $request['note'], $request['customer_note'], $request['added_by_user'] ); |
|
83 | + $note_id = $order->add_order_note($request['note'], $request['customer_note'], $request['added_by_user']); |
|
84 | 84 | |
85 | - if ( ! $note_id ) { |
|
86 | - return new WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
85 | + if ( ! $note_id) { |
|
86 | + return new WP_Error('woocommerce_api_cannot_create_order_note', __('Cannot create order note, please try again.', 'woocommerce'), array('status' => 500)); |
|
87 | 87 | } |
88 | 88 | |
89 | - $note = get_comment( $note_id ); |
|
90 | - $this->update_additional_fields_for_object( $note, $request ); |
|
89 | + $note = get_comment($note_id); |
|
90 | + $this->update_additional_fields_for_object($note, $request); |
|
91 | 91 | |
92 | 92 | /** |
93 | 93 | * Fires after a order note is created or updated via the REST API. |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | * @param WP_REST_Request $request Request object. |
97 | 97 | * @param boolean $creating True when creating item, false when updating. |
98 | 98 | */ |
99 | - do_action( 'woocommerce_rest_insert_order_note', $note, $request, true ); |
|
99 | + do_action('woocommerce_rest_insert_order_note', $note, $request, true); |
|
100 | 100 | |
101 | - $request->set_param( 'context', 'edit' ); |
|
102 | - $response = $this->prepare_item_for_response( $note, $request ); |
|
103 | - $response = rest_ensure_response( $response ); |
|
104 | - $response->set_status( 201 ); |
|
105 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, str_replace( '(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base ), $note_id ) ) ); |
|
101 | + $request->set_param('context', 'edit'); |
|
102 | + $response = $this->prepare_item_for_response($note, $request); |
|
103 | + $response = rest_ensure_response($response); |
|
104 | + $response->set_status(201); |
|
105 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, str_replace('(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base), $note_id))); |
|
106 | 106 | |
107 | 107 | return $response; |
108 | 108 | } |
@@ -119,49 +119,49 @@ discard block |
||
119 | 119 | 'type' => 'object', |
120 | 120 | 'properties' => array( |
121 | 121 | 'id' => array( |
122 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
122 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
123 | 123 | 'type' => 'integer', |
124 | - 'context' => array( 'view', 'edit' ), |
|
124 | + 'context' => array('view', 'edit'), |
|
125 | 125 | 'readonly' => true, |
126 | 126 | ), |
127 | 127 | 'author' => array( |
128 | - 'description' => __( 'Order note author.', 'woocommerce' ), |
|
128 | + 'description' => __('Order note author.', 'woocommerce'), |
|
129 | 129 | 'type' => 'string', |
130 | - 'context' => array( 'view', 'edit' ), |
|
130 | + 'context' => array('view', 'edit'), |
|
131 | 131 | 'readonly' => true, |
132 | 132 | ), |
133 | 133 | 'date_created' => array( |
134 | - 'description' => __( "The date the order note was created, in the site's timezone.", 'woocommerce' ), |
|
134 | + 'description' => __("The date the order note was created, in the site's timezone.", 'woocommerce'), |
|
135 | 135 | 'type' => 'date-time', |
136 | - 'context' => array( 'view', 'edit' ), |
|
136 | + 'context' => array('view', 'edit'), |
|
137 | 137 | 'readonly' => true, |
138 | 138 | ), |
139 | 139 | 'date_created_gmt' => array( |
140 | - 'description' => __( 'The date the order note was created, as GMT.', 'woocommerce' ), |
|
140 | + 'description' => __('The date the order note was created, as GMT.', 'woocommerce'), |
|
141 | 141 | 'type' => 'date-time', |
142 | - 'context' => array( 'view', 'edit' ), |
|
142 | + 'context' => array('view', 'edit'), |
|
143 | 143 | 'readonly' => true, |
144 | 144 | ), |
145 | 145 | 'note' => array( |
146 | - 'description' => __( 'Order note content.', 'woocommerce' ), |
|
146 | + 'description' => __('Order note content.', 'woocommerce'), |
|
147 | 147 | 'type' => 'string', |
148 | - 'context' => array( 'view', 'edit' ), |
|
148 | + 'context' => array('view', 'edit'), |
|
149 | 149 | ), |
150 | 150 | 'customer_note' => array( |
151 | - 'description' => __( 'If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce' ), |
|
151 | + 'description' => __('If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce'), |
|
152 | 152 | 'type' => 'boolean', |
153 | 153 | 'default' => false, |
154 | - 'context' => array( 'view', 'edit' ), |
|
154 | + 'context' => array('view', 'edit'), |
|
155 | 155 | ), |
156 | 156 | 'added_by_user' => array( |
157 | - 'description' => __( 'If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce' ), |
|
157 | + 'description' => __('If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce'), |
|
158 | 158 | 'type' => 'boolean', |
159 | 159 | 'default' => false, |
160 | - 'context' => array( 'edit' ), |
|
160 | + 'context' => array('edit'), |
|
161 | 161 | ), |
162 | 162 | ), |
163 | 163 | ); |
164 | 164 | |
165 | - return $this->add_additional_fields_schema( $schema ); |
|
165 | + return $this->add_additional_fields_schema($schema); |
|
166 | 166 | } |
167 | 167 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.5.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Reports Customers Totals controller class. |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | $users_count = count_users(); |
43 | 43 | $total_customers = 0; |
44 | 44 | |
45 | - foreach ( $users_count['avail_roles'] as $role => $total ) { |
|
46 | - if ( in_array( $role, array( 'administrator', 'shop_manager' ), true ) ) { |
|
45 | + foreach ($users_count['avail_roles'] as $role => $total) { |
|
46 | + if (in_array($role, array('administrator', 'shop_manager'), true)) { |
|
47 | 47 | continue; |
48 | 48 | } |
49 | 49 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | $customers_query = new WP_User_Query( |
54 | 54 | array( |
55 | - 'role__not_in' => array( 'administrator', 'shop_manager' ), |
|
55 | + 'role__not_in' => array('administrator', 'shop_manager'), |
|
56 | 56 | 'number' => 0, |
57 | 57 | 'fields' => 'ID', |
58 | 58 | 'count_total' => true, |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | $data = array( |
72 | 72 | array( |
73 | 73 | 'slug' => 'paying', |
74 | - 'name' => __( 'Paying customer', 'woocommerce' ), |
|
74 | + 'name' => __('Paying customer', 'woocommerce'), |
|
75 | 75 | 'total' => $total_paying, |
76 | 76 | ), |
77 | 77 | array( |
78 | 78 | 'slug' => 'non_paying', |
79 | - 'name' => __( 'Non-paying customer', 'woocommerce' ), |
|
79 | + 'name' => __('Non-paying customer', 'woocommerce'), |
|
80 | 80 | 'total' => $total_customers - $total_paying, |
81 | 81 | ), |
82 | 82 | ); |
@@ -91,19 +91,19 @@ discard block |
||
91 | 91 | * @param WP_REST_Request $request Request object. |
92 | 92 | * @return WP_REST_Response $response Response data. |
93 | 93 | */ |
94 | - public function prepare_item_for_response( $report, $request ) { |
|
94 | + public function prepare_item_for_response($report, $request) { |
|
95 | 95 | $data = array( |
96 | 96 | 'slug' => $report->slug, |
97 | 97 | 'name' => $report->name, |
98 | 98 | 'total' => $report->total, |
99 | 99 | ); |
100 | 100 | |
101 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
102 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
103 | - $data = $this->filter_response_by_context( $data, $context ); |
|
101 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
102 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
103 | + $data = $this->filter_response_by_context($data, $context); |
|
104 | 104 | |
105 | 105 | // Wrap the data in a response object. |
106 | - $response = rest_ensure_response( $data ); |
|
106 | + $response = rest_ensure_response($data); |
|
107 | 107 | |
108 | 108 | /** |
109 | 109 | * Filter a report returned from the API. |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @param object $report The original report object. |
115 | 115 | * @param WP_REST_Request $request Request used to generate the response. |
116 | 116 | */ |
117 | - return apply_filters( 'woocommerce_rest_prepare_report_customers_count', $response, $report, $request ); |
|
117 | + return apply_filters('woocommerce_rest_prepare_report_customers_count', $response, $report, $request); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -129,26 +129,26 @@ discard block |
||
129 | 129 | 'type' => 'object', |
130 | 130 | 'properties' => array( |
131 | 131 | 'slug' => array( |
132 | - 'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ), |
|
132 | + 'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'), |
|
133 | 133 | 'type' => 'string', |
134 | - 'context' => array( 'view' ), |
|
134 | + 'context' => array('view'), |
|
135 | 135 | 'readonly' => true, |
136 | 136 | ), |
137 | 137 | 'name' => array( |
138 | - 'description' => __( 'Customer type name.', 'woocommerce' ), |
|
138 | + 'description' => __('Customer type name.', 'woocommerce'), |
|
139 | 139 | 'type' => 'string', |
140 | - 'context' => array( 'view' ), |
|
140 | + 'context' => array('view'), |
|
141 | 141 | 'readonly' => true, |
142 | 142 | ), |
143 | 143 | 'total' => array( |
144 | - 'description' => __( 'Amount of customers.', 'woocommerce' ), |
|
144 | + 'description' => __('Amount of customers.', 'woocommerce'), |
|
145 | 145 | 'type' => 'string', |
146 | - 'context' => array( 'view' ), |
|
146 | + 'context' => array('view'), |
|
147 | 147 | 'readonly' => true, |
148 | 148 | ), |
149 | 149 | ), |
150 | 150 | ); |
151 | 151 | |
152 | - return $this->add_additional_fields_schema( $schema ); |
|
152 | + return $this->add_additional_fields_schema($schema); |
|
153 | 153 | } |
154 | 154 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.5.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Reports Products Totals controller class. |
@@ -46,16 +46,16 @@ discard block |
||
46 | 46 | 'hide_empty' => false, |
47 | 47 | ) |
48 | 48 | ); |
49 | - $data = array(); |
|
49 | + $data = array(); |
|
50 | 50 | |
51 | - foreach ( $terms as $product_type ) { |
|
52 | - if ( ! isset( $types[ $product_type->name ] ) ) { |
|
51 | + foreach ($terms as $product_type) { |
|
52 | + if ( ! isset($types[$product_type->name])) { |
|
53 | 53 | continue; |
54 | 54 | } |
55 | 55 | |
56 | 56 | $data[] = array( |
57 | 57 | 'slug' => $product_type->name, |
58 | - 'name' => $types[ $product_type->name ], |
|
58 | + 'name' => $types[$product_type->name], |
|
59 | 59 | 'total' => (int) $product_type->count, |
60 | 60 | ); |
61 | 61 | } |
@@ -70,19 +70,19 @@ discard block |
||
70 | 70 | * @param WP_REST_Request $request Request object. |
71 | 71 | * @return WP_REST_Response $response Response data. |
72 | 72 | */ |
73 | - public function prepare_item_for_response( $report, $request ) { |
|
73 | + public function prepare_item_for_response($report, $request) { |
|
74 | 74 | $data = array( |
75 | 75 | 'slug' => $report->slug, |
76 | 76 | 'name' => $report->name, |
77 | 77 | 'total' => $report->total, |
78 | 78 | ); |
79 | 79 | |
80 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
81 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
82 | - $data = $this->filter_response_by_context( $data, $context ); |
|
80 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
81 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
82 | + $data = $this->filter_response_by_context($data, $context); |
|
83 | 83 | |
84 | 84 | // Wrap the data in a response object. |
85 | - $response = rest_ensure_response( $data ); |
|
85 | + $response = rest_ensure_response($data); |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * Filter a report returned from the API. |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @param object $report The original report object. |
94 | 94 | * @param WP_REST_Request $request Request used to generate the response. |
95 | 95 | */ |
96 | - return apply_filters( 'woocommerce_rest_prepare_report_products_count', $response, $report, $request ); |
|
96 | + return apply_filters('woocommerce_rest_prepare_report_products_count', $response, $report, $request); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -108,26 +108,26 @@ discard block |
||
108 | 108 | 'type' => 'object', |
109 | 109 | 'properties' => array( |
110 | 110 | 'slug' => array( |
111 | - 'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ), |
|
111 | + 'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'), |
|
112 | 112 | 'type' => 'string', |
113 | - 'context' => array( 'view' ), |
|
113 | + 'context' => array('view'), |
|
114 | 114 | 'readonly' => true, |
115 | 115 | ), |
116 | 116 | 'name' => array( |
117 | - 'description' => __( 'Product type name.', 'woocommerce' ), |
|
117 | + 'description' => __('Product type name.', 'woocommerce'), |
|
118 | 118 | 'type' => 'string', |
119 | - 'context' => array( 'view' ), |
|
119 | + 'context' => array('view'), |
|
120 | 120 | 'readonly' => true, |
121 | 121 | ), |
122 | 122 | 'total' => array( |
123 | - 'description' => __( 'Amount of products.', 'woocommerce' ), |
|
123 | + 'description' => __('Amount of products.', 'woocommerce'), |
|
124 | 124 | 'type' => 'string', |
125 | - 'context' => array( 'view' ), |
|
125 | + 'context' => array('view'), |
|
126 | 126 | 'readonly' => true, |
127 | 127 | ), |
128 | 128 | ), |
129 | 129 | ); |
130 | 130 | |
131 | - return $this->add_additional_fields_schema( $schema ); |
|
131 | + return $this->add_additional_fields_schema($schema); |
|
132 | 132 | } |
133 | 133 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Shipping Zones class. |