@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -40,88 +40,88 @@ discard block |
||
40 | 40 | * Register the routes for customers. |
41 | 41 | */ |
42 | 42 | public function register_routes() { |
43 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
43 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
44 | 44 | array( |
45 | 45 | 'methods' => WP_REST_Server::READABLE, |
46 | - 'callback' => array( $this, 'get_items' ), |
|
47 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
46 | + 'callback' => array($this, 'get_items'), |
|
47 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
48 | 48 | 'args' => $this->get_collection_params(), |
49 | 49 | ), |
50 | 50 | array( |
51 | 51 | 'methods' => WP_REST_Server::CREATABLE, |
52 | - 'callback' => array( $this, 'create_item' ), |
|
53 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
54 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
52 | + 'callback' => array($this, 'create_item'), |
|
53 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
54 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
55 | 55 | 'email' => array( |
56 | 56 | 'required' => true, |
57 | 57 | 'type' => 'string', |
58 | - 'description' => __( 'New user email address.', 'woocommerce' ), |
|
58 | + 'description' => __('New user email address.', 'woocommerce'), |
|
59 | 59 | ), |
60 | 60 | 'username' => array( |
61 | - 'required' => 'no' === get_option( 'woocommerce_registration_generate_username', 'yes' ), |
|
62 | - 'description' => __( 'New user username.', 'woocommerce' ), |
|
61 | + 'required' => 'no' === get_option('woocommerce_registration_generate_username', 'yes'), |
|
62 | + 'description' => __('New user username.', 'woocommerce'), |
|
63 | 63 | 'type' => 'string', |
64 | 64 | ), |
65 | 65 | 'password' => array( |
66 | - 'required' => 'no' === get_option( 'woocommerce_registration_generate_password', 'no' ), |
|
67 | - 'description' => __( 'New user password.', 'woocommerce' ), |
|
66 | + 'required' => 'no' === get_option('woocommerce_registration_generate_password', 'no'), |
|
67 | + 'description' => __('New user password.', 'woocommerce'), |
|
68 | 68 | 'type' => 'string', |
69 | 69 | ), |
70 | - ) ), |
|
70 | + )), |
|
71 | 71 | ), |
72 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
73 | - ) ); |
|
72 | + 'schema' => array($this, 'get_public_item_schema'), |
|
73 | + )); |
|
74 | 74 | |
75 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
75 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
76 | 76 | 'args' => array( |
77 | 77 | 'id' => array( |
78 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
78 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
79 | 79 | 'type' => 'integer', |
80 | 80 | ), |
81 | 81 | ), |
82 | 82 | array( |
83 | 83 | 'methods' => WP_REST_Server::READABLE, |
84 | - 'callback' => array( $this, 'get_item' ), |
|
85 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
84 | + 'callback' => array($this, 'get_item'), |
|
85 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
86 | 86 | 'args' => array( |
87 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
87 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
88 | 88 | ), |
89 | 89 | ), |
90 | 90 | array( |
91 | 91 | 'methods' => WP_REST_Server::EDITABLE, |
92 | - 'callback' => array( $this, 'update_item' ), |
|
93 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
94 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
92 | + 'callback' => array($this, 'update_item'), |
|
93 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
94 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
95 | 95 | ), |
96 | 96 | array( |
97 | 97 | 'methods' => WP_REST_Server::DELETABLE, |
98 | - 'callback' => array( $this, 'delete_item' ), |
|
99 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
98 | + 'callback' => array($this, 'delete_item'), |
|
99 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
100 | 100 | 'args' => array( |
101 | 101 | 'force' => array( |
102 | 102 | 'default' => false, |
103 | 103 | 'type' => 'boolean', |
104 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
104 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
105 | 105 | ), |
106 | 106 | 'reassign' => array( |
107 | 107 | 'default' => 0, |
108 | 108 | 'type' => 'integer', |
109 | - 'description' => __( 'ID to reassign posts to.', 'woocommerce' ), |
|
109 | + 'description' => __('ID to reassign posts to.', 'woocommerce'), |
|
110 | 110 | ), |
111 | 111 | ), |
112 | 112 | ), |
113 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
114 | - ) ); |
|
113 | + 'schema' => array($this, 'get_public_item_schema'), |
|
114 | + )); |
|
115 | 115 | |
116 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
116 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
117 | 117 | array( |
118 | 118 | 'methods' => WP_REST_Server::EDITABLE, |
119 | - 'callback' => array( $this, 'batch_items' ), |
|
120 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
121 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
119 | + 'callback' => array($this, 'batch_items'), |
|
120 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
121 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
122 | 122 | ), |
123 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
124 | - ) ); |
|
123 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
124 | + )); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | * @param WP_REST_Request $request Full details about the request. |
131 | 131 | * @return WP_Error|boolean |
132 | 132 | */ |
133 | - public function get_items_permissions_check( $request ) { |
|
134 | - if ( ! wc_rest_check_user_permissions( 'read' ) ) { |
|
135 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
133 | + public function get_items_permissions_check($request) { |
|
134 | + if ( ! wc_rest_check_user_permissions('read')) { |
|
135 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | return true; |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return bool|WP_Error |
147 | 147 | */ |
148 | - public function create_item_permissions_check( $request ) { |
|
149 | - if ( ! wc_rest_check_user_permissions( 'create' ) ) { |
|
150 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
148 | + public function create_item_permissions_check($request) { |
|
149 | + if ( ! wc_rest_check_user_permissions('create')) { |
|
150 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | return true; |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | * @param WP_REST_Request $request Full details about the request. |
160 | 160 | * @return WP_Error|boolean |
161 | 161 | */ |
162 | - public function get_item_permissions_check( $request ) { |
|
162 | + public function get_item_permissions_check($request) { |
|
163 | 163 | $id = (int) $request['id']; |
164 | 164 | |
165 | - if ( ! wc_rest_check_user_permissions( 'read', $id ) ) { |
|
166 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
165 | + if ( ! wc_rest_check_user_permissions('read', $id)) { |
|
166 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | return true; |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @return bool|WP_Error |
178 | 178 | */ |
179 | - public function update_item_permissions_check( $request ) { |
|
179 | + public function update_item_permissions_check($request) { |
|
180 | 180 | $id = (int) $request['id']; |
181 | 181 | |
182 | - if ( ! wc_rest_check_user_permissions( 'edit', $id ) ) { |
|
183 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
182 | + if ( ! wc_rest_check_user_permissions('edit', $id)) { |
|
183 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | return true; |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return bool|WP_Error |
195 | 195 | */ |
196 | - public function delete_item_permissions_check( $request ) { |
|
196 | + public function delete_item_permissions_check($request) { |
|
197 | 197 | $id = (int) $request['id']; |
198 | 198 | |
199 | - if ( ! wc_rest_check_user_permissions( 'delete', $id ) ) { |
|
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_user_permissions('delete', $id)) { |
|
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_user_permissions( '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_user_permissions('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 Full details about the request. |
225 | 225 | * @return WP_Error|WP_REST_Response |
226 | 226 | */ |
227 | - public function get_items( $request ) { |
|
227 | + public function get_items($request) { |
|
228 | 228 | $prepared_args = array(); |
229 | 229 | $prepared_args['exclude'] = $request['exclude']; |
230 | 230 | $prepared_args['include'] = $request['include']; |
231 | 231 | $prepared_args['order'] = $request['order']; |
232 | 232 | $prepared_args['number'] = $request['per_page']; |
233 | - if ( ! empty( $request['offset'] ) ) { |
|
233 | + if ( ! empty($request['offset'])) { |
|
234 | 234 | $prepared_args['offset'] = $request['offset']; |
235 | 235 | } else { |
236 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
236 | + $prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number']; |
|
237 | 237 | } |
238 | 238 | $orderby_possibles = array( |
239 | 239 | 'id' => 'ID', |
@@ -241,21 +241,21 @@ discard block |
||
241 | 241 | 'name' => 'display_name', |
242 | 242 | 'registered_date' => 'registered', |
243 | 243 | ); |
244 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
244 | + $prepared_args['orderby'] = $orderby_possibles[$request['orderby']]; |
|
245 | 245 | $prepared_args['search'] = $request['search']; |
246 | 246 | |
247 | - if ( '' !== $prepared_args['search'] ) { |
|
247 | + if ('' !== $prepared_args['search']) { |
|
248 | 248 | $prepared_args['search'] = '*' . $prepared_args['search'] . '*'; |
249 | 249 | } |
250 | 250 | |
251 | 251 | // Filter by email. |
252 | - if ( ! empty( $request['email'] ) ) { |
|
252 | + if ( ! empty($request['email'])) { |
|
253 | 253 | $prepared_args['search'] = $request['email']; |
254 | - $prepared_args['search_columns'] = array( 'user_email' ); |
|
254 | + $prepared_args['search_columns'] = array('user_email'); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | // Filter by role. |
258 | - if ( 'all' !== $request['role'] ) { |
|
258 | + if ('all' !== $request['role']) { |
|
259 | 259 | $prepared_args['role'] = $request['role']; |
260 | 260 | } |
261 | 261 | |
@@ -267,49 +267,49 @@ discard block |
||
267 | 267 | * @param array $prepared_args Array of arguments for WP_User_Query. |
268 | 268 | * @param WP_REST_Request $request The current request. |
269 | 269 | */ |
270 | - $prepared_args = apply_filters( 'woocommerce_rest_customer_query', $prepared_args, $request ); |
|
270 | + $prepared_args = apply_filters('woocommerce_rest_customer_query', $prepared_args, $request); |
|
271 | 271 | |
272 | - $query = new WP_User_Query( $prepared_args ); |
|
272 | + $query = new WP_User_Query($prepared_args); |
|
273 | 273 | |
274 | 274 | $users = array(); |
275 | - foreach ( $query->results as $user ) { |
|
276 | - $data = $this->prepare_item_for_response( $user, $request ); |
|
277 | - $users[] = $this->prepare_response_for_collection( $data ); |
|
275 | + foreach ($query->results as $user) { |
|
276 | + $data = $this->prepare_item_for_response($user, $request); |
|
277 | + $users[] = $this->prepare_response_for_collection($data); |
|
278 | 278 | } |
279 | 279 | |
280 | - $response = rest_ensure_response( $users ); |
|
280 | + $response = rest_ensure_response($users); |
|
281 | 281 | |
282 | 282 | // Store pagination values for headers then unset for count query. |
283 | 283 | $per_page = (int) $prepared_args['number']; |
284 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
284 | + $page = ceil((((int) $prepared_args['offset']) / $per_page) + 1); |
|
285 | 285 | |
286 | 286 | $prepared_args['fields'] = 'ID'; |
287 | 287 | |
288 | 288 | $total_users = $query->get_total(); |
289 | - if ( $total_users < 1 ) { |
|
289 | + if ($total_users < 1) { |
|
290 | 290 | // Out-of-bounds, run the query again without LIMIT for total count. |
291 | - unset( $prepared_args['number'] ); |
|
292 | - unset( $prepared_args['offset'] ); |
|
293 | - $count_query = new WP_User_Query( $prepared_args ); |
|
291 | + unset($prepared_args['number']); |
|
292 | + unset($prepared_args['offset']); |
|
293 | + $count_query = new WP_User_Query($prepared_args); |
|
294 | 294 | $total_users = $count_query->get_total(); |
295 | 295 | } |
296 | - $response->header( 'X-WP-Total', (int) $total_users ); |
|
297 | - $max_pages = ceil( $total_users / $per_page ); |
|
298 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
296 | + $response->header('X-WP-Total', (int) $total_users); |
|
297 | + $max_pages = ceil($total_users / $per_page); |
|
298 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
299 | 299 | |
300 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
301 | - if ( $page > 1 ) { |
|
300 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
301 | + if ($page > 1) { |
|
302 | 302 | $prev_page = $page - 1; |
303 | - if ( $prev_page > $max_pages ) { |
|
303 | + if ($prev_page > $max_pages) { |
|
304 | 304 | $prev_page = $max_pages; |
305 | 305 | } |
306 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
307 | - $response->link_header( 'prev', $prev_link ); |
|
306 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
307 | + $response->link_header('prev', $prev_link); |
|
308 | 308 | } |
309 | - if ( $max_pages > $page ) { |
|
309 | + if ($max_pages > $page) { |
|
310 | 310 | $next_page = $page + 1; |
311 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
312 | - $response->link_header( 'next', $next_link ); |
|
311 | + $next_link = add_query_arg('page', $next_page, $base); |
|
312 | + $response->link_header('next', $next_link); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | return $response; |
@@ -321,32 +321,32 @@ discard block |
||
321 | 321 | * @param WP_REST_Request $request Full details about the request. |
322 | 322 | * @return WP_Error|WP_REST_Response |
323 | 323 | */ |
324 | - public function create_item( $request ) { |
|
324 | + public function create_item($request) { |
|
325 | 325 | try { |
326 | - if ( ! empty( $request['id'] ) ) { |
|
327 | - throw new WC_REST_Exception( 'woocommerce_rest_customer_exists', __( 'Cannot create existing resource.', 'woocommerce' ), 400 ); |
|
326 | + if ( ! empty($request['id'])) { |
|
327 | + throw new WC_REST_Exception('woocommerce_rest_customer_exists', __('Cannot create existing resource.', 'woocommerce'), 400); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | // Sets the username. |
331 | - $request['username'] = ! empty( $request['username'] ) ? $request['username'] : ''; |
|
331 | + $request['username'] = ! empty($request['username']) ? $request['username'] : ''; |
|
332 | 332 | |
333 | 333 | // Sets the password. |
334 | - $request['password'] = ! empty( $request['password'] ) ? $request['password'] : ''; |
|
334 | + $request['password'] = ! empty($request['password']) ? $request['password'] : ''; |
|
335 | 335 | |
336 | 336 | // Create customer. |
337 | 337 | $customer = new WC_Customer; |
338 | - $customer->set_username( $request['username'] ); |
|
339 | - $customer->set_password( $request['password'] ); |
|
340 | - $customer->set_email( $request['email'] ); |
|
341 | - $this->update_customer_meta_fields( $customer, $request ); |
|
338 | + $customer->set_username($request['username']); |
|
339 | + $customer->set_password($request['password']); |
|
340 | + $customer->set_email($request['email']); |
|
341 | + $this->update_customer_meta_fields($customer, $request); |
|
342 | 342 | $customer->save(); |
343 | 343 | |
344 | - if ( ! $customer->get_id() ) { |
|
345 | - throw new WC_REST_Exception( 'woocommerce_rest_cannot_create', __( 'This resource cannot be created.', 'woocommerce' ), 400 ); |
|
344 | + if ( ! $customer->get_id()) { |
|
345 | + throw new WC_REST_Exception('woocommerce_rest_cannot_create', __('This resource cannot be created.', 'woocommerce'), 400); |
|
346 | 346 | } |
347 | 347 | |
348 | - $user_data = get_userdata( $customer->get_id() ); |
|
349 | - $this->update_additional_fields_for_object( $user_data, $request ); |
|
348 | + $user_data = get_userdata($customer->get_id()); |
|
349 | + $this->update_additional_fields_for_object($user_data, $request); |
|
350 | 350 | |
351 | 351 | /** |
352 | 352 | * Fires after a customer is created or updated via the REST API. |
@@ -355,17 +355,17 @@ discard block |
||
355 | 355 | * @param WP_REST_Request $request Request object. |
356 | 356 | * @param boolean $creating True when creating customer, false when updating customer. |
357 | 357 | */ |
358 | - do_action( 'woocommerce_rest_insert_customer', $user_data, $request, true ); |
|
358 | + do_action('woocommerce_rest_insert_customer', $user_data, $request, true); |
|
359 | 359 | |
360 | - $request->set_param( 'context', 'edit' ); |
|
361 | - $response = $this->prepare_item_for_response( $user_data, $request ); |
|
362 | - $response = rest_ensure_response( $response ); |
|
363 | - $response->set_status( 201 ); |
|
364 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $customer->get_id() ) ) ); |
|
360 | + $request->set_param('context', 'edit'); |
|
361 | + $response = $this->prepare_item_for_response($user_data, $request); |
|
362 | + $response = rest_ensure_response($response); |
|
363 | + $response->set_status(201); |
|
364 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $customer->get_id()))); |
|
365 | 365 | |
366 | 366 | return $response; |
367 | - } catch ( Exception $e ) { |
|
368 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
367 | + } catch (Exception $e) { |
|
368 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
369 | 369 | } |
370 | 370 | } |
371 | 371 | |
@@ -375,16 +375,16 @@ discard block |
||
375 | 375 | * @param WP_REST_Request $request Full details about the request. |
376 | 376 | * @return WP_Error|WP_REST_Response |
377 | 377 | */ |
378 | - public function get_item( $request ) { |
|
378 | + public function get_item($request) { |
|
379 | 379 | $id = (int) $request['id']; |
380 | - $user_data = get_userdata( $id ); |
|
380 | + $user_data = get_userdata($id); |
|
381 | 381 | |
382 | - if ( empty( $id ) || empty( $user_data->ID ) ) { |
|
383 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
382 | + if (empty($id) || empty($user_data->ID)) { |
|
383 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
384 | 384 | } |
385 | 385 | |
386 | - $customer = $this->prepare_item_for_response( $user_data, $request ); |
|
387 | - $response = rest_ensure_response( $customer ); |
|
386 | + $customer = $this->prepare_item_for_response($user_data, $request); |
|
387 | + $response = rest_ensure_response($customer); |
|
388 | 388 | |
389 | 389 | return $response; |
390 | 390 | } |
@@ -395,41 +395,41 @@ discard block |
||
395 | 395 | * @param WP_REST_Request $request Full details about the request. |
396 | 396 | * @return WP_Error|WP_REST_Response |
397 | 397 | */ |
398 | - public function update_item( $request ) { |
|
398 | + public function update_item($request) { |
|
399 | 399 | try { |
400 | 400 | $id = (int) $request['id']; |
401 | - $customer = new WC_Customer( $id ); |
|
401 | + $customer = new WC_Customer($id); |
|
402 | 402 | |
403 | - if ( ! $customer->get_id() ) { |
|
404 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), 400 ); |
|
403 | + if ( ! $customer->get_id()) { |
|
404 | + throw new WC_REST_Exception('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), 400); |
|
405 | 405 | } |
406 | 406 | |
407 | - if ( ! empty( $request['email'] ) && email_exists( $request['email'] ) && $request['email'] !== $customer->get_email() ) { |
|
408 | - throw new WC_REST_Exception( 'woocommerce_rest_customer_invalid_email', __( 'Email address is invalid.', 'woocommerce' ), 400 ); |
|
407 | + if ( ! empty($request['email']) && email_exists($request['email']) && $request['email'] !== $customer->get_email()) { |
|
408 | + throw new WC_REST_Exception('woocommerce_rest_customer_invalid_email', __('Email address is invalid.', 'woocommerce'), 400); |
|
409 | 409 | } |
410 | 410 | |
411 | - if ( ! empty( $request['username'] ) && $request['username'] !== $customer->get_username() ) { |
|
412 | - throw new WC_REST_Exception( 'woocommerce_rest_customer_invalid_argument', __( "Username isn't editable.", 'woocommerce' ), 400 ); |
|
411 | + if ( ! empty($request['username']) && $request['username'] !== $customer->get_username()) { |
|
412 | + throw new WC_REST_Exception('woocommerce_rest_customer_invalid_argument', __("Username isn't editable.", 'woocommerce'), 400); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | // Customer email. |
416 | - if ( isset( $request['email'] ) ) { |
|
417 | - $customer->set_email( sanitize_email( $request['email'] ) ); |
|
416 | + if (isset($request['email'])) { |
|
417 | + $customer->set_email(sanitize_email($request['email'])); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | // Customer password. |
421 | - if ( isset( $request['password'] ) ) { |
|
422 | - $customer->set_password( $request['password'] ); |
|
421 | + if (isset($request['password'])) { |
|
422 | + $customer->set_password($request['password']); |
|
423 | 423 | } |
424 | 424 | |
425 | - $this->update_customer_meta_fields( $customer, $request ); |
|
425 | + $this->update_customer_meta_fields($customer, $request); |
|
426 | 426 | $customer->save(); |
427 | 427 | |
428 | - $user_data = get_userdata( $customer->get_id() ); |
|
429 | - $this->update_additional_fields_for_object( $user_data, $request ); |
|
428 | + $user_data = get_userdata($customer->get_id()); |
|
429 | + $this->update_additional_fields_for_object($user_data, $request); |
|
430 | 430 | |
431 | - if ( ! is_user_member_of_blog( $user_data->ID ) ) { |
|
432 | - $user_data->add_role( 'customer' ); |
|
431 | + if ( ! is_user_member_of_blog($user_data->ID)) { |
|
432 | + $user_data->add_role('customer'); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -439,14 +439,14 @@ discard block |
||
439 | 439 | * @param WP_REST_Request $request Request object. |
440 | 440 | * @param boolean $creating True when creating customer, false when updating customer. |
441 | 441 | */ |
442 | - do_action( 'woocommerce_rest_insert_customer', $user_data, $request, false ); |
|
442 | + do_action('woocommerce_rest_insert_customer', $user_data, $request, false); |
|
443 | 443 | |
444 | - $request->set_param( 'context', 'edit' ); |
|
445 | - $response = $this->prepare_item_for_response( $user_data, $request ); |
|
446 | - $response = rest_ensure_response( $response ); |
|
444 | + $request->set_param('context', 'edit'); |
|
445 | + $response = $this->prepare_item_for_response($user_data, $request); |
|
446 | + $response = rest_ensure_response($response); |
|
447 | 447 | return $response; |
448 | - } catch ( Exception $e ) { |
|
449 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
448 | + } catch (Exception $e) { |
|
449 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
450 | 450 | } |
451 | 451 | } |
452 | 452 | |
@@ -456,43 +456,43 @@ discard block |
||
456 | 456 | * @param WP_REST_Request $request Full details about the request. |
457 | 457 | * @return WP_Error|WP_REST_Response |
458 | 458 | */ |
459 | - public function delete_item( $request ) { |
|
459 | + public function delete_item($request) { |
|
460 | 460 | $id = (int) $request['id']; |
461 | - $reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null; |
|
462 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
461 | + $reassign = isset($request['reassign']) ? absint($request['reassign']) : null; |
|
462 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
463 | 463 | |
464 | 464 | // We don't support trashing for this type, error out. |
465 | - if ( ! $force ) { |
|
466 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Customers do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
465 | + if ( ! $force) { |
|
466 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Customers do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
467 | 467 | } |
468 | 468 | |
469 | - $user_data = get_userdata( $id ); |
|
470 | - if ( ! $user_data ) { |
|
471 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
469 | + $user_data = get_userdata($id); |
|
470 | + if ( ! $user_data) { |
|
471 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400)); |
|
472 | 472 | } |
473 | 473 | |
474 | - if ( ! empty( $reassign ) ) { |
|
475 | - if ( $reassign === $id || ! get_userdata( $reassign ) ) { |
|
476 | - return new WP_Error( 'woocommerce_rest_customer_invalid_reassign', __( 'Invalid resource id for reassignment.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
474 | + if ( ! empty($reassign)) { |
|
475 | + if ($reassign === $id || ! get_userdata($reassign)) { |
|
476 | + return new WP_Error('woocommerce_rest_customer_invalid_reassign', __('Invalid resource id for reassignment.', 'woocommerce'), array('status' => 400)); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
480 | - $request->set_param( 'context', 'edit' ); |
|
481 | - $response = $this->prepare_item_for_response( $user_data, $request ); |
|
480 | + $request->set_param('context', 'edit'); |
|
481 | + $response = $this->prepare_item_for_response($user_data, $request); |
|
482 | 482 | |
483 | 483 | /** Include admin customer functions to get access to wp_delete_user() */ |
484 | 484 | require_once ABSPATH . 'wp-admin/includes/user.php'; |
485 | 485 | |
486 | - $customer = new WC_Customer( $id ); |
|
486 | + $customer = new WC_Customer($id); |
|
487 | 487 | |
488 | - if ( ! is_null( $reassign ) ) { |
|
489 | - $result = $customer->delete_and_reassign( $reassign ); |
|
488 | + if ( ! is_null($reassign)) { |
|
489 | + $result = $customer->delete_and_reassign($reassign); |
|
490 | 490 | } else { |
491 | 491 | $result = $customer->delete(); |
492 | 492 | } |
493 | 493 | |
494 | - if ( ! $result ) { |
|
495 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
494 | + if ( ! $result) { |
|
495 | + return new WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | * @param WP_REST_Response $response The response returned from the API. |
503 | 503 | * @param WP_REST_Request $request The request sent to the API. |
504 | 504 | */ |
505 | - do_action( 'woocommerce_rest_delete_customer', $user_data, $response, $request ); |
|
505 | + do_action('woocommerce_rest_delete_customer', $user_data, $response, $request); |
|
506 | 506 | |
507 | 507 | return $response; |
508 | 508 | } |
@@ -514,15 +514,15 @@ discard block |
||
514 | 514 | * @param WP_REST_Request $request Request object. |
515 | 515 | * @return WP_REST_Response $response Response data. |
516 | 516 | */ |
517 | - public function prepare_item_for_response( $user_data, $request ) { |
|
518 | - $customer = new WC_Customer( $user_data->ID ); |
|
517 | + public function prepare_item_for_response($user_data, $request) { |
|
518 | + $customer = new WC_Customer($user_data->ID); |
|
519 | 519 | $_data = $customer->get_data(); |
520 | - $last_order = wc_get_customer_last_order( $customer->get_id() ); |
|
521 | - $format_date = array( 'date_created', 'date_modified' ); |
|
520 | + $last_order = wc_get_customer_last_order($customer->get_id()); |
|
521 | + $format_date = array('date_created', 'date_modified'); |
|
522 | 522 | |
523 | 523 | // Format date values. |
524 | - foreach ( $format_date as $key ) { |
|
525 | - $_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ] ) : null; // v1 API used UTC. |
|
524 | + foreach ($format_date as $key) { |
|
525 | + $_data[$key] = $_data[$key] ? wc_rest_prepare_date_response($_data[$key]) : null; // v1 API used UTC. |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | $data = array( |
@@ -534,8 +534,8 @@ discard block |
||
534 | 534 | 'last_name' => $_data['last_name'], |
535 | 535 | 'username' => $_data['username'], |
536 | 536 | 'last_order' => array( |
537 | - 'id' => is_object( $last_order ) ? $last_order->get_id() : null, |
|
538 | - 'date' => is_object( $last_order ) ? wc_rest_prepare_date_response( $last_order->get_date_created() ) : null, // v1 API used UTC. |
|
537 | + 'id' => is_object($last_order) ? $last_order->get_id() : null, |
|
538 | + 'date' => is_object($last_order) ? wc_rest_prepare_date_response($last_order->get_date_created()) : null, // v1 API used UTC. |
|
539 | 539 | ), |
540 | 540 | 'orders_count' => $customer->get_order_count(), |
541 | 541 | 'total_spent' => $customer->get_total_spent(), |
@@ -544,11 +544,11 @@ discard block |
||
544 | 544 | 'shipping' => $_data['shipping'], |
545 | 545 | ); |
546 | 546 | |
547 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
548 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
549 | - $data = $this->filter_response_by_context( $data, $context ); |
|
550 | - $response = rest_ensure_response( $data ); |
|
551 | - $response->add_links( $this->prepare_links( $user_data ) ); |
|
547 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
548 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
549 | + $data = $this->filter_response_by_context($data, $context); |
|
550 | + $response = rest_ensure_response($data); |
|
551 | + $response->add_links($this->prepare_links($user_data)); |
|
552 | 552 | |
553 | 553 | /** |
554 | 554 | * Filter customer data returned from the REST API. |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | * @param WP_User $user_data User object used to create response. |
558 | 558 | * @param WP_REST_Request $request Request object. |
559 | 559 | */ |
560 | - return apply_filters( 'woocommerce_rest_prepare_customer', $response, $user_data, $request ); |
|
560 | + return apply_filters('woocommerce_rest_prepare_customer', $response, $user_data, $request); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -566,33 +566,33 @@ discard block |
||
566 | 566 | * @param WC_Customer $customer |
567 | 567 | * @param WP_REST_Request $request |
568 | 568 | */ |
569 | - protected function update_customer_meta_fields( $customer, $request ) { |
|
569 | + protected function update_customer_meta_fields($customer, $request) { |
|
570 | 570 | $schema = $this->get_item_schema(); |
571 | 571 | |
572 | 572 | // Customer first name. |
573 | - if ( isset( $request['first_name'] ) ) { |
|
574 | - $customer->set_first_name( wc_clean( $request['first_name'] ) ); |
|
573 | + if (isset($request['first_name'])) { |
|
574 | + $customer->set_first_name(wc_clean($request['first_name'])); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | // Customer last name. |
578 | - if ( isset( $request['last_name'] ) ) { |
|
579 | - $customer->set_last_name( wc_clean( $request['last_name'] ) ); |
|
578 | + if (isset($request['last_name'])) { |
|
579 | + $customer->set_last_name(wc_clean($request['last_name'])); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | // Customer billing address. |
583 | - if ( isset( $request['billing'] ) ) { |
|
584 | - foreach ( array_keys( $schema['properties']['billing']['properties'] ) as $field ) { |
|
585 | - if ( isset( $request['billing'][ $field ] ) && is_callable( array( $customer, "set_billing_{$field}" ) ) ) { |
|
586 | - $customer->{"set_billing_{$field}"}( $request['billing'][ $field ] ); |
|
583 | + if (isset($request['billing'])) { |
|
584 | + foreach (array_keys($schema['properties']['billing']['properties']) as $field) { |
|
585 | + if (isset($request['billing'][$field]) && is_callable(array($customer, "set_billing_{$field}"))) { |
|
586 | + $customer->{"set_billing_{$field}"}($request['billing'][$field]); |
|
587 | 587 | } |
588 | 588 | } |
589 | 589 | } |
590 | 590 | |
591 | 591 | // Customer shipping address. |
592 | - if ( isset( $request['shipping'] ) ) { |
|
593 | - foreach ( array_keys( $schema['properties']['shipping']['properties'] ) as $field ) { |
|
594 | - if ( isset( $request['shipping'][ $field ] ) && is_callable( array( $customer, "set_shipping_{$field}" ) ) ) { |
|
595 | - $customer->{"set_shipping_{$field}"}( $request['shipping'][ $field ] ); |
|
592 | + if (isset($request['shipping'])) { |
|
593 | + foreach (array_keys($schema['properties']['shipping']['properties']) as $field) { |
|
594 | + if (isset($request['shipping'][$field]) && is_callable(array($customer, "set_shipping_{$field}"))) { |
|
595 | + $customer->{"set_shipping_{$field}"}($request['shipping'][$field]); |
|
596 | 596 | } |
597 | 597 | } |
598 | 598 | } |
@@ -604,13 +604,13 @@ discard block |
||
604 | 604 | * @param WP_User $customer Customer object. |
605 | 605 | * @return array Links for the given customer. |
606 | 606 | */ |
607 | - protected function prepare_links( $customer ) { |
|
607 | + protected function prepare_links($customer) { |
|
608 | 608 | $links = array( |
609 | 609 | 'self' => array( |
610 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $customer->ID ) ), |
|
610 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $customer->ID)), |
|
611 | 611 | ), |
612 | 612 | 'collection' => array( |
613 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
613 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
614 | 614 | ), |
615 | 615 | ); |
616 | 616 | |
@@ -629,215 +629,215 @@ discard block |
||
629 | 629 | 'type' => 'object', |
630 | 630 | 'properties' => array( |
631 | 631 | 'id' => array( |
632 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
632 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
633 | 633 | 'type' => 'integer', |
634 | - 'context' => array( 'view', 'edit' ), |
|
634 | + 'context' => array('view', 'edit'), |
|
635 | 635 | 'readonly' => true, |
636 | 636 | ), |
637 | 637 | 'date_created' => array( |
638 | - 'description' => __( 'The date the customer was created, as GMT.', 'woocommerce' ), |
|
638 | + 'description' => __('The date the customer was created, as GMT.', 'woocommerce'), |
|
639 | 639 | 'type' => 'date-time', |
640 | - 'context' => array( 'view', 'edit' ), |
|
640 | + 'context' => array('view', 'edit'), |
|
641 | 641 | 'readonly' => true, |
642 | 642 | ), |
643 | 643 | 'date_modified' => array( |
644 | - 'description' => __( 'The date the customer was last modified, as GMT.', 'woocommerce' ), |
|
644 | + 'description' => __('The date the customer was last modified, as GMT.', 'woocommerce'), |
|
645 | 645 | 'type' => 'date-time', |
646 | - 'context' => array( 'view', 'edit' ), |
|
646 | + 'context' => array('view', 'edit'), |
|
647 | 647 | 'readonly' => true, |
648 | 648 | ), |
649 | 649 | 'email' => array( |
650 | - 'description' => __( 'The email address for the customer.', 'woocommerce' ), |
|
650 | + 'description' => __('The email address for the customer.', 'woocommerce'), |
|
651 | 651 | 'type' => 'string', |
652 | 652 | 'format' => 'email', |
653 | - 'context' => array( 'view', 'edit' ), |
|
653 | + 'context' => array('view', 'edit'), |
|
654 | 654 | ), |
655 | 655 | 'first_name' => array( |
656 | - 'description' => __( 'Customer first name.', 'woocommerce' ), |
|
656 | + 'description' => __('Customer first name.', 'woocommerce'), |
|
657 | 657 | 'type' => 'string', |
658 | - 'context' => array( 'view', 'edit' ), |
|
658 | + 'context' => array('view', 'edit'), |
|
659 | 659 | 'arg_options' => array( |
660 | 660 | 'sanitize_callback' => 'sanitize_text_field', |
661 | 661 | ), |
662 | 662 | ), |
663 | 663 | 'last_name' => array( |
664 | - 'description' => __( 'Customer last name.', 'woocommerce' ), |
|
664 | + 'description' => __('Customer last name.', 'woocommerce'), |
|
665 | 665 | 'type' => 'string', |
666 | - 'context' => array( 'view', 'edit' ), |
|
666 | + 'context' => array('view', 'edit'), |
|
667 | 667 | 'arg_options' => array( |
668 | 668 | 'sanitize_callback' => 'sanitize_text_field', |
669 | 669 | ), |
670 | 670 | ), |
671 | 671 | 'username' => array( |
672 | - 'description' => __( 'Customer login name.', 'woocommerce' ), |
|
672 | + 'description' => __('Customer login name.', 'woocommerce'), |
|
673 | 673 | 'type' => 'string', |
674 | - 'context' => array( 'view', 'edit' ), |
|
674 | + 'context' => array('view', 'edit'), |
|
675 | 675 | 'arg_options' => array( |
676 | 676 | 'sanitize_callback' => 'sanitize_user', |
677 | 677 | ), |
678 | 678 | ), |
679 | 679 | 'password' => array( |
680 | - 'description' => __( 'Customer password.', 'woocommerce' ), |
|
680 | + 'description' => __('Customer password.', 'woocommerce'), |
|
681 | 681 | 'type' => 'string', |
682 | - 'context' => array( 'edit' ), |
|
682 | + 'context' => array('edit'), |
|
683 | 683 | ), |
684 | 684 | 'last_order' => array( |
685 | - 'description' => __( 'Last order data.', 'woocommerce' ), |
|
685 | + 'description' => __('Last order data.', 'woocommerce'), |
|
686 | 686 | 'type' => 'object', |
687 | - 'context' => array( 'view', 'edit' ), |
|
687 | + 'context' => array('view', 'edit'), |
|
688 | 688 | 'readonly' => true, |
689 | 689 | 'properties' => array( |
690 | 690 | 'id' => array( |
691 | - 'description' => __( 'Last order ID.', 'woocommerce' ), |
|
691 | + 'description' => __('Last order ID.', 'woocommerce'), |
|
692 | 692 | 'type' => 'integer', |
693 | - 'context' => array( 'view', 'edit' ), |
|
693 | + 'context' => array('view', 'edit'), |
|
694 | 694 | 'readonly' => true, |
695 | 695 | ), |
696 | 696 | 'date' => array( |
697 | - 'description' => __( 'The date of the customer last order, as GMT.', 'woocommerce' ), |
|
697 | + 'description' => __('The date of the customer last order, as GMT.', 'woocommerce'), |
|
698 | 698 | 'type' => 'date-time', |
699 | - 'context' => array( 'view', 'edit' ), |
|
699 | + 'context' => array('view', 'edit'), |
|
700 | 700 | 'readonly' => true, |
701 | 701 | ), |
702 | 702 | ), |
703 | 703 | ), |
704 | 704 | 'orders_count' => array( |
705 | - 'description' => __( 'Quantity of orders made by the customer.', 'woocommerce' ), |
|
705 | + 'description' => __('Quantity of orders made by the customer.', 'woocommerce'), |
|
706 | 706 | 'type' => 'integer', |
707 | - 'context' => array( 'view', 'edit' ), |
|
707 | + 'context' => array('view', 'edit'), |
|
708 | 708 | 'readonly' => true, |
709 | 709 | ), |
710 | 710 | 'total_spent' => array( |
711 | - 'description' => __( 'Total amount spent.', 'woocommerce' ), |
|
711 | + 'description' => __('Total amount spent.', 'woocommerce'), |
|
712 | 712 | 'type' => 'string', |
713 | - 'context' => array( 'view', 'edit' ), |
|
713 | + 'context' => array('view', 'edit'), |
|
714 | 714 | 'readonly' => true, |
715 | 715 | ), |
716 | 716 | 'avatar_url' => array( |
717 | - 'description' => __( 'Avatar URL.', 'woocommerce' ), |
|
717 | + 'description' => __('Avatar URL.', 'woocommerce'), |
|
718 | 718 | 'type' => 'string', |
719 | - 'context' => array( 'view', 'edit' ), |
|
719 | + 'context' => array('view', 'edit'), |
|
720 | 720 | 'readonly' => true, |
721 | 721 | ), |
722 | 722 | 'billing' => array( |
723 | - 'description' => __( 'List of billing address data.', 'woocommerce' ), |
|
723 | + 'description' => __('List of billing address data.', 'woocommerce'), |
|
724 | 724 | 'type' => 'object', |
725 | - 'context' => array( 'view', 'edit' ), |
|
725 | + 'context' => array('view', 'edit'), |
|
726 | 726 | 'properties' => array( |
727 | 727 | 'first_name' => array( |
728 | - 'description' => __( 'First name.', 'woocommerce' ), |
|
728 | + 'description' => __('First name.', 'woocommerce'), |
|
729 | 729 | 'type' => 'string', |
730 | - 'context' => array( 'view', 'edit' ), |
|
730 | + 'context' => array('view', 'edit'), |
|
731 | 731 | ), |
732 | 732 | 'last_name' => array( |
733 | - 'description' => __( 'Last name.', 'woocommerce' ), |
|
733 | + 'description' => __('Last name.', 'woocommerce'), |
|
734 | 734 | 'type' => 'string', |
735 | - 'context' => array( 'view', 'edit' ), |
|
735 | + 'context' => array('view', 'edit'), |
|
736 | 736 | ), |
737 | 737 | 'company' => array( |
738 | - 'description' => __( 'Company name.', 'woocommerce' ), |
|
738 | + 'description' => __('Company name.', 'woocommerce'), |
|
739 | 739 | 'type' => 'string', |
740 | - 'context' => array( 'view', 'edit' ), |
|
740 | + 'context' => array('view', 'edit'), |
|
741 | 741 | ), |
742 | 742 | 'address_1' => array( |
743 | - 'description' => __( 'Address line 1.', 'woocommerce' ), |
|
743 | + 'description' => __('Address line 1.', 'woocommerce'), |
|
744 | 744 | 'type' => 'string', |
745 | - 'context' => array( 'view', 'edit' ), |
|
745 | + 'context' => array('view', 'edit'), |
|
746 | 746 | ), |
747 | 747 | 'address_2' => array( |
748 | - 'description' => __( 'Address line 2.', 'woocommerce' ), |
|
748 | + 'description' => __('Address line 2.', 'woocommerce'), |
|
749 | 749 | 'type' => 'string', |
750 | - 'context' => array( 'view', 'edit' ), |
|
750 | + 'context' => array('view', 'edit'), |
|
751 | 751 | ), |
752 | 752 | 'city' => array( |
753 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
753 | + 'description' => __('City name.', 'woocommerce'), |
|
754 | 754 | 'type' => 'string', |
755 | - 'context' => array( 'view', 'edit' ), |
|
755 | + 'context' => array('view', 'edit'), |
|
756 | 756 | ), |
757 | 757 | 'state' => array( |
758 | - 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
|
758 | + 'description' => __('ISO code or name of the state, province or district.', 'woocommerce'), |
|
759 | 759 | 'type' => 'string', |
760 | - 'context' => array( 'view', 'edit' ), |
|
760 | + 'context' => array('view', 'edit'), |
|
761 | 761 | ), |
762 | 762 | 'postcode' => array( |
763 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
763 | + 'description' => __('Postal code.', 'woocommerce'), |
|
764 | 764 | 'type' => 'string', |
765 | - 'context' => array( 'view', 'edit' ), |
|
765 | + 'context' => array('view', 'edit'), |
|
766 | 766 | ), |
767 | 767 | 'country' => array( |
768 | - 'description' => __( 'ISO code of the country.', 'woocommerce' ), |
|
768 | + 'description' => __('ISO code of the country.', 'woocommerce'), |
|
769 | 769 | 'type' => 'string', |
770 | - 'context' => array( 'view', 'edit' ), |
|
770 | + 'context' => array('view', 'edit'), |
|
771 | 771 | ), |
772 | 772 | 'email' => array( |
773 | - 'description' => __( 'Email address.', 'woocommerce' ), |
|
773 | + 'description' => __('Email address.', 'woocommerce'), |
|
774 | 774 | 'type' => 'string', |
775 | 775 | 'format' => 'email', |
776 | - 'context' => array( 'view', 'edit' ), |
|
776 | + 'context' => array('view', 'edit'), |
|
777 | 777 | ), |
778 | 778 | 'phone' => array( |
779 | - 'description' => __( 'Phone number.', 'woocommerce' ), |
|
779 | + 'description' => __('Phone number.', 'woocommerce'), |
|
780 | 780 | 'type' => 'string', |
781 | - 'context' => array( 'view', 'edit' ), |
|
781 | + 'context' => array('view', 'edit'), |
|
782 | 782 | ), |
783 | 783 | ), |
784 | 784 | ), |
785 | 785 | 'shipping' => array( |
786 | - 'description' => __( 'List of shipping address data.', 'woocommerce' ), |
|
786 | + 'description' => __('List of shipping address data.', 'woocommerce'), |
|
787 | 787 | 'type' => 'object', |
788 | - 'context' => array( 'view', 'edit' ), |
|
788 | + 'context' => array('view', 'edit'), |
|
789 | 789 | 'properties' => array( |
790 | 790 | 'first_name' => array( |
791 | - 'description' => __( 'First name.', 'woocommerce' ), |
|
791 | + 'description' => __('First name.', 'woocommerce'), |
|
792 | 792 | 'type' => 'string', |
793 | - 'context' => array( 'view', 'edit' ), |
|
793 | + 'context' => array('view', 'edit'), |
|
794 | 794 | ), |
795 | 795 | 'last_name' => array( |
796 | - 'description' => __( 'Last name.', 'woocommerce' ), |
|
796 | + 'description' => __('Last name.', 'woocommerce'), |
|
797 | 797 | 'type' => 'string', |
798 | - 'context' => array( 'view', 'edit' ), |
|
798 | + 'context' => array('view', 'edit'), |
|
799 | 799 | ), |
800 | 800 | 'company' => array( |
801 | - 'description' => __( 'Company name.', 'woocommerce' ), |
|
801 | + 'description' => __('Company name.', 'woocommerce'), |
|
802 | 802 | 'type' => 'string', |
803 | - 'context' => array( 'view', 'edit' ), |
|
803 | + 'context' => array('view', 'edit'), |
|
804 | 804 | ), |
805 | 805 | 'address_1' => array( |
806 | - 'description' => __( 'Address line 1.', 'woocommerce' ), |
|
806 | + 'description' => __('Address line 1.', 'woocommerce'), |
|
807 | 807 | 'type' => 'string', |
808 | - 'context' => array( 'view', 'edit' ), |
|
808 | + 'context' => array('view', 'edit'), |
|
809 | 809 | ), |
810 | 810 | 'address_2' => array( |
811 | - 'description' => __( 'Address line 2.', 'woocommerce' ), |
|
811 | + 'description' => __('Address line 2.', 'woocommerce'), |
|
812 | 812 | 'type' => 'string', |
813 | - 'context' => array( 'view', 'edit' ), |
|
813 | + 'context' => array('view', 'edit'), |
|
814 | 814 | ), |
815 | 815 | 'city' => array( |
816 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
816 | + 'description' => __('City name.', 'woocommerce'), |
|
817 | 817 | 'type' => 'string', |
818 | - 'context' => array( 'view', 'edit' ), |
|
818 | + 'context' => array('view', 'edit'), |
|
819 | 819 | ), |
820 | 820 | 'state' => array( |
821 | - 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
|
821 | + 'description' => __('ISO code or name of the state, province or district.', 'woocommerce'), |
|
822 | 822 | 'type' => 'string', |
823 | - 'context' => array( 'view', 'edit' ), |
|
823 | + 'context' => array('view', 'edit'), |
|
824 | 824 | ), |
825 | 825 | 'postcode' => array( |
826 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
826 | + 'description' => __('Postal code.', 'woocommerce'), |
|
827 | 827 | 'type' => 'string', |
828 | - 'context' => array( 'view', 'edit' ), |
|
828 | + 'context' => array('view', 'edit'), |
|
829 | 829 | ), |
830 | 830 | 'country' => array( |
831 | - 'description' => __( 'ISO code of the country.', 'woocommerce' ), |
|
831 | + 'description' => __('ISO code of the country.', 'woocommerce'), |
|
832 | 832 | 'type' => 'string', |
833 | - 'context' => array( 'view', 'edit' ), |
|
833 | + 'context' => array('view', 'edit'), |
|
834 | 834 | ), |
835 | 835 | ), |
836 | 836 | ), |
837 | 837 | ), |
838 | 838 | ); |
839 | 839 | |
840 | - return $this->add_additional_fields_schema( $schema ); |
|
840 | + return $this->add_additional_fields_schema($schema); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | protected function get_role_names() { |
849 | 849 | global $wp_roles; |
850 | 850 | |
851 | - return array_keys( $wp_roles->role_names ); |
|
851 | + return array_keys($wp_roles->role_names); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
@@ -862,7 +862,7 @@ discard block |
||
862 | 862 | $params['context']['default'] = 'view'; |
863 | 863 | |
864 | 864 | $params['exclude'] = array( |
865 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
865 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
866 | 866 | 'type' => 'array', |
867 | 867 | 'items' => array( |
868 | 868 | 'type' => 'integer', |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | 'sanitize_callback' => 'wp_parse_id_list', |
872 | 872 | ); |
873 | 873 | $params['include'] = array( |
874 | - 'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ), |
|
874 | + 'description' => __('Limit result set to specific IDs.', 'woocommerce'), |
|
875 | 875 | 'type' => 'array', |
876 | 876 | 'items' => array( |
877 | 877 | 'type' => 'integer', |
@@ -880,22 +880,22 @@ discard block |
||
880 | 880 | 'sanitize_callback' => 'wp_parse_id_list', |
881 | 881 | ); |
882 | 882 | $params['offset'] = array( |
883 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
883 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
884 | 884 | 'type' => 'integer', |
885 | 885 | 'sanitize_callback' => 'absint', |
886 | 886 | 'validate_callback' => 'rest_validate_request_arg', |
887 | 887 | ); |
888 | 888 | $params['order'] = array( |
889 | 889 | 'default' => 'asc', |
890 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
891 | - 'enum' => array( 'asc', 'desc' ), |
|
890 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
891 | + 'enum' => array('asc', 'desc'), |
|
892 | 892 | 'sanitize_callback' => 'sanitize_key', |
893 | 893 | 'type' => 'string', |
894 | 894 | 'validate_callback' => 'rest_validate_request_arg', |
895 | 895 | ); |
896 | 896 | $params['orderby'] = array( |
897 | 897 | 'default' => 'name', |
898 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
898 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
899 | 899 | 'enum' => array( |
900 | 900 | 'id', |
901 | 901 | 'include', |
@@ -907,16 +907,16 @@ discard block |
||
907 | 907 | 'validate_callback' => 'rest_validate_request_arg', |
908 | 908 | ); |
909 | 909 | $params['email'] = array( |
910 | - 'description' => __( 'Limit result set to resources with a specific email.', 'woocommerce' ), |
|
910 | + 'description' => __('Limit result set to resources with a specific email.', 'woocommerce'), |
|
911 | 911 | 'type' => 'string', |
912 | 912 | 'format' => 'email', |
913 | 913 | 'validate_callback' => 'rest_validate_request_arg', |
914 | 914 | ); |
915 | 915 | $params['role'] = array( |
916 | - 'description' => __( 'Limit result set to resources with a specific role.', 'woocommerce' ), |
|
916 | + 'description' => __('Limit result set to resources with a specific role.', 'woocommerce'), |
|
917 | 917 | 'type' => 'string', |
918 | 918 | 'default' => 'customer', |
919 | - 'enum' => array_merge( array( 'all' ), $this->get_role_names() ), |
|
919 | + 'enum' => array_merge(array('all'), $this->get_role_names()), |
|
920 | 920 | 'validate_callback' => 'rest_validate_request_arg', |
921 | 921 | ); |
922 | 922 | return $params; |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -47,74 +47,74 @@ discard block |
||
47 | 47 | * Initialize orders actions. |
48 | 48 | */ |
49 | 49 | public function __construct() { |
50 | - add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'query_args' ), 10, 2 ); |
|
50 | + add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'query_args'), 10, 2); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Register the routes for orders. |
55 | 55 | */ |
56 | 56 | public function register_routes() { |
57 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
57 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
58 | 58 | array( |
59 | 59 | 'methods' => WP_REST_Server::READABLE, |
60 | - 'callback' => array( $this, 'get_items' ), |
|
61 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
60 | + 'callback' => array($this, 'get_items'), |
|
61 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
62 | 62 | 'args' => $this->get_collection_params(), |
63 | 63 | ), |
64 | 64 | array( |
65 | 65 | 'methods' => WP_REST_Server::CREATABLE, |
66 | - 'callback' => array( $this, 'create_item' ), |
|
67 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
68 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
66 | + 'callback' => array($this, 'create_item'), |
|
67 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
68 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
69 | 69 | ), |
70 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
71 | - ) ); |
|
70 | + 'schema' => array($this, 'get_public_item_schema'), |
|
71 | + )); |
|
72 | 72 | |
73 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
73 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
74 | 74 | 'args' => array( |
75 | 75 | 'id' => array( |
76 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
76 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
77 | 77 | 'type' => 'integer', |
78 | 78 | ), |
79 | 79 | ), |
80 | 80 | array( |
81 | 81 | 'methods' => WP_REST_Server::READABLE, |
82 | - 'callback' => array( $this, 'get_item' ), |
|
83 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
82 | + 'callback' => array($this, 'get_item'), |
|
83 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
84 | 84 | 'args' => array( |
85 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
85 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
86 | 86 | ), |
87 | 87 | ), |
88 | 88 | array( |
89 | 89 | 'methods' => WP_REST_Server::EDITABLE, |
90 | - 'callback' => array( $this, 'update_item' ), |
|
91 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
92 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
90 | + 'callback' => array($this, 'update_item'), |
|
91 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
92 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
93 | 93 | ), |
94 | 94 | array( |
95 | 95 | 'methods' => WP_REST_Server::DELETABLE, |
96 | - 'callback' => array( $this, 'delete_item' ), |
|
97 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
96 | + 'callback' => array($this, 'delete_item'), |
|
97 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
98 | 98 | 'args' => array( |
99 | 99 | 'force' => array( |
100 | 100 | 'default' => false, |
101 | 101 | 'type' => 'boolean', |
102 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
102 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
103 | 103 | ), |
104 | 104 | ), |
105 | 105 | ), |
106 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
107 | - ) ); |
|
106 | + 'schema' => array($this, 'get_public_item_schema'), |
|
107 | + )); |
|
108 | 108 | |
109 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
109 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
110 | 110 | array( |
111 | 111 | 'methods' => WP_REST_Server::EDITABLE, |
112 | - 'callback' => array( $this, 'batch_items' ), |
|
113 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
114 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
112 | + 'callback' => array($this, 'batch_items'), |
|
113 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
114 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
115 | 115 | ), |
116 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
117 | - ) ); |
|
116 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
117 | + )); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | * @param WP_REST_Request $request Request object. |
125 | 125 | * @return WP_REST_Response $data |
126 | 126 | */ |
127 | - public function prepare_item_for_response( $post, $request ) { |
|
128 | - $order = wc_get_order( $post ); |
|
129 | - $dp = is_null( $request['dp'] ) ? wc_get_price_decimals() : absint( $request['dp'] ); |
|
127 | + public function prepare_item_for_response($post, $request) { |
|
128 | + $order = wc_get_order($post); |
|
129 | + $dp = is_null($request['dp']) ? wc_get_price_decimals() : absint($request['dp']); |
|
130 | 130 | |
131 | 131 | $data = array( |
132 | 132 | 'id' => $order->get_id(), |
@@ -137,16 +137,16 @@ discard block |
||
137 | 137 | 'currency' => $order->get_currency(), |
138 | 138 | 'version' => $order->get_version(), |
139 | 139 | 'prices_include_tax' => $order->get_prices_include_tax(), |
140 | - 'date_created' => wc_rest_prepare_date_response( $order->get_date_created() ), // v1 API used UTC. |
|
141 | - 'date_modified' => wc_rest_prepare_date_response( $order->get_date_modified() ), // v1 API used UTC. |
|
140 | + 'date_created' => wc_rest_prepare_date_response($order->get_date_created()), // v1 API used UTC. |
|
141 | + 'date_modified' => wc_rest_prepare_date_response($order->get_date_modified()), // v1 API used UTC. |
|
142 | 142 | 'customer_id' => $order->get_customer_id(), |
143 | - 'discount_total' => wc_format_decimal( $order->get_total_discount(), $dp ), |
|
144 | - 'discount_tax' => wc_format_decimal( $order->get_discount_tax(), $dp ), |
|
145 | - 'shipping_total' => wc_format_decimal( $order->get_shipping_total(), $dp ), |
|
146 | - 'shipping_tax' => wc_format_decimal( $order->get_shipping_tax(), $dp ), |
|
147 | - 'cart_tax' => wc_format_decimal( $order->get_cart_tax(), $dp ), |
|
148 | - 'total' => wc_format_decimal( $order->get_total(), $dp ), |
|
149 | - 'total_tax' => wc_format_decimal( $order->get_total_tax(), $dp ), |
|
143 | + 'discount_total' => wc_format_decimal($order->get_total_discount(), $dp), |
|
144 | + 'discount_tax' => wc_format_decimal($order->get_discount_tax(), $dp), |
|
145 | + 'shipping_total' => wc_format_decimal($order->get_shipping_total(), $dp), |
|
146 | + 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), |
|
147 | + 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), |
|
148 | + 'total' => wc_format_decimal($order->get_total(), $dp), |
|
149 | + 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), |
|
150 | 150 | 'billing' => array(), |
151 | 151 | 'shipping' => array(), |
152 | 152 | 'payment_method' => $order->get_payment_method(), |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | 'customer_user_agent' => $order->get_customer_user_agent(), |
157 | 157 | 'created_via' => $order->get_created_via(), |
158 | 158 | 'customer_note' => $order->get_customer_note(), |
159 | - 'date_completed' => wc_rest_prepare_date_response( $order->get_date_completed(), false ), // v1 API used local time. |
|
160 | - 'date_paid' => wc_rest_prepare_date_response( $order->get_date_paid(), false ), // v1 API used local time. |
|
159 | + 'date_completed' => wc_rest_prepare_date_response($order->get_date_completed(), false), // v1 API used local time. |
|
160 | + 'date_paid' => wc_rest_prepare_date_response($order->get_date_paid(), false), // v1 API used local time. |
|
161 | 161 | 'cart_hash' => $order->get_cart_hash(), |
162 | 162 | 'line_items' => array(), |
163 | 163 | 'tax_lines' => array(), |
@@ -168,18 +168,18 @@ discard block |
||
168 | 168 | ); |
169 | 169 | |
170 | 170 | // Add addresses. |
171 | - $data['billing'] = $order->get_address( 'billing' ); |
|
172 | - $data['shipping'] = $order->get_address( 'shipping' ); |
|
171 | + $data['billing'] = $order->get_address('billing'); |
|
172 | + $data['shipping'] = $order->get_address('shipping'); |
|
173 | 173 | |
174 | 174 | // Add line items. |
175 | - foreach ( $order->get_items() as $item_id => $item ) { |
|
176 | - $product = $order->get_product_from_item( $item ); |
|
175 | + foreach ($order->get_items() as $item_id => $item) { |
|
176 | + $product = $order->get_product_from_item($item); |
|
177 | 177 | $product_id = 0; |
178 | 178 | $variation_id = 0; |
179 | 179 | $product_sku = null; |
180 | 180 | |
181 | 181 | // Check if the product exists. |
182 | - if ( is_object( $product ) ) { |
|
182 | + if (is_object($product)) { |
|
183 | 183 | $product_id = $item->get_product_id(); |
184 | 184 | $variation_id = $item->get_variation_id(); |
185 | 185 | $product_sku = $product->get_sku(); |
@@ -189,11 +189,11 @@ discard block |
||
189 | 189 | |
190 | 190 | $hideprefix = 'true' === $request['all_item_meta'] ? null : '_'; |
191 | 191 | |
192 | - foreach ( $item->get_formatted_meta_data( $hideprefix, true ) as $meta_key => $formatted_meta ) { |
|
192 | + foreach ($item->get_formatted_meta_data($hideprefix, true) as $meta_key => $formatted_meta) { |
|
193 | 193 | $item_meta[] = array( |
194 | 194 | 'key' => $formatted_meta->key, |
195 | 195 | 'label' => $formatted_meta->display_key, |
196 | - 'value' => wc_clean( $formatted_meta->display_value ), |
|
196 | + 'value' => wc_clean($formatted_meta->display_value), |
|
197 | 197 | ); |
198 | 198 | } |
199 | 199 | |
@@ -203,71 +203,71 @@ discard block |
||
203 | 203 | 'sku' => $product_sku, |
204 | 204 | 'product_id' => (int) $product_id, |
205 | 205 | 'variation_id' => (int) $variation_id, |
206 | - 'quantity' => wc_stock_amount( $item['qty'] ), |
|
207 | - 'tax_class' => ! empty( $item['tax_class'] ) ? $item['tax_class'] : '', |
|
208 | - 'price' => wc_format_decimal( $order->get_item_total( $item, false, false ), $dp ), |
|
209 | - 'subtotal' => wc_format_decimal( $order->get_line_subtotal( $item, false, false ), $dp ), |
|
210 | - 'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $dp ), |
|
211 | - 'total' => wc_format_decimal( $order->get_line_total( $item, false, false ), $dp ), |
|
212 | - 'total_tax' => wc_format_decimal( $item['line_tax'], $dp ), |
|
206 | + 'quantity' => wc_stock_amount($item['qty']), |
|
207 | + 'tax_class' => ! empty($item['tax_class']) ? $item['tax_class'] : '', |
|
208 | + 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), |
|
209 | + 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), |
|
210 | + 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), |
|
211 | + 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), |
|
212 | + 'total_tax' => wc_format_decimal($item['line_tax'], $dp), |
|
213 | 213 | 'taxes' => array(), |
214 | 214 | 'meta' => $item_meta, |
215 | 215 | ); |
216 | 216 | |
217 | - $item_line_taxes = maybe_unserialize( $item['line_tax_data'] ); |
|
218 | - if ( isset( $item_line_taxes['total'] ) ) { |
|
217 | + $item_line_taxes = maybe_unserialize($item['line_tax_data']); |
|
218 | + if (isset($item_line_taxes['total'])) { |
|
219 | 219 | $line_tax = array(); |
220 | 220 | |
221 | - foreach ( $item_line_taxes['total'] as $tax_rate_id => $tax ) { |
|
222 | - $line_tax[ $tax_rate_id ] = array( |
|
221 | + foreach ($item_line_taxes['total'] as $tax_rate_id => $tax) { |
|
222 | + $line_tax[$tax_rate_id] = array( |
|
223 | 223 | 'id' => $tax_rate_id, |
224 | 224 | 'total' => $tax, |
225 | 225 | 'subtotal' => '', |
226 | 226 | ); |
227 | 227 | } |
228 | 228 | |
229 | - foreach ( $item_line_taxes['subtotal'] as $tax_rate_id => $tax ) { |
|
230 | - $line_tax[ $tax_rate_id ]['subtotal'] = $tax; |
|
229 | + foreach ($item_line_taxes['subtotal'] as $tax_rate_id => $tax) { |
|
230 | + $line_tax[$tax_rate_id]['subtotal'] = $tax; |
|
231 | 231 | } |
232 | 232 | |
233 | - $line_item['taxes'] = array_values( $line_tax ); |
|
233 | + $line_item['taxes'] = array_values($line_tax); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | $data['line_items'][] = $line_item; |
237 | 237 | } |
238 | 238 | |
239 | 239 | // Add taxes. |
240 | - foreach ( $order->get_items( 'tax' ) as $key => $tax ) { |
|
240 | + foreach ($order->get_items('tax') as $key => $tax) { |
|
241 | 241 | $tax_line = array( |
242 | 242 | 'id' => $key, |
243 | 243 | 'rate_code' => $tax['name'], |
244 | 244 | 'rate_id' => $tax['rate_id'], |
245 | - 'label' => isset( $tax['label'] ) ? $tax['label'] : $tax['name'], |
|
245 | + 'label' => isset($tax['label']) ? $tax['label'] : $tax['name'], |
|
246 | 246 | 'compound' => (bool) $tax['compound'], |
247 | - 'tax_total' => wc_format_decimal( $tax['tax_amount'], $dp ), |
|
248 | - 'shipping_tax_total' => wc_format_decimal( $tax['shipping_tax_amount'], $dp ), |
|
247 | + 'tax_total' => wc_format_decimal($tax['tax_amount'], $dp), |
|
248 | + 'shipping_tax_total' => wc_format_decimal($tax['shipping_tax_amount'], $dp), |
|
249 | 249 | ); |
250 | 250 | |
251 | 251 | $data['tax_lines'][] = $tax_line; |
252 | 252 | } |
253 | 253 | |
254 | 254 | // Add shipping. |
255 | - foreach ( $order->get_shipping_methods() as $shipping_item_id => $shipping_item ) { |
|
255 | + foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) { |
|
256 | 256 | $shipping_line = array( |
257 | 257 | 'id' => $shipping_item_id, |
258 | 258 | 'method_title' => $shipping_item['name'], |
259 | 259 | 'method_id' => $shipping_item['method_id'], |
260 | - 'total' => wc_format_decimal( $shipping_item['cost'], $dp ), |
|
261 | - 'total_tax' => wc_format_decimal( '', $dp ), |
|
260 | + 'total' => wc_format_decimal($shipping_item['cost'], $dp), |
|
261 | + 'total_tax' => wc_format_decimal('', $dp), |
|
262 | 262 | 'taxes' => array(), |
263 | 263 | ); |
264 | 264 | |
265 | 265 | $shipping_taxes = $shipping_item->get_taxes(); |
266 | 266 | |
267 | - if ( ! empty( $shipping_taxes['total'] ) ) { |
|
268 | - $shipping_line['total_tax'] = wc_format_decimal( array_sum( $shipping_taxes['total'] ), $dp ); |
|
267 | + if ( ! empty($shipping_taxes['total'])) { |
|
268 | + $shipping_line['total_tax'] = wc_format_decimal(array_sum($shipping_taxes['total']), $dp); |
|
269 | 269 | |
270 | - foreach ( $shipping_taxes['total'] as $tax_rate_id => $tax ) { |
|
270 | + foreach ($shipping_taxes['total'] as $tax_rate_id => $tax) { |
|
271 | 271 | $shipping_line['taxes'][] = array( |
272 | 272 | 'id' => $tax_rate_id, |
273 | 273 | 'total' => $tax, |
@@ -279,70 +279,70 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | // Add fees. |
282 | - foreach ( $order->get_fees() as $fee_item_id => $fee_item ) { |
|
282 | + foreach ($order->get_fees() as $fee_item_id => $fee_item) { |
|
283 | 283 | $fee_line = array( |
284 | 284 | 'id' => $fee_item_id, |
285 | 285 | 'name' => $fee_item['name'], |
286 | - 'tax_class' => ! empty( $fee_item['tax_class'] ) ? $fee_item['tax_class'] : '', |
|
286 | + 'tax_class' => ! empty($fee_item['tax_class']) ? $fee_item['tax_class'] : '', |
|
287 | 287 | 'tax_status' => 'taxable', |
288 | - 'total' => wc_format_decimal( $order->get_line_total( $fee_item ), $dp ), |
|
289 | - 'total_tax' => wc_format_decimal( $order->get_line_tax( $fee_item ), $dp ), |
|
288 | + 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), |
|
289 | + 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp), |
|
290 | 290 | 'taxes' => array(), |
291 | 291 | ); |
292 | 292 | |
293 | - $fee_line_taxes = maybe_unserialize( $fee_item['line_tax_data'] ); |
|
294 | - if ( isset( $fee_line_taxes['total'] ) ) { |
|
293 | + $fee_line_taxes = maybe_unserialize($fee_item['line_tax_data']); |
|
294 | + if (isset($fee_line_taxes['total'])) { |
|
295 | 295 | $fee_tax = array(); |
296 | 296 | |
297 | - foreach ( $fee_line_taxes['total'] as $tax_rate_id => $tax ) { |
|
298 | - $fee_tax[ $tax_rate_id ] = array( |
|
297 | + foreach ($fee_line_taxes['total'] as $tax_rate_id => $tax) { |
|
298 | + $fee_tax[$tax_rate_id] = array( |
|
299 | 299 | 'id' => $tax_rate_id, |
300 | 300 | 'total' => $tax, |
301 | 301 | 'subtotal' => '', |
302 | 302 | ); |
303 | 303 | } |
304 | 304 | |
305 | - if ( isset( $fee_line_taxes['subtotal'] ) ) { |
|
306 | - foreach ( $fee_line_taxes['subtotal'] as $tax_rate_id => $tax ) { |
|
307 | - $fee_tax[ $tax_rate_id ]['subtotal'] = $tax; |
|
305 | + if (isset($fee_line_taxes['subtotal'])) { |
|
306 | + foreach ($fee_line_taxes['subtotal'] as $tax_rate_id => $tax) { |
|
307 | + $fee_tax[$tax_rate_id]['subtotal'] = $tax; |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | |
311 | - $fee_line['taxes'] = array_values( $fee_tax ); |
|
311 | + $fee_line['taxes'] = array_values($fee_tax); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | $data['fee_lines'][] = $fee_line; |
315 | 315 | } |
316 | 316 | |
317 | 317 | // Add coupons. |
318 | - foreach ( $order->get_items( 'coupon' ) as $coupon_item_id => $coupon_item ) { |
|
318 | + foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) { |
|
319 | 319 | $coupon_line = array( |
320 | 320 | 'id' => $coupon_item_id, |
321 | 321 | 'code' => $coupon_item['name'], |
322 | - 'discount' => wc_format_decimal( $coupon_item['discount_amount'], $dp ), |
|
323 | - 'discount_tax' => wc_format_decimal( $coupon_item['discount_amount_tax'], $dp ), |
|
322 | + 'discount' => wc_format_decimal($coupon_item['discount_amount'], $dp), |
|
323 | + 'discount_tax' => wc_format_decimal($coupon_item['discount_amount_tax'], $dp), |
|
324 | 324 | ); |
325 | 325 | |
326 | 326 | $data['coupon_lines'][] = $coupon_line; |
327 | 327 | } |
328 | 328 | |
329 | 329 | // Add refunds. |
330 | - foreach ( $order->get_refunds() as $refund ) { |
|
330 | + foreach ($order->get_refunds() as $refund) { |
|
331 | 331 | $data['refunds'][] = array( |
332 | 332 | 'id' => $refund->get_id(), |
333 | 333 | 'refund' => $refund->get_reason() ? $refund->get_reason() : '', |
334 | - 'total' => '-' . wc_format_decimal( $refund->get_amount(), $dp ), |
|
334 | + 'total' => '-' . wc_format_decimal($refund->get_amount(), $dp), |
|
335 | 335 | ); |
336 | 336 | } |
337 | 337 | |
338 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
339 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
340 | - $data = $this->filter_response_by_context( $data, $context ); |
|
338 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
339 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
340 | + $data = $this->filter_response_by_context($data, $context); |
|
341 | 341 | |
342 | 342 | // Wrap the data in a response object. |
343 | - $response = rest_ensure_response( $data ); |
|
343 | + $response = rest_ensure_response($data); |
|
344 | 344 | |
345 | - $response->add_links( $this->prepare_links( $order, $request ) ); |
|
345 | + $response->add_links($this->prepare_links($order, $request)); |
|
346 | 346 | |
347 | 347 | /** |
348 | 348 | * Filter the data for a response. |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | * @param WP_Post $post Post object. |
355 | 355 | * @param WP_REST_Request $request Request object. |
356 | 356 | */ |
357 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request ); |
|
357 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request); |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | /** |
@@ -364,23 +364,23 @@ discard block |
||
364 | 364 | * @param WP_REST_Request $request Request object. |
365 | 365 | * @return array Links for the given order. |
366 | 366 | */ |
367 | - protected function prepare_links( $order, $request ) { |
|
367 | + protected function prepare_links($order, $request) { |
|
368 | 368 | $links = array( |
369 | 369 | 'self' => array( |
370 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $order->get_id() ) ), |
|
370 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $order->get_id())), |
|
371 | 371 | ), |
372 | 372 | 'collection' => array( |
373 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
373 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
374 | 374 | ), |
375 | 375 | ); |
376 | - if ( 0 !== (int) $order->get_user_id() ) { |
|
376 | + if (0 !== (int) $order->get_user_id()) { |
|
377 | 377 | $links['customer'] = array( |
378 | - 'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $order->get_user_id() ) ), |
|
378 | + 'href' => rest_url(sprintf('/%s/customers/%d', $this->namespace, $order->get_user_id())), |
|
379 | 379 | ); |
380 | 380 | } |
381 | - if ( 0 !== (int) $order->get_parent_id() ) { |
|
381 | + if (0 !== (int) $order->get_parent_id()) { |
|
382 | 382 | $links['up'] = array( |
383 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order->get_parent_id() ) ), |
|
383 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order->get_parent_id())), |
|
384 | 384 | ); |
385 | 385 | } |
386 | 386 | return $links; |
@@ -393,18 +393,18 @@ discard block |
||
393 | 393 | * @param WP_REST_Request $request |
394 | 394 | * @return array |
395 | 395 | */ |
396 | - public function query_args( $args, $request ) { |
|
396 | + public function query_args($args, $request) { |
|
397 | 397 | global $wpdb; |
398 | 398 | |
399 | 399 | // Set post_status. |
400 | - if ( 'any' !== $request['status'] ) { |
|
400 | + if ('any' !== $request['status']) { |
|
401 | 401 | $args['post_status'] = 'wc-' . $request['status']; |
402 | 402 | } else { |
403 | 403 | $args['post_status'] = 'any'; |
404 | 404 | } |
405 | 405 | |
406 | - if ( isset( $request['customer'] ) ) { |
|
407 | - if ( ! empty( $args['meta_query'] ) ) { |
|
406 | + if (isset($request['customer'])) { |
|
407 | + if ( ! empty($args['meta_query'])) { |
|
408 | 408 | $args['meta_query'] = array(); |
409 | 409 | } |
410 | 410 | |
@@ -416,27 +416,27 @@ discard block |
||
416 | 416 | } |
417 | 417 | |
418 | 418 | // Search by product. |
419 | - if ( ! empty( $request['product'] ) ) { |
|
420 | - $order_ids = $wpdb->get_col( $wpdb->prepare( " |
|
419 | + if ( ! empty($request['product'])) { |
|
420 | + $order_ids = $wpdb->get_col($wpdb->prepare(" |
|
421 | 421 | SELECT order_id |
422 | 422 | FROM {$wpdb->prefix}woocommerce_order_items |
423 | 423 | WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key = '_product_id' AND meta_value = %d ) |
424 | 424 | AND order_item_type = 'line_item' |
425 | - ", $request['product'] ) ); |
|
425 | + ", $request['product'])); |
|
426 | 426 | |
427 | 427 | // Force WP_Query return empty if don't found any order. |
428 | - $order_ids = ! empty( $order_ids ) ? $order_ids : array( 0 ); |
|
428 | + $order_ids = ! empty($order_ids) ? $order_ids : array(0); |
|
429 | 429 | |
430 | 430 | $args['post__in'] = $order_ids; |
431 | 431 | } |
432 | 432 | |
433 | 433 | // Search. |
434 | - if ( ! empty( $args['s'] ) ) { |
|
435 | - $order_ids = wc_order_search( $args['s'] ); |
|
434 | + if ( ! empty($args['s'])) { |
|
435 | + $order_ids = wc_order_search($args['s']); |
|
436 | 436 | |
437 | - if ( ! empty( $order_ids ) ) { |
|
438 | - unset( $args['s'] ); |
|
439 | - $args['post__in'] = array_merge( $order_ids, array( 0 ) ); |
|
437 | + if ( ! empty($order_ids)) { |
|
438 | + unset($args['s']); |
|
439 | + $args['post__in'] = array_merge($order_ids, array(0)); |
|
440 | 440 | } |
441 | 441 | } |
442 | 442 | |
@@ -449,41 +449,41 @@ discard block |
||
449 | 449 | * @param WP_REST_Request $request Request object. |
450 | 450 | * @return WP_Error|WC_Order $data Object. |
451 | 451 | */ |
452 | - protected function prepare_item_for_database( $request ) { |
|
453 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
454 | - $order = new WC_Order( $id ); |
|
452 | + protected function prepare_item_for_database($request) { |
|
453 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
454 | + $order = new WC_Order($id); |
|
455 | 455 | $schema = $this->get_item_schema(); |
456 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
456 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
457 | 457 | |
458 | 458 | // Handle all writable props |
459 | - foreach ( $data_keys as $key ) { |
|
460 | - $value = $request[ $key ]; |
|
459 | + foreach ($data_keys as $key) { |
|
460 | + $value = $request[$key]; |
|
461 | 461 | |
462 | - if ( ! is_null( $value ) ) { |
|
463 | - switch ( $key ) { |
|
462 | + if ( ! is_null($value)) { |
|
463 | + switch ($key) { |
|
464 | 464 | case 'billing' : |
465 | 465 | case 'shipping' : |
466 | - $this->update_address( $order, $value, $key ); |
|
466 | + $this->update_address($order, $value, $key); |
|
467 | 467 | break; |
468 | 468 | case 'line_items' : |
469 | 469 | case 'shipping_lines' : |
470 | 470 | case 'fee_lines' : |
471 | 471 | case 'coupon_lines' : |
472 | - if ( is_array( $value ) ) { |
|
473 | - foreach ( $value as $item ) { |
|
474 | - if ( is_array( $item ) ) { |
|
475 | - if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) { |
|
476 | - $order->remove_item( $item['id'] ); |
|
472 | + if (is_array($value)) { |
|
473 | + foreach ($value as $item) { |
|
474 | + if (is_array($item)) { |
|
475 | + if ($this->item_is_null($item) || (isset($item['quantity']) && 0 === $item['quantity'])) { |
|
476 | + $order->remove_item($item['id']); |
|
477 | 477 | } else { |
478 | - $this->set_item( $order, $key, $item ); |
|
478 | + $this->set_item($order, $key, $item); |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | } |
482 | 482 | } |
483 | 483 | break; |
484 | 484 | default : |
485 | - if ( is_callable( array( $order, "set_{$key}" ) ) ) { |
|
486 | - $order->{"set_{$key}"}( $value ); |
|
485 | + if (is_callable(array($order, "set_{$key}"))) { |
|
486 | + $order->{"set_{$key}"}($value); |
|
487 | 487 | } |
488 | 488 | break; |
489 | 489 | } |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | * @param WC_Order $order The order object. |
500 | 500 | * @param WP_REST_Request $request Request object. |
501 | 501 | */ |
502 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $order, $request ); |
|
502 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $order, $request); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /** |
@@ -508,8 +508,8 @@ discard block |
||
508 | 508 | * @param array $data |
509 | 509 | * @return WC_Order |
510 | 510 | */ |
511 | - protected function create_base_order( $data ) { |
|
512 | - return wc_create_order( $data ); |
|
511 | + protected function create_base_order($data) { |
|
512 | + return wc_create_order($data); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -517,8 +517,8 @@ discard block |
||
517 | 517 | * @param array $schema |
518 | 518 | * @return bool |
519 | 519 | */ |
520 | - protected function filter_writable_props( $schema ) { |
|
521 | - return empty( $schema['readonly'] ); |
|
520 | + protected function filter_writable_props($schema) { |
|
521 | + return empty($schema['readonly']); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
@@ -527,34 +527,34 @@ discard block |
||
527 | 527 | * @param WP_REST_Request $request Full details about the request. |
528 | 528 | * @return int|WP_Error |
529 | 529 | */ |
530 | - protected function create_order( $request ) { |
|
530 | + protected function create_order($request) { |
|
531 | 531 | try { |
532 | 532 | // Make sure customer exists. |
533 | - if ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] && false === get_user_by( 'id', $request['customer_id'] ) ) { |
|
534 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_customer_id',__( 'Customer ID is invalid.', 'woocommerce' ), 400 ); |
|
533 | + if ( ! is_null($request['customer_id']) && 0 !== $request['customer_id'] && false === get_user_by('id', $request['customer_id'])) { |
|
534 | + throw new WC_REST_Exception('woocommerce_rest_invalid_customer_id', __('Customer ID is invalid.', 'woocommerce'), 400); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | // Make sure customer is part of blog. |
538 | - if ( is_multisite() && ! is_user_member_of_blog( $request['customer_id'] ) ) { |
|
539 | - add_user_to_blog( get_current_blog_id(), $request['customer_id'], 'customer' ); |
|
538 | + if (is_multisite() && ! is_user_member_of_blog($request['customer_id'])) { |
|
539 | + add_user_to_blog(get_current_blog_id(), $request['customer_id'], 'customer'); |
|
540 | 540 | } |
541 | 541 | |
542 | - $order = $this->prepare_item_for_database( $request ); |
|
543 | - $order->set_created_via( 'rest-api' ); |
|
544 | - $order->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) ); |
|
542 | + $order = $this->prepare_item_for_database($request); |
|
543 | + $order->set_created_via('rest-api'); |
|
544 | + $order->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax')); |
|
545 | 545 | $order->calculate_totals(); |
546 | 546 | $order->save(); |
547 | 547 | |
548 | 548 | // Handle set paid. |
549 | - if ( true === $request['set_paid'] ) { |
|
550 | - $order->payment_complete( $request['transaction_id'] ); |
|
549 | + if (true === $request['set_paid']) { |
|
550 | + $order->payment_complete($request['transaction_id']); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | return $order->get_id(); |
554 | - } catch ( WC_Data_Exception $e ) { |
|
555 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
556 | - } catch ( WC_REST_Exception $e ) { |
|
557 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
554 | + } catch (WC_Data_Exception $e) { |
|
555 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData()); |
|
556 | + } catch (WC_REST_Exception $e) { |
|
557 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
@@ -564,26 +564,26 @@ discard block |
||
564 | 564 | * @param WP_REST_Request $request Full details about the request. |
565 | 565 | * @return int|WP_Error |
566 | 566 | */ |
567 | - protected function update_order( $request ) { |
|
567 | + protected function update_order($request) { |
|
568 | 568 | try { |
569 | - $order = $this->prepare_item_for_database( $request ); |
|
569 | + $order = $this->prepare_item_for_database($request); |
|
570 | 570 | $order->save(); |
571 | 571 | |
572 | 572 | // Handle set paid. |
573 | - if ( $order->needs_payment() && true === $request['set_paid'] ) { |
|
574 | - $order->payment_complete( $request['transaction_id'] ); |
|
573 | + if ($order->needs_payment() && true === $request['set_paid']) { |
|
574 | + $order->payment_complete($request['transaction_id']); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | // If items have changed, recalculate order totals. |
578 | - if ( isset( $request['billing'] ) || isset( $request['shipping'] ) || isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) { |
|
579 | - $order->calculate_totals( true ); |
|
578 | + if (isset($request['billing']) || isset($request['shipping']) || isset($request['line_items']) || isset($request['shipping_lines']) || isset($request['fee_lines']) || isset($request['coupon_lines'])) { |
|
579 | + $order->calculate_totals(true); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | return $order->get_id(); |
583 | - } catch ( WC_Data_Exception $e ) { |
|
584 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
585 | - } catch ( WC_REST_Exception $e ) { |
|
586 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
583 | + } catch (WC_Data_Exception $e) { |
|
584 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData()); |
|
585 | + } catch (WC_REST_Exception $e) { |
|
586 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
587 | 587 | } |
588 | 588 | } |
589 | 589 | |
@@ -594,10 +594,10 @@ discard block |
||
594 | 594 | * @param array $posted |
595 | 595 | * @param string $type |
596 | 596 | */ |
597 | - protected function update_address( $order, $posted, $type = 'billing' ) { |
|
598 | - foreach ( $posted as $key => $value ) { |
|
599 | - if ( is_callable( array( $order, "set_{$type}_{$key}" ) ) ) { |
|
600 | - $order->{"set_{$type}_{$key}"}( $value ); |
|
597 | + protected function update_address($order, $posted, $type = 'billing') { |
|
598 | + foreach ($posted as $key => $value) { |
|
599 | + if (is_callable(array($order, "set_{$type}_{$key}"))) { |
|
600 | + $order->{"set_{$type}_{$key}"}($value); |
|
601 | 601 | } |
602 | 602 | } |
603 | 603 | } |
@@ -610,15 +610,15 @@ discard block |
||
610 | 610 | * @return int |
611 | 611 | * @throws WC_REST_Exception |
612 | 612 | */ |
613 | - protected function get_product_id( $posted ) { |
|
614 | - if ( ! empty( $posted['sku'] ) ) { |
|
615 | - $product_id = (int) wc_get_product_id_by_sku( $posted['sku'] ); |
|
616 | - } elseif ( ! empty( $posted['product_id'] ) && empty( $posted['variation_id'] ) ) { |
|
613 | + protected function get_product_id($posted) { |
|
614 | + if ( ! empty($posted['sku'])) { |
|
615 | + $product_id = (int) wc_get_product_id_by_sku($posted['sku']); |
|
616 | + } elseif ( ! empty($posted['product_id']) && empty($posted['variation_id'])) { |
|
617 | 617 | $product_id = (int) $posted['product_id']; |
618 | - } elseif ( ! empty( $posted['variation_id'] ) ) { |
|
618 | + } elseif ( ! empty($posted['variation_id'])) { |
|
619 | 619 | $product_id = (int) $posted['variation_id']; |
620 | 620 | } else { |
621 | - throw new WC_REST_Exception( 'woocommerce_rest_required_product_reference', __( 'Product ID or SKU is required.', 'woocommerce' ), 400 ); |
|
621 | + throw new WC_REST_Exception('woocommerce_rest_required_product_reference', __('Product ID or SKU is required.', 'woocommerce'), 400); |
|
622 | 622 | } |
623 | 623 | return $product_id; |
624 | 624 | } |
@@ -629,9 +629,9 @@ discard block |
||
629 | 629 | * @param string $prop |
630 | 630 | * @param array $posted Request data. |
631 | 631 | */ |
632 | - protected function maybe_set_item_prop( $item, $prop, $posted ) { |
|
633 | - if ( isset( $posted[ $prop ] ) ) { |
|
634 | - $item->{"set_$prop"}( $posted[ $prop ] ); |
|
632 | + protected function maybe_set_item_prop($item, $prop, $posted) { |
|
633 | + if (isset($posted[$prop])) { |
|
634 | + $item->{"set_$prop"}($posted[$prop]); |
|
635 | 635 | } |
636 | 636 | } |
637 | 637 | |
@@ -641,9 +641,9 @@ discard block |
||
641 | 641 | * @param string[] $props |
642 | 642 | * @param array $posted Request data. |
643 | 643 | */ |
644 | - protected function maybe_set_item_props( $item, $props, $posted ) { |
|
645 | - foreach ( $props as $prop ) { |
|
646 | - $this->maybe_set_item_prop( $item, $prop, $posted ); |
|
644 | + protected function maybe_set_item_props($item, $props, $posted) { |
|
645 | + foreach ($props as $prop) { |
|
646 | + $this->maybe_set_item_prop($item, $prop, $posted); |
|
647 | 647 | } |
648 | 648 | } |
649 | 649 | |
@@ -656,22 +656,22 @@ discard block |
||
656 | 656 | * @return WC_Order_Item_Product |
657 | 657 | * @throws WC_REST_Exception Invalid data, server error. |
658 | 658 | */ |
659 | - protected function prepare_line_items( $posted, $action = 'create' ) { |
|
660 | - $item = new WC_Order_Item_Product( ! empty( $posted['id'] ) ? $posted['id'] : '' ); |
|
661 | - $product = wc_get_product( $this->get_product_id( $posted ) ); |
|
662 | - |
|
663 | - if ( $product !== $item->get_product() ) { |
|
664 | - $item->set_product( $product ); |
|
665 | - |
|
666 | - if ( 'create' === $action ) { |
|
667 | - $quantity = isset( $posted['quantity'] ) ? $posted['quantity'] : 1; |
|
668 | - $total = wc_get_price_excluding_tax( $product, array( 'qty' => $quantity ) ); |
|
669 | - $item->set_total( $total ); |
|
670 | - $item->set_subtotal( $total ); |
|
659 | + protected function prepare_line_items($posted, $action = 'create') { |
|
660 | + $item = new WC_Order_Item_Product( ! empty($posted['id']) ? $posted['id'] : ''); |
|
661 | + $product = wc_get_product($this->get_product_id($posted)); |
|
662 | + |
|
663 | + if ($product !== $item->get_product()) { |
|
664 | + $item->set_product($product); |
|
665 | + |
|
666 | + if ('create' === $action) { |
|
667 | + $quantity = isset($posted['quantity']) ? $posted['quantity'] : 1; |
|
668 | + $total = wc_get_price_excluding_tax($product, array('qty' => $quantity)); |
|
669 | + $item->set_total($total); |
|
670 | + $item->set_subtotal($total); |
|
671 | 671 | } |
672 | 672 | } |
673 | 673 | |
674 | - $this->maybe_set_item_props( $item, array( 'name', 'quantity', 'total', 'subtotal', 'tax_class' ), $posted ); |
|
674 | + $this->maybe_set_item_props($item, array('name', 'quantity', 'total', 'subtotal', 'tax_class'), $posted); |
|
675 | 675 | |
676 | 676 | return $item; |
677 | 677 | } |
@@ -685,16 +685,16 @@ discard block |
||
685 | 685 | * @return WC_Order_Item_Shipping |
686 | 686 | * @throws WC_REST_Exception Invalid data, server error. |
687 | 687 | */ |
688 | - protected function prepare_shipping_lines( $posted, $action ) { |
|
689 | - $item = new WC_Order_Item_Shipping( ! empty( $posted['id'] ) ? $posted['id'] : '' ); |
|
688 | + protected function prepare_shipping_lines($posted, $action) { |
|
689 | + $item = new WC_Order_Item_Shipping( ! empty($posted['id']) ? $posted['id'] : ''); |
|
690 | 690 | |
691 | - if ( 'create' === $action ) { |
|
692 | - if ( empty( $posted['method_id'] ) ) { |
|
693 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce' ), 400 ); |
|
691 | + if ('create' === $action) { |
|
692 | + if (empty($posted['method_id'])) { |
|
693 | + throw new WC_REST_Exception('woocommerce_rest_invalid_shipping_item', __('Shipping method ID is required.', 'woocommerce'), 400); |
|
694 | 694 | } |
695 | 695 | } |
696 | 696 | |
697 | - $this->maybe_set_item_props( $item, array( 'method_id', 'method_title', 'total' ), $posted ); |
|
697 | + $this->maybe_set_item_props($item, array('method_id', 'method_title', 'total'), $posted); |
|
698 | 698 | |
699 | 699 | return $item; |
700 | 700 | } |
@@ -708,16 +708,16 @@ discard block |
||
708 | 708 | * @return WC_Order_Item_Fee |
709 | 709 | * @throws WC_REST_Exception Invalid data, server error. |
710 | 710 | */ |
711 | - protected function prepare_fee_lines( $posted, $action ) { |
|
712 | - $item = new WC_Order_Item_Fee( ! empty( $posted['id'] ) ? $posted['id'] : '' ); |
|
711 | + protected function prepare_fee_lines($posted, $action) { |
|
712 | + $item = new WC_Order_Item_Fee( ! empty($posted['id']) ? $posted['id'] : ''); |
|
713 | 713 | |
714 | - if ( 'create' === $action ) { |
|
715 | - if ( empty( $posted['name'] ) ) { |
|
716 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_fee_item', __( 'Fee name is required.', 'woocommerce' ), 400 ); |
|
714 | + if ('create' === $action) { |
|
715 | + if (empty($posted['name'])) { |
|
716 | + throw new WC_REST_Exception('woocommerce_rest_invalid_fee_item', __('Fee name is required.', 'woocommerce'), 400); |
|
717 | 717 | } |
718 | 718 | } |
719 | 719 | |
720 | - $this->maybe_set_item_props( $item, array( 'name', 'tax_class', 'tax_status', 'total' ), $posted ); |
|
720 | + $this->maybe_set_item_props($item, array('name', 'tax_class', 'tax_status', 'total'), $posted); |
|
721 | 721 | |
722 | 722 | return $item; |
723 | 723 | } |
@@ -731,16 +731,16 @@ discard block |
||
731 | 731 | * @return WC_Order_Item_Coupon |
732 | 732 | * @throws WC_REST_Exception Invalid data, server error. |
733 | 733 | */ |
734 | - protected function prepare_coupon_lines( $posted, $action ) { |
|
735 | - $item = new WC_Order_Item_Coupon( ! empty( $posted['id'] ) ? $posted['id'] : '' ); |
|
734 | + protected function prepare_coupon_lines($posted, $action) { |
|
735 | + $item = new WC_Order_Item_Coupon( ! empty($posted['id']) ? $posted['id'] : ''); |
|
736 | 736 | |
737 | - if ( 'create' === $action ) { |
|
738 | - if ( empty( $posted['code'] ) ) { |
|
739 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_coupon_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 ); |
|
737 | + if ('create' === $action) { |
|
738 | + if (empty($posted['code'])) { |
|
739 | + throw new WC_REST_Exception('woocommerce_rest_invalid_coupon_coupon', __('Coupon code is required.', 'woocommerce'), 400); |
|
740 | 740 | } |
741 | 741 | } |
742 | 742 | |
743 | - $this->maybe_set_item_props( $item, array( 'code', 'discount' ), $posted ); |
|
743 | + $this->maybe_set_item_props($item, array('code', 'discount'), $posted); |
|
744 | 744 | |
745 | 745 | return $item; |
746 | 746 | } |
@@ -755,10 +755,10 @@ discard block |
||
755 | 755 | * @param array $posted item provided in the request body |
756 | 756 | * @throws WC_REST_Exception If item ID is not associated with order |
757 | 757 | */ |
758 | - protected function set_item( $order, $item_type, $posted ) { |
|
758 | + protected function set_item($order, $item_type, $posted) { |
|
759 | 759 | global $wpdb; |
760 | 760 | |
761 | - if ( ! empty( $posted['id'] ) ) { |
|
761 | + if ( ! empty($posted['id'])) { |
|
762 | 762 | $action = 'update'; |
763 | 763 | } else { |
764 | 764 | $action = 'create'; |
@@ -767,29 +767,29 @@ discard block |
||
767 | 767 | $method = 'prepare_' . $item_type; |
768 | 768 | |
769 | 769 | // Verify provided line item ID is associated with order. |
770 | - if ( 'update' === $action ) { |
|
770 | + if ('update' === $action) { |
|
771 | 771 | $result = $wpdb->get_row( |
772 | - $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d", |
|
773 | - absint( $posted['id'] ), |
|
774 | - absint( $order->get_id() ) |
|
772 | + $wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d", |
|
773 | + absint($posted['id']), |
|
774 | + absint($order->get_id()) |
|
775 | 775 | ) ); |
776 | - if ( is_null( $result ) ) { |
|
777 | - throw new WC_REST_Exception( 'woocommerce_rest_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 ); |
|
776 | + if (is_null($result)) { |
|
777 | + throw new WC_REST_Exception('woocommerce_rest_invalid_item_id', __('Order item ID provided is not associated with order.', 'woocommerce'), 400); |
|
778 | 778 | } |
779 | 779 | } |
780 | 780 | |
781 | 781 | // Prepare item data |
782 | - $item = $this->$method( $posted, $action ); |
|
782 | + $item = $this->$method($posted, $action); |
|
783 | 783 | |
784 | 784 | /** |
785 | 785 | * Action hook to adjust item before save. |
786 | 786 | * @since 3.0.0 |
787 | 787 | */ |
788 | - do_action( 'woocommerce_rest_set_order_item', $item, $posted ); |
|
788 | + do_action('woocommerce_rest_set_order_item', $item, $posted); |
|
789 | 789 | |
790 | 790 | // Save or add to order |
791 | - if ( 'create' === $action ) { |
|
792 | - $order->add_item( $item ); |
|
791 | + if ('create' === $action) { |
|
792 | + $order->add_item($item); |
|
793 | 793 | } else { |
794 | 794 | $item->save(); |
795 | 795 | } |
@@ -802,11 +802,11 @@ discard block |
||
802 | 802 | * @param array $item Item provided in the request body. |
803 | 803 | * @return bool True if the item resource ID is null, false otherwise. |
804 | 804 | */ |
805 | - protected function item_is_null( $item ) { |
|
806 | - $keys = array( 'product_id', 'method_id', 'method_title', 'name', 'code' ); |
|
805 | + protected function item_is_null($item) { |
|
806 | + $keys = array('product_id', 'method_id', 'method_title', 'name', 'code'); |
|
807 | 807 | |
808 | - foreach ( $keys as $key ) { |
|
809 | - if ( array_key_exists( $key, $item ) && is_null( $item[ $key ] ) ) { |
|
808 | + foreach ($keys as $key) { |
|
809 | + if (array_key_exists($key, $item) && is_null($item[$key])) { |
|
810 | 810 | return true; |
811 | 811 | } |
812 | 812 | } |
@@ -820,19 +820,19 @@ discard block |
||
820 | 820 | * @param WP_REST_Request $request Full details about the request. |
821 | 821 | * @return WP_Error|WP_REST_Response |
822 | 822 | */ |
823 | - public function create_item( $request ) { |
|
824 | - if ( ! empty( $request['id'] ) ) { |
|
823 | + public function create_item($request) { |
|
824 | + if ( ! empty($request['id'])) { |
|
825 | 825 | /* translators: %s: post type */ |
826 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
826 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
827 | 827 | } |
828 | 828 | |
829 | - $order_id = $this->create_order( $request ); |
|
830 | - if ( is_wp_error( $order_id ) ) { |
|
829 | + $order_id = $this->create_order($request); |
|
830 | + if (is_wp_error($order_id)) { |
|
831 | 831 | return $order_id; |
832 | 832 | } |
833 | 833 | |
834 | - $post = get_post( $order_id ); |
|
835 | - $this->update_additional_fields_for_object( $post, $request ); |
|
834 | + $post = get_post($order_id); |
|
835 | + $this->update_additional_fields_for_object($post, $request); |
|
836 | 836 | |
837 | 837 | /** |
838 | 838 | * Fires after a single item is created or updated via the REST API. |
@@ -841,12 +841,12 @@ discard block |
||
841 | 841 | * @param WP_REST_Request $request Request object. |
842 | 842 | * @param boolean $creating True when creating item, false when updating. |
843 | 843 | */ |
844 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true ); |
|
845 | - $request->set_param( 'context', 'edit' ); |
|
846 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
847 | - $response = rest_ensure_response( $response ); |
|
848 | - $response->set_status( 201 ); |
|
849 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ) ); |
|
844 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true); |
|
845 | + $request->set_param('context', 'edit'); |
|
846 | + $response = $this->prepare_item_for_response($post, $request); |
|
847 | + $response = rest_ensure_response($response); |
|
848 | + $response->set_status(201); |
|
849 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID))); |
|
850 | 850 | |
851 | 851 | return $response; |
852 | 852 | } |
@@ -857,21 +857,21 @@ discard block |
||
857 | 857 | * @param WP_REST_Request $request Full details about the request. |
858 | 858 | * @return WP_Error|WP_REST_Response |
859 | 859 | */ |
860 | - public function update_item( $request ) { |
|
860 | + public function update_item($request) { |
|
861 | 861 | try { |
862 | 862 | $post_id = (int) $request['id']; |
863 | 863 | |
864 | - if ( empty( $post_id ) || get_post_type( $post_id ) !== $this->post_type ) { |
|
865 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
864 | + if (empty($post_id) || get_post_type($post_id) !== $this->post_type) { |
|
865 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
866 | 866 | } |
867 | 867 | |
868 | - $order_id = $this->update_order( $request ); |
|
869 | - if ( is_wp_error( $order_id ) ) { |
|
868 | + $order_id = $this->update_order($request); |
|
869 | + if (is_wp_error($order_id)) { |
|
870 | 870 | return $order_id; |
871 | 871 | } |
872 | 872 | |
873 | - $post = get_post( $order_id ); |
|
874 | - $this->update_additional_fields_for_object( $post, $request ); |
|
873 | + $post = get_post($order_id); |
|
874 | + $this->update_additional_fields_for_object($post, $request); |
|
875 | 875 | |
876 | 876 | /** |
877 | 877 | * Fires after a single item is created or updated via the REST API. |
@@ -880,13 +880,13 @@ discard block |
||
880 | 880 | * @param WP_REST_Request $request Request object. |
881 | 881 | * @param boolean $creating True when creating item, false when updating. |
882 | 882 | */ |
883 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, false ); |
|
884 | - $request->set_param( 'context', 'edit' ); |
|
885 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
886 | - return rest_ensure_response( $response ); |
|
883 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, false); |
|
884 | + $request->set_param('context', 'edit'); |
|
885 | + $response = $this->prepare_item_for_response($post, $request); |
|
886 | + return rest_ensure_response($response); |
|
887 | 887 | |
888 | - } catch ( Exception $e ) { |
|
889 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
888 | + } catch (Exception $e) { |
|
889 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
890 | 890 | } |
891 | 891 | } |
892 | 892 | |
@@ -897,8 +897,8 @@ discard block |
||
897 | 897 | protected function get_order_statuses() { |
898 | 898 | $order_statuses = array(); |
899 | 899 | |
900 | - foreach ( array_keys( wc_get_order_statuses() ) as $status ) { |
|
901 | - $order_statuses[] = str_replace( 'wc-', '', $status ); |
|
900 | + foreach (array_keys(wc_get_order_statuses()) as $status) { |
|
901 | + $order_statuses[] = str_replace('wc-', '', $status); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | return $order_statuses; |
@@ -916,419 +916,419 @@ discard block |
||
916 | 916 | 'type' => 'object', |
917 | 917 | 'properties' => array( |
918 | 918 | 'id' => array( |
919 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
919 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
920 | 920 | 'type' => 'integer', |
921 | - 'context' => array( 'view', 'edit' ), |
|
921 | + 'context' => array('view', 'edit'), |
|
922 | 922 | 'readonly' => true, |
923 | 923 | ), |
924 | 924 | 'parent_id' => array( |
925 | - 'description' => __( 'Parent order ID.', 'woocommerce' ), |
|
925 | + 'description' => __('Parent order ID.', 'woocommerce'), |
|
926 | 926 | 'type' => 'integer', |
927 | - 'context' => array( 'view', 'edit' ), |
|
927 | + 'context' => array('view', 'edit'), |
|
928 | 928 | ), |
929 | 929 | 'status' => array( |
930 | - 'description' => __( 'Order status.', 'woocommerce' ), |
|
930 | + 'description' => __('Order status.', 'woocommerce'), |
|
931 | 931 | 'type' => 'string', |
932 | 932 | 'default' => 'pending', |
933 | 933 | 'enum' => $this->get_order_statuses(), |
934 | - 'context' => array( 'view', 'edit' ), |
|
934 | + 'context' => array('view', 'edit'), |
|
935 | 935 | ), |
936 | 936 | 'order_key' => array( |
937 | - 'description' => __( 'Order key.', 'woocommerce' ), |
|
937 | + 'description' => __('Order key.', 'woocommerce'), |
|
938 | 938 | 'type' => 'string', |
939 | - 'context' => array( 'view', 'edit' ), |
|
939 | + 'context' => array('view', 'edit'), |
|
940 | 940 | 'readonly' => true, |
941 | 941 | ), |
942 | 942 | 'number' => array( |
943 | - 'description' => __( 'Order number.', 'woocommerce' ), |
|
943 | + 'description' => __('Order number.', 'woocommerce'), |
|
944 | 944 | 'type' => 'string', |
945 | - 'context' => array( 'view', 'edit' ), |
|
945 | + 'context' => array('view', 'edit'), |
|
946 | 946 | 'readonly' => true, |
947 | 947 | ), |
948 | 948 | 'currency' => array( |
949 | - 'description' => __( 'Currency the order was created with, in ISO format.', 'woocommerce' ), |
|
949 | + 'description' => __('Currency the order was created with, in ISO format.', 'woocommerce'), |
|
950 | 950 | 'type' => 'string', |
951 | 951 | 'default' => get_woocommerce_currency(), |
952 | - 'enum' => array_keys( get_woocommerce_currencies() ), |
|
953 | - 'context' => array( 'view', 'edit' ), |
|
952 | + 'enum' => array_keys(get_woocommerce_currencies()), |
|
953 | + 'context' => array('view', 'edit'), |
|
954 | 954 | ), |
955 | 955 | 'version' => array( |
956 | - 'description' => __( 'Version of WooCommerce which last updated the order.', 'woocommerce' ), |
|
956 | + 'description' => __('Version of WooCommerce which last updated the order.', 'woocommerce'), |
|
957 | 957 | 'type' => 'integer', |
958 | - 'context' => array( 'view', 'edit' ), |
|
958 | + 'context' => array('view', 'edit'), |
|
959 | 959 | 'readonly' => true, |
960 | 960 | ), |
961 | 961 | 'prices_include_tax' => array( |
962 | - 'description' => __( 'True the prices included tax during checkout.', 'woocommerce' ), |
|
962 | + 'description' => __('True the prices included tax during checkout.', 'woocommerce'), |
|
963 | 963 | 'type' => 'boolean', |
964 | - 'context' => array( 'view', 'edit' ), |
|
964 | + 'context' => array('view', 'edit'), |
|
965 | 965 | 'readonly' => true, |
966 | 966 | ), |
967 | 967 | 'date_created' => array( |
968 | - 'description' => __( "The date the order was created, as GMT.", 'woocommerce' ), |
|
968 | + 'description' => __("The date the order was created, as GMT.", 'woocommerce'), |
|
969 | 969 | 'type' => 'date-time', |
970 | - 'context' => array( 'view', 'edit' ), |
|
970 | + 'context' => array('view', 'edit'), |
|
971 | 971 | 'readonly' => true, |
972 | 972 | ), |
973 | 973 | 'date_modified' => array( |
974 | - 'description' => __( "The date the order was last modified, as GMT.", 'woocommerce' ), |
|
974 | + 'description' => __("The date the order was last modified, as GMT.", 'woocommerce'), |
|
975 | 975 | 'type' => 'date-time', |
976 | - 'context' => array( 'view', 'edit' ), |
|
976 | + 'context' => array('view', 'edit'), |
|
977 | 977 | 'readonly' => true, |
978 | 978 | ), |
979 | 979 | 'customer_id' => array( |
980 | - 'description' => __( 'User ID who owns the order. 0 for guests.', 'woocommerce' ), |
|
980 | + 'description' => __('User ID who owns the order. 0 for guests.', 'woocommerce'), |
|
981 | 981 | 'type' => 'integer', |
982 | 982 | 'default' => 0, |
983 | - 'context' => array( 'view', 'edit' ), |
|
983 | + 'context' => array('view', 'edit'), |
|
984 | 984 | ), |
985 | 985 | 'discount_total' => array( |
986 | - 'description' => __( 'Total discount amount for the order.', 'woocommerce' ), |
|
986 | + 'description' => __('Total discount amount for the order.', 'woocommerce'), |
|
987 | 987 | 'type' => 'string', |
988 | - 'context' => array( 'view', 'edit' ), |
|
988 | + 'context' => array('view', 'edit'), |
|
989 | 989 | 'readonly' => true, |
990 | 990 | ), |
991 | 991 | 'discount_tax' => array( |
992 | - 'description' => __( 'Total discount tax amount for the order.', 'woocommerce' ), |
|
992 | + 'description' => __('Total discount tax amount for the order.', 'woocommerce'), |
|
993 | 993 | 'type' => 'string', |
994 | - 'context' => array( 'view', 'edit' ), |
|
994 | + 'context' => array('view', 'edit'), |
|
995 | 995 | 'readonly' => true, |
996 | 996 | ), |
997 | 997 | 'shipping_total' => array( |
998 | - 'description' => __( 'Total shipping amount for the order.', 'woocommerce' ), |
|
998 | + 'description' => __('Total shipping amount for the order.', 'woocommerce'), |
|
999 | 999 | 'type' => 'string', |
1000 | - 'context' => array( 'view', 'edit' ), |
|
1000 | + 'context' => array('view', 'edit'), |
|
1001 | 1001 | 'readonly' => true, |
1002 | 1002 | ), |
1003 | 1003 | 'shipping_tax' => array( |
1004 | - 'description' => __( 'Total shipping tax amount for the order.', 'woocommerce' ), |
|
1004 | + 'description' => __('Total shipping tax amount for the order.', 'woocommerce'), |
|
1005 | 1005 | 'type' => 'string', |
1006 | - 'context' => array( 'view', 'edit' ), |
|
1006 | + 'context' => array('view', 'edit'), |
|
1007 | 1007 | 'readonly' => true, |
1008 | 1008 | ), |
1009 | 1009 | 'cart_tax' => array( |
1010 | - 'description' => __( 'Sum of line item taxes only.', 'woocommerce' ), |
|
1010 | + 'description' => __('Sum of line item taxes only.', 'woocommerce'), |
|
1011 | 1011 | 'type' => 'string', |
1012 | - 'context' => array( 'view', 'edit' ), |
|
1012 | + 'context' => array('view', 'edit'), |
|
1013 | 1013 | 'readonly' => true, |
1014 | 1014 | ), |
1015 | 1015 | 'total' => array( |
1016 | - 'description' => __( 'Grand total.', 'woocommerce' ), |
|
1016 | + 'description' => __('Grand total.', 'woocommerce'), |
|
1017 | 1017 | 'type' => 'string', |
1018 | - 'context' => array( 'view', 'edit' ), |
|
1018 | + 'context' => array('view', 'edit'), |
|
1019 | 1019 | 'readonly' => true, |
1020 | 1020 | ), |
1021 | 1021 | 'total_tax' => array( |
1022 | - 'description' => __( 'Sum of all taxes.', 'woocommerce' ), |
|
1022 | + 'description' => __('Sum of all taxes.', 'woocommerce'), |
|
1023 | 1023 | 'type' => 'string', |
1024 | - 'context' => array( 'view', 'edit' ), |
|
1024 | + 'context' => array('view', 'edit'), |
|
1025 | 1025 | 'readonly' => true, |
1026 | 1026 | ), |
1027 | 1027 | 'billing' => array( |
1028 | - 'description' => __( 'Billing address.', 'woocommerce' ), |
|
1028 | + 'description' => __('Billing address.', 'woocommerce'), |
|
1029 | 1029 | 'type' => 'object', |
1030 | - 'context' => array( 'view', 'edit' ), |
|
1030 | + 'context' => array('view', 'edit'), |
|
1031 | 1031 | 'properties' => array( |
1032 | 1032 | 'first_name' => array( |
1033 | - 'description' => __( 'First name.', 'woocommerce' ), |
|
1033 | + 'description' => __('First name.', 'woocommerce'), |
|
1034 | 1034 | 'type' => 'string', |
1035 | - 'context' => array( 'view', 'edit' ), |
|
1035 | + 'context' => array('view', 'edit'), |
|
1036 | 1036 | ), |
1037 | 1037 | 'last_name' => array( |
1038 | - 'description' => __( 'Last name.', 'woocommerce' ), |
|
1038 | + 'description' => __('Last name.', 'woocommerce'), |
|
1039 | 1039 | 'type' => 'string', |
1040 | - 'context' => array( 'view', 'edit' ), |
|
1040 | + 'context' => array('view', 'edit'), |
|
1041 | 1041 | ), |
1042 | 1042 | 'company' => array( |
1043 | - 'description' => __( 'Company name.', 'woocommerce' ), |
|
1043 | + 'description' => __('Company name.', 'woocommerce'), |
|
1044 | 1044 | 'type' => 'string', |
1045 | - 'context' => array( 'view', 'edit' ), |
|
1045 | + 'context' => array('view', 'edit'), |
|
1046 | 1046 | ), |
1047 | 1047 | 'address_1' => array( |
1048 | - 'description' => __( 'Address line 1.', 'woocommerce' ), |
|
1048 | + 'description' => __('Address line 1.', 'woocommerce'), |
|
1049 | 1049 | 'type' => 'string', |
1050 | - 'context' => array( 'view', 'edit' ), |
|
1050 | + 'context' => array('view', 'edit'), |
|
1051 | 1051 | ), |
1052 | 1052 | 'address_2' => array( |
1053 | - 'description' => __( 'Address line 2.', 'woocommerce' ), |
|
1053 | + 'description' => __('Address line 2.', 'woocommerce'), |
|
1054 | 1054 | 'type' => 'string', |
1055 | - 'context' => array( 'view', 'edit' ), |
|
1055 | + 'context' => array('view', 'edit'), |
|
1056 | 1056 | ), |
1057 | 1057 | 'city' => array( |
1058 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
1058 | + 'description' => __('City name.', 'woocommerce'), |
|
1059 | 1059 | 'type' => 'string', |
1060 | - 'context' => array( 'view', 'edit' ), |
|
1060 | + 'context' => array('view', 'edit'), |
|
1061 | 1061 | ), |
1062 | 1062 | 'state' => array( |
1063 | - 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
|
1063 | + 'description' => __('ISO code or name of the state, province or district.', 'woocommerce'), |
|
1064 | 1064 | 'type' => 'string', |
1065 | - 'context' => array( 'view', 'edit' ), |
|
1065 | + 'context' => array('view', 'edit'), |
|
1066 | 1066 | ), |
1067 | 1067 | 'postcode' => array( |
1068 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
1068 | + 'description' => __('Postal code.', 'woocommerce'), |
|
1069 | 1069 | 'type' => 'string', |
1070 | - 'context' => array( 'view', 'edit' ), |
|
1070 | + 'context' => array('view', 'edit'), |
|
1071 | 1071 | ), |
1072 | 1072 | 'country' => array( |
1073 | - 'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ), |
|
1073 | + 'description' => __('Country code in ISO 3166-1 alpha-2 format.', 'woocommerce'), |
|
1074 | 1074 | 'type' => 'string', |
1075 | - 'context' => array( 'view', 'edit' ), |
|
1075 | + 'context' => array('view', 'edit'), |
|
1076 | 1076 | ), |
1077 | 1077 | 'email' => array( |
1078 | - 'description' => __( 'Email address.', 'woocommerce' ), |
|
1078 | + 'description' => __('Email address.', 'woocommerce'), |
|
1079 | 1079 | 'type' => 'string', |
1080 | 1080 | 'format' => 'email', |
1081 | - 'context' => array( 'view', 'edit' ), |
|
1081 | + 'context' => array('view', 'edit'), |
|
1082 | 1082 | ), |
1083 | 1083 | 'phone' => array( |
1084 | - 'description' => __( 'Phone number.', 'woocommerce' ), |
|
1084 | + 'description' => __('Phone number.', 'woocommerce'), |
|
1085 | 1085 | 'type' => 'string', |
1086 | - 'context' => array( 'view', 'edit' ), |
|
1086 | + 'context' => array('view', 'edit'), |
|
1087 | 1087 | ), |
1088 | 1088 | ), |
1089 | 1089 | ), |
1090 | 1090 | 'shipping' => array( |
1091 | - 'description' => __( 'Shipping address.', 'woocommerce' ), |
|
1091 | + 'description' => __('Shipping address.', 'woocommerce'), |
|
1092 | 1092 | 'type' => 'object', |
1093 | - 'context' => array( 'view', 'edit' ), |
|
1093 | + 'context' => array('view', 'edit'), |
|
1094 | 1094 | 'properties' => array( |
1095 | 1095 | 'first_name' => array( |
1096 | - 'description' => __( 'First name.', 'woocommerce' ), |
|
1096 | + 'description' => __('First name.', 'woocommerce'), |
|
1097 | 1097 | 'type' => 'string', |
1098 | - 'context' => array( 'view', 'edit' ), |
|
1098 | + 'context' => array('view', 'edit'), |
|
1099 | 1099 | ), |
1100 | 1100 | 'last_name' => array( |
1101 | - 'description' => __( 'Last name.', 'woocommerce' ), |
|
1101 | + 'description' => __('Last name.', 'woocommerce'), |
|
1102 | 1102 | 'type' => 'string', |
1103 | - 'context' => array( 'view', 'edit' ), |
|
1103 | + 'context' => array('view', 'edit'), |
|
1104 | 1104 | ), |
1105 | 1105 | 'company' => array( |
1106 | - 'description' => __( 'Company name.', 'woocommerce' ), |
|
1106 | + 'description' => __('Company name.', 'woocommerce'), |
|
1107 | 1107 | 'type' => 'string', |
1108 | - 'context' => array( 'view', 'edit' ), |
|
1108 | + 'context' => array('view', 'edit'), |
|
1109 | 1109 | ), |
1110 | 1110 | 'address_1' => array( |
1111 | - 'description' => __( 'Address line 1.', 'woocommerce' ), |
|
1111 | + 'description' => __('Address line 1.', 'woocommerce'), |
|
1112 | 1112 | 'type' => 'string', |
1113 | - 'context' => array( 'view', 'edit' ), |
|
1113 | + 'context' => array('view', 'edit'), |
|
1114 | 1114 | ), |
1115 | 1115 | 'address_2' => array( |
1116 | - 'description' => __( 'Address line 2.', 'woocommerce' ), |
|
1116 | + 'description' => __('Address line 2.', 'woocommerce'), |
|
1117 | 1117 | 'type' => 'string', |
1118 | - 'context' => array( 'view', 'edit' ), |
|
1118 | + 'context' => array('view', 'edit'), |
|
1119 | 1119 | ), |
1120 | 1120 | 'city' => array( |
1121 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
1121 | + 'description' => __('City name.', 'woocommerce'), |
|
1122 | 1122 | 'type' => 'string', |
1123 | - 'context' => array( 'view', 'edit' ), |
|
1123 | + 'context' => array('view', 'edit'), |
|
1124 | 1124 | ), |
1125 | 1125 | 'state' => array( |
1126 | - 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
|
1126 | + 'description' => __('ISO code or name of the state, province or district.', 'woocommerce'), |
|
1127 | 1127 | 'type' => 'string', |
1128 | - 'context' => array( 'view', 'edit' ), |
|
1128 | + 'context' => array('view', 'edit'), |
|
1129 | 1129 | ), |
1130 | 1130 | 'postcode' => array( |
1131 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
1131 | + 'description' => __('Postal code.', 'woocommerce'), |
|
1132 | 1132 | 'type' => 'string', |
1133 | - 'context' => array( 'view', 'edit' ), |
|
1133 | + 'context' => array('view', 'edit'), |
|
1134 | 1134 | ), |
1135 | 1135 | 'country' => array( |
1136 | - 'description' => __( 'Country code in ISO 3166-1 alpha-2 format.', 'woocommerce' ), |
|
1136 | + 'description' => __('Country code in ISO 3166-1 alpha-2 format.', 'woocommerce'), |
|
1137 | 1137 | 'type' => 'string', |
1138 | - 'context' => array( 'view', 'edit' ), |
|
1138 | + 'context' => array('view', 'edit'), |
|
1139 | 1139 | ), |
1140 | 1140 | ), |
1141 | 1141 | ), |
1142 | 1142 | 'payment_method' => array( |
1143 | - 'description' => __( 'Payment method ID.', 'woocommerce' ), |
|
1143 | + 'description' => __('Payment method ID.', 'woocommerce'), |
|
1144 | 1144 | 'type' => 'string', |
1145 | - 'context' => array( 'view', 'edit' ), |
|
1145 | + 'context' => array('view', 'edit'), |
|
1146 | 1146 | ), |
1147 | 1147 | 'payment_method_title' => array( |
1148 | - 'description' => __( 'Payment method title.', 'woocommerce' ), |
|
1148 | + 'description' => __('Payment method title.', 'woocommerce'), |
|
1149 | 1149 | 'type' => 'string', |
1150 | - 'context' => array( 'view', 'edit' ), |
|
1150 | + 'context' => array('view', 'edit'), |
|
1151 | 1151 | 'arg_options' => array( |
1152 | 1152 | 'sanitize_callback' => 'sanitize_text_field', |
1153 | 1153 | ), |
1154 | 1154 | ), |
1155 | 1155 | 'set_paid' => array( |
1156 | - 'description' => __( 'Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce' ), |
|
1156 | + 'description' => __('Define if the order is paid. It will set the status to processing and reduce stock items.', 'woocommerce'), |
|
1157 | 1157 | 'type' => 'boolean', |
1158 | 1158 | 'default' => false, |
1159 | - 'context' => array( 'edit' ), |
|
1159 | + 'context' => array('edit'), |
|
1160 | 1160 | ), |
1161 | 1161 | 'transaction_id' => array( |
1162 | - 'description' => __( 'Unique transaction ID.', 'woocommerce' ), |
|
1162 | + 'description' => __('Unique transaction ID.', 'woocommerce'), |
|
1163 | 1163 | 'type' => 'string', |
1164 | - 'context' => array( 'view', 'edit' ), |
|
1164 | + 'context' => array('view', 'edit'), |
|
1165 | 1165 | ), |
1166 | 1166 | 'customer_ip_address' => array( |
1167 | - 'description' => __( "Customer's IP address.", 'woocommerce' ), |
|
1167 | + 'description' => __("Customer's IP address.", 'woocommerce'), |
|
1168 | 1168 | 'type' => 'string', |
1169 | - 'context' => array( 'view', 'edit' ), |
|
1169 | + 'context' => array('view', 'edit'), |
|
1170 | 1170 | 'readonly' => true, |
1171 | 1171 | ), |
1172 | 1172 | 'customer_user_agent' => array( |
1173 | - 'description' => __( 'User agent of the customer.', 'woocommerce' ), |
|
1173 | + 'description' => __('User agent of the customer.', 'woocommerce'), |
|
1174 | 1174 | 'type' => 'string', |
1175 | - 'context' => array( 'view', 'edit' ), |
|
1175 | + 'context' => array('view', 'edit'), |
|
1176 | 1176 | 'readonly' => true, |
1177 | 1177 | ), |
1178 | 1178 | 'created_via' => array( |
1179 | - 'description' => __( 'Shows where the order was created.', 'woocommerce' ), |
|
1179 | + 'description' => __('Shows where the order was created.', 'woocommerce'), |
|
1180 | 1180 | 'type' => 'string', |
1181 | - 'context' => array( 'view', 'edit' ), |
|
1181 | + 'context' => array('view', 'edit'), |
|
1182 | 1182 | 'readonly' => true, |
1183 | 1183 | ), |
1184 | 1184 | 'customer_note' => array( |
1185 | - 'description' => __( 'Note left by customer during checkout.', 'woocommerce' ), |
|
1185 | + 'description' => __('Note left by customer during checkout.', 'woocommerce'), |
|
1186 | 1186 | 'type' => 'string', |
1187 | - 'context' => array( 'view', 'edit' ), |
|
1187 | + 'context' => array('view', 'edit'), |
|
1188 | 1188 | ), |
1189 | 1189 | 'date_completed' => array( |
1190 | - 'description' => __( "The date the order was completed, in the site's timezone.", 'woocommerce' ), |
|
1190 | + 'description' => __("The date the order was completed, in the site's timezone.", 'woocommerce'), |
|
1191 | 1191 | 'type' => 'date-time', |
1192 | - 'context' => array( 'view', 'edit' ), |
|
1192 | + 'context' => array('view', 'edit'), |
|
1193 | 1193 | 'readonly' => true, |
1194 | 1194 | ), |
1195 | 1195 | 'date_paid' => array( |
1196 | - 'description' => __( "The date the order was paid, in the site's timezone.", 'woocommerce' ), |
|
1196 | + 'description' => __("The date the order was paid, in the site's timezone.", 'woocommerce'), |
|
1197 | 1197 | 'type' => 'date-time', |
1198 | - 'context' => array( 'view', 'edit' ), |
|
1198 | + 'context' => array('view', 'edit'), |
|
1199 | 1199 | 'readonly' => true, |
1200 | 1200 | ), |
1201 | 1201 | 'cart_hash' => array( |
1202 | - 'description' => __( 'MD5 hash of cart items to ensure orders are not modified.', 'woocommerce' ), |
|
1202 | + 'description' => __('MD5 hash of cart items to ensure orders are not modified.', 'woocommerce'), |
|
1203 | 1203 | 'type' => 'string', |
1204 | - 'context' => array( 'view', 'edit' ), |
|
1204 | + 'context' => array('view', 'edit'), |
|
1205 | 1205 | 'readonly' => true, |
1206 | 1206 | ), |
1207 | 1207 | 'line_items' => array( |
1208 | - 'description' => __( 'Line items data.', 'woocommerce' ), |
|
1208 | + 'description' => __('Line items data.', 'woocommerce'), |
|
1209 | 1209 | 'type' => 'array', |
1210 | - 'context' => array( 'view', 'edit' ), |
|
1210 | + 'context' => array('view', 'edit'), |
|
1211 | 1211 | 'items' => array( |
1212 | 1212 | 'type' => 'object', |
1213 | 1213 | 'properties' => array( |
1214 | 1214 | 'id' => array( |
1215 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
1215 | + 'description' => __('Item ID.', 'woocommerce'), |
|
1216 | 1216 | 'type' => 'integer', |
1217 | - 'context' => array( 'view', 'edit' ), |
|
1217 | + 'context' => array('view', 'edit'), |
|
1218 | 1218 | 'readonly' => true, |
1219 | 1219 | ), |
1220 | 1220 | 'name' => array( |
1221 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
1221 | + 'description' => __('Product name.', 'woocommerce'), |
|
1222 | 1222 | 'type' => 'mixed', |
1223 | - 'context' => array( 'view', 'edit' ), |
|
1223 | + 'context' => array('view', 'edit'), |
|
1224 | 1224 | 'readonly' => true, |
1225 | 1225 | ), |
1226 | 1226 | 'sku' => array( |
1227 | - 'description' => __( 'Product SKU.', 'woocommerce' ), |
|
1227 | + 'description' => __('Product SKU.', 'woocommerce'), |
|
1228 | 1228 | 'type' => 'string', |
1229 | - 'context' => array( 'view', 'edit' ), |
|
1229 | + 'context' => array('view', 'edit'), |
|
1230 | 1230 | 'readonly' => true, |
1231 | 1231 | ), |
1232 | 1232 | 'product_id' => array( |
1233 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
1233 | + 'description' => __('Product ID.', 'woocommerce'), |
|
1234 | 1234 | 'type' => 'mixed', |
1235 | - 'context' => array( 'view', 'edit' ), |
|
1235 | + 'context' => array('view', 'edit'), |
|
1236 | 1236 | ), |
1237 | 1237 | 'variation_id' => array( |
1238 | - 'description' => __( 'Variation ID, if applicable.', 'woocommerce' ), |
|
1238 | + 'description' => __('Variation ID, if applicable.', 'woocommerce'), |
|
1239 | 1239 | 'type' => 'integer', |
1240 | - 'context' => array( 'view', 'edit' ), |
|
1240 | + 'context' => array('view', 'edit'), |
|
1241 | 1241 | ), |
1242 | 1242 | 'quantity' => array( |
1243 | - 'description' => __( 'Quantity ordered.', 'woocommerce' ), |
|
1243 | + 'description' => __('Quantity ordered.', 'woocommerce'), |
|
1244 | 1244 | 'type' => 'integer', |
1245 | - 'context' => array( 'view', 'edit' ), |
|
1245 | + 'context' => array('view', 'edit'), |
|
1246 | 1246 | ), |
1247 | 1247 | 'tax_class' => array( |
1248 | - 'description' => __( 'Tax class of product.', 'woocommerce' ), |
|
1248 | + 'description' => __('Tax class of product.', 'woocommerce'), |
|
1249 | 1249 | 'type' => 'string', |
1250 | - 'context' => array( 'view', 'edit' ), |
|
1250 | + 'context' => array('view', 'edit'), |
|
1251 | 1251 | 'readonly' => true, |
1252 | 1252 | ), |
1253 | 1253 | 'price' => array( |
1254 | - 'description' => __( 'Product price.', 'woocommerce' ), |
|
1254 | + 'description' => __('Product price.', 'woocommerce'), |
|
1255 | 1255 | 'type' => 'string', |
1256 | - 'context' => array( 'view', 'edit' ), |
|
1256 | + 'context' => array('view', 'edit'), |
|
1257 | 1257 | 'readonly' => true, |
1258 | 1258 | ), |
1259 | 1259 | 'subtotal' => array( |
1260 | - 'description' => __( 'Line subtotal (before discounts).', 'woocommerce' ), |
|
1260 | + 'description' => __('Line subtotal (before discounts).', 'woocommerce'), |
|
1261 | 1261 | 'type' => 'string', |
1262 | - 'context' => array( 'view', 'edit' ), |
|
1262 | + 'context' => array('view', 'edit'), |
|
1263 | 1263 | ), |
1264 | 1264 | 'subtotal_tax' => array( |
1265 | - 'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce' ), |
|
1265 | + 'description' => __('Line subtotal tax (before discounts).', 'woocommerce'), |
|
1266 | 1266 | 'type' => 'string', |
1267 | - 'context' => array( 'view', 'edit' ), |
|
1267 | + 'context' => array('view', 'edit'), |
|
1268 | 1268 | ), |
1269 | 1269 | 'total' => array( |
1270 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
1270 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
1271 | 1271 | 'type' => 'string', |
1272 | - 'context' => array( 'view', 'edit' ), |
|
1272 | + 'context' => array('view', 'edit'), |
|
1273 | 1273 | ), |
1274 | 1274 | 'total_tax' => array( |
1275 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
1275 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
1276 | 1276 | 'type' => 'string', |
1277 | - 'context' => array( 'view', 'edit' ), |
|
1277 | + 'context' => array('view', 'edit'), |
|
1278 | 1278 | ), |
1279 | 1279 | 'taxes' => array( |
1280 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
1280 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
1281 | 1281 | 'type' => 'array', |
1282 | - 'context' => array( 'view', 'edit' ), |
|
1282 | + 'context' => array('view', 'edit'), |
|
1283 | 1283 | 'readonly' => true, |
1284 | 1284 | 'items' => array( |
1285 | 1285 | 'type' => 'object', |
1286 | 1286 | 'properties' => array( |
1287 | 1287 | 'id' => array( |
1288 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
1288 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
1289 | 1289 | 'type' => 'integer', |
1290 | - 'context' => array( 'view', 'edit' ), |
|
1290 | + 'context' => array('view', 'edit'), |
|
1291 | 1291 | 'readonly' => true, |
1292 | 1292 | ), |
1293 | 1293 | 'total' => array( |
1294 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
1294 | + 'description' => __('Tax total.', 'woocommerce'), |
|
1295 | 1295 | 'type' => 'string', |
1296 | - 'context' => array( 'view', 'edit' ), |
|
1296 | + 'context' => array('view', 'edit'), |
|
1297 | 1297 | 'readonly' => true, |
1298 | 1298 | ), |
1299 | 1299 | 'subtotal' => array( |
1300 | - 'description' => __( 'Tax subtotal.', 'woocommerce' ), |
|
1300 | + 'description' => __('Tax subtotal.', 'woocommerce'), |
|
1301 | 1301 | 'type' => 'string', |
1302 | - 'context' => array( 'view', 'edit' ), |
|
1302 | + 'context' => array('view', 'edit'), |
|
1303 | 1303 | 'readonly' => true, |
1304 | 1304 | ), |
1305 | 1305 | ), |
1306 | 1306 | ), |
1307 | 1307 | ), |
1308 | 1308 | 'meta' => array( |
1309 | - 'description' => __( 'Line item meta data.', 'woocommerce' ), |
|
1309 | + 'description' => __('Line item meta data.', 'woocommerce'), |
|
1310 | 1310 | 'type' => 'array', |
1311 | - 'context' => array( 'view', 'edit' ), |
|
1311 | + 'context' => array('view', 'edit'), |
|
1312 | 1312 | 'readonly' => true, |
1313 | 1313 | 'items' => array( |
1314 | 1314 | 'type' => 'object', |
1315 | 1315 | 'properties' => array( |
1316 | 1316 | 'key' => array( |
1317 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
1317 | + 'description' => __('Meta key.', 'woocommerce'), |
|
1318 | 1318 | 'type' => 'string', |
1319 | - 'context' => array( 'view', 'edit' ), |
|
1319 | + 'context' => array('view', 'edit'), |
|
1320 | 1320 | 'readonly' => true, |
1321 | 1321 | ), |
1322 | 1322 | 'label' => array( |
1323 | - 'description' => __( 'Meta label.', 'woocommerce' ), |
|
1323 | + 'description' => __('Meta label.', 'woocommerce'), |
|
1324 | 1324 | 'type' => 'string', |
1325 | - 'context' => array( 'view', 'edit' ), |
|
1325 | + 'context' => array('view', 'edit'), |
|
1326 | 1326 | 'readonly' => true, |
1327 | 1327 | ), |
1328 | 1328 | 'value' => array( |
1329 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
1329 | + 'description' => __('Meta value.', 'woocommerce'), |
|
1330 | 1330 | 'type' => 'mixed', |
1331 | - 'context' => array( 'view', 'edit' ), |
|
1331 | + 'context' => array('view', 'edit'), |
|
1332 | 1332 | 'readonly' => true, |
1333 | 1333 | ), |
1334 | 1334 | ), |
@@ -1338,110 +1338,110 @@ discard block |
||
1338 | 1338 | ), |
1339 | 1339 | ), |
1340 | 1340 | 'tax_lines' => array( |
1341 | - 'description' => __( 'Tax lines data.', 'woocommerce' ), |
|
1341 | + 'description' => __('Tax lines data.', 'woocommerce'), |
|
1342 | 1342 | 'type' => 'array', |
1343 | - 'context' => array( 'view', 'edit' ), |
|
1343 | + 'context' => array('view', 'edit'), |
|
1344 | 1344 | 'readonly' => true, |
1345 | 1345 | 'items' => array( |
1346 | 1346 | 'type' => 'object', |
1347 | 1347 | 'properties' => array( |
1348 | 1348 | 'id' => array( |
1349 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
1349 | + 'description' => __('Item ID.', 'woocommerce'), |
|
1350 | 1350 | 'type' => 'integer', |
1351 | - 'context' => array( 'view', 'edit' ), |
|
1351 | + 'context' => array('view', 'edit'), |
|
1352 | 1352 | 'readonly' => true, |
1353 | 1353 | ), |
1354 | 1354 | 'rate_code' => array( |
1355 | - 'description' => __( 'Tax rate code.', 'woocommerce' ), |
|
1355 | + 'description' => __('Tax rate code.', 'woocommerce'), |
|
1356 | 1356 | 'type' => 'string', |
1357 | - 'context' => array( 'view', 'edit' ), |
|
1357 | + 'context' => array('view', 'edit'), |
|
1358 | 1358 | 'readonly' => true, |
1359 | 1359 | ), |
1360 | 1360 | 'rate_id' => array( |
1361 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
1361 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
1362 | 1362 | 'type' => 'string', |
1363 | - 'context' => array( 'view', 'edit' ), |
|
1363 | + 'context' => array('view', 'edit'), |
|
1364 | 1364 | 'readonly' => true, |
1365 | 1365 | ), |
1366 | 1366 | 'label' => array( |
1367 | - 'description' => __( 'Tax rate label.', 'woocommerce' ), |
|
1367 | + 'description' => __('Tax rate label.', 'woocommerce'), |
|
1368 | 1368 | 'type' => 'string', |
1369 | - 'context' => array( 'view', 'edit' ), |
|
1369 | + 'context' => array('view', 'edit'), |
|
1370 | 1370 | 'readonly' => true, |
1371 | 1371 | ), |
1372 | 1372 | 'compound' => array( |
1373 | - 'description' => __( 'Show if is a compound tax rate.', 'woocommerce' ), |
|
1373 | + 'description' => __('Show if is a compound tax rate.', 'woocommerce'), |
|
1374 | 1374 | 'type' => 'boolean', |
1375 | - 'context' => array( 'view', 'edit' ), |
|
1375 | + 'context' => array('view', 'edit'), |
|
1376 | 1376 | 'readonly' => true, |
1377 | 1377 | ), |
1378 | 1378 | 'tax_total' => array( |
1379 | - 'description' => __( 'Tax total (not including shipping taxes).', 'woocommerce' ), |
|
1379 | + 'description' => __('Tax total (not including shipping taxes).', 'woocommerce'), |
|
1380 | 1380 | 'type' => 'string', |
1381 | - 'context' => array( 'view', 'edit' ), |
|
1381 | + 'context' => array('view', 'edit'), |
|
1382 | 1382 | 'readonly' => true, |
1383 | 1383 | ), |
1384 | 1384 | 'shipping_tax_total' => array( |
1385 | - 'description' => __( 'Shipping tax total.', 'woocommerce' ), |
|
1385 | + 'description' => __('Shipping tax total.', 'woocommerce'), |
|
1386 | 1386 | 'type' => 'string', |
1387 | - 'context' => array( 'view', 'edit' ), |
|
1387 | + 'context' => array('view', 'edit'), |
|
1388 | 1388 | 'readonly' => true, |
1389 | 1389 | ), |
1390 | 1390 | ), |
1391 | 1391 | ), |
1392 | 1392 | ), |
1393 | 1393 | 'shipping_lines' => array( |
1394 | - 'description' => __( 'Shipping lines data.', 'woocommerce' ), |
|
1394 | + 'description' => __('Shipping lines data.', 'woocommerce'), |
|
1395 | 1395 | 'type' => 'array', |
1396 | - 'context' => array( 'view', 'edit' ), |
|
1396 | + 'context' => array('view', 'edit'), |
|
1397 | 1397 | 'items' => array( |
1398 | 1398 | 'type' => 'object', |
1399 | 1399 | 'properties' => array( |
1400 | 1400 | 'id' => array( |
1401 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
1401 | + 'description' => __('Item ID.', 'woocommerce'), |
|
1402 | 1402 | 'type' => 'integer', |
1403 | - 'context' => array( 'view', 'edit' ), |
|
1403 | + 'context' => array('view', 'edit'), |
|
1404 | 1404 | 'readonly' => true, |
1405 | 1405 | ), |
1406 | 1406 | 'method_title' => array( |
1407 | - 'description' => __( 'Shipping method name.', 'woocommerce' ), |
|
1407 | + 'description' => __('Shipping method name.', 'woocommerce'), |
|
1408 | 1408 | 'type' => 'mixed', |
1409 | - 'context' => array( 'view', 'edit' ), |
|
1409 | + 'context' => array('view', 'edit'), |
|
1410 | 1410 | ), |
1411 | 1411 | 'method_id' => array( |
1412 | - 'description' => __( 'Shipping method ID.', 'woocommerce' ), |
|
1412 | + 'description' => __('Shipping method ID.', 'woocommerce'), |
|
1413 | 1413 | 'type' => 'mixed', |
1414 | - 'context' => array( 'view', 'edit' ), |
|
1414 | + 'context' => array('view', 'edit'), |
|
1415 | 1415 | ), |
1416 | 1416 | 'total' => array( |
1417 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
1417 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
1418 | 1418 | 'type' => 'string', |
1419 | - 'context' => array( 'view', 'edit' ), |
|
1419 | + 'context' => array('view', 'edit'), |
|
1420 | 1420 | ), |
1421 | 1421 | 'total_tax' => array( |
1422 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
1422 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
1423 | 1423 | 'type' => 'string', |
1424 | - 'context' => array( 'view', 'edit' ), |
|
1424 | + 'context' => array('view', 'edit'), |
|
1425 | 1425 | 'readonly' => true, |
1426 | 1426 | ), |
1427 | 1427 | 'taxes' => array( |
1428 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
1428 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
1429 | 1429 | 'type' => 'array', |
1430 | - 'context' => array( 'view', 'edit' ), |
|
1430 | + 'context' => array('view', 'edit'), |
|
1431 | 1431 | 'readonly' => true, |
1432 | 1432 | 'items' => array( |
1433 | 1433 | 'type' => 'object', |
1434 | 1434 | 'properties' => array( |
1435 | 1435 | 'id' => array( |
1436 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
1436 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
1437 | 1437 | 'type' => 'integer', |
1438 | - 'context' => array( 'view', 'edit' ), |
|
1438 | + 'context' => array('view', 'edit'), |
|
1439 | 1439 | 'readonly' => true, |
1440 | 1440 | ), |
1441 | 1441 | 'total' => array( |
1442 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
1442 | + 'description' => __('Tax total.', 'woocommerce'), |
|
1443 | 1443 | 'type' => 'string', |
1444 | - 'context' => array( 'view', 'edit' ), |
|
1444 | + 'context' => array('view', 'edit'), |
|
1445 | 1445 | 'readonly' => true, |
1446 | 1446 | ), |
1447 | 1447 | ), |
@@ -1451,68 +1451,68 @@ discard block |
||
1451 | 1451 | ), |
1452 | 1452 | ), |
1453 | 1453 | 'fee_lines' => array( |
1454 | - 'description' => __( 'Fee lines data.', 'woocommerce' ), |
|
1454 | + 'description' => __('Fee lines data.', 'woocommerce'), |
|
1455 | 1455 | 'type' => 'array', |
1456 | - 'context' => array( 'view', 'edit' ), |
|
1456 | + 'context' => array('view', 'edit'), |
|
1457 | 1457 | 'items' => array( |
1458 | 1458 | 'type' => 'object', |
1459 | 1459 | 'properties' => array( |
1460 | 1460 | 'id' => array( |
1461 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
1461 | + 'description' => __('Item ID.', 'woocommerce'), |
|
1462 | 1462 | 'type' => 'integer', |
1463 | - 'context' => array( 'view', 'edit' ), |
|
1463 | + 'context' => array('view', 'edit'), |
|
1464 | 1464 | 'readonly' => true, |
1465 | 1465 | ), |
1466 | 1466 | 'name' => array( |
1467 | - 'description' => __( 'Fee name.', 'woocommerce' ), |
|
1467 | + 'description' => __('Fee name.', 'woocommerce'), |
|
1468 | 1468 | 'type' => 'mixed', |
1469 | - 'context' => array( 'view', 'edit' ), |
|
1469 | + 'context' => array('view', 'edit'), |
|
1470 | 1470 | ), |
1471 | 1471 | 'tax_class' => array( |
1472 | - 'description' => __( 'Tax class of fee.', 'woocommerce' ), |
|
1472 | + 'description' => __('Tax class of fee.', 'woocommerce'), |
|
1473 | 1473 | 'type' => 'string', |
1474 | - 'context' => array( 'view', 'edit' ), |
|
1474 | + 'context' => array('view', 'edit'), |
|
1475 | 1475 | ), |
1476 | 1476 | 'tax_status' => array( |
1477 | - 'description' => __( 'Tax status of fee.', 'woocommerce' ), |
|
1477 | + 'description' => __('Tax status of fee.', 'woocommerce'), |
|
1478 | 1478 | 'type' => 'string', |
1479 | - 'context' => array( 'view', 'edit' ), |
|
1480 | - 'enum' => array( 'taxable', 'none' ), |
|
1479 | + 'context' => array('view', 'edit'), |
|
1480 | + 'enum' => array('taxable', 'none'), |
|
1481 | 1481 | ), |
1482 | 1482 | 'total' => array( |
1483 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
1483 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
1484 | 1484 | 'type' => 'string', |
1485 | - 'context' => array( 'view', 'edit' ), |
|
1485 | + 'context' => array('view', 'edit'), |
|
1486 | 1486 | ), |
1487 | 1487 | 'total_tax' => array( |
1488 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
1488 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
1489 | 1489 | 'type' => 'string', |
1490 | - 'context' => array( 'view', 'edit' ), |
|
1490 | + 'context' => array('view', 'edit'), |
|
1491 | 1491 | ), |
1492 | 1492 | 'taxes' => array( |
1493 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
1493 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
1494 | 1494 | 'type' => 'array', |
1495 | - 'context' => array( 'view', 'edit' ), |
|
1495 | + 'context' => array('view', 'edit'), |
|
1496 | 1496 | 'readonly' => true, |
1497 | 1497 | 'items' => array( |
1498 | 1498 | 'type' => 'object', |
1499 | 1499 | 'properties' => array( |
1500 | 1500 | 'id' => array( |
1501 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
1501 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
1502 | 1502 | 'type' => 'integer', |
1503 | - 'context' => array( 'view', 'edit' ), |
|
1503 | + 'context' => array('view', 'edit'), |
|
1504 | 1504 | 'readonly' => true, |
1505 | 1505 | ), |
1506 | 1506 | 'total' => array( |
1507 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
1507 | + 'description' => __('Tax total.', 'woocommerce'), |
|
1508 | 1508 | 'type' => 'string', |
1509 | - 'context' => array( 'view', 'edit' ), |
|
1509 | + 'context' => array('view', 'edit'), |
|
1510 | 1510 | 'readonly' => true, |
1511 | 1511 | ), |
1512 | 1512 | 'subtotal' => array( |
1513 | - 'description' => __( 'Tax subtotal.', 'woocommerce' ), |
|
1513 | + 'description' => __('Tax subtotal.', 'woocommerce'), |
|
1514 | 1514 | 'type' => 'string', |
1515 | - 'context' => array( 'view', 'edit' ), |
|
1515 | + 'context' => array('view', 'edit'), |
|
1516 | 1516 | 'readonly' => true, |
1517 | 1517 | ), |
1518 | 1518 | ), |
@@ -1522,61 +1522,61 @@ discard block |
||
1522 | 1522 | ), |
1523 | 1523 | ), |
1524 | 1524 | 'coupon_lines' => array( |
1525 | - 'description' => __( 'Coupons line data.', 'woocommerce' ), |
|
1525 | + 'description' => __('Coupons line data.', 'woocommerce'), |
|
1526 | 1526 | 'type' => 'array', |
1527 | - 'context' => array( 'view', 'edit' ), |
|
1527 | + 'context' => array('view', 'edit'), |
|
1528 | 1528 | 'items' => array( |
1529 | 1529 | 'type' => 'object', |
1530 | 1530 | 'properties' => array( |
1531 | 1531 | 'id' => array( |
1532 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
1532 | + 'description' => __('Item ID.', 'woocommerce'), |
|
1533 | 1533 | 'type' => 'integer', |
1534 | - 'context' => array( 'view', 'edit' ), |
|
1534 | + 'context' => array('view', 'edit'), |
|
1535 | 1535 | 'readonly' => true, |
1536 | 1536 | ), |
1537 | 1537 | 'code' => array( |
1538 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
1538 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
1539 | 1539 | 'type' => 'mixed', |
1540 | - 'context' => array( 'view', 'edit' ), |
|
1540 | + 'context' => array('view', 'edit'), |
|
1541 | 1541 | ), |
1542 | 1542 | 'discount' => array( |
1543 | - 'description' => __( 'Discount total.', 'woocommerce' ), |
|
1543 | + 'description' => __('Discount total.', 'woocommerce'), |
|
1544 | 1544 | 'type' => 'string', |
1545 | - 'context' => array( 'view', 'edit' ), |
|
1545 | + 'context' => array('view', 'edit'), |
|
1546 | 1546 | ), |
1547 | 1547 | 'discount_tax' => array( |
1548 | - 'description' => __( 'Discount total tax.', 'woocommerce' ), |
|
1548 | + 'description' => __('Discount total tax.', 'woocommerce'), |
|
1549 | 1549 | 'type' => 'string', |
1550 | - 'context' => array( 'view', 'edit' ), |
|
1550 | + 'context' => array('view', 'edit'), |
|
1551 | 1551 | 'readonly' => true, |
1552 | 1552 | ), |
1553 | 1553 | ), |
1554 | 1554 | ), |
1555 | 1555 | ), |
1556 | 1556 | 'refunds' => array( |
1557 | - 'description' => __( 'List of refunds.', 'woocommerce' ), |
|
1557 | + 'description' => __('List of refunds.', 'woocommerce'), |
|
1558 | 1558 | 'type' => 'array', |
1559 | - 'context' => array( 'view', 'edit' ), |
|
1559 | + 'context' => array('view', 'edit'), |
|
1560 | 1560 | 'readonly' => true, |
1561 | 1561 | 'items' => array( |
1562 | 1562 | 'type' => 'object', |
1563 | 1563 | 'properties' => array( |
1564 | 1564 | 'id' => array( |
1565 | - 'description' => __( 'Refund ID.', 'woocommerce' ), |
|
1565 | + 'description' => __('Refund ID.', 'woocommerce'), |
|
1566 | 1566 | 'type' => 'integer', |
1567 | - 'context' => array( 'view', 'edit' ), |
|
1567 | + 'context' => array('view', 'edit'), |
|
1568 | 1568 | 'readonly' => true, |
1569 | 1569 | ), |
1570 | 1570 | 'reason' => array( |
1571 | - 'description' => __( 'Refund reason.', 'woocommerce' ), |
|
1571 | + 'description' => __('Refund reason.', 'woocommerce'), |
|
1572 | 1572 | 'type' => 'string', |
1573 | - 'context' => array( 'view', 'edit' ), |
|
1573 | + 'context' => array('view', 'edit'), |
|
1574 | 1574 | 'readonly' => true, |
1575 | 1575 | ), |
1576 | 1576 | 'total' => array( |
1577 | - 'description' => __( 'Refund total.', 'woocommerce' ), |
|
1577 | + 'description' => __('Refund total.', 'woocommerce'), |
|
1578 | 1578 | 'type' => 'string', |
1579 | - 'context' => array( 'view', 'edit' ), |
|
1579 | + 'context' => array('view', 'edit'), |
|
1580 | 1580 | 'readonly' => true, |
1581 | 1581 | ), |
1582 | 1582 | ), |
@@ -1585,7 +1585,7 @@ discard block |
||
1585 | 1585 | ), |
1586 | 1586 | ); |
1587 | 1587 | |
1588 | - return $this->add_additional_fields_schema( $schema ); |
|
1588 | + return $this->add_additional_fields_schema($schema); |
|
1589 | 1589 | } |
1590 | 1590 | |
1591 | 1591 | /** |
@@ -1598,27 +1598,27 @@ discard block |
||
1598 | 1598 | |
1599 | 1599 | $params['status'] = array( |
1600 | 1600 | 'default' => 'any', |
1601 | - 'description' => __( 'Limit result set to orders assigned a specific status.', 'woocommerce' ), |
|
1601 | + 'description' => __('Limit result set to orders assigned a specific status.', 'woocommerce'), |
|
1602 | 1602 | 'type' => 'string', |
1603 | - 'enum' => array_merge( array( 'any' ), $this->get_order_statuses() ), |
|
1603 | + 'enum' => array_merge(array('any'), $this->get_order_statuses()), |
|
1604 | 1604 | 'sanitize_callback' => 'sanitize_key', |
1605 | 1605 | 'validate_callback' => 'rest_validate_request_arg', |
1606 | 1606 | ); |
1607 | 1607 | $params['customer'] = array( |
1608 | - 'description' => __( 'Limit result set to orders assigned a specific customer.', 'woocommerce' ), |
|
1608 | + 'description' => __('Limit result set to orders assigned a specific customer.', 'woocommerce'), |
|
1609 | 1609 | 'type' => 'integer', |
1610 | 1610 | 'sanitize_callback' => 'absint', |
1611 | 1611 | 'validate_callback' => 'rest_validate_request_arg', |
1612 | 1612 | ); |
1613 | 1613 | $params['product'] = array( |
1614 | - 'description' => __( 'Limit result set to orders assigned a specific product.', 'woocommerce' ), |
|
1614 | + 'description' => __('Limit result set to orders assigned a specific product.', 'woocommerce'), |
|
1615 | 1615 | 'type' => 'integer', |
1616 | 1616 | 'sanitize_callback' => 'absint', |
1617 | 1617 | 'validate_callback' => 'rest_validate_request_arg', |
1618 | 1618 | ); |
1619 | 1619 | $params['dp'] = array( |
1620 | 1620 | 'default' => wc_get_price_decimals(), |
1621 | - 'description' => __( 'Number of decimal points to use in each resource.', 'woocommerce' ), |
|
1621 | + 'description' => __('Number of decimal points to use in each resource.', 'woocommerce'), |
|
1622 | 1622 | 'type' => 'integer', |
1623 | 1623 | 'sanitize_callback' => 'absint', |
1624 | 1624 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -47,67 +47,67 @@ discard block |
||
47 | 47 | * Register the routes for order notes. |
48 | 48 | */ |
49 | 49 | public function register_routes() { |
50 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
50 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
51 | 51 | 'args' => array( |
52 | 52 | 'order_id' => array( |
53 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
53 | + 'description' => __('The order ID.', 'woocommerce'), |
|
54 | 54 | 'type' => 'integer', |
55 | 55 | ), |
56 | 56 | ), |
57 | 57 | array( |
58 | 58 | 'methods' => WP_REST_Server::READABLE, |
59 | - 'callback' => array( $this, 'get_items' ), |
|
60 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
59 | + 'callback' => array($this, 'get_items'), |
|
60 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
61 | 61 | 'args' => $this->get_collection_params(), |
62 | 62 | ), |
63 | 63 | array( |
64 | 64 | 'methods' => WP_REST_Server::CREATABLE, |
65 | - 'callback' => array( $this, 'create_item' ), |
|
66 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
67 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
65 | + 'callback' => array($this, 'create_item'), |
|
66 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
67 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
68 | 68 | 'note' => array( |
69 | 69 | 'type' => 'string', |
70 | - 'description' => __( 'Order note content.', 'woocommerce' ), |
|
70 | + 'description' => __('Order note content.', 'woocommerce'), |
|
71 | 71 | 'required' => true, |
72 | 72 | ), |
73 | - ) ), |
|
73 | + )), |
|
74 | 74 | ), |
75 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
76 | - ) ); |
|
75 | + 'schema' => array($this, 'get_public_item_schema'), |
|
76 | + )); |
|
77 | 77 | |
78 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
78 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
79 | 79 | 'args' => 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 | 83 | ), |
84 | 84 | 'order_id' => array( |
85 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
85 | + 'description' => __('The order ID.', 'woocommerce'), |
|
86 | 86 | 'type' => 'integer', |
87 | 87 | ), |
88 | 88 | ), |
89 | 89 | array( |
90 | 90 | 'methods' => WP_REST_Server::READABLE, |
91 | - 'callback' => array( $this, 'get_item' ), |
|
92 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
91 | + 'callback' => array($this, 'get_item'), |
|
92 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
93 | 93 | 'args' => array( |
94 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
94 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
95 | 95 | ), |
96 | 96 | ), |
97 | 97 | array( |
98 | 98 | 'methods' => WP_REST_Server::DELETABLE, |
99 | - 'callback' => array( $this, 'delete_item' ), |
|
100 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
99 | + 'callback' => array($this, 'delete_item'), |
|
100 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
101 | 101 | 'args' => array( |
102 | 102 | 'force' => array( |
103 | 103 | 'default' => false, |
104 | 104 | 'type' => 'boolean', |
105 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
105 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
106 | 106 | ), |
107 | 107 | ), |
108 | 108 | ), |
109 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
110 | - ) ); |
|
109 | + 'schema' => array($this, 'get_public_item_schema'), |
|
110 | + )); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -116,9 +116,9 @@ discard block |
||
116 | 116 | * @param WP_REST_Request $request Full details about the request. |
117 | 117 | * @return WP_Error|boolean |
118 | 118 | */ |
119 | - public function get_items_permissions_check( $request ) { |
|
120 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) { |
|
121 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
119 | + public function get_items_permissions_check($request) { |
|
120 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) { |
|
121 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | return true; |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return bool|WP_Error |
133 | 133 | */ |
134 | - public function create_item_permissions_check( $request ) { |
|
135 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) { |
|
136 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
134 | + public function create_item_permissions_check($request) { |
|
135 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) { |
|
136 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return true; |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | * @param WP_REST_Request $request Full details about the request. |
146 | 146 | * @return WP_Error|boolean |
147 | 147 | */ |
148 | - public function get_item_permissions_check( $request ) { |
|
149 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
148 | + public function get_item_permissions_check($request) { |
|
149 | + $order = wc_get_order((int) $request['order_id']); |
|
150 | 150 | |
151 | - if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'read', $order->get_id() ) ) { |
|
152 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
151 | + if ($order && ! wc_rest_check_post_permissions($this->post_type, 'read', $order->get_id())) { |
|
152 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | return true; |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | * |
163 | 163 | * @return bool|WP_Error |
164 | 164 | */ |
165 | - public function delete_item_permissions_check( $request ) { |
|
166 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
165 | + public function delete_item_permissions_check($request) { |
|
166 | + $order = wc_get_order((int) $request['order_id']); |
|
167 | 167 | |
168 | - if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $order->get_id() ) ) { |
|
169 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
168 | + if ($order && ! wc_rest_check_post_permissions($this->post_type, 'delete', $order->get_id())) { |
|
169 | + return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | return true; |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return array|WP_Error |
181 | 181 | */ |
182 | - public function get_items( $request ) { |
|
183 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
182 | + public function get_items($request) { |
|
183 | + $order = wc_get_order((int) $request['order_id']); |
|
184 | 184 | |
185 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
186 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
185 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
186 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | $args = array( |
@@ -192,20 +192,20 @@ discard block |
||
192 | 192 | 'type' => 'order_note', |
193 | 193 | ); |
194 | 194 | |
195 | - remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); |
|
195 | + remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1); |
|
196 | 196 | |
197 | - $notes = get_comments( $args ); |
|
197 | + $notes = get_comments($args); |
|
198 | 198 | |
199 | - add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); |
|
199 | + add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1); |
|
200 | 200 | |
201 | 201 | $data = array(); |
202 | - foreach ( $notes as $note ) { |
|
203 | - $order_note = $this->prepare_item_for_response( $note, $request ); |
|
204 | - $order_note = $this->prepare_response_for_collection( $order_note ); |
|
202 | + foreach ($notes as $note) { |
|
203 | + $order_note = $this->prepare_item_for_response($note, $request); |
|
204 | + $order_note = $this->prepare_response_for_collection($order_note); |
|
205 | 205 | $data[] = $order_note; |
206 | 206 | } |
207 | 207 | |
208 | - return rest_ensure_response( $data ); |
|
208 | + return rest_ensure_response($data); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -214,27 +214,27 @@ discard block |
||
214 | 214 | * @param WP_REST_Request $request Full details about the request. |
215 | 215 | * @return WP_Error|WP_REST_Response |
216 | 216 | */ |
217 | - public function create_item( $request ) { |
|
218 | - if ( ! empty( $request['id'] ) ) { |
|
217 | + public function create_item($request) { |
|
218 | + if ( ! empty($request['id'])) { |
|
219 | 219 | /* translators: %s: post type */ |
220 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
220 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
221 | 221 | } |
222 | 222 | |
223 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
223 | + $order = wc_get_order((int) $request['order_id']); |
|
224 | 224 | |
225 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
226 | - return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
225 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
226 | + return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | // Create the note. |
230 | - $note_id = $order->add_order_note( $request['note'], $request['customer_note'] ); |
|
230 | + $note_id = $order->add_order_note($request['note'], $request['customer_note']); |
|
231 | 231 | |
232 | - if ( ! $note_id ) { |
|
233 | - return new WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
232 | + if ( ! $note_id) { |
|
233 | + return new WP_Error('woocommerce_api_cannot_create_order_note', __('Cannot create order note, please try again.', 'woocommerce'), array('status' => 500)); |
|
234 | 234 | } |
235 | 235 | |
236 | - $note = get_comment( $note_id ); |
|
237 | - $this->update_additional_fields_for_object( $note, $request ); |
|
236 | + $note = get_comment($note_id); |
|
237 | + $this->update_additional_fields_for_object($note, $request); |
|
238 | 238 | |
239 | 239 | /** |
240 | 240 | * Fires after a order note is created or updated via the REST API. |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | * @param WP_REST_Request $request Request object. |
244 | 244 | * @param boolean $creating True when creating item, false when updating. |
245 | 245 | */ |
246 | - do_action( 'woocommerce_rest_insert_order_note', $note, $request, true ); |
|
246 | + do_action('woocommerce_rest_insert_order_note', $note, $request, true); |
|
247 | 247 | |
248 | - $request->set_param( 'context', 'edit' ); |
|
249 | - $response = $this->prepare_item_for_response( $note, $request ); |
|
250 | - $response = rest_ensure_response( $response ); |
|
251 | - $response->set_status( 201 ); |
|
252 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, str_replace( '(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base ), $note_id ) ) ); |
|
248 | + $request->set_param('context', 'edit'); |
|
249 | + $response = $this->prepare_item_for_response($note, $request); |
|
250 | + $response = rest_ensure_response($response); |
|
251 | + $response->set_status(201); |
|
252 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, str_replace('(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base), $note_id))); |
|
253 | 253 | |
254 | 254 | return $response; |
255 | 255 | } |
@@ -260,22 +260,22 @@ discard block |
||
260 | 260 | * @param WP_REST_Request $request Full details about the request. |
261 | 261 | * @return WP_Error|WP_REST_Response |
262 | 262 | */ |
263 | - public function get_item( $request ) { |
|
263 | + public function get_item($request) { |
|
264 | 264 | $id = (int) $request['id']; |
265 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
265 | + $order = wc_get_order((int) $request['order_id']); |
|
266 | 266 | |
267 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
268 | - return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
267 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
268 | + return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
269 | 269 | } |
270 | 270 | |
271 | - $note = get_comment( $id ); |
|
271 | + $note = get_comment($id); |
|
272 | 272 | |
273 | - if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { |
|
274 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
273 | + if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) { |
|
274 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
275 | 275 | } |
276 | 276 | |
277 | - $order_note = $this->prepare_item_for_response( $note, $request ); |
|
278 | - $response = rest_ensure_response( $order_note ); |
|
277 | + $order_note = $this->prepare_item_for_response($note, $request); |
|
278 | + $response = rest_ensure_response($order_note); |
|
279 | 279 | |
280 | 280 | return $response; |
281 | 281 | } |
@@ -286,34 +286,34 @@ discard block |
||
286 | 286 | * @param WP_REST_Request $request Full details about the request. |
287 | 287 | * @return WP_REST_Response|WP_Error |
288 | 288 | */ |
289 | - public function delete_item( $request ) { |
|
289 | + public function delete_item($request) { |
|
290 | 290 | $id = (int) $request['id']; |
291 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
291 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
292 | 292 | |
293 | 293 | // We don't support trashing for this type, error out. |
294 | - if ( ! $force ) { |
|
295 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
294 | + if ( ! $force) { |
|
295 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
296 | 296 | } |
297 | 297 | |
298 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
298 | + $order = wc_get_order((int) $request['order_id']); |
|
299 | 299 | |
300 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
301 | - return new WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
300 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
301 | + return new WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
302 | 302 | } |
303 | 303 | |
304 | - $note = get_comment( $id ); |
|
304 | + $note = get_comment($id); |
|
305 | 305 | |
306 | - if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { |
|
307 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
306 | + if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) { |
|
307 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
308 | 308 | } |
309 | 309 | |
310 | - $request->set_param( 'context', 'edit' ); |
|
311 | - $response = $this->prepare_item_for_response( $note, $request ); |
|
310 | + $request->set_param('context', 'edit'); |
|
311 | + $response = $this->prepare_item_for_response($note, $request); |
|
312 | 312 | |
313 | - $result = wc_delete_order_note( $note->comment_ID ); |
|
313 | + $result = wc_delete_order_note($note->comment_ID); |
|
314 | 314 | |
315 | - if ( ! $result ) { |
|
316 | - return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), 'order_note' ), array( 'status' => 500 ) ); |
|
315 | + if ( ! $result) { |
|
316 | + return new WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), 'order_note'), array('status' => 500)); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | * @param WP_REST_Response $response The response data. |
324 | 324 | * @param WP_REST_Request $request The request sent to the API. |
325 | 325 | */ |
326 | - do_action( 'woocommerce_rest_delete_order_note', $note, $response, $request ); |
|
326 | + do_action('woocommerce_rest_delete_order_note', $note, $response, $request); |
|
327 | 327 | |
328 | 328 | return $response; |
329 | 329 | } |
@@ -335,22 +335,22 @@ discard block |
||
335 | 335 | * @param WP_REST_Request $request Request object. |
336 | 336 | * @return WP_REST_Response $response Response data. |
337 | 337 | */ |
338 | - public function prepare_item_for_response( $note, $request ) { |
|
338 | + public function prepare_item_for_response($note, $request) { |
|
339 | 339 | $data = array( |
340 | 340 | 'id' => (int) $note->comment_ID, |
341 | - 'date_created' => wc_rest_prepare_date_response( $note->comment_date_gmt ), |
|
341 | + 'date_created' => wc_rest_prepare_date_response($note->comment_date_gmt), |
|
342 | 342 | 'note' => $note->comment_content, |
343 | - 'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ), |
|
343 | + 'customer_note' => (bool) get_comment_meta($note->comment_ID, 'is_customer_note', true), |
|
344 | 344 | ); |
345 | 345 | |
346 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
347 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
348 | - $data = $this->filter_response_by_context( $data, $context ); |
|
346 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
347 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
348 | + $data = $this->filter_response_by_context($data, $context); |
|
349 | 349 | |
350 | 350 | // Wrap the data in a response object. |
351 | - $response = rest_ensure_response( $data ); |
|
351 | + $response = rest_ensure_response($data); |
|
352 | 352 | |
353 | - $response->add_links( $this->prepare_links( $note ) ); |
|
353 | + $response->add_links($this->prepare_links($note)); |
|
354 | 354 | |
355 | 355 | /** |
356 | 356 | * Filter order note object returned from the REST API. |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @param WP_Comment $note Order note object used to create response. |
360 | 360 | * @param WP_REST_Request $request Request object. |
361 | 361 | */ |
362 | - return apply_filters( 'woocommerce_rest_prepare_order_note', $response, $note, $request ); |
|
362 | + return apply_filters('woocommerce_rest_prepare_order_note', $response, $note, $request); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -368,18 +368,18 @@ discard block |
||
368 | 368 | * @param WP_Comment $note Delivery order_note object. |
369 | 369 | * @return array Links for the given order note. |
370 | 370 | */ |
371 | - protected function prepare_links( $note ) { |
|
371 | + protected function prepare_links($note) { |
|
372 | 372 | $order_id = (int) $note->comment_post_ID; |
373 | - $base = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base ); |
|
373 | + $base = str_replace('(?P<order_id>[\d]+)', $order_id, $this->rest_base); |
|
374 | 374 | $links = array( |
375 | 375 | 'self' => array( |
376 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $note->comment_ID ) ), |
|
376 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $note->comment_ID)), |
|
377 | 377 | ), |
378 | 378 | 'collection' => array( |
379 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
379 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
380 | 380 | ), |
381 | 381 | 'up' => array( |
382 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ), |
|
382 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order_id)), |
|
383 | 383 | ), |
384 | 384 | ); |
385 | 385 | |
@@ -398,32 +398,32 @@ discard block |
||
398 | 398 | 'type' => 'object', |
399 | 399 | 'properties' => array( |
400 | 400 | 'id' => array( |
401 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
401 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
402 | 402 | 'type' => 'integer', |
403 | - 'context' => array( 'view', 'edit' ), |
|
403 | + 'context' => array('view', 'edit'), |
|
404 | 404 | 'readonly' => true, |
405 | 405 | ), |
406 | 406 | 'date_created' => array( |
407 | - 'description' => __( "The date the order note was created, in the site's timezone.", 'woocommerce' ), |
|
407 | + 'description' => __("The date the order note was created, in the site's timezone.", 'woocommerce'), |
|
408 | 408 | 'type' => 'date-time', |
409 | - 'context' => array( 'view', 'edit' ), |
|
409 | + 'context' => array('view', 'edit'), |
|
410 | 410 | 'readonly' => true, |
411 | 411 | ), |
412 | 412 | 'note' => array( |
413 | - 'description' => __( 'Order note.', 'woocommerce' ), |
|
413 | + 'description' => __('Order note.', 'woocommerce'), |
|
414 | 414 | 'type' => 'string', |
415 | - 'context' => array( 'view', 'edit' ), |
|
415 | + 'context' => array('view', 'edit'), |
|
416 | 416 | ), |
417 | 417 | 'customer_note' => array( |
418 | - 'description' => __( 'Shows/define if the note is only for reference or for the customer (the user will be notified).', 'woocommerce' ), |
|
418 | + 'description' => __('Shows/define if the note is only for reference or for the customer (the user will be notified).', 'woocommerce'), |
|
419 | 419 | 'type' => 'boolean', |
420 | 420 | 'default' => false, |
421 | - 'context' => array( 'view', 'edit' ), |
|
421 | + 'context' => array('view', 'edit'), |
|
422 | 422 | ), |
423 | 423 | ), |
424 | 424 | ); |
425 | 425 | |
426 | - return $this->add_additional_fields_schema( $schema ); |
|
426 | + return $this->add_additional_fields_schema($schema); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | */ |
434 | 434 | public function get_collection_params() { |
435 | 435 | return array( |
436 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
436 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
437 | 437 | ); |
438 | 438 | } |
439 | 439 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @package WooCommerce/RestApi |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | array( |
37 | 37 | array( |
38 | 38 | 'methods' => WP_REST_Server::READABLE, |
39 | - 'callback' => array( $this, 'get_items' ), |
|
40 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
39 | + 'callback' => array($this, 'get_items'), |
|
40 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
41 | 41 | 'args' => $this->get_collection_params(), |
42 | 42 | ), |
43 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
43 | + 'schema' => array($this, 'get_public_item_schema'), |
|
44 | 44 | ) |
45 | 45 | ); |
46 | 46 | |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | array( |
51 | 51 | 'args' => array( |
52 | 52 | 'id' => array( |
53 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
53 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
54 | 54 | 'type' => 'integer', |
55 | 55 | ), |
56 | 56 | ), |
57 | 57 | array( |
58 | 58 | 'methods' => WP_REST_Server::READABLE, |
59 | - 'callback' => array( $this, 'get_item' ), |
|
60 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
59 | + 'callback' => array($this, 'get_item'), |
|
60 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
61 | 61 | 'args' => array( |
62 | 62 | 'context' => $this->get_context_param( |
63 | 63 | array( |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | ), |
67 | 67 | ), |
68 | 68 | ), |
69 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
69 | + 'schema' => array($this, 'get_public_item_schema'), |
|
70 | 70 | ) |
71 | 71 | ); |
72 | 72 | } |
@@ -78,24 +78,24 @@ discard block |
||
78 | 78 | * @param string $context Request context. |
79 | 79 | * @return bool|WP_Error |
80 | 80 | */ |
81 | - protected function check_permissions( $request, $context = 'read' ) { |
|
81 | + protected function check_permissions($request, $context = 'read') { |
|
82 | 82 | // Get taxonomy. |
83 | - $taxonomy = $this->get_taxonomy( $request ); |
|
84 | - if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) { |
|
85 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
83 | + $taxonomy = $this->get_taxonomy($request); |
|
84 | + if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) { |
|
85 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Taxonomy does not exist.', 'woocommerce'), array('status' => 404)); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Check permissions for a single term. |
89 | - $id = intval( $request['id'] ); |
|
90 | - if ( $id ) { |
|
91 | - $term = get_term( $id, $taxonomy ); |
|
89 | + $id = intval($request['id']); |
|
90 | + if ($id) { |
|
91 | + $term = get_term($id, $taxonomy); |
|
92 | 92 | |
93 | - if ( is_wp_error( $term ) || ! $term || $term->taxonomy !== $taxonomy ) { |
|
94 | - return new WP_Error( 'woocommerce_rest_term_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
93 | + if (is_wp_error($term) || ! $term || $term->taxonomy !== $taxonomy) { |
|
94 | + return new WP_Error('woocommerce_rest_term_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | - return current_user_can( 'edit_posts' ); |
|
98 | + return current_user_can('edit_posts'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @param WP_REST_Request $request Request instance. |
106 | 106 | * @return WP_REST_Response |
107 | 107 | */ |
108 | - public function prepare_item_for_response( $item, $request ) { |
|
108 | + public function prepare_item_for_response($item, $request) { |
|
109 | 109 | $data = array( |
110 | 110 | 'id' => (int) $item->term_id, |
111 | 111 | 'name' => $item->name, |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | 'count' => (int) $item->count, |
115 | 115 | ); |
116 | 116 | |
117 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
118 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
119 | - $data = $this->filter_response_by_context( $data, $context ); |
|
117 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
118 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
119 | + $data = $this->filter_response_by_context($data, $context); |
|
120 | 120 | |
121 | - $response = rest_ensure_response( $data ); |
|
121 | + $response = rest_ensure_response($data); |
|
122 | 122 | |
123 | - $response->header( 'X-Woo-Notice', __( 'Private REST API for use by block editor only.', 'woocommerce' ) ); |
|
124 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
123 | + $response->header('X-Woo-Notice', __('Private REST API for use by block editor only.', 'woocommerce')); |
|
124 | + $response->add_links($this->prepare_links($item, $request)); |
|
125 | 125 | |
126 | 126 | return $response; |
127 | 127 | } |
@@ -146,6 +146,6 @@ discard block |
||
146 | 146 | $schema['properties']['parent'] = $raw_schema['properties']['parent']; |
147 | 147 | $schema['properties']['count'] = $raw_schema['properties']['count']; |
148 | 148 | |
149 | - return $this->add_additional_fields_schema( $schema ); |
|
149 | + return $this->add_additional_fields_schema($schema); |
|
150 | 150 | } |
151 | 151 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @package WooCommerce/RestApi |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | array( |
37 | 37 | array( |
38 | 38 | 'methods' => WP_REST_Server::READABLE, |
39 | - 'callback' => array( $this, 'get_items' ), |
|
40 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
39 | + 'callback' => array($this, 'get_items'), |
|
40 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
41 | 41 | 'args' => $this->get_collection_params(), |
42 | 42 | ), |
43 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
43 | + 'schema' => array($this, 'get_public_item_schema'), |
|
44 | 44 | ) |
45 | 45 | ); |
46 | 46 | |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | array( |
51 | 51 | 'args' => array( |
52 | 52 | 'id' => array( |
53 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
53 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
54 | 54 | 'type' => 'integer', |
55 | 55 | ), |
56 | 56 | ), |
57 | 57 | array( |
58 | 58 | 'methods' => WP_REST_Server::READABLE, |
59 | - 'callback' => array( $this, 'get_item' ), |
|
60 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
59 | + 'callback' => array($this, 'get_item'), |
|
60 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
61 | 61 | 'args' => array( |
62 | 62 | 'context' => $this->get_context_param( |
63 | 63 | array( |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | ), |
67 | 67 | ), |
68 | 68 | ), |
69 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
69 | + 'schema' => array($this, 'get_public_item_schema'), |
|
70 | 70 | ) |
71 | 71 | ); |
72 | 72 | } |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * @param WP_REST_Request $request Full details about the request. |
78 | 78 | * @return WP_Error|boolean |
79 | 79 | */ |
80 | - public function get_items_permissions_check( $request ) { |
|
81 | - if ( ! current_user_can( 'edit_posts' ) ) { |
|
82 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
80 | + public function get_items_permissions_check($request) { |
|
81 | + if ( ! current_user_can('edit_posts')) { |
|
82 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | return true; |
@@ -90,15 +90,15 @@ discard block |
||
90 | 90 | * @param WP_REST_Request $request Full details about the request. |
91 | 91 | * @return WP_Error|boolean |
92 | 92 | */ |
93 | - public function get_item_permissions_check( $request ) { |
|
94 | - $taxonomy = $this->get_taxonomy( $request ); |
|
93 | + public function get_item_permissions_check($request) { |
|
94 | + $taxonomy = $this->get_taxonomy($request); |
|
95 | 95 | |
96 | - if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) { |
|
97 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
96 | + if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) { |
|
97 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
98 | 98 | } |
99 | 99 | |
100 | - if ( ! current_user_can( 'edit_posts' ) ) { |
|
101 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
100 | + if ( ! current_user_can('edit_posts')) { |
|
101 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return true; |
@@ -111,24 +111,24 @@ discard block |
||
111 | 111 | * @param string $context Request context. |
112 | 112 | * @return bool|WP_Error |
113 | 113 | */ |
114 | - protected function check_permissions( $request, $context = 'read' ) { |
|
114 | + protected function check_permissions($request, $context = 'read') { |
|
115 | 115 | // Get taxonomy. |
116 | - $taxonomy = $this->get_taxonomy( $request ); |
|
117 | - if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) { |
|
118 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
116 | + $taxonomy = $this->get_taxonomy($request); |
|
117 | + if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) { |
|
118 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Taxonomy does not exist.', 'woocommerce'), array('status' => 404)); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | // Check permissions for a single term. |
122 | - $id = intval( $request['id'] ); |
|
123 | - if ( $id ) { |
|
124 | - $term = get_term( $id, $taxonomy ); |
|
122 | + $id = intval($request['id']); |
|
123 | + if ($id) { |
|
124 | + $term = get_term($id, $taxonomy); |
|
125 | 125 | |
126 | - if ( is_wp_error( $term ) || ! $term || $term->taxonomy !== $taxonomy ) { |
|
127 | - return new WP_Error( 'woocommerce_rest_term_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
126 | + if (is_wp_error($term) || ! $term || $term->taxonomy !== $taxonomy) { |
|
127 | + return new WP_Error('woocommerce_rest_term_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
131 | - return current_user_can( 'edit_posts' ); |
|
131 | + return current_user_can('edit_posts'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,23 +138,23 @@ discard block |
||
138 | 138 | * @param WP_REST_Request $request Request instance. |
139 | 139 | * @return WP_REST_Response |
140 | 140 | */ |
141 | - public function prepare_item_for_response( $item, $request ) { |
|
142 | - $taxonomy = wc_attribute_taxonomy_name( $item->attribute_name ); |
|
141 | + public function prepare_item_for_response($item, $request) { |
|
142 | + $taxonomy = wc_attribute_taxonomy_name($item->attribute_name); |
|
143 | 143 | $data = array( |
144 | 144 | 'id' => (int) $item->attribute_id, |
145 | 145 | 'name' => $item->attribute_label, |
146 | 146 | 'slug' => $taxonomy, |
147 | - 'count' => wp_count_terms( $taxonomy ), |
|
147 | + 'count' => wp_count_terms($taxonomy), |
|
148 | 148 | ); |
149 | 149 | |
150 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
151 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
152 | - $data = $this->filter_response_by_context( $data, $context ); |
|
150 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
151 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
152 | + $data = $this->filter_response_by_context($data, $context); |
|
153 | 153 | |
154 | - $response = rest_ensure_response( $data ); |
|
154 | + $response = rest_ensure_response($data); |
|
155 | 155 | |
156 | - $response->header( 'X-Woo-Notice', __( 'Private REST API for use by block editor only.', 'woocommerce' ) ); |
|
157 | - $response->add_links( $this->prepare_links( $item ) ); |
|
156 | + $response->header('X-Woo-Notice', __('Private REST API for use by block editor only.', 'woocommerce')); |
|
157 | + $response->add_links($this->prepare_links($item)); |
|
158 | 158 | |
159 | 159 | return $response; |
160 | 160 | } |
@@ -177,12 +177,12 @@ discard block |
||
177 | 177 | $schema['properties']['name'] = $raw_schema['properties']['name']; |
178 | 178 | $schema['properties']['slug'] = $raw_schema['properties']['slug']; |
179 | 179 | $schema['properties']['count'] = array( |
180 | - 'description' => __( 'Number of terms in the attribute taxonomy.', 'woocommerce' ), |
|
180 | + 'description' => __('Number of terms in the attribute taxonomy.', 'woocommerce'), |
|
181 | 181 | 'type' => 'integer', |
182 | - 'context' => array( 'view', 'edit' ), |
|
182 | + 'context' => array('view', 'edit'), |
|
183 | 183 | 'readonly' => true, |
184 | 184 | ); |
185 | 185 | |
186 | - return $this->add_additional_fields_schema( $schema ); |
|
186 | + return $this->add_additional_fields_schema($schema); |
|
187 | 187 | } |
188 | 188 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @package WooCommerce/RestApi |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | array( |
37 | 37 | array( |
38 | 38 | 'methods' => WP_REST_Server::READABLE, |
39 | - 'callback' => array( $this, 'get_items' ), |
|
40 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
39 | + 'callback' => array($this, 'get_items'), |
|
40 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
41 | 41 | 'args' => $this->get_collection_params(), |
42 | 42 | ), |
43 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
43 | + 'schema' => array($this, 'get_public_item_schema'), |
|
44 | 44 | ) |
45 | 45 | ); |
46 | 46 | |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | array( |
51 | 51 | 'args' => array( |
52 | 52 | 'id' => array( |
53 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
53 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
54 | 54 | 'type' => 'integer', |
55 | 55 | ), |
56 | 56 | ), |
57 | 57 | array( |
58 | 58 | 'methods' => WP_REST_Server::READABLE, |
59 | - 'callback' => array( $this, 'get_item' ), |
|
60 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
59 | + 'callback' => array($this, 'get_item'), |
|
60 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
61 | 61 | 'args' => array( |
62 | 62 | 'context' => $this->get_context_param( |
63 | 63 | array( |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | ), |
67 | 67 | ), |
68 | 68 | ), |
69 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
69 | + 'schema' => array($this, 'get_public_item_schema'), |
|
70 | 70 | ) |
71 | 71 | ); |
72 | 72 | } |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * @param WP_REST_Request $request Full details about the request. |
78 | 78 | * @return WP_Error|boolean |
79 | 79 | */ |
80 | - public function get_items_permissions_check( $request ) { |
|
81 | - if ( ! current_user_can( 'edit_posts' ) ) { |
|
82 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
80 | + public function get_items_permissions_check($request) { |
|
81 | + if ( ! current_user_can('edit_posts')) { |
|
82 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | return true; |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | * @param WP_REST_Request $request Full details about the request. |
92 | 92 | * @return WP_Error|boolean |
93 | 93 | */ |
94 | - public function get_item_permissions_check( $request ) { |
|
95 | - if ( ! current_user_can( 'edit_posts' ) ) { |
|
96 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
94 | + public function get_item_permissions_check($request) { |
|
95 | + if ( ! current_user_can('edit_posts')) { |
|
96 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | return true; |
@@ -105,52 +105,52 @@ discard block |
||
105 | 105 | * @param WP_REST_Request $request Full details about the request. |
106 | 106 | * @return WP_Error|WP_REST_Response |
107 | 107 | */ |
108 | - public function get_items( $request ) { |
|
109 | - $query_args = $this->prepare_objects_query( $request ); |
|
110 | - $query_results = $this->get_objects( $query_args ); |
|
108 | + public function get_items($request) { |
|
109 | + $query_args = $this->prepare_objects_query($request); |
|
110 | + $query_results = $this->get_objects($query_args); |
|
111 | 111 | |
112 | 112 | $objects = array(); |
113 | - foreach ( $query_results['objects'] as $object ) { |
|
114 | - $data = $this->prepare_object_for_response( $object, $request ); |
|
115 | - $objects[] = $this->prepare_response_for_collection( $data ); |
|
113 | + foreach ($query_results['objects'] as $object) { |
|
114 | + $data = $this->prepare_object_for_response($object, $request); |
|
115 | + $objects[] = $this->prepare_response_for_collection($data); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $page = (int) $query_args['paged']; |
119 | 119 | $max_pages = $query_results['pages']; |
120 | 120 | |
121 | - $response = rest_ensure_response( $objects ); |
|
122 | - $response->header( 'X-WP-Total', $query_results['total'] ); |
|
123 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
124 | - $response->header( 'X-Woo-Notice', __( 'Private REST API for use by block editor only.', 'woocommerce' ) ); |
|
121 | + $response = rest_ensure_response($objects); |
|
122 | + $response->header('X-WP-Total', $query_results['total']); |
|
123 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
124 | + $response->header('X-Woo-Notice', __('Private REST API for use by block editor only.', 'woocommerce')); |
|
125 | 125 | |
126 | 126 | $base = $this->rest_base; |
127 | 127 | $attrib_prefix = '(?P<'; |
128 | - if ( strpos( $base, $attrib_prefix ) !== false ) { |
|
128 | + if (strpos($base, $attrib_prefix) !== false) { |
|
129 | 129 | $attrib_names = array(); |
130 | - preg_match( '/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE ); |
|
131 | - foreach ( $attrib_names as $attrib_name_match ) { |
|
132 | - $beginning_offset = strlen( $attrib_prefix ); |
|
133 | - $attrib_name_end = strpos( $attrib_name_match[0], '>', $attrib_name_match[1] ); |
|
134 | - $attrib_name = substr( $attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset ); |
|
135 | - if ( isset( $request[ $attrib_name ] ) ) { |
|
136 | - $base = str_replace( "(?P<$attrib_name>[\d]+)", $request[ $attrib_name ], $base ); |
|
130 | + preg_match('/\(\?P<[^>]+>.*\)/', $base, $attrib_names, PREG_OFFSET_CAPTURE); |
|
131 | + foreach ($attrib_names as $attrib_name_match) { |
|
132 | + $beginning_offset = strlen($attrib_prefix); |
|
133 | + $attrib_name_end = strpos($attrib_name_match[0], '>', $attrib_name_match[1]); |
|
134 | + $attrib_name = substr($attrib_name_match[0], $beginning_offset, $attrib_name_end - $beginning_offset); |
|
135 | + if (isset($request[$attrib_name])) { |
|
136 | + $base = str_replace("(?P<$attrib_name>[\d]+)", $request[$attrib_name], $base); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | } |
140 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ) ); |
|
140 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $base))); |
|
141 | 141 | |
142 | - if ( $page > 1 ) { |
|
142 | + if ($page > 1) { |
|
143 | 143 | $prev_page = $page - 1; |
144 | - if ( $prev_page > $max_pages ) { |
|
144 | + if ($prev_page > $max_pages) { |
|
145 | 145 | $prev_page = $max_pages; |
146 | 146 | } |
147 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
148 | - $response->link_header( 'prev', $prev_link ); |
|
147 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
148 | + $response->link_header('prev', $prev_link); |
|
149 | 149 | } |
150 | - if ( $max_pages > $page ) { |
|
150 | + if ($max_pages > $page) { |
|
151 | 151 | $next_page = $page + 1; |
152 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
153 | - $response->link_header( 'next', $next_link ); |
|
152 | + $next_link = add_query_arg('page', $next_page, $base); |
|
153 | + $response->link_header('next', $next_link); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | return $response; |
@@ -162,35 +162,35 @@ discard block |
||
162 | 162 | * @param WC_Product|WC_Product_Variation $product Product instance. |
163 | 163 | * @return array |
164 | 164 | */ |
165 | - protected function get_images( $product ) { |
|
165 | + protected function get_images($product) { |
|
166 | 166 | $images = array(); |
167 | 167 | $attachment_ids = array(); |
168 | 168 | |
169 | 169 | // Add featured image. |
170 | - if ( has_post_thumbnail( $product->get_id() ) ) { |
|
170 | + if (has_post_thumbnail($product->get_id())) { |
|
171 | 171 | $attachment_ids[] = $product->get_image_id(); |
172 | 172 | } |
173 | 173 | |
174 | 174 | // Add gallery images. |
175 | - $attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() ); |
|
175 | + $attachment_ids = array_merge($attachment_ids, $product->get_gallery_image_ids()); |
|
176 | 176 | |
177 | 177 | // Build image data. |
178 | - foreach ( $attachment_ids as $attachment_id ) { |
|
179 | - $attachment_post = get_post( $attachment_id ); |
|
180 | - if ( is_null( $attachment_post ) ) { |
|
178 | + foreach ($attachment_ids as $attachment_id) { |
|
179 | + $attachment_post = get_post($attachment_id); |
|
180 | + if (is_null($attachment_post)) { |
|
181 | 181 | continue; |
182 | 182 | } |
183 | 183 | |
184 | - $attachment = wp_get_attachment_image_src( $attachment_id, 'full' ); |
|
185 | - if ( ! is_array( $attachment ) ) { |
|
184 | + $attachment = wp_get_attachment_image_src($attachment_id, 'full'); |
|
185 | + if ( ! is_array($attachment)) { |
|
186 | 186 | continue; |
187 | 187 | } |
188 | 188 | |
189 | 189 | $images[] = array( |
190 | 190 | 'id' => (int) $attachment_id, |
191 | - 'src' => current( $attachment ), |
|
192 | - 'name' => get_the_title( $attachment_id ), |
|
193 | - 'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ), |
|
191 | + 'src' => current($attachment), |
|
192 | + 'name' => get_the_title($attachment_id), |
|
193 | + 'alt' => get_post_meta($attachment_id, '_wp_attachment_image_alt', true), |
|
194 | 194 | ); |
195 | 195 | } |
196 | 196 | |
@@ -206,18 +206,18 @@ discard block |
||
206 | 206 | * @param WP_REST_Request $request Request object. |
207 | 207 | * @return WP_REST_Response |
208 | 208 | */ |
209 | - public function prepare_item_for_response( $post, $request ) { |
|
210 | - $product = wc_get_product( $post ); |
|
211 | - $data = $this->get_product_data( $product ); |
|
209 | + public function prepare_item_for_response($post, $request) { |
|
210 | + $product = wc_get_product($post); |
|
211 | + $data = $this->get_product_data($product); |
|
212 | 212 | |
213 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
214 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
215 | - $data = $this->filter_response_by_context( $data, $context ); |
|
213 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
214 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
215 | + $data = $this->filter_response_by_context($data, $context); |
|
216 | 216 | |
217 | 217 | // Wrap the data in a response object. |
218 | - $response = rest_ensure_response( $data ); |
|
219 | - $response->header( 'X-Woo-Notice', __( 'Private REST API for use by block editor only.', 'woocommerce' ) ); |
|
220 | - $response->add_links( $this->prepare_links( $product, $request ) ); |
|
218 | + $response = rest_ensure_response($data); |
|
219 | + $response->header('X-Woo-Notice', __('Private REST API for use by block editor only.', 'woocommerce')); |
|
220 | + $response->add_links($this->prepare_links($product, $request)); |
|
221 | 221 | |
222 | 222 | return $response; |
223 | 223 | } |
@@ -229,52 +229,52 @@ discard block |
||
229 | 229 | * @param WP_REST_Request $request Request data. |
230 | 230 | * @return array |
231 | 231 | */ |
232 | - protected function prepare_objects_query( $request ) { |
|
233 | - $args = parent::prepare_objects_query( $request ); |
|
232 | + protected function prepare_objects_query($request) { |
|
233 | + $args = parent::prepare_objects_query($request); |
|
234 | 234 | $operator_mapping = array( |
235 | 235 | 'in' => 'IN', |
236 | 236 | 'not_in' => 'NOT IN', |
237 | 237 | 'and' => 'AND', |
238 | 238 | ); |
239 | 239 | |
240 | - $orderby = $request->get_param( 'orderby' ); |
|
241 | - $order = $request->get_param( 'order' ); |
|
242 | - $category_operator = $operator_mapping[ $request->get_param( 'category_operator' ) ]; |
|
243 | - $attribute_operator = $operator_mapping[ $request->get_param( 'attribute_operator' ) ]; |
|
244 | - $catalog_visibility = $request->get_param( 'catalog_visibility' ); |
|
240 | + $orderby = $request->get_param('orderby'); |
|
241 | + $order = $request->get_param('order'); |
|
242 | + $category_operator = $operator_mapping[$request->get_param('category_operator')]; |
|
243 | + $attribute_operator = $operator_mapping[$request->get_param('attribute_operator')]; |
|
244 | + $catalog_visibility = $request->get_param('catalog_visibility'); |
|
245 | 245 | |
246 | - $ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order ); |
|
246 | + $ordering_args = WC()->query->get_catalog_ordering_args($orderby, $order); |
|
247 | 247 | $args['orderby'] = $ordering_args['orderby']; |
248 | 248 | $args['order'] = $ordering_args['order']; |
249 | - if ( $ordering_args['meta_key'] ) { |
|
249 | + if ($ordering_args['meta_key']) { |
|
250 | 250 | $args['meta_key'] = $ordering_args['meta_key']; // WPCS: slow query ok. |
251 | 251 | } |
252 | 252 | |
253 | - if ( $category_operator && isset( $args['tax_query'] ) ) { |
|
254 | - foreach ( $args['tax_query'] as $i => $tax_query ) { |
|
255 | - if ( 'product_cat' === $tax_query['taxonomy'] ) { |
|
256 | - $args['tax_query'][ $i ]['operator'] = $category_operator; |
|
257 | - $args['tax_query'][ $i ]['include_children'] = 'AND' === $category_operator ? false : true; |
|
253 | + if ($category_operator && isset($args['tax_query'])) { |
|
254 | + foreach ($args['tax_query'] as $i => $tax_query) { |
|
255 | + if ('product_cat' === $tax_query['taxonomy']) { |
|
256 | + $args['tax_query'][$i]['operator'] = $category_operator; |
|
257 | + $args['tax_query'][$i]['include_children'] = 'AND' === $category_operator ? false : true; |
|
258 | 258 | } |
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
262 | - if ( $attribute_operator && isset( $args['tax_query'] ) ) { |
|
263 | - foreach ( $args['tax_query'] as $i => $tax_query ) { |
|
264 | - if ( in_array( $tax_query['taxonomy'], wc_get_attribute_taxonomy_names(), true ) ) { |
|
265 | - $args['tax_query'][ $i ]['operator'] = $attribute_operator; |
|
262 | + if ($attribute_operator && isset($args['tax_query'])) { |
|
263 | + foreach ($args['tax_query'] as $i => $tax_query) { |
|
264 | + if (in_array($tax_query['taxonomy'], wc_get_attribute_taxonomy_names(), true)) { |
|
265 | + $args['tax_query'][$i]['operator'] = $attribute_operator; |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
270 | - if ( in_array( $catalog_visibility, array_keys( wc_get_product_visibility_options() ), true ) ) { |
|
270 | + if (in_array($catalog_visibility, array_keys(wc_get_product_visibility_options()), true)) { |
|
271 | 271 | $exclude_from_catalog = 'search' === $catalog_visibility ? '' : 'exclude-from-catalog'; |
272 | 272 | $exclude_from_search = 'catalog' === $catalog_visibility ? '' : 'exclude-from-search'; |
273 | 273 | |
274 | 274 | $args['tax_query'][] = array( |
275 | 275 | 'taxonomy' => 'product_visibility', |
276 | 276 | 'field' => 'name', |
277 | - 'terms' => array( $exclude_from_catalog, $exclude_from_search ), |
|
277 | + 'terms' => array($exclude_from_catalog, $exclude_from_search), |
|
278 | 278 | 'operator' => 'hidden' === $catalog_visibility ? 'AND' : 'NOT IN', |
279 | 279 | ); |
280 | 280 | } |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | * Options: 'view' and 'edit'. |
291 | 291 | * @return array |
292 | 292 | */ |
293 | - protected function get_product_data( $product, $context = 'view' ) { |
|
294 | - $raw_data = parent::get_product_data( $product, $context ); |
|
293 | + protected function get_product_data($product, $context = 'view') { |
|
294 | + $raw_data = parent::get_product_data($product, $context); |
|
295 | 295 | $data = array(); |
296 | 296 | |
297 | 297 | $data['id'] = $raw_data['id']; |
@@ -317,27 +317,27 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function get_collection_params() { |
319 | 319 | $params = parent::get_collection_params(); |
320 | - $params['orderby']['enum'] = array_merge( $params['orderby']['enum'], array( 'price', 'popularity', 'rating', 'menu_order' ) ); |
|
320 | + $params['orderby']['enum'] = array_merge($params['orderby']['enum'], array('price', 'popularity', 'rating', 'menu_order')); |
|
321 | 321 | $params['category_operator'] = array( |
322 | - 'description' => __( 'Operator to compare product category terms.', 'woocommerce' ), |
|
322 | + 'description' => __('Operator to compare product category terms.', 'woocommerce'), |
|
323 | 323 | 'type' => 'string', |
324 | - 'enum' => array( 'in', 'not_in', 'and' ), |
|
324 | + 'enum' => array('in', 'not_in', 'and'), |
|
325 | 325 | 'default' => 'in', |
326 | 326 | 'sanitize_callback' => 'sanitize_key', |
327 | 327 | 'validate_callback' => 'rest_validate_request_arg', |
328 | 328 | ); |
329 | 329 | $params['attribute_operator'] = array( |
330 | - 'description' => __( 'Operator to compare product attribute terms.', 'woocommerce' ), |
|
330 | + 'description' => __('Operator to compare product attribute terms.', 'woocommerce'), |
|
331 | 331 | 'type' => 'string', |
332 | - 'enum' => array( 'in', 'not_in', 'and' ), |
|
332 | + 'enum' => array('in', 'not_in', 'and'), |
|
333 | 333 | 'default' => 'in', |
334 | 334 | 'sanitize_callback' => 'sanitize_key', |
335 | 335 | 'validate_callback' => 'rest_validate_request_arg', |
336 | 336 | ); |
337 | 337 | $params['catalog_visibility'] = array( |
338 | - 'description' => __( 'Determines if hidden or visible catalog products are shown.', 'woocommerce' ), |
|
338 | + 'description' => __('Determines if hidden or visible catalog products are shown.', 'woocommerce'), |
|
339 | 339 | 'type' => 'string', |
340 | - 'enum' => array( 'visible', 'catalog', 'search', 'hidden' ), |
|
340 | + 'enum' => array('visible', 'catalog', 'search', 'hidden'), |
|
341 | 341 | 'sanitize_callback' => 'sanitize_key', |
342 | 342 | 'validate_callback' => 'rest_validate_request_arg', |
343 | 343 | ); |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | $schema['properties']['images'] = array( |
372 | 372 | 'description' => $raw_schema['properties']['images']['description'], |
373 | 373 | 'type' => 'object', |
374 | - 'context' => array( 'view', 'edit' ), |
|
374 | + 'context' => array('view', 'edit'), |
|
375 | 375 | 'items' => array( |
376 | 376 | 'type' => 'object', |
377 | 377 | 'properties' => array(), |
@@ -385,6 +385,6 @@ discard block |
||
385 | 385 | $schema['properties']['images']['items']['properties']['name'] = $images_schema['name']; |
386 | 386 | $schema['properties']['images']['items']['properties']['alt'] = $images_schema['alt']; |
387 | 387 | |
388 | - return $this->add_additional_fields_schema( $schema ); |
|
388 | + return $this->add_additional_fields_schema($schema); |
|
389 | 389 | } |
390 | 390 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @package WooCommerce/RestApi |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | array( |
37 | 37 | array( |
38 | 38 | 'methods' => WP_REST_Server::READABLE, |
39 | - 'callback' => array( $this, 'get_items' ), |
|
40 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
39 | + 'callback' => array($this, 'get_items'), |
|
40 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
41 | 41 | 'args' => $this->get_collection_params(), |
42 | 42 | ), |
43 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
43 | + 'schema' => array($this, 'get_public_item_schema'), |
|
44 | 44 | ) |
45 | 45 | ); |
46 | 46 | |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | array( |
51 | 51 | 'args' => array( |
52 | 52 | 'id' => array( |
53 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
53 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
54 | 54 | 'type' => 'integer', |
55 | 55 | ), |
56 | 56 | ), |
57 | 57 | array( |
58 | 58 | 'methods' => WP_REST_Server::READABLE, |
59 | - 'callback' => array( $this, 'get_item' ), |
|
60 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
59 | + 'callback' => array($this, 'get_item'), |
|
60 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
61 | 61 | 'args' => array( |
62 | 62 | 'context' => $this->get_context_param( |
63 | 63 | array( |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | ), |
67 | 67 | ), |
68 | 68 | ), |
69 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
69 | + 'schema' => array($this, 'get_public_item_schema'), |
|
70 | 70 | ) |
71 | 71 | ); |
72 | 72 | } |
@@ -78,24 +78,24 @@ discard block |
||
78 | 78 | * @param string $context Request context. |
79 | 79 | * @return bool|WP_Error |
80 | 80 | */ |
81 | - protected function check_permissions( $request, $context = 'read' ) { |
|
81 | + protected function check_permissions($request, $context = 'read') { |
|
82 | 82 | // Get taxonomy. |
83 | - $taxonomy = $this->get_taxonomy( $request ); |
|
84 | - if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) { |
|
85 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Taxonomy does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
83 | + $taxonomy = $this->get_taxonomy($request); |
|
84 | + if ( ! $taxonomy || ! taxonomy_exists($taxonomy)) { |
|
85 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Taxonomy does not exist.', 'woocommerce'), array('status' => 404)); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Check permissions for a single term. |
89 | - $id = intval( $request['id'] ); |
|
90 | - if ( $id ) { |
|
91 | - $term = get_term( $id, $taxonomy ); |
|
89 | + $id = intval($request['id']); |
|
90 | + if ($id) { |
|
91 | + $term = get_term($id, $taxonomy); |
|
92 | 92 | |
93 | - if ( is_wp_error( $term ) || ! $term || $term->taxonomy !== $taxonomy ) { |
|
94 | - return new WP_Error( 'woocommerce_rest_term_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
93 | + if (is_wp_error($term) || ! $term || $term->taxonomy !== $taxonomy) { |
|
94 | + return new WP_Error('woocommerce_rest_term_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | - return current_user_can( 'edit_posts' ); |
|
98 | + return current_user_can('edit_posts'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -105,10 +105,10 @@ discard block |
||
105 | 105 | * @param WP_REST_Request $request Request instance. |
106 | 106 | * @return WP_REST_Response |
107 | 107 | */ |
108 | - public function prepare_item_for_response( $item, $request ) { |
|
108 | + public function prepare_item_for_response($item, $request) { |
|
109 | 109 | // Get the attribute slug. |
110 | - $attribute_id = absint( $request->get_param( 'attribute_id' ) ); |
|
111 | - $attribute = wc_get_attribute( $attribute_id ); |
|
110 | + $attribute_id = absint($request->get_param('attribute_id')); |
|
111 | + $attribute = wc_get_attribute($attribute_id); |
|
112 | 112 | |
113 | 113 | $data = array( |
114 | 114 | 'id' => (int) $item->term_id, |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | ), |
123 | 123 | ); |
124 | 124 | |
125 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
126 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
127 | - $data = $this->filter_response_by_context( $data, $context ); |
|
125 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
126 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
127 | + $data = $this->filter_response_by_context($data, $context); |
|
128 | 128 | |
129 | - $response = rest_ensure_response( $data ); |
|
129 | + $response = rest_ensure_response($data); |
|
130 | 130 | |
131 | - $response->header( 'X-Woo-Notice', __( 'Private REST API for use by block editor only.', 'woocommerce' ) ); |
|
131 | + $response->header('X-Woo-Notice', __('Private REST API for use by block editor only.', 'woocommerce')); |
|
132 | 132 | |
133 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
133 | + $response->add_links($this->prepare_links($item, $request)); |
|
134 | 134 | |
135 | 135 | return $response; |
136 | 136 | } |
@@ -154,32 +154,32 @@ discard block |
||
154 | 154 | $schema['properties']['slug'] = $raw_schema['properties']['slug']; |
155 | 155 | $schema['properties']['count'] = $raw_schema['properties']['count']; |
156 | 156 | $schema['properties']['attribute'] = array( |
157 | - 'description' => __( 'Attribute.', 'woocommerce' ), |
|
157 | + 'description' => __('Attribute.', 'woocommerce'), |
|
158 | 158 | 'type' => 'object', |
159 | - 'context' => array( 'view', 'edit' ), |
|
159 | + 'context' => array('view', 'edit'), |
|
160 | 160 | 'readonly' => true, |
161 | 161 | 'properties' => array( |
162 | 162 | 'id' => array( |
163 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
163 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
164 | 164 | 'type' => 'integer', |
165 | - 'context' => array( 'view', 'edit' ), |
|
165 | + 'context' => array('view', 'edit'), |
|
166 | 166 | 'readonly' => true, |
167 | 167 | ), |
168 | 168 | 'name' => array( |
169 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
169 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
170 | 170 | 'type' => 'string', |
171 | - 'context' => array( 'view', 'edit' ), |
|
171 | + 'context' => array('view', 'edit'), |
|
172 | 172 | 'readonly' => true, |
173 | 173 | ), |
174 | 174 | 'slug' => array( |
175 | - 'description' => __( 'Attribute slug.', 'woocommerce' ), |
|
175 | + 'description' => __('Attribute slug.', 'woocommerce'), |
|
176 | 176 | 'type' => 'string', |
177 | - 'context' => array( 'view', 'edit' ), |
|
177 | + 'context' => array('view', 'edit'), |
|
178 | 178 | 'readonly' => true, |
179 | 179 | ), |
180 | 180 | ), |
181 | 181 | ); |
182 | 182 | |
183 | - return $this->add_additional_fields_schema( $schema ); |
|
183 | + return $this->add_additional_fields_schema($schema); |
|
184 | 184 | } |
185 | 185 | } |
@@ -5,7 +5,7 @@ |
||
5 | 5 | * @package WooCommerce/RestApi |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Controllers class. |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Shipping methods controller class. |
@@ -40,30 +40,30 @@ discard block |
||
40 | 40 | $this->namespace, '/' . $this->rest_base, array( |
41 | 41 | array( |
42 | 42 | 'methods' => WP_REST_Server::READABLE, |
43 | - 'callback' => array( $this, 'get_items' ), |
|
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
43 | + 'callback' => array($this, 'get_items'), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | 45 | 'args' => $this->get_collection_params(), |
46 | 46 | ), |
47 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
47 | + 'schema' => array($this, 'get_public_item_schema'), |
|
48 | 48 | ) |
49 | 49 | ); |
50 | 50 | register_rest_route( |
51 | 51 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array( |
52 | 52 | 'args' => array( |
53 | 53 | 'id' => array( |
54 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
54 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
55 | 55 | 'type' => 'string', |
56 | 56 | ), |
57 | 57 | ), |
58 | 58 | array( |
59 | 59 | 'methods' => WP_REST_Server::READABLE, |
60 | - 'callback' => array( $this, 'get_item' ), |
|
61 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
60 | + 'callback' => array($this, 'get_item'), |
|
61 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
62 | 62 | 'args' => array( |
63 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
63 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
64 | 64 | ), |
65 | 65 | ), |
66 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
66 | + 'schema' => array($this, 'get_public_item_schema'), |
|
67 | 67 | ) |
68 | 68 | ); |
69 | 69 | } |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | * @param WP_REST_Request $request Full details about the request. |
75 | 75 | * @return WP_Error|boolean |
76 | 76 | */ |
77 | - public function get_items_permissions_check( $request ) { |
|
78 | - if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { |
|
79 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
77 | + public function get_items_permissions_check($request) { |
|
78 | + if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) { |
|
79 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
80 | 80 | } |
81 | 81 | return true; |
82 | 82 | } |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | * @param WP_REST_Request $request Full details about the request. |
88 | 88 | * @return WP_Error|boolean |
89 | 89 | */ |
90 | - public function get_item_permissions_check( $request ) { |
|
91 | - if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { |
|
92 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
90 | + public function get_item_permissions_check($request) { |
|
91 | + if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) { |
|
92 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
93 | 93 | } |
94 | 94 | return true; |
95 | 95 | } |
@@ -100,15 +100,15 @@ discard block |
||
100 | 100 | * @param WP_REST_Request $request Full details about the request. |
101 | 101 | * @return WP_Error|WP_REST_Response |
102 | 102 | */ |
103 | - public function get_items( $request ) { |
|
103 | + public function get_items($request) { |
|
104 | 104 | $wc_shipping = WC_Shipping::instance(); |
105 | 105 | $response = array(); |
106 | - foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) { |
|
107 | - $method = $this->prepare_item_for_response( $shipping_method, $request ); |
|
108 | - $method = $this->prepare_response_for_collection( $method ); |
|
106 | + foreach ($wc_shipping->get_shipping_methods() as $id => $shipping_method) { |
|
107 | + $method = $this->prepare_item_for_response($shipping_method, $request); |
|
108 | + $method = $this->prepare_response_for_collection($method); |
|
109 | 109 | $response[] = $method; |
110 | 110 | } |
111 | - return rest_ensure_response( $response ); |
|
111 | + return rest_ensure_response($response); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -117,17 +117,17 @@ discard block |
||
117 | 117 | * @param WP_REST_Request $request Request data. |
118 | 118 | * @return WP_REST_Response|WP_Error |
119 | 119 | */ |
120 | - public function get_item( $request ) { |
|
120 | + public function get_item($request) { |
|
121 | 121 | $wc_shipping = WC_Shipping::instance(); |
122 | 122 | $methods = $wc_shipping->get_shipping_methods(); |
123 | - if ( empty( $methods[ $request['id'] ] ) ) { |
|
124 | - return new WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
123 | + if (empty($methods[$request['id']])) { |
|
124 | + return new WP_Error('woocommerce_rest_shipping_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
125 | 125 | } |
126 | 126 | |
127 | - $method = $methods[ $request['id'] ]; |
|
128 | - $response = $this->prepare_item_for_response( $method, $request ); |
|
127 | + $method = $methods[$request['id']]; |
|
128 | + $response = $this->prepare_item_for_response($method, $request); |
|
129 | 129 | |
130 | - return rest_ensure_response( $response ); |
|
130 | + return rest_ensure_response($response); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,21 +137,21 @@ discard block |
||
137 | 137 | * @param WP_REST_Request $request Request object. |
138 | 138 | * @return WP_REST_Response $response Response data. |
139 | 139 | */ |
140 | - public function prepare_item_for_response( $method, $request ) { |
|
140 | + public function prepare_item_for_response($method, $request) { |
|
141 | 141 | $data = array( |
142 | 142 | 'id' => $method->id, |
143 | 143 | 'title' => $method->method_title, |
144 | 144 | 'description' => $method->method_description, |
145 | 145 | ); |
146 | 146 | |
147 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
148 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
149 | - $data = $this->filter_response_by_context( $data, $context ); |
|
147 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
148 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
149 | + $data = $this->filter_response_by_context($data, $context); |
|
150 | 150 | |
151 | 151 | // Wrap the data in a response object. |
152 | - $response = rest_ensure_response( $data ); |
|
152 | + $response = rest_ensure_response($data); |
|
153 | 153 | |
154 | - $response->add_links( $this->prepare_links( $method, $request ) ); |
|
154 | + $response->add_links($this->prepare_links($method, $request)); |
|
155 | 155 | |
156 | 156 | /** |
157 | 157 | * Filter shipping methods object returned from the REST API. |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @param WC_Shipping_Method $method Shipping method object used to create response. |
161 | 161 | * @param WP_REST_Request $request Request object. |
162 | 162 | */ |
163 | - return apply_filters( 'woocommerce_rest_prepare_shipping_method', $response, $method, $request ); |
|
163 | + return apply_filters('woocommerce_rest_prepare_shipping_method', $response, $method, $request); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | * @param WP_REST_Request $request Request object. |
171 | 171 | * @return array |
172 | 172 | */ |
173 | - protected function prepare_links( $method, $request ) { |
|
173 | + protected function prepare_links($method, $request) { |
|
174 | 174 | $links = array( |
175 | 175 | 'self' => array( |
176 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $method->id ) ), |
|
176 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $method->id)), |
|
177 | 177 | ), |
178 | 178 | 'collection' => array( |
179 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
179 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
180 | 180 | ), |
181 | 181 | ); |
182 | 182 | |
@@ -195,27 +195,27 @@ discard block |
||
195 | 195 | 'type' => 'object', |
196 | 196 | 'properties' => array( |
197 | 197 | 'id' => array( |
198 | - 'description' => __( 'Method ID.', 'woocommerce' ), |
|
198 | + 'description' => __('Method ID.', 'woocommerce'), |
|
199 | 199 | 'type' => 'string', |
200 | - 'context' => array( 'view' ), |
|
200 | + 'context' => array('view'), |
|
201 | 201 | 'readonly' => true, |
202 | 202 | ), |
203 | 203 | 'title' => array( |
204 | - 'description' => __( 'Shipping method title.', 'woocommerce' ), |
|
204 | + 'description' => __('Shipping method title.', 'woocommerce'), |
|
205 | 205 | 'type' => 'string', |
206 | - 'context' => array( 'view' ), |
|
206 | + 'context' => array('view'), |
|
207 | 207 | 'readonly' => true, |
208 | 208 | ), |
209 | 209 | 'description' => array( |
210 | - 'description' => __( 'Shipping method description.', 'woocommerce' ), |
|
210 | + 'description' => __('Shipping method description.', 'woocommerce'), |
|
211 | 211 | 'type' => 'string', |
212 | - 'context' => array( 'view' ), |
|
212 | + 'context' => array('view'), |
|
213 | 213 | 'readonly' => true, |
214 | 214 | ), |
215 | 215 | ), |
216 | 216 | ); |
217 | 217 | |
218 | - return $this->add_additional_fields_schema( $schema ); |
|
218 | + return $this->add_additional_fields_schema($schema); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public function get_collection_params() { |
227 | 227 | return array( |
228 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
228 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
229 | 229 | ); |
230 | 230 | } |
231 | 231 | } |