@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Product Shipping Classes controller class. |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param \WP_REST_Request $request Request params. |
38 | 38 | * @return \WP_REST_Response $response |
39 | 39 | */ |
40 | - public function prepare_item_for_response( $item, $request ) { |
|
40 | + public function prepare_item_for_response($item, $request) { |
|
41 | 41 | $data = array( |
42 | 42 | 'id' => (int) $item->term_id, |
43 | 43 | 'name' => $item->name, |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | 'count' => (int) $item->count, |
47 | 47 | ); |
48 | 48 | |
49 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
50 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
51 | - $data = $this->filter_response_by_context( $data, $context ); |
|
49 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
50 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
51 | + $data = $this->filter_response_by_context($data, $context); |
|
52 | 52 | |
53 | - $response = rest_ensure_response( $data ); |
|
53 | + $response = rest_ensure_response($data); |
|
54 | 54 | |
55 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
55 | + $response->add_links($this->prepare_links($item, $request)); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Filter a term item returned from the API. |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param object $item The original term object. |
64 | 64 | * @param \WP_REST_Request $request Request used to generate the response. |
65 | 65 | */ |
66 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
66 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -78,44 +78,44 @@ discard block |
||
78 | 78 | 'type' => 'object', |
79 | 79 | 'properties' => array( |
80 | 80 | 'id' => array( |
81 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
81 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
82 | 82 | 'type' => 'integer', |
83 | - 'context' => array( 'view', 'edit' ), |
|
83 | + 'context' => array('view', 'edit'), |
|
84 | 84 | 'readonly' => true, |
85 | 85 | ), |
86 | 86 | 'name' => array( |
87 | - 'description' => __( 'Shipping class name.', 'woocommerce' ), |
|
87 | + 'description' => __('Shipping class name.', 'woocommerce'), |
|
88 | 88 | 'type' => 'string', |
89 | - 'context' => array( 'view', 'edit' ), |
|
89 | + 'context' => array('view', 'edit'), |
|
90 | 90 | 'arg_options' => array( |
91 | 91 | 'sanitize_callback' => 'sanitize_text_field', |
92 | 92 | ), |
93 | 93 | ), |
94 | 94 | 'slug' => array( |
95 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
95 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
96 | 96 | 'type' => 'string', |
97 | - 'context' => array( 'view', 'edit' ), |
|
97 | + 'context' => array('view', 'edit'), |
|
98 | 98 | 'arg_options' => array( |
99 | 99 | 'sanitize_callback' => 'sanitize_title', |
100 | 100 | ), |
101 | 101 | ), |
102 | 102 | 'description' => array( |
103 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
103 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
104 | 104 | 'type' => 'string', |
105 | - 'context' => array( 'view', 'edit' ), |
|
105 | + 'context' => array('view', 'edit'), |
|
106 | 106 | 'arg_options' => array( |
107 | 107 | 'sanitize_callback' => 'wp_filter_post_kses', |
108 | 108 | ), |
109 | 109 | ), |
110 | 110 | 'count' => array( |
111 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
111 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
112 | 112 | 'type' => 'integer', |
113 | - 'context' => array( 'view', 'edit' ), |
|
113 | + 'context' => array('view', 'edit'), |
|
114 | 114 | 'readonly' => true, |
115 | 115 | ), |
116 | 116 | ), |
117 | 117 | ); |
118 | 118 | |
119 | - return $this->add_additional_fields_schema( $schema ); |
|
119 | + return $this->add_additional_fields_schema($schema); |
|
120 | 120 | } |
121 | 121 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Product Categories controller class. |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * @param \WP_REST_Request $request Request instance. |
38 | 38 | * @return \WP_REST_Response |
39 | 39 | */ |
40 | - public function prepare_item_for_response( $item, $request ) { |
|
40 | + public function prepare_item_for_response($item, $request) { |
|
41 | 41 | // Get category display type. |
42 | - $display_type = get_term_meta( $item->term_id, 'display_type', true ); |
|
42 | + $display_type = get_term_meta($item->term_id, 'display_type', true); |
|
43 | 43 | |
44 | 44 | // Get category order. |
45 | - $menu_order = get_term_meta( $item->term_id, 'order', true ); |
|
45 | + $menu_order = get_term_meta($item->term_id, 'order', true); |
|
46 | 46 | |
47 | 47 | $data = array( |
48 | 48 | 'id' => (int) $item->term_id, |
@@ -57,29 +57,29 @@ discard block |
||
57 | 57 | ); |
58 | 58 | |
59 | 59 | // Get category image. |
60 | - $image_id = get_term_meta( $item->term_id, 'thumbnail_id', true ); |
|
61 | - if ( $image_id ) { |
|
62 | - $attachment = get_post( $image_id ); |
|
60 | + $image_id = get_term_meta($item->term_id, 'thumbnail_id', true); |
|
61 | + if ($image_id) { |
|
62 | + $attachment = get_post($image_id); |
|
63 | 63 | |
64 | 64 | $data['image'] = array( |
65 | 65 | 'id' => (int) $image_id, |
66 | - 'date_created' => wc_rest_prepare_date_response( $attachment->post_date ), |
|
67 | - 'date_created_gmt' => wc_rest_prepare_date_response( $attachment->post_date_gmt ), |
|
68 | - 'date_modified' => wc_rest_prepare_date_response( $attachment->post_modified ), |
|
69 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $attachment->post_modified_gmt ), |
|
70 | - 'src' => wp_get_attachment_url( $image_id ), |
|
71 | - 'name' => get_the_title( $attachment ), |
|
72 | - 'alt' => get_post_meta( $image_id, '_wp_attachment_image_alt', true ), |
|
66 | + 'date_created' => wc_rest_prepare_date_response($attachment->post_date), |
|
67 | + 'date_created_gmt' => wc_rest_prepare_date_response($attachment->post_date_gmt), |
|
68 | + 'date_modified' => wc_rest_prepare_date_response($attachment->post_modified), |
|
69 | + 'date_modified_gmt' => wc_rest_prepare_date_response($attachment->post_modified_gmt), |
|
70 | + 'src' => wp_get_attachment_url($image_id), |
|
71 | + 'name' => get_the_title($attachment), |
|
72 | + 'alt' => get_post_meta($image_id, '_wp_attachment_image_alt', true), |
|
73 | 73 | ); |
74 | 74 | } |
75 | 75 | |
76 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
77 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
78 | - $data = $this->filter_response_by_context( $data, $context ); |
|
76 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
77 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
78 | + $data = $this->filter_response_by_context($data, $context); |
|
79 | 79 | |
80 | - $response = rest_ensure_response( $data ); |
|
80 | + $response = rest_ensure_response($data); |
|
81 | 81 | |
82 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
82 | + $response->add_links($this->prepare_links($item, $request)); |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Filter a term item returned from the API. |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param object $item The original term object. |
91 | 91 | * @param \WP_REST_Request $request Request used to generate the response. |
92 | 92 | */ |
93 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
93 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -102,50 +102,50 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @since 3.5.5 |
104 | 104 | */ |
105 | - protected function update_term_meta_fields( $term, $request ) { |
|
105 | + protected function update_term_meta_fields($term, $request) { |
|
106 | 106 | $id = (int) $term->term_id; |
107 | 107 | |
108 | - if ( isset( $request['display'] ) ) { |
|
109 | - update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] ); |
|
108 | + if (isset($request['display'])) { |
|
109 | + update_term_meta($id, 'display_type', 'default' === $request['display'] ? '' : $request['display']); |
|
110 | 110 | } |
111 | 111 | |
112 | - if ( isset( $request['menu_order'] ) ) { |
|
113 | - update_term_meta( $id, 'order', $request['menu_order'] ); |
|
112 | + if (isset($request['menu_order'])) { |
|
113 | + update_term_meta($id, 'order', $request['menu_order']); |
|
114 | 114 | } |
115 | 115 | |
116 | - if ( isset( $request['image'] ) ) { |
|
117 | - if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) { |
|
118 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) ); |
|
116 | + if (isset($request['image'])) { |
|
117 | + if (empty($request['image']['id']) && ! empty($request['image']['src'])) { |
|
118 | + $upload = wc_rest_upload_image_from_url(esc_url_raw($request['image']['src'])); |
|
119 | 119 | |
120 | - if ( is_wp_error( $upload ) ) { |
|
120 | + if (is_wp_error($upload)) { |
|
121 | 121 | return $upload; |
122 | 122 | } |
123 | 123 | |
124 | - $image_id = wc_rest_set_uploaded_image_as_attachment( $upload ); |
|
124 | + $image_id = wc_rest_set_uploaded_image_as_attachment($upload); |
|
125 | 125 | } else { |
126 | - $image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0; |
|
126 | + $image_id = isset($request['image']['id']) ? absint($request['image']['id']) : 0; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | // Check if image_id is a valid image attachment before updating the term meta. |
130 | - if ( $image_id && wp_attachment_is_image( $image_id ) ) { |
|
131 | - update_term_meta( $id, 'thumbnail_id', $image_id ); |
|
130 | + if ($image_id && wp_attachment_is_image($image_id)) { |
|
131 | + update_term_meta($id, 'thumbnail_id', $image_id); |
|
132 | 132 | |
133 | 133 | // Set the image alt. |
134 | - if ( ! empty( $request['image']['alt'] ) ) { |
|
135 | - update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) ); |
|
134 | + if ( ! empty($request['image']['alt'])) { |
|
135 | + update_post_meta($image_id, '_wp_attachment_image_alt', wc_clean($request['image']['alt'])); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | // Set the image title. |
139 | - if ( ! empty( $request['image']['name'] ) ) { |
|
139 | + if ( ! empty($request['image']['name'])) { |
|
140 | 140 | wp_update_post( |
141 | 141 | array( |
142 | 142 | 'ID' => $image_id, |
143 | - 'post_title' => wc_clean( $request['image']['name'] ), |
|
143 | + 'post_title' => wc_clean($request['image']['name']), |
|
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | } |
147 | 147 | } else { |
148 | - delete_term_meta( $id, 'thumbnail_id' ); |
|
148 | + delete_term_meta($id, 'thumbnail_id'); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -164,113 +164,113 @@ discard block |
||
164 | 164 | 'type' => 'object', |
165 | 165 | 'properties' => array( |
166 | 166 | 'id' => array( |
167 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
167 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
168 | 168 | 'type' => 'integer', |
169 | - 'context' => array( 'view', 'edit' ), |
|
169 | + 'context' => array('view', 'edit'), |
|
170 | 170 | 'readonly' => true, |
171 | 171 | ), |
172 | 172 | 'name' => array( |
173 | - 'description' => __( 'Category name.', 'woocommerce' ), |
|
173 | + 'description' => __('Category name.', 'woocommerce'), |
|
174 | 174 | 'type' => 'string', |
175 | - 'context' => array( 'view', 'edit' ), |
|
175 | + 'context' => array('view', 'edit'), |
|
176 | 176 | 'arg_options' => array( |
177 | 177 | 'sanitize_callback' => 'sanitize_text_field', |
178 | 178 | ), |
179 | 179 | ), |
180 | 180 | 'slug' => array( |
181 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
181 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
182 | 182 | 'type' => 'string', |
183 | - 'context' => array( 'view', 'edit' ), |
|
183 | + 'context' => array('view', 'edit'), |
|
184 | 184 | 'arg_options' => array( |
185 | 185 | 'sanitize_callback' => 'sanitize_title', |
186 | 186 | ), |
187 | 187 | ), |
188 | 188 | 'parent' => array( |
189 | - 'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ), |
|
189 | + 'description' => __('The ID for the parent of the resource.', 'woocommerce'), |
|
190 | 190 | 'type' => 'integer', |
191 | - 'context' => array( 'view', 'edit' ), |
|
191 | + 'context' => array('view', 'edit'), |
|
192 | 192 | ), |
193 | 193 | 'description' => array( |
194 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
194 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
195 | 195 | 'type' => 'string', |
196 | - 'context' => array( 'view', 'edit' ), |
|
196 | + 'context' => array('view', 'edit'), |
|
197 | 197 | 'arg_options' => array( |
198 | 198 | 'sanitize_callback' => 'wp_filter_post_kses', |
199 | 199 | ), |
200 | 200 | ), |
201 | 201 | 'display' => array( |
202 | - 'description' => __( 'Category archive display type.', 'woocommerce' ), |
|
202 | + 'description' => __('Category archive display type.', 'woocommerce'), |
|
203 | 203 | 'type' => 'string', |
204 | 204 | 'default' => 'default', |
205 | - 'enum' => array( 'default', 'products', 'subcategories', 'both' ), |
|
206 | - 'context' => array( 'view', 'edit' ), |
|
205 | + 'enum' => array('default', 'products', 'subcategories', 'both'), |
|
206 | + 'context' => array('view', 'edit'), |
|
207 | 207 | ), |
208 | 208 | 'image' => array( |
209 | - 'description' => __( 'Image data.', 'woocommerce' ), |
|
209 | + 'description' => __('Image data.', 'woocommerce'), |
|
210 | 210 | 'type' => 'object', |
211 | - 'context' => array( 'view', 'edit' ), |
|
211 | + 'context' => array('view', 'edit'), |
|
212 | 212 | 'properties' => array( |
213 | 213 | 'id' => array( |
214 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
214 | + 'description' => __('Image ID.', 'woocommerce'), |
|
215 | 215 | 'type' => 'integer', |
216 | - 'context' => array( 'view', 'edit' ), |
|
216 | + 'context' => array('view', 'edit'), |
|
217 | 217 | ), |
218 | 218 | 'date_created' => array( |
219 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
219 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
220 | 220 | 'type' => 'date-time', |
221 | - 'context' => array( 'view', 'edit' ), |
|
221 | + 'context' => array('view', 'edit'), |
|
222 | 222 | 'readonly' => true, |
223 | 223 | ), |
224 | 224 | 'date_created_gmt' => array( |
225 | - 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
|
225 | + 'description' => __('The date the image was created, as GMT.', 'woocommerce'), |
|
226 | 226 | 'type' => 'date-time', |
227 | - 'context' => array( 'view', 'edit' ), |
|
227 | + 'context' => array('view', 'edit'), |
|
228 | 228 | 'readonly' => true, |
229 | 229 | ), |
230 | 230 | 'date_modified' => array( |
231 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
231 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
232 | 232 | 'type' => 'date-time', |
233 | - 'context' => array( 'view', 'edit' ), |
|
233 | + 'context' => array('view', 'edit'), |
|
234 | 234 | 'readonly' => true, |
235 | 235 | ), |
236 | 236 | 'date_modified_gmt' => array( |
237 | - 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
|
237 | + 'description' => __('The date the image was last modified, as GMT.', 'woocommerce'), |
|
238 | 238 | 'type' => 'date-time', |
239 | - 'context' => array( 'view', 'edit' ), |
|
239 | + 'context' => array('view', 'edit'), |
|
240 | 240 | 'readonly' => true, |
241 | 241 | ), |
242 | 242 | 'src' => array( |
243 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
243 | + 'description' => __('Image URL.', 'woocommerce'), |
|
244 | 244 | 'type' => 'string', |
245 | 245 | 'format' => 'uri', |
246 | - 'context' => array( 'view', 'edit' ), |
|
246 | + 'context' => array('view', 'edit'), |
|
247 | 247 | ), |
248 | 248 | 'name' => array( |
249 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
249 | + 'description' => __('Image name.', 'woocommerce'), |
|
250 | 250 | 'type' => 'string', |
251 | - 'context' => array( 'view', 'edit' ), |
|
251 | + 'context' => array('view', 'edit'), |
|
252 | 252 | ), |
253 | 253 | 'alt' => array( |
254 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
254 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
255 | 255 | 'type' => 'string', |
256 | - 'context' => array( 'view', 'edit' ), |
|
256 | + 'context' => array('view', 'edit'), |
|
257 | 257 | ), |
258 | 258 | ), |
259 | 259 | ), |
260 | 260 | 'menu_order' => array( |
261 | - 'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ), |
|
261 | + 'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'), |
|
262 | 262 | 'type' => 'integer', |
263 | - 'context' => array( 'view', 'edit' ), |
|
263 | + 'context' => array('view', 'edit'), |
|
264 | 264 | ), |
265 | 265 | 'count' => array( |
266 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
266 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
267 | 267 | 'type' => 'integer', |
268 | - 'context' => array( 'view', 'edit' ), |
|
268 | + 'context' => array('view', 'edit'), |
|
269 | 269 | 'readonly' => true, |
270 | 270 | ), |
271 | 271 | ), |
272 | 272 | ); |
273 | 273 | |
274 | - return $this->add_additional_fields_schema( $schema ); |
|
274 | + return $this->add_additional_fields_schema($schema); |
|
275 | 275 | } |
276 | 276 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Coupons controller class. |
@@ -40,26 +40,26 @@ discard block |
||
40 | 40 | array( |
41 | 41 | array( |
42 | 42 | 'methods' => \WP_REST_Server::READABLE, |
43 | - 'callback' => array( $this, 'get_items' ), |
|
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
43 | + 'callback' => array($this, 'get_items'), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | 45 | 'args' => $this->get_collection_params(), |
46 | 46 | ), |
47 | 47 | array( |
48 | 48 | 'methods' => \WP_REST_Server::CREATABLE, |
49 | - 'callback' => array( $this, 'create_item' ), |
|
50 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
49 | + 'callback' => array($this, 'create_item'), |
|
50 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
51 | 51 | 'args' => array_merge( |
52 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
52 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
53 | 53 | array( |
54 | 54 | 'code' => array( |
55 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
55 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
56 | 56 | 'required' => true, |
57 | 57 | 'type' => 'string', |
58 | 58 | ), |
59 | 59 | ) |
60 | 60 | ), |
61 | 61 | ), |
62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
62 | + 'schema' => array($this, 'get_public_item_schema'), |
|
63 | 63 | ), |
64 | 64 | true |
65 | 65 | ); |
@@ -70,37 +70,37 @@ discard block |
||
70 | 70 | array( |
71 | 71 | 'args' => array( |
72 | 72 | 'id' => array( |
73 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
73 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
74 | 74 | 'type' => 'integer', |
75 | 75 | ), |
76 | 76 | ), |
77 | 77 | array( |
78 | 78 | 'methods' => \WP_REST_Server::READABLE, |
79 | - 'callback' => array( $this, 'get_item' ), |
|
80 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
79 | + 'callback' => array($this, 'get_item'), |
|
80 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
81 | 81 | 'args' => array( |
82 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
82 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
83 | 83 | ), |
84 | 84 | ), |
85 | 85 | array( |
86 | 86 | 'methods' => \WP_REST_Server::EDITABLE, |
87 | - 'callback' => array( $this, 'update_item' ), |
|
88 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
89 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
87 | + 'callback' => array($this, 'update_item'), |
|
88 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
89 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
90 | 90 | ), |
91 | 91 | array( |
92 | 92 | 'methods' => \WP_REST_Server::DELETABLE, |
93 | - 'callback' => array( $this, 'delete_item' ), |
|
94 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
93 | + 'callback' => array($this, 'delete_item'), |
|
94 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
95 | 95 | 'args' => array( |
96 | 96 | 'force' => array( |
97 | 97 | 'default' => false, |
98 | 98 | 'type' => 'boolean', |
99 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
99 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
100 | 100 | ), |
101 | 101 | ), |
102 | 102 | ), |
103 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
103 | + 'schema' => array($this, 'get_public_item_schema'), |
|
104 | 104 | ), |
105 | 105 | true |
106 | 106 | ); |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | array( |
112 | 112 | array( |
113 | 113 | 'methods' => \WP_REST_Server::EDITABLE, |
114 | - 'callback' => array( $this, 'batch_items' ), |
|
115 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
116 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
114 | + 'callback' => array($this, 'batch_items'), |
|
115 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
116 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
117 | 117 | ), |
118 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
118 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
119 | 119 | ), |
120 | 120 | true |
121 | 121 | ); |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | * @param int $id Object ID. |
129 | 129 | * @return WC_Data |
130 | 130 | */ |
131 | - protected function get_object( $id ) { |
|
132 | - return new \WC_Coupon( $id ); |
|
131 | + protected function get_object($id) { |
|
132 | + return new \WC_Coupon($id); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,28 +139,28 @@ discard block |
||
139 | 139 | * @param WC_Data $object WC_Data instance. |
140 | 140 | * @return array |
141 | 141 | */ |
142 | - protected function get_formatted_item_data( $object ) { |
|
142 | + protected function get_formatted_item_data($object) { |
|
143 | 143 | $data = $object->get_data(); |
144 | 144 | |
145 | - $format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' ); |
|
146 | - $format_date = array( 'date_created', 'date_modified', 'date_expires' ); |
|
147 | - $format_null = array( 'usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items' ); |
|
145 | + $format_decimal = array('amount', 'minimum_amount', 'maximum_amount'); |
|
146 | + $format_date = array('date_created', 'date_modified', 'date_expires'); |
|
147 | + $format_null = array('usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items'); |
|
148 | 148 | |
149 | 149 | // Format decimal values. |
150 | - foreach ( $format_decimal as $key ) { |
|
151 | - $data[ $key ] = wc_format_decimal( $data[ $key ], 2 ); |
|
150 | + foreach ($format_decimal as $key) { |
|
151 | + $data[$key] = wc_format_decimal($data[$key], 2); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Format date values. |
155 | - foreach ( $format_date as $key ) { |
|
156 | - $datetime = $data[ $key ]; |
|
157 | - $data[ $key ] = wc_rest_prepare_date_response( $datetime, false ); |
|
158 | - $data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime ); |
|
155 | + foreach ($format_date as $key) { |
|
156 | + $datetime = $data[$key]; |
|
157 | + $data[$key] = wc_rest_prepare_date_response($datetime, false); |
|
158 | + $data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | // Format null values. |
162 | - foreach ( $format_null as $key ) { |
|
163 | - $data[ $key ] = $data[ $key ] ? $data[ $key ] : null; |
|
162 | + foreach ($format_null as $key) { |
|
163 | + $data[$key] = $data[$key] ? $data[$key] : null; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | return array( |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | * @param \WP_REST_Request $request Request object. |
203 | 203 | * @return \WP_REST_Response |
204 | 204 | */ |
205 | - public function prepare_object_for_response( $object, $request ) { |
|
206 | - $data = $this->get_formatted_item_data( $object ); |
|
207 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
208 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
209 | - $data = $this->filter_response_by_context( $data, $context ); |
|
210 | - $response = rest_ensure_response( $data ); |
|
211 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
205 | + public function prepare_object_for_response($object, $request) { |
|
206 | + $data = $this->get_formatted_item_data($object); |
|
207 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
208 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
209 | + $data = $this->filter_response_by_context($data, $context); |
|
210 | + $response = rest_ensure_response($data); |
|
211 | + $response->add_links($this->prepare_links($object, $request)); |
|
212 | 212 | |
213 | 213 | /** |
214 | 214 | * Filter the data for a response. |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param WC_Data $object Object data. |
221 | 221 | * @param \WP_REST_Request $request Request object. |
222 | 222 | */ |
223 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
223 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -230,15 +230,15 @@ discard block |
||
230 | 230 | * @param \WP_REST_Request $request Full details about the request. |
231 | 231 | * @return array |
232 | 232 | */ |
233 | - protected function prepare_objects_query( $request ) { |
|
234 | - $args = parent::prepare_objects_query( $request ); |
|
233 | + protected function prepare_objects_query($request) { |
|
234 | + $args = parent::prepare_objects_query($request); |
|
235 | 235 | |
236 | - if ( ! empty( $request['code'] ) ) { |
|
237 | - $id = wc_get_coupon_id_by_code( $request['code'] ); |
|
238 | - $args['post__in'] = array( $id ); |
|
236 | + if ( ! empty($request['code'])) { |
|
237 | + $id = wc_get_coupon_id_by_code($request['code']); |
|
238 | + $args['post__in'] = array($id); |
|
239 | 239 | } |
240 | 240 | |
241 | - if ( ! empty( $request['search'] ) ) { |
|
241 | + if ( ! empty($request['search'])) { |
|
242 | 242 | $args['search'] = $request['search']; |
243 | 243 | $args['s'] = false; |
244 | 244 | } |
@@ -253,47 +253,47 @@ discard block |
||
253 | 253 | * @param bool $creating If is creating a new object. |
254 | 254 | * @return \WP_Error|WC_Data |
255 | 255 | */ |
256 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
257 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
258 | - $coupon = new \WC_Coupon( $id ); |
|
256 | + protected function prepare_object_for_database($request, $creating = false) { |
|
257 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
258 | + $coupon = new \WC_Coupon($id); |
|
259 | 259 | $schema = $this->get_item_schema(); |
260 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
260 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
261 | 261 | |
262 | 262 | // Validate required POST fields. |
263 | - if ( $creating && empty( $request['code'] ) ) { |
|
264 | - return new \WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) ); |
|
263 | + if ($creating && empty($request['code'])) { |
|
264 | + return new \WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400)); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Handle all writable props. |
268 | - foreach ( $data_keys as $key ) { |
|
269 | - $value = $request[ $key ]; |
|
268 | + foreach ($data_keys as $key) { |
|
269 | + $value = $request[$key]; |
|
270 | 270 | |
271 | - if ( ! is_null( $value ) ) { |
|
272 | - switch ( $key ) { |
|
271 | + if ( ! is_null($value)) { |
|
272 | + switch ($key) { |
|
273 | 273 | case 'code': |
274 | - $coupon_code = wc_format_coupon_code( $value ); |
|
274 | + $coupon_code = wc_format_coupon_code($value); |
|
275 | 275 | $id = $coupon->get_id() ? $coupon->get_id() : 0; |
276 | - $id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id ); |
|
276 | + $id_from_code = wc_get_coupon_id_by_code($coupon_code, $id); |
|
277 | 277 | |
278 | - if ( $id_from_code ) { |
|
279 | - return new \WP_Error( 'woocommerce_rest_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce' ), array( 'status' => 400 ) ); |
|
278 | + if ($id_from_code) { |
|
279 | + return new \WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400)); |
|
280 | 280 | } |
281 | 281 | |
282 | - $coupon->set_code( $coupon_code ); |
|
282 | + $coupon->set_code($coupon_code); |
|
283 | 283 | break; |
284 | 284 | case 'meta_data': |
285 | - if ( is_array( $value ) ) { |
|
286 | - foreach ( $value as $meta ) { |
|
287 | - $coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
285 | + if (is_array($value)) { |
|
286 | + foreach ($value as $meta) { |
|
287 | + $coupon->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | break; |
291 | 291 | case 'description': |
292 | - $coupon->set_description( wp_filter_post_kses( $value ) ); |
|
292 | + $coupon->set_description(wp_filter_post_kses($value)); |
|
293 | 293 | break; |
294 | 294 | default: |
295 | - if ( is_callable( array( $coupon, "set_{$key}" ) ) ) { |
|
296 | - $coupon->{"set_{$key}"}( $value ); |
|
295 | + if (is_callable(array($coupon, "set_{$key}"))) { |
|
296 | + $coupon->{"set_{$key}"}($value); |
|
297 | 297 | } |
298 | 298 | break; |
299 | 299 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * @param \WP_REST_Request $request Request object. |
311 | 311 | * @param bool $creating If is creating a new object. |
312 | 312 | */ |
313 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating ); |
|
313 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -325,194 +325,194 @@ discard block |
||
325 | 325 | 'type' => 'object', |
326 | 326 | 'properties' => array( |
327 | 327 | 'id' => array( |
328 | - 'description' => __( 'Unique identifier for the object.', 'woocommerce' ), |
|
328 | + 'description' => __('Unique identifier for the object.', 'woocommerce'), |
|
329 | 329 | 'type' => 'integer', |
330 | - 'context' => array( 'view', 'edit' ), |
|
330 | + 'context' => array('view', 'edit'), |
|
331 | 331 | 'readonly' => true, |
332 | 332 | ), |
333 | 333 | 'code' => array( |
334 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
334 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
335 | 335 | 'type' => 'string', |
336 | - 'context' => array( 'view', 'edit' ), |
|
336 | + 'context' => array('view', 'edit'), |
|
337 | 337 | ), |
338 | 338 | 'amount' => array( |
339 | - 'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce' ), |
|
339 | + 'description' => __('The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce'), |
|
340 | 340 | 'type' => 'string', |
341 | - 'context' => array( 'view', 'edit' ), |
|
341 | + 'context' => array('view', 'edit'), |
|
342 | 342 | ), |
343 | 343 | 'date_created' => array( |
344 | - 'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce' ), |
|
344 | + 'description' => __("The date the coupon was created, in the site's timezone.", 'woocommerce'), |
|
345 | 345 | 'type' => 'date-time', |
346 | - 'context' => array( 'view', 'edit' ), |
|
346 | + 'context' => array('view', 'edit'), |
|
347 | 347 | 'readonly' => true, |
348 | 348 | ), |
349 | 349 | 'date_created_gmt' => array( |
350 | - 'description' => __( 'The date the coupon was created, as GMT.', 'woocommerce' ), |
|
350 | + 'description' => __('The date the coupon was created, as GMT.', 'woocommerce'), |
|
351 | 351 | 'type' => 'date-time', |
352 | - 'context' => array( 'view', 'edit' ), |
|
352 | + 'context' => array('view', 'edit'), |
|
353 | 353 | 'readonly' => true, |
354 | 354 | ), |
355 | 355 | 'date_modified' => array( |
356 | - 'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce' ), |
|
356 | + 'description' => __("The date the coupon was last modified, in the site's timezone.", 'woocommerce'), |
|
357 | 357 | 'type' => 'date-time', |
358 | - 'context' => array( 'view', 'edit' ), |
|
358 | + 'context' => array('view', 'edit'), |
|
359 | 359 | 'readonly' => true, |
360 | 360 | ), |
361 | 361 | 'date_modified_gmt' => array( |
362 | - 'description' => __( 'The date the coupon was last modified, as GMT.', 'woocommerce' ), |
|
362 | + 'description' => __('The date the coupon was last modified, as GMT.', 'woocommerce'), |
|
363 | 363 | 'type' => 'date-time', |
364 | - 'context' => array( 'view', 'edit' ), |
|
364 | + 'context' => array('view', 'edit'), |
|
365 | 365 | 'readonly' => true, |
366 | 366 | ), |
367 | 367 | 'discount_type' => array( |
368 | - 'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ), |
|
368 | + 'description' => __('Determines the type of discount that will be applied.', 'woocommerce'), |
|
369 | 369 | 'type' => 'string', |
370 | 370 | 'default' => 'fixed_cart', |
371 | - 'enum' => array_keys( wc_get_coupon_types() ), |
|
372 | - 'context' => array( 'view', 'edit' ), |
|
371 | + 'enum' => array_keys(wc_get_coupon_types()), |
|
372 | + 'context' => array('view', 'edit'), |
|
373 | 373 | ), |
374 | 374 | 'description' => array( |
375 | - 'description' => __( 'Coupon description.', 'woocommerce' ), |
|
375 | + 'description' => __('Coupon description.', 'woocommerce'), |
|
376 | 376 | 'type' => 'string', |
377 | - 'context' => array( 'view', 'edit' ), |
|
377 | + 'context' => array('view', 'edit'), |
|
378 | 378 | ), |
379 | 379 | 'date_expires' => array( |
380 | - 'description' => __( "The date the coupon expires, in the site's timezone.", 'woocommerce' ), |
|
380 | + 'description' => __("The date the coupon expires, in the site's timezone.", 'woocommerce'), |
|
381 | 381 | 'type' => 'string', |
382 | - 'context' => array( 'view', 'edit' ), |
|
382 | + 'context' => array('view', 'edit'), |
|
383 | 383 | ), |
384 | 384 | 'date_expires_gmt' => array( |
385 | - 'description' => __( 'The date the coupon expires, as GMT.', 'woocommerce' ), |
|
385 | + 'description' => __('The date the coupon expires, as GMT.', 'woocommerce'), |
|
386 | 386 | 'type' => 'string', |
387 | - 'context' => array( 'view', 'edit' ), |
|
387 | + 'context' => array('view', 'edit'), |
|
388 | 388 | ), |
389 | 389 | 'usage_count' => array( |
390 | - 'description' => __( 'Number of times the coupon has been used already.', 'woocommerce' ), |
|
390 | + 'description' => __('Number of times the coupon has been used already.', 'woocommerce'), |
|
391 | 391 | 'type' => 'integer', |
392 | - 'context' => array( 'view', 'edit' ), |
|
392 | + 'context' => array('view', 'edit'), |
|
393 | 393 | 'readonly' => true, |
394 | 394 | ), |
395 | 395 | 'individual_use' => array( |
396 | - 'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce' ), |
|
396 | + 'description' => __('If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce'), |
|
397 | 397 | 'type' => 'boolean', |
398 | 398 | 'default' => false, |
399 | - 'context' => array( 'view', 'edit' ), |
|
399 | + 'context' => array('view', 'edit'), |
|
400 | 400 | ), |
401 | 401 | 'product_ids' => array( |
402 | - 'description' => __( 'List of product IDs the coupon can be used on.', 'woocommerce' ), |
|
402 | + 'description' => __('List of product IDs the coupon can be used on.', 'woocommerce'), |
|
403 | 403 | 'type' => 'array', |
404 | 404 | 'items' => array( |
405 | 405 | 'type' => 'integer', |
406 | 406 | ), |
407 | - 'context' => array( 'view', 'edit' ), |
|
407 | + 'context' => array('view', 'edit'), |
|
408 | 408 | ), |
409 | 409 | 'excluded_product_ids' => array( |
410 | - 'description' => __( 'List of product IDs the coupon cannot be used on.', 'woocommerce' ), |
|
410 | + 'description' => __('List of product IDs the coupon cannot be used on.', 'woocommerce'), |
|
411 | 411 | 'type' => 'array', |
412 | 412 | 'items' => array( |
413 | 413 | 'type' => 'integer', |
414 | 414 | ), |
415 | - 'context' => array( 'view', 'edit' ), |
|
415 | + 'context' => array('view', 'edit'), |
|
416 | 416 | ), |
417 | 417 | 'usage_limit' => array( |
418 | - 'description' => __( 'How many times the coupon can be used in total.', 'woocommerce' ), |
|
418 | + 'description' => __('How many times the coupon can be used in total.', 'woocommerce'), |
|
419 | 419 | 'type' => 'integer', |
420 | - 'context' => array( 'view', 'edit' ), |
|
420 | + 'context' => array('view', 'edit'), |
|
421 | 421 | ), |
422 | 422 | 'usage_limit_per_user' => array( |
423 | - 'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce' ), |
|
423 | + 'description' => __('How many times the coupon can be used per customer.', 'woocommerce'), |
|
424 | 424 | 'type' => 'integer', |
425 | - 'context' => array( 'view', 'edit' ), |
|
425 | + 'context' => array('view', 'edit'), |
|
426 | 426 | ), |
427 | 427 | 'limit_usage_to_x_items' => array( |
428 | - 'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'woocommerce' ), |
|
428 | + 'description' => __('Max number of items in the cart the coupon can be applied to.', 'woocommerce'), |
|
429 | 429 | 'type' => 'integer', |
430 | - 'context' => array( 'view', 'edit' ), |
|
430 | + 'context' => array('view', 'edit'), |
|
431 | 431 | ), |
432 | 432 | 'free_shipping' => array( |
433 | - 'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce' ), |
|
433 | + 'description' => __('If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce'), |
|
434 | 434 | 'type' => 'boolean', |
435 | 435 | 'default' => false, |
436 | - 'context' => array( 'view', 'edit' ), |
|
436 | + 'context' => array('view', 'edit'), |
|
437 | 437 | ), |
438 | 438 | 'product_categories' => array( |
439 | - 'description' => __( 'List of category IDs the coupon applies to.', 'woocommerce' ), |
|
439 | + 'description' => __('List of category IDs the coupon applies to.', 'woocommerce'), |
|
440 | 440 | 'type' => 'array', |
441 | 441 | 'items' => array( |
442 | 442 | 'type' => 'integer', |
443 | 443 | ), |
444 | - 'context' => array( 'view', 'edit' ), |
|
444 | + 'context' => array('view', 'edit'), |
|
445 | 445 | ), |
446 | 446 | 'excluded_product_categories' => array( |
447 | - 'description' => __( 'List of category IDs the coupon does not apply to.', 'woocommerce' ), |
|
447 | + 'description' => __('List of category IDs the coupon does not apply to.', 'woocommerce'), |
|
448 | 448 | 'type' => 'array', |
449 | 449 | 'items' => array( |
450 | 450 | 'type' => 'integer', |
451 | 451 | ), |
452 | - 'context' => array( 'view', 'edit' ), |
|
452 | + 'context' => array('view', 'edit'), |
|
453 | 453 | ), |
454 | 454 | 'exclude_sale_items' => array( |
455 | - 'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'woocommerce' ), |
|
455 | + 'description' => __('If true, this coupon will not be applied to items that have sale prices.', 'woocommerce'), |
|
456 | 456 | 'type' => 'boolean', |
457 | 457 | 'default' => false, |
458 | - 'context' => array( 'view', 'edit' ), |
|
458 | + 'context' => array('view', 'edit'), |
|
459 | 459 | ), |
460 | 460 | 'minimum_amount' => array( |
461 | - 'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce' ), |
|
461 | + 'description' => __('Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce'), |
|
462 | 462 | 'type' => 'string', |
463 | - 'context' => array( 'view', 'edit' ), |
|
463 | + 'context' => array('view', 'edit'), |
|
464 | 464 | ), |
465 | 465 | 'maximum_amount' => array( |
466 | - 'description' => __( 'Maximum order amount allowed when using the coupon.', 'woocommerce' ), |
|
466 | + 'description' => __('Maximum order amount allowed when using the coupon.', 'woocommerce'), |
|
467 | 467 | 'type' => 'string', |
468 | - 'context' => array( 'view', 'edit' ), |
|
468 | + 'context' => array('view', 'edit'), |
|
469 | 469 | ), |
470 | 470 | 'email_restrictions' => array( |
471 | - 'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ), |
|
471 | + 'description' => __('List of email addresses that can use this coupon.', 'woocommerce'), |
|
472 | 472 | 'type' => 'array', |
473 | 473 | 'items' => array( |
474 | 474 | 'type' => 'string', |
475 | 475 | ), |
476 | - 'context' => array( 'view', 'edit' ), |
|
476 | + 'context' => array('view', 'edit'), |
|
477 | 477 | ), |
478 | 478 | 'used_by' => array( |
479 | - 'description' => __( 'List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce' ), |
|
479 | + 'description' => __('List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce'), |
|
480 | 480 | 'type' => 'array', |
481 | 481 | 'items' => array( |
482 | 482 | 'type' => 'integer', |
483 | 483 | ), |
484 | - 'context' => array( 'view', 'edit' ), |
|
484 | + 'context' => array('view', 'edit'), |
|
485 | 485 | 'readonly' => true, |
486 | 486 | ), |
487 | 487 | 'meta_data' => array( |
488 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
488 | + 'description' => __('Meta data.', 'woocommerce'), |
|
489 | 489 | 'type' => 'array', |
490 | - 'context' => array( 'view', 'edit' ), |
|
490 | + 'context' => array('view', 'edit'), |
|
491 | 491 | 'items' => array( |
492 | 492 | 'type' => 'object', |
493 | 493 | 'properties' => array( |
494 | 494 | 'id' => array( |
495 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
495 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
496 | 496 | 'type' => 'integer', |
497 | - 'context' => array( 'view', 'edit' ), |
|
497 | + 'context' => array('view', 'edit'), |
|
498 | 498 | 'readonly' => true, |
499 | 499 | ), |
500 | 500 | 'key' => array( |
501 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
501 | + 'description' => __('Meta key.', 'woocommerce'), |
|
502 | 502 | 'type' => 'string', |
503 | - 'context' => array( 'view', 'edit' ), |
|
503 | + 'context' => array('view', 'edit'), |
|
504 | 504 | ), |
505 | 505 | 'value' => array( |
506 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
506 | + 'description' => __('Meta value.', 'woocommerce'), |
|
507 | 507 | 'type' => 'mixed', |
508 | - 'context' => array( 'view', 'edit' ), |
|
508 | + 'context' => array('view', 'edit'), |
|
509 | 509 | ), |
510 | 510 | ), |
511 | 511 | ), |
512 | 512 | ), |
513 | 513 | ), |
514 | 514 | ); |
515 | - return $this->add_additional_fields_schema( $schema ); |
|
515 | + return $this->add_additional_fields_schema($schema); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -524,14 +524,14 @@ discard block |
||
524 | 524 | $params = parent::get_collection_params(); |
525 | 525 | |
526 | 526 | $params['code'] = array( |
527 | - 'description' => __( 'Limit result set to resources with a specific code.', 'woocommerce' ), |
|
527 | + 'description' => __('Limit result set to resources with a specific code.', 'woocommerce'), |
|
528 | 528 | 'type' => 'string', |
529 | 529 | 'sanitize_callback' => 'sanitize_text_field', |
530 | 530 | 'validate_callback' => 'rest_validate_request_arg', |
531 | 531 | ); |
532 | 532 | |
533 | 533 | $params['search'] = array( |
534 | - 'description' => __( 'Limit results to coupons with codes matching a given string.', 'woocommerce' ), |
|
534 | + 'description' => __('Limit results to coupons with codes matching a given string.', 'woocommerce'), |
|
535 | 535 | 'type' => 'string', |
536 | 536 | 'validate_callback' => 'rest_validate_request_arg', |
537 | 537 | ); |
@@ -545,8 +545,8 @@ discard block |
||
545 | 545 | * @param array $schema Schema array. |
546 | 546 | * @return bool |
547 | 547 | */ |
548 | - protected function filter_writable_props( $schema ) { |
|
549 | - return empty( $schema['readonly'] ); |
|
548 | + protected function filter_writable_props($schema) { |
|
549 | + return empty($schema['readonly']); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
@@ -555,10 +555,10 @@ discard block |
||
555 | 555 | * @param \WP_REST_Request $request Full details about the request. |
556 | 556 | * @return \WP_Error\WP_REST_Response |
557 | 557 | */ |
558 | - public function get_items( $request ) { |
|
559 | - add_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10, 2 ); |
|
560 | - $response = parent::get_items( $request ); |
|
561 | - remove_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10 ); |
|
558 | + public function get_items($request) { |
|
559 | + add_filter('posts_where', array($this, 'add_wp_query_search_code_filter'), 10, 2); |
|
560 | + $response = parent::get_items($request); |
|
561 | + remove_filter('posts_where', array($this, 'add_wp_query_search_code_filter'), 10); |
|
562 | 562 | return $response; |
563 | 563 | } |
564 | 564 | |
@@ -569,12 +569,12 @@ discard block |
||
569 | 569 | * @param object $wp_query \WP_Query object. |
570 | 570 | * @return string |
571 | 571 | */ |
572 | - public function add_wp_query_search_code_filter( $where, $wp_query ) { |
|
572 | + public function add_wp_query_search_code_filter($where, $wp_query) { |
|
573 | 573 | global $wpdb; |
574 | 574 | |
575 | - $search = $wp_query->get( 'search' ); |
|
576 | - if ( $search ) { |
|
577 | - $search = $wpdb->esc_like( $search ); |
|
575 | + $search = $wp_query->get('search'); |
|
576 | + if ($search) { |
|
577 | + $search = $wpdb->esc_like($search); |
|
578 | 578 | $search = "'%" . $search . "%'"; |
579 | 579 | $where .= ' AND ' . $wpdb->posts . '.post_title LIKE ' . $search; |
580 | 580 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Order Notes controller class. |
@@ -40,29 +40,29 @@ discard block |
||
40 | 40 | array( |
41 | 41 | 'args' => array( |
42 | 42 | 'order_id' => array( |
43 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
43 | + 'description' => __('The order ID.', 'woocommerce'), |
|
44 | 44 | 'type' => 'integer', |
45 | 45 | ), |
46 | 46 | ), |
47 | 47 | array( |
48 | 48 | 'methods' => \WP_REST_Server::READABLE, |
49 | - 'callback' => array( $this, 'get_items' ), |
|
50 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
49 | + 'callback' => array($this, 'get_items'), |
|
50 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
51 | 51 | 'args' => $this->get_collection_params(), |
52 | 52 | ), |
53 | 53 | array( |
54 | 54 | 'methods' => \WP_REST_Server::CREATABLE, |
55 | - 'callback' => array( $this, 'create_item' ), |
|
56 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
57 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), array( |
|
55 | + 'callback' => array($this, 'create_item'), |
|
56 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
57 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), array( |
|
58 | 58 | 'note' => array( |
59 | 59 | 'type' => 'string', |
60 | - 'description' => __( 'Order note content.', 'woocommerce' ), |
|
60 | + 'description' => __('Order note content.', 'woocommerce'), |
|
61 | 61 | 'required' => true, |
62 | 62 | ), |
63 | - ) ), |
|
63 | + )), |
|
64 | 64 | ), |
65 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
65 | + 'schema' => array($this, 'get_public_item_schema'), |
|
66 | 66 | ), |
67 | 67 | true |
68 | 68 | ); |
@@ -73,35 +73,35 @@ discard block |
||
73 | 73 | 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 | 'order_id' => array( |
80 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
80 | + 'description' => __('The order ID.', 'woocommerce'), |
|
81 | 81 | 'type' => 'integer', |
82 | 82 | ), |
83 | 83 | ), |
84 | 84 | array( |
85 | 85 | 'methods' => \WP_REST_Server::READABLE, |
86 | - 'callback' => array( $this, 'get_item' ), |
|
87 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
86 | + 'callback' => array($this, 'get_item'), |
|
87 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
88 | 88 | 'args' => array( |
89 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
89 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | array( |
93 | 93 | 'methods' => \WP_REST_Server::DELETABLE, |
94 | - 'callback' => array( $this, 'delete_item' ), |
|
95 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
94 | + 'callback' => array($this, 'delete_item'), |
|
95 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
96 | 96 | 'args' => array( |
97 | 97 | 'force' => array( |
98 | 98 | 'default' => false, |
99 | 99 | 'type' => 'boolean', |
100 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
100 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
101 | 101 | ), |
102 | 102 | ), |
103 | 103 | ), |
104 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
104 | + 'schema' => array($this, 'get_public_item_schema'), |
|
105 | 105 | ), |
106 | 106 | true |
107 | 107 | ); |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * @param \WP_REST_Request $request Full details about the request. |
114 | 114 | * @return \WP_Error|boolean |
115 | 115 | */ |
116 | - public function get_items_permissions_check( $request ) { |
|
117 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) { |
|
118 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
116 | + public function get_items_permissions_check($request) { |
|
117 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) { |
|
118 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | return true; |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return bool|\WP_Error |
130 | 130 | */ |
131 | - public function create_item_permissions_check( $request ) { |
|
132 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) { |
|
133 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
131 | + public function create_item_permissions_check($request) { |
|
132 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) { |
|
133 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | return true; |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param \WP_REST_Request $request Full details about the request. |
143 | 143 | * @return \WP_Error|boolean |
144 | 144 | */ |
145 | - public function get_item_permissions_check( $request ) { |
|
146 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
145 | + public function get_item_permissions_check($request) { |
|
146 | + $order = wc_get_order((int) $request['order_id']); |
|
147 | 147 | |
148 | - if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'read', $order->get_id() ) ) { |
|
149 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
148 | + if ($order && ! wc_rest_check_post_permissions($this->post_type, 'read', $order->get_id())) { |
|
149 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | return true; |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @return bool|\WP_Error |
161 | 161 | */ |
162 | - public function delete_item_permissions_check( $request ) { |
|
163 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
162 | + public function delete_item_permissions_check($request) { |
|
163 | + $order = wc_get_order((int) $request['order_id']); |
|
164 | 164 | |
165 | - if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $order->get_id() ) ) { |
|
166 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
165 | + if ($order && ! wc_rest_check_post_permissions($this->post_type, 'delete', $order->get_id())) { |
|
166 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete 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 array|\WP_Error |
178 | 178 | */ |
179 | - public function get_items( $request ) { |
|
180 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
179 | + public function get_items($request) { |
|
180 | + $order = wc_get_order((int) $request['order_id']); |
|
181 | 181 | |
182 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
183 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
182 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
183 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | $args = array( |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | ); |
191 | 191 | |
192 | 192 | // Allow filter by order note type. |
193 | - if ( 'customer' === $request['type'] ) { |
|
193 | + if ('customer' === $request['type']) { |
|
194 | 194 | $args['meta_query'] = array( // WPCS: slow query ok. |
195 | 195 | array( |
196 | 196 | 'key' => 'is_customer_note', |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | 'compare' => '=', |
199 | 199 | ), |
200 | 200 | ); |
201 | - } elseif ( 'internal' === $request['type'] ) { |
|
201 | + } elseif ('internal' === $request['type']) { |
|
202 | 202 | $args['meta_query'] = array( // WPCS: slow query ok. |
203 | 203 | array( |
204 | 204 | 'key' => 'is_customer_note', |
@@ -207,20 +207,20 @@ discard block |
||
207 | 207 | ); |
208 | 208 | } |
209 | 209 | |
210 | - remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); |
|
210 | + remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1); |
|
211 | 211 | |
212 | - $notes = get_comments( $args ); |
|
212 | + $notes = get_comments($args); |
|
213 | 213 | |
214 | - add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); |
|
214 | + add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1); |
|
215 | 215 | |
216 | 216 | $data = array(); |
217 | - foreach ( $notes as $note ) { |
|
218 | - $order_note = $this->prepare_item_for_response( $note, $request ); |
|
219 | - $order_note = $this->prepare_response_for_collection( $order_note ); |
|
217 | + foreach ($notes as $note) { |
|
218 | + $order_note = $this->prepare_item_for_response($note, $request); |
|
219 | + $order_note = $this->prepare_response_for_collection($order_note); |
|
220 | 220 | $data[] = $order_note; |
221 | 221 | } |
222 | 222 | |
223 | - return rest_ensure_response( $data ); |
|
223 | + return rest_ensure_response($data); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -229,27 +229,27 @@ discard block |
||
229 | 229 | * @param \WP_REST_Request $request Full details about the request. |
230 | 230 | * @return \WP_Error\WP_REST_Response |
231 | 231 | */ |
232 | - public function create_item( $request ) { |
|
233 | - if ( ! empty( $request['id'] ) ) { |
|
232 | + public function create_item($request) { |
|
233 | + if ( ! empty($request['id'])) { |
|
234 | 234 | /* translators: %s: post type */ |
235 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
235 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
236 | 236 | } |
237 | 237 | |
238 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
238 | + $order = wc_get_order((int) $request['order_id']); |
|
239 | 239 | |
240 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
241 | - return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
240 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
241 | + return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | // Create the note. |
245 | - $note_id = $order->add_order_note( $request['note'], $request['customer_note'], $request['added_by_user'] ); |
|
245 | + $note_id = $order->add_order_note($request['note'], $request['customer_note'], $request['added_by_user']); |
|
246 | 246 | |
247 | - if ( ! $note_id ) { |
|
248 | - return new \WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
247 | + if ( ! $note_id) { |
|
248 | + return new \WP_Error('woocommerce_api_cannot_create_order_note', __('Cannot create order note, please try again.', 'woocommerce'), array('status' => 500)); |
|
249 | 249 | } |
250 | 250 | |
251 | - $note = get_comment( $note_id ); |
|
252 | - $this->update_additional_fields_for_object( $note, $request ); |
|
251 | + $note = get_comment($note_id); |
|
252 | + $this->update_additional_fields_for_object($note, $request); |
|
253 | 253 | |
254 | 254 | /** |
255 | 255 | * Fires after a order note is created or updated via the REST API. |
@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | * @param \WP_REST_Request $request Request object. |
259 | 259 | * @param boolean $creating True when creating item, false when updating. |
260 | 260 | */ |
261 | - do_action( 'woocommerce_rest_insert_order_note', $note, $request, true ); |
|
261 | + do_action('woocommerce_rest_insert_order_note', $note, $request, true); |
|
262 | 262 | |
263 | - $request->set_param( 'context', 'edit' ); |
|
264 | - $response = $this->prepare_item_for_response( $note, $request ); |
|
265 | - $response = rest_ensure_response( $response ); |
|
266 | - $response->set_status( 201 ); |
|
267 | - $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 ) ) ); |
|
263 | + $request->set_param('context', 'edit'); |
|
264 | + $response = $this->prepare_item_for_response($note, $request); |
|
265 | + $response = rest_ensure_response($response); |
|
266 | + $response->set_status(201); |
|
267 | + $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))); |
|
268 | 268 | |
269 | 269 | return $response; |
270 | 270 | } |
@@ -275,22 +275,22 @@ discard block |
||
275 | 275 | * @param \WP_REST_Request $request Full details about the request. |
276 | 276 | * @return \WP_Error\WP_REST_Response |
277 | 277 | */ |
278 | - public function get_item( $request ) { |
|
278 | + public function get_item($request) { |
|
279 | 279 | $id = (int) $request['id']; |
280 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
280 | + $order = wc_get_order((int) $request['order_id']); |
|
281 | 281 | |
282 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
283 | - return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
282 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
283 | + return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
284 | 284 | } |
285 | 285 | |
286 | - $note = get_comment( $id ); |
|
286 | + $note = get_comment($id); |
|
287 | 287 | |
288 | - if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { |
|
289 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
288 | + if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) { |
|
289 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
290 | 290 | } |
291 | 291 | |
292 | - $order_note = $this->prepare_item_for_response( $note, $request ); |
|
293 | - $response = rest_ensure_response( $order_note ); |
|
292 | + $order_note = $this->prepare_item_for_response($note, $request); |
|
293 | + $response = rest_ensure_response($order_note); |
|
294 | 294 | |
295 | 295 | return $response; |
296 | 296 | } |
@@ -301,33 +301,33 @@ discard block |
||
301 | 301 | * @param \WP_REST_Request $request Full details about the request. |
302 | 302 | * @return \WP_REST_Response|\WP_Error |
303 | 303 | */ |
304 | - public function delete_item( $request ) { |
|
304 | + public function delete_item($request) { |
|
305 | 305 | $id = (int) $request['id']; |
306 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
306 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
307 | 307 | |
308 | 308 | // We don't support trashing for this type, error out. |
309 | - if ( ! $force ) { |
|
310 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
309 | + if ( ! $force) { |
|
310 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
311 | 311 | } |
312 | 312 | |
313 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
313 | + $order = wc_get_order((int) $request['order_id']); |
|
314 | 314 | |
315 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
316 | - return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
315 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
316 | + return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
317 | 317 | } |
318 | 318 | |
319 | - $note = get_comment( $id ); |
|
319 | + $note = get_comment($id); |
|
320 | 320 | |
321 | - if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { |
|
322 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
321 | + if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) { |
|
322 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
323 | 323 | } |
324 | 324 | |
325 | - $request->set_param( 'context', 'edit' ); |
|
326 | - $previous = $this->prepare_item_for_response( $note, $request ); |
|
327 | - $result = wc_delete_order_note( $note->comment_ID ); |
|
325 | + $request->set_param('context', 'edit'); |
|
326 | + $previous = $this->prepare_item_for_response($note, $request); |
|
327 | + $result = wc_delete_order_note($note->comment_ID); |
|
328 | 328 | |
329 | - if ( ! $result ) { |
|
330 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), 'order_note' ), array( 'status' => 500 ) ); |
|
329 | + if ( ! $result) { |
|
330 | + return new \WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), 'order_note'), array('status' => 500)); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | $response = new \WP_REST_Response(); |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @param \WP_REST_Response $response The response data. |
346 | 346 | * @param \WP_REST_Request $request The request sent to the API. |
347 | 347 | */ |
348 | - do_action( 'woocommerce_rest_delete_order_note', $note, $response, $request ); |
|
348 | + do_action('woocommerce_rest_delete_order_note', $note, $response, $request); |
|
349 | 349 | |
350 | 350 | return $response; |
351 | 351 | } |
@@ -357,24 +357,24 @@ discard block |
||
357 | 357 | * @param \WP_REST_Request $request Request object. |
358 | 358 | * @return \WP_REST_Response $response Response data. |
359 | 359 | */ |
360 | - public function prepare_item_for_response( $note, $request ) { |
|
360 | + public function prepare_item_for_response($note, $request) { |
|
361 | 361 | $data = array( |
362 | 362 | 'id' => (int) $note->comment_ID, |
363 | - 'author' => __( 'WooCommerce', 'woocommerce' ) === $note->comment_author ? 'system' : $note->comment_author, |
|
364 | - 'date_created' => wc_rest_prepare_date_response( $note->comment_date ), |
|
365 | - 'date_created_gmt' => wc_rest_prepare_date_response( $note->comment_date_gmt ), |
|
363 | + 'author' => __('WooCommerce', 'woocommerce') === $note->comment_author ? 'system' : $note->comment_author, |
|
364 | + 'date_created' => wc_rest_prepare_date_response($note->comment_date), |
|
365 | + 'date_created_gmt' => wc_rest_prepare_date_response($note->comment_date_gmt), |
|
366 | 366 | 'note' => $note->comment_content, |
367 | - 'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ), |
|
367 | + 'customer_note' => (bool) get_comment_meta($note->comment_ID, 'is_customer_note', true), |
|
368 | 368 | ); |
369 | 369 | |
370 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
371 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
372 | - $data = $this->filter_response_by_context( $data, $context ); |
|
370 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
371 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
372 | + $data = $this->filter_response_by_context($data, $context); |
|
373 | 373 | |
374 | 374 | // Wrap the data in a response object. |
375 | - $response = rest_ensure_response( $data ); |
|
375 | + $response = rest_ensure_response($data); |
|
376 | 376 | |
377 | - $response->add_links( $this->prepare_links( $note ) ); |
|
377 | + $response->add_links($this->prepare_links($note)); |
|
378 | 378 | |
379 | 379 | /** |
380 | 380 | * Filter order note object returned from the REST API. |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @param WP_Comment $note Order note object used to create response. |
384 | 384 | * @param \WP_REST_Request $request Request object. |
385 | 385 | */ |
386 | - return apply_filters( 'woocommerce_rest_prepare_order_note', $response, $note, $request ); |
|
386 | + return apply_filters('woocommerce_rest_prepare_order_note', $response, $note, $request); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -392,18 +392,18 @@ discard block |
||
392 | 392 | * @param WP_Comment $note Delivery order_note object. |
393 | 393 | * @return array Links for the given order note. |
394 | 394 | */ |
395 | - protected function prepare_links( $note ) { |
|
395 | + protected function prepare_links($note) { |
|
396 | 396 | $order_id = (int) $note->comment_post_ID; |
397 | - $base = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base ); |
|
397 | + $base = str_replace('(?P<order_id>[\d]+)', $order_id, $this->rest_base); |
|
398 | 398 | $links = array( |
399 | 399 | 'self' => array( |
400 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $note->comment_ID ) ), |
|
400 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $note->comment_ID)), |
|
401 | 401 | ), |
402 | 402 | 'collection' => array( |
403 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
403 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
404 | 404 | ), |
405 | 405 | 'up' => array( |
406 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ), |
|
406 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order_id)), |
|
407 | 407 | ), |
408 | 408 | ); |
409 | 409 | |
@@ -422,50 +422,50 @@ discard block |
||
422 | 422 | 'type' => 'object', |
423 | 423 | 'properties' => array( |
424 | 424 | 'id' => array( |
425 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
425 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
426 | 426 | 'type' => 'integer', |
427 | - 'context' => array( 'view', 'edit' ), |
|
427 | + 'context' => array('view', 'edit'), |
|
428 | 428 | 'readonly' => true, |
429 | 429 | ), |
430 | 430 | 'author' => array( |
431 | - 'description' => __( 'Order note author.', 'woocommerce' ), |
|
431 | + 'description' => __('Order note author.', 'woocommerce'), |
|
432 | 432 | 'type' => 'string', |
433 | - 'context' => array( 'view', 'edit' ), |
|
433 | + 'context' => array('view', 'edit'), |
|
434 | 434 | 'readonly' => true, |
435 | 435 | ), |
436 | 436 | 'date_created' => array( |
437 | - 'description' => __( "The date the order note was created, in the site's timezone.", 'woocommerce' ), |
|
437 | + 'description' => __("The date the order note was created, in the site's timezone.", 'woocommerce'), |
|
438 | 438 | 'type' => 'date-time', |
439 | - 'context' => array( 'view', 'edit' ), |
|
439 | + 'context' => array('view', 'edit'), |
|
440 | 440 | 'readonly' => true, |
441 | 441 | ), |
442 | 442 | 'date_created_gmt' => array( |
443 | - 'description' => __( 'The date the order note was created, as GMT.', 'woocommerce' ), |
|
443 | + 'description' => __('The date the order note was created, as GMT.', 'woocommerce'), |
|
444 | 444 | 'type' => 'date-time', |
445 | - 'context' => array( 'view', 'edit' ), |
|
445 | + 'context' => array('view', 'edit'), |
|
446 | 446 | 'readonly' => true, |
447 | 447 | ), |
448 | 448 | 'note' => array( |
449 | - 'description' => __( 'Order note content.', 'woocommerce' ), |
|
449 | + 'description' => __('Order note content.', 'woocommerce'), |
|
450 | 450 | 'type' => 'string', |
451 | - 'context' => array( 'view', 'edit' ), |
|
451 | + 'context' => array('view', 'edit'), |
|
452 | 452 | ), |
453 | 453 | 'customer_note' => array( |
454 | - 'description' => __( 'If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce' ), |
|
454 | + 'description' => __('If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce'), |
|
455 | 455 | 'type' => 'boolean', |
456 | 456 | 'default' => false, |
457 | - 'context' => array( 'view', 'edit' ), |
|
457 | + 'context' => array('view', 'edit'), |
|
458 | 458 | ), |
459 | 459 | 'added_by_user' => array( |
460 | - 'description' => __( 'If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce' ), |
|
460 | + 'description' => __('If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce'), |
|
461 | 461 | 'type' => 'boolean', |
462 | 462 | 'default' => false, |
463 | - 'context' => array( 'edit' ), |
|
463 | + 'context' => array('edit'), |
|
464 | 464 | ), |
465 | 465 | ), |
466 | 466 | ); |
467 | 467 | |
468 | - return $this->add_additional_fields_schema( $schema ); |
|
468 | + return $this->add_additional_fields_schema($schema); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
@@ -475,12 +475,12 @@ discard block |
||
475 | 475 | */ |
476 | 476 | public function get_collection_params() { |
477 | 477 | $params = array(); |
478 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
478 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
479 | 479 | $params['type'] = array( |
480 | 480 | 'default' => 'any', |
481 | - 'description' => __( 'Limit result to customers or internal notes.', 'woocommerce' ), |
|
481 | + 'description' => __('Limit result to customers or internal notes.', 'woocommerce'), |
|
482 | 482 | 'type' => 'string', |
483 | - 'enum' => array( 'any', 'customer', 'internal' ), |
|
483 | + 'enum' => array('any', 'customer', 'internal'), |
|
484 | 484 | 'sanitize_callback' => 'sanitize_key', |
485 | 485 | 'validate_callback' => 'rest_validate_request_arg', |
486 | 486 | ); |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Customer Downloads controller class. |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | array( |
34 | 34 | 'args' => array( |
35 | 35 | 'customer_id' => array( |
36 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
36 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
37 | 37 | 'type' => 'integer', |
38 | 38 | ), |
39 | 39 | ), |
40 | 40 | array( |
41 | 41 | 'methods' => \WP_REST_Server::READABLE, |
42 | - 'callback' => array( $this, 'get_items' ), |
|
43 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
42 | + 'callback' => array($this, 'get_items'), |
|
43 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
44 | 44 | 'args' => $this->get_collection_params(), |
45 | 45 | ), |
46 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
46 | + 'schema' => array($this, 'get_public_item_schema'), |
|
47 | 47 | ), |
48 | 48 | true |
49 | 49 | ); |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | * @param \WP_REST_Request $request Full details about the request. |
56 | 56 | * @return \WP_Error|boolean |
57 | 57 | */ |
58 | - public function get_items_permissions_check( $request ) { |
|
59 | - $customer = get_user_by( 'id', (int) $request['customer_id'] ); |
|
58 | + public function get_items_permissions_check($request) { |
|
59 | + $customer = get_user_by('id', (int) $request['customer_id']); |
|
60 | 60 | |
61 | - if ( ! $customer ) { |
|
62 | - return new \WP_Error( 'woocommerce_rest_customer_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
61 | + if ( ! $customer) { |
|
62 | + return new \WP_Error('woocommerce_rest_customer_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
63 | 63 | } |
64 | 64 | |
65 | - if ( ! wc_rest_check_user_permissions( 'read', $customer->get_id() ) ) { |
|
66 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
65 | + if ( ! wc_rest_check_user_permissions('read', $customer->get_id())) { |
|
66 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | return true; |
@@ -75,17 +75,17 @@ discard block |
||
75 | 75 | * @param \WP_REST_Request $request Request params. |
76 | 76 | * @return array |
77 | 77 | */ |
78 | - public function get_items( $request ) { |
|
79 | - $downloads = wc_get_customer_available_downloads( (int) $request['customer_id'] ); |
|
78 | + public function get_items($request) { |
|
79 | + $downloads = wc_get_customer_available_downloads((int) $request['customer_id']); |
|
80 | 80 | |
81 | 81 | $data = array(); |
82 | - foreach ( $downloads as $download_data ) { |
|
83 | - $download = $this->prepare_item_for_response( (object) $download_data, $request ); |
|
84 | - $download = $this->prepare_response_for_collection( $download ); |
|
82 | + foreach ($downloads as $download_data) { |
|
83 | + $download = $this->prepare_item_for_response((object) $download_data, $request); |
|
84 | + $download = $this->prepare_response_for_collection($download); |
|
85 | 85 | $data[] = $download; |
86 | 86 | } |
87 | 87 | |
88 | - return rest_ensure_response( $data ); |
|
88 | + return rest_ensure_response($data); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param \WP_REST_Request $request Request object. |
96 | 96 | * @return \WP_REST_Response $response Response data. |
97 | 97 | */ |
98 | - public function prepare_item_for_response( $download, $request ) { |
|
98 | + public function prepare_item_for_response($download, $request) { |
|
99 | 99 | $data = array( |
100 | 100 | 'download_id' => $download->download_id, |
101 | 101 | 'download_url' => $download->download_url, |
@@ -105,19 +105,19 @@ discard block |
||
105 | 105 | 'order_id' => $download->order_id, |
106 | 106 | 'order_key' => $download->order_key, |
107 | 107 | 'downloads_remaining' => '' === $download->downloads_remaining ? 'unlimited' : $download->downloads_remaining, |
108 | - 'access_expires' => $download->access_expires ? wc_rest_prepare_date_response( $download->access_expires ) : 'never', |
|
109 | - 'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response( get_gmt_from_date( $download->access_expires ) ) : 'never', |
|
108 | + 'access_expires' => $download->access_expires ? wc_rest_prepare_date_response($download->access_expires) : 'never', |
|
109 | + 'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response(get_gmt_from_date($download->access_expires)) : 'never', |
|
110 | 110 | 'file' => $download->file, |
111 | 111 | ); |
112 | 112 | |
113 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
114 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
115 | - $data = $this->filter_response_by_context( $data, $context ); |
|
113 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
114 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
115 | + $data = $this->filter_response_by_context($data, $context); |
|
116 | 116 | |
117 | 117 | // Wrap the data in a response object. |
118 | - $response = rest_ensure_response( $data ); |
|
118 | + $response = rest_ensure_response($data); |
|
119 | 119 | |
120 | - $response->add_links( $this->prepare_links( $download, $request ) ); |
|
120 | + $response->add_links($this->prepare_links($download, $request)); |
|
121 | 121 | |
122 | 122 | /** |
123 | 123 | * Filter customer download data returned from the REST API. |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param stdClass $download Download object used to create response. |
127 | 127 | * @param \WP_REST_Request $request Request object. |
128 | 128 | */ |
129 | - return apply_filters( 'woocommerce_rest_prepare_customer_download', $response, $download, $request ); |
|
129 | + return apply_filters('woocommerce_rest_prepare_customer_download', $response, $download, $request); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -136,17 +136,17 @@ discard block |
||
136 | 136 | * @param \WP_REST_Request $request Request object. |
137 | 137 | * @return array Links for the given customer download. |
138 | 138 | */ |
139 | - protected function prepare_links( $download, $request ) { |
|
140 | - $base = str_replace( '(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base ); |
|
139 | + protected function prepare_links($download, $request) { |
|
140 | + $base = str_replace('(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base); |
|
141 | 141 | $links = array( |
142 | 142 | 'collection' => array( |
143 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
143 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
144 | 144 | ), |
145 | 145 | 'product' => array( |
146 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $download->product_id ) ), |
|
146 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $download->product_id)), |
|
147 | 147 | ), |
148 | 148 | 'order' => array( |
149 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $download->order_id ) ), |
|
149 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $download->order_id)), |
|
150 | 150 | ), |
151 | 151 | ); |
152 | 152 | |
@@ -165,81 +165,81 @@ discard block |
||
165 | 165 | 'type' => 'object', |
166 | 166 | 'properties' => array( |
167 | 167 | 'download_id' => array( |
168 | - 'description' => __( 'Download ID.', 'woocommerce' ), |
|
168 | + 'description' => __('Download ID.', 'woocommerce'), |
|
169 | 169 | 'type' => 'string', |
170 | - 'context' => array( 'view' ), |
|
170 | + 'context' => array('view'), |
|
171 | 171 | 'readonly' => true, |
172 | 172 | ), |
173 | 173 | 'download_url' => array( |
174 | - 'description' => __( 'Download file URL.', 'woocommerce' ), |
|
174 | + 'description' => __('Download file URL.', 'woocommerce'), |
|
175 | 175 | 'type' => 'string', |
176 | - 'context' => array( 'view' ), |
|
176 | + 'context' => array('view'), |
|
177 | 177 | 'readonly' => true, |
178 | 178 | ), |
179 | 179 | 'product_id' => array( |
180 | - 'description' => __( 'Downloadable product ID.', 'woocommerce' ), |
|
180 | + 'description' => __('Downloadable product ID.', 'woocommerce'), |
|
181 | 181 | 'type' => 'integer', |
182 | - 'context' => array( 'view' ), |
|
182 | + 'context' => array('view'), |
|
183 | 183 | 'readonly' => true, |
184 | 184 | ), |
185 | 185 | 'product_name' => array( |
186 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
186 | + 'description' => __('Product name.', 'woocommerce'), |
|
187 | 187 | 'type' => 'string', |
188 | - 'context' => array( 'view' ), |
|
188 | + 'context' => array('view'), |
|
189 | 189 | 'readonly' => true, |
190 | 190 | ), |
191 | 191 | 'download_name' => array( |
192 | - 'description' => __( 'Downloadable file name.', 'woocommerce' ), |
|
192 | + 'description' => __('Downloadable file name.', 'woocommerce'), |
|
193 | 193 | 'type' => 'string', |
194 | - 'context' => array( 'view' ), |
|
194 | + 'context' => array('view'), |
|
195 | 195 | 'readonly' => true, |
196 | 196 | ), |
197 | 197 | 'order_id' => array( |
198 | - 'description' => __( 'Order ID.', 'woocommerce' ), |
|
198 | + 'description' => __('Order ID.', 'woocommerce'), |
|
199 | 199 | 'type' => 'integer', |
200 | - 'context' => array( 'view' ), |
|
200 | + 'context' => array('view'), |
|
201 | 201 | 'readonly' => true, |
202 | 202 | ), |
203 | 203 | 'order_key' => array( |
204 | - 'description' => __( 'Order key.', 'woocommerce' ), |
|
204 | + 'description' => __('Order key.', 'woocommerce'), |
|
205 | 205 | 'type' => 'string', |
206 | - 'context' => array( 'view' ), |
|
206 | + 'context' => array('view'), |
|
207 | 207 | 'readonly' => true, |
208 | 208 | ), |
209 | 209 | 'downloads_remaining' => array( |
210 | - 'description' => __( 'Number of downloads remaining.', 'woocommerce' ), |
|
210 | + 'description' => __('Number of downloads remaining.', 'woocommerce'), |
|
211 | 211 | 'type' => 'string', |
212 | - 'context' => array( 'view' ), |
|
212 | + 'context' => array('view'), |
|
213 | 213 | 'readonly' => true, |
214 | 214 | ), |
215 | 215 | 'access_expires' => array( |
216 | - 'description' => __( "The date when download access expires, in the site's timezone.", 'woocommerce' ), |
|
216 | + 'description' => __("The date when download access expires, in the site's timezone.", 'woocommerce'), |
|
217 | 217 | 'type' => 'string', |
218 | - 'context' => array( 'view' ), |
|
218 | + 'context' => array('view'), |
|
219 | 219 | 'readonly' => true, |
220 | 220 | ), |
221 | 221 | 'access_expires_gmt' => array( |
222 | - 'description' => __( 'The date when download access expires, as GMT.', 'woocommerce' ), |
|
222 | + 'description' => __('The date when download access expires, as GMT.', 'woocommerce'), |
|
223 | 223 | 'type' => 'string', |
224 | - 'context' => array( 'view' ), |
|
224 | + 'context' => array('view'), |
|
225 | 225 | 'readonly' => true, |
226 | 226 | ), |
227 | 227 | 'file' => array( |
228 | - 'description' => __( 'File details.', 'woocommerce' ), |
|
228 | + 'description' => __('File details.', 'woocommerce'), |
|
229 | 229 | 'type' => 'object', |
230 | - 'context' => array( 'view' ), |
|
230 | + 'context' => array('view'), |
|
231 | 231 | 'readonly' => true, |
232 | 232 | 'properties' => array( |
233 | 233 | 'name' => array( |
234 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
234 | + 'description' => __('File name.', 'woocommerce'), |
|
235 | 235 | 'type' => 'string', |
236 | - 'context' => array( 'view' ), |
|
236 | + 'context' => array('view'), |
|
237 | 237 | 'readonly' => true, |
238 | 238 | ), |
239 | 239 | 'file' => array( |
240 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
240 | + 'description' => __('File URL.', 'woocommerce'), |
|
241 | 241 | 'type' => 'string', |
242 | - 'context' => array( 'view' ), |
|
242 | + 'context' => array('view'), |
|
243 | 243 | 'readonly' => true, |
244 | 244 | ), |
245 | 245 | ), |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | ), |
248 | 248 | ); |
249 | 249 | |
250 | - return $this->add_additional_fields_schema( $schema ); |
|
250 | + return $this->add_additional_fields_schema($schema); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function get_collection_params() { |
259 | 259 | return array( |
260 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
260 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
261 | 261 | ); |
262 | 262 | } |
263 | 263 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Settings controller class. |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | array( |
36 | 36 | array( |
37 | 37 | 'methods' => \WP_REST_Server::READABLE, |
38 | - 'callback' => array( $this, 'get_items' ), |
|
39 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
38 | + 'callback' => array($this, 'get_items'), |
|
39 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
40 | 40 | ), |
41 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
41 | + 'schema' => array($this, 'get_public_item_schema'), |
|
42 | 42 | ), |
43 | 43 | true |
44 | 44 | ); |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | array( |
49 | 49 | array( |
50 | 50 | 'methods' => \WP_REST_Server::EDITABLE, |
51 | - 'callback' => array( $this, 'batch_items' ), |
|
52 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
51 | + 'callback' => array($this, 'batch_items'), |
|
52 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
53 | 53 | ), |
54 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
54 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
55 | 55 | ), |
56 | 56 | true |
57 | 57 | ); |
@@ -63,9 +63,9 @@ discard block |
||
63 | 63 | * @param \WP_REST_Request $request Full data about the request. |
64 | 64 | * @return \WP_Error|bool |
65 | 65 | */ |
66 | - public function update_items_permissions_check( $request ) { |
|
67 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
68 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
66 | + public function update_items_permissions_check($request) { |
|
67 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
68 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | return true; |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * @param \WP_REST_Request $request Request data. |
78 | 78 | * @return \WP_Error\WP_REST_Response |
79 | 79 | */ |
80 | - public function update_item( $request ) { |
|
80 | + public function update_item($request) { |
|
81 | 81 | $options_controller = new \WC_REST_Setting_Options_Controller(); |
82 | - $response = $options_controller->update_item( $request ); |
|
82 | + $response = $options_controller->update_item($request); |
|
83 | 83 | |
84 | 84 | return $response; |
85 | 85 | } |
@@ -91,34 +91,34 @@ discard block |
||
91 | 91 | * @param \WP_REST_Request $request Request data. |
92 | 92 | * @return \WP_Error\WP_REST_Response |
93 | 93 | */ |
94 | - public function get_items( $request ) { |
|
95 | - $groups = apply_filters( 'woocommerce_settings_groups', array() ); |
|
96 | - if ( empty( $groups ) ) { |
|
97 | - return new \WP_Error( 'rest_setting_groups_empty', __( 'No setting groups have been registered.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
94 | + public function get_items($request) { |
|
95 | + $groups = apply_filters('woocommerce_settings_groups', array()); |
|
96 | + if (empty($groups)) { |
|
97 | + return new \WP_Error('rest_setting_groups_empty', __('No setting groups have been registered.', 'woocommerce'), array('status' => 500)); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | $defaults = $this->group_defaults(); |
101 | 101 | $filtered_groups = array(); |
102 | - foreach ( $groups as $group ) { |
|
102 | + foreach ($groups as $group) { |
|
103 | 103 | $sub_groups = array(); |
104 | - foreach ( $groups as $_group ) { |
|
105 | - if ( ! empty( $_group['parent_id'] ) && $group['id'] === $_group['parent_id'] ) { |
|
104 | + foreach ($groups as $_group) { |
|
105 | + if ( ! empty($_group['parent_id']) && $group['id'] === $_group['parent_id']) { |
|
106 | 106 | $sub_groups[] = $_group['id']; |
107 | 107 | } |
108 | 108 | } |
109 | 109 | $group['sub_groups'] = $sub_groups; |
110 | 110 | |
111 | - $group = wp_parse_args( $group, $defaults ); |
|
112 | - if ( ! is_null( $group['id'] ) && ! is_null( $group['label'] ) ) { |
|
113 | - $group_obj = $this->filter_group( $group ); |
|
114 | - $group_data = $this->prepare_item_for_response( $group_obj, $request ); |
|
115 | - $group_data = $this->prepare_response_for_collection( $group_data ); |
|
111 | + $group = wp_parse_args($group, $defaults); |
|
112 | + if ( ! is_null($group['id']) && ! is_null($group['label'])) { |
|
113 | + $group_obj = $this->filter_group($group); |
|
114 | + $group_data = $this->prepare_item_for_response($group_obj, $request); |
|
115 | + $group_data = $this->prepare_response_for_collection($group_data); |
|
116 | 116 | |
117 | 117 | $filtered_groups[] = $group_data; |
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | - $response = rest_ensure_response( $filtered_groups ); |
|
121 | + $response = rest_ensure_response($filtered_groups); |
|
122 | 122 | return $response; |
123 | 123 | } |
124 | 124 | |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | * @param string $group_id Group ID. |
129 | 129 | * @return array Links for the given group. |
130 | 130 | */ |
131 | - protected function prepare_links( $group_id ) { |
|
131 | + protected function prepare_links($group_id) { |
|
132 | 132 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
133 | 133 | $links = array( |
134 | 134 | 'options' => array( |
135 | - 'href' => rest_url( trailingslashit( $base ) . $group_id ), |
|
135 | + 'href' => rest_url(trailingslashit($base) . $group_id), |
|
136 | 136 | ), |
137 | 137 | ); |
138 | 138 | |
@@ -147,14 +147,14 @@ discard block |
||
147 | 147 | * @param \WP_REST_Request $request Request object. |
148 | 148 | * @return \WP_REST_Response $response Response data. |
149 | 149 | */ |
150 | - public function prepare_item_for_response( $item, $request ) { |
|
151 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
152 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
153 | - $data = $this->filter_response_by_context( $data, $context ); |
|
150 | + public function prepare_item_for_response($item, $request) { |
|
151 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
152 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
153 | + $data = $this->filter_response_by_context($data, $context); |
|
154 | 154 | |
155 | - $response = rest_ensure_response( $data ); |
|
155 | + $response = rest_ensure_response($data); |
|
156 | 156 | |
157 | - $response->add_links( $this->prepare_links( $item['id'] ) ); |
|
157 | + $response->add_links($this->prepare_links($item['id'])); |
|
158 | 158 | |
159 | 159 | return $response; |
160 | 160 | } |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | * @param array $group Group. |
168 | 168 | * @return array |
169 | 169 | */ |
170 | - public function filter_group( $group ) { |
|
170 | + public function filter_group($group) { |
|
171 | 171 | return array_intersect_key( |
172 | 172 | $group, |
173 | - array_flip( array_filter( array_keys( $group ), array( $this, 'allowed_group_keys' ) ) ) |
|
173 | + array_flip(array_filter(array_keys($group), array($this, 'allowed_group_keys'))) |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param string $key Key to check. |
182 | 182 | * @return boolean |
183 | 183 | */ |
184 | - public function allowed_group_keys( $key ) { |
|
185 | - return in_array( $key, array( 'id', 'label', 'description', 'parent_id', 'sub_groups' ) ); |
|
184 | + public function allowed_group_keys($key) { |
|
185 | + return in_array($key, array('id', 'label', 'description', 'parent_id', 'sub_groups')); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | * @param \WP_REST_Request $request Full data about the request. |
209 | 209 | * @return \WP_Error|boolean |
210 | 210 | */ |
211 | - public function get_items_permissions_check( $request ) { |
|
212 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
213 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
211 | + public function get_items_permissions_check($request) { |
|
212 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
213 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return true; |
@@ -229,33 +229,33 @@ discard block |
||
229 | 229 | 'type' => 'object', |
230 | 230 | 'properties' => array( |
231 | 231 | 'id' => array( |
232 | - 'description' => __( 'A unique identifier that can be used to link settings together.', 'woocommerce' ), |
|
232 | + 'description' => __('A unique identifier that can be used to link settings together.', 'woocommerce'), |
|
233 | 233 | 'type' => 'string', |
234 | - 'context' => array( 'view', 'edit' ), |
|
234 | + 'context' => array('view', 'edit'), |
|
235 | 235 | ), |
236 | 236 | 'label' => array( |
237 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
237 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
238 | 238 | 'type' => 'string', |
239 | - 'context' => array( 'view', 'edit' ), |
|
239 | + 'context' => array('view', 'edit'), |
|
240 | 240 | ), |
241 | 241 | 'description' => array( |
242 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
242 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
243 | 243 | 'type' => 'string', |
244 | - 'context' => array( 'view', 'edit' ), |
|
244 | + 'context' => array('view', 'edit'), |
|
245 | 245 | ), |
246 | 246 | 'parent_id' => array( |
247 | - 'description' => __( 'ID of parent grouping.', 'woocommerce' ), |
|
247 | + 'description' => __('ID of parent grouping.', 'woocommerce'), |
|
248 | 248 | 'type' => 'string', |
249 | - 'context' => array( 'view', 'edit' ), |
|
249 | + 'context' => array('view', 'edit'), |
|
250 | 250 | ), |
251 | 251 | 'sub_groups' => array( |
252 | - 'description' => __( 'IDs for settings sub groups.', 'woocommerce' ), |
|
252 | + 'description' => __('IDs for settings sub groups.', 'woocommerce'), |
|
253 | 253 | 'type' => 'string', |
254 | - 'context' => array( 'view', 'edit' ), |
|
254 | + 'context' => array('view', 'edit'), |
|
255 | 255 | ), |
256 | 256 | ), |
257 | 257 | ); |
258 | 258 | |
259 | - return $this->add_additional_fields_schema( $schema ); |
|
259 | + return $this->add_additional_fields_schema($schema); |
|
260 | 260 | } |
261 | 261 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Shipping Zone Locations class. |
@@ -26,22 +26,22 @@ discard block |
||
26 | 26 | array( |
27 | 27 | 'args' => array( |
28 | 28 | 'id' => array( |
29 | - 'description' => __( 'Unique ID for the resource.', 'woocommerce' ), |
|
29 | + 'description' => __('Unique ID for the resource.', 'woocommerce'), |
|
30 | 30 | 'type' => 'integer', |
31 | 31 | ), |
32 | 32 | ), |
33 | 33 | array( |
34 | 34 | 'methods' => \WP_REST_Server::READABLE, |
35 | - 'callback' => array( $this, 'get_items' ), |
|
36 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
35 | + 'callback' => array($this, 'get_items'), |
|
36 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
37 | 37 | ), |
38 | 38 | array( |
39 | 39 | 'methods' => \WP_REST_Server::EDITABLE, |
40 | - 'callback' => array( $this, 'update_items' ), |
|
41 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
42 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
40 | + 'callback' => array($this, 'update_items'), |
|
41 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
42 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
43 | 43 | ), |
44 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
44 | + 'schema' => array($this, 'get_public_item_schema'), |
|
45 | 45 | ), |
46 | 46 | true |
47 | 47 | ); |
@@ -53,23 +53,23 @@ discard block |
||
53 | 53 | * @param \WP_REST_Request $request Request data. |
54 | 54 | * @return \WP_REST_Response|\WP_Error |
55 | 55 | */ |
56 | - public function get_items( $request ) { |
|
57 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
56 | + public function get_items($request) { |
|
57 | + $zone = $this->get_zone((int) $request['id']); |
|
58 | 58 | |
59 | - if ( is_wp_error( $zone ) ) { |
|
59 | + if (is_wp_error($zone)) { |
|
60 | 60 | return $zone; |
61 | 61 | } |
62 | 62 | |
63 | 63 | $locations = $zone->get_zone_locations(); |
64 | 64 | $data = array(); |
65 | 65 | |
66 | - foreach ( $locations as $location_obj ) { |
|
67 | - $location = $this->prepare_item_for_response( $location_obj, $request ); |
|
68 | - $location = $this->prepare_response_for_collection( $location ); |
|
66 | + foreach ($locations as $location_obj) { |
|
67 | + $location = $this->prepare_item_for_response($location_obj, $request); |
|
68 | + $location = $this->prepare_response_for_collection($location); |
|
69 | 69 | $data[] = $location; |
70 | 70 | } |
71 | 71 | |
72 | - return rest_ensure_response( $data ); |
|
72 | + return rest_ensure_response($data); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -78,41 +78,41 @@ discard block |
||
78 | 78 | * @param \WP_REST_Request $request Request data. |
79 | 79 | * @return \WP_REST_Response|\WP_Error |
80 | 80 | */ |
81 | - public function update_items( $request ) { |
|
82 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
81 | + public function update_items($request) { |
|
82 | + $zone = $this->get_zone((int) $request['id']); |
|
83 | 83 | |
84 | - if ( is_wp_error( $zone ) ) { |
|
84 | + if (is_wp_error($zone)) { |
|
85 | 85 | return $zone; |
86 | 86 | } |
87 | 87 | |
88 | - if ( 0 === $zone->get_id() ) { |
|
89 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_locations_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) ); |
|
88 | + if (0 === $zone->get_id()) { |
|
89 | + return new \WP_Error('woocommerce_rest_shipping_zone_locations_invalid_zone', __('The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce'), array('status' => 403)); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | $raw_locations = $request->get_json_params(); |
93 | 93 | $locations = array(); |
94 | 94 | |
95 | - foreach ( (array) $raw_locations as $raw_location ) { |
|
96 | - if ( empty( $raw_location['code'] ) ) { |
|
95 | + foreach ((array) $raw_locations as $raw_location) { |
|
96 | + if (empty($raw_location['code'])) { |
|
97 | 97 | continue; |
98 | 98 | } |
99 | 99 | |
100 | - $type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country'; |
|
100 | + $type = ! empty($raw_location['type']) ? sanitize_text_field($raw_location['type']) : 'country'; |
|
101 | 101 | |
102 | - if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) { |
|
102 | + if ( ! in_array($type, array('postcode', 'state', 'country', 'continent'), true)) { |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | |
106 | 106 | $locations[] = array( |
107 | - 'code' => sanitize_text_field( $raw_location['code'] ), |
|
108 | - 'type' => sanitize_text_field( $type ), |
|
107 | + 'code' => sanitize_text_field($raw_location['code']), |
|
108 | + 'type' => sanitize_text_field($type), |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
112 | - $zone->set_locations( $locations ); |
|
112 | + $zone->set_locations($locations); |
|
113 | 113 | $zone->save(); |
114 | 114 | |
115 | - return $this->get_items( $request ); |
|
115 | + return $this->get_items($request); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | * @param \WP_REST_Request $request Request object. |
123 | 123 | * @return \WP_REST_Response $response |
124 | 124 | */ |
125 | - public function prepare_item_for_response( $item, $request ) { |
|
126 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
127 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
128 | - $data = $this->filter_response_by_context( $data, $context ); |
|
125 | + public function prepare_item_for_response($item, $request) { |
|
126 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
127 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
128 | + $data = $this->filter_response_by_context($data, $context); |
|
129 | 129 | |
130 | 130 | // Wrap the data in a response object. |
131 | - $response = rest_ensure_response( $data ); |
|
131 | + $response = rest_ensure_response($data); |
|
132 | 132 | |
133 | - $response->add_links( $this->prepare_links( (int) $request['id'] ) ); |
|
133 | + $response->add_links($this->prepare_links((int) $request['id'])); |
|
134 | 134 | |
135 | 135 | return $response; |
136 | 136 | } |
@@ -141,14 +141,14 @@ discard block |
||
141 | 141 | * @param int $zone_id Given Shipping Zone ID. |
142 | 142 | * @return array Links for the given Shipping Zone Location. |
143 | 143 | */ |
144 | - protected function prepare_links( $zone_id ) { |
|
144 | + protected function prepare_links($zone_id) { |
|
145 | 145 | $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id; |
146 | 146 | $links = array( |
147 | 147 | 'collection' => array( |
148 | - 'href' => rest_url( $base . '/locations' ), |
|
148 | + 'href' => rest_url($base . '/locations'), |
|
149 | 149 | ), |
150 | 150 | 'describes' => array( |
151 | - 'href' => rest_url( $base ), |
|
151 | + 'href' => rest_url($base), |
|
152 | 152 | ), |
153 | 153 | ); |
154 | 154 | |
@@ -167,12 +167,12 @@ discard block |
||
167 | 167 | 'type' => 'object', |
168 | 168 | 'properties' => array( |
169 | 169 | 'code' => array( |
170 | - 'description' => __( 'Shipping zone location code.', 'woocommerce' ), |
|
170 | + 'description' => __('Shipping zone location code.', 'woocommerce'), |
|
171 | 171 | 'type' => 'string', |
172 | - 'context' => array( 'view', 'edit' ), |
|
172 | + 'context' => array('view', 'edit'), |
|
173 | 173 | ), |
174 | 174 | 'type' => array( |
175 | - 'description' => __( 'Shipping zone location type.', 'woocommerce' ), |
|
175 | + 'description' => __('Shipping zone location type.', 'woocommerce'), |
|
176 | 176 | 'type' => 'string', |
177 | 177 | 'default' => 'country', |
178 | 178 | 'enum' => array( |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | 'country', |
182 | 182 | 'continent', |
183 | 183 | ), |
184 | - 'context' => array( 'view', 'edit' ), |
|
184 | + 'context' => array('view', 'edit'), |
|
185 | 185 | ), |
186 | 186 | ), |
187 | 187 | ); |
188 | 188 | |
189 | - return $this->add_additional_fields_schema( $schema ); |
|
189 | + return $this->add_additional_fields_schema($schema); |
|
190 | 190 | } |
191 | 191 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Shipping Zones class. |
@@ -26,25 +26,25 @@ discard block |
||
26 | 26 | array( |
27 | 27 | array( |
28 | 28 | 'methods' => \WP_REST_Server::READABLE, |
29 | - 'callback' => array( $this, 'get_items' ), |
|
30 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
29 | + 'callback' => array($this, 'get_items'), |
|
30 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
31 | 31 | ), |
32 | 32 | array( |
33 | 33 | 'methods' => \WP_REST_Server::CREATABLE, |
34 | - 'callback' => array( $this, 'create_item' ), |
|
35 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
34 | + 'callback' => array($this, 'create_item'), |
|
35 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
36 | 36 | 'args' => array_merge( |
37 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
37 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
38 | 38 | array( |
39 | 39 | 'name' => array( |
40 | 40 | 'required' => true, |
41 | 41 | 'type' => 'string', |
42 | - 'description' => __( 'Shipping zone name.', 'woocommerce' ), |
|
42 | + 'description' => __('Shipping zone name.', 'woocommerce'), |
|
43 | 43 | ), |
44 | 44 | ) |
45 | 45 | ), |
46 | 46 | ), |
47 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
47 | + 'schema' => array($this, 'get_public_item_schema'), |
|
48 | 48 | ), |
49 | 49 | true |
50 | 50 | ); |
@@ -55,34 +55,34 @@ discard block |
||
55 | 55 | array( |
56 | 56 | 'args' => array( |
57 | 57 | 'id' => array( |
58 | - 'description' => __( 'Unique ID for the resource.', 'woocommerce' ), |
|
58 | + 'description' => __('Unique ID for the resource.', 'woocommerce'), |
|
59 | 59 | 'type' => 'integer', |
60 | 60 | ), |
61 | 61 | ), |
62 | 62 | array( |
63 | 63 | 'methods' => \WP_REST_Server::READABLE, |
64 | - 'callback' => array( $this, 'get_item' ), |
|
65 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
64 | + 'callback' => array($this, 'get_item'), |
|
65 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
66 | 66 | ), |
67 | 67 | array( |
68 | 68 | 'methods' => \WP_REST_Server::EDITABLE, |
69 | - 'callback' => array( $this, 'update_item' ), |
|
70 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
71 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
69 | + 'callback' => array($this, 'update_item'), |
|
70 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
71 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
72 | 72 | ), |
73 | 73 | array( |
74 | 74 | 'methods' => \WP_REST_Server::DELETABLE, |
75 | - 'callback' => array( $this, 'delete_item' ), |
|
76 | - 'permission_callback' => array( $this, 'delete_items_permissions_check' ), |
|
75 | + 'callback' => array($this, 'delete_item'), |
|
76 | + 'permission_callback' => array($this, 'delete_items_permissions_check'), |
|
77 | 77 | 'args' => array( |
78 | 78 | 'force' => array( |
79 | 79 | 'default' => false, |
80 | 80 | 'type' => 'boolean', |
81 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
81 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
82 | 82 | ), |
83 | 83 | ), |
84 | 84 | ), |
85 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
85 | + 'schema' => array($this, 'get_public_item_schema'), |
|
86 | 86 | ), |
87 | 87 | true |
88 | 88 | ); |
@@ -94,18 +94,18 @@ discard block |
||
94 | 94 | * @param \WP_REST_Request $request Request data. |
95 | 95 | * @return \WP_REST_Response|\WP_Error |
96 | 96 | */ |
97 | - public function get_item( $request ) { |
|
98 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
97 | + public function get_item($request) { |
|
98 | + $zone = $this->get_zone($request->get_param('id')); |
|
99 | 99 | |
100 | - if ( is_wp_error( $zone ) ) { |
|
100 | + if (is_wp_error($zone)) { |
|
101 | 101 | return $zone; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $data = $zone->get_data(); |
105 | - $data = $this->prepare_item_for_response( $data, $request ); |
|
106 | - $data = $this->prepare_response_for_collection( $data ); |
|
105 | + $data = $this->prepare_item_for_response($data, $request); |
|
106 | + $data = $this->prepare_response_for_collection($data); |
|
107 | 107 | |
108 | - return rest_ensure_response( $data ); |
|
108 | + return rest_ensure_response($data); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -114,20 +114,20 @@ discard block |
||
114 | 114 | * @param \WP_REST_Request $request Request data. |
115 | 115 | * @return \WP_REST_Response |
116 | 116 | */ |
117 | - public function get_items( $request ) { |
|
118 | - $rest_of_the_world = \WC_Shipping_Zones::get_zone_by( 'zone_id', 0 ); |
|
117 | + public function get_items($request) { |
|
118 | + $rest_of_the_world = \WC_Shipping_Zones::get_zone_by('zone_id', 0); |
|
119 | 119 | |
120 | 120 | $zones = \WC_Shipping_Zones::get_zones(); |
121 | - array_unshift( $zones, $rest_of_the_world->get_data() ); |
|
121 | + array_unshift($zones, $rest_of_the_world->get_data()); |
|
122 | 122 | $data = array(); |
123 | 123 | |
124 | - foreach ( $zones as $zone_obj ) { |
|
125 | - $zone = $this->prepare_item_for_response( $zone_obj, $request ); |
|
126 | - $zone = $this->prepare_response_for_collection( $zone ); |
|
124 | + foreach ($zones as $zone_obj) { |
|
125 | + $zone = $this->prepare_item_for_response($zone_obj, $request); |
|
126 | + $zone = $this->prepare_response_for_collection($zone); |
|
127 | 127 | $data[] = $zone; |
128 | 128 | } |
129 | 129 | |
130 | - return rest_ensure_response( $data ); |
|
130 | + return rest_ensure_response($data); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -136,27 +136,27 @@ discard block |
||
136 | 136 | * @param \WP_REST_Request $request Full details about the request. |
137 | 137 | * @return \WP_REST_Request|\WP_Error |
138 | 138 | */ |
139 | - public function create_item( $request ) { |
|
140 | - $zone = new \WC_Shipping_Zone( null ); |
|
139 | + public function create_item($request) { |
|
140 | + $zone = new \WC_Shipping_Zone(null); |
|
141 | 141 | |
142 | - if ( ! is_null( $request->get_param( 'name' ) ) ) { |
|
143 | - $zone->set_zone_name( $request->get_param( 'name' ) ); |
|
142 | + if ( ! is_null($request->get_param('name'))) { |
|
143 | + $zone->set_zone_name($request->get_param('name')); |
|
144 | 144 | } |
145 | 145 | |
146 | - if ( ! is_null( $request->get_param( 'order' ) ) ) { |
|
147 | - $zone->set_zone_order( $request->get_param( 'order' ) ); |
|
146 | + if ( ! is_null($request->get_param('order'))) { |
|
147 | + $zone->set_zone_order($request->get_param('order')); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | $zone->save(); |
151 | 151 | |
152 | - if ( $zone->get_id() !== 0 ) { |
|
153 | - $request->set_param( 'id', $zone->get_id() ); |
|
154 | - $response = $this->get_item( $request ); |
|
155 | - $response->set_status( 201 ); |
|
156 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id() ) ) ); |
|
152 | + if ($zone->get_id() !== 0) { |
|
153 | + $request->set_param('id', $zone->get_id()); |
|
154 | + $response = $this->get_item($request); |
|
155 | + $response->set_status(201); |
|
156 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $zone->get_id()))); |
|
157 | 157 | return $response; |
158 | 158 | } else { |
159 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_not_created', __( "Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce' ), array( 'status' => 500 ) ); |
|
159 | + return new \WP_Error('woocommerce_rest_shipping_zone_not_created', __("Resource cannot be created. Check to make sure 'order' and 'name' are present.", 'woocommerce'), array('status' => 500)); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -166,34 +166,34 @@ discard block |
||
166 | 166 | * @param \WP_REST_Request $request Full details about the request. |
167 | 167 | * @return \WP_REST_Request|\WP_Error |
168 | 168 | */ |
169 | - public function update_item( $request ) { |
|
170 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
169 | + public function update_item($request) { |
|
170 | + $zone = $this->get_zone($request->get_param('id')); |
|
171 | 171 | |
172 | - if ( is_wp_error( $zone ) ) { |
|
172 | + if (is_wp_error($zone)) { |
|
173 | 173 | return $zone; |
174 | 174 | } |
175 | 175 | |
176 | - if ( 0 === $zone->get_id() ) { |
|
177 | - return new \WP_Error( 'woocommerce_rest_shipping_zone_invalid_zone', __( 'The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce' ), array( 'status' => 403 ) ); |
|
176 | + if (0 === $zone->get_id()) { |
|
177 | + return new \WP_Error('woocommerce_rest_shipping_zone_invalid_zone', __('The "locations not covered by your other zones" zone cannot be updated.', 'woocommerce'), array('status' => 403)); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | $zone_changed = false; |
181 | 181 | |
182 | - if ( ! is_null( $request->get_param( 'name' ) ) ) { |
|
183 | - $zone->set_zone_name( $request->get_param( 'name' ) ); |
|
182 | + if ( ! is_null($request->get_param('name'))) { |
|
183 | + $zone->set_zone_name($request->get_param('name')); |
|
184 | 184 | $zone_changed = true; |
185 | 185 | } |
186 | 186 | |
187 | - if ( ! is_null( $request->get_param( 'order' ) ) ) { |
|
188 | - $zone->set_zone_order( $request->get_param( 'order' ) ); |
|
187 | + if ( ! is_null($request->get_param('order'))) { |
|
188 | + $zone->set_zone_order($request->get_param('order')); |
|
189 | 189 | $zone_changed = true; |
190 | 190 | } |
191 | 191 | |
192 | - if ( $zone_changed ) { |
|
192 | + if ($zone_changed) { |
|
193 | 193 | $zone->save(); |
194 | 194 | } |
195 | 195 | |
196 | - return $this->get_item( $request ); |
|
196 | + return $this->get_item($request); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -202,21 +202,21 @@ discard block |
||
202 | 202 | * @param \WP_REST_Request $request Full details about the request. |
203 | 203 | * @return \WP_REST_Request|\WP_Error |
204 | 204 | */ |
205 | - public function delete_item( $request ) { |
|
206 | - $zone = $this->get_zone( $request->get_param( 'id' ) ); |
|
205 | + public function delete_item($request) { |
|
206 | + $zone = $this->get_zone($request->get_param('id')); |
|
207 | 207 | |
208 | - if ( is_wp_error( $zone ) ) { |
|
208 | + if (is_wp_error($zone)) { |
|
209 | 209 | return $zone; |
210 | 210 | } |
211 | 211 | |
212 | 212 | $force = $request['force']; |
213 | 213 | |
214 | 214 | // We don't support trashing for this type, error out. |
215 | - if ( ! $force ) { |
|
216 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Shipping zones do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
215 | + if ( ! $force) { |
|
216 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Shipping zones do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
217 | 217 | } |
218 | 218 | |
219 | - $previous = $this->get_item( $request ); |
|
219 | + $previous = $this->get_item($request); |
|
220 | 220 | $zone->delete(); |
221 | 221 | $response = new \WP_REST_Response(); |
222 | 222 | $response->set_data( |
@@ -236,21 +236,21 @@ discard block |
||
236 | 236 | * @param \WP_REST_Request $request Request object. |
237 | 237 | * @return \WP_REST_Response $response |
238 | 238 | */ |
239 | - public function prepare_item_for_response( $item, $request ) { |
|
239 | + public function prepare_item_for_response($item, $request) { |
|
240 | 240 | $data = array( |
241 | 241 | 'id' => (int) $item['id'], |
242 | 242 | 'name' => $item['zone_name'], |
243 | 243 | 'order' => (int) $item['zone_order'], |
244 | 244 | ); |
245 | 245 | |
246 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
247 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
248 | - $data = $this->filter_response_by_context( $data, $context ); |
|
246 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
247 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
248 | + $data = $this->filter_response_by_context($data, $context); |
|
249 | 249 | |
250 | 250 | // Wrap the data in a response object. |
251 | - $response = rest_ensure_response( $data ); |
|
251 | + $response = rest_ensure_response($data); |
|
252 | 252 | |
253 | - $response->add_links( $this->prepare_links( $data['id'] ) ); |
|
253 | + $response->add_links($this->prepare_links($data['id'])); |
|
254 | 254 | |
255 | 255 | return $response; |
256 | 256 | } |
@@ -261,17 +261,17 @@ discard block |
||
261 | 261 | * @param int $zone_id Given Shipping Zone ID. |
262 | 262 | * @return array Links for the given Shipping Zone. |
263 | 263 | */ |
264 | - protected function prepare_links( $zone_id ) { |
|
264 | + protected function prepare_links($zone_id) { |
|
265 | 265 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
266 | 266 | $links = array( |
267 | 267 | 'self' => array( |
268 | - 'href' => rest_url( trailingslashit( $base ) . $zone_id ), |
|
268 | + 'href' => rest_url(trailingslashit($base) . $zone_id), |
|
269 | 269 | ), |
270 | 270 | 'collection' => array( |
271 | - 'href' => rest_url( $base ), |
|
271 | + 'href' => rest_url($base), |
|
272 | 272 | ), |
273 | 273 | 'describedby' => array( |
274 | - 'href' => rest_url( trailingslashit( $base ) . $zone_id . '/locations' ), |
|
274 | + 'href' => rest_url(trailingslashit($base) . $zone_id . '/locations'), |
|
275 | 275 | ), |
276 | 276 | ); |
277 | 277 | |
@@ -290,27 +290,27 @@ discard block |
||
290 | 290 | 'type' => 'object', |
291 | 291 | 'properties' => array( |
292 | 292 | 'id' => array( |
293 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
293 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
294 | 294 | 'type' => 'integer', |
295 | - 'context' => array( 'view', 'edit' ), |
|
295 | + 'context' => array('view', 'edit'), |
|
296 | 296 | 'readonly' => true, |
297 | 297 | ), |
298 | 298 | 'name' => array( |
299 | - 'description' => __( 'Shipping zone name.', 'woocommerce' ), |
|
299 | + 'description' => __('Shipping zone name.', 'woocommerce'), |
|
300 | 300 | 'type' => 'string', |
301 | - 'context' => array( 'view', 'edit' ), |
|
301 | + 'context' => array('view', 'edit'), |
|
302 | 302 | 'arg_options' => array( |
303 | 303 | 'sanitize_callback' => 'sanitize_text_field', |
304 | 304 | ), |
305 | 305 | ), |
306 | 306 | 'order' => array( |
307 | - 'description' => __( 'Shipping zone order.', 'woocommerce' ), |
|
307 | + 'description' => __('Shipping zone order.', 'woocommerce'), |
|
308 | 308 | 'type' => 'integer', |
309 | - 'context' => array( 'view', 'edit' ), |
|
309 | + 'context' => array('view', 'edit'), |
|
310 | 310 | ), |
311 | 311 | ), |
312 | 312 | ); |
313 | 313 | |
314 | - return $this->add_additional_fields_schema( $schema ); |
|
314 | + return $this->add_additional_fields_schema($schema); |
|
315 | 315 | } |
316 | 316 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Tax Class controller class. |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | array( |
34 | 34 | array( |
35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
36 | - 'callback' => array( $this, 'get_items' ), |
|
37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'get_items'), |
|
37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
38 | 38 | 'args' => $this->get_collection_params(), |
39 | 39 | ), |
40 | 40 | array( |
41 | 41 | 'methods' => \WP_REST_Server::CREATABLE, |
42 | - 'callback' => array( $this, 'create_item' ), |
|
43 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
44 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
42 | + 'callback' => array($this, 'create_item'), |
|
43 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
44 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
45 | 45 | ), |
46 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
46 | + 'schema' => array($this, 'get_public_item_schema'), |
|
47 | 47 | ), |
48 | 48 | true |
49 | 49 | ); |
@@ -54,23 +54,23 @@ discard block |
||
54 | 54 | array( |
55 | 55 | 'args' => array( |
56 | 56 | 'slug' => array( |
57 | - 'description' => __( 'Unique slug for the resource.', 'woocommerce' ), |
|
57 | + 'description' => __('Unique slug for the resource.', 'woocommerce'), |
|
58 | 58 | 'type' => 'string', |
59 | 59 | ), |
60 | 60 | ), |
61 | 61 | array( |
62 | 62 | 'methods' => \WP_REST_Server::DELETABLE, |
63 | - 'callback' => array( $this, 'delete_item' ), |
|
64 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
63 | + 'callback' => array($this, 'delete_item'), |
|
64 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
65 | 65 | 'args' => array( |
66 | 66 | 'force' => array( |
67 | 67 | 'default' => false, |
68 | 68 | 'type' => 'boolean', |
69 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
69 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
70 | 70 | ), |
71 | 71 | ), |
72 | 72 | ), |
73 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
73 | + 'schema' => array($this, 'get_public_item_schema'), |
|
74 | 74 | ), |
75 | 75 | true |
76 | 76 | ); |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param \WP_REST_Request $request Full details about the request. |
83 | 83 | * @return \WP_Error|boolean |
84 | 84 | */ |
85 | - public function get_items_permissions_check( $request ) { |
|
86 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
87 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
85 | + public function get_items_permissions_check($request) { |
|
86 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
87 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | return true; |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @return bool|\WP_Error |
99 | 99 | */ |
100 | - public function create_item_permissions_check( $request ) { |
|
101 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) { |
|
102 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
100 | + public function create_item_permissions_check($request) { |
|
101 | + if ( ! wc_rest_check_manager_permissions('settings', 'create')) { |
|
102 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return true; |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return bool|\WP_Error |
114 | 114 | */ |
115 | - public function delete_item_permissions_check( $request ) { |
|
116 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { |
|
117 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
115 | + public function delete_item_permissions_check($request) { |
|
116 | + if ( ! wc_rest_check_manager_permissions('settings', 'delete')) { |
|
117 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | return true; |
@@ -126,32 +126,32 @@ discard block |
||
126 | 126 | * @param \WP_REST_Request $request Request params. |
127 | 127 | * @return array |
128 | 128 | */ |
129 | - public function get_items( $request ) { |
|
129 | + public function get_items($request) { |
|
130 | 130 | $tax_classes = array(); |
131 | 131 | |
132 | 132 | // Add standard class. |
133 | 133 | $tax_classes[] = array( |
134 | 134 | 'slug' => 'standard', |
135 | - 'name' => __( 'Standard rate', 'woocommerce' ), |
|
135 | + 'name' => __('Standard rate', 'woocommerce'), |
|
136 | 136 | ); |
137 | 137 | |
138 | 138 | $classes = \WC_Tax::get_tax_classes(); |
139 | 139 | |
140 | - foreach ( $classes as $class ) { |
|
140 | + foreach ($classes as $class) { |
|
141 | 141 | $tax_classes[] = array( |
142 | - 'slug' => sanitize_title( $class ), |
|
142 | + 'slug' => sanitize_title($class), |
|
143 | 143 | 'name' => $class, |
144 | 144 | ); |
145 | 145 | } |
146 | 146 | |
147 | 147 | $data = array(); |
148 | - foreach ( $tax_classes as $tax_class ) { |
|
149 | - $class = $this->prepare_item_for_response( $tax_class, $request ); |
|
150 | - $class = $this->prepare_response_for_collection( $class ); |
|
148 | + foreach ($tax_classes as $tax_class) { |
|
149 | + $class = $this->prepare_item_for_response($tax_class, $request); |
|
150 | + $class = $this->prepare_response_for_collection($class); |
|
151 | 151 | $data[] = $class; |
152 | 152 | } |
153 | 153 | |
154 | - return rest_ensure_response( $data ); |
|
154 | + return rest_ensure_response($data); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -160,33 +160,33 @@ discard block |
||
160 | 160 | * @param \WP_REST_Request $request Full details about the request. |
161 | 161 | * @return \WP_Error\WP_REST_Response |
162 | 162 | */ |
163 | - public function create_item( $request ) { |
|
163 | + public function create_item($request) { |
|
164 | 164 | $exists = false; |
165 | 165 | $classes = \WC_Tax::get_tax_classes(); |
166 | 166 | $tax_class = array( |
167 | - 'slug' => sanitize_title( $request['name'] ), |
|
167 | + 'slug' => sanitize_title($request['name']), |
|
168 | 168 | 'name' => $request['name'], |
169 | 169 | ); |
170 | 170 | |
171 | 171 | // Check if class exists. |
172 | - foreach ( $classes as $key => $class ) { |
|
173 | - if ( sanitize_title( $class ) === $tax_class['slug'] ) { |
|
172 | + foreach ($classes as $key => $class) { |
|
173 | + if (sanitize_title($class) === $tax_class['slug']) { |
|
174 | 174 | $exists = true; |
175 | 175 | break; |
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | 179 | // Return error if tax class already exists. |
180 | - if ( $exists ) { |
|
181 | - return new \WP_Error( 'woocommerce_rest_tax_class_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
180 | + if ($exists) { |
|
181 | + return new \WP_Error('woocommerce_rest_tax_class_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400)); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // Add the new class. |
185 | 185 | $classes[] = $tax_class['name']; |
186 | 186 | |
187 | - update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) ); |
|
187 | + update_option('woocommerce_tax_classes', implode("\n", $classes)); |
|
188 | 188 | |
189 | - $this->update_additional_fields_for_object( $tax_class, $request ); |
|
189 | + $this->update_additional_fields_for_object($tax_class, $request); |
|
190 | 190 | |
191 | 191 | /** |
192 | 192 | * Fires after a tax class is created or updated via the REST API. |
@@ -195,13 +195,13 @@ discard block |
||
195 | 195 | * @param \WP_REST_Request $request Request object. |
196 | 196 | * @param boolean $creating True when creating tax class, false when updating tax class. |
197 | 197 | */ |
198 | - do_action( 'woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true ); |
|
198 | + do_action('woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true); |
|
199 | 199 | |
200 | - $request->set_param( 'context', 'edit' ); |
|
201 | - $response = $this->prepare_item_for_response( $tax_class, $request ); |
|
202 | - $response = rest_ensure_response( $response ); |
|
203 | - $response->set_status( 201 ); |
|
204 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug'] ) ) ); |
|
200 | + $request->set_param('context', 'edit'); |
|
201 | + $response = $this->prepare_item_for_response($tax_class, $request); |
|
202 | + $response = rest_ensure_response($response); |
|
203 | + $response->set_status(201); |
|
204 | + $response->header('Location', rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug']))); |
|
205 | 205 | |
206 | 206 | return $response; |
207 | 207 | } |
@@ -212,40 +212,40 @@ discard block |
||
212 | 212 | * @param \WP_REST_Request $request Full details about the request. |
213 | 213 | * @return \WP_Error\WP_REST_Response |
214 | 214 | */ |
215 | - public function delete_item( $request ) { |
|
215 | + public function delete_item($request) { |
|
216 | 216 | global $wpdb; |
217 | 217 | |
218 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
218 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
219 | 219 | |
220 | 220 | // We don't support trashing for this type, error out. |
221 | - if ( ! $force ) { |
|
222 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
221 | + if ( ! $force) { |
|
222 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | $tax_class = array( |
226 | - 'slug' => sanitize_title( $request['slug'] ), |
|
226 | + 'slug' => sanitize_title($request['slug']), |
|
227 | 227 | 'name' => '', |
228 | 228 | ); |
229 | 229 | $classes = \WC_Tax::get_tax_classes(); |
230 | 230 | $deleted = false; |
231 | 231 | |
232 | - foreach ( $classes as $key => $class ) { |
|
233 | - if ( sanitize_title( $class ) === $tax_class['slug'] ) { |
|
232 | + foreach ($classes as $key => $class) { |
|
233 | + if (sanitize_title($class) === $tax_class['slug']) { |
|
234 | 234 | $tax_class['name'] = $class; |
235 | - unset( $classes[ $key ] ); |
|
235 | + unset($classes[$key]); |
|
236 | 236 | $deleted = true; |
237 | 237 | break; |
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | - if ( ! $deleted ) { |
|
242 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
241 | + if ( ! $deleted) { |
|
242 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400)); |
|
243 | 243 | } |
244 | 244 | |
245 | - $request->set_param( 'context', 'edit' ); |
|
246 | - $previous = $this->prepare_item_for_response( $tax_class, $request ); |
|
245 | + $request->set_param('context', 'edit'); |
|
246 | + $previous = $this->prepare_item_for_response($tax_class, $request); |
|
247 | 247 | |
248 | - update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) ); |
|
248 | + update_option('woocommerce_tax_classes', implode("\n", $classes)); |
|
249 | 249 | |
250 | 250 | // Delete tax rate locations locations from the selected class. |
251 | 251 | $wpdb->query( |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | ); |
264 | 264 | |
265 | 265 | // Delete tax rates in the selected class. |
266 | - $wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class['slug'] ), array( '%s' ) ); |
|
266 | + $wpdb->delete($wpdb->prefix . 'woocommerce_tax_rates', array('tax_rate_class' => $tax_class['slug']), array('%s')); |
|
267 | 267 | |
268 | 268 | $response = new \WP_REST_Response(); |
269 | 269 | $response->set_data( |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @param \WP_REST_Response $response The response returned from the API. |
281 | 281 | * @param \WP_REST_Request $request The request sent to the API. |
282 | 282 | */ |
283 | - do_action( 'woocommerce_rest_delete_tax', (object) $tax_class, $response, $request ); |
|
283 | + do_action('woocommerce_rest_delete_tax', (object) $tax_class, $response, $request); |
|
284 | 284 | |
285 | 285 | return $response; |
286 | 286 | } |
@@ -292,17 +292,17 @@ discard block |
||
292 | 292 | * @param \WP_REST_Request $request Request object. |
293 | 293 | * @return \WP_REST_Response $response Response data. |
294 | 294 | */ |
295 | - public function prepare_item_for_response( $tax_class, $request ) { |
|
295 | + public function prepare_item_for_response($tax_class, $request) { |
|
296 | 296 | $data = $tax_class; |
297 | 297 | |
298 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
299 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
300 | - $data = $this->filter_response_by_context( $data, $context ); |
|
298 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
299 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
300 | + $data = $this->filter_response_by_context($data, $context); |
|
301 | 301 | |
302 | 302 | // Wrap the data in a response object. |
303 | - $response = rest_ensure_response( $data ); |
|
303 | + $response = rest_ensure_response($data); |
|
304 | 304 | |
305 | - $response->add_links( $this->prepare_links() ); |
|
305 | + $response->add_links($this->prepare_links()); |
|
306 | 306 | |
307 | 307 | /** |
308 | 308 | * Filter tax object returned from the REST API. |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @param stdClass $tax_class Tax object used to create response. |
312 | 312 | * @param \WP_REST_Request $request Request object. |
313 | 313 | */ |
314 | - return apply_filters( 'woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request ); |
|
314 | + return apply_filters('woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | protected function prepare_links() { |
323 | 323 | $links = array( |
324 | 324 | 'collection' => array( |
325 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
325 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
326 | 326 | ), |
327 | 327 | ); |
328 | 328 | |
@@ -341,15 +341,15 @@ discard block |
||
341 | 341 | 'type' => 'object', |
342 | 342 | 'properties' => array( |
343 | 343 | 'slug' => array( |
344 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
344 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
345 | 345 | 'type' => 'string', |
346 | - 'context' => array( 'view', 'edit' ), |
|
346 | + 'context' => array('view', 'edit'), |
|
347 | 347 | 'readonly' => true, |
348 | 348 | ), |
349 | 349 | 'name' => array( |
350 | - 'description' => __( 'Tax class name.', 'woocommerce' ), |
|
350 | + 'description' => __('Tax class name.', 'woocommerce'), |
|
351 | 351 | 'type' => 'string', |
352 | - 'context' => array( 'view', 'edit' ), |
|
352 | + 'context' => array('view', 'edit'), |
|
353 | 353 | 'required' => true, |
354 | 354 | 'arg_options' => array( |
355 | 355 | 'sanitize_callback' => 'sanitize_text_field', |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | ), |
359 | 359 | ); |
360 | 360 | |
361 | - return $this->add_additional_fields_schema( $schema ); |
|
361 | + return $this->add_additional_fields_schema($schema); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function get_collection_params() { |
370 | 370 | return array( |
371 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
371 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
372 | 372 | ); |
373 | 373 | } |
374 | 374 | } |