@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Shipping Zone Methods class. |
@@ -26,31 +26,31 @@ discard block |
||
26 | 26 | array( |
27 | 27 | 'args' => array( |
28 | 28 | 'zone_id' => array( |
29 | - 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), |
|
29 | + 'description' => __('Unique ID for the zone.', 'woocommerce'), |
|
30 | 30 | 'type' => 'integer', |
31 | 31 | ), |
32 | 32 | ), |
33 | 33 | array( |
34 | 34 | 'methods' => \WP_REST_Server::READABLE, |
35 | - 'callback' => array( $this, 'get_items' ), |
|
36 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
35 | + 'callback' => array($this, 'get_items'), |
|
36 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
37 | 37 | ), |
38 | 38 | array( |
39 | 39 | 'methods' => \WP_REST_Server::CREATABLE, |
40 | - 'callback' => array( $this, 'create_item' ), |
|
41 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
40 | + 'callback' => array($this, 'create_item'), |
|
41 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
42 | 42 | 'args' => array_merge( |
43 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
43 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
44 | 44 | array( |
45 | 45 | 'method_id' => array( |
46 | 46 | 'required' => true, |
47 | 47 | 'readonly' => false, |
48 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
48 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
49 | 49 | ), |
50 | 50 | ) |
51 | 51 | ), |
52 | 52 | ), |
53 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
53 | + 'schema' => array($this, 'get_public_item_schema'), |
|
54 | 54 | ), |
55 | 55 | true |
56 | 56 | ); |
@@ -61,38 +61,38 @@ discard block |
||
61 | 61 | array( |
62 | 62 | 'args' => array( |
63 | 63 | 'zone_id' => array( |
64 | - 'description' => __( 'Unique ID for the zone.', 'woocommerce' ), |
|
64 | + 'description' => __('Unique ID for the zone.', 'woocommerce'), |
|
65 | 65 | 'type' => 'integer', |
66 | 66 | ), |
67 | 67 | 'instance_id' => array( |
68 | - 'description' => __( 'Unique ID for the instance.', 'woocommerce' ), |
|
68 | + 'description' => __('Unique ID for the instance.', 'woocommerce'), |
|
69 | 69 | 'type' => 'integer', |
70 | 70 | ), |
71 | 71 | ), |
72 | 72 | array( |
73 | 73 | 'methods' => \WP_REST_Server::READABLE, |
74 | - 'callback' => array( $this, 'get_item' ), |
|
75 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
74 | + 'callback' => array($this, 'get_item'), |
|
75 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
76 | 76 | ), |
77 | 77 | array( |
78 | 78 | 'methods' => \WP_REST_Server::EDITABLE, |
79 | - 'callback' => array( $this, 'update_item' ), |
|
80 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
81 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
79 | + 'callback' => array($this, 'update_item'), |
|
80 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
81 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
82 | 82 | ), |
83 | 83 | array( |
84 | 84 | 'methods' => \WP_REST_Server::DELETABLE, |
85 | - 'callback' => array( $this, 'delete_item' ), |
|
86 | - 'permission_callback' => array( $this, 'delete_items_permissions_check' ), |
|
85 | + 'callback' => array($this, 'delete_item'), |
|
86 | + 'permission_callback' => array($this, 'delete_items_permissions_check'), |
|
87 | 87 | 'args' => array( |
88 | 88 | 'force' => array( |
89 | 89 | 'default' => false, |
90 | 90 | 'type' => 'boolean', |
91 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
91 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
92 | 92 | ), |
93 | 93 | ), |
94 | 94 | ), |
95 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
95 | + 'schema' => array($this, 'get_public_item_schema'), |
|
96 | 96 | ), |
97 | 97 | true |
98 | 98 | ); |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | * @param \WP_REST_Request $request Request data. |
105 | 105 | * @return \WP_REST_Response|\WP_Error |
106 | 106 | */ |
107 | - public function get_item( $request ) { |
|
108 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
107 | + public function get_item($request) { |
|
108 | + $zone = $this->get_zone($request['zone_id']); |
|
109 | 109 | |
110 | - if ( is_wp_error( $zone ) ) { |
|
110 | + if (is_wp_error($zone)) { |
|
111 | 111 | return $zone; |
112 | 112 | } |
113 | 113 | |
@@ -115,20 +115,20 @@ discard block |
||
115 | 115 | $methods = $zone->get_shipping_methods(); |
116 | 116 | $method = false; |
117 | 117 | |
118 | - foreach ( $methods as $method_obj ) { |
|
119 | - if ( $instance_id === $method_obj->instance_id ) { |
|
118 | + foreach ($methods as $method_obj) { |
|
119 | + if ($instance_id === $method_obj->instance_id) { |
|
120 | 120 | $method = $method_obj; |
121 | 121 | break; |
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | - if ( false === $method ) { |
|
126 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
125 | + if (false === $method) { |
|
126 | + return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
127 | 127 | } |
128 | 128 | |
129 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
129 | + $data = $this->prepare_item_for_response($method, $request); |
|
130 | 130 | |
131 | - return rest_ensure_response( $data ); |
|
131 | + return rest_ensure_response($data); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -137,22 +137,22 @@ discard block |
||
137 | 137 | * @param \WP_REST_Request $request Request data. |
138 | 138 | * @return \WP_REST_Response|\WP_Error |
139 | 139 | */ |
140 | - public function get_items( $request ) { |
|
141 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
140 | + public function get_items($request) { |
|
141 | + $zone = $this->get_zone($request['zone_id']); |
|
142 | 142 | |
143 | - if ( is_wp_error( $zone ) ) { |
|
143 | + if (is_wp_error($zone)) { |
|
144 | 144 | return $zone; |
145 | 145 | } |
146 | 146 | |
147 | 147 | $methods = $zone->get_shipping_methods(); |
148 | 148 | $data = array(); |
149 | 149 | |
150 | - foreach ( $methods as $method_obj ) { |
|
151 | - $method = $this->prepare_item_for_response( $method_obj, $request ); |
|
150 | + foreach ($methods as $method_obj) { |
|
151 | + $method = $this->prepare_item_for_response($method_obj, $request); |
|
152 | 152 | $data[] = $method; |
153 | 153 | } |
154 | 154 | |
155 | - return rest_ensure_response( $data ); |
|
155 | + return rest_ensure_response($data); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -161,34 +161,34 @@ discard block |
||
161 | 161 | * @param \WP_REST_Request $request Full details about the request. |
162 | 162 | * @return \WP_REST_Request|\WP_Error |
163 | 163 | */ |
164 | - public function create_item( $request ) { |
|
164 | + public function create_item($request) { |
|
165 | 165 | $method_id = $request['method_id']; |
166 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
167 | - if ( is_wp_error( $zone ) ) { |
|
166 | + $zone = $this->get_zone($request['zone_id']); |
|
167 | + if (is_wp_error($zone)) { |
|
168 | 168 | return $zone; |
169 | 169 | } |
170 | 170 | |
171 | - $instance_id = $zone->add_shipping_method( $method_id ); |
|
171 | + $instance_id = $zone->add_shipping_method($method_id); |
|
172 | 172 | $methods = $zone->get_shipping_methods(); |
173 | 173 | $method = false; |
174 | - foreach ( $methods as $method_obj ) { |
|
175 | - if ( $instance_id === $method_obj->instance_id ) { |
|
174 | + foreach ($methods as $method_obj) { |
|
175 | + if ($instance_id === $method_obj->instance_id) { |
|
176 | 176 | $method = $method_obj; |
177 | 177 | break; |
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - if ( false === $method ) { |
|
182 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( 'Resource cannot be created.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
181 | + if (false === $method) { |
|
182 | + return new \WP_Error('woocommerce_rest_shipping_zone_not_created', __('Resource cannot be created.', 'woocommerce'), array('status' => 500)); |
|
183 | 183 | } |
184 | 184 | |
185 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
186 | - if ( is_wp_error( $method ) ) { |
|
185 | + $method = $this->update_fields($instance_id, $method, $request); |
|
186 | + if (is_wp_error($method)) { |
|
187 | 187 | return $method; |
188 | 188 | } |
189 | 189 | |
190 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
191 | - return rest_ensure_response( $data ); |
|
190 | + $data = $this->prepare_item_for_response($method, $request); |
|
191 | + return rest_ensure_response($data); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | * @param \WP_REST_Request $request Full details about the request. |
198 | 198 | * @return \WP_Error|boolean |
199 | 199 | */ |
200 | - public function delete_item( $request ) { |
|
201 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
202 | - if ( is_wp_error( $zone ) ) { |
|
200 | + public function delete_item($request) { |
|
201 | + $zone = $this->get_zone($request['zone_id']); |
|
202 | + if (is_wp_error($zone)) { |
|
203 | 203 | return $zone; |
204 | 204 | } |
205 | 205 | |
@@ -207,34 +207,34 @@ discard block |
||
207 | 207 | $force = $request['force']; |
208 | 208 | |
209 | 209 | // We don't support trashing for this type, error out. |
210 | - if ( ! $force ) { |
|
211 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Shipping methods do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
210 | + if ( ! $force) { |
|
211 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Shipping methods do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | $methods = $zone->get_shipping_methods(); |
215 | 215 | $method = false; |
216 | 216 | |
217 | - foreach ( $methods as $method_obj ) { |
|
218 | - if ( $instance_id === $method_obj->instance_id ) { |
|
217 | + foreach ($methods as $method_obj) { |
|
218 | + if ($instance_id === $method_obj->instance_id) { |
|
219 | 219 | $method = $method_obj; |
220 | 220 | break; |
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | - if ( false === $method ) { |
|
225 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
224 | + if (false === $method) { |
|
225 | + return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
226 | 226 | } |
227 | 227 | |
228 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
229 | - if ( is_wp_error( $method ) ) { |
|
228 | + $method = $this->update_fields($instance_id, $method, $request); |
|
229 | + if (is_wp_error($method)) { |
|
230 | 230 | return $method; |
231 | 231 | } |
232 | 232 | |
233 | - $request->set_param( 'context', 'view' ); |
|
234 | - $previous = $this->prepare_item_for_response( $method, $request ); |
|
233 | + $request->set_param('context', 'view'); |
|
234 | + $previous = $this->prepare_item_for_response($method, $request); |
|
235 | 235 | |
236 | 236 | // Actually delete. |
237 | - $zone->delete_shipping_method( $instance_id ); |
|
237 | + $zone->delete_shipping_method($instance_id); |
|
238 | 238 | $response = new \WP_REST_Response(); |
239 | 239 | $response->set_data( |
240 | 240 | array( |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param \WP_REST_Response $response The response data. |
251 | 251 | * @param \WP_REST_Request $request The request sent to the API. |
252 | 252 | */ |
253 | - do_action( 'woocommerce_rest_delete_shipping_zone_method', $method, $response, $request ); |
|
253 | + do_action('woocommerce_rest_delete_shipping_zone_method', $method, $response, $request); |
|
254 | 254 | |
255 | 255 | return $response; |
256 | 256 | } |
@@ -261,9 +261,9 @@ discard block |
||
261 | 261 | * @param \WP_REST_Request $request Request data. |
262 | 262 | * @return \WP_REST_Response|\WP_Error |
263 | 263 | */ |
264 | - public function update_item( $request ) { |
|
265 | - $zone = $this->get_zone( $request['zone_id'] ); |
|
266 | - if ( is_wp_error( $zone ) ) { |
|
264 | + public function update_item($request) { |
|
265 | + $zone = $this->get_zone($request['zone_id']); |
|
266 | + if (is_wp_error($zone)) { |
|
267 | 267 | return $zone; |
268 | 268 | } |
269 | 269 | |
@@ -271,24 +271,24 @@ discard block |
||
271 | 271 | $methods = $zone->get_shipping_methods(); |
272 | 272 | $method = false; |
273 | 273 | |
274 | - foreach ( $methods as $method_obj ) { |
|
275 | - if ( $instance_id === $method_obj->instance_id ) { |
|
274 | + foreach ($methods as $method_obj) { |
|
275 | + if ($instance_id === $method_obj->instance_id) { |
|
276 | 276 | $method = $method_obj; |
277 | 277 | break; |
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - if ( false === $method ) { |
|
282 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
281 | + if (false === $method) { |
|
282 | + return new \WP_Error('woocommerce_rest_shipping_zone_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
283 | 283 | } |
284 | 284 | |
285 | - $method = $this->update_fields( $instance_id, $method, $request ); |
|
286 | - if ( is_wp_error( $method ) ) { |
|
285 | + $method = $this->update_fields($instance_id, $method, $request); |
|
286 | + if (is_wp_error($method)) { |
|
287 | 287 | return $method; |
288 | 288 | } |
289 | 289 | |
290 | - $data = $this->prepare_item_for_response( $method, $request ); |
|
291 | - return rest_ensure_response( $data ); |
|
290 | + $data = $this->prepare_item_for_response($method, $request); |
|
291 | + return rest_ensure_response($data); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -300,47 +300,47 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return WC_Shipping_Method |
302 | 302 | */ |
303 | - public function update_fields( $instance_id, $method, $request ) { |
|
303 | + public function update_fields($instance_id, $method, $request) { |
|
304 | 304 | global $wpdb; |
305 | 305 | |
306 | 306 | // Update settings if present. |
307 | - if ( isset( $request['settings'] ) ) { |
|
307 | + if (isset($request['settings'])) { |
|
308 | 308 | $method->init_instance_settings(); |
309 | 309 | $instance_settings = $method->instance_settings; |
310 | 310 | $errors_found = false; |
311 | - foreach ( $method->get_instance_form_fields() as $key => $field ) { |
|
312 | - if ( isset( $request['settings'][ $key ] ) ) { |
|
313 | - if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { |
|
314 | - $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); |
|
311 | + foreach ($method->get_instance_form_fields() as $key => $field) { |
|
312 | + if (isset($request['settings'][$key])) { |
|
313 | + if (is_callable(array($this, 'validate_setting_' . $field['type'] . '_field'))) { |
|
314 | + $value = $this->{'validate_setting_' . $field['type'] . '_field'}($request['settings'][$key], $field); |
|
315 | 315 | } else { |
316 | - $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); |
|
316 | + $value = $this->validate_setting_text_field($request['settings'][$key], $field); |
|
317 | 317 | } |
318 | - if ( is_wp_error( $value ) ) { |
|
318 | + if (is_wp_error($value)) { |
|
319 | 319 | $errors_found = true; |
320 | 320 | break; |
321 | 321 | } |
322 | - $instance_settings[ $key ] = $value; |
|
322 | + $instance_settings[$key] = $value; |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
326 | - if ( $errors_found ) { |
|
327 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
326 | + if ($errors_found) { |
|
327 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
328 | 328 | } |
329 | 329 | |
330 | - update_option( $method->get_instance_option_key(), apply_filters( 'woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method ) ); |
|
330 | + update_option($method->get_instance_option_key(), apply_filters('woocommerce_shipping_' . $method->id . '_instance_settings_values', $instance_settings, $method)); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | // Update order. |
334 | - if ( isset( $request['order'] ) ) { |
|
335 | - $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'method_order' => absint( $request['order'] ) ), array( 'instance_id' => absint( $instance_id ) ) ); |
|
336 | - $method->method_order = absint( $request['order'] ); |
|
334 | + if (isset($request['order'])) { |
|
335 | + $wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('method_order' => absint($request['order'])), array('instance_id' => absint($instance_id))); |
|
336 | + $method->method_order = absint($request['order']); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Update if this method is enabled or not. |
340 | - if ( isset( $request['enabled'] ) ) { |
|
341 | - if ( $wpdb->update( "{$wpdb->prefix}woocommerce_shipping_zone_methods", array( 'is_enabled' => $request['enabled'] ), array( 'instance_id' => absint( $instance_id ) ) ) ) { |
|
342 | - do_action( 'woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled'] ); |
|
343 | - $method->enabled = ( true === $request['enabled'] ? 'yes' : 'no' ); |
|
340 | + if (isset($request['enabled'])) { |
|
341 | + if ($wpdb->update("{$wpdb->prefix}woocommerce_shipping_zone_methods", array('is_enabled' => $request['enabled']), array('instance_id' => absint($instance_id)))) { |
|
342 | + do_action('woocommerce_shipping_zone_method_status_toggled', $instance_id, $method->id, $request['zone_id'], $request['enabled']); |
|
343 | + $method->enabled = (true === $request['enabled'] ? 'yes' : 'no'); |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
@@ -354,29 +354,29 @@ discard block |
||
354 | 354 | * @param \WP_REST_Request $request Request object. |
355 | 355 | * @return \WP_REST_Response $response |
356 | 356 | */ |
357 | - public function prepare_item_for_response( $item, $request ) { |
|
357 | + public function prepare_item_for_response($item, $request) { |
|
358 | 358 | $method = array( |
359 | 359 | 'id' => $item->instance_id, |
360 | 360 | 'instance_id' => $item->instance_id, |
361 | 361 | 'title' => $item->instance_settings['title'], |
362 | 362 | 'order' => $item->method_order, |
363 | - 'enabled' => ( 'yes' === $item->enabled ), |
|
363 | + 'enabled' => ('yes' === $item->enabled), |
|
364 | 364 | 'method_id' => $item->id, |
365 | 365 | 'method_title' => $item->method_title, |
366 | 366 | 'method_description' => $item->method_description, |
367 | - 'settings' => $this->get_settings( $item ), |
|
367 | + 'settings' => $this->get_settings($item), |
|
368 | 368 | ); |
369 | 369 | |
370 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
371 | - $data = $this->add_additional_fields_to_object( $method, $request ); |
|
372 | - $data = $this->filter_response_by_context( $data, $context ); |
|
370 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
371 | + $data = $this->add_additional_fields_to_object($method, $request); |
|
372 | + $data = $this->filter_response_by_context($data, $context); |
|
373 | 373 | |
374 | 374 | // Wrap the data in a response object. |
375 | - $response = rest_ensure_response( $data ); |
|
375 | + $response = rest_ensure_response($data); |
|
376 | 376 | |
377 | - $response->add_links( $this->prepare_links( $request['zone_id'], $item->instance_id ) ); |
|
377 | + $response->add_links($this->prepare_links($request['zone_id'], $item->instance_id)); |
|
378 | 378 | |
379 | - $response = $this->prepare_response_for_collection( $response ); |
|
379 | + $response = $this->prepare_response_for_collection($response); |
|
380 | 380 | |
381 | 381 | return $response; |
382 | 382 | } |
@@ -388,24 +388,24 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @return array |
390 | 390 | */ |
391 | - public function get_settings( $item ) { |
|
391 | + public function get_settings($item) { |
|
392 | 392 | $item->init_instance_settings(); |
393 | 393 | $settings = array(); |
394 | - foreach ( $item->get_instance_form_fields() as $id => $field ) { |
|
394 | + foreach ($item->get_instance_form_fields() as $id => $field) { |
|
395 | 395 | $data = array( |
396 | 396 | 'id' => $id, |
397 | 397 | 'label' => $field['title'], |
398 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
398 | + 'description' => empty($field['description']) ? '' : $field['description'], |
|
399 | 399 | 'type' => $field['type'], |
400 | - 'value' => $item->instance_settings[ $id ], |
|
401 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
402 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
403 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
400 | + 'value' => $item->instance_settings[$id], |
|
401 | + 'default' => empty($field['default']) ? '' : $field['default'], |
|
402 | + 'tip' => empty($field['description']) ? '' : $field['description'], |
|
403 | + 'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'], |
|
404 | 404 | ); |
405 | - if ( ! empty( $field['options'] ) ) { |
|
405 | + if ( ! empty($field['options'])) { |
|
406 | 406 | $data['options'] = $field['options']; |
407 | 407 | } |
408 | - $settings[ $id ] = $data; |
|
408 | + $settings[$id] = $data; |
|
409 | 409 | } |
410 | 410 | return $settings; |
411 | 411 | } |
@@ -417,17 +417,17 @@ discard block |
||
417 | 417 | * @param int $instance_id Given Shipping Zone Method Instance ID. |
418 | 418 | * @return array Links for the given Shipping Zone Method. |
419 | 419 | */ |
420 | - protected function prepare_links( $zone_id, $instance_id ) { |
|
420 | + protected function prepare_links($zone_id, $instance_id) { |
|
421 | 421 | $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id; |
422 | 422 | $links = array( |
423 | 423 | 'self' => array( |
424 | - 'href' => rest_url( $base . '/methods/' . $instance_id ), |
|
424 | + 'href' => rest_url($base . '/methods/' . $instance_id), |
|
425 | 425 | ), |
426 | 426 | 'collection' => array( |
427 | - 'href' => rest_url( $base . '/methods' ), |
|
427 | + 'href' => rest_url($base . '/methods'), |
|
428 | 428 | ), |
429 | 429 | 'describes' => array( |
430 | - 'href' => rest_url( $base ), |
|
430 | + 'href' => rest_url($base), |
|
431 | 431 | ), |
432 | 432 | ); |
433 | 433 | |
@@ -446,102 +446,102 @@ discard block |
||
446 | 446 | 'type' => 'object', |
447 | 447 | 'properties' => array( |
448 | 448 | 'id' => array( |
449 | - 'description' => __( 'Shipping method instance ID.', 'woocommerce' ), |
|
449 | + 'description' => __('Shipping method instance ID.', 'woocommerce'), |
|
450 | 450 | 'type' => 'integer', |
451 | - 'context' => array( 'view', 'edit' ), |
|
451 | + 'context' => array('view', 'edit'), |
|
452 | 452 | 'readonly' => true, |
453 | 453 | ), |
454 | 454 | 'instance_id' => array( |
455 | - 'description' => __( 'Shipping method instance ID.', 'woocommerce' ), |
|
455 | + 'description' => __('Shipping method instance ID.', 'woocommerce'), |
|
456 | 456 | 'type' => 'integer', |
457 | - 'context' => array( 'view', 'edit' ), |
|
457 | + 'context' => array('view', 'edit'), |
|
458 | 458 | 'readonly' => true, |
459 | 459 | ), |
460 | 460 | 'title' => array( |
461 | - 'description' => __( 'Shipping method customer facing title.', 'woocommerce' ), |
|
461 | + 'description' => __('Shipping method customer facing title.', 'woocommerce'), |
|
462 | 462 | 'type' => 'string', |
463 | - 'context' => array( 'view', 'edit' ), |
|
463 | + 'context' => array('view', 'edit'), |
|
464 | 464 | 'readonly' => true, |
465 | 465 | ), |
466 | 466 | 'order' => array( |
467 | - 'description' => __( 'Shipping method sort order.', 'woocommerce' ), |
|
467 | + 'description' => __('Shipping method sort order.', 'woocommerce'), |
|
468 | 468 | 'type' => 'integer', |
469 | - 'context' => array( 'view', 'edit' ), |
|
469 | + 'context' => array('view', 'edit'), |
|
470 | 470 | ), |
471 | 471 | 'enabled' => array( |
472 | - 'description' => __( 'Shipping method enabled status.', 'woocommerce' ), |
|
472 | + 'description' => __('Shipping method enabled status.', 'woocommerce'), |
|
473 | 473 | 'type' => 'boolean', |
474 | - 'context' => array( 'view', 'edit' ), |
|
474 | + 'context' => array('view', 'edit'), |
|
475 | 475 | ), |
476 | 476 | 'method_id' => array( |
477 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
477 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
478 | 478 | 'type' => 'string', |
479 | - 'context' => array( 'view', 'edit' ), |
|
479 | + 'context' => array('view', 'edit'), |
|
480 | 480 | 'readonly' => true, |
481 | 481 | ), |
482 | 482 | 'method_title' => array( |
483 | - 'description' => __( 'Shipping method title.', 'woocommerce' ), |
|
483 | + 'description' => __('Shipping method title.', 'woocommerce'), |
|
484 | 484 | 'type' => 'string', |
485 | - 'context' => array( 'view', 'edit' ), |
|
485 | + 'context' => array('view', 'edit'), |
|
486 | 486 | 'readonly' => true, |
487 | 487 | ), |
488 | 488 | 'method_description' => array( |
489 | - 'description' => __( 'Shipping method description.', 'woocommerce' ), |
|
489 | + 'description' => __('Shipping method description.', 'woocommerce'), |
|
490 | 490 | 'type' => 'string', |
491 | - 'context' => array( 'view', 'edit' ), |
|
491 | + 'context' => array('view', 'edit'), |
|
492 | 492 | 'readonly' => true, |
493 | 493 | ), |
494 | 494 | 'settings' => array( |
495 | - 'description' => __( 'Shipping method settings.', 'woocommerce' ), |
|
495 | + 'description' => __('Shipping method settings.', 'woocommerce'), |
|
496 | 496 | 'type' => 'object', |
497 | - 'context' => array( 'view', 'edit' ), |
|
497 | + 'context' => array('view', 'edit'), |
|
498 | 498 | 'properties' => array( |
499 | 499 | 'id' => array( |
500 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
500 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
501 | 501 | 'type' => 'string', |
502 | - 'context' => array( 'view', 'edit' ), |
|
502 | + 'context' => array('view', 'edit'), |
|
503 | 503 | 'readonly' => true, |
504 | 504 | ), |
505 | 505 | 'label' => array( |
506 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
506 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
507 | 507 | 'type' => 'string', |
508 | - 'context' => array( 'view', 'edit' ), |
|
508 | + 'context' => array('view', 'edit'), |
|
509 | 509 | 'readonly' => true, |
510 | 510 | ), |
511 | 511 | 'description' => array( |
512 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
512 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
513 | 513 | 'type' => 'string', |
514 | - 'context' => array( 'view', 'edit' ), |
|
514 | + 'context' => array('view', 'edit'), |
|
515 | 515 | 'readonly' => true, |
516 | 516 | ), |
517 | 517 | 'type' => array( |
518 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
518 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
519 | 519 | 'type' => 'string', |
520 | - 'context' => array( 'view', 'edit' ), |
|
521 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ), |
|
520 | + 'context' => array('view', 'edit'), |
|
521 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'), |
|
522 | 522 | 'readonly' => true, |
523 | 523 | ), |
524 | 524 | 'value' => array( |
525 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
525 | + 'description' => __('Setting value.', 'woocommerce'), |
|
526 | 526 | 'type' => 'string', |
527 | - 'context' => array( 'view', 'edit' ), |
|
527 | + 'context' => array('view', 'edit'), |
|
528 | 528 | ), |
529 | 529 | 'default' => array( |
530 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
530 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
531 | 531 | 'type' => 'string', |
532 | - 'context' => array( 'view', 'edit' ), |
|
532 | + 'context' => array('view', 'edit'), |
|
533 | 533 | 'readonly' => true, |
534 | 534 | ), |
535 | 535 | 'tip' => array( |
536 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
536 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
537 | 537 | 'type' => 'string', |
538 | - 'context' => array( 'view', 'edit' ), |
|
538 | + 'context' => array('view', 'edit'), |
|
539 | 539 | 'readonly' => true, |
540 | 540 | ), |
541 | 541 | 'placeholder' => array( |
542 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
542 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
543 | 543 | 'type' => 'string', |
544 | - 'context' => array( 'view', 'edit' ), |
|
544 | + 'context' => array('view', 'edit'), |
|
545 | 545 | 'readonly' => true, |
546 | 546 | ), |
547 | 547 | ), |
@@ -549,6 +549,6 @@ discard block |
||
549 | 549 | ), |
550 | 550 | ); |
551 | 551 | |
552 | - return $this->add_additional_fields_schema( $schema ); |
|
552 | + return $this->add_additional_fields_schema($schema); |
|
553 | 553 | } |
554 | 554 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Network Orders controller class. |
@@ -20,18 +20,18 @@ discard block |
||
20 | 20 | * Register the routes for network orders. |
21 | 21 | */ |
22 | 22 | public function register_routes() { |
23 | - if ( is_multisite() ) { |
|
23 | + if (is_multisite()) { |
|
24 | 24 | register_rest_route( |
25 | 25 | $this->namespace, |
26 | 26 | '/' . $this->rest_base . '/network', |
27 | 27 | array( |
28 | 28 | array( |
29 | 29 | 'methods' => \WP_REST_Server::READABLE, |
30 | - 'callback' => array( $this, 'network_orders' ), |
|
31 | - 'permission_callback' => array( $this, 'network_orders_permissions_check' ), |
|
30 | + 'callback' => array($this, 'network_orders'), |
|
31 | + 'permission_callback' => array($this, 'network_orders_permissions_check'), |
|
32 | 32 | 'args' => $this->get_collection_params(), |
33 | 33 | ), |
34 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
34 | + 'schema' => array($this, 'get_public_item_schema'), |
|
35 | 35 | ), |
36 | 36 | true |
37 | 37 | ); |
@@ -46,34 +46,34 @@ discard block |
||
46 | 46 | public function get_public_item_schema() { |
47 | 47 | $schema = parent::get_public_item_schema(); |
48 | 48 | |
49 | - $schema['properties']['blog'] = array( |
|
50 | - 'description' => __( 'Blog id of the record on the multisite.', 'woocommerce' ), |
|
49 | + $schema['properties']['blog'] = array( |
|
50 | + 'description' => __('Blog id of the record on the multisite.', 'woocommerce'), |
|
51 | 51 | 'type' => 'integer', |
52 | - 'context' => array( 'view' ), |
|
52 | + 'context' => array('view'), |
|
53 | 53 | 'readonly' => true, |
54 | 54 | ); |
55 | - $schema['properties']['edit_url'] = array( |
|
56 | - 'description' => __( 'URL to edit the order', 'woocommerce' ), |
|
55 | + $schema['properties']['edit_url'] = array( |
|
56 | + 'description' => __('URL to edit the order', 'woocommerce'), |
|
57 | 57 | 'type' => 'string', |
58 | - 'context' => array( 'view' ), |
|
58 | + 'context' => array('view'), |
|
59 | 59 | 'readonly' => true, |
60 | 60 | ); |
61 | - $schema['properties']['customer'][] = array( |
|
62 | - 'description' => __( 'Name of the customer for the order', 'woocommerce' ), |
|
61 | + $schema['properties']['customer'][] = array( |
|
62 | + 'description' => __('Name of the customer for the order', 'woocommerce'), |
|
63 | 63 | 'type' => 'string', |
64 | - 'context' => array( 'view' ), |
|
64 | + 'context' => array('view'), |
|
65 | 65 | 'readonly' => true, |
66 | 66 | ); |
67 | - $schema['properties']['status_name'][] = array( |
|
68 | - 'description' => __( 'Order Status', 'woocommerce' ), |
|
67 | + $schema['properties']['status_name'][] = array( |
|
68 | + 'description' => __('Order Status', 'woocommerce'), |
|
69 | 69 | 'type' => 'string', |
70 | - 'context' => array( 'view' ), |
|
70 | + 'context' => array('view'), |
|
71 | 71 | 'readonly' => true, |
72 | 72 | ); |
73 | 73 | $schema['properties']['formatted_total'][] = array( |
74 | - 'description' => __( 'Order total formatted for locale', 'woocommerce' ), |
|
74 | + 'description' => __('Order total formatted for locale', 'woocommerce'), |
|
75 | 75 | 'type' => 'string', |
76 | - 'context' => array( 'view' ), |
|
76 | + 'context' => array('view'), |
|
77 | 77 | 'readonly' => true, |
78 | 78 | ); |
79 | 79 | |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return bool $permission |
89 | 89 | */ |
90 | - public function network_orders_permissions_check( $request ) { |
|
91 | - $blog_id = $request->get_param( 'blog_id' ); |
|
92 | - $blog_id = ! empty( $blog_id ) ? $blog_id : get_current_blog_id(); |
|
90 | + public function network_orders_permissions_check($request) { |
|
91 | + $blog_id = $request->get_param('blog_id'); |
|
92 | + $blog_id = ! empty($blog_id) ? $blog_id : get_current_blog_id(); |
|
93 | 93 | |
94 | - switch_to_blog( $blog_id ); |
|
94 | + switch_to_blog($blog_id); |
|
95 | 95 | |
96 | - $permission = $this->get_items_permissions_check( $request ); |
|
96 | + $permission = $this->get_items_permissions_check($request); |
|
97 | 97 | |
98 | 98 | restore_current_blog(); |
99 | 99 | |
@@ -107,39 +107,39 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return \WP_REST_Response |
109 | 109 | */ |
110 | - public function network_orders( $request ) { |
|
111 | - $blog_id = $request->get_param( 'blog_id' ); |
|
112 | - $blog_id = ! empty( $blog_id ) ? $blog_id : get_current_blog_id(); |
|
113 | - $active_plugins = get_blog_option( $blog_id, 'active_plugins', array() ); |
|
114 | - $network_active_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
|
110 | + public function network_orders($request) { |
|
111 | + $blog_id = $request->get_param('blog_id'); |
|
112 | + $blog_id = ! empty($blog_id) ? $blog_id : get_current_blog_id(); |
|
113 | + $active_plugins = get_blog_option($blog_id, 'active_plugins', array()); |
|
114 | + $network_active_plugins = array_keys(get_site_option('active_sitewide_plugins', array())); |
|
115 | 115 | |
116 | - $plugins = array_merge( $active_plugins, $network_active_plugins ); |
|
116 | + $plugins = array_merge($active_plugins, $network_active_plugins); |
|
117 | 117 | $wc_active = false; |
118 | - foreach ( $plugins as $plugin ) { |
|
119 | - if ( substr_compare( $plugin, '/woocommerce.php', strlen( $plugin ) - strlen( '/woocommerce.php' ), strlen( '/woocommerce.php' ) ) === 0 ) { |
|
118 | + foreach ($plugins as $plugin) { |
|
119 | + if (substr_compare($plugin, '/woocommerce.php', strlen($plugin) - strlen('/woocommerce.php'), strlen('/woocommerce.php')) === 0) { |
|
120 | 120 | $wc_active = true; |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | 124 | // If WooCommerce not active for site, return an empty response. |
125 | - if ( ! $wc_active ) { |
|
126 | - $response = rest_ensure_response( array() ); |
|
125 | + if ( ! $wc_active) { |
|
126 | + $response = rest_ensure_response(array()); |
|
127 | 127 | return $response; |
128 | 128 | } |
129 | 129 | |
130 | - switch_to_blog( $blog_id ); |
|
131 | - add_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'network_orders_filter_args' ) ); |
|
132 | - $items = $this->get_items( $request ); |
|
133 | - remove_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'network_orders_filter_args' ) ); |
|
130 | + switch_to_blog($blog_id); |
|
131 | + add_filter('woocommerce_rest_orders_prepare_object_query', array($this, 'network_orders_filter_args')); |
|
132 | + $items = $this->get_items($request); |
|
133 | + remove_filter('woocommerce_rest_orders_prepare_object_query', array($this, 'network_orders_filter_args')); |
|
134 | 134 | |
135 | - foreach ( $items->data as &$current_order ) { |
|
136 | - $order = wc_get_order( $current_order['id'] ); |
|
135 | + foreach ($items->data as &$current_order) { |
|
136 | + $order = wc_get_order($current_order['id']); |
|
137 | 137 | |
138 | - $current_order['blog'] = get_blog_details( get_current_blog_id() ); |
|
139 | - $current_order['edit_url'] = get_admin_url( $blog_id, 'post.php?post=' . absint( $order->get_id() ) . '&action=edit' ); |
|
138 | + $current_order['blog'] = get_blog_details(get_current_blog_id()); |
|
139 | + $current_order['edit_url'] = get_admin_url($blog_id, 'post.php?post=' . absint($order->get_id()) . '&action=edit'); |
|
140 | 140 | /* translators: 1: first name 2: last name */ |
141 | - $current_order['customer'] = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $order->get_billing_first_name(), $order->get_billing_last_name() ) ); |
|
142 | - $current_order['status_name'] = wc_get_order_status_name( $order->get_status() ); |
|
141 | + $current_order['customer'] = trim(sprintf(_x('%1$s %2$s', 'full name', 'woocommerce'), $order->get_billing_first_name(), $order->get_billing_last_name())); |
|
142 | + $current_order['status_name'] = wc_get_order_status_name($order->get_status()); |
|
143 | 143 | $current_order['formatted_total'] = $order->get_formatted_order_total(); |
144 | 144 | } |
145 | 145 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return array |
157 | 157 | */ |
158 | - public function network_orders_filter_args( $args ) { |
|
158 | + public function network_orders_filter_args($args) { |
|
159 | 159 | $args['post_status'] = array( |
160 | 160 | 'wc-on-hold', |
161 | 161 | 'wc-processing', |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * Payment gateways controller class. |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | array( |
34 | 34 | array( |
35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
36 | - 'callback' => array( $this, 'get_items' ), |
|
37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'get_items'), |
|
37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
38 | 38 | 'args' => $this->get_collection_params(), |
39 | 39 | ), |
40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
41 | 41 | ), |
42 | 42 | true |
43 | 43 | ); |
@@ -47,25 +47,25 @@ discard block |
||
47 | 47 | array( |
48 | 48 | 'args' => array( |
49 | 49 | 'id' => array( |
50 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
50 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
51 | 51 | 'type' => 'string', |
52 | 52 | ), |
53 | 53 | ), |
54 | 54 | array( |
55 | 55 | 'methods' => \WP_REST_Server::READABLE, |
56 | - 'callback' => array( $this, 'get_item' ), |
|
57 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
56 | + 'callback' => array($this, 'get_item'), |
|
57 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
58 | 58 | 'args' => array( |
59 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
59 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
60 | 60 | ), |
61 | 61 | ), |
62 | 62 | array( |
63 | 63 | 'methods' => \WP_REST_Server::EDITABLE, |
64 | - 'callback' => array( $this, 'update_item' ), |
|
65 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
66 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
64 | + 'callback' => array($this, 'update_item'), |
|
65 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
66 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
67 | 67 | ), |
68 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
68 | + 'schema' => array($this, 'get_public_item_schema'), |
|
69 | 69 | ), |
70 | 70 | true |
71 | 71 | ); |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * @param \WP_REST_Request $request Full details about the request. |
78 | 78 | * @return \WP_Error|boolean |
79 | 79 | */ |
80 | - public function get_items_permissions_check( $request ) { |
|
81 | - if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'read' ) ) { |
|
82 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
80 | + public function get_items_permissions_check($request) { |
|
81 | + if ( ! wc_rest_check_manager_permissions('payment_gateways', 'read')) { |
|
82 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
83 | 83 | } |
84 | 84 | return true; |
85 | 85 | } |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | * @param \WP_REST_Request $request Full details about the request. |
91 | 91 | * @return \WP_Error|boolean |
92 | 92 | */ |
93 | - public function get_item_permissions_check( $request ) { |
|
94 | - if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'read' ) ) { |
|
95 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
93 | + public function get_item_permissions_check($request) { |
|
94 | + if ( ! wc_rest_check_manager_permissions('payment_gateways', 'read')) { |
|
95 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
96 | 96 | } |
97 | 97 | return true; |
98 | 98 | } |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | * @param \WP_REST_Request $request Full details about the request. |
104 | 104 | * @return \WP_Error|boolean |
105 | 105 | */ |
106 | - public function update_items_permissions_check( $request ) { |
|
107 | - if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'edit' ) ) { |
|
108 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
106 | + public function update_items_permissions_check($request) { |
|
107 | + if ( ! wc_rest_check_manager_permissions('payment_gateways', 'edit')) { |
|
108 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
109 | 109 | } |
110 | 110 | return true; |
111 | 111 | } |
@@ -116,16 +116,16 @@ discard block |
||
116 | 116 | * @param \WP_REST_Request $request Full details about the request. |
117 | 117 | * @return \WP_Error\WP_REST_Response |
118 | 118 | */ |
119 | - public function get_items( $request ) { |
|
119 | + public function get_items($request) { |
|
120 | 120 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
121 | 121 | $response = array(); |
122 | - foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) { |
|
122 | + foreach ($payment_gateways as $payment_gateway_id => $payment_gateway) { |
|
123 | 123 | $payment_gateway->id = $payment_gateway_id; |
124 | - $gateway = $this->prepare_item_for_response( $payment_gateway, $request ); |
|
125 | - $gateway = $this->prepare_response_for_collection( $gateway ); |
|
124 | + $gateway = $this->prepare_item_for_response($payment_gateway, $request); |
|
125 | + $gateway = $this->prepare_response_for_collection($gateway); |
|
126 | 126 | $response[] = $gateway; |
127 | 127 | } |
128 | - return rest_ensure_response( $response ); |
|
128 | + return rest_ensure_response($response); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -134,15 +134,15 @@ discard block |
||
134 | 134 | * @param \WP_REST_Request $request Request data. |
135 | 135 | * @return \WP_REST_Response|\WP_Error |
136 | 136 | */ |
137 | - public function get_item( $request ) { |
|
138 | - $gateway = $this->get_gateway( $request ); |
|
137 | + public function get_item($request) { |
|
138 | + $gateway = $this->get_gateway($request); |
|
139 | 139 | |
140 | - if ( is_null( $gateway ) ) { |
|
141 | - return new \WP_Error( 'woocommerce_rest_payment_gateway_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
140 | + if (is_null($gateway)) { |
|
141 | + return new \WP_Error('woocommerce_rest_payment_gateway_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
142 | 142 | } |
143 | 143 | |
144 | - $gateway = $this->prepare_item_for_response( $gateway, $request ); |
|
145 | - return rest_ensure_response( $gateway ); |
|
144 | + $gateway = $this->prepare_item_for_response($gateway, $request); |
|
145 | + return rest_ensure_response($gateway); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | * @param \WP_REST_Request $request Request data. |
152 | 152 | * @return \WP_REST_Response|\WP_Error |
153 | 153 | */ |
154 | - public function update_item( $request ) { |
|
155 | - $gateway = $this->get_gateway( $request ); |
|
154 | + public function update_item($request) { |
|
155 | + $gateway = $this->get_gateway($request); |
|
156 | 156 | |
157 | - if ( is_null( $gateway ) ) { |
|
158 | - return new \WP_Error( 'woocommerce_rest_payment_gateway_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
157 | + if (is_null($gateway)) { |
|
158 | + return new \WP_Error('woocommerce_rest_payment_gateway_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | // Get settings. |
@@ -163,60 +163,60 @@ discard block |
||
163 | 163 | $settings = $gateway->settings; |
164 | 164 | |
165 | 165 | // Update settings. |
166 | - if ( isset( $request['settings'] ) ) { |
|
166 | + if (isset($request['settings'])) { |
|
167 | 167 | $errors_found = false; |
168 | - foreach ( $gateway->form_fields as $key => $field ) { |
|
169 | - if ( isset( $request['settings'][ $key ] ) ) { |
|
170 | - if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { |
|
171 | - $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); |
|
168 | + foreach ($gateway->form_fields as $key => $field) { |
|
169 | + if (isset($request['settings'][$key])) { |
|
170 | + if (is_callable(array($this, 'validate_setting_' . $field['type'] . '_field'))) { |
|
171 | + $value = $this->{'validate_setting_' . $field['type'] . '_field'}($request['settings'][$key], $field); |
|
172 | 172 | } else { |
173 | - $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); |
|
173 | + $value = $this->validate_setting_text_field($request['settings'][$key], $field); |
|
174 | 174 | } |
175 | - if ( is_wp_error( $value ) ) { |
|
175 | + if (is_wp_error($value)) { |
|
176 | 176 | $errors_found = true; |
177 | 177 | break; |
178 | 178 | } |
179 | - $settings[ $key ] = $value; |
|
179 | + $settings[$key] = $value; |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - if ( $errors_found ) { |
|
184 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
183 | + if ($errors_found) { |
|
184 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Update if this method is enabled or not. |
189 | - if ( isset( $request['enabled'] ) ) { |
|
190 | - $settings['enabled'] = wc_bool_to_string( $request['enabled'] ); |
|
189 | + if (isset($request['enabled'])) { |
|
190 | + $settings['enabled'] = wc_bool_to_string($request['enabled']); |
|
191 | 191 | $gateway->enabled = $settings['enabled']; |
192 | 192 | } |
193 | 193 | |
194 | 194 | // Update title. |
195 | - if ( isset( $request['title'] ) ) { |
|
195 | + if (isset($request['title'])) { |
|
196 | 196 | $settings['title'] = $request['title']; |
197 | 197 | $gateway->title = $settings['title']; |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Update description. |
201 | - if ( isset( $request['description'] ) ) { |
|
201 | + if (isset($request['description'])) { |
|
202 | 202 | $settings['description'] = $request['description']; |
203 | 203 | $gateway->description = $settings['description']; |
204 | 204 | } |
205 | 205 | |
206 | 206 | // Update options. |
207 | 207 | $gateway->settings = $settings; |
208 | - update_option( $gateway->get_option_key(), apply_filters( 'woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway ) ); |
|
208 | + update_option($gateway->get_option_key(), apply_filters('woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway)); |
|
209 | 209 | |
210 | 210 | // Update order. |
211 | - if ( isset( $request['order'] ) ) { |
|
212 | - $order = (array) get_option( 'woocommerce_gateway_order' ); |
|
213 | - $order[ $gateway->id ] = $request['order']; |
|
214 | - update_option( 'woocommerce_gateway_order', $order ); |
|
215 | - $gateway->order = absint( $request['order'] ); |
|
211 | + if (isset($request['order'])) { |
|
212 | + $order = (array) get_option('woocommerce_gateway_order'); |
|
213 | + $order[$gateway->id] = $request['order']; |
|
214 | + update_option('woocommerce_gateway_order', $order); |
|
215 | + $gateway->order = absint($request['order']); |
|
216 | 216 | } |
217 | 217 | |
218 | - $gateway = $this->prepare_item_for_response( $gateway, $request ); |
|
219 | - return rest_ensure_response( $gateway ); |
|
218 | + $gateway = $this->prepare_item_for_response($gateway, $request); |
|
219 | + return rest_ensure_response($gateway); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -225,11 +225,11 @@ discard block |
||
225 | 225 | * @param \WP_REST_Request $request Request data. |
226 | 226 | * @return \WP_REST_Response|null |
227 | 227 | */ |
228 | - public function get_gateway( $request ) { |
|
228 | + public function get_gateway($request) { |
|
229 | 229 | $gateway = null; |
230 | 230 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
231 | - foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) { |
|
232 | - if ( $request['id'] !== $payment_gateway_id ) { |
|
231 | + foreach ($payment_gateways as $payment_gateway_id => $payment_gateway) { |
|
232 | + if ($request['id'] !== $payment_gateway_id) { |
|
233 | 233 | continue; |
234 | 234 | } |
235 | 235 | $payment_gateway->id = $payment_gateway_id; |
@@ -245,26 +245,26 @@ discard block |
||
245 | 245 | * @param \WP_REST_Request $request Request object. |
246 | 246 | * @return \WP_REST_Response $response Response data. |
247 | 247 | */ |
248 | - public function prepare_item_for_response( $gateway, $request ) { |
|
249 | - $order = (array) get_option( 'woocommerce_gateway_order' ); |
|
248 | + public function prepare_item_for_response($gateway, $request) { |
|
249 | + $order = (array) get_option('woocommerce_gateway_order'); |
|
250 | 250 | $item = array( |
251 | 251 | 'id' => $gateway->id, |
252 | 252 | 'title' => $gateway->title, |
253 | 253 | 'description' => $gateway->description, |
254 | - 'order' => isset( $order[ $gateway->id ] ) ? $order[ $gateway->id ] : '', |
|
255 | - 'enabled' => ( 'yes' === $gateway->enabled ), |
|
254 | + 'order' => isset($order[$gateway->id]) ? $order[$gateway->id] : '', |
|
255 | + 'enabled' => ('yes' === $gateway->enabled), |
|
256 | 256 | 'method_title' => $gateway->get_method_title(), |
257 | 257 | 'method_description' => $gateway->get_method_description(), |
258 | 258 | 'method_supports' => $gateway->supports, |
259 | - 'settings' => $this->get_settings( $gateway ), |
|
259 | + 'settings' => $this->get_settings($gateway), |
|
260 | 260 | ); |
261 | 261 | |
262 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
263 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
264 | - $data = $this->filter_response_by_context( $data, $context ); |
|
262 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
263 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
264 | + $data = $this->filter_response_by_context($data, $context); |
|
265 | 265 | |
266 | - $response = rest_ensure_response( $data ); |
|
267 | - $response->add_links( $this->prepare_links( $gateway, $request ) ); |
|
266 | + $response = rest_ensure_response($data); |
|
267 | + $response->add_links($this->prepare_links($gateway, $request)); |
|
268 | 268 | |
269 | 269 | /** |
270 | 270 | * Filter payment gateway objects returned from the REST API. |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | * @param WC_Payment_Gateway $gateway Payment gateway object. |
274 | 274 | * @param \WP_REST_Request $request Request object. |
275 | 275 | */ |
276 | - return apply_filters( 'woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request ); |
|
276 | + return apply_filters('woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -283,34 +283,34 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @return array |
285 | 285 | */ |
286 | - public function get_settings( $gateway ) { |
|
286 | + public function get_settings($gateway) { |
|
287 | 287 | $settings = array(); |
288 | 288 | $gateway->init_form_fields(); |
289 | - foreach ( $gateway->form_fields as $id => $field ) { |
|
289 | + foreach ($gateway->form_fields as $id => $field) { |
|
290 | 290 | // Make sure we at least have a title and type. |
291 | - if ( empty( $field['title'] ) || empty( $field['type'] ) ) { |
|
291 | + if (empty($field['title']) || empty($field['type'])) { |
|
292 | 292 | continue; |
293 | 293 | } |
294 | 294 | |
295 | 295 | // Ignore 'enabled' and 'description' which get included elsewhere. |
296 | - if ( in_array( $id, array( 'enabled', 'description' ), true ) ) { |
|
296 | + if (in_array($id, array('enabled', 'description'), true)) { |
|
297 | 297 | continue; |
298 | 298 | } |
299 | 299 | |
300 | 300 | $data = array( |
301 | 301 | 'id' => $id, |
302 | - 'label' => empty( $field['label'] ) ? $field['title'] : $field['label'], |
|
303 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
302 | + 'label' => empty($field['label']) ? $field['title'] : $field['label'], |
|
303 | + 'description' => empty($field['description']) ? '' : $field['description'], |
|
304 | 304 | 'type' => $field['type'], |
305 | - 'value' => empty( $gateway->settings[ $id ] ) ? '' : $gateway->settings[ $id ], |
|
306 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
307 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
308 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
305 | + 'value' => empty($gateway->settings[$id]) ? '' : $gateway->settings[$id], |
|
306 | + 'default' => empty($field['default']) ? '' : $field['default'], |
|
307 | + 'tip' => empty($field['description']) ? '' : $field['description'], |
|
308 | + 'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'], |
|
309 | 309 | ); |
310 | - if ( ! empty( $field['options'] ) ) { |
|
310 | + if ( ! empty($field['options'])) { |
|
311 | 311 | $data['options'] = $field['options']; |
312 | 312 | } |
313 | - $settings[ $id ] = $data; |
|
313 | + $settings[$id] = $data; |
|
314 | 314 | } |
315 | 315 | return $settings; |
316 | 316 | } |
@@ -322,13 +322,13 @@ discard block |
||
322 | 322 | * @param \WP_REST_Request $request Request object. |
323 | 323 | * @return array |
324 | 324 | */ |
325 | - protected function prepare_links( $gateway, $request ) { |
|
325 | + protected function prepare_links($gateway, $request) { |
|
326 | 326 | $links = array( |
327 | 327 | 'self' => array( |
328 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $gateway->id ) ), |
|
328 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $gateway->id)), |
|
329 | 329 | ), |
330 | 330 | 'collection' => array( |
331 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
331 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
332 | 332 | ), |
333 | 333 | ); |
334 | 334 | |
@@ -347,106 +347,106 @@ discard block |
||
347 | 347 | 'type' => 'object', |
348 | 348 | 'properties' => array( |
349 | 349 | 'id' => array( |
350 | - 'description' => __( 'Payment gateway ID.', 'woocommerce' ), |
|
350 | + 'description' => __('Payment gateway ID.', 'woocommerce'), |
|
351 | 351 | 'type' => 'string', |
352 | - 'context' => array( 'view', 'edit' ), |
|
352 | + 'context' => array('view', 'edit'), |
|
353 | 353 | 'readonly' => true, |
354 | 354 | ), |
355 | 355 | 'title' => array( |
356 | - 'description' => __( 'Payment gateway title on checkout.', 'woocommerce' ), |
|
356 | + 'description' => __('Payment gateway title on checkout.', 'woocommerce'), |
|
357 | 357 | 'type' => 'string', |
358 | - 'context' => array( 'view', 'edit' ), |
|
358 | + 'context' => array('view', 'edit'), |
|
359 | 359 | ), |
360 | 360 | 'description' => array( |
361 | - 'description' => __( 'Payment gateway description on checkout.', 'woocommerce' ), |
|
361 | + 'description' => __('Payment gateway description on checkout.', 'woocommerce'), |
|
362 | 362 | 'type' => 'string', |
363 | - 'context' => array( 'view', 'edit' ), |
|
363 | + 'context' => array('view', 'edit'), |
|
364 | 364 | ), |
365 | 365 | 'order' => array( |
366 | - 'description' => __( 'Payment gateway sort order.', 'woocommerce' ), |
|
366 | + 'description' => __('Payment gateway sort order.', 'woocommerce'), |
|
367 | 367 | 'type' => 'integer', |
368 | - 'context' => array( 'view', 'edit' ), |
|
368 | + 'context' => array('view', 'edit'), |
|
369 | 369 | 'arg_options' => array( |
370 | 370 | 'sanitize_callback' => 'absint', |
371 | 371 | ), |
372 | 372 | ), |
373 | 373 | 'enabled' => array( |
374 | - 'description' => __( 'Payment gateway enabled status.', 'woocommerce' ), |
|
374 | + 'description' => __('Payment gateway enabled status.', 'woocommerce'), |
|
375 | 375 | 'type' => 'boolean', |
376 | - 'context' => array( 'view', 'edit' ), |
|
376 | + 'context' => array('view', 'edit'), |
|
377 | 377 | ), |
378 | 378 | 'method_title' => array( |
379 | - 'description' => __( 'Payment gateway method title.', 'woocommerce' ), |
|
379 | + 'description' => __('Payment gateway method title.', 'woocommerce'), |
|
380 | 380 | 'type' => 'string', |
381 | - 'context' => array( 'view', 'edit' ), |
|
381 | + 'context' => array('view', 'edit'), |
|
382 | 382 | 'readonly' => true, |
383 | 383 | ), |
384 | 384 | 'method_description' => array( |
385 | - 'description' => __( 'Payment gateway method description.', 'woocommerce' ), |
|
385 | + 'description' => __('Payment gateway method description.', 'woocommerce'), |
|
386 | 386 | 'type' => 'string', |
387 | - 'context' => array( 'view', 'edit' ), |
|
387 | + 'context' => array('view', 'edit'), |
|
388 | 388 | 'readonly' => true, |
389 | 389 | ), |
390 | 390 | 'method_supports' => array( |
391 | - 'description' => __( 'Supported features for this payment gateway.', 'woocommerce' ), |
|
391 | + 'description' => __('Supported features for this payment gateway.', 'woocommerce'), |
|
392 | 392 | 'type' => 'array', |
393 | - 'context' => array( 'view', 'edit' ), |
|
393 | + 'context' => array('view', 'edit'), |
|
394 | 394 | 'readonly' => true, |
395 | 395 | 'items' => array( |
396 | 396 | 'type' => 'string', |
397 | 397 | ), |
398 | 398 | ), |
399 | 399 | 'settings' => array( |
400 | - 'description' => __( 'Payment gateway settings.', 'woocommerce' ), |
|
400 | + 'description' => __('Payment gateway settings.', 'woocommerce'), |
|
401 | 401 | 'type' => 'object', |
402 | - 'context' => array( 'view', 'edit' ), |
|
402 | + 'context' => array('view', 'edit'), |
|
403 | 403 | 'properties' => array( |
404 | 404 | 'id' => array( |
405 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
405 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
406 | 406 | 'type' => 'string', |
407 | - 'context' => array( 'view', 'edit' ), |
|
407 | + 'context' => array('view', 'edit'), |
|
408 | 408 | 'readonly' => true, |
409 | 409 | ), |
410 | 410 | 'label' => array( |
411 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
411 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
412 | 412 | 'type' => 'string', |
413 | - 'context' => array( 'view', 'edit' ), |
|
413 | + 'context' => array('view', 'edit'), |
|
414 | 414 | 'readonly' => true, |
415 | 415 | ), |
416 | 416 | 'description' => array( |
417 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
417 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
418 | 418 | 'type' => 'string', |
419 | - 'context' => array( 'view', 'edit' ), |
|
419 | + 'context' => array('view', 'edit'), |
|
420 | 420 | 'readonly' => true, |
421 | 421 | ), |
422 | 422 | 'type' => array( |
423 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
423 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
424 | 424 | 'type' => 'string', |
425 | - 'context' => array( 'view', 'edit' ), |
|
426 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ), |
|
425 | + 'context' => array('view', 'edit'), |
|
426 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'), |
|
427 | 427 | 'readonly' => true, |
428 | 428 | ), |
429 | 429 | 'value' => array( |
430 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
430 | + 'description' => __('Setting value.', 'woocommerce'), |
|
431 | 431 | 'type' => 'string', |
432 | - 'context' => array( 'view', 'edit' ), |
|
432 | + 'context' => array('view', 'edit'), |
|
433 | 433 | ), |
434 | 434 | 'default' => array( |
435 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
435 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
436 | 436 | 'type' => 'string', |
437 | - 'context' => array( 'view', 'edit' ), |
|
437 | + 'context' => array('view', 'edit'), |
|
438 | 438 | 'readonly' => true, |
439 | 439 | ), |
440 | 440 | 'tip' => array( |
441 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
441 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
442 | 442 | 'type' => 'string', |
443 | - 'context' => array( 'view', 'edit' ), |
|
443 | + 'context' => array('view', 'edit'), |
|
444 | 444 | 'readonly' => true, |
445 | 445 | ), |
446 | 446 | 'placeholder' => array( |
447 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
447 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
448 | 448 | 'type' => 'string', |
449 | - 'context' => array( 'view', 'edit' ), |
|
449 | + 'context' => array('view', 'edit'), |
|
450 | 450 | 'readonly' => true, |
451 | 451 | ), |
452 | 452 | ), |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | ), |
455 | 455 | ); |
456 | 456 | |
457 | - return $this->add_additional_fields_schema( $schema ); |
|
457 | + return $this->add_additional_fields_schema($schema); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | */ |
465 | 465 | public function get_collection_params() { |
466 | 466 | return array( |
467 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
467 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
468 | 468 | ); |
469 | 469 | } |
470 | 470 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Products controller class. |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * Initialize product actions. |
42 | 42 | */ |
43 | 43 | public function __construct() { |
44 | - add_action( "woocommerce_rest_insert_{$this->post_type}_object", array( $this, 'clear_transients' ) ); |
|
44 | + add_action("woocommerce_rest_insert_{$this->post_type}_object", array($this, 'clear_transients')); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -54,17 +54,17 @@ discard block |
||
54 | 54 | array( |
55 | 55 | array( |
56 | 56 | 'methods' => \WP_REST_Server::READABLE, |
57 | - 'callback' => array( $this, 'get_items' ), |
|
58 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
57 | + 'callback' => array($this, 'get_items'), |
|
58 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
59 | 59 | 'args' => $this->get_collection_params(), |
60 | 60 | ), |
61 | 61 | array( |
62 | 62 | 'methods' => \WP_REST_Server::CREATABLE, |
63 | - 'callback' => array( $this, 'create_item' ), |
|
64 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
65 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
63 | + 'callback' => array($this, 'create_item'), |
|
64 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
65 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
66 | 66 | ), |
67 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
67 | + 'schema' => array($this, 'get_public_item_schema'), |
|
68 | 68 | ), |
69 | 69 | true |
70 | 70 | ); |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | array( |
76 | 76 | 'args' => array( |
77 | 77 | 'id' => array( |
78 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
78 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
79 | 79 | 'type' => 'integer', |
80 | 80 | ), |
81 | 81 | ), |
82 | 82 | array( |
83 | 83 | 'methods' => \WP_REST_Server::READABLE, |
84 | - 'callback' => array( $this, 'get_item' ), |
|
85 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
84 | + 'callback' => array($this, 'get_item'), |
|
85 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
86 | 86 | 'args' => array( |
87 | 87 | 'context' => $this->get_context_param( |
88 | 88 | array( |
@@ -93,23 +93,23 @@ discard block |
||
93 | 93 | ), |
94 | 94 | array( |
95 | 95 | 'methods' => \WP_REST_Server::EDITABLE, |
96 | - 'callback' => array( $this, 'update_item' ), |
|
97 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
98 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
96 | + 'callback' => array($this, 'update_item'), |
|
97 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
98 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
99 | 99 | ), |
100 | 100 | array( |
101 | 101 | 'methods' => \WP_REST_Server::DELETABLE, |
102 | - 'callback' => array( $this, 'delete_item' ), |
|
103 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
102 | + 'callback' => array($this, 'delete_item'), |
|
103 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
104 | 104 | 'args' => array( |
105 | 105 | 'force' => array( |
106 | 106 | 'default' => false, |
107 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
107 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
108 | 108 | 'type' => 'boolean', |
109 | 109 | ), |
110 | 110 | ), |
111 | 111 | ), |
112 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
112 | + 'schema' => array($this, 'get_public_item_schema'), |
|
113 | 113 | ), |
114 | 114 | true |
115 | 115 | ); |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | array( |
121 | 121 | array( |
122 | 122 | 'methods' => \WP_REST_Server::EDITABLE, |
123 | - 'callback' => array( $this, 'batch_items' ), |
|
124 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
125 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
123 | + 'callback' => array($this, 'batch_items'), |
|
124 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
125 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
126 | 126 | ), |
127 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
127 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
128 | 128 | ), |
129 | 129 | true |
130 | 130 | ); |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | * @since 3.0.0 |
139 | 139 | * @return WC_Data |
140 | 140 | */ |
141 | - protected function get_object( $id ) { |
|
142 | - return wc_get_product( $id ); |
|
141 | + protected function get_object($id) { |
|
142 | + return wc_get_product($id); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -151,24 +151,24 @@ discard block |
||
151 | 151 | * @since 3.0.0 |
152 | 152 | * @return \WP_REST_Response |
153 | 153 | */ |
154 | - public function prepare_object_for_response( $object, $request ) { |
|
155 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
156 | - $data = $this->get_product_data( $object, $context ); |
|
154 | + public function prepare_object_for_response($object, $request) { |
|
155 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
156 | + $data = $this->get_product_data($object, $context); |
|
157 | 157 | |
158 | 158 | // Add variations to variable products. |
159 | - if ( $object->is_type( 'variable' ) && $object->has_child() ) { |
|
159 | + if ($object->is_type('variable') && $object->has_child()) { |
|
160 | 160 | $data['variations'] = $object->get_children(); |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Add grouped products data. |
164 | - if ( $object->is_type( 'grouped' ) && $object->has_child() ) { |
|
164 | + if ($object->is_type('grouped') && $object->has_child()) { |
|
165 | 165 | $data['grouped_products'] = $object->get_children(); |
166 | 166 | } |
167 | 167 | |
168 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
169 | - $data = $this->filter_response_by_context( $data, $context ); |
|
170 | - $response = rest_ensure_response( $data ); |
|
171 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
168 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
169 | + $data = $this->filter_response_by_context($data, $context); |
|
170 | + $response = rest_ensure_response($data); |
|
171 | + $response->add_links($this->prepare_links($object, $request)); |
|
172 | 172 | |
173 | 173 | /** |
174 | 174 | * Filter the data for a response. |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @param WC_Data $object Object data. |
181 | 181 | * @param \WP_REST_Request $request Request object. |
182 | 182 | */ |
183 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
183 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -190,28 +190,28 @@ discard block |
||
190 | 190 | * @param bool $creating If is creating a new object. |
191 | 191 | * @return \WP_Error|WC_Data |
192 | 192 | */ |
193 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
194 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
193 | + protected function prepare_object_for_database($request, $creating = false) { |
|
194 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
195 | 195 | |
196 | 196 | // Type is the most important part here because we need to be using the correct class and methods. |
197 | - if ( isset( $request['type'] ) ) { |
|
198 | - $classname = \WC_Product_Factory::get_classname_from_product_type( $request['type'] ); |
|
197 | + if (isset($request['type'])) { |
|
198 | + $classname = \WC_Product_Factory::get_classname_from_product_type($request['type']); |
|
199 | 199 | |
200 | - if ( ! class_exists( $classname ) ) { |
|
200 | + if ( ! class_exists($classname)) { |
|
201 | 201 | $classname = 'WC_Product_Simple'; |
202 | 202 | } |
203 | 203 | |
204 | - $product = new $classname( $id ); |
|
205 | - } elseif ( isset( $request['id'] ) ) { |
|
206 | - $product = wc_get_product( $id ); |
|
204 | + $product = new $classname($id); |
|
205 | + } elseif (isset($request['id'])) { |
|
206 | + $product = wc_get_product($id); |
|
207 | 207 | } else { |
208 | 208 | $product = new \WC_Product_Simple(); |
209 | 209 | } |
210 | 210 | |
211 | - if ( 'variation' === $product->get_type() ) { |
|
211 | + if ('variation' === $product->get_type()) { |
|
212 | 212 | return new \WP_Error( |
213 | 213 | "woocommerce_rest_invalid_{$this->post_type}_id", |
214 | - __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), |
|
214 | + __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), |
|
215 | 215 | array( |
216 | 216 | 'status' => 404, |
217 | 217 | ) |
@@ -219,365 +219,365 @@ discard block |
||
219 | 219 | } |
220 | 220 | |
221 | 221 | // Post title. |
222 | - if ( isset( $request['name'] ) ) { |
|
223 | - $product->set_name( wp_filter_post_kses( $request['name'] ) ); |
|
222 | + if (isset($request['name'])) { |
|
223 | + $product->set_name(wp_filter_post_kses($request['name'])); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | // Post content. |
227 | - if ( isset( $request['description'] ) ) { |
|
228 | - $product->set_description( wp_filter_post_kses( $request['description'] ) ); |
|
227 | + if (isset($request['description'])) { |
|
228 | + $product->set_description(wp_filter_post_kses($request['description'])); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // Post excerpt. |
232 | - if ( isset( $request['short_description'] ) ) { |
|
233 | - $product->set_short_description( wp_filter_post_kses( $request['short_description'] ) ); |
|
232 | + if (isset($request['short_description'])) { |
|
233 | + $product->set_short_description(wp_filter_post_kses($request['short_description'])); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | // Post status. |
237 | - if ( isset( $request['status'] ) ) { |
|
238 | - $product->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' ); |
|
237 | + if (isset($request['status'])) { |
|
238 | + $product->set_status(get_post_status_object($request['status']) ? $request['status'] : 'draft'); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | // Post slug. |
242 | - if ( isset( $request['slug'] ) ) { |
|
243 | - $product->set_slug( $request['slug'] ); |
|
242 | + if (isset($request['slug'])) { |
|
243 | + $product->set_slug($request['slug']); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | // Menu order. |
247 | - if ( isset( $request['menu_order'] ) ) { |
|
248 | - $product->set_menu_order( $request['menu_order'] ); |
|
247 | + if (isset($request['menu_order'])) { |
|
248 | + $product->set_menu_order($request['menu_order']); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | // Comment status. |
252 | - if ( isset( $request['reviews_allowed'] ) ) { |
|
253 | - $product->set_reviews_allowed( $request['reviews_allowed'] ); |
|
252 | + if (isset($request['reviews_allowed'])) { |
|
253 | + $product->set_reviews_allowed($request['reviews_allowed']); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | // Virtual. |
257 | - if ( isset( $request['virtual'] ) ) { |
|
258 | - $product->set_virtual( $request['virtual'] ); |
|
257 | + if (isset($request['virtual'])) { |
|
258 | + $product->set_virtual($request['virtual']); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | // Tax status. |
262 | - if ( isset( $request['tax_status'] ) ) { |
|
263 | - $product->set_tax_status( $request['tax_status'] ); |
|
262 | + if (isset($request['tax_status'])) { |
|
263 | + $product->set_tax_status($request['tax_status']); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | // Tax Class. |
267 | - if ( isset( $request['tax_class'] ) ) { |
|
268 | - $product->set_tax_class( $request['tax_class'] ); |
|
267 | + if (isset($request['tax_class'])) { |
|
268 | + $product->set_tax_class($request['tax_class']); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | // Catalog Visibility. |
272 | - if ( isset( $request['catalog_visibility'] ) ) { |
|
273 | - $product->set_catalog_visibility( $request['catalog_visibility'] ); |
|
272 | + if (isset($request['catalog_visibility'])) { |
|
273 | + $product->set_catalog_visibility($request['catalog_visibility']); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | // Purchase Note. |
277 | - if ( isset( $request['purchase_note'] ) ) { |
|
278 | - $product->set_purchase_note( wp_kses_post( wp_unslash( $request['purchase_note'] ) ) ); |
|
277 | + if (isset($request['purchase_note'])) { |
|
278 | + $product->set_purchase_note(wp_kses_post(wp_unslash($request['purchase_note']))); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | // Featured Product. |
282 | - if ( isset( $request['featured'] ) ) { |
|
283 | - $product->set_featured( $request['featured'] ); |
|
282 | + if (isset($request['featured'])) { |
|
283 | + $product->set_featured($request['featured']); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Shipping data. |
287 | - $product = $this->save_product_shipping_data( $product, $request ); |
|
287 | + $product = $this->save_product_shipping_data($product, $request); |
|
288 | 288 | |
289 | 289 | // SKU. |
290 | - if ( isset( $request['sku'] ) ) { |
|
291 | - $product->set_sku( wc_clean( $request['sku'] ) ); |
|
290 | + if (isset($request['sku'])) { |
|
291 | + $product->set_sku(wc_clean($request['sku'])); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | // Attributes. |
295 | - if ( isset( $request['attributes'] ) ) { |
|
295 | + if (isset($request['attributes'])) { |
|
296 | 296 | $attributes = array(); |
297 | 297 | |
298 | - foreach ( $request['attributes'] as $attribute ) { |
|
298 | + foreach ($request['attributes'] as $attribute) { |
|
299 | 299 | $attribute_id = 0; |
300 | 300 | $attribute_name = ''; |
301 | 301 | |
302 | 302 | // Check ID for global attributes or name for product attributes. |
303 | - if ( ! empty( $attribute['id'] ) ) { |
|
304 | - $attribute_id = absint( $attribute['id'] ); |
|
305 | - $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
|
306 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
307 | - $attribute_name = wc_clean( $attribute['name'] ); |
|
303 | + if ( ! empty($attribute['id'])) { |
|
304 | + $attribute_id = absint($attribute['id']); |
|
305 | + $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id); |
|
306 | + } elseif ( ! empty($attribute['name'])) { |
|
307 | + $attribute_name = wc_clean($attribute['name']); |
|
308 | 308 | } |
309 | 309 | |
310 | - if ( ! $attribute_id && ! $attribute_name ) { |
|
310 | + if ( ! $attribute_id && ! $attribute_name) { |
|
311 | 311 | continue; |
312 | 312 | } |
313 | 313 | |
314 | - if ( $attribute_id ) { |
|
314 | + if ($attribute_id) { |
|
315 | 315 | |
316 | - if ( isset( $attribute['options'] ) ) { |
|
316 | + if (isset($attribute['options'])) { |
|
317 | 317 | $options = $attribute['options']; |
318 | 318 | |
319 | - if ( ! is_array( $attribute['options'] ) ) { |
|
319 | + if ( ! is_array($attribute['options'])) { |
|
320 | 320 | // Text based attributes - Posted values are term names. |
321 | - $options = explode( WC_DELIMITER, $options ); |
|
321 | + $options = explode(WC_DELIMITER, $options); |
|
322 | 322 | } |
323 | 323 | |
324 | - $values = array_map( 'wc_sanitize_term_text_based', $options ); |
|
325 | - $values = array_filter( $values, 'strlen' ); |
|
324 | + $values = array_map('wc_sanitize_term_text_based', $options); |
|
325 | + $values = array_filter($values, 'strlen'); |
|
326 | 326 | } else { |
327 | 327 | $values = array(); |
328 | 328 | } |
329 | 329 | |
330 | - if ( ! empty( $values ) ) { |
|
330 | + if ( ! empty($values)) { |
|
331 | 331 | // Add attribute to array, but don't set values. |
332 | 332 | $attribute_object = new \WC_Product_Attribute(); |
333 | - $attribute_object->set_id( $attribute_id ); |
|
334 | - $attribute_object->set_name( $attribute_name ); |
|
335 | - $attribute_object->set_options( $values ); |
|
336 | - $attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' ); |
|
337 | - $attribute_object->set_visible( ( isset( $attribute['visible'] ) && $attribute['visible'] ) ? 1 : 0 ); |
|
338 | - $attribute_object->set_variation( ( isset( $attribute['variation'] ) && $attribute['variation'] ) ? 1 : 0 ); |
|
333 | + $attribute_object->set_id($attribute_id); |
|
334 | + $attribute_object->set_name($attribute_name); |
|
335 | + $attribute_object->set_options($values); |
|
336 | + $attribute_object->set_position(isset($attribute['position']) ? (string) absint($attribute['position']) : '0'); |
|
337 | + $attribute_object->set_visible((isset($attribute['visible']) && $attribute['visible']) ? 1 : 0); |
|
338 | + $attribute_object->set_variation((isset($attribute['variation']) && $attribute['variation']) ? 1 : 0); |
|
339 | 339 | $attributes[] = $attribute_object; |
340 | 340 | } |
341 | - } elseif ( isset( $attribute['options'] ) ) { |
|
341 | + } elseif (isset($attribute['options'])) { |
|
342 | 342 | // Custom attribute - Add attribute to array and set the values. |
343 | - if ( is_array( $attribute['options'] ) ) { |
|
343 | + if (is_array($attribute['options'])) { |
|
344 | 344 | $values = $attribute['options']; |
345 | 345 | } else { |
346 | - $values = explode( WC_DELIMITER, $attribute['options'] ); |
|
346 | + $values = explode(WC_DELIMITER, $attribute['options']); |
|
347 | 347 | } |
348 | 348 | $attribute_object = new \WC_Product_Attribute(); |
349 | - $attribute_object->set_name( $attribute_name ); |
|
350 | - $attribute_object->set_options( $values ); |
|
351 | - $attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' ); |
|
352 | - $attribute_object->set_visible( ( isset( $attribute['visible'] ) && $attribute['visible'] ) ? 1 : 0 ); |
|
353 | - $attribute_object->set_variation( ( isset( $attribute['variation'] ) && $attribute['variation'] ) ? 1 : 0 ); |
|
349 | + $attribute_object->set_name($attribute_name); |
|
350 | + $attribute_object->set_options($values); |
|
351 | + $attribute_object->set_position(isset($attribute['position']) ? (string) absint($attribute['position']) : '0'); |
|
352 | + $attribute_object->set_visible((isset($attribute['visible']) && $attribute['visible']) ? 1 : 0); |
|
353 | + $attribute_object->set_variation((isset($attribute['variation']) && $attribute['variation']) ? 1 : 0); |
|
354 | 354 | $attributes[] = $attribute_object; |
355 | 355 | } |
356 | 356 | } |
357 | - $product->set_attributes( $attributes ); |
|
357 | + $product->set_attributes($attributes); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | // Sales and prices. |
361 | - if ( in_array( $product->get_type(), array( 'variable', 'grouped' ), true ) ) { |
|
362 | - $product->set_regular_price( '' ); |
|
363 | - $product->set_sale_price( '' ); |
|
364 | - $product->set_date_on_sale_to( '' ); |
|
365 | - $product->set_date_on_sale_from( '' ); |
|
366 | - $product->set_price( '' ); |
|
361 | + if (in_array($product->get_type(), array('variable', 'grouped'), true)) { |
|
362 | + $product->set_regular_price(''); |
|
363 | + $product->set_sale_price(''); |
|
364 | + $product->set_date_on_sale_to(''); |
|
365 | + $product->set_date_on_sale_from(''); |
|
366 | + $product->set_price(''); |
|
367 | 367 | } else { |
368 | 368 | // Regular Price. |
369 | - if ( isset( $request['regular_price'] ) ) { |
|
370 | - $product->set_regular_price( $request['regular_price'] ); |
|
369 | + if (isset($request['regular_price'])) { |
|
370 | + $product->set_regular_price($request['regular_price']); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | // Sale Price. |
374 | - if ( isset( $request['sale_price'] ) ) { |
|
375 | - $product->set_sale_price( $request['sale_price'] ); |
|
374 | + if (isset($request['sale_price'])) { |
|
375 | + $product->set_sale_price($request['sale_price']); |
|
376 | 376 | } |
377 | 377 | |
378 | - if ( isset( $request['date_on_sale_from'] ) ) { |
|
379 | - $product->set_date_on_sale_from( $request['date_on_sale_from'] ); |
|
378 | + if (isset($request['date_on_sale_from'])) { |
|
379 | + $product->set_date_on_sale_from($request['date_on_sale_from']); |
|
380 | 380 | } |
381 | 381 | |
382 | - if ( isset( $request['date_on_sale_from_gmt'] ) ) { |
|
383 | - $product->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null ); |
|
382 | + if (isset($request['date_on_sale_from_gmt'])) { |
|
383 | + $product->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null); |
|
384 | 384 | } |
385 | 385 | |
386 | - if ( isset( $request['date_on_sale_to'] ) ) { |
|
387 | - $product->set_date_on_sale_to( $request['date_on_sale_to'] ); |
|
386 | + if (isset($request['date_on_sale_to'])) { |
|
387 | + $product->set_date_on_sale_to($request['date_on_sale_to']); |
|
388 | 388 | } |
389 | 389 | |
390 | - if ( isset( $request['date_on_sale_to_gmt'] ) ) { |
|
391 | - $product->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null ); |
|
390 | + if (isset($request['date_on_sale_to_gmt'])) { |
|
391 | + $product->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null); |
|
392 | 392 | } |
393 | 393 | } |
394 | 394 | |
395 | 395 | // Product parent ID. |
396 | - if ( isset( $request['parent_id'] ) ) { |
|
397 | - $product->set_parent_id( $request['parent_id'] ); |
|
396 | + if (isset($request['parent_id'])) { |
|
397 | + $product->set_parent_id($request['parent_id']); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | // Sold individually. |
401 | - if ( isset( $request['sold_individually'] ) ) { |
|
402 | - $product->set_sold_individually( $request['sold_individually'] ); |
|
401 | + if (isset($request['sold_individually'])) { |
|
402 | + $product->set_sold_individually($request['sold_individually']); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | // Stock status; stock_status has priority over in_stock. |
406 | - if ( isset( $request['stock_status'] ) ) { |
|
406 | + if (isset($request['stock_status'])) { |
|
407 | 407 | $stock_status = $request['stock_status']; |
408 | 408 | } else { |
409 | 409 | $stock_status = $product->get_stock_status(); |
410 | 410 | } |
411 | 411 | |
412 | 412 | // Stock data. |
413 | - if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) { |
|
413 | + if ('yes' === get_option('woocommerce_manage_stock')) { |
|
414 | 414 | // Manage stock. |
415 | - if ( isset( $request['manage_stock'] ) ) { |
|
416 | - $product->set_manage_stock( $request['manage_stock'] ); |
|
415 | + if (isset($request['manage_stock'])) { |
|
416 | + $product->set_manage_stock($request['manage_stock']); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | // Backorders. |
420 | - if ( isset( $request['backorders'] ) ) { |
|
421 | - $product->set_backorders( $request['backorders'] ); |
|
420 | + if (isset($request['backorders'])) { |
|
421 | + $product->set_backorders($request['backorders']); |
|
422 | 422 | } |
423 | 423 | |
424 | - if ( $product->is_type( 'grouped' ) ) { |
|
425 | - $product->set_manage_stock( 'no' ); |
|
426 | - $product->set_backorders( 'no' ); |
|
427 | - $product->set_stock_quantity( '' ); |
|
428 | - $product->set_stock_status( $stock_status ); |
|
429 | - } elseif ( $product->is_type( 'external' ) ) { |
|
430 | - $product->set_manage_stock( 'no' ); |
|
431 | - $product->set_backorders( 'no' ); |
|
432 | - $product->set_stock_quantity( '' ); |
|
433 | - $product->set_stock_status( 'instock' ); |
|
434 | - } elseif ( $product->get_manage_stock() ) { |
|
424 | + if ($product->is_type('grouped')) { |
|
425 | + $product->set_manage_stock('no'); |
|
426 | + $product->set_backorders('no'); |
|
427 | + $product->set_stock_quantity(''); |
|
428 | + $product->set_stock_status($stock_status); |
|
429 | + } elseif ($product->is_type('external')) { |
|
430 | + $product->set_manage_stock('no'); |
|
431 | + $product->set_backorders('no'); |
|
432 | + $product->set_stock_quantity(''); |
|
433 | + $product->set_stock_status('instock'); |
|
434 | + } elseif ($product->get_manage_stock()) { |
|
435 | 435 | // Stock status is always determined by children so sync later. |
436 | - if ( ! $product->is_type( 'variable' ) ) { |
|
437 | - $product->set_stock_status( $stock_status ); |
|
436 | + if ( ! $product->is_type('variable')) { |
|
437 | + $product->set_stock_status($stock_status); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | // Stock quantity. |
441 | - if ( isset( $request['stock_quantity'] ) ) { |
|
442 | - $product->set_stock_quantity( wc_stock_amount( $request['stock_quantity'] ) ); |
|
443 | - } elseif ( isset( $request['inventory_delta'] ) ) { |
|
444 | - $stock_quantity = wc_stock_amount( $product->get_stock_quantity() ); |
|
445 | - $stock_quantity += wc_stock_amount( $request['inventory_delta'] ); |
|
446 | - $product->set_stock_quantity( wc_stock_amount( $stock_quantity ) ); |
|
441 | + if (isset($request['stock_quantity'])) { |
|
442 | + $product->set_stock_quantity(wc_stock_amount($request['stock_quantity'])); |
|
443 | + } elseif (isset($request['inventory_delta'])) { |
|
444 | + $stock_quantity = wc_stock_amount($product->get_stock_quantity()); |
|
445 | + $stock_quantity += wc_stock_amount($request['inventory_delta']); |
|
446 | + $product->set_stock_quantity(wc_stock_amount($stock_quantity)); |
|
447 | 447 | } |
448 | 448 | } else { |
449 | 449 | // Don't manage stock. |
450 | - $product->set_manage_stock( 'no' ); |
|
451 | - $product->set_stock_quantity( '' ); |
|
452 | - $product->set_stock_status( $stock_status ); |
|
450 | + $product->set_manage_stock('no'); |
|
451 | + $product->set_stock_quantity(''); |
|
452 | + $product->set_stock_status($stock_status); |
|
453 | 453 | } |
454 | - } elseif ( ! $product->is_type( 'variable' ) ) { |
|
455 | - $product->set_stock_status( $stock_status ); |
|
454 | + } elseif ( ! $product->is_type('variable')) { |
|
455 | + $product->set_stock_status($stock_status); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | // Upsells. |
459 | - if ( isset( $request['upsell_ids'] ) ) { |
|
459 | + if (isset($request['upsell_ids'])) { |
|
460 | 460 | $upsells = array(); |
461 | 461 | $ids = $request['upsell_ids']; |
462 | 462 | |
463 | - if ( ! empty( $ids ) ) { |
|
464 | - foreach ( $ids as $id ) { |
|
465 | - if ( $id && $id > 0 ) { |
|
463 | + if ( ! empty($ids)) { |
|
464 | + foreach ($ids as $id) { |
|
465 | + if ($id && $id > 0) { |
|
466 | 466 | $upsells[] = $id; |
467 | 467 | } |
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
471 | - $product->set_upsell_ids( $upsells ); |
|
471 | + $product->set_upsell_ids($upsells); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | // Cross sells. |
475 | - if ( isset( $request['cross_sell_ids'] ) ) { |
|
475 | + if (isset($request['cross_sell_ids'])) { |
|
476 | 476 | $crosssells = array(); |
477 | 477 | $ids = $request['cross_sell_ids']; |
478 | 478 | |
479 | - if ( ! empty( $ids ) ) { |
|
480 | - foreach ( $ids as $id ) { |
|
481 | - if ( $id && $id > 0 ) { |
|
479 | + if ( ! empty($ids)) { |
|
480 | + foreach ($ids as $id) { |
|
481 | + if ($id && $id > 0) { |
|
482 | 482 | $crosssells[] = $id; |
483 | 483 | } |
484 | 484 | } |
485 | 485 | } |
486 | 486 | |
487 | - $product->set_cross_sell_ids( $crosssells ); |
|
487 | + $product->set_cross_sell_ids($crosssells); |
|
488 | 488 | } |
489 | 489 | |
490 | 490 | // Product categories. |
491 | - if ( isset( $request['categories'] ) && is_array( $request['categories'] ) ) { |
|
492 | - $product = $this->save_taxonomy_terms( $product, $request['categories'] ); |
|
491 | + if (isset($request['categories']) && is_array($request['categories'])) { |
|
492 | + $product = $this->save_taxonomy_terms($product, $request['categories']); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | // Product tags. |
496 | - if ( isset( $request['tags'] ) && is_array( $request['tags'] ) ) { |
|
497 | - $product = $this->save_taxonomy_terms( $product, $request['tags'], 'tag' ); |
|
496 | + if (isset($request['tags']) && is_array($request['tags'])) { |
|
497 | + $product = $this->save_taxonomy_terms($product, $request['tags'], 'tag'); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | // Downloadable. |
501 | - if ( isset( $request['downloadable'] ) ) { |
|
502 | - $product->set_downloadable( $request['downloadable'] ); |
|
501 | + if (isset($request['downloadable'])) { |
|
502 | + $product->set_downloadable($request['downloadable']); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | // Downloadable options. |
506 | - if ( $product->get_downloadable() ) { |
|
506 | + if ($product->get_downloadable()) { |
|
507 | 507 | |
508 | 508 | // Downloadable files. |
509 | - if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) { |
|
510 | - $product = $this->save_downloadable_files( $product, $request['downloads'] ); |
|
509 | + if (isset($request['downloads']) && is_array($request['downloads'])) { |
|
510 | + $product = $this->save_downloadable_files($product, $request['downloads']); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | // Download limit. |
514 | - if ( isset( $request['download_limit'] ) ) { |
|
515 | - $product->set_download_limit( $request['download_limit'] ); |
|
514 | + if (isset($request['download_limit'])) { |
|
515 | + $product->set_download_limit($request['download_limit']); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | // Download expiry. |
519 | - if ( isset( $request['download_expiry'] ) ) { |
|
520 | - $product->set_download_expiry( $request['download_expiry'] ); |
|
519 | + if (isset($request['download_expiry'])) { |
|
520 | + $product->set_download_expiry($request['download_expiry']); |
|
521 | 521 | } |
522 | 522 | } |
523 | 523 | |
524 | 524 | // Product url and button text for external products. |
525 | - if ( $product->is_type( 'external' ) ) { |
|
526 | - if ( isset( $request['external_url'] ) ) { |
|
527 | - $product->set_product_url( $request['external_url'] ); |
|
525 | + if ($product->is_type('external')) { |
|
526 | + if (isset($request['external_url'])) { |
|
527 | + $product->set_product_url($request['external_url']); |
|
528 | 528 | } |
529 | 529 | |
530 | - if ( isset( $request['button_text'] ) ) { |
|
531 | - $product->set_button_text( $request['button_text'] ); |
|
530 | + if (isset($request['button_text'])) { |
|
531 | + $product->set_button_text($request['button_text']); |
|
532 | 532 | } |
533 | 533 | } |
534 | 534 | |
535 | 535 | // Save default attributes for variable products. |
536 | - if ( $product->is_type( 'variable' ) ) { |
|
537 | - $product = $this->save_default_attributes( $product, $request ); |
|
536 | + if ($product->is_type('variable')) { |
|
537 | + $product = $this->save_default_attributes($product, $request); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | // Set children for a grouped product. |
541 | - if ( $product->is_type( 'grouped' ) && isset( $request['grouped_products'] ) ) { |
|
542 | - $product->set_children( $request['grouped_products'] ); |
|
541 | + if ($product->is_type('grouped') && isset($request['grouped_products'])) { |
|
542 | + $product->set_children($request['grouped_products']); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | // Check for featured/gallery images, upload it and set it. |
546 | - if ( isset( $request['images'] ) ) { |
|
547 | - $product = $this->set_product_images( $product, $request['images'] ); |
|
546 | + if (isset($request['images'])) { |
|
547 | + $product = $this->set_product_images($product, $request['images']); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | // Allow set meta_data. |
551 | - if ( is_array( $request['meta_data'] ) ) { |
|
552 | - foreach ( $request['meta_data'] as $meta ) { |
|
553 | - $product->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
551 | + if (is_array($request['meta_data'])) { |
|
552 | + foreach ($request['meta_data'] as $meta) { |
|
553 | + $product->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | |
557 | - if ( ! empty( $request['date_created'] ) ) { |
|
558 | - $date = rest_parse_date( $request['date_created'] ); |
|
557 | + if ( ! empty($request['date_created'])) { |
|
558 | + $date = rest_parse_date($request['date_created']); |
|
559 | 559 | |
560 | - if ( $date ) { |
|
561 | - $product->set_date_created( $date ); |
|
560 | + if ($date) { |
|
561 | + $product->set_date_created($date); |
|
562 | 562 | } |
563 | 563 | } |
564 | 564 | |
565 | - if ( ! empty( $request['date_created_gmt'] ) ) { |
|
566 | - $date = rest_parse_date( $request['date_created_gmt'], true ); |
|
565 | + if ( ! empty($request['date_created_gmt'])) { |
|
566 | + $date = rest_parse_date($request['date_created_gmt'], true); |
|
567 | 567 | |
568 | - if ( $date ) { |
|
569 | - $product->set_date_created( $date ); |
|
568 | + if ($date) { |
|
569 | + $product->set_date_created($date); |
|
570 | 570 | } |
571 | 571 | } |
572 | 572 | |
573 | - if ( ! empty( $request['search'] ) ) { |
|
574 | - $args['search'] = trim( $request['search'] ); |
|
575 | - unset( $args['s'] ); |
|
573 | + if ( ! empty($request['search'])) { |
|
574 | + $args['search'] = trim($request['search']); |
|
575 | + unset($args['s']); |
|
576 | 576 | } |
577 | 577 | |
578 | - if ( ! empty( $request['low_in_stock'] ) ) { |
|
578 | + if ( ! empty($request['low_in_stock'])) { |
|
579 | 579 | $args['low_in_stock'] = $request['low_in_stock']; |
580 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
580 | + $args['post_type'] = array('product', 'product_variation'); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | * @param \WP_REST_Request $request Request object. |
591 | 591 | * @param bool $creating If is creating a new object. |
592 | 592 | */ |
593 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $product, $request, $creating ); |
|
593 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $product, $request, $creating); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
@@ -599,14 +599,14 @@ discard block |
||
599 | 599 | * @param \WP_REST_Request $request Full details about the request. |
600 | 600 | * @return \WP_Error\WP_REST_Response |
601 | 601 | */ |
602 | - public function get_items( $request ) { |
|
603 | - add_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10, 2 ); |
|
604 | - add_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10, 2 ); |
|
605 | - add_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10, 2 ); |
|
606 | - $response = parent::get_items( $request ); |
|
607 | - remove_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10 ); |
|
608 | - remove_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10 ); |
|
609 | - remove_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10 ); |
|
602 | + public function get_items($request) { |
|
603 | + add_filter('posts_where', array(__CLASS__, 'add_wp_query_filter'), 10, 2); |
|
604 | + add_filter('posts_join', array(__CLASS__, 'add_wp_query_join'), 10, 2); |
|
605 | + add_filter('posts_groupby', array(__CLASS__, 'add_wp_query_group_by'), 10, 2); |
|
606 | + $response = parent::get_items($request); |
|
607 | + remove_filter('posts_where', array(__CLASS__, 'add_wp_query_filter'), 10); |
|
608 | + remove_filter('posts_join', array(__CLASS__, 'add_wp_query_join'), 10); |
|
609 | + remove_filter('posts_groupby', array(__CLASS__, 'add_wp_query_group_by'), 10); |
|
610 | 610 | return $response; |
611 | 611 | } |
612 | 612 | |
@@ -617,19 +617,19 @@ discard block |
||
617 | 617 | * @param object $wp_query \WP_Query object. |
618 | 618 | * @return string |
619 | 619 | */ |
620 | - public static function add_wp_query_filter( $where, $wp_query ) { |
|
620 | + public static function add_wp_query_filter($where, $wp_query) { |
|
621 | 621 | global $wpdb; |
622 | 622 | |
623 | - $search = $wp_query->get( 'search' ); |
|
624 | - if ( $search ) { |
|
625 | - $search = $wpdb->esc_like( $search ); |
|
623 | + $search = $wp_query->get('search'); |
|
624 | + if ($search) { |
|
625 | + $search = $wpdb->esc_like($search); |
|
626 | 626 | $search = "'%" . $search . "%'"; |
627 | 627 | $where .= " AND ({$wpdb->posts}.post_title LIKE {$search}"; |
628 | 628 | $where .= wc_product_sku_enabled() ? ' OR ps_post_meta.meta_key = "_sku" AND ps_post_meta.meta_value LIKE ' . $search . ')' : ')'; |
629 | 629 | } |
630 | 630 | |
631 | - if ( $wp_query->get( 'low_in_stock' ) ) { |
|
632 | - $low_stock_amount = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) ); |
|
631 | + if ($wp_query->get('low_in_stock')) { |
|
632 | + $low_stock_amount = absint(max(get_option('woocommerce_notify_low_stock_amount'), 1)); |
|
633 | 633 | $where .= " AND lis_postmeta2.meta_key = '_manage_stock' |
634 | 634 | AND lis_postmeta2.meta_value = 'yes' |
635 | 635 | AND lis_postmeta.meta_key = '_stock' |
@@ -653,15 +653,15 @@ discard block |
||
653 | 653 | * @param object $wp_query \WP_Query object. |
654 | 654 | * @return string |
655 | 655 | */ |
656 | - public static function add_wp_query_join( $join, $wp_query ) { |
|
656 | + public static function add_wp_query_join($join, $wp_query) { |
|
657 | 657 | global $wpdb; |
658 | 658 | |
659 | - $search = $wp_query->get( 'search' ); |
|
660 | - if ( $search && wc_product_sku_enabled() ) { |
|
659 | + $search = $wp_query->get('search'); |
|
660 | + if ($search && wc_product_sku_enabled()) { |
|
661 | 661 | $join .= " INNER JOIN {$wpdb->postmeta} AS ps_post_meta ON ps_post_meta.post_id = {$wpdb->posts}.ID"; |
662 | 662 | } |
663 | 663 | |
664 | - if ( $wp_query->get( 'low_in_stock' ) ) { |
|
664 | + if ($wp_query->get('low_in_stock')) { |
|
665 | 665 | $join .= " INNER JOIN {$wpdb->postmeta} AS lis_postmeta ON {$wpdb->posts}.ID = lis_postmeta.post_id |
666 | 666 | INNER JOIN {$wpdb->postmeta} AS lis_postmeta2 ON {$wpdb->posts}.ID = lis_postmeta2.post_id |
667 | 667 | INNER JOIN {$wpdb->postmeta} AS lis_postmeta3 ON {$wpdb->posts}.ID = lis_postmeta3.post_id"; |
@@ -677,12 +677,12 @@ discard block |
||
677 | 677 | * @param object $wp_query \WP_Query object. |
678 | 678 | * @return string |
679 | 679 | */ |
680 | - public static function add_wp_query_group_by( $groupby, $wp_query ) { |
|
680 | + public static function add_wp_query_group_by($groupby, $wp_query) { |
|
681 | 681 | global $wpdb; |
682 | 682 | |
683 | - $search = $wp_query->get( 'search' ); |
|
684 | - $low_in_stock = $wp_query->get( 'low_in_stock' ); |
|
685 | - if ( empty( $groupby ) && ( $search || $low_in_stock ) ) { |
|
683 | + $search = $wp_query->get('search'); |
|
684 | + $low_in_stock = $wp_query->get('low_in_stock'); |
|
685 | + if (empty($groupby) && ($search || $low_in_stock)) { |
|
686 | 686 | $groupby = $wpdb->posts . '.ID'; |
687 | 687 | } |
688 | 688 | return $groupby; |
@@ -695,8 +695,8 @@ discard block |
||
695 | 695 | * @param \WP_REST_Request $request Request data. |
696 | 696 | * @return array |
697 | 697 | */ |
698 | - protected function prepare_objects_query( $request ) { |
|
699 | - $args = parent::prepare_objects_query( $request ); |
|
698 | + protected function prepare_objects_query($request) { |
|
699 | + $args = parent::prepare_objects_query($request); |
|
700 | 700 | |
701 | 701 | // Set post_status. |
702 | 702 | $args['post_status'] = $request['status']; |
@@ -713,18 +713,18 @@ discard block |
||
713 | 713 | ); |
714 | 714 | |
715 | 715 | // Set tax_query for each passed arg. |
716 | - foreach ( $taxonomies as $taxonomy => $key ) { |
|
717 | - if ( ! empty( $request[ $key ] ) ) { |
|
716 | + foreach ($taxonomies as $taxonomy => $key) { |
|
717 | + if ( ! empty($request[$key])) { |
|
718 | 718 | $tax_query[] = array( |
719 | 719 | 'taxonomy' => $taxonomy, |
720 | 720 | 'field' => 'term_id', |
721 | - 'terms' => $request[ $key ], |
|
721 | + 'terms' => $request[$key], |
|
722 | 722 | ); |
723 | 723 | } |
724 | 724 | } |
725 | 725 | |
726 | 726 | // Filter product type by slug. |
727 | - if ( ! empty( $request['type'] ) ) { |
|
727 | + if ( ! empty($request['type'])) { |
|
728 | 728 | $tax_query[] = array( |
729 | 729 | 'taxonomy' => 'product_type', |
730 | 730 | 'field' => 'slug', |
@@ -733,8 +733,8 @@ discard block |
||
733 | 733 | } |
734 | 734 | |
735 | 735 | // Filter by attribute and term. |
736 | - if ( ! empty( $request['attribute'] ) && ! empty( $request['attribute_term'] ) ) { |
|
737 | - if ( in_array( $request['attribute'], wc_get_attribute_taxonomy_names(), true ) ) { |
|
736 | + if ( ! empty($request['attribute']) && ! empty($request['attribute_term'])) { |
|
737 | + if (in_array($request['attribute'], wc_get_attribute_taxonomy_names(), true)) { |
|
738 | 738 | $tax_query[] = array( |
739 | 739 | 'taxonomy' => $request['attribute'], |
740 | 740 | 'field' => 'term_id', |
@@ -744,16 +744,16 @@ discard block |
||
744 | 744 | } |
745 | 745 | |
746 | 746 | // Build tax_query if taxonomies are set. |
747 | - if ( ! empty( $tax_query ) ) { |
|
748 | - if ( ! empty( $args['tax_query'] ) ) { |
|
749 | - $args['tax_query'] = array_merge( $tax_query, $args['tax_query'] ); // WPCS: slow query ok. |
|
747 | + if ( ! empty($tax_query)) { |
|
748 | + if ( ! empty($args['tax_query'])) { |
|
749 | + $args['tax_query'] = array_merge($tax_query, $args['tax_query']); // WPCS: slow query ok. |
|
750 | 750 | } else { |
751 | 751 | $args['tax_query'] = $tax_query; // WPCS: slow query ok. |
752 | 752 | } |
753 | 753 | } |
754 | 754 | |
755 | 755 | // Filter featured. |
756 | - if ( is_bool( $request['featured'] ) ) { |
|
756 | + if (is_bool($request['featured'])) { |
|
757 | 757 | $args['tax_query'][] = array( |
758 | 758 | 'taxonomy' => 'product_visibility', |
759 | 759 | 'field' => 'name', |
@@ -763,10 +763,10 @@ discard block |
||
763 | 763 | } |
764 | 764 | |
765 | 765 | // Filter by sku. |
766 | - if ( ! empty( $request['sku'] ) ) { |
|
767 | - $skus = explode( ',', $request['sku'] ); |
|
766 | + if ( ! empty($request['sku'])) { |
|
767 | + $skus = explode(',', $request['sku']); |
|
768 | 768 | // Include the current string as a SKU too. |
769 | - if ( 1 < count( $skus ) ) { |
|
769 | + if (1 < count($skus)) { |
|
770 | 770 | $skus[] = $request['sku']; |
771 | 771 | } |
772 | 772 | |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | } |
782 | 782 | |
783 | 783 | // Filter by tax class. |
784 | - if ( ! empty( $request['tax_class'] ) ) { |
|
784 | + if ( ! empty($request['tax_class'])) { |
|
785 | 785 | $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
786 | 786 | $args, |
787 | 787 | array( |
@@ -792,12 +792,12 @@ discard block |
||
792 | 792 | } |
793 | 793 | |
794 | 794 | // Price filter. |
795 | - if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) { |
|
796 | - $args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) ); // WPCS: slow query ok. |
|
795 | + if ( ! empty($request['min_price']) || ! empty($request['max_price'])) { |
|
796 | + $args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request)); // WPCS: slow query ok. |
|
797 | 797 | } |
798 | 798 | |
799 | 799 | // Filter product by stock_status. |
800 | - if ( ! empty( $request['stock_status'] ) ) { |
|
800 | + if ( ! empty($request['stock_status'])) { |
|
801 | 801 | $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
802 | 802 | $args, |
803 | 803 | array( |
@@ -808,30 +808,30 @@ discard block |
||
808 | 808 | } |
809 | 809 | |
810 | 810 | // Filter by on sale products. |
811 | - if ( is_bool( $request['on_sale'] ) ) { |
|
811 | + if (is_bool($request['on_sale'])) { |
|
812 | 812 | $on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in'; |
813 | 813 | $on_sale_ids = wc_get_product_ids_on_sale(); |
814 | 814 | |
815 | 815 | // Use 0 when there's no on sale products to avoid return all products. |
816 | - $on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids; |
|
816 | + $on_sale_ids = empty($on_sale_ids) ? array(0) : $on_sale_ids; |
|
817 | 817 | |
818 | - $args[ $on_sale_key ] += $on_sale_ids; |
|
818 | + $args[$on_sale_key] += $on_sale_ids; |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | // Force the post_type argument, since it's not a user input variable. |
822 | - if ( ! empty( $request['sku'] ) ) { |
|
823 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
822 | + if ( ! empty($request['sku'])) { |
|
823 | + $args['post_type'] = array('product', 'product_variation'); |
|
824 | 824 | } else { |
825 | 825 | $args['post_type'] = $this->post_type; |
826 | 826 | } |
827 | 827 | |
828 | - $orderby = $request->get_param( 'orderby' ); |
|
829 | - $order = $request->get_param( 'order' ); |
|
828 | + $orderby = $request->get_param('orderby'); |
|
829 | + $order = $request->get_param('order'); |
|
830 | 830 | |
831 | - $ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order ); |
|
831 | + $ordering_args = WC()->query->get_catalog_ordering_args($orderby, $order); |
|
832 | 832 | $args['orderby'] = $ordering_args['orderby']; |
833 | 833 | $args['order'] = $ordering_args['order']; |
834 | - if ( $ordering_args['meta_key'] ) { |
|
834 | + if ($ordering_args['meta_key']) { |
|
835 | 835 | $args['meta_key'] = $ordering_args['meta_key']; // WPCS: slow query ok. |
836 | 836 | } |
837 | 837 | |
@@ -845,11 +845,11 @@ discard block |
||
845 | 845 | * |
846 | 846 | * @return array |
847 | 847 | */ |
848 | - protected function get_downloads( $product ) { |
|
848 | + protected function get_downloads($product) { |
|
849 | 849 | $downloads = array(); |
850 | 850 | |
851 | - if ( $product->is_downloadable() ) { |
|
852 | - foreach ( $product->get_downloads() as $file_id => $file ) { |
|
851 | + if ($product->is_downloadable()) { |
|
852 | + foreach ($product->get_downloads() as $file_id => $file) { |
|
853 | 853 | $downloads[] = array( |
854 | 854 | 'id' => $file_id, // MD5 hash. |
855 | 855 | 'name' => $file['name'], |
@@ -869,10 +869,10 @@ discard block |
||
869 | 869 | * |
870 | 870 | * @return array |
871 | 871 | */ |
872 | - protected function get_taxonomy_terms( $product, $taxonomy = 'cat' ) { |
|
872 | + protected function get_taxonomy_terms($product, $taxonomy = 'cat') { |
|
873 | 873 | $terms = array(); |
874 | 874 | |
875 | - foreach ( wc_get_object_terms( $product->get_id(), 'product_' . $taxonomy ) as $term ) { |
|
875 | + foreach (wc_get_object_terms($product->get_id(), 'product_' . $taxonomy) as $term) { |
|
876 | 876 | $terms[] = array( |
877 | 877 | 'id' => $term->term_id, |
878 | 878 | 'name' => $term->name, |
@@ -889,39 +889,39 @@ discard block |
||
889 | 889 | * @param WC_Product|WC_Product_Variation $product Product instance. |
890 | 890 | * @return array |
891 | 891 | */ |
892 | - protected function get_images( $product ) { |
|
892 | + protected function get_images($product) { |
|
893 | 893 | $images = array(); |
894 | 894 | $attachment_ids = array(); |
895 | 895 | |
896 | 896 | // Add featured image. |
897 | - if ( $product->get_image_id() ) { |
|
897 | + if ($product->get_image_id()) { |
|
898 | 898 | $attachment_ids[] = $product->get_image_id(); |
899 | 899 | } |
900 | 900 | |
901 | 901 | // Add gallery images. |
902 | - $attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() ); |
|
902 | + $attachment_ids = array_merge($attachment_ids, $product->get_gallery_image_ids()); |
|
903 | 903 | |
904 | 904 | // Build image data. |
905 | - foreach ( $attachment_ids as $attachment_id ) { |
|
906 | - $attachment_post = get_post( $attachment_id ); |
|
907 | - if ( is_null( $attachment_post ) ) { |
|
905 | + foreach ($attachment_ids as $attachment_id) { |
|
906 | + $attachment_post = get_post($attachment_id); |
|
907 | + if (is_null($attachment_post)) { |
|
908 | 908 | continue; |
909 | 909 | } |
910 | 910 | |
911 | - $attachment = wp_get_attachment_image_src( $attachment_id, 'full' ); |
|
912 | - if ( ! is_array( $attachment ) ) { |
|
911 | + $attachment = wp_get_attachment_image_src($attachment_id, 'full'); |
|
912 | + if ( ! is_array($attachment)) { |
|
913 | 913 | continue; |
914 | 914 | } |
915 | 915 | |
916 | 916 | $images[] = array( |
917 | 917 | 'id' => (int) $attachment_id, |
918 | - 'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date, false ), |
|
919 | - 'date_created_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ), |
|
920 | - 'date_modified' => wc_rest_prepare_date_response( $attachment_post->post_modified, false ), |
|
921 | - 'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ), |
|
922 | - 'src' => current( $attachment ), |
|
923 | - 'name' => get_the_title( $attachment_id ), |
|
924 | - 'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ), |
|
918 | + 'date_created' => wc_rest_prepare_date_response($attachment_post->post_date, false), |
|
919 | + 'date_created_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_date_gmt)), |
|
920 | + 'date_modified' => wc_rest_prepare_date_response($attachment_post->post_modified, false), |
|
921 | + 'date_modified_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_modified_gmt)), |
|
922 | + 'src' => current($attachment), |
|
923 | + 'name' => get_the_title($attachment_id), |
|
924 | + 'alt' => get_post_meta($attachment_id, '_wp_attachment_image_alt', true), |
|
925 | 925 | ); |
926 | 926 | } |
927 | 927 | |
@@ -936,9 +936,9 @@ discard block |
||
936 | 936 | * @deprecated 3.0.0 |
937 | 937 | * @return string |
938 | 938 | */ |
939 | - protected function get_attribute_taxonomy_label( $name ) { |
|
940 | - $tax = get_taxonomy( $name ); |
|
941 | - $labels = get_taxonomy_labels( $tax ); |
|
939 | + protected function get_attribute_taxonomy_label($name) { |
|
940 | + $tax = get_taxonomy($name); |
|
941 | + $labels = get_taxonomy_labels($tax); |
|
942 | 942 | |
943 | 943 | return $labels->singular_name; |
944 | 944 | } |
@@ -952,25 +952,25 @@ discard block |
||
952 | 952 | * @since 3.0.0 |
953 | 953 | * @return string |
954 | 954 | */ |
955 | - protected function get_attribute_taxonomy_name( $slug, $product ) { |
|
955 | + protected function get_attribute_taxonomy_name($slug, $product) { |
|
956 | 956 | // Format slug so it matches attributes of the product. |
957 | - $slug = wc_attribute_taxonomy_slug( $slug ); |
|
957 | + $slug = wc_attribute_taxonomy_slug($slug); |
|
958 | 958 | $attributes = $product->get_attributes(); |
959 | 959 | $attribute = false; |
960 | 960 | |
961 | 961 | // pa_ attributes. |
962 | - if ( isset( $attributes[ wc_attribute_taxonomy_name( $slug ) ] ) ) { |
|
963 | - $attribute = $attributes[ wc_attribute_taxonomy_name( $slug ) ]; |
|
964 | - } elseif ( isset( $attributes[ $slug ] ) ) { |
|
965 | - $attribute = $attributes[ $slug ]; |
|
962 | + if (isset($attributes[wc_attribute_taxonomy_name($slug)])) { |
|
963 | + $attribute = $attributes[wc_attribute_taxonomy_name($slug)]; |
|
964 | + } elseif (isset($attributes[$slug])) { |
|
965 | + $attribute = $attributes[$slug]; |
|
966 | 966 | } |
967 | 967 | |
968 | - if ( ! $attribute ) { |
|
968 | + if ( ! $attribute) { |
|
969 | 969 | return $slug; |
970 | 970 | } |
971 | 971 | |
972 | 972 | // Taxonomy attribute name. |
973 | - if ( $attribute->is_taxonomy() ) { |
|
973 | + if ($attribute->is_taxonomy()) { |
|
974 | 974 | $taxonomy = $attribute->get_taxonomy_object(); |
975 | 975 | return $taxonomy->attribute_label; |
976 | 976 | } |
@@ -986,21 +986,21 @@ discard block |
||
986 | 986 | * |
987 | 987 | * @return array |
988 | 988 | */ |
989 | - protected function get_default_attributes( $product ) { |
|
989 | + protected function get_default_attributes($product) { |
|
990 | 990 | $default = array(); |
991 | 991 | |
992 | - if ( $product->is_type( 'variable' ) ) { |
|
993 | - foreach ( array_filter( (array) $product->get_default_attributes(), 'strlen' ) as $key => $value ) { |
|
994 | - if ( 0 === strpos( $key, 'pa_' ) ) { |
|
992 | + if ($product->is_type('variable')) { |
|
993 | + foreach (array_filter((array) $product->get_default_attributes(), 'strlen') as $key => $value) { |
|
994 | + if (0 === strpos($key, 'pa_')) { |
|
995 | 995 | $default[] = array( |
996 | - 'id' => wc_attribute_taxonomy_id_by_name( $key ), |
|
997 | - 'name' => $this->get_attribute_taxonomy_name( $key, $product ), |
|
996 | + 'id' => wc_attribute_taxonomy_id_by_name($key), |
|
997 | + 'name' => $this->get_attribute_taxonomy_name($key, $product), |
|
998 | 998 | 'option' => $value, |
999 | 999 | ); |
1000 | 1000 | } else { |
1001 | 1001 | $default[] = array( |
1002 | 1002 | 'id' => 0, |
1003 | - 'name' => $this->get_attribute_taxonomy_name( $key, $product ), |
|
1003 | + 'name' => $this->get_attribute_taxonomy_name($key, $product), |
|
1004 | 1004 | 'option' => $value, |
1005 | 1005 | ); |
1006 | 1006 | } |
@@ -1018,8 +1018,8 @@ discard block |
||
1018 | 1018 | * |
1019 | 1019 | * @return array |
1020 | 1020 | */ |
1021 | - protected function get_attribute_options( $product_id, $attribute ) { |
|
1022 | - if ( isset( $attribute['is_taxonomy'] ) && $attribute['is_taxonomy'] ) { |
|
1021 | + protected function get_attribute_options($product_id, $attribute) { |
|
1022 | + if (isset($attribute['is_taxonomy']) && $attribute['is_taxonomy']) { |
|
1023 | 1023 | return wc_get_product_terms( |
1024 | 1024 | $product_id, |
1025 | 1025 | $attribute['name'], |
@@ -1027,8 +1027,8 @@ discard block |
||
1027 | 1027 | 'fields' => 'names', |
1028 | 1028 | ) |
1029 | 1029 | ); |
1030 | - } elseif ( isset( $attribute['value'] ) ) { |
|
1031 | - return array_map( 'trim', explode( '|', $attribute['value'] ) ); |
|
1030 | + } elseif (isset($attribute['value'])) { |
|
1031 | + return array_map('trim', explode('|', $attribute['value'])); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | return array(); |
@@ -1041,43 +1041,43 @@ discard block |
||
1041 | 1041 | * |
1042 | 1042 | * @return array |
1043 | 1043 | */ |
1044 | - protected function get_attributes( $product ) { |
|
1044 | + protected function get_attributes($product) { |
|
1045 | 1045 | $attributes = array(); |
1046 | 1046 | |
1047 | - if ( $product->is_type( 'variation' ) ) { |
|
1048 | - $_product = wc_get_product( $product->get_parent_id() ); |
|
1049 | - foreach ( $product->get_variation_attributes() as $attribute_name => $attribute ) { |
|
1050 | - $name = str_replace( 'attribute_', '', $attribute_name ); |
|
1047 | + if ($product->is_type('variation')) { |
|
1048 | + $_product = wc_get_product($product->get_parent_id()); |
|
1049 | + foreach ($product->get_variation_attributes() as $attribute_name => $attribute) { |
|
1050 | + $name = str_replace('attribute_', '', $attribute_name); |
|
1051 | 1051 | |
1052 | - if ( empty( $attribute ) && '0' !== $attribute ) { |
|
1052 | + if (empty($attribute) && '0' !== $attribute) { |
|
1053 | 1053 | continue; |
1054 | 1054 | } |
1055 | 1055 | |
1056 | 1056 | // Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`. |
1057 | - if ( 0 === strpos( $attribute_name, 'attribute_pa_' ) ) { |
|
1058 | - $option_term = get_term_by( 'slug', $attribute, $name ); |
|
1057 | + if (0 === strpos($attribute_name, 'attribute_pa_')) { |
|
1058 | + $option_term = get_term_by('slug', $attribute, $name); |
|
1059 | 1059 | $attributes[] = array( |
1060 | - 'id' => wc_attribute_taxonomy_id_by_name( $name ), |
|
1061 | - 'name' => $this->get_attribute_taxonomy_name( $name, $_product ), |
|
1062 | - 'option' => $option_term && ! is_wp_error( $option_term ) ? $option_term->name : $attribute, |
|
1060 | + 'id' => wc_attribute_taxonomy_id_by_name($name), |
|
1061 | + 'name' => $this->get_attribute_taxonomy_name($name, $_product), |
|
1062 | + 'option' => $option_term && ! is_wp_error($option_term) ? $option_term->name : $attribute, |
|
1063 | 1063 | ); |
1064 | 1064 | } else { |
1065 | 1065 | $attributes[] = array( |
1066 | 1066 | 'id' => 0, |
1067 | - 'name' => $this->get_attribute_taxonomy_name( $name, $_product ), |
|
1067 | + 'name' => $this->get_attribute_taxonomy_name($name, $_product), |
|
1068 | 1068 | 'option' => $attribute, |
1069 | 1069 | ); |
1070 | 1070 | } |
1071 | 1071 | } |
1072 | 1072 | } else { |
1073 | - foreach ( $product->get_attributes() as $attribute ) { |
|
1073 | + foreach ($product->get_attributes() as $attribute) { |
|
1074 | 1074 | $attributes[] = array( |
1075 | - 'id' => $attribute['is_taxonomy'] ? wc_attribute_taxonomy_id_by_name( $attribute['name'] ) : 0, |
|
1076 | - 'name' => $this->get_attribute_taxonomy_name( $attribute['name'], $product ), |
|
1075 | + 'id' => $attribute['is_taxonomy'] ? wc_attribute_taxonomy_id_by_name($attribute['name']) : 0, |
|
1076 | + 'name' => $this->get_attribute_taxonomy_name($attribute['name'], $product), |
|
1077 | 1077 | 'position' => (int) $attribute['position'], |
1078 | 1078 | 'visible' => (bool) $attribute['is_visible'], |
1079 | 1079 | 'variation' => (bool) $attribute['is_variation'], |
1080 | - 'options' => $this->get_attribute_options( $product->get_id(), $attribute ), |
|
1080 | + 'options' => $this->get_attribute_options($product->get_id(), $attribute), |
|
1081 | 1081 | ); |
1082 | 1082 | } |
1083 | 1083 | } |
@@ -1094,76 +1094,76 @@ discard block |
||
1094 | 1094 | * |
1095 | 1095 | * @return array |
1096 | 1096 | */ |
1097 | - protected function get_product_data( $product, $context = 'view' ) { |
|
1097 | + protected function get_product_data($product, $context = 'view') { |
|
1098 | 1098 | $data = array( |
1099 | 1099 | 'id' => $product->get_id(), |
1100 | - 'name' => $product->get_name( $context ), |
|
1101 | - 'slug' => $product->get_slug( $context ), |
|
1100 | + 'name' => $product->get_name($context), |
|
1101 | + 'slug' => $product->get_slug($context), |
|
1102 | 1102 | 'permalink' => $product->get_permalink(), |
1103 | - 'date_created' => wc_rest_prepare_date_response( $product->get_date_created( $context ), false ), |
|
1104 | - 'date_created_gmt' => wc_rest_prepare_date_response( $product->get_date_created( $context ) ), |
|
1105 | - 'date_modified' => wc_rest_prepare_date_response( $product->get_date_modified( $context ), false ), |
|
1106 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $product->get_date_modified( $context ) ), |
|
1103 | + 'date_created' => wc_rest_prepare_date_response($product->get_date_created($context), false), |
|
1104 | + 'date_created_gmt' => wc_rest_prepare_date_response($product->get_date_created($context)), |
|
1105 | + 'date_modified' => wc_rest_prepare_date_response($product->get_date_modified($context), false), |
|
1106 | + 'date_modified_gmt' => wc_rest_prepare_date_response($product->get_date_modified($context)), |
|
1107 | 1107 | 'type' => $product->get_type(), |
1108 | - 'status' => $product->get_status( $context ), |
|
1108 | + 'status' => $product->get_status($context), |
|
1109 | 1109 | 'featured' => $product->is_featured(), |
1110 | - 'catalog_visibility' => $product->get_catalog_visibility( $context ), |
|
1111 | - 'description' => 'view' === $context ? wpautop( do_shortcode( $product->get_description() ) ) : $product->get_description( $context ), |
|
1112 | - 'short_description' => 'view' === $context ? apply_filters( 'woocommerce_short_description', $product->get_short_description() ) : $product->get_short_description( $context ), |
|
1113 | - 'sku' => $product->get_sku( $context ), |
|
1114 | - 'price' => $product->get_price( $context ), |
|
1115 | - 'regular_price' => $product->get_regular_price( $context ), |
|
1116 | - 'sale_price' => $product->get_sale_price( $context ) ? $product->get_sale_price( $context ) : '', |
|
1117 | - 'date_on_sale_from' => wc_rest_prepare_date_response( $product->get_date_on_sale_from( $context ), false ), |
|
1118 | - 'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $product->get_date_on_sale_from( $context ) ), |
|
1119 | - 'date_on_sale_to' => wc_rest_prepare_date_response( $product->get_date_on_sale_to( $context ), false ), |
|
1120 | - 'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $product->get_date_on_sale_to( $context ) ), |
|
1110 | + 'catalog_visibility' => $product->get_catalog_visibility($context), |
|
1111 | + 'description' => 'view' === $context ? wpautop(do_shortcode($product->get_description())) : $product->get_description($context), |
|
1112 | + 'short_description' => 'view' === $context ? apply_filters('woocommerce_short_description', $product->get_short_description()) : $product->get_short_description($context), |
|
1113 | + 'sku' => $product->get_sku($context), |
|
1114 | + 'price' => $product->get_price($context), |
|
1115 | + 'regular_price' => $product->get_regular_price($context), |
|
1116 | + 'sale_price' => $product->get_sale_price($context) ? $product->get_sale_price($context) : '', |
|
1117 | + 'date_on_sale_from' => wc_rest_prepare_date_response($product->get_date_on_sale_from($context), false), |
|
1118 | + 'date_on_sale_from_gmt' => wc_rest_prepare_date_response($product->get_date_on_sale_from($context)), |
|
1119 | + 'date_on_sale_to' => wc_rest_prepare_date_response($product->get_date_on_sale_to($context), false), |
|
1120 | + 'date_on_sale_to_gmt' => wc_rest_prepare_date_response($product->get_date_on_sale_to($context)), |
|
1121 | 1121 | 'price_html' => $product->get_price_html(), |
1122 | - 'on_sale' => $product->is_on_sale( $context ), |
|
1122 | + 'on_sale' => $product->is_on_sale($context), |
|
1123 | 1123 | 'purchasable' => $product->is_purchasable(), |
1124 | - 'total_sales' => $product->get_total_sales( $context ), |
|
1124 | + 'total_sales' => $product->get_total_sales($context), |
|
1125 | 1125 | 'virtual' => $product->is_virtual(), |
1126 | 1126 | 'downloadable' => $product->is_downloadable(), |
1127 | - 'downloads' => $this->get_downloads( $product ), |
|
1128 | - 'download_limit' => $product->get_download_limit( $context ), |
|
1129 | - 'download_expiry' => $product->get_download_expiry( $context ), |
|
1130 | - 'external_url' => $product->is_type( 'external' ) ? $product->get_product_url( $context ) : '', |
|
1131 | - 'button_text' => $product->is_type( 'external' ) ? $product->get_button_text( $context ) : '', |
|
1132 | - 'tax_status' => $product->get_tax_status( $context ), |
|
1133 | - 'tax_class' => $product->get_tax_class( $context ), |
|
1127 | + 'downloads' => $this->get_downloads($product), |
|
1128 | + 'download_limit' => $product->get_download_limit($context), |
|
1129 | + 'download_expiry' => $product->get_download_expiry($context), |
|
1130 | + 'external_url' => $product->is_type('external') ? $product->get_product_url($context) : '', |
|
1131 | + 'button_text' => $product->is_type('external') ? $product->get_button_text($context) : '', |
|
1132 | + 'tax_status' => $product->get_tax_status($context), |
|
1133 | + 'tax_class' => $product->get_tax_class($context), |
|
1134 | 1134 | 'manage_stock' => $product->managing_stock(), |
1135 | - 'stock_quantity' => $product->get_stock_quantity( $context ), |
|
1136 | - 'stock_status' => $product->get_stock_status( $context ), |
|
1137 | - 'backorders' => $product->get_backorders( $context ), |
|
1135 | + 'stock_quantity' => $product->get_stock_quantity($context), |
|
1136 | + 'stock_status' => $product->get_stock_status($context), |
|
1137 | + 'backorders' => $product->get_backorders($context), |
|
1138 | 1138 | 'backorders_allowed' => $product->backorders_allowed(), |
1139 | 1139 | 'backordered' => $product->is_on_backorder(), |
1140 | 1140 | 'sold_individually' => $product->is_sold_individually(), |
1141 | - 'weight' => $product->get_weight( $context ), |
|
1141 | + 'weight' => $product->get_weight($context), |
|
1142 | 1142 | 'dimensions' => array( |
1143 | - 'length' => $product->get_length( $context ), |
|
1144 | - 'width' => $product->get_width( $context ), |
|
1145 | - 'height' => $product->get_height( $context ), |
|
1143 | + 'length' => $product->get_length($context), |
|
1144 | + 'width' => $product->get_width($context), |
|
1145 | + 'height' => $product->get_height($context), |
|
1146 | 1146 | ), |
1147 | 1147 | 'shipping_required' => $product->needs_shipping(), |
1148 | 1148 | 'shipping_taxable' => $product->is_shipping_taxable(), |
1149 | 1149 | 'shipping_class' => $product->get_shipping_class(), |
1150 | - 'shipping_class_id' => $product->get_shipping_class_id( $context ), |
|
1151 | - 'reviews_allowed' => $product->get_reviews_allowed( $context ), |
|
1152 | - 'average_rating' => 'view' === $context ? wc_format_decimal( $product->get_average_rating(), 2 ) : $product->get_average_rating( $context ), |
|
1150 | + 'shipping_class_id' => $product->get_shipping_class_id($context), |
|
1151 | + 'reviews_allowed' => $product->get_reviews_allowed($context), |
|
1152 | + 'average_rating' => 'view' === $context ? wc_format_decimal($product->get_average_rating(), 2) : $product->get_average_rating($context), |
|
1153 | 1153 | 'rating_count' => $product->get_rating_count(), |
1154 | - 'related_ids' => array_map( 'absint', array_values( wc_get_related_products( $product->get_id() ) ) ), |
|
1155 | - 'upsell_ids' => array_map( 'absint', $product->get_upsell_ids( $context ) ), |
|
1156 | - 'cross_sell_ids' => array_map( 'absint', $product->get_cross_sell_ids( $context ) ), |
|
1157 | - 'parent_id' => $product->get_parent_id( $context ), |
|
1158 | - 'purchase_note' => 'view' === $context ? wpautop( do_shortcode( wp_kses_post( $product->get_purchase_note() ) ) ) : $product->get_purchase_note( $context ), |
|
1159 | - 'categories' => $this->get_taxonomy_terms( $product ), |
|
1160 | - 'tags' => $this->get_taxonomy_terms( $product, 'tag' ), |
|
1161 | - 'images' => $this->get_images( $product ), |
|
1162 | - 'attributes' => $this->get_attributes( $product ), |
|
1163 | - 'default_attributes' => $this->get_default_attributes( $product ), |
|
1154 | + 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), |
|
1155 | + 'upsell_ids' => array_map('absint', $product->get_upsell_ids($context)), |
|
1156 | + 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids($context)), |
|
1157 | + 'parent_id' => $product->get_parent_id($context), |
|
1158 | + 'purchase_note' => 'view' === $context ? wpautop(do_shortcode(wp_kses_post($product->get_purchase_note()))) : $product->get_purchase_note($context), |
|
1159 | + 'categories' => $this->get_taxonomy_terms($product), |
|
1160 | + 'tags' => $this->get_taxonomy_terms($product, 'tag'), |
|
1161 | + 'images' => $this->get_images($product), |
|
1162 | + 'attributes' => $this->get_attributes($product), |
|
1163 | + 'default_attributes' => $this->get_default_attributes($product), |
|
1164 | 1164 | 'variations' => array(), |
1165 | 1165 | 'grouped_products' => array(), |
1166 | - 'menu_order' => $product->get_menu_order( $context ), |
|
1166 | + 'menu_order' => $product->get_menu_order($context), |
|
1167 | 1167 | 'meta_data' => $product->get_meta_data(), |
1168 | 1168 | ); |
1169 | 1169 | |
@@ -1178,19 +1178,19 @@ discard block |
||
1178 | 1178 | * |
1179 | 1179 | * @return array Links for the given post. |
1180 | 1180 | */ |
1181 | - protected function prepare_links( $object, $request ) { |
|
1181 | + protected function prepare_links($object, $request) { |
|
1182 | 1182 | $links = array( |
1183 | 1183 | 'self' => array( |
1184 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ), // @codingStandardsIgnoreLine. |
|
1184 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())), // @codingStandardsIgnoreLine. |
|
1185 | 1185 | ), |
1186 | 1186 | 'collection' => array( |
1187 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), // @codingStandardsIgnoreLine. |
|
1187 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), // @codingStandardsIgnoreLine. |
|
1188 | 1188 | ), |
1189 | 1189 | ); |
1190 | 1190 | |
1191 | - if ( $object->get_parent_id() ) { |
|
1191 | + if ($object->get_parent_id()) { |
|
1192 | 1192 | $links['up'] = array( |
1193 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $object->get_parent_id() ) ), // @codingStandardsIgnoreLine. |
|
1193 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $object->get_parent_id())), // @codingStandardsIgnoreLine. |
|
1194 | 1194 | ); |
1195 | 1195 | } |
1196 | 1196 | |
@@ -1206,49 +1206,49 @@ discard block |
||
1206 | 1206 | * @param array $images Images data. |
1207 | 1207 | * @return WC_Product |
1208 | 1208 | */ |
1209 | - protected function set_product_images( $product, $images ) { |
|
1210 | - $images = is_array( $images ) ? array_filter( $images ) : array(); |
|
1209 | + protected function set_product_images($product, $images) { |
|
1210 | + $images = is_array($images) ? array_filter($images) : array(); |
|
1211 | 1211 | |
1212 | - if ( ! empty( $images ) ) { |
|
1212 | + if ( ! empty($images)) { |
|
1213 | 1213 | $gallery = array(); |
1214 | 1214 | |
1215 | - foreach ( $images as $index => $image ) { |
|
1216 | - $attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0; |
|
1215 | + foreach ($images as $index => $image) { |
|
1216 | + $attachment_id = isset($image['id']) ? absint($image['id']) : 0; |
|
1217 | 1217 | |
1218 | - if ( 0 === $attachment_id && isset( $image['src'] ) ) { |
|
1219 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) ); |
|
1218 | + if (0 === $attachment_id && isset($image['src'])) { |
|
1219 | + $upload = wc_rest_upload_image_from_url(esc_url_raw($image['src'])); |
|
1220 | 1220 | |
1221 | - if ( is_wp_error( $upload ) ) { |
|
1222 | - if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $product->get_id(), $images ) ) { |
|
1223 | - throw new \WC_REST_Exception( 'woocommerce_product_image_upload_error', $upload->get_error_message(), 400 ); |
|
1221 | + if (is_wp_error($upload)) { |
|
1222 | + if ( ! apply_filters('woocommerce_rest_suppress_image_upload_error', false, $upload, $product->get_id(), $images)) { |
|
1223 | + throw new \WC_REST_Exception('woocommerce_product_image_upload_error', $upload->get_error_message(), 400); |
|
1224 | 1224 | } else { |
1225 | 1225 | continue; |
1226 | 1226 | } |
1227 | 1227 | } |
1228 | 1228 | |
1229 | - $attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $product->get_id() ); |
|
1229 | + $attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $product->get_id()); |
|
1230 | 1230 | } |
1231 | 1231 | |
1232 | - if ( ! wp_attachment_is_image( $attachment_id ) ) { |
|
1232 | + if ( ! wp_attachment_is_image($attachment_id)) { |
|
1233 | 1233 | /* translators: %s: image ID */ |
1234 | - throw new \WC_REST_Exception( 'woocommerce_product_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 ); |
|
1234 | + throw new \WC_REST_Exception('woocommerce_product_invalid_image_id', sprintf(__('#%s is an invalid image ID.', 'woocommerce'), $attachment_id), 400); |
|
1235 | 1235 | } |
1236 | 1236 | |
1237 | 1237 | $featured_image = $product->get_image_id(); |
1238 | 1238 | |
1239 | - if ( 0 === $index ) { |
|
1240 | - $product->set_image_id( $attachment_id ); |
|
1239 | + if (0 === $index) { |
|
1240 | + $product->set_image_id($attachment_id); |
|
1241 | 1241 | } else { |
1242 | 1242 | $gallery[] = $attachment_id; |
1243 | 1243 | } |
1244 | 1244 | |
1245 | 1245 | // Set the image alt if present. |
1246 | - if ( ! empty( $image['alt'] ) ) { |
|
1247 | - update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) ); |
|
1246 | + if ( ! empty($image['alt'])) { |
|
1247 | + update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt'])); |
|
1248 | 1248 | } |
1249 | 1249 | |
1250 | 1250 | // Set the image name if present. |
1251 | - if ( ! empty( $image['name'] ) ) { |
|
1251 | + if ( ! empty($image['name'])) { |
|
1252 | 1252 | wp_update_post( |
1253 | 1253 | array( |
1254 | 1254 | 'ID' => $attachment_id, |
@@ -1258,10 +1258,10 @@ discard block |
||
1258 | 1258 | } |
1259 | 1259 | } |
1260 | 1260 | |
1261 | - $product->set_gallery_image_ids( $gallery ); |
|
1261 | + $product->set_gallery_image_ids($gallery); |
|
1262 | 1262 | } else { |
1263 | - $product->set_image_id( '' ); |
|
1264 | - $product->set_gallery_image_ids( array() ); |
|
1263 | + $product->set_image_id(''); |
|
1264 | + $product->set_gallery_image_ids(array()); |
|
1265 | 1265 | } |
1266 | 1266 | |
1267 | 1267 | return $product; |
@@ -1275,39 +1275,39 @@ discard block |
||
1275 | 1275 | * |
1276 | 1276 | * @return WC_Product |
1277 | 1277 | */ |
1278 | - protected function save_product_shipping_data( $product, $data ) { |
|
1278 | + protected function save_product_shipping_data($product, $data) { |
|
1279 | 1279 | // Virtual. |
1280 | - if ( isset( $data['virtual'] ) && true === $data['virtual'] ) { |
|
1281 | - $product->set_weight( '' ); |
|
1282 | - $product->set_height( '' ); |
|
1283 | - $product->set_length( '' ); |
|
1284 | - $product->set_width( '' ); |
|
1280 | + if (isset($data['virtual']) && true === $data['virtual']) { |
|
1281 | + $product->set_weight(''); |
|
1282 | + $product->set_height(''); |
|
1283 | + $product->set_length(''); |
|
1284 | + $product->set_width(''); |
|
1285 | 1285 | } else { |
1286 | - if ( isset( $data['weight'] ) ) { |
|
1287 | - $product->set_weight( $data['weight'] ); |
|
1286 | + if (isset($data['weight'])) { |
|
1287 | + $product->set_weight($data['weight']); |
|
1288 | 1288 | } |
1289 | 1289 | |
1290 | 1290 | // Height. |
1291 | - if ( isset( $data['dimensions']['height'] ) ) { |
|
1292 | - $product->set_height( $data['dimensions']['height'] ); |
|
1291 | + if (isset($data['dimensions']['height'])) { |
|
1292 | + $product->set_height($data['dimensions']['height']); |
|
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | // Width. |
1296 | - if ( isset( $data['dimensions']['width'] ) ) { |
|
1297 | - $product->set_width( $data['dimensions']['width'] ); |
|
1296 | + if (isset($data['dimensions']['width'])) { |
|
1297 | + $product->set_width($data['dimensions']['width']); |
|
1298 | 1298 | } |
1299 | 1299 | |
1300 | 1300 | // Length. |
1301 | - if ( isset( $data['dimensions']['length'] ) ) { |
|
1302 | - $product->set_length( $data['dimensions']['length'] ); |
|
1301 | + if (isset($data['dimensions']['length'])) { |
|
1302 | + $product->set_length($data['dimensions']['length']); |
|
1303 | 1303 | } |
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 | // Shipping class. |
1307 | - if ( isset( $data['shipping_class'] ) ) { |
|
1307 | + if (isset($data['shipping_class'])) { |
|
1308 | 1308 | $data_store = $product->get_data_store(); |
1309 | - $shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) ); |
|
1310 | - $product->set_shipping_class_id( $shipping_class_id ); |
|
1309 | + $shipping_class_id = $data_store->get_shipping_class_id_by_slug(wc_clean($data['shipping_class'])); |
|
1310 | + $product->set_shipping_class_id($shipping_class_id); |
|
1311 | 1311 | } |
1312 | 1312 | |
1313 | 1313 | return $product; |
@@ -1322,24 +1322,24 @@ discard block |
||
1322 | 1322 | * |
1323 | 1323 | * @return WC_Product |
1324 | 1324 | */ |
1325 | - protected function save_downloadable_files( $product, $downloads, $deprecated = 0 ) { |
|
1326 | - if ( $deprecated ) { |
|
1327 | - wc_deprecated_argument( 'variation_id', '3.0', 'save_downloadable_files() not requires a variation_id anymore.' ); |
|
1325 | + protected function save_downloadable_files($product, $downloads, $deprecated = 0) { |
|
1326 | + if ($deprecated) { |
|
1327 | + wc_deprecated_argument('variation_id', '3.0', 'save_downloadable_files() not requires a variation_id anymore.'); |
|
1328 | 1328 | } |
1329 | 1329 | |
1330 | 1330 | $files = array(); |
1331 | - foreach ( $downloads as $key => $file ) { |
|
1332 | - if ( empty( $file['file'] ) ) { |
|
1331 | + foreach ($downloads as $key => $file) { |
|
1332 | + if (empty($file['file'])) { |
|
1333 | 1333 | continue; |
1334 | 1334 | } |
1335 | 1335 | |
1336 | 1336 | $download = new \WC_Product_Download(); |
1337 | - $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() ); |
|
1338 | - $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) ); |
|
1339 | - $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) ); |
|
1337 | + $download->set_id( ! empty($file['id']) ? $file['id'] : wp_generate_uuid4()); |
|
1338 | + $download->set_name($file['name'] ? $file['name'] : wc_get_filename_from_url($file['file'])); |
|
1339 | + $download->set_file(apply_filters('woocommerce_file_download_path', $file['file'], $product, $key)); |
|
1340 | 1340 | $files[] = $download; |
1341 | 1341 | } |
1342 | - $product->set_downloads( $files ); |
|
1342 | + $product->set_downloads($files); |
|
1343 | 1343 | |
1344 | 1344 | return $product; |
1345 | 1345 | } |
@@ -1353,13 +1353,13 @@ discard block |
||
1353 | 1353 | * |
1354 | 1354 | * @return WC_Product |
1355 | 1355 | */ |
1356 | - protected function save_taxonomy_terms( $product, $terms, $taxonomy = 'cat' ) { |
|
1357 | - $term_ids = wp_list_pluck( $terms, 'id' ); |
|
1356 | + protected function save_taxonomy_terms($product, $terms, $taxonomy = 'cat') { |
|
1357 | + $term_ids = wp_list_pluck($terms, 'id'); |
|
1358 | 1358 | |
1359 | - if ( 'cat' === $taxonomy ) { |
|
1360 | - $product->set_category_ids( $term_ids ); |
|
1361 | - } elseif ( 'tag' === $taxonomy ) { |
|
1362 | - $product->set_tag_ids( $term_ids ); |
|
1359 | + if ('cat' === $taxonomy) { |
|
1360 | + $product->set_category_ids($term_ids); |
|
1361 | + } elseif ('tag' === $taxonomy) { |
|
1362 | + $product->set_tag_ids($term_ids); |
|
1363 | 1363 | } |
1364 | 1364 | |
1365 | 1365 | return $product; |
@@ -1374,53 +1374,53 @@ discard block |
||
1374 | 1374 | * @since 3.0.0 |
1375 | 1375 | * @return WC_Product |
1376 | 1376 | */ |
1377 | - protected function save_default_attributes( $product, $request ) { |
|
1378 | - if ( isset( $request['default_attributes'] ) && is_array( $request['default_attributes'] ) ) { |
|
1377 | + protected function save_default_attributes($product, $request) { |
|
1378 | + if (isset($request['default_attributes']) && is_array($request['default_attributes'])) { |
|
1379 | 1379 | |
1380 | 1380 | $attributes = $product->get_attributes(); |
1381 | 1381 | $default_attributes = array(); |
1382 | 1382 | |
1383 | - foreach ( $request['default_attributes'] as $attribute ) { |
|
1383 | + foreach ($request['default_attributes'] as $attribute) { |
|
1384 | 1384 | $attribute_id = 0; |
1385 | 1385 | $attribute_name = ''; |
1386 | 1386 | |
1387 | 1387 | // Check ID for global attributes or name for product attributes. |
1388 | - if ( ! empty( $attribute['id'] ) ) { |
|
1389 | - $attribute_id = absint( $attribute['id'] ); |
|
1390 | - $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
|
1391 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
1392 | - $attribute_name = sanitize_title( $attribute['name'] ); |
|
1388 | + if ( ! empty($attribute['id'])) { |
|
1389 | + $attribute_id = absint($attribute['id']); |
|
1390 | + $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id); |
|
1391 | + } elseif ( ! empty($attribute['name'])) { |
|
1392 | + $attribute_name = sanitize_title($attribute['name']); |
|
1393 | 1393 | } |
1394 | 1394 | |
1395 | - if ( ! $attribute_id && ! $attribute_name ) { |
|
1395 | + if ( ! $attribute_id && ! $attribute_name) { |
|
1396 | 1396 | continue; |
1397 | 1397 | } |
1398 | 1398 | |
1399 | - if ( isset( $attributes[ $attribute_name ] ) ) { |
|
1400 | - $_attribute = $attributes[ $attribute_name ]; |
|
1399 | + if (isset($attributes[$attribute_name])) { |
|
1400 | + $_attribute = $attributes[$attribute_name]; |
|
1401 | 1401 | |
1402 | - if ( $_attribute['is_variation'] ) { |
|
1403 | - $value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
1402 | + if ($_attribute['is_variation']) { |
|
1403 | + $value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : ''; |
|
1404 | 1404 | |
1405 | - if ( ! empty( $_attribute['is_taxonomy'] ) ) { |
|
1405 | + if ( ! empty($_attribute['is_taxonomy'])) { |
|
1406 | 1406 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
1407 | - $term = get_term_by( 'name', $value, $attribute_name ); |
|
1407 | + $term = get_term_by('name', $value, $attribute_name); |
|
1408 | 1408 | |
1409 | - if ( $term && ! is_wp_error( $term ) ) { |
|
1409 | + if ($term && ! is_wp_error($term)) { |
|
1410 | 1410 | $value = $term->slug; |
1411 | 1411 | } else { |
1412 | - $value = sanitize_title( $value ); |
|
1412 | + $value = sanitize_title($value); |
|
1413 | 1413 | } |
1414 | 1414 | } |
1415 | 1415 | |
1416 | - if ( $value ) { |
|
1417 | - $default_attributes[ $attribute_name ] = $value; |
|
1416 | + if ($value) { |
|
1417 | + $default_attributes[$attribute_name] = $value; |
|
1418 | 1418 | } |
1419 | 1419 | } |
1420 | 1420 | } |
1421 | 1421 | } |
1422 | 1422 | |
1423 | - $product->set_default_attributes( $default_attributes ); |
|
1423 | + $product->set_default_attributes($default_attributes); |
|
1424 | 1424 | } |
1425 | 1425 | |
1426 | 1426 | return $product; |
@@ -1431,9 +1431,9 @@ discard block |
||
1431 | 1431 | * |
1432 | 1432 | * @param WC_Data $object Object data. |
1433 | 1433 | */ |
1434 | - public function clear_transients( $object ) { |
|
1435 | - wc_delete_product_transients( $object->get_id() ); |
|
1436 | - wp_cache_delete( 'product-' . $object->get_id(), 'products' ); |
|
1434 | + public function clear_transients($object) { |
|
1435 | + wc_delete_product_transients($object->get_id()); |
|
1436 | + wp_cache_delete('product-' . $object->get_id(), 'products'); |
|
1437 | 1437 | } |
1438 | 1438 | |
1439 | 1439 | /** |
@@ -1443,33 +1443,33 @@ discard block |
||
1443 | 1443 | * |
1444 | 1444 | * @return \WP_REST_Response|\WP_Error |
1445 | 1445 | */ |
1446 | - public function delete_item( $request ) { |
|
1446 | + public function delete_item($request) { |
|
1447 | 1447 | $id = (int) $request['id']; |
1448 | 1448 | $force = (bool) $request['force']; |
1449 | - $object = $this->get_object( (int) $request['id'] ); |
|
1449 | + $object = $this->get_object((int) $request['id']); |
|
1450 | 1450 | $result = false; |
1451 | 1451 | |
1452 | - if ( ! $object || 0 === $object->get_id() ) { |
|
1452 | + if ( ! $object || 0 === $object->get_id()) { |
|
1453 | 1453 | return new \WP_Error( |
1454 | 1454 | "woocommerce_rest_{$this->post_type}_invalid_id", |
1455 | - __( 'Invalid ID.', 'woocommerce' ), |
|
1455 | + __('Invalid ID.', 'woocommerce'), |
|
1456 | 1456 | array( |
1457 | 1457 | 'status' => 404, |
1458 | 1458 | ) |
1459 | 1459 | ); |
1460 | 1460 | } |
1461 | 1461 | |
1462 | - if ( 'variation' === $object->get_type() ) { |
|
1462 | + if ('variation' === $object->get_type()) { |
|
1463 | 1463 | return new \WP_Error( |
1464 | 1464 | "woocommerce_rest_invalid_{$this->post_type}_id", |
1465 | - __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), |
|
1465 | + __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), |
|
1466 | 1466 | array( |
1467 | 1467 | 'status' => 404, |
1468 | 1468 | ) |
1469 | 1469 | ); |
1470 | 1470 | } |
1471 | 1471 | |
1472 | - $supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) ); |
|
1472 | + $supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable(array($object, 'get_status')); |
|
1473 | 1473 | |
1474 | 1474 | /** |
1475 | 1475 | * Filter whether an object is trashable. |
@@ -1479,26 +1479,26 @@ discard block |
||
1479 | 1479 | * @param boolean $supports_trash Whether the object type support trashing. |
1480 | 1480 | * @param WC_Data $object The object being considered for trashing support. |
1481 | 1481 | */ |
1482 | - $supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object ); |
|
1482 | + $supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object); |
|
1483 | 1483 | |
1484 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) { |
|
1484 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) { |
|
1485 | 1485 | return new \WP_Error( |
1486 | 1486 | "woocommerce_rest_user_cannot_delete_{$this->post_type}", |
1487 | 1487 | /* translators: %s: post type */ |
1488 | - sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), |
|
1488 | + sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), |
|
1489 | 1489 | array( |
1490 | 1490 | 'status' => rest_authorization_required_code(), |
1491 | 1491 | ) |
1492 | 1492 | ); |
1493 | 1493 | } |
1494 | 1494 | |
1495 | - $request->set_param( 'context', 'edit' ); |
|
1495 | + $request->set_param('context', 'edit'); |
|
1496 | 1496 | |
1497 | 1497 | // If we're forcing, then delete permanently. |
1498 | - if ( $force ) { |
|
1499 | - $previous = $this->prepare_object_for_response( $object, $request ); |
|
1498 | + if ($force) { |
|
1499 | + $previous = $this->prepare_object_for_response($object, $request); |
|
1500 | 1500 | |
1501 | - $object->delete( true ); |
|
1501 | + $object->delete(true); |
|
1502 | 1502 | $result = 0 === $object->get_id(); |
1503 | 1503 | |
1504 | 1504 | $response = new \WP_REST_Response(); |
@@ -1510,11 +1510,11 @@ discard block |
||
1510 | 1510 | ); |
1511 | 1511 | } else { |
1512 | 1512 | // If we don't support trashing for this type, error out. |
1513 | - if ( ! $supports_trash ) { |
|
1513 | + if ( ! $supports_trash) { |
|
1514 | 1514 | return new \WP_Error( |
1515 | 1515 | 'woocommerce_rest_trash_not_supported', |
1516 | 1516 | /* translators: %s: post type */ |
1517 | - sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), |
|
1517 | + sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), |
|
1518 | 1518 | array( |
1519 | 1519 | 'status' => 501, |
1520 | 1520 | ) |
@@ -1522,12 +1522,12 @@ discard block |
||
1522 | 1522 | } |
1523 | 1523 | |
1524 | 1524 | // Otherwise, only trash if we haven't already. |
1525 | - if ( is_callable( array( $object, 'get_status' ) ) ) { |
|
1526 | - if ( 'trash' === $object->get_status() ) { |
|
1525 | + if (is_callable(array($object, 'get_status'))) { |
|
1526 | + if ('trash' === $object->get_status()) { |
|
1527 | 1527 | return new \WP_Error( |
1528 | 1528 | 'woocommerce_rest_already_trashed', |
1529 | 1529 | /* translators: %s: post type */ |
1530 | - sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), |
|
1530 | + sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), |
|
1531 | 1531 | array( |
1532 | 1532 | 'status' => 410, |
1533 | 1533 | ) |
@@ -1538,14 +1538,14 @@ discard block |
||
1538 | 1538 | $result = 'trash' === $object->get_status(); |
1539 | 1539 | } |
1540 | 1540 | |
1541 | - $response = $this->prepare_object_for_response( $object, $request ); |
|
1541 | + $response = $this->prepare_object_for_response($object, $request); |
|
1542 | 1542 | } |
1543 | 1543 | |
1544 | - if ( ! $result ) { |
|
1544 | + if ( ! $result) { |
|
1545 | 1545 | return new \WP_Error( |
1546 | 1546 | 'woocommerce_rest_cannot_delete', |
1547 | 1547 | /* translators: %s: post type */ |
1548 | - sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), |
|
1548 | + sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), |
|
1549 | 1549 | array( |
1550 | 1550 | 'status' => 500, |
1551 | 1551 | ) |
@@ -1559,7 +1559,7 @@ discard block |
||
1559 | 1559 | * @param \WP_REST_Response $response The response data. |
1560 | 1560 | * @param \WP_REST_Request $request The request sent to the API. |
1561 | 1561 | */ |
1562 | - do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request ); |
|
1562 | + do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request); |
|
1563 | 1563 | |
1564 | 1564 | return $response; |
1565 | 1565 | } |
@@ -1570,613 +1570,613 @@ discard block |
||
1570 | 1570 | * @return array |
1571 | 1571 | */ |
1572 | 1572 | public function get_item_schema() { |
1573 | - $weight_unit = get_option( 'woocommerce_weight_unit' ); |
|
1574 | - $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
|
1573 | + $weight_unit = get_option('woocommerce_weight_unit'); |
|
1574 | + $dimension_unit = get_option('woocommerce_dimension_unit'); |
|
1575 | 1575 | $schema = array( |
1576 | 1576 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
1577 | 1577 | 'title' => $this->post_type, |
1578 | 1578 | 'type' => 'object', |
1579 | 1579 | 'properties' => array( |
1580 | 1580 | 'id' => array( |
1581 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
1581 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
1582 | 1582 | 'type' => 'integer', |
1583 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1583 | + 'context' => array('view', 'edit', 'embed'), |
|
1584 | 1584 | 'readonly' => true, |
1585 | 1585 | ), |
1586 | 1586 | 'name' => array( |
1587 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
1587 | + 'description' => __('Product name.', 'woocommerce'), |
|
1588 | 1588 | 'type' => 'string', |
1589 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1589 | + 'context' => array('view', 'edit', 'embed'), |
|
1590 | 1590 | ), |
1591 | 1591 | 'slug' => array( |
1592 | - 'description' => __( 'Product slug.', 'woocommerce' ), |
|
1592 | + 'description' => __('Product slug.', 'woocommerce'), |
|
1593 | 1593 | 'type' => 'string', |
1594 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1594 | + 'context' => array('view', 'edit', 'embed'), |
|
1595 | 1595 | ), |
1596 | 1596 | 'permalink' => array( |
1597 | - 'description' => __( 'Product URL.', 'woocommerce' ), |
|
1597 | + 'description' => __('Product URL.', 'woocommerce'), |
|
1598 | 1598 | 'type' => 'string', |
1599 | 1599 | 'format' => 'uri', |
1600 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1600 | + 'context' => array('view', 'edit', 'embed'), |
|
1601 | 1601 | 'readonly' => true, |
1602 | 1602 | ), |
1603 | 1603 | 'date_created' => array( |
1604 | - 'description' => __( "The date the product was created, in the site's timezone.", 'woocommerce' ), |
|
1604 | + 'description' => __("The date the product was created, in the site's timezone.", 'woocommerce'), |
|
1605 | 1605 | 'type' => 'date-time', |
1606 | - 'context' => array( 'view', 'edit' ), |
|
1606 | + 'context' => array('view', 'edit'), |
|
1607 | 1607 | ), |
1608 | 1608 | 'date_created_gmt' => array( |
1609 | - 'description' => __( 'The date the product was created, as GMT.', 'woocommerce' ), |
|
1609 | + 'description' => __('The date the product was created, as GMT.', 'woocommerce'), |
|
1610 | 1610 | 'type' => 'date-time', |
1611 | - 'context' => array( 'view', 'edit' ), |
|
1611 | + 'context' => array('view', 'edit'), |
|
1612 | 1612 | ), |
1613 | 1613 | 'date_modified' => array( |
1614 | - 'description' => __( "The date the product was last modified, in the site's timezone.", 'woocommerce' ), |
|
1614 | + 'description' => __("The date the product was last modified, in the site's timezone.", 'woocommerce'), |
|
1615 | 1615 | 'type' => 'date-time', |
1616 | - 'context' => array( 'view', 'edit' ), |
|
1616 | + 'context' => array('view', 'edit'), |
|
1617 | 1617 | 'readonly' => true, |
1618 | 1618 | ), |
1619 | 1619 | 'date_modified_gmt' => array( |
1620 | - 'description' => __( 'The date the product was last modified, as GMT.', 'woocommerce' ), |
|
1620 | + 'description' => __('The date the product was last modified, as GMT.', 'woocommerce'), |
|
1621 | 1621 | 'type' => 'date-time', |
1622 | - 'context' => array( 'view', 'edit' ), |
|
1622 | + 'context' => array('view', 'edit'), |
|
1623 | 1623 | 'readonly' => true, |
1624 | 1624 | ), |
1625 | 1625 | 'type' => array( |
1626 | - 'description' => __( 'Product type.', 'woocommerce' ), |
|
1626 | + 'description' => __('Product type.', 'woocommerce'), |
|
1627 | 1627 | 'type' => 'string', |
1628 | 1628 | 'default' => 'simple', |
1629 | - 'enum' => array_keys( wc_get_product_types() ), |
|
1630 | - 'context' => array( 'view', 'edit' ), |
|
1629 | + 'enum' => array_keys(wc_get_product_types()), |
|
1630 | + 'context' => array('view', 'edit'), |
|
1631 | 1631 | ), |
1632 | 1632 | 'status' => array( |
1633 | - 'description' => __( 'Product status (post status).', 'woocommerce' ), |
|
1633 | + 'description' => __('Product status (post status).', 'woocommerce'), |
|
1634 | 1634 | 'type' => 'string', |
1635 | 1635 | 'default' => 'publish', |
1636 | - 'enum' => array_merge( array_keys( get_post_statuses() ), array( 'future' ) ), |
|
1637 | - 'context' => array( 'view', 'edit' ), |
|
1636 | + 'enum' => array_merge(array_keys(get_post_statuses()), array('future')), |
|
1637 | + 'context' => array('view', 'edit'), |
|
1638 | 1638 | ), |
1639 | 1639 | 'featured' => array( |
1640 | - 'description' => __( 'Featured product.', 'woocommerce' ), |
|
1640 | + 'description' => __('Featured product.', 'woocommerce'), |
|
1641 | 1641 | 'type' => 'boolean', |
1642 | 1642 | 'default' => false, |
1643 | - 'context' => array( 'view', 'edit' ), |
|
1643 | + 'context' => array('view', 'edit'), |
|
1644 | 1644 | ), |
1645 | 1645 | 'catalog_visibility' => array( |
1646 | - 'description' => __( 'Catalog visibility.', 'woocommerce' ), |
|
1646 | + 'description' => __('Catalog visibility.', 'woocommerce'), |
|
1647 | 1647 | 'type' => 'string', |
1648 | 1648 | 'default' => 'visible', |
1649 | - 'enum' => array( 'visible', 'catalog', 'search', 'hidden' ), |
|
1650 | - 'context' => array( 'view', 'edit' ), |
|
1649 | + 'enum' => array('visible', 'catalog', 'search', 'hidden'), |
|
1650 | + 'context' => array('view', 'edit'), |
|
1651 | 1651 | ), |
1652 | 1652 | 'description' => array( |
1653 | - 'description' => __( 'Product description.', 'woocommerce' ), |
|
1653 | + 'description' => __('Product description.', 'woocommerce'), |
|
1654 | 1654 | 'type' => 'string', |
1655 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1655 | + 'context' => array('view', 'edit', 'embed'), |
|
1656 | 1656 | ), |
1657 | 1657 | 'short_description' => array( |
1658 | - 'description' => __( 'Product short description.', 'woocommerce' ), |
|
1658 | + 'description' => __('Product short description.', 'woocommerce'), |
|
1659 | 1659 | 'type' => 'string', |
1660 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1660 | + 'context' => array('view', 'edit', 'embed'), |
|
1661 | 1661 | ), |
1662 | 1662 | 'sku' => array( |
1663 | - 'description' => __( 'Unique identifier.', 'woocommerce' ), |
|
1663 | + 'description' => __('Unique identifier.', 'woocommerce'), |
|
1664 | 1664 | 'type' => 'string', |
1665 | - 'context' => array( 'view', 'edit' ), |
|
1665 | + 'context' => array('view', 'edit'), |
|
1666 | 1666 | ), |
1667 | 1667 | 'price' => array( |
1668 | - 'description' => __( 'Current product price.', 'woocommerce' ), |
|
1668 | + 'description' => __('Current product price.', 'woocommerce'), |
|
1669 | 1669 | 'type' => 'string', |
1670 | - 'context' => array( 'view', 'edit' ), |
|
1670 | + 'context' => array('view', 'edit'), |
|
1671 | 1671 | 'readonly' => true, |
1672 | 1672 | ), |
1673 | 1673 | 'regular_price' => array( |
1674 | - 'description' => __( 'Product regular price.', 'woocommerce' ), |
|
1674 | + 'description' => __('Product regular price.', 'woocommerce'), |
|
1675 | 1675 | 'type' => 'string', |
1676 | - 'context' => array( 'view', 'edit' ), |
|
1676 | + 'context' => array('view', 'edit'), |
|
1677 | 1677 | ), |
1678 | 1678 | 'sale_price' => array( |
1679 | - 'description' => __( 'Product sale price.', 'woocommerce' ), |
|
1679 | + 'description' => __('Product sale price.', 'woocommerce'), |
|
1680 | 1680 | 'type' => 'string', |
1681 | - 'context' => array( 'view', 'edit' ), |
|
1681 | + 'context' => array('view', 'edit'), |
|
1682 | 1682 | ), |
1683 | 1683 | 'date_on_sale_from' => array( |
1684 | - 'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ), |
|
1684 | + 'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'), |
|
1685 | 1685 | 'type' => 'date-time', |
1686 | - 'context' => array( 'view', 'edit' ), |
|
1686 | + 'context' => array('view', 'edit'), |
|
1687 | 1687 | ), |
1688 | 1688 | 'date_on_sale_from_gmt' => array( |
1689 | - 'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ), |
|
1689 | + 'description' => __('Start date of sale price, as GMT.', 'woocommerce'), |
|
1690 | 1690 | 'type' => 'date-time', |
1691 | - 'context' => array( 'view', 'edit' ), |
|
1691 | + 'context' => array('view', 'edit'), |
|
1692 | 1692 | ), |
1693 | 1693 | 'date_on_sale_to' => array( |
1694 | - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
|
1694 | + 'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'), |
|
1695 | 1695 | 'type' => 'date-time', |
1696 | - 'context' => array( 'view', 'edit' ), |
|
1696 | + 'context' => array('view', 'edit'), |
|
1697 | 1697 | ), |
1698 | 1698 | 'date_on_sale_to_gmt' => array( |
1699 | - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
|
1699 | + 'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'), |
|
1700 | 1700 | 'type' => 'date-time', |
1701 | - 'context' => array( 'view', 'edit' ), |
|
1701 | + 'context' => array('view', 'edit'), |
|
1702 | 1702 | ), |
1703 | 1703 | 'price_html' => array( |
1704 | - 'description' => __( 'Price formatted in HTML.', 'woocommerce' ), |
|
1704 | + 'description' => __('Price formatted in HTML.', 'woocommerce'), |
|
1705 | 1705 | 'type' => 'string', |
1706 | - 'context' => array( 'view', 'edit' ), |
|
1706 | + 'context' => array('view', 'edit'), |
|
1707 | 1707 | 'readonly' => true, |
1708 | 1708 | ), |
1709 | 1709 | 'on_sale' => array( |
1710 | - 'description' => __( 'Shows if the product is on sale.', 'woocommerce' ), |
|
1710 | + 'description' => __('Shows if the product is on sale.', 'woocommerce'), |
|
1711 | 1711 | 'type' => 'boolean', |
1712 | - 'context' => array( 'view', 'edit' ), |
|
1712 | + 'context' => array('view', 'edit'), |
|
1713 | 1713 | 'readonly' => true, |
1714 | 1714 | ), |
1715 | 1715 | 'purchasable' => array( |
1716 | - 'description' => __( 'Shows if the product can be bought.', 'woocommerce' ), |
|
1716 | + 'description' => __('Shows if the product can be bought.', 'woocommerce'), |
|
1717 | 1717 | 'type' => 'boolean', |
1718 | - 'context' => array( 'view', 'edit' ), |
|
1718 | + 'context' => array('view', 'edit'), |
|
1719 | 1719 | 'readonly' => true, |
1720 | 1720 | ), |
1721 | 1721 | 'total_sales' => array( |
1722 | - 'description' => __( 'Amount of sales.', 'woocommerce' ), |
|
1722 | + 'description' => __('Amount of sales.', 'woocommerce'), |
|
1723 | 1723 | 'type' => 'integer', |
1724 | - 'context' => array( 'view', 'edit' ), |
|
1724 | + 'context' => array('view', 'edit'), |
|
1725 | 1725 | 'readonly' => true, |
1726 | 1726 | ), |
1727 | 1727 | 'virtual' => array( |
1728 | - 'description' => __( 'If the product is virtual.', 'woocommerce' ), |
|
1728 | + 'description' => __('If the product is virtual.', 'woocommerce'), |
|
1729 | 1729 | 'type' => 'boolean', |
1730 | 1730 | 'default' => false, |
1731 | - 'context' => array( 'view', 'edit' ), |
|
1731 | + 'context' => array('view', 'edit'), |
|
1732 | 1732 | ), |
1733 | 1733 | 'downloadable' => array( |
1734 | - 'description' => __( 'If the product is downloadable.', 'woocommerce' ), |
|
1734 | + 'description' => __('If the product is downloadable.', 'woocommerce'), |
|
1735 | 1735 | 'type' => 'boolean', |
1736 | 1736 | 'default' => false, |
1737 | - 'context' => array( 'view', 'edit' ), |
|
1737 | + 'context' => array('view', 'edit'), |
|
1738 | 1738 | ), |
1739 | 1739 | 'downloads' => array( |
1740 | - 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
|
1740 | + 'description' => __('List of downloadable files.', 'woocommerce'), |
|
1741 | 1741 | 'type' => 'array', |
1742 | - 'context' => array( 'view', 'edit' ), |
|
1742 | + 'context' => array('view', 'edit'), |
|
1743 | 1743 | 'items' => array( |
1744 | 1744 | 'type' => 'object', |
1745 | 1745 | 'properties' => array( |
1746 | 1746 | 'id' => array( |
1747 | - 'description' => __( 'File ID.', 'woocommerce' ), |
|
1747 | + 'description' => __('File ID.', 'woocommerce'), |
|
1748 | 1748 | 'type' => 'string', |
1749 | - 'context' => array( 'view', 'edit' ), |
|
1749 | + 'context' => array('view', 'edit'), |
|
1750 | 1750 | ), |
1751 | 1751 | 'name' => array( |
1752 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
1752 | + 'description' => __('File name.', 'woocommerce'), |
|
1753 | 1753 | 'type' => 'string', |
1754 | - 'context' => array( 'view', 'edit' ), |
|
1754 | + 'context' => array('view', 'edit'), |
|
1755 | 1755 | ), |
1756 | 1756 | 'file' => array( |
1757 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
1757 | + 'description' => __('File URL.', 'woocommerce'), |
|
1758 | 1758 | 'type' => 'string', |
1759 | - 'context' => array( 'view', 'edit' ), |
|
1759 | + 'context' => array('view', 'edit'), |
|
1760 | 1760 | ), |
1761 | 1761 | ), |
1762 | 1762 | ), |
1763 | 1763 | ), |
1764 | 1764 | 'download_limit' => array( |
1765 | - 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
|
1765 | + 'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'), |
|
1766 | 1766 | 'type' => 'integer', |
1767 | 1767 | 'default' => -1, |
1768 | - 'context' => array( 'view', 'edit' ), |
|
1768 | + 'context' => array('view', 'edit'), |
|
1769 | 1769 | ), |
1770 | 1770 | 'download_expiry' => array( |
1771 | - 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
|
1771 | + 'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'), |
|
1772 | 1772 | 'type' => 'integer', |
1773 | 1773 | 'default' => -1, |
1774 | - 'context' => array( 'view', 'edit' ), |
|
1774 | + 'context' => array('view', 'edit'), |
|
1775 | 1775 | ), |
1776 | 1776 | 'external_url' => array( |
1777 | - 'description' => __( 'Product external URL. Only for external products.', 'woocommerce' ), |
|
1777 | + 'description' => __('Product external URL. Only for external products.', 'woocommerce'), |
|
1778 | 1778 | 'type' => 'string', |
1779 | 1779 | 'format' => 'uri', |
1780 | - 'context' => array( 'view', 'edit' ), |
|
1780 | + 'context' => array('view', 'edit'), |
|
1781 | 1781 | ), |
1782 | 1782 | 'button_text' => array( |
1783 | - 'description' => __( 'Product external button text. Only for external products.', 'woocommerce' ), |
|
1783 | + 'description' => __('Product external button text. Only for external products.', 'woocommerce'), |
|
1784 | 1784 | 'type' => 'string', |
1785 | - 'context' => array( 'view', 'edit' ), |
|
1785 | + 'context' => array('view', 'edit'), |
|
1786 | 1786 | ), |
1787 | 1787 | 'tax_status' => array( |
1788 | - 'description' => __( 'Tax status.', 'woocommerce' ), |
|
1788 | + 'description' => __('Tax status.', 'woocommerce'), |
|
1789 | 1789 | 'type' => 'string', |
1790 | 1790 | 'default' => 'taxable', |
1791 | - 'enum' => array( 'taxable', 'shipping', 'none' ), |
|
1792 | - 'context' => array( 'view', 'edit' ), |
|
1791 | + 'enum' => array('taxable', 'shipping', 'none'), |
|
1792 | + 'context' => array('view', 'edit'), |
|
1793 | 1793 | ), |
1794 | 1794 | 'tax_class' => array( |
1795 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
1795 | + 'description' => __('Tax class.', 'woocommerce'), |
|
1796 | 1796 | 'type' => 'string', |
1797 | - 'context' => array( 'view', 'edit' ), |
|
1797 | + 'context' => array('view', 'edit'), |
|
1798 | 1798 | ), |
1799 | 1799 | 'manage_stock' => array( |
1800 | - 'description' => __( 'Stock management at product level.', 'woocommerce' ), |
|
1800 | + 'description' => __('Stock management at product level.', 'woocommerce'), |
|
1801 | 1801 | 'type' => 'boolean', |
1802 | 1802 | 'default' => false, |
1803 | - 'context' => array( 'view', 'edit' ), |
|
1803 | + 'context' => array('view', 'edit'), |
|
1804 | 1804 | ), |
1805 | 1805 | 'stock_quantity' => array( |
1806 | - 'description' => __( 'Stock quantity.', 'woocommerce' ), |
|
1806 | + 'description' => __('Stock quantity.', 'woocommerce'), |
|
1807 | 1807 | 'type' => 'integer', |
1808 | - 'context' => array( 'view', 'edit' ), |
|
1808 | + 'context' => array('view', 'edit'), |
|
1809 | 1809 | ), |
1810 | 1810 | 'stock_status' => array( |
1811 | - 'description' => __( 'Controls the stock status of the product.', 'woocommerce' ), |
|
1811 | + 'description' => __('Controls the stock status of the product.', 'woocommerce'), |
|
1812 | 1812 | 'type' => 'string', |
1813 | 1813 | 'default' => 'instock', |
1814 | - 'enum' => array_keys( wc_get_product_stock_status_options() ), |
|
1815 | - 'context' => array( 'view', 'edit' ), |
|
1814 | + 'enum' => array_keys(wc_get_product_stock_status_options()), |
|
1815 | + 'context' => array('view', 'edit'), |
|
1816 | 1816 | ), |
1817 | 1817 | 'backorders' => array( |
1818 | - 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
|
1818 | + 'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'), |
|
1819 | 1819 | 'type' => 'string', |
1820 | 1820 | 'default' => 'no', |
1821 | - 'enum' => array( 'no', 'notify', 'yes' ), |
|
1822 | - 'context' => array( 'view', 'edit' ), |
|
1821 | + 'enum' => array('no', 'notify', 'yes'), |
|
1822 | + 'context' => array('view', 'edit'), |
|
1823 | 1823 | ), |
1824 | 1824 | 'backorders_allowed' => array( |
1825 | - 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
|
1825 | + 'description' => __('Shows if backorders are allowed.', 'woocommerce'), |
|
1826 | 1826 | 'type' => 'boolean', |
1827 | - 'context' => array( 'view', 'edit' ), |
|
1827 | + 'context' => array('view', 'edit'), |
|
1828 | 1828 | 'readonly' => true, |
1829 | 1829 | ), |
1830 | 1830 | 'backordered' => array( |
1831 | - 'description' => __( 'Shows if the product is on backordered.', 'woocommerce' ), |
|
1831 | + 'description' => __('Shows if the product is on backordered.', 'woocommerce'), |
|
1832 | 1832 | 'type' => 'boolean', |
1833 | - 'context' => array( 'view', 'edit' ), |
|
1833 | + 'context' => array('view', 'edit'), |
|
1834 | 1834 | 'readonly' => true, |
1835 | 1835 | ), |
1836 | 1836 | 'sold_individually' => array( |
1837 | - 'description' => __( 'Allow one item to be bought in a single order.', 'woocommerce' ), |
|
1837 | + 'description' => __('Allow one item to be bought in a single order.', 'woocommerce'), |
|
1838 | 1838 | 'type' => 'boolean', |
1839 | 1839 | 'default' => false, |
1840 | - 'context' => array( 'view', 'edit' ), |
|
1840 | + 'context' => array('view', 'edit'), |
|
1841 | 1841 | ), |
1842 | 1842 | 'weight' => array( |
1843 | 1843 | /* translators: %s: weight unit */ |
1844 | - 'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit ), |
|
1844 | + 'description' => sprintf(__('Product weight (%s).', 'woocommerce'), $weight_unit), |
|
1845 | 1845 | 'type' => 'string', |
1846 | - 'context' => array( 'view', 'edit' ), |
|
1846 | + 'context' => array('view', 'edit'), |
|
1847 | 1847 | ), |
1848 | 1848 | 'dimensions' => array( |
1849 | - 'description' => __( 'Product dimensions.', 'woocommerce' ), |
|
1849 | + 'description' => __('Product dimensions.', 'woocommerce'), |
|
1850 | 1850 | 'type' => 'object', |
1851 | - 'context' => array( 'view', 'edit' ), |
|
1851 | + 'context' => array('view', 'edit'), |
|
1852 | 1852 | 'properties' => array( |
1853 | 1853 | 'length' => array( |
1854 | 1854 | /* translators: %s: dimension unit */ |
1855 | - 'description' => sprintf( __( 'Product length (%s).', 'woocommerce' ), $dimension_unit ), |
|
1855 | + 'description' => sprintf(__('Product length (%s).', 'woocommerce'), $dimension_unit), |
|
1856 | 1856 | 'type' => 'string', |
1857 | - 'context' => array( 'view', 'edit' ), |
|
1857 | + 'context' => array('view', 'edit'), |
|
1858 | 1858 | ), |
1859 | 1859 | 'width' => array( |
1860 | 1860 | /* translators: %s: dimension unit */ |
1861 | - 'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit ), |
|
1861 | + 'description' => sprintf(__('Product width (%s).', 'woocommerce'), $dimension_unit), |
|
1862 | 1862 | 'type' => 'string', |
1863 | - 'context' => array( 'view', 'edit' ), |
|
1863 | + 'context' => array('view', 'edit'), |
|
1864 | 1864 | ), |
1865 | 1865 | 'height' => array( |
1866 | 1866 | /* translators: %s: dimension unit */ |
1867 | - 'description' => sprintf( __( 'Product height (%s).', 'woocommerce' ), $dimension_unit ), |
|
1867 | + 'description' => sprintf(__('Product height (%s).', 'woocommerce'), $dimension_unit), |
|
1868 | 1868 | 'type' => 'string', |
1869 | - 'context' => array( 'view', 'edit' ), |
|
1869 | + 'context' => array('view', 'edit'), |
|
1870 | 1870 | ), |
1871 | 1871 | ), |
1872 | 1872 | ), |
1873 | 1873 | 'shipping_required' => array( |
1874 | - 'description' => __( 'Shows if the product need to be shipped.', 'woocommerce' ), |
|
1874 | + 'description' => __('Shows if the product need to be shipped.', 'woocommerce'), |
|
1875 | 1875 | 'type' => 'boolean', |
1876 | - 'context' => array( 'view', 'edit' ), |
|
1876 | + 'context' => array('view', 'edit'), |
|
1877 | 1877 | 'readonly' => true, |
1878 | 1878 | ), |
1879 | 1879 | 'shipping_taxable' => array( |
1880 | - 'description' => __( 'Shows whether or not the product shipping is taxable.', 'woocommerce' ), |
|
1880 | + 'description' => __('Shows whether or not the product shipping is taxable.', 'woocommerce'), |
|
1881 | 1881 | 'type' => 'boolean', |
1882 | - 'context' => array( 'view', 'edit' ), |
|
1882 | + 'context' => array('view', 'edit'), |
|
1883 | 1883 | 'readonly' => true, |
1884 | 1884 | ), |
1885 | 1885 | 'shipping_class' => array( |
1886 | - 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
|
1886 | + 'description' => __('Shipping class slug.', 'woocommerce'), |
|
1887 | 1887 | 'type' => 'string', |
1888 | - 'context' => array( 'view', 'edit' ), |
|
1888 | + 'context' => array('view', 'edit'), |
|
1889 | 1889 | ), |
1890 | 1890 | 'shipping_class_id' => array( |
1891 | - 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
|
1891 | + 'description' => __('Shipping class ID.', 'woocommerce'), |
|
1892 | 1892 | 'type' => 'string', |
1893 | - 'context' => array( 'view', 'edit' ), |
|
1893 | + 'context' => array('view', 'edit'), |
|
1894 | 1894 | 'readonly' => true, |
1895 | 1895 | ), |
1896 | 1896 | 'reviews_allowed' => array( |
1897 | - 'description' => __( 'Allow reviews.', 'woocommerce' ), |
|
1897 | + 'description' => __('Allow reviews.', 'woocommerce'), |
|
1898 | 1898 | 'type' => 'boolean', |
1899 | 1899 | 'default' => true, |
1900 | - 'context' => array( 'view', 'edit' ), |
|
1900 | + 'context' => array('view', 'edit'), |
|
1901 | 1901 | ), |
1902 | 1902 | 'average_rating' => array( |
1903 | - 'description' => __( 'Reviews average rating.', 'woocommerce' ), |
|
1903 | + 'description' => __('Reviews average rating.', 'woocommerce'), |
|
1904 | 1904 | 'type' => 'string', |
1905 | - 'context' => array( 'view', 'edit' ), |
|
1905 | + 'context' => array('view', 'edit'), |
|
1906 | 1906 | 'readonly' => true, |
1907 | 1907 | ), |
1908 | 1908 | 'rating_count' => array( |
1909 | - 'description' => __( 'Amount of reviews that the product have.', 'woocommerce' ), |
|
1909 | + 'description' => __('Amount of reviews that the product have.', 'woocommerce'), |
|
1910 | 1910 | 'type' => 'integer', |
1911 | - 'context' => array( 'view', 'edit' ), |
|
1911 | + 'context' => array('view', 'edit'), |
|
1912 | 1912 | 'readonly' => true, |
1913 | 1913 | ), |
1914 | 1914 | 'related_ids' => array( |
1915 | - 'description' => __( 'List of related products IDs.', 'woocommerce' ), |
|
1915 | + 'description' => __('List of related products IDs.', 'woocommerce'), |
|
1916 | 1916 | 'type' => 'array', |
1917 | 1917 | 'items' => array( |
1918 | 1918 | 'type' => 'integer', |
1919 | 1919 | ), |
1920 | - 'context' => array( 'view', 'edit' ), |
|
1920 | + 'context' => array('view', 'edit'), |
|
1921 | 1921 | 'readonly' => true, |
1922 | 1922 | ), |
1923 | 1923 | 'upsell_ids' => array( |
1924 | - 'description' => __( 'List of up-sell products IDs.', 'woocommerce' ), |
|
1924 | + 'description' => __('List of up-sell products IDs.', 'woocommerce'), |
|
1925 | 1925 | 'type' => 'array', |
1926 | 1926 | 'items' => array( |
1927 | 1927 | 'type' => 'integer', |
1928 | 1928 | ), |
1929 | - 'context' => array( 'view', 'edit' ), |
|
1929 | + 'context' => array('view', 'edit'), |
|
1930 | 1930 | ), |
1931 | 1931 | 'cross_sell_ids' => array( |
1932 | - 'description' => __( 'List of cross-sell products IDs.', 'woocommerce' ), |
|
1932 | + 'description' => __('List of cross-sell products IDs.', 'woocommerce'), |
|
1933 | 1933 | 'type' => 'array', |
1934 | 1934 | 'items' => array( |
1935 | 1935 | 'type' => 'integer', |
1936 | 1936 | ), |
1937 | - 'context' => array( 'view', 'edit' ), |
|
1937 | + 'context' => array('view', 'edit'), |
|
1938 | 1938 | ), |
1939 | 1939 | 'parent_id' => array( |
1940 | - 'description' => __( 'Product parent ID.', 'woocommerce' ), |
|
1940 | + 'description' => __('Product parent ID.', 'woocommerce'), |
|
1941 | 1941 | 'type' => 'integer', |
1942 | - 'context' => array( 'view', 'edit' ), |
|
1942 | + 'context' => array('view', 'edit'), |
|
1943 | 1943 | ), |
1944 | 1944 | 'purchase_note' => array( |
1945 | - 'description' => __( 'Optional note to send the customer after purchase.', 'woocommerce' ), |
|
1945 | + 'description' => __('Optional note to send the customer after purchase.', 'woocommerce'), |
|
1946 | 1946 | 'type' => 'string', |
1947 | - 'context' => array( 'view', 'edit' ), |
|
1947 | + 'context' => array('view', 'edit'), |
|
1948 | 1948 | ), |
1949 | 1949 | 'categories' => array( |
1950 | - 'description' => __( 'List of categories.', 'woocommerce' ), |
|
1950 | + 'description' => __('List of categories.', 'woocommerce'), |
|
1951 | 1951 | 'type' => 'array', |
1952 | - 'context' => array( 'view', 'edit' ), |
|
1952 | + 'context' => array('view', 'edit'), |
|
1953 | 1953 | 'items' => array( |
1954 | 1954 | 'type' => 'object', |
1955 | 1955 | 'properties' => array( |
1956 | 1956 | 'id' => array( |
1957 | - 'description' => __( 'Category ID.', 'woocommerce' ), |
|
1957 | + 'description' => __('Category ID.', 'woocommerce'), |
|
1958 | 1958 | 'type' => 'integer', |
1959 | - 'context' => array( 'view', 'edit' ), |
|
1959 | + 'context' => array('view', 'edit'), |
|
1960 | 1960 | ), |
1961 | 1961 | 'name' => array( |
1962 | - 'description' => __( 'Category name.', 'woocommerce' ), |
|
1962 | + 'description' => __('Category name.', 'woocommerce'), |
|
1963 | 1963 | 'type' => 'string', |
1964 | - 'context' => array( 'view', 'edit' ), |
|
1964 | + 'context' => array('view', 'edit'), |
|
1965 | 1965 | 'readonly' => true, |
1966 | 1966 | ), |
1967 | 1967 | 'slug' => array( |
1968 | - 'description' => __( 'Category slug.', 'woocommerce' ), |
|
1968 | + 'description' => __('Category slug.', 'woocommerce'), |
|
1969 | 1969 | 'type' => 'string', |
1970 | - 'context' => array( 'view', 'edit' ), |
|
1970 | + 'context' => array('view', 'edit'), |
|
1971 | 1971 | 'readonly' => true, |
1972 | 1972 | ), |
1973 | 1973 | ), |
1974 | 1974 | ), |
1975 | 1975 | ), |
1976 | 1976 | 'tags' => array( |
1977 | - 'description' => __( 'List of tags.', 'woocommerce' ), |
|
1977 | + 'description' => __('List of tags.', 'woocommerce'), |
|
1978 | 1978 | 'type' => 'array', |
1979 | - 'context' => array( 'view', 'edit' ), |
|
1979 | + 'context' => array('view', 'edit'), |
|
1980 | 1980 | 'items' => array( |
1981 | 1981 | 'type' => 'object', |
1982 | 1982 | 'properties' => array( |
1983 | 1983 | 'id' => array( |
1984 | - 'description' => __( 'Tag ID.', 'woocommerce' ), |
|
1984 | + 'description' => __('Tag ID.', 'woocommerce'), |
|
1985 | 1985 | 'type' => 'integer', |
1986 | - 'context' => array( 'view', 'edit' ), |
|
1986 | + 'context' => array('view', 'edit'), |
|
1987 | 1987 | ), |
1988 | 1988 | 'name' => array( |
1989 | - 'description' => __( 'Tag name.', 'woocommerce' ), |
|
1989 | + 'description' => __('Tag name.', 'woocommerce'), |
|
1990 | 1990 | 'type' => 'string', |
1991 | - 'context' => array( 'view', 'edit' ), |
|
1991 | + 'context' => array('view', 'edit'), |
|
1992 | 1992 | 'readonly' => true, |
1993 | 1993 | ), |
1994 | 1994 | 'slug' => array( |
1995 | - 'description' => __( 'Tag slug.', 'woocommerce' ), |
|
1995 | + 'description' => __('Tag slug.', 'woocommerce'), |
|
1996 | 1996 | 'type' => 'string', |
1997 | - 'context' => array( 'view', 'edit' ), |
|
1997 | + 'context' => array('view', 'edit'), |
|
1998 | 1998 | 'readonly' => true, |
1999 | 1999 | ), |
2000 | 2000 | ), |
2001 | 2001 | ), |
2002 | 2002 | ), |
2003 | 2003 | 'images' => array( |
2004 | - 'description' => __( 'List of images.', 'woocommerce' ), |
|
2004 | + 'description' => __('List of images.', 'woocommerce'), |
|
2005 | 2005 | 'type' => 'object', |
2006 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
2006 | + 'context' => array('view', 'edit', 'embed'), |
|
2007 | 2007 | 'items' => array( |
2008 | 2008 | 'type' => 'object', |
2009 | 2009 | 'properties' => array( |
2010 | 2010 | 'id' => array( |
2011 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
2011 | + 'description' => __('Image ID.', 'woocommerce'), |
|
2012 | 2012 | 'type' => 'integer', |
2013 | - 'context' => array( 'view', 'edit' ), |
|
2013 | + 'context' => array('view', 'edit'), |
|
2014 | 2014 | ), |
2015 | 2015 | 'date_created' => array( |
2016 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
2016 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
2017 | 2017 | 'type' => 'date-time', |
2018 | - 'context' => array( 'view', 'edit' ), |
|
2018 | + 'context' => array('view', 'edit'), |
|
2019 | 2019 | 'readonly' => true, |
2020 | 2020 | ), |
2021 | 2021 | 'date_created_gmt' => array( |
2022 | - 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
|
2022 | + 'description' => __('The date the image was created, as GMT.', 'woocommerce'), |
|
2023 | 2023 | 'type' => 'date-time', |
2024 | - 'context' => array( 'view', 'edit' ), |
|
2024 | + 'context' => array('view', 'edit'), |
|
2025 | 2025 | 'readonly' => true, |
2026 | 2026 | ), |
2027 | 2027 | 'date_modified' => array( |
2028 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
2028 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
2029 | 2029 | 'type' => 'date-time', |
2030 | - 'context' => array( 'view', 'edit' ), |
|
2030 | + 'context' => array('view', 'edit'), |
|
2031 | 2031 | 'readonly' => true, |
2032 | 2032 | ), |
2033 | 2033 | 'date_modified_gmt' => array( |
2034 | - 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
|
2034 | + 'description' => __('The date the image was last modified, as GMT.', 'woocommerce'), |
|
2035 | 2035 | 'type' => 'date-time', |
2036 | - 'context' => array( 'view', 'edit' ), |
|
2036 | + 'context' => array('view', 'edit'), |
|
2037 | 2037 | 'readonly' => true, |
2038 | 2038 | ), |
2039 | 2039 | 'src' => array( |
2040 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
2040 | + 'description' => __('Image URL.', 'woocommerce'), |
|
2041 | 2041 | 'type' => 'string', |
2042 | 2042 | 'format' => 'uri', |
2043 | - 'context' => array( 'view', 'edit' ), |
|
2043 | + 'context' => array('view', 'edit'), |
|
2044 | 2044 | ), |
2045 | 2045 | 'name' => array( |
2046 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
2046 | + 'description' => __('Image name.', 'woocommerce'), |
|
2047 | 2047 | 'type' => 'string', |
2048 | - 'context' => array( 'view', 'edit' ), |
|
2048 | + 'context' => array('view', 'edit'), |
|
2049 | 2049 | ), |
2050 | 2050 | 'alt' => array( |
2051 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
2051 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
2052 | 2052 | 'type' => 'string', |
2053 | - 'context' => array( 'view', 'edit' ), |
|
2053 | + 'context' => array('view', 'edit'), |
|
2054 | 2054 | ), |
2055 | 2055 | ), |
2056 | 2056 | ), |
2057 | 2057 | ), |
2058 | 2058 | 'attributes' => array( |
2059 | - 'description' => __( 'List of attributes.', 'woocommerce' ), |
|
2059 | + 'description' => __('List of attributes.', 'woocommerce'), |
|
2060 | 2060 | 'type' => 'array', |
2061 | - 'context' => array( 'view', 'edit' ), |
|
2061 | + 'context' => array('view', 'edit'), |
|
2062 | 2062 | 'items' => array( |
2063 | 2063 | 'type' => 'object', |
2064 | 2064 | 'properties' => array( |
2065 | 2065 | 'id' => array( |
2066 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
2066 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
2067 | 2067 | 'type' => 'integer', |
2068 | - 'context' => array( 'view', 'edit' ), |
|
2068 | + 'context' => array('view', 'edit'), |
|
2069 | 2069 | ), |
2070 | 2070 | 'name' => array( |
2071 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
2071 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
2072 | 2072 | 'type' => 'string', |
2073 | - 'context' => array( 'view', 'edit' ), |
|
2073 | + 'context' => array('view', 'edit'), |
|
2074 | 2074 | ), |
2075 | 2075 | 'position' => array( |
2076 | - 'description' => __( 'Attribute position.', 'woocommerce' ), |
|
2076 | + 'description' => __('Attribute position.', 'woocommerce'), |
|
2077 | 2077 | 'type' => 'integer', |
2078 | - 'context' => array( 'view', 'edit' ), |
|
2078 | + 'context' => array('view', 'edit'), |
|
2079 | 2079 | ), |
2080 | 2080 | 'visible' => array( |
2081 | - 'description' => __( "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", 'woocommerce' ), |
|
2081 | + 'description' => __("Define if the attribute is visible on the \"Additional information\" tab in the product's page.", 'woocommerce'), |
|
2082 | 2082 | 'type' => 'boolean', |
2083 | 2083 | 'default' => false, |
2084 | - 'context' => array( 'view', 'edit' ), |
|
2084 | + 'context' => array('view', 'edit'), |
|
2085 | 2085 | ), |
2086 | 2086 | 'variation' => array( |
2087 | - 'description' => __( 'Define if the attribute can be used as variation.', 'woocommerce' ), |
|
2087 | + 'description' => __('Define if the attribute can be used as variation.', 'woocommerce'), |
|
2088 | 2088 | 'type' => 'boolean', |
2089 | 2089 | 'default' => false, |
2090 | - 'context' => array( 'view', 'edit' ), |
|
2090 | + 'context' => array('view', 'edit'), |
|
2091 | 2091 | ), |
2092 | 2092 | 'options' => array( |
2093 | - 'description' => __( 'List of available term names of the attribute.', 'woocommerce' ), |
|
2093 | + 'description' => __('List of available term names of the attribute.', 'woocommerce'), |
|
2094 | 2094 | 'type' => 'array', |
2095 | 2095 | 'items' => array( |
2096 | 2096 | 'type' => 'string', |
2097 | 2097 | ), |
2098 | - 'context' => array( 'view', 'edit' ), |
|
2098 | + 'context' => array('view', 'edit'), |
|
2099 | 2099 | ), |
2100 | 2100 | ), |
2101 | 2101 | ), |
2102 | 2102 | ), |
2103 | 2103 | 'default_attributes' => array( |
2104 | - 'description' => __( 'Defaults variation attributes.', 'woocommerce' ), |
|
2104 | + 'description' => __('Defaults variation attributes.', 'woocommerce'), |
|
2105 | 2105 | 'type' => 'array', |
2106 | - 'context' => array( 'view', 'edit' ), |
|
2106 | + 'context' => array('view', 'edit'), |
|
2107 | 2107 | 'items' => array( |
2108 | 2108 | 'type' => 'object', |
2109 | 2109 | 'properties' => array( |
2110 | 2110 | 'id' => array( |
2111 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
2111 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
2112 | 2112 | 'type' => 'integer', |
2113 | - 'context' => array( 'view', 'edit' ), |
|
2113 | + 'context' => array('view', 'edit'), |
|
2114 | 2114 | ), |
2115 | 2115 | 'name' => array( |
2116 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
2116 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
2117 | 2117 | 'type' => 'string', |
2118 | - 'context' => array( 'view', 'edit' ), |
|
2118 | + 'context' => array('view', 'edit'), |
|
2119 | 2119 | ), |
2120 | 2120 | 'option' => array( |
2121 | - 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
|
2121 | + 'description' => __('Selected attribute term name.', 'woocommerce'), |
|
2122 | 2122 | 'type' => 'string', |
2123 | - 'context' => array( 'view', 'edit' ), |
|
2123 | + 'context' => array('view', 'edit'), |
|
2124 | 2124 | ), |
2125 | 2125 | ), |
2126 | 2126 | ), |
2127 | 2127 | ), |
2128 | 2128 | 'variations' => array( |
2129 | - 'description' => __( 'List of variations IDs.', 'woocommerce' ), |
|
2129 | + 'description' => __('List of variations IDs.', 'woocommerce'), |
|
2130 | 2130 | 'type' => 'array', |
2131 | - 'context' => array( 'view', 'edit' ), |
|
2131 | + 'context' => array('view', 'edit'), |
|
2132 | 2132 | 'items' => array( |
2133 | 2133 | 'type' => 'integer', |
2134 | 2134 | ), |
2135 | 2135 | 'readonly' => true, |
2136 | 2136 | ), |
2137 | 2137 | 'grouped_products' => array( |
2138 | - 'description' => __( 'List of grouped products ID.', 'woocommerce' ), |
|
2138 | + 'description' => __('List of grouped products ID.', 'woocommerce'), |
|
2139 | 2139 | 'type' => 'array', |
2140 | 2140 | 'items' => array( |
2141 | 2141 | 'type' => 'integer', |
2142 | 2142 | ), |
2143 | - 'context' => array( 'view', 'edit' ), |
|
2143 | + 'context' => array('view', 'edit'), |
|
2144 | 2144 | 'readonly' => true, |
2145 | 2145 | ), |
2146 | 2146 | 'menu_order' => array( |
2147 | - 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), |
|
2147 | + 'description' => __('Menu order, used to custom sort products.', 'woocommerce'), |
|
2148 | 2148 | 'type' => 'integer', |
2149 | - 'context' => array( 'view', 'edit' ), |
|
2149 | + 'context' => array('view', 'edit'), |
|
2150 | 2150 | ), |
2151 | 2151 | 'meta_data' => array( |
2152 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
2152 | + 'description' => __('Meta data.', 'woocommerce'), |
|
2153 | 2153 | 'type' => 'array', |
2154 | - 'context' => array( 'view', 'edit' ), |
|
2154 | + 'context' => array('view', 'edit'), |
|
2155 | 2155 | 'items' => array( |
2156 | 2156 | 'type' => 'object', |
2157 | 2157 | 'properties' => array( |
2158 | 2158 | 'id' => array( |
2159 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
2159 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
2160 | 2160 | 'type' => 'integer', |
2161 | - 'context' => array( 'view', 'edit' ), |
|
2161 | + 'context' => array('view', 'edit'), |
|
2162 | 2162 | 'readonly' => true, |
2163 | 2163 | ), |
2164 | 2164 | 'key' => array( |
2165 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
2165 | + 'description' => __('Meta key.', 'woocommerce'), |
|
2166 | 2166 | 'type' => 'string', |
2167 | - 'context' => array( 'view', 'edit' ), |
|
2167 | + 'context' => array('view', 'edit'), |
|
2168 | 2168 | ), |
2169 | 2169 | 'value' => array( |
2170 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
2170 | + 'description' => __('Meta value.', 'woocommerce'), |
|
2171 | 2171 | 'type' => 'mixed', |
2172 | - 'context' => array( 'view', 'edit' ), |
|
2172 | + 'context' => array('view', 'edit'), |
|
2173 | 2173 | ), |
2174 | 2174 | ), |
2175 | 2175 | ), |
2176 | 2176 | ), |
2177 | 2177 | ), |
2178 | 2178 | ); |
2179 | - return $this->add_additional_fields_schema( $schema ); |
|
2179 | + return $this->add_additional_fields_schema($schema); |
|
2180 | 2180 | } |
2181 | 2181 | |
2182 | 2182 | /** |
@@ -2187,115 +2187,115 @@ discard block |
||
2187 | 2187 | public function get_collection_params() { |
2188 | 2188 | $params = parent::get_collection_params(); |
2189 | 2189 | |
2190 | - $params['slug'] = array( |
|
2191 | - 'description' => __( 'Limit result set to products with a specific slug.', 'woocommerce' ), |
|
2190 | + $params['slug'] = array( |
|
2191 | + 'description' => __('Limit result set to products with a specific slug.', 'woocommerce'), |
|
2192 | 2192 | 'type' => 'string', |
2193 | 2193 | 'validate_callback' => 'rest_validate_request_arg', |
2194 | 2194 | ); |
2195 | - $params['status'] = array( |
|
2195 | + $params['status'] = array( |
|
2196 | 2196 | 'default' => 'any', |
2197 | - 'description' => __( 'Limit result set to products assigned a specific status.', 'woocommerce' ), |
|
2197 | + 'description' => __('Limit result set to products assigned a specific status.', 'woocommerce'), |
|
2198 | 2198 | 'type' => 'string', |
2199 | - 'enum' => array_merge( array( 'any', 'future' ), array_keys( get_post_statuses() ) ), |
|
2199 | + 'enum' => array_merge(array('any', 'future'), array_keys(get_post_statuses())), |
|
2200 | 2200 | 'sanitize_callback' => 'sanitize_key', |
2201 | 2201 | 'validate_callback' => 'rest_validate_request_arg', |
2202 | 2202 | ); |
2203 | - $params['type'] = array( |
|
2204 | - 'description' => __( 'Limit result set to products assigned a specific type.', 'woocommerce' ), |
|
2203 | + $params['type'] = array( |
|
2204 | + 'description' => __('Limit result set to products assigned a specific type.', 'woocommerce'), |
|
2205 | 2205 | 'type' => 'string', |
2206 | - 'enum' => array_keys( wc_get_product_types() ), |
|
2206 | + 'enum' => array_keys(wc_get_product_types()), |
|
2207 | 2207 | 'sanitize_callback' => 'sanitize_key', |
2208 | 2208 | 'validate_callback' => 'rest_validate_request_arg', |
2209 | 2209 | ); |
2210 | - $params['sku'] = array( |
|
2211 | - 'description' => __( 'Limit result set to products with specific SKU(s). Use commas to separate.', 'woocommerce' ), |
|
2210 | + $params['sku'] = array( |
|
2211 | + 'description' => __('Limit result set to products with specific SKU(s). Use commas to separate.', 'woocommerce'), |
|
2212 | 2212 | 'type' => 'string', |
2213 | 2213 | 'sanitize_callback' => 'sanitize_text_field', |
2214 | 2214 | 'validate_callback' => 'rest_validate_request_arg', |
2215 | 2215 | ); |
2216 | - $params['featured'] = array( |
|
2217 | - 'description' => __( 'Limit result set to featured products.', 'woocommerce' ), |
|
2216 | + $params['featured'] = array( |
|
2217 | + 'description' => __('Limit result set to featured products.', 'woocommerce'), |
|
2218 | 2218 | 'type' => 'boolean', |
2219 | 2219 | 'sanitize_callback' => 'wc_string_to_bool', |
2220 | 2220 | 'validate_callback' => 'rest_validate_request_arg', |
2221 | 2221 | ); |
2222 | - $params['category'] = array( |
|
2223 | - 'description' => __( 'Limit result set to products assigned a specific category ID.', 'woocommerce' ), |
|
2222 | + $params['category'] = array( |
|
2223 | + 'description' => __('Limit result set to products assigned a specific category ID.', 'woocommerce'), |
|
2224 | 2224 | 'type' => 'string', |
2225 | 2225 | 'sanitize_callback' => 'wp_parse_id_list', |
2226 | 2226 | 'validate_callback' => 'rest_validate_request_arg', |
2227 | 2227 | ); |
2228 | - $params['tag'] = array( |
|
2229 | - 'description' => __( 'Limit result set to products assigned a specific tag ID.', 'woocommerce' ), |
|
2228 | + $params['tag'] = array( |
|
2229 | + 'description' => __('Limit result set to products assigned a specific tag ID.', 'woocommerce'), |
|
2230 | 2230 | 'type' => 'string', |
2231 | 2231 | 'sanitize_callback' => 'wp_parse_id_list', |
2232 | 2232 | 'validate_callback' => 'rest_validate_request_arg', |
2233 | 2233 | ); |
2234 | 2234 | $params['shipping_class'] = array( |
2235 | - 'description' => __( 'Limit result set to products assigned a specific shipping class ID.', 'woocommerce' ), |
|
2235 | + 'description' => __('Limit result set to products assigned a specific shipping class ID.', 'woocommerce'), |
|
2236 | 2236 | 'type' => 'string', |
2237 | 2237 | 'sanitize_callback' => 'wp_parse_id_list', |
2238 | 2238 | 'validate_callback' => 'rest_validate_request_arg', |
2239 | 2239 | ); |
2240 | - $params['attribute'] = array( |
|
2241 | - 'description' => __( 'Limit result set to products with a specific attribute. Use the taxonomy name/attribute slug.', 'woocommerce' ), |
|
2240 | + $params['attribute'] = array( |
|
2241 | + 'description' => __('Limit result set to products with a specific attribute. Use the taxonomy name/attribute slug.', 'woocommerce'), |
|
2242 | 2242 | 'type' => 'string', |
2243 | 2243 | 'sanitize_callback' => 'sanitize_text_field', |
2244 | 2244 | 'validate_callback' => 'rest_validate_request_arg', |
2245 | 2245 | ); |
2246 | 2246 | $params['attribute_term'] = array( |
2247 | - 'description' => __( 'Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce' ), |
|
2247 | + 'description' => __('Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce'), |
|
2248 | 2248 | 'type' => 'string', |
2249 | 2249 | 'sanitize_callback' => 'wp_parse_id_list', |
2250 | 2250 | 'validate_callback' => 'rest_validate_request_arg', |
2251 | 2251 | ); |
2252 | 2252 | |
2253 | - if ( wc_tax_enabled() ) { |
|
2253 | + if (wc_tax_enabled()) { |
|
2254 | 2254 | $params['tax_class'] = array( |
2255 | - 'description' => __( 'Limit result set to products with a specific tax class.', 'woocommerce' ), |
|
2255 | + 'description' => __('Limit result set to products with a specific tax class.', 'woocommerce'), |
|
2256 | 2256 | 'type' => 'string', |
2257 | - 'enum' => array_merge( array( 'standard' ), \WC_Tax::get_tax_class_slugs() ), |
|
2257 | + 'enum' => array_merge(array('standard'), \WC_Tax::get_tax_class_slugs()), |
|
2258 | 2258 | 'sanitize_callback' => 'sanitize_text_field', |
2259 | 2259 | 'validate_callback' => 'rest_validate_request_arg', |
2260 | 2260 | ); |
2261 | 2261 | } |
2262 | - $params['on_sale'] = array( |
|
2263 | - 'description' => __( 'Limit result set to products on sale.', 'woocommerce' ), |
|
2262 | + $params['on_sale'] = array( |
|
2263 | + 'description' => __('Limit result set to products on sale.', 'woocommerce'), |
|
2264 | 2264 | 'type' => 'boolean', |
2265 | 2265 | 'sanitize_callback' => 'wc_string_to_bool', |
2266 | 2266 | 'validate_callback' => 'rest_validate_request_arg', |
2267 | 2267 | ); |
2268 | 2268 | $params['min_price'] = array( |
2269 | - 'description' => __( 'Limit result set to products based on a minimum price.', 'woocommerce' ), |
|
2269 | + 'description' => __('Limit result set to products based on a minimum price.', 'woocommerce'), |
|
2270 | 2270 | 'type' => 'string', |
2271 | 2271 | 'sanitize_callback' => 'sanitize_text_field', |
2272 | 2272 | 'validate_callback' => 'rest_validate_request_arg', |
2273 | 2273 | ); |
2274 | 2274 | $params['max_price'] = array( |
2275 | - 'description' => __( 'Limit result set to products based on a maximum price.', 'woocommerce' ), |
|
2275 | + 'description' => __('Limit result set to products based on a maximum price.', 'woocommerce'), |
|
2276 | 2276 | 'type' => 'string', |
2277 | 2277 | 'sanitize_callback' => 'sanitize_text_field', |
2278 | 2278 | 'validate_callback' => 'rest_validate_request_arg', |
2279 | 2279 | ); |
2280 | 2280 | $params['stock_status'] = array( |
2281 | - 'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce' ), |
|
2281 | + 'description' => __('Limit result set to products with specified stock status.', 'woocommerce'), |
|
2282 | 2282 | 'type' => 'string', |
2283 | - 'enum' => array_keys( wc_get_product_stock_status_options() ), |
|
2283 | + 'enum' => array_keys(wc_get_product_stock_status_options()), |
|
2284 | 2284 | 'sanitize_callback' => 'sanitize_text_field', |
2285 | 2285 | 'validate_callback' => 'rest_validate_request_arg', |
2286 | 2286 | ); |
2287 | 2287 | $params['low_in_stock'] = array( |
2288 | - 'description' => __( 'Limit result set to products that are low or out of stock.', 'woocommerce' ), |
|
2288 | + 'description' => __('Limit result set to products that are low or out of stock.', 'woocommerce'), |
|
2289 | 2289 | 'type' => 'boolean', |
2290 | 2290 | 'default' => false, |
2291 | 2291 | 'sanitize_callback' => 'wc_string_to_bool', |
2292 | 2292 | ); |
2293 | - $params['search'] = array( |
|
2294 | - 'description' => __( 'Search by similar product name or sku.', 'woocommerce' ), |
|
2293 | + $params['search'] = array( |
|
2294 | + 'description' => __('Search by similar product name or sku.', 'woocommerce'), |
|
2295 | 2295 | 'type' => 'string', |
2296 | 2296 | 'validate_callback' => 'rest_validate_request_arg', |
2297 | 2297 | ); |
2298 | - $params['orderby']['enum'] = array_merge( $params['orderby']['enum'], array( 'price', 'popularity', 'rating' ) ); |
|
2298 | + $params['orderby']['enum'] = array_merge($params['orderby']['enum'], array('price', 'popularity', 'rating')); |
|
2299 | 2299 | |
2300 | 2300 | return $params; |
2301 | 2301 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API variations controller class. |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * Initialize product actions (parent). |
35 | 35 | */ |
36 | 36 | public function __construct() { |
37 | - add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'add_product_id' ), 9, 2 ); |
|
37 | + add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'add_product_id'), 9, 2); |
|
38 | 38 | parent::__construct(); |
39 | 39 | } |
40 | 40 | |
@@ -48,23 +48,23 @@ discard block |
||
48 | 48 | array( |
49 | 49 | 'args' => array( |
50 | 50 | 'product_id' => array( |
51 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
51 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
52 | 52 | 'type' => 'integer', |
53 | 53 | ), |
54 | 54 | ), |
55 | 55 | array( |
56 | 56 | 'methods' => \WP_REST_Server::READABLE, |
57 | - 'callback' => array( $this, 'get_items' ), |
|
58 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
57 | + 'callback' => array($this, 'get_items'), |
|
58 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
59 | 59 | 'args' => $this->get_collection_params(), |
60 | 60 | ), |
61 | 61 | array( |
62 | 62 | 'methods' => \WP_REST_Server::CREATABLE, |
63 | - 'callback' => array( $this, 'create_item' ), |
|
64 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
65 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
63 | + 'callback' => array($this, 'create_item'), |
|
64 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
65 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
66 | 66 | ), |
67 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
67 | + 'schema' => array($this, 'get_public_item_schema'), |
|
68 | 68 | ), |
69 | 69 | true |
70 | 70 | ); |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | array( |
75 | 75 | 'args' => array( |
76 | 76 | 'product_id' => array( |
77 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
77 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
78 | 78 | 'type' => 'integer', |
79 | 79 | ), |
80 | 80 | 'id' => array( |
81 | - 'description' => __( 'Unique identifier for the variation.', 'woocommerce' ), |
|
81 | + 'description' => __('Unique identifier for the variation.', 'woocommerce'), |
|
82 | 82 | 'type' => 'integer', |
83 | 83 | ), |
84 | 84 | ), |
85 | 85 | array( |
86 | 86 | 'methods' => \WP_REST_Server::READABLE, |
87 | - 'callback' => array( $this, 'get_item' ), |
|
88 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
87 | + 'callback' => array($this, 'get_item'), |
|
88 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
89 | 89 | 'args' => array( |
90 | 90 | 'context' => $this->get_context_param( |
91 | 91 | array( |
@@ -96,23 +96,23 @@ discard block |
||
96 | 96 | ), |
97 | 97 | array( |
98 | 98 | 'methods' => \WP_REST_Server::EDITABLE, |
99 | - 'callback' => array( $this, 'update_item' ), |
|
100 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
101 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
99 | + 'callback' => array($this, 'update_item'), |
|
100 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
101 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
102 | 102 | ), |
103 | 103 | array( |
104 | 104 | 'methods' => \WP_REST_Server::DELETABLE, |
105 | - 'callback' => array( $this, 'delete_item' ), |
|
106 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
105 | + 'callback' => array($this, 'delete_item'), |
|
106 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
107 | 107 | 'args' => array( |
108 | 108 | 'force' => array( |
109 | 109 | 'default' => false, |
110 | 110 | 'type' => 'boolean', |
111 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
111 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
112 | 112 | ), |
113 | 113 | ), |
114 | 114 | ), |
115 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
115 | + 'schema' => array($this, 'get_public_item_schema'), |
|
116 | 116 | ), |
117 | 117 | true |
118 | 118 | ); |
@@ -121,17 +121,17 @@ discard block |
||
121 | 121 | array( |
122 | 122 | 'args' => array( |
123 | 123 | 'product_id' => array( |
124 | - 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
|
124 | + 'description' => __('Unique identifier for the variable product.', 'woocommerce'), |
|
125 | 125 | 'type' => 'integer', |
126 | 126 | ), |
127 | 127 | ), |
128 | 128 | array( |
129 | 129 | 'methods' => \WP_REST_Server::EDITABLE, |
130 | - 'callback' => array( $this, 'batch_items' ), |
|
131 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
132 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
130 | + 'callback' => array($this, 'batch_items'), |
|
131 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
132 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
133 | 133 | ), |
134 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
134 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
135 | 135 | ), |
136 | 136 | true |
137 | 137 | ); |
@@ -144,8 +144,8 @@ discard block |
||
144 | 144 | * @param int $id Object ID. |
145 | 145 | * @return WC_Data |
146 | 146 | */ |
147 | - protected function get_object( $id ) { |
|
148 | - return wc_get_product( $id ); |
|
147 | + protected function get_object($id) { |
|
148 | + return wc_get_product($id); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -154,16 +154,16 @@ discard block |
||
154 | 154 | * @param \WP_REST_Request $request Full details about the request. |
155 | 155 | * @return \WP_Error|boolean |
156 | 156 | */ |
157 | - public function update_item_permissions_check( $request ) { |
|
158 | - $object = $this->get_object( (int) $request['id'] ); |
|
157 | + public function update_item_permissions_check($request) { |
|
158 | + $object = $this->get_object((int) $request['id']); |
|
159 | 159 | |
160 | - if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) { |
|
161 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
160 | + if ($object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions($this->post_type, 'edit', $object->get_id())) { |
|
161 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // Check if variation belongs to the correct parent product. |
165 | - if ( $object && 0 !== $object->get_parent_id() && absint( $request['product_id'] ) !== $object->get_parent_id() ) { |
|
166 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Parent product does not match current variation.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
165 | + if ($object && 0 !== $object->get_parent_id() && absint($request['product_id']) !== $object->get_parent_id()) { |
|
166 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Parent product does not match current variation.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | return true; |
@@ -176,33 +176,33 @@ discard block |
||
176 | 176 | * @param \WP_REST_Request $request Request object. |
177 | 177 | * @return \WP_REST_Response |
178 | 178 | */ |
179 | - public function prepare_object_for_response( $object, $request ) { |
|
180 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
179 | + public function prepare_object_for_response($object, $request) { |
|
180 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
181 | 181 | $data = array( |
182 | 182 | 'id' => $object->get_id(), |
183 | - 'name' => $object->get_name( $context ), |
|
183 | + 'name' => $object->get_name($context), |
|
184 | 184 | 'type' => $object->get_type(), |
185 | - 'parent_id' => $object->get_parent_id( $context ), |
|
186 | - 'date_created' => wc_rest_prepare_date_response( $object->get_date_created(), false ), |
|
187 | - 'date_created_gmt' => wc_rest_prepare_date_response( $object->get_date_created() ), |
|
188 | - 'date_modified' => wc_rest_prepare_date_response( $object->get_date_modified(), false ), |
|
189 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $object->get_date_modified() ), |
|
190 | - 'description' => wc_format_content( $object->get_description() ), |
|
185 | + 'parent_id' => $object->get_parent_id($context), |
|
186 | + 'date_created' => wc_rest_prepare_date_response($object->get_date_created(), false), |
|
187 | + 'date_created_gmt' => wc_rest_prepare_date_response($object->get_date_created()), |
|
188 | + 'date_modified' => wc_rest_prepare_date_response($object->get_date_modified(), false), |
|
189 | + 'date_modified_gmt' => wc_rest_prepare_date_response($object->get_date_modified()), |
|
190 | + 'description' => wc_format_content($object->get_description()), |
|
191 | 191 | 'permalink' => $object->get_permalink(), |
192 | 192 | 'sku' => $object->get_sku(), |
193 | 193 | 'price' => $object->get_price(), |
194 | 194 | 'regular_price' => $object->get_regular_price(), |
195 | 195 | 'sale_price' => $object->get_sale_price(), |
196 | - 'date_on_sale_from' => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ), |
|
197 | - 'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ), |
|
198 | - 'date_on_sale_to' => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ), |
|
199 | - 'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ), |
|
196 | + 'date_on_sale_from' => wc_rest_prepare_date_response($object->get_date_on_sale_from(), false), |
|
197 | + 'date_on_sale_from_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_from()), |
|
198 | + 'date_on_sale_to' => wc_rest_prepare_date_response($object->get_date_on_sale_to(), false), |
|
199 | + 'date_on_sale_to_gmt' => wc_rest_prepare_date_response($object->get_date_on_sale_to()), |
|
200 | 200 | 'on_sale' => $object->is_on_sale(), |
201 | 201 | 'status' => $object->get_status(), |
202 | 202 | 'purchasable' => $object->is_purchasable(), |
203 | 203 | 'virtual' => $object->is_virtual(), |
204 | 204 | 'downloadable' => $object->is_downloadable(), |
205 | - 'downloads' => $this->get_downloads( $object ), |
|
205 | + 'downloads' => $this->get_downloads($object), |
|
206 | 206 | 'download_limit' => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1, |
207 | 207 | 'download_expiry' => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1, |
208 | 208 | 'tax_status' => $object->get_tax_status(), |
@@ -221,17 +221,17 @@ discard block |
||
221 | 221 | ), |
222 | 222 | 'shipping_class' => $object->get_shipping_class(), |
223 | 223 | 'shipping_class_id' => $object->get_shipping_class_id(), |
224 | - 'image' => $this->get_image( $object ), |
|
225 | - 'attributes' => $this->get_attributes( $object ), |
|
224 | + 'image' => $this->get_image($object), |
|
225 | + 'attributes' => $this->get_attributes($object), |
|
226 | 226 | 'menu_order' => $object->get_menu_order(), |
227 | 227 | 'meta_data' => $object->get_meta_data(), |
228 | 228 | ); |
229 | 229 | |
230 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
231 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
232 | - $data = $this->filter_response_by_context( $data, $context ); |
|
233 | - $response = rest_ensure_response( $data ); |
|
234 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
230 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
231 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
232 | + $data = $this->filter_response_by_context($data, $context); |
|
233 | + $response = rest_ensure_response($data); |
|
234 | + $response->add_links($this->prepare_links($object, $request)); |
|
235 | 235 | |
236 | 236 | /** |
237 | 237 | * Filter the data for a response. |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @param WC_Data $object Object data. |
244 | 244 | * @param \WP_REST_Request $request Request object. |
245 | 245 | */ |
246 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
246 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -252,32 +252,32 @@ discard block |
||
252 | 252 | * @param WC_Product_Variation $variation Variation data. |
253 | 253 | * @return array |
254 | 254 | */ |
255 | - protected function get_image( $variation ) { |
|
256 | - if ( ! $variation->get_image_id() ) { |
|
255 | + protected function get_image($variation) { |
|
256 | + if ( ! $variation->get_image_id()) { |
|
257 | 257 | return; |
258 | 258 | } |
259 | 259 | |
260 | 260 | $attachment_id = $variation->get_image_id(); |
261 | - $attachment_post = get_post( $attachment_id ); |
|
262 | - if ( is_null( $attachment_post ) ) { |
|
261 | + $attachment_post = get_post($attachment_id); |
|
262 | + if (is_null($attachment_post)) { |
|
263 | 263 | return; |
264 | 264 | } |
265 | 265 | |
266 | - $attachment = wp_get_attachment_image_src( $attachment_id, 'full' ); |
|
267 | - if ( ! is_array( $attachment ) ) { |
|
266 | + $attachment = wp_get_attachment_image_src($attachment_id, 'full'); |
|
267 | + if ( ! is_array($attachment)) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
271 | - if ( ! isset( $image ) ) { |
|
271 | + if ( ! isset($image)) { |
|
272 | 272 | return array( |
273 | 273 | 'id' => (int) $attachment_id, |
274 | - 'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date, false ), |
|
275 | - 'date_created_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ), |
|
276 | - 'date_modified' => wc_rest_prepare_date_response( $attachment_post->post_modified, false ), |
|
277 | - 'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ), |
|
278 | - 'src' => current( $attachment ), |
|
279 | - 'name' => get_the_title( $attachment_id ), |
|
280 | - 'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ), |
|
274 | + 'date_created' => wc_rest_prepare_date_response($attachment_post->post_date, false), |
|
275 | + 'date_created_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_date_gmt)), |
|
276 | + 'date_modified' => wc_rest_prepare_date_response($attachment_post->post_modified, false), |
|
277 | + 'date_modified_gmt' => wc_rest_prepare_date_response(strtotime($attachment_post->post_modified_gmt)), |
|
278 | + 'src' => current($attachment), |
|
279 | + 'name' => get_the_title($attachment_id), |
|
280 | + 'alt' => get_post_meta($attachment_id, '_wp_attachment_image_alt', true), |
|
281 | 281 | ); |
282 | 282 | } |
283 | 283 | } |
@@ -291,35 +291,35 @@ discard block |
||
291 | 291 | * @param array $image Image data. |
292 | 292 | * @return WC_Product_Variation |
293 | 293 | */ |
294 | - protected function set_variation_image( $variation, $image ) { |
|
295 | - $attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0; |
|
294 | + protected function set_variation_image($variation, $image) { |
|
295 | + $attachment_id = isset($image['id']) ? absint($image['id']) : 0; |
|
296 | 296 | |
297 | - if ( 0 === $attachment_id && isset( $image['src'] ) ) { |
|
298 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) ); |
|
297 | + if (0 === $attachment_id && isset($image['src'])) { |
|
298 | + $upload = wc_rest_upload_image_from_url(esc_url_raw($image['src'])); |
|
299 | 299 | |
300 | - if ( is_wp_error( $upload ) ) { |
|
301 | - if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array( $image ) ) ) { |
|
302 | - throw new \WC_REST_Exception( 'woocommerce_variation_image_upload_error', $upload->get_error_message(), 400 ); |
|
300 | + if (is_wp_error($upload)) { |
|
301 | + if ( ! apply_filters('woocommerce_rest_suppress_image_upload_error', false, $upload, $variation->get_id(), array($image))) { |
|
302 | + throw new \WC_REST_Exception('woocommerce_variation_image_upload_error', $upload->get_error_message(), 400); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | - $attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $variation->get_id() ); |
|
306 | + $attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $variation->get_id()); |
|
307 | 307 | } |
308 | 308 | |
309 | - if ( ! wp_attachment_is_image( $attachment_id ) ) { |
|
309 | + if ( ! wp_attachment_is_image($attachment_id)) { |
|
310 | 310 | /* translators: %s: attachment ID */ |
311 | - throw new \WC_REST_Exception( 'woocommerce_variation_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 ); |
|
311 | + throw new \WC_REST_Exception('woocommerce_variation_invalid_image_id', sprintf(__('#%s is an invalid image ID.', 'woocommerce'), $attachment_id), 400); |
|
312 | 312 | } |
313 | 313 | |
314 | - $variation->set_image_id( $attachment_id ); |
|
314 | + $variation->set_image_id($attachment_id); |
|
315 | 315 | |
316 | 316 | // Set the image alt if present. |
317 | - if ( ! empty( $image['alt'] ) ) { |
|
318 | - update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) ); |
|
317 | + if ( ! empty($image['alt'])) { |
|
318 | + update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt'])); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | // Set the image name if present. |
322 | - if ( ! empty( $image['name'] ) ) { |
|
322 | + if ( ! empty($image['name'])) { |
|
323 | 323 | wp_update_post( |
324 | 324 | array( |
325 | 325 | 'ID' => $attachment_id, |
@@ -338,17 +338,17 @@ discard block |
||
338 | 338 | * @param \WP_REST_Request $request Full details about the request. |
339 | 339 | * @return array |
340 | 340 | */ |
341 | - protected function prepare_objects_query( $request ) { |
|
342 | - $args = parent::prepare_objects_query( $request ); |
|
341 | + protected function prepare_objects_query($request) { |
|
342 | + $args = parent::prepare_objects_query($request); |
|
343 | 343 | |
344 | 344 | // Set post_status. |
345 | 345 | $args['post_status'] = $request['status']; |
346 | 346 | |
347 | 347 | // Filter by sku. |
348 | - if ( ! empty( $request['sku'] ) ) { |
|
349 | - $skus = explode( ',', $request['sku'] ); |
|
348 | + if ( ! empty($request['sku'])) { |
|
349 | + $skus = explode(',', $request['sku']); |
|
350 | 350 | // Include the current string as a SKU too. |
351 | - if ( 1 < count( $skus ) ) { |
|
351 | + if (1 < count($skus)) { |
|
352 | 352 | $skus[] = $request['sku']; |
353 | 353 | } |
354 | 354 | |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | } |
364 | 364 | |
365 | 365 | // Filter by tax class. |
366 | - if ( ! empty( $request['tax_class'] ) ) { |
|
366 | + if ( ! empty($request['tax_class'])) { |
|
367 | 367 | $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
368 | 368 | $args, |
369 | 369 | array( |
@@ -374,12 +374,12 @@ discard block |
||
374 | 374 | } |
375 | 375 | |
376 | 376 | // Price filter. |
377 | - if ( ! empty( $request['min_price'] ) || ! empty( $request['max_price'] ) ) { |
|
378 | - $args['meta_query'] = $this->add_meta_query( $args, wc_get_min_max_price_meta_query( $request ) ); // WPCS: slow query ok. |
|
377 | + if ( ! empty($request['min_price']) || ! empty($request['max_price'])) { |
|
378 | + $args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request)); // WPCS: slow query ok. |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | // Filter product based on stock_status. |
382 | - if ( ! empty( $request['stock_status'] ) ) { |
|
382 | + if ( ! empty($request['stock_status'])) { |
|
383 | 383 | $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
384 | 384 | $args, |
385 | 385 | array( |
@@ -390,28 +390,28 @@ discard block |
||
390 | 390 | } |
391 | 391 | |
392 | 392 | // Filter by on sale products. |
393 | - if ( is_bool( $request['on_sale'] ) ) { |
|
393 | + if (is_bool($request['on_sale'])) { |
|
394 | 394 | $on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in'; |
395 | 395 | $on_sale_ids = wc_get_product_ids_on_sale(); |
396 | 396 | |
397 | 397 | // Use 0 when there's no on sale products to avoid return all products. |
398 | - $on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids; |
|
398 | + $on_sale_ids = empty($on_sale_ids) ? array(0) : $on_sale_ids; |
|
399 | 399 | |
400 | - $args[ $on_sale_key ] += $on_sale_ids; |
|
400 | + $args[$on_sale_key] += $on_sale_ids; |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | // Force the post_type argument, since it's not a user input variable. |
404 | - if ( ! empty( $request['sku'] ) ) { |
|
405 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
404 | + if ( ! empty($request['sku'])) { |
|
405 | + $args['post_type'] = array('product', 'product_variation'); |
|
406 | 406 | } else { |
407 | 407 | $args['post_type'] = $this->post_type; |
408 | 408 | } |
409 | 409 | |
410 | 410 | $args['post_parent'] = $request['product_id']; |
411 | 411 | |
412 | - if ( ! empty( $request['search'] ) ) { |
|
412 | + if ( ! empty($request['search'])) { |
|
413 | 413 | $args['search'] = $request['search']; |
414 | - unset( $args['s'] ); |
|
414 | + unset($args['s']); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | return $args; |
@@ -424,136 +424,136 @@ discard block |
||
424 | 424 | * @param bool $creating If is creating a new object. |
425 | 425 | * @return \WP_Error|WC_Data |
426 | 426 | */ |
427 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
428 | - if ( isset( $request['id'] ) ) { |
|
429 | - $variation = wc_get_product( absint( $request['id'] ) ); |
|
427 | + protected function prepare_object_for_database($request, $creating = false) { |
|
428 | + if (isset($request['id'])) { |
|
429 | + $variation = wc_get_product(absint($request['id'])); |
|
430 | 430 | } else { |
431 | 431 | $variation = new \WC_Product_Variation(); |
432 | 432 | } |
433 | 433 | |
434 | - $variation->set_parent_id( absint( $request['product_id'] ) ); |
|
434 | + $variation->set_parent_id(absint($request['product_id'])); |
|
435 | 435 | |
436 | 436 | // Status. |
437 | - if ( isset( $request['status'] ) ) { |
|
438 | - $variation->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' ); |
|
437 | + if (isset($request['status'])) { |
|
438 | + $variation->set_status(get_post_status_object($request['status']) ? $request['status'] : 'draft'); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | // SKU. |
442 | - if ( isset( $request['sku'] ) ) { |
|
443 | - $variation->set_sku( wc_clean( $request['sku'] ) ); |
|
442 | + if (isset($request['sku'])) { |
|
443 | + $variation->set_sku(wc_clean($request['sku'])); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | // Thumbnail. |
447 | - if ( isset( $request['image'] ) ) { |
|
448 | - if ( is_array( $request['image'] ) ) { |
|
449 | - $variation = $this->set_variation_image( $variation, $request['image'] ); |
|
447 | + if (isset($request['image'])) { |
|
448 | + if (is_array($request['image'])) { |
|
449 | + $variation = $this->set_variation_image($variation, $request['image']); |
|
450 | 450 | } else { |
451 | - $variation->set_image_id( '' ); |
|
451 | + $variation->set_image_id(''); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
455 | 455 | // Virtual variation. |
456 | - if ( isset( $request['virtual'] ) ) { |
|
457 | - $variation->set_virtual( $request['virtual'] ); |
|
456 | + if (isset($request['virtual'])) { |
|
457 | + $variation->set_virtual($request['virtual']); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | // Downloadable variation. |
461 | - if ( isset( $request['downloadable'] ) ) { |
|
462 | - $variation->set_downloadable( $request['downloadable'] ); |
|
461 | + if (isset($request['downloadable'])) { |
|
462 | + $variation->set_downloadable($request['downloadable']); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | // Downloads. |
466 | - if ( $variation->get_downloadable() ) { |
|
466 | + if ($variation->get_downloadable()) { |
|
467 | 467 | // Downloadable files. |
468 | - if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) { |
|
469 | - $variation = $this->save_downloadable_files( $variation, $request['downloads'] ); |
|
468 | + if (isset($request['downloads']) && is_array($request['downloads'])) { |
|
469 | + $variation = $this->save_downloadable_files($variation, $request['downloads']); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | // Download limit. |
473 | - if ( isset( $request['download_limit'] ) ) { |
|
474 | - $variation->set_download_limit( $request['download_limit'] ); |
|
473 | + if (isset($request['download_limit'])) { |
|
474 | + $variation->set_download_limit($request['download_limit']); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | // Download expiry. |
478 | - if ( isset( $request['download_expiry'] ) ) { |
|
479 | - $variation->set_download_expiry( $request['download_expiry'] ); |
|
478 | + if (isset($request['download_expiry'])) { |
|
479 | + $variation->set_download_expiry($request['download_expiry']); |
|
480 | 480 | } |
481 | 481 | } |
482 | 482 | |
483 | 483 | // Shipping data. |
484 | - $variation = $this->save_product_shipping_data( $variation, $request ); |
|
484 | + $variation = $this->save_product_shipping_data($variation, $request); |
|
485 | 485 | |
486 | 486 | // Stock handling. |
487 | - if ( isset( $request['manage_stock'] ) ) { |
|
488 | - $variation->set_manage_stock( $request['manage_stock'] ); |
|
487 | + if (isset($request['manage_stock'])) { |
|
488 | + $variation->set_manage_stock($request['manage_stock']); |
|
489 | 489 | } |
490 | 490 | |
491 | - if ( isset( $request['stock_status'] ) ) { |
|
492 | - $variation->set_stock_status( $request['stock_status'] ); |
|
491 | + if (isset($request['stock_status'])) { |
|
492 | + $variation->set_stock_status($request['stock_status']); |
|
493 | 493 | } |
494 | 494 | |
495 | - if ( isset( $request['backorders'] ) ) { |
|
496 | - $variation->set_backorders( $request['backorders'] ); |
|
495 | + if (isset($request['backorders'])) { |
|
496 | + $variation->set_backorders($request['backorders']); |
|
497 | 497 | } |
498 | 498 | |
499 | - if ( $variation->get_manage_stock() ) { |
|
500 | - if ( isset( $request['stock_quantity'] ) ) { |
|
501 | - $variation->set_stock_quantity( $request['stock_quantity'] ); |
|
502 | - } elseif ( isset( $request['inventory_delta'] ) ) { |
|
503 | - $stock_quantity = wc_stock_amount( $variation->get_stock_quantity() ); |
|
504 | - $stock_quantity += wc_stock_amount( $request['inventory_delta'] ); |
|
505 | - $variation->set_stock_quantity( $stock_quantity ); |
|
499 | + if ($variation->get_manage_stock()) { |
|
500 | + if (isset($request['stock_quantity'])) { |
|
501 | + $variation->set_stock_quantity($request['stock_quantity']); |
|
502 | + } elseif (isset($request['inventory_delta'])) { |
|
503 | + $stock_quantity = wc_stock_amount($variation->get_stock_quantity()); |
|
504 | + $stock_quantity += wc_stock_amount($request['inventory_delta']); |
|
505 | + $variation->set_stock_quantity($stock_quantity); |
|
506 | 506 | } |
507 | 507 | } else { |
508 | - $variation->set_backorders( 'no' ); |
|
509 | - $variation->set_stock_quantity( '' ); |
|
508 | + $variation->set_backorders('no'); |
|
509 | + $variation->set_stock_quantity(''); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | // Regular Price. |
513 | - if ( isset( $request['regular_price'] ) ) { |
|
514 | - $variation->set_regular_price( $request['regular_price'] ); |
|
513 | + if (isset($request['regular_price'])) { |
|
514 | + $variation->set_regular_price($request['regular_price']); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | // Sale Price. |
518 | - if ( isset( $request['sale_price'] ) ) { |
|
519 | - $variation->set_sale_price( $request['sale_price'] ); |
|
518 | + if (isset($request['sale_price'])) { |
|
519 | + $variation->set_sale_price($request['sale_price']); |
|
520 | 520 | } |
521 | 521 | |
522 | - if ( isset( $request['date_on_sale_from'] ) ) { |
|
523 | - $variation->set_date_on_sale_from( $request['date_on_sale_from'] ); |
|
522 | + if (isset($request['date_on_sale_from'])) { |
|
523 | + $variation->set_date_on_sale_from($request['date_on_sale_from']); |
|
524 | 524 | } |
525 | 525 | |
526 | - if ( isset( $request['date_on_sale_from_gmt'] ) ) { |
|
527 | - $variation->set_date_on_sale_from( $request['date_on_sale_from_gmt'] ? strtotime( $request['date_on_sale_from_gmt'] ) : null ); |
|
526 | + if (isset($request['date_on_sale_from_gmt'])) { |
|
527 | + $variation->set_date_on_sale_from($request['date_on_sale_from_gmt'] ? strtotime($request['date_on_sale_from_gmt']) : null); |
|
528 | 528 | } |
529 | 529 | |
530 | - if ( isset( $request['date_on_sale_to'] ) ) { |
|
531 | - $variation->set_date_on_sale_to( $request['date_on_sale_to'] ); |
|
530 | + if (isset($request['date_on_sale_to'])) { |
|
531 | + $variation->set_date_on_sale_to($request['date_on_sale_to']); |
|
532 | 532 | } |
533 | 533 | |
534 | - if ( isset( $request['date_on_sale_to_gmt'] ) ) { |
|
535 | - $variation->set_date_on_sale_to( $request['date_on_sale_to_gmt'] ? strtotime( $request['date_on_sale_to_gmt'] ) : null ); |
|
534 | + if (isset($request['date_on_sale_to_gmt'])) { |
|
535 | + $variation->set_date_on_sale_to($request['date_on_sale_to_gmt'] ? strtotime($request['date_on_sale_to_gmt']) : null); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | // Tax class. |
539 | - if ( isset( $request['tax_class'] ) ) { |
|
540 | - $variation->set_tax_class( $request['tax_class'] ); |
|
539 | + if (isset($request['tax_class'])) { |
|
540 | + $variation->set_tax_class($request['tax_class']); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | // Description. |
544 | - if ( isset( $request['description'] ) ) { |
|
545 | - $variation->set_description( wp_kses_post( $request['description'] ) ); |
|
544 | + if (isset($request['description'])) { |
|
545 | + $variation->set_description(wp_kses_post($request['description'])); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | // Update taxonomies. |
549 | - if ( isset( $request['attributes'] ) ) { |
|
549 | + if (isset($request['attributes'])) { |
|
550 | 550 | $attributes = array(); |
551 | - $parent = wc_get_product( $variation->get_parent_id() ); |
|
551 | + $parent = wc_get_product($variation->get_parent_id()); |
|
552 | 552 | |
553 | - if ( ! $parent ) { |
|
553 | + if ( ! $parent) { |
|
554 | 554 | return new \WP_Error( |
555 | 555 | // Translators: %d parent ID. |
556 | - "woocommerce_rest_{$this->post_type}_invalid_parent", sprintf( __( 'Cannot set attributes due to invalid parent product.', 'woocommerce' ), $variation->get_parent_id() ), array( |
|
556 | + "woocommerce_rest_{$this->post_type}_invalid_parent", sprintf(__('Cannot set attributes due to invalid parent product.', 'woocommerce'), $variation->get_parent_id()), array( |
|
557 | 557 | 'status' => 404, |
558 | 558 | ) |
559 | 559 | ); |
@@ -561,55 +561,55 @@ discard block |
||
561 | 561 | |
562 | 562 | $parent_attributes = $parent->get_attributes(); |
563 | 563 | |
564 | - foreach ( $request['attributes'] as $attribute ) { |
|
564 | + foreach ($request['attributes'] as $attribute) { |
|
565 | 565 | $attribute_id = 0; |
566 | 566 | $attribute_name = ''; |
567 | 567 | |
568 | 568 | // Check ID for global attributes or name for product attributes. |
569 | - if ( ! empty( $attribute['id'] ) ) { |
|
570 | - $attribute_id = absint( $attribute['id'] ); |
|
571 | - $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
|
572 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
573 | - $attribute_name = sanitize_title( $attribute['name'] ); |
|
569 | + if ( ! empty($attribute['id'])) { |
|
570 | + $attribute_id = absint($attribute['id']); |
|
571 | + $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id); |
|
572 | + } elseif ( ! empty($attribute['name'])) { |
|
573 | + $attribute_name = sanitize_title($attribute['name']); |
|
574 | 574 | } |
575 | 575 | |
576 | - if ( ! $attribute_id && ! $attribute_name ) { |
|
576 | + if ( ! $attribute_id && ! $attribute_name) { |
|
577 | 577 | continue; |
578 | 578 | } |
579 | 579 | |
580 | - if ( ! isset( $parent_attributes[ $attribute_name ] ) || ! $parent_attributes[ $attribute_name ]->get_variation() ) { |
|
580 | + if ( ! isset($parent_attributes[$attribute_name]) || ! $parent_attributes[$attribute_name]->get_variation()) { |
|
581 | 581 | continue; |
582 | 582 | } |
583 | 583 | |
584 | - $attribute_key = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() ); |
|
585 | - $attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
584 | + $attribute_key = sanitize_title($parent_attributes[$attribute_name]->get_name()); |
|
585 | + $attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : ''; |
|
586 | 586 | |
587 | - if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) { |
|
587 | + if ($parent_attributes[$attribute_name]->is_taxonomy()) { |
|
588 | 588 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
589 | - $term = get_term_by( 'name', $attribute_value, $attribute_name ); |
|
589 | + $term = get_term_by('name', $attribute_value, $attribute_name); |
|
590 | 590 | |
591 | - if ( $term && ! is_wp_error( $term ) ) { |
|
591 | + if ($term && ! is_wp_error($term)) { |
|
592 | 592 | $attribute_value = $term->slug; |
593 | 593 | } else { |
594 | - $attribute_value = sanitize_title( $attribute_value ); |
|
594 | + $attribute_value = sanitize_title($attribute_value); |
|
595 | 595 | } |
596 | 596 | } |
597 | 597 | |
598 | - $attributes[ $attribute_key ] = $attribute_value; |
|
598 | + $attributes[$attribute_key] = $attribute_value; |
|
599 | 599 | } |
600 | 600 | |
601 | - $variation->set_attributes( $attributes ); |
|
601 | + $variation->set_attributes($attributes); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | // Menu order. |
605 | - if ( $request['menu_order'] ) { |
|
606 | - $variation->set_menu_order( $request['menu_order'] ); |
|
605 | + if ($request['menu_order']) { |
|
606 | + $variation->set_menu_order($request['menu_order']); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | // Meta data. |
610 | - if ( is_array( $request['meta_data'] ) ) { |
|
611 | - foreach ( $request['meta_data'] as $meta ) { |
|
612 | - $variation->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
610 | + if (is_array($request['meta_data'])) { |
|
611 | + foreach ($request['meta_data'] as $meta) { |
|
612 | + $variation->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | * @param \WP_REST_Request $request Request object. |
624 | 624 | * @param bool $creating If is creating a new object. |
625 | 625 | */ |
626 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating ); |
|
626 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $variation, $request, $creating); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | /** |
@@ -631,9 +631,9 @@ discard block |
||
631 | 631 | * |
632 | 632 | * @param WC_Data $object Object data. |
633 | 633 | */ |
634 | - public function clear_transients( $object ) { |
|
635 | - wc_delete_product_transients( $object->get_parent_id() ); |
|
636 | - wp_cache_delete( 'product-' . $object->get_parent_id(), 'products' ); |
|
634 | + public function clear_transients($object) { |
|
635 | + wc_delete_product_transients($object->get_parent_id()); |
|
636 | + wp_cache_delete('product-' . $object->get_parent_id(), 'products'); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -643,20 +643,20 @@ discard block |
||
643 | 643 | * |
644 | 644 | * @return bool|\WP_Error\WP_REST_Response |
645 | 645 | */ |
646 | - public function delete_item( $request ) { |
|
646 | + public function delete_item($request) { |
|
647 | 647 | $force = (bool) $request['force']; |
648 | - $object = $this->get_object( (int) $request['id'] ); |
|
648 | + $object = $this->get_object((int) $request['id']); |
|
649 | 649 | $result = false; |
650 | 650 | |
651 | - if ( ! $object || 0 === $object->get_id() ) { |
|
651 | + if ( ! $object || 0 === $object->get_id()) { |
|
652 | 652 | return new \WP_Error( |
653 | - "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( |
|
653 | + "woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array( |
|
654 | 654 | 'status' => 404, |
655 | 655 | ) |
656 | 656 | ); |
657 | 657 | } |
658 | 658 | |
659 | - $supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) ); |
|
659 | + $supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable(array($object, 'get_status')); |
|
660 | 660 | |
661 | 661 | /** |
662 | 662 | * Filter whether an object is trashable. |
@@ -666,24 +666,24 @@ discard block |
||
666 | 666 | * @param boolean $supports_trash Whether the object type support trashing. |
667 | 667 | * @param WC_Data $object The object being considered for trashing support. |
668 | 668 | */ |
669 | - $supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object ); |
|
669 | + $supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_object_trashable", $supports_trash, $object); |
|
670 | 670 | |
671 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) { |
|
671 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $object->get_id())) { |
|
672 | 672 | return new \WP_Error( |
673 | 673 | /* translators: %s: post type */ |
674 | - "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( |
|
674 | + "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array( |
|
675 | 675 | 'status' => rest_authorization_required_code(), |
676 | 676 | ) |
677 | 677 | ); |
678 | 678 | } |
679 | 679 | |
680 | - $request->set_param( 'context', 'edit' ); |
|
680 | + $request->set_param('context', 'edit'); |
|
681 | 681 | |
682 | 682 | // If we're forcing, then delete permanently. |
683 | - if ( $force ) { |
|
684 | - $previous = $this->prepare_object_for_response( $object, $request ); |
|
683 | + if ($force) { |
|
684 | + $previous = $this->prepare_object_for_response($object, $request); |
|
685 | 685 | |
686 | - $object->delete( true ); |
|
686 | + $object->delete(true); |
|
687 | 687 | |
688 | 688 | $result = 0 === $object->get_id(); |
689 | 689 | $response = new \WP_REST_Response(); |
@@ -695,21 +695,21 @@ discard block |
||
695 | 695 | ); |
696 | 696 | } else { |
697 | 697 | // If we don't support trashing for this type, error out. |
698 | - if ( ! $supports_trash ) { |
|
698 | + if ( ! $supports_trash) { |
|
699 | 699 | return new \WP_Error( |
700 | 700 | /* translators: %s: post type */ |
701 | - 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( |
|
701 | + 'woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array( |
|
702 | 702 | 'status' => 501, |
703 | 703 | ) |
704 | 704 | ); |
705 | 705 | } |
706 | 706 | |
707 | 707 | // Otherwise, only trash if we haven't already. |
708 | - if ( is_callable( array( $object, 'get_status' ) ) ) { |
|
709 | - if ( 'trash' === $object->get_status() ) { |
|
708 | + if (is_callable(array($object, 'get_status'))) { |
|
709 | + if ('trash' === $object->get_status()) { |
|
710 | 710 | return new \WP_Error( |
711 | 711 | /* translators: %s: post type */ |
712 | - 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( |
|
712 | + 'woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array( |
|
713 | 713 | 'status' => 410, |
714 | 714 | ) |
715 | 715 | ); |
@@ -719,13 +719,13 @@ discard block |
||
719 | 719 | $result = 'trash' === $object->get_status(); |
720 | 720 | } |
721 | 721 | |
722 | - $response = $this->prepare_object_for_response( $object, $request ); |
|
722 | + $response = $this->prepare_object_for_response($object, $request); |
|
723 | 723 | } |
724 | 724 | |
725 | - if ( ! $result ) { |
|
725 | + if ( ! $result) { |
|
726 | 726 | return new \WP_Error( |
727 | 727 | /* translators: %s: post type */ |
728 | - 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( |
|
728 | + 'woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array( |
|
729 | 729 | 'status' => 500, |
730 | 730 | ) |
731 | 731 | ); |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | * @param \WP_REST_Response $response The response data. |
739 | 739 | * @param \WP_REST_Request $request The request sent to the API. |
740 | 740 | */ |
741 | - do_action( "woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request ); |
|
741 | + do_action("woocommerce_rest_delete_{$this->post_type}_object", $object, $response, $request); |
|
742 | 742 | |
743 | 743 | return $response; |
744 | 744 | } |
@@ -750,30 +750,30 @@ discard block |
||
750 | 750 | * @param \WP_REST_Request $request Full details about the request. |
751 | 751 | * @return array Of \WP_Error or \WP_REST_Response. |
752 | 752 | */ |
753 | - public function batch_items( $request ) { |
|
754 | - $items = array_filter( $request->get_params() ); |
|
753 | + public function batch_items($request) { |
|
754 | + $items = array_filter($request->get_params()); |
|
755 | 755 | $params = $request->get_url_params(); |
756 | 756 | $product_id = $params['product_id']; |
757 | 757 | $body_params = array(); |
758 | 758 | |
759 | - foreach ( array( 'update', 'create', 'delete' ) as $batch_type ) { |
|
760 | - if ( ! empty( $items[ $batch_type ] ) ) { |
|
759 | + foreach (array('update', 'create', 'delete') as $batch_type) { |
|
760 | + if ( ! empty($items[$batch_type])) { |
|
761 | 761 | $injected_items = array(); |
762 | - foreach ( $items[ $batch_type ] as $item ) { |
|
763 | - $injected_items[] = is_array( $item ) ? array_merge( |
|
762 | + foreach ($items[$batch_type] as $item) { |
|
763 | + $injected_items[] = is_array($item) ? array_merge( |
|
764 | 764 | array( |
765 | 765 | 'product_id' => $product_id, |
766 | 766 | ), $item |
767 | 767 | ) : $item; |
768 | 768 | } |
769 | - $body_params[ $batch_type ] = $injected_items; |
|
769 | + $body_params[$batch_type] = $injected_items; |
|
770 | 770 | } |
771 | 771 | } |
772 | 772 | |
773 | - $request = new \WP_REST_Request( $request->get_method() ); |
|
774 | - $request->set_body_params( $body_params ); |
|
773 | + $request = new \WP_REST_Request($request->get_method()); |
|
774 | + $request->set_body_params($body_params); |
|
775 | 775 | |
776 | - return parent::batch_items( $request ); |
|
776 | + return parent::batch_items($request); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | /** |
@@ -783,18 +783,18 @@ discard block |
||
783 | 783 | * @param \WP_REST_Request $request Request object. |
784 | 784 | * @return array Links for the given post. |
785 | 785 | */ |
786 | - protected function prepare_links( $object, $request ) { |
|
786 | + protected function prepare_links($object, $request) { |
|
787 | 787 | $product_id = (int) $request['product_id']; |
788 | - $base = str_replace( '(?P<product_id>[\d]+)', $product_id, $this->rest_base ); |
|
788 | + $base = str_replace('(?P<product_id>[\d]+)', $product_id, $this->rest_base); |
|
789 | 789 | $links = array( |
790 | 790 | 'self' => array( |
791 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $object->get_id() ) ), |
|
791 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $object->get_id())), |
|
792 | 792 | ), |
793 | 793 | 'collection' => array( |
794 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
794 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
795 | 795 | ), |
796 | 796 | 'up' => array( |
797 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product_id ) ), |
|
797 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product_id)), |
|
798 | 798 | ), |
799 | 799 | ); |
800 | 800 | return $links; |
@@ -806,371 +806,371 @@ discard block |
||
806 | 806 | * @return array |
807 | 807 | */ |
808 | 808 | public function get_item_schema() { |
809 | - $weight_unit = get_option( 'woocommerce_weight_unit' ); |
|
810 | - $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
|
809 | + $weight_unit = get_option('woocommerce_weight_unit'); |
|
810 | + $dimension_unit = get_option('woocommerce_dimension_unit'); |
|
811 | 811 | $schema = array( |
812 | 812 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
813 | 813 | 'title' => $this->post_type, |
814 | 814 | 'type' => 'object', |
815 | 815 | 'properties' => array( |
816 | 816 | 'id' => array( |
817 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
817 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
818 | 818 | 'type' => 'integer', |
819 | - 'context' => array( 'view', 'edit' ), |
|
819 | + 'context' => array('view', 'edit'), |
|
820 | 820 | 'readonly' => true, |
821 | 821 | ), |
822 | 822 | 'name' => array( |
823 | - 'description' => __( 'Product parent name.', 'woocommerce' ), |
|
823 | + 'description' => __('Product parent name.', 'woocommerce'), |
|
824 | 824 | 'type' => 'string', |
825 | - 'context' => array( 'view', 'edit' ), |
|
825 | + 'context' => array('view', 'edit'), |
|
826 | 826 | ), |
827 | 827 | 'type' => array( |
828 | - 'description' => __( 'Product type.', 'woocommerce' ), |
|
828 | + 'description' => __('Product type.', 'woocommerce'), |
|
829 | 829 | 'type' => 'string', |
830 | 830 | 'default' => 'variation', |
831 | - 'enum' => array( 'variation' ), |
|
832 | - 'context' => array( 'view', 'edit' ), |
|
831 | + 'enum' => array('variation'), |
|
832 | + 'context' => array('view', 'edit'), |
|
833 | 833 | ), |
834 | 834 | 'parent_id' => array( |
835 | - 'description' => __( 'Product parent ID.', 'woocommerce' ), |
|
835 | + 'description' => __('Product parent ID.', 'woocommerce'), |
|
836 | 836 | 'type' => 'integer', |
837 | - 'context' => array( 'view', 'edit' ), |
|
837 | + 'context' => array('view', 'edit'), |
|
838 | 838 | ), |
839 | 839 | 'date_created' => array( |
840 | - 'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ), |
|
840 | + 'description' => __("The date the variation was created, in the site's timezone.", 'woocommerce'), |
|
841 | 841 | 'type' => 'date-time', |
842 | - 'context' => array( 'view', 'edit' ), |
|
842 | + 'context' => array('view', 'edit'), |
|
843 | 843 | 'readonly' => true, |
844 | 844 | ), |
845 | 845 | 'date_modified' => array( |
846 | - 'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ), |
|
846 | + 'description' => __("The date the variation was last modified, in the site's timezone.", 'woocommerce'), |
|
847 | 847 | 'type' => 'date-time', |
848 | - 'context' => array( 'view', 'edit' ), |
|
848 | + 'context' => array('view', 'edit'), |
|
849 | 849 | 'readonly' => true, |
850 | 850 | ), |
851 | 851 | 'description' => array( |
852 | - 'description' => __( 'Variation description.', 'woocommerce' ), |
|
852 | + 'description' => __('Variation description.', 'woocommerce'), |
|
853 | 853 | 'type' => 'string', |
854 | - 'context' => array( 'view', 'edit' ), |
|
854 | + 'context' => array('view', 'edit'), |
|
855 | 855 | ), |
856 | 856 | 'permalink' => array( |
857 | - 'description' => __( 'Variation URL.', 'woocommerce' ), |
|
857 | + 'description' => __('Variation URL.', 'woocommerce'), |
|
858 | 858 | 'type' => 'string', |
859 | 859 | 'format' => 'uri', |
860 | - 'context' => array( 'view', 'edit' ), |
|
860 | + 'context' => array('view', 'edit'), |
|
861 | 861 | 'readonly' => true, |
862 | 862 | ), |
863 | 863 | 'sku' => array( |
864 | - 'description' => __( 'Unique identifier.', 'woocommerce' ), |
|
864 | + 'description' => __('Unique identifier.', 'woocommerce'), |
|
865 | 865 | 'type' => 'string', |
866 | - 'context' => array( 'view', 'edit' ), |
|
866 | + 'context' => array('view', 'edit'), |
|
867 | 867 | ), |
868 | 868 | 'price' => array( |
869 | - 'description' => __( 'Current variation price.', 'woocommerce' ), |
|
869 | + 'description' => __('Current variation price.', 'woocommerce'), |
|
870 | 870 | 'type' => 'string', |
871 | - 'context' => array( 'view', 'edit' ), |
|
871 | + 'context' => array('view', 'edit'), |
|
872 | 872 | 'readonly' => true, |
873 | 873 | ), |
874 | 874 | 'regular_price' => array( |
875 | - 'description' => __( 'Variation regular price.', 'woocommerce' ), |
|
875 | + 'description' => __('Variation regular price.', 'woocommerce'), |
|
876 | 876 | 'type' => 'string', |
877 | - 'context' => array( 'view', 'edit' ), |
|
877 | + 'context' => array('view', 'edit'), |
|
878 | 878 | ), |
879 | 879 | 'sale_price' => array( |
880 | - 'description' => __( 'Variation sale price.', 'woocommerce' ), |
|
880 | + 'description' => __('Variation sale price.', 'woocommerce'), |
|
881 | 881 | 'type' => 'string', |
882 | - 'context' => array( 'view', 'edit' ), |
|
882 | + 'context' => array('view', 'edit'), |
|
883 | 883 | ), |
884 | 884 | 'date_on_sale_from' => array( |
885 | - 'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ), |
|
885 | + 'description' => __("Start date of sale price, in the site's timezone.", 'woocommerce'), |
|
886 | 886 | 'type' => 'date-time', |
887 | - 'context' => array( 'view', 'edit' ), |
|
887 | + 'context' => array('view', 'edit'), |
|
888 | 888 | ), |
889 | 889 | 'date_on_sale_from_gmt' => array( |
890 | - 'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ), |
|
890 | + 'description' => __('Start date of sale price, as GMT.', 'woocommerce'), |
|
891 | 891 | 'type' => 'date-time', |
892 | - 'context' => array( 'view', 'edit' ), |
|
892 | + 'context' => array('view', 'edit'), |
|
893 | 893 | ), |
894 | 894 | 'date_on_sale_to' => array( |
895 | - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
|
895 | + 'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'), |
|
896 | 896 | 'type' => 'date-time', |
897 | - 'context' => array( 'view', 'edit' ), |
|
897 | + 'context' => array('view', 'edit'), |
|
898 | 898 | ), |
899 | 899 | 'date_on_sale_to_gmt' => array( |
900 | - 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
|
900 | + 'description' => __("End date of sale price, in the site's timezone.", 'woocommerce'), |
|
901 | 901 | 'type' => 'date-time', |
902 | - 'context' => array( 'view', 'edit' ), |
|
902 | + 'context' => array('view', 'edit'), |
|
903 | 903 | ), |
904 | 904 | 'on_sale' => array( |
905 | - 'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ), |
|
905 | + 'description' => __('Shows if the variation is on sale.', 'woocommerce'), |
|
906 | 906 | 'type' => 'boolean', |
907 | - 'context' => array( 'view', 'edit' ), |
|
907 | + 'context' => array('view', 'edit'), |
|
908 | 908 | 'readonly' => true, |
909 | 909 | ), |
910 | 910 | 'status' => array( |
911 | - 'description' => __( 'Variation status.', 'woocommerce' ), |
|
911 | + 'description' => __('Variation status.', 'woocommerce'), |
|
912 | 912 | 'type' => 'string', |
913 | 913 | 'default' => 'publish', |
914 | - 'enum' => array_keys( get_post_statuses() ), |
|
915 | - 'context' => array( 'view', 'edit' ), |
|
914 | + 'enum' => array_keys(get_post_statuses()), |
|
915 | + 'context' => array('view', 'edit'), |
|
916 | 916 | ), |
917 | 917 | 'purchasable' => array( |
918 | - 'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ), |
|
918 | + 'description' => __('Shows if the variation can be bought.', 'woocommerce'), |
|
919 | 919 | 'type' => 'boolean', |
920 | - 'context' => array( 'view', 'edit' ), |
|
920 | + 'context' => array('view', 'edit'), |
|
921 | 921 | 'readonly' => true, |
922 | 922 | ), |
923 | 923 | 'virtual' => array( |
924 | - 'description' => __( 'If the variation is virtual.', 'woocommerce' ), |
|
924 | + 'description' => __('If the variation is virtual.', 'woocommerce'), |
|
925 | 925 | 'type' => 'boolean', |
926 | 926 | 'default' => false, |
927 | - 'context' => array( 'view', 'edit' ), |
|
927 | + 'context' => array('view', 'edit'), |
|
928 | 928 | ), |
929 | 929 | 'downloadable' => array( |
930 | - 'description' => __( 'If the variation is downloadable.', 'woocommerce' ), |
|
930 | + 'description' => __('If the variation is downloadable.', 'woocommerce'), |
|
931 | 931 | 'type' => 'boolean', |
932 | 932 | 'default' => false, |
933 | - 'context' => array( 'view', 'edit' ), |
|
933 | + 'context' => array('view', 'edit'), |
|
934 | 934 | ), |
935 | 935 | 'downloads' => array( |
936 | - 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
|
936 | + 'description' => __('List of downloadable files.', 'woocommerce'), |
|
937 | 937 | 'type' => 'array', |
938 | - 'context' => array( 'view', 'edit' ), |
|
938 | + 'context' => array('view', 'edit'), |
|
939 | 939 | 'items' => array( |
940 | 940 | 'type' => 'object', |
941 | 941 | 'properties' => array( |
942 | 942 | 'id' => array( |
943 | - 'description' => __( 'File ID.', 'woocommerce' ), |
|
943 | + 'description' => __('File ID.', 'woocommerce'), |
|
944 | 944 | 'type' => 'string', |
945 | - 'context' => array( 'view', 'edit' ), |
|
945 | + 'context' => array('view', 'edit'), |
|
946 | 946 | ), |
947 | 947 | 'name' => array( |
948 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
948 | + 'description' => __('File name.', 'woocommerce'), |
|
949 | 949 | 'type' => 'string', |
950 | - 'context' => array( 'view', 'edit' ), |
|
950 | + 'context' => array('view', 'edit'), |
|
951 | 951 | ), |
952 | 952 | 'file' => array( |
953 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
953 | + 'description' => __('File URL.', 'woocommerce'), |
|
954 | 954 | 'type' => 'string', |
955 | - 'context' => array( 'view', 'edit' ), |
|
955 | + 'context' => array('view', 'edit'), |
|
956 | 956 | ), |
957 | 957 | ), |
958 | 958 | ), |
959 | 959 | ), |
960 | 960 | 'download_limit' => array( |
961 | - 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
|
961 | + 'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'), |
|
962 | 962 | 'type' => 'integer', |
963 | 963 | 'default' => -1, |
964 | - 'context' => array( 'view', 'edit' ), |
|
964 | + 'context' => array('view', 'edit'), |
|
965 | 965 | ), |
966 | 966 | 'download_expiry' => array( |
967 | - 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
|
967 | + 'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'), |
|
968 | 968 | 'type' => 'integer', |
969 | 969 | 'default' => -1, |
970 | - 'context' => array( 'view', 'edit' ), |
|
970 | + 'context' => array('view', 'edit'), |
|
971 | 971 | ), |
972 | 972 | 'tax_status' => array( |
973 | - 'description' => __( 'Tax status.', 'woocommerce' ), |
|
973 | + 'description' => __('Tax status.', 'woocommerce'), |
|
974 | 974 | 'type' => 'string', |
975 | 975 | 'default' => 'taxable', |
976 | - 'enum' => array( 'taxable', 'shipping', 'none' ), |
|
977 | - 'context' => array( 'view', 'edit' ), |
|
976 | + 'enum' => array('taxable', 'shipping', 'none'), |
|
977 | + 'context' => array('view', 'edit'), |
|
978 | 978 | ), |
979 | 979 | 'tax_class' => array( |
980 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
980 | + 'description' => __('Tax class.', 'woocommerce'), |
|
981 | 981 | 'type' => 'string', |
982 | - 'context' => array( 'view', 'edit' ), |
|
982 | + 'context' => array('view', 'edit'), |
|
983 | 983 | ), |
984 | 984 | 'manage_stock' => array( |
985 | - 'description' => __( 'Stock management at variation level.', 'woocommerce' ), |
|
985 | + 'description' => __('Stock management at variation level.', 'woocommerce'), |
|
986 | 986 | 'type' => 'boolean', |
987 | 987 | 'default' => false, |
988 | - 'context' => array( 'view', 'edit' ), |
|
988 | + 'context' => array('view', 'edit'), |
|
989 | 989 | ), |
990 | 990 | 'stock_quantity' => array( |
991 | - 'description' => __( 'Stock quantity.', 'woocommerce' ), |
|
991 | + 'description' => __('Stock quantity.', 'woocommerce'), |
|
992 | 992 | 'type' => 'integer', |
993 | - 'context' => array( 'view', 'edit' ), |
|
993 | + 'context' => array('view', 'edit'), |
|
994 | 994 | ), |
995 | 995 | 'stock_status' => array( |
996 | - 'description' => __( 'Controls the stock status of the product.', 'woocommerce' ), |
|
996 | + 'description' => __('Controls the stock status of the product.', 'woocommerce'), |
|
997 | 997 | 'type' => 'string', |
998 | 998 | 'default' => 'instock', |
999 | - 'enum' => array_keys( wc_get_product_stock_status_options() ), |
|
1000 | - 'context' => array( 'view', 'edit' ), |
|
999 | + 'enum' => array_keys(wc_get_product_stock_status_options()), |
|
1000 | + 'context' => array('view', 'edit'), |
|
1001 | 1001 | ), |
1002 | 1002 | 'backorders' => array( |
1003 | - 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
|
1003 | + 'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'), |
|
1004 | 1004 | 'type' => 'string', |
1005 | 1005 | 'default' => 'no', |
1006 | - 'enum' => array( 'no', 'notify', 'yes' ), |
|
1007 | - 'context' => array( 'view', 'edit' ), |
|
1006 | + 'enum' => array('no', 'notify', 'yes'), |
|
1007 | + 'context' => array('view', 'edit'), |
|
1008 | 1008 | ), |
1009 | 1009 | 'backorders_allowed' => array( |
1010 | - 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
|
1010 | + 'description' => __('Shows if backorders are allowed.', 'woocommerce'), |
|
1011 | 1011 | 'type' => 'boolean', |
1012 | - 'context' => array( 'view', 'edit' ), |
|
1012 | + 'context' => array('view', 'edit'), |
|
1013 | 1013 | 'readonly' => true, |
1014 | 1014 | ), |
1015 | 1015 | 'backordered' => array( |
1016 | - 'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ), |
|
1016 | + 'description' => __('Shows if the variation is on backordered.', 'woocommerce'), |
|
1017 | 1017 | 'type' => 'boolean', |
1018 | - 'context' => array( 'view', 'edit' ), |
|
1018 | + 'context' => array('view', 'edit'), |
|
1019 | 1019 | 'readonly' => true, |
1020 | 1020 | ), |
1021 | 1021 | 'weight' => array( |
1022 | 1022 | /* translators: %s: weight unit */ |
1023 | - 'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ), |
|
1023 | + 'description' => sprintf(__('Variation weight (%s).', 'woocommerce'), $weight_unit), |
|
1024 | 1024 | 'type' => 'string', |
1025 | - 'context' => array( 'view', 'edit' ), |
|
1025 | + 'context' => array('view', 'edit'), |
|
1026 | 1026 | ), |
1027 | 1027 | 'dimensions' => array( |
1028 | - 'description' => __( 'Variation dimensions.', 'woocommerce' ), |
|
1028 | + 'description' => __('Variation dimensions.', 'woocommerce'), |
|
1029 | 1029 | 'type' => 'object', |
1030 | - 'context' => array( 'view', 'edit' ), |
|
1030 | + 'context' => array('view', 'edit'), |
|
1031 | 1031 | 'properties' => array( |
1032 | 1032 | 'length' => array( |
1033 | 1033 | /* translators: %s: dimension unit */ |
1034 | - 'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ), |
|
1034 | + 'description' => sprintf(__('Variation length (%s).', 'woocommerce'), $dimension_unit), |
|
1035 | 1035 | 'type' => 'string', |
1036 | - 'context' => array( 'view', 'edit' ), |
|
1036 | + 'context' => array('view', 'edit'), |
|
1037 | 1037 | ), |
1038 | 1038 | 'width' => array( |
1039 | 1039 | /* translators: %s: dimension unit */ |
1040 | - 'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ), |
|
1040 | + 'description' => sprintf(__('Variation width (%s).', 'woocommerce'), $dimension_unit), |
|
1041 | 1041 | 'type' => 'string', |
1042 | - 'context' => array( 'view', 'edit' ), |
|
1042 | + 'context' => array('view', 'edit'), |
|
1043 | 1043 | ), |
1044 | 1044 | 'height' => array( |
1045 | 1045 | /* translators: %s: dimension unit */ |
1046 | - 'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ), |
|
1046 | + 'description' => sprintf(__('Variation height (%s).', 'woocommerce'), $dimension_unit), |
|
1047 | 1047 | 'type' => 'string', |
1048 | - 'context' => array( 'view', 'edit' ), |
|
1048 | + 'context' => array('view', 'edit'), |
|
1049 | 1049 | ), |
1050 | 1050 | ), |
1051 | 1051 | ), |
1052 | 1052 | 'shipping_class' => array( |
1053 | - 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
|
1053 | + 'description' => __('Shipping class slug.', 'woocommerce'), |
|
1054 | 1054 | 'type' => 'string', |
1055 | - 'context' => array( 'view', 'edit' ), |
|
1055 | + 'context' => array('view', 'edit'), |
|
1056 | 1056 | ), |
1057 | 1057 | 'shipping_class_id' => array( |
1058 | - 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
|
1058 | + 'description' => __('Shipping class ID.', 'woocommerce'), |
|
1059 | 1059 | 'type' => 'string', |
1060 | - 'context' => array( 'view', 'edit' ), |
|
1060 | + 'context' => array('view', 'edit'), |
|
1061 | 1061 | 'readonly' => true, |
1062 | 1062 | ), |
1063 | 1063 | 'image' => array( |
1064 | - 'description' => __( 'Variation image data.', 'woocommerce' ), |
|
1064 | + 'description' => __('Variation image data.', 'woocommerce'), |
|
1065 | 1065 | 'type' => 'object', |
1066 | - 'context' => array( 'view', 'edit' ), |
|
1066 | + 'context' => array('view', 'edit'), |
|
1067 | 1067 | 'properties' => array( |
1068 | 1068 | 'id' => array( |
1069 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
1069 | + 'description' => __('Image ID.', 'woocommerce'), |
|
1070 | 1070 | 'type' => 'integer', |
1071 | - 'context' => array( 'view', 'edit' ), |
|
1071 | + 'context' => array('view', 'edit'), |
|
1072 | 1072 | ), |
1073 | 1073 | 'date_created' => array( |
1074 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
1074 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
1075 | 1075 | 'type' => 'date-time', |
1076 | - 'context' => array( 'view', 'edit' ), |
|
1076 | + 'context' => array('view', 'edit'), |
|
1077 | 1077 | 'readonly' => true, |
1078 | 1078 | ), |
1079 | 1079 | 'date_created_gmt' => array( |
1080 | - 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
|
1080 | + 'description' => __('The date the image was created, as GMT.', 'woocommerce'), |
|
1081 | 1081 | 'type' => 'date-time', |
1082 | - 'context' => array( 'view', 'edit' ), |
|
1082 | + 'context' => array('view', 'edit'), |
|
1083 | 1083 | 'readonly' => true, |
1084 | 1084 | ), |
1085 | 1085 | 'date_modified' => array( |
1086 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
1086 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
1087 | 1087 | 'type' => 'date-time', |
1088 | - 'context' => array( 'view', 'edit' ), |
|
1088 | + 'context' => array('view', 'edit'), |
|
1089 | 1089 | 'readonly' => true, |
1090 | 1090 | ), |
1091 | 1091 | 'date_modified_gmt' => array( |
1092 | - 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
|
1092 | + 'description' => __('The date the image was last modified, as GMT.', 'woocommerce'), |
|
1093 | 1093 | 'type' => 'date-time', |
1094 | - 'context' => array( 'view', 'edit' ), |
|
1094 | + 'context' => array('view', 'edit'), |
|
1095 | 1095 | 'readonly' => true, |
1096 | 1096 | ), |
1097 | 1097 | 'src' => array( |
1098 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
1098 | + 'description' => __('Image URL.', 'woocommerce'), |
|
1099 | 1099 | 'type' => 'string', |
1100 | 1100 | 'format' => 'uri', |
1101 | - 'context' => array( 'view', 'edit' ), |
|
1101 | + 'context' => array('view', 'edit'), |
|
1102 | 1102 | ), |
1103 | 1103 | 'name' => array( |
1104 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
1104 | + 'description' => __('Image name.', 'woocommerce'), |
|
1105 | 1105 | 'type' => 'string', |
1106 | - 'context' => array( 'view', 'edit' ), |
|
1106 | + 'context' => array('view', 'edit'), |
|
1107 | 1107 | ), |
1108 | 1108 | 'alt' => array( |
1109 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
1109 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
1110 | 1110 | 'type' => 'string', |
1111 | - 'context' => array( 'view', 'edit' ), |
|
1111 | + 'context' => array('view', 'edit'), |
|
1112 | 1112 | ), |
1113 | 1113 | ), |
1114 | 1114 | ), |
1115 | 1115 | 'attributes' => array( |
1116 | - 'description' => __( 'List of attributes.', 'woocommerce' ), |
|
1116 | + 'description' => __('List of attributes.', 'woocommerce'), |
|
1117 | 1117 | 'type' => 'array', |
1118 | - 'context' => array( 'view', 'edit' ), |
|
1118 | + 'context' => array('view', 'edit'), |
|
1119 | 1119 | 'items' => array( |
1120 | 1120 | 'type' => 'object', |
1121 | 1121 | 'properties' => array( |
1122 | 1122 | 'id' => array( |
1123 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
1123 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
1124 | 1124 | 'type' => 'integer', |
1125 | - 'context' => array( 'view', 'edit' ), |
|
1125 | + 'context' => array('view', 'edit'), |
|
1126 | 1126 | ), |
1127 | 1127 | 'name' => array( |
1128 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
1128 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
1129 | 1129 | 'type' => 'string', |
1130 | - 'context' => array( 'view', 'edit' ), |
|
1130 | + 'context' => array('view', 'edit'), |
|
1131 | 1131 | ), |
1132 | 1132 | 'option' => array( |
1133 | - 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
|
1133 | + 'description' => __('Selected attribute term name.', 'woocommerce'), |
|
1134 | 1134 | 'type' => 'string', |
1135 | - 'context' => array( 'view', 'edit' ), |
|
1135 | + 'context' => array('view', 'edit'), |
|
1136 | 1136 | ), |
1137 | 1137 | ), |
1138 | 1138 | ), |
1139 | 1139 | ), |
1140 | 1140 | 'menu_order' => array( |
1141 | - 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), |
|
1141 | + 'description' => __('Menu order, used to custom sort products.', 'woocommerce'), |
|
1142 | 1142 | 'type' => 'integer', |
1143 | - 'context' => array( 'view', 'edit' ), |
|
1143 | + 'context' => array('view', 'edit'), |
|
1144 | 1144 | ), |
1145 | 1145 | 'meta_data' => array( |
1146 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
1146 | + 'description' => __('Meta data.', 'woocommerce'), |
|
1147 | 1147 | 'type' => 'array', |
1148 | - 'context' => array( 'view', 'edit' ), |
|
1148 | + 'context' => array('view', 'edit'), |
|
1149 | 1149 | 'items' => array( |
1150 | 1150 | 'type' => 'object', |
1151 | 1151 | 'properties' => array( |
1152 | 1152 | 'id' => array( |
1153 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
1153 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
1154 | 1154 | 'type' => 'integer', |
1155 | - 'context' => array( 'view', 'edit' ), |
|
1155 | + 'context' => array('view', 'edit'), |
|
1156 | 1156 | 'readonly' => true, |
1157 | 1157 | ), |
1158 | 1158 | 'key' => array( |
1159 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
1159 | + 'description' => __('Meta key.', 'woocommerce'), |
|
1160 | 1160 | 'type' => 'string', |
1161 | - 'context' => array( 'view', 'edit' ), |
|
1161 | + 'context' => array('view', 'edit'), |
|
1162 | 1162 | ), |
1163 | 1163 | 'value' => array( |
1164 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
1164 | + 'description' => __('Meta value.', 'woocommerce'), |
|
1165 | 1165 | 'type' => 'mixed', |
1166 | - 'context' => array( 'view', 'edit' ), |
|
1166 | + 'context' => array('view', 'edit'), |
|
1167 | 1167 | ), |
1168 | 1168 | ), |
1169 | 1169 | ), |
1170 | 1170 | ), |
1171 | 1171 | ), |
1172 | 1172 | ); |
1173 | - return $this->add_additional_fields_schema( $schema ); |
|
1173 | + return $this->add_additional_fields_schema($schema); |
|
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | /** |
@@ -1193,15 +1193,15 @@ discard block |
||
1193 | 1193 | ); |
1194 | 1194 | |
1195 | 1195 | $params['stock_status'] = array( |
1196 | - 'description' => __( 'Limit result set to products with specified stock status.', 'woocommerce' ), |
|
1196 | + 'description' => __('Limit result set to products with specified stock status.', 'woocommerce'), |
|
1197 | 1197 | 'type' => 'string', |
1198 | - 'enum' => array_keys( wc_get_product_stock_status_options() ), |
|
1198 | + 'enum' => array_keys(wc_get_product_stock_status_options()), |
|
1199 | 1199 | 'sanitize_callback' => 'sanitize_text_field', |
1200 | 1200 | 'validate_callback' => 'rest_validate_request_arg', |
1201 | 1201 | ); |
1202 | 1202 | |
1203 | 1203 | $params['search'] = array( |
1204 | - 'description' => __( 'Search by similar product name or sku.', 'woocommerce' ), |
|
1204 | + 'description' => __('Search by similar product name or sku.', 'woocommerce'), |
|
1205 | 1205 | 'type' => 'string', |
1206 | 1206 | 'validate_callback' => 'rest_validate_request_arg', |
1207 | 1207 | ); |
@@ -1215,14 +1215,14 @@ discard block |
||
1215 | 1215 | * @param \WP_REST_Request $request Full details about the request. |
1216 | 1216 | * @return \WP_Error\WP_REST_Response |
1217 | 1217 | */ |
1218 | - public function get_items( $request ) { |
|
1219 | - add_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10, 2 ); |
|
1220 | - add_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10, 2 ); |
|
1221 | - add_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10, 2 ); |
|
1222 | - $response = parent::get_items( $request ); |
|
1223 | - remove_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10 ); |
|
1224 | - remove_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10 ); |
|
1225 | - remove_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10 ); |
|
1218 | + public function get_items($request) { |
|
1219 | + add_filter('posts_where', array(__CLASS__, 'add_wp_query_filter'), 10, 2); |
|
1220 | + add_filter('posts_join', array(__CLASS__, 'add_wp_query_join'), 10, 2); |
|
1221 | + add_filter('posts_groupby', array(__CLASS__, 'add_wp_query_group_by'), 10, 2); |
|
1222 | + $response = parent::get_items($request); |
|
1223 | + remove_filter('posts_where', array(__CLASS__, 'add_wp_query_filter'), 10); |
|
1224 | + remove_filter('posts_join', array(__CLASS__, 'add_wp_query_join'), 10); |
|
1225 | + remove_filter('posts_groupby', array(__CLASS__, 'add_wp_query_group_by'), 10); |
|
1226 | 1226 | return $response; |
1227 | 1227 | } |
1228 | 1228 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Customer Downloads controller class. |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | array( |
34 | 34 | 'args' => array( |
35 | 35 | 'customer_id' => array( |
36 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
36 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
37 | 37 | 'type' => 'integer', |
38 | 38 | ), |
39 | 39 | ), |
40 | 40 | array( |
41 | 41 | 'methods' => \WP_REST_Server::READABLE, |
42 | - 'callback' => array( $this, 'get_items' ), |
|
43 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
42 | + 'callback' => array($this, 'get_items'), |
|
43 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
44 | 44 | 'args' => $this->get_collection_params(), |
45 | 45 | ), |
46 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
46 | + 'schema' => array($this, 'get_public_item_schema'), |
|
47 | 47 | ), |
48 | 48 | true |
49 | 49 | ); |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | * @param \WP_REST_Request $request Full details about the request. |
56 | 56 | * @return \WP_Error|boolean |
57 | 57 | */ |
58 | - public function get_items_permissions_check( $request ) { |
|
59 | - $customer = get_user_by( 'id', (int) $request['customer_id'] ); |
|
58 | + public function get_items_permissions_check($request) { |
|
59 | + $customer = get_user_by('id', (int) $request['customer_id']); |
|
60 | 60 | |
61 | - if ( ! $customer ) { |
|
62 | - return new \WP_Error( 'woocommerce_rest_customer_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
61 | + if ( ! $customer) { |
|
62 | + return new \WP_Error('woocommerce_rest_customer_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
63 | 63 | } |
64 | 64 | |
65 | - if ( ! wc_rest_check_user_permissions( 'read', $customer->get_id() ) ) { |
|
66 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
65 | + if ( ! wc_rest_check_user_permissions('read', $customer->get_id())) { |
|
66 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | return true; |
@@ -75,17 +75,17 @@ discard block |
||
75 | 75 | * @param \WP_REST_Request $request Request params. |
76 | 76 | * @return array |
77 | 77 | */ |
78 | - public function get_items( $request ) { |
|
79 | - $downloads = wc_get_customer_available_downloads( (int) $request['customer_id'] ); |
|
78 | + public function get_items($request) { |
|
79 | + $downloads = wc_get_customer_available_downloads((int) $request['customer_id']); |
|
80 | 80 | |
81 | 81 | $data = array(); |
82 | - foreach ( $downloads as $download_data ) { |
|
83 | - $download = $this->prepare_item_for_response( (object) $download_data, $request ); |
|
84 | - $download = $this->prepare_response_for_collection( $download ); |
|
82 | + foreach ($downloads as $download_data) { |
|
83 | + $download = $this->prepare_item_for_response((object) $download_data, $request); |
|
84 | + $download = $this->prepare_response_for_collection($download); |
|
85 | 85 | $data[] = $download; |
86 | 86 | } |
87 | 87 | |
88 | - return rest_ensure_response( $data ); |
|
88 | + return rest_ensure_response($data); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param \WP_REST_Request $request Request object. |
96 | 96 | * @return \WP_REST_Response $response Response data. |
97 | 97 | */ |
98 | - public function prepare_item_for_response( $download, $request ) { |
|
98 | + public function prepare_item_for_response($download, $request) { |
|
99 | 99 | $data = array( |
100 | 100 | 'download_id' => $download->download_id, |
101 | 101 | 'download_url' => $download->download_url, |
@@ -105,19 +105,19 @@ discard block |
||
105 | 105 | 'order_id' => $download->order_id, |
106 | 106 | 'order_key' => $download->order_key, |
107 | 107 | 'downloads_remaining' => '' === $download->downloads_remaining ? 'unlimited' : $download->downloads_remaining, |
108 | - 'access_expires' => $download->access_expires ? wc_rest_prepare_date_response( $download->access_expires ) : 'never', |
|
109 | - 'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response( get_gmt_from_date( $download->access_expires ) ) : 'never', |
|
108 | + 'access_expires' => $download->access_expires ? wc_rest_prepare_date_response($download->access_expires) : 'never', |
|
109 | + 'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response(get_gmt_from_date($download->access_expires)) : 'never', |
|
110 | 110 | 'file' => $download->file, |
111 | 111 | ); |
112 | 112 | |
113 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
114 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
115 | - $data = $this->filter_response_by_context( $data, $context ); |
|
113 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
114 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
115 | + $data = $this->filter_response_by_context($data, $context); |
|
116 | 116 | |
117 | 117 | // Wrap the data in a response object. |
118 | - $response = rest_ensure_response( $data ); |
|
118 | + $response = rest_ensure_response($data); |
|
119 | 119 | |
120 | - $response->add_links( $this->prepare_links( $download, $request ) ); |
|
120 | + $response->add_links($this->prepare_links($download, $request)); |
|
121 | 121 | |
122 | 122 | /** |
123 | 123 | * Filter customer download data returned from the REST API. |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param stdClass $download Download object used to create response. |
127 | 127 | * @param \WP_REST_Request $request Request object. |
128 | 128 | */ |
129 | - return apply_filters( 'woocommerce_rest_prepare_customer_download', $response, $download, $request ); |
|
129 | + return apply_filters('woocommerce_rest_prepare_customer_download', $response, $download, $request); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -136,17 +136,17 @@ discard block |
||
136 | 136 | * @param \WP_REST_Request $request Request object. |
137 | 137 | * @return array Links for the given customer download. |
138 | 138 | */ |
139 | - protected function prepare_links( $download, $request ) { |
|
140 | - $base = str_replace( '(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base ); |
|
139 | + protected function prepare_links($download, $request) { |
|
140 | + $base = str_replace('(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base); |
|
141 | 141 | $links = array( |
142 | 142 | 'collection' => array( |
143 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
143 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
144 | 144 | ), |
145 | 145 | 'product' => array( |
146 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $download->product_id ) ), |
|
146 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $download->product_id)), |
|
147 | 147 | ), |
148 | 148 | 'order' => array( |
149 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $download->order_id ) ), |
|
149 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $download->order_id)), |
|
150 | 150 | ), |
151 | 151 | ); |
152 | 152 | |
@@ -165,81 +165,81 @@ discard block |
||
165 | 165 | 'type' => 'object', |
166 | 166 | 'properties' => array( |
167 | 167 | 'download_id' => array( |
168 | - 'description' => __( 'Download ID.', 'woocommerce' ), |
|
168 | + 'description' => __('Download ID.', 'woocommerce'), |
|
169 | 169 | 'type' => 'string', |
170 | - 'context' => array( 'view' ), |
|
170 | + 'context' => array('view'), |
|
171 | 171 | 'readonly' => true, |
172 | 172 | ), |
173 | 173 | 'download_url' => array( |
174 | - 'description' => __( 'Download file URL.', 'woocommerce' ), |
|
174 | + 'description' => __('Download file URL.', 'woocommerce'), |
|
175 | 175 | 'type' => 'string', |
176 | - 'context' => array( 'view' ), |
|
176 | + 'context' => array('view'), |
|
177 | 177 | 'readonly' => true, |
178 | 178 | ), |
179 | 179 | 'product_id' => array( |
180 | - 'description' => __( 'Downloadable product ID.', 'woocommerce' ), |
|
180 | + 'description' => __('Downloadable product ID.', 'woocommerce'), |
|
181 | 181 | 'type' => 'integer', |
182 | - 'context' => array( 'view' ), |
|
182 | + 'context' => array('view'), |
|
183 | 183 | 'readonly' => true, |
184 | 184 | ), |
185 | 185 | 'product_name' => array( |
186 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
186 | + 'description' => __('Product name.', 'woocommerce'), |
|
187 | 187 | 'type' => 'string', |
188 | - 'context' => array( 'view' ), |
|
188 | + 'context' => array('view'), |
|
189 | 189 | 'readonly' => true, |
190 | 190 | ), |
191 | 191 | 'download_name' => array( |
192 | - 'description' => __( 'Downloadable file name.', 'woocommerce' ), |
|
192 | + 'description' => __('Downloadable file name.', 'woocommerce'), |
|
193 | 193 | 'type' => 'string', |
194 | - 'context' => array( 'view' ), |
|
194 | + 'context' => array('view'), |
|
195 | 195 | 'readonly' => true, |
196 | 196 | ), |
197 | 197 | 'order_id' => array( |
198 | - 'description' => __( 'Order ID.', 'woocommerce' ), |
|
198 | + 'description' => __('Order ID.', 'woocommerce'), |
|
199 | 199 | 'type' => 'integer', |
200 | - 'context' => array( 'view' ), |
|
200 | + 'context' => array('view'), |
|
201 | 201 | 'readonly' => true, |
202 | 202 | ), |
203 | 203 | 'order_key' => array( |
204 | - 'description' => __( 'Order key.', 'woocommerce' ), |
|
204 | + 'description' => __('Order key.', 'woocommerce'), |
|
205 | 205 | 'type' => 'string', |
206 | - 'context' => array( 'view' ), |
|
206 | + 'context' => array('view'), |
|
207 | 207 | 'readonly' => true, |
208 | 208 | ), |
209 | 209 | 'downloads_remaining' => array( |
210 | - 'description' => __( 'Number of downloads remaining.', 'woocommerce' ), |
|
210 | + 'description' => __('Number of downloads remaining.', 'woocommerce'), |
|
211 | 211 | 'type' => 'string', |
212 | - 'context' => array( 'view' ), |
|
212 | + 'context' => array('view'), |
|
213 | 213 | 'readonly' => true, |
214 | 214 | ), |
215 | 215 | 'access_expires' => array( |
216 | - 'description' => __( "The date when download access expires, in the site's timezone.", 'woocommerce' ), |
|
216 | + 'description' => __("The date when download access expires, in the site's timezone.", 'woocommerce'), |
|
217 | 217 | 'type' => 'string', |
218 | - 'context' => array( 'view' ), |
|
218 | + 'context' => array('view'), |
|
219 | 219 | 'readonly' => true, |
220 | 220 | ), |
221 | 221 | 'access_expires_gmt' => array( |
222 | - 'description' => __( 'The date when download access expires, as GMT.', 'woocommerce' ), |
|
222 | + 'description' => __('The date when download access expires, as GMT.', 'woocommerce'), |
|
223 | 223 | 'type' => 'string', |
224 | - 'context' => array( 'view' ), |
|
224 | + 'context' => array('view'), |
|
225 | 225 | 'readonly' => true, |
226 | 226 | ), |
227 | 227 | 'file' => array( |
228 | - 'description' => __( 'File details.', 'woocommerce' ), |
|
228 | + 'description' => __('File details.', 'woocommerce'), |
|
229 | 229 | 'type' => 'object', |
230 | - 'context' => array( 'view' ), |
|
230 | + 'context' => array('view'), |
|
231 | 231 | 'readonly' => true, |
232 | 232 | 'properties' => array( |
233 | 233 | 'name' => array( |
234 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
234 | + 'description' => __('File name.', 'woocommerce'), |
|
235 | 235 | 'type' => 'string', |
236 | - 'context' => array( 'view' ), |
|
236 | + 'context' => array('view'), |
|
237 | 237 | 'readonly' => true, |
238 | 238 | ), |
239 | 239 | 'file' => array( |
240 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
240 | + 'description' => __('File URL.', 'woocommerce'), |
|
241 | 241 | 'type' => 'string', |
242 | - 'context' => array( 'view' ), |
|
242 | + 'context' => array('view'), |
|
243 | 243 | 'readonly' => true, |
244 | 244 | ), |
245 | 245 | ), |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | ), |
248 | 248 | ); |
249 | 249 | |
250 | - return $this->add_additional_fields_schema( $schema ); |
|
250 | + return $this->add_additional_fields_schema($schema); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function get_collection_params() { |
259 | 259 | return array( |
260 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
260 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
261 | 261 | ); |
262 | 262 | } |
263 | 263 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Product Categories controller class. |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * @param \WP_REST_Request $request Request instance. |
38 | 38 | * @return \WP_REST_Response |
39 | 39 | */ |
40 | - public function prepare_item_for_response( $item, $request ) { |
|
40 | + public function prepare_item_for_response($item, $request) { |
|
41 | 41 | // Get category display type. |
42 | - $display_type = get_term_meta( $item->term_id, 'display_type', true ); |
|
42 | + $display_type = get_term_meta($item->term_id, 'display_type', true); |
|
43 | 43 | |
44 | 44 | // Get category order. |
45 | - $menu_order = get_term_meta( $item->term_id, 'order', true ); |
|
45 | + $menu_order = get_term_meta($item->term_id, 'order', true); |
|
46 | 46 | |
47 | 47 | $data = array( |
48 | 48 | 'id' => (int) $item->term_id, |
@@ -57,29 +57,29 @@ discard block |
||
57 | 57 | ); |
58 | 58 | |
59 | 59 | // Get category image. |
60 | - $image_id = get_term_meta( $item->term_id, 'thumbnail_id', true ); |
|
61 | - if ( $image_id ) { |
|
62 | - $attachment = get_post( $image_id ); |
|
60 | + $image_id = get_term_meta($item->term_id, 'thumbnail_id', true); |
|
61 | + if ($image_id) { |
|
62 | + $attachment = get_post($image_id); |
|
63 | 63 | |
64 | 64 | $data['image'] = array( |
65 | 65 | 'id' => (int) $image_id, |
66 | - 'date_created' => wc_rest_prepare_date_response( $attachment->post_date ), |
|
67 | - 'date_created_gmt' => wc_rest_prepare_date_response( $attachment->post_date_gmt ), |
|
68 | - 'date_modified' => wc_rest_prepare_date_response( $attachment->post_modified ), |
|
69 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $attachment->post_modified_gmt ), |
|
70 | - 'src' => wp_get_attachment_url( $image_id ), |
|
71 | - 'name' => get_the_title( $attachment ), |
|
72 | - 'alt' => get_post_meta( $image_id, '_wp_attachment_image_alt', true ), |
|
66 | + 'date_created' => wc_rest_prepare_date_response($attachment->post_date), |
|
67 | + 'date_created_gmt' => wc_rest_prepare_date_response($attachment->post_date_gmt), |
|
68 | + 'date_modified' => wc_rest_prepare_date_response($attachment->post_modified), |
|
69 | + 'date_modified_gmt' => wc_rest_prepare_date_response($attachment->post_modified_gmt), |
|
70 | + 'src' => wp_get_attachment_url($image_id), |
|
71 | + 'name' => get_the_title($attachment), |
|
72 | + 'alt' => get_post_meta($image_id, '_wp_attachment_image_alt', true), |
|
73 | 73 | ); |
74 | 74 | } |
75 | 75 | |
76 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
77 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
78 | - $data = $this->filter_response_by_context( $data, $context ); |
|
76 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
77 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
78 | + $data = $this->filter_response_by_context($data, $context); |
|
79 | 79 | |
80 | - $response = rest_ensure_response( $data ); |
|
80 | + $response = rest_ensure_response($data); |
|
81 | 81 | |
82 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
82 | + $response->add_links($this->prepare_links($item, $request)); |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Filter a term item returned from the API. |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param object $item The original term object. |
91 | 91 | * @param \WP_REST_Request $request Request used to generate the response. |
92 | 92 | */ |
93 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
93 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -102,50 +102,50 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @since 3.5.5 |
104 | 104 | */ |
105 | - protected function update_term_meta_fields( $term, $request ) { |
|
105 | + protected function update_term_meta_fields($term, $request) { |
|
106 | 106 | $id = (int) $term->term_id; |
107 | 107 | |
108 | - if ( isset( $request['display'] ) ) { |
|
109 | - update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] ); |
|
108 | + if (isset($request['display'])) { |
|
109 | + update_term_meta($id, 'display_type', 'default' === $request['display'] ? '' : $request['display']); |
|
110 | 110 | } |
111 | 111 | |
112 | - if ( isset( $request['menu_order'] ) ) { |
|
113 | - update_term_meta( $id, 'order', $request['menu_order'] ); |
|
112 | + if (isset($request['menu_order'])) { |
|
113 | + update_term_meta($id, 'order', $request['menu_order']); |
|
114 | 114 | } |
115 | 115 | |
116 | - if ( isset( $request['image'] ) ) { |
|
117 | - if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) { |
|
118 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) ); |
|
116 | + if (isset($request['image'])) { |
|
117 | + if (empty($request['image']['id']) && ! empty($request['image']['src'])) { |
|
118 | + $upload = wc_rest_upload_image_from_url(esc_url_raw($request['image']['src'])); |
|
119 | 119 | |
120 | - if ( is_wp_error( $upload ) ) { |
|
120 | + if (is_wp_error($upload)) { |
|
121 | 121 | return $upload; |
122 | 122 | } |
123 | 123 | |
124 | - $image_id = wc_rest_set_uploaded_image_as_attachment( $upload ); |
|
124 | + $image_id = wc_rest_set_uploaded_image_as_attachment($upload); |
|
125 | 125 | } else { |
126 | - $image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0; |
|
126 | + $image_id = isset($request['image']['id']) ? absint($request['image']['id']) : 0; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | // Check if image_id is a valid image attachment before updating the term meta. |
130 | - if ( $image_id && wp_attachment_is_image( $image_id ) ) { |
|
131 | - update_term_meta( $id, 'thumbnail_id', $image_id ); |
|
130 | + if ($image_id && wp_attachment_is_image($image_id)) { |
|
131 | + update_term_meta($id, 'thumbnail_id', $image_id); |
|
132 | 132 | |
133 | 133 | // Set the image alt. |
134 | - if ( ! empty( $request['image']['alt'] ) ) { |
|
135 | - update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) ); |
|
134 | + if ( ! empty($request['image']['alt'])) { |
|
135 | + update_post_meta($image_id, '_wp_attachment_image_alt', wc_clean($request['image']['alt'])); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | // Set the image title. |
139 | - if ( ! empty( $request['image']['name'] ) ) { |
|
139 | + if ( ! empty($request['image']['name'])) { |
|
140 | 140 | wp_update_post( |
141 | 141 | array( |
142 | 142 | 'ID' => $image_id, |
143 | - 'post_title' => wc_clean( $request['image']['name'] ), |
|
143 | + 'post_title' => wc_clean($request['image']['name']), |
|
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | } |
147 | 147 | } else { |
148 | - delete_term_meta( $id, 'thumbnail_id' ); |
|
148 | + delete_term_meta($id, 'thumbnail_id'); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -164,113 +164,113 @@ discard block |
||
164 | 164 | 'type' => 'object', |
165 | 165 | 'properties' => array( |
166 | 166 | 'id' => array( |
167 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
167 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
168 | 168 | 'type' => 'integer', |
169 | - 'context' => array( 'view', 'edit' ), |
|
169 | + 'context' => array('view', 'edit'), |
|
170 | 170 | 'readonly' => true, |
171 | 171 | ), |
172 | 172 | 'name' => array( |
173 | - 'description' => __( 'Category name.', 'woocommerce' ), |
|
173 | + 'description' => __('Category name.', 'woocommerce'), |
|
174 | 174 | 'type' => 'string', |
175 | - 'context' => array( 'view', 'edit' ), |
|
175 | + 'context' => array('view', 'edit'), |
|
176 | 176 | 'arg_options' => array( |
177 | 177 | 'sanitize_callback' => 'sanitize_text_field', |
178 | 178 | ), |
179 | 179 | ), |
180 | 180 | 'slug' => array( |
181 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
181 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
182 | 182 | 'type' => 'string', |
183 | - 'context' => array( 'view', 'edit' ), |
|
183 | + 'context' => array('view', 'edit'), |
|
184 | 184 | 'arg_options' => array( |
185 | 185 | 'sanitize_callback' => 'sanitize_title', |
186 | 186 | ), |
187 | 187 | ), |
188 | 188 | 'parent' => array( |
189 | - 'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ), |
|
189 | + 'description' => __('The ID for the parent of the resource.', 'woocommerce'), |
|
190 | 190 | 'type' => 'integer', |
191 | - 'context' => array( 'view', 'edit' ), |
|
191 | + 'context' => array('view', 'edit'), |
|
192 | 192 | ), |
193 | 193 | 'description' => array( |
194 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
194 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
195 | 195 | 'type' => 'string', |
196 | - 'context' => array( 'view', 'edit' ), |
|
196 | + 'context' => array('view', 'edit'), |
|
197 | 197 | 'arg_options' => array( |
198 | 198 | 'sanitize_callback' => 'wp_filter_post_kses', |
199 | 199 | ), |
200 | 200 | ), |
201 | 201 | 'display' => array( |
202 | - 'description' => __( 'Category archive display type.', 'woocommerce' ), |
|
202 | + 'description' => __('Category archive display type.', 'woocommerce'), |
|
203 | 203 | 'type' => 'string', |
204 | 204 | 'default' => 'default', |
205 | - 'enum' => array( 'default', 'products', 'subcategories', 'both' ), |
|
206 | - 'context' => array( 'view', 'edit' ), |
|
205 | + 'enum' => array('default', 'products', 'subcategories', 'both'), |
|
206 | + 'context' => array('view', 'edit'), |
|
207 | 207 | ), |
208 | 208 | 'image' => array( |
209 | - 'description' => __( 'Image data.', 'woocommerce' ), |
|
209 | + 'description' => __('Image data.', 'woocommerce'), |
|
210 | 210 | 'type' => 'object', |
211 | - 'context' => array( 'view', 'edit' ), |
|
211 | + 'context' => array('view', 'edit'), |
|
212 | 212 | 'properties' => array( |
213 | 213 | 'id' => array( |
214 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
214 | + 'description' => __('Image ID.', 'woocommerce'), |
|
215 | 215 | 'type' => 'integer', |
216 | - 'context' => array( 'view', 'edit' ), |
|
216 | + 'context' => array('view', 'edit'), |
|
217 | 217 | ), |
218 | 218 | 'date_created' => array( |
219 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
219 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
220 | 220 | 'type' => 'date-time', |
221 | - 'context' => array( 'view', 'edit' ), |
|
221 | + 'context' => array('view', 'edit'), |
|
222 | 222 | 'readonly' => true, |
223 | 223 | ), |
224 | 224 | 'date_created_gmt' => array( |
225 | - 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
|
225 | + 'description' => __('The date the image was created, as GMT.', 'woocommerce'), |
|
226 | 226 | 'type' => 'date-time', |
227 | - 'context' => array( 'view', 'edit' ), |
|
227 | + 'context' => array('view', 'edit'), |
|
228 | 228 | 'readonly' => true, |
229 | 229 | ), |
230 | 230 | 'date_modified' => array( |
231 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
231 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
232 | 232 | 'type' => 'date-time', |
233 | - 'context' => array( 'view', 'edit' ), |
|
233 | + 'context' => array('view', 'edit'), |
|
234 | 234 | 'readonly' => true, |
235 | 235 | ), |
236 | 236 | 'date_modified_gmt' => array( |
237 | - 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
|
237 | + 'description' => __('The date the image was last modified, as GMT.', 'woocommerce'), |
|
238 | 238 | 'type' => 'date-time', |
239 | - 'context' => array( 'view', 'edit' ), |
|
239 | + 'context' => array('view', 'edit'), |
|
240 | 240 | 'readonly' => true, |
241 | 241 | ), |
242 | 242 | 'src' => array( |
243 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
243 | + 'description' => __('Image URL.', 'woocommerce'), |
|
244 | 244 | 'type' => 'string', |
245 | 245 | 'format' => 'uri', |
246 | - 'context' => array( 'view', 'edit' ), |
|
246 | + 'context' => array('view', 'edit'), |
|
247 | 247 | ), |
248 | 248 | 'name' => array( |
249 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
249 | + 'description' => __('Image name.', 'woocommerce'), |
|
250 | 250 | 'type' => 'string', |
251 | - 'context' => array( 'view', 'edit' ), |
|
251 | + 'context' => array('view', 'edit'), |
|
252 | 252 | ), |
253 | 253 | 'alt' => array( |
254 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
254 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
255 | 255 | 'type' => 'string', |
256 | - 'context' => array( 'view', 'edit' ), |
|
256 | + 'context' => array('view', 'edit'), |
|
257 | 257 | ), |
258 | 258 | ), |
259 | 259 | ), |
260 | 260 | 'menu_order' => array( |
261 | - 'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ), |
|
261 | + 'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'), |
|
262 | 262 | 'type' => 'integer', |
263 | - 'context' => array( 'view', 'edit' ), |
|
263 | + 'context' => array('view', 'edit'), |
|
264 | 264 | ), |
265 | 265 | 'count' => array( |
266 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
266 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
267 | 267 | 'type' => 'integer', |
268 | - 'context' => array( 'view', 'edit' ), |
|
268 | + 'context' => array('view', 'edit'), |
|
269 | 269 | 'readonly' => true, |
270 | 270 | ), |
271 | 271 | ), |
272 | 272 | ); |
273 | 273 | |
274 | - return $this->add_additional_fields_schema( $schema ); |
|
274 | + return $this->add_additional_fields_schema($schema); |
|
275 | 275 | } |
276 | 276 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Data; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Data as DataController; |
15 | 15 | |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | array( |
38 | 38 | array( |
39 | 39 | 'methods' => \WP_REST_Server::READABLE, |
40 | - 'callback' => array( $this, 'get_items' ), |
|
41 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
40 | + 'callback' => array($this, 'get_items'), |
|
41 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
42 | 42 | ), |
43 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
43 | + 'schema' => array($this, 'get_public_item_schema'), |
|
44 | 44 | ) |
45 | 45 | ); |
46 | 46 | } |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | * @param \WP_REST_Request $request Request data. |
53 | 53 | * @return \WP_Error\WP_REST_Response |
54 | 54 | */ |
55 | - public function get_items( $request ) { |
|
55 | + public function get_items($request) { |
|
56 | 56 | global $wpdb; |
57 | 57 | |
58 | - if ( isset( $request['match'] ) ) { |
|
58 | + if (isset($request['match'])) { |
|
59 | 59 | $downloads = $wpdb->get_results( |
60 | 60 | $wpdb->prepare( |
61 | 61 | "SELECT DISTINCT( user_ip_address ) FROM {$wpdb->prefix}wc_download_log |
@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | ) |
66 | 66 | ); |
67 | 67 | } else { |
68 | - return new \WP_Error( 'woocommerce_rest_data_download_ips_invalid_request', __( 'Invalid request. Please pass the match parameter.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
68 | + return new \WP_Error('woocommerce_rest_data_download_ips_invalid_request', __('Invalid request. Please pass the match parameter.', 'woocommerce'), array('status' => 400)); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $data = array(); |
72 | 72 | |
73 | - if ( ! empty( $downloads ) ) { |
|
74 | - foreach ( $downloads as $download ) { |
|
75 | - $response = $this->prepare_item_for_response( $download, $request ); |
|
76 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
73 | + if ( ! empty($downloads)) { |
|
74 | + foreach ($downloads as $download) { |
|
75 | + $response = $this->prepare_item_for_response($download, $request); |
|
76 | + $data[] = $this->prepare_response_for_collection($response); |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
80 | - return rest_ensure_response( $data ); |
|
80 | + return rest_ensure_response($data); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | * @param \WP_REST_Request $request Request object. |
89 | 89 | * @return \WP_REST_Response $response Response data. |
90 | 90 | */ |
91 | - public function prepare_item_for_response( $item, $request ) { |
|
92 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
93 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
94 | - $response = rest_ensure_response( $data ); |
|
91 | + public function prepare_item_for_response($item, $request) { |
|
92 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
93 | + $data = $this->filter_response_by_context($data, 'view'); |
|
94 | + $response = rest_ensure_response($data); |
|
95 | 95 | |
96 | - $response->add_links( $this->prepare_links( $item ) ); |
|
96 | + $response->add_links($this->prepare_links($item)); |
|
97 | 97 | |
98 | 98 | /** |
99 | 99 | * Filter the list returned from the API. |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @param array $item The original item. |
103 | 103 | * @param \WP_REST_Request $request Request used to generate the response. |
104 | 104 | */ |
105 | - return apply_filters( 'woocommerce_rest_prepare_data_download_ip', $response, $item, $request ); |
|
105 | + return apply_filters('woocommerce_rest_prepare_data_download_ip', $response, $item, $request); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | * @param object $item Data object. |
112 | 112 | * @return array Links for the given object. |
113 | 113 | */ |
114 | - protected function prepare_links( $item ) { |
|
114 | + protected function prepare_links($item) { |
|
115 | 115 | $links = array( |
116 | 116 | 'collection' => array( |
117 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
117 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
118 | 118 | ), |
119 | 119 | ); |
120 | 120 | return $links; |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function get_collection_params() { |
129 | 129 | $params = array(); |
130 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
130 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
131 | 131 | $params['match'] = array( |
132 | - 'description' => __( 'A partial IP address can be passed and matching results will be returned.', 'woocommerce' ), |
|
132 | + 'description' => __('A partial IP address can be passed and matching results will be returned.', 'woocommerce'), |
|
133 | 133 | 'type' => 'string', |
134 | 134 | 'validate_callback' => 'rest_validate_request_arg', |
135 | 135 | ); |
@@ -150,13 +150,13 @@ discard block |
||
150 | 150 | 'properties' => array( |
151 | 151 | 'user_ip_address' => array( |
152 | 152 | 'type' => 'string', |
153 | - 'description' => __( 'IP address.', 'woocommerce' ), |
|
154 | - 'context' => array( 'view' ), |
|
153 | + 'description' => __('IP address.', 'woocommerce'), |
|
154 | + 'context' => array('view'), |
|
155 | 155 | 'readonly' => true, |
156 | 156 | ), |
157 | 157 | ), |
158 | 158 | ); |
159 | 159 | |
160 | - return $this->add_additional_fields_schema( $schema ); |
|
160 | + return $this->add_additional_fields_schema($schema); |
|
161 | 161 | } |
162 | 162 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Version4\Controllers\Data; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | use \WooCommerce\RestApi\Version4\Controllers\Data as DataController; |
15 | 15 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | array( |
36 | 36 | array( |
37 | 37 | 'methods' => \WP_REST_Server::READABLE, |
38 | - 'callback' => array( $this, 'get_items' ), |
|
39 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
38 | + 'callback' => array($this, 'get_items'), |
|
39 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
40 | 40 | ), |
41 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
41 | + 'schema' => array($this, 'get_public_item_schema'), |
|
42 | 42 | ) |
43 | 43 | ); |
44 | 44 | register_rest_route( |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | array( |
48 | 48 | array( |
49 | 49 | 'methods' => \WP_REST_Server::READABLE, |
50 | - 'callback' => array( $this, 'get_current_item' ), |
|
51 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
50 | + 'callback' => array($this, 'get_current_item'), |
|
51 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
52 | 52 | ), |
53 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
53 | + 'schema' => array($this, 'get_public_item_schema'), |
|
54 | 54 | ) |
55 | 55 | ); |
56 | 56 | register_rest_route( |
@@ -59,16 +59,16 @@ discard block |
||
59 | 59 | array( |
60 | 60 | array( |
61 | 61 | 'methods' => \WP_REST_Server::READABLE, |
62 | - 'callback' => array( $this, 'get_item' ), |
|
63 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
62 | + 'callback' => array($this, 'get_item'), |
|
63 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
64 | 64 | 'args' => array( |
65 | 65 | 'location' => array( |
66 | - 'description' => __( 'ISO4217 currency code.', 'woocommerce' ), |
|
66 | + 'description' => __('ISO4217 currency code.', 'woocommerce'), |
|
67 | 67 | 'type' => 'string', |
68 | 68 | ), |
69 | 69 | ), |
70 | 70 | ), |
71 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
71 | + 'schema' => array($this, 'get_public_item_schema'), |
|
72 | 72 | ) |
73 | 73 | ); |
74 | 74 | } |
@@ -80,18 +80,18 @@ discard block |
||
80 | 80 | * @param \WP_REST_Request $request Request data. |
81 | 81 | * @return array|mixed Response data, ready for insertion into collection data. |
82 | 82 | */ |
83 | - public function get_currency( $code = false, $request ) { |
|
83 | + public function get_currency($code = false, $request) { |
|
84 | 84 | $currencies = get_woocommerce_currencies(); |
85 | 85 | $data = array(); |
86 | 86 | |
87 | - if ( ! array_key_exists( $code, $currencies ) ) { |
|
87 | + if ( ! array_key_exists($code, $currencies)) { |
|
88 | 88 | return false; |
89 | 89 | } |
90 | 90 | |
91 | 91 | $currency = array( |
92 | 92 | 'code' => $code, |
93 | - 'name' => $currencies[ $code ], |
|
94 | - 'symbol' => get_woocommerce_currency_symbol( $code ), |
|
93 | + 'name' => $currencies[$code], |
|
94 | + 'symbol' => get_woocommerce_currency_symbol($code), |
|
95 | 95 | ); |
96 | 96 | |
97 | 97 | return $currency; |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | * @param \WP_REST_Request $request Request data. |
104 | 104 | * @return \WP_Error\WP_REST_Response |
105 | 105 | */ |
106 | - public function get_items( $request ) { |
|
106 | + public function get_items($request) { |
|
107 | 107 | $currencies = get_woocommerce_currencies(); |
108 | - foreach ( array_keys( $currencies ) as $code ) { |
|
109 | - $currency = $this->get_currency( $code, $request ); |
|
110 | - $response = $this->prepare_item_for_response( $currency, $request ); |
|
111 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
108 | + foreach (array_keys($currencies) as $code) { |
|
109 | + $currency = $this->get_currency($code, $request); |
|
110 | + $response = $this->prepare_item_for_response($currency, $request); |
|
111 | + $data[] = $this->prepare_response_for_collection($response); |
|
112 | 112 | } |
113 | 113 | |
114 | - return rest_ensure_response( $data ); |
|
114 | + return rest_ensure_response($data); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | * @param \WP_REST_Request $request Request data. |
121 | 121 | * @return \WP_Error\WP_REST_Response |
122 | 122 | */ |
123 | - public function get_item( $request ) { |
|
124 | - $data = $this->get_currency( strtoupper( $request['currency'] ), $request ); |
|
125 | - if ( empty( $data ) ) { |
|
126 | - return new \WP_Error( 'woocommerce_rest_data_invalid_currency', __( 'There are no currencies matching these parameters.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
123 | + public function get_item($request) { |
|
124 | + $data = $this->get_currency(strtoupper($request['currency']), $request); |
|
125 | + if (empty($data)) { |
|
126 | + return new \WP_Error('woocommerce_rest_data_invalid_currency', __('There are no currencies matching these parameters.', 'woocommerce'), array('status' => 404)); |
|
127 | 127 | } |
128 | - return $this->prepare_item_for_response( $data, $request ); |
|
128 | + return $this->prepare_item_for_response($data, $request); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | * @param \WP_REST_Request $request Request data. |
135 | 135 | * @return \WP_Error\WP_REST_Response |
136 | 136 | */ |
137 | - public function get_current_item( $request ) { |
|
138 | - $currency = get_option( 'woocommerce_currency' ); |
|
139 | - return $this->prepare_item_for_response( $this->get_currency( $currency, $request ), $request ); |
|
137 | + public function get_current_item($request) { |
|
138 | + $currency = get_option('woocommerce_currency'); |
|
139 | + return $this->prepare_item_for_response($this->get_currency($currency, $request), $request); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | * @param \WP_REST_Request $request Request object. |
147 | 147 | * @return \WP_REST_Response $response Response data. |
148 | 148 | */ |
149 | - public function prepare_item_for_response( $item, $request ) { |
|
150 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
151 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
152 | - $response = rest_ensure_response( $data ); |
|
149 | + public function prepare_item_for_response($item, $request) { |
|
150 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
151 | + $data = $this->filter_response_by_context($data, 'view'); |
|
152 | + $response = rest_ensure_response($data); |
|
153 | 153 | |
154 | - $response->add_links( $this->prepare_links( $item ) ); |
|
154 | + $response->add_links($this->prepare_links($item)); |
|
155 | 155 | |
156 | 156 | /** |
157 | 157 | * Filter currency returned from the API. |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @param array $item Currency data. |
161 | 161 | * @param \WP_REST_Request $request Request used to generate the response. |
162 | 162 | */ |
163 | - return apply_filters( 'woocommerce_rest_prepare_data_currency', $response, $item, $request ); |
|
163 | + return apply_filters('woocommerce_rest_prepare_data_currency', $response, $item, $request); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -169,14 +169,14 @@ discard block |
||
169 | 169 | * @param object $item Data object. |
170 | 170 | * @return array Links for the given currency. |
171 | 171 | */ |
172 | - protected function prepare_links( $item ) { |
|
173 | - $code = strtoupper( $item['code'] ); |
|
172 | + protected function prepare_links($item) { |
|
173 | + $code = strtoupper($item['code']); |
|
174 | 174 | $links = array( |
175 | 175 | 'self' => array( |
176 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $code ) ), |
|
176 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $code)), |
|
177 | 177 | ), |
178 | 178 | 'collection' => array( |
179 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
179 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
180 | 180 | ), |
181 | 181 | ); |
182 | 182 | |
@@ -197,25 +197,25 @@ discard block |
||
197 | 197 | 'properties' => array( |
198 | 198 | 'code' => array( |
199 | 199 | 'type' => 'string', |
200 | - 'description' => __( 'ISO4217 currency code.', 'woocommerce' ), |
|
201 | - 'context' => array( 'view' ), |
|
200 | + 'description' => __('ISO4217 currency code.', 'woocommerce'), |
|
201 | + 'context' => array('view'), |
|
202 | 202 | 'readonly' => true, |
203 | 203 | ), |
204 | 204 | 'name' => array( |
205 | 205 | 'type' => 'string', |
206 | - 'description' => __( 'Full name of currency.', 'woocommerce' ), |
|
207 | - 'context' => array( 'view' ), |
|
206 | + 'description' => __('Full name of currency.', 'woocommerce'), |
|
207 | + 'context' => array('view'), |
|
208 | 208 | 'readonly' => true, |
209 | 209 | ), |
210 | 210 | 'symbol' => array( |
211 | 211 | 'type' => 'string', |
212 | - 'description' => __( 'Currency symbol.', 'woocommerce' ), |
|
213 | - 'context' => array( 'view' ), |
|
212 | + 'description' => __('Currency symbol.', 'woocommerce'), |
|
213 | + 'context' => array('view'), |
|
214 | 214 | 'readonly' => true, |
215 | 215 | ), |
216 | 216 | ), |
217 | 217 | ); |
218 | 218 | |
219 | - return $this->add_additional_fields_schema( $schema ); |
|
219 | + return $this->add_additional_fields_schema($schema); |
|
220 | 220 | } |
221 | 221 | } |