@@ -33,7 +33,7 @@ |
||
33 | 33 | * @return object Instance. |
34 | 34 | */ |
35 | 35 | final public static function instance() { |
36 | - if ( null === static::$instance ) { |
|
36 | + if (null === static::$instance) { |
|
37 | 37 | static::$instance = new static(); |
38 | 38 | } |
39 | 39 | return static::$instance; |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API System Status Tools controller class. |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | array( |
34 | 34 | array( |
35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
36 | - 'callback' => array( $this, 'get_items' ), |
|
37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'get_items'), |
|
37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
38 | 38 | 'args' => $this->get_collection_params(), |
39 | 39 | ), |
40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
41 | 41 | ), |
42 | 42 | true |
43 | 43 | ); |
@@ -48,22 +48,22 @@ discard block |
||
48 | 48 | array( |
49 | 49 | 'args' => array( |
50 | 50 | 'id' => array( |
51 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
51 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
52 | 52 | 'type' => 'string', |
53 | 53 | ), |
54 | 54 | ), |
55 | 55 | array( |
56 | 56 | 'methods' => \WP_REST_Server::READABLE, |
57 | - 'callback' => array( $this, 'get_item' ), |
|
58 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
57 | + 'callback' => array($this, 'get_item'), |
|
58 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
59 | 59 | ), |
60 | 60 | array( |
61 | 61 | 'methods' => \WP_REST_Server::EDITABLE, |
62 | - 'callback' => array( $this, 'update_item' ), |
|
63 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
64 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
62 | + 'callback' => array($this, 'update_item'), |
|
63 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
64 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
65 | 65 | ), |
66 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
66 | + 'schema' => array($this, 'get_public_item_schema'), |
|
67 | 67 | ), |
68 | 68 | true |
69 | 69 | ); |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | * @param \WP_REST_Request $request Full details about the request. |
76 | 76 | * @return \WP_Error|boolean |
77 | 77 | */ |
78 | - public function get_items_permissions_check( $request ) { |
|
79 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
80 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
78 | + public function get_items_permissions_check($request) { |
|
79 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
80 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
81 | 81 | } |
82 | 82 | return true; |
83 | 83 | } |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | * @param \WP_REST_Request $request Full details about the request. |
89 | 89 | * @return \WP_Error|boolean |
90 | 90 | */ |
91 | - public function get_item_permissions_check( $request ) { |
|
92 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'read' ) ) { |
|
93 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
91 | + public function get_item_permissions_check($request) { |
|
92 | + if ( ! wc_rest_check_manager_permissions('system_status', 'read')) { |
|
93 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
94 | 94 | } |
95 | 95 | return true; |
96 | 96 | } |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param \WP_REST_Request $request Full details about the request. |
102 | 102 | * @return \WP_Error|boolean |
103 | 103 | */ |
104 | - public function update_item_permissions_check( $request ) { |
|
105 | - if ( ! wc_rest_check_manager_permissions( 'system_status', 'edit' ) ) { |
|
106 | - return new \WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
104 | + public function update_item_permissions_check($request) { |
|
105 | + if ( ! wc_rest_check_manager_permissions('system_status', 'edit')) { |
|
106 | + return new \WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
107 | 107 | } |
108 | 108 | return true; |
109 | 109 | } |
@@ -117,89 +117,89 @@ discard block |
||
117 | 117 | public function get_tools() { |
118 | 118 | $tools = array( |
119 | 119 | 'clear_transients' => array( |
120 | - 'name' => __( 'WooCommerce transients', 'woocommerce' ), |
|
121 | - 'button' => __( 'Clear transients', 'woocommerce' ), |
|
122 | - 'desc' => __( 'This tool will clear the product/shop transients cache.', 'woocommerce' ), |
|
120 | + 'name' => __('WooCommerce transients', 'woocommerce'), |
|
121 | + 'button' => __('Clear transients', 'woocommerce'), |
|
122 | + 'desc' => __('This tool will clear the product/shop transients cache.', 'woocommerce'), |
|
123 | 123 | ), |
124 | 124 | 'clear_expired_transients' => array( |
125 | - 'name' => __( 'Expired transients', 'woocommerce' ), |
|
126 | - 'button' => __( 'Clear transients', 'woocommerce' ), |
|
127 | - 'desc' => __( 'This tool will clear ALL expired transients from WordPress.', 'woocommerce' ), |
|
125 | + 'name' => __('Expired transients', 'woocommerce'), |
|
126 | + 'button' => __('Clear transients', 'woocommerce'), |
|
127 | + 'desc' => __('This tool will clear ALL expired transients from WordPress.', 'woocommerce'), |
|
128 | 128 | ), |
129 | 129 | 'delete_orphaned_variations' => array( |
130 | - 'name' => __( 'Orphaned variations', 'woocommerce' ), |
|
131 | - 'button' => __( 'Delete orphaned variations', 'woocommerce' ), |
|
132 | - 'desc' => __( 'This tool will delete all variations which have no parent.', 'woocommerce' ), |
|
130 | + 'name' => __('Orphaned variations', 'woocommerce'), |
|
131 | + 'button' => __('Delete orphaned variations', 'woocommerce'), |
|
132 | + 'desc' => __('This tool will delete all variations which have no parent.', 'woocommerce'), |
|
133 | 133 | ), |
134 | 134 | 'clear_expired_download_permissions' => array( |
135 | - 'name' => __( 'Used-up download permissions', 'woocommerce' ), |
|
136 | - 'button' => __( 'Clean up download permissions', 'woocommerce' ), |
|
137 | - 'desc' => __( 'This tool will delete expired download permissions and permissions with 0 remaining downloads.', 'woocommerce' ), |
|
135 | + 'name' => __('Used-up download permissions', 'woocommerce'), |
|
136 | + 'button' => __('Clean up download permissions', 'woocommerce'), |
|
137 | + 'desc' => __('This tool will delete expired download permissions and permissions with 0 remaining downloads.', 'woocommerce'), |
|
138 | 138 | ), |
139 | 139 | 'regenerate_product_lookup_tables' => array( |
140 | - 'name' => __( 'Product lookup tables', 'woocommerce' ), |
|
141 | - 'button' => __( 'Regenerate', 'woocommerce' ), |
|
142 | - 'desc' => __( 'This tool will regenerate product lookup table data. This process may take a while.', 'woocommerce' ), |
|
140 | + 'name' => __('Product lookup tables', 'woocommerce'), |
|
141 | + 'button' => __('Regenerate', 'woocommerce'), |
|
142 | + 'desc' => __('This tool will regenerate product lookup table data. This process may take a while.', 'woocommerce'), |
|
143 | 143 | ), |
144 | 144 | 'recount_terms' => array( |
145 | - 'name' => __( 'Term counts', 'woocommerce' ), |
|
146 | - 'button' => __( 'Recount terms', 'woocommerce' ), |
|
147 | - 'desc' => __( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', 'woocommerce' ), |
|
145 | + 'name' => __('Term counts', 'woocommerce'), |
|
146 | + 'button' => __('Recount terms', 'woocommerce'), |
|
147 | + 'desc' => __('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', 'woocommerce'), |
|
148 | 148 | ), |
149 | 149 | 'reset_roles' => array( |
150 | - 'name' => __( 'Capabilities', 'woocommerce' ), |
|
151 | - 'button' => __( 'Reset capabilities', 'woocommerce' ), |
|
152 | - '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' ), |
|
150 | + 'name' => __('Capabilities', 'woocommerce'), |
|
151 | + 'button' => __('Reset capabilities', 'woocommerce'), |
|
152 | + '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'), |
|
153 | 153 | ), |
154 | 154 | 'clear_sessions' => array( |
155 | - 'name' => __( 'Clear customer sessions', 'woocommerce' ), |
|
156 | - 'button' => __( 'Clear', 'woocommerce' ), |
|
155 | + 'name' => __('Clear customer sessions', 'woocommerce'), |
|
156 | + 'button' => __('Clear', 'woocommerce'), |
|
157 | 157 | 'desc' => sprintf( |
158 | 158 | '<strong class="red">%1$s</strong> %2$s', |
159 | - __( 'Note:', 'woocommerce' ), |
|
160 | - __( 'This tool will delete all customer session data from the database, including current carts and saved carts in the database.', 'woocommerce' ) |
|
159 | + __('Note:', 'woocommerce'), |
|
160 | + __('This tool will delete all customer session data from the database, including current carts and saved carts in the database.', 'woocommerce') |
|
161 | 161 | ), |
162 | 162 | ), |
163 | 163 | 'install_pages' => array( |
164 | - 'name' => __( 'Create default WooCommerce pages', 'woocommerce' ), |
|
165 | - 'button' => __( 'Create pages', 'woocommerce' ), |
|
164 | + 'name' => __('Create default WooCommerce pages', 'woocommerce'), |
|
165 | + 'button' => __('Create pages', 'woocommerce'), |
|
166 | 166 | 'desc' => sprintf( |
167 | 167 | '<strong class="red">%1$s</strong> %2$s', |
168 | - __( 'Note:', 'woocommerce' ), |
|
169 | - __( 'This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.', 'woocommerce' ) |
|
168 | + __('Note:', 'woocommerce'), |
|
169 | + __('This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.', 'woocommerce') |
|
170 | 170 | ), |
171 | 171 | ), |
172 | 172 | 'delete_taxes' => array( |
173 | - 'name' => __( 'Delete WooCommerce tax rates', 'woocommerce' ), |
|
174 | - 'button' => __( 'Delete tax rates', 'woocommerce' ), |
|
173 | + 'name' => __('Delete WooCommerce tax rates', 'woocommerce'), |
|
174 | + 'button' => __('Delete tax rates', 'woocommerce'), |
|
175 | 175 | 'desc' => sprintf( |
176 | 176 | '<strong class="red">%1$s</strong> %2$s', |
177 | - __( 'Note:', 'woocommerce' ), |
|
178 | - __( 'This option will delete ALL of your tax rates, use with caution. This action cannot be reversed.', 'woocommerce' ) |
|
177 | + __('Note:', 'woocommerce'), |
|
178 | + __('This option will delete ALL of your tax rates, use with caution. This action cannot be reversed.', 'woocommerce') |
|
179 | 179 | ), |
180 | 180 | ), |
181 | 181 | 'regenerate_thumbnails' => array( |
182 | - 'name' => __( 'Regenerate shop thumbnails', 'woocommerce' ), |
|
183 | - 'button' => __( 'Regenerate', 'woocommerce' ), |
|
184 | - 'desc' => __( 'This will regenerate all shop thumbnails to match your theme and/or image settings.', 'woocommerce' ), |
|
182 | + 'name' => __('Regenerate shop thumbnails', 'woocommerce'), |
|
183 | + 'button' => __('Regenerate', 'woocommerce'), |
|
184 | + 'desc' => __('This will regenerate all shop thumbnails to match your theme and/or image settings.', 'woocommerce'), |
|
185 | 185 | ), |
186 | 186 | 'db_update_routine' => array( |
187 | - 'name' => __( 'Update database', 'woocommerce' ), |
|
188 | - 'button' => __( 'Update database', 'woocommerce' ), |
|
187 | + 'name' => __('Update database', 'woocommerce'), |
|
188 | + 'button' => __('Update database', 'woocommerce'), |
|
189 | 189 | 'desc' => sprintf( |
190 | 190 | '<strong class="red">%1$s</strong> %2$s', |
191 | - __( 'Note:', 'woocommerce' ), |
|
192 | - __( 'This tool will update your WooCommerce database to the latest version. Please ensure you make sufficient backups before proceeding.', 'woocommerce' ) |
|
191 | + __('Note:', 'woocommerce'), |
|
192 | + __('This tool will update your WooCommerce database to the latest version. Please ensure you make sufficient backups before proceeding.', 'woocommerce') |
|
193 | 193 | ), |
194 | 194 | ), |
195 | 195 | ); |
196 | 196 | |
197 | 197 | // Jetpack does the image resizing heavy lifting so you don't have to. |
198 | - if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', true ) ) { |
|
199 | - unset( $tools['regenerate_thumbnails'] ); |
|
198 | + if ((class_exists('Jetpack') && Jetpack::is_module_active('photon')) || ! apply_filters('woocommerce_background_image_regeneration', true)) { |
|
199 | + unset($tools['regenerate_thumbnails']); |
|
200 | 200 | } |
201 | 201 | |
202 | - return apply_filters( 'woocommerce_debug_tools', $tools ); |
|
202 | + return apply_filters('woocommerce_debug_tools', $tools); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | * @param \WP_REST_Request $request Full details about the request. |
209 | 209 | * @return \WP_Error\WP_REST_Response |
210 | 210 | */ |
211 | - public function get_items( $request ) { |
|
211 | + public function get_items($request) { |
|
212 | 212 | $tools = array(); |
213 | - foreach ( $this->get_tools() as $id => $tool ) { |
|
213 | + foreach ($this->get_tools() as $id => $tool) { |
|
214 | 214 | $tools[] = $this->prepare_response_for_collection( |
215 | 215 | $this->prepare_item_for_response( |
216 | 216 | array( |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | ); |
225 | 225 | } |
226 | 226 | |
227 | - $response = rest_ensure_response( $tools ); |
|
227 | + $response = rest_ensure_response($tools); |
|
228 | 228 | return $response; |
229 | 229 | } |
230 | 230 | |
@@ -234,12 +234,12 @@ discard block |
||
234 | 234 | * @param \WP_REST_Request $request Request data. |
235 | 235 | * @return \WP_Error\WP_REST_Response |
236 | 236 | */ |
237 | - public function get_item( $request ) { |
|
237 | + public function get_item($request) { |
|
238 | 238 | $tools = $this->get_tools(); |
239 | - if ( empty( $tools[ $request['id'] ] ) ) { |
|
240 | - return new \WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
239 | + if (empty($tools[$request['id']])) { |
|
240 | + return new \WP_Error('woocommerce_rest_system_status_tool_invalid_id', __('Invalid tool ID.', 'woocommerce'), array('status' => 404)); |
|
241 | 241 | } |
242 | - $tool = $tools[ $request['id'] ]; |
|
242 | + $tool = $tools[$request['id']]; |
|
243 | 243 | return rest_ensure_response( |
244 | 244 | $this->prepare_item_for_response( |
245 | 245 | array( |
@@ -259,13 +259,13 @@ discard block |
||
259 | 259 | * @param \WP_REST_Request $request Request data. |
260 | 260 | * @return \WP_Error\WP_REST_Response |
261 | 261 | */ |
262 | - public function update_item( $request ) { |
|
262 | + public function update_item($request) { |
|
263 | 263 | $tools = $this->get_tools(); |
264 | - if ( empty( $tools[ $request['id'] ] ) ) { |
|
265 | - return new \WP_Error( 'woocommerce_rest_system_status_tool_invalid_id', __( 'Invalid tool ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
264 | + if (empty($tools[$request['id']])) { |
|
265 | + return new \WP_Error('woocommerce_rest_system_status_tool_invalid_id', __('Invalid tool ID.', 'woocommerce'), array('status' => 404)); |
|
266 | 266 | } |
267 | 267 | |
268 | - $tool = $tools[ $request['id'] ]; |
|
268 | + $tool = $tools[$request['id']]; |
|
269 | 269 | $tool = array( |
270 | 270 | 'id' => $request['id'], |
271 | 271 | 'name' => $tool['name'], |
@@ -273,8 +273,8 @@ discard block |
||
273 | 273 | 'description' => $tool['desc'], |
274 | 274 | ); |
275 | 275 | |
276 | - $execute_return = $this->execute_tool( $request['id'] ); |
|
277 | - $tool = array_merge( $tool, $execute_return ); |
|
276 | + $execute_return = $this->execute_tool($request['id']); |
|
277 | + $tool = array_merge($tool, $execute_return); |
|
278 | 278 | |
279 | 279 | /** |
280 | 280 | * Fires after a WooCommerce REST system status tool has been executed. |
@@ -282,11 +282,11 @@ discard block |
||
282 | 282 | * @param array $tool Details about the tool that has been executed. |
283 | 283 | * @param \WP_REST_Request $request The current \WP_REST_Request object. |
284 | 284 | */ |
285 | - do_action( 'woocommerce_rest_insert_system_status_tool', $tool, $request ); |
|
285 | + do_action('woocommerce_rest_insert_system_status_tool', $tool, $request); |
|
286 | 286 | |
287 | - $request->set_param( 'context', 'edit' ); |
|
288 | - $response = $this->prepare_item_for_response( $tool, $request ); |
|
289 | - return rest_ensure_response( $response ); |
|
287 | + $request->set_param('context', 'edit'); |
|
288 | + $response = $this->prepare_item_for_response($tool, $request); |
|
289 | + return rest_ensure_response($response); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -296,14 +296,14 @@ discard block |
||
296 | 296 | * @param \WP_REST_Request $request Request object. |
297 | 297 | * @return \WP_REST_Response $response Response data. |
298 | 298 | */ |
299 | - public function prepare_item_for_response( $item, $request ) { |
|
300 | - $context = empty( $request['context'] ) ? 'view' : $request['context']; |
|
301 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
302 | - $data = $this->filter_response_by_context( $data, $context ); |
|
299 | + public function prepare_item_for_response($item, $request) { |
|
300 | + $context = empty($request['context']) ? 'view' : $request['context']; |
|
301 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
302 | + $data = $this->filter_response_by_context($data, $context); |
|
303 | 303 | |
304 | - $response = rest_ensure_response( $data ); |
|
304 | + $response = rest_ensure_response($data); |
|
305 | 305 | |
306 | - $response->add_links( $this->prepare_links( $item['id'] ) ); |
|
306 | + $response->add_links($this->prepare_links($item['id'])); |
|
307 | 307 | |
308 | 308 | return $response; |
309 | 309 | } |
@@ -320,46 +320,46 @@ discard block |
||
320 | 320 | 'type' => 'object', |
321 | 321 | 'properties' => array( |
322 | 322 | 'id' => array( |
323 | - 'description' => __( 'A unique identifier for the tool.', 'woocommerce' ), |
|
323 | + 'description' => __('A unique identifier for the tool.', 'woocommerce'), |
|
324 | 324 | 'type' => 'string', |
325 | - 'context' => array( 'view', 'edit' ), |
|
325 | + 'context' => array('view', 'edit'), |
|
326 | 326 | 'arg_options' => array( |
327 | 327 | 'sanitize_callback' => 'sanitize_title', |
328 | 328 | ), |
329 | 329 | ), |
330 | 330 | 'name' => array( |
331 | - 'description' => __( 'Tool name.', 'woocommerce' ), |
|
331 | + 'description' => __('Tool name.', 'woocommerce'), |
|
332 | 332 | 'type' => 'string', |
333 | - 'context' => array( 'view', 'edit' ), |
|
333 | + 'context' => array('view', 'edit'), |
|
334 | 334 | 'arg_options' => array( |
335 | 335 | 'sanitize_callback' => 'sanitize_text_field', |
336 | 336 | ), |
337 | 337 | ), |
338 | 338 | 'action' => array( |
339 | - 'description' => __( 'What running the tool will do.', 'woocommerce' ), |
|
339 | + 'description' => __('What running the tool will do.', 'woocommerce'), |
|
340 | 340 | 'type' => 'string', |
341 | - 'context' => array( 'view', 'edit' ), |
|
341 | + 'context' => array('view', 'edit'), |
|
342 | 342 | 'arg_options' => array( |
343 | 343 | 'sanitize_callback' => 'sanitize_text_field', |
344 | 344 | ), |
345 | 345 | ), |
346 | 346 | 'description' => array( |
347 | - 'description' => __( 'Tool description.', 'woocommerce' ), |
|
347 | + 'description' => __('Tool description.', 'woocommerce'), |
|
348 | 348 | 'type' => 'string', |
349 | - 'context' => array( 'view', 'edit' ), |
|
349 | + 'context' => array('view', 'edit'), |
|
350 | 350 | 'arg_options' => array( |
351 | 351 | 'sanitize_callback' => 'sanitize_text_field', |
352 | 352 | ), |
353 | 353 | ), |
354 | 354 | 'success' => array( |
355 | - 'description' => __( 'Did the tool run successfully?', 'woocommerce' ), |
|
355 | + 'description' => __('Did the tool run successfully?', 'woocommerce'), |
|
356 | 356 | 'type' => 'boolean', |
357 | - 'context' => array( 'edit' ), |
|
357 | + 'context' => array('edit'), |
|
358 | 358 | ), |
359 | 359 | 'message' => array( |
360 | - 'description' => __( 'Tool return message.', 'woocommerce' ), |
|
360 | + 'description' => __('Tool return message.', 'woocommerce'), |
|
361 | 361 | 'type' => 'string', |
362 | - 'context' => array( 'edit' ), |
|
362 | + 'context' => array('edit'), |
|
363 | 363 | 'arg_options' => array( |
364 | 364 | 'sanitize_callback' => 'sanitize_text_field', |
365 | 365 | ), |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | ), |
368 | 368 | ); |
369 | 369 | |
370 | - return $this->add_additional_fields_schema( $schema ); |
|
370 | + return $this->add_additional_fields_schema($schema); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -376,11 +376,11 @@ discard block |
||
376 | 376 | * @param string $id ID. |
377 | 377 | * @return array |
378 | 378 | */ |
379 | - protected function prepare_links( $id ) { |
|
379 | + protected function prepare_links($id) { |
|
380 | 380 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
381 | 381 | $links = array( |
382 | 382 | 'item' => array( |
383 | - 'href' => rest_url( trailingslashit( $base ) . $id ), |
|
383 | + 'href' => rest_url(trailingslashit($base) . $id), |
|
384 | 384 | 'embeddable' => true, |
385 | 385 | ), |
386 | 386 | ); |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | */ |
396 | 396 | public function get_collection_params() { |
397 | 397 | return array( |
398 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
398 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
399 | 399 | ); |
400 | 400 | } |
401 | 401 | |
@@ -405,30 +405,30 @@ discard block |
||
405 | 405 | * @param string $tool Tool. |
406 | 406 | * @return array |
407 | 407 | */ |
408 | - public function execute_tool( $tool ) { |
|
408 | + public function execute_tool($tool) { |
|
409 | 409 | global $wpdb; |
410 | 410 | $ran = true; |
411 | - switch ( $tool ) { |
|
411 | + switch ($tool) { |
|
412 | 412 | case 'clear_transients': |
413 | 413 | wc_delete_product_transients(); |
414 | 414 | wc_delete_shop_order_transients(); |
415 | - delete_transient( 'wc_count_comments' ); |
|
415 | + delete_transient('wc_count_comments'); |
|
416 | 416 | |
417 | 417 | $attribute_taxonomies = wc_get_attribute_taxonomies(); |
418 | 418 | |
419 | - if ( $attribute_taxonomies ) { |
|
420 | - foreach ( $attribute_taxonomies as $attribute ) { |
|
421 | - delete_transient( 'wc_layered_nav_counts_pa_' . $attribute->attribute_name ); |
|
419 | + if ($attribute_taxonomies) { |
|
420 | + foreach ($attribute_taxonomies as $attribute) { |
|
421 | + delete_transient('wc_layered_nav_counts_pa_' . $attribute->attribute_name); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | - \WC_Cache_Helper::get_transient_version( 'shipping', true ); |
|
426 | - $message = __( 'Product transients cleared', 'woocommerce' ); |
|
425 | + \WC_Cache_Helper::get_transient_version('shipping', true); |
|
426 | + $message = __('Product transients cleared', 'woocommerce'); |
|
427 | 427 | break; |
428 | 428 | |
429 | 429 | case 'clear_expired_transients': |
430 | 430 | /* translators: %d: amount of expired transients */ |
431 | - $message = sprintf( __( '%d transients rows cleared', 'woocommerce' ), wc_delete_expired_transients() ); |
|
431 | + $message = sprintf(__('%d transients rows cleared', 'woocommerce'), wc_delete_expired_transients()); |
|
432 | 432 | break; |
433 | 433 | |
434 | 434 | case 'delete_orphaned_variations': |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | ) |
443 | 443 | ); |
444 | 444 | /* translators: %d: amount of orphaned variations */ |
445 | - $message = sprintf( __( '%d orphaned variations deleted', 'woocommerce' ), $result ); |
|
445 | + $message = sprintf(__('%d orphaned variations deleted', 'woocommerce'), $result); |
|
446 | 446 | break; |
447 | 447 | |
448 | 448 | case 'clear_expired_download_permissions': |
@@ -452,25 +452,25 @@ discard block |
||
452 | 452 | $wpdb->prepare( |
453 | 453 | "DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions |
454 | 454 | WHERE ( downloads_remaining != '' AND downloads_remaining = 0 ) OR ( access_expires IS NOT NULL AND access_expires < %s )", |
455 | - date( 'Y-m-d', current_time( 'timestamp' ) ) |
|
455 | + date('Y-m-d', current_time('timestamp')) |
|
456 | 456 | ) |
457 | 457 | ) |
458 | 458 | ); |
459 | 459 | /* translators: %d: amount of permissions */ |
460 | - $message = sprintf( __( '%d permissions deleted', 'woocommerce' ), $result ); |
|
460 | + $message = sprintf(__('%d permissions deleted', 'woocommerce'), $result); |
|
461 | 461 | break; |
462 | 462 | |
463 | 463 | case 'regenerate_product_lookup_tables': |
464 | - if ( ! wc_update_product_lookup_tables_is_running() ) { |
|
464 | + if ( ! wc_update_product_lookup_tables_is_running()) { |
|
465 | 465 | wc_update_product_lookup_tables(); |
466 | 466 | } |
467 | - $message = __( 'Lookup tables are regenerating', 'woocommerce' ); |
|
467 | + $message = __('Lookup tables are regenerating', 'woocommerce'); |
|
468 | 468 | break; |
469 | 469 | case 'reset_roles': |
470 | 470 | // Remove then re-add caps and roles. |
471 | 471 | \WC_Install::remove_roles(); |
472 | 472 | \WC_Install::create_roles(); |
473 | - $message = __( 'Roles successfully reset', 'woocommerce' ); |
|
473 | + $message = __('Roles successfully reset', 'woocommerce'); |
|
474 | 474 | break; |
475 | 475 | |
476 | 476 | case 'recount_terms': |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | 'fields' => 'id=>parent', |
482 | 482 | ) |
483 | 483 | ); |
484 | - _wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), true, false ); |
|
484 | + _wc_term_recount($product_cats, get_taxonomy('product_cat'), true, false); |
|
485 | 485 | $product_tags = get_terms( |
486 | 486 | 'product_tag', |
487 | 487 | array( |
@@ -489,61 +489,61 @@ discard block |
||
489 | 489 | 'fields' => 'id=>parent', |
490 | 490 | ) |
491 | 491 | ); |
492 | - _wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), true, false ); |
|
493 | - $message = __( 'Terms successfully recounted', 'woocommerce' ); |
|
492 | + _wc_term_recount($product_tags, get_taxonomy('product_tag'), true, false); |
|
493 | + $message = __('Terms successfully recounted', 'woocommerce'); |
|
494 | 494 | break; |
495 | 495 | |
496 | 496 | case 'clear_sessions': |
497 | - $wpdb->query( "TRUNCATE {$wpdb->prefix}woocommerce_sessions" ); |
|
498 | - $result = absint( $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';" ) ); // WPCS: unprepared SQL ok. |
|
497 | + $wpdb->query("TRUNCATE {$wpdb->prefix}woocommerce_sessions"); |
|
498 | + $result = absint($wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key='_woocommerce_persistent_cart_" . get_current_blog_id() . "';")); // WPCS: unprepared SQL ok. |
|
499 | 499 | wp_cache_flush(); |
500 | 500 | /* translators: %d: amount of sessions */ |
501 | - $message = sprintf( __( 'Deleted all active sessions, and %d saved carts.', 'woocommerce' ), absint( $result ) ); |
|
501 | + $message = sprintf(__('Deleted all active sessions, and %d saved carts.', 'woocommerce'), absint($result)); |
|
502 | 502 | break; |
503 | 503 | |
504 | 504 | case 'install_pages': |
505 | 505 | \WC_Install::create_pages(); |
506 | - $message = __( 'All missing WooCommerce pages successfully installed', 'woocommerce' ); |
|
506 | + $message = __('All missing WooCommerce pages successfully installed', 'woocommerce'); |
|
507 | 507 | break; |
508 | 508 | |
509 | 509 | case 'delete_taxes': |
510 | - $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;" ); |
|
511 | - $wpdb->query( "TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;" ); |
|
512 | - \WC_Cache_Helper::incr_cache_prefix( 'taxes' ); |
|
513 | - $message = __( 'Tax rates successfully deleted', 'woocommerce' ); |
|
510 | + $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rates;"); |
|
511 | + $wpdb->query("TRUNCATE TABLE {$wpdb->prefix}woocommerce_tax_rate_locations;"); |
|
512 | + \WC_Cache_Helper::incr_cache_prefix('taxes'); |
|
513 | + $message = __('Tax rates successfully deleted', 'woocommerce'); |
|
514 | 514 | break; |
515 | 515 | |
516 | 516 | case 'regenerate_thumbnails': |
517 | 517 | \WC_Regenerate_Images::queue_image_regeneration(); |
518 | - $message = __( 'Thumbnail regeneration has been scheduled to run in the background.', 'woocommerce' ); |
|
518 | + $message = __('Thumbnail regeneration has been scheduled to run in the background.', 'woocommerce'); |
|
519 | 519 | break; |
520 | 520 | |
521 | 521 | case 'db_update_routine': |
522 | 522 | $blog_id = get_current_blog_id(); |
523 | 523 | // Used to fire an action added in WP_Background_Process::_construct() that calls WP_Background_Process::handle_cron_healthcheck(). |
524 | 524 | // This method will make sure the database updates are executed even if cron is disabled. Nothing will happen if the updates are already running. |
525 | - do_action( 'wp_' . $blog_id . '_wc_updater_cron' ); |
|
526 | - $message = __( 'Database upgrade routine has been scheduled to run in the background.', 'woocommerce' ); |
|
525 | + do_action('wp_' . $blog_id . '_wc_updater_cron'); |
|
526 | + $message = __('Database upgrade routine has been scheduled to run in the background.', 'woocommerce'); |
|
527 | 527 | break; |
528 | 528 | |
529 | 529 | default: |
530 | 530 | $tools = $this->get_tools(); |
531 | - if ( isset( $tools[ $tool ]['callback'] ) ) { |
|
532 | - $callback = $tools[ $tool ]['callback']; |
|
533 | - $return = call_user_func( $callback ); |
|
534 | - if ( is_string( $return ) ) { |
|
531 | + if (isset($tools[$tool]['callback'])) { |
|
532 | + $callback = $tools[$tool]['callback']; |
|
533 | + $return = call_user_func($callback); |
|
534 | + if (is_string($return)) { |
|
535 | 535 | $message = $return; |
536 | - } elseif ( false === $return ) { |
|
537 | - $callback_string = is_array( $callback ) ? get_class( $callback[0] ) . '::' . $callback[1] : $callback; |
|
536 | + } elseif (false === $return) { |
|
537 | + $callback_string = is_array($callback) ? get_class($callback[0]) . '::' . $callback[1] : $callback; |
|
538 | 538 | $ran = false; |
539 | 539 | /* translators: %s: callback string */ |
540 | - $message = sprintf( __( 'There was an error calling %s', 'woocommerce' ), $callback_string ); |
|
540 | + $message = sprintf(__('There was an error calling %s', 'woocommerce'), $callback_string); |
|
541 | 541 | } else { |
542 | - $message = __( 'Tool ran.', 'woocommerce' ); |
|
542 | + $message = __('Tool ran.', 'woocommerce'); |
|
543 | 543 | } |
544 | 544 | } else { |
545 | 545 | $ran = false; |
546 | - $message = __( 'There was an error calling this tool. There is no callback present.', 'woocommerce' ); |
|
546 | + $message = __('There was an error calling this tool. There is no callback present.', 'woocommerce'); |
|
547 | 547 | } |
548 | 548 | break; |
549 | 549 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Product Tags controller class. |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param \WP_REST_Request $request Request params. |
38 | 38 | * @return \WP_REST_Response $response |
39 | 39 | */ |
40 | - public function prepare_item_for_response( $item, $request ) { |
|
40 | + public function prepare_item_for_response($item, $request) { |
|
41 | 41 | $data = array( |
42 | 42 | 'id' => (int) $item->term_id, |
43 | 43 | 'name' => $item->name, |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | 'count' => (int) $item->count, |
47 | 47 | ); |
48 | 48 | |
49 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
50 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
51 | - $data = $this->filter_response_by_context( $data, $context ); |
|
49 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
50 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
51 | + $data = $this->filter_response_by_context($data, $context); |
|
52 | 52 | |
53 | - $response = rest_ensure_response( $data ); |
|
53 | + $response = rest_ensure_response($data); |
|
54 | 54 | |
55 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
55 | + $response->add_links($this->prepare_links($item, $request)); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Filter a term item returned from the API. |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param object $item The original term object. |
64 | 64 | * @param \WP_REST_Request $request Request used to generate the response. |
65 | 65 | */ |
66 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
66 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -78,44 +78,44 @@ discard block |
||
78 | 78 | 'type' => 'object', |
79 | 79 | 'properties' => array( |
80 | 80 | 'id' => array( |
81 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
81 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
82 | 82 | 'type' => 'integer', |
83 | - 'context' => array( 'view', 'edit' ), |
|
83 | + 'context' => array('view', 'edit'), |
|
84 | 84 | 'readonly' => true, |
85 | 85 | ), |
86 | 86 | 'name' => array( |
87 | - 'description' => __( 'Tag name.', 'woocommerce' ), |
|
87 | + 'description' => __('Tag name.', 'woocommerce'), |
|
88 | 88 | 'type' => 'string', |
89 | - 'context' => array( 'view', 'edit' ), |
|
89 | + 'context' => array('view', 'edit'), |
|
90 | 90 | 'arg_options' => array( |
91 | 91 | 'sanitize_callback' => 'sanitize_text_field', |
92 | 92 | ), |
93 | 93 | ), |
94 | 94 | 'slug' => array( |
95 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
95 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
96 | 96 | 'type' => 'string', |
97 | - 'context' => array( 'view', 'edit' ), |
|
97 | + 'context' => array('view', 'edit'), |
|
98 | 98 | 'arg_options' => array( |
99 | 99 | 'sanitize_callback' => 'sanitize_title', |
100 | 100 | ), |
101 | 101 | ), |
102 | 102 | 'description' => array( |
103 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
103 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
104 | 104 | 'type' => 'string', |
105 | - 'context' => array( 'view', 'edit' ), |
|
105 | + 'context' => array('view', 'edit'), |
|
106 | 106 | 'arg_options' => array( |
107 | 107 | 'sanitize_callback' => 'wp_filter_post_kses', |
108 | 108 | ), |
109 | 109 | ), |
110 | 110 | 'count' => array( |
111 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
111 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
112 | 112 | 'type' => 'integer', |
113 | - 'context' => array( 'view', 'edit' ), |
|
113 | + 'context' => array('view', 'edit'), |
|
114 | 114 | 'readonly' => true, |
115 | 115 | ), |
116 | 116 | ), |
117 | 117 | ); |
118 | 118 | |
119 | - return $this->add_additional_fields_schema( $schema ); |
|
119 | + return $this->add_additional_fields_schema($schema); |
|
120 | 120 | } |
121 | 121 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | use \WP_REST_Server; |
15 | 15 | |
@@ -35,36 +35,36 @@ discard block |
||
35 | 35 | array( |
36 | 36 | array( |
37 | 37 | 'methods' => \WP_REST_Server::READABLE, |
38 | - 'callback' => array( $this, 'get_items' ), |
|
39 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
38 | + 'callback' => array($this, 'get_items'), |
|
39 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
40 | 40 | 'args' => $this->get_collection_params(), |
41 | 41 | ), |
42 | 42 | array( |
43 | 43 | 'methods' => \WP_REST_Server::CREATABLE, |
44 | - 'callback' => array( $this, 'create_item' ), |
|
45 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
44 | + 'callback' => array($this, 'create_item'), |
|
45 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
46 | 46 | 'args' => array_merge( |
47 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
47 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
48 | 48 | array( |
49 | 49 | 'email' => array( |
50 | 50 | 'required' => true, |
51 | 51 | 'type' => 'string', |
52 | - 'description' => __( 'New user email address.', 'woocommerce' ), |
|
52 | + 'description' => __('New user email address.', 'woocommerce'), |
|
53 | 53 | ), |
54 | 54 | 'username' => array( |
55 | - 'required' => 'no' === get_option( 'woocommerce_registration_generate_username', 'yes' ), |
|
56 | - 'description' => __( 'New user username.', 'woocommerce' ), |
|
55 | + 'required' => 'no' === get_option('woocommerce_registration_generate_username', 'yes'), |
|
56 | + 'description' => __('New user username.', 'woocommerce'), |
|
57 | 57 | 'type' => 'string', |
58 | 58 | ), |
59 | 59 | 'password' => array( |
60 | - 'required' => 'no' === get_option( 'woocommerce_registration_generate_password', 'no' ), |
|
61 | - 'description' => __( 'New user password.', 'woocommerce' ), |
|
60 | + 'required' => 'no' === get_option('woocommerce_registration_generate_password', 'no'), |
|
61 | + 'description' => __('New user password.', 'woocommerce'), |
|
62 | 62 | 'type' => 'string', |
63 | 63 | ), |
64 | 64 | ) |
65 | 65 | ), |
66 | 66 | ), |
67 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
67 | + 'schema' => array($this, 'get_public_item_schema'), |
|
68 | 68 | ), |
69 | 69 | true |
70 | 70 | ); |
@@ -75,42 +75,42 @@ discard block |
||
75 | 75 | array( |
76 | 76 | 'args' => array( |
77 | 77 | 'id' => array( |
78 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
78 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
79 | 79 | 'type' => 'integer', |
80 | 80 | ), |
81 | 81 | ), |
82 | 82 | array( |
83 | 83 | 'methods' => \WP_REST_Server::READABLE, |
84 | - 'callback' => array( $this, 'get_item' ), |
|
85 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
84 | + 'callback' => array($this, 'get_item'), |
|
85 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
86 | 86 | 'args' => array( |
87 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
87 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
88 | 88 | ), |
89 | 89 | ), |
90 | 90 | array( |
91 | 91 | 'methods' => \WP_REST_Server::EDITABLE, |
92 | - 'callback' => array( $this, 'update_item' ), |
|
93 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
94 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
92 | + 'callback' => array($this, 'update_item'), |
|
93 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
94 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
95 | 95 | ), |
96 | 96 | array( |
97 | 97 | 'methods' => \WP_REST_Server::DELETABLE, |
98 | - 'callback' => array( $this, 'delete_item' ), |
|
99 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
98 | + 'callback' => array($this, 'delete_item'), |
|
99 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
100 | 100 | 'args' => array( |
101 | 101 | 'force' => array( |
102 | 102 | 'default' => false, |
103 | 103 | 'type' => 'boolean', |
104 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
104 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
105 | 105 | ), |
106 | 106 | 'reassign' => array( |
107 | 107 | 'default' => 0, |
108 | 108 | 'type' => 'integer', |
109 | - 'description' => __( 'ID to reassign posts to.', 'woocommerce' ), |
|
109 | + 'description' => __('ID to reassign posts to.', 'woocommerce'), |
|
110 | 110 | ), |
111 | 111 | ), |
112 | 112 | ), |
113 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
113 | + 'schema' => array($this, 'get_public_item_schema'), |
|
114 | 114 | ), |
115 | 115 | true |
116 | 116 | ); |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | array( |
122 | 122 | array( |
123 | 123 | 'methods' => \WP_REST_Server::EDITABLE, |
124 | - 'callback' => array( $this, 'batch_items' ), |
|
125 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
126 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
124 | + 'callback' => array($this, 'batch_items'), |
|
125 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
126 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
127 | 127 | ), |
128 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
128 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
129 | 129 | ), |
130 | 130 | true |
131 | 131 | ); |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | * @param \WP_REST_Request $request Full details about the request. |
138 | 138 | * @return \WP_Error|boolean |
139 | 139 | */ |
140 | - public function get_items_permissions_check( $request ) { |
|
141 | - if ( ! wc_rest_check_user_permissions( 'read' ) ) { |
|
142 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
140 | + public function get_items_permissions_check($request) { |
|
141 | + if ( ! wc_rest_check_user_permissions('read')) { |
|
142 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | return true; |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return bool|\WP_Error |
154 | 154 | */ |
155 | - public function create_item_permissions_check( $request ) { |
|
156 | - if ( ! wc_rest_check_user_permissions( 'create' ) ) { |
|
157 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
155 | + public function create_item_permissions_check($request) { |
|
156 | + if ( ! wc_rest_check_user_permissions('create')) { |
|
157 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return true; |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | * @param \WP_REST_Request $request Full details about the request. |
167 | 167 | * @return \WP_Error|boolean |
168 | 168 | */ |
169 | - public function get_item_permissions_check( $request ) { |
|
169 | + public function get_item_permissions_check($request) { |
|
170 | 170 | $id = (int) $request['id']; |
171 | 171 | |
172 | - if ( ! wc_rest_check_user_permissions( 'read', $id ) ) { |
|
173 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
172 | + if ( ! wc_rest_check_user_permissions('read', $id)) { |
|
173 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return true; |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return bool|\WP_Error |
185 | 185 | */ |
186 | - public function update_item_permissions_check( $request ) { |
|
186 | + public function update_item_permissions_check($request) { |
|
187 | 187 | $id = (int) $request['id']; |
188 | 188 | |
189 | - if ( ! wc_rest_check_user_permissions( 'edit', $id ) ) { |
|
190 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
189 | + if ( ! wc_rest_check_user_permissions('edit', $id)) { |
|
190 | + return new \WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | return true; |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return bool|\WP_Error |
202 | 202 | */ |
203 | - public function delete_item_permissions_check( $request ) { |
|
203 | + public function delete_item_permissions_check($request) { |
|
204 | 204 | $id = (int) $request['id']; |
205 | 205 | |
206 | - if ( ! wc_rest_check_user_permissions( 'delete', $id ) ) { |
|
207 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
206 | + if ( ! wc_rest_check_user_permissions('delete', $id)) { |
|
207 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | return true; |
@@ -217,9 +217,9 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @return bool|\WP_Error |
219 | 219 | */ |
220 | - public function batch_items_permissions_check( $request ) { |
|
221 | - if ( ! wc_rest_check_user_permissions( 'batch' ) ) { |
|
222 | - return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
220 | + public function batch_items_permissions_check($request) { |
|
221 | + if ( ! wc_rest_check_user_permissions('batch')) { |
|
222 | + return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | return true; |
@@ -233,16 +233,16 @@ discard block |
||
233 | 233 | * @since 3.0.0 |
234 | 234 | * @return array |
235 | 235 | */ |
236 | - protected function get_formatted_item_data( $object ) { |
|
236 | + protected function get_formatted_item_data($object) { |
|
237 | 237 | $data = $object->get_data(); |
238 | - $format_date = array( 'date_created', 'date_modified' ); |
|
238 | + $format_date = array('date_created', 'date_modified'); |
|
239 | 239 | |
240 | 240 | // Format date values. |
241 | - foreach ( $format_date as $key ) { |
|
241 | + foreach ($format_date as $key) { |
|
242 | 242 | // Date created is stored UTC, date modified is stored WP local time. |
243 | - $datetime = 'date_created' === $key ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $data[ $key ]->getTimestamp() ) ) : $data[ $key ]; |
|
244 | - $data[ $key ] = wc_rest_prepare_date_response( $datetime, false ); |
|
245 | - $data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime ); |
|
243 | + $datetime = 'date_created' === $key ? get_date_from_gmt(gmdate('Y-m-d H:i:s', $data[$key]->getTimestamp())) : $data[$key]; |
|
244 | + $data[$key] = wc_rest_prepare_date_response($datetime, false); |
|
245 | + $data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | return array( |
@@ -270,16 +270,16 @@ discard block |
||
270 | 270 | * @param \WP_REST_Request $request Full details about the request. |
271 | 271 | * @return \WP_Error\WP_REST_Response |
272 | 272 | */ |
273 | - public function get_items( $request ) { |
|
273 | + public function get_items($request) { |
|
274 | 274 | $prepared_args = array(); |
275 | 275 | $prepared_args['exclude'] = $request['exclude']; |
276 | 276 | $prepared_args['include'] = $request['include']; |
277 | 277 | $prepared_args['order'] = $request['order']; |
278 | 278 | $prepared_args['number'] = $request['per_page']; |
279 | - if ( ! empty( $request['offset'] ) ) { |
|
279 | + if ( ! empty($request['offset'])) { |
|
280 | 280 | $prepared_args['offset'] = $request['offset']; |
281 | 281 | } else { |
282 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
282 | + $prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number']; |
|
283 | 283 | } |
284 | 284 | $orderby_possibles = array( |
285 | 285 | 'id' => 'ID', |
@@ -287,21 +287,21 @@ discard block |
||
287 | 287 | 'name' => 'display_name', |
288 | 288 | 'registered_date' => 'registered', |
289 | 289 | ); |
290 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
290 | + $prepared_args['orderby'] = $orderby_possibles[$request['orderby']]; |
|
291 | 291 | $prepared_args['search'] = $request['search']; |
292 | 292 | |
293 | - if ( '' !== $prepared_args['search'] ) { |
|
293 | + if ('' !== $prepared_args['search']) { |
|
294 | 294 | $prepared_args['search'] = '*' . $prepared_args['search'] . '*'; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Filter by email. |
298 | - if ( ! empty( $request['email'] ) ) { |
|
298 | + if ( ! empty($request['email'])) { |
|
299 | 299 | $prepared_args['search'] = $request['email']; |
300 | - $prepared_args['search_columns'] = array( 'user_email' ); |
|
300 | + $prepared_args['search_columns'] = array('user_email'); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | // Filter by role. |
304 | - if ( 'all' !== $request['role'] ) { |
|
304 | + if ('all' !== $request['role']) { |
|
305 | 305 | $prepared_args['role'] = $request['role']; |
306 | 306 | } |
307 | 307 | |
@@ -313,49 +313,49 @@ discard block |
||
313 | 313 | * @param array $prepared_args Array of arguments for \ WP_User_Query. |
314 | 314 | * @param \WP_REST_Request $request The current request. |
315 | 315 | */ |
316 | - $prepared_args = apply_filters( 'woocommerce_rest_customer_query', $prepared_args, $request ); |
|
316 | + $prepared_args = apply_filters('woocommerce_rest_customer_query', $prepared_args, $request); |
|
317 | 317 | |
318 | - $query = new \ WP_User_Query( $prepared_args ); |
|
318 | + $query = new \ WP_User_Query($prepared_args); |
|
319 | 319 | |
320 | 320 | $users = array(); |
321 | - foreach ( $query->results as $user ) { |
|
322 | - $data = $this->prepare_item_for_response( $user, $request ); |
|
323 | - $users[] = $this->prepare_response_for_collection( $data ); |
|
321 | + foreach ($query->results as $user) { |
|
322 | + $data = $this->prepare_item_for_response($user, $request); |
|
323 | + $users[] = $this->prepare_response_for_collection($data); |
|
324 | 324 | } |
325 | 325 | |
326 | - $response = rest_ensure_response( $users ); |
|
326 | + $response = rest_ensure_response($users); |
|
327 | 327 | |
328 | 328 | // Store pagination values for headers then unset for count query. |
329 | 329 | $per_page = (int) $prepared_args['number']; |
330 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
330 | + $page = ceil((((int) $prepared_args['offset']) / $per_page) + 1); |
|
331 | 331 | |
332 | 332 | $prepared_args['fields'] = 'ID'; |
333 | 333 | |
334 | 334 | $total_users = $query->get_total(); |
335 | - if ( $total_users < 1 ) { |
|
335 | + if ($total_users < 1) { |
|
336 | 336 | // Out-of-bounds, run the query again without LIMIT for total count. |
337 | - unset( $prepared_args['number'] ); |
|
338 | - unset( $prepared_args['offset'] ); |
|
339 | - $count_query = new \ WP_User_Query( $prepared_args ); |
|
337 | + unset($prepared_args['number']); |
|
338 | + unset($prepared_args['offset']); |
|
339 | + $count_query = new \ WP_User_Query($prepared_args); |
|
340 | 340 | $total_users = $count_query->get_total(); |
341 | 341 | } |
342 | - $response->header( 'X-WP-Total', (int) $total_users ); |
|
343 | - $max_pages = ceil( $total_users / $per_page ); |
|
344 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
342 | + $response->header('X-WP-Total', (int) $total_users); |
|
343 | + $max_pages = ceil($total_users / $per_page); |
|
344 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
345 | 345 | |
346 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
347 | - if ( $page > 1 ) { |
|
346 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
347 | + if ($page > 1) { |
|
348 | 348 | $prev_page = $page - 1; |
349 | - if ( $prev_page > $max_pages ) { |
|
349 | + if ($prev_page > $max_pages) { |
|
350 | 350 | $prev_page = $max_pages; |
351 | 351 | } |
352 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
353 | - $response->link_header( 'prev', $prev_link ); |
|
352 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
353 | + $response->link_header('prev', $prev_link); |
|
354 | 354 | } |
355 | - if ( $max_pages > $page ) { |
|
355 | + if ($max_pages > $page) { |
|
356 | 356 | $next_page = $page + 1; |
357 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
358 | - $response->link_header( 'next', $next_link ); |
|
357 | + $next_link = add_query_arg('page', $next_page, $base); |
|
358 | + $response->link_header('next', $next_link); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | return $response; |
@@ -368,32 +368,32 @@ discard block |
||
368 | 368 | * @param \WP_REST_Request $request Full details about the request. |
369 | 369 | * @return \WP_Error\WP_REST_Response |
370 | 370 | */ |
371 | - public function create_item( $request ) { |
|
371 | + public function create_item($request) { |
|
372 | 372 | try { |
373 | - if ( ! empty( $request['id'] ) ) { |
|
374 | - throw new \WC_REST_Exception( 'woocommerce_rest_customer_exists', __( 'Cannot create existing resource.', 'woocommerce' ), 400 ); |
|
373 | + if ( ! empty($request['id'])) { |
|
374 | + throw new \WC_REST_Exception('woocommerce_rest_customer_exists', __('Cannot create existing resource.', 'woocommerce'), 400); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | // Sets the username. |
378 | - $request['username'] = ! empty( $request['username'] ) ? $request['username'] : ''; |
|
378 | + $request['username'] = ! empty($request['username']) ? $request['username'] : ''; |
|
379 | 379 | |
380 | 380 | // Sets the password. |
381 | - $request['password'] = ! empty( $request['password'] ) ? $request['password'] : ''; |
|
381 | + $request['password'] = ! empty($request['password']) ? $request['password'] : ''; |
|
382 | 382 | |
383 | 383 | // Create customer. |
384 | 384 | $customer = new \WC_Customer(); |
385 | - $customer->set_username( $request['username'] ); |
|
386 | - $customer->set_password( $request['password'] ); |
|
387 | - $customer->set_email( $request['email'] ); |
|
388 | - $this->update_customer_meta_fields( $customer, $request ); |
|
385 | + $customer->set_username($request['username']); |
|
386 | + $customer->set_password($request['password']); |
|
387 | + $customer->set_email($request['email']); |
|
388 | + $this->update_customer_meta_fields($customer, $request); |
|
389 | 389 | $customer->save(); |
390 | 390 | |
391 | - if ( ! $customer->get_id() ) { |
|
392 | - throw new \WC_REST_Exception( 'woocommerce_rest_cannot_create', __( 'This resource cannot be created.', 'woocommerce' ), 400 ); |
|
391 | + if ( ! $customer->get_id()) { |
|
392 | + throw new \WC_REST_Exception('woocommerce_rest_cannot_create', __('This resource cannot be created.', 'woocommerce'), 400); |
|
393 | 393 | } |
394 | 394 | |
395 | - $user_data = get_userdata( $customer->get_id() ); |
|
396 | - $this->update_additional_fields_for_object( $user_data, $request ); |
|
395 | + $user_data = get_userdata($customer->get_id()); |
|
396 | + $this->update_additional_fields_for_object($user_data, $request); |
|
397 | 397 | |
398 | 398 | /** |
399 | 399 | * Fires after a customer is created or updated via the REST API. |
@@ -402,17 +402,17 @@ discard block |
||
402 | 402 | * @param \WP_REST_Request $request Request object. |
403 | 403 | * @param boolean $creating True when creating customer, false when updating customer. |
404 | 404 | */ |
405 | - do_action( 'woocommerce_rest_insert_customer', $user_data, $request, true ); |
|
405 | + do_action('woocommerce_rest_insert_customer', $user_data, $request, true); |
|
406 | 406 | |
407 | - $request->set_param( 'context', 'edit' ); |
|
408 | - $response = $this->prepare_item_for_response( $user_data, $request ); |
|
409 | - $response = rest_ensure_response( $response ); |
|
410 | - $response->set_status( 201 ); |
|
411 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $customer->get_id() ) ) ); |
|
407 | + $request->set_param('context', 'edit'); |
|
408 | + $response = $this->prepare_item_for_response($user_data, $request); |
|
409 | + $response = rest_ensure_response($response); |
|
410 | + $response->set_status(201); |
|
411 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $customer->get_id()))); |
|
412 | 412 | |
413 | 413 | return $response; |
414 | - } catch ( \Exception $e ) { |
|
415 | - return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
414 | + } catch (\Exception $e) { |
|
415 | + return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | |
@@ -422,16 +422,16 @@ discard block |
||
422 | 422 | * @param \WP_REST_Request $request Full details about the request. |
423 | 423 | * @return \WP_Error\WP_REST_Response |
424 | 424 | */ |
425 | - public function get_item( $request ) { |
|
425 | + public function get_item($request) { |
|
426 | 426 | $id = (int) $request['id']; |
427 | - $user_data = get_userdata( $id ); |
|
427 | + $user_data = get_userdata($id); |
|
428 | 428 | |
429 | - if ( empty( $id ) || empty( $user_data->ID ) ) { |
|
430 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
429 | + if (empty($id) || empty($user_data->ID)) { |
|
430 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
431 | 431 | } |
432 | 432 | |
433 | - $customer = $this->prepare_item_for_response( $user_data, $request ); |
|
434 | - $response = rest_ensure_response( $customer ); |
|
433 | + $customer = $this->prepare_item_for_response($user_data, $request); |
|
434 | + $response = rest_ensure_response($customer); |
|
435 | 435 | |
436 | 436 | return $response; |
437 | 437 | } |
@@ -444,41 +444,41 @@ discard block |
||
444 | 444 | * @param \WP_REST_Request $request Full details about the request. |
445 | 445 | * @return \WP_Error\WP_REST_Response |
446 | 446 | */ |
447 | - public function update_item( $request ) { |
|
447 | + public function update_item($request) { |
|
448 | 448 | try { |
449 | 449 | $id = (int) $request['id']; |
450 | - $customer = new \WC_Customer( $id ); |
|
450 | + $customer = new \WC_Customer($id); |
|
451 | 451 | |
452 | - if ( ! $customer->get_id() ) { |
|
453 | - throw new \WC_REST_Exception( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), 400 ); |
|
452 | + if ( ! $customer->get_id()) { |
|
453 | + throw new \WC_REST_Exception('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), 400); |
|
454 | 454 | } |
455 | 455 | |
456 | - if ( ! empty( $request['email'] ) && email_exists( $request['email'] ) && $request['email'] !== $customer->get_email() ) { |
|
457 | - throw new \WC_REST_Exception( 'woocommerce_rest_customer_invalid_email', __( 'Email address is invalid.', 'woocommerce' ), 400 ); |
|
456 | + if ( ! empty($request['email']) && email_exists($request['email']) && $request['email'] !== $customer->get_email()) { |
|
457 | + throw new \WC_REST_Exception('woocommerce_rest_customer_invalid_email', __('Email address is invalid.', 'woocommerce'), 400); |
|
458 | 458 | } |
459 | 459 | |
460 | - if ( ! empty( $request['username'] ) && $request['username'] !== $customer->get_username() ) { |
|
461 | - throw new \WC_REST_Exception( 'woocommerce_rest_customer_invalid_argument', __( "Username isn't editable.", 'woocommerce' ), 400 ); |
|
460 | + if ( ! empty($request['username']) && $request['username'] !== $customer->get_username()) { |
|
461 | + throw new \WC_REST_Exception('woocommerce_rest_customer_invalid_argument', __("Username isn't editable.", 'woocommerce'), 400); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | // Customer email. |
465 | - if ( isset( $request['email'] ) ) { |
|
466 | - $customer->set_email( sanitize_email( $request['email'] ) ); |
|
465 | + if (isset($request['email'])) { |
|
466 | + $customer->set_email(sanitize_email($request['email'])); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | // Customer password. |
470 | - if ( isset( $request['password'] ) ) { |
|
471 | - $customer->set_password( $request['password'] ); |
|
470 | + if (isset($request['password'])) { |
|
471 | + $customer->set_password($request['password']); |
|
472 | 472 | } |
473 | 473 | |
474 | - $this->update_customer_meta_fields( $customer, $request ); |
|
474 | + $this->update_customer_meta_fields($customer, $request); |
|
475 | 475 | $customer->save(); |
476 | 476 | |
477 | - $user_data = get_userdata( $customer->get_id() ); |
|
478 | - $this->update_additional_fields_for_object( $user_data, $request ); |
|
477 | + $user_data = get_userdata($customer->get_id()); |
|
478 | + $this->update_additional_fields_for_object($user_data, $request); |
|
479 | 479 | |
480 | - if ( ! is_user_member_of_blog( $user_data->ID ) ) { |
|
481 | - $user_data->add_role( 'customer' ); |
|
480 | + if ( ! is_user_member_of_blog($user_data->ID)) { |
|
481 | + $user_data->add_role('customer'); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | /** |
@@ -488,14 +488,14 @@ discard block |
||
488 | 488 | * @param \WP_REST_Request $request Request object. |
489 | 489 | * @param boolean $creating True when creating customer, false when updating customer. |
490 | 490 | */ |
491 | - do_action( 'woocommerce_rest_insert_customer', $user_data, $request, false ); |
|
491 | + do_action('woocommerce_rest_insert_customer', $user_data, $request, false); |
|
492 | 492 | |
493 | - $request->set_param( 'context', 'edit' ); |
|
494 | - $response = $this->prepare_item_for_response( $user_data, $request ); |
|
495 | - $response = rest_ensure_response( $response ); |
|
493 | + $request->set_param('context', 'edit'); |
|
494 | + $response = $this->prepare_item_for_response($user_data, $request); |
|
495 | + $response = rest_ensure_response($response); |
|
496 | 496 | return $response; |
497 | - } catch ( Exception $e ) { |
|
498 | - return new \WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
497 | + } catch (Exception $e) { |
|
498 | + return new \WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
499 | 499 | } |
500 | 500 | } |
501 | 501 | |
@@ -505,43 +505,43 @@ discard block |
||
505 | 505 | * @param \WP_REST_Request $request Full details about the request. |
506 | 506 | * @return \WP_Error\WP_REST_Response |
507 | 507 | */ |
508 | - public function delete_item( $request ) { |
|
508 | + public function delete_item($request) { |
|
509 | 509 | $id = (int) $request['id']; |
510 | - $reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null; |
|
511 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
510 | + $reassign = isset($request['reassign']) ? absint($request['reassign']) : null; |
|
511 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
512 | 512 | |
513 | 513 | // We don't support trashing for this type, error out. |
514 | - if ( ! $force ) { |
|
515 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Customers do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
514 | + if ( ! $force) { |
|
515 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Customers do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
516 | 516 | } |
517 | 517 | |
518 | - $user_data = get_userdata( $id ); |
|
519 | - if ( ! $user_data ) { |
|
520 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
518 | + $user_data = get_userdata($id); |
|
519 | + if ( ! $user_data) { |
|
520 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400)); |
|
521 | 521 | } |
522 | 522 | |
523 | - if ( ! empty( $reassign ) ) { |
|
524 | - if ( $reassign === $id || ! get_userdata( $reassign ) ) { |
|
525 | - return new \WP_Error( 'woocommerce_rest_customer_invalid_reassign', __( 'Invalid resource id for reassignment.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
523 | + if ( ! empty($reassign)) { |
|
524 | + if ($reassign === $id || ! get_userdata($reassign)) { |
|
525 | + return new \WP_Error('woocommerce_rest_customer_invalid_reassign', __('Invalid resource id for reassignment.', 'woocommerce'), array('status' => 400)); |
|
526 | 526 | } |
527 | 527 | } |
528 | 528 | |
529 | - $request->set_param( 'context', 'edit' ); |
|
530 | - $response = $this->prepare_item_for_response( $user_data, $request ); |
|
529 | + $request->set_param('context', 'edit'); |
|
530 | + $response = $this->prepare_item_for_response($user_data, $request); |
|
531 | 531 | |
532 | 532 | /** Include admin customer functions to get access to wp_delete_user() */ |
533 | 533 | require_once ABSPATH . 'wp-admin/includes/user.php'; |
534 | 534 | |
535 | - $customer = new \WC_Customer( $id ); |
|
535 | + $customer = new \WC_Customer($id); |
|
536 | 536 | |
537 | - if ( ! is_null( $reassign ) ) { |
|
538 | - $result = $customer->delete_and_reassign( $reassign ); |
|
537 | + if ( ! is_null($reassign)) { |
|
538 | + $result = $customer->delete_and_reassign($reassign); |
|
539 | 539 | } else { |
540 | 540 | $result = $customer->delete(); |
541 | 541 | } |
542 | 542 | |
543 | - if ( ! $result ) { |
|
544 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
543 | + if ( ! $result) { |
|
544 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | * @param \WP_REST_Response $response The response returned from the API. |
552 | 552 | * @param \WP_REST_Request $request The request sent to the API. |
553 | 553 | */ |
554 | - do_action( 'woocommerce_rest_delete_customer', $user_data, $response, $request ); |
|
554 | + do_action('woocommerce_rest_delete_customer', $user_data, $response, $request); |
|
555 | 555 | |
556 | 556 | return $response; |
557 | 557 | } |
@@ -563,14 +563,14 @@ discard block |
||
563 | 563 | * @param \WP_REST_Request $request Request object. |
564 | 564 | * @return \WP_REST_Response $response Response data. |
565 | 565 | */ |
566 | - public function prepare_item_for_response( $user_data, $request ) { |
|
567 | - $customer = new \WC_Customer( $user_data->ID ); |
|
568 | - $data = $this->get_formatted_item_data( $customer ); |
|
569 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
570 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
571 | - $data = $this->filter_response_by_context( $data, $context ); |
|
572 | - $response = rest_ensure_response( $data ); |
|
573 | - $response->add_links( $this->prepare_links( $user_data ) ); |
|
566 | + public function prepare_item_for_response($user_data, $request) { |
|
567 | + $customer = new \WC_Customer($user_data->ID); |
|
568 | + $data = $this->get_formatted_item_data($customer); |
|
569 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
570 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
571 | + $data = $this->filter_response_by_context($data, $context); |
|
572 | + $response = rest_ensure_response($data); |
|
573 | + $response->add_links($this->prepare_links($user_data)); |
|
574 | 574 | |
575 | 575 | /** |
576 | 576 | * Filter customer data returned from the REST API. |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * @param WP_User $user_data User object used to create response. |
580 | 580 | * @param \WP_REST_Request $request Request object. |
581 | 581 | */ |
582 | - return apply_filters( 'woocommerce_rest_prepare_customer', $response, $user_data, $request ); |
|
582 | + return apply_filters('woocommerce_rest_prepare_customer', $response, $user_data, $request); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | /** |
@@ -588,42 +588,42 @@ discard block |
||
588 | 588 | * @param WC_Customer $customer Customer being updated. |
589 | 589 | * @param \WP_REST_Request $request Request params. |
590 | 590 | */ |
591 | - protected function update_customer_meta_fields( $customer, $request ) { |
|
591 | + protected function update_customer_meta_fields($customer, $request) { |
|
592 | 592 | $schema = $this->get_item_schema(); |
593 | 593 | |
594 | 594 | // Customer first name. |
595 | - if ( isset( $request['first_name'] ) ) { |
|
596 | - $customer->set_first_name( wc_clean( $request['first_name'] ) ); |
|
595 | + if (isset($request['first_name'])) { |
|
596 | + $customer->set_first_name(wc_clean($request['first_name'])); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | // Customer last name. |
600 | - if ( isset( $request['last_name'] ) ) { |
|
601 | - $customer->set_last_name( wc_clean( $request['last_name'] ) ); |
|
600 | + if (isset($request['last_name'])) { |
|
601 | + $customer->set_last_name(wc_clean($request['last_name'])); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | // Customer billing address. |
605 | - if ( isset( $request['billing'] ) ) { |
|
606 | - foreach ( array_keys( $schema['properties']['billing']['properties'] ) as $field ) { |
|
607 | - if ( isset( $request['billing'][ $field ] ) && is_callable( array( $customer, "set_billing_{$field}" ) ) ) { |
|
608 | - $customer->{"set_billing_{$field}"}( $request['billing'][ $field ] ); |
|
605 | + if (isset($request['billing'])) { |
|
606 | + foreach (array_keys($schema['properties']['billing']['properties']) as $field) { |
|
607 | + if (isset($request['billing'][$field]) && is_callable(array($customer, "set_billing_{$field}"))) { |
|
608 | + $customer->{"set_billing_{$field}"}($request['billing'][$field]); |
|
609 | 609 | } |
610 | 610 | } |
611 | 611 | } |
612 | 612 | |
613 | 613 | // Customer shipping address. |
614 | - if ( isset( $request['shipping'] ) ) { |
|
615 | - foreach ( array_keys( $schema['properties']['shipping']['properties'] ) as $field ) { |
|
616 | - if ( isset( $request['shipping'][ $field ] ) && is_callable( array( $customer, "set_shipping_{$field}" ) ) ) { |
|
617 | - $customer->{"set_shipping_{$field}"}( $request['shipping'][ $field ] ); |
|
614 | + if (isset($request['shipping'])) { |
|
615 | + foreach (array_keys($schema['properties']['shipping']['properties']) as $field) { |
|
616 | + if (isset($request['shipping'][$field]) && is_callable(array($customer, "set_shipping_{$field}"))) { |
|
617 | + $customer->{"set_shipping_{$field}"}($request['shipping'][$field]); |
|
618 | 618 | } |
619 | 619 | } |
620 | 620 | } |
621 | 621 | |
622 | 622 | // Meta data. |
623 | - if ( isset( $request['meta_data'] ) ) { |
|
624 | - if ( is_array( $request['meta_data'] ) ) { |
|
625 | - foreach ( $request['meta_data'] as $meta ) { |
|
626 | - $customer->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
623 | + if (isset($request['meta_data'])) { |
|
624 | + if (is_array($request['meta_data'])) { |
|
625 | + foreach ($request['meta_data'] as $meta) { |
|
626 | + $customer->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
627 | 627 | } |
628 | 628 | } |
629 | 629 | } |
@@ -635,13 +635,13 @@ discard block |
||
635 | 635 | * @param WP_User $customer Customer object. |
636 | 636 | * @return array Links for the given customer. |
637 | 637 | */ |
638 | - protected function prepare_links( $customer ) { |
|
638 | + protected function prepare_links($customer) { |
|
639 | 639 | $links = array( |
640 | 640 | 'self' => array( |
641 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $customer->ID ) ), |
|
641 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $customer->ID)), |
|
642 | 642 | ), |
643 | 643 | 'collection' => array( |
644 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
644 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
645 | 645 | ), |
646 | 646 | ); |
647 | 647 | |
@@ -660,225 +660,225 @@ discard block |
||
660 | 660 | 'type' => 'object', |
661 | 661 | 'properties' => array( |
662 | 662 | 'id' => array( |
663 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
663 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
664 | 664 | 'type' => 'integer', |
665 | - 'context' => array( 'view', 'edit' ), |
|
665 | + 'context' => array('view', 'edit'), |
|
666 | 666 | 'readonly' => true, |
667 | 667 | ), |
668 | 668 | 'date_created' => array( |
669 | - 'description' => __( "The date the customer was created, in the site's timezone.", 'woocommerce' ), |
|
669 | + 'description' => __("The date the customer was created, in the site's timezone.", 'woocommerce'), |
|
670 | 670 | 'type' => 'date-time', |
671 | - 'context' => array( 'view', 'edit' ), |
|
671 | + 'context' => array('view', 'edit'), |
|
672 | 672 | 'readonly' => true, |
673 | 673 | ), |
674 | 674 | 'date_created_gmt' => array( |
675 | - 'description' => __( 'The date the customer was created, as GMT.', 'woocommerce' ), |
|
675 | + 'description' => __('The date the customer was created, as GMT.', 'woocommerce'), |
|
676 | 676 | 'type' => 'date-time', |
677 | - 'context' => array( 'view', 'edit' ), |
|
677 | + 'context' => array('view', 'edit'), |
|
678 | 678 | 'readonly' => true, |
679 | 679 | ), |
680 | 680 | 'date_modified' => array( |
681 | - 'description' => __( "The date the customer was last modified, in the site's timezone.", 'woocommerce' ), |
|
681 | + 'description' => __("The date the customer was last modified, in the site's timezone.", 'woocommerce'), |
|
682 | 682 | 'type' => 'date-time', |
683 | - 'context' => array( 'view', 'edit' ), |
|
683 | + 'context' => array('view', 'edit'), |
|
684 | 684 | 'readonly' => true, |
685 | 685 | ), |
686 | 686 | 'date_modified_gmt' => array( |
687 | - 'description' => __( 'The date the customer was last modified, as GMT.', 'woocommerce' ), |
|
687 | + 'description' => __('The date the customer was last modified, as GMT.', 'woocommerce'), |
|
688 | 688 | 'type' => 'date-time', |
689 | - 'context' => array( 'view', 'edit' ), |
|
689 | + 'context' => array('view', 'edit'), |
|
690 | 690 | 'readonly' => true, |
691 | 691 | ), |
692 | 692 | 'email' => array( |
693 | - 'description' => __( 'The email address for the customer.', 'woocommerce' ), |
|
693 | + 'description' => __('The email address for the customer.', 'woocommerce'), |
|
694 | 694 | 'type' => 'string', |
695 | 695 | 'format' => 'email', |
696 | - 'context' => array( 'view', 'edit' ), |
|
696 | + 'context' => array('view', 'edit'), |
|
697 | 697 | ), |
698 | 698 | 'first_name' => array( |
699 | - 'description' => __( 'Customer first name.', 'woocommerce' ), |
|
699 | + 'description' => __('Customer first name.', 'woocommerce'), |
|
700 | 700 | 'type' => 'string', |
701 | - 'context' => array( 'view', 'edit' ), |
|
701 | + 'context' => array('view', 'edit'), |
|
702 | 702 | 'arg_options' => array( |
703 | 703 | 'sanitize_callback' => 'sanitize_text_field', |
704 | 704 | ), |
705 | 705 | ), |
706 | 706 | 'last_name' => array( |
707 | - 'description' => __( 'Customer last name.', 'woocommerce' ), |
|
707 | + 'description' => __('Customer last name.', 'woocommerce'), |
|
708 | 708 | 'type' => 'string', |
709 | - 'context' => array( 'view', 'edit' ), |
|
709 | + 'context' => array('view', 'edit'), |
|
710 | 710 | 'arg_options' => array( |
711 | 711 | 'sanitize_callback' => 'sanitize_text_field', |
712 | 712 | ), |
713 | 713 | ), |
714 | 714 | 'role' => array( |
715 | - 'description' => __( 'Customer role.', 'woocommerce' ), |
|
715 | + 'description' => __('Customer role.', 'woocommerce'), |
|
716 | 716 | 'type' => 'string', |
717 | - 'context' => array( 'view', 'edit' ), |
|
717 | + 'context' => array('view', 'edit'), |
|
718 | 718 | 'readonly' => true, |
719 | 719 | ), |
720 | 720 | 'username' => array( |
721 | - 'description' => __( 'Customer login name.', 'woocommerce' ), |
|
721 | + 'description' => __('Customer login name.', 'woocommerce'), |
|
722 | 722 | 'type' => 'string', |
723 | - 'context' => array( 'view', 'edit' ), |
|
723 | + 'context' => array('view', 'edit'), |
|
724 | 724 | 'arg_options' => array( |
725 | 725 | 'sanitize_callback' => 'sanitize_user', |
726 | 726 | ), |
727 | 727 | ), |
728 | 728 | 'password' => array( |
729 | - 'description' => __( 'Customer password.', 'woocommerce' ), |
|
729 | + 'description' => __('Customer password.', 'woocommerce'), |
|
730 | 730 | 'type' => 'string', |
731 | - 'context' => array( 'edit' ), |
|
731 | + 'context' => array('edit'), |
|
732 | 732 | ), |
733 | 733 | 'billing' => array( |
734 | - 'description' => __( 'List of billing address data.', 'woocommerce' ), |
|
734 | + 'description' => __('List of billing address data.', 'woocommerce'), |
|
735 | 735 | 'type' => 'object', |
736 | - 'context' => array( 'view', 'edit' ), |
|
736 | + 'context' => array('view', 'edit'), |
|
737 | 737 | 'properties' => array( |
738 | 738 | 'first_name' => array( |
739 | - 'description' => __( 'First name.', 'woocommerce' ), |
|
739 | + 'description' => __('First name.', 'woocommerce'), |
|
740 | 740 | 'type' => 'string', |
741 | - 'context' => array( 'view', 'edit' ), |
|
741 | + 'context' => array('view', 'edit'), |
|
742 | 742 | ), |
743 | 743 | 'last_name' => array( |
744 | - 'description' => __( 'Last name.', 'woocommerce' ), |
|
744 | + 'description' => __('Last name.', 'woocommerce'), |
|
745 | 745 | 'type' => 'string', |
746 | - 'context' => array( 'view', 'edit' ), |
|
746 | + 'context' => array('view', 'edit'), |
|
747 | 747 | ), |
748 | 748 | 'company' => array( |
749 | - 'description' => __( 'Company name.', 'woocommerce' ), |
|
749 | + 'description' => __('Company name.', 'woocommerce'), |
|
750 | 750 | 'type' => 'string', |
751 | - 'context' => array( 'view', 'edit' ), |
|
751 | + 'context' => array('view', 'edit'), |
|
752 | 752 | ), |
753 | 753 | 'address_1' => array( |
754 | - 'description' => __( 'Address line 1', 'woocommerce' ), |
|
754 | + 'description' => __('Address line 1', 'woocommerce'), |
|
755 | 755 | 'type' => 'string', |
756 | - 'context' => array( 'view', 'edit' ), |
|
756 | + 'context' => array('view', 'edit'), |
|
757 | 757 | ), |
758 | 758 | 'address_2' => array( |
759 | - 'description' => __( 'Address line 2', 'woocommerce' ), |
|
759 | + 'description' => __('Address line 2', 'woocommerce'), |
|
760 | 760 | 'type' => 'string', |
761 | - 'context' => array( 'view', 'edit' ), |
|
761 | + 'context' => array('view', 'edit'), |
|
762 | 762 | ), |
763 | 763 | 'city' => array( |
764 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
764 | + 'description' => __('City name.', 'woocommerce'), |
|
765 | 765 | 'type' => 'string', |
766 | - 'context' => array( 'view', 'edit' ), |
|
766 | + 'context' => array('view', 'edit'), |
|
767 | 767 | ), |
768 | 768 | 'state' => array( |
769 | - 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
|
769 | + 'description' => __('ISO code or name of the state, province or district.', 'woocommerce'), |
|
770 | 770 | 'type' => 'string', |
771 | - 'context' => array( 'view', 'edit' ), |
|
771 | + 'context' => array('view', 'edit'), |
|
772 | 772 | ), |
773 | 773 | 'postcode' => array( |
774 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
774 | + 'description' => __('Postal code.', 'woocommerce'), |
|
775 | 775 | 'type' => 'string', |
776 | - 'context' => array( 'view', 'edit' ), |
|
776 | + 'context' => array('view', 'edit'), |
|
777 | 777 | ), |
778 | 778 | 'country' => array( |
779 | - 'description' => __( 'ISO code of the country.', 'woocommerce' ), |
|
779 | + 'description' => __('ISO code of the country.', 'woocommerce'), |
|
780 | 780 | 'type' => 'string', |
781 | - 'context' => array( 'view', 'edit' ), |
|
781 | + 'context' => array('view', 'edit'), |
|
782 | 782 | ), |
783 | 783 | 'email' => array( |
784 | - 'description' => __( 'Email address.', 'woocommerce' ), |
|
784 | + 'description' => __('Email address.', 'woocommerce'), |
|
785 | 785 | 'type' => 'string', |
786 | 786 | 'format' => 'email', |
787 | - 'context' => array( 'view', 'edit' ), |
|
787 | + 'context' => array('view', 'edit'), |
|
788 | 788 | ), |
789 | 789 | 'phone' => array( |
790 | - 'description' => __( 'Phone number.', 'woocommerce' ), |
|
790 | + 'description' => __('Phone number.', 'woocommerce'), |
|
791 | 791 | 'type' => 'string', |
792 | - 'context' => array( 'view', 'edit' ), |
|
792 | + 'context' => array('view', 'edit'), |
|
793 | 793 | ), |
794 | 794 | ), |
795 | 795 | ), |
796 | 796 | 'shipping' => array( |
797 | - 'description' => __( 'List of shipping address data.', 'woocommerce' ), |
|
797 | + 'description' => __('List of shipping address data.', 'woocommerce'), |
|
798 | 798 | 'type' => 'object', |
799 | - 'context' => array( 'view', 'edit' ), |
|
799 | + 'context' => array('view', 'edit'), |
|
800 | 800 | 'properties' => array( |
801 | 801 | 'first_name' => array( |
802 | - 'description' => __( 'First name.', 'woocommerce' ), |
|
802 | + 'description' => __('First name.', 'woocommerce'), |
|
803 | 803 | 'type' => 'string', |
804 | - 'context' => array( 'view', 'edit' ), |
|
804 | + 'context' => array('view', 'edit'), |
|
805 | 805 | ), |
806 | 806 | 'last_name' => array( |
807 | - 'description' => __( 'Last name.', 'woocommerce' ), |
|
807 | + 'description' => __('Last name.', 'woocommerce'), |
|
808 | 808 | 'type' => 'string', |
809 | - 'context' => array( 'view', 'edit' ), |
|
809 | + 'context' => array('view', 'edit'), |
|
810 | 810 | ), |
811 | 811 | 'company' => array( |
812 | - 'description' => __( 'Company name.', 'woocommerce' ), |
|
812 | + 'description' => __('Company name.', 'woocommerce'), |
|
813 | 813 | 'type' => 'string', |
814 | - 'context' => array( 'view', 'edit' ), |
|
814 | + 'context' => array('view', 'edit'), |
|
815 | 815 | ), |
816 | 816 | 'address_1' => array( |
817 | - 'description' => __( 'Address line 1', 'woocommerce' ), |
|
817 | + 'description' => __('Address line 1', 'woocommerce'), |
|
818 | 818 | 'type' => 'string', |
819 | - 'context' => array( 'view', 'edit' ), |
|
819 | + 'context' => array('view', 'edit'), |
|
820 | 820 | ), |
821 | 821 | 'address_2' => array( |
822 | - 'description' => __( 'Address line 2', 'woocommerce' ), |
|
822 | + 'description' => __('Address line 2', 'woocommerce'), |
|
823 | 823 | 'type' => 'string', |
824 | - 'context' => array( 'view', 'edit' ), |
|
824 | + 'context' => array('view', 'edit'), |
|
825 | 825 | ), |
826 | 826 | 'city' => array( |
827 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
827 | + 'description' => __('City name.', 'woocommerce'), |
|
828 | 828 | 'type' => 'string', |
829 | - 'context' => array( 'view', 'edit' ), |
|
829 | + 'context' => array('view', 'edit'), |
|
830 | 830 | ), |
831 | 831 | 'state' => array( |
832 | - 'description' => __( 'ISO code or name of the state, province or district.', 'woocommerce' ), |
|
832 | + 'description' => __('ISO code or name of the state, province or district.', 'woocommerce'), |
|
833 | 833 | 'type' => 'string', |
834 | - 'context' => array( 'view', 'edit' ), |
|
834 | + 'context' => array('view', 'edit'), |
|
835 | 835 | ), |
836 | 836 | 'postcode' => array( |
837 | - 'description' => __( 'Postal code.', 'woocommerce' ), |
|
837 | + 'description' => __('Postal code.', 'woocommerce'), |
|
838 | 838 | 'type' => 'string', |
839 | - 'context' => array( 'view', 'edit' ), |
|
839 | + 'context' => array('view', 'edit'), |
|
840 | 840 | ), |
841 | 841 | 'country' => array( |
842 | - 'description' => __( 'ISO code of the country.', 'woocommerce' ), |
|
842 | + 'description' => __('ISO code of the country.', 'woocommerce'), |
|
843 | 843 | 'type' => 'string', |
844 | - 'context' => array( 'view', 'edit' ), |
|
844 | + 'context' => array('view', 'edit'), |
|
845 | 845 | ), |
846 | 846 | ), |
847 | 847 | ), |
848 | 848 | 'is_paying_customer' => array( |
849 | - 'description' => __( 'Is the customer a paying customer?', 'woocommerce' ), |
|
849 | + 'description' => __('Is the customer a paying customer?', 'woocommerce'), |
|
850 | 850 | 'type' => 'bool', |
851 | - 'context' => array( 'view', 'edit' ), |
|
851 | + 'context' => array('view', 'edit'), |
|
852 | 852 | 'readonly' => true, |
853 | 853 | ), |
854 | 854 | 'avatar_url' => array( |
855 | - 'description' => __( 'Avatar URL.', 'woocommerce' ), |
|
855 | + 'description' => __('Avatar URL.', 'woocommerce'), |
|
856 | 856 | 'type' => 'string', |
857 | - 'context' => array( 'view', 'edit' ), |
|
857 | + 'context' => array('view', 'edit'), |
|
858 | 858 | 'readonly' => true, |
859 | 859 | ), |
860 | 860 | 'meta_data' => array( |
861 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
861 | + 'description' => __('Meta data.', 'woocommerce'), |
|
862 | 862 | 'type' => 'array', |
863 | - 'context' => array( 'view', 'edit' ), |
|
863 | + 'context' => array('view', 'edit'), |
|
864 | 864 | 'items' => array( |
865 | 865 | 'type' => 'object', |
866 | 866 | 'properties' => array( |
867 | 867 | 'id' => array( |
868 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
868 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
869 | 869 | 'type' => 'integer', |
870 | - 'context' => array( 'view', 'edit' ), |
|
870 | + 'context' => array('view', 'edit'), |
|
871 | 871 | 'readonly' => true, |
872 | 872 | ), |
873 | 873 | 'key' => array( |
874 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
874 | + 'description' => __('Meta key.', 'woocommerce'), |
|
875 | 875 | 'type' => 'string', |
876 | - 'context' => array( 'view', 'edit' ), |
|
876 | + 'context' => array('view', 'edit'), |
|
877 | 877 | ), |
878 | 878 | 'value' => array( |
879 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
879 | + 'description' => __('Meta value.', 'woocommerce'), |
|
880 | 880 | 'type' => 'mixed', |
881 | - 'context' => array( 'view', 'edit' ), |
|
881 | + 'context' => array('view', 'edit'), |
|
882 | 882 | ), |
883 | 883 | ), |
884 | 884 | ), |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | ), |
887 | 887 | ); |
888 | 888 | |
889 | - return $this->add_additional_fields_schema( $schema ); |
|
889 | + return $this->add_additional_fields_schema($schema); |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | protected function get_role_names() { |
898 | 898 | global $wp_roles; |
899 | 899 | |
900 | - return array_keys( $wp_roles->role_names ); |
|
900 | + return array_keys($wp_roles->role_names); |
|
901 | 901 | } |
902 | 902 | |
903 | 903 | /** |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | $params['context']['default'] = 'view'; |
912 | 912 | |
913 | 913 | $params['exclude'] = array( |
914 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
914 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
915 | 915 | 'type' => 'array', |
916 | 916 | 'items' => array( |
917 | 917 | 'type' => 'integer', |
@@ -920,7 +920,7 @@ discard block |
||
920 | 920 | 'sanitize_callback' => 'wp_parse_id_list', |
921 | 921 | ); |
922 | 922 | $params['include'] = array( |
923 | - 'description' => __( 'Limit result set to specific IDs.', 'woocommerce' ), |
|
923 | + 'description' => __('Limit result set to specific IDs.', 'woocommerce'), |
|
924 | 924 | 'type' => 'array', |
925 | 925 | 'items' => array( |
926 | 926 | 'type' => 'integer', |
@@ -929,22 +929,22 @@ discard block |
||
929 | 929 | 'sanitize_callback' => 'wp_parse_id_list', |
930 | 930 | ); |
931 | 931 | $params['offset'] = array( |
932 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
932 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
933 | 933 | 'type' => 'integer', |
934 | 934 | 'sanitize_callback' => 'absint', |
935 | 935 | 'validate_callback' => 'rest_validate_request_arg', |
936 | 936 | ); |
937 | 937 | $params['order'] = array( |
938 | 938 | 'default' => 'asc', |
939 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
940 | - 'enum' => array( 'asc', 'desc' ), |
|
939 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
940 | + 'enum' => array('asc', 'desc'), |
|
941 | 941 | 'sanitize_callback' => 'sanitize_key', |
942 | 942 | 'type' => 'string', |
943 | 943 | 'validate_callback' => 'rest_validate_request_arg', |
944 | 944 | ); |
945 | 945 | $params['orderby'] = array( |
946 | 946 | 'default' => 'name', |
947 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
947 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
948 | 948 | 'enum' => array( |
949 | 949 | 'id', |
950 | 950 | 'include', |
@@ -956,16 +956,16 @@ discard block |
||
956 | 956 | 'validate_callback' => 'rest_validate_request_arg', |
957 | 957 | ); |
958 | 958 | $params['email'] = array( |
959 | - 'description' => __( 'Limit result set to resources with a specific email.', 'woocommerce' ), |
|
959 | + 'description' => __('Limit result set to resources with a specific email.', 'woocommerce'), |
|
960 | 960 | 'type' => 'string', |
961 | 961 | 'format' => 'email', |
962 | 962 | 'validate_callback' => 'rest_validate_request_arg', |
963 | 963 | ); |
964 | 964 | $params['role'] = array( |
965 | - 'description' => __( 'Limit result set to resources with a specific role.', 'woocommerce' ), |
|
965 | + 'description' => __('Limit result set to resources with a specific role.', 'woocommerce'), |
|
966 | 966 | 'type' => 'string', |
967 | 967 | 'default' => 'customer', |
968 | - 'enum' => array_merge( array( 'all' ), $this->get_role_names() ), |
|
968 | + 'enum' => array_merge(array('all'), $this->get_role_names()), |
|
969 | 969 | 'validate_callback' => 'rest_validate_request_arg', |
970 | 970 | ); |
971 | 971 | return $params; |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Product Shipping Classes controller class. |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param \WP_REST_Request $request Request params. |
38 | 38 | * @return \WP_REST_Response $response |
39 | 39 | */ |
40 | - public function prepare_item_for_response( $item, $request ) { |
|
40 | + public function prepare_item_for_response($item, $request) { |
|
41 | 41 | $data = array( |
42 | 42 | 'id' => (int) $item->term_id, |
43 | 43 | 'name' => $item->name, |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | 'count' => (int) $item->count, |
47 | 47 | ); |
48 | 48 | |
49 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
50 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
51 | - $data = $this->filter_response_by_context( $data, $context ); |
|
49 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
50 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
51 | + $data = $this->filter_response_by_context($data, $context); |
|
52 | 52 | |
53 | - $response = rest_ensure_response( $data ); |
|
53 | + $response = rest_ensure_response($data); |
|
54 | 54 | |
55 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
55 | + $response->add_links($this->prepare_links($item, $request)); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Filter a term item returned from the API. |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @param object $item The original term object. |
64 | 64 | * @param \WP_REST_Request $request Request used to generate the response. |
65 | 65 | */ |
66 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
66 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -78,44 +78,44 @@ discard block |
||
78 | 78 | 'type' => 'object', |
79 | 79 | 'properties' => array( |
80 | 80 | 'id' => array( |
81 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
81 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
82 | 82 | 'type' => 'integer', |
83 | - 'context' => array( 'view', 'edit' ), |
|
83 | + 'context' => array('view', 'edit'), |
|
84 | 84 | 'readonly' => true, |
85 | 85 | ), |
86 | 86 | 'name' => array( |
87 | - 'description' => __( 'Shipping class name.', 'woocommerce' ), |
|
87 | + 'description' => __('Shipping class name.', 'woocommerce'), |
|
88 | 88 | 'type' => 'string', |
89 | - 'context' => array( 'view', 'edit' ), |
|
89 | + 'context' => array('view', 'edit'), |
|
90 | 90 | 'arg_options' => array( |
91 | 91 | 'sanitize_callback' => 'sanitize_text_field', |
92 | 92 | ), |
93 | 93 | ), |
94 | 94 | 'slug' => array( |
95 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
95 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
96 | 96 | 'type' => 'string', |
97 | - 'context' => array( 'view', 'edit' ), |
|
97 | + 'context' => array('view', 'edit'), |
|
98 | 98 | 'arg_options' => array( |
99 | 99 | 'sanitize_callback' => 'sanitize_title', |
100 | 100 | ), |
101 | 101 | ), |
102 | 102 | 'description' => array( |
103 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
103 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
104 | 104 | 'type' => 'string', |
105 | - 'context' => array( 'view', 'edit' ), |
|
105 | + 'context' => array('view', 'edit'), |
|
106 | 106 | 'arg_options' => array( |
107 | 107 | 'sanitize_callback' => 'wp_filter_post_kses', |
108 | 108 | ), |
109 | 109 | ), |
110 | 110 | 'count' => array( |
111 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
111 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
112 | 112 | 'type' => 'integer', |
113 | - 'context' => array( 'view', 'edit' ), |
|
113 | + 'context' => array('view', 'edit'), |
|
114 | 114 | 'readonly' => true, |
115 | 115 | ), |
116 | 116 | ), |
117 | 117 | ); |
118 | 118 | |
119 | - return $this->add_additional_fields_schema( $schema ); |
|
119 | + return $this->add_additional_fields_schema($schema); |
|
120 | 120 | } |
121 | 121 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Product Categories controller class. |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | * @param \WP_REST_Request $request Request instance. |
38 | 38 | * @return \WP_REST_Response |
39 | 39 | */ |
40 | - public function prepare_item_for_response( $item, $request ) { |
|
40 | + public function prepare_item_for_response($item, $request) { |
|
41 | 41 | // Get category display type. |
42 | - $display_type = get_term_meta( $item->term_id, 'display_type', true ); |
|
42 | + $display_type = get_term_meta($item->term_id, 'display_type', true); |
|
43 | 43 | |
44 | 44 | // Get category order. |
45 | - $menu_order = get_term_meta( $item->term_id, 'order', true ); |
|
45 | + $menu_order = get_term_meta($item->term_id, 'order', true); |
|
46 | 46 | |
47 | 47 | $data = array( |
48 | 48 | 'id' => (int) $item->term_id, |
@@ -57,29 +57,29 @@ discard block |
||
57 | 57 | ); |
58 | 58 | |
59 | 59 | // Get category image. |
60 | - $image_id = get_term_meta( $item->term_id, 'thumbnail_id', true ); |
|
61 | - if ( $image_id ) { |
|
62 | - $attachment = get_post( $image_id ); |
|
60 | + $image_id = get_term_meta($item->term_id, 'thumbnail_id', true); |
|
61 | + if ($image_id) { |
|
62 | + $attachment = get_post($image_id); |
|
63 | 63 | |
64 | 64 | $data['image'] = array( |
65 | 65 | 'id' => (int) $image_id, |
66 | - 'date_created' => wc_rest_prepare_date_response( $attachment->post_date ), |
|
67 | - 'date_created_gmt' => wc_rest_prepare_date_response( $attachment->post_date_gmt ), |
|
68 | - 'date_modified' => wc_rest_prepare_date_response( $attachment->post_modified ), |
|
69 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $attachment->post_modified_gmt ), |
|
70 | - 'src' => wp_get_attachment_url( $image_id ), |
|
71 | - 'name' => get_the_title( $attachment ), |
|
72 | - 'alt' => get_post_meta( $image_id, '_wp_attachment_image_alt', true ), |
|
66 | + 'date_created' => wc_rest_prepare_date_response($attachment->post_date), |
|
67 | + 'date_created_gmt' => wc_rest_prepare_date_response($attachment->post_date_gmt), |
|
68 | + 'date_modified' => wc_rest_prepare_date_response($attachment->post_modified), |
|
69 | + 'date_modified_gmt' => wc_rest_prepare_date_response($attachment->post_modified_gmt), |
|
70 | + 'src' => wp_get_attachment_url($image_id), |
|
71 | + 'name' => get_the_title($attachment), |
|
72 | + 'alt' => get_post_meta($image_id, '_wp_attachment_image_alt', true), |
|
73 | 73 | ); |
74 | 74 | } |
75 | 75 | |
76 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
77 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
78 | - $data = $this->filter_response_by_context( $data, $context ); |
|
76 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
77 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
78 | + $data = $this->filter_response_by_context($data, $context); |
|
79 | 79 | |
80 | - $response = rest_ensure_response( $data ); |
|
80 | + $response = rest_ensure_response($data); |
|
81 | 81 | |
82 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
82 | + $response->add_links($this->prepare_links($item, $request)); |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Filter a term item returned from the API. |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param object $item The original term object. |
91 | 91 | * @param \WP_REST_Request $request Request used to generate the response. |
92 | 92 | */ |
93 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
93 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -102,50 +102,50 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @since 3.5.5 |
104 | 104 | */ |
105 | - protected function update_term_meta_fields( $term, $request ) { |
|
105 | + protected function update_term_meta_fields($term, $request) { |
|
106 | 106 | $id = (int) $term->term_id; |
107 | 107 | |
108 | - if ( isset( $request['display'] ) ) { |
|
109 | - update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] ); |
|
108 | + if (isset($request['display'])) { |
|
109 | + update_term_meta($id, 'display_type', 'default' === $request['display'] ? '' : $request['display']); |
|
110 | 110 | } |
111 | 111 | |
112 | - if ( isset( $request['menu_order'] ) ) { |
|
113 | - update_term_meta( $id, 'order', $request['menu_order'] ); |
|
112 | + if (isset($request['menu_order'])) { |
|
113 | + update_term_meta($id, 'order', $request['menu_order']); |
|
114 | 114 | } |
115 | 115 | |
116 | - if ( isset( $request['image'] ) ) { |
|
117 | - if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) { |
|
118 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) ); |
|
116 | + if (isset($request['image'])) { |
|
117 | + if (empty($request['image']['id']) && ! empty($request['image']['src'])) { |
|
118 | + $upload = wc_rest_upload_image_from_url(esc_url_raw($request['image']['src'])); |
|
119 | 119 | |
120 | - if ( is_wp_error( $upload ) ) { |
|
120 | + if (is_wp_error($upload)) { |
|
121 | 121 | return $upload; |
122 | 122 | } |
123 | 123 | |
124 | - $image_id = wc_rest_set_uploaded_image_as_attachment( $upload ); |
|
124 | + $image_id = wc_rest_set_uploaded_image_as_attachment($upload); |
|
125 | 125 | } else { |
126 | - $image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0; |
|
126 | + $image_id = isset($request['image']['id']) ? absint($request['image']['id']) : 0; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | // Check if image_id is a valid image attachment before updating the term meta. |
130 | - if ( $image_id && wp_attachment_is_image( $image_id ) ) { |
|
131 | - update_term_meta( $id, 'thumbnail_id', $image_id ); |
|
130 | + if ($image_id && wp_attachment_is_image($image_id)) { |
|
131 | + update_term_meta($id, 'thumbnail_id', $image_id); |
|
132 | 132 | |
133 | 133 | // Set the image alt. |
134 | - if ( ! empty( $request['image']['alt'] ) ) { |
|
135 | - update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) ); |
|
134 | + if ( ! empty($request['image']['alt'])) { |
|
135 | + update_post_meta($image_id, '_wp_attachment_image_alt', wc_clean($request['image']['alt'])); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | // Set the image title. |
139 | - if ( ! empty( $request['image']['name'] ) ) { |
|
139 | + if ( ! empty($request['image']['name'])) { |
|
140 | 140 | wp_update_post( |
141 | 141 | array( |
142 | 142 | 'ID' => $image_id, |
143 | - 'post_title' => wc_clean( $request['image']['name'] ), |
|
143 | + 'post_title' => wc_clean($request['image']['name']), |
|
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | } |
147 | 147 | } else { |
148 | - delete_term_meta( $id, 'thumbnail_id' ); |
|
148 | + delete_term_meta($id, 'thumbnail_id'); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -164,113 +164,113 @@ discard block |
||
164 | 164 | 'type' => 'object', |
165 | 165 | 'properties' => array( |
166 | 166 | 'id' => array( |
167 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
167 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
168 | 168 | 'type' => 'integer', |
169 | - 'context' => array( 'view', 'edit' ), |
|
169 | + 'context' => array('view', 'edit'), |
|
170 | 170 | 'readonly' => true, |
171 | 171 | ), |
172 | 172 | 'name' => array( |
173 | - 'description' => __( 'Category name.', 'woocommerce' ), |
|
173 | + 'description' => __('Category name.', 'woocommerce'), |
|
174 | 174 | 'type' => 'string', |
175 | - 'context' => array( 'view', 'edit' ), |
|
175 | + 'context' => array('view', 'edit'), |
|
176 | 176 | 'arg_options' => array( |
177 | 177 | 'sanitize_callback' => 'sanitize_text_field', |
178 | 178 | ), |
179 | 179 | ), |
180 | 180 | 'slug' => array( |
181 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
181 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
182 | 182 | 'type' => 'string', |
183 | - 'context' => array( 'view', 'edit' ), |
|
183 | + 'context' => array('view', 'edit'), |
|
184 | 184 | 'arg_options' => array( |
185 | 185 | 'sanitize_callback' => 'sanitize_title', |
186 | 186 | ), |
187 | 187 | ), |
188 | 188 | 'parent' => array( |
189 | - 'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ), |
|
189 | + 'description' => __('The ID for the parent of the resource.', 'woocommerce'), |
|
190 | 190 | 'type' => 'integer', |
191 | - 'context' => array( 'view', 'edit' ), |
|
191 | + 'context' => array('view', 'edit'), |
|
192 | 192 | ), |
193 | 193 | 'description' => array( |
194 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
194 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
195 | 195 | 'type' => 'string', |
196 | - 'context' => array( 'view', 'edit' ), |
|
196 | + 'context' => array('view', 'edit'), |
|
197 | 197 | 'arg_options' => array( |
198 | 198 | 'sanitize_callback' => 'wp_filter_post_kses', |
199 | 199 | ), |
200 | 200 | ), |
201 | 201 | 'display' => array( |
202 | - 'description' => __( 'Category archive display type.', 'woocommerce' ), |
|
202 | + 'description' => __('Category archive display type.', 'woocommerce'), |
|
203 | 203 | 'type' => 'string', |
204 | 204 | 'default' => 'default', |
205 | - 'enum' => array( 'default', 'products', 'subcategories', 'both' ), |
|
206 | - 'context' => array( 'view', 'edit' ), |
|
205 | + 'enum' => array('default', 'products', 'subcategories', 'both'), |
|
206 | + 'context' => array('view', 'edit'), |
|
207 | 207 | ), |
208 | 208 | 'image' => array( |
209 | - 'description' => __( 'Image data.', 'woocommerce' ), |
|
209 | + 'description' => __('Image data.', 'woocommerce'), |
|
210 | 210 | 'type' => 'object', |
211 | - 'context' => array( 'view', 'edit' ), |
|
211 | + 'context' => array('view', 'edit'), |
|
212 | 212 | 'properties' => array( |
213 | 213 | 'id' => array( |
214 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
214 | + 'description' => __('Image ID.', 'woocommerce'), |
|
215 | 215 | 'type' => 'integer', |
216 | - 'context' => array( 'view', 'edit' ), |
|
216 | + 'context' => array('view', 'edit'), |
|
217 | 217 | ), |
218 | 218 | 'date_created' => array( |
219 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
219 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
220 | 220 | 'type' => 'date-time', |
221 | - 'context' => array( 'view', 'edit' ), |
|
221 | + 'context' => array('view', 'edit'), |
|
222 | 222 | 'readonly' => true, |
223 | 223 | ), |
224 | 224 | 'date_created_gmt' => array( |
225 | - 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
|
225 | + 'description' => __('The date the image was created, as GMT.', 'woocommerce'), |
|
226 | 226 | 'type' => 'date-time', |
227 | - 'context' => array( 'view', 'edit' ), |
|
227 | + 'context' => array('view', 'edit'), |
|
228 | 228 | 'readonly' => true, |
229 | 229 | ), |
230 | 230 | 'date_modified' => array( |
231 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
231 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
232 | 232 | 'type' => 'date-time', |
233 | - 'context' => array( 'view', 'edit' ), |
|
233 | + 'context' => array('view', 'edit'), |
|
234 | 234 | 'readonly' => true, |
235 | 235 | ), |
236 | 236 | 'date_modified_gmt' => array( |
237 | - 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
|
237 | + 'description' => __('The date the image was last modified, as GMT.', 'woocommerce'), |
|
238 | 238 | 'type' => 'date-time', |
239 | - 'context' => array( 'view', 'edit' ), |
|
239 | + 'context' => array('view', 'edit'), |
|
240 | 240 | 'readonly' => true, |
241 | 241 | ), |
242 | 242 | 'src' => array( |
243 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
243 | + 'description' => __('Image URL.', 'woocommerce'), |
|
244 | 244 | 'type' => 'string', |
245 | 245 | 'format' => 'uri', |
246 | - 'context' => array( 'view', 'edit' ), |
|
246 | + 'context' => array('view', 'edit'), |
|
247 | 247 | ), |
248 | 248 | 'name' => array( |
249 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
249 | + 'description' => __('Image name.', 'woocommerce'), |
|
250 | 250 | 'type' => 'string', |
251 | - 'context' => array( 'view', 'edit' ), |
|
251 | + 'context' => array('view', 'edit'), |
|
252 | 252 | ), |
253 | 253 | 'alt' => array( |
254 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
254 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
255 | 255 | 'type' => 'string', |
256 | - 'context' => array( 'view', 'edit' ), |
|
256 | + 'context' => array('view', 'edit'), |
|
257 | 257 | ), |
258 | 258 | ), |
259 | 259 | ), |
260 | 260 | 'menu_order' => array( |
261 | - 'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ), |
|
261 | + 'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'), |
|
262 | 262 | 'type' => 'integer', |
263 | - 'context' => array( 'view', 'edit' ), |
|
263 | + 'context' => array('view', 'edit'), |
|
264 | 264 | ), |
265 | 265 | 'count' => array( |
266 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
266 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
267 | 267 | 'type' => 'integer', |
268 | - 'context' => array( 'view', 'edit' ), |
|
268 | + 'context' => array('view', 'edit'), |
|
269 | 269 | 'readonly' => true, |
270 | 270 | ), |
271 | 271 | ), |
272 | 272 | ); |
273 | 273 | |
274 | - return $this->add_additional_fields_schema( $schema ); |
|
274 | + return $this->add_additional_fields_schema($schema); |
|
275 | 275 | } |
276 | 276 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Coupons controller class. |
@@ -40,26 +40,26 @@ discard block |
||
40 | 40 | array( |
41 | 41 | array( |
42 | 42 | 'methods' => \WP_REST_Server::READABLE, |
43 | - 'callback' => array( $this, 'get_items' ), |
|
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
43 | + 'callback' => array($this, 'get_items'), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | 45 | 'args' => $this->get_collection_params(), |
46 | 46 | ), |
47 | 47 | array( |
48 | 48 | 'methods' => \WP_REST_Server::CREATABLE, |
49 | - 'callback' => array( $this, 'create_item' ), |
|
50 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
49 | + 'callback' => array($this, 'create_item'), |
|
50 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
51 | 51 | 'args' => array_merge( |
52 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
52 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
53 | 53 | array( |
54 | 54 | 'code' => array( |
55 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
55 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
56 | 56 | 'required' => true, |
57 | 57 | 'type' => 'string', |
58 | 58 | ), |
59 | 59 | ) |
60 | 60 | ), |
61 | 61 | ), |
62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
62 | + 'schema' => array($this, 'get_public_item_schema'), |
|
63 | 63 | ), |
64 | 64 | true |
65 | 65 | ); |
@@ -70,37 +70,37 @@ discard block |
||
70 | 70 | array( |
71 | 71 | 'args' => array( |
72 | 72 | 'id' => array( |
73 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
73 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
74 | 74 | 'type' => 'integer', |
75 | 75 | ), |
76 | 76 | ), |
77 | 77 | array( |
78 | 78 | 'methods' => \WP_REST_Server::READABLE, |
79 | - 'callback' => array( $this, 'get_item' ), |
|
80 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
79 | + 'callback' => array($this, 'get_item'), |
|
80 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
81 | 81 | 'args' => array( |
82 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
82 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
83 | 83 | ), |
84 | 84 | ), |
85 | 85 | array( |
86 | 86 | 'methods' => \WP_REST_Server::EDITABLE, |
87 | - 'callback' => array( $this, 'update_item' ), |
|
88 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
89 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
87 | + 'callback' => array($this, 'update_item'), |
|
88 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
89 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
90 | 90 | ), |
91 | 91 | array( |
92 | 92 | 'methods' => \WP_REST_Server::DELETABLE, |
93 | - 'callback' => array( $this, 'delete_item' ), |
|
94 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
93 | + 'callback' => array($this, 'delete_item'), |
|
94 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
95 | 95 | 'args' => array( |
96 | 96 | 'force' => array( |
97 | 97 | 'default' => false, |
98 | 98 | 'type' => 'boolean', |
99 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
99 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
100 | 100 | ), |
101 | 101 | ), |
102 | 102 | ), |
103 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
103 | + 'schema' => array($this, 'get_public_item_schema'), |
|
104 | 104 | ), |
105 | 105 | true |
106 | 106 | ); |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | array( |
112 | 112 | array( |
113 | 113 | 'methods' => \WP_REST_Server::EDITABLE, |
114 | - 'callback' => array( $this, 'batch_items' ), |
|
115 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
116 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
114 | + 'callback' => array($this, 'batch_items'), |
|
115 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
116 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
117 | 117 | ), |
118 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
118 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
119 | 119 | ), |
120 | 120 | true |
121 | 121 | ); |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | * @param int $id Object ID. |
129 | 129 | * @return WC_Data |
130 | 130 | */ |
131 | - protected function get_object( $id ) { |
|
132 | - return new \WC_Coupon( $id ); |
|
131 | + protected function get_object($id) { |
|
132 | + return new \WC_Coupon($id); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,28 +139,28 @@ discard block |
||
139 | 139 | * @param WC_Data $object WC_Data instance. |
140 | 140 | * @return array |
141 | 141 | */ |
142 | - protected function get_formatted_item_data( $object ) { |
|
142 | + protected function get_formatted_item_data($object) { |
|
143 | 143 | $data = $object->get_data(); |
144 | 144 | |
145 | - $format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' ); |
|
146 | - $format_date = array( 'date_created', 'date_modified', 'date_expires' ); |
|
147 | - $format_null = array( 'usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items' ); |
|
145 | + $format_decimal = array('amount', 'minimum_amount', 'maximum_amount'); |
|
146 | + $format_date = array('date_created', 'date_modified', 'date_expires'); |
|
147 | + $format_null = array('usage_limit', 'usage_limit_per_user', 'limit_usage_to_x_items'); |
|
148 | 148 | |
149 | 149 | // Format decimal values. |
150 | - foreach ( $format_decimal as $key ) { |
|
151 | - $data[ $key ] = wc_format_decimal( $data[ $key ], 2 ); |
|
150 | + foreach ($format_decimal as $key) { |
|
151 | + $data[$key] = wc_format_decimal($data[$key], 2); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Format date values. |
155 | - foreach ( $format_date as $key ) { |
|
156 | - $datetime = $data[ $key ]; |
|
157 | - $data[ $key ] = wc_rest_prepare_date_response( $datetime, false ); |
|
158 | - $data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime ); |
|
155 | + foreach ($format_date as $key) { |
|
156 | + $datetime = $data[$key]; |
|
157 | + $data[$key] = wc_rest_prepare_date_response($datetime, false); |
|
158 | + $data[$key . '_gmt'] = wc_rest_prepare_date_response($datetime); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | // Format null values. |
162 | - foreach ( $format_null as $key ) { |
|
163 | - $data[ $key ] = $data[ $key ] ? $data[ $key ] : null; |
|
162 | + foreach ($format_null as $key) { |
|
163 | + $data[$key] = $data[$key] ? $data[$key] : null; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | return array( |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | * @param \WP_REST_Request $request Request object. |
203 | 203 | * @return \WP_REST_Response |
204 | 204 | */ |
205 | - public function prepare_object_for_response( $object, $request ) { |
|
206 | - $data = $this->get_formatted_item_data( $object ); |
|
207 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
208 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
209 | - $data = $this->filter_response_by_context( $data, $context ); |
|
210 | - $response = rest_ensure_response( $data ); |
|
211 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
205 | + public function prepare_object_for_response($object, $request) { |
|
206 | + $data = $this->get_formatted_item_data($object); |
|
207 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
208 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
209 | + $data = $this->filter_response_by_context($data, $context); |
|
210 | + $response = rest_ensure_response($data); |
|
211 | + $response->add_links($this->prepare_links($object, $request)); |
|
212 | 212 | |
213 | 213 | /** |
214 | 214 | * Filter the data for a response. |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @param WC_Data $object Object data. |
221 | 221 | * @param \WP_REST_Request $request Request object. |
222 | 222 | */ |
223 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
223 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -230,15 +230,15 @@ discard block |
||
230 | 230 | * @param \WP_REST_Request $request Full details about the request. |
231 | 231 | * @return array |
232 | 232 | */ |
233 | - protected function prepare_objects_query( $request ) { |
|
234 | - $args = parent::prepare_objects_query( $request ); |
|
233 | + protected function prepare_objects_query($request) { |
|
234 | + $args = parent::prepare_objects_query($request); |
|
235 | 235 | |
236 | - if ( ! empty( $request['code'] ) ) { |
|
237 | - $id = wc_get_coupon_id_by_code( $request['code'] ); |
|
238 | - $args['post__in'] = array( $id ); |
|
236 | + if ( ! empty($request['code'])) { |
|
237 | + $id = wc_get_coupon_id_by_code($request['code']); |
|
238 | + $args['post__in'] = array($id); |
|
239 | 239 | } |
240 | 240 | |
241 | - if ( ! empty( $request['search'] ) ) { |
|
241 | + if ( ! empty($request['search'])) { |
|
242 | 242 | $args['search'] = $request['search']; |
243 | 243 | $args['s'] = false; |
244 | 244 | } |
@@ -253,47 +253,47 @@ discard block |
||
253 | 253 | * @param bool $creating If is creating a new object. |
254 | 254 | * @return \WP_Error|WC_Data |
255 | 255 | */ |
256 | - protected function prepare_object_for_database( $request, $creating = false ) { |
|
257 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
258 | - $coupon = new \WC_Coupon( $id ); |
|
256 | + protected function prepare_object_for_database($request, $creating = false) { |
|
257 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
258 | + $coupon = new \WC_Coupon($id); |
|
259 | 259 | $schema = $this->get_item_schema(); |
260 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
260 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
261 | 261 | |
262 | 262 | // Validate required POST fields. |
263 | - if ( $creating && empty( $request['code'] ) ) { |
|
264 | - return new \WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) ); |
|
263 | + if ($creating && empty($request['code'])) { |
|
264 | + return new \WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400)); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Handle all writable props. |
268 | - foreach ( $data_keys as $key ) { |
|
269 | - $value = $request[ $key ]; |
|
268 | + foreach ($data_keys as $key) { |
|
269 | + $value = $request[$key]; |
|
270 | 270 | |
271 | - if ( ! is_null( $value ) ) { |
|
272 | - switch ( $key ) { |
|
271 | + if ( ! is_null($value)) { |
|
272 | + switch ($key) { |
|
273 | 273 | case 'code': |
274 | - $coupon_code = wc_format_coupon_code( $value ); |
|
274 | + $coupon_code = wc_format_coupon_code($value); |
|
275 | 275 | $id = $coupon->get_id() ? $coupon->get_id() : 0; |
276 | - $id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id ); |
|
276 | + $id_from_code = wc_get_coupon_id_by_code($coupon_code, $id); |
|
277 | 277 | |
278 | - if ( $id_from_code ) { |
|
279 | - return new \WP_Error( 'woocommerce_rest_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce' ), array( 'status' => 400 ) ); |
|
278 | + if ($id_from_code) { |
|
279 | + return new \WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400)); |
|
280 | 280 | } |
281 | 281 | |
282 | - $coupon->set_code( $coupon_code ); |
|
282 | + $coupon->set_code($coupon_code); |
|
283 | 283 | break; |
284 | 284 | case 'meta_data': |
285 | - if ( is_array( $value ) ) { |
|
286 | - foreach ( $value as $meta ) { |
|
287 | - $coupon->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
285 | + if (is_array($value)) { |
|
286 | + foreach ($value as $meta) { |
|
287 | + $coupon->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | break; |
291 | 291 | case 'description': |
292 | - $coupon->set_description( wp_filter_post_kses( $value ) ); |
|
292 | + $coupon->set_description(wp_filter_post_kses($value)); |
|
293 | 293 | break; |
294 | 294 | default: |
295 | - if ( is_callable( array( $coupon, "set_{$key}" ) ) ) { |
|
296 | - $coupon->{"set_{$key}"}( $value ); |
|
295 | + if (is_callable(array($coupon, "set_{$key}"))) { |
|
296 | + $coupon->{"set_{$key}"}($value); |
|
297 | 297 | } |
298 | 298 | break; |
299 | 299 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * @param \WP_REST_Request $request Request object. |
311 | 311 | * @param bool $creating If is creating a new object. |
312 | 312 | */ |
313 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating ); |
|
313 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}_object", $coupon, $request, $creating); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -325,194 +325,194 @@ discard block |
||
325 | 325 | 'type' => 'object', |
326 | 326 | 'properties' => array( |
327 | 327 | 'id' => array( |
328 | - 'description' => __( 'Unique identifier for the object.', 'woocommerce' ), |
|
328 | + 'description' => __('Unique identifier for the object.', 'woocommerce'), |
|
329 | 329 | 'type' => 'integer', |
330 | - 'context' => array( 'view', 'edit' ), |
|
330 | + 'context' => array('view', 'edit'), |
|
331 | 331 | 'readonly' => true, |
332 | 332 | ), |
333 | 333 | 'code' => array( |
334 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
334 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
335 | 335 | 'type' => 'string', |
336 | - 'context' => array( 'view', 'edit' ), |
|
336 | + 'context' => array('view', 'edit'), |
|
337 | 337 | ), |
338 | 338 | 'amount' => array( |
339 | - 'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce' ), |
|
339 | + 'description' => __('The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce'), |
|
340 | 340 | 'type' => 'string', |
341 | - 'context' => array( 'view', 'edit' ), |
|
341 | + 'context' => array('view', 'edit'), |
|
342 | 342 | ), |
343 | 343 | 'date_created' => array( |
344 | - 'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce' ), |
|
344 | + 'description' => __("The date the coupon was created, in the site's timezone.", 'woocommerce'), |
|
345 | 345 | 'type' => 'date-time', |
346 | - 'context' => array( 'view', 'edit' ), |
|
346 | + 'context' => array('view', 'edit'), |
|
347 | 347 | 'readonly' => true, |
348 | 348 | ), |
349 | 349 | 'date_created_gmt' => array( |
350 | - 'description' => __( 'The date the coupon was created, as GMT.', 'woocommerce' ), |
|
350 | + 'description' => __('The date the coupon was created, as GMT.', 'woocommerce'), |
|
351 | 351 | 'type' => 'date-time', |
352 | - 'context' => array( 'view', 'edit' ), |
|
352 | + 'context' => array('view', 'edit'), |
|
353 | 353 | 'readonly' => true, |
354 | 354 | ), |
355 | 355 | 'date_modified' => array( |
356 | - 'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce' ), |
|
356 | + 'description' => __("The date the coupon was last modified, in the site's timezone.", 'woocommerce'), |
|
357 | 357 | 'type' => 'date-time', |
358 | - 'context' => array( 'view', 'edit' ), |
|
358 | + 'context' => array('view', 'edit'), |
|
359 | 359 | 'readonly' => true, |
360 | 360 | ), |
361 | 361 | 'date_modified_gmt' => array( |
362 | - 'description' => __( 'The date the coupon was last modified, as GMT.', 'woocommerce' ), |
|
362 | + 'description' => __('The date the coupon was last modified, as GMT.', 'woocommerce'), |
|
363 | 363 | 'type' => 'date-time', |
364 | - 'context' => array( 'view', 'edit' ), |
|
364 | + 'context' => array('view', 'edit'), |
|
365 | 365 | 'readonly' => true, |
366 | 366 | ), |
367 | 367 | 'discount_type' => array( |
368 | - 'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ), |
|
368 | + 'description' => __('Determines the type of discount that will be applied.', 'woocommerce'), |
|
369 | 369 | 'type' => 'string', |
370 | 370 | 'default' => 'fixed_cart', |
371 | - 'enum' => array_keys( wc_get_coupon_types() ), |
|
372 | - 'context' => array( 'view', 'edit' ), |
|
371 | + 'enum' => array_keys(wc_get_coupon_types()), |
|
372 | + 'context' => array('view', 'edit'), |
|
373 | 373 | ), |
374 | 374 | 'description' => array( |
375 | - 'description' => __( 'Coupon description.', 'woocommerce' ), |
|
375 | + 'description' => __('Coupon description.', 'woocommerce'), |
|
376 | 376 | 'type' => 'string', |
377 | - 'context' => array( 'view', 'edit' ), |
|
377 | + 'context' => array('view', 'edit'), |
|
378 | 378 | ), |
379 | 379 | 'date_expires' => array( |
380 | - 'description' => __( "The date the coupon expires, in the site's timezone.", 'woocommerce' ), |
|
380 | + 'description' => __("The date the coupon expires, in the site's timezone.", 'woocommerce'), |
|
381 | 381 | 'type' => 'string', |
382 | - 'context' => array( 'view', 'edit' ), |
|
382 | + 'context' => array('view', 'edit'), |
|
383 | 383 | ), |
384 | 384 | 'date_expires_gmt' => array( |
385 | - 'description' => __( 'The date the coupon expires, as GMT.', 'woocommerce' ), |
|
385 | + 'description' => __('The date the coupon expires, as GMT.', 'woocommerce'), |
|
386 | 386 | 'type' => 'string', |
387 | - 'context' => array( 'view', 'edit' ), |
|
387 | + 'context' => array('view', 'edit'), |
|
388 | 388 | ), |
389 | 389 | 'usage_count' => array( |
390 | - 'description' => __( 'Number of times the coupon has been used already.', 'woocommerce' ), |
|
390 | + 'description' => __('Number of times the coupon has been used already.', 'woocommerce'), |
|
391 | 391 | 'type' => 'integer', |
392 | - 'context' => array( 'view', 'edit' ), |
|
392 | + 'context' => array('view', 'edit'), |
|
393 | 393 | 'readonly' => true, |
394 | 394 | ), |
395 | 395 | 'individual_use' => array( |
396 | - 'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce' ), |
|
396 | + 'description' => __('If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce'), |
|
397 | 397 | 'type' => 'boolean', |
398 | 398 | 'default' => false, |
399 | - 'context' => array( 'view', 'edit' ), |
|
399 | + 'context' => array('view', 'edit'), |
|
400 | 400 | ), |
401 | 401 | 'product_ids' => array( |
402 | - 'description' => __( 'List of product IDs the coupon can be used on.', 'woocommerce' ), |
|
402 | + 'description' => __('List of product IDs the coupon can be used on.', 'woocommerce'), |
|
403 | 403 | 'type' => 'array', |
404 | 404 | 'items' => array( |
405 | 405 | 'type' => 'integer', |
406 | 406 | ), |
407 | - 'context' => array( 'view', 'edit' ), |
|
407 | + 'context' => array('view', 'edit'), |
|
408 | 408 | ), |
409 | 409 | 'excluded_product_ids' => array( |
410 | - 'description' => __( 'List of product IDs the coupon cannot be used on.', 'woocommerce' ), |
|
410 | + 'description' => __('List of product IDs the coupon cannot be used on.', 'woocommerce'), |
|
411 | 411 | 'type' => 'array', |
412 | 412 | 'items' => array( |
413 | 413 | 'type' => 'integer', |
414 | 414 | ), |
415 | - 'context' => array( 'view', 'edit' ), |
|
415 | + 'context' => array('view', 'edit'), |
|
416 | 416 | ), |
417 | 417 | 'usage_limit' => array( |
418 | - 'description' => __( 'How many times the coupon can be used in total.', 'woocommerce' ), |
|
418 | + 'description' => __('How many times the coupon can be used in total.', 'woocommerce'), |
|
419 | 419 | 'type' => 'integer', |
420 | - 'context' => array( 'view', 'edit' ), |
|
420 | + 'context' => array('view', 'edit'), |
|
421 | 421 | ), |
422 | 422 | 'usage_limit_per_user' => array( |
423 | - 'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce' ), |
|
423 | + 'description' => __('How many times the coupon can be used per customer.', 'woocommerce'), |
|
424 | 424 | 'type' => 'integer', |
425 | - 'context' => array( 'view', 'edit' ), |
|
425 | + 'context' => array('view', 'edit'), |
|
426 | 426 | ), |
427 | 427 | 'limit_usage_to_x_items' => array( |
428 | - 'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'woocommerce' ), |
|
428 | + 'description' => __('Max number of items in the cart the coupon can be applied to.', 'woocommerce'), |
|
429 | 429 | 'type' => 'integer', |
430 | - 'context' => array( 'view', 'edit' ), |
|
430 | + 'context' => array('view', 'edit'), |
|
431 | 431 | ), |
432 | 432 | 'free_shipping' => array( |
433 | - 'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce' ), |
|
433 | + 'description' => __('If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce'), |
|
434 | 434 | 'type' => 'boolean', |
435 | 435 | 'default' => false, |
436 | - 'context' => array( 'view', 'edit' ), |
|
436 | + 'context' => array('view', 'edit'), |
|
437 | 437 | ), |
438 | 438 | 'product_categories' => array( |
439 | - 'description' => __( 'List of category IDs the coupon applies to.', 'woocommerce' ), |
|
439 | + 'description' => __('List of category IDs the coupon applies to.', 'woocommerce'), |
|
440 | 440 | 'type' => 'array', |
441 | 441 | 'items' => array( |
442 | 442 | 'type' => 'integer', |
443 | 443 | ), |
444 | - 'context' => array( 'view', 'edit' ), |
|
444 | + 'context' => array('view', 'edit'), |
|
445 | 445 | ), |
446 | 446 | 'excluded_product_categories' => array( |
447 | - 'description' => __( 'List of category IDs the coupon does not apply to.', 'woocommerce' ), |
|
447 | + 'description' => __('List of category IDs the coupon does not apply to.', 'woocommerce'), |
|
448 | 448 | 'type' => 'array', |
449 | 449 | 'items' => array( |
450 | 450 | 'type' => 'integer', |
451 | 451 | ), |
452 | - 'context' => array( 'view', 'edit' ), |
|
452 | + 'context' => array('view', 'edit'), |
|
453 | 453 | ), |
454 | 454 | 'exclude_sale_items' => array( |
455 | - 'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'woocommerce' ), |
|
455 | + 'description' => __('If true, this coupon will not be applied to items that have sale prices.', 'woocommerce'), |
|
456 | 456 | 'type' => 'boolean', |
457 | 457 | 'default' => false, |
458 | - 'context' => array( 'view', 'edit' ), |
|
458 | + 'context' => array('view', 'edit'), |
|
459 | 459 | ), |
460 | 460 | 'minimum_amount' => array( |
461 | - 'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce' ), |
|
461 | + 'description' => __('Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce'), |
|
462 | 462 | 'type' => 'string', |
463 | - 'context' => array( 'view', 'edit' ), |
|
463 | + 'context' => array('view', 'edit'), |
|
464 | 464 | ), |
465 | 465 | 'maximum_amount' => array( |
466 | - 'description' => __( 'Maximum order amount allowed when using the coupon.', 'woocommerce' ), |
|
466 | + 'description' => __('Maximum order amount allowed when using the coupon.', 'woocommerce'), |
|
467 | 467 | 'type' => 'string', |
468 | - 'context' => array( 'view', 'edit' ), |
|
468 | + 'context' => array('view', 'edit'), |
|
469 | 469 | ), |
470 | 470 | 'email_restrictions' => array( |
471 | - 'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ), |
|
471 | + 'description' => __('List of email addresses that can use this coupon.', 'woocommerce'), |
|
472 | 472 | 'type' => 'array', |
473 | 473 | 'items' => array( |
474 | 474 | 'type' => 'string', |
475 | 475 | ), |
476 | - 'context' => array( 'view', 'edit' ), |
|
476 | + 'context' => array('view', 'edit'), |
|
477 | 477 | ), |
478 | 478 | 'used_by' => array( |
479 | - 'description' => __( 'List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce' ), |
|
479 | + 'description' => __('List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce'), |
|
480 | 480 | 'type' => 'array', |
481 | 481 | 'items' => array( |
482 | 482 | 'type' => 'integer', |
483 | 483 | ), |
484 | - 'context' => array( 'view', 'edit' ), |
|
484 | + 'context' => array('view', 'edit'), |
|
485 | 485 | 'readonly' => true, |
486 | 486 | ), |
487 | 487 | 'meta_data' => array( |
488 | - 'description' => __( 'Meta data.', 'woocommerce' ), |
|
488 | + 'description' => __('Meta data.', 'woocommerce'), |
|
489 | 489 | 'type' => 'array', |
490 | - 'context' => array( 'view', 'edit' ), |
|
490 | + 'context' => array('view', 'edit'), |
|
491 | 491 | 'items' => array( |
492 | 492 | 'type' => 'object', |
493 | 493 | 'properties' => array( |
494 | 494 | 'id' => array( |
495 | - 'description' => __( 'Meta ID.', 'woocommerce' ), |
|
495 | + 'description' => __('Meta ID.', 'woocommerce'), |
|
496 | 496 | 'type' => 'integer', |
497 | - 'context' => array( 'view', 'edit' ), |
|
497 | + 'context' => array('view', 'edit'), |
|
498 | 498 | 'readonly' => true, |
499 | 499 | ), |
500 | 500 | 'key' => array( |
501 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
501 | + 'description' => __('Meta key.', 'woocommerce'), |
|
502 | 502 | 'type' => 'string', |
503 | - 'context' => array( 'view', 'edit' ), |
|
503 | + 'context' => array('view', 'edit'), |
|
504 | 504 | ), |
505 | 505 | 'value' => array( |
506 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
506 | + 'description' => __('Meta value.', 'woocommerce'), |
|
507 | 507 | 'type' => 'mixed', |
508 | - 'context' => array( 'view', 'edit' ), |
|
508 | + 'context' => array('view', 'edit'), |
|
509 | 509 | ), |
510 | 510 | ), |
511 | 511 | ), |
512 | 512 | ), |
513 | 513 | ), |
514 | 514 | ); |
515 | - return $this->add_additional_fields_schema( $schema ); |
|
515 | + return $this->add_additional_fields_schema($schema); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
@@ -524,14 +524,14 @@ discard block |
||
524 | 524 | $params = parent::get_collection_params(); |
525 | 525 | |
526 | 526 | $params['code'] = array( |
527 | - 'description' => __( 'Limit result set to resources with a specific code.', 'woocommerce' ), |
|
527 | + 'description' => __('Limit result set to resources with a specific code.', 'woocommerce'), |
|
528 | 528 | 'type' => 'string', |
529 | 529 | 'sanitize_callback' => 'sanitize_text_field', |
530 | 530 | 'validate_callback' => 'rest_validate_request_arg', |
531 | 531 | ); |
532 | 532 | |
533 | 533 | $params['search'] = array( |
534 | - 'description' => __( 'Limit results to coupons with codes matching a given string.', 'woocommerce' ), |
|
534 | + 'description' => __('Limit results to coupons with codes matching a given string.', 'woocommerce'), |
|
535 | 535 | 'type' => 'string', |
536 | 536 | 'validate_callback' => 'rest_validate_request_arg', |
537 | 537 | ); |
@@ -545,8 +545,8 @@ discard block |
||
545 | 545 | * @param array $schema Schema array. |
546 | 546 | * @return bool |
547 | 547 | */ |
548 | - protected function filter_writable_props( $schema ) { |
|
549 | - return empty( $schema['readonly'] ); |
|
548 | + protected function filter_writable_props($schema) { |
|
549 | + return empty($schema['readonly']); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
@@ -555,10 +555,10 @@ discard block |
||
555 | 555 | * @param \WP_REST_Request $request Full details about the request. |
556 | 556 | * @return \WP_Error\WP_REST_Response |
557 | 557 | */ |
558 | - public function get_items( $request ) { |
|
559 | - add_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10, 2 ); |
|
560 | - $response = parent::get_items( $request ); |
|
561 | - remove_filter( 'posts_where', array( $this, 'add_wp_query_search_code_filter' ), 10 ); |
|
558 | + public function get_items($request) { |
|
559 | + add_filter('posts_where', array($this, 'add_wp_query_search_code_filter'), 10, 2); |
|
560 | + $response = parent::get_items($request); |
|
561 | + remove_filter('posts_where', array($this, 'add_wp_query_search_code_filter'), 10); |
|
562 | 562 | return $response; |
563 | 563 | } |
564 | 564 | |
@@ -569,12 +569,12 @@ discard block |
||
569 | 569 | * @param object $wp_query \WP_Query object. |
570 | 570 | * @return string |
571 | 571 | */ |
572 | - public function add_wp_query_search_code_filter( $where, $wp_query ) { |
|
572 | + public function add_wp_query_search_code_filter($where, $wp_query) { |
|
573 | 573 | global $wpdb; |
574 | 574 | |
575 | - $search = $wp_query->get( 'search' ); |
|
576 | - if ( $search ) { |
|
577 | - $search = $wpdb->esc_like( $search ); |
|
575 | + $search = $wp_query->get('search'); |
|
576 | + if ($search) { |
|
577 | + $search = $wpdb->esc_like($search); |
|
578 | 578 | $search = "'%" . $search . "%'"; |
579 | 579 | $where .= ' AND ' . $wpdb->posts . '.post_title LIKE ' . $search; |
580 | 580 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Order Notes controller class. |
@@ -40,29 +40,29 @@ discard block |
||
40 | 40 | array( |
41 | 41 | 'args' => array( |
42 | 42 | 'order_id' => array( |
43 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
43 | + 'description' => __('The order ID.', 'woocommerce'), |
|
44 | 44 | 'type' => 'integer', |
45 | 45 | ), |
46 | 46 | ), |
47 | 47 | array( |
48 | 48 | 'methods' => \WP_REST_Server::READABLE, |
49 | - 'callback' => array( $this, 'get_items' ), |
|
50 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
49 | + 'callback' => array($this, 'get_items'), |
|
50 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
51 | 51 | 'args' => $this->get_collection_params(), |
52 | 52 | ), |
53 | 53 | array( |
54 | 54 | 'methods' => \WP_REST_Server::CREATABLE, |
55 | - 'callback' => array( $this, 'create_item' ), |
|
56 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
57 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), array( |
|
55 | + 'callback' => array($this, 'create_item'), |
|
56 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
57 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), array( |
|
58 | 58 | 'note' => array( |
59 | 59 | 'type' => 'string', |
60 | - 'description' => __( 'Order note content.', 'woocommerce' ), |
|
60 | + 'description' => __('Order note content.', 'woocommerce'), |
|
61 | 61 | 'required' => true, |
62 | 62 | ), |
63 | - ) ), |
|
63 | + )), |
|
64 | 64 | ), |
65 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
65 | + 'schema' => array($this, 'get_public_item_schema'), |
|
66 | 66 | ), |
67 | 67 | true |
68 | 68 | ); |
@@ -73,35 +73,35 @@ discard block |
||
73 | 73 | array( |
74 | 74 | 'args' => array( |
75 | 75 | 'id' => array( |
76 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
76 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
77 | 77 | 'type' => 'integer', |
78 | 78 | ), |
79 | 79 | 'order_id' => array( |
80 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
80 | + 'description' => __('The order ID.', 'woocommerce'), |
|
81 | 81 | 'type' => 'integer', |
82 | 82 | ), |
83 | 83 | ), |
84 | 84 | array( |
85 | 85 | 'methods' => \WP_REST_Server::READABLE, |
86 | - 'callback' => array( $this, 'get_item' ), |
|
87 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
86 | + 'callback' => array($this, 'get_item'), |
|
87 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
88 | 88 | 'args' => array( |
89 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
89 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | array( |
93 | 93 | 'methods' => \WP_REST_Server::DELETABLE, |
94 | - 'callback' => array( $this, 'delete_item' ), |
|
95 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
94 | + 'callback' => array($this, 'delete_item'), |
|
95 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
96 | 96 | 'args' => array( |
97 | 97 | 'force' => array( |
98 | 98 | 'default' => false, |
99 | 99 | 'type' => 'boolean', |
100 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
100 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
101 | 101 | ), |
102 | 102 | ), |
103 | 103 | ), |
104 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
104 | + 'schema' => array($this, 'get_public_item_schema'), |
|
105 | 105 | ), |
106 | 106 | true |
107 | 107 | ); |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * @param \WP_REST_Request $request Full details about the request. |
114 | 114 | * @return \WP_Error|boolean |
115 | 115 | */ |
116 | - public function get_items_permissions_check( $request ) { |
|
117 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'read' ) ) { |
|
118 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
116 | + public function get_items_permissions_check($request) { |
|
117 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'read')) { |
|
118 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | return true; |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return bool|\WP_Error |
130 | 130 | */ |
131 | - public function create_item_permissions_check( $request ) { |
|
132 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'create' ) ) { |
|
133 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
131 | + public function create_item_permissions_check($request) { |
|
132 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'create')) { |
|
133 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | return true; |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param \WP_REST_Request $request Full details about the request. |
143 | 143 | * @return \WP_Error|boolean |
144 | 144 | */ |
145 | - public function get_item_permissions_check( $request ) { |
|
146 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
145 | + public function get_item_permissions_check($request) { |
|
146 | + $order = wc_get_order((int) $request['order_id']); |
|
147 | 147 | |
148 | - if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'read', $order->get_id() ) ) { |
|
149 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
148 | + if ($order && ! wc_rest_check_post_permissions($this->post_type, 'read', $order->get_id())) { |
|
149 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | return true; |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @return bool|\WP_Error |
161 | 161 | */ |
162 | - public function delete_item_permissions_check( $request ) { |
|
163 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
162 | + public function delete_item_permissions_check($request) { |
|
163 | + $order = wc_get_order((int) $request['order_id']); |
|
164 | 164 | |
165 | - if ( $order && ! wc_rest_check_post_permissions( $this->post_type, 'delete', $order->get_id() ) ) { |
|
166 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
165 | + if ($order && ! wc_rest_check_post_permissions($this->post_type, 'delete', $order->get_id())) { |
|
166 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | return true; |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | * |
177 | 177 | * @return array|\WP_Error |
178 | 178 | */ |
179 | - public function get_items( $request ) { |
|
180 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
179 | + public function get_items($request) { |
|
180 | + $order = wc_get_order((int) $request['order_id']); |
|
181 | 181 | |
182 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
183 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
182 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
183 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | $args = array( |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | ); |
191 | 191 | |
192 | 192 | // Allow filter by order note type. |
193 | - if ( 'customer' === $request['type'] ) { |
|
193 | + if ('customer' === $request['type']) { |
|
194 | 194 | $args['meta_query'] = array( // WPCS: slow query ok. |
195 | 195 | array( |
196 | 196 | 'key' => 'is_customer_note', |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | 'compare' => '=', |
199 | 199 | ), |
200 | 200 | ); |
201 | - } elseif ( 'internal' === $request['type'] ) { |
|
201 | + } elseif ('internal' === $request['type']) { |
|
202 | 202 | $args['meta_query'] = array( // WPCS: slow query ok. |
203 | 203 | array( |
204 | 204 | 'key' => 'is_customer_note', |
@@ -207,20 +207,20 @@ discard block |
||
207 | 207 | ); |
208 | 208 | } |
209 | 209 | |
210 | - remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); |
|
210 | + remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1); |
|
211 | 211 | |
212 | - $notes = get_comments( $args ); |
|
212 | + $notes = get_comments($args); |
|
213 | 213 | |
214 | - add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); |
|
214 | + add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'), 10, 1); |
|
215 | 215 | |
216 | 216 | $data = array(); |
217 | - foreach ( $notes as $note ) { |
|
218 | - $order_note = $this->prepare_item_for_response( $note, $request ); |
|
219 | - $order_note = $this->prepare_response_for_collection( $order_note ); |
|
217 | + foreach ($notes as $note) { |
|
218 | + $order_note = $this->prepare_item_for_response($note, $request); |
|
219 | + $order_note = $this->prepare_response_for_collection($order_note); |
|
220 | 220 | $data[] = $order_note; |
221 | 221 | } |
222 | 222 | |
223 | - return rest_ensure_response( $data ); |
|
223 | + return rest_ensure_response($data); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -229,27 +229,27 @@ discard block |
||
229 | 229 | * @param \WP_REST_Request $request Full details about the request. |
230 | 230 | * @return \WP_Error\WP_REST_Response |
231 | 231 | */ |
232 | - public function create_item( $request ) { |
|
233 | - if ( ! empty( $request['id'] ) ) { |
|
232 | + public function create_item($request) { |
|
233 | + if ( ! empty($request['id'])) { |
|
234 | 234 | /* translators: %s: post type */ |
235 | - return new \WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
235 | + return new \WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
236 | 236 | } |
237 | 237 | |
238 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
238 | + $order = wc_get_order((int) $request['order_id']); |
|
239 | 239 | |
240 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
241 | - return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
240 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
241 | + return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | // Create the note. |
245 | - $note_id = $order->add_order_note( $request['note'], $request['customer_note'], $request['added_by_user'] ); |
|
245 | + $note_id = $order->add_order_note($request['note'], $request['customer_note'], $request['added_by_user']); |
|
246 | 246 | |
247 | - if ( ! $note_id ) { |
|
248 | - return new \WP_Error( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
247 | + if ( ! $note_id) { |
|
248 | + return new \WP_Error('woocommerce_api_cannot_create_order_note', __('Cannot create order note, please try again.', 'woocommerce'), array('status' => 500)); |
|
249 | 249 | } |
250 | 250 | |
251 | - $note = get_comment( $note_id ); |
|
252 | - $this->update_additional_fields_for_object( $note, $request ); |
|
251 | + $note = get_comment($note_id); |
|
252 | + $this->update_additional_fields_for_object($note, $request); |
|
253 | 253 | |
254 | 254 | /** |
255 | 255 | * Fires after a order note is created or updated via the REST API. |
@@ -258,13 +258,13 @@ discard block |
||
258 | 258 | * @param \WP_REST_Request $request Request object. |
259 | 259 | * @param boolean $creating True when creating item, false when updating. |
260 | 260 | */ |
261 | - do_action( 'woocommerce_rest_insert_order_note', $note, $request, true ); |
|
261 | + do_action('woocommerce_rest_insert_order_note', $note, $request, true); |
|
262 | 262 | |
263 | - $request->set_param( 'context', 'edit' ); |
|
264 | - $response = $this->prepare_item_for_response( $note, $request ); |
|
265 | - $response = rest_ensure_response( $response ); |
|
266 | - $response->set_status( 201 ); |
|
267 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, str_replace( '(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base ), $note_id ) ) ); |
|
263 | + $request->set_param('context', 'edit'); |
|
264 | + $response = $this->prepare_item_for_response($note, $request); |
|
265 | + $response = rest_ensure_response($response); |
|
266 | + $response->set_status(201); |
|
267 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, str_replace('(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base), $note_id))); |
|
268 | 268 | |
269 | 269 | return $response; |
270 | 270 | } |
@@ -275,22 +275,22 @@ discard block |
||
275 | 275 | * @param \WP_REST_Request $request Full details about the request. |
276 | 276 | * @return \WP_Error\WP_REST_Response |
277 | 277 | */ |
278 | - public function get_item( $request ) { |
|
278 | + public function get_item($request) { |
|
279 | 279 | $id = (int) $request['id']; |
280 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
280 | + $order = wc_get_order((int) $request['order_id']); |
|
281 | 281 | |
282 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
283 | - return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
282 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
283 | + return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
284 | 284 | } |
285 | 285 | |
286 | - $note = get_comment( $id ); |
|
286 | + $note = get_comment($id); |
|
287 | 287 | |
288 | - if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { |
|
289 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
288 | + if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) { |
|
289 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
290 | 290 | } |
291 | 291 | |
292 | - $order_note = $this->prepare_item_for_response( $note, $request ); |
|
293 | - $response = rest_ensure_response( $order_note ); |
|
292 | + $order_note = $this->prepare_item_for_response($note, $request); |
|
293 | + $response = rest_ensure_response($order_note); |
|
294 | 294 | |
295 | 295 | return $response; |
296 | 296 | } |
@@ -301,33 +301,33 @@ discard block |
||
301 | 301 | * @param \WP_REST_Request $request Full details about the request. |
302 | 302 | * @return \WP_REST_Response|\WP_Error |
303 | 303 | */ |
304 | - public function delete_item( $request ) { |
|
304 | + public function delete_item($request) { |
|
305 | 305 | $id = (int) $request['id']; |
306 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
306 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
307 | 307 | |
308 | 308 | // We don't support trashing for this type, error out. |
309 | - if ( ! $force ) { |
|
310 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
309 | + if ( ! $force) { |
|
310 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
311 | 311 | } |
312 | 312 | |
313 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
313 | + $order = wc_get_order((int) $request['order_id']); |
|
314 | 314 | |
315 | - if ( ! $order || $this->post_type !== $order->get_type() ) { |
|
316 | - return new \WP_Error( 'woocommerce_rest_order_invalid_id', __( 'Invalid order ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
315 | + if ( ! $order || $this->post_type !== $order->get_type()) { |
|
316 | + return new \WP_Error('woocommerce_rest_order_invalid_id', __('Invalid order ID.', 'woocommerce'), array('status' => 404)); |
|
317 | 317 | } |
318 | 318 | |
319 | - $note = get_comment( $id ); |
|
319 | + $note = get_comment($id); |
|
320 | 320 | |
321 | - if ( empty( $id ) || empty( $note ) || intval( $note->comment_post_ID ) !== intval( $order->get_id() ) ) { |
|
322 | - return new \WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
321 | + if (empty($id) || empty($note) || intval($note->comment_post_ID) !== intval($order->get_id())) { |
|
322 | + return new \WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
323 | 323 | } |
324 | 324 | |
325 | - $request->set_param( 'context', 'edit' ); |
|
326 | - $previous = $this->prepare_item_for_response( $note, $request ); |
|
327 | - $result = wc_delete_order_note( $note->comment_ID ); |
|
325 | + $request->set_param('context', 'edit'); |
|
326 | + $previous = $this->prepare_item_for_response($note, $request); |
|
327 | + $result = wc_delete_order_note($note->comment_ID); |
|
328 | 328 | |
329 | - if ( ! $result ) { |
|
330 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), 'order_note' ), array( 'status' => 500 ) ); |
|
329 | + if ( ! $result) { |
|
330 | + return new \WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), 'order_note'), array('status' => 500)); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | $response = new \WP_REST_Response(); |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @param \WP_REST_Response $response The response data. |
346 | 346 | * @param \WP_REST_Request $request The request sent to the API. |
347 | 347 | */ |
348 | - do_action( 'woocommerce_rest_delete_order_note', $note, $response, $request ); |
|
348 | + do_action('woocommerce_rest_delete_order_note', $note, $response, $request); |
|
349 | 349 | |
350 | 350 | return $response; |
351 | 351 | } |
@@ -357,24 +357,24 @@ discard block |
||
357 | 357 | * @param \WP_REST_Request $request Request object. |
358 | 358 | * @return \WP_REST_Response $response Response data. |
359 | 359 | */ |
360 | - public function prepare_item_for_response( $note, $request ) { |
|
360 | + public function prepare_item_for_response($note, $request) { |
|
361 | 361 | $data = array( |
362 | 362 | 'id' => (int) $note->comment_ID, |
363 | - 'author' => __( 'WooCommerce', 'woocommerce' ) === $note->comment_author ? 'system' : $note->comment_author, |
|
364 | - 'date_created' => wc_rest_prepare_date_response( $note->comment_date ), |
|
365 | - 'date_created_gmt' => wc_rest_prepare_date_response( $note->comment_date_gmt ), |
|
363 | + 'author' => __('WooCommerce', 'woocommerce') === $note->comment_author ? 'system' : $note->comment_author, |
|
364 | + 'date_created' => wc_rest_prepare_date_response($note->comment_date), |
|
365 | + 'date_created_gmt' => wc_rest_prepare_date_response($note->comment_date_gmt), |
|
366 | 366 | 'note' => $note->comment_content, |
367 | - 'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ), |
|
367 | + 'customer_note' => (bool) get_comment_meta($note->comment_ID, 'is_customer_note', true), |
|
368 | 368 | ); |
369 | 369 | |
370 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
371 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
372 | - $data = $this->filter_response_by_context( $data, $context ); |
|
370 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
371 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
372 | + $data = $this->filter_response_by_context($data, $context); |
|
373 | 373 | |
374 | 374 | // Wrap the data in a response object. |
375 | - $response = rest_ensure_response( $data ); |
|
375 | + $response = rest_ensure_response($data); |
|
376 | 376 | |
377 | - $response->add_links( $this->prepare_links( $note ) ); |
|
377 | + $response->add_links($this->prepare_links($note)); |
|
378 | 378 | |
379 | 379 | /** |
380 | 380 | * Filter order note object returned from the REST API. |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @param WP_Comment $note Order note object used to create response. |
384 | 384 | * @param \WP_REST_Request $request Request object. |
385 | 385 | */ |
386 | - return apply_filters( 'woocommerce_rest_prepare_order_note', $response, $note, $request ); |
|
386 | + return apply_filters('woocommerce_rest_prepare_order_note', $response, $note, $request); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -392,18 +392,18 @@ discard block |
||
392 | 392 | * @param WP_Comment $note Delivery order_note object. |
393 | 393 | * @return array Links for the given order note. |
394 | 394 | */ |
395 | - protected function prepare_links( $note ) { |
|
395 | + protected function prepare_links($note) { |
|
396 | 396 | $order_id = (int) $note->comment_post_ID; |
397 | - $base = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base ); |
|
397 | + $base = str_replace('(?P<order_id>[\d]+)', $order_id, $this->rest_base); |
|
398 | 398 | $links = array( |
399 | 399 | 'self' => array( |
400 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $note->comment_ID ) ), |
|
400 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $note->comment_ID)), |
|
401 | 401 | ), |
402 | 402 | 'collection' => array( |
403 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
403 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
404 | 404 | ), |
405 | 405 | 'up' => array( |
406 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ), |
|
406 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order_id)), |
|
407 | 407 | ), |
408 | 408 | ); |
409 | 409 | |
@@ -422,50 +422,50 @@ discard block |
||
422 | 422 | 'type' => 'object', |
423 | 423 | 'properties' => array( |
424 | 424 | 'id' => array( |
425 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
425 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
426 | 426 | 'type' => 'integer', |
427 | - 'context' => array( 'view', 'edit' ), |
|
427 | + 'context' => array('view', 'edit'), |
|
428 | 428 | 'readonly' => true, |
429 | 429 | ), |
430 | 430 | 'author' => array( |
431 | - 'description' => __( 'Order note author.', 'woocommerce' ), |
|
431 | + 'description' => __('Order note author.', 'woocommerce'), |
|
432 | 432 | 'type' => 'string', |
433 | - 'context' => array( 'view', 'edit' ), |
|
433 | + 'context' => array('view', 'edit'), |
|
434 | 434 | 'readonly' => true, |
435 | 435 | ), |
436 | 436 | 'date_created' => array( |
437 | - 'description' => __( "The date the order note was created, in the site's timezone.", 'woocommerce' ), |
|
437 | + 'description' => __("The date the order note was created, in the site's timezone.", 'woocommerce'), |
|
438 | 438 | 'type' => 'date-time', |
439 | - 'context' => array( 'view', 'edit' ), |
|
439 | + 'context' => array('view', 'edit'), |
|
440 | 440 | 'readonly' => true, |
441 | 441 | ), |
442 | 442 | 'date_created_gmt' => array( |
443 | - 'description' => __( 'The date the order note was created, as GMT.', 'woocommerce' ), |
|
443 | + 'description' => __('The date the order note was created, as GMT.', 'woocommerce'), |
|
444 | 444 | 'type' => 'date-time', |
445 | - 'context' => array( 'view', 'edit' ), |
|
445 | + 'context' => array('view', 'edit'), |
|
446 | 446 | 'readonly' => true, |
447 | 447 | ), |
448 | 448 | 'note' => array( |
449 | - 'description' => __( 'Order note content.', 'woocommerce' ), |
|
449 | + 'description' => __('Order note content.', 'woocommerce'), |
|
450 | 450 | 'type' => 'string', |
451 | - 'context' => array( 'view', 'edit' ), |
|
451 | + 'context' => array('view', 'edit'), |
|
452 | 452 | ), |
453 | 453 | 'customer_note' => array( |
454 | - 'description' => __( 'If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce' ), |
|
454 | + 'description' => __('If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.', 'woocommerce'), |
|
455 | 455 | 'type' => 'boolean', |
456 | 456 | 'default' => false, |
457 | - 'context' => array( 'view', 'edit' ), |
|
457 | + 'context' => array('view', 'edit'), |
|
458 | 458 | ), |
459 | 459 | 'added_by_user' => array( |
460 | - 'description' => __( 'If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce' ), |
|
460 | + 'description' => __('If true, this note will be attributed to the current user. If false, the note will be attributed to the system.', 'woocommerce'), |
|
461 | 461 | 'type' => 'boolean', |
462 | 462 | 'default' => false, |
463 | - 'context' => array( 'edit' ), |
|
463 | + 'context' => array('edit'), |
|
464 | 464 | ), |
465 | 465 | ), |
466 | 466 | ); |
467 | 467 | |
468 | - return $this->add_additional_fields_schema( $schema ); |
|
468 | + return $this->add_additional_fields_schema($schema); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
@@ -475,12 +475,12 @@ discard block |
||
475 | 475 | */ |
476 | 476 | public function get_collection_params() { |
477 | 477 | $params = array(); |
478 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
478 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
479 | 479 | $params['type'] = array( |
480 | 480 | 'default' => 'any', |
481 | - 'description' => __( 'Limit result to customers or internal notes.', 'woocommerce' ), |
|
481 | + 'description' => __('Limit result to customers or internal notes.', 'woocommerce'), |
|
482 | 482 | 'type' => 'string', |
483 | - 'enum' => array( 'any', 'customer', 'internal' ), |
|
483 | + 'enum' => array('any', 'customer', 'internal'), |
|
484 | 484 | 'sanitize_callback' => 'sanitize_key', |
485 | 485 | 'validate_callback' => 'rest_validate_request_arg', |
486 | 486 | ); |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | namespace WooCommerce\RestApi\Controllers\Version4; |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * REST API Customer Downloads controller class. |
@@ -33,17 +33,17 @@ discard block |
||
33 | 33 | array( |
34 | 34 | 'args' => array( |
35 | 35 | 'customer_id' => array( |
36 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
36 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
37 | 37 | 'type' => 'integer', |
38 | 38 | ), |
39 | 39 | ), |
40 | 40 | array( |
41 | 41 | 'methods' => \WP_REST_Server::READABLE, |
42 | - 'callback' => array( $this, 'get_items' ), |
|
43 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
42 | + 'callback' => array($this, 'get_items'), |
|
43 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
44 | 44 | 'args' => $this->get_collection_params(), |
45 | 45 | ), |
46 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
46 | + 'schema' => array($this, 'get_public_item_schema'), |
|
47 | 47 | ), |
48 | 48 | true |
49 | 49 | ); |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | * @param \WP_REST_Request $request Full details about the request. |
56 | 56 | * @return \WP_Error|boolean |
57 | 57 | */ |
58 | - public function get_items_permissions_check( $request ) { |
|
59 | - $customer = get_user_by( 'id', (int) $request['customer_id'] ); |
|
58 | + public function get_items_permissions_check($request) { |
|
59 | + $customer = get_user_by('id', (int) $request['customer_id']); |
|
60 | 60 | |
61 | - if ( ! $customer ) { |
|
62 | - return new \WP_Error( 'woocommerce_rest_customer_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
61 | + if ( ! $customer) { |
|
62 | + return new \WP_Error('woocommerce_rest_customer_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
63 | 63 | } |
64 | 64 | |
65 | - if ( ! wc_rest_check_user_permissions( 'read', $customer->get_id() ) ) { |
|
66 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
65 | + if ( ! wc_rest_check_user_permissions('read', $customer->get_id())) { |
|
66 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | return true; |
@@ -75,17 +75,17 @@ discard block |
||
75 | 75 | * @param \WP_REST_Request $request Request params. |
76 | 76 | * @return array |
77 | 77 | */ |
78 | - public function get_items( $request ) { |
|
79 | - $downloads = wc_get_customer_available_downloads( (int) $request['customer_id'] ); |
|
78 | + public function get_items($request) { |
|
79 | + $downloads = wc_get_customer_available_downloads((int) $request['customer_id']); |
|
80 | 80 | |
81 | 81 | $data = array(); |
82 | - foreach ( $downloads as $download_data ) { |
|
83 | - $download = $this->prepare_item_for_response( (object) $download_data, $request ); |
|
84 | - $download = $this->prepare_response_for_collection( $download ); |
|
82 | + foreach ($downloads as $download_data) { |
|
83 | + $download = $this->prepare_item_for_response((object) $download_data, $request); |
|
84 | + $download = $this->prepare_response_for_collection($download); |
|
85 | 85 | $data[] = $download; |
86 | 86 | } |
87 | 87 | |
88 | - return rest_ensure_response( $data ); |
|
88 | + return rest_ensure_response($data); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param \WP_REST_Request $request Request object. |
96 | 96 | * @return \WP_REST_Response $response Response data. |
97 | 97 | */ |
98 | - public function prepare_item_for_response( $download, $request ) { |
|
98 | + public function prepare_item_for_response($download, $request) { |
|
99 | 99 | $data = array( |
100 | 100 | 'download_id' => $download->download_id, |
101 | 101 | 'download_url' => $download->download_url, |
@@ -105,19 +105,19 @@ discard block |
||
105 | 105 | 'order_id' => $download->order_id, |
106 | 106 | 'order_key' => $download->order_key, |
107 | 107 | 'downloads_remaining' => '' === $download->downloads_remaining ? 'unlimited' : $download->downloads_remaining, |
108 | - 'access_expires' => $download->access_expires ? wc_rest_prepare_date_response( $download->access_expires ) : 'never', |
|
109 | - 'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response( get_gmt_from_date( $download->access_expires ) ) : 'never', |
|
108 | + 'access_expires' => $download->access_expires ? wc_rest_prepare_date_response($download->access_expires) : 'never', |
|
109 | + 'access_expires_gmt' => $download->access_expires ? wc_rest_prepare_date_response(get_gmt_from_date($download->access_expires)) : 'never', |
|
110 | 110 | 'file' => $download->file, |
111 | 111 | ); |
112 | 112 | |
113 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
114 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
115 | - $data = $this->filter_response_by_context( $data, $context ); |
|
113 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
114 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
115 | + $data = $this->filter_response_by_context($data, $context); |
|
116 | 116 | |
117 | 117 | // Wrap the data in a response object. |
118 | - $response = rest_ensure_response( $data ); |
|
118 | + $response = rest_ensure_response($data); |
|
119 | 119 | |
120 | - $response->add_links( $this->prepare_links( $download, $request ) ); |
|
120 | + $response->add_links($this->prepare_links($download, $request)); |
|
121 | 121 | |
122 | 122 | /** |
123 | 123 | * Filter customer download data returned from the REST API. |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param stdClass $download Download object used to create response. |
127 | 127 | * @param \WP_REST_Request $request Request object. |
128 | 128 | */ |
129 | - return apply_filters( 'woocommerce_rest_prepare_customer_download', $response, $download, $request ); |
|
129 | + return apply_filters('woocommerce_rest_prepare_customer_download', $response, $download, $request); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -136,17 +136,17 @@ discard block |
||
136 | 136 | * @param \WP_REST_Request $request Request object. |
137 | 137 | * @return array Links for the given customer download. |
138 | 138 | */ |
139 | - protected function prepare_links( $download, $request ) { |
|
140 | - $base = str_replace( '(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base ); |
|
139 | + protected function prepare_links($download, $request) { |
|
140 | + $base = str_replace('(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base); |
|
141 | 141 | $links = array( |
142 | 142 | 'collection' => array( |
143 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
143 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
144 | 144 | ), |
145 | 145 | 'product' => array( |
146 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $download->product_id ) ), |
|
146 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $download->product_id)), |
|
147 | 147 | ), |
148 | 148 | 'order' => array( |
149 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $download->order_id ) ), |
|
149 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $download->order_id)), |
|
150 | 150 | ), |
151 | 151 | ); |
152 | 152 | |
@@ -165,81 +165,81 @@ discard block |
||
165 | 165 | 'type' => 'object', |
166 | 166 | 'properties' => array( |
167 | 167 | 'download_id' => array( |
168 | - 'description' => __( 'Download ID.', 'woocommerce' ), |
|
168 | + 'description' => __('Download ID.', 'woocommerce'), |
|
169 | 169 | 'type' => 'string', |
170 | - 'context' => array( 'view' ), |
|
170 | + 'context' => array('view'), |
|
171 | 171 | 'readonly' => true, |
172 | 172 | ), |
173 | 173 | 'download_url' => array( |
174 | - 'description' => __( 'Download file URL.', 'woocommerce' ), |
|
174 | + 'description' => __('Download file URL.', 'woocommerce'), |
|
175 | 175 | 'type' => 'string', |
176 | - 'context' => array( 'view' ), |
|
176 | + 'context' => array('view'), |
|
177 | 177 | 'readonly' => true, |
178 | 178 | ), |
179 | 179 | 'product_id' => array( |
180 | - 'description' => __( 'Downloadable product ID.', 'woocommerce' ), |
|
180 | + 'description' => __('Downloadable product ID.', 'woocommerce'), |
|
181 | 181 | 'type' => 'integer', |
182 | - 'context' => array( 'view' ), |
|
182 | + 'context' => array('view'), |
|
183 | 183 | 'readonly' => true, |
184 | 184 | ), |
185 | 185 | 'product_name' => array( |
186 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
186 | + 'description' => __('Product name.', 'woocommerce'), |
|
187 | 187 | 'type' => 'string', |
188 | - 'context' => array( 'view' ), |
|
188 | + 'context' => array('view'), |
|
189 | 189 | 'readonly' => true, |
190 | 190 | ), |
191 | 191 | 'download_name' => array( |
192 | - 'description' => __( 'Downloadable file name.', 'woocommerce' ), |
|
192 | + 'description' => __('Downloadable file name.', 'woocommerce'), |
|
193 | 193 | 'type' => 'string', |
194 | - 'context' => array( 'view' ), |
|
194 | + 'context' => array('view'), |
|
195 | 195 | 'readonly' => true, |
196 | 196 | ), |
197 | 197 | 'order_id' => array( |
198 | - 'description' => __( 'Order ID.', 'woocommerce' ), |
|
198 | + 'description' => __('Order ID.', 'woocommerce'), |
|
199 | 199 | 'type' => 'integer', |
200 | - 'context' => array( 'view' ), |
|
200 | + 'context' => array('view'), |
|
201 | 201 | 'readonly' => true, |
202 | 202 | ), |
203 | 203 | 'order_key' => array( |
204 | - 'description' => __( 'Order key.', 'woocommerce' ), |
|
204 | + 'description' => __('Order key.', 'woocommerce'), |
|
205 | 205 | 'type' => 'string', |
206 | - 'context' => array( 'view' ), |
|
206 | + 'context' => array('view'), |
|
207 | 207 | 'readonly' => true, |
208 | 208 | ), |
209 | 209 | 'downloads_remaining' => array( |
210 | - 'description' => __( 'Number of downloads remaining.', 'woocommerce' ), |
|
210 | + 'description' => __('Number of downloads remaining.', 'woocommerce'), |
|
211 | 211 | 'type' => 'string', |
212 | - 'context' => array( 'view' ), |
|
212 | + 'context' => array('view'), |
|
213 | 213 | 'readonly' => true, |
214 | 214 | ), |
215 | 215 | 'access_expires' => array( |
216 | - 'description' => __( "The date when download access expires, in the site's timezone.", 'woocommerce' ), |
|
216 | + 'description' => __("The date when download access expires, in the site's timezone.", 'woocommerce'), |
|
217 | 217 | 'type' => 'string', |
218 | - 'context' => array( 'view' ), |
|
218 | + 'context' => array('view'), |
|
219 | 219 | 'readonly' => true, |
220 | 220 | ), |
221 | 221 | 'access_expires_gmt' => array( |
222 | - 'description' => __( 'The date when download access expires, as GMT.', 'woocommerce' ), |
|
222 | + 'description' => __('The date when download access expires, as GMT.', 'woocommerce'), |
|
223 | 223 | 'type' => 'string', |
224 | - 'context' => array( 'view' ), |
|
224 | + 'context' => array('view'), |
|
225 | 225 | 'readonly' => true, |
226 | 226 | ), |
227 | 227 | 'file' => array( |
228 | - 'description' => __( 'File details.', 'woocommerce' ), |
|
228 | + 'description' => __('File details.', 'woocommerce'), |
|
229 | 229 | 'type' => 'object', |
230 | - 'context' => array( 'view' ), |
|
230 | + 'context' => array('view'), |
|
231 | 231 | 'readonly' => true, |
232 | 232 | 'properties' => array( |
233 | 233 | 'name' => array( |
234 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
234 | + 'description' => __('File name.', 'woocommerce'), |
|
235 | 235 | 'type' => 'string', |
236 | - 'context' => array( 'view' ), |
|
236 | + 'context' => array('view'), |
|
237 | 237 | 'readonly' => true, |
238 | 238 | ), |
239 | 239 | 'file' => array( |
240 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
240 | + 'description' => __('File URL.', 'woocommerce'), |
|
241 | 241 | 'type' => 'string', |
242 | - 'context' => array( 'view' ), |
|
242 | + 'context' => array('view'), |
|
243 | 243 | 'readonly' => true, |
244 | 244 | ), |
245 | 245 | ), |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | ), |
248 | 248 | ); |
249 | 249 | |
250 | - return $this->add_additional_fields_schema( $schema ); |
|
250 | + return $this->add_additional_fields_schema($schema); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function get_collection_params() { |
259 | 259 | return array( |
260 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
260 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
261 | 261 | ); |
262 | 262 | } |
263 | 263 | } |