@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | * @package WooCommerce/RestApi |
13 | 13 | */ |
14 | 14 | |
15 | -defined( 'ABSPATH' ) || exit; |
|
15 | +defined('ABSPATH') || exit; |
|
16 | 16 | |
17 | -if ( version_compare( PHP_VERSION, '5.6.0', '<' ) ) { |
|
17 | +if (version_compare(PHP_VERSION, '5.6.0', '<')) { |
|
18 | 18 | return; |
19 | 19 | } |
20 | 20 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * This callback registers this version of the API with WooCommerce. |
29 | 29 | */ |
30 | -$register_callback = function() use ( $version, $init_callback ) { |
|
31 | - if ( ! is_callable( array( wc()->api, 'register' ) ) ) { |
|
30 | +$register_callback = function() use ($version, $init_callback) { |
|
31 | + if ( ! is_callable(array(wc()->api, 'register'))) { |
|
32 | 32 | return; |
33 | 33 | } |
34 | - wc()->api->register( $version, $init_callback ); |
|
34 | + wc()->api->register($version, $init_callback); |
|
35 | 35 | }; |
36 | 36 | |
37 | -add_action( 'woocommerce_loaded', $register_callback ); |
|
37 | +add_action('woocommerce_loaded', $register_callback); |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | namespace WooCommerce\RestApi\Version4; |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Controllers class. |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | 'webhooks' => __NAMESPACE__ . '\Controllers\Webhooks', |
57 | 57 | ]; |
58 | 58 | |
59 | - if ( class_exists( '\WC_Admin_Note' ) ) { |
|
59 | + if (class_exists('\WC_Admin_Note')) { |
|
60 | 60 | $controllers['admin-notes'] = __NAMESPACE__ . '\Controllers\AdminNotes'; |
61 | 61 | } |
62 | 62 | |
63 | - if ( class_exists( '\WC_Admin_Reports_Sync' ) ) { |
|
63 | + if (class_exists('\WC_Admin_Reports_Sync')) { |
|
64 | 64 | $controllers['reports-categories'] = __NAMESPACE__ . '\Controllers\Reports\Categories'; |
65 | 65 | $controllers['reports-coupons'] = __NAMESPACE__ . '\Controllers\Reports\Coupons'; |
66 | 66 | $controllers['reports-coupon-stats'] = __NAMESPACE__ . '\Controllers\Reports\CouponStats'; |
@@ -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 | * AdminNotes controller class. |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | array( |
41 | 41 | array( |
42 | 42 | 'methods' => \WP_REST_Server::READABLE, |
43 | - 'callback' => array( $this, 'get_items' ), |
|
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
43 | + 'callback' => array($this, 'get_items'), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | 45 | 'args' => $this->get_collection_params(), |
46 | 46 | ), |
47 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
47 | + 'schema' => array($this, 'get_public_item_schema'), |
|
48 | 48 | ) |
49 | 49 | ); |
50 | 50 | |
@@ -54,21 +54,21 @@ discard block |
||
54 | 54 | array( |
55 | 55 | 'args' => array( |
56 | 56 | 'id' => array( |
57 | - 'description' => __( 'Unique ID for the resource.', 'woocommerce' ), |
|
57 | + 'description' => __('Unique ID for the resource.', 'woocommerce'), |
|
58 | 58 | 'type' => 'integer', |
59 | 59 | ), |
60 | 60 | ), |
61 | 61 | array( |
62 | 62 | 'methods' => \WP_REST_Server::READABLE, |
63 | - 'callback' => array( $this, 'get_item' ), |
|
64 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
63 | + 'callback' => array($this, 'get_item'), |
|
64 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
65 | 65 | ), |
66 | 66 | array( |
67 | 67 | 'methods' => \WP_REST_Server::EDITABLE, |
68 | - 'callback' => array( $this, 'update_item' ), |
|
69 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
68 | + 'callback' => array($this, 'update_item'), |
|
69 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
70 | 70 | ), |
71 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
71 | + 'schema' => array($this, 'get_public_item_schema'), |
|
72 | 72 | ) |
73 | 73 | ); |
74 | 74 | } |
@@ -79,26 +79,26 @@ discard block |
||
79 | 79 | * @param WP_REST_Request $request Request data. |
80 | 80 | * @return WP_REST_Response|WP_Error |
81 | 81 | */ |
82 | - public function get_item( $request ) { |
|
83 | - $note = \WC_Admin_Notes::get_note( $request->get_param( 'id' ) ); |
|
82 | + public function get_item($request) { |
|
83 | + $note = \WC_Admin_Notes::get_note($request->get_param('id')); |
|
84 | 84 | |
85 | - if ( ! $note ) { |
|
85 | + if ( ! $note) { |
|
86 | 86 | return new \WP_Error( |
87 | 87 | 'woocommerce_admin_notes_invalid_id', |
88 | - __( 'Sorry, there is no resouce with that ID.', 'woocommerce' ), |
|
89 | - array( 'status' => 404 ) |
|
88 | + __('Sorry, there is no resouce with that ID.', 'woocommerce'), |
|
89 | + array('status' => 404) |
|
90 | 90 | ); |
91 | 91 | } |
92 | 92 | |
93 | - if ( is_wp_error( $note ) ) { |
|
93 | + if (is_wp_error($note)) { |
|
94 | 94 | return $note; |
95 | 95 | } |
96 | 96 | |
97 | 97 | $data = $note->get_data(); |
98 | - $data = $this->prepare_item_for_response( $data, $request ); |
|
99 | - $data = $this->prepare_response_for_collection( $data ); |
|
98 | + $data = $this->prepare_item_for_response($data, $request); |
|
99 | + $data = $this->prepare_response_for_collection($data); |
|
100 | 100 | |
101 | - return rest_ensure_response( $data ); |
|
101 | + return rest_ensure_response($data); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -107,20 +107,20 @@ discard block |
||
107 | 107 | * @param WP_REST_Request $request Request data. |
108 | 108 | * @return WP_REST_Response |
109 | 109 | */ |
110 | - public function get_items( $request ) { |
|
111 | - $query_args = $this->prepare_objects_query( $request ); |
|
110 | + public function get_items($request) { |
|
111 | + $query_args = $this->prepare_objects_query($request); |
|
112 | 112 | |
113 | - $notes = \WC_Admin_Notes::get_notes( 'edit', $query_args ); |
|
113 | + $notes = \WC_Admin_Notes::get_notes('edit', $query_args); |
|
114 | 114 | |
115 | 115 | $data = array(); |
116 | - foreach ( (array) $notes as $note_obj ) { |
|
117 | - $note = $this->prepare_item_for_response( $note_obj, $request ); |
|
118 | - $note = $this->prepare_response_for_collection( $note ); |
|
116 | + foreach ((array) $notes as $note_obj) { |
|
117 | + $note = $this->prepare_item_for_response($note_obj, $request); |
|
118 | + $note = $this->prepare_response_for_collection($note); |
|
119 | 119 | $data[] = $note; |
120 | 120 | } |
121 | 121 | |
122 | - $response = rest_ensure_response( $data ); |
|
123 | - $response->header( 'X-WP-Total', \WC_Admin_Notes::get_notes_count( $query_args['type'], $query_args['status'] ) ); |
|
122 | + $response = rest_ensure_response($data); |
|
123 | + $response->header('X-WP-Total', \WC_Admin_Notes::get_notes_count($query_args['type'], $query_args['status'])); |
|
124 | 124 | |
125 | 125 | return $response; |
126 | 126 | } |
@@ -131,16 +131,16 @@ discard block |
||
131 | 131 | * @param WP_REST_Request $request Full details about the request. |
132 | 132 | * @return array |
133 | 133 | */ |
134 | - protected function prepare_objects_query( $request ) { |
|
134 | + protected function prepare_objects_query($request) { |
|
135 | 135 | $args = array(); |
136 | 136 | $args['order'] = $request['order']; |
137 | 137 | $args['orderby'] = $request['orderby']; |
138 | 138 | $args['per_page'] = $request['per_page']; |
139 | 139 | $args['page'] = $request['page']; |
140 | - $args['type'] = isset( $request['type'] ) ? $request['type'] : array(); |
|
141 | - $args['status'] = isset( $request['status'] ) ? $request['status'] : array(); |
|
140 | + $args['type'] = isset($request['type']) ? $request['type'] : array(); |
|
141 | + $args['status'] = isset($request['status']) ? $request['status'] : array(); |
|
142 | 142 | |
143 | - if ( 'date' === $args['orderby'] ) { |
|
143 | + if ('date' === $args['orderby']) { |
|
144 | 144 | $args['orderby'] = 'date_created'; |
145 | 145 | } |
146 | 146 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param array $args Key value array of query var to query value. |
154 | 154 | * @param WP_REST_Request $request The request used. |
155 | 155 | */ |
156 | - $args = apply_filters( 'woocommerce_rest_admin_notes_object_query', $args, $request ); |
|
156 | + $args = apply_filters('woocommerce_rest_admin_notes_object_query', $args, $request); |
|
157 | 157 | |
158 | 158 | return $args; |
159 | 159 | } |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | * @param WP_REST_Request $request Full details about the request. |
165 | 165 | * @return WP_Error|boolean |
166 | 166 | */ |
167 | - public function get_item_permissions_check( $request ) { |
|
168 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
169 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
167 | + public function get_item_permissions_check($request) { |
|
168 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
169 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | return true; |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | * @param WP_REST_Request $request Full details about the request. |
179 | 179 | * @return WP_Error|boolean |
180 | 180 | */ |
181 | - public function get_items_permissions_check( $request ) { |
|
182 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
183 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
181 | + public function get_items_permissions_check($request) { |
|
182 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
183 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | return true; |
@@ -192,32 +192,32 @@ discard block |
||
192 | 192 | * @param WP_REST_Request $request Full details about the request. |
193 | 193 | * @return WP_REST_Request|WP_Error |
194 | 194 | */ |
195 | - public function update_item( $request ) { |
|
196 | - $note = \WC_Admin_Notes::get_note( $request->get_param( 'id' ) ); |
|
195 | + public function update_item($request) { |
|
196 | + $note = \WC_Admin_Notes::get_note($request->get_param('id')); |
|
197 | 197 | |
198 | - if ( ! $note ) { |
|
198 | + if ( ! $note) { |
|
199 | 199 | return new \WP_Error( |
200 | 200 | 'woocommerce_admin_notes_invalid_id', |
201 | - __( 'Sorry, there is no resouce with that ID.', 'woocommerce' ), |
|
202 | - array( 'status' => 404 ) |
|
201 | + __('Sorry, there is no resouce with that ID.', 'woocommerce'), |
|
202 | + array('status' => 404) |
|
203 | 203 | ); |
204 | 204 | } |
205 | 205 | |
206 | 206 | $note_changed = false; |
207 | - if ( ! is_null( $request->get_param( 'status' ) ) ) { |
|
208 | - $note->set_status( $request->get_param( 'status' ) ); |
|
207 | + if ( ! is_null($request->get_param('status'))) { |
|
208 | + $note->set_status($request->get_param('status')); |
|
209 | 209 | $note_changed = true; |
210 | 210 | } |
211 | 211 | |
212 | - if ( ! is_null( $request->get_param( 'date_reminder' ) ) ) { |
|
213 | - $note->set_date_reminder( $request->get_param( 'date_reminder' ) ); |
|
212 | + if ( ! is_null($request->get_param('date_reminder'))) { |
|
213 | + $note->set_date_reminder($request->get_param('date_reminder')); |
|
214 | 214 | $note_changed = true; |
215 | 215 | } |
216 | 216 | |
217 | - if ( $note_changed ) { |
|
217 | + if ($note_changed) { |
|
218 | 218 | $note->save(); |
219 | 219 | } |
220 | - return $this->get_item( $request ); |
|
220 | + return $this->get_item($request); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
@@ -226,9 +226,9 @@ discard block |
||
226 | 226 | * @param WP_REST_Request $request Full data about the request. |
227 | 227 | * @return WP_Error|bool |
228 | 228 | */ |
229 | - public function update_items_permissions_check( $request ) { |
|
230 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
231 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
229 | + public function update_items_permissions_check($request) { |
|
230 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
231 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
232 | 232 | } |
233 | 233 | return true; |
234 | 234 | } |
@@ -239,21 +239,21 @@ discard block |
||
239 | 239 | * @param string $query The query, path, or URL to transform. |
240 | 240 | * @return string A fully formed URL. |
241 | 241 | */ |
242 | - public function prepare_query_for_response( $query ) { |
|
243 | - if ( empty( $query ) ) { |
|
242 | + public function prepare_query_for_response($query) { |
|
243 | + if (empty($query)) { |
|
244 | 244 | return $query; |
245 | 245 | } |
246 | - if ( 'https://' === substr( $query, 0, 8 ) ) { |
|
246 | + if ('https://' === substr($query, 0, 8)) { |
|
247 | 247 | return $query; |
248 | 248 | } |
249 | - if ( 'http://' === substr( $query, 0, 7 ) ) { |
|
249 | + if ('http://' === substr($query, 0, 7)) { |
|
250 | 250 | return $query; |
251 | 251 | } |
252 | - if ( '?' === substr( $query, 0, 1 ) ) { |
|
253 | - return admin_url( 'admin.php' . $query ); |
|
252 | + if ('?' === substr($query, 0, 1)) { |
|
253 | + return admin_url('admin.php' . $query); |
|
254 | 254 | } |
255 | 255 | |
256 | - return admin_url( $query ); |
|
256 | + return admin_url($query); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
@@ -263,32 +263,32 @@ discard block |
||
263 | 263 | * @param WP_REST_Request $request Request object. |
264 | 264 | * @return WP_REST_Response $response Response data. |
265 | 265 | */ |
266 | - public function prepare_item_for_response( $data, $request ) { |
|
267 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
268 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
269 | - $data['date_created_gmt'] = wc_rest_prepare_date_response( $data['date_created'] ); |
|
270 | - $data['date_created'] = wc_rest_prepare_date_response( $data['date_created'], false ); |
|
271 | - $data['date_reminder_gmt'] = wc_rest_prepare_date_response( $data['date_reminder'] ); |
|
272 | - $data['date_reminder'] = wc_rest_prepare_date_response( $data['date_reminder'], false ); |
|
273 | - $data['title'] = stripslashes( $data['title'] ); |
|
274 | - $data['content'] = stripslashes( $data['content'] ); |
|
266 | + public function prepare_item_for_response($data, $request) { |
|
267 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
268 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
269 | + $data['date_created_gmt'] = wc_rest_prepare_date_response($data['date_created']); |
|
270 | + $data['date_created'] = wc_rest_prepare_date_response($data['date_created'], false); |
|
271 | + $data['date_reminder_gmt'] = wc_rest_prepare_date_response($data['date_reminder']); |
|
272 | + $data['date_reminder'] = wc_rest_prepare_date_response($data['date_reminder'], false); |
|
273 | + $data['title'] = stripslashes($data['title']); |
|
274 | + $data['content'] = stripslashes($data['content']); |
|
275 | 275 | $data['is_snoozable'] = (bool) $data['is_snoozable']; |
276 | - foreach ( (array) $data['actions'] as $key => $value ) { |
|
277 | - $data['actions'][ $key ]->label = stripslashes( $data['actions'][ $key ]->label ); |
|
278 | - $data['actions'][ $key ]->url = $this->prepare_query_for_response( $data['actions'][ $key ]->query ); |
|
279 | - $data['actions'][ $key ]->status = stripslashes( $data['actions'][ $key ]->status ); |
|
276 | + foreach ((array) $data['actions'] as $key => $value) { |
|
277 | + $data['actions'][$key]->label = stripslashes($data['actions'][$key]->label); |
|
278 | + $data['actions'][$key]->url = $this->prepare_query_for_response($data['actions'][$key]->query); |
|
279 | + $data['actions'][$key]->status = stripslashes($data['actions'][$key]->status); |
|
280 | 280 | } |
281 | - $data = $this->filter_response_by_context( $data, $context ); |
|
281 | + $data = $this->filter_response_by_context($data, $context); |
|
282 | 282 | |
283 | 283 | // Wrap the data in a response object. |
284 | - $response = rest_ensure_response( $data ); |
|
284 | + $response = rest_ensure_response($data); |
|
285 | 285 | $response->add_links( |
286 | 286 | array( |
287 | 287 | 'self' => array( |
288 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $data['id'] ) ), |
|
288 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $data['id'])), |
|
289 | 289 | ), |
290 | 290 | 'collection' => array( |
291 | - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), |
|
291 | + 'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)), |
|
292 | 292 | ), |
293 | 293 | ) |
294 | 294 | ); |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * @param array $data The original note. |
302 | 302 | * @param WP_REST_Request $request Request used to generate the response. |
303 | 303 | */ |
304 | - return apply_filters( 'woocommerce_rest_prepare_admin_note', $response, $data, $request ); |
|
304 | + return apply_filters('woocommerce_rest_prepare_admin_note', $response, $data, $request); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -311,16 +311,16 @@ discard block |
||
311 | 311 | */ |
312 | 312 | public function get_collection_params() { |
313 | 313 | $params = array(); |
314 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
314 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
315 | 315 | $params['order'] = array( |
316 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
316 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
317 | 317 | 'type' => 'string', |
318 | 318 | 'default' => 'desc', |
319 | - 'enum' => array( 'asc', 'desc' ), |
|
319 | + 'enum' => array('asc', 'desc'), |
|
320 | 320 | 'validate_callback' => 'rest_validate_request_arg', |
321 | 321 | ); |
322 | - $params['orderby'] = array( |
|
323 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
322 | + $params['orderby'] = array( |
|
323 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
324 | 324 | 'type' => 'string', |
325 | 325 | 'default' => 'date', |
326 | 326 | 'enum' => array( |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | ), |
333 | 333 | 'validate_callback' => 'rest_validate_request_arg', |
334 | 334 | ); |
335 | - $params['page'] = array( |
|
336 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
335 | + $params['page'] = array( |
|
336 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
337 | 337 | 'type' => 'integer', |
338 | 338 | 'default' => 1, |
339 | 339 | 'sanitize_callback' => 'absint', |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | 'minimum' => 1, |
342 | 342 | ); |
343 | 343 | $params['per_page'] = array( |
344 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
344 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
345 | 345 | 'type' => 'integer', |
346 | 346 | 'default' => 10, |
347 | 347 | 'minimum' => 1, |
@@ -349,8 +349,8 @@ discard block |
||
349 | 349 | 'sanitize_callback' => 'absint', |
350 | 350 | 'validate_callback' => 'rest_validate_request_arg', |
351 | 351 | ); |
352 | - $params['type'] = array( |
|
353 | - 'description' => __( 'Type of note.', 'woocommerce' ), |
|
352 | + $params['type'] = array( |
|
353 | + 'description' => __('Type of note.', 'woocommerce'), |
|
354 | 354 | 'type' => 'array', |
355 | 355 | 'sanitize_callback' => 'wp_parse_slug_list', |
356 | 356 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -359,8 +359,8 @@ discard block |
||
359 | 359 | 'type' => 'string', |
360 | 360 | ), |
361 | 361 | ); |
362 | - $params['status'] = array( |
|
363 | - 'description' => __( 'Status of note.', 'woocommerce' ), |
|
362 | + $params['status'] = array( |
|
363 | + 'description' => __('Status of note.', 'woocommerce'), |
|
364 | 364 | 'type' => 'array', |
365 | 365 | 'sanitize_callback' => 'wp_parse_slug_list', |
366 | 366 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -384,102 +384,102 @@ discard block |
||
384 | 384 | 'type' => 'object', |
385 | 385 | 'properties' => array( |
386 | 386 | 'id' => array( |
387 | - 'description' => __( 'ID of the note record.', 'woocommerce' ), |
|
387 | + 'description' => __('ID of the note record.', 'woocommerce'), |
|
388 | 388 | 'type' => 'integer', |
389 | - 'context' => array( 'view' ), |
|
389 | + 'context' => array('view'), |
|
390 | 390 | 'readonly' => true, |
391 | 391 | ), |
392 | 392 | 'name' => array( |
393 | - 'description' => __( 'Name of the note.', 'woocommerce' ), |
|
393 | + 'description' => __('Name of the note.', 'woocommerce'), |
|
394 | 394 | 'type' => 'string', |
395 | - 'context' => array( 'view', 'edit' ), |
|
395 | + 'context' => array('view', 'edit'), |
|
396 | 396 | 'readonly' => true, |
397 | 397 | ), |
398 | 398 | 'type' => array( |
399 | - 'description' => __( 'The type of the note (e.g. error, warning, etc.).', 'woocommerce' ), |
|
399 | + 'description' => __('The type of the note (e.g. error, warning, etc.).', 'woocommerce'), |
|
400 | 400 | 'type' => 'string', |
401 | - 'context' => array( 'view', 'edit' ), |
|
401 | + 'context' => array('view', 'edit'), |
|
402 | 402 | 'readonly' => true, |
403 | 403 | ), |
404 | 404 | 'locale' => array( |
405 | - 'description' => __( 'Locale used for the note title and content.', 'woocommerce' ), |
|
405 | + 'description' => __('Locale used for the note title and content.', 'woocommerce'), |
|
406 | 406 | 'type' => 'string', |
407 | - 'context' => array( 'view', 'edit' ), |
|
407 | + 'context' => array('view', 'edit'), |
|
408 | 408 | 'readonly' => true, |
409 | 409 | ), |
410 | 410 | 'title' => array( |
411 | - 'description' => __( 'Title of the note.', 'woocommerce' ), |
|
411 | + 'description' => __('Title of the note.', 'woocommerce'), |
|
412 | 412 | 'type' => 'string', |
413 | - 'context' => array( 'view', 'edit' ), |
|
413 | + 'context' => array('view', 'edit'), |
|
414 | 414 | 'readonly' => true, |
415 | 415 | ), |
416 | 416 | 'content' => array( |
417 | - 'description' => __( 'Content of the note.', 'woocommerce' ), |
|
417 | + 'description' => __('Content of the note.', 'woocommerce'), |
|
418 | 418 | 'type' => 'string', |
419 | - 'context' => array( 'view', 'edit' ), |
|
419 | + 'context' => array('view', 'edit'), |
|
420 | 420 | 'readonly' => true, |
421 | 421 | ), |
422 | 422 | 'icon' => array( |
423 | - 'description' => __( 'Icon (gridicon) for the note.', 'woocommerce' ), |
|
423 | + 'description' => __('Icon (gridicon) for the note.', 'woocommerce'), |
|
424 | 424 | 'type' => 'string', |
425 | - 'context' => array( 'view', 'edit' ), |
|
425 | + 'context' => array('view', 'edit'), |
|
426 | 426 | 'readonly' => true, |
427 | 427 | ), |
428 | 428 | 'content_data' => array( |
429 | - 'description' => __( 'Content data for the note. JSON string. Available for re-localization.', 'woocommerce' ), |
|
429 | + 'description' => __('Content data for the note. JSON string. Available for re-localization.', 'woocommerce'), |
|
430 | 430 | 'type' => 'string', |
431 | - 'context' => array( 'view', 'edit' ), |
|
431 | + 'context' => array('view', 'edit'), |
|
432 | 432 | 'readonly' => true, |
433 | 433 | ), |
434 | 434 | 'status' => array( |
435 | - 'description' => __( 'The status of the note (e.g. unactioned, actioned).', 'woocommerce' ), |
|
435 | + 'description' => __('The status of the note (e.g. unactioned, actioned).', 'woocommerce'), |
|
436 | 436 | 'type' => 'string', |
437 | - 'context' => array( 'view', 'edit' ), |
|
437 | + 'context' => array('view', 'edit'), |
|
438 | 438 | ), |
439 | 439 | 'source' => array( |
440 | - 'description' => __( 'Source of the note.', 'woocommerce' ), |
|
440 | + 'description' => __('Source of the note.', 'woocommerce'), |
|
441 | 441 | 'type' => 'string', |
442 | - 'context' => array( 'view', 'edit' ), |
|
442 | + 'context' => array('view', 'edit'), |
|
443 | 443 | 'readonly' => true, |
444 | 444 | ), |
445 | 445 | 'date_created' => array( |
446 | - 'description' => __( 'Date the note was created.', 'woocommerce' ), |
|
446 | + 'description' => __('Date the note was created.', 'woocommerce'), |
|
447 | 447 | 'type' => 'string', |
448 | - 'context' => array( 'view', 'edit' ), |
|
448 | + 'context' => array('view', 'edit'), |
|
449 | 449 | 'readonly' => true, |
450 | 450 | ), |
451 | 451 | 'date_created_gmt' => array( |
452 | - 'description' => __( 'Date the note was created (GMT).', 'woocommerce' ), |
|
452 | + 'description' => __('Date the note was created (GMT).', 'woocommerce'), |
|
453 | 453 | 'type' => 'string', |
454 | - 'context' => array( 'view', 'edit' ), |
|
454 | + 'context' => array('view', 'edit'), |
|
455 | 455 | 'readonly' => true, |
456 | 456 | ), |
457 | 457 | 'date_reminder' => array( |
458 | - 'description' => __( 'Date after which the user should be reminded of the note, if any.', 'woocommerce' ), |
|
458 | + 'description' => __('Date after which the user should be reminded of the note, if any.', 'woocommerce'), |
|
459 | 459 | 'type' => 'string', |
460 | - 'context' => array( 'view', 'edit' ), |
|
460 | + 'context' => array('view', 'edit'), |
|
461 | 461 | 'readonly' => true, |
462 | 462 | ), |
463 | 463 | 'date_reminder_gmt' => array( |
464 | - 'description' => __( 'Date after which the user should be reminded of the note, if any (GMT).', 'woocommerce' ), |
|
464 | + 'description' => __('Date after which the user should be reminded of the note, if any (GMT).', 'woocommerce'), |
|
465 | 465 | 'type' => 'string', |
466 | - 'context' => array( 'view', 'edit' ), |
|
466 | + 'context' => array('view', 'edit'), |
|
467 | 467 | 'readonly' => true, |
468 | 468 | ), |
469 | 469 | 'is_snoozable' => array( |
470 | - 'description' => __( 'Whether or a user can request to be reminded about the note.', 'woocommerce' ), |
|
470 | + 'description' => __('Whether or a user can request to be reminded about the note.', 'woocommerce'), |
|
471 | 471 | 'type' => 'boolean', |
472 | - 'context' => array( 'view', 'edit' ), |
|
472 | + 'context' => array('view', 'edit'), |
|
473 | 473 | 'readonly' => true, |
474 | 474 | ), |
475 | 475 | 'actions' => array( |
476 | - 'description' => __( 'An array of actions, if any, for the note.', 'woocommerce' ), |
|
476 | + 'description' => __('An array of actions, if any, for the note.', 'woocommerce'), |
|
477 | 477 | 'type' => 'array', |
478 | - 'context' => array( 'view', 'edit' ), |
|
478 | + 'context' => array('view', 'edit'), |
|
479 | 479 | 'readonly' => true, |
480 | 480 | ), |
481 | 481 | ), |
482 | 482 | ); |
483 | - return $this->add_additional_fields_schema( $schema ); |
|
483 | + return $this->add_additional_fields_schema($schema); |
|
484 | 484 | } |
485 | 485 | } |
@@ -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 Order Refunds controller class. |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * Order refunds actions. |
42 | 42 | */ |
43 | 43 | public function __construct() { |
44 | - add_filter( "woocommerce_rest_{$this->post_type}_object_trashable", '__return_false' ); |
|
44 | + add_filter("woocommerce_rest_{$this->post_type}_object_trashable", '__return_false'); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -54,23 +54,23 @@ discard block |
||
54 | 54 | array( |
55 | 55 | 'args' => array( |
56 | 56 | 'order_id' => array( |
57 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
57 | + 'description' => __('The order ID.', 'woocommerce'), |
|
58 | 58 | 'type' => 'integer', |
59 | 59 | ), |
60 | 60 | ), |
61 | 61 | array( |
62 | 62 | 'methods' => \WP_REST_Server::READABLE, |
63 | - 'callback' => array( $this, 'get_items' ), |
|
64 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
63 | + 'callback' => array($this, 'get_items'), |
|
64 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
65 | 65 | 'args' => $this->get_collection_params(), |
66 | 66 | ), |
67 | 67 | array( |
68 | 68 | 'methods' => \WP_REST_Server::CREATABLE, |
69 | - 'callback' => array( $this, 'create_item' ), |
|
70 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
71 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
69 | + 'callback' => array($this, 'create_item'), |
|
70 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
71 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
72 | 72 | ), |
73 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
73 | + 'schema' => array($this, 'get_public_item_schema'), |
|
74 | 74 | ), |
75 | 75 | true |
76 | 76 | ); |
@@ -81,35 +81,35 @@ discard block |
||
81 | 81 | array( |
82 | 82 | 'args' => array( |
83 | 83 | 'order_id' => array( |
84 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
84 | + 'description' => __('The order ID.', 'woocommerce'), |
|
85 | 85 | 'type' => 'integer', |
86 | 86 | ), |
87 | 87 | 'id' => array( |
88 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
88 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
89 | 89 | 'type' => 'integer', |
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | array( |
93 | 93 | 'methods' => \WP_REST_Server::READABLE, |
94 | - 'callback' => array( $this, 'get_item' ), |
|
95 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
94 | + 'callback' => array($this, 'get_item'), |
|
95 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
96 | 96 | 'args' => array( |
97 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
97 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
98 | 98 | ), |
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' => true, |
107 | 107 | 'type' => 'boolean', |
108 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
108 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
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 | ); |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @param int $id Object ID. |
123 | 123 | * @return WC_Data |
124 | 124 | */ |
125 | - protected function get_object( $id ) { |
|
126 | - return wc_get_order( $id ); |
|
125 | + protected function get_object($id) { |
|
126 | + return wc_get_order($id); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -133,27 +133,27 @@ discard block |
||
133 | 133 | * @param WC_Data $object WC_Data instance. |
134 | 134 | * @return array |
135 | 135 | */ |
136 | - protected function get_formatted_item_data( $object ) { |
|
136 | + protected function get_formatted_item_data($object) { |
|
137 | 137 | $data = $object->get_data(); |
138 | - $format_decimal = array( 'amount' ); |
|
139 | - $format_date = array( 'date_created' ); |
|
140 | - $format_line_items = array( 'line_items' ); |
|
138 | + $format_decimal = array('amount'); |
|
139 | + $format_date = array('date_created'); |
|
140 | + $format_line_items = array('line_items'); |
|
141 | 141 | |
142 | 142 | // Format decimal values. |
143 | - foreach ( $format_decimal as $key ) { |
|
144 | - $data[ $key ] = wc_format_decimal( $data[ $key ], $this->request['dp'] ); |
|
143 | + foreach ($format_decimal as $key) { |
|
144 | + $data[$key] = wc_format_decimal($data[$key], $this->request['dp']); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | // Format date values. |
148 | - foreach ( $format_date as $key ) { |
|
149 | - $datetime = $data[ $key ]; |
|
150 | - $data[ $key ] = wc_rest_prepare_date_response( $datetime, false ); |
|
151 | - $data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime ); |
|
148 | + foreach ($format_date as $key) { |
|
149 | + $datetime = $data[$key]; |
|
150 | + $data[$key] = wc_rest_prepare_date_response($datetime, false); |
|
151 | + $data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Format line items. |
155 | - foreach ( $format_line_items as $key ) { |
|
156 | - $data[ $key ] = array_values( array_map( array( $this, 'get_order_item_data' ), $data[ $key ] ) ); |
|
155 | + foreach ($format_line_items as $key) { |
|
156 | + $data[$key] = array_values(array_map(array($this, 'get_order_item_data'), $data[$key])); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | return array( |
@@ -179,28 +179,28 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return \WP_Error\WP_REST_Response |
181 | 181 | */ |
182 | - public function prepare_object_for_response( $object, $request ) { |
|
182 | + public function prepare_object_for_response($object, $request) { |
|
183 | 183 | $this->request = $request; |
184 | - $this->request['dp'] = is_null( $this->request['dp'] ) ? wc_get_price_decimals() : absint( $this->request['dp'] ); |
|
185 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
184 | + $this->request['dp'] = is_null($this->request['dp']) ? wc_get_price_decimals() : absint($this->request['dp']); |
|
185 | + $order = wc_get_order((int) $request['order_id']); |
|
186 | 186 | |
187 | - if ( ! $order ) { |
|
188 | - return new \WP_Error( 'woocommerce_rest_invalid_order_id', __( 'Invalid order ID.', 'woocommerce' ), 404 ); |
|
187 | + if ( ! $order) { |
|
188 | + return new \WP_Error('woocommerce_rest_invalid_order_id', __('Invalid order ID.', 'woocommerce'), 404); |
|
189 | 189 | } |
190 | 190 | |
191 | - if ( ! $object || $object->get_parent_id() !== $order->get_id() ) { |
|
192 | - return new \WP_Error( 'woocommerce_rest_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 404 ); |
|
191 | + if ( ! $object || $object->get_parent_id() !== $order->get_id()) { |
|
192 | + return new \WP_Error('woocommerce_rest_invalid_order_refund_id', __('Invalid order refund ID.', 'woocommerce'), 404); |
|
193 | 193 | } |
194 | 194 | |
195 | - $data = $this->get_formatted_item_data( $object ); |
|
196 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
197 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
198 | - $data = $this->filter_response_by_context( $data, $context ); |
|
195 | + $data = $this->get_formatted_item_data($object); |
|
196 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
197 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
198 | + $data = $this->filter_response_by_context($data, $context); |
|
199 | 199 | |
200 | 200 | // Wrap the data in a response object. |
201 | - $response = rest_ensure_response( $data ); |
|
201 | + $response = rest_ensure_response($data); |
|
202 | 202 | |
203 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
203 | + $response->add_links($this->prepare_links($object, $request)); |
|
204 | 204 | |
205 | 205 | /** |
206 | 206 | * Filter the data for a response. |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @param WC_Data $object Object data. |
213 | 213 | * @param \WP_REST_Request $request Request object. |
214 | 214 | */ |
215 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
215 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -223,38 +223,38 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return \WP_Error\WP_REST_Response |
225 | 225 | */ |
226 | - public function prepare_item_for_response( $post, $request ) { |
|
227 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
226 | + public function prepare_item_for_response($post, $request) { |
|
227 | + $order = wc_get_order((int) $request['order_id']); |
|
228 | 228 | |
229 | - if ( ! $order ) { |
|
230 | - return new \WP_Error( 'woocommerce_rest_invalid_order_id', __( 'Invalid order ID.', 'woocommerce' ), 404 ); |
|
229 | + if ( ! $order) { |
|
230 | + return new \WP_Error('woocommerce_rest_invalid_order_id', __('Invalid order ID.', 'woocommerce'), 404); |
|
231 | 231 | } |
232 | 232 | |
233 | - $refund = wc_get_order( $post ); |
|
233 | + $refund = wc_get_order($post); |
|
234 | 234 | |
235 | - if ( ! $refund || $refund->get_parent_id() !== $order->get_id() ) { |
|
236 | - return new \WP_Error( 'woocommerce_rest_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 404 ); |
|
235 | + if ( ! $refund || $refund->get_parent_id() !== $order->get_id()) { |
|
236 | + return new \WP_Error('woocommerce_rest_invalid_order_refund_id', __('Invalid order refund ID.', 'woocommerce'), 404); |
|
237 | 237 | } |
238 | 238 | |
239 | - $dp = is_null( $request['dp'] ) ? wc_get_price_decimals() : absint( $request['dp'] ); |
|
239 | + $dp = is_null($request['dp']) ? wc_get_price_decimals() : absint($request['dp']); |
|
240 | 240 | |
241 | 241 | $data = array( |
242 | 242 | 'id' => $refund->get_id(), |
243 | - 'date_created' => wc_rest_prepare_date_response( $refund->get_date_created() ), |
|
244 | - 'amount' => wc_format_decimal( $refund->get_amount(), $dp ), |
|
243 | + 'date_created' => wc_rest_prepare_date_response($refund->get_date_created()), |
|
244 | + 'amount' => wc_format_decimal($refund->get_amount(), $dp), |
|
245 | 245 | 'reason' => $refund->get_reason(), |
246 | 246 | 'line_items' => array(), |
247 | 247 | ); |
248 | 248 | |
249 | 249 | // Add line items. |
250 | - foreach ( $refund->get_items() as $item_id => $item ) { |
|
251 | - $product = $refund->get_product_from_item( $item ); |
|
250 | + foreach ($refund->get_items() as $item_id => $item) { |
|
251 | + $product = $refund->get_product_from_item($item); |
|
252 | 252 | $product_id = 0; |
253 | 253 | $variation_id = 0; |
254 | 254 | $product_sku = null; |
255 | 255 | |
256 | 256 | // Check if the product exists. |
257 | - if ( is_object( $product ) ) { |
|
257 | + if (is_object($product)) { |
|
258 | 258 | $product_id = $item->get_product_id(); |
259 | 259 | $variation_id = $item->get_variation_id(); |
260 | 260 | $product_sku = $product->get_sku(); |
@@ -264,11 +264,11 @@ discard block |
||
264 | 264 | |
265 | 265 | $hideprefix = 'true' === $request['all_item_meta'] ? null : '_'; |
266 | 266 | |
267 | - foreach ( $item->get_formatted_meta_data( $hideprefix, true ) as $meta_key => $formatted_meta ) { |
|
267 | + foreach ($item->get_formatted_meta_data($hideprefix, true) as $meta_key => $formatted_meta) { |
|
268 | 268 | $item_meta[] = array( |
269 | 269 | 'key' => $formatted_meta->key, |
270 | 270 | 'label' => $formatted_meta->display_key, |
271 | - 'value' => wc_clean( $formatted_meta->display_value ), |
|
271 | + 'value' => wc_clean($formatted_meta->display_value), |
|
272 | 272 | ); |
273 | 273 | } |
274 | 274 | |
@@ -278,47 +278,47 @@ discard block |
||
278 | 278 | 'sku' => $product_sku, |
279 | 279 | 'product_id' => (int) $product_id, |
280 | 280 | 'variation_id' => (int) $variation_id, |
281 | - 'quantity' => wc_stock_amount( $item['qty'] ), |
|
282 | - 'tax_class' => ! empty( $item['tax_class'] ) ? $item['tax_class'] : '', |
|
283 | - 'price' => wc_format_decimal( $refund->get_item_total( $item, false, false ), $dp ), |
|
284 | - 'subtotal' => wc_format_decimal( $refund->get_line_subtotal( $item, false, false ), $dp ), |
|
285 | - 'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $dp ), |
|
286 | - 'total' => wc_format_decimal( $refund->get_line_total( $item, false, false ), $dp ), |
|
287 | - 'total_tax' => wc_format_decimal( $item['line_tax'], $dp ), |
|
281 | + 'quantity' => wc_stock_amount($item['qty']), |
|
282 | + 'tax_class' => ! empty($item['tax_class']) ? $item['tax_class'] : '', |
|
283 | + 'price' => wc_format_decimal($refund->get_item_total($item, false, false), $dp), |
|
284 | + 'subtotal' => wc_format_decimal($refund->get_line_subtotal($item, false, false), $dp), |
|
285 | + 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), |
|
286 | + 'total' => wc_format_decimal($refund->get_line_total($item, false, false), $dp), |
|
287 | + 'total_tax' => wc_format_decimal($item['line_tax'], $dp), |
|
288 | 288 | 'taxes' => array(), |
289 | 289 | 'meta' => $item_meta, |
290 | 290 | ); |
291 | 291 | |
292 | - $item_line_taxes = maybe_unserialize( $item['line_tax_data'] ); |
|
293 | - if ( isset( $item_line_taxes['total'] ) ) { |
|
292 | + $item_line_taxes = maybe_unserialize($item['line_tax_data']); |
|
293 | + if (isset($item_line_taxes['total'])) { |
|
294 | 294 | $line_tax = array(); |
295 | 295 | |
296 | - foreach ( $item_line_taxes['total'] as $tax_rate_id => $tax ) { |
|
297 | - $line_tax[ $tax_rate_id ] = array( |
|
296 | + foreach ($item_line_taxes['total'] as $tax_rate_id => $tax) { |
|
297 | + $line_tax[$tax_rate_id] = array( |
|
298 | 298 | 'id' => $tax_rate_id, |
299 | 299 | 'total' => $tax, |
300 | 300 | 'subtotal' => '', |
301 | 301 | ); |
302 | 302 | } |
303 | 303 | |
304 | - foreach ( $item_line_taxes['subtotal'] as $tax_rate_id => $tax ) { |
|
305 | - $line_tax[ $tax_rate_id ]['subtotal'] = $tax; |
|
304 | + foreach ($item_line_taxes['subtotal'] as $tax_rate_id => $tax) { |
|
305 | + $line_tax[$tax_rate_id]['subtotal'] = $tax; |
|
306 | 306 | } |
307 | 307 | |
308 | - $line_item['taxes'] = array_values( $line_tax ); |
|
308 | + $line_item['taxes'] = array_values($line_tax); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | $data['line_items'][] = $line_item; |
312 | 312 | } |
313 | 313 | |
314 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
315 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
316 | - $data = $this->filter_response_by_context( $data, $context ); |
|
314 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
315 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
316 | + $data = $this->filter_response_by_context($data, $context); |
|
317 | 317 | |
318 | 318 | // Wrap the data in a response object. |
319 | - $response = rest_ensure_response( $data ); |
|
319 | + $response = rest_ensure_response($data); |
|
320 | 320 | |
321 | - $response->add_links( $this->prepare_links( $refund, $request ) ); |
|
321 | + $response->add_links($this->prepare_links($refund, $request)); |
|
322 | 322 | |
323 | 323 | /** |
324 | 324 | * Filter the data for a response. |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @param WP_Post $post Post object. |
331 | 331 | * @param \WP_REST_Request $request Request object. |
332 | 332 | */ |
333 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request ); |
|
333 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -340,17 +340,17 @@ discard block |
||
340 | 340 | * @param \WP_REST_Request $request Request object. |
341 | 341 | * @return array Links for the given post. |
342 | 342 | */ |
343 | - protected function prepare_links( $object, $request ) { |
|
344 | - $base = str_replace( '(?P<order_id>[\d]+)', $object->get_parent_id(), $this->rest_base ); |
|
343 | + protected function prepare_links($object, $request) { |
|
344 | + $base = str_replace('(?P<order_id>[\d]+)', $object->get_parent_id(), $this->rest_base); |
|
345 | 345 | $links = array( |
346 | 346 | 'self' => array( |
347 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $object->get_id() ) ), |
|
347 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $object->get_id())), |
|
348 | 348 | ), |
349 | 349 | 'collection' => array( |
350 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
350 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
351 | 351 | ), |
352 | 352 | 'up' => array( |
353 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $object->get_parent_id() ) ), |
|
353 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $object->get_parent_id())), |
|
354 | 354 | ), |
355 | 355 | ); |
356 | 356 | |
@@ -364,11 +364,11 @@ discard block |
||
364 | 364 | * @param \WP_REST_Request $request Full details about the request. |
365 | 365 | * @return array |
366 | 366 | */ |
367 | - protected function prepare_objects_query( $request ) { |
|
368 | - $args = parent::prepare_objects_query( $request ); |
|
367 | + protected function prepare_objects_query($request) { |
|
368 | + $args = parent::prepare_objects_query($request); |
|
369 | 369 | |
370 | - $args['post_status'] = array_keys( wc_get_order_statuses() ); |
|
371 | - $args['post_parent__in'] = array( absint( $request['order_id'] ) ); |
|
370 | + $args['post_status'] = array_keys(wc_get_order_statuses()); |
|
371 | + $args['post_parent__in'] = array(absint($request['order_id'])); |
|
372 | 372 | |
373 | 373 | return $args; |
374 | 374 | } |
@@ -379,20 +379,20 @@ discard block |
||
379 | 379 | * @param \WP_REST_Request $request Full details about the request. |
380 | 380 | * @return \WP_Error\WP_REST_Response |
381 | 381 | */ |
382 | - public function create_item( $request ) { |
|
383 | - if ( ! empty( $request['id'] ) ) { |
|
382 | + public function create_item($request) { |
|
383 | + if ( ! empty($request['id'])) { |
|
384 | 384 | /* translators: %s: post type */ |
385 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
385 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
386 | 386 | } |
387 | 387 | |
388 | - $order_data = get_post( (int) $request['order_id'] ); |
|
388 | + $order_data = get_post((int) $request['order_id']); |
|
389 | 389 | |
390 | - if ( empty( $order_data ) ) { |
|
391 | - return new \WP_Error( 'woocommerce_rest_invalid_order', __( 'Order is invalid', 'woocommerce' ), 400 ); |
|
390 | + if (empty($order_data)) { |
|
391 | + return new \WP_Error('woocommerce_rest_invalid_order', __('Order is invalid', 'woocommerce'), 400); |
|
392 | 392 | } |
393 | 393 | |
394 | - if ( 0 > $request['amount'] ) { |
|
395 | - return new \WP_Error( 'woocommerce_rest_invalid_order_refund', __( 'Refund amount must be greater than zero.', 'woocommerce' ), 400 ); |
|
394 | + if (0 > $request['amount']) { |
|
395 | + return new \WP_Error('woocommerce_rest_invalid_order_refund', __('Refund amount must be greater than zero.', 'woocommerce'), 400); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | // Create the refund. |
@@ -400,22 +400,22 @@ discard block |
||
400 | 400 | array( |
401 | 401 | 'order_id' => $order_data->ID, |
402 | 402 | 'amount' => $request['amount'], |
403 | - 'reason' => empty( $request['reason'] ) ? null : $request['reason'], |
|
404 | - 'refund_payment' => is_bool( $request['api_refund'] ) ? $request['api_refund'] : true, |
|
403 | + 'reason' => empty($request['reason']) ? null : $request['reason'], |
|
404 | + 'refund_payment' => is_bool($request['api_refund']) ? $request['api_refund'] : true, |
|
405 | 405 | 'restock_items' => true, |
406 | 406 | ) |
407 | 407 | ); |
408 | 408 | |
409 | - if ( is_wp_error( $refund ) ) { |
|
410 | - return new \WP_Error( 'woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500 ); |
|
409 | + if (is_wp_error($refund)) { |
|
410 | + return new \WP_Error('woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500); |
|
411 | 411 | } |
412 | 412 | |
413 | - if ( ! $refund ) { |
|
414 | - return new \WP_Error( 'woocommerce_rest_cannot_create_order_refund', __( 'Cannot create order refund, please try again.', 'woocommerce' ), 500 ); |
|
413 | + if ( ! $refund) { |
|
414 | + return new \WP_Error('woocommerce_rest_cannot_create_order_refund', __('Cannot create order refund, please try again.', 'woocommerce'), 500); |
|
415 | 415 | } |
416 | 416 | |
417 | - $post = get_post( $refund->get_id() ); |
|
418 | - $this->update_additional_fields_for_object( $post, $request ); |
|
417 | + $post = get_post($refund->get_id()); |
|
418 | + $this->update_additional_fields_for_object($post, $request); |
|
419 | 419 | |
420 | 420 | /** |
421 | 421 | * Fires after a single item is created or updated via the REST API. |
@@ -424,13 +424,13 @@ discard block |
||
424 | 424 | * @param \WP_REST_Request $request Request object. |
425 | 425 | * @param boolean $creating True when creating item, false when updating. |
426 | 426 | */ |
427 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true ); |
|
427 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true); |
|
428 | 428 | |
429 | - $request->set_param( 'context', 'edit' ); |
|
430 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
431 | - $response = rest_ensure_response( $response ); |
|
432 | - $response->set_status( 201 ); |
|
433 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ) ); |
|
429 | + $request->set_param('context', 'edit'); |
|
430 | + $response = $this->prepare_item_for_response($post, $request); |
|
431 | + $response = rest_ensure_response($response); |
|
432 | + $response->set_status(201); |
|
433 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID))); |
|
434 | 434 | |
435 | 435 | return $response; |
436 | 436 | } |
@@ -443,15 +443,15 @@ discard block |
||
443 | 443 | * @param bool $creating If is creating a new object. |
444 | 444 | * @return \WP_Error|WC_Data The prepared item, or \WP_Error object on failure. |
445 | 445 | */ |
446 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
447 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
446 | + protected function prepare_object_for_database($request, $creating = false) { |
|
447 | + $order = wc_get_order((int) $request['order_id']); |
|
448 | 448 | |
449 | - if ( ! $order ) { |
|
450 | - return new \WP_Error( 'woocommerce_rest_invalid_order_id', __( 'Invalid order ID.', 'woocommerce' ), 404 ); |
|
449 | + if ( ! $order) { |
|
450 | + return new \WP_Error('woocommerce_rest_invalid_order_id', __('Invalid order ID.', 'woocommerce'), 404); |
|
451 | 451 | } |
452 | 452 | |
453 | - if ( 0 > $request['amount'] ) { |
|
454 | - return new \WP_Error( 'woocommerce_rest_invalid_order_refund', __( 'Refund amount must be greater than zero.', 'woocommerce' ), 400 ); |
|
453 | + if (0 > $request['amount']) { |
|
454 | + return new \WP_Error('woocommerce_rest_invalid_order_refund', __('Refund amount must be greater than zero.', 'woocommerce'), 400); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | // Create the refund. |
@@ -459,24 +459,24 @@ discard block |
||
459 | 459 | array( |
460 | 460 | 'order_id' => $order->get_id(), |
461 | 461 | 'amount' => $request['amount'], |
462 | - 'reason' => empty( $request['reason'] ) ? null : $request['reason'], |
|
463 | - 'line_items' => empty( $request['line_items'] ) ? array() : $request['line_items'], |
|
464 | - 'refund_payment' => is_bool( $request['api_refund'] ) ? $request['api_refund'] : true, |
|
462 | + 'reason' => empty($request['reason']) ? null : $request['reason'], |
|
463 | + 'line_items' => empty($request['line_items']) ? array() : $request['line_items'], |
|
464 | + 'refund_payment' => is_bool($request['api_refund']) ? $request['api_refund'] : true, |
|
465 | 465 | 'restock_items' => true, |
466 | 466 | ) |
467 | 467 | ); |
468 | 468 | |
469 | - if ( is_wp_error( $refund ) ) { |
|
470 | - return new \WP_Error( 'woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500 ); |
|
469 | + if (is_wp_error($refund)) { |
|
470 | + return new \WP_Error('woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500); |
|
471 | 471 | } |
472 | 472 | |
473 | - if ( ! $refund ) { |
|
474 | - return new \WP_Error( 'woocommerce_rest_cannot_create_order_refund', __( 'Cannot create order refund, please try again.', 'woocommerce' ), 500 ); |
|
473 | + if ( ! $refund) { |
|
474 | + return new \WP_Error('woocommerce_rest_cannot_create_order_refund', __('Cannot create order refund, please try again.', 'woocommerce'), 500); |
|
475 | 475 | } |
476 | 476 | |
477 | - if ( ! empty( $request['meta_data'] ) && is_array( $request['meta_data'] ) ) { |
|
478 | - foreach ( $request['meta_data'] as $meta ) { |
|
479 | - $refund->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
477 | + if ( ! empty($request['meta_data']) && is_array($request['meta_data'])) { |
|
478 | + foreach ($request['meta_data'] as $meta) { |
|
479 | + $refund->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
480 | 480 | } |
481 | 481 | $refund->save_meta_data(); |
482 | 482 | } |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | * @param \WP_REST_Request $request Request object. |
492 | 492 | * @param bool $creating If is creating a new object. |
493 | 493 | */ |
494 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $refund, $request, $creating ); |
|
494 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $refund, $request, $creating); |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | /** |
@@ -502,19 +502,19 @@ discard block |
||
502 | 502 | * @param bool $creating If is creating a new object. |
503 | 503 | * @return \WC_Data|\WP_Error |
504 | 504 | */ |
505 | - protected function save_object( $request, $creating = false ) { |
|
505 | + protected function save_object($request, $creating = false) { |
|
506 | 506 | try { |
507 | - $object = $this->prepare_object_for_database( $request, $creating ); |
|
507 | + $object = $this->prepare_object_for_database($request, $creating); |
|
508 | 508 | |
509 | - if ( is_wp_error( $object ) ) { |
|
509 | + if (is_wp_error($object)) { |
|
510 | 510 | return $object; |
511 | 511 | } |
512 | 512 | |
513 | - return $this->get_object( $object->get_id() ); |
|
514 | - } catch ( \WC_Data_Exception $e ) { |
|
515 | - return new \WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
516 | - } catch ( \WC_REST_Exception $e ) { |
|
517 | - return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
513 | + return $this->get_object($object->get_id()); |
|
514 | + } catch (\WC_Data_Exception $e) { |
|
515 | + return new \WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData()); |
|
516 | + } catch (\WC_REST_Exception $e) { |
|
517 | + return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
518 | 518 | } |
519 | 519 | } |
520 | 520 | |
@@ -530,221 +530,221 @@ discard block |
||
530 | 530 | 'type' => 'object', |
531 | 531 | 'properties' => array( |
532 | 532 | 'id' => array( |
533 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
533 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
534 | 534 | 'type' => 'integer', |
535 | - 'context' => array( 'view', 'edit' ), |
|
535 | + 'context' => array('view', 'edit'), |
|
536 | 536 | 'readonly' => true, |
537 | 537 | ), |
538 | 538 | 'date_created' => array( |
539 | - 'description' => __( "The date the order refund was created, in the site's timezone.", 'woocommerce' ), |
|
539 | + 'description' => __("The date the order refund was created, in the site's timezone.", 'woocommerce'), |
|
540 | 540 | 'type' => 'date-time', |
541 | - 'context' => array( 'view', 'edit' ), |
|
541 | + 'context' => array('view', 'edit'), |
|
542 | 542 | 'readonly' => true, |
543 | 543 | ), |
544 | 544 | 'date_created_gmt' => array( |
545 | - 'description' => __( 'The date the order refund was created, as GMT.', 'woocommerce' ), |
|
545 | + 'description' => __('The date the order refund was created, as GMT.', 'woocommerce'), |
|
546 | 546 | 'type' => 'date-time', |
547 | - 'context' => array( 'view', 'edit' ), |
|
547 | + 'context' => array('view', 'edit'), |
|
548 | 548 | 'readonly' => true, |
549 | 549 | ), |
550 | 550 | 'amount' => array( |
551 | - 'description' => __( 'Refund amount.', 'woocommerce' ), |
|
551 | + 'description' => __('Refund amount.', 'woocommerce'), |
|
552 | 552 | 'type' => 'string', |
553 | - 'context' => array( 'view', 'edit' ), |
|
553 | + 'context' => array('view', 'edit'), |
|
554 | 554 | ), |
555 | 555 | 'reason' => array( |
556 | - 'description' => __( 'Reason for refund.', 'woocommerce' ), |
|
556 | + 'description' => __('Reason for refund.', 'woocommerce'), |
|
557 | 557 | 'type' => 'string', |
558 | - 'context' => array( 'view', 'edit' ), |
|
558 | + 'context' => array('view', 'edit'), |
|
559 | 559 | ), |
560 | 560 | 'refunded_by' => array( |
561 | - 'description' => __( 'User ID of user who created the refund.', 'woocommerce' ), |
|
561 | + 'description' => __('User ID of user who created the refund.', 'woocommerce'), |
|
562 | 562 | 'type' => 'integer', |
563 | - 'context' => array( 'view', 'edit' ), |
|
563 | + 'context' => array('view', 'edit'), |
|
564 | 564 | ), |
565 | 565 | 'refunded_payment' => array( |
566 | - 'description' => __( 'If the payment was refunded via the API.', 'woocommerce' ), |
|
566 | + 'description' => __('If the payment was refunded via the API.', 'woocommerce'), |
|
567 | 567 | 'type' => 'boolean', |
568 | - 'context' => array( 'view' ), |
|
568 | + 'context' => array('view'), |
|
569 | 569 | 'readonly' => true, |
570 | 570 | ), |
571 | 571 | 'meta_data' => array( |
572 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
572 | + 'description' => __('Meta data.', 'woocommerce'), |
|
573 | 573 | 'type' => 'array', |
574 | - 'context' => array( 'view', 'edit' ), |
|
574 | + 'context' => array('view', 'edit'), |
|
575 | 575 | 'items' => array( |
576 | 576 | 'type' => 'object', |
577 | 577 | 'properties' => array( |
578 | 578 | 'id' => array( |
579 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
579 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
580 | 580 | 'type' => 'integer', |
581 | - 'context' => array( 'view', 'edit' ), |
|
581 | + 'context' => array('view', 'edit'), |
|
582 | 582 | 'readonly' => true, |
583 | 583 | ), |
584 | 584 | 'key' => array( |
585 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
585 | + 'description' => __('Meta key.', 'woocommerce'), |
|
586 | 586 | 'type' => 'string', |
587 | - 'context' => array( 'view', 'edit' ), |
|
587 | + 'context' => array('view', 'edit'), |
|
588 | 588 | ), |
589 | 589 | 'value' => array( |
590 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
590 | + 'description' => __('Meta value.', 'woocommerce'), |
|
591 | 591 | 'type' => 'mixed', |
592 | - 'context' => array( 'view', 'edit' ), |
|
592 | + 'context' => array('view', 'edit'), |
|
593 | 593 | ), |
594 | 594 | ), |
595 | 595 | ), |
596 | 596 | ), |
597 | 597 | 'line_items' => array( |
598 | - 'description' => __( 'Line items data.', 'woocommerce' ), |
|
598 | + 'description' => __('Line items data.', 'woocommerce'), |
|
599 | 599 | 'type' => 'array', |
600 | - 'context' => array( 'view', 'edit' ), |
|
600 | + 'context' => array('view', 'edit'), |
|
601 | 601 | 'readonly' => true, |
602 | 602 | 'items' => array( |
603 | 603 | 'type' => 'object', |
604 | 604 | 'properties' => array( |
605 | 605 | 'id' => array( |
606 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
606 | + 'description' => __('Item ID.', 'woocommerce'), |
|
607 | 607 | 'type' => 'integer', |
608 | - 'context' => array( 'view', 'edit' ), |
|
608 | + 'context' => array('view', 'edit'), |
|
609 | 609 | 'readonly' => true, |
610 | 610 | ), |
611 | 611 | 'name' => array( |
612 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
612 | + 'description' => __('Product name.', 'woocommerce'), |
|
613 | 613 | 'type' => 'mixed', |
614 | - 'context' => array( 'view', 'edit' ), |
|
614 | + 'context' => array('view', 'edit'), |
|
615 | 615 | 'readonly' => true, |
616 | 616 | ), |
617 | 617 | 'product_id' => array( |
618 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
618 | + 'description' => __('Product ID.', 'woocommerce'), |
|
619 | 619 | 'type' => 'mixed', |
620 | - 'context' => array( 'view', 'edit' ), |
|
620 | + 'context' => array('view', 'edit'), |
|
621 | 621 | 'readonly' => true, |
622 | 622 | ), |
623 | 623 | 'variation_id' => array( |
624 | - 'description' => __( 'Variation ID, if applicable.', 'woocommerce' ), |
|
624 | + 'description' => __('Variation ID, if applicable.', 'woocommerce'), |
|
625 | 625 | 'type' => 'integer', |
626 | - 'context' => array( 'view', 'edit' ), |
|
626 | + 'context' => array('view', 'edit'), |
|
627 | 627 | 'readonly' => true, |
628 | 628 | ), |
629 | 629 | 'quantity' => array( |
630 | - 'description' => __( 'Quantity ordered.', 'woocommerce' ), |
|
630 | + 'description' => __('Quantity ordered.', 'woocommerce'), |
|
631 | 631 | 'type' => 'integer', |
632 | - 'context' => array( 'view', 'edit' ), |
|
632 | + 'context' => array('view', 'edit'), |
|
633 | 633 | 'readonly' => true, |
634 | 634 | ), |
635 | 635 | 'tax_class' => array( |
636 | - 'description' => __( 'Tax class of product.', 'woocommerce' ), |
|
636 | + 'description' => __('Tax class of product.', 'woocommerce'), |
|
637 | 637 | 'type' => 'string', |
638 | - 'context' => array( 'view', 'edit' ), |
|
638 | + 'context' => array('view', 'edit'), |
|
639 | 639 | 'readonly' => true, |
640 | 640 | ), |
641 | 641 | 'subtotal' => array( |
642 | - 'description' => __( 'Line subtotal (before discounts).', 'woocommerce' ), |
|
642 | + 'description' => __('Line subtotal (before discounts).', 'woocommerce'), |
|
643 | 643 | 'type' => 'string', |
644 | - 'context' => array( 'view', 'edit' ), |
|
644 | + 'context' => array('view', 'edit'), |
|
645 | 645 | 'readonly' => true, |
646 | 646 | ), |
647 | 647 | 'subtotal_tax' => array( |
648 | - 'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce' ), |
|
648 | + 'description' => __('Line subtotal tax (before discounts).', 'woocommerce'), |
|
649 | 649 | 'type' => 'string', |
650 | - 'context' => array( 'view', 'edit' ), |
|
650 | + 'context' => array('view', 'edit'), |
|
651 | 651 | 'readonly' => true, |
652 | 652 | ), |
653 | 653 | 'total' => array( |
654 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
654 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
655 | 655 | 'type' => 'string', |
656 | - 'context' => array( 'view', 'edit' ), |
|
656 | + 'context' => array('view', 'edit'), |
|
657 | 657 | 'readonly' => true, |
658 | 658 | ), |
659 | 659 | 'total_tax' => array( |
660 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
660 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
661 | 661 | 'type' => 'string', |
662 | - 'context' => array( 'view', 'edit' ), |
|
662 | + 'context' => array('view', 'edit'), |
|
663 | 663 | 'readonly' => true, |
664 | 664 | ), |
665 | 665 | 'taxes' => array( |
666 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
666 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
667 | 667 | 'type' => 'array', |
668 | - 'context' => array( 'view', 'edit' ), |
|
668 | + 'context' => array('view', 'edit'), |
|
669 | 669 | 'readonly' => true, |
670 | 670 | 'items' => array( |
671 | 671 | 'type' => 'object', |
672 | 672 | 'properties' => array( |
673 | 673 | 'id' => array( |
674 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
674 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
675 | 675 | 'type' => 'integer', |
676 | - 'context' => array( 'view', 'edit' ), |
|
676 | + 'context' => array('view', 'edit'), |
|
677 | 677 | 'readonly' => true, |
678 | 678 | ), |
679 | 679 | 'total' => array( |
680 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
680 | + 'description' => __('Tax total.', 'woocommerce'), |
|
681 | 681 | 'type' => 'string', |
682 | - 'context' => array( 'view', 'edit' ), |
|
682 | + 'context' => array('view', 'edit'), |
|
683 | 683 | 'readonly' => true, |
684 | 684 | ), |
685 | 685 | 'subtotal' => array( |
686 | - 'description' => __( 'Tax subtotal.', 'woocommerce' ), |
|
686 | + 'description' => __('Tax subtotal.', 'woocommerce'), |
|
687 | 687 | 'type' => 'string', |
688 | - 'context' => array( 'view', 'edit' ), |
|
688 | + 'context' => array('view', 'edit'), |
|
689 | 689 | 'readonly' => true, |
690 | 690 | ), |
691 | 691 | ), |
692 | 692 | ), |
693 | 693 | ), |
694 | 694 | 'meta_data' => array( |
695 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
695 | + 'description' => __('Meta data.', 'woocommerce'), |
|
696 | 696 | 'type' => 'array', |
697 | - 'context' => array( 'view', 'edit' ), |
|
697 | + 'context' => array('view', 'edit'), |
|
698 | 698 | 'readonly' => true, |
699 | 699 | 'items' => array( |
700 | 700 | 'type' => 'object', |
701 | 701 | 'properties' => array( |
702 | 702 | 'id' => array( |
703 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
703 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
704 | 704 | 'type' => 'integer', |
705 | - 'context' => array( 'view', 'edit' ), |
|
705 | + 'context' => array('view', 'edit'), |
|
706 | 706 | 'readonly' => true, |
707 | 707 | ), |
708 | 708 | 'key' => array( |
709 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
709 | + 'description' => __('Meta key.', 'woocommerce'), |
|
710 | 710 | 'type' => 'string', |
711 | - 'context' => array( 'view', 'edit' ), |
|
711 | + 'context' => array('view', 'edit'), |
|
712 | 712 | 'readonly' => true, |
713 | 713 | ), |
714 | 714 | 'value' => array( |
715 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
715 | + 'description' => __('Meta value.', 'woocommerce'), |
|
716 | 716 | 'type' => 'mixed', |
717 | - 'context' => array( 'view', 'edit' ), |
|
717 | + 'context' => array('view', 'edit'), |
|
718 | 718 | 'readonly' => true, |
719 | 719 | ), |
720 | 720 | ), |
721 | 721 | ), |
722 | 722 | ), |
723 | 723 | 'sku' => array( |
724 | - 'description' => __( 'Product SKU.', 'woocommerce' ), |
|
724 | + 'description' => __('Product SKU.', 'woocommerce'), |
|
725 | 725 | 'type' => 'string', |
726 | - 'context' => array( 'view', 'edit' ), |
|
726 | + 'context' => array('view', 'edit'), |
|
727 | 727 | 'readonly' => true, |
728 | 728 | ), |
729 | 729 | 'price' => array( |
730 | - 'description' => __( 'Product price.', 'woocommerce' ), |
|
730 | + 'description' => __('Product price.', 'woocommerce'), |
|
731 | 731 | 'type' => 'number', |
732 | - 'context' => array( 'view', 'edit' ), |
|
732 | + 'context' => array('view', 'edit'), |
|
733 | 733 | 'readonly' => true, |
734 | 734 | ), |
735 | 735 | ), |
736 | 736 | ), |
737 | 737 | ), |
738 | 738 | 'api_refund' => array( |
739 | - 'description' => __( 'When true, the payment gateway API is used to generate the refund.', 'woocommerce' ), |
|
739 | + 'description' => __('When true, the payment gateway API is used to generate the refund.', 'woocommerce'), |
|
740 | 740 | 'type' => 'boolean', |
741 | - 'context' => array( 'edit' ), |
|
741 | + 'context' => array('edit'), |
|
742 | 742 | 'default' => true, |
743 | 743 | ), |
744 | 744 | ), |
745 | 745 | ); |
746 | 746 | |
747 | - return $this->add_additional_fields_schema( $schema ); |
|
747 | + return $this->add_additional_fields_schema($schema); |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | /** |
@@ -757,13 +757,13 @@ discard block |
||
757 | 757 | |
758 | 758 | $params['dp'] = array( |
759 | 759 | 'default' => wc_get_price_decimals(), |
760 | - 'description' => __( 'Number of decimal points to use in each resource.', 'woocommerce' ), |
|
760 | + 'description' => __('Number of decimal points to use in each resource.', 'woocommerce'), |
|
761 | 761 | 'type' => 'integer', |
762 | 762 | 'sanitize_callback' => 'absint', |
763 | 763 | 'validate_callback' => 'rest_validate_request_arg', |
764 | 764 | ); |
765 | 765 | |
766 | - unset( $params['status'], $params['customer'], $params['product'] ); |
|
766 | + unset($params['status'], $params['customer'], $params['product']); |
|
767 | 767 | |
768 | 768 | return $params; |
769 | 769 | } |
@@ -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 Attributes controller class. |
@@ -40,26 +40,26 @@ discard block |
||
40 | 40 | array( |
41 | 41 | array( |
42 | 42 | 'methods' => \WP_REST_Server::READABLE, |
43 | - 'callback' => array( $this, 'get_items' ), |
|
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
43 | + 'callback' => array($this, 'get_items'), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | 45 | 'args' => $this->get_collection_params(), |
46 | 46 | ), |
47 | 47 | array( |
48 | 48 | 'methods' => \WP_REST_Server::CREATABLE, |
49 | - 'callback' => array( $this, 'create_item' ), |
|
50 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
49 | + 'callback' => array($this, 'create_item'), |
|
50 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
51 | 51 | 'args' => array_merge( |
52 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
52 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
53 | 53 | array( |
54 | 54 | 'name' => array( |
55 | - 'description' => __( 'Name for the resource.', 'woocommerce' ), |
|
55 | + 'description' => __('Name for the resource.', 'woocommerce'), |
|
56 | 56 | 'type' => 'string', |
57 | 57 | 'required' => true, |
58 | 58 | ), |
59 | 59 | ) |
60 | 60 | ), |
61 | 61 | ), |
62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
62 | + 'schema' => array($this, 'get_public_item_schema'), |
|
63 | 63 | ), |
64 | 64 | true |
65 | 65 | ); |
@@ -70,37 +70,37 @@ discard block |
||
70 | 70 | array( |
71 | 71 | 'args' => array( |
72 | 72 | 'id' => array( |
73 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
73 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
74 | 74 | 'type' => 'integer', |
75 | 75 | ), |
76 | 76 | ), |
77 | 77 | array( |
78 | 78 | 'methods' => \WP_REST_Server::READABLE, |
79 | - 'callback' => array( $this, 'get_item' ), |
|
80 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
79 | + 'callback' => array($this, 'get_item'), |
|
80 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
81 | 81 | 'args' => array( |
82 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
82 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
83 | 83 | ), |
84 | 84 | ), |
85 | 85 | array( |
86 | 86 | 'methods' => \WP_REST_Server::EDITABLE, |
87 | - 'callback' => array( $this, 'update_item' ), |
|
88 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
89 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
87 | + 'callback' => array($this, 'update_item'), |
|
88 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
89 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
90 | 90 | ), |
91 | 91 | array( |
92 | 92 | 'methods' => \WP_REST_Server::DELETABLE, |
93 | - 'callback' => array( $this, 'delete_item' ), |
|
94 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
93 | + 'callback' => array($this, 'delete_item'), |
|
94 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
95 | 95 | 'args' => array( |
96 | 96 | 'force' => array( |
97 | 97 | 'default' => true, |
98 | 98 | 'type' => 'boolean', |
99 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
99 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
100 | 100 | ), |
101 | 101 | ), |
102 | 102 | ), |
103 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
103 | + 'schema' => array($this, 'get_public_item_schema'), |
|
104 | 104 | ), |
105 | 105 | true |
106 | 106 | ); |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | array( |
112 | 112 | array( |
113 | 113 | 'methods' => \WP_REST_Server::EDITABLE, |
114 | - 'callback' => array( $this, 'batch_items' ), |
|
115 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
116 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
114 | + 'callback' => array($this, 'batch_items'), |
|
115 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
116 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
117 | 117 | ), |
118 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
118 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
119 | 119 | ), |
120 | 120 | true |
121 | 121 | ); |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * @param \WP_REST_Request $request Full details about the request. |
128 | 128 | * @return \WP_Error|boolean |
129 | 129 | */ |
130 | - public function get_items_permissions_check( $request ) { |
|
131 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) { |
|
132 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
130 | + public function get_items_permissions_check($request) { |
|
131 | + if ( ! wc_rest_check_manager_permissions('attributes', 'read')) { |
|
132 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | return true; |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @param \WP_REST_Request $request Full details about the request. |
142 | 142 | * @return \WP_Error|boolean |
143 | 143 | */ |
144 | - public function create_item_permissions_check( $request ) { |
|
145 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'create' ) ) { |
|
146 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you cannot create new resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
144 | + public function create_item_permissions_check($request) { |
|
145 | + if ( ! wc_rest_check_manager_permissions('attributes', 'create')) { |
|
146 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you cannot create new resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return true; |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | * @param \WP_REST_Request $request Full details about the request. |
156 | 156 | * @return \WP_Error|boolean |
157 | 157 | */ |
158 | - public function get_item_permissions_check( $request ) { |
|
159 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
160 | - return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
158 | + public function get_item_permissions_check($request) { |
|
159 | + if ( ! $this->get_taxonomy($request)) { |
|
160 | + return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
161 | 161 | } |
162 | 162 | |
163 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) { |
|
164 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
163 | + if ( ! wc_rest_check_manager_permissions('attributes', 'read')) { |
|
164 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | return true; |
@@ -173,13 +173,13 @@ discard block |
||
173 | 173 | * @param \WP_REST_Request $request Full details about the request. |
174 | 174 | * @return \WP_Error|boolean |
175 | 175 | */ |
176 | - public function update_item_permissions_check( $request ) { |
|
177 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
178 | - return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
176 | + public function update_item_permissions_check($request) { |
|
177 | + if ( ! $this->get_taxonomy($request)) { |
|
178 | + return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'edit' ) ) { |
|
182 | - return new \WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
181 | + if ( ! wc_rest_check_manager_permissions('attributes', 'edit')) { |
|
182 | + return new \WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return true; |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | * @param \WP_REST_Request $request Full details about the request. |
192 | 192 | * @return \WP_Error|boolean |
193 | 193 | */ |
194 | - public function delete_item_permissions_check( $request ) { |
|
195 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
196 | - return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
194 | + public function delete_item_permissions_check($request) { |
|
195 | + if ( ! $this->get_taxonomy($request)) { |
|
196 | + return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'delete' ) ) { |
|
200 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
199 | + if ( ! wc_rest_check_manager_permissions('attributes', 'delete')) { |
|
200 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | return true; |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @return bool|\WP_Error |
212 | 212 | */ |
213 | - public function batch_items_permissions_check( $request ) { |
|
214 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'batch' ) ) { |
|
215 | - return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
213 | + public function batch_items_permissions_check($request) { |
|
214 | + if ( ! wc_rest_check_manager_permissions('attributes', 'batch')) { |
|
215 | + return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | return true; |
@@ -224,16 +224,16 @@ discard block |
||
224 | 224 | * @param \WP_REST_Request $request Request params. |
225 | 225 | * @return array |
226 | 226 | */ |
227 | - public function get_items( $request ) { |
|
227 | + public function get_items($request) { |
|
228 | 228 | $attributes = wc_get_attribute_taxonomies(); |
229 | 229 | $data = array(); |
230 | - foreach ( $attributes as $attribute_obj ) { |
|
231 | - $attribute = $this->prepare_item_for_response( $attribute_obj, $request ); |
|
232 | - $attribute = $this->prepare_response_for_collection( $attribute ); |
|
230 | + foreach ($attributes as $attribute_obj) { |
|
231 | + $attribute = $this->prepare_item_for_response($attribute_obj, $request); |
|
232 | + $attribute = $this->prepare_response_for_collection($attribute); |
|
233 | 233 | $data[] = $attribute; |
234 | 234 | } |
235 | 235 | |
236 | - return rest_ensure_response( $data ); |
|
236 | + return rest_ensure_response($data); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -242,31 +242,31 @@ discard block |
||
242 | 242 | * @param \WP_REST_Request $request Full details about the request. |
243 | 243 | * @return \WP_REST_Request|\WP_Error |
244 | 244 | */ |
245 | - public function create_item( $request ) { |
|
245 | + public function create_item($request) { |
|
246 | 246 | global $wpdb; |
247 | 247 | |
248 | 248 | $id = wc_create_attribute( |
249 | 249 | array( |
250 | 250 | 'name' => $request['name'], |
251 | - 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), |
|
252 | - 'type' => ! empty( $request['type'] ) ? $request['type'] : 'select', |
|
253 | - 'order_by' => ! empty( $request['order_by'] ) ? $request['order_by'] : 'menu_order', |
|
251 | + 'slug' => wc_sanitize_taxonomy_name(stripslashes($request['slug'])), |
|
252 | + 'type' => ! empty($request['type']) ? $request['type'] : 'select', |
|
253 | + 'order_by' => ! empty($request['order_by']) ? $request['order_by'] : 'menu_order', |
|
254 | 254 | 'has_archives' => true === $request['has_archives'], |
255 | 255 | ) |
256 | 256 | ); |
257 | 257 | |
258 | 258 | // Checks for errors. |
259 | - if ( is_wp_error( $id ) ) { |
|
260 | - return new \WP_Error( 'woocommerce_rest_cannot_create', $id->get_error_message(), array( 'status' => 400 ) ); |
|
259 | + if (is_wp_error($id)) { |
|
260 | + return new \WP_Error('woocommerce_rest_cannot_create', $id->get_error_message(), array('status' => 400)); |
|
261 | 261 | } |
262 | 262 | |
263 | - $attribute = $this->get_attribute( $id ); |
|
263 | + $attribute = $this->get_attribute($id); |
|
264 | 264 | |
265 | - if ( is_wp_error( $attribute ) ) { |
|
265 | + if (is_wp_error($attribute)) { |
|
266 | 266 | return $attribute; |
267 | 267 | } |
268 | 268 | |
269 | - $this->update_additional_fields_for_object( $attribute, $request ); |
|
269 | + $this->update_additional_fields_for_object($attribute, $request); |
|
270 | 270 | |
271 | 271 | /** |
272 | 272 | * Fires after a single product attribute is created or updated via the REST API. |
@@ -275,13 +275,13 @@ discard block |
||
275 | 275 | * @param \WP_REST_Request $request Request object. |
276 | 276 | * @param boolean $creating True when creating attribute, false when updating. |
277 | 277 | */ |
278 | - do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, true ); |
|
278 | + do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, true); |
|
279 | 279 | |
280 | - $request->set_param( 'context', 'edit' ); |
|
281 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
282 | - $response = rest_ensure_response( $response ); |
|
283 | - $response->set_status( 201 ); |
|
284 | - $response->header( 'Location', rest_url( '/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id ) ); |
|
280 | + $request->set_param('context', 'edit'); |
|
281 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
282 | + $response = rest_ensure_response($response); |
|
283 | + $response->set_status(201); |
|
284 | + $response->header('Location', rest_url('/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id)); |
|
285 | 285 | |
286 | 286 | return $response; |
287 | 287 | } |
@@ -292,16 +292,16 @@ discard block |
||
292 | 292 | * @param \WP_REST_Request $request Full details about the request. |
293 | 293 | * @return \WP_REST_Request|\WP_Error |
294 | 294 | */ |
295 | - public function get_item( $request ) { |
|
296 | - $attribute = $this->get_attribute( (int) $request['id'] ); |
|
295 | + public function get_item($request) { |
|
296 | + $attribute = $this->get_attribute((int) $request['id']); |
|
297 | 297 | |
298 | - if ( is_wp_error( $attribute ) ) { |
|
298 | + if (is_wp_error($attribute)) { |
|
299 | 299 | return $attribute; |
300 | 300 | } |
301 | 301 | |
302 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
302 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
303 | 303 | |
304 | - return rest_ensure_response( $response ); |
|
304 | + return rest_ensure_response($response); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * @param \WP_REST_Request $request Full details about the request. |
311 | 311 | * @return \WP_REST_Request|\WP_Error |
312 | 312 | */ |
313 | - public function update_item( $request ) { |
|
313 | + public function update_item($request) { |
|
314 | 314 | global $wpdb; |
315 | 315 | |
316 | 316 | $id = (int) $request['id']; |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | $id, |
319 | 319 | array( |
320 | 320 | 'name' => $request['name'], |
321 | - 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), |
|
321 | + 'slug' => wc_sanitize_taxonomy_name(stripslashes($request['slug'])), |
|
322 | 322 | 'type' => $request['type'], |
323 | 323 | 'order_by' => $request['order_by'], |
324 | 324 | 'has_archives' => $request['has_archives'], |
@@ -326,17 +326,17 @@ discard block |
||
326 | 326 | ); |
327 | 327 | |
328 | 328 | // Checks for errors. |
329 | - if ( is_wp_error( $edited ) ) { |
|
330 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', $edited->get_error_message(), array( 'status' => 400 ) ); |
|
329 | + if (is_wp_error($edited)) { |
|
330 | + return new \WP_Error('woocommerce_rest_cannot_edit', $edited->get_error_message(), array('status' => 400)); |
|
331 | 331 | } |
332 | 332 | |
333 | - $attribute = $this->get_attribute( $id ); |
|
333 | + $attribute = $this->get_attribute($id); |
|
334 | 334 | |
335 | - if ( is_wp_error( $attribute ) ) { |
|
335 | + if (is_wp_error($attribute)) { |
|
336 | 336 | return $attribute; |
337 | 337 | } |
338 | 338 | |
339 | - $this->update_additional_fields_for_object( $attribute, $request ); |
|
339 | + $this->update_additional_fields_for_object($attribute, $request); |
|
340 | 340 | |
341 | 341 | /** |
342 | 342 | * Fires after a single product attribute is created or updated via the REST API. |
@@ -345,12 +345,12 @@ discard block |
||
345 | 345 | * @param \WP_REST_Request $request Request object. |
346 | 346 | * @param boolean $creating True when creating attribute, false when updating. |
347 | 347 | */ |
348 | - do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, false ); |
|
348 | + do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, false); |
|
349 | 349 | |
350 | - $request->set_param( 'context', 'edit' ); |
|
351 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
350 | + $request->set_param('context', 'edit'); |
|
351 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
352 | 352 | |
353 | - return rest_ensure_response( $response ); |
|
353 | + return rest_ensure_response($response); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -359,26 +359,26 @@ discard block |
||
359 | 359 | * @param \WP_REST_Request $request Full details about the request. |
360 | 360 | * @return \WP_REST_Response|\WP_Error |
361 | 361 | */ |
362 | - public function delete_item( $request ) { |
|
363 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
362 | + public function delete_item($request) { |
|
363 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
364 | 364 | |
365 | 365 | // We don't support trashing for this type, error out. |
366 | - if ( ! $force ) { |
|
367 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
366 | + if ( ! $force) { |
|
367 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Resource does not support trashing.', 'woocommerce'), array('status' => 501)); |
|
368 | 368 | } |
369 | 369 | |
370 | - $attribute = $this->get_attribute( (int) $request['id'] ); |
|
370 | + $attribute = $this->get_attribute((int) $request['id']); |
|
371 | 371 | |
372 | - if ( is_wp_error( $attribute ) ) { |
|
372 | + if (is_wp_error($attribute)) { |
|
373 | 373 | return $attribute; |
374 | 374 | } |
375 | 375 | |
376 | - $request->set_param( 'context', 'edit' ); |
|
377 | - $previous = $this->prepare_item_for_response( $attribute, $request ); |
|
378 | - $deleted = wc_delete_attribute( $attribute->attribute_id ); |
|
376 | + $request->set_param('context', 'edit'); |
|
377 | + $previous = $this->prepare_item_for_response($attribute, $request); |
|
378 | + $deleted = wc_delete_attribute($attribute->attribute_id); |
|
379 | 379 | |
380 | - if ( false === $deleted ) { |
|
381 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
380 | + if (false === $deleted) { |
|
381 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | $response = new \WP_REST_Response(); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * @param \WP_REST_Response $response The response data. |
397 | 397 | * @param \WP_REST_Request $request The request sent to the API. |
398 | 398 | */ |
399 | - do_action( 'woocommerce_rest_delete_product_attribute', $attribute, $response, $request ); |
|
399 | + do_action('woocommerce_rest_delete_product_attribute', $attribute, $response, $request); |
|
400 | 400 | |
401 | 401 | return $response; |
402 | 402 | } |
@@ -408,23 +408,23 @@ discard block |
||
408 | 408 | * @param \WP_REST_Request $request Request params. |
409 | 409 | * @return \WP_REST_Response $response |
410 | 410 | */ |
411 | - public function prepare_item_for_response( $item, $request ) { |
|
411 | + public function prepare_item_for_response($item, $request) { |
|
412 | 412 | $data = array( |
413 | 413 | 'id' => (int) $item->attribute_id, |
414 | 414 | 'name' => $item->attribute_label, |
415 | - 'slug' => wc_attribute_taxonomy_name( $item->attribute_name ), |
|
415 | + 'slug' => wc_attribute_taxonomy_name($item->attribute_name), |
|
416 | 416 | 'type' => $item->attribute_type, |
417 | 417 | 'order_by' => $item->attribute_orderby, |
418 | 418 | 'has_archives' => (bool) $item->attribute_public, |
419 | 419 | ); |
420 | 420 | |
421 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
422 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
423 | - $data = $this->filter_response_by_context( $data, $context ); |
|
421 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
422 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
423 | + $data = $this->filter_response_by_context($data, $context); |
|
424 | 424 | |
425 | - $response = rest_ensure_response( $data ); |
|
425 | + $response = rest_ensure_response($data); |
|
426 | 426 | |
427 | - $response->add_links( $this->prepare_links( $item ) ); |
|
427 | + $response->add_links($this->prepare_links($item)); |
|
428 | 428 | |
429 | 429 | /** |
430 | 430 | * Filter a attribute item returned from the API. |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | * @param object $item The original attribute object. |
436 | 436 | * @param \WP_REST_Request $request Request used to generate the response. |
437 | 437 | */ |
438 | - return apply_filters( 'woocommerce_rest_prepare_product_attribute', $response, $item, $request ); |
|
438 | + return apply_filters('woocommerce_rest_prepare_product_attribute', $response, $item, $request); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -444,14 +444,14 @@ discard block |
||
444 | 444 | * @param object $attribute Attribute object. |
445 | 445 | * @return array Links for the given attribute. |
446 | 446 | */ |
447 | - protected function prepare_links( $attribute ) { |
|
447 | + protected function prepare_links($attribute) { |
|
448 | 448 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
449 | 449 | $links = array( |
450 | 450 | 'self' => array( |
451 | - 'href' => rest_url( trailingslashit( $base ) . $attribute->attribute_id ), |
|
451 | + 'href' => rest_url(trailingslashit($base) . $attribute->attribute_id), |
|
452 | 452 | ), |
453 | 453 | 'collection' => array( |
454 | - 'href' => rest_url( $base ), |
|
454 | + 'href' => rest_url($base), |
|
455 | 455 | ), |
456 | 456 | ); |
457 | 457 | |
@@ -470,51 +470,51 @@ discard block |
||
470 | 470 | 'type' => 'object', |
471 | 471 | 'properties' => array( |
472 | 472 | 'id' => array( |
473 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
473 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
474 | 474 | 'type' => 'integer', |
475 | - 'context' => array( 'view', 'edit' ), |
|
475 | + 'context' => array('view', 'edit'), |
|
476 | 476 | 'readonly' => true, |
477 | 477 | ), |
478 | 478 | 'name' => array( |
479 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
479 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
480 | 480 | 'type' => 'string', |
481 | - 'context' => array( 'view', 'edit' ), |
|
481 | + 'context' => array('view', 'edit'), |
|
482 | 482 | 'arg_options' => array( |
483 | 483 | 'sanitize_callback' => 'sanitize_text_field', |
484 | 484 | ), |
485 | 485 | ), |
486 | 486 | 'slug' => array( |
487 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
487 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
488 | 488 | 'type' => 'string', |
489 | - 'context' => array( 'view', 'edit' ), |
|
489 | + 'context' => array('view', 'edit'), |
|
490 | 490 | 'arg_options' => array( |
491 | 491 | 'sanitize_callback' => 'sanitize_title', |
492 | 492 | ), |
493 | 493 | ), |
494 | 494 | 'type' => array( |
495 | - 'description' => __( 'Type of attribute.', 'woocommerce' ), |
|
495 | + 'description' => __('Type of attribute.', 'woocommerce'), |
|
496 | 496 | 'type' => 'string', |
497 | 497 | 'default' => 'select', |
498 | - 'enum' => array_keys( wc_get_attribute_types() ), |
|
499 | - 'context' => array( 'view', 'edit' ), |
|
498 | + 'enum' => array_keys(wc_get_attribute_types()), |
|
499 | + 'context' => array('view', 'edit'), |
|
500 | 500 | ), |
501 | 501 | 'order_by' => array( |
502 | - 'description' => __( 'Default sort order.', 'woocommerce' ), |
|
502 | + 'description' => __('Default sort order.', 'woocommerce'), |
|
503 | 503 | 'type' => 'string', |
504 | 504 | 'default' => 'menu_order', |
505 | - 'enum' => array( 'menu_order', 'name', 'name_num', 'id' ), |
|
506 | - 'context' => array( 'view', 'edit' ), |
|
505 | + 'enum' => array('menu_order', 'name', 'name_num', 'id'), |
|
506 | + 'context' => array('view', 'edit'), |
|
507 | 507 | ), |
508 | 508 | 'has_archives' => array( |
509 | - 'description' => __( 'Enable/Disable attribute archives.', 'woocommerce' ), |
|
509 | + 'description' => __('Enable/Disable attribute archives.', 'woocommerce'), |
|
510 | 510 | 'type' => 'boolean', |
511 | 511 | 'default' => false, |
512 | - 'context' => array( 'view', 'edit' ), |
|
512 | + 'context' => array('view', 'edit'), |
|
513 | 513 | ), |
514 | 514 | ), |
515 | 515 | ); |
516 | 516 | |
517 | - return $this->add_additional_fields_schema( $schema ); |
|
517 | + return $this->add_additional_fields_schema($schema); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | */ |
525 | 525 | public function get_collection_params() { |
526 | 526 | $params = array(); |
527 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
527 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
528 | 528 | |
529 | 529 | return $params; |
530 | 530 | } |
@@ -535,13 +535,13 @@ discard block |
||
535 | 535 | * @param \WP_REST_Request $request Full details about the request. |
536 | 536 | * @return string |
537 | 537 | */ |
538 | - protected function get_taxonomy( $request ) { |
|
539 | - if ( '' !== $this->attribute ) { |
|
538 | + protected function get_taxonomy($request) { |
|
539 | + if ('' !== $this->attribute) { |
|
540 | 540 | return $this->attribute; |
541 | 541 | } |
542 | 542 | |
543 | - if ( $request['id'] ) { |
|
544 | - $name = wc_attribute_taxonomy_name_by_id( (int) $request['id'] ); |
|
543 | + if ($request['id']) { |
|
544 | + $name = wc_attribute_taxonomy_name_by_id((int) $request['id']); |
|
545 | 545 | |
546 | 546 | $this->attribute = $name; |
547 | 547 | } |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | * @param int $id Attribute ID. |
556 | 556 | * @return stdClass|\WP_Error |
557 | 557 | */ |
558 | - protected function get_attribute( $id ) { |
|
558 | + protected function get_attribute($id) { |
|
559 | 559 | global $wpdb; |
560 | 560 | |
561 | 561 | $attribute = $wpdb->get_row( |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | ) |
570 | 570 | ); |
571 | 571 | |
572 | - if ( is_wp_error( $attribute ) || is_null( $attribute ) ) { |
|
573 | - return new \WP_Error( 'woocommerce_rest_attribute_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
572 | + if (is_wp_error($attribute) || is_null($attribute)) { |
|
573 | + return new \WP_Error('woocommerce_rest_attribute_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | return $attribute; |
@@ -584,16 +584,16 @@ discard block |
||
584 | 584 | * @param bool $new_data Is the data new or old. |
585 | 585 | * @return bool|\WP_Error |
586 | 586 | */ |
587 | - protected function validate_attribute_slug( $slug, $new_data = true ) { |
|
588 | - if ( strlen( $slug ) >= 28 ) { |
|
587 | + protected function validate_attribute_slug($slug, $new_data = true) { |
|
588 | + if (strlen($slug) >= 28) { |
|
589 | 589 | /* Translators: %s slug. */ |
590 | - return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf( __( 'Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
591 | - } elseif ( wc_check_if_attribute_name_is_reserved( $slug ) ) { |
|
590 | + return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf(__('Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
591 | + } elseif (wc_check_if_attribute_name_is_reserved($slug)) { |
|
592 | 592 | /* Translators: %s slug. */ |
593 | - return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
594 | - } elseif ( $new_data && taxonomy_exists( wc_attribute_taxonomy_name( $slug ) ) ) { |
|
593 | + return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf(__('Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
594 | + } elseif ($new_data && taxonomy_exists(wc_attribute_taxonomy_name($slug))) { |
|
595 | 595 | /* Translators: %s slug. */ |
596 | - return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
596 | + return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf(__('Slug "%s" is already in use. Change it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | return true; |
@@ -606,6 +606,6 @@ discard block |
||
606 | 606 | * @since 3.0.0 |
607 | 607 | */ |
608 | 608 | protected function flush_rewrite_rules() { |
609 | - wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' ); |
|
609 | + wp_schedule_single_event(time(), 'woocommerce_flush_rewrite_rules'); |
|
610 | 610 | } |
611 | 611 | } |
@@ -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 Shipping Classes controller class. |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param \WP_REST_Request $request Request params. |
38 | 38 | * @return \WP_REST_Response $response |
39 | 39 | */ |
40 | - public function prepare_item_for_response( $item, $request ) { |
|
40 | + public function prepare_item_for_response($item, $request) { |
|
41 | 41 | $data = array( |
42 | 42 | 'id' => (int) $item->term_id, |
43 | 43 | 'name' => $item->name, |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | 'count' => (int) $item->count, |
47 | 47 | ); |
48 | 48 | |
49 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
50 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
51 | - $data = $this->filter_response_by_context( $data, $context ); |
|
49 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
50 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
51 | + $data = $this->filter_response_by_context($data, $context); |
|
52 | 52 | |
53 | - $response = rest_ensure_response( $data ); |
|
53 | + $response = rest_ensure_response($data); |
|
54 | 54 | |
55 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
55 | + $response->add_links($this->prepare_links($item, $request)); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Filter a term item returned from the API. |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param object $item The original term object. |
64 | 64 | * @param \WP_REST_Request $request Request used to generate the response. |
65 | 65 | */ |
66 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
66 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -78,44 +78,44 @@ discard block |
||
78 | 78 | 'type' => 'object', |
79 | 79 | 'properties' => array( |
80 | 80 | 'id' => array( |
81 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
81 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
82 | 82 | 'type' => 'integer', |
83 | - 'context' => array( 'view', 'edit' ), |
|
83 | + 'context' => array('view', 'edit'), |
|
84 | 84 | 'readonly' => true, |
85 | 85 | ), |
86 | 86 | 'name' => array( |
87 | - 'description' => __( 'Shipping class name.', 'woocommerce' ), |
|
87 | + 'description' => __('Shipping class name.', 'woocommerce'), |
|
88 | 88 | 'type' => 'string', |
89 | - 'context' => array( 'view', 'edit' ), |
|
89 | + 'context' => array('view', 'edit'), |
|
90 | 90 | 'arg_options' => array( |
91 | 91 | 'sanitize_callback' => 'sanitize_text_field', |
92 | 92 | ), |
93 | 93 | ), |
94 | 94 | 'slug' => array( |
95 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
95 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
96 | 96 | 'type' => 'string', |
97 | - 'context' => array( 'view', 'edit' ), |
|
97 | + 'context' => array('view', 'edit'), |
|
98 | 98 | 'arg_options' => array( |
99 | 99 | 'sanitize_callback' => 'sanitize_title', |
100 | 100 | ), |
101 | 101 | ), |
102 | 102 | 'description' => array( |
103 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
103 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
104 | 104 | 'type' => 'string', |
105 | - 'context' => array( 'view', 'edit' ), |
|
105 | + 'context' => array('view', 'edit'), |
|
106 | 106 | 'arg_options' => array( |
107 | 107 | 'sanitize_callback' => 'wp_filter_post_kses', |
108 | 108 | ), |
109 | 109 | ), |
110 | 110 | 'count' => array( |
111 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
111 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
112 | 112 | 'type' => 'integer', |
113 | - 'context' => array( 'view', 'edit' ), |
|
113 | + 'context' => array('view', 'edit'), |
|
114 | 114 | 'readonly' => true, |
115 | 115 | ), |
116 | 116 | ), |
117 | 117 | ); |
118 | 118 | |
119 | - return $this->add_additional_fields_schema( $schema ); |
|
119 | + return $this->add_additional_fields_schema($schema); |
|
120 | 120 | } |
121 | 121 | } |
@@ -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 System Status controller class. |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | array( |
34 | 34 | array( |
35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
36 | - 'callback' => array( $this, 'get_items' ), |
|
37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'get_items'), |
|
37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
38 | 38 | 'args' => $this->get_collection_params(), |
39 | 39 | ), |
40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
41 | 41 | ), |
42 | 42 | true |
43 | 43 | ); |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | * @param \WP_REST_Request $request Full details about the request. |
50 | 50 | * @return \WP_Error|boolean |
51 | 51 | */ |
52 | - public function get_items_permissions_check( $request ) { |
|
53 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
54 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
52 | + public function get_items_permissions_check($request) { |
|
53 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
54 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
55 | 55 | } |
56 | 56 | return true; |
57 | 57 | } |
@@ -62,24 +62,24 @@ discard block |
||
62 | 62 | * @param \WP_REST_Request $request Full details about the request. |
63 | 63 | * @return \WP_Error\WP_REST_Response |
64 | 64 | */ |
65 | - public function get_items( $request ) { |
|
65 | + public function get_items($request) { |
|
66 | 66 | $schema = $this->get_item_schema(); |
67 | 67 | $mappings = $this->get_item_mappings(); |
68 | 68 | $response = array(); |
69 | 69 | |
70 | - foreach ( $mappings as $section => $values ) { |
|
71 | - foreach ( $values as $key => $value ) { |
|
72 | - if ( isset( $schema['properties'][ $section ]['properties'][ $key ]['type'] ) ) { |
|
73 | - settype( $values[ $key ], $schema['properties'][ $section ]['properties'][ $key ]['type'] ); |
|
70 | + foreach ($mappings as $section => $values) { |
|
71 | + foreach ($values as $key => $value) { |
|
72 | + if (isset($schema['properties'][$section]['properties'][$key]['type'])) { |
|
73 | + settype($values[$key], $schema['properties'][$section]['properties'][$key]['type']); |
|
74 | 74 | } |
75 | 75 | } |
76 | - settype( $values, $schema['properties'][ $section ]['type'] ); |
|
77 | - $response[ $section ] = $values; |
|
76 | + settype($values, $schema['properties'][$section]['type']); |
|
77 | + $response[$section] = $values; |
|
78 | 78 | } |
79 | 79 | |
80 | - $response = $this->prepare_item_for_response( $response, $request ); |
|
80 | + $response = $this->prepare_item_for_response($response, $request); |
|
81 | 81 | |
82 | - return rest_ensure_response( $response ); |
|
82 | + return rest_ensure_response($response); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -94,229 +94,229 @@ discard block |
||
94 | 94 | 'type' => 'object', |
95 | 95 | 'properties' => array( |
96 | 96 | 'environment' => array( |
97 | - 'description' => __( 'Environment.', 'woocommerce' ), |
|
97 | + 'description' => __('Environment.', 'woocommerce'), |
|
98 | 98 | 'type' => 'object', |
99 | - 'context' => array( 'view' ), |
|
99 | + 'context' => array('view'), |
|
100 | 100 | 'readonly' => true, |
101 | 101 | 'properties' => array( |
102 | 102 | 'home_url' => array( |
103 | - 'description' => __( 'Home URL.', 'woocommerce' ), |
|
103 | + 'description' => __('Home URL.', 'woocommerce'), |
|
104 | 104 | 'type' => 'string', |
105 | 105 | 'format' => 'uri', |
106 | - 'context' => array( 'view' ), |
|
106 | + 'context' => array('view'), |
|
107 | 107 | 'readonly' => true, |
108 | 108 | ), |
109 | 109 | 'site_url' => array( |
110 | - 'description' => __( 'Site URL.', 'woocommerce' ), |
|
110 | + 'description' => __('Site URL.', 'woocommerce'), |
|
111 | 111 | 'type' => 'string', |
112 | 112 | 'format' => 'uri', |
113 | - 'context' => array( 'view' ), |
|
113 | + 'context' => array('view'), |
|
114 | 114 | 'readonly' => true, |
115 | 115 | ), |
116 | 116 | 'wc_version' => array( |
117 | - 'description' => __( 'WooCommerce version.', 'woocommerce' ), |
|
117 | + 'description' => __('WooCommerce version.', 'woocommerce'), |
|
118 | 118 | 'type' => 'string', |
119 | - 'context' => array( 'view' ), |
|
119 | + 'context' => array('view'), |
|
120 | 120 | 'readonly' => true, |
121 | 121 | ), |
122 | 122 | 'log_directory' => array( |
123 | - 'description' => __( 'Log directory.', 'woocommerce' ), |
|
123 | + 'description' => __('Log directory.', 'woocommerce'), |
|
124 | 124 | 'type' => 'string', |
125 | - 'context' => array( 'view' ), |
|
125 | + 'context' => array('view'), |
|
126 | 126 | 'readonly' => true, |
127 | 127 | ), |
128 | 128 | 'log_directory_writable' => array( |
129 | - 'description' => __( 'Is log directory writable?', 'woocommerce' ), |
|
129 | + 'description' => __('Is log directory writable?', 'woocommerce'), |
|
130 | 130 | 'type' => 'boolean', |
131 | - 'context' => array( 'view' ), |
|
131 | + 'context' => array('view'), |
|
132 | 132 | 'readonly' => true, |
133 | 133 | ), |
134 | 134 | 'wp_version' => array( |
135 | - 'description' => __( 'WordPress version.', 'woocommerce' ), |
|
135 | + 'description' => __('WordPress version.', 'woocommerce'), |
|
136 | 136 | 'type' => 'string', |
137 | - 'context' => array( 'view' ), |
|
137 | + 'context' => array('view'), |
|
138 | 138 | 'readonly' => true, |
139 | 139 | ), |
140 | 140 | 'wp_multisite' => array( |
141 | - 'description' => __( 'Is WordPress multisite?', 'woocommerce' ), |
|
141 | + 'description' => __('Is WordPress multisite?', 'woocommerce'), |
|
142 | 142 | 'type' => 'boolean', |
143 | - 'context' => array( 'view' ), |
|
143 | + 'context' => array('view'), |
|
144 | 144 | 'readonly' => true, |
145 | 145 | ), |
146 | 146 | 'wp_memory_limit' => array( |
147 | - 'description' => __( 'WordPress memory limit.', 'woocommerce' ), |
|
147 | + 'description' => __('WordPress memory limit.', 'woocommerce'), |
|
148 | 148 | 'type' => 'integer', |
149 | - 'context' => array( 'view' ), |
|
149 | + 'context' => array('view'), |
|
150 | 150 | 'readonly' => true, |
151 | 151 | ), |
152 | 152 | 'wp_debug_mode' => array( |
153 | - 'description' => __( 'Is WordPress debug mode active?', 'woocommerce' ), |
|
153 | + 'description' => __('Is WordPress debug mode active?', 'woocommerce'), |
|
154 | 154 | 'type' => 'boolean', |
155 | - 'context' => array( 'view' ), |
|
155 | + 'context' => array('view'), |
|
156 | 156 | 'readonly' => true, |
157 | 157 | ), |
158 | 158 | 'wp_cron' => array( |
159 | - 'description' => __( 'Are WordPress cron jobs enabled?', 'woocommerce' ), |
|
159 | + 'description' => __('Are WordPress cron jobs enabled?', 'woocommerce'), |
|
160 | 160 | 'type' => 'boolean', |
161 | - 'context' => array( 'view' ), |
|
161 | + 'context' => array('view'), |
|
162 | 162 | 'readonly' => true, |
163 | 163 | ), |
164 | 164 | 'language' => array( |
165 | - 'description' => __( 'WordPress language.', 'woocommerce' ), |
|
165 | + 'description' => __('WordPress language.', 'woocommerce'), |
|
166 | 166 | 'type' => 'string', |
167 | - 'context' => array( 'view' ), |
|
167 | + 'context' => array('view'), |
|
168 | 168 | 'readonly' => true, |
169 | 169 | ), |
170 | 170 | 'server_info' => array( |
171 | - 'description' => __( 'Server info.', 'woocommerce' ), |
|
171 | + 'description' => __('Server info.', 'woocommerce'), |
|
172 | 172 | 'type' => 'string', |
173 | - 'context' => array( 'view' ), |
|
173 | + 'context' => array('view'), |
|
174 | 174 | 'readonly' => true, |
175 | 175 | ), |
176 | 176 | 'php_version' => array( |
177 | - 'description' => __( 'PHP version.', 'woocommerce' ), |
|
177 | + 'description' => __('PHP version.', 'woocommerce'), |
|
178 | 178 | 'type' => 'string', |
179 | - 'context' => array( 'view' ), |
|
179 | + 'context' => array('view'), |
|
180 | 180 | 'readonly' => true, |
181 | 181 | ), |
182 | 182 | 'php_post_max_size' => array( |
183 | - 'description' => __( 'PHP post max size.', 'woocommerce' ), |
|
183 | + 'description' => __('PHP post max size.', 'woocommerce'), |
|
184 | 184 | 'type' => 'integer', |
185 | - 'context' => array( 'view' ), |
|
185 | + 'context' => array('view'), |
|
186 | 186 | 'readonly' => true, |
187 | 187 | ), |
188 | 188 | 'php_max_execution_time' => array( |
189 | - 'description' => __( 'PHP max execution time.', 'woocommerce' ), |
|
189 | + 'description' => __('PHP max execution time.', 'woocommerce'), |
|
190 | 190 | 'type' => 'integer', |
191 | - 'context' => array( 'view' ), |
|
191 | + 'context' => array('view'), |
|
192 | 192 | 'readonly' => true, |
193 | 193 | ), |
194 | 194 | 'php_max_input_vars' => array( |
195 | - 'description' => __( 'PHP max input vars.', 'woocommerce' ), |
|
195 | + 'description' => __('PHP max input vars.', 'woocommerce'), |
|
196 | 196 | 'type' => 'integer', |
197 | - 'context' => array( 'view' ), |
|
197 | + 'context' => array('view'), |
|
198 | 198 | 'readonly' => true, |
199 | 199 | ), |
200 | 200 | 'curl_version' => array( |
201 | - 'description' => __( 'cURL version.', 'woocommerce' ), |
|
201 | + 'description' => __('cURL version.', 'woocommerce'), |
|
202 | 202 | 'type' => 'string', |
203 | - 'context' => array( 'view' ), |
|
203 | + 'context' => array('view'), |
|
204 | 204 | 'readonly' => true, |
205 | 205 | ), |
206 | 206 | 'suhosin_installed' => array( |
207 | - 'description' => __( 'Is SUHOSIN installed?', 'woocommerce' ), |
|
207 | + 'description' => __('Is SUHOSIN installed?', 'woocommerce'), |
|
208 | 208 | 'type' => 'boolean', |
209 | - 'context' => array( 'view' ), |
|
209 | + 'context' => array('view'), |
|
210 | 210 | 'readonly' => true, |
211 | 211 | ), |
212 | 212 | 'max_upload_size' => array( |
213 | - 'description' => __( 'Max upload size.', 'woocommerce' ), |
|
213 | + 'description' => __('Max upload size.', 'woocommerce'), |
|
214 | 214 | 'type' => 'integer', |
215 | - 'context' => array( 'view' ), |
|
215 | + 'context' => array('view'), |
|
216 | 216 | 'readonly' => true, |
217 | 217 | ), |
218 | 218 | 'mysql_version' => array( |
219 | - 'description' => __( 'MySQL version.', 'woocommerce' ), |
|
219 | + 'description' => __('MySQL version.', 'woocommerce'), |
|
220 | 220 | 'type' => 'string', |
221 | - 'context' => array( 'view' ), |
|
221 | + 'context' => array('view'), |
|
222 | 222 | 'readonly' => true, |
223 | 223 | ), |
224 | 224 | 'mysql_version_string' => array( |
225 | - 'description' => __( 'MySQL version string.', 'woocommerce' ), |
|
225 | + 'description' => __('MySQL version string.', 'woocommerce'), |
|
226 | 226 | 'type' => 'string', |
227 | - 'context' => array( 'view' ), |
|
227 | + 'context' => array('view'), |
|
228 | 228 | 'readonly' => true, |
229 | 229 | ), |
230 | 230 | 'default_timezone' => array( |
231 | - 'description' => __( 'Default timezone.', 'woocommerce' ), |
|
231 | + 'description' => __('Default timezone.', 'woocommerce'), |
|
232 | 232 | 'type' => 'string', |
233 | - 'context' => array( 'view' ), |
|
233 | + 'context' => array('view'), |
|
234 | 234 | 'readonly' => true, |
235 | 235 | ), |
236 | 236 | 'fsockopen_or_curl_enabled' => array( |
237 | - 'description' => __( 'Is fsockopen/cURL enabled?', 'woocommerce' ), |
|
237 | + 'description' => __('Is fsockopen/cURL enabled?', 'woocommerce'), |
|
238 | 238 | 'type' => 'boolean', |
239 | - 'context' => array( 'view' ), |
|
239 | + 'context' => array('view'), |
|
240 | 240 | 'readonly' => true, |
241 | 241 | ), |
242 | 242 | 'soapclient_enabled' => array( |
243 | - 'description' => __( 'Is SoapClient class enabled?', 'woocommerce' ), |
|
243 | + 'description' => __('Is SoapClient class enabled?', 'woocommerce'), |
|
244 | 244 | 'type' => 'boolean', |
245 | - 'context' => array( 'view' ), |
|
245 | + 'context' => array('view'), |
|
246 | 246 | 'readonly' => true, |
247 | 247 | ), |
248 | 248 | 'domdocument_enabled' => array( |
249 | - 'description' => __( 'Is DomDocument class enabled?', 'woocommerce' ), |
|
249 | + 'description' => __('Is DomDocument class enabled?', 'woocommerce'), |
|
250 | 250 | 'type' => 'boolean', |
251 | - 'context' => array( 'view' ), |
|
251 | + 'context' => array('view'), |
|
252 | 252 | 'readonly' => true, |
253 | 253 | ), |
254 | 254 | 'gzip_enabled' => array( |
255 | - 'description' => __( 'Is GZip enabled?', 'woocommerce' ), |
|
255 | + 'description' => __('Is GZip enabled?', 'woocommerce'), |
|
256 | 256 | 'type' => 'boolean', |
257 | - 'context' => array( 'view' ), |
|
257 | + 'context' => array('view'), |
|
258 | 258 | 'readonly' => true, |
259 | 259 | ), |
260 | 260 | 'mbstring_enabled' => array( |
261 | - 'description' => __( 'Is mbstring enabled?', 'woocommerce' ), |
|
261 | + 'description' => __('Is mbstring enabled?', 'woocommerce'), |
|
262 | 262 | 'type' => 'boolean', |
263 | - 'context' => array( 'view' ), |
|
263 | + 'context' => array('view'), |
|
264 | 264 | 'readonly' => true, |
265 | 265 | ), |
266 | 266 | 'remote_post_successful' => array( |
267 | - 'description' => __( 'Remote POST successful?', 'woocommerce' ), |
|
267 | + 'description' => __('Remote POST successful?', 'woocommerce'), |
|
268 | 268 | 'type' => 'boolean', |
269 | - 'context' => array( 'view' ), |
|
269 | + 'context' => array('view'), |
|
270 | 270 | 'readonly' => true, |
271 | 271 | ), |
272 | 272 | 'remote_post_response' => array( |
273 | - 'description' => __( 'Remote POST response.', 'woocommerce' ), |
|
273 | + 'description' => __('Remote POST response.', 'woocommerce'), |
|
274 | 274 | 'type' => 'string', |
275 | - 'context' => array( 'view' ), |
|
275 | + 'context' => array('view'), |
|
276 | 276 | 'readonly' => true, |
277 | 277 | ), |
278 | 278 | 'remote_get_successful' => array( |
279 | - 'description' => __( 'Remote GET successful?', 'woocommerce' ), |
|
279 | + 'description' => __('Remote GET successful?', 'woocommerce'), |
|
280 | 280 | 'type' => 'boolean', |
281 | - 'context' => array( 'view' ), |
|
281 | + 'context' => array('view'), |
|
282 | 282 | 'readonly' => true, |
283 | 283 | ), |
284 | 284 | 'remote_get_response' => array( |
285 | - 'description' => __( 'Remote GET response.', 'woocommerce' ), |
|
285 | + 'description' => __('Remote GET response.', 'woocommerce'), |
|
286 | 286 | 'type' => 'string', |
287 | - 'context' => array( 'view' ), |
|
287 | + 'context' => array('view'), |
|
288 | 288 | 'readonly' => true, |
289 | 289 | ), |
290 | 290 | ), |
291 | 291 | ), |
292 | 292 | 'database' => array( |
293 | - 'description' => __( 'Database.', 'woocommerce' ), |
|
293 | + 'description' => __('Database.', 'woocommerce'), |
|
294 | 294 | 'type' => 'object', |
295 | - 'context' => array( 'view' ), |
|
295 | + 'context' => array('view'), |
|
296 | 296 | 'readonly' => true, |
297 | 297 | 'properties' => array( |
298 | 298 | 'wc_database_version' => array( |
299 | - 'description' => __( 'WC database version.', 'woocommerce' ), |
|
299 | + 'description' => __('WC database version.', 'woocommerce'), |
|
300 | 300 | 'type' => 'string', |
301 | - 'context' => array( 'view' ), |
|
301 | + 'context' => array('view'), |
|
302 | 302 | 'readonly' => true, |
303 | 303 | ), |
304 | 304 | 'database_prefix' => array( |
305 | - 'description' => __( 'Database prefix.', 'woocommerce' ), |
|
305 | + 'description' => __('Database prefix.', 'woocommerce'), |
|
306 | 306 | 'type' => 'string', |
307 | - 'context' => array( 'view' ), |
|
307 | + 'context' => array('view'), |
|
308 | 308 | 'readonly' => true, |
309 | 309 | ), |
310 | 310 | 'maxmind_geoip_database' => array( |
311 | - 'description' => __( 'MaxMind GeoIP database.', 'woocommerce' ), |
|
311 | + 'description' => __('MaxMind GeoIP database.', 'woocommerce'), |
|
312 | 312 | 'type' => 'string', |
313 | - 'context' => array( 'view' ), |
|
313 | + 'context' => array('view'), |
|
314 | 314 | 'readonly' => true, |
315 | 315 | ), |
316 | 316 | 'database_tables' => array( |
317 | - 'description' => __( 'Database tables.', 'woocommerce' ), |
|
317 | + 'description' => __('Database tables.', 'woocommerce'), |
|
318 | 318 | 'type' => 'array', |
319 | - 'context' => array( 'view' ), |
|
319 | + 'context' => array('view'), |
|
320 | 320 | 'readonly' => true, |
321 | 321 | 'items' => array( |
322 | 322 | 'type' => 'string', |
@@ -325,190 +325,190 @@ discard block |
||
325 | 325 | ), |
326 | 326 | ), |
327 | 327 | 'active_plugins' => array( |
328 | - 'description' => __( 'Active plugins.', 'woocommerce' ), |
|
328 | + 'description' => __('Active plugins.', 'woocommerce'), |
|
329 | 329 | 'type' => 'array', |
330 | - 'context' => array( 'view' ), |
|
330 | + 'context' => array('view'), |
|
331 | 331 | 'readonly' => true, |
332 | 332 | 'items' => array( |
333 | 333 | 'type' => 'string', |
334 | 334 | ), |
335 | 335 | ), |
336 | 336 | 'inactive_plugins' => array( |
337 | - 'description' => __( 'Inactive plugins.', 'woocommerce' ), |
|
337 | + 'description' => __('Inactive plugins.', 'woocommerce'), |
|
338 | 338 | 'type' => 'array', |
339 | - 'context' => array( 'view' ), |
|
339 | + 'context' => array('view'), |
|
340 | 340 | 'readonly' => true, |
341 | 341 | 'items' => array( |
342 | 342 | 'type' => 'string', |
343 | 343 | ), |
344 | 344 | ), |
345 | 345 | 'dropins_mu_plugins' => array( |
346 | - 'description' => __( 'Dropins & MU plugins.', 'woocommerce' ), |
|
346 | + 'description' => __('Dropins & MU plugins.', 'woocommerce'), |
|
347 | 347 | 'type' => 'array', |
348 | - 'context' => array( 'view' ), |
|
348 | + 'context' => array('view'), |
|
349 | 349 | 'readonly' => true, |
350 | 350 | 'items' => array( |
351 | 351 | 'type' => 'string', |
352 | 352 | ), |
353 | 353 | ), |
354 | 354 | 'theme' => array( |
355 | - 'description' => __( 'Theme.', 'woocommerce' ), |
|
355 | + 'description' => __('Theme.', 'woocommerce'), |
|
356 | 356 | 'type' => 'object', |
357 | - 'context' => array( 'view' ), |
|
357 | + 'context' => array('view'), |
|
358 | 358 | 'readonly' => true, |
359 | 359 | 'properties' => array( |
360 | 360 | 'name' => array( |
361 | - 'description' => __( 'Theme name.', 'woocommerce' ), |
|
361 | + 'description' => __('Theme name.', 'woocommerce'), |
|
362 | 362 | 'type' => 'string', |
363 | - 'context' => array( 'view' ), |
|
363 | + 'context' => array('view'), |
|
364 | 364 | 'readonly' => true, |
365 | 365 | ), |
366 | 366 | 'version' => array( |
367 | - 'description' => __( 'Theme version.', 'woocommerce' ), |
|
367 | + 'description' => __('Theme version.', 'woocommerce'), |
|
368 | 368 | 'type' => 'string', |
369 | - 'context' => array( 'view' ), |
|
369 | + 'context' => array('view'), |
|
370 | 370 | 'readonly' => true, |
371 | 371 | ), |
372 | 372 | 'version_latest' => array( |
373 | - 'description' => __( 'Latest version of theme.', 'woocommerce' ), |
|
373 | + 'description' => __('Latest version of theme.', 'woocommerce'), |
|
374 | 374 | 'type' => 'string', |
375 | - 'context' => array( 'view' ), |
|
375 | + 'context' => array('view'), |
|
376 | 376 | 'readonly' => true, |
377 | 377 | ), |
378 | 378 | 'author_url' => array( |
379 | - 'description' => __( 'Theme author URL.', 'woocommerce' ), |
|
379 | + 'description' => __('Theme author URL.', 'woocommerce'), |
|
380 | 380 | 'type' => 'string', |
381 | 381 | 'format' => 'uri', |
382 | - 'context' => array( 'view' ), |
|
382 | + 'context' => array('view'), |
|
383 | 383 | 'readonly' => true, |
384 | 384 | ), |
385 | 385 | 'is_child_theme' => array( |
386 | - 'description' => __( 'Is this theme a child theme?', 'woocommerce' ), |
|
386 | + 'description' => __('Is this theme a child theme?', 'woocommerce'), |
|
387 | 387 | 'type' => 'boolean', |
388 | - 'context' => array( 'view' ), |
|
388 | + 'context' => array('view'), |
|
389 | 389 | 'readonly' => true, |
390 | 390 | ), |
391 | 391 | 'has_woocommerce_support' => array( |
392 | - 'description' => __( 'Does the theme declare WooCommerce support?', 'woocommerce' ), |
|
392 | + 'description' => __('Does the theme declare WooCommerce support?', 'woocommerce'), |
|
393 | 393 | 'type' => 'boolean', |
394 | - 'context' => array( 'view' ), |
|
394 | + 'context' => array('view'), |
|
395 | 395 | 'readonly' => true, |
396 | 396 | ), |
397 | 397 | 'has_woocommerce_file' => array( |
398 | - 'description' => __( 'Does the theme have a woocommerce.php file?', 'woocommerce' ), |
|
398 | + 'description' => __('Does the theme have a woocommerce.php file?', 'woocommerce'), |
|
399 | 399 | 'type' => 'boolean', |
400 | - 'context' => array( 'view' ), |
|
400 | + 'context' => array('view'), |
|
401 | 401 | 'readonly' => true, |
402 | 402 | ), |
403 | 403 | 'has_outdated_templates' => array( |
404 | - 'description' => __( 'Does this theme have outdated templates?', 'woocommerce' ), |
|
404 | + 'description' => __('Does this theme have outdated templates?', 'woocommerce'), |
|
405 | 405 | 'type' => 'boolean', |
406 | - 'context' => array( 'view' ), |
|
406 | + 'context' => array('view'), |
|
407 | 407 | 'readonly' => true, |
408 | 408 | ), |
409 | 409 | 'overrides' => array( |
410 | - 'description' => __( 'Template overrides.', 'woocommerce' ), |
|
410 | + 'description' => __('Template overrides.', 'woocommerce'), |
|
411 | 411 | 'type' => 'array', |
412 | - 'context' => array( 'view' ), |
|
412 | + 'context' => array('view'), |
|
413 | 413 | 'readonly' => true, |
414 | 414 | 'items' => array( |
415 | 415 | 'type' => 'string', |
416 | 416 | ), |
417 | 417 | ), |
418 | 418 | 'parent_name' => array( |
419 | - 'description' => __( 'Parent theme name.', 'woocommerce' ), |
|
419 | + 'description' => __('Parent theme name.', 'woocommerce'), |
|
420 | 420 | 'type' => 'string', |
421 | - 'context' => array( 'view' ), |
|
421 | + 'context' => array('view'), |
|
422 | 422 | 'readonly' => true, |
423 | 423 | ), |
424 | 424 | 'parent_version' => array( |
425 | - 'description' => __( 'Parent theme version.', 'woocommerce' ), |
|
425 | + 'description' => __('Parent theme version.', 'woocommerce'), |
|
426 | 426 | 'type' => 'string', |
427 | - 'context' => array( 'view' ), |
|
427 | + 'context' => array('view'), |
|
428 | 428 | 'readonly' => true, |
429 | 429 | ), |
430 | 430 | 'parent_author_url' => array( |
431 | - 'description' => __( 'Parent theme author URL.', 'woocommerce' ), |
|
431 | + 'description' => __('Parent theme author URL.', 'woocommerce'), |
|
432 | 432 | 'type' => 'string', |
433 | 433 | 'format' => 'uri', |
434 | - 'context' => array( 'view' ), |
|
434 | + 'context' => array('view'), |
|
435 | 435 | 'readonly' => true, |
436 | 436 | ), |
437 | 437 | ), |
438 | 438 | ), |
439 | 439 | 'settings' => array( |
440 | - 'description' => __( 'Settings.', 'woocommerce' ), |
|
440 | + 'description' => __('Settings.', 'woocommerce'), |
|
441 | 441 | 'type' => 'object', |
442 | - 'context' => array( 'view' ), |
|
442 | + 'context' => array('view'), |
|
443 | 443 | 'readonly' => true, |
444 | 444 | 'properties' => array( |
445 | 445 | 'api_enabled' => array( |
446 | - 'description' => __( 'REST API enabled?', 'woocommerce' ), |
|
446 | + 'description' => __('REST API enabled?', 'woocommerce'), |
|
447 | 447 | 'type' => 'boolean', |
448 | - 'context' => array( 'view' ), |
|
448 | + 'context' => array('view'), |
|
449 | 449 | 'readonly' => true, |
450 | 450 | ), |
451 | 451 | 'force_ssl' => array( |
452 | - 'description' => __( 'SSL forced?', 'woocommerce' ), |
|
452 | + 'description' => __('SSL forced?', 'woocommerce'), |
|
453 | 453 | 'type' => 'boolean', |
454 | - 'context' => array( 'view' ), |
|
454 | + 'context' => array('view'), |
|
455 | 455 | 'readonly' => true, |
456 | 456 | ), |
457 | 457 | 'currency' => array( |
458 | - 'description' => __( 'Currency.', 'woocommerce' ), |
|
458 | + 'description' => __('Currency.', 'woocommerce'), |
|
459 | 459 | 'type' => 'string', |
460 | - 'context' => array( 'view' ), |
|
460 | + 'context' => array('view'), |
|
461 | 461 | 'readonly' => true, |
462 | 462 | ), |
463 | 463 | 'currency_symbol' => array( |
464 | - 'description' => __( 'Currency symbol.', 'woocommerce' ), |
|
464 | + 'description' => __('Currency symbol.', 'woocommerce'), |
|
465 | 465 | 'type' => 'string', |
466 | - 'context' => array( 'view' ), |
|
466 | + 'context' => array('view'), |
|
467 | 467 | 'readonly' => true, |
468 | 468 | ), |
469 | 469 | 'currency_position' => array( |
470 | - 'description' => __( 'Currency position.', 'woocommerce' ), |
|
470 | + 'description' => __('Currency position.', 'woocommerce'), |
|
471 | 471 | 'type' => 'string', |
472 | - 'context' => array( 'view' ), |
|
472 | + 'context' => array('view'), |
|
473 | 473 | 'readonly' => true, |
474 | 474 | ), |
475 | 475 | 'thousand_separator' => array( |
476 | - 'description' => __( 'Thousand separator.', 'woocommerce' ), |
|
476 | + 'description' => __('Thousand separator.', 'woocommerce'), |
|
477 | 477 | 'type' => 'string', |
478 | - 'context' => array( 'view' ), |
|
478 | + 'context' => array('view'), |
|
479 | 479 | 'readonly' => true, |
480 | 480 | ), |
481 | 481 | 'decimal_separator' => array( |
482 | - 'description' => __( 'Decimal separator.', 'woocommerce' ), |
|
482 | + 'description' => __('Decimal separator.', 'woocommerce'), |
|
483 | 483 | 'type' => 'string', |
484 | - 'context' => array( 'view' ), |
|
484 | + 'context' => array('view'), |
|
485 | 485 | 'readonly' => true, |
486 | 486 | ), |
487 | 487 | 'number_of_decimals' => array( |
488 | - 'description' => __( 'Number of decimals.', 'woocommerce' ), |
|
488 | + 'description' => __('Number of decimals.', 'woocommerce'), |
|
489 | 489 | 'type' => 'integer', |
490 | - 'context' => array( 'view' ), |
|
490 | + 'context' => array('view'), |
|
491 | 491 | 'readonly' => true, |
492 | 492 | ), |
493 | 493 | 'geolocation_enabled' => array( |
494 | - 'description' => __( 'Geolocation enabled?', 'woocommerce' ), |
|
494 | + 'description' => __('Geolocation enabled?', 'woocommerce'), |
|
495 | 495 | 'type' => 'boolean', |
496 | - 'context' => array( 'view' ), |
|
496 | + 'context' => array('view'), |
|
497 | 497 | 'readonly' => true, |
498 | 498 | ), |
499 | 499 | 'taxonomies' => array( |
500 | - 'description' => __( 'Taxonomy terms for product/order statuses.', 'woocommerce' ), |
|
500 | + 'description' => __('Taxonomy terms for product/order statuses.', 'woocommerce'), |
|
501 | 501 | 'type' => 'array', |
502 | - 'context' => array( 'view' ), |
|
502 | + 'context' => array('view'), |
|
503 | 503 | 'readonly' => true, |
504 | 504 | 'items' => array( |
505 | 505 | 'type' => 'string', |
506 | 506 | ), |
507 | 507 | ), |
508 | 508 | 'product_visibility_terms' => array( |
509 | - 'description' => __( 'Terms in the product visibility taxonomy.', 'woocommerce' ), |
|
509 | + 'description' => __('Terms in the product visibility taxonomy.', 'woocommerce'), |
|
510 | 510 | 'type' => 'array', |
511 | - 'context' => array( 'view' ), |
|
511 | + 'context' => array('view'), |
|
512 | 512 | 'readonly' => true, |
513 | 513 | 'items' => array( |
514 | 514 | 'type' => 'string', |
@@ -517,38 +517,38 @@ discard block |
||
517 | 517 | ), |
518 | 518 | ), |
519 | 519 | 'security' => array( |
520 | - 'description' => __( 'Security.', 'woocommerce' ), |
|
520 | + 'description' => __('Security.', 'woocommerce'), |
|
521 | 521 | 'type' => 'object', |
522 | - 'context' => array( 'view' ), |
|
522 | + 'context' => array('view'), |
|
523 | 523 | 'readonly' => true, |
524 | 524 | 'properties' => array( |
525 | 525 | 'secure_connection' => array( |
526 | - 'description' => __( 'Is the connection to your store secure?', 'woocommerce' ), |
|
526 | + 'description' => __('Is the connection to your store secure?', 'woocommerce'), |
|
527 | 527 | 'type' => 'boolean', |
528 | - 'context' => array( 'view' ), |
|
528 | + 'context' => array('view'), |
|
529 | 529 | 'readonly' => true, |
530 | 530 | ), |
531 | 531 | 'hide_errors' => array( |
532 | - 'description' => __( 'Hide errors from visitors?', 'woocommerce' ), |
|
532 | + 'description' => __('Hide errors from visitors?', 'woocommerce'), |
|
533 | 533 | 'type' => 'boolean', |
534 | - 'context' => array( 'view' ), |
|
534 | + 'context' => array('view'), |
|
535 | 535 | 'readonly' => true, |
536 | 536 | ), |
537 | 537 | ), |
538 | 538 | ), |
539 | 539 | 'pages' => array( |
540 | - 'description' => __( 'WooCommerce pages.', 'woocommerce' ), |
|
540 | + 'description' => __('WooCommerce pages.', 'woocommerce'), |
|
541 | 541 | 'type' => 'array', |
542 | - 'context' => array( 'view' ), |
|
542 | + 'context' => array('view'), |
|
543 | 543 | 'readonly' => true, |
544 | 544 | 'items' => array( |
545 | 545 | 'type' => 'string', |
546 | 546 | ), |
547 | 547 | ), |
548 | 548 | 'post_type_counts' => array( |
549 | - 'description' => __( 'Post type counts.', 'woocommerce' ), |
|
549 | + 'description' => __('Post type counts.', 'woocommerce'), |
|
550 | 550 | 'type' => 'array', |
551 | - 'context' => array( 'view' ), |
|
551 | + 'context' => array('view'), |
|
552 | 552 | 'readonly' => true, |
553 | 553 | 'items' => array( |
554 | 554 | 'type' => 'string', |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | ), |
558 | 558 | ); |
559 | 559 | |
560 | - return $this->add_additional_fields_schema( $schema ); |
|
560 | + return $this->add_additional_fields_schema($schema); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -591,23 +591,23 @@ discard block |
||
591 | 591 | |
592 | 592 | // Figure out cURL version, if installed. |
593 | 593 | $curl_version = ''; |
594 | - if ( function_exists( 'curl_version' ) ) { |
|
594 | + if (function_exists('curl_version')) { |
|
595 | 595 | $curl_version = curl_version(); |
596 | 596 | $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version']; |
597 | - } elseif ( extension_loaded( 'curl' ) ) { |
|
598 | - $curl_version = __( 'cURL installed but unable to retrieve version.', 'woocommerce' ); |
|
597 | + } elseif (extension_loaded('curl')) { |
|
598 | + $curl_version = __('cURL installed but unable to retrieve version.', 'woocommerce'); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | // WP memory limit. |
602 | - $wp_memory_limit = wc_let_to_num( WP_MEMORY_LIMIT ); |
|
603 | - if ( function_exists( 'memory_get_usage' ) ) { |
|
604 | - $wp_memory_limit = max( $wp_memory_limit, wc_let_to_num( @ini_get( 'memory_limit' ) ) ); |
|
602 | + $wp_memory_limit = wc_let_to_num(WP_MEMORY_LIMIT); |
|
603 | + if (function_exists('memory_get_usage')) { |
|
604 | + $wp_memory_limit = max($wp_memory_limit, wc_let_to_num(@ini_get('memory_limit'))); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | // Test POST requests. |
608 | - $post_response_code = get_transient( 'woocommerce_test_remote_post' ); |
|
608 | + $post_response_code = get_transient('woocommerce_test_remote_post'); |
|
609 | 609 | |
610 | - if ( false === $post_response_code || is_wp_error( $post_response_code ) ) { |
|
610 | + if (false === $post_response_code || is_wp_error($post_response_code)) { |
|
611 | 611 | $response = wp_safe_remote_post( |
612 | 612 | 'https://www.paypal.com/cgi-bin/webscr', |
613 | 613 | array( |
@@ -619,63 +619,63 @@ discard block |
||
619 | 619 | ), |
620 | 620 | ) |
621 | 621 | ); |
622 | - if ( ! is_wp_error( $response ) ) { |
|
622 | + if ( ! is_wp_error($response)) { |
|
623 | 623 | $post_response_code = $response['response']['code']; |
624 | 624 | } |
625 | - set_transient( 'woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS ); |
|
625 | + set_transient('woocommerce_test_remote_post', $post_response_code, HOUR_IN_SECONDS); |
|
626 | 626 | } |
627 | 627 | |
628 | - $post_response_successful = ! is_wp_error( $post_response_code ) && $post_response_code >= 200 && $post_response_code < 300; |
|
628 | + $post_response_successful = ! is_wp_error($post_response_code) && $post_response_code >= 200 && $post_response_code < 300; |
|
629 | 629 | |
630 | 630 | // Test GET requests. |
631 | - $get_response_code = get_transient( 'woocommerce_test_remote_get' ); |
|
631 | + $get_response_code = get_transient('woocommerce_test_remote_get'); |
|
632 | 632 | |
633 | - if ( false === $get_response_code || is_wp_error( $get_response_code ) ) { |
|
634 | - $response = wp_safe_remote_get( 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . ( is_multisite() ? '1' : '0' ) ); |
|
635 | - if ( ! is_wp_error( $response ) ) { |
|
633 | + if (false === $get_response_code || is_wp_error($get_response_code)) { |
|
634 | + $response = wp_safe_remote_get('https://woocommerce.com/wc-api/product-key-api?request=ping&network=' . (is_multisite() ? '1' : '0')); |
|
635 | + if ( ! is_wp_error($response)) { |
|
636 | 636 | $get_response_code = $response['response']['code']; |
637 | 637 | } |
638 | - set_transient( 'woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS ); |
|
638 | + set_transient('woocommerce_test_remote_get', $get_response_code, HOUR_IN_SECONDS); |
|
639 | 639 | } |
640 | 640 | |
641 | - $get_response_successful = ! is_wp_error( $get_response_code ) && $get_response_code >= 200 && $get_response_code < 300; |
|
641 | + $get_response_successful = ! is_wp_error($get_response_code) && $get_response_code >= 200 && $get_response_code < 300; |
|
642 | 642 | |
643 | 643 | $database_version = wc_get_server_database_version(); |
644 | 644 | |
645 | 645 | // Return all environment info. Described by JSON Schema. |
646 | 646 | return array( |
647 | - 'home_url' => get_option( 'home' ), |
|
648 | - 'site_url' => get_option( 'siteurl' ), |
|
647 | + 'home_url' => get_option('home'), |
|
648 | + 'site_url' => get_option('siteurl'), |
|
649 | 649 | 'version' => WC()->version, |
650 | 650 | 'log_directory' => WC_LOG_DIR, |
651 | - 'log_directory_writable' => (bool) @fopen( WC_LOG_DIR . 'test-log.log', 'a' ), |
|
652 | - 'wp_version' => get_bloginfo( 'version' ), |
|
651 | + 'log_directory_writable' => (bool) @fopen(WC_LOG_DIR . 'test-log.log', 'a'), |
|
652 | + 'wp_version' => get_bloginfo('version'), |
|
653 | 653 | 'wp_multisite' => is_multisite(), |
654 | 654 | 'wp_memory_limit' => $wp_memory_limit, |
655 | - 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ), |
|
656 | - 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ), |
|
655 | + 'wp_debug_mode' => (defined('WP_DEBUG') && WP_DEBUG), |
|
656 | + 'wp_cron' => ! (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON), |
|
657 | 657 | 'language' => get_locale(), |
658 | 658 | 'external_object_cache' => wp_using_ext_object_cache(), |
659 | - 'server_info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? wc_clean( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '', |
|
659 | + 'server_info' => isset($_SERVER['SERVER_SOFTWARE']) ? wc_clean(wp_unslash($_SERVER['SERVER_SOFTWARE'])) : '', |
|
660 | 660 | 'php_version' => phpversion(), |
661 | - 'php_post_max_size' => wc_let_to_num( ini_get( 'post_max_size' ) ), |
|
662 | - 'php_max_execution_time' => ini_get( 'max_execution_time' ), |
|
663 | - 'php_max_input_vars' => ini_get( 'max_input_vars' ), |
|
661 | + 'php_post_max_size' => wc_let_to_num(ini_get('post_max_size')), |
|
662 | + 'php_max_execution_time' => ini_get('max_execution_time'), |
|
663 | + 'php_max_input_vars' => ini_get('max_input_vars'), |
|
664 | 664 | 'curl_version' => $curl_version, |
665 | - 'suhosin_installed' => extension_loaded( 'suhosin' ), |
|
665 | + 'suhosin_installed' => extension_loaded('suhosin'), |
|
666 | 666 | 'max_upload_size' => wp_max_upload_size(), |
667 | 667 | 'mysql_version' => $database_version['number'], |
668 | 668 | 'mysql_version_string' => $database_version['string'], |
669 | 669 | 'default_timezone' => date_default_timezone_get(), |
670 | - 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ), |
|
671 | - 'soapclient_enabled' => class_exists( 'SoapClient' ), |
|
672 | - 'domdocument_enabled' => class_exists( 'DOMDocument' ), |
|
673 | - 'gzip_enabled' => is_callable( 'gzopen' ), |
|
674 | - 'mbstring_enabled' => extension_loaded( 'mbstring' ), |
|
670 | + 'fsockopen_or_curl_enabled' => (function_exists('fsockopen') || function_exists('curl_init')), |
|
671 | + 'soapclient_enabled' => class_exists('SoapClient'), |
|
672 | + 'domdocument_enabled' => class_exists('DOMDocument'), |
|
673 | + 'gzip_enabled' => is_callable('gzopen'), |
|
674 | + 'mbstring_enabled' => extension_loaded('mbstring'), |
|
675 | 675 | 'remote_post_successful' => $post_response_successful, |
676 | - 'remote_post_response' => is_wp_error( $post_response_code ) ? $post_response_code->get_error_message() : $post_response_code, |
|
676 | + 'remote_post_response' => is_wp_error($post_response_code) ? $post_response_code->get_error_message() : $post_response_code, |
|
677 | 677 | 'remote_get_successful' => $get_response_successful, |
678 | - 'remote_get_response' => is_wp_error( $get_response_code ) ? $get_response_code->get_error_message() : $get_response_code, |
|
678 | + 'remote_get_response' => is_wp_error($get_response_code) ? $get_response_code->get_error_message() : $get_response_code, |
|
679 | 679 | ); |
680 | 680 | } |
681 | 681 | |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | * @param string $table Table name. |
686 | 686 | * @return stromg |
687 | 687 | */ |
688 | - protected function add_db_table_prefix( $table ) { |
|
688 | + protected function add_db_table_prefix($table) { |
|
689 | 689 | global $wpdb; |
690 | 690 | return $wpdb->prefix . $table; |
691 | 691 | } |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | * |
739 | 739 | * If we changed the tables above to include the prefix, then any filters against that table could break. |
740 | 740 | */ |
741 | - $core_tables = array_map( array( $this, 'add_db_table_prefix' ), $core_tables ); |
|
741 | + $core_tables = array_map(array($this, 'add_db_table_prefix'), $core_tables); |
|
742 | 742 | |
743 | 743 | /** |
744 | 744 | * Organize WooCommerce and non-WooCommerce tables separately for display purposes later. |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | * To ensure we include all WC tables, even if they do not exist, pre-populate the WC array with all the tables. |
747 | 747 | */ |
748 | 748 | $tables = array( |
749 | - 'woocommerce' => array_fill_keys( $core_tables, false ), |
|
749 | + 'woocommerce' => array_fill_keys($core_tables, false), |
|
750 | 750 | 'other' => array(), |
751 | 751 | ); |
752 | 752 | |
@@ -755,16 +755,16 @@ discard block |
||
755 | 755 | 'index' => 0, |
756 | 756 | ); |
757 | 757 | |
758 | - $site_tables_prefix = $wpdb->get_blog_prefix( get_current_blog_id() ); |
|
759 | - $global_tables = $wpdb->tables( 'global', true ); |
|
760 | - foreach ( $database_table_information as $table ) { |
|
758 | + $site_tables_prefix = $wpdb->get_blog_prefix(get_current_blog_id()); |
|
759 | + $global_tables = $wpdb->tables('global', true); |
|
760 | + foreach ($database_table_information as $table) { |
|
761 | 761 | // Only include tables matching the prefix of the current site, this is to prevent displaying all tables on a MS install not relating to the current. |
762 | - if ( is_multisite() && 0 !== strpos( $table->name, $site_tables_prefix ) && ! in_array( $table->name, $global_tables, true ) ) { |
|
762 | + if (is_multisite() && 0 !== strpos($table->name, $site_tables_prefix) && ! in_array($table->name, $global_tables, true)) { |
|
763 | 763 | continue; |
764 | 764 | } |
765 | - $table_type = in_array( $table->name, $core_tables, true ) ? 'woocommerce' : 'other'; |
|
765 | + $table_type = in_array($table->name, $core_tables, true) ? 'woocommerce' : 'other'; |
|
766 | 766 | |
767 | - $tables[ $table_type ][ $table->name ] = array( |
|
767 | + $tables[$table_type][$table->name] = array( |
|
768 | 768 | 'data' => $table->data, |
769 | 769 | 'index' => $table->index, |
770 | 770 | 'engine' => $table->engine, |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | |
777 | 777 | // Return all database info. Described by JSON Schema. |
778 | 778 | return array( |
779 | - 'wc_database_version' => get_option( 'woocommerce_db_version' ), |
|
779 | + 'wc_database_version' => get_option('woocommerce_db_version'), |
|
780 | 780 | 'database_prefix' => $wpdb->prefix, |
781 | 781 | 'maxmind_geoip_database' => \WC_Geolocation::get_local_database_path(), |
782 | 782 | 'database_tables' => $tables, |
@@ -792,9 +792,9 @@ discard block |
||
792 | 792 | public function get_post_type_counts() { |
793 | 793 | global $wpdb; |
794 | 794 | |
795 | - $post_type_counts = $wpdb->get_results( "SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;" ); |
|
795 | + $post_type_counts = $wpdb->get_results("SELECT post_type AS 'type', count(1) AS 'count' FROM {$wpdb->posts} GROUP BY post_type;"); |
|
796 | 796 | |
797 | - return is_array( $post_type_counts ) ? $post_type_counts : array(); |
|
797 | + return is_array($post_type_counts) ? $post_type_counts : array(); |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | /** |
@@ -805,21 +805,21 @@ discard block |
||
805 | 805 | public function get_active_plugins() { |
806 | 806 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
807 | 807 | |
808 | - if ( ! function_exists( 'get_plugin_data' ) ) { |
|
808 | + if ( ! function_exists('get_plugin_data')) { |
|
809 | 809 | return array(); |
810 | 810 | } |
811 | 811 | |
812 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
813 | - if ( is_multisite() ) { |
|
814 | - $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
|
815 | - $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
|
812 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
813 | + if (is_multisite()) { |
|
814 | + $network_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array())); |
|
815 | + $active_plugins = array_merge($active_plugins, $network_activated_plugins); |
|
816 | 816 | } |
817 | 817 | |
818 | 818 | $active_plugins_data = array(); |
819 | 819 | |
820 | - foreach ( $active_plugins as $plugin ) { |
|
821 | - $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); |
|
822 | - $active_plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
|
820 | + foreach ($active_plugins as $plugin) { |
|
821 | + $data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
822 | + $active_plugins_data[] = $this->format_plugin_data($plugin, $data); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | return $active_plugins_data; |
@@ -833,25 +833,25 @@ discard block |
||
833 | 833 | public function get_inactive_plugins() { |
834 | 834 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
835 | 835 | |
836 | - if ( ! function_exists( 'get_plugins' ) ) { |
|
836 | + if ( ! function_exists('get_plugins')) { |
|
837 | 837 | return array(); |
838 | 838 | } |
839 | 839 | |
840 | 840 | $plugins = get_plugins(); |
841 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
841 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
842 | 842 | |
843 | - if ( is_multisite() ) { |
|
844 | - $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); |
|
845 | - $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); |
|
843 | + if (is_multisite()) { |
|
844 | + $network_activated_plugins = array_keys(get_site_option('active_sitewide_plugins', array())); |
|
845 | + $active_plugins = array_merge($active_plugins, $network_activated_plugins); |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | $plugins_data = array(); |
849 | 849 | |
850 | - foreach ( $plugins as $plugin => $data ) { |
|
851 | - if ( in_array( $plugin, $active_plugins, true ) ) { |
|
850 | + foreach ($plugins as $plugin => $data) { |
|
851 | + if (in_array($plugin, $active_plugins, true)) { |
|
852 | 852 | continue; |
853 | 853 | } |
854 | - $plugins_data[] = $this->format_plugin_data( $plugin, $data ); |
|
854 | + $plugins_data[] = $this->format_plugin_data($plugin, $data); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | return $plugins_data; |
@@ -865,23 +865,23 @@ discard block |
||
865 | 865 | * @param array $data Plugin data from WP. |
866 | 866 | * @return array Formatted data. |
867 | 867 | */ |
868 | - protected function format_plugin_data( $plugin, $data ) { |
|
868 | + protected function format_plugin_data($plugin, $data) { |
|
869 | 869 | require_once ABSPATH . 'wp-admin/includes/update.php'; |
870 | 870 | |
871 | - if ( ! function_exists( 'get_plugin_updates' ) ) { |
|
871 | + if ( ! function_exists('get_plugin_updates')) { |
|
872 | 872 | return array(); |
873 | 873 | } |
874 | 874 | |
875 | 875 | // Use WP API to lookup latest updates for plugins. WC_Helper injects updates for premium plugins. |
876 | - if ( empty( $this->available_updates ) ) { |
|
876 | + if (empty($this->available_updates)) { |
|
877 | 877 | $this->available_updates = get_plugin_updates(); |
878 | 878 | } |
879 | 879 | |
880 | 880 | $version_latest = $data['Version']; |
881 | 881 | |
882 | 882 | // Find latest version. |
883 | - if ( isset( $this->available_updates[ $plugin ]->update->new_version ) ) { |
|
884 | - $version_latest = $this->available_updates[ $plugin ]->update->new_version; |
|
883 | + if (isset($this->available_updates[$plugin]->update->new_version)) { |
|
884 | + $version_latest = $this->available_updates[$plugin]->update->new_version; |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | return array( |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | 'version_latest' => $version_latest, |
892 | 892 | 'url' => $data['PluginURI'], |
893 | 893 | 'author_name' => $data['AuthorName'], |
894 | - 'author_url' => esc_url_raw( $data['AuthorURI'] ), |
|
894 | + 'author_url' => esc_url_raw($data['AuthorURI']), |
|
895 | 895 | 'network_activated' => $data['Network'], |
896 | 896 | ); |
897 | 897 | } |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | 'dropins' => array(), |
909 | 909 | 'mu_plugins' => array(), |
910 | 910 | ); |
911 | - foreach ( $dropins as $key => $dropin ) { |
|
911 | + foreach ($dropins as $key => $dropin) { |
|
912 | 912 | $plugins['dropins'][] = array( |
913 | 913 | 'plugin' => $key, |
914 | 914 | 'name' => $dropin['Name'], |
@@ -916,14 +916,14 @@ discard block |
||
916 | 916 | } |
917 | 917 | |
918 | 918 | $mu_plugins = get_mu_plugins(); |
919 | - foreach ( $mu_plugins as $plugin => $mu_plugin ) { |
|
919 | + foreach ($mu_plugins as $plugin => $mu_plugin) { |
|
920 | 920 | $plugins['mu_plugins'][] = array( |
921 | 921 | 'plugin' => $plugin, |
922 | 922 | 'name' => $mu_plugin['Name'], |
923 | 923 | 'version' => $mu_plugin['Version'], |
924 | 924 | 'url' => $mu_plugin['PluginURI'], |
925 | 925 | 'author_name' => $mu_plugin['AuthorName'], |
926 | - 'author_url' => esc_url_raw( $mu_plugin['AuthorURI'] ), |
|
926 | + 'author_url' => esc_url_raw($mu_plugin['AuthorURI']), |
|
927 | 927 | ); |
928 | 928 | } |
929 | 929 | return $plugins; |
@@ -940,12 +940,12 @@ discard block |
||
940 | 940 | |
941 | 941 | // Get parent theme info if this theme is a child theme, otherwise |
942 | 942 | // pass empty info in the response. |
943 | - if ( is_child_theme() ) { |
|
944 | - $parent_theme = wp_get_theme( $active_theme->template ); |
|
943 | + if (is_child_theme()) { |
|
944 | + $parent_theme = wp_get_theme($active_theme->template); |
|
945 | 945 | $parent_theme_info = array( |
946 | 946 | 'parent_name' => $parent_theme->name, |
947 | 947 | 'parent_version' => $parent_theme->version, |
948 | - 'parent_version_latest' => \WC_Admin_Status::get_latest_theme_version( $parent_theme ), |
|
948 | + 'parent_version_latest' => \WC_Admin_Status::get_latest_theme_version($parent_theme), |
|
949 | 949 | 'parent_author_url' => $parent_theme->{'Author URI'}, |
950 | 950 | ); |
951 | 951 | } else { |
@@ -963,34 +963,34 @@ discard block |
||
963 | 963 | */ |
964 | 964 | $override_files = array(); |
965 | 965 | $outdated_templates = false; |
966 | - $scan_files = \WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates/' ); |
|
967 | - foreach ( $scan_files as $file ) { |
|
968 | - $located = apply_filters( 'wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/' ); |
|
966 | + $scan_files = \WC_Admin_Status::scan_template_files(WC()->plugin_path() . '/templates/'); |
|
967 | + foreach ($scan_files as $file) { |
|
968 | + $located = apply_filters('wc_get_template', $file, $file, array(), WC()->template_path(), WC()->plugin_path() . '/templates/'); |
|
969 | 969 | |
970 | - if ( file_exists( $located ) ) { |
|
970 | + if (file_exists($located)) { |
|
971 | 971 | $theme_file = $located; |
972 | - } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
|
972 | + } elseif (file_exists(get_stylesheet_directory() . '/' . $file)) { |
|
973 | 973 | $theme_file = get_stylesheet_directory() . '/' . $file; |
974 | - } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) { |
|
974 | + } elseif (file_exists(get_stylesheet_directory() . '/' . WC()->template_path() . $file)) { |
|
975 | 975 | $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file; |
976 | - } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { |
|
976 | + } elseif (file_exists(get_template_directory() . '/' . $file)) { |
|
977 | 977 | $theme_file = get_template_directory() . '/' . $file; |
978 | - } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) { |
|
978 | + } elseif (file_exists(get_template_directory() . '/' . WC()->template_path() . $file)) { |
|
979 | 979 | $theme_file = get_template_directory() . '/' . WC()->template_path() . $file; |
980 | 980 | } else { |
981 | 981 | $theme_file = false; |
982 | 982 | } |
983 | 983 | |
984 | - if ( ! empty( $theme_file ) ) { |
|
985 | - $core_version = \WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file ); |
|
986 | - $theme_version = \WC_Admin_Status::get_file_version( $theme_file ); |
|
987 | - if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) { |
|
988 | - if ( ! $outdated_templates ) { |
|
984 | + if ( ! empty($theme_file)) { |
|
985 | + $core_version = \WC_Admin_Status::get_file_version(WC()->plugin_path() . '/templates/' . $file); |
|
986 | + $theme_version = \WC_Admin_Status::get_file_version($theme_file); |
|
987 | + if ($core_version && (empty($theme_version) || version_compare($theme_version, $core_version, '<'))) { |
|
988 | + if ( ! $outdated_templates) { |
|
989 | 989 | $outdated_templates = true; |
990 | 990 | } |
991 | 991 | } |
992 | 992 | $override_files[] = array( |
993 | - 'file' => str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ), |
|
993 | + 'file' => str_replace(WP_CONTENT_DIR . '/themes/', '', $theme_file), |
|
994 | 994 | 'version' => $theme_version, |
995 | 995 | 'core_version' => $core_version, |
996 | 996 | ); |
@@ -1000,16 +1000,16 @@ discard block |
||
1000 | 1000 | $active_theme_info = array( |
1001 | 1001 | 'name' => $active_theme->name, |
1002 | 1002 | 'version' => $active_theme->version, |
1003 | - 'version_latest' => \WC_Admin_Status::get_latest_theme_version( $active_theme ), |
|
1004 | - 'author_url' => esc_url_raw( $active_theme->{'Author URI'} ), |
|
1003 | + 'version_latest' => \WC_Admin_Status::get_latest_theme_version($active_theme), |
|
1004 | + 'author_url' => esc_url_raw($active_theme->{'Author URI'} ), |
|
1005 | 1005 | 'is_child_theme' => is_child_theme(), |
1006 | - 'has_woocommerce_support' => current_theme_supports( 'woocommerce' ), |
|
1007 | - 'has_woocommerce_file' => ( file_exists( get_stylesheet_directory() . '/woocommerce.php' ) || file_exists( get_template_directory() . '/woocommerce.php' ) ), |
|
1006 | + 'has_woocommerce_support' => current_theme_supports('woocommerce'), |
|
1007 | + 'has_woocommerce_file' => (file_exists(get_stylesheet_directory() . '/woocommerce.php') || file_exists(get_template_directory() . '/woocommerce.php')), |
|
1008 | 1008 | 'has_outdated_templates' => $outdated_templates, |
1009 | 1009 | 'overrides' => $override_files, |
1010 | 1010 | ); |
1011 | 1011 | |
1012 | - return array_merge( $active_theme_info, $parent_theme_info ); |
|
1012 | + return array_merge($active_theme_info, $parent_theme_info); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | /** |
@@ -1021,36 +1021,36 @@ discard block |
||
1021 | 1021 | public function get_settings() { |
1022 | 1022 | // Get a list of terms used for product/order taxonomies. |
1023 | 1023 | $term_response = array(); |
1024 | - $terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); |
|
1025 | - foreach ( $terms as $term ) { |
|
1026 | - $term_response[ $term->slug ] = strtolower( $term->name ); |
|
1024 | + $terms = get_terms('product_type', array('hide_empty' => 0)); |
|
1025 | + foreach ($terms as $term) { |
|
1026 | + $term_response[$term->slug] = strtolower($term->name); |
|
1027 | 1027 | } |
1028 | 1028 | |
1029 | 1029 | // Get a list of terms used for product visibility. |
1030 | 1030 | $product_visibility_terms = array(); |
1031 | - $terms = get_terms( 'product_visibility', array( 'hide_empty' => 0 ) ); |
|
1032 | - foreach ( $terms as $term ) { |
|
1033 | - $product_visibility_terms[ $term->slug ] = strtolower( $term->name ); |
|
1031 | + $terms = get_terms('product_visibility', array('hide_empty' => 0)); |
|
1032 | + foreach ($terms as $term) { |
|
1033 | + $product_visibility_terms[$term->slug] = strtolower($term->name); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | // Check if WooCommerce.com account is connected. |
1037 | 1037 | $woo_com_connected = 'no'; |
1038 | - $helper_options = get_option( 'woocommerce_helper_data', array() ); |
|
1039 | - if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) { |
|
1038 | + $helper_options = get_option('woocommerce_helper_data', array()); |
|
1039 | + if (array_key_exists('auth', $helper_options) && ! empty($helper_options['auth'])) { |
|
1040 | 1040 | $woo_com_connected = 'yes'; |
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | // Return array of useful settings for debugging. |
1044 | 1044 | return array( |
1045 | - 'api_enabled' => 'yes' === get_option( 'woocommerce_api_enabled' ), |
|
1046 | - 'force_ssl' => 'yes' === get_option( 'woocommerce_force_ssl_checkout' ), |
|
1045 | + 'api_enabled' => 'yes' === get_option('woocommerce_api_enabled'), |
|
1046 | + 'force_ssl' => 'yes' === get_option('woocommerce_force_ssl_checkout'), |
|
1047 | 1047 | 'currency' => get_woocommerce_currency(), |
1048 | 1048 | 'currency_symbol' => get_woocommerce_currency_symbol(), |
1049 | - 'currency_position' => get_option( 'woocommerce_currency_pos' ), |
|
1049 | + 'currency_position' => get_option('woocommerce_currency_pos'), |
|
1050 | 1050 | 'thousand_separator' => wc_get_price_thousand_separator(), |
1051 | 1051 | 'decimal_separator' => wc_get_price_decimal_separator(), |
1052 | 1052 | 'number_of_decimals' => wc_get_price_decimals(), |
1053 | - 'geolocation_enabled' => in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation' ) ), |
|
1053 | + 'geolocation_enabled' => in_array(get_option('woocommerce_default_customer_address'), array('geolocation_ajax', 'geolocation')), |
|
1054 | 1054 | 'taxonomies' => $term_response, |
1055 | 1055 | 'product_visibility_terms' => $product_visibility_terms, |
1056 | 1056 | 'woocommerce_com_connected' => $woo_com_connected, |
@@ -1063,10 +1063,10 @@ discard block |
||
1063 | 1063 | * @return array |
1064 | 1064 | */ |
1065 | 1065 | public function get_security_info() { |
1066 | - $check_page = wc_get_page_permalink( 'shop' ); |
|
1066 | + $check_page = wc_get_page_permalink('shop'); |
|
1067 | 1067 | return array( |
1068 | - 'secure_connection' => 'https' === substr( $check_page, 0, 5 ), |
|
1069 | - 'hide_errors' => ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), |
|
1068 | + 'secure_connection' => 'https' === substr($check_page, 0, 5), |
|
1069 | + 'hide_errors' => ! (defined('WP_DEBUG') && defined('WP_DEBUG_DISPLAY') && WP_DEBUG && WP_DEBUG_DISPLAY) || 0 === intval(ini_get('display_errors')), |
|
1070 | 1070 | ); |
1071 | 1071 | } |
1072 | 1072 | |
@@ -1079,31 +1079,31 @@ discard block |
||
1079 | 1079 | public function get_pages() { |
1080 | 1080 | // WC pages to check against. |
1081 | 1081 | $check_pages = array( |
1082 | - _x( 'Shop base', 'Page setting', 'woocommerce' ) => array( |
|
1082 | + _x('Shop base', 'Page setting', 'woocommerce') => array( |
|
1083 | 1083 | 'option' => 'woocommerce_shop_page_id', |
1084 | 1084 | 'shortcode' => '', |
1085 | 1085 | ), |
1086 | - _x( 'Cart', 'Page setting', 'woocommerce' ) => array( |
|
1086 | + _x('Cart', 'Page setting', 'woocommerce') => array( |
|
1087 | 1087 | 'option' => 'woocommerce_cart_page_id', |
1088 | - 'shortcode' => '[' . apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) . ']', |
|
1088 | + 'shortcode' => '[' . apply_filters('woocommerce_cart_shortcode_tag', 'woocommerce_cart') . ']', |
|
1089 | 1089 | ), |
1090 | - _x( 'Checkout', 'Page setting', 'woocommerce' ) => array( |
|
1090 | + _x('Checkout', 'Page setting', 'woocommerce') => array( |
|
1091 | 1091 | 'option' => 'woocommerce_checkout_page_id', |
1092 | - 'shortcode' => '[' . apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) . ']', |
|
1092 | + 'shortcode' => '[' . apply_filters('woocommerce_checkout_shortcode_tag', 'woocommerce_checkout') . ']', |
|
1093 | 1093 | ), |
1094 | - _x( 'My account', 'Page setting', 'woocommerce' ) => array( |
|
1094 | + _x('My account', 'Page setting', 'woocommerce') => array( |
|
1095 | 1095 | 'option' => 'woocommerce_myaccount_page_id', |
1096 | - 'shortcode' => '[' . apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) . ']', |
|
1096 | + 'shortcode' => '[' . apply_filters('woocommerce_my_account_shortcode_tag', 'woocommerce_my_account') . ']', |
|
1097 | 1097 | ), |
1098 | - _x( 'Terms and conditions', 'Page setting', 'woocommerce' ) => array( |
|
1098 | + _x('Terms and conditions', 'Page setting', 'woocommerce') => array( |
|
1099 | 1099 | 'option' => 'woocommerce_terms_page_id', |
1100 | 1100 | 'shortcode' => '', |
1101 | 1101 | ), |
1102 | 1102 | ); |
1103 | 1103 | |
1104 | 1104 | $pages_output = array(); |
1105 | - foreach ( $check_pages as $page_name => $values ) { |
|
1106 | - $page_id = get_option( $values['option'] ); |
|
1105 | + foreach ($check_pages as $page_name => $values) { |
|
1106 | + $page_id = get_option($values['option']); |
|
1107 | 1107 | $page_set = false; |
1108 | 1108 | $page_exists = false; |
1109 | 1109 | $page_visible = false; |
@@ -1111,21 +1111,21 @@ discard block |
||
1111 | 1111 | $shortcode_required = false; |
1112 | 1112 | |
1113 | 1113 | // Page checks. |
1114 | - if ( $page_id ) { |
|
1114 | + if ($page_id) { |
|
1115 | 1115 | $page_set = true; |
1116 | 1116 | } |
1117 | - if ( get_post( $page_id ) ) { |
|
1117 | + if (get_post($page_id)) { |
|
1118 | 1118 | $page_exists = true; |
1119 | 1119 | } |
1120 | - if ( 'publish' === get_post_status( $page_id ) ) { |
|
1120 | + if ('publish' === get_post_status($page_id)) { |
|
1121 | 1121 | $page_visible = true; |
1122 | 1122 | } |
1123 | 1123 | |
1124 | 1124 | // Shortcode checks. |
1125 | - if ( $values['shortcode'] && get_post( $page_id ) ) { |
|
1125 | + if ($values['shortcode'] && get_post($page_id)) { |
|
1126 | 1126 | $shortcode_required = true; |
1127 | - $page = get_post( $page_id ); |
|
1128 | - if ( strstr( $page->post_content, $values['shortcode'] ) ) { |
|
1127 | + $page = get_post($page_id); |
|
1128 | + if (strstr($page->post_content, $values['shortcode'])) { |
|
1129 | 1129 | $shortcode_present = true; |
1130 | 1130 | } |
1131 | 1131 | } |
@@ -1153,7 +1153,7 @@ discard block |
||
1153 | 1153 | */ |
1154 | 1154 | public function get_collection_params() { |
1155 | 1155 | return array( |
1156 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
1156 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
1157 | 1157 | ); |
1158 | 1158 | } |
1159 | 1159 | |
@@ -1164,11 +1164,11 @@ discard block |
||
1164 | 1164 | * @param \WP_REST_Request $request Request object. |
1165 | 1165 | * @return \WP_REST_Response |
1166 | 1166 | */ |
1167 | - public function prepare_item_for_response( $system_status, $request ) { |
|
1168 | - $data = $this->add_additional_fields_to_object( $system_status, $request ); |
|
1169 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
1167 | + public function prepare_item_for_response($system_status, $request) { |
|
1168 | + $data = $this->add_additional_fields_to_object($system_status, $request); |
|
1169 | + $data = $this->filter_response_by_context($data, 'view'); |
|
1170 | 1170 | |
1171 | - $response = rest_ensure_response( $data ); |
|
1171 | + $response = rest_ensure_response($data); |
|
1172 | 1172 | |
1173 | 1173 | /** |
1174 | 1174 | * Filter the system status returned from the REST API. |
@@ -1177,6 +1177,6 @@ discard block |
||
1177 | 1177 | * @param mixed $system_status System status |
1178 | 1178 | * @param \WP_REST_Request $request Request object. |
1179 | 1179 | */ |
1180 | - return apply_filters( 'woocommerce_rest_prepare_system_status', $response, $system_status, $request ); |
|
1180 | + return apply_filters('woocommerce_rest_prepare_system_status', $response, $system_status, $request); |
|
1181 | 1181 | } |
1182 | 1182 | } |
@@ -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 Leaderboards class. |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * Register routes. |
28 | 28 | */ |
29 | 29 | public function register_routes() { |
30 | - if ( ! class_exists( 'WC_Admin_Reports_Coupons_Data_Store' ) ) { |
|
30 | + if ( ! class_exists('WC_Admin_Reports_Coupons_Data_Store')) { |
|
31 | 31 | return; |
32 | 32 | } |
33 | 33 | |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | array( |
38 | 38 | array( |
39 | 39 | 'methods' => \WP_REST_Server::READABLE, |
40 | - 'callback' => array( $this, 'get_items' ), |
|
41 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
40 | + 'callback' => array($this, 'get_items'), |
|
41 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
42 | 42 | 'args' => $this->get_collection_params(), |
43 | 43 | ), |
44 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
44 | + 'schema' => array($this, 'get_public_item_schema'), |
|
45 | 45 | ), |
46 | 46 | true |
47 | 47 | ); |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | array( |
53 | 53 | array( |
54 | 54 | 'methods' => \WP_REST_Server::READABLE, |
55 | - 'callback' => array( $this, 'get_allowed_items' ), |
|
56 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
55 | + 'callback' => array($this, 'get_allowed_items'), |
|
56 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
57 | 57 | ), |
58 | - 'schema' => array( $this, 'get_public_allowed_item_schema' ), |
|
58 | + 'schema' => array($this, 'get_public_allowed_item_schema'), |
|
59 | 59 | ), |
60 | 60 | true |
61 | 61 | ); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param string $before Items before date. |
70 | 70 | * @param string $persisted_query URL query string. |
71 | 71 | */ |
72 | - public function get_coupons_leaderboard( $per_page, $after, $before, $persisted_query ) { |
|
72 | + public function get_coupons_leaderboard($per_page, $after, $before, $persisted_query) { |
|
73 | 73 | $coupons_data_store = new \WC_Admin_Reports_Coupons_Data_Store(); |
74 | 74 | $coupons_data = $per_page > 0 ? $coupons_data_store->get_data( |
75 | 75 | array( |
@@ -83,27 +83,27 @@ discard block |
||
83 | 83 | )->data : array(); |
84 | 84 | |
85 | 85 | $rows = array(); |
86 | - foreach ( $coupons_data as $coupon ) { |
|
87 | - $url_query = wp_parse_args( |
|
86 | + foreach ($coupons_data as $coupon) { |
|
87 | + $url_query = wp_parse_args( |
|
88 | 88 | array( |
89 | 89 | 'filter' => 'single_coupon', |
90 | 90 | 'coupons' => $coupon['coupon_id'], |
91 | 91 | ), |
92 | 92 | $persisted_query |
93 | 93 | ); |
94 | - $coupon_url = wc_admin_url( 'analytics/coupons', $url_query ); |
|
95 | - $coupon_code = isset( $coupon['extended_info'] ) && isset( $coupon['extended_info']['code'] ) ? $coupon['extended_info']['code'] : ''; |
|
94 | + $coupon_url = wc_admin_url('analytics/coupons', $url_query); |
|
95 | + $coupon_code = isset($coupon['extended_info']) && isset($coupon['extended_info']['code']) ? $coupon['extended_info']['code'] : ''; |
|
96 | 96 | $rows[] = array( |
97 | 97 | array( |
98 | 98 | 'display' => "<a href='{$coupon_url}'>{$coupon_code}</a>", |
99 | 99 | 'value' => $coupon_code, |
100 | 100 | ), |
101 | 101 | array( |
102 | - 'display' => wc_admin_number_format( $coupon['orders_count'] ), |
|
102 | + 'display' => wc_admin_number_format($coupon['orders_count']), |
|
103 | 103 | 'value' => $coupon['orders_count'], |
104 | 104 | ), |
105 | 105 | array( |
106 | - 'display' => wc_price( $coupon['amount'] ), |
|
106 | + 'display' => wc_price($coupon['amount']), |
|
107 | 107 | 'value' => $coupon['amount'], |
108 | 108 | ), |
109 | 109 | ); |
@@ -111,16 +111,16 @@ discard block |
||
111 | 111 | |
112 | 112 | return array( |
113 | 113 | 'id' => 'coupons', |
114 | - 'label' => __( 'Top Coupons - Number of Orders', 'woocommerce' ), |
|
114 | + 'label' => __('Top Coupons - Number of Orders', 'woocommerce'), |
|
115 | 115 | 'headers' => array( |
116 | 116 | array( |
117 | - 'label' => __( 'Coupon Code', 'woocommerce' ), |
|
117 | + 'label' => __('Coupon Code', 'woocommerce'), |
|
118 | 118 | ), |
119 | 119 | array( |
120 | - 'label' => __( 'Orders', 'woocommerce' ), |
|
120 | + 'label' => __('Orders', 'woocommerce'), |
|
121 | 121 | ), |
122 | 122 | array( |
123 | - 'label' => __( 'Amount Discounted', 'woocommerce' ), |
|
123 | + 'label' => __('Amount Discounted', 'woocommerce'), |
|
124 | 124 | ), |
125 | 125 | ), |
126 | 126 | 'rows' => $rows, |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * @param string $before Items before date. |
136 | 136 | * @param string $persisted_query URL query string. |
137 | 137 | */ |
138 | - public function get_categories_leaderboard( $per_page, $after, $before, $persisted_query ) { |
|
138 | + public function get_categories_leaderboard($per_page, $after, $before, $persisted_query) { |
|
139 | 139 | $categories_data_store = new \WC_Admin_Reports_Categories_Data_Store(); |
140 | 140 | $categories_data = $per_page > 0 ? $categories_data_store->get_data( |
141 | 141 | array( |
@@ -149,27 +149,27 @@ discard block |
||
149 | 149 | )->data : array(); |
150 | 150 | |
151 | 151 | $rows = array(); |
152 | - foreach ( $categories_data as $category ) { |
|
153 | - $url_query = wp_parse_args( |
|
152 | + foreach ($categories_data as $category) { |
|
153 | + $url_query = wp_parse_args( |
|
154 | 154 | array( |
155 | 155 | 'filter' => 'single_category', |
156 | 156 | 'categories' => $category['category_id'], |
157 | 157 | ), |
158 | 158 | $persisted_query |
159 | 159 | ); |
160 | - $category_url = wc_admin_url( 'analytics/categories', $url_query ); |
|
161 | - $category_name = isset( $category['extended_info'] ) && isset( $category['extended_info']['name'] ) ? $category['extended_info']['name'] : ''; |
|
160 | + $category_url = wc_admin_url('analytics/categories', $url_query); |
|
161 | + $category_name = isset($category['extended_info']) && isset($category['extended_info']['name']) ? $category['extended_info']['name'] : ''; |
|
162 | 162 | $rows[] = array( |
163 | 163 | array( |
164 | 164 | 'display' => "<a href='{$category_url}'>{$category_name}</a>", |
165 | 165 | 'value' => $category_name, |
166 | 166 | ), |
167 | 167 | array( |
168 | - 'display' => wc_admin_number_format( $category['items_sold'] ), |
|
168 | + 'display' => wc_admin_number_format($category['items_sold']), |
|
169 | 169 | 'value' => $category['items_sold'], |
170 | 170 | ), |
171 | 171 | array( |
172 | - 'display' => wc_price( $category['net_revenue'] ), |
|
172 | + 'display' => wc_price($category['net_revenue']), |
|
173 | 173 | 'value' => $category['net_revenue'], |
174 | 174 | ), |
175 | 175 | ); |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | |
178 | 178 | return array( |
179 | 179 | 'id' => 'categories', |
180 | - 'label' => __( 'Top Categories - Items Sold', 'woocommerce' ), |
|
180 | + 'label' => __('Top Categories - Items Sold', 'woocommerce'), |
|
181 | 181 | 'headers' => array( |
182 | 182 | array( |
183 | - 'label' => __( 'Category', 'woocommerce' ), |
|
183 | + 'label' => __('Category', 'woocommerce'), |
|
184 | 184 | ), |
185 | 185 | array( |
186 | - 'label' => __( 'Items Sold', 'woocommerce' ), |
|
186 | + 'label' => __('Items Sold', 'woocommerce'), |
|
187 | 187 | ), |
188 | 188 | array( |
189 | - 'label' => __( 'Net Revenue', 'woocommerce' ), |
|
189 | + 'label' => __('Net Revenue', 'woocommerce'), |
|
190 | 190 | ), |
191 | 191 | ), |
192 | 192 | 'rows' => $rows, |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @param string $before Items before date. |
202 | 202 | * @param string $persisted_query URL query string. |
203 | 203 | */ |
204 | - public function get_customers_leaderboard( $per_page, $after, $before, $persisted_query ) { |
|
204 | + public function get_customers_leaderboard($per_page, $after, $before, $persisted_query) { |
|
205 | 205 | $customers_data_store = new \WC_Admin_Reports_Customers_Data_Store(); |
206 | 206 | $customers_data = $per_page > 0 ? $customers_data_store->get_data( |
207 | 207 | array( |
@@ -214,26 +214,26 @@ discard block |
||
214 | 214 | )->data : array(); |
215 | 215 | |
216 | 216 | $rows = array(); |
217 | - foreach ( $customers_data as $customer ) { |
|
218 | - $url_query = wp_parse_args( |
|
217 | + foreach ($customers_data as $customer) { |
|
218 | + $url_query = wp_parse_args( |
|
219 | 219 | array( |
220 | 220 | 'filter' => 'single_customer', |
221 | 221 | 'customers' => $customer['id'], |
222 | 222 | ), |
223 | 223 | $persisted_query |
224 | 224 | ); |
225 | - $customer_url = wc_admin_url( 'analytics/customers', $url_query ); |
|
225 | + $customer_url = wc_admin_url('analytics/customers', $url_query); |
|
226 | 226 | $rows[] = array( |
227 | 227 | array( |
228 | 228 | 'display' => "<a href='{$customer_url}'>{$customer['name']}</a>", |
229 | 229 | 'value' => $customer['name'], |
230 | 230 | ), |
231 | 231 | array( |
232 | - 'display' => wc_admin_number_format( $customer['orders_count'] ), |
|
232 | + 'display' => wc_admin_number_format($customer['orders_count']), |
|
233 | 233 | 'value' => $customer['orders_count'], |
234 | 234 | ), |
235 | 235 | array( |
236 | - 'display' => wc_price( $customer['total_spend'] ), |
|
236 | + 'display' => wc_price($customer['total_spend']), |
|
237 | 237 | 'value' => $customer['total_spend'], |
238 | 238 | ), |
239 | 239 | ); |
@@ -241,16 +241,16 @@ discard block |
||
241 | 241 | |
242 | 242 | return array( |
243 | 243 | 'id' => 'customers', |
244 | - 'label' => __( 'Top Customers - Total Spend', 'woocommerce' ), |
|
244 | + 'label' => __('Top Customers - Total Spend', 'woocommerce'), |
|
245 | 245 | 'headers' => array( |
246 | 246 | array( |
247 | - 'label' => __( 'Customer Name', 'woocommerce' ), |
|
247 | + 'label' => __('Customer Name', 'woocommerce'), |
|
248 | 248 | ), |
249 | 249 | array( |
250 | - 'label' => __( 'Orders', 'woocommerce' ), |
|
250 | + 'label' => __('Orders', 'woocommerce'), |
|
251 | 251 | ), |
252 | 252 | array( |
253 | - 'label' => __( 'Total Spend', 'woocommerce' ), |
|
253 | + 'label' => __('Total Spend', 'woocommerce'), |
|
254 | 254 | ), |
255 | 255 | ), |
256 | 256 | 'rows' => $rows, |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | * @param string $before Items before date. |
266 | 266 | * @param string $persisted_query URL query string. |
267 | 267 | */ |
268 | - public function get_products_leaderboard( $per_page, $after, $before, $persisted_query ) { |
|
268 | + public function get_products_leaderboard($per_page, $after, $before, $persisted_query) { |
|
269 | 269 | $products_data_store = new \WC_Admin_Reports_Products_Data_Store(); |
270 | 270 | $products_data = $per_page > 0 ? $products_data_store->get_data( |
271 | 271 | array( |
@@ -279,27 +279,27 @@ discard block |
||
279 | 279 | )->data : array(); |
280 | 280 | |
281 | 281 | $rows = array(); |
282 | - foreach ( $products_data as $product ) { |
|
283 | - $url_query = wp_parse_args( |
|
282 | + foreach ($products_data as $product) { |
|
283 | + $url_query = wp_parse_args( |
|
284 | 284 | array( |
285 | 285 | 'filter' => 'single_product', |
286 | 286 | 'products' => $product['product_id'], |
287 | 287 | ), |
288 | 288 | $persisted_query |
289 | 289 | ); |
290 | - $product_url = wc_admin_url( 'analytics/products', $url_query ); |
|
291 | - $product_name = isset( $product['extended_info'] ) && isset( $product['extended_info']['name'] ) ? $product['extended_info']['name'] : ''; |
|
290 | + $product_url = wc_admin_url('analytics/products', $url_query); |
|
291 | + $product_name = isset($product['extended_info']) && isset($product['extended_info']['name']) ? $product['extended_info']['name'] : ''; |
|
292 | 292 | $rows[] = array( |
293 | 293 | array( |
294 | 294 | 'display' => "<a href='{$product_url}'>{$product_name}</a>", |
295 | 295 | 'value' => $product_name, |
296 | 296 | ), |
297 | 297 | array( |
298 | - 'display' => wc_admin_number_format( $product['items_sold'] ), |
|
298 | + 'display' => wc_admin_number_format($product['items_sold']), |
|
299 | 299 | 'value' => $product['items_sold'], |
300 | 300 | ), |
301 | 301 | array( |
302 | - 'display' => wc_price( $product['net_revenue'] ), |
|
302 | + 'display' => wc_price($product['net_revenue']), |
|
303 | 303 | 'value' => $product['net_revenue'], |
304 | 304 | ), |
305 | 305 | ); |
@@ -307,16 +307,16 @@ discard block |
||
307 | 307 | |
308 | 308 | return array( |
309 | 309 | 'id' => 'products', |
310 | - 'label' => __( 'Top Products - Items Sold', 'woocommerce' ), |
|
310 | + 'label' => __('Top Products - Items Sold', 'woocommerce'), |
|
311 | 311 | 'headers' => array( |
312 | 312 | array( |
313 | - 'label' => __( 'Product', 'woocommerce' ), |
|
313 | + 'label' => __('Product', 'woocommerce'), |
|
314 | 314 | ), |
315 | 315 | array( |
316 | - 'label' => __( 'Items Sold', 'woocommerce' ), |
|
316 | + 'label' => __('Items Sold', 'woocommerce'), |
|
317 | 317 | ), |
318 | 318 | array( |
319 | - 'label' => __( 'Net Revenue', 'woocommerce' ), |
|
319 | + 'label' => __('Net Revenue', 'woocommerce'), |
|
320 | 320 | ), |
321 | 321 | ), |
322 | 322 | 'rows' => $rows, |
@@ -332,15 +332,15 @@ discard block |
||
332 | 332 | * @param string $persisted_query URL query string. |
333 | 333 | * @return array |
334 | 334 | */ |
335 | - public function get_leaderboards( $per_page, $after, $before, $persisted_query ) { |
|
335 | + public function get_leaderboards($per_page, $after, $before, $persisted_query) { |
|
336 | 336 | $leaderboards = array( |
337 | - $this->get_customers_leaderboard( $per_page, $after, $before, $persisted_query ), |
|
338 | - $this->get_coupons_leaderboard( $per_page, $after, $before, $persisted_query ), |
|
339 | - $this->get_categories_leaderboard( $per_page, $after, $before, $persisted_query ), |
|
340 | - $this->get_products_leaderboard( $per_page, $after, $before, $persisted_query ), |
|
337 | + $this->get_customers_leaderboard($per_page, $after, $before, $persisted_query), |
|
338 | + $this->get_coupons_leaderboard($per_page, $after, $before, $persisted_query), |
|
339 | + $this->get_categories_leaderboard($per_page, $after, $before, $persisted_query), |
|
340 | + $this->get_products_leaderboard($per_page, $after, $before, $persisted_query), |
|
341 | 341 | ); |
342 | 342 | |
343 | - return apply_filters( 'woocommerce_leaderboards', $leaderboards, $per_page, $after, $before, $persisted_query ); |
|
343 | + return apply_filters('woocommerce_leaderboards', $leaderboards, $per_page, $after, $before, $persisted_query); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -349,19 +349,19 @@ discard block |
||
349 | 349 | * @param \WP_REST_Request $request Request data. |
350 | 350 | * @return \WP_Error\WP_REST_Response |
351 | 351 | */ |
352 | - public function get_items( $request ) { |
|
353 | - $persisted_query = json_decode( $request['persisted_query'], true ); |
|
354 | - $leaderboards = $this->get_leaderboards( $request['per_page'], $request['after'], $request['before'], $persisted_query ); |
|
352 | + public function get_items($request) { |
|
353 | + $persisted_query = json_decode($request['persisted_query'], true); |
|
354 | + $leaderboards = $this->get_leaderboards($request['per_page'], $request['after'], $request['before'], $persisted_query); |
|
355 | 355 | $data = array(); |
356 | 356 | |
357 | - if ( ! empty( $leaderboards ) ) { |
|
358 | - foreach ( $leaderboards as $leaderboard ) { |
|
359 | - $response = $this->prepare_item_for_response( $leaderboard, $request ); |
|
360 | - $data[] = $this->prepare_response_for_collection( $response ); |
|
357 | + if ( ! empty($leaderboards)) { |
|
358 | + foreach ($leaderboards as $leaderboard) { |
|
359 | + $response = $this->prepare_item_for_response($leaderboard, $request); |
|
360 | + $data[] = $this->prepare_response_for_collection($response); |
|
361 | 361 | } |
362 | 362 | } |
363 | 363 | |
364 | - return rest_ensure_response( $data ); |
|
364 | + return rest_ensure_response($data); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | /** |
@@ -370,11 +370,11 @@ discard block |
||
370 | 370 | * @param \WP_REST_Request $request Request data. |
371 | 371 | * @return array|\WP_Error |
372 | 372 | */ |
373 | - public function get_allowed_items( $request ) { |
|
374 | - $leaderboards = $this->get_leaderboards( 0, null, null, null ); |
|
373 | + public function get_allowed_items($request) { |
|
374 | + $leaderboards = $this->get_leaderboards(0, null, null, null); |
|
375 | 375 | |
376 | 376 | $data = array(); |
377 | - foreach ( $leaderboards as $leaderboard ) { |
|
377 | + foreach ($leaderboards as $leaderboard) { |
|
378 | 378 | $data[] = (object) array( |
379 | 379 | 'id' => $leaderboard['id'], |
380 | 380 | 'label' => $leaderboard['label'], |
@@ -383,16 +383,16 @@ discard block |
||
383 | 383 | } |
384 | 384 | |
385 | 385 | $objects = array(); |
386 | - foreach ( $data as $item ) { |
|
387 | - $prepared = $this->prepare_item_for_response( $item, $request ); |
|
388 | - $objects[] = $this->prepare_response_for_collection( $prepared ); |
|
386 | + foreach ($data as $item) { |
|
387 | + $prepared = $this->prepare_item_for_response($item, $request); |
|
388 | + $objects[] = $this->prepare_response_for_collection($prepared); |
|
389 | 389 | } |
390 | 390 | |
391 | - $response = rest_ensure_response( $objects ); |
|
392 | - $response->header( 'X-WP-Total', count( $data ) ); |
|
393 | - $response->header( 'X-WP-TotalPages', 1 ); |
|
391 | + $response = rest_ensure_response($objects); |
|
392 | + $response->header('X-WP-Total', count($data)); |
|
393 | + $response->header('X-WP-TotalPages', 1); |
|
394 | 394 | |
395 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
395 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
396 | 396 | |
397 | 397 | return $response; |
398 | 398 | } |
@@ -404,10 +404,10 @@ discard block |
||
404 | 404 | * @param \WP_REST_Request $request Request object. |
405 | 405 | * @return \WP_REST_Response $response Response data. |
406 | 406 | */ |
407 | - public function prepare_item_for_response( $item, $request ) { |
|
408 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
409 | - $data = $this->filter_response_by_context( $data, 'view' ); |
|
410 | - $response = rest_ensure_response( $data ); |
|
407 | + public function prepare_item_for_response($item, $request) { |
|
408 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
409 | + $data = $this->filter_response_by_context($data, 'view'); |
|
410 | + $response = rest_ensure_response($data); |
|
411 | 411 | |
412 | 412 | /** |
413 | 413 | * Filter the list returned from the API. |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | * @param array $item The original item. |
417 | 417 | * @param \WP_REST_Request $request Request used to generate the response. |
418 | 418 | */ |
419 | - return apply_filters( 'woocommerce_rest_prepare_leaderboard', $response, $item, $request ); |
|
419 | + return apply_filters('woocommerce_rest_prepare_leaderboard', $response, $item, $request); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -427,15 +427,15 @@ discard block |
||
427 | 427 | public function get_collection_params() { |
428 | 428 | $params = array(); |
429 | 429 | $params['page'] = array( |
430 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
430 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
431 | 431 | 'type' => 'integer', |
432 | 432 | 'default' => 1, |
433 | 433 | 'sanitize_callback' => 'absint', |
434 | 434 | 'validate_callback' => 'rest_validate_request_arg', |
435 | 435 | 'minimum' => 1, |
436 | 436 | ); |
437 | - $params['per_page'] = array( |
|
438 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
437 | + $params['per_page'] = array( |
|
438 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
439 | 439 | 'type' => 'integer', |
440 | 440 | 'default' => 5, |
441 | 441 | 'minimum' => 1, |
@@ -443,20 +443,20 @@ discard block |
||
443 | 443 | 'sanitize_callback' => 'absint', |
444 | 444 | 'validate_callback' => 'rest_validate_request_arg', |
445 | 445 | ); |
446 | - $params['after'] = array( |
|
447 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
446 | + $params['after'] = array( |
|
447 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
448 | 448 | 'type' => 'string', |
449 | 449 | 'format' => 'date-time', |
450 | 450 | 'validate_callback' => 'rest_validate_request_arg', |
451 | 451 | ); |
452 | - $params['before'] = array( |
|
453 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
452 | + $params['before'] = array( |
|
453 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
454 | 454 | 'type' => 'string', |
455 | 455 | 'format' => 'date-time', |
456 | 456 | 'validate_callback' => 'rest_validate_request_arg', |
457 | 457 | ); |
458 | 458 | $params['persisted_query'] = array( |
459 | - 'description' => __( 'URL query to persist across links.', 'woocommerce' ), |
|
459 | + 'description' => __('URL query to persist across links.', 'woocommerce'), |
|
460 | 460 | 'type' => 'string', |
461 | 461 | 'validate_callback' => 'rest_validate_request_arg', |
462 | 462 | ); |
@@ -476,28 +476,28 @@ discard block |
||
476 | 476 | 'properties' => array( |
477 | 477 | 'id' => array( |
478 | 478 | 'type' => 'string', |
479 | - 'description' => __( 'Leaderboard ID.', 'woocommerce' ), |
|
480 | - 'context' => array( 'view' ), |
|
479 | + 'description' => __('Leaderboard ID.', 'woocommerce'), |
|
480 | + 'context' => array('view'), |
|
481 | 481 | 'readonly' => true, |
482 | 482 | ), |
483 | 483 | 'label' => array( |
484 | 484 | 'type' => 'string', |
485 | - 'description' => __( 'Displayed title for the leaderboard.', 'woocommerce' ), |
|
486 | - 'context' => array( 'view' ), |
|
485 | + 'description' => __('Displayed title for the leaderboard.', 'woocommerce'), |
|
486 | + 'context' => array('view'), |
|
487 | 487 | 'readonly' => true, |
488 | 488 | ), |
489 | 489 | 'headers' => array( |
490 | 490 | 'type' => 'array', |
491 | - 'description' => __( 'Table headers.', 'woocommerce' ), |
|
492 | - 'context' => array( 'view' ), |
|
491 | + 'description' => __('Table headers.', 'woocommerce'), |
|
492 | + 'context' => array('view'), |
|
493 | 493 | 'readonly' => true, |
494 | 494 | 'items' => array( |
495 | 495 | 'type' => 'array', |
496 | 496 | 'properties' => array( |
497 | 497 | 'label' => array( |
498 | - 'description' => __( 'Table column header.', 'woocommerce' ), |
|
498 | + 'description' => __('Table column header.', 'woocommerce'), |
|
499 | 499 | 'type' => 'string', |
500 | - 'context' => array( 'view', 'edit' ), |
|
500 | + 'context' => array('view', 'edit'), |
|
501 | 501 | 'readonly' => true, |
502 | 502 | ), |
503 | 503 | ), |
@@ -505,22 +505,22 @@ discard block |
||
505 | 505 | ), |
506 | 506 | 'rows' => array( |
507 | 507 | 'type' => 'array', |
508 | - 'description' => __( 'Table rows.', 'woocommerce' ), |
|
509 | - 'context' => array( 'view' ), |
|
508 | + 'description' => __('Table rows.', 'woocommerce'), |
|
509 | + 'context' => array('view'), |
|
510 | 510 | 'readonly' => true, |
511 | 511 | 'items' => array( |
512 | 512 | 'type' => 'array', |
513 | 513 | 'properties' => array( |
514 | 514 | 'display' => array( |
515 | - 'description' => __( 'Table cell display.', 'woocommerce' ), |
|
515 | + 'description' => __('Table cell display.', 'woocommerce'), |
|
516 | 516 | 'type' => 'string', |
517 | - 'context' => array( 'view', 'edit' ), |
|
517 | + 'context' => array('view', 'edit'), |
|
518 | 518 | 'readonly' => true, |
519 | 519 | ), |
520 | 520 | 'value' => array( |
521 | - 'description' => __( 'Table cell value.', 'woocommerce' ), |
|
521 | + 'description' => __('Table cell value.', 'woocommerce'), |
|
522 | 522 | 'type' => 'string', |
523 | - 'context' => array( 'view', 'edit' ), |
|
523 | + 'context' => array('view', 'edit'), |
|
524 | 524 | 'readonly' => true, |
525 | 525 | ), |
526 | 526 | ), |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | ), |
530 | 530 | ); |
531 | 531 | |
532 | - return $this->add_additional_fields_schema( $schema ); |
|
532 | + return $this->add_additional_fields_schema($schema); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | */ |
540 | 540 | public function get_public_allowed_item_schema() { |
541 | 541 | $schema = $this->get_public_item_schema(); |
542 | - unset( $schema['properties']['rows'] ); |
|
542 | + unset($schema['properties']['rows']); |
|
543 | 543 | return $schema; |
544 | 544 | } |
545 | 545 | } |
@@ -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 Coupons controller class. |
@@ -40,26 +40,26 @@ discard block |
||
40 | 40 | array( |
41 | 41 | array( |
42 | 42 | 'methods' => \WP_REST_Server::READABLE, |
43 | - 'callback' => array( $this, 'get_items' ), |
|
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
43 | + 'callback' => array($this, 'get_items'), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | 45 | 'args' => $this->get_collection_params(), |
46 | 46 | ), |
47 | 47 | array( |
48 | 48 | 'methods' => \WP_REST_Server::CREATABLE, |
49 | - 'callback' => array( $this, 'create_item' ), |
|
50 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
49 | + 'callback' => array($this, 'create_item'), |
|
50 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
51 | 51 | 'args' => array_merge( |
52 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
52 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
53 | 53 | array( |
54 | 54 | 'code' => array( |
55 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
55 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
56 | 56 | 'required' => true, |
57 | 57 | 'type' => 'string', |
58 | 58 | ), |
59 | 59 | ) |
60 | 60 | ), |
61 | 61 | ), |
62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
62 | + 'schema' => array($this, 'get_public_item_schema'), |
|
63 | 63 | ), |
64 | 64 | true |
65 | 65 | ); |
@@ -70,37 +70,37 @@ discard block |
||
70 | 70 | array( |
71 | 71 | 'args' => array( |
72 | 72 | 'id' => array( |
73 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
73 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
74 | 74 | 'type' => 'integer', |
75 | 75 | ), |
76 | 76 | ), |
77 | 77 | array( |
78 | 78 | 'methods' => \WP_REST_Server::READABLE, |
79 | - 'callback' => array( $this, 'get_item' ), |
|
80 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
79 | + 'callback' => array($this, 'get_item'), |
|
80 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
81 | 81 | 'args' => array( |
82 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
82 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
83 | 83 | ), |
84 | 84 | ), |
85 | 85 | array( |
86 | 86 | 'methods' => \WP_REST_Server::EDITABLE, |
87 | - 'callback' => array( $this, 'update_item' ), |
|
88 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
89 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
87 | + 'callback' => array($this, 'update_item'), |
|
88 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
89 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
90 | 90 | ), |
91 | 91 | array( |
92 | 92 | 'methods' => \WP_REST_Server::DELETABLE, |
93 | - 'callback' => array( $this, 'delete_item' ), |
|
94 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
93 | + 'callback' => array($this, 'delete_item'), |
|
94 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
95 | 95 | 'args' => array( |
96 | 96 | 'force' => array( |
97 | 97 | 'default' => false, |
98 | 98 | 'type' => 'boolean', |
99 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
99 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
100 | 100 | ), |
101 | 101 | ), |
102 | 102 | ), |
103 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
103 | + 'schema' => array($this, 'get_public_item_schema'), |
|
104 | 104 | ), |
105 | 105 | true |
106 | 106 | ); |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | array( |
112 | 112 | array( |
113 | 113 | 'methods' => \WP_REST_Server::EDITABLE, |
114 | - 'callback' => array( $this, 'batch_items' ), |
|
115 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
116 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
114 | + 'callback' => array($this, 'batch_items'), |
|
115 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
116 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
117 | 117 | ), |
118 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
118 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
119 | 119 | ), |
120 | 120 | true |
121 | 121 | ); |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | * @param int $id Object ID. |
129 | 129 | * @return WC_Data |
130 | 130 | */ |
131 | - protected function get_object( $id ) { |
|
132 | - return new \WC_Coupon( $id ); |
|
131 | + protected function get_object($id) { |
|
132 | + return new \WC_Coupon($id); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,28 +139,28 @@ discard block |
||
139 | 139 | * @param WC_Data $object WC_Data instance. |
140 | 140 | * @return array |
141 | 141 | */ |
142 | - protected function get_formatted_item_data( $object ) { |
|
142 | + protected function get_formatted_item_data($object) { |
|
143 | 143 | $data = $object->get_data(); |
144 | 144 | |
145 | - $format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' ); |
|
146 | - $format_date = array( 'date_created', 'date_modified', 'date_expires' ); |
|
147 | - $format_null = array( 'usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items' ); |
|
145 | + $format_decimal = array('amount', 'minimum_amount', 'maximum_amount'); |
|
146 | + $format_date = array('date_created', 'date_modified', 'date_expires'); |
|
147 | + $format_null = array('usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items'); |
|
148 | 148 | |
149 | 149 | // Format decimal values. |
150 | - foreach ( $format_decimal as $key ) { |
|
151 | - $data[ $key ] = wc_format_decimal( $data[ $key ], 2 ); |
|
150 | + foreach ($format_decimal as $key) { |
|
151 | + $data[$key] = wc_format_decimal($data[$key], 2); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Format date values. |
155 | - foreach ( $format_date as $key ) { |
|
156 | - $datetime = $data[ $key ]; |
|
157 | - $data[ $key ] = wc_rest_prepare_date_response( $datetime, false ); |
|
158 | - $data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime ); |
|
155 | + foreach ($format_date as $key) { |
|
156 | + $datetime = $data[$key]; |
|
157 | + $data[$key] = wc_rest_prepare_date_response($datetime, false); |
|
158 | + $data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | // Format null values. |
162 | - foreach ( $format_null as $key ) { |
|
163 | - $data[ $key ] = $data[ $key ] ? $data[ $key ] : null; |
|
162 | + foreach ($format_null as $key) { |
|
163 | + $data[$key] = $data[$key] ? $data[$key] : null; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | return array( |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | * @param \WP_REST_Request $request Request object. |
203 | 203 | * @return \WP_REST_Response |
204 | 204 | */ |
205 | - public function prepare_object_for_response( $object, $request ) { |
|
206 | - $data = $this->get_formatted_item_data( $object ); |
|
207 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
208 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
209 | - $data = $this->filter_response_by_context( $data, $context ); |
|
210 | - $response = rest_ensure_response( $data ); |
|
211 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
205 | + public function prepare_object_for_response($object, $request) { |
|
206 | + $data = $this->get_formatted_item_data($object); |
|
207 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
208 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
209 | + $data = $this->filter_response_by_context($data, $context); |
|
210 | + $response = rest_ensure_response($data); |
|
211 | + $response->add_links($this->prepare_links($object, $request)); |
|
212 | 212 | |
213 | 213 | /** |
214 | 214 | * Filter the data for a response. |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param WC_Data $object Object data. |
221 | 221 | * @param \WP_REST_Request $request Request object. |
222 | 222 | */ |
223 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
223 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -230,15 +230,15 @@ discard block |
||
230 | 230 | * @param \WP_REST_Request $request Full details about the request. |
231 | 231 | * @return array |
232 | 232 | */ |
233 | - protected function prepare_objects_query( $request ) { |
|
234 | - $args = parent::prepare_objects_query( $request ); |
|
233 | + protected function prepare_objects_query($request) { |
|
234 | + $args = parent::prepare_objects_query($request); |
|
235 | 235 | |
236 | - if ( ! empty( $request['code'] ) ) { |
|
237 | - $id = wc_get_coupon_id_by_code( $request['code'] ); |
|
238 | - $args['post__in'] = array( $id ); |
|
236 | + if ( ! empty($request['code'])) { |
|
237 | + $id = wc_get_coupon_id_by_code($request['code']); |
|
238 | + $args['post__in'] = array($id); |
|
239 | 239 | } |
240 | 240 | |
241 | - if ( ! empty( $request['search'] ) ) { |
|
241 | + if ( ! empty($request['search'])) { |
|
242 | 242 | $args['search'] = $request['search']; |
243 | 243 | $args['s'] = false; |
244 | 244 | } |
@@ -253,47 +253,47 @@ discard block |
||
253 | 253 | * @param bool $creating If is creating a new object. |
254 | 254 | * @return \WP_Error|WC_Data |
255 | 255 | */ |
256 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
257 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
258 | - $coupon = new \WC_Coupon( $id ); |
|
256 | + protected function prepare_object_for_database($request, $creating = false) { |
|
257 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
258 | + $coupon = new \WC_Coupon($id); |
|
259 | 259 | $schema = $this->get_item_schema(); |
260 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
260 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
261 | 261 | |
262 | 262 | // Validate required POST fields. |
263 | - if ( $creating && empty( $request['code'] ) ) { |
|
264 | - return new \WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) ); |
|
263 | + if ($creating && empty($request['code'])) { |
|
264 | + return new \WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400)); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Handle all writable props. |
268 | - foreach ( $data_keys as $key ) { |
|
269 | - $value = $request[ $key ]; |
|
268 | + foreach ($data_keys as $key) { |
|
269 | + $value = $request[$key]; |
|
270 | 270 | |
271 | - if ( ! is_null( $value ) ) { |
|
272 | - switch ( $key ) { |
|
271 | + if ( ! is_null($value)) { |
|
272 | + switch ($key) { |
|
273 | 273 | case 'code': |
274 | - $coupon_code = wc_format_coupon_code( $value ); |
|
274 | + $coupon_code = wc_format_coupon_code($value); |
|
275 | 275 | $id = $coupon->get_id() ? $coupon->get_id() : 0; |
276 | - $id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id ); |
|
276 | + $id_from_code = wc_get_coupon_id_by_code($coupon_code, $id); |
|
277 | 277 | |
278 | - if ( $id_from_code ) { |
|
279 | - return new \WP_Error( 'woocommerce_rest_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce' ), array( 'status' => 400 ) ); |
|
278 | + if ($id_from_code) { |
|
279 | + return new \WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400)); |
|
280 | 280 | } |
281 | 281 | |
282 | - $coupon->set_code( $coupon_code ); |
|
282 | + $coupon->set_code($coupon_code); |
|
283 | 283 | break; |
284 | 284 | case 'meta_data': |
285 | - if ( is_array( $value ) ) { |
|
286 | - foreach ( $value as $meta ) { |
|
287 | - $coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
285 | + if (is_array($value)) { |
|
286 | + foreach ($value as $meta) { |
|
287 | + $coupon->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | break; |
291 | 291 | case 'description': |
292 | - $coupon->set_description( wp_filter_post_kses( $value ) ); |
|
292 | + $coupon->set_description(wp_filter_post_kses($value)); |
|
293 | 293 | break; |
294 | 294 | default: |
295 | - if ( is_callable( array( $coupon, "set_{$key}" ) ) ) { |
|
296 | - $coupon->{"set_{$key}"}( $value ); |
|
295 | + if (is_callable(array($coupon, "set_{$key}"))) { |
|
296 | + $coupon->{"set_{$key}"}($value); |
|
297 | 297 | } |
298 | 298 | break; |
299 | 299 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * @param \WP_REST_Request $request Request object. |
311 | 311 | * @param bool $creating If is creating a new object. |
312 | 312 | */ |
313 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating ); |
|
313 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -325,194 +325,194 @@ discard block |
||
325 | 325 | 'type' => 'object', |
326 | 326 | 'properties' => array( |
327 | 327 | 'id' => array( |
328 | - 'description' => __( 'Unique identifier for the object.', 'woocommerce' ), |
|
328 | + 'description' => __('Unique identifier for the object.', 'woocommerce'), |
|
329 | 329 | 'type' => 'integer', |
330 | - 'context' => array( 'view', 'edit' ), |
|
330 | + 'context' => array('view', 'edit'), |
|
331 | 331 | 'readonly' => true, |
332 | 332 | ), |
333 | 333 | 'code' => array( |
334 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
334 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
335 | 335 | 'type' => 'string', |
336 | - 'context' => array( 'view', 'edit' ), |
|
336 | + 'context' => array('view', 'edit'), |
|
337 | 337 | ), |
338 | 338 | 'amount' => array( |
339 | - 'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce' ), |
|
339 | + 'description' => __('The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce'), |
|
340 | 340 | 'type' => 'string', |
341 | - 'context' => array( 'view', 'edit' ), |
|
341 | + 'context' => array('view', 'edit'), |
|
342 | 342 | ), |
343 | 343 | 'date_created' => array( |
344 | - 'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce' ), |
|
344 | + 'description' => __("The date the coupon was created, in the site's timezone.", 'woocommerce'), |
|
345 | 345 | 'type' => 'date-time', |
346 | - 'context' => array( 'view', 'edit' ), |
|
346 | + 'context' => array('view', 'edit'), |
|
347 | 347 | 'readonly' => true, |
348 | 348 | ), |
349 | 349 | 'date_created_gmt' => array( |
350 | - 'description' => __( 'The date the coupon was created, as GMT.', 'woocommerce' ), |
|
350 | + 'description' => __('The date the coupon was created, as GMT.', 'woocommerce'), |
|
351 | 351 | 'type' => 'date-time', |
352 | - 'context' => array( 'view', 'edit' ), |
|
352 | + 'context' => array('view', 'edit'), |
|
353 | 353 | 'readonly' => true, |
354 | 354 | ), |
355 | 355 | 'date_modified' => array( |
356 | - 'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce' ), |
|
356 | + 'description' => __("The date the coupon was last modified, in the site's timezone.", 'woocommerce'), |
|
357 | 357 | 'type' => 'date-time', |
358 | - 'context' => array( 'view', 'edit' ), |
|
358 | + 'context' => array('view', 'edit'), |
|
359 | 359 | 'readonly' => true, |
360 | 360 | ), |
361 | 361 | 'date_modified_gmt' => array( |
362 | - 'description' => __( 'The date the coupon was last modified, as GMT.', 'woocommerce' ), |
|
362 | + 'description' => __('The date the coupon was last modified, as GMT.', 'woocommerce'), |
|
363 | 363 | 'type' => 'date-time', |
364 | - 'context' => array( 'view', 'edit' ), |
|
364 | + 'context' => array('view', 'edit'), |
|
365 | 365 | 'readonly' => true, |
366 | 366 | ), |
367 | 367 | 'discount_type' => array( |
368 | - 'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ), |
|
368 | + 'description' => __('Determines the type of discount that will be applied.', 'woocommerce'), |
|
369 | 369 | 'type' => 'string', |
370 | 370 | 'default' => 'fixed_cart', |
371 | - 'enum' => array_keys( wc_get_coupon_types() ), |
|
372 | - 'context' => array( 'view', 'edit' ), |
|
371 | + 'enum' => array_keys(wc_get_coupon_types()), |
|
372 | + 'context' => array('view', 'edit'), |
|
373 | 373 | ), |
374 | 374 | 'description' => array( |
375 | - 'description' => __( 'Coupon description.', 'woocommerce' ), |
|
375 | + 'description' => __('Coupon description.', 'woocommerce'), |
|
376 | 376 | 'type' => 'string', |
377 | - 'context' => array( 'view', 'edit' ), |
|
377 | + 'context' => array('view', 'edit'), |
|
378 | 378 | ), |
379 | 379 | 'date_expires' => array( |
380 | - 'description' => __( "The date the coupon expires, in the site's timezone.", 'woocommerce' ), |
|
380 | + 'description' => __("The date the coupon expires, in the site's timezone.", 'woocommerce'), |
|
381 | 381 | 'type' => 'string', |
382 | - 'context' => array( 'view', 'edit' ), |
|
382 | + 'context' => array('view', 'edit'), |
|
383 | 383 | ), |
384 | 384 | 'date_expires_gmt' => array( |
385 | - 'description' => __( 'The date the coupon expires, as GMT.', 'woocommerce' ), |
|
385 | + 'description' => __('The date the coupon expires, as GMT.', 'woocommerce'), |
|
386 | 386 | 'type' => 'string', |
387 | - 'context' => array( 'view', 'edit' ), |
|
387 | + 'context' => array('view', 'edit'), |
|
388 | 388 | ), |
389 | 389 | 'usage_count' => array( |
390 | - 'description' => __( 'Number of times the coupon has been used already.', 'woocommerce' ), |
|
390 | + 'description' => __('Number of times the coupon has been used already.', 'woocommerce'), |
|
391 | 391 | 'type' => 'integer', |
392 | - 'context' => array( 'view', 'edit' ), |
|
392 | + 'context' => array('view', 'edit'), |
|
393 | 393 | 'readonly' => true, |
394 | 394 | ), |
395 | 395 | 'individual_use' => array( |
396 | - 'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce' ), |
|
396 | + 'description' => __('If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce'), |
|
397 | 397 | 'type' => 'boolean', |
398 | 398 | 'default' => false, |
399 | - 'context' => array( 'view', 'edit' ), |
|
399 | + 'context' => array('view', 'edit'), |
|
400 | 400 | ), |
401 | 401 | 'product_ids' => array( |
402 | - 'description' => __( 'List of product IDs the coupon can be used on.', 'woocommerce' ), |
|
402 | + 'description' => __('List of product IDs the coupon can be used on.', 'woocommerce'), |
|
403 | 403 | 'type' => 'array', |
404 | 404 | 'items' => array( |
405 | 405 | 'type' => 'integer', |
406 | 406 | ), |
407 | - 'context' => array( 'view', 'edit' ), |
|
407 | + 'context' => array('view', 'edit'), |
|
408 | 408 | ), |
409 | 409 | 'excluded_product_ids' => array( |
410 | - 'description' => __( 'List of product IDs the coupon cannot be used on.', 'woocommerce' ), |
|
410 | + 'description' => __('List of product IDs the coupon cannot be used on.', 'woocommerce'), |
|
411 | 411 | 'type' => 'array', |
412 | 412 | 'items' => array( |
413 | 413 | 'type' => 'integer', |
414 | 414 | ), |
415 | - 'context' => array( 'view', 'edit' ), |
|
415 | + 'context' => array('view', 'edit'), |
|
416 | 416 | ), |
417 | 417 | 'usage_limit' => array( |
418 | - 'description' => __( 'How many times the coupon can be used in total.', 'woocommerce' ), |
|
418 | + 'description' => __('How many times the coupon can be used in total.', 'woocommerce'), |
|
419 | 419 | 'type' => 'integer', |
420 | - 'context' => array( 'view', 'edit' ), |
|
420 | + 'context' => array('view', 'edit'), |
|
421 | 421 | ), |
422 | 422 | 'usage_limit_per_user' => array( |
423 | - 'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce' ), |
|
423 | + 'description' => __('How many times the coupon can be used per customer.', 'woocommerce'), |
|
424 | 424 | 'type' => 'integer', |
425 | - 'context' => array( 'view', 'edit' ), |
|
425 | + 'context' => array('view', 'edit'), |
|
426 | 426 | ), |
427 | 427 | 'limit_usage_to_x_items' => array( |
428 | - 'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'woocommerce' ), |
|
428 | + 'description' => __('Max number of items in the cart the coupon can be applied to.', 'woocommerce'), |
|
429 | 429 | 'type' => 'integer', |
430 | - 'context' => array( 'view', 'edit' ), |
|
430 | + 'context' => array('view', 'edit'), |
|
431 | 431 | ), |
432 | 432 | 'free_shipping' => array( |
433 | - 'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce' ), |
|
433 | + 'description' => __('If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce'), |
|
434 | 434 | 'type' => 'boolean', |
435 | 435 | 'default' => false, |
436 | - 'context' => array( 'view', 'edit' ), |
|
436 | + 'context' => array('view', 'edit'), |
|
437 | 437 | ), |
438 | 438 | 'product_categories' => array( |
439 | - 'description' => __( 'List of category IDs the coupon applies to.', 'woocommerce' ), |
|
439 | + 'description' => __('List of category IDs the coupon applies to.', 'woocommerce'), |
|
440 | 440 | 'type' => 'array', |
441 | 441 | 'items' => array( |
442 | 442 | 'type' => 'integer', |
443 | 443 | ), |
444 | - 'context' => array( 'view', 'edit' ), |
|
444 | + 'context' => array('view', 'edit'), |
|
445 | 445 | ), |
446 | 446 | 'excluded_product_categories' => array( |
447 | - 'description' => __( 'List of category IDs the coupon does not apply to.', 'woocommerce' ), |
|
447 | + 'description' => __('List of category IDs the coupon does not apply to.', 'woocommerce'), |
|
448 | 448 | 'type' => 'array', |
449 | 449 | 'items' => array( |
450 | 450 | 'type' => 'integer', |
451 | 451 | ), |
452 | - 'context' => array( 'view', 'edit' ), |
|
452 | + 'context' => array('view', 'edit'), |
|
453 | 453 | ), |
454 | 454 | 'exclude_sale_items' => array( |
455 | - 'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'woocommerce' ), |
|
455 | + 'description' => __('If true, this coupon will not be applied to items that have sale prices.', 'woocommerce'), |
|
456 | 456 | 'type' => 'boolean', |
457 | 457 | 'default' => false, |
458 | - 'context' => array( 'view', 'edit' ), |
|
458 | + 'context' => array('view', 'edit'), |
|
459 | 459 | ), |
460 | 460 | 'minimum_amount' => array( |
461 | - 'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce' ), |
|
461 | + 'description' => __('Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce'), |
|
462 | 462 | 'type' => 'string', |
463 | - 'context' => array( 'view', 'edit' ), |
|
463 | + 'context' => array('view', 'edit'), |
|
464 | 464 | ), |
465 | 465 | 'maximum_amount' => array( |
466 | - 'description' => __( 'Maximum order amount allowed when using the coupon.', 'woocommerce' ), |
|
466 | + 'description' => __('Maximum order amount allowed when using the coupon.', 'woocommerce'), |
|
467 | 467 | 'type' => 'string', |
468 | - 'context' => array( 'view', 'edit' ), |
|
468 | + 'context' => array('view', 'edit'), |
|
469 | 469 | ), |
470 | 470 | 'email_restrictions' => array( |
471 | - 'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ), |
|
471 | + 'description' => __('List of email addresses that can use this coupon.', 'woocommerce'), |
|
472 | 472 | 'type' => 'array', |
473 | 473 | 'items' => array( |
474 | 474 | 'type' => 'string', |
475 | 475 | ), |
476 | - 'context' => array( 'view', 'edit' ), |
|
476 | + 'context' => array('view', 'edit'), |
|
477 | 477 | ), |
478 | 478 | 'used_by' => array( |
479 | - 'description' => __( 'List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce' ), |
|
479 | + 'description' => __('List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce'), |
|
480 | 480 | 'type' => 'array', |
481 | 481 | 'items' => array( |
482 | 482 | 'type' => 'integer', |
483 | 483 | ), |
484 | - 'context' => array( 'view', 'edit' ), |
|
484 | + 'context' => array('view', 'edit'), |
|
485 | 485 | 'readonly' => true, |
486 | 486 | ), |
487 | 487 | 'meta_data' => array( |
488 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
488 | + 'description' => __('Meta data.', 'woocommerce'), |
|
489 | 489 | 'type' => 'array', |
490 | - 'context' => array( 'view', 'edit' ), |
|
490 | + 'context' => array('view', 'edit'), |
|
491 | 491 | 'items' => array( |
492 | 492 | 'type' => 'object', |
493 | 493 | 'properties' => array( |
494 | 494 | 'id' => array( |
495 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
495 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
496 | 496 | 'type' => 'integer', |
497 | - 'context' => array( 'view', 'edit' ), |
|
497 | + 'context' => array('view', 'edit'), |
|
498 | 498 | 'readonly' => true, |
499 | 499 | ), |
500 | 500 | 'key' => array( |
501 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
501 | + 'description' => __('Meta key.', 'woocommerce'), |
|
502 | 502 | 'type' => 'string', |
503 | - 'context' => array( 'view', 'edit' ), |
|
503 | + 'context' => array('view', 'edit'), |
|
504 | 504 | ), |
505 | 505 | 'value' => array( |
506 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
506 | + 'description' => __('Meta value.', 'woocommerce'), |
|
507 | 507 | 'type' => 'mixed', |
508 | - 'context' => array( 'view', 'edit' ), |
|
508 | + 'context' => array('view', 'edit'), |
|
509 | 509 | ), |
510 | 510 | ), |
511 | 511 | ), |
512 | 512 | ), |
513 | 513 | ), |
514 | 514 | ); |
515 | - return $this->add_additional_fields_schema( $schema ); |
|
515 | + return $this->add_additional_fields_schema($schema); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -524,14 +524,14 @@ discard block |
||
524 | 524 | $params = parent::get_collection_params(); |
525 | 525 | |
526 | 526 | $params['code'] = array( |
527 | - 'description' => __( 'Limit result set to resources with a specific code.', 'woocommerce' ), |
|
527 | + 'description' => __('Limit result set to resources with a specific code.', 'woocommerce'), |
|
528 | 528 | 'type' => 'string', |
529 | 529 | 'sanitize_callback' => 'sanitize_text_field', |
530 | 530 | 'validate_callback' => 'rest_validate_request_arg', |
531 | 531 | ); |
532 | 532 | |
533 | 533 | $params['search'] = array( |
534 | - 'description' => __( 'Limit results to coupons with codes matching a given string.', 'woocommerce' ), |
|
534 | + 'description' => __('Limit results to coupons with codes matching a given string.', 'woocommerce'), |
|
535 | 535 | 'type' => 'string', |
536 | 536 | 'validate_callback' => 'rest_validate_request_arg', |
537 | 537 | ); |
@@ -545,8 +545,8 @@ discard block |
||
545 | 545 | * @param array $schema Schema array. |
546 | 546 | * @return bool |
547 | 547 | */ |
548 | - protected function filter_writable_props( $schema ) { |
|
549 | - return empty( $schema['readonly'] ); |
|
548 | + protected function filter_writable_props($schema) { |
|
549 | + return empty($schema['readonly']); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
@@ -555,10 +555,10 @@ discard block |
||
555 | 555 | * @param \WP_REST_Request $request Full details about the request. |
556 | 556 | * @return \WP_Error\WP_REST_Response |
557 | 557 | */ |
558 | - public function get_items( $request ) { |
|
559 | - add_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10, 2 ); |
|
560 | - $response = parent::get_items( $request ); |
|
561 | - remove_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10 ); |
|
558 | + public function get_items($request) { |
|
559 | + add_filter('posts_where', array($this, 'add_wp_query_search_code_filter'), 10, 2); |
|
560 | + $response = parent::get_items($request); |
|
561 | + remove_filter('posts_where', array($this, 'add_wp_query_search_code_filter'), 10); |
|
562 | 562 | return $response; |
563 | 563 | } |
564 | 564 | |
@@ -569,12 +569,12 @@ discard block |
||
569 | 569 | * @param object $wp_query \WP_Query object. |
570 | 570 | * @return string |
571 | 571 | */ |
572 | - public function add_wp_query_search_code_filter( $where, $wp_query ) { |
|
572 | + public function add_wp_query_search_code_filter($where, $wp_query) { |
|
573 | 573 | global $wpdb; |
574 | 574 | |
575 | - $search = $wp_query->get( 'search' ); |
|
576 | - if ( $search ) { |
|
577 | - $search = $wpdb->esc_like( $search ); |
|
575 | + $search = $wp_query->get('search'); |
|
576 | + if ($search) { |
|
577 | + $search = $wpdb->esc_like($search); |
|
578 | 578 | $search = "'%" . $search . "%'"; |
579 | 579 | $where .= ' AND ' . $wpdb->posts . '.post_title LIKE ' . $search; |
580 | 580 | } |