@@ -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 | * Shipping methods 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 | ); |
@@ -47,19 +47,19 @@ discard block |
||
47 | 47 | array( |
48 | 48 | 'args' => array( |
49 | 49 | 'id' => array( |
50 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
50 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
51 | 51 | 'type' => 'string', |
52 | 52 | ), |
53 | 53 | ), |
54 | 54 | array( |
55 | 55 | 'methods' => \WP_REST_Server::READABLE, |
56 | - 'callback' => array( $this, 'get_item' ), |
|
57 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
56 | + 'callback' => array($this, 'get_item'), |
|
57 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
58 | 58 | 'args' => array( |
59 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
59 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
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 | ); |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * @param \WP_REST_Request $request Full details about the request. |
72 | 72 | * @return \WP_Error|boolean |
73 | 73 | */ |
74 | - public function get_items_permissions_check( $request ) { |
|
75 | - if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { |
|
76 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
74 | + public function get_items_permissions_check($request) { |
|
75 | + if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) { |
|
76 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
77 | 77 | } |
78 | 78 | return true; |
79 | 79 | } |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * @param \WP_REST_Request $request Full details about the request. |
85 | 85 | * @return \WP_Error|boolean |
86 | 86 | */ |
87 | - public function get_item_permissions_check( $request ) { |
|
88 | - if ( ! wc_rest_check_manager_permissions( 'shipping_methods', 'read' ) ) { |
|
89 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
87 | + public function get_item_permissions_check($request) { |
|
88 | + if ( ! wc_rest_check_manager_permissions('shipping_methods', 'read')) { |
|
89 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
90 | 90 | } |
91 | 91 | return true; |
92 | 92 | } |
@@ -97,15 +97,15 @@ discard block |
||
97 | 97 | * @param \WP_REST_Request $request Full details about the request. |
98 | 98 | * @return \WP_Error\WP_REST_Response |
99 | 99 | */ |
100 | - public function get_items( $request ) { |
|
100 | + public function get_items($request) { |
|
101 | 101 | $wc_shipping = \WC_Shipping::instance(); |
102 | 102 | $response = array(); |
103 | - foreach ( $wc_shipping->get_shipping_methods() as $id => $shipping_method ) { |
|
104 | - $method = $this->prepare_item_for_response( $shipping_method, $request ); |
|
105 | - $method = $this->prepare_response_for_collection( $method ); |
|
103 | + foreach ($wc_shipping->get_shipping_methods() as $id => $shipping_method) { |
|
104 | + $method = $this->prepare_item_for_response($shipping_method, $request); |
|
105 | + $method = $this->prepare_response_for_collection($method); |
|
106 | 106 | $response[] = $method; |
107 | 107 | } |
108 | - return rest_ensure_response( $response ); |
|
108 | + return rest_ensure_response($response); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -114,17 +114,17 @@ discard block |
||
114 | 114 | * @param \WP_REST_Request $request Request data. |
115 | 115 | * @return \WP_REST_Response|\WP_Error |
116 | 116 | */ |
117 | - public function get_item( $request ) { |
|
117 | + public function get_item($request) { |
|
118 | 118 | $wc_shipping = \WC_Shipping::instance(); |
119 | 119 | $methods = $wc_shipping->get_shipping_methods(); |
120 | - if ( empty( $methods[ $request['id'] ] ) ) { |
|
121 | - return new \WP_Error( 'woocommerce_rest_shipping_method_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
120 | + if (empty($methods[$request['id']])) { |
|
121 | + return new \WP_Error('woocommerce_rest_shipping_method_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
122 | 122 | } |
123 | 123 | |
124 | - $method = $methods[ $request['id'] ]; |
|
125 | - $response = $this->prepare_item_for_response( $method, $request ); |
|
124 | + $method = $methods[$request['id']]; |
|
125 | + $response = $this->prepare_item_for_response($method, $request); |
|
126 | 126 | |
127 | - return rest_ensure_response( $response ); |
|
127 | + return rest_ensure_response($response); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -134,21 +134,21 @@ discard block |
||
134 | 134 | * @param \WP_REST_Request $request Request object. |
135 | 135 | * @return \WP_REST_Response $response Response data. |
136 | 136 | */ |
137 | - public function prepare_item_for_response( $method, $request ) { |
|
137 | + public function prepare_item_for_response($method, $request) { |
|
138 | 138 | $data = array( |
139 | 139 | 'id' => $method->id, |
140 | 140 | 'title' => $method->method_title, |
141 | 141 | 'description' => $method->method_description, |
142 | 142 | ); |
143 | 143 | |
144 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
145 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
146 | - $data = $this->filter_response_by_context( $data, $context ); |
|
144 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
145 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
146 | + $data = $this->filter_response_by_context($data, $context); |
|
147 | 147 | |
148 | 148 | // Wrap the data in a response object. |
149 | - $response = rest_ensure_response( $data ); |
|
149 | + $response = rest_ensure_response($data); |
|
150 | 150 | |
151 | - $response->add_links( $this->prepare_links( $method, $request ) ); |
|
151 | + $response->add_links($this->prepare_links($method, $request)); |
|
152 | 152 | |
153 | 153 | /** |
154 | 154 | * Filter shipping methods object returned from the REST API. |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param WC_Shipping_Method $method Shipping method object used to create response. |
158 | 158 | * @param \WP_REST_Request $request Request object. |
159 | 159 | */ |
160 | - return apply_filters( 'woocommerce_rest_prepare_shipping_method', $response, $method, $request ); |
|
160 | + return apply_filters('woocommerce_rest_prepare_shipping_method', $response, $method, $request); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -167,13 +167,13 @@ discard block |
||
167 | 167 | * @param \WP_REST_Request $request Request object. |
168 | 168 | * @return array |
169 | 169 | */ |
170 | - protected function prepare_links( $method, $request ) { |
|
170 | + protected function prepare_links($method, $request) { |
|
171 | 171 | $links = array( |
172 | 172 | 'self' => array( |
173 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $method->id ) ), |
|
173 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $method->id)), |
|
174 | 174 | ), |
175 | 175 | 'collection' => array( |
176 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
176 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
177 | 177 | ), |
178 | 178 | ); |
179 | 179 | |
@@ -192,27 +192,27 @@ discard block |
||
192 | 192 | 'type' => 'object', |
193 | 193 | 'properties' => array( |
194 | 194 | 'id' => array( |
195 | - 'description' => __( 'Method ID.', 'woocommerce' ), |
|
195 | + 'description' => __('Method ID.', 'woocommerce'), |
|
196 | 196 | 'type' => 'string', |
197 | - 'context' => array( 'view' ), |
|
197 | + 'context' => array('view'), |
|
198 | 198 | 'readonly' => true, |
199 | 199 | ), |
200 | 200 | 'title' => array( |
201 | - 'description' => __( 'Shipping method title.', 'woocommerce' ), |
|
201 | + 'description' => __('Shipping method title.', 'woocommerce'), |
|
202 | 202 | 'type' => 'string', |
203 | - 'context' => array( 'view' ), |
|
203 | + 'context' => array('view'), |
|
204 | 204 | 'readonly' => true, |
205 | 205 | ), |
206 | 206 | 'description' => array( |
207 | - 'description' => __( 'Shipping method description.', 'woocommerce' ), |
|
207 | + 'description' => __('Shipping method description.', 'woocommerce'), |
|
208 | 208 | 'type' => 'string', |
209 | - 'context' => array( 'view' ), |
|
209 | + 'context' => array('view'), |
|
210 | 210 | 'readonly' => true, |
211 | 211 | ), |
212 | 212 | ), |
213 | 213 | ); |
214 | 214 | |
215 | - return $this->add_additional_fields_schema( $schema ); |
|
215 | + return $this->add_additional_fields_schema($schema); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function get_collection_params() { |
224 | 224 | return array( |
225 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
225 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
226 | 226 | ); |
227 | 227 | } |
228 | 228 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | namespace WooCommerce\RestApi\Controllers\Version4; |
17 | 17 | |
18 | -defined( 'ABSPATH' ) || exit; |
|
18 | +defined('ABSPATH') || exit; |
|
19 | 19 | |
20 | 20 | use \WP_REST_Controller; |
21 | 21 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - protected function add_additional_fields_schema( $schema ) { |
|
55 | - if ( empty( $schema['title'] ) ) { |
|
54 | + protected function add_additional_fields_schema($schema) { |
|
55 | + if (empty($schema['title'])) { |
|
56 | 56 | return $schema; |
57 | 57 | } |
58 | 58 | |
@@ -61,17 +61,17 @@ discard block |
||
61 | 61 | */ |
62 | 62 | $object_type = $schema['title']; |
63 | 63 | |
64 | - $additional_fields = $this->get_additional_fields( $object_type ); |
|
64 | + $additional_fields = $this->get_additional_fields($object_type); |
|
65 | 65 | |
66 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
67 | - if ( ! $field_options['schema'] ) { |
|
66 | + foreach ($additional_fields as $field_name => $field_options) { |
|
67 | + if ( ! $field_options['schema']) { |
|
68 | 68 | continue; |
69 | 69 | } |
70 | 70 | |
71 | - $schema['properties'][ $field_name ] = $field_options['schema']; |
|
71 | + $schema['properties'][$field_name] = $field_options['schema']; |
|
72 | 72 | } |
73 | 73 | |
74 | - $schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] ); |
|
74 | + $schema['properties'] = apply_filters('woocommerce_rest_' . $object_type . '_schema', $schema['properties']); |
|
75 | 75 | |
76 | 76 | return $schema; |
77 | 77 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @return string |
83 | 83 | */ |
84 | 84 | protected function get_normalized_rest_base() { |
85 | - return preg_replace( '/\(.*\)\//i', '', $this->rest_base ); |
|
85 | + return preg_replace('/\(.*\)\//i', '', $this->rest_base); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -91,25 +91,25 @@ discard block |
||
91 | 91 | * @param array $items Request items. |
92 | 92 | * @return bool|\WP_Error |
93 | 93 | */ |
94 | - protected function check_batch_limit( $items ) { |
|
95 | - $limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() ); |
|
94 | + protected function check_batch_limit($items) { |
|
95 | + $limit = apply_filters('woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base()); |
|
96 | 96 | $total = 0; |
97 | 97 | |
98 | - if ( ! empty( $items['create'] ) ) { |
|
99 | - $total += count( $items['create'] ); |
|
98 | + if ( ! empty($items['create'])) { |
|
99 | + $total += count($items['create']); |
|
100 | 100 | } |
101 | 101 | |
102 | - if ( ! empty( $items['update'] ) ) { |
|
103 | - $total += count( $items['update'] ); |
|
102 | + if ( ! empty($items['update'])) { |
|
103 | + $total += count($items['update']); |
|
104 | 104 | } |
105 | 105 | |
106 | - if ( ! empty( $items['delete'] ) ) { |
|
107 | - $total += count( $items['delete'] ); |
|
106 | + if ( ! empty($items['delete'])) { |
|
107 | + $total += count($items['delete']); |
|
108 | 108 | } |
109 | 109 | |
110 | - if ( $total > $limit ) { |
|
110 | + if ($total > $limit) { |
|
111 | 111 | /* translators: %s: items limit */ |
112 | - return new \WP_Error( 'woocommerce_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'woocommerce' ), $limit ), array( 'status' => 413 ) ); |
|
112 | + return new \WP_Error('woocommerce_rest_request_entity_too_large', sprintf(__('Unable to accept more than %s items for this request.', 'woocommerce'), $limit), array('status' => 413)); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return true; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @param \WP_REST_Request $request Full details about the request. |
122 | 122 | * @return array Of \WP_Error or \WP_REST_Response. |
123 | 123 | */ |
124 | - public function batch_items( $request ) { |
|
124 | + public function batch_items($request) { |
|
125 | 125 | /** |
126 | 126 | * REST Server |
127 | 127 | * |
@@ -130,34 +130,34 @@ discard block |
||
130 | 130 | global $wp_rest_server; |
131 | 131 | |
132 | 132 | // Get the request params. |
133 | - $items = array_filter( $request->get_params() ); |
|
133 | + $items = array_filter($request->get_params()); |
|
134 | 134 | $response = array(); |
135 | 135 | |
136 | 136 | // Check batch limit. |
137 | - $limit = $this->check_batch_limit( $items ); |
|
138 | - if ( is_wp_error( $limit ) ) { |
|
137 | + $limit = $this->check_batch_limit($items); |
|
138 | + if (is_wp_error($limit)) { |
|
139 | 139 | return $limit; |
140 | 140 | } |
141 | 141 | |
142 | - if ( ! empty( $items['create'] ) ) { |
|
143 | - foreach ( $items['create'] as $item ) { |
|
144 | - $_item = new \WP_REST_Request( 'POST' ); |
|
142 | + if ( ! empty($items['create'])) { |
|
143 | + foreach ($items['create'] as $item) { |
|
144 | + $_item = new \WP_REST_Request('POST'); |
|
145 | 145 | |
146 | 146 | // Default parameters. |
147 | 147 | $defaults = array(); |
148 | 148 | $schema = $this->get_public_item_schema(); |
149 | - foreach ( $schema['properties'] as $arg => $options ) { |
|
150 | - if ( isset( $options['default'] ) ) { |
|
151 | - $defaults[ $arg ] = $options['default']; |
|
149 | + foreach ($schema['properties'] as $arg => $options) { |
|
150 | + if (isset($options['default'])) { |
|
151 | + $defaults[$arg] = $options['default']; |
|
152 | 152 | } |
153 | 153 | } |
154 | - $_item->set_default_params( $defaults ); |
|
154 | + $_item->set_default_params($defaults); |
|
155 | 155 | |
156 | 156 | // Set request parameters. |
157 | - $_item->set_body_params( $item ); |
|
158 | - $_response = $this->create_item( $_item ); |
|
157 | + $_item->set_body_params($item); |
|
158 | + $_response = $this->create_item($_item); |
|
159 | 159 | |
160 | - if ( is_wp_error( $_response ) ) { |
|
160 | + if (is_wp_error($_response)) { |
|
161 | 161 | $response['create'][] = array( |
162 | 162 | 'id' => 0, |
163 | 163 | 'error' => array( |
@@ -167,18 +167,18 @@ discard block |
||
167 | 167 | ), |
168 | 168 | ); |
169 | 169 | } else { |
170 | - $response['create'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
170 | + $response['create'][] = $wp_rest_server->response_to_data($_response, ''); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | - if ( ! empty( $items['update'] ) ) { |
|
176 | - foreach ( $items['update'] as $item ) { |
|
177 | - $_item = new \WP_REST_Request( 'PUT' ); |
|
178 | - $_item->set_body_params( $item ); |
|
179 | - $_response = $this->update_item( $_item ); |
|
175 | + if ( ! empty($items['update'])) { |
|
176 | + foreach ($items['update'] as $item) { |
|
177 | + $_item = new \WP_REST_Request('PUT'); |
|
178 | + $_item->set_body_params($item); |
|
179 | + $_response = $this->update_item($_item); |
|
180 | 180 | |
181 | - if ( is_wp_error( $_response ) ) { |
|
181 | + if (is_wp_error($_response)) { |
|
182 | 182 | $response['update'][] = array( |
183 | 183 | 'id' => $item['id'], |
184 | 184 | 'error' => array( |
@@ -188,29 +188,29 @@ discard block |
||
188 | 188 | ), |
189 | 189 | ); |
190 | 190 | } else { |
191 | - $response['update'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
191 | + $response['update'][] = $wp_rest_server->response_to_data($_response, ''); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - if ( ! empty( $items['delete'] ) ) { |
|
197 | - foreach ( $items['delete'] as $id ) { |
|
196 | + if ( ! empty($items['delete'])) { |
|
197 | + foreach ($items['delete'] as $id) { |
|
198 | 198 | $id = (int) $id; |
199 | 199 | |
200 | - if ( 0 === $id ) { |
|
200 | + if (0 === $id) { |
|
201 | 201 | continue; |
202 | 202 | } |
203 | 203 | |
204 | - $_item = new \WP_REST_Request( 'DELETE' ); |
|
204 | + $_item = new \WP_REST_Request('DELETE'); |
|
205 | 205 | $_item->set_query_params( |
206 | 206 | array( |
207 | 207 | 'id' => $id, |
208 | 208 | 'force' => true, |
209 | 209 | ) |
210 | 210 | ); |
211 | - $_response = $this->delete_item( $_item ); |
|
211 | + $_response = $this->delete_item($_item); |
|
212 | 212 | |
213 | - if ( is_wp_error( $_response ) ) { |
|
213 | + if (is_wp_error($_response)) { |
|
214 | 214 | $response['delete'][] = array( |
215 | 215 | 'id' => $id, |
216 | 216 | 'error' => array( |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | ), |
221 | 221 | ); |
222 | 222 | } else { |
223 | - $response['delete'][] = $wp_rest_server->response_to_data( $_response, '' ); |
|
223 | + $response['delete'][] = $wp_rest_server->response_to_data($_response, ''); |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | } |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | * @param array $setting Setting. |
237 | 237 | * @return string |
238 | 238 | */ |
239 | - public function validate_setting_text_field( $value, $setting ) { |
|
240 | - $value = is_null( $value ) ? '' : $value; |
|
241 | - return wp_kses_post( trim( stripslashes( $value ) ) ); |
|
239 | + public function validate_setting_text_field($value, $setting) { |
|
240 | + $value = is_null($value) ? '' : $value; |
|
241 | + return wp_kses_post(trim(stripslashes($value))); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -249,11 +249,11 @@ discard block |
||
249 | 249 | * @param array $setting Setting. |
250 | 250 | * @return string|\WP_Error |
251 | 251 | */ |
252 | - public function validate_setting_select_field( $value, $setting ) { |
|
253 | - if ( array_key_exists( $value, $setting['options'] ) ) { |
|
252 | + public function validate_setting_select_field($value, $setting) { |
|
253 | + if (array_key_exists($value, $setting['options'])) { |
|
254 | 254 | return $value; |
255 | 255 | } else { |
256 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
256 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
@@ -265,18 +265,18 @@ discard block |
||
265 | 265 | * @param array $setting Setting. |
266 | 266 | * @return array|\WP_Error |
267 | 267 | */ |
268 | - public function validate_setting_multiselect_field( $values, $setting ) { |
|
269 | - if ( empty( $values ) ) { |
|
268 | + public function validate_setting_multiselect_field($values, $setting) { |
|
269 | + if (empty($values)) { |
|
270 | 270 | return array(); |
271 | 271 | } |
272 | 272 | |
273 | - if ( ! is_array( $values ) ) { |
|
274 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
273 | + if ( ! is_array($values)) { |
|
274 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | $final_values = array(); |
278 | - foreach ( $values as $value ) { |
|
279 | - if ( array_key_exists( $value, $setting['options'] ) ) { |
|
278 | + foreach ($values as $value) { |
|
279 | + if (array_key_exists($value, $setting['options'])) { |
|
280 | 280 | $final_values[] = $value; |
281 | 281 | } |
282 | 282 | } |
@@ -292,19 +292,19 @@ discard block |
||
292 | 292 | * @param array $setting Setting. |
293 | 293 | * @return string|\WP_Error |
294 | 294 | */ |
295 | - public function validate_setting_image_width_field( $values, $setting ) { |
|
296 | - if ( ! is_array( $values ) ) { |
|
297 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
295 | + public function validate_setting_image_width_field($values, $setting) { |
|
296 | + if ( ! is_array($values)) { |
|
297 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | $current = $setting['value']; |
301 | - if ( isset( $values['width'] ) ) { |
|
302 | - $current['width'] = intval( $values['width'] ); |
|
301 | + if (isset($values['width'])) { |
|
302 | + $current['width'] = intval($values['width']); |
|
303 | 303 | } |
304 | - if ( isset( $values['height'] ) ) { |
|
305 | - $current['height'] = intval( $values['height'] ); |
|
304 | + if (isset($values['height'])) { |
|
305 | + $current['height'] = intval($values['height']); |
|
306 | 306 | } |
307 | - if ( isset( $values['crop'] ) ) { |
|
307 | + if (isset($values['crop'])) { |
|
308 | 308 | $current['crop'] = (bool) $values['crop']; |
309 | 309 | } |
310 | 310 | return $current; |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | * @param array $setting Setting. |
319 | 319 | * @return string|\WP_Error |
320 | 320 | */ |
321 | - public function validate_setting_radio_field( $value, $setting ) { |
|
322 | - return $this->validate_setting_select_field( $value, $setting ); |
|
321 | + public function validate_setting_radio_field($value, $setting) { |
|
322 | + return $this->validate_setting_select_field($value, $setting); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -330,14 +330,14 @@ discard block |
||
330 | 330 | * @param array $setting Setting. |
331 | 331 | * @return string|\WP_Error |
332 | 332 | */ |
333 | - public function validate_setting_checkbox_field( $value, $setting ) { |
|
334 | - if ( in_array( $value, array( 'yes', 'no' ) ) ) { |
|
333 | + public function validate_setting_checkbox_field($value, $setting) { |
|
334 | + if (in_array($value, array('yes', 'no'))) { |
|
335 | 335 | return $value; |
336 | - } elseif ( empty( $value ) ) { |
|
337 | - $value = isset( $setting['default'] ) ? $setting['default'] : 'no'; |
|
336 | + } elseif (empty($value)) { |
|
337 | + $value = isset($setting['default']) ? $setting['default'] : 'no'; |
|
338 | 338 | return $value; |
339 | 339 | } else { |
340 | - return new \WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
340 | + return new \WP_Error('rest_setting_value_invalid', __('An invalid setting value was passed.', 'woocommerce'), array('status' => 400)); |
|
341 | 341 | } |
342 | 342 | } |
343 | 343 | |
@@ -349,10 +349,10 @@ discard block |
||
349 | 349 | * @param array $setting Setting. |
350 | 350 | * @return string |
351 | 351 | */ |
352 | - public function validate_setting_textarea_field( $value, $setting ) { |
|
353 | - $value = is_null( $value ) ? '' : $value; |
|
352 | + public function validate_setting_textarea_field($value, $setting) { |
|
353 | + $value = is_null($value) ? '' : $value; |
|
354 | 354 | return wp_kses( |
355 | - trim( stripslashes( $value ) ), |
|
355 | + trim(stripslashes($value)), |
|
356 | 356 | array_merge( |
357 | 357 | array( |
358 | 358 | 'iframe' => array( |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | 'class' => true, |
363 | 363 | ), |
364 | 364 | ), |
365 | - wp_kses_allowed_html( 'post' ) |
|
365 | + wp_kses_allowed_html('post') |
|
366 | 366 | ) |
367 | 367 | ); |
368 | 368 | } |
@@ -375,8 +375,8 @@ discard block |
||
375 | 375 | * @param array $meta_query Meta query. |
376 | 376 | * @return array |
377 | 377 | */ |
378 | - protected function add_meta_query( $args, $meta_query ) { |
|
379 | - if ( empty( $args['meta_query'] ) ) { |
|
378 | + protected function add_meta_query($args, $meta_query) { |
|
379 | + if (empty($args['meta_query'])) { |
|
380 | 380 | $args['meta_query'] = array(); |
381 | 381 | } |
382 | 382 | |
@@ -397,25 +397,25 @@ discard block |
||
397 | 397 | 'type' => 'object', |
398 | 398 | 'properties' => array( |
399 | 399 | 'create' => array( |
400 | - 'description' => __( 'List of created resources.', 'woocommerce' ), |
|
400 | + 'description' => __('List of created resources.', 'woocommerce'), |
|
401 | 401 | 'type' => 'array', |
402 | - 'context' => array( 'view', 'edit' ), |
|
402 | + 'context' => array('view', 'edit'), |
|
403 | 403 | 'items' => array( |
404 | 404 | 'type' => 'object', |
405 | 405 | ), |
406 | 406 | ), |
407 | 407 | 'update' => array( |
408 | - 'description' => __( 'List of updated resources.', 'woocommerce' ), |
|
408 | + 'description' => __('List of updated resources.', 'woocommerce'), |
|
409 | 409 | 'type' => 'array', |
410 | - 'context' => array( 'view', 'edit' ), |
|
410 | + 'context' => array('view', 'edit'), |
|
411 | 411 | 'items' => array( |
412 | 412 | 'type' => 'object', |
413 | 413 | ), |
414 | 414 | ), |
415 | 415 | 'delete' => array( |
416 | - 'description' => __( 'List of delete resources.', 'woocommerce' ), |
|
416 | + 'description' => __('List of delete resources.', 'woocommerce'), |
|
417 | 417 | 'type' => 'array', |
418 | - 'context' => array( 'view', 'edit' ), |
|
418 | + 'context' => array('view', 'edit'), |
|
419 | 419 | 'items' => array( |
420 | 420 | 'type' => 'integer', |
421 | 421 | ), |
@@ -435,32 +435,32 @@ discard block |
||
435 | 435 | * @param \WP_REST_Request $request Full details about the request. |
436 | 436 | * @return array Fields to be included in the response. |
437 | 437 | */ |
438 | - public function get_fields_for_response( $request ) { |
|
438 | + public function get_fields_for_response($request) { |
|
439 | 439 | $schema = $this->get_item_schema(); |
440 | - $fields = isset( $schema['properties'] ) ? array_keys( $schema['properties'] ) : array(); |
|
440 | + $fields = isset($schema['properties']) ? array_keys($schema['properties']) : array(); |
|
441 | 441 | |
442 | 442 | $additional_fields = $this->get_additional_fields(); |
443 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
443 | + foreach ($additional_fields as $field_name => $field_options) { |
|
444 | 444 | // For back-compat, include any field with an empty schema |
445 | 445 | // because it won't be present in $this->get_item_schema(). |
446 | - if ( is_null( $field_options['schema'] ) ) { |
|
446 | + if (is_null($field_options['schema'])) { |
|
447 | 447 | $fields[] = $field_name; |
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | - if ( ! isset( $request['_fields'] ) ) { |
|
451 | + if ( ! isset($request['_fields'])) { |
|
452 | 452 | return $fields; |
453 | 453 | } |
454 | - $requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] ); |
|
455 | - if ( 0 === count( $requested_fields ) ) { |
|
454 | + $requested_fields = is_array($request['_fields']) ? $request['_fields'] : preg_split('/[\s,]+/', $request['_fields']); |
|
455 | + if (0 === count($requested_fields)) { |
|
456 | 456 | return $fields; |
457 | 457 | } |
458 | 458 | // Trim off outside whitespace from the comma delimited list. |
459 | - $requested_fields = array_map( 'trim', $requested_fields ); |
|
459 | + $requested_fields = array_map('trim', $requested_fields); |
|
460 | 460 | // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
461 | - if ( in_array( 'id', $fields, true ) ) { |
|
461 | + if (in_array('id', $fields, true)) { |
|
462 | 462 | $requested_fields[] = 'id'; |
463 | 463 | } |
464 | - return array_intersect( $fields, $requested_fields ); |
|
464 | + return array_intersect($fields, $requested_fields); |
|
465 | 465 | } |
466 | 466 | } |
@@ -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 reports controller class. |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | array( |
34 | 34 | array( |
35 | 35 | 'methods' => \WP_REST_Server::READABLE, |
36 | - 'callback' => array( $this, 'get_items' ), |
|
37 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
36 | + 'callback' => array($this, 'get_items'), |
|
37 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
38 | 38 | 'args' => $this->get_collection_params(), |
39 | 39 | ), |
40 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
40 | + 'schema' => array($this, 'get_public_item_schema'), |
|
41 | 41 | ), |
42 | 42 | true |
43 | 43 | ); |
@@ -49,9 +49,9 @@ discard block |
||
49 | 49 | * @param \WP_REST_Request $request Full details about the request. |
50 | 50 | * @return \WP_Error|boolean |
51 | 51 | */ |
52 | - public function get_items_permissions_check( $request ) { |
|
53 | - if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) { |
|
54 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
52 | + public function get_items_permissions_check($request) { |
|
53 | + if ( ! wc_rest_check_manager_permissions('reports', 'read')) { |
|
54 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | return true; |
@@ -64,66 +64,66 @@ discard block |
||
64 | 64 | * @param \WP_REST_Request $request Request data. |
65 | 65 | * @return array|\WP_Error |
66 | 66 | */ |
67 | - public function get_items( $request ) { |
|
67 | + public function get_items($request) { |
|
68 | 68 | $data = []; |
69 | 69 | $reports = []; |
70 | - if ( class_exists( 'WC_Admin_Reports_Sync' ) ) { |
|
70 | + if (class_exists('WC_Admin_Reports_Sync')) { |
|
71 | 71 | $reports = array( |
72 | 72 | array( |
73 | 73 | 'slug' => 'performance-indicators', |
74 | - 'description' => __( 'Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce' ), |
|
74 | + 'description' => __('Batch endpoint for getting specific performance indicators from `stats` endpoints.', 'woocommerce'), |
|
75 | 75 | ), |
76 | 76 | array( |
77 | 77 | 'slug' => 'revenue/stats', |
78 | - 'description' => __( 'Stats about revenue.', 'woocommerce' ), |
|
78 | + 'description' => __('Stats about revenue.', 'woocommerce'), |
|
79 | 79 | ), |
80 | 80 | array( |
81 | 81 | 'slug' => 'orders/stats', |
82 | - 'description' => __( 'Stats about orders.', 'woocommerce' ), |
|
82 | + 'description' => __('Stats about orders.', 'woocommerce'), |
|
83 | 83 | ), |
84 | 84 | array( |
85 | 85 | 'slug' => 'products', |
86 | - 'description' => __( 'Products detailed reports.', 'woocommerce' ), |
|
86 | + 'description' => __('Products detailed reports.', 'woocommerce'), |
|
87 | 87 | ), |
88 | 88 | array( |
89 | 89 | 'slug' => 'products/stats', |
90 | - 'description' => __( 'Stats about products.', 'woocommerce' ), |
|
90 | + 'description' => __('Stats about products.', 'woocommerce'), |
|
91 | 91 | ), |
92 | 92 | array( |
93 | 93 | 'slug' => 'categories', |
94 | - 'description' => __( 'Product categories detailed reports.', 'woocommerce' ), |
|
94 | + 'description' => __('Product categories detailed reports.', 'woocommerce'), |
|
95 | 95 | ), |
96 | 96 | array( |
97 | 97 | 'slug' => 'categories/stats', |
98 | - 'description' => __( 'Stats about product categories.', 'woocommerce' ), |
|
98 | + 'description' => __('Stats about product categories.', 'woocommerce'), |
|
99 | 99 | ), |
100 | 100 | array( |
101 | 101 | 'slug' => 'coupons', |
102 | - 'description' => __( 'Coupons detailed reports.', 'woocommerce' ), |
|
102 | + 'description' => __('Coupons detailed reports.', 'woocommerce'), |
|
103 | 103 | ), |
104 | 104 | array( |
105 | 105 | 'slug' => 'coupons/stats', |
106 | - 'description' => __( 'Stats about coupons.', 'woocommerce' ), |
|
106 | + 'description' => __('Stats about coupons.', 'woocommerce'), |
|
107 | 107 | ), |
108 | 108 | array( |
109 | 109 | 'slug' => 'taxes', |
110 | - 'description' => __( 'Taxes detailed reports.', 'woocommerce' ), |
|
110 | + 'description' => __('Taxes detailed reports.', 'woocommerce'), |
|
111 | 111 | ), |
112 | 112 | array( |
113 | 113 | 'slug' => 'taxes/stats', |
114 | - 'description' => __( 'Stats about taxes.', 'woocommerce' ), |
|
114 | + 'description' => __('Stats about taxes.', 'woocommerce'), |
|
115 | 115 | ), |
116 | 116 | array( |
117 | 117 | 'slug' => 'downloads', |
118 | - 'description' => __( 'Product downloads detailed reports.', 'woocommerce' ), |
|
118 | + 'description' => __('Product downloads detailed reports.', 'woocommerce'), |
|
119 | 119 | ), |
120 | 120 | array( |
121 | 121 | 'slug' => 'downloads/stats', |
122 | - 'description' => __( 'Stats about product downloads.', 'woocommerce' ), |
|
122 | + 'description' => __('Stats about product downloads.', 'woocommerce'), |
|
123 | 123 | ), |
124 | 124 | array( |
125 | 125 | 'slug' => 'customers', |
126 | - 'description' => __( 'Customers detailed reports.', 'woocommerce' ), |
|
126 | + 'description' => __('Customers detailed reports.', 'woocommerce'), |
|
127 | 127 | ), |
128 | 128 | ); |
129 | 129 | } |
@@ -135,22 +135,22 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @param array $endpoints The list of allowed reports.. |
137 | 137 | */ |
138 | - $reports = apply_filters( 'woocommerce_admin_reports', $reports ); |
|
138 | + $reports = apply_filters('woocommerce_admin_reports', $reports); |
|
139 | 139 | |
140 | - foreach ( $reports as $report ) { |
|
141 | - if ( empty( $report['slug'] ) ) { |
|
140 | + foreach ($reports as $report) { |
|
141 | + if (empty($report['slug'])) { |
|
142 | 142 | continue; |
143 | 143 | } |
144 | 144 | |
145 | - if ( empty( $report['path'] ) ) { |
|
145 | + if (empty($report['path'])) { |
|
146 | 146 | $report['path'] = '/' . $this->namespace . '/reports/' . $report['slug']; |
147 | 147 | } |
148 | 148 | |
149 | 149 | // Allows a different admin page to be loaded here, |
150 | 150 | // or allows an empty url if no report exists for a set of performance indicators. |
151 | - if ( ! isset( $report['url'] ) ) { |
|
152 | - if ( '/stats' === substr( $report['slug'], -6 ) ) { |
|
153 | - $url_slug = substr( $report['slug'], 0, -6 ); |
|
151 | + if ( ! isset($report['url'])) { |
|
152 | + if ('/stats' === substr($report['slug'], -6)) { |
|
153 | + $url_slug = substr($report['slug'], 0, -6); |
|
154 | 154 | } else { |
155 | 155 | $url_slug = $report['slug']; |
156 | 156 | } |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | $report['url'] = '/analytics/' . $url_slug; |
159 | 159 | } |
160 | 160 | |
161 | - $item = $this->prepare_item_for_response( (object) $report, $request ); |
|
162 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
161 | + $item = $this->prepare_item_for_response((object) $report, $request); |
|
162 | + $data[] = $this->prepare_response_for_collection($item); |
|
163 | 163 | } |
164 | 164 | |
165 | - return rest_ensure_response( $data ); |
|
165 | + return rest_ensure_response($data); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,14 +172,14 @@ discard block |
||
172 | 172 | * @param int $order_id Order ID. |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - public function get_order_number( $order_id ) { |
|
176 | - $order = wc_get_order( $order_id ); |
|
175 | + public function get_order_number($order_id) { |
|
176 | + $order = wc_get_order($order_id); |
|
177 | 177 | |
178 | - if ( 'shop_order_refund' === $order->get_type() ) { |
|
179 | - $order = wc_get_order( $order->get_parent_id() ); |
|
178 | + if ('shop_order_refund' === $order->get_type()) { |
|
179 | + $order = wc_get_order($order->get_parent_id()); |
|
180 | 180 | } |
181 | 181 | |
182 | - if ( ! has_filter( 'woocommerce_order_number' ) ) { |
|
182 | + if ( ! has_filter('woocommerce_order_number')) { |
|
183 | 183 | return $order->get_id(); |
184 | 184 | } |
185 | 185 | |
@@ -193,29 +193,29 @@ discard block |
||
193 | 193 | * @param \WP_REST_Request $request Request object. |
194 | 194 | * @return \WP_REST_Response |
195 | 195 | */ |
196 | - public function prepare_item_for_response( $report, $request ) { |
|
196 | + public function prepare_item_for_response($report, $request) { |
|
197 | 197 | $data = array( |
198 | 198 | 'slug' => $report->slug, |
199 | 199 | 'description' => $report->description, |
200 | 200 | 'path' => $report->path, |
201 | 201 | ); |
202 | 202 | |
203 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
204 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
205 | - $data = $this->filter_response_by_context( $data, $context ); |
|
203 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
204 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
205 | + $data = $this->filter_response_by_context($data, $context); |
|
206 | 206 | |
207 | 207 | // Wrap the data in a response object. |
208 | - $response = rest_ensure_response( $data ); |
|
208 | + $response = rest_ensure_response($data); |
|
209 | 209 | $response->add_links( |
210 | 210 | array( |
211 | 211 | 'self' => array( |
212 | - 'href' => rest_url( $report->path ), |
|
212 | + 'href' => rest_url($report->path), |
|
213 | 213 | ), |
214 | 214 | 'report' => array( |
215 | 215 | 'href' => $report->url, |
216 | 216 | ), |
217 | 217 | 'collection' => array( |
218 | - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), |
|
218 | + 'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)), |
|
219 | 219 | ), |
220 | 220 | ) |
221 | 221 | ); |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @param object $report The original report object. |
230 | 230 | * @param \WP_REST_Request $request Request used to generate the response. |
231 | 231 | */ |
232 | - return apply_filters( 'woocommerce_rest_prepare_report', $response, $report, $request ); |
|
232 | + return apply_filters('woocommerce_rest_prepare_report', $response, $report, $request); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -244,27 +244,27 @@ discard block |
||
244 | 244 | 'type' => 'object', |
245 | 245 | 'properties' => array( |
246 | 246 | 'slug' => array( |
247 | - 'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ), |
|
247 | + 'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'), |
|
248 | 248 | 'type' => 'string', |
249 | - 'context' => array( 'view' ), |
|
249 | + 'context' => array('view'), |
|
250 | 250 | 'readonly' => true, |
251 | 251 | ), |
252 | 252 | 'description' => array( |
253 | - 'description' => __( 'A human-readable description of the resource.', 'woocommerce' ), |
|
253 | + 'description' => __('A human-readable description of the resource.', 'woocommerce'), |
|
254 | 254 | 'type' => 'string', |
255 | - 'context' => array( 'view' ), |
|
255 | + 'context' => array('view'), |
|
256 | 256 | 'readonly' => true, |
257 | 257 | ), |
258 | 258 | 'path' => array( |
259 | - 'description' => __( 'API path.', 'woocommerce' ), |
|
259 | + 'description' => __('API path.', 'woocommerce'), |
|
260 | 260 | 'type' => 'string', |
261 | - 'context' => array( 'view' ), |
|
261 | + 'context' => array('view'), |
|
262 | 262 | 'readonly' => true, |
263 | 263 | ), |
264 | 264 | ), |
265 | 265 | ); |
266 | 266 | |
267 | - return $this->add_additional_fields_schema( $schema ); |
|
267 | + return $this->add_additional_fields_schema($schema); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | */ |
275 | 275 | public function get_collection_params() { |
276 | 276 | return array( |
277 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
277 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
278 | 278 | ); |
279 | 279 | } |
280 | 280 | |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | public function get_order_statuses() { |
287 | 287 | $order_statuses = array(); |
288 | 288 | |
289 | - foreach ( array_keys( wc_get_order_statuses() ) as $status ) { |
|
290 | - $order_statuses[] = str_replace( 'wc-', '', $status ); |
|
289 | + foreach (array_keys(wc_get_order_statuses()) as $status) { |
|
290 | + $order_statuses[] = str_replace('wc-', '', $status); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | return $order_statuses; |
@@ -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 Attributes controller class. |
@@ -40,26 +40,26 @@ discard block |
||
40 | 40 | array( |
41 | 41 | array( |
42 | 42 | 'methods' => \WP_REST_Server::READABLE, |
43 | - 'callback' => array( $this, 'get_items' ), |
|
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
43 | + 'callback' => array($this, 'get_items'), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | 45 | 'args' => $this->get_collection_params(), |
46 | 46 | ), |
47 | 47 | array( |
48 | 48 | 'methods' => \WP_REST_Server::CREATABLE, |
49 | - 'callback' => array( $this, 'create_item' ), |
|
50 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
49 | + 'callback' => array($this, 'create_item'), |
|
50 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
51 | 51 | 'args' => array_merge( |
52 | - $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
|
52 | + $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE), |
|
53 | 53 | array( |
54 | 54 | 'name' => array( |
55 | - 'description' => __( 'Name for the resource.', 'woocommerce' ), |
|
55 | + 'description' => __('Name for the resource.', 'woocommerce'), |
|
56 | 56 | 'type' => 'string', |
57 | 57 | 'required' => true, |
58 | 58 | ), |
59 | 59 | ) |
60 | 60 | ), |
61 | 61 | ), |
62 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
62 | + 'schema' => array($this, 'get_public_item_schema'), |
|
63 | 63 | ), |
64 | 64 | true |
65 | 65 | ); |
@@ -70,37 +70,37 @@ discard block |
||
70 | 70 | array( |
71 | 71 | 'args' => array( |
72 | 72 | 'id' => array( |
73 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
73 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
74 | 74 | 'type' => 'integer', |
75 | 75 | ), |
76 | 76 | ), |
77 | 77 | array( |
78 | 78 | 'methods' => \WP_REST_Server::READABLE, |
79 | - 'callback' => array( $this, 'get_item' ), |
|
80 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
79 | + 'callback' => array($this, 'get_item'), |
|
80 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
81 | 81 | 'args' => array( |
82 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
82 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
83 | 83 | ), |
84 | 84 | ), |
85 | 85 | array( |
86 | 86 | 'methods' => \WP_REST_Server::EDITABLE, |
87 | - 'callback' => array( $this, 'update_item' ), |
|
88 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
89 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
87 | + 'callback' => array($this, 'update_item'), |
|
88 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
89 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
90 | 90 | ), |
91 | 91 | array( |
92 | 92 | 'methods' => \WP_REST_Server::DELETABLE, |
93 | - 'callback' => array( $this, 'delete_item' ), |
|
94 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
93 | + 'callback' => array($this, 'delete_item'), |
|
94 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
95 | 95 | 'args' => array( |
96 | 96 | 'force' => array( |
97 | 97 | 'default' => true, |
98 | 98 | 'type' => 'boolean', |
99 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
99 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
100 | 100 | ), |
101 | 101 | ), |
102 | 102 | ), |
103 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
103 | + 'schema' => array($this, 'get_public_item_schema'), |
|
104 | 104 | ), |
105 | 105 | true |
106 | 106 | ); |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | array( |
112 | 112 | array( |
113 | 113 | 'methods' => \WP_REST_Server::EDITABLE, |
114 | - 'callback' => array( $this, 'batch_items' ), |
|
115 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
116 | - 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
|
114 | + 'callback' => array($this, 'batch_items'), |
|
115 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
116 | + 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE), |
|
117 | 117 | ), |
118 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
118 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
119 | 119 | ), |
120 | 120 | true |
121 | 121 | ); |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * @param \WP_REST_Request $request Full details about the request. |
128 | 128 | * @return \WP_Error|boolean |
129 | 129 | */ |
130 | - public function get_items_permissions_check( $request ) { |
|
131 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) { |
|
132 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
130 | + public function get_items_permissions_check($request) { |
|
131 | + if ( ! wc_rest_check_manager_permissions('attributes', 'read')) { |
|
132 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | return true; |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * @param \WP_REST_Request $request Full details about the request. |
142 | 142 | * @return \WP_Error|boolean |
143 | 143 | */ |
144 | - public function create_item_permissions_check( $request ) { |
|
145 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'create' ) ) { |
|
146 | - return new \WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you cannot create new resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
144 | + public function create_item_permissions_check($request) { |
|
145 | + if ( ! wc_rest_check_manager_permissions('attributes', 'create')) { |
|
146 | + return new \WP_Error('woocommerce_rest_cannot_create', __('Sorry, you cannot create new resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return true; |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | * @param \WP_REST_Request $request Full details about the request. |
156 | 156 | * @return \WP_Error|boolean |
157 | 157 | */ |
158 | - public function get_item_permissions_check( $request ) { |
|
159 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
160 | - return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
158 | + public function get_item_permissions_check($request) { |
|
159 | + if ( ! $this->get_taxonomy($request)) { |
|
160 | + return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
161 | 161 | } |
162 | 162 | |
163 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) { |
|
164 | - return new \WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
163 | + if ( ! wc_rest_check_manager_permissions('attributes', 'read')) { |
|
164 | + return new \WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | return true; |
@@ -173,13 +173,13 @@ discard block |
||
173 | 173 | * @param \WP_REST_Request $request Full details about the request. |
174 | 174 | * @return \WP_Error|boolean |
175 | 175 | */ |
176 | - public function update_item_permissions_check( $request ) { |
|
177 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
178 | - return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
176 | + public function update_item_permissions_check($request) { |
|
177 | + if ( ! $this->get_taxonomy($request)) { |
|
178 | + return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'edit' ) ) { |
|
182 | - return new \WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
181 | + if ( ! wc_rest_check_manager_permissions('attributes', 'edit')) { |
|
182 | + return new \WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return true; |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | * @param \WP_REST_Request $request Full details about the request. |
192 | 192 | * @return \WP_Error|boolean |
193 | 193 | */ |
194 | - public function delete_item_permissions_check( $request ) { |
|
195 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
196 | - return new \WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
194 | + public function delete_item_permissions_check($request) { |
|
195 | + if ( ! $this->get_taxonomy($request)) { |
|
196 | + return new \WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'delete' ) ) { |
|
200 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
199 | + if ( ! wc_rest_check_manager_permissions('attributes', 'delete')) { |
|
200 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | return true; |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | * |
211 | 211 | * @return bool|\WP_Error |
212 | 212 | */ |
213 | - public function batch_items_permissions_check( $request ) { |
|
214 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'batch' ) ) { |
|
215 | - return new \WP_Error( 'woocommerce_rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
213 | + public function batch_items_permissions_check($request) { |
|
214 | + if ( ! wc_rest_check_manager_permissions('attributes', 'batch')) { |
|
215 | + return new \WP_Error('woocommerce_rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | return true; |
@@ -224,16 +224,16 @@ discard block |
||
224 | 224 | * @param \WP_REST_Request $request Request params. |
225 | 225 | * @return array |
226 | 226 | */ |
227 | - public function get_items( $request ) { |
|
227 | + public function get_items($request) { |
|
228 | 228 | $attributes = wc_get_attribute_taxonomies(); |
229 | 229 | $data = array(); |
230 | - foreach ( $attributes as $attribute_obj ) { |
|
231 | - $attribute = $this->prepare_item_for_response( $attribute_obj, $request ); |
|
232 | - $attribute = $this->prepare_response_for_collection( $attribute ); |
|
230 | + foreach ($attributes as $attribute_obj) { |
|
231 | + $attribute = $this->prepare_item_for_response($attribute_obj, $request); |
|
232 | + $attribute = $this->prepare_response_for_collection($attribute); |
|
233 | 233 | $data[] = $attribute; |
234 | 234 | } |
235 | 235 | |
236 | - return rest_ensure_response( $data ); |
|
236 | + return rest_ensure_response($data); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -242,31 +242,31 @@ discard block |
||
242 | 242 | * @param \WP_REST_Request $request Full details about the request. |
243 | 243 | * @return \WP_REST_Request|\WP_Error |
244 | 244 | */ |
245 | - public function create_item( $request ) { |
|
245 | + public function create_item($request) { |
|
246 | 246 | global $wpdb; |
247 | 247 | |
248 | 248 | $id = wc_create_attribute( |
249 | 249 | array( |
250 | 250 | 'name' => $request['name'], |
251 | - 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), |
|
252 | - 'type' => ! empty( $request['type'] ) ? $request['type'] : 'select', |
|
253 | - 'order_by' => ! empty( $request['order_by'] ) ? $request['order_by'] : 'menu_order', |
|
251 | + 'slug' => wc_sanitize_taxonomy_name(stripslashes($request['slug'])), |
|
252 | + 'type' => ! empty($request['type']) ? $request['type'] : 'select', |
|
253 | + 'order_by' => ! empty($request['order_by']) ? $request['order_by'] : 'menu_order', |
|
254 | 254 | 'has_archives' => true === $request['has_archives'], |
255 | 255 | ) |
256 | 256 | ); |
257 | 257 | |
258 | 258 | // Checks for errors. |
259 | - if ( is_wp_error( $id ) ) { |
|
260 | - return new \WP_Error( 'woocommerce_rest_cannot_create', $id->get_error_message(), array( 'status' => 400 ) ); |
|
259 | + if (is_wp_error($id)) { |
|
260 | + return new \WP_Error('woocommerce_rest_cannot_create', $id->get_error_message(), array('status' => 400)); |
|
261 | 261 | } |
262 | 262 | |
263 | - $attribute = $this->get_attribute( $id ); |
|
263 | + $attribute = $this->get_attribute($id); |
|
264 | 264 | |
265 | - if ( is_wp_error( $attribute ) ) { |
|
265 | + if (is_wp_error($attribute)) { |
|
266 | 266 | return $attribute; |
267 | 267 | } |
268 | 268 | |
269 | - $this->update_additional_fields_for_object( $attribute, $request ); |
|
269 | + $this->update_additional_fields_for_object($attribute, $request); |
|
270 | 270 | |
271 | 271 | /** |
272 | 272 | * Fires after a single product attribute is created or updated via the REST API. |
@@ -275,13 +275,13 @@ discard block |
||
275 | 275 | * @param \WP_REST_Request $request Request object. |
276 | 276 | * @param boolean $creating True when creating attribute, false when updating. |
277 | 277 | */ |
278 | - do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, true ); |
|
278 | + do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, true); |
|
279 | 279 | |
280 | - $request->set_param( 'context', 'edit' ); |
|
281 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
282 | - $response = rest_ensure_response( $response ); |
|
283 | - $response->set_status( 201 ); |
|
284 | - $response->header( 'Location', rest_url( '/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id ) ); |
|
280 | + $request->set_param('context', 'edit'); |
|
281 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
282 | + $response = rest_ensure_response($response); |
|
283 | + $response->set_status(201); |
|
284 | + $response->header('Location', rest_url('/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id)); |
|
285 | 285 | |
286 | 286 | return $response; |
287 | 287 | } |
@@ -292,16 +292,16 @@ discard block |
||
292 | 292 | * @param \WP_REST_Request $request Full details about the request. |
293 | 293 | * @return \WP_REST_Request|\WP_Error |
294 | 294 | */ |
295 | - public function get_item( $request ) { |
|
296 | - $attribute = $this->get_attribute( (int) $request['id'] ); |
|
295 | + public function get_item($request) { |
|
296 | + $attribute = $this->get_attribute((int) $request['id']); |
|
297 | 297 | |
298 | - if ( is_wp_error( $attribute ) ) { |
|
298 | + if (is_wp_error($attribute)) { |
|
299 | 299 | return $attribute; |
300 | 300 | } |
301 | 301 | |
302 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
302 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
303 | 303 | |
304 | - return rest_ensure_response( $response ); |
|
304 | + return rest_ensure_response($response); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * @param \WP_REST_Request $request Full details about the request. |
311 | 311 | * @return \WP_REST_Request|\WP_Error |
312 | 312 | */ |
313 | - public function update_item( $request ) { |
|
313 | + public function update_item($request) { |
|
314 | 314 | global $wpdb; |
315 | 315 | |
316 | 316 | $id = (int) $request['id']; |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | $id, |
319 | 319 | array( |
320 | 320 | 'name' => $request['name'], |
321 | - 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), |
|
321 | + 'slug' => wc_sanitize_taxonomy_name(stripslashes($request['slug'])), |
|
322 | 322 | 'type' => $request['type'], |
323 | 323 | 'order_by' => $request['order_by'], |
324 | 324 | 'has_archives' => $request['has_archives'], |
@@ -326,17 +326,17 @@ discard block |
||
326 | 326 | ); |
327 | 327 | |
328 | 328 | // Checks for errors. |
329 | - if ( is_wp_error( $edited ) ) { |
|
330 | - return new \WP_Error( 'woocommerce_rest_cannot_edit', $edited->get_error_message(), array( 'status' => 400 ) ); |
|
329 | + if (is_wp_error($edited)) { |
|
330 | + return new \WP_Error('woocommerce_rest_cannot_edit', $edited->get_error_message(), array('status' => 400)); |
|
331 | 331 | } |
332 | 332 | |
333 | - $attribute = $this->get_attribute( $id ); |
|
333 | + $attribute = $this->get_attribute($id); |
|
334 | 334 | |
335 | - if ( is_wp_error( $attribute ) ) { |
|
335 | + if (is_wp_error($attribute)) { |
|
336 | 336 | return $attribute; |
337 | 337 | } |
338 | 338 | |
339 | - $this->update_additional_fields_for_object( $attribute, $request ); |
|
339 | + $this->update_additional_fields_for_object($attribute, $request); |
|
340 | 340 | |
341 | 341 | /** |
342 | 342 | * Fires after a single product attribute is created or updated via the REST API. |
@@ -345,12 +345,12 @@ discard block |
||
345 | 345 | * @param \WP_REST_Request $request Request object. |
346 | 346 | * @param boolean $creating True when creating attribute, false when updating. |
347 | 347 | */ |
348 | - do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, false ); |
|
348 | + do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, false); |
|
349 | 349 | |
350 | - $request->set_param( 'context', 'edit' ); |
|
351 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
350 | + $request->set_param('context', 'edit'); |
|
351 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
352 | 352 | |
353 | - return rest_ensure_response( $response ); |
|
353 | + return rest_ensure_response($response); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -359,26 +359,26 @@ discard block |
||
359 | 359 | * @param \WP_REST_Request $request Full details about the request. |
360 | 360 | * @return \WP_REST_Response|\WP_Error |
361 | 361 | */ |
362 | - public function delete_item( $request ) { |
|
363 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
362 | + public function delete_item($request) { |
|
363 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
364 | 364 | |
365 | 365 | // We don't support trashing for this type, error out. |
366 | - if ( ! $force ) { |
|
367 | - return new \WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
366 | + if ( ! $force) { |
|
367 | + return new \WP_Error('woocommerce_rest_trash_not_supported', __('Resource does not support trashing.', 'woocommerce'), array('status' => 501)); |
|
368 | 368 | } |
369 | 369 | |
370 | - $attribute = $this->get_attribute( (int) $request['id'] ); |
|
370 | + $attribute = $this->get_attribute((int) $request['id']); |
|
371 | 371 | |
372 | - if ( is_wp_error( $attribute ) ) { |
|
372 | + if (is_wp_error($attribute)) { |
|
373 | 373 | return $attribute; |
374 | 374 | } |
375 | 375 | |
376 | - $request->set_param( 'context', 'edit' ); |
|
377 | - $previous = $this->prepare_item_for_response( $attribute, $request ); |
|
378 | - $deleted = wc_delete_attribute( $attribute->attribute_id ); |
|
376 | + $request->set_param('context', 'edit'); |
|
377 | + $previous = $this->prepare_item_for_response($attribute, $request); |
|
378 | + $deleted = wc_delete_attribute($attribute->attribute_id); |
|
379 | 379 | |
380 | - if ( false === $deleted ) { |
|
381 | - return new \WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
380 | + if (false === $deleted) { |
|
381 | + return new \WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | $response = new \WP_REST_Response(); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | * @param \WP_REST_Response $response The response data. |
397 | 397 | * @param \WP_REST_Request $request The request sent to the API. |
398 | 398 | */ |
399 | - do_action( 'woocommerce_rest_delete_product_attribute', $attribute, $response, $request ); |
|
399 | + do_action('woocommerce_rest_delete_product_attribute', $attribute, $response, $request); |
|
400 | 400 | |
401 | 401 | return $response; |
402 | 402 | } |
@@ -408,23 +408,23 @@ discard block |
||
408 | 408 | * @param \WP_REST_Request $request Request params. |
409 | 409 | * @return \WP_REST_Response $response |
410 | 410 | */ |
411 | - public function prepare_item_for_response( $item, $request ) { |
|
411 | + public function prepare_item_for_response($item, $request) { |
|
412 | 412 | $data = array( |
413 | 413 | 'id' => (int) $item->attribute_id, |
414 | 414 | 'name' => $item->attribute_label, |
415 | - 'slug' => wc_attribute_taxonomy_name( $item->attribute_name ), |
|
415 | + 'slug' => wc_attribute_taxonomy_name($item->attribute_name), |
|
416 | 416 | 'type' => $item->attribute_type, |
417 | 417 | 'order_by' => $item->attribute_orderby, |
418 | 418 | 'has_archives' => (bool) $item->attribute_public, |
419 | 419 | ); |
420 | 420 | |
421 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
422 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
423 | - $data = $this->filter_response_by_context( $data, $context ); |
|
421 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
422 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
423 | + $data = $this->filter_response_by_context($data, $context); |
|
424 | 424 | |
425 | - $response = rest_ensure_response( $data ); |
|
425 | + $response = rest_ensure_response($data); |
|
426 | 426 | |
427 | - $response->add_links( $this->prepare_links( $item ) ); |
|
427 | + $response->add_links($this->prepare_links($item)); |
|
428 | 428 | |
429 | 429 | /** |
430 | 430 | * Filter a attribute item returned from the API. |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | * @param object $item The original attribute object. |
436 | 436 | * @param \WP_REST_Request $request Request used to generate the response. |
437 | 437 | */ |
438 | - return apply_filters( 'woocommerce_rest_prepare_product_attribute', $response, $item, $request ); |
|
438 | + return apply_filters('woocommerce_rest_prepare_product_attribute', $response, $item, $request); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -444,14 +444,14 @@ discard block |
||
444 | 444 | * @param object $attribute Attribute object. |
445 | 445 | * @return array Links for the given attribute. |
446 | 446 | */ |
447 | - protected function prepare_links( $attribute ) { |
|
447 | + protected function prepare_links($attribute) { |
|
448 | 448 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
449 | 449 | $links = array( |
450 | 450 | 'self' => array( |
451 | - 'href' => rest_url( trailingslashit( $base ) . $attribute->attribute_id ), |
|
451 | + 'href' => rest_url(trailingslashit($base) . $attribute->attribute_id), |
|
452 | 452 | ), |
453 | 453 | 'collection' => array( |
454 | - 'href' => rest_url( $base ), |
|
454 | + 'href' => rest_url($base), |
|
455 | 455 | ), |
456 | 456 | ); |
457 | 457 | |
@@ -470,51 +470,51 @@ discard block |
||
470 | 470 | 'type' => 'object', |
471 | 471 | 'properties' => array( |
472 | 472 | 'id' => array( |
473 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
473 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
474 | 474 | 'type' => 'integer', |
475 | - 'context' => array( 'view', 'edit' ), |
|
475 | + 'context' => array('view', 'edit'), |
|
476 | 476 | 'readonly' => true, |
477 | 477 | ), |
478 | 478 | 'name' => array( |
479 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
479 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
480 | 480 | 'type' => 'string', |
481 | - 'context' => array( 'view', 'edit' ), |
|
481 | + 'context' => array('view', 'edit'), |
|
482 | 482 | 'arg_options' => array( |
483 | 483 | 'sanitize_callback' => 'sanitize_text_field', |
484 | 484 | ), |
485 | 485 | ), |
486 | 486 | 'slug' => array( |
487 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
487 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
488 | 488 | 'type' => 'string', |
489 | - 'context' => array( 'view', 'edit' ), |
|
489 | + 'context' => array('view', 'edit'), |
|
490 | 490 | 'arg_options' => array( |
491 | 491 | 'sanitize_callback' => 'sanitize_title', |
492 | 492 | ), |
493 | 493 | ), |
494 | 494 | 'type' => array( |
495 | - 'description' => __( 'Type of attribute.', 'woocommerce' ), |
|
495 | + 'description' => __('Type of attribute.', 'woocommerce'), |
|
496 | 496 | 'type' => 'string', |
497 | 497 | 'default' => 'select', |
498 | - 'enum' => array_keys( wc_get_attribute_types() ), |
|
499 | - 'context' => array( 'view', 'edit' ), |
|
498 | + 'enum' => array_keys(wc_get_attribute_types()), |
|
499 | + 'context' => array('view', 'edit'), |
|
500 | 500 | ), |
501 | 501 | 'order_by' => array( |
502 | - 'description' => __( 'Default sort order.', 'woocommerce' ), |
|
502 | + 'description' => __('Default sort order.', 'woocommerce'), |
|
503 | 503 | 'type' => 'string', |
504 | 504 | 'default' => 'menu_order', |
505 | - 'enum' => array( 'menu_order', 'name', 'name_num', 'id' ), |
|
506 | - 'context' => array( 'view', 'edit' ), |
|
505 | + 'enum' => array('menu_order', 'name', 'name_num', 'id'), |
|
506 | + 'context' => array('view', 'edit'), |
|
507 | 507 | ), |
508 | 508 | 'has_archives' => array( |
509 | - 'description' => __( 'Enable/Disable attribute archives.', 'woocommerce' ), |
|
509 | + 'description' => __('Enable/Disable attribute archives.', 'woocommerce'), |
|
510 | 510 | 'type' => 'boolean', |
511 | 511 | 'default' => false, |
512 | - 'context' => array( 'view', 'edit' ), |
|
512 | + 'context' => array('view', 'edit'), |
|
513 | 513 | ), |
514 | 514 | ), |
515 | 515 | ); |
516 | 516 | |
517 | - return $this->add_additional_fields_schema( $schema ); |
|
517 | + return $this->add_additional_fields_schema($schema); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | */ |
525 | 525 | public function get_collection_params() { |
526 | 526 | $params = array(); |
527 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
527 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
528 | 528 | |
529 | 529 | return $params; |
530 | 530 | } |
@@ -535,13 +535,13 @@ discard block |
||
535 | 535 | * @param \WP_REST_Request $request Full details about the request. |
536 | 536 | * @return string |
537 | 537 | */ |
538 | - protected function get_taxonomy( $request ) { |
|
539 | - if ( '' !== $this->attribute ) { |
|
538 | + protected function get_taxonomy($request) { |
|
539 | + if ('' !== $this->attribute) { |
|
540 | 540 | return $this->attribute; |
541 | 541 | } |
542 | 542 | |
543 | - if ( $request['id'] ) { |
|
544 | - $name = wc_attribute_taxonomy_name_by_id( (int) $request['id'] ); |
|
543 | + if ($request['id']) { |
|
544 | + $name = wc_attribute_taxonomy_name_by_id((int) $request['id']); |
|
545 | 545 | |
546 | 546 | $this->attribute = $name; |
547 | 547 | } |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | * @param int $id Attribute ID. |
556 | 556 | * @return stdClass|\WP_Error |
557 | 557 | */ |
558 | - protected function get_attribute( $id ) { |
|
558 | + protected function get_attribute($id) { |
|
559 | 559 | global $wpdb; |
560 | 560 | |
561 | 561 | $attribute = $wpdb->get_row( |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | ) |
570 | 570 | ); |
571 | 571 | |
572 | - if ( is_wp_error( $attribute ) || is_null( $attribute ) ) { |
|
573 | - return new \WP_Error( 'woocommerce_rest_attribute_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
572 | + if (is_wp_error($attribute) || is_null($attribute)) { |
|
573 | + return new \WP_Error('woocommerce_rest_attribute_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | return $attribute; |
@@ -584,16 +584,16 @@ discard block |
||
584 | 584 | * @param bool $new_data Is the data new or old. |
585 | 585 | * @return bool|\WP_Error |
586 | 586 | */ |
587 | - protected function validate_attribute_slug( $slug, $new_data = true ) { |
|
588 | - if ( strlen( $slug ) >= 28 ) { |
|
587 | + protected function validate_attribute_slug($slug, $new_data = true) { |
|
588 | + if (strlen($slug) >= 28) { |
|
589 | 589 | /* Translators: %s slug. */ |
590 | - return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf( __( 'Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
591 | - } elseif ( wc_check_if_attribute_name_is_reserved( $slug ) ) { |
|
590 | + return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf(__('Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
591 | + } elseif (wc_check_if_attribute_name_is_reserved($slug)) { |
|
592 | 592 | /* Translators: %s slug. */ |
593 | - return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
594 | - } elseif ( $new_data && taxonomy_exists( wc_attribute_taxonomy_name( $slug ) ) ) { |
|
593 | + return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf(__('Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
594 | + } elseif ($new_data && taxonomy_exists(wc_attribute_taxonomy_name($slug))) { |
|
595 | 595 | /* Translators: %s slug. */ |
596 | - return new \WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
596 | + return new \WP_Error('woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf(__('Slug "%s" is already in use. Change it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | return true; |
@@ -606,6 +606,6 @@ discard block |
||
606 | 606 | * @since 3.0.0 |
607 | 607 | */ |
608 | 608 | protected function flush_rewrite_rules() { |
609 | - wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' ); |
|
609 | + wp_schedule_single_event(time(), 'woocommerce_flush_rewrite_rules'); |
|
610 | 610 | } |
611 | 611 | } |