@@ -8,7 +8,7 @@ |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Taxes controller class. |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Setting Options controller class. |
@@ -42,16 +42,16 @@ discard block |
||
42 | 42 | $this->namespace, '/' . $this->rest_base, array( |
43 | 43 | 'args' => array( |
44 | 44 | 'group' => array( |
45 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
45 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
46 | 46 | 'type' => 'string', |
47 | 47 | ), |
48 | 48 | ), |
49 | 49 | array( |
50 | 50 | 'methods' => WP_REST_Server::READABLE, |
51 | - 'callback' => array( $this, 'get_items' ), |
|
52 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
51 | + 'callback' => array($this, 'get_items'), |
|
52 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
53 | 53 | ), |
54 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
54 | + 'schema' => array($this, 'get_public_item_schema'), |
|
55 | 55 | ) |
56 | 56 | ); |
57 | 57 | |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | $this->namespace, '/' . $this->rest_base . '/batch', array( |
60 | 60 | 'args' => array( |
61 | 61 | 'group' => array( |
62 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
62 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
63 | 63 | 'type' => 'string', |
64 | 64 | ), |
65 | 65 | ), |
66 | 66 | array( |
67 | 67 | 'methods' => WP_REST_Server::EDITABLE, |
68 | - 'callback' => array( $this, 'batch_items' ), |
|
69 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
70 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
68 | + 'callback' => array($this, 'batch_items'), |
|
69 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
70 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
71 | 71 | ), |
72 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
72 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
73 | 73 | ) |
74 | 74 | ); |
75 | 75 | |
@@ -77,26 +77,26 @@ discard block |
||
77 | 77 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array( |
78 | 78 | 'args' => array( |
79 | 79 | 'group' => array( |
80 | - 'description' => __( 'Settings group ID.', 'woocommerce' ), |
|
80 | + 'description' => __('Settings group ID.', 'woocommerce'), |
|
81 | 81 | 'type' => 'string', |
82 | 82 | ), |
83 | 83 | 'id' => array( |
84 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
84 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
85 | 85 | 'type' => 'string', |
86 | 86 | ), |
87 | 87 | ), |
88 | 88 | array( |
89 | 89 | 'methods' => WP_REST_Server::READABLE, |
90 | - 'callback' => array( $this, 'get_item' ), |
|
91 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
90 | + 'callback' => array($this, 'get_item'), |
|
91 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
92 | 92 | ), |
93 | 93 | array( |
94 | 94 | 'methods' => WP_REST_Server::EDITABLE, |
95 | - 'callback' => array( $this, 'update_item' ), |
|
96 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
97 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
95 | + 'callback' => array($this, 'update_item'), |
|
96 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
97 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
98 | 98 | ), |
99 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
99 | + 'schema' => array($this, 'get_public_item_schema'), |
|
100 | 100 | ) |
101 | 101 | ); |
102 | 102 | } |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | * @param WP_REST_Request $request Request data. |
109 | 109 | * @return WP_Error|WP_REST_Response |
110 | 110 | */ |
111 | - public function get_item( $request ) { |
|
112 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
111 | + public function get_item($request) { |
|
112 | + $setting = $this->get_setting($request['group_id'], $request['id']); |
|
113 | 113 | |
114 | - if ( is_wp_error( $setting ) ) { |
|
114 | + if (is_wp_error($setting)) { |
|
115 | 115 | return $setting; |
116 | 116 | } |
117 | 117 | |
118 | - $response = $this->prepare_item_for_response( $setting, $request ); |
|
118 | + $response = $this->prepare_item_for_response($setting, $request); |
|
119 | 119 | |
120 | - return rest_ensure_response( $response ); |
|
120 | + return rest_ensure_response($response); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -127,24 +127,24 @@ discard block |
||
127 | 127 | * @param WP_REST_Request $request Request data. |
128 | 128 | * @return WP_Error|WP_REST_Response |
129 | 129 | */ |
130 | - public function get_items( $request ) { |
|
131 | - $settings = $this->get_group_settings( $request['group_id'] ); |
|
130 | + public function get_items($request) { |
|
131 | + $settings = $this->get_group_settings($request['group_id']); |
|
132 | 132 | |
133 | - if ( is_wp_error( $settings ) ) { |
|
133 | + if (is_wp_error($settings)) { |
|
134 | 134 | return $settings; |
135 | 135 | } |
136 | 136 | |
137 | 137 | $data = array(); |
138 | 138 | |
139 | - foreach ( $settings as $setting_obj ) { |
|
140 | - $setting = $this->prepare_item_for_response( $setting_obj, $request ); |
|
141 | - $setting = $this->prepare_response_for_collection( $setting ); |
|
142 | - if ( $this->is_setting_type_valid( $setting['type'] ) ) { |
|
139 | + foreach ($settings as $setting_obj) { |
|
140 | + $setting = $this->prepare_item_for_response($setting_obj, $request); |
|
141 | + $setting = $this->prepare_response_for_collection($setting); |
|
142 | + if ($this->is_setting_type_valid($setting['type'])) { |
|
143 | 143 | $data[] = $setting; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | - return rest_ensure_response( $data ); |
|
147 | + return rest_ensure_response($data); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -154,35 +154,35 @@ discard block |
||
154 | 154 | * @param string $group_id Group ID. |
155 | 155 | * @return array|WP_Error |
156 | 156 | */ |
157 | - public function get_group_settings( $group_id ) { |
|
158 | - if ( empty( $group_id ) ) { |
|
159 | - return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
157 | + public function get_group_settings($group_id) { |
|
158 | + if (empty($group_id)) { |
|
159 | + return new WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404)); |
|
160 | 160 | } |
161 | 161 | |
162 | - $settings = apply_filters( 'woocommerce_settings-' . $group_id, array() ); |
|
162 | + $settings = apply_filters('woocommerce_settings-' . $group_id, array()); |
|
163 | 163 | |
164 | - if ( empty( $settings ) ) { |
|
165 | - return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
164 | + if (empty($settings)) { |
|
165 | + return new WP_Error('rest_setting_setting_group_invalid', __('Invalid setting group.', 'woocommerce'), array('status' => 404)); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | $filtered_settings = array(); |
169 | - foreach ( $settings as $setting ) { |
|
169 | + foreach ($settings as $setting) { |
|
170 | 170 | $option_key = $setting['option_key']; |
171 | - $setting = $this->filter_setting( $setting ); |
|
172 | - $default = isset( $setting['default'] ) ? $setting['default'] : ''; |
|
171 | + $setting = $this->filter_setting($setting); |
|
172 | + $default = isset($setting['default']) ? $setting['default'] : ''; |
|
173 | 173 | // Get the option value. |
174 | - if ( is_array( $option_key ) ) { |
|
175 | - $option = get_option( $option_key[0] ); |
|
176 | - $setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default; |
|
174 | + if (is_array($option_key)) { |
|
175 | + $option = get_option($option_key[0]); |
|
176 | + $setting['value'] = isset($option[$option_key[1]]) ? $option[$option_key[1]] : $default; |
|
177 | 177 | } else { |
178 | - $admin_setting_value = WC_Admin_Settings::get_option( $option_key, $default ); |
|
178 | + $admin_setting_value = WC_Admin_Settings::get_option($option_key, $default); |
|
179 | 179 | $setting['value'] = $admin_setting_value; |
180 | 180 | } |
181 | 181 | |
182 | - if ( 'multi_select_countries' === $setting['type'] ) { |
|
182 | + if ('multi_select_countries' === $setting['type']) { |
|
183 | 183 | $setting['options'] = WC()->countries->get_countries(); |
184 | 184 | $setting['type'] = 'multiselect'; |
185 | - } elseif ( 'single_select_country' === $setting['type'] ) { |
|
185 | + } elseif ('single_select_country' === $setting['type']) { |
|
186 | 186 | $setting['type'] = 'select'; |
187 | 187 | $setting['options'] = $this->get_countries_and_states(); |
188 | 188 | } |
@@ -201,20 +201,20 @@ discard block |
||
201 | 201 | */ |
202 | 202 | private function get_countries_and_states() { |
203 | 203 | $countries = WC()->countries->get_countries(); |
204 | - if ( ! $countries ) { |
|
204 | + if ( ! $countries) { |
|
205 | 205 | return array(); |
206 | 206 | } |
207 | 207 | |
208 | 208 | $output = array(); |
209 | 209 | |
210 | - foreach ( $countries as $key => $value ) { |
|
211 | - $states = WC()->countries->get_states( $key ); |
|
212 | - if ( $states ) { |
|
213 | - foreach ( $states as $state_key => $state_value ) { |
|
214 | - $output[ $key . ':' . $state_key ] = $value . ' - ' . $state_value; |
|
210 | + foreach ($countries as $key => $value) { |
|
211 | + $states = WC()->countries->get_states($key); |
|
212 | + if ($states) { |
|
213 | + foreach ($states as $state_key => $state_value) { |
|
214 | + $output[$key . ':' . $state_key] = $value . ' - ' . $state_value; |
|
215 | 215 | } |
216 | 216 | } else { |
217 | - $output[ $key ] = $value; |
|
217 | + $output[$key] = $value; |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
@@ -229,27 +229,27 @@ discard block |
||
229 | 229 | * @param string $setting_id Setting ID. |
230 | 230 | * @return stdClass|WP_Error |
231 | 231 | */ |
232 | - public function get_setting( $group_id, $setting_id ) { |
|
233 | - if ( empty( $setting_id ) ) { |
|
234 | - return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
232 | + public function get_setting($group_id, $setting_id) { |
|
233 | + if (empty($setting_id)) { |
|
234 | + return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
235 | 235 | } |
236 | 236 | |
237 | - $settings = $this->get_group_settings( $group_id ); |
|
237 | + $settings = $this->get_group_settings($group_id); |
|
238 | 238 | |
239 | - if ( is_wp_error( $settings ) ) { |
|
239 | + if (is_wp_error($settings)) { |
|
240 | 240 | return $settings; |
241 | 241 | } |
242 | 242 | |
243 | - $array_key = array_keys( wp_list_pluck( $settings, 'id' ), $setting_id ); |
|
243 | + $array_key = array_keys(wp_list_pluck($settings, 'id'), $setting_id); |
|
244 | 244 | |
245 | - if ( empty( $array_key ) ) { |
|
246 | - return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
245 | + if (empty($array_key)) { |
|
246 | + return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
247 | 247 | } |
248 | 248 | |
249 | - $setting = $settings[ $array_key[0] ]; |
|
249 | + $setting = $settings[$array_key[0]]; |
|
250 | 250 | |
251 | - if ( ! $this->is_setting_type_valid( $setting['type'] ) ) { |
|
252 | - return new WP_Error( 'rest_setting_setting_invalid', __( 'Invalid setting.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
251 | + if ( ! $this->is_setting_type_valid($setting['type'])) { |
|
252 | + return new WP_Error('rest_setting_setting_invalid', __('Invalid setting.', 'woocommerce'), array('status' => 404)); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | return $setting; |
@@ -262,24 +262,24 @@ discard block |
||
262 | 262 | * @param WP_REST_Request $request Full details about the request. |
263 | 263 | * @return array Of WP_Error or WP_REST_Response. |
264 | 264 | */ |
265 | - public function batch_items( $request ) { |
|
265 | + public function batch_items($request) { |
|
266 | 266 | // Get the request params. |
267 | - $items = array_filter( $request->get_params() ); |
|
267 | + $items = array_filter($request->get_params()); |
|
268 | 268 | |
269 | 269 | /* |
270 | 270 | * Since our batch settings update is group-specific and matches based on the route, |
271 | 271 | * we inject the URL parameters (containing group) into the batch items |
272 | 272 | */ |
273 | - if ( ! empty( $items['update'] ) ) { |
|
273 | + if ( ! empty($items['update'])) { |
|
274 | 274 | $to_update = array(); |
275 | - foreach ( $items['update'] as $item ) { |
|
276 | - $to_update[] = array_merge( $request->get_url_params(), $item ); |
|
275 | + foreach ($items['update'] as $item) { |
|
276 | + $to_update[] = array_merge($request->get_url_params(), $item); |
|
277 | 277 | } |
278 | - $request = new WP_REST_Request( $request->get_method() ); |
|
279 | - $request->set_body_params( array( 'update' => $to_update ) ); |
|
278 | + $request = new WP_REST_Request($request->get_method()); |
|
279 | + $request->set_body_params(array('update' => $to_update)); |
|
280 | 280 | } |
281 | 281 | |
282 | - return parent::batch_items( $request ); |
|
282 | + return parent::batch_items($request); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -289,39 +289,39 @@ discard block |
||
289 | 289 | * @param WP_REST_Request $request Request data. |
290 | 290 | * @return WP_Error|WP_REST_Response |
291 | 291 | */ |
292 | - public function update_item( $request ) { |
|
293 | - $setting = $this->get_setting( $request['group_id'], $request['id'] ); |
|
292 | + public function update_item($request) { |
|
293 | + $setting = $this->get_setting($request['group_id'], $request['id']); |
|
294 | 294 | |
295 | - if ( is_wp_error( $setting ) ) { |
|
295 | + if (is_wp_error($setting)) { |
|
296 | 296 | return $setting; |
297 | 297 | } |
298 | 298 | |
299 | - if ( is_callable( array( $this, 'validate_setting_' . $setting['type'] . '_field' ) ) ) { |
|
300 | - $value = $this->{'validate_setting_' . $setting['type'] . '_field'}( $request['value'], $setting ); |
|
299 | + if (is_callable(array($this, 'validate_setting_' . $setting['type'] . '_field'))) { |
|
300 | + $value = $this->{'validate_setting_' . $setting['type'] . '_field'}($request['value'], $setting); |
|
301 | 301 | } else { |
302 | - $value = $this->validate_setting_text_field( $request['value'], $setting ); |
|
302 | + $value = $this->validate_setting_text_field($request['value'], $setting); |
|
303 | 303 | } |
304 | 304 | |
305 | - if ( is_wp_error( $value ) ) { |
|
305 | + if (is_wp_error($value)) { |
|
306 | 306 | return $value; |
307 | 307 | } |
308 | 308 | |
309 | - if ( is_array( $setting['option_key'] ) ) { |
|
309 | + if (is_array($setting['option_key'])) { |
|
310 | 310 | $setting['value'] = $value; |
311 | 311 | $option_key = $setting['option_key']; |
312 | - $prev = get_option( $option_key[0] ); |
|
313 | - $prev[ $option_key[1] ] = $request['value']; |
|
314 | - update_option( $option_key[0], $prev ); |
|
312 | + $prev = get_option($option_key[0]); |
|
313 | + $prev[$option_key[1]] = $request['value']; |
|
314 | + update_option($option_key[0], $prev); |
|
315 | 315 | } else { |
316 | 316 | $update_data = array(); |
317 | - $update_data[ $setting['option_key'] ] = $value; |
|
317 | + $update_data[$setting['option_key']] = $value; |
|
318 | 318 | $setting['value'] = $value; |
319 | - WC_Admin_Settings::save_fields( array( $setting ), $update_data ); |
|
319 | + WC_Admin_Settings::save_fields(array($setting), $update_data); |
|
320 | 320 | } |
321 | 321 | |
322 | - $response = $this->prepare_item_for_response( $setting, $request ); |
|
322 | + $response = $this->prepare_item_for_response($setting, $request); |
|
323 | 323 | |
324 | - return rest_ensure_response( $response ); |
|
324 | + return rest_ensure_response($response); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -332,13 +332,13 @@ discard block |
||
332 | 332 | * @param WP_REST_Request $request Request object. |
333 | 333 | * @return WP_REST_Response $response Response data. |
334 | 334 | */ |
335 | - public function prepare_item_for_response( $item, $request ) { |
|
336 | - unset( $item['option_key'] ); |
|
337 | - $data = $this->filter_setting( $item ); |
|
338 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
339 | - $data = $this->filter_response_by_context( $data, empty( $request['context'] ) ? 'view' : $request['context'] ); |
|
340 | - $response = rest_ensure_response( $data ); |
|
341 | - $response->add_links( $this->prepare_links( $data['id'], $request['group_id'] ) ); |
|
335 | + public function prepare_item_for_response($item, $request) { |
|
336 | + unset($item['option_key']); |
|
337 | + $data = $this->filter_setting($item); |
|
338 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
339 | + $data = $this->filter_response_by_context($data, empty($request['context']) ? 'view' : $request['context']); |
|
340 | + $response = rest_ensure_response($data); |
|
341 | + $response->add_links($this->prepare_links($data['id'], $request['group_id'])); |
|
342 | 342 | return $response; |
343 | 343 | } |
344 | 344 | |
@@ -350,14 +350,14 @@ discard block |
||
350 | 350 | * @param string $group_id Group ID. |
351 | 351 | * @return array Links for the given setting. |
352 | 352 | */ |
353 | - protected function prepare_links( $setting_id, $group_id ) { |
|
354 | - $base = str_replace( '(?P<group_id>[\w-]+)', $group_id, $this->rest_base ); |
|
353 | + protected function prepare_links($setting_id, $group_id) { |
|
354 | + $base = str_replace('(?P<group_id>[\w-]+)', $group_id, $this->rest_base); |
|
355 | 355 | $links = array( |
356 | 356 | 'self' => array( |
357 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $base, $setting_id ) ), |
|
357 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $base, $setting_id)), |
|
358 | 358 | ), |
359 | 359 | 'collection' => array( |
360 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
360 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
361 | 361 | ), |
362 | 362 | ); |
363 | 363 | |
@@ -371,9 +371,9 @@ discard block |
||
371 | 371 | * @param WP_REST_Request $request Full data about the request. |
372 | 372 | * @return WP_Error|boolean |
373 | 373 | */ |
374 | - public function get_items_permissions_check( $request ) { |
|
375 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
376 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
374 | + public function get_items_permissions_check($request) { |
|
375 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
376 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | return true; |
@@ -386,9 +386,9 @@ discard block |
||
386 | 386 | * @param WP_REST_Request $request Full data about the request. |
387 | 387 | * @return WP_Error|boolean |
388 | 388 | */ |
389 | - public function update_items_permissions_check( $request ) { |
|
390 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
391 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
389 | + public function update_items_permissions_check($request) { |
|
390 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
391 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you cannot edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | return true; |
@@ -402,18 +402,18 @@ discard block |
||
402 | 402 | * @param array $setting Settings. |
403 | 403 | * @return array |
404 | 404 | */ |
405 | - public function filter_setting( $setting ) { |
|
405 | + public function filter_setting($setting) { |
|
406 | 406 | $setting = array_intersect_key( |
407 | 407 | $setting, |
408 | - array_flip( array_filter( array_keys( $setting ), array( $this, 'allowed_setting_keys' ) ) ) |
|
408 | + array_flip(array_filter(array_keys($setting), array($this, 'allowed_setting_keys'))) |
|
409 | 409 | ); |
410 | 410 | |
411 | - if ( empty( $setting['options'] ) ) { |
|
412 | - unset( $setting['options'] ); |
|
411 | + if (empty($setting['options'])) { |
|
412 | + unset($setting['options']); |
|
413 | 413 | } |
414 | 414 | |
415 | - if ( 'image_width' === $setting['type'] ) { |
|
416 | - $setting = $this->cast_image_width( $setting ); |
|
415 | + if ('image_width' === $setting['type']) { |
|
416 | + $setting = $this->cast_image_width($setting); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | return $setting; |
@@ -428,12 +428,12 @@ discard block |
||
428 | 428 | * @param array $setting Settings. |
429 | 429 | * @return array |
430 | 430 | */ |
431 | - public function cast_image_width( $setting ) { |
|
432 | - foreach ( array( 'default', 'value' ) as $key ) { |
|
433 | - if ( isset( $setting[ $key ] ) ) { |
|
434 | - $setting[ $key ]['width'] = intval( $setting[ $key ]['width'] ); |
|
435 | - $setting[ $key ]['height'] = intval( $setting[ $key ]['height'] ); |
|
436 | - $setting[ $key ]['crop'] = (bool) $setting[ $key ]['crop']; |
|
431 | + public function cast_image_width($setting) { |
|
432 | + foreach (array('default', 'value') as $key) { |
|
433 | + if (isset($setting[$key])) { |
|
434 | + $setting[$key]['width'] = intval($setting[$key]['width']); |
|
435 | + $setting[$key]['height'] = intval($setting[$key]['height']); |
|
436 | + $setting[$key]['crop'] = (bool) $setting[$key]['crop']; |
|
437 | 437 | } |
438 | 438 | } |
439 | 439 | return $setting; |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | * @param string $key Key to check. |
447 | 447 | * @return boolean |
448 | 448 | */ |
449 | - public function allowed_setting_keys( $key ) { |
|
449 | + public function allowed_setting_keys($key) { |
|
450 | 450 | return in_array( |
451 | 451 | $key, array( |
452 | 452 | 'id', |
@@ -470,20 +470,20 @@ discard block |
||
470 | 470 | * @param string $type Type. |
471 | 471 | * @return bool |
472 | 472 | */ |
473 | - public function is_setting_type_valid( $type ) { |
|
473 | + public function is_setting_type_valid($type) { |
|
474 | 474 | return in_array( |
475 | 475 | $type, array( |
476 | - 'text', // Validates with validate_setting_text_field. |
|
477 | - 'email', // Validates with validate_setting_text_field. |
|
478 | - 'number', // Validates with validate_setting_text_field. |
|
479 | - 'color', // Validates with validate_setting_text_field. |
|
480 | - 'password', // Validates with validate_setting_text_field. |
|
481 | - 'textarea', // Validates with validate_setting_textarea_field. |
|
482 | - 'select', // Validates with validate_setting_select_field. |
|
483 | - 'multiselect', // Validates with validate_setting_multiselect_field. |
|
484 | - 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
485 | - 'checkbox', // Validates with validate_setting_checkbox_field. |
|
486 | - 'image_width', // Validates with validate_setting_image_width_field. |
|
476 | + 'text', // Validates with validate_setting_text_field. |
|
477 | + 'email', // Validates with validate_setting_text_field. |
|
478 | + 'number', // Validates with validate_setting_text_field. |
|
479 | + 'color', // Validates with validate_setting_text_field. |
|
480 | + 'password', // Validates with validate_setting_text_field. |
|
481 | + 'textarea', // Validates with validate_setting_textarea_field. |
|
482 | + 'select', // Validates with validate_setting_select_field. |
|
483 | + 'multiselect', // Validates with validate_setting_multiselect_field. |
|
484 | + 'radio', // Validates with validate_setting_radio_field (-> validate_setting_select_field). |
|
485 | + 'checkbox', // Validates with validate_setting_checkbox_field. |
|
486 | + 'image_width', // Validates with validate_setting_image_width_field. |
|
487 | 487 | 'thumbnail_cropping', // Validates with validate_setting_text_field. |
488 | 488 | ) |
489 | 489 | ); |
@@ -502,80 +502,80 @@ discard block |
||
502 | 502 | 'type' => 'object', |
503 | 503 | 'properties' => array( |
504 | 504 | 'id' => array( |
505 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
505 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
506 | 506 | 'type' => 'string', |
507 | 507 | 'arg_options' => array( |
508 | 508 | 'sanitize_callback' => 'sanitize_title', |
509 | 509 | ), |
510 | - 'context' => array( 'view', 'edit' ), |
|
510 | + 'context' => array('view', 'edit'), |
|
511 | 511 | 'readonly' => true, |
512 | 512 | ), |
513 | 513 | 'label' => array( |
514 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
514 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
515 | 515 | 'type' => 'string', |
516 | 516 | 'arg_options' => array( |
517 | 517 | 'sanitize_callback' => 'sanitize_text_field', |
518 | 518 | ), |
519 | - 'context' => array( 'view', 'edit' ), |
|
519 | + 'context' => array('view', 'edit'), |
|
520 | 520 | 'readonly' => true, |
521 | 521 | ), |
522 | 522 | 'description' => array( |
523 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
523 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
524 | 524 | 'type' => 'string', |
525 | 525 | 'arg_options' => array( |
526 | 526 | 'sanitize_callback' => 'sanitize_text_field', |
527 | 527 | ), |
528 | - 'context' => array( 'view', 'edit' ), |
|
528 | + 'context' => array('view', 'edit'), |
|
529 | 529 | 'readonly' => true, |
530 | 530 | ), |
531 | 531 | 'value' => array( |
532 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
532 | + 'description' => __('Setting value.', 'woocommerce'), |
|
533 | 533 | 'type' => 'mixed', |
534 | - 'context' => array( 'view', 'edit' ), |
|
534 | + 'context' => array('view', 'edit'), |
|
535 | 535 | ), |
536 | 536 | 'default' => array( |
537 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
537 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
538 | 538 | 'type' => 'mixed', |
539 | - 'context' => array( 'view', 'edit' ), |
|
539 | + 'context' => array('view', 'edit'), |
|
540 | 540 | 'readonly' => true, |
541 | 541 | ), |
542 | 542 | 'tip' => array( |
543 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
543 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
544 | 544 | 'type' => 'string', |
545 | 545 | 'arg_options' => array( |
546 | 546 | 'sanitize_callback' => 'sanitize_text_field', |
547 | 547 | ), |
548 | - 'context' => array( 'view', 'edit' ), |
|
548 | + 'context' => array('view', 'edit'), |
|
549 | 549 | 'readonly' => true, |
550 | 550 | ), |
551 | 551 | 'placeholder' => array( |
552 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
552 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
553 | 553 | 'type' => 'string', |
554 | 554 | 'arg_options' => array( |
555 | 555 | 'sanitize_callback' => 'sanitize_text_field', |
556 | 556 | ), |
557 | - 'context' => array( 'view', 'edit' ), |
|
557 | + 'context' => array('view', 'edit'), |
|
558 | 558 | 'readonly' => true, |
559 | 559 | ), |
560 | 560 | 'type' => array( |
561 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
561 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
562 | 562 | 'type' => 'string', |
563 | 563 | 'arg_options' => array( |
564 | 564 | 'sanitize_callback' => 'sanitize_text_field', |
565 | 565 | ), |
566 | - 'context' => array( 'view', 'edit' ), |
|
567 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'thumbnail_cropping' ), |
|
566 | + 'context' => array('view', 'edit'), |
|
567 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox', 'thumbnail_cropping'), |
|
568 | 568 | 'readonly' => true, |
569 | 569 | ), |
570 | 570 | 'options' => array( |
571 | - 'description' => __( 'Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce' ), |
|
571 | + 'description' => __('Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons.', 'woocommerce'), |
|
572 | 572 | 'type' => 'object', |
573 | - 'context' => array( 'view', 'edit' ), |
|
573 | + 'context' => array('view', 'edit'), |
|
574 | 574 | 'readonly' => true, |
575 | 575 | ), |
576 | 576 | ), |
577 | 577 | ); |
578 | 578 | |
579 | - return $this->add_additional_fields_schema( $schema ); |
|
579 | + return $this->add_additional_fields_schema($schema); |
|
580 | 580 | } |
581 | 581 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Coupons controller class. |
@@ -47,25 +47,25 @@ discard block |
||
47 | 47 | $this->namespace, '/' . $this->rest_base, array( |
48 | 48 | array( |
49 | 49 | 'methods' => WP_REST_Server::READABLE, |
50 | - 'callback' => array( $this, 'get_items' ), |
|
51 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
50 | + 'callback' => array($this, 'get_items'), |
|
51 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
52 | 52 | 'args' => $this->get_collection_params(), |
53 | 53 | ), |
54 | 54 | array( |
55 | 55 | 'methods' => WP_REST_Server::CREATABLE, |
56 | - 'callback' => array( $this, 'create_item' ), |
|
57 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
56 | + 'callback' => array($this, 'create_item'), |
|
57 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
58 | 58 | 'args' => array_merge( |
59 | - $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
59 | + $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
60 | 60 | 'code' => array( |
61 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
61 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
62 | 62 | 'required' => true, |
63 | 63 | 'type' => 'string', |
64 | 64 | ), |
65 | 65 | ) |
66 | 66 | ), |
67 | 67 | ), |
68 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
68 | + 'schema' => array($this, 'get_public_item_schema'), |
|
69 | 69 | ) |
70 | 70 | ); |
71 | 71 | |
@@ -73,37 +73,37 @@ discard block |
||
73 | 73 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
74 | 74 | 'args' => array( |
75 | 75 | 'id' => array( |
76 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
76 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
77 | 77 | 'type' => 'integer', |
78 | 78 | ), |
79 | 79 | ), |
80 | 80 | array( |
81 | 81 | 'methods' => WP_REST_Server::READABLE, |
82 | - 'callback' => array( $this, 'get_item' ), |
|
83 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
82 | + 'callback' => array($this, 'get_item'), |
|
83 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
84 | 84 | 'args' => array( |
85 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
85 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
86 | 86 | ), |
87 | 87 | ), |
88 | 88 | array( |
89 | 89 | 'methods' => WP_REST_Server::EDITABLE, |
90 | - 'callback' => array( $this, 'update_item' ), |
|
91 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
92 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
90 | + 'callback' => array($this, 'update_item'), |
|
91 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
92 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
93 | 93 | ), |
94 | 94 | array( |
95 | 95 | 'methods' => WP_REST_Server::DELETABLE, |
96 | - 'callback' => array( $this, 'delete_item' ), |
|
97 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
96 | + 'callback' => array($this, 'delete_item'), |
|
97 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
98 | 98 | 'args' => array( |
99 | 99 | 'force' => array( |
100 | 100 | 'default' => false, |
101 | 101 | 'type' => 'boolean', |
102 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
102 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
103 | 103 | ), |
104 | 104 | ), |
105 | 105 | ), |
106 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
106 | + 'schema' => array($this, 'get_public_item_schema'), |
|
107 | 107 | ) |
108 | 108 | ); |
109 | 109 | |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | $this->namespace, '/' . $this->rest_base . '/batch', 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 | ); |
121 | 121 | } |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | * @param int $id Object ID. |
128 | 128 | * @return WC_Data |
129 | 129 | */ |
130 | - protected function get_object( $id ) { |
|
131 | - return new WC_Coupon( $id ); |
|
130 | + protected function get_object($id) { |
|
131 | + return new WC_Coupon($id); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,28 +138,28 @@ discard block |
||
138 | 138 | * @param WC_Data $object WC_Data instance. |
139 | 139 | * @return array |
140 | 140 | */ |
141 | - protected function get_formatted_item_data( $object ) { |
|
141 | + protected function get_formatted_item_data($object) { |
|
142 | 142 | $data = $object->get_data(); |
143 | 143 | |
144 | - $format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' ); |
|
145 | - $format_date = array( 'date_created', 'date_modified', 'date_expires' ); |
|
146 | - $format_null = array( 'usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items' ); |
|
144 | + $format_decimal = array('amount', 'minimum_amount', 'maximum_amount'); |
|
145 | + $format_date = array('date_created', 'date_modified', 'date_expires'); |
|
146 | + $format_null = array('usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items'); |
|
147 | 147 | |
148 | 148 | // Format decimal values. |
149 | - foreach ( $format_decimal as $key ) { |
|
150 | - $data[ $key ] = wc_format_decimal( $data[ $key ], 2 ); |
|
149 | + foreach ($format_decimal as $key) { |
|
150 | + $data[$key] = wc_format_decimal($data[$key], 2); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Format date values. |
154 | - foreach ( $format_date as $key ) { |
|
155 | - $datetime = $data[ $key ]; |
|
156 | - $data[ $key ] = wc_rest_prepare_date_response( $datetime, false ); |
|
157 | - $data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime ); |
|
154 | + foreach ($format_date as $key) { |
|
155 | + $datetime = $data[$key]; |
|
156 | + $data[$key] = wc_rest_prepare_date_response($datetime, false); |
|
157 | + $data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // Format null values. |
161 | - foreach ( $format_null as $key ) { |
|
162 | - $data[ $key ] = $data[ $key ] ? $data[ $key ] : null; |
|
161 | + foreach ($format_null as $key) { |
|
162 | + $data[$key] = $data[$key] ? $data[$key] : null; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return array( |
@@ -201,13 +201,13 @@ discard block |
||
201 | 201 | * @param WP_REST_Request $request Request object. |
202 | 202 | * @return WP_REST_Response |
203 | 203 | */ |
204 | - public function prepare_object_for_response( $object, $request ) { |
|
205 | - $data = $this->get_formatted_item_data( $object ); |
|
206 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
207 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
208 | - $data = $this->filter_response_by_context( $data, $context ); |
|
209 | - $response = rest_ensure_response( $data ); |
|
210 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
204 | + public function prepare_object_for_response($object, $request) { |
|
205 | + $data = $this->get_formatted_item_data($object); |
|
206 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
207 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
208 | + $data = $this->filter_response_by_context($data, $context); |
|
209 | + $response = rest_ensure_response($data); |
|
210 | + $response->add_links($this->prepare_links($object, $request)); |
|
211 | 211 | |
212 | 212 | /** |
213 | 213 | * Filter the data for a response. |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @param WC_Data $object Object data. |
220 | 220 | * @param WP_REST_Request $request Request object. |
221 | 221 | */ |
222 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
222 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -229,12 +229,12 @@ discard block |
||
229 | 229 | * @param WP_REST_Request $request Full details about the request. |
230 | 230 | * @return array |
231 | 231 | */ |
232 | - protected function prepare_objects_query( $request ) { |
|
233 | - $args = parent::prepare_objects_query( $request ); |
|
232 | + protected function prepare_objects_query($request) { |
|
233 | + $args = parent::prepare_objects_query($request); |
|
234 | 234 | |
235 | - if ( ! empty( $request['code'] ) ) { |
|
236 | - $id = wc_get_coupon_id_by_code( $request['code'] ); |
|
237 | - $args['post__in'] = array( $id ); |
|
235 | + if ( ! empty($request['code'])) { |
|
236 | + $id = wc_get_coupon_id_by_code($request['code']); |
|
237 | + $args['post__in'] = array($id); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | // Get only ids. |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | * @param array $schema Schema. |
250 | 250 | * @return bool |
251 | 251 | */ |
252 | - protected function filter_writable_props( $schema ) { |
|
253 | - return empty( $schema['readonly'] ); |
|
252 | + protected function filter_writable_props($schema) { |
|
253 | + return empty($schema['readonly']); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -260,47 +260,47 @@ discard block |
||
260 | 260 | * @param bool $creating If is creating a new object. |
261 | 261 | * @return WP_Error|WC_Data |
262 | 262 | */ |
263 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
264 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
265 | - $coupon = new WC_Coupon( $id ); |
|
263 | + protected function prepare_object_for_database($request, $creating = false) { |
|
264 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
265 | + $coupon = new WC_Coupon($id); |
|
266 | 266 | $schema = $this->get_item_schema(); |
267 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
267 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
268 | 268 | |
269 | 269 | // Validate required POST fields. |
270 | - if ( $creating && empty( $request['code'] ) ) { |
|
271 | - return new WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) ); |
|
270 | + if ($creating && empty($request['code'])) { |
|
271 | + return new WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400)); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | // Handle all writable props. |
275 | - foreach ( $data_keys as $key ) { |
|
276 | - $value = $request[ $key ]; |
|
275 | + foreach ($data_keys as $key) { |
|
276 | + $value = $request[$key]; |
|
277 | 277 | |
278 | - if ( ! is_null( $value ) ) { |
|
279 | - switch ( $key ) { |
|
278 | + if ( ! is_null($value)) { |
|
279 | + switch ($key) { |
|
280 | 280 | case 'code': |
281 | - $coupon_code = wc_format_coupon_code( $value ); |
|
281 | + $coupon_code = wc_format_coupon_code($value); |
|
282 | 282 | $id = $coupon->get_id() ? $coupon->get_id() : 0; |
283 | - $id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id ); |
|
283 | + $id_from_code = wc_get_coupon_id_by_code($coupon_code, $id); |
|
284 | 284 | |
285 | - if ( $id_from_code ) { |
|
286 | - return new WP_Error( 'woocommerce_rest_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce' ), array( 'status' => 400 ) ); |
|
285 | + if ($id_from_code) { |
|
286 | + return new WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400)); |
|
287 | 287 | } |
288 | 288 | |
289 | - $coupon->set_code( $coupon_code ); |
|
289 | + $coupon->set_code($coupon_code); |
|
290 | 290 | break; |
291 | 291 | case 'meta_data': |
292 | - if ( is_array( $value ) ) { |
|
293 | - foreach ( $value as $meta ) { |
|
294 | - $coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
292 | + if (is_array($value)) { |
|
293 | + foreach ($value as $meta) { |
|
294 | + $coupon->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
295 | 295 | } |
296 | 296 | } |
297 | 297 | break; |
298 | 298 | case 'description': |
299 | - $coupon->set_description( wp_filter_post_kses( $value ) ); |
|
299 | + $coupon->set_description(wp_filter_post_kses($value)); |
|
300 | 300 | break; |
301 | 301 | default: |
302 | - if ( is_callable( array( $coupon, "set_{$key}" ) ) ) { |
|
303 | - $coupon->{"set_{$key}"}( $value ); |
|
302 | + if (is_callable(array($coupon, "set_{$key}"))) { |
|
303 | + $coupon->{"set_{$key}"}($value); |
|
304 | 304 | } |
305 | 305 | break; |
306 | 306 | } |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | * @param WP_REST_Request $request Request object. |
318 | 318 | * @param bool $creating If is creating a new object. |
319 | 319 | */ |
320 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating ); |
|
320 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -332,194 +332,194 @@ discard block |
||
332 | 332 | 'type' => 'object', |
333 | 333 | 'properties' => array( |
334 | 334 | 'id' => array( |
335 | - 'description' => __( 'Unique identifier for the object.', 'woocommerce' ), |
|
335 | + 'description' => __('Unique identifier for the object.', 'woocommerce'), |
|
336 | 336 | 'type' => 'integer', |
337 | - 'context' => array( 'view', 'edit' ), |
|
337 | + 'context' => array('view', 'edit'), |
|
338 | 338 | 'readonly' => true, |
339 | 339 | ), |
340 | 340 | 'code' => array( |
341 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
341 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
342 | 342 | 'type' => 'string', |
343 | - 'context' => array( 'view', 'edit' ), |
|
343 | + 'context' => array('view', 'edit'), |
|
344 | 344 | ), |
345 | 345 | 'amount' => array( |
346 | - 'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce' ), |
|
346 | + 'description' => __('The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce'), |
|
347 | 347 | 'type' => 'string', |
348 | - 'context' => array( 'view', 'edit' ), |
|
348 | + 'context' => array('view', 'edit'), |
|
349 | 349 | ), |
350 | 350 | 'date_created' => array( |
351 | - 'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce' ), |
|
351 | + 'description' => __("The date the coupon was created, in the site's timezone.", 'woocommerce'), |
|
352 | 352 | 'type' => 'date-time', |
353 | - 'context' => array( 'view', 'edit' ), |
|
353 | + 'context' => array('view', 'edit'), |
|
354 | 354 | 'readonly' => true, |
355 | 355 | ), |
356 | 356 | 'date_created_gmt' => array( |
357 | - 'description' => __( 'The date the coupon was created, as GMT.', 'woocommerce' ), |
|
357 | + 'description' => __('The date the coupon was created, as GMT.', 'woocommerce'), |
|
358 | 358 | 'type' => 'date-time', |
359 | - 'context' => array( 'view', 'edit' ), |
|
359 | + 'context' => array('view', 'edit'), |
|
360 | 360 | 'readonly' => true, |
361 | 361 | ), |
362 | 362 | 'date_modified' => array( |
363 | - 'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce' ), |
|
363 | + 'description' => __("The date the coupon was last modified, in the site's timezone.", 'woocommerce'), |
|
364 | 364 | 'type' => 'date-time', |
365 | - 'context' => array( 'view', 'edit' ), |
|
365 | + 'context' => array('view', 'edit'), |
|
366 | 366 | 'readonly' => true, |
367 | 367 | ), |
368 | 368 | 'date_modified_gmt' => array( |
369 | - 'description' => __( 'The date the coupon was last modified, as GMT.', 'woocommerce' ), |
|
369 | + 'description' => __('The date the coupon was last modified, as GMT.', 'woocommerce'), |
|
370 | 370 | 'type' => 'date-time', |
371 | - 'context' => array( 'view', 'edit' ), |
|
371 | + 'context' => array('view', 'edit'), |
|
372 | 372 | 'readonly' => true, |
373 | 373 | ), |
374 | 374 | 'discount_type' => array( |
375 | - 'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ), |
|
375 | + 'description' => __('Determines the type of discount that will be applied.', 'woocommerce'), |
|
376 | 376 | 'type' => 'string', |
377 | 377 | 'default' => 'fixed_cart', |
378 | - 'enum' => array_keys( wc_get_coupon_types() ), |
|
379 | - 'context' => array( 'view', 'edit' ), |
|
378 | + 'enum' => array_keys(wc_get_coupon_types()), |
|
379 | + 'context' => array('view', 'edit'), |
|
380 | 380 | ), |
381 | 381 | 'description' => array( |
382 | - 'description' => __( 'Coupon description.', 'woocommerce' ), |
|
382 | + 'description' => __('Coupon description.', 'woocommerce'), |
|
383 | 383 | 'type' => 'string', |
384 | - 'context' => array( 'view', 'edit' ), |
|
384 | + 'context' => array('view', 'edit'), |
|
385 | 385 | ), |
386 | 386 | 'date_expires' => array( |
387 | - 'description' => __( "The date the coupon expires, in the site's timezone.", 'woocommerce' ), |
|
387 | + 'description' => __("The date the coupon expires, in the site's timezone.", 'woocommerce'), |
|
388 | 388 | 'type' => 'string', |
389 | - 'context' => array( 'view', 'edit' ), |
|
389 | + 'context' => array('view', 'edit'), |
|
390 | 390 | ), |
391 | 391 | 'date_expires_gmt' => array( |
392 | - 'description' => __( 'The date the coupon expires, as GMT.', 'woocommerce' ), |
|
392 | + 'description' => __('The date the coupon expires, as GMT.', 'woocommerce'), |
|
393 | 393 | 'type' => 'string', |
394 | - 'context' => array( 'view', 'edit' ), |
|
394 | + 'context' => array('view', 'edit'), |
|
395 | 395 | ), |
396 | 396 | 'usage_count' => array( |
397 | - 'description' => __( 'Number of times the coupon has been used already.', 'woocommerce' ), |
|
397 | + 'description' => __('Number of times the coupon has been used already.', 'woocommerce'), |
|
398 | 398 | 'type' => 'integer', |
399 | - 'context' => array( 'view', 'edit' ), |
|
399 | + 'context' => array('view', 'edit'), |
|
400 | 400 | 'readonly' => true, |
401 | 401 | ), |
402 | 402 | 'individual_use' => array( |
403 | - 'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce' ), |
|
403 | + 'description' => __('If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce'), |
|
404 | 404 | 'type' => 'boolean', |
405 | 405 | 'default' => false, |
406 | - 'context' => array( 'view', 'edit' ), |
|
406 | + 'context' => array('view', 'edit'), |
|
407 | 407 | ), |
408 | 408 | 'product_ids' => array( |
409 | - 'description' => __( 'List of product IDs the coupon can be used on.', 'woocommerce' ), |
|
409 | + 'description' => __('List of product IDs the coupon can be used on.', 'woocommerce'), |
|
410 | 410 | 'type' => 'array', |
411 | 411 | 'items' => array( |
412 | 412 | 'type' => 'integer', |
413 | 413 | ), |
414 | - 'context' => array( 'view', 'edit' ), |
|
414 | + 'context' => array('view', 'edit'), |
|
415 | 415 | ), |
416 | 416 | 'excluded_product_ids' => array( |
417 | - 'description' => __( 'List of product IDs the coupon cannot be used on.', 'woocommerce' ), |
|
417 | + 'description' => __('List of product IDs the coupon cannot be used on.', 'woocommerce'), |
|
418 | 418 | 'type' => 'array', |
419 | 419 | 'items' => array( |
420 | 420 | 'type' => 'integer', |
421 | 421 | ), |
422 | - 'context' => array( 'view', 'edit' ), |
|
422 | + 'context' => array('view', 'edit'), |
|
423 | 423 | ), |
424 | 424 | 'usage_limit' => array( |
425 | - 'description' => __( 'How many times the coupon can be used in total.', 'woocommerce' ), |
|
425 | + 'description' => __('How many times the coupon can be used in total.', 'woocommerce'), |
|
426 | 426 | 'type' => 'integer', |
427 | - 'context' => array( 'view', 'edit' ), |
|
427 | + 'context' => array('view', 'edit'), |
|
428 | 428 | ), |
429 | 429 | 'usage_limit_per_user' => array( |
430 | - 'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce' ), |
|
430 | + 'description' => __('How many times the coupon can be used per customer.', 'woocommerce'), |
|
431 | 431 | 'type' => 'integer', |
432 | - 'context' => array( 'view', 'edit' ), |
|
432 | + 'context' => array('view', 'edit'), |
|
433 | 433 | ), |
434 | 434 | 'limit_usage_to_x_items' => array( |
435 | - 'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'woocommerce' ), |
|
435 | + 'description' => __('Max number of items in the cart the coupon can be applied to.', 'woocommerce'), |
|
436 | 436 | 'type' => 'integer', |
437 | - 'context' => array( 'view', 'edit' ), |
|
437 | + 'context' => array('view', 'edit'), |
|
438 | 438 | ), |
439 | 439 | 'free_shipping' => array( |
440 | - 'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce' ), |
|
440 | + 'description' => __('If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce'), |
|
441 | 441 | 'type' => 'boolean', |
442 | 442 | 'default' => false, |
443 | - 'context' => array( 'view', 'edit' ), |
|
443 | + 'context' => array('view', 'edit'), |
|
444 | 444 | ), |
445 | 445 | 'product_categories' => array( |
446 | - 'description' => __( 'List of category IDs the coupon applies to.', 'woocommerce' ), |
|
446 | + 'description' => __('List of category IDs the coupon applies to.', 'woocommerce'), |
|
447 | 447 | 'type' => 'array', |
448 | 448 | 'items' => array( |
449 | 449 | 'type' => 'integer', |
450 | 450 | ), |
451 | - 'context' => array( 'view', 'edit' ), |
|
451 | + 'context' => array('view', 'edit'), |
|
452 | 452 | ), |
453 | 453 | 'excluded_product_categories' => array( |
454 | - 'description' => __( 'List of category IDs the coupon does not apply to.', 'woocommerce' ), |
|
454 | + 'description' => __('List of category IDs the coupon does not apply to.', 'woocommerce'), |
|
455 | 455 | 'type' => 'array', |
456 | 456 | 'items' => array( |
457 | 457 | 'type' => 'integer', |
458 | 458 | ), |
459 | - 'context' => array( 'view', 'edit' ), |
|
459 | + 'context' => array('view', 'edit'), |
|
460 | 460 | ), |
461 | 461 | 'exclude_sale_items' => array( |
462 | - 'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'woocommerce' ), |
|
462 | + 'description' => __('If true, this coupon will not be applied to items that have sale prices.', 'woocommerce'), |
|
463 | 463 | 'type' => 'boolean', |
464 | 464 | 'default' => false, |
465 | - 'context' => array( 'view', 'edit' ), |
|
465 | + 'context' => array('view', 'edit'), |
|
466 | 466 | ), |
467 | 467 | 'minimum_amount' => array( |
468 | - 'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce' ), |
|
468 | + 'description' => __('Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce'), |
|
469 | 469 | 'type' => 'string', |
470 | - 'context' => array( 'view', 'edit' ), |
|
470 | + 'context' => array('view', 'edit'), |
|
471 | 471 | ), |
472 | 472 | 'maximum_amount' => array( |
473 | - 'description' => __( 'Maximum order amount allowed when using the coupon.', 'woocommerce' ), |
|
473 | + 'description' => __('Maximum order amount allowed when using the coupon.', 'woocommerce'), |
|
474 | 474 | 'type' => 'string', |
475 | - 'context' => array( 'view', 'edit' ), |
|
475 | + 'context' => array('view', 'edit'), |
|
476 | 476 | ), |
477 | 477 | 'email_restrictions' => array( |
478 | - 'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ), |
|
478 | + 'description' => __('List of email addresses that can use this coupon.', 'woocommerce'), |
|
479 | 479 | 'type' => 'array', |
480 | 480 | 'items' => array( |
481 | 481 | 'type' => 'string', |
482 | 482 | ), |
483 | - 'context' => array( 'view', 'edit' ), |
|
483 | + 'context' => array('view', 'edit'), |
|
484 | 484 | ), |
485 | 485 | 'used_by' => array( |
486 | - 'description' => __( 'List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce' ), |
|
486 | + 'description' => __('List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce'), |
|
487 | 487 | 'type' => 'array', |
488 | 488 | 'items' => array( |
489 | 489 | 'type' => 'integer', |
490 | 490 | ), |
491 | - 'context' => array( 'view', 'edit' ), |
|
491 | + 'context' => array('view', 'edit'), |
|
492 | 492 | 'readonly' => true, |
493 | 493 | ), |
494 | 494 | 'meta_data' => array( |
495 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
495 | + 'description' => __('Meta data.', 'woocommerce'), |
|
496 | 496 | 'type' => 'array', |
497 | - 'context' => array( 'view', 'edit' ), |
|
497 | + 'context' => array('view', 'edit'), |
|
498 | 498 | 'items' => array( |
499 | 499 | 'type' => 'object', |
500 | 500 | 'properties' => array( |
501 | 501 | 'id' => array( |
502 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
502 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
503 | 503 | 'type' => 'integer', |
504 | - 'context' => array( 'view', 'edit' ), |
|
504 | + 'context' => array('view', 'edit'), |
|
505 | 505 | 'readonly' => true, |
506 | 506 | ), |
507 | 507 | 'key' => array( |
508 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
508 | + 'description' => __('Meta key.', 'woocommerce'), |
|
509 | 509 | 'type' => 'string', |
510 | - 'context' => array( 'view', 'edit' ), |
|
510 | + 'context' => array('view', 'edit'), |
|
511 | 511 | ), |
512 | 512 | 'value' => array( |
513 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
513 | + 'description' => __('Meta value.', 'woocommerce'), |
|
514 | 514 | 'type' => 'mixed', |
515 | - 'context' => array( 'view', 'edit' ), |
|
515 | + 'context' => array('view', 'edit'), |
|
516 | 516 | ), |
517 | 517 | ), |
518 | 518 | ), |
519 | 519 | ), |
520 | 520 | ), |
521 | 521 | ); |
522 | - return $this->add_additional_fields_schema( $schema ); |
|
522 | + return $this->add_additional_fields_schema($schema); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | /** |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | $params = parent::get_collection_params(); |
532 | 532 | |
533 | 533 | $params['code'] = array( |
534 | - 'description' => __( 'Limit result set to resources with a specific code.', 'woocommerce' ), |
|
534 | + 'description' => __('Limit result set to resources with a specific code.', 'woocommerce'), |
|
535 | 535 | 'type' => 'string', |
536 | 536 | 'sanitize_callback' => 'sanitize_text_field', |
537 | 537 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Shipping Zone Locations class. |
@@ -26,22 +26,22 @@ discard block |
||
26 | 26 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)/locations', 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 | ); |
47 | 47 | } |
@@ -52,23 +52,23 @@ discard block |
||
52 | 52 | * @param WP_REST_Request $request Request data. |
53 | 53 | * @return WP_REST_Response|WP_Error |
54 | 54 | */ |
55 | - public function get_items( $request ) { |
|
56 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
55 | + public function get_items($request) { |
|
56 | + $zone = $this->get_zone((int) $request['id']); |
|
57 | 57 | |
58 | - if ( is_wp_error( $zone ) ) { |
|
58 | + if (is_wp_error($zone)) { |
|
59 | 59 | return $zone; |
60 | 60 | } |
61 | 61 | |
62 | 62 | $locations = $zone->get_zone_locations(); |
63 | 63 | $data = array(); |
64 | 64 | |
65 | - foreach ( $locations as $location_obj ) { |
|
66 | - $location = $this->prepare_item_for_response( $location_obj, $request ); |
|
67 | - $location = $this->prepare_response_for_collection( $location ); |
|
65 | + foreach ($locations as $location_obj) { |
|
66 | + $location = $this->prepare_item_for_response($location_obj, $request); |
|
67 | + $location = $this->prepare_response_for_collection($location); |
|
68 | 68 | $data[] = $location; |
69 | 69 | } |
70 | 70 | |
71 | - return rest_ensure_response( $data ); |
|
71 | + return rest_ensure_response($data); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,41 +77,41 @@ discard block |
||
77 | 77 | * @param WP_REST_Request $request Request data. |
78 | 78 | * @return WP_REST_Response|WP_Error |
79 | 79 | */ |
80 | - public function update_items( $request ) { |
|
81 | - $zone = $this->get_zone( (int) $request['id'] ); |
|
80 | + public function update_items($request) { |
|
81 | + $zone = $this->get_zone((int) $request['id']); |
|
82 | 82 | |
83 | - if ( is_wp_error( $zone ) ) { |
|
83 | + if (is_wp_error($zone)) { |
|
84 | 84 | return $zone; |
85 | 85 | } |
86 | 86 | |
87 | - if ( 0 === $zone->get_id() ) { |
|
88 | - 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 ) ); |
|
87 | + if (0 === $zone->get_id()) { |
|
88 | + 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)); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | $raw_locations = $request->get_json_params(); |
92 | 92 | $locations = array(); |
93 | 93 | |
94 | - foreach ( (array) $raw_locations as $raw_location ) { |
|
95 | - if ( empty( $raw_location['code'] ) ) { |
|
94 | + foreach ((array) $raw_locations as $raw_location) { |
|
95 | + if (empty($raw_location['code'])) { |
|
96 | 96 | continue; |
97 | 97 | } |
98 | 98 | |
99 | - $type = ! empty( $raw_location['type'] ) ? sanitize_text_field( $raw_location['type'] ) : 'country'; |
|
99 | + $type = ! empty($raw_location['type']) ? sanitize_text_field($raw_location['type']) : 'country'; |
|
100 | 100 | |
101 | - if ( ! in_array( $type, array( 'postcode', 'state', 'country', 'continent' ), true ) ) { |
|
101 | + if ( ! in_array($type, array('postcode', 'state', 'country', 'continent'), true)) { |
|
102 | 102 | continue; |
103 | 103 | } |
104 | 104 | |
105 | 105 | $locations[] = array( |
106 | - 'code' => sanitize_text_field( $raw_location['code'] ), |
|
107 | - 'type' => sanitize_text_field( $type ), |
|
106 | + 'code' => sanitize_text_field($raw_location['code']), |
|
107 | + 'type' => sanitize_text_field($type), |
|
108 | 108 | ); |
109 | 109 | } |
110 | 110 | |
111 | - $zone->set_locations( $locations ); |
|
111 | + $zone->set_locations($locations); |
|
112 | 112 | $zone->save(); |
113 | 113 | |
114 | - return $this->get_items( $request ); |
|
114 | + return $this->get_items($request); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | * @param WP_REST_Request $request Request object. |
122 | 122 | * @return WP_REST_Response $response |
123 | 123 | */ |
124 | - public function prepare_item_for_response( $item, $request ) { |
|
125 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
126 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
127 | - $data = $this->filter_response_by_context( $data, $context ); |
|
124 | + public function prepare_item_for_response($item, $request) { |
|
125 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
126 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
127 | + $data = $this->filter_response_by_context($data, $context); |
|
128 | 128 | |
129 | 129 | // Wrap the data in a response object. |
130 | - $response = rest_ensure_response( $data ); |
|
130 | + $response = rest_ensure_response($data); |
|
131 | 131 | |
132 | - $response->add_links( $this->prepare_links( (int) $request['id'] ) ); |
|
132 | + $response->add_links($this->prepare_links((int) $request['id'])); |
|
133 | 133 | |
134 | 134 | return $response; |
135 | 135 | } |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | * @param int $zone_id Given Shipping Zone ID. |
141 | 141 | * @return array Links for the given Shipping Zone Location. |
142 | 142 | */ |
143 | - protected function prepare_links( $zone_id ) { |
|
143 | + protected function prepare_links($zone_id) { |
|
144 | 144 | $base = '/' . $this->namespace . '/' . $this->rest_base . '/' . $zone_id; |
145 | 145 | $links = array( |
146 | 146 | 'collection' => array( |
147 | - 'href' => rest_url( $base . '/locations' ), |
|
147 | + 'href' => rest_url($base . '/locations'), |
|
148 | 148 | ), |
149 | 149 | 'describes' => array( |
150 | - 'href' => rest_url( $base ), |
|
150 | + 'href' => rest_url($base), |
|
151 | 151 | ), |
152 | 152 | ); |
153 | 153 | |
@@ -166,12 +166,12 @@ discard block |
||
166 | 166 | 'type' => 'object', |
167 | 167 | 'properties' => array( |
168 | 168 | 'code' => array( |
169 | - 'description' => __( 'Shipping zone location code.', 'woocommerce' ), |
|
169 | + 'description' => __('Shipping zone location code.', 'woocommerce'), |
|
170 | 170 | 'type' => 'string', |
171 | - 'context' => array( 'view', 'edit' ), |
|
171 | + 'context' => array('view', 'edit'), |
|
172 | 172 | ), |
173 | 173 | 'type' => array( |
174 | - 'description' => __( 'Shipping zone location type.', 'woocommerce' ), |
|
174 | + 'description' => __('Shipping zone location type.', 'woocommerce'), |
|
175 | 175 | 'type' => 'string', |
176 | 176 | 'default' => 'country', |
177 | 177 | 'enum' => array( |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | 'country', |
181 | 181 | 'continent', |
182 | 182 | ), |
183 | - 'context' => array( 'view', 'edit' ), |
|
183 | + 'context' => array('view', 'edit'), |
|
184 | 184 | ), |
185 | 185 | ), |
186 | 186 | ); |
187 | 187 | |
188 | - return $this->add_additional_fields_schema( $schema ); |
|
188 | + return $this->add_additional_fields_schema($schema); |
|
189 | 189 | } |
190 | 190 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Customers controller class. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @param WP_REST_Request $request Request object. |
33 | 33 | * @return WP_REST_Response $response Response data. |
34 | 34 | */ |
35 | - public function prepare_item_for_response( $download, $request ) { |
|
35 | + public function prepare_item_for_response($download, $request) { |
|
36 | 36 | $data = array( |
37 | 37 | 'download_id' => $download->download_id, |
38 | 38 | 'download_url' => $download->download_url, |
@@ -42,19 +42,19 @@ discard block |
||
42 | 42 | 'order_id' => $download->order_id, |
43 | 43 | 'order_key' => $download->order_key, |
44 | 44 | 'downloads_remaining' => '' === $download->downloads_remaining ? 'unlimited' : $download->downloads_remaining, |
45 | - 'access_expires' => $download->access_expires ? wc_rest_prepare_date_response( $download->access_expires ) : 'never', |
|
46 | - 'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response( get_gmt_from_date( $download->access_expires ) ) : 'never', |
|
45 | + 'access_expires' => $download->access_expires ? wc_rest_prepare_date_response($download->access_expires) : 'never', |
|
46 | + 'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response(get_gmt_from_date($download->access_expires)) : 'never', |
|
47 | 47 | 'file' => $download->file, |
48 | 48 | ); |
49 | 49 | |
50 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
51 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
52 | - $data = $this->filter_response_by_context( $data, $context ); |
|
50 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
51 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
52 | + $data = $this->filter_response_by_context($data, $context); |
|
53 | 53 | |
54 | 54 | // Wrap the data in a response object. |
55 | - $response = rest_ensure_response( $data ); |
|
55 | + $response = rest_ensure_response($data); |
|
56 | 56 | |
57 | - $response->add_links( $this->prepare_links( $download, $request ) ); |
|
57 | + $response->add_links($this->prepare_links($download, $request)); |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Filter customer download data returned from the REST API. |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param stdClass $download Download object used to create response. |
64 | 64 | * @param WP_REST_Request $request Request object. |
65 | 65 | */ |
66 | - return apply_filters( 'woocommerce_rest_prepare_customer_download', $response, $download, $request ); |
|
66 | + return apply_filters('woocommerce_rest_prepare_customer_download', $response, $download, $request); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -78,81 +78,81 @@ discard block |
||
78 | 78 | 'type' => 'object', |
79 | 79 | 'properties' => array( |
80 | 80 | 'download_id' => array( |
81 | - 'description' => __( 'Download ID.', 'woocommerce' ), |
|
81 | + 'description' => __('Download ID.', 'woocommerce'), |
|
82 | 82 | 'type' => 'string', |
83 | - 'context' => array( 'view' ), |
|
83 | + 'context' => array('view'), |
|
84 | 84 | 'readonly' => true, |
85 | 85 | ), |
86 | 86 | 'download_url' => array( |
87 | - 'description' => __( 'Download file URL.', 'woocommerce' ), |
|
87 | + 'description' => __('Download file URL.', 'woocommerce'), |
|
88 | 88 | 'type' => 'string', |
89 | - 'context' => array( 'view' ), |
|
89 | + 'context' => array('view'), |
|
90 | 90 | 'readonly' => true, |
91 | 91 | ), |
92 | 92 | 'product_id' => array( |
93 | - 'description' => __( 'Downloadable product ID.', 'woocommerce' ), |
|
93 | + 'description' => __('Downloadable product ID.', 'woocommerce'), |
|
94 | 94 | 'type' => 'integer', |
95 | - 'context' => array( 'view' ), |
|
95 | + 'context' => array('view'), |
|
96 | 96 | 'readonly' => true, |
97 | 97 | ), |
98 | 98 | 'product_name' => array( |
99 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
99 | + 'description' => __('Product name.', 'woocommerce'), |
|
100 | 100 | 'type' => 'string', |
101 | - 'context' => array( 'view' ), |
|
101 | + 'context' => array('view'), |
|
102 | 102 | 'readonly' => true, |
103 | 103 | ), |
104 | 104 | 'download_name' => array( |
105 | - 'description' => __( 'Downloadable file name.', 'woocommerce' ), |
|
105 | + 'description' => __('Downloadable file name.', 'woocommerce'), |
|
106 | 106 | 'type' => 'string', |
107 | - 'context' => array( 'view' ), |
|
107 | + 'context' => array('view'), |
|
108 | 108 | 'readonly' => true, |
109 | 109 | ), |
110 | 110 | 'order_id' => array( |
111 | - 'description' => __( 'Order ID.', 'woocommerce' ), |
|
111 | + 'description' => __('Order ID.', 'woocommerce'), |
|
112 | 112 | 'type' => 'integer', |
113 | - 'context' => array( 'view' ), |
|
113 | + 'context' => array('view'), |
|
114 | 114 | 'readonly' => true, |
115 | 115 | ), |
116 | 116 | 'order_key' => array( |
117 | - 'description' => __( 'Order key.', 'woocommerce' ), |
|
117 | + 'description' => __('Order key.', 'woocommerce'), |
|
118 | 118 | 'type' => 'string', |
119 | - 'context' => array( 'view' ), |
|
119 | + 'context' => array('view'), |
|
120 | 120 | 'readonly' => true, |
121 | 121 | ), |
122 | 122 | 'downloads_remaining' => array( |
123 | - 'description' => __( 'Number of downloads remaining.', 'woocommerce' ), |
|
123 | + 'description' => __('Number of downloads remaining.', 'woocommerce'), |
|
124 | 124 | 'type' => 'string', |
125 | - 'context' => array( 'view' ), |
|
125 | + 'context' => array('view'), |
|
126 | 126 | 'readonly' => true, |
127 | 127 | ), |
128 | 128 | 'access_expires' => array( |
129 | - 'description' => __( "The date when download access expires, in the site's timezone.", 'woocommerce' ), |
|
129 | + 'description' => __("The date when download access expires, in the site's timezone.", 'woocommerce'), |
|
130 | 130 | 'type' => 'string', |
131 | - 'context' => array( 'view' ), |
|
131 | + 'context' => array('view'), |
|
132 | 132 | 'readonly' => true, |
133 | 133 | ), |
134 | 134 | 'access_expires_gmt' => array( |
135 | - 'description' => __( 'The date when download access expires, as GMT.', 'woocommerce' ), |
|
135 | + 'description' => __('The date when download access expires, as GMT.', 'woocommerce'), |
|
136 | 136 | 'type' => 'string', |
137 | - 'context' => array( 'view' ), |
|
137 | + 'context' => array('view'), |
|
138 | 138 | 'readonly' => true, |
139 | 139 | ), |
140 | 140 | 'file' => array( |
141 | - 'description' => __( 'File details.', 'woocommerce' ), |
|
141 | + 'description' => __('File details.', 'woocommerce'), |
|
142 | 142 | 'type' => 'object', |
143 | - 'context' => array( 'view' ), |
|
143 | + 'context' => array('view'), |
|
144 | 144 | 'readonly' => true, |
145 | 145 | 'properties' => array( |
146 | 146 | 'name' => array( |
147 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
147 | + 'description' => __('File name.', 'woocommerce'), |
|
148 | 148 | 'type' => 'string', |
149 | - 'context' => array( 'view' ), |
|
149 | + 'context' => array('view'), |
|
150 | 150 | 'readonly' => true, |
151 | 151 | ), |
152 | 152 | 'file' => array( |
153 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
153 | + 'description' => __('File URL.', 'woocommerce'), |
|
154 | 154 | 'type' => 'string', |
155 | - 'context' => array( 'view' ), |
|
155 | + 'context' => array('view'), |
|
156 | 156 | 'readonly' => true, |
157 | 157 | ), |
158 | 158 | ), |
@@ -160,6 +160,6 @@ discard block |
||
160 | 160 | ), |
161 | 161 | ); |
162 | 162 | |
163 | - return $this->add_additional_fields_schema( $schema ); |
|
163 | + return $this->add_additional_fields_schema($schema); |
|
164 | 164 | } |
165 | 165 | } |
@@ -5,7 +5,7 @@ |
||
5 | 5 | * @package WooCommerce/RestApi |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Controllers class. |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Paymenga gateways controller class. |
@@ -40,36 +40,36 @@ discard block |
||
40 | 40 | $this->namespace, '/' . $this->rest_base, array( |
41 | 41 | array( |
42 | 42 | 'methods' => WP_REST_Server::READABLE, |
43 | - 'callback' => array( $this, 'get_items' ), |
|
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
43 | + 'callback' => array($this, 'get_items'), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | 45 | 'args' => $this->get_collection_params(), |
46 | 46 | ), |
47 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
47 | + 'schema' => array($this, 'get_public_item_schema'), |
|
48 | 48 | ) |
49 | 49 | ); |
50 | 50 | register_rest_route( |
51 | 51 | $this->namespace, '/' . $this->rest_base . '/(?P<id>[\w-]+)', array( |
52 | 52 | 'args' => array( |
53 | 53 | 'id' => array( |
54 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
54 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
55 | 55 | 'type' => 'string', |
56 | 56 | ), |
57 | 57 | ), |
58 | 58 | array( |
59 | 59 | 'methods' => WP_REST_Server::READABLE, |
60 | - 'callback' => array( $this, 'get_item' ), |
|
61 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
60 | + 'callback' => array($this, 'get_item'), |
|
61 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
62 | 62 | 'args' => array( |
63 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
63 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
64 | 64 | ), |
65 | 65 | ), |
66 | 66 | array( |
67 | 67 | 'methods' => WP_REST_Server::EDITABLE, |
68 | - 'callback' => array( $this, 'update_item' ), |
|
69 | - 'permission_callback' => array( $this, 'update_items_permissions_check' ), |
|
70 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
68 | + 'callback' => array($this, 'update_item'), |
|
69 | + 'permission_callback' => array($this, 'update_items_permissions_check'), |
|
70 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
71 | 71 | ), |
72 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
72 | + 'schema' => array($this, 'get_public_item_schema'), |
|
73 | 73 | ) |
74 | 74 | ); |
75 | 75 | } |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * @param WP_REST_Request $request Full details about the request. |
81 | 81 | * @return WP_Error|boolean |
82 | 82 | */ |
83 | - public function get_items_permissions_check( $request ) { |
|
84 | - if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'read' ) ) { |
|
85 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
83 | + public function get_items_permissions_check($request) { |
|
84 | + if ( ! wc_rest_check_manager_permissions('payment_gateways', 'read')) { |
|
85 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
86 | 86 | } |
87 | 87 | return true; |
88 | 88 | } |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | * @param WP_REST_Request $request Full details about the request. |
94 | 94 | * @return WP_Error|boolean |
95 | 95 | */ |
96 | - public function get_item_permissions_check( $request ) { |
|
97 | - if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'read' ) ) { |
|
98 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
96 | + public function get_item_permissions_check($request) { |
|
97 | + if ( ! wc_rest_check_manager_permissions('payment_gateways', 'read')) { |
|
98 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
99 | 99 | } |
100 | 100 | return true; |
101 | 101 | } |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param WP_REST_Request $request Full details about the request. |
107 | 107 | * @return WP_Error|boolean |
108 | 108 | */ |
109 | - public function update_items_permissions_check( $request ) { |
|
110 | - if ( ! wc_rest_check_manager_permissions( 'payment_gateways', 'edit' ) ) { |
|
111 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
109 | + public function update_items_permissions_check($request) { |
|
110 | + if ( ! wc_rest_check_manager_permissions('payment_gateways', 'edit')) { |
|
111 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
112 | 112 | } |
113 | 113 | return true; |
114 | 114 | } |
@@ -119,16 +119,16 @@ discard block |
||
119 | 119 | * @param WP_REST_Request $request Full details about the request. |
120 | 120 | * @return WP_Error|WP_REST_Response |
121 | 121 | */ |
122 | - public function get_items( $request ) { |
|
122 | + public function get_items($request) { |
|
123 | 123 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
124 | 124 | $response = array(); |
125 | - foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) { |
|
125 | + foreach ($payment_gateways as $payment_gateway_id => $payment_gateway) { |
|
126 | 126 | $payment_gateway->id = $payment_gateway_id; |
127 | - $gateway = $this->prepare_item_for_response( $payment_gateway, $request ); |
|
128 | - $gateway = $this->prepare_response_for_collection( $gateway ); |
|
127 | + $gateway = $this->prepare_item_for_response($payment_gateway, $request); |
|
128 | + $gateway = $this->prepare_response_for_collection($gateway); |
|
129 | 129 | $response[] = $gateway; |
130 | 130 | } |
131 | - return rest_ensure_response( $response ); |
|
131 | + return rest_ensure_response($response); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -137,15 +137,15 @@ discard block |
||
137 | 137 | * @param WP_REST_Request $request Request data. |
138 | 138 | * @return WP_REST_Response|WP_Error |
139 | 139 | */ |
140 | - public function get_item( $request ) { |
|
141 | - $gateway = $this->get_gateway( $request ); |
|
140 | + public function get_item($request) { |
|
141 | + $gateway = $this->get_gateway($request); |
|
142 | 142 | |
143 | - if ( is_null( $gateway ) ) { |
|
144 | - return new WP_Error( 'woocommerce_rest_payment_gateway_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
143 | + if (is_null($gateway)) { |
|
144 | + return new WP_Error('woocommerce_rest_payment_gateway_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
145 | 145 | } |
146 | 146 | |
147 | - $gateway = $this->prepare_item_for_response( $gateway, $request ); |
|
148 | - return rest_ensure_response( $gateway ); |
|
147 | + $gateway = $this->prepare_item_for_response($gateway, $request); |
|
148 | + return rest_ensure_response($gateway); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * @param WP_REST_Request $request Request data. |
155 | 155 | * @return WP_REST_Response|WP_Error |
156 | 156 | */ |
157 | - public function update_item( $request ) { |
|
158 | - $gateway = $this->get_gateway( $request ); |
|
157 | + public function update_item($request) { |
|
158 | + $gateway = $this->get_gateway($request); |
|
159 | 159 | |
160 | - if ( is_null( $gateway ) ) { |
|
161 | - return new WP_Error( 'woocommerce_rest_payment_gateway_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
160 | + if (is_null($gateway)) { |
|
161 | + return new WP_Error('woocommerce_rest_payment_gateway_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // Get settings. |
@@ -166,60 +166,60 @@ discard block |
||
166 | 166 | $settings = $gateway->settings; |
167 | 167 | |
168 | 168 | // Update settings. |
169 | - if ( isset( $request['settings'] ) ) { |
|
169 | + if (isset($request['settings'])) { |
|
170 | 170 | $errors_found = false; |
171 | - foreach ( $gateway->form_fields as $key => $field ) { |
|
172 | - if ( isset( $request['settings'][ $key ] ) ) { |
|
173 | - if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { |
|
174 | - $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); |
|
171 | + foreach ($gateway->form_fields as $key => $field) { |
|
172 | + if (isset($request['settings'][$key])) { |
|
173 | + if (is_callable(array($this, 'validate_setting_' . $field['type'] . '_field'))) { |
|
174 | + $value = $this->{'validate_setting_' . $field['type'] . '_field'}($request['settings'][$key], $field); |
|
175 | 175 | } else { |
176 | - $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); |
|
176 | + $value = $this->validate_setting_text_field($request['settings'][$key], $field); |
|
177 | 177 | } |
178 | - if ( is_wp_error( $value ) ) { |
|
178 | + if (is_wp_error($value)) { |
|
179 | 179 | $errors_found = true; |
180 | 180 | break; |
181 | 181 | } |
182 | - $settings[ $key ] = $value; |
|
182 | + $settings[$key] = $value; |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
186 | - if ( $errors_found ) { |
|
187 | - return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
186 | + if ($errors_found) { |
|
187 | + return new WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | 191 | // Update if this method is enabled or not. |
192 | - if ( isset( $request['enabled'] ) ) { |
|
193 | - $settings['enabled'] = wc_bool_to_string( $request['enabled'] ); |
|
192 | + if (isset($request['enabled'])) { |
|
193 | + $settings['enabled'] = wc_bool_to_string($request['enabled']); |
|
194 | 194 | $gateway->enabled = $settings['enabled']; |
195 | 195 | } |
196 | 196 | |
197 | 197 | // Update title. |
198 | - if ( isset( $request['title'] ) ) { |
|
198 | + if (isset($request['title'])) { |
|
199 | 199 | $settings['title'] = $request['title']; |
200 | 200 | $gateway->title = $settings['title']; |
201 | 201 | } |
202 | 202 | |
203 | 203 | // Update description. |
204 | - if ( isset( $request['description'] ) ) { |
|
204 | + if (isset($request['description'])) { |
|
205 | 205 | $settings['description'] = $request['description']; |
206 | 206 | $gateway->description = $settings['description']; |
207 | 207 | } |
208 | 208 | |
209 | 209 | // Update options. |
210 | 210 | $gateway->settings = $settings; |
211 | - update_option( $gateway->get_option_key(), apply_filters( 'woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway ) ); |
|
211 | + update_option($gateway->get_option_key(), apply_filters('woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway)); |
|
212 | 212 | |
213 | 213 | // Update order. |
214 | - if ( isset( $request['order'] ) ) { |
|
215 | - $order = (array) get_option( 'woocommerce_gateway_order' ); |
|
216 | - $order[ $gateway->id ] = $request['order']; |
|
217 | - update_option( 'woocommerce_gateway_order', $order ); |
|
218 | - $gateway->order = absint( $request['order'] ); |
|
214 | + if (isset($request['order'])) { |
|
215 | + $order = (array) get_option('woocommerce_gateway_order'); |
|
216 | + $order[$gateway->id] = $request['order']; |
|
217 | + update_option('woocommerce_gateway_order', $order); |
|
218 | + $gateway->order = absint($request['order']); |
|
219 | 219 | } |
220 | 220 | |
221 | - $gateway = $this->prepare_item_for_response( $gateway, $request ); |
|
222 | - return rest_ensure_response( $gateway ); |
|
221 | + $gateway = $this->prepare_item_for_response($gateway, $request); |
|
222 | + return rest_ensure_response($gateway); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -228,11 +228,11 @@ discard block |
||
228 | 228 | * @param WP_REST_Request $request Request data. |
229 | 229 | * @return WP_REST_Response|null |
230 | 230 | */ |
231 | - public function get_gateway( $request ) { |
|
231 | + public function get_gateway($request) { |
|
232 | 232 | $gateway = null; |
233 | 233 | $payment_gateways = WC()->payment_gateways->payment_gateways(); |
234 | - foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) { |
|
235 | - if ( $request['id'] !== $payment_gateway_id ) { |
|
234 | + foreach ($payment_gateways as $payment_gateway_id => $payment_gateway) { |
|
235 | + if ($request['id'] !== $payment_gateway_id) { |
|
236 | 236 | continue; |
237 | 237 | } |
238 | 238 | $payment_gateway->id = $payment_gateway_id; |
@@ -248,25 +248,25 @@ discard block |
||
248 | 248 | * @param WP_REST_Request $request Request object. |
249 | 249 | * @return WP_REST_Response $response Response data. |
250 | 250 | */ |
251 | - public function prepare_item_for_response( $gateway, $request ) { |
|
252 | - $order = (array) get_option( 'woocommerce_gateway_order' ); |
|
251 | + public function prepare_item_for_response($gateway, $request) { |
|
252 | + $order = (array) get_option('woocommerce_gateway_order'); |
|
253 | 253 | $item = array( |
254 | 254 | 'id' => $gateway->id, |
255 | 255 | 'title' => $gateway->title, |
256 | 256 | 'description' => $gateway->description, |
257 | - 'order' => isset( $order[ $gateway->id ] ) ? $order[ $gateway->id ] : '', |
|
258 | - 'enabled' => ( 'yes' === $gateway->enabled ), |
|
257 | + 'order' => isset($order[$gateway->id]) ? $order[$gateway->id] : '', |
|
258 | + 'enabled' => ('yes' === $gateway->enabled), |
|
259 | 259 | 'method_title' => $gateway->get_method_title(), |
260 | 260 | 'method_description' => $gateway->get_method_description(), |
261 | - 'settings' => $this->get_settings( $gateway ), |
|
261 | + 'settings' => $this->get_settings($gateway), |
|
262 | 262 | ); |
263 | 263 | |
264 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
265 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
266 | - $data = $this->filter_response_by_context( $data, $context ); |
|
264 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
265 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
266 | + $data = $this->filter_response_by_context($data, $context); |
|
267 | 267 | |
268 | - $response = rest_ensure_response( $data ); |
|
269 | - $response->add_links( $this->prepare_links( $gateway, $request ) ); |
|
268 | + $response = rest_ensure_response($data); |
|
269 | + $response->add_links($this->prepare_links($gateway, $request)); |
|
270 | 270 | |
271 | 271 | /** |
272 | 272 | * Filter payment gateway objects returned from the REST API. |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * @param WC_Payment_Gateway $gateway Payment gateway object. |
276 | 276 | * @param WP_REST_Request $request Request object. |
277 | 277 | */ |
278 | - return apply_filters( 'woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request ); |
|
278 | + return apply_filters('woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -285,36 +285,36 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return array |
287 | 287 | */ |
288 | - public function get_settings( $gateway ) { |
|
288 | + public function get_settings($gateway) { |
|
289 | 289 | $settings = array(); |
290 | 290 | $gateway->init_form_fields(); |
291 | - foreach ( $gateway->form_fields as $id => $field ) { |
|
291 | + foreach ($gateway->form_fields as $id => $field) { |
|
292 | 292 | // Make sure we at least have a title and type. |
293 | - if ( empty( $field['title'] ) || empty( $field['type'] ) ) { |
|
293 | + if (empty($field['title']) || empty($field['type'])) { |
|
294 | 294 | continue; |
295 | 295 | } |
296 | 296 | // Ignore 'title' settings/fields -- they are UI only. |
297 | - if ( 'title' === $field['type'] ) { |
|
297 | + if ('title' === $field['type']) { |
|
298 | 298 | continue; |
299 | 299 | } |
300 | 300 | // Ignore 'enabled' and 'description' which get included elsewhere. |
301 | - if ( in_array( $id, array( 'enabled', 'description' ), true ) ) { |
|
301 | + if (in_array($id, array('enabled', 'description'), true)) { |
|
302 | 302 | continue; |
303 | 303 | } |
304 | 304 | $data = array( |
305 | 305 | 'id' => $id, |
306 | - 'label' => empty( $field['label'] ) ? $field['title'] : $field['label'], |
|
307 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
306 | + 'label' => empty($field['label']) ? $field['title'] : $field['label'], |
|
307 | + 'description' => empty($field['description']) ? '' : $field['description'], |
|
308 | 308 | 'type' => $field['type'], |
309 | - 'value' => empty( $gateway->settings[ $id ] ) ? '' : $gateway->settings[ $id ], |
|
310 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
311 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
312 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
309 | + 'value' => empty($gateway->settings[$id]) ? '' : $gateway->settings[$id], |
|
310 | + 'default' => empty($field['default']) ? '' : $field['default'], |
|
311 | + 'tip' => empty($field['description']) ? '' : $field['description'], |
|
312 | + 'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'], |
|
313 | 313 | ); |
314 | - if ( ! empty( $field['options'] ) ) { |
|
314 | + if ( ! empty($field['options'])) { |
|
315 | 315 | $data['options'] = $field['options']; |
316 | 316 | } |
317 | - $settings[ $id ] = $data; |
|
317 | + $settings[$id] = $data; |
|
318 | 318 | } |
319 | 319 | return $settings; |
320 | 320 | } |
@@ -326,13 +326,13 @@ discard block |
||
326 | 326 | * @param WP_REST_Request $request Request object. |
327 | 327 | * @return array |
328 | 328 | */ |
329 | - protected function prepare_links( $gateway, $request ) { |
|
329 | + protected function prepare_links($gateway, $request) { |
|
330 | 330 | $links = array( |
331 | 331 | 'self' => array( |
332 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $gateway->id ) ), |
|
332 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $gateway->id)), |
|
333 | 333 | ), |
334 | 334 | 'collection' => array( |
335 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
335 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
336 | 336 | ), |
337 | 337 | ); |
338 | 338 | |
@@ -351,97 +351,97 @@ discard block |
||
351 | 351 | 'type' => 'object', |
352 | 352 | 'properties' => array( |
353 | 353 | 'id' => array( |
354 | - 'description' => __( 'Payment gateway ID.', 'woocommerce' ), |
|
354 | + 'description' => __('Payment gateway ID.', 'woocommerce'), |
|
355 | 355 | 'type' => 'string', |
356 | - 'context' => array( 'view', 'edit' ), |
|
356 | + 'context' => array('view', 'edit'), |
|
357 | 357 | 'readonly' => true, |
358 | 358 | ), |
359 | 359 | 'title' => array( |
360 | - 'description' => __( 'Payment gateway title on checkout.', 'woocommerce' ), |
|
360 | + 'description' => __('Payment gateway title on checkout.', 'woocommerce'), |
|
361 | 361 | 'type' => 'string', |
362 | - 'context' => array( 'view', 'edit' ), |
|
362 | + 'context' => array('view', 'edit'), |
|
363 | 363 | ), |
364 | 364 | 'description' => array( |
365 | - 'description' => __( 'Payment gateway description on checkout.', 'woocommerce' ), |
|
365 | + 'description' => __('Payment gateway description on checkout.', 'woocommerce'), |
|
366 | 366 | 'type' => 'string', |
367 | - 'context' => array( 'view', 'edit' ), |
|
367 | + 'context' => array('view', 'edit'), |
|
368 | 368 | ), |
369 | 369 | 'order' => array( |
370 | - 'description' => __( 'Payment gateway sort order.', 'woocommerce' ), |
|
370 | + 'description' => __('Payment gateway sort order.', 'woocommerce'), |
|
371 | 371 | 'type' => 'integer', |
372 | - 'context' => array( 'view', 'edit' ), |
|
372 | + 'context' => array('view', 'edit'), |
|
373 | 373 | 'arg_options' => array( |
374 | 374 | 'sanitize_callback' => 'absint', |
375 | 375 | ), |
376 | 376 | ), |
377 | 377 | 'enabled' => array( |
378 | - 'description' => __( 'Payment gateway enabled status.', 'woocommerce' ), |
|
378 | + 'description' => __('Payment gateway enabled status.', 'woocommerce'), |
|
379 | 379 | 'type' => 'boolean', |
380 | - 'context' => array( 'view', 'edit' ), |
|
380 | + 'context' => array('view', 'edit'), |
|
381 | 381 | ), |
382 | 382 | 'method_title' => array( |
383 | - 'description' => __( 'Payment gateway method title.', 'woocommerce' ), |
|
383 | + 'description' => __('Payment gateway method title.', 'woocommerce'), |
|
384 | 384 | 'type' => 'string', |
385 | - 'context' => array( 'view', 'edit' ), |
|
385 | + 'context' => array('view', 'edit'), |
|
386 | 386 | 'readonly' => true, |
387 | 387 | ), |
388 | 388 | 'method_description' => array( |
389 | - 'description' => __( 'Payment gateway method description.', 'woocommerce' ), |
|
389 | + 'description' => __('Payment gateway method description.', 'woocommerce'), |
|
390 | 390 | 'type' => 'string', |
391 | - 'context' => array( 'view', 'edit' ), |
|
391 | + 'context' => array('view', 'edit'), |
|
392 | 392 | 'readonly' => true, |
393 | 393 | ), |
394 | 394 | 'settings' => array( |
395 | - 'description' => __( 'Payment gateway settings.', 'woocommerce' ), |
|
395 | + 'description' => __('Payment gateway settings.', 'woocommerce'), |
|
396 | 396 | 'type' => 'object', |
397 | - 'context' => array( 'view', 'edit' ), |
|
397 | + 'context' => array('view', 'edit'), |
|
398 | 398 | 'properties' => array( |
399 | 399 | 'id' => array( |
400 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
400 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
401 | 401 | 'type' => 'string', |
402 | - 'context' => array( 'view', 'edit' ), |
|
402 | + 'context' => array('view', 'edit'), |
|
403 | 403 | 'readonly' => true, |
404 | 404 | ), |
405 | 405 | 'label' => array( |
406 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
406 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
407 | 407 | 'type' => 'string', |
408 | - 'context' => array( 'view', 'edit' ), |
|
408 | + 'context' => array('view', 'edit'), |
|
409 | 409 | 'readonly' => true, |
410 | 410 | ), |
411 | 411 | 'description' => array( |
412 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
412 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
413 | 413 | 'type' => 'string', |
414 | - 'context' => array( 'view', 'edit' ), |
|
414 | + 'context' => array('view', 'edit'), |
|
415 | 415 | 'readonly' => true, |
416 | 416 | ), |
417 | 417 | 'type' => array( |
418 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
418 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
419 | 419 | 'type' => 'string', |
420 | - 'context' => array( 'view', 'edit' ), |
|
421 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ), |
|
420 | + 'context' => array('view', 'edit'), |
|
421 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'), |
|
422 | 422 | 'readonly' => true, |
423 | 423 | ), |
424 | 424 | 'value' => array( |
425 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
425 | + 'description' => __('Setting value.', 'woocommerce'), |
|
426 | 426 | 'type' => 'string', |
427 | - 'context' => array( 'view', 'edit' ), |
|
427 | + 'context' => array('view', 'edit'), |
|
428 | 428 | ), |
429 | 429 | 'default' => array( |
430 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
430 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
431 | 431 | 'type' => 'string', |
432 | - 'context' => array( 'view', 'edit' ), |
|
432 | + 'context' => array('view', 'edit'), |
|
433 | 433 | 'readonly' => true, |
434 | 434 | ), |
435 | 435 | 'tip' => array( |
436 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
436 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
437 | 437 | 'type' => 'string', |
438 | - 'context' => array( 'view', 'edit' ), |
|
438 | + 'context' => array('view', 'edit'), |
|
439 | 439 | 'readonly' => true, |
440 | 440 | ), |
441 | 441 | 'placeholder' => array( |
442 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
442 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
443 | 443 | 'type' => 'string', |
444 | - 'context' => array( 'view', 'edit' ), |
|
444 | + 'context' => array('view', 'edit'), |
|
445 | 445 | 'readonly' => true, |
446 | 446 | ), |
447 | 447 | ), |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | ), |
450 | 450 | ); |
451 | 451 | |
452 | - return $this->add_additional_fields_schema( $schema ); |
|
452 | + return $this->add_additional_fields_schema($schema); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | */ |
460 | 460 | public function get_collection_params() { |
461 | 461 | return array( |
462 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
462 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
463 | 463 | ); |
464 | 464 | } |
465 | 465 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 2.6.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Webhooks controller class. |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | * @param WP_REST_Request $request Request object. |
33 | 33 | * @return WP_REST_Response $response |
34 | 34 | */ |
35 | - public function prepare_item_for_response( $id, $request ) { |
|
36 | - $webhook = wc_get_webhook( $id ); |
|
35 | + public function prepare_item_for_response($id, $request) { |
|
36 | + $webhook = wc_get_webhook($id); |
|
37 | 37 | |
38 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
39 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
38 | + if (empty($webhook) || is_null($webhook)) { |
|
39 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | $data = array( |
@@ -48,20 +48,20 @@ discard block |
||
48 | 48 | 'event' => $webhook->get_event(), |
49 | 49 | 'hooks' => $webhook->get_hooks(), |
50 | 50 | 'delivery_url' => $webhook->get_delivery_url(), |
51 | - 'date_created' => wc_rest_prepare_date_response( $webhook->get_date_created(), false ), |
|
52 | - 'date_created_gmt' => wc_rest_prepare_date_response( $webhook->get_date_created() ), |
|
53 | - 'date_modified' => wc_rest_prepare_date_response( $webhook->get_date_modified(), false ), |
|
54 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $webhook->get_date_modified() ), |
|
51 | + 'date_created' => wc_rest_prepare_date_response($webhook->get_date_created(), false), |
|
52 | + 'date_created_gmt' => wc_rest_prepare_date_response($webhook->get_date_created()), |
|
53 | + 'date_modified' => wc_rest_prepare_date_response($webhook->get_date_modified(), false), |
|
54 | + 'date_modified_gmt' => wc_rest_prepare_date_response($webhook->get_date_modified()), |
|
55 | 55 | ); |
56 | 56 | |
57 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
58 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
59 | - $data = $this->filter_response_by_context( $data, $context ); |
|
57 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
58 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
59 | + $data = $this->filter_response_by_context($data, $context); |
|
60 | 60 | |
61 | 61 | // Wrap the data in a response object. |
62 | - $response = rest_ensure_response( $data ); |
|
62 | + $response = rest_ensure_response($data); |
|
63 | 63 | |
64 | - $response->add_links( $this->prepare_links( $webhook->get_id(), $request ) ); |
|
64 | + $response->add_links($this->prepare_links($webhook->get_id(), $request)); |
|
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Filter webhook object returned from the REST API. |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param WC_Webhook $webhook Webhook object used to create response. |
71 | 71 | * @param WP_REST_Request $request Request object. |
72 | 72 | */ |
73 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request ); |
|
73 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -95,88 +95,88 @@ discard block |
||
95 | 95 | 'type' => 'object', |
96 | 96 | 'properties' => array( |
97 | 97 | 'id' => array( |
98 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
98 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
99 | 99 | 'type' => 'integer', |
100 | - 'context' => array( 'view', 'edit' ), |
|
100 | + 'context' => array('view', 'edit'), |
|
101 | 101 | 'readonly' => true, |
102 | 102 | ), |
103 | 103 | 'name' => array( |
104 | - 'description' => __( 'A friendly name for the webhook.', 'woocommerce' ), |
|
104 | + 'description' => __('A friendly name for the webhook.', 'woocommerce'), |
|
105 | 105 | 'type' => 'string', |
106 | - 'context' => array( 'view', 'edit' ), |
|
106 | + 'context' => array('view', 'edit'), |
|
107 | 107 | ), |
108 | 108 | 'status' => array( |
109 | - 'description' => __( 'Webhook status.', 'woocommerce' ), |
|
109 | + 'description' => __('Webhook status.', 'woocommerce'), |
|
110 | 110 | 'type' => 'string', |
111 | 111 | 'default' => 'active', |
112 | - 'enum' => array_keys( wc_get_webhook_statuses() ), |
|
113 | - 'context' => array( 'view', 'edit' ), |
|
112 | + 'enum' => array_keys(wc_get_webhook_statuses()), |
|
113 | + 'context' => array('view', 'edit'), |
|
114 | 114 | ), |
115 | 115 | 'topic' => array( |
116 | - 'description' => __( 'Webhook topic.', 'woocommerce' ), |
|
116 | + 'description' => __('Webhook topic.', 'woocommerce'), |
|
117 | 117 | 'type' => 'string', |
118 | - 'context' => array( 'view', 'edit' ), |
|
118 | + 'context' => array('view', 'edit'), |
|
119 | 119 | ), |
120 | 120 | 'resource' => array( |
121 | - 'description' => __( 'Webhook resource.', 'woocommerce' ), |
|
121 | + 'description' => __('Webhook resource.', 'woocommerce'), |
|
122 | 122 | 'type' => 'string', |
123 | - 'context' => array( 'view', 'edit' ), |
|
123 | + 'context' => array('view', 'edit'), |
|
124 | 124 | 'readonly' => true, |
125 | 125 | ), |
126 | 126 | 'event' => array( |
127 | - 'description' => __( 'Webhook event.', 'woocommerce' ), |
|
127 | + 'description' => __('Webhook event.', 'woocommerce'), |
|
128 | 128 | 'type' => 'string', |
129 | - 'context' => array( 'view', 'edit' ), |
|
129 | + 'context' => array('view', 'edit'), |
|
130 | 130 | 'readonly' => true, |
131 | 131 | ), |
132 | 132 | 'hooks' => array( |
133 | - 'description' => __( 'WooCommerce action names associated with the webhook.', 'woocommerce' ), |
|
133 | + 'description' => __('WooCommerce action names associated with the webhook.', 'woocommerce'), |
|
134 | 134 | 'type' => 'array', |
135 | - 'context' => array( 'view', 'edit' ), |
|
135 | + 'context' => array('view', 'edit'), |
|
136 | 136 | 'readonly' => true, |
137 | 137 | 'items' => array( |
138 | 138 | 'type' => 'string', |
139 | 139 | ), |
140 | 140 | ), |
141 | 141 | 'delivery_url' => array( |
142 | - 'description' => __( 'The URL where the webhook payload is delivered.', 'woocommerce' ), |
|
142 | + 'description' => __('The URL where the webhook payload is delivered.', 'woocommerce'), |
|
143 | 143 | 'type' => 'string', |
144 | 144 | 'format' => 'uri', |
145 | - 'context' => array( 'view', 'edit' ), |
|
145 | + 'context' => array('view', 'edit'), |
|
146 | 146 | 'readonly' => true, |
147 | 147 | ), |
148 | 148 | 'secret' => array( |
149 | - 'description' => __( "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce' ), |
|
149 | + 'description' => __("Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce'), |
|
150 | 150 | 'type' => 'string', |
151 | - 'context' => array( 'edit' ), |
|
151 | + 'context' => array('edit'), |
|
152 | 152 | ), |
153 | 153 | 'date_created' => array( |
154 | - 'description' => __( "The date the webhook was created, in the site's timezone.", 'woocommerce' ), |
|
154 | + 'description' => __("The date the webhook was created, in the site's timezone.", 'woocommerce'), |
|
155 | 155 | 'type' => 'date-time', |
156 | - 'context' => array( 'view', 'edit' ), |
|
156 | + 'context' => array('view', 'edit'), |
|
157 | 157 | 'readonly' => true, |
158 | 158 | ), |
159 | 159 | 'date_created_gmt' => array( |
160 | - 'description' => __( 'The date the webhook was created, as GMT.', 'woocommerce' ), |
|
160 | + 'description' => __('The date the webhook was created, as GMT.', 'woocommerce'), |
|
161 | 161 | 'type' => 'date-time', |
162 | - 'context' => array( 'view', 'edit' ), |
|
162 | + 'context' => array('view', 'edit'), |
|
163 | 163 | 'readonly' => true, |
164 | 164 | ), |
165 | 165 | 'date_modified' => array( |
166 | - 'description' => __( "The date the webhook was last modified, in the site's timezone.", 'woocommerce' ), |
|
166 | + 'description' => __("The date the webhook was last modified, in the site's timezone.", 'woocommerce'), |
|
167 | 167 | 'type' => 'date-time', |
168 | - 'context' => array( 'view', 'edit' ), |
|
168 | + 'context' => array('view', 'edit'), |
|
169 | 169 | 'readonly' => true, |
170 | 170 | ), |
171 | 171 | 'date_modified_gmt' => array( |
172 | - 'description' => __( 'The date the webhook was last modified, as GMT.', 'woocommerce' ), |
|
172 | + 'description' => __('The date the webhook was last modified, as GMT.', 'woocommerce'), |
|
173 | 173 | 'type' => 'date-time', |
174 | - 'context' => array( 'view', 'edit' ), |
|
174 | + 'context' => array('view', 'edit'), |
|
175 | 175 | 'readonly' => true, |
176 | 176 | ), |
177 | 177 | ), |
178 | 178 | ); |
179 | 179 | |
180 | - return $this->add_additional_fields_schema( $schema ); |
|
180 | + return $this->add_additional_fields_schema($schema); |
|
181 | 181 | } |
182 | 182 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * System status tools controller. |
@@ -42,11 +42,11 @@ discard block |
||
42 | 42 | array( |
43 | 43 | array( |
44 | 44 | 'methods' => WP_REST_Server::READABLE, |
45 | - 'callback' => array( $this, 'get_items' ), |
|
46 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
45 | + 'callback' => array($this, 'get_items'), |
|
46 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
47 | 47 | 'args' => $this->get_collection_params(), |
48 | 48 | ), |
49 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
49 | + 'schema' => array($this, 'get_public_item_schema'), |
|
50 | 50 | ) |
51 | 51 | ); |
52 | 52 | |
@@ -56,22 +56,22 @@ discard block |
||
56 | 56 | array( |
57 | 57 | 'args' => array( |
58 | 58 | 'id' => array( |
59 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
59 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
60 | 60 | 'type' => 'string', |
61 | 61 | ), |
62 | 62 | ), |
63 | 63 | array( |
64 | 64 | 'methods' => WP_REST_Server::READABLE, |
65 | - 'callback' => array( $this, 'get_item' ), |
|
66 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
65 | + 'callback' => array($this, 'get_item'), |
|
66 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
67 | 67 | ), |
68 | 68 | array( |
69 | 69 | 'methods' => WP_REST_Server::EDITABLE, |
70 | - 'callback' => array( $this, 'update_item' ), |
|
71 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
72 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
70 | + 'callback' => array($this, 'update_item'), |
|
71 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
72 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
73 | 73 | ), |
74 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
74 | + 'schema' => array($this, 'get_public_item_schema'), |
|
75 | 75 | ) |
76 | 76 | ); |
77 | 77 | } |
@@ -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( 'system_status', '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('system_status', '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 | return true; |
90 | 90 | } |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | * @param WP_REST_Request $request Full details about the request. |
96 | 96 | * @return WP_Error|boolean |
97 | 97 | */ |
98 | - public function get_item_permissions_check( $request ) { |
|
99 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
100 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
98 | + public function get_item_permissions_check($request) { |
|
99 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
100 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
101 | 101 | } |
102 | 102 | return true; |
103 | 103 | } |
@@ -108,9 +108,9 @@ discard block |
||
108 | 108 | * @param WP_REST_Request $request Full details about the request. |
109 | 109 | * @return WP_Error|boolean |
110 | 110 | */ |
111 | - public function update_item_permissions_check( $request ) { |
|
112 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'edit' ) ) { |
|
113 | - return new WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
111 | + public function update_item_permissions_check($request) { |
|
112 | + if ( ! wc_rest_check_manager_permissions('system_status', 'edit')) { |
|
113 | + return new WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
114 | 114 | } |
115 | 115 | return true; |
116 | 116 | } |
@@ -124,89 +124,89 @@ discard block |
||
124 | 124 | public function get_tools() { |
125 | 125 | $tools = array( |
126 | 126 | 'clear_transients' => array( |
127 | - 'name' => __( 'WooCommerce transients', 'woocommerce' ), |
|
128 | - 'button' => __( 'Clear transients', 'woocommerce' ), |
|
129 | - 'desc' => __( 'This tool will clear the product/shop transients cache.', 'woocommerce' ), |
|
127 | + 'name' => __('WooCommerce transients', 'woocommerce'), |
|
128 | + 'button' => __('Clear transients', 'woocommerce'), |
|
129 | + 'desc' => __('This tool will clear the product/shop transients cache.', 'woocommerce'), |
|
130 | 130 | ), |
131 | 131 | 'clear_expired_transients' => array( |
132 | - 'name' => __( 'Expired transients', 'woocommerce' ), |
|
133 | - 'button' => __( 'Clear transients', 'woocommerce' ), |
|
134 | - 'desc' => __( 'This tool will clear ALL expired transients from WordPress.', 'woocommerce' ), |
|
132 | + 'name' => __('Expired transients', 'woocommerce'), |
|
133 | + 'button' => __('Clear transients', 'woocommerce'), |
|
134 | + 'desc' => __('This tool will clear ALL expired transients from WordPress.', 'woocommerce'), |
|
135 | 135 | ), |
136 | 136 | 'delete_orphaned_variations' => array( |
137 | - 'name' => __( 'Orphaned variations', 'woocommerce' ), |
|
138 | - 'button' => __( 'Delete orphaned variations', 'woocommerce' ), |
|
139 | - 'desc' => __( 'This tool will delete all variations which have no parent.', 'woocommerce' ), |
|
137 | + 'name' => __('Orphaned variations', 'woocommerce'), |
|
138 | + 'button' => __('Delete orphaned variations', 'woocommerce'), |
|
139 | + 'desc' => __('This tool will delete all variations which have no parent.', 'woocommerce'), |
|
140 | 140 | ), |
141 | 141 | 'clear_expired_download_permissions' => array( |
142 | - 'name' => __( 'Used-up download permissions', 'woocommerce' ), |
|
143 | - 'button' => __( 'Clean up download permissions', 'woocommerce' ), |
|
144 | - 'desc' => __( 'This tool will delete expired download permissions and permissions with 0 remaining downloads.', 'woocommerce' ), |
|
142 | + 'name' => __('Used-up download permissions', 'woocommerce'), |
|
143 | + 'button' => __('Clean up download permissions', 'woocommerce'), |
|
144 | + 'desc' => __('This tool will delete expired download permissions and permissions with 0 remaining downloads.', 'woocommerce'), |
|
145 | 145 | ), |
146 | 146 | 'regenerate_product_lookup_tables' => array( |
147 | - 'name' => __( 'Product lookup tables', 'woocommerce' ), |
|
148 | - 'button' => __( 'Regenerate', 'woocommerce' ), |
|
149 | - 'desc' => __( 'This tool will regenerate product lookup table data. This process may take a while.', 'woocommerce' ), |
|
147 | + 'name' => __('Product lookup tables', 'woocommerce'), |
|
148 | + 'button' => __('Regenerate', 'woocommerce'), |
|
149 | + 'desc' => __('This tool will regenerate product lookup table data. This process may take a while.', 'woocommerce'), |
|
150 | 150 | ), |
151 | 151 | 'recount_terms' => array( |
152 | - 'name' => __( 'Term counts', 'woocommerce' ), |
|
153 | - 'button' => __( 'Recount terms', 'woocommerce' ), |
|
154 | - 'desc' => __( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', 'woocommerce' ), |
|
152 | + 'name' => __('Term counts', 'woocommerce'), |
|
153 | + 'button' => __('Recount terms', 'woocommerce'), |
|
154 | + 'desc' => __('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', 'woocommerce'), |
|
155 | 155 | ), |
156 | 156 | 'reset_roles' => array( |
157 | - 'name' => __( 'Capabilities', 'woocommerce' ), |
|
158 | - 'button' => __( 'Reset capabilities', 'woocommerce' ), |
|
159 | - 'desc' => __( 'This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.', 'woocommerce' ), |
|
157 | + 'name' => __('Capabilities', 'woocommerce'), |
|
158 | + 'button' => __('Reset capabilities', 'woocommerce'), |
|
159 | + 'desc' => __('This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.', 'woocommerce'), |
|
160 | 160 | ), |
161 | 161 | 'clear_sessions' => array( |
162 | - 'name' => __( 'Clear customer sessions', 'woocommerce' ), |
|
163 | - 'button' => __( 'Clear', 'woocommerce' ), |
|
162 | + 'name' => __('Clear customer sessions', 'woocommerce'), |
|
163 | + 'button' => __('Clear', 'woocommerce'), |
|
164 | 164 | 'desc' => sprintf( |
165 | 165 | '<strong class="red">%1$s</strong> %2$s', |
166 | - __( 'Note:', 'woocommerce' ), |
|
167 | - __( 'This tool will delete all customer session data from the database, including current carts and saved carts in the database.', 'woocommerce' ) |
|
166 | + __('Note:', 'woocommerce'), |
|
167 | + __('This tool will delete all customer session data from the database, including current carts and saved carts in the database.', 'woocommerce') |
|
168 | 168 | ), |
169 | 169 | ), |
170 | 170 | 'install_pages' => array( |
171 | - 'name' => __( 'Create default WooCommerce pages', 'woocommerce' ), |
|
172 | - 'button' => __( 'Create pages', 'woocommerce' ), |
|
171 | + 'name' => __('Create default WooCommerce pages', 'woocommerce'), |
|
172 | + 'button' => __('Create pages', 'woocommerce'), |
|
173 | 173 | 'desc' => sprintf( |
174 | 174 | '<strong class="red">%1$s</strong> %2$s', |
175 | - __( 'Note:', 'woocommerce' ), |
|
176 | - __( 'This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.', 'woocommerce' ) |
|
175 | + __('Note:', 'woocommerce'), |
|
176 | + __('This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.', 'woocommerce') |
|
177 | 177 | ), |
178 | 178 | ), |
179 | 179 | 'delete_taxes' => array( |
180 | - 'name' => __( 'Delete WooCommerce tax rates', 'woocommerce' ), |
|
181 | - 'button' => __( 'Delete tax rates', 'woocommerce' ), |
|
180 | + 'name' => __('Delete WooCommerce tax rates', 'woocommerce'), |
|
181 | + 'button' => __('Delete tax rates', 'woocommerce'), |
|
182 | 182 | 'desc' => sprintf( |
183 | 183 | '<strong class="red">%1$s</strong> %2$s', |
184 | - __( 'Note:', 'woocommerce' ), |
|
185 | - __( 'This option will delete ALL of your tax rates, use with caution. This action cannot be reversed.', 'woocommerce' ) |
|
184 | + __('Note:', 'woocommerce'), |
|
185 | + __('This option will delete ALL of your tax rates, use with caution. This action cannot be reversed.', 'woocommerce') |
|
186 | 186 | ), |
187 | 187 | ), |
188 | 188 | 'regenerate_thumbnails' => array( |
189 | - 'name' => __( 'Regenerate shop thumbnails', 'woocommerce' ), |
|
190 | - 'button' => __( 'Regenerate', 'woocommerce' ), |
|
191 | - 'desc' => __( 'This will regenerate all shop thumbnails to match your theme and/or image settings.', 'woocommerce' ), |
|
189 | + 'name' => __('Regenerate shop thumbnails', 'woocommerce'), |
|
190 | + 'button' => __('Regenerate', 'woocommerce'), |
|
191 | + 'desc' => __('This will regenerate all shop thumbnails to match your theme and/or image settings.', 'woocommerce'), |
|
192 | 192 | ), |
193 | 193 | 'db_update_routine' => array( |
194 | - 'name' => __( 'Update database', 'woocommerce' ), |
|
195 | - 'button' => __( 'Update database', 'woocommerce' ), |
|
194 | + 'name' => __('Update database', 'woocommerce'), |
|
195 | + 'button' => __('Update database', 'woocommerce'), |
|
196 | 196 | 'desc' => sprintf( |
197 | 197 | '<strong class="red">%1$s</strong> %2$s', |
198 | - __( 'Note:', 'woocommerce' ), |
|
199 | - __( 'This tool will update your WooCommerce database to the latest version. Please ensure you make sufficient backups before proceeding.', 'woocommerce' ) |
|
198 | + __('Note:', 'woocommerce'), |
|
199 | + __('This tool will update your WooCommerce database to the latest version. Please ensure you make sufficient backups before proceeding.', 'woocommerce') |
|
200 | 200 | ), |
201 | 201 | ), |
202 | 202 | ); |
203 | 203 | |
204 | 204 | // Jetpack does the image resizing heavy lifting so you don't have to. |
205 | - if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', true ) ) { |
|
206 | - unset( $tools['regenerate_thumbnails'] ); |
|
205 | + if ((class_exists('Jetpack') && Jetpack::is_module_active('photon')) || ! apply_filters('woocommerce_background_image_regeneration', true)) { |
|
206 | + unset($tools['regenerate_thumbnails']); |
|
207 | 207 | } |
208 | 208 | |
209 | - return apply_filters( 'woocommerce_debug_tools', $tools ); |
|
209 | + return apply_filters('woocommerce_debug_tools', $tools); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -215,9 +215,9 @@ discard block |
||
215 | 215 | * @param WP_REST_Request $request Full details about the request. |
216 | 216 | * @return WP_Error|WP_REST_Response |
217 | 217 | */ |
218 | - public function get_items( $request ) { |
|
218 | + public function get_items($request) { |
|
219 | 219 | $tools = array(); |
220 | - foreach ( $this->get_tools() as $id => $tool ) { |
|
220 | + foreach ($this->get_tools() as $id => $tool) { |
|
221 | 221 | $tools[] = $this->prepare_response_for_collection( |
222 | 222 | $this->prepare_item_for_response( |
223 | 223 | array( |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | ); |
232 | 232 | } |
233 | 233 | |
234 | - $response = rest_ensure_response( $tools ); |
|
234 | + $response = rest_ensure_response($tools); |
|
235 | 235 | return $response; |
236 | 236 | } |
237 | 237 | |
@@ -241,12 +241,12 @@ discard block |
||
241 | 241 | * @param WP_REST_Request $request Request data. |
242 | 242 | * @return WP_Error|WP_REST_Response |
243 | 243 | */ |
244 | - public function get_item( $request ) { |
|
244 | + public function get_item($request) { |
|
245 | 245 | $tools = $this->get_tools(); |
246 | - if ( empty( $tools[ $request['id'] ] ) ) { |
|
247 | - return new WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
246 | + if (empty($tools[$request['id']])) { |
|
247 | + return new WP_Error('woocommerce_rest_system_status_tool_invalid_id', __('Invalid tool ID.', 'woocommerce'), array('status' => 404)); |
|
248 | 248 | } |
249 | - $tool = $tools[ $request['id'] ]; |
|
249 | + $tool = $tools[$request['id']]; |
|
250 | 250 | return rest_ensure_response( |
251 | 251 | $this->prepare_item_for_response( |
252 | 252 | array( |
@@ -266,13 +266,13 @@ discard block |
||
266 | 266 | * @param WP_REST_Request $request Request data. |
267 | 267 | * @return WP_Error|WP_REST_Response |
268 | 268 | */ |
269 | - public function update_item( $request ) { |
|
269 | + public function update_item($request) { |
|
270 | 270 | $tools = $this->get_tools(); |
271 | - if ( empty( $tools[ $request['id'] ] ) ) { |
|
272 | - return new WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
271 | + if (empty($tools[$request['id']])) { |
|
272 | + return new WP_Error('woocommerce_rest_system_status_tool_invalid_id', __('Invalid tool ID.', 'woocommerce'), array('status' => 404)); |
|
273 | 273 | } |
274 | 274 | |
275 | - $tool = $tools[ $request['id'] ]; |
|
275 | + $tool = $tools[$request['id']]; |
|
276 | 276 | $tool = array( |
277 | 277 | 'id' => $request['id'], |
278 | 278 | 'name' => $tool['name'], |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | 'description' => $tool['desc'], |
281 | 281 | ); |
282 | 282 | |
283 | - $execute_return = $this->execute_tool( $request['id'] ); |
|
284 | - $tool = array_merge( $tool, $execute_return ); |
|
283 | + $execute_return = $this->execute_tool($request['id']); |
|
284 | + $tool = array_merge($tool, $execute_return); |
|
285 | 285 | |
286 | 286 | /** |
287 | 287 | * Fires after a WooCommerce REST system status tool has been executed. |
@@ -289,11 +289,11 @@ discard block |
||
289 | 289 | * @param array $tool Details about the tool that has been executed. |
290 | 290 | * @param WP_REST_Request $request The current WP_REST_Request object. |
291 | 291 | */ |
292 | - do_action( 'woocommerce_rest_insert_system_status_tool', $tool, $request ); |
|
292 | + do_action('woocommerce_rest_insert_system_status_tool', $tool, $request); |
|
293 | 293 | |
294 | - $request->set_param( 'context', 'edit' ); |
|
295 | - $response = $this->prepare_item_for_response( $tool, $request ); |
|
296 | - return rest_ensure_response( $response ); |
|
294 | + $request->set_param('context', 'edit'); |
|
295 | + $response = $this->prepare_item_for_response($tool, $request); |
|
296 | + return rest_ensure_response($response); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -303,14 +303,14 @@ discard block |
||
303 | 303 | * @param WP_REST_Request $request Request object. |
304 | 304 | * @return WP_REST_Response $response Response data. |
305 | 305 | */ |
306 | - public function prepare_item_for_response( $item, $request ) { |
|
307 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
308 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
309 | - $data = $this->filter_response_by_context( $data, $context ); |
|
306 | + public function prepare_item_for_response($item, $request) { |
|
307 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
308 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
309 | + $data = $this->filter_response_by_context($data, $context); |
|
310 | 310 | |
311 | - $response = rest_ensure_response( $data ); |
|
311 | + $response = rest_ensure_response($data); |
|
312 | 312 | |
313 | - $response->add_links( $this->prepare_links( $item['id'] ) ); |
|
313 | + $response->add_links($this->prepare_links($item['id'])); |
|
314 | 314 | |
315 | 315 | return $response; |
316 | 316 | } |
@@ -327,46 +327,46 @@ discard block |
||
327 | 327 | 'type' => 'object', |
328 | 328 | 'properties' => array( |
329 | 329 | 'id' => array( |
330 | - 'description' => __( 'A unique identifier for the tool.', 'woocommerce' ), |
|
330 | + 'description' => __('A unique identifier for the tool.', 'woocommerce'), |
|
331 | 331 | 'type' => 'string', |
332 | - 'context' => array( 'view', 'edit' ), |
|
332 | + 'context' => array('view', 'edit'), |
|
333 | 333 | 'arg_options' => array( |
334 | 334 | 'sanitize_callback' => 'sanitize_title', |
335 | 335 | ), |
336 | 336 | ), |
337 | 337 | 'name' => array( |
338 | - 'description' => __( 'Tool name.', 'woocommerce' ), |
|
338 | + 'description' => __('Tool name.', 'woocommerce'), |
|
339 | 339 | 'type' => 'string', |
340 | - 'context' => array( 'view', 'edit' ), |
|
340 | + 'context' => array('view', 'edit'), |
|
341 | 341 | 'arg_options' => array( |
342 | 342 | 'sanitize_callback' => 'sanitize_text_field', |
343 | 343 | ), |
344 | 344 | ), |
345 | 345 | 'action' => array( |
346 | - 'description' => __( 'What running the tool will do.', 'woocommerce' ), |
|
346 | + 'description' => __('What running the tool will do.', 'woocommerce'), |
|
347 | 347 | 'type' => 'string', |
348 | - 'context' => array( 'view', 'edit' ), |
|
348 | + 'context' => array('view', 'edit'), |
|
349 | 349 | 'arg_options' => array( |
350 | 350 | 'sanitize_callback' => 'sanitize_text_field', |
351 | 351 | ), |
352 | 352 | ), |
353 | 353 | 'description' => array( |
354 | - 'description' => __( 'Tool description.', 'woocommerce' ), |
|
354 | + 'description' => __('Tool description.', 'woocommerce'), |
|
355 | 355 | 'type' => 'string', |
356 | - 'context' => array( 'view', 'edit' ), |
|
356 | + 'context' => array('view', 'edit'), |
|
357 | 357 | 'arg_options' => array( |
358 | 358 | 'sanitize_callback' => 'sanitize_text_field', |
359 | 359 | ), |
360 | 360 | ), |
361 | 361 | 'success' => array( |
362 | - 'description' => __( 'Did the tool run successfully?', 'woocommerce' ), |
|
362 | + 'description' => __('Did the tool run successfully?', 'woocommerce'), |
|
363 | 363 | 'type' => 'boolean', |
364 | - 'context' => array( 'edit' ), |
|
364 | + 'context' => array('edit'), |
|
365 | 365 | ), |
366 | 366 | 'message' => array( |
367 | - 'description' => __( 'Tool return message.', 'woocommerce' ), |
|
367 | + 'description' => __('Tool return message.', 'woocommerce'), |
|
368 | 368 | 'type' => 'string', |
369 | - 'context' => array( 'edit' ), |
|
369 | + 'context' => array('edit'), |
|
370 | 370 | 'arg_options' => array( |
371 | 371 | 'sanitize_callback' => 'sanitize_text_field', |
372 | 372 | ), |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | ), |
375 | 375 | ); |
376 | 376 | |
377 | - return $this->add_additional_fields_schema( $schema ); |
|
377 | + return $this->add_additional_fields_schema($schema); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | /** |
@@ -383,11 +383,11 @@ discard block |
||
383 | 383 | * @param string $id ID. |
384 | 384 | * @return array |
385 | 385 | */ |
386 | - protected function prepare_links( $id ) { |
|
386 | + protected function prepare_links($id) { |
|
387 | 387 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
388 | 388 | $links = array( |
389 | 389 | 'item' => array( |
390 | - 'href' => rest_url( trailingslashit( $base ) . $id ), |
|
390 | + 'href' => rest_url(trailingslashit($base) . $id), |
|
391 | 391 | 'embeddable' => true, |
392 | 392 | ), |
393 | 393 | ); |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | */ |
403 | 403 | public function get_collection_params() { |
404 | 404 | return array( |
405 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
405 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
406 | 406 | ); |
407 | 407 | } |
408 | 408 | |
@@ -412,30 +412,30 @@ discard block |
||
412 | 412 | * @param string $tool Tool. |
413 | 413 | * @return array |
414 | 414 | */ |
415 | - public function execute_tool( $tool ) { |
|
415 | + public function execute_tool($tool) { |
|
416 | 416 | global $wpdb; |
417 | 417 | $ran = true; |
418 | - switch ( $tool ) { |
|
418 | + switch ($tool) { |
|
419 | 419 | case 'clear_transients': |
420 | 420 | wc_delete_product_transients(); |
421 | 421 | wc_delete_shop_order_transients(); |
422 | - delete_transient( 'wc_count_comments' ); |
|
422 | + delete_transient('wc_count_comments'); |
|
423 | 423 | |
424 | 424 | $attribute_taxonomies = wc_get_attribute_taxonomies(); |
425 | 425 | |
426 | - if ( $attribute_taxonomies ) { |
|
427 | - foreach ( $attribute_taxonomies as $attribute ) { |
|
428 | - delete_transient( 'wc_layered_nav_counts_pa_' . $attribute->attribute_name ); |
|
426 | + if ($attribute_taxonomies) { |
|
427 | + foreach ($attribute_taxonomies as $attribute) { |
|
428 | + delete_transient('wc_layered_nav_counts_pa_' . $attribute->attribute_name); |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | |
432 | - WC_Cache_Helper::get_transient_version( 'shipping', true ); |
|
433 | - $message = __( 'Product transients cleared', 'woocommerce' ); |
|
432 | + WC_Cache_Helper::get_transient_version('shipping', true); |
|
433 | + $message = __('Product transients cleared', 'woocommerce'); |
|
434 | 434 | break; |
435 | 435 | |
436 | 436 | case 'clear_expired_transients': |
437 | 437 | /* translators: %d: amount of expired transients */ |
438 | - $message = sprintf( __( '%d transients rows cleared', 'woocommerce' ), wc_delete_expired_transients() ); |
|
438 | + $message = sprintf(__('%d transients rows cleared', 'woocommerce'), wc_delete_expired_transients()); |
|
439 | 439 | break; |
440 | 440 | |
441 | 441 | case 'delete_orphaned_variations': |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | ) |
450 | 450 | ); |
451 | 451 | /* translators: %d: amount of orphaned variations */ |
452 | - $message = sprintf( __( '%d orphaned variations deleted', 'woocommerce' ), $result ); |
|
452 | + $message = sprintf(__('%d orphaned variations deleted', 'woocommerce'), $result); |
|
453 | 453 | break; |
454 | 454 | |
455 | 455 | case 'clear_expired_download_permissions': |
@@ -459,25 +459,25 @@ discard block |
||
459 | 459 | $wpdb->prepare( |
460 | 460 | "DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions |
461 | 461 | WHERE ( downloads_remaining != '' AND downloads_remaining = 0 ) OR ( access_expires IS NOT NULL AND access_expires < %s )", |
462 | - date( 'Y-m-d', current_time( 'timestamp' ) ) |
|
462 | + date('Y-m-d', current_time('timestamp')) |
|
463 | 463 | ) |
464 | 464 | ) |
465 | 465 | ); |
466 | 466 | /* translators: %d: amount of permissions */ |
467 | - $message = sprintf( __( '%d permissions deleted', 'woocommerce' ), $result ); |
|
467 | + $message = sprintf(__('%d permissions deleted', 'woocommerce'), $result); |
|
468 | 468 | break; |
469 | 469 | |
470 | 470 | case 'regenerate_product_lookup_tables': |
471 | - if ( ! wc_update_product_lookup_tables_is_running() ) { |
|
471 | + if ( ! wc_update_product_lookup_tables_is_running()) { |
|
472 | 472 | wc_update_product_lookup_tables(); |
473 | 473 | } |
474 | - $message = __( 'Lookup tables are regenerating', 'woocommerce' ); |
|
474 | + $message = __('Lookup tables are regenerating', 'woocommerce'); |
|
475 | 475 | break; |
476 | 476 | case 'reset_roles': |
477 | 477 | // Remove then re-add caps and roles. |
478 | 478 | WC_Install::remove_roles(); |
479 | 479 | WC_Install::create_roles(); |
480 | - $message = __( 'Roles successfully reset', 'woocommerce' ); |
|
480 | + $message = __('Roles successfully reset', 'woocommerce'); |
|
481 | 481 | break; |
482 | 482 | |
483 | 483 | case 'recount_terms': |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | 'fields' => 'id=>parent', |
489 | 489 | ) |
490 | 490 | ); |
491 | - _wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), true, false ); |
|
491 | + _wc_term_recount($product_cats, get_taxonomy('product_cat'), true, false); |
|
492 | 492 | $product_tags = get_terms( |
493 | 493 | 'product_tag', |
494 | 494 | array( |
@@ -496,61 +496,61 @@ discard block |
||
496 | 496 | 'fields' => 'id=>parent', |
497 | 497 | ) |
498 | 498 | ); |
499 | - _wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), true, false ); |
|
500 | - $message = __( 'Terms successfully recounted', 'woocommerce' ); |
|
499 | + _wc_term_recount($product_tags, get_taxonomy('product_tag'), true, false); |
|
500 | + $message = __('Terms successfully recounted', 'woocommerce'); |
|
501 | 501 | break; |
502 | 502 | |
503 | 503 | case 'clear_sessions': |
504 | - $wpdb->query( "TRUNCATE {$wpdb->prefix}woocommerce_sessions" ); |
|
505 | - $result = absint( $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';" ) ); // WPCS: unprepared SQL ok. |
|
504 | + $wpdb->query("TRUNCATE {$wpdb->prefix}woocommerce_sessions"); |
|
505 | + $result = absint($wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';")); // WPCS: unprepared SQL ok. |
|
506 | 506 | wp_cache_flush(); |
507 | 507 | /* translators: %d: amount of sessions */ |
508 | - $message = sprintf( __( 'Deleted all active sessions, and %d saved carts.', 'woocommerce' ), absint( $result ) ); |
|
508 | + $message = sprintf(__('Deleted all active sessions, and %d saved carts.', 'woocommerce'), absint($result)); |
|
509 | 509 | break; |
510 | 510 | |
511 | 511 | case 'install_pages': |
512 | 512 | WC_Install::create_pages(); |
513 | - $message = __( 'All missing WooCommerce pages successfully installed', 'woocommerce' ); |
|
513 | + $message = __('All missing WooCommerce pages successfully installed', 'woocommerce'); |
|
514 | 514 | break; |
515 | 515 | |
516 | 516 | case 'delete_taxes': |
517 | - $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;" ); |
|
518 | - $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;" ); |
|
519 | - WC_Cache_Helper::incr_cache_prefix( 'taxes' ); |
|
520 | - $message = __( 'Tax rates successfully deleted', 'woocommerce' ); |
|
517 | + $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;"); |
|
518 | + $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;"); |
|
519 | + WC_Cache_Helper::incr_cache_prefix('taxes'); |
|
520 | + $message = __('Tax rates successfully deleted', 'woocommerce'); |
|
521 | 521 | break; |
522 | 522 | |
523 | 523 | case 'regenerate_thumbnails': |
524 | 524 | WC_Regenerate_Images::queue_image_regeneration(); |
525 | - $message = __( 'Thumbnail regeneration has been scheduled to run in the background.', 'woocommerce' ); |
|
525 | + $message = __('Thumbnail regeneration has been scheduled to run in the background.', 'woocommerce'); |
|
526 | 526 | break; |
527 | 527 | |
528 | 528 | case 'db_update_routine': |
529 | 529 | $blog_id = get_current_blog_id(); |
530 | 530 | // Used to fire an action added in WP_Background_Process::_construct() that calls WP_Background_Process::handle_cron_healthcheck(). |
531 | 531 | // This method will make sure the database updates are executed even if cron is disabled. Nothing will happen if the updates are already running. |
532 | - do_action( 'wp_' . $blog_id . '_wc_updater_cron' ); |
|
533 | - $message = __( 'Database upgrade routine has been scheduled to run in the background.', 'woocommerce' ); |
|
532 | + do_action('wp_' . $blog_id . '_wc_updater_cron'); |
|
533 | + $message = __('Database upgrade routine has been scheduled to run in the background.', 'woocommerce'); |
|
534 | 534 | break; |
535 | 535 | |
536 | 536 | default: |
537 | 537 | $tools = $this->get_tools(); |
538 | - if ( isset( $tools[ $tool ]['callback'] ) ) { |
|
539 | - $callback = $tools[ $tool ]['callback']; |
|
540 | - $return = call_user_func( $callback ); |
|
541 | - if ( is_string( $return ) ) { |
|
538 | + if (isset($tools[$tool]['callback'])) { |
|
539 | + $callback = $tools[$tool]['callback']; |
|
540 | + $return = call_user_func($callback); |
|
541 | + if (is_string($return)) { |
|
542 | 542 | $message = $return; |
543 | - } elseif ( false === $return ) { |
|
544 | - $callback_string = is_array( $callback ) ? get_class( $callback[0] ) . '::' . $callback[1] : $callback; |
|
543 | + } elseif (false === $return) { |
|
544 | + $callback_string = is_array($callback) ? get_class($callback[0]) . '::' . $callback[1] : $callback; |
|
545 | 545 | $ran = false; |
546 | 546 | /* translators: %s: callback string */ |
547 | - $message = sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string ); |
|
547 | + $message = sprintf(__('There was an error calling %s', 'woocommerce'), $callback_string); |
|
548 | 548 | } else { |
549 | - $message = __( 'Tool ran.', 'woocommerce' ); |
|
549 | + $message = __('Tool ran.', 'woocommerce'); |
|
550 | 550 | } |
551 | 551 | } else { |
552 | 552 | $ran = false; |
553 | - $message = __( 'There was an error calling this tool. There is no callback present.', 'woocommerce' ); |
|
553 | + $message = __('There was an error calling this tool. There is no callback present.', 'woocommerce'); |
|
554 | 554 | } |
555 | 555 | break; |
556 | 556 | } |