@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param WP_REST_Request $request |
51 | 51 | * @return WP_REST_Response $response |
52 | 52 | */ |
53 | - public function prepare_item_for_response( $item, $request ) { |
|
53 | + public function prepare_item_for_response($item, $request) { |
|
54 | 54 | $data = array( |
55 | 55 | 'id' => (int) $item->term_id, |
56 | 56 | 'name' => $item->name, |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | 'count' => (int) $item->count, |
60 | 60 | ); |
61 | 61 | |
62 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
63 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
64 | - $data = $this->filter_response_by_context( $data, $context ); |
|
62 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
63 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
64 | + $data = $this->filter_response_by_context($data, $context); |
|
65 | 65 | |
66 | - $response = rest_ensure_response( $data ); |
|
66 | + $response = rest_ensure_response($data); |
|
67 | 67 | |
68 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
68 | + $response->add_links($this->prepare_links($item, $request)); |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Filter a term item returned from the API. |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param object $item The original term object. |
77 | 77 | * @param WP_REST_Request $request Request used to generate the response. |
78 | 78 | */ |
79 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
79 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -91,44 +91,44 @@ discard block |
||
91 | 91 | 'type' => 'object', |
92 | 92 | 'properties' => array( |
93 | 93 | 'id' => array( |
94 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
94 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
95 | 95 | 'type' => 'integer', |
96 | - 'context' => array( 'view', 'edit' ), |
|
96 | + 'context' => array('view', 'edit'), |
|
97 | 97 | 'readonly' => true, |
98 | 98 | ), |
99 | 99 | 'name' => array( |
100 | - 'description' => __( 'Tag name.', 'woocommerce' ), |
|
100 | + 'description' => __('Tag name.', 'woocommerce'), |
|
101 | 101 | 'type' => 'string', |
102 | - 'context' => array( 'view', 'edit' ), |
|
102 | + 'context' => array('view', 'edit'), |
|
103 | 103 | 'arg_options' => array( |
104 | 104 | 'sanitize_callback' => 'sanitize_text_field', |
105 | 105 | ), |
106 | 106 | ), |
107 | 107 | 'slug' => array( |
108 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
108 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
109 | 109 | 'type' => 'string', |
110 | - 'context' => array( 'view', 'edit' ), |
|
110 | + 'context' => array('view', 'edit'), |
|
111 | 111 | 'arg_options' => array( |
112 | 112 | 'sanitize_callback' => 'sanitize_title', |
113 | 113 | ), |
114 | 114 | ), |
115 | 115 | 'description' => array( |
116 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
116 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
117 | 117 | 'type' => 'string', |
118 | - 'context' => array( 'view', 'edit' ), |
|
118 | + 'context' => array('view', 'edit'), |
|
119 | 119 | 'arg_options' => array( |
120 | 120 | 'sanitize_callback' => 'wp_filter_post_kses', |
121 | 121 | ), |
122 | 122 | ), |
123 | 123 | 'count' => array( |
124 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
124 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
125 | 125 | 'type' => 'integer', |
126 | - 'context' => array( 'view', 'edit' ), |
|
126 | + 'context' => array('view', 'edit'), |
|
127 | 127 | 'readonly' => true, |
128 | 128 | ), |
129 | 129 | ), |
130 | 130 | ); |
131 | 131 | |
132 | - return $this->add_additional_fields_schema( $schema ); |
|
132 | + return $this->add_additional_fields_schema($schema); |
|
133 | 133 | } |
134 | 134 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -40,21 +40,21 @@ discard block |
||
40 | 40 | * Register the routes for customers. |
41 | 41 | */ |
42 | 42 | public function register_routes() { |
43 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
43 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
44 | 44 | 'args' => array( |
45 | 45 | 'customer_id' => array( |
46 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
46 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
47 | 47 | 'type' => 'integer', |
48 | 48 | ), |
49 | 49 | ), |
50 | 50 | array( |
51 | 51 | 'methods' => WP_REST_Server::READABLE, |
52 | - 'callback' => array( $this, 'get_items' ), |
|
53 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
52 | + 'callback' => array($this, 'get_items'), |
|
53 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
54 | 54 | 'args' => $this->get_collection_params(), |
55 | 55 | ), |
56 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
57 | - ) ); |
|
56 | + 'schema' => array($this, 'get_public_item_schema'), |
|
57 | + )); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | * @param WP_REST_Request $request Full details about the request. |
64 | 64 | * @return WP_Error|boolean |
65 | 65 | */ |
66 | - public function get_items_permissions_check( $request ) { |
|
67 | - $customer = get_user_by( 'id', (int) $request['customer_id'] ); |
|
66 | + public function get_items_permissions_check($request) { |
|
67 | + $customer = get_user_by('id', (int) $request['customer_id']); |
|
68 | 68 | |
69 | - if ( ! $customer ) { |
|
70 | - return new WP_Error( 'woocommerce_rest_customer_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
69 | + if ( ! $customer) { |
|
70 | + return new WP_Error('woocommerce_rest_customer_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
71 | 71 | } |
72 | 72 | |
73 | - if ( ! wc_rest_check_user_permissions( 'read', $customer->get_id() ) ) { |
|
74 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
73 | + if ( ! wc_rest_check_user_permissions('read', $customer->get_id())) { |
|
74 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | return true; |
@@ -83,17 +83,17 @@ discard block |
||
83 | 83 | * @param WP_REST_Request $request |
84 | 84 | * @return array |
85 | 85 | */ |
86 | - public function get_items( $request ) { |
|
87 | - $downloads = wc_get_customer_available_downloads( (int) $request['customer_id'] ); |
|
86 | + public function get_items($request) { |
|
87 | + $downloads = wc_get_customer_available_downloads((int) $request['customer_id']); |
|
88 | 88 | |
89 | 89 | $data = array(); |
90 | - foreach ( $downloads as $download_data ) { |
|
91 | - $download = $this->prepare_item_for_response( (object) $download_data, $request ); |
|
92 | - $download = $this->prepare_response_for_collection( $download ); |
|
90 | + foreach ($downloads as $download_data) { |
|
91 | + $download = $this->prepare_item_for_response((object) $download_data, $request); |
|
92 | + $download = $this->prepare_response_for_collection($download); |
|
93 | 93 | $data[] = $download; |
94 | 94 | } |
95 | 95 | |
96 | - return rest_ensure_response( $data ); |
|
96 | + return rest_ensure_response($data); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,22 +103,22 @@ discard block |
||
103 | 103 | * @param WP_REST_Request $request Request object. |
104 | 104 | * @return WP_REST_Response $response Response data. |
105 | 105 | */ |
106 | - public function prepare_item_for_response( $download, $request ) { |
|
106 | + public function prepare_item_for_response($download, $request) { |
|
107 | 107 | $data = (array) $download; |
108 | - $data['access_expires'] = $data['access_expires'] ? wc_rest_prepare_date_response( $data['access_expires'] ) : 'never'; |
|
108 | + $data['access_expires'] = $data['access_expires'] ? wc_rest_prepare_date_response($data['access_expires']) : 'never'; |
|
109 | 109 | $data['downloads_remaining'] = '' === $data['downloads_remaining'] ? 'unlimited' : $data['downloads_remaining']; |
110 | 110 | |
111 | 111 | // Remove "product_name" since it's new in 3.0. |
112 | - unset( $data['product_name'] ); |
|
112 | + unset($data['product_name']); |
|
113 | 113 | |
114 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
115 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
116 | - $data = $this->filter_response_by_context( $data, $context ); |
|
114 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
115 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
116 | + $data = $this->filter_response_by_context($data, $context); |
|
117 | 117 | |
118 | 118 | // Wrap the data in a response object. |
119 | - $response = rest_ensure_response( $data ); |
|
119 | + $response = rest_ensure_response($data); |
|
120 | 120 | |
121 | - $response->add_links( $this->prepare_links( $download, $request ) ); |
|
121 | + $response->add_links($this->prepare_links($download, $request)); |
|
122 | 122 | |
123 | 123 | /** |
124 | 124 | * Filter customer download data returned from the REST API. |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @param stdObject $download Download object used to create response. |
128 | 128 | * @param WP_REST_Request $request Request object. |
129 | 129 | */ |
130 | - return apply_filters( 'woocommerce_rest_prepare_customer_download', $response, $download, $request ); |
|
130 | + return apply_filters('woocommerce_rest_prepare_customer_download', $response, $download, $request); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -137,17 +137,17 @@ discard block |
||
137 | 137 | * @param WP_REST_Request $request Request object. |
138 | 138 | * @return array Links for the given customer download. |
139 | 139 | */ |
140 | - protected function prepare_links( $download, $request ) { |
|
141 | - $base = str_replace( '(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base ); |
|
140 | + protected function prepare_links($download, $request) { |
|
141 | + $base = str_replace('(?P<customer_id>[\d]+)', $request['customer_id'], $this->rest_base); |
|
142 | 142 | $links = array( |
143 | 143 | 'collection' => array( |
144 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
144 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
145 | 145 | ), |
146 | 146 | 'product' => array( |
147 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $download->product_id ) ), |
|
147 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $download->product_id)), |
|
148 | 148 | ), |
149 | 149 | 'order' => array( |
150 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $download->order_id ) ), |
|
150 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $download->order_id)), |
|
151 | 151 | ), |
152 | 152 | ); |
153 | 153 | |
@@ -166,69 +166,69 @@ discard block |
||
166 | 166 | 'type' => 'object', |
167 | 167 | 'properties' => array( |
168 | 168 | 'download_url' => array( |
169 | - 'description' => __( 'Download file URL.', 'woocommerce' ), |
|
169 | + 'description' => __('Download file URL.', 'woocommerce'), |
|
170 | 170 | 'type' => 'string', |
171 | - 'context' => array( 'view' ), |
|
171 | + 'context' => array('view'), |
|
172 | 172 | 'readonly' => true, |
173 | 173 | ), |
174 | 174 | 'download_id' => array( |
175 | - 'description' => __( 'Download ID (MD5).', 'woocommerce' ), |
|
175 | + 'description' => __('Download ID (MD5).', 'woocommerce'), |
|
176 | 176 | 'type' => 'string', |
177 | - 'context' => array( 'view' ), |
|
177 | + 'context' => array('view'), |
|
178 | 178 | 'readonly' => true, |
179 | 179 | ), |
180 | 180 | 'product_id' => array( |
181 | - 'description' => __( 'Downloadable product ID.', 'woocommerce' ), |
|
181 | + 'description' => __('Downloadable product ID.', 'woocommerce'), |
|
182 | 182 | 'type' => 'integer', |
183 | - 'context' => array( 'view' ), |
|
183 | + 'context' => array('view'), |
|
184 | 184 | 'readonly' => true, |
185 | 185 | ), |
186 | 186 | 'download_name' => array( |
187 | - 'description' => __( 'Downloadable file name.', 'woocommerce' ), |
|
187 | + 'description' => __('Downloadable file name.', 'woocommerce'), |
|
188 | 188 | 'type' => 'string', |
189 | - 'context' => array( 'view' ), |
|
189 | + 'context' => array('view'), |
|
190 | 190 | 'readonly' => true, |
191 | 191 | ), |
192 | 192 | 'order_id' => array( |
193 | - 'description' => __( 'Order ID.', 'woocommerce' ), |
|
193 | + 'description' => __('Order ID.', 'woocommerce'), |
|
194 | 194 | 'type' => 'integer', |
195 | - 'context' => array( 'view' ), |
|
195 | + 'context' => array('view'), |
|
196 | 196 | 'readonly' => true, |
197 | 197 | ), |
198 | 198 | 'order_key' => array( |
199 | - 'description' => __( 'Order key.', 'woocommerce' ), |
|
199 | + 'description' => __('Order key.', 'woocommerce'), |
|
200 | 200 | 'type' => 'string', |
201 | - 'context' => array( 'view' ), |
|
201 | + 'context' => array('view'), |
|
202 | 202 | 'readonly' => true, |
203 | 203 | ), |
204 | 204 | 'downloads_remaining' => array( |
205 | - 'description' => __( 'Number of downloads remaining.', 'woocommerce' ), |
|
205 | + 'description' => __('Number of downloads remaining.', 'woocommerce'), |
|
206 | 206 | 'type' => 'string', |
207 | - 'context' => array( 'view' ), |
|
207 | + 'context' => array('view'), |
|
208 | 208 | 'readonly' => true, |
209 | 209 | ), |
210 | 210 | 'access_expires' => array( |
211 | - 'description' => __( "The date when download access expires, in the site's timezone.", 'woocommerce' ), |
|
211 | + 'description' => __("The date when download access expires, in the site's timezone.", 'woocommerce'), |
|
212 | 212 | 'type' => 'string', |
213 | - 'context' => array( 'view' ), |
|
213 | + 'context' => array('view'), |
|
214 | 214 | 'readonly' => true, |
215 | 215 | ), |
216 | 216 | 'file' => array( |
217 | - 'description' => __( 'File details.', 'woocommerce' ), |
|
217 | + 'description' => __('File details.', 'woocommerce'), |
|
218 | 218 | 'type' => 'object', |
219 | - 'context' => array( 'view' ), |
|
219 | + 'context' => array('view'), |
|
220 | 220 | 'readonly' => true, |
221 | 221 | 'properties' => array( |
222 | 222 | 'name' => array( |
223 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
223 | + 'description' => __('File name.', 'woocommerce'), |
|
224 | 224 | 'type' => 'string', |
225 | - 'context' => array( 'view' ), |
|
225 | + 'context' => array('view'), |
|
226 | 226 | 'readonly' => true, |
227 | 227 | ), |
228 | 228 | 'file' => array( |
229 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
229 | + 'description' => __('File URL.', 'woocommerce'), |
|
230 | 230 | 'type' => 'string', |
231 | - 'context' => array( 'view' ), |
|
231 | + 'context' => array('view'), |
|
232 | 232 | 'readonly' => true, |
233 | 233 | ), |
234 | 234 | ), |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | ), |
237 | 237 | ); |
238 | 238 | |
239 | - return $this->add_additional_fields_schema( $schema ); |
|
239 | + return $this->add_additional_fields_schema($schema); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function get_collection_params() { |
248 | 248 | return array( |
249 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
249 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
250 | 250 | ); |
251 | 251 | } |
252 | 252 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -47,75 +47,75 @@ discard block |
||
47 | 47 | * Initialize product actions. |
48 | 48 | */ |
49 | 49 | public function __construct() { |
50 | - add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'query_args' ), 10, 2 ); |
|
51 | - add_action( "woocommerce_rest_insert_{$this->post_type}", array( $this, 'clear_transients' ) ); |
|
50 | + add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'query_args'), 10, 2); |
|
51 | + add_action("woocommerce_rest_insert_{$this->post_type}", array($this, 'clear_transients')); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Register the routes for products. |
56 | 56 | */ |
57 | 57 | public function register_routes() { |
58 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
58 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
59 | 59 | array( |
60 | 60 | 'methods' => WP_REST_Server::READABLE, |
61 | - 'callback' => array( $this, 'get_items' ), |
|
62 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
61 | + 'callback' => array($this, 'get_items'), |
|
62 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
63 | 63 | 'args' => $this->get_collection_params(), |
64 | 64 | ), |
65 | 65 | array( |
66 | 66 | 'methods' => WP_REST_Server::CREATABLE, |
67 | - 'callback' => array( $this, 'create_item' ), |
|
68 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
69 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
67 | + 'callback' => array($this, 'create_item'), |
|
68 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
69 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
70 | 70 | ), |
71 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
72 | - ) ); |
|
71 | + 'schema' => array($this, 'get_public_item_schema'), |
|
72 | + )); |
|
73 | 73 | |
74 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
74 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
75 | 75 | 'args' => array( |
76 | 76 | 'id' => array( |
77 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
77 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
78 | 78 | 'type' => 'integer', |
79 | 79 | ), |
80 | 80 | ), |
81 | 81 | array( |
82 | 82 | 'methods' => WP_REST_Server::READABLE, |
83 | - 'callback' => array( $this, 'get_item' ), |
|
84 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
83 | + 'callback' => array($this, 'get_item'), |
|
84 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
85 | 85 | 'args' => array( |
86 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
86 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
87 | 87 | ), |
88 | 88 | ), |
89 | 89 | array( |
90 | 90 | 'methods' => WP_REST_Server::EDITABLE, |
91 | - 'callback' => array( $this, 'update_item' ), |
|
92 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
93 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
91 | + 'callback' => array($this, 'update_item'), |
|
92 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
93 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
94 | 94 | ), |
95 | 95 | array( |
96 | 96 | 'methods' => WP_REST_Server::DELETABLE, |
97 | - 'callback' => array( $this, 'delete_item' ), |
|
98 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
97 | + 'callback' => array($this, 'delete_item'), |
|
98 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
99 | 99 | 'args' => array( |
100 | 100 | 'force' => array( |
101 | 101 | 'default' => false, |
102 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
102 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
103 | 103 | 'type' => 'boolean', |
104 | 104 | ), |
105 | 105 | ), |
106 | 106 | ), |
107 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
108 | - ) ); |
|
107 | + 'schema' => array($this, 'get_public_item_schema'), |
|
108 | + )); |
|
109 | 109 | |
110 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
110 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
111 | 111 | array( |
112 | 112 | 'methods' => WP_REST_Server::EDITABLE, |
113 | - 'callback' => array( $this, 'batch_items' ), |
|
114 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
115 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
113 | + 'callback' => array($this, 'batch_items'), |
|
114 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
115 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
116 | 116 | ), |
117 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
118 | - ) ); |
|
117 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
118 | + )); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @return array |
125 | 125 | */ |
126 | 126 | protected function get_post_types() { |
127 | - return array( 'product', 'product_variation' ); |
|
127 | + return array('product', 'product_variation'); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param WP_REST_Request $request Request data. |
135 | 135 | * @return array |
136 | 136 | */ |
137 | - public function query_args( $args, $request ) { |
|
137 | + public function query_args($args, $request) { |
|
138 | 138 | // Set post_status. |
139 | 139 | $args['post_status'] = $request['status']; |
140 | 140 | |
@@ -150,22 +150,22 @@ discard block |
||
150 | 150 | ); |
151 | 151 | |
152 | 152 | // Set tax_query for each passed arg. |
153 | - foreach ( $taxonomies as $taxonomy => $key ) { |
|
154 | - if ( ! empty( $request[ $key ] ) && is_array( $request[ $key ] ) ) { |
|
155 | - $request[ $key ] = array_filter( $request[ $key ] ); |
|
153 | + foreach ($taxonomies as $taxonomy => $key) { |
|
154 | + if ( ! empty($request[$key]) && is_array($request[$key])) { |
|
155 | + $request[$key] = array_filter($request[$key]); |
|
156 | 156 | } |
157 | 157 | |
158 | - if ( ! empty( $request[ $key ] ) ) { |
|
158 | + if ( ! empty($request[$key])) { |
|
159 | 159 | $tax_query[] = array( |
160 | 160 | 'taxonomy' => $taxonomy, |
161 | 161 | 'field' => 'term_id', |
162 | - 'terms' => $request[ $key ], |
|
162 | + 'terms' => $request[$key], |
|
163 | 163 | ); |
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
167 | 167 | // Filter product type by slug. |
168 | - if ( ! empty( $request['type'] ) ) { |
|
168 | + if ( ! empty($request['type'])) { |
|
169 | 169 | $tax_query[] = array( |
170 | 170 | 'taxonomy' => 'product_type', |
171 | 171 | 'field' => 'slug', |
@@ -174,8 +174,8 @@ discard block |
||
174 | 174 | } |
175 | 175 | |
176 | 176 | // Filter by attribute and term. |
177 | - if ( ! empty( $request['attribute'] ) && ! empty( $request['attribute_term'] ) ) { |
|
178 | - if ( in_array( $request['attribute'], wc_get_attribute_taxonomy_names(), true ) ) { |
|
177 | + if ( ! empty($request['attribute']) && ! empty($request['attribute_term'])) { |
|
178 | + if (in_array($request['attribute'], wc_get_attribute_taxonomy_names(), true)) { |
|
179 | 179 | $tax_query[] = array( |
180 | 180 | 'taxonomy' => $request['attribute'], |
181 | 181 | 'field' => 'term_id', |
@@ -184,34 +184,34 @@ discard block |
||
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
187 | - if ( ! empty( $tax_query ) ) { |
|
187 | + if ( ! empty($tax_query)) { |
|
188 | 188 | $args['tax_query'] = $tax_query; |
189 | 189 | } |
190 | 190 | |
191 | 191 | // Filter by sku. |
192 | - if ( ! empty( $request['sku'] ) ) { |
|
193 | - $skus = explode( ',', $request['sku'] ); |
|
192 | + if ( ! empty($request['sku'])) { |
|
193 | + $skus = explode(',', $request['sku']); |
|
194 | 194 | // Include the current string as a SKU too. |
195 | - if ( 1 < count( $skus ) ) { |
|
195 | + if (1 < count($skus)) { |
|
196 | 196 | $skus[] = $request['sku']; |
197 | 197 | } |
198 | 198 | |
199 | - $args['meta_query'] = $this->add_meta_query( $args, array( |
|
199 | + $args['meta_query'] = $this->add_meta_query($args, array( |
|
200 | 200 | 'key' => '_sku', |
201 | 201 | 'value' => $skus, |
202 | 202 | 'compare' => 'IN', |
203 | - ) ); |
|
203 | + )); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | // Apply all WP_Query filters again. |
207 | - if ( is_array( $request['filter'] ) ) { |
|
208 | - $args = array_merge( $args, $request['filter'] ); |
|
209 | - unset( $args['filter'] ); |
|
207 | + if (is_array($request['filter'])) { |
|
208 | + $args = array_merge($args, $request['filter']); |
|
209 | + unset($args['filter']); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | // Force the post_type argument, since it's not a user input variable. |
213 | - if ( ! empty( $request['sku'] ) ) { |
|
214 | - $args['post_type'] = array( 'product', 'product_variation' ); |
|
213 | + if ( ! empty($request['sku'])) { |
|
214 | + $args['post_type'] = array('product', 'product_variation'); |
|
215 | 215 | } else { |
216 | 216 | $args['post_type'] = $this->post_type; |
217 | 217 | } |
@@ -225,11 +225,11 @@ discard block |
||
225 | 225 | * @param WC_Product|WC_Product_Variation $product Product instance. |
226 | 226 | * @return array |
227 | 227 | */ |
228 | - protected function get_downloads( $product ) { |
|
228 | + protected function get_downloads($product) { |
|
229 | 229 | $downloads = array(); |
230 | 230 | |
231 | - if ( $product->is_downloadable() ) { |
|
232 | - foreach ( $product->get_downloads() as $file_id => $file ) { |
|
231 | + if ($product->is_downloadable()) { |
|
232 | + foreach ($product->get_downloads() as $file_id => $file) { |
|
233 | 233 | $downloads[] = array( |
234 | 234 | 'id' => $file_id, // MD5 hash. |
235 | 235 | 'name' => $file['name'], |
@@ -248,10 +248,10 @@ discard block |
||
248 | 248 | * @param string $taxonomy Taxonomy slug. |
249 | 249 | * @return array |
250 | 250 | */ |
251 | - protected function get_taxonomy_terms( $product, $taxonomy = 'cat' ) { |
|
251 | + protected function get_taxonomy_terms($product, $taxonomy = 'cat') { |
|
252 | 252 | $terms = array(); |
253 | 253 | |
254 | - foreach ( wc_get_object_terms( $product->get_id(), 'product_' . $taxonomy ) as $term ) { |
|
254 | + foreach (wc_get_object_terms($product->get_id(), 'product_' . $taxonomy) as $term) { |
|
255 | 255 | $terms[] = array( |
256 | 256 | 'id' => $term->term_id, |
257 | 257 | 'name' => $term->name, |
@@ -268,50 +268,50 @@ discard block |
||
268 | 268 | * @param WC_Product|WC_Product_Variation $product Product instance. |
269 | 269 | * @return array |
270 | 270 | */ |
271 | - protected function get_images( $product ) { |
|
271 | + protected function get_images($product) { |
|
272 | 272 | $images = array(); |
273 | 273 | $attachment_ids = array(); |
274 | 274 | |
275 | 275 | // Add featured image. |
276 | - if ( $product->get_image_id() ) { |
|
276 | + if ($product->get_image_id()) { |
|
277 | 277 | $attachment_ids[] = $product->get_image_id(); |
278 | 278 | } |
279 | 279 | |
280 | 280 | // Add gallery images. |
281 | - $attachment_ids = array_merge( $attachment_ids, $product->get_gallery_image_ids() ); |
|
281 | + $attachment_ids = array_merge($attachment_ids, $product->get_gallery_image_ids()); |
|
282 | 282 | |
283 | 283 | // Build image data. |
284 | - foreach ( $attachment_ids as $position => $attachment_id ) { |
|
285 | - $attachment_post = get_post( $attachment_id ); |
|
286 | - if ( is_null( $attachment_post ) ) { |
|
284 | + foreach ($attachment_ids as $position => $attachment_id) { |
|
285 | + $attachment_post = get_post($attachment_id); |
|
286 | + if (is_null($attachment_post)) { |
|
287 | 287 | continue; |
288 | 288 | } |
289 | 289 | |
290 | - $attachment = wp_get_attachment_image_src( $attachment_id, 'full' ); |
|
291 | - if ( ! is_array( $attachment ) ) { |
|
290 | + $attachment = wp_get_attachment_image_src($attachment_id, 'full'); |
|
291 | + if ( ! is_array($attachment)) { |
|
292 | 292 | continue; |
293 | 293 | } |
294 | 294 | |
295 | 295 | $images[] = array( |
296 | 296 | 'id' => (int) $attachment_id, |
297 | - 'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date_gmt ), |
|
298 | - 'date_modified' => wc_rest_prepare_date_response( $attachment_post->post_modified_gmt ), |
|
299 | - 'src' => current( $attachment ), |
|
300 | - 'name' => get_the_title( $attachment_id ), |
|
301 | - 'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ), |
|
297 | + 'date_created' => wc_rest_prepare_date_response($attachment_post->post_date_gmt), |
|
298 | + 'date_modified' => wc_rest_prepare_date_response($attachment_post->post_modified_gmt), |
|
299 | + 'src' => current($attachment), |
|
300 | + 'name' => get_the_title($attachment_id), |
|
301 | + 'alt' => get_post_meta($attachment_id, '_wp_attachment_image_alt', true), |
|
302 | 302 | 'position' => (int) $position, |
303 | 303 | ); |
304 | 304 | } |
305 | 305 | |
306 | 306 | // Set a placeholder image if the product has no images set. |
307 | - if ( empty( $images ) ) { |
|
307 | + if (empty($images)) { |
|
308 | 308 | $images[] = array( |
309 | 309 | 'id' => 0, |
310 | - 'date_created' => wc_rest_prepare_date_response( current_time( 'mysql' ) ), // Default to now. |
|
311 | - 'date_modified' => wc_rest_prepare_date_response( current_time( 'mysql' ) ), |
|
310 | + 'date_created' => wc_rest_prepare_date_response(current_time('mysql')), // Default to now. |
|
311 | + 'date_modified' => wc_rest_prepare_date_response(current_time('mysql')), |
|
312 | 312 | 'src' => wc_placeholder_img_src(), |
313 | - 'name' => __( 'Placeholder', 'woocommerce' ), |
|
314 | - 'alt' => __( 'Placeholder', 'woocommerce' ), |
|
313 | + 'name' => __('Placeholder', 'woocommerce'), |
|
314 | + 'alt' => __('Placeholder', 'woocommerce'), |
|
315 | 315 | 'position' => 0, |
316 | 316 | ); |
317 | 317 | } |
@@ -325,9 +325,9 @@ discard block |
||
325 | 325 | * @param string $name Taxonomy name. |
326 | 326 | * @return string |
327 | 327 | */ |
328 | - protected function get_attribute_taxonomy_label( $name ) { |
|
329 | - $tax = get_taxonomy( $name ); |
|
330 | - $labels = get_taxonomy_labels( $tax ); |
|
328 | + protected function get_attribute_taxonomy_label($name) { |
|
329 | + $tax = get_taxonomy($name); |
|
330 | + $labels = get_taxonomy_labels($tax); |
|
331 | 331 | |
332 | 332 | return $labels->singular_name; |
333 | 333 | } |
@@ -338,21 +338,21 @@ discard block |
||
338 | 338 | * @param WC_Product $product Product instance. |
339 | 339 | * @return array |
340 | 340 | */ |
341 | - protected function get_default_attributes( $product ) { |
|
341 | + protected function get_default_attributes($product) { |
|
342 | 342 | $default = array(); |
343 | 343 | |
344 | - if ( $product->is_type( 'variable' ) ) { |
|
345 | - foreach ( array_filter( (array) $product->get_default_attributes(), 'strlen' ) as $key => $value ) { |
|
346 | - if ( 0 === strpos( $key, 'pa_' ) ) { |
|
344 | + if ($product->is_type('variable')) { |
|
345 | + foreach (array_filter((array) $product->get_default_attributes(), 'strlen') as $key => $value) { |
|
346 | + if (0 === strpos($key, 'pa_')) { |
|
347 | 347 | $default[] = array( |
348 | - 'id' => wc_attribute_taxonomy_id_by_name( $key ), |
|
349 | - 'name' => $this->get_attribute_taxonomy_label( $key ), |
|
348 | + 'id' => wc_attribute_taxonomy_id_by_name($key), |
|
349 | + 'name' => $this->get_attribute_taxonomy_label($key), |
|
350 | 350 | 'option' => $value, |
351 | 351 | ); |
352 | 352 | } else { |
353 | 353 | $default[] = array( |
354 | 354 | 'id' => 0, |
355 | - 'name' => wc_attribute_taxonomy_slug( $key ), |
|
355 | + 'name' => wc_attribute_taxonomy_slug($key), |
|
356 | 356 | 'option' => $value, |
357 | 357 | ); |
358 | 358 | } |
@@ -369,11 +369,11 @@ discard block |
||
369 | 369 | * @param array $attribute Attribute data. |
370 | 370 | * @return array |
371 | 371 | */ |
372 | - protected function get_attribute_options( $product_id, $attribute ) { |
|
373 | - if ( isset( $attribute['is_taxonomy'] ) && $attribute['is_taxonomy'] ) { |
|
374 | - return wc_get_product_terms( $product_id, $attribute['name'], array( 'fields' => 'names' ) ); |
|
375 | - } elseif ( isset( $attribute['value'] ) ) { |
|
376 | - return array_map( 'trim', explode( '|', $attribute['value'] ) ); |
|
372 | + protected function get_attribute_options($product_id, $attribute) { |
|
373 | + if (isset($attribute['is_taxonomy']) && $attribute['is_taxonomy']) { |
|
374 | + return wc_get_product_terms($product_id, $attribute['name'], array('fields' => 'names')); |
|
375 | + } elseif (isset($attribute['value'])) { |
|
376 | + return array_map('trim', explode('|', $attribute['value'])); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | return array(); |
@@ -385,25 +385,25 @@ discard block |
||
385 | 385 | * @param WC_Product|WC_Product_Variation $product Product instance. |
386 | 386 | * @return array |
387 | 387 | */ |
388 | - protected function get_attributes( $product ) { |
|
388 | + protected function get_attributes($product) { |
|
389 | 389 | $attributes = array(); |
390 | 390 | |
391 | - if ( $product->is_type( 'variation' ) ) { |
|
391 | + if ($product->is_type('variation')) { |
|
392 | 392 | // Variation attributes. |
393 | - foreach ( $product->get_variation_attributes() as $attribute_name => $attribute ) { |
|
394 | - $name = str_replace( 'attribute_', '', $attribute_name ); |
|
393 | + foreach ($product->get_variation_attributes() as $attribute_name => $attribute) { |
|
394 | + $name = str_replace('attribute_', '', $attribute_name); |
|
395 | 395 | |
396 | - if ( ! $attribute ) { |
|
396 | + if ( ! $attribute) { |
|
397 | 397 | continue; |
398 | 398 | } |
399 | 399 | |
400 | 400 | // Taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`. |
401 | - if ( 0 === strpos( $attribute_name, 'attribute_pa_' ) ) { |
|
402 | - $option_term = get_term_by( 'slug', $attribute, $name ); |
|
401 | + if (0 === strpos($attribute_name, 'attribute_pa_')) { |
|
402 | + $option_term = get_term_by('slug', $attribute, $name); |
|
403 | 403 | $attributes[] = array( |
404 | - 'id' => wc_attribute_taxonomy_id_by_name( $name ), |
|
405 | - 'name' => $this->get_attribute_taxonomy_label( $name ), |
|
406 | - 'option' => $option_term && ! is_wp_error( $option_term ) ? $option_term->name : $attribute, |
|
404 | + 'id' => wc_attribute_taxonomy_id_by_name($name), |
|
405 | + 'name' => $this->get_attribute_taxonomy_label($name), |
|
406 | + 'option' => $option_term && ! is_wp_error($option_term) ? $option_term->name : $attribute, |
|
407 | 407 | ); |
408 | 408 | } else { |
409 | 409 | $attributes[] = array( |
@@ -414,15 +414,15 @@ discard block |
||
414 | 414 | } |
415 | 415 | } |
416 | 416 | } else { |
417 | - foreach ( $product->get_attributes() as $attribute ) { |
|
418 | - if ( $attribute['is_taxonomy'] ) { |
|
417 | + foreach ($product->get_attributes() as $attribute) { |
|
418 | + if ($attribute['is_taxonomy']) { |
|
419 | 419 | $attributes[] = array( |
420 | - 'id' => wc_attribute_taxonomy_id_by_name( $attribute['name'] ), |
|
421 | - 'name' => $this->get_attribute_taxonomy_label( $attribute['name'] ), |
|
420 | + 'id' => wc_attribute_taxonomy_id_by_name($attribute['name']), |
|
421 | + 'name' => $this->get_attribute_taxonomy_label($attribute['name']), |
|
422 | 422 | 'position' => (int) $attribute['position'], |
423 | 423 | 'visible' => (bool) $attribute['is_visible'], |
424 | 424 | 'variation' => (bool) $attribute['is_variation'], |
425 | - 'options' => $this->get_attribute_options( $product->get_id(), $attribute ), |
|
425 | + 'options' => $this->get_attribute_options($product->get_id(), $attribute), |
|
426 | 426 | ); |
427 | 427 | } else { |
428 | 428 | $attributes[] = array( |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | 'position' => (int) $attribute['position'], |
432 | 432 | 'visible' => (bool) $attribute['is_visible'], |
433 | 433 | 'variation' => (bool) $attribute['is_variation'], |
434 | - 'options' => $this->get_attribute_options( $product->get_id(), $attribute ), |
|
434 | + 'options' => $this->get_attribute_options($product->get_id(), $attribute), |
|
435 | 435 | ); |
436 | 436 | } |
437 | 437 | } |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * @param WC_Product $product Product instance. |
448 | 448 | * @return int |
449 | 449 | */ |
450 | - protected function get_product_menu_order( $product ) { |
|
450 | + protected function get_product_menu_order($product) { |
|
451 | 451 | return $product->get_menu_order(); |
452 | 452 | } |
453 | 453 | |
@@ -457,38 +457,38 @@ discard block |
||
457 | 457 | * @param WC_Product $product Product instance. |
458 | 458 | * @return array |
459 | 459 | */ |
460 | - protected function get_product_data( $product ) { |
|
460 | + protected function get_product_data($product) { |
|
461 | 461 | $data = array( |
462 | 462 | 'id' => $product->get_id(), |
463 | 463 | 'name' => $product->get_name(), |
464 | 464 | 'slug' => $product->get_slug(), |
465 | 465 | 'permalink' => $product->get_permalink(), |
466 | - 'date_created' => wc_rest_prepare_date_response( $product->get_date_created() ), |
|
467 | - 'date_modified' => wc_rest_prepare_date_response( $product->get_date_modified() ), |
|
466 | + 'date_created' => wc_rest_prepare_date_response($product->get_date_created()), |
|
467 | + 'date_modified' => wc_rest_prepare_date_response($product->get_date_modified()), |
|
468 | 468 | 'type' => $product->get_type(), |
469 | 469 | 'status' => $product->get_status(), |
470 | 470 | 'featured' => $product->is_featured(), |
471 | 471 | 'catalog_visibility' => $product->get_catalog_visibility(), |
472 | - 'description' => wpautop( do_shortcode( $product->get_description() ) ), |
|
473 | - 'short_description' => apply_filters( 'woocommerce_short_description', $product->get_short_description() ), |
|
472 | + 'description' => wpautop(do_shortcode($product->get_description())), |
|
473 | + 'short_description' => apply_filters('woocommerce_short_description', $product->get_short_description()), |
|
474 | 474 | 'sku' => $product->get_sku(), |
475 | 475 | 'price' => $product->get_price(), |
476 | 476 | 'regular_price' => $product->get_regular_price(), |
477 | 477 | 'sale_price' => $product->get_sale_price() ? $product->get_sale_price() : '', |
478 | - 'date_on_sale_from' => $product->get_date_on_sale_from() ? date( 'Y-m-d', $product->get_date_on_sale_from()->getTimestamp() ) : '', |
|
479 | - 'date_on_sale_to' => $product->get_date_on_sale_to() ? date( 'Y-m-d', $product->get_date_on_sale_to()->getTimestamp() ) : '', |
|
478 | + 'date_on_sale_from' => $product->get_date_on_sale_from() ? date('Y-m-d', $product->get_date_on_sale_from()->getTimestamp()) : '', |
|
479 | + 'date_on_sale_to' => $product->get_date_on_sale_to() ? date('Y-m-d', $product->get_date_on_sale_to()->getTimestamp()) : '', |
|
480 | 480 | 'price_html' => $product->get_price_html(), |
481 | 481 | 'on_sale' => $product->is_on_sale(), |
482 | 482 | 'purchasable' => $product->is_purchasable(), |
483 | 483 | 'total_sales' => $product->get_total_sales(), |
484 | 484 | 'virtual' => $product->is_virtual(), |
485 | 485 | 'downloadable' => $product->is_downloadable(), |
486 | - 'downloads' => $this->get_downloads( $product ), |
|
486 | + 'downloads' => $this->get_downloads($product), |
|
487 | 487 | 'download_limit' => $product->get_download_limit(), |
488 | 488 | 'download_expiry' => $product->get_download_expiry(), |
489 | 489 | 'download_type' => 'standard', |
490 | - 'external_url' => $product->is_type( 'external' ) ? $product->get_product_url() : '', |
|
491 | - 'button_text' => $product->is_type( 'external' ) ? $product->get_button_text() : '', |
|
490 | + 'external_url' => $product->is_type('external') ? $product->get_product_url() : '', |
|
491 | + 'button_text' => $product->is_type('external') ? $product->get_button_text() : '', |
|
492 | 492 | 'tax_status' => $product->get_tax_status(), |
493 | 493 | 'tax_class' => $product->get_tax_class(), |
494 | 494 | 'manage_stock' => $product->managing_stock(), |
@@ -509,18 +509,18 @@ discard block |
||
509 | 509 | 'shipping_class' => $product->get_shipping_class(), |
510 | 510 | 'shipping_class_id' => $product->get_shipping_class_id(), |
511 | 511 | 'reviews_allowed' => $product->get_reviews_allowed(), |
512 | - 'average_rating' => wc_format_decimal( $product->get_average_rating(), 2 ), |
|
512 | + 'average_rating' => wc_format_decimal($product->get_average_rating(), 2), |
|
513 | 513 | 'rating_count' => $product->get_rating_count(), |
514 | - 'related_ids' => array_map( 'absint', array_values( wc_get_related_products( $product->get_id() ) ) ), |
|
515 | - 'upsell_ids' => array_map( 'absint', $product->get_upsell_ids() ), |
|
516 | - 'cross_sell_ids' => array_map( 'absint', $product->get_cross_sell_ids() ), |
|
514 | + 'related_ids' => array_map('absint', array_values(wc_get_related_products($product->get_id()))), |
|
515 | + 'upsell_ids' => array_map('absint', $product->get_upsell_ids()), |
|
516 | + 'cross_sell_ids' => array_map('absint', $product->get_cross_sell_ids()), |
|
517 | 517 | 'parent_id' => $product->get_parent_id(), |
518 | - 'purchase_note' => wpautop( do_shortcode( wp_kses_post( $product->get_purchase_note() ) ) ), |
|
519 | - 'categories' => $this->get_taxonomy_terms( $product ), |
|
520 | - 'tags' => $this->get_taxonomy_terms( $product, 'tag' ), |
|
521 | - 'images' => $this->get_images( $product ), |
|
522 | - 'attributes' => $this->get_attributes( $product ), |
|
523 | - 'default_attributes' => $this->get_default_attributes( $product ), |
|
518 | + 'purchase_note' => wpautop(do_shortcode(wp_kses_post($product->get_purchase_note()))), |
|
519 | + 'categories' => $this->get_taxonomy_terms($product), |
|
520 | + 'tags' => $this->get_taxonomy_terms($product, 'tag'), |
|
521 | + 'images' => $this->get_images($product), |
|
522 | + 'attributes' => $this->get_attributes($product), |
|
523 | + 'default_attributes' => $this->get_default_attributes($product), |
|
524 | 524 | 'variations' => array(), |
525 | 525 | 'grouped_products' => array(), |
526 | 526 | 'menu_order' => $product->get_menu_order(), |
@@ -535,32 +535,32 @@ discard block |
||
535 | 535 | * @param WC_Product $product Product instance. |
536 | 536 | * @return array |
537 | 537 | */ |
538 | - protected function get_variation_data( $product ) { |
|
538 | + protected function get_variation_data($product) { |
|
539 | 539 | $variations = array(); |
540 | 540 | |
541 | - foreach ( $product->get_children() as $child_id ) { |
|
542 | - $variation = wc_get_product( $child_id ); |
|
543 | - if ( ! $variation || ! $variation->exists() ) { |
|
541 | + foreach ($product->get_children() as $child_id) { |
|
542 | + $variation = wc_get_product($child_id); |
|
543 | + if ( ! $variation || ! $variation->exists()) { |
|
544 | 544 | continue; |
545 | 545 | } |
546 | 546 | |
547 | 547 | $variations[] = array( |
548 | 548 | 'id' => $variation->get_id(), |
549 | - 'date_created' => wc_rest_prepare_date_response( $variation->get_date_created() ), |
|
550 | - 'date_modified' => wc_rest_prepare_date_response( $variation->get_date_modified() ), |
|
549 | + 'date_created' => wc_rest_prepare_date_response($variation->get_date_created()), |
|
550 | + 'date_modified' => wc_rest_prepare_date_response($variation->get_date_modified()), |
|
551 | 551 | 'permalink' => $variation->get_permalink(), |
552 | 552 | 'sku' => $variation->get_sku(), |
553 | 553 | 'price' => $variation->get_price(), |
554 | 554 | 'regular_price' => $variation->get_regular_price(), |
555 | 555 | 'sale_price' => $variation->get_sale_price(), |
556 | - 'date_on_sale_from' => $variation->get_date_on_sale_from() ? date( 'Y-m-d', $variation->get_date_on_sale_from()->getTimestamp() ) : '', |
|
557 | - 'date_on_sale_to' => $variation->get_date_on_sale_to() ? date( 'Y-m-d', $variation->get_date_on_sale_to()->getTimestamp() ) : '', |
|
556 | + 'date_on_sale_from' => $variation->get_date_on_sale_from() ? date('Y-m-d', $variation->get_date_on_sale_from()->getTimestamp()) : '', |
|
557 | + 'date_on_sale_to' => $variation->get_date_on_sale_to() ? date('Y-m-d', $variation->get_date_on_sale_to()->getTimestamp()) : '', |
|
558 | 558 | 'on_sale' => $variation->is_on_sale(), |
559 | 559 | 'purchasable' => $variation->is_purchasable(), |
560 | 560 | 'visible' => $variation->is_visible(), |
561 | 561 | 'virtual' => $variation->is_virtual(), |
562 | 562 | 'downloadable' => $variation->is_downloadable(), |
563 | - 'downloads' => $this->get_downloads( $variation ), |
|
563 | + 'downloads' => $this->get_downloads($variation), |
|
564 | 564 | 'download_limit' => '' !== $variation->get_download_limit() ? (int) $variation->get_download_limit() : -1, |
565 | 565 | 'download_expiry' => '' !== $variation->get_download_expiry() ? (int) $variation->get_download_expiry() : -1, |
566 | 566 | 'tax_status' => $variation->get_tax_status(), |
@@ -579,8 +579,8 @@ discard block |
||
579 | 579 | ), |
580 | 580 | 'shipping_class' => $variation->get_shipping_class(), |
581 | 581 | 'shipping_class_id' => $variation->get_shipping_class_id(), |
582 | - 'image' => $this->get_images( $variation ), |
|
583 | - 'attributes' => $this->get_attributes( $variation ), |
|
582 | + 'image' => $this->get_images($variation), |
|
583 | + 'attributes' => $this->get_attributes($variation), |
|
584 | 584 | ); |
585 | 585 | } |
586 | 586 | |
@@ -594,28 +594,28 @@ discard block |
||
594 | 594 | * @param WP_REST_Request $request Request object. |
595 | 595 | * @return WP_REST_Response |
596 | 596 | */ |
597 | - public function prepare_item_for_response( $post, $request ) { |
|
598 | - $product = wc_get_product( $post ); |
|
599 | - $data = $this->get_product_data( $product ); |
|
597 | + public function prepare_item_for_response($post, $request) { |
|
598 | + $product = wc_get_product($post); |
|
599 | + $data = $this->get_product_data($product); |
|
600 | 600 | |
601 | 601 | // Add variations to variable products. |
602 | - if ( $product->is_type( 'variable' ) && $product->has_child() ) { |
|
603 | - $data['variations'] = $this->get_variation_data( $product ); |
|
602 | + if ($product->is_type('variable') && $product->has_child()) { |
|
603 | + $data['variations'] = $this->get_variation_data($product); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | // Add grouped products data. |
607 | - if ( $product->is_type( 'grouped' ) && $product->has_child() ) { |
|
607 | + if ($product->is_type('grouped') && $product->has_child()) { |
|
608 | 608 | $data['grouped_products'] = $product->get_children(); |
609 | 609 | } |
610 | 610 | |
611 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
612 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
613 | - $data = $this->filter_response_by_context( $data, $context ); |
|
611 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
612 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
613 | + $data = $this->filter_response_by_context($data, $context); |
|
614 | 614 | |
615 | 615 | // Wrap the data in a response object. |
616 | - $response = rest_ensure_response( $data ); |
|
616 | + $response = rest_ensure_response($data); |
|
617 | 617 | |
618 | - $response->add_links( $this->prepare_links( $product, $request ) ); |
|
618 | + $response->add_links($this->prepare_links($product, $request)); |
|
619 | 619 | |
620 | 620 | /** |
621 | 621 | * Filter the data for a response. |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | * @param WP_Post $post Post object. |
628 | 628 | * @param WP_REST_Request $request Request object. |
629 | 629 | */ |
630 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request ); |
|
630 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | /** |
@@ -637,19 +637,19 @@ discard block |
||
637 | 637 | * @param WP_REST_Request $request Request object. |
638 | 638 | * @return array Links for the given product. |
639 | 639 | */ |
640 | - protected function prepare_links( $product, $request ) { |
|
640 | + protected function prepare_links($product, $request) { |
|
641 | 641 | $links = array( |
642 | 642 | 'self' => array( |
643 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $product->get_id() ) ), |
|
643 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $product->get_id())), |
|
644 | 644 | ), |
645 | 645 | 'collection' => array( |
646 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
646 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
647 | 647 | ), |
648 | 648 | ); |
649 | 649 | |
650 | - if ( $product->get_parent_id() ) { |
|
650 | + if ($product->get_parent_id()) { |
|
651 | 651 | $links['up'] = array( |
652 | - 'href' => rest_url( sprintf( '/%s/products/%d', $this->namespace, $product->get_parent_id() ) ), |
|
652 | + 'href' => rest_url(sprintf('/%s/products/%d', $this->namespace, $product->get_parent_id())), |
|
653 | 653 | ); |
654 | 654 | } |
655 | 655 | |
@@ -662,57 +662,57 @@ discard block |
||
662 | 662 | * @param WP_REST_Request $request Request object. |
663 | 663 | * @return WP_Error|stdClass $data Post object. |
664 | 664 | */ |
665 | - protected function prepare_item_for_database( $request ) { |
|
666 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
665 | + protected function prepare_item_for_database($request) { |
|
666 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
667 | 667 | |
668 | 668 | // Type is the most important part here because we need to be using the correct class and methods. |
669 | - if ( isset( $request['type'] ) ) { |
|
670 | - $classname = WC_Product_Factory::get_classname_from_product_type( $request['type'] ); |
|
669 | + if (isset($request['type'])) { |
|
670 | + $classname = WC_Product_Factory::get_classname_from_product_type($request['type']); |
|
671 | 671 | |
672 | - if ( ! class_exists( $classname ) ) { |
|
672 | + if ( ! class_exists($classname)) { |
|
673 | 673 | $classname = 'WC_Product_Simple'; |
674 | 674 | } |
675 | 675 | |
676 | - $product = new $classname( $id ); |
|
677 | - } elseif ( isset( $request['id'] ) ) { |
|
678 | - $product = wc_get_product( $id ); |
|
676 | + $product = new $classname($id); |
|
677 | + } elseif (isset($request['id'])) { |
|
678 | + $product = wc_get_product($id); |
|
679 | 679 | } else { |
680 | 680 | $product = new WC_Product_Simple(); |
681 | 681 | } |
682 | 682 | |
683 | 683 | // Post title. |
684 | - if ( isset( $request['name'] ) ) { |
|
685 | - $product->set_name( wp_filter_post_kses( $request['name'] ) ); |
|
684 | + if (isset($request['name'])) { |
|
685 | + $product->set_name(wp_filter_post_kses($request['name'])); |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | // Post content. |
689 | - if ( isset( $request['description'] ) ) { |
|
690 | - $product->set_description( wp_filter_post_kses( $request['description'] ) ); |
|
689 | + if (isset($request['description'])) { |
|
690 | + $product->set_description(wp_filter_post_kses($request['description'])); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | // Post excerpt. |
694 | - if ( isset( $request['short_description'] ) ) { |
|
695 | - $product->set_short_description( wp_filter_post_kses( $request['short_description'] ) ); |
|
694 | + if (isset($request['short_description'])) { |
|
695 | + $product->set_short_description(wp_filter_post_kses($request['short_description'])); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | // Post status. |
699 | - if ( isset( $request['status'] ) ) { |
|
700 | - $product->set_status( get_post_status_object( $request['status'] ) ? $request['status'] : 'draft' ); |
|
699 | + if (isset($request['status'])) { |
|
700 | + $product->set_status(get_post_status_object($request['status']) ? $request['status'] : 'draft'); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | // Post slug. |
704 | - if ( isset( $request['slug'] ) ) { |
|
705 | - $product->set_slug( $request['slug'] ); |
|
704 | + if (isset($request['slug'])) { |
|
705 | + $product->set_slug($request['slug']); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | // Menu order. |
709 | - if ( isset( $request['menu_order'] ) ) { |
|
710 | - $product->set_menu_order( $request['menu_order'] ); |
|
709 | + if (isset($request['menu_order'])) { |
|
710 | + $product->set_menu_order($request['menu_order']); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | // Comment status. |
714 | - if ( isset( $request['reviews_allowed'] ) ) { |
|
715 | - $product->set_reviews_allowed( $request['reviews_allowed'] ); |
|
714 | + if (isset($request['reviews_allowed'])) { |
|
715 | + $product->set_reviews_allowed($request['reviews_allowed']); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | * for inserting or updating the database. |
726 | 726 | * @param WP_REST_Request $request Request object. |
727 | 727 | */ |
728 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $product, $request ); |
|
728 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $product, $request); |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | /** |
@@ -734,18 +734,18 @@ discard block |
||
734 | 734 | * @param WP_REST_Request $request Full details about the request. |
735 | 735 | * @return WP_Error|WP_REST_Response |
736 | 736 | */ |
737 | - public function create_item( $request ) { |
|
738 | - if ( ! empty( $request['id'] ) ) { |
|
739 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
737 | + public function create_item($request) { |
|
738 | + if ( ! empty($request['id'])) { |
|
739 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
740 | 740 | } |
741 | 741 | |
742 | 742 | $product_id = 0; |
743 | 743 | |
744 | 744 | try { |
745 | - $product_id = $this->save_product( $request ); |
|
746 | - $post = get_post( $product_id ); |
|
747 | - $this->update_additional_fields_for_object( $post, $request ); |
|
748 | - $this->update_post_meta_fields( $post, $request ); |
|
745 | + $product_id = $this->save_product($request); |
|
746 | + $post = get_post($product_id); |
|
747 | + $this->update_additional_fields_for_object($post, $request); |
|
748 | + $this->update_post_meta_fields($post, $request); |
|
749 | 749 | |
750 | 750 | /** |
751 | 751 | * Fires after a single item is created or updated via the REST API. |
@@ -754,20 +754,20 @@ discard block |
||
754 | 754 | * @param WP_REST_Request $request Request object. |
755 | 755 | * @param boolean $creating True when creating item, false when updating. |
756 | 756 | */ |
757 | - do_action( 'woocommerce_rest_insert_product', $post, $request, true ); |
|
758 | - $request->set_param( 'context', 'edit' ); |
|
759 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
760 | - $response = rest_ensure_response( $response ); |
|
761 | - $response->set_status( 201 ); |
|
762 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ) ); |
|
757 | + do_action('woocommerce_rest_insert_product', $post, $request, true); |
|
758 | + $request->set_param('context', 'edit'); |
|
759 | + $response = $this->prepare_item_for_response($post, $request); |
|
760 | + $response = rest_ensure_response($response); |
|
761 | + $response->set_status(201); |
|
762 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID))); |
|
763 | 763 | |
764 | 764 | return $response; |
765 | - } catch ( WC_Data_Exception $e ) { |
|
766 | - $this->delete_post( $product_id ); |
|
767 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
768 | - } catch ( WC_REST_Exception $e ) { |
|
769 | - $this->delete_post( $product_id ); |
|
770 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
765 | + } catch (WC_Data_Exception $e) { |
|
766 | + $this->delete_post($product_id); |
|
767 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData()); |
|
768 | + } catch (WC_REST_Exception $e) { |
|
769 | + $this->delete_post($product_id); |
|
770 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
771 | 771 | } |
772 | 772 | } |
773 | 773 | |
@@ -777,18 +777,18 @@ discard block |
||
777 | 777 | * @param WP_REST_Request $request Full details about the request. |
778 | 778 | * @return WP_Error|WP_REST_Response |
779 | 779 | */ |
780 | - public function update_item( $request ) { |
|
780 | + public function update_item($request) { |
|
781 | 781 | $post_id = (int) $request['id']; |
782 | 782 | |
783 | - if ( empty( $post_id ) || get_post_type( $post_id ) !== $this->post_type ) { |
|
784 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
783 | + if (empty($post_id) || get_post_type($post_id) !== $this->post_type) { |
|
784 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | try { |
788 | - $product_id = $this->save_product( $request ); |
|
789 | - $post = get_post( $product_id ); |
|
790 | - $this->update_additional_fields_for_object( $post, $request ); |
|
791 | - $this->update_post_meta_fields( $post, $request ); |
|
788 | + $product_id = $this->save_product($request); |
|
789 | + $post = get_post($product_id); |
|
790 | + $this->update_additional_fields_for_object($post, $request); |
|
791 | + $this->update_post_meta_fields($post, $request); |
|
792 | 792 | |
793 | 793 | /** |
794 | 794 | * Fires after a single item is created or updated via the REST API. |
@@ -797,15 +797,15 @@ discard block |
||
797 | 797 | * @param WP_REST_Request $request Request object. |
798 | 798 | * @param boolean $creating True when creating item, false when updating. |
799 | 799 | */ |
800 | - do_action( 'woocommerce_rest_insert_product', $post, $request, false ); |
|
801 | - $request->set_param( 'context', 'edit' ); |
|
802 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
800 | + do_action('woocommerce_rest_insert_product', $post, $request, false); |
|
801 | + $request->set_param('context', 'edit'); |
|
802 | + $response = $this->prepare_item_for_response($post, $request); |
|
803 | 803 | |
804 | - return rest_ensure_response( $response ); |
|
805 | - } catch ( WC_Data_Exception $e ) { |
|
806 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
807 | - } catch ( WC_REST_Exception $e ) { |
|
808 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
804 | + return rest_ensure_response($response); |
|
805 | + } catch (WC_Data_Exception $e) { |
|
806 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData()); |
|
807 | + } catch (WC_REST_Exception $e) { |
|
808 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
809 | 809 | } |
810 | 810 | } |
811 | 811 | |
@@ -815,8 +815,8 @@ discard block |
||
815 | 815 | * @param WP_REST_Request $request Full details about the request. |
816 | 816 | * @return int |
817 | 817 | */ |
818 | - public function save_product( $request ) { |
|
819 | - $product = $this->prepare_item_for_database( $request ); |
|
818 | + public function save_product($request) { |
|
819 | + $product = $this->prepare_item_for_database($request); |
|
820 | 820 | return $product->save(); |
821 | 821 | } |
822 | 822 | |
@@ -828,10 +828,10 @@ discard block |
||
828 | 828 | * @param array $images |
829 | 829 | * @throws WC_REST_Exception |
830 | 830 | */ |
831 | - protected function save_product_images( $product_id, $images ) { |
|
832 | - $product = wc_get_product( $product_id ); |
|
831 | + protected function save_product_images($product_id, $images) { |
|
832 | + $product = wc_get_product($product_id); |
|
833 | 833 | |
834 | - return set_product_images( $product, $images ); |
|
834 | + return set_product_images($product, $images); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | /** |
@@ -842,54 +842,54 @@ discard block |
||
842 | 842 | * @param array $images Images data. |
843 | 843 | * @return WC_Product |
844 | 844 | */ |
845 | - protected function set_product_images( $product, $images ) { |
|
846 | - if ( is_array( $images ) ) { |
|
845 | + protected function set_product_images($product, $images) { |
|
846 | + if (is_array($images)) { |
|
847 | 847 | $gallery = array(); |
848 | 848 | |
849 | - foreach ( $images as $image ) { |
|
850 | - $attachment_id = isset( $image['id'] ) ? absint( $image['id'] ) : 0; |
|
849 | + foreach ($images as $image) { |
|
850 | + $attachment_id = isset($image['id']) ? absint($image['id']) : 0; |
|
851 | 851 | |
852 | - if ( 0 === $attachment_id && isset( $image['src'] ) ) { |
|
853 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $image['src'] ) ); |
|
852 | + if (0 === $attachment_id && isset($image['src'])) { |
|
853 | + $upload = wc_rest_upload_image_from_url(esc_url_raw($image['src'])); |
|
854 | 854 | |
855 | - if ( is_wp_error( $upload ) ) { |
|
856 | - if ( ! apply_filters( 'woocommerce_rest_suppress_image_upload_error', false, $upload, $product->get_id(), $images ) ) { |
|
857 | - throw new WC_REST_Exception( 'woocommerce_product_image_upload_error', $upload->get_error_message(), 400 ); |
|
855 | + if (is_wp_error($upload)) { |
|
856 | + if ( ! apply_filters('woocommerce_rest_suppress_image_upload_error', false, $upload, $product->get_id(), $images)) { |
|
857 | + throw new WC_REST_Exception('woocommerce_product_image_upload_error', $upload->get_error_message(), 400); |
|
858 | 858 | } else { |
859 | 859 | continue; |
860 | 860 | } |
861 | 861 | } |
862 | 862 | |
863 | - $attachment_id = wc_rest_set_uploaded_image_as_attachment( $upload, $product->get_id() ); |
|
863 | + $attachment_id = wc_rest_set_uploaded_image_as_attachment($upload, $product->get_id()); |
|
864 | 864 | } |
865 | 865 | |
866 | - if ( ! wp_attachment_is_image( $attachment_id ) ) { |
|
867 | - throw new WC_REST_Exception( 'woocommerce_product_invalid_image_id', sprintf( __( '#%s is an invalid image ID.', 'woocommerce' ), $attachment_id ), 400 ); |
|
866 | + if ( ! wp_attachment_is_image($attachment_id)) { |
|
867 | + throw new WC_REST_Exception('woocommerce_product_invalid_image_id', sprintf(__('#%s is an invalid image ID.', 'woocommerce'), $attachment_id), 400); |
|
868 | 868 | } |
869 | 869 | |
870 | - if ( isset( $image['position'] ) && 0 === absint( $image['position'] ) ) { |
|
871 | - $product->set_image_id( $attachment_id ); |
|
870 | + if (isset($image['position']) && 0 === absint($image['position'])) { |
|
871 | + $product->set_image_id($attachment_id); |
|
872 | 872 | } else { |
873 | 873 | $gallery[] = $attachment_id; |
874 | 874 | } |
875 | 875 | |
876 | 876 | // Set the image alt if present. |
877 | - if ( ! empty( $image['alt'] ) ) { |
|
878 | - update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) ); |
|
877 | + if ( ! empty($image['alt'])) { |
|
878 | + update_post_meta($attachment_id, '_wp_attachment_image_alt', wc_clean($image['alt'])); |
|
879 | 879 | } |
880 | 880 | |
881 | 881 | // Set the image name if present. |
882 | - if ( ! empty( $image['name'] ) ) { |
|
883 | - wp_update_post( array( 'ID' => $attachment_id, 'post_title' => $image['name'] ) ); |
|
882 | + if ( ! empty($image['name'])) { |
|
883 | + wp_update_post(array('ID' => $attachment_id, 'post_title' => $image['name'])); |
|
884 | 884 | } |
885 | 885 | } |
886 | 886 | |
887 | - if ( ! empty( $gallery ) ) { |
|
888 | - $product->set_gallery_image_ids( $gallery ); |
|
887 | + if ( ! empty($gallery)) { |
|
888 | + $product->set_gallery_image_ids($gallery); |
|
889 | 889 | } |
890 | 890 | } else { |
891 | - $product->set_image_id( '' ); |
|
892 | - $product->set_gallery_image_ids( array() ); |
|
891 | + $product->set_image_id(''); |
|
892 | + $product->set_gallery_image_ids(array()); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | return $product; |
@@ -902,39 +902,39 @@ discard block |
||
902 | 902 | * @param array $data Shipping data. |
903 | 903 | * @return WC_Product |
904 | 904 | */ |
905 | - protected function save_product_shipping_data( $product, $data ) { |
|
905 | + protected function save_product_shipping_data($product, $data) { |
|
906 | 906 | // Virtual. |
907 | - if ( isset( $data['virtual'] ) && true === $data['virtual'] ) { |
|
908 | - $product->set_weight( '' ); |
|
909 | - $product->set_height( '' ); |
|
910 | - $product->set_length( '' ); |
|
911 | - $product->set_width( '' ); |
|
907 | + if (isset($data['virtual']) && true === $data['virtual']) { |
|
908 | + $product->set_weight(''); |
|
909 | + $product->set_height(''); |
|
910 | + $product->set_length(''); |
|
911 | + $product->set_width(''); |
|
912 | 912 | } else { |
913 | - if ( isset( $data['weight'] ) ) { |
|
914 | - $product->set_weight( $data['weight'] ); |
|
913 | + if (isset($data['weight'])) { |
|
914 | + $product->set_weight($data['weight']); |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | // Height. |
918 | - if ( isset( $data['dimensions']['height'] ) ) { |
|
919 | - $product->set_height( $data['dimensions']['height'] ); |
|
918 | + if (isset($data['dimensions']['height'])) { |
|
919 | + $product->set_height($data['dimensions']['height']); |
|
920 | 920 | } |
921 | 921 | |
922 | 922 | // Width. |
923 | - if ( isset( $data['dimensions']['width'] ) ) { |
|
924 | - $product->set_width( $data['dimensions']['width'] ); |
|
923 | + if (isset($data['dimensions']['width'])) { |
|
924 | + $product->set_width($data['dimensions']['width']); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | // Length. |
928 | - if ( isset( $data['dimensions']['length'] ) ) { |
|
929 | - $product->set_length( $data['dimensions']['length'] ); |
|
928 | + if (isset($data['dimensions']['length'])) { |
|
929 | + $product->set_length($data['dimensions']['length']); |
|
930 | 930 | } |
931 | 931 | } |
932 | 932 | |
933 | 933 | // Shipping class. |
934 | - if ( isset( $data['shipping_class'] ) ) { |
|
934 | + if (isset($data['shipping_class'])) { |
|
935 | 935 | $data_store = $product->get_data_store(); |
936 | - $shipping_class_id = $data_store->get_shipping_class_id_by_slug( wc_clean( $data['shipping_class'] ) ); |
|
937 | - $product->set_shipping_class_id( $shipping_class_id ); |
|
936 | + $shipping_class_id = $data_store->get_shipping_class_id_by_slug(wc_clean($data['shipping_class'])); |
|
937 | + $product->set_shipping_class_id($shipping_class_id); |
|
938 | 938 | } |
939 | 939 | |
940 | 940 | return $product; |
@@ -948,24 +948,24 @@ discard block |
||
948 | 948 | * @param int $deprecated Deprecated since 3.0. |
949 | 949 | * @return WC_Product |
950 | 950 | */ |
951 | - protected function save_downloadable_files( $product, $downloads, $deprecated = 0 ) { |
|
952 | - if ( $deprecated ) { |
|
953 | - wc_deprecated_argument( 'variation_id', '3.0', 'save_downloadable_files() not requires a variation_id anymore.' ); |
|
951 | + protected function save_downloadable_files($product, $downloads, $deprecated = 0) { |
|
952 | + if ($deprecated) { |
|
953 | + wc_deprecated_argument('variation_id', '3.0', 'save_downloadable_files() not requires a variation_id anymore.'); |
|
954 | 954 | } |
955 | 955 | |
956 | 956 | $files = array(); |
957 | - foreach ( $downloads as $key => $file ) { |
|
958 | - if ( empty( $file['file'] ) ) { |
|
957 | + foreach ($downloads as $key => $file) { |
|
958 | + if (empty($file['file'])) { |
|
959 | 959 | continue; |
960 | 960 | } |
961 | 961 | |
962 | 962 | $download = new WC_Product_Download(); |
963 | - $download->set_id( ! empty( $file['id'] ) ? $file['id'] : wp_generate_uuid4() ); |
|
964 | - $download->set_name( $file['name'] ? $file['name'] : wc_get_filename_from_url( $file['file'] ) ); |
|
965 | - $download->set_file( apply_filters( 'woocommerce_file_download_path', $file['file'], $product, $key ) ); |
|
966 | - $files[] = $download; |
|
963 | + $download->set_id( ! empty($file['id']) ? $file['id'] : wp_generate_uuid4()); |
|
964 | + $download->set_name($file['name'] ? $file['name'] : wc_get_filename_from_url($file['file'])); |
|
965 | + $download->set_file(apply_filters('woocommerce_file_download_path', $file['file'], $product, $key)); |
|
966 | + $files[] = $download; |
|
967 | 967 | } |
968 | - $product->set_downloads( $files ); |
|
968 | + $product->set_downloads($files); |
|
969 | 969 | |
970 | 970 | return $product; |
971 | 971 | } |
@@ -978,13 +978,13 @@ discard block |
||
978 | 978 | * @param string $taxonomy Taxonomy name. |
979 | 979 | * @return WC_Product |
980 | 980 | */ |
981 | - protected function save_taxonomy_terms( $product, $terms, $taxonomy = 'cat' ) { |
|
982 | - $term_ids = wp_list_pluck( $terms, 'id' ); |
|
981 | + protected function save_taxonomy_terms($product, $terms, $taxonomy = 'cat') { |
|
982 | + $term_ids = wp_list_pluck($terms, 'id'); |
|
983 | 983 | |
984 | - if ( 'cat' === $taxonomy ) { |
|
985 | - $product->set_category_ids( $term_ids ); |
|
986 | - } elseif ( 'tag' === $taxonomy ) { |
|
987 | - $product->set_tag_ids( $term_ids ); |
|
984 | + if ('cat' === $taxonomy) { |
|
985 | + $product->set_category_ids($term_ids); |
|
986 | + } elseif ('tag' === $taxonomy) { |
|
987 | + $product->set_tag_ids($term_ids); |
|
988 | 988 | } |
989 | 989 | |
990 | 990 | return $product; |
@@ -999,52 +999,52 @@ discard block |
||
999 | 999 | * @param WP_REST_Request $request Request data. |
1000 | 1000 | * @return WC_Product |
1001 | 1001 | */ |
1002 | - protected function save_default_attributes( $product, $request ) { |
|
1003 | - if ( isset( $request['default_attributes'] ) && is_array( $request['default_attributes'] ) ) { |
|
1002 | + protected function save_default_attributes($product, $request) { |
|
1003 | + if (isset($request['default_attributes']) && is_array($request['default_attributes'])) { |
|
1004 | 1004 | $attributes = $product->get_attributes(); |
1005 | 1005 | $default_attributes = array(); |
1006 | 1006 | |
1007 | - foreach ( $request['default_attributes'] as $attribute ) { |
|
1007 | + foreach ($request['default_attributes'] as $attribute) { |
|
1008 | 1008 | $attribute_id = 0; |
1009 | 1009 | $attribute_name = ''; |
1010 | 1010 | |
1011 | 1011 | // Check ID for global attributes or name for product attributes. |
1012 | - if ( ! empty( $attribute['id'] ) ) { |
|
1013 | - $attribute_id = absint( $attribute['id'] ); |
|
1014 | - $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
|
1015 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
1016 | - $attribute_name = sanitize_title( $attribute['name'] ); |
|
1012 | + if ( ! empty($attribute['id'])) { |
|
1013 | + $attribute_id = absint($attribute['id']); |
|
1014 | + $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id); |
|
1015 | + } elseif ( ! empty($attribute['name'])) { |
|
1016 | + $attribute_name = sanitize_title($attribute['name']); |
|
1017 | 1017 | } |
1018 | 1018 | |
1019 | - if ( ! $attribute_id && ! $attribute_name ) { |
|
1019 | + if ( ! $attribute_id && ! $attribute_name) { |
|
1020 | 1020 | continue; |
1021 | 1021 | } |
1022 | 1022 | |
1023 | - if ( isset( $attributes[ $attribute_name ] ) ) { |
|
1024 | - $_attribute = $attributes[ $attribute_name ]; |
|
1023 | + if (isset($attributes[$attribute_name])) { |
|
1024 | + $_attribute = $attributes[$attribute_name]; |
|
1025 | 1025 | |
1026 | - if ( $_attribute['is_variation'] ) { |
|
1027 | - $value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
1026 | + if ($_attribute['is_variation']) { |
|
1027 | + $value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : ''; |
|
1028 | 1028 | |
1029 | - if ( ! empty( $_attribute['is_taxonomy'] ) ) { |
|
1029 | + if ( ! empty($_attribute['is_taxonomy'])) { |
|
1030 | 1030 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
1031 | - $term = get_term_by( 'name', $value, $attribute_name ); |
|
1031 | + $term = get_term_by('name', $value, $attribute_name); |
|
1032 | 1032 | |
1033 | - if ( $term && ! is_wp_error( $term ) ) { |
|
1033 | + if ($term && ! is_wp_error($term)) { |
|
1034 | 1034 | $value = $term->slug; |
1035 | 1035 | } else { |
1036 | - $value = sanitize_title( $value ); |
|
1036 | + $value = sanitize_title($value); |
|
1037 | 1037 | } |
1038 | 1038 | } |
1039 | 1039 | |
1040 | - if ( $value ) { |
|
1041 | - $default_attributes[ $attribute_name ] = $value; |
|
1040 | + if ($value) { |
|
1041 | + $default_attributes[$attribute_name] = $value; |
|
1042 | 1042 | } |
1043 | 1043 | } |
1044 | 1044 | } |
1045 | 1045 | } |
1046 | 1046 | |
1047 | - $product->set_default_attributes( $default_attributes ); |
|
1047 | + $product->set_default_attributes($default_attributes); |
|
1048 | 1048 | } |
1049 | 1049 | |
1050 | 1050 | return $product; |
@@ -1059,8 +1059,8 @@ discard block |
||
1059 | 1059 | * @return bool |
1060 | 1060 | * @throws WC_REST_Exception |
1061 | 1061 | */ |
1062 | - protected function save_product_meta( $product, $request ) { |
|
1063 | - $product = $this->set_product_meta( $product, $request ); |
|
1062 | + protected function save_product_meta($product, $request) { |
|
1063 | + $product = $this->set_product_meta($product, $request); |
|
1064 | 1064 | $product->save(); |
1065 | 1065 | |
1066 | 1066 | return true; |
@@ -1074,281 +1074,281 @@ discard block |
||
1074 | 1074 | * @param WP_REST_Request $request Request data. |
1075 | 1075 | * @return WC_Product |
1076 | 1076 | */ |
1077 | - protected function set_product_meta( $product, $request ) { |
|
1077 | + protected function set_product_meta($product, $request) { |
|
1078 | 1078 | // Virtual. |
1079 | - if ( isset( $request['virtual'] ) ) { |
|
1080 | - $product->set_virtual( $request['virtual'] ); |
|
1079 | + if (isset($request['virtual'])) { |
|
1080 | + $product->set_virtual($request['virtual']); |
|
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | // Tax status. |
1084 | - if ( isset( $request['tax_status'] ) ) { |
|
1085 | - $product->set_tax_status( $request['tax_status'] ); |
|
1084 | + if (isset($request['tax_status'])) { |
|
1085 | + $product->set_tax_status($request['tax_status']); |
|
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | // Tax Class. |
1089 | - if ( isset( $request['tax_class'] ) ) { |
|
1090 | - $product->set_tax_class( $request['tax_class'] ); |
|
1089 | + if (isset($request['tax_class'])) { |
|
1090 | + $product->set_tax_class($request['tax_class']); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | // Catalog Visibility. |
1094 | - if ( isset( $request['catalog_visibility'] ) ) { |
|
1095 | - $product->set_catalog_visibility( $request['catalog_visibility'] ); |
|
1094 | + if (isset($request['catalog_visibility'])) { |
|
1095 | + $product->set_catalog_visibility($request['catalog_visibility']); |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | // Purchase Note. |
1099 | - if ( isset( $request['purchase_note'] ) ) { |
|
1100 | - $product->set_purchase_note( wp_kses_post( wp_unslash( $request['purchase_note'] ) ) ); |
|
1099 | + if (isset($request['purchase_note'])) { |
|
1100 | + $product->set_purchase_note(wp_kses_post(wp_unslash($request['purchase_note']))); |
|
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | // Featured Product. |
1104 | - if ( isset( $request['featured'] ) ) { |
|
1105 | - $product->set_featured( $request['featured'] ); |
|
1104 | + if (isset($request['featured'])) { |
|
1105 | + $product->set_featured($request['featured']); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | // Shipping data. |
1109 | - $product = $this->save_product_shipping_data( $product, $request ); |
|
1109 | + $product = $this->save_product_shipping_data($product, $request); |
|
1110 | 1110 | |
1111 | 1111 | // SKU. |
1112 | - if ( isset( $request['sku'] ) ) { |
|
1113 | - $product->set_sku( wc_clean( $request['sku'] ) ); |
|
1112 | + if (isset($request['sku'])) { |
|
1113 | + $product->set_sku(wc_clean($request['sku'])); |
|
1114 | 1114 | } |
1115 | 1115 | |
1116 | 1116 | // Attributes. |
1117 | - if ( isset( $request['attributes'] ) ) { |
|
1117 | + if (isset($request['attributes'])) { |
|
1118 | 1118 | $attributes = array(); |
1119 | 1119 | |
1120 | - foreach ( $request['attributes'] as $attribute ) { |
|
1120 | + foreach ($request['attributes'] as $attribute) { |
|
1121 | 1121 | $attribute_id = 0; |
1122 | 1122 | $attribute_name = ''; |
1123 | 1123 | |
1124 | 1124 | // Check ID for global attributes or name for product attributes. |
1125 | - if ( ! empty( $attribute['id'] ) ) { |
|
1126 | - $attribute_id = absint( $attribute['id'] ); |
|
1127 | - $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
|
1128 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
1129 | - $attribute_name = wc_clean( $attribute['name'] ); |
|
1125 | + if ( ! empty($attribute['id'])) { |
|
1126 | + $attribute_id = absint($attribute['id']); |
|
1127 | + $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id); |
|
1128 | + } elseif ( ! empty($attribute['name'])) { |
|
1129 | + $attribute_name = wc_clean($attribute['name']); |
|
1130 | 1130 | } |
1131 | 1131 | |
1132 | - if ( ! $attribute_id && ! $attribute_name ) { |
|
1132 | + if ( ! $attribute_id && ! $attribute_name) { |
|
1133 | 1133 | continue; |
1134 | 1134 | } |
1135 | 1135 | |
1136 | - if ( $attribute_id ) { |
|
1136 | + if ($attribute_id) { |
|
1137 | 1137 | |
1138 | - if ( isset( $attribute['options'] ) ) { |
|
1138 | + if (isset($attribute['options'])) { |
|
1139 | 1139 | $options = $attribute['options']; |
1140 | 1140 | |
1141 | - if ( ! is_array( $attribute['options'] ) ) { |
|
1141 | + if ( ! is_array($attribute['options'])) { |
|
1142 | 1142 | // Text based attributes - Posted values are term names. |
1143 | - $options = explode( WC_DELIMITER, $options ); |
|
1143 | + $options = explode(WC_DELIMITER, $options); |
|
1144 | 1144 | } |
1145 | 1145 | |
1146 | - $values = array_map( 'wc_sanitize_term_text_based', $options ); |
|
1147 | - $values = array_filter( $values, 'strlen' ); |
|
1146 | + $values = array_map('wc_sanitize_term_text_based', $options); |
|
1147 | + $values = array_filter($values, 'strlen'); |
|
1148 | 1148 | } else { |
1149 | 1149 | $values = array(); |
1150 | 1150 | } |
1151 | 1151 | |
1152 | - if ( ! empty( $values ) ) { |
|
1152 | + if ( ! empty($values)) { |
|
1153 | 1153 | // Add attribute to array, but don't set values. |
1154 | 1154 | $attribute_object = new WC_Product_Attribute(); |
1155 | - $attribute_object->set_id( $attribute_id ); |
|
1156 | - $attribute_object->set_name( $attribute_name ); |
|
1157 | - $attribute_object->set_options( $values ); |
|
1158 | - $attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' ); |
|
1159 | - $attribute_object->set_visible( ( isset( $attribute['visible'] ) && $attribute['visible'] ) ? 1 : 0 ); |
|
1160 | - $attribute_object->set_variation( ( isset( $attribute['variation'] ) && $attribute['variation'] ) ? 1 : 0 ); |
|
1155 | + $attribute_object->set_id($attribute_id); |
|
1156 | + $attribute_object->set_name($attribute_name); |
|
1157 | + $attribute_object->set_options($values); |
|
1158 | + $attribute_object->set_position(isset($attribute['position']) ? (string) absint($attribute['position']) : '0'); |
|
1159 | + $attribute_object->set_visible((isset($attribute['visible']) && $attribute['visible']) ? 1 : 0); |
|
1160 | + $attribute_object->set_variation((isset($attribute['variation']) && $attribute['variation']) ? 1 : 0); |
|
1161 | 1161 | $attributes[] = $attribute_object; |
1162 | 1162 | } |
1163 | - } elseif ( isset( $attribute['options'] ) ) { |
|
1163 | + } elseif (isset($attribute['options'])) { |
|
1164 | 1164 | // Custom attribute - Add attribute to array and set the values. |
1165 | - if ( is_array( $attribute['options'] ) ) { |
|
1165 | + if (is_array($attribute['options'])) { |
|
1166 | 1166 | $values = $attribute['options']; |
1167 | 1167 | } else { |
1168 | - $values = explode( WC_DELIMITER, $attribute['options'] ); |
|
1168 | + $values = explode(WC_DELIMITER, $attribute['options']); |
|
1169 | 1169 | } |
1170 | 1170 | $attribute_object = new WC_Product_Attribute(); |
1171 | - $attribute_object->set_name( $attribute_name ); |
|
1172 | - $attribute_object->set_options( $values ); |
|
1173 | - $attribute_object->set_position( isset( $attribute['position'] ) ? (string) absint( $attribute['position'] ) : '0' ); |
|
1174 | - $attribute_object->set_visible( ( isset( $attribute['visible'] ) && $attribute['visible'] ) ? 1 : 0 ); |
|
1175 | - $attribute_object->set_variation( ( isset( $attribute['variation'] ) && $attribute['variation'] ) ? 1 : 0 ); |
|
1171 | + $attribute_object->set_name($attribute_name); |
|
1172 | + $attribute_object->set_options($values); |
|
1173 | + $attribute_object->set_position(isset($attribute['position']) ? (string) absint($attribute['position']) : '0'); |
|
1174 | + $attribute_object->set_visible((isset($attribute['visible']) && $attribute['visible']) ? 1 : 0); |
|
1175 | + $attribute_object->set_variation((isset($attribute['variation']) && $attribute['variation']) ? 1 : 0); |
|
1176 | 1176 | $attributes[] = $attribute_object; |
1177 | 1177 | } |
1178 | 1178 | } |
1179 | - $product->set_attributes( $attributes ); |
|
1179 | + $product->set_attributes($attributes); |
|
1180 | 1180 | } |
1181 | 1181 | |
1182 | 1182 | // Sales and prices. |
1183 | - if ( in_array( $product->get_type(), array( 'variable', 'grouped' ), true ) ) { |
|
1184 | - $product->set_regular_price( '' ); |
|
1185 | - $product->set_sale_price( '' ); |
|
1186 | - $product->set_date_on_sale_to( '' ); |
|
1187 | - $product->set_date_on_sale_from( '' ); |
|
1188 | - $product->set_price( '' ); |
|
1183 | + if (in_array($product->get_type(), array('variable', 'grouped'), true)) { |
|
1184 | + $product->set_regular_price(''); |
|
1185 | + $product->set_sale_price(''); |
|
1186 | + $product->set_date_on_sale_to(''); |
|
1187 | + $product->set_date_on_sale_from(''); |
|
1188 | + $product->set_price(''); |
|
1189 | 1189 | } else { |
1190 | 1190 | // Regular Price. |
1191 | - if ( isset( $request['regular_price'] ) ) { |
|
1192 | - $product->set_regular_price( $request['regular_price'] ); |
|
1191 | + if (isset($request['regular_price'])) { |
|
1192 | + $product->set_regular_price($request['regular_price']); |
|
1193 | 1193 | } |
1194 | 1194 | |
1195 | 1195 | // Sale Price. |
1196 | - if ( isset( $request['sale_price'] ) ) { |
|
1197 | - $product->set_sale_price( $request['sale_price'] ); |
|
1196 | + if (isset($request['sale_price'])) { |
|
1197 | + $product->set_sale_price($request['sale_price']); |
|
1198 | 1198 | } |
1199 | 1199 | |
1200 | - if ( isset( $request['date_on_sale_from'] ) ) { |
|
1201 | - $product->set_date_on_sale_from( $request['date_on_sale_from'] ); |
|
1200 | + if (isset($request['date_on_sale_from'])) { |
|
1201 | + $product->set_date_on_sale_from($request['date_on_sale_from']); |
|
1202 | 1202 | } |
1203 | 1203 | |
1204 | - if ( isset( $request['date_on_sale_to'] ) ) { |
|
1205 | - $product->set_date_on_sale_to( $request['date_on_sale_to'] ); |
|
1204 | + if (isset($request['date_on_sale_to'])) { |
|
1205 | + $product->set_date_on_sale_to($request['date_on_sale_to']); |
|
1206 | 1206 | } |
1207 | 1207 | } |
1208 | 1208 | |
1209 | 1209 | // Product parent ID for groups. |
1210 | - if ( isset( $request['parent_id'] ) ) { |
|
1211 | - $product->set_parent_id( $request['parent_id'] ); |
|
1210 | + if (isset($request['parent_id'])) { |
|
1211 | + $product->set_parent_id($request['parent_id']); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | // Sold individually. |
1215 | - if ( isset( $request['sold_individually'] ) ) { |
|
1216 | - $product->set_sold_individually( $request['sold_individually'] ); |
|
1215 | + if (isset($request['sold_individually'])) { |
|
1216 | + $product->set_sold_individually($request['sold_individually']); |
|
1217 | 1217 | } |
1218 | 1218 | |
1219 | 1219 | // Stock status. |
1220 | - if ( isset( $request['in_stock'] ) ) { |
|
1220 | + if (isset($request['in_stock'])) { |
|
1221 | 1221 | $stock_status = true === $request['in_stock'] ? 'instock' : 'outofstock'; |
1222 | 1222 | } else { |
1223 | 1223 | $stock_status = $product->get_stock_status(); |
1224 | 1224 | } |
1225 | 1225 | |
1226 | 1226 | // Stock data. |
1227 | - if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) { |
|
1227 | + if ('yes' === get_option('woocommerce_manage_stock')) { |
|
1228 | 1228 | // Manage stock. |
1229 | - if ( isset( $request['manage_stock'] ) ) { |
|
1230 | - $product->set_manage_stock( $request['manage_stock'] ); |
|
1229 | + if (isset($request['manage_stock'])) { |
|
1230 | + $product->set_manage_stock($request['manage_stock']); |
|
1231 | 1231 | } |
1232 | 1232 | |
1233 | 1233 | // Backorders. |
1234 | - if ( isset( $request['backorders'] ) ) { |
|
1235 | - $product->set_backorders( $request['backorders'] ); |
|
1234 | + if (isset($request['backorders'])) { |
|
1235 | + $product->set_backorders($request['backorders']); |
|
1236 | 1236 | } |
1237 | 1237 | |
1238 | - if ( $product->is_type( 'grouped' ) ) { |
|
1239 | - $product->set_manage_stock( 'no' ); |
|
1240 | - $product->set_backorders( 'no' ); |
|
1241 | - $product->set_stock_quantity( '' ); |
|
1242 | - $product->set_stock_status( $stock_status ); |
|
1243 | - } elseif ( $product->is_type( 'external' ) ) { |
|
1244 | - $product->set_manage_stock( 'no' ); |
|
1245 | - $product->set_backorders( 'no' ); |
|
1246 | - $product->set_stock_quantity( '' ); |
|
1247 | - $product->set_stock_status( 'instock' ); |
|
1248 | - } elseif ( $product->get_manage_stock() ) { |
|
1238 | + if ($product->is_type('grouped')) { |
|
1239 | + $product->set_manage_stock('no'); |
|
1240 | + $product->set_backorders('no'); |
|
1241 | + $product->set_stock_quantity(''); |
|
1242 | + $product->set_stock_status($stock_status); |
|
1243 | + } elseif ($product->is_type('external')) { |
|
1244 | + $product->set_manage_stock('no'); |
|
1245 | + $product->set_backorders('no'); |
|
1246 | + $product->set_stock_quantity(''); |
|
1247 | + $product->set_stock_status('instock'); |
|
1248 | + } elseif ($product->get_manage_stock()) { |
|
1249 | 1249 | // Stock status is always determined by children so sync later. |
1250 | - if ( ! $product->is_type( 'variable' ) ) { |
|
1251 | - $product->set_stock_status( $stock_status ); |
|
1250 | + if ( ! $product->is_type('variable')) { |
|
1251 | + $product->set_stock_status($stock_status); |
|
1252 | 1252 | } |
1253 | 1253 | |
1254 | 1254 | // Stock quantity. |
1255 | - if ( isset( $request['stock_quantity'] ) ) { |
|
1256 | - $product->set_stock_quantity( wc_stock_amount( $request['stock_quantity'] ) ); |
|
1257 | - } elseif ( isset( $request['inventory_delta'] ) ) { |
|
1258 | - $stock_quantity = wc_stock_amount( $product->get_stock_quantity() ); |
|
1259 | - $stock_quantity += wc_stock_amount( $request['inventory_delta'] ); |
|
1260 | - $product->set_stock_quantity( wc_stock_amount( $stock_quantity ) ); |
|
1255 | + if (isset($request['stock_quantity'])) { |
|
1256 | + $product->set_stock_quantity(wc_stock_amount($request['stock_quantity'])); |
|
1257 | + } elseif (isset($request['inventory_delta'])) { |
|
1258 | + $stock_quantity = wc_stock_amount($product->get_stock_quantity()); |
|
1259 | + $stock_quantity += wc_stock_amount($request['inventory_delta']); |
|
1260 | + $product->set_stock_quantity(wc_stock_amount($stock_quantity)); |
|
1261 | 1261 | } |
1262 | 1262 | } else { |
1263 | 1263 | // Don't manage stock. |
1264 | - $product->set_manage_stock( 'no' ); |
|
1265 | - $product->set_stock_quantity( '' ); |
|
1266 | - $product->set_stock_status( $stock_status ); |
|
1264 | + $product->set_manage_stock('no'); |
|
1265 | + $product->set_stock_quantity(''); |
|
1266 | + $product->set_stock_status($stock_status); |
|
1267 | 1267 | } |
1268 | - } elseif ( ! $product->is_type( 'variable' ) ) { |
|
1269 | - $product->set_stock_status( $stock_status ); |
|
1268 | + } elseif ( ! $product->is_type('variable')) { |
|
1269 | + $product->set_stock_status($stock_status); |
|
1270 | 1270 | } |
1271 | 1271 | |
1272 | 1272 | // Upsells. |
1273 | - if ( isset( $request['upsell_ids'] ) ) { |
|
1273 | + if (isset($request['upsell_ids'])) { |
|
1274 | 1274 | $upsells = array(); |
1275 | 1275 | $ids = $request['upsell_ids']; |
1276 | 1276 | |
1277 | - if ( ! empty( $ids ) ) { |
|
1278 | - foreach ( $ids as $id ) { |
|
1279 | - if ( $id && $id > 0 ) { |
|
1277 | + if ( ! empty($ids)) { |
|
1278 | + foreach ($ids as $id) { |
|
1279 | + if ($id && $id > 0) { |
|
1280 | 1280 | $upsells[] = $id; |
1281 | 1281 | } |
1282 | 1282 | } |
1283 | 1283 | } |
1284 | 1284 | |
1285 | - $product->set_upsell_ids( $upsells ); |
|
1285 | + $product->set_upsell_ids($upsells); |
|
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | // Cross sells. |
1289 | - if ( isset( $request['cross_sell_ids'] ) ) { |
|
1289 | + if (isset($request['cross_sell_ids'])) { |
|
1290 | 1290 | $crosssells = array(); |
1291 | 1291 | $ids = $request['cross_sell_ids']; |
1292 | 1292 | |
1293 | - if ( ! empty( $ids ) ) { |
|
1294 | - foreach ( $ids as $id ) { |
|
1295 | - if ( $id && $id > 0 ) { |
|
1293 | + if ( ! empty($ids)) { |
|
1294 | + foreach ($ids as $id) { |
|
1295 | + if ($id && $id > 0) { |
|
1296 | 1296 | $crosssells[] = $id; |
1297 | 1297 | } |
1298 | 1298 | } |
1299 | 1299 | } |
1300 | 1300 | |
1301 | - $product->set_cross_sell_ids( $crosssells ); |
|
1301 | + $product->set_cross_sell_ids($crosssells); |
|
1302 | 1302 | } |
1303 | 1303 | |
1304 | 1304 | // Product categories. |
1305 | - if ( isset( $request['categories'] ) && is_array( $request['categories'] ) ) { |
|
1306 | - $product = $this->save_taxonomy_terms( $product, $request['categories'] ); |
|
1305 | + if (isset($request['categories']) && is_array($request['categories'])) { |
|
1306 | + $product = $this->save_taxonomy_terms($product, $request['categories']); |
|
1307 | 1307 | } |
1308 | 1308 | |
1309 | 1309 | // Product tags. |
1310 | - if ( isset( $request['tags'] ) && is_array( $request['tags'] ) ) { |
|
1311 | - $product = $this->save_taxonomy_terms( $product, $request['tags'], 'tag' ); |
|
1310 | + if (isset($request['tags']) && is_array($request['tags'])) { |
|
1311 | + $product = $this->save_taxonomy_terms($product, $request['tags'], 'tag'); |
|
1312 | 1312 | } |
1313 | 1313 | |
1314 | 1314 | // Downloadable. |
1315 | - if ( isset( $request['downloadable'] ) ) { |
|
1316 | - $product->set_downloadable( $request['downloadable'] ); |
|
1315 | + if (isset($request['downloadable'])) { |
|
1316 | + $product->set_downloadable($request['downloadable']); |
|
1317 | 1317 | } |
1318 | 1318 | |
1319 | 1319 | // Downloadable options. |
1320 | - if ( $product->get_downloadable() ) { |
|
1320 | + if ($product->get_downloadable()) { |
|
1321 | 1321 | |
1322 | 1322 | // Downloadable files. |
1323 | - if ( isset( $request['downloads'] ) && is_array( $request['downloads'] ) ) { |
|
1324 | - $product = $this->save_downloadable_files( $product, $request['downloads'] ); |
|
1323 | + if (isset($request['downloads']) && is_array($request['downloads'])) { |
|
1324 | + $product = $this->save_downloadable_files($product, $request['downloads']); |
|
1325 | 1325 | } |
1326 | 1326 | |
1327 | 1327 | // Download limit. |
1328 | - if ( isset( $request['download_limit'] ) ) { |
|
1329 | - $product->set_download_limit( $request['download_limit'] ); |
|
1328 | + if (isset($request['download_limit'])) { |
|
1329 | + $product->set_download_limit($request['download_limit']); |
|
1330 | 1330 | } |
1331 | 1331 | |
1332 | 1332 | // Download expiry. |
1333 | - if ( isset( $request['download_expiry'] ) ) { |
|
1334 | - $product->set_download_expiry( $request['download_expiry'] ); |
|
1333 | + if (isset($request['download_expiry'])) { |
|
1334 | + $product->set_download_expiry($request['download_expiry']); |
|
1335 | 1335 | } |
1336 | 1336 | } |
1337 | 1337 | |
1338 | 1338 | // Product url and button text for external products. |
1339 | - if ( $product->is_type( 'external' ) ) { |
|
1340 | - if ( isset( $request['external_url'] ) ) { |
|
1341 | - $product->set_product_url( $request['external_url'] ); |
|
1339 | + if ($product->is_type('external')) { |
|
1340 | + if (isset($request['external_url'])) { |
|
1341 | + $product->set_product_url($request['external_url']); |
|
1342 | 1342 | } |
1343 | 1343 | |
1344 | - if ( isset( $request['button_text'] ) ) { |
|
1345 | - $product->set_button_text( $request['button_text'] ); |
|
1344 | + if (isset($request['button_text'])) { |
|
1345 | + $product->set_button_text($request['button_text']); |
|
1346 | 1346 | } |
1347 | 1347 | } |
1348 | 1348 | |
1349 | 1349 | // Save default attributes for variable products. |
1350 | - if ( $product->is_type( 'variable' ) ) { |
|
1351 | - $product = $this->save_default_attributes( $product, $request ); |
|
1350 | + if ($product->is_type('variable')) { |
|
1351 | + $product = $this->save_default_attributes($product, $request); |
|
1352 | 1352 | } |
1353 | 1353 | |
1354 | 1354 | return $product; |
@@ -1362,177 +1362,177 @@ discard block |
||
1362 | 1362 | * @param WP_REST_Request $request Request data. |
1363 | 1363 | * @return bool |
1364 | 1364 | */ |
1365 | - protected function save_variations_data( $product, $request ) { |
|
1366 | - foreach ( $request['variations'] as $menu_order => $data ) { |
|
1367 | - $variation = new WC_Product_Variation( isset( $data['id'] ) ? absint( $data['id'] ) : 0 ); |
|
1365 | + protected function save_variations_data($product, $request) { |
|
1366 | + foreach ($request['variations'] as $menu_order => $data) { |
|
1367 | + $variation = new WC_Product_Variation(isset($data['id']) ? absint($data['id']) : 0); |
|
1368 | 1368 | |
1369 | 1369 | // Create initial name and status. |
1370 | - if ( ! $variation->get_slug() ) { |
|
1370 | + if ( ! $variation->get_slug()) { |
|
1371 | 1371 | /* translators: 1: variation id 2: product name */ |
1372 | - $variation->set_name( sprintf( __( 'Variation #%1$s of %2$s', 'woocommerce' ), $variation->get_id(), $product->get_name() ) ); |
|
1373 | - $variation->set_status( isset( $data['visible'] ) && false === $data['visible'] ? 'private' : 'publish' ); |
|
1372 | + $variation->set_name(sprintf(__('Variation #%1$s of %2$s', 'woocommerce'), $variation->get_id(), $product->get_name())); |
|
1373 | + $variation->set_status(isset($data['visible']) && false === $data['visible'] ? 'private' : 'publish'); |
|
1374 | 1374 | } |
1375 | 1375 | |
1376 | 1376 | // Parent ID. |
1377 | - $variation->set_parent_id( $product->get_id() ); |
|
1377 | + $variation->set_parent_id($product->get_id()); |
|
1378 | 1378 | |
1379 | 1379 | // Menu order. |
1380 | - $variation->set_menu_order( $menu_order ); |
|
1380 | + $variation->set_menu_order($menu_order); |
|
1381 | 1381 | |
1382 | 1382 | // Status. |
1383 | - if ( isset( $data['visible'] ) ) { |
|
1384 | - $variation->set_status( false === $data['visible'] ? 'private' : 'publish' ); |
|
1383 | + if (isset($data['visible'])) { |
|
1384 | + $variation->set_status(false === $data['visible'] ? 'private' : 'publish'); |
|
1385 | 1385 | } |
1386 | 1386 | |
1387 | 1387 | // SKU. |
1388 | - if ( isset( $data['sku'] ) ) { |
|
1389 | - $variation->set_sku( wc_clean( $data['sku'] ) ); |
|
1388 | + if (isset($data['sku'])) { |
|
1389 | + $variation->set_sku(wc_clean($data['sku'])); |
|
1390 | 1390 | } |
1391 | 1391 | |
1392 | 1392 | // Thumbnail. |
1393 | - if ( isset( $data['image'] ) && is_array( $data['image'] ) ) { |
|
1393 | + if (isset($data['image']) && is_array($data['image'])) { |
|
1394 | 1394 | $image = $data['image']; |
1395 | - $image = current( $image ); |
|
1396 | - if ( is_array( $image ) ) { |
|
1395 | + $image = current($image); |
|
1396 | + if (is_array($image)) { |
|
1397 | 1397 | $image['position'] = 0; |
1398 | 1398 | } |
1399 | 1399 | |
1400 | - $variation = $this->set_product_images( $variation, array( $image ) ); |
|
1400 | + $variation = $this->set_product_images($variation, array($image)); |
|
1401 | 1401 | } |
1402 | 1402 | |
1403 | 1403 | // Virtual variation. |
1404 | - if ( isset( $data['virtual'] ) ) { |
|
1405 | - $variation->set_virtual( $data['virtual'] ); |
|
1404 | + if (isset($data['virtual'])) { |
|
1405 | + $variation->set_virtual($data['virtual']); |
|
1406 | 1406 | } |
1407 | 1407 | |
1408 | 1408 | // Downloadable variation. |
1409 | - if ( isset( $data['downloadable'] ) ) { |
|
1410 | - $variation->set_downloadable( $data['downloadable'] ); |
|
1409 | + if (isset($data['downloadable'])) { |
|
1410 | + $variation->set_downloadable($data['downloadable']); |
|
1411 | 1411 | } |
1412 | 1412 | |
1413 | 1413 | // Downloads. |
1414 | - if ( $variation->get_downloadable() ) { |
|
1414 | + if ($variation->get_downloadable()) { |
|
1415 | 1415 | // Downloadable files. |
1416 | - if ( isset( $data['downloads'] ) && is_array( $data['downloads'] ) ) { |
|
1417 | - $variation = $this->save_downloadable_files( $variation, $data['downloads'] ); |
|
1416 | + if (isset($data['downloads']) && is_array($data['downloads'])) { |
|
1417 | + $variation = $this->save_downloadable_files($variation, $data['downloads']); |
|
1418 | 1418 | } |
1419 | 1419 | |
1420 | 1420 | // Download limit. |
1421 | - if ( isset( $data['download_limit'] ) ) { |
|
1422 | - $variation->set_download_limit( $data['download_limit'] ); |
|
1421 | + if (isset($data['download_limit'])) { |
|
1422 | + $variation->set_download_limit($data['download_limit']); |
|
1423 | 1423 | } |
1424 | 1424 | |
1425 | 1425 | // Download expiry. |
1426 | - if ( isset( $data['download_expiry'] ) ) { |
|
1427 | - $variation->set_download_expiry( $data['download_expiry'] ); |
|
1426 | + if (isset($data['download_expiry'])) { |
|
1427 | + $variation->set_download_expiry($data['download_expiry']); |
|
1428 | 1428 | } |
1429 | 1429 | } |
1430 | 1430 | |
1431 | 1431 | // Shipping data. |
1432 | - $variation = $this->save_product_shipping_data( $variation, $data ); |
|
1432 | + $variation = $this->save_product_shipping_data($variation, $data); |
|
1433 | 1433 | |
1434 | 1434 | // Stock handling. |
1435 | - if ( isset( $data['manage_stock'] ) ) { |
|
1436 | - $variation->set_manage_stock( $data['manage_stock'] ); |
|
1435 | + if (isset($data['manage_stock'])) { |
|
1436 | + $variation->set_manage_stock($data['manage_stock']); |
|
1437 | 1437 | } |
1438 | 1438 | |
1439 | - if ( isset( $data['in_stock'] ) ) { |
|
1440 | - $variation->set_stock_status( true === $data['in_stock'] ? 'instock' : 'outofstock' ); |
|
1439 | + if (isset($data['in_stock'])) { |
|
1440 | + $variation->set_stock_status(true === $data['in_stock'] ? 'instock' : 'outofstock'); |
|
1441 | 1441 | } |
1442 | 1442 | |
1443 | - if ( isset( $data['backorders'] ) ) { |
|
1444 | - $variation->set_backorders( $data['backorders'] ); |
|
1443 | + if (isset($data['backorders'])) { |
|
1444 | + $variation->set_backorders($data['backorders']); |
|
1445 | 1445 | } |
1446 | 1446 | |
1447 | - if ( $variation->get_manage_stock() ) { |
|
1448 | - if ( isset( $data['stock_quantity'] ) ) { |
|
1449 | - $variation->set_stock_quantity( $data['stock_quantity'] ); |
|
1450 | - } elseif ( isset( $data['inventory_delta'] ) ) { |
|
1451 | - $stock_quantity = wc_stock_amount( $variation->get_stock_quantity() ); |
|
1452 | - $stock_quantity += wc_stock_amount( $data['inventory_delta'] ); |
|
1453 | - $variation->set_stock_quantity( $stock_quantity ); |
|
1447 | + if ($variation->get_manage_stock()) { |
|
1448 | + if (isset($data['stock_quantity'])) { |
|
1449 | + $variation->set_stock_quantity($data['stock_quantity']); |
|
1450 | + } elseif (isset($data['inventory_delta'])) { |
|
1451 | + $stock_quantity = wc_stock_amount($variation->get_stock_quantity()); |
|
1452 | + $stock_quantity += wc_stock_amount($data['inventory_delta']); |
|
1453 | + $variation->set_stock_quantity($stock_quantity); |
|
1454 | 1454 | } |
1455 | 1455 | } else { |
1456 | - $variation->set_backorders( 'no' ); |
|
1457 | - $variation->set_stock_quantity( '' ); |
|
1456 | + $variation->set_backorders('no'); |
|
1457 | + $variation->set_stock_quantity(''); |
|
1458 | 1458 | } |
1459 | 1459 | |
1460 | 1460 | // Regular Price. |
1461 | - if ( isset( $data['regular_price'] ) ) { |
|
1462 | - $variation->set_regular_price( $data['regular_price'] ); |
|
1461 | + if (isset($data['regular_price'])) { |
|
1462 | + $variation->set_regular_price($data['regular_price']); |
|
1463 | 1463 | } |
1464 | 1464 | |
1465 | 1465 | // Sale Price. |
1466 | - if ( isset( $data['sale_price'] ) ) { |
|
1467 | - $variation->set_sale_price( $data['sale_price'] ); |
|
1466 | + if (isset($data['sale_price'])) { |
|
1467 | + $variation->set_sale_price($data['sale_price']); |
|
1468 | 1468 | } |
1469 | 1469 | |
1470 | - if ( isset( $data['date_on_sale_from'] ) ) { |
|
1471 | - $variation->set_date_on_sale_from( $data['date_on_sale_from'] ); |
|
1470 | + if (isset($data['date_on_sale_from'])) { |
|
1471 | + $variation->set_date_on_sale_from($data['date_on_sale_from']); |
|
1472 | 1472 | } |
1473 | 1473 | |
1474 | - if ( isset( $data['date_on_sale_to'] ) ) { |
|
1475 | - $variation->set_date_on_sale_to( $data['date_on_sale_to'] ); |
|
1474 | + if (isset($data['date_on_sale_to'])) { |
|
1475 | + $variation->set_date_on_sale_to($data['date_on_sale_to']); |
|
1476 | 1476 | } |
1477 | 1477 | |
1478 | 1478 | // Tax class. |
1479 | - if ( isset( $data['tax_class'] ) ) { |
|
1480 | - $variation->set_tax_class( $data['tax_class'] ); |
|
1479 | + if (isset($data['tax_class'])) { |
|
1480 | + $variation->set_tax_class($data['tax_class']); |
|
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | // Description. |
1484 | - if ( isset( $data['description'] ) ) { |
|
1485 | - $variation->set_description( wp_kses_post( $data['description'] ) ); |
|
1484 | + if (isset($data['description'])) { |
|
1485 | + $variation->set_description(wp_kses_post($data['description'])); |
|
1486 | 1486 | } |
1487 | 1487 | |
1488 | 1488 | // Update taxonomies. |
1489 | - if ( isset( $data['attributes'] ) ) { |
|
1489 | + if (isset($data['attributes'])) { |
|
1490 | 1490 | $attributes = array(); |
1491 | 1491 | $parent_attributes = $product->get_attributes(); |
1492 | 1492 | |
1493 | - foreach ( $data['attributes'] as $attribute ) { |
|
1493 | + foreach ($data['attributes'] as $attribute) { |
|
1494 | 1494 | $attribute_id = 0; |
1495 | 1495 | $attribute_name = ''; |
1496 | 1496 | |
1497 | 1497 | // Check ID for global attributes or name for product attributes. |
1498 | - if ( ! empty( $attribute['id'] ) ) { |
|
1499 | - $attribute_id = absint( $attribute['id'] ); |
|
1500 | - $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); |
|
1501 | - } elseif ( ! empty( $attribute['name'] ) ) { |
|
1502 | - $attribute_name = sanitize_title( $attribute['name'] ); |
|
1498 | + if ( ! empty($attribute['id'])) { |
|
1499 | + $attribute_id = absint($attribute['id']); |
|
1500 | + $attribute_name = wc_attribute_taxonomy_name_by_id($attribute_id); |
|
1501 | + } elseif ( ! empty($attribute['name'])) { |
|
1502 | + $attribute_name = sanitize_title($attribute['name']); |
|
1503 | 1503 | } |
1504 | 1504 | |
1505 | - if ( ! $attribute_id && ! $attribute_name ) { |
|
1505 | + if ( ! $attribute_id && ! $attribute_name) { |
|
1506 | 1506 | continue; |
1507 | 1507 | } |
1508 | 1508 | |
1509 | - if ( ! isset( $parent_attributes[ $attribute_name ] ) || ! $parent_attributes[ $attribute_name ]->get_variation() ) { |
|
1509 | + if ( ! isset($parent_attributes[$attribute_name]) || ! $parent_attributes[$attribute_name]->get_variation()) { |
|
1510 | 1510 | continue; |
1511 | 1511 | } |
1512 | 1512 | |
1513 | - $attribute_key = sanitize_title( $parent_attributes[ $attribute_name ]->get_name() ); |
|
1514 | - $attribute_value = isset( $attribute['option'] ) ? wc_clean( stripslashes( $attribute['option'] ) ) : ''; |
|
1513 | + $attribute_key = sanitize_title($parent_attributes[$attribute_name]->get_name()); |
|
1514 | + $attribute_value = isset($attribute['option']) ? wc_clean(stripslashes($attribute['option'])) : ''; |
|
1515 | 1515 | |
1516 | - if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) { |
|
1516 | + if ($parent_attributes[$attribute_name]->is_taxonomy()) { |
|
1517 | 1517 | // If dealing with a taxonomy, we need to get the slug from the name posted to the API. |
1518 | - $term = get_term_by( 'name', $attribute_value, $attribute_name ); |
|
1518 | + $term = get_term_by('name', $attribute_value, $attribute_name); |
|
1519 | 1519 | |
1520 | - if ( $term && ! is_wp_error( $term ) ) { |
|
1520 | + if ($term && ! is_wp_error($term)) { |
|
1521 | 1521 | $attribute_value = $term->slug; |
1522 | 1522 | } else { |
1523 | - $attribute_value = sanitize_title( $attribute_value ); |
|
1523 | + $attribute_value = sanitize_title($attribute_value); |
|
1524 | 1524 | } |
1525 | 1525 | } |
1526 | 1526 | |
1527 | - $attributes[ $attribute_key ] = $attribute_value; |
|
1527 | + $attributes[$attribute_key] = $attribute_value; |
|
1528 | 1528 | } |
1529 | 1529 | |
1530 | - $variation->set_attributes( $attributes ); |
|
1530 | + $variation->set_attributes($attributes); |
|
1531 | 1531 | } |
1532 | 1532 | |
1533 | 1533 | $variation->save(); |
1534 | 1534 | |
1535 | - do_action( 'woocommerce_rest_save_product_variation', $variation->get_id(), $menu_order, $data ); |
|
1535 | + do_action('woocommerce_rest_save_product_variation', $variation->get_id(), $menu_order, $data); |
|
1536 | 1536 | } |
1537 | 1537 | |
1538 | 1538 | return true; |
@@ -1545,8 +1545,8 @@ discard block |
||
1545 | 1545 | * @param WP_REST_Request $request Request data. |
1546 | 1546 | * @return bool|WP_Error |
1547 | 1547 | */ |
1548 | - protected function add_post_meta_fields( $post, $request ) { |
|
1549 | - return $this->update_post_meta_fields( $post, $request ); |
|
1548 | + protected function add_post_meta_fields($post, $request) { |
|
1549 | + return $this->update_post_meta_fields($post, $request); |
|
1550 | 1550 | } |
1551 | 1551 | |
1552 | 1552 | /** |
@@ -1556,30 +1556,30 @@ discard block |
||
1556 | 1556 | * @param WP_REST_Request $request Request data. |
1557 | 1557 | * @return bool|WP_Error |
1558 | 1558 | */ |
1559 | - protected function update_post_meta_fields( $post, $request ) { |
|
1560 | - $product = wc_get_product( $post ); |
|
1559 | + protected function update_post_meta_fields($post, $request) { |
|
1560 | + $product = wc_get_product($post); |
|
1561 | 1561 | |
1562 | 1562 | // Check for featured/gallery images, upload it and set it. |
1563 | - if ( isset( $request['images'] ) ) { |
|
1564 | - $product = $this->set_product_images( $product, $request['images'] ); |
|
1563 | + if (isset($request['images'])) { |
|
1564 | + $product = $this->set_product_images($product, $request['images']); |
|
1565 | 1565 | } |
1566 | 1566 | |
1567 | 1567 | // Save product meta fields. |
1568 | - $product = $this->set_product_meta( $product, $request ); |
|
1568 | + $product = $this->set_product_meta($product, $request); |
|
1569 | 1569 | |
1570 | 1570 | // Save the product data. |
1571 | 1571 | $product->save(); |
1572 | 1572 | |
1573 | 1573 | // Save variations. |
1574 | - if ( $product->is_type( 'variable' ) ) { |
|
1575 | - if ( isset( $request['variations'] ) && is_array( $request['variations'] ) ) { |
|
1576 | - $this->save_variations_data( $product, $request ); |
|
1574 | + if ($product->is_type('variable')) { |
|
1575 | + if (isset($request['variations']) && is_array($request['variations'])) { |
|
1576 | + $this->save_variations_data($product, $request); |
|
1577 | 1577 | } |
1578 | 1578 | } |
1579 | 1579 | |
1580 | 1580 | // Clear caches here so in sync with any new variations/children. |
1581 | - wc_delete_product_transients( $product->get_id() ); |
|
1582 | - wp_cache_delete( 'product-' . $product->get_id(), 'products' ); |
|
1581 | + wc_delete_product_transients($product->get_id()); |
|
1582 | + wp_cache_delete('product-' . $product->get_id(), 'products'); |
|
1583 | 1583 | |
1584 | 1584 | return true; |
1585 | 1585 | } |
@@ -1589,8 +1589,8 @@ discard block |
||
1589 | 1589 | * |
1590 | 1590 | * @param WP_Post $post Post data. |
1591 | 1591 | */ |
1592 | - public function clear_transients( $post ) { |
|
1593 | - wc_delete_product_transients( $post->ID ); |
|
1592 | + public function clear_transients($post) { |
|
1593 | + wc_delete_product_transients($post->ID); |
|
1594 | 1594 | } |
1595 | 1595 | |
1596 | 1596 | /** |
@@ -1598,27 +1598,27 @@ discard block |
||
1598 | 1598 | * |
1599 | 1599 | * @param int|WP_Post $id Post ID or WP_Post instance. |
1600 | 1600 | */ |
1601 | - protected function delete_post( $id ) { |
|
1602 | - if ( ! empty( $id->ID ) ) { |
|
1601 | + protected function delete_post($id) { |
|
1602 | + if ( ! empty($id->ID)) { |
|
1603 | 1603 | $id = $id->ID; |
1604 | - } elseif ( ! is_numeric( $id ) || 0 >= $id ) { |
|
1604 | + } elseif ( ! is_numeric($id) || 0 >= $id) { |
|
1605 | 1605 | return; |
1606 | 1606 | } |
1607 | 1607 | |
1608 | 1608 | // Delete product attachments. |
1609 | - $attachments = get_posts( array( |
|
1609 | + $attachments = get_posts(array( |
|
1610 | 1610 | 'post_parent' => $id, |
1611 | 1611 | 'post_status' => 'any', |
1612 | 1612 | 'post_type' => 'attachment', |
1613 | - ) ); |
|
1613 | + )); |
|
1614 | 1614 | |
1615 | - foreach ( (array) $attachments as $attachment ) { |
|
1616 | - wp_delete_attachment( $attachment->ID, true ); |
|
1615 | + foreach ((array) $attachments as $attachment) { |
|
1616 | + wp_delete_attachment($attachment->ID, true); |
|
1617 | 1617 | } |
1618 | 1618 | |
1619 | 1619 | // Delete product. |
1620 | - $product = wc_get_product( $id ); |
|
1621 | - $product->delete( true ); |
|
1620 | + $product = wc_get_product($id); |
|
1621 | + $product->delete(true); |
|
1622 | 1622 | } |
1623 | 1623 | |
1624 | 1624 | /** |
@@ -1627,16 +1627,16 @@ discard block |
||
1627 | 1627 | * @param WP_REST_Request $request Full details about the request. |
1628 | 1628 | * @return WP_REST_Response|WP_Error |
1629 | 1629 | */ |
1630 | - public function delete_item( $request ) { |
|
1630 | + public function delete_item($request) { |
|
1631 | 1631 | $id = (int) $request['id']; |
1632 | 1632 | $force = (bool) $request['force']; |
1633 | - $post = get_post( $id ); |
|
1634 | - $product = wc_get_product( $id ); |
|
1633 | + $post = get_post($id); |
|
1634 | + $product = wc_get_product($id); |
|
1635 | 1635 | |
1636 | - if ( ! empty( $post->post_type ) && 'product_variation' === $post->post_type && 'product' === $this->post_type ) { |
|
1637 | - return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
1638 | - } elseif ( empty( $id ) || empty( $post->ID ) || $post->post_type !== $this->post_type ) { |
|
1639 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid post ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
1636 | + if ( ! empty($post->post_type) && 'product_variation' === $post->post_type && 'product' === $this->post_type) { |
|
1637 | + return new WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), array('status' => 404)); |
|
1638 | + } elseif (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) { |
|
1639 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid post ID.', 'woocommerce'), array('status' => 404)); |
|
1640 | 1640 | } |
1641 | 1641 | |
1642 | 1642 | $supports_trash = EMPTY_TRASH_DAYS > 0; |
@@ -1649,49 +1649,49 @@ discard block |
||
1649 | 1649 | * @param boolean $supports_trash Whether the item type support trashing. |
1650 | 1650 | * @param WP_Post $post The Post object being considered for trashing support. |
1651 | 1651 | */ |
1652 | - $supports_trash = apply_filters( "woocommerce_rest_{$this->post_type}_trashable", $supports_trash, $post ); |
|
1652 | + $supports_trash = apply_filters("woocommerce_rest_{$this->post_type}_trashable", $supports_trash, $post); |
|
1653 | 1653 | |
1654 | - if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $post->ID ) ) { |
|
1654 | + if ( ! wc_rest_check_post_permissions($this->post_type, 'delete', $post->ID)) { |
|
1655 | 1655 | /* translators: %s: post type */ |
1656 | - return new WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( 'status' => rest_authorization_required_code() ) ); |
|
1656 | + return new WP_Error("woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf(__('Sorry, you are not allowed to delete %s.', 'woocommerce'), $this->post_type), array('status' => rest_authorization_required_code())); |
|
1657 | 1657 | } |
1658 | 1658 | |
1659 | - $request->set_param( 'context', 'edit' ); |
|
1660 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
1659 | + $request->set_param('context', 'edit'); |
|
1660 | + $response = $this->prepare_item_for_response($post, $request); |
|
1661 | 1661 | |
1662 | 1662 | // If we're forcing, then delete permanently. |
1663 | - if ( $force ) { |
|
1664 | - if ( $product->is_type( 'variable' ) ) { |
|
1665 | - foreach ( $product->get_children() as $child_id ) { |
|
1666 | - $child = wc_get_product( $child_id ); |
|
1667 | - if ( ! empty( $child ) ) { |
|
1668 | - $child->delete( true ); |
|
1663 | + if ($force) { |
|
1664 | + if ($product->is_type('variable')) { |
|
1665 | + foreach ($product->get_children() as $child_id) { |
|
1666 | + $child = wc_get_product($child_id); |
|
1667 | + if ( ! empty($child)) { |
|
1668 | + $child->delete(true); |
|
1669 | 1669 | } |
1670 | 1670 | } |
1671 | 1671 | } else { |
1672 | 1672 | // For other product types, if the product has children, remove the relationship. |
1673 | - foreach ( $product->get_children() as $child_id ) { |
|
1674 | - $child = wc_get_product( $child_id ); |
|
1675 | - if ( ! empty( $child ) ) { |
|
1676 | - $child->set_parent_id( 0 ); |
|
1673 | + foreach ($product->get_children() as $child_id) { |
|
1674 | + $child = wc_get_product($child_id); |
|
1675 | + if ( ! empty($child)) { |
|
1676 | + $child->set_parent_id(0); |
|
1677 | 1677 | $child->save(); |
1678 | 1678 | } |
1679 | 1679 | } |
1680 | 1680 | } |
1681 | 1681 | |
1682 | - $product->delete( true ); |
|
1683 | - $result = ! ( $product->get_id() > 0 ); |
|
1682 | + $product->delete(true); |
|
1683 | + $result = ! ($product->get_id() > 0); |
|
1684 | 1684 | } else { |
1685 | 1685 | // If we don't support trashing for this type, error out. |
1686 | - if ( ! $supports_trash ) { |
|
1686 | + if ( ! $supports_trash) { |
|
1687 | 1687 | /* translators: %s: post type */ |
1688 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) ); |
|
1688 | + return new WP_Error('woocommerce_rest_trash_not_supported', sprintf(__('The %s does not support trashing.', 'woocommerce'), $this->post_type), array('status' => 501)); |
|
1689 | 1689 | } |
1690 | 1690 | |
1691 | 1691 | // Otherwise, only trash if we haven't already. |
1692 | - if ( 'trash' === $post->post_status ) { |
|
1692 | + if ('trash' === $post->post_status) { |
|
1693 | 1693 | /* translators: %s: post type */ |
1694 | - return new WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) ); |
|
1694 | + return new WP_Error('woocommerce_rest_already_trashed', sprintf(__('The %s has already been deleted.', 'woocommerce'), $this->post_type), array('status' => 410)); |
|
1695 | 1695 | } |
1696 | 1696 | |
1697 | 1697 | // (Note that internally this falls through to `wp_delete_post` if |
@@ -1700,14 +1700,14 @@ discard block |
||
1700 | 1700 | $result = 'trash' === $product->get_status(); |
1701 | 1701 | } |
1702 | 1702 | |
1703 | - if ( ! $result ) { |
|
1703 | + if ( ! $result) { |
|
1704 | 1704 | /* translators: %s: post type */ |
1705 | - return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) ); |
|
1705 | + return new WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500)); |
|
1706 | 1706 | } |
1707 | 1707 | |
1708 | 1708 | // Delete parent product transients. |
1709 | - if ( $parent_id = wp_get_post_parent_id( $id ) ) { |
|
1710 | - wc_delete_product_transients( $parent_id ); |
|
1709 | + if ($parent_id = wp_get_post_parent_id($id)) { |
|
1710 | + wc_delete_product_transients($parent_id); |
|
1711 | 1711 | } |
1712 | 1712 | |
1713 | 1713 | /** |
@@ -1717,7 +1717,7 @@ discard block |
||
1717 | 1717 | * @param WP_REST_Response $response The response data. |
1718 | 1718 | * @param WP_REST_Request $request The request sent to the API. |
1719 | 1719 | */ |
1720 | - do_action( "woocommerce_rest_delete_{$this->post_type}", $post, $response, $request ); |
|
1720 | + do_action("woocommerce_rest_delete_{$this->post_type}", $post, $response, $request); |
|
1721 | 1721 | |
1722 | 1722 | return $response; |
1723 | 1723 | } |
@@ -1728,822 +1728,822 @@ discard block |
||
1728 | 1728 | * @return array |
1729 | 1729 | */ |
1730 | 1730 | public function get_item_schema() { |
1731 | - $weight_unit = get_option( 'woocommerce_weight_unit' ); |
|
1732 | - $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
|
1731 | + $weight_unit = get_option('woocommerce_weight_unit'); |
|
1732 | + $dimension_unit = get_option('woocommerce_dimension_unit'); |
|
1733 | 1733 | $schema = array( |
1734 | 1734 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
1735 | 1735 | 'title' => $this->post_type, |
1736 | 1736 | 'type' => 'object', |
1737 | 1737 | 'properties' => array( |
1738 | 1738 | 'id' => array( |
1739 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
1739 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
1740 | 1740 | 'type' => 'integer', |
1741 | - 'context' => array( 'view', 'edit' ), |
|
1741 | + 'context' => array('view', 'edit'), |
|
1742 | 1742 | 'readonly' => true, |
1743 | 1743 | ), |
1744 | 1744 | 'name' => array( |
1745 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
1745 | + 'description' => __('Product name.', 'woocommerce'), |
|
1746 | 1746 | 'type' => 'string', |
1747 | - 'context' => array( 'view', 'edit' ), |
|
1747 | + 'context' => array('view', 'edit'), |
|
1748 | 1748 | ), |
1749 | 1749 | 'slug' => array( |
1750 | - 'description' => __( 'Product slug.', 'woocommerce' ), |
|
1750 | + 'description' => __('Product slug.', 'woocommerce'), |
|
1751 | 1751 | 'type' => 'string', |
1752 | - 'context' => array( 'view', 'edit' ), |
|
1752 | + 'context' => array('view', 'edit'), |
|
1753 | 1753 | ), |
1754 | 1754 | 'permalink' => array( |
1755 | - 'description' => __( 'Product URL.', 'woocommerce' ), |
|
1755 | + 'description' => __('Product URL.', 'woocommerce'), |
|
1756 | 1756 | 'type' => 'string', |
1757 | 1757 | 'format' => 'uri', |
1758 | - 'context' => array( 'view', 'edit' ), |
|
1758 | + 'context' => array('view', 'edit'), |
|
1759 | 1759 | 'readonly' => true, |
1760 | 1760 | ), |
1761 | 1761 | 'date_created' => array( |
1762 | - 'description' => __( "The date the product was created, in the site's timezone.", 'woocommerce' ), |
|
1762 | + 'description' => __("The date the product was created, in the site's timezone.", 'woocommerce'), |
|
1763 | 1763 | 'type' => 'date-time', |
1764 | - 'context' => array( 'view', 'edit' ), |
|
1764 | + 'context' => array('view', 'edit'), |
|
1765 | 1765 | 'readonly' => true, |
1766 | 1766 | ), |
1767 | 1767 | 'date_modified' => array( |
1768 | - 'description' => __( "The date the product was last modified, in the site's timezone.", 'woocommerce' ), |
|
1768 | + 'description' => __("The date the product was last modified, in the site's timezone.", 'woocommerce'), |
|
1769 | 1769 | 'type' => 'date-time', |
1770 | - 'context' => array( 'view', 'edit' ), |
|
1770 | + 'context' => array('view', 'edit'), |
|
1771 | 1771 | 'readonly' => true, |
1772 | 1772 | ), |
1773 | 1773 | 'type' => array( |
1774 | - 'description' => __( 'Product type.', 'woocommerce' ), |
|
1774 | + 'description' => __('Product type.', 'woocommerce'), |
|
1775 | 1775 | 'type' => 'string', |
1776 | 1776 | 'default' => 'simple', |
1777 | - 'enum' => array_keys( wc_get_product_types() ), |
|
1778 | - 'context' => array( 'view', 'edit' ), |
|
1777 | + 'enum' => array_keys(wc_get_product_types()), |
|
1778 | + 'context' => array('view', 'edit'), |
|
1779 | 1779 | ), |
1780 | 1780 | 'status' => array( |
1781 | - 'description' => __( 'Product status (post status).', 'woocommerce' ), |
|
1781 | + 'description' => __('Product status (post status).', 'woocommerce'), |
|
1782 | 1782 | 'type' => 'string', |
1783 | 1783 | 'default' => 'publish', |
1784 | - 'enum' => array_merge( array_keys( get_post_statuses() ), array( 'future' ) ), |
|
1785 | - 'context' => array( 'view', 'edit' ), |
|
1784 | + 'enum' => array_merge(array_keys(get_post_statuses()), array('future')), |
|
1785 | + 'context' => array('view', 'edit'), |
|
1786 | 1786 | ), |
1787 | 1787 | 'featured' => array( |
1788 | - 'description' => __( 'Featured product.', 'woocommerce' ), |
|
1788 | + 'description' => __('Featured product.', 'woocommerce'), |
|
1789 | 1789 | 'type' => 'boolean', |
1790 | 1790 | 'default' => false, |
1791 | - 'context' => array( 'view', 'edit' ), |
|
1791 | + 'context' => array('view', 'edit'), |
|
1792 | 1792 | ), |
1793 | 1793 | 'catalog_visibility' => array( |
1794 | - 'description' => __( 'Catalog visibility.', 'woocommerce' ), |
|
1794 | + 'description' => __('Catalog visibility.', 'woocommerce'), |
|
1795 | 1795 | 'type' => 'string', |
1796 | 1796 | 'default' => 'visible', |
1797 | - 'enum' => array( 'visible', 'catalog', 'search', 'hidden' ), |
|
1798 | - 'context' => array( 'view', 'edit' ), |
|
1797 | + 'enum' => array('visible', 'catalog', 'search', 'hidden'), |
|
1798 | + 'context' => array('view', 'edit'), |
|
1799 | 1799 | ), |
1800 | 1800 | 'description' => array( |
1801 | - 'description' => __( 'Product description.', 'woocommerce' ), |
|
1801 | + 'description' => __('Product description.', 'woocommerce'), |
|
1802 | 1802 | 'type' => 'string', |
1803 | - 'context' => array( 'view', 'edit' ), |
|
1803 | + 'context' => array('view', 'edit'), |
|
1804 | 1804 | ), |
1805 | 1805 | 'short_description' => array( |
1806 | - 'description' => __( 'Product short description.', 'woocommerce' ), |
|
1806 | + 'description' => __('Product short description.', 'woocommerce'), |
|
1807 | 1807 | 'type' => 'string', |
1808 | - 'context' => array( 'view', 'edit' ), |
|
1808 | + 'context' => array('view', 'edit'), |
|
1809 | 1809 | ), |
1810 | 1810 | 'sku' => array( |
1811 | - 'description' => __( 'Unique identifier.', 'woocommerce' ), |
|
1811 | + 'description' => __('Unique identifier.', 'woocommerce'), |
|
1812 | 1812 | 'type' => 'string', |
1813 | - 'context' => array( 'view', 'edit' ), |
|
1813 | + 'context' => array('view', 'edit'), |
|
1814 | 1814 | ), |
1815 | 1815 | 'price' => array( |
1816 | - 'description' => __( 'Current product price.', 'woocommerce' ), |
|
1816 | + 'description' => __('Current product price.', 'woocommerce'), |
|
1817 | 1817 | 'type' => 'string', |
1818 | - 'context' => array( 'view', 'edit' ), |
|
1818 | + 'context' => array('view', 'edit'), |
|
1819 | 1819 | 'readonly' => true, |
1820 | 1820 | ), |
1821 | 1821 | 'regular_price' => array( |
1822 | - 'description' => __( 'Product regular price.', 'woocommerce' ), |
|
1822 | + 'description' => __('Product regular price.', 'woocommerce'), |
|
1823 | 1823 | 'type' => 'string', |
1824 | - 'context' => array( 'view', 'edit' ), |
|
1824 | + 'context' => array('view', 'edit'), |
|
1825 | 1825 | ), |
1826 | 1826 | 'sale_price' => array( |
1827 | - 'description' => __( 'Product sale price.', 'woocommerce' ), |
|
1827 | + 'description' => __('Product sale price.', 'woocommerce'), |
|
1828 | 1828 | 'type' => 'string', |
1829 | - 'context' => array( 'view', 'edit' ), |
|
1829 | + 'context' => array('view', 'edit'), |
|
1830 | 1830 | ), |
1831 | 1831 | 'date_on_sale_from' => array( |
1832 | - 'description' => __( 'Start date of sale price.', 'woocommerce' ), |
|
1832 | + 'description' => __('Start date of sale price.', 'woocommerce'), |
|
1833 | 1833 | 'type' => 'string', |
1834 | - 'context' => array( 'view', 'edit' ), |
|
1834 | + 'context' => array('view', 'edit'), |
|
1835 | 1835 | ), |
1836 | 1836 | 'date_on_sale_to' => array( |
1837 | - 'description' => __( 'End date of sale price.', 'woocommerce' ), |
|
1837 | + 'description' => __('End date of sale price.', 'woocommerce'), |
|
1838 | 1838 | 'type' => 'string', |
1839 | - 'context' => array( 'view', 'edit' ), |
|
1839 | + 'context' => array('view', 'edit'), |
|
1840 | 1840 | ), |
1841 | 1841 | 'price_html' => array( |
1842 | - 'description' => __( 'Price formatted in HTML.', 'woocommerce' ), |
|
1842 | + 'description' => __('Price formatted in HTML.', 'woocommerce'), |
|
1843 | 1843 | 'type' => 'string', |
1844 | - 'context' => array( 'view', 'edit' ), |
|
1844 | + 'context' => array('view', 'edit'), |
|
1845 | 1845 | 'readonly' => true, |
1846 | 1846 | ), |
1847 | 1847 | 'on_sale' => array( |
1848 | - 'description' => __( 'Shows if the product is on sale.', 'woocommerce' ), |
|
1848 | + 'description' => __('Shows if the product is on sale.', 'woocommerce'), |
|
1849 | 1849 | 'type' => 'boolean', |
1850 | - 'context' => array( 'view', 'edit' ), |
|
1850 | + 'context' => array('view', 'edit'), |
|
1851 | 1851 | 'readonly' => true, |
1852 | 1852 | ), |
1853 | 1853 | 'purchasable' => array( |
1854 | - 'description' => __( 'Shows if the product can be bought.', 'woocommerce' ), |
|
1854 | + 'description' => __('Shows if the product can be bought.', 'woocommerce'), |
|
1855 | 1855 | 'type' => 'boolean', |
1856 | - 'context' => array( 'view', 'edit' ), |
|
1856 | + 'context' => array('view', 'edit'), |
|
1857 | 1857 | 'readonly' => true, |
1858 | 1858 | ), |
1859 | 1859 | 'total_sales' => array( |
1860 | - 'description' => __( 'Amount of sales.', 'woocommerce' ), |
|
1860 | + 'description' => __('Amount of sales.', 'woocommerce'), |
|
1861 | 1861 | 'type' => 'integer', |
1862 | - 'context' => array( 'view', 'edit' ), |
|
1862 | + 'context' => array('view', 'edit'), |
|
1863 | 1863 | 'readonly' => true, |
1864 | 1864 | ), |
1865 | 1865 | 'virtual' => array( |
1866 | - 'description' => __( 'If the product is virtual.', 'woocommerce' ), |
|
1866 | + 'description' => __('If the product is virtual.', 'woocommerce'), |
|
1867 | 1867 | 'type' => 'boolean', |
1868 | 1868 | 'default' => false, |
1869 | - 'context' => array( 'view', 'edit' ), |
|
1869 | + 'context' => array('view', 'edit'), |
|
1870 | 1870 | ), |
1871 | 1871 | 'downloadable' => array( |
1872 | - 'description' => __( 'If the product is downloadable.', 'woocommerce' ), |
|
1872 | + 'description' => __('If the product is downloadable.', 'woocommerce'), |
|
1873 | 1873 | 'type' => 'boolean', |
1874 | 1874 | 'default' => false, |
1875 | - 'context' => array( 'view', 'edit' ), |
|
1875 | + 'context' => array('view', 'edit'), |
|
1876 | 1876 | ), |
1877 | 1877 | 'downloads' => array( |
1878 | - 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
|
1878 | + 'description' => __('List of downloadable files.', 'woocommerce'), |
|
1879 | 1879 | 'type' => 'array', |
1880 | - 'context' => array( 'view', 'edit' ), |
|
1880 | + 'context' => array('view', 'edit'), |
|
1881 | 1881 | 'items' => array( |
1882 | 1882 | 'type' => 'object', |
1883 | 1883 | 'properties' => array( |
1884 | 1884 | 'id' => array( |
1885 | - 'description' => __( 'File ID.', 'woocommerce' ), |
|
1885 | + 'description' => __('File ID.', 'woocommerce'), |
|
1886 | 1886 | 'type' => 'string', |
1887 | - 'context' => array( 'view', 'edit' ), |
|
1887 | + 'context' => array('view', 'edit'), |
|
1888 | 1888 | ), |
1889 | 1889 | 'name' => array( |
1890 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
1890 | + 'description' => __('File name.', 'woocommerce'), |
|
1891 | 1891 | 'type' => 'string', |
1892 | - 'context' => array( 'view', 'edit' ), |
|
1892 | + 'context' => array('view', 'edit'), |
|
1893 | 1893 | ), |
1894 | 1894 | 'file' => array( |
1895 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
1895 | + 'description' => __('File URL.', 'woocommerce'), |
|
1896 | 1896 | 'type' => 'string', |
1897 | - 'context' => array( 'view', 'edit' ), |
|
1897 | + 'context' => array('view', 'edit'), |
|
1898 | 1898 | ), |
1899 | 1899 | ), |
1900 | 1900 | ), |
1901 | 1901 | ), |
1902 | 1902 | 'download_limit' => array( |
1903 | - 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
|
1903 | + 'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'), |
|
1904 | 1904 | 'type' => 'integer', |
1905 | 1905 | 'default' => -1, |
1906 | - 'context' => array( 'view', 'edit' ), |
|
1906 | + 'context' => array('view', 'edit'), |
|
1907 | 1907 | ), |
1908 | 1908 | 'download_expiry' => array( |
1909 | - 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
|
1909 | + 'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'), |
|
1910 | 1910 | 'type' => 'integer', |
1911 | 1911 | 'default' => -1, |
1912 | - 'context' => array( 'view', 'edit' ), |
|
1912 | + 'context' => array('view', 'edit'), |
|
1913 | 1913 | ), |
1914 | 1914 | 'download_type' => array( |
1915 | - 'description' => __( 'Download type, this controls the schema on the front-end.', 'woocommerce' ), |
|
1915 | + 'description' => __('Download type, this controls the schema on the front-end.', 'woocommerce'), |
|
1916 | 1916 | 'type' => 'string', |
1917 | 1917 | 'default' => 'standard', |
1918 | - 'enum' => array( 'standard' ), |
|
1919 | - 'context' => array( 'view', 'edit' ), |
|
1918 | + 'enum' => array('standard'), |
|
1919 | + 'context' => array('view', 'edit'), |
|
1920 | 1920 | ), |
1921 | 1921 | 'external_url' => array( |
1922 | - 'description' => __( 'Product external URL. Only for external products.', 'woocommerce' ), |
|
1922 | + 'description' => __('Product external URL. Only for external products.', 'woocommerce'), |
|
1923 | 1923 | 'type' => 'string', |
1924 | 1924 | 'format' => 'uri', |
1925 | - 'context' => array( 'view', 'edit' ), |
|
1925 | + 'context' => array('view', 'edit'), |
|
1926 | 1926 | ), |
1927 | 1927 | 'button_text' => array( |
1928 | - 'description' => __( 'Product external button text. Only for external products.', 'woocommerce' ), |
|
1928 | + 'description' => __('Product external button text. Only for external products.', 'woocommerce'), |
|
1929 | 1929 | 'type' => 'string', |
1930 | - 'context' => array( 'view', 'edit' ), |
|
1930 | + 'context' => array('view', 'edit'), |
|
1931 | 1931 | ), |
1932 | 1932 | 'tax_status' => array( |
1933 | - 'description' => __( 'Tax status.', 'woocommerce' ), |
|
1933 | + 'description' => __('Tax status.', 'woocommerce'), |
|
1934 | 1934 | 'type' => 'string', |
1935 | 1935 | 'default' => 'taxable', |
1936 | - 'enum' => array( 'taxable', 'shipping', 'none' ), |
|
1937 | - 'context' => array( 'view', 'edit' ), |
|
1936 | + 'enum' => array('taxable', 'shipping', 'none'), |
|
1937 | + 'context' => array('view', 'edit'), |
|
1938 | 1938 | ), |
1939 | 1939 | 'tax_class' => array( |
1940 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
1940 | + 'description' => __('Tax class.', 'woocommerce'), |
|
1941 | 1941 | 'type' => 'string', |
1942 | - 'context' => array( 'view', 'edit' ), |
|
1942 | + 'context' => array('view', 'edit'), |
|
1943 | 1943 | ), |
1944 | 1944 | 'manage_stock' => array( |
1945 | - 'description' => __( 'Stock management at product level.', 'woocommerce' ), |
|
1945 | + 'description' => __('Stock management at product level.', 'woocommerce'), |
|
1946 | 1946 | 'type' => 'boolean', |
1947 | 1947 | 'default' => false, |
1948 | - 'context' => array( 'view', 'edit' ), |
|
1948 | + 'context' => array('view', 'edit'), |
|
1949 | 1949 | ), |
1950 | 1950 | 'stock_quantity' => array( |
1951 | - 'description' => __( 'Stock quantity.', 'woocommerce' ), |
|
1951 | + 'description' => __('Stock quantity.', 'woocommerce'), |
|
1952 | 1952 | 'type' => 'integer', |
1953 | - 'context' => array( 'view', 'edit' ), |
|
1953 | + 'context' => array('view', 'edit'), |
|
1954 | 1954 | ), |
1955 | 1955 | 'in_stock' => array( |
1956 | - 'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ), |
|
1956 | + 'description' => __('Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce'), |
|
1957 | 1957 | 'type' => 'boolean', |
1958 | 1958 | 'default' => true, |
1959 | - 'context' => array( 'view', 'edit' ), |
|
1959 | + 'context' => array('view', 'edit'), |
|
1960 | 1960 | ), |
1961 | 1961 | 'backorders' => array( |
1962 | - 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
|
1962 | + 'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'), |
|
1963 | 1963 | 'type' => 'string', |
1964 | 1964 | 'default' => 'no', |
1965 | - 'enum' => array( 'no', 'notify', 'yes' ), |
|
1966 | - 'context' => array( 'view', 'edit' ), |
|
1965 | + 'enum' => array('no', 'notify', 'yes'), |
|
1966 | + 'context' => array('view', 'edit'), |
|
1967 | 1967 | ), |
1968 | 1968 | 'backorders_allowed' => array( |
1969 | - 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
|
1969 | + 'description' => __('Shows if backorders are allowed.', 'woocommerce'), |
|
1970 | 1970 | 'type' => 'boolean', |
1971 | - 'context' => array( 'view', 'edit' ), |
|
1971 | + 'context' => array('view', 'edit'), |
|
1972 | 1972 | 'readonly' => true, |
1973 | 1973 | ), |
1974 | 1974 | 'backordered' => array( |
1975 | - 'description' => __( 'Shows if the product is on backordered.', 'woocommerce' ), |
|
1975 | + 'description' => __('Shows if the product is on backordered.', 'woocommerce'), |
|
1976 | 1976 | 'type' => 'boolean', |
1977 | - 'context' => array( 'view', 'edit' ), |
|
1977 | + 'context' => array('view', 'edit'), |
|
1978 | 1978 | 'readonly' => true, |
1979 | 1979 | ), |
1980 | 1980 | 'sold_individually' => array( |
1981 | - 'description' => __( 'Allow one item to be bought in a single order.', 'woocommerce' ), |
|
1981 | + 'description' => __('Allow one item to be bought in a single order.', 'woocommerce'), |
|
1982 | 1982 | 'type' => 'boolean', |
1983 | 1983 | 'default' => false, |
1984 | - 'context' => array( 'view', 'edit' ), |
|
1984 | + 'context' => array('view', 'edit'), |
|
1985 | 1985 | ), |
1986 | 1986 | 'weight' => array( |
1987 | 1987 | /* translators: %s: weight unit */ |
1988 | - 'description' => sprintf( __( 'Product weight (%s).', 'woocommerce' ), $weight_unit ), |
|
1988 | + 'description' => sprintf(__('Product weight (%s).', 'woocommerce'), $weight_unit), |
|
1989 | 1989 | 'type' => 'string', |
1990 | - 'context' => array( 'view', 'edit' ), |
|
1990 | + 'context' => array('view', 'edit'), |
|
1991 | 1991 | ), |
1992 | 1992 | 'dimensions' => array( |
1993 | - 'description' => __( 'Product dimensions.', 'woocommerce' ), |
|
1993 | + 'description' => __('Product dimensions.', 'woocommerce'), |
|
1994 | 1994 | 'type' => 'object', |
1995 | - 'context' => array( 'view', 'edit' ), |
|
1995 | + 'context' => array('view', 'edit'), |
|
1996 | 1996 | 'properties' => array( |
1997 | 1997 | 'length' => array( |
1998 | 1998 | /* translators: %s: dimension unit */ |
1999 | - 'description' => sprintf( __( 'Product length (%s).', 'woocommerce' ), $dimension_unit ), |
|
1999 | + 'description' => sprintf(__('Product length (%s).', 'woocommerce'), $dimension_unit), |
|
2000 | 2000 | 'type' => 'string', |
2001 | - 'context' => array( 'view', 'edit' ), |
|
2001 | + 'context' => array('view', 'edit'), |
|
2002 | 2002 | ), |
2003 | 2003 | 'width' => array( |
2004 | 2004 | /* translators: %s: dimension unit */ |
2005 | - 'description' => sprintf( __( 'Product width (%s).', 'woocommerce' ), $dimension_unit ), |
|
2005 | + 'description' => sprintf(__('Product width (%s).', 'woocommerce'), $dimension_unit), |
|
2006 | 2006 | 'type' => 'string', |
2007 | - 'context' => array( 'view', 'edit' ), |
|
2007 | + 'context' => array('view', 'edit'), |
|
2008 | 2008 | ), |
2009 | 2009 | 'height' => array( |
2010 | 2010 | /* translators: %s: dimension unit */ |
2011 | - 'description' => sprintf( __( 'Product height (%s).', 'woocommerce' ), $dimension_unit ), |
|
2011 | + 'description' => sprintf(__('Product height (%s).', 'woocommerce'), $dimension_unit), |
|
2012 | 2012 | 'type' => 'string', |
2013 | - 'context' => array( 'view', 'edit' ), |
|
2013 | + 'context' => array('view', 'edit'), |
|
2014 | 2014 | ), |
2015 | 2015 | ), |
2016 | 2016 | ), |
2017 | 2017 | 'shipping_required' => array( |
2018 | - 'description' => __( 'Shows if the product need to be shipped.', 'woocommerce' ), |
|
2018 | + 'description' => __('Shows if the product need to be shipped.', 'woocommerce'), |
|
2019 | 2019 | 'type' => 'boolean', |
2020 | - 'context' => array( 'view', 'edit' ), |
|
2020 | + 'context' => array('view', 'edit'), |
|
2021 | 2021 | 'readonly' => true, |
2022 | 2022 | ), |
2023 | 2023 | 'shipping_taxable' => array( |
2024 | - 'description' => __( 'Shows whether or not the product shipping is taxable.', 'woocommerce' ), |
|
2024 | + 'description' => __('Shows whether or not the product shipping is taxable.', 'woocommerce'), |
|
2025 | 2025 | 'type' => 'boolean', |
2026 | - 'context' => array( 'view', 'edit' ), |
|
2026 | + 'context' => array('view', 'edit'), |
|
2027 | 2027 | 'readonly' => true, |
2028 | 2028 | ), |
2029 | 2029 | 'shipping_class' => array( |
2030 | - 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
|
2030 | + 'description' => __('Shipping class slug.', 'woocommerce'), |
|
2031 | 2031 | 'type' => 'string', |
2032 | - 'context' => array( 'view', 'edit' ), |
|
2032 | + 'context' => array('view', 'edit'), |
|
2033 | 2033 | ), |
2034 | 2034 | 'shipping_class_id' => array( |
2035 | - 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
|
2035 | + 'description' => __('Shipping class ID.', 'woocommerce'), |
|
2036 | 2036 | 'type' => 'integer', |
2037 | - 'context' => array( 'view', 'edit' ), |
|
2037 | + 'context' => array('view', 'edit'), |
|
2038 | 2038 | 'readonly' => true, |
2039 | 2039 | ), |
2040 | 2040 | 'reviews_allowed' => array( |
2041 | - 'description' => __( 'Allow reviews.', 'woocommerce' ), |
|
2041 | + 'description' => __('Allow reviews.', 'woocommerce'), |
|
2042 | 2042 | 'type' => 'boolean', |
2043 | 2043 | 'default' => true, |
2044 | - 'context' => array( 'view', 'edit' ), |
|
2044 | + 'context' => array('view', 'edit'), |
|
2045 | 2045 | ), |
2046 | 2046 | 'average_rating' => array( |
2047 | - 'description' => __( 'Reviews average rating.', 'woocommerce' ), |
|
2047 | + 'description' => __('Reviews average rating.', 'woocommerce'), |
|
2048 | 2048 | 'type' => 'string', |
2049 | - 'context' => array( 'view', 'edit' ), |
|
2049 | + 'context' => array('view', 'edit'), |
|
2050 | 2050 | 'readonly' => true, |
2051 | 2051 | ), |
2052 | 2052 | 'rating_count' => array( |
2053 | - 'description' => __( 'Amount of reviews that the product have.', 'woocommerce' ), |
|
2053 | + 'description' => __('Amount of reviews that the product have.', 'woocommerce'), |
|
2054 | 2054 | 'type' => 'integer', |
2055 | - 'context' => array( 'view', 'edit' ), |
|
2055 | + 'context' => array('view', 'edit'), |
|
2056 | 2056 | 'readonly' => true, |
2057 | 2057 | ), |
2058 | 2058 | 'related_ids' => array( |
2059 | - 'description' => __( 'List of related products IDs.', 'woocommerce' ), |
|
2059 | + 'description' => __('List of related products IDs.', 'woocommerce'), |
|
2060 | 2060 | 'type' => 'array', |
2061 | 2061 | 'items' => array( |
2062 | 2062 | 'type' => 'integer', |
2063 | 2063 | ), |
2064 | - 'context' => array( 'view', 'edit' ), |
|
2064 | + 'context' => array('view', 'edit'), |
|
2065 | 2065 | 'readonly' => true, |
2066 | 2066 | ), |
2067 | 2067 | 'upsell_ids' => array( |
2068 | - 'description' => __( 'List of upsell products IDs.', 'woocommerce' ), |
|
2068 | + 'description' => __('List of upsell products IDs.', 'woocommerce'), |
|
2069 | 2069 | 'type' => 'array', |
2070 | 2070 | 'items' => array( |
2071 | 2071 | 'type' => 'integer', |
2072 | 2072 | ), |
2073 | - 'context' => array( 'view', 'edit' ), |
|
2073 | + 'context' => array('view', 'edit'), |
|
2074 | 2074 | ), |
2075 | 2075 | 'cross_sell_ids' => array( |
2076 | - 'description' => __( 'List of cross-sell products IDs.', 'woocommerce' ), |
|
2076 | + 'description' => __('List of cross-sell products IDs.', 'woocommerce'), |
|
2077 | 2077 | 'type' => 'array', |
2078 | 2078 | 'items' => array( |
2079 | 2079 | 'type' => 'integer', |
2080 | 2080 | ), |
2081 | - 'context' => array( 'view', 'edit' ), |
|
2081 | + 'context' => array('view', 'edit'), |
|
2082 | 2082 | ), |
2083 | 2083 | 'parent_id' => array( |
2084 | - 'description' => __( 'Product parent ID.', 'woocommerce' ), |
|
2084 | + 'description' => __('Product parent ID.', 'woocommerce'), |
|
2085 | 2085 | 'type' => 'integer', |
2086 | - 'context' => array( 'view', 'edit' ), |
|
2086 | + 'context' => array('view', 'edit'), |
|
2087 | 2087 | ), |
2088 | 2088 | 'purchase_note' => array( |
2089 | - 'description' => __( 'Optional note to send the customer after purchase.', 'woocommerce' ), |
|
2089 | + 'description' => __('Optional note to send the customer after purchase.', 'woocommerce'), |
|
2090 | 2090 | 'type' => 'string', |
2091 | - 'context' => array( 'view', 'edit' ), |
|
2091 | + 'context' => array('view', 'edit'), |
|
2092 | 2092 | ), |
2093 | 2093 | 'categories' => array( |
2094 | - 'description' => __( 'List of categories.', 'woocommerce' ), |
|
2094 | + 'description' => __('List of categories.', 'woocommerce'), |
|
2095 | 2095 | 'type' => 'array', |
2096 | - 'context' => array( 'view', 'edit' ), |
|
2096 | + 'context' => array('view', 'edit'), |
|
2097 | 2097 | 'items' => array( |
2098 | 2098 | 'type' => 'object', |
2099 | 2099 | 'properties' => array( |
2100 | 2100 | 'id' => array( |
2101 | - 'description' => __( 'Category ID.', 'woocommerce' ), |
|
2101 | + 'description' => __('Category ID.', 'woocommerce'), |
|
2102 | 2102 | 'type' => 'integer', |
2103 | - 'context' => array( 'view', 'edit' ), |
|
2103 | + 'context' => array('view', 'edit'), |
|
2104 | 2104 | ), |
2105 | 2105 | 'name' => array( |
2106 | - 'description' => __( 'Category name.', 'woocommerce' ), |
|
2106 | + 'description' => __('Category name.', 'woocommerce'), |
|
2107 | 2107 | 'type' => 'string', |
2108 | - 'context' => array( 'view', 'edit' ), |
|
2108 | + 'context' => array('view', 'edit'), |
|
2109 | 2109 | 'readonly' => true, |
2110 | 2110 | ), |
2111 | 2111 | 'slug' => array( |
2112 | - 'description' => __( 'Category slug.', 'woocommerce' ), |
|
2112 | + 'description' => __('Category slug.', 'woocommerce'), |
|
2113 | 2113 | 'type' => 'string', |
2114 | - 'context' => array( 'view', 'edit' ), |
|
2114 | + 'context' => array('view', 'edit'), |
|
2115 | 2115 | 'readonly' => true, |
2116 | 2116 | ), |
2117 | 2117 | ), |
2118 | 2118 | ), |
2119 | 2119 | ), |
2120 | 2120 | 'tags' => array( |
2121 | - 'description' => __( 'List of tags.', 'woocommerce' ), |
|
2121 | + 'description' => __('List of tags.', 'woocommerce'), |
|
2122 | 2122 | 'type' => 'array', |
2123 | - 'context' => array( 'view', 'edit' ), |
|
2123 | + 'context' => array('view', 'edit'), |
|
2124 | 2124 | 'items' => array( |
2125 | 2125 | 'type' => 'object', |
2126 | 2126 | 'properties' => array( |
2127 | 2127 | 'id' => array( |
2128 | - 'description' => __( 'Tag ID.', 'woocommerce' ), |
|
2128 | + 'description' => __('Tag ID.', 'woocommerce'), |
|
2129 | 2129 | 'type' => 'integer', |
2130 | - 'context' => array( 'view', 'edit' ), |
|
2130 | + 'context' => array('view', 'edit'), |
|
2131 | 2131 | ), |
2132 | 2132 | 'name' => array( |
2133 | - 'description' => __( 'Tag name.', 'woocommerce' ), |
|
2133 | + 'description' => __('Tag name.', 'woocommerce'), |
|
2134 | 2134 | 'type' => 'string', |
2135 | - 'context' => array( 'view', 'edit' ), |
|
2135 | + 'context' => array('view', 'edit'), |
|
2136 | 2136 | 'readonly' => true, |
2137 | 2137 | ), |
2138 | 2138 | 'slug' => array( |
2139 | - 'description' => __( 'Tag slug.', 'woocommerce' ), |
|
2139 | + 'description' => __('Tag slug.', 'woocommerce'), |
|
2140 | 2140 | 'type' => 'string', |
2141 | - 'context' => array( 'view', 'edit' ), |
|
2141 | + 'context' => array('view', 'edit'), |
|
2142 | 2142 | 'readonly' => true, |
2143 | 2143 | ), |
2144 | 2144 | ), |
2145 | 2145 | ), |
2146 | 2146 | ), |
2147 | 2147 | 'images' => array( |
2148 | - 'description' => __( 'List of images.', 'woocommerce' ), |
|
2148 | + 'description' => __('List of images.', 'woocommerce'), |
|
2149 | 2149 | 'type' => 'object', |
2150 | - 'context' => array( 'view', 'edit' ), |
|
2150 | + 'context' => array('view', 'edit'), |
|
2151 | 2151 | 'items' => array( |
2152 | 2152 | 'type' => 'object', |
2153 | 2153 | 'properties' => array( |
2154 | 2154 | 'id' => array( |
2155 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
2155 | + 'description' => __('Image ID.', 'woocommerce'), |
|
2156 | 2156 | 'type' => 'integer', |
2157 | - 'context' => array( 'view', 'edit' ), |
|
2157 | + 'context' => array('view', 'edit'), |
|
2158 | 2158 | ), |
2159 | 2159 | 'date_created' => array( |
2160 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
2160 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
2161 | 2161 | 'type' => 'date-time', |
2162 | - 'context' => array( 'view', 'edit' ), |
|
2162 | + 'context' => array('view', 'edit'), |
|
2163 | 2163 | 'readonly' => true, |
2164 | 2164 | ), |
2165 | 2165 | 'date_modified' => array( |
2166 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
2166 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
2167 | 2167 | 'type' => 'date-time', |
2168 | - 'context' => array( 'view', 'edit' ), |
|
2168 | + 'context' => array('view', 'edit'), |
|
2169 | 2169 | 'readonly' => true, |
2170 | 2170 | ), |
2171 | 2171 | 'src' => array( |
2172 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
2172 | + 'description' => __('Image URL.', 'woocommerce'), |
|
2173 | 2173 | 'type' => 'string', |
2174 | 2174 | 'format' => 'uri', |
2175 | - 'context' => array( 'view', 'edit' ), |
|
2175 | + 'context' => array('view', 'edit'), |
|
2176 | 2176 | ), |
2177 | 2177 | 'name' => array( |
2178 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
2178 | + 'description' => __('Image name.', 'woocommerce'), |
|
2179 | 2179 | 'type' => 'string', |
2180 | - 'context' => array( 'view', 'edit' ), |
|
2180 | + 'context' => array('view', 'edit'), |
|
2181 | 2181 | ), |
2182 | 2182 | 'alt' => array( |
2183 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
2183 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
2184 | 2184 | 'type' => 'string', |
2185 | - 'context' => array( 'view', 'edit' ), |
|
2185 | + 'context' => array('view', 'edit'), |
|
2186 | 2186 | ), |
2187 | 2187 | 'position' => array( |
2188 | - 'description' => __( 'Image position. 0 means that the image is featured.', 'woocommerce' ), |
|
2188 | + 'description' => __('Image position. 0 means that the image is featured.', 'woocommerce'), |
|
2189 | 2189 | 'type' => 'integer', |
2190 | - 'context' => array( 'view', 'edit' ), |
|
2190 | + 'context' => array('view', 'edit'), |
|
2191 | 2191 | ), |
2192 | 2192 | ), |
2193 | 2193 | ), |
2194 | 2194 | ), |
2195 | 2195 | 'attributes' => array( |
2196 | - 'description' => __( 'List of attributes.', 'woocommerce' ), |
|
2196 | + 'description' => __('List of attributes.', 'woocommerce'), |
|
2197 | 2197 | 'type' => 'array', |
2198 | - 'context' => array( 'view', 'edit' ), |
|
2198 | + 'context' => array('view', 'edit'), |
|
2199 | 2199 | 'items' => array( |
2200 | 2200 | 'type' => 'object', |
2201 | 2201 | 'properties' => array( |
2202 | 2202 | 'id' => array( |
2203 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
2203 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
2204 | 2204 | 'type' => 'integer', |
2205 | - 'context' => array( 'view', 'edit' ), |
|
2205 | + 'context' => array('view', 'edit'), |
|
2206 | 2206 | ), |
2207 | 2207 | 'name' => array( |
2208 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
2208 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
2209 | 2209 | 'type' => 'string', |
2210 | - 'context' => array( 'view', 'edit' ), |
|
2210 | + 'context' => array('view', 'edit'), |
|
2211 | 2211 | ), |
2212 | 2212 | 'position' => array( |
2213 | - 'description' => __( 'Attribute position.', 'woocommerce' ), |
|
2213 | + 'description' => __('Attribute position.', 'woocommerce'), |
|
2214 | 2214 | 'type' => 'integer', |
2215 | - 'context' => array( 'view', 'edit' ), |
|
2215 | + 'context' => array('view', 'edit'), |
|
2216 | 2216 | ), |
2217 | 2217 | 'visible' => array( |
2218 | - 'description' => __( "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", 'woocommerce' ), |
|
2218 | + 'description' => __("Define if the attribute is visible on the \"Additional information\" tab in the product's page.", 'woocommerce'), |
|
2219 | 2219 | 'type' => 'boolean', |
2220 | 2220 | 'default' => false, |
2221 | - 'context' => array( 'view', 'edit' ), |
|
2221 | + 'context' => array('view', 'edit'), |
|
2222 | 2222 | ), |
2223 | 2223 | 'variation' => array( |
2224 | - 'description' => __( 'Define if the attribute can be used as variation.', 'woocommerce' ), |
|
2224 | + 'description' => __('Define if the attribute can be used as variation.', 'woocommerce'), |
|
2225 | 2225 | 'type' => 'boolean', |
2226 | 2226 | 'default' => false, |
2227 | - 'context' => array( 'view', 'edit' ), |
|
2227 | + 'context' => array('view', 'edit'), |
|
2228 | 2228 | ), |
2229 | 2229 | 'options' => array( |
2230 | - 'description' => __( 'List of available term names of the attribute.', 'woocommerce' ), |
|
2230 | + 'description' => __('List of available term names of the attribute.', 'woocommerce'), |
|
2231 | 2231 | 'type' => 'array', |
2232 | - 'context' => array( 'view', 'edit' ), |
|
2232 | + 'context' => array('view', 'edit'), |
|
2233 | 2233 | ), |
2234 | 2234 | ), |
2235 | 2235 | ), |
2236 | 2236 | ), |
2237 | 2237 | 'default_attributes' => array( |
2238 | - 'description' => __( 'Defaults variation attributes.', 'woocommerce' ), |
|
2238 | + 'description' => __('Defaults variation attributes.', 'woocommerce'), |
|
2239 | 2239 | 'type' => 'array', |
2240 | - 'context' => array( 'view', 'edit' ), |
|
2240 | + 'context' => array('view', 'edit'), |
|
2241 | 2241 | 'items' => array( |
2242 | 2242 | 'type' => 'object', |
2243 | 2243 | 'properties' => array( |
2244 | 2244 | 'id' => array( |
2245 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
2245 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
2246 | 2246 | 'type' => 'integer', |
2247 | - 'context' => array( 'view', 'edit' ), |
|
2247 | + 'context' => array('view', 'edit'), |
|
2248 | 2248 | ), |
2249 | 2249 | 'name' => array( |
2250 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
2250 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
2251 | 2251 | 'type' => 'string', |
2252 | - 'context' => array( 'view', 'edit' ), |
|
2252 | + 'context' => array('view', 'edit'), |
|
2253 | 2253 | ), |
2254 | 2254 | 'option' => array( |
2255 | - 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
|
2255 | + 'description' => __('Selected attribute term name.', 'woocommerce'), |
|
2256 | 2256 | 'type' => 'string', |
2257 | - 'context' => array( 'view', 'edit' ), |
|
2257 | + 'context' => array('view', 'edit'), |
|
2258 | 2258 | ), |
2259 | 2259 | ), |
2260 | 2260 | ), |
2261 | 2261 | ), |
2262 | 2262 | 'variations' => array( |
2263 | - 'description' => __( 'List of variations.', 'woocommerce' ), |
|
2263 | + 'description' => __('List of variations.', 'woocommerce'), |
|
2264 | 2264 | 'type' => 'array', |
2265 | - 'context' => array( 'view', 'edit' ), |
|
2265 | + 'context' => array('view', 'edit'), |
|
2266 | 2266 | 'items' => array( |
2267 | 2267 | 'type' => 'object', |
2268 | 2268 | 'properties' => array( |
2269 | 2269 | 'id' => array( |
2270 | - 'description' => __( 'Variation ID.', 'woocommerce' ), |
|
2270 | + 'description' => __('Variation ID.', 'woocommerce'), |
|
2271 | 2271 | 'type' => 'integer', |
2272 | - 'context' => array( 'view', 'edit' ), |
|
2272 | + 'context' => array('view', 'edit'), |
|
2273 | 2273 | 'readonly' => true, |
2274 | 2274 | ), |
2275 | 2275 | 'date_created' => array( |
2276 | - 'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ), |
|
2276 | + 'description' => __("The date the variation was created, in the site's timezone.", 'woocommerce'), |
|
2277 | 2277 | 'type' => 'date-time', |
2278 | - 'context' => array( 'view', 'edit' ), |
|
2278 | + 'context' => array('view', 'edit'), |
|
2279 | 2279 | 'readonly' => true, |
2280 | 2280 | ), |
2281 | 2281 | 'date_modified' => array( |
2282 | - 'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ), |
|
2282 | + 'description' => __("The date the variation was last modified, in the site's timezone.", 'woocommerce'), |
|
2283 | 2283 | 'type' => 'date-time', |
2284 | - 'context' => array( 'view', 'edit' ), |
|
2284 | + 'context' => array('view', 'edit'), |
|
2285 | 2285 | 'readonly' => true, |
2286 | 2286 | ), |
2287 | 2287 | 'permalink' => array( |
2288 | - 'description' => __( 'Variation URL.', 'woocommerce' ), |
|
2288 | + 'description' => __('Variation URL.', 'woocommerce'), |
|
2289 | 2289 | 'type' => 'string', |
2290 | 2290 | 'format' => 'uri', |
2291 | - 'context' => array( 'view', 'edit' ), |
|
2291 | + 'context' => array('view', 'edit'), |
|
2292 | 2292 | 'readonly' => true, |
2293 | 2293 | ), |
2294 | 2294 | 'sku' => array( |
2295 | - 'description' => __( 'Unique identifier.', 'woocommerce' ), |
|
2295 | + 'description' => __('Unique identifier.', 'woocommerce'), |
|
2296 | 2296 | 'type' => 'string', |
2297 | - 'context' => array( 'view', 'edit' ), |
|
2297 | + 'context' => array('view', 'edit'), |
|
2298 | 2298 | ), |
2299 | 2299 | 'price' => array( |
2300 | - 'description' => __( 'Current variation price.', 'woocommerce' ), |
|
2300 | + 'description' => __('Current variation price.', 'woocommerce'), |
|
2301 | 2301 | 'type' => 'string', |
2302 | - 'context' => array( 'view', 'edit' ), |
|
2302 | + 'context' => array('view', 'edit'), |
|
2303 | 2303 | 'readonly' => true, |
2304 | 2304 | ), |
2305 | 2305 | 'regular_price' => array( |
2306 | - 'description' => __( 'Variation regular price.', 'woocommerce' ), |
|
2306 | + 'description' => __('Variation regular price.', 'woocommerce'), |
|
2307 | 2307 | 'type' => 'string', |
2308 | - 'context' => array( 'view', 'edit' ), |
|
2308 | + 'context' => array('view', 'edit'), |
|
2309 | 2309 | ), |
2310 | 2310 | 'sale_price' => array( |
2311 | - 'description' => __( 'Variation sale price.', 'woocommerce' ), |
|
2311 | + 'description' => __('Variation sale price.', 'woocommerce'), |
|
2312 | 2312 | 'type' => 'string', |
2313 | - 'context' => array( 'view', 'edit' ), |
|
2313 | + 'context' => array('view', 'edit'), |
|
2314 | 2314 | ), |
2315 | 2315 | 'date_on_sale_from' => array( |
2316 | - 'description' => __( 'Start date of sale price.', 'woocommerce' ), |
|
2316 | + 'description' => __('Start date of sale price.', 'woocommerce'), |
|
2317 | 2317 | 'type' => 'string', |
2318 | - 'context' => array( 'view', 'edit' ), |
|
2318 | + 'context' => array('view', 'edit'), |
|
2319 | 2319 | ), |
2320 | 2320 | 'date_on_sale_to' => array( |
2321 | - 'description' => __( 'End date of sale price.', 'woocommerce' ), |
|
2321 | + 'description' => __('End date of sale price.', 'woocommerce'), |
|
2322 | 2322 | 'type' => 'string', |
2323 | - 'context' => array( 'view', 'edit' ), |
|
2323 | + 'context' => array('view', 'edit'), |
|
2324 | 2324 | ), |
2325 | 2325 | 'on_sale' => array( |
2326 | - 'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ), |
|
2326 | + 'description' => __('Shows if the variation is on sale.', 'woocommerce'), |
|
2327 | 2327 | 'type' => 'boolean', |
2328 | - 'context' => array( 'view', 'edit' ), |
|
2328 | + 'context' => array('view', 'edit'), |
|
2329 | 2329 | 'readonly' => true, |
2330 | 2330 | ), |
2331 | 2331 | 'purchasable' => array( |
2332 | - 'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ), |
|
2332 | + 'description' => __('Shows if the variation can be bought.', 'woocommerce'), |
|
2333 | 2333 | 'type' => 'boolean', |
2334 | - 'context' => array( 'view', 'edit' ), |
|
2334 | + 'context' => array('view', 'edit'), |
|
2335 | 2335 | 'readonly' => true, |
2336 | 2336 | ), |
2337 | 2337 | 'visible' => array( |
2338 | - 'description' => __( 'If the variation is visible.', 'woocommerce' ), |
|
2338 | + 'description' => __('If the variation is visible.', 'woocommerce'), |
|
2339 | 2339 | 'type' => 'boolean', |
2340 | - 'context' => array( 'view', 'edit' ), |
|
2340 | + 'context' => array('view', 'edit'), |
|
2341 | 2341 | ), |
2342 | 2342 | 'virtual' => array( |
2343 | - 'description' => __( 'If the variation is virtual.', 'woocommerce' ), |
|
2343 | + 'description' => __('If the variation is virtual.', 'woocommerce'), |
|
2344 | 2344 | 'type' => 'boolean', |
2345 | 2345 | 'default' => false, |
2346 | - 'context' => array( 'view', 'edit' ), |
|
2346 | + 'context' => array('view', 'edit'), |
|
2347 | 2347 | ), |
2348 | 2348 | 'downloadable' => array( |
2349 | - 'description' => __( 'If the variation is downloadable.', 'woocommerce' ), |
|
2349 | + 'description' => __('If the variation is downloadable.', 'woocommerce'), |
|
2350 | 2350 | 'type' => 'boolean', |
2351 | 2351 | 'default' => false, |
2352 | - 'context' => array( 'view', 'edit' ), |
|
2352 | + 'context' => array('view', 'edit'), |
|
2353 | 2353 | ), |
2354 | 2354 | 'downloads' => array( |
2355 | - 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
|
2355 | + 'description' => __('List of downloadable files.', 'woocommerce'), |
|
2356 | 2356 | 'type' => 'array', |
2357 | - 'context' => array( 'view', 'edit' ), |
|
2357 | + 'context' => array('view', 'edit'), |
|
2358 | 2358 | 'items' => array( |
2359 | 2359 | 'type' => 'object', |
2360 | 2360 | 'properties' => array( |
2361 | 2361 | 'id' => array( |
2362 | - 'description' => __( 'File ID.', 'woocommerce' ), |
|
2362 | + 'description' => __('File ID.', 'woocommerce'), |
|
2363 | 2363 | 'type' => 'string', |
2364 | - 'context' => array( 'view', 'edit' ), |
|
2364 | + 'context' => array('view', 'edit'), |
|
2365 | 2365 | ), |
2366 | 2366 | 'name' => array( |
2367 | - 'description' => __( 'File name.', 'woocommerce' ), |
|
2367 | + 'description' => __('File name.', 'woocommerce'), |
|
2368 | 2368 | 'type' => 'string', |
2369 | - 'context' => array( 'view', 'edit' ), |
|
2369 | + 'context' => array('view', 'edit'), |
|
2370 | 2370 | ), |
2371 | 2371 | 'file' => array( |
2372 | - 'description' => __( 'File URL.', 'woocommerce' ), |
|
2372 | + 'description' => __('File URL.', 'woocommerce'), |
|
2373 | 2373 | 'type' => 'string', |
2374 | - 'context' => array( 'view', 'edit' ), |
|
2374 | + 'context' => array('view', 'edit'), |
|
2375 | 2375 | ), |
2376 | 2376 | ), |
2377 | 2377 | ), |
2378 | 2378 | ), |
2379 | 2379 | 'download_limit' => array( |
2380 | - 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
|
2380 | + 'description' => __('Number of times downloadable files can be downloaded after purchase.', 'woocommerce'), |
|
2381 | 2381 | 'type' => 'integer', |
2382 | 2382 | 'default' => null, |
2383 | - 'context' => array( 'view', 'edit' ), |
|
2383 | + 'context' => array('view', 'edit'), |
|
2384 | 2384 | ), |
2385 | 2385 | 'download_expiry' => array( |
2386 | - 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
|
2386 | + 'description' => __('Number of days until access to downloadable files expires.', 'woocommerce'), |
|
2387 | 2387 | 'type' => 'integer', |
2388 | 2388 | 'default' => null, |
2389 | - 'context' => array( 'view', 'edit' ), |
|
2389 | + 'context' => array('view', 'edit'), |
|
2390 | 2390 | ), |
2391 | 2391 | 'tax_status' => array( |
2392 | - 'description' => __( 'Tax status.', 'woocommerce' ), |
|
2392 | + 'description' => __('Tax status.', 'woocommerce'), |
|
2393 | 2393 | 'type' => 'string', |
2394 | 2394 | 'default' => 'taxable', |
2395 | - 'enum' => array( 'taxable', 'shipping', 'none' ), |
|
2396 | - 'context' => array( 'view', 'edit' ), |
|
2395 | + 'enum' => array('taxable', 'shipping', 'none'), |
|
2396 | + 'context' => array('view', 'edit'), |
|
2397 | 2397 | ), |
2398 | 2398 | 'tax_class' => array( |
2399 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
2399 | + 'description' => __('Tax class.', 'woocommerce'), |
|
2400 | 2400 | 'type' => 'string', |
2401 | - 'context' => array( 'view', 'edit' ), |
|
2401 | + 'context' => array('view', 'edit'), |
|
2402 | 2402 | ), |
2403 | 2403 | 'manage_stock' => array( |
2404 | - 'description' => __( 'Stock management at variation level.', 'woocommerce' ), |
|
2404 | + 'description' => __('Stock management at variation level.', 'woocommerce'), |
|
2405 | 2405 | 'type' => 'boolean', |
2406 | 2406 | 'default' => false, |
2407 | - 'context' => array( 'view', 'edit' ), |
|
2407 | + 'context' => array('view', 'edit'), |
|
2408 | 2408 | ), |
2409 | 2409 | 'stock_quantity' => array( |
2410 | - 'description' => __( 'Stock quantity.', 'woocommerce' ), |
|
2410 | + 'description' => __('Stock quantity.', 'woocommerce'), |
|
2411 | 2411 | 'type' => 'integer', |
2412 | - 'context' => array( 'view', 'edit' ), |
|
2412 | + 'context' => array('view', 'edit'), |
|
2413 | 2413 | ), |
2414 | 2414 | 'in_stock' => array( |
2415 | - 'description' => __( 'Controls whether or not the variation is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ), |
|
2415 | + 'description' => __('Controls whether or not the variation is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce'), |
|
2416 | 2416 | 'type' => 'boolean', |
2417 | 2417 | 'default' => true, |
2418 | - 'context' => array( 'view', 'edit' ), |
|
2418 | + 'context' => array('view', 'edit'), |
|
2419 | 2419 | ), |
2420 | 2420 | 'backorders' => array( |
2421 | - 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
|
2421 | + 'description' => __('If managing stock, this controls if backorders are allowed.', 'woocommerce'), |
|
2422 | 2422 | 'type' => 'string', |
2423 | 2423 | 'default' => 'no', |
2424 | - 'enum' => array( 'no', 'notify', 'yes' ), |
|
2425 | - 'context' => array( 'view', 'edit' ), |
|
2424 | + 'enum' => array('no', 'notify', 'yes'), |
|
2425 | + 'context' => array('view', 'edit'), |
|
2426 | 2426 | ), |
2427 | 2427 | 'backorders_allowed' => array( |
2428 | - 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
|
2428 | + 'description' => __('Shows if backorders are allowed.', 'woocommerce'), |
|
2429 | 2429 | 'type' => 'boolean', |
2430 | - 'context' => array( 'view', 'edit' ), |
|
2430 | + 'context' => array('view', 'edit'), |
|
2431 | 2431 | 'readonly' => true, |
2432 | 2432 | ), |
2433 | 2433 | 'backordered' => array( |
2434 | - 'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ), |
|
2434 | + 'description' => __('Shows if the variation is on backordered.', 'woocommerce'), |
|
2435 | 2435 | 'type' => 'boolean', |
2436 | - 'context' => array( 'view', 'edit' ), |
|
2436 | + 'context' => array('view', 'edit'), |
|
2437 | 2437 | 'readonly' => true, |
2438 | 2438 | ), |
2439 | 2439 | 'weight' => array( |
2440 | 2440 | /* translators: %s: weight unit */ |
2441 | - 'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ), |
|
2441 | + 'description' => sprintf(__('Variation weight (%s).', 'woocommerce'), $weight_unit), |
|
2442 | 2442 | 'type' => 'string', |
2443 | - 'context' => array( 'view', 'edit' ), |
|
2443 | + 'context' => array('view', 'edit'), |
|
2444 | 2444 | ), |
2445 | 2445 | 'dimensions' => array( |
2446 | - 'description' => __( 'Variation dimensions.', 'woocommerce' ), |
|
2446 | + 'description' => __('Variation dimensions.', 'woocommerce'), |
|
2447 | 2447 | 'type' => 'object', |
2448 | - 'context' => array( 'view', 'edit' ), |
|
2448 | + 'context' => array('view', 'edit'), |
|
2449 | 2449 | 'properties' => array( |
2450 | 2450 | 'length' => array( |
2451 | 2451 | /* translators: %s: dimension unit */ |
2452 | - 'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ), |
|
2452 | + 'description' => sprintf(__('Variation length (%s).', 'woocommerce'), $dimension_unit), |
|
2453 | 2453 | 'type' => 'string', |
2454 | - 'context' => array( 'view', 'edit' ), |
|
2454 | + 'context' => array('view', 'edit'), |
|
2455 | 2455 | ), |
2456 | 2456 | 'width' => array( |
2457 | 2457 | /* translators: %s: dimension unit */ |
2458 | - 'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ), |
|
2458 | + 'description' => sprintf(__('Variation width (%s).', 'woocommerce'), $dimension_unit), |
|
2459 | 2459 | 'type' => 'string', |
2460 | - 'context' => array( 'view', 'edit' ), |
|
2460 | + 'context' => array('view', 'edit'), |
|
2461 | 2461 | ), |
2462 | 2462 | 'height' => array( |
2463 | 2463 | /* translators: %s: dimension unit */ |
2464 | - 'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ), |
|
2464 | + 'description' => sprintf(__('Variation height (%s).', 'woocommerce'), $dimension_unit), |
|
2465 | 2465 | 'type' => 'string', |
2466 | - 'context' => array( 'view', 'edit' ), |
|
2466 | + 'context' => array('view', 'edit'), |
|
2467 | 2467 | ), |
2468 | 2468 | ), |
2469 | 2469 | ), |
2470 | 2470 | 'shipping_class' => array( |
2471 | - 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
|
2471 | + 'description' => __('Shipping class slug.', 'woocommerce'), |
|
2472 | 2472 | 'type' => 'string', |
2473 | - 'context' => array( 'view', 'edit' ), |
|
2473 | + 'context' => array('view', 'edit'), |
|
2474 | 2474 | ), |
2475 | 2475 | 'shipping_class_id' => array( |
2476 | - 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
|
2476 | + 'description' => __('Shipping class ID.', 'woocommerce'), |
|
2477 | 2477 | 'type' => 'integer', |
2478 | - 'context' => array( 'view', 'edit' ), |
|
2478 | + 'context' => array('view', 'edit'), |
|
2479 | 2479 | 'readonly' => true, |
2480 | 2480 | ), |
2481 | 2481 | 'image' => array( |
2482 | - 'description' => __( 'Variation image data.', 'woocommerce' ), |
|
2482 | + 'description' => __('Variation image data.', 'woocommerce'), |
|
2483 | 2483 | 'type' => 'object', |
2484 | - 'context' => array( 'view', 'edit' ), |
|
2484 | + 'context' => array('view', 'edit'), |
|
2485 | 2485 | 'properties' => array( |
2486 | 2486 | 'id' => array( |
2487 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
2487 | + 'description' => __('Image ID.', 'woocommerce'), |
|
2488 | 2488 | 'type' => 'integer', |
2489 | - 'context' => array( 'view', 'edit' ), |
|
2489 | + 'context' => array('view', 'edit'), |
|
2490 | 2490 | ), |
2491 | 2491 | 'date_created' => array( |
2492 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
2492 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
2493 | 2493 | 'type' => 'date-time', |
2494 | - 'context' => array( 'view', 'edit' ), |
|
2494 | + 'context' => array('view', 'edit'), |
|
2495 | 2495 | 'readonly' => true, |
2496 | 2496 | ), |
2497 | 2497 | 'date_modified' => array( |
2498 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
2498 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
2499 | 2499 | 'type' => 'date-time', |
2500 | - 'context' => array( 'view', 'edit' ), |
|
2500 | + 'context' => array('view', 'edit'), |
|
2501 | 2501 | 'readonly' => true, |
2502 | 2502 | ), |
2503 | 2503 | 'src' => array( |
2504 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
2504 | + 'description' => __('Image URL.', 'woocommerce'), |
|
2505 | 2505 | 'type' => 'string', |
2506 | 2506 | 'format' => 'uri', |
2507 | - 'context' => array( 'view', 'edit' ), |
|
2507 | + 'context' => array('view', 'edit'), |
|
2508 | 2508 | ), |
2509 | 2509 | 'name' => array( |
2510 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
2510 | + 'description' => __('Image name.', 'woocommerce'), |
|
2511 | 2511 | 'type' => 'string', |
2512 | - 'context' => array( 'view', 'edit' ), |
|
2512 | + 'context' => array('view', 'edit'), |
|
2513 | 2513 | ), |
2514 | 2514 | 'alt' => array( |
2515 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
2515 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
2516 | 2516 | 'type' => 'string', |
2517 | - 'context' => array( 'view', 'edit' ), |
|
2517 | + 'context' => array('view', 'edit'), |
|
2518 | 2518 | ), |
2519 | 2519 | 'position' => array( |
2520 | - 'description' => __( 'Image position. 0 means that the image is featured.', 'woocommerce' ), |
|
2520 | + 'description' => __('Image position. 0 means that the image is featured.', 'woocommerce'), |
|
2521 | 2521 | 'type' => 'integer', |
2522 | - 'context' => array( 'view', 'edit' ), |
|
2522 | + 'context' => array('view', 'edit'), |
|
2523 | 2523 | ), |
2524 | 2524 | ), |
2525 | 2525 | ), |
2526 | 2526 | 'attributes' => array( |
2527 | - 'description' => __( 'List of attributes.', 'woocommerce' ), |
|
2527 | + 'description' => __('List of attributes.', 'woocommerce'), |
|
2528 | 2528 | 'type' => 'array', |
2529 | - 'context' => array( 'view', 'edit' ), |
|
2529 | + 'context' => array('view', 'edit'), |
|
2530 | 2530 | 'items' => array( |
2531 | 2531 | 'type' => 'object', |
2532 | 2532 | 'properties' => array( |
2533 | 2533 | 'id' => array( |
2534 | - 'description' => __( 'Attribute ID.', 'woocommerce' ), |
|
2534 | + 'description' => __('Attribute ID.', 'woocommerce'), |
|
2535 | 2535 | 'type' => 'integer', |
2536 | - 'context' => array( 'view', 'edit' ), |
|
2536 | + 'context' => array('view', 'edit'), |
|
2537 | 2537 | ), |
2538 | 2538 | 'name' => array( |
2539 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
2539 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
2540 | 2540 | 'type' => 'string', |
2541 | - 'context' => array( 'view', 'edit' ), |
|
2541 | + 'context' => array('view', 'edit'), |
|
2542 | 2542 | ), |
2543 | 2543 | 'option' => array( |
2544 | - 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
|
2544 | + 'description' => __('Selected attribute term name.', 'woocommerce'), |
|
2545 | 2545 | 'type' => 'string', |
2546 | - 'context' => array( 'view', 'edit' ), |
|
2546 | + 'context' => array('view', 'edit'), |
|
2547 | 2547 | ), |
2548 | 2548 | ), |
2549 | 2549 | ), |
@@ -2552,23 +2552,23 @@ discard block |
||
2552 | 2552 | ), |
2553 | 2553 | ), |
2554 | 2554 | 'grouped_products' => array( |
2555 | - 'description' => __( 'List of grouped products ID.', 'woocommerce' ), |
|
2555 | + 'description' => __('List of grouped products ID.', 'woocommerce'), |
|
2556 | 2556 | 'type' => 'array', |
2557 | 2557 | 'items' => array( |
2558 | 2558 | 'type' => 'integer', |
2559 | 2559 | ), |
2560 | - 'context' => array( 'view', 'edit' ), |
|
2560 | + 'context' => array('view', 'edit'), |
|
2561 | 2561 | 'readonly' => true, |
2562 | 2562 | ), |
2563 | 2563 | 'menu_order' => array( |
2564 | - 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), |
|
2564 | + 'description' => __('Menu order, used to custom sort products.', 'woocommerce'), |
|
2565 | 2565 | 'type' => 'integer', |
2566 | - 'context' => array( 'view', 'edit' ), |
|
2566 | + 'context' => array('view', 'edit'), |
|
2567 | 2567 | ), |
2568 | 2568 | ), |
2569 | 2569 | ); |
2570 | 2570 | |
2571 | - return $this->add_additional_fields_schema( $schema ); |
|
2571 | + return $this->add_additional_fields_schema($schema); |
|
2572 | 2572 | } |
2573 | 2573 | |
2574 | 2574 | /** |
@@ -2580,57 +2580,57 @@ discard block |
||
2580 | 2580 | $params = parent::get_collection_params(); |
2581 | 2581 | |
2582 | 2582 | $params['slug'] = array( |
2583 | - 'description' => __( 'Limit result set to products with a specific slug.', 'woocommerce' ), |
|
2583 | + 'description' => __('Limit result set to products with a specific slug.', 'woocommerce'), |
|
2584 | 2584 | 'type' => 'string', |
2585 | 2585 | 'validate_callback' => 'rest_validate_request_arg', |
2586 | 2586 | ); |
2587 | 2587 | $params['status'] = array( |
2588 | 2588 | 'default' => 'any', |
2589 | - 'description' => __( 'Limit result set to products assigned a specific status.', 'woocommerce' ), |
|
2589 | + 'description' => __('Limit result set to products assigned a specific status.', 'woocommerce'), |
|
2590 | 2590 | 'type' => 'string', |
2591 | - 'enum' => array_merge( array( 'any', 'future' ), array_keys( get_post_statuses() ) ), |
|
2591 | + 'enum' => array_merge(array('any', 'future'), array_keys(get_post_statuses())), |
|
2592 | 2592 | 'sanitize_callback' => 'sanitize_key', |
2593 | 2593 | 'validate_callback' => 'rest_validate_request_arg', |
2594 | 2594 | ); |
2595 | 2595 | $params['type'] = array( |
2596 | - 'description' => __( 'Limit result set to products assigned a specific type.', 'woocommerce' ), |
|
2596 | + 'description' => __('Limit result set to products assigned a specific type.', 'woocommerce'), |
|
2597 | 2597 | 'type' => 'string', |
2598 | - 'enum' => array_keys( wc_get_product_types() ), |
|
2598 | + 'enum' => array_keys(wc_get_product_types()), |
|
2599 | 2599 | 'sanitize_callback' => 'sanitize_key', |
2600 | 2600 | 'validate_callback' => 'rest_validate_request_arg', |
2601 | 2601 | ); |
2602 | 2602 | $params['category'] = array( |
2603 | - 'description' => __( 'Limit result set to products assigned a specific category ID.', 'woocommerce' ), |
|
2603 | + 'description' => __('Limit result set to products assigned a specific category ID.', 'woocommerce'), |
|
2604 | 2604 | 'type' => 'string', |
2605 | 2605 | 'sanitize_callback' => 'wp_parse_id_list', |
2606 | 2606 | 'validate_callback' => 'rest_validate_request_arg', |
2607 | 2607 | ); |
2608 | 2608 | $params['tag'] = array( |
2609 | - 'description' => __( 'Limit result set to products assigned a specific tag ID.', 'woocommerce' ), |
|
2609 | + 'description' => __('Limit result set to products assigned a specific tag ID.', 'woocommerce'), |
|
2610 | 2610 | 'type' => 'string', |
2611 | 2611 | 'sanitize_callback' => 'wp_parse_id_list', |
2612 | 2612 | 'validate_callback' => 'rest_validate_request_arg', |
2613 | 2613 | ); |
2614 | 2614 | $params['shipping_class'] = array( |
2615 | - 'description' => __( 'Limit result set to products assigned a specific shipping class ID.', 'woocommerce' ), |
|
2615 | + 'description' => __('Limit result set to products assigned a specific shipping class ID.', 'woocommerce'), |
|
2616 | 2616 | 'type' => 'string', |
2617 | 2617 | 'sanitize_callback' => 'wp_parse_id_list', |
2618 | 2618 | 'validate_callback' => 'rest_validate_request_arg', |
2619 | 2619 | ); |
2620 | 2620 | $params['attribute'] = array( |
2621 | - 'description' => __( 'Limit result set to products with a specific attribute.', 'woocommerce' ), |
|
2621 | + 'description' => __('Limit result set to products with a specific attribute.', 'woocommerce'), |
|
2622 | 2622 | 'type' => 'string', |
2623 | 2623 | 'sanitize_callback' => 'sanitize_text_field', |
2624 | 2624 | 'validate_callback' => 'rest_validate_request_arg', |
2625 | 2625 | ); |
2626 | 2626 | $params['attribute_term'] = array( |
2627 | - 'description' => __( 'Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce' ), |
|
2627 | + 'description' => __('Limit result set to products with a specific attribute term ID (required an assigned attribute).', 'woocommerce'), |
|
2628 | 2628 | 'type' => 'string', |
2629 | 2629 | 'sanitize_callback' => 'wp_parse_id_list', |
2630 | 2630 | 'validate_callback' => 'rest_validate_request_arg', |
2631 | 2631 | ); |
2632 | 2632 | $params['sku'] = array( |
2633 | - 'description' => __( 'Limit result set to products with a specific SKU.', 'woocommerce' ), |
|
2633 | + 'description' => __('Limit result set to products with a specific SKU.', 'woocommerce'), |
|
2634 | 2634 | 'type' => 'string', |
2635 | 2635 | 'sanitize_callback' => 'sanitize_text_field', |
2636 | 2636 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -40,89 +40,89 @@ discard block |
||
40 | 40 | * Register the routes for terms. |
41 | 41 | */ |
42 | 42 | public function register_routes() { |
43 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
43 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
44 | 44 | 'args' => array( |
45 | 45 | 'attribute_id' => array( |
46 | - 'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ), |
|
46 | + 'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'), |
|
47 | 47 | 'type' => 'integer', |
48 | 48 | ), |
49 | 49 | ), |
50 | 50 | array( |
51 | 51 | 'methods' => WP_REST_Server::READABLE, |
52 | - 'callback' => array( $this, 'get_items' ), |
|
53 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
52 | + 'callback' => array($this, 'get_items'), |
|
53 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
54 | 54 | 'args' => $this->get_collection_params(), |
55 | 55 | ), |
56 | 56 | array( |
57 | 57 | 'methods' => WP_REST_Server::CREATABLE, |
58 | - 'callback' => array( $this, 'create_item' ), |
|
59 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
60 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
58 | + 'callback' => array($this, 'create_item'), |
|
59 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
60 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
61 | 61 | 'name' => array( |
62 | 62 | 'type' => 'string', |
63 | - 'description' => __( 'Name for the resource.', 'woocommerce' ), |
|
63 | + 'description' => __('Name for the resource.', 'woocommerce'), |
|
64 | 64 | 'required' => true, |
65 | 65 | ), |
66 | - ) ), |
|
66 | + )), |
|
67 | 67 | ), |
68 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
68 | + 'schema' => array($this, 'get_public_item_schema'), |
|
69 | 69 | )); |
70 | 70 | |
71 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
71 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
72 | 72 | 'args' => array( |
73 | 73 | 'id' => array( |
74 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
74 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
75 | 75 | 'type' => 'integer', |
76 | 76 | ), |
77 | 77 | 'attribute_id' => array( |
78 | - 'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ), |
|
78 | + 'description' => __('Unique identifier for the attribute of the terms.', '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 | ), |
107 | 107 | ), |
108 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
109 | - ) ); |
|
108 | + 'schema' => array($this, 'get_public_item_schema'), |
|
109 | + )); |
|
110 | 110 | |
111 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
111 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
112 | 112 | 'args' => array( |
113 | 113 | 'attribute_id' => array( |
114 | - 'description' => __( 'Unique identifier for the attribute of the terms.', 'woocommerce' ), |
|
114 | + 'description' => __('Unique identifier for the attribute of the terms.', 'woocommerce'), |
|
115 | 115 | 'type' => 'integer', |
116 | 116 | ), |
117 | 117 | ), |
118 | 118 | array( |
119 | 119 | 'methods' => WP_REST_Server::EDITABLE, |
120 | - 'callback' => array( $this, 'batch_items' ), |
|
121 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
122 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
120 | + 'callback' => array($this, 'batch_items'), |
|
121 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
122 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
123 | 123 | ), |
124 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
125 | - ) ); |
|
124 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
125 | + )); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @param WP_REST_Request $request |
133 | 133 | * @return WP_REST_Response $response |
134 | 134 | */ |
135 | - public function prepare_item_for_response( $item, $request ) { |
|
135 | + public function prepare_item_for_response($item, $request) { |
|
136 | 136 | // Get term order. |
137 | - $menu_order = get_term_meta( $item->term_id, 'order_' . $this->taxonomy, true ); |
|
137 | + $menu_order = get_term_meta($item->term_id, 'order_' . $this->taxonomy, true); |
|
138 | 138 | |
139 | 139 | $data = array( |
140 | 140 | 'id' => (int) $item->term_id, |
@@ -145,13 +145,13 @@ discard block |
||
145 | 145 | 'count' => (int) $item->count, |
146 | 146 | ); |
147 | 147 | |
148 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
149 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
150 | - $data = $this->filter_response_by_context( $data, $context ); |
|
148 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
149 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
150 | + $data = $this->filter_response_by_context($data, $context); |
|
151 | 151 | |
152 | - $response = rest_ensure_response( $data ); |
|
152 | + $response = rest_ensure_response($data); |
|
153 | 153 | |
154 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
154 | + $response->add_links($this->prepare_links($item, $request)); |
|
155 | 155 | |
156 | 156 | /** |
157 | 157 | * Filter a term item returned from the API. |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param object $item The original term object. |
163 | 163 | * @param WP_REST_Request $request Request used to generate the response. |
164 | 164 | */ |
165 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
165 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,10 +172,10 @@ discard block |
||
172 | 172 | * @param WP_REST_Request $request |
173 | 173 | * @return bool|WP_Error |
174 | 174 | */ |
175 | - protected function update_term_meta_fields( $term, $request ) { |
|
175 | + protected function update_term_meta_fields($term, $request) { |
|
176 | 176 | $id = (int) $term->term_id; |
177 | 177 | |
178 | - update_term_meta( $id, 'order_' . $this->taxonomy, $request['menu_order'] ); |
|
178 | + update_term_meta($id, 'order_' . $this->taxonomy, $request['menu_order']); |
|
179 | 179 | |
180 | 180 | return true; |
181 | 181 | } |
@@ -192,49 +192,49 @@ discard block |
||
192 | 192 | 'type' => 'object', |
193 | 193 | 'properties' => array( |
194 | 194 | 'id' => array( |
195 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
195 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
196 | 196 | 'type' => 'integer', |
197 | - 'context' => array( 'view', 'edit' ), |
|
197 | + 'context' => array('view', 'edit'), |
|
198 | 198 | 'readonly' => true, |
199 | 199 | ), |
200 | 200 | 'name' => array( |
201 | - 'description' => __( 'Term name.', 'woocommerce' ), |
|
201 | + 'description' => __('Term name.', 'woocommerce'), |
|
202 | 202 | 'type' => 'string', |
203 | - 'context' => array( 'view', 'edit' ), |
|
203 | + 'context' => array('view', 'edit'), |
|
204 | 204 | 'arg_options' => array( |
205 | 205 | 'sanitize_callback' => 'sanitize_text_field', |
206 | 206 | ), |
207 | 207 | ), |
208 | 208 | 'slug' => array( |
209 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
209 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
210 | 210 | 'type' => 'string', |
211 | - 'context' => array( 'view', 'edit' ), |
|
211 | + 'context' => array('view', 'edit'), |
|
212 | 212 | 'arg_options' => array( |
213 | 213 | 'sanitize_callback' => 'sanitize_title', |
214 | 214 | ), |
215 | 215 | ), |
216 | 216 | 'description' => array( |
217 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
217 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
218 | 218 | 'type' => 'string', |
219 | - 'context' => array( 'view', 'edit' ), |
|
219 | + 'context' => array('view', 'edit'), |
|
220 | 220 | 'arg_options' => array( |
221 | 221 | 'sanitize_callback' => 'wp_filter_post_kses', |
222 | 222 | ), |
223 | 223 | ), |
224 | 224 | 'menu_order' => array( |
225 | - 'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ), |
|
225 | + 'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'), |
|
226 | 226 | 'type' => 'integer', |
227 | - 'context' => array( 'view', 'edit' ), |
|
227 | + 'context' => array('view', 'edit'), |
|
228 | 228 | ), |
229 | 229 | 'count' => array( |
230 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
230 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
231 | 231 | 'type' => 'integer', |
232 | - 'context' => array( 'view', 'edit' ), |
|
232 | + 'context' => array('view', 'edit'), |
|
233 | 233 | 'readonly' => true, |
234 | 234 | ), |
235 | 235 | ), |
236 | 236 | ); |
237 | 237 | |
238 | - return $this->add_additional_fields_schema( $schema ); |
|
238 | + return $this->add_additional_fields_schema($schema); |
|
239 | 239 | } |
240 | 240 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -40,67 +40,67 @@ discard block |
||
40 | 40 | * Register the routes for taxes. |
41 | 41 | */ |
42 | 42 | public function register_routes() { |
43 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
43 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
44 | 44 | array( |
45 | 45 | 'methods' => WP_REST_Server::READABLE, |
46 | - 'callback' => array( $this, 'get_items' ), |
|
47 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
46 | + 'callback' => array($this, 'get_items'), |
|
47 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
48 | 48 | 'args' => $this->get_collection_params(), |
49 | 49 | ), |
50 | 50 | array( |
51 | 51 | 'methods' => WP_REST_Server::CREATABLE, |
52 | - 'callback' => array( $this, 'create_item' ), |
|
53 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
54 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
52 | + 'callback' => array($this, 'create_item'), |
|
53 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
54 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
55 | 55 | ), |
56 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
57 | - ) ); |
|
56 | + 'schema' => array($this, 'get_public_item_schema'), |
|
57 | + )); |
|
58 | 58 | |
59 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
59 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
60 | 60 | 'args' => array( |
61 | 61 | 'id' => array( |
62 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
62 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
63 | 63 | 'type' => 'integer', |
64 | 64 | ), |
65 | 65 | ), |
66 | 66 | array( |
67 | 67 | 'methods' => WP_REST_Server::READABLE, |
68 | - 'callback' => array( $this, 'get_item' ), |
|
69 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
68 | + 'callback' => array($this, 'get_item'), |
|
69 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
70 | 70 | 'args' => array( |
71 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
71 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
72 | 72 | ), |
73 | 73 | ), |
74 | 74 | array( |
75 | 75 | 'methods' => WP_REST_Server::EDITABLE, |
76 | - 'callback' => array( $this, 'update_item' ), |
|
77 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
78 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
76 | + 'callback' => array($this, 'update_item'), |
|
77 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
78 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
79 | 79 | ), |
80 | 80 | array( |
81 | 81 | 'methods' => WP_REST_Server::DELETABLE, |
82 | - 'callback' => array( $this, 'delete_item' ), |
|
83 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
82 | + 'callback' => array($this, 'delete_item'), |
|
83 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
84 | 84 | 'args' => array( |
85 | 85 | 'force' => array( |
86 | 86 | 'default' => false, |
87 | 87 | 'type' => 'boolean', |
88 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
88 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
89 | 89 | ), |
90 | 90 | ), |
91 | 91 | ), |
92 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
93 | - ) ); |
|
92 | + 'schema' => array($this, 'get_public_item_schema'), |
|
93 | + )); |
|
94 | 94 | |
95 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
95 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
96 | 96 | array( |
97 | 97 | 'methods' => WP_REST_Server::EDITABLE, |
98 | - 'callback' => array( $this, 'batch_items' ), |
|
99 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
100 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
98 | + 'callback' => array($this, 'batch_items'), |
|
99 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
100 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
101 | 101 | ), |
102 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
103 | - ) ); |
|
102 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
103 | + )); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | * @param WP_REST_Request $request Full details about the request. |
110 | 110 | * @return WP_Error|boolean |
111 | 111 | */ |
112 | - public function get_items_permissions_check( $request ) { |
|
113 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
114 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
112 | + public function get_items_permissions_check($request) { |
|
113 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
114 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return true; |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return bool|WP_Error |
126 | 126 | */ |
127 | - public function create_item_permissions_check( $request ) { |
|
128 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) { |
|
129 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
127 | + public function create_item_permissions_check($request) { |
|
128 | + if ( ! wc_rest_check_manager_permissions('settings', 'create')) { |
|
129 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | return true; |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | * @param WP_REST_Request $request Full details about the request. |
139 | 139 | * @return WP_Error|boolean |
140 | 140 | */ |
141 | - public function get_item_permissions_check( $request ) { |
|
142 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
143 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
141 | + public function get_item_permissions_check($request) { |
|
142 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
143 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return true; |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @return bool|WP_Error |
155 | 155 | */ |
156 | - public function update_item_permissions_check( $request ) { |
|
157 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) { |
|
158 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
156 | + public function update_item_permissions_check($request) { |
|
157 | + if ( ! wc_rest_check_manager_permissions('settings', 'edit')) { |
|
158 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return true; |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return bool|WP_Error |
170 | 170 | */ |
171 | - public function delete_item_permissions_check( $request ) { |
|
172 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { |
|
173 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
171 | + public function delete_item_permissions_check($request) { |
|
172 | + if ( ! wc_rest_check_manager_permissions('settings', 'delete')) { |
|
173 | + return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | return true; |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return bool|WP_Error |
185 | 185 | */ |
186 | - public function batch_items_permissions_check( $request ) { |
|
187 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'batch' ) ) { |
|
188 | - 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() ) ); |
|
186 | + public function batch_items_permissions_check($request) { |
|
187 | + if ( ! wc_rest_check_manager_permissions('settings', 'batch')) { |
|
188 | + 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())); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | return true; |
@@ -197,22 +197,22 @@ discard block |
||
197 | 197 | * @param WP_REST_Request $request Full details about the request. |
198 | 198 | * @return WP_Error|WP_REST_Response |
199 | 199 | */ |
200 | - public function get_items( $request ) { |
|
200 | + public function get_items($request) { |
|
201 | 201 | global $wpdb; |
202 | 202 | |
203 | 203 | $prepared_args = array(); |
204 | 204 | $prepared_args['order'] = $request['order']; |
205 | 205 | $prepared_args['number'] = $request['per_page']; |
206 | - if ( ! empty( $request['offset'] ) ) { |
|
206 | + if ( ! empty($request['offset'])) { |
|
207 | 207 | $prepared_args['offset'] = $request['offset']; |
208 | 208 | } else { |
209 | - $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number']; |
|
209 | + $prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number']; |
|
210 | 210 | } |
211 | 211 | $orderby_possibles = array( |
212 | 212 | 'id' => 'tax_rate_id', |
213 | 213 | 'order' => 'tax_rate_order', |
214 | 214 | ); |
215 | - $prepared_args['orderby'] = $orderby_possibles[ $request['orderby'] ]; |
|
215 | + $prepared_args['orderby'] = $orderby_possibles[$request['orderby']]; |
|
216 | 216 | $prepared_args['class'] = $request['class']; |
217 | 217 | |
218 | 218 | /** |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @param array $prepared_args Array of arguments for $wpdb->get_results(). |
222 | 222 | * @param WP_REST_Request $request The current request. |
223 | 223 | */ |
224 | - $prepared_args = apply_filters( 'woocommerce_rest_tax_query', $prepared_args, $request ); |
|
224 | + $prepared_args = apply_filters('woocommerce_rest_tax_query', $prepared_args, $request); |
|
225 | 225 | |
226 | 226 | $query = " |
227 | 227 | SELECT * |
@@ -230,54 +230,54 @@ discard block |
||
230 | 230 | "; |
231 | 231 | |
232 | 232 | // Filter by tax class. |
233 | - if ( ! empty( $prepared_args['class'] ) ) { |
|
234 | - $class = 'standard' !== $prepared_args['class'] ? sanitize_title( $prepared_args['class'] ) : ''; |
|
233 | + if ( ! empty($prepared_args['class'])) { |
|
234 | + $class = 'standard' !== $prepared_args['class'] ? sanitize_title($prepared_args['class']) : ''; |
|
235 | 235 | $query .= " AND tax_rate_class = '$class'"; |
236 | 236 | } |
237 | 237 | |
238 | 238 | // Order tax rates. |
239 | - $order_by = sprintf( ' ORDER BY %s', sanitize_key( $prepared_args['orderby'] ) ); |
|
239 | + $order_by = sprintf(' ORDER BY %s', sanitize_key($prepared_args['orderby'])); |
|
240 | 240 | |
241 | 241 | // Pagination. |
242 | - $pagination = sprintf( ' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number'] ); |
|
242 | + $pagination = sprintf(' LIMIT %d, %d', $prepared_args['offset'], $prepared_args['number']); |
|
243 | 243 | |
244 | 244 | // Query taxes. |
245 | - $results = $wpdb->get_results( $query . $order_by . $pagination ); |
|
245 | + $results = $wpdb->get_results($query . $order_by . $pagination); |
|
246 | 246 | |
247 | 247 | $taxes = array(); |
248 | - foreach ( $results as $tax ) { |
|
249 | - $data = $this->prepare_item_for_response( $tax, $request ); |
|
250 | - $taxes[] = $this->prepare_response_for_collection( $data ); |
|
248 | + foreach ($results as $tax) { |
|
249 | + $data = $this->prepare_item_for_response($tax, $request); |
|
250 | + $taxes[] = $this->prepare_response_for_collection($data); |
|
251 | 251 | } |
252 | 252 | |
253 | - $response = rest_ensure_response( $taxes ); |
|
253 | + $response = rest_ensure_response($taxes); |
|
254 | 254 | |
255 | 255 | // Store pagination values for headers then unset for count query. |
256 | 256 | $per_page = (int) $prepared_args['number']; |
257 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
257 | + $page = ceil((((int) $prepared_args['offset']) / $per_page) + 1); |
|
258 | 258 | |
259 | 259 | // Query only for ids. |
260 | - $wpdb->get_results( str_replace( 'SELECT *', 'SELECT tax_rate_id', $query ) ); |
|
260 | + $wpdb->get_results(str_replace('SELECT *', 'SELECT tax_rate_id', $query)); |
|
261 | 261 | |
262 | 262 | // Calculate totals. |
263 | 263 | $total_taxes = (int) $wpdb->num_rows; |
264 | - $response->header( 'X-WP-Total', (int) $total_taxes ); |
|
265 | - $max_pages = ceil( $total_taxes / $per_page ); |
|
266 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
264 | + $response->header('X-WP-Total', (int) $total_taxes); |
|
265 | + $max_pages = ceil($total_taxes / $per_page); |
|
266 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
267 | 267 | |
268 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
269 | - if ( $page > 1 ) { |
|
268 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
269 | + if ($page > 1) { |
|
270 | 270 | $prev_page = $page - 1; |
271 | - if ( $prev_page > $max_pages ) { |
|
271 | + if ($prev_page > $max_pages) { |
|
272 | 272 | $prev_page = $max_pages; |
273 | 273 | } |
274 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
275 | - $response->link_header( 'prev', $prev_link ); |
|
274 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
275 | + $response->link_header('prev', $prev_link); |
|
276 | 276 | } |
277 | - if ( $max_pages > $page ) { |
|
277 | + if ($max_pages > $page) { |
|
278 | 278 | $next_page = $page + 1; |
279 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
280 | - $response->link_header( 'next', $next_link ); |
|
279 | + $next_link = add_query_arg('page', $next_page, $base); |
|
280 | + $response->link_header('next', $next_link); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | return $response; |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | * @param stdClass|null $current Existing tax object. |
291 | 291 | * @return object |
292 | 292 | */ |
293 | - protected function create_or_update_tax( $request, $current = null ) { |
|
294 | - $id = absint( isset( $request['id'] ) ? $request['id'] : 0 ); |
|
293 | + protected function create_or_update_tax($request, $current = null) { |
|
294 | + $id = absint(isset($request['id']) ? $request['id'] : 0); |
|
295 | 295 | $data = array(); |
296 | 296 | $fields = array( |
297 | 297 | 'tax_rate_country', |
@@ -305,52 +305,52 @@ discard block |
||
305 | 305 | 'tax_rate_class', |
306 | 306 | ); |
307 | 307 | |
308 | - foreach ( $fields as $field ) { |
|
308 | + foreach ($fields as $field) { |
|
309 | 309 | // Keys via API differ from the stored names returned by _get_tax_rate. |
310 | - $key = 'tax_rate' === $field ? 'rate' : str_replace( 'tax_rate_', '', $field ); |
|
310 | + $key = 'tax_rate' === $field ? 'rate' : str_replace('tax_rate_', '', $field); |
|
311 | 311 | |
312 | 312 | // Remove data that was not posted. |
313 | - if ( ! isset( $request[ $key ] ) ) { |
|
313 | + if ( ! isset($request[$key])) { |
|
314 | 314 | continue; |
315 | 315 | } |
316 | 316 | |
317 | 317 | // Test new data against current data. |
318 | - if ( $current && $current->$field === $request[ $key ] ) { |
|
318 | + if ($current && $current->$field === $request[$key]) { |
|
319 | 319 | continue; |
320 | 320 | } |
321 | 321 | |
322 | 322 | // Add to data array. |
323 | - switch ( $key ) { |
|
323 | + switch ($key) { |
|
324 | 324 | case 'tax_rate_priority' : |
325 | 325 | case 'tax_rate_compound' : |
326 | 326 | case 'tax_rate_shipping' : |
327 | 327 | case 'tax_rate_order' : |
328 | - $data[ $field ] = absint( $request[ $key ] ); |
|
328 | + $data[$field] = absint($request[$key]); |
|
329 | 329 | break; |
330 | 330 | case 'tax_rate_class' : |
331 | - $data[ $field ] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : ''; |
|
331 | + $data[$field] = 'standard' !== $request['tax_rate_class'] ? $request['tax_rate_class'] : ''; |
|
332 | 332 | break; |
333 | 333 | default : |
334 | - $data[ $field ] = wc_clean( $request[ $key ] ); |
|
334 | + $data[$field] = wc_clean($request[$key]); |
|
335 | 335 | break; |
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | - if ( $id ) { |
|
340 | - WC_Tax::_update_tax_rate( $id, $data ); |
|
339 | + if ($id) { |
|
340 | + WC_Tax::_update_tax_rate($id, $data); |
|
341 | 341 | } else { |
342 | - $id = WC_Tax::_insert_tax_rate( $data ); |
|
342 | + $id = WC_Tax::_insert_tax_rate($data); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | // Add locales. |
346 | - if ( ! empty( $request['postcode'] ) ) { |
|
347 | - WC_Tax::_update_tax_rate_postcodes( $id, wc_clean( $request['postcode'] ) ); |
|
346 | + if ( ! empty($request['postcode'])) { |
|
347 | + WC_Tax::_update_tax_rate_postcodes($id, wc_clean($request['postcode'])); |
|
348 | 348 | } |
349 | - if ( ! empty( $request['city'] ) ) { |
|
350 | - WC_Tax::_update_tax_rate_cities( $id, wc_clean( $request['city'] ) ); |
|
349 | + if ( ! empty($request['city'])) { |
|
350 | + WC_Tax::_update_tax_rate_cities($id, wc_clean($request['city'])); |
|
351 | 351 | } |
352 | 352 | |
353 | - return WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
353 | + return WC_Tax::_get_tax_rate($id, OBJECT); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -359,14 +359,14 @@ discard block |
||
359 | 359 | * @param WP_REST_Request $request Full details about the request. |
360 | 360 | * @return WP_Error|WP_REST_Response |
361 | 361 | */ |
362 | - public function create_item( $request ) { |
|
363 | - if ( ! empty( $request['id'] ) ) { |
|
364 | - return new WP_Error( 'woocommerce_rest_tax_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
362 | + public function create_item($request) { |
|
363 | + if ( ! empty($request['id'])) { |
|
364 | + return new WP_Error('woocommerce_rest_tax_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400)); |
|
365 | 365 | } |
366 | 366 | |
367 | - $tax = $this->create_or_update_tax( $request ); |
|
367 | + $tax = $this->create_or_update_tax($request); |
|
368 | 368 | |
369 | - $this->update_additional_fields_for_object( $tax, $request ); |
|
369 | + $this->update_additional_fields_for_object($tax, $request); |
|
370 | 370 | |
371 | 371 | /** |
372 | 372 | * Fires after a tax is created or updated via the REST API. |
@@ -375,13 +375,13 @@ discard block |
||
375 | 375 | * @param WP_REST_Request $request Request object. |
376 | 376 | * @param boolean $creating True when creating tax, false when updating tax. |
377 | 377 | */ |
378 | - do_action( 'woocommerce_rest_insert_tax', $tax, $request, true ); |
|
378 | + do_action('woocommerce_rest_insert_tax', $tax, $request, true); |
|
379 | 379 | |
380 | - $request->set_param( 'context', 'edit' ); |
|
381 | - $response = $this->prepare_item_for_response( $tax, $request ); |
|
382 | - $response = rest_ensure_response( $response ); |
|
383 | - $response->set_status( 201 ); |
|
384 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ) ); |
|
380 | + $request->set_param('context', 'edit'); |
|
381 | + $response = $this->prepare_item_for_response($tax, $request); |
|
382 | + $response = rest_ensure_response($response); |
|
383 | + $response->set_status(201); |
|
384 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id))); |
|
385 | 385 | |
386 | 386 | return $response; |
387 | 387 | } |
@@ -392,16 +392,16 @@ discard block |
||
392 | 392 | * @param WP_REST_Request $request Full details about the request. |
393 | 393 | * @return WP_Error|WP_REST_Response |
394 | 394 | */ |
395 | - public function get_item( $request ) { |
|
395 | + public function get_item($request) { |
|
396 | 396 | $id = (int) $request['id']; |
397 | - $tax_obj = WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
397 | + $tax_obj = WC_Tax::_get_tax_rate($id, OBJECT); |
|
398 | 398 | |
399 | - if ( empty( $id ) || empty( $tax_obj ) ) { |
|
400 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
399 | + if (empty($id) || empty($tax_obj)) { |
|
400 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
401 | 401 | } |
402 | 402 | |
403 | - $tax = $this->prepare_item_for_response( $tax_obj, $request ); |
|
404 | - $response = rest_ensure_response( $tax ); |
|
403 | + $tax = $this->prepare_item_for_response($tax_obj, $request); |
|
404 | + $response = rest_ensure_response($tax); |
|
405 | 405 | |
406 | 406 | return $response; |
407 | 407 | } |
@@ -412,17 +412,17 @@ discard block |
||
412 | 412 | * @param WP_REST_Request $request Full details about the request. |
413 | 413 | * @return WP_Error|WP_REST_Response |
414 | 414 | */ |
415 | - public function update_item( $request ) { |
|
415 | + public function update_item($request) { |
|
416 | 416 | $id = (int) $request['id']; |
417 | - $tax_obj = WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
417 | + $tax_obj = WC_Tax::_get_tax_rate($id, OBJECT); |
|
418 | 418 | |
419 | - if ( empty( $id ) || empty( $tax_obj ) ) { |
|
420 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
419 | + if (empty($id) || empty($tax_obj)) { |
|
420 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
421 | 421 | } |
422 | 422 | |
423 | - $tax = $this->create_or_update_tax( $request, $tax_obj ); |
|
423 | + $tax = $this->create_or_update_tax($request, $tax_obj); |
|
424 | 424 | |
425 | - $this->update_additional_fields_for_object( $tax, $request ); |
|
425 | + $this->update_additional_fields_for_object($tax, $request); |
|
426 | 426 | |
427 | 427 | /** |
428 | 428 | * Fires after a tax is created or updated via the REST API. |
@@ -431,11 +431,11 @@ discard block |
||
431 | 431 | * @param WP_REST_Request $request Request object. |
432 | 432 | * @param boolean $creating True when creating tax, false when updating tax. |
433 | 433 | */ |
434 | - do_action( 'woocommerce_rest_insert_tax', $tax, $request, false ); |
|
434 | + do_action('woocommerce_rest_insert_tax', $tax, $request, false); |
|
435 | 435 | |
436 | - $request->set_param( 'context', 'edit' ); |
|
437 | - $response = $this->prepare_item_for_response( $tax, $request ); |
|
438 | - $response = rest_ensure_response( $response ); |
|
436 | + $request->set_param('context', 'edit'); |
|
437 | + $response = $this->prepare_item_for_response($tax, $request); |
|
438 | + $response = rest_ensure_response($response); |
|
439 | 439 | |
440 | 440 | return $response; |
441 | 441 | } |
@@ -446,30 +446,30 @@ discard block |
||
446 | 446 | * @param WP_REST_Request $request Full details about the request. |
447 | 447 | * @return WP_Error|WP_REST_Response |
448 | 448 | */ |
449 | - public function delete_item( $request ) { |
|
449 | + public function delete_item($request) { |
|
450 | 450 | global $wpdb; |
451 | 451 | |
452 | 452 | $id = (int) $request['id']; |
453 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
453 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
454 | 454 | |
455 | 455 | // We don't support trashing for this type, error out. |
456 | - if ( ! $force ) { |
|
457 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
456 | + if ( ! $force) { |
|
457 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
458 | 458 | } |
459 | 459 | |
460 | - $tax = WC_Tax::_get_tax_rate( $id, OBJECT ); |
|
460 | + $tax = WC_Tax::_get_tax_rate($id, OBJECT); |
|
461 | 461 | |
462 | - if ( empty( $id ) || empty( $tax ) ) { |
|
463 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
462 | + if (empty($id) || empty($tax)) { |
|
463 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 400)); |
|
464 | 464 | } |
465 | 465 | |
466 | - $request->set_param( 'context', 'edit' ); |
|
467 | - $response = $this->prepare_item_for_response( $tax, $request ); |
|
466 | + $request->set_param('context', 'edit'); |
|
467 | + $response = $this->prepare_item_for_response($tax, $request); |
|
468 | 468 | |
469 | - WC_Tax::_delete_tax_rate( $id ); |
|
469 | + WC_Tax::_delete_tax_rate($id); |
|
470 | 470 | |
471 | - if ( 0 === $wpdb->rows_affected ) { |
|
472 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
471 | + if (0 === $wpdb->rows_affected) { |
|
472 | + return new WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | * @param WP_REST_Response $response The response returned from the API. |
480 | 480 | * @param WP_REST_Request $request The request sent to the API. |
481 | 481 | */ |
482 | - do_action( 'woocommerce_rest_delete_tax', $tax, $response, $request ); |
|
482 | + do_action('woocommerce_rest_delete_tax', $tax, $response, $request); |
|
483 | 483 | |
484 | 484 | return $response; |
485 | 485 | } |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | * @param WP_REST_Request $request Request object. |
492 | 492 | * @return WP_REST_Response $response Response data. |
493 | 493 | */ |
494 | - public function prepare_item_for_response( $tax, $request ) { |
|
494 | + public function prepare_item_for_response($tax, $request) { |
|
495 | 495 | global $wpdb; |
496 | 496 | |
497 | 497 | $id = (int) $tax->tax_rate_id; |
@@ -511,26 +511,26 @@ discard block |
||
511 | 511 | ); |
512 | 512 | |
513 | 513 | // Get locales from a tax rate. |
514 | - $locales = $wpdb->get_results( $wpdb->prepare( " |
|
514 | + $locales = $wpdb->get_results($wpdb->prepare(" |
|
515 | 515 | SELECT location_code, location_type |
516 | 516 | FROM {$wpdb->prefix}woocommerce_tax_rate_locations |
517 | 517 | WHERE tax_rate_id = %d |
518 | - ", $id ) ); |
|
518 | + ", $id)); |
|
519 | 519 | |
520 | - if ( ! is_wp_error( $tax ) && ! is_null( $tax ) ) { |
|
521 | - foreach ( $locales as $locale ) { |
|
522 | - $data[ $locale->location_type ] = $locale->location_code; |
|
520 | + if ( ! is_wp_error($tax) && ! is_null($tax)) { |
|
521 | + foreach ($locales as $locale) { |
|
522 | + $data[$locale->location_type] = $locale->location_code; |
|
523 | 523 | } |
524 | 524 | } |
525 | 525 | |
526 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
527 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
528 | - $data = $this->filter_response_by_context( $data, $context ); |
|
526 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
527 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
528 | + $data = $this->filter_response_by_context($data, $context); |
|
529 | 529 | |
530 | 530 | // Wrap the data in a response object. |
531 | - $response = rest_ensure_response( $data ); |
|
531 | + $response = rest_ensure_response($data); |
|
532 | 532 | |
533 | - $response->add_links( $this->prepare_links( $tax ) ); |
|
533 | + $response->add_links($this->prepare_links($tax)); |
|
534 | 534 | |
535 | 535 | /** |
536 | 536 | * Filter tax object returned from the REST API. |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | * @param stdClass $tax Tax object used to create response. |
540 | 540 | * @param WP_REST_Request $request Request object. |
541 | 541 | */ |
542 | - return apply_filters( 'woocommerce_rest_prepare_tax', $response, $tax, $request ); |
|
542 | + return apply_filters('woocommerce_rest_prepare_tax', $response, $tax, $request); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | /** |
@@ -548,13 +548,13 @@ discard block |
||
548 | 548 | * @param stdClass $tax Tax object. |
549 | 549 | * @return array Links for the given tax. |
550 | 550 | */ |
551 | - protected function prepare_links( $tax ) { |
|
551 | + protected function prepare_links($tax) { |
|
552 | 552 | $links = array( |
553 | 553 | 'self' => array( |
554 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id ) ), |
|
554 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $tax->tax_rate_id)), |
|
555 | 555 | ), |
556 | 556 | 'collection' => array( |
557 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
557 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
558 | 558 | ), |
559 | 559 | ); |
560 | 560 | |
@@ -573,75 +573,75 @@ discard block |
||
573 | 573 | 'type' => 'object', |
574 | 574 | 'properties' => array( |
575 | 575 | 'id' => array( |
576 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
576 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
577 | 577 | 'type' => 'integer', |
578 | - 'context' => array( 'view', 'edit' ), |
|
578 | + 'context' => array('view', 'edit'), |
|
579 | 579 | 'readonly' => true, |
580 | 580 | ), |
581 | 581 | 'country' => array( |
582 | - 'description' => __( 'Country ISO 3166 code.', 'woocommerce' ), |
|
582 | + 'description' => __('Country ISO 3166 code.', 'woocommerce'), |
|
583 | 583 | 'type' => 'string', |
584 | - 'context' => array( 'view', 'edit' ), |
|
584 | + 'context' => array('view', 'edit'), |
|
585 | 585 | ), |
586 | 586 | 'state' => array( |
587 | - 'description' => __( 'State code.', 'woocommerce' ), |
|
587 | + 'description' => __('State code.', 'woocommerce'), |
|
588 | 588 | 'type' => 'string', |
589 | - 'context' => array( 'view', 'edit' ), |
|
589 | + 'context' => array('view', 'edit'), |
|
590 | 590 | ), |
591 | 591 | 'postcode' => array( |
592 | - 'description' => __( 'Postcode / ZIP.', 'woocommerce' ), |
|
592 | + 'description' => __('Postcode / ZIP.', 'woocommerce'), |
|
593 | 593 | 'type' => 'string', |
594 | - 'context' => array( 'view', 'edit' ), |
|
594 | + 'context' => array('view', 'edit'), |
|
595 | 595 | ), |
596 | 596 | 'city' => array( |
597 | - 'description' => __( 'City name.', 'woocommerce' ), |
|
597 | + 'description' => __('City name.', 'woocommerce'), |
|
598 | 598 | 'type' => 'string', |
599 | - 'context' => array( 'view', 'edit' ), |
|
599 | + 'context' => array('view', 'edit'), |
|
600 | 600 | ), |
601 | 601 | 'rate' => array( |
602 | - 'description' => __( 'Tax rate.', 'woocommerce' ), |
|
602 | + 'description' => __('Tax rate.', 'woocommerce'), |
|
603 | 603 | 'type' => 'string', |
604 | - 'context' => array( 'view', 'edit' ), |
|
604 | + 'context' => array('view', 'edit'), |
|
605 | 605 | ), |
606 | 606 | 'name' => array( |
607 | - 'description' => __( 'Tax rate name.', 'woocommerce' ), |
|
607 | + 'description' => __('Tax rate name.', 'woocommerce'), |
|
608 | 608 | 'type' => 'string', |
609 | - 'context' => array( 'view', 'edit' ), |
|
609 | + 'context' => array('view', 'edit'), |
|
610 | 610 | ), |
611 | 611 | 'priority' => array( |
612 | - 'description' => __( 'Tax priority.', 'woocommerce' ), |
|
612 | + 'description' => __('Tax priority.', 'woocommerce'), |
|
613 | 613 | 'type' => 'integer', |
614 | 614 | 'default' => 1, |
615 | - 'context' => array( 'view', 'edit' ), |
|
615 | + 'context' => array('view', 'edit'), |
|
616 | 616 | ), |
617 | 617 | 'compound' => array( |
618 | - 'description' => __( 'Whether or not this is a compound rate.', 'woocommerce' ), |
|
618 | + 'description' => __('Whether or not this is a compound rate.', 'woocommerce'), |
|
619 | 619 | 'type' => 'boolean', |
620 | 620 | 'default' => false, |
621 | - 'context' => array( 'view', 'edit' ), |
|
621 | + 'context' => array('view', 'edit'), |
|
622 | 622 | ), |
623 | 623 | 'shipping' => array( |
624 | - 'description' => __( 'Whether or not this tax rate also gets applied to shipping.', 'woocommerce' ), |
|
624 | + 'description' => __('Whether or not this tax rate also gets applied to shipping.', 'woocommerce'), |
|
625 | 625 | 'type' => 'boolean', |
626 | 626 | 'default' => true, |
627 | - 'context' => array( 'view', 'edit' ), |
|
627 | + 'context' => array('view', 'edit'), |
|
628 | 628 | ), |
629 | 629 | 'order' => array( |
630 | - 'description' => __( 'Indicates the order that will appear in queries.', 'woocommerce' ), |
|
630 | + 'description' => __('Indicates the order that will appear in queries.', 'woocommerce'), |
|
631 | 631 | 'type' => 'integer', |
632 | - 'context' => array( 'view', 'edit' ), |
|
632 | + 'context' => array('view', 'edit'), |
|
633 | 633 | ), |
634 | 634 | 'class' => array( |
635 | - 'description' => __( 'Tax class.', 'woocommerce' ), |
|
635 | + 'description' => __('Tax class.', 'woocommerce'), |
|
636 | 636 | 'type' => 'string', |
637 | 637 | 'default' => 'standard', |
638 | - 'enum' => array_merge( array( 'standard' ), WC_Tax::get_tax_class_slugs() ), |
|
639 | - 'context' => array( 'view', 'edit' ), |
|
638 | + 'enum' => array_merge(array('standard'), WC_Tax::get_tax_class_slugs()), |
|
639 | + 'context' => array('view', 'edit'), |
|
640 | 640 | ), |
641 | 641 | ), |
642 | 642 | ); |
643 | 643 | |
644 | - return $this->add_additional_fields_schema( $schema ); |
|
644 | + return $this->add_additional_fields_schema($schema); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | $params['context']['default'] = 'view'; |
656 | 656 | |
657 | 657 | $params['page'] = array( |
658 | - 'description' => __( 'Current page of the collection.', 'woocommerce' ), |
|
658 | + 'description' => __('Current page of the collection.', 'woocommerce'), |
|
659 | 659 | 'type' => 'integer', |
660 | 660 | 'default' => 1, |
661 | 661 | 'sanitize_callback' => 'absint', |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | 'minimum' => 1, |
664 | 664 | ); |
665 | 665 | $params['per_page'] = array( |
666 | - 'description' => __( 'Maximum number of items to be returned in result set.', 'woocommerce' ), |
|
666 | + 'description' => __('Maximum number of items to be returned in result set.', 'woocommerce'), |
|
667 | 667 | 'type' => 'integer', |
668 | 668 | 'default' => 10, |
669 | 669 | 'minimum' => 1, |
@@ -672,22 +672,22 @@ discard block |
||
672 | 672 | 'validate_callback' => 'rest_validate_request_arg', |
673 | 673 | ); |
674 | 674 | $params['offset'] = array( |
675 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
675 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
676 | 676 | 'type' => 'integer', |
677 | 677 | 'sanitize_callback' => 'absint', |
678 | 678 | 'validate_callback' => 'rest_validate_request_arg', |
679 | 679 | ); |
680 | 680 | $params['order'] = array( |
681 | 681 | 'default' => 'asc', |
682 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
683 | - 'enum' => array( 'asc', 'desc' ), |
|
682 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
683 | + 'enum' => array('asc', 'desc'), |
|
684 | 684 | 'sanitize_callback' => 'sanitize_key', |
685 | 685 | 'type' => 'string', |
686 | 686 | 'validate_callback' => 'rest_validate_request_arg', |
687 | 687 | ); |
688 | 688 | $params['orderby'] = array( |
689 | 689 | 'default' => 'order', |
690 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
690 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
691 | 691 | 'enum' => array( |
692 | 692 | 'id', |
693 | 693 | 'order', |
@@ -697,8 +697,8 @@ discard block |
||
697 | 697 | 'validate_callback' => 'rest_validate_request_arg', |
698 | 698 | ); |
699 | 699 | $params['class'] = array( |
700 | - 'description' => __( 'Sort by tax class.', 'woocommerce' ), |
|
701 | - 'enum' => array_merge( array( 'standard' ), WC_Tax::get_tax_class_slugs() ), |
|
700 | + 'description' => __('Sort by tax class.', 'woocommerce'), |
|
701 | + 'enum' => array_merge(array('standard'), WC_Tax::get_tax_class_slugs()), |
|
702 | 702 | 'sanitize_callback' => 'sanitize_title', |
703 | 703 | 'type' => 'string', |
704 | 704 | 'validate_callback' => 'rest_validate_request_arg', |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -42,16 +42,16 @@ discard block |
||
42 | 42 | * @param WP_REST_Request $request |
43 | 43 | * @return array|WP_Error |
44 | 44 | */ |
45 | - public function get_items( $request ) { |
|
45 | + public function get_items($request) { |
|
46 | 46 | // Set date filtering. |
47 | 47 | $filter = array( |
48 | 48 | 'period' => $request['period'], |
49 | 49 | 'date_min' => $request['date_min'], |
50 | 50 | 'date_max' => $request['date_max'], |
51 | 51 | ); |
52 | - $this->setup_report( $filter ); |
|
52 | + $this->setup_report($filter); |
|
53 | 53 | |
54 | - $report_data = $this->report->get_order_report_data( array( |
|
54 | + $report_data = $this->report->get_order_report_data(array( |
|
55 | 55 | 'data' => array( |
56 | 56 | '_product_id' => array( |
57 | 57 | 'type' => 'order_item_meta', |
@@ -68,32 +68,32 @@ discard block |
||
68 | 68 | ), |
69 | 69 | 'order_by' => 'order_item_qty DESC', |
70 | 70 | 'group_by' => 'product_id', |
71 | - 'limit' => isset( $filter['limit'] ) ? absint( $filter['limit'] ) : 12, |
|
71 | + 'limit' => isset($filter['limit']) ? absint($filter['limit']) : 12, |
|
72 | 72 | 'query_type' => 'get_results', |
73 | 73 | 'filter_range' => true, |
74 | - ) ); |
|
74 | + )); |
|
75 | 75 | |
76 | 76 | $top_sellers = array(); |
77 | 77 | |
78 | - foreach ( $report_data as $item ) { |
|
79 | - $product = wc_get_product( $item->product_id ); |
|
78 | + foreach ($report_data as $item) { |
|
79 | + $product = wc_get_product($item->product_id); |
|
80 | 80 | |
81 | - if ( $product ) { |
|
81 | + if ($product) { |
|
82 | 82 | $top_sellers[] = array( |
83 | 83 | 'name' => $product->get_name(), |
84 | 84 | 'product_id' => (int) $item->product_id, |
85 | - 'quantity' => wc_stock_amount( $item->order_item_qty ), |
|
85 | + 'quantity' => wc_stock_amount($item->order_item_qty), |
|
86 | 86 | ); |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | 90 | $data = array(); |
91 | - foreach ( $top_sellers as $top_seller ) { |
|
92 | - $item = $this->prepare_item_for_response( (object) $top_seller, $request ); |
|
93 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
91 | + foreach ($top_sellers as $top_seller) { |
|
92 | + $item = $this->prepare_item_for_response((object) $top_seller, $request); |
|
93 | + $data[] = $this->prepare_response_for_collection($item); |
|
94 | 94 | } |
95 | 95 | |
96 | - return rest_ensure_response( $data ); |
|
96 | + return rest_ensure_response($data); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,27 +103,27 @@ discard block |
||
103 | 103 | * @param WP_REST_Request $request Request object. |
104 | 104 | * @return WP_REST_Response $response Response data. |
105 | 105 | */ |
106 | - public function prepare_item_for_response( $top_seller, $request ) { |
|
106 | + public function prepare_item_for_response($top_seller, $request) { |
|
107 | 107 | $data = array( |
108 | 108 | 'name' => $top_seller->name, |
109 | 109 | 'product_id' => $top_seller->product_id, |
110 | 110 | 'quantity' => $top_seller->quantity, |
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 ); |
|
119 | - $response->add_links( array( |
|
118 | + $response = rest_ensure_response($data); |
|
119 | + $response->add_links(array( |
|
120 | 120 | 'about' => array( |
121 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
121 | + 'href' => rest_url(sprintf('%s/reports', $this->namespace)), |
|
122 | 122 | ), |
123 | 123 | 'product' => array( |
124 | - 'href' => rest_url( sprintf( '/%s/products/%s', $this->namespace, $top_seller->product_id ) ), |
|
124 | + 'href' => rest_url(sprintf('/%s/products/%s', $this->namespace, $top_seller->product_id)), |
|
125 | 125 | ), |
126 | - ) ); |
|
126 | + )); |
|
127 | 127 | |
128 | 128 | /** |
129 | 129 | * Filter a report top sellers returned from the API. |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @param stdClass $top_seller The original report object. |
135 | 135 | * @param WP_REST_Request $request Request used to generate the response. |
136 | 136 | */ |
137 | - return apply_filters( 'woocommerce_rest_prepare_report_top_sellers', $response, $top_seller, $request ); |
|
137 | + return apply_filters('woocommerce_rest_prepare_report_top_sellers', $response, $top_seller, $request); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -149,26 +149,26 @@ discard block |
||
149 | 149 | 'type' => 'object', |
150 | 150 | 'properties' => array( |
151 | 151 | 'name' => array( |
152 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
152 | + 'description' => __('Product name.', 'woocommerce'), |
|
153 | 153 | 'type' => 'string', |
154 | - 'context' => array( 'view' ), |
|
154 | + 'context' => array('view'), |
|
155 | 155 | 'readonly' => true, |
156 | 156 | ), |
157 | 157 | 'product_id' => array( |
158 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
158 | + 'description' => __('Product ID.', 'woocommerce'), |
|
159 | 159 | 'type' => 'integer', |
160 | - 'context' => array( 'view' ), |
|
160 | + 'context' => array('view'), |
|
161 | 161 | 'readonly' => true, |
162 | 162 | ), |
163 | 163 | 'quantity' => array( |
164 | - 'description' => __( 'Total number of purchases.', 'woocommerce' ), |
|
164 | + 'description' => __('Total number of purchases.', 'woocommerce'), |
|
165 | 165 | 'type' => 'integer', |
166 | - 'context' => array( 'view' ), |
|
166 | + 'context' => array('view'), |
|
167 | 167 | 'readonly' => true, |
168 | 168 | ), |
169 | 169 | ), |
170 | 170 | ); |
171 | 171 | |
172 | - return $this->add_additional_fields_schema( $schema ); |
|
172 | + return $this->add_additional_fields_schema($schema); |
|
173 | 173 | } |
174 | 174 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | * @param WP_REST_Request $request Request instance. |
51 | 51 | * @return WP_REST_Response |
52 | 52 | */ |
53 | - public function prepare_item_for_response( $item, $request ) { |
|
53 | + public function prepare_item_for_response($item, $request) { |
|
54 | 54 | // Get category display type. |
55 | - $display_type = get_term_meta( $item->term_id, 'display_type', true ); |
|
55 | + $display_type = get_term_meta($item->term_id, 'display_type', true); |
|
56 | 56 | |
57 | 57 | // Get category order. |
58 | - $menu_order = get_term_meta( $item->term_id, 'order', true ); |
|
58 | + $menu_order = get_term_meta($item->term_id, 'order', true); |
|
59 | 59 | |
60 | 60 | $data = array( |
61 | 61 | 'id' => (int) $item->term_id, |
@@ -70,27 +70,27 @@ discard block |
||
70 | 70 | ); |
71 | 71 | |
72 | 72 | // Get category image. |
73 | - $image_id = get_term_meta( $item->term_id, 'thumbnail_id', true ); |
|
74 | - if ( $image_id ) { |
|
75 | - $attachment = get_post( $image_id ); |
|
73 | + $image_id = get_term_meta($item->term_id, 'thumbnail_id', true); |
|
74 | + if ($image_id) { |
|
75 | + $attachment = get_post($image_id); |
|
76 | 76 | |
77 | 77 | $data['image'] = array( |
78 | 78 | 'id' => (int) $image_id, |
79 | - 'date_created' => wc_rest_prepare_date_response( $attachment->post_date_gmt ), |
|
80 | - 'date_modified' => wc_rest_prepare_date_response( $attachment->post_modified_gmt ), |
|
81 | - 'src' => wp_get_attachment_url( $image_id ), |
|
82 | - 'title' => get_the_title( $attachment ), |
|
83 | - 'alt' => get_post_meta( $image_id, '_wp_attachment_image_alt', true ), |
|
79 | + 'date_created' => wc_rest_prepare_date_response($attachment->post_date_gmt), |
|
80 | + 'date_modified' => wc_rest_prepare_date_response($attachment->post_modified_gmt), |
|
81 | + 'src' => wp_get_attachment_url($image_id), |
|
82 | + 'title' => get_the_title($attachment), |
|
83 | + 'alt' => get_post_meta($image_id, '_wp_attachment_image_alt', true), |
|
84 | 84 | ); |
85 | 85 | } |
86 | 86 | |
87 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
88 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
89 | - $data = $this->filter_response_by_context( $data, $context ); |
|
87 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
88 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
89 | + $data = $this->filter_response_by_context($data, $context); |
|
90 | 90 | |
91 | - $response = rest_ensure_response( $data ); |
|
91 | + $response = rest_ensure_response($data); |
|
92 | 92 | |
93 | - $response->add_links( $this->prepare_links( $item, $request ) ); |
|
93 | + $response->add_links($this->prepare_links($item, $request)); |
|
94 | 94 | |
95 | 95 | /** |
96 | 96 | * Filter a term item returned from the API. |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * @param object $item The original term object. |
102 | 102 | * @param WP_REST_Request $request Request used to generate the response. |
103 | 103 | */ |
104 | - return apply_filters( "woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request ); |
|
104 | + return apply_filters("woocommerce_rest_prepare_{$this->taxonomy}", $response, $item, $request); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -111,48 +111,48 @@ discard block |
||
111 | 111 | * @param WP_REST_Request $request Request instance. |
112 | 112 | * @return bool|WP_Error |
113 | 113 | */ |
114 | - protected function update_term_meta_fields( $term, $request ) { |
|
114 | + protected function update_term_meta_fields($term, $request) { |
|
115 | 115 | $id = (int) $term->term_id; |
116 | 116 | |
117 | - if ( isset( $request['display'] ) ) { |
|
118 | - update_term_meta( $id, 'display_type', 'default' === $request['display'] ? '' : $request['display'] ); |
|
117 | + if (isset($request['display'])) { |
|
118 | + update_term_meta($id, 'display_type', 'default' === $request['display'] ? '' : $request['display']); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( isset( $request['menu_order'] ) ) { |
|
122 | - update_term_meta( $id, 'order', $request['menu_order'] ); |
|
121 | + if (isset($request['menu_order'])) { |
|
122 | + update_term_meta($id, 'order', $request['menu_order']); |
|
123 | 123 | } |
124 | 124 | |
125 | - if ( isset( $request['image'] ) ) { |
|
126 | - if ( empty( $request['image']['id'] ) && ! empty( $request['image']['src'] ) ) { |
|
127 | - $upload = wc_rest_upload_image_from_url( esc_url_raw( $request['image']['src'] ) ); |
|
125 | + if (isset($request['image'])) { |
|
126 | + if (empty($request['image']['id']) && ! empty($request['image']['src'])) { |
|
127 | + $upload = wc_rest_upload_image_from_url(esc_url_raw($request['image']['src'])); |
|
128 | 128 | |
129 | - if ( is_wp_error( $upload ) ) { |
|
129 | + if (is_wp_error($upload)) { |
|
130 | 130 | return $upload; |
131 | 131 | } |
132 | 132 | |
133 | - $image_id = wc_rest_set_uploaded_image_as_attachment( $upload ); |
|
133 | + $image_id = wc_rest_set_uploaded_image_as_attachment($upload); |
|
134 | 134 | } else { |
135 | - $image_id = isset( $request['image']['id'] ) ? absint( $request['image']['id'] ) : 0; |
|
135 | + $image_id = isset($request['image']['id']) ? absint($request['image']['id']) : 0; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | // Check if image_id is a valid image attachment before updating the term meta. |
139 | - if ( $image_id && wp_attachment_is_image( $image_id ) ) { |
|
140 | - update_term_meta( $id, 'thumbnail_id', $image_id ); |
|
139 | + if ($image_id && wp_attachment_is_image($image_id)) { |
|
140 | + update_term_meta($id, 'thumbnail_id', $image_id); |
|
141 | 141 | |
142 | 142 | // Set the image alt. |
143 | - if ( ! empty( $request['image']['alt'] ) ) { |
|
144 | - update_post_meta( $image_id, '_wp_attachment_image_alt', wc_clean( $request['image']['alt'] ) ); |
|
143 | + if ( ! empty($request['image']['alt'])) { |
|
144 | + update_post_meta($image_id, '_wp_attachment_image_alt', wc_clean($request['image']['alt'])); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | // Set the image title. |
148 | - if ( ! empty( $request['image']['title'] ) ) { |
|
149 | - wp_update_post( array( |
|
148 | + if ( ! empty($request['image']['title'])) { |
|
149 | + wp_update_post(array( |
|
150 | 150 | 'ID' => $image_id, |
151 | - 'post_title' => wc_clean( $request['image']['title'] ), |
|
152 | - ) ); |
|
151 | + 'post_title' => wc_clean($request['image']['title']), |
|
152 | + )); |
|
153 | 153 | } |
154 | 154 | } else { |
155 | - delete_term_meta( $id, 'thumbnail_id' ); |
|
155 | + delete_term_meta($id, 'thumbnail_id'); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
@@ -171,101 +171,101 @@ discard block |
||
171 | 171 | 'type' => 'object', |
172 | 172 | 'properties' => array( |
173 | 173 | 'id' => array( |
174 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
174 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
175 | 175 | 'type' => 'integer', |
176 | - 'context' => array( 'view', 'edit' ), |
|
176 | + 'context' => array('view', 'edit'), |
|
177 | 177 | 'readonly' => true, |
178 | 178 | ), |
179 | 179 | 'name' => array( |
180 | - 'description' => __( 'Category name.', 'woocommerce' ), |
|
180 | + 'description' => __('Category name.', 'woocommerce'), |
|
181 | 181 | 'type' => 'string', |
182 | - 'context' => array( 'view', 'edit' ), |
|
182 | + 'context' => array('view', 'edit'), |
|
183 | 183 | 'arg_options' => array( |
184 | 184 | 'sanitize_callback' => 'sanitize_text_field', |
185 | 185 | ), |
186 | 186 | ), |
187 | 187 | 'slug' => array( |
188 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
188 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
189 | 189 | 'type' => 'string', |
190 | - 'context' => array( 'view', 'edit' ), |
|
190 | + 'context' => array('view', 'edit'), |
|
191 | 191 | 'arg_options' => array( |
192 | 192 | 'sanitize_callback' => 'sanitize_title', |
193 | 193 | ), |
194 | 194 | ), |
195 | 195 | 'parent' => array( |
196 | - 'description' => __( 'The ID for the parent of the resource.', 'woocommerce' ), |
|
196 | + 'description' => __('The ID for the parent of the resource.', 'woocommerce'), |
|
197 | 197 | 'type' => 'integer', |
198 | - 'context' => array( 'view', 'edit' ), |
|
198 | + 'context' => array('view', 'edit'), |
|
199 | 199 | ), |
200 | 200 | 'description' => array( |
201 | - 'description' => __( 'HTML description of the resource.', 'woocommerce' ), |
|
201 | + 'description' => __('HTML description of the resource.', 'woocommerce'), |
|
202 | 202 | 'type' => 'string', |
203 | - 'context' => array( 'view', 'edit' ), |
|
203 | + 'context' => array('view', 'edit'), |
|
204 | 204 | 'arg_options' => array( |
205 | 205 | 'sanitize_callback' => 'wp_filter_post_kses', |
206 | 206 | ), |
207 | 207 | ), |
208 | 208 | 'display' => array( |
209 | - 'description' => __( 'Category archive display type.', 'woocommerce' ), |
|
209 | + 'description' => __('Category archive display type.', 'woocommerce'), |
|
210 | 210 | 'type' => 'string', |
211 | 211 | 'default' => 'default', |
212 | - 'enum' => array( 'default', 'products', 'subcategories', 'both' ), |
|
213 | - 'context' => array( 'view', 'edit' ), |
|
212 | + 'enum' => array('default', 'products', 'subcategories', 'both'), |
|
213 | + 'context' => array('view', 'edit'), |
|
214 | 214 | ), |
215 | 215 | 'image' => array( |
216 | - 'description' => __( 'Image data.', 'woocommerce' ), |
|
216 | + 'description' => __('Image data.', 'woocommerce'), |
|
217 | 217 | 'type' => 'object', |
218 | - 'context' => array( 'view', 'edit' ), |
|
218 | + 'context' => array('view', 'edit'), |
|
219 | 219 | 'properties' => array( |
220 | 220 | 'id' => array( |
221 | - 'description' => __( 'Image ID.', 'woocommerce' ), |
|
221 | + 'description' => __('Image ID.', 'woocommerce'), |
|
222 | 222 | 'type' => 'integer', |
223 | - 'context' => array( 'view', 'edit' ), |
|
223 | + 'context' => array('view', 'edit'), |
|
224 | 224 | ), |
225 | 225 | 'date_created' => array( |
226 | - 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
|
226 | + 'description' => __("The date the image was created, in the site's timezone.", 'woocommerce'), |
|
227 | 227 | 'type' => 'date-time', |
228 | - 'context' => array( 'view', 'edit' ), |
|
228 | + 'context' => array('view', 'edit'), |
|
229 | 229 | 'readonly' => true, |
230 | 230 | ), |
231 | 231 | 'date_modified' => array( |
232 | - 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
|
232 | + 'description' => __("The date the image was last modified, in the site's timezone.", 'woocommerce'), |
|
233 | 233 | 'type' => 'date-time', |
234 | - 'context' => array( 'view', 'edit' ), |
|
234 | + 'context' => array('view', 'edit'), |
|
235 | 235 | 'readonly' => true, |
236 | 236 | ), |
237 | 237 | 'src' => array( |
238 | - 'description' => __( 'Image URL.', 'woocommerce' ), |
|
238 | + 'description' => __('Image URL.', 'woocommerce'), |
|
239 | 239 | 'type' => 'string', |
240 | 240 | 'format' => 'uri', |
241 | - 'context' => array( 'view', 'edit' ), |
|
241 | + 'context' => array('view', 'edit'), |
|
242 | 242 | ), |
243 | 243 | 'title' => array( |
244 | - 'description' => __( 'Image name.', 'woocommerce' ), |
|
244 | + 'description' => __('Image name.', 'woocommerce'), |
|
245 | 245 | 'type' => 'string', |
246 | - 'context' => array( 'view', 'edit' ), |
|
246 | + 'context' => array('view', 'edit'), |
|
247 | 247 | ), |
248 | 248 | 'alt' => array( |
249 | - 'description' => __( 'Image alternative text.', 'woocommerce' ), |
|
249 | + 'description' => __('Image alternative text.', 'woocommerce'), |
|
250 | 250 | 'type' => 'string', |
251 | - 'context' => array( 'view', 'edit' ), |
|
251 | + 'context' => array('view', 'edit'), |
|
252 | 252 | ), |
253 | 253 | ), |
254 | 254 | ), |
255 | 255 | 'menu_order' => array( |
256 | - 'description' => __( 'Menu order, used to custom sort the resource.', 'woocommerce' ), |
|
256 | + 'description' => __('Menu order, used to custom sort the resource.', 'woocommerce'), |
|
257 | 257 | 'type' => 'integer', |
258 | - 'context' => array( 'view', 'edit' ), |
|
258 | + 'context' => array('view', 'edit'), |
|
259 | 259 | ), |
260 | 260 | 'count' => array( |
261 | - 'description' => __( 'Number of published products for the resource.', 'woocommerce' ), |
|
261 | + 'description' => __('Number of published products for the resource.', 'woocommerce'), |
|
262 | 262 | 'type' => 'integer', |
263 | - 'context' => array( 'view', 'edit' ), |
|
263 | + 'context' => array('view', 'edit'), |
|
264 | 264 | 'readonly' => true, |
265 | 265 | ), |
266 | 266 | ), |
267 | 267 | ); |
268 | 268 | |
269 | - return $this->add_additional_fields_schema( $schema ); |
|
269 | + return $this->add_additional_fields_schema($schema); |
|
270 | 270 | } |
271 | 271 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 3.0.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -40,43 +40,43 @@ discard block |
||
40 | 40 | * Register the routes for tax classes. |
41 | 41 | */ |
42 | 42 | public function register_routes() { |
43 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
43 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
44 | 44 | array( |
45 | 45 | 'methods' => WP_REST_Server::READABLE, |
46 | - 'callback' => array( $this, 'get_items' ), |
|
47 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
46 | + 'callback' => array($this, 'get_items'), |
|
47 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
48 | 48 | 'args' => $this->get_collection_params(), |
49 | 49 | ), |
50 | 50 | array( |
51 | 51 | 'methods' => WP_REST_Server::CREATABLE, |
52 | - 'callback' => array( $this, 'create_item' ), |
|
53 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
54 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
52 | + 'callback' => array($this, 'create_item'), |
|
53 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
54 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
55 | 55 | ), |
56 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
57 | - ) ); |
|
56 | + 'schema' => array($this, 'get_public_item_schema'), |
|
57 | + )); |
|
58 | 58 | |
59 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<slug>\w[\w\s\-]*)', array( |
|
59 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<slug>\w[\w\s\-]*)', array( |
|
60 | 60 | 'args' => array( |
61 | 61 | 'slug' => array( |
62 | - 'description' => __( 'Unique slug for the resource.', 'woocommerce' ), |
|
62 | + 'description' => __('Unique slug for the resource.', 'woocommerce'), |
|
63 | 63 | 'type' => 'string', |
64 | 64 | ), |
65 | 65 | ), |
66 | 66 | array( |
67 | 67 | 'methods' => WP_REST_Server::DELETABLE, |
68 | - 'callback' => array( $this, 'delete_item' ), |
|
69 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
68 | + 'callback' => array($this, 'delete_item'), |
|
69 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
70 | 70 | 'args' => array( |
71 | 71 | 'force' => array( |
72 | 72 | 'default' => false, |
73 | 73 | 'type' => 'boolean', |
74 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
74 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
75 | 75 | ), |
76 | 76 | ), |
77 | 77 | ), |
78 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
79 | - ) ); |
|
78 | + 'schema' => array($this, 'get_public_item_schema'), |
|
79 | + )); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | * @param WP_REST_Request $request Full details about the request. |
86 | 86 | * @return WP_Error|boolean |
87 | 87 | */ |
88 | - public function get_items_permissions_check( $request ) { |
|
89 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) { |
|
90 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
88 | + public function get_items_permissions_check($request) { |
|
89 | + if ( ! wc_rest_check_manager_permissions('settings', 'read')) { |
|
90 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return true; |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return bool|WP_Error |
102 | 102 | */ |
103 | - public function create_item_permissions_check( $request ) { |
|
104 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'create' ) ) { |
|
105 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
103 | + public function create_item_permissions_check($request) { |
|
104 | + if ( ! wc_rest_check_manager_permissions('settings', 'create')) { |
|
105 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return true; |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return bool|WP_Error |
117 | 117 | */ |
118 | - public function delete_item_permissions_check( $request ) { |
|
119 | - if ( ! wc_rest_check_manager_permissions( 'settings', 'delete' ) ) { |
|
120 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
118 | + public function delete_item_permissions_check($request) { |
|
119 | + if ( ! wc_rest_check_manager_permissions('settings', 'delete')) { |
|
120 | + return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | return true; |
@@ -129,32 +129,32 @@ discard block |
||
129 | 129 | * @param WP_REST_Request $request |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function get_items( $request ) { |
|
132 | + public function get_items($request) { |
|
133 | 133 | $tax_classes = array(); |
134 | 134 | |
135 | 135 | // Add standard class. |
136 | 136 | $tax_classes[] = array( |
137 | 137 | 'slug' => 'standard', |
138 | - 'name' => __( 'Standard rate', 'woocommerce' ), |
|
138 | + 'name' => __('Standard rate', 'woocommerce'), |
|
139 | 139 | ); |
140 | 140 | |
141 | 141 | $classes = WC_Tax::get_tax_classes(); |
142 | 142 | |
143 | - foreach ( $classes as $class ) { |
|
143 | + foreach ($classes as $class) { |
|
144 | 144 | $tax_classes[] = array( |
145 | - 'slug' => sanitize_title( $class ), |
|
145 | + 'slug' => sanitize_title($class), |
|
146 | 146 | 'name' => $class, |
147 | 147 | ); |
148 | 148 | } |
149 | 149 | |
150 | 150 | $data = array(); |
151 | - foreach ( $tax_classes as $tax_class ) { |
|
152 | - $class = $this->prepare_item_for_response( $tax_class, $request ); |
|
153 | - $class = $this->prepare_response_for_collection( $class ); |
|
151 | + foreach ($tax_classes as $tax_class) { |
|
152 | + $class = $this->prepare_item_for_response($tax_class, $request); |
|
153 | + $class = $this->prepare_response_for_collection($class); |
|
154 | 154 | $data[] = $class; |
155 | 155 | } |
156 | 156 | |
157 | - return rest_ensure_response( $data ); |
|
157 | + return rest_ensure_response($data); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -163,33 +163,33 @@ discard block |
||
163 | 163 | * @param WP_REST_Request $request Full details about the request. |
164 | 164 | * @return WP_Error|WP_REST_Response |
165 | 165 | */ |
166 | - public function create_item( $request ) { |
|
166 | + public function create_item($request) { |
|
167 | 167 | $exists = false; |
168 | 168 | $classes = WC_Tax::get_tax_classes(); |
169 | 169 | $tax_class = array( |
170 | - 'slug' => sanitize_title( $request['name'] ), |
|
170 | + 'slug' => sanitize_title($request['name']), |
|
171 | 171 | 'name' => $request['name'], |
172 | 172 | ); |
173 | 173 | |
174 | 174 | // Check if class exists. |
175 | - foreach ( $classes as $key => $class ) { |
|
176 | - if ( sanitize_title( $class ) === $tax_class['slug'] ) { |
|
175 | + foreach ($classes as $key => $class) { |
|
176 | + if (sanitize_title($class) === $tax_class['slug']) { |
|
177 | 177 | $exists = true; |
178 | 178 | break; |
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Return error if tax class already exists. |
183 | - if ( $exists ) { |
|
184 | - return new WP_Error( 'woocommerce_rest_tax_class_exists', __( 'Cannot create existing resource.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
183 | + if ($exists) { |
|
184 | + return new WP_Error('woocommerce_rest_tax_class_exists', __('Cannot create existing resource.', 'woocommerce'), array('status' => 400)); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | // Add the new class. |
188 | 188 | $classes[] = $tax_class['name']; |
189 | 189 | |
190 | - update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) ); |
|
190 | + update_option('woocommerce_tax_classes', implode("\n", $classes)); |
|
191 | 191 | |
192 | - $this->update_additional_fields_for_object( $tax_class, $request ); |
|
192 | + $this->update_additional_fields_for_object($tax_class, $request); |
|
193 | 193 | |
194 | 194 | /** |
195 | 195 | * Fires after a tax class is created or updated via the REST API. |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | * @param WP_REST_Request $request Request object. |
199 | 199 | * @param boolean $creating True when creating tax class, false when updating tax class. |
200 | 200 | */ |
201 | - do_action( 'woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true ); |
|
201 | + do_action('woocommerce_rest_insert_tax_class', (object) $tax_class, $request, true); |
|
202 | 202 | |
203 | - $request->set_param( 'context', 'edit' ); |
|
204 | - $response = $this->prepare_item_for_response( $tax_class, $request ); |
|
205 | - $response = rest_ensure_response( $response ); |
|
206 | - $response->set_status( 201 ); |
|
207 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug'] ) ) ); |
|
203 | + $request->set_param('context', 'edit'); |
|
204 | + $response = $this->prepare_item_for_response($tax_class, $request); |
|
205 | + $response = rest_ensure_response($response); |
|
206 | + $response->set_status(201); |
|
207 | + $response->header('Location', rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $tax_class['slug']))); |
|
208 | 208 | |
209 | 209 | return $response; |
210 | 210 | } |
@@ -215,53 +215,53 @@ discard block |
||
215 | 215 | * @param WP_REST_Request $request Full details about the request. |
216 | 216 | * @return WP_Error|WP_REST_Response |
217 | 217 | */ |
218 | - public function delete_item( $request ) { |
|
218 | + public function delete_item($request) { |
|
219 | 219 | global $wpdb; |
220 | 220 | |
221 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
221 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
222 | 222 | |
223 | 223 | // We don't support trashing for this type, error out. |
224 | - if ( ! $force ) { |
|
225 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Taxes do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
224 | + if ( ! $force) { |
|
225 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Taxes do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | $tax_class = array( |
229 | - 'slug' => sanitize_title( $request['slug'] ), |
|
229 | + 'slug' => sanitize_title($request['slug']), |
|
230 | 230 | 'name' => '', |
231 | 231 | ); |
232 | 232 | $classes = WC_Tax::get_tax_classes(); |
233 | 233 | $deleted = false; |
234 | 234 | |
235 | - foreach ( $classes as $key => $class ) { |
|
236 | - if ( sanitize_title( $class ) === $tax_class['slug'] ) { |
|
235 | + foreach ($classes as $key => $class) { |
|
236 | + if (sanitize_title($class) === $tax_class['slug']) { |
|
237 | 237 | $tax_class['name'] = $class; |
238 | - unset( $classes[ $key ] ); |
|
238 | + unset($classes[$key]); |
|
239 | 239 | $deleted = true; |
240 | 240 | break; |
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
244 | - if ( ! $deleted ) { |
|
245 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource id.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
244 | + if ( ! $deleted) { |
|
245 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource id.', 'woocommerce'), array('status' => 400)); |
|
246 | 246 | } |
247 | 247 | |
248 | - update_option( 'woocommerce_tax_classes', implode( "\n", $classes ) ); |
|
248 | + update_option('woocommerce_tax_classes', implode("\n", $classes)); |
|
249 | 249 | |
250 | 250 | // Delete tax rate locations locations from the selected class. |
251 | - $wpdb->query( $wpdb->prepare( " |
|
251 | + $wpdb->query($wpdb->prepare(" |
|
252 | 252 | DELETE locations.* |
253 | 253 | FROM {$wpdb->prefix}woocommerce_tax_rate_locations AS locations |
254 | 254 | INNER JOIN |
255 | 255 | {$wpdb->prefix}woocommerce_tax_rates AS rates |
256 | 256 | ON rates.tax_rate_id = locations.tax_rate_id |
257 | 257 | WHERE rates.tax_rate_class = '%s' |
258 | - ", $tax_class['slug'] ) ); |
|
258 | + ", $tax_class['slug'])); |
|
259 | 259 | |
260 | 260 | // Delete tax rates in the selected class. |
261 | - $wpdb->delete( $wpdb->prefix . 'woocommerce_tax_rates', array( 'tax_rate_class' => $tax_class['slug'] ), array( '%s' ) ); |
|
261 | + $wpdb->delete($wpdb->prefix . 'woocommerce_tax_rates', array('tax_rate_class' => $tax_class['slug']), array('%s')); |
|
262 | 262 | |
263 | - $request->set_param( 'context', 'edit' ); |
|
264 | - $response = $this->prepare_item_for_response( $tax_class, $request ); |
|
263 | + $request->set_param('context', 'edit'); |
|
264 | + $response = $this->prepare_item_for_response($tax_class, $request); |
|
265 | 265 | |
266 | 266 | /** |
267 | 267 | * Fires after a tax class is deleted via the REST API. |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @param WP_REST_Response $response The response returned from the API. |
271 | 271 | * @param WP_REST_Request $request The request sent to the API. |
272 | 272 | */ |
273 | - do_action( 'woocommerce_rest_delete_tax', (object) $tax_class, $response, $request ); |
|
273 | + do_action('woocommerce_rest_delete_tax', (object) $tax_class, $response, $request); |
|
274 | 274 | |
275 | 275 | return $response; |
276 | 276 | } |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | * @param WP_REST_Request $request Request object. |
283 | 283 | * @return WP_REST_Response $response Response data. |
284 | 284 | */ |
285 | - public function prepare_item_for_response( $tax_class, $request ) { |
|
285 | + public function prepare_item_for_response($tax_class, $request) { |
|
286 | 286 | $data = $tax_class; |
287 | 287 | |
288 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
289 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
290 | - $data = $this->filter_response_by_context( $data, $context ); |
|
288 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
289 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
290 | + $data = $this->filter_response_by_context($data, $context); |
|
291 | 291 | |
292 | 292 | // Wrap the data in a response object. |
293 | - $response = rest_ensure_response( $data ); |
|
293 | + $response = rest_ensure_response($data); |
|
294 | 294 | |
295 | - $response->add_links( $this->prepare_links() ); |
|
295 | + $response->add_links($this->prepare_links()); |
|
296 | 296 | |
297 | 297 | /** |
298 | 298 | * Filter tax object returned from the REST API. |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * @param stdClass $tax_class Tax object used to create response. |
302 | 302 | * @param WP_REST_Request $request Request object. |
303 | 303 | */ |
304 | - return apply_filters( 'woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request ); |
|
304 | + return apply_filters('woocommerce_rest_prepare_tax', $response, (object) $tax_class, $request); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | protected function prepare_links() { |
313 | 313 | $links = array( |
314 | 314 | 'collection' => array( |
315 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
315 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
316 | 316 | ), |
317 | 317 | ); |
318 | 318 | |
@@ -331,15 +331,15 @@ discard block |
||
331 | 331 | 'type' => 'object', |
332 | 332 | 'properties' => array( |
333 | 333 | 'slug' => array( |
334 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
334 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
335 | 335 | 'type' => 'string', |
336 | - 'context' => array( 'view', 'edit' ), |
|
336 | + 'context' => array('view', 'edit'), |
|
337 | 337 | 'readonly' => true, |
338 | 338 | ), |
339 | 339 | 'name' => array( |
340 | - 'description' => __( 'Tax class name.', 'woocommerce' ), |
|
340 | + 'description' => __('Tax class name.', 'woocommerce'), |
|
341 | 341 | 'type' => 'string', |
342 | - 'context' => array( 'view', 'edit' ), |
|
342 | + 'context' => array('view', 'edit'), |
|
343 | 343 | 'required' => true, |
344 | 344 | 'arg_options' => array( |
345 | 345 | 'sanitize_callback' => 'sanitize_text_field', |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | ), |
349 | 349 | ); |
350 | 350 | |
351 | - return $this->add_additional_fields_schema( $schema ); |
|
351 | + return $this->add_additional_fields_schema($schema); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | */ |
359 | 359 | public function get_collection_params() { |
360 | 360 | return array( |
361 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
361 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
362 | 362 | ); |
363 | 363 | } |
364 | 364 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if ( ! defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -45,78 +45,78 @@ discard block |
||
45 | 45 | * Register the routes for webhooks. |
46 | 46 | */ |
47 | 47 | public function register_routes() { |
48 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
48 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
49 | 49 | array( |
50 | 50 | 'methods' => WP_REST_Server::READABLE, |
51 | - 'callback' => array( $this, 'get_items' ), |
|
52 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
51 | + 'callback' => array($this, 'get_items'), |
|
52 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
53 | 53 | 'args' => $this->get_collection_params(), |
54 | 54 | ), |
55 | 55 | array( |
56 | 56 | 'methods' => WP_REST_Server::CREATABLE, |
57 | - 'callback' => array( $this, 'create_item' ), |
|
58 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
59 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
57 | + 'callback' => array($this, 'create_item'), |
|
58 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
59 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
60 | 60 | 'topic' => array( |
61 | 61 | 'required' => true, |
62 | 62 | 'type' => 'string', |
63 | - 'description' => __( 'Webhook topic.', 'woocommerce' ), |
|
63 | + 'description' => __('Webhook topic.', 'woocommerce'), |
|
64 | 64 | ), |
65 | 65 | 'delivery_url' => array( |
66 | 66 | 'required' => true, |
67 | 67 | 'type' => 'string', |
68 | - 'description' => __( 'Webhook delivery URL.', 'woocommerce' ), |
|
68 | + 'description' => __('Webhook delivery URL.', 'woocommerce'), |
|
69 | 69 | ), |
70 | - ) ), |
|
70 | + )), |
|
71 | 71 | ), |
72 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
73 | - ) ); |
|
72 | + 'schema' => array($this, 'get_public_item_schema'), |
|
73 | + )); |
|
74 | 74 | |
75 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
75 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
76 | 76 | 'args' => array( |
77 | 77 | 'id' => array( |
78 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
78 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
79 | 79 | 'type' => 'integer', |
80 | 80 | ), |
81 | 81 | ), |
82 | 82 | array( |
83 | 83 | 'methods' => WP_REST_Server::READABLE, |
84 | - 'callback' => array( $this, 'get_item' ), |
|
85 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
84 | + 'callback' => array($this, 'get_item'), |
|
85 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
86 | 86 | 'args' => array( |
87 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
87 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
88 | 88 | ), |
89 | 89 | ), |
90 | 90 | array( |
91 | 91 | 'methods' => WP_REST_Server::EDITABLE, |
92 | - 'callback' => array( $this, 'update_item' ), |
|
93 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
94 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
92 | + 'callback' => array($this, 'update_item'), |
|
93 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
94 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
95 | 95 | ), |
96 | 96 | array( |
97 | 97 | 'methods' => WP_REST_Server::DELETABLE, |
98 | - 'callback' => array( $this, 'delete_item' ), |
|
99 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
98 | + 'callback' => array($this, 'delete_item'), |
|
99 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
100 | 100 | 'args' => array( |
101 | 101 | 'force' => array( |
102 | 102 | 'default' => false, |
103 | 103 | 'type' => 'boolean', |
104 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
104 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
105 | 105 | ), |
106 | 106 | ), |
107 | 107 | ), |
108 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
109 | - ) ); |
|
108 | + 'schema' => array($this, 'get_public_item_schema'), |
|
109 | + )); |
|
110 | 110 | |
111 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
111 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
112 | 112 | array( |
113 | 113 | 'methods' => WP_REST_Server::EDITABLE, |
114 | - 'callback' => array( $this, 'batch_items' ), |
|
115 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
116 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
114 | + 'callback' => array($this, 'batch_items'), |
|
115 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
116 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
117 | 117 | ), |
118 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
119 | - ) ); |
|
118 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
119 | + )); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * @param WP_REST_Request $request Full details about the request. |
126 | 126 | * @return WP_Error|boolean |
127 | 127 | */ |
128 | - public function get_items_permissions_check( $request ) { |
|
129 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) { |
|
130 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
128 | + public function get_items_permissions_check($request) { |
|
129 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) { |
|
130 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | return true; |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return bool|WP_Error |
142 | 142 | */ |
143 | - public function create_item_permissions_check( $request ) { |
|
144 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'create' ) ) { |
|
145 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
143 | + public function create_item_permissions_check($request) { |
|
144 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'create')) { |
|
145 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | return true; |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | * @param WP_REST_Request $request Full details about the request. |
155 | 155 | * @return WP_Error|boolean |
156 | 156 | */ |
157 | - public function get_item_permissions_check( $request ) { |
|
158 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) { |
|
159 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
157 | + public function get_item_permissions_check($request) { |
|
158 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) { |
|
159 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | return true; |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | * |
170 | 170 | * @return bool|WP_Error |
171 | 171 | */ |
172 | - public function update_item_permissions_check( $request ) { |
|
173 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'edit' ) ) { |
|
174 | - return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
172 | + public function update_item_permissions_check($request) { |
|
173 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'edit')) { |
|
174 | + return new WP_Error('woocommerce_rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | return true; |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @return bool|WP_Error |
186 | 186 | */ |
187 | - public function delete_item_permissions_check( $request ) { |
|
188 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'delete' ) ) { |
|
189 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
187 | + public function delete_item_permissions_check($request) { |
|
188 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'delete')) { |
|
189 | + return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | return true; |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @return bool|WP_Error |
201 | 201 | */ |
202 | - public function batch_items_permissions_check( $request ) { |
|
203 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'batch' ) ) { |
|
204 | - 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() ) ); |
|
202 | + public function batch_items_permissions_check($request) { |
|
203 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'batch')) { |
|
204 | + 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())); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return true; |
@@ -223,20 +223,20 @@ discard block |
||
223 | 223 | * @param WP_REST_Request $request Full details about the request. |
224 | 224 | * @return WP_Error|WP_REST_Response |
225 | 225 | */ |
226 | - public function get_items( $request ) { |
|
226 | + public function get_items($request) { |
|
227 | 227 | $args = array(); |
228 | 228 | $args['order'] = $request['order']; |
229 | 229 | $args['orderby'] = $request['orderby']; |
230 | 230 | $args['status'] = 'all' === $request['status'] ? '' : $request['status']; |
231 | - $args['include'] = implode( ',', $request['include'] ); |
|
232 | - $args['exclude'] = implode( ',', $request['exclude'] ); |
|
231 | + $args['include'] = implode(',', $request['include']); |
|
232 | + $args['exclude'] = implode(',', $request['exclude']); |
|
233 | 233 | $args['limit'] = $request['per_page']; |
234 | 234 | $args['search'] = $request['search']; |
235 | 235 | $args['before'] = $request['before']; |
236 | 236 | $args['after'] = $request['after']; |
237 | 237 | |
238 | - if ( empty( $request['offset'] ) ) { |
|
239 | - $args['offset'] = 1 < $request['page'] ? ( $request['page'] - 1 ) * $args['limit'] : 0; |
|
238 | + if (empty($request['offset'])) { |
|
239 | + $args['offset'] = 1 < $request['page'] ? ($request['page'] - 1) * $args['limit'] : 0; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -245,43 +245,43 @@ discard block |
||
245 | 245 | * @param array $args Array of arguments for $wpdb->get_results(). |
246 | 246 | * @param WP_REST_Request $request The current request. |
247 | 247 | */ |
248 | - $prepared_args = apply_filters( 'woocommerce_rest_webhook_query', $args, $request ); |
|
249 | - unset( $prepared_args['page'] ); |
|
248 | + $prepared_args = apply_filters('woocommerce_rest_webhook_query', $args, $request); |
|
249 | + unset($prepared_args['page']); |
|
250 | 250 | $prepared_args['paginate'] = true; |
251 | 251 | |
252 | 252 | // Get the webhooks. |
253 | 253 | $webhooks = array(); |
254 | - $data_store = WC_Data_Store::load( 'webhook' ); |
|
255 | - $results = $data_store->search_webhooks( $prepared_args ); |
|
254 | + $data_store = WC_Data_Store::load('webhook'); |
|
255 | + $results = $data_store->search_webhooks($prepared_args); |
|
256 | 256 | $webhook_ids = $results->webhooks; |
257 | 257 | |
258 | - foreach ( $webhook_ids as $webhook_id ) { |
|
259 | - $data = $this->prepare_item_for_response( $webhook_id, $request ); |
|
260 | - $webhooks[] = $this->prepare_response_for_collection( $data ); |
|
258 | + foreach ($webhook_ids as $webhook_id) { |
|
259 | + $data = $this->prepare_item_for_response($webhook_id, $request); |
|
260 | + $webhooks[] = $this->prepare_response_for_collection($data); |
|
261 | 261 | } |
262 | 262 | |
263 | - $response = rest_ensure_response( $webhooks ); |
|
263 | + $response = rest_ensure_response($webhooks); |
|
264 | 264 | $per_page = (int) $prepared_args['limit']; |
265 | - $page = ceil( ( ( (int) $prepared_args['offset'] ) / $per_page ) + 1 ); |
|
265 | + $page = ceil((((int) $prepared_args['offset']) / $per_page) + 1); |
|
266 | 266 | $total_webhooks = $results->total; |
267 | 267 | $max_pages = $results->max_num_pages; |
268 | - $base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
268 | + $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
269 | 269 | |
270 | - $response->header( 'X-WP-Total', $total_webhooks ); |
|
271 | - $response->header( 'X-WP-TotalPages', $max_pages ); |
|
270 | + $response->header('X-WP-Total', $total_webhooks); |
|
271 | + $response->header('X-WP-TotalPages', $max_pages); |
|
272 | 272 | |
273 | - if ( $page > 1 ) { |
|
273 | + if ($page > 1) { |
|
274 | 274 | $prev_page = $page - 1; |
275 | - if ( $prev_page > $max_pages ) { |
|
275 | + if ($prev_page > $max_pages) { |
|
276 | 276 | $prev_page = $max_pages; |
277 | 277 | } |
278 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
279 | - $response->link_header( 'prev', $prev_link ); |
|
278 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
279 | + $response->link_header('prev', $prev_link); |
|
280 | 280 | } |
281 | - if ( $max_pages > $page ) { |
|
281 | + if ($max_pages > $page) { |
|
282 | 282 | $next_page = $page + 1; |
283 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
284 | - $response->link_header( 'next', $next_link ); |
|
283 | + $next_link = add_query_arg('page', $next_page, $base); |
|
284 | + $response->link_header('next', $next_link); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | return $response; |
@@ -293,15 +293,15 @@ discard block |
||
293 | 293 | * @param WP_REST_Request $request Full details about the request. |
294 | 294 | * @return WP_Error|WP_REST_Response |
295 | 295 | */ |
296 | - public function get_item( $request ) { |
|
296 | + public function get_item($request) { |
|
297 | 297 | $id = (int) $request['id']; |
298 | 298 | |
299 | - if ( empty( $id ) ) { |
|
300 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
299 | + if (empty($id)) { |
|
300 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404)); |
|
301 | 301 | } |
302 | 302 | |
303 | - $data = $this->prepare_item_for_response( $id, $request ); |
|
304 | - $response = rest_ensure_response( $data ); |
|
303 | + $data = $this->prepare_item_for_response($id, $request); |
|
304 | + $response = rest_ensure_response($data); |
|
305 | 305 | |
306 | 306 | return $response; |
307 | 307 | } |
@@ -312,38 +312,38 @@ discard block |
||
312 | 312 | * @param WP_REST_Request $request Full details about the request. |
313 | 313 | * @return WP_Error|WP_REST_Response |
314 | 314 | */ |
315 | - public function create_item( $request ) { |
|
316 | - if ( ! empty( $request['id'] ) ) { |
|
315 | + public function create_item($request) { |
|
316 | + if ( ! empty($request['id'])) { |
|
317 | 317 | /* translators: %s: post type */ |
318 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
318 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | // Validate topic. |
322 | - if ( empty( $request['topic'] ) || ! wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) { |
|
323 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic is required and must be valid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
322 | + if (empty($request['topic']) || ! wc_is_webhook_valid_topic(strtolower($request['topic']))) { |
|
323 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic is required and must be valid.', 'woocommerce'), array('status' => 400)); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | // Validate delivery URL. |
327 | - if ( empty( $request['delivery_url'] ) || ! wc_is_valid_url( $request['delivery_url'] ) ) { |
|
328 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
327 | + if (empty($request['delivery_url']) || ! wc_is_valid_url($request['delivery_url'])) { |
|
328 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400)); |
|
329 | 329 | } |
330 | 330 | |
331 | - $post = $this->prepare_item_for_database( $request ); |
|
332 | - if ( is_wp_error( $post ) ) { |
|
331 | + $post = $this->prepare_item_for_database($request); |
|
332 | + if (is_wp_error($post)) { |
|
333 | 333 | return $post; |
334 | 334 | } |
335 | 335 | |
336 | 336 | $webhook = new WC_Webhook(); |
337 | - $webhook->set_name( $post->post_title ); |
|
338 | - $webhook->set_user_id( $post->post_author ); |
|
339 | - $webhook->set_status( 'publish' === $post->post_status ? 'active' : 'disabled' ); |
|
340 | - $webhook->set_topic( $request['topic'] ); |
|
341 | - $webhook->set_delivery_url( $request['delivery_url'] ); |
|
342 | - $webhook->set_secret( ! empty( $request['secret'] ) ? $request['secret'] : wp_generate_password( 50, true, true ) ); |
|
343 | - $webhook->set_api_version( $this->get_default_api_version() ); |
|
337 | + $webhook->set_name($post->post_title); |
|
338 | + $webhook->set_user_id($post->post_author); |
|
339 | + $webhook->set_status('publish' === $post->post_status ? 'active' : 'disabled'); |
|
340 | + $webhook->set_topic($request['topic']); |
|
341 | + $webhook->set_delivery_url($request['delivery_url']); |
|
342 | + $webhook->set_secret( ! empty($request['secret']) ? $request['secret'] : wp_generate_password(50, true, true)); |
|
343 | + $webhook->set_api_version($this->get_default_api_version()); |
|
344 | 344 | $webhook->save(); |
345 | 345 | |
346 | - $this->update_additional_fields_for_object( $webhook, $request ); |
|
346 | + $this->update_additional_fields_for_object($webhook, $request); |
|
347 | 347 | |
348 | 348 | /** |
349 | 349 | * Fires after a single item is created or updated via the REST API. |
@@ -352,13 +352,13 @@ discard block |
||
352 | 352 | * @param WP_REST_Request $request Request object. |
353 | 353 | * @param bool $creating True when creating item, false when updating. |
354 | 354 | */ |
355 | - do_action( "woocommerce_rest_insert_webhook_object", $webhook, $request, true ); |
|
355 | + do_action("woocommerce_rest_insert_webhook_object", $webhook, $request, true); |
|
356 | 356 | |
357 | - $request->set_param( 'context', 'edit' ); |
|
358 | - $response = $this->prepare_item_for_response( $webhook->get_id(), $request ); |
|
359 | - $response = rest_ensure_response( $response ); |
|
360 | - $response->set_status( 201 ); |
|
361 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $webhook->get_id() ) ) ); |
|
357 | + $request->set_param('context', 'edit'); |
|
358 | + $response = $this->prepare_item_for_response($webhook->get_id(), $request); |
|
359 | + $response = rest_ensure_response($response); |
|
360 | + $response->set_status(201); |
|
361 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $webhook->get_id()))); |
|
362 | 362 | |
363 | 363 | // Send ping. |
364 | 364 | $webhook->deliver_ping(); |
@@ -372,58 +372,58 @@ discard block |
||
372 | 372 | * @param WP_REST_Request $request Full details about the request. |
373 | 373 | * @return WP_Error|WP_REST_Response |
374 | 374 | */ |
375 | - public function update_item( $request ) { |
|
375 | + public function update_item($request) { |
|
376 | 376 | $id = (int) $request['id']; |
377 | - $webhook = wc_get_webhook( $id ); |
|
377 | + $webhook = wc_get_webhook($id); |
|
378 | 378 | |
379 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
380 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
379 | + if (empty($webhook) || is_null($webhook)) { |
|
380 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | // Update topic. |
384 | - if ( ! empty( $request['topic'] ) ) { |
|
385 | - if ( wc_is_webhook_valid_topic( strtolower( $request['topic'] ) ) ) { |
|
386 | - $webhook->set_topic( $request['topic'] ); |
|
384 | + if ( ! empty($request['topic'])) { |
|
385 | + if (wc_is_webhook_valid_topic(strtolower($request['topic']))) { |
|
386 | + $webhook->set_topic($request['topic']); |
|
387 | 387 | } else { |
388 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_topic", __( 'Webhook topic must be valid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
388 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_topic", __('Webhook topic must be valid.', 'woocommerce'), array('status' => 400)); |
|
389 | 389 | } |
390 | 390 | } |
391 | 391 | |
392 | 392 | // Update delivery URL. |
393 | - if ( ! empty( $request['delivery_url'] ) ) { |
|
394 | - if ( wc_is_valid_url( $request['delivery_url'] ) ) { |
|
395 | - $webhook->set_delivery_url( $request['delivery_url'] ); |
|
393 | + if ( ! empty($request['delivery_url'])) { |
|
394 | + if (wc_is_valid_url($request['delivery_url'])) { |
|
395 | + $webhook->set_delivery_url($request['delivery_url']); |
|
396 | 396 | } else { |
397 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_delivery_url", __( 'Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
397 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_delivery_url", __('Webhook delivery URL must be a valid URL starting with http:// or https://.', 'woocommerce'), array('status' => 400)); |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
401 | 401 | // Update secret. |
402 | - if ( ! empty( $request['secret'] ) ) { |
|
403 | - $webhook->set_secret( $request['secret'] ); |
|
402 | + if ( ! empty($request['secret'])) { |
|
403 | + $webhook->set_secret($request['secret']); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | // Update status. |
407 | - if ( ! empty( $request['status'] ) ) { |
|
408 | - if ( wc_is_webhook_valid_status( strtolower( $request['status'] ) ) ) { |
|
409 | - $webhook->set_status( $request['status'] ); |
|
407 | + if ( ! empty($request['status'])) { |
|
408 | + if (wc_is_webhook_valid_status(strtolower($request['status']))) { |
|
409 | + $webhook->set_status($request['status']); |
|
410 | 410 | } else { |
411 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_status", __( 'Webhook status must be valid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
411 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_status", __('Webhook status must be valid.', 'woocommerce'), array('status' => 400)); |
|
412 | 412 | } |
413 | 413 | } |
414 | 414 | |
415 | - $post = $this->prepare_item_for_database( $request ); |
|
416 | - if ( is_wp_error( $post ) ) { |
|
415 | + $post = $this->prepare_item_for_database($request); |
|
416 | + if (is_wp_error($post)) { |
|
417 | 417 | return $post; |
418 | 418 | } |
419 | 419 | |
420 | - if ( isset( $post->post_title ) ) { |
|
421 | - $webhook->set_name( $post->post_title ); |
|
420 | + if (isset($post->post_title)) { |
|
421 | + $webhook->set_name($post->post_title); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | $webhook->save(); |
425 | 425 | |
426 | - $this->update_additional_fields_for_object( $webhook, $request ); |
|
426 | + $this->update_additional_fields_for_object($webhook, $request); |
|
427 | 427 | |
428 | 428 | /** |
429 | 429 | * Fires after a single item is created or updated via the REST API. |
@@ -432,12 +432,12 @@ discard block |
||
432 | 432 | * @param WP_REST_Request $request Request object. |
433 | 433 | * @param bool $creating True when creating item, false when updating. |
434 | 434 | */ |
435 | - do_action( "woocommerce_rest_insert_webhook_object", $webhook, $request, false ); |
|
435 | + do_action("woocommerce_rest_insert_webhook_object", $webhook, $request, false); |
|
436 | 436 | |
437 | - $request->set_param( 'context', 'edit' ); |
|
438 | - $response = $this->prepare_item_for_response( $webhook->get_id(), $request ); |
|
437 | + $request->set_param('context', 'edit'); |
|
438 | + $response = $this->prepare_item_for_response($webhook->get_id(), $request); |
|
439 | 439 | |
440 | - return rest_ensure_response( $response ); |
|
440 | + return rest_ensure_response($response); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -446,28 +446,28 @@ discard block |
||
446 | 446 | * @param WP_REST_Request $request Full details about the request. |
447 | 447 | * @return WP_REST_Response|WP_Error |
448 | 448 | */ |
449 | - public function delete_item( $request ) { |
|
449 | + public function delete_item($request) { |
|
450 | 450 | $id = (int) $request['id']; |
451 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
451 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
452 | 452 | |
453 | 453 | // We don't support trashing for this type, error out. |
454 | - if ( ! $force ) { |
|
455 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Webhooks do not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
454 | + if ( ! $force) { |
|
455 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Webhooks do not support trashing.', 'woocommerce'), array('status' => 501)); |
|
456 | 456 | } |
457 | 457 | |
458 | - $webhook = wc_get_webhook( $id ); |
|
458 | + $webhook = wc_get_webhook($id); |
|
459 | 459 | |
460 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
461 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
460 | + if (empty($webhook) || is_null($webhook)) { |
|
461 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('Invalid ID.', 'woocommerce'), array('status' => 404)); |
|
462 | 462 | } |
463 | 463 | |
464 | - $request->set_param( 'context', 'edit' ); |
|
465 | - $response = $this->prepare_item_for_response( $webhook, $request ); |
|
466 | - $result = $webhook->delete( true ); |
|
464 | + $request->set_param('context', 'edit'); |
|
465 | + $response = $this->prepare_item_for_response($webhook, $request); |
|
466 | + $result = $webhook->delete(true); |
|
467 | 467 | |
468 | - if ( ! $result ) { |
|
468 | + if ( ! $result) { |
|
469 | 469 | /* translators: %s: post type */ |
470 | - return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) ); |
|
470 | + return new WP_Error('woocommerce_rest_cannot_delete', sprintf(__('The %s cannot be deleted.', 'woocommerce'), $this->post_type), array('status' => 500)); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | /** |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @param WP_REST_Response $response The response data. |
478 | 478 | * @param WP_REST_Request $request The request sent to the API. |
479 | 479 | */ |
480 | - do_action( "woocommerce_rest_delete_webhook_object", $webhook, $response, $request ); |
|
480 | + do_action("woocommerce_rest_delete_webhook_object", $webhook, $response, $request); |
|
481 | 481 | |
482 | 482 | return $response; |
483 | 483 | } |
@@ -488,17 +488,17 @@ discard block |
||
488 | 488 | * @param WP_REST_Request $request Request object. |
489 | 489 | * @return WP_Error|stdClass $data Post object. |
490 | 490 | */ |
491 | - protected function prepare_item_for_database( $request ) { |
|
491 | + protected function prepare_item_for_database($request) { |
|
492 | 492 | $data = new stdClass; |
493 | 493 | |
494 | 494 | // Post ID. |
495 | - if ( isset( $request['id'] ) ) { |
|
496 | - $data->ID = absint( $request['id'] ); |
|
495 | + if (isset($request['id'])) { |
|
496 | + $data->ID = absint($request['id']); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | // Validate required POST fields. |
500 | - if ( 'POST' === $request->get_method() && empty( $data->ID ) ) { |
|
501 | - $data->post_title = ! empty( $request['name'] ) ? $request['name'] : sprintf( __( 'Webhook created on %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce' ) ) ); // @codingStandardsIgnoreLine |
|
500 | + if ('POST' === $request->get_method() && empty($data->ID)) { |
|
501 | + $data->post_title = ! empty($request['name']) ? $request['name'] : sprintf(__('Webhook created on %s', 'woocommerce'), strftime(_x('%b %d, %Y @ %I:%M %p', 'Webhook created on date parsed by strftime', 'woocommerce'))); // @codingStandardsIgnoreLine |
|
502 | 502 | |
503 | 503 | // Post author. |
504 | 504 | $data->post_author = get_current_user_id(); |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | } else { |
512 | 512 | |
513 | 513 | // Allow edit post title. |
514 | - if ( ! empty( $request['name'] ) ) { |
|
514 | + if ( ! empty($request['name'])) { |
|
515 | 515 | $data->post_title = $request['name']; |
516 | 516 | } |
517 | 517 | } |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | * for inserting or updating the database. |
533 | 533 | * @param WP_REST_Request $request Request object. |
534 | 534 | */ |
535 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $data, $request ); |
|
535 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $data, $request); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -542,14 +542,14 @@ discard block |
||
542 | 542 | * @param WP_REST_Request $request Request object. |
543 | 543 | * @return WP_REST_Response $response Response data. |
544 | 544 | */ |
545 | - public function prepare_item_for_response( $id, $request ) { |
|
546 | - $webhook = wc_get_webhook( $id ); |
|
545 | + public function prepare_item_for_response($id, $request) { |
|
546 | + $webhook = wc_get_webhook($id); |
|
547 | 547 | |
548 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
549 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
548 | + if (empty($webhook) || is_null($webhook)) { |
|
549 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
550 | 550 | } |
551 | 551 | |
552 | - $data = array( |
|
552 | + $data = array( |
|
553 | 553 | 'id' => $webhook->get_id(), |
554 | 554 | 'name' => $webhook->get_name(), |
555 | 555 | 'status' => $webhook->get_status(), |
@@ -558,18 +558,18 @@ discard block |
||
558 | 558 | 'event' => $webhook->get_event(), |
559 | 559 | 'hooks' => $webhook->get_hooks(), |
560 | 560 | 'delivery_url' => $webhook->get_delivery_url(), |
561 | - 'date_created' => wc_rest_prepare_date_response( $webhook->get_date_created() ), |
|
562 | - 'date_modified' => wc_rest_prepare_date_response( $webhook->get_date_modified() ), |
|
561 | + 'date_created' => wc_rest_prepare_date_response($webhook->get_date_created()), |
|
562 | + 'date_modified' => wc_rest_prepare_date_response($webhook->get_date_modified()), |
|
563 | 563 | ); |
564 | 564 | |
565 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
566 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
567 | - $data = $this->filter_response_by_context( $data, $context ); |
|
565 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
566 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
567 | + $data = $this->filter_response_by_context($data, $context); |
|
568 | 568 | |
569 | 569 | // Wrap the data in a response object. |
570 | - $response = rest_ensure_response( $data ); |
|
570 | + $response = rest_ensure_response($data); |
|
571 | 571 | |
572 | - $response->add_links( $this->prepare_links( $webhook->get_id() ) ); |
|
572 | + $response->add_links($this->prepare_links($webhook->get_id())); |
|
573 | 573 | |
574 | 574 | /** |
575 | 575 | * Filter webhook object returned from the REST API. |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | * @param WC_Webhook $webhook Webhook object used to create response. |
579 | 579 | * @param WP_REST_Request $request Request object. |
580 | 580 | */ |
581 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request ); |
|
581 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $webhook, $request); |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | /** |
@@ -587,13 +587,13 @@ discard block |
||
587 | 587 | * @param int $id Webhook ID. |
588 | 588 | * @return array |
589 | 589 | */ |
590 | - protected function prepare_links( $id ) { |
|
590 | + protected function prepare_links($id) { |
|
591 | 591 | $links = array( |
592 | 592 | 'self' => array( |
593 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $id ) ), |
|
593 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $id)), |
|
594 | 594 | ), |
595 | 595 | 'collection' => array( |
596 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
596 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
597 | 597 | ), |
598 | 598 | ); |
599 | 599 | |
@@ -612,77 +612,77 @@ discard block |
||
612 | 612 | 'type' => 'object', |
613 | 613 | 'properties' => array( |
614 | 614 | 'id' => array( |
615 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
615 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
616 | 616 | 'type' => 'integer', |
617 | - 'context' => array( 'view', 'edit' ), |
|
617 | + 'context' => array('view', 'edit'), |
|
618 | 618 | 'readonly' => true, |
619 | 619 | ), |
620 | 620 | 'name' => array( |
621 | - 'description' => __( 'A friendly name for the webhook.', 'woocommerce' ), |
|
621 | + 'description' => __('A friendly name for the webhook.', 'woocommerce'), |
|
622 | 622 | 'type' => 'string', |
623 | - 'context' => array( 'view', 'edit' ), |
|
623 | + 'context' => array('view', 'edit'), |
|
624 | 624 | ), |
625 | 625 | 'status' => array( |
626 | - 'description' => __( 'Webhook status.', 'woocommerce' ), |
|
626 | + 'description' => __('Webhook status.', 'woocommerce'), |
|
627 | 627 | 'type' => 'string', |
628 | 628 | 'default' => 'active', |
629 | - 'enum' => array_keys( wc_get_webhook_statuses() ), |
|
630 | - 'context' => array( 'view', 'edit' ), |
|
629 | + 'enum' => array_keys(wc_get_webhook_statuses()), |
|
630 | + 'context' => array('view', 'edit'), |
|
631 | 631 | ), |
632 | 632 | 'topic' => array( |
633 | - 'description' => __( 'Webhook topic.', 'woocommerce' ), |
|
633 | + 'description' => __('Webhook topic.', 'woocommerce'), |
|
634 | 634 | 'type' => 'string', |
635 | - 'context' => array( 'view', 'edit' ), |
|
635 | + 'context' => array('view', 'edit'), |
|
636 | 636 | ), |
637 | 637 | 'resource' => array( |
638 | - 'description' => __( 'Webhook resource.', 'woocommerce' ), |
|
638 | + 'description' => __('Webhook resource.', 'woocommerce'), |
|
639 | 639 | 'type' => 'string', |
640 | - 'context' => array( 'view', 'edit' ), |
|
640 | + 'context' => array('view', 'edit'), |
|
641 | 641 | 'readonly' => true, |
642 | 642 | ), |
643 | 643 | 'event' => array( |
644 | - 'description' => __( 'Webhook event.', 'woocommerce' ), |
|
644 | + 'description' => __('Webhook event.', 'woocommerce'), |
|
645 | 645 | 'type' => 'string', |
646 | - 'context' => array( 'view', 'edit' ), |
|
646 | + 'context' => array('view', 'edit'), |
|
647 | 647 | 'readonly' => true, |
648 | 648 | ), |
649 | 649 | 'hooks' => array( |
650 | - 'description' => __( 'WooCommerce action names associated with the webhook.', 'woocommerce' ), |
|
650 | + 'description' => __('WooCommerce action names associated with the webhook.', 'woocommerce'), |
|
651 | 651 | 'type' => 'array', |
652 | - 'context' => array( 'view', 'edit' ), |
|
652 | + 'context' => array('view', 'edit'), |
|
653 | 653 | 'readonly' => true, |
654 | 654 | 'items' => array( |
655 | 655 | 'type' => 'string', |
656 | 656 | ), |
657 | 657 | ), |
658 | 658 | 'delivery_url' => array( |
659 | - 'description' => __( 'The URL where the webhook payload is delivered.', 'woocommerce' ), |
|
659 | + 'description' => __('The URL where the webhook payload is delivered.', 'woocommerce'), |
|
660 | 660 | 'type' => 'string', |
661 | 661 | 'format' => 'uri', |
662 | - 'context' => array( 'view', 'edit' ), |
|
662 | + 'context' => array('view', 'edit'), |
|
663 | 663 | 'readonly' => true, |
664 | 664 | ), |
665 | 665 | 'secret' => array( |
666 | - 'description' => __( "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce' ), |
|
666 | + 'description' => __("Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default to a MD5 hash from the current user's ID|username if not provided.", 'woocommerce'), |
|
667 | 667 | 'type' => 'string', |
668 | - 'context' => array( 'edit' ), |
|
668 | + 'context' => array('edit'), |
|
669 | 669 | ), |
670 | 670 | 'date_created' => array( |
671 | - 'description' => __( "The date the webhook was created, in the site's timezone.", 'woocommerce' ), |
|
671 | + 'description' => __("The date the webhook was created, in the site's timezone.", 'woocommerce'), |
|
672 | 672 | 'type' => 'date-time', |
673 | - 'context' => array( 'view', 'edit' ), |
|
673 | + 'context' => array('view', 'edit'), |
|
674 | 674 | 'readonly' => true, |
675 | 675 | ), |
676 | 676 | 'date_modified' => array( |
677 | - 'description' => __( "The date the webhook was last modified, in the site's timezone.", 'woocommerce' ), |
|
677 | + 'description' => __("The date the webhook was last modified, in the site's timezone.", 'woocommerce'), |
|
678 | 678 | 'type' => 'date-time', |
679 | - 'context' => array( 'view', 'edit' ), |
|
679 | + 'context' => array('view', 'edit'), |
|
680 | 680 | 'readonly' => true, |
681 | 681 | ), |
682 | 682 | ), |
683 | 683 | ); |
684 | 684 | |
685 | - return $this->add_additional_fields_schema( $schema ); |
|
685 | + return $this->add_additional_fields_schema($schema); |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | /** |
@@ -696,19 +696,19 @@ discard block |
||
696 | 696 | $params['context']['default'] = 'view'; |
697 | 697 | |
698 | 698 | $params['after'] = array( |
699 | - 'description' => __( 'Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce' ), |
|
699 | + 'description' => __('Limit response to resources published after a given ISO8601 compliant date.', 'woocommerce'), |
|
700 | 700 | 'type' => 'string', |
701 | 701 | 'format' => 'date-time', |
702 | 702 | 'validate_callback' => 'rest_validate_request_arg', |
703 | 703 | ); |
704 | 704 | $params['before'] = array( |
705 | - 'description' => __( 'Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce' ), |
|
705 | + 'description' => __('Limit response to resources published before a given ISO8601 compliant date.', 'woocommerce'), |
|
706 | 706 | 'type' => 'string', |
707 | 707 | 'format' => 'date-time', |
708 | 708 | 'validate_callback' => 'rest_validate_request_arg', |
709 | 709 | ); |
710 | 710 | $params['exclude'] = array( |
711 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'woocommerce' ), |
|
711 | + 'description' => __('Ensure result set excludes specific IDs.', 'woocommerce'), |
|
712 | 712 | 'type' => 'array', |
713 | 713 | 'items' => array( |
714 | 714 | 'type' => 'integer', |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | 'sanitize_callback' => 'wp_parse_id_list', |
718 | 718 | ); |
719 | 719 | $params['include'] = array( |
720 | - 'description' => __( 'Limit result set to specific ids.', 'woocommerce' ), |
|
720 | + 'description' => __('Limit result set to specific ids.', 'woocommerce'), |
|
721 | 721 | 'type' => 'array', |
722 | 722 | 'items' => array( |
723 | 723 | 'type' => 'integer', |
@@ -726,20 +726,20 @@ discard block |
||
726 | 726 | 'sanitize_callback' => 'wp_parse_id_list', |
727 | 727 | ); |
728 | 728 | $params['offset'] = array( |
729 | - 'description' => __( 'Offset the result set by a specific number of items.', 'woocommerce' ), |
|
729 | + 'description' => __('Offset the result set by a specific number of items.', 'woocommerce'), |
|
730 | 730 | 'type' => 'integer', |
731 | 731 | 'sanitize_callback' => 'absint', |
732 | 732 | 'validate_callback' => 'rest_validate_request_arg', |
733 | 733 | ); |
734 | 734 | $params['order'] = array( |
735 | - 'description' => __( 'Order sort attribute ascending or descending.', 'woocommerce' ), |
|
735 | + 'description' => __('Order sort attribute ascending or descending.', 'woocommerce'), |
|
736 | 736 | 'type' => 'string', |
737 | 737 | 'default' => 'desc', |
738 | - 'enum' => array( 'asc', 'desc' ), |
|
738 | + 'enum' => array('asc', 'desc'), |
|
739 | 739 | 'validate_callback' => 'rest_validate_request_arg', |
740 | 740 | ); |
741 | 741 | $params['orderby'] = array( |
742 | - 'description' => __( 'Sort collection by object attribute.', 'woocommerce' ), |
|
742 | + 'description' => __('Sort collection by object attribute.', 'woocommerce'), |
|
743 | 743 | 'type' => 'string', |
744 | 744 | 'default' => 'date', |
745 | 745 | 'enum' => array( |
@@ -751,9 +751,9 @@ discard block |
||
751 | 751 | ); |
752 | 752 | $params['status'] = array( |
753 | 753 | 'default' => 'all', |
754 | - 'description' => __( 'Limit result set to webhooks assigned a specific status.', 'woocommerce' ), |
|
754 | + 'description' => __('Limit result set to webhooks assigned a specific status.', 'woocommerce'), |
|
755 | 755 | 'type' => 'string', |
756 | - 'enum' => array( 'all', 'active', 'paused', 'disabled' ), |
|
756 | + 'enum' => array('all', 'active', 'paused', 'disabled'), |
|
757 | 757 | 'sanitize_callback' => 'sanitize_key', |
758 | 758 | 'validate_callback' => 'rest_validate_request_arg', |
759 | 759 | ); |