@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.5.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * REST API Reports Coupons Totals controller class. |
@@ -41,25 +41,25 @@ discard block |
||
41 | 41 | protected function get_reports() { |
42 | 42 | global $wpdb; |
43 | 43 | |
44 | - $data = get_transient( 'rest_api_coupons_type_count' ); |
|
45 | - if ( false !== $data ) { |
|
44 | + $data = get_transient('rest_api_coupons_type_count'); |
|
45 | + if (false !== $data) { |
|
46 | 46 | return $data; |
47 | 47 | } |
48 | 48 | |
49 | 49 | $types = wc_get_coupon_types(); |
50 | 50 | $data = array(); |
51 | 51 | |
52 | - foreach ( $types as $slug => $name ) { |
|
52 | + foreach ($types as $slug => $name) { |
|
53 | 53 | $results = $wpdb->get_results( |
54 | - $wpdb->prepare( " |
|
54 | + $wpdb->prepare(" |
|
55 | 55 | SELECT count(meta_id) AS total |
56 | 56 | FROM $wpdb->postmeta |
57 | 57 | WHERE meta_key = 'discount_type' |
58 | 58 | AND meta_value = %s |
59 | - ", $slug ) |
|
59 | + ", $slug) |
|
60 | 60 | ); |
61 | 61 | |
62 | - $total = isset( $results[0] ) ? (int) $results[0]->total : 0; |
|
62 | + $total = isset($results[0]) ? (int) $results[0]->total : 0; |
|
63 | 63 | |
64 | 64 | $data[] = array( |
65 | 65 | 'slug' => $slug, |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | ); |
69 | 69 | } |
70 | 70 | |
71 | - set_transient( 'rest_api_coupons_type_count', $data, YEAR_IN_SECONDS ); |
|
71 | + set_transient('rest_api_coupons_type_count', $data, YEAR_IN_SECONDS); |
|
72 | 72 | |
73 | 73 | return $data; |
74 | 74 | } |
@@ -80,19 +80,19 @@ discard block |
||
80 | 80 | * @param WP_REST_Request $request Request object. |
81 | 81 | * @return WP_REST_Response $response Response data. |
82 | 82 | */ |
83 | - public function prepare_item_for_response( $report, $request ) { |
|
83 | + public function prepare_item_for_response($report, $request) { |
|
84 | 84 | $data = array( |
85 | 85 | 'slug' => $report->slug, |
86 | 86 | 'name' => $report->name, |
87 | 87 | 'total' => $report->total, |
88 | 88 | ); |
89 | 89 | |
90 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
91 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
92 | - $data = $this->filter_response_by_context( $data, $context ); |
|
90 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
91 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
92 | + $data = $this->filter_response_by_context($data, $context); |
|
93 | 93 | |
94 | 94 | // Wrap the data in a response object. |
95 | - $response = rest_ensure_response( $data ); |
|
95 | + $response = rest_ensure_response($data); |
|
96 | 96 | |
97 | 97 | /** |
98 | 98 | * Filter a report returned from the API. |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param object $report The original report object. |
104 | 104 | * @param WP_REST_Request $request Request used to generate the response. |
105 | 105 | */ |
106 | - return apply_filters( 'woocommerce_rest_prepare_report_coupons_count', $response, $report, $request ); |
|
106 | + return apply_filters('woocommerce_rest_prepare_report_coupons_count', $response, $report, $request); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -118,26 +118,26 @@ discard block |
||
118 | 118 | 'type' => 'object', |
119 | 119 | 'properties' => array( |
120 | 120 | 'slug' => array( |
121 | - 'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ), |
|
121 | + 'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'), |
|
122 | 122 | 'type' => 'string', |
123 | - 'context' => array( 'view' ), |
|
123 | + 'context' => array('view'), |
|
124 | 124 | 'readonly' => true, |
125 | 125 | ), |
126 | 126 | 'name' => array( |
127 | - 'description' => __( 'Coupon type name.', 'woocommerce' ), |
|
127 | + 'description' => __('Coupon type name.', 'woocommerce'), |
|
128 | 128 | 'type' => 'string', |
129 | - 'context' => array( 'view' ), |
|
129 | + 'context' => array('view'), |
|
130 | 130 | 'readonly' => true, |
131 | 131 | ), |
132 | 132 | 'total' => array( |
133 | - 'description' => __( 'Amount of coupons.', 'woocommerce' ), |
|
133 | + 'description' => __('Amount of coupons.', 'woocommerce'), |
|
134 | 134 | 'type' => 'string', |
135 | - 'context' => array( 'view' ), |
|
135 | + 'context' => array('view'), |
|
136 | 136 | 'readonly' => true, |
137 | 137 | ), |
138 | 138 | ), |
139 | 139 | ); |
140 | 140 | |
141 | - return $this->add_additional_fields_schema( $schema ); |
|
141 | + return $this->add_additional_fields_schema($schema); |
|
142 | 142 | } |
143 | 143 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 3.0.0 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Paymenga gateways controller class. |
@@ -32,26 +32,26 @@ discard block |
||
32 | 32 | * @param WP_REST_Request $request Request object. |
33 | 33 | * @return WP_REST_Response $response Response data. |
34 | 34 | */ |
35 | - public function prepare_item_for_response( $gateway, $request ) { |
|
36 | - $order = (array) get_option( 'woocommerce_gateway_order' ); |
|
35 | + public function prepare_item_for_response($gateway, $request) { |
|
36 | + $order = (array) get_option('woocommerce_gateway_order'); |
|
37 | 37 | $item = array( |
38 | 38 | 'id' => $gateway->id, |
39 | 39 | 'title' => $gateway->title, |
40 | 40 | 'description' => $gateway->description, |
41 | - 'order' => isset( $order[ $gateway->id ] ) ? $order[ $gateway->id ] : '', |
|
42 | - 'enabled' => ( 'yes' === $gateway->enabled ), |
|
41 | + 'order' => isset($order[$gateway->id]) ? $order[$gateway->id] : '', |
|
42 | + 'enabled' => ('yes' === $gateway->enabled), |
|
43 | 43 | 'method_title' => $gateway->get_method_title(), |
44 | 44 | 'method_description' => $gateway->get_method_description(), |
45 | 45 | 'method_supports' => $gateway->supports, |
46 | - 'settings' => $this->get_settings( $gateway ), |
|
46 | + 'settings' => $this->get_settings($gateway), |
|
47 | 47 | ); |
48 | 48 | |
49 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
50 | - $data = $this->add_additional_fields_to_object( $item, $request ); |
|
51 | - $data = $this->filter_response_by_context( $data, $context ); |
|
49 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
50 | + $data = $this->add_additional_fields_to_object($item, $request); |
|
51 | + $data = $this->filter_response_by_context($data, $context); |
|
52 | 52 | |
53 | - $response = rest_ensure_response( $data ); |
|
54 | - $response->add_links( $this->prepare_links( $gateway, $request ) ); |
|
53 | + $response = rest_ensure_response($data); |
|
54 | + $response->add_links($this->prepare_links($gateway, $request)); |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Filter payment gateway objects returned from the REST API. |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param WC_Payment_Gateway $gateway Payment gateway object. |
61 | 61 | * @param WP_REST_Request $request Request object. |
62 | 62 | */ |
63 | - return apply_filters( 'woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request ); |
|
63 | + return apply_filters('woocommerce_rest_prepare_payment_gateway', $response, $gateway, $request); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -70,34 +70,34 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return array |
72 | 72 | */ |
73 | - public function get_settings( $gateway ) { |
|
73 | + public function get_settings($gateway) { |
|
74 | 74 | $settings = array(); |
75 | 75 | $gateway->init_form_fields(); |
76 | - foreach ( $gateway->form_fields as $id => $field ) { |
|
76 | + foreach ($gateway->form_fields as $id => $field) { |
|
77 | 77 | // Make sure we at least have a title and type. |
78 | - if ( empty( $field['title'] ) || empty( $field['type'] ) ) { |
|
78 | + if (empty($field['title']) || empty($field['type'])) { |
|
79 | 79 | continue; |
80 | 80 | } |
81 | 81 | |
82 | 82 | // Ignore 'enabled' and 'description' which get included elsewhere. |
83 | - if ( in_array( $id, array( 'enabled', 'description' ), true ) ) { |
|
83 | + if (in_array($id, array('enabled', 'description'), true)) { |
|
84 | 84 | continue; |
85 | 85 | } |
86 | 86 | |
87 | 87 | $data = array( |
88 | 88 | 'id' => $id, |
89 | - 'label' => empty( $field['label'] ) ? $field['title'] : $field['label'], |
|
90 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
89 | + 'label' => empty($field['label']) ? $field['title'] : $field['label'], |
|
90 | + 'description' => empty($field['description']) ? '' : $field['description'], |
|
91 | 91 | 'type' => $field['type'], |
92 | - 'value' => empty( $gateway->settings[ $id ] ) ? '' : $gateway->settings[ $id ], |
|
93 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
94 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
95 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
92 | + 'value' => empty($gateway->settings[$id]) ? '' : $gateway->settings[$id], |
|
93 | + 'default' => empty($field['default']) ? '' : $field['default'], |
|
94 | + 'tip' => empty($field['description']) ? '' : $field['description'], |
|
95 | + 'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'], |
|
96 | 96 | ); |
97 | - if ( ! empty( $field['options'] ) ) { |
|
97 | + if ( ! empty($field['options'])) { |
|
98 | 98 | $data['options'] = $field['options']; |
99 | 99 | } |
100 | - $settings[ $id ] = $data; |
|
100 | + $settings[$id] = $data; |
|
101 | 101 | } |
102 | 102 | return $settings; |
103 | 103 | } |
@@ -114,106 +114,106 @@ discard block |
||
114 | 114 | 'type' => 'object', |
115 | 115 | 'properties' => array( |
116 | 116 | 'id' => array( |
117 | - 'description' => __( 'Payment gateway ID.', 'woocommerce' ), |
|
117 | + 'description' => __('Payment gateway ID.', 'woocommerce'), |
|
118 | 118 | 'type' => 'string', |
119 | - 'context' => array( 'view', 'edit' ), |
|
119 | + 'context' => array('view', 'edit'), |
|
120 | 120 | 'readonly' => true, |
121 | 121 | ), |
122 | 122 | 'title' => array( |
123 | - 'description' => __( 'Payment gateway title on checkout.', 'woocommerce' ), |
|
123 | + 'description' => __('Payment gateway title on checkout.', 'woocommerce'), |
|
124 | 124 | 'type' => 'string', |
125 | - 'context' => array( 'view', 'edit' ), |
|
125 | + 'context' => array('view', 'edit'), |
|
126 | 126 | ), |
127 | 127 | 'description' => array( |
128 | - 'description' => __( 'Payment gateway description on checkout.', 'woocommerce' ), |
|
128 | + 'description' => __('Payment gateway description on checkout.', 'woocommerce'), |
|
129 | 129 | 'type' => 'string', |
130 | - 'context' => array( 'view', 'edit' ), |
|
130 | + 'context' => array('view', 'edit'), |
|
131 | 131 | ), |
132 | 132 | 'order' => array( |
133 | - 'description' => __( 'Payment gateway sort order.', 'woocommerce' ), |
|
133 | + 'description' => __('Payment gateway sort order.', 'woocommerce'), |
|
134 | 134 | 'type' => 'integer', |
135 | - 'context' => array( 'view', 'edit' ), |
|
135 | + 'context' => array('view', 'edit'), |
|
136 | 136 | 'arg_options' => array( |
137 | 137 | 'sanitize_callback' => 'absint', |
138 | 138 | ), |
139 | 139 | ), |
140 | 140 | 'enabled' => array( |
141 | - 'description' => __( 'Payment gateway enabled status.', 'woocommerce' ), |
|
141 | + 'description' => __('Payment gateway enabled status.', 'woocommerce'), |
|
142 | 142 | 'type' => 'boolean', |
143 | - 'context' => array( 'view', 'edit' ), |
|
143 | + 'context' => array('view', 'edit'), |
|
144 | 144 | ), |
145 | 145 | 'method_title' => array( |
146 | - 'description' => __( 'Payment gateway method title.', 'woocommerce' ), |
|
146 | + 'description' => __('Payment gateway method title.', 'woocommerce'), |
|
147 | 147 | 'type' => 'string', |
148 | - 'context' => array( 'view', 'edit' ), |
|
148 | + 'context' => array('view', 'edit'), |
|
149 | 149 | 'readonly' => true, |
150 | 150 | ), |
151 | 151 | 'method_description' => array( |
152 | - 'description' => __( 'Payment gateway method description.', 'woocommerce' ), |
|
152 | + 'description' => __('Payment gateway method description.', 'woocommerce'), |
|
153 | 153 | 'type' => 'string', |
154 | - 'context' => array( 'view', 'edit' ), |
|
154 | + 'context' => array('view', 'edit'), |
|
155 | 155 | 'readonly' => true, |
156 | 156 | ), |
157 | 157 | 'method_supports' => array( |
158 | - 'description' => __( 'Supported features for this payment gateway.', 'woocommerce' ), |
|
158 | + 'description' => __('Supported features for this payment gateway.', 'woocommerce'), |
|
159 | 159 | 'type' => 'array', |
160 | - 'context' => array( 'view', 'edit' ), |
|
160 | + 'context' => array('view', 'edit'), |
|
161 | 161 | 'readonly' => true, |
162 | 162 | 'items' => array( |
163 | 163 | 'type' => 'string', |
164 | 164 | ), |
165 | 165 | ), |
166 | 166 | 'settings' => array( |
167 | - 'description' => __( 'Payment gateway settings.', 'woocommerce' ), |
|
167 | + 'description' => __('Payment gateway settings.', 'woocommerce'), |
|
168 | 168 | 'type' => 'object', |
169 | - 'context' => array( 'view', 'edit' ), |
|
169 | + 'context' => array('view', 'edit'), |
|
170 | 170 | 'properties' => array( |
171 | 171 | 'id' => array( |
172 | - 'description' => __( 'A unique identifier for the setting.', 'woocommerce' ), |
|
172 | + 'description' => __('A unique identifier for the setting.', 'woocommerce'), |
|
173 | 173 | 'type' => 'string', |
174 | - 'context' => array( 'view', 'edit' ), |
|
174 | + 'context' => array('view', 'edit'), |
|
175 | 175 | 'readonly' => true, |
176 | 176 | ), |
177 | 177 | 'label' => array( |
178 | - 'description' => __( 'A human readable label for the setting used in interfaces.', 'woocommerce' ), |
|
178 | + 'description' => __('A human readable label for the setting used in interfaces.', 'woocommerce'), |
|
179 | 179 | 'type' => 'string', |
180 | - 'context' => array( 'view', 'edit' ), |
|
180 | + 'context' => array('view', 'edit'), |
|
181 | 181 | 'readonly' => true, |
182 | 182 | ), |
183 | 183 | 'description' => array( |
184 | - 'description' => __( 'A human readable description for the setting used in interfaces.', 'woocommerce' ), |
|
184 | + 'description' => __('A human readable description for the setting used in interfaces.', 'woocommerce'), |
|
185 | 185 | 'type' => 'string', |
186 | - 'context' => array( 'view', 'edit' ), |
|
186 | + 'context' => array('view', 'edit'), |
|
187 | 187 | 'readonly' => true, |
188 | 188 | ), |
189 | 189 | 'type' => array( |
190 | - 'description' => __( 'Type of setting.', 'woocommerce' ), |
|
190 | + 'description' => __('Type of setting.', 'woocommerce'), |
|
191 | 191 | 'type' => 'string', |
192 | - 'context' => array( 'view', 'edit' ), |
|
193 | - 'enum' => array( 'text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox' ), |
|
192 | + 'context' => array('view', 'edit'), |
|
193 | + 'enum' => array('text', 'email', 'number', 'color', 'password', 'textarea', 'select', 'multiselect', 'radio', 'image_width', 'checkbox'), |
|
194 | 194 | 'readonly' => true, |
195 | 195 | ), |
196 | 196 | 'value' => array( |
197 | - 'description' => __( 'Setting value.', 'woocommerce' ), |
|
197 | + 'description' => __('Setting value.', 'woocommerce'), |
|
198 | 198 | 'type' => 'string', |
199 | - 'context' => array( 'view', 'edit' ), |
|
199 | + 'context' => array('view', 'edit'), |
|
200 | 200 | ), |
201 | 201 | 'default' => array( |
202 | - 'description' => __( 'Default value for the setting.', 'woocommerce' ), |
|
202 | + 'description' => __('Default value for the setting.', 'woocommerce'), |
|
203 | 203 | 'type' => 'string', |
204 | - 'context' => array( 'view', 'edit' ), |
|
204 | + 'context' => array('view', 'edit'), |
|
205 | 205 | 'readonly' => true, |
206 | 206 | ), |
207 | 207 | 'tip' => array( |
208 | - 'description' => __( 'Additional help text shown to the user about the setting.', 'woocommerce' ), |
|
208 | + 'description' => __('Additional help text shown to the user about the setting.', 'woocommerce'), |
|
209 | 209 | 'type' => 'string', |
210 | - 'context' => array( 'view', 'edit' ), |
|
210 | + 'context' => array('view', 'edit'), |
|
211 | 211 | 'readonly' => true, |
212 | 212 | ), |
213 | 213 | 'placeholder' => array( |
214 | - 'description' => __( 'Placeholder text to be displayed in text inputs.', 'woocommerce' ), |
|
214 | + 'description' => __('Placeholder text to be displayed in text inputs.', 'woocommerce'), |
|
215 | 215 | 'type' => 'string', |
216 | - 'context' => array( 'view', 'edit' ), |
|
216 | + 'context' => array('view', 'edit'), |
|
217 | 217 | 'readonly' => true, |
218 | 218 | ), |
219 | 219 | ), |
@@ -221,6 +221,6 @@ discard block |
||
221 | 221 | ), |
222 | 222 | ); |
223 | 223 | |
224 | - return $this->add_additional_fields_schema( $schema ); |
|
224 | + return $this->add_additional_fields_schema($schema); |
|
225 | 225 | } |
226 | 226 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @since 2.6.0 |
11 | 11 | */ |
12 | 12 | |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -47,69 +47,69 @@ discard block |
||
47 | 47 | * Order refunds actions. |
48 | 48 | */ |
49 | 49 | public function __construct() { |
50 | - add_filter( "woocommerce_rest_{$this->post_type}_trashable", '__return_false' ); |
|
51 | - add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'query_args' ), 10, 2 ); |
|
50 | + add_filter("woocommerce_rest_{$this->post_type}_trashable", '__return_false'); |
|
51 | + add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'query_args'), 10, 2); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Register the routes for order refunds. |
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 | 'args' => array( |
60 | 60 | 'order_id' => array( |
61 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
61 | + 'description' => __('The order ID.', 'woocommerce'), |
|
62 | 62 | 'type' => 'integer', |
63 | 63 | ), |
64 | 64 | ), |
65 | 65 | array( |
66 | 66 | 'methods' => WP_REST_Server::READABLE, |
67 | - 'callback' => array( $this, 'get_items' ), |
|
68 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
67 | + 'callback' => array($this, 'get_items'), |
|
68 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
69 | 69 | 'args' => $this->get_collection_params(), |
70 | 70 | ), |
71 | 71 | array( |
72 | 72 | 'methods' => WP_REST_Server::CREATABLE, |
73 | - 'callback' => array( $this, 'create_item' ), |
|
74 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
75 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
73 | + 'callback' => array($this, 'create_item'), |
|
74 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
75 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
76 | 76 | ), |
77 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
78 | - ) ); |
|
77 | + 'schema' => array($this, 'get_public_item_schema'), |
|
78 | + )); |
|
79 | 79 | |
80 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
80 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
81 | 81 | 'args' => array( |
82 | 82 | 'order_id' => array( |
83 | - 'description' => __( 'The order ID.', 'woocommerce' ), |
|
83 | + 'description' => __('The order ID.', 'woocommerce'), |
|
84 | 84 | 'type' => 'integer', |
85 | 85 | ), |
86 | 86 | 'id' => array( |
87 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
87 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
88 | 88 | 'type' => 'integer', |
89 | 89 | ), |
90 | 90 | ), |
91 | 91 | array( |
92 | 92 | 'methods' => WP_REST_Server::READABLE, |
93 | - 'callback' => array( $this, 'get_item' ), |
|
94 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
93 | + 'callback' => array($this, 'get_item'), |
|
94 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
95 | 95 | 'args' => array( |
96 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
96 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
97 | 97 | ), |
98 | 98 | ), |
99 | 99 | array( |
100 | 100 | 'methods' => WP_REST_Server::DELETABLE, |
101 | - 'callback' => array( $this, 'delete_item' ), |
|
102 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
101 | + 'callback' => array($this, 'delete_item'), |
|
102 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
103 | 103 | 'args' => array( |
104 | 104 | 'force' => array( |
105 | 105 | 'default' => true, |
106 | 106 | 'type' => 'boolean', |
107 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
107 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
108 | 108 | ), |
109 | 109 | ), |
110 | 110 | ), |
111 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
112 | - ) ); |
|
111 | + 'schema' => array($this, 'get_public_item_schema'), |
|
112 | + )); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -120,38 +120,38 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return WP_Error|WP_REST_Response |
122 | 122 | */ |
123 | - public function prepare_item_for_response( $post, $request ) { |
|
124 | - $order = wc_get_order( (int) $request['order_id'] ); |
|
123 | + public function prepare_item_for_response($post, $request) { |
|
124 | + $order = wc_get_order((int) $request['order_id']); |
|
125 | 125 | |
126 | - if ( ! $order ) { |
|
127 | - return new WP_Error( 'woocommerce_rest_invalid_order_id', __( 'Invalid order ID.', 'woocommerce' ), 404 ); |
|
126 | + if ( ! $order) { |
|
127 | + return new WP_Error('woocommerce_rest_invalid_order_id', __('Invalid order ID.', 'woocommerce'), 404); |
|
128 | 128 | } |
129 | 129 | |
130 | - $refund = wc_get_order( $post ); |
|
130 | + $refund = wc_get_order($post); |
|
131 | 131 | |
132 | - if ( ! $refund || $refund->get_parent_id() !== $order->get_id() ) { |
|
133 | - return new WP_Error( 'woocommerce_rest_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 404 ); |
|
132 | + if ( ! $refund || $refund->get_parent_id() !== $order->get_id()) { |
|
133 | + return new WP_Error('woocommerce_rest_invalid_order_refund_id', __('Invalid order refund ID.', 'woocommerce'), 404); |
|
134 | 134 | } |
135 | 135 | |
136 | - $dp = is_null( $request['dp'] ) ? wc_get_price_decimals() : absint( $request['dp'] ); |
|
136 | + $dp = is_null($request['dp']) ? wc_get_price_decimals() : absint($request['dp']); |
|
137 | 137 | |
138 | 138 | $data = array( |
139 | 139 | 'id' => $refund->get_id(), |
140 | - 'date_created' => wc_rest_prepare_date_response( $refund->get_date_created() ), |
|
141 | - 'amount' => wc_format_decimal( $refund->get_amount(), $dp ), |
|
140 | + 'date_created' => wc_rest_prepare_date_response($refund->get_date_created()), |
|
141 | + 'amount' => wc_format_decimal($refund->get_amount(), $dp), |
|
142 | 142 | 'reason' => $refund->get_reason(), |
143 | 143 | 'line_items' => array(), |
144 | 144 | ); |
145 | 145 | |
146 | 146 | // Add line items. |
147 | - foreach ( $refund->get_items() as $item_id => $item ) { |
|
148 | - $product = $refund->get_product_from_item( $item ); |
|
147 | + foreach ($refund->get_items() as $item_id => $item) { |
|
148 | + $product = $refund->get_product_from_item($item); |
|
149 | 149 | $product_id = 0; |
150 | 150 | $variation_id = 0; |
151 | 151 | $product_sku = null; |
152 | 152 | |
153 | 153 | // Check if the product exists. |
154 | - if ( is_object( $product ) ) { |
|
154 | + if (is_object($product)) { |
|
155 | 155 | $product_id = $item->get_product_id(); |
156 | 156 | $variation_id = $item->get_variation_id(); |
157 | 157 | $product_sku = $product->get_sku(); |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | |
162 | 162 | $hideprefix = 'true' === $request['all_item_meta'] ? null : '_'; |
163 | 163 | |
164 | - foreach ( $item->get_formatted_meta_data( $hideprefix, true ) as $meta_key => $formatted_meta ) { |
|
164 | + foreach ($item->get_formatted_meta_data($hideprefix, true) as $meta_key => $formatted_meta) { |
|
165 | 165 | $item_meta[] = array( |
166 | 166 | 'key' => $formatted_meta->key, |
167 | 167 | 'label' => $formatted_meta->display_key, |
168 | - 'value' => wc_clean( $formatted_meta->display_value ), |
|
168 | + 'value' => wc_clean($formatted_meta->display_value), |
|
169 | 169 | ); |
170 | 170 | } |
171 | 171 | |
@@ -175,47 +175,47 @@ discard block |
||
175 | 175 | 'sku' => $product_sku, |
176 | 176 | 'product_id' => (int) $product_id, |
177 | 177 | 'variation_id' => (int) $variation_id, |
178 | - 'quantity' => wc_stock_amount( $item['qty'] ), |
|
179 | - 'tax_class' => ! empty( $item['tax_class'] ) ? $item['tax_class'] : '', |
|
180 | - 'price' => wc_format_decimal( $refund->get_item_total( $item, false, false ), $dp ), |
|
181 | - 'subtotal' => wc_format_decimal( $refund->get_line_subtotal( $item, false, false ), $dp ), |
|
182 | - 'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $dp ), |
|
183 | - 'total' => wc_format_decimal( $refund->get_line_total( $item, false, false ), $dp ), |
|
184 | - 'total_tax' => wc_format_decimal( $item['line_tax'], $dp ), |
|
178 | + 'quantity' => wc_stock_amount($item['qty']), |
|
179 | + 'tax_class' => ! empty($item['tax_class']) ? $item['tax_class'] : '', |
|
180 | + 'price' => wc_format_decimal($refund->get_item_total($item, false, false), $dp), |
|
181 | + 'subtotal' => wc_format_decimal($refund->get_line_subtotal($item, false, false), $dp), |
|
182 | + 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), |
|
183 | + 'total' => wc_format_decimal($refund->get_line_total($item, false, false), $dp), |
|
184 | + 'total_tax' => wc_format_decimal($item['line_tax'], $dp), |
|
185 | 185 | 'taxes' => array(), |
186 | 186 | 'meta' => $item_meta, |
187 | 187 | ); |
188 | 188 | |
189 | - $item_line_taxes = maybe_unserialize( $item['line_tax_data'] ); |
|
190 | - if ( isset( $item_line_taxes['total'] ) ) { |
|
189 | + $item_line_taxes = maybe_unserialize($item['line_tax_data']); |
|
190 | + if (isset($item_line_taxes['total'])) { |
|
191 | 191 | $line_tax = array(); |
192 | 192 | |
193 | - foreach ( $item_line_taxes['total'] as $tax_rate_id => $tax ) { |
|
194 | - $line_tax[ $tax_rate_id ] = array( |
|
193 | + foreach ($item_line_taxes['total'] as $tax_rate_id => $tax) { |
|
194 | + $line_tax[$tax_rate_id] = array( |
|
195 | 195 | 'id' => $tax_rate_id, |
196 | 196 | 'total' => $tax, |
197 | 197 | 'subtotal' => '', |
198 | 198 | ); |
199 | 199 | } |
200 | 200 | |
201 | - foreach ( $item_line_taxes['subtotal'] as $tax_rate_id => $tax ) { |
|
202 | - $line_tax[ $tax_rate_id ]['subtotal'] = $tax; |
|
201 | + foreach ($item_line_taxes['subtotal'] as $tax_rate_id => $tax) { |
|
202 | + $line_tax[$tax_rate_id]['subtotal'] = $tax; |
|
203 | 203 | } |
204 | 204 | |
205 | - $line_item['taxes'] = array_values( $line_tax ); |
|
205 | + $line_item['taxes'] = array_values($line_tax); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | $data['line_items'][] = $line_item; |
209 | 209 | } |
210 | 210 | |
211 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
212 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
213 | - $data = $this->filter_response_by_context( $data, $context ); |
|
211 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
212 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
213 | + $data = $this->filter_response_by_context($data, $context); |
|
214 | 214 | |
215 | 215 | // Wrap the data in a response object. |
216 | - $response = rest_ensure_response( $data ); |
|
216 | + $response = rest_ensure_response($data); |
|
217 | 217 | |
218 | - $response->add_links( $this->prepare_links( $refund, $request ) ); |
|
218 | + $response->add_links($this->prepare_links($refund, $request)); |
|
219 | 219 | |
220 | 220 | /** |
221 | 221 | * Filter the data for a response. |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @param WP_Post $post Post object. |
228 | 228 | * @param WP_REST_Request $request Request object. |
229 | 229 | */ |
230 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request ); |
|
230 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -237,18 +237,18 @@ discard block |
||
237 | 237 | * @param WP_REST_Request $request Request object. |
238 | 238 | * @return array Links for the given order refund. |
239 | 239 | */ |
240 | - protected function prepare_links( $refund, $request ) { |
|
240 | + protected function prepare_links($refund, $request) { |
|
241 | 241 | $order_id = $refund->get_parent_id(); |
242 | - $base = str_replace( '(?P<order_id>[\d]+)', $order_id, $this->rest_base ); |
|
242 | + $base = str_replace('(?P<order_id>[\d]+)', $order_id, $this->rest_base); |
|
243 | 243 | $links = array( |
244 | 244 | 'self' => array( |
245 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $refund->get_id() ) ), |
|
245 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $refund->get_id())), |
|
246 | 246 | ), |
247 | 247 | 'collection' => array( |
248 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
248 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
249 | 249 | ), |
250 | 250 | 'up' => array( |
251 | - 'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order_id ) ), |
|
251 | + 'href' => rest_url(sprintf('/%s/orders/%d', $this->namespace, $order_id)), |
|
252 | 252 | ), |
253 | 253 | ); |
254 | 254 | |
@@ -262,9 +262,9 @@ discard block |
||
262 | 262 | * @param WP_REST_Request $request Request object. |
263 | 263 | * @return array |
264 | 264 | */ |
265 | - public function query_args( $args, $request ) { |
|
266 | - $args['post_status'] = array_keys( wc_get_order_statuses() ); |
|
267 | - $args['post_parent__in'] = array( absint( $request['order_id'] ) ); |
|
265 | + public function query_args($args, $request) { |
|
266 | + $args['post_status'] = array_keys(wc_get_order_statuses()); |
|
267 | + $args['post_parent__in'] = array(absint($request['order_id'])); |
|
268 | 268 | |
269 | 269 | return $args; |
270 | 270 | } |
@@ -275,41 +275,41 @@ discard block |
||
275 | 275 | * @param WP_REST_Request $request Full details about the request. |
276 | 276 | * @return WP_Error|WP_REST_Response |
277 | 277 | */ |
278 | - public function create_item( $request ) { |
|
279 | - if ( ! empty( $request['id'] ) ) { |
|
278 | + public function create_item($request) { |
|
279 | + if ( ! empty($request['id'])) { |
|
280 | 280 | /* translators: %s: post type */ |
281 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
281 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
282 | 282 | } |
283 | 283 | |
284 | - $order_data = get_post( (int) $request['order_id'] ); |
|
284 | + $order_data = get_post((int) $request['order_id']); |
|
285 | 285 | |
286 | - if ( empty( $order_data ) ) { |
|
287 | - return new WP_Error( 'woocommerce_rest_invalid_order', __( 'Order is invalid', 'woocommerce' ), 400 ); |
|
286 | + if (empty($order_data)) { |
|
287 | + return new WP_Error('woocommerce_rest_invalid_order', __('Order is invalid', 'woocommerce'), 400); |
|
288 | 288 | } |
289 | 289 | |
290 | - if ( 0 > $request['amount'] ) { |
|
291 | - return new WP_Error( 'woocommerce_rest_invalid_order_refund', __( 'Refund amount must be greater than zero.', 'woocommerce' ), 400 ); |
|
290 | + if (0 > $request['amount']) { |
|
291 | + return new WP_Error('woocommerce_rest_invalid_order_refund', __('Refund amount must be greater than zero.', 'woocommerce'), 400); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | // Create the refund. |
295 | - $refund = wc_create_refund( array( |
|
295 | + $refund = wc_create_refund(array( |
|
296 | 296 | 'order_id' => $order_data->ID, |
297 | 297 | 'amount' => $request['amount'], |
298 | - 'reason' => empty( $request['reason'] ) ? null : $request['reason'], |
|
299 | - 'refund_payment' => is_bool( $request['api_refund'] ) ? $request['api_refund'] : true, |
|
298 | + 'reason' => empty($request['reason']) ? null : $request['reason'], |
|
299 | + 'refund_payment' => is_bool($request['api_refund']) ? $request['api_refund'] : true, |
|
300 | 300 | 'restock_items' => true, |
301 | - ) ); |
|
301 | + )); |
|
302 | 302 | |
303 | - if ( is_wp_error( $refund ) ) { |
|
304 | - return new WP_Error( 'woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500 ); |
|
303 | + if (is_wp_error($refund)) { |
|
304 | + return new WP_Error('woocommerce_rest_cannot_create_order_refund', $refund->get_error_message(), 500); |
|
305 | 305 | } |
306 | 306 | |
307 | - if ( ! $refund ) { |
|
308 | - return new WP_Error( 'woocommerce_rest_cannot_create_order_refund', __( 'Cannot create order refund, please try again.', 'woocommerce' ), 500 ); |
|
307 | + if ( ! $refund) { |
|
308 | + return new WP_Error('woocommerce_rest_cannot_create_order_refund', __('Cannot create order refund, please try again.', 'woocommerce'), 500); |
|
309 | 309 | } |
310 | 310 | |
311 | - $post = get_post( $refund->get_id() ); |
|
312 | - $this->update_additional_fields_for_object( $post, $request ); |
|
311 | + $post = get_post($refund->get_id()); |
|
312 | + $this->update_additional_fields_for_object($post, $request); |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * Fires after a single item is created or updated via the REST API. |
@@ -318,13 +318,13 @@ discard block |
||
318 | 318 | * @param WP_REST_Request $request Request object. |
319 | 319 | * @param boolean $creating True when creating item, false when updating. |
320 | 320 | */ |
321 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true ); |
|
321 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true); |
|
322 | 322 | |
323 | - $request->set_param( 'context', 'edit' ); |
|
324 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
325 | - $response = rest_ensure_response( $response ); |
|
326 | - $response->set_status( 201 ); |
|
327 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ) ); |
|
323 | + $request->set_param('context', 'edit'); |
|
324 | + $response = $this->prepare_item_for_response($post, $request); |
|
325 | + $response = rest_ensure_response($response); |
|
326 | + $response->set_status(201); |
|
327 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID))); |
|
328 | 328 | |
329 | 329 | return $response; |
330 | 330 | } |
@@ -341,160 +341,160 @@ discard block |
||
341 | 341 | 'type' => 'object', |
342 | 342 | 'properties' => array( |
343 | 343 | 'id' => array( |
344 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
344 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
345 | 345 | 'type' => 'integer', |
346 | - 'context' => array( 'view', 'edit' ), |
|
346 | + 'context' => array('view', 'edit'), |
|
347 | 347 | 'readonly' => true, |
348 | 348 | ), |
349 | 349 | 'date_created' => array( |
350 | - 'description' => __( "The date the order refund was created, in the site's timezone.", 'woocommerce' ), |
|
350 | + 'description' => __("The date the order refund was created, in the site's timezone.", 'woocommerce'), |
|
351 | 351 | 'type' => 'date-time', |
352 | - 'context' => array( 'view', 'edit' ), |
|
352 | + 'context' => array('view', 'edit'), |
|
353 | 353 | 'readonly' => true, |
354 | 354 | ), |
355 | 355 | 'amount' => array( |
356 | - 'description' => __( 'Refund amount.', 'woocommerce' ), |
|
356 | + 'description' => __('Refund amount.', 'woocommerce'), |
|
357 | 357 | 'type' => 'string', |
358 | - 'context' => array( 'view', 'edit' ), |
|
358 | + 'context' => array('view', 'edit'), |
|
359 | 359 | ), |
360 | 360 | 'reason' => array( |
361 | - 'description' => __( 'Reason for refund.', 'woocommerce' ), |
|
361 | + 'description' => __('Reason for refund.', 'woocommerce'), |
|
362 | 362 | 'type' => 'string', |
363 | - 'context' => array( 'view', 'edit' ), |
|
363 | + 'context' => array('view', 'edit'), |
|
364 | 364 | ), |
365 | 365 | 'line_items' => array( |
366 | - 'description' => __( 'Line items data.', 'woocommerce' ), |
|
366 | + 'description' => __('Line items data.', 'woocommerce'), |
|
367 | 367 | 'type' => 'array', |
368 | - 'context' => array( 'view', 'edit' ), |
|
368 | + 'context' => array('view', 'edit'), |
|
369 | 369 | 'readonly' => true, |
370 | 370 | 'items' => array( |
371 | 371 | 'type' => 'object', |
372 | 372 | 'properties' => array( |
373 | 373 | 'id' => array( |
374 | - 'description' => __( 'Item ID.', 'woocommerce' ), |
|
374 | + 'description' => __('Item ID.', 'woocommerce'), |
|
375 | 375 | 'type' => 'integer', |
376 | - 'context' => array( 'view', 'edit' ), |
|
376 | + 'context' => array('view', 'edit'), |
|
377 | 377 | 'readonly' => true, |
378 | 378 | ), |
379 | 379 | 'name' => array( |
380 | - 'description' => __( 'Product name.', 'woocommerce' ), |
|
380 | + 'description' => __('Product name.', 'woocommerce'), |
|
381 | 381 | 'type' => 'mixed', |
382 | - 'context' => array( 'view', 'edit' ), |
|
382 | + 'context' => array('view', 'edit'), |
|
383 | 383 | 'readonly' => true, |
384 | 384 | ), |
385 | 385 | 'sku' => array( |
386 | - 'description' => __( 'Product SKU.', 'woocommerce' ), |
|
386 | + 'description' => __('Product SKU.', 'woocommerce'), |
|
387 | 387 | 'type' => 'string', |
388 | - 'context' => array( 'view', 'edit' ), |
|
388 | + 'context' => array('view', 'edit'), |
|
389 | 389 | 'readonly' => true, |
390 | 390 | ), |
391 | 391 | 'product_id' => array( |
392 | - 'description' => __( 'Product ID.', 'woocommerce' ), |
|
392 | + 'description' => __('Product ID.', 'woocommerce'), |
|
393 | 393 | 'type' => 'mixed', |
394 | - 'context' => array( 'view', 'edit' ), |
|
394 | + 'context' => array('view', 'edit'), |
|
395 | 395 | 'readonly' => true, |
396 | 396 | ), |
397 | 397 | 'variation_id' => array( |
398 | - 'description' => __( 'Variation ID, if applicable.', 'woocommerce' ), |
|
398 | + 'description' => __('Variation ID, if applicable.', 'woocommerce'), |
|
399 | 399 | 'type' => 'integer', |
400 | - 'context' => array( 'view', 'edit' ), |
|
400 | + 'context' => array('view', 'edit'), |
|
401 | 401 | 'readonly' => true, |
402 | 402 | ), |
403 | 403 | 'quantity' => array( |
404 | - 'description' => __( 'Quantity ordered.', 'woocommerce' ), |
|
404 | + 'description' => __('Quantity ordered.', 'woocommerce'), |
|
405 | 405 | 'type' => 'integer', |
406 | - 'context' => array( 'view', 'edit' ), |
|
406 | + 'context' => array('view', 'edit'), |
|
407 | 407 | 'readonly' => true, |
408 | 408 | ), |
409 | 409 | 'tax_class' => array( |
410 | - 'description' => __( 'Tax class of product.', 'woocommerce' ), |
|
410 | + 'description' => __('Tax class of product.', 'woocommerce'), |
|
411 | 411 | 'type' => 'string', |
412 | - 'context' => array( 'view', 'edit' ), |
|
412 | + 'context' => array('view', 'edit'), |
|
413 | 413 | 'readonly' => true, |
414 | 414 | ), |
415 | 415 | 'price' => array( |
416 | - 'description' => __( 'Product price.', 'woocommerce' ), |
|
416 | + 'description' => __('Product price.', 'woocommerce'), |
|
417 | 417 | 'type' => 'string', |
418 | - 'context' => array( 'view', 'edit' ), |
|
418 | + 'context' => array('view', 'edit'), |
|
419 | 419 | 'readonly' => true, |
420 | 420 | ), |
421 | 421 | 'subtotal' => array( |
422 | - 'description' => __( 'Line subtotal (before discounts).', 'woocommerce' ), |
|
422 | + 'description' => __('Line subtotal (before discounts).', 'woocommerce'), |
|
423 | 423 | 'type' => 'string', |
424 | - 'context' => array( 'view', 'edit' ), |
|
424 | + 'context' => array('view', 'edit'), |
|
425 | 425 | 'readonly' => true, |
426 | 426 | ), |
427 | 427 | 'subtotal_tax' => array( |
428 | - 'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce' ), |
|
428 | + 'description' => __('Line subtotal tax (before discounts).', 'woocommerce'), |
|
429 | 429 | 'type' => 'string', |
430 | - 'context' => array( 'view', 'edit' ), |
|
430 | + 'context' => array('view', 'edit'), |
|
431 | 431 | 'readonly' => true, |
432 | 432 | ), |
433 | 433 | 'total' => array( |
434 | - 'description' => __( 'Line total (after discounts).', 'woocommerce' ), |
|
434 | + 'description' => __('Line total (after discounts).', 'woocommerce'), |
|
435 | 435 | 'type' => 'string', |
436 | - 'context' => array( 'view', 'edit' ), |
|
436 | + 'context' => array('view', 'edit'), |
|
437 | 437 | 'readonly' => true, |
438 | 438 | ), |
439 | 439 | 'total_tax' => array( |
440 | - 'description' => __( 'Line total tax (after discounts).', 'woocommerce' ), |
|
440 | + 'description' => __('Line total tax (after discounts).', 'woocommerce'), |
|
441 | 441 | 'type' => 'string', |
442 | - 'context' => array( 'view', 'edit' ), |
|
442 | + 'context' => array('view', 'edit'), |
|
443 | 443 | 'readonly' => true, |
444 | 444 | ), |
445 | 445 | 'taxes' => array( |
446 | - 'description' => __( 'Line taxes.', 'woocommerce' ), |
|
446 | + 'description' => __('Line taxes.', 'woocommerce'), |
|
447 | 447 | 'type' => 'array', |
448 | - 'context' => array( 'view', 'edit' ), |
|
448 | + 'context' => array('view', 'edit'), |
|
449 | 449 | 'readonly' => true, |
450 | 450 | 'items' => array( |
451 | 451 | 'type' => 'object', |
452 | 452 | 'properties' => array( |
453 | 453 | 'id' => array( |
454 | - 'description' => __( 'Tax rate ID.', 'woocommerce' ), |
|
454 | + 'description' => __('Tax rate ID.', 'woocommerce'), |
|
455 | 455 | 'type' => 'integer', |
456 | - 'context' => array( 'view', 'edit' ), |
|
456 | + 'context' => array('view', 'edit'), |
|
457 | 457 | 'readonly' => true, |
458 | 458 | ), |
459 | 459 | 'total' => array( |
460 | - 'description' => __( 'Tax total.', 'woocommerce' ), |
|
460 | + 'description' => __('Tax total.', 'woocommerce'), |
|
461 | 461 | 'type' => 'string', |
462 | - 'context' => array( 'view', 'edit' ), |
|
462 | + 'context' => array('view', 'edit'), |
|
463 | 463 | 'readonly' => true, |
464 | 464 | ), |
465 | 465 | 'subtotal' => array( |
466 | - 'description' => __( 'Tax subtotal.', 'woocommerce' ), |
|
466 | + 'description' => __('Tax subtotal.', 'woocommerce'), |
|
467 | 467 | 'type' => 'string', |
468 | - 'context' => array( 'view', 'edit' ), |
|
468 | + 'context' => array('view', 'edit'), |
|
469 | 469 | 'readonly' => true, |
470 | 470 | ), |
471 | 471 | ), |
472 | 472 | ), |
473 | 473 | ), |
474 | 474 | 'meta' => array( |
475 | - 'description' => __( 'Line item meta data.', 'woocommerce' ), |
|
475 | + 'description' => __('Line item meta data.', 'woocommerce'), |
|
476 | 476 | 'type' => 'array', |
477 | - 'context' => array( 'view', 'edit' ), |
|
477 | + 'context' => array('view', 'edit'), |
|
478 | 478 | 'readonly' => true, |
479 | 479 | 'items' => array( |
480 | 480 | 'type' => 'object', |
481 | 481 | 'properties' => array( |
482 | 482 | 'key' => array( |
483 | - 'description' => __( 'Meta key.', 'woocommerce' ), |
|
483 | + 'description' => __('Meta key.', 'woocommerce'), |
|
484 | 484 | 'type' => 'string', |
485 | - 'context' => array( 'view', 'edit' ), |
|
485 | + 'context' => array('view', 'edit'), |
|
486 | 486 | 'readonly' => true, |
487 | 487 | ), |
488 | 488 | 'label' => array( |
489 | - 'description' => __( 'Meta label.', 'woocommerce' ), |
|
489 | + 'description' => __('Meta label.', 'woocommerce'), |
|
490 | 490 | 'type' => 'string', |
491 | - 'context' => array( 'view', 'edit' ), |
|
491 | + 'context' => array('view', 'edit'), |
|
492 | 492 | 'readonly' => true, |
493 | 493 | ), |
494 | 494 | 'value' => array( |
495 | - 'description' => __( 'Meta value.', 'woocommerce' ), |
|
495 | + 'description' => __('Meta value.', 'woocommerce'), |
|
496 | 496 | 'type' => 'mixed', |
497 | - 'context' => array( 'view', 'edit' ), |
|
497 | + 'context' => array('view', 'edit'), |
|
498 | 498 | 'readonly' => true, |
499 | 499 | ), |
500 | 500 | ), |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | ), |
507 | 507 | ); |
508 | 508 | |
509 | - return $this->add_additional_fields_schema( $schema ); |
|
509 | + return $this->add_additional_fields_schema($schema); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | |
520 | 520 | $params['dp'] = array( |
521 | 521 | 'default' => wc_get_price_decimals(), |
522 | - 'description' => __( 'Number of decimal points to use in each resource.', 'woocommerce' ), |
|
522 | + 'description' => __('Number of decimal points to use in each resource.', 'woocommerce'), |
|
523 | 523 | 'type' => 'integer', |
524 | 524 | 'sanitize_callback' => 'absint', |
525 | 525 | '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 | |
@@ -41,43 +41,43 @@ discard block |
||
41 | 41 | * Register the routes for webhook deliveries. |
42 | 42 | */ |
43 | 43 | public function register_routes() { |
44 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
44 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
45 | 45 | 'args' => array( |
46 | 46 | 'webhook_id' => array( |
47 | - 'description' => __( 'Unique identifier for the webhook.', 'woocommerce' ), |
|
47 | + 'description' => __('Unique identifier for the webhook.', 'woocommerce'), |
|
48 | 48 | 'type' => 'integer', |
49 | 49 | ), |
50 | 50 | ), |
51 | 51 | array( |
52 | 52 | 'methods' => WP_REST_Server::READABLE, |
53 | - 'callback' => array( $this, 'get_items' ), |
|
54 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
53 | + 'callback' => array($this, 'get_items'), |
|
54 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
55 | 55 | 'args' => $this->get_collection_params(), |
56 | 56 | ), |
57 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
58 | - ) ); |
|
57 | + 'schema' => array($this, 'get_public_item_schema'), |
|
58 | + )); |
|
59 | 59 | |
60 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
60 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
61 | 61 | 'args' => array( |
62 | 62 | 'webhook_id' => array( |
63 | - 'description' => __( 'Unique identifier for the webhook.', 'woocommerce' ), |
|
63 | + 'description' => __('Unique identifier for the webhook.', 'woocommerce'), |
|
64 | 64 | 'type' => 'integer', |
65 | 65 | ), |
66 | 66 | 'id' => array( |
67 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
67 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
68 | 68 | 'type' => 'integer', |
69 | 69 | ), |
70 | 70 | ), |
71 | 71 | array( |
72 | 72 | 'methods' => WP_REST_Server::READABLE, |
73 | - 'callback' => array( $this, 'get_item' ), |
|
74 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
73 | + 'callback' => array($this, 'get_item'), |
|
74 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
75 | 75 | 'args' => array( |
76 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
76 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
77 | 77 | ), |
78 | 78 | ), |
79 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
80 | - ) ); |
|
79 | + 'schema' => array($this, 'get_public_item_schema'), |
|
80 | + )); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | * @param WP_REST_Request $request Full details about the request. |
87 | 87 | * @return WP_Error|boolean |
88 | 88 | */ |
89 | - public function get_items_permissions_check( $request ) { |
|
90 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) { |
|
91 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
89 | + public function get_items_permissions_check($request) { |
|
90 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) { |
|
91 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | return true; |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @param WP_REST_Request $request Full details about the request. |
101 | 101 | * @return WP_Error|boolean |
102 | 102 | */ |
103 | - public function get_item_permissions_check( $request ) { |
|
104 | - if ( ! wc_rest_check_manager_permissions( 'webhooks', 'read' ) ) { |
|
105 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
103 | + public function get_item_permissions_check($request) { |
|
104 | + if ( ! wc_rest_check_manager_permissions('webhooks', 'read')) { |
|
105 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot view this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return true; |
@@ -115,22 +115,22 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return array|WP_Error |
117 | 117 | */ |
118 | - public function get_items( $request ) { |
|
119 | - $webhook = wc_get_webhook( (int) $request['webhook_id'] ); |
|
118 | + public function get_items($request) { |
|
119 | + $webhook = wc_get_webhook((int) $request['webhook_id']); |
|
120 | 120 | |
121 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
122 | - return new WP_Error( 'woocommerce_rest_webhook_invalid_id', __( 'Invalid webhook ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
121 | + if (empty($webhook) || is_null($webhook)) { |
|
122 | + return new WP_Error('woocommerce_rest_webhook_invalid_id', __('Invalid webhook ID.', 'woocommerce'), array('status' => 404)); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $logs = array(); |
126 | 126 | $data = array(); |
127 | - foreach ( $logs as $log ) { |
|
128 | - $delivery = $this->prepare_item_for_response( (object) $log, $request ); |
|
129 | - $delivery = $this->prepare_response_for_collection( $delivery ); |
|
127 | + foreach ($logs as $log) { |
|
128 | + $delivery = $this->prepare_item_for_response((object) $log, $request); |
|
129 | + $delivery = $this->prepare_response_for_collection($delivery); |
|
130 | 130 | $data[] = $delivery; |
131 | 131 | } |
132 | 132 | |
133 | - return rest_ensure_response( $data ); |
|
133 | + return rest_ensure_response($data); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,22 +139,22 @@ discard block |
||
139 | 139 | * @param WP_REST_Request $request Full details about the request. |
140 | 140 | * @return WP_Error|WP_REST_Response |
141 | 141 | */ |
142 | - public function get_item( $request ) { |
|
142 | + public function get_item($request) { |
|
143 | 143 | $id = (int) $request['id']; |
144 | - $webhook = wc_get_webhook( (int) $request['webhook_id'] ); |
|
144 | + $webhook = wc_get_webhook((int) $request['webhook_id']); |
|
145 | 145 | |
146 | - if ( empty( $webhook ) || is_null( $webhook ) ) { |
|
147 | - return new WP_Error( 'woocommerce_rest_webhook_invalid_id', __( 'Invalid webhook ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
146 | + if (empty($webhook) || is_null($webhook)) { |
|
147 | + return new WP_Error('woocommerce_rest_webhook_invalid_id', __('Invalid webhook ID.', 'woocommerce'), array('status' => 404)); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | $log = array(); |
151 | 151 | |
152 | - if ( empty( $id ) || empty( $log ) ) { |
|
153 | - return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
152 | + if (empty($id) || empty($log)) { |
|
153 | + return new WP_Error('woocommerce_rest_invalid_id', __('Invalid resource ID.', 'woocommerce'), array('status' => 404)); |
|
154 | 154 | } |
155 | 155 | |
156 | - $delivery = $this->prepare_item_for_response( (object) $log, $request ); |
|
157 | - $response = rest_ensure_response( $delivery ); |
|
156 | + $delivery = $this->prepare_item_for_response((object) $log, $request); |
|
157 | + $response = rest_ensure_response($delivery); |
|
158 | 158 | |
159 | 159 | return $response; |
160 | 160 | } |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | * @param WP_REST_Request $request Request object. |
167 | 167 | * @return WP_REST_Response $response Response data. |
168 | 168 | */ |
169 | - public function prepare_item_for_response( $log, $request ) { |
|
169 | + public function prepare_item_for_response($log, $request) { |
|
170 | 170 | $data = (array) $log; |
171 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
172 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
173 | - $data = $this->filter_response_by_context( $data, $context ); |
|
171 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
172 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
173 | + $data = $this->filter_response_by_context($data, $context); |
|
174 | 174 | |
175 | 175 | // Wrap the data in a response object. |
176 | - $response = rest_ensure_response( $data ); |
|
176 | + $response = rest_ensure_response($data); |
|
177 | 177 | |
178 | - $response->add_links( $this->prepare_links( $log ) ); |
|
178 | + $response->add_links($this->prepare_links($log)); |
|
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Filter webhook delivery object returned from the REST API. |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @param stdClass $log Delivery log object used to create response. |
185 | 185 | * @param WP_REST_Request $request Request object. |
186 | 186 | */ |
187 | - return apply_filters( 'woocommerce_rest_prepare_webhook_delivery', $response, $log, $request ); |
|
187 | + return apply_filters('woocommerce_rest_prepare_webhook_delivery', $response, $log, $request); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -193,18 +193,18 @@ discard block |
||
193 | 193 | * @param stdClass $log Delivery log object. |
194 | 194 | * @return array Links for the given webhook delivery. |
195 | 195 | */ |
196 | - protected function prepare_links( $log ) { |
|
196 | + protected function prepare_links($log) { |
|
197 | 197 | $webhook_id = (int) $log->request_headers['X-WC-Webhook-ID']; |
198 | - $base = str_replace( '(?P<webhook_id>[\d]+)', $webhook_id, $this->rest_base ); |
|
198 | + $base = str_replace('(?P<webhook_id>[\d]+)', $webhook_id, $this->rest_base); |
|
199 | 199 | $links = array( |
200 | 200 | 'self' => array( |
201 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $base, $log->id ) ), |
|
201 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $base, $log->id)), |
|
202 | 202 | ), |
203 | 203 | 'collection' => array( |
204 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $base ) ), |
|
204 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $base)), |
|
205 | 205 | ), |
206 | 206 | 'up' => array( |
207 | - 'href' => rest_url( sprintf( '/%s/webhooks/%d', $this->namespace, $webhook_id ) ), |
|
207 | + 'href' => rest_url(sprintf('/%s/webhooks/%d', $this->namespace, $webhook_id)), |
|
208 | 208 | ), |
209 | 209 | ); |
210 | 210 | |
@@ -223,82 +223,82 @@ discard block |
||
223 | 223 | 'type' => 'object', |
224 | 224 | 'properties' => array( |
225 | 225 | 'id' => array( |
226 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
226 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
227 | 227 | 'type' => 'integer', |
228 | - 'context' => array( 'view' ), |
|
228 | + 'context' => array('view'), |
|
229 | 229 | 'readonly' => true, |
230 | 230 | ), |
231 | 231 | 'duration' => array( |
232 | - 'description' => __( 'The delivery duration, in seconds.', 'woocommerce' ), |
|
232 | + 'description' => __('The delivery duration, in seconds.', 'woocommerce'), |
|
233 | 233 | 'type' => 'string', |
234 | - 'context' => array( 'view' ), |
|
234 | + 'context' => array('view'), |
|
235 | 235 | 'readonly' => true, |
236 | 236 | ), |
237 | 237 | 'summary' => array( |
238 | - 'description' => __( 'A friendly summary of the response including the HTTP response code, message, and body.', 'woocommerce' ), |
|
238 | + 'description' => __('A friendly summary of the response including the HTTP response code, message, and body.', 'woocommerce'), |
|
239 | 239 | 'type' => 'string', |
240 | - 'context' => array( 'view' ), |
|
240 | + 'context' => array('view'), |
|
241 | 241 | 'readonly' => true, |
242 | 242 | ), |
243 | 243 | 'request_url' => array( |
244 | - 'description' => __( 'The URL where the webhook was delivered.', 'woocommerce' ), |
|
244 | + 'description' => __('The URL where the webhook was delivered.', 'woocommerce'), |
|
245 | 245 | 'type' => 'string', |
246 | 246 | 'format' => 'uri', |
247 | - 'context' => array( 'view' ), |
|
247 | + 'context' => array('view'), |
|
248 | 248 | 'readonly' => true, |
249 | 249 | ), |
250 | 250 | 'request_headers' => array( |
251 | - 'description' => __( 'Request headers.', 'woocommerce' ), |
|
251 | + 'description' => __('Request headers.', 'woocommerce'), |
|
252 | 252 | 'type' => 'array', |
253 | - 'context' => array( 'view' ), |
|
253 | + 'context' => array('view'), |
|
254 | 254 | 'readonly' => true, |
255 | 255 | 'items' => array( |
256 | 256 | 'type' => 'string', |
257 | 257 | ), |
258 | 258 | ), |
259 | 259 | 'request_body' => array( |
260 | - 'description' => __( 'Request body.', 'woocommerce' ), |
|
260 | + 'description' => __('Request body.', 'woocommerce'), |
|
261 | 261 | 'type' => 'string', |
262 | - 'context' => array( 'view' ), |
|
262 | + 'context' => array('view'), |
|
263 | 263 | 'readonly' => true, |
264 | 264 | ), |
265 | 265 | 'response_code' => array( |
266 | - 'description' => __( 'The HTTP response code from the receiving server.', 'woocommerce' ), |
|
266 | + 'description' => __('The HTTP response code from the receiving server.', 'woocommerce'), |
|
267 | 267 | 'type' => 'string', |
268 | - 'context' => array( 'view' ), |
|
268 | + 'context' => array('view'), |
|
269 | 269 | 'readonly' => true, |
270 | 270 | ), |
271 | 271 | 'response_message' => array( |
272 | - 'description' => __( 'The HTTP response message from the receiving server.', 'woocommerce' ), |
|
272 | + 'description' => __('The HTTP response message from the receiving server.', 'woocommerce'), |
|
273 | 273 | 'type' => 'string', |
274 | - 'context' => array( 'view' ), |
|
274 | + 'context' => array('view'), |
|
275 | 275 | 'readonly' => true, |
276 | 276 | ), |
277 | 277 | 'response_headers' => array( |
278 | - 'description' => __( 'Array of the response headers from the receiving server.', 'woocommerce' ), |
|
278 | + 'description' => __('Array of the response headers from the receiving server.', 'woocommerce'), |
|
279 | 279 | 'type' => 'array', |
280 | - 'context' => array( 'view' ), |
|
280 | + 'context' => array('view'), |
|
281 | 281 | 'readonly' => true, |
282 | 282 | 'items' => array( |
283 | 283 | 'type' => 'string', |
284 | 284 | ), |
285 | 285 | ), |
286 | 286 | 'response_body' => array( |
287 | - 'description' => __( 'The response body from the receiving server.', 'woocommerce' ), |
|
287 | + 'description' => __('The response body from the receiving server.', 'woocommerce'), |
|
288 | 288 | 'type' => 'string', |
289 | - 'context' => array( 'view' ), |
|
289 | + 'context' => array('view'), |
|
290 | 290 | 'readonly' => true, |
291 | 291 | ), |
292 | 292 | 'date_created' => array( |
293 | - 'description' => __( "The date the webhook delivery was logged, in the site's timezone.", 'woocommerce' ), |
|
293 | + 'description' => __("The date the webhook delivery was logged, in the site's timezone.", 'woocommerce'), |
|
294 | 294 | 'type' => 'date-time', |
295 | - 'context' => array( 'view', 'edit' ), |
|
295 | + 'context' => array('view', 'edit'), |
|
296 | 296 | 'readonly' => true, |
297 | 297 | ), |
298 | 298 | ), |
299 | 299 | ); |
300 | 300 | |
301 | - return $this->add_additional_fields_schema( $schema ); |
|
301 | + return $this->add_additional_fields_schema($schema); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | */ |
309 | 309 | public function get_collection_params() { |
310 | 310 | return array( |
311 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
311 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
312 | 312 | ); |
313 | 313 | } |
314 | 314 | } |
@@ -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,15 +40,15 @@ discard block |
||
40 | 40 | * Register the routes for reports. |
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 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
51 | - ) ); |
|
50 | + 'schema' => array($this, 'get_public_item_schema'), |
|
51 | + )); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * @param WP_REST_Request $request Full details about the request. |
58 | 58 | * @return WP_Error|boolean |
59 | 59 | */ |
60 | - public function get_items_permissions_check( $request ) { |
|
61 | - if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) { |
|
62 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
60 | + public function get_items_permissions_check($request) { |
|
61 | + if ( ! wc_rest_check_manager_permissions('reports', 'read')) { |
|
62 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | return true; |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | return array( |
76 | 76 | array( |
77 | 77 | 'slug' => 'sales', |
78 | - 'description' => __( 'List of sales reports.', 'woocommerce' ), |
|
78 | + 'description' => __('List of sales reports.', 'woocommerce'), |
|
79 | 79 | ), |
80 | 80 | array( |
81 | 81 | 'slug' => 'top_sellers', |
82 | - 'description' => __( 'List of top sellers products.', 'woocommerce' ), |
|
82 | + 'description' => __('List of top sellers products.', 'woocommerce'), |
|
83 | 83 | ), |
84 | 84 | ); |
85 | 85 | } |
@@ -90,16 +90,16 @@ discard block |
||
90 | 90 | * @param WP_REST_Request $request |
91 | 91 | * @return array|WP_Error |
92 | 92 | */ |
93 | - public function get_items( $request ) { |
|
93 | + public function get_items($request) { |
|
94 | 94 | $data = array(); |
95 | 95 | $reports = $this->get_reports(); |
96 | 96 | |
97 | - foreach ( $reports as $report ) { |
|
98 | - $item = $this->prepare_item_for_response( (object) $report, $request ); |
|
99 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
97 | + foreach ($reports as $report) { |
|
98 | + $item = $this->prepare_item_for_response((object) $report, $request); |
|
99 | + $data[] = $this->prepare_response_for_collection($item); |
|
100 | 100 | } |
101 | 101 | |
102 | - return rest_ensure_response( $data ); |
|
102 | + return rest_ensure_response($data); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -109,26 +109,26 @@ discard block |
||
109 | 109 | * @param WP_REST_Request $request Request object. |
110 | 110 | * @return WP_REST_Response $response Response data. |
111 | 111 | */ |
112 | - public function prepare_item_for_response( $report, $request ) { |
|
112 | + public function prepare_item_for_response($report, $request) { |
|
113 | 113 | $data = array( |
114 | 114 | 'slug' => $report->slug, |
115 | 115 | 'description' => $report->description, |
116 | 116 | ); |
117 | 117 | |
118 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
119 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
120 | - $data = $this->filter_response_by_context( $data, $context ); |
|
118 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
119 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
120 | + $data = $this->filter_response_by_context($data, $context); |
|
121 | 121 | |
122 | 122 | // Wrap the data in a response object. |
123 | - $response = rest_ensure_response( $data ); |
|
124 | - $response->add_links( array( |
|
123 | + $response = rest_ensure_response($data); |
|
124 | + $response->add_links(array( |
|
125 | 125 | 'self' => array( |
126 | - 'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $report->slug ) ), |
|
126 | + 'href' => rest_url(sprintf('/%s/%s/%s', $this->namespace, $this->rest_base, $report->slug)), |
|
127 | 127 | ), |
128 | 128 | 'collection' => array( |
129 | - 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), |
|
129 | + 'href' => rest_url(sprintf('%s/%s', $this->namespace, $this->rest_base)), |
|
130 | 130 | ), |
131 | - ) ); |
|
131 | + )); |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * Filter a report returned from the API. |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param object $report The original report object. |
140 | 140 | * @param WP_REST_Request $request Request used to generate the response. |
141 | 141 | */ |
142 | - return apply_filters( 'woocommerce_rest_prepare_report', $response, $report, $request ); |
|
142 | + return apply_filters('woocommerce_rest_prepare_report', $response, $report, $request); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -154,21 +154,21 @@ discard block |
||
154 | 154 | 'type' => 'object', |
155 | 155 | 'properties' => array( |
156 | 156 | 'slug' => array( |
157 | - 'description' => __( 'An alphanumeric identifier for the resource.', 'woocommerce' ), |
|
157 | + 'description' => __('An alphanumeric identifier for the resource.', 'woocommerce'), |
|
158 | 158 | 'type' => 'string', |
159 | - 'context' => array( 'view' ), |
|
159 | + 'context' => array('view'), |
|
160 | 160 | 'readonly' => true, |
161 | 161 | ), |
162 | 162 | 'description' => array( |
163 | - 'description' => __( 'A human-readable description of the resource.', 'woocommerce' ), |
|
163 | + 'description' => __('A human-readable description of the resource.', 'woocommerce'), |
|
164 | 164 | 'type' => 'string', |
165 | - 'context' => array( 'view' ), |
|
165 | + 'context' => array('view'), |
|
166 | 166 | 'readonly' => true, |
167 | 167 | ), |
168 | 168 | ), |
169 | 169 | ); |
170 | 170 | |
171 | - return $this->add_additional_fields_schema( $schema ); |
|
171 | + return $this->add_additional_fields_schema($schema); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public function get_collection_params() { |
180 | 180 | return array( |
181 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
181 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
182 | 182 | ); |
183 | 183 | } |
184 | 184 | } |
@@ -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,73 +47,73 @@ discard block |
||
47 | 47 | * Register the routes for product attributes. |
48 | 48 | */ |
49 | 49 | public function register_routes() { |
50 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
50 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
51 | 51 | array( |
52 | 52 | 'methods' => WP_REST_Server::READABLE, |
53 | - 'callback' => array( $this, 'get_items' ), |
|
54 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
53 | + 'callback' => array($this, 'get_items'), |
|
54 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
55 | 55 | 'args' => $this->get_collection_params(), |
56 | 56 | ), |
57 | 57 | array( |
58 | 58 | 'methods' => WP_REST_Server::CREATABLE, |
59 | - 'callback' => array( $this, 'create_item' ), |
|
60 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
61 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
59 | + 'callback' => array($this, 'create_item'), |
|
60 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
61 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
62 | 62 | 'name' => array( |
63 | - 'description' => __( 'Name for the resource.', 'woocommerce' ), |
|
63 | + 'description' => __('Name for the resource.', 'woocommerce'), |
|
64 | 64 | 'type' => 'string', |
65 | 65 | 'required' => true, |
66 | 66 | ), |
67 | - ) ), |
|
67 | + )), |
|
68 | 68 | ), |
69 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
69 | + 'schema' => array($this, 'get_public_item_schema'), |
|
70 | 70 | )); |
71 | 71 | |
72 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
72 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
73 | 73 | 'args' => array( |
74 | 74 | 'id' => array( |
75 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
75 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
76 | 76 | 'type' => 'integer', |
77 | 77 | ), |
78 | 78 | ), |
79 | 79 | array( |
80 | 80 | 'methods' => WP_REST_Server::READABLE, |
81 | - 'callback' => array( $this, 'get_item' ), |
|
82 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
81 | + 'callback' => array($this, 'get_item'), |
|
82 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
83 | 83 | 'args' => array( |
84 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
84 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
85 | 85 | ), |
86 | 86 | ), |
87 | 87 | array( |
88 | 88 | 'methods' => WP_REST_Server::EDITABLE, |
89 | - 'callback' => array( $this, 'update_item' ), |
|
90 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
91 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
89 | + 'callback' => array($this, 'update_item'), |
|
90 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
91 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
92 | 92 | ), |
93 | 93 | array( |
94 | 94 | 'methods' => WP_REST_Server::DELETABLE, |
95 | - 'callback' => array( $this, 'delete_item' ), |
|
96 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
95 | + 'callback' => array($this, 'delete_item'), |
|
96 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
97 | 97 | 'args' => array( |
98 | 98 | 'force' => array( |
99 | 99 | 'default' => true, |
100 | 100 | 'type' => 'boolean', |
101 | - 'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ), |
|
101 | + 'description' => __('Required to be true, as resource does not support trashing.', 'woocommerce'), |
|
102 | 102 | ), |
103 | 103 | ), |
104 | 104 | ), |
105 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
106 | - ) ); |
|
105 | + 'schema' => array($this, 'get_public_item_schema'), |
|
106 | + )); |
|
107 | 107 | |
108 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
108 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
109 | 109 | array( |
110 | 110 | 'methods' => WP_REST_Server::EDITABLE, |
111 | - 'callback' => array( $this, 'batch_items' ), |
|
112 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
113 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
111 | + 'callback' => array($this, 'batch_items'), |
|
112 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
113 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
114 | 114 | ), |
115 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
116 | - ) ); |
|
115 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
116 | + )); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | * @param WP_REST_Request $request Full details about the request. |
123 | 123 | * @return WP_Error|boolean |
124 | 124 | */ |
125 | - public function get_items_permissions_check( $request ) { |
|
126 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) { |
|
127 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
125 | + public function get_items_permissions_check($request) { |
|
126 | + if ( ! wc_rest_check_manager_permissions('attributes', 'read')) { |
|
127 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return true; |
@@ -136,9 +136,9 @@ discard block |
||
136 | 136 | * @param WP_REST_Request $request Full details about the request. |
137 | 137 | * @return WP_Error|boolean |
138 | 138 | */ |
139 | - public function create_item_permissions_check( $request ) { |
|
140 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'create' ) ) { |
|
141 | - return new WP_Error( 'woocommerce_rest_cannot_create', __( 'Sorry, you cannot create new resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
139 | + public function create_item_permissions_check($request) { |
|
140 | + if ( ! wc_rest_check_manager_permissions('attributes', 'create')) { |
|
141 | + return new WP_Error('woocommerce_rest_cannot_create', __('Sorry, you cannot create new resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | return true; |
@@ -150,13 +150,13 @@ discard block |
||
150 | 150 | * @param WP_REST_Request $request Full details about the request. |
151 | 151 | * @return WP_Error|boolean |
152 | 152 | */ |
153 | - public function get_item_permissions_check( $request ) { |
|
154 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
155 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
153 | + public function get_item_permissions_check($request) { |
|
154 | + if ( ! $this->get_taxonomy($request)) { |
|
155 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
156 | 156 | } |
157 | 157 | |
158 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'read' ) ) { |
|
159 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
158 | + if ( ! wc_rest_check_manager_permissions('attributes', '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; |
@@ -168,13 +168,13 @@ discard block |
||
168 | 168 | * @param WP_REST_Request $request Full details about the request. |
169 | 169 | * @return WP_Error|boolean |
170 | 170 | */ |
171 | - public function update_item_permissions_check( $request ) { |
|
172 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
173 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
171 | + public function update_item_permissions_check($request) { |
|
172 | + if ( ! $this->get_taxonomy($request)) { |
|
173 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
174 | 174 | } |
175 | 175 | |
176 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'edit' ) ) { |
|
177 | - return new WP_Error( 'woocommerce_rest_cannot_update', __( 'Sorry, you cannot update resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
176 | + if ( ! wc_rest_check_manager_permissions('attributes', 'edit')) { |
|
177 | + return new WP_Error('woocommerce_rest_cannot_update', __('Sorry, you cannot update resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | return true; |
@@ -186,13 +186,13 @@ discard block |
||
186 | 186 | * @param WP_REST_Request $request Full details about the request. |
187 | 187 | * @return WP_Error|boolean |
188 | 188 | */ |
189 | - public function delete_item_permissions_check( $request ) { |
|
190 | - if ( ! $this->get_taxonomy( $request ) ) { |
|
191 | - return new WP_Error( 'woocommerce_rest_taxonomy_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
189 | + public function delete_item_permissions_check($request) { |
|
190 | + if ( ! $this->get_taxonomy($request)) { |
|
191 | + return new WP_Error('woocommerce_rest_taxonomy_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
192 | 192 | } |
193 | 193 | |
194 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'delete' ) ) { |
|
195 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
194 | + if ( ! wc_rest_check_manager_permissions('attributes', 'delete')) { |
|
195 | + return new WP_Error('woocommerce_rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | return true; |
@@ -205,9 +205,9 @@ discard block |
||
205 | 205 | * |
206 | 206 | * @return bool|WP_Error |
207 | 207 | */ |
208 | - public function batch_items_permissions_check( $request ) { |
|
209 | - if ( ! wc_rest_check_manager_permissions( 'attributes', 'batch' ) ) { |
|
210 | - 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() ) ); |
|
208 | + public function batch_items_permissions_check($request) { |
|
209 | + if ( ! wc_rest_check_manager_permissions('attributes', 'batch')) { |
|
210 | + 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())); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | return true; |
@@ -219,16 +219,16 @@ discard block |
||
219 | 219 | * @param WP_REST_Request $request |
220 | 220 | * @return array |
221 | 221 | */ |
222 | - public function get_items( $request ) { |
|
222 | + public function get_items($request) { |
|
223 | 223 | $attributes = wc_get_attribute_taxonomies(); |
224 | 224 | $data = array(); |
225 | - foreach ( $attributes as $attribute_obj ) { |
|
226 | - $attribute = $this->prepare_item_for_response( $attribute_obj, $request ); |
|
227 | - $attribute = $this->prepare_response_for_collection( $attribute ); |
|
225 | + foreach ($attributes as $attribute_obj) { |
|
226 | + $attribute = $this->prepare_item_for_response($attribute_obj, $request); |
|
227 | + $attribute = $this->prepare_response_for_collection($attribute); |
|
228 | 228 | $data[] = $attribute; |
229 | 229 | } |
230 | 230 | |
231 | - return rest_ensure_response( $data ); |
|
231 | + return rest_ensure_response($data); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -237,29 +237,29 @@ discard block |
||
237 | 237 | * @param WP_REST_Request $request Full details about the request. |
238 | 238 | * @return WP_REST_Request|WP_Error |
239 | 239 | */ |
240 | - public function create_item( $request ) { |
|
240 | + public function create_item($request) { |
|
241 | 241 | global $wpdb; |
242 | 242 | |
243 | - $id = wc_create_attribute( array( |
|
243 | + $id = wc_create_attribute(array( |
|
244 | 244 | 'name' => $request['name'], |
245 | - 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), |
|
246 | - 'type' => ! empty( $request['type'] ) ? $request['type'] : 'select', |
|
247 | - 'order_by' => ! empty( $request['order_by'] ) ? $request['order_by'] : 'menu_order', |
|
245 | + 'slug' => wc_sanitize_taxonomy_name(stripslashes($request['slug'])), |
|
246 | + 'type' => ! empty($request['type']) ? $request['type'] : 'select', |
|
247 | + 'order_by' => ! empty($request['order_by']) ? $request['order_by'] : 'menu_order', |
|
248 | 248 | 'has_archives' => true === $request['has_archives'], |
249 | - ) ); |
|
249 | + )); |
|
250 | 250 | |
251 | 251 | // Checks for errors. |
252 | - if ( is_wp_error( $id ) ) { |
|
253 | - return new WP_Error( 'woocommerce_rest_cannot_create', $id->get_error_message(), array( 'status' => 400 ) ); |
|
252 | + if (is_wp_error($id)) { |
|
253 | + return new WP_Error('woocommerce_rest_cannot_create', $id->get_error_message(), array('status' => 400)); |
|
254 | 254 | } |
255 | 255 | |
256 | - $attribute = $this->get_attribute( $id ); |
|
256 | + $attribute = $this->get_attribute($id); |
|
257 | 257 | |
258 | - if ( is_wp_error( $attribute ) ) { |
|
258 | + if (is_wp_error($attribute)) { |
|
259 | 259 | return $attribute; |
260 | 260 | } |
261 | 261 | |
262 | - $this->update_additional_fields_for_object( $attribute, $request ); |
|
262 | + $this->update_additional_fields_for_object($attribute, $request); |
|
263 | 263 | |
264 | 264 | /** |
265 | 265 | * Fires after a single product attribute is created or updated via the REST API. |
@@ -268,13 +268,13 @@ discard block |
||
268 | 268 | * @param WP_REST_Request $request Request object. |
269 | 269 | * @param boolean $creating True when creating attribute, false when updating. |
270 | 270 | */ |
271 | - do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, true ); |
|
271 | + do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, true); |
|
272 | 272 | |
273 | - $request->set_param( 'context', 'edit' ); |
|
274 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
275 | - $response = rest_ensure_response( $response ); |
|
276 | - $response->set_status( 201 ); |
|
277 | - $response->header( 'Location', rest_url( '/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id ) ); |
|
273 | + $request->set_param('context', 'edit'); |
|
274 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
275 | + $response = rest_ensure_response($response); |
|
276 | + $response->set_status(201); |
|
277 | + $response->header('Location', rest_url('/' . $this->namespace . '/' . $this->rest_base . '/' . $attribute->attribute_id)); |
|
278 | 278 | |
279 | 279 | return $response; |
280 | 280 | } |
@@ -285,16 +285,16 @@ discard block |
||
285 | 285 | * @param WP_REST_Request $request Full details about the request. |
286 | 286 | * @return WP_REST_Request|WP_Error |
287 | 287 | */ |
288 | - public function get_item( $request ) { |
|
289 | - $attribute = $this->get_attribute( (int) $request['id'] ); |
|
288 | + public function get_item($request) { |
|
289 | + $attribute = $this->get_attribute((int) $request['id']); |
|
290 | 290 | |
291 | - if ( is_wp_error( $attribute ) ) { |
|
291 | + if (is_wp_error($attribute)) { |
|
292 | 292 | return $attribute; |
293 | 293 | } |
294 | 294 | |
295 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
295 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
296 | 296 | |
297 | - return rest_ensure_response( $response ); |
|
297 | + return rest_ensure_response($response); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -303,30 +303,30 @@ discard block |
||
303 | 303 | * @param WP_REST_Request $request Full details about the request. |
304 | 304 | * @return WP_REST_Request|WP_Error |
305 | 305 | */ |
306 | - public function update_item( $request ) { |
|
306 | + public function update_item($request) { |
|
307 | 307 | global $wpdb; |
308 | 308 | |
309 | 309 | $id = (int) $request['id']; |
310 | - $edited = wc_update_attribute( $id, array( |
|
310 | + $edited = wc_update_attribute($id, array( |
|
311 | 311 | 'name' => $request['name'], |
312 | - 'slug' => wc_sanitize_taxonomy_name( stripslashes( $request['slug'] ) ), |
|
312 | + 'slug' => wc_sanitize_taxonomy_name(stripslashes($request['slug'])), |
|
313 | 313 | 'type' => $request['type'], |
314 | 314 | 'order_by' => $request['order_by'], |
315 | 315 | 'has_archives' => $request['has_archives'], |
316 | - ) ); |
|
316 | + )); |
|
317 | 317 | |
318 | 318 | // Checks for errors. |
319 | - if ( is_wp_error( $edited ) ) { |
|
320 | - return new WP_Error( 'woocommerce_rest_cannot_edit', $edited->get_error_message(), array( 'status' => 400 ) ); |
|
319 | + if (is_wp_error($edited)) { |
|
320 | + return new WP_Error('woocommerce_rest_cannot_edit', $edited->get_error_message(), array('status' => 400)); |
|
321 | 321 | } |
322 | 322 | |
323 | - $attribute = $this->get_attribute( $id ); |
|
323 | + $attribute = $this->get_attribute($id); |
|
324 | 324 | |
325 | - if ( is_wp_error( $attribute ) ) { |
|
325 | + if (is_wp_error($attribute)) { |
|
326 | 326 | return $attribute; |
327 | 327 | } |
328 | 328 | |
329 | - $this->update_additional_fields_for_object( $attribute, $request ); |
|
329 | + $this->update_additional_fields_for_object($attribute, $request); |
|
330 | 330 | |
331 | 331 | /** |
332 | 332 | * Fires after a single product attribute is created or updated via the REST API. |
@@ -335,12 +335,12 @@ discard block |
||
335 | 335 | * @param WP_REST_Request $request Request object. |
336 | 336 | * @param boolean $creating True when creating attribute, false when updating. |
337 | 337 | */ |
338 | - do_action( 'woocommerce_rest_insert_product_attribute', $attribute, $request, false ); |
|
338 | + do_action('woocommerce_rest_insert_product_attribute', $attribute, $request, false); |
|
339 | 339 | |
340 | - $request->set_param( 'context', 'edit' ); |
|
341 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
340 | + $request->set_param('context', 'edit'); |
|
341 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
342 | 342 | |
343 | - return rest_ensure_response( $response ); |
|
343 | + return rest_ensure_response($response); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -349,27 +349,27 @@ discard block |
||
349 | 349 | * @param WP_REST_Request $request Full details about the request. |
350 | 350 | * @return WP_REST_Response|WP_Error |
351 | 351 | */ |
352 | - public function delete_item( $request ) { |
|
353 | - $force = isset( $request['force'] ) ? (bool) $request['force'] : false; |
|
352 | + public function delete_item($request) { |
|
353 | + $force = isset($request['force']) ? (bool) $request['force'] : false; |
|
354 | 354 | |
355 | 355 | // We don't support trashing for this type, error out. |
356 | - if ( ! $force ) { |
|
357 | - return new WP_Error( 'woocommerce_rest_trash_not_supported', __( 'Resource does not support trashing.', 'woocommerce' ), array( 'status' => 501 ) ); |
|
356 | + if ( ! $force) { |
|
357 | + return new WP_Error('woocommerce_rest_trash_not_supported', __('Resource does not support trashing.', 'woocommerce'), array('status' => 501)); |
|
358 | 358 | } |
359 | 359 | |
360 | - $attribute = $this->get_attribute( (int) $request['id'] ); |
|
360 | + $attribute = $this->get_attribute((int) $request['id']); |
|
361 | 361 | |
362 | - if ( is_wp_error( $attribute ) ) { |
|
362 | + if (is_wp_error($attribute)) { |
|
363 | 363 | return $attribute; |
364 | 364 | } |
365 | 365 | |
366 | - $request->set_param( 'context', 'edit' ); |
|
367 | - $response = $this->prepare_item_for_response( $attribute, $request ); |
|
366 | + $request->set_param('context', 'edit'); |
|
367 | + $response = $this->prepare_item_for_response($attribute, $request); |
|
368 | 368 | |
369 | - $deleted = wc_delete_attribute( $attribute->attribute_id ); |
|
369 | + $deleted = wc_delete_attribute($attribute->attribute_id); |
|
370 | 370 | |
371 | - if ( false === $deleted ) { |
|
372 | - return new WP_Error( 'woocommerce_rest_cannot_delete', __( 'The resource cannot be deleted.', 'woocommerce' ), array( 'status' => 500 ) ); |
|
371 | + if (false === $deleted) { |
|
372 | + return new WP_Error('woocommerce_rest_cannot_delete', __('The resource cannot be deleted.', 'woocommerce'), array('status' => 500)); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | * @param WP_REST_Response $response The response data. |
380 | 380 | * @param WP_REST_Request $request The request sent to the API. |
381 | 381 | */ |
382 | - do_action( 'woocommerce_rest_delete_product_attribute', $attribute, $response, $request ); |
|
382 | + do_action('woocommerce_rest_delete_product_attribute', $attribute, $response, $request); |
|
383 | 383 | |
384 | 384 | return $response; |
385 | 385 | } |
@@ -391,23 +391,23 @@ discard block |
||
391 | 391 | * @param WP_REST_Request $request |
392 | 392 | * @return WP_REST_Response $response |
393 | 393 | */ |
394 | - public function prepare_item_for_response( $item, $request ) { |
|
394 | + public function prepare_item_for_response($item, $request) { |
|
395 | 395 | $data = array( |
396 | 396 | 'id' => (int) $item->attribute_id, |
397 | 397 | 'name' => $item->attribute_label, |
398 | - 'slug' => wc_attribute_taxonomy_name( $item->attribute_name ), |
|
398 | + 'slug' => wc_attribute_taxonomy_name($item->attribute_name), |
|
399 | 399 | 'type' => $item->attribute_type, |
400 | 400 | 'order_by' => $item->attribute_orderby, |
401 | 401 | 'has_archives' => (bool) $item->attribute_public, |
402 | 402 | ); |
403 | 403 | |
404 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
405 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
406 | - $data = $this->filter_response_by_context( $data, $context ); |
|
404 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
405 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
406 | + $data = $this->filter_response_by_context($data, $context); |
|
407 | 407 | |
408 | - $response = rest_ensure_response( $data ); |
|
408 | + $response = rest_ensure_response($data); |
|
409 | 409 | |
410 | - $response->add_links( $this->prepare_links( $item ) ); |
|
410 | + $response->add_links($this->prepare_links($item)); |
|
411 | 411 | |
412 | 412 | /** |
413 | 413 | * Filter a attribute item returned from the API. |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | * @param object $item The original attribute object. |
419 | 419 | * @param WP_REST_Request $request Request used to generate the response. |
420 | 420 | */ |
421 | - return apply_filters( 'woocommerce_rest_prepare_product_attribute', $response, $item, $request ); |
|
421 | + return apply_filters('woocommerce_rest_prepare_product_attribute', $response, $item, $request); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | /** |
@@ -427,14 +427,14 @@ discard block |
||
427 | 427 | * @param object $attribute Attribute object. |
428 | 428 | * @return array Links for the given attribute. |
429 | 429 | */ |
430 | - protected function prepare_links( $attribute ) { |
|
430 | + protected function prepare_links($attribute) { |
|
431 | 431 | $base = '/' . $this->namespace . '/' . $this->rest_base; |
432 | 432 | $links = array( |
433 | 433 | 'self' => array( |
434 | - 'href' => rest_url( trailingslashit( $base ) . $attribute->attribute_id ), |
|
434 | + 'href' => rest_url(trailingslashit($base) . $attribute->attribute_id), |
|
435 | 435 | ), |
436 | 436 | 'collection' => array( |
437 | - 'href' => rest_url( $base ), |
|
437 | + 'href' => rest_url($base), |
|
438 | 438 | ), |
439 | 439 | ); |
440 | 440 | |
@@ -453,51 +453,51 @@ discard block |
||
453 | 453 | 'type' => 'object', |
454 | 454 | 'properties' => array( |
455 | 455 | 'id' => array( |
456 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
456 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
457 | 457 | 'type' => 'integer', |
458 | - 'context' => array( 'view', 'edit' ), |
|
458 | + 'context' => array('view', 'edit'), |
|
459 | 459 | 'readonly' => true, |
460 | 460 | ), |
461 | 461 | 'name' => array( |
462 | - 'description' => __( 'Attribute name.', 'woocommerce' ), |
|
462 | + 'description' => __('Attribute name.', 'woocommerce'), |
|
463 | 463 | 'type' => 'string', |
464 | - 'context' => array( 'view', 'edit' ), |
|
464 | + 'context' => array('view', 'edit'), |
|
465 | 465 | 'arg_options' => array( |
466 | 466 | 'sanitize_callback' => 'sanitize_text_field', |
467 | 467 | ), |
468 | 468 | ), |
469 | 469 | 'slug' => array( |
470 | - 'description' => __( 'An alphanumeric identifier for the resource unique to its type.', 'woocommerce' ), |
|
470 | + 'description' => __('An alphanumeric identifier for the resource unique to its type.', 'woocommerce'), |
|
471 | 471 | 'type' => 'string', |
472 | - 'context' => array( 'view', 'edit' ), |
|
472 | + 'context' => array('view', 'edit'), |
|
473 | 473 | 'arg_options' => array( |
474 | 474 | 'sanitize_callback' => 'sanitize_title', |
475 | 475 | ), |
476 | 476 | ), |
477 | 477 | 'type' => array( |
478 | - 'description' => __( 'Type of attribute.', 'woocommerce' ), |
|
478 | + 'description' => __('Type of attribute.', 'woocommerce'), |
|
479 | 479 | 'type' => 'string', |
480 | 480 | 'default' => 'select', |
481 | - 'enum' => array_keys( wc_get_attribute_types() ), |
|
482 | - 'context' => array( 'view', 'edit' ), |
|
481 | + 'enum' => array_keys(wc_get_attribute_types()), |
|
482 | + 'context' => array('view', 'edit'), |
|
483 | 483 | ), |
484 | 484 | 'order_by' => array( |
485 | - 'description' => __( 'Default sort order.', 'woocommerce' ), |
|
485 | + 'description' => __('Default sort order.', 'woocommerce'), |
|
486 | 486 | 'type' => 'string', |
487 | 487 | 'default' => 'menu_order', |
488 | - 'enum' => array( 'menu_order', 'name', 'name_num', 'id' ), |
|
489 | - 'context' => array( 'view', 'edit' ), |
|
488 | + 'enum' => array('menu_order', 'name', 'name_num', 'id'), |
|
489 | + 'context' => array('view', 'edit'), |
|
490 | 490 | ), |
491 | 491 | 'has_archives' => array( |
492 | - 'description' => __( 'Enable/Disable attribute archives.', 'woocommerce' ), |
|
492 | + 'description' => __('Enable/Disable attribute archives.', 'woocommerce'), |
|
493 | 493 | 'type' => 'boolean', |
494 | 494 | 'default' => false, |
495 | - 'context' => array( 'view', 'edit' ), |
|
495 | + 'context' => array('view', 'edit'), |
|
496 | 496 | ), |
497 | 497 | ), |
498 | 498 | ); |
499 | 499 | |
500 | - return $this->add_additional_fields_schema( $schema ); |
|
500 | + return $this->add_additional_fields_schema($schema); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | */ |
508 | 508 | public function get_collection_params() { |
509 | 509 | $params = array(); |
510 | - $params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); |
|
510 | + $params['context'] = $this->get_context_param(array('default' => 'view')); |
|
511 | 511 | |
512 | 512 | return $params; |
513 | 513 | } |
@@ -518,13 +518,13 @@ discard block |
||
518 | 518 | * @param WP_REST_Request $request Full details about the request. |
519 | 519 | * @return string |
520 | 520 | */ |
521 | - protected function get_taxonomy( $request ) { |
|
522 | - if ( '' !== $this->attribute ) { |
|
521 | + protected function get_taxonomy($request) { |
|
522 | + if ('' !== $this->attribute) { |
|
523 | 523 | return $this->attribute; |
524 | 524 | } |
525 | 525 | |
526 | - if ( $request['id'] ) { |
|
527 | - $name = wc_attribute_taxonomy_name_by_id( (int) $request['id'] ); |
|
526 | + if ($request['id']) { |
|
527 | + $name = wc_attribute_taxonomy_name_by_id((int) $request['id']); |
|
528 | 528 | |
529 | 529 | $this->attribute = $name; |
530 | 530 | } |
@@ -538,17 +538,17 @@ discard block |
||
538 | 538 | * @param int $id Attribute ID. |
539 | 539 | * @return stdClass|WP_Error |
540 | 540 | */ |
541 | - protected function get_attribute( $id ) { |
|
541 | + protected function get_attribute($id) { |
|
542 | 542 | global $wpdb; |
543 | 543 | |
544 | - $attribute = $wpdb->get_row( $wpdb->prepare( " |
|
544 | + $attribute = $wpdb->get_row($wpdb->prepare(" |
|
545 | 545 | SELECT * |
546 | 546 | FROM {$wpdb->prefix}woocommerce_attribute_taxonomies |
547 | 547 | WHERE attribute_id = %d |
548 | - ", $id ) ); |
|
548 | + ", $id)); |
|
549 | 549 | |
550 | - if ( is_wp_error( $attribute ) || is_null( $attribute ) ) { |
|
551 | - return new WP_Error( 'woocommerce_rest_attribute_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); |
|
550 | + if (is_wp_error($attribute) || is_null($attribute)) { |
|
551 | + return new WP_Error('woocommerce_rest_attribute_invalid', __('Resource does not exist.', 'woocommerce'), array('status' => 404)); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | return $attribute; |
@@ -562,13 +562,13 @@ discard block |
||
562 | 562 | * @param bool $new_data |
563 | 563 | * @return bool|WP_Error |
564 | 564 | */ |
565 | - protected function validate_attribute_slug( $slug, $new_data = true ) { |
|
566 | - if ( strlen( $slug ) >= 28 ) { |
|
567 | - return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf( __( 'Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
568 | - } elseif ( wc_check_if_attribute_name_is_reserved( $slug ) ) { |
|
569 | - return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
570 | - } elseif ( $new_data && taxonomy_exists( wc_attribute_taxonomy_name( $slug ) ) ) { |
|
571 | - return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) ); |
|
565 | + protected function validate_attribute_slug($slug, $new_data = true) { |
|
566 | + if (strlen($slug) >= 28) { |
|
567 | + return new WP_Error('woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf(__('Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
568 | + } elseif (wc_check_if_attribute_name_is_reserved($slug)) { |
|
569 | + return new WP_Error('woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf(__('Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
570 | + } elseif ($new_data && taxonomy_exists(wc_attribute_taxonomy_name($slug))) { |
|
571 | + return new WP_Error('woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf(__('Slug "%s" is already in use. Change it, please.', 'woocommerce'), $slug), array('status' => 400)); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | return true; |
@@ -581,6 +581,6 @@ discard block |
||
581 | 581 | * @since 3.0.0 |
582 | 582 | */ |
583 | 583 | protected function flush_rewrite_rules() { |
584 | - wp_schedule_single_event( time(), 'woocommerce_flush_rewrite_rules' ); |
|
584 | + wp_schedule_single_event(time(), 'woocommerce_flush_rewrite_rules'); |
|
585 | 585 | } |
586 | 586 | } |
@@ -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,15 +47,15 @@ discard block |
||
47 | 47 | * Register the routes for sales reports. |
48 | 48 | */ |
49 | 49 | public function register_routes() { |
50 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
50 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
51 | 51 | array( |
52 | 52 | 'methods' => WP_REST_Server::READABLE, |
53 | - 'callback' => array( $this, 'get_items' ), |
|
54 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
53 | + 'callback' => array($this, 'get_items'), |
|
54 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
55 | 55 | 'args' => $this->get_collection_params(), |
56 | 56 | ), |
57 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
58 | - ) ); |
|
57 | + 'schema' => array($this, 'get_public_item_schema'), |
|
58 | + )); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * @param WP_REST_Request $request Full details about the request. |
65 | 65 | * @return WP_Error|boolean |
66 | 66 | */ |
67 | - public function get_items_permissions_check( $request ) { |
|
68 | - if ( ! wc_rest_check_manager_permissions( 'reports', 'read' ) ) { |
|
69 | - return new WP_Error( 'woocommerce_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
|
67 | + public function get_items_permissions_check($request) { |
|
68 | + if ( ! wc_rest_check_manager_permissions('reports', 'read')) { |
|
69 | + return new WP_Error('woocommerce_rest_cannot_view', __('Sorry, you cannot list resources.', 'woocommerce'), array('status' => rest_authorization_required_code())); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return true; |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | * @param WP_REST_Request $request |
79 | 79 | * @return array|WP_Error |
80 | 80 | */ |
81 | - public function get_items( $request ) { |
|
81 | + public function get_items($request) { |
|
82 | 82 | $data = array(); |
83 | - $item = $this->prepare_item_for_response( null, $request ); |
|
84 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
83 | + $item = $this->prepare_item_for_response(null, $request); |
|
84 | + $data[] = $this->prepare_response_for_collection($item); |
|
85 | 85 | |
86 | - return rest_ensure_response( $data ); |
|
86 | + return rest_ensure_response($data); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -93,109 +93,109 @@ discard block |
||
93 | 93 | * @param WP_REST_Request $request Request object. |
94 | 94 | * @return WP_REST_Response $response Response data. |
95 | 95 | */ |
96 | - public function prepare_item_for_response( $_, $request ) { |
|
96 | + public function prepare_item_for_response($_, $request) { |
|
97 | 97 | // Set date filtering. |
98 | 98 | $filter = array( |
99 | 99 | 'period' => $request['period'], |
100 | 100 | 'date_min' => $request['date_min'], |
101 | 101 | 'date_max' => $request['date_max'], |
102 | 102 | ); |
103 | - $this->setup_report( $filter ); |
|
103 | + $this->setup_report($filter); |
|
104 | 104 | |
105 | 105 | // New customers. |
106 | 106 | $users_query = new WP_User_Query( |
107 | 107 | array( |
108 | - 'fields' => array( 'user_registered' ), |
|
108 | + 'fields' => array('user_registered'), |
|
109 | 109 | 'role' => 'customer', |
110 | 110 | ) |
111 | 111 | ); |
112 | 112 | |
113 | 113 | $customers = $users_query->get_results(); |
114 | 114 | |
115 | - foreach ( $customers as $key => $customer ) { |
|
116 | - if ( strtotime( $customer->user_registered ) < $this->report->start_date || strtotime( $customer->user_registered ) > $this->report->end_date ) { |
|
117 | - unset( $customers[ $key ] ); |
|
115 | + foreach ($customers as $key => $customer) { |
|
116 | + if (strtotime($customer->user_registered) < $this->report->start_date || strtotime($customer->user_registered) > $this->report->end_date) { |
|
117 | + unset($customers[$key]); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | - $total_customers = count( $customers ); |
|
121 | + $total_customers = count($customers); |
|
122 | 122 | $report_data = $this->report->get_report_data(); |
123 | 123 | $period_totals = array(); |
124 | 124 | |
125 | 125 | // Setup period totals by ensuring each period in the interval has data. |
126 | - for ( $i = 0; $i <= $this->report->chart_interval; $i++ ) { |
|
126 | + for ($i = 0; $i <= $this->report->chart_interval; $i++) { |
|
127 | 127 | |
128 | - switch ( $this->report->chart_groupby ) { |
|
128 | + switch ($this->report->chart_groupby) { |
|
129 | 129 | case 'day' : |
130 | - $time = date( 'Y-m-d', strtotime( "+{$i} DAY", $this->report->start_date ) ); |
|
130 | + $time = date('Y-m-d', strtotime("+{$i} DAY", $this->report->start_date)); |
|
131 | 131 | break; |
132 | 132 | default : |
133 | - $time = date( 'Y-m', strtotime( "+{$i} MONTH", $this->report->start_date ) ); |
|
133 | + $time = date('Y-m', strtotime("+{$i} MONTH", $this->report->start_date)); |
|
134 | 134 | break; |
135 | 135 | } |
136 | 136 | |
137 | 137 | // Set the customer signups for each period. |
138 | 138 | $customer_count = 0; |
139 | - foreach ( $customers as $customer ) { |
|
140 | - if ( date( ( 'day' == $this->report->chart_groupby ) ? 'Y-m-d' : 'Y-m', strtotime( $customer->user_registered ) ) == $time ) { |
|
139 | + foreach ($customers as $customer) { |
|
140 | + if (date(('day' == $this->report->chart_groupby) ? 'Y-m-d' : 'Y-m', strtotime($customer->user_registered)) == $time) { |
|
141 | 141 | $customer_count++; |
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | - $period_totals[ $time ] = array( |
|
146 | - 'sales' => wc_format_decimal( 0.00, 2 ), |
|
145 | + $period_totals[$time] = array( |
|
146 | + 'sales' => wc_format_decimal(0.00, 2), |
|
147 | 147 | 'orders' => 0, |
148 | 148 | 'items' => 0, |
149 | - 'tax' => wc_format_decimal( 0.00, 2 ), |
|
150 | - 'shipping' => wc_format_decimal( 0.00, 2 ), |
|
151 | - 'discount' => wc_format_decimal( 0.00, 2 ), |
|
149 | + 'tax' => wc_format_decimal(0.00, 2), |
|
150 | + 'shipping' => wc_format_decimal(0.00, 2), |
|
151 | + 'discount' => wc_format_decimal(0.00, 2), |
|
152 | 152 | 'customers' => $customer_count, |
153 | 153 | ); |
154 | 154 | } |
155 | 155 | |
156 | 156 | // add total sales, total order count, total tax and total shipping for each period |
157 | - foreach ( $report_data->orders as $order ) { |
|
158 | - $time = ( 'day' === $this->report->chart_groupby ) ? date( 'Y-m-d', strtotime( $order->post_date ) ) : date( 'Y-m', strtotime( $order->post_date ) ); |
|
157 | + foreach ($report_data->orders as $order) { |
|
158 | + $time = ('day' === $this->report->chart_groupby) ? date('Y-m-d', strtotime($order->post_date)) : date('Y-m', strtotime($order->post_date)); |
|
159 | 159 | |
160 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
160 | + if ( ! isset($period_totals[$time])) { |
|
161 | 161 | continue; |
162 | 162 | } |
163 | 163 | |
164 | - $period_totals[ $time ]['sales'] = wc_format_decimal( $order->total_sales, 2 ); |
|
165 | - $period_totals[ $time ]['tax'] = wc_format_decimal( $order->total_tax + $order->total_shipping_tax, 2 ); |
|
166 | - $period_totals[ $time ]['shipping'] = wc_format_decimal( $order->total_shipping, 2 ); |
|
164 | + $period_totals[$time]['sales'] = wc_format_decimal($order->total_sales, 2); |
|
165 | + $period_totals[$time]['tax'] = wc_format_decimal($order->total_tax + $order->total_shipping_tax, 2); |
|
166 | + $period_totals[$time]['shipping'] = wc_format_decimal($order->total_shipping, 2); |
|
167 | 167 | } |
168 | 168 | |
169 | - foreach ( $report_data->order_counts as $order ) { |
|
170 | - $time = ( 'day' === $this->report->chart_groupby ) ? date( 'Y-m-d', strtotime( $order->post_date ) ) : date( 'Y-m', strtotime( $order->post_date ) ); |
|
169 | + foreach ($report_data->order_counts as $order) { |
|
170 | + $time = ('day' === $this->report->chart_groupby) ? date('Y-m-d', strtotime($order->post_date)) : date('Y-m', strtotime($order->post_date)); |
|
171 | 171 | |
172 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
172 | + if ( ! isset($period_totals[$time])) { |
|
173 | 173 | continue; |
174 | 174 | } |
175 | 175 | |
176 | - $period_totals[ $time ]['orders'] = (int) $order->count; |
|
176 | + $period_totals[$time]['orders'] = (int) $order->count; |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | // Add total order items for each period. |
180 | - foreach ( $report_data->order_items as $order_item ) { |
|
181 | - $time = ( 'day' === $this->report->chart_groupby ) ? date( 'Y-m-d', strtotime( $order_item->post_date ) ) : date( 'Y-m', strtotime( $order_item->post_date ) ); |
|
180 | + foreach ($report_data->order_items as $order_item) { |
|
181 | + $time = ('day' === $this->report->chart_groupby) ? date('Y-m-d', strtotime($order_item->post_date)) : date('Y-m', strtotime($order_item->post_date)); |
|
182 | 182 | |
183 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
183 | + if ( ! isset($period_totals[$time])) { |
|
184 | 184 | continue; |
185 | 185 | } |
186 | 186 | |
187 | - $period_totals[ $time ]['items'] = (int) $order_item->order_item_count; |
|
187 | + $period_totals[$time]['items'] = (int) $order_item->order_item_count; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | // Add total discount for each period. |
191 | - foreach ( $report_data->coupons as $discount ) { |
|
192 | - $time = ( 'day' === $this->report->chart_groupby ) ? date( 'Y-m-d', strtotime( $discount->post_date ) ) : date( 'Y-m', strtotime( $discount->post_date ) ); |
|
191 | + foreach ($report_data->coupons as $discount) { |
|
192 | + $time = ('day' === $this->report->chart_groupby) ? date('Y-m-d', strtotime($discount->post_date)) : date('Y-m', strtotime($discount->post_date)); |
|
193 | 193 | |
194 | - if ( ! isset( $period_totals[ $time ] ) ) { |
|
194 | + if ( ! isset($period_totals[$time])) { |
|
195 | 195 | continue; |
196 | 196 | } |
197 | 197 | |
198 | - $period_totals[ $time ]['discount'] = wc_format_decimal( $discount->discount_amount, 2 ); |
|
198 | + $period_totals[$time]['discount'] = wc_format_decimal($discount->discount_amount, 2); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | $sales_data = array( |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | 'average_sales' => $report_data->average_sales, |
205 | 205 | 'total_orders' => $report_data->total_orders, |
206 | 206 | 'total_items' => $report_data->total_items, |
207 | - 'total_tax' => wc_format_decimal( $report_data->total_tax + $report_data->total_shipping_tax, 2 ), |
|
207 | + 'total_tax' => wc_format_decimal($report_data->total_tax + $report_data->total_shipping_tax, 2), |
|
208 | 208 | 'total_shipping' => $report_data->total_shipping, |
209 | 209 | 'total_refunds' => $report_data->total_refunds, |
210 | 210 | 'total_discount' => $report_data->total_coupons, |
@@ -213,17 +213,17 @@ discard block |
||
213 | 213 | 'total_customers' => $total_customers, |
214 | 214 | ); |
215 | 215 | |
216 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
217 | - $data = $this->add_additional_fields_to_object( $sales_data, $request ); |
|
218 | - $data = $this->filter_response_by_context( $data, $context ); |
|
216 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
217 | + $data = $this->add_additional_fields_to_object($sales_data, $request); |
|
218 | + $data = $this->filter_response_by_context($data, $context); |
|
219 | 219 | |
220 | 220 | // Wrap the data in a response object. |
221 | - $response = rest_ensure_response( $data ); |
|
222 | - $response->add_links( array( |
|
221 | + $response = rest_ensure_response($data); |
|
222 | + $response->add_links(array( |
|
223 | 223 | 'about' => array( |
224 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
224 | + 'href' => rest_url(sprintf('%s/reports', $this->namespace)), |
|
225 | 225 | ), |
226 | - ) ); |
|
226 | + )); |
|
227 | 227 | |
228 | 228 | /** |
229 | 229 | * Filter a report sales returned from the API. |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @param stdClass $data The original report object. |
235 | 235 | * @param WP_REST_Request $request Request used to generate the response. |
236 | 236 | */ |
237 | - return apply_filters( 'woocommerce_rest_prepare_report_sales', $response, (object) $sales_data, $request ); |
|
237 | + return apply_filters('woocommerce_rest_prepare_report_sales', $response, (object) $sales_data, $request); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -242,37 +242,37 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @param array $filter date filtering |
244 | 244 | */ |
245 | - protected function setup_report( $filter ) { |
|
246 | - include_once( WC()->plugin_path() . '/includes/admin/reports/class-wc-admin-report.php' ); |
|
247 | - include_once( WC()->plugin_path() . '/includes/admin/reports/class-wc-report-sales-by-date.php' ); |
|
245 | + protected function setup_report($filter) { |
|
246 | + include_once(WC()->plugin_path() . '/includes/admin/reports/class-wc-admin-report.php'); |
|
247 | + include_once(WC()->plugin_path() . '/includes/admin/reports/class-wc-report-sales-by-date.php'); |
|
248 | 248 | |
249 | 249 | $this->report = new WC_Report_Sales_By_Date(); |
250 | 250 | |
251 | - if ( empty( $filter['period'] ) ) { |
|
251 | + if (empty($filter['period'])) { |
|
252 | 252 | // Custom date range. |
253 | 253 | $filter['period'] = 'custom'; |
254 | 254 | |
255 | - if ( ! empty( $filter['date_min'] ) || ! empty( $filter['date_max'] ) ) { |
|
255 | + if ( ! empty($filter['date_min']) || ! empty($filter['date_max'])) { |
|
256 | 256 | |
257 | 257 | // Overwrite _GET to make use of WC_Admin_Report::calculate_current_range() for custom date ranges. |
258 | 258 | $_GET['start_date'] = $filter['date_min']; |
259 | - $_GET['end_date'] = isset( $filter['date_max'] ) ? $filter['date_max'] : null; |
|
259 | + $_GET['end_date'] = isset($filter['date_max']) ? $filter['date_max'] : null; |
|
260 | 260 | |
261 | 261 | } else { |
262 | 262 | |
263 | 263 | // Default custom range to today. |
264 | - $_GET['start_date'] = $_GET['end_date'] = date( 'Y-m-d', current_time( 'timestamp' ) ); |
|
264 | + $_GET['start_date'] = $_GET['end_date'] = date('Y-m-d', current_time('timestamp')); |
|
265 | 265 | } |
266 | 266 | } else { |
267 | - $filter['period'] = empty( $filter['period'] ) ? 'week' : $filter['period']; |
|
267 | + $filter['period'] = empty($filter['period']) ? 'week' : $filter['period']; |
|
268 | 268 | |
269 | 269 | // Change "week" period to "7day". |
270 | - if ( 'week' === $filter['period'] ) { |
|
270 | + if ('week' === $filter['period']) { |
|
271 | 271 | $filter['period'] = '7day'; |
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
275 | - $this->report->calculate_current_range( $filter['period'] ); |
|
275 | + $this->report->calculate_current_range($filter['period']); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -287,78 +287,78 @@ discard block |
||
287 | 287 | 'type' => 'object', |
288 | 288 | 'properties' => array( |
289 | 289 | 'total_sales' => array( |
290 | - 'description' => __( 'Gross sales in the period.', 'woocommerce' ), |
|
290 | + 'description' => __('Gross sales in the period.', 'woocommerce'), |
|
291 | 291 | 'type' => 'string', |
292 | - 'context' => array( 'view' ), |
|
292 | + 'context' => array('view'), |
|
293 | 293 | 'readonly' => true, |
294 | 294 | ), |
295 | 295 | 'net_sales' => array( |
296 | - 'description' => __( 'Net sales in the period.', 'woocommerce' ), |
|
296 | + 'description' => __('Net sales in the period.', 'woocommerce'), |
|
297 | 297 | 'type' => 'string', |
298 | - 'context' => array( 'view' ), |
|
298 | + 'context' => array('view'), |
|
299 | 299 | 'readonly' => true, |
300 | 300 | ), |
301 | 301 | 'average_sales' => array( |
302 | - 'description' => __( 'Average net daily sales.', 'woocommerce' ), |
|
302 | + 'description' => __('Average net daily sales.', 'woocommerce'), |
|
303 | 303 | 'type' => 'string', |
304 | - 'context' => array( 'view' ), |
|
304 | + 'context' => array('view'), |
|
305 | 305 | 'readonly' => true, |
306 | 306 | ), |
307 | 307 | 'total_orders' => array( |
308 | - 'description' => __( 'Total of orders placed.', 'woocommerce' ), |
|
308 | + 'description' => __('Total of orders placed.', 'woocommerce'), |
|
309 | 309 | 'type' => 'integer', |
310 | - 'context' => array( 'view' ), |
|
310 | + 'context' => array('view'), |
|
311 | 311 | 'readonly' => true, |
312 | 312 | ), |
313 | 313 | 'total_items' => array( |
314 | - 'description' => __( 'Total of items purchased.', 'woocommerce' ), |
|
314 | + 'description' => __('Total of items purchased.', 'woocommerce'), |
|
315 | 315 | 'type' => 'integer', |
316 | - 'context' => array( 'view' ), |
|
316 | + 'context' => array('view'), |
|
317 | 317 | 'readonly' => true, |
318 | 318 | ), |
319 | 319 | 'total_tax' => array( |
320 | - 'description' => __( 'Total charged for taxes.', 'woocommerce' ), |
|
320 | + 'description' => __('Total charged for taxes.', 'woocommerce'), |
|
321 | 321 | 'type' => 'string', |
322 | - 'context' => array( 'view' ), |
|
322 | + 'context' => array('view'), |
|
323 | 323 | 'readonly' => true, |
324 | 324 | ), |
325 | 325 | 'total_shipping' => array( |
326 | - 'description' => __( 'Total charged for shipping.', 'woocommerce' ), |
|
326 | + 'description' => __('Total charged for shipping.', 'woocommerce'), |
|
327 | 327 | 'type' => 'string', |
328 | - 'context' => array( 'view' ), |
|
328 | + 'context' => array('view'), |
|
329 | 329 | 'readonly' => true, |
330 | 330 | ), |
331 | 331 | 'total_refunds' => array( |
332 | - 'description' => __( 'Total of refunded orders.', 'woocommerce' ), |
|
332 | + 'description' => __('Total of refunded orders.', 'woocommerce'), |
|
333 | 333 | 'type' => 'integer', |
334 | - 'context' => array( 'view' ), |
|
334 | + 'context' => array('view'), |
|
335 | 335 | 'readonly' => true, |
336 | 336 | ), |
337 | 337 | 'total_discount' => array( |
338 | - 'description' => __( 'Total of coupons used.', 'woocommerce' ), |
|
338 | + 'description' => __('Total of coupons used.', 'woocommerce'), |
|
339 | 339 | 'type' => 'integer', |
340 | - 'context' => array( 'view' ), |
|
340 | + 'context' => array('view'), |
|
341 | 341 | 'readonly' => true, |
342 | 342 | ), |
343 | 343 | 'totals_grouped_by' => array( |
344 | - 'description' => __( 'Group type.', 'woocommerce' ), |
|
344 | + 'description' => __('Group type.', 'woocommerce'), |
|
345 | 345 | 'type' => 'string', |
346 | - 'context' => array( 'view' ), |
|
346 | + 'context' => array('view'), |
|
347 | 347 | 'readonly' => true, |
348 | 348 | ), |
349 | 349 | 'totals' => array( |
350 | - 'description' => __( 'Totals.', 'woocommerce' ), |
|
350 | + 'description' => __('Totals.', 'woocommerce'), |
|
351 | 351 | 'type' => 'array', |
352 | 352 | 'items' => array( |
353 | 353 | 'type' => 'array', |
354 | 354 | ), |
355 | - 'context' => array( 'view' ), |
|
355 | + 'context' => array('view'), |
|
356 | 356 | 'readonly' => true, |
357 | 357 | ), |
358 | 358 | ), |
359 | 359 | ); |
360 | 360 | |
361 | - return $this->add_additional_fields_schema( $schema ); |
|
361 | + return $this->add_additional_fields_schema($schema); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function get_collection_params() { |
370 | 370 | return array( |
371 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
371 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
372 | 372 | 'period' => array( |
373 | - 'description' => __( 'Report period.', 'woocommerce' ), |
|
373 | + 'description' => __('Report period.', 'woocommerce'), |
|
374 | 374 | 'type' => 'string', |
375 | - 'enum' => array( 'week', 'month', 'last_month', 'year' ), |
|
375 | + 'enum' => array('week', 'month', 'last_month', 'year'), |
|
376 | 376 | 'validate_callback' => 'rest_validate_request_arg', |
377 | 377 | 'sanitize_callback' => 'sanitize_text_field', |
378 | 378 | ), |
379 | 379 | 'date_min' => array( |
380 | 380 | /* translators: %s: date format */ |
381 | - 'description' => sprintf( __( 'Return sales for a specific start date, the date need to be in the %s format.', 'woocommerce' ), 'YYYY-MM-DD' ), |
|
381 | + 'description' => sprintf(__('Return sales for a specific start date, the date need to be in the %s format.', 'woocommerce'), 'YYYY-MM-DD'), |
|
382 | 382 | 'type' => 'string', |
383 | 383 | 'format' => 'date', |
384 | 384 | 'validate_callback' => 'wc_rest_validate_reports_request_arg', |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | ), |
387 | 387 | 'date_max' => array( |
388 | 388 | /* translators: %s: date format */ |
389 | - 'description' => sprintf( __( 'Return sales for a specific end date, the date need to be in the %s format.', 'woocommerce' ), 'YYYY-MM-DD' ), |
|
389 | + 'description' => sprintf(__('Return sales for a specific end date, the date need to be in the %s format.', 'woocommerce'), 'YYYY-MM-DD'), |
|
390 | 390 | 'type' => 'string', |
391 | 391 | 'format' => 'date', |
392 | 392 | 'validate_callback' => 'wc_rest_validate_reports_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 | |
@@ -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' => __( 'Shipping class name.', 'woocommerce' ), |
|
100 | + 'description' => __('Shipping class 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 | |
@@ -47,80 +47,80 @@ discard block |
||
47 | 47 | * Coupons actions. |
48 | 48 | */ |
49 | 49 | public function __construct() { |
50 | - add_filter( "woocommerce_rest_{$this->post_type}_query", array( $this, 'query_args' ), 10, 2 ); |
|
50 | + add_filter("woocommerce_rest_{$this->post_type}_query", array($this, 'query_args'), 10, 2); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Register the routes for coupons. |
55 | 55 | */ |
56 | 56 | public function register_routes() { |
57 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
57 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
58 | 58 | array( |
59 | 59 | 'methods' => WP_REST_Server::READABLE, |
60 | - 'callback' => array( $this, 'get_items' ), |
|
61 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
60 | + 'callback' => array($this, 'get_items'), |
|
61 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
62 | 62 | 'args' => $this->get_collection_params(), |
63 | 63 | ), |
64 | 64 | array( |
65 | 65 | 'methods' => WP_REST_Server::CREATABLE, |
66 | - 'callback' => array( $this, 'create_item' ), |
|
67 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
68 | - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( |
|
66 | + 'callback' => array($this, 'create_item'), |
|
67 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
68 | + 'args' => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array( |
|
69 | 69 | 'code' => array( |
70 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
70 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
71 | 71 | 'required' => true, |
72 | 72 | 'type' => 'string', |
73 | 73 | ), |
74 | - ) ), |
|
74 | + )), |
|
75 | 75 | ), |
76 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
77 | - ) ); |
|
76 | + 'schema' => array($this, 'get_public_item_schema'), |
|
77 | + )); |
|
78 | 78 | |
79 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
79 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array( |
|
80 | 80 | 'args' => array( |
81 | 81 | 'id' => array( |
82 | - 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
|
82 | + 'description' => __('Unique identifier for the resource.', 'woocommerce'), |
|
83 | 83 | 'type' => 'integer', |
84 | 84 | ), |
85 | 85 | ), |
86 | 86 | array( |
87 | 87 | 'methods' => WP_REST_Server::READABLE, |
88 | - 'callback' => array( $this, 'get_item' ), |
|
89 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
88 | + 'callback' => array($this, 'get_item'), |
|
89 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
90 | 90 | 'args' => array( |
91 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
91 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
92 | 92 | ), |
93 | 93 | ), |
94 | 94 | array( |
95 | 95 | 'methods' => WP_REST_Server::EDITABLE, |
96 | - 'callback' => array( $this, 'update_item' ), |
|
97 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
98 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
96 | + 'callback' => array($this, 'update_item'), |
|
97 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
98 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
99 | 99 | ), |
100 | 100 | array( |
101 | 101 | 'methods' => WP_REST_Server::DELETABLE, |
102 | - 'callback' => array( $this, 'delete_item' ), |
|
103 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
102 | + 'callback' => array($this, 'delete_item'), |
|
103 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
104 | 104 | 'args' => array( |
105 | 105 | 'force' => array( |
106 | 106 | 'default' => false, |
107 | 107 | 'type' => 'boolean', |
108 | - 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
|
108 | + 'description' => __('Whether to bypass trash and force deletion.', 'woocommerce'), |
|
109 | 109 | ), |
110 | 110 | ), |
111 | 111 | ), |
112 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
113 | - ) ); |
|
112 | + 'schema' => array($this, 'get_public_item_schema'), |
|
113 | + )); |
|
114 | 114 | |
115 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array( |
|
115 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/batch', array( |
|
116 | 116 | array( |
117 | 117 | 'methods' => WP_REST_Server::EDITABLE, |
118 | - 'callback' => array( $this, 'batch_items' ), |
|
119 | - 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
|
120 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
118 | + 'callback' => array($this, 'batch_items'), |
|
119 | + 'permission_callback' => array($this, 'batch_items_permissions_check'), |
|
120 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
121 | 121 | ), |
122 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
123 | - ) ); |
|
122 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
123 | + )); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -130,10 +130,10 @@ discard block |
||
130 | 130 | * @param WP_REST_Request $request Request data. |
131 | 131 | * @return array |
132 | 132 | */ |
133 | - public function query_args( $args, $request ) { |
|
134 | - if ( ! empty( $request['code'] ) ) { |
|
135 | - $id = wc_get_coupon_id_by_code( $request['code'] ); |
|
136 | - $args['post__in'] = array( $id ); |
|
133 | + public function query_args($args, $request) { |
|
134 | + if ( ! empty($request['code'])) { |
|
135 | + $id = wc_get_coupon_id_by_code($request['code']); |
|
136 | + $args['post__in'] = array($id); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $args; |
@@ -146,31 +146,31 @@ discard block |
||
146 | 146 | * @param WP_REST_Request $request Request object. |
147 | 147 | * @return WP_REST_Response $data |
148 | 148 | */ |
149 | - public function prepare_item_for_response( $post, $request ) { |
|
150 | - $coupon = new WC_Coupon( (int) $post->ID ); |
|
149 | + public function prepare_item_for_response($post, $request) { |
|
150 | + $coupon = new WC_Coupon((int) $post->ID); |
|
151 | 151 | $_data = $coupon->get_data(); |
152 | 152 | |
153 | - $format_decimal = array( 'amount', 'minimum_amount', 'maximum_amount' ); |
|
154 | - $format_date = array( 'date_created', 'date_modified' ); |
|
155 | - $format_date_utc = array( 'date_expires' ); |
|
156 | - $format_null = array( 'usage_limit', 'usage_limit_per_user' ); |
|
153 | + $format_decimal = array('amount', 'minimum_amount', 'maximum_amount'); |
|
154 | + $format_date = array('date_created', 'date_modified'); |
|
155 | + $format_date_utc = array('date_expires'); |
|
156 | + $format_null = array('usage_limit', 'usage_limit_per_user'); |
|
157 | 157 | |
158 | 158 | // Format decimal values. |
159 | - foreach ( $format_decimal as $key ) { |
|
160 | - $_data[ $key ] = wc_format_decimal( $_data[ $key ], 2 ); |
|
159 | + foreach ($format_decimal as $key) { |
|
160 | + $_data[$key] = wc_format_decimal($_data[$key], 2); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | // Format date values. |
164 | - foreach ( $format_date as $key ) { |
|
165 | - $_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ], false ) : null; |
|
164 | + foreach ($format_date as $key) { |
|
165 | + $_data[$key] = $_data[$key] ? wc_rest_prepare_date_response($_data[$key], false) : null; |
|
166 | 166 | } |
167 | - foreach ( $format_date_utc as $key ) { |
|
168 | - $_data[ $key ] = $_data[ $key ] ? wc_rest_prepare_date_response( $_data[ $key ] ) : null; |
|
167 | + foreach ($format_date_utc as $key) { |
|
168 | + $_data[$key] = $_data[$key] ? wc_rest_prepare_date_response($_data[$key]) : null; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // Format null values. |
172 | - foreach ( $format_null as $key ) { |
|
173 | - $_data[ $key ] = $_data[ $key ] ? $_data[ $key ] : null; |
|
172 | + foreach ($format_null as $key) { |
|
173 | + $_data[$key] = $_data[$key] ? $_data[$key] : null; |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | $data = array( |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | 'used_by' => $_data['used_by'], |
200 | 200 | ); |
201 | 201 | |
202 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
203 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
204 | - $data = $this->filter_response_by_context( $data, $context ); |
|
205 | - $response = rest_ensure_response( $data ); |
|
206 | - $response->add_links( $this->prepare_links( $post, $request ) ); |
|
202 | + $context = ! empty($request['context']) ? $request['context'] : 'view'; |
|
203 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
204 | + $data = $this->filter_response_by_context($data, $context); |
|
205 | + $response = rest_ensure_response($data); |
|
206 | + $response->add_links($this->prepare_links($post, $request)); |
|
207 | 207 | |
208 | 208 | /** |
209 | 209 | * Filter the data for a response. |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @param WP_Post $post Post object. |
216 | 216 | * @param WP_REST_Request $request Request object. |
217 | 217 | */ |
218 | - return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request ); |
|
218 | + return apply_filters("woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * @param array $schema |
224 | 224 | * @return bool |
225 | 225 | */ |
226 | - protected function filter_writable_props( $schema ) { |
|
227 | - return empty( $schema['readonly'] ); |
|
226 | + protected function filter_writable_props($schema) { |
|
227 | + return empty($schema['readonly']); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -233,53 +233,53 @@ discard block |
||
233 | 233 | * @param WP_REST_Request $request Request object. |
234 | 234 | * @return WP_Error|stdClass $data Post object. |
235 | 235 | */ |
236 | - protected function prepare_item_for_database( $request ) { |
|
237 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
238 | - $coupon = new WC_Coupon( $id ); |
|
236 | + protected function prepare_item_for_database($request) { |
|
237 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
238 | + $coupon = new WC_Coupon($id); |
|
239 | 239 | $schema = $this->get_item_schema(); |
240 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
240 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
241 | 241 | |
242 | 242 | // Update to schema to make compatible with CRUD schema. |
243 | - if ( $request['exclude_product_ids'] ) { |
|
243 | + if ($request['exclude_product_ids']) { |
|
244 | 244 | $request['excluded_product_ids'] = $request['exclude_product_ids']; |
245 | 245 | } |
246 | - if ( $request['expiry_date'] ) { |
|
246 | + if ($request['expiry_date']) { |
|
247 | 247 | $request['date_expires'] = $request['expiry_date']; |
248 | 248 | } |
249 | 249 | |
250 | 250 | // Validate required POST fields. |
251 | - if ( 'POST' === $request->get_method() && 0 === $coupon->get_id() ) { |
|
252 | - if ( empty( $request['code'] ) ) { |
|
253 | - return new WP_Error( 'woocommerce_rest_empty_coupon_code', sprintf( __( 'The coupon code cannot be empty.', 'woocommerce' ), 'code' ), array( 'status' => 400 ) ); |
|
251 | + if ('POST' === $request->get_method() && 0 === $coupon->get_id()) { |
|
252 | + if (empty($request['code'])) { |
|
253 | + return new WP_Error('woocommerce_rest_empty_coupon_code', sprintf(__('The coupon code cannot be empty.', 'woocommerce'), 'code'), array('status' => 400)); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
257 | 257 | // Handle all writable props. |
258 | - foreach ( $data_keys as $key ) { |
|
259 | - $value = $request[ $key ]; |
|
258 | + foreach ($data_keys as $key) { |
|
259 | + $value = $request[$key]; |
|
260 | 260 | |
261 | - if ( ! is_null( $value ) ) { |
|
262 | - switch ( $key ) { |
|
261 | + if ( ! is_null($value)) { |
|
262 | + switch ($key) { |
|
263 | 263 | case 'code' : |
264 | - $coupon_code = wc_format_coupon_code( $value ); |
|
264 | + $coupon_code = wc_format_coupon_code($value); |
|
265 | 265 | $id = $coupon->get_id() ? $coupon->get_id() : 0; |
266 | - $id_from_code = wc_get_coupon_id_by_code( $coupon_code, $id ); |
|
266 | + $id_from_code = wc_get_coupon_id_by_code($coupon_code, $id); |
|
267 | 267 | |
268 | - if ( $id_from_code ) { |
|
269 | - return new WP_Error( 'woocommerce_rest_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce' ), array( 'status' => 400 ) ); |
|
268 | + if ($id_from_code) { |
|
269 | + return new WP_Error('woocommerce_rest_coupon_code_already_exists', __('The coupon code already exists', 'woocommerce'), array('status' => 400)); |
|
270 | 270 | } |
271 | 271 | |
272 | - $coupon->set_code( $coupon_code ); |
|
272 | + $coupon->set_code($coupon_code); |
|
273 | 273 | break; |
274 | 274 | case 'description' : |
275 | - $coupon->set_description( wp_filter_post_kses( $value ) ); |
|
275 | + $coupon->set_description(wp_filter_post_kses($value)); |
|
276 | 276 | break; |
277 | 277 | case 'expiry_date' : |
278 | - $coupon->set_date_expires( $value ); |
|
278 | + $coupon->set_date_expires($value); |
|
279 | 279 | break; |
280 | 280 | default : |
281 | - if ( is_callable( array( $coupon, "set_{$key}" ) ) ) { |
|
282 | - $coupon->{"set_{$key}"}( $value ); |
|
281 | + if (is_callable(array($coupon, "set_{$key}"))) { |
|
282 | + $coupon->{"set_{$key}"}($value); |
|
283 | 283 | } |
284 | 284 | break; |
285 | 285 | } |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * @param WC_Coupon $coupon The coupon object. |
296 | 296 | * @param WP_REST_Request $request Request object. |
297 | 297 | */ |
298 | - return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $coupon, $request ); |
|
298 | + return apply_filters("woocommerce_rest_pre_insert_{$this->post_type}", $coupon, $request); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -304,21 +304,21 @@ discard block |
||
304 | 304 | * @param WP_REST_Request $request Full details about the request. |
305 | 305 | * @return WP_Error|WP_REST_Response |
306 | 306 | */ |
307 | - public function create_item( $request ) { |
|
308 | - if ( ! empty( $request['id'] ) ) { |
|
307 | + public function create_item($request) { |
|
308 | + if ( ! empty($request['id'])) { |
|
309 | 309 | /* translators: %s: post type */ |
310 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_exists", sprintf( __( 'Cannot create existing %s.', 'woocommerce' ), $this->post_type ), array( 'status' => 400 ) ); |
|
310 | + return new WP_Error("woocommerce_rest_{$this->post_type}_exists", sprintf(__('Cannot create existing %s.', 'woocommerce'), $this->post_type), array('status' => 400)); |
|
311 | 311 | } |
312 | 312 | |
313 | - $coupon_id = $this->save_coupon( $request ); |
|
314 | - if ( is_wp_error( $coupon_id ) ) { |
|
313 | + $coupon_id = $this->save_coupon($request); |
|
314 | + if (is_wp_error($coupon_id)) { |
|
315 | 315 | return $coupon_id; |
316 | 316 | } |
317 | 317 | |
318 | - $post = get_post( $coupon_id ); |
|
319 | - $this->update_additional_fields_for_object( $post, $request ); |
|
318 | + $post = get_post($coupon_id); |
|
319 | + $this->update_additional_fields_for_object($post, $request); |
|
320 | 320 | |
321 | - $this->add_post_meta_fields( $post, $request ); |
|
321 | + $this->add_post_meta_fields($post, $request); |
|
322 | 322 | |
323 | 323 | /** |
324 | 324 | * Fires after a single item is created or updated via the REST API. |
@@ -327,12 +327,12 @@ discard block |
||
327 | 327 | * @param WP_REST_Request $request Request object. |
328 | 328 | * @param boolean $creating True when creating item, false when updating. |
329 | 329 | */ |
330 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, true ); |
|
331 | - $request->set_param( 'context', 'edit' ); |
|
332 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
333 | - $response = rest_ensure_response( $response ); |
|
334 | - $response->set_status( 201 ); |
|
335 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID ) ) ); |
|
330 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, true); |
|
331 | + $request->set_param('context', 'edit'); |
|
332 | + $response = $this->prepare_item_for_response($post, $request); |
|
333 | + $response = rest_ensure_response($response); |
|
334 | + $response->set_status(201); |
|
335 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $post->ID))); |
|
336 | 336 | |
337 | 337 | return $response; |
338 | 338 | } |
@@ -343,21 +343,21 @@ discard block |
||
343 | 343 | * @param WP_REST_Request $request Full details about the request. |
344 | 344 | * @return WP_Error|WP_REST_Response |
345 | 345 | */ |
346 | - public function update_item( $request ) { |
|
346 | + public function update_item($request) { |
|
347 | 347 | try { |
348 | 348 | $post_id = (int) $request['id']; |
349 | 349 | |
350 | - if ( empty( $post_id ) || get_post_type( $post_id ) !== $this->post_type ) { |
|
351 | - return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
350 | + if (empty($post_id) || get_post_type($post_id) !== $this->post_type) { |
|
351 | + return new WP_Error("woocommerce_rest_{$this->post_type}_invalid_id", __('ID is invalid.', 'woocommerce'), array('status' => 400)); |
|
352 | 352 | } |
353 | 353 | |
354 | - $coupon_id = $this->save_coupon( $request ); |
|
355 | - if ( is_wp_error( $coupon_id ) ) { |
|
354 | + $coupon_id = $this->save_coupon($request); |
|
355 | + if (is_wp_error($coupon_id)) { |
|
356 | 356 | return $coupon_id; |
357 | 357 | } |
358 | 358 | |
359 | - $post = get_post( $coupon_id ); |
|
360 | - $this->update_additional_fields_for_object( $post, $request ); |
|
359 | + $post = get_post($coupon_id); |
|
360 | + $this->update_additional_fields_for_object($post, $request); |
|
361 | 361 | |
362 | 362 | /** |
363 | 363 | * Fires after a single item is created or updated via the REST API. |
@@ -366,13 +366,13 @@ discard block |
||
366 | 366 | * @param WP_REST_Request $request Request object. |
367 | 367 | * @param boolean $creating True when creating item, false when updating. |
368 | 368 | */ |
369 | - do_action( "woocommerce_rest_insert_{$this->post_type}", $post, $request, false ); |
|
370 | - $request->set_param( 'context', 'edit' ); |
|
371 | - $response = $this->prepare_item_for_response( $post, $request ); |
|
372 | - return rest_ensure_response( $response ); |
|
369 | + do_action("woocommerce_rest_insert_{$this->post_type}", $post, $request, false); |
|
370 | + $request->set_param('context', 'edit'); |
|
371 | + $response = $this->prepare_item_for_response($post, $request); |
|
372 | + return rest_ensure_response($response); |
|
373 | 373 | |
374 | - } catch ( Exception $e ) { |
|
375 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
374 | + } catch (Exception $e) { |
|
375 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
376 | 376 | } |
377 | 377 | } |
378 | 378 | |
@@ -383,20 +383,20 @@ discard block |
||
383 | 383 | * @param WP_REST_Request $request Full details about the request. |
384 | 384 | * @return WP_Error|int |
385 | 385 | */ |
386 | - protected function save_coupon( $request ) { |
|
386 | + protected function save_coupon($request) { |
|
387 | 387 | try { |
388 | - $coupon = $this->prepare_item_for_database( $request ); |
|
388 | + $coupon = $this->prepare_item_for_database($request); |
|
389 | 389 | |
390 | - if ( is_wp_error( $coupon ) ) { |
|
390 | + if (is_wp_error($coupon)) { |
|
391 | 391 | return $coupon; |
392 | 392 | } |
393 | 393 | |
394 | 394 | $coupon->save(); |
395 | 395 | return $coupon->get_id(); |
396 | - } catch ( WC_Data_Exception $e ) { |
|
397 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); |
|
398 | - } catch ( WC_REST_Exception $e ) { |
|
399 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
396 | + } catch (WC_Data_Exception $e) { |
|
397 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), $e->getErrorData()); |
|
398 | + } catch (WC_REST_Exception $e) { |
|
399 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
@@ -412,152 +412,152 @@ discard block |
||
412 | 412 | 'type' => 'object', |
413 | 413 | 'properties' => array( |
414 | 414 | 'id' => array( |
415 | - 'description' => __( 'Unique identifier for the object.', 'woocommerce' ), |
|
415 | + 'description' => __('Unique identifier for the object.', 'woocommerce'), |
|
416 | 416 | 'type' => 'integer', |
417 | - 'context' => array( 'view', 'edit' ), |
|
417 | + 'context' => array('view', 'edit'), |
|
418 | 418 | 'readonly' => true, |
419 | 419 | ), |
420 | 420 | 'code' => array( |
421 | - 'description' => __( 'Coupon code.', 'woocommerce' ), |
|
421 | + 'description' => __('Coupon code.', 'woocommerce'), |
|
422 | 422 | 'type' => 'string', |
423 | - 'context' => array( 'view', 'edit' ), |
|
423 | + 'context' => array('view', 'edit'), |
|
424 | 424 | ), |
425 | 425 | 'date_created' => array( |
426 | - 'description' => __( "The date the coupon was created, in the site's timezone.", 'woocommerce' ), |
|
426 | + 'description' => __("The date the coupon was created, in the site's timezone.", 'woocommerce'), |
|
427 | 427 | 'type' => 'date-time', |
428 | - 'context' => array( 'view', 'edit' ), |
|
428 | + 'context' => array('view', 'edit'), |
|
429 | 429 | 'readonly' => true, |
430 | 430 | ), |
431 | 431 | 'date_modified' => array( |
432 | - 'description' => __( "The date the coupon was last modified, in the site's timezone.", 'woocommerce' ), |
|
432 | + 'description' => __("The date the coupon was last modified, in the site's timezone.", 'woocommerce'), |
|
433 | 433 | 'type' => 'date-time', |
434 | - 'context' => array( 'view', 'edit' ), |
|
434 | + 'context' => array('view', 'edit'), |
|
435 | 435 | 'readonly' => true, |
436 | 436 | ), |
437 | 437 | 'description' => array( |
438 | - 'description' => __( 'Coupon description.', 'woocommerce' ), |
|
438 | + 'description' => __('Coupon description.', 'woocommerce'), |
|
439 | 439 | 'type' => 'string', |
440 | - 'context' => array( 'view', 'edit' ), |
|
440 | + 'context' => array('view', 'edit'), |
|
441 | 441 | ), |
442 | 442 | 'discount_type' => array( |
443 | - 'description' => __( 'Determines the type of discount that will be applied.', 'woocommerce' ), |
|
443 | + 'description' => __('Determines the type of discount that will be applied.', 'woocommerce'), |
|
444 | 444 | 'type' => 'string', |
445 | 445 | 'default' => 'fixed_cart', |
446 | - 'enum' => array_keys( wc_get_coupon_types() ), |
|
447 | - 'context' => array( 'view', 'edit' ), |
|
446 | + 'enum' => array_keys(wc_get_coupon_types()), |
|
447 | + 'context' => array('view', 'edit'), |
|
448 | 448 | ), |
449 | 449 | 'amount' => array( |
450 | - 'description' => __( 'The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce' ), |
|
450 | + 'description' => __('The amount of discount. Should always be numeric, even if setting a percentage.', 'woocommerce'), |
|
451 | 451 | 'type' => 'string', |
452 | - 'context' => array( 'view', 'edit' ), |
|
452 | + 'context' => array('view', 'edit'), |
|
453 | 453 | ), |
454 | 454 | 'expiry_date' => array( |
455 | - 'description' => __( 'UTC DateTime when the coupon expires.', 'woocommerce' ), |
|
455 | + 'description' => __('UTC DateTime when the coupon expires.', 'woocommerce'), |
|
456 | 456 | 'type' => 'string', |
457 | - 'context' => array( 'view', 'edit' ), |
|
457 | + 'context' => array('view', 'edit'), |
|
458 | 458 | ), |
459 | 459 | 'usage_count' => array( |
460 | - 'description' => __( 'Number of times the coupon has been used already.', 'woocommerce' ), |
|
460 | + 'description' => __('Number of times the coupon has been used already.', 'woocommerce'), |
|
461 | 461 | 'type' => 'integer', |
462 | - 'context' => array( 'view', 'edit' ), |
|
462 | + 'context' => array('view', 'edit'), |
|
463 | 463 | 'readonly' => true, |
464 | 464 | ), |
465 | 465 | 'individual_use' => array( |
466 | - 'description' => __( 'If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce' ), |
|
466 | + 'description' => __('If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.', 'woocommerce'), |
|
467 | 467 | 'type' => 'boolean', |
468 | 468 | 'default' => false, |
469 | - 'context' => array( 'view', 'edit' ), |
|
469 | + 'context' => array('view', 'edit'), |
|
470 | 470 | ), |
471 | 471 | 'product_ids' => array( |
472 | - 'description' => __( "List of product IDs the coupon can be used on.", 'woocommerce' ), |
|
472 | + 'description' => __("List of product IDs the coupon can be used on.", 'woocommerce'), |
|
473 | 473 | 'type' => 'array', |
474 | 474 | 'items' => array( |
475 | 475 | 'type' => 'integer', |
476 | 476 | ), |
477 | - 'context' => array( 'view', 'edit' ), |
|
477 | + 'context' => array('view', 'edit'), |
|
478 | 478 | ), |
479 | 479 | 'exclude_product_ids' => array( |
480 | - 'description' => __( "List of product IDs the coupon cannot be used on.", 'woocommerce' ), |
|
480 | + 'description' => __("List of product IDs the coupon cannot be used on.", 'woocommerce'), |
|
481 | 481 | 'type' => 'array', |
482 | 482 | 'items' => array( |
483 | 483 | 'type' => 'integer', |
484 | 484 | ), |
485 | - 'context' => array( 'view', 'edit' ), |
|
485 | + 'context' => array('view', 'edit'), |
|
486 | 486 | ), |
487 | 487 | 'usage_limit' => array( |
488 | - 'description' => __( 'How many times the coupon can be used in total.', 'woocommerce' ), |
|
488 | + 'description' => __('How many times the coupon can be used in total.', 'woocommerce'), |
|
489 | 489 | 'type' => 'integer', |
490 | - 'context' => array( 'view', 'edit' ), |
|
490 | + 'context' => array('view', 'edit'), |
|
491 | 491 | ), |
492 | 492 | 'usage_limit_per_user' => array( |
493 | - 'description' => __( 'How many times the coupon can be used per customer.', 'woocommerce' ), |
|
493 | + 'description' => __('How many times the coupon can be used per customer.', 'woocommerce'), |
|
494 | 494 | 'type' => 'integer', |
495 | - 'context' => array( 'view', 'edit' ), |
|
495 | + 'context' => array('view', 'edit'), |
|
496 | 496 | ), |
497 | 497 | 'limit_usage_to_x_items' => array( |
498 | - 'description' => __( 'Max number of items in the cart the coupon can be applied to.', 'woocommerce' ), |
|
498 | + 'description' => __('Max number of items in the cart the coupon can be applied to.', 'woocommerce'), |
|
499 | 499 | 'type' => 'integer', |
500 | - 'context' => array( 'view', 'edit' ), |
|
500 | + 'context' => array('view', 'edit'), |
|
501 | 501 | ), |
502 | 502 | 'free_shipping' => array( |
503 | - 'description' => __( 'If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce' ), |
|
503 | + 'description' => __('If true and if the free shipping method requires a coupon, this coupon will enable free shipping.', 'woocommerce'), |
|
504 | 504 | 'type' => 'boolean', |
505 | 505 | 'default' => false, |
506 | - 'context' => array( 'view', 'edit' ), |
|
506 | + 'context' => array('view', 'edit'), |
|
507 | 507 | ), |
508 | 508 | 'product_categories' => array( |
509 | - 'description' => __( "List of category IDs the coupon applies to.", 'woocommerce' ), |
|
509 | + 'description' => __("List of category IDs the coupon applies to.", 'woocommerce'), |
|
510 | 510 | 'type' => 'array', |
511 | 511 | 'items' => array( |
512 | 512 | 'type' => 'integer', |
513 | 513 | ), |
514 | - 'context' => array( 'view', 'edit' ), |
|
514 | + 'context' => array('view', 'edit'), |
|
515 | 515 | ), |
516 | 516 | 'excluded_product_categories' => array( |
517 | - 'description' => __( "List of category IDs the coupon does not apply to.", 'woocommerce' ), |
|
517 | + 'description' => __("List of category IDs the coupon does not apply to.", 'woocommerce'), |
|
518 | 518 | 'type' => 'array', |
519 | 519 | 'items' => array( |
520 | 520 | 'type' => 'integer', |
521 | 521 | ), |
522 | - 'context' => array( 'view', 'edit' ), |
|
522 | + 'context' => array('view', 'edit'), |
|
523 | 523 | ), |
524 | 524 | 'exclude_sale_items' => array( |
525 | - 'description' => __( 'If true, this coupon will not be applied to items that have sale prices.', 'woocommerce' ), |
|
525 | + 'description' => __('If true, this coupon will not be applied to items that have sale prices.', 'woocommerce'), |
|
526 | 526 | 'type' => 'boolean', |
527 | 527 | 'default' => false, |
528 | - 'context' => array( 'view', 'edit' ), |
|
528 | + 'context' => array('view', 'edit'), |
|
529 | 529 | ), |
530 | 530 | 'minimum_amount' => array( |
531 | - 'description' => __( 'Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce' ), |
|
531 | + 'description' => __('Minimum order amount that needs to be in the cart before coupon applies.', 'woocommerce'), |
|
532 | 532 | 'type' => 'string', |
533 | - 'context' => array( 'view', 'edit' ), |
|
533 | + 'context' => array('view', 'edit'), |
|
534 | 534 | ), |
535 | 535 | 'maximum_amount' => array( |
536 | - 'description' => __( 'Maximum order amount allowed when using the coupon.', 'woocommerce' ), |
|
536 | + 'description' => __('Maximum order amount allowed when using the coupon.', 'woocommerce'), |
|
537 | 537 | 'type' => 'string', |
538 | - 'context' => array( 'view', 'edit' ), |
|
538 | + 'context' => array('view', 'edit'), |
|
539 | 539 | ), |
540 | 540 | 'email_restrictions' => array( |
541 | - 'description' => __( 'List of email addresses that can use this coupon.', 'woocommerce' ), |
|
541 | + 'description' => __('List of email addresses that can use this coupon.', 'woocommerce'), |
|
542 | 542 | 'type' => 'array', |
543 | 543 | 'items' => array( |
544 | 544 | 'type' => 'string', |
545 | 545 | ), |
546 | - 'context' => array( 'view', 'edit' ), |
|
546 | + 'context' => array('view', 'edit'), |
|
547 | 547 | ), |
548 | 548 | 'used_by' => array( |
549 | - 'description' => __( 'List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce' ), |
|
549 | + 'description' => __('List of user IDs (or guest email addresses) that have used the coupon.', 'woocommerce'), |
|
550 | 550 | 'type' => 'array', |
551 | 551 | 'items' => array( |
552 | 552 | 'type' => 'integer', |
553 | 553 | ), |
554 | - 'context' => array( 'view', 'edit' ), |
|
554 | + 'context' => array('view', 'edit'), |
|
555 | 555 | 'readonly' => true, |
556 | 556 | ), |
557 | 557 | ), |
558 | 558 | ); |
559 | 559 | |
560 | - return $this->add_additional_fields_schema( $schema ); |
|
560 | + return $this->add_additional_fields_schema($schema); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | $params = parent::get_collection_params(); |
570 | 570 | |
571 | 571 | $params['code'] = array( |
572 | - 'description' => __( 'Limit result set to resources with a specific code.', 'woocommerce' ), |
|
572 | + 'description' => __('Limit result set to resources with a specific code.', 'woocommerce'), |
|
573 | 573 | 'type' => 'string', |
574 | 574 | 'sanitize_callback' => 'sanitize_text_field', |
575 | 575 | 'validate_callback' => 'rest_validate_request_arg', |