@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
10 | 10 | class WPInv_Item extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'item'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'item'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'item'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Item Data array. This is the core item data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'parent_id' => 0, |
|
34 | - 'status' => 'draft', |
|
35 | - 'version' => '', |
|
36 | - 'date_created' => null, |
|
27 | + * Item Data array. This is the core item data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'parent_id' => 0, |
|
34 | + 'status' => 'draft', |
|
35 | + 'version' => '', |
|
36 | + 'date_created' => null, |
|
37 | 37 | 'date_modified' => null, |
38 | 38 | 'name' => '', |
39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | ); |
59 | 59 | |
60 | 60 | /** |
61 | - * Stores meta in cache for future reads. |
|
62 | - * |
|
63 | - * A group must be set to to enable caching. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - protected $cache_group = 'getpaid_items'; |
|
61 | + * Stores meta in cache for future reads. |
|
62 | + * |
|
63 | + * A group must be set to to enable caching. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + protected $cache_group = 'getpaid_items'; |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
74 | 74 | protected $post = null; |
75 | 75 | |
76 | 76 | /** |
77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | - * |
|
79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | - */ |
|
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
83 | - |
|
84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | - $this->set_id( $item_id ); |
|
92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | - $this->set_id( $item_id ); |
|
94 | - } else { |
|
95 | - $this->set_object_read( true ); |
|
96 | - } |
|
77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | + * |
|
79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | + */ |
|
81 | + public function __construct( $item = 0 ) { |
|
82 | + parent::__construct( $item ); |
|
83 | + |
|
84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | + $this->set_id( $item ); |
|
86 | + } elseif ( $item instanceof self ) { |
|
87 | + $this->set_id( $item->get_id() ); |
|
88 | + } elseif ( ! empty( $item->ID ) ) { |
|
89 | + $this->set_id( $item->ID ); |
|
90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | + $this->set_id( $item_id ); |
|
92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | + $this->set_id( $item_id ); |
|
94 | + } else { |
|
95 | + $this->set_object_read( true ); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | // Load the datastore. |
99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
100 | 100 | |
101 | - if ( $this->get_id() > 0 ) { |
|
101 | + if ( $this->get_id() > 0 ) { |
|
102 | 102 | $this->post = get_post( $this->get_id() ); |
103 | 103 | $this->ID = $this->get_id(); |
104 | - $this->data_store->read( $this ); |
|
104 | + $this->data_store->read( $this ); |
|
105 | 105 | } |
106 | 106 | |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | 109 | /* |
110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,401 +122,401 @@ discard block |
||
122 | 122 | */ |
123 | 123 | |
124 | 124 | /** |
125 | - * Get parent item ID. |
|
126 | - * |
|
127 | - * @since 1.0.19 |
|
128 | - * @param string $context View or edit context. |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function get_parent_id( $context = 'view' ) { |
|
132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
125 | + * Get parent item ID. |
|
126 | + * |
|
127 | + * @since 1.0.19 |
|
128 | + * @param string $context View or edit context. |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function get_parent_id( $context = 'view' ) { |
|
132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Get item status. |
|
137 | - * |
|
138 | - * @since 1.0.19 |
|
139 | - * @param string $context View or edit context. |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function get_status( $context = 'view' ) { |
|
143 | - return $this->get_prop( 'status', $context ); |
|
136 | + * Get item status. |
|
137 | + * |
|
138 | + * @since 1.0.19 |
|
139 | + * @param string $context View or edit context. |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function get_status( $context = 'view' ) { |
|
143 | + return $this->get_prop( 'status', $context ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * Get plugin version when the item was created. |
|
148 | - * |
|
149 | - * @since 1.0.19 |
|
150 | - * @param string $context View or edit context. |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public function get_version( $context = 'view' ) { |
|
154 | - return $this->get_prop( 'version', $context ); |
|
147 | + * Get plugin version when the item was created. |
|
148 | + * |
|
149 | + * @since 1.0.19 |
|
150 | + * @param string $context View or edit context. |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public function get_version( $context = 'view' ) { |
|
154 | + return $this->get_prop( 'version', $context ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | - * Get date when the item was created. |
|
159 | - * |
|
160 | - * @since 1.0.19 |
|
161 | - * @param string $context View or edit context. |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - public function get_date_created( $context = 'view' ) { |
|
165 | - return $this->get_prop( 'date_created', $context ); |
|
158 | + * Get date when the item was created. |
|
159 | + * |
|
160 | + * @since 1.0.19 |
|
161 | + * @param string $context View or edit context. |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + public function get_date_created( $context = 'view' ) { |
|
165 | + return $this->get_prop( 'date_created', $context ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | - * Get GMT date when the item was created. |
|
170 | - * |
|
171 | - * @since 1.0.19 |
|
172 | - * @param string $context View or edit context. |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
169 | + * Get GMT date when the item was created. |
|
170 | + * |
|
171 | + * @since 1.0.19 |
|
172 | + * @param string $context View or edit context. |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
176 | 176 | $date = $this->get_date_created( $context ); |
177 | 177 | |
178 | 178 | if ( $date ) { |
179 | 179 | $date = get_gmt_from_date( $date ); |
180 | 180 | } |
181 | - return $date; |
|
181 | + return $date; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Get date when the item was last modified. |
|
186 | - * |
|
187 | - * @since 1.0.19 |
|
188 | - * @param string $context View or edit context. |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public function get_date_modified( $context = 'view' ) { |
|
192 | - return $this->get_prop( 'date_modified', $context ); |
|
185 | + * Get date when the item was last modified. |
|
186 | + * |
|
187 | + * @since 1.0.19 |
|
188 | + * @param string $context View or edit context. |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public function get_date_modified( $context = 'view' ) { |
|
192 | + return $this->get_prop( 'date_modified', $context ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Get GMT date when the item was last modified. |
|
197 | - * |
|
198 | - * @since 1.0.19 |
|
199 | - * @param string $context View or edit context. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
196 | + * Get GMT date when the item was last modified. |
|
197 | + * |
|
198 | + * @since 1.0.19 |
|
199 | + * @param string $context View or edit context. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
203 | 203 | $date = $this->get_date_modified( $context ); |
204 | 204 | |
205 | 205 | if ( $date ) { |
206 | 206 | $date = get_gmt_from_date( $date ); |
207 | 207 | } |
208 | - return $date; |
|
208 | + return $date; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get the item name. |
|
213 | - * |
|
214 | - * @since 1.0.19 |
|
215 | - * @param string $context View or edit context. |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public function get_name( $context = 'view' ) { |
|
219 | - return $this->get_prop( 'name', $context ); |
|
212 | + * Get the item name. |
|
213 | + * |
|
214 | + * @since 1.0.19 |
|
215 | + * @param string $context View or edit context. |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public function get_name( $context = 'view' ) { |
|
219 | + return $this->get_prop( 'name', $context ); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | - * Alias of self::get_name(). |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @param string $context View or edit context. |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function get_title( $context = 'view' ) { |
|
230 | - return $this->get_name( $context ); |
|
223 | + * Alias of self::get_name(). |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @param string $context View or edit context. |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function get_title( $context = 'view' ) { |
|
230 | + return $this->get_name( $context ); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
234 | - * Get the item description. |
|
235 | - * |
|
236 | - * @since 1.0.19 |
|
237 | - * @param string $context View or edit context. |
|
238 | - * @return string |
|
239 | - */ |
|
240 | - public function get_description( $context = 'view' ) { |
|
241 | - return $this->get_prop( 'description', $context ); |
|
234 | + * Get the item description. |
|
235 | + * |
|
236 | + * @since 1.0.19 |
|
237 | + * @param string $context View or edit context. |
|
238 | + * @return string |
|
239 | + */ |
|
240 | + public function get_description( $context = 'view' ) { |
|
241 | + return $this->get_prop( 'description', $context ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * Alias of self::get_description(). |
|
246 | - * |
|
247 | - * @since 1.0.19 |
|
248 | - * @param string $context View or edit context. |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function get_excerpt( $context = 'view' ) { |
|
252 | - return $this->get_description( $context ); |
|
245 | + * Alias of self::get_description(). |
|
246 | + * |
|
247 | + * @since 1.0.19 |
|
248 | + * @param string $context View or edit context. |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function get_excerpt( $context = 'view' ) { |
|
252 | + return $this->get_description( $context ); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | - * Alias of self::get_description(). |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - * @param string $context View or edit context. |
|
260 | - * @return string |
|
261 | - */ |
|
262 | - public function get_summary( $context = 'view' ) { |
|
263 | - return $this->get_description( $context ); |
|
256 | + * Alias of self::get_description(). |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + * @param string $context View or edit context. |
|
260 | + * @return string |
|
261 | + */ |
|
262 | + public function get_summary( $context = 'view' ) { |
|
263 | + return $this->get_description( $context ); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | - * Get the owner of the item. |
|
268 | - * |
|
269 | - * @since 1.0.19 |
|
270 | - * @param string $context View or edit context. |
|
271 | - * @return int |
|
272 | - */ |
|
273 | - public function get_author( $context = 'view' ) { |
|
274 | - return (int) $this->get_prop( 'author', $context ); |
|
275 | - } |
|
267 | + * Get the owner of the item. |
|
268 | + * |
|
269 | + * @since 1.0.19 |
|
270 | + * @param string $context View or edit context. |
|
271 | + * @return int |
|
272 | + */ |
|
273 | + public function get_author( $context = 'view' ) { |
|
274 | + return (int) $this->get_prop( 'author', $context ); |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Alias of self::get_author(). |
|
279 | - * |
|
280 | - * @since 1.0.19 |
|
281 | - * @param string $context View or edit context. |
|
282 | - * @return int |
|
283 | - */ |
|
284 | - public function get_owner( $context = 'view' ) { |
|
285 | - return $this->get_author( $context ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Get the price of the item. |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @param string $context View or edit context. |
|
293 | - * @return float |
|
294 | - */ |
|
295 | - public function get_price( $context = 'view' ) { |
|
277 | + /** |
|
278 | + * Alias of self::get_author(). |
|
279 | + * |
|
280 | + * @since 1.0.19 |
|
281 | + * @param string $context View or edit context. |
|
282 | + * @return int |
|
283 | + */ |
|
284 | + public function get_owner( $context = 'view' ) { |
|
285 | + return $this->get_author( $context ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Get the price of the item. |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @param string $context View or edit context. |
|
293 | + * @return float |
|
294 | + */ |
|
295 | + public function get_price( $context = 'view' ) { |
|
296 | 296 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
297 | - } |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * Get the inital price of the item. |
|
301 | - * |
|
302 | - * @since 1.0.19 |
|
303 | - * @param string $context View or edit context. |
|
304 | - * @return float |
|
305 | - */ |
|
306 | - public function get_initial_price( $context = 'view' ) { |
|
299 | + /** |
|
300 | + * Get the inital price of the item. |
|
301 | + * |
|
302 | + * @since 1.0.19 |
|
303 | + * @param string $context View or edit context. |
|
304 | + * @return float |
|
305 | + */ |
|
306 | + public function get_initial_price( $context = 'view' ) { |
|
307 | 307 | |
308 | - $price = (float) $this->get_price( $context ); |
|
308 | + $price = (float) $this->get_price( $context ); |
|
309 | 309 | |
310 | - if ( $this->has_free_trial() ) { |
|
311 | - $price = 0; |
|
312 | - } |
|
310 | + if ( $this->has_free_trial() ) { |
|
311 | + $price = 0; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
318 | - * Returns a formated price. |
|
319 | - * |
|
320 | - * @since 1.0.19 |
|
321 | - * @param string $context View or edit context. |
|
322 | - * @return string |
|
323 | - */ |
|
318 | + * Returns a formated price. |
|
319 | + * |
|
320 | + * @since 1.0.19 |
|
321 | + * @param string $context View or edit context. |
|
322 | + * @return string |
|
323 | + */ |
|
324 | 324 | public function get_the_price() { |
325 | 325 | return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Returns the formated initial price. |
|
330 | - * |
|
331 | - * @since 1.0.19 |
|
332 | - * @param string $context View or edit context. |
|
333 | - * @return string |
|
334 | - */ |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Returns the formated initial price. |
|
330 | + * |
|
331 | + * @since 1.0.19 |
|
332 | + * @param string $context View or edit context. |
|
333 | + * @return string |
|
334 | + */ |
|
335 | 335 | public function get_the_initial_price() { |
336 | 336 | return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
340 | - * Get the VAT rule of the item. |
|
341 | - * |
|
342 | - * @since 1.0.19 |
|
343 | - * @param string $context View or edit context. |
|
344 | - * @return string |
|
345 | - */ |
|
346 | - public function get_vat_rule( $context = 'view' ) { |
|
340 | + * Get the VAT rule of the item. |
|
341 | + * |
|
342 | + * @since 1.0.19 |
|
343 | + * @param string $context View or edit context. |
|
344 | + * @return string |
|
345 | + */ |
|
346 | + public function get_vat_rule( $context = 'view' ) { |
|
347 | 347 | return $this->get_prop( 'vat_rule', $context ); |
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
351 | - * Get the VAT class of the item. |
|
352 | - * |
|
353 | - * @since 1.0.19 |
|
354 | - * @param string $context View or edit context. |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function get_vat_class( $context = 'view' ) { |
|
351 | + * Get the VAT class of the item. |
|
352 | + * |
|
353 | + * @since 1.0.19 |
|
354 | + * @param string $context View or edit context. |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function get_vat_class( $context = 'view' ) { |
|
358 | 358 | return $this->get_prop( 'vat_class', $context ); |
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
362 | - * Get the type of the item. |
|
363 | - * |
|
364 | - * @since 1.0.19 |
|
365 | - * @param string $context View or edit context. |
|
366 | - * @return string |
|
367 | - */ |
|
368 | - public function get_type( $context = 'view' ) { |
|
362 | + * Get the type of the item. |
|
363 | + * |
|
364 | + * @since 1.0.19 |
|
365 | + * @param string $context View or edit context. |
|
366 | + * @return string |
|
367 | + */ |
|
368 | + public function get_type( $context = 'view' ) { |
|
369 | 369 | return $this->get_prop( 'type', $context ); |
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
373 | - * Get the custom id of the item. |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * @param string $context View or edit context. |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function get_custom_id( $context = 'view' ) { |
|
373 | + * Get the custom id of the item. |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * @param string $context View or edit context. |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function get_custom_id( $context = 'view' ) { |
|
380 | 380 | return $this->get_prop( 'custom_id', $context ); |
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
384 | - * Get the custom name of the item. |
|
385 | - * |
|
386 | - * @since 1.0.19 |
|
387 | - * @param string $context View or edit context. |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - public function get_custom_name( $context = 'view' ) { |
|
384 | + * Get the custom name of the item. |
|
385 | + * |
|
386 | + * @since 1.0.19 |
|
387 | + * @param string $context View or edit context. |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + public function get_custom_name( $context = 'view' ) { |
|
391 | 391 | return $this->get_prop( 'custom_name', $context ); |
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
395 | - * Get the custom singular name of the item. |
|
396 | - * |
|
397 | - * @since 1.0.19 |
|
398 | - * @param string $context View or edit context. |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
395 | + * Get the custom singular name of the item. |
|
396 | + * |
|
397 | + * @since 1.0.19 |
|
398 | + * @param string $context View or edit context. |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public function get_custom_singular_name( $context = 'view' ) { |
|
402 | 402 | return $this->get_prop( 'custom_singular_name', $context ); |
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
406 | - * Checks if an item is editable.. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @param string $context View or edit context. |
|
410 | - * @return int |
|
411 | - */ |
|
412 | - public function get_is_editable( $context = 'view' ) { |
|
406 | + * Checks if an item is editable.. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @param string $context View or edit context. |
|
410 | + * @return int |
|
411 | + */ |
|
412 | + public function get_is_editable( $context = 'view' ) { |
|
413 | 413 | return (int) $this->get_prop( 'is_editable', $context ); |
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
417 | - * Alias of self::get_is_editable(). |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - * @param string $context View or edit context. |
|
421 | - * @return int |
|
422 | - */ |
|
423 | - public function get_editable( $context = 'view' ) { |
|
424 | - return $this->get_is_editable( $context ); |
|
417 | + * Alias of self::get_is_editable(). |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + * @param string $context View or edit context. |
|
421 | + * @return int |
|
422 | + */ |
|
423 | + public function get_editable( $context = 'view' ) { |
|
424 | + return $this->get_is_editable( $context ); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
428 | - * Checks if dynamic pricing is enabled. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $context View or edit context. |
|
432 | - * @return int |
|
433 | - */ |
|
434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
428 | + * Checks if dynamic pricing is enabled. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $context View or edit context. |
|
432 | + * @return int |
|
433 | + */ |
|
434 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
435 | 435 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
439 | - * Returns the minimum price if dynamic pricing is enabled. |
|
440 | - * |
|
441 | - * @since 1.0.19 |
|
442 | - * @param string $context View or edit context. |
|
443 | - * @return float |
|
444 | - */ |
|
445 | - public function get_minimum_price( $context = 'view' ) { |
|
439 | + * Returns the minimum price if dynamic pricing is enabled. |
|
440 | + * |
|
441 | + * @since 1.0.19 |
|
442 | + * @param string $context View or edit context. |
|
443 | + * @return float |
|
444 | + */ |
|
445 | + public function get_minimum_price( $context = 'view' ) { |
|
446 | 446 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Checks if this is a recurring item. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return int |
|
455 | - */ |
|
456 | - public function get_is_recurring( $context = 'view' ) { |
|
450 | + * Checks if this is a recurring item. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return int |
|
455 | + */ |
|
456 | + public function get_is_recurring( $context = 'view' ) { |
|
457 | 457 | return (int) $this->get_prop( 'is_recurring', $context ); |
458 | - } |
|
458 | + } |
|
459 | 459 | |
460 | - /** |
|
461 | - * Get the recurring price of the item. |
|
462 | - * |
|
463 | - * @since 1.0.19 |
|
464 | - * @param string $context View or edit context. |
|
465 | - * @return float |
|
466 | - */ |
|
467 | - public function get_recurring_price( $context = 'view' ) { |
|
468 | - $price = $this->get_price( $context ); |
|
460 | + /** |
|
461 | + * Get the recurring price of the item. |
|
462 | + * |
|
463 | + * @since 1.0.19 |
|
464 | + * @param string $context View or edit context. |
|
465 | + * @return float |
|
466 | + */ |
|
467 | + public function get_recurring_price( $context = 'view' ) { |
|
468 | + $price = $this->get_price( $context ); |
|
469 | 469 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Get the formatted recurring price of the item. |
|
474 | - * |
|
475 | - * @since 1.0.19 |
|
476 | - * @param string $context View or edit context. |
|
477 | - * @return string |
|
478 | - */ |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Get the formatted recurring price of the item. |
|
474 | + * |
|
475 | + * @since 1.0.19 |
|
476 | + * @param string $context View or edit context. |
|
477 | + * @return string |
|
478 | + */ |
|
479 | 479 | public function get_the_recurring_price() { |
480 | 480 | return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) ); |
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Get the first renewal date (in timestamps) of the item. |
|
485 | - * |
|
486 | - * @since 1.0.19 |
|
487 | - * @return int |
|
488 | - */ |
|
489 | - public function get_first_renewal_date() { |
|
490 | - |
|
491 | - $periods = array( |
|
492 | - 'D' => 'days', |
|
493 | - 'W' => 'weeks', |
|
494 | - 'M' => 'months', |
|
495 | - 'Y' => 'years', |
|
496 | - ); |
|
497 | - |
|
498 | - $period = $this->get_recurring_period(); |
|
499 | - $interval = $this->get_recurring_interval(); |
|
500 | - |
|
501 | - if ( $this->has_free_trial() ) { |
|
502 | - $period = $this->get_trial_period(); |
|
503 | - $interval = $this->get_trial_interval(); |
|
504 | - } |
|
505 | - |
|
506 | - $period = $periods[ $period ]; |
|
507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Get the first renewal date (in timestamps) of the item. |
|
485 | + * |
|
486 | + * @since 1.0.19 |
|
487 | + * @return int |
|
488 | + */ |
|
489 | + public function get_first_renewal_date() { |
|
490 | + |
|
491 | + $periods = array( |
|
492 | + 'D' => 'days', |
|
493 | + 'W' => 'weeks', |
|
494 | + 'M' => 'months', |
|
495 | + 'Y' => 'years', |
|
496 | + ); |
|
497 | + |
|
498 | + $period = $this->get_recurring_period(); |
|
499 | + $interval = $this->get_recurring_interval(); |
|
500 | + |
|
501 | + if ( $this->has_free_trial() ) { |
|
502 | + $period = $this->get_trial_period(); |
|
503 | + $interval = $this->get_trial_interval(); |
|
504 | + } |
|
505 | + |
|
506 | + $period = $periods[ $period ]; |
|
507 | + $interval = empty( $interval ) ? 1 : $interval; |
|
508 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
509 | 509 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
513 | - * Get the recurring period. |
|
514 | - * |
|
515 | - * @since 1.0.19 |
|
516 | - * @param bool $full Return abbreviation or in full. |
|
517 | - * @return string |
|
518 | - */ |
|
519 | - public function get_recurring_period( $full = false ) { |
|
513 | + * Get the recurring period. |
|
514 | + * |
|
515 | + * @since 1.0.19 |
|
516 | + * @param bool $full Return abbreviation or in full. |
|
517 | + * @return string |
|
518 | + */ |
|
519 | + public function get_recurring_period( $full = false ) { |
|
520 | 520 | $period = $this->get_prop( 'recurring_period', 'view' ); |
521 | 521 | |
522 | 522 | if ( $full && ! is_bool( $full ) ) { |
@@ -527,63 +527,63 @@ discard block |
||
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
530 | - * Get the recurring interval. |
|
531 | - * |
|
532 | - * @since 1.0.19 |
|
533 | - * @param string $context View or edit context. |
|
534 | - * @return int |
|
535 | - */ |
|
536 | - public function get_recurring_interval( $context = 'view' ) { |
|
537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
530 | + * Get the recurring interval. |
|
531 | + * |
|
532 | + * @since 1.0.19 |
|
533 | + * @param string $context View or edit context. |
|
534 | + * @return int |
|
535 | + */ |
|
536 | + public function get_recurring_interval( $context = 'view' ) { |
|
537 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
538 | 538 | |
539 | - if ( $interval < 1 ) { |
|
540 | - $interval = 1; |
|
541 | - } |
|
539 | + if ( $interval < 1 ) { |
|
540 | + $interval = 1; |
|
541 | + } |
|
542 | 542 | |
543 | 543 | return $interval; |
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Get the recurring limit. |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param string $context View or edit context. |
|
551 | - * @return int |
|
552 | - */ |
|
553 | - public function get_recurring_limit( $context = 'view' ) { |
|
547 | + * Get the recurring limit. |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param string $context View or edit context. |
|
551 | + * @return int |
|
552 | + */ |
|
553 | + public function get_recurring_limit( $context = 'view' ) { |
|
554 | 554 | return (int) $this->get_prop( 'recurring_limit', $context ); |
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
558 | - * Checks if we have a free trial. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param string $context View or edit context. |
|
562 | - * @return int |
|
563 | - */ |
|
564 | - public function get_is_free_trial( $context = 'view' ) { |
|
558 | + * Checks if we have a free trial. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param string $context View or edit context. |
|
562 | + * @return int |
|
563 | + */ |
|
564 | + public function get_is_free_trial( $context = 'view' ) { |
|
565 | 565 | return (int) $this->get_prop( 'is_free_trial', $context ); |
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
569 | - * Alias for self::get_is_free_trial(). |
|
570 | - * |
|
571 | - * @since 1.0.19 |
|
572 | - * @param string $context View or edit context. |
|
573 | - * @return int |
|
574 | - */ |
|
575 | - public function get_free_trial( $context = 'view' ) { |
|
569 | + * Alias for self::get_is_free_trial(). |
|
570 | + * |
|
571 | + * @since 1.0.19 |
|
572 | + * @param string $context View or edit context. |
|
573 | + * @return int |
|
574 | + */ |
|
575 | + public function get_free_trial( $context = 'view' ) { |
|
576 | 576 | return $this->get_is_free_trial( $context ); |
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
580 | - * Get the trial period. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - * @param bool $full Return abbreviation or in full. |
|
584 | - * @return string |
|
585 | - */ |
|
586 | - public function get_trial_period( $full = false ) { |
|
580 | + * Get the trial period. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + * @param bool $full Return abbreviation or in full. |
|
584 | + * @return string |
|
585 | + */ |
|
586 | + public function get_trial_period( $full = false ) { |
|
587 | 587 | $period = $this->get_prop( 'trial_period', 'view' ); |
588 | 588 | |
589 | 589 | if ( $full && ! is_bool( $full ) ) { |
@@ -594,104 +594,104 @@ discard block |
||
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
597 | - * Get the trial interval. |
|
598 | - * |
|
599 | - * @since 1.0.19 |
|
600 | - * @param string $context View or edit context. |
|
601 | - * @return int |
|
602 | - */ |
|
603 | - public function get_trial_interval( $context = 'view' ) { |
|
597 | + * Get the trial interval. |
|
598 | + * |
|
599 | + * @since 1.0.19 |
|
600 | + * @param string $context View or edit context. |
|
601 | + * @return int |
|
602 | + */ |
|
603 | + public function get_trial_interval( $context = 'view' ) { |
|
604 | 604 | return (int) $this->get_prop( 'trial_interval', $context ); |
605 | - } |
|
605 | + } |
|
606 | 606 | |
607 | - /** |
|
608 | - * Get the item's edit url. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @return string |
|
612 | - */ |
|
613 | - public function get_edit_url() { |
|
607 | + /** |
|
608 | + * Get the item's edit url. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @return string |
|
612 | + */ |
|
613 | + public function get_edit_url() { |
|
614 | 614 | return get_edit_post_link( $this->get_id() ); |
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Given an item's name/custom id, it returns its id. |
|
619 | - * |
|
620 | - * |
|
621 | - * @static |
|
622 | - * @param string $value The item name or custom id. |
|
623 | - * @param string $field Either name or custom_id. |
|
624 | - * @param string $type in case you need to search for a given type. |
|
625 | - * @since 1.0.15 |
|
626 | - * @return int |
|
627 | - */ |
|
628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | - |
|
630 | - // Trim the value. |
|
631 | - $value = trim( $value ); |
|
632 | - |
|
633 | - if ( empty( $value ) ) { |
|
634 | - return 0; |
|
635 | - } |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Given an item's name/custom id, it returns its id. |
|
619 | + * |
|
620 | + * |
|
621 | + * @static |
|
622 | + * @param string $value The item name or custom id. |
|
623 | + * @param string $field Either name or custom_id. |
|
624 | + * @param string $type in case you need to search for a given type. |
|
625 | + * @since 1.0.15 |
|
626 | + * @return int |
|
627 | + */ |
|
628 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | + |
|
630 | + // Trim the value. |
|
631 | + $value = trim( $value ); |
|
632 | + |
|
633 | + if ( empty( $value ) ) { |
|
634 | + return 0; |
|
635 | + } |
|
636 | 636 | |
637 | 637 | // Valid fields. |
638 | 638 | $fields = array( 'custom_id', 'name', 'slug' ); |
639 | 639 | |
640 | - // Ensure a field has been passed. |
|
641 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
642 | - return 0; |
|
643 | - } |
|
644 | - |
|
645 | - if ( $field == 'name' ) { |
|
646 | - $field = 'slug'; |
|
647 | - } |
|
648 | - |
|
649 | - // Maybe retrieve from the cache. |
|
650 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
651 | - if ( ! empty( $item_id ) ) { |
|
652 | - return $item_id; |
|
653 | - } |
|
654 | - |
|
655 | - // Fetch from the db. |
|
656 | - if ( $field =='slug' ) { |
|
657 | - $items = get_posts( |
|
658 | - array( |
|
659 | - 'post_type' => 'wpi_item', |
|
660 | - 'name' => $value, |
|
661 | - 'posts_per_page' => 1, |
|
662 | - 'post_status' => 'any', |
|
663 | - ) |
|
664 | - ); |
|
665 | - } |
|
666 | - |
|
667 | - if ( $field =='custom_id' ) { |
|
668 | - $items = get_posts( |
|
669 | - array( |
|
670 | - 'post_type' => 'wpi_item', |
|
671 | - 'posts_per_page' => 1, |
|
672 | - 'post_status' => 'any', |
|
673 | - 'meta_query' => array( |
|
674 | - array( |
|
675 | - 'key' => '_wpinv_type', |
|
676 | - 'value' => $type, |
|
677 | - ), |
|
678 | - array( |
|
679 | - 'key' => '_wpinv_custom_id', |
|
680 | - 'value' => $type, |
|
681 | - ) |
|
682 | - ) |
|
683 | - ) |
|
684 | - ); |
|
685 | - } |
|
686 | - |
|
687 | - if ( empty( $items ) ) { |
|
688 | - return 0; |
|
689 | - } |
|
690 | - |
|
691 | - // Update the cache with our data |
|
692 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
693 | - |
|
694 | - return $items[0]->ID; |
|
640 | + // Ensure a field has been passed. |
|
641 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
642 | + return 0; |
|
643 | + } |
|
644 | + |
|
645 | + if ( $field == 'name' ) { |
|
646 | + $field = 'slug'; |
|
647 | + } |
|
648 | + |
|
649 | + // Maybe retrieve from the cache. |
|
650 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
651 | + if ( ! empty( $item_id ) ) { |
|
652 | + return $item_id; |
|
653 | + } |
|
654 | + |
|
655 | + // Fetch from the db. |
|
656 | + if ( $field =='slug' ) { |
|
657 | + $items = get_posts( |
|
658 | + array( |
|
659 | + 'post_type' => 'wpi_item', |
|
660 | + 'name' => $value, |
|
661 | + 'posts_per_page' => 1, |
|
662 | + 'post_status' => 'any', |
|
663 | + ) |
|
664 | + ); |
|
665 | + } |
|
666 | + |
|
667 | + if ( $field =='custom_id' ) { |
|
668 | + $items = get_posts( |
|
669 | + array( |
|
670 | + 'post_type' => 'wpi_item', |
|
671 | + 'posts_per_page' => 1, |
|
672 | + 'post_status' => 'any', |
|
673 | + 'meta_query' => array( |
|
674 | + array( |
|
675 | + 'key' => '_wpinv_type', |
|
676 | + 'value' => $type, |
|
677 | + ), |
|
678 | + array( |
|
679 | + 'key' => '_wpinv_custom_id', |
|
680 | + 'value' => $type, |
|
681 | + ) |
|
682 | + ) |
|
683 | + ) |
|
684 | + ); |
|
685 | + } |
|
686 | + |
|
687 | + if ( empty( $items ) ) { |
|
688 | + return 0; |
|
689 | + } |
|
690 | + |
|
691 | + // Update the cache with our data |
|
692 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
693 | + |
|
694 | + return $items[0]->ID; |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -724,52 +724,52 @@ discard block |
||
724 | 724 | */ |
725 | 725 | |
726 | 726 | /** |
727 | - * Set parent order ID. |
|
728 | - * |
|
729 | - * @since 1.0.19 |
|
730 | - */ |
|
731 | - public function set_parent_id( $value ) { |
|
732 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
733 | - return; |
|
734 | - } |
|
735 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
736 | - } |
|
737 | - |
|
738 | - /** |
|
739 | - * Sets item status. |
|
740 | - * |
|
741 | - * @since 1.0.19 |
|
742 | - * @param string $status New status. |
|
743 | - * @return array details of change. |
|
744 | - */ |
|
745 | - public function set_status( $status ) { |
|
727 | + * Set parent order ID. |
|
728 | + * |
|
729 | + * @since 1.0.19 |
|
730 | + */ |
|
731 | + public function set_parent_id( $value ) { |
|
732 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
733 | + return; |
|
734 | + } |
|
735 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
736 | + } |
|
737 | + |
|
738 | + /** |
|
739 | + * Sets item status. |
|
740 | + * |
|
741 | + * @since 1.0.19 |
|
742 | + * @param string $status New status. |
|
743 | + * @return array details of change. |
|
744 | + */ |
|
745 | + public function set_status( $status ) { |
|
746 | 746 | $old_status = $this->get_status(); |
747 | 747 | |
748 | 748 | $this->set_prop( 'status', $status ); |
749 | 749 | |
750 | - return array( |
|
751 | - 'from' => $old_status, |
|
752 | - 'to' => $status, |
|
753 | - ); |
|
750 | + return array( |
|
751 | + 'from' => $old_status, |
|
752 | + 'to' => $status, |
|
753 | + ); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | /** |
757 | - * Set plugin version when the item was created. |
|
758 | - * |
|
759 | - * @since 1.0.19 |
|
760 | - */ |
|
761 | - public function set_version( $value ) { |
|
762 | - $this->set_prop( 'version', $value ); |
|
757 | + * Set plugin version when the item was created. |
|
758 | + * |
|
759 | + * @since 1.0.19 |
|
760 | + */ |
|
761 | + public function set_version( $value ) { |
|
762 | + $this->set_prop( 'version', $value ); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
766 | - * Set date when the item was created. |
|
767 | - * |
|
768 | - * @since 1.0.19 |
|
769 | - * @param string $value Value to set. |
|
766 | + * Set date when the item was created. |
|
767 | + * |
|
768 | + * @since 1.0.19 |
|
769 | + * @param string $value Value to set. |
|
770 | 770 | * @return bool Whether or not the date was set. |
771 | - */ |
|
772 | - public function set_date_created( $value ) { |
|
771 | + */ |
|
772 | + public function set_date_created( $value ) { |
|
773 | 773 | $date = strtotime( $value ); |
774 | 774 | |
775 | 775 | if ( $date ) { |
@@ -782,13 +782,13 @@ discard block |
||
782 | 782 | } |
783 | 783 | |
784 | 784 | /** |
785 | - * Set date when the item was last modified. |
|
786 | - * |
|
787 | - * @since 1.0.19 |
|
788 | - * @param string $value Value to set. |
|
785 | + * Set date when the item was last modified. |
|
786 | + * |
|
787 | + * @since 1.0.19 |
|
788 | + * @param string $value Value to set. |
|
789 | 789 | * @return bool Whether or not the date was set. |
790 | - */ |
|
791 | - public function set_date_modified( $value ) { |
|
790 | + */ |
|
791 | + public function set_date_modified( $value ) { |
|
792 | 792 | $date = strtotime( $value ); |
793 | 793 | |
794 | 794 | if ( $date ) { |
@@ -801,115 +801,115 @@ discard block |
||
801 | 801 | } |
802 | 802 | |
803 | 803 | /** |
804 | - * Set the item name. |
|
805 | - * |
|
806 | - * @since 1.0.19 |
|
807 | - * @param string $value New name. |
|
808 | - */ |
|
809 | - public function set_name( $value ) { |
|
804 | + * Set the item name. |
|
805 | + * |
|
806 | + * @since 1.0.19 |
|
807 | + * @param string $value New name. |
|
808 | + */ |
|
809 | + public function set_name( $value ) { |
|
810 | 810 | $name = sanitize_text_field( $value ); |
811 | - $this->set_prop( 'name', $name ); |
|
811 | + $this->set_prop( 'name', $name ); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | /** |
815 | - * Alias of self::set_name(). |
|
816 | - * |
|
817 | - * @since 1.0.19 |
|
818 | - * @param string $value New name. |
|
819 | - */ |
|
820 | - public function set_title( $value ) { |
|
821 | - $this->set_name( $value ); |
|
815 | + * Alias of self::set_name(). |
|
816 | + * |
|
817 | + * @since 1.0.19 |
|
818 | + * @param string $value New name. |
|
819 | + */ |
|
820 | + public function set_title( $value ) { |
|
821 | + $this->set_name( $value ); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
825 | - * Set the item description. |
|
826 | - * |
|
827 | - * @since 1.0.19 |
|
828 | - * @param string $value New description. |
|
829 | - */ |
|
830 | - public function set_description( $value ) { |
|
825 | + * Set the item description. |
|
826 | + * |
|
827 | + * @since 1.0.19 |
|
828 | + * @param string $value New description. |
|
829 | + */ |
|
830 | + public function set_description( $value ) { |
|
831 | 831 | $description = wp_kses_post( $value ); |
832 | - return $this->set_prop( 'description', $description ); |
|
832 | + return $this->set_prop( 'description', $description ); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
836 | - * Alias of self::set_description(). |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
839 | - * @param string $value New description. |
|
840 | - */ |
|
841 | - public function set_excerpt( $value ) { |
|
842 | - $this->set_description( $value ); |
|
836 | + * Alias of self::set_description(). |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | + * @param string $value New description. |
|
840 | + */ |
|
841 | + public function set_excerpt( $value ) { |
|
842 | + $this->set_description( $value ); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
846 | - * Alias of self::set_description(). |
|
847 | - * |
|
848 | - * @since 1.0.19 |
|
849 | - * @param string $value New description. |
|
850 | - */ |
|
851 | - public function set_summary( $value ) { |
|
852 | - $this->set_description( $value ); |
|
846 | + * Alias of self::set_description(). |
|
847 | + * |
|
848 | + * @since 1.0.19 |
|
849 | + * @param string $value New description. |
|
850 | + */ |
|
851 | + public function set_summary( $value ) { |
|
852 | + $this->set_description( $value ); |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
856 | - * Set the owner of the item. |
|
857 | - * |
|
858 | - * @since 1.0.19 |
|
859 | - * @param int $value New author. |
|
860 | - */ |
|
861 | - public function set_author( $value ) { |
|
862 | - $this->set_prop( 'author', (int) $value ); |
|
863 | - } |
|
856 | + * Set the owner of the item. |
|
857 | + * |
|
858 | + * @since 1.0.19 |
|
859 | + * @param int $value New author. |
|
860 | + */ |
|
861 | + public function set_author( $value ) { |
|
862 | + $this->set_prop( 'author', (int) $value ); |
|
863 | + } |
|
864 | 864 | |
865 | - /** |
|
866 | - * Alias of self::set_author(). |
|
867 | - * |
|
868 | - * @since 1.0.19 |
|
869 | - * @param int $value New author. |
|
870 | - */ |
|
871 | - public function set_owner( $value ) { |
|
872 | - $this->set_author( $value ); |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * Set the price of the item. |
|
877 | - * |
|
878 | - * @since 1.0.19 |
|
879 | - * @param float $value New price. |
|
880 | - */ |
|
881 | - public function set_price( $value ) { |
|
865 | + /** |
|
866 | + * Alias of self::set_author(). |
|
867 | + * |
|
868 | + * @since 1.0.19 |
|
869 | + * @param int $value New author. |
|
870 | + */ |
|
871 | + public function set_owner( $value ) { |
|
872 | + $this->set_author( $value ); |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * Set the price of the item. |
|
877 | + * |
|
878 | + * @since 1.0.19 |
|
879 | + * @param float $value New price. |
|
880 | + */ |
|
881 | + public function set_price( $value ) { |
|
882 | 882 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
886 | - * Set the VAT rule of the item. |
|
887 | - * |
|
888 | - * @since 1.0.19 |
|
889 | - * @param string $value new rule. |
|
890 | - */ |
|
891 | - public function set_vat_rule( $value ) { |
|
886 | + * Set the VAT rule of the item. |
|
887 | + * |
|
888 | + * @since 1.0.19 |
|
889 | + * @param string $value new rule. |
|
890 | + */ |
|
891 | + public function set_vat_rule( $value ) { |
|
892 | 892 | $this->set_prop( 'vat_rule', $value ); |
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
896 | - * Set the VAT class of the item. |
|
897 | - * |
|
898 | - * @since 1.0.19 |
|
899 | - * @param string $value new class. |
|
900 | - */ |
|
901 | - public function set_vat_class( $value ) { |
|
896 | + * Set the VAT class of the item. |
|
897 | + * |
|
898 | + * @since 1.0.19 |
|
899 | + * @param string $value new class. |
|
900 | + */ |
|
901 | + public function set_vat_class( $value ) { |
|
902 | 902 | $this->set_prop( 'vat_class', $value ); |
903 | 903 | } |
904 | 904 | |
905 | 905 | /** |
906 | - * Set the type of the item. |
|
907 | - * |
|
908 | - * @since 1.0.19 |
|
909 | - * @param string $value new item type. |
|
910 | - * @return string |
|
911 | - */ |
|
912 | - public function set_type( $value ) { |
|
906 | + * Set the type of the item. |
|
907 | + * |
|
908 | + * @since 1.0.19 |
|
909 | + * @param string $value new item type. |
|
910 | + * @return string |
|
911 | + */ |
|
912 | + public function set_type( $value ) { |
|
913 | 913 | |
914 | 914 | if ( empty( $value ) ) { |
915 | 915 | $value = 'custom'; |
@@ -919,134 +919,134 @@ discard block |
||
919 | 919 | } |
920 | 920 | |
921 | 921 | /** |
922 | - * Set the custom id of the item. |
|
923 | - * |
|
924 | - * @since 1.0.19 |
|
925 | - * @param string $value new custom id. |
|
926 | - */ |
|
927 | - public function set_custom_id( $value ) { |
|
922 | + * Set the custom id of the item. |
|
923 | + * |
|
924 | + * @since 1.0.19 |
|
925 | + * @param string $value new custom id. |
|
926 | + */ |
|
927 | + public function set_custom_id( $value ) { |
|
928 | 928 | $this->set_prop( 'custom_id', $value ); |
929 | 929 | } |
930 | 930 | |
931 | 931 | /** |
932 | - * Set the custom name of the item. |
|
933 | - * |
|
934 | - * @since 1.0.19 |
|
935 | - * @param string $value new custom name. |
|
936 | - */ |
|
937 | - public function set_custom_name( $value ) { |
|
932 | + * Set the custom name of the item. |
|
933 | + * |
|
934 | + * @since 1.0.19 |
|
935 | + * @param string $value new custom name. |
|
936 | + */ |
|
937 | + public function set_custom_name( $value ) { |
|
938 | 938 | $this->set_prop( 'custom_name', $value ); |
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
942 | - * Set the custom singular name of the item. |
|
943 | - * |
|
944 | - * @since 1.0.19 |
|
945 | - * @param string $value new custom singular name. |
|
946 | - */ |
|
947 | - public function set_custom_singular_name( $value ) { |
|
942 | + * Set the custom singular name of the item. |
|
943 | + * |
|
944 | + * @since 1.0.19 |
|
945 | + * @param string $value new custom singular name. |
|
946 | + */ |
|
947 | + public function set_custom_singular_name( $value ) { |
|
948 | 948 | $this->set_prop( 'custom_singular_name', $value ); |
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
952 | - * Sets if an item is editable.. |
|
953 | - * |
|
954 | - * @since 1.0.19 |
|
955 | - * @param int|bool $value whether or not the item is editable. |
|
956 | - */ |
|
957 | - public function set_is_editable( $value ) { |
|
958 | - if ( is_numeric( $value ) ) { |
|
959 | - $this->set_prop( 'is_editable', (int) $value ); |
|
960 | - } |
|
952 | + * Sets if an item is editable.. |
|
953 | + * |
|
954 | + * @since 1.0.19 |
|
955 | + * @param int|bool $value whether or not the item is editable. |
|
956 | + */ |
|
957 | + public function set_is_editable( $value ) { |
|
958 | + if ( is_numeric( $value ) ) { |
|
959 | + $this->set_prop( 'is_editable', (int) $value ); |
|
960 | + } |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | /** |
964 | - * Sets if dynamic pricing is enabled. |
|
965 | - * |
|
966 | - * @since 1.0.19 |
|
967 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
968 | - */ |
|
969 | - public function set_is_dynamic_pricing( $value ) { |
|
964 | + * Sets if dynamic pricing is enabled. |
|
965 | + * |
|
966 | + * @since 1.0.19 |
|
967 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
968 | + */ |
|
969 | + public function set_is_dynamic_pricing( $value ) { |
|
970 | 970 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
971 | 971 | } |
972 | 972 | |
973 | 973 | /** |
974 | - * Sets the minimum price if dynamic pricing is enabled. |
|
975 | - * |
|
976 | - * @since 1.0.19 |
|
977 | - * @param float $value minimum price. |
|
978 | - */ |
|
979 | - public function set_minimum_price( $value ) { |
|
974 | + * Sets the minimum price if dynamic pricing is enabled. |
|
975 | + * |
|
976 | + * @since 1.0.19 |
|
977 | + * @param float $value minimum price. |
|
978 | + */ |
|
979 | + public function set_minimum_price( $value ) { |
|
980 | 980 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
981 | 981 | } |
982 | 982 | |
983 | 983 | /** |
984 | - * Sets if this is a recurring item. |
|
985 | - * |
|
986 | - * @since 1.0.19 |
|
987 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
988 | - */ |
|
989 | - public function set_is_recurring( $value ) { |
|
984 | + * Sets if this is a recurring item. |
|
985 | + * |
|
986 | + * @since 1.0.19 |
|
987 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
988 | + */ |
|
989 | + public function set_is_recurring( $value ) { |
|
990 | 990 | $this->set_prop( 'is_recurring', (int) $value ); |
991 | 991 | } |
992 | 992 | |
993 | 993 | /** |
994 | - * Set the recurring period. |
|
995 | - * |
|
996 | - * @since 1.0.19 |
|
997 | - * @param string $value new period. |
|
998 | - */ |
|
999 | - public function set_recurring_period( $value ) { |
|
994 | + * Set the recurring period. |
|
995 | + * |
|
996 | + * @since 1.0.19 |
|
997 | + * @param string $value new period. |
|
998 | + */ |
|
999 | + public function set_recurring_period( $value ) { |
|
1000 | 1000 | $this->set_prop( 'recurring_period', $value ); |
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | /** |
1004 | - * Set the recurring interval. |
|
1005 | - * |
|
1006 | - * @since 1.0.19 |
|
1007 | - * @param int $value recurring interval. |
|
1008 | - */ |
|
1009 | - public function set_recurring_interval( $value ) { |
|
1004 | + * Set the recurring interval. |
|
1005 | + * |
|
1006 | + * @since 1.0.19 |
|
1007 | + * @param int $value recurring interval. |
|
1008 | + */ |
|
1009 | + public function set_recurring_interval( $value ) { |
|
1010 | 1010 | return $this->set_prop( 'recurring_interval', (int) $value ); |
1011 | 1011 | } |
1012 | 1012 | |
1013 | 1013 | /** |
1014 | - * Get the recurring limit. |
|
1015 | - * @since 1.0.19 |
|
1016 | - * @param int $value The recurring limit. |
|
1017 | - * @return int |
|
1018 | - */ |
|
1019 | - public function set_recurring_limit( $value ) { |
|
1014 | + * Get the recurring limit. |
|
1015 | + * @since 1.0.19 |
|
1016 | + * @param int $value The recurring limit. |
|
1017 | + * @return int |
|
1018 | + */ |
|
1019 | + public function set_recurring_limit( $value ) { |
|
1020 | 1020 | $this->set_prop( 'recurring_limit', (int) $value ); |
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | /** |
1024 | - * Checks if we have a free trial. |
|
1025 | - * |
|
1026 | - * @since 1.0.19 |
|
1027 | - * @param int|bool $value whether or not it has a free trial. |
|
1028 | - */ |
|
1029 | - public function set_is_free_trial( $value ) { |
|
1024 | + * Checks if we have a free trial. |
|
1025 | + * |
|
1026 | + * @since 1.0.19 |
|
1027 | + * @param int|bool $value whether or not it has a free trial. |
|
1028 | + */ |
|
1029 | + public function set_is_free_trial( $value ) { |
|
1030 | 1030 | $this->set_prop( 'is_free_trial', (int) $value ); |
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | /** |
1034 | - * Set the trial period. |
|
1035 | - * |
|
1036 | - * @since 1.0.19 |
|
1037 | - * @param string $value trial period. |
|
1038 | - */ |
|
1039 | - public function set_trial_period( $value ) { |
|
1034 | + * Set the trial period. |
|
1035 | + * |
|
1036 | + * @since 1.0.19 |
|
1037 | + * @param string $value trial period. |
|
1038 | + */ |
|
1039 | + public function set_trial_period( $value ) { |
|
1040 | 1040 | $this->set_prop( 'trial_period', $value ); |
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | /** |
1044 | - * Set the trial interval. |
|
1045 | - * |
|
1046 | - * @since 1.0.19 |
|
1047 | - * @param int $value trial interval. |
|
1048 | - */ |
|
1049 | - public function set_trial_interval( $value ) { |
|
1044 | + * Set the trial interval. |
|
1045 | + * |
|
1046 | + * @since 1.0.19 |
|
1047 | + * @param int $value trial interval. |
|
1048 | + */ |
|
1049 | + public function set_trial_interval( $value ) { |
|
1050 | 1050 | $this->set_prop( 'trial_interval', $value ); |
1051 | 1051 | } |
1052 | 1052 | |
@@ -1054,17 +1054,17 @@ discard block |
||
1054 | 1054 | * Create an item. For backwards compatibilty. |
1055 | 1055 | * |
1056 | 1056 | * @deprecated |
1057 | - * @return int item id |
|
1057 | + * @return int item id |
|
1058 | 1058 | */ |
1059 | 1059 | public function create( $data = array() ) { |
1060 | 1060 | |
1061 | - // Set the properties. |
|
1062 | - if ( is_array( $data ) ) { |
|
1063 | - $this->set_props( $data ); |
|
1064 | - } |
|
1061 | + // Set the properties. |
|
1062 | + if ( is_array( $data ) ) { |
|
1063 | + $this->set_props( $data ); |
|
1064 | + } |
|
1065 | 1065 | |
1066 | - // Save the item. |
|
1067 | - return $this->save(); |
|
1066 | + // Save the item. |
|
1067 | + return $this->save(); |
|
1068 | 1068 | |
1069 | 1069 | } |
1070 | 1070 | |
@@ -1072,7 +1072,7 @@ discard block |
||
1072 | 1072 | * Updates an item. For backwards compatibilty. |
1073 | 1073 | * |
1074 | 1074 | * @deprecated |
1075 | - * @return int item id |
|
1075 | + * @return int item id |
|
1076 | 1076 | */ |
1077 | 1077 | public function update( $data = array() ) { |
1078 | 1078 | return $this->create( $data ); |
@@ -1088,84 +1088,84 @@ discard block |
||
1088 | 1088 | */ |
1089 | 1089 | |
1090 | 1090 | /** |
1091 | - * Checks whether the item has enabled dynamic pricing. |
|
1092 | - * |
|
1093 | - * @since 1.0.19 |
|
1094 | - * @return bool |
|
1095 | - */ |
|
1096 | - public function user_can_set_their_price() { |
|
1091 | + * Checks whether the item has enabled dynamic pricing. |
|
1092 | + * |
|
1093 | + * @since 1.0.19 |
|
1094 | + * @return bool |
|
1095 | + */ |
|
1096 | + public function user_can_set_their_price() { |
|
1097 | 1097 | return (bool) $this->get_is_dynamic_pricing(); |
1098 | - } |
|
1098 | + } |
|
1099 | 1099 | |
1100 | - /** |
|
1101 | - * Checks whether the item is recurring. |
|
1102 | - * |
|
1103 | - * @since 1.0.19 |
|
1104 | - * @return bool |
|
1105 | - */ |
|
1106 | - public function is_recurring() { |
|
1100 | + /** |
|
1101 | + * Checks whether the item is recurring. |
|
1102 | + * |
|
1103 | + * @since 1.0.19 |
|
1104 | + * @return bool |
|
1105 | + */ |
|
1106 | + public function is_recurring() { |
|
1107 | 1107 | return (bool) $this->get_is_recurring(); |
1108 | 1108 | } |
1109 | 1109 | |
1110 | 1110 | /** |
1111 | - * Checks whether the item has a free trial. |
|
1112 | - * |
|
1113 | - * @since 1.0.19 |
|
1114 | - * @return bool |
|
1115 | - */ |
|
1111 | + * Checks whether the item has a free trial. |
|
1112 | + * |
|
1113 | + * @since 1.0.19 |
|
1114 | + * @return bool |
|
1115 | + */ |
|
1116 | 1116 | public function has_free_trial() { |
1117 | 1117 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1118 | 1118 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | /** |
1122 | - * Checks whether the item is free. |
|
1123 | - * |
|
1124 | - * @since 1.0.19 |
|
1125 | - * @return bool |
|
1126 | - */ |
|
1122 | + * Checks whether the item is free. |
|
1123 | + * |
|
1124 | + * @since 1.0.19 |
|
1125 | + * @return bool |
|
1126 | + */ |
|
1127 | 1127 | public function is_free() { |
1128 | 1128 | $is_free = $this->get_price() == 0; |
1129 | 1129 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
1130 | 1130 | } |
1131 | 1131 | |
1132 | 1132 | /** |
1133 | - * Checks the item status against a passed in status. |
|
1134 | - * |
|
1135 | - * @param array|string $status Status to check. |
|
1136 | - * @return bool |
|
1137 | - */ |
|
1138 | - public function has_status( $status ) { |
|
1139 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1140 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1133 | + * Checks the item status against a passed in status. |
|
1134 | + * |
|
1135 | + * @param array|string $status Status to check. |
|
1136 | + * @return bool |
|
1137 | + */ |
|
1138 | + public function has_status( $status ) { |
|
1139 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1140 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | /** |
1144 | - * Checks the item type against a passed in types. |
|
1145 | - * |
|
1146 | - * @param array|string $type Type to check. |
|
1147 | - * @return bool |
|
1148 | - */ |
|
1149 | - public function is_type( $type ) { |
|
1150 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1151 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1152 | - } |
|
1144 | + * Checks the item type against a passed in types. |
|
1145 | + * |
|
1146 | + * @param array|string $type Type to check. |
|
1147 | + * @return bool |
|
1148 | + */ |
|
1149 | + public function is_type( $type ) { |
|
1150 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1151 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1152 | + } |
|
1153 | 1153 | |
1154 | 1154 | /** |
1155 | - * Checks whether the item is editable. |
|
1156 | - * |
|
1157 | - * @since 1.0.19 |
|
1158 | - * @return bool |
|
1159 | - */ |
|
1155 | + * Checks whether the item is editable. |
|
1156 | + * |
|
1157 | + * @since 1.0.19 |
|
1158 | + * @return bool |
|
1159 | + */ |
|
1160 | 1160 | public function is_editable() { |
1161 | 1161 | $is_editable = $this->get_is_editable(); |
1162 | 1162 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
1163 | - } |
|
1163 | + } |
|
1164 | 1164 | |
1165 | - /** |
|
1166 | - * Returns an array of cart fees. |
|
1167 | - */ |
|
1168 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1165 | + /** |
|
1166 | + * Returns an array of cart fees. |
|
1167 | + */ |
|
1168 | + public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1169 | 1169 | global $wpi_session; |
1170 | 1170 | |
1171 | 1171 | $fees = $wpi_session->get( 'wpi_cart_fees' ); |
@@ -1209,11 +1209,11 @@ discard block |
||
1209 | 1209 | } |
1210 | 1210 | |
1211 | 1211 | /** |
1212 | - * Checks whether the item is purchasable. |
|
1213 | - * |
|
1214 | - * @since 1.0.19 |
|
1215 | - * @return bool |
|
1216 | - */ |
|
1212 | + * Checks whether the item is purchasable. |
|
1213 | + * |
|
1214 | + * @since 1.0.19 |
|
1215 | + * @return bool |
|
1216 | + */ |
|
1217 | 1217 | public function can_purchase() { |
1218 | 1218 | $can_purchase = null !== $this->get_id(); |
1219 | 1219 | |
@@ -1225,11 +1225,11 @@ discard block |
||
1225 | 1225 | } |
1226 | 1226 | |
1227 | 1227 | /** |
1228 | - * Checks whether the item supports dynamic pricing. |
|
1229 | - * |
|
1230 | - * @since 1.0.19 |
|
1231 | - * @return bool |
|
1232 | - */ |
|
1228 | + * Checks whether the item supports dynamic pricing. |
|
1229 | + * |
|
1230 | + * @since 1.0.19 |
|
1231 | + * @return bool |
|
1232 | + */ |
|
1233 | 1233 | public function supports_dynamic_pricing() { |
1234 | 1234 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
1235 | 1235 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -78,30 +78,30 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @param int|object|WPInv_Item|WP_Post $item Item to read. |
80 | 80 | */ |
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
83 | - |
|
84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | - $this->set_id( $item_id ); |
|
92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | - $this->set_id( $item_id ); |
|
81 | + public function __construct($item = 0) { |
|
82 | + parent::__construct($item); |
|
83 | + |
|
84 | + if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) { |
|
85 | + $this->set_id($item); |
|
86 | + } elseif ($item instanceof self) { |
|
87 | + $this->set_id($item->get_id()); |
|
88 | + } elseif (!empty($item->ID)) { |
|
89 | + $this->set_id($item->ID); |
|
90 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) { |
|
91 | + $this->set_id($item_id); |
|
92 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) { |
|
93 | + $this->set_id($item_id); |
|
94 | 94 | } else { |
95 | - $this->set_object_read( true ); |
|
95 | + $this->set_object_read(true); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // Load the datastore. |
99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
99 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
100 | 100 | |
101 | - if ( $this->get_id() > 0 ) { |
|
102 | - $this->post = get_post( $this->get_id() ); |
|
101 | + if ($this->get_id() > 0) { |
|
102 | + $this->post = get_post($this->get_id()); |
|
103 | 103 | $this->ID = $this->get_id(); |
104 | - $this->data_store->read( $this ); |
|
104 | + $this->data_store->read($this); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | } |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | * @param string $context View or edit context. |
129 | 129 | * @return int |
130 | 130 | */ |
131 | - public function get_parent_id( $context = 'view' ) { |
|
132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
131 | + public function get_parent_id($context = 'view') { |
|
132 | + return (int) $this->get_prop('parent_id', $context); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $context View or edit context. |
140 | 140 | * @return string |
141 | 141 | */ |
142 | - public function get_status( $context = 'view' ) { |
|
143 | - return $this->get_prop( 'status', $context ); |
|
142 | + public function get_status($context = 'view') { |
|
143 | + return $this->get_prop('status', $context); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | * @param string $context View or edit context. |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function get_version( $context = 'view' ) { |
|
154 | - return $this->get_prop( 'version', $context ); |
|
153 | + public function get_version($context = 'view') { |
|
154 | + return $this->get_prop('version', $context); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | * @param string $context View or edit context. |
162 | 162 | * @return string |
163 | 163 | */ |
164 | - public function get_date_created( $context = 'view' ) { |
|
165 | - return $this->get_prop( 'date_created', $context ); |
|
164 | + public function get_date_created($context = 'view') { |
|
165 | + return $this->get_prop('date_created', $context); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | * @param string $context View or edit context. |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
176 | - $date = $this->get_date_created( $context ); |
|
175 | + public function get_date_created_gmt($context = 'view') { |
|
176 | + $date = $this->get_date_created($context); |
|
177 | 177 | |
178 | - if ( $date ) { |
|
179 | - $date = get_gmt_from_date( $date ); |
|
178 | + if ($date) { |
|
179 | + $date = get_gmt_from_date($date); |
|
180 | 180 | } |
181 | 181 | return $date; |
182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * @param string $context View or edit context. |
189 | 189 | * @return string |
190 | 190 | */ |
191 | - public function get_date_modified( $context = 'view' ) { |
|
192 | - return $this->get_prop( 'date_modified', $context ); |
|
191 | + public function get_date_modified($context = 'view') { |
|
192 | + return $this->get_prop('date_modified', $context); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | * @param string $context View or edit context. |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
203 | - $date = $this->get_date_modified( $context ); |
|
202 | + public function get_date_modified_gmt($context = 'view') { |
|
203 | + $date = $this->get_date_modified($context); |
|
204 | 204 | |
205 | - if ( $date ) { |
|
206 | - $date = get_gmt_from_date( $date ); |
|
205 | + if ($date) { |
|
206 | + $date = get_gmt_from_date($date); |
|
207 | 207 | } |
208 | 208 | return $date; |
209 | 209 | } |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | * @param string $context View or edit context. |
216 | 216 | * @return string |
217 | 217 | */ |
218 | - public function get_name( $context = 'view' ) { |
|
219 | - return $this->get_prop( 'name', $context ); |
|
218 | + public function get_name($context = 'view') { |
|
219 | + return $this->get_prop('name', $context); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | * @param string $context View or edit context. |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public function get_title( $context = 'view' ) { |
|
230 | - return $this->get_name( $context ); |
|
229 | + public function get_title($context = 'view') { |
|
230 | + return $this->get_name($context); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | * @param string $context View or edit context. |
238 | 238 | * @return string |
239 | 239 | */ |
240 | - public function get_description( $context = 'view' ) { |
|
241 | - return $this->get_prop( 'description', $context ); |
|
240 | + public function get_description($context = 'view') { |
|
241 | + return $this->get_prop('description', $context); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | * @param string $context View or edit context. |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function get_excerpt( $context = 'view' ) { |
|
252 | - return $this->get_description( $context ); |
|
251 | + public function get_excerpt($context = 'view') { |
|
252 | + return $this->get_description($context); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -259,8 +259,8 @@ discard block |
||
259 | 259 | * @param string $context View or edit context. |
260 | 260 | * @return string |
261 | 261 | */ |
262 | - public function get_summary( $context = 'view' ) { |
|
263 | - return $this->get_description( $context ); |
|
262 | + public function get_summary($context = 'view') { |
|
263 | + return $this->get_description($context); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | * @param string $context View or edit context. |
271 | 271 | * @return int |
272 | 272 | */ |
273 | - public function get_author( $context = 'view' ) { |
|
274 | - return (int) $this->get_prop( 'author', $context ); |
|
273 | + public function get_author($context = 'view') { |
|
274 | + return (int) $this->get_prop('author', $context); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | * @param string $context View or edit context. |
282 | 282 | * @return int |
283 | 283 | */ |
284 | - public function get_owner( $context = 'view' ) { |
|
285 | - return $this->get_author( $context ); |
|
284 | + public function get_owner($context = 'view') { |
|
285 | + return $this->get_author($context); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | * @param string $context View or edit context. |
293 | 293 | * @return float |
294 | 294 | */ |
295 | - public function get_price( $context = 'view' ) { |
|
296 | - return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
|
295 | + public function get_price($context = 'view') { |
|
296 | + return wpinv_sanitize_amount($this->get_prop('price', $context)); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -303,15 +303,15 @@ discard block |
||
303 | 303 | * @param string $context View or edit context. |
304 | 304 | * @return float |
305 | 305 | */ |
306 | - public function get_initial_price( $context = 'view' ) { |
|
306 | + public function get_initial_price($context = 'view') { |
|
307 | 307 | |
308 | - $price = (float) $this->get_price( $context ); |
|
308 | + $price = (float) $this->get_price($context); |
|
309 | 309 | |
310 | - if ( $this->has_free_trial() ) { |
|
310 | + if ($this->has_free_trial()) { |
|
311 | 311 | $price = 0; |
312 | 312 | } |
313 | 313 | |
314 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
|
314 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this)); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @return string |
323 | 323 | */ |
324 | 324 | public function get_the_price() { |
325 | - return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
|
325 | + return wpinv_price(wpinv_format_amount($this->get_price())); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @return string |
334 | 334 | */ |
335 | 335 | public function get_the_initial_price() { |
336 | - return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
|
336 | + return wpinv_price(wpinv_format_amount($this->get_initial_price())); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | * @param string $context View or edit context. |
344 | 344 | * @return string |
345 | 345 | */ |
346 | - public function get_vat_rule( $context = 'view' ) { |
|
347 | - return $this->get_prop( 'vat_rule', $context ); |
|
346 | + public function get_vat_rule($context = 'view') { |
|
347 | + return $this->get_prop('vat_rule', $context); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -354,8 +354,8 @@ discard block |
||
354 | 354 | * @param string $context View or edit context. |
355 | 355 | * @return string |
356 | 356 | */ |
357 | - public function get_vat_class( $context = 'view' ) { |
|
358 | - return $this->get_prop( 'vat_class', $context ); |
|
357 | + public function get_vat_class($context = 'view') { |
|
358 | + return $this->get_prop('vat_class', $context); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -365,8 +365,8 @@ discard block |
||
365 | 365 | * @param string $context View or edit context. |
366 | 366 | * @return string |
367 | 367 | */ |
368 | - public function get_type( $context = 'view' ) { |
|
369 | - return $this->get_prop( 'type', $context ); |
|
368 | + public function get_type($context = 'view') { |
|
369 | + return $this->get_prop('type', $context); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | * @param string $context View or edit context. |
377 | 377 | * @return string |
378 | 378 | */ |
379 | - public function get_custom_id( $context = 'view' ) { |
|
380 | - return $this->get_prop( 'custom_id', $context ); |
|
379 | + public function get_custom_id($context = 'view') { |
|
380 | + return $this->get_prop('custom_id', $context); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | * @param string $context View or edit context. |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - public function get_custom_name( $context = 'view' ) { |
|
391 | - return $this->get_prop( 'custom_name', $context ); |
|
390 | + public function get_custom_name($context = 'view') { |
|
391 | + return $this->get_prop('custom_name', $context); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -398,8 +398,8 @@ discard block |
||
398 | 398 | * @param string $context View or edit context. |
399 | 399 | * @return string |
400 | 400 | */ |
401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
402 | - return $this->get_prop( 'custom_singular_name', $context ); |
|
401 | + public function get_custom_singular_name($context = 'view') { |
|
402 | + return $this->get_prop('custom_singular_name', $context); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -409,8 +409,8 @@ discard block |
||
409 | 409 | * @param string $context View or edit context. |
410 | 410 | * @return int |
411 | 411 | */ |
412 | - public function get_is_editable( $context = 'view' ) { |
|
413 | - return (int) $this->get_prop( 'is_editable', $context ); |
|
412 | + public function get_is_editable($context = 'view') { |
|
413 | + return (int) $this->get_prop('is_editable', $context); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | * @param string $context View or edit context. |
421 | 421 | * @return int |
422 | 422 | */ |
423 | - public function get_editable( $context = 'view' ) { |
|
424 | - return $this->get_is_editable( $context ); |
|
423 | + public function get_editable($context = 'view') { |
|
424 | + return $this->get_is_editable($context); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -431,8 +431,8 @@ discard block |
||
431 | 431 | * @param string $context View or edit context. |
432 | 432 | * @return int |
433 | 433 | */ |
434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
435 | - return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
|
434 | + public function get_is_dynamic_pricing($context = 'view') { |
|
435 | + return (int) $this->get_prop('is_dynamic_pricing', $context); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | * @param string $context View or edit context. |
443 | 443 | * @return float |
444 | 444 | */ |
445 | - public function get_minimum_price( $context = 'view' ) { |
|
446 | - return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
|
445 | + public function get_minimum_price($context = 'view') { |
|
446 | + return wpinv_sanitize_amount($this->get_prop('minimum_price', $context)); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -453,8 +453,8 @@ discard block |
||
453 | 453 | * @param string $context View or edit context. |
454 | 454 | * @return int |
455 | 455 | */ |
456 | - public function get_is_recurring( $context = 'view' ) { |
|
457 | - return (int) $this->get_prop( 'is_recurring', $context ); |
|
456 | + public function get_is_recurring($context = 'view') { |
|
457 | + return (int) $this->get_prop('is_recurring', $context); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -464,9 +464,9 @@ discard block |
||
464 | 464 | * @param string $context View or edit context. |
465 | 465 | * @return float |
466 | 466 | */ |
467 | - public function get_recurring_price( $context = 'view' ) { |
|
468 | - $price = $this->get_price( $context ); |
|
469 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
|
467 | + public function get_recurring_price($context = 'view') { |
|
468 | + $price = $this->get_price($context); |
|
469 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID)); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @return string |
478 | 478 | */ |
479 | 479 | public function get_the_recurring_price() { |
480 | - return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) ); |
|
480 | + return wpinv_price(wpinv_format_amount($this->get_recurring_price())); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -498,15 +498,15 @@ discard block |
||
498 | 498 | $period = $this->get_recurring_period(); |
499 | 499 | $interval = $this->get_recurring_interval(); |
500 | 500 | |
501 | - if ( $this->has_free_trial() ) { |
|
501 | + if ($this->has_free_trial()) { |
|
502 | 502 | $period = $this->get_trial_period(); |
503 | 503 | $interval = $this->get_trial_interval(); |
504 | 504 | } |
505 | 505 | |
506 | - $period = $periods[ $period ]; |
|
507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
509 | - return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
|
506 | + $period = $periods[$period]; |
|
507 | + $interval = empty($interval) ? 1 : $interval; |
|
508 | + $next_renewal = strtotime("+$interval $period", current_time('timestamp')); |
|
509 | + return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -516,14 +516,14 @@ discard block |
||
516 | 516 | * @param bool $full Return abbreviation or in full. |
517 | 517 | * @return string |
518 | 518 | */ |
519 | - public function get_recurring_period( $full = false ) { |
|
520 | - $period = $this->get_prop( 'recurring_period', 'view' ); |
|
519 | + public function get_recurring_period($full = false) { |
|
520 | + $period = $this->get_prop('recurring_period', 'view'); |
|
521 | 521 | |
522 | - if ( $full && ! is_bool( $full ) ) { |
|
522 | + if ($full && !is_bool($full)) { |
|
523 | 523 | $full = false; |
524 | 524 | } |
525 | 525 | |
526 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
526 | + return getpaid_sanitize_recurring_period($period, $full); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -533,10 +533,10 @@ discard block |
||
533 | 533 | * @param string $context View or edit context. |
534 | 534 | * @return int |
535 | 535 | */ |
536 | - public function get_recurring_interval( $context = 'view' ) { |
|
537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
536 | + public function get_recurring_interval($context = 'view') { |
|
537 | + $interval = absint($this->get_prop('recurring_interval', $context)); |
|
538 | 538 | |
539 | - if ( $interval < 1 ) { |
|
539 | + if ($interval < 1) { |
|
540 | 540 | $interval = 1; |
541 | 541 | } |
542 | 542 | |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @param string $context View or edit context. |
551 | 551 | * @return int |
552 | 552 | */ |
553 | - public function get_recurring_limit( $context = 'view' ) { |
|
554 | - return (int) $this->get_prop( 'recurring_limit', $context ); |
|
553 | + public function get_recurring_limit($context = 'view') { |
|
554 | + return (int) $this->get_prop('recurring_limit', $context); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -561,8 +561,8 @@ discard block |
||
561 | 561 | * @param string $context View or edit context. |
562 | 562 | * @return int |
563 | 563 | */ |
564 | - public function get_is_free_trial( $context = 'view' ) { |
|
565 | - return (int) $this->get_prop( 'is_free_trial', $context ); |
|
564 | + public function get_is_free_trial($context = 'view') { |
|
565 | + return (int) $this->get_prop('is_free_trial', $context); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
@@ -572,8 +572,8 @@ discard block |
||
572 | 572 | * @param string $context View or edit context. |
573 | 573 | * @return int |
574 | 574 | */ |
575 | - public function get_free_trial( $context = 'view' ) { |
|
576 | - return $this->get_is_free_trial( $context ); |
|
575 | + public function get_free_trial($context = 'view') { |
|
576 | + return $this->get_is_free_trial($context); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -583,14 +583,14 @@ discard block |
||
583 | 583 | * @param bool $full Return abbreviation or in full. |
584 | 584 | * @return string |
585 | 585 | */ |
586 | - public function get_trial_period( $full = false ) { |
|
587 | - $period = $this->get_prop( 'trial_period', 'view' ); |
|
586 | + public function get_trial_period($full = false) { |
|
587 | + $period = $this->get_prop('trial_period', 'view'); |
|
588 | 588 | |
589 | - if ( $full && ! is_bool( $full ) ) { |
|
589 | + if ($full && !is_bool($full)) { |
|
590 | 590 | $full = false; |
591 | 591 | } |
592 | 592 | |
593 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
593 | + return getpaid_sanitize_recurring_period($period, $full); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
@@ -600,8 +600,8 @@ discard block |
||
600 | 600 | * @param string $context View or edit context. |
601 | 601 | * @return int |
602 | 602 | */ |
603 | - public function get_trial_interval( $context = 'view' ) { |
|
604 | - return (int) $this->get_prop( 'trial_interval', $context ); |
|
603 | + public function get_trial_interval($context = 'view') { |
|
604 | + return (int) $this->get_prop('trial_interval', $context); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | /** |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | * @return string |
612 | 612 | */ |
613 | 613 | public function get_edit_url() { |
614 | - return get_edit_post_link( $this->get_id() ); |
|
614 | + return get_edit_post_link($this->get_id()); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -625,35 +625,35 @@ discard block |
||
625 | 625 | * @since 1.0.15 |
626 | 626 | * @return int |
627 | 627 | */ |
628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
628 | + public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') { |
|
629 | 629 | |
630 | 630 | // Trim the value. |
631 | - $value = trim( $value ); |
|
631 | + $value = trim($value); |
|
632 | 632 | |
633 | - if ( empty( $value ) ) { |
|
633 | + if (empty($value)) { |
|
634 | 634 | return 0; |
635 | 635 | } |
636 | 636 | |
637 | 637 | // Valid fields. |
638 | - $fields = array( 'custom_id', 'name', 'slug' ); |
|
638 | + $fields = array('custom_id', 'name', 'slug'); |
|
639 | 639 | |
640 | 640 | // Ensure a field has been passed. |
641 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
641 | + if (empty($field) || !in_array($field, $fields)) { |
|
642 | 642 | return 0; |
643 | 643 | } |
644 | 644 | |
645 | - if ( $field == 'name' ) { |
|
645 | + if ($field == 'name') { |
|
646 | 646 | $field = 'slug'; |
647 | 647 | } |
648 | 648 | |
649 | 649 | // Maybe retrieve from the cache. |
650 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
651 | - if ( ! empty( $item_id ) ) { |
|
650 | + $item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
651 | + if (!empty($item_id)) { |
|
652 | 652 | return $item_id; |
653 | 653 | } |
654 | 654 | |
655 | 655 | // Fetch from the db. |
656 | - if ( $field =='slug' ) { |
|
656 | + if ($field == 'slug') { |
|
657 | 657 | $items = get_posts( |
658 | 658 | array( |
659 | 659 | 'post_type' => 'wpi_item', |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | ); |
665 | 665 | } |
666 | 666 | |
667 | - if ( $field =='custom_id' ) { |
|
667 | + if ($field == 'custom_id') { |
|
668 | 668 | $items = get_posts( |
669 | 669 | array( |
670 | 670 | 'post_type' => 'wpi_item', |
@@ -684,12 +684,12 @@ discard block |
||
684 | 684 | ); |
685 | 685 | } |
686 | 686 | |
687 | - if ( empty( $items ) ) { |
|
687 | + if (empty($items)) { |
|
688 | 688 | return 0; |
689 | 689 | } |
690 | 690 | |
691 | 691 | // Update the cache with our data |
692 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
692 | + wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
693 | 693 | |
694 | 694 | return $items[0]->ID; |
695 | 695 | } |
@@ -697,19 +697,19 @@ discard block |
||
697 | 697 | /** |
698 | 698 | * Margic method for retrieving a property. |
699 | 699 | */ |
700 | - public function __get( $key ) { |
|
700 | + public function __get($key) { |
|
701 | 701 | |
702 | 702 | // Check if we have a helper method for that. |
703 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
704 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
703 | + if (method_exists($this, 'get_' . $key)) { |
|
704 | + return call_user_func(array($this, 'get_' . $key)); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | // Check if the key is in the associated $post object. |
708 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
708 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
709 | 709 | return $this->post->$key; |
710 | 710 | } |
711 | 711 | |
712 | - return $this->get_prop( $key ); |
|
712 | + return $this->get_prop($key); |
|
713 | 713 | |
714 | 714 | } |
715 | 715 | |
@@ -728,11 +728,11 @@ discard block |
||
728 | 728 | * |
729 | 729 | * @since 1.0.19 |
730 | 730 | */ |
731 | - public function set_parent_id( $value ) { |
|
732 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
731 | + public function set_parent_id($value) { |
|
732 | + if ($value && ($value === $this->get_id() || !get_post($value))) { |
|
733 | 733 | return; |
734 | 734 | } |
735 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
735 | + $this->set_prop('parent_id', absint($value)); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | /** |
@@ -742,10 +742,10 @@ discard block |
||
742 | 742 | * @param string $status New status. |
743 | 743 | * @return array details of change. |
744 | 744 | */ |
745 | - public function set_status( $status ) { |
|
745 | + public function set_status($status) { |
|
746 | 746 | $old_status = $this->get_status(); |
747 | 747 | |
748 | - $this->set_prop( 'status', $status ); |
|
748 | + $this->set_prop('status', $status); |
|
749 | 749 | |
750 | 750 | return array( |
751 | 751 | 'from' => $old_status, |
@@ -758,8 +758,8 @@ discard block |
||
758 | 758 | * |
759 | 759 | * @since 1.0.19 |
760 | 760 | */ |
761 | - public function set_version( $value ) { |
|
762 | - $this->set_prop( 'version', $value ); |
|
761 | + public function set_version($value) { |
|
762 | + $this->set_prop('version', $value); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
@@ -769,11 +769,11 @@ discard block |
||
769 | 769 | * @param string $value Value to set. |
770 | 770 | * @return bool Whether or not the date was set. |
771 | 771 | */ |
772 | - public function set_date_created( $value ) { |
|
773 | - $date = strtotime( $value ); |
|
772 | + public function set_date_created($value) { |
|
773 | + $date = strtotime($value); |
|
774 | 774 | |
775 | - if ( $date ) { |
|
776 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
775 | + if ($date) { |
|
776 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
777 | 777 | return true; |
778 | 778 | } |
779 | 779 | |
@@ -788,11 +788,11 @@ discard block |
||
788 | 788 | * @param string $value Value to set. |
789 | 789 | * @return bool Whether or not the date was set. |
790 | 790 | */ |
791 | - public function set_date_modified( $value ) { |
|
792 | - $date = strtotime( $value ); |
|
791 | + public function set_date_modified($value) { |
|
792 | + $date = strtotime($value); |
|
793 | 793 | |
794 | - if ( $date ) { |
|
795 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
794 | + if ($date) { |
|
795 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
796 | 796 | return true; |
797 | 797 | } |
798 | 798 | |
@@ -806,9 +806,9 @@ discard block |
||
806 | 806 | * @since 1.0.19 |
807 | 807 | * @param string $value New name. |
808 | 808 | */ |
809 | - public function set_name( $value ) { |
|
810 | - $name = sanitize_text_field( $value ); |
|
811 | - $this->set_prop( 'name', $name ); |
|
809 | + public function set_name($value) { |
|
810 | + $name = sanitize_text_field($value); |
|
811 | + $this->set_prop('name', $name); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | /** |
@@ -817,8 +817,8 @@ discard block |
||
817 | 817 | * @since 1.0.19 |
818 | 818 | * @param string $value New name. |
819 | 819 | */ |
820 | - public function set_title( $value ) { |
|
821 | - $this->set_name( $value ); |
|
820 | + public function set_title($value) { |
|
821 | + $this->set_name($value); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
@@ -827,9 +827,9 @@ discard block |
||
827 | 827 | * @since 1.0.19 |
828 | 828 | * @param string $value New description. |
829 | 829 | */ |
830 | - public function set_description( $value ) { |
|
831 | - $description = wp_kses_post( $value ); |
|
832 | - return $this->set_prop( 'description', $description ); |
|
830 | + public function set_description($value) { |
|
831 | + $description = wp_kses_post($value); |
|
832 | + return $this->set_prop('description', $description); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
@@ -838,8 +838,8 @@ discard block |
||
838 | 838 | * @since 1.0.19 |
839 | 839 | * @param string $value New description. |
840 | 840 | */ |
841 | - public function set_excerpt( $value ) { |
|
842 | - $this->set_description( $value ); |
|
841 | + public function set_excerpt($value) { |
|
842 | + $this->set_description($value); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
@@ -848,8 +848,8 @@ discard block |
||
848 | 848 | * @since 1.0.19 |
849 | 849 | * @param string $value New description. |
850 | 850 | */ |
851 | - public function set_summary( $value ) { |
|
852 | - $this->set_description( $value ); |
|
851 | + public function set_summary($value) { |
|
852 | + $this->set_description($value); |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
@@ -858,8 +858,8 @@ discard block |
||
858 | 858 | * @since 1.0.19 |
859 | 859 | * @param int $value New author. |
860 | 860 | */ |
861 | - public function set_author( $value ) { |
|
862 | - $this->set_prop( 'author', (int) $value ); |
|
861 | + public function set_author($value) { |
|
862 | + $this->set_prop('author', (int) $value); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | /** |
@@ -868,8 +868,8 @@ discard block |
||
868 | 868 | * @since 1.0.19 |
869 | 869 | * @param int $value New author. |
870 | 870 | */ |
871 | - public function set_owner( $value ) { |
|
872 | - $this->set_author( $value ); |
|
871 | + public function set_owner($value) { |
|
872 | + $this->set_author($value); |
|
873 | 873 | } |
874 | 874 | |
875 | 875 | /** |
@@ -878,8 +878,8 @@ discard block |
||
878 | 878 | * @since 1.0.19 |
879 | 879 | * @param float $value New price. |
880 | 880 | */ |
881 | - public function set_price( $value ) { |
|
882 | - $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
|
881 | + public function set_price($value) { |
|
882 | + $this->set_prop('price', (float) wpinv_sanitize_amount($value)); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
@@ -888,8 +888,8 @@ discard block |
||
888 | 888 | * @since 1.0.19 |
889 | 889 | * @param string $value new rule. |
890 | 890 | */ |
891 | - public function set_vat_rule( $value ) { |
|
892 | - $this->set_prop( 'vat_rule', $value ); |
|
891 | + public function set_vat_rule($value) { |
|
892 | + $this->set_prop('vat_rule', $value); |
|
893 | 893 | } |
894 | 894 | |
895 | 895 | /** |
@@ -898,8 +898,8 @@ discard block |
||
898 | 898 | * @since 1.0.19 |
899 | 899 | * @param string $value new class. |
900 | 900 | */ |
901 | - public function set_vat_class( $value ) { |
|
902 | - $this->set_prop( 'vat_class', $value ); |
|
901 | + public function set_vat_class($value) { |
|
902 | + $this->set_prop('vat_class', $value); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | /** |
@@ -909,13 +909,13 @@ discard block |
||
909 | 909 | * @param string $value new item type. |
910 | 910 | * @return string |
911 | 911 | */ |
912 | - public function set_type( $value ) { |
|
912 | + public function set_type($value) { |
|
913 | 913 | |
914 | - if ( empty( $value ) ) { |
|
914 | + if (empty($value)) { |
|
915 | 915 | $value = 'custom'; |
916 | 916 | } |
917 | 917 | |
918 | - $this->set_prop( 'type', $value ); |
|
918 | + $this->set_prop('type', $value); |
|
919 | 919 | } |
920 | 920 | |
921 | 921 | /** |
@@ -924,8 +924,8 @@ discard block |
||
924 | 924 | * @since 1.0.19 |
925 | 925 | * @param string $value new custom id. |
926 | 926 | */ |
927 | - public function set_custom_id( $value ) { |
|
928 | - $this->set_prop( 'custom_id', $value ); |
|
927 | + public function set_custom_id($value) { |
|
928 | + $this->set_prop('custom_id', $value); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | /** |
@@ -934,8 +934,8 @@ discard block |
||
934 | 934 | * @since 1.0.19 |
935 | 935 | * @param string $value new custom name. |
936 | 936 | */ |
937 | - public function set_custom_name( $value ) { |
|
938 | - $this->set_prop( 'custom_name', $value ); |
|
937 | + public function set_custom_name($value) { |
|
938 | + $this->set_prop('custom_name', $value); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
@@ -944,8 +944,8 @@ discard block |
||
944 | 944 | * @since 1.0.19 |
945 | 945 | * @param string $value new custom singular name. |
946 | 946 | */ |
947 | - public function set_custom_singular_name( $value ) { |
|
948 | - $this->set_prop( 'custom_singular_name', $value ); |
|
947 | + public function set_custom_singular_name($value) { |
|
948 | + $this->set_prop('custom_singular_name', $value); |
|
949 | 949 | } |
950 | 950 | |
951 | 951 | /** |
@@ -954,9 +954,9 @@ discard block |
||
954 | 954 | * @since 1.0.19 |
955 | 955 | * @param int|bool $value whether or not the item is editable. |
956 | 956 | */ |
957 | - public function set_is_editable( $value ) { |
|
958 | - if ( is_numeric( $value ) ) { |
|
959 | - $this->set_prop( 'is_editable', (int) $value ); |
|
957 | + public function set_is_editable($value) { |
|
958 | + if (is_numeric($value)) { |
|
959 | + $this->set_prop('is_editable', (int) $value); |
|
960 | 960 | } |
961 | 961 | } |
962 | 962 | |
@@ -966,8 +966,8 @@ discard block |
||
966 | 966 | * @since 1.0.19 |
967 | 967 | * @param int|bool $value whether or not dynamic pricing is allowed. |
968 | 968 | */ |
969 | - public function set_is_dynamic_pricing( $value ) { |
|
970 | - $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
|
969 | + public function set_is_dynamic_pricing($value) { |
|
970 | + $this->set_prop('is_dynamic_pricing', (int) $value); |
|
971 | 971 | } |
972 | 972 | |
973 | 973 | /** |
@@ -976,8 +976,8 @@ discard block |
||
976 | 976 | * @since 1.0.19 |
977 | 977 | * @param float $value minimum price. |
978 | 978 | */ |
979 | - public function set_minimum_price( $value ) { |
|
980 | - $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
|
979 | + public function set_minimum_price($value) { |
|
980 | + $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value)); |
|
981 | 981 | } |
982 | 982 | |
983 | 983 | /** |
@@ -986,8 +986,8 @@ discard block |
||
986 | 986 | * @since 1.0.19 |
987 | 987 | * @param int|bool $value whether or not dynamic pricing is allowed. |
988 | 988 | */ |
989 | - public function set_is_recurring( $value ) { |
|
990 | - $this->set_prop( 'is_recurring', (int) $value ); |
|
989 | + public function set_is_recurring($value) { |
|
990 | + $this->set_prop('is_recurring', (int) $value); |
|
991 | 991 | } |
992 | 992 | |
993 | 993 | /** |
@@ -996,8 +996,8 @@ discard block |
||
996 | 996 | * @since 1.0.19 |
997 | 997 | * @param string $value new period. |
998 | 998 | */ |
999 | - public function set_recurring_period( $value ) { |
|
1000 | - $this->set_prop( 'recurring_period', $value ); |
|
999 | + public function set_recurring_period($value) { |
|
1000 | + $this->set_prop('recurring_period', $value); |
|
1001 | 1001 | } |
1002 | 1002 | |
1003 | 1003 | /** |
@@ -1006,8 +1006,8 @@ discard block |
||
1006 | 1006 | * @since 1.0.19 |
1007 | 1007 | * @param int $value recurring interval. |
1008 | 1008 | */ |
1009 | - public function set_recurring_interval( $value ) { |
|
1010 | - return $this->set_prop( 'recurring_interval', (int) $value ); |
|
1009 | + public function set_recurring_interval($value) { |
|
1010 | + return $this->set_prop('recurring_interval', (int) $value); |
|
1011 | 1011 | } |
1012 | 1012 | |
1013 | 1013 | /** |
@@ -1016,8 +1016,8 @@ discard block |
||
1016 | 1016 | * @param int $value The recurring limit. |
1017 | 1017 | * @return int |
1018 | 1018 | */ |
1019 | - public function set_recurring_limit( $value ) { |
|
1020 | - $this->set_prop( 'recurring_limit', (int) $value ); |
|
1019 | + public function set_recurring_limit($value) { |
|
1020 | + $this->set_prop('recurring_limit', (int) $value); |
|
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | /** |
@@ -1026,8 +1026,8 @@ discard block |
||
1026 | 1026 | * @since 1.0.19 |
1027 | 1027 | * @param int|bool $value whether or not it has a free trial. |
1028 | 1028 | */ |
1029 | - public function set_is_free_trial( $value ) { |
|
1030 | - $this->set_prop( 'is_free_trial', (int) $value ); |
|
1029 | + public function set_is_free_trial($value) { |
|
1030 | + $this->set_prop('is_free_trial', (int) $value); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | /** |
@@ -1036,8 +1036,8 @@ discard block |
||
1036 | 1036 | * @since 1.0.19 |
1037 | 1037 | * @param string $value trial period. |
1038 | 1038 | */ |
1039 | - public function set_trial_period( $value ) { |
|
1040 | - $this->set_prop( 'trial_period', $value ); |
|
1039 | + public function set_trial_period($value) { |
|
1040 | + $this->set_prop('trial_period', $value); |
|
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | /** |
@@ -1046,8 +1046,8 @@ discard block |
||
1046 | 1046 | * @since 1.0.19 |
1047 | 1047 | * @param int $value trial interval. |
1048 | 1048 | */ |
1049 | - public function set_trial_interval( $value ) { |
|
1050 | - $this->set_prop( 'trial_interval', $value ); |
|
1049 | + public function set_trial_interval($value) { |
|
1050 | + $this->set_prop('trial_interval', $value); |
|
1051 | 1051 | } |
1052 | 1052 | |
1053 | 1053 | /** |
@@ -1056,11 +1056,11 @@ discard block |
||
1056 | 1056 | * @deprecated |
1057 | 1057 | * @return int item id |
1058 | 1058 | */ |
1059 | - public function create( $data = array() ) { |
|
1059 | + public function create($data = array()) { |
|
1060 | 1060 | |
1061 | 1061 | // Set the properties. |
1062 | - if ( is_array( $data ) ) { |
|
1063 | - $this->set_props( $data ); |
|
1062 | + if (is_array($data)) { |
|
1063 | + $this->set_props($data); |
|
1064 | 1064 | } |
1065 | 1065 | |
1066 | 1066 | // Save the item. |
@@ -1074,8 +1074,8 @@ discard block |
||
1074 | 1074 | * @deprecated |
1075 | 1075 | * @return int item id |
1076 | 1076 | */ |
1077 | - public function update( $data = array() ) { |
|
1078 | - return $this->create( $data ); |
|
1077 | + public function update($data = array()) { |
|
1078 | + return $this->create($data); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /* |
@@ -1115,7 +1115,7 @@ discard block |
||
1115 | 1115 | */ |
1116 | 1116 | public function has_free_trial() { |
1117 | 1117 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1118 | - return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
|
1118 | + return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this); |
|
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | /** |
@@ -1125,8 +1125,8 @@ discard block |
||
1125 | 1125 | * @return bool |
1126 | 1126 | */ |
1127 | 1127 | public function is_free() { |
1128 | - $is_free = $this->get_price() == 0; |
|
1129 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
|
1128 | + $is_free = $this->get_price() == 0; |
|
1129 | + return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this); |
|
1130 | 1130 | } |
1131 | 1131 | |
1132 | 1132 | /** |
@@ -1135,9 +1135,9 @@ discard block |
||
1135 | 1135 | * @param array|string $status Status to check. |
1136 | 1136 | * @return bool |
1137 | 1137 | */ |
1138 | - public function has_status( $status ) { |
|
1139 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1140 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1138 | + public function has_status($status) { |
|
1139 | + $has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status; |
|
1140 | + return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | /** |
@@ -1146,9 +1146,9 @@ discard block |
||
1146 | 1146 | * @param array|string $type Type to check. |
1147 | 1147 | * @return bool |
1148 | 1148 | */ |
1149 | - public function is_type( $type ) { |
|
1150 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1151 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1149 | + public function is_type($type) { |
|
1150 | + $is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type; |
|
1151 | + return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type); |
|
1152 | 1152 | } |
1153 | 1153 | |
1154 | 1154 | /** |
@@ -1159,53 +1159,53 @@ discard block |
||
1159 | 1159 | */ |
1160 | 1160 | public function is_editable() { |
1161 | 1161 | $is_editable = $this->get_is_editable(); |
1162 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
|
1162 | + return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this); |
|
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | /** |
1166 | 1166 | * Returns an array of cart fees. |
1167 | 1167 | */ |
1168 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1168 | + public function get_fees($type = 'fee', $item_id = 0) { |
|
1169 | 1169 | global $wpi_session; |
1170 | 1170 | |
1171 | - $fees = $wpi_session->get( 'wpi_cart_fees' ); |
|
1171 | + $fees = $wpi_session->get('wpi_cart_fees'); |
|
1172 | 1172 | |
1173 | - if ( ! wpinv_get_cart_contents() ) { |
|
1173 | + if (!wpinv_get_cart_contents()) { |
|
1174 | 1174 | // We can only get item type fees when the cart is empty |
1175 | 1175 | $type = 'custom'; |
1176 | 1176 | } |
1177 | 1177 | |
1178 | - if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { |
|
1179 | - foreach( $fees as $key => $fee ) { |
|
1180 | - if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1181 | - unset( $fees[ $key ] ); |
|
1178 | + if (!empty($fees) && !empty($type) && 'all' !== $type) { |
|
1179 | + foreach ($fees as $key => $fee) { |
|
1180 | + if (!empty($fee['type']) && $type != $fee['type']) { |
|
1181 | + unset($fees[$key]); |
|
1182 | 1182 | } |
1183 | 1183 | } |
1184 | 1184 | } |
1185 | 1185 | |
1186 | - if ( ! empty( $fees ) && ! empty( $item_id ) ) { |
|
1186 | + if (!empty($fees) && !empty($item_id)) { |
|
1187 | 1187 | // Remove fees that don't belong to the specified Item |
1188 | - foreach ( $fees as $key => $fee ) { |
|
1189 | - if ( (int) $item_id !== (int)$fee['custom_id'] ) { |
|
1190 | - unset( $fees[ $key ] ); |
|
1188 | + foreach ($fees as $key => $fee) { |
|
1189 | + if ((int) $item_id !== (int) $fee['custom_id']) { |
|
1190 | + unset($fees[$key]); |
|
1191 | 1191 | } |
1192 | 1192 | } |
1193 | 1193 | } |
1194 | 1194 | |
1195 | - if ( ! empty( $fees ) ) { |
|
1195 | + if (!empty($fees)) { |
|
1196 | 1196 | // Remove fees that belong to a specific item but are not in the cart |
1197 | - foreach( $fees as $key => $fee ) { |
|
1198 | - if( empty( $fee['custom_id'] ) ) { |
|
1197 | + foreach ($fees as $key => $fee) { |
|
1198 | + if (empty($fee['custom_id'])) { |
|
1199 | 1199 | continue; |
1200 | 1200 | } |
1201 | 1201 | |
1202 | - if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) { |
|
1203 | - unset( $fees[ $key ] ); |
|
1202 | + if (!wpinv_item_in_cart($fee['custom_id'])) { |
|
1203 | + unset($fees[$key]); |
|
1204 | 1204 | } |
1205 | 1205 | } |
1206 | 1206 | } |
1207 | 1207 | |
1208 | - return ! empty( $fees ) ? $fees : array(); |
|
1208 | + return !empty($fees) ? $fees : array(); |
|
1209 | 1209 | } |
1210 | 1210 | |
1211 | 1211 | /** |
@@ -1217,11 +1217,11 @@ discard block |
||
1217 | 1217 | public function can_purchase() { |
1218 | 1218 | $can_purchase = null !== $this->get_id(); |
1219 | 1219 | |
1220 | - if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
1220 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
1221 | 1221 | $can_purchase = false; |
1222 | 1222 | } |
1223 | 1223 | |
1224 | - return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
1224 | + return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
1225 | 1225 | } |
1226 | 1226 | |
1227 | 1227 | /** |
@@ -1231,6 +1231,6 @@ discard block |
||
1231 | 1231 | * @return bool |
1232 | 1232 | */ |
1233 | 1233 | public function supports_dynamic_pricing() { |
1234 | - return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
|
1234 | + return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this); |
|
1235 | 1235 | } |
1236 | 1236 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @deprecated |
@@ -19,48 +19,48 @@ discard block |
||
19 | 19 | * @deprecated |
20 | 20 | */ |
21 | 21 | function wpinv_get_invoice_cart() { |
22 | - return wpinv_get_invoice( getpaid_get_current_invoice_id() ); |
|
22 | + return wpinv_get_invoice(getpaid_get_current_invoice_id()); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @deprecated |
27 | 27 | */ |
28 | -function wpinv_get_invoice_description( $invoice ) { |
|
29 | - $invoice = new WPInv_Invoice( $invoice ); |
|
28 | +function wpinv_get_invoice_description($invoice) { |
|
29 | + $invoice = new WPInv_Invoice($invoice); |
|
30 | 30 | return $invoice->get_description(); |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @deprecated |
35 | 35 | */ |
36 | -function wpinv_get_invoice_currency_code( $invoice ) { |
|
37 | - $invoice = new WPInv_Invoice( $invoice ); |
|
36 | +function wpinv_get_invoice_currency_code($invoice) { |
|
37 | + $invoice = new WPInv_Invoice($invoice); |
|
38 | 38 | return $invoice->get_currency(); |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @deprecated |
43 | 43 | */ |
44 | -function wpinv_get_payment_user_email( $invoice ) { |
|
45 | - $invoice = new WPInv_Invoice( $invoice ); |
|
44 | +function wpinv_get_payment_user_email($invoice) { |
|
45 | + $invoice = new WPInv_Invoice($invoice); |
|
46 | 46 | return $invoice->get_email(); |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * @deprecated |
51 | 51 | */ |
52 | -function wpinv_get_user_id( $invoice ) { |
|
53 | - $invoice = new WPInv_Invoice( $invoice ); |
|
52 | +function wpinv_get_user_id($invoice) { |
|
53 | + $invoice = new WPInv_Invoice($invoice); |
|
54 | 54 | return $invoice->get_user_id(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @deprecated |
59 | 59 | */ |
60 | -function wpinv_get_invoice_status( $invoice, $return_label = false ) { |
|
61 | - $invoice = new WPInv_Invoice( $invoice ); |
|
60 | +function wpinv_get_invoice_status($invoice, $return_label = false) { |
|
61 | + $invoice = new WPInv_Invoice($invoice); |
|
62 | 62 | |
63 | - if ( $return_label ) { |
|
63 | + if ($return_label) { |
|
64 | 64 | return $invoice->get_status_nicename(); |
65 | 65 | } |
66 | 66 | |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @deprecated |
72 | 72 | */ |
73 | -function wpinv_get_payment_gateway( $invoice, $return_label = false ) { |
|
74 | - $invoice = new WPInv_Invoice( $invoice ); |
|
73 | +function wpinv_get_payment_gateway($invoice, $return_label = false) { |
|
74 | + $invoice = new WPInv_Invoice($invoice); |
|
75 | 75 | |
76 | - if ( $return_label ) { |
|
76 | + if ($return_label) { |
|
77 | 77 | return $invoice->get_gateway_title(); |
78 | 78 | } |
79 | 79 | |
@@ -83,75 +83,75 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @deprecated |
85 | 85 | */ |
86 | -function wpinv_get_payment_gateway_name( $invoice ) { |
|
87 | - return wpinv_get_payment_gateway( $invoice, true ); |
|
86 | +function wpinv_get_payment_gateway_name($invoice) { |
|
87 | + return wpinv_get_payment_gateway($invoice, true); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * @deprecated |
92 | 92 | */ |
93 | -function wpinv_get_payment_transaction_id( $invoice ) { |
|
94 | - $invoice = new WPInv_Invoice( $invoice ); |
|
93 | +function wpinv_get_payment_transaction_id($invoice) { |
|
94 | + $invoice = new WPInv_Invoice($invoice); |
|
95 | 95 | return $invoice->get_transaction_id(); |
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
99 | 99 | * @deprecated |
100 | 100 | */ |
101 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
102 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
103 | - return $invoice->get_meta( $meta_key, $single ); |
|
101 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
102 | + $invoice = new WPInv_Invoice($invoice_id); |
|
103 | + return $invoice->get_meta($meta_key, $single); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @deprecated |
108 | 108 | */ |
109 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) { |
|
110 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
111 | - return $invoice->update_meta_data( $meta_key, $meta_value ); |
|
109 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') { |
|
110 | + $invoice = new WPInv_Invoice($invoice_id); |
|
111 | + return $invoice->update_meta_data($meta_key, $meta_value); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | 115 | * @deprecated |
116 | 116 | */ |
117 | -function wpinv_get_items( $invoice = 0 ) { |
|
118 | - $invoice = new WPInv_Invoice( $invoice ); |
|
117 | +function wpinv_get_items($invoice = 0) { |
|
118 | + $invoice = new WPInv_Invoice($invoice); |
|
119 | 119 | return $invoice->get_items(); |
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @deprecated |
124 | 124 | */ |
125 | -function wpinv_get_fees( $invoice = 0 ) { |
|
126 | - $invoice = new WPInv_Invoice( $invoice ); |
|
125 | +function wpinv_get_fees($invoice = 0) { |
|
126 | + $invoice = new WPInv_Invoice($invoice); |
|
127 | 127 | return $invoice->get_fees(); |
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * @deprecated |
132 | 132 | */ |
133 | -function wpinv_get_invoice_ip( $invoice ) { |
|
134 | - $invoice = new WPInv_Invoice( $invoice ); |
|
133 | +function wpinv_get_invoice_ip($invoice) { |
|
134 | + $invoice = new WPInv_Invoice($invoice); |
|
135 | 135 | return $invoice->get_ip(); |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * @deprecated |
140 | 140 | */ |
141 | -function wpinv_get_invoice_user_info( $invoice ) { |
|
142 | - $invoice = new WPInv_Invoice( $invoice ); |
|
141 | +function wpinv_get_invoice_user_info($invoice) { |
|
142 | + $invoice = new WPInv_Invoice($invoice); |
|
143 | 143 | return $invoice->get_user_info(); |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * @deprecated |
148 | 148 | */ |
149 | -function wpinv_subtotal( $invoice = 0, $currency = false ) { |
|
150 | - $invoice = new WPInv_Invoice( $invoice ); |
|
149 | +function wpinv_subtotal($invoice = 0, $currency = false) { |
|
150 | + $invoice = new WPInv_Invoice($invoice); |
|
151 | 151 | $subtotal = $invoice->get_subtotal(); |
152 | 152 | |
153 | - if ( $currency ) { |
|
154 | - return wpinv_price( wpinv_format_amount( $subtotal ), $invoice->get_currency() ); |
|
153 | + if ($currency) { |
|
154 | + return wpinv_price(wpinv_format_amount($subtotal), $invoice->get_currency()); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | return $subtotal; |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | /** |
161 | 161 | * @deprecated |
162 | 162 | */ |
163 | -function wpinv_tax( $invoice = 0, $currency = false ) { |
|
164 | - $invoice = new WPInv_Invoice( $invoice ); |
|
163 | +function wpinv_tax($invoice = 0, $currency = false) { |
|
164 | + $invoice = new WPInv_Invoice($invoice); |
|
165 | 165 | $tax = $invoice->get_total_tax(); |
166 | 166 | |
167 | - if ( $currency ) { |
|
168 | - return wpinv_price( wpinv_format_amount( $tax ), $invoice->get_currency() ); |
|
167 | + if ($currency) { |
|
168 | + return wpinv_price(wpinv_format_amount($tax), $invoice->get_currency()); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | return $tax; |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * @deprecated |
176 | 176 | */ |
177 | -function wpinv_discount( $invoice = 0, $currency = false, $deprecated ) { |
|
178 | - $invoice = new WPInv_Invoice( $invoice ); |
|
177 | +function wpinv_discount($invoice = 0, $currency = false, $deprecated) { |
|
178 | + $invoice = new WPInv_Invoice($invoice); |
|
179 | 179 | $discount = $invoice->get_total_discount(); |
180 | 180 | |
181 | - if ( $currency ) { |
|
182 | - return wpinv_price( wpinv_format_amount( $discount ), $invoice->get_currency() ); |
|
181 | + if ($currency) { |
|
182 | + return wpinv_price(wpinv_format_amount($discount), $invoice->get_currency()); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return $discount; |
@@ -188,20 +188,20 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * @deprecated |
190 | 190 | */ |
191 | -function wpinv_discount_code( $invoice = 0 ) { |
|
192 | - $invoice = new WPInv_Invoice( $invoice ); |
|
191 | +function wpinv_discount_code($invoice = 0) { |
|
192 | + $invoice = new WPInv_Invoice($invoice); |
|
193 | 193 | return $invoice->get_discount_code(); |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @deprecated |
198 | 198 | */ |
199 | -function wpinv_payment_total( $invoice = 0, $currency = false ) { |
|
200 | - $invoice = new WPInv_Invoice( $invoice ); |
|
199 | +function wpinv_payment_total($invoice = 0, $currency = false) { |
|
200 | + $invoice = new WPInv_Invoice($invoice); |
|
201 | 201 | $total = $invoice->get_total(); |
202 | 202 | |
203 | - if ( $currency ) { |
|
204 | - return wpinv_price( wpinv_format_amount( $total ), $invoice->get_currency() ); |
|
203 | + if ($currency) { |
|
204 | + return wpinv_price(wpinv_format_amount($total), $invoice->get_currency()); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return $total; |
@@ -210,51 +210,51 @@ discard block |
||
210 | 210 | /** |
211 | 211 | * @deprecated |
212 | 212 | */ |
213 | -function wpinv_get_date_created( $invoice = 0, $format = '' ) { |
|
214 | - $invoice = new WPInv_Invoice( $invoice ); |
|
213 | +function wpinv_get_date_created($invoice = 0, $format = '') { |
|
214 | + $invoice = new WPInv_Invoice($invoice); |
|
215 | 215 | |
216 | - $format = ! empty( $format ) ? $format : get_option( 'date_format' ); |
|
216 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
217 | 217 | $date_created = $invoice->get_created_date(); |
218 | 218 | |
219 | - return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
219 | + return empty($date_created) ? date_i18n($format, strtotime($date_created)) : ''; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | 223 | * @deprecated |
224 | 224 | */ |
225 | -function wpinv_get_invoice_date( $invoice = 0, $format = '' ) { |
|
226 | - wpinv_get_date_created( $invoice, $format ); |
|
225 | +function wpinv_get_invoice_date($invoice = 0, $format = '') { |
|
226 | + wpinv_get_date_created($invoice, $format); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | 230 | * @deprecated |
231 | 231 | */ |
232 | -function wpinv_get_invoice_vat_number( $invoice = 0 ) { |
|
233 | - $invoice = new WPInv_Invoice( $invoice ); |
|
232 | +function wpinv_get_invoice_vat_number($invoice = 0) { |
|
233 | + $invoice = new WPInv_Invoice($invoice); |
|
234 | 234 | return $invoice->get_vat_number(); |
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | 238 | * @deprecated |
239 | 239 | */ |
240 | -function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
241 | - $invoice = new WPInv_Invoice( $invoice ); |
|
242 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
240 | +function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
241 | + $invoice = new WPInv_Invoice($invoice); |
|
242 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | 246 | * @deprecated |
247 | 247 | */ |
248 | -function wpinv_get_payment_key( $invoice = 0 ) { |
|
249 | - $invoice = new WPInv_Invoice( $invoice ); |
|
248 | +function wpinv_get_payment_key($invoice = 0) { |
|
249 | + $invoice = new WPInv_Invoice($invoice); |
|
250 | 250 | return $invoice->get_key(); |
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
254 | 254 | * @deprecated |
255 | 255 | */ |
256 | -function wpinv_get_invoice_number( $invoice = 0 ) { |
|
257 | - $invoice = new WPInv_Invoice( $invoice ); |
|
256 | +function wpinv_get_invoice_number($invoice = 0) { |
|
257 | + $invoice = new WPInv_Invoice($invoice); |
|
258 | 258 | return $invoice->get_number(); |
259 | 259 | } |
260 | 260 | |
@@ -401,9 +401,9 @@ discard block |
||
401 | 401 | /** |
402 | 402 | * @deprecated |
403 | 403 | */ |
404 | -function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) { |
|
405 | - $invoice = new WPInv_Invoice( $invoice ); |
|
406 | - return $invoice->update_status( $new_status ); |
|
404 | +function wpinv_update_payment_status($invoice, $new_status = 'publish') { |
|
405 | + $invoice = new WPInv_Invoice($invoice); |
|
406 | + return $invoice->update_status($new_status); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -456,22 +456,22 @@ discard block |
||
456 | 456 | /** |
457 | 457 | * @deprecated |
458 | 458 | */ |
459 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
459 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
460 | 460 | |
461 | 461 | // Fetch the invoice. |
462 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
462 | + $invoice = new WPInv_Invoice($invoice_id); |
|
463 | 463 | |
464 | - if ( 0 == $invoice->get_id() ) { |
|
464 | + if (0 == $invoice->get_id()) { |
|
465 | 465 | return false; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Prepare the transaction id. |
469 | - if ( empty( $transaction_id ) ) { |
|
469 | + if (empty($transaction_id)) { |
|
470 | 470 | $transaction_id = $invoice_id; |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Set the transaction id; |
474 | - $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) ); |
|
474 | + $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice)); |
|
475 | 475 | |
476 | 476 | // Save the invoice. |
477 | 477 | return $invoice->save(); |
@@ -480,9 +480,9 @@ discard block |
||
480 | 480 | /** |
481 | 481 | * @deprecated |
482 | 482 | */ |
483 | -function wpinv_send_to_gateway( $gateway, $payment_data ) { |
|
483 | +function wpinv_send_to_gateway($gateway, $payment_data) { |
|
484 | 484 | $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway'); |
485 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
485 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | /** |
@@ -495,8 +495,8 @@ discard block |
||
495 | 495 | /** |
496 | 496 | * @deprecated |
497 | 497 | */ |
498 | -function wpinv_die( $message = '', $title = '', $status = 400 ) { |
|
499 | - add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 ); |
|
500 | - add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 ); |
|
501 | - wp_die( $message, $title, array( 'response' => $status )); |
|
498 | +function wpinv_die($message = '', $title = '', $status = 400) { |
|
499 | + add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3); |
|
500 | + add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3); |
|
501 | + wp_die($message, $title, array('response' => $status)); |
|
502 | 502 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return bool |
20 | 20 | */ |
21 | -function getpaid_is_eu_state( $country ) { |
|
22 | - return WPInv_EUVat::is_eu_state( $country ); |
|
21 | +function getpaid_is_eu_state($country) { |
|
22 | + return WPInv_EUVat::is_eu_state($country); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @return bool |
29 | 29 | */ |
30 | -function getpaid_is_gst_country( $country ) { |
|
31 | - return WPInv_EUVat::is_gst_country( $country ); |
|
30 | +function getpaid_is_gst_country($country) { |
|
31 | + return WPInv_EUVat::is_gst_country($country); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -42,117 +42,117 @@ discard block |
||
42 | 42 | |
43 | 43 | |
44 | 44 | function wpinv_use_taxes() { |
45 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
45 | + $ret = wpinv_get_option('enable_taxes', false); |
|
46 | 46 | |
47 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
47 | + return (bool) apply_filters('wpinv_use_taxes', $ret); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | function wpinv_get_tax_rates() { |
51 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
51 | + $rates = get_option('wpinv_tax_rates', array()); |
|
52 | 52 | |
53 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
53 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
54 | 54 | } |
55 | 55 | |
56 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
56 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
57 | 57 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
58 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
58 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
59 | 59 | |
60 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
60 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
61 | 61 | return $wpi_tax_rates[$item_id]; |
62 | 62 | } |
63 | 63 | |
64 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
64 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
65 | 65 | $wpi_tax_rates[$item_id] = 0; |
66 | 66 | return 0; |
67 | 67 | } |
68 | 68 | |
69 | 69 | $is_global = false; |
70 | - if ( $item_id == 'global' ) { |
|
70 | + if ($item_id == 'global') { |
|
71 | 71 | $is_global = true; |
72 | 72 | $item_id = 0; |
73 | 73 | } |
74 | 74 | |
75 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
76 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
75 | + $rate = (float) wpinv_get_option('tax_rate', 0); |
|
76 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
77 | 77 | |
78 | - if( empty( $country ) ) { |
|
79 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
78 | + if (empty($country)) { |
|
79 | + if (!empty($_POST['wpinv_country'])) { |
|
80 | 80 | $country = $_POST['wpinv_country']; |
81 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
81 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
82 | 82 | $country = $_POST['wpinv_country']; |
83 | - } elseif( !empty( $_POST['country'] ) ) { |
|
83 | + } elseif (!empty($_POST['country'])) { |
|
84 | 84 | $country = $_POST['country']; |
85 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
85 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
86 | 86 | $country = $user_address['country']; |
87 | 87 | } |
88 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
88 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
89 | 89 | } |
90 | 90 | |
91 | - if( empty( $state ) ) { |
|
92 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
91 | + if (empty($state)) { |
|
92 | + if (!empty($_POST['wpinv_state'])) { |
|
93 | 93 | $state = $_POST['wpinv_state']; |
94 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
94 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
95 | 95 | $state = $_POST['wpinv_state']; |
96 | - } elseif( !empty( $_POST['state'] ) ) { |
|
96 | + } elseif (!empty($_POST['state'])) { |
|
97 | 97 | $state = $_POST['state']; |
98 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
98 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
99 | 99 | $state = $user_address['state']; |
100 | 100 | } |
101 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
101 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
102 | 102 | } |
103 | 103 | |
104 | - if( !empty( $country ) ) { |
|
105 | - $tax_rates = wpinv_get_tax_rates(); |
|
104 | + if (!empty($country)) { |
|
105 | + $tax_rates = wpinv_get_tax_rates(); |
|
106 | 106 | |
107 | - if( !empty( $tax_rates ) ) { |
|
107 | + if (!empty($tax_rates)) { |
|
108 | 108 | // Locate the tax rate for this country / state, if it exists |
109 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
110 | - if( $country != $tax_rate['country'] ) |
|
109 | + foreach ($tax_rates as $key => $tax_rate) { |
|
110 | + if ($country != $tax_rate['country']) |
|
111 | 111 | continue; |
112 | 112 | |
113 | - if( !empty( $tax_rate['global'] ) ) { |
|
114 | - if( !empty( $tax_rate['rate'] ) ) { |
|
115 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
113 | + if (!empty($tax_rate['global'])) { |
|
114 | + if (!empty($tax_rate['rate'])) { |
|
115 | + $rate = number_format($tax_rate['rate'], 4); |
|
116 | 116 | } |
117 | 117 | } else { |
118 | 118 | |
119 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
119 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
120 | 120 | continue; |
121 | 121 | |
122 | 122 | $state_rate = $tax_rate['rate']; |
123 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
124 | - $rate = number_format( $state_rate, 4 ); |
|
123 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
124 | + $rate = number_format($state_rate, 4); |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | } |
128 | 128 | } |
129 | 129 | } |
130 | 130 | |
131 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
131 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
132 | 132 | |
133 | - if ( !empty( $item_id ) ) { |
|
133 | + if (!empty($item_id)) { |
|
134 | 134 | $wpi_tax_rates[$item_id] = $rate; |
135 | - } else if ( $is_global ) { |
|
135 | + } else if ($is_global) { |
|
136 | 136 | $wpi_tax_rates['global'] = $rate; |
137 | 137 | } |
138 | 138 | |
139 | 139 | return $rate; |
140 | 140 | } |
141 | 141 | |
142 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
143 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
144 | - $rate = round( $rate, 4 ); |
|
142 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
143 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
144 | + $rate = round($rate, 4); |
|
145 | 145 | $formatted = $rate .= '%'; |
146 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
146 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
147 | 147 | } |
148 | 148 | |
149 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
150 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
149 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
150 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
151 | 151 | $tax = 0.00; |
152 | 152 | |
153 | - if ( wpinv_use_taxes() ) { |
|
154 | - if ( wpinv_prices_include_tax() ) { |
|
155 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
153 | + if (wpinv_use_taxes()) { |
|
154 | + if (wpinv_prices_include_tax()) { |
|
155 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
156 | 156 | $tax = $amount - $pre_tax; |
157 | 157 | } else { |
158 | 158 | $tax = $amount * $rate * 0.01; |
@@ -160,46 +160,46 @@ discard block |
||
160 | 160 | |
161 | 161 | } |
162 | 162 | |
163 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
163 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | function wpinv_prices_include_tax() { |
167 | 167 | return false; // TODO |
168 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
168 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
169 | 169 | |
170 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
170 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
171 | 171 | } |
172 | 172 | |
173 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
174 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
173 | +function wpinv_sales_tax_for_year($year = null) { |
|
174 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
177 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
178 | 178 | global $wpdb; |
179 | 179 | |
180 | 180 | // Start at zero |
181 | 181 | $tax = 0; |
182 | 182 | |
183 | - if ( ! empty( $year ) ) { |
|
183 | + if (!empty($year)) { |
|
184 | 184 | $args = array( |
185 | 185 | 'post_type' => 'wpi_invoice', |
186 | - 'post_status' => array( 'publish' ), |
|
186 | + 'post_status' => array('publish'), |
|
187 | 187 | 'posts_per_page' => -1, |
188 | 188 | 'year' => $year, |
189 | 189 | 'fields' => 'ids' |
190 | 190 | ); |
191 | 191 | |
192 | - $payments = get_posts( $args ); |
|
193 | - $payment_ids = implode( ',', $payments ); |
|
192 | + $payments = get_posts($args); |
|
193 | + $payment_ids = implode(',', $payments); |
|
194 | 194 | |
195 | - if ( count( $payments ) > 0 ) { |
|
195 | + if (count($payments) > 0) { |
|
196 | 196 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
197 | - $tax = $wpdb->get_var( $sql ); |
|
197 | + $tax = $wpdb->get_var($sql); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | } |
201 | 201 | |
202 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
202 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | function wpinv_is_cart_taxed() { |
@@ -208,33 +208,33 @@ discard block |
||
208 | 208 | |
209 | 209 | function wpinv_prices_show_tax_on_checkout() { |
210 | 210 | return false; // TODO |
211 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
211 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
212 | 212 | |
213 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
213 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | function wpinv_display_tax_rate() { |
217 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
217 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
218 | 218 | |
219 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
219 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | function wpinv_cart_needs_tax_address_fields() { |
223 | - if( !wpinv_is_cart_taxed() ) |
|
223 | + if (!wpinv_is_cart_taxed()) |
|
224 | 224 | return false; |
225 | 225 | |
226 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
226 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
227 | 227 | } |
228 | 228 | |
229 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
230 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
231 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
229 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
230 | + $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
231 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
232 | 232 | } |
233 | 233 | |
234 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
234 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
235 | 235 | $currency = wpinv_get_currency(); |
236 | 236 | |
237 | - switch ( $currency ) { |
|
237 | + switch ($currency) { |
|
238 | 238 | case 'RIAL' : |
239 | 239 | case 'JPY' : |
240 | 240 | case 'TWD' : |
@@ -243,48 +243,48 @@ discard block |
||
243 | 243 | break; |
244 | 244 | } |
245 | 245 | |
246 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
246 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | function wpinv_tax_amount() { |
250 | 250 | $output = 0.00; |
251 | 251 | |
252 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
252 | + return apply_filters('wpinv_tax_amount', $output); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | function wpinv_recalculated_tax() { |
256 | - define( 'WPINV_RECALCTAX', true ); |
|
256 | + define('WPINV_RECALCTAX', true); |
|
257 | 257 | } |
258 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
258 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
259 | 259 | |
260 | -function wpinv_recalculate_tax( $return = false ) { |
|
261 | - $invoice_id = (int)wpinv_get_invoice_cart_id(); |
|
262 | - if ( empty( $invoice_id ) ) { |
|
260 | +function wpinv_recalculate_tax($return = false) { |
|
261 | + $invoice_id = (int) wpinv_get_invoice_cart_id(); |
|
262 | + if (empty($invoice_id)) { |
|
263 | 263 | return false; |
264 | 264 | } |
265 | 265 | |
266 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
266 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
267 | 267 | |
268 | - if ( empty( $invoice ) ) { |
|
268 | + if (empty($invoice)) { |
|
269 | 269 | return false; |
270 | 270 | } |
271 | 271 | |
272 | - if ( empty( $_POST['country'] ) ) { |
|
272 | + if (empty($_POST['country'])) { |
|
273 | 273 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
274 | 274 | } |
275 | 275 | |
276 | 276 | $invoice->country = sanitize_text_field($_POST['country']); |
277 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
277 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
278 | 278 | if (isset($_POST['state'])) { |
279 | 279 | $invoice->state = sanitize_text_field($_POST['state']); |
280 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
280 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | $invoice->cart_details = wpinv_get_cart_content_details(); |
284 | 284 | |
285 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
286 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
287 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
285 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
286 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
287 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
288 | 288 | |
289 | 289 | $invoice->tax = $tax; |
290 | 290 | $invoice->subtotal = $subtotal; |
@@ -292,61 +292,61 @@ discard block |
||
292 | 292 | |
293 | 293 | $invoice->save(); |
294 | 294 | |
295 | - if ( $invoice->is_free_trial() ) { |
|
295 | + if ($invoice->is_free_trial()) { |
|
296 | 296 | $total = 0; |
297 | 297 | } |
298 | 298 | |
299 | 299 | $response = array( |
300 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
300 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
301 | 301 | 'total_raw' => $total, |
302 | - 'free' => !( (float)$total > 0 ) && $invoice->is_free() ? true : false, |
|
303 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
302 | + 'free' => !((float) $total > 0) && $invoice->is_free() ? true : false, |
|
303 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
304 | 304 | ); |
305 | 305 | |
306 | - if ( $return ) { |
|
306 | + if ($return) { |
|
307 | 307 | return $response; |
308 | 308 | } |
309 | 309 | |
310 | - wp_send_json( $response ); |
|
310 | + wp_send_json($response); |
|
311 | 311 | } |
312 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
313 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
312 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
313 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
314 | 314 | |
315 | 315 | // VAT Settings |
316 | -function wpinv_vat_rate_add_callback( $args ) { |
|
316 | +function wpinv_vat_rate_add_callback($args) { |
|
317 | 317 | ?> |
318 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
318 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
319 | 319 | <?php |
320 | 320 | } |
321 | 321 | |
322 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
322 | +function wpinv_vat_rate_delete_callback($args) { |
|
323 | 323 | global $wpinv_euvat; |
324 | 324 | |
325 | 325 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
326 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
327 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
326 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
327 | + if (isset($vat_classes[$vat_class])) { |
|
328 | 328 | ?> |
329 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
329 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
330 | 330 | <?php |
331 | 331 | } |
332 | 332 | } |
333 | 333 | |
334 | -function wpinv_vat_rates_callback( $args ) { |
|
334 | +function wpinv_vat_rates_callback($args) { |
|
335 | 335 | global $wpinv_euvat; |
336 | 336 | |
337 | 337 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
338 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
338 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
339 | 339 | |
340 | 340 | $eu_states = $wpinv_euvat->get_eu_states(); |
341 | 341 | $countries = wpinv_get_country_list(); |
342 | 342 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
343 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
343 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
344 | 344 | ob_start(); |
345 | 345 | ?> |
346 | 346 | </td><tr> |
347 | 347 | <td colspan="2" class="wpinv_vat_tdbox"> |
348 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
349 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
348 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
349 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
350 | 350 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
351 | 351 | <colgroup> |
352 | 352 | <col width="50px" /> |
@@ -358,43 +358,43 @@ discard block |
||
358 | 358 | </colgroup> |
359 | 359 | <thead> |
360 | 360 | <tr> |
361 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
362 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
363 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
364 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
365 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
361 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
362 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
363 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
364 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
365 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
366 | 366 | </tr> |
367 | 367 | </thead> |
368 | 368 | <tbody> |
369 | - <?php if( !empty( $eu_states ) ) { ?> |
|
369 | + <?php if (!empty($eu_states)) { ?> |
|
370 | 370 | <?php |
371 | - foreach ( $eu_states as $state ) { |
|
372 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
371 | + foreach ($eu_states as $state) { |
|
372 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
373 | 373 | |
374 | 374 | // Filter the rate for each country |
375 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
375 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
376 | 376 | |
377 | 377 | // If one does not exist create a default |
378 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
378 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
379 | 379 | |
380 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
381 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
382 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
383 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
380 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
381 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
382 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
383 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
384 | 384 | ?> |
385 | 385 | <tr> |
386 | 386 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
387 | 387 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
388 | 388 | <td class="wpinv_vat_global"> |
389 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
390 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
391 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
389 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
390 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
391 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
392 | 392 | </td> |
393 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
394 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
393 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
394 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
395 | 395 | <td class="wpinv_vat_group"> |
396 | 396 | <?php |
397 | - echo wpinv_html_select( array( |
|
397 | + echo wpinv_html_select(array( |
|
398 | 398 | 'name' => 'vat_rates[' . $state . '][group]', |
399 | 399 | 'selected' => $vat_group, |
400 | 400 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -403,14 +403,14 @@ discard block |
||
403 | 403 | 'multiple' => false, |
404 | 404 | 'show_option_all' => false, |
405 | 405 | 'show_option_none' => false |
406 | - ) ); |
|
406 | + )); |
|
407 | 407 | ?> |
408 | 408 | </td> |
409 | 409 | </tr> |
410 | 410 | <?php } ?> |
411 | 411 | <tr> |
412 | 412 | <td colspan="6" style="background-color:#fafafa;"> |
413 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
413 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
414 | 414 | </td> |
415 | 415 | </tr> |
416 | 416 | <?php } ?> |
@@ -422,35 +422,35 @@ discard block |
||
422 | 422 | echo $content; |
423 | 423 | } |
424 | 424 | |
425 | -function wpinv_vat_number_callback( $args ) { |
|
425 | +function wpinv_vat_number_callback($args) { |
|
426 | 426 | global $wpinv_euvat; |
427 | 427 | |
428 | 428 | $vat_number = $wpinv_euvat->get_vat_number(); |
429 | 429 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
430 | 430 | |
431 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
432 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
431 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
432 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
433 | 433 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
434 | 434 | |
435 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
436 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
437 | - $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
|
438 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
439 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
435 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
436 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
437 | + $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int) $vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
|
438 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
439 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
440 | 440 | |
441 | 441 | echo $html; |
442 | 442 | } |
443 | 443 | |
444 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
444 | +function wpinv_eu_fallback_rate_callback($args) { |
|
445 | 445 | global $wpinv_options; |
446 | 446 | |
447 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
448 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
447 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
448 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
449 | 449 | |
450 | - $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
451 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
452 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
453 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
450 | + $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
451 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
452 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
453 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
454 | 454 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
455 | 455 | echo $html; |
456 | 456 | ?> |
@@ -458,36 +458,36 @@ discard block |
||
458 | 458 | <?php |
459 | 459 | } |
460 | 460 | |
461 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
461 | +function wpinv_vat_ip_lookup_callback($args) { |
|
462 | 462 | global $wpinv_options, $wpinv_euvat; |
463 | 463 | |
464 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
464 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
465 | 465 | |
466 | 466 | $options = array(); |
467 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
468 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
467 | + if (function_exists('geoip_country_code_by_name')) { |
|
468 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
472 | 472 | |
473 | - if ( !function_exists( 'bcadd' ) ) { |
|
474 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
473 | + if (!function_exists('bcadd')) { |
|
474 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
475 | 475 | } else { |
476 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
476 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
477 | 477 | } |
478 | 478 | |
479 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
480 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
479 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
480 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
481 | 481 | } |
482 | 482 | |
483 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
484 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
483 | + if (function_exists('simplexml_load_file')) { |
|
484 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
485 | 485 | } |
486 | 486 | |
487 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
488 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
487 | + $options['site'] = __('Use default country', 'invoicing'); |
|
488 | + $options['default'] = __('Auto', 'invoicing'); |
|
489 | 489 | |
490 | - $html = wpinv_html_select( array( |
|
490 | + $html = wpinv_html_select(array( |
|
491 | 491 | 'name' => "wpinv_settings[{$args['id']}]", |
492 | 492 | 'selected' => $value, |
493 | 493 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -499,23 +499,23 @@ discard block |
||
499 | 499 | )); |
500 | 500 | |
501 | 501 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
502 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
502 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
503 | 503 | $desc .= '<p>'; |
504 | - if ( empty( $geoip2_message ) ) { |
|
505 | - if ( $geoip2_database ) { |
|
504 | + if (empty($geoip2_message)) { |
|
505 | + if ($geoip2_database) { |
|
506 | 506 | $last_updated = ''; |
507 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
508 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
509 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
507 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
508 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
509 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
510 | 510 | } |
511 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~30MB)', 'invoicing' ) . '"></input>'; |
|
511 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~30MB)', 'invoicing') . '"></input>'; |
|
512 | 512 | } else { |
513 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~30MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
513 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~30MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
514 | 514 | } |
515 | 515 | } else { |
516 | 516 | $desc .= $geoip2_message; |
517 | 517 | } |
518 | - $desc .= '</p><p>'. __( 'geoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
518 | + $desc .= '</p><p>' . __('geoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
519 | 519 | $desc .= '</label>'; |
520 | 520 | |
521 | 521 | $html .= $desc; |
@@ -531,39 +531,39 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @param string|bool|null $vat_rule |
533 | 533 | */ |
534 | -function getpaid_filter_vat_rule( $vat_rule ) { |
|
534 | +function getpaid_filter_vat_rule($vat_rule) { |
|
535 | 535 | |
536 | - if ( empty( $vat_rule ) ) { |
|
536 | + if (empty($vat_rule)) { |
|
537 | 537 | return getpaid_tax()->allow_vat_rules() ? 'digital' : 'physical'; |
538 | 538 | } |
539 | 539 | |
540 | 540 | return $vat_rule; |
541 | 541 | } |
542 | -add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' ); |
|
542 | +add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule'); |
|
543 | 543 | |
544 | 544 | /** |
545 | 545 | * Filters the VAT class to ensure that each item has a VAT class. |
546 | 546 | * |
547 | 547 | * @param string|bool|null $vat_rule |
548 | 548 | */ |
549 | -function getpaid_filter_vat_class( $vat_class ) { |
|
550 | - return empty( $vat_class ) ? '_standard' : $vat_class; |
|
549 | +function getpaid_filter_vat_class($vat_class) { |
|
550 | + return empty($vat_class) ? '_standard' : $vat_class; |
|
551 | 551 | } |
552 | -add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' ); |
|
552 | +add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class'); |
|
553 | 553 | |
554 | 554 | /** |
555 | 555 | * Returns the ip address location url. |
556 | 556 | * |
557 | 557 | */ |
558 | -function getpaid_ip_location_url( $ip_address ) { |
|
558 | +function getpaid_ip_location_url($ip_address) { |
|
559 | 559 | |
560 | 560 | return add_query_arg( |
561 | 561 | array( |
562 | 562 | 'action' => 'wpinv_ip_geolocation', |
563 | 563 | 'ip' => $ip_address, |
564 | - '_wpnonce' => wp_create_nonce( 'getpaid-ip-location' ) |
|
564 | + '_wpnonce' => wp_create_nonce('getpaid-ip-location') |
|
565 | 565 | ), |
566 | - admin_url( 'admin-ajax.php' ) |
|
566 | + admin_url('admin-ajax.php') |
|
567 | 567 | ); |
568 | 568 | |
569 | 569 | } |
@@ -573,54 +573,54 @@ discard block |
||
573 | 573 | * |
574 | 574 | * @return array|bool |
575 | 575 | */ |
576 | -function getpaid_geolocate_ip_address( $ip_address ) { |
|
576 | +function getpaid_geolocate_ip_address($ip_address) { |
|
577 | 577 | |
578 | 578 | // Do we have an ip address? |
579 | - if ( empty( $ip_address ) ) { |
|
579 | + if (empty($ip_address)) { |
|
580 | 580 | return false; |
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
584 | 584 | * Retrieve ip address using max mind. |
585 | 585 | */ |
586 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = getpaid_tax()->geoip2_city_record( $ip_address ) ) { |
|
586 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = getpaid_tax()->geoip2_city_record($ip_address)) { |
|
587 | 587 | |
588 | 588 | try { |
589 | 589 | $iso = $geoip2_city->country->isoCode; |
590 | 590 | $country = $geoip2_city->country->name; |
591 | - $region = ! empty( $geoip2_city->subdivisions ) && ! empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
591 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
592 | 592 | $city = $geoip2_city->city->name; |
593 | 593 | $longitude = $geoip2_city->location->longitude; |
594 | 594 | $latitude = $geoip2_city->location->latitude; |
595 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
596 | - } catch( Exception $e ) { } |
|
595 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
596 | + } catch (Exception $e) { } |
|
597 | 597 | |
598 | 598 | } |
599 | 599 | |
600 | 600 | // If that fails, GeoLocate using GeoPlugin. |
601 | - if ( ( empty( $iso ) || empty( $longitude ) || empty( $latitude ) ) && function_exists( 'simplexml_load_file' ) ) { |
|
601 | + if ((empty($iso) || empty($longitude) || empty($latitude)) && function_exists('simplexml_load_file')) { |
|
602 | 602 | |
603 | 603 | try { |
604 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip_address ); |
|
604 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip_address); |
|
605 | 605 | |
606 | - if ( ! empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && ! empty( $load_xml->geoplugin_latitude ) && ! empty( $load_xml->geoplugin_longitude ) ) { |
|
606 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
607 | 607 | $iso = $load_xml->geoplugin_countryCode; |
608 | 608 | $country = $load_xml->geoplugin_countryName; |
609 | - $region = ! empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
610 | - $city = ! empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
609 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
610 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
611 | 611 | $longitude = $load_xml->geoplugin_longitude; |
612 | 612 | $latitude = $load_xml->geoplugin_latitude; |
613 | 613 | $credit = $load_xml->geoplugin_credit; |
614 | - $credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
614 | + $credit = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit; |
|
615 | 615 | } |
616 | - } catch( Exception $e ) { } |
|
616 | + } catch (Exception $e) { } |
|
617 | 617 | |
618 | 618 | } |
619 | 619 | |
620 | - if ( empty( $iso ) ) { |
|
620 | + if (empty($iso)) { |
|
621 | 621 | return false; |
622 | 622 | } |
623 | 623 | |
624 | - return compact( 'iso', 'country', 'region', 'city', 'longitude', 'latitude', 'credit' ); |
|
624 | + return compact('iso', 'country', 'region', 'city', 'longitude', 'latitude', 'credit'); |
|
625 | 625 | |
626 | 626 | } |
@@ -18,978 +18,978 @@ |
||
18 | 18 | class GetPaid_REST_Posts_Controller extends GetPaid_REST_Controller { |
19 | 19 | |
20 | 20 | /** |
21 | - * Post type. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - protected $post_type; |
|
26 | - |
|
27 | - /** |
|
28 | - * Controls visibility on frontend. |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - public $public = false; |
|
33 | - |
|
34 | - /** |
|
35 | - * Contains this controller's class name. |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - public $crud_class; |
|
40 | - |
|
41 | - /** |
|
42 | - * Registers the routes for the objects of the controller. |
|
43 | - * |
|
44 | - * @since 1.0.19 |
|
45 | - * |
|
46 | - * @see register_rest_route() |
|
47 | - */ |
|
48 | - public function register_namespace_routes( $namespace ) { |
|
49 | - |
|
50 | - register_rest_route( |
|
51 | - $namespace, |
|
52 | - '/' . $this->rest_base, |
|
53 | - array( |
|
54 | - array( |
|
55 | - 'methods' => WP_REST_Server::READABLE, |
|
56 | - 'callback' => array( $this, 'get_items' ), |
|
57 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
58 | - 'args' => $this->get_collection_params(), |
|
59 | - ), |
|
60 | - array( |
|
61 | - 'methods' => WP_REST_Server::CREATABLE, |
|
62 | - 'callback' => array( $this, 'create_item' ), |
|
63 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
64 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
65 | - ), |
|
66 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
67 | - ) |
|
68 | - ); |
|
69 | - |
|
70 | - $get_item_args = array( |
|
71 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
72 | - ); |
|
73 | - |
|
74 | - register_rest_route( |
|
75 | - $namespace, |
|
76 | - '/' . $this->rest_base . '/(?P<id>[\d]+)', |
|
77 | - array( |
|
78 | - 'args' => array( |
|
79 | - 'id' => array( |
|
80 | - 'description' => __( 'Unique identifier for the object.', 'invoicing' ), |
|
81 | - 'type' => 'integer', |
|
82 | - ), |
|
83 | - ), |
|
84 | - array( |
|
85 | - 'methods' => WP_REST_Server::READABLE, |
|
86 | - 'callback' => array( $this, 'get_item' ), |
|
87 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
88 | - 'args' => $get_item_args, |
|
89 | - ), |
|
90 | - array( |
|
91 | - 'methods' => WP_REST_Server::EDITABLE, |
|
92 | - 'callback' => array( $this, 'update_item' ), |
|
93 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
94 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
95 | - ), |
|
96 | - array( |
|
97 | - 'methods' => WP_REST_Server::DELETABLE, |
|
98 | - 'callback' => array( $this, 'delete_item' ), |
|
99 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
100 | - 'args' => array( |
|
101 | - 'force' => array( |
|
102 | - 'type' => 'boolean', |
|
103 | - 'default' => false, |
|
104 | - 'description' => __( 'Whether to bypass Trash and force deletion.', 'invoicing' ), |
|
105 | - ), |
|
106 | - ), |
|
107 | - ), |
|
108 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
109 | - ) |
|
110 | - ); |
|
111 | - |
|
112 | - register_rest_route( |
|
113 | - $namespace, |
|
114 | - '/' . $this->rest_base . '/batch', |
|
115 | - array( |
|
116 | - array( |
|
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 ), |
|
121 | - ), |
|
122 | - 'schema' => array( $this, 'get_public_batch_schema' ), |
|
123 | - ) |
|
124 | - ); |
|
125 | - |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Check permissions of items on REST API. |
|
130 | - * |
|
131 | - * @since 1.0.19 |
|
132 | - * @param string $context Request context. |
|
133 | - * @param int $object_id Post ID. |
|
134 | - * @return bool |
|
135 | - */ |
|
136 | - public function check_post_permissions( $context = 'read', $object_id = 0 ) { |
|
137 | - |
|
138 | - $contexts = array( |
|
139 | - 'read' => 'read_private_posts', |
|
140 | - 'create' => 'publish_posts', |
|
141 | - 'edit' => 'edit_post', |
|
142 | - 'delete' => 'delete_post', |
|
143 | - 'batch' => 'edit_others_posts', |
|
144 | - ); |
|
145 | - |
|
146 | - if ( 'revision' === $this->post_type ) { |
|
147 | - $permission = false; |
|
148 | - } else { |
|
149 | - $cap = $contexts[ $context ]; |
|
150 | - $post_type_object = get_post_type_object( $this->post_type ); |
|
151 | - $permission = current_user_can( $post_type_object->cap->$cap, $object_id ); |
|
152 | - } |
|
153 | - |
|
154 | - return apply_filters( 'getpaid_rest_check_permissions', $permission, $context, $object_id, $this->post_type ); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Check if a given request has access to read items. |
|
159 | - * |
|
160 | - * @param WP_REST_Request $request Full details about the request. |
|
161 | - * @return WP_Error|boolean |
|
162 | - */ |
|
163 | - public function get_items_permissions_check( $request ) { |
|
164 | - return $this->check_post_permissions() ? true : new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Check if a given request has access to create an item. |
|
169 | - * |
|
170 | - * @param WP_REST_Request $request Full details about the request. |
|
171 | - * @return WP_Error|boolean |
|
172 | - */ |
|
173 | - public function create_item_permissions_check( $request ) { |
|
174 | - return $this->check_post_permissions( 'create' ) ? true : new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Check if a given request has access to read an item. |
|
179 | - * |
|
180 | - * @param WP_REST_Request $request Full details about the request. |
|
181 | - * @return WP_Error|boolean |
|
182 | - */ |
|
183 | - public function get_item_permissions_check( $request ) { |
|
184 | - $post = get_post( (int) $request['id'] ); |
|
185 | - |
|
186 | - if ( $post && ! $this->check_post_permissions( 'read', $post->ID ) ) { |
|
187 | - return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
188 | - } |
|
189 | - |
|
190 | - return true; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Check if a given request has access to update an item. |
|
195 | - * |
|
196 | - * @param WP_REST_Request $request Full details about the request. |
|
197 | - * @return WP_Error|boolean |
|
198 | - */ |
|
199 | - public function update_item_permissions_check( $request ) { |
|
200 | - $post = get_post( (int) $request['id'] ); |
|
201 | - |
|
202 | - if ( $post && ! $this->check_post_permissions( 'edit', $post->ID ) ) { |
|
203 | - return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
204 | - } |
|
205 | - |
|
206 | - return true; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Check if a given request has access to delete an item. |
|
211 | - * |
|
212 | - * @param WP_REST_Request $request Full details about the request. |
|
213 | - * @return bool|WP_Error |
|
214 | - */ |
|
215 | - public function delete_item_permissions_check( $request ) { |
|
216 | - $post = get_post( (int) $request['id'] ); |
|
217 | - |
|
218 | - if ( $post && ! $this->check_post_permissions( 'delete', $post->ID ) ) { |
|
219 | - return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
220 | - } |
|
221 | - |
|
222 | - return true; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Check if a given request has access batch create, update and delete items. |
|
227 | - * |
|
228 | - * @param WP_REST_Request $request Full details about the request. |
|
229 | - * |
|
230 | - * @return boolean|WP_Error |
|
231 | - */ |
|
232 | - public function batch_items_permissions_check( $request ) { |
|
233 | - return $this->check_post_permissions( 'batch' ) ? true : new WP_Error( 'rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Saves a single object. |
|
238 | - * |
|
239 | - * @param GetPaid_Data $object Object to save. |
|
240 | - * @return WP_Error|GetPaid_Data |
|
241 | - */ |
|
242 | - protected function save_object( $object ) { |
|
243 | - $object->save(); |
|
244 | - |
|
245 | - if ( ! empty( $object->last_error ) ) { |
|
246 | - return new WP_Error( 'rest_cannot_save', $object->last_error, array( 'status' => 400 ) ); |
|
247 | - } |
|
248 | - |
|
249 | - return new $this->crud_class( $object->get_id() ); |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Returns the item's object. |
|
254 | - * |
|
255 | - * Child classes must implement this method. |
|
256 | - * @since 1.0.13 |
|
257 | - * |
|
258 | - * @param int|WP_Post $object_id Supplied ID. |
|
259 | - * @return GetPaid_Data|WP_Error GetPaid_Data object if ID is valid, WP_Error otherwise. |
|
260 | - */ |
|
261 | - protected function get_object( $object_id ) { |
|
262 | - |
|
263 | - // Do we have an object? |
|
264 | - if ( empty( $this->crud_class ) || ! class_exists( $this->crud_class ) ) { |
|
265 | - return new WP_Error( 'no_crud_class', __( 'You need to specify a CRUD class for this controller', 'invoicing' ) ); |
|
266 | - } |
|
267 | - |
|
268 | - // Fetch the object. |
|
269 | - $object = new $this->crud_class( $object_id ); |
|
270 | - if ( ! empty( $object->last_error ) ) { |
|
271 | - return new WP_Error( 'rest_object_invalid_id', $object->last_error, array( 'status' => 404 ) ); |
|
272 | - } |
|
273 | - |
|
274 | - return $object->get_id() ? $object : new WP_Error( 'rest_object_invalid_id', __( 'Invalid ID.', 'invoicing' ), array( 'status' => 404 ) ); |
|
275 | - |
|
276 | - } |
|
21 | + * Post type. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + protected $post_type; |
|
26 | + |
|
27 | + /** |
|
28 | + * Controls visibility on frontend. |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + public $public = false; |
|
33 | + |
|
34 | + /** |
|
35 | + * Contains this controller's class name. |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + public $crud_class; |
|
40 | + |
|
41 | + /** |
|
42 | + * Registers the routes for the objects of the controller. |
|
43 | + * |
|
44 | + * @since 1.0.19 |
|
45 | + * |
|
46 | + * @see register_rest_route() |
|
47 | + */ |
|
48 | + public function register_namespace_routes( $namespace ) { |
|
49 | + |
|
50 | + register_rest_route( |
|
51 | + $namespace, |
|
52 | + '/' . $this->rest_base, |
|
53 | + array( |
|
54 | + array( |
|
55 | + 'methods' => WP_REST_Server::READABLE, |
|
56 | + 'callback' => array( $this, 'get_items' ), |
|
57 | + 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
58 | + 'args' => $this->get_collection_params(), |
|
59 | + ), |
|
60 | + array( |
|
61 | + 'methods' => WP_REST_Server::CREATABLE, |
|
62 | + 'callback' => array( $this, 'create_item' ), |
|
63 | + 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
64 | + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
65 | + ), |
|
66 | + 'schema' => array( $this, 'get_public_item_schema' ), |
|
67 | + ) |
|
68 | + ); |
|
69 | + |
|
70 | + $get_item_args = array( |
|
71 | + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
72 | + ); |
|
73 | + |
|
74 | + register_rest_route( |
|
75 | + $namespace, |
|
76 | + '/' . $this->rest_base . '/(?P<id>[\d]+)', |
|
77 | + array( |
|
78 | + 'args' => array( |
|
79 | + 'id' => array( |
|
80 | + 'description' => __( 'Unique identifier for the object.', 'invoicing' ), |
|
81 | + 'type' => 'integer', |
|
82 | + ), |
|
83 | + ), |
|
84 | + array( |
|
85 | + 'methods' => WP_REST_Server::READABLE, |
|
86 | + 'callback' => array( $this, 'get_item' ), |
|
87 | + 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
88 | + 'args' => $get_item_args, |
|
89 | + ), |
|
90 | + array( |
|
91 | + 'methods' => WP_REST_Server::EDITABLE, |
|
92 | + 'callback' => array( $this, 'update_item' ), |
|
93 | + 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
94 | + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
95 | + ), |
|
96 | + array( |
|
97 | + 'methods' => WP_REST_Server::DELETABLE, |
|
98 | + 'callback' => array( $this, 'delete_item' ), |
|
99 | + 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
100 | + 'args' => array( |
|
101 | + 'force' => array( |
|
102 | + 'type' => 'boolean', |
|
103 | + 'default' => false, |
|
104 | + 'description' => __( 'Whether to bypass Trash and force deletion.', 'invoicing' ), |
|
105 | + ), |
|
106 | + ), |
|
107 | + ), |
|
108 | + 'schema' => array( $this, 'get_public_item_schema' ), |
|
109 | + ) |
|
110 | + ); |
|
111 | + |
|
112 | + register_rest_route( |
|
113 | + $namespace, |
|
114 | + '/' . $this->rest_base . '/batch', |
|
115 | + array( |
|
116 | + array( |
|
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 ), |
|
121 | + ), |
|
122 | + 'schema' => array( $this, 'get_public_batch_schema' ), |
|
123 | + ) |
|
124 | + ); |
|
125 | + |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Check permissions of items on REST API. |
|
130 | + * |
|
131 | + * @since 1.0.19 |
|
132 | + * @param string $context Request context. |
|
133 | + * @param int $object_id Post ID. |
|
134 | + * @return bool |
|
135 | + */ |
|
136 | + public function check_post_permissions( $context = 'read', $object_id = 0 ) { |
|
137 | + |
|
138 | + $contexts = array( |
|
139 | + 'read' => 'read_private_posts', |
|
140 | + 'create' => 'publish_posts', |
|
141 | + 'edit' => 'edit_post', |
|
142 | + 'delete' => 'delete_post', |
|
143 | + 'batch' => 'edit_others_posts', |
|
144 | + ); |
|
145 | + |
|
146 | + if ( 'revision' === $this->post_type ) { |
|
147 | + $permission = false; |
|
148 | + } else { |
|
149 | + $cap = $contexts[ $context ]; |
|
150 | + $post_type_object = get_post_type_object( $this->post_type ); |
|
151 | + $permission = current_user_can( $post_type_object->cap->$cap, $object_id ); |
|
152 | + } |
|
153 | + |
|
154 | + return apply_filters( 'getpaid_rest_check_permissions', $permission, $context, $object_id, $this->post_type ); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Check if a given request has access to read items. |
|
159 | + * |
|
160 | + * @param WP_REST_Request $request Full details about the request. |
|
161 | + * @return WP_Error|boolean |
|
162 | + */ |
|
163 | + public function get_items_permissions_check( $request ) { |
|
164 | + return $this->check_post_permissions() ? true : new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Check if a given request has access to create an item. |
|
169 | + * |
|
170 | + * @param WP_REST_Request $request Full details about the request. |
|
171 | + * @return WP_Error|boolean |
|
172 | + */ |
|
173 | + public function create_item_permissions_check( $request ) { |
|
174 | + return $this->check_post_permissions( 'create' ) ? true : new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Check if a given request has access to read an item. |
|
179 | + * |
|
180 | + * @param WP_REST_Request $request Full details about the request. |
|
181 | + * @return WP_Error|boolean |
|
182 | + */ |
|
183 | + public function get_item_permissions_check( $request ) { |
|
184 | + $post = get_post( (int) $request['id'] ); |
|
185 | + |
|
186 | + if ( $post && ! $this->check_post_permissions( 'read', $post->ID ) ) { |
|
187 | + return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
188 | + } |
|
189 | + |
|
190 | + return true; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Check if a given request has access to update an item. |
|
195 | + * |
|
196 | + * @param WP_REST_Request $request Full details about the request. |
|
197 | + * @return WP_Error|boolean |
|
198 | + */ |
|
199 | + public function update_item_permissions_check( $request ) { |
|
200 | + $post = get_post( (int) $request['id'] ); |
|
201 | + |
|
202 | + if ( $post && ! $this->check_post_permissions( 'edit', $post->ID ) ) { |
|
203 | + return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
204 | + } |
|
205 | + |
|
206 | + return true; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Check if a given request has access to delete an item. |
|
211 | + * |
|
212 | + * @param WP_REST_Request $request Full details about the request. |
|
213 | + * @return bool|WP_Error |
|
214 | + */ |
|
215 | + public function delete_item_permissions_check( $request ) { |
|
216 | + $post = get_post( (int) $request['id'] ); |
|
217 | + |
|
218 | + if ( $post && ! $this->check_post_permissions( 'delete', $post->ID ) ) { |
|
219 | + return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
220 | + } |
|
221 | + |
|
222 | + return true; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Check if a given request has access batch create, update and delete items. |
|
227 | + * |
|
228 | + * @param WP_REST_Request $request Full details about the request. |
|
229 | + * |
|
230 | + * @return boolean|WP_Error |
|
231 | + */ |
|
232 | + public function batch_items_permissions_check( $request ) { |
|
233 | + return $this->check_post_permissions( 'batch' ) ? true : new WP_Error( 'rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Saves a single object. |
|
238 | + * |
|
239 | + * @param GetPaid_Data $object Object to save. |
|
240 | + * @return WP_Error|GetPaid_Data |
|
241 | + */ |
|
242 | + protected function save_object( $object ) { |
|
243 | + $object->save(); |
|
244 | + |
|
245 | + if ( ! empty( $object->last_error ) ) { |
|
246 | + return new WP_Error( 'rest_cannot_save', $object->last_error, array( 'status' => 400 ) ); |
|
247 | + } |
|
248 | + |
|
249 | + return new $this->crud_class( $object->get_id() ); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Returns the item's object. |
|
254 | + * |
|
255 | + * Child classes must implement this method. |
|
256 | + * @since 1.0.13 |
|
257 | + * |
|
258 | + * @param int|WP_Post $object_id Supplied ID. |
|
259 | + * @return GetPaid_Data|WP_Error GetPaid_Data object if ID is valid, WP_Error otherwise. |
|
260 | + */ |
|
261 | + protected function get_object( $object_id ) { |
|
262 | + |
|
263 | + // Do we have an object? |
|
264 | + if ( empty( $this->crud_class ) || ! class_exists( $this->crud_class ) ) { |
|
265 | + return new WP_Error( 'no_crud_class', __( 'You need to specify a CRUD class for this controller', 'invoicing' ) ); |
|
266 | + } |
|
267 | + |
|
268 | + // Fetch the object. |
|
269 | + $object = new $this->crud_class( $object_id ); |
|
270 | + if ( ! empty( $object->last_error ) ) { |
|
271 | + return new WP_Error( 'rest_object_invalid_id', $object->last_error, array( 'status' => 404 ) ); |
|
272 | + } |
|
273 | + |
|
274 | + return $object->get_id() ? $object : new WP_Error( 'rest_object_invalid_id', __( 'Invalid ID.', 'invoicing' ), array( 'status' => 404 ) ); |
|
275 | + |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * @deprecated |
|
280 | - */ |
|
281 | - public function get_post( $object_id ) { |
|
282 | - return $this->get_object( $object_id ); |
|
278 | + /** |
|
279 | + * @deprecated |
|
280 | + */ |
|
281 | + public function get_post( $object_id ) { |
|
282 | + return $this->get_object( $object_id ); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Get a single object. |
|
287 | + * |
|
288 | + * @param WP_REST_Request $request Full details about the request. |
|
289 | + * @return WP_Error|WP_REST_Response |
|
290 | + */ |
|
291 | + public function get_item( $request ) { |
|
292 | + |
|
293 | + // Fetch the item. |
|
294 | + $object = $this->get_object( $request['id'] ); |
|
295 | + |
|
296 | + if ( is_wp_error( $object ) ) { |
|
297 | + return $object; |
|
298 | + } |
|
299 | + |
|
300 | + // Generate a response. |
|
301 | + $data = $this->prepare_item_for_response( $object, $request ); |
|
302 | + $response = rest_ensure_response( $data ); |
|
303 | + |
|
304 | + // (Maybe) add a link to the html pagee. |
|
305 | + if ( $this->public && ! is_wp_error( $response ) ) { |
|
306 | + $response->link_header( 'alternate', get_permalink( $object->get_id() ), array( 'type' => 'text/html' ) ); |
|
307 | + } |
|
308 | + |
|
309 | + return $response; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Create a single object. |
|
314 | + * |
|
315 | + * @param WP_REST_Request $request Full details about the request. |
|
316 | + * @return WP_Error|WP_REST_Response |
|
317 | + */ |
|
318 | + public function create_item( $request ) { |
|
319 | + |
|
320 | + // Can not create an existing item. |
|
321 | + if ( ! empty( $request['id'] ) ) { |
|
322 | + /* translators: %s: post type */ |
|
323 | + return new WP_Error( "getpaid_rest_{$this->post_type}_exists", __( 'Cannot create existing resource.', 'invoicing' ), array( 'status' => 400 ) ); |
|
324 | + } |
|
325 | + |
|
326 | + // Generate a GetPaid_Data object from the request. |
|
327 | + $object = $this->prepare_item_for_database( $request ); |
|
328 | + if ( is_wp_error( $object ) ) { |
|
329 | + return $object; |
|
330 | + } |
|
331 | + |
|
332 | + // Save the object. |
|
333 | + $object = $this->save_object( $object ); |
|
334 | + if ( is_wp_error( $object ) ) { |
|
335 | + return $object; |
|
336 | + } |
|
337 | + |
|
338 | + // Save special fields. |
|
339 | + $save_special = $this->update_additional_fields_for_object( $object, $request ); |
|
340 | + if ( is_wp_error( $save_special ) ) { |
|
341 | + $object->delete( true ); |
|
342 | + return $save_special; |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Fires after a single item is created or updated via the REST API. |
|
347 | + * |
|
348 | + * @param WP_Post $post Post object. |
|
349 | + * @param WP_REST_Request $request Request object. |
|
350 | + * @param boolean $creating True when creating item, false when updating. |
|
351 | + */ |
|
352 | + do_action( "getpaid_rest_insert_{$this->post_type}", $object, $request, true ); |
|
353 | + |
|
354 | + $request->set_param( 'context', 'edit' ); |
|
355 | + $response = $this->prepare_item_for_response( $object, $request ); |
|
356 | + $response = rest_ensure_response( $response ); |
|
357 | + $response->set_status( 201 ); |
|
358 | + $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ) ); |
|
359 | + |
|
360 | + return $response; |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Update a single object. |
|
365 | + * |
|
366 | + * @param WP_REST_Request $request Full details about the request. |
|
367 | + * @return WP_Error|WP_REST_Response |
|
368 | + */ |
|
369 | + public function update_item( $request ) { |
|
370 | + |
|
371 | + // Fetch the item. |
|
372 | + $object = $this->get_object( $request['id'] ); |
|
373 | + if ( is_wp_error( $object ) ) { |
|
374 | + return $object; |
|
375 | + } |
|
376 | + |
|
377 | + // Prepare the item for saving. |
|
378 | + $object = $this->prepare_item_for_database( $request ); |
|
379 | + if ( is_wp_error( $object ) ) { |
|
380 | + return $object; |
|
381 | + } |
|
382 | + |
|
383 | + // Save the item. |
|
384 | + $object = $this->save_object( $object ); |
|
385 | + if ( is_wp_error( $object ) ) { |
|
386 | + return $object; |
|
387 | + } |
|
388 | + |
|
389 | + // Save special fields (those added via hooks). |
|
390 | + $save_special = $this->update_additional_fields_for_object( $object, $request ); |
|
391 | + if ( is_wp_error( $save_special ) ) { |
|
392 | + return $save_special; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Fires after a single item is created or updated via the REST API. |
|
397 | + * |
|
398 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
399 | + * @param WP_REST_Request $request Request object. |
|
400 | + * @param boolean $creating True when creating item, false when updating. |
|
401 | + */ |
|
402 | + do_action( "getpaid_rest_insert_{$this->post_type}", $object, $request, false ); |
|
403 | + |
|
404 | + $request->set_param( 'context', 'edit' ); |
|
405 | + $response = $this->prepare_item_for_response( $object, $request ); |
|
406 | + return rest_ensure_response( $response ); |
|
283 | 407 | } |
284 | 408 | |
285 | - /** |
|
286 | - * Get a single object. |
|
287 | - * |
|
288 | - * @param WP_REST_Request $request Full details about the request. |
|
289 | - * @return WP_Error|WP_REST_Response |
|
290 | - */ |
|
291 | - public function get_item( $request ) { |
|
292 | - |
|
293 | - // Fetch the item. |
|
294 | - $object = $this->get_object( $request['id'] ); |
|
295 | - |
|
296 | - if ( is_wp_error( $object ) ) { |
|
297 | - return $object; |
|
298 | - } |
|
299 | - |
|
300 | - // Generate a response. |
|
301 | - $data = $this->prepare_item_for_response( $object, $request ); |
|
302 | - $response = rest_ensure_response( $data ); |
|
303 | - |
|
304 | - // (Maybe) add a link to the html pagee. |
|
305 | - if ( $this->public && ! is_wp_error( $response ) ) { |
|
306 | - $response->link_header( 'alternate', get_permalink( $object->get_id() ), array( 'type' => 'text/html' ) ); |
|
307 | - } |
|
308 | - |
|
309 | - return $response; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Create a single object. |
|
314 | - * |
|
315 | - * @param WP_REST_Request $request Full details about the request. |
|
316 | - * @return WP_Error|WP_REST_Response |
|
317 | - */ |
|
318 | - public function create_item( $request ) { |
|
319 | - |
|
320 | - // Can not create an existing item. |
|
321 | - if ( ! empty( $request['id'] ) ) { |
|
322 | - /* translators: %s: post type */ |
|
323 | - return new WP_Error( "getpaid_rest_{$this->post_type}_exists", __( 'Cannot create existing resource.', 'invoicing' ), array( 'status' => 400 ) ); |
|
324 | - } |
|
325 | - |
|
326 | - // Generate a GetPaid_Data object from the request. |
|
327 | - $object = $this->prepare_item_for_database( $request ); |
|
328 | - if ( is_wp_error( $object ) ) { |
|
329 | - return $object; |
|
330 | - } |
|
331 | - |
|
332 | - // Save the object. |
|
333 | - $object = $this->save_object( $object ); |
|
334 | - if ( is_wp_error( $object ) ) { |
|
335 | - return $object; |
|
336 | - } |
|
337 | - |
|
338 | - // Save special fields. |
|
339 | - $save_special = $this->update_additional_fields_for_object( $object, $request ); |
|
340 | - if ( is_wp_error( $save_special ) ) { |
|
341 | - $object->delete( true ); |
|
342 | - return $save_special; |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Fires after a single item is created or updated via the REST API. |
|
347 | - * |
|
348 | - * @param WP_Post $post Post object. |
|
349 | - * @param WP_REST_Request $request Request object. |
|
350 | - * @param boolean $creating True when creating item, false when updating. |
|
351 | - */ |
|
352 | - do_action( "getpaid_rest_insert_{$this->post_type}", $object, $request, true ); |
|
353 | - |
|
354 | - $request->set_param( 'context', 'edit' ); |
|
355 | - $response = $this->prepare_item_for_response( $object, $request ); |
|
356 | - $response = rest_ensure_response( $response ); |
|
357 | - $response->set_status( 201 ); |
|
358 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ) ); |
|
359 | - |
|
360 | - return $response; |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Update a single object. |
|
365 | - * |
|
366 | - * @param WP_REST_Request $request Full details about the request. |
|
367 | - * @return WP_Error|WP_REST_Response |
|
368 | - */ |
|
369 | - public function update_item( $request ) { |
|
370 | - |
|
371 | - // Fetch the item. |
|
372 | - $object = $this->get_object( $request['id'] ); |
|
373 | - if ( is_wp_error( $object ) ) { |
|
374 | - return $object; |
|
375 | - } |
|
376 | - |
|
377 | - // Prepare the item for saving. |
|
378 | - $object = $this->prepare_item_for_database( $request ); |
|
379 | - if ( is_wp_error( $object ) ) { |
|
380 | - return $object; |
|
381 | - } |
|
382 | - |
|
383 | - // Save the item. |
|
384 | - $object = $this->save_object( $object ); |
|
385 | - if ( is_wp_error( $object ) ) { |
|
386 | - return $object; |
|
387 | - } |
|
388 | - |
|
389 | - // Save special fields (those added via hooks). |
|
390 | - $save_special = $this->update_additional_fields_for_object( $object, $request ); |
|
391 | - if ( is_wp_error( $save_special ) ) { |
|
392 | - return $save_special; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Fires after a single item is created or updated via the REST API. |
|
397 | - * |
|
398 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
399 | - * @param WP_REST_Request $request Request object. |
|
400 | - * @param boolean $creating True when creating item, false when updating. |
|
401 | - */ |
|
402 | - do_action( "getpaid_rest_insert_{$this->post_type}", $object, $request, false ); |
|
403 | - |
|
404 | - $request->set_param( 'context', 'edit' ); |
|
405 | - $response = $this->prepare_item_for_response( $object, $request ); |
|
406 | - return rest_ensure_response( $response ); |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Get a collection of objects. |
|
411 | - * |
|
412 | - * @param WP_REST_Request $request Full details about the request. |
|
413 | - * @return WP_Error|WP_REST_Response |
|
414 | - */ |
|
415 | - public function get_items( $request ) { |
|
416 | - $args = array(); |
|
417 | - $args['offset'] = $request['offset']; |
|
418 | - $args['order'] = $request['order']; |
|
419 | - $args['orderby'] = $request['orderby']; |
|
420 | - $args['paged'] = $request['page']; |
|
421 | - $args['post__in'] = $request['include']; |
|
422 | - $args['post__not_in'] = $request['exclude']; |
|
423 | - $args['posts_per_page'] = $request['per_page']; |
|
424 | - $args['name'] = $request['slug']; |
|
425 | - $args['post_parent__in'] = $request['parent']; |
|
426 | - $args['post_parent__not_in'] = $request['parent_exclude']; |
|
427 | - $args['s'] = $request['search']; |
|
428 | - $args['post_status'] = $request['status'] == 'any' ? 'any' : wpinv_parse_list( $request['status'] ); |
|
429 | - |
|
430 | - $args['date_query'] = array(); |
|
431 | - // Set before into date query. Date query must be specified as an array of an array. |
|
432 | - if ( isset( $request['before'] ) ) { |
|
433 | - $args['date_query'][0]['before'] = $request['before']; |
|
434 | - } |
|
435 | - |
|
436 | - // Set after into date query. Date query must be specified as an array of an array. |
|
437 | - if ( isset( $request['after'] ) ) { |
|
438 | - $args['date_query'][0]['after'] = $request['after']; |
|
439 | - } |
|
440 | - |
|
441 | - // Force the post_type & fields arguments, since they're not a user input variable. |
|
442 | - $args['post_type'] = $this->post_type; |
|
443 | - $args['fields'] = 'ids'; |
|
444 | - |
|
445 | - // Filter the query arguments for a request. |
|
446 | - $args = apply_filters( "getpaid_rest_{$this->post_type}_query", $args, $request ); |
|
447 | - $query_args = $this->prepare_items_query( $args, $request ); |
|
448 | - |
|
449 | - $posts_query = new WP_Query(); |
|
450 | - $query_result = $posts_query->query( $query_args ); |
|
451 | - |
|
452 | - $posts = array(); |
|
453 | - foreach ( $query_result as $post_id ) { |
|
454 | - if ( ! $this->check_post_permissions( 'read', $post_id ) ) { |
|
455 | - continue; |
|
456 | - } |
|
457 | - |
|
458 | - $data = $this->prepare_item_for_response( $this->get_object( $post_id ), $request ); |
|
459 | - $posts[] = $this->prepare_response_for_collection( $data ); |
|
460 | - } |
|
461 | - |
|
462 | - $page = (int) $query_args['paged']; |
|
463 | - $total_posts = $posts_query->found_posts; |
|
464 | - |
|
465 | - if ( $total_posts < 1 ) { |
|
466 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
467 | - unset( $query_args['paged'] ); |
|
468 | - $count_query = new WP_Query(); |
|
469 | - $count_query->query( $query_args ); |
|
470 | - $total_posts = $count_query->found_posts; |
|
471 | - } |
|
472 | - |
|
473 | - $max_pages = ceil( $total_posts / (int) $query_args['posts_per_page'] ); |
|
474 | - |
|
475 | - $response = rest_ensure_response( $posts ); |
|
476 | - $response->header( 'X-WP-Total', (int) $total_posts ); |
|
477 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
478 | - |
|
479 | - $request_params = $request->get_query_params(); |
|
480 | - $base = add_query_arg( $request_params, rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
481 | - |
|
482 | - if ( $page > 1 ) { |
|
483 | - $prev_page = $page - 1; |
|
484 | - if ( $prev_page > $max_pages ) { |
|
485 | - $prev_page = $max_pages; |
|
486 | - } |
|
487 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
488 | - $response->link_header( 'prev', $prev_link ); |
|
489 | - } |
|
490 | - if ( $max_pages > $page ) { |
|
491 | - $next_page = $page + 1; |
|
492 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
493 | - $response->link_header( 'next', $next_link ); |
|
494 | - } |
|
495 | - |
|
496 | - return $response; |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * Delete a single item. |
|
501 | - * |
|
502 | - * @param WP_REST_Request $request Full details about the request. |
|
503 | - * @return WP_REST_Response|WP_Error |
|
504 | - */ |
|
505 | - public function delete_item( $request ) { |
|
506 | - |
|
507 | - // Fetch the item. |
|
508 | - $item = $this->get_object( $request['id'] ); |
|
509 | - if ( is_wp_error( $item ) ) { |
|
510 | - return $item; |
|
511 | - } |
|
512 | - |
|
513 | - $supports_trash = EMPTY_TRASH_DAYS > 0; |
|
514 | - $force = $supports_trash && (bool) $request['force']; |
|
515 | - |
|
516 | - if ( ! $this->check_post_permissions( 'delete', $item->ID ) ) { |
|
517 | - return new WP_Error( "cannot_delete", __( 'Sorry, you are not allowed to delete this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
518 | - } |
|
519 | - |
|
520 | - $request->set_param( 'context', 'edit' ); |
|
521 | - $response = $this->prepare_item_for_response( $item, $request ); |
|
522 | - |
|
523 | - if ( ! wp_delete_post( $item->ID, $force ) ) { |
|
524 | - return new WP_Error( 'rest_cannot_delete', sprintf( __( 'The resource cannot be deleted.', 'invoicing' ), $this->post_type ), array( 'status' => 500 ) ); |
|
525 | - } |
|
526 | - |
|
527 | - return $response; |
|
528 | - } |
|
529 | - |
|
530 | - /** |
|
531 | - * Prepare links for the request. |
|
532 | - * |
|
533 | - * @param GetPaid_Data $object GetPaid_Data object. |
|
534 | - * @return array Links for the given object. |
|
535 | - */ |
|
536 | - protected function prepare_links( $object ) { |
|
537 | - |
|
538 | - $links = array( |
|
539 | - 'self' => array( |
|
540 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ), |
|
541 | - ), |
|
542 | - 'collection' => array( |
|
543 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
544 | - ), |
|
545 | - ); |
|
546 | - |
|
547 | - if ( is_callable( array( $object, 'get_user_id' ) ) ) { |
|
548 | - $links['user'] = array( |
|
549 | - 'href' => rest_url( 'wp/v2/users/' . call_user_func( array( $object, 'get_user_id' ) ) ), |
|
550 | - 'embeddable' => true, |
|
551 | - ); |
|
552 | - } |
|
553 | - |
|
554 | - return $links; |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Determine the allowed query_vars for a get_items() response and |
|
559 | - * prepare for WP_Query. |
|
560 | - * |
|
561 | - * @param array $prepared_args Prepared arguments. |
|
562 | - * @param WP_REST_Request $request Request object. |
|
563 | - * @return array $query_args |
|
564 | - */ |
|
565 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
566 | - |
|
567 | - $valid_vars = array_flip( $this->get_allowed_query_vars() ); |
|
568 | - $query_args = array(); |
|
569 | - foreach ( $valid_vars as $var => $index ) { |
|
570 | - if ( isset( $prepared_args[ $var ] ) ) { |
|
571 | - $query_args[ $var ] = apply_filters( "getpaid_rest_query_var-{$var}", $prepared_args[ $var ] ); |
|
572 | - } |
|
573 | - } |
|
574 | - |
|
575 | - $query_args['ignore_sticky_posts'] = true; |
|
576 | - |
|
577 | - if ( 'include' === $query_args['orderby'] ) { |
|
578 | - $query_args['orderby'] = 'post__in'; |
|
579 | - } elseif ( 'id' === $query_args['orderby'] ) { |
|
580 | - $query_args['orderby'] = 'ID'; // ID must be capitalized. |
|
581 | - } elseif ( 'slug' === $query_args['orderby'] ) { |
|
582 | - $query_args['orderby'] = 'name'; |
|
583 | - } |
|
584 | - |
|
585 | - return apply_filters( 'getpaid_rest_prepare_items_query', $query_args, $request, $this ); |
|
586 | - |
|
587 | - } |
|
588 | - |
|
589 | - /** |
|
590 | - * Get all the WP Query vars that are allowed for the API request. |
|
591 | - * |
|
592 | - * @return array |
|
593 | - */ |
|
594 | - protected function get_allowed_query_vars() { |
|
595 | - global $wp; |
|
596 | - |
|
597 | - /** |
|
598 | - * Filter the publicly allowed query vars. |
|
599 | - * |
|
600 | - * Allows adjusting of the default query vars that are made public. |
|
601 | - * |
|
602 | - * @param array Array of allowed WP_Query query vars. |
|
603 | - */ |
|
604 | - $valid_vars = apply_filters( 'query_vars', $wp->public_query_vars ); |
|
605 | - |
|
606 | - $post_type_obj = get_post_type_object( $this->post_type ); |
|
607 | - if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { |
|
608 | - $private = apply_filters( 'getpaid_rest_private_query_vars', $wp->private_query_vars ); |
|
609 | - $valid_vars = array_merge( $valid_vars, $private ); |
|
610 | - } |
|
611 | - |
|
612 | - // Define our own in addition to WP's normal vars. |
|
613 | - $rest_valid = array( |
|
614 | - 'post_status', |
|
615 | - 'date_query', |
|
616 | - 'ignore_sticky_posts', |
|
617 | - 'offset', |
|
618 | - 'post__in', |
|
619 | - 'post__not_in', |
|
620 | - 'post_parent', |
|
621 | - 'post_parent__in', |
|
622 | - 'post_parent__not_in', |
|
623 | - 'posts_per_page', |
|
624 | - 'meta_query', |
|
625 | - 'tax_query', |
|
626 | - 'meta_key', |
|
627 | - 'meta_value', |
|
628 | - 'meta_compare', |
|
629 | - 'meta_value_num', |
|
630 | - ); |
|
631 | - $valid_vars = array_merge( $valid_vars, $rest_valid ); |
|
632 | - |
|
633 | - // Filter allowed query vars for the REST API. |
|
634 | - $valid_vars = apply_filters( 'getpaid_rest_query_vars', $valid_vars, $this ); |
|
635 | - |
|
636 | - return $valid_vars; |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * Get the query params for collections of attachments. |
|
641 | - * |
|
642 | - * @return array |
|
643 | - */ |
|
644 | - public function get_collection_params() { |
|
645 | - $params = parent::get_collection_params(); |
|
646 | - |
|
647 | - $params['context']['default'] = 'view'; |
|
648 | - |
|
649 | - $params['status'] = array( |
|
650 | - 'default' => 'any', |
|
651 | - 'description' => __( 'Limit result set to resources assigned one or more statuses.', 'invoicing' ), |
|
652 | - 'type' => array( 'array', 'string' ), |
|
653 | - 'items' => array( |
|
654 | - 'enum' => array_merge( array( 'any' ), $this->get_post_statuses() ), |
|
655 | - 'type' => 'string', |
|
656 | - ), |
|
657 | - 'sanitize_callback' => 'rest_validate_request_arg', |
|
658 | - ); |
|
659 | - |
|
660 | - $params['after'] = array( |
|
661 | - 'description' => __( 'Limit response to resources created after a given ISO8601 compliant date.', 'invoicing' ), |
|
662 | - 'type' => 'string', |
|
663 | - 'format' => 'string', |
|
664 | - 'validate_callback' => 'rest_validate_request_arg', |
|
665 | - ); |
|
666 | - $params['before'] = array( |
|
667 | - 'description' => __( 'Limit response to resources created before a given ISO8601 compliant date.', 'invoicing' ), |
|
668 | - 'type' => 'string', |
|
669 | - 'format' => 'string', |
|
670 | - 'validate_callback' => 'rest_validate_request_arg', |
|
671 | - ); |
|
672 | - $params['exclude'] = array( |
|
673 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'invoicing' ), |
|
674 | - 'type' => 'array', |
|
675 | - 'items' => array( |
|
676 | - 'type' => 'integer', |
|
677 | - ), |
|
678 | - 'default' => array(), |
|
679 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
680 | - ); |
|
681 | - $params['include'] = array( |
|
682 | - 'description' => __( 'Limit result set to specific ids.', 'invoicing' ), |
|
683 | - 'type' => 'array', |
|
684 | - 'items' => array( |
|
685 | - 'type' => 'integer', |
|
686 | - ), |
|
687 | - 'default' => array(), |
|
688 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
689 | - ); |
|
690 | - $params['offset'] = array( |
|
691 | - 'description' => __( 'Offset the result set by a specific number of items.', 'invoicing' ), |
|
692 | - 'type' => 'integer', |
|
693 | - 'sanitize_callback' => 'absint', |
|
694 | - 'validate_callback' => 'rest_validate_request_arg', |
|
695 | - ); |
|
696 | - $params['order'] = array( |
|
697 | - 'description' => __( 'Order sort attribute ascending or descending.', 'invoicing' ), |
|
698 | - 'type' => 'string', |
|
699 | - 'default' => 'desc', |
|
700 | - 'enum' => array( 'asc', 'desc' ), |
|
701 | - 'validate_callback' => 'rest_validate_request_arg', |
|
702 | - ); |
|
703 | - $params['orderby'] = array( |
|
704 | - 'description' => __( 'Sort collection by object attribute.', 'invoicing' ), |
|
705 | - 'type' => 'string', |
|
706 | - 'default' => 'date', |
|
707 | - 'enum' => array( |
|
708 | - 'date', |
|
709 | - 'id', |
|
710 | - 'include', |
|
711 | - 'title', |
|
712 | - 'slug', |
|
713 | - 'modified', |
|
714 | - ), |
|
715 | - 'validate_callback' => 'rest_validate_request_arg', |
|
716 | - ); |
|
717 | - |
|
718 | - $post_type_obj = get_post_type_object( $this->post_type ); |
|
719 | - |
|
720 | - if ( isset( $post_type_obj->hierarchical ) && $post_type_obj->hierarchical ) { |
|
721 | - $params['parent'] = array( |
|
722 | - 'description' => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ), |
|
723 | - 'type' => 'array', |
|
724 | - 'items' => array( |
|
725 | - 'type' => 'integer', |
|
726 | - ), |
|
727 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
728 | - 'default' => array(), |
|
729 | - ); |
|
730 | - $params['parent_exclude'] = array( |
|
731 | - 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ), |
|
732 | - 'type' => 'array', |
|
733 | - 'items' => array( |
|
734 | - 'type' => 'integer', |
|
735 | - ), |
|
736 | - 'sanitize_callback' => 'wp_parse_id_list', |
|
737 | - 'default' => array(), |
|
738 | - ); |
|
739 | - } |
|
740 | - |
|
741 | - return $params; |
|
742 | - } |
|
743 | - |
|
744 | - /** |
|
745 | - * Retrieves the items's schema, conforming to JSON Schema. |
|
746 | - * |
|
747 | - * @since 1.0.19 |
|
748 | - * |
|
749 | - * @return array Item schema data. |
|
750 | - */ |
|
751 | - public function get_item_schema() { |
|
752 | - |
|
753 | - // Maybe retrieve the schema from cache. |
|
754 | - if ( $this->schema ) { |
|
755 | - return $this->add_additional_fields_schema( $this->schema ); |
|
756 | - } |
|
757 | - |
|
758 | - $type = str_replace( 'wpi_', '', $this->post_type ); |
|
759 | - $schema = array( |
|
760 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
761 | - 'title' => $this->post_type, |
|
762 | - 'type' => 'object', |
|
763 | - 'properties' => wpinv_get_data( "$type-schema" ), |
|
764 | - ); |
|
765 | - |
|
766 | - // Filters the invoice schema for the REST API. |
|
409 | + /** |
|
410 | + * Get a collection of objects. |
|
411 | + * |
|
412 | + * @param WP_REST_Request $request Full details about the request. |
|
413 | + * @return WP_Error|WP_REST_Response |
|
414 | + */ |
|
415 | + public function get_items( $request ) { |
|
416 | + $args = array(); |
|
417 | + $args['offset'] = $request['offset']; |
|
418 | + $args['order'] = $request['order']; |
|
419 | + $args['orderby'] = $request['orderby']; |
|
420 | + $args['paged'] = $request['page']; |
|
421 | + $args['post__in'] = $request['include']; |
|
422 | + $args['post__not_in'] = $request['exclude']; |
|
423 | + $args['posts_per_page'] = $request['per_page']; |
|
424 | + $args['name'] = $request['slug']; |
|
425 | + $args['post_parent__in'] = $request['parent']; |
|
426 | + $args['post_parent__not_in'] = $request['parent_exclude']; |
|
427 | + $args['s'] = $request['search']; |
|
428 | + $args['post_status'] = $request['status'] == 'any' ? 'any' : wpinv_parse_list( $request['status'] ); |
|
429 | + |
|
430 | + $args['date_query'] = array(); |
|
431 | + // Set before into date query. Date query must be specified as an array of an array. |
|
432 | + if ( isset( $request['before'] ) ) { |
|
433 | + $args['date_query'][0]['before'] = $request['before']; |
|
434 | + } |
|
435 | + |
|
436 | + // Set after into date query. Date query must be specified as an array of an array. |
|
437 | + if ( isset( $request['after'] ) ) { |
|
438 | + $args['date_query'][0]['after'] = $request['after']; |
|
439 | + } |
|
440 | + |
|
441 | + // Force the post_type & fields arguments, since they're not a user input variable. |
|
442 | + $args['post_type'] = $this->post_type; |
|
443 | + $args['fields'] = 'ids'; |
|
444 | + |
|
445 | + // Filter the query arguments for a request. |
|
446 | + $args = apply_filters( "getpaid_rest_{$this->post_type}_query", $args, $request ); |
|
447 | + $query_args = $this->prepare_items_query( $args, $request ); |
|
448 | + |
|
449 | + $posts_query = new WP_Query(); |
|
450 | + $query_result = $posts_query->query( $query_args ); |
|
451 | + |
|
452 | + $posts = array(); |
|
453 | + foreach ( $query_result as $post_id ) { |
|
454 | + if ( ! $this->check_post_permissions( 'read', $post_id ) ) { |
|
455 | + continue; |
|
456 | + } |
|
457 | + |
|
458 | + $data = $this->prepare_item_for_response( $this->get_object( $post_id ), $request ); |
|
459 | + $posts[] = $this->prepare_response_for_collection( $data ); |
|
460 | + } |
|
461 | + |
|
462 | + $page = (int) $query_args['paged']; |
|
463 | + $total_posts = $posts_query->found_posts; |
|
464 | + |
|
465 | + if ( $total_posts < 1 ) { |
|
466 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
467 | + unset( $query_args['paged'] ); |
|
468 | + $count_query = new WP_Query(); |
|
469 | + $count_query->query( $query_args ); |
|
470 | + $total_posts = $count_query->found_posts; |
|
471 | + } |
|
472 | + |
|
473 | + $max_pages = ceil( $total_posts / (int) $query_args['posts_per_page'] ); |
|
474 | + |
|
475 | + $response = rest_ensure_response( $posts ); |
|
476 | + $response->header( 'X-WP-Total', (int) $total_posts ); |
|
477 | + $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
478 | + |
|
479 | + $request_params = $request->get_query_params(); |
|
480 | + $base = add_query_arg( $request_params, rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
481 | + |
|
482 | + if ( $page > 1 ) { |
|
483 | + $prev_page = $page - 1; |
|
484 | + if ( $prev_page > $max_pages ) { |
|
485 | + $prev_page = $max_pages; |
|
486 | + } |
|
487 | + $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
488 | + $response->link_header( 'prev', $prev_link ); |
|
489 | + } |
|
490 | + if ( $max_pages > $page ) { |
|
491 | + $next_page = $page + 1; |
|
492 | + $next_link = add_query_arg( 'page', $next_page, $base ); |
|
493 | + $response->link_header( 'next', $next_link ); |
|
494 | + } |
|
495 | + |
|
496 | + return $response; |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * Delete a single item. |
|
501 | + * |
|
502 | + * @param WP_REST_Request $request Full details about the request. |
|
503 | + * @return WP_REST_Response|WP_Error |
|
504 | + */ |
|
505 | + public function delete_item( $request ) { |
|
506 | + |
|
507 | + // Fetch the item. |
|
508 | + $item = $this->get_object( $request['id'] ); |
|
509 | + if ( is_wp_error( $item ) ) { |
|
510 | + return $item; |
|
511 | + } |
|
512 | + |
|
513 | + $supports_trash = EMPTY_TRASH_DAYS > 0; |
|
514 | + $force = $supports_trash && (bool) $request['force']; |
|
515 | + |
|
516 | + if ( ! $this->check_post_permissions( 'delete', $item->ID ) ) { |
|
517 | + return new WP_Error( "cannot_delete", __( 'Sorry, you are not allowed to delete this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
518 | + } |
|
519 | + |
|
520 | + $request->set_param( 'context', 'edit' ); |
|
521 | + $response = $this->prepare_item_for_response( $item, $request ); |
|
522 | + |
|
523 | + if ( ! wp_delete_post( $item->ID, $force ) ) { |
|
524 | + return new WP_Error( 'rest_cannot_delete', sprintf( __( 'The resource cannot be deleted.', 'invoicing' ), $this->post_type ), array( 'status' => 500 ) ); |
|
525 | + } |
|
526 | + |
|
527 | + return $response; |
|
528 | + } |
|
529 | + |
|
530 | + /** |
|
531 | + * Prepare links for the request. |
|
532 | + * |
|
533 | + * @param GetPaid_Data $object GetPaid_Data object. |
|
534 | + * @return array Links for the given object. |
|
535 | + */ |
|
536 | + protected function prepare_links( $object ) { |
|
537 | + |
|
538 | + $links = array( |
|
539 | + 'self' => array( |
|
540 | + 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ), |
|
541 | + ), |
|
542 | + 'collection' => array( |
|
543 | + 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
544 | + ), |
|
545 | + ); |
|
546 | + |
|
547 | + if ( is_callable( array( $object, 'get_user_id' ) ) ) { |
|
548 | + $links['user'] = array( |
|
549 | + 'href' => rest_url( 'wp/v2/users/' . call_user_func( array( $object, 'get_user_id' ) ) ), |
|
550 | + 'embeddable' => true, |
|
551 | + ); |
|
552 | + } |
|
553 | + |
|
554 | + return $links; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Determine the allowed query_vars for a get_items() response and |
|
559 | + * prepare for WP_Query. |
|
560 | + * |
|
561 | + * @param array $prepared_args Prepared arguments. |
|
562 | + * @param WP_REST_Request $request Request object. |
|
563 | + * @return array $query_args |
|
564 | + */ |
|
565 | + protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
566 | + |
|
567 | + $valid_vars = array_flip( $this->get_allowed_query_vars() ); |
|
568 | + $query_args = array(); |
|
569 | + foreach ( $valid_vars as $var => $index ) { |
|
570 | + if ( isset( $prepared_args[ $var ] ) ) { |
|
571 | + $query_args[ $var ] = apply_filters( "getpaid_rest_query_var-{$var}", $prepared_args[ $var ] ); |
|
572 | + } |
|
573 | + } |
|
574 | + |
|
575 | + $query_args['ignore_sticky_posts'] = true; |
|
576 | + |
|
577 | + if ( 'include' === $query_args['orderby'] ) { |
|
578 | + $query_args['orderby'] = 'post__in'; |
|
579 | + } elseif ( 'id' === $query_args['orderby'] ) { |
|
580 | + $query_args['orderby'] = 'ID'; // ID must be capitalized. |
|
581 | + } elseif ( 'slug' === $query_args['orderby'] ) { |
|
582 | + $query_args['orderby'] = 'name'; |
|
583 | + } |
|
584 | + |
|
585 | + return apply_filters( 'getpaid_rest_prepare_items_query', $query_args, $request, $this ); |
|
586 | + |
|
587 | + } |
|
588 | + |
|
589 | + /** |
|
590 | + * Get all the WP Query vars that are allowed for the API request. |
|
591 | + * |
|
592 | + * @return array |
|
593 | + */ |
|
594 | + protected function get_allowed_query_vars() { |
|
595 | + global $wp; |
|
596 | + |
|
597 | + /** |
|
598 | + * Filter the publicly allowed query vars. |
|
599 | + * |
|
600 | + * Allows adjusting of the default query vars that are made public. |
|
601 | + * |
|
602 | + * @param array Array of allowed WP_Query query vars. |
|
603 | + */ |
|
604 | + $valid_vars = apply_filters( 'query_vars', $wp->public_query_vars ); |
|
605 | + |
|
606 | + $post_type_obj = get_post_type_object( $this->post_type ); |
|
607 | + if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { |
|
608 | + $private = apply_filters( 'getpaid_rest_private_query_vars', $wp->private_query_vars ); |
|
609 | + $valid_vars = array_merge( $valid_vars, $private ); |
|
610 | + } |
|
611 | + |
|
612 | + // Define our own in addition to WP's normal vars. |
|
613 | + $rest_valid = array( |
|
614 | + 'post_status', |
|
615 | + 'date_query', |
|
616 | + 'ignore_sticky_posts', |
|
617 | + 'offset', |
|
618 | + 'post__in', |
|
619 | + 'post__not_in', |
|
620 | + 'post_parent', |
|
621 | + 'post_parent__in', |
|
622 | + 'post_parent__not_in', |
|
623 | + 'posts_per_page', |
|
624 | + 'meta_query', |
|
625 | + 'tax_query', |
|
626 | + 'meta_key', |
|
627 | + 'meta_value', |
|
628 | + 'meta_compare', |
|
629 | + 'meta_value_num', |
|
630 | + ); |
|
631 | + $valid_vars = array_merge( $valid_vars, $rest_valid ); |
|
632 | + |
|
633 | + // Filter allowed query vars for the REST API. |
|
634 | + $valid_vars = apply_filters( 'getpaid_rest_query_vars', $valid_vars, $this ); |
|
635 | + |
|
636 | + return $valid_vars; |
|
637 | + } |
|
638 | + |
|
639 | + /** |
|
640 | + * Get the query params for collections of attachments. |
|
641 | + * |
|
642 | + * @return array |
|
643 | + */ |
|
644 | + public function get_collection_params() { |
|
645 | + $params = parent::get_collection_params(); |
|
646 | + |
|
647 | + $params['context']['default'] = 'view'; |
|
648 | + |
|
649 | + $params['status'] = array( |
|
650 | + 'default' => 'any', |
|
651 | + 'description' => __( 'Limit result set to resources assigned one or more statuses.', 'invoicing' ), |
|
652 | + 'type' => array( 'array', 'string' ), |
|
653 | + 'items' => array( |
|
654 | + 'enum' => array_merge( array( 'any' ), $this->get_post_statuses() ), |
|
655 | + 'type' => 'string', |
|
656 | + ), |
|
657 | + 'sanitize_callback' => 'rest_validate_request_arg', |
|
658 | + ); |
|
659 | + |
|
660 | + $params['after'] = array( |
|
661 | + 'description' => __( 'Limit response to resources created after a given ISO8601 compliant date.', 'invoicing' ), |
|
662 | + 'type' => 'string', |
|
663 | + 'format' => 'string', |
|
664 | + 'validate_callback' => 'rest_validate_request_arg', |
|
665 | + ); |
|
666 | + $params['before'] = array( |
|
667 | + 'description' => __( 'Limit response to resources created before a given ISO8601 compliant date.', 'invoicing' ), |
|
668 | + 'type' => 'string', |
|
669 | + 'format' => 'string', |
|
670 | + 'validate_callback' => 'rest_validate_request_arg', |
|
671 | + ); |
|
672 | + $params['exclude'] = array( |
|
673 | + 'description' => __( 'Ensure result set excludes specific IDs.', 'invoicing' ), |
|
674 | + 'type' => 'array', |
|
675 | + 'items' => array( |
|
676 | + 'type' => 'integer', |
|
677 | + ), |
|
678 | + 'default' => array(), |
|
679 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
680 | + ); |
|
681 | + $params['include'] = array( |
|
682 | + 'description' => __( 'Limit result set to specific ids.', 'invoicing' ), |
|
683 | + 'type' => 'array', |
|
684 | + 'items' => array( |
|
685 | + 'type' => 'integer', |
|
686 | + ), |
|
687 | + 'default' => array(), |
|
688 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
689 | + ); |
|
690 | + $params['offset'] = array( |
|
691 | + 'description' => __( 'Offset the result set by a specific number of items.', 'invoicing' ), |
|
692 | + 'type' => 'integer', |
|
693 | + 'sanitize_callback' => 'absint', |
|
694 | + 'validate_callback' => 'rest_validate_request_arg', |
|
695 | + ); |
|
696 | + $params['order'] = array( |
|
697 | + 'description' => __( 'Order sort attribute ascending or descending.', 'invoicing' ), |
|
698 | + 'type' => 'string', |
|
699 | + 'default' => 'desc', |
|
700 | + 'enum' => array( 'asc', 'desc' ), |
|
701 | + 'validate_callback' => 'rest_validate_request_arg', |
|
702 | + ); |
|
703 | + $params['orderby'] = array( |
|
704 | + 'description' => __( 'Sort collection by object attribute.', 'invoicing' ), |
|
705 | + 'type' => 'string', |
|
706 | + 'default' => 'date', |
|
707 | + 'enum' => array( |
|
708 | + 'date', |
|
709 | + 'id', |
|
710 | + 'include', |
|
711 | + 'title', |
|
712 | + 'slug', |
|
713 | + 'modified', |
|
714 | + ), |
|
715 | + 'validate_callback' => 'rest_validate_request_arg', |
|
716 | + ); |
|
717 | + |
|
718 | + $post_type_obj = get_post_type_object( $this->post_type ); |
|
719 | + |
|
720 | + if ( isset( $post_type_obj->hierarchical ) && $post_type_obj->hierarchical ) { |
|
721 | + $params['parent'] = array( |
|
722 | + 'description' => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ), |
|
723 | + 'type' => 'array', |
|
724 | + 'items' => array( |
|
725 | + 'type' => 'integer', |
|
726 | + ), |
|
727 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
728 | + 'default' => array(), |
|
729 | + ); |
|
730 | + $params['parent_exclude'] = array( |
|
731 | + 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ), |
|
732 | + 'type' => 'array', |
|
733 | + 'items' => array( |
|
734 | + 'type' => 'integer', |
|
735 | + ), |
|
736 | + 'sanitize_callback' => 'wp_parse_id_list', |
|
737 | + 'default' => array(), |
|
738 | + ); |
|
739 | + } |
|
740 | + |
|
741 | + return $params; |
|
742 | + } |
|
743 | + |
|
744 | + /** |
|
745 | + * Retrieves the items's schema, conforming to JSON Schema. |
|
746 | + * |
|
747 | + * @since 1.0.19 |
|
748 | + * |
|
749 | + * @return array Item schema data. |
|
750 | + */ |
|
751 | + public function get_item_schema() { |
|
752 | + |
|
753 | + // Maybe retrieve the schema from cache. |
|
754 | + if ( $this->schema ) { |
|
755 | + return $this->add_additional_fields_schema( $this->schema ); |
|
756 | + } |
|
757 | + |
|
758 | + $type = str_replace( 'wpi_', '', $this->post_type ); |
|
759 | + $schema = array( |
|
760 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
761 | + 'title' => $this->post_type, |
|
762 | + 'type' => 'object', |
|
763 | + 'properties' => wpinv_get_data( "$type-schema" ), |
|
764 | + ); |
|
765 | + |
|
766 | + // Filters the invoice schema for the REST API. |
|
767 | 767 | $schema = apply_filters( "wpinv_rest_{$type}_schema", $schema ); |
768 | 768 | |
769 | - // Cache the invoice schema. |
|
770 | - $this->schema = $schema; |
|
771 | - |
|
772 | - return $this->add_additional_fields_schema( $this->schema ); |
|
773 | - } |
|
774 | - |
|
775 | - /** |
|
776 | - * Only return writable props from schema. |
|
777 | - * |
|
778 | - * @param array $schema Schema. |
|
779 | - * @return bool |
|
780 | - */ |
|
781 | - public function filter_writable_props( $schema ) { |
|
782 | - return empty( $schema['readonly'] ); |
|
783 | - } |
|
784 | - |
|
785 | - /** |
|
786 | - * Sanitizes and validates the list of post statuses. |
|
787 | - * |
|
788 | - * @since 1.0.13 |
|
789 | - * |
|
790 | - * @param string|array $statuses One or more post statuses. |
|
791 | - * @param WP_REST_Request $request Full details about the request. |
|
792 | - * @param string $parameter Additional parameter to pass to validation. |
|
793 | - * @return array|WP_Error A list of valid statuses, otherwise WP_Error object. |
|
794 | - */ |
|
795 | - public function sanitize_post_statuses( $statuses, $request, $parameter ) { |
|
796 | - return array_intersect( wp_parse_slug_list( $statuses ), $this->get_post_statuses() ); |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * Retrieves a valid list of post statuses. |
|
801 | - * |
|
802 | - * @since 1.0.19 |
|
803 | - * |
|
804 | - * @return array A list of registered item statuses. |
|
805 | - */ |
|
806 | - public function get_post_statuses() { |
|
807 | - return get_post_stati(); |
|
808 | - } |
|
809 | - |
|
810 | - /** |
|
811 | - * Prepare a single object for create or update. |
|
812 | - * |
|
813 | - * @since 1.0.19 |
|
814 | - * @param WP_REST_Request $request Request object. |
|
815 | - * @return GetPaid_Data|WP_Error Data object or WP_Error. |
|
816 | - */ |
|
817 | - protected function prepare_item_for_database( $request ) { |
|
818 | - |
|
819 | - // Do we have an object? |
|
820 | - if ( empty( $this->crud_class ) || ! class_exists( $this->crud_class ) ) { |
|
821 | - return new WP_Error( 'no_crud_class', __( 'You need to specify a CRUD class for this controller', 'invoicing' ) ); |
|
822 | - } |
|
823 | - |
|
824 | - // Prepare the object. |
|
825 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
826 | - $object = new $this->crud_class( $id ); |
|
827 | - |
|
828 | - // Abort if an error exists. |
|
829 | - if ( ! empty( $object->last_error ) ) { |
|
830 | - return new WP_Error( 'invalid_item', $object->last_error ); |
|
831 | - } |
|
832 | - |
|
833 | - $schema = $this->get_item_schema(); |
|
834 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
835 | - |
|
836 | - // Handle all writable props. |
|
837 | - foreach ( $data_keys as $key ) { |
|
838 | - $value = $request[ $key ]; |
|
839 | - |
|
840 | - if ( ! is_null( $value ) ) { |
|
841 | - switch ( $key ) { |
|
842 | - |
|
843 | - case 'meta_data': |
|
844 | - if ( is_array( $value ) ) { |
|
845 | - foreach ( $value as $meta ) { |
|
846 | - $object->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
847 | - } |
|
848 | - } |
|
849 | - break; |
|
850 | - |
|
851 | - default: |
|
852 | - if ( is_callable( array( $object, "set_{$key}" ) ) ) { |
|
853 | - $object->{"set_{$key}"}( $value ); |
|
854 | - } |
|
855 | - break; |
|
856 | - } |
|
857 | - } |
|
858 | - |
|
859 | - } |
|
860 | - |
|
861 | - // Filters an object before it is inserted via the REST API.. |
|
862 | - return apply_filters( "getpaid_rest_pre_insert_{$this->post_type}_object", $object, $request ); |
|
863 | - } |
|
864 | - |
|
865 | - /** |
|
866 | - * Retrieves data from a GetPaid class. |
|
867 | - * |
|
868 | - * @since 1.0.19 |
|
869 | - * @param GetPaid_Meta_Data[] $meta_data meta data objects. |
|
870 | - * @return array |
|
871 | - */ |
|
872 | - protected function prepare_object_meta_data( $meta_data ) { |
|
873 | - $meta = array(); |
|
874 | - |
|
875 | - foreach( $meta_data as $object ) { |
|
876 | - $meta[] = $object->get_data(); |
|
877 | - } |
|
878 | - |
|
879 | - return $meta; |
|
880 | - } |
|
881 | - |
|
882 | - /** |
|
883 | - * Retrieves invoice items. |
|
884 | - * |
|
885 | - * @since 1.0.19 |
|
886 | - * @param WPInv_Invoice $invoice Invoice items. |
|
887 | - * @return array |
|
888 | - */ |
|
889 | - protected function prepare_invoice_items( $invoice ) { |
|
890 | - $items = array(); |
|
891 | - |
|
892 | - foreach( $invoice->get_items() as $item ) { |
|
893 | - $item_data = $item->prepare_data_for_saving(); |
|
894 | - |
|
895 | - if ( 'amount' == $invoice->get_template() ) { |
|
896 | - $item_data['quantity'] = 1; |
|
897 | - } |
|
898 | - |
|
899 | - $items[] = $item_data; |
|
900 | - } |
|
901 | - |
|
902 | - return $items; |
|
903 | - } |
|
904 | - |
|
905 | - /** |
|
906 | - * Retrieves data from a GetPaid class. |
|
907 | - * |
|
908 | - * @since 1.0.19 |
|
909 | - * @param GetPaid_Data $object Data object. |
|
910 | - * @param array $fields Fields to include. |
|
911 | - * @param string $context either view or edit. |
|
912 | - * @return array |
|
913 | - */ |
|
914 | - protected function prepare_object_data( $object, $fields, $context = 'view' ) { |
|
915 | - |
|
916 | - $data = array(); |
|
917 | - $schema = $this->get_item_schema(); |
|
918 | - $data_keys = array_keys( $schema['properties'] ); |
|
919 | - |
|
920 | - // Handle all writable props. |
|
921 | - foreach ( $data_keys as $key ) { |
|
922 | - |
|
923 | - // Abort if it is not included. |
|
924 | - if ( ! empty( $fields ) && ! $this->is_field_included( $key, $fields ) ) { |
|
925 | - continue; |
|
926 | - } |
|
927 | - |
|
928 | - // Handle meta data. |
|
929 | - if ( $key == 'meta_data' ) { |
|
930 | - $data['meta_data'] = $this->prepare_object_meta_data( $object->get_meta_data() ); |
|
931 | - continue; |
|
932 | - } |
|
933 | - |
|
934 | - // Handle items. |
|
935 | - if ( $key == 'items' && is_a( $object, 'WPInv_Invoice' ) ) { |
|
936 | - $data['items'] = $this->prepare_invoice_items( $object ); |
|
937 | - continue; |
|
938 | - } |
|
939 | - |
|
940 | - // Booleans. |
|
941 | - if ( is_callable( array( $object, $key ) ) ) { |
|
942 | - $data[ $key ] = $object->$key( $context ); |
|
943 | - continue; |
|
944 | - } |
|
945 | - |
|
946 | - // Get object value. |
|
947 | - if ( is_callable( array( $object, "get_{$key}" ) ) ) { |
|
948 | - $value = $object->{"get_{$key}"}( $context ); |
|
949 | - |
|
950 | - // If the value is an instance of GetPaid_Data... |
|
951 | - if ( is_a( $value, 'GetPaid_Data' ) ) { |
|
952 | - $value = $value->get_data( $context ); |
|
953 | - } |
|
954 | - |
|
955 | - // For objects, retrieves it's properties. |
|
956 | - $data[ $key ] = is_object( $value ) ? get_object_vars( $value ) : $value ; |
|
957 | - continue; |
|
958 | - } |
|
959 | - |
|
960 | - // The value does not exist on an object. |
|
961 | - $data[ $key ] = apply_filters( "getpaid_{$this->post_type}_{$key}_object_data", null, $object ); |
|
962 | - |
|
963 | - } |
|
964 | - |
|
965 | - return $data; |
|
966 | - } |
|
967 | - |
|
968 | - /** |
|
969 | - * Prepare a single object output for response. |
|
970 | - * |
|
971 | - * @since 1.0.19 |
|
972 | - * @param GetPaid_Data $object Data object. |
|
973 | - * @param WP_REST_Request $request Request object. |
|
974 | - * @return WP_REST_Response |
|
975 | - */ |
|
976 | - public function prepare_item_for_response( $object, $request ) { |
|
977 | - |
|
978 | - // Fetch the fields to include in this response. |
|
979 | - $fields = $this->get_fields_for_response( $request ); |
|
980 | - |
|
981 | - // Prepare object data. |
|
982 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
983 | - $data = $this->prepare_object_data( $object, $fields, $context ); |
|
984 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
985 | - $data = $this->filter_response_by_context( $data, $context ); |
|
986 | - |
|
987 | - // Prepare the response. |
|
988 | - $response = rest_ensure_response( $data ); |
|
989 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
990 | - |
|
991 | - // Filter item response. |
|
992 | - return apply_filters( "getpaid_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
993 | - } |
|
769 | + // Cache the invoice schema. |
|
770 | + $this->schema = $schema; |
|
771 | + |
|
772 | + return $this->add_additional_fields_schema( $this->schema ); |
|
773 | + } |
|
774 | + |
|
775 | + /** |
|
776 | + * Only return writable props from schema. |
|
777 | + * |
|
778 | + * @param array $schema Schema. |
|
779 | + * @return bool |
|
780 | + */ |
|
781 | + public function filter_writable_props( $schema ) { |
|
782 | + return empty( $schema['readonly'] ); |
|
783 | + } |
|
784 | + |
|
785 | + /** |
|
786 | + * Sanitizes and validates the list of post statuses. |
|
787 | + * |
|
788 | + * @since 1.0.13 |
|
789 | + * |
|
790 | + * @param string|array $statuses One or more post statuses. |
|
791 | + * @param WP_REST_Request $request Full details about the request. |
|
792 | + * @param string $parameter Additional parameter to pass to validation. |
|
793 | + * @return array|WP_Error A list of valid statuses, otherwise WP_Error object. |
|
794 | + */ |
|
795 | + public function sanitize_post_statuses( $statuses, $request, $parameter ) { |
|
796 | + return array_intersect( wp_parse_slug_list( $statuses ), $this->get_post_statuses() ); |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * Retrieves a valid list of post statuses. |
|
801 | + * |
|
802 | + * @since 1.0.19 |
|
803 | + * |
|
804 | + * @return array A list of registered item statuses. |
|
805 | + */ |
|
806 | + public function get_post_statuses() { |
|
807 | + return get_post_stati(); |
|
808 | + } |
|
809 | + |
|
810 | + /** |
|
811 | + * Prepare a single object for create or update. |
|
812 | + * |
|
813 | + * @since 1.0.19 |
|
814 | + * @param WP_REST_Request $request Request object. |
|
815 | + * @return GetPaid_Data|WP_Error Data object or WP_Error. |
|
816 | + */ |
|
817 | + protected function prepare_item_for_database( $request ) { |
|
818 | + |
|
819 | + // Do we have an object? |
|
820 | + if ( empty( $this->crud_class ) || ! class_exists( $this->crud_class ) ) { |
|
821 | + return new WP_Error( 'no_crud_class', __( 'You need to specify a CRUD class for this controller', 'invoicing' ) ); |
|
822 | + } |
|
823 | + |
|
824 | + // Prepare the object. |
|
825 | + $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
826 | + $object = new $this->crud_class( $id ); |
|
827 | + |
|
828 | + // Abort if an error exists. |
|
829 | + if ( ! empty( $object->last_error ) ) { |
|
830 | + return new WP_Error( 'invalid_item', $object->last_error ); |
|
831 | + } |
|
832 | + |
|
833 | + $schema = $this->get_item_schema(); |
|
834 | + $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
835 | + |
|
836 | + // Handle all writable props. |
|
837 | + foreach ( $data_keys as $key ) { |
|
838 | + $value = $request[ $key ]; |
|
839 | + |
|
840 | + if ( ! is_null( $value ) ) { |
|
841 | + switch ( $key ) { |
|
842 | + |
|
843 | + case 'meta_data': |
|
844 | + if ( is_array( $value ) ) { |
|
845 | + foreach ( $value as $meta ) { |
|
846 | + $object->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
847 | + } |
|
848 | + } |
|
849 | + break; |
|
850 | + |
|
851 | + default: |
|
852 | + if ( is_callable( array( $object, "set_{$key}" ) ) ) { |
|
853 | + $object->{"set_{$key}"}( $value ); |
|
854 | + } |
|
855 | + break; |
|
856 | + } |
|
857 | + } |
|
858 | + |
|
859 | + } |
|
860 | + |
|
861 | + // Filters an object before it is inserted via the REST API.. |
|
862 | + return apply_filters( "getpaid_rest_pre_insert_{$this->post_type}_object", $object, $request ); |
|
863 | + } |
|
864 | + |
|
865 | + /** |
|
866 | + * Retrieves data from a GetPaid class. |
|
867 | + * |
|
868 | + * @since 1.0.19 |
|
869 | + * @param GetPaid_Meta_Data[] $meta_data meta data objects. |
|
870 | + * @return array |
|
871 | + */ |
|
872 | + protected function prepare_object_meta_data( $meta_data ) { |
|
873 | + $meta = array(); |
|
874 | + |
|
875 | + foreach( $meta_data as $object ) { |
|
876 | + $meta[] = $object->get_data(); |
|
877 | + } |
|
878 | + |
|
879 | + return $meta; |
|
880 | + } |
|
881 | + |
|
882 | + /** |
|
883 | + * Retrieves invoice items. |
|
884 | + * |
|
885 | + * @since 1.0.19 |
|
886 | + * @param WPInv_Invoice $invoice Invoice items. |
|
887 | + * @return array |
|
888 | + */ |
|
889 | + protected function prepare_invoice_items( $invoice ) { |
|
890 | + $items = array(); |
|
891 | + |
|
892 | + foreach( $invoice->get_items() as $item ) { |
|
893 | + $item_data = $item->prepare_data_for_saving(); |
|
894 | + |
|
895 | + if ( 'amount' == $invoice->get_template() ) { |
|
896 | + $item_data['quantity'] = 1; |
|
897 | + } |
|
898 | + |
|
899 | + $items[] = $item_data; |
|
900 | + } |
|
901 | + |
|
902 | + return $items; |
|
903 | + } |
|
904 | + |
|
905 | + /** |
|
906 | + * Retrieves data from a GetPaid class. |
|
907 | + * |
|
908 | + * @since 1.0.19 |
|
909 | + * @param GetPaid_Data $object Data object. |
|
910 | + * @param array $fields Fields to include. |
|
911 | + * @param string $context either view or edit. |
|
912 | + * @return array |
|
913 | + */ |
|
914 | + protected function prepare_object_data( $object, $fields, $context = 'view' ) { |
|
915 | + |
|
916 | + $data = array(); |
|
917 | + $schema = $this->get_item_schema(); |
|
918 | + $data_keys = array_keys( $schema['properties'] ); |
|
919 | + |
|
920 | + // Handle all writable props. |
|
921 | + foreach ( $data_keys as $key ) { |
|
922 | + |
|
923 | + // Abort if it is not included. |
|
924 | + if ( ! empty( $fields ) && ! $this->is_field_included( $key, $fields ) ) { |
|
925 | + continue; |
|
926 | + } |
|
927 | + |
|
928 | + // Handle meta data. |
|
929 | + if ( $key == 'meta_data' ) { |
|
930 | + $data['meta_data'] = $this->prepare_object_meta_data( $object->get_meta_data() ); |
|
931 | + continue; |
|
932 | + } |
|
933 | + |
|
934 | + // Handle items. |
|
935 | + if ( $key == 'items' && is_a( $object, 'WPInv_Invoice' ) ) { |
|
936 | + $data['items'] = $this->prepare_invoice_items( $object ); |
|
937 | + continue; |
|
938 | + } |
|
939 | + |
|
940 | + // Booleans. |
|
941 | + if ( is_callable( array( $object, $key ) ) ) { |
|
942 | + $data[ $key ] = $object->$key( $context ); |
|
943 | + continue; |
|
944 | + } |
|
945 | + |
|
946 | + // Get object value. |
|
947 | + if ( is_callable( array( $object, "get_{$key}" ) ) ) { |
|
948 | + $value = $object->{"get_{$key}"}( $context ); |
|
949 | + |
|
950 | + // If the value is an instance of GetPaid_Data... |
|
951 | + if ( is_a( $value, 'GetPaid_Data' ) ) { |
|
952 | + $value = $value->get_data( $context ); |
|
953 | + } |
|
954 | + |
|
955 | + // For objects, retrieves it's properties. |
|
956 | + $data[ $key ] = is_object( $value ) ? get_object_vars( $value ) : $value ; |
|
957 | + continue; |
|
958 | + } |
|
959 | + |
|
960 | + // The value does not exist on an object. |
|
961 | + $data[ $key ] = apply_filters( "getpaid_{$this->post_type}_{$key}_object_data", null, $object ); |
|
962 | + |
|
963 | + } |
|
964 | + |
|
965 | + return $data; |
|
966 | + } |
|
967 | + |
|
968 | + /** |
|
969 | + * Prepare a single object output for response. |
|
970 | + * |
|
971 | + * @since 1.0.19 |
|
972 | + * @param GetPaid_Data $object Data object. |
|
973 | + * @param WP_REST_Request $request Request object. |
|
974 | + * @return WP_REST_Response |
|
975 | + */ |
|
976 | + public function prepare_item_for_response( $object, $request ) { |
|
977 | + |
|
978 | + // Fetch the fields to include in this response. |
|
979 | + $fields = $this->get_fields_for_response( $request ); |
|
980 | + |
|
981 | + // Prepare object data. |
|
982 | + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
983 | + $data = $this->prepare_object_data( $object, $fields, $context ); |
|
984 | + $data = $this->add_additional_fields_to_object( $data, $request ); |
|
985 | + $data = $this->filter_response_by_context( $data, $context ); |
|
986 | + |
|
987 | + // Prepare the response. |
|
988 | + $response = rest_ensure_response( $data ); |
|
989 | + $response->add_links( $this->prepare_links( $object, $request ) ); |
|
990 | + |
|
991 | + // Filter item response. |
|
992 | + return apply_filters( "getpaid_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
993 | + } |
|
994 | 994 | |
995 | 995 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @version 1.0.19 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * GetPaid REST Posts controller class. |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @see register_rest_route() |
47 | 47 | */ |
48 | - public function register_namespace_routes( $namespace ) { |
|
48 | + public function register_namespace_routes($namespace) { |
|
49 | 49 | |
50 | 50 | register_rest_route( |
51 | 51 | $namespace, |
@@ -53,22 +53,22 @@ discard block |
||
53 | 53 | array( |
54 | 54 | array( |
55 | 55 | 'methods' => WP_REST_Server::READABLE, |
56 | - 'callback' => array( $this, 'get_items' ), |
|
57 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
56 | + 'callback' => array($this, 'get_items'), |
|
57 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
58 | 58 | 'args' => $this->get_collection_params(), |
59 | 59 | ), |
60 | 60 | array( |
61 | 61 | 'methods' => WP_REST_Server::CREATABLE, |
62 | - 'callback' => array( $this, 'create_item' ), |
|
63 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
64 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
62 | + 'callback' => array($this, 'create_item'), |
|
63 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
64 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
65 | 65 | ), |
66 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
66 | + 'schema' => array($this, 'get_public_item_schema'), |
|
67 | 67 | ) |
68 | 68 | ); |
69 | 69 | |
70 | 70 | $get_item_args = array( |
71 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
71 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
72 | 72 | ); |
73 | 73 | |
74 | 74 | register_rest_route( |
@@ -77,35 +77,35 @@ discard block |
||
77 | 77 | array( |
78 | 78 | 'args' => array( |
79 | 79 | 'id' => array( |
80 | - 'description' => __( 'Unique identifier for the object.', 'invoicing' ), |
|
80 | + 'description' => __('Unique identifier for the object.', 'invoicing'), |
|
81 | 81 | 'type' => 'integer', |
82 | 82 | ), |
83 | 83 | ), |
84 | 84 | array( |
85 | 85 | 'methods' => WP_REST_Server::READABLE, |
86 | - 'callback' => array( $this, 'get_item' ), |
|
87 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
86 | + 'callback' => array($this, 'get_item'), |
|
87 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
88 | 88 | 'args' => $get_item_args, |
89 | 89 | ), |
90 | 90 | array( |
91 | 91 | 'methods' => WP_REST_Server::EDITABLE, |
92 | - 'callback' => array( $this, 'update_item' ), |
|
93 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
94 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
92 | + 'callback' => array($this, 'update_item'), |
|
93 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
94 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
95 | 95 | ), |
96 | 96 | array( |
97 | 97 | 'methods' => WP_REST_Server::DELETABLE, |
98 | - 'callback' => array( $this, 'delete_item' ), |
|
99 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
98 | + 'callback' => array($this, 'delete_item'), |
|
99 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
100 | 100 | 'args' => array( |
101 | 101 | 'force' => array( |
102 | 102 | 'type' => 'boolean', |
103 | 103 | 'default' => false, |
104 | - 'description' => __( 'Whether to bypass Trash and force deletion.', 'invoicing' ), |
|
104 | + 'description' => __('Whether to bypass Trash and force deletion.', 'invoicing'), |
|
105 | 105 | ), |
106 | 106 | ), |
107 | 107 | ), |
108 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
108 | + 'schema' => array($this, 'get_public_item_schema'), |
|
109 | 109 | ) |
110 | 110 | ); |
111 | 111 | |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | 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' ), |
|
122 | + 'schema' => array($this, 'get_public_batch_schema'), |
|
123 | 123 | ) |
124 | 124 | ); |
125 | 125 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param int $object_id Post ID. |
134 | 134 | * @return bool |
135 | 135 | */ |
136 | - public function check_post_permissions( $context = 'read', $object_id = 0 ) { |
|
136 | + public function check_post_permissions($context = 'read', $object_id = 0) { |
|
137 | 137 | |
138 | 138 | $contexts = array( |
139 | 139 | 'read' => 'read_private_posts', |
@@ -143,15 +143,15 @@ discard block |
||
143 | 143 | 'batch' => 'edit_others_posts', |
144 | 144 | ); |
145 | 145 | |
146 | - if ( 'revision' === $this->post_type ) { |
|
146 | + if ('revision' === $this->post_type) { |
|
147 | 147 | $permission = false; |
148 | 148 | } else { |
149 | - $cap = $contexts[ $context ]; |
|
150 | - $post_type_object = get_post_type_object( $this->post_type ); |
|
151 | - $permission = current_user_can( $post_type_object->cap->$cap, $object_id ); |
|
149 | + $cap = $contexts[$context]; |
|
150 | + $post_type_object = get_post_type_object($this->post_type); |
|
151 | + $permission = current_user_can($post_type_object->cap->$cap, $object_id); |
|
152 | 152 | } |
153 | 153 | |
154 | - return apply_filters( 'getpaid_rest_check_permissions', $permission, $context, $object_id, $this->post_type ); |
|
154 | + return apply_filters('getpaid_rest_check_permissions', $permission, $context, $object_id, $this->post_type); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | * @param WP_REST_Request $request Full details about the request. |
161 | 161 | * @return WP_Error|boolean |
162 | 162 | */ |
163 | - public function get_items_permissions_check( $request ) { |
|
164 | - return $this->check_post_permissions() ? true : new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot list resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
163 | + public function get_items_permissions_check($request) { |
|
164 | + return $this->check_post_permissions() ? true : new WP_Error('rest_cannot_view', __('Sorry, you cannot list resources.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | * @param WP_REST_Request $request Full details about the request. |
171 | 171 | * @return WP_Error|boolean |
172 | 172 | */ |
173 | - public function create_item_permissions_check( $request ) { |
|
174 | - return $this->check_post_permissions( 'create' ) ? true : new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create resources.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
173 | + public function create_item_permissions_check($request) { |
|
174 | + return $this->check_post_permissions('create') ? true : new WP_Error('rest_cannot_create', __('Sorry, you are not allowed to create resources.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | * @param WP_REST_Request $request Full details about the request. |
181 | 181 | * @return WP_Error|boolean |
182 | 182 | */ |
183 | - public function get_item_permissions_check( $request ) { |
|
184 | - $post = get_post( (int) $request['id'] ); |
|
183 | + public function get_item_permissions_check($request) { |
|
184 | + $post = get_post((int) $request['id']); |
|
185 | 185 | |
186 | - if ( $post && ! $this->check_post_permissions( 'read', $post->ID ) ) { |
|
187 | - return new WP_Error( 'rest_cannot_view', __( 'Sorry, you cannot view this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
186 | + if ($post && !$this->check_post_permissions('read', $post->ID)) { |
|
187 | + return new WP_Error('rest_cannot_view', __('Sorry, you cannot view this resource.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | return true; |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | * @param WP_REST_Request $request Full details about the request. |
197 | 197 | * @return WP_Error|boolean |
198 | 198 | */ |
199 | - public function update_item_permissions_check( $request ) { |
|
200 | - $post = get_post( (int) $request['id'] ); |
|
199 | + public function update_item_permissions_check($request) { |
|
200 | + $post = get_post((int) $request['id']); |
|
201 | 201 | |
202 | - if ( $post && ! $this->check_post_permissions( 'edit', $post->ID ) ) { |
|
203 | - return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
202 | + if ($post && !$this->check_post_permissions('edit', $post->ID)) { |
|
203 | + return new WP_Error('rest_cannot_edit', __('Sorry, you are not allowed to edit this resource.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | return true; |
@@ -212,11 +212,11 @@ discard block |
||
212 | 212 | * @param WP_REST_Request $request Full details about the request. |
213 | 213 | * @return bool|WP_Error |
214 | 214 | */ |
215 | - public function delete_item_permissions_check( $request ) { |
|
216 | - $post = get_post( (int) $request['id'] ); |
|
215 | + public function delete_item_permissions_check($request) { |
|
216 | + $post = get_post((int) $request['id']); |
|
217 | 217 | |
218 | - if ( $post && ! $this->check_post_permissions( 'delete', $post->ID ) ) { |
|
219 | - return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
218 | + if ($post && !$this->check_post_permissions('delete', $post->ID)) { |
|
219 | + return new WP_Error('rest_cannot_delete', __('Sorry, you are not allowed to delete this resource.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | return true; |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return boolean|WP_Error |
231 | 231 | */ |
232 | - public function batch_items_permissions_check( $request ) { |
|
233 | - return $this->check_post_permissions( 'batch' ) ? true : new WP_Error( 'rest_cannot_batch', __( 'Sorry, you are not allowed to batch manipulate this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
232 | + public function batch_items_permissions_check($request) { |
|
233 | + return $this->check_post_permissions('batch') ? true : new WP_Error('rest_cannot_batch', __('Sorry, you are not allowed to batch manipulate this resource.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -239,14 +239,14 @@ discard block |
||
239 | 239 | * @param GetPaid_Data $object Object to save. |
240 | 240 | * @return WP_Error|GetPaid_Data |
241 | 241 | */ |
242 | - protected function save_object( $object ) { |
|
242 | + protected function save_object($object) { |
|
243 | 243 | $object->save(); |
244 | 244 | |
245 | - if ( ! empty( $object->last_error ) ) { |
|
246 | - return new WP_Error( 'rest_cannot_save', $object->last_error, array( 'status' => 400 ) ); |
|
245 | + if (!empty($object->last_error)) { |
|
246 | + return new WP_Error('rest_cannot_save', $object->last_error, array('status' => 400)); |
|
247 | 247 | } |
248 | 248 | |
249 | - return new $this->crud_class( $object->get_id() ); |
|
249 | + return new $this->crud_class($object->get_id()); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -258,28 +258,28 @@ discard block |
||
258 | 258 | * @param int|WP_Post $object_id Supplied ID. |
259 | 259 | * @return GetPaid_Data|WP_Error GetPaid_Data object if ID is valid, WP_Error otherwise. |
260 | 260 | */ |
261 | - protected function get_object( $object_id ) { |
|
261 | + protected function get_object($object_id) { |
|
262 | 262 | |
263 | 263 | // Do we have an object? |
264 | - if ( empty( $this->crud_class ) || ! class_exists( $this->crud_class ) ) { |
|
265 | - return new WP_Error( 'no_crud_class', __( 'You need to specify a CRUD class for this controller', 'invoicing' ) ); |
|
264 | + if (empty($this->crud_class) || !class_exists($this->crud_class)) { |
|
265 | + return new WP_Error('no_crud_class', __('You need to specify a CRUD class for this controller', 'invoicing')); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | // Fetch the object. |
269 | - $object = new $this->crud_class( $object_id ); |
|
270 | - if ( ! empty( $object->last_error ) ) { |
|
271 | - return new WP_Error( 'rest_object_invalid_id', $object->last_error, array( 'status' => 404 ) ); |
|
269 | + $object = new $this->crud_class($object_id); |
|
270 | + if (!empty($object->last_error)) { |
|
271 | + return new WP_Error('rest_object_invalid_id', $object->last_error, array('status' => 404)); |
|
272 | 272 | } |
273 | 273 | |
274 | - return $object->get_id() ? $object : new WP_Error( 'rest_object_invalid_id', __( 'Invalid ID.', 'invoicing' ), array( 'status' => 404 ) ); |
|
274 | + return $object->get_id() ? $object : new WP_Error('rest_object_invalid_id', __('Invalid ID.', 'invoicing'), array('status' => 404)); |
|
275 | 275 | |
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
279 | 279 | * @deprecated |
280 | 280 | */ |
281 | - public function get_post( $object_id ) { |
|
282 | - return $this->get_object( $object_id ); |
|
281 | + public function get_post($object_id) { |
|
282 | + return $this->get_object($object_id); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -288,22 +288,22 @@ discard block |
||
288 | 288 | * @param WP_REST_Request $request Full details about the request. |
289 | 289 | * @return WP_Error|WP_REST_Response |
290 | 290 | */ |
291 | - public function get_item( $request ) { |
|
291 | + public function get_item($request) { |
|
292 | 292 | |
293 | 293 | // Fetch the item. |
294 | - $object = $this->get_object( $request['id'] ); |
|
294 | + $object = $this->get_object($request['id']); |
|
295 | 295 | |
296 | - if ( is_wp_error( $object ) ) { |
|
296 | + if (is_wp_error($object)) { |
|
297 | 297 | return $object; |
298 | 298 | } |
299 | 299 | |
300 | 300 | // Generate a response. |
301 | - $data = $this->prepare_item_for_response( $object, $request ); |
|
302 | - $response = rest_ensure_response( $data ); |
|
301 | + $data = $this->prepare_item_for_response($object, $request); |
|
302 | + $response = rest_ensure_response($data); |
|
303 | 303 | |
304 | 304 | // (Maybe) add a link to the html pagee. |
305 | - if ( $this->public && ! is_wp_error( $response ) ) { |
|
306 | - $response->link_header( 'alternate', get_permalink( $object->get_id() ), array( 'type' => 'text/html' ) ); |
|
305 | + if ($this->public && !is_wp_error($response)) { |
|
306 | + $response->link_header('alternate', get_permalink($object->get_id()), array('type' => 'text/html')); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | return $response; |
@@ -315,30 +315,30 @@ discard block |
||
315 | 315 | * @param WP_REST_Request $request Full details about the request. |
316 | 316 | * @return WP_Error|WP_REST_Response |
317 | 317 | */ |
318 | - public function create_item( $request ) { |
|
318 | + public function create_item($request) { |
|
319 | 319 | |
320 | 320 | // Can not create an existing item. |
321 | - if ( ! empty( $request['id'] ) ) { |
|
321 | + if (!empty($request['id'])) { |
|
322 | 322 | /* translators: %s: post type */ |
323 | - return new WP_Error( "getpaid_rest_{$this->post_type}_exists", __( 'Cannot create existing resource.', 'invoicing' ), array( 'status' => 400 ) ); |
|
323 | + return new WP_Error("getpaid_rest_{$this->post_type}_exists", __('Cannot create existing resource.', 'invoicing'), array('status' => 400)); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | // Generate a GetPaid_Data object from the request. |
327 | - $object = $this->prepare_item_for_database( $request ); |
|
328 | - if ( is_wp_error( $object ) ) { |
|
327 | + $object = $this->prepare_item_for_database($request); |
|
328 | + if (is_wp_error($object)) { |
|
329 | 329 | return $object; |
330 | 330 | } |
331 | 331 | |
332 | 332 | // Save the object. |
333 | - $object = $this->save_object( $object ); |
|
334 | - if ( is_wp_error( $object ) ) { |
|
333 | + $object = $this->save_object($object); |
|
334 | + if (is_wp_error($object)) { |
|
335 | 335 | return $object; |
336 | 336 | } |
337 | 337 | |
338 | 338 | // Save special fields. |
339 | - $save_special = $this->update_additional_fields_for_object( $object, $request ); |
|
340 | - if ( is_wp_error( $save_special ) ) { |
|
341 | - $object->delete( true ); |
|
339 | + $save_special = $this->update_additional_fields_for_object($object, $request); |
|
340 | + if (is_wp_error($save_special)) { |
|
341 | + $object->delete(true); |
|
342 | 342 | return $save_special; |
343 | 343 | } |
344 | 344 | |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | * @param WP_REST_Request $request Request object. |
350 | 350 | * @param boolean $creating True when creating item, false when updating. |
351 | 351 | */ |
352 | - do_action( "getpaid_rest_insert_{$this->post_type}", $object, $request, true ); |
|
352 | + do_action("getpaid_rest_insert_{$this->post_type}", $object, $request, true); |
|
353 | 353 | |
354 | - $request->set_param( 'context', 'edit' ); |
|
355 | - $response = $this->prepare_item_for_response( $object, $request ); |
|
356 | - $response = rest_ensure_response( $response ); |
|
357 | - $response->set_status( 201 ); |
|
358 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ) ); |
|
354 | + $request->set_param('context', 'edit'); |
|
355 | + $response = $this->prepare_item_for_response($object, $request); |
|
356 | + $response = rest_ensure_response($response); |
|
357 | + $response->set_status(201); |
|
358 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id()))); |
|
359 | 359 | |
360 | 360 | return $response; |
361 | 361 | } |
@@ -366,29 +366,29 @@ discard block |
||
366 | 366 | * @param WP_REST_Request $request Full details about the request. |
367 | 367 | * @return WP_Error|WP_REST_Response |
368 | 368 | */ |
369 | - public function update_item( $request ) { |
|
369 | + public function update_item($request) { |
|
370 | 370 | |
371 | 371 | // Fetch the item. |
372 | - $object = $this->get_object( $request['id'] ); |
|
373 | - if ( is_wp_error( $object ) ) { |
|
372 | + $object = $this->get_object($request['id']); |
|
373 | + if (is_wp_error($object)) { |
|
374 | 374 | return $object; |
375 | 375 | } |
376 | 376 | |
377 | 377 | // Prepare the item for saving. |
378 | - $object = $this->prepare_item_for_database( $request ); |
|
379 | - if ( is_wp_error( $object ) ) { |
|
378 | + $object = $this->prepare_item_for_database($request); |
|
379 | + if (is_wp_error($object)) { |
|
380 | 380 | return $object; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // Save the item. |
384 | - $object = $this->save_object( $object ); |
|
385 | - if ( is_wp_error( $object ) ) { |
|
384 | + $object = $this->save_object($object); |
|
385 | + if (is_wp_error($object)) { |
|
386 | 386 | return $object; |
387 | 387 | } |
388 | 388 | |
389 | 389 | // Save special fields (those added via hooks). |
390 | - $save_special = $this->update_additional_fields_for_object( $object, $request ); |
|
391 | - if ( is_wp_error( $save_special ) ) { |
|
390 | + $save_special = $this->update_additional_fields_for_object($object, $request); |
|
391 | + if (is_wp_error($save_special)) { |
|
392 | 392 | return $save_special; |
393 | 393 | } |
394 | 394 | |
@@ -399,11 +399,11 @@ discard block |
||
399 | 399 | * @param WP_REST_Request $request Request object. |
400 | 400 | * @param boolean $creating True when creating item, false when updating. |
401 | 401 | */ |
402 | - do_action( "getpaid_rest_insert_{$this->post_type}", $object, $request, false ); |
|
402 | + do_action("getpaid_rest_insert_{$this->post_type}", $object, $request, false); |
|
403 | 403 | |
404 | - $request->set_param( 'context', 'edit' ); |
|
405 | - $response = $this->prepare_item_for_response( $object, $request ); |
|
406 | - return rest_ensure_response( $response ); |
|
404 | + $request->set_param('context', 'edit'); |
|
405 | + $response = $this->prepare_item_for_response($object, $request); |
|
406 | + return rest_ensure_response($response); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | * @param WP_REST_Request $request Full details about the request. |
413 | 413 | * @return WP_Error|WP_REST_Response |
414 | 414 | */ |
415 | - public function get_items( $request ) { |
|
415 | + public function get_items($request) { |
|
416 | 416 | $args = array(); |
417 | 417 | $args['offset'] = $request['offset']; |
418 | 418 | $args['order'] = $request['order']; |
@@ -425,16 +425,16 @@ discard block |
||
425 | 425 | $args['post_parent__in'] = $request['parent']; |
426 | 426 | $args['post_parent__not_in'] = $request['parent_exclude']; |
427 | 427 | $args['s'] = $request['search']; |
428 | - $args['post_status'] = $request['status'] == 'any' ? 'any' : wpinv_parse_list( $request['status'] ); |
|
428 | + $args['post_status'] = $request['status'] == 'any' ? 'any' : wpinv_parse_list($request['status']); |
|
429 | 429 | |
430 | 430 | $args['date_query'] = array(); |
431 | 431 | // Set before into date query. Date query must be specified as an array of an array. |
432 | - if ( isset( $request['before'] ) ) { |
|
432 | + if (isset($request['before'])) { |
|
433 | 433 | $args['date_query'][0]['before'] = $request['before']; |
434 | 434 | } |
435 | 435 | |
436 | 436 | // Set after into date query. Date query must be specified as an array of an array. |
437 | - if ( isset( $request['after'] ) ) { |
|
437 | + if (isset($request['after'])) { |
|
438 | 438 | $args['date_query'][0]['after'] = $request['after']; |
439 | 439 | } |
440 | 440 | |
@@ -443,54 +443,54 @@ discard block |
||
443 | 443 | $args['fields'] = 'ids'; |
444 | 444 | |
445 | 445 | // Filter the query arguments for a request. |
446 | - $args = apply_filters( "getpaid_rest_{$this->post_type}_query", $args, $request ); |
|
447 | - $query_args = $this->prepare_items_query( $args, $request ); |
|
446 | + $args = apply_filters("getpaid_rest_{$this->post_type}_query", $args, $request); |
|
447 | + $query_args = $this->prepare_items_query($args, $request); |
|
448 | 448 | |
449 | 449 | $posts_query = new WP_Query(); |
450 | - $query_result = $posts_query->query( $query_args ); |
|
450 | + $query_result = $posts_query->query($query_args); |
|
451 | 451 | |
452 | 452 | $posts = array(); |
453 | - foreach ( $query_result as $post_id ) { |
|
454 | - if ( ! $this->check_post_permissions( 'read', $post_id ) ) { |
|
453 | + foreach ($query_result as $post_id) { |
|
454 | + if (!$this->check_post_permissions('read', $post_id)) { |
|
455 | 455 | continue; |
456 | 456 | } |
457 | 457 | |
458 | - $data = $this->prepare_item_for_response( $this->get_object( $post_id ), $request ); |
|
459 | - $posts[] = $this->prepare_response_for_collection( $data ); |
|
458 | + $data = $this->prepare_item_for_response($this->get_object($post_id), $request); |
|
459 | + $posts[] = $this->prepare_response_for_collection($data); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | $page = (int) $query_args['paged']; |
463 | 463 | $total_posts = $posts_query->found_posts; |
464 | 464 | |
465 | - if ( $total_posts < 1 ) { |
|
465 | + if ($total_posts < 1) { |
|
466 | 466 | // Out-of-bounds, run the query again without LIMIT for total count. |
467 | - unset( $query_args['paged'] ); |
|
467 | + unset($query_args['paged']); |
|
468 | 468 | $count_query = new WP_Query(); |
469 | - $count_query->query( $query_args ); |
|
469 | + $count_query->query($query_args); |
|
470 | 470 | $total_posts = $count_query->found_posts; |
471 | 471 | } |
472 | 472 | |
473 | - $max_pages = ceil( $total_posts / (int) $query_args['posts_per_page'] ); |
|
473 | + $max_pages = ceil($total_posts / (int) $query_args['posts_per_page']); |
|
474 | 474 | |
475 | - $response = rest_ensure_response( $posts ); |
|
476 | - $response->header( 'X-WP-Total', (int) $total_posts ); |
|
477 | - $response->header( 'X-WP-TotalPages', (int) $max_pages ); |
|
475 | + $response = rest_ensure_response($posts); |
|
476 | + $response->header('X-WP-Total', (int) $total_posts); |
|
477 | + $response->header('X-WP-TotalPages', (int) $max_pages); |
|
478 | 478 | |
479 | 479 | $request_params = $request->get_query_params(); |
480 | - $base = add_query_arg( $request_params, rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) ); |
|
480 | + $base = add_query_arg($request_params, rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base))); |
|
481 | 481 | |
482 | - if ( $page > 1 ) { |
|
482 | + if ($page > 1) { |
|
483 | 483 | $prev_page = $page - 1; |
484 | - if ( $prev_page > $max_pages ) { |
|
484 | + if ($prev_page > $max_pages) { |
|
485 | 485 | $prev_page = $max_pages; |
486 | 486 | } |
487 | - $prev_link = add_query_arg( 'page', $prev_page, $base ); |
|
488 | - $response->link_header( 'prev', $prev_link ); |
|
487 | + $prev_link = add_query_arg('page', $prev_page, $base); |
|
488 | + $response->link_header('prev', $prev_link); |
|
489 | 489 | } |
490 | - if ( $max_pages > $page ) { |
|
490 | + if ($max_pages > $page) { |
|
491 | 491 | $next_page = $page + 1; |
492 | - $next_link = add_query_arg( 'page', $next_page, $base ); |
|
493 | - $response->link_header( 'next', $next_link ); |
|
492 | + $next_link = add_query_arg('page', $next_page, $base); |
|
493 | + $response->link_header('next', $next_link); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | return $response; |
@@ -502,26 +502,26 @@ discard block |
||
502 | 502 | * @param WP_REST_Request $request Full details about the request. |
503 | 503 | * @return WP_REST_Response|WP_Error |
504 | 504 | */ |
505 | - public function delete_item( $request ) { |
|
505 | + public function delete_item($request) { |
|
506 | 506 | |
507 | 507 | // Fetch the item. |
508 | - $item = $this->get_object( $request['id'] ); |
|
509 | - if ( is_wp_error( $item ) ) { |
|
508 | + $item = $this->get_object($request['id']); |
|
509 | + if (is_wp_error($item)) { |
|
510 | 510 | return $item; |
511 | 511 | } |
512 | 512 | |
513 | 513 | $supports_trash = EMPTY_TRASH_DAYS > 0; |
514 | 514 | $force = $supports_trash && (bool) $request['force']; |
515 | 515 | |
516 | - if ( ! $this->check_post_permissions( 'delete', $item->ID ) ) { |
|
517 | - return new WP_Error( "cannot_delete", __( 'Sorry, you are not allowed to delete this resource.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
516 | + if (!$this->check_post_permissions('delete', $item->ID)) { |
|
517 | + return new WP_Error("cannot_delete", __('Sorry, you are not allowed to delete this resource.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
518 | 518 | } |
519 | 519 | |
520 | - $request->set_param( 'context', 'edit' ); |
|
521 | - $response = $this->prepare_item_for_response( $item, $request ); |
|
520 | + $request->set_param('context', 'edit'); |
|
521 | + $response = $this->prepare_item_for_response($item, $request); |
|
522 | 522 | |
523 | - if ( ! wp_delete_post( $item->ID, $force ) ) { |
|
524 | - return new WP_Error( 'rest_cannot_delete', sprintf( __( 'The resource cannot be deleted.', 'invoicing' ), $this->post_type ), array( 'status' => 500 ) ); |
|
523 | + if (!wp_delete_post($item->ID, $force)) { |
|
524 | + return new WP_Error('rest_cannot_delete', sprintf(__('The resource cannot be deleted.', 'invoicing'), $this->post_type), array('status' => 500)); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | return $response; |
@@ -533,20 +533,20 @@ discard block |
||
533 | 533 | * @param GetPaid_Data $object GetPaid_Data object. |
534 | 534 | * @return array Links for the given object. |
535 | 535 | */ |
536 | - protected function prepare_links( $object ) { |
|
536 | + protected function prepare_links($object) { |
|
537 | 537 | |
538 | 538 | $links = array( |
539 | 539 | 'self' => array( |
540 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ), |
|
540 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())), |
|
541 | 541 | ), |
542 | 542 | 'collection' => array( |
543 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
543 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
544 | 544 | ), |
545 | 545 | ); |
546 | 546 | |
547 | - if ( is_callable( array( $object, 'get_user_id' ) ) ) { |
|
547 | + if (is_callable(array($object, 'get_user_id'))) { |
|
548 | 548 | $links['user'] = array( |
549 | - 'href' => rest_url( 'wp/v2/users/' . call_user_func( array( $object, 'get_user_id' ) ) ), |
|
549 | + 'href' => rest_url('wp/v2/users/' . call_user_func(array($object, 'get_user_id'))), |
|
550 | 550 | 'embeddable' => true, |
551 | 551 | ); |
552 | 552 | } |
@@ -562,27 +562,27 @@ discard block |
||
562 | 562 | * @param WP_REST_Request $request Request object. |
563 | 563 | * @return array $query_args |
564 | 564 | */ |
565 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
565 | + protected function prepare_items_query($prepared_args = array(), $request = null) { |
|
566 | 566 | |
567 | - $valid_vars = array_flip( $this->get_allowed_query_vars() ); |
|
567 | + $valid_vars = array_flip($this->get_allowed_query_vars()); |
|
568 | 568 | $query_args = array(); |
569 | - foreach ( $valid_vars as $var => $index ) { |
|
570 | - if ( isset( $prepared_args[ $var ] ) ) { |
|
571 | - $query_args[ $var ] = apply_filters( "getpaid_rest_query_var-{$var}", $prepared_args[ $var ] ); |
|
569 | + foreach ($valid_vars as $var => $index) { |
|
570 | + if (isset($prepared_args[$var])) { |
|
571 | + $query_args[$var] = apply_filters("getpaid_rest_query_var-{$var}", $prepared_args[$var]); |
|
572 | 572 | } |
573 | 573 | } |
574 | 574 | |
575 | 575 | $query_args['ignore_sticky_posts'] = true; |
576 | 576 | |
577 | - if ( 'include' === $query_args['orderby'] ) { |
|
577 | + if ('include' === $query_args['orderby']) { |
|
578 | 578 | $query_args['orderby'] = 'post__in'; |
579 | - } elseif ( 'id' === $query_args['orderby'] ) { |
|
579 | + } elseif ('id' === $query_args['orderby']) { |
|
580 | 580 | $query_args['orderby'] = 'ID'; // ID must be capitalized. |
581 | - } elseif ( 'slug' === $query_args['orderby'] ) { |
|
581 | + } elseif ('slug' === $query_args['orderby']) { |
|
582 | 582 | $query_args['orderby'] = 'name'; |
583 | 583 | } |
584 | 584 | |
585 | - return apply_filters( 'getpaid_rest_prepare_items_query', $query_args, $request, $this ); |
|
585 | + return apply_filters('getpaid_rest_prepare_items_query', $query_args, $request, $this); |
|
586 | 586 | |
587 | 587 | } |
588 | 588 | |
@@ -601,12 +601,12 @@ discard block |
||
601 | 601 | * |
602 | 602 | * @param array Array of allowed WP_Query query vars. |
603 | 603 | */ |
604 | - $valid_vars = apply_filters( 'query_vars', $wp->public_query_vars ); |
|
604 | + $valid_vars = apply_filters('query_vars', $wp->public_query_vars); |
|
605 | 605 | |
606 | - $post_type_obj = get_post_type_object( $this->post_type ); |
|
607 | - if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { |
|
608 | - $private = apply_filters( 'getpaid_rest_private_query_vars', $wp->private_query_vars ); |
|
609 | - $valid_vars = array_merge( $valid_vars, $private ); |
|
606 | + $post_type_obj = get_post_type_object($this->post_type); |
|
607 | + if (current_user_can($post_type_obj->cap->edit_posts)) { |
|
608 | + $private = apply_filters('getpaid_rest_private_query_vars', $wp->private_query_vars); |
|
609 | + $valid_vars = array_merge($valid_vars, $private); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | // Define our own in addition to WP's normal vars. |
@@ -628,10 +628,10 @@ discard block |
||
628 | 628 | 'meta_compare', |
629 | 629 | 'meta_value_num', |
630 | 630 | ); |
631 | - $valid_vars = array_merge( $valid_vars, $rest_valid ); |
|
631 | + $valid_vars = array_merge($valid_vars, $rest_valid); |
|
632 | 632 | |
633 | 633 | // Filter allowed query vars for the REST API. |
634 | - $valid_vars = apply_filters( 'getpaid_rest_query_vars', $valid_vars, $this ); |
|
634 | + $valid_vars = apply_filters('getpaid_rest_query_vars', $valid_vars, $this); |
|
635 | 635 | |
636 | 636 | return $valid_vars; |
637 | 637 | } |
@@ -648,29 +648,29 @@ discard block |
||
648 | 648 | |
649 | 649 | $params['status'] = array( |
650 | 650 | 'default' => 'any', |
651 | - 'description' => __( 'Limit result set to resources assigned one or more statuses.', 'invoicing' ), |
|
652 | - 'type' => array( 'array', 'string' ), |
|
651 | + 'description' => __('Limit result set to resources assigned one or more statuses.', 'invoicing'), |
|
652 | + 'type' => array('array', 'string'), |
|
653 | 653 | 'items' => array( |
654 | - 'enum' => array_merge( array( 'any' ), $this->get_post_statuses() ), |
|
654 | + 'enum' => array_merge(array('any'), $this->get_post_statuses()), |
|
655 | 655 | 'type' => 'string', |
656 | 656 | ), |
657 | 657 | 'sanitize_callback' => 'rest_validate_request_arg', |
658 | 658 | ); |
659 | 659 | |
660 | 660 | $params['after'] = array( |
661 | - 'description' => __( 'Limit response to resources created after a given ISO8601 compliant date.', 'invoicing' ), |
|
661 | + 'description' => __('Limit response to resources created after a given ISO8601 compliant date.', 'invoicing'), |
|
662 | 662 | 'type' => 'string', |
663 | 663 | 'format' => 'string', |
664 | 664 | 'validate_callback' => 'rest_validate_request_arg', |
665 | 665 | ); |
666 | 666 | $params['before'] = array( |
667 | - 'description' => __( 'Limit response to resources created before a given ISO8601 compliant date.', 'invoicing' ), |
|
667 | + 'description' => __('Limit response to resources created before a given ISO8601 compliant date.', 'invoicing'), |
|
668 | 668 | 'type' => 'string', |
669 | 669 | 'format' => 'string', |
670 | 670 | 'validate_callback' => 'rest_validate_request_arg', |
671 | 671 | ); |
672 | 672 | $params['exclude'] = array( |
673 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'invoicing' ), |
|
673 | + 'description' => __('Ensure result set excludes specific IDs.', 'invoicing'), |
|
674 | 674 | 'type' => 'array', |
675 | 675 | 'items' => array( |
676 | 676 | 'type' => 'integer', |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | 'sanitize_callback' => 'wp_parse_id_list', |
680 | 680 | ); |
681 | 681 | $params['include'] = array( |
682 | - 'description' => __( 'Limit result set to specific ids.', 'invoicing' ), |
|
682 | + 'description' => __('Limit result set to specific ids.', 'invoicing'), |
|
683 | 683 | 'type' => 'array', |
684 | 684 | 'items' => array( |
685 | 685 | 'type' => 'integer', |
@@ -688,20 +688,20 @@ discard block |
||
688 | 688 | 'sanitize_callback' => 'wp_parse_id_list', |
689 | 689 | ); |
690 | 690 | $params['offset'] = array( |
691 | - 'description' => __( 'Offset the result set by a specific number of items.', 'invoicing' ), |
|
691 | + 'description' => __('Offset the result set by a specific number of items.', 'invoicing'), |
|
692 | 692 | 'type' => 'integer', |
693 | 693 | 'sanitize_callback' => 'absint', |
694 | 694 | 'validate_callback' => 'rest_validate_request_arg', |
695 | 695 | ); |
696 | 696 | $params['order'] = array( |
697 | - 'description' => __( 'Order sort attribute ascending or descending.', 'invoicing' ), |
|
697 | + 'description' => __('Order sort attribute ascending or descending.', 'invoicing'), |
|
698 | 698 | 'type' => 'string', |
699 | 699 | 'default' => 'desc', |
700 | - 'enum' => array( 'asc', 'desc' ), |
|
700 | + 'enum' => array('asc', 'desc'), |
|
701 | 701 | 'validate_callback' => 'rest_validate_request_arg', |
702 | 702 | ); |
703 | 703 | $params['orderby'] = array( |
704 | - 'description' => __( 'Sort collection by object attribute.', 'invoicing' ), |
|
704 | + 'description' => __('Sort collection by object attribute.', 'invoicing'), |
|
705 | 705 | 'type' => 'string', |
706 | 706 | 'default' => 'date', |
707 | 707 | 'enum' => array( |
@@ -715,11 +715,11 @@ discard block |
||
715 | 715 | 'validate_callback' => 'rest_validate_request_arg', |
716 | 716 | ); |
717 | 717 | |
718 | - $post_type_obj = get_post_type_object( $this->post_type ); |
|
718 | + $post_type_obj = get_post_type_object($this->post_type); |
|
719 | 719 | |
720 | - if ( isset( $post_type_obj->hierarchical ) && $post_type_obj->hierarchical ) { |
|
720 | + if (isset($post_type_obj->hierarchical) && $post_type_obj->hierarchical) { |
|
721 | 721 | $params['parent'] = array( |
722 | - 'description' => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ), |
|
722 | + 'description' => __('Limit result set to those of particular parent IDs.', 'invoicing'), |
|
723 | 723 | 'type' => 'array', |
724 | 724 | 'items' => array( |
725 | 725 | 'type' => 'integer', |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | 'default' => array(), |
729 | 729 | ); |
730 | 730 | $params['parent_exclude'] = array( |
731 | - 'description' => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ), |
|
731 | + 'description' => __('Limit result set to all items except those of a particular parent ID.', 'invoicing'), |
|
732 | 732 | 'type' => 'array', |
733 | 733 | 'items' => array( |
734 | 734 | 'type' => 'integer', |
@@ -751,25 +751,25 @@ discard block |
||
751 | 751 | public function get_item_schema() { |
752 | 752 | |
753 | 753 | // Maybe retrieve the schema from cache. |
754 | - if ( $this->schema ) { |
|
755 | - return $this->add_additional_fields_schema( $this->schema ); |
|
754 | + if ($this->schema) { |
|
755 | + return $this->add_additional_fields_schema($this->schema); |
|
756 | 756 | } |
757 | 757 | |
758 | - $type = str_replace( 'wpi_', '', $this->post_type ); |
|
758 | + $type = str_replace('wpi_', '', $this->post_type); |
|
759 | 759 | $schema = array( |
760 | 760 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
761 | 761 | 'title' => $this->post_type, |
762 | 762 | 'type' => 'object', |
763 | - 'properties' => wpinv_get_data( "$type-schema" ), |
|
763 | + 'properties' => wpinv_get_data("$type-schema"), |
|
764 | 764 | ); |
765 | 765 | |
766 | 766 | // Filters the invoice schema for the REST API. |
767 | - $schema = apply_filters( "wpinv_rest_{$type}_schema", $schema ); |
|
767 | + $schema = apply_filters("wpinv_rest_{$type}_schema", $schema); |
|
768 | 768 | |
769 | 769 | // Cache the invoice schema. |
770 | 770 | $this->schema = $schema; |
771 | 771 | |
772 | - return $this->add_additional_fields_schema( $this->schema ); |
|
772 | + return $this->add_additional_fields_schema($this->schema); |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | /** |
@@ -778,8 +778,8 @@ discard block |
||
778 | 778 | * @param array $schema Schema. |
779 | 779 | * @return bool |
780 | 780 | */ |
781 | - public function filter_writable_props( $schema ) { |
|
782 | - return empty( $schema['readonly'] ); |
|
781 | + public function filter_writable_props($schema) { |
|
782 | + return empty($schema['readonly']); |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
@@ -792,8 +792,8 @@ discard block |
||
792 | 792 | * @param string $parameter Additional parameter to pass to validation. |
793 | 793 | * @return array|WP_Error A list of valid statuses, otherwise WP_Error object. |
794 | 794 | */ |
795 | - public function sanitize_post_statuses( $statuses, $request, $parameter ) { |
|
796 | - return array_intersect( wp_parse_slug_list( $statuses ), $this->get_post_statuses() ); |
|
795 | + public function sanitize_post_statuses($statuses, $request, $parameter) { |
|
796 | + return array_intersect(wp_parse_slug_list($statuses), $this->get_post_statuses()); |
|
797 | 797 | } |
798 | 798 | |
799 | 799 | /** |
@@ -814,43 +814,43 @@ discard block |
||
814 | 814 | * @param WP_REST_Request $request Request object. |
815 | 815 | * @return GetPaid_Data|WP_Error Data object or WP_Error. |
816 | 816 | */ |
817 | - protected function prepare_item_for_database( $request ) { |
|
817 | + protected function prepare_item_for_database($request) { |
|
818 | 818 | |
819 | 819 | // Do we have an object? |
820 | - if ( empty( $this->crud_class ) || ! class_exists( $this->crud_class ) ) { |
|
821 | - return new WP_Error( 'no_crud_class', __( 'You need to specify a CRUD class for this controller', 'invoicing' ) ); |
|
820 | + if (empty($this->crud_class) || !class_exists($this->crud_class)) { |
|
821 | + return new WP_Error('no_crud_class', __('You need to specify a CRUD class for this controller', 'invoicing')); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | // Prepare the object. |
825 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
826 | - $object = new $this->crud_class( $id ); |
|
825 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
826 | + $object = new $this->crud_class($id); |
|
827 | 827 | |
828 | 828 | // Abort if an error exists. |
829 | - if ( ! empty( $object->last_error ) ) { |
|
830 | - return new WP_Error( 'invalid_item', $object->last_error ); |
|
829 | + if (!empty($object->last_error)) { |
|
830 | + return new WP_Error('invalid_item', $object->last_error); |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | $schema = $this->get_item_schema(); |
834 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
834 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
835 | 835 | |
836 | 836 | // Handle all writable props. |
837 | - foreach ( $data_keys as $key ) { |
|
838 | - $value = $request[ $key ]; |
|
837 | + foreach ($data_keys as $key) { |
|
838 | + $value = $request[$key]; |
|
839 | 839 | |
840 | - if ( ! is_null( $value ) ) { |
|
841 | - switch ( $key ) { |
|
840 | + if (!is_null($value)) { |
|
841 | + switch ($key) { |
|
842 | 842 | |
843 | 843 | case 'meta_data': |
844 | - if ( is_array( $value ) ) { |
|
845 | - foreach ( $value as $meta ) { |
|
846 | - $object->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
844 | + if (is_array($value)) { |
|
845 | + foreach ($value as $meta) { |
|
846 | + $object->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
847 | 847 | } |
848 | 848 | } |
849 | 849 | break; |
850 | 850 | |
851 | 851 | default: |
852 | - if ( is_callable( array( $object, "set_{$key}" ) ) ) { |
|
853 | - $object->{"set_{$key}"}( $value ); |
|
852 | + if (is_callable(array($object, "set_{$key}"))) { |
|
853 | + $object->{"set_{$key}"}($value); |
|
854 | 854 | } |
855 | 855 | break; |
856 | 856 | } |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | } |
860 | 860 | |
861 | 861 | // Filters an object before it is inserted via the REST API.. |
862 | - return apply_filters( "getpaid_rest_pre_insert_{$this->post_type}_object", $object, $request ); |
|
862 | + return apply_filters("getpaid_rest_pre_insert_{$this->post_type}_object", $object, $request); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | /** |
@@ -869,10 +869,10 @@ discard block |
||
869 | 869 | * @param GetPaid_Meta_Data[] $meta_data meta data objects. |
870 | 870 | * @return array |
871 | 871 | */ |
872 | - protected function prepare_object_meta_data( $meta_data ) { |
|
872 | + protected function prepare_object_meta_data($meta_data) { |
|
873 | 873 | $meta = array(); |
874 | 874 | |
875 | - foreach( $meta_data as $object ) { |
|
875 | + foreach ($meta_data as $object) { |
|
876 | 876 | $meta[] = $object->get_data(); |
877 | 877 | } |
878 | 878 | |
@@ -886,13 +886,13 @@ discard block |
||
886 | 886 | * @param WPInv_Invoice $invoice Invoice items. |
887 | 887 | * @return array |
888 | 888 | */ |
889 | - protected function prepare_invoice_items( $invoice ) { |
|
889 | + protected function prepare_invoice_items($invoice) { |
|
890 | 890 | $items = array(); |
891 | 891 | |
892 | - foreach( $invoice->get_items() as $item ) { |
|
892 | + foreach ($invoice->get_items() as $item) { |
|
893 | 893 | $item_data = $item->prepare_data_for_saving(); |
894 | 894 | |
895 | - if ( 'amount' == $invoice->get_template() ) { |
|
895 | + if ('amount' == $invoice->get_template()) { |
|
896 | 896 | $item_data['quantity'] = 1; |
897 | 897 | } |
898 | 898 | |
@@ -911,54 +911,54 @@ discard block |
||
911 | 911 | * @param string $context either view or edit. |
912 | 912 | * @return array |
913 | 913 | */ |
914 | - protected function prepare_object_data( $object, $fields, $context = 'view' ) { |
|
914 | + protected function prepare_object_data($object, $fields, $context = 'view') { |
|
915 | 915 | |
916 | 916 | $data = array(); |
917 | 917 | $schema = $this->get_item_schema(); |
918 | - $data_keys = array_keys( $schema['properties'] ); |
|
918 | + $data_keys = array_keys($schema['properties']); |
|
919 | 919 | |
920 | 920 | // Handle all writable props. |
921 | - foreach ( $data_keys as $key ) { |
|
921 | + foreach ($data_keys as $key) { |
|
922 | 922 | |
923 | 923 | // Abort if it is not included. |
924 | - if ( ! empty( $fields ) && ! $this->is_field_included( $key, $fields ) ) { |
|
924 | + if (!empty($fields) && !$this->is_field_included($key, $fields)) { |
|
925 | 925 | continue; |
926 | 926 | } |
927 | 927 | |
928 | 928 | // Handle meta data. |
929 | - if ( $key == 'meta_data' ) { |
|
930 | - $data['meta_data'] = $this->prepare_object_meta_data( $object->get_meta_data() ); |
|
929 | + if ($key == 'meta_data') { |
|
930 | + $data['meta_data'] = $this->prepare_object_meta_data($object->get_meta_data()); |
|
931 | 931 | continue; |
932 | 932 | } |
933 | 933 | |
934 | 934 | // Handle items. |
935 | - if ( $key == 'items' && is_a( $object, 'WPInv_Invoice' ) ) { |
|
936 | - $data['items'] = $this->prepare_invoice_items( $object ); |
|
935 | + if ($key == 'items' && is_a($object, 'WPInv_Invoice')) { |
|
936 | + $data['items'] = $this->prepare_invoice_items($object); |
|
937 | 937 | continue; |
938 | 938 | } |
939 | 939 | |
940 | 940 | // Booleans. |
941 | - if ( is_callable( array( $object, $key ) ) ) { |
|
942 | - $data[ $key ] = $object->$key( $context ); |
|
941 | + if (is_callable(array($object, $key))) { |
|
942 | + $data[$key] = $object->$key($context); |
|
943 | 943 | continue; |
944 | 944 | } |
945 | 945 | |
946 | 946 | // Get object value. |
947 | - if ( is_callable( array( $object, "get_{$key}" ) ) ) { |
|
948 | - $value = $object->{"get_{$key}"}( $context ); |
|
947 | + if (is_callable(array($object, "get_{$key}"))) { |
|
948 | + $value = $object->{"get_{$key}"}($context); |
|
949 | 949 | |
950 | 950 | // If the value is an instance of GetPaid_Data... |
951 | - if ( is_a( $value, 'GetPaid_Data' ) ) { |
|
952 | - $value = $value->get_data( $context ); |
|
951 | + if (is_a($value, 'GetPaid_Data')) { |
|
952 | + $value = $value->get_data($context); |
|
953 | 953 | } |
954 | 954 | |
955 | 955 | // For objects, retrieves it's properties. |
956 | - $data[ $key ] = is_object( $value ) ? get_object_vars( $value ) : $value ; |
|
956 | + $data[$key] = is_object($value) ? get_object_vars($value) : $value; |
|
957 | 957 | continue; |
958 | 958 | } |
959 | 959 | |
960 | 960 | // The value does not exist on an object. |
961 | - $data[ $key ] = apply_filters( "getpaid_{$this->post_type}_{$key}_object_data", null, $object ); |
|
961 | + $data[$key] = apply_filters("getpaid_{$this->post_type}_{$key}_object_data", null, $object); |
|
962 | 962 | |
963 | 963 | } |
964 | 964 | |
@@ -973,23 +973,23 @@ discard block |
||
973 | 973 | * @param WP_REST_Request $request Request object. |
974 | 974 | * @return WP_REST_Response |
975 | 975 | */ |
976 | - public function prepare_item_for_response( $object, $request ) { |
|
976 | + public function prepare_item_for_response($object, $request) { |
|
977 | 977 | |
978 | 978 | // Fetch the fields to include in this response. |
979 | - $fields = $this->get_fields_for_response( $request ); |
|
979 | + $fields = $this->get_fields_for_response($request); |
|
980 | 980 | |
981 | 981 | // Prepare object data. |
982 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
983 | - $data = $this->prepare_object_data( $object, $fields, $context ); |
|
984 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
985 | - $data = $this->filter_response_by_context( $data, $context ); |
|
982 | + $context = !empty($request['context']) ? $request['context'] : 'view'; |
|
983 | + $data = $this->prepare_object_data($object, $fields, $context); |
|
984 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
985 | + $data = $this->filter_response_by_context($data, $context); |
|
986 | 986 | |
987 | 987 | // Prepare the response. |
988 | - $response = rest_ensure_response( $data ); |
|
989 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
988 | + $response = rest_ensure_response($data); |
|
989 | + $response->add_links($this->prepare_links($object, $request)); |
|
990 | 990 | |
991 | 991 | // Filter item response. |
992 | - return apply_filters( "getpaid_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
|
992 | + return apply_filters("getpaid_rest_prepare_{$this->post_type}_object", $response, $object, $request); |
|
993 | 993 | } |
994 | 994 | |
995 | 995 | } |
@@ -15,149 +15,149 @@ |
||
15 | 15 | class WPInv_REST_Items_Controller extends GetPaid_REST_Posts_Controller { |
16 | 16 | |
17 | 17 | /** |
18 | - * Post type. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $post_type = 'wpi_item'; |
|
18 | + * Post type. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $post_type = 'wpi_item'; |
|
23 | 23 | |
24 | - /** |
|
25 | - * The base of this controller's route. |
|
26 | - * |
|
27 | - * @since 1.0.13 |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $rest_base = 'items'; |
|
31 | - |
|
32 | - /** Contains this controller's class name. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - public $crud_class = 'WPInv_Item'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Registers the routes for the objects of the controller. |
|
40 | - * |
|
41 | - * @since 1.0.19 |
|
42 | - * |
|
43 | - * @see register_rest_route() |
|
44 | - */ |
|
45 | - public function register_namespace_routes( $namespace ) { |
|
46 | - |
|
47 | - parent::register_namespace_routes( $namespace ); |
|
48 | - |
|
49 | - register_rest_route( |
|
50 | - $this->namespace, |
|
51 | - '/' . $this->rest_base . '/item-types', |
|
52 | - array( |
|
53 | - array( |
|
54 | - 'methods' => WP_REST_Server::READABLE, |
|
55 | - 'callback' => array( $this, 'get_item_types' ), |
|
56 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
57 | - ), |
|
58 | - ) |
|
59 | - ); |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Handles rest requests for item types. |
|
65 | - * |
|
66 | - * @since 1.0.13 |
|
67 | - * |
|
68 | - * |
|
69 | - * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
70 | - */ |
|
71 | - public function get_item_types() { |
|
72 | - return rest_ensure_response( wpinv_get_item_types() ); |
|
73 | - } |
|
24 | + /** |
|
25 | + * The base of this controller's route. |
|
26 | + * |
|
27 | + * @since 1.0.13 |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $rest_base = 'items'; |
|
31 | + |
|
32 | + /** Contains this controller's class name. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + public $crud_class = 'WPInv_Item'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Registers the routes for the objects of the controller. |
|
40 | + * |
|
41 | + * @since 1.0.19 |
|
42 | + * |
|
43 | + * @see register_rest_route() |
|
44 | + */ |
|
45 | + public function register_namespace_routes( $namespace ) { |
|
46 | + |
|
47 | + parent::register_namespace_routes( $namespace ); |
|
48 | + |
|
49 | + register_rest_route( |
|
50 | + $this->namespace, |
|
51 | + '/' . $this->rest_base . '/item-types', |
|
52 | + array( |
|
53 | + array( |
|
54 | + 'methods' => WP_REST_Server::READABLE, |
|
55 | + 'callback' => array( $this, 'get_item_types' ), |
|
56 | + 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
57 | + ), |
|
58 | + ) |
|
59 | + ); |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Handles rest requests for item types. |
|
65 | + * |
|
66 | + * @since 1.0.13 |
|
67 | + * |
|
68 | + * |
|
69 | + * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
70 | + */ |
|
71 | + public function get_item_types() { |
|
72 | + return rest_ensure_response( wpinv_get_item_types() ); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | /** |
76 | - * Retrieves the query params for the items collection. |
|
77 | - * |
|
78 | - * @since 1.0.13 |
|
79 | - * |
|
80 | - * @return array Collection parameters. |
|
81 | - */ |
|
82 | - public function get_collection_params() { |
|
83 | - |
|
84 | - $params = array_merge( |
|
85 | - |
|
86 | - parent::get_collection_params(), |
|
87 | - |
|
88 | - array( |
|
89 | - |
|
90 | - // Item types |
|
91 | - 'type' => array( |
|
92 | - 'description' => __( 'Type of items to fetch.', 'invoicing' ), |
|
93 | - 'type' => array( 'array', 'string' ), |
|
94 | - 'default' => 'any', |
|
95 | - 'items' => array( |
|
96 | - 'enum' => array_merge( array( 'any' ), wpinv_item_types() ), |
|
97 | - 'type' => 'string', |
|
98 | - ), |
|
99 | - ), |
|
100 | - |
|
101 | - ) |
|
102 | - ); |
|
103 | - |
|
104 | - // Filter collection parameters for the items controller. |
|
105 | - return apply_filters( 'getpaid_rest_items_collection_params', $params, $this ); |
|
106 | - |
|
107 | - } |
|
76 | + * Retrieves the query params for the items collection. |
|
77 | + * |
|
78 | + * @since 1.0.13 |
|
79 | + * |
|
80 | + * @return array Collection parameters. |
|
81 | + */ |
|
82 | + public function get_collection_params() { |
|
83 | + |
|
84 | + $params = array_merge( |
|
85 | + |
|
86 | + parent::get_collection_params(), |
|
87 | + |
|
88 | + array( |
|
89 | + |
|
90 | + // Item types |
|
91 | + 'type' => array( |
|
92 | + 'description' => __( 'Type of items to fetch.', 'invoicing' ), |
|
93 | + 'type' => array( 'array', 'string' ), |
|
94 | + 'default' => 'any', |
|
95 | + 'items' => array( |
|
96 | + 'enum' => array_merge( array( 'any' ), wpinv_item_types() ), |
|
97 | + 'type' => 'string', |
|
98 | + ), |
|
99 | + ), |
|
100 | + |
|
101 | + ) |
|
102 | + ); |
|
103 | + |
|
104 | + // Filter collection parameters for the items controller. |
|
105 | + return apply_filters( 'getpaid_rest_items_collection_params', $params, $this ); |
|
106 | + |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Get all the WP Query vars that are allowed for the API request. |
|
111 | - * |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - protected function get_allowed_query_vars() { |
|
115 | - $vars = array_merge( array( 'type' ), parent::get_allowed_query_vars() ); |
|
116 | - return apply_filters( 'getpaid_rest_items_allowed_query_vars', $vars, $this ); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Determine the allowed query_vars for a get_items() response and |
|
121 | - * prepare for WP_Query. |
|
122 | - * |
|
123 | - * @param array $prepared_args Prepared arguments. |
|
124 | - * @param WP_REST_Request $request Request object. |
|
125 | - * @return array $query_args |
|
126 | - */ |
|
127 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
128 | - |
|
129 | - $query_args = parent::prepare_items_query( $prepared_args ); |
|
130 | - |
|
131 | - // Retrieve items by type. |
|
132 | - if ( isset( $query_args['type'] ) && 'any' != $query_args['type'] ) { |
|
133 | - |
|
134 | - if ( empty( $query_args['meta_query'] ) ) { |
|
135 | - $query_args['meta_query'] = array(); |
|
136 | - } |
|
137 | - |
|
138 | - $types = wpinv_parse_list( $query_args['type'] ); |
|
139 | - $query_args['meta_query'][] = array( |
|
140 | - 'key' => '_wpinv_type', |
|
141 | - 'value' => implode( ',', $types ), |
|
142 | - 'compare' => 'IN', |
|
143 | - ); |
|
144 | - unset( $query_args['type'] ); |
|
145 | - |
|
146 | - } |
|
147 | - |
|
148 | - return apply_filters( 'getpaid_rest_items_prepare_items_query', $query_args, $request, $this ); |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Retrieves a valid list of post statuses. |
|
154 | - * |
|
155 | - * @since 1.0.15 |
|
156 | - * |
|
157 | - * @return array A list of registered item statuses. |
|
158 | - */ |
|
159 | - public function get_post_statuses() { |
|
160 | - return array( 'draft', 'pending', 'publish' ); |
|
161 | - } |
|
109 | + /** |
|
110 | + * Get all the WP Query vars that are allowed for the API request. |
|
111 | + * |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + protected function get_allowed_query_vars() { |
|
115 | + $vars = array_merge( array( 'type' ), parent::get_allowed_query_vars() ); |
|
116 | + return apply_filters( 'getpaid_rest_items_allowed_query_vars', $vars, $this ); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Determine the allowed query_vars for a get_items() response and |
|
121 | + * prepare for WP_Query. |
|
122 | + * |
|
123 | + * @param array $prepared_args Prepared arguments. |
|
124 | + * @param WP_REST_Request $request Request object. |
|
125 | + * @return array $query_args |
|
126 | + */ |
|
127 | + protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
128 | + |
|
129 | + $query_args = parent::prepare_items_query( $prepared_args ); |
|
130 | + |
|
131 | + // Retrieve items by type. |
|
132 | + if ( isset( $query_args['type'] ) && 'any' != $query_args['type'] ) { |
|
133 | + |
|
134 | + if ( empty( $query_args['meta_query'] ) ) { |
|
135 | + $query_args['meta_query'] = array(); |
|
136 | + } |
|
137 | + |
|
138 | + $types = wpinv_parse_list( $query_args['type'] ); |
|
139 | + $query_args['meta_query'][] = array( |
|
140 | + 'key' => '_wpinv_type', |
|
141 | + 'value' => implode( ',', $types ), |
|
142 | + 'compare' => 'IN', |
|
143 | + ); |
|
144 | + unset( $query_args['type'] ); |
|
145 | + |
|
146 | + } |
|
147 | + |
|
148 | + return apply_filters( 'getpaid_rest_items_prepare_items_query', $query_args, $request, $this ); |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Retrieves a valid list of post statuses. |
|
154 | + * |
|
155 | + * @since 1.0.15 |
|
156 | + * |
|
157 | + * @return array A list of registered item statuses. |
|
158 | + */ |
|
159 | + public function get_post_statuses() { |
|
160 | + return array( 'draft', 'pending', 'publish' ); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.19 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * REST API items controller class. |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @see register_rest_route() |
44 | 44 | */ |
45 | - public function register_namespace_routes( $namespace ) { |
|
45 | + public function register_namespace_routes($namespace) { |
|
46 | 46 | |
47 | - parent::register_namespace_routes( $namespace ); |
|
47 | + parent::register_namespace_routes($namespace); |
|
48 | 48 | |
49 | 49 | register_rest_route( |
50 | 50 | $this->namespace, |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | array( |
53 | 53 | array( |
54 | 54 | 'methods' => WP_REST_Server::READABLE, |
55 | - 'callback' => array( $this, 'get_item_types' ), |
|
56 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
55 | + 'callback' => array($this, 'get_item_types'), |
|
56 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
57 | 57 | ), |
58 | 58 | ) |
59 | 59 | ); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
70 | 70 | */ |
71 | 71 | public function get_item_types() { |
72 | - return rest_ensure_response( wpinv_get_item_types() ); |
|
72 | + return rest_ensure_response(wpinv_get_item_types()); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | |
90 | 90 | // Item types |
91 | 91 | 'type' => array( |
92 | - 'description' => __( 'Type of items to fetch.', 'invoicing' ), |
|
93 | - 'type' => array( 'array', 'string' ), |
|
92 | + 'description' => __('Type of items to fetch.', 'invoicing'), |
|
93 | + 'type' => array('array', 'string'), |
|
94 | 94 | 'default' => 'any', |
95 | 95 | 'items' => array( |
96 | - 'enum' => array_merge( array( 'any' ), wpinv_item_types() ), |
|
96 | + 'enum' => array_merge(array('any'), wpinv_item_types()), |
|
97 | 97 | 'type' => 'string', |
98 | 98 | ), |
99 | 99 | ), |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | ); |
103 | 103 | |
104 | 104 | // Filter collection parameters for the items controller. |
105 | - return apply_filters( 'getpaid_rest_items_collection_params', $params, $this ); |
|
105 | + return apply_filters('getpaid_rest_items_collection_params', $params, $this); |
|
106 | 106 | |
107 | 107 | } |
108 | 108 | |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @return array |
113 | 113 | */ |
114 | 114 | protected function get_allowed_query_vars() { |
115 | - $vars = array_merge( array( 'type' ), parent::get_allowed_query_vars() ); |
|
116 | - return apply_filters( 'getpaid_rest_items_allowed_query_vars', $vars, $this ); |
|
115 | + $vars = array_merge(array('type'), parent::get_allowed_query_vars()); |
|
116 | + return apply_filters('getpaid_rest_items_allowed_query_vars', $vars, $this); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -124,28 +124,28 @@ discard block |
||
124 | 124 | * @param WP_REST_Request $request Request object. |
125 | 125 | * @return array $query_args |
126 | 126 | */ |
127 | - protected function prepare_items_query( $prepared_args = array(), $request = null ) { |
|
127 | + protected function prepare_items_query($prepared_args = array(), $request = null) { |
|
128 | 128 | |
129 | - $query_args = parent::prepare_items_query( $prepared_args ); |
|
129 | + $query_args = parent::prepare_items_query($prepared_args); |
|
130 | 130 | |
131 | 131 | // Retrieve items by type. |
132 | - if ( isset( $query_args['type'] ) && 'any' != $query_args['type'] ) { |
|
132 | + if (isset($query_args['type']) && 'any' != $query_args['type']) { |
|
133 | 133 | |
134 | - if ( empty( $query_args['meta_query'] ) ) { |
|
134 | + if (empty($query_args['meta_query'])) { |
|
135 | 135 | $query_args['meta_query'] = array(); |
136 | 136 | } |
137 | 137 | |
138 | - $types = wpinv_parse_list( $query_args['type'] ); |
|
138 | + $types = wpinv_parse_list($query_args['type']); |
|
139 | 139 | $query_args['meta_query'][] = array( |
140 | 140 | 'key' => '_wpinv_type', |
141 | - 'value' => implode( ',', $types ), |
|
141 | + 'value' => implode(',', $types), |
|
142 | 142 | 'compare' => 'IN', |
143 | 143 | ); |
144 | - unset( $query_args['type'] ); |
|
144 | + unset($query_args['type']); |
|
145 | 145 | |
146 | 146 | } |
147 | 147 | |
148 | - return apply_filters( 'getpaid_rest_items_prepare_items_query', $query_args, $request, $this ); |
|
148 | + return apply_filters('getpaid_rest_items_prepare_items_query', $query_args, $request, $this); |
|
149 | 149 | |
150 | 150 | } |
151 | 151 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @return array A list of registered item statuses. |
158 | 158 | */ |
159 | 159 | public function get_post_statuses() { |
160 | - return array( 'draft', 'pending', 'publish' ); |
|
160 | + return array('draft', 'pending', 'publish'); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
@@ -13,240 +13,240 @@ |
||
13 | 13 | |
14 | 14 | return array( |
15 | 15 | |
16 | - 'id' => array( |
|
17 | - 'description' => __( 'Unique identifier for the item.', 'invoicing' ), |
|
18 | - 'type' => 'integer', |
|
19 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
20 | - 'readonly' => true, |
|
21 | - ), |
|
22 | - |
|
23 | - 'parent_id' => array( |
|
24 | - 'description' => __( 'Parent item ID.', 'invoicing' ), |
|
25 | - 'type' => 'integer', |
|
26 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
27 | - 'default' => 0, |
|
28 | - ), |
|
29 | - |
|
30 | - 'status' => array( |
|
31 | - 'description' => __( 'A named status for the item.', 'invoicing' ), |
|
32 | - 'type' => 'string', |
|
33 | - 'enum' => array( 'draft', 'pending', 'publish' ), |
|
34 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
35 | - 'default' => 'draft', |
|
36 | - ), |
|
37 | - |
|
38 | - 'version' => array( |
|
39 | - 'description' => __( 'Plugin version when the item was created.', 'invoicing' ), |
|
40 | - 'type' => 'string', |
|
41 | - 'context' => array( 'view', 'edit' ), |
|
42 | - 'readonly' => true, |
|
43 | - ), |
|
44 | - |
|
45 | - 'date_created' => array( |
|
46 | - 'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ), |
|
47 | - 'type' => 'string', |
|
48 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
49 | - ), |
|
50 | - |
|
51 | - 'date_created_gmt' => array( |
|
52 | - 'description' => __( 'The GMT date the item was created.', 'invoicing' ), |
|
53 | - 'type' => 'string', |
|
54 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
55 | - 'readonly' => true, |
|
56 | - ), |
|
57 | - |
|
58 | - 'date_modified' => array( |
|
59 | - 'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ), |
|
60 | - 'type' => 'string', |
|
61 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
62 | - 'readonly' => true, |
|
63 | - ), |
|
64 | - |
|
65 | - 'date_modified_gmt' => array( |
|
66 | - 'description' => __( 'The GMT date the item was last modified.', 'invoicing' ), |
|
67 | - 'type' => 'string', |
|
68 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
69 | - 'readonly' => true, |
|
70 | - ), |
|
71 | - |
|
72 | - 'name' => array( |
|
73 | - 'description' => __( "The item's name.", 'invoicing' ), |
|
74 | - 'type' => 'string', |
|
75 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
76 | - 'required' => true, |
|
77 | - ), |
|
78 | - |
|
79 | - 'description' => array( |
|
80 | - 'description' => __( "The item's description.", 'invoicing' ), |
|
81 | - 'type' => 'string', |
|
82 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
83 | - ), |
|
84 | - |
|
85 | - 'owner' => array( |
|
86 | - 'description' => __( 'The owner of the item (user id).', 'invoicing' ), |
|
87 | - 'type' => 'integer', |
|
88 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
89 | - ), |
|
90 | - |
|
91 | - 'price' => array( |
|
92 | - 'description' => __( 'The price of the item.', 'invoicing' ), |
|
93 | - 'type' => 'number', |
|
94 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
95 | - 'required' => true, |
|
96 | - ), |
|
97 | - |
|
98 | - 'the_price' => array( |
|
99 | - 'description' => __( 'The formatted price of the item.', 'invoicing' ), |
|
100 | - 'type' => 'string', |
|
101 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
102 | - 'readonly' => true, |
|
103 | - ), |
|
104 | - |
|
105 | - 'type' => array( |
|
106 | - 'description' => __( 'The item type.', 'invoicing' ), |
|
107 | - 'type' => 'string', |
|
108 | - 'enum' => wpinv_item_types(), |
|
109 | - 'default' => 'custom', |
|
110 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
111 | - ), |
|
112 | - |
|
113 | - 'vat_rule' => array( |
|
114 | - 'description' => __( 'VAT rule applied to the item.', 'invoicing' ), |
|
115 | - 'type' => 'string', |
|
116 | - 'enum' => array_keys( getpaid_tax()->get_rules() ), |
|
117 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
118 | - ), |
|
119 | - |
|
120 | - 'vat_class' => array( |
|
121 | - 'description' => __( 'VAT class for the item.', 'invoicing' ), |
|
122 | - 'type' => 'string', |
|
123 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
124 | - 'enum' => array_keys( getpaid_tax()->get_vat_groups() ), |
|
125 | - ), |
|
126 | - |
|
127 | - 'custom_id' => array( |
|
128 | - 'description' => __( 'Custom id for the item.', 'invoicing' ), |
|
129 | - 'type' => 'string', |
|
130 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
131 | - ), |
|
16 | + 'id' => array( |
|
17 | + 'description' => __( 'Unique identifier for the item.', 'invoicing' ), |
|
18 | + 'type' => 'integer', |
|
19 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
20 | + 'readonly' => true, |
|
21 | + ), |
|
22 | + |
|
23 | + 'parent_id' => array( |
|
24 | + 'description' => __( 'Parent item ID.', 'invoicing' ), |
|
25 | + 'type' => 'integer', |
|
26 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
27 | + 'default' => 0, |
|
28 | + ), |
|
29 | + |
|
30 | + 'status' => array( |
|
31 | + 'description' => __( 'A named status for the item.', 'invoicing' ), |
|
32 | + 'type' => 'string', |
|
33 | + 'enum' => array( 'draft', 'pending', 'publish' ), |
|
34 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
35 | + 'default' => 'draft', |
|
36 | + ), |
|
37 | + |
|
38 | + 'version' => array( |
|
39 | + 'description' => __( 'Plugin version when the item was created.', 'invoicing' ), |
|
40 | + 'type' => 'string', |
|
41 | + 'context' => array( 'view', 'edit' ), |
|
42 | + 'readonly' => true, |
|
43 | + ), |
|
44 | + |
|
45 | + 'date_created' => array( |
|
46 | + 'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ), |
|
47 | + 'type' => 'string', |
|
48 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
49 | + ), |
|
50 | + |
|
51 | + 'date_created_gmt' => array( |
|
52 | + 'description' => __( 'The GMT date the item was created.', 'invoicing' ), |
|
53 | + 'type' => 'string', |
|
54 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
55 | + 'readonly' => true, |
|
56 | + ), |
|
57 | + |
|
58 | + 'date_modified' => array( |
|
59 | + 'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ), |
|
60 | + 'type' => 'string', |
|
61 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
62 | + 'readonly' => true, |
|
63 | + ), |
|
64 | + |
|
65 | + 'date_modified_gmt' => array( |
|
66 | + 'description' => __( 'The GMT date the item was last modified.', 'invoicing' ), |
|
67 | + 'type' => 'string', |
|
68 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
69 | + 'readonly' => true, |
|
70 | + ), |
|
71 | + |
|
72 | + 'name' => array( |
|
73 | + 'description' => __( "The item's name.", 'invoicing' ), |
|
74 | + 'type' => 'string', |
|
75 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
76 | + 'required' => true, |
|
77 | + ), |
|
78 | + |
|
79 | + 'description' => array( |
|
80 | + 'description' => __( "The item's description.", 'invoicing' ), |
|
81 | + 'type' => 'string', |
|
82 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
83 | + ), |
|
84 | + |
|
85 | + 'owner' => array( |
|
86 | + 'description' => __( 'The owner of the item (user id).', 'invoicing' ), |
|
87 | + 'type' => 'integer', |
|
88 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
89 | + ), |
|
90 | + |
|
91 | + 'price' => array( |
|
92 | + 'description' => __( 'The price of the item.', 'invoicing' ), |
|
93 | + 'type' => 'number', |
|
94 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
95 | + 'required' => true, |
|
96 | + ), |
|
97 | + |
|
98 | + 'the_price' => array( |
|
99 | + 'description' => __( 'The formatted price of the item.', 'invoicing' ), |
|
100 | + 'type' => 'string', |
|
101 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
102 | + 'readonly' => true, |
|
103 | + ), |
|
104 | + |
|
105 | + 'type' => array( |
|
106 | + 'description' => __( 'The item type.', 'invoicing' ), |
|
107 | + 'type' => 'string', |
|
108 | + 'enum' => wpinv_item_types(), |
|
109 | + 'default' => 'custom', |
|
110 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
111 | + ), |
|
112 | + |
|
113 | + 'vat_rule' => array( |
|
114 | + 'description' => __( 'VAT rule applied to the item.', 'invoicing' ), |
|
115 | + 'type' => 'string', |
|
116 | + 'enum' => array_keys( getpaid_tax()->get_rules() ), |
|
117 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
118 | + ), |
|
119 | + |
|
120 | + 'vat_class' => array( |
|
121 | + 'description' => __( 'VAT class for the item.', 'invoicing' ), |
|
122 | + 'type' => 'string', |
|
123 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
124 | + 'enum' => array_keys( getpaid_tax()->get_vat_groups() ), |
|
125 | + ), |
|
126 | + |
|
127 | + 'custom_id' => array( |
|
128 | + 'description' => __( 'Custom id for the item.', 'invoicing' ), |
|
129 | + 'type' => 'string', |
|
130 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
131 | + ), |
|
132 | 132 | |
133 | - 'custom_name' => array( |
|
134 | - 'description' => __( 'Custom name for the item.', 'invoicing' ), |
|
135 | - 'type' => 'string', |
|
136 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
137 | - ), |
|
138 | - |
|
139 | - 'custom_singular_name' => array( |
|
140 | - 'description' => __( 'Custom singular name for the item.', 'invoicing' ), |
|
141 | - 'type' => 'string', |
|
142 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
143 | - ), |
|
144 | - |
|
145 | - 'is_editable' => array( |
|
146 | - 'description' => __( 'Whether or not the item is editable.', 'invoicing' ), |
|
147 | - 'type' => 'integer', |
|
148 | - 'enum' => array( 0, 1 ), |
|
149 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
150 | - ), |
|
151 | - |
|
152 | - 'is_dynamic_pricing' => array( |
|
153 | - 'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ), |
|
154 | - 'type' => 'integer', |
|
155 | - 'enum' => array( 0, 1 ), |
|
156 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
157 | - ), |
|
158 | - |
|
159 | - 'minimum_price' => array( |
|
160 | - 'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ), |
|
161 | - 'type' => 'number', |
|
162 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
163 | - ), |
|
164 | - |
|
165 | - 'is_recurring' => array( |
|
166 | - 'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ), |
|
167 | - 'type' => 'integer', |
|
168 | - 'enum' => array( 0, 1 ), |
|
169 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
170 | - ), |
|
171 | - |
|
172 | - 'initial_price' => array( |
|
173 | - 'description' => __( 'The initial price of the item.', 'invoicing' ), |
|
174 | - 'type' => 'number', |
|
175 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
176 | - 'readonly' => true, |
|
177 | - ), |
|
178 | - |
|
179 | - 'the_initial_price' => array( |
|
180 | - 'description' => __( 'The formatted initial price of the item.', 'invoicing' ), |
|
181 | - 'type' => 'string', |
|
182 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
183 | - 'readonly' => true, |
|
184 | - ), |
|
185 | - |
|
186 | - 'recurring_price' => array( |
|
187 | - 'description' => __( 'The recurring price of the item.', 'invoicing' ), |
|
188 | - 'type' => 'number', |
|
189 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
190 | - 'readonly' => true, |
|
191 | - ), |
|
192 | - |
|
193 | - 'the_recurring_price' => array( |
|
194 | - 'description' => __( 'The formatted recurring price of the item.', 'invoicing' ), |
|
195 | - 'type' => 'string', |
|
196 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
197 | - 'readonly' => true, |
|
198 | - ), |
|
199 | - |
|
200 | - 'recurring_period' => array( |
|
201 | - 'description' => __( 'The recurring period for a recurring item.', 'invoicing' ), |
|
202 | - 'type' => 'string', |
|
203 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
204 | - 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
205 | - ), |
|
206 | - |
|
207 | - 'recurring_interval' => array( |
|
208 | - 'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ), |
|
209 | - 'type' => 'integer', |
|
210 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
211 | - ), |
|
212 | - |
|
213 | - 'recurring_limit' => array( |
|
214 | - 'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ), |
|
215 | - 'type' => 'integer', |
|
216 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
217 | - ), |
|
218 | - |
|
219 | - 'is_free_trial' => array( |
|
220 | - 'description' => __( 'Whether the item has a free trial period.', 'invoicing' ), |
|
221 | - 'type' => 'integer', |
|
222 | - 'enum' => array( 0, 1 ), |
|
223 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
224 | - ), |
|
225 | - |
|
226 | - 'trial_period' => array( |
|
227 | - 'description' => __( 'The trial period.', 'invoicing' ), |
|
228 | - 'type' => 'string', |
|
229 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
230 | - 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
231 | - ), |
|
232 | - |
|
233 | - 'trial_interval' => array( |
|
234 | - 'description' => __( 'The trial interval.', 'invoicing' ), |
|
235 | - 'type' => 'integer', |
|
236 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
237 | - ), |
|
238 | - |
|
239 | - 'first_renewal_date' => array( |
|
240 | - 'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ), |
|
241 | - 'type' => 'string', |
|
242 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
243 | - 'readonly' => true, |
|
244 | - ), |
|
245 | - |
|
246 | - 'edit_url' => array( |
|
247 | - 'description' => __( 'The URL to edit an item.', 'invoicing' ), |
|
248 | - 'type' => 'string', |
|
249 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
250 | - 'readonly' => true, |
|
251 | - ), |
|
133 | + 'custom_name' => array( |
|
134 | + 'description' => __( 'Custom name for the item.', 'invoicing' ), |
|
135 | + 'type' => 'string', |
|
136 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
137 | + ), |
|
138 | + |
|
139 | + 'custom_singular_name' => array( |
|
140 | + 'description' => __( 'Custom singular name for the item.', 'invoicing' ), |
|
141 | + 'type' => 'string', |
|
142 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
143 | + ), |
|
144 | + |
|
145 | + 'is_editable' => array( |
|
146 | + 'description' => __( 'Whether or not the item is editable.', 'invoicing' ), |
|
147 | + 'type' => 'integer', |
|
148 | + 'enum' => array( 0, 1 ), |
|
149 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
150 | + ), |
|
151 | + |
|
152 | + 'is_dynamic_pricing' => array( |
|
153 | + 'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ), |
|
154 | + 'type' => 'integer', |
|
155 | + 'enum' => array( 0, 1 ), |
|
156 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
157 | + ), |
|
158 | + |
|
159 | + 'minimum_price' => array( |
|
160 | + 'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ), |
|
161 | + 'type' => 'number', |
|
162 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
163 | + ), |
|
164 | + |
|
165 | + 'is_recurring' => array( |
|
166 | + 'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ), |
|
167 | + 'type' => 'integer', |
|
168 | + 'enum' => array( 0, 1 ), |
|
169 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
170 | + ), |
|
171 | + |
|
172 | + 'initial_price' => array( |
|
173 | + 'description' => __( 'The initial price of the item.', 'invoicing' ), |
|
174 | + 'type' => 'number', |
|
175 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
176 | + 'readonly' => true, |
|
177 | + ), |
|
178 | + |
|
179 | + 'the_initial_price' => array( |
|
180 | + 'description' => __( 'The formatted initial price of the item.', 'invoicing' ), |
|
181 | + 'type' => 'string', |
|
182 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
183 | + 'readonly' => true, |
|
184 | + ), |
|
185 | + |
|
186 | + 'recurring_price' => array( |
|
187 | + 'description' => __( 'The recurring price of the item.', 'invoicing' ), |
|
188 | + 'type' => 'number', |
|
189 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
190 | + 'readonly' => true, |
|
191 | + ), |
|
192 | + |
|
193 | + 'the_recurring_price' => array( |
|
194 | + 'description' => __( 'The formatted recurring price of the item.', 'invoicing' ), |
|
195 | + 'type' => 'string', |
|
196 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
197 | + 'readonly' => true, |
|
198 | + ), |
|
199 | + |
|
200 | + 'recurring_period' => array( |
|
201 | + 'description' => __( 'The recurring period for a recurring item.', 'invoicing' ), |
|
202 | + 'type' => 'string', |
|
203 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
204 | + 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
205 | + ), |
|
206 | + |
|
207 | + 'recurring_interval' => array( |
|
208 | + 'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ), |
|
209 | + 'type' => 'integer', |
|
210 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
211 | + ), |
|
212 | + |
|
213 | + 'recurring_limit' => array( |
|
214 | + 'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ), |
|
215 | + 'type' => 'integer', |
|
216 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
217 | + ), |
|
218 | + |
|
219 | + 'is_free_trial' => array( |
|
220 | + 'description' => __( 'Whether the item has a free trial period.', 'invoicing' ), |
|
221 | + 'type' => 'integer', |
|
222 | + 'enum' => array( 0, 1 ), |
|
223 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
224 | + ), |
|
225 | + |
|
226 | + 'trial_period' => array( |
|
227 | + 'description' => __( 'The trial period.', 'invoicing' ), |
|
228 | + 'type' => 'string', |
|
229 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
230 | + 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
231 | + ), |
|
232 | + |
|
233 | + 'trial_interval' => array( |
|
234 | + 'description' => __( 'The trial interval.', 'invoicing' ), |
|
235 | + 'type' => 'integer', |
|
236 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
237 | + ), |
|
238 | + |
|
239 | + 'first_renewal_date' => array( |
|
240 | + 'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ), |
|
241 | + 'type' => 'string', |
|
242 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
243 | + 'readonly' => true, |
|
244 | + ), |
|
245 | + |
|
246 | + 'edit_url' => array( |
|
247 | + 'description' => __( 'The URL to edit an item.', 'invoicing' ), |
|
248 | + 'type' => 'string', |
|
249 | + 'context' => array( 'view', 'edit', 'embed' ), |
|
250 | + 'readonly' => true, |
|
251 | + ), |
|
252 | 252 | ); |
@@ -9,244 +9,244 @@ |
||
9 | 9 | * @version 1.0.19 |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | return array( |
15 | 15 | |
16 | 16 | 'id' => array( |
17 | - 'description' => __( 'Unique identifier for the item.', 'invoicing' ), |
|
17 | + 'description' => __('Unique identifier for the item.', 'invoicing'), |
|
18 | 18 | 'type' => 'integer', |
19 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
19 | + 'context' => array('view', 'edit', 'embed'), |
|
20 | 20 | 'readonly' => true, |
21 | 21 | ), |
22 | 22 | |
23 | 23 | 'parent_id' => array( |
24 | - 'description' => __( 'Parent item ID.', 'invoicing' ), |
|
24 | + 'description' => __('Parent item ID.', 'invoicing'), |
|
25 | 25 | 'type' => 'integer', |
26 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
26 | + 'context' => array('view', 'edit', 'embed'), |
|
27 | 27 | 'default' => 0, |
28 | 28 | ), |
29 | 29 | |
30 | 30 | 'status' => array( |
31 | - 'description' => __( 'A named status for the item.', 'invoicing' ), |
|
31 | + 'description' => __('A named status for the item.', 'invoicing'), |
|
32 | 32 | 'type' => 'string', |
33 | - 'enum' => array( 'draft', 'pending', 'publish' ), |
|
34 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
33 | + 'enum' => array('draft', 'pending', 'publish'), |
|
34 | + 'context' => array('view', 'edit', 'embed'), |
|
35 | 35 | 'default' => 'draft', |
36 | 36 | ), |
37 | 37 | |
38 | 38 | 'version' => array( |
39 | - 'description' => __( 'Plugin version when the item was created.', 'invoicing' ), |
|
39 | + 'description' => __('Plugin version when the item was created.', 'invoicing'), |
|
40 | 40 | 'type' => 'string', |
41 | - 'context' => array( 'view', 'edit' ), |
|
41 | + 'context' => array('view', 'edit'), |
|
42 | 42 | 'readonly' => true, |
43 | 43 | ), |
44 | 44 | |
45 | 45 | 'date_created' => array( |
46 | - 'description' => __( "The date the item was created, in the site's timezone.", 'invoicing' ), |
|
46 | + 'description' => __("The date the item was created, in the site's timezone.", 'invoicing'), |
|
47 | 47 | 'type' => 'string', |
48 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
48 | + 'context' => array('view', 'edit', 'embed'), |
|
49 | 49 | ), |
50 | 50 | |
51 | 51 | 'date_created_gmt' => array( |
52 | - 'description' => __( 'The GMT date the item was created.', 'invoicing' ), |
|
52 | + 'description' => __('The GMT date the item was created.', 'invoicing'), |
|
53 | 53 | 'type' => 'string', |
54 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
54 | + 'context' => array('view', 'edit', 'embed'), |
|
55 | 55 | 'readonly' => true, |
56 | 56 | ), |
57 | 57 | |
58 | 58 | 'date_modified' => array( |
59 | - 'description' => __( "The date the item was last modified, in the site's timezone.", 'invoicing' ), |
|
59 | + 'description' => __("The date the item was last modified, in the site's timezone.", 'invoicing'), |
|
60 | 60 | 'type' => 'string', |
61 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
61 | + 'context' => array('view', 'edit', 'embed'), |
|
62 | 62 | 'readonly' => true, |
63 | 63 | ), |
64 | 64 | |
65 | 65 | 'date_modified_gmt' => array( |
66 | - 'description' => __( 'The GMT date the item was last modified.', 'invoicing' ), |
|
66 | + 'description' => __('The GMT date the item was last modified.', 'invoicing'), |
|
67 | 67 | 'type' => 'string', |
68 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
68 | + 'context' => array('view', 'edit', 'embed'), |
|
69 | 69 | 'readonly' => true, |
70 | 70 | ), |
71 | 71 | |
72 | 72 | 'name' => array( |
73 | - 'description' => __( "The item's name.", 'invoicing' ), |
|
73 | + 'description' => __("The item's name.", 'invoicing'), |
|
74 | 74 | 'type' => 'string', |
75 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
75 | + 'context' => array('view', 'edit', 'embed'), |
|
76 | 76 | 'required' => true, |
77 | 77 | ), |
78 | 78 | |
79 | 79 | 'description' => array( |
80 | - 'description' => __( "The item's description.", 'invoicing' ), |
|
80 | + 'description' => __("The item's description.", 'invoicing'), |
|
81 | 81 | 'type' => 'string', |
82 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
82 | + 'context' => array('view', 'edit', 'embed'), |
|
83 | 83 | ), |
84 | 84 | |
85 | 85 | 'owner' => array( |
86 | - 'description' => __( 'The owner of the item (user id).', 'invoicing' ), |
|
86 | + 'description' => __('The owner of the item (user id).', 'invoicing'), |
|
87 | 87 | 'type' => 'integer', |
88 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
88 | + 'context' => array('view', 'edit', 'embed'), |
|
89 | 89 | ), |
90 | 90 | |
91 | 91 | 'price' => array( |
92 | - 'description' => __( 'The price of the item.', 'invoicing' ), |
|
92 | + 'description' => __('The price of the item.', 'invoicing'), |
|
93 | 93 | 'type' => 'number', |
94 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
94 | + 'context' => array('view', 'edit', 'embed'), |
|
95 | 95 | 'required' => true, |
96 | 96 | ), |
97 | 97 | |
98 | 98 | 'the_price' => array( |
99 | - 'description' => __( 'The formatted price of the item.', 'invoicing' ), |
|
99 | + 'description' => __('The formatted price of the item.', 'invoicing'), |
|
100 | 100 | 'type' => 'string', |
101 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
101 | + 'context' => array('view', 'edit', 'embed'), |
|
102 | 102 | 'readonly' => true, |
103 | 103 | ), |
104 | 104 | |
105 | 105 | 'type' => array( |
106 | - 'description' => __( 'The item type.', 'invoicing' ), |
|
106 | + 'description' => __('The item type.', 'invoicing'), |
|
107 | 107 | 'type' => 'string', |
108 | 108 | 'enum' => wpinv_item_types(), |
109 | 109 | 'default' => 'custom', |
110 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
110 | + 'context' => array('view', 'edit', 'embed'), |
|
111 | 111 | ), |
112 | 112 | |
113 | 113 | 'vat_rule' => array( |
114 | - 'description' => __( 'VAT rule applied to the item.', 'invoicing' ), |
|
114 | + 'description' => __('VAT rule applied to the item.', 'invoicing'), |
|
115 | 115 | 'type' => 'string', |
116 | - 'enum' => array_keys( getpaid_tax()->get_rules() ), |
|
117 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
116 | + 'enum' => array_keys(getpaid_tax()->get_rules()), |
|
117 | + 'context' => array('view', 'edit', 'embed'), |
|
118 | 118 | ), |
119 | 119 | |
120 | 120 | 'vat_class' => array( |
121 | - 'description' => __( 'VAT class for the item.', 'invoicing' ), |
|
121 | + 'description' => __('VAT class for the item.', 'invoicing'), |
|
122 | 122 | 'type' => 'string', |
123 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
124 | - 'enum' => array_keys( getpaid_tax()->get_vat_groups() ), |
|
123 | + 'context' => array('view', 'edit', 'embed'), |
|
124 | + 'enum' => array_keys(getpaid_tax()->get_vat_groups()), |
|
125 | 125 | ), |
126 | 126 | |
127 | 127 | 'custom_id' => array( |
128 | - 'description' => __( 'Custom id for the item.', 'invoicing' ), |
|
128 | + 'description' => __('Custom id for the item.', 'invoicing'), |
|
129 | 129 | 'type' => 'string', |
130 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
130 | + 'context' => array('view', 'edit', 'embed'), |
|
131 | 131 | ), |
132 | 132 | |
133 | 133 | 'custom_name' => array( |
134 | - 'description' => __( 'Custom name for the item.', 'invoicing' ), |
|
134 | + 'description' => __('Custom name for the item.', 'invoicing'), |
|
135 | 135 | 'type' => 'string', |
136 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
136 | + 'context' => array('view', 'edit', 'embed'), |
|
137 | 137 | ), |
138 | 138 | |
139 | 139 | 'custom_singular_name' => array( |
140 | - 'description' => __( 'Custom singular name for the item.', 'invoicing' ), |
|
140 | + 'description' => __('Custom singular name for the item.', 'invoicing'), |
|
141 | 141 | 'type' => 'string', |
142 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
142 | + 'context' => array('view', 'edit', 'embed'), |
|
143 | 143 | ), |
144 | 144 | |
145 | 145 | 'is_editable' => array( |
146 | - 'description' => __( 'Whether or not the item is editable.', 'invoicing' ), |
|
146 | + 'description' => __('Whether or not the item is editable.', 'invoicing'), |
|
147 | 147 | 'type' => 'integer', |
148 | - 'enum' => array( 0, 1 ), |
|
149 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
148 | + 'enum' => array(0, 1), |
|
149 | + 'context' => array('view', 'edit', 'embed'), |
|
150 | 150 | ), |
151 | 151 | |
152 | 152 | 'is_dynamic_pricing' => array( |
153 | - 'description' => __( 'Whether or not customers can enter their own prices when checking out.', 'invoicing' ), |
|
153 | + 'description' => __('Whether or not customers can enter their own prices when checking out.', 'invoicing'), |
|
154 | 154 | 'type' => 'integer', |
155 | - 'enum' => array( 0, 1 ), |
|
156 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
155 | + 'enum' => array(0, 1), |
|
156 | + 'context' => array('view', 'edit', 'embed'), |
|
157 | 157 | ), |
158 | 158 | |
159 | 159 | 'minimum_price' => array( |
160 | - 'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ), |
|
160 | + 'description' => __('For dynamic prices, this is the minimum price that a user can set.', 'invoicing'), |
|
161 | 161 | 'type' => 'number', |
162 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
162 | + 'context' => array('view', 'edit', 'embed'), |
|
163 | 163 | ), |
164 | 164 | |
165 | 165 | 'is_recurring' => array( |
166 | - 'description' => __( 'Whether or not this is a subscription item.', 'invoicing' ), |
|
166 | + 'description' => __('Whether or not this is a subscription item.', 'invoicing'), |
|
167 | 167 | 'type' => 'integer', |
168 | - 'enum' => array( 0, 1 ), |
|
169 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
168 | + 'enum' => array(0, 1), |
|
169 | + 'context' => array('view', 'edit', 'embed'), |
|
170 | 170 | ), |
171 | 171 | |
172 | 172 | 'initial_price' => array( |
173 | - 'description' => __( 'The initial price of the item.', 'invoicing' ), |
|
173 | + 'description' => __('The initial price of the item.', 'invoicing'), |
|
174 | 174 | 'type' => 'number', |
175 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
175 | + 'context' => array('view', 'edit', 'embed'), |
|
176 | 176 | 'readonly' => true, |
177 | 177 | ), |
178 | 178 | |
179 | 179 | 'the_initial_price' => array( |
180 | - 'description' => __( 'The formatted initial price of the item.', 'invoicing' ), |
|
180 | + 'description' => __('The formatted initial price of the item.', 'invoicing'), |
|
181 | 181 | 'type' => 'string', |
182 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
182 | + 'context' => array('view', 'edit', 'embed'), |
|
183 | 183 | 'readonly' => true, |
184 | 184 | ), |
185 | 185 | |
186 | 186 | 'recurring_price' => array( |
187 | - 'description' => __( 'The recurring price of the item.', 'invoicing' ), |
|
187 | + 'description' => __('The recurring price of the item.', 'invoicing'), |
|
188 | 188 | 'type' => 'number', |
189 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
189 | + 'context' => array('view', 'edit', 'embed'), |
|
190 | 190 | 'readonly' => true, |
191 | 191 | ), |
192 | 192 | |
193 | 193 | 'the_recurring_price' => array( |
194 | - 'description' => __( 'The formatted recurring price of the item.', 'invoicing' ), |
|
194 | + 'description' => __('The formatted recurring price of the item.', 'invoicing'), |
|
195 | 195 | 'type' => 'string', |
196 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
196 | + 'context' => array('view', 'edit', 'embed'), |
|
197 | 197 | 'readonly' => true, |
198 | 198 | ), |
199 | 199 | |
200 | 200 | 'recurring_period' => array( |
201 | - 'description' => __( 'The recurring period for a recurring item.', 'invoicing' ), |
|
201 | + 'description' => __('The recurring period for a recurring item.', 'invoicing'), |
|
202 | 202 | 'type' => 'string', |
203 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
204 | - 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
203 | + 'context' => array('view', 'edit', 'embed'), |
|
204 | + 'enum' => array('D', 'W', 'M', 'Y'), |
|
205 | 205 | ), |
206 | 206 | |
207 | 207 | 'recurring_interval' => array( |
208 | - 'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ), |
|
208 | + 'description' => __('The recurring interval for a subscription item.', 'invoicing'), |
|
209 | 209 | 'type' => 'integer', |
210 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
210 | + 'context' => array('view', 'edit', 'embed'), |
|
211 | 211 | ), |
212 | 212 | |
213 | 213 | 'recurring_limit' => array( |
214 | - 'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ), |
|
214 | + 'description' => __('The maximum number of renewals for a subscription item.', 'invoicing'), |
|
215 | 215 | 'type' => 'integer', |
216 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
216 | + 'context' => array('view', 'edit', 'embed'), |
|
217 | 217 | ), |
218 | 218 | |
219 | 219 | 'is_free_trial' => array( |
220 | - 'description' => __( 'Whether the item has a free trial period.', 'invoicing' ), |
|
220 | + 'description' => __('Whether the item has a free trial period.', 'invoicing'), |
|
221 | 221 | 'type' => 'integer', |
222 | - 'enum' => array( 0, 1 ), |
|
223 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
222 | + 'enum' => array(0, 1), |
|
223 | + 'context' => array('view', 'edit', 'embed'), |
|
224 | 224 | ), |
225 | 225 | |
226 | 226 | 'trial_period' => array( |
227 | - 'description' => __( 'The trial period.', 'invoicing' ), |
|
227 | + 'description' => __('The trial period.', 'invoicing'), |
|
228 | 228 | 'type' => 'string', |
229 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
230 | - 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
229 | + 'context' => array('view', 'edit', 'embed'), |
|
230 | + 'enum' => array('D', 'W', 'M', 'Y'), |
|
231 | 231 | ), |
232 | 232 | |
233 | 233 | 'trial_interval' => array( |
234 | - 'description' => __( 'The trial interval.', 'invoicing' ), |
|
234 | + 'description' => __('The trial interval.', 'invoicing'), |
|
235 | 235 | 'type' => 'integer', |
236 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
236 | + 'context' => array('view', 'edit', 'embed'), |
|
237 | 237 | ), |
238 | 238 | |
239 | 239 | 'first_renewal_date' => array( |
240 | - 'description' => __( 'The first renewal date in case the item was to be bought today.', 'invoicing' ), |
|
240 | + 'description' => __('The first renewal date in case the item was to be bought today.', 'invoicing'), |
|
241 | 241 | 'type' => 'string', |
242 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
242 | + 'context' => array('view', 'edit', 'embed'), |
|
243 | 243 | 'readonly' => true, |
244 | 244 | ), |
245 | 245 | |
246 | 246 | 'edit_url' => array( |
247 | - 'description' => __( 'The URL to edit an item.', 'invoicing' ), |
|
247 | + 'description' => __('The URL to edit an item.', 'invoicing'), |
|
248 | 248 | 'type' => 'string', |
249 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
249 | + 'context' => array('view', 'edit', 'embed'), |
|
250 | 250 | 'readonly' => true, |
251 | 251 | ), |
252 | 252 | ); |
@@ -57,26 +57,26 @@ |
||
57 | 57 | add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) ); |
58 | 58 | } |
59 | 59 | |
60 | - /** |
|
61 | - * Registers routes |
|
62 | - * |
|
60 | + /** |
|
61 | + * Registers routes |
|
62 | + * |
|
63 | 63 | * @since 1.0.13 |
64 | - */ |
|
65 | - public function register_rest_routes() { |
|
64 | + */ |
|
65 | + public function register_rest_routes() { |
|
66 | 66 | |
67 | 67 | // Discounts. |
68 | 68 | $this->discounts_controller->register_routes(); |
69 | 69 | |
70 | 70 | /** |
71 | - * Fires when registering Invoicing REST routes. |
|
72 | - * |
|
73 | - * |
|
74 | - * @since 1.0.15 |
|
75 | - * |
|
76 | - * |
|
77 | - * @param array $invoice_data Invoice properties. |
|
78 | - * @param WP_REST_Request $request The request used. |
|
79 | - */ |
|
71 | + * Fires when registering Invoicing REST routes. |
|
72 | + * |
|
73 | + * |
|
74 | + * @since 1.0.15 |
|
75 | + * |
|
76 | + * |
|
77 | + * @param array $invoice_data Invoice properties. |
|
78 | + * @param WP_REST_Request $request The request used. |
|
79 | + */ |
|
80 | 80 | do_action( "wpinv_register_rest_routes", $this ); |
81 | 81 | |
82 | 82 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @param string A prefix for our REST routes |
21 | 21 | */ |
22 | - public $api_namespace = ''; |
|
22 | + public $api_namespace = ''; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @param WPInv_REST_Invoice_Controller Invoices controller |
@@ -42,19 +42,19 @@ discard block |
||
42 | 42 | * @since 1.0.13 |
43 | 43 | * Sets the API namespace and inits hooks |
44 | 44 | */ |
45 | - public function __construct( $api_namespace = 'invoicing/v1' ) { |
|
45 | + public function __construct($api_namespace = 'invoicing/v1') { |
|
46 | 46 | |
47 | 47 | // Include controllers and related files |
48 | 48 | $this->includes(); |
49 | 49 | |
50 | 50 | // Set up class variables |
51 | - $this->api_namespace = apply_filters( 'wpinv_rest_api_namespace', $api_namespace ); |
|
51 | + $this->api_namespace = apply_filters('wpinv_rest_api_namespace', $api_namespace); |
|
52 | 52 | $this->invoices_controller = new WPInv_REST_Invoice_Controller(); |
53 | 53 | $this->items_controller = new WPInv_REST_Items_Controller(); |
54 | - $this->discounts_controller= new WPInv_REST_Discounts_Controller( $this->api_namespace ); |
|
54 | + $this->discounts_controller = new WPInv_REST_Discounts_Controller($this->api_namespace); |
|
55 | 55 | |
56 | 56 | //Register REST routes |
57 | - add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) ); |
|
57 | + add_action('rest_api_init', array($this, 'register_rest_routes')); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param array $invoice_data Invoice properties. |
78 | 78 | * @param WP_REST_Request $request The request used. |
79 | 79 | */ |
80 | - do_action( "wpinv_register_rest_routes", $this ); |
|
80 | + do_action("wpinv_register_rest_routes", $this); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | protected function includes() { |
91 | 91 | |
92 | 92 | // Invoices |
93 | - require_once( WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-invoice-controller.php' ); |
|
93 | + require_once(WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-invoice-controller.php'); |
|
94 | 94 | |
95 | 95 | // Items |
96 | - require_once( WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-items-controller.php' ); |
|
96 | + require_once(WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-items-controller.php'); |
|
97 | 97 | |
98 | 98 | // Discounts |
99 | - require_once( WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-discounts-controller.php' ); |
|
99 | + require_once(WPINV_PLUGIN_DIR . 'includes/api/class-wpinv-rest-discounts-controller.php'); |
|
100 | 100 | |
101 | 101 | } |
102 | 102 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Returns an array of payment gateways. |
@@ -12,141 +12,141 @@ discard block |
||
12 | 12 | * @return array |
13 | 13 | */ |
14 | 14 | function wpinv_get_payment_gateways() { |
15 | - return apply_filters( 'wpinv_payment_gateways', array() ); |
|
15 | + return apply_filters('wpinv_payment_gateways', array()); |
|
16 | 16 | } |
17 | 17 | |
18 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
18 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
19 | 19 | global $wpinv_options; |
20 | 20 | |
21 | 21 | $gateways = array(); |
22 | - foreach ( $all_gateways as $key => $gateway ) { |
|
23 | - if ( !empty( $wpinv_options[$key . '_title'] ) ) { |
|
24 | - $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' ); |
|
22 | + foreach ($all_gateways as $key => $gateway) { |
|
23 | + if (!empty($wpinv_options[$key . '_title'])) { |
|
24 | + $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing'); |
|
25 | 25 | } |
26 | 26 | |
27 | - $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
27 | + $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
28 | 28 | } |
29 | 29 | |
30 | - asort( $gateways ); |
|
30 | + asort($gateways); |
|
31 | 31 | |
32 | - foreach ( $gateways as $gateway => $key ) { |
|
32 | + foreach ($gateways as $gateway => $key) { |
|
33 | 33 | $gateways[$gateway] = $all_gateways[$gateway]; |
34 | 34 | } |
35 | 35 | |
36 | 36 | return $gateways; |
37 | 37 | } |
38 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
38 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
39 | 39 | |
40 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
40 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
41 | 41 | $gateways = wpinv_get_payment_gateways(); |
42 | - $enabled = wpinv_get_option( 'gateways', false ); |
|
42 | + $enabled = wpinv_get_option('gateways', false); |
|
43 | 43 | |
44 | 44 | $gateway_list = array(); |
45 | 45 | |
46 | - foreach ( $gateways as $key => $gateway ) { |
|
47 | - if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) { |
|
48 | - $gateway_list[ $key ] = $gateway; |
|
46 | + foreach ($gateways as $key => $gateway) { |
|
47 | + if (isset($enabled[$key]) && $enabled[$key] == 1) { |
|
48 | + $gateway_list[$key] = $gateway; |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - if ( true === $sort ) { |
|
53 | - uasort( $gateway_list, 'wpinv_sort_gateway_order' ); |
|
52 | + if (true === $sort) { |
|
53 | + uasort($gateway_list, 'wpinv_sort_gateway_order'); |
|
54 | 54 | |
55 | 55 | // Reorder our gateways so the default is first |
56 | 56 | $default_gateway_id = wpinv_get_default_gateway(); |
57 | 57 | |
58 | - if ( wpinv_is_gateway_active( $default_gateway_id ) ) { |
|
59 | - $default_gateway = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] ); |
|
60 | - unset( $gateway_list[ $default_gateway_id ] ); |
|
58 | + if (wpinv_is_gateway_active($default_gateway_id)) { |
|
59 | + $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]); |
|
60 | + unset($gateway_list[$default_gateway_id]); |
|
61 | 61 | |
62 | - $gateway_list = array_merge( $default_gateway, $gateway_list ); |
|
62 | + $gateway_list = array_merge($default_gateway, $gateway_list); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | - return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list ); |
|
66 | + return apply_filters('wpinv_enabled_payment_gateways', $gateway_list); |
|
67 | 67 | } |
68 | 68 | |
69 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
69 | +function wpinv_sort_gateway_order($a, $b) { |
|
70 | 70 | return $a['ordering'] - $b['ordering']; |
71 | 71 | } |
72 | 72 | |
73 | -function wpinv_is_gateway_active( $gateway ) { |
|
73 | +function wpinv_is_gateway_active($gateway) { |
|
74 | 74 | $gateways = wpinv_get_enabled_payment_gateways(); |
75 | 75 | |
76 | - $ret = is_array($gateways) && $gateway ? array_key_exists( $gateway, $gateways ) : false; |
|
76 | + $ret = is_array($gateways) && $gateway ? array_key_exists($gateway, $gateways) : false; |
|
77 | 77 | |
78 | - return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways ); |
|
78 | + return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | function wpinv_get_default_gateway() { |
82 | - $default = wpinv_get_option( 'default_gateway', 'paypal' ); |
|
82 | + $default = wpinv_get_option('default_gateway', 'paypal'); |
|
83 | 83 | |
84 | - if ( !wpinv_is_gateway_active( $default ) ) { |
|
84 | + if (!wpinv_is_gateway_active($default)) { |
|
85 | 85 | $gateways = wpinv_get_enabled_payment_gateways(); |
86 | - $gateways = array_keys( $gateways ); |
|
87 | - $default = reset( $gateways ); |
|
86 | + $gateways = array_keys($gateways); |
|
87 | + $default = reset($gateways); |
|
88 | 88 | } |
89 | 89 | |
90 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
90 | + return apply_filters('wpinv_default_gateway', $default); |
|
91 | 91 | } |
92 | 92 | |
93 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
93 | +function wpinv_get_gateway_admin_label($gateway) { |
|
94 | 94 | $gateways = wpinv_get_payment_gateways(); |
95 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
96 | - $payment = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false; |
|
95 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
96 | + $payment = isset($_GET['id']) ? absint($_GET['id']) : false; |
|
97 | 97 | |
98 | - if( $gateway == 'manual' && $payment ) { |
|
99 | - if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) { |
|
100 | - $label = __( 'Free Purchase', 'invoicing' ); |
|
98 | + if ($gateway == 'manual' && $payment) { |
|
99 | + if (!((float) wpinv_payment_total($payment) > 0)) { |
|
100 | + $label = __('Free Purchase', 'invoicing'); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | - return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
104 | + return apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
105 | 105 | } |
106 | 106 | |
107 | -function wpinv_get_gateway_description( $gateway ) { |
|
107 | +function wpinv_get_gateway_description($gateway) { |
|
108 | 108 | global $wpinv_options; |
109 | 109 | |
110 | - $description = ! empty( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
110 | + $description = !empty($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
111 | 111 | |
112 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
112 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
113 | 113 | } |
114 | 114 | |
115 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
116 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
115 | +function wpinv_get_gateway_button_label($gateway) { |
|
116 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
117 | 117 | } |
118 | 118 | |
119 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
119 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
120 | 120 | $gateways = wpinv_get_payment_gateways(); |
121 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
121 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
122 | 122 | |
123 | - if ( $gateway == 'none' ) { |
|
124 | - $label = __( 'None', 'invoicing' ); |
|
123 | + if ($gateway == 'none') { |
|
124 | + $label = __('None', 'invoicing'); |
|
125 | 125 | } |
126 | 126 | |
127 | - return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway ); |
|
127 | + return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway); |
|
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_settings_sections_gateways( $settings ) { |
|
130 | +function wpinv_settings_sections_gateways($settings) { |
|
131 | 131 | $gateways = wpinv_get_payment_gateways(); |
132 | 132 | |
133 | 133 | if (!empty($gateways)) { |
134 | - foreach ($gateways as $key => $gateway) { |
|
134 | + foreach ($gateways as $key => $gateway) { |
|
135 | 135 | $settings[$key] = $gateway['admin_label']; |
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | 139 | return $settings; |
140 | 140 | } |
141 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
141 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
142 | 142 | |
143 | 143 | /** |
144 | 144 | * Adds GateWay settings. |
145 | 145 | */ |
146 | -function wpinv_settings_gateways( $settings ) { |
|
146 | +function wpinv_settings_gateways($settings) { |
|
147 | 147 | |
148 | 148 | // Loop through each gateway. |
149 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
149 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
150 | 150 | |
151 | 151 | $gateway_settings = array( |
152 | 152 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | "{$key}_header" => array( |
155 | 155 | |
156 | 156 | 'id' => "{$key}_gateway_header", |
157 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
157 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
158 | 158 | 'custom' => $key, |
159 | 159 | 'type' => 'gateway_header', |
160 | 160 | |
@@ -163,56 +163,56 @@ discard block |
||
163 | 163 | // Activate/Deactivate a gateway. |
164 | 164 | "{$key}_active" => array( |
165 | 165 | 'id' => $key . '_active', |
166 | - 'name' => __( 'Activate', 'invoicing' ), |
|
167 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
166 | + 'name' => __('Activate', 'invoicing'), |
|
167 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
168 | 168 | 'type' => 'checkbox', |
169 | 169 | ), |
170 | 170 | |
171 | 171 | // Activate/Deactivate sandbox. |
172 | 172 | "{$key}_sandbox" => array( |
173 | 173 | 'id' => $key . '_sandbox', |
174 | - 'name' => __( 'Sandbox', 'invoicing' ), |
|
175 | - 'desc' => __( 'Enable sandbox to test payments', 'invoicing' ), |
|
174 | + 'name' => __('Sandbox', 'invoicing'), |
|
175 | + 'desc' => __('Enable sandbox to test payments', 'invoicing'), |
|
176 | 176 | 'type' => 'checkbox', |
177 | 177 | ), |
178 | 178 | |
179 | 179 | // Checkout title. |
180 | 180 | "{$key}_title" => array( |
181 | 181 | 'id' => $key . '_title', |
182 | - 'name' => __( 'Checkout Title', 'invoicing' ), |
|
183 | - 'std' => isset( $gateway['checkout_label'] ) ? $gateway['checkout_label'] : '', |
|
182 | + 'name' => __('Checkout Title', 'invoicing'), |
|
183 | + 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '', |
|
184 | 184 | 'type' => 'text', |
185 | 185 | ), |
186 | 186 | |
187 | 187 | // Checkout description. |
188 | 188 | "{$key}_desc" => array( |
189 | 189 | 'id' => $key . '_desc', |
190 | - 'name' => __( 'Checkout Description', 'invoicing' ), |
|
191 | - 'std' => apply_filters( "getpaid_default_{$key}_checkout_description", '' ), |
|
190 | + 'name' => __('Checkout Description', 'invoicing'), |
|
191 | + 'std' => apply_filters("getpaid_default_{$key}_checkout_description", ''), |
|
192 | 192 | 'type' => 'text', |
193 | 193 | ), |
194 | 194 | |
195 | 195 | // Checkout order. |
196 | 196 | "{$key}_ordering" => array( |
197 | 197 | 'id' => $key . '_ordering', |
198 | - 'name' => __( 'Priority', 'invoicing' ), |
|
199 | - 'std' => apply_filters( "getpaid_default_{$key}_checkout_description", '' ), |
|
198 | + 'name' => __('Priority', 'invoicing'), |
|
199 | + 'std' => apply_filters("getpaid_default_{$key}_checkout_description", ''), |
|
200 | 200 | 'type' => 'number', |
201 | 201 | 'step' => '1', |
202 | 202 | 'min' => '-100000', |
203 | 203 | 'max' => '100000', |
204 | - 'std' => isset( $gateway['ordering'] ) ? $gateway['ordering'] : '10', |
|
204 | + 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
|
205 | 205 | ), |
206 | 206 | |
207 | 207 | ); |
208 | 208 | |
209 | 209 | // Maybe remove the sandbox. |
210 | - if ( ! apply_filters( "wpinv_{$key}_supports_sandbox", false ) ) { |
|
211 | - unset( $gateway_settings["{$key}_sandbox"] ); |
|
210 | + if (!apply_filters("wpinv_{$key}_supports_sandbox", false)) { |
|
211 | + unset($gateway_settings["{$key}_sandbox"]); |
|
212 | 212 | } |
213 | 213 | |
214 | - $gateway_settings = apply_filters( 'wpinv_gateway_settings', $gateway_settings, $key, $gateway ); |
|
215 | - $gateway_settings = apply_filters( 'wpinv_gateway_settings_' . $key, $gateway_settings, $gateway ); |
|
214 | + $gateway_settings = apply_filters('wpinv_gateway_settings', $gateway_settings, $key, $gateway); |
|
215 | + $gateway_settings = apply_filters('wpinv_gateway_settings_' . $key, $gateway_settings, $gateway); |
|
216 | 216 | |
217 | 217 | $settings[$key] = $gateway_settings; |
218 | 218 | } |
@@ -220,38 +220,38 @@ discard block |
||
220 | 220 | return $settings; |
221 | 221 | |
222 | 222 | } |
223 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
223 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
224 | 224 | |
225 | -function wpinv_gateway_header_callback( $args ) { |
|
226 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
225 | +function wpinv_gateway_header_callback($args) { |
|
226 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
227 | 227 | } |
228 | 228 | |
229 | -function wpinv_get_gateway_supports( $gateway ) { |
|
229 | +function wpinv_get_gateway_supports($gateway) { |
|
230 | 230 | $gateways = wpinv_get_enabled_payment_gateways(); |
231 | - $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array(); |
|
232 | - return apply_filters( 'wpinv_gateway_supports', $supports, $gateway ); |
|
231 | + $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array(); |
|
232 | + return apply_filters('wpinv_gateway_supports', $supports, $gateway); |
|
233 | 233 | } |
234 | 234 | |
235 | -function wpinv_gateway_supports_buy_now( $gateway ) { |
|
236 | - $supports = wpinv_get_gateway_supports( $gateway ); |
|
237 | - $ret = in_array( 'buy_now', $supports ); |
|
238 | - return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway ); |
|
235 | +function wpinv_gateway_supports_buy_now($gateway) { |
|
236 | + $supports = wpinv_get_gateway_supports($gateway); |
|
237 | + $ret = in_array('buy_now', $supports); |
|
238 | + return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | function wpinv_shop_supports_buy_now() { |
242 | 242 | $gateways = wpinv_get_enabled_payment_gateways(); |
243 | 243 | $ret = false; |
244 | 244 | |
245 | - if ( !wpinv_use_taxes() && $gateways ) { |
|
246 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
247 | - if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) { |
|
245 | + if (!wpinv_use_taxes() && $gateways) { |
|
246 | + foreach ($gateways as $gateway_id => $gateway) { |
|
247 | + if (wpinv_gateway_supports_buy_now($gateway_id)) { |
|
248 | 248 | $ret = true; |
249 | 249 | break; |
250 | 250 | } |
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
254 | - return apply_filters( 'wpinv_shop_supports_buy_now', $ret ); |
|
254 | + return apply_filters('wpinv_shop_supports_buy_now', $ret); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | |
@@ -259,61 +259,61 @@ discard block |
||
259 | 259 | $gateways = wpinv_get_enabled_payment_gateways(); |
260 | 260 | $show_gateways = false; |
261 | 261 | |
262 | - $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false; |
|
262 | + $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false; |
|
263 | 263 | |
264 | - if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) { |
|
264 | + if (count($gateways) > 1 && empty($chosen_gateway)) { |
|
265 | 265 | $show_gateways = true; |
266 | - if ( wpinv_get_cart_total() <= 0 ) { |
|
266 | + if (wpinv_get_cart_total() <= 0) { |
|
267 | 267 | $show_gateways = false; |
268 | 268 | } |
269 | 269 | } |
270 | 270 | |
271 | - if ( !$show_gateways && wpinv_cart_has_recurring_item() ) { |
|
271 | + if (!$show_gateways && wpinv_cart_has_recurring_item()) { |
|
272 | 272 | $show_gateways = true; |
273 | 273 | } |
274 | 274 | |
275 | - return apply_filters( 'wpinv_show_gateways', $show_gateways ); |
|
275 | + return apply_filters('wpinv_show_gateways', $show_gateways); |
|
276 | 276 | } |
277 | 277 | |
278 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
279 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
278 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
279 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
280 | 280 | |
281 | 281 | $chosen = false; |
282 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
282 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
283 | 283 | $chosen = $invoice->get_gateway(); |
284 | 284 | } |
285 | 285 | |
286 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
286 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
287 | 287 | |
288 | - if ( false !== $chosen ) { |
|
289 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
288 | + if (false !== $chosen) { |
|
289 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
290 | 290 | } |
291 | 291 | |
292 | - if ( ! empty ( $chosen ) ) { |
|
293 | - $enabled_gateway = urldecode( $chosen ); |
|
294 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
292 | + if (!empty ($chosen)) { |
|
293 | + $enabled_gateway = urldecode($chosen); |
|
294 | + } else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) { |
|
295 | 295 | $enabled_gateway = 'manual'; |
296 | 296 | } else { |
297 | 297 | $enabled_gateway = wpinv_get_default_gateway(); |
298 | 298 | } |
299 | 299 | |
300 | - if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
|
301 | - if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
|
300 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
301 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
302 | 302 | $enabled_gateway = wpinv_get_default_gateway(); |
303 | - }else{ |
|
303 | + } else { |
|
304 | 304 | $enabled_gateway = $gateways[0]; |
305 | 305 | } |
306 | 306 | |
307 | 307 | } |
308 | 308 | |
309 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
309 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
310 | 310 | } |
311 | 311 | |
312 | -function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) { |
|
313 | - return wpinv_error_log( $message, $title ); |
|
312 | +function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) { |
|
313 | + return wpinv_error_log($message, $title); |
|
314 | 314 | } |
315 | 315 | |
316 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
316 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
317 | 317 | $ret = 0; |
318 | 318 | $args = array( |
319 | 319 | 'meta_key' => '_wpinv_gateway', |
@@ -324,48 +324,48 @@ discard block |
||
324 | 324 | 'fields' => 'ids' |
325 | 325 | ); |
326 | 326 | |
327 | - $payments = new WP_Query( $args ); |
|
327 | + $payments = new WP_Query($args); |
|
328 | 328 | |
329 | - if( $payments ) |
|
329 | + if ($payments) |
|
330 | 330 | $ret = $payments->post_count; |
331 | 331 | return $ret; |
332 | 332 | } |
333 | 333 | |
334 | -function wpinv_settings_update_gateways( $input ) { |
|
334 | +function wpinv_settings_update_gateways($input) { |
|
335 | 335 | global $wpinv_options; |
336 | 336 | |
337 | - if ( !empty( $input['save_gateway'] ) ) { |
|
338 | - $gateways = wpinv_get_option( 'gateways', false ); |
|
337 | + if (!empty($input['save_gateway'])) { |
|
338 | + $gateways = wpinv_get_option('gateways', false); |
|
339 | 339 | $gateways = !empty($gateways) ? $gateways : array(); |
340 | 340 | $gateway = $input['save_gateway']; |
341 | 341 | |
342 | - if ( !empty( $input[$gateway . '_active'] ) ) { |
|
342 | + if (!empty($input[$gateway . '_active'])) { |
|
343 | 343 | $gateways[$gateway] = 1; |
344 | 344 | } else { |
345 | - if ( isset( $gateways[$gateway] ) ) { |
|
346 | - unset( $gateways[$gateway] ); |
|
345 | + if (isset($gateways[$gateway])) { |
|
346 | + unset($gateways[$gateway]); |
|
347 | 347 | } |
348 | 348 | } |
349 | 349 | |
350 | 350 | $input['gateways'] = $gateways; |
351 | 351 | } |
352 | 352 | |
353 | - if ( !empty( $input['default_gateway'] ) ) { |
|
353 | + if (!empty($input['default_gateway'])) { |
|
354 | 354 | $gateways = wpinv_get_payment_gateways(); |
355 | 355 | |
356 | - foreach ( $gateways as $key => $gateway ) { |
|
357 | - $active = 0; |
|
358 | - if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) { |
|
356 | + foreach ($gateways as $key => $gateway) { |
|
357 | + $active = 0; |
|
358 | + if (!empty($input['gateways']) && !empty($input['gateways'][$key])) { |
|
359 | 359 | $active = 1; |
360 | 360 | } |
361 | 361 | |
362 | 362 | $input[$key . '_active'] = $active; |
363 | 363 | |
364 | - if ( empty( $wpinv_options[$key . '_title'] ) ) { |
|
364 | + if (empty($wpinv_options[$key . '_title'])) { |
|
365 | 365 | $input[$key . '_title'] = $gateway['checkout_label']; |
366 | 366 | } |
367 | 367 | |
368 | - if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) { |
|
368 | + if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) { |
|
369 | 369 | $input[$key . '_ordering'] = $gateway['ordering']; |
370 | 370 | } |
371 | 371 | } |
@@ -373,27 +373,27 @@ discard block |
||
373 | 373 | |
374 | 374 | return $input; |
375 | 375 | } |
376 | -add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 ); |
|
376 | +add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1); |
|
377 | 377 | |
378 | 378 | // PayPal Standard settings |
379 | -function wpinv_gateway_settings_paypal( $setting ) { |
|
380 | - $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' ); |
|
381 | - $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
379 | +function wpinv_gateway_settings_paypal($setting) { |
|
380 | + $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing'); |
|
381 | + $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
382 | 382 | |
383 | 383 | $setting['paypal_sandbox'] = array( |
384 | 384 | 'type' => 'checkbox', |
385 | 385 | 'id' => 'paypal_sandbox', |
386 | - 'name' => __( 'PayPal Sandbox', 'invoicing' ), |
|
387 | - 'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ), |
|
386 | + 'name' => __('PayPal Sandbox', 'invoicing'), |
|
387 | + 'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'), |
|
388 | 388 | 'std' => 1 |
389 | 389 | ); |
390 | 390 | |
391 | 391 | $setting['paypal_email'] = array( |
392 | 392 | 'type' => 'text', |
393 | 393 | 'id' => 'paypal_email', |
394 | - 'name' => __( 'PayPal Email', 'invoicing' ), |
|
395 | - 'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ), |
|
396 | - 'std' => __( '[email protected]', 'invoicing' ), |
|
394 | + 'name' => __('PayPal Email', 'invoicing'), |
|
395 | + 'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'), |
|
396 | + 'std' => __('[email protected]', 'invoicing'), |
|
397 | 397 | ); |
398 | 398 | /* |
399 | 399 | $setting['paypal_ipn_url'] = array( |
@@ -407,18 +407,18 @@ discard block |
||
407 | 407 | |
408 | 408 | return $setting; |
409 | 409 | } |
410 | -add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 ); |
|
410 | +add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1); |
|
411 | 411 | |
412 | 412 | /** |
413 | 413 | * Displays the ipn url field. |
414 | 414 | */ |
415 | -function wpinv_ipn_url_callback( $args ) { |
|
416 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
415 | +function wpinv_ipn_url_callback($args) { |
|
416 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
417 | 417 | |
418 | 418 | $attrs = $args['readonly'] ? ' readonly' : ''; |
419 | 419 | |
420 | - $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">'; |
|
421 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
420 | + $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">'; |
|
421 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
422 | 422 | |
423 | 423 | echo $html; |
424 | 424 | } |
@@ -430,9 +430,9 @@ discard block |
||
430 | 430 | * |
431 | 431 | * @return bool |
432 | 432 | */ |
433 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
434 | - $sandbox = empty( $gateway ) ? false : wpinv_get_option( "{$gateway}_sandbox", false ); |
|
435 | - return apply_filters( 'wpinv_is_test_mode', $sandbox, $gateway ); |
|
433 | +function wpinv_is_test_mode($gateway = '') { |
|
434 | + $sandbox = empty($gateway) ? false : wpinv_get_option("{$gateway}_sandbox", false); |
|
435 | + return apply_filters('wpinv_is_test_mode', $sandbox, $gateway); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | * |
444 | 444 | * @return string |
445 | 445 | */ |
446 | -function wpinv_get_ipn_url( $gateway = false, $args = array() ) { |
|
446 | +function wpinv_get_ipn_url($gateway = false, $args = array()) { |
|
447 | 447 | $args = wp_parse_args( |
448 | 448 | array( |
449 | 449 | 'wpi-listener' => 'IPN', |
@@ -452,24 +452,24 @@ discard block |
||
452 | 452 | $args |
453 | 453 | ); |
454 | 454 | |
455 | - return apply_filters( 'wpinv_ipn_url', add_query_arg( $args, home_url( 'index.php' ) ), $gateway, $args ); |
|
455 | + return apply_filters('wpinv_ipn_url', add_query_arg($args, home_url('index.php')), $gateway, $args); |
|
456 | 456 | |
457 | 457 | } |
458 | 458 | |
459 | -function wpinv_get_post_data( $method = 'request' ) { |
|
459 | +function wpinv_get_post_data($method = 'request') { |
|
460 | 460 | $data = array(); |
461 | 461 | $request = $_REQUEST; |
462 | 462 | |
463 | - if ( $method == 'post' ) { |
|
464 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
463 | + if ($method == 'post') { |
|
464 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
465 | 465 | return $data; |
466 | 466 | } |
467 | 467 | |
468 | 468 | $request = $_POST; |
469 | 469 | } |
470 | 470 | |
471 | - if ( $method == 'get' ) { |
|
472 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) { |
|
471 | + if ($method == 'get') { |
|
472 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') { |
|
473 | 473 | return $data; |
474 | 474 | } |
475 | 475 | |
@@ -480,11 +480,11 @@ discard block |
||
480 | 480 | $post_data = ''; |
481 | 481 | |
482 | 482 | // Fallback just in case post_max_size is lower than needed |
483 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
484 | - $post_data = file_get_contents( 'php://input' ); |
|
483 | + if (ini_get('allow_url_fopen')) { |
|
484 | + $post_data = file_get_contents('php://input'); |
|
485 | 485 | } else { |
486 | 486 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
487 | - ini_set( 'post_max_size', '12M' ); |
|
487 | + ini_set('post_max_size', '12M'); |
|
488 | 488 | } |
489 | 489 | // Start the encoded data collection with notification command |
490 | 490 | $encoded_data = 'cmd=_notify-validate'; |
@@ -493,33 +493,33 @@ discard block |
||
493 | 493 | $arg_separator = wpinv_get_php_arg_separator_output(); |
494 | 494 | |
495 | 495 | // Verify there is a post_data |
496 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
496 | + if ($post_data || strlen($post_data) > 0) { |
|
497 | 497 | // Append the data |
498 | 498 | $encoded_data .= $arg_separator . $post_data; |
499 | 499 | } else { |
500 | 500 | // Check if POST is empty |
501 | - if ( empty( $request ) ) { |
|
501 | + if (empty($request)) { |
|
502 | 502 | // Nothing to do |
503 | 503 | return; |
504 | 504 | } else { |
505 | 505 | // Loop through each POST |
506 | - foreach ( $request as $key => $value ) { |
|
506 | + foreach ($request as $key => $value) { |
|
507 | 507 | // Encode the value and append the data |
508 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
508 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
509 | 509 | } |
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
513 | 513 | // Convert collected post data to an array |
514 | - wp_parse_str( $encoded_data, $data ); |
|
514 | + wp_parse_str($encoded_data, $data); |
|
515 | 515 | |
516 | - foreach ( $data as $key => $value ) { |
|
517 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
518 | - $new_key = str_replace( '&', '&', $key ); |
|
519 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
516 | + foreach ($data as $key => $value) { |
|
517 | + if (false !== strpos($key, 'amp;')) { |
|
518 | + $new_key = str_replace('&', '&', $key); |
|
519 | + $new_key = str_replace('amp;', '&', $new_key); |
|
520 | 520 | |
521 | - unset( $data[ $key ] ); |
|
522 | - $data[ $new_key ] = sanitize_text_field( $value ); |
|
521 | + unset($data[$key]); |
|
522 | + $data[$new_key] = sanitize_text_field($value); |
|
523 | 523 | } |
524 | 524 | } |
525 | 525 | |
@@ -529,12 +529,12 @@ discard block |
||
529 | 529 | /** |
530 | 530 | * Checks if a given gateway supports subscription payments. |
531 | 531 | */ |
532 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
532 | +function wpinv_gateway_support_subscription($gateway) { |
|
533 | 533 | $supports = false; |
534 | 534 | |
535 | - if ( wpinv_is_gateway_active( $gateway ) ) { |
|
536 | - $supports = apply_filters( 'wpinv_' . $gateway . '_support_subscription', $supports ); |
|
537 | - $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $gateway ); |
|
535 | + if (wpinv_is_gateway_active($gateway)) { |
|
536 | + $supports = apply_filters('wpinv_' . $gateway . '_support_subscription', $supports); |
|
537 | + $supports = apply_filters('getapid_gateway_supports_subscription', $supports, $gateway); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | return $supports; |
@@ -546,14 +546,14 @@ discard block |
||
546 | 546 | * @param array $gateways an array of gateways. |
547 | 547 | * @param GetPaid_Payment_Form $form payment form. |
548 | 548 | */ |
549 | -function wpinv_payment_gateways_on_cart( $gateways, $form ) { |
|
549 | +function wpinv_payment_gateways_on_cart($gateways, $form) { |
|
550 | 550 | |
551 | - if ( $form->is_recurring() ) { |
|
551 | + if ($form->is_recurring()) { |
|
552 | 552 | |
553 | - foreach ( array_keys( $gateways ) as $gateway ) { |
|
553 | + foreach (array_keys($gateways) as $gateway) { |
|
554 | 554 | |
555 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
556 | - unset( $gateways[$gateway] ); |
|
555 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
556 | + unset($gateways[$gateway]); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | } |
@@ -562,24 +562,24 @@ discard block |
||
562 | 562 | |
563 | 563 | return $gateways; |
564 | 564 | } |
565 | -add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 ); |
|
565 | +add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2); |
|
566 | 566 | |
567 | 567 | /** |
568 | 568 | * Validates checkout fields. |
569 | 569 | * |
570 | 570 | * @param GetPaid_Payment_Form_Submission $submission |
571 | 571 | */ |
572 | -function wpinv_checkout_validate_gateway( $submission ) { |
|
572 | +function wpinv_checkout_validate_gateway($submission) { |
|
573 | 573 | |
574 | 574 | $data = $submission->get_data(); |
575 | 575 | |
576 | 576 | // Non-recurring gateways should not be allowed to process recurring invoices. |
577 | - if ( $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
578 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment.', 'invoicing' ) ); |
|
577 | + if ($submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
578 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment.', 'invoicing')); |
|
579 | 579 | } |
580 | 580 | |
581 | - if ( ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
582 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
581 | + if (!wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
582 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing')); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | } |
@@ -587,84 +587,84 @@ discard block |
||
587 | 587 | /** |
588 | 588 | * Validates a zip code. |
589 | 589 | */ |
590 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
590 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
591 | 591 | |
592 | - if ( empty( $zip ) || empty( $country_code ) ){ |
|
592 | + if (empty($zip) || empty($country_code)) { |
|
593 | 593 | return false; |
594 | 594 | } |
595 | 595 | |
596 | 596 | // Prepare the country code. |
597 | - $country_code = strtoupper( trim( $country_code ) ); |
|
597 | + $country_code = strtoupper(trim($country_code)); |
|
598 | 598 | |
599 | 599 | // Fetch the regexes. |
600 | - $zip_regex = wpinv_get_data( 'zip-regexes' ); |
|
600 | + $zip_regex = wpinv_get_data('zip-regexes'); |
|
601 | 601 | |
602 | 602 | // Check if it is valid. |
603 | - $is_valid = ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ); |
|
603 | + $is_valid = !isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip); |
|
604 | 604 | |
605 | - return apply_filters( 'wpinv_is_zip_valid', $is_valid, $zip, $country_code ); |
|
605 | + return apply_filters('wpinv_is_zip_valid', $is_valid, $zip, $country_code); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | function wpinv_checkout_validate_agree_to_terms() { |
609 | 609 | // Validate agree to terms |
610 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
610 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
611 | 611 | // User did not agree |
612 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
612 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
616 | 616 | function wpinv_checkout_validate_invoice_user() { |
617 | 617 | global $wpi_cart, $user_ID; |
618 | 618 | |
619 | - if(empty($wpi_cart)){ |
|
619 | + if (empty($wpi_cart)) { |
|
620 | 620 | $wpi_cart = wpinv_get_invoice_cart(); |
621 | 621 | } |
622 | 622 | |
623 | - $invoice_user = (int)$wpi_cart->get_user_id(); |
|
623 | + $invoice_user = (int) $wpi_cart->get_user_id(); |
|
624 | 624 | $valid_user_data = array( |
625 | 625 | 'user_id' => $invoice_user |
626 | 626 | ); |
627 | 627 | |
628 | 628 | // If guest checkout allowed |
629 | - if ( !wpinv_require_login_to_checkout() ) { |
|
629 | + if (!wpinv_require_login_to_checkout()) { |
|
630 | 630 | return $valid_user_data; |
631 | 631 | } |
632 | 632 | |
633 | 633 | // Verify there is a user_ID |
634 | - if ( $user_ID == $invoice_user ) { |
|
634 | + if ($user_ID == $invoice_user) { |
|
635 | 635 | // Get the logged in user data |
636 | - $user_data = get_userdata( $user_ID ); |
|
637 | - $required_fields = wpinv_checkout_required_fields(); |
|
636 | + $user_data = get_userdata($user_ID); |
|
637 | + $required_fields = wpinv_checkout_required_fields(); |
|
638 | 638 | |
639 | 639 | // Loop through required fields and show error messages |
640 | - if ( !empty( $required_fields ) ) { |
|
641 | - foreach ( $required_fields as $field_name => $value ) { |
|
642 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
643 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
640 | + if (!empty($required_fields)) { |
|
641 | + foreach ($required_fields as $field_name => $value) { |
|
642 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
643 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
644 | 644 | } |
645 | 645 | } |
646 | 646 | } |
647 | 647 | |
648 | 648 | // Verify data |
649 | - if ( $user_data ) { |
|
649 | + if ($user_data) { |
|
650 | 650 | // Collected logged in user data |
651 | 651 | $valid_user_data = array( |
652 | 652 | 'user_id' => $user_ID, |
653 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
654 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
655 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
653 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
654 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
655 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
656 | 656 | ); |
657 | 657 | |
658 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
659 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
658 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
659 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
660 | 660 | } |
661 | 661 | } else { |
662 | 662 | // Set invalid user error |
663 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
663 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
664 | 664 | } |
665 | 665 | } else { |
666 | 666 | // Set invalid user error |
667 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
667 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | // Return user data |
@@ -676,18 +676,18 @@ discard block |
||
676 | 676 | |
677 | 677 | $data = array(); |
678 | 678 | |
679 | - if ( is_user_logged_in() ) { |
|
680 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
681 | - $data['user_id'] = (int)get_current_user_id(); |
|
679 | + if (is_user_logged_in()) { |
|
680 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) { |
|
681 | + $data['user_id'] = (int) get_current_user_id(); |
|
682 | 682 | } else { |
683 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
683 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
684 | 684 | } |
685 | 685 | } else { |
686 | 686 | // If guest checkout allowed |
687 | - if ( !wpinv_require_login_to_checkout() ) { |
|
687 | + if (!wpinv_require_login_to_checkout()) { |
|
688 | 688 | $data['user_id'] = 0; |
689 | 689 | } else { |
690 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
690 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
691 | 691 | } |
692 | 692 | } |
693 | 693 | |
@@ -701,41 +701,41 @@ discard block |
||
701 | 701 | * @param WPInv_Invoice $invoice |
702 | 702 | * @param GetPaid_Payment_Form_Submission $submission |
703 | 703 | */ |
704 | -function wpinv_process_checkout( $invoice, $submission ) { |
|
704 | +function wpinv_process_checkout($invoice, $submission) { |
|
705 | 705 | |
706 | 706 | // No need to send free invoices to the gateway. |
707 | - if ( $invoice->is_free() ) { |
|
708 | - $invoice->set_gateway( 'none' ); |
|
709 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
707 | + if ($invoice->is_free()) { |
|
708 | + $invoice->set_gateway('none'); |
|
709 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
710 | 710 | $invoice->mark_paid(); |
711 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
711 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
712 | 712 | } |
713 | 713 | |
714 | 714 | // Clear an checkout errors. |
715 | 715 | wpinv_clear_errors(); |
716 | 716 | |
717 | 717 | // Fires before sending to the gateway. |
718 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
718 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
719 | 719 | |
720 | 720 | // Allow the sumission data to be modified before it is sent to the gateway. |
721 | 721 | $submission_data = $submission->get_data(); |
722 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $submission_data['wpi-gateway'], $submission, $invoice ); |
|
723 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
722 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $submission_data['wpi-gateway'], $submission, $invoice); |
|
723 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
724 | 724 | |
725 | 725 | // Validate the currency. |
726 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
727 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
726 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
727 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing')); |
|
728 | 728 | } |
729 | 729 | |
730 | 730 | // Check to see if we have any errors. |
731 | - if ( wpinv_get_errors() ) { |
|
731 | + if (wpinv_get_errors()) { |
|
732 | 732 | wpinv_send_back_to_checkout(); |
733 | 733 | } |
734 | 734 | |
735 | 735 | // Send info to the gateway for payment processing |
736 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
736 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
737 | 737 | |
738 | 738 | // Backwards compatibility. |
739 | - wpinv_send_to_gateway( $submission_gateway, $invoice->get_payment_meta() ); |
|
739 | + wpinv_send_to_gateway($submission_gateway, $invoice->get_payment_meta()); |
|
740 | 740 | |
741 | 741 | } |