@@ -11,30 +11,30 @@ discard block |
||
11 | 11 | class WPInv_Invoice extends GetPaid_Data { |
12 | 12 | |
13 | 13 | /** |
14 | - * Which data store to load. |
|
15 | - * |
|
16 | - * @var string |
|
17 | - */ |
|
14 | + * Which data store to load. |
|
15 | + * |
|
16 | + * @var string |
|
17 | + */ |
|
18 | 18 | protected $data_store_name = 'invoice'; |
19 | 19 | |
20 | 20 | /** |
21 | - * This is the name of this object type. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
21 | + * This is the name of this object type. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | 25 | protected $object_type = 'invoice'; |
26 | 26 | |
27 | 27 | /** |
28 | - * Item Data array. This is the core item data exposed in APIs. |
|
29 | - * |
|
30 | - * @since 1.0.19 |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $data = array( |
|
34 | - 'parent_id' => 0, |
|
35 | - 'status' => 'wpi-pending', |
|
36 | - 'version' => '', |
|
37 | - 'date_created' => null, |
|
28 | + * Item Data array. This is the core item data exposed in APIs. |
|
29 | + * |
|
30 | + * @since 1.0.19 |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $data = array( |
|
34 | + 'parent_id' => 0, |
|
35 | + 'status' => 'wpi-pending', |
|
36 | + 'version' => '', |
|
37 | + 'date_created' => null, |
|
38 | 38 | 'date_modified' => null, |
39 | 39 | 'due_date' => null, |
40 | 40 | 'completed_date' => null, |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | 'transaction_id' => '', |
77 | 77 | 'currency' => '', |
78 | 78 | 'disable_taxes' => false, |
79 | - 'subscription_id' => null, |
|
80 | - 'is_viewed' => false, |
|
81 | - 'email_cc' => '', |
|
82 | - 'template' => 'quantity', // hours, amount only |
|
79 | + 'subscription_id' => null, |
|
80 | + 'is_viewed' => false, |
|
81 | + 'email_cc' => '', |
|
82 | + 'template' => 'quantity', // hours, amount only |
|
83 | 83 | ); |
84 | 84 | |
85 | 85 | /** |
86 | - * Stores meta in cache for future reads. |
|
87 | - * |
|
88 | - * A group must be set to to enable caching. |
|
89 | - * |
|
90 | - * @var string |
|
91 | - */ |
|
92 | - protected $cache_group = 'getpaid_invoices'; |
|
86 | + * Stores meta in cache for future reads. |
|
87 | + * |
|
88 | + * A group must be set to to enable caching. |
|
89 | + * |
|
90 | + * @var string |
|
91 | + */ |
|
92 | + protected $cache_group = 'getpaid_invoices'; |
|
93 | 93 | |
94 | 94 | /** |
95 | 95 | * Stores a reference to the original WP_Post object |
@@ -103,97 +103,97 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @var int |
105 | 105 | */ |
106 | - protected $recurring_item = null; |
|
106 | + protected $recurring_item = null; |
|
107 | 107 | |
108 | - /** |
|
108 | + /** |
|
109 | 109 | * Stores an array of item totals. |
110 | - * |
|
111 | - * e.g $totals['discount'] = array( |
|
112 | - * 'initial' => 10, |
|
113 | - * 'recurring' => 10, |
|
114 | - * ) |
|
110 | + * |
|
111 | + * e.g $totals['discount'] = array( |
|
112 | + * 'initial' => 10, |
|
113 | + * 'recurring' => 10, |
|
114 | + * ) |
|
115 | 115 | * |
116 | 116 | * @var array |
117 | 117 | */ |
118 | - protected $totals = array(); |
|
118 | + protected $totals = array(); |
|
119 | 119 | |
120 | - /** |
|
121 | - * Stores the status transition information. |
|
122 | - * |
|
123 | - * @since 1.0.19 |
|
124 | - * @var bool |
|
125 | - */ |
|
126 | - protected $status_transition = false; |
|
120 | + /** |
|
121 | + * Stores the status transition information. |
|
122 | + * |
|
123 | + * @since 1.0.19 |
|
124 | + * @var bool |
|
125 | + */ |
|
126 | + protected $status_transition = false; |
|
127 | 127 | |
128 | 128 | /** |
129 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
130 | - * |
|
131 | - * @param int/string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, number or object to read. |
|
132 | - */ |
|
129 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
130 | + * |
|
131 | + * @param int/string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, number or object to read. |
|
132 | + */ |
|
133 | 133 | public function __construct( $invoice = false ) { |
134 | 134 | |
135 | 135 | parent::__construct( $invoice ); |
136 | 136 | |
137 | - if ( is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
138 | - $this->set_id( $invoice ); |
|
139 | - } elseif ( $invoice instanceof self ) { |
|
140 | - $this->set_id( $invoice->get_id() ); |
|
141 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
142 | - $this->set_id( $invoice->ID ); |
|
143 | - } elseif ( is_array( $invoice ) ) { |
|
144 | - $this->set_props( $invoice ); |
|
145 | - |
|
146 | - if ( isset( $invoice['ID'] ) ) { |
|
147 | - $this->set_id( $invoice['ID'] ); |
|
148 | - } |
|
149 | - |
|
150 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'key' ) ) { |
|
151 | - $this->set_id( $invoice_id ); |
|
152 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'number' ) ) { |
|
153 | - $this->set_id( $invoice_id ); |
|
154 | - } else { |
|
155 | - $this->set_object_read( true ); |
|
156 | - } |
|
137 | + if ( is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
138 | + $this->set_id( $invoice ); |
|
139 | + } elseif ( $invoice instanceof self ) { |
|
140 | + $this->set_id( $invoice->get_id() ); |
|
141 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
142 | + $this->set_id( $invoice->ID ); |
|
143 | + } elseif ( is_array( $invoice ) ) { |
|
144 | + $this->set_props( $invoice ); |
|
145 | + |
|
146 | + if ( isset( $invoice['ID'] ) ) { |
|
147 | + $this->set_id( $invoice['ID'] ); |
|
148 | + } |
|
149 | + |
|
150 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'key' ) ) { |
|
151 | + $this->set_id( $invoice_id ); |
|
152 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'number' ) ) { |
|
153 | + $this->set_id( $invoice_id ); |
|
154 | + } else { |
|
155 | + $this->set_object_read( true ); |
|
156 | + } |
|
157 | 157 | |
158 | 158 | // Load the datastore. |
159 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
159 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
160 | 160 | |
161 | - if ( $this->get_id() > 0 ) { |
|
161 | + if ( $this->get_id() > 0 ) { |
|
162 | 162 | $this->post = get_post( $this->get_id() ); |
163 | 163 | $this->ID = $this->get_id(); |
164 | - $this->data_store->read( $this ); |
|
164 | + $this->data_store->read( $this ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | - * Given a discount code, it returns a discount id. |
|
171 | - * |
|
172 | - * |
|
173 | - * @static |
|
174 | - * @param string $discount_code |
|
175 | - * @since 1.0.15 |
|
176 | - * @return int |
|
177 | - */ |
|
178 | - public static function get_discount_id_by_code( $invoice_key_or_number, $field = 'key' ) { |
|
170 | + * Given a discount code, it returns a discount id. |
|
171 | + * |
|
172 | + * |
|
173 | + * @static |
|
174 | + * @param string $discount_code |
|
175 | + * @since 1.0.15 |
|
176 | + * @return int |
|
177 | + */ |
|
178 | + public static function get_discount_id_by_code( $invoice_key_or_number, $field = 'key' ) { |
|
179 | 179 | global $wpdb; |
180 | 180 | |
181 | - // Trim the code. |
|
181 | + // Trim the code. |
|
182 | 182 | $key = trim( $invoice_key_or_number ); |
183 | 183 | |
184 | 184 | // Valid fields. |
185 | 185 | $fields = array( 'key', 'number' ); |
186 | 186 | |
187 | - // Ensure a value has been passed. |
|
188 | - if ( empty( $key ) || ! in_array( $field, $fields ) ) { |
|
189 | - return 0; |
|
190 | - } |
|
187 | + // Ensure a value has been passed. |
|
188 | + if ( empty( $key ) || ! in_array( $field, $fields ) ) { |
|
189 | + return 0; |
|
190 | + } |
|
191 | 191 | |
192 | - // Maybe retrieve from the cache. |
|
193 | - $invoice_id = wp_cache_get( $key, 'getpaid_invoice_keys_' . $field ); |
|
194 | - if ( ! empty( $invoice_id ) ) { |
|
195 | - return $invoice_id; |
|
196 | - } |
|
192 | + // Maybe retrieve from the cache. |
|
193 | + $invoice_id = wp_cache_get( $key, 'getpaid_invoice_keys_' . $field ); |
|
194 | + if ( ! empty( $invoice_id ) ) { |
|
195 | + return $invoice_id; |
|
196 | + } |
|
197 | 197 | |
198 | 198 | // Fetch from the db. |
199 | 199 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -201,14 +201,14 @@ discard block |
||
201 | 201 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE $field=%s LIMIT 1", $key ) |
202 | 202 | ); |
203 | 203 | |
204 | - if ( empty( $invoice_id ) ) { |
|
205 | - return 0; |
|
206 | - } |
|
204 | + if ( empty( $invoice_id ) ) { |
|
205 | + return 0; |
|
206 | + } |
|
207 | 207 | |
208 | - // Update the cache with our data |
|
209 | - wp_cache_set( $key, $invoice_id, 'getpaid_invoice_keys_' . $field ); |
|
208 | + // Update the cache with our data |
|
209 | + wp_cache_set( $key, $invoice_id, 'getpaid_invoice_keys_' . $field ); |
|
210 | 210 | |
211 | - return $invoice_id; |
|
211 | + return $invoice_id; |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -234,53 +234,53 @@ discard block |
||
234 | 234 | */ |
235 | 235 | |
236 | 236 | /** |
237 | - * Get parent invoice ID. |
|
238 | - * |
|
239 | - * @since 1.0.19 |
|
240 | - * @param string $context View or edit context. |
|
241 | - * @return int |
|
242 | - */ |
|
243 | - public function get_parent_id( $context = 'view' ) { |
|
244 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
237 | + * Get parent invoice ID. |
|
238 | + * |
|
239 | + * @since 1.0.19 |
|
240 | + * @param string $context View or edit context. |
|
241 | + * @return int |
|
242 | + */ |
|
243 | + public function get_parent_id( $context = 'view' ) { |
|
244 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
248 | - * Get parent invoice. |
|
249 | - * |
|
250 | - * @since 1.0.19 |
|
251 | - * @return WPInv_Invoice |
|
252 | - */ |
|
248 | + * Get parent invoice. |
|
249 | + * |
|
250 | + * @since 1.0.19 |
|
251 | + * @return WPInv_Invoice |
|
252 | + */ |
|
253 | 253 | public function get_parent_payment() { |
254 | 254 | return new WPInv_Invoice( $this->get_parent_id() ); |
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
258 | - * Alias for self::get_parent_payment(). |
|
259 | - * |
|
260 | - * @since 1.0.19 |
|
261 | - * @return WPInv_Invoice |
|
262 | - */ |
|
258 | + * Alias for self::get_parent_payment(). |
|
259 | + * |
|
260 | + * @since 1.0.19 |
|
261 | + * @return WPInv_Invoice |
|
262 | + */ |
|
263 | 263 | public function get_parent() { |
264 | 264 | return $this->get_parent_payment(); |
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
268 | - * Get invoice status. |
|
269 | - * |
|
270 | - * @since 1.0.19 |
|
271 | - * @param string $context View or edit context. |
|
272 | - * @return string |
|
273 | - */ |
|
274 | - public function get_status( $context = 'view' ) { |
|
275 | - return $this->get_prop( 'status', $context ); |
|
268 | + * Get invoice status. |
|
269 | + * |
|
270 | + * @since 1.0.19 |
|
271 | + * @param string $context View or edit context. |
|
272 | + * @return string |
|
273 | + */ |
|
274 | + public function get_status( $context = 'view' ) { |
|
275 | + return $this->get_prop( 'status', $context ); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
279 | - * Get invoice status nice name. |
|
280 | - * |
|
281 | - * @since 1.0.19 |
|
282 | - * @return string |
|
283 | - */ |
|
279 | + * Get invoice status nice name. |
|
280 | + * |
|
281 | + * @since 1.0.19 |
|
282 | + * @return string |
|
283 | + */ |
|
284 | 284 | public function get_status_nicename() { |
285 | 285 | $statuses = wpinv_get_invoice_statuses( true, true, $this ); |
286 | 286 | |
@@ -294,20 +294,20 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Get plugin version when the invoice was created. |
|
298 | - * |
|
299 | - * @since 1.0.19 |
|
300 | - * @param string $context View or edit context. |
|
301 | - * @return string |
|
302 | - */ |
|
303 | - public function get_version( $context = 'view' ) { |
|
304 | - return $this->get_prop( 'version', $context ); |
|
305 | - } |
|
297 | + * Get plugin version when the invoice was created. |
|
298 | + * |
|
299 | + * @since 1.0.19 |
|
300 | + * @param string $context View or edit context. |
|
301 | + * @return string |
|
302 | + */ |
|
303 | + public function get_version( $context = 'view' ) { |
|
304 | + return $this->get_prop( 'version', $context ); |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * @deprecated |
|
309 | - */ |
|
310 | - public function get_invoice_date( $formatted = true ) { |
|
307 | + /** |
|
308 | + * @deprecated |
|
309 | + */ |
|
310 | + public function get_invoice_date( $formatted = true ) { |
|
311 | 311 | $date_completed = $this->get_date_completed(); |
312 | 312 | $invoice_date = $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
313 | 313 | |
@@ -324,187 +324,187 @@ discard block |
||
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
327 | - * Get date when the invoice was created. |
|
328 | - * |
|
329 | - * @since 1.0.19 |
|
330 | - * @param string $context View or edit context. |
|
331 | - * @return string |
|
332 | - */ |
|
333 | - public function get_date_created( $context = 'view' ) { |
|
334 | - return $this->get_prop( 'date_created', $context ); |
|
335 | - } |
|
327 | + * Get date when the invoice was created. |
|
328 | + * |
|
329 | + * @since 1.0.19 |
|
330 | + * @param string $context View or edit context. |
|
331 | + * @return string |
|
332 | + */ |
|
333 | + public function get_date_created( $context = 'view' ) { |
|
334 | + return $this->get_prop( 'date_created', $context ); |
|
335 | + } |
|
336 | 336 | |
337 | - /** |
|
338 | - * Alias for self::get_date_created(). |
|
339 | - * |
|
340 | - * @since 1.0.19 |
|
341 | - * @param string $context View or edit context. |
|
342 | - * @return string |
|
343 | - */ |
|
344 | - public function get_created_date( $context = 'view' ) { |
|
345 | - return $this->get_date_created( $context ); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Get GMT date when the invoice was created. |
|
350 | - * |
|
351 | - * @since 1.0.19 |
|
352 | - * @param string $context View or edit context. |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - public function get_date_created_gmt( $context = 'view' ) { |
|
337 | + /** |
|
338 | + * Alias for self::get_date_created(). |
|
339 | + * |
|
340 | + * @since 1.0.19 |
|
341 | + * @param string $context View or edit context. |
|
342 | + * @return string |
|
343 | + */ |
|
344 | + public function get_created_date( $context = 'view' ) { |
|
345 | + return $this->get_date_created( $context ); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Get GMT date when the invoice was created. |
|
350 | + * |
|
351 | + * @since 1.0.19 |
|
352 | + * @param string $context View or edit context. |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + public function get_date_created_gmt( $context = 'view' ) { |
|
356 | 356 | $date = $this->get_date_created( $context ); |
357 | 357 | |
358 | 358 | if ( $date ) { |
359 | 359 | $date = get_gmt_from_date( $date ); |
360 | 360 | } |
361 | - return $date; |
|
361 | + return $date; |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
365 | - * Get date when the invoice was last modified. |
|
366 | - * |
|
367 | - * @since 1.0.19 |
|
368 | - * @param string $context View or edit context. |
|
369 | - * @return string |
|
370 | - */ |
|
371 | - public function get_date_modified( $context = 'view' ) { |
|
372 | - return $this->get_prop( 'date_modified', $context ); |
|
373 | - } |
|
365 | + * Get date when the invoice was last modified. |
|
366 | + * |
|
367 | + * @since 1.0.19 |
|
368 | + * @param string $context View or edit context. |
|
369 | + * @return string |
|
370 | + */ |
|
371 | + public function get_date_modified( $context = 'view' ) { |
|
372 | + return $this->get_prop( 'date_modified', $context ); |
|
373 | + } |
|
374 | 374 | |
375 | - /** |
|
376 | - * Alias for self::get_date_modified(). |
|
377 | - * |
|
378 | - * @since 1.0.19 |
|
379 | - * @param string $context View or edit context. |
|
380 | - * @return string |
|
381 | - */ |
|
382 | - public function get_modified_date( $context = 'view' ) { |
|
383 | - return $this->get_date_modified( $context ); |
|
375 | + /** |
|
376 | + * Alias for self::get_date_modified(). |
|
377 | + * |
|
378 | + * @since 1.0.19 |
|
379 | + * @param string $context View or edit context. |
|
380 | + * @return string |
|
381 | + */ |
|
382 | + public function get_modified_date( $context = 'view' ) { |
|
383 | + return $this->get_date_modified( $context ); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
387 | - * Get GMT date when the invoice was last modified. |
|
388 | - * |
|
389 | - * @since 1.0.19 |
|
390 | - * @param string $context View or edit context. |
|
391 | - * @return string |
|
392 | - */ |
|
393 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
387 | + * Get GMT date when the invoice was last modified. |
|
388 | + * |
|
389 | + * @since 1.0.19 |
|
390 | + * @param string $context View or edit context. |
|
391 | + * @return string |
|
392 | + */ |
|
393 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
394 | 394 | $date = $this->get_date_modified( $context ); |
395 | 395 | |
396 | 396 | if ( $date ) { |
397 | 397 | $date = get_gmt_from_date( $date ); |
398 | 398 | } |
399 | - return $date; |
|
399 | + return $date; |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
403 | - * Get the invoice due date. |
|
404 | - * |
|
405 | - * @since 1.0.19 |
|
406 | - * @param string $context View or edit context. |
|
407 | - * @return string |
|
408 | - */ |
|
409 | - public function get_due_date( $context = 'view' ) { |
|
410 | - return $this->get_prop( 'due_date', $context ); |
|
403 | + * Get the invoice due date. |
|
404 | + * |
|
405 | + * @since 1.0.19 |
|
406 | + * @param string $context View or edit context. |
|
407 | + * @return string |
|
408 | + */ |
|
409 | + public function get_due_date( $context = 'view' ) { |
|
410 | + return $this->get_prop( 'due_date', $context ); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | /** |
414 | - * Alias for self::get_due_date(). |
|
415 | - * |
|
416 | - * @since 1.0.19 |
|
417 | - * @param string $context View or edit context. |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - public function get_date_due( $context = 'view' ) { |
|
421 | - return $this->get_due_date( $context ); |
|
414 | + * Alias for self::get_due_date(). |
|
415 | + * |
|
416 | + * @since 1.0.19 |
|
417 | + * @param string $context View or edit context. |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + public function get_date_due( $context = 'view' ) { |
|
421 | + return $this->get_due_date( $context ); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | /** |
425 | - * Get the invoice GMT due date. |
|
426 | - * |
|
427 | - * @since 1.0.19 |
|
428 | - * @param string $context View or edit context. |
|
429 | - * @return string |
|
430 | - */ |
|
431 | - public function get_due_date_gmt( $context = 'view' ) { |
|
425 | + * Get the invoice GMT due date. |
|
426 | + * |
|
427 | + * @since 1.0.19 |
|
428 | + * @param string $context View or edit context. |
|
429 | + * @return string |
|
430 | + */ |
|
431 | + public function get_due_date_gmt( $context = 'view' ) { |
|
432 | 432 | $date = $this->get_due_date( $context ); |
433 | 433 | |
434 | 434 | if ( $date ) { |
435 | 435 | $date = get_gmt_from_date( $date ); |
436 | 436 | } |
437 | - return $date; |
|
437 | + return $date; |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
441 | - * Alias for self::get_due_date_gmt(). |
|
442 | - * |
|
443 | - * @since 1.0.19 |
|
444 | - * @param string $context View or edit context. |
|
445 | - * @return string |
|
446 | - */ |
|
447 | - public function get_gmt_date_due( $context = 'view' ) { |
|
448 | - return $this->get_due_date_gmt( $context ); |
|
441 | + * Alias for self::get_due_date_gmt(). |
|
442 | + * |
|
443 | + * @since 1.0.19 |
|
444 | + * @param string $context View or edit context. |
|
445 | + * @return string |
|
446 | + */ |
|
447 | + public function get_gmt_date_due( $context = 'view' ) { |
|
448 | + return $this->get_due_date_gmt( $context ); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
452 | - * Get date when the invoice was completed. |
|
453 | - * |
|
454 | - * @since 1.0.19 |
|
455 | - * @param string $context View or edit context. |
|
456 | - * @return string |
|
457 | - */ |
|
458 | - public function get_completed_date( $context = 'view' ) { |
|
459 | - return $this->get_prop( 'completed_date', $context ); |
|
452 | + * Get date when the invoice was completed. |
|
453 | + * |
|
454 | + * @since 1.0.19 |
|
455 | + * @param string $context View or edit context. |
|
456 | + * @return string |
|
457 | + */ |
|
458 | + public function get_completed_date( $context = 'view' ) { |
|
459 | + return $this->get_prop( 'completed_date', $context ); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | /** |
463 | - * Alias for self::get_completed_date(). |
|
464 | - * |
|
465 | - * @since 1.0.19 |
|
466 | - * @param string $context View or edit context. |
|
467 | - * @return string |
|
468 | - */ |
|
469 | - public function get_date_completed( $context = 'view' ) { |
|
470 | - return $this->get_completed_date( $context ); |
|
463 | + * Alias for self::get_completed_date(). |
|
464 | + * |
|
465 | + * @since 1.0.19 |
|
466 | + * @param string $context View or edit context. |
|
467 | + * @return string |
|
468 | + */ |
|
469 | + public function get_date_completed( $context = 'view' ) { |
|
470 | + return $this->get_completed_date( $context ); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | /** |
474 | - * Get GMT date when the invoice was was completed. |
|
475 | - * |
|
476 | - * @since 1.0.19 |
|
477 | - * @param string $context View or edit context. |
|
478 | - * @return string |
|
479 | - */ |
|
480 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
474 | + * Get GMT date when the invoice was was completed. |
|
475 | + * |
|
476 | + * @since 1.0.19 |
|
477 | + * @param string $context View or edit context. |
|
478 | + * @return string |
|
479 | + */ |
|
480 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
481 | 481 | $date = $this->get_completed_date( $context ); |
482 | 482 | |
483 | 483 | if ( $date ) { |
484 | 484 | $date = get_gmt_from_date( $date ); |
485 | 485 | } |
486 | - return $date; |
|
486 | + return $date; |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
490 | - * Alias for self::get_completed_date_gmt(). |
|
491 | - * |
|
492 | - * @since 1.0.19 |
|
493 | - * @param string $context View or edit context. |
|
494 | - * @return string |
|
495 | - */ |
|
496 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
497 | - return $this->get_completed_date_gmt( $context ); |
|
490 | + * Alias for self::get_completed_date_gmt(). |
|
491 | + * |
|
492 | + * @since 1.0.19 |
|
493 | + * @param string $context View or edit context. |
|
494 | + * @return string |
|
495 | + */ |
|
496 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
497 | + return $this->get_completed_date_gmt( $context ); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /** |
501 | - * Get the invoice number. |
|
502 | - * |
|
503 | - * @since 1.0.19 |
|
504 | - * @param string $context View or edit context. |
|
505 | - * @return string |
|
506 | - */ |
|
507 | - public function get_number( $context = 'view' ) { |
|
501 | + * Get the invoice number. |
|
502 | + * |
|
503 | + * @since 1.0.19 |
|
504 | + * @param string $context View or edit context. |
|
505 | + * @return string |
|
506 | + */ |
|
507 | + public function get_number( $context = 'view' ) { |
|
508 | 508 | $number = $this->get_prop( 'number', $context ); |
509 | 509 | |
510 | 510 | if ( empty( $number ) ) { |
@@ -512,17 +512,17 @@ discard block |
||
512 | 512 | $this->set_number( $number ); |
513 | 513 | } |
514 | 514 | |
515 | - return $number; |
|
515 | + return $number; |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
519 | - * Get the invoice key. |
|
520 | - * |
|
521 | - * @since 1.0.19 |
|
522 | - * @param string $context View or edit context. |
|
523 | - * @return string |
|
524 | - */ |
|
525 | - public function get_key( $context = 'view' ) { |
|
519 | + * Get the invoice key. |
|
520 | + * |
|
521 | + * @since 1.0.19 |
|
522 | + * @param string $context View or edit context. |
|
523 | + * @return string |
|
524 | + */ |
|
525 | + public function get_key( $context = 'view' ) { |
|
526 | 526 | $key = $this->get_prop( 'key', $context ); |
527 | 527 | |
528 | 528 | if ( empty( $key ) ) { |
@@ -530,24 +530,24 @@ discard block |
||
530 | 530 | $this->set_key( $key ); |
531 | 531 | } |
532 | 532 | |
533 | - return $key; |
|
533 | + return $key; |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
537 | - * Get the invoice type. |
|
538 | - * |
|
539 | - * @since 1.0.19 |
|
540 | - * @param string $context View or edit context. |
|
541 | - * @return string |
|
542 | - */ |
|
543 | - public function get_type( $context = 'view' ) { |
|
537 | + * Get the invoice type. |
|
538 | + * |
|
539 | + * @since 1.0.19 |
|
540 | + * @param string $context View or edit context. |
|
541 | + * @return string |
|
542 | + */ |
|
543 | + public function get_type( $context = 'view' ) { |
|
544 | 544 | return $this->get_prop( 'type', $context ); |
545 | - } |
|
545 | + } |
|
546 | 546 | |
547 | - /** |
|
548 | - * @deprecated |
|
549 | - */ |
|
550 | - public function get_invoice_quote_type( $post_id ) { |
|
547 | + /** |
|
548 | + * @deprecated |
|
549 | + */ |
|
550 | + public function get_invoice_quote_type( $post_id ) { |
|
551 | 551 | if ( empty( $post_id ) ) { |
552 | 552 | return ''; |
553 | 553 | } |
@@ -564,35 +564,35 @@ discard block |
||
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
567 | - * Get the invoice post type. |
|
568 | - * |
|
569 | - * @since 1.0.19 |
|
570 | - * @param string $context View or edit context. |
|
571 | - * @return string |
|
572 | - */ |
|
573 | - public function get_post_type( $context = 'view' ) { |
|
567 | + * Get the invoice post type. |
|
568 | + * |
|
569 | + * @since 1.0.19 |
|
570 | + * @param string $context View or edit context. |
|
571 | + * @return string |
|
572 | + */ |
|
573 | + public function get_post_type( $context = 'view' ) { |
|
574 | 574 | return $this->get_prop( 'post_type', $context ); |
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
578 | - * Get the invoice mode. |
|
579 | - * |
|
580 | - * @since 1.0.19 |
|
581 | - * @param string $context View or edit context. |
|
582 | - * @return string |
|
583 | - */ |
|
584 | - public function get_mode( $context = 'view' ) { |
|
578 | + * Get the invoice mode. |
|
579 | + * |
|
580 | + * @since 1.0.19 |
|
581 | + * @param string $context View or edit context. |
|
582 | + * @return string |
|
583 | + */ |
|
584 | + public function get_mode( $context = 'view' ) { |
|
585 | 585 | return $this->get_prop( 'mode', $context ); |
586 | 586 | } |
587 | 587 | |
588 | 588 | /** |
589 | - * Get the invoice path. |
|
590 | - * |
|
591 | - * @since 1.0.19 |
|
592 | - * @param string $context View or edit context. |
|
593 | - * @return string |
|
594 | - */ |
|
595 | - public function get_path( $context = 'view' ) { |
|
589 | + * Get the invoice path. |
|
590 | + * |
|
591 | + * @since 1.0.19 |
|
592 | + * @param string $context View or edit context. |
|
593 | + * @return string |
|
594 | + */ |
|
595 | + public function get_path( $context = 'view' ) { |
|
596 | 596 | $path = $this->get_prop( 'path', $context ); |
597 | 597 | |
598 | 598 | if ( empty( $path ) ) { |
@@ -600,73 +600,73 @@ discard block |
||
600 | 600 | $path = sanitize_title( $prefix . $this->get_id() ); |
601 | 601 | } |
602 | 602 | |
603 | - return $path; |
|
603 | + return $path; |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | /** |
607 | - * Get the invoice name/title. |
|
608 | - * |
|
609 | - * @since 1.0.19 |
|
610 | - * @param string $context View or edit context. |
|
611 | - * @return string |
|
612 | - */ |
|
613 | - public function get_name( $context = 'view' ) { |
|
607 | + * Get the invoice name/title. |
|
608 | + * |
|
609 | + * @since 1.0.19 |
|
610 | + * @param string $context View or edit context. |
|
611 | + * @return string |
|
612 | + */ |
|
613 | + public function get_name( $context = 'view' ) { |
|
614 | 614 | $name = $this->get_prop( 'title', $context ); |
615 | 615 | |
616 | - return empty( $name ) ? $this->get_number( $context ) : $name; |
|
616 | + return empty( $name ) ? $this->get_number( $context ) : $name; |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
620 | - * Alias of self::get_name(). |
|
621 | - * |
|
622 | - * @since 1.0.19 |
|
623 | - * @param string $context View or edit context. |
|
624 | - * @return string |
|
625 | - */ |
|
626 | - public function get_title( $context = 'view' ) { |
|
627 | - return $this->get_name( $context ); |
|
620 | + * Alias of self::get_name(). |
|
621 | + * |
|
622 | + * @since 1.0.19 |
|
623 | + * @param string $context View or edit context. |
|
624 | + * @return string |
|
625 | + */ |
|
626 | + public function get_title( $context = 'view' ) { |
|
627 | + return $this->get_name( $context ); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
631 | - * Get the invoice description. |
|
632 | - * |
|
633 | - * @since 1.0.19 |
|
634 | - * @param string $context View or edit context. |
|
635 | - * @return string |
|
636 | - */ |
|
637 | - public function get_description( $context = 'view' ) { |
|
638 | - return $this->get_prop( 'description', $context ); |
|
631 | + * Get the invoice description. |
|
632 | + * |
|
633 | + * @since 1.0.19 |
|
634 | + * @param string $context View or edit context. |
|
635 | + * @return string |
|
636 | + */ |
|
637 | + public function get_description( $context = 'view' ) { |
|
638 | + return $this->get_prop( 'description', $context ); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | /** |
642 | - * Alias of self::get_description(). |
|
643 | - * |
|
644 | - * @since 1.0.19 |
|
645 | - * @param string $context View or edit context. |
|
646 | - * @return string |
|
647 | - */ |
|
648 | - public function get_excerpt( $context = 'view' ) { |
|
649 | - return $this->get_description( $context ); |
|
642 | + * Alias of self::get_description(). |
|
643 | + * |
|
644 | + * @since 1.0.19 |
|
645 | + * @param string $context View or edit context. |
|
646 | + * @return string |
|
647 | + */ |
|
648 | + public function get_excerpt( $context = 'view' ) { |
|
649 | + return $this->get_description( $context ); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | /** |
653 | - * Alias of self::get_description(). |
|
654 | - * |
|
655 | - * @since 1.0.19 |
|
656 | - * @param string $context View or edit context. |
|
657 | - * @return string |
|
658 | - */ |
|
659 | - public function get_summary( $context = 'view' ) { |
|
660 | - return $this->get_description( $context ); |
|
653 | + * Alias of self::get_description(). |
|
654 | + * |
|
655 | + * @since 1.0.19 |
|
656 | + * @param string $context View or edit context. |
|
657 | + * @return string |
|
658 | + */ |
|
659 | + public function get_summary( $context = 'view' ) { |
|
660 | + return $this->get_description( $context ); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
664 | - * Returns the user info. |
|
665 | - * |
|
666 | - * @since 1.0.19 |
|
664 | + * Returns the user info. |
|
665 | + * |
|
666 | + * @since 1.0.19 |
|
667 | 667 | * @param string $context View or edit context. |
668 | - * @return array |
|
669 | - */ |
|
668 | + * @return array |
|
669 | + */ |
|
670 | 670 | public function get_user_info( $context = 'view' ) { |
671 | 671 | $user_info = array( |
672 | 672 | 'user_id' => $this->get_user_id( $context ), |
@@ -687,598 +687,598 @@ discard block |
||
687 | 687 | } |
688 | 688 | |
689 | 689 | /** |
690 | - * Get the customer id. |
|
691 | - * |
|
692 | - * @since 1.0.19 |
|
693 | - * @param string $context View or edit context. |
|
694 | - * @return int |
|
695 | - */ |
|
696 | - public function get_author( $context = 'view' ) { |
|
697 | - return (int) $this->get_prop( 'author', $context ); |
|
690 | + * Get the customer id. |
|
691 | + * |
|
692 | + * @since 1.0.19 |
|
693 | + * @param string $context View or edit context. |
|
694 | + * @return int |
|
695 | + */ |
|
696 | + public function get_author( $context = 'view' ) { |
|
697 | + return (int) $this->get_prop( 'author', $context ); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
701 | - * Alias of self::get_author(). |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - * @param string $context View or edit context. |
|
705 | - * @return int |
|
706 | - */ |
|
707 | - public function get_user_id( $context = 'view' ) { |
|
708 | - return $this->get_author( $context ); |
|
701 | + * Alias of self::get_author(). |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + * @param string $context View or edit context. |
|
705 | + * @return int |
|
706 | + */ |
|
707 | + public function get_user_id( $context = 'view' ) { |
|
708 | + return $this->get_author( $context ); |
|
709 | 709 | } |
710 | 710 | |
711 | - /** |
|
712 | - * Alias of self::get_author(). |
|
713 | - * |
|
714 | - * @since 1.0.19 |
|
715 | - * @param string $context View or edit context. |
|
716 | - * @return int |
|
717 | - */ |
|
718 | - public function get_customer_id( $context = 'view' ) { |
|
719 | - return $this->get_author( $context ); |
|
711 | + /** |
|
712 | + * Alias of self::get_author(). |
|
713 | + * |
|
714 | + * @since 1.0.19 |
|
715 | + * @param string $context View or edit context. |
|
716 | + * @return int |
|
717 | + */ |
|
718 | + public function get_customer_id( $context = 'view' ) { |
|
719 | + return $this->get_author( $context ); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | /** |
723 | - * Get the customer's ip. |
|
724 | - * |
|
725 | - * @since 1.0.19 |
|
726 | - * @param string $context View or edit context. |
|
727 | - * @return string |
|
728 | - */ |
|
729 | - public function get_ip( $context = 'view' ) { |
|
730 | - return $this->get_prop( 'user_ip', $context ); |
|
723 | + * Get the customer's ip. |
|
724 | + * |
|
725 | + * @since 1.0.19 |
|
726 | + * @param string $context View or edit context. |
|
727 | + * @return string |
|
728 | + */ |
|
729 | + public function get_ip( $context = 'view' ) { |
|
730 | + return $this->get_prop( 'user_ip', $context ); |
|
731 | 731 | } |
732 | 732 | |
733 | 733 | /** |
734 | - * Alias of self::get_ip(). |
|
735 | - * |
|
736 | - * @since 1.0.19 |
|
737 | - * @param string $context View or edit context. |
|
738 | - * @return string |
|
739 | - */ |
|
740 | - public function get_user_ip( $context = 'view' ) { |
|
741 | - return $this->get_ip( $context ); |
|
734 | + * Alias of self::get_ip(). |
|
735 | + * |
|
736 | + * @since 1.0.19 |
|
737 | + * @param string $context View or edit context. |
|
738 | + * @return string |
|
739 | + */ |
|
740 | + public function get_user_ip( $context = 'view' ) { |
|
741 | + return $this->get_ip( $context ); |
|
742 | 742 | } |
743 | 743 | |
744 | - /** |
|
745 | - * Alias of self::get_ip(). |
|
746 | - * |
|
747 | - * @since 1.0.19 |
|
748 | - * @param string $context View or edit context. |
|
749 | - * @return string |
|
750 | - */ |
|
751 | - public function get_customer_ip( $context = 'view' ) { |
|
752 | - return $this->get_ip( $context ); |
|
744 | + /** |
|
745 | + * Alias of self::get_ip(). |
|
746 | + * |
|
747 | + * @since 1.0.19 |
|
748 | + * @param string $context View or edit context. |
|
749 | + * @return string |
|
750 | + */ |
|
751 | + public function get_customer_ip( $context = 'view' ) { |
|
752 | + return $this->get_ip( $context ); |
|
753 | 753 | } |
754 | 754 | |
755 | 755 | /** |
756 | - * Get the customer's first name. |
|
757 | - * |
|
758 | - * @since 1.0.19 |
|
759 | - * @param string $context View or edit context. |
|
760 | - * @return string |
|
761 | - */ |
|
762 | - public function get_first_name( $context = 'view' ) { |
|
763 | - return $this->get_prop( 'first_name', $context ); |
|
756 | + * Get the customer's first name. |
|
757 | + * |
|
758 | + * @since 1.0.19 |
|
759 | + * @param string $context View or edit context. |
|
760 | + * @return string |
|
761 | + */ |
|
762 | + public function get_first_name( $context = 'view' ) { |
|
763 | + return $this->get_prop( 'first_name', $context ); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | /** |
767 | - * Alias of self::get_first_name(). |
|
768 | - * |
|
769 | - * @since 1.0.19 |
|
770 | - * @param string $context View or edit context. |
|
771 | - * @return int |
|
772 | - */ |
|
773 | - public function get_user_first_name( $context = 'view' ) { |
|
774 | - return $this->get_first_name( $context ); |
|
767 | + * Alias of self::get_first_name(). |
|
768 | + * |
|
769 | + * @since 1.0.19 |
|
770 | + * @param string $context View or edit context. |
|
771 | + * @return int |
|
772 | + */ |
|
773 | + public function get_user_first_name( $context = 'view' ) { |
|
774 | + return $this->get_first_name( $context ); |
|
775 | 775 | } |
776 | 776 | |
777 | - /** |
|
778 | - * Alias of self::get_first_name(). |
|
779 | - * |
|
780 | - * @since 1.0.19 |
|
781 | - * @param string $context View or edit context. |
|
782 | - * @return int |
|
783 | - */ |
|
784 | - public function get_customer_first_name( $context = 'view' ) { |
|
785 | - return $this->get_first_name( $context ); |
|
777 | + /** |
|
778 | + * Alias of self::get_first_name(). |
|
779 | + * |
|
780 | + * @since 1.0.19 |
|
781 | + * @param string $context View or edit context. |
|
782 | + * @return int |
|
783 | + */ |
|
784 | + public function get_customer_first_name( $context = 'view' ) { |
|
785 | + return $this->get_first_name( $context ); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
789 | - * Get the customer's last name. |
|
790 | - * |
|
791 | - * @since 1.0.19 |
|
792 | - * @param string $context View or edit context. |
|
793 | - * @return string |
|
794 | - */ |
|
795 | - public function get_last_name( $context = 'view' ) { |
|
796 | - return $this->get_prop( 'last_name', $context ); |
|
789 | + * Get the customer's last name. |
|
790 | + * |
|
791 | + * @since 1.0.19 |
|
792 | + * @param string $context View or edit context. |
|
793 | + * @return string |
|
794 | + */ |
|
795 | + public function get_last_name( $context = 'view' ) { |
|
796 | + return $this->get_prop( 'last_name', $context ); |
|
797 | 797 | } |
798 | 798 | |
799 | 799 | /** |
800 | - * Alias of self::get_last_name(). |
|
801 | - * |
|
802 | - * @since 1.0.19 |
|
803 | - * @param string $context View or edit context. |
|
804 | - * @return int |
|
805 | - */ |
|
806 | - public function get_user_last_name( $context = 'view' ) { |
|
807 | - return $this->get_last_name( $context ); |
|
800 | + * Alias of self::get_last_name(). |
|
801 | + * |
|
802 | + * @since 1.0.19 |
|
803 | + * @param string $context View or edit context. |
|
804 | + * @return int |
|
805 | + */ |
|
806 | + public function get_user_last_name( $context = 'view' ) { |
|
807 | + return $this->get_last_name( $context ); |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | /** |
811 | - * Alias of self::get_last_name(). |
|
812 | - * |
|
813 | - * @since 1.0.19 |
|
814 | - * @param string $context View or edit context. |
|
815 | - * @return int |
|
816 | - */ |
|
817 | - public function get_customer_last_name( $context = 'view' ) { |
|
818 | - return $this->get_last_name( $context ); |
|
811 | + * Alias of self::get_last_name(). |
|
812 | + * |
|
813 | + * @since 1.0.19 |
|
814 | + * @param string $context View or edit context. |
|
815 | + * @return int |
|
816 | + */ |
|
817 | + public function get_customer_last_name( $context = 'view' ) { |
|
818 | + return $this->get_last_name( $context ); |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | /** |
822 | - * Get the customer's full name. |
|
823 | - * |
|
824 | - * @since 1.0.19 |
|
825 | - * @param string $context View or edit context. |
|
826 | - * @return string |
|
827 | - */ |
|
828 | - public function get_full_name( $context = 'view' ) { |
|
829 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
822 | + * Get the customer's full name. |
|
823 | + * |
|
824 | + * @since 1.0.19 |
|
825 | + * @param string $context View or edit context. |
|
826 | + * @return string |
|
827 | + */ |
|
828 | + public function get_full_name( $context = 'view' ) { |
|
829 | + return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
833 | - * Alias of self::get_full_name(). |
|
834 | - * |
|
835 | - * @since 1.0.19 |
|
836 | - * @param string $context View or edit context. |
|
837 | - * @return int |
|
838 | - */ |
|
839 | - public function get_user_full_name( $context = 'view' ) { |
|
840 | - return $this->get_full_name( $context ); |
|
833 | + * Alias of self::get_full_name(). |
|
834 | + * |
|
835 | + * @since 1.0.19 |
|
836 | + * @param string $context View or edit context. |
|
837 | + * @return int |
|
838 | + */ |
|
839 | + public function get_user_full_name( $context = 'view' ) { |
|
840 | + return $this->get_full_name( $context ); |
|
841 | 841 | } |
842 | 842 | |
843 | 843 | /** |
844 | - * Alias of self::get_full_name(). |
|
845 | - * |
|
846 | - * @since 1.0.19 |
|
847 | - * @param string $context View or edit context. |
|
848 | - * @return int |
|
849 | - */ |
|
850 | - public function get_customer_full_name( $context = 'view' ) { |
|
851 | - return $this->get_full_name( $context ); |
|
844 | + * Alias of self::get_full_name(). |
|
845 | + * |
|
846 | + * @since 1.0.19 |
|
847 | + * @param string $context View or edit context. |
|
848 | + * @return int |
|
849 | + */ |
|
850 | + public function get_customer_full_name( $context = 'view' ) { |
|
851 | + return $this->get_full_name( $context ); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
855 | - * Get the customer's phone number. |
|
856 | - * |
|
857 | - * @since 1.0.19 |
|
858 | - * @param string $context View or edit context. |
|
859 | - * @return string |
|
860 | - */ |
|
861 | - public function get_phone( $context = 'view' ) { |
|
862 | - return $this->get_prop( 'phone', $context ); |
|
855 | + * Get the customer's phone number. |
|
856 | + * |
|
857 | + * @since 1.0.19 |
|
858 | + * @param string $context View or edit context. |
|
859 | + * @return string |
|
860 | + */ |
|
861 | + public function get_phone( $context = 'view' ) { |
|
862 | + return $this->get_prop( 'phone', $context ); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | /** |
866 | - * Alias of self::get_phone(). |
|
867 | - * |
|
868 | - * @since 1.0.19 |
|
869 | - * @param string $context View or edit context. |
|
870 | - * @return int |
|
871 | - */ |
|
872 | - public function get_phone_number( $context = 'view' ) { |
|
873 | - return $this->get_phone( $context ); |
|
866 | + * Alias of self::get_phone(). |
|
867 | + * |
|
868 | + * @since 1.0.19 |
|
869 | + * @param string $context View or edit context. |
|
870 | + * @return int |
|
871 | + */ |
|
872 | + public function get_phone_number( $context = 'view' ) { |
|
873 | + return $this->get_phone( $context ); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
877 | - * Alias of self::get_phone(). |
|
878 | - * |
|
879 | - * @since 1.0.19 |
|
880 | - * @param string $context View or edit context. |
|
881 | - * @return int |
|
882 | - */ |
|
883 | - public function get_user_phone( $context = 'view' ) { |
|
884 | - return $this->get_phone( $context ); |
|
877 | + * Alias of self::get_phone(). |
|
878 | + * |
|
879 | + * @since 1.0.19 |
|
880 | + * @param string $context View or edit context. |
|
881 | + * @return int |
|
882 | + */ |
|
883 | + public function get_user_phone( $context = 'view' ) { |
|
884 | + return $this->get_phone( $context ); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
888 | - * Alias of self::get_phone(). |
|
889 | - * |
|
890 | - * @since 1.0.19 |
|
891 | - * @param string $context View or edit context. |
|
892 | - * @return int |
|
893 | - */ |
|
894 | - public function get_customer_phone( $context = 'view' ) { |
|
895 | - return $this->get_phone( $context ); |
|
888 | + * Alias of self::get_phone(). |
|
889 | + * |
|
890 | + * @since 1.0.19 |
|
891 | + * @param string $context View or edit context. |
|
892 | + * @return int |
|
893 | + */ |
|
894 | + public function get_customer_phone( $context = 'view' ) { |
|
895 | + return $this->get_phone( $context ); |
|
896 | 896 | } |
897 | 897 | |
898 | 898 | /** |
899 | - * Get the customer's email address. |
|
900 | - * |
|
901 | - * @since 1.0.19 |
|
902 | - * @param string $context View or edit context. |
|
903 | - * @return string |
|
904 | - */ |
|
905 | - public function get_email( $context = 'view' ) { |
|
906 | - return $this->get_prop( 'email', $context ); |
|
899 | + * Get the customer's email address. |
|
900 | + * |
|
901 | + * @since 1.0.19 |
|
902 | + * @param string $context View or edit context. |
|
903 | + * @return string |
|
904 | + */ |
|
905 | + public function get_email( $context = 'view' ) { |
|
906 | + return $this->get_prop( 'email', $context ); |
|
907 | 907 | } |
908 | 908 | |
909 | 909 | /** |
910 | - * Alias of self::get_email(). |
|
911 | - * |
|
912 | - * @since 1.0.19 |
|
913 | - * @param string $context View or edit context. |
|
914 | - * @return string |
|
915 | - */ |
|
916 | - public function get_email_address( $context = 'view' ) { |
|
917 | - return $this->get_email( $context ); |
|
910 | + * Alias of self::get_email(). |
|
911 | + * |
|
912 | + * @since 1.0.19 |
|
913 | + * @param string $context View or edit context. |
|
914 | + * @return string |
|
915 | + */ |
|
916 | + public function get_email_address( $context = 'view' ) { |
|
917 | + return $this->get_email( $context ); |
|
918 | 918 | } |
919 | 919 | |
920 | 920 | /** |
921 | - * Alias of self::get_email(). |
|
922 | - * |
|
923 | - * @since 1.0.19 |
|
924 | - * @param string $context View or edit context. |
|
925 | - * @return int |
|
926 | - */ |
|
927 | - public function get_user_email( $context = 'view' ) { |
|
928 | - return $this->get_email( $context ); |
|
921 | + * Alias of self::get_email(). |
|
922 | + * |
|
923 | + * @since 1.0.19 |
|
924 | + * @param string $context View or edit context. |
|
925 | + * @return int |
|
926 | + */ |
|
927 | + public function get_user_email( $context = 'view' ) { |
|
928 | + return $this->get_email( $context ); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | /** |
932 | - * Alias of self::get_email(). |
|
933 | - * |
|
934 | - * @since 1.0.19 |
|
935 | - * @param string $context View or edit context. |
|
936 | - * @return int |
|
937 | - */ |
|
938 | - public function get_customer_email( $context = 'view' ) { |
|
939 | - return $this->get_email( $context ); |
|
932 | + * Alias of self::get_email(). |
|
933 | + * |
|
934 | + * @since 1.0.19 |
|
935 | + * @param string $context View or edit context. |
|
936 | + * @return int |
|
937 | + */ |
|
938 | + public function get_customer_email( $context = 'view' ) { |
|
939 | + return $this->get_email( $context ); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | /** |
943 | - * Get the customer's country. |
|
944 | - * |
|
945 | - * @since 1.0.19 |
|
946 | - * @param string $context View or edit context. |
|
947 | - * @return string |
|
948 | - */ |
|
949 | - public function get_country( $context = 'view' ) { |
|
950 | - $country = $this->get_prop( 'country', $context ); |
|
951 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
943 | + * Get the customer's country. |
|
944 | + * |
|
945 | + * @since 1.0.19 |
|
946 | + * @param string $context View or edit context. |
|
947 | + * @return string |
|
948 | + */ |
|
949 | + public function get_country( $context = 'view' ) { |
|
950 | + $country = $this->get_prop( 'country', $context ); |
|
951 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | /** |
955 | - * Alias of self::get_country(). |
|
956 | - * |
|
957 | - * @since 1.0.19 |
|
958 | - * @param string $context View or edit context. |
|
959 | - * @return int |
|
960 | - */ |
|
961 | - public function get_user_country( $context = 'view' ) { |
|
962 | - return $this->get_country( $context ); |
|
955 | + * Alias of self::get_country(). |
|
956 | + * |
|
957 | + * @since 1.0.19 |
|
958 | + * @param string $context View or edit context. |
|
959 | + * @return int |
|
960 | + */ |
|
961 | + public function get_user_country( $context = 'view' ) { |
|
962 | + return $this->get_country( $context ); |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | /** |
966 | - * Alias of self::get_country(). |
|
967 | - * |
|
968 | - * @since 1.0.19 |
|
969 | - * @param string $context View or edit context. |
|
970 | - * @return int |
|
971 | - */ |
|
972 | - public function get_customer_country( $context = 'view' ) { |
|
973 | - return $this->get_country( $context ); |
|
966 | + * Alias of self::get_country(). |
|
967 | + * |
|
968 | + * @since 1.0.19 |
|
969 | + * @param string $context View or edit context. |
|
970 | + * @return int |
|
971 | + */ |
|
972 | + public function get_customer_country( $context = 'view' ) { |
|
973 | + return $this->get_country( $context ); |
|
974 | 974 | } |
975 | 975 | |
976 | 976 | /** |
977 | - * Get the customer's state. |
|
978 | - * |
|
979 | - * @since 1.0.19 |
|
980 | - * @param string $context View or edit context. |
|
981 | - * @return string |
|
982 | - */ |
|
983 | - public function get_state( $context = 'view' ) { |
|
984 | - $state = $this->get_prop( 'state', $context ); |
|
985 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
977 | + * Get the customer's state. |
|
978 | + * |
|
979 | + * @since 1.0.19 |
|
980 | + * @param string $context View or edit context. |
|
981 | + * @return string |
|
982 | + */ |
|
983 | + public function get_state( $context = 'view' ) { |
|
984 | + $state = $this->get_prop( 'state', $context ); |
|
985 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
986 | 986 | } |
987 | 987 | |
988 | 988 | /** |
989 | - * Alias of self::get_state(). |
|
990 | - * |
|
991 | - * @since 1.0.19 |
|
992 | - * @param string $context View or edit context. |
|
993 | - * @return int |
|
994 | - */ |
|
995 | - public function get_user_state( $context = 'view' ) { |
|
996 | - return $this->get_state( $context ); |
|
989 | + * Alias of self::get_state(). |
|
990 | + * |
|
991 | + * @since 1.0.19 |
|
992 | + * @param string $context View or edit context. |
|
993 | + * @return int |
|
994 | + */ |
|
995 | + public function get_user_state( $context = 'view' ) { |
|
996 | + return $this->get_state( $context ); |
|
997 | 997 | } |
998 | 998 | |
999 | 999 | /** |
1000 | - * Alias of self::get_state(). |
|
1001 | - * |
|
1002 | - * @since 1.0.19 |
|
1003 | - * @param string $context View or edit context. |
|
1004 | - * @return int |
|
1005 | - */ |
|
1006 | - public function get_customer_state( $context = 'view' ) { |
|
1007 | - return $this->get_state( $context ); |
|
1000 | + * Alias of self::get_state(). |
|
1001 | + * |
|
1002 | + * @since 1.0.19 |
|
1003 | + * @param string $context View or edit context. |
|
1004 | + * @return int |
|
1005 | + */ |
|
1006 | + public function get_customer_state( $context = 'view' ) { |
|
1007 | + return $this->get_state( $context ); |
|
1008 | 1008 | } |
1009 | 1009 | |
1010 | 1010 | /** |
1011 | - * Get the customer's city. |
|
1012 | - * |
|
1013 | - * @since 1.0.19 |
|
1014 | - * @param string $context View or edit context. |
|
1015 | - * @return string |
|
1016 | - */ |
|
1017 | - public function get_city( $context = 'view' ) { |
|
1018 | - return $this->get_prop( 'city', $context ); |
|
1011 | + * Get the customer's city. |
|
1012 | + * |
|
1013 | + * @since 1.0.19 |
|
1014 | + * @param string $context View or edit context. |
|
1015 | + * @return string |
|
1016 | + */ |
|
1017 | + public function get_city( $context = 'view' ) { |
|
1018 | + return $this->get_prop( 'city', $context ); |
|
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | /** |
1022 | - * Alias of self::get_city(). |
|
1023 | - * |
|
1024 | - * @since 1.0.19 |
|
1025 | - * @param string $context View or edit context. |
|
1026 | - * @return string |
|
1027 | - */ |
|
1028 | - public function get_user_city( $context = 'view' ) { |
|
1029 | - return $this->get_city( $context ); |
|
1022 | + * Alias of self::get_city(). |
|
1023 | + * |
|
1024 | + * @since 1.0.19 |
|
1025 | + * @param string $context View or edit context. |
|
1026 | + * @return string |
|
1027 | + */ |
|
1028 | + public function get_user_city( $context = 'view' ) { |
|
1029 | + return $this->get_city( $context ); |
|
1030 | 1030 | } |
1031 | 1031 | |
1032 | 1032 | /** |
1033 | - * Alias of self::get_city(). |
|
1034 | - * |
|
1035 | - * @since 1.0.19 |
|
1036 | - * @param string $context View or edit context. |
|
1037 | - * @return string |
|
1038 | - */ |
|
1039 | - public function get_customer_city( $context = 'view' ) { |
|
1040 | - return $this->get_city( $context ); |
|
1033 | + * Alias of self::get_city(). |
|
1034 | + * |
|
1035 | + * @since 1.0.19 |
|
1036 | + * @param string $context View or edit context. |
|
1037 | + * @return string |
|
1038 | + */ |
|
1039 | + public function get_customer_city( $context = 'view' ) { |
|
1040 | + return $this->get_city( $context ); |
|
1041 | 1041 | } |
1042 | 1042 | |
1043 | 1043 | /** |
1044 | - * Get the customer's zip. |
|
1045 | - * |
|
1046 | - * @since 1.0.19 |
|
1047 | - * @param string $context View or edit context. |
|
1048 | - * @return string |
|
1049 | - */ |
|
1050 | - public function get_zip( $context = 'view' ) { |
|
1051 | - return $this->get_prop( 'zip', $context ); |
|
1044 | + * Get the customer's zip. |
|
1045 | + * |
|
1046 | + * @since 1.0.19 |
|
1047 | + * @param string $context View or edit context. |
|
1048 | + * @return string |
|
1049 | + */ |
|
1050 | + public function get_zip( $context = 'view' ) { |
|
1051 | + return $this->get_prop( 'zip', $context ); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | /** |
1055 | - * Alias of self::get_zip(). |
|
1056 | - * |
|
1057 | - * @since 1.0.19 |
|
1058 | - * @param string $context View or edit context. |
|
1059 | - * @return string |
|
1060 | - */ |
|
1061 | - public function get_user_zip( $context = 'view' ) { |
|
1062 | - return $this->get_zip( $context ); |
|
1055 | + * Alias of self::get_zip(). |
|
1056 | + * |
|
1057 | + * @since 1.0.19 |
|
1058 | + * @param string $context View or edit context. |
|
1059 | + * @return string |
|
1060 | + */ |
|
1061 | + public function get_user_zip( $context = 'view' ) { |
|
1062 | + return $this->get_zip( $context ); |
|
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | /** |
1066 | - * Alias of self::get_zip(). |
|
1067 | - * |
|
1068 | - * @since 1.0.19 |
|
1069 | - * @param string $context View or edit context. |
|
1070 | - * @return string |
|
1071 | - */ |
|
1072 | - public function get_customer_zip( $context = 'view' ) { |
|
1073 | - return $this->get_zip( $context ); |
|
1066 | + * Alias of self::get_zip(). |
|
1067 | + * |
|
1068 | + * @since 1.0.19 |
|
1069 | + * @param string $context View or edit context. |
|
1070 | + * @return string |
|
1071 | + */ |
|
1072 | + public function get_customer_zip( $context = 'view' ) { |
|
1073 | + return $this->get_zip( $context ); |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | /** |
1077 | - * Get the customer's company. |
|
1078 | - * |
|
1079 | - * @since 1.0.19 |
|
1080 | - * @param string $context View or edit context. |
|
1081 | - * @return string |
|
1082 | - */ |
|
1083 | - public function get_company( $context = 'view' ) { |
|
1084 | - return $this->get_prop( 'company', $context ); |
|
1077 | + * Get the customer's company. |
|
1078 | + * |
|
1079 | + * @since 1.0.19 |
|
1080 | + * @param string $context View or edit context. |
|
1081 | + * @return string |
|
1082 | + */ |
|
1083 | + public function get_company( $context = 'view' ) { |
|
1084 | + return $this->get_prop( 'company', $context ); |
|
1085 | 1085 | } |
1086 | 1086 | |
1087 | 1087 | /** |
1088 | - * Alias of self::get_company(). |
|
1089 | - * |
|
1090 | - * @since 1.0.19 |
|
1091 | - * @param string $context View or edit context. |
|
1092 | - * @return string |
|
1093 | - */ |
|
1094 | - public function get_user_company( $context = 'view' ) { |
|
1095 | - return $this->get_company( $context ); |
|
1088 | + * Alias of self::get_company(). |
|
1089 | + * |
|
1090 | + * @since 1.0.19 |
|
1091 | + * @param string $context View or edit context. |
|
1092 | + * @return string |
|
1093 | + */ |
|
1094 | + public function get_user_company( $context = 'view' ) { |
|
1095 | + return $this->get_company( $context ); |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | /** |
1099 | - * Alias of self::get_company(). |
|
1100 | - * |
|
1101 | - * @since 1.0.19 |
|
1102 | - * @param string $context View or edit context. |
|
1103 | - * @return string |
|
1104 | - */ |
|
1105 | - public function get_customer_company( $context = 'view' ) { |
|
1106 | - return $this->get_company( $context ); |
|
1099 | + * Alias of self::get_company(). |
|
1100 | + * |
|
1101 | + * @since 1.0.19 |
|
1102 | + * @param string $context View or edit context. |
|
1103 | + * @return string |
|
1104 | + */ |
|
1105 | + public function get_customer_company( $context = 'view' ) { |
|
1106 | + return $this->get_company( $context ); |
|
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | /** |
1110 | - * Get the customer's vat number. |
|
1111 | - * |
|
1112 | - * @since 1.0.19 |
|
1113 | - * @param string $context View or edit context. |
|
1114 | - * @return string |
|
1115 | - */ |
|
1116 | - public function get_vat_number( $context = 'view' ) { |
|
1117 | - return $this->get_prop( 'vat_number', $context ); |
|
1110 | + * Get the customer's vat number. |
|
1111 | + * |
|
1112 | + * @since 1.0.19 |
|
1113 | + * @param string $context View or edit context. |
|
1114 | + * @return string |
|
1115 | + */ |
|
1116 | + public function get_vat_number( $context = 'view' ) { |
|
1117 | + return $this->get_prop( 'vat_number', $context ); |
|
1118 | 1118 | } |
1119 | 1119 | |
1120 | 1120 | /** |
1121 | - * Alias of self::get_vat_number(). |
|
1122 | - * |
|
1123 | - * @since 1.0.19 |
|
1124 | - * @param string $context View or edit context. |
|
1125 | - * @return string |
|
1126 | - */ |
|
1127 | - public function get_user_vat_number( $context = 'view' ) { |
|
1128 | - return $this->get_vat_number( $context ); |
|
1121 | + * Alias of self::get_vat_number(). |
|
1122 | + * |
|
1123 | + * @since 1.0.19 |
|
1124 | + * @param string $context View or edit context. |
|
1125 | + * @return string |
|
1126 | + */ |
|
1127 | + public function get_user_vat_number( $context = 'view' ) { |
|
1128 | + return $this->get_vat_number( $context ); |
|
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | /** |
1132 | - * Alias of self::get_vat_number(). |
|
1133 | - * |
|
1134 | - * @since 1.0.19 |
|
1135 | - * @param string $context View or edit context. |
|
1136 | - * @return string |
|
1137 | - */ |
|
1138 | - public function get_customer_vat_number( $context = 'view' ) { |
|
1139 | - return $this->get_vat_number( $context ); |
|
1132 | + * Alias of self::get_vat_number(). |
|
1133 | + * |
|
1134 | + * @since 1.0.19 |
|
1135 | + * @param string $context View or edit context. |
|
1136 | + * @return string |
|
1137 | + */ |
|
1138 | + public function get_customer_vat_number( $context = 'view' ) { |
|
1139 | + return $this->get_vat_number( $context ); |
|
1140 | 1140 | } |
1141 | 1141 | |
1142 | 1142 | /** |
1143 | - * Get the customer's vat rate. |
|
1144 | - * |
|
1145 | - * @since 1.0.19 |
|
1146 | - * @param string $context View or edit context. |
|
1147 | - * @return string |
|
1148 | - */ |
|
1149 | - public function get_vat_rate( $context = 'view' ) { |
|
1150 | - return $this->get_prop( 'vat_rate', $context ); |
|
1143 | + * Get the customer's vat rate. |
|
1144 | + * |
|
1145 | + * @since 1.0.19 |
|
1146 | + * @param string $context View or edit context. |
|
1147 | + * @return string |
|
1148 | + */ |
|
1149 | + public function get_vat_rate( $context = 'view' ) { |
|
1150 | + return $this->get_prop( 'vat_rate', $context ); |
|
1151 | 1151 | } |
1152 | 1152 | |
1153 | 1153 | /** |
1154 | - * Alias of self::get_vat_rate(). |
|
1155 | - * |
|
1156 | - * @since 1.0.19 |
|
1157 | - * @param string $context View or edit context. |
|
1158 | - * @return string |
|
1159 | - */ |
|
1160 | - public function get_user_vat_rate( $context = 'view' ) { |
|
1161 | - return $this->get_vat_rate( $context ); |
|
1154 | + * Alias of self::get_vat_rate(). |
|
1155 | + * |
|
1156 | + * @since 1.0.19 |
|
1157 | + * @param string $context View or edit context. |
|
1158 | + * @return string |
|
1159 | + */ |
|
1160 | + public function get_user_vat_rate( $context = 'view' ) { |
|
1161 | + return $this->get_vat_rate( $context ); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | /** |
1165 | - * Alias of self::get_vat_rate(). |
|
1166 | - * |
|
1167 | - * @since 1.0.19 |
|
1168 | - * @param string $context View or edit context. |
|
1169 | - * @return string |
|
1170 | - */ |
|
1171 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
1172 | - return $this->get_vat_rate( $context ); |
|
1173 | - } |
|
1165 | + * Alias of self::get_vat_rate(). |
|
1166 | + * |
|
1167 | + * @since 1.0.19 |
|
1168 | + * @param string $context View or edit context. |
|
1169 | + * @return string |
|
1170 | + */ |
|
1171 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
1172 | + return $this->get_vat_rate( $context ); |
|
1173 | + } |
|
1174 | + |
|
1175 | + /** |
|
1176 | + * Get the customer's address. |
|
1177 | + * |
|
1178 | + * @since 1.0.19 |
|
1179 | + * @param string $context View or edit context. |
|
1180 | + * @return string |
|
1181 | + */ |
|
1182 | + public function get_address( $context = 'view' ) { |
|
1183 | + return $this->get_prop( 'address', $context ); |
|
1184 | + } |
|
1185 | + |
|
1186 | + /** |
|
1187 | + * Alias of self::get_address(). |
|
1188 | + * |
|
1189 | + * @since 1.0.19 |
|
1190 | + * @param string $context View or edit context. |
|
1191 | + * @return string |
|
1192 | + */ |
|
1193 | + public function get_user_address( $context = 'view' ) { |
|
1194 | + return $this->get_address( $context ); |
|
1195 | + } |
|
1196 | + |
|
1197 | + /** |
|
1198 | + * Alias of self::get_address(). |
|
1199 | + * |
|
1200 | + * @since 1.0.19 |
|
1201 | + * @param string $context View or edit context. |
|
1202 | + * @return string |
|
1203 | + */ |
|
1204 | + public function get_customer_address( $context = 'view' ) { |
|
1205 | + return $this->get_address( $context ); |
|
1206 | + } |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * Get whether the customer has viewed the invoice or not. |
|
1210 | + * |
|
1211 | + * @since 1.0.19 |
|
1212 | + * @param string $context View or edit context. |
|
1213 | + * @return bool |
|
1214 | + */ |
|
1215 | + public function get_is_viewed( $context = 'view' ) { |
|
1216 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1217 | + } |
|
1218 | + |
|
1219 | + /** |
|
1220 | + * Get other recipients for invoice communications. |
|
1221 | + * |
|
1222 | + * @since 1.0.19 |
|
1223 | + * @param string $context View or edit context. |
|
1224 | + * @return bool |
|
1225 | + */ |
|
1226 | + public function get_email_cc( $context = 'view' ) { |
|
1227 | + return $this->get_prop( 'email_cc', $context ); |
|
1228 | + } |
|
1174 | 1229 | |
1175 | 1230 | /** |
1176 | - * Get the customer's address. |
|
1177 | - * |
|
1178 | - * @since 1.0.19 |
|
1179 | - * @param string $context View or edit context. |
|
1180 | - * @return string |
|
1181 | - */ |
|
1182 | - public function get_address( $context = 'view' ) { |
|
1183 | - return $this->get_prop( 'address', $context ); |
|
1184 | - } |
|
1185 | - |
|
1186 | - /** |
|
1187 | - * Alias of self::get_address(). |
|
1188 | - * |
|
1189 | - * @since 1.0.19 |
|
1190 | - * @param string $context View or edit context. |
|
1191 | - * @return string |
|
1192 | - */ |
|
1193 | - public function get_user_address( $context = 'view' ) { |
|
1194 | - return $this->get_address( $context ); |
|
1195 | - } |
|
1196 | - |
|
1197 | - /** |
|
1198 | - * Alias of self::get_address(). |
|
1199 | - * |
|
1200 | - * @since 1.0.19 |
|
1201 | - * @param string $context View or edit context. |
|
1202 | - * @return string |
|
1203 | - */ |
|
1204 | - public function get_customer_address( $context = 'view' ) { |
|
1205 | - return $this->get_address( $context ); |
|
1206 | - } |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * Get whether the customer has viewed the invoice or not. |
|
1210 | - * |
|
1211 | - * @since 1.0.19 |
|
1212 | - * @param string $context View or edit context. |
|
1213 | - * @return bool |
|
1214 | - */ |
|
1215 | - public function get_is_viewed( $context = 'view' ) { |
|
1216 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
1217 | - } |
|
1218 | - |
|
1219 | - /** |
|
1220 | - * Get other recipients for invoice communications. |
|
1221 | - * |
|
1222 | - * @since 1.0.19 |
|
1223 | - * @param string $context View or edit context. |
|
1224 | - * @return bool |
|
1225 | - */ |
|
1226 | - public function get_email_cc( $context = 'view' ) { |
|
1227 | - return $this->get_prop( 'email_cc', $context ); |
|
1228 | - } |
|
1229 | - |
|
1230 | - /** |
|
1231 | - * Get invoice template. |
|
1232 | - * |
|
1233 | - * @since 1.0.19 |
|
1234 | - * @param string $context View or edit context. |
|
1235 | - * @return bool |
|
1236 | - */ |
|
1237 | - public function get_template( $context = 'view' ) { |
|
1238 | - return $this->get_prop( 'template', $context ); |
|
1239 | - } |
|
1240 | - |
|
1241 | - /** |
|
1242 | - * Get whether the customer has confirmed their address. |
|
1243 | - * |
|
1244 | - * @since 1.0.19 |
|
1245 | - * @param string $context View or edit context. |
|
1246 | - * @return bool |
|
1247 | - */ |
|
1248 | - public function get_address_confirmed( $context = 'view' ) { |
|
1249 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1250 | - } |
|
1251 | - |
|
1252 | - /** |
|
1253 | - * Alias of self::get_address_confirmed(). |
|
1254 | - * |
|
1255 | - * @since 1.0.19 |
|
1256 | - * @param string $context View or edit context. |
|
1257 | - * @return bool |
|
1258 | - */ |
|
1259 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
1260 | - return $this->get_address_confirmed( $context ); |
|
1261 | - } |
|
1262 | - |
|
1263 | - /** |
|
1264 | - * Alias of self::get_address(). |
|
1265 | - * |
|
1266 | - * @since 1.0.19 |
|
1267 | - * @param string $context View or edit context. |
|
1268 | - * @return bool |
|
1269 | - */ |
|
1270 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
1271 | - return $this->get_address_confirmed( $context ); |
|
1272 | - } |
|
1273 | - |
|
1274 | - /** |
|
1275 | - * Get the invoice subtotal. |
|
1276 | - * |
|
1277 | - * @since 1.0.19 |
|
1278 | - * @param string $context View or edit context. |
|
1279 | - * @return float |
|
1280 | - */ |
|
1281 | - public function get_subtotal( $context = 'view' ) { |
|
1231 | + * Get invoice template. |
|
1232 | + * |
|
1233 | + * @since 1.0.19 |
|
1234 | + * @param string $context View or edit context. |
|
1235 | + * @return bool |
|
1236 | + */ |
|
1237 | + public function get_template( $context = 'view' ) { |
|
1238 | + return $this->get_prop( 'template', $context ); |
|
1239 | + } |
|
1240 | + |
|
1241 | + /** |
|
1242 | + * Get whether the customer has confirmed their address. |
|
1243 | + * |
|
1244 | + * @since 1.0.19 |
|
1245 | + * @param string $context View or edit context. |
|
1246 | + * @return bool |
|
1247 | + */ |
|
1248 | + public function get_address_confirmed( $context = 'view' ) { |
|
1249 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1250 | + } |
|
1251 | + |
|
1252 | + /** |
|
1253 | + * Alias of self::get_address_confirmed(). |
|
1254 | + * |
|
1255 | + * @since 1.0.19 |
|
1256 | + * @param string $context View or edit context. |
|
1257 | + * @return bool |
|
1258 | + */ |
|
1259 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
1260 | + return $this->get_address_confirmed( $context ); |
|
1261 | + } |
|
1262 | + |
|
1263 | + /** |
|
1264 | + * Alias of self::get_address(). |
|
1265 | + * |
|
1266 | + * @since 1.0.19 |
|
1267 | + * @param string $context View or edit context. |
|
1268 | + * @return bool |
|
1269 | + */ |
|
1270 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
1271 | + return $this->get_address_confirmed( $context ); |
|
1272 | + } |
|
1273 | + |
|
1274 | + /** |
|
1275 | + * Get the invoice subtotal. |
|
1276 | + * |
|
1277 | + * @since 1.0.19 |
|
1278 | + * @param string $context View or edit context. |
|
1279 | + * @return float |
|
1280 | + */ |
|
1281 | + public function get_subtotal( $context = 'view' ) { |
|
1282 | 1282 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
1283 | 1283 | |
1284 | 1284 | // Backwards compatibility. |
@@ -1290,155 +1290,155 @@ discard block |
||
1290 | 1290 | } |
1291 | 1291 | |
1292 | 1292 | /** |
1293 | - * Get the invoice discount total. |
|
1294 | - * |
|
1295 | - * @since 1.0.19 |
|
1296 | - * @param string $context View or edit context. |
|
1297 | - * @return float |
|
1298 | - */ |
|
1299 | - public function get_total_discount( $context = 'view' ) { |
|
1300 | - return (float) $this->get_prop( 'total_discount', $context ); |
|
1293 | + * Get the invoice discount total. |
|
1294 | + * |
|
1295 | + * @since 1.0.19 |
|
1296 | + * @param string $context View or edit context. |
|
1297 | + * @return float |
|
1298 | + */ |
|
1299 | + public function get_total_discount( $context = 'view' ) { |
|
1300 | + return (float) $this->get_prop( 'total_discount', $context ); |
|
1301 | 1301 | } |
1302 | 1302 | |
1303 | 1303 | /** |
1304 | - * Get the invoice tax total. |
|
1305 | - * |
|
1306 | - * @since 1.0.19 |
|
1307 | - * @param string $context View or edit context. |
|
1308 | - * @return float |
|
1309 | - */ |
|
1310 | - public function get_total_tax( $context = 'view' ) { |
|
1311 | - return (float) $this->get_prop( 'total_tax', $context ); |
|
1312 | - } |
|
1304 | + * Get the invoice tax total. |
|
1305 | + * |
|
1306 | + * @since 1.0.19 |
|
1307 | + * @param string $context View or edit context. |
|
1308 | + * @return float |
|
1309 | + */ |
|
1310 | + public function get_total_tax( $context = 'view' ) { |
|
1311 | + return (float) $this->get_prop( 'total_tax', $context ); |
|
1312 | + } |
|
1313 | 1313 | |
1314 | - /** |
|
1315 | - * @deprecated |
|
1316 | - */ |
|
1317 | - public function get_final_tax( $currency = false ) { |
|
1318 | - $tax = $this->get_total_tax(); |
|
1314 | + /** |
|
1315 | + * @deprecated |
|
1316 | + */ |
|
1317 | + public function get_final_tax( $currency = false ) { |
|
1318 | + $tax = $this->get_total_tax(); |
|
1319 | 1319 | |
1320 | 1320 | if ( $currency ) { |
1321 | - return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() ); |
|
1321 | + return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() ); |
|
1322 | 1322 | } |
1323 | 1323 | |
1324 | 1324 | return $tax; |
1325 | 1325 | } |
1326 | 1326 | |
1327 | 1327 | /** |
1328 | - * Get the invoice fees total. |
|
1329 | - * |
|
1330 | - * @since 1.0.19 |
|
1331 | - * @param string $context View or edit context. |
|
1332 | - * @return float |
|
1333 | - */ |
|
1334 | - public function get_total_fees( $context = 'view' ) { |
|
1335 | - return (float) $this->get_prop( 'total_fees', $context ); |
|
1328 | + * Get the invoice fees total. |
|
1329 | + * |
|
1330 | + * @since 1.0.19 |
|
1331 | + * @param string $context View or edit context. |
|
1332 | + * @return float |
|
1333 | + */ |
|
1334 | + public function get_total_fees( $context = 'view' ) { |
|
1335 | + return (float) $this->get_prop( 'total_fees', $context ); |
|
1336 | 1336 | } |
1337 | 1337 | |
1338 | 1338 | /** |
1339 | - * Alias for self::get_total_fees(). |
|
1340 | - * |
|
1341 | - * @since 1.0.19 |
|
1342 | - * @param string $context View or edit context. |
|
1343 | - * @return float |
|
1344 | - */ |
|
1345 | - public function get_fees_total( $context = 'view' ) { |
|
1346 | - return $this->get_total_fees( $context ); |
|
1339 | + * Alias for self::get_total_fees(). |
|
1340 | + * |
|
1341 | + * @since 1.0.19 |
|
1342 | + * @param string $context View or edit context. |
|
1343 | + * @return float |
|
1344 | + */ |
|
1345 | + public function get_fees_total( $context = 'view' ) { |
|
1346 | + return $this->get_total_fees( $context ); |
|
1347 | 1347 | } |
1348 | 1348 | |
1349 | 1349 | /** |
1350 | - * Get the invoice total. |
|
1351 | - * |
|
1352 | - * @since 1.0.19 |
|
1350 | + * Get the invoice total. |
|
1351 | + * |
|
1352 | + * @since 1.0.19 |
|
1353 | 1353 | * @return float |
1354 | - */ |
|
1355 | - public function get_total() { |
|
1356 | - $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
|
1357 | - return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
1354 | + */ |
|
1355 | + public function get_total() { |
|
1356 | + $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total(); |
|
1357 | + return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
1358 | 1358 | } |
1359 | 1359 | |
1360 | 1360 | /** |
1361 | - * Get the initial invoice total. |
|
1362 | - * |
|
1363 | - * @since 1.0.19 |
|
1361 | + * Get the initial invoice total. |
|
1362 | + * |
|
1363 | + * @since 1.0.19 |
|
1364 | 1364 | * @param string $context View or edit context. |
1365 | 1365 | * @return float |
1366 | - */ |
|
1366 | + */ |
|
1367 | 1367 | public function get_initial_total() { |
1368 | 1368 | |
1369 | - if ( empty( $this->totals ) ) { |
|
1370 | - $this->recalculate_total(); |
|
1371 | - } |
|
1369 | + if ( empty( $this->totals ) ) { |
|
1370 | + $this->recalculate_total(); |
|
1371 | + } |
|
1372 | 1372 | |
1373 | - $tax = $this->totals['tax']['initial']; |
|
1374 | - $fee = $this->totals['fee']['initial']; |
|
1375 | - $discount = $this->totals['discount']['initial']; |
|
1376 | - $subtotal = $this->totals['subtotal']['initial']; |
|
1377 | - $total = $tax + $fee - $discount + $subtotal; |
|
1373 | + $tax = $this->totals['tax']['initial']; |
|
1374 | + $fee = $this->totals['fee']['initial']; |
|
1375 | + $discount = $this->totals['discount']['initial']; |
|
1376 | + $subtotal = $this->totals['subtotal']['initial']; |
|
1377 | + $total = $tax + $fee - $discount + $subtotal; |
|
1378 | 1378 | |
1379 | - if ( 0 > $total ) { |
|
1380 | - $total = 0; |
|
1381 | - } |
|
1379 | + if ( 0 > $total ) { |
|
1380 | + $total = 0; |
|
1381 | + } |
|
1382 | 1382 | |
1383 | 1383 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
1384 | - } |
|
1384 | + } |
|
1385 | 1385 | |
1386 | - /** |
|
1387 | - * Get the recurring invoice total. |
|
1388 | - * |
|
1389 | - * @since 1.0.19 |
|
1386 | + /** |
|
1387 | + * Get the recurring invoice total. |
|
1388 | + * |
|
1389 | + * @since 1.0.19 |
|
1390 | 1390 | * @param string $context View or edit context. |
1391 | 1391 | * @return float |
1392 | - */ |
|
1392 | + */ |
|
1393 | 1393 | public function get_recurring_total() { |
1394 | 1394 | |
1395 | - if ( empty( $this->totals ) ) { |
|
1396 | - $this->recalculate_total(); |
|
1397 | - } |
|
1395 | + if ( empty( $this->totals ) ) { |
|
1396 | + $this->recalculate_total(); |
|
1397 | + } |
|
1398 | 1398 | |
1399 | - $tax = $this->totals['tax']['recurring']; |
|
1400 | - $fee = $this->totals['fee']['recurring']; |
|
1401 | - $discount = $this->totals['discount']['recurring']; |
|
1402 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
1403 | - $total = $tax + $fee - $discount + $subtotal; |
|
1399 | + $tax = $this->totals['tax']['recurring']; |
|
1400 | + $fee = $this->totals['fee']['recurring']; |
|
1401 | + $discount = $this->totals['discount']['recurring']; |
|
1402 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
1403 | + $total = $tax + $fee - $discount + $subtotal; |
|
1404 | 1404 | |
1405 | - if ( 0 > $total ) { |
|
1406 | - $total = 0; |
|
1407 | - } |
|
1405 | + if ( 0 > $total ) { |
|
1406 | + $total = 0; |
|
1407 | + } |
|
1408 | 1408 | |
1409 | 1409 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
1410 | - } |
|
1410 | + } |
|
1411 | 1411 | |
1412 | - /** |
|
1413 | - * Returns recurring payment details. |
|
1414 | - * |
|
1415 | - * @since 1.0.19 |
|
1412 | + /** |
|
1413 | + * Returns recurring payment details. |
|
1414 | + * |
|
1415 | + * @since 1.0.19 |
|
1416 | 1416 | * @param string $field Optionally provide a field to return. |
1417 | - * @param string $currency Whether to include the currency. |
|
1417 | + * @param string $currency Whether to include the currency. |
|
1418 | 1418 | * @return float |
1419 | - */ |
|
1419 | + */ |
|
1420 | 1420 | public function get_recurring_details( $field = '', $currency = false ) { |
1421 | 1421 | |
1422 | - // Maybe recalculate totals. |
|
1423 | - if ( empty( $this->totals ) ) { |
|
1424 | - $this->recalculate_total(); |
|
1425 | - } |
|
1422 | + // Maybe recalculate totals. |
|
1423 | + if ( empty( $this->totals ) ) { |
|
1424 | + $this->recalculate_total(); |
|
1425 | + } |
|
1426 | 1426 | |
1427 | - // Prepare recurring totals. |
|
1427 | + // Prepare recurring totals. |
|
1428 | 1428 | $data = apply_filters( |
1429 | - 'wpinv_get_invoice_recurring_details', |
|
1430 | - array( |
|
1431 | - 'cart_details' => $this->get_cart_details(), |
|
1432 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1433 | - 'discount' => $this->totals['discount']['recurring'], |
|
1434 | - 'tax' => $this->totals['tax']['recurring'], |
|
1435 | - 'fee' => $this->totals['fee']['recurring'], |
|
1436 | - 'total' => $this->get_recurring_total(), |
|
1437 | - ), |
|
1438 | - $this, |
|
1439 | - $field, |
|
1440 | - $currency |
|
1441 | - ); |
|
1429 | + 'wpinv_get_invoice_recurring_details', |
|
1430 | + array( |
|
1431 | + 'cart_details' => $this->get_cart_details(), |
|
1432 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
1433 | + 'discount' => $this->totals['discount']['recurring'], |
|
1434 | + 'tax' => $this->totals['tax']['recurring'], |
|
1435 | + 'fee' => $this->totals['fee']['recurring'], |
|
1436 | + 'total' => $this->get_recurring_total(), |
|
1437 | + ), |
|
1438 | + $this, |
|
1439 | + $field, |
|
1440 | + $currency |
|
1441 | + ); |
|
1442 | 1442 | |
1443 | 1443 | if ( isset( $data[$field] ) ) { |
1444 | 1444 | return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
@@ -1448,145 +1448,145 @@ discard block |
||
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | /** |
1451 | - * Get the invoice fees. |
|
1452 | - * |
|
1453 | - * @since 1.0.19 |
|
1454 | - * @param string $context View or edit context. |
|
1455 | - * @return array |
|
1456 | - */ |
|
1457 | - public function get_fees( $context = 'view' ) { |
|
1458 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1451 | + * Get the invoice fees. |
|
1452 | + * |
|
1453 | + * @since 1.0.19 |
|
1454 | + * @param string $context View or edit context. |
|
1455 | + * @return array |
|
1456 | + */ |
|
1457 | + public function get_fees( $context = 'view' ) { |
|
1458 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1459 | 1459 | } |
1460 | 1460 | |
1461 | 1461 | /** |
1462 | - * Get the invoice discounts. |
|
1463 | - * |
|
1464 | - * @since 1.0.19 |
|
1465 | - * @param string $context View or edit context. |
|
1466 | - * @return array |
|
1467 | - */ |
|
1468 | - public function get_discounts( $context = 'view' ) { |
|
1469 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1462 | + * Get the invoice discounts. |
|
1463 | + * |
|
1464 | + * @since 1.0.19 |
|
1465 | + * @param string $context View or edit context. |
|
1466 | + * @return array |
|
1467 | + */ |
|
1468 | + public function get_discounts( $context = 'view' ) { |
|
1469 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1470 | 1470 | } |
1471 | 1471 | |
1472 | 1472 | /** |
1473 | - * Get the invoice taxes. |
|
1474 | - * |
|
1475 | - * @since 1.0.19 |
|
1476 | - * @param string $context View or edit context. |
|
1477 | - * @return array |
|
1478 | - */ |
|
1479 | - public function get_taxes( $context = 'view' ) { |
|
1480 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1473 | + * Get the invoice taxes. |
|
1474 | + * |
|
1475 | + * @since 1.0.19 |
|
1476 | + * @param string $context View or edit context. |
|
1477 | + * @return array |
|
1478 | + */ |
|
1479 | + public function get_taxes( $context = 'view' ) { |
|
1480 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | /** |
1484 | - * Get the invoice items. |
|
1485 | - * |
|
1486 | - * @since 1.0.19 |
|
1487 | - * @param string $context View or edit context. |
|
1488 | - * @return GetPaid_Form_Item[] |
|
1489 | - */ |
|
1490 | - public function get_items( $context = 'view' ) { |
|
1484 | + * Get the invoice items. |
|
1485 | + * |
|
1486 | + * @since 1.0.19 |
|
1487 | + * @param string $context View or edit context. |
|
1488 | + * @return GetPaid_Form_Item[] |
|
1489 | + */ |
|
1490 | + public function get_items( $context = 'view' ) { |
|
1491 | 1491 | return $this->get_prop( 'items', $context ); |
1492 | 1492 | } |
1493 | 1493 | |
1494 | 1494 | /** |
1495 | - * Get the invoice's payment form. |
|
1496 | - * |
|
1497 | - * @since 1.0.19 |
|
1498 | - * @param string $context View or edit context. |
|
1499 | - * @return int |
|
1500 | - */ |
|
1501 | - public function get_payment_form( $context = 'view' ) { |
|
1502 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1495 | + * Get the invoice's payment form. |
|
1496 | + * |
|
1497 | + * @since 1.0.19 |
|
1498 | + * @param string $context View or edit context. |
|
1499 | + * @return int |
|
1500 | + */ |
|
1501 | + public function get_payment_form( $context = 'view' ) { |
|
1502 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1503 | 1503 | } |
1504 | 1504 | |
1505 | 1505 | /** |
1506 | - * Get the invoice's submission id. |
|
1507 | - * |
|
1508 | - * @since 1.0.19 |
|
1509 | - * @param string $context View or edit context. |
|
1510 | - * @return string |
|
1511 | - */ |
|
1512 | - public function get_submission_id( $context = 'view' ) { |
|
1513 | - return $this->get_prop( 'submission_id', $context ); |
|
1506 | + * Get the invoice's submission id. |
|
1507 | + * |
|
1508 | + * @since 1.0.19 |
|
1509 | + * @param string $context View or edit context. |
|
1510 | + * @return string |
|
1511 | + */ |
|
1512 | + public function get_submission_id( $context = 'view' ) { |
|
1513 | + return $this->get_prop( 'submission_id', $context ); |
|
1514 | 1514 | } |
1515 | 1515 | |
1516 | 1516 | /** |
1517 | - * Get the invoice's discount code. |
|
1518 | - * |
|
1519 | - * @since 1.0.19 |
|
1520 | - * @param string $context View or edit context. |
|
1521 | - * @return string |
|
1522 | - */ |
|
1523 | - public function get_discount_code( $context = 'view' ) { |
|
1524 | - return $this->get_prop( 'discount_code', $context ); |
|
1517 | + * Get the invoice's discount code. |
|
1518 | + * |
|
1519 | + * @since 1.0.19 |
|
1520 | + * @param string $context View or edit context. |
|
1521 | + * @return string |
|
1522 | + */ |
|
1523 | + public function get_discount_code( $context = 'view' ) { |
|
1524 | + return $this->get_prop( 'discount_code', $context ); |
|
1525 | 1525 | } |
1526 | 1526 | |
1527 | 1527 | /** |
1528 | - * Get the invoice's gateway. |
|
1529 | - * |
|
1530 | - * @since 1.0.19 |
|
1531 | - * @param string $context View or edit context. |
|
1532 | - * @return string |
|
1533 | - */ |
|
1534 | - public function get_gateway( $context = 'view' ) { |
|
1535 | - return $this->get_prop( 'gateway', $context ); |
|
1528 | + * Get the invoice's gateway. |
|
1529 | + * |
|
1530 | + * @since 1.0.19 |
|
1531 | + * @param string $context View or edit context. |
|
1532 | + * @return string |
|
1533 | + */ |
|
1534 | + public function get_gateway( $context = 'view' ) { |
|
1535 | + return $this->get_prop( 'gateway', $context ); |
|
1536 | 1536 | } |
1537 | 1537 | |
1538 | 1538 | /** |
1539 | - * Get the invoice's gateway display title. |
|
1540 | - * |
|
1541 | - * @since 1.0.19 |
|
1542 | - * @return string |
|
1543 | - */ |
|
1539 | + * Get the invoice's gateway display title. |
|
1540 | + * |
|
1541 | + * @since 1.0.19 |
|
1542 | + * @return string |
|
1543 | + */ |
|
1544 | 1544 | public function get_gateway_title() { |
1545 | 1545 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
1546 | 1546 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
1547 | 1547 | } |
1548 | 1548 | |
1549 | 1549 | /** |
1550 | - * Get the invoice's transaction id. |
|
1551 | - * |
|
1552 | - * @since 1.0.19 |
|
1553 | - * @param string $context View or edit context. |
|
1554 | - * @return string |
|
1555 | - */ |
|
1556 | - public function get_transaction_id( $context = 'view' ) { |
|
1557 | - return $this->get_prop( 'transaction_id', $context ); |
|
1550 | + * Get the invoice's transaction id. |
|
1551 | + * |
|
1552 | + * @since 1.0.19 |
|
1553 | + * @param string $context View or edit context. |
|
1554 | + * @return string |
|
1555 | + */ |
|
1556 | + public function get_transaction_id( $context = 'view' ) { |
|
1557 | + return $this->get_prop( 'transaction_id', $context ); |
|
1558 | 1558 | } |
1559 | 1559 | |
1560 | 1560 | /** |
1561 | - * Get the invoice's currency. |
|
1562 | - * |
|
1563 | - * @since 1.0.19 |
|
1564 | - * @param string $context View or edit context. |
|
1565 | - * @return string |
|
1566 | - */ |
|
1567 | - public function get_currency( $context = 'view' ) { |
|
1561 | + * Get the invoice's currency. |
|
1562 | + * |
|
1563 | + * @since 1.0.19 |
|
1564 | + * @param string $context View or edit context. |
|
1565 | + * @return string |
|
1566 | + */ |
|
1567 | + public function get_currency( $context = 'view' ) { |
|
1568 | 1568 | $currency = $this->get_prop( 'currency', $context ); |
1569 | 1569 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | /** |
1573 | - * Checks if we are charging taxes for this invoice. |
|
1574 | - * |
|
1575 | - * @since 1.0.19 |
|
1576 | - * @param string $context View or edit context. |
|
1577 | - * @return bool |
|
1578 | - */ |
|
1579 | - public function get_disable_taxes( $context = 'view' ) { |
|
1573 | + * Checks if we are charging taxes for this invoice. |
|
1574 | + * |
|
1575 | + * @since 1.0.19 |
|
1576 | + * @param string $context View or edit context. |
|
1577 | + * @return bool |
|
1578 | + */ |
|
1579 | + public function get_disable_taxes( $context = 'view' ) { |
|
1580 | 1580 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
1581 | 1581 | } |
1582 | 1582 | |
1583 | 1583 | /** |
1584 | - * Retrieves the subscription id for an invoice. |
|
1585 | - * |
|
1586 | - * @since 1.0.19 |
|
1587 | - * @param string $context View or edit context. |
|
1588 | - * @return int |
|
1589 | - */ |
|
1584 | + * Retrieves the subscription id for an invoice. |
|
1585 | + * |
|
1586 | + * @since 1.0.19 |
|
1587 | + * @param string $context View or edit context. |
|
1588 | + * @return int |
|
1589 | + */ |
|
1590 | 1590 | public function get_subscription_id( $context = 'view' ) { |
1591 | 1591 | $subscription_id = $this->get_prop( 'subscription_id', $context ); |
1592 | 1592 | |
@@ -1599,12 +1599,12 @@ discard block |
||
1599 | 1599 | } |
1600 | 1600 | |
1601 | 1601 | /** |
1602 | - * Retrieves the payment meta for an invoice. |
|
1603 | - * |
|
1604 | - * @since 1.0.19 |
|
1605 | - * @param string $context View or edit context. |
|
1606 | - * @return array |
|
1607 | - */ |
|
1602 | + * Retrieves the payment meta for an invoice. |
|
1603 | + * |
|
1604 | + * @since 1.0.19 |
|
1605 | + * @param string $context View or edit context. |
|
1606 | + * @return array |
|
1607 | + */ |
|
1608 | 1608 | public function get_payment_meta( $context = 'view' ) { |
1609 | 1609 | |
1610 | 1610 | return array( |
@@ -1624,11 +1624,11 @@ discard block |
||
1624 | 1624 | } |
1625 | 1625 | |
1626 | 1626 | /** |
1627 | - * Retrieves the cart details for an invoice. |
|
1628 | - * |
|
1629 | - * @since 1.0.19 |
|
1630 | - * @return array |
|
1631 | - */ |
|
1627 | + * Retrieves the cart details for an invoice. |
|
1628 | + * |
|
1629 | + * @since 1.0.19 |
|
1630 | + * @return array |
|
1631 | + */ |
|
1632 | 1632 | public function get_cart_details() { |
1633 | 1633 | $items = $this->get_items(); |
1634 | 1634 | $cart_details = array(); |
@@ -1638,16 +1638,16 @@ discard block |
||
1638 | 1638 | } |
1639 | 1639 | |
1640 | 1640 | return $cart_details; |
1641 | - } |
|
1641 | + } |
|
1642 | 1642 | |
1643 | - /** |
|
1644 | - * Retrieves the recurring item. |
|
1645 | - * |
|
1646 | - * @return null|GetPaid_Form_Item |
|
1647 | - */ |
|
1648 | - public function get_recurring( $object = false ) { |
|
1643 | + /** |
|
1644 | + * Retrieves the recurring item. |
|
1645 | + * |
|
1646 | + * @return null|GetPaid_Form_Item |
|
1647 | + */ |
|
1648 | + public function get_recurring( $object = false ) { |
|
1649 | 1649 | |
1650 | - // Are we returning an object? |
|
1650 | + // Are we returning an object? |
|
1651 | 1651 | if ( $object ) { |
1652 | 1652 | return $this->get_item( $this->recurring_item ); |
1653 | 1653 | } |
@@ -1655,58 +1655,58 @@ discard block |
||
1655 | 1655 | return $this->recurring_item; |
1656 | 1656 | } |
1657 | 1657 | |
1658 | - /** |
|
1659 | - * Retrieves the subscription name. |
|
1660 | - * |
|
1661 | - * @since 1.0.19 |
|
1662 | - * @return string |
|
1663 | - */ |
|
1664 | - public function get_subscription_name() { |
|
1658 | + /** |
|
1659 | + * Retrieves the subscription name. |
|
1660 | + * |
|
1661 | + * @since 1.0.19 |
|
1662 | + * @return string |
|
1663 | + */ |
|
1664 | + public function get_subscription_name() { |
|
1665 | 1665 | |
1666 | - // Retrieve the recurring name |
|
1666 | + // Retrieve the recurring name |
|
1667 | 1667 | $item = $this->get_recurring( true ); |
1668 | 1668 | |
1669 | - // Abort if it does not exist. |
|
1669 | + // Abort if it does not exist. |
|
1670 | 1670 | if ( empty( $item ) ) { |
1671 | 1671 | return ''; |
1672 | 1672 | } |
1673 | 1673 | |
1674 | - // Return the item name. |
|
1674 | + // Return the item name. |
|
1675 | 1675 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
1676 | - } |
|
1677 | - |
|
1678 | - /** |
|
1679 | - * Retrieves the view url. |
|
1680 | - * |
|
1681 | - * @since 1.0.19 |
|
1682 | - * @return string |
|
1683 | - */ |
|
1684 | - public function get_view_url() { |
|
1676 | + } |
|
1677 | + |
|
1678 | + /** |
|
1679 | + * Retrieves the view url. |
|
1680 | + * |
|
1681 | + * @since 1.0.19 |
|
1682 | + * @return string |
|
1683 | + */ |
|
1684 | + public function get_view_url() { |
|
1685 | 1685 | $invoice_url = get_permalink( $this->get_id() ); |
1686 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1686 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
1687 | 1687 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
1688 | - } |
|
1688 | + } |
|
1689 | 1689 | |
1690 | - /** |
|
1691 | - * Retrieves the payment url. |
|
1692 | - * |
|
1693 | - * @since 1.0.19 |
|
1694 | - * @return string |
|
1695 | - */ |
|
1696 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1690 | + /** |
|
1691 | + * Retrieves the payment url. |
|
1692 | + * |
|
1693 | + * @since 1.0.19 |
|
1694 | + * @return string |
|
1695 | + */ |
|
1696 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
1697 | 1697 | |
1698 | - // Retrieve the checkout url. |
|
1698 | + // Retrieve the checkout url. |
|
1699 | 1699 | $pay_url = wpinv_get_checkout_uri(); |
1700 | 1700 | |
1701 | - // Maybe force ssl. |
|
1701 | + // Maybe force ssl. |
|
1702 | 1702 | if ( is_ssl() ) { |
1703 | 1703 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
1704 | 1704 | } |
1705 | 1705 | |
1706 | - // Add the invoice key. |
|
1707 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1706 | + // Add the invoice key. |
|
1707 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
1708 | 1708 | |
1709 | - // (Maybe?) add a secret |
|
1709 | + // (Maybe?) add a secret |
|
1710 | 1710 | if ( $secret ) { |
1711 | 1711 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
1712 | 1712 | } |
@@ -1715,18 +1715,18 @@ discard block |
||
1715 | 1715 | } |
1716 | 1716 | |
1717 | 1717 | /** |
1718 | - * Magic method for accessing invoice properties. |
|
1719 | - * |
|
1720 | - * @since 1.0.15 |
|
1721 | - * @access public |
|
1722 | - * |
|
1723 | - * @param string $key Discount data to retrieve |
|
1724 | - * @param string $context View or edit context. |
|
1725 | - * @return mixed Value of the given invoice property (if set). |
|
1726 | - */ |
|
1727 | - public function get( $key, $context = 'view' ) { |
|
1718 | + * Magic method for accessing invoice properties. |
|
1719 | + * |
|
1720 | + * @since 1.0.15 |
|
1721 | + * @access public |
|
1722 | + * |
|
1723 | + * @param string $key Discount data to retrieve |
|
1724 | + * @param string $context View or edit context. |
|
1725 | + * @return mixed Value of the given invoice property (if set). |
|
1726 | + */ |
|
1727 | + public function get( $key, $context = 'view' ) { |
|
1728 | 1728 | return $this->get_prop( $key, $context ); |
1729 | - } |
|
1729 | + } |
|
1730 | 1730 | |
1731 | 1731 | /* |
1732 | 1732 | |-------------------------------------------------------------------------- |
@@ -1739,118 +1739,118 @@ discard block |
||
1739 | 1739 | */ |
1740 | 1740 | |
1741 | 1741 | /** |
1742 | - * Magic method for setting invoice properties. |
|
1743 | - * |
|
1744 | - * @since 1.0.19 |
|
1745 | - * @access public |
|
1746 | - * |
|
1747 | - * @param string $key Discount data to retrieve |
|
1748 | - * @param mixed $value new value. |
|
1749 | - * @return mixed Value of the given invoice property (if set). |
|
1750 | - */ |
|
1751 | - public function set( $key, $value ) { |
|
1742 | + * Magic method for setting invoice properties. |
|
1743 | + * |
|
1744 | + * @since 1.0.19 |
|
1745 | + * @access public |
|
1746 | + * |
|
1747 | + * @param string $key Discount data to retrieve |
|
1748 | + * @param mixed $value new value. |
|
1749 | + * @return mixed Value of the given invoice property (if set). |
|
1750 | + */ |
|
1751 | + public function set( $key, $value ) { |
|
1752 | 1752 | |
1753 | 1753 | $setter = "set_$key"; |
1754 | 1754 | if ( is_callable( array( $this, $setter ) ) ) { |
1755 | 1755 | $this->{$setter}( $value ); |
1756 | 1756 | } |
1757 | 1757 | |
1758 | - } |
|
1759 | - |
|
1760 | - /** |
|
1761 | - * Sets item status. |
|
1762 | - * |
|
1763 | - * @since 1.0.19 |
|
1764 | - * @param string $new_status New status. |
|
1765 | - * @param string $note Optional note to add. |
|
1766 | - * @param bool $manual_update Is this a manual status change?. |
|
1767 | - * @return array details of change. |
|
1768 | - */ |
|
1769 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
1770 | - $old_status = $this->get_status(); |
|
1771 | - |
|
1772 | - $this->set_prop( 'status', $new_status ); |
|
1773 | - |
|
1774 | - // If setting the status, ensure it's set to a valid status. |
|
1775 | - if ( true === $this->object_read ) { |
|
1776 | - |
|
1777 | - // Only allow valid new status. |
|
1778 | - if ( ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) { |
|
1779 | - $new_status = 'wpi-pending'; |
|
1780 | - } |
|
1781 | - |
|
1782 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
1783 | - if ( $old_status && ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) { |
|
1784 | - $old_status = 'wpi-pending'; |
|
1785 | - } |
|
1786 | - } |
|
1787 | - |
|
1788 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
1789 | - $this->status_transition = array( |
|
1790 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
1791 | - 'to' => $new_status, |
|
1792 | - 'note' => $note, |
|
1793 | - 'manual' => (bool) $manual_update, |
|
1794 | - ); |
|
1795 | - |
|
1796 | - if ( $manual_update ) { |
|
1797 | - do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
1798 | - } |
|
1799 | - |
|
1800 | - $this->maybe_set_date_paid(); |
|
1801 | - |
|
1802 | - } |
|
1803 | - |
|
1804 | - return array( |
|
1805 | - 'from' => $old_status, |
|
1806 | - 'to' => $new_status, |
|
1807 | - ); |
|
1808 | - } |
|
1809 | - |
|
1810 | - /** |
|
1811 | - * Maybe set date paid. |
|
1812 | - * |
|
1813 | - * Sets the date paid variable when transitioning to the payment complete |
|
1814 | - * order status. |
|
1815 | - * |
|
1816 | - * @since 1.0.19 |
|
1817 | - */ |
|
1818 | - public function maybe_set_date_paid() { |
|
1819 | - |
|
1820 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
1821 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
1822 | - } |
|
1823 | - } |
|
1824 | - |
|
1825 | - /** |
|
1826 | - * Set parent invoice ID. |
|
1827 | - * |
|
1828 | - * @since 1.0.19 |
|
1829 | - */ |
|
1830 | - public function set_parent_id( $value ) { |
|
1831 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
1832 | - return; |
|
1833 | - } |
|
1834 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
1835 | - } |
|
1836 | - |
|
1837 | - /** |
|
1838 | - * Set plugin version when the invoice was created. |
|
1839 | - * |
|
1840 | - * @since 1.0.19 |
|
1841 | - */ |
|
1842 | - public function set_version( $value ) { |
|
1843 | - $this->set_prop( 'version', $value ); |
|
1844 | - } |
|
1845 | - |
|
1846 | - /** |
|
1847 | - * Set date when the invoice was created. |
|
1848 | - * |
|
1849 | - * @since 1.0.19 |
|
1850 | - * @param string $value Value to set. |
|
1758 | + } |
|
1759 | + |
|
1760 | + /** |
|
1761 | + * Sets item status. |
|
1762 | + * |
|
1763 | + * @since 1.0.19 |
|
1764 | + * @param string $new_status New status. |
|
1765 | + * @param string $note Optional note to add. |
|
1766 | + * @param bool $manual_update Is this a manual status change?. |
|
1767 | + * @return array details of change. |
|
1768 | + */ |
|
1769 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
1770 | + $old_status = $this->get_status(); |
|
1771 | + |
|
1772 | + $this->set_prop( 'status', $new_status ); |
|
1773 | + |
|
1774 | + // If setting the status, ensure it's set to a valid status. |
|
1775 | + if ( true === $this->object_read ) { |
|
1776 | + |
|
1777 | + // Only allow valid new status. |
|
1778 | + if ( ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) { |
|
1779 | + $new_status = 'wpi-pending'; |
|
1780 | + } |
|
1781 | + |
|
1782 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
1783 | + if ( $old_status && ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) { |
|
1784 | + $old_status = 'wpi-pending'; |
|
1785 | + } |
|
1786 | + } |
|
1787 | + |
|
1788 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
1789 | + $this->status_transition = array( |
|
1790 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
1791 | + 'to' => $new_status, |
|
1792 | + 'note' => $note, |
|
1793 | + 'manual' => (bool) $manual_update, |
|
1794 | + ); |
|
1795 | + |
|
1796 | + if ( $manual_update ) { |
|
1797 | + do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
1798 | + } |
|
1799 | + |
|
1800 | + $this->maybe_set_date_paid(); |
|
1801 | + |
|
1802 | + } |
|
1803 | + |
|
1804 | + return array( |
|
1805 | + 'from' => $old_status, |
|
1806 | + 'to' => $new_status, |
|
1807 | + ); |
|
1808 | + } |
|
1809 | + |
|
1810 | + /** |
|
1811 | + * Maybe set date paid. |
|
1812 | + * |
|
1813 | + * Sets the date paid variable when transitioning to the payment complete |
|
1814 | + * order status. |
|
1815 | + * |
|
1816 | + * @since 1.0.19 |
|
1817 | + */ |
|
1818 | + public function maybe_set_date_paid() { |
|
1819 | + |
|
1820 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
1821 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
1822 | + } |
|
1823 | + } |
|
1824 | + |
|
1825 | + /** |
|
1826 | + * Set parent invoice ID. |
|
1827 | + * |
|
1828 | + * @since 1.0.19 |
|
1829 | + */ |
|
1830 | + public function set_parent_id( $value ) { |
|
1831 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
1832 | + return; |
|
1833 | + } |
|
1834 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
1835 | + } |
|
1836 | + |
|
1837 | + /** |
|
1838 | + * Set plugin version when the invoice was created. |
|
1839 | + * |
|
1840 | + * @since 1.0.19 |
|
1841 | + */ |
|
1842 | + public function set_version( $value ) { |
|
1843 | + $this->set_prop( 'version', $value ); |
|
1844 | + } |
|
1845 | + |
|
1846 | + /** |
|
1847 | + * Set date when the invoice was created. |
|
1848 | + * |
|
1849 | + * @since 1.0.19 |
|
1850 | + * @param string $value Value to set. |
|
1851 | 1851 | * @return bool Whether or not the date was set. |
1852 | - */ |
|
1853 | - public function set_date_created( $value ) { |
|
1852 | + */ |
|
1853 | + public function set_date_created( $value ) { |
|
1854 | 1854 | $date = strtotime( $value ); |
1855 | 1855 | |
1856 | 1856 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1863,13 +1863,13 @@ discard block |
||
1863 | 1863 | } |
1864 | 1864 | |
1865 | 1865 | /** |
1866 | - * Set date invoice due date. |
|
1867 | - * |
|
1868 | - * @since 1.0.19 |
|
1869 | - * @param string $value Value to set. |
|
1866 | + * Set date invoice due date. |
|
1867 | + * |
|
1868 | + * @since 1.0.19 |
|
1869 | + * @param string $value Value to set. |
|
1870 | 1870 | * @return bool Whether or not the date was set. |
1871 | - */ |
|
1872 | - public function set_due_date( $value ) { |
|
1871 | + */ |
|
1872 | + public function set_due_date( $value ) { |
|
1873 | 1873 | $date = strtotime( $value ); |
1874 | 1874 | |
1875 | 1875 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1877,29 +1877,29 @@ discard block |
||
1877 | 1877 | return true; |
1878 | 1878 | } |
1879 | 1879 | |
1880 | - $this->set_prop( 'due_date', '' ); |
|
1880 | + $this->set_prop( 'due_date', '' ); |
|
1881 | 1881 | return false; |
1882 | 1882 | |
1883 | 1883 | } |
1884 | 1884 | |
1885 | 1885 | /** |
1886 | - * Alias of self::set_due_date(). |
|
1887 | - * |
|
1888 | - * @since 1.0.19 |
|
1889 | - * @param string $value New name. |
|
1890 | - */ |
|
1891 | - public function set_date_due( $value ) { |
|
1892 | - $this->set_due_date( $value ); |
|
1886 | + * Alias of self::set_due_date(). |
|
1887 | + * |
|
1888 | + * @since 1.0.19 |
|
1889 | + * @param string $value New name. |
|
1890 | + */ |
|
1891 | + public function set_date_due( $value ) { |
|
1892 | + $this->set_due_date( $value ); |
|
1893 | 1893 | } |
1894 | 1894 | |
1895 | 1895 | /** |
1896 | - * Set date invoice was completed. |
|
1897 | - * |
|
1898 | - * @since 1.0.19 |
|
1899 | - * @param string $value Value to set. |
|
1896 | + * Set date invoice was completed. |
|
1897 | + * |
|
1898 | + * @since 1.0.19 |
|
1899 | + * @param string $value Value to set. |
|
1900 | 1900 | * @return bool Whether or not the date was set. |
1901 | - */ |
|
1902 | - public function set_completed_date( $value ) { |
|
1901 | + */ |
|
1902 | + public function set_completed_date( $value ) { |
|
1903 | 1903 | $date = strtotime( $value ); |
1904 | 1904 | |
1905 | 1905 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1907,29 +1907,29 @@ discard block |
||
1907 | 1907 | return true; |
1908 | 1908 | } |
1909 | 1909 | |
1910 | - $this->set_prop( 'completed_date', '' ); |
|
1910 | + $this->set_prop( 'completed_date', '' ); |
|
1911 | 1911 | return false; |
1912 | 1912 | |
1913 | 1913 | } |
1914 | 1914 | |
1915 | 1915 | /** |
1916 | - * Alias of self::set_completed_date(). |
|
1917 | - * |
|
1918 | - * @since 1.0.19 |
|
1919 | - * @param string $value New name. |
|
1920 | - */ |
|
1921 | - public function set_date_completed( $value ) { |
|
1922 | - $this->set_completed_date( $value ); |
|
1916 | + * Alias of self::set_completed_date(). |
|
1917 | + * |
|
1918 | + * @since 1.0.19 |
|
1919 | + * @param string $value New name. |
|
1920 | + */ |
|
1921 | + public function set_date_completed( $value ) { |
|
1922 | + $this->set_completed_date( $value ); |
|
1923 | 1923 | } |
1924 | 1924 | |
1925 | 1925 | /** |
1926 | - * Set date when the invoice was last modified. |
|
1927 | - * |
|
1928 | - * @since 1.0.19 |
|
1929 | - * @param string $value Value to set. |
|
1926 | + * Set date when the invoice was last modified. |
|
1927 | + * |
|
1928 | + * @since 1.0.19 |
|
1929 | + * @param string $value Value to set. |
|
1930 | 1930 | * @return bool Whether or not the date was set. |
1931 | - */ |
|
1932 | - public function set_date_modified( $value ) { |
|
1931 | + */ |
|
1932 | + public function set_date_modified( $value ) { |
|
1933 | 1933 | $date = strtotime( $value ); |
1934 | 1934 | |
1935 | 1935 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -1937,706 +1937,706 @@ discard block |
||
1937 | 1937 | return true; |
1938 | 1938 | } |
1939 | 1939 | |
1940 | - $this->set_prop( 'date_modified', '' ); |
|
1940 | + $this->set_prop( 'date_modified', '' ); |
|
1941 | 1941 | return false; |
1942 | 1942 | |
1943 | 1943 | } |
1944 | 1944 | |
1945 | 1945 | /** |
1946 | - * Set the invoice number. |
|
1947 | - * |
|
1948 | - * @since 1.0.19 |
|
1949 | - * @param string $value New number. |
|
1950 | - */ |
|
1951 | - public function set_number( $value ) { |
|
1946 | + * Set the invoice number. |
|
1947 | + * |
|
1948 | + * @since 1.0.19 |
|
1949 | + * @param string $value New number. |
|
1950 | + */ |
|
1951 | + public function set_number( $value ) { |
|
1952 | 1952 | $number = sanitize_text_field( $value ); |
1953 | - $this->set_prop( 'number', $number ); |
|
1953 | + $this->set_prop( 'number', $number ); |
|
1954 | 1954 | } |
1955 | 1955 | |
1956 | 1956 | /** |
1957 | - * Set the invoice type. |
|
1958 | - * |
|
1959 | - * @since 1.0.19 |
|
1960 | - * @param string $value Type. |
|
1961 | - */ |
|
1962 | - public function set_type( $value ) { |
|
1957 | + * Set the invoice type. |
|
1958 | + * |
|
1959 | + * @since 1.0.19 |
|
1960 | + * @param string $value Type. |
|
1961 | + */ |
|
1962 | + public function set_type( $value ) { |
|
1963 | 1963 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
1964 | - $this->set_prop( 'type', $type ); |
|
1965 | - } |
|
1964 | + $this->set_prop( 'type', $type ); |
|
1965 | + } |
|
1966 | 1966 | |
1967 | 1967 | /** |
1968 | - * Set the invoice post type. |
|
1969 | - * |
|
1970 | - * @since 1.0.19 |
|
1971 | - * @param string $value Post type. |
|
1972 | - */ |
|
1973 | - public function set_post_type( $value ) { |
|
1968 | + * Set the invoice post type. |
|
1969 | + * |
|
1970 | + * @since 1.0.19 |
|
1971 | + * @param string $value Post type. |
|
1972 | + */ |
|
1973 | + public function set_post_type( $value ) { |
|
1974 | 1974 | if ( getpaid_is_invoice_post_type( $value ) ) { |
1975 | - $this->set_type( $value ); |
|
1975 | + $this->set_type( $value ); |
|
1976 | 1976 | $this->set_prop( 'post_type', $value ); |
1977 | 1977 | } |
1978 | 1978 | } |
1979 | 1979 | |
1980 | 1980 | /** |
1981 | - * Set the invoice key. |
|
1982 | - * |
|
1983 | - * @since 1.0.19 |
|
1984 | - * @param string $value New key. |
|
1985 | - */ |
|
1986 | - public function set_key( $value ) { |
|
1981 | + * Set the invoice key. |
|
1982 | + * |
|
1983 | + * @since 1.0.19 |
|
1984 | + * @param string $value New key. |
|
1985 | + */ |
|
1986 | + public function set_key( $value ) { |
|
1987 | 1987 | $key = sanitize_text_field( $value ); |
1988 | - $this->set_prop( 'key', $key ); |
|
1988 | + $this->set_prop( 'key', $key ); |
|
1989 | 1989 | } |
1990 | 1990 | |
1991 | 1991 | /** |
1992 | - * Set the invoice mode. |
|
1993 | - * |
|
1994 | - * @since 1.0.19 |
|
1995 | - * @param string $value mode. |
|
1996 | - */ |
|
1997 | - public function set_mode( $value ) { |
|
1992 | + * Set the invoice mode. |
|
1993 | + * |
|
1994 | + * @since 1.0.19 |
|
1995 | + * @param string $value mode. |
|
1996 | + */ |
|
1997 | + public function set_mode( $value ) { |
|
1998 | 1998 | if ( ! in_array( $value, array( 'live', 'test' ) ) ) { |
1999 | 1999 | $this->set_prop( 'value', $value ); |
2000 | 2000 | } |
2001 | 2001 | } |
2002 | 2002 | |
2003 | 2003 | /** |
2004 | - * Set the invoice path. |
|
2005 | - * |
|
2006 | - * @since 1.0.19 |
|
2007 | - * @param string $value path. |
|
2008 | - */ |
|
2009 | - public function set_path( $value ) { |
|
2004 | + * Set the invoice path. |
|
2005 | + * |
|
2006 | + * @since 1.0.19 |
|
2007 | + * @param string $value path. |
|
2008 | + */ |
|
2009 | + public function set_path( $value ) { |
|
2010 | 2010 | $this->set_prop( 'path', $value ); |
2011 | 2011 | } |
2012 | 2012 | |
2013 | 2013 | /** |
2014 | - * Set the invoice name. |
|
2015 | - * |
|
2016 | - * @since 1.0.19 |
|
2017 | - * @param string $value New name. |
|
2018 | - */ |
|
2019 | - public function set_name( $value ) { |
|
2014 | + * Set the invoice name. |
|
2015 | + * |
|
2016 | + * @since 1.0.19 |
|
2017 | + * @param string $value New name. |
|
2018 | + */ |
|
2019 | + public function set_name( $value ) { |
|
2020 | 2020 | $name = sanitize_text_field( $value ); |
2021 | - $this->set_prop( 'name', $name ); |
|
2021 | + $this->set_prop( 'name', $name ); |
|
2022 | 2022 | } |
2023 | 2023 | |
2024 | 2024 | /** |
2025 | - * Alias of self::set_name(). |
|
2026 | - * |
|
2027 | - * @since 1.0.19 |
|
2028 | - * @param string $value New name. |
|
2029 | - */ |
|
2030 | - public function set_title( $value ) { |
|
2031 | - $this->set_name( $value ); |
|
2025 | + * Alias of self::set_name(). |
|
2026 | + * |
|
2027 | + * @since 1.0.19 |
|
2028 | + * @param string $value New name. |
|
2029 | + */ |
|
2030 | + public function set_title( $value ) { |
|
2031 | + $this->set_name( $value ); |
|
2032 | 2032 | } |
2033 | 2033 | |
2034 | 2034 | /** |
2035 | - * Set the invoice description. |
|
2036 | - * |
|
2037 | - * @since 1.0.19 |
|
2038 | - * @param string $value New description. |
|
2039 | - */ |
|
2040 | - public function set_description( $value ) { |
|
2035 | + * Set the invoice description. |
|
2036 | + * |
|
2037 | + * @since 1.0.19 |
|
2038 | + * @param string $value New description. |
|
2039 | + */ |
|
2040 | + public function set_description( $value ) { |
|
2041 | 2041 | $description = wp_kses_post( $value ); |
2042 | - return $this->set_prop( 'description', $description ); |
|
2042 | + return $this->set_prop( 'description', $description ); |
|
2043 | + } |
|
2044 | + |
|
2045 | + /** |
|
2046 | + * Alias of self::set_description(). |
|
2047 | + * |
|
2048 | + * @since 1.0.19 |
|
2049 | + * @param string $value New description. |
|
2050 | + */ |
|
2051 | + public function set_excerpt( $value ) { |
|
2052 | + $this->set_description( $value ); |
|
2053 | + } |
|
2054 | + |
|
2055 | + /** |
|
2056 | + * Alias of self::set_description(). |
|
2057 | + * |
|
2058 | + * @since 1.0.19 |
|
2059 | + * @param string $value New description. |
|
2060 | + */ |
|
2061 | + public function set_summary( $value ) { |
|
2062 | + $this->set_description( $value ); |
|
2063 | + } |
|
2064 | + |
|
2065 | + /** |
|
2066 | + * Set the receiver of the invoice. |
|
2067 | + * |
|
2068 | + * @since 1.0.19 |
|
2069 | + * @param int $value New author. |
|
2070 | + */ |
|
2071 | + public function set_author( $value ) { |
|
2072 | + $user = get_user_by( 'id', (int) $value ); |
|
2073 | + |
|
2074 | + if ( $user && $user->ID ) { |
|
2075 | + $this->set_prop( 'author', $user->ID ); |
|
2076 | + $this->set_prop( 'email', $user->user_email ); |
|
2077 | + } |
|
2078 | + |
|
2043 | 2079 | } |
2044 | 2080 | |
2045 | 2081 | /** |
2046 | - * Alias of self::set_description(). |
|
2047 | - * |
|
2048 | - * @since 1.0.19 |
|
2049 | - * @param string $value New description. |
|
2050 | - */ |
|
2051 | - public function set_excerpt( $value ) { |
|
2052 | - $this->set_description( $value ); |
|
2082 | + * Alias of self::set_author(). |
|
2083 | + * |
|
2084 | + * @since 1.0.19 |
|
2085 | + * @param int $value New user id. |
|
2086 | + */ |
|
2087 | + public function set_user_id( $value ) { |
|
2088 | + $this->set_author( $value ); |
|
2053 | 2089 | } |
2054 | 2090 | |
2055 | 2091 | /** |
2056 | - * Alias of self::set_description(). |
|
2057 | - * |
|
2058 | - * @since 1.0.19 |
|
2059 | - * @param string $value New description. |
|
2060 | - */ |
|
2061 | - public function set_summary( $value ) { |
|
2062 | - $this->set_description( $value ); |
|
2092 | + * Alias of self::set_author(). |
|
2093 | + * |
|
2094 | + * @since 1.0.19 |
|
2095 | + * @param int $value New user id. |
|
2096 | + */ |
|
2097 | + public function set_customer_id( $value ) { |
|
2098 | + $this->set_author( $value ); |
|
2063 | 2099 | } |
2064 | 2100 | |
2065 | 2101 | /** |
2066 | - * Set the receiver of the invoice. |
|
2067 | - * |
|
2068 | - * @since 1.0.19 |
|
2069 | - * @param int $value New author. |
|
2070 | - */ |
|
2071 | - public function set_author( $value ) { |
|
2072 | - $user = get_user_by( 'id', (int) $value ); |
|
2073 | - |
|
2074 | - if ( $user && $user->ID ) { |
|
2075 | - $this->set_prop( 'author', $user->ID ); |
|
2076 | - $this->set_prop( 'email', $user->user_email ); |
|
2077 | - } |
|
2078 | - |
|
2102 | + * Set the customer's ip. |
|
2103 | + * |
|
2104 | + * @since 1.0.19 |
|
2105 | + * @param string $value ip address. |
|
2106 | + */ |
|
2107 | + public function set_ip( $value ) { |
|
2108 | + $this->set_prop( 'ip', $value ); |
|
2079 | 2109 | } |
2080 | 2110 | |
2081 | 2111 | /** |
2082 | - * Alias of self::set_author(). |
|
2083 | - * |
|
2084 | - * @since 1.0.19 |
|
2085 | - * @param int $value New user id. |
|
2086 | - */ |
|
2087 | - public function set_user_id( $value ) { |
|
2088 | - $this->set_author( $value ); |
|
2112 | + * Alias of self::set_ip(). |
|
2113 | + * |
|
2114 | + * @since 1.0.19 |
|
2115 | + * @param string $value ip address. |
|
2116 | + */ |
|
2117 | + public function set_user_ip( $value ) { |
|
2118 | + $this->set_ip( $value ); |
|
2089 | 2119 | } |
2090 | 2120 | |
2091 | 2121 | /** |
2092 | - * Alias of self::set_author(). |
|
2093 | - * |
|
2094 | - * @since 1.0.19 |
|
2095 | - * @param int $value New user id. |
|
2096 | - */ |
|
2097 | - public function set_customer_id( $value ) { |
|
2098 | - $this->set_author( $value ); |
|
2122 | + * Set the customer's first name. |
|
2123 | + * |
|
2124 | + * @since 1.0.19 |
|
2125 | + * @param string $value first name. |
|
2126 | + */ |
|
2127 | + public function set_first_name( $value ) { |
|
2128 | + $this->set_prop( 'first_name', $value ); |
|
2099 | 2129 | } |
2100 | 2130 | |
2101 | 2131 | /** |
2102 | - * Set the customer's ip. |
|
2103 | - * |
|
2104 | - * @since 1.0.19 |
|
2105 | - * @param string $value ip address. |
|
2106 | - */ |
|
2107 | - public function set_ip( $value ) { |
|
2108 | - $this->set_prop( 'ip', $value ); |
|
2132 | + * Alias of self::set_first_name(). |
|
2133 | + * |
|
2134 | + * @since 1.0.19 |
|
2135 | + * @param string $value first name. |
|
2136 | + */ |
|
2137 | + public function set_user_first_name( $value ) { |
|
2138 | + $this->set_first_name( $value ); |
|
2109 | 2139 | } |
2110 | 2140 | |
2111 | 2141 | /** |
2112 | - * Alias of self::set_ip(). |
|
2113 | - * |
|
2114 | - * @since 1.0.19 |
|
2115 | - * @param string $value ip address. |
|
2116 | - */ |
|
2117 | - public function set_user_ip( $value ) { |
|
2118 | - $this->set_ip( $value ); |
|
2142 | + * Alias of self::set_first_name(). |
|
2143 | + * |
|
2144 | + * @since 1.0.19 |
|
2145 | + * @param string $value first name. |
|
2146 | + */ |
|
2147 | + public function set_customer_first_name( $value ) { |
|
2148 | + $this->set_first_name( $value ); |
|
2119 | 2149 | } |
2120 | 2150 | |
2121 | 2151 | /** |
2122 | - * Set the customer's first name. |
|
2123 | - * |
|
2124 | - * @since 1.0.19 |
|
2125 | - * @param string $value first name. |
|
2126 | - */ |
|
2127 | - public function set_first_name( $value ) { |
|
2128 | - $this->set_prop( 'first_name', $value ); |
|
2152 | + * Set the customer's last name. |
|
2153 | + * |
|
2154 | + * @since 1.0.19 |
|
2155 | + * @param string $value last name. |
|
2156 | + */ |
|
2157 | + public function set_last_name( $value ) { |
|
2158 | + $this->set_prop( 'last_name', $value ); |
|
2129 | 2159 | } |
2130 | 2160 | |
2131 | 2161 | /** |
2132 | - * Alias of self::set_first_name(). |
|
2133 | - * |
|
2134 | - * @since 1.0.19 |
|
2135 | - * @param string $value first name. |
|
2136 | - */ |
|
2137 | - public function set_user_first_name( $value ) { |
|
2138 | - $this->set_first_name( $value ); |
|
2162 | + * Alias of self::set_last_name(). |
|
2163 | + * |
|
2164 | + * @since 1.0.19 |
|
2165 | + * @param string $value last name. |
|
2166 | + */ |
|
2167 | + public function set_user_last_name( $value ) { |
|
2168 | + $this->set_last_name( $value ); |
|
2139 | 2169 | } |
2140 | 2170 | |
2141 | 2171 | /** |
2142 | - * Alias of self::set_first_name(). |
|
2143 | - * |
|
2144 | - * @since 1.0.19 |
|
2145 | - * @param string $value first name. |
|
2146 | - */ |
|
2147 | - public function set_customer_first_name( $value ) { |
|
2148 | - $this->set_first_name( $value ); |
|
2172 | + * Alias of self::set_last_name(). |
|
2173 | + * |
|
2174 | + * @since 1.0.19 |
|
2175 | + * @param string $value last name. |
|
2176 | + */ |
|
2177 | + public function set_customer_last_name( $value ) { |
|
2178 | + $this->set_last_name( $value ); |
|
2149 | 2179 | } |
2150 | 2180 | |
2151 | 2181 | /** |
2152 | - * Set the customer's last name. |
|
2153 | - * |
|
2154 | - * @since 1.0.19 |
|
2155 | - * @param string $value last name. |
|
2156 | - */ |
|
2157 | - public function set_last_name( $value ) { |
|
2158 | - $this->set_prop( 'last_name', $value ); |
|
2182 | + * Set the customer's phone number. |
|
2183 | + * |
|
2184 | + * @since 1.0.19 |
|
2185 | + * @param string $value phone. |
|
2186 | + */ |
|
2187 | + public function set_phone( $value ) { |
|
2188 | + $this->set_prop( 'phone', $value ); |
|
2159 | 2189 | } |
2160 | 2190 | |
2161 | 2191 | /** |
2162 | - * Alias of self::set_last_name(). |
|
2163 | - * |
|
2164 | - * @since 1.0.19 |
|
2165 | - * @param string $value last name. |
|
2166 | - */ |
|
2167 | - public function set_user_last_name( $value ) { |
|
2168 | - $this->set_last_name( $value ); |
|
2192 | + * Alias of self::set_phone(). |
|
2193 | + * |
|
2194 | + * @since 1.0.19 |
|
2195 | + * @param string $value phone. |
|
2196 | + */ |
|
2197 | + public function set_user_phone( $value ) { |
|
2198 | + $this->set_phone( $value ); |
|
2169 | 2199 | } |
2170 | 2200 | |
2171 | 2201 | /** |
2172 | - * Alias of self::set_last_name(). |
|
2173 | - * |
|
2174 | - * @since 1.0.19 |
|
2175 | - * @param string $value last name. |
|
2176 | - */ |
|
2177 | - public function set_customer_last_name( $value ) { |
|
2178 | - $this->set_last_name( $value ); |
|
2202 | + * Alias of self::set_phone(). |
|
2203 | + * |
|
2204 | + * @since 1.0.19 |
|
2205 | + * @param string $value phone. |
|
2206 | + */ |
|
2207 | + public function set_customer_phone( $value ) { |
|
2208 | + $this->set_phone( $value ); |
|
2179 | 2209 | } |
2180 | 2210 | |
2181 | 2211 | /** |
2182 | - * Set the customer's phone number. |
|
2183 | - * |
|
2184 | - * @since 1.0.19 |
|
2185 | - * @param string $value phone. |
|
2186 | - */ |
|
2187 | - public function set_phone( $value ) { |
|
2188 | - $this->set_prop( 'phone', $value ); |
|
2212 | + * Alias of self::set_phone(). |
|
2213 | + * |
|
2214 | + * @since 1.0.19 |
|
2215 | + * @param string $value phone. |
|
2216 | + */ |
|
2217 | + public function set_phone_number( $value ) { |
|
2218 | + $this->set_phone( $value ); |
|
2189 | 2219 | } |
2190 | 2220 | |
2191 | 2221 | /** |
2192 | - * Alias of self::set_phone(). |
|
2193 | - * |
|
2194 | - * @since 1.0.19 |
|
2195 | - * @param string $value phone. |
|
2196 | - */ |
|
2197 | - public function set_user_phone( $value ) { |
|
2198 | - $this->set_phone( $value ); |
|
2222 | + * Set the customer's email address. |
|
2223 | + * |
|
2224 | + * @since 1.0.19 |
|
2225 | + * @param string $value email address. |
|
2226 | + */ |
|
2227 | + public function set_email( $value ) { |
|
2228 | + $this->set_prop( 'email', $value ); |
|
2199 | 2229 | } |
2200 | 2230 | |
2201 | 2231 | /** |
2202 | - * Alias of self::set_phone(). |
|
2203 | - * |
|
2204 | - * @since 1.0.19 |
|
2205 | - * @param string $value phone. |
|
2206 | - */ |
|
2207 | - public function set_customer_phone( $value ) { |
|
2208 | - $this->set_phone( $value ); |
|
2232 | + * Alias of self::set_email(). |
|
2233 | + * |
|
2234 | + * @since 1.0.19 |
|
2235 | + * @param string $value email address. |
|
2236 | + */ |
|
2237 | + public function set_user_email( $value ) { |
|
2238 | + $this->set_email( $value ); |
|
2209 | 2239 | } |
2210 | 2240 | |
2211 | 2241 | /** |
2212 | - * Alias of self::set_phone(). |
|
2213 | - * |
|
2214 | - * @since 1.0.19 |
|
2215 | - * @param string $value phone. |
|
2216 | - */ |
|
2217 | - public function set_phone_number( $value ) { |
|
2218 | - $this->set_phone( $value ); |
|
2242 | + * Alias of self::set_email(). |
|
2243 | + * |
|
2244 | + * @since 1.0.19 |
|
2245 | + * @param string $value email address. |
|
2246 | + */ |
|
2247 | + public function set_email_address( $value ) { |
|
2248 | + $this->set_email( $value ); |
|
2219 | 2249 | } |
2220 | 2250 | |
2221 | 2251 | /** |
2222 | - * Set the customer's email address. |
|
2223 | - * |
|
2224 | - * @since 1.0.19 |
|
2225 | - * @param string $value email address. |
|
2226 | - */ |
|
2227 | - public function set_email( $value ) { |
|
2228 | - $this->set_prop( 'email', $value ); |
|
2252 | + * Alias of self::set_email(). |
|
2253 | + * |
|
2254 | + * @since 1.0.19 |
|
2255 | + * @param string $value email address. |
|
2256 | + */ |
|
2257 | + public function set_customer_email( $value ) { |
|
2258 | + $this->set_email( $value ); |
|
2229 | 2259 | } |
2230 | 2260 | |
2231 | 2261 | /** |
2232 | - * Alias of self::set_email(). |
|
2233 | - * |
|
2234 | - * @since 1.0.19 |
|
2235 | - * @param string $value email address. |
|
2236 | - */ |
|
2237 | - public function set_user_email( $value ) { |
|
2238 | - $this->set_email( $value ); |
|
2262 | + * Set the customer's country. |
|
2263 | + * |
|
2264 | + * @since 1.0.19 |
|
2265 | + * @param string $value country. |
|
2266 | + */ |
|
2267 | + public function set_country( $value ) { |
|
2268 | + $this->set_prop( 'country', $value ); |
|
2239 | 2269 | } |
2240 | 2270 | |
2241 | 2271 | /** |
2242 | - * Alias of self::set_email(). |
|
2243 | - * |
|
2244 | - * @since 1.0.19 |
|
2245 | - * @param string $value email address. |
|
2246 | - */ |
|
2247 | - public function set_email_address( $value ) { |
|
2248 | - $this->set_email( $value ); |
|
2272 | + * Alias of self::set_country(). |
|
2273 | + * |
|
2274 | + * @since 1.0.19 |
|
2275 | + * @param string $value country. |
|
2276 | + */ |
|
2277 | + public function set_user_country( $value ) { |
|
2278 | + $this->set_country( $value ); |
|
2249 | 2279 | } |
2250 | 2280 | |
2251 | 2281 | /** |
2252 | - * Alias of self::set_email(). |
|
2253 | - * |
|
2254 | - * @since 1.0.19 |
|
2255 | - * @param string $value email address. |
|
2256 | - */ |
|
2257 | - public function set_customer_email( $value ) { |
|
2258 | - $this->set_email( $value ); |
|
2282 | + * Alias of self::set_country(). |
|
2283 | + * |
|
2284 | + * @since 1.0.19 |
|
2285 | + * @param string $value country. |
|
2286 | + */ |
|
2287 | + public function set_customer_country( $value ) { |
|
2288 | + $this->set_country( $value ); |
|
2259 | 2289 | } |
2260 | 2290 | |
2261 | 2291 | /** |
2262 | - * Set the customer's country. |
|
2263 | - * |
|
2264 | - * @since 1.0.19 |
|
2265 | - * @param string $value country. |
|
2266 | - */ |
|
2267 | - public function set_country( $value ) { |
|
2268 | - $this->set_prop( 'country', $value ); |
|
2292 | + * Set the customer's state. |
|
2293 | + * |
|
2294 | + * @since 1.0.19 |
|
2295 | + * @param string $value state. |
|
2296 | + */ |
|
2297 | + public function set_state( $value ) { |
|
2298 | + $this->set_prop( 'state', $value ); |
|
2269 | 2299 | } |
2270 | 2300 | |
2271 | 2301 | /** |
2272 | - * Alias of self::set_country(). |
|
2273 | - * |
|
2274 | - * @since 1.0.19 |
|
2275 | - * @param string $value country. |
|
2276 | - */ |
|
2277 | - public function set_user_country( $value ) { |
|
2278 | - $this->set_country( $value ); |
|
2302 | + * Alias of self::set_state(). |
|
2303 | + * |
|
2304 | + * @since 1.0.19 |
|
2305 | + * @param string $value state. |
|
2306 | + */ |
|
2307 | + public function set_user_state( $value ) { |
|
2308 | + $this->set_state( $value ); |
|
2279 | 2309 | } |
2280 | 2310 | |
2281 | 2311 | /** |
2282 | - * Alias of self::set_country(). |
|
2283 | - * |
|
2284 | - * @since 1.0.19 |
|
2285 | - * @param string $value country. |
|
2286 | - */ |
|
2287 | - public function set_customer_country( $value ) { |
|
2288 | - $this->set_country( $value ); |
|
2312 | + * Alias of self::set_state(). |
|
2313 | + * |
|
2314 | + * @since 1.0.19 |
|
2315 | + * @param string $value state. |
|
2316 | + */ |
|
2317 | + public function set_customer_state( $value ) { |
|
2318 | + $this->set_state( $value ); |
|
2289 | 2319 | } |
2290 | 2320 | |
2291 | 2321 | /** |
2292 | - * Set the customer's state. |
|
2293 | - * |
|
2294 | - * @since 1.0.19 |
|
2295 | - * @param string $value state. |
|
2296 | - */ |
|
2297 | - public function set_state( $value ) { |
|
2298 | - $this->set_prop( 'state', $value ); |
|
2322 | + * Set the customer's city. |
|
2323 | + * |
|
2324 | + * @since 1.0.19 |
|
2325 | + * @param string $value city. |
|
2326 | + */ |
|
2327 | + public function set_city( $value ) { |
|
2328 | + $this->set_prop( 'city', $value ); |
|
2299 | 2329 | } |
2300 | 2330 | |
2301 | 2331 | /** |
2302 | - * Alias of self::set_state(). |
|
2303 | - * |
|
2304 | - * @since 1.0.19 |
|
2305 | - * @param string $value state. |
|
2306 | - */ |
|
2307 | - public function set_user_state( $value ) { |
|
2308 | - $this->set_state( $value ); |
|
2332 | + * Alias of self::set_city(). |
|
2333 | + * |
|
2334 | + * @since 1.0.19 |
|
2335 | + * @param string $value city. |
|
2336 | + */ |
|
2337 | + public function set_user_city( $value ) { |
|
2338 | + $this->set_city( $value ); |
|
2309 | 2339 | } |
2310 | 2340 | |
2311 | 2341 | /** |
2312 | - * Alias of self::set_state(). |
|
2313 | - * |
|
2314 | - * @since 1.0.19 |
|
2315 | - * @param string $value state. |
|
2316 | - */ |
|
2317 | - public function set_customer_state( $value ) { |
|
2318 | - $this->set_state( $value ); |
|
2342 | + * Alias of self::set_city(). |
|
2343 | + * |
|
2344 | + * @since 1.0.19 |
|
2345 | + * @param string $value city. |
|
2346 | + */ |
|
2347 | + public function set_customer_city( $value ) { |
|
2348 | + $this->set_city( $value ); |
|
2319 | 2349 | } |
2320 | 2350 | |
2321 | 2351 | /** |
2322 | - * Set the customer's city. |
|
2323 | - * |
|
2324 | - * @since 1.0.19 |
|
2325 | - * @param string $value city. |
|
2326 | - */ |
|
2327 | - public function set_city( $value ) { |
|
2328 | - $this->set_prop( 'city', $value ); |
|
2352 | + * Set the customer's zip code. |
|
2353 | + * |
|
2354 | + * @since 1.0.19 |
|
2355 | + * @param string $value zip. |
|
2356 | + */ |
|
2357 | + public function set_zip( $value ) { |
|
2358 | + $this->set_prop( 'zip', $value ); |
|
2329 | 2359 | } |
2330 | 2360 | |
2331 | 2361 | /** |
2332 | - * Alias of self::set_city(). |
|
2333 | - * |
|
2334 | - * @since 1.0.19 |
|
2335 | - * @param string $value city. |
|
2336 | - */ |
|
2337 | - public function set_user_city( $value ) { |
|
2338 | - $this->set_city( $value ); |
|
2362 | + * Alias of self::set_zip(). |
|
2363 | + * |
|
2364 | + * @since 1.0.19 |
|
2365 | + * @param string $value zip. |
|
2366 | + */ |
|
2367 | + public function set_user_zip( $value ) { |
|
2368 | + $this->set_zip( $value ); |
|
2339 | 2369 | } |
2340 | 2370 | |
2341 | 2371 | /** |
2342 | - * Alias of self::set_city(). |
|
2343 | - * |
|
2344 | - * @since 1.0.19 |
|
2345 | - * @param string $value city. |
|
2346 | - */ |
|
2347 | - public function set_customer_city( $value ) { |
|
2348 | - $this->set_city( $value ); |
|
2372 | + * Alias of self::set_zip(). |
|
2373 | + * |
|
2374 | + * @since 1.0.19 |
|
2375 | + * @param string $value zip. |
|
2376 | + */ |
|
2377 | + public function set_customer_zip( $value ) { |
|
2378 | + $this->set_zip( $value ); |
|
2349 | 2379 | } |
2350 | 2380 | |
2351 | 2381 | /** |
2352 | - * Set the customer's zip code. |
|
2353 | - * |
|
2354 | - * @since 1.0.19 |
|
2355 | - * @param string $value zip. |
|
2356 | - */ |
|
2357 | - public function set_zip( $value ) { |
|
2358 | - $this->set_prop( 'zip', $value ); |
|
2382 | + * Set the customer's company. |
|
2383 | + * |
|
2384 | + * @since 1.0.19 |
|
2385 | + * @param string $value company. |
|
2386 | + */ |
|
2387 | + public function set_company( $value ) { |
|
2388 | + $this->set_prop( 'company', $value ); |
|
2359 | 2389 | } |
2360 | 2390 | |
2361 | 2391 | /** |
2362 | - * Alias of self::set_zip(). |
|
2363 | - * |
|
2364 | - * @since 1.0.19 |
|
2365 | - * @param string $value zip. |
|
2366 | - */ |
|
2367 | - public function set_user_zip( $value ) { |
|
2368 | - $this->set_zip( $value ); |
|
2392 | + * Alias of self::set_company(). |
|
2393 | + * |
|
2394 | + * @since 1.0.19 |
|
2395 | + * @param string $value company. |
|
2396 | + */ |
|
2397 | + public function set_user_company( $value ) { |
|
2398 | + $this->set_company( $value ); |
|
2369 | 2399 | } |
2370 | 2400 | |
2371 | 2401 | /** |
2372 | - * Alias of self::set_zip(). |
|
2373 | - * |
|
2374 | - * @since 1.0.19 |
|
2375 | - * @param string $value zip. |
|
2376 | - */ |
|
2377 | - public function set_customer_zip( $value ) { |
|
2378 | - $this->set_zip( $value ); |
|
2402 | + * Alias of self::set_company(). |
|
2403 | + * |
|
2404 | + * @since 1.0.19 |
|
2405 | + * @param string $value company. |
|
2406 | + */ |
|
2407 | + public function set_customer_company( $value ) { |
|
2408 | + $this->set_company( $value ); |
|
2379 | 2409 | } |
2380 | 2410 | |
2381 | 2411 | /** |
2382 | - * Set the customer's company. |
|
2383 | - * |
|
2384 | - * @since 1.0.19 |
|
2385 | - * @param string $value company. |
|
2386 | - */ |
|
2387 | - public function set_company( $value ) { |
|
2388 | - $this->set_prop( 'company', $value ); |
|
2412 | + * Set the customer's var number. |
|
2413 | + * |
|
2414 | + * @since 1.0.19 |
|
2415 | + * @param string $value var number. |
|
2416 | + */ |
|
2417 | + public function set_vat_number( $value ) { |
|
2418 | + $this->set_prop( 'vat_number', $value ); |
|
2389 | 2419 | } |
2390 | 2420 | |
2391 | 2421 | /** |
2392 | - * Alias of self::set_company(). |
|
2393 | - * |
|
2394 | - * @since 1.0.19 |
|
2395 | - * @param string $value company. |
|
2396 | - */ |
|
2397 | - public function set_user_company( $value ) { |
|
2398 | - $this->set_company( $value ); |
|
2422 | + * Alias of self::set_vat_number(). |
|
2423 | + * |
|
2424 | + * @since 1.0.19 |
|
2425 | + * @param string $value var number. |
|
2426 | + */ |
|
2427 | + public function set_user_vat_number( $value ) { |
|
2428 | + $this->set_vat_number( $value ); |
|
2399 | 2429 | } |
2400 | 2430 | |
2401 | 2431 | /** |
2402 | - * Alias of self::set_company(). |
|
2403 | - * |
|
2404 | - * @since 1.0.19 |
|
2405 | - * @param string $value company. |
|
2406 | - */ |
|
2407 | - public function set_customer_company( $value ) { |
|
2408 | - $this->set_company( $value ); |
|
2432 | + * Alias of self::set_vat_number(). |
|
2433 | + * |
|
2434 | + * @since 1.0.19 |
|
2435 | + * @param string $value var number. |
|
2436 | + */ |
|
2437 | + public function set_customer_vat_number( $value ) { |
|
2438 | + $this->set_vat_number( $value ); |
|
2409 | 2439 | } |
2410 | 2440 | |
2411 | 2441 | /** |
2412 | - * Set the customer's var number. |
|
2413 | - * |
|
2414 | - * @since 1.0.19 |
|
2415 | - * @param string $value var number. |
|
2416 | - */ |
|
2417 | - public function set_vat_number( $value ) { |
|
2418 | - $this->set_prop( 'vat_number', $value ); |
|
2442 | + * Set the customer's vat rate. |
|
2443 | + * |
|
2444 | + * @since 1.0.19 |
|
2445 | + * @param string $value var rate. |
|
2446 | + */ |
|
2447 | + public function set_vat_rate( $value ) { |
|
2448 | + $this->set_prop( 'vat_rate', $value ); |
|
2419 | 2449 | } |
2420 | 2450 | |
2421 | 2451 | /** |
2422 | - * Alias of self::set_vat_number(). |
|
2423 | - * |
|
2424 | - * @since 1.0.19 |
|
2425 | - * @param string $value var number. |
|
2426 | - */ |
|
2427 | - public function set_user_vat_number( $value ) { |
|
2428 | - $this->set_vat_number( $value ); |
|
2452 | + * Alias of self::set_vat_rate(). |
|
2453 | + * |
|
2454 | + * @since 1.0.19 |
|
2455 | + * @param string $value var number. |
|
2456 | + */ |
|
2457 | + public function set_user_vat_rate( $value ) { |
|
2458 | + $this->set_vat_rate( $value ); |
|
2429 | 2459 | } |
2430 | 2460 | |
2431 | 2461 | /** |
2432 | - * Alias of self::set_vat_number(). |
|
2433 | - * |
|
2434 | - * @since 1.0.19 |
|
2435 | - * @param string $value var number. |
|
2436 | - */ |
|
2437 | - public function set_customer_vat_number( $value ) { |
|
2438 | - $this->set_vat_number( $value ); |
|
2462 | + * Alias of self::set_vat_rate(). |
|
2463 | + * |
|
2464 | + * @since 1.0.19 |
|
2465 | + * @param string $value var number. |
|
2466 | + */ |
|
2467 | + public function set_customer_vat_rate( $value ) { |
|
2468 | + $this->set_vat_rate( $value ); |
|
2439 | 2469 | } |
2440 | 2470 | |
2441 | 2471 | /** |
2442 | - * Set the customer's vat rate. |
|
2443 | - * |
|
2444 | - * @since 1.0.19 |
|
2445 | - * @param string $value var rate. |
|
2446 | - */ |
|
2447 | - public function set_vat_rate( $value ) { |
|
2448 | - $this->set_prop( 'vat_rate', $value ); |
|
2472 | + * Set the customer's address. |
|
2473 | + * |
|
2474 | + * @since 1.0.19 |
|
2475 | + * @param string $value address. |
|
2476 | + */ |
|
2477 | + public function set_address( $value ) { |
|
2478 | + $this->set_prop( 'address', $value ); |
|
2449 | 2479 | } |
2450 | 2480 | |
2451 | 2481 | /** |
2452 | - * Alias of self::set_vat_rate(). |
|
2453 | - * |
|
2454 | - * @since 1.0.19 |
|
2455 | - * @param string $value var number. |
|
2456 | - */ |
|
2457 | - public function set_user_vat_rate( $value ) { |
|
2458 | - $this->set_vat_rate( $value ); |
|
2482 | + * Alias of self::set_address(). |
|
2483 | + * |
|
2484 | + * @since 1.0.19 |
|
2485 | + * @param string $value address. |
|
2486 | + */ |
|
2487 | + public function set_user_address( $value ) { |
|
2488 | + $this->set_address( $value ); |
|
2459 | 2489 | } |
2460 | 2490 | |
2461 | 2491 | /** |
2462 | - * Alias of self::set_vat_rate(). |
|
2463 | - * |
|
2464 | - * @since 1.0.19 |
|
2465 | - * @param string $value var number. |
|
2466 | - */ |
|
2467 | - public function set_customer_vat_rate( $value ) { |
|
2468 | - $this->set_vat_rate( $value ); |
|
2492 | + * Alias of self::set_address(). |
|
2493 | + * |
|
2494 | + * @since 1.0.19 |
|
2495 | + * @param string $value address. |
|
2496 | + */ |
|
2497 | + public function set_customer_address( $value ) { |
|
2498 | + $this->set_address( $value ); |
|
2469 | 2499 | } |
2470 | 2500 | |
2471 | 2501 | /** |
2472 | - * Set the customer's address. |
|
2473 | - * |
|
2474 | - * @since 1.0.19 |
|
2475 | - * @param string $value address. |
|
2476 | - */ |
|
2477 | - public function set_address( $value ) { |
|
2478 | - $this->set_prop( 'address', $value ); |
|
2502 | + * Set whether the customer has viewed the invoice or not. |
|
2503 | + * |
|
2504 | + * @since 1.0.19 |
|
2505 | + * @param int|bool $value confirmed. |
|
2506 | + */ |
|
2507 | + public function set_is_viewed( $value ) { |
|
2508 | + $this->set_prop( 'is_viewed', $value ); |
|
2479 | 2509 | } |
2480 | 2510 | |
2481 | 2511 | /** |
2482 | - * Alias of self::set_address(). |
|
2483 | - * |
|
2484 | - * @since 1.0.19 |
|
2485 | - * @param string $value address. |
|
2486 | - */ |
|
2487 | - public function set_user_address( $value ) { |
|
2488 | - $this->set_address( $value ); |
|
2512 | + * Set extra email recipients. |
|
2513 | + * |
|
2514 | + * @since 1.0.19 |
|
2515 | + * @param string $value email recipients. |
|
2516 | + */ |
|
2517 | + public function set_email_cc( $value ) { |
|
2518 | + $this->set_prop( 'email_cc', $value ); |
|
2489 | 2519 | } |
2490 | 2520 | |
2491 | 2521 | /** |
2492 | - * Alias of self::set_address(). |
|
2493 | - * |
|
2494 | - * @since 1.0.19 |
|
2495 | - * @param string $value address. |
|
2496 | - */ |
|
2497 | - public function set_customer_address( $value ) { |
|
2498 | - $this->set_address( $value ); |
|
2522 | + * Set the invoice template. |
|
2523 | + * |
|
2524 | + * @since 1.0.19 |
|
2525 | + * @param string $value email recipients. |
|
2526 | + */ |
|
2527 | + public function set_template( $value ) { |
|
2528 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2529 | + $this->set_prop( 'template', $value ); |
|
2530 | + } |
|
2499 | 2531 | } |
2500 | 2532 | |
2501 | 2533 | /** |
2502 | - * Set whether the customer has viewed the invoice or not. |
|
2503 | - * |
|
2504 | - * @since 1.0.19 |
|
2505 | - * @param int|bool $value confirmed. |
|
2506 | - */ |
|
2507 | - public function set_is_viewed( $value ) { |
|
2508 | - $this->set_prop( 'is_viewed', $value ); |
|
2509 | - } |
|
2510 | - |
|
2511 | - /** |
|
2512 | - * Set extra email recipients. |
|
2513 | - * |
|
2514 | - * @since 1.0.19 |
|
2515 | - * @param string $value email recipients. |
|
2516 | - */ |
|
2517 | - public function set_email_cc( $value ) { |
|
2518 | - $this->set_prop( 'email_cc', $value ); |
|
2519 | - } |
|
2520 | - |
|
2521 | - /** |
|
2522 | - * Set the invoice template. |
|
2523 | - * |
|
2524 | - * @since 1.0.19 |
|
2525 | - * @param string $value email recipients. |
|
2526 | - */ |
|
2527 | - public function set_template( $value ) { |
|
2528 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
2529 | - $this->set_prop( 'template', $value ); |
|
2530 | - } |
|
2531 | - } |
|
2532 | - |
|
2533 | - /** |
|
2534 | - * Set the customer's address confirmed status. |
|
2535 | - * |
|
2536 | - * @since 1.0.19 |
|
2537 | - * @param int|bool $value confirmed. |
|
2538 | - */ |
|
2539 | - public function set_address_confirmed( $value ) { |
|
2540 | - $this->set_prop( 'address_confirmed', $value ); |
|
2534 | + * Set the customer's address confirmed status. |
|
2535 | + * |
|
2536 | + * @since 1.0.19 |
|
2537 | + * @param int|bool $value confirmed. |
|
2538 | + */ |
|
2539 | + public function set_address_confirmed( $value ) { |
|
2540 | + $this->set_prop( 'address_confirmed', $value ); |
|
2541 | 2541 | } |
2542 | 2542 | |
2543 | 2543 | /** |
2544 | - * Alias of self::set_address_confirmed(). |
|
2545 | - * |
|
2546 | - * @since 1.0.19 |
|
2547 | - * @param int|bool $value confirmed. |
|
2548 | - */ |
|
2549 | - public function set_user_address_confirmed( $value ) { |
|
2550 | - $this->set_address_confirmed( $value ); |
|
2544 | + * Alias of self::set_address_confirmed(). |
|
2545 | + * |
|
2546 | + * @since 1.0.19 |
|
2547 | + * @param int|bool $value confirmed. |
|
2548 | + */ |
|
2549 | + public function set_user_address_confirmed( $value ) { |
|
2550 | + $this->set_address_confirmed( $value ); |
|
2551 | 2551 | } |
2552 | 2552 | |
2553 | 2553 | /** |
2554 | - * Alias of self::set_address_confirmed(). |
|
2555 | - * |
|
2556 | - * @since 1.0.19 |
|
2557 | - * @param int|bool $value confirmed. |
|
2558 | - */ |
|
2559 | - public function set_customer_address_confirmed( $value ) { |
|
2560 | - $this->set_address_confirmed( $value ); |
|
2554 | + * Alias of self::set_address_confirmed(). |
|
2555 | + * |
|
2556 | + * @since 1.0.19 |
|
2557 | + * @param int|bool $value confirmed. |
|
2558 | + */ |
|
2559 | + public function set_customer_address_confirmed( $value ) { |
|
2560 | + $this->set_address_confirmed( $value ); |
|
2561 | 2561 | } |
2562 | 2562 | |
2563 | 2563 | /** |
2564 | - * Set the invoice sub total. |
|
2565 | - * |
|
2566 | - * @since 1.0.19 |
|
2567 | - * @param float $value sub total. |
|
2568 | - */ |
|
2569 | - public function set_subtotal( $value ) { |
|
2570 | - $this->set_prop( 'subtotal', $value ); |
|
2564 | + * Set the invoice sub total. |
|
2565 | + * |
|
2566 | + * @since 1.0.19 |
|
2567 | + * @param float $value sub total. |
|
2568 | + */ |
|
2569 | + public function set_subtotal( $value ) { |
|
2570 | + $this->set_prop( 'subtotal', $value ); |
|
2571 | 2571 | } |
2572 | 2572 | |
2573 | 2573 | /** |
2574 | - * Set the invoice discount amount. |
|
2575 | - * |
|
2576 | - * @since 1.0.19 |
|
2577 | - * @param float $value discount total. |
|
2578 | - */ |
|
2579 | - public function set_total_discount( $value ) { |
|
2580 | - $this->set_prop( 'total_discount', $value ); |
|
2574 | + * Set the invoice discount amount. |
|
2575 | + * |
|
2576 | + * @since 1.0.19 |
|
2577 | + * @param float $value discount total. |
|
2578 | + */ |
|
2579 | + public function set_total_discount( $value ) { |
|
2580 | + $this->set_prop( 'total_discount', $value ); |
|
2581 | 2581 | } |
2582 | 2582 | |
2583 | 2583 | /** |
2584 | - * Alias of self::set_total_discount(). |
|
2585 | - * |
|
2586 | - * @since 1.0.19 |
|
2587 | - * @param float $value discount total. |
|
2588 | - */ |
|
2589 | - public function set_discount( $value ) { |
|
2590 | - $this->set_total_discount( $value ); |
|
2584 | + * Alias of self::set_total_discount(). |
|
2585 | + * |
|
2586 | + * @since 1.0.19 |
|
2587 | + * @param float $value discount total. |
|
2588 | + */ |
|
2589 | + public function set_discount( $value ) { |
|
2590 | + $this->set_total_discount( $value ); |
|
2591 | 2591 | } |
2592 | 2592 | |
2593 | 2593 | /** |
2594 | - * Set the invoice tax amount. |
|
2595 | - * |
|
2596 | - * @since 1.0.19 |
|
2597 | - * @param float $value tax total. |
|
2598 | - */ |
|
2599 | - public function set_total_tax( $value ) { |
|
2600 | - $this->set_prop( 'total_tax', $value ); |
|
2594 | + * Set the invoice tax amount. |
|
2595 | + * |
|
2596 | + * @since 1.0.19 |
|
2597 | + * @param float $value tax total. |
|
2598 | + */ |
|
2599 | + public function set_total_tax( $value ) { |
|
2600 | + $this->set_prop( 'total_tax', $value ); |
|
2601 | 2601 | } |
2602 | 2602 | |
2603 | 2603 | /** |
2604 | - * Alias of self::set_total_tax(). |
|
2605 | - * |
|
2606 | - * @since 1.0.19 |
|
2607 | - * @param float $value tax total. |
|
2608 | - */ |
|
2609 | - public function set_tax_total( $value ) { |
|
2610 | - $this->set_total_tax( $value ); |
|
2604 | + * Alias of self::set_total_tax(). |
|
2605 | + * |
|
2606 | + * @since 1.0.19 |
|
2607 | + * @param float $value tax total. |
|
2608 | + */ |
|
2609 | + public function set_tax_total( $value ) { |
|
2610 | + $this->set_total_tax( $value ); |
|
2611 | 2611 | } |
2612 | 2612 | |
2613 | 2613 | /** |
2614 | - * Set the invoice fees amount. |
|
2615 | - * |
|
2616 | - * @since 1.0.19 |
|
2617 | - * @param float $value fees total. |
|
2618 | - */ |
|
2619 | - public function set_total_fees( $value ) { |
|
2620 | - $this->set_prop( 'total_fees', $value ); |
|
2614 | + * Set the invoice fees amount. |
|
2615 | + * |
|
2616 | + * @since 1.0.19 |
|
2617 | + * @param float $value fees total. |
|
2618 | + */ |
|
2619 | + public function set_total_fees( $value ) { |
|
2620 | + $this->set_prop( 'total_fees', $value ); |
|
2621 | 2621 | } |
2622 | 2622 | |
2623 | 2623 | /** |
2624 | - * Alias of self::set_total_fees(). |
|
2625 | - * |
|
2626 | - * @since 1.0.19 |
|
2627 | - * @param float $value fees total. |
|
2628 | - */ |
|
2629 | - public function set_fees_total( $value ) { |
|
2630 | - $this->set_total_fees( $value ); |
|
2624 | + * Alias of self::set_total_fees(). |
|
2625 | + * |
|
2626 | + * @since 1.0.19 |
|
2627 | + * @param float $value fees total. |
|
2628 | + */ |
|
2629 | + public function set_fees_total( $value ) { |
|
2630 | + $this->set_total_fees( $value ); |
|
2631 | 2631 | } |
2632 | 2632 | |
2633 | 2633 | /** |
2634 | - * Set the invoice fees. |
|
2635 | - * |
|
2636 | - * @since 1.0.19 |
|
2637 | - * @param array $value fees. |
|
2638 | - */ |
|
2639 | - public function set_fees( $value ) { |
|
2634 | + * Set the invoice fees. |
|
2635 | + * |
|
2636 | + * @since 1.0.19 |
|
2637 | + * @param array $value fees. |
|
2638 | + */ |
|
2639 | + public function set_fees( $value ) { |
|
2640 | 2640 | |
2641 | 2641 | $this->set_prop( 'fees', array() ); |
2642 | 2642 | |
@@ -2654,23 +2654,23 @@ discard block |
||
2654 | 2654 | } |
2655 | 2655 | |
2656 | 2656 | /** |
2657 | - * Set the invoice taxes. |
|
2658 | - * |
|
2659 | - * @since 1.0.19 |
|
2660 | - * @param array $value taxes. |
|
2661 | - */ |
|
2662 | - public function set_taxes( $value ) { |
|
2663 | - $this->set_prop( 'taxes', $value ); |
|
2657 | + * Set the invoice taxes. |
|
2658 | + * |
|
2659 | + * @since 1.0.19 |
|
2660 | + * @param array $value taxes. |
|
2661 | + */ |
|
2662 | + public function set_taxes( $value ) { |
|
2663 | + $this->set_prop( 'taxes', $value ); |
|
2664 | 2664 | } |
2665 | 2665 | |
2666 | 2666 | /** |
2667 | - * Set the invoice discounts. |
|
2668 | - * |
|
2669 | - * @since 1.0.19 |
|
2670 | - * @param array $value discounts. |
|
2671 | - */ |
|
2672 | - public function set_discounts( $value ) { |
|
2673 | - $this->set_prop( 'discounts', array() ); |
|
2667 | + * Set the invoice discounts. |
|
2668 | + * |
|
2669 | + * @since 1.0.19 |
|
2670 | + * @param array $value discounts. |
|
2671 | + */ |
|
2672 | + public function set_discounts( $value ) { |
|
2673 | + $this->set_prop( 'discounts', array() ); |
|
2674 | 2674 | |
2675 | 2675 | // Ensure that we have an array. |
2676 | 2676 | if ( ! is_array( $value ) ) { |
@@ -2685,12 +2685,12 @@ discard block |
||
2685 | 2685 | } |
2686 | 2686 | |
2687 | 2687 | /** |
2688 | - * Set the invoice items. |
|
2689 | - * |
|
2690 | - * @since 1.0.19 |
|
2691 | - * @param GetPaid_Form_Item[] $value items. |
|
2692 | - */ |
|
2693 | - public function set_items( $value ) { |
|
2688 | + * Set the invoice items. |
|
2689 | + * |
|
2690 | + * @since 1.0.19 |
|
2691 | + * @param GetPaid_Form_Item[] $value items. |
|
2692 | + */ |
|
2693 | + public function set_items( $value ) { |
|
2694 | 2694 | |
2695 | 2695 | // Remove existing items. |
2696 | 2696 | $this->set_prop( 'items', array() ); |
@@ -2707,83 +2707,83 @@ discard block |
||
2707 | 2707 | } |
2708 | 2708 | |
2709 | 2709 | /** |
2710 | - * Set the payment form. |
|
2711 | - * |
|
2712 | - * @since 1.0.19 |
|
2713 | - * @param int $value payment form. |
|
2714 | - */ |
|
2715 | - public function set_payment_form( $value ) { |
|
2716 | - $this->set_prop( 'payment_form', $value ); |
|
2710 | + * Set the payment form. |
|
2711 | + * |
|
2712 | + * @since 1.0.19 |
|
2713 | + * @param int $value payment form. |
|
2714 | + */ |
|
2715 | + public function set_payment_form( $value ) { |
|
2716 | + $this->set_prop( 'payment_form', $value ); |
|
2717 | 2717 | } |
2718 | 2718 | |
2719 | 2719 | /** |
2720 | - * Set the submission id. |
|
2721 | - * |
|
2722 | - * @since 1.0.19 |
|
2723 | - * @param string $value submission id. |
|
2724 | - */ |
|
2725 | - public function set_submission_id( $value ) { |
|
2726 | - $this->set_prop( 'submission_id', $value ); |
|
2720 | + * Set the submission id. |
|
2721 | + * |
|
2722 | + * @since 1.0.19 |
|
2723 | + * @param string $value submission id. |
|
2724 | + */ |
|
2725 | + public function set_submission_id( $value ) { |
|
2726 | + $this->set_prop( 'submission_id', $value ); |
|
2727 | 2727 | } |
2728 | 2728 | |
2729 | 2729 | /** |
2730 | - * Set the discount code. |
|
2731 | - * |
|
2732 | - * @since 1.0.19 |
|
2733 | - * @param string $value discount code. |
|
2734 | - */ |
|
2735 | - public function set_discount_code( $value ) { |
|
2736 | - $this->set_prop( 'discount_code', $value ); |
|
2730 | + * Set the discount code. |
|
2731 | + * |
|
2732 | + * @since 1.0.19 |
|
2733 | + * @param string $value discount code. |
|
2734 | + */ |
|
2735 | + public function set_discount_code( $value ) { |
|
2736 | + $this->set_prop( 'discount_code', $value ); |
|
2737 | 2737 | } |
2738 | 2738 | |
2739 | 2739 | /** |
2740 | - * Set the gateway. |
|
2741 | - * |
|
2742 | - * @since 1.0.19 |
|
2743 | - * @param string $value gateway. |
|
2744 | - */ |
|
2745 | - public function set_gateway( $value ) { |
|
2746 | - $this->set_prop( 'gateway', $value ); |
|
2740 | + * Set the gateway. |
|
2741 | + * |
|
2742 | + * @since 1.0.19 |
|
2743 | + * @param string $value gateway. |
|
2744 | + */ |
|
2745 | + public function set_gateway( $value ) { |
|
2746 | + $this->set_prop( 'gateway', $value ); |
|
2747 | 2747 | } |
2748 | 2748 | |
2749 | 2749 | /** |
2750 | - * Set the transaction id. |
|
2751 | - * |
|
2752 | - * @since 1.0.19 |
|
2753 | - * @param string $value transaction id. |
|
2754 | - */ |
|
2755 | - public function set_transaction_id( $value ) { |
|
2756 | - $this->set_prop( 'transaction_id', $value ); |
|
2750 | + * Set the transaction id. |
|
2751 | + * |
|
2752 | + * @since 1.0.19 |
|
2753 | + * @param string $value transaction id. |
|
2754 | + */ |
|
2755 | + public function set_transaction_id( $value ) { |
|
2756 | + $this->set_prop( 'transaction_id', $value ); |
|
2757 | 2757 | } |
2758 | 2758 | |
2759 | 2759 | /** |
2760 | - * Set the currency id. |
|
2761 | - * |
|
2762 | - * @since 1.0.19 |
|
2763 | - * @param string $value currency id. |
|
2764 | - */ |
|
2765 | - public function set_currency( $value ) { |
|
2766 | - $this->set_prop( 'currency', $value ); |
|
2760 | + * Set the currency id. |
|
2761 | + * |
|
2762 | + * @since 1.0.19 |
|
2763 | + * @param string $value currency id. |
|
2764 | + */ |
|
2765 | + public function set_currency( $value ) { |
|
2766 | + $this->set_prop( 'currency', $value ); |
|
2767 | 2767 | } |
2768 | 2768 | |
2769 | - /** |
|
2770 | - * Set whether to disable taxes. |
|
2771 | - * |
|
2772 | - * @since 1.0.19 |
|
2773 | - * @param bool $value value. |
|
2774 | - */ |
|
2775 | - public function set_disable_taxes( $value ) { |
|
2776 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
2777 | - } |
|
2769 | + /** |
|
2770 | + * Set whether to disable taxes. |
|
2771 | + * |
|
2772 | + * @since 1.0.19 |
|
2773 | + * @param bool $value value. |
|
2774 | + */ |
|
2775 | + public function set_disable_taxes( $value ) { |
|
2776 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
2777 | + } |
|
2778 | 2778 | |
2779 | 2779 | /** |
2780 | - * Set the subscription id. |
|
2781 | - * |
|
2782 | - * @since 1.0.19 |
|
2783 | - * @param string $value subscription id. |
|
2784 | - */ |
|
2785 | - public function set_subscription_id( $value ) { |
|
2786 | - $this->set_prop( 'subscription_id', $value ); |
|
2780 | + * Set the subscription id. |
|
2781 | + * |
|
2782 | + * @since 1.0.19 |
|
2783 | + * @param string $value subscription id. |
|
2784 | + */ |
|
2785 | + public function set_subscription_id( $value ) { |
|
2786 | + $this->set_prop( 'subscription_id', $value ); |
|
2787 | 2787 | } |
2788 | 2788 | |
2789 | 2789 | /* |
@@ -2822,12 +2822,12 @@ discard block |
||
2822 | 2822 | */ |
2823 | 2823 | public function is_taxable() { |
2824 | 2824 | return $this->get_disable_taxes(); |
2825 | - } |
|
2825 | + } |
|
2826 | 2826 | |
2827 | - /** |
|
2828 | - * @deprecated |
|
2829 | - */ |
|
2830 | - public function has_vat() { |
|
2827 | + /** |
|
2828 | + * @deprecated |
|
2829 | + */ |
|
2830 | + public function has_vat() { |
|
2831 | 2831 | global $wpinv_euvat, $wpi_country; |
2832 | 2832 | |
2833 | 2833 | $requires_vat = false; |
@@ -2838,17 +2838,17 @@ discard block |
||
2838 | 2838 | } |
2839 | 2839 | |
2840 | 2840 | return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
2841 | - } |
|
2841 | + } |
|
2842 | 2842 | |
2843 | - /** |
|
2844 | - * Checks to see if the invoice requires payment. |
|
2845 | - */ |
|
2846 | - public function is_free() { |
|
2843 | + /** |
|
2844 | + * Checks to see if the invoice requires payment. |
|
2845 | + */ |
|
2846 | + public function is_free() { |
|
2847 | 2847 | $is_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
2848 | 2848 | |
2849 | - if ( $is_free && $this->is_recurring() ) { |
|
2850 | - $is_free = ! ( (float) wpinv_round_amount( $this->get_recurring_total() ) > 0 ); |
|
2851 | - } |
|
2849 | + if ( $is_free && $this->is_recurring() ) { |
|
2850 | + $is_free = ! ( (float) wpinv_round_amount( $this->get_recurring_total() ) > 0 ); |
|
2851 | + } |
|
2852 | 2852 | |
2853 | 2853 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
2854 | 2854 | } |
@@ -2859,30 +2859,30 @@ discard block |
||
2859 | 2859 | public function is_paid() { |
2860 | 2860 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
2861 | 2861 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
2862 | - } |
|
2862 | + } |
|
2863 | 2863 | |
2864 | - /** |
|
2864 | + /** |
|
2865 | 2865 | * Checks if the invoice needs payment. |
2866 | 2866 | */ |
2867 | - public function needs_payment() { |
|
2868 | - $needs_payment = ! $this->is_paid() && ! $this->is_free(); |
|
2867 | + public function needs_payment() { |
|
2868 | + $needs_payment = ! $this->is_paid() && ! $this->is_free(); |
|
2869 | 2869 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
2870 | 2870 | } |
2871 | 2871 | |
2872 | - /** |
|
2872 | + /** |
|
2873 | 2873 | * Checks if the invoice is refunded. |
2874 | 2874 | */ |
2875 | - public function is_refunded() { |
|
2875 | + public function is_refunded() { |
|
2876 | 2876 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
2877 | 2877 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
2878 | - } |
|
2878 | + } |
|
2879 | 2879 | |
2880 | - /** |
|
2880 | + /** |
|
2881 | 2881 | * Checks if the invoice is draft. |
2882 | 2882 | */ |
2883 | - public function is_draft() { |
|
2883 | + public function is_draft() { |
|
2884 | 2884 | return $this->has_status( 'draft, auto-draft' ); |
2885 | - } |
|
2885 | + } |
|
2886 | 2886 | |
2887 | 2887 | /** |
2888 | 2888 | * Checks if the invoice has a given status. |
@@ -2890,9 +2890,9 @@ discard block |
||
2890 | 2890 | public function has_status( $status ) { |
2891 | 2891 | $status = wpinv_parse_list( $status ); |
2892 | 2892 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
2893 | - } |
|
2893 | + } |
|
2894 | 2894 | |
2895 | - /** |
|
2895 | + /** |
|
2896 | 2896 | * Checks if the invoice is of a given type. |
2897 | 2897 | */ |
2898 | 2898 | public function is_type( $type ) { |
@@ -2915,25 +2915,25 @@ discard block |
||
2915 | 2915 | */ |
2916 | 2916 | public function has_free_trial() { |
2917 | 2917 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
2918 | - } |
|
2918 | + } |
|
2919 | 2919 | |
2920 | - /** |
|
2920 | + /** |
|
2921 | 2921 | * @deprecated |
2922 | 2922 | */ |
2923 | 2923 | public function is_free_trial() { |
2924 | 2924 | $this->has_free_trial(); |
2925 | 2925 | } |
2926 | 2926 | |
2927 | - /** |
|
2927 | + /** |
|
2928 | 2928 | * Check if the initial payment if 0. |
2929 | 2929 | * |
2930 | 2930 | */ |
2931 | - public function is_initial_free() { |
|
2931 | + public function is_initial_free() { |
|
2932 | 2932 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
2933 | 2933 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
2934 | 2934 | } |
2935 | 2935 | |
2936 | - /** |
|
2936 | + /** |
|
2937 | 2937 | * Check if the recurring item has a free trial. |
2938 | 2938 | * |
2939 | 2939 | */ |
@@ -2946,21 +2946,21 @@ discard block |
||
2946 | 2946 | |
2947 | 2947 | $item = new WPInv_Item( $this->recurring_item ); |
2948 | 2948 | return $item->has_free_trial(); |
2949 | - } |
|
2949 | + } |
|
2950 | 2950 | |
2951 | - /** |
|
2951 | + /** |
|
2952 | 2952 | * Check if the free trial is a result of a discount. |
2953 | 2953 | */ |
2954 | 2954 | public function is_free_trial_from_discount() { |
2955 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
2956 | - } |
|
2955 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
2956 | + } |
|
2957 | 2957 | |
2958 | - /** |
|
2958 | + /** |
|
2959 | 2959 | * @deprecated |
2960 | 2960 | */ |
2961 | 2961 | public function discount_first_payment_only() { |
2962 | 2962 | |
2963 | - $discount_code = $this->get_discount_code(); |
|
2963 | + $discount_code = $this->get_discount_code(); |
|
2964 | 2964 | if ( empty( $this->discount_code ) || ! $this->is_recurring() ) { |
2965 | 2965 | return true; |
2966 | 2966 | } |
@@ -2992,19 +2992,19 @@ discard block |
||
2992 | 2992 | public function add_item( $item ) { |
2993 | 2993 | |
2994 | 2994 | // Make sure that it is available for purchase. |
2995 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
2996 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
2995 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
2996 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
2997 | 2997 | } |
2998 | 2998 | |
2999 | 2999 | // Do we have a recurring item? |
3000 | - if ( $item->is_recurring() ) { |
|
3000 | + if ( $item->is_recurring() ) { |
|
3001 | 3001 | |
3002 | - // An invoice can only contain one recurring item. |
|
3003 | - if ( ! empty( $this->recurring_item ) ) { |
|
3004 | - return false; |
|
3005 | - } |
|
3002 | + // An invoice can only contain one recurring item. |
|
3003 | + if ( ! empty( $this->recurring_item ) ) { |
|
3004 | + return false; |
|
3005 | + } |
|
3006 | 3006 | |
3007 | - $this->recurring_item = $item->get_id(); |
|
3007 | + $this->recurring_item = $item->get_id(); |
|
3008 | 3008 | } |
3009 | 3009 | |
3010 | 3010 | // Invoice id. |
@@ -3015,25 +3015,25 @@ discard block |
||
3015 | 3015 | $items[ $item->get_id() ] = $item; |
3016 | 3016 | |
3017 | 3017 | $this->set_prop( 'items', $items ); |
3018 | - return true; |
|
3018 | + return true; |
|
3019 | 3019 | } |
3020 | 3020 | |
3021 | 3021 | /** |
3022 | - * Retrieves a specific item. |
|
3023 | - * |
|
3024 | - * @since 1.0.19 |
|
3025 | - */ |
|
3026 | - public function get_item( $item_id ) { |
|
3022 | + * Retrieves a specific item. |
|
3023 | + * |
|
3024 | + * @since 1.0.19 |
|
3025 | + */ |
|
3026 | + public function get_item( $item_id ) { |
|
3027 | 3027 | $items = $this->get_items(); |
3028 | - return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
3028 | + return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null; |
|
3029 | 3029 | } |
3030 | 3030 | |
3031 | 3031 | /** |
3032 | - * Removes a specific item. |
|
3033 | - * |
|
3034 | - * @since 1.0.19 |
|
3035 | - */ |
|
3036 | - public function remove_item( $item_id ) { |
|
3032 | + * Removes a specific item. |
|
3033 | + * |
|
3034 | + * @since 1.0.19 |
|
3035 | + */ |
|
3036 | + public function remove_item( $item_id ) { |
|
3037 | 3037 | $items = $this->get_items(); |
3038 | 3038 | |
3039 | 3039 | if ( $item_id == $this->recurring_item ) { |
@@ -3061,38 +3061,38 @@ discard block |
||
3061 | 3061 | if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) { |
3062 | 3062 | |
3063 | 3063 | $amount = $fees[ $fee ]['amount'] += $amount; |
3064 | - $fees[ $fee ] = array( |
|
3064 | + $fees[ $fee ] = array( |
|
3065 | 3065 | 'amount' => $amount, |
3066 | 3066 | 'recurring' => (bool) $recurring, |
3067 | 3067 | ); |
3068 | 3068 | |
3069 | - } else { |
|
3070 | - $fees[ $fee ] = array( |
|
3069 | + } else { |
|
3070 | + $fees[ $fee ] = array( |
|
3071 | 3071 | 'amount' => $amount, |
3072 | 3072 | 'recurring' => (bool) $recurring, |
3073 | 3073 | ); |
3074 | - } |
|
3074 | + } |
|
3075 | 3075 | |
3076 | 3076 | $this->set_prop( 'fees', $fee ); |
3077 | 3077 | |
3078 | 3078 | } |
3079 | 3079 | |
3080 | 3080 | /** |
3081 | - * Retrieves a specific fee. |
|
3082 | - * |
|
3083 | - * @since 1.0.19 |
|
3084 | - */ |
|
3085 | - public function get_fee( $fee ) { |
|
3081 | + * Retrieves a specific fee. |
|
3082 | + * |
|
3083 | + * @since 1.0.19 |
|
3084 | + */ |
|
3085 | + public function get_fee( $fee ) { |
|
3086 | 3086 | $fees = $this->get_fees(); |
3087 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3087 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
3088 | 3088 | } |
3089 | 3089 | |
3090 | 3090 | /** |
3091 | - * Removes a specific fee. |
|
3092 | - * |
|
3093 | - * @since 1.0.19 |
|
3094 | - */ |
|
3095 | - public function remove_fee( $fee ) { |
|
3091 | + * Removes a specific fee. |
|
3092 | + * |
|
3093 | + * @since 1.0.19 |
|
3094 | + */ |
|
3095 | + public function remove_fee( $fee ) { |
|
3096 | 3096 | $fees = $this->get_fees(); |
3097 | 3097 | if ( isset( $fees[ $fee ] ) ) { |
3098 | 3098 | unset( $fees[ $fee ] ); |
@@ -3115,44 +3115,44 @@ discard block |
||
3115 | 3115 | if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) { |
3116 | 3116 | |
3117 | 3117 | $amount = $discounts[ $discount ]['amount'] += $amount; |
3118 | - $discounts[ $discount ] = array( |
|
3118 | + $discounts[ $discount ] = array( |
|
3119 | 3119 | 'amount' => $amount, |
3120 | 3120 | 'recurring' => (bool) $recurring, |
3121 | 3121 | ); |
3122 | 3122 | |
3123 | - } else { |
|
3124 | - $discounts[ $discount ] = array( |
|
3123 | + } else { |
|
3124 | + $discounts[ $discount ] = array( |
|
3125 | 3125 | 'amount' => $amount, |
3126 | 3126 | 'recurring' => (bool) $recurring, |
3127 | 3127 | ); |
3128 | - } |
|
3128 | + } |
|
3129 | 3129 | |
3130 | 3130 | $this->set_prop( 'discounts', $discount ); |
3131 | 3131 | |
3132 | 3132 | } |
3133 | 3133 | |
3134 | 3134 | /** |
3135 | - * Retrieves a specific discount. |
|
3136 | - * |
|
3137 | - * @since 1.0.19 |
|
3138 | - */ |
|
3139 | - public function get_discount( $discount = false ) { |
|
3135 | + * Retrieves a specific discount. |
|
3136 | + * |
|
3137 | + * @since 1.0.19 |
|
3138 | + */ |
|
3139 | + public function get_discount( $discount = false ) { |
|
3140 | 3140 | |
3141 | - // Backwards compatibilty. |
|
3142 | - if ( empty( $discount ) ) { |
|
3143 | - return $this->get_total_discount(); |
|
3144 | - } |
|
3141 | + // Backwards compatibilty. |
|
3142 | + if ( empty( $discount ) ) { |
|
3143 | + return $this->get_total_discount(); |
|
3144 | + } |
|
3145 | 3145 | |
3146 | 3146 | $discounts = $this->get_discounts(); |
3147 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3147 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
3148 | 3148 | } |
3149 | 3149 | |
3150 | 3150 | /** |
3151 | - * Removes a specific discount. |
|
3152 | - * |
|
3153 | - * @since 1.0.19 |
|
3154 | - */ |
|
3155 | - public function remove_discount( $discount ) { |
|
3151 | + * Removes a specific discount. |
|
3152 | + * |
|
3153 | + * @since 1.0.19 |
|
3154 | + */ |
|
3155 | + public function remove_discount( $discount ) { |
|
3156 | 3156 | $discounts = $this->get_discounts(); |
3157 | 3157 | if ( isset( $discounts[ $discount ] ) ) { |
3158 | 3158 | unset( $discounts[ $discount ] ); |
@@ -3178,38 +3178,38 @@ discard block |
||
3178 | 3178 | if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) { |
3179 | 3179 | |
3180 | 3180 | $amount = $taxes[ $tax ]['amount'] += $amount; |
3181 | - $taxes[ $tax ] = array( |
|
3181 | + $taxes[ $tax ] = array( |
|
3182 | 3182 | 'amount' => $amount, |
3183 | 3183 | 'recurring' => (bool) $recurring, |
3184 | 3184 | ); |
3185 | 3185 | |
3186 | - } else { |
|
3187 | - $taxes[ $tax ] = array( |
|
3186 | + } else { |
|
3187 | + $taxes[ $tax ] = array( |
|
3188 | 3188 | 'amount' => $amount, |
3189 | 3189 | 'recurring' => (bool) $recurring, |
3190 | 3190 | ); |
3191 | - } |
|
3191 | + } |
|
3192 | 3192 | |
3193 | 3193 | $this->set_prop( 'taxes', $tax ); |
3194 | 3194 | |
3195 | 3195 | } |
3196 | 3196 | |
3197 | 3197 | /** |
3198 | - * Retrieves a specific tax. |
|
3199 | - * |
|
3200 | - * @since 1.0.19 |
|
3201 | - */ |
|
3202 | - public function get_tax( $tax ) { |
|
3198 | + * Retrieves a specific tax. |
|
3199 | + * |
|
3200 | + * @since 1.0.19 |
|
3201 | + */ |
|
3202 | + public function get_tax( $tax ) { |
|
3203 | 3203 | $taxes = $this->get_taxes(); |
3204 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3204 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
3205 | 3205 | } |
3206 | 3206 | |
3207 | 3207 | /** |
3208 | - * Removes a specific tax. |
|
3209 | - * |
|
3210 | - * @since 1.0.19 |
|
3211 | - */ |
|
3212 | - public function remove_tax( $tax ) { |
|
3208 | + * Removes a specific tax. |
|
3209 | + * |
|
3210 | + * @since 1.0.19 |
|
3211 | + */ |
|
3212 | + public function remove_tax( $tax ) { |
|
3213 | 3213 | $taxes = $this->get_discounts(); |
3214 | 3214 | if ( isset( $taxes[ $tax ] ) ) { |
3215 | 3215 | unset( $taxes[ $tax ] ); |
@@ -3218,160 +3218,160 @@ discard block |
||
3218 | 3218 | } |
3219 | 3219 | |
3220 | 3220 | /** |
3221 | - * Recalculates the invoice subtotal. |
|
3222 | - * |
|
3223 | - * @since 1.0.19 |
|
3224 | - * @return float The recalculated subtotal |
|
3225 | - */ |
|
3226 | - public function recalculate_subtotal() { |
|
3221 | + * Recalculates the invoice subtotal. |
|
3222 | + * |
|
3223 | + * @since 1.0.19 |
|
3224 | + * @return float The recalculated subtotal |
|
3225 | + */ |
|
3226 | + public function recalculate_subtotal() { |
|
3227 | 3227 | $items = $this->get_items(); |
3228 | - $subtotal = 0; |
|
3229 | - $recurring = 0; |
|
3228 | + $subtotal = 0; |
|
3229 | + $recurring = 0; |
|
3230 | 3230 | |
3231 | 3231 | foreach ( $items as $item ) { |
3232 | - $subtotal += $item->get_sub_total(); |
|
3233 | - $recurring += $item->get_recurring_sub_total(); |
|
3232 | + $subtotal += $item->get_sub_total(); |
|
3233 | + $recurring += $item->get_recurring_sub_total(); |
|
3234 | 3234 | } |
3235 | 3235 | |
3236 | - if ( $this->is_renewal() ) { |
|
3237 | - $this->set_subtotal( $recurring ); |
|
3238 | - } else { |
|
3239 | - $this->set_subtotal( $subtotal ); |
|
3240 | - } |
|
3236 | + if ( $this->is_renewal() ) { |
|
3237 | + $this->set_subtotal( $recurring ); |
|
3238 | + } else { |
|
3239 | + $this->set_subtotal( $subtotal ); |
|
3240 | + } |
|
3241 | 3241 | |
3242 | - $this->totals['subtotal'] = array( |
|
3243 | - 'initial' => $subtotal, |
|
3244 | - 'recurring' => $recurring, |
|
3245 | - ); |
|
3242 | + $this->totals['subtotal'] = array( |
|
3243 | + 'initial' => $subtotal, |
|
3244 | + 'recurring' => $recurring, |
|
3245 | + ); |
|
3246 | 3246 | |
3247 | 3247 | return $this->is_renewal() ? $recurring : $subtotal; |
3248 | 3248 | } |
3249 | 3249 | |
3250 | 3250 | /** |
3251 | - * Recalculates the invoice discount total. |
|
3252 | - * |
|
3253 | - * @since 1.0.19 |
|
3254 | - * @return float The recalculated discount |
|
3255 | - */ |
|
3256 | - public function recalculate_total_discount() { |
|
3251 | + * Recalculates the invoice discount total. |
|
3252 | + * |
|
3253 | + * @since 1.0.19 |
|
3254 | + * @return float The recalculated discount |
|
3255 | + */ |
|
3256 | + public function recalculate_total_discount() { |
|
3257 | 3257 | $discounts = $this->get_discounts(); |
3258 | - $discount = 0; |
|
3259 | - $recurring = 0; |
|
3258 | + $discount = 0; |
|
3259 | + $recurring = 0; |
|
3260 | 3260 | |
3261 | 3261 | foreach ( $discounts as $data ) { |
3262 | 3262 | |
3263 | - if ( $data['recurring'] ) { |
|
3264 | - $recurring += $data['amount']; |
|
3265 | - } else { |
|
3266 | - $discount += $data['amount']; |
|
3267 | - } |
|
3263 | + if ( $data['recurring'] ) { |
|
3264 | + $recurring += $data['amount']; |
|
3265 | + } else { |
|
3266 | + $discount += $data['amount']; |
|
3267 | + } |
|
3268 | 3268 | |
3269 | - } |
|
3269 | + } |
|
3270 | 3270 | |
3271 | - if ( $this->is_renewal() ) { |
|
3272 | - $this->set_total_discount( $recurring ); |
|
3273 | - } else { |
|
3274 | - $this->set_total_discount( $discount ); |
|
3275 | - } |
|
3271 | + if ( $this->is_renewal() ) { |
|
3272 | + $this->set_total_discount( $recurring ); |
|
3273 | + } else { |
|
3274 | + $this->set_total_discount( $discount ); |
|
3275 | + } |
|
3276 | 3276 | |
3277 | - $this->totals['discount'] = array( |
|
3278 | - 'initial' => $discount, |
|
3279 | - 'recurring' => $recurring, |
|
3280 | - ); |
|
3277 | + $this->totals['discount'] = array( |
|
3278 | + 'initial' => $discount, |
|
3279 | + 'recurring' => $recurring, |
|
3280 | + ); |
|
3281 | 3281 | |
3282 | - return $this->is_renewal() ? $recurring : $discount; |
|
3282 | + return $this->is_renewal() ? $recurring : $discount; |
|
3283 | 3283 | |
3284 | 3284 | } |
3285 | 3285 | |
3286 | 3286 | /** |
3287 | - * Recalculates the invoice tax total. |
|
3288 | - * |
|
3289 | - * @since 1.0.19 |
|
3290 | - * @return float The recalculated tax |
|
3291 | - */ |
|
3292 | - public function recalculate_total_tax() { |
|
3287 | + * Recalculates the invoice tax total. |
|
3288 | + * |
|
3289 | + * @since 1.0.19 |
|
3290 | + * @return float The recalculated tax |
|
3291 | + */ |
|
3292 | + public function recalculate_total_tax() { |
|
3293 | 3293 | $taxes = $this->get_taxes(); |
3294 | - $tax = 0; |
|
3295 | - $recurring = 0; |
|
3294 | + $tax = 0; |
|
3295 | + $recurring = 0; |
|
3296 | 3296 | |
3297 | 3297 | foreach ( $taxes as $data ) { |
3298 | 3298 | |
3299 | - if ( $data['recurring'] ) { |
|
3300 | - $recurring += $data['amount']; |
|
3301 | - } else { |
|
3302 | - $tax += $data['amount']; |
|
3303 | - } |
|
3299 | + if ( $data['recurring'] ) { |
|
3300 | + $recurring += $data['amount']; |
|
3301 | + } else { |
|
3302 | + $tax += $data['amount']; |
|
3303 | + } |
|
3304 | 3304 | |
3305 | - } |
|
3305 | + } |
|
3306 | 3306 | |
3307 | - if ( $this->is_renewal() ) { |
|
3308 | - $this->set_total_tax( $recurring ); |
|
3309 | - } else { |
|
3310 | - $this->set_total_tax( $tax ); |
|
3311 | - } |
|
3307 | + if ( $this->is_renewal() ) { |
|
3308 | + $this->set_total_tax( $recurring ); |
|
3309 | + } else { |
|
3310 | + $this->set_total_tax( $tax ); |
|
3311 | + } |
|
3312 | 3312 | |
3313 | - $this->totals['tax'] = array( |
|
3314 | - 'initial' => $tax, |
|
3315 | - 'recurring' => $recurring, |
|
3316 | - ); |
|
3313 | + $this->totals['tax'] = array( |
|
3314 | + 'initial' => $tax, |
|
3315 | + 'recurring' => $recurring, |
|
3316 | + ); |
|
3317 | 3317 | |
3318 | - return $this->is_renewal() ? $recurring : $tax; |
|
3318 | + return $this->is_renewal() ? $recurring : $tax; |
|
3319 | 3319 | |
3320 | 3320 | } |
3321 | 3321 | |
3322 | 3322 | /** |
3323 | - * Recalculates the invoice fees total. |
|
3324 | - * |
|
3325 | - * @since 1.0.19 |
|
3326 | - * @return float The recalculated fee |
|
3327 | - */ |
|
3328 | - public function recalculate_total_fees() { |
|
3329 | - $fees = $this->get_fees(); |
|
3330 | - $fee = 0; |
|
3331 | - $recurring = 0; |
|
3323 | + * Recalculates the invoice fees total. |
|
3324 | + * |
|
3325 | + * @since 1.0.19 |
|
3326 | + * @return float The recalculated fee |
|
3327 | + */ |
|
3328 | + public function recalculate_total_fees() { |
|
3329 | + $fees = $this->get_fees(); |
|
3330 | + $fee = 0; |
|
3331 | + $recurring = 0; |
|
3332 | 3332 | |
3333 | 3333 | foreach ( $fees as $data ) { |
3334 | 3334 | |
3335 | - if ( $data['recurring'] ) { |
|
3336 | - $recurring += $data['amount']; |
|
3337 | - } else { |
|
3338 | - $fee += $data['amount']; |
|
3339 | - } |
|
3335 | + if ( $data['recurring'] ) { |
|
3336 | + $recurring += $data['amount']; |
|
3337 | + } else { |
|
3338 | + $fee += $data['amount']; |
|
3339 | + } |
|
3340 | 3340 | |
3341 | - } |
|
3341 | + } |
|
3342 | 3342 | |
3343 | 3343 | if ( $this->is_renewal() ) { |
3344 | - $this->set_total_fees( $recurring ); |
|
3345 | - } else { |
|
3346 | - $this->set_total_fees( $fee ); |
|
3347 | - } |
|
3344 | + $this->set_total_fees( $recurring ); |
|
3345 | + } else { |
|
3346 | + $this->set_total_fees( $fee ); |
|
3347 | + } |
|
3348 | 3348 | |
3349 | - $this->totals['fee'] = array( |
|
3350 | - 'initial' => $fee, |
|
3351 | - 'recurring' => $recurring, |
|
3352 | - ); |
|
3349 | + $this->totals['fee'] = array( |
|
3350 | + 'initial' => $fee, |
|
3351 | + 'recurring' => $recurring, |
|
3352 | + ); |
|
3353 | 3353 | |
3354 | 3354 | $this->set_total_fees( $fee ); |
3355 | 3355 | return $this->is_renewal() ? $recurring : $fee; |
3356 | 3356 | } |
3357 | 3357 | |
3358 | 3358 | /** |
3359 | - * Recalculates the invoice total. |
|
3360 | - * |
|
3361 | - * @since 1.0.19 |
|
3359 | + * Recalculates the invoice total. |
|
3360 | + * |
|
3361 | + * @since 1.0.19 |
|
3362 | 3362 | * @return float The invoice total |
3363 | - */ |
|
3364 | - public function recalculate_total() { |
|
3363 | + */ |
|
3364 | + public function recalculate_total() { |
|
3365 | 3365 | $this->recalculate_subtotal(); |
3366 | 3366 | $this->recalculate_total_fees(); |
3367 | 3367 | $this->recalculate_total_discount(); |
3368 | 3368 | $this->recalculate_total_tax(); |
3369 | - return $this->get_total(); |
|
3370 | - } |
|
3369 | + return $this->get_total(); |
|
3370 | + } |
|
3371 | 3371 | |
3372 | - /** |
|
3373 | - * @deprecated |
|
3374 | - */ |
|
3372 | + /** |
|
3373 | + * @deprecated |
|
3374 | + */ |
|
3375 | 3375 | public function recalculate_totals( $temp = false ) { |
3376 | 3376 | $this->update_items( $temp ); |
3377 | 3377 | $this->save( true ); |
@@ -3435,9 +3435,9 @@ discard block |
||
3435 | 3435 | } |
3436 | 3436 | |
3437 | 3437 | return $note_id; |
3438 | - } |
|
3438 | + } |
|
3439 | 3439 | |
3440 | - /** |
|
3440 | + /** |
|
3441 | 3441 | * Generates a unique key for the invoice. |
3442 | 3442 | */ |
3443 | 3443 | public function generate_key( $string = '' ) { |
@@ -3458,106 +3458,106 @@ discard block |
||
3458 | 3458 | $number = $next_number; |
3459 | 3459 | } |
3460 | 3460 | |
3461 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
3461 | + $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
3462 | 3462 | |
3463 | - return $number; |
|
3464 | - } |
|
3463 | + return $number; |
|
3464 | + } |
|
3465 | 3465 | |
3466 | - /** |
|
3467 | - * Handle the status transition. |
|
3468 | - */ |
|
3469 | - protected function status_transition() { |
|
3470 | - $status_transition = $this->status_transition; |
|
3466 | + /** |
|
3467 | + * Handle the status transition. |
|
3468 | + */ |
|
3469 | + protected function status_transition() { |
|
3470 | + $status_transition = $this->status_transition; |
|
3471 | 3471 | |
3472 | - // Reset status transition variable. |
|
3473 | - $this->status_transition = false; |
|
3472 | + // Reset status transition variable. |
|
3473 | + $this->status_transition = false; |
|
3474 | 3474 | |
3475 | - if ( $status_transition ) { |
|
3476 | - try { |
|
3475 | + if ( $status_transition ) { |
|
3476 | + try { |
|
3477 | 3477 | |
3478 | - // Fire a hook for the status change. |
|
3479 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
3478 | + // Fire a hook for the status change. |
|
3479 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
3480 | 3480 | |
3481 | - // @deprecated this is deprecated and will be removed in the future. |
|
3482 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3481 | + // @deprecated this is deprecated and will be removed in the future. |
|
3482 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
3483 | 3483 | |
3484 | - if ( ! empty( $status_transition['from'] ) ) { |
|
3484 | + if ( ! empty( $status_transition['from'] ) ) { |
|
3485 | 3485 | |
3486 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
3487 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
3486 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
3487 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
3488 | 3488 | |
3489 | - // Fire another hook. |
|
3490 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
3491 | - do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
3489 | + // Fire another hook. |
|
3490 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
3491 | + do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this ); |
|
3492 | 3492 | |
3493 | - // @deprecated this is deprecated and will be removed in the future. |
|
3494 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->ID, $status_transition['from'] ); |
|
3493 | + // @deprecated this is deprecated and will be removed in the future. |
|
3494 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->ID, $status_transition['from'] ); |
|
3495 | 3495 | |
3496 | - // Note the transition occurred. |
|
3497 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3496 | + // Note the transition occurred. |
|
3497 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3498 | 3498 | |
3499 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3500 | - if ( |
|
3501 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed' ), true ) |
|
3502 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3503 | - ) { |
|
3504 | - do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition ); |
|
3505 | - } |
|
3506 | - } else { |
|
3507 | - /* translators: %s: new invoice status */ |
|
3508 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
3499 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
3500 | + if ( |
|
3501 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed' ), true ) |
|
3502 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
3503 | + ) { |
|
3504 | + do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition ); |
|
3505 | + } |
|
3506 | + } else { |
|
3507 | + /* translators: %s: new invoice status */ |
|
3508 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) ); |
|
3509 | 3509 | |
3510 | - // Note the transition occurred. |
|
3511 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3510 | + // Note the transition occurred. |
|
3511 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
3512 | 3512 | |
3513 | - } |
|
3514 | - } catch ( Exception $e ) { |
|
3515 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3516 | - } |
|
3517 | - } |
|
3518 | - } |
|
3513 | + } |
|
3514 | + } catch ( Exception $e ) { |
|
3515 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
3516 | + } |
|
3517 | + } |
|
3518 | + } |
|
3519 | 3519 | |
3520 | - /** |
|
3521 | - * Updates an invoice status. |
|
3522 | - */ |
|
3523 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3520 | + /** |
|
3521 | + * Updates an invoice status. |
|
3522 | + */ |
|
3523 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
3524 | 3524 | |
3525 | - // Fires before updating a status. |
|
3526 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $this->get_status( 'edit' ) ); |
|
3525 | + // Fires before updating a status. |
|
3526 | + do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $this->get_status( 'edit' ) ); |
|
3527 | 3527 | |
3528 | - // Update the status. |
|
3529 | - $this->set_status( $new_status, $note, $manual ); |
|
3528 | + // Update the status. |
|
3529 | + $this->set_status( $new_status, $note, $manual ); |
|
3530 | 3530 | |
3531 | - // Save the order. |
|
3532 | - return $this->save(); |
|
3531 | + // Save the order. |
|
3532 | + return $this->save(); |
|
3533 | 3533 | |
3534 | - } |
|
3534 | + } |
|
3535 | 3535 | |
3536 | - /** |
|
3537 | - * @deprecated |
|
3538 | - */ |
|
3539 | - public function refresh_item_ids() { |
|
3536 | + /** |
|
3537 | + * @deprecated |
|
3538 | + */ |
|
3539 | + public function refresh_item_ids() { |
|
3540 | 3540 | $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) ); |
3541 | 3541 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
3542 | - } |
|
3542 | + } |
|
3543 | 3543 | |
3544 | - /** |
|
3545 | - * @deprecated |
|
3546 | - */ |
|
3547 | - public function update_items( $temp = false ) { |
|
3544 | + /** |
|
3545 | + * @deprecated |
|
3546 | + */ |
|
3547 | + public function update_items( $temp = false ) { |
|
3548 | 3548 | |
3549 | - $this->set_items( $this->get_items() ); |
|
3549 | + $this->set_items( $this->get_items() ); |
|
3550 | 3550 | |
3551 | - if ( ! $temp ) { |
|
3552 | - $this->save(); |
|
3553 | - } |
|
3551 | + if ( ! $temp ) { |
|
3552 | + $this->save(); |
|
3553 | + } |
|
3554 | 3554 | |
3555 | 3555 | return $this; |
3556 | - } |
|
3556 | + } |
|
3557 | 3557 | |
3558 | - /** |
|
3559 | - * @deprecated |
|
3560 | - */ |
|
3558 | + /** |
|
3559 | + * @deprecated |
|
3560 | + */ |
|
3561 | 3561 | public function validate_discount() { |
3562 | 3562 | |
3563 | 3563 | $discount_code = $this->get_discount_code(); |
@@ -3573,25 +3573,25 @@ discard block |
||
3573 | 3573 | |
3574 | 3574 | } |
3575 | 3575 | |
3576 | - /** |
|
3577 | - * Refunds an invoice. |
|
3578 | - */ |
|
3576 | + /** |
|
3577 | + * Refunds an invoice. |
|
3578 | + */ |
|
3579 | 3579 | public function refund() { |
3580 | - $this->set_status( 'wpi-refunded' ); |
|
3580 | + $this->set_status( 'wpi-refunded' ); |
|
3581 | 3581 | $this->save(); |
3582 | 3582 | } |
3583 | 3583 | |
3584 | - /** |
|
3585 | - * Save data to the database. |
|
3586 | - * |
|
3587 | - * @since 1.0.19 |
|
3588 | - * @return int invoice ID |
|
3589 | - */ |
|
3590 | - public function save() { |
|
3591 | - $this->maybe_set_date_paid(); |
|
3592 | - parent::save(); |
|
3593 | - $this->status_transition(); |
|
3594 | - return $this->get_id(); |
|
3595 | - } |
|
3584 | + /** |
|
3585 | + * Save data to the database. |
|
3586 | + * |
|
3587 | + * @since 1.0.19 |
|
3588 | + * @return int invoice ID |
|
3589 | + */ |
|
3590 | + public function save() { |
|
3591 | + $this->maybe_set_date_paid(); |
|
3592 | + parent::save(); |
|
3593 | + $this->status_transition(); |
|
3594 | + return $this->get_id(); |
|
3595 | + } |
|
3596 | 3596 | |
3597 | 3597 | } |
@@ -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,60 +10,60 @@ discard block |
||
10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
11 | 11 | |
12 | 12 | /** |
13 | - * Stores a custom description for the item. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $custom_description = ''; |
|
18 | - |
|
19 | - /** |
|
20 | - * Stores the item quantity. |
|
21 | - * |
|
22 | - * @var int |
|
23 | - */ |
|
24 | - protected $quantity = 1; |
|
25 | - |
|
26 | - /** |
|
27 | - * Stores the item meta. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $meta = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Is this item required? |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $is_required = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * Are quantities allowed? |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $allow_quantities = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Associated invoice. |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - public $invoice_id = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * Item discount. |
|
56 | - * |
|
57 | - * @var float |
|
58 | - */ |
|
59 | - public $item_discount = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * Item tax. |
|
63 | - * |
|
64 | - * @var float |
|
65 | - */ |
|
66 | - public $item_tax = 0; |
|
13 | + * Stores a custom description for the item. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $custom_description = ''; |
|
18 | + |
|
19 | + /** |
|
20 | + * Stores the item quantity. |
|
21 | + * |
|
22 | + * @var int |
|
23 | + */ |
|
24 | + protected $quantity = 1; |
|
25 | + |
|
26 | + /** |
|
27 | + * Stores the item meta. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $meta = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Is this item required? |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $is_required = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * Are quantities allowed? |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $allow_quantities = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Associated invoice. |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + public $invoice_id = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * Item discount. |
|
56 | + * |
|
57 | + * @var float |
|
58 | + */ |
|
59 | + public $item_discount = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * Item tax. |
|
63 | + * |
|
64 | + * @var float |
|
65 | + */ |
|
66 | + public $item_tax = 0; |
|
67 | 67 | |
68 | 68 | /* |
69 | 69 | |-------------------------------------------------------------------------- |
@@ -81,208 +81,208 @@ discard block |
||
81 | 81 | */ |
82 | 82 | |
83 | 83 | /** |
84 | - * Get the item name. |
|
85 | - * |
|
86 | - * @since 1.0.19 |
|
87 | - * @param string $context View or edit context. |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the item description. |
|
97 | - * |
|
98 | - * @since 1.0.19 |
|
99 | - * @param string $context View or edit context. |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function get_description( $context = 'view' ) { |
|
103 | - |
|
104 | - if ( ! empty( $this->custom_description ) ) { |
|
105 | - return $this->custom_description; |
|
106 | - } |
|
107 | - |
|
108 | - return parent::get_description( $context ); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Returns the sub total. |
|
113 | - * |
|
114 | - * @since 1.0.19 |
|
115 | - * @param string $context View or edit context. |
|
116 | - * @return int |
|
117 | - */ |
|
118 | - public function get_sub_total( $context = 'view' ) { |
|
119 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns the recurring sub total. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - * @param string $context View or edit context. |
|
127 | - * @return int |
|
128 | - */ |
|
129 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @deprecated |
|
135 | - */ |
|
136 | - public function get_qantity( $context = 'view' ) { |
|
137 | - return $this->get_quantity( $context ); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Get the item quantity. |
|
142 | - * |
|
143 | - * @since 1.0.19 |
|
144 | - * @param string $context View or edit context. |
|
145 | - * @return int |
|
146 | - */ |
|
147 | - public function get_quantity( $context = 'view' ) { |
|
148 | - $quantity = (int) $this->quantity; |
|
149 | - |
|
150 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
151 | - $quantity = 1; |
|
152 | - } |
|
153 | - |
|
154 | - if ( 'view' == $context ) { |
|
155 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
156 | - } |
|
157 | - |
|
158 | - return $quantity; |
|
159 | - |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Get the item meta data. |
|
164 | - * |
|
165 | - * @since 1.0.19 |
|
166 | - * @param string $context View or edit context. |
|
167 | - * @return meta |
|
168 | - */ |
|
169 | - public function get_item_meta( $context = 'view' ) { |
|
170 | - $meta = $this->meta; |
|
171 | - |
|
172 | - if ( 'view' == $context ) { |
|
173 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
174 | - } |
|
175 | - |
|
176 | - return $meta; |
|
177 | - |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Returns whether or not customers can update the item quantity. |
|
182 | - * |
|
183 | - * @since 1.0.19 |
|
184 | - * @param string $context View or edit context. |
|
185 | - * @return bool |
|
186 | - */ |
|
187 | - public function get_allow_quantities( $context = 'view' ) { |
|
188 | - $allow_quantities = (bool) $this->allow_quantities; |
|
189 | - |
|
190 | - if ( 'view' == $context ) { |
|
191 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
192 | - } |
|
193 | - |
|
194 | - return $allow_quantities; |
|
195 | - |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Returns whether or not the item is required. |
|
200 | - * |
|
201 | - * @since 1.0.19 |
|
202 | - * @param string $context View or edit context. |
|
203 | - * @return bool |
|
204 | - */ |
|
205 | - public function get_is_required( $context = 'view' ) { |
|
206 | - $is_required = (bool) $this->is_required; |
|
207 | - |
|
208 | - if ( 'view' == $context ) { |
|
209 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
210 | - } |
|
211 | - |
|
212 | - return $is_required; |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Prepares form data for use. |
|
218 | - * |
|
219 | - * @since 1.0.19 |
|
220 | - * @return array |
|
221 | - */ |
|
222 | - public function prepare_data_for_use() { |
|
223 | - |
|
224 | - return array( |
|
225 | - 'title' => sanitize_text_field( $this->get_name() ), |
|
226 | - 'id' => $this->get_id(), |
|
227 | - 'price' => $this->get_price(), |
|
228 | - 'recurring' => $this->is_recurring(), |
|
229 | - 'description' => $this->get_description(), |
|
230 | - 'allow_quantities' => $this->allows_quantities(), |
|
231 | - 'required' => $this->is_required(), |
|
232 | - ); |
|
233 | - |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Prepares form data for ajax use. |
|
238 | - * |
|
239 | - * @since 1.0.19 |
|
240 | - * @return array |
|
241 | - */ |
|
242 | - public function prepare_data_for_invoice_edit_ajax() { |
|
243 | - |
|
244 | - return array( |
|
245 | - 'id' => $this->get_id(), |
|
246 | - 'texts' => array( |
|
247 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
248 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
249 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
250 | - 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ) ), |
|
251 | - 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ) ), |
|
252 | - ), |
|
253 | - 'inputs' => array( |
|
254 | - 'item-id' => $this->get_id(), |
|
255 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
256 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
257 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
258 | - 'item-price' => $this->get_price(), |
|
259 | - ) |
|
260 | - ); |
|
261 | - |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Prepares form data for saving (cart_details). |
|
266 | - * |
|
267 | - * @since 1.0.19 |
|
268 | - * @return array |
|
269 | - */ |
|
270 | - public function prepare_data_for_saving() { |
|
271 | - |
|
272 | - return array( |
|
273 | - 'post_id' => $this->invoice_id, |
|
274 | - 'item_id' => $this->get_id(), |
|
275 | - 'item_name' => sanitize_text_field( $this->get_name() ), |
|
276 | - 'item_description' => $this->get_description(), |
|
277 | - 'tax' => $this->item_tax, |
|
278 | - 'item_price' => $this->get_price(), |
|
279 | - 'quantity' => (int) $this->get_quantity(), |
|
280 | - 'discount' => $this->item_discount, |
|
281 | - 'subtotal' => $this->get_sub_total(), |
|
282 | - 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
283 | - 'meta' => $this->get_item_meta(), |
|
84 | + * Get the item name. |
|
85 | + * |
|
86 | + * @since 1.0.19 |
|
87 | + * @param string $context View or edit context. |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function get_name( $context = 'view' ) { |
|
91 | + $name = parent::get_name( $context ); |
|
92 | + return $name . wpinv_get_item_suffix( $this ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the item description. |
|
97 | + * |
|
98 | + * @since 1.0.19 |
|
99 | + * @param string $context View or edit context. |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function get_description( $context = 'view' ) { |
|
103 | + |
|
104 | + if ( ! empty( $this->custom_description ) ) { |
|
105 | + return $this->custom_description; |
|
106 | + } |
|
107 | + |
|
108 | + return parent::get_description( $context ); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Returns the sub total. |
|
113 | + * |
|
114 | + * @since 1.0.19 |
|
115 | + * @param string $context View or edit context. |
|
116 | + * @return int |
|
117 | + */ |
|
118 | + public function get_sub_total( $context = 'view' ) { |
|
119 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns the recurring sub total. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + * @param string $context View or edit context. |
|
127 | + * @return int |
|
128 | + */ |
|
129 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
130 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @deprecated |
|
135 | + */ |
|
136 | + public function get_qantity( $context = 'view' ) { |
|
137 | + return $this->get_quantity( $context ); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Get the item quantity. |
|
142 | + * |
|
143 | + * @since 1.0.19 |
|
144 | + * @param string $context View or edit context. |
|
145 | + * @return int |
|
146 | + */ |
|
147 | + public function get_quantity( $context = 'view' ) { |
|
148 | + $quantity = (int) $this->quantity; |
|
149 | + |
|
150 | + if ( empty( $quantity ) || 1 > $quantity ) { |
|
151 | + $quantity = 1; |
|
152 | + } |
|
153 | + |
|
154 | + if ( 'view' == $context ) { |
|
155 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
156 | + } |
|
157 | + |
|
158 | + return $quantity; |
|
159 | + |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Get the item meta data. |
|
164 | + * |
|
165 | + * @since 1.0.19 |
|
166 | + * @param string $context View or edit context. |
|
167 | + * @return meta |
|
168 | + */ |
|
169 | + public function get_item_meta( $context = 'view' ) { |
|
170 | + $meta = $this->meta; |
|
171 | + |
|
172 | + if ( 'view' == $context ) { |
|
173 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
174 | + } |
|
175 | + |
|
176 | + return $meta; |
|
177 | + |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Returns whether or not customers can update the item quantity. |
|
182 | + * |
|
183 | + * @since 1.0.19 |
|
184 | + * @param string $context View or edit context. |
|
185 | + * @return bool |
|
186 | + */ |
|
187 | + public function get_allow_quantities( $context = 'view' ) { |
|
188 | + $allow_quantities = (bool) $this->allow_quantities; |
|
189 | + |
|
190 | + if ( 'view' == $context ) { |
|
191 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
192 | + } |
|
193 | + |
|
194 | + return $allow_quantities; |
|
195 | + |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Returns whether or not the item is required. |
|
200 | + * |
|
201 | + * @since 1.0.19 |
|
202 | + * @param string $context View or edit context. |
|
203 | + * @return bool |
|
204 | + */ |
|
205 | + public function get_is_required( $context = 'view' ) { |
|
206 | + $is_required = (bool) $this->is_required; |
|
207 | + |
|
208 | + if ( 'view' == $context ) { |
|
209 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
210 | + } |
|
211 | + |
|
212 | + return $is_required; |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Prepares form data for use. |
|
218 | + * |
|
219 | + * @since 1.0.19 |
|
220 | + * @return array |
|
221 | + */ |
|
222 | + public function prepare_data_for_use() { |
|
223 | + |
|
224 | + return array( |
|
225 | + 'title' => sanitize_text_field( $this->get_name() ), |
|
226 | + 'id' => $this->get_id(), |
|
227 | + 'price' => $this->get_price(), |
|
228 | + 'recurring' => $this->is_recurring(), |
|
229 | + 'description' => $this->get_description(), |
|
230 | + 'allow_quantities' => $this->allows_quantities(), |
|
231 | + 'required' => $this->is_required(), |
|
232 | + ); |
|
233 | + |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Prepares form data for ajax use. |
|
238 | + * |
|
239 | + * @since 1.0.19 |
|
240 | + * @return array |
|
241 | + */ |
|
242 | + public function prepare_data_for_invoice_edit_ajax() { |
|
243 | + |
|
244 | + return array( |
|
245 | + 'id' => $this->get_id(), |
|
246 | + 'texts' => array( |
|
247 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
248 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
249 | + 'item-quantity' => absint( $this->get_quantity() ), |
|
250 | + 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ) ), |
|
251 | + 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ) ), |
|
252 | + ), |
|
253 | + 'inputs' => array( |
|
254 | + 'item-id' => $this->get_id(), |
|
255 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
256 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
257 | + 'item-quantity' => absint( $this->get_quantity() ), |
|
258 | + 'item-price' => $this->get_price(), |
|
259 | + ) |
|
260 | + ); |
|
261 | + |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Prepares form data for saving (cart_details). |
|
266 | + * |
|
267 | + * @since 1.0.19 |
|
268 | + * @return array |
|
269 | + */ |
|
270 | + public function prepare_data_for_saving() { |
|
271 | + |
|
272 | + return array( |
|
273 | + 'post_id' => $this->invoice_id, |
|
274 | + 'item_id' => $this->get_id(), |
|
275 | + 'item_name' => sanitize_text_field( $this->get_name() ), |
|
276 | + 'item_description' => $this->get_description(), |
|
277 | + 'tax' => $this->item_tax, |
|
278 | + 'item_price' => $this->get_price(), |
|
279 | + 'quantity' => (int) $this->get_quantity(), |
|
280 | + 'discount' => $this->item_discount, |
|
281 | + 'subtotal' => $this->get_sub_total(), |
|
282 | + 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
283 | + 'meta' => $this->get_item_meta(), |
|
284 | 284 | ); |
285 | - } |
|
285 | + } |
|
286 | 286 | |
287 | 287 | /* |
288 | 288 | |-------------------------------------------------------------------------- |
@@ -294,70 +294,70 @@ discard block |
||
294 | 294 | | object. |
295 | 295 | */ |
296 | 296 | |
297 | - /** |
|
298 | - * Set the item qantity. |
|
299 | - * |
|
300 | - * @since 1.0.19 |
|
301 | - * @param int $quantity The item quantity. |
|
302 | - */ |
|
303 | - public function set_quantity( $quantity ) { |
|
304 | - |
|
305 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
306 | - $quantity = 1; |
|
307 | - } |
|
308 | - |
|
309 | - $this->quantity = $quantity; |
|
310 | - |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Set the item meta data. |
|
315 | - * |
|
316 | - * @since 1.0.19 |
|
317 | - * @param array $meta The item meta data. |
|
318 | - */ |
|
319 | - public function set_item_meta( $meta ) { |
|
320 | - $this->meta = maybe_unserialize( $meta ); |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Set whether or not the quantities are allowed. |
|
325 | - * |
|
326 | - * @since 1.0.19 |
|
327 | - * @param bool $allow_quantities |
|
328 | - */ |
|
329 | - public function set_allow_quantities( $allow_quantities ) { |
|
330 | - $this->allow_quantities = (bool) $allow_quantities; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Set whether or not the item is required. |
|
335 | - * |
|
336 | - * @since 1.0.19 |
|
337 | - * @param bool $is_required |
|
338 | - */ |
|
339 | - public function set_is_required( $is_required ) { |
|
340 | - $this->is_required = (bool) $is_required; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Sets the custom item description. |
|
345 | - * |
|
346 | - * @since 1.0.19 |
|
347 | - * @param string $description |
|
348 | - */ |
|
349 | - public function set_custom_description( $description ) { |
|
350 | - $this->custom_description = $description; |
|
351 | - } |
|
297 | + /** |
|
298 | + * Set the item qantity. |
|
299 | + * |
|
300 | + * @since 1.0.19 |
|
301 | + * @param int $quantity The item quantity. |
|
302 | + */ |
|
303 | + public function set_quantity( $quantity ) { |
|
304 | + |
|
305 | + if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
306 | + $quantity = 1; |
|
307 | + } |
|
308 | + |
|
309 | + $this->quantity = $quantity; |
|
310 | + |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Set the item meta data. |
|
315 | + * |
|
316 | + * @since 1.0.19 |
|
317 | + * @param array $meta The item meta data. |
|
318 | + */ |
|
319 | + public function set_item_meta( $meta ) { |
|
320 | + $this->meta = maybe_unserialize( $meta ); |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Set whether or not the quantities are allowed. |
|
325 | + * |
|
326 | + * @since 1.0.19 |
|
327 | + * @param bool $allow_quantities |
|
328 | + */ |
|
329 | + public function set_allow_quantities( $allow_quantities ) { |
|
330 | + $this->allow_quantities = (bool) $allow_quantities; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Set whether or not the item is required. |
|
335 | + * |
|
336 | + * @since 1.0.19 |
|
337 | + * @param bool $is_required |
|
338 | + */ |
|
339 | + public function set_is_required( $is_required ) { |
|
340 | + $this->is_required = (bool) $is_required; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Sets the custom item description. |
|
345 | + * |
|
346 | + * @since 1.0.19 |
|
347 | + * @param string $description |
|
348 | + */ |
|
349 | + public function set_custom_description( $description ) { |
|
350 | + $this->custom_description = $description; |
|
351 | + } |
|
352 | 352 | |
353 | 353 | /** |
354 | 354 | * We do not want to save items to the database. |
355 | 355 | * |
356 | - * @return int item id |
|
356 | + * @return int item id |
|
357 | 357 | */ |
358 | 358 | public function save( $data = array() ) { |
359 | 359 | return $this->get_id(); |
360 | - } |
|
360 | + } |
|
361 | 361 | |
362 | 362 | /* |
363 | 363 | |-------------------------------------------------------------------------- |
@@ -369,23 +369,23 @@ discard block |
||
369 | 369 | */ |
370 | 370 | |
371 | 371 | /** |
372 | - * Checks whether the item has enabled dynamic pricing. |
|
373 | - * |
|
374 | - * @since 1.0.19 |
|
375 | - * @return bool |
|
376 | - */ |
|
377 | - public function is_required() { |
|
372 | + * Checks whether the item has enabled dynamic pricing. |
|
373 | + * |
|
374 | + * @since 1.0.19 |
|
375 | + * @return bool |
|
376 | + */ |
|
377 | + public function is_required() { |
|
378 | 378 | return (bool) $this->get_is_required(); |
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Checks whether users can edit the quantities. |
|
383 | - * |
|
384 | - * @since 1.0.19 |
|
385 | - * @return bool |
|
386 | - */ |
|
387 | - public function allows_quantities() { |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Checks whether users can edit the quantities. |
|
383 | + * |
|
384 | + * @since 1.0.19 |
|
385 | + * @return bool |
|
386 | + */ |
|
387 | + public function allows_quantities() { |
|
388 | 388 | return (bool) $this->get_allow_quantities(); |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | 391 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,179 +14,179 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Payment_Form_Data_Store extends GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Data stored in meta keys, but not considered "meta" for a form. |
|
19 | - * |
|
20 | - * @since 1.0.19 |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $internal_meta_keys = array( |
|
24 | - 'wpinv_form_elements', |
|
25 | - 'wpinv_form_items', |
|
26 | - 'wpinv_form_earned', |
|
27 | - 'wpinv_form_refunded', |
|
28 | - 'wpinv_form_cancelled', |
|
29 | - 'wpinv_form_failed' |
|
30 | - ); |
|
31 | - |
|
32 | - /** |
|
33 | - * A map of meta keys to data props. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $meta_key_to_props = array( |
|
40 | - 'wpinv_form_elements' => 'elements', |
|
41 | - 'wpinv_form_items' => 'items', |
|
42 | - 'wpinv_form_earned' => 'earned', |
|
43 | - 'wpinv_form_refunded' => 'refunded', |
|
44 | - 'wpinv_form_cancelled' => 'cancelled', |
|
45 | - 'wpinv_form_failed' => 'failed', |
|
46 | - ); |
|
47 | - |
|
48 | - /* |
|
17 | + /** |
|
18 | + * Data stored in meta keys, but not considered "meta" for a form. |
|
19 | + * |
|
20 | + * @since 1.0.19 |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $internal_meta_keys = array( |
|
24 | + 'wpinv_form_elements', |
|
25 | + 'wpinv_form_items', |
|
26 | + 'wpinv_form_earned', |
|
27 | + 'wpinv_form_refunded', |
|
28 | + 'wpinv_form_cancelled', |
|
29 | + 'wpinv_form_failed' |
|
30 | + ); |
|
31 | + |
|
32 | + /** |
|
33 | + * A map of meta keys to data props. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $meta_key_to_props = array( |
|
40 | + 'wpinv_form_elements' => 'elements', |
|
41 | + 'wpinv_form_items' => 'items', |
|
42 | + 'wpinv_form_earned' => 'earned', |
|
43 | + 'wpinv_form_refunded' => 'refunded', |
|
44 | + 'wpinv_form_cancelled' => 'cancelled', |
|
45 | + 'wpinv_form_failed' => 'failed', |
|
46 | + ); |
|
47 | + |
|
48 | + /* |
|
49 | 49 | |-------------------------------------------------------------------------- |
50 | 50 | | CRUD Methods |
51 | 51 | |-------------------------------------------------------------------------- |
52 | 52 | */ |
53 | 53 | |
54 | - /** |
|
55 | - * Method to create a new form in the database. |
|
56 | - * |
|
57 | - * @param GetPaid_Payment_Form $form Form object. |
|
58 | - */ |
|
59 | - public function create( &$form ) { |
|
60 | - $form->set_version( WPINV_VERSION ); |
|
61 | - $form->set_date_created( current_time('mysql') ); |
|
62 | - |
|
63 | - // Create a new post. |
|
64 | - $id = wp_insert_post( |
|
65 | - apply_filters( |
|
66 | - 'getpaid_new_payment_form_data', |
|
67 | - array( |
|
68 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
69 | - 'post_type' => 'wpi_payment_form', |
|
70 | - 'post_status' => $this->get_post_status( $form ), |
|
71 | - 'ping_status' => 'closed', |
|
72 | - 'post_author' => $form->get_author( 'edit' ), |
|
73 | - 'post_title' => $form->get_name( 'edit' ), |
|
74 | - ) |
|
75 | - ), |
|
76 | - true |
|
77 | - ); |
|
78 | - |
|
79 | - if ( $id && ! is_wp_error( $id ) ) { |
|
80 | - $form->set_id( $id ); |
|
81 | - $this->update_post_meta( $form ); |
|
82 | - $form->save_meta_data(); |
|
83 | - $form->apply_changes(); |
|
84 | - $this->clear_caches( $form ); |
|
85 | - do_action( 'getpaid_create_payment_form', $form->get_id(), $form ); |
|
86 | - return true; |
|
87 | - } |
|
88 | - |
|
89 | - if ( is_wp_error( $id ) ) { |
|
90 | - $form->last_error = $id->get_error_message(); |
|
91 | - } |
|
92 | - |
|
93 | - return false; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Method to read a form from the database. |
|
98 | - * |
|
99 | - * @param GetPaid_Payment_Form $form Form object. |
|
100 | - * |
|
101 | - */ |
|
102 | - public function read( &$form ) { |
|
103 | - |
|
104 | - $form->set_defaults(); |
|
105 | - $form_object = get_post( $form->get_id() ); |
|
106 | - |
|
107 | - if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
108 | - $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
109 | - $form->set_id( 0 ); |
|
110 | - return false; |
|
111 | - } |
|
112 | - |
|
113 | - $form->set_props( |
|
114 | - array( |
|
115 | - 'date_created' => 0 < $form_object->post_date ? $form_object->post_date : null, |
|
116 | - 'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null, |
|
117 | - 'status' => $form_object->post_status, |
|
118 | - 'name' => $form_object->post_title, |
|
119 | - 'author' => $form_object->post_author, |
|
120 | - ) |
|
121 | - ); |
|
122 | - |
|
123 | - $this->read_object_data( $form, $form_object ); |
|
124 | - $form->read_meta_data(); |
|
125 | - $form->set_object_read( true ); |
|
126 | - do_action( 'getpaid_read_payment_form', $form->get_id(), $form ); |
|
127 | - |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Method to update a form in the database. |
|
132 | - * |
|
133 | - * @param GetPaid_Payment_Form $form Form object. |
|
134 | - */ |
|
135 | - public function update( &$form ) { |
|
136 | - $form->save_meta_data(); |
|
137 | - $form->set_version( WPINV_VERSION ); |
|
138 | - |
|
139 | - if ( null === $form->get_date_created( 'edit' ) ) { |
|
140 | - $form->set_date_created( current_time('mysql') ); |
|
141 | - } |
|
142 | - |
|
143 | - // Grab the current status so we can compare. |
|
144 | - $previous_status = get_post_status( $form->get_id() ); |
|
145 | - |
|
146 | - $changes = $form->get_changes(); |
|
147 | - |
|
148 | - // Only update the post when the post data changes. |
|
149 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
150 | - $post_data = array( |
|
151 | - 'post_date' => $form->get_date_created( 'edit' ), |
|
152 | - 'post_status' => $form->get_status( 'edit' ), |
|
153 | - 'post_title' => $form->get_name( 'edit' ), |
|
154 | - 'post_author' => $form->get_author( 'edit' ), |
|
155 | - 'post_modified' => $form->get_date_modified( 'edit' ), |
|
156 | - ); |
|
157 | - |
|
158 | - /** |
|
159 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
160 | - * to update data, since wp_update_post spawns more calls to the |
|
161 | - * save_post action. |
|
162 | - * |
|
163 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
164 | - * or an update purely from CRUD. |
|
165 | - */ |
|
166 | - if ( doing_action( 'save_post' ) ) { |
|
167 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
168 | - clean_post_cache( $form->get_id() ); |
|
169 | - } else { |
|
170 | - wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
171 | - } |
|
172 | - $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
173 | - } |
|
174 | - $this->update_post_meta( $form ); |
|
175 | - $form->apply_changes(); |
|
176 | - $this->clear_caches( $form ); |
|
177 | - |
|
178 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
179 | - $new_status = $form->get_status( 'edit' ); |
|
180 | - |
|
181 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
182 | - do_action( 'getpaid_new_payment_form', $form->get_id(), $form ); |
|
183 | - } else { |
|
184 | - do_action( 'getpaid_update_payment_form', $form->get_id(), $form ); |
|
185 | - } |
|
186 | - |
|
187 | - } |
|
188 | - |
|
189 | - /* |
|
54 | + /** |
|
55 | + * Method to create a new form in the database. |
|
56 | + * |
|
57 | + * @param GetPaid_Payment_Form $form Form object. |
|
58 | + */ |
|
59 | + public function create( &$form ) { |
|
60 | + $form->set_version( WPINV_VERSION ); |
|
61 | + $form->set_date_created( current_time('mysql') ); |
|
62 | + |
|
63 | + // Create a new post. |
|
64 | + $id = wp_insert_post( |
|
65 | + apply_filters( |
|
66 | + 'getpaid_new_payment_form_data', |
|
67 | + array( |
|
68 | + 'post_date' => $form->get_date_created( 'edit' ), |
|
69 | + 'post_type' => 'wpi_payment_form', |
|
70 | + 'post_status' => $this->get_post_status( $form ), |
|
71 | + 'ping_status' => 'closed', |
|
72 | + 'post_author' => $form->get_author( 'edit' ), |
|
73 | + 'post_title' => $form->get_name( 'edit' ), |
|
74 | + ) |
|
75 | + ), |
|
76 | + true |
|
77 | + ); |
|
78 | + |
|
79 | + if ( $id && ! is_wp_error( $id ) ) { |
|
80 | + $form->set_id( $id ); |
|
81 | + $this->update_post_meta( $form ); |
|
82 | + $form->save_meta_data(); |
|
83 | + $form->apply_changes(); |
|
84 | + $this->clear_caches( $form ); |
|
85 | + do_action( 'getpaid_create_payment_form', $form->get_id(), $form ); |
|
86 | + return true; |
|
87 | + } |
|
88 | + |
|
89 | + if ( is_wp_error( $id ) ) { |
|
90 | + $form->last_error = $id->get_error_message(); |
|
91 | + } |
|
92 | + |
|
93 | + return false; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Method to read a form from the database. |
|
98 | + * |
|
99 | + * @param GetPaid_Payment_Form $form Form object. |
|
100 | + * |
|
101 | + */ |
|
102 | + public function read( &$form ) { |
|
103 | + |
|
104 | + $form->set_defaults(); |
|
105 | + $form_object = get_post( $form->get_id() ); |
|
106 | + |
|
107 | + if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) { |
|
108 | + $form->last_error = __( 'Invalid form.', 'invoicing' ); |
|
109 | + $form->set_id( 0 ); |
|
110 | + return false; |
|
111 | + } |
|
112 | + |
|
113 | + $form->set_props( |
|
114 | + array( |
|
115 | + 'date_created' => 0 < $form_object->post_date ? $form_object->post_date : null, |
|
116 | + 'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null, |
|
117 | + 'status' => $form_object->post_status, |
|
118 | + 'name' => $form_object->post_title, |
|
119 | + 'author' => $form_object->post_author, |
|
120 | + ) |
|
121 | + ); |
|
122 | + |
|
123 | + $this->read_object_data( $form, $form_object ); |
|
124 | + $form->read_meta_data(); |
|
125 | + $form->set_object_read( true ); |
|
126 | + do_action( 'getpaid_read_payment_form', $form->get_id(), $form ); |
|
127 | + |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Method to update a form in the database. |
|
132 | + * |
|
133 | + * @param GetPaid_Payment_Form $form Form object. |
|
134 | + */ |
|
135 | + public function update( &$form ) { |
|
136 | + $form->save_meta_data(); |
|
137 | + $form->set_version( WPINV_VERSION ); |
|
138 | + |
|
139 | + if ( null === $form->get_date_created( 'edit' ) ) { |
|
140 | + $form->set_date_created( current_time('mysql') ); |
|
141 | + } |
|
142 | + |
|
143 | + // Grab the current status so we can compare. |
|
144 | + $previous_status = get_post_status( $form->get_id() ); |
|
145 | + |
|
146 | + $changes = $form->get_changes(); |
|
147 | + |
|
148 | + // Only update the post when the post data changes. |
|
149 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
150 | + $post_data = array( |
|
151 | + 'post_date' => $form->get_date_created( 'edit' ), |
|
152 | + 'post_status' => $form->get_status( 'edit' ), |
|
153 | + 'post_title' => $form->get_name( 'edit' ), |
|
154 | + 'post_author' => $form->get_author( 'edit' ), |
|
155 | + 'post_modified' => $form->get_date_modified( 'edit' ), |
|
156 | + ); |
|
157 | + |
|
158 | + /** |
|
159 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
160 | + * to update data, since wp_update_post spawns more calls to the |
|
161 | + * save_post action. |
|
162 | + * |
|
163 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
164 | + * or an update purely from CRUD. |
|
165 | + */ |
|
166 | + if ( doing_action( 'save_post' ) ) { |
|
167 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) ); |
|
168 | + clean_post_cache( $form->get_id() ); |
|
169 | + } else { |
|
170 | + wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) ); |
|
171 | + } |
|
172 | + $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
173 | + } |
|
174 | + $this->update_post_meta( $form ); |
|
175 | + $form->apply_changes(); |
|
176 | + $this->clear_caches( $form ); |
|
177 | + |
|
178 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
179 | + $new_status = $form->get_status( 'edit' ); |
|
180 | + |
|
181 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
182 | + do_action( 'getpaid_new_payment_form', $form->get_id(), $form ); |
|
183 | + } else { |
|
184 | + do_action( 'getpaid_update_payment_form', $form->get_id(), $form ); |
|
185 | + } |
|
186 | + |
|
187 | + } |
|
188 | + |
|
189 | + /* |
|
190 | 190 | |-------------------------------------------------------------------------- |
191 | 191 | | Additional Methods |
192 | 192 | |-------------------------------------------------------------------------- |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,196 +15,196 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Discount_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpi_discount_code', |
|
26 | - '_wpi_discount_amount', |
|
27 | - '_wpi_discount_start', |
|
28 | - '_wpi_discount_expiration', |
|
29 | - '_wpi_discount_type', |
|
30 | - '_wpi_discount_uses', |
|
31 | - '_wpi_discount_is_single_use', |
|
32 | - '_wpi_discount_items', |
|
33 | - '_wpi_discount_excluded_items', |
|
34 | - '_wpi_discount_max_uses', |
|
35 | - '_wpi_discount_is_recurring', |
|
36 | - '_wpi_discount_min_total', |
|
37 | - '_wpi_discount_max_total', |
|
38 | - ); |
|
39 | - |
|
40 | - /** |
|
41 | - * A map of meta keys to data props. |
|
42 | - * |
|
43 | - * @since 1.0.19 |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $meta_key_to_props = array( |
|
48 | - '_wpi_discount_code' => 'code', |
|
49 | - '_wpi_discount_amount' => 'amount', |
|
50 | - '_wpi_discount_start' => 'start', |
|
51 | - '_wpi_discount_expiration' => 'expiration', |
|
52 | - '_wpi_discount_type' => 'type', |
|
53 | - '_wpi_discount_uses' => 'uses', |
|
54 | - '_wpi_discount_is_single_use' => 'is_single_use', |
|
55 | - '_wpi_discount_items' => 'items', |
|
56 | - '_wpi_discount_excluded_items' => 'excluded_items', |
|
57 | - '_wpi_discount_max_uses' => 'max_uses', |
|
58 | - '_wpi_discount_is_recurring' => 'is_recurring', |
|
59 | - '_wpi_discount_min_total' => 'min_total', |
|
60 | - '_wpi_discount_max_total' => 'max_total', |
|
61 | - ); |
|
62 | - |
|
63 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpi_discount_code', |
|
26 | + '_wpi_discount_amount', |
|
27 | + '_wpi_discount_start', |
|
28 | + '_wpi_discount_expiration', |
|
29 | + '_wpi_discount_type', |
|
30 | + '_wpi_discount_uses', |
|
31 | + '_wpi_discount_is_single_use', |
|
32 | + '_wpi_discount_items', |
|
33 | + '_wpi_discount_excluded_items', |
|
34 | + '_wpi_discount_max_uses', |
|
35 | + '_wpi_discount_is_recurring', |
|
36 | + '_wpi_discount_min_total', |
|
37 | + '_wpi_discount_max_total', |
|
38 | + ); |
|
39 | + |
|
40 | + /** |
|
41 | + * A map of meta keys to data props. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $meta_key_to_props = array( |
|
48 | + '_wpi_discount_code' => 'code', |
|
49 | + '_wpi_discount_amount' => 'amount', |
|
50 | + '_wpi_discount_start' => 'start', |
|
51 | + '_wpi_discount_expiration' => 'expiration', |
|
52 | + '_wpi_discount_type' => 'type', |
|
53 | + '_wpi_discount_uses' => 'uses', |
|
54 | + '_wpi_discount_is_single_use' => 'is_single_use', |
|
55 | + '_wpi_discount_items' => 'items', |
|
56 | + '_wpi_discount_excluded_items' => 'excluded_items', |
|
57 | + '_wpi_discount_max_uses' => 'max_uses', |
|
58 | + '_wpi_discount_is_recurring' => 'is_recurring', |
|
59 | + '_wpi_discount_min_total' => 'min_total', |
|
60 | + '_wpi_discount_max_total' => 'max_total', |
|
61 | + ); |
|
62 | + |
|
63 | + /* |
|
64 | 64 | |-------------------------------------------------------------------------- |
65 | 65 | | CRUD Methods |
66 | 66 | |-------------------------------------------------------------------------- |
67 | 67 | */ |
68 | 68 | |
69 | - /** |
|
70 | - * Method to create a new discount in the database. |
|
71 | - * |
|
72 | - * @param WPInv_Discount $discount Discount object. |
|
73 | - */ |
|
74 | - public function create( &$discount ) { |
|
75 | - $discount->set_version( WPINV_VERSION ); |
|
76 | - $discount->set_date_created( current_time('mysql') ); |
|
77 | - |
|
78 | - // Create a new post. |
|
79 | - $id = wp_insert_post( |
|
80 | - apply_filters( |
|
81 | - 'getpaid_new_discount_data', |
|
82 | - array( |
|
83 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
84 | - 'post_type' => 'wpi_discount', |
|
85 | - 'post_status' => $this->get_post_status( $discount ), |
|
86 | - 'ping_status' => 'closed', |
|
87 | - 'post_author' => $discount->get_author( 'edit' ), |
|
88 | - 'post_title' => $discount->get_name( 'edit' ), |
|
89 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
90 | - ) |
|
91 | - ), |
|
92 | - true |
|
93 | - ); |
|
94 | - |
|
95 | - if ( $id && ! is_wp_error( $id ) ) { |
|
96 | - $discount->set_id( $id ); |
|
97 | - $this->update_post_meta( $discount ); |
|
98 | - $discount->save_meta_data(); |
|
99 | - $discount->apply_changes(); |
|
100 | - $this->clear_caches( $discount ); |
|
101 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
102 | - return true; |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_wp_error( $id ) ) { |
|
106 | - $discount->last_error = $id->get_error_message(); |
|
107 | - } |
|
108 | - |
|
109 | - return false; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Method to read a discount from the database. |
|
114 | - * |
|
115 | - * @param WPInv_Discount $discount Discount object. |
|
116 | - * |
|
117 | - */ |
|
118 | - public function read( &$discount ) { |
|
119 | - |
|
120 | - $discount->set_defaults(); |
|
121 | - $discount_object = get_post( $discount->get_id() ); |
|
122 | - |
|
123 | - if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
124 | - $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
125 | - $discount->set_id( 0 ); |
|
126 | - return false; |
|
127 | - } |
|
128 | - |
|
129 | - $discount->set_props( |
|
130 | - array( |
|
131 | - 'date_created' => 0 < $discount_object->post_date ? $discount_object->post_date : null, |
|
132 | - 'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null, |
|
133 | - 'status' => $discount_object->post_status, |
|
134 | - 'name' => $discount_object->post_title, |
|
135 | - 'author' => $discount_object->post_author, |
|
136 | - 'description' => $discount_object->post_excerpt, |
|
137 | - ) |
|
138 | - ); |
|
139 | - |
|
140 | - $this->read_object_data( $discount, $discount_object ); |
|
141 | - $discount->read_meta_data(); |
|
142 | - $discount->set_object_read( true ); |
|
143 | - do_action( 'getpaid_read_discount', $discount->get_id(), $discount ); |
|
144 | - |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Method to update a discount in the database. |
|
149 | - * |
|
150 | - * @param WPInv_Discount $discount Discount object. |
|
151 | - */ |
|
152 | - public function update( &$discount ) { |
|
153 | - $discount->save_meta_data(); |
|
154 | - $discount->set_version( WPINV_VERSION ); |
|
155 | - |
|
156 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
157 | - $discount->set_date_created( current_time('mysql') ); |
|
158 | - } |
|
159 | - |
|
160 | - // Grab the current status so we can compare. |
|
161 | - $previous_status = get_post_status( $discount->get_id() ); |
|
162 | - |
|
163 | - $changes = $discount->get_changes(); |
|
164 | - |
|
165 | - // Only update the post when the post data changes. |
|
166 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
167 | - $post_data = array( |
|
168 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
169 | - 'post_status' => $discount->get_status( 'edit' ), |
|
170 | - 'post_title' => $discount->get_name( 'edit' ), |
|
171 | - 'post_author' => $discount->get_author( 'edit' ), |
|
172 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
173 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
174 | - ); |
|
175 | - |
|
176 | - /** |
|
177 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
178 | - * to update data, since wp_update_post spawns more calls to the |
|
179 | - * save_post action. |
|
180 | - * |
|
181 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
182 | - * or an update purely from CRUD. |
|
183 | - */ |
|
184 | - if ( doing_action( 'save_post' ) ) { |
|
185 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
186 | - clean_post_cache( $discount->get_id() ); |
|
187 | - } else { |
|
188 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
189 | - } |
|
190 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
191 | - } |
|
192 | - $this->update_post_meta( $discount ); |
|
193 | - $discount->apply_changes(); |
|
194 | - $this->clear_caches( $discount ); |
|
195 | - |
|
196 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
197 | - $new_status = $discount->get_status( 'edit' ); |
|
198 | - |
|
199 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
200 | - do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
201 | - } else { |
|
202 | - do_action( 'getpaid_update_discount', $discount->get_id(), $discount ); |
|
203 | - } |
|
204 | - |
|
205 | - } |
|
206 | - |
|
207 | - /* |
|
69 | + /** |
|
70 | + * Method to create a new discount in the database. |
|
71 | + * |
|
72 | + * @param WPInv_Discount $discount Discount object. |
|
73 | + */ |
|
74 | + public function create( &$discount ) { |
|
75 | + $discount->set_version( WPINV_VERSION ); |
|
76 | + $discount->set_date_created( current_time('mysql') ); |
|
77 | + |
|
78 | + // Create a new post. |
|
79 | + $id = wp_insert_post( |
|
80 | + apply_filters( |
|
81 | + 'getpaid_new_discount_data', |
|
82 | + array( |
|
83 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
84 | + 'post_type' => 'wpi_discount', |
|
85 | + 'post_status' => $this->get_post_status( $discount ), |
|
86 | + 'ping_status' => 'closed', |
|
87 | + 'post_author' => $discount->get_author( 'edit' ), |
|
88 | + 'post_title' => $discount->get_name( 'edit' ), |
|
89 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
90 | + ) |
|
91 | + ), |
|
92 | + true |
|
93 | + ); |
|
94 | + |
|
95 | + if ( $id && ! is_wp_error( $id ) ) { |
|
96 | + $discount->set_id( $id ); |
|
97 | + $this->update_post_meta( $discount ); |
|
98 | + $discount->save_meta_data(); |
|
99 | + $discount->apply_changes(); |
|
100 | + $this->clear_caches( $discount ); |
|
101 | + do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
102 | + return true; |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_wp_error( $id ) ) { |
|
106 | + $discount->last_error = $id->get_error_message(); |
|
107 | + } |
|
108 | + |
|
109 | + return false; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Method to read a discount from the database. |
|
114 | + * |
|
115 | + * @param WPInv_Discount $discount Discount object. |
|
116 | + * |
|
117 | + */ |
|
118 | + public function read( &$discount ) { |
|
119 | + |
|
120 | + $discount->set_defaults(); |
|
121 | + $discount_object = get_post( $discount->get_id() ); |
|
122 | + |
|
123 | + if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
124 | + $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
125 | + $discount->set_id( 0 ); |
|
126 | + return false; |
|
127 | + } |
|
128 | + |
|
129 | + $discount->set_props( |
|
130 | + array( |
|
131 | + 'date_created' => 0 < $discount_object->post_date ? $discount_object->post_date : null, |
|
132 | + 'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null, |
|
133 | + 'status' => $discount_object->post_status, |
|
134 | + 'name' => $discount_object->post_title, |
|
135 | + 'author' => $discount_object->post_author, |
|
136 | + 'description' => $discount_object->post_excerpt, |
|
137 | + ) |
|
138 | + ); |
|
139 | + |
|
140 | + $this->read_object_data( $discount, $discount_object ); |
|
141 | + $discount->read_meta_data(); |
|
142 | + $discount->set_object_read( true ); |
|
143 | + do_action( 'getpaid_read_discount', $discount->get_id(), $discount ); |
|
144 | + |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Method to update a discount in the database. |
|
149 | + * |
|
150 | + * @param WPInv_Discount $discount Discount object. |
|
151 | + */ |
|
152 | + public function update( &$discount ) { |
|
153 | + $discount->save_meta_data(); |
|
154 | + $discount->set_version( WPINV_VERSION ); |
|
155 | + |
|
156 | + if ( null === $discount->get_date_created( 'edit' ) ) { |
|
157 | + $discount->set_date_created( current_time('mysql') ); |
|
158 | + } |
|
159 | + |
|
160 | + // Grab the current status so we can compare. |
|
161 | + $previous_status = get_post_status( $discount->get_id() ); |
|
162 | + |
|
163 | + $changes = $discount->get_changes(); |
|
164 | + |
|
165 | + // Only update the post when the post data changes. |
|
166 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
167 | + $post_data = array( |
|
168 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
169 | + 'post_status' => $discount->get_status( 'edit' ), |
|
170 | + 'post_title' => $discount->get_name( 'edit' ), |
|
171 | + 'post_author' => $discount->get_author( 'edit' ), |
|
172 | + 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
173 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
174 | + ); |
|
175 | + |
|
176 | + /** |
|
177 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
178 | + * to update data, since wp_update_post spawns more calls to the |
|
179 | + * save_post action. |
|
180 | + * |
|
181 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
182 | + * or an update purely from CRUD. |
|
183 | + */ |
|
184 | + if ( doing_action( 'save_post' ) ) { |
|
185 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
186 | + clean_post_cache( $discount->get_id() ); |
|
187 | + } else { |
|
188 | + wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
189 | + } |
|
190 | + $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
191 | + } |
|
192 | + $this->update_post_meta( $discount ); |
|
193 | + $discount->apply_changes(); |
|
194 | + $this->clear_caches( $discount ); |
|
195 | + |
|
196 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
197 | + $new_status = $discount->get_status( 'edit' ); |
|
198 | + |
|
199 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
200 | + do_action( 'getpaid_new_discount', $discount->get_id(), $discount ); |
|
201 | + } else { |
|
202 | + do_action( 'getpaid_update_discount', $discount->get_id(), $discount ); |
|
203 | + } |
|
204 | + |
|
205 | + } |
|
206 | + |
|
207 | + /* |
|
208 | 208 | |-------------------------------------------------------------------------- |
209 | 209 | | Additional Methods |
210 | 210 | |-------------------------------------------------------------------------- |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | |
11 | 11 | if ( ! defined( 'ABSPATH' ) ) { |
12 | - exit; |
|
12 | + exit; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -21,356 +21,356 @@ discard block |
||
21 | 21 | */ |
22 | 22 | abstract class GetPaid_Data { |
23 | 23 | |
24 | - /** |
|
25 | - * ID for this object. |
|
26 | - * |
|
27 | - * @since 1.0.19 |
|
28 | - * @var int |
|
29 | - */ |
|
30 | - protected $id = 0; |
|
31 | - |
|
32 | - /** |
|
33 | - * Core data for this object. Name value pairs (name + default value). |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Core data changes for this object. |
|
42 | - * |
|
43 | - * @since 1.0.19 |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $changes = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * This is false until the object is read from the DB. |
|
50 | - * |
|
51 | - * @since 1.0.19 |
|
52 | - * @var bool |
|
53 | - */ |
|
54 | - protected $object_read = false; |
|
55 | - |
|
56 | - /** |
|
57 | - * This is the name of this object type. |
|
58 | - * |
|
59 | - * @since 1.0.19 |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - protected $object_type = 'data'; |
|
63 | - |
|
64 | - /** |
|
65 | - * Extra data for this object. Name value pairs (name + default value). |
|
66 | - * Used as a standard way for sub classes (like item types) to add |
|
67 | - * additional information to an inherited class. |
|
68 | - * |
|
69 | - * @since 1.0.19 |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - protected $extra_data = array(); |
|
73 | - |
|
74 | - /** |
|
75 | - * Set to _data on construct so we can track and reset data if needed. |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - protected $default_data = array(); |
|
81 | - |
|
82 | - /** |
|
83 | - * Contains a reference to the data store for this class. |
|
84 | - * |
|
85 | - * @since 1.0.19 |
|
86 | - * @var GetPaid_Data_Store |
|
87 | - */ |
|
88 | - protected $data_store; |
|
89 | - |
|
90 | - /** |
|
91 | - * Stores meta in cache for future reads. |
|
92 | - * A group must be set to to enable caching. |
|
93 | - * |
|
94 | - * @since 1.0.19 |
|
95 | - * @var string |
|
96 | - */ |
|
97 | - protected $cache_group = ''; |
|
98 | - |
|
99 | - /** |
|
100 | - * Stores the last error. |
|
101 | - * |
|
102 | - * @since 1.0.19 |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $last_error = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Stores additional meta data. |
|
109 | - * |
|
110 | - * @since 1.0.19 |
|
111 | - * @var array |
|
112 | - */ |
|
113 | - protected $meta_data = null; |
|
114 | - |
|
115 | - /** |
|
116 | - * Default constructor. |
|
117 | - * |
|
118 | - * @param int|object|array $read ID to load from the DB (optional) or already queried data. |
|
119 | - */ |
|
120 | - public function __construct( $read = 0 ) { |
|
121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
122 | - $this->default_data = $this->data; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Only store the object ID to avoid serializing the data object instance. |
|
127 | - * |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function __sleep() { |
|
131 | - return array( 'id' ); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Re-run the constructor with the object ID. |
|
136 | - * |
|
137 | - * If the object no longer exists, remove the ID. |
|
138 | - */ |
|
139 | - public function __wakeup() { |
|
140 | - try { |
|
141 | - $this->__construct( absint( $this->id ) ); |
|
142 | - } catch ( Exception $e ) { |
|
143 | - $this->set_id( 0 ); |
|
144 | - $this->set_object_read( true ); |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * When the object is cloned, make sure meta is duplicated correctly. |
|
150 | - * |
|
151 | - * @since 1.0.19 |
|
152 | - */ |
|
153 | - public function __clone() { |
|
154 | - $this->maybe_read_meta_data(); |
|
155 | - if ( ! empty( $this->meta_data ) ) { |
|
156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
158 | - if ( ! empty( $meta->id ) ) { |
|
159 | - $this->meta_data[ $array_key ]->id = null; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Get the data store. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @return object |
|
170 | - */ |
|
171 | - public function get_data_store() { |
|
172 | - return $this->data_store; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Get the object type. |
|
177 | - * |
|
178 | - * @since 1.0.19 |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function get_object_type() { |
|
182 | - return $this->object_type; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns the unique ID for this object. |
|
187 | - * |
|
188 | - * @since 1.0.19 |
|
189 | - * @return int |
|
190 | - */ |
|
191 | - public function get_id() { |
|
192 | - return $this->id; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Get form status. |
|
197 | - * |
|
198 | - * @since 1.0.19 |
|
199 | - * @param string $context View or edit context. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function get_status( $context = 'view' ) { |
|
203 | - return $this->get_prop( 'status', $context ); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Delete an object, set the ID to 0, and return result. |
|
208 | - * |
|
209 | - * @since 1.0.19 |
|
210 | - * @param bool $force_delete Should the data be deleted permanently. |
|
211 | - * @return bool result |
|
212 | - */ |
|
213 | - public function delete( $force_delete = false ) { |
|
214 | - if ( $this->data_store ) { |
|
215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | - $this->set_id( 0 ); |
|
217 | - return true; |
|
218 | - } |
|
219 | - return false; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Save should create or update based on object existence. |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @return int |
|
227 | - */ |
|
228 | - public function save() { |
|
229 | - if ( ! $this->data_store ) { |
|
230 | - return $this->get_id(); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
235 | - * |
|
236 | - * @param GetPaid_Data $this The object being saved. |
|
237 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
238 | - */ |
|
239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
240 | - |
|
241 | - if ( $this->get_id() ) { |
|
242 | - $this->data_store->update( $this ); |
|
243 | - } else { |
|
244 | - $this->data_store->create( $this ); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Trigger action after saving to the DB. |
|
249 | - * |
|
250 | - * @param GetPaid_Data $this The object being saved. |
|
251 | - * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
252 | - */ |
|
253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
254 | - |
|
255 | - return $this->get_id(); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Change data to JSON format. |
|
260 | - * |
|
261 | - * @since 1.0.19 |
|
262 | - * @return string Data in JSON format. |
|
263 | - */ |
|
264 | - public function __toString() { |
|
265 | - return wp_json_encode( $this->get_data() ); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Returns all data for this object. |
|
270 | - * |
|
271 | - * @since 1.0.19 |
|
272 | - * @return array |
|
273 | - */ |
|
274 | - public function get_data() { |
|
275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Returns array of expected data keys for this object. |
|
280 | - * |
|
281 | - * @since 1.0.19 |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function get_data_keys() { |
|
285 | - return array_keys( $this->data ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Returns all "extra" data keys for an object (for sub objects like item types). |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @return array |
|
293 | - */ |
|
294 | - public function get_extra_data_keys() { |
|
295 | - return array_keys( $this->extra_data ); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Filter null meta values from array. |
|
300 | - * |
|
301 | - * @since 1.0.19 |
|
302 | - * @param mixed $meta Meta value to check. |
|
303 | - * @return bool |
|
304 | - */ |
|
305 | - protected function filter_null_meta( $meta ) { |
|
306 | - return ! is_null( $meta->value ); |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Get All Meta Data. |
|
311 | - * |
|
312 | - * @since 1.0.19 |
|
313 | - * @return array of objects. |
|
314 | - */ |
|
315 | - public function get_meta_data() { |
|
316 | - $this->maybe_read_meta_data(); |
|
317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Check if the key is an internal one. |
|
322 | - * |
|
323 | - * @since 1.0.19 |
|
324 | - * @param string $key Key to check. |
|
325 | - * @return bool true if it's an internal key, false otherwise |
|
326 | - */ |
|
327 | - protected function is_internal_meta_key( $key ) { |
|
328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
329 | - |
|
330 | - if ( ! $internal_meta_key ) { |
|
331 | - return false; |
|
332 | - } |
|
333 | - |
|
334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
335 | - |
|
336 | - if ( ! $has_setter_or_getter ) { |
|
337 | - return false; |
|
338 | - } |
|
339 | - |
|
340 | - /* translators: %s: $key Key to check */ |
|
341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
342 | - |
|
343 | - return true; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Magic method for setting data fields. |
|
348 | - * |
|
349 | - * This method does not update custom fields in the database. |
|
350 | - * |
|
351 | - * @since 1.0.19 |
|
352 | - * @access public |
|
353 | - * |
|
354 | - */ |
|
355 | - public function __set( $key, $value ) { |
|
356 | - |
|
357 | - if ( 'id' == strtolower( $key ) ) { |
|
358 | - return $this->set_id( $value ); |
|
359 | - } |
|
360 | - |
|
361 | - if ( method_exists( $this, "set_$key") ) { |
|
362 | - |
|
363 | - /* translators: %s: $key Key to set */ |
|
364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
365 | - |
|
366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
367 | - } else { |
|
368 | - $this->set_prop( $key, $value ); |
|
369 | - } |
|
370 | - |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
24 | + /** |
|
25 | + * ID for this object. |
|
26 | + * |
|
27 | + * @since 1.0.19 |
|
28 | + * @var int |
|
29 | + */ |
|
30 | + protected $id = 0; |
|
31 | + |
|
32 | + /** |
|
33 | + * Core data for this object. Name value pairs (name + default value). |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Core data changes for this object. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $changes = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * This is false until the object is read from the DB. |
|
50 | + * |
|
51 | + * @since 1.0.19 |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + protected $object_read = false; |
|
55 | + |
|
56 | + /** |
|
57 | + * This is the name of this object type. |
|
58 | + * |
|
59 | + * @since 1.0.19 |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + protected $object_type = 'data'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Extra data for this object. Name value pairs (name + default value). |
|
66 | + * Used as a standard way for sub classes (like item types) to add |
|
67 | + * additional information to an inherited class. |
|
68 | + * |
|
69 | + * @since 1.0.19 |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $extra_data = array(); |
|
73 | + |
|
74 | + /** |
|
75 | + * Set to _data on construct so we can track and reset data if needed. |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + protected $default_data = array(); |
|
81 | + |
|
82 | + /** |
|
83 | + * Contains a reference to the data store for this class. |
|
84 | + * |
|
85 | + * @since 1.0.19 |
|
86 | + * @var GetPaid_Data_Store |
|
87 | + */ |
|
88 | + protected $data_store; |
|
89 | + |
|
90 | + /** |
|
91 | + * Stores meta in cache for future reads. |
|
92 | + * A group must be set to to enable caching. |
|
93 | + * |
|
94 | + * @since 1.0.19 |
|
95 | + * @var string |
|
96 | + */ |
|
97 | + protected $cache_group = ''; |
|
98 | + |
|
99 | + /** |
|
100 | + * Stores the last error. |
|
101 | + * |
|
102 | + * @since 1.0.19 |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $last_error = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Stores additional meta data. |
|
109 | + * |
|
110 | + * @since 1.0.19 |
|
111 | + * @var array |
|
112 | + */ |
|
113 | + protected $meta_data = null; |
|
114 | + |
|
115 | + /** |
|
116 | + * Default constructor. |
|
117 | + * |
|
118 | + * @param int|object|array $read ID to load from the DB (optional) or already queried data. |
|
119 | + */ |
|
120 | + public function __construct( $read = 0 ) { |
|
121 | + $this->data = array_merge( $this->data, $this->extra_data ); |
|
122 | + $this->default_data = $this->data; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Only store the object ID to avoid serializing the data object instance. |
|
127 | + * |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function __sleep() { |
|
131 | + return array( 'id' ); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Re-run the constructor with the object ID. |
|
136 | + * |
|
137 | + * If the object no longer exists, remove the ID. |
|
138 | + */ |
|
139 | + public function __wakeup() { |
|
140 | + try { |
|
141 | + $this->__construct( absint( $this->id ) ); |
|
142 | + } catch ( Exception $e ) { |
|
143 | + $this->set_id( 0 ); |
|
144 | + $this->set_object_read( true ); |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * When the object is cloned, make sure meta is duplicated correctly. |
|
150 | + * |
|
151 | + * @since 1.0.19 |
|
152 | + */ |
|
153 | + public function __clone() { |
|
154 | + $this->maybe_read_meta_data(); |
|
155 | + if ( ! empty( $this->meta_data ) ) { |
|
156 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | + $this->meta_data[ $array_key ] = clone $meta; |
|
158 | + if ( ! empty( $meta->id ) ) { |
|
159 | + $this->meta_data[ $array_key ]->id = null; |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Get the data store. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @return object |
|
170 | + */ |
|
171 | + public function get_data_store() { |
|
172 | + return $this->data_store; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Get the object type. |
|
177 | + * |
|
178 | + * @since 1.0.19 |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function get_object_type() { |
|
182 | + return $this->object_type; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns the unique ID for this object. |
|
187 | + * |
|
188 | + * @since 1.0.19 |
|
189 | + * @return int |
|
190 | + */ |
|
191 | + public function get_id() { |
|
192 | + return $this->id; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Get form status. |
|
197 | + * |
|
198 | + * @since 1.0.19 |
|
199 | + * @param string $context View or edit context. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function get_status( $context = 'view' ) { |
|
203 | + return $this->get_prop( 'status', $context ); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Delete an object, set the ID to 0, and return result. |
|
208 | + * |
|
209 | + * @since 1.0.19 |
|
210 | + * @param bool $force_delete Should the data be deleted permanently. |
|
211 | + * @return bool result |
|
212 | + */ |
|
213 | + public function delete( $force_delete = false ) { |
|
214 | + if ( $this->data_store ) { |
|
215 | + $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | + $this->set_id( 0 ); |
|
217 | + return true; |
|
218 | + } |
|
219 | + return false; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Save should create or update based on object existence. |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @return int |
|
227 | + */ |
|
228 | + public function save() { |
|
229 | + if ( ! $this->data_store ) { |
|
230 | + return $this->get_id(); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Trigger action before saving to the DB. Allows you to adjust object props before save. |
|
235 | + * |
|
236 | + * @param GetPaid_Data $this The object being saved. |
|
237 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
238 | + */ |
|
239 | + do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
240 | + |
|
241 | + if ( $this->get_id() ) { |
|
242 | + $this->data_store->update( $this ); |
|
243 | + } else { |
|
244 | + $this->data_store->create( $this ); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Trigger action after saving to the DB. |
|
249 | + * |
|
250 | + * @param GetPaid_Data $this The object being saved. |
|
251 | + * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
|
252 | + */ |
|
253 | + do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
254 | + |
|
255 | + return $this->get_id(); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Change data to JSON format. |
|
260 | + * |
|
261 | + * @since 1.0.19 |
|
262 | + * @return string Data in JSON format. |
|
263 | + */ |
|
264 | + public function __toString() { |
|
265 | + return wp_json_encode( $this->get_data() ); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Returns all data for this object. |
|
270 | + * |
|
271 | + * @since 1.0.19 |
|
272 | + * @return array |
|
273 | + */ |
|
274 | + public function get_data() { |
|
275 | + return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Returns array of expected data keys for this object. |
|
280 | + * |
|
281 | + * @since 1.0.19 |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function get_data_keys() { |
|
285 | + return array_keys( $this->data ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Returns all "extra" data keys for an object (for sub objects like item types). |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @return array |
|
293 | + */ |
|
294 | + public function get_extra_data_keys() { |
|
295 | + return array_keys( $this->extra_data ); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Filter null meta values from array. |
|
300 | + * |
|
301 | + * @since 1.0.19 |
|
302 | + * @param mixed $meta Meta value to check. |
|
303 | + * @return bool |
|
304 | + */ |
|
305 | + protected function filter_null_meta( $meta ) { |
|
306 | + return ! is_null( $meta->value ); |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Get All Meta Data. |
|
311 | + * |
|
312 | + * @since 1.0.19 |
|
313 | + * @return array of objects. |
|
314 | + */ |
|
315 | + public function get_meta_data() { |
|
316 | + $this->maybe_read_meta_data(); |
|
317 | + return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Check if the key is an internal one. |
|
322 | + * |
|
323 | + * @since 1.0.19 |
|
324 | + * @param string $key Key to check. |
|
325 | + * @return bool true if it's an internal key, false otherwise |
|
326 | + */ |
|
327 | + protected function is_internal_meta_key( $key ) { |
|
328 | + $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
329 | + |
|
330 | + if ( ! $internal_meta_key ) { |
|
331 | + return false; |
|
332 | + } |
|
333 | + |
|
334 | + $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
335 | + |
|
336 | + if ( ! $has_setter_or_getter ) { |
|
337 | + return false; |
|
338 | + } |
|
339 | + |
|
340 | + /* translators: %s: $key Key to check */ |
|
341 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
342 | + |
|
343 | + return true; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Magic method for setting data fields. |
|
348 | + * |
|
349 | + * This method does not update custom fields in the database. |
|
350 | + * |
|
351 | + * @since 1.0.19 |
|
352 | + * @access public |
|
353 | + * |
|
354 | + */ |
|
355 | + public function __set( $key, $value ) { |
|
356 | + |
|
357 | + if ( 'id' == strtolower( $key ) ) { |
|
358 | + return $this->set_id( $value ); |
|
359 | + } |
|
360 | + |
|
361 | + if ( method_exists( $this, "set_$key") ) { |
|
362 | + |
|
363 | + /* translators: %s: $key Key to set */ |
|
364 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
365 | + |
|
366 | + call_user_func( array( $this, "set_$key" ), $value ); |
|
367 | + } else { |
|
368 | + $this->set_prop( $key, $value ); |
|
369 | + } |
|
370 | + |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | 374 | * Margic method for retrieving a property. |
375 | 375 | */ |
376 | 376 | public function __get( $key ) { |
@@ -378,10 +378,10 @@ discard block |
||
378 | 378 | // Check if we have a helper method for that. |
379 | 379 | if ( method_exists( $this, 'get_' . $key ) ) { |
380 | 380 | |
381 | - if ( 'post_type' != $key ) { |
|
382 | - /* translators: %s: $key Key to set */ |
|
383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
384 | - } |
|
381 | + if ( 'post_type' != $key ) { |
|
382 | + /* translators: %s: $key Key to set */ |
|
383 | + getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
384 | + } |
|
385 | 385 | |
386 | 386 | return call_user_func( array( $this, 'get_' . $key ) ); |
387 | 387 | } |
@@ -391,497 +391,497 @@ discard block |
||
391 | 391 | return $this->post->$key; |
392 | 392 | } |
393 | 393 | |
394 | - return $this->get_prop( $key ); |
|
395 | - |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Get Meta Data by Key. |
|
400 | - * |
|
401 | - * @since 1.0.19 |
|
402 | - * @param string $key Meta Key. |
|
403 | - * @param bool $single return first found meta with key, or all with $key. |
|
404 | - * @param string $context What the value is for. Valid values are view and edit. |
|
405 | - * @return mixed |
|
406 | - */ |
|
407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
408 | - |
|
409 | - // Check if this is an internal meta key. |
|
410 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
411 | - $function = 'get_' . $key; |
|
412 | - |
|
413 | - if ( is_callable( array( $this, $function ) ) ) { |
|
414 | - return $this->{$function}(); |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - // Read the meta data if not yet read. |
|
419 | - $this->maybe_read_meta_data(); |
|
420 | - $meta_data = $this->get_meta_data(); |
|
421 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
422 | - $value = $single ? '' : array(); |
|
423 | - |
|
424 | - if ( ! empty( $array_keys ) ) { |
|
425 | - // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
426 | - if ( $single ) { |
|
427 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
428 | - } else { |
|
429 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
430 | - } |
|
431 | - } |
|
432 | - |
|
433 | - if ( 'view' === $context ) { |
|
434 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
435 | - } |
|
436 | - |
|
437 | - return $value; |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * See if meta data exists, since get_meta always returns a '' or array(). |
|
442 | - * |
|
443 | - * @since 1.0.19 |
|
444 | - * @param string $key Meta Key. |
|
445 | - * @return boolean |
|
446 | - */ |
|
447 | - public function meta_exists( $key = '' ) { |
|
448 | - $this->maybe_read_meta_data(); |
|
449 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
450 | - return in_array( $key, $array_keys, true ); |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Set all meta data from array. |
|
455 | - * |
|
456 | - * @since 1.0.19 |
|
457 | - * @param array $data Key/Value pairs. |
|
458 | - */ |
|
459 | - public function set_meta_data( $data ) { |
|
460 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
461 | - $this->maybe_read_meta_data(); |
|
462 | - foreach ( $data as $meta ) { |
|
463 | - $meta = (array) $meta; |
|
464 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
465 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
466 | - array( |
|
467 | - 'id' => $meta['id'], |
|
468 | - 'key' => $meta['key'], |
|
469 | - 'value' => $meta['value'], |
|
470 | - ) |
|
471 | - ); |
|
472 | - } |
|
473 | - } |
|
474 | - } |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Add meta data. |
|
479 | - * |
|
480 | - * @since 1.0.19 |
|
481 | - * |
|
482 | - * @param string $key Meta key. |
|
483 | - * @param string|array $value Meta value. |
|
484 | - * @param bool $unique Should this be a unique key?. |
|
485 | - */ |
|
486 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
487 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
488 | - $function = 'set_' . $key; |
|
489 | - |
|
490 | - if ( is_callable( array( $this, $function ) ) ) { |
|
491 | - return $this->{$function}( $value ); |
|
492 | - } |
|
493 | - } |
|
494 | - |
|
495 | - $this->maybe_read_meta_data(); |
|
496 | - if ( $unique ) { |
|
497 | - $this->delete_meta_data( $key ); |
|
498 | - } |
|
499 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
500 | - array( |
|
501 | - 'key' => $key, |
|
502 | - 'value' => $value, |
|
503 | - ) |
|
504 | - ); |
|
505 | - } |
|
506 | - |
|
507 | - /** |
|
508 | - * Update meta data by key or ID, if provided. |
|
509 | - * |
|
510 | - * @since 1.0.19 |
|
511 | - * |
|
512 | - * @param string $key Meta key. |
|
513 | - * @param string|array $value Meta value. |
|
514 | - * @param int $meta_id Meta ID. |
|
515 | - */ |
|
516 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
517 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
518 | - $function = 'set_' . $key; |
|
519 | - |
|
520 | - if ( is_callable( array( $this, $function ) ) ) { |
|
521 | - return $this->{$function}( $value ); |
|
522 | - } |
|
523 | - } |
|
524 | - |
|
525 | - $this->maybe_read_meta_data(); |
|
526 | - |
|
527 | - $array_key = false; |
|
528 | - |
|
529 | - if ( $meta_id ) { |
|
530 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
531 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
532 | - } else { |
|
533 | - // Find matches by key. |
|
534 | - $matches = array(); |
|
535 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
536 | - if ( $meta->key === $key ) { |
|
537 | - $matches[] = $meta_data_array_key; |
|
538 | - } |
|
539 | - } |
|
540 | - |
|
541 | - if ( ! empty( $matches ) ) { |
|
542 | - // Set matches to null so only one key gets the new value. |
|
543 | - foreach ( $matches as $meta_data_array_key ) { |
|
544 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
545 | - } |
|
546 | - $array_key = current( $matches ); |
|
547 | - } |
|
548 | - } |
|
549 | - |
|
550 | - if ( false !== $array_key ) { |
|
551 | - $meta = $this->meta_data[ $array_key ]; |
|
552 | - $meta->key = $key; |
|
553 | - $meta->value = $value; |
|
554 | - } else { |
|
555 | - $this->add_meta_data( $key, $value, true ); |
|
556 | - } |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * Delete meta data. |
|
561 | - * |
|
562 | - * @since 1.0.19 |
|
563 | - * @param string $key Meta key. |
|
564 | - */ |
|
565 | - public function delete_meta_data( $key ) { |
|
566 | - $this->maybe_read_meta_data(); |
|
567 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
568 | - |
|
569 | - if ( $array_keys ) { |
|
570 | - foreach ( $array_keys as $array_key ) { |
|
571 | - $this->meta_data[ $array_key ]->value = null; |
|
572 | - } |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * Delete meta data. |
|
578 | - * |
|
579 | - * @since 1.0.19 |
|
580 | - * @param int $mid Meta ID. |
|
581 | - */ |
|
582 | - public function delete_meta_data_by_mid( $mid ) { |
|
583 | - $this->maybe_read_meta_data(); |
|
584 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
585 | - |
|
586 | - if ( $array_keys ) { |
|
587 | - foreach ( $array_keys as $array_key ) { |
|
588 | - $this->meta_data[ $array_key ]->value = null; |
|
589 | - } |
|
590 | - } |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * Read meta data if null. |
|
595 | - * |
|
596 | - * @since 1.0.19 |
|
597 | - */ |
|
598 | - protected function maybe_read_meta_data() { |
|
599 | - if ( is_null( $this->meta_data ) ) { |
|
600 | - $this->read_meta_data(); |
|
601 | - } |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Read Meta Data from the database. Ignore any internal properties. |
|
606 | - * Uses it's own caches because get_metadata does not provide meta_ids. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param bool $force_read True to force a new DB read (and update cache). |
|
610 | - */ |
|
611 | - public function read_meta_data( $force_read = false ) { |
|
612 | - $this->meta_data = array(); |
|
613 | - $cache_loaded = false; |
|
614 | - |
|
615 | - if ( ! $this->get_id() ) { |
|
616 | - return; |
|
617 | - } |
|
618 | - |
|
619 | - if ( ! $this->data_store ) { |
|
620 | - return; |
|
621 | - } |
|
622 | - |
|
623 | - if ( ! empty( $this->cache_group ) ) { |
|
624 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
625 | - } |
|
626 | - |
|
627 | - if ( ! $force_read ) { |
|
628 | - if ( ! empty( $this->cache_group ) ) { |
|
629 | - $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | - $cache_loaded = ! empty( $cached_meta ); |
|
631 | - } |
|
632 | - } |
|
633 | - |
|
634 | - $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
635 | - if ( $raw_meta_data ) { |
|
636 | - foreach ( $raw_meta_data as $meta ) { |
|
637 | - $this->meta_data[] = new GetPaid_Meta_Data( |
|
638 | - array( |
|
639 | - 'id' => (int) $meta->meta_id, |
|
640 | - 'key' => $meta->meta_key, |
|
641 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
642 | - ) |
|
643 | - ); |
|
644 | - } |
|
645 | - |
|
646 | - if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
647 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
648 | - } |
|
649 | - } |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * Update Meta Data in the database. |
|
654 | - * |
|
655 | - * @since 1.0.19 |
|
656 | - */ |
|
657 | - public function save_meta_data() { |
|
658 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
659 | - return; |
|
660 | - } |
|
661 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
662 | - if ( is_null( $meta->value ) ) { |
|
663 | - if ( ! empty( $meta->id ) ) { |
|
664 | - $this->data_store->delete_meta( $this, $meta ); |
|
665 | - unset( $this->meta_data[ $array_key ] ); |
|
666 | - } |
|
667 | - } elseif ( empty( $meta->id ) ) { |
|
668 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
669 | - $meta->apply_changes(); |
|
670 | - } else { |
|
671 | - if ( $meta->get_changes() ) { |
|
672 | - $this->data_store->update_meta( $this, $meta ); |
|
673 | - $meta->apply_changes(); |
|
674 | - } |
|
675 | - } |
|
676 | - } |
|
677 | - if ( ! empty( $this->cache_group ) ) { |
|
678 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
679 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
680 | - } |
|
681 | - } |
|
682 | - |
|
683 | - /** |
|
684 | - * Set ID. |
|
685 | - * |
|
686 | - * @since 1.0.19 |
|
687 | - * @param int $id ID. |
|
688 | - */ |
|
689 | - public function set_id( $id ) { |
|
690 | - $this->id = absint( $id ); |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Sets item status. |
|
695 | - * |
|
696 | - * @since 1.0.19 |
|
697 | - * @param string $status New status. |
|
698 | - * @return array details of change. |
|
699 | - */ |
|
700 | - public function set_status( $status ) { |
|
394 | + return $this->get_prop( $key ); |
|
395 | + |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Get Meta Data by Key. |
|
400 | + * |
|
401 | + * @since 1.0.19 |
|
402 | + * @param string $key Meta Key. |
|
403 | + * @param bool $single return first found meta with key, or all with $key. |
|
404 | + * @param string $context What the value is for. Valid values are view and edit. |
|
405 | + * @return mixed |
|
406 | + */ |
|
407 | + public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
408 | + |
|
409 | + // Check if this is an internal meta key. |
|
410 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
411 | + $function = 'get_' . $key; |
|
412 | + |
|
413 | + if ( is_callable( array( $this, $function ) ) ) { |
|
414 | + return $this->{$function}(); |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + // Read the meta data if not yet read. |
|
419 | + $this->maybe_read_meta_data(); |
|
420 | + $meta_data = $this->get_meta_data(); |
|
421 | + $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
422 | + $value = $single ? '' : array(); |
|
423 | + |
|
424 | + if ( ! empty( $array_keys ) ) { |
|
425 | + // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
|
426 | + if ( $single ) { |
|
427 | + $value = $meta_data[ current( $array_keys ) ]->value; |
|
428 | + } else { |
|
429 | + $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
430 | + } |
|
431 | + } |
|
432 | + |
|
433 | + if ( 'view' === $context ) { |
|
434 | + $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
435 | + } |
|
436 | + |
|
437 | + return $value; |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * See if meta data exists, since get_meta always returns a '' or array(). |
|
442 | + * |
|
443 | + * @since 1.0.19 |
|
444 | + * @param string $key Meta Key. |
|
445 | + * @return boolean |
|
446 | + */ |
|
447 | + public function meta_exists( $key = '' ) { |
|
448 | + $this->maybe_read_meta_data(); |
|
449 | + $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
450 | + return in_array( $key, $array_keys, true ); |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Set all meta data from array. |
|
455 | + * |
|
456 | + * @since 1.0.19 |
|
457 | + * @param array $data Key/Value pairs. |
|
458 | + */ |
|
459 | + public function set_meta_data( $data ) { |
|
460 | + if ( ! empty( $data ) && is_array( $data ) ) { |
|
461 | + $this->maybe_read_meta_data(); |
|
462 | + foreach ( $data as $meta ) { |
|
463 | + $meta = (array) $meta; |
|
464 | + if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
465 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
466 | + array( |
|
467 | + 'id' => $meta['id'], |
|
468 | + 'key' => $meta['key'], |
|
469 | + 'value' => $meta['value'], |
|
470 | + ) |
|
471 | + ); |
|
472 | + } |
|
473 | + } |
|
474 | + } |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Add meta data. |
|
479 | + * |
|
480 | + * @since 1.0.19 |
|
481 | + * |
|
482 | + * @param string $key Meta key. |
|
483 | + * @param string|array $value Meta value. |
|
484 | + * @param bool $unique Should this be a unique key?. |
|
485 | + */ |
|
486 | + public function add_meta_data( $key, $value, $unique = false ) { |
|
487 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
488 | + $function = 'set_' . $key; |
|
489 | + |
|
490 | + if ( is_callable( array( $this, $function ) ) ) { |
|
491 | + return $this->{$function}( $value ); |
|
492 | + } |
|
493 | + } |
|
494 | + |
|
495 | + $this->maybe_read_meta_data(); |
|
496 | + if ( $unique ) { |
|
497 | + $this->delete_meta_data( $key ); |
|
498 | + } |
|
499 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
500 | + array( |
|
501 | + 'key' => $key, |
|
502 | + 'value' => $value, |
|
503 | + ) |
|
504 | + ); |
|
505 | + } |
|
506 | + |
|
507 | + /** |
|
508 | + * Update meta data by key or ID, if provided. |
|
509 | + * |
|
510 | + * @since 1.0.19 |
|
511 | + * |
|
512 | + * @param string $key Meta key. |
|
513 | + * @param string|array $value Meta value. |
|
514 | + * @param int $meta_id Meta ID. |
|
515 | + */ |
|
516 | + public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
517 | + if ( $this->is_internal_meta_key( $key ) ) { |
|
518 | + $function = 'set_' . $key; |
|
519 | + |
|
520 | + if ( is_callable( array( $this, $function ) ) ) { |
|
521 | + return $this->{$function}( $value ); |
|
522 | + } |
|
523 | + } |
|
524 | + |
|
525 | + $this->maybe_read_meta_data(); |
|
526 | + |
|
527 | + $array_key = false; |
|
528 | + |
|
529 | + if ( $meta_id ) { |
|
530 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
531 | + $array_key = $array_keys ? current( $array_keys ) : false; |
|
532 | + } else { |
|
533 | + // Find matches by key. |
|
534 | + $matches = array(); |
|
535 | + foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
536 | + if ( $meta->key === $key ) { |
|
537 | + $matches[] = $meta_data_array_key; |
|
538 | + } |
|
539 | + } |
|
540 | + |
|
541 | + if ( ! empty( $matches ) ) { |
|
542 | + // Set matches to null so only one key gets the new value. |
|
543 | + foreach ( $matches as $meta_data_array_key ) { |
|
544 | + $this->meta_data[ $meta_data_array_key ]->value = null; |
|
545 | + } |
|
546 | + $array_key = current( $matches ); |
|
547 | + } |
|
548 | + } |
|
549 | + |
|
550 | + if ( false !== $array_key ) { |
|
551 | + $meta = $this->meta_data[ $array_key ]; |
|
552 | + $meta->key = $key; |
|
553 | + $meta->value = $value; |
|
554 | + } else { |
|
555 | + $this->add_meta_data( $key, $value, true ); |
|
556 | + } |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * Delete meta data. |
|
561 | + * |
|
562 | + * @since 1.0.19 |
|
563 | + * @param string $key Meta key. |
|
564 | + */ |
|
565 | + public function delete_meta_data( $key ) { |
|
566 | + $this->maybe_read_meta_data(); |
|
567 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
568 | + |
|
569 | + if ( $array_keys ) { |
|
570 | + foreach ( $array_keys as $array_key ) { |
|
571 | + $this->meta_data[ $array_key ]->value = null; |
|
572 | + } |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * Delete meta data. |
|
578 | + * |
|
579 | + * @since 1.0.19 |
|
580 | + * @param int $mid Meta ID. |
|
581 | + */ |
|
582 | + public function delete_meta_data_by_mid( $mid ) { |
|
583 | + $this->maybe_read_meta_data(); |
|
584 | + $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
585 | + |
|
586 | + if ( $array_keys ) { |
|
587 | + foreach ( $array_keys as $array_key ) { |
|
588 | + $this->meta_data[ $array_key ]->value = null; |
|
589 | + } |
|
590 | + } |
|
591 | + } |
|
592 | + |
|
593 | + /** |
|
594 | + * Read meta data if null. |
|
595 | + * |
|
596 | + * @since 1.0.19 |
|
597 | + */ |
|
598 | + protected function maybe_read_meta_data() { |
|
599 | + if ( is_null( $this->meta_data ) ) { |
|
600 | + $this->read_meta_data(); |
|
601 | + } |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Read Meta Data from the database. Ignore any internal properties. |
|
606 | + * Uses it's own caches because get_metadata does not provide meta_ids. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param bool $force_read True to force a new DB read (and update cache). |
|
610 | + */ |
|
611 | + public function read_meta_data( $force_read = false ) { |
|
612 | + $this->meta_data = array(); |
|
613 | + $cache_loaded = false; |
|
614 | + |
|
615 | + if ( ! $this->get_id() ) { |
|
616 | + return; |
|
617 | + } |
|
618 | + |
|
619 | + if ( ! $this->data_store ) { |
|
620 | + return; |
|
621 | + } |
|
622 | + |
|
623 | + if ( ! empty( $this->cache_group ) ) { |
|
624 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
625 | + } |
|
626 | + |
|
627 | + if ( ! $force_read ) { |
|
628 | + if ( ! empty( $this->cache_group ) ) { |
|
629 | + $cached_meta = wp_cache_get( $cache_key, $this->cache_group ); |
|
630 | + $cache_loaded = ! empty( $cached_meta ); |
|
631 | + } |
|
632 | + } |
|
633 | + |
|
634 | + $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this ); |
|
635 | + if ( $raw_meta_data ) { |
|
636 | + foreach ( $raw_meta_data as $meta ) { |
|
637 | + $this->meta_data[] = new GetPaid_Meta_Data( |
|
638 | + array( |
|
639 | + 'id' => (int) $meta->meta_id, |
|
640 | + 'key' => $meta->meta_key, |
|
641 | + 'value' => maybe_unserialize( $meta->meta_value ), |
|
642 | + ) |
|
643 | + ); |
|
644 | + } |
|
645 | + |
|
646 | + if ( ! $cache_loaded && ! empty( $this->cache_group ) ) { |
|
647 | + wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
648 | + } |
|
649 | + } |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * Update Meta Data in the database. |
|
654 | + * |
|
655 | + * @since 1.0.19 |
|
656 | + */ |
|
657 | + public function save_meta_data() { |
|
658 | + if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
659 | + return; |
|
660 | + } |
|
661 | + foreach ( $this->meta_data as $array_key => $meta ) { |
|
662 | + if ( is_null( $meta->value ) ) { |
|
663 | + if ( ! empty( $meta->id ) ) { |
|
664 | + $this->data_store->delete_meta( $this, $meta ); |
|
665 | + unset( $this->meta_data[ $array_key ] ); |
|
666 | + } |
|
667 | + } elseif ( empty( $meta->id ) ) { |
|
668 | + $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
669 | + $meta->apply_changes(); |
|
670 | + } else { |
|
671 | + if ( $meta->get_changes() ) { |
|
672 | + $this->data_store->update_meta( $this, $meta ); |
|
673 | + $meta->apply_changes(); |
|
674 | + } |
|
675 | + } |
|
676 | + } |
|
677 | + if ( ! empty( $this->cache_group ) ) { |
|
678 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
679 | + wp_cache_delete( $cache_key, $this->cache_group ); |
|
680 | + } |
|
681 | + } |
|
682 | + |
|
683 | + /** |
|
684 | + * Set ID. |
|
685 | + * |
|
686 | + * @since 1.0.19 |
|
687 | + * @param int $id ID. |
|
688 | + */ |
|
689 | + public function set_id( $id ) { |
|
690 | + $this->id = absint( $id ); |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Sets item status. |
|
695 | + * |
|
696 | + * @since 1.0.19 |
|
697 | + * @param string $status New status. |
|
698 | + * @return array details of change. |
|
699 | + */ |
|
700 | + public function set_status( $status ) { |
|
701 | 701 | $old_status = $this->get_status(); |
702 | 702 | |
703 | - $this->set_prop( 'status', $status ); |
|
704 | - |
|
705 | - return array( |
|
706 | - 'from' => $old_status, |
|
707 | - 'to' => $status, |
|
708 | - ); |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * Set all props to default values. |
|
713 | - * |
|
714 | - * @since 1.0.19 |
|
715 | - */ |
|
716 | - public function set_defaults() { |
|
717 | - $this->data = $this->default_data; |
|
718 | - $this->changes = array(); |
|
719 | - $this->set_object_read( false ); |
|
720 | - } |
|
721 | - |
|
722 | - /** |
|
723 | - * Set object read property. |
|
724 | - * |
|
725 | - * @since 1.0.19 |
|
726 | - * @param boolean $read Should read?. |
|
727 | - */ |
|
728 | - public function set_object_read( $read = true ) { |
|
729 | - $this->object_read = (bool) $read; |
|
730 | - } |
|
731 | - |
|
732 | - /** |
|
733 | - * Get object read property. |
|
734 | - * |
|
735 | - * @since 1.0.19 |
|
736 | - * @return boolean |
|
737 | - */ |
|
738 | - public function get_object_read() { |
|
739 | - return (bool) $this->object_read; |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * Set a collection of props in one go, collect any errors, and return the result. |
|
744 | - * Only sets using public methods. |
|
745 | - * |
|
746 | - * @since 1.0.19 |
|
747 | - * |
|
748 | - * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
749 | - * @param string $context In what context to run this. |
|
750 | - * |
|
751 | - * @return bool|WP_Error |
|
752 | - */ |
|
753 | - public function set_props( $props, $context = 'set' ) { |
|
754 | - $errors = false; |
|
755 | - |
|
756 | - foreach ( $props as $prop => $value ) { |
|
757 | - try { |
|
758 | - /** |
|
759 | - * Checks if the prop being set is allowed, and the value is not null. |
|
760 | - */ |
|
761 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
762 | - continue; |
|
763 | - } |
|
764 | - $setter = "set_$prop"; |
|
765 | - |
|
766 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
767 | - $this->{$setter}( $value ); |
|
768 | - } |
|
769 | - } catch ( Exception $e ) { |
|
770 | - if ( ! $errors ) { |
|
771 | - $errors = new WP_Error(); |
|
772 | - } |
|
773 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
774 | - $this->last_error = $e->getMessage(); |
|
775 | - } |
|
776 | - } |
|
777 | - |
|
778 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
779 | - } |
|
780 | - |
|
781 | - /** |
|
782 | - * Sets a prop for a setter method. |
|
783 | - * |
|
784 | - * This stores changes in a special array so we can track what needs saving |
|
785 | - * the the DB later. |
|
786 | - * |
|
787 | - * @since 1.0.19 |
|
788 | - * @param string $prop Name of prop to set. |
|
789 | - * @param mixed $value Value of the prop. |
|
790 | - */ |
|
791 | - protected function set_prop( $prop, $value ) { |
|
792 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
793 | - if ( true === $this->object_read ) { |
|
794 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
795 | - $this->changes[ $prop ] = maybe_unserialize( $value ); |
|
796 | - } |
|
797 | - } else { |
|
798 | - $this->data[ $prop ] = maybe_unserialize( $value ); |
|
799 | - } |
|
800 | - } |
|
801 | - } |
|
802 | - |
|
803 | - /** |
|
804 | - * Return data changes only. |
|
805 | - * |
|
806 | - * @since 1.0.19 |
|
807 | - * @return array |
|
808 | - */ |
|
809 | - public function get_changes() { |
|
810 | - return $this->changes; |
|
811 | - } |
|
812 | - |
|
813 | - /** |
|
814 | - * Merge changes with data and clear. |
|
815 | - * |
|
816 | - * @since 1.0.19 |
|
817 | - */ |
|
818 | - public function apply_changes() { |
|
819 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
820 | - $this->changes = array(); |
|
821 | - } |
|
822 | - |
|
823 | - /** |
|
824 | - * Prefix for action and filter hooks on data. |
|
825 | - * |
|
826 | - * @since 1.0.19 |
|
827 | - * @return string |
|
828 | - */ |
|
829 | - protected function get_hook_prefix() { |
|
830 | - return 'wpinv_get_' . $this->object_type . '_'; |
|
831 | - } |
|
832 | - |
|
833 | - /** |
|
834 | - * Gets a prop for a getter method. |
|
835 | - * |
|
836 | - * Gets the value from either current pending changes, or the data itself. |
|
837 | - * Context controls what happens to the value before it's returned. |
|
838 | - * |
|
839 | - * @since 1.0.19 |
|
840 | - * @param string $prop Name of prop to get. |
|
841 | - * @param string $context What the value is for. Valid values are view and edit. |
|
842 | - * @return mixed |
|
843 | - */ |
|
844 | - protected function get_prop( $prop, $context = 'view' ) { |
|
845 | - $value = null; |
|
846 | - |
|
847 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
848 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
849 | - |
|
850 | - if ( 'view' === $context ) { |
|
851 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
852 | - } |
|
853 | - } |
|
854 | - |
|
855 | - return $value; |
|
856 | - } |
|
857 | - |
|
858 | - /** |
|
859 | - * Sets a date prop whilst handling formatting and datetime objects. |
|
860 | - * |
|
861 | - * @since 1.0.19 |
|
862 | - * @param string $prop Name of prop to set. |
|
863 | - * @param string|integer $value Value of the prop. |
|
864 | - */ |
|
865 | - protected function set_date_prop( $prop, $value ) { |
|
866 | - |
|
867 | - if ( empty( $value ) ) { |
|
868 | - $this->set_prop( $prop, null ); |
|
869 | - return; |
|
870 | - } |
|
871 | - $this->set_prop( $prop, $value ); |
|
872 | - |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * When invalid data is found, throw an exception unless reading from the DB. |
|
877 | - * |
|
878 | - * @throws Exception Data Exception. |
|
879 | - * @since 1.0.19 |
|
880 | - * @param string $code Error code. |
|
881 | - * @param string $message Error message. |
|
882 | - */ |
|
883 | - protected function error( $code, $message ) { |
|
884 | - throw new Exception( $message, $code ); |
|
885 | - } |
|
703 | + $this->set_prop( 'status', $status ); |
|
704 | + |
|
705 | + return array( |
|
706 | + 'from' => $old_status, |
|
707 | + 'to' => $status, |
|
708 | + ); |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * Set all props to default values. |
|
713 | + * |
|
714 | + * @since 1.0.19 |
|
715 | + */ |
|
716 | + public function set_defaults() { |
|
717 | + $this->data = $this->default_data; |
|
718 | + $this->changes = array(); |
|
719 | + $this->set_object_read( false ); |
|
720 | + } |
|
721 | + |
|
722 | + /** |
|
723 | + * Set object read property. |
|
724 | + * |
|
725 | + * @since 1.0.19 |
|
726 | + * @param boolean $read Should read?. |
|
727 | + */ |
|
728 | + public function set_object_read( $read = true ) { |
|
729 | + $this->object_read = (bool) $read; |
|
730 | + } |
|
731 | + |
|
732 | + /** |
|
733 | + * Get object read property. |
|
734 | + * |
|
735 | + * @since 1.0.19 |
|
736 | + * @return boolean |
|
737 | + */ |
|
738 | + public function get_object_read() { |
|
739 | + return (bool) $this->object_read; |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Set a collection of props in one go, collect any errors, and return the result. |
|
744 | + * Only sets using public methods. |
|
745 | + * |
|
746 | + * @since 1.0.19 |
|
747 | + * |
|
748 | + * @param array $props Key value pairs to set. Key is the prop and should map to a setter function name. |
|
749 | + * @param string $context In what context to run this. |
|
750 | + * |
|
751 | + * @return bool|WP_Error |
|
752 | + */ |
|
753 | + public function set_props( $props, $context = 'set' ) { |
|
754 | + $errors = false; |
|
755 | + |
|
756 | + foreach ( $props as $prop => $value ) { |
|
757 | + try { |
|
758 | + /** |
|
759 | + * Checks if the prop being set is allowed, and the value is not null. |
|
760 | + */ |
|
761 | + if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
762 | + continue; |
|
763 | + } |
|
764 | + $setter = "set_$prop"; |
|
765 | + |
|
766 | + if ( is_callable( array( $this, $setter ) ) ) { |
|
767 | + $this->{$setter}( $value ); |
|
768 | + } |
|
769 | + } catch ( Exception $e ) { |
|
770 | + if ( ! $errors ) { |
|
771 | + $errors = new WP_Error(); |
|
772 | + } |
|
773 | + $errors->add( $e->getCode(), $e->getMessage() ); |
|
774 | + $this->last_error = $e->getMessage(); |
|
775 | + } |
|
776 | + } |
|
777 | + |
|
778 | + return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
779 | + } |
|
780 | + |
|
781 | + /** |
|
782 | + * Sets a prop for a setter method. |
|
783 | + * |
|
784 | + * This stores changes in a special array so we can track what needs saving |
|
785 | + * the the DB later. |
|
786 | + * |
|
787 | + * @since 1.0.19 |
|
788 | + * @param string $prop Name of prop to set. |
|
789 | + * @param mixed $value Value of the prop. |
|
790 | + */ |
|
791 | + protected function set_prop( $prop, $value ) { |
|
792 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
793 | + if ( true === $this->object_read ) { |
|
794 | + if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
795 | + $this->changes[ $prop ] = maybe_unserialize( $value ); |
|
796 | + } |
|
797 | + } else { |
|
798 | + $this->data[ $prop ] = maybe_unserialize( $value ); |
|
799 | + } |
|
800 | + } |
|
801 | + } |
|
802 | + |
|
803 | + /** |
|
804 | + * Return data changes only. |
|
805 | + * |
|
806 | + * @since 1.0.19 |
|
807 | + * @return array |
|
808 | + */ |
|
809 | + public function get_changes() { |
|
810 | + return $this->changes; |
|
811 | + } |
|
812 | + |
|
813 | + /** |
|
814 | + * Merge changes with data and clear. |
|
815 | + * |
|
816 | + * @since 1.0.19 |
|
817 | + */ |
|
818 | + public function apply_changes() { |
|
819 | + $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
820 | + $this->changes = array(); |
|
821 | + } |
|
822 | + |
|
823 | + /** |
|
824 | + * Prefix for action and filter hooks on data. |
|
825 | + * |
|
826 | + * @since 1.0.19 |
|
827 | + * @return string |
|
828 | + */ |
|
829 | + protected function get_hook_prefix() { |
|
830 | + return 'wpinv_get_' . $this->object_type . '_'; |
|
831 | + } |
|
832 | + |
|
833 | + /** |
|
834 | + * Gets a prop for a getter method. |
|
835 | + * |
|
836 | + * Gets the value from either current pending changes, or the data itself. |
|
837 | + * Context controls what happens to the value before it's returned. |
|
838 | + * |
|
839 | + * @since 1.0.19 |
|
840 | + * @param string $prop Name of prop to get. |
|
841 | + * @param string $context What the value is for. Valid values are view and edit. |
|
842 | + * @return mixed |
|
843 | + */ |
|
844 | + protected function get_prop( $prop, $context = 'view' ) { |
|
845 | + $value = null; |
|
846 | + |
|
847 | + if ( array_key_exists( $prop, $this->data ) ) { |
|
848 | + $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
849 | + |
|
850 | + if ( 'view' === $context ) { |
|
851 | + $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
852 | + } |
|
853 | + } |
|
854 | + |
|
855 | + return $value; |
|
856 | + } |
|
857 | + |
|
858 | + /** |
|
859 | + * Sets a date prop whilst handling formatting and datetime objects. |
|
860 | + * |
|
861 | + * @since 1.0.19 |
|
862 | + * @param string $prop Name of prop to set. |
|
863 | + * @param string|integer $value Value of the prop. |
|
864 | + */ |
|
865 | + protected function set_date_prop( $prop, $value ) { |
|
866 | + |
|
867 | + if ( empty( $value ) ) { |
|
868 | + $this->set_prop( $prop, null ); |
|
869 | + return; |
|
870 | + } |
|
871 | + $this->set_prop( $prop, $value ); |
|
872 | + |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * When invalid data is found, throw an exception unless reading from the DB. |
|
877 | + * |
|
878 | + * @throws Exception Data Exception. |
|
879 | + * @since 1.0.19 |
|
880 | + * @param string $code Error code. |
|
881 | + * @param string $message Error message. |
|
882 | + */ |
|
883 | + protected function error( $code, $message ) { |
|
884 | + throw new Exception( $message, $code ); |
|
885 | + } |
|
886 | 886 | |
887 | 887 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,228 +14,228 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP { |
16 | 16 | |
17 | - /** |
|
18 | - * Data stored in meta keys, but not considered "meta" for an item. |
|
19 | - * |
|
20 | - * @since 1.0.19 |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $internal_meta_keys = array( |
|
24 | - '_wpinv_price', |
|
25 | - '_wpinv_vat_rule', |
|
26 | - '_wpinv_vat_class', |
|
27 | - '_wpinv_type', |
|
28 | - '_wpinv_custom_id', |
|
29 | - '_wpinv_custom_name', |
|
30 | - '_wpinv_custom_singular_name', |
|
31 | - '_wpinv_editable', |
|
32 | - '_wpinv_dynamic_pricing', |
|
33 | - '_minimum_price', |
|
34 | - '_wpinv_is_recurring', |
|
35 | - '_wpinv_recurring_period', |
|
36 | - '_wpinv_recurring_interval', |
|
37 | - '_wpinv_recurring_limit', |
|
38 | - '_wpinv_free_trial', |
|
39 | - '_wpinv_trial_period', |
|
40 | - '_wpinv_trial_interval' |
|
41 | - ); |
|
42 | - |
|
43 | - /** |
|
44 | - * A map of meta keys to data props. |
|
45 | - * |
|
46 | - * @since 1.0.19 |
|
47 | - * |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $meta_key_to_props = array( |
|
51 | - '_wpinv_price' => 'price', |
|
52 | - '_wpinv_vat_rule' => 'vat_rule', |
|
53 | - '_wpinv_vat_class' => 'vat_class', |
|
54 | - '_wpinv_type' => 'type', |
|
55 | - '_wpinv_custom_id' => 'custom_id', |
|
56 | - '_wpinv_custom_name' => 'custom_name', |
|
57 | - '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | - '_wpinv_editable' => 'is_editable', |
|
59 | - '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | - '_minimum_price' => 'minimum_price', |
|
61 | - '_wpinv_custom_name' => 'custom_name', |
|
62 | - '_wpinv_is_recurring' => 'is_recurring', |
|
63 | - '_wpinv_recurring_period' => 'recurring_period', |
|
64 | - '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | - '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | - '_wpinv_free_trial' => 'is_free_trial', |
|
67 | - '_wpinv_trial_period' => 'trial_period', |
|
68 | - '_wpinv_trial_interval' => 'trial_interval', |
|
69 | - '_wpinv_version' => 'version', |
|
70 | - ); |
|
71 | - |
|
72 | - /* |
|
17 | + /** |
|
18 | + * Data stored in meta keys, but not considered "meta" for an item. |
|
19 | + * |
|
20 | + * @since 1.0.19 |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $internal_meta_keys = array( |
|
24 | + '_wpinv_price', |
|
25 | + '_wpinv_vat_rule', |
|
26 | + '_wpinv_vat_class', |
|
27 | + '_wpinv_type', |
|
28 | + '_wpinv_custom_id', |
|
29 | + '_wpinv_custom_name', |
|
30 | + '_wpinv_custom_singular_name', |
|
31 | + '_wpinv_editable', |
|
32 | + '_wpinv_dynamic_pricing', |
|
33 | + '_minimum_price', |
|
34 | + '_wpinv_is_recurring', |
|
35 | + '_wpinv_recurring_period', |
|
36 | + '_wpinv_recurring_interval', |
|
37 | + '_wpinv_recurring_limit', |
|
38 | + '_wpinv_free_trial', |
|
39 | + '_wpinv_trial_period', |
|
40 | + '_wpinv_trial_interval' |
|
41 | + ); |
|
42 | + |
|
43 | + /** |
|
44 | + * A map of meta keys to data props. |
|
45 | + * |
|
46 | + * @since 1.0.19 |
|
47 | + * |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $meta_key_to_props = array( |
|
51 | + '_wpinv_price' => 'price', |
|
52 | + '_wpinv_vat_rule' => 'vat_rule', |
|
53 | + '_wpinv_vat_class' => 'vat_class', |
|
54 | + '_wpinv_type' => 'type', |
|
55 | + '_wpinv_custom_id' => 'custom_id', |
|
56 | + '_wpinv_custom_name' => 'custom_name', |
|
57 | + '_wpinv_custom_singular_name' => 'custom_singular_name', |
|
58 | + '_wpinv_editable' => 'is_editable', |
|
59 | + '_wpinv_dynamic_pricing' => 'is_dynamic_pricing', |
|
60 | + '_minimum_price' => 'minimum_price', |
|
61 | + '_wpinv_custom_name' => 'custom_name', |
|
62 | + '_wpinv_is_recurring' => 'is_recurring', |
|
63 | + '_wpinv_recurring_period' => 'recurring_period', |
|
64 | + '_wpinv_recurring_interval' => 'recurring_interval', |
|
65 | + '_wpinv_recurring_limit' => 'recurring_limit', |
|
66 | + '_wpinv_free_trial' => 'is_free_trial', |
|
67 | + '_wpinv_trial_period' => 'trial_period', |
|
68 | + '_wpinv_trial_interval' => 'trial_interval', |
|
69 | + '_wpinv_version' => 'version', |
|
70 | + ); |
|
71 | + |
|
72 | + /* |
|
73 | 73 | |-------------------------------------------------------------------------- |
74 | 74 | | CRUD Methods |
75 | 75 | |-------------------------------------------------------------------------- |
76 | 76 | */ |
77 | 77 | |
78 | - /** |
|
79 | - * Method to create a new item in the database. |
|
80 | - * |
|
81 | - * @param WPInv_Item $item Item object. |
|
82 | - */ |
|
83 | - public function create( &$item ) { |
|
84 | - $item->set_version( WPINV_VERSION ); |
|
85 | - $item->set_date_created( current_time('mysql') ); |
|
86 | - |
|
87 | - // Create a new post. |
|
88 | - $id = wp_insert_post( |
|
89 | - apply_filters( |
|
90 | - 'getpaid_new_item_data', |
|
91 | - array( |
|
92 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | - 'post_type' => 'wpi_item', |
|
94 | - 'post_status' => $this->get_post_status( $item ), |
|
95 | - 'ping_status' => 'closed', |
|
96 | - 'post_author' => $item->get_author( 'edit' ), |
|
97 | - 'post_title' => $item->get_name( 'edit' ), |
|
98 | - 'post_parent' => 0, |
|
99 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | - ) |
|
101 | - ), |
|
102 | - true |
|
103 | - ); |
|
104 | - |
|
105 | - if ( $id && ! is_wp_error( $id ) ) { |
|
106 | - $item->set_id( $id ); |
|
107 | - $this->update_post_meta( $item ); |
|
108 | - $item->save_meta_data(); |
|
109 | - $item->apply_changes(); |
|
110 | - $this->clear_caches( $item ); |
|
111 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
112 | - return true; |
|
113 | - } |
|
114 | - |
|
115 | - if ( is_wp_error( $id ) ) { |
|
116 | - $item->last_error = $id->get_error_message(); |
|
117 | - } |
|
78 | + /** |
|
79 | + * Method to create a new item in the database. |
|
80 | + * |
|
81 | + * @param WPInv_Item $item Item object. |
|
82 | + */ |
|
83 | + public function create( &$item ) { |
|
84 | + $item->set_version( WPINV_VERSION ); |
|
85 | + $item->set_date_created( current_time('mysql') ); |
|
86 | + |
|
87 | + // Create a new post. |
|
88 | + $id = wp_insert_post( |
|
89 | + apply_filters( |
|
90 | + 'getpaid_new_item_data', |
|
91 | + array( |
|
92 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
93 | + 'post_type' => 'wpi_item', |
|
94 | + 'post_status' => $this->get_post_status( $item ), |
|
95 | + 'ping_status' => 'closed', |
|
96 | + 'post_author' => $item->get_author( 'edit' ), |
|
97 | + 'post_title' => $item->get_name( 'edit' ), |
|
98 | + 'post_parent' => 0, |
|
99 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
100 | + ) |
|
101 | + ), |
|
102 | + true |
|
103 | + ); |
|
104 | + |
|
105 | + if ( $id && ! is_wp_error( $id ) ) { |
|
106 | + $item->set_id( $id ); |
|
107 | + $this->update_post_meta( $item ); |
|
108 | + $item->save_meta_data(); |
|
109 | + $item->apply_changes(); |
|
110 | + $this->clear_caches( $item ); |
|
111 | + do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
112 | + return true; |
|
113 | + } |
|
114 | + |
|
115 | + if ( is_wp_error( $id ) ) { |
|
116 | + $item->last_error = $id->get_error_message(); |
|
117 | + } |
|
118 | 118 | |
119 | - return false; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Method to read an item from the database. |
|
124 | - * |
|
125 | - * @param WPInv_Item $item Item object. |
|
126 | - * |
|
127 | - */ |
|
128 | - public function read( &$item ) { |
|
129 | - |
|
130 | - $item->set_defaults(); |
|
131 | - $item_object = get_post( $item->get_id() ); |
|
132 | - |
|
133 | - if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | - $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | - $item->set_id( 0 ); |
|
136 | - return false; |
|
137 | - } |
|
138 | - |
|
139 | - $item->set_props( |
|
140 | - array( |
|
141 | - 'parent_id' => $item_object->post_parent, |
|
142 | - 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
143 | - 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
144 | - 'status' => $item_object->post_status, |
|
145 | - 'name' => $item_object->post_title, |
|
146 | - 'description' => $item_object->post_excerpt, |
|
147 | - 'author' => $item_object->post_author, |
|
148 | - ) |
|
149 | - ); |
|
150 | - |
|
151 | - $this->read_object_data( $item, $item_object ); |
|
152 | - $item->read_meta_data(); |
|
153 | - $item->set_object_read( true ); |
|
154 | - do_action( 'getpaid_read_item', $item->get_id(), $item ); |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Method to update an item in the database. |
|
160 | - * |
|
161 | - * @param WPInv_Item $item Item object. |
|
162 | - */ |
|
163 | - public function update( &$item ) { |
|
164 | - $item->save_meta_data(); |
|
165 | - $item->set_version( WPINV_VERSION ); |
|
166 | - |
|
167 | - if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | - $item->set_date_created( current_time('mysql') ); |
|
169 | - } |
|
170 | - |
|
171 | - // Grab the current status so we can compare. |
|
172 | - $previous_status = get_post_status( $item->get_id() ); |
|
173 | - |
|
174 | - $changes = $item->get_changes(); |
|
175 | - |
|
176 | - // Only update the post when the post data changes. |
|
177 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
178 | - $post_data = array( |
|
179 | - 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | - 'post_status' => $item->get_status( 'edit' ), |
|
181 | - 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | - 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | - 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | - 'post_title' => $item->get_name( 'edit' ), |
|
185 | - 'post_author' => $item->get_author( 'edit' ), |
|
186 | - ); |
|
187 | - |
|
188 | - /** |
|
189 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
190 | - * to update data, since wp_update_post spawns more calls to the |
|
191 | - * save_post action. |
|
192 | - * |
|
193 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
194 | - * or an update purely from CRUD. |
|
195 | - */ |
|
196 | - if ( doing_action( 'save_post' ) ) { |
|
197 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | - clean_post_cache( $item->get_id() ); |
|
199 | - } else { |
|
200 | - wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
201 | - } |
|
202 | - $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | - } |
|
204 | - $this->update_post_meta( $item ); |
|
205 | - $item->apply_changes(); |
|
206 | - $this->clear_caches( $item ); |
|
207 | - |
|
208 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
209 | - $new_status = $item->get_status( 'edit' ); |
|
210 | - |
|
211 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | - do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
213 | - } else { |
|
214 | - do_action( 'getpaid_update_item', $item->get_id(), $item ); |
|
215 | - } |
|
216 | - |
|
217 | - } |
|
218 | - |
|
219 | - /* |
|
119 | + return false; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Method to read an item from the database. |
|
124 | + * |
|
125 | + * @param WPInv_Item $item Item object. |
|
126 | + * |
|
127 | + */ |
|
128 | + public function read( &$item ) { |
|
129 | + |
|
130 | + $item->set_defaults(); |
|
131 | + $item_object = get_post( $item->get_id() ); |
|
132 | + |
|
133 | + if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) { |
|
134 | + $item->last_error = __( 'Invalid item.', 'invoicing' ); |
|
135 | + $item->set_id( 0 ); |
|
136 | + return false; |
|
137 | + } |
|
138 | + |
|
139 | + $item->set_props( |
|
140 | + array( |
|
141 | + 'parent_id' => $item_object->post_parent, |
|
142 | + 'date_created' => 0 < $item_object->post_date ? $item_object->post_date : null, |
|
143 | + 'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null, |
|
144 | + 'status' => $item_object->post_status, |
|
145 | + 'name' => $item_object->post_title, |
|
146 | + 'description' => $item_object->post_excerpt, |
|
147 | + 'author' => $item_object->post_author, |
|
148 | + ) |
|
149 | + ); |
|
150 | + |
|
151 | + $this->read_object_data( $item, $item_object ); |
|
152 | + $item->read_meta_data(); |
|
153 | + $item->set_object_read( true ); |
|
154 | + do_action( 'getpaid_read_item', $item->get_id(), $item ); |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Method to update an item in the database. |
|
160 | + * |
|
161 | + * @param WPInv_Item $item Item object. |
|
162 | + */ |
|
163 | + public function update( &$item ) { |
|
164 | + $item->save_meta_data(); |
|
165 | + $item->set_version( WPINV_VERSION ); |
|
166 | + |
|
167 | + if ( null === $item->get_date_created( 'edit' ) ) { |
|
168 | + $item->set_date_created( current_time('mysql') ); |
|
169 | + } |
|
170 | + |
|
171 | + // Grab the current status so we can compare. |
|
172 | + $previous_status = get_post_status( $item->get_id() ); |
|
173 | + |
|
174 | + $changes = $item->get_changes(); |
|
175 | + |
|
176 | + // Only update the post when the post data changes. |
|
177 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) { |
|
178 | + $post_data = array( |
|
179 | + 'post_date' => $item->get_date_created( 'edit' ), |
|
180 | + 'post_status' => $item->get_status( 'edit' ), |
|
181 | + 'post_parent' => $item->get_parent_id( 'edit' ), |
|
182 | + 'post_excerpt' => $item->get_description( 'edit' ), |
|
183 | + 'post_modified' => $item->get_date_modified( 'edit' ), |
|
184 | + 'post_title' => $item->get_name( 'edit' ), |
|
185 | + 'post_author' => $item->get_author( 'edit' ), |
|
186 | + ); |
|
187 | + |
|
188 | + /** |
|
189 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
190 | + * to update data, since wp_update_post spawns more calls to the |
|
191 | + * save_post action. |
|
192 | + * |
|
193 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
194 | + * or an update purely from CRUD. |
|
195 | + */ |
|
196 | + if ( doing_action( 'save_post' ) ) { |
|
197 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) ); |
|
198 | + clean_post_cache( $item->get_id() ); |
|
199 | + } else { |
|
200 | + wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) ); |
|
201 | + } |
|
202 | + $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
203 | + } |
|
204 | + $this->update_post_meta( $item ); |
|
205 | + $item->apply_changes(); |
|
206 | + $this->clear_caches( $item ); |
|
207 | + |
|
208 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
209 | + $new_status = $item->get_status( 'edit' ); |
|
210 | + |
|
211 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
212 | + do_action( 'getpaid_new_item', $item->get_id(), $item ); |
|
213 | + } else { |
|
214 | + do_action( 'getpaid_update_item', $item->get_id(), $item ); |
|
215 | + } |
|
216 | + |
|
217 | + } |
|
218 | + |
|
219 | + /* |
|
220 | 220 | |-------------------------------------------------------------------------- |
221 | 221 | | Additional Methods |
222 | 222 | |-------------------------------------------------------------------------- |
223 | 223 | */ |
224 | 224 | |
225 | - /** |
|
226 | - * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
227 | - * |
|
228 | - * @param WPInv_Item $item WPInv_Item object. |
|
229 | - * @since 1.0.19 |
|
230 | - */ |
|
231 | - protected function update_post_meta( &$item ) { |
|
225 | + /** |
|
226 | + * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class. |
|
227 | + * |
|
228 | + * @param WPInv_Item $item WPInv_Item object. |
|
229 | + * @since 1.0.19 |
|
230 | + */ |
|
231 | + protected function update_post_meta( &$item ) { |
|
232 | 232 | |
233 | - // Ensure that we have a custom id. |
|
233 | + // Ensure that we have a custom id. |
|
234 | 234 | if ( ! $item->get_custom_id() ) { |
235 | 235 | $item->set_custom_id( $item->get_id() ); |
236 | - } |
|
236 | + } |
|
237 | 237 | |
238 | - parent::update_post_meta( $item ); |
|
239 | - } |
|
238 | + parent::update_post_meta( $item ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,490 +15,490 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpinv_subscr_profile_id', |
|
26 | - '_wpinv_taxes', |
|
27 | - '_wpinv_fees', |
|
28 | - '_wpinv_discounts', |
|
29 | - '_wpinv_submission_id', |
|
30 | - '_wpinv_payment_form', |
|
31 | - '_wpinv_is_viewed', |
|
32 | - 'wpinv_email_cc', |
|
33 | - 'wpinv_template' |
|
34 | - ); |
|
35 | - |
|
36 | - /** |
|
37 | - * A map of meta keys to data props. |
|
38 | - * |
|
39 | - * @since 1.0.19 |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $meta_key_to_props = array( |
|
44 | - '_wpinv_subscr_profile_id' => 'subscription_id', |
|
45 | - '_wpinv_taxes' => 'taxes', |
|
46 | - '_wpinv_fees' => 'fees', |
|
47 | - '_wpinv_discounts' => 'discounts', |
|
48 | - '_wpinv_submission_id' => 'submission_id', |
|
49 | - '_wpinv_payment_form' => 'payment_form', |
|
50 | - '_wpinv_is_viewed' => 'is_viewed', |
|
51 | - 'wpinv_email_cc' => 'email_cc', |
|
52 | - 'wpinv_template' => 'template', |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * A map of database fields to data props. |
|
57 | - * |
|
58 | - * @since 1.0.19 |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - protected $database_fields_to_props = array( |
|
63 | - 'post_id' => 'id', |
|
64 | - 'number' => 'number', |
|
65 | - 'currency' => 'currency', |
|
66 | - 'key' => 'key', |
|
67 | - 'type' => 'type', |
|
68 | - 'mode' => 'mode', |
|
69 | - 'user_ip' => 'user_ip', |
|
70 | - 'first_name' => 'first_name', |
|
71 | - 'last_name' => 'last_name', |
|
72 | - 'address' => 'address', |
|
73 | - 'city' => 'city', |
|
74 | - 'state' => 'state', |
|
75 | - 'country' => 'country', |
|
76 | - 'zip' => 'zip', |
|
77 | - 'zip' => 'zip', |
|
78 | - 'adddress_confirmed' => 'address_confirmed', |
|
79 | - 'gateway' => 'gateway', |
|
80 | - 'transaction_id' => 'transaction_id', |
|
81 | - 'currency' => 'currency', |
|
82 | - 'subtotal' => 'subtotal', |
|
83 | - 'tax' => 'total_tax', |
|
84 | - 'fees_total' => 'total_fees', |
|
85 | - 'discount' => 'total_discount', |
|
86 | - 'total' => 'total', |
|
87 | - 'discount_code' => 'discount_code', |
|
88 | - 'disable_taxes' => 'disable_taxes', |
|
89 | - 'due_date' => 'due_date', |
|
90 | - 'completed_date' => 'completed_date', |
|
91 | - 'company' => 'company', |
|
92 | - 'vat_number' => 'vat_number', |
|
93 | - 'vat_rate' => 'vat_rate', |
|
94 | - ); |
|
95 | - |
|
96 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpinv_subscr_profile_id', |
|
26 | + '_wpinv_taxes', |
|
27 | + '_wpinv_fees', |
|
28 | + '_wpinv_discounts', |
|
29 | + '_wpinv_submission_id', |
|
30 | + '_wpinv_payment_form', |
|
31 | + '_wpinv_is_viewed', |
|
32 | + 'wpinv_email_cc', |
|
33 | + 'wpinv_template' |
|
34 | + ); |
|
35 | + |
|
36 | + /** |
|
37 | + * A map of meta keys to data props. |
|
38 | + * |
|
39 | + * @since 1.0.19 |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $meta_key_to_props = array( |
|
44 | + '_wpinv_subscr_profile_id' => 'subscription_id', |
|
45 | + '_wpinv_taxes' => 'taxes', |
|
46 | + '_wpinv_fees' => 'fees', |
|
47 | + '_wpinv_discounts' => 'discounts', |
|
48 | + '_wpinv_submission_id' => 'submission_id', |
|
49 | + '_wpinv_payment_form' => 'payment_form', |
|
50 | + '_wpinv_is_viewed' => 'is_viewed', |
|
51 | + 'wpinv_email_cc' => 'email_cc', |
|
52 | + 'wpinv_template' => 'template', |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * A map of database fields to data props. |
|
57 | + * |
|
58 | + * @since 1.0.19 |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + protected $database_fields_to_props = array( |
|
63 | + 'post_id' => 'id', |
|
64 | + 'number' => 'number', |
|
65 | + 'currency' => 'currency', |
|
66 | + 'key' => 'key', |
|
67 | + 'type' => 'type', |
|
68 | + 'mode' => 'mode', |
|
69 | + 'user_ip' => 'user_ip', |
|
70 | + 'first_name' => 'first_name', |
|
71 | + 'last_name' => 'last_name', |
|
72 | + 'address' => 'address', |
|
73 | + 'city' => 'city', |
|
74 | + 'state' => 'state', |
|
75 | + 'country' => 'country', |
|
76 | + 'zip' => 'zip', |
|
77 | + 'zip' => 'zip', |
|
78 | + 'adddress_confirmed' => 'address_confirmed', |
|
79 | + 'gateway' => 'gateway', |
|
80 | + 'transaction_id' => 'transaction_id', |
|
81 | + 'currency' => 'currency', |
|
82 | + 'subtotal' => 'subtotal', |
|
83 | + 'tax' => 'total_tax', |
|
84 | + 'fees_total' => 'total_fees', |
|
85 | + 'discount' => 'total_discount', |
|
86 | + 'total' => 'total', |
|
87 | + 'discount_code' => 'discount_code', |
|
88 | + 'disable_taxes' => 'disable_taxes', |
|
89 | + 'due_date' => 'due_date', |
|
90 | + 'completed_date' => 'completed_date', |
|
91 | + 'company' => 'company', |
|
92 | + 'vat_number' => 'vat_number', |
|
93 | + 'vat_rate' => 'vat_rate', |
|
94 | + ); |
|
95 | + |
|
96 | + /* |
|
97 | 97 | |-------------------------------------------------------------------------- |
98 | 98 | | CRUD Methods |
99 | 99 | |-------------------------------------------------------------------------- |
100 | 100 | */ |
101 | - /** |
|
102 | - * Method to create a new invoice in the database. |
|
103 | - * |
|
104 | - * @param WPInv_Invoice $invoice Invoice object. |
|
105 | - */ |
|
106 | - public function create( &$invoice ) { |
|
107 | - $invoice->set_version( WPINV_VERSION ); |
|
108 | - $invoice->set_date_created( current_time('mysql') ); |
|
109 | - |
|
110 | - // Ensure both the key and number are set. |
|
111 | - $invoice->get_key(); |
|
112 | - $invoice->get_number(); |
|
113 | - |
|
114 | - // Create a new post. |
|
115 | - $id = wp_insert_post( |
|
116 | - apply_filters( |
|
117 | - 'getpaid_new_invoice_data', |
|
118 | - array( |
|
119 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
120 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
121 | - 'post_status' => $this->get_post_status( $invoice ), |
|
122 | - 'ping_status' => 'closed', |
|
123 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
124 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
125 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
126 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
127 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
128 | - ) |
|
129 | - ), |
|
130 | - true |
|
131 | - ); |
|
132 | - |
|
133 | - if ( $id && ! is_wp_error( $id ) ) { |
|
134 | - $invoice->set_id( $id ); |
|
135 | - getpaid_save_invoice_user_address( $invoice ); |
|
136 | - $this->save_special_fields( $invoice ); |
|
137 | - $this->save_items( $invoice ); |
|
138 | - $this->update_post_meta( $invoice ); |
|
139 | - $invoice->save_meta_data(); |
|
140 | - $invoice->apply_changes(); |
|
141 | - $this->clear_caches( $invoice ); |
|
142 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
143 | - return true; |
|
144 | - } |
|
145 | - |
|
146 | - if ( is_wp_error( $id ) ) { |
|
147 | - $invoice->last_error = $id->get_error_message(); |
|
148 | - } |
|
149 | - |
|
150 | - return false; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Method to read an invoice from the database. |
|
155 | - * |
|
156 | - * @param WPInv_Invoice $invoice Invoice object. |
|
157 | - * |
|
158 | - */ |
|
159 | - public function read( &$invoice ) { |
|
160 | - |
|
161 | - $invoice->set_defaults(); |
|
162 | - $invoice_object = get_post( $invoice->get_id() ); |
|
163 | - |
|
164 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
165 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
166 | - $invoice->set_id( 0 ); |
|
167 | - return false; |
|
168 | - } |
|
169 | - |
|
170 | - $invoice->set_props( |
|
171 | - array( |
|
172 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
173 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
174 | - 'status' => $invoice_object->post_status, |
|
175 | - 'author' => $invoice_object->post_author, |
|
176 | - 'description' => $invoice_object->post_excerpt, |
|
177 | - 'parent_id' => $invoice_object->post_parent, |
|
178 | - 'name' => $invoice_object->post_title, |
|
179 | - 'path' => $invoice_object->post_name, |
|
180 | - 'post_type' => $invoice_object->post_type, |
|
181 | - ) |
|
182 | - ); |
|
183 | - |
|
184 | - $invoice->set_type( $invoice_object->post_type ); |
|
185 | - |
|
186 | - $this->read_object_data( $invoice, $invoice_object ); |
|
187 | - $this->add_special_fields( $invoice ); |
|
188 | - $this->add_items( $invoice ); |
|
189 | - $invoice->read_meta_data(); |
|
190 | - $invoice->set_object_read( true ); |
|
191 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
192 | - |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Method to update an invoice in the database. |
|
197 | - * |
|
198 | - * @param WPInv_Invoice $invoice Invoice object. |
|
199 | - */ |
|
200 | - public function update( &$invoice ) { |
|
201 | - $invoice->save_meta_data(); |
|
202 | - $invoice->set_version( WPINV_VERSION ); |
|
203 | - |
|
204 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
205 | - $invoice->set_date_created( current_time('mysql') ); |
|
206 | - } |
|
207 | - |
|
208 | - // Ensure both the key and number are set. |
|
209 | - $invoice->get_key(); |
|
210 | - $invoice->get_number(); |
|
211 | - |
|
212 | - // Grab the current status so we can compare. |
|
213 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
214 | - |
|
215 | - $changes = $invoice->get_changes(); |
|
216 | - |
|
217 | - // Only update the post when the post data changes. |
|
218 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
219 | - $post_data = array( |
|
220 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
221 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
222 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
223 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
224 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
225 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
226 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
227 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
228 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
229 | - ); |
|
230 | - |
|
231 | - /** |
|
232 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
233 | - * to update data, since wp_update_post spawns more calls to the |
|
234 | - * save_post action. |
|
235 | - * |
|
236 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
237 | - * or an update purely from CRUD. |
|
238 | - */ |
|
239 | - if ( doing_action( 'save_post' ) ) { |
|
240 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
241 | - clean_post_cache( $invoice->get_id() ); |
|
242 | - } else { |
|
243 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
244 | - } |
|
245 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
246 | - } |
|
247 | - $this->update_post_meta( $invoice ); |
|
248 | - $this->save_special_fields( $invoice ); |
|
249 | - $this->save_items( $invoice ); |
|
250 | - $invoice->apply_changes(); |
|
251 | - getpaid_save_invoice_user_address( $invoice ); |
|
252 | - $this->clear_caches( $invoice ); |
|
253 | - |
|
254 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
255 | - $new_status = $invoice->get_status( 'edit' ); |
|
256 | - |
|
257 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
258 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
259 | - } else { |
|
260 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
261 | - } |
|
262 | - |
|
263 | - } |
|
264 | - |
|
265 | - /* |
|
101 | + /** |
|
102 | + * Method to create a new invoice in the database. |
|
103 | + * |
|
104 | + * @param WPInv_Invoice $invoice Invoice object. |
|
105 | + */ |
|
106 | + public function create( &$invoice ) { |
|
107 | + $invoice->set_version( WPINV_VERSION ); |
|
108 | + $invoice->set_date_created( current_time('mysql') ); |
|
109 | + |
|
110 | + // Ensure both the key and number are set. |
|
111 | + $invoice->get_key(); |
|
112 | + $invoice->get_number(); |
|
113 | + |
|
114 | + // Create a new post. |
|
115 | + $id = wp_insert_post( |
|
116 | + apply_filters( |
|
117 | + 'getpaid_new_invoice_data', |
|
118 | + array( |
|
119 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
120 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
121 | + 'post_status' => $this->get_post_status( $invoice ), |
|
122 | + 'ping_status' => 'closed', |
|
123 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
124 | + 'post_title' => $invoice->get_number( 'edit' ), |
|
125 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
126 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
127 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
128 | + ) |
|
129 | + ), |
|
130 | + true |
|
131 | + ); |
|
132 | + |
|
133 | + if ( $id && ! is_wp_error( $id ) ) { |
|
134 | + $invoice->set_id( $id ); |
|
135 | + getpaid_save_invoice_user_address( $invoice ); |
|
136 | + $this->save_special_fields( $invoice ); |
|
137 | + $this->save_items( $invoice ); |
|
138 | + $this->update_post_meta( $invoice ); |
|
139 | + $invoice->save_meta_data(); |
|
140 | + $invoice->apply_changes(); |
|
141 | + $this->clear_caches( $invoice ); |
|
142 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
143 | + return true; |
|
144 | + } |
|
145 | + |
|
146 | + if ( is_wp_error( $id ) ) { |
|
147 | + $invoice->last_error = $id->get_error_message(); |
|
148 | + } |
|
149 | + |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Method to read an invoice from the database. |
|
155 | + * |
|
156 | + * @param WPInv_Invoice $invoice Invoice object. |
|
157 | + * |
|
158 | + */ |
|
159 | + public function read( &$invoice ) { |
|
160 | + |
|
161 | + $invoice->set_defaults(); |
|
162 | + $invoice_object = get_post( $invoice->get_id() ); |
|
163 | + |
|
164 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
165 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
166 | + $invoice->set_id( 0 ); |
|
167 | + return false; |
|
168 | + } |
|
169 | + |
|
170 | + $invoice->set_props( |
|
171 | + array( |
|
172 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
173 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
174 | + 'status' => $invoice_object->post_status, |
|
175 | + 'author' => $invoice_object->post_author, |
|
176 | + 'description' => $invoice_object->post_excerpt, |
|
177 | + 'parent_id' => $invoice_object->post_parent, |
|
178 | + 'name' => $invoice_object->post_title, |
|
179 | + 'path' => $invoice_object->post_name, |
|
180 | + 'post_type' => $invoice_object->post_type, |
|
181 | + ) |
|
182 | + ); |
|
183 | + |
|
184 | + $invoice->set_type( $invoice_object->post_type ); |
|
185 | + |
|
186 | + $this->read_object_data( $invoice, $invoice_object ); |
|
187 | + $this->add_special_fields( $invoice ); |
|
188 | + $this->add_items( $invoice ); |
|
189 | + $invoice->read_meta_data(); |
|
190 | + $invoice->set_object_read( true ); |
|
191 | + do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
192 | + |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Method to update an invoice in the database. |
|
197 | + * |
|
198 | + * @param WPInv_Invoice $invoice Invoice object. |
|
199 | + */ |
|
200 | + public function update( &$invoice ) { |
|
201 | + $invoice->save_meta_data(); |
|
202 | + $invoice->set_version( WPINV_VERSION ); |
|
203 | + |
|
204 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
205 | + $invoice->set_date_created( current_time('mysql') ); |
|
206 | + } |
|
207 | + |
|
208 | + // Ensure both the key and number are set. |
|
209 | + $invoice->get_key(); |
|
210 | + $invoice->get_number(); |
|
211 | + |
|
212 | + // Grab the current status so we can compare. |
|
213 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
214 | + |
|
215 | + $changes = $invoice->get_changes(); |
|
216 | + |
|
217 | + // Only update the post when the post data changes. |
|
218 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
219 | + $post_data = array( |
|
220 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
221 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
222 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
223 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
224 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
225 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
226 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
227 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
228 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
229 | + ); |
|
230 | + |
|
231 | + /** |
|
232 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
233 | + * to update data, since wp_update_post spawns more calls to the |
|
234 | + * save_post action. |
|
235 | + * |
|
236 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
237 | + * or an update purely from CRUD. |
|
238 | + */ |
|
239 | + if ( doing_action( 'save_post' ) ) { |
|
240 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
241 | + clean_post_cache( $invoice->get_id() ); |
|
242 | + } else { |
|
243 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
244 | + } |
|
245 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
246 | + } |
|
247 | + $this->update_post_meta( $invoice ); |
|
248 | + $this->save_special_fields( $invoice ); |
|
249 | + $this->save_items( $invoice ); |
|
250 | + $invoice->apply_changes(); |
|
251 | + getpaid_save_invoice_user_address( $invoice ); |
|
252 | + $this->clear_caches( $invoice ); |
|
253 | + |
|
254 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
255 | + $new_status = $invoice->get_status( 'edit' ); |
|
256 | + |
|
257 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
258 | + do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
259 | + } else { |
|
260 | + do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice ); |
|
261 | + } |
|
262 | + |
|
263 | + } |
|
264 | + |
|
265 | + /* |
|
266 | 266 | |-------------------------------------------------------------------------- |
267 | 267 | | Additional Methods |
268 | 268 | |-------------------------------------------------------------------------- |
269 | 269 | */ |
270 | 270 | |
271 | - /** |
|
271 | + /** |
|
272 | 272 | * Retrieves special fields and adds to the invoice. |
273 | - * |
|
274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
273 | + * |
|
274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
275 | 275 | */ |
276 | 276 | public function add_special_fields( &$invoice ) { |
277 | - global $wpdb; |
|
277 | + global $wpdb; |
|
278 | 278 | |
279 | - // Maybe retrieve from the cache. |
|
280 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
279 | + // Maybe retrieve from the cache. |
|
280 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
281 | 281 | |
282 | - // If not found, retrieve from the db. |
|
283 | - if ( false === $data ) { |
|
284 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
282 | + // If not found, retrieve from the db. |
|
283 | + if ( false === $data ) { |
|
284 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
285 | 285 | |
286 | - $data = $wpdb->get_row( |
|
287 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
288 | - ARRAY_A |
|
289 | - ); |
|
286 | + $data = $wpdb->get_row( |
|
287 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
288 | + ARRAY_A |
|
289 | + ); |
|
290 | 290 | |
291 | - // Update the cache with our data |
|
292 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
291 | + // Update the cache with our data |
|
292 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
293 | 293 | |
294 | - } |
|
294 | + } |
|
295 | 295 | |
296 | - // Abort if the data does not exist. |
|
297 | - if ( empty( $data ) ) { |
|
298 | - return; |
|
299 | - } |
|
296 | + // Abort if the data does not exist. |
|
297 | + if ( empty( $data ) ) { |
|
298 | + return; |
|
299 | + } |
|
300 | 300 | |
301 | - $props = array(); |
|
301 | + $props = array(); |
|
302 | 302 | |
303 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
303 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
304 | 304 | |
305 | - if ( $db_field == 'post_id' ) { |
|
306 | - continue; |
|
307 | - } |
|
308 | - |
|
309 | - $props[ $prop ] = $data[ $db_field ]; |
|
310 | - } |
|
311 | - |
|
312 | - $invoice->set_props( $props ); |
|
313 | - |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Gets a list of special fields that need updated based on change state |
|
318 | - * or if they are present in the database or not. |
|
319 | - * |
|
320 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
321 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
322 | - */ |
|
323 | - protected function get_special_fields_to_update( $invoice ) { |
|
324 | - $fields_to_update = array(); |
|
325 | - $changed_props = $invoice->get_changes(); |
|
326 | - |
|
327 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
328 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
329 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
330 | - $fields_to_update[ $database_field ] = $prop; |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - return $fields_to_update; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
339 | - * |
|
340 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
341 | - * @since 1.0.19 |
|
342 | - */ |
|
343 | - protected function update_special_fields( &$invoice ) { |
|
344 | - global $wpdb; |
|
345 | - |
|
346 | - $updated_props = array(); |
|
347 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
348 | - |
|
349 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
350 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
351 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
352 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
353 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
354 | - } |
|
355 | - |
|
356 | - if ( ! empty( $updated_props ) ) { |
|
357 | - |
|
358 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
359 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
360 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
361 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
362 | - |
|
363 | - } |
|
364 | - |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Helper method that inserts special fields to the database. |
|
369 | - * |
|
370 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
371 | - * @since 1.0.19 |
|
372 | - */ |
|
373 | - protected function insert_special_fields( &$invoice ) { |
|
374 | - global $wpdb; |
|
375 | - |
|
376 | - $updated_props = array(); |
|
377 | - |
|
378 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
379 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
380 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
381 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
382 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
383 | - } |
|
384 | - |
|
385 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
386 | - $wpdb->insert( $table, $updated_props ); |
|
387 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
388 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
389 | - |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
305 | + if ( $db_field == 'post_id' ) { |
|
306 | + continue; |
|
307 | + } |
|
308 | + |
|
309 | + $props[ $prop ] = $data[ $db_field ]; |
|
310 | + } |
|
311 | + |
|
312 | + $invoice->set_props( $props ); |
|
313 | + |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Gets a list of special fields that need updated based on change state |
|
318 | + * or if they are present in the database or not. |
|
319 | + * |
|
320 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
321 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
322 | + */ |
|
323 | + protected function get_special_fields_to_update( $invoice ) { |
|
324 | + $fields_to_update = array(); |
|
325 | + $changed_props = $invoice->get_changes(); |
|
326 | + |
|
327 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
328 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
329 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
330 | + $fields_to_update[ $database_field ] = $prop; |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + return $fields_to_update; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
339 | + * |
|
340 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
341 | + * @since 1.0.19 |
|
342 | + */ |
|
343 | + protected function update_special_fields( &$invoice ) { |
|
344 | + global $wpdb; |
|
345 | + |
|
346 | + $updated_props = array(); |
|
347 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
348 | + |
|
349 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
350 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
351 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
352 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
353 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
354 | + } |
|
355 | + |
|
356 | + if ( ! empty( $updated_props ) ) { |
|
357 | + |
|
358 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
359 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
360 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
361 | + do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
362 | + |
|
363 | + } |
|
364 | + |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Helper method that inserts special fields to the database. |
|
369 | + * |
|
370 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
371 | + * @since 1.0.19 |
|
372 | + */ |
|
373 | + protected function insert_special_fields( &$invoice ) { |
|
374 | + global $wpdb; |
|
375 | + |
|
376 | + $updated_props = array(); |
|
377 | + |
|
378 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
379 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
380 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
381 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
382 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
383 | + } |
|
384 | + |
|
385 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
386 | + $wpdb->insert( $table, $updated_props ); |
|
387 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
388 | + do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
389 | + |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | 393 | * Saves all special fields. |
394 | - * |
|
395 | - * @param WPInv_Invoice $invoice Invoice object. |
|
394 | + * |
|
395 | + * @param WPInv_Invoice $invoice Invoice object. |
|
396 | 396 | */ |
397 | 397 | public function save_special_fields( $invoice ) { |
398 | - global $wpdb; |
|
398 | + global $wpdb; |
|
399 | 399 | |
400 | - // The invoices table. |
|
401 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
402 | - $id = (int) $invoice->get_id(); |
|
400 | + // The invoices table. |
|
401 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
402 | + $id = (int) $invoice->get_id(); |
|
403 | 403 | |
404 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
404 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
405 | 405 | |
406 | - $this->update_special_fields( $invoice ); |
|
406 | + $this->update_special_fields( $invoice ); |
|
407 | 407 | |
408 | - } else { |
|
408 | + } else { |
|
409 | 409 | |
410 | - $this->insert_special_fields( $invoice ); |
|
410 | + $this->insert_special_fields( $invoice ); |
|
411 | 411 | |
412 | - } |
|
412 | + } |
|
413 | 413 | |
414 | - } |
|
414 | + } |
|
415 | 415 | |
416 | - /** |
|
416 | + /** |
|
417 | 417 | * Set's up cart details. |
418 | - * |
|
419 | - * @param WPInv_Invoice $invoice Invoice object. |
|
418 | + * |
|
419 | + * @param WPInv_Invoice $invoice Invoice object. |
|
420 | 420 | */ |
421 | 421 | public function add_items( &$invoice ) { |
422 | - global $wpdb; |
|
422 | + global $wpdb; |
|
423 | 423 | |
424 | - // Maybe retrieve from the cache. |
|
425 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
424 | + // Maybe retrieve from the cache. |
|
425 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
426 | 426 | |
427 | - // If not found, retrieve from the db. |
|
428 | - if ( false === $items ) { |
|
429 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
427 | + // If not found, retrieve from the db. |
|
428 | + if ( false === $items ) { |
|
429 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
430 | 430 | |
431 | - $items = $wpdb->get_results( |
|
432 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
433 | - ); |
|
431 | + $items = $wpdb->get_results( |
|
432 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
433 | + ); |
|
434 | 434 | |
435 | - // Update the cache with our data |
|
436 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
435 | + // Update the cache with our data |
|
436 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
437 | 437 | |
438 | - } |
|
438 | + } |
|
439 | 439 | |
440 | - // Abort if no items found. |
|
440 | + // Abort if no items found. |
|
441 | 441 | if ( empty( $items ) ) { |
442 | 442 | return; |
443 | - } |
|
443 | + } |
|
444 | 444 | |
445 | - foreach ( $items as $item_data ) { |
|
446 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
445 | + foreach ( $items as $item_data ) { |
|
446 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
447 | 447 | |
448 | - // Set item data. |
|
449 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
450 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
451 | - $item->set_name( $item_data->item_name ); |
|
452 | - $item->set_description( $item_data->item_description ); |
|
453 | - $item->set_price( $item_data->item_price ); |
|
454 | - $item->set_quantity( $item_data->quantity ); |
|
455 | - $item->set_item_meta( $item_data->meta ); |
|
448 | + // Set item data. |
|
449 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
450 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
451 | + $item->set_name( $item_data->item_name ); |
|
452 | + $item->set_description( $item_data->item_description ); |
|
453 | + $item->set_price( $item_data->item_price ); |
|
454 | + $item->set_quantity( $item_data->quantity ); |
|
455 | + $item->set_item_meta( $item_data->meta ); |
|
456 | 456 | |
457 | - $invoice->add_item( $item ); |
|
458 | - } |
|
457 | + $invoice->add_item( $item ); |
|
458 | + } |
|
459 | 459 | |
460 | - } |
|
460 | + } |
|
461 | 461 | |
462 | - /** |
|
462 | + /** |
|
463 | 463 | * Saves cart details. |
464 | - * |
|
465 | - * @param WPInv_Invoice $invoice Invoice object. |
|
464 | + * |
|
465 | + * @param WPInv_Invoice $invoice Invoice object. |
|
466 | 466 | */ |
467 | 467 | public function save_items( $invoice ) { |
468 | 468 | |
469 | - // Delete previously existing items. |
|
470 | - $this->delete_items( $invoice ); |
|
469 | + // Delete previously existing items. |
|
470 | + $this->delete_items( $invoice ); |
|
471 | 471 | |
472 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
472 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
473 | 473 | |
474 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
475 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
476 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
477 | - } |
|
474 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
475 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
476 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
477 | + } |
|
478 | 478 | |
479 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
480 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
479 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
480 | + do_action( "getpaid_invoice_save_items", $invoice ); |
|
481 | 481 | |
482 | - } |
|
482 | + } |
|
483 | 483 | |
484 | - /** |
|
484 | + /** |
|
485 | 485 | * Deletes an invoice's cart details from the database. |
486 | - * |
|
487 | - * @param WPInv_Invoice $invoice Invoice object. |
|
486 | + * |
|
487 | + * @param WPInv_Invoice $invoice Invoice object. |
|
488 | 488 | */ |
489 | 489 | public function delete_items( $invoice ) { |
490 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
491 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
492 | - } |
|
490 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
491 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
492 | + } |
|
493 | 493 | |
494 | - /** |
|
494 | + /** |
|
495 | 495 | * Deletes an invoice's special fields from the database. |
496 | - * |
|
497 | - * @param WPInv_Invoice $invoice Invoice object. |
|
496 | + * |
|
497 | + * @param WPInv_Invoice $invoice Invoice object. |
|
498 | 498 | */ |
499 | 499 | public function delete_special_fields( $invoice ) { |
500 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
501 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
500 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
501 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | } |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | */ |
160 | 160 | function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
161 | 161 | |
162 | - if ( current_user_can( 'manage_options' ) ) { |
|
163 | - return 'manage_options'; |
|
164 | - }; |
|
162 | + if ( current_user_can( 'manage_options' ) ) { |
|
163 | + return 'manage_options'; |
|
164 | + }; |
|
165 | 165 | |
166 | - return $capalibilty; |
|
166 | + return $capalibilty; |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | function wpinv_create_user( $email ) { |
186 | 186 | |
187 | 187 | // Prepare user values. |
188 | - $args = array( |
|
189 | - 'user_login' => wpinv_generate_user_name( $email ), |
|
190 | - 'user_pass' => wp_generate_password(), |
|
191 | - 'user_email' => $email, |
|
188 | + $args = array( |
|
189 | + 'user_login' => wpinv_generate_user_name( $email ), |
|
190 | + 'user_pass' => wp_generate_password(), |
|
191 | + 'user_email' => $email, |
|
192 | 192 | 'role' => 'subscriber', |
193 | 193 | ); |
194 | 194 | |
@@ -205,20 +205,20 @@ discard block |
||
205 | 205 | function wpinv_generate_user_name( $prefix = '' ) { |
206 | 206 | |
207 | 207 | // If prefix is an email, retrieve the part before the email. |
208 | - $prefix = strtok( $prefix, '@' ); |
|
208 | + $prefix = strtok( $prefix, '@' ); |
|
209 | 209 | |
210 | - // Trim to 4 characters max. |
|
211 | - $prefix = sanitize_user( $prefix ); |
|
210 | + // Trim to 4 characters max. |
|
211 | + $prefix = sanitize_user( $prefix ); |
|
212 | 212 | |
213 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
214 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
215 | - $prefix = 'gtp'; |
|
216 | - } |
|
213 | + $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
214 | + if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
215 | + $prefix = 'gtp'; |
|
216 | + } |
|
217 | 217 | |
218 | - $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
219 | - if ( username_exists( $username ) ) { |
|
220 | - return wpinv_generate_user_name( $username ); |
|
221 | - } |
|
218 | + $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
219 | + if ( username_exists( $username ) ) { |
|
220 | + return wpinv_generate_user_name( $username ); |
|
221 | + } |
|
222 | 222 | |
223 | 223 | return $username; |
224 | 224 | } |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
162 | 162 | |
163 | 163 | // Register autoloader. |
164 | - try { |
|
165 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
166 | - } catch ( Exception $e ) { |
|
167 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
164 | + try { |
|
165 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
166 | + } catch ( Exception $e ) { |
|
167 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | require_once( WPINV_PLUGIN_DIR . 'includes/class-getpaid-post-types.php' ); |
@@ -189,11 +189,11 @@ discard block |
||
189 | 189 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
190 | 190 | require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
191 | 191 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
192 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
192 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
197 | 197 | require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
198 | 198 | require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
199 | 199 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
@@ -253,47 +253,47 @@ discard block |
||
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | - * Class autoloader |
|
257 | - * |
|
258 | - * @param string $class_name The name of the class to load. |
|
259 | - * @access public |
|
260 | - * @since 1.0.19 |
|
261 | - * @return void |
|
262 | - */ |
|
263 | - public function autoload( $class_name ) { |
|
264 | - |
|
265 | - // Normalize the class name... |
|
266 | - $class_name = strtolower( $class_name ); |
|
267 | - |
|
268 | - // ... and make sure it is our class. |
|
269 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
270 | - return; |
|
271 | - } |
|
272 | - |
|
273 | - // Next, prepare the file name from the class. |
|
274 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
275 | - |
|
276 | - // And an array of possible locations in order of importance. |
|
277 | - $locations = array( |
|
278 | - 'includes', |
|
279 | - 'includes/data-stores', |
|
256 | + * Class autoloader |
|
257 | + * |
|
258 | + * @param string $class_name The name of the class to load. |
|
259 | + * @access public |
|
260 | + * @since 1.0.19 |
|
261 | + * @return void |
|
262 | + */ |
|
263 | + public function autoload( $class_name ) { |
|
264 | + |
|
265 | + // Normalize the class name... |
|
266 | + $class_name = strtolower( $class_name ); |
|
267 | + |
|
268 | + // ... and make sure it is our class. |
|
269 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
270 | + return; |
|
271 | + } |
|
272 | + |
|
273 | + // Next, prepare the file name from the class. |
|
274 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
275 | + |
|
276 | + // And an array of possible locations in order of importance. |
|
277 | + $locations = array( |
|
278 | + 'includes', |
|
279 | + 'includes/data-stores', |
|
280 | 280 | 'includes/admin', |
281 | 281 | 'includes/admin/meta-boxes' |
282 | - ); |
|
282 | + ); |
|
283 | 283 | |
284 | - // Base path of the classes. |
|
285 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
284 | + // Base path of the classes. |
|
285 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
286 | 286 | |
287 | - foreach ( $locations as $location ) { |
|
287 | + foreach ( $locations as $location ) { |
|
288 | 288 | |
289 | - if ( file_exists( "$plugin_path/$location/$file_name" ) ) { |
|
290 | - include "$plugin_path/$location/$file_name"; |
|
291 | - break; |
|
292 | - } |
|
289 | + if ( file_exists( "$plugin_path/$location/$file_name" ) ) { |
|
290 | + include "$plugin_path/$location/$file_name"; |
|
291 | + break; |
|
292 | + } |
|
293 | 293 | |
294 | - } |
|
294 | + } |
|
295 | 295 | |
296 | - } |
|
296 | + } |
|
297 | 297 | |
298 | 298 | public function init() { |
299 | 299 | } |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
387 | 387 | wp_enqueue_style( 'jquery-ui-css' ); |
388 | 388 | wp_deregister_style( 'yoast-seo-select2' ); |
389 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
389 | + wp_deregister_style( 'yoast-seo-monorepo' ); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | if ( $page == 'wpinv-subscriptions' ) { |
401 | 401 | wp_enqueue_script( 'jquery-ui-datepicker' ); |
402 | 402 | wp_deregister_style( 'yoast-seo-select2' ); |
403 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
403 | + wp_deregister_style( 'yoast-seo-monorepo' ); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
@@ -569,19 +569,19 @@ discard block |
||
569 | 569 | require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
570 | 570 | } |
571 | 571 | |
572 | - /** |
|
573 | - * Register widgets |
|
574 | - * |
|
575 | - */ |
|
576 | - public function register_widgets() { |
|
577 | - register_widget( "WPInv_Checkout_Widget" ); |
|
578 | - register_widget( "WPInv_History_Widget" ); |
|
579 | - register_widget( "WPInv_Receipt_Widget" ); |
|
580 | - register_widget( "WPInv_Subscriptions_Widget" ); |
|
581 | - register_widget( "WPInv_Buy_Item_Widget" ); |
|
572 | + /** |
|
573 | + * Register widgets |
|
574 | + * |
|
575 | + */ |
|
576 | + public function register_widgets() { |
|
577 | + register_widget( "WPInv_Checkout_Widget" ); |
|
578 | + register_widget( "WPInv_History_Widget" ); |
|
579 | + register_widget( "WPInv_Receipt_Widget" ); |
|
580 | + register_widget( "WPInv_Subscriptions_Widget" ); |
|
581 | + register_widget( "WPInv_Buy_Item_Widget" ); |
|
582 | 582 | register_widget( "WPInv_Messages_Widget" ); |
583 | 583 | register_widget( 'WPInv_GetPaid_Widget' ); |
584 | - } |
|
584 | + } |
|
585 | 585 | |
586 | 586 | /** |
587 | 587 | * Remove our pages from yoast sitemaps. |