@@ -15,125 +15,125 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $data_store_name = 'subscription'; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'subscription'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Item Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'customer_id' => 0, |
|
40 | - 'frequency' => 1, |
|
41 | - 'period' => 'D', |
|
42 | - 'initial_amount' => null, |
|
43 | - 'recurring_amount' => null, |
|
44 | - 'bill_times' => 0, |
|
45 | - 'transaction_id' => '', |
|
46 | - 'parent_payment_id' => null, |
|
47 | - 'product_id' => 0, |
|
48 | - 'created' => '0000-00-00 00:00:00', |
|
49 | - 'expiration' => '0000-00-00 00:00:00', |
|
50 | - 'trial_period' => '', |
|
51 | - 'status' => 'pending', |
|
52 | - 'profile_id' => '', |
|
53 | - 'gateway' => '', |
|
54 | - 'customer' => '', |
|
55 | - ); |
|
56 | - |
|
57 | - /** |
|
58 | - * Stores the status transition information. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - protected $status_transition = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | - * |
|
68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | - * @param bool $deprecated |
|
70 | - */ |
|
71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | - |
|
73 | - parent::__construct( $subscription ); |
|
74 | - |
|
75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | - $this->set_id( $subscription ); |
|
77 | - } elseif ( $subscription instanceof self ) { |
|
78 | - $this->set_id( $subscription->get_id() ); |
|
79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | - $this->set_id( $subscription_id ); |
|
81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
82 | - $this->set_id( $subscription->id ); |
|
83 | - } else { |
|
84 | - $this->set_object_read( true ); |
|
85 | - } |
|
86 | - |
|
87 | - // Load the datastore. |
|
88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | - |
|
90 | - if ( $this->get_id() > 0 ) { |
|
91 | - $this->data_store->read( $this ); |
|
92 | - } |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | - * |
|
99 | - * |
|
100 | - * @static |
|
101 | - * @param string $value |
|
102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | - * @since 1.0.19 |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $data_store_name = 'subscription'; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'subscription'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Item Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'customer_id' => 0, |
|
40 | + 'frequency' => 1, |
|
41 | + 'period' => 'D', |
|
42 | + 'initial_amount' => null, |
|
43 | + 'recurring_amount' => null, |
|
44 | + 'bill_times' => 0, |
|
45 | + 'transaction_id' => '', |
|
46 | + 'parent_payment_id' => null, |
|
47 | + 'product_id' => 0, |
|
48 | + 'created' => '0000-00-00 00:00:00', |
|
49 | + 'expiration' => '0000-00-00 00:00:00', |
|
50 | + 'trial_period' => '', |
|
51 | + 'status' => 'pending', |
|
52 | + 'profile_id' => '', |
|
53 | + 'gateway' => '', |
|
54 | + 'customer' => '', |
|
55 | + ); |
|
56 | + |
|
57 | + /** |
|
58 | + * Stores the status transition information. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + protected $status_transition = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | + * |
|
68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | + * @param bool $deprecated |
|
70 | + */ |
|
71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | + |
|
73 | + parent::__construct( $subscription ); |
|
74 | + |
|
75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | + $this->set_id( $subscription ); |
|
77 | + } elseif ( $subscription instanceof self ) { |
|
78 | + $this->set_id( $subscription->get_id() ); |
|
79 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | + $this->set_id( $subscription_id ); |
|
81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
82 | + $this->set_id( $subscription->id ); |
|
83 | + } else { |
|
84 | + $this->set_object_read( true ); |
|
85 | + } |
|
86 | + |
|
87 | + // Load the datastore. |
|
88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | + |
|
90 | + if ( $this->get_id() > 0 ) { |
|
91 | + $this->data_store->read( $this ); |
|
92 | + } |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | + * |
|
99 | + * |
|
100 | + * @static |
|
101 | + * @param string $value |
|
102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | + * @since 1.0.19 |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | - // Trim the value. |
|
110 | - $value = trim( $value ); |
|
109 | + // Trim the value. |
|
110 | + $value = trim( $value ); |
|
111 | 111 | |
112 | - if ( empty( $value ) ) { |
|
113 | - return 0; |
|
114 | - } |
|
112 | + if ( empty( $value ) ) { |
|
113 | + return 0; |
|
114 | + } |
|
115 | 115 | |
116 | - if ( 'invoice_id' == $field ) { |
|
117 | - $field = 'parent_payment_id'; |
|
118 | - } |
|
116 | + if ( 'invoice_id' == $field ) { |
|
117 | + $field = 'parent_payment_id'; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | // Valid fields. |
121 | 121 | $fields = array( |
122 | - 'parent_payment_id', |
|
123 | - 'transaction_id', |
|
124 | - 'profile_id', |
|
125 | - ); |
|
126 | - |
|
127 | - // Ensure a field has been passed. |
|
128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | - return 0; |
|
130 | - } |
|
131 | - |
|
132 | - // Maybe retrieve from the cache. |
|
133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | - if ( ! empty( $subscription_id ) ) { |
|
135 | - return $subscription_id; |
|
136 | - } |
|
122 | + 'parent_payment_id', |
|
123 | + 'transaction_id', |
|
124 | + 'profile_id', |
|
125 | + ); |
|
126 | + |
|
127 | + // Ensure a field has been passed. |
|
128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | + return 0; |
|
130 | + } |
|
131 | + |
|
132 | + // Maybe retrieve from the cache. |
|
133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | + if ( ! empty( $subscription_id ) ) { |
|
135 | + return $subscription_id; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | // Fetch from the db. |
139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,42 +141,42 @@ discard block |
||
141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
142 | 142 | ); |
143 | 143 | |
144 | - if ( empty( $subscription_id ) ) { |
|
145 | - return 0; |
|
146 | - } |
|
144 | + if ( empty( $subscription_id ) ) { |
|
145 | + return 0; |
|
146 | + } |
|
147 | 147 | |
148 | - // Update the cache with our data. |
|
149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
148 | + // Update the cache with our data. |
|
149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
150 | 150 | |
151 | - return $subscription_id; |
|
152 | - } |
|
151 | + return $subscription_id; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
154 | + /** |
|
155 | 155 | * Clears the subscription's cache. |
156 | 156 | */ |
157 | 157 | public function clear_cache() { |
158 | - $caches = array( |
|
159 | - 'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(), |
|
160 | - 'getpaid_subscription_transaction_ids_to_subscription_ids' => $this->get_transaction_id(), |
|
161 | - 'getpaid_subscription_profile_ids_to_subscription_ids' => $this->get_profile_id(), |
|
162 | - 'getpaid_subscriptions' => $this->get_id(), |
|
163 | - ); |
|
164 | - |
|
165 | - foreach ( $caches as $cache => $value ) { |
|
166 | - if ( '' !== $value && false !== $value ) { |
|
167 | - wp_cache_delete( $value, $cache ); |
|
168 | - } |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
158 | + $caches = array( |
|
159 | + 'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(), |
|
160 | + 'getpaid_subscription_transaction_ids_to_subscription_ids' => $this->get_transaction_id(), |
|
161 | + 'getpaid_subscription_profile_ids_to_subscription_ids' => $this->get_profile_id(), |
|
162 | + 'getpaid_subscriptions' => $this->get_id(), |
|
163 | + ); |
|
164 | + |
|
165 | + foreach ( $caches as $cache => $value ) { |
|
166 | + if ( '' !== $value && false !== $value ) { |
|
167 | + wp_cache_delete( $value, $cache ); |
|
168 | + } |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | 173 | * Checks if a subscription key is set. |
174 | 174 | */ |
175 | 175 | public function _isset( $key ) { |
176 | 176 | return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
177 | - } |
|
177 | + } |
|
178 | 178 | |
179 | - /* |
|
179 | + /* |
|
180 | 180 | |-------------------------------------------------------------------------- |
181 | 181 | | CRUD methods |
182 | 182 | |-------------------------------------------------------------------------- |
@@ -185,544 +185,544 @@ discard block |
||
185 | 185 | | |
186 | 186 | */ |
187 | 187 | |
188 | - /* |
|
188 | + /* |
|
189 | 189 | |-------------------------------------------------------------------------- |
190 | 190 | | Getters |
191 | 191 | |-------------------------------------------------------------------------- |
192 | 192 | */ |
193 | 193 | |
194 | - /** |
|
195 | - * Get customer id. |
|
196 | - * |
|
197 | - * @since 1.0.19 |
|
198 | - * @param string $context View or edit context. |
|
199 | - * @return int |
|
200 | - */ |
|
201 | - public function get_customer_id( $context = 'view' ) { |
|
202 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Get customer information. |
|
207 | - * |
|
208 | - * @since 1.0.19 |
|
209 | - * @param string $context View or edit context. |
|
210 | - * @return WP_User|false WP_User object on success, false on failure. |
|
211 | - */ |
|
212 | - public function get_customer( $context = 'view' ) { |
|
213 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Get parent invoice id. |
|
218 | - * |
|
219 | - * @since 1.0.19 |
|
220 | - * @param string $context View or edit context. |
|
221 | - * @return int |
|
222 | - */ |
|
223 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
224 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Alias for self::get_parent_invoice_id(). |
|
229 | - * |
|
230 | - * @since 1.0.19 |
|
231 | - * @param string $context View or edit context. |
|
232 | - * @return int |
|
233 | - */ |
|
194 | + /** |
|
195 | + * Get customer id. |
|
196 | + * |
|
197 | + * @since 1.0.19 |
|
198 | + * @param string $context View or edit context. |
|
199 | + * @return int |
|
200 | + */ |
|
201 | + public function get_customer_id( $context = 'view' ) { |
|
202 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Get customer information. |
|
207 | + * |
|
208 | + * @since 1.0.19 |
|
209 | + * @param string $context View or edit context. |
|
210 | + * @return WP_User|false WP_User object on success, false on failure. |
|
211 | + */ |
|
212 | + public function get_customer( $context = 'view' ) { |
|
213 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Get parent invoice id. |
|
218 | + * |
|
219 | + * @since 1.0.19 |
|
220 | + * @param string $context View or edit context. |
|
221 | + * @return int |
|
222 | + */ |
|
223 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
224 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Alias for self::get_parent_invoice_id(). |
|
229 | + * |
|
230 | + * @since 1.0.19 |
|
231 | + * @param string $context View or edit context. |
|
232 | + * @return int |
|
233 | + */ |
|
234 | 234 | public function get_parent_payment_id( $context = 'view' ) { |
235 | 235 | return $this->get_parent_invoice_id( $context ); |
236 | - } |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Alias for self::get_parent_invoice_id(). |
|
240 | + * |
|
241 | + * @since 1.0.0 |
|
242 | + * @return int |
|
243 | + */ |
|
244 | + public function get_original_payment_id( $context = 'view' ) { |
|
245 | + return $this->get_parent_invoice_id( $context ); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Get parent invoice. |
|
250 | + * |
|
251 | + * @since 1.0.19 |
|
252 | + * @param string $context View or edit context. |
|
253 | + * @return WPInv_Invoice |
|
254 | + */ |
|
255 | + public function get_parent_invoice( $context = 'view' ) { |
|
256 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Alias for self::get_parent_invoice(). |
|
261 | + * |
|
262 | + * @since 1.0.19 |
|
263 | + * @param string $context View or edit context. |
|
264 | + * @return WPInv_Invoice |
|
265 | + */ |
|
266 | + public function get_parent_payment( $context = 'view' ) { |
|
267 | + return $this->get_parent_invoice( $context ); |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Get subscription's product id. |
|
272 | + * |
|
273 | + * @since 1.0.19 |
|
274 | + * @param string $context View or edit context. |
|
275 | + * @return int |
|
276 | + */ |
|
277 | + public function get_product_id( $context = 'view' ) { |
|
278 | + return (int) $this->get_prop( 'product_id', $context ); |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Get the subscription product. |
|
283 | + * |
|
284 | + * @since 1.0.19 |
|
285 | + * @param string $context View or edit context. |
|
286 | + * @return WPInv_Item |
|
287 | + */ |
|
288 | + public function get_product( $context = 'view' ) { |
|
289 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Get parent invoice's gateway. |
|
294 | + * |
|
295 | + * Here for backwards compatibility. |
|
296 | + * |
|
297 | + * @since 1.0.19 |
|
298 | + * @param string $context View or edit context. |
|
299 | + * @return string |
|
300 | + */ |
|
301 | + public function get_gateway( $context = 'view' ) { |
|
302 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Get the period of a renewal. |
|
307 | + * |
|
308 | + * @since 1.0.19 |
|
309 | + * @param string $context View or edit context. |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function get_period( $context = 'view' ) { |
|
313 | + return $this->get_prop( 'period', $context ); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Get number of periods each renewal is valid for. |
|
318 | + * |
|
319 | + * @since 1.0.19 |
|
320 | + * @param string $context View or edit context. |
|
321 | + * @return int |
|
322 | + */ |
|
323 | + public function get_frequency( $context = 'view' ) { |
|
324 | + return (int) $this->get_prop( 'frequency', $context ); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Get the initial amount for the subscription. |
|
329 | + * |
|
330 | + * @since 1.0.19 |
|
331 | + * @param string $context View or edit context. |
|
332 | + * @return float |
|
333 | + */ |
|
334 | + public function get_initial_amount( $context = 'view' ) { |
|
335 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Get the recurring amount for the subscription. |
|
340 | + * |
|
341 | + * @since 1.0.19 |
|
342 | + * @param string $context View or edit context. |
|
343 | + * @return float |
|
344 | + */ |
|
345 | + public function get_recurring_amount( $context = 'view' ) { |
|
346 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Get number of times that this subscription can be renewed. |
|
351 | + * |
|
352 | + * @since 1.0.19 |
|
353 | + * @param string $context View or edit context. |
|
354 | + * @return int |
|
355 | + */ |
|
356 | + public function get_bill_times( $context = 'view' ) { |
|
357 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Get transaction id of this subscription's parent invoice. |
|
362 | + * |
|
363 | + * @since 1.0.19 |
|
364 | + * @param string $context View or edit context. |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public function get_transaction_id( $context = 'view' ) { |
|
368 | + return $this->get_prop( 'transaction_id', $context ); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Get the date that the subscription was created. |
|
373 | + * |
|
374 | + * @since 1.0.19 |
|
375 | + * @param string $context View or edit context. |
|
376 | + * @return string |
|
377 | + */ |
|
378 | + public function get_created( $context = 'view' ) { |
|
379 | + return $this->get_prop( 'created', $context ); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Alias for self::get_created(). |
|
384 | + * |
|
385 | + * @since 1.0.19 |
|
386 | + * @param string $context View or edit context. |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_date_created( $context = 'view' ) { |
|
390 | + return $this->get_created( $context ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Retrieves the creation date in a timestamp |
|
395 | + * |
|
396 | + * @since 1.0.0 |
|
397 | + * @return int |
|
398 | + */ |
|
399 | + public function get_time_created() { |
|
400 | + $created = $this->get_date_created(); |
|
401 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Get GMT date when the subscription was created. |
|
406 | + * |
|
407 | + * @since 1.0.19 |
|
408 | + * @param string $context View or edit context. |
|
409 | + * @return string |
|
410 | + */ |
|
411 | + public function get_date_created_gmt( $context = 'view' ) { |
|
412 | + $date = $this->get_date_created( $context ); |
|
413 | + |
|
414 | + if ( $date ) { |
|
415 | + $date = get_gmt_from_date( $date ); |
|
416 | + } |
|
417 | + return $date; |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * Get the date that the subscription will renew. |
|
422 | + * |
|
423 | + * @since 1.0.19 |
|
424 | + * @param string $context View or edit context. |
|
425 | + * @return string |
|
426 | + */ |
|
427 | + public function get_next_renewal_date( $context = 'view' ) { |
|
428 | + return $this->get_prop( 'expiration', $context ); |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Alias for self::get_next_renewal_date(). |
|
433 | + * |
|
434 | + * @since 1.0.19 |
|
435 | + * @param string $context View or edit context. |
|
436 | + * @return string |
|
437 | + */ |
|
438 | + public function get_expiration( $context = 'view' ) { |
|
439 | + return $this->get_next_renewal_date( $context ); |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Retrieves the expiration date in a timestamp |
|
444 | + * |
|
445 | + * @since 1.0.0 |
|
446 | + * @return int |
|
447 | + */ |
|
448 | + public function get_expiration_time() { |
|
449 | + $expiration = $this->get_expiration(); |
|
450 | + |
|
451 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
452 | + return current_time( 'timestamp' ); |
|
453 | + } |
|
454 | + |
|
455 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
456 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Get GMT date when the subscription will renew. |
|
461 | + * |
|
462 | + * @since 1.0.19 |
|
463 | + * @param string $context View or edit context. |
|
464 | + * @return string |
|
465 | + */ |
|
466 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
467 | + $date = $this->get_next_renewal_date( $context ); |
|
468 | + |
|
469 | + if ( $date ) { |
|
470 | + $date = get_gmt_from_date( $date ); |
|
471 | + } |
|
472 | + return $date; |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Get the subscription's trial period. |
|
477 | + * |
|
478 | + * @since 1.0.19 |
|
479 | + * @param string $context View or edit context. |
|
480 | + * @return string |
|
481 | + */ |
|
482 | + public function get_trial_period( $context = 'view' ) { |
|
483 | + return $this->get_prop( 'trial_period', $context ); |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Get the subscription's status. |
|
488 | + * |
|
489 | + * @since 1.0.19 |
|
490 | + * @param string $context View or edit context. |
|
491 | + * @return string |
|
492 | + */ |
|
493 | + public function get_status( $context = 'view' ) { |
|
494 | + return $this->get_prop( 'status', $context ); |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * Get the subscription's profile id. |
|
499 | + * |
|
500 | + * @since 1.0.19 |
|
501 | + * @param string $context View or edit context. |
|
502 | + * @return string |
|
503 | + */ |
|
504 | + public function get_profile_id( $context = 'view' ) { |
|
505 | + return $this->get_prop( 'profile_id', $context ); |
|
506 | + } |
|
507 | + |
|
508 | + /* |
|
509 | + |-------------------------------------------------------------------------- |
|
510 | + | Setters |
|
511 | + |-------------------------------------------------------------------------- |
|
512 | + */ |
|
513 | + |
|
514 | + /** |
|
515 | + * Set customer id. |
|
516 | + * |
|
517 | + * @since 1.0.19 |
|
518 | + * @param int $value The customer's id. |
|
519 | + */ |
|
520 | + public function set_customer_id( $value ) { |
|
521 | + $this->set_prop( 'customer_id', (int) $value ); |
|
522 | + } |
|
523 | + |
|
524 | + /** |
|
525 | + * Set parent invoice id. |
|
526 | + * |
|
527 | + * @since 1.0.19 |
|
528 | + * @param int $value The parent invoice id. |
|
529 | + */ |
|
530 | + public function set_parent_invoice_id( $value ) { |
|
531 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
532 | + } |
|
533 | + |
|
534 | + /** |
|
535 | + * Alias for self::set_parent_invoice_id(). |
|
536 | + * |
|
537 | + * @since 1.0.19 |
|
538 | + * @param int $value The parent invoice id. |
|
539 | + */ |
|
540 | + public function set_parent_payment_id( $value ) { |
|
541 | + $this->set_parent_invoice_id( $value ); |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Alias for self::set_parent_invoice_id(). |
|
546 | + * |
|
547 | + * @since 1.0.19 |
|
548 | + * @param int $value The parent invoice id. |
|
549 | + */ |
|
550 | + public function set_original_payment_id( $value ) { |
|
551 | + $this->set_parent_invoice_id( $value ); |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * Set subscription's product id. |
|
556 | + * |
|
557 | + * @since 1.0.19 |
|
558 | + * @param int $value The subscription product id. |
|
559 | + */ |
|
560 | + public function set_product_id( $value ) { |
|
561 | + $this->set_prop( 'product_id', (int) $value ); |
|
562 | + } |
|
563 | + |
|
564 | + /** |
|
565 | + * Set the period of a renewal. |
|
566 | + * |
|
567 | + * @since 1.0.19 |
|
568 | + * @param string $value The renewal period. |
|
569 | + */ |
|
570 | + public function set_period( $value ) { |
|
571 | + $this->set_prop( 'period', $value ); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Set number of periods each renewal is valid for. |
|
576 | + * |
|
577 | + * @since 1.0.19 |
|
578 | + * @param int $value The subscription frequency. |
|
579 | + */ |
|
580 | + public function set_frequency( $value ) { |
|
581 | + $value = empty( $value ) ? 1 : (int) $value; |
|
582 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * Set the initial amount for the subscription. |
|
587 | + * |
|
588 | + * @since 1.0.19 |
|
589 | + * @param float $value The initial subcription amount. |
|
590 | + */ |
|
591 | + public function set_initial_amount( $value ) { |
|
592 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Set the recurring amount for the subscription. |
|
597 | + * |
|
598 | + * @since 1.0.19 |
|
599 | + * @param float $value The recurring subcription amount. |
|
600 | + */ |
|
601 | + public function set_recurring_amount( $value ) { |
|
602 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Set number of times that this subscription can be renewed. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param int $value Bill times. |
|
610 | + */ |
|
611 | + public function set_bill_times( $value ) { |
|
612 | + $this->set_prop( 'bill_times', (int) $value ); |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Get transaction id of this subscription's parent invoice. |
|
617 | + * |
|
618 | + * @since 1.0.19 |
|
619 | + * @param string $value Bill times. |
|
620 | + */ |
|
621 | + public function set_transaction_id( $value ) { |
|
622 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * Set date when this subscription started. |
|
627 | + * |
|
628 | + * @since 1.0.19 |
|
629 | + * @param string $value strtotime compliant date. |
|
630 | + */ |
|
631 | + public function set_created( $value ) { |
|
632 | + $date = strtotime( $value ); |
|
633 | + |
|
634 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
635 | + $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
636 | + return; |
|
637 | + } |
|
638 | + |
|
639 | + $this->set_prop( 'created', '' ); |
|
640 | + |
|
641 | + } |
|
237 | 642 | |
238 | - /** |
|
239 | - * Alias for self::get_parent_invoice_id(). |
|
643 | + /** |
|
644 | + * Alias for self::set_created(). |
|
240 | 645 | * |
241 | - * @since 1.0.0 |
|
242 | - * @return int |
|
646 | + * @since 1.0.19 |
|
647 | + * @param string $value strtotime compliant date. |
|
243 | 648 | */ |
244 | - public function get_original_payment_id( $context = 'view' ) { |
|
245 | - return $this->get_parent_invoice_id( $context ); |
|
649 | + public function set_date_created( $value ) { |
|
650 | + $this->set_created( $value ); |
|
246 | 651 | } |
247 | 652 | |
248 | - /** |
|
249 | - * Get parent invoice. |
|
250 | - * |
|
251 | - * @since 1.0.19 |
|
252 | - * @param string $context View or edit context. |
|
253 | - * @return WPInv_Invoice |
|
254 | - */ |
|
255 | - public function get_parent_invoice( $context = 'view' ) { |
|
256 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Alias for self::get_parent_invoice(). |
|
261 | - * |
|
262 | - * @since 1.0.19 |
|
263 | - * @param string $context View or edit context. |
|
264 | - * @return WPInv_Invoice |
|
265 | - */ |
|
266 | - public function get_parent_payment( $context = 'view' ) { |
|
267 | - return $this->get_parent_invoice( $context ); |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Get subscription's product id. |
|
272 | - * |
|
273 | - * @since 1.0.19 |
|
274 | - * @param string $context View or edit context. |
|
275 | - * @return int |
|
276 | - */ |
|
277 | - public function get_product_id( $context = 'view' ) { |
|
278 | - return (int) $this->get_prop( 'product_id', $context ); |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Get the subscription product. |
|
283 | - * |
|
284 | - * @since 1.0.19 |
|
285 | - * @param string $context View or edit context. |
|
286 | - * @return WPInv_Item |
|
287 | - */ |
|
288 | - public function get_product( $context = 'view' ) { |
|
289 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Get parent invoice's gateway. |
|
294 | - * |
|
295 | - * Here for backwards compatibility. |
|
296 | - * |
|
297 | - * @since 1.0.19 |
|
298 | - * @param string $context View or edit context. |
|
299 | - * @return string |
|
300 | - */ |
|
301 | - public function get_gateway( $context = 'view' ) { |
|
302 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Get the period of a renewal. |
|
307 | - * |
|
308 | - * @since 1.0.19 |
|
309 | - * @param string $context View or edit context. |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function get_period( $context = 'view' ) { |
|
313 | - return $this->get_prop( 'period', $context ); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Get number of periods each renewal is valid for. |
|
318 | - * |
|
319 | - * @since 1.0.19 |
|
320 | - * @param string $context View or edit context. |
|
321 | - * @return int |
|
322 | - */ |
|
323 | - public function get_frequency( $context = 'view' ) { |
|
324 | - return (int) $this->get_prop( 'frequency', $context ); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Get the initial amount for the subscription. |
|
329 | - * |
|
330 | - * @since 1.0.19 |
|
331 | - * @param string $context View or edit context. |
|
332 | - * @return float |
|
333 | - */ |
|
334 | - public function get_initial_amount( $context = 'view' ) { |
|
335 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Get the recurring amount for the subscription. |
|
340 | - * |
|
341 | - * @since 1.0.19 |
|
342 | - * @param string $context View or edit context. |
|
343 | - * @return float |
|
344 | - */ |
|
345 | - public function get_recurring_amount( $context = 'view' ) { |
|
346 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Get number of times that this subscription can be renewed. |
|
351 | - * |
|
352 | - * @since 1.0.19 |
|
353 | - * @param string $context View or edit context. |
|
354 | - * @return int |
|
355 | - */ |
|
356 | - public function get_bill_times( $context = 'view' ) { |
|
357 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Get transaction id of this subscription's parent invoice. |
|
362 | - * |
|
363 | - * @since 1.0.19 |
|
364 | - * @param string $context View or edit context. |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public function get_transaction_id( $context = 'view' ) { |
|
368 | - return $this->get_prop( 'transaction_id', $context ); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Get the date that the subscription was created. |
|
373 | - * |
|
374 | - * @since 1.0.19 |
|
375 | - * @param string $context View or edit context. |
|
376 | - * @return string |
|
377 | - */ |
|
378 | - public function get_created( $context = 'view' ) { |
|
379 | - return $this->get_prop( 'created', $context ); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Alias for self::get_created(). |
|
384 | - * |
|
385 | - * @since 1.0.19 |
|
386 | - * @param string $context View or edit context. |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_date_created( $context = 'view' ) { |
|
390 | - return $this->get_created( $context ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Retrieves the creation date in a timestamp |
|
395 | - * |
|
396 | - * @since 1.0.0 |
|
397 | - * @return int |
|
398 | - */ |
|
399 | - public function get_time_created() { |
|
400 | - $created = $this->get_date_created(); |
|
401 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Get GMT date when the subscription was created. |
|
406 | - * |
|
407 | - * @since 1.0.19 |
|
408 | - * @param string $context View or edit context. |
|
409 | - * @return string |
|
410 | - */ |
|
411 | - public function get_date_created_gmt( $context = 'view' ) { |
|
412 | - $date = $this->get_date_created( $context ); |
|
653 | + /** |
|
654 | + * Set the date that the subscription will renew. |
|
655 | + * |
|
656 | + * @since 1.0.19 |
|
657 | + * @param string $value strtotime compliant date. |
|
658 | + */ |
|
659 | + public function set_next_renewal_date( $value ) { |
|
660 | + $date = strtotime( $value ); |
|
413 | 661 | |
414 | - if ( $date ) { |
|
415 | - $date = get_gmt_from_date( $date ); |
|
662 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
663 | + $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
664 | + return; |
|
416 | 665 | } |
417 | - return $date; |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * Get the date that the subscription will renew. |
|
422 | - * |
|
423 | - * @since 1.0.19 |
|
424 | - * @param string $context View or edit context. |
|
425 | - * @return string |
|
426 | - */ |
|
427 | - public function get_next_renewal_date( $context = 'view' ) { |
|
428 | - return $this->get_prop( 'expiration', $context ); |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Alias for self::get_next_renewal_date(). |
|
433 | - * |
|
434 | - * @since 1.0.19 |
|
435 | - * @param string $context View or edit context. |
|
436 | - * @return string |
|
437 | - */ |
|
438 | - public function get_expiration( $context = 'view' ) { |
|
439 | - return $this->get_next_renewal_date( $context ); |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Retrieves the expiration date in a timestamp |
|
444 | - * |
|
445 | - * @since 1.0.0 |
|
446 | - * @return int |
|
447 | - */ |
|
448 | - public function get_expiration_time() { |
|
449 | - $expiration = $this->get_expiration(); |
|
450 | - |
|
451 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
452 | - return current_time( 'timestamp' ); |
|
453 | - } |
|
454 | - |
|
455 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
456 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Get GMT date when the subscription will renew. |
|
461 | - * |
|
462 | - * @since 1.0.19 |
|
463 | - * @param string $context View or edit context. |
|
464 | - * @return string |
|
465 | - */ |
|
466 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
467 | - $date = $this->get_next_renewal_date( $context ); |
|
468 | 666 | |
469 | - if ( $date ) { |
|
470 | - $date = get_gmt_from_date( $date ); |
|
471 | - } |
|
472 | - return $date; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Get the subscription's trial period. |
|
477 | - * |
|
478 | - * @since 1.0.19 |
|
479 | - * @param string $context View or edit context. |
|
480 | - * @return string |
|
481 | - */ |
|
482 | - public function get_trial_period( $context = 'view' ) { |
|
483 | - return $this->get_prop( 'trial_period', $context ); |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Get the subscription's status. |
|
488 | - * |
|
489 | - * @since 1.0.19 |
|
490 | - * @param string $context View or edit context. |
|
491 | - * @return string |
|
492 | - */ |
|
493 | - public function get_status( $context = 'view' ) { |
|
494 | - return $this->get_prop( 'status', $context ); |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * Get the subscription's profile id. |
|
499 | - * |
|
500 | - * @since 1.0.19 |
|
501 | - * @param string $context View or edit context. |
|
502 | - * @return string |
|
503 | - */ |
|
504 | - public function get_profile_id( $context = 'view' ) { |
|
505 | - return $this->get_prop( 'profile_id', $context ); |
|
506 | - } |
|
507 | - |
|
508 | - /* |
|
509 | - |-------------------------------------------------------------------------- |
|
510 | - | Setters |
|
511 | - |-------------------------------------------------------------------------- |
|
512 | - */ |
|
667 | + $this->set_prop( 'expiration', '' ); |
|
513 | 668 | |
514 | - /** |
|
515 | - * Set customer id. |
|
516 | - * |
|
517 | - * @since 1.0.19 |
|
518 | - * @param int $value The customer's id. |
|
519 | - */ |
|
520 | - public function set_customer_id( $value ) { |
|
521 | - $this->set_prop( 'customer_id', (int) $value ); |
|
522 | - } |
|
523 | - |
|
524 | - /** |
|
525 | - * Set parent invoice id. |
|
526 | - * |
|
527 | - * @since 1.0.19 |
|
528 | - * @param int $value The parent invoice id. |
|
529 | - */ |
|
530 | - public function set_parent_invoice_id( $value ) { |
|
531 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
532 | - } |
|
533 | - |
|
534 | - /** |
|
535 | - * Alias for self::set_parent_invoice_id(). |
|
536 | - * |
|
537 | - * @since 1.0.19 |
|
538 | - * @param int $value The parent invoice id. |
|
539 | - */ |
|
540 | - public function set_parent_payment_id( $value ) { |
|
541 | - $this->set_parent_invoice_id( $value ); |
|
542 | - } |
|
669 | + } |
|
543 | 670 | |
544 | - /** |
|
545 | - * Alias for self::set_parent_invoice_id(). |
|
671 | + /** |
|
672 | + * Alias for self::set_next_renewal_date(). |
|
546 | 673 | * |
547 | 674 | * @since 1.0.19 |
548 | - * @param int $value The parent invoice id. |
|
675 | + * @param string $value strtotime compliant date. |
|
549 | 676 | */ |
550 | - public function set_original_payment_id( $value ) { |
|
551 | - $this->set_parent_invoice_id( $value ); |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * Set subscription's product id. |
|
556 | - * |
|
557 | - * @since 1.0.19 |
|
558 | - * @param int $value The subscription product id. |
|
559 | - */ |
|
560 | - public function set_product_id( $value ) { |
|
561 | - $this->set_prop( 'product_id', (int) $value ); |
|
562 | - } |
|
563 | - |
|
564 | - /** |
|
565 | - * Set the period of a renewal. |
|
566 | - * |
|
567 | - * @since 1.0.19 |
|
568 | - * @param string $value The renewal period. |
|
569 | - */ |
|
570 | - public function set_period( $value ) { |
|
571 | - $this->set_prop( 'period', $value ); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Set number of periods each renewal is valid for. |
|
576 | - * |
|
577 | - * @since 1.0.19 |
|
578 | - * @param int $value The subscription frequency. |
|
579 | - */ |
|
580 | - public function set_frequency( $value ) { |
|
581 | - $value = empty( $value ) ? 1 : (int) $value; |
|
582 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * Set the initial amount for the subscription. |
|
587 | - * |
|
588 | - * @since 1.0.19 |
|
589 | - * @param float $value The initial subcription amount. |
|
590 | - */ |
|
591 | - public function set_initial_amount( $value ) { |
|
592 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Set the recurring amount for the subscription. |
|
597 | - * |
|
598 | - * @since 1.0.19 |
|
599 | - * @param float $value The recurring subcription amount. |
|
600 | - */ |
|
601 | - public function set_recurring_amount( $value ) { |
|
602 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Set number of times that this subscription can be renewed. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param int $value Bill times. |
|
610 | - */ |
|
611 | - public function set_bill_times( $value ) { |
|
612 | - $this->set_prop( 'bill_times', (int) $value ); |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Get transaction id of this subscription's parent invoice. |
|
617 | - * |
|
618 | - * @since 1.0.19 |
|
619 | - * @param string $value Bill times. |
|
620 | - */ |
|
621 | - public function set_transaction_id( $value ) { |
|
622 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Set date when this subscription started. |
|
627 | - * |
|
628 | - * @since 1.0.19 |
|
629 | - * @param string $value strtotime compliant date. |
|
630 | - */ |
|
631 | - public function set_created( $value ) { |
|
632 | - $date = strtotime( $value ); |
|
677 | + public function set_expiration( $value ) { |
|
678 | + $this->set_next_renewal_date( $value ); |
|
679 | + } |
|
633 | 680 | |
634 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
635 | - $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
681 | + /** |
|
682 | + * Set the subscription's trial period. |
|
683 | + * |
|
684 | + * @since 1.0.19 |
|
685 | + * @param string $value trial period e.g 1 year. |
|
686 | + */ |
|
687 | + public function set_trial_period( $value ) { |
|
688 | + $this->set_prop( 'trial_period', $value ); |
|
689 | + } |
|
690 | + |
|
691 | + /** |
|
692 | + * Set the subscription's status. |
|
693 | + * |
|
694 | + * @since 1.0.19 |
|
695 | + * @param string $new_status New subscription status. |
|
696 | + */ |
|
697 | + public function set_status( $new_status ) { |
|
698 | + |
|
699 | + // Abort if this is not a valid status; |
|
700 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
636 | 701 | return; |
637 | 702 | } |
638 | 703 | |
639 | - $this->set_prop( 'created', '' ); |
|
640 | - |
|
641 | - } |
|
704 | + $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
705 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
706 | + $this->status_transition = array( |
|
707 | + 'from' => $old_status, |
|
708 | + 'to' => $new_status, |
|
709 | + ); |
|
710 | + } |
|
642 | 711 | |
643 | - /** |
|
644 | - * Alias for self::set_created(). |
|
645 | - * |
|
646 | - * @since 1.0.19 |
|
647 | - * @param string $value strtotime compliant date. |
|
648 | - */ |
|
649 | - public function set_date_created( $value ) { |
|
650 | - $this->set_created( $value ); |
|
712 | + $this->set_prop( 'status', $new_status ); |
|
651 | 713 | } |
652 | 714 | |
653 | - /** |
|
654 | - * Set the date that the subscription will renew. |
|
655 | - * |
|
656 | - * @since 1.0.19 |
|
657 | - * @param string $value strtotime compliant date. |
|
658 | - */ |
|
659 | - public function set_next_renewal_date( $value ) { |
|
660 | - $date = strtotime( $value ); |
|
715 | + /** |
|
716 | + * Set the subscription's (remote) profile id. |
|
717 | + * |
|
718 | + * @since 1.0.19 |
|
719 | + * @param string $value the remote profile id. |
|
720 | + */ |
|
721 | + public function set_profile_id( $value ) { |
|
722 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
723 | + } |
|
661 | 724 | |
662 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
663 | - $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) ); |
|
664 | - return; |
|
665 | - } |
|
666 | - |
|
667 | - $this->set_prop( 'expiration', '' ); |
|
668 | - |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * Alias for self::set_next_renewal_date(). |
|
673 | - * |
|
674 | - * @since 1.0.19 |
|
675 | - * @param string $value strtotime compliant date. |
|
676 | - */ |
|
677 | - public function set_expiration( $value ) { |
|
678 | - $this->set_next_renewal_date( $value ); |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Set the subscription's trial period. |
|
683 | - * |
|
684 | - * @since 1.0.19 |
|
685 | - * @param string $value trial period e.g 1 year. |
|
686 | - */ |
|
687 | - public function set_trial_period( $value ) { |
|
688 | - $this->set_prop( 'trial_period', $value ); |
|
689 | - } |
|
690 | - |
|
691 | - /** |
|
692 | - * Set the subscription's status. |
|
693 | - * |
|
694 | - * @since 1.0.19 |
|
695 | - * @param string $new_status New subscription status. |
|
696 | - */ |
|
697 | - public function set_status( $new_status ) { |
|
698 | - |
|
699 | - // Abort if this is not a valid status; |
|
700 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
701 | - return; |
|
702 | - } |
|
703 | - |
|
704 | - $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
705 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
706 | - $this->status_transition = array( |
|
707 | - 'from' => $old_status, |
|
708 | - 'to' => $new_status, |
|
709 | - ); |
|
710 | - } |
|
711 | - |
|
712 | - $this->set_prop( 'status', $new_status ); |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Set the subscription's (remote) profile id. |
|
717 | - * |
|
718 | - * @since 1.0.19 |
|
719 | - * @param string $value the remote profile id. |
|
720 | - */ |
|
721 | - public function set_profile_id( $value ) { |
|
722 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
723 | - } |
|
724 | - |
|
725 | - /* |
|
725 | + /* |
|
726 | 726 | |-------------------------------------------------------------------------- |
727 | 727 | | Boolean methods |
728 | 728 | |-------------------------------------------------------------------------- |
@@ -731,55 +731,55 @@ discard block |
||
731 | 731 | | |
732 | 732 | */ |
733 | 733 | |
734 | - /** |
|
734 | + /** |
|
735 | 735 | * Checks if the subscription has a given status. |
736 | - * |
|
737 | - * @param string|array String or array of strings to check for. |
|
738 | - * @return bool |
|
736 | + * |
|
737 | + * @param string|array String or array of strings to check for. |
|
738 | + * @return bool |
|
739 | 739 | */ |
740 | 740 | public function has_status( $status ) { |
741 | 741 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
742 | - } |
|
742 | + } |
|
743 | 743 | |
744 | - /** |
|
744 | + /** |
|
745 | 745 | * Checks if the subscription has a trial period. |
746 | - * |
|
747 | - * @return bool |
|
746 | + * |
|
747 | + * @return bool |
|
748 | 748 | */ |
749 | 749 | public function has_trial_period() { |
750 | - $period = $this->get_trial_period(); |
|
750 | + $period = $this->get_trial_period(); |
|
751 | 751 | return ! empty( $period ); |
752 | - } |
|
753 | - |
|
754 | - /** |
|
755 | - * Is the subscription active? |
|
756 | - * |
|
757 | - * @return bool |
|
758 | - */ |
|
759 | - public function is_active() { |
|
760 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
761 | - } |
|
762 | - |
|
763 | - /** |
|
764 | - * Is the subscription expired? |
|
765 | - * |
|
766 | - * @return bool |
|
767 | - */ |
|
768 | - public function is_expired() { |
|
769 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
770 | - } |
|
771 | - |
|
772 | - /** |
|
773 | - * Is this the last renewals? |
|
774 | - * |
|
775 | - * @return bool |
|
776 | - */ |
|
777 | - public function is_last_renewal() { |
|
778 | - $max_bills = $this->get_bill_times(); |
|
779 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
780 | - } |
|
781 | - |
|
782 | - /* |
|
752 | + } |
|
753 | + |
|
754 | + /** |
|
755 | + * Is the subscription active? |
|
756 | + * |
|
757 | + * @return bool |
|
758 | + */ |
|
759 | + public function is_active() { |
|
760 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
761 | + } |
|
762 | + |
|
763 | + /** |
|
764 | + * Is the subscription expired? |
|
765 | + * |
|
766 | + * @return bool |
|
767 | + */ |
|
768 | + public function is_expired() { |
|
769 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * Is this the last renewals? |
|
774 | + * |
|
775 | + * @return bool |
|
776 | + */ |
|
777 | + public function is_last_renewal() { |
|
778 | + $max_bills = $this->get_bill_times(); |
|
779 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
780 | + } |
|
781 | + |
|
782 | + /* |
|
783 | 783 | |-------------------------------------------------------------------------- |
784 | 784 | | Additional methods |
785 | 785 | |-------------------------------------------------------------------------- |
@@ -788,27 +788,27 @@ discard block |
||
788 | 788 | | |
789 | 789 | */ |
790 | 790 | |
791 | - /** |
|
792 | - * Backwards compatibilty. |
|
793 | - */ |
|
794 | - public function create( $data = array() ) { |
|
791 | + /** |
|
792 | + * Backwards compatibilty. |
|
793 | + */ |
|
794 | + public function create( $data = array() ) { |
|
795 | 795 | |
796 | - // Set the properties. |
|
797 | - if ( is_array( $data ) ) { |
|
798 | - $this->set_props( $data ); |
|
799 | - } |
|
796 | + // Set the properties. |
|
797 | + if ( is_array( $data ) ) { |
|
798 | + $this->set_props( $data ); |
|
799 | + } |
|
800 | 800 | |
801 | - // Save the item. |
|
802 | - return $this->save(); |
|
801 | + // Save the item. |
|
802 | + return $this->save(); |
|
803 | 803 | |
804 | - } |
|
804 | + } |
|
805 | 805 | |
806 | - /** |
|
807 | - * Backwards compatibilty. |
|
808 | - */ |
|
809 | - public function update( $args = array() ) { |
|
810 | - return $this->create( $args ); |
|
811 | - } |
|
806 | + /** |
|
807 | + * Backwards compatibilty. |
|
808 | + */ |
|
809 | + public function update( $args = array() ) { |
|
810 | + return $this->create( $args ); |
|
811 | + } |
|
812 | 812 | |
813 | 813 | /** |
814 | 814 | * Retrieve renewal payments for a subscription |
@@ -818,22 +818,22 @@ discard block |
||
818 | 818 | */ |
819 | 819 | public function get_child_payments( $hide_pending = true ) { |
820 | 820 | |
821 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
821 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
822 | 822 | |
823 | - if ( ! $hide_pending ) { |
|
824 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
825 | - } |
|
823 | + if ( ! $hide_pending ) { |
|
824 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
825 | + } |
|
826 | 826 | |
827 | 827 | return get_posts( |
828 | - array( |
|
829 | - 'post_parent' => $this->get_parent_payment_id(), |
|
830 | - 'numberposts' => -1, |
|
831 | - 'post_status' => $statuses, |
|
832 | - 'orderby' => 'ID', |
|
833 | - 'order' => 'ASC', |
|
834 | - 'post_type' => 'wpi_invoice', |
|
835 | - ) |
|
836 | - ); |
|
828 | + array( |
|
829 | + 'post_parent' => $this->get_parent_payment_id(), |
|
830 | + 'numberposts' => -1, |
|
831 | + 'post_status' => $statuses, |
|
832 | + 'orderby' => 'ID', |
|
833 | + 'order' => 'ASC', |
|
834 | + 'post_type' => 'wpi_invoice', |
|
835 | + ) |
|
836 | + ); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | * @return int |
844 | 844 | */ |
845 | 845 | public function get_total_payments() { |
846 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
846 | + return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
847 | 847 | } |
848 | 848 | |
849 | 849 | /** |
@@ -867,192 +867,192 @@ discard block |
||
867 | 867 | * |
868 | 868 | * @since 2.4 |
869 | 869 | * @param array $args Array of values for the payment, including amount and transaction ID |
870 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
870 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
871 | 871 | * @return bool |
872 | 872 | */ |
873 | 873 | public function add_payment( $args = array(), $invoice = false ) { |
874 | 874 | |
875 | - // Process each payment once. |
|
875 | + // Process each payment once. |
|
876 | 876 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
877 | 877 | return false; |
878 | 878 | } |
879 | 879 | |
880 | - // Are we creating a new invoice? |
|
881 | - if ( empty( $invoice ) ) { |
|
882 | - $invoice = $this->create_payment( false ); |
|
880 | + // Are we creating a new invoice? |
|
881 | + if ( empty( $invoice ) ) { |
|
882 | + $invoice = $this->create_payment( false ); |
|
883 | 883 | |
884 | - if ( empty( $invoice ) ) { |
|
885 | - return false; |
|
886 | - } |
|
887 | - } |
|
884 | + if ( empty( $invoice ) ) { |
|
885 | + return false; |
|
886 | + } |
|
887 | + } |
|
888 | 888 | |
889 | - // Maybe set a transaction id. |
|
890 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
891 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
892 | - } |
|
889 | + // Maybe set a transaction id. |
|
890 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
891 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
892 | + } |
|
893 | 893 | |
894 | - // Set the completed date. |
|
895 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
894 | + // Set the completed date. |
|
895 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
896 | 896 | |
897 | - // And the gateway. |
|
898 | - if ( ! empty( $args['gateway'] ) ) { |
|
899 | - $invoice->set_gateway( $args['gateway'] ); |
|
900 | - } |
|
897 | + // And the gateway. |
|
898 | + if ( ! empty( $args['gateway'] ) ) { |
|
899 | + $invoice->set_gateway( $args['gateway'] ); |
|
900 | + } |
|
901 | 901 | |
902 | - $invoice->set_status( 'wpi-renewal' ); |
|
903 | - $invoice->save(); |
|
902 | + $invoice->set_status( 'wpi-renewal' ); |
|
903 | + $invoice->save(); |
|
904 | 904 | |
905 | - if ( ! $invoice->exists() ) { |
|
906 | - return false; |
|
907 | - } |
|
905 | + if ( ! $invoice->exists() ) { |
|
906 | + return false; |
|
907 | + } |
|
908 | 908 | |
909 | - return $this->after_add_payment( $invoice ); |
|
910 | - } |
|
909 | + return $this->after_add_payment( $invoice ); |
|
910 | + } |
|
911 | 911 | |
912 | 912 | public function after_add_payment( $invoice ) { |
913 | 913 | |
914 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
915 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
914 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
915 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
916 | 916 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
917 | 917 | |
918 | 918 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
919 | 919 | |
920 | 920 | return $invoice->get_id(); |
921 | - } |
|
921 | + } |
|
922 | 922 | |
923 | - /** |
|
923 | + /** |
|
924 | 924 | * Creates a new invoice and returns it. |
925 | 925 | * |
926 | 926 | * @since 1.0.19 |
927 | - * @param bool $save Whether we should save the invoice. |
|
927 | + * @param bool $save Whether we should save the invoice. |
|
928 | 928 | * @return WPInv_Invoice|bool |
929 | 929 | */ |
930 | 930 | public function create_payment( $save = true ) { |
931 | 931 | |
932 | - $parent_invoice = $this->get_parent_payment(); |
|
933 | - |
|
934 | - if ( ! $parent_invoice->exists() ) { |
|
935 | - return false; |
|
936 | - } |
|
937 | - |
|
938 | - // Duplicate the parent invoice. |
|
939 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
940 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
941 | - $invoice->set_subscription_id( $this->get_id() ); |
|
942 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
943 | - |
|
944 | - // Set invoice items. |
|
945 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
946 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
947 | - $invoice_items = array(); |
|
948 | - |
|
949 | - foreach ( $invoice->get_items() as $item ) { |
|
950 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
951 | - $invoice_items[] = $item; |
|
952 | - } |
|
953 | - } |
|
954 | - |
|
955 | - $invoice->set_items( $invoice_items ); |
|
956 | - |
|
957 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
958 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
959 | - } |
|
960 | - |
|
961 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
962 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
963 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
964 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
965 | - } |
|
966 | - |
|
967 | - $invoice->recalculate_total(); |
|
968 | - $invoice->set_status( 'wpi-pending' ); |
|
969 | - |
|
970 | - if ( ! $save ) { |
|
971 | - return $invoice; |
|
972 | - } |
|
973 | - |
|
974 | - $invoice->save(); |
|
975 | - |
|
976 | - return $invoice->exists() ? $invoice : false; |
|
977 | - } |
|
978 | - |
|
979 | - /** |
|
980 | - * Renews or completes a subscription |
|
981 | - * |
|
982 | - * @since 1.0.0 |
|
983 | - * @return int The subscription's id |
|
984 | - */ |
|
985 | - public function renew( $calculate_from = null ) { |
|
986 | - |
|
987 | - // Complete subscription if applicable |
|
988 | - if ( $this->is_last_renewal() ) { |
|
989 | - return $this->complete(); |
|
990 | - } |
|
991 | - |
|
992 | - // Calculate new expiration |
|
993 | - $frequency = $this->get_frequency(); |
|
994 | - $period = $this->get_period(); |
|
995 | - $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
996 | - $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
997 | - |
|
998 | - $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
999 | - $this->set_status( 'active' ); |
|
1000 | - $this->save(); |
|
1001 | - |
|
1002 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
1003 | - |
|
1004 | - return $this->get_id(); |
|
1005 | - } |
|
1006 | - |
|
1007 | - /** |
|
1008 | - * Marks a subscription as completed |
|
1009 | - * |
|
1010 | - * Subscription is completed when the number of payments matches the billing_times field |
|
1011 | - * |
|
1012 | - * @since 1.0.0 |
|
1013 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
1014 | - */ |
|
1015 | - public function complete() { |
|
1016 | - |
|
1017 | - // Only mark a subscription as complete if it's not already cancelled. |
|
1018 | - if ( $this->has_status( 'cancelled' ) ) { |
|
1019 | - return false; |
|
1020 | - } |
|
1021 | - |
|
1022 | - $this->set_status( 'completed' ); |
|
1023 | - return $this->save(); |
|
1024 | - |
|
1025 | - } |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * Marks a subscription as expired |
|
1029 | - * |
|
1030 | - * @since 1.0.0 |
|
1031 | - * @param bool $check_expiration |
|
1032 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1033 | - */ |
|
1034 | - public function expire( $check_expiration = false ) { |
|
1035 | - |
|
1036 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1037 | - // Do not mark as expired since real expiration date is in the future |
|
1038 | - return false; |
|
1039 | - } |
|
1040 | - |
|
1041 | - $this->set_status( 'expired' ); |
|
1042 | - return $this->save(); |
|
1043 | - |
|
1044 | - } |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * Marks a subscription as failing |
|
1048 | - * |
|
1049 | - * @since 2.4.2 |
|
1050 | - * @return int Subscription id. |
|
1051 | - */ |
|
1052 | - public function failing() { |
|
1053 | - $this->set_status( 'failing' ); |
|
1054 | - return $this->save(); |
|
1055 | - } |
|
932 | + $parent_invoice = $this->get_parent_payment(); |
|
933 | + |
|
934 | + if ( ! $parent_invoice->exists() ) { |
|
935 | + return false; |
|
936 | + } |
|
937 | + |
|
938 | + // Duplicate the parent invoice. |
|
939 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
940 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
941 | + $invoice->set_subscription_id( $this->get_id() ); |
|
942 | + $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
943 | + |
|
944 | + // Set invoice items. |
|
945 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
946 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
947 | + $invoice_items = array(); |
|
948 | + |
|
949 | + foreach ( $invoice->get_items() as $item ) { |
|
950 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
951 | + $invoice_items[] = $item; |
|
952 | + } |
|
953 | + } |
|
954 | + |
|
955 | + $invoice->set_items( $invoice_items ); |
|
956 | + |
|
957 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
958 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
959 | + } |
|
960 | + |
|
961 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
962 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
963 | + if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
964 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
965 | + } |
|
966 | + |
|
967 | + $invoice->recalculate_total(); |
|
968 | + $invoice->set_status( 'wpi-pending' ); |
|
969 | + |
|
970 | + if ( ! $save ) { |
|
971 | + return $invoice; |
|
972 | + } |
|
973 | + |
|
974 | + $invoice->save(); |
|
975 | + |
|
976 | + return $invoice->exists() ? $invoice : false; |
|
977 | + } |
|
978 | + |
|
979 | + /** |
|
980 | + * Renews or completes a subscription |
|
981 | + * |
|
982 | + * @since 1.0.0 |
|
983 | + * @return int The subscription's id |
|
984 | + */ |
|
985 | + public function renew( $calculate_from = null ) { |
|
986 | + |
|
987 | + // Complete subscription if applicable |
|
988 | + if ( $this->is_last_renewal() ) { |
|
989 | + return $this->complete(); |
|
990 | + } |
|
991 | + |
|
992 | + // Calculate new expiration |
|
993 | + $frequency = $this->get_frequency(); |
|
994 | + $period = $this->get_period(); |
|
995 | + $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from; |
|
996 | + $new_expiration = strtotime( "+ $frequency $period", $calculate_from ); |
|
997 | + |
|
998 | + $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
999 | + $this->set_status( 'active' ); |
|
1000 | + $this->save(); |
|
1001 | + |
|
1002 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
1003 | + |
|
1004 | + return $this->get_id(); |
|
1005 | + } |
|
1006 | + |
|
1007 | + /** |
|
1008 | + * Marks a subscription as completed |
|
1009 | + * |
|
1010 | + * Subscription is completed when the number of payments matches the billing_times field |
|
1011 | + * |
|
1012 | + * @since 1.0.0 |
|
1013 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
1014 | + */ |
|
1015 | + public function complete() { |
|
1016 | + |
|
1017 | + // Only mark a subscription as complete if it's not already cancelled. |
|
1018 | + if ( $this->has_status( 'cancelled' ) ) { |
|
1019 | + return false; |
|
1020 | + } |
|
1021 | + |
|
1022 | + $this->set_status( 'completed' ); |
|
1023 | + return $this->save(); |
|
1024 | + |
|
1025 | + } |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * Marks a subscription as expired |
|
1029 | + * |
|
1030 | + * @since 1.0.0 |
|
1031 | + * @param bool $check_expiration |
|
1032 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1033 | + */ |
|
1034 | + public function expire( $check_expiration = false ) { |
|
1035 | + |
|
1036 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1037 | + // Do not mark as expired since real expiration date is in the future |
|
1038 | + return false; |
|
1039 | + } |
|
1040 | + |
|
1041 | + $this->set_status( 'expired' ); |
|
1042 | + return $this->save(); |
|
1043 | + |
|
1044 | + } |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * Marks a subscription as failing |
|
1048 | + * |
|
1049 | + * @since 2.4.2 |
|
1050 | + * @return int Subscription id. |
|
1051 | + */ |
|
1052 | + public function failing() { |
|
1053 | + $this->set_status( 'failing' ); |
|
1054 | + return $this->save(); |
|
1055 | + } |
|
1056 | 1056 | |
1057 | 1057 | /** |
1058 | 1058 | * Marks a subscription as cancelled |
@@ -1061,19 +1061,19 @@ discard block |
||
1061 | 1061 | * @return int Subscription id. |
1062 | 1062 | */ |
1063 | 1063 | public function cancel() { |
1064 | - $this->set_status( 'cancelled' ); |
|
1065 | - return $this->save(); |
|
1064 | + $this->set_status( 'cancelled' ); |
|
1065 | + return $this->save(); |
|
1066 | 1066 | } |
1067 | 1067 | |
1068 | - /** |
|
1069 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1070 | - * |
|
1071 | - * @since 1.0.0 |
|
1072 | - * @return bool |
|
1073 | - */ |
|
1074 | - public function can_cancel() { |
|
1075 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1076 | - } |
|
1068 | + /** |
|
1069 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1070 | + * |
|
1071 | + * @since 1.0.0 |
|
1072 | + * @return bool |
|
1073 | + */ |
|
1074 | + public function can_cancel() { |
|
1075 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1076 | + } |
|
1077 | 1077 | |
1078 | 1078 | /** |
1079 | 1079 | * Returns an array of subscription statuses that can be cancelled |
@@ -1086,109 +1086,109 @@ discard block |
||
1086 | 1086 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - /** |
|
1090 | - * Retrieves the URL to cancel subscription |
|
1091 | - * |
|
1092 | - * @since 1.0.0 |
|
1093 | - * @return string |
|
1094 | - */ |
|
1095 | - public function get_cancel_url() { |
|
1096 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1097 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1098 | - } |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Retrieves the URL to view a subscription |
|
1102 | - * |
|
1103 | - * @since 1.0.19 |
|
1104 | - * @return string |
|
1105 | - */ |
|
1106 | - public function get_view_url() { |
|
1107 | - |
|
1108 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1109 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1110 | - |
|
1111 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1112 | - } |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * Determines if subscription can be manually renewed |
|
1116 | - * |
|
1117 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
1118 | - * that can be renewed manually |
|
1119 | - * |
|
1120 | - * @since 2.5 |
|
1121 | - * @return bool |
|
1122 | - */ |
|
1123 | - public function can_renew() { |
|
1124 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1125 | - } |
|
1126 | - |
|
1127 | - /** |
|
1128 | - * Retrieves the URL to renew a subscription |
|
1129 | - * |
|
1130 | - * @since 2.5 |
|
1131 | - * @return string |
|
1132 | - */ |
|
1133 | - public function get_renew_url() { |
|
1134 | - $url = wp_nonce_url( |
|
1089 | + /** |
|
1090 | + * Retrieves the URL to cancel subscription |
|
1091 | + * |
|
1092 | + * @since 1.0.0 |
|
1093 | + * @return string |
|
1094 | + */ |
|
1095 | + public function get_cancel_url() { |
|
1096 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1097 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1098 | + } |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Retrieves the URL to view a subscription |
|
1102 | + * |
|
1103 | + * @since 1.0.19 |
|
1104 | + * @return string |
|
1105 | + */ |
|
1106 | + public function get_view_url() { |
|
1107 | + |
|
1108 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1109 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1110 | + |
|
1111 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1112 | + } |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * Determines if subscription can be manually renewed |
|
1116 | + * |
|
1117 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
1118 | + * that can be renewed manually |
|
1119 | + * |
|
1120 | + * @since 2.5 |
|
1121 | + * @return bool |
|
1122 | + */ |
|
1123 | + public function can_renew() { |
|
1124 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1125 | + } |
|
1126 | + |
|
1127 | + /** |
|
1128 | + * Retrieves the URL to renew a subscription |
|
1129 | + * |
|
1130 | + * @since 2.5 |
|
1131 | + * @return string |
|
1132 | + */ |
|
1133 | + public function get_renew_url() { |
|
1134 | + $url = wp_nonce_url( |
|
1135 | 1135 | add_query_arg( |
1136 | 1136 | array( |
1137 | - 'getpaid-action' => 'renew_subscription', |
|
1138 | - 'sub_id' => $this->get_id, |
|
1137 | + 'getpaid-action' => 'renew_subscription', |
|
1138 | + 'sub_id' => $this->get_id, |
|
1139 | 1139 | ) |
1140 | 1140 | ), |
1141 | 1141 | 'getpaid-nonce' |
1142 | 1142 | ); |
1143 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1144 | - } |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * Determines if subscription can have their payment method updated |
|
1148 | - * |
|
1149 | - * @since 1.0.0 |
|
1150 | - * @return bool |
|
1151 | - */ |
|
1152 | - public function can_update() { |
|
1153 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1154 | - } |
|
1155 | - |
|
1156 | - /** |
|
1157 | - * Retrieves the URL to update subscription |
|
1158 | - * |
|
1159 | - * @since 1.0.0 |
|
1160 | - * @return string |
|
1161 | - */ |
|
1162 | - public function get_update_url() { |
|
1163 | - $url = add_query_arg( |
|
1143 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1144 | + } |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * Determines if subscription can have their payment method updated |
|
1148 | + * |
|
1149 | + * @since 1.0.0 |
|
1150 | + * @return bool |
|
1151 | + */ |
|
1152 | + public function can_update() { |
|
1153 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1154 | + } |
|
1155 | + |
|
1156 | + /** |
|
1157 | + * Retrieves the URL to update subscription |
|
1158 | + * |
|
1159 | + * @since 1.0.0 |
|
1160 | + * @return string |
|
1161 | + */ |
|
1162 | + public function get_update_url() { |
|
1163 | + $url = add_query_arg( |
|
1164 | 1164 | array( |
1165 | - 'action' => 'update', |
|
1166 | - 'subscription_id' => $this->get_id(), |
|
1165 | + 'action' => 'update', |
|
1166 | + 'subscription_id' => $this->get_id(), |
|
1167 | 1167 | ) |
1168 | 1168 | ); |
1169 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1170 | - } |
|
1171 | - |
|
1172 | - /** |
|
1173 | - * Retrieves the subscription status label |
|
1174 | - * |
|
1175 | - * @since 1.0.0 |
|
1176 | - * @return string |
|
1177 | - */ |
|
1178 | - public function get_status_label() { |
|
1179 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1180 | - } |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * Retrieves the subscription status class |
|
1184 | - * |
|
1185 | - * @since 1.0.19 |
|
1186 | - * @return string |
|
1187 | - */ |
|
1188 | - public function get_status_class() { |
|
1189 | - $statuses = getpaid_get_subscription_status_classes(); |
|
1190 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
1191 | - } |
|
1169 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1170 | + } |
|
1171 | + |
|
1172 | + /** |
|
1173 | + * Retrieves the subscription status label |
|
1174 | + * |
|
1175 | + * @since 1.0.0 |
|
1176 | + * @return string |
|
1177 | + */ |
|
1178 | + public function get_status_label() { |
|
1179 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1180 | + } |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * Retrieves the subscription status class |
|
1184 | + * |
|
1185 | + * @since 1.0.19 |
|
1186 | + * @return string |
|
1187 | + */ |
|
1188 | + public function get_status_class() { |
|
1189 | + $statuses = getpaid_get_subscription_status_classes(); |
|
1190 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark'; |
|
1191 | + } |
|
1192 | 1192 | |
1193 | 1193 | /** |
1194 | 1194 | * Retrieves the subscription status label |
@@ -1198,11 +1198,11 @@ discard block |
||
1198 | 1198 | */ |
1199 | 1199 | public function get_status_label_html() { |
1200 | 1200 | |
1201 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1202 | - $class = esc_attr( $this->get_status_class() ); |
|
1203 | - $status = sanitize_html_class( $this->get_status() ); |
|
1201 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1202 | + $class = esc_attr( $this->get_status_class() ); |
|
1203 | + $status = sanitize_html_class( $this->get_status() ); |
|
1204 | 1204 | |
1205 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1205 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | 1208 | /** |
@@ -1213,75 +1213,75 @@ discard block |
||
1213 | 1213 | * @return bool |
1214 | 1214 | */ |
1215 | 1215 | public function payment_exists( $txn_id = '' ) { |
1216 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1216 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1217 | 1217 | return ! empty( $invoice_id ); |
1218 | - } |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * Handle the status transition. |
|
1222 | - */ |
|
1223 | - protected function status_transition() { |
|
1224 | - $status_transition = $this->status_transition; |
|
1225 | - |
|
1226 | - // Reset status transition variable. |
|
1227 | - $this->status_transition = false; |
|
1228 | - |
|
1229 | - if ( $status_transition ) { |
|
1230 | - try { |
|
1231 | - |
|
1232 | - // Fire a hook for the status change. |
|
1233 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1234 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1235 | - |
|
1236 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1237 | - |
|
1238 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
1239 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1240 | - |
|
1241 | - // Note the transition occurred. |
|
1242 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1243 | - |
|
1244 | - // Fire another hook. |
|
1245 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1246 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1247 | - |
|
1248 | - } else { |
|
1249 | - /* translators: %s: new invoice status */ |
|
1250 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1251 | - |
|
1252 | - // Note the transition occurred. |
|
1253 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1254 | - |
|
1255 | - } |
|
1256 | - } catch ( Exception $e ) { |
|
1257 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1258 | - } |
|
1259 | - } |
|
1260 | - |
|
1261 | - } |
|
1262 | - |
|
1263 | - /** |
|
1264 | - * Save data to the database. |
|
1265 | - * |
|
1266 | - * @since 1.0.19 |
|
1267 | - * @return int subscription ID |
|
1268 | - */ |
|
1269 | - public function save() { |
|
1270 | - parent::save(); |
|
1271 | - $this->status_transition(); |
|
1272 | - return $this->get_id(); |
|
1273 | - } |
|
1274 | - |
|
1275 | - /** |
|
1276 | - * Activates a subscription. |
|
1277 | - * |
|
1278 | - * @since 1.0.19 |
|
1279 | - * @return int subscription ID |
|
1280 | - */ |
|
1281 | - public function activate() { |
|
1282 | - $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
1283 | - $this->set_status( $status ); |
|
1284 | - return $this->save(); |
|
1285 | - } |
|
1218 | + } |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * Handle the status transition. |
|
1222 | + */ |
|
1223 | + protected function status_transition() { |
|
1224 | + $status_transition = $this->status_transition; |
|
1225 | + |
|
1226 | + // Reset status transition variable. |
|
1227 | + $this->status_transition = false; |
|
1228 | + |
|
1229 | + if ( $status_transition ) { |
|
1230 | + try { |
|
1231 | + |
|
1232 | + // Fire a hook for the status change. |
|
1233 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1234 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1235 | + |
|
1236 | + if ( ! empty( $status_transition['from'] ) ) { |
|
1237 | + |
|
1238 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
1239 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1240 | + |
|
1241 | + // Note the transition occurred. |
|
1242 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1243 | + |
|
1244 | + // Fire another hook. |
|
1245 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1246 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1247 | + |
|
1248 | + } else { |
|
1249 | + /* translators: %s: new invoice status */ |
|
1250 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1251 | + |
|
1252 | + // Note the transition occurred. |
|
1253 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1254 | + |
|
1255 | + } |
|
1256 | + } catch ( Exception $e ) { |
|
1257 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1258 | + } |
|
1259 | + } |
|
1260 | + |
|
1261 | + } |
|
1262 | + |
|
1263 | + /** |
|
1264 | + * Save data to the database. |
|
1265 | + * |
|
1266 | + * @since 1.0.19 |
|
1267 | + * @return int subscription ID |
|
1268 | + */ |
|
1269 | + public function save() { |
|
1270 | + parent::save(); |
|
1271 | + $this->status_transition(); |
|
1272 | + return $this->get_id(); |
|
1273 | + } |
|
1274 | + |
|
1275 | + /** |
|
1276 | + * Activates a subscription. |
|
1277 | + * |
|
1278 | + * @since 1.0.19 |
|
1279 | + * @return int subscription ID |
|
1280 | + */ |
|
1281 | + public function activate() { |
|
1282 | + $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active'; |
|
1283 | + $this->set_status( $status ); |
|
1284 | + return $this->save(); |
|
1285 | + } |
|
1286 | 1286 | |
1287 | 1287 | } |
@@ -5,110 +5,110 @@ discard block |
||
5 | 5 | */ |
6 | 6 | |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; // Exit if accessed directly |
|
8 | + exit; // Exit if accessed directly |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) : |
12 | 12 | |
13 | - /** |
|
14 | - * GetPaid_Admin_Profile Class. |
|
15 | - */ |
|
16 | - class GetPaid_Admin_Profile { |
|
17 | - |
|
18 | - /** |
|
19 | - * Hook in tabs. |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
23 | - add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
24 | - |
|
25 | - add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
26 | - add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Get Address Fields for the edit user pages. |
|
31 | - * |
|
32 | - * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
33 | - */ |
|
34 | - public function get_customer_meta_fields() { |
|
35 | - |
|
36 | - $show_fields = apply_filters( |
|
37 | - 'getpaid_customer_meta_fields', |
|
38 | - array( |
|
39 | - 'billing' => array( |
|
40 | - 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
41 | - 'fields' => array( |
|
42 | - '_wpinv_first_name' => array( |
|
43 | - 'label' => __( 'First name', 'invoicing' ), |
|
44 | - 'description' => '', |
|
45 | - ), |
|
46 | - '_wpinv_last_name' => array( |
|
47 | - 'label' => __( 'Last name', 'invoicing' ), |
|
48 | - 'description' => '', |
|
49 | - ), |
|
50 | - '_wpinv_company' => array( |
|
51 | - 'label' => __( 'Company', 'invoicing' ), |
|
52 | - 'description' => '', |
|
53 | - ), |
|
54 | - '_wpinv_company_id' => array( |
|
55 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
56 | - 'description' => '', |
|
57 | - ), |
|
58 | - '_wpinv_address' => array( |
|
59 | - 'label' => __( 'Address', 'invoicing' ), |
|
60 | - 'description' => '', |
|
61 | - ), |
|
62 | - '_wpinv_city' => array( |
|
63 | - 'label' => __( 'City', 'invoicing' ), |
|
64 | - 'description' => '', |
|
65 | - ), |
|
66 | - '_wpinv_zip' => array( |
|
67 | - 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
68 | - 'description' => '', |
|
69 | - ), |
|
70 | - '_wpinv_country' => array( |
|
71 | - 'label' => __( 'Country / Region', 'invoicing' ), |
|
72 | - 'description' => '', |
|
73 | - 'class' => 'getpaid_js_field-country', |
|
74 | - 'type' => 'select', |
|
75 | - 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
76 | - ), |
|
77 | - '_wpinv_state' => array( |
|
78 | - 'label' => __( 'State / County', 'invoicing' ), |
|
79 | - 'description' => __( 'State / County or state code', 'invoicing' ), |
|
80 | - 'class' => 'getpaid_js_field-state regular-text', |
|
81 | - ), |
|
82 | - '_wpinv_phone' => array( |
|
83 | - 'label' => __( 'Phone', 'invoicing' ), |
|
84 | - 'description' => '', |
|
85 | - ), |
|
86 | - '_wpinv_vat_number' => array( |
|
87 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
88 | - 'description' => '', |
|
89 | - ), |
|
90 | - ), |
|
91 | - ), |
|
92 | - ) |
|
93 | - ); |
|
94 | - return $show_fields; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Show Address Fields on edit user pages. |
|
99 | - * |
|
100 | - * @param WP_User $user |
|
101 | - */ |
|
102 | - public function add_customer_meta_fields( $user ) { |
|
103 | - |
|
104 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - $show_fields = $this->get_customer_meta_fields(); |
|
109 | - |
|
110 | - foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
111 | - ?> |
|
13 | + /** |
|
14 | + * GetPaid_Admin_Profile Class. |
|
15 | + */ |
|
16 | + class GetPaid_Admin_Profile { |
|
17 | + |
|
18 | + /** |
|
19 | + * Hook in tabs. |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
23 | + add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
24 | + |
|
25 | + add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
26 | + add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Get Address Fields for the edit user pages. |
|
31 | + * |
|
32 | + * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
33 | + */ |
|
34 | + public function get_customer_meta_fields() { |
|
35 | + |
|
36 | + $show_fields = apply_filters( |
|
37 | + 'getpaid_customer_meta_fields', |
|
38 | + array( |
|
39 | + 'billing' => array( |
|
40 | + 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
41 | + 'fields' => array( |
|
42 | + '_wpinv_first_name' => array( |
|
43 | + 'label' => __( 'First name', 'invoicing' ), |
|
44 | + 'description' => '', |
|
45 | + ), |
|
46 | + '_wpinv_last_name' => array( |
|
47 | + 'label' => __( 'Last name', 'invoicing' ), |
|
48 | + 'description' => '', |
|
49 | + ), |
|
50 | + '_wpinv_company' => array( |
|
51 | + 'label' => __( 'Company', 'invoicing' ), |
|
52 | + 'description' => '', |
|
53 | + ), |
|
54 | + '_wpinv_company_id' => array( |
|
55 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
56 | + 'description' => '', |
|
57 | + ), |
|
58 | + '_wpinv_address' => array( |
|
59 | + 'label' => __( 'Address', 'invoicing' ), |
|
60 | + 'description' => '', |
|
61 | + ), |
|
62 | + '_wpinv_city' => array( |
|
63 | + 'label' => __( 'City', 'invoicing' ), |
|
64 | + 'description' => '', |
|
65 | + ), |
|
66 | + '_wpinv_zip' => array( |
|
67 | + 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
68 | + 'description' => '', |
|
69 | + ), |
|
70 | + '_wpinv_country' => array( |
|
71 | + 'label' => __( 'Country / Region', 'invoicing' ), |
|
72 | + 'description' => '', |
|
73 | + 'class' => 'getpaid_js_field-country', |
|
74 | + 'type' => 'select', |
|
75 | + 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
76 | + ), |
|
77 | + '_wpinv_state' => array( |
|
78 | + 'label' => __( 'State / County', 'invoicing' ), |
|
79 | + 'description' => __( 'State / County or state code', 'invoicing' ), |
|
80 | + 'class' => 'getpaid_js_field-state regular-text', |
|
81 | + ), |
|
82 | + '_wpinv_phone' => array( |
|
83 | + 'label' => __( 'Phone', 'invoicing' ), |
|
84 | + 'description' => '', |
|
85 | + ), |
|
86 | + '_wpinv_vat_number' => array( |
|
87 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
88 | + 'description' => '', |
|
89 | + ), |
|
90 | + ), |
|
91 | + ), |
|
92 | + ) |
|
93 | + ); |
|
94 | + return $show_fields; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Show Address Fields on edit user pages. |
|
99 | + * |
|
100 | + * @param WP_User $user |
|
101 | + */ |
|
102 | + public function add_customer_meta_fields( $user ) { |
|
103 | + |
|
104 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + $show_fields = $this->get_customer_meta_fields(); |
|
109 | + |
|
110 | + foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
111 | + ?> |
|
112 | 112 | <h2><?php echo esc_html( $fieldset['title'] ); ?></h2> |
113 | 113 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
114 | 114 | <?php foreach ( $fieldset['fields'] as $key => $field ) : ?> |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | <?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?> |
121 | 121 | <select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;"> |
122 | 122 | <?php |
123 | - $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
124 | - foreach ( $field['options'] as $option_key => $option_value ) : |
|
125 | - ?> |
|
123 | + $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
124 | + foreach ( $field['options'] as $option_key => $option_value ) : |
|
125 | + ?> |
|
126 | 126 | <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option> |
127 | 127 | <?php endforeach; ?> |
128 | 128 | </select> |
@@ -137,59 +137,59 @@ discard block |
||
137 | 137 | <?php endforeach; ?> |
138 | 138 | </table> |
139 | 139 | <?php |
140 | - endforeach; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Save Address Fields on edit user pages. |
|
145 | - * |
|
146 | - * @param int $user_id User ID of the user being saved |
|
147 | - */ |
|
148 | - public function save_customer_meta_fields( $user_id ) { |
|
149 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
150 | - return; |
|
151 | - } |
|
152 | - |
|
153 | - $save_fields = $this->get_customer_meta_fields(); |
|
154 | - |
|
155 | - $customer = getpaid_get_customer_by_user_id( get_current_user_id() ); |
|
156 | - |
|
157 | - if ( empty( $customer ) ) { |
|
158 | - $customer = new GetPaid_Customer( 0 ); |
|
159 | - $customer->clone_user( get_current_user_id() ); |
|
160 | - } |
|
161 | - |
|
162 | - foreach ( $save_fields as $fieldset ) { |
|
163 | - |
|
164 | - foreach ( $fieldset['fields'] as $key => $field ) { |
|
165 | - |
|
166 | - if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
167 | - $customer->set( $key, ! empty( $_POST[ $key ] ) ); |
|
168 | - } elseif ( isset( $_POST[ $key ] ) ) { |
|
169 | - $customer->set( $key, wpinv_clean( $_POST[ $key ] ) ); |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
177 | - * |
|
178 | - * @since 3.1.0 |
|
179 | - * @param int $user_id User ID of the user being edited |
|
180 | - * @param string $key Key for user meta field |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - protected function get_user_meta( $user_id, $key ) { |
|
184 | - $value = get_user_meta( $user_id, $key, true ); |
|
185 | - $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
186 | - if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
187 | - $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
188 | - } |
|
189 | - |
|
190 | - return $value; |
|
191 | - } |
|
192 | - } |
|
140 | + endforeach; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Save Address Fields on edit user pages. |
|
145 | + * |
|
146 | + * @param int $user_id User ID of the user being saved |
|
147 | + */ |
|
148 | + public function save_customer_meta_fields( $user_id ) { |
|
149 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
150 | + return; |
|
151 | + } |
|
152 | + |
|
153 | + $save_fields = $this->get_customer_meta_fields(); |
|
154 | + |
|
155 | + $customer = getpaid_get_customer_by_user_id( get_current_user_id() ); |
|
156 | + |
|
157 | + if ( empty( $customer ) ) { |
|
158 | + $customer = new GetPaid_Customer( 0 ); |
|
159 | + $customer->clone_user( get_current_user_id() ); |
|
160 | + } |
|
161 | + |
|
162 | + foreach ( $save_fields as $fieldset ) { |
|
163 | + |
|
164 | + foreach ( $fieldset['fields'] as $key => $field ) { |
|
165 | + |
|
166 | + if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
167 | + $customer->set( $key, ! empty( $_POST[ $key ] ) ); |
|
168 | + } elseif ( isset( $_POST[ $key ] ) ) { |
|
169 | + $customer->set( $key, wpinv_clean( $_POST[ $key ] ) ); |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
177 | + * |
|
178 | + * @since 3.1.0 |
|
179 | + * @param int $user_id User ID of the user being edited |
|
180 | + * @param string $key Key for user meta field |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + protected function get_user_meta( $user_id, $key ) { |
|
184 | + $value = get_user_meta( $user_id, $key, true ); |
|
185 | + $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
186 | + if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
187 | + $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
188 | + } |
|
189 | + |
|
190 | + return $value; |
|
191 | + } |
|
192 | + } |
|
193 | 193 | |
194 | 194 | endif; |
195 | 195 |
@@ -11,187 +11,187 @@ |
||
11 | 11 | */ |
12 | 12 | class GetPaid_Data_Store { |
13 | 13 | |
14 | - /** |
|
15 | - * Contains an instance of the data store class that we are working with. |
|
16 | - * |
|
17 | - * @var GetPaid_Data_Store |
|
18 | - */ |
|
19 | - private $instance = null; |
|
20 | - |
|
21 | - /** |
|
22 | - * Contains an array of default supported data stores. |
|
23 | - * Format of object name => class name. |
|
24 | - * Example: 'item' => 'GetPaid_Item_Data_Store' |
|
25 | - * You can also pass something like item-<type> for item stores and |
|
26 | - * that type will be used first when available, if a store is requested like |
|
27 | - * this and doesn't exist, then the store would fall back to 'item'. |
|
28 | - * Ran through `getpaid_data_stores`. |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - private $stores = array( |
|
33 | - 'item' => 'GetPaid_Item_Data_Store', |
|
34 | - 'payment_form' => 'GetPaid_Payment_Form_Data_Store', |
|
35 | - 'discount' => 'GetPaid_Discount_Data_Store', |
|
36 | - 'invoice' => 'GetPaid_Invoice_Data_Store', |
|
37 | - 'subscription' => 'GetPaid_Subscription_Data_Store', |
|
38 | - 'customer' => 'GetPaid_Customer_Data_Store', |
|
39 | - ); |
|
40 | - |
|
41 | - /** |
|
42 | - * Contains the name of the current data store's class name. |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - private $current_class_name = ''; |
|
47 | - |
|
48 | - /** |
|
49 | - * The object type this store works with. |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - private $object_type = ''; |
|
54 | - |
|
55 | - /** |
|
56 | - * Tells GetPaid_Data_Store which object |
|
57 | - * store we want to work with. |
|
58 | - * |
|
59 | - * @param string $object_type Name of object. |
|
60 | - */ |
|
61 | - public function __construct( $object_type ) { |
|
62 | - $this->object_type = $object_type; |
|
63 | - $this->stores = apply_filters( 'getpaid_data_stores', $this->stores ); |
|
64 | - |
|
65 | - // If this object type can't be found, check to see if we can load one |
|
66 | - // level up (so if item-type isn't found, we try item). |
|
67 | - if ( ! array_key_exists( $object_type, $this->stores ) ) { |
|
68 | - $pieces = explode( '-', $object_type ); |
|
69 | - $object_type = $pieces[0]; |
|
70 | - } |
|
71 | - |
|
72 | - if ( array_key_exists( $object_type, $this->stores ) ) { |
|
73 | - $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] ); |
|
74 | - if ( is_object( $store ) ) { |
|
75 | - $this->current_class_name = get_class( $store ); |
|
76 | - $this->instance = $store; |
|
77 | - } else { |
|
78 | - if ( ! class_exists( $store ) ) { |
|
79 | - throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) ); |
|
80 | - } |
|
81 | - $this->current_class_name = $store; |
|
82 | - $this->instance = new $store(); |
|
83 | - } |
|
84 | - } else { |
|
85 | - throw new Exception( __( 'Invalid data store.', 'invoicing' ) ); |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Only store the object type to avoid serializing the data store instance. |
|
91 | - * |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function __sleep() { |
|
95 | - return array( 'object_type' ); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Re-run the constructor with the object type. |
|
100 | - * |
|
101 | - * @throws Exception When validation fails. |
|
102 | - */ |
|
103 | - public function __wakeup() { |
|
104 | - $this->__construct( $this->object_type ); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Loads a data store. |
|
109 | - * |
|
110 | - * @param string $object_type Name of object. |
|
111 | - * |
|
112 | - * @since 1.0.19 |
|
113 | - * @throws Exception When validation fails. |
|
114 | - * @return GetPaid_Data_Store |
|
115 | - */ |
|
116 | - public static function load( $object_type ) { |
|
117 | - return new GetPaid_Data_Store( $object_type ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Returns the class name of the current data store. |
|
122 | - * |
|
123 | - * @since 1.0.19 |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public function get_current_class_name() { |
|
127 | - return $this->current_class_name; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Returns the object type of the current data store. |
|
132 | - * |
|
133 | - * @since 1.0.19 |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_object_type() { |
|
137 | - return $this->object_type; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Reads an object from the data store. |
|
142 | - * |
|
143 | - * @since 1.0.19 |
|
144 | - * @param GetPaid_Data $data GetPaid data instance. |
|
145 | - */ |
|
146 | - public function read( &$data ) { |
|
147 | - $this->instance->read( $data ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Create an object in the data store. |
|
152 | - * |
|
153 | - * @since 1.0.19 |
|
154 | - * @param GetPaid_Data $data GetPaid data instance. |
|
155 | - */ |
|
156 | - public function create( &$data ) { |
|
157 | - $this->instance->create( $data ); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Update an object in the data store. |
|
162 | - * |
|
163 | - * @since 1.0.19 |
|
164 | - * @param GetPaid_Data $data GetPaid data instance. |
|
165 | - */ |
|
166 | - public function update( &$data ) { |
|
167 | - $this->instance->update( $data ); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Delete an object from the data store. |
|
172 | - * |
|
173 | - * @since 1.0.19 |
|
174 | - * @param GetPaid_Data $data GetPaid data instance. |
|
175 | - * @param array $args Array of args to pass to the delete method. |
|
176 | - */ |
|
177 | - public function delete( &$data, $args = array() ) { |
|
178 | - $this->instance->delete( $data, $args ); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Data stores can define additional function. This passes |
|
183 | - * through to the instance if that function exists. |
|
184 | - * |
|
185 | - * @since 1.0.19 |
|
186 | - * @param string $method Method. |
|
187 | - * @return mixed |
|
188 | - */ |
|
189 | - public function __call( $method, $parameters ) { |
|
190 | - if ( is_callable( array( $this->instance, $method ) ) ) { |
|
191 | - $object = array_shift( $parameters ); |
|
192 | - $parameters = array_merge( array( &$object ), $parameters ); |
|
193 | - return call_user_func_array( array( $this->instance, $method ), $parameters ); |
|
194 | - } |
|
195 | - } |
|
14 | + /** |
|
15 | + * Contains an instance of the data store class that we are working with. |
|
16 | + * |
|
17 | + * @var GetPaid_Data_Store |
|
18 | + */ |
|
19 | + private $instance = null; |
|
20 | + |
|
21 | + /** |
|
22 | + * Contains an array of default supported data stores. |
|
23 | + * Format of object name => class name. |
|
24 | + * Example: 'item' => 'GetPaid_Item_Data_Store' |
|
25 | + * You can also pass something like item-<type> for item stores and |
|
26 | + * that type will be used first when available, if a store is requested like |
|
27 | + * this and doesn't exist, then the store would fall back to 'item'. |
|
28 | + * Ran through `getpaid_data_stores`. |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + private $stores = array( |
|
33 | + 'item' => 'GetPaid_Item_Data_Store', |
|
34 | + 'payment_form' => 'GetPaid_Payment_Form_Data_Store', |
|
35 | + 'discount' => 'GetPaid_Discount_Data_Store', |
|
36 | + 'invoice' => 'GetPaid_Invoice_Data_Store', |
|
37 | + 'subscription' => 'GetPaid_Subscription_Data_Store', |
|
38 | + 'customer' => 'GetPaid_Customer_Data_Store', |
|
39 | + ); |
|
40 | + |
|
41 | + /** |
|
42 | + * Contains the name of the current data store's class name. |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + private $current_class_name = ''; |
|
47 | + |
|
48 | + /** |
|
49 | + * The object type this store works with. |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + private $object_type = ''; |
|
54 | + |
|
55 | + /** |
|
56 | + * Tells GetPaid_Data_Store which object |
|
57 | + * store we want to work with. |
|
58 | + * |
|
59 | + * @param string $object_type Name of object. |
|
60 | + */ |
|
61 | + public function __construct( $object_type ) { |
|
62 | + $this->object_type = $object_type; |
|
63 | + $this->stores = apply_filters( 'getpaid_data_stores', $this->stores ); |
|
64 | + |
|
65 | + // If this object type can't be found, check to see if we can load one |
|
66 | + // level up (so if item-type isn't found, we try item). |
|
67 | + if ( ! array_key_exists( $object_type, $this->stores ) ) { |
|
68 | + $pieces = explode( '-', $object_type ); |
|
69 | + $object_type = $pieces[0]; |
|
70 | + } |
|
71 | + |
|
72 | + if ( array_key_exists( $object_type, $this->stores ) ) { |
|
73 | + $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] ); |
|
74 | + if ( is_object( $store ) ) { |
|
75 | + $this->current_class_name = get_class( $store ); |
|
76 | + $this->instance = $store; |
|
77 | + } else { |
|
78 | + if ( ! class_exists( $store ) ) { |
|
79 | + throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) ); |
|
80 | + } |
|
81 | + $this->current_class_name = $store; |
|
82 | + $this->instance = new $store(); |
|
83 | + } |
|
84 | + } else { |
|
85 | + throw new Exception( __( 'Invalid data store.', 'invoicing' ) ); |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Only store the object type to avoid serializing the data store instance. |
|
91 | + * |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function __sleep() { |
|
95 | + return array( 'object_type' ); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Re-run the constructor with the object type. |
|
100 | + * |
|
101 | + * @throws Exception When validation fails. |
|
102 | + */ |
|
103 | + public function __wakeup() { |
|
104 | + $this->__construct( $this->object_type ); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Loads a data store. |
|
109 | + * |
|
110 | + * @param string $object_type Name of object. |
|
111 | + * |
|
112 | + * @since 1.0.19 |
|
113 | + * @throws Exception When validation fails. |
|
114 | + * @return GetPaid_Data_Store |
|
115 | + */ |
|
116 | + public static function load( $object_type ) { |
|
117 | + return new GetPaid_Data_Store( $object_type ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Returns the class name of the current data store. |
|
122 | + * |
|
123 | + * @since 1.0.19 |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public function get_current_class_name() { |
|
127 | + return $this->current_class_name; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Returns the object type of the current data store. |
|
132 | + * |
|
133 | + * @since 1.0.19 |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_object_type() { |
|
137 | + return $this->object_type; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Reads an object from the data store. |
|
142 | + * |
|
143 | + * @since 1.0.19 |
|
144 | + * @param GetPaid_Data $data GetPaid data instance. |
|
145 | + */ |
|
146 | + public function read( &$data ) { |
|
147 | + $this->instance->read( $data ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Create an object in the data store. |
|
152 | + * |
|
153 | + * @since 1.0.19 |
|
154 | + * @param GetPaid_Data $data GetPaid data instance. |
|
155 | + */ |
|
156 | + public function create( &$data ) { |
|
157 | + $this->instance->create( $data ); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Update an object in the data store. |
|
162 | + * |
|
163 | + * @since 1.0.19 |
|
164 | + * @param GetPaid_Data $data GetPaid data instance. |
|
165 | + */ |
|
166 | + public function update( &$data ) { |
|
167 | + $this->instance->update( $data ); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Delete an object from the data store. |
|
172 | + * |
|
173 | + * @since 1.0.19 |
|
174 | + * @param GetPaid_Data $data GetPaid data instance. |
|
175 | + * @param array $args Array of args to pass to the delete method. |
|
176 | + */ |
|
177 | + public function delete( &$data, $args = array() ) { |
|
178 | + $this->instance->delete( $data, $args ); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Data stores can define additional function. This passes |
|
183 | + * through to the instance if that function exists. |
|
184 | + * |
|
185 | + * @since 1.0.19 |
|
186 | + * @param string $method Method. |
|
187 | + * @return mixed |
|
188 | + */ |
|
189 | + public function __call( $method, $parameters ) { |
|
190 | + if ( is_callable( array( $this->instance, $method ) ) ) { |
|
191 | + $object = array_shift( $parameters ); |
|
192 | + $parameters = array_merge( array( &$object ), $parameters ); |
|
193 | + return call_user_func_array( array( $this->instance, $method ), $parameters ); |
|
194 | + } |
|
195 | + } |
|
196 | 196 | |
197 | 197 | } |
@@ -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_Customer_Data_Store { |
17 | 17 | |
18 | - /* |
|
18 | + /* |
|
19 | 19 | |-------------------------------------------------------------------------- |
20 | 20 | | CRUD Methods |
21 | 21 | |-------------------------------------------------------------------------- |
22 | 22 | */ |
23 | 23 | |
24 | - /** |
|
25 | - * Method to create a new customer in the database. |
|
26 | - * |
|
27 | - * @param GetPaid_Customer $customer customer object. |
|
28 | - */ |
|
29 | - public function create( &$customer ) { |
|
30 | - global $wpdb; |
|
31 | - |
|
32 | - $values = array(); |
|
33 | - $formats = array(); |
|
34 | - |
|
35 | - $fields = self::get_database_fields(); |
|
36 | - unset( $fields['id'] ); |
|
37 | - |
|
38 | - foreach ( $fields as $key => $format ) { |
|
39 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
40 | - $formats[] = $format; |
|
41 | - } |
|
42 | - |
|
43 | - $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats ); |
|
44 | - |
|
45 | - if ( $result ) { |
|
46 | - $customer->set_id( $wpdb->insert_id ); |
|
47 | - $customer->apply_changes(); |
|
48 | - $customer->clear_cache(); |
|
49 | - do_action( 'getpaid_new_customer', $customer ); |
|
50 | - return true; |
|
51 | - } |
|
52 | - |
|
53 | - return false; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Method to read a customer from the database. |
|
58 | - * |
|
59 | - * @param GetPaid_Customer $customer customer object. |
|
60 | - * |
|
61 | - */ |
|
62 | - public function read( &$customer ) { |
|
63 | - global $wpdb; |
|
64 | - |
|
65 | - $customer->set_defaults(); |
|
66 | - |
|
67 | - if ( ! $customer->get_id() ) { |
|
68 | - $customer->last_error = 'Invalid customer.'; |
|
69 | - $customer->set_id( 0 ); |
|
70 | - return false; |
|
71 | - } |
|
72 | - |
|
73 | - // Maybe retrieve from the cache. |
|
74 | - $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' ); |
|
75 | - |
|
76 | - // If not found, retrieve from the db. |
|
77 | - if ( false === $raw_customer ) { |
|
78 | - |
|
79 | - $raw_customer = $wpdb->get_row( |
|
80 | - $wpdb->prepare( |
|
81 | - "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d", |
|
82 | - $customer->get_id() |
|
83 | - ) |
|
84 | - ); |
|
85 | - |
|
86 | - // Update the cache with our data |
|
87 | - wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' ); |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - if ( ! $raw_customer ) { |
|
92 | - $raw_customer->last_error = 'Invalid customer.'; |
|
93 | - return false; |
|
94 | - } |
|
95 | - |
|
96 | - // Loop through raw customer fields. |
|
97 | - foreach ( (array) $raw_customer as $key => $value ) { |
|
98 | - $customer->set( $key, $value ); |
|
99 | - } |
|
100 | - |
|
101 | - $customer->set_object_read( true ); |
|
102 | - do_action( 'getpaid_read_customer', $customer ); |
|
103 | - |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Method to update a customer in the database. |
|
108 | - * |
|
109 | - * @param GetPaid_Customer $customer Customer object. |
|
110 | - */ |
|
111 | - public function update( &$customer ) { |
|
112 | - global $wpdb; |
|
113 | - |
|
114 | - do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() ); |
|
115 | - |
|
116 | - $changes = $customer->get_changes(); |
|
117 | - $values = array(); |
|
118 | - $format = array(); |
|
119 | - |
|
120 | - foreach ( self::get_database_fields() as $key => $format ) { |
|
121 | - if ( array_key_exists( $key, $changes ) ) { |
|
122 | - $values[ $key ] = $customer->get( $key, 'edit' ); |
|
123 | - $formats[] = $format; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - if ( empty( $values ) ) { |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - $wpdb->update( |
|
132 | - $wpdb->prefix . 'getpaid_customers', |
|
133 | - $values, |
|
134 | - array( |
|
135 | - 'id' => $customer->get_id(), |
|
136 | - ), |
|
137 | - $formats, |
|
138 | - '%d' |
|
139 | - ); |
|
140 | - |
|
141 | - // Apply the changes. |
|
142 | - $customer->apply_changes(); |
|
143 | - |
|
144 | - // Delete cache. |
|
145 | - $customer->clear_cache(); |
|
146 | - |
|
147 | - // Fire a hook. |
|
148 | - do_action( 'getpaid_update_customer', $customer ); |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Method to delete a customer from the database. |
|
154 | - * |
|
155 | - * @param GetPaid_Customer $customer |
|
156 | - */ |
|
157 | - public function delete( &$customer ) { |
|
158 | - global $wpdb; |
|
159 | - |
|
160 | - do_action( 'getpaid_before_delete_customer', $customer ); |
|
161 | - |
|
162 | - $wpdb->delete( |
|
163 | - $wpdb->prefix . 'getpaid_customers', |
|
164 | - array( |
|
165 | - 'id' => $customer->get_id(), |
|
166 | - ), |
|
167 | - '%d' |
|
168 | - ); |
|
169 | - |
|
170 | - // Delete cache. |
|
171 | - $customer->clear_cache(); |
|
172 | - |
|
173 | - // Fire a hook. |
|
174 | - do_action( 'getpaid_delete_customer', $customer ); |
|
175 | - |
|
176 | - $customer->set_id( 0 ); |
|
177 | - } |
|
178 | - |
|
179 | - /* |
|
24 | + /** |
|
25 | + * Method to create a new customer in the database. |
|
26 | + * |
|
27 | + * @param GetPaid_Customer $customer customer object. |
|
28 | + */ |
|
29 | + public function create( &$customer ) { |
|
30 | + global $wpdb; |
|
31 | + |
|
32 | + $values = array(); |
|
33 | + $formats = array(); |
|
34 | + |
|
35 | + $fields = self::get_database_fields(); |
|
36 | + unset( $fields['id'] ); |
|
37 | + |
|
38 | + foreach ( $fields as $key => $format ) { |
|
39 | + $values[ $key ] = $customer->get( $key, 'edit' ); |
|
40 | + $formats[] = $format; |
|
41 | + } |
|
42 | + |
|
43 | + $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats ); |
|
44 | + |
|
45 | + if ( $result ) { |
|
46 | + $customer->set_id( $wpdb->insert_id ); |
|
47 | + $customer->apply_changes(); |
|
48 | + $customer->clear_cache(); |
|
49 | + do_action( 'getpaid_new_customer', $customer ); |
|
50 | + return true; |
|
51 | + } |
|
52 | + |
|
53 | + return false; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Method to read a customer from the database. |
|
58 | + * |
|
59 | + * @param GetPaid_Customer $customer customer object. |
|
60 | + * |
|
61 | + */ |
|
62 | + public function read( &$customer ) { |
|
63 | + global $wpdb; |
|
64 | + |
|
65 | + $customer->set_defaults(); |
|
66 | + |
|
67 | + if ( ! $customer->get_id() ) { |
|
68 | + $customer->last_error = 'Invalid customer.'; |
|
69 | + $customer->set_id( 0 ); |
|
70 | + return false; |
|
71 | + } |
|
72 | + |
|
73 | + // Maybe retrieve from the cache. |
|
74 | + $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' ); |
|
75 | + |
|
76 | + // If not found, retrieve from the db. |
|
77 | + if ( false === $raw_customer ) { |
|
78 | + |
|
79 | + $raw_customer = $wpdb->get_row( |
|
80 | + $wpdb->prepare( |
|
81 | + "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d", |
|
82 | + $customer->get_id() |
|
83 | + ) |
|
84 | + ); |
|
85 | + |
|
86 | + // Update the cache with our data |
|
87 | + wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' ); |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + if ( ! $raw_customer ) { |
|
92 | + $raw_customer->last_error = 'Invalid customer.'; |
|
93 | + return false; |
|
94 | + } |
|
95 | + |
|
96 | + // Loop through raw customer fields. |
|
97 | + foreach ( (array) $raw_customer as $key => $value ) { |
|
98 | + $customer->set( $key, $value ); |
|
99 | + } |
|
100 | + |
|
101 | + $customer->set_object_read( true ); |
|
102 | + do_action( 'getpaid_read_customer', $customer ); |
|
103 | + |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Method to update a customer in the database. |
|
108 | + * |
|
109 | + * @param GetPaid_Customer $customer Customer object. |
|
110 | + */ |
|
111 | + public function update( &$customer ) { |
|
112 | + global $wpdb; |
|
113 | + |
|
114 | + do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() ); |
|
115 | + |
|
116 | + $changes = $customer->get_changes(); |
|
117 | + $values = array(); |
|
118 | + $format = array(); |
|
119 | + |
|
120 | + foreach ( self::get_database_fields() as $key => $format ) { |
|
121 | + if ( array_key_exists( $key, $changes ) ) { |
|
122 | + $values[ $key ] = $customer->get( $key, 'edit' ); |
|
123 | + $formats[] = $format; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + if ( empty( $values ) ) { |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + $wpdb->update( |
|
132 | + $wpdb->prefix . 'getpaid_customers', |
|
133 | + $values, |
|
134 | + array( |
|
135 | + 'id' => $customer->get_id(), |
|
136 | + ), |
|
137 | + $formats, |
|
138 | + '%d' |
|
139 | + ); |
|
140 | + |
|
141 | + // Apply the changes. |
|
142 | + $customer->apply_changes(); |
|
143 | + |
|
144 | + // Delete cache. |
|
145 | + $customer->clear_cache(); |
|
146 | + |
|
147 | + // Fire a hook. |
|
148 | + do_action( 'getpaid_update_customer', $customer ); |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Method to delete a customer from the database. |
|
154 | + * |
|
155 | + * @param GetPaid_Customer $customer |
|
156 | + */ |
|
157 | + public function delete( &$customer ) { |
|
158 | + global $wpdb; |
|
159 | + |
|
160 | + do_action( 'getpaid_before_delete_customer', $customer ); |
|
161 | + |
|
162 | + $wpdb->delete( |
|
163 | + $wpdb->prefix . 'getpaid_customers', |
|
164 | + array( |
|
165 | + 'id' => $customer->get_id(), |
|
166 | + ), |
|
167 | + '%d' |
|
168 | + ); |
|
169 | + |
|
170 | + // Delete cache. |
|
171 | + $customer->clear_cache(); |
|
172 | + |
|
173 | + // Fire a hook. |
|
174 | + do_action( 'getpaid_delete_customer', $customer ); |
|
175 | + |
|
176 | + $customer->set_id( 0 ); |
|
177 | + } |
|
178 | + |
|
179 | + /* |
|
180 | 180 | |-------------------------------------------------------------------------- |
181 | 181 | | Additional Methods |
182 | 182 | |-------------------------------------------------------------------------- |
183 | 183 | */ |
184 | - public static function get_database_fields() { |
|
185 | - |
|
186 | - $fields = array( |
|
187 | - 'id' => '%d', |
|
188 | - 'user_id' => '%d', |
|
189 | - 'email' => '%s', |
|
190 | - 'email_cc' => '%s', |
|
191 | - 'status' => '%s', |
|
192 | - 'purchase_value' => '%f', |
|
193 | - 'purchase_count' => '%d', |
|
194 | - 'date_created' => '%s', |
|
195 | - 'date_modified' => '%s', |
|
196 | - 'uuid' => '%s', |
|
197 | - ); |
|
198 | - |
|
199 | - // Add address fields. |
|
200 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
201 | - |
|
202 | - // Skip id, user_id and email. |
|
203 | - if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
204 | - $fields[ $field ] = '%s'; |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - return $fields; |
|
209 | - } |
|
184 | + public static function get_database_fields() { |
|
185 | + |
|
186 | + $fields = array( |
|
187 | + 'id' => '%d', |
|
188 | + 'user_id' => '%d', |
|
189 | + 'email' => '%s', |
|
190 | + 'email_cc' => '%s', |
|
191 | + 'status' => '%s', |
|
192 | + 'purchase_value' => '%f', |
|
193 | + 'purchase_count' => '%d', |
|
194 | + 'date_created' => '%s', |
|
195 | + 'date_modified' => '%s', |
|
196 | + 'uuid' => '%s', |
|
197 | + ); |
|
198 | + |
|
199 | + // Add address fields. |
|
200 | + foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
201 | + |
|
202 | + // Skip id, user_id and email. |
|
203 | + if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) { |
|
204 | + $fields[ $field ] = '%s'; |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + return $fields; |
|
209 | + } |
|
210 | 210 | } |
@@ -19,28 +19,28 @@ discard block |
||
19 | 19 | */ |
20 | 20 | function getpaid_get_customers( $args = array(), $return = 'results' ) { |
21 | 21 | |
22 | - // Do not retrieve all fields if we just want the count. |
|
23 | - if ( 'count' === $return ) { |
|
24 | - $args['fields'] = 'id'; |
|
25 | - $args['number'] = 1; |
|
26 | - } |
|
22 | + // Do not retrieve all fields if we just want the count. |
|
23 | + if ( 'count' === $return ) { |
|
24 | + $args['fields'] = 'id'; |
|
25 | + $args['number'] = 1; |
|
26 | + } |
|
27 | 27 | |
28 | - // Do not count all matches if we just want the results. |
|
29 | - if ( 'results' === $return ) { |
|
30 | - $args['count_total'] = false; |
|
31 | - } |
|
28 | + // Do not count all matches if we just want the results. |
|
29 | + if ( 'results' === $return ) { |
|
30 | + $args['count_total'] = false; |
|
31 | + } |
|
32 | 32 | |
33 | - $query = new GetPaid_Customers_Query( $args ); |
|
33 | + $query = new GetPaid_Customers_Query( $args ); |
|
34 | 34 | |
35 | - if ( 'results' === $return ) { |
|
36 | - return $query->get_results(); |
|
37 | - } |
|
35 | + if ( 'results' === $return ) { |
|
36 | + return $query->get_results(); |
|
37 | + } |
|
38 | 38 | |
39 | - if ( 'count' === $return ) { |
|
40 | - return $query->get_total(); |
|
41 | - } |
|
39 | + if ( 'count' === $return ) { |
|
40 | + return $query->get_total(); |
|
41 | + } |
|
42 | 42 | |
43 | - return $query; |
|
43 | + return $query; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | */ |
107 | 107 | function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
108 | 108 | |
109 | - if ( current_user_can( 'manage_options' ) ) { |
|
110 | - return 'manage_options'; |
|
111 | - }; |
|
109 | + if ( current_user_can( 'manage_options' ) ) { |
|
110 | + return 'manage_options'; |
|
111 | + }; |
|
112 | 112 | |
113 | - return $capalibilty; |
|
113 | + return $capalibilty; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | * @return bool Whether the current user has the given capability. |
134 | 134 | */ |
135 | 135 | function wpinv_current_user_can( $capability, $args = array() ) { |
136 | - $can = wpinv_current_user_can_manage_invoicing(); |
|
136 | + $can = wpinv_current_user_can_manage_invoicing(); |
|
137 | 137 | |
138 | - return apply_filters( 'getpaid_current_user_can', $can, $capability, $args ); |
|
138 | + return apply_filters( 'getpaid_current_user_can', $can, $capability, $args ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -149,10 +149,10 @@ discard block |
||
149 | 149 | // Prepare user values. |
150 | 150 | $prefix = preg_replace( '/\s+/', '', $prefix ); |
151 | 151 | $prefix = empty( $prefix ) ? $email : $prefix; |
152 | - $args = array( |
|
153 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
154 | - 'user_pass' => wp_generate_password(), |
|
155 | - 'user_email' => $email, |
|
152 | + $args = array( |
|
153 | + 'user_login' => wpinv_generate_user_name( $prefix ), |
|
154 | + 'user_pass' => wp_generate_password(), |
|
155 | + 'user_email' => $email, |
|
156 | 156 | 'role' => 'subscriber', |
157 | 157 | ); |
158 | 158 | |
@@ -169,16 +169,16 @@ discard block |
||
169 | 169 | function wpinv_generate_user_name( $prefix = '' ) { |
170 | 170 | |
171 | 171 | // If prefix is an email, retrieve the part before the email. |
172 | - $prefix = strtok( $prefix, '@' ); |
|
172 | + $prefix = strtok( $prefix, '@' ); |
|
173 | 173 | $prefix = trim( $prefix, '.' ); |
174 | 174 | |
175 | - // Sanitize the username. |
|
176 | - $prefix = sanitize_user( $prefix, true ); |
|
175 | + // Sanitize the username. |
|
176 | + $prefix = sanitize_user( $prefix, true ); |
|
177 | 177 | |
178 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
179 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
180 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
181 | - } |
|
178 | + $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
179 | + if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
180 | + $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
181 | + } |
|
182 | 182 | |
183 | 183 | $username = $prefix; |
184 | 184 | $postfix = 2; |
@@ -317,43 +317,43 @@ discard block |
||
317 | 317 | |
318 | 318 | $value = $customer->get( $key ); |
319 | 319 | |
320 | - // Display the country. |
|
321 | - if ( 'country' == $key ) { |
|
322 | - |
|
323 | - aui()->select( |
|
324 | - array( |
|
325 | - 'options' => wpinv_get_country_list(), |
|
326 | - 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
327 | - 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
328 | - 'value' => sanitize_text_field( $value ), |
|
329 | - 'placeholder' => $label, |
|
330 | - 'label' => wp_kses_post( $label ), |
|
331 | - 'label_type' => 'vertical', |
|
332 | - 'class' => 'getpaid-address-field', |
|
320 | + // Display the country. |
|
321 | + if ( 'country' == $key ) { |
|
322 | + |
|
323 | + aui()->select( |
|
324 | + array( |
|
325 | + 'options' => wpinv_get_country_list(), |
|
326 | + 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
|
327 | + 'id' => 'wpinv-' . sanitize_html_class( $key ), |
|
328 | + 'value' => sanitize_text_field( $value ), |
|
329 | + 'placeholder' => $label, |
|
330 | + 'label' => wp_kses_post( $label ), |
|
331 | + 'label_type' => 'vertical', |
|
332 | + 'class' => 'getpaid-address-field', |
|
333 | 333 | ), |
334 | 334 | true |
335 | - ); |
|
335 | + ); |
|
336 | 336 | |
337 | - } |
|
337 | + } |
|
338 | 338 | |
339 | - // Display the state. |
|
340 | - elseif ( 'state' == $key ) { |
|
339 | + // Display the state. |
|
340 | + elseif ( 'state' == $key ) { |
|
341 | 341 | |
342 | - getpaid_get_states_select_markup( |
|
342 | + getpaid_get_states_select_markup( |
|
343 | 343 | $customer->get( 'country' ), |
344 | - $value, |
|
345 | - $label, |
|
346 | - $label, |
|
347 | - '', |
|
348 | - false, |
|
349 | - '', |
|
350 | - 'getpaid_address[' . esc_attr( $key ) . ']', |
|
344 | + $value, |
|
345 | + $label, |
|
346 | + $label, |
|
347 | + '', |
|
348 | + false, |
|
349 | + '', |
|
350 | + 'getpaid_address[' . esc_attr( $key ) . ']', |
|
351 | 351 | true |
352 | - ); |
|
352 | + ); |
|
353 | 353 | |
354 | 354 | } else { |
355 | 355 | |
356 | - aui()->input( |
|
356 | + aui()->input( |
|
357 | 357 | array( |
358 | 358 | 'name' => 'getpaid_address[' . esc_attr( $key ) . ']', |
359 | 359 | 'id' => 'wpinv-' . sanitize_html_class( $key ), |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | 'class' => 'getpaid-address-field', |
366 | 366 | ), |
367 | 367 | true |
368 | - ); |
|
368 | + ); |
|
369 | 369 | |
370 | 370 | } |
371 | 371 | } |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | function getpaid_allowed_html() { |
510 | 510 | $allowed_html = wp_kses_allowed_html( 'post' ); |
511 | 511 | |
512 | - // form fields |
|
512 | + // form fields |
|
513 | 513 | $allowed_html['form'] = array( |
514 | 514 | 'action' => true, |
515 | 515 | 'accept' => true, |
@@ -521,12 +521,12 @@ discard block |
||
521 | 521 | ); |
522 | 522 | |
523 | 523 | // - input |
524 | - $allowed_html['input'] = array( |
|
525 | - 'class' => array(), |
|
526 | - 'id' => array(), |
|
527 | - 'name' => array(), |
|
528 | - 'value' => array(), |
|
529 | - 'type' => array(), |
|
524 | + $allowed_html['input'] = array( |
|
525 | + 'class' => array(), |
|
526 | + 'id' => array(), |
|
527 | + 'name' => array(), |
|
528 | + 'value' => array(), |
|
529 | + 'type' => array(), |
|
530 | 530 | 'placeholder' => array(), |
531 | 531 | 'autocomplete' => array(), |
532 | 532 | 'autofocus' => array(), |
@@ -540,33 +540,33 @@ discard block |
||
540 | 540 | 'max' => array(), |
541 | 541 | 'step' => array(), |
542 | 542 | 'size' => array(), |
543 | - ); |
|
543 | + ); |
|
544 | 544 | |
545 | 545 | // - input |
546 | - $allowed_html['textarea'] = array( |
|
547 | - 'class' => array(), |
|
548 | - 'id' => array(), |
|
549 | - 'name' => array(), |
|
550 | - 'value' => array(), |
|
551 | - ); |
|
552 | - |
|
553 | - // select |
|
554 | - $allowed_html['select'] = array( |
|
555 | - 'class' => array(), |
|
556 | - 'id' => array(), |
|
557 | - 'name' => array(), |
|
546 | + $allowed_html['textarea'] = array( |
|
547 | + 'class' => array(), |
|
548 | + 'id' => array(), |
|
549 | + 'name' => array(), |
|
550 | + 'value' => array(), |
|
551 | + ); |
|
552 | + |
|
553 | + // select |
|
554 | + $allowed_html['select'] = array( |
|
555 | + 'class' => array(), |
|
556 | + 'id' => array(), |
|
557 | + 'name' => array(), |
|
558 | 558 | 'autocomplete' => array(), |
559 | 559 | 'multiple' => array(), |
560 | - ); |
|
560 | + ); |
|
561 | 561 | |
562 | - // select options |
|
563 | - $allowed_html['option'] = array( |
|
564 | - 'selected' => array(), |
|
562 | + // select options |
|
563 | + $allowed_html['option'] = array( |
|
564 | + 'selected' => array(), |
|
565 | 565 | 'disabled' => array(), |
566 | 566 | 'value' => array(), |
567 | - ); |
|
567 | + ); |
|
568 | 568 | |
569 | - return $allowed_html; |
|
569 | + return $allowed_html; |
|
570 | 570 | |
571 | 571 | } |
572 | 572 |
@@ -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,545 +15,545 @@ 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_subscription_id', |
|
27 | - '_wpinv_taxes', |
|
28 | - '_wpinv_fees', |
|
29 | - '_wpinv_discounts', |
|
30 | - '_wpinv_submission_id', |
|
31 | - '_wpinv_payment_form', |
|
32 | - '_wpinv_is_viewed', |
|
33 | - '_wpinv_phone', |
|
34 | - '_wpinv_company_id', |
|
35 | - 'wpinv_shipping', |
|
36 | - 'wpinv_email_cc', |
|
37 | - 'wpinv_template', |
|
38 | - 'wpinv_created_via', |
|
39 | - ); |
|
40 | - |
|
41 | - /** |
|
42 | - * A map of meta keys to data props. |
|
43 | - * |
|
44 | - * @since 1.0.19 |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - protected $meta_key_to_props = array( |
|
49 | - '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
50 | - '_wpinv_subscription_id' => 'subscription_id', |
|
51 | - '_wpinv_taxes' => 'taxes', |
|
52 | - '_wpinv_fees' => 'fees', |
|
53 | - '_wpinv_discounts' => 'discounts', |
|
54 | - '_wpinv_submission_id' => 'submission_id', |
|
55 | - '_wpinv_payment_form' => 'payment_form', |
|
56 | - '_wpinv_is_viewed' => 'is_viewed', |
|
57 | - 'wpinv_email_cc' => 'email_cc', |
|
58 | - 'wpinv_template' => 'template', |
|
59 | - 'wpinv_created_via' => 'created_via', |
|
60 | - '_wpinv_phone' => 'phone', |
|
61 | - '_wpinv_company_id' => 'company_id', |
|
62 | - 'wpinv_shipping' => 'shipping', |
|
63 | - ); |
|
64 | - |
|
65 | - /** |
|
66 | - * A map of database fields to data props. |
|
67 | - * |
|
68 | - * @since 1.0.19 |
|
69 | - * |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - protected $database_fields_to_props = array( |
|
73 | - 'post_id' => 'id', |
|
74 | - 'number' => 'number', |
|
75 | - 'currency' => 'currency', |
|
76 | - 'invoice_key' => 'key', |
|
77 | - 'type' => 'type', |
|
78 | - 'mode' => 'mode', |
|
79 | - 'user_ip' => 'user_ip', |
|
80 | - 'first_name' => 'first_name', |
|
81 | - 'last_name' => 'last_name', |
|
82 | - 'address' => 'address', |
|
83 | - 'city' => 'city', |
|
84 | - 'state' => 'state', |
|
85 | - 'country' => 'country', |
|
86 | - 'zip' => 'zip', |
|
87 | - 'zip' => 'zip', |
|
88 | - 'adddress_confirmed' => 'address_confirmed', |
|
89 | - 'gateway' => 'gateway', |
|
90 | - 'transaction_id' => 'transaction_id', |
|
91 | - 'currency' => 'currency', |
|
92 | - 'subtotal' => 'subtotal', |
|
93 | - 'tax' => 'total_tax', |
|
94 | - 'fees_total' => 'total_fees', |
|
95 | - 'discount' => 'total_discount', |
|
96 | - 'total' => 'total', |
|
97 | - 'discount_code' => 'discount_code', |
|
98 | - 'disable_taxes' => 'disable_taxes', |
|
99 | - 'due_date' => 'due_date', |
|
100 | - 'completed_date' => 'completed_date', |
|
101 | - 'company' => 'company', |
|
102 | - 'vat_number' => 'vat_number', |
|
103 | - 'vat_rate' => 'vat_rate', |
|
104 | - 'customer_id' => 'customer_id', |
|
105 | - ); |
|
106 | - |
|
107 | - /* |
|
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_subscription_id', |
|
27 | + '_wpinv_taxes', |
|
28 | + '_wpinv_fees', |
|
29 | + '_wpinv_discounts', |
|
30 | + '_wpinv_submission_id', |
|
31 | + '_wpinv_payment_form', |
|
32 | + '_wpinv_is_viewed', |
|
33 | + '_wpinv_phone', |
|
34 | + '_wpinv_company_id', |
|
35 | + 'wpinv_shipping', |
|
36 | + 'wpinv_email_cc', |
|
37 | + 'wpinv_template', |
|
38 | + 'wpinv_created_via', |
|
39 | + ); |
|
40 | + |
|
41 | + /** |
|
42 | + * A map of meta keys to data props. |
|
43 | + * |
|
44 | + * @since 1.0.19 |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + protected $meta_key_to_props = array( |
|
49 | + '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
50 | + '_wpinv_subscription_id' => 'subscription_id', |
|
51 | + '_wpinv_taxes' => 'taxes', |
|
52 | + '_wpinv_fees' => 'fees', |
|
53 | + '_wpinv_discounts' => 'discounts', |
|
54 | + '_wpinv_submission_id' => 'submission_id', |
|
55 | + '_wpinv_payment_form' => 'payment_form', |
|
56 | + '_wpinv_is_viewed' => 'is_viewed', |
|
57 | + 'wpinv_email_cc' => 'email_cc', |
|
58 | + 'wpinv_template' => 'template', |
|
59 | + 'wpinv_created_via' => 'created_via', |
|
60 | + '_wpinv_phone' => 'phone', |
|
61 | + '_wpinv_company_id' => 'company_id', |
|
62 | + 'wpinv_shipping' => 'shipping', |
|
63 | + ); |
|
64 | + |
|
65 | + /** |
|
66 | + * A map of database fields to data props. |
|
67 | + * |
|
68 | + * @since 1.0.19 |
|
69 | + * |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + protected $database_fields_to_props = array( |
|
73 | + 'post_id' => 'id', |
|
74 | + 'number' => 'number', |
|
75 | + 'currency' => 'currency', |
|
76 | + 'invoice_key' => 'key', |
|
77 | + 'type' => 'type', |
|
78 | + 'mode' => 'mode', |
|
79 | + 'user_ip' => 'user_ip', |
|
80 | + 'first_name' => 'first_name', |
|
81 | + 'last_name' => 'last_name', |
|
82 | + 'address' => 'address', |
|
83 | + 'city' => 'city', |
|
84 | + 'state' => 'state', |
|
85 | + 'country' => 'country', |
|
86 | + 'zip' => 'zip', |
|
87 | + 'zip' => 'zip', |
|
88 | + 'adddress_confirmed' => 'address_confirmed', |
|
89 | + 'gateway' => 'gateway', |
|
90 | + 'transaction_id' => 'transaction_id', |
|
91 | + 'currency' => 'currency', |
|
92 | + 'subtotal' => 'subtotal', |
|
93 | + 'tax' => 'total_tax', |
|
94 | + 'fees_total' => 'total_fees', |
|
95 | + 'discount' => 'total_discount', |
|
96 | + 'total' => 'total', |
|
97 | + 'discount_code' => 'discount_code', |
|
98 | + 'disable_taxes' => 'disable_taxes', |
|
99 | + 'due_date' => 'due_date', |
|
100 | + 'completed_date' => 'completed_date', |
|
101 | + 'company' => 'company', |
|
102 | + 'vat_number' => 'vat_number', |
|
103 | + 'vat_rate' => 'vat_rate', |
|
104 | + 'customer_id' => 'customer_id', |
|
105 | + ); |
|
106 | + |
|
107 | + /* |
|
108 | 108 | |-------------------------------------------------------------------------- |
109 | 109 | | CRUD Methods |
110 | 110 | |-------------------------------------------------------------------------- |
111 | 111 | */ |
112 | 112 | |
113 | - /** |
|
114 | - * Method to create a new invoice in the database. |
|
115 | - * |
|
116 | - * @param WPInv_Invoice $invoice Invoice object. |
|
117 | - */ |
|
118 | - public function create( &$invoice ) { |
|
119 | - $invoice->set_version( WPINV_VERSION ); |
|
120 | - $invoice->set_date_created( current_time( 'mysql' ) ); |
|
121 | - |
|
122 | - // Create a new post. |
|
123 | - $id = wp_insert_post( |
|
124 | - apply_filters( |
|
125 | - 'getpaid_new_invoice_data', |
|
126 | - array( |
|
127 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
128 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
129 | - 'post_status' => $this->get_post_status( $invoice ), |
|
130 | - 'ping_status' => 'closed', |
|
131 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
132 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
133 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
134 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
135 | - ) |
|
136 | - ), |
|
137 | - true |
|
138 | - ); |
|
139 | - |
|
140 | - if ( $id && ! is_wp_error( $id ) ) { |
|
141 | - |
|
142 | - // Update the new id and regenerate a title. |
|
143 | - $invoice->set_id( $id ); |
|
144 | - |
|
145 | - $invoice->maybe_set_number(); |
|
146 | - |
|
147 | - wp_update_post( |
|
148 | - array( |
|
149 | - 'ID' => $invoice->get_id(), |
|
150 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
151 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
152 | - ) |
|
153 | - ); |
|
154 | - |
|
155 | - // Save special fields and items. |
|
156 | - $this->save_special_fields( $invoice ); |
|
157 | - $this->save_items( $invoice ); |
|
158 | - |
|
159 | - // Update meta data. |
|
160 | - $this->update_post_meta( $invoice ); |
|
161 | - $invoice->save_meta_data(); |
|
162 | - |
|
163 | - // Apply changes. |
|
164 | - $invoice->apply_changes(); |
|
165 | - $this->clear_caches( $invoice ); |
|
166 | - |
|
167 | - // Fires after a new invoice is created. |
|
168 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
169 | - return true; |
|
170 | - } |
|
171 | - |
|
172 | - if ( is_wp_error( $id ) ) { |
|
173 | - $invoice->last_error = $id->get_error_message(); |
|
174 | - } |
|
175 | - |
|
176 | - return false; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Method to read an invoice from the database. |
|
181 | - * |
|
182 | - * @param WPInv_Invoice $invoice Invoice object. |
|
183 | - * |
|
184 | - */ |
|
185 | - public function read( &$invoice ) { |
|
186 | - |
|
187 | - $invoice->set_defaults(); |
|
188 | - $invoice_object = get_post( $invoice->get_id() ); |
|
189 | - |
|
190 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
191 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
192 | - $invoice->set_id( 0 ); |
|
193 | - return false; |
|
194 | - } |
|
195 | - |
|
196 | - $invoice->set_props( |
|
197 | - array( |
|
198 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
199 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
200 | - 'status' => $invoice_object->post_status, |
|
201 | - 'author' => $invoice_object->post_author, |
|
202 | - 'description' => $invoice_object->post_excerpt, |
|
203 | - 'parent_id' => $invoice_object->post_parent, |
|
204 | - 'name' => $invoice_object->post_title, |
|
205 | - 'path' => $invoice_object->post_name, |
|
206 | - 'post_type' => $invoice_object->post_type, |
|
207 | - ) |
|
208 | - ); |
|
209 | - |
|
210 | - $invoice->set_type( $invoice_object->post_type ); |
|
211 | - |
|
212 | - $this->read_object_data( $invoice, $invoice_object ); |
|
213 | - $this->add_special_fields( $invoice ); |
|
214 | - $this->add_items( $invoice ); |
|
215 | - $invoice->read_meta_data(); |
|
216 | - $invoice->set_object_read( true ); |
|
217 | - do_action( 'getpaid_read_invoice', $invoice ); |
|
218 | - |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Method to update an invoice in the database. |
|
223 | - * |
|
224 | - * @param WPInv_Invoice $invoice Invoice object. |
|
225 | - */ |
|
226 | - public function update( &$invoice ) { |
|
227 | - $invoice->save_meta_data(); |
|
228 | - $invoice->set_version( WPINV_VERSION ); |
|
229 | - |
|
230 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
231 | - $invoice->set_date_created( current_time( 'mysql' ) ); |
|
232 | - } |
|
233 | - |
|
234 | - // Ensure both the key and number are set. |
|
235 | - $invoice->get_path(); |
|
236 | - |
|
237 | - // Grab the current status so we can compare. |
|
238 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
239 | - |
|
240 | - $changes = $invoice->get_changes(); |
|
241 | - |
|
242 | - // Only update the post when the post data changes. |
|
243 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
244 | - $post_data = array( |
|
245 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
246 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
247 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
248 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
249 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
250 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
251 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
252 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
253 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
254 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
255 | - ); |
|
256 | - |
|
257 | - /** |
|
258 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
259 | - * to update data, since wp_update_post spawns more calls to the |
|
260 | - * save_post action. |
|
261 | - * |
|
262 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
263 | - * or an update purely from CRUD. |
|
264 | - */ |
|
265 | - if ( doing_action( 'save_post' ) ) { |
|
266 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
267 | - clean_post_cache( $invoice->get_id() ); |
|
268 | - } else { |
|
269 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
270 | - } |
|
271 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
272 | - } |
|
273 | - |
|
274 | - // Update meta data. |
|
275 | - $this->update_post_meta( $invoice ); |
|
276 | - |
|
277 | - // Save special fields and items. |
|
278 | - $this->save_special_fields( $invoice ); |
|
279 | - $this->save_items( $invoice ); |
|
280 | - |
|
281 | - // Apply the changes. |
|
282 | - $invoice->apply_changes(); |
|
283 | - |
|
284 | - // Clear caches. |
|
285 | - $this->clear_caches( $invoice ); |
|
286 | - |
|
287 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
288 | - $new_status = $invoice->get_status( 'edit' ); |
|
289 | - |
|
290 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
291 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
292 | - } else { |
|
293 | - do_action( 'getpaid_update_invoice', $invoice ); |
|
294 | - } |
|
295 | - |
|
296 | - } |
|
297 | - |
|
298 | - /* |
|
113 | + /** |
|
114 | + * Method to create a new invoice in the database. |
|
115 | + * |
|
116 | + * @param WPInv_Invoice $invoice Invoice object. |
|
117 | + */ |
|
118 | + public function create( &$invoice ) { |
|
119 | + $invoice->set_version( WPINV_VERSION ); |
|
120 | + $invoice->set_date_created( current_time( 'mysql' ) ); |
|
121 | + |
|
122 | + // Create a new post. |
|
123 | + $id = wp_insert_post( |
|
124 | + apply_filters( |
|
125 | + 'getpaid_new_invoice_data', |
|
126 | + array( |
|
127 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
128 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
129 | + 'post_status' => $this->get_post_status( $invoice ), |
|
130 | + 'ping_status' => 'closed', |
|
131 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
132 | + 'post_title' => $invoice->get_title( 'edit' ), |
|
133 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
134 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
135 | + ) |
|
136 | + ), |
|
137 | + true |
|
138 | + ); |
|
139 | + |
|
140 | + if ( $id && ! is_wp_error( $id ) ) { |
|
141 | + |
|
142 | + // Update the new id and regenerate a title. |
|
143 | + $invoice->set_id( $id ); |
|
144 | + |
|
145 | + $invoice->maybe_set_number(); |
|
146 | + |
|
147 | + wp_update_post( |
|
148 | + array( |
|
149 | + 'ID' => $invoice->get_id(), |
|
150 | + 'post_title' => $invoice->get_number( 'edit' ), |
|
151 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
152 | + ) |
|
153 | + ); |
|
154 | + |
|
155 | + // Save special fields and items. |
|
156 | + $this->save_special_fields( $invoice ); |
|
157 | + $this->save_items( $invoice ); |
|
158 | + |
|
159 | + // Update meta data. |
|
160 | + $this->update_post_meta( $invoice ); |
|
161 | + $invoice->save_meta_data(); |
|
162 | + |
|
163 | + // Apply changes. |
|
164 | + $invoice->apply_changes(); |
|
165 | + $this->clear_caches( $invoice ); |
|
166 | + |
|
167 | + // Fires after a new invoice is created. |
|
168 | + do_action( 'getpaid_new_invoice', $invoice ); |
|
169 | + return true; |
|
170 | + } |
|
171 | + |
|
172 | + if ( is_wp_error( $id ) ) { |
|
173 | + $invoice->last_error = $id->get_error_message(); |
|
174 | + } |
|
175 | + |
|
176 | + return false; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Method to read an invoice from the database. |
|
181 | + * |
|
182 | + * @param WPInv_Invoice $invoice Invoice object. |
|
183 | + * |
|
184 | + */ |
|
185 | + public function read( &$invoice ) { |
|
186 | + |
|
187 | + $invoice->set_defaults(); |
|
188 | + $invoice_object = get_post( $invoice->get_id() ); |
|
189 | + |
|
190 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
191 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
192 | + $invoice->set_id( 0 ); |
|
193 | + return false; |
|
194 | + } |
|
195 | + |
|
196 | + $invoice->set_props( |
|
197 | + array( |
|
198 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
199 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
200 | + 'status' => $invoice_object->post_status, |
|
201 | + 'author' => $invoice_object->post_author, |
|
202 | + 'description' => $invoice_object->post_excerpt, |
|
203 | + 'parent_id' => $invoice_object->post_parent, |
|
204 | + 'name' => $invoice_object->post_title, |
|
205 | + 'path' => $invoice_object->post_name, |
|
206 | + 'post_type' => $invoice_object->post_type, |
|
207 | + ) |
|
208 | + ); |
|
209 | + |
|
210 | + $invoice->set_type( $invoice_object->post_type ); |
|
211 | + |
|
212 | + $this->read_object_data( $invoice, $invoice_object ); |
|
213 | + $this->add_special_fields( $invoice ); |
|
214 | + $this->add_items( $invoice ); |
|
215 | + $invoice->read_meta_data(); |
|
216 | + $invoice->set_object_read( true ); |
|
217 | + do_action( 'getpaid_read_invoice', $invoice ); |
|
218 | + |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Method to update an invoice in the database. |
|
223 | + * |
|
224 | + * @param WPInv_Invoice $invoice Invoice object. |
|
225 | + */ |
|
226 | + public function update( &$invoice ) { |
|
227 | + $invoice->save_meta_data(); |
|
228 | + $invoice->set_version( WPINV_VERSION ); |
|
229 | + |
|
230 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
231 | + $invoice->set_date_created( current_time( 'mysql' ) ); |
|
232 | + } |
|
233 | + |
|
234 | + // Ensure both the key and number are set. |
|
235 | + $invoice->get_path(); |
|
236 | + |
|
237 | + // Grab the current status so we can compare. |
|
238 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
239 | + |
|
240 | + $changes = $invoice->get_changes(); |
|
241 | + |
|
242 | + // Only update the post when the post data changes. |
|
243 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
244 | + $post_data = array( |
|
245 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
246 | + 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
247 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
248 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
249 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
250 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
251 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
252 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
253 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
254 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
255 | + ); |
|
256 | + |
|
257 | + /** |
|
258 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
259 | + * to update data, since wp_update_post spawns more calls to the |
|
260 | + * save_post action. |
|
261 | + * |
|
262 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
263 | + * or an update purely from CRUD. |
|
264 | + */ |
|
265 | + if ( doing_action( 'save_post' ) ) { |
|
266 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
267 | + clean_post_cache( $invoice->get_id() ); |
|
268 | + } else { |
|
269 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
270 | + } |
|
271 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
272 | + } |
|
273 | + |
|
274 | + // Update meta data. |
|
275 | + $this->update_post_meta( $invoice ); |
|
276 | + |
|
277 | + // Save special fields and items. |
|
278 | + $this->save_special_fields( $invoice ); |
|
279 | + $this->save_items( $invoice ); |
|
280 | + |
|
281 | + // Apply the changes. |
|
282 | + $invoice->apply_changes(); |
|
283 | + |
|
284 | + // Clear caches. |
|
285 | + $this->clear_caches( $invoice ); |
|
286 | + |
|
287 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
288 | + $new_status = $invoice->get_status( 'edit' ); |
|
289 | + |
|
290 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
291 | + do_action( 'getpaid_new_invoice', $invoice ); |
|
292 | + } else { |
|
293 | + do_action( 'getpaid_update_invoice', $invoice ); |
|
294 | + } |
|
295 | + |
|
296 | + } |
|
297 | + |
|
298 | + /* |
|
299 | 299 | |-------------------------------------------------------------------------- |
300 | 300 | | Additional Methods |
301 | 301 | |-------------------------------------------------------------------------- |
302 | 302 | */ |
303 | 303 | |
304 | - /** |
|
304 | + /** |
|
305 | 305 | * Retrieves special fields and adds to the invoice. |
306 | - * |
|
307 | - * @param WPInv_Invoice $invoice Invoice object. |
|
306 | + * |
|
307 | + * @param WPInv_Invoice $invoice Invoice object. |
|
308 | 308 | */ |
309 | 309 | public function add_special_fields( &$invoice ) { |
310 | - global $wpdb; |
|
311 | - |
|
312 | - // Maybe retrieve from the cache. |
|
313 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
314 | - |
|
315 | - // If not found, retrieve from the db. |
|
316 | - if ( false === $data ) { |
|
317 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
318 | - |
|
319 | - $data = $wpdb->get_row( |
|
320 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
321 | - ARRAY_A |
|
322 | - ); |
|
323 | - |
|
324 | - // Update the cache with our data |
|
325 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
326 | - |
|
327 | - } |
|
328 | - |
|
329 | - // Abort if the data does not exist. |
|
330 | - if ( empty( $data ) ) { |
|
331 | - $invoice->set_object_read( true ); |
|
332 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
333 | - return; |
|
334 | - } |
|
335 | - |
|
336 | - $props = array(); |
|
337 | - |
|
338 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
339 | - |
|
340 | - if ( $db_field == 'post_id' ) { |
|
341 | - continue; |
|
342 | - } |
|
343 | - |
|
344 | - $props[ $prop ] = $data[ $db_field ]; |
|
345 | - } |
|
346 | - |
|
347 | - $invoice->set_props( $props ); |
|
348 | - |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Gets a list of special fields that need updated based on change state |
|
353 | - * or if they are present in the database or not. |
|
354 | - * |
|
355 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
356 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
357 | - */ |
|
358 | - protected function get_special_fields_to_update( $invoice ) { |
|
359 | - $fields_to_update = array(); |
|
360 | - $changed_props = $invoice->get_changes(); |
|
361 | - |
|
362 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
363 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
364 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
365 | - $fields_to_update[ $database_field ] = $prop; |
|
366 | - } |
|
367 | - } |
|
368 | - |
|
369 | - return $fields_to_update; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
374 | - * |
|
375 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
376 | - * @since 1.0.19 |
|
377 | - */ |
|
378 | - protected function update_special_fields( &$invoice ) { |
|
379 | - global $wpdb; |
|
380 | - |
|
381 | - $updated_props = array(); |
|
382 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
383 | - |
|
384 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
385 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
386 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
387 | - $value = is_bool( $value ) ? (int) $value : $value; |
|
388 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
389 | - } |
|
390 | - |
|
391 | - if ( ! empty( $updated_props ) ) { |
|
392 | - |
|
393 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
394 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
395 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
396 | - do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props ); |
|
397 | - |
|
398 | - } |
|
399 | - |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Helper method that inserts special fields to the database. |
|
404 | - * |
|
405 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
406 | - * @since 1.0.19 |
|
407 | - */ |
|
408 | - protected function insert_special_fields( &$invoice ) { |
|
409 | - global $wpdb; |
|
410 | - |
|
411 | - $updated_props = array(); |
|
412 | - |
|
413 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
414 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
415 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
416 | - $value = is_bool( $value ) ? (int) $value : $value; |
|
417 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
418 | - } |
|
419 | - |
|
420 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
421 | - $wpdb->insert( $table, $updated_props ); |
|
422 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
423 | - do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props ); |
|
424 | - |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
310 | + global $wpdb; |
|
311 | + |
|
312 | + // Maybe retrieve from the cache. |
|
313 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
314 | + |
|
315 | + // If not found, retrieve from the db. |
|
316 | + if ( false === $data ) { |
|
317 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
318 | + |
|
319 | + $data = $wpdb->get_row( |
|
320 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
321 | + ARRAY_A |
|
322 | + ); |
|
323 | + |
|
324 | + // Update the cache with our data |
|
325 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
326 | + |
|
327 | + } |
|
328 | + |
|
329 | + // Abort if the data does not exist. |
|
330 | + if ( empty( $data ) ) { |
|
331 | + $invoice->set_object_read( true ); |
|
332 | + $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
333 | + return; |
|
334 | + } |
|
335 | + |
|
336 | + $props = array(); |
|
337 | + |
|
338 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
339 | + |
|
340 | + if ( $db_field == 'post_id' ) { |
|
341 | + continue; |
|
342 | + } |
|
343 | + |
|
344 | + $props[ $prop ] = $data[ $db_field ]; |
|
345 | + } |
|
346 | + |
|
347 | + $invoice->set_props( $props ); |
|
348 | + |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Gets a list of special fields that need updated based on change state |
|
353 | + * or if they are present in the database or not. |
|
354 | + * |
|
355 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
356 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
357 | + */ |
|
358 | + protected function get_special_fields_to_update( $invoice ) { |
|
359 | + $fields_to_update = array(); |
|
360 | + $changed_props = $invoice->get_changes(); |
|
361 | + |
|
362 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
363 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
364 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
365 | + $fields_to_update[ $database_field ] = $prop; |
|
366 | + } |
|
367 | + } |
|
368 | + |
|
369 | + return $fields_to_update; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
374 | + * |
|
375 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
376 | + * @since 1.0.19 |
|
377 | + */ |
|
378 | + protected function update_special_fields( &$invoice ) { |
|
379 | + global $wpdb; |
|
380 | + |
|
381 | + $updated_props = array(); |
|
382 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
383 | + |
|
384 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
385 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
386 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
387 | + $value = is_bool( $value ) ? (int) $value : $value; |
|
388 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
389 | + } |
|
390 | + |
|
391 | + if ( ! empty( $updated_props ) ) { |
|
392 | + |
|
393 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
394 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
395 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
396 | + do_action( 'getpaid_invoice_update_database_fields', $invoice, $updated_props ); |
|
397 | + |
|
398 | + } |
|
399 | + |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Helper method that inserts special fields to the database. |
|
404 | + * |
|
405 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
406 | + * @since 1.0.19 |
|
407 | + */ |
|
408 | + protected function insert_special_fields( &$invoice ) { |
|
409 | + global $wpdb; |
|
410 | + |
|
411 | + $updated_props = array(); |
|
412 | + |
|
413 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
414 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
415 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
416 | + $value = is_bool( $value ) ? (int) $value : $value; |
|
417 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
418 | + } |
|
419 | + |
|
420 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
421 | + $wpdb->insert( $table, $updated_props ); |
|
422 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
423 | + do_action( 'getpaid_invoice_insert_database_fields', $invoice, $updated_props ); |
|
424 | + |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | 428 | * Saves all special fields. |
429 | - * |
|
430 | - * @param WPInv_Invoice $invoice Invoice object. |
|
429 | + * |
|
430 | + * @param WPInv_Invoice $invoice Invoice object. |
|
431 | 431 | */ |
432 | 432 | public function save_special_fields( &$invoice ) { |
433 | - global $wpdb; |
|
433 | + global $wpdb; |
|
434 | 434 | |
435 | - // The invoices table. |
|
436 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
437 | - $id = (int) $invoice->get_id(); |
|
438 | - $invoice->maybe_set_key(); |
|
435 | + // The invoices table. |
|
436 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
437 | + $id = (int) $invoice->get_id(); |
|
438 | + $invoice->maybe_set_key(); |
|
439 | 439 | |
440 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
440 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
441 | 441 | |
442 | - $this->update_special_fields( $invoice ); |
|
442 | + $this->update_special_fields( $invoice ); |
|
443 | 443 | |
444 | - } else { |
|
444 | + } else { |
|
445 | 445 | |
446 | - $this->insert_special_fields( $invoice ); |
|
446 | + $this->insert_special_fields( $invoice ); |
|
447 | 447 | |
448 | - } |
|
448 | + } |
|
449 | 449 | |
450 | - } |
|
450 | + } |
|
451 | 451 | |
452 | - /** |
|
452 | + /** |
|
453 | 453 | * Set's up cart details. |
454 | - * |
|
455 | - * @param WPInv_Invoice $invoice Invoice object. |
|
454 | + * |
|
455 | + * @param WPInv_Invoice $invoice Invoice object. |
|
456 | 456 | */ |
457 | 457 | public function add_items( &$invoice ) { |
458 | - global $wpdb; |
|
458 | + global $wpdb; |
|
459 | 459 | |
460 | - // Maybe retrieve from the cache. |
|
461 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
460 | + // Maybe retrieve from the cache. |
|
461 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
462 | 462 | |
463 | - // If not found, retrieve from the db. |
|
464 | - if ( false === $items ) { |
|
465 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
463 | + // If not found, retrieve from the db. |
|
464 | + if ( false === $items ) { |
|
465 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
466 | 466 | |
467 | - $items = $wpdb->get_results( |
|
468 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
469 | - ); |
|
467 | + $items = $wpdb->get_results( |
|
468 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
469 | + ); |
|
470 | 470 | |
471 | - // Update the cache with our data |
|
472 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
471 | + // Update the cache with our data |
|
472 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
473 | 473 | |
474 | - } |
|
474 | + } |
|
475 | 475 | |
476 | - // Abort if no items found. |
|
476 | + // Abort if no items found. |
|
477 | 477 | if ( empty( $items ) ) { |
478 | 478 | return; |
479 | - } |
|
480 | - |
|
481 | - $_items = array(); |
|
482 | - foreach ( $items as $item_data ) { |
|
483 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
484 | - |
|
485 | - // Set item data. |
|
486 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
487 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
488 | - $item->set_name( $item_data->item_name ); |
|
489 | - $item->set_description( $item_data->item_description ); |
|
490 | - $item->set_price( $item_data->item_price ); |
|
491 | - $item->set_quantity( $item_data->quantity ); |
|
492 | - $item->set_item_meta( $item_data->meta ); |
|
493 | - $_items[] = $item; |
|
494 | - } |
|
495 | - |
|
496 | - $invoice->set_items( $_items ); |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
479 | + } |
|
480 | + |
|
481 | + $_items = array(); |
|
482 | + foreach ( $items as $item_data ) { |
|
483 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
484 | + |
|
485 | + // Set item data. |
|
486 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
487 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
488 | + $item->set_name( $item_data->item_name ); |
|
489 | + $item->set_description( $item_data->item_description ); |
|
490 | + $item->set_price( $item_data->item_price ); |
|
491 | + $item->set_quantity( $item_data->quantity ); |
|
492 | + $item->set_item_meta( $item_data->meta ); |
|
493 | + $_items[] = $item; |
|
494 | + } |
|
495 | + |
|
496 | + $invoice->set_items( $_items ); |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | 500 | * Saves cart details. |
501 | - * |
|
502 | - * @param WPInv_Invoice $invoice Invoice object. |
|
501 | + * |
|
502 | + * @param WPInv_Invoice $invoice Invoice object. |
|
503 | 503 | */ |
504 | 504 | public function save_items( $invoice ) { |
505 | 505 | |
506 | - // Delete previously existing items. |
|
507 | - $this->delete_items( $invoice ); |
|
506 | + // Delete previously existing items. |
|
507 | + $this->delete_items( $invoice ); |
|
508 | 508 | |
509 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
509 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
510 | 510 | |
511 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
512 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
513 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
514 | - } |
|
511 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
512 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
513 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
514 | + } |
|
515 | 515 | |
516 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
517 | - do_action( 'getpaid_invoice_save_items', $invoice ); |
|
516 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
517 | + do_action( 'getpaid_invoice_save_items', $invoice ); |
|
518 | 518 | |
519 | - } |
|
519 | + } |
|
520 | 520 | |
521 | - /** |
|
521 | + /** |
|
522 | 522 | * Deletes an invoice's cart details from the database. |
523 | - * |
|
524 | - * @param WPInv_Invoice $invoice Invoice object. |
|
523 | + * |
|
524 | + * @param WPInv_Invoice $invoice Invoice object. |
|
525 | 525 | */ |
526 | 526 | public function delete_items( $invoice ) { |
527 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
528 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
529 | - } |
|
527 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
528 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
529 | + } |
|
530 | 530 | |
531 | - /** |
|
531 | + /** |
|
532 | 532 | * Deletes an invoice's special fields from the database. |
533 | - * |
|
534 | - * @param WPInv_Invoice $invoice Invoice object. |
|
533 | + * |
|
534 | + * @param WPInv_Invoice $invoice Invoice object. |
|
535 | 535 | */ |
536 | 536 | public function delete_special_fields( $invoice ) { |
537 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
538 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * Get the status to save to the post object. |
|
543 | - * |
|
544 | - * |
|
545 | - * @since 1.0.19 |
|
546 | - * @param WPInv_Invoice $object GetPaid_Data object. |
|
547 | - * @return string |
|
548 | - */ |
|
549 | - protected function get_post_status( $object ) { |
|
550 | - $object_status = $object->get_status( 'edit' ); |
|
551 | - |
|
552 | - if ( ! $object_status ) { |
|
553 | - $object_status = $object->get_default_status(); |
|
554 | - } |
|
555 | - |
|
556 | - return $object_status; |
|
557 | - } |
|
537 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
538 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * Get the status to save to the post object. |
|
543 | + * |
|
544 | + * |
|
545 | + * @since 1.0.19 |
|
546 | + * @param WPInv_Invoice $object GetPaid_Data object. |
|
547 | + * @return string |
|
548 | + */ |
|
549 | + protected function get_post_status( $object ) { |
|
550 | + $object_status = $object->get_status( 'edit' ); |
|
551 | + |
|
552 | + if ( ! $object_status ) { |
|
553 | + $object_status = $object->get_default_status(); |
|
554 | + } |
|
555 | + |
|
556 | + return $object_status; |
|
557 | + } |
|
558 | 558 | |
559 | 559 | } |
@@ -15,69 +15,69 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Customer extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | 23 | protected $data_store_name = 'customer'; |
24 | 24 | |
25 | 25 | /** |
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'customer'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Get the customer if ID is passed, otherwise the customer is new and empty. |
|
34 | - * |
|
35 | - * @param int|string|GetPaid_Customer|object $customer customer id, object, or email. |
|
36 | - */ |
|
37 | - public function __construct( $customer = 0 ) { |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'customer'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Get the customer if ID is passed, otherwise the customer is new and empty. |
|
34 | + * |
|
35 | + * @param int|string|GetPaid_Customer|object $customer customer id, object, or email. |
|
36 | + */ |
|
37 | + public function __construct( $customer = 0 ) { |
|
38 | 38 | |
39 | 39 | // Setup default customer data. |
40 | 40 | $this->setup_default_data(); |
41 | 41 | |
42 | - if ( is_numeric( $customer ) ) { |
|
43 | - $this->set_id( $customer ); |
|
44 | - } elseif ( $customer instanceof self ) { |
|
45 | - $this->set_id( $customer->get_id() ); |
|
46 | - } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) { |
|
47 | - $this->set_id( $customer_id ); |
|
48 | - } elseif ( ! empty( $customer->id ) ) { |
|
49 | - $this->set_id( $customer->id ); |
|
50 | - } |
|
42 | + if ( is_numeric( $customer ) ) { |
|
43 | + $this->set_id( $customer ); |
|
44 | + } elseif ( $customer instanceof self ) { |
|
45 | + $this->set_id( $customer->get_id() ); |
|
46 | + } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) { |
|
47 | + $this->set_id( $customer_id ); |
|
48 | + } elseif ( ! empty( $customer->id ) ) { |
|
49 | + $this->set_id( $customer->id ); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | // Load the datastore. |
53 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
53 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
54 | 54 | |
55 | - if ( $this->get_id() > 0 ) { |
|
56 | - $this->data_store->read( $this ); |
|
55 | + if ( $this->get_id() > 0 ) { |
|
56 | + $this->data_store->read( $this ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $this->set_object_read( true ); |
60 | - } |
|
60 | + } |
|
61 | 61 | |
62 | 62 | /** |
63 | - * Sets up default customer data. |
|
64 | - */ |
|
65 | - private function setup_default_data() { |
|
63 | + * Sets up default customer data. |
|
64 | + */ |
|
65 | + private function setup_default_data() { |
|
66 | 66 | |
67 | 67 | $this->data = array( |
68 | - 'user_id' => 0, |
|
69 | - 'email' => '', |
|
70 | - 'email_cc' => '', |
|
71 | - 'status' => 'active', |
|
72 | - 'purchase_value' => 0, |
|
73 | - 'purchase_count' => 0, |
|
74 | - 'date_created' => current_time( 'mysql' ), |
|
75 | - 'date_modified' => current_time( 'mysql' ), |
|
76 | - 'uuid' => wp_generate_uuid4(), |
|
77 | - ); |
|
68 | + 'user_id' => 0, |
|
69 | + 'email' => '', |
|
70 | + 'email_cc' => '', |
|
71 | + 'status' => 'active', |
|
72 | + 'purchase_value' => 0, |
|
73 | + 'purchase_count' => 0, |
|
74 | + 'date_created' => current_time( 'mysql' ), |
|
75 | + 'date_modified' => current_time( 'mysql' ), |
|
76 | + 'uuid' => wp_generate_uuid4(), |
|
77 | + ); |
|
78 | 78 | |
79 | 79 | // Add address fields. |
80 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
80 | + foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
81 | 81 | |
82 | 82 | if ( isset( $this->data[ $field ] ) ) { |
83 | 83 | continue; |
@@ -95,22 +95,22 @@ discard block |
||
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | |
98 | - $this->data[ $field ] = ''; |
|
99 | - } |
|
98 | + $this->data[ $field ] = ''; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | $this->default_data = $this->data; |
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Given a customer email or user id, it returns a customer id. |
|
106 | - * |
|
107 | - * @static |
|
108 | - * @param string $value |
|
109 | - * @since 1.0.15 |
|
110 | - * @return int |
|
111 | - */ |
|
112 | - public static function get_customer_id_by( $value, $by = 'email' ) { |
|
113 | - global $wpdb; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Given a customer email or user id, it returns a customer id. |
|
106 | + * |
|
107 | + * @static |
|
108 | + * @param string $value |
|
109 | + * @since 1.0.15 |
|
110 | + * @return int |
|
111 | + */ |
|
112 | + public static function get_customer_id_by( $value, $by = 'email' ) { |
|
113 | + global $wpdb; |
|
114 | 114 | |
115 | 115 | // Prepare value. |
116 | 116 | if ( 'email' === $by ) { |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | return 0; |
126 | 126 | } |
127 | 127 | |
128 | - // Maybe retrieve from the cache. |
|
128 | + // Maybe retrieve from the cache. |
|
129 | 129 | $cache_key = 'getpaid_customer_ids_by_' . $by; |
130 | - $customer_id = wp_cache_get( $value, $cache_key ); |
|
131 | - if ( false !== $customer_id ) { |
|
132 | - return $customer_id; |
|
133 | - } |
|
130 | + $customer_id = wp_cache_get( $value, $cache_key ); |
|
131 | + if ( false !== $customer_id ) { |
|
132 | + return $customer_id; |
|
133 | + } |
|
134 | 134 | |
135 | 135 | if ( 'email' === $by ) { |
136 | 136 | $customer_id = (int) $wpdb->get_var( |
@@ -142,23 +142,23 @@ discard block |
||
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
145 | - // Update the cache with our data |
|
146 | - wp_cache_set( $value, $customer_id, $cache_key ); |
|
145 | + // Update the cache with our data |
|
146 | + wp_cache_set( $value, $customer_id, $cache_key ); |
|
147 | 147 | |
148 | - return $customer_id; |
|
148 | + return $customer_id; |
|
149 | 149 | |
150 | - } |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
152 | + /** |
|
153 | 153 | * Clears the customer's cache. |
154 | 154 | */ |
155 | 155 | public function clear_cache() { |
156 | 156 | wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' ); |
157 | 157 | wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' ); |
158 | - wp_cache_delete( $this->get_id(), 'getpaid_customers' ); |
|
159 | - } |
|
158 | + wp_cache_delete( $this->get_id(), 'getpaid_customers' ); |
|
159 | + } |
|
160 | 160 | |
161 | - /* |
|
161 | + /* |
|
162 | 162 | |-------------------------------------------------------------------------- |
163 | 163 | | CRUD methods |
164 | 164 | |-------------------------------------------------------------------------- |
@@ -189,11 +189,11 @@ discard block |
||
189 | 189 | return call_user_func( array( $this, 'get_' . $key ), $context ); |
190 | 190 | } |
191 | 191 | |
192 | - return $this->get_prop( $key, $context ); |
|
192 | + return $this->get_prop( $key, $context ); |
|
193 | 193 | |
194 | 194 | } |
195 | 195 | |
196 | - /* |
|
196 | + /* |
|
197 | 197 | |-------------------------------------------------------------------------- |
198 | 198 | | Setters |
199 | 199 | |-------------------------------------------------------------------------- |
@@ -216,114 +216,114 @@ discard block |
||
216 | 216 | return call_user_func( array( $this, 'set_' . $key ), $value ); |
217 | 217 | } |
218 | 218 | |
219 | - return $this->set_prop( $key, $value ); |
|
219 | + return $this->set_prop( $key, $value ); |
|
220 | 220 | |
221 | 221 | } |
222 | 222 | |
223 | - /** |
|
224 | - * Sets customer status. |
|
225 | - * |
|
226 | - * @since 1.0.0 |
|
227 | - * @param string $status New status. |
|
228 | - */ |
|
229 | - public function set_status( $status ) { |
|
230 | - |
|
231 | - if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) { |
|
232 | - return $this->set_prop( 'status', $status ); |
|
233 | - } |
|
234 | - |
|
235 | - $this->set_prop( 'status', 'inactive' ); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Sets the purchase value. |
|
240 | - * |
|
241 | - * @since 1.0.0 |
|
242 | - * @param float $purchase_value. |
|
243 | - */ |
|
244 | - public function set_purchase_value( $purchase_value ) { |
|
245 | - $this->set_prop( 'purchase_value', (float) $purchase_value ); |
|
246 | - } |
|
223 | + /** |
|
224 | + * Sets customer status. |
|
225 | + * |
|
226 | + * @since 1.0.0 |
|
227 | + * @param string $status New status. |
|
228 | + */ |
|
229 | + public function set_status( $status ) { |
|
230 | + |
|
231 | + if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) { |
|
232 | + return $this->set_prop( 'status', $status ); |
|
233 | + } |
|
234 | + |
|
235 | + $this->set_prop( 'status', 'inactive' ); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Sets the purchase value. |
|
240 | + * |
|
241 | + * @since 1.0.0 |
|
242 | + * @param float $purchase_value. |
|
243 | + */ |
|
244 | + public function set_purchase_value( $purchase_value ) { |
|
245 | + $this->set_prop( 'purchase_value', (float) $purchase_value ); |
|
246 | + } |
|
247 | 247 | |
248 | 248 | /** |
249 | - * Sets the purchase count. |
|
250 | - * |
|
251 | - * @since 1.0.0 |
|
252 | - * @param int $purchase_count. |
|
253 | - */ |
|
254 | - public function set_purchase_count( $purchase_count ) { |
|
255 | - $this->set_prop( 'purchase_count', absint( $purchase_count ) ); |
|
256 | - } |
|
249 | + * Sets the purchase count. |
|
250 | + * |
|
251 | + * @since 1.0.0 |
|
252 | + * @param int $purchase_count. |
|
253 | + */ |
|
254 | + public function set_purchase_count( $purchase_count ) { |
|
255 | + $this->set_prop( 'purchase_count', absint( $purchase_count ) ); |
|
256 | + } |
|
257 | 257 | |
258 | 258 | /** |
259 | - * Sets the user id. |
|
260 | - * |
|
261 | - * @since 1.0.0 |
|
262 | - * @param int $user_id. |
|
263 | - */ |
|
264 | - public function set_user_id( $user_id ) { |
|
265 | - $this->set_prop( 'user_id', absint( $user_id ) ); |
|
266 | - } |
|
259 | + * Sets the user id. |
|
260 | + * |
|
261 | + * @since 1.0.0 |
|
262 | + * @param int $user_id. |
|
263 | + */ |
|
264 | + public function set_user_id( $user_id ) { |
|
265 | + $this->set_prop( 'user_id', absint( $user_id ) ); |
|
266 | + } |
|
267 | 267 | |
268 | 268 | /** |
269 | - * Sets the email. |
|
270 | - * |
|
271 | - * @since 1.0.0 |
|
272 | - * @param string $email. |
|
273 | - */ |
|
274 | - public function set_email( $email ) { |
|
269 | + * Sets the email. |
|
270 | + * |
|
271 | + * @since 1.0.0 |
|
272 | + * @param string $email. |
|
273 | + */ |
|
274 | + public function set_email( $email ) { |
|
275 | 275 | $email = is_string( $email ) ? sanitize_email( $email ) : ''; |
276 | - $this->set_prop( 'email', $email ); |
|
277 | - } |
|
276 | + $this->set_prop( 'email', $email ); |
|
277 | + } |
|
278 | 278 | |
279 | 279 | /** |
280 | - * Sets the email cc. |
|
281 | - * |
|
282 | - * @since 1.0.0 |
|
283 | - * @param string $email_cc. |
|
284 | - */ |
|
285 | - public function set_email_cc( $email_cc ) { |
|
280 | + * Sets the email cc. |
|
281 | + * |
|
282 | + * @since 1.0.0 |
|
283 | + * @param string $email_cc. |
|
284 | + */ |
|
285 | + public function set_email_cc( $email_cc ) { |
|
286 | 286 | $email_cc = implode( ', ', wp_parse_list( $email_cc ) ); |
287 | - $this->set_prop( 'email_cc', $email_cc ); |
|
288 | - } |
|
287 | + $this->set_prop( 'email_cc', $email_cc ); |
|
288 | + } |
|
289 | 289 | |
290 | 290 | /** |
291 | - * Sets the created date. |
|
292 | - * |
|
293 | - * @since 1.0.0 |
|
294 | - * @param string $date_created date created. |
|
295 | - */ |
|
296 | - public function set_date_created( $date_created ) { |
|
291 | + * Sets the created date. |
|
292 | + * |
|
293 | + * @since 1.0.0 |
|
294 | + * @param string $date_created date created. |
|
295 | + */ |
|
296 | + public function set_date_created( $date_created ) { |
|
297 | 297 | |
298 | - $date = strtotime( $date_created ); |
|
298 | + $date = strtotime( $date_created ); |
|
299 | 299 | |
300 | 300 | if ( $date && $date_created !== '0000-00-00 00:00:00' && $date_created !== '0000-00-00 00:00' ) { |
301 | 301 | $this->set_prop( 'date_created', gmdate( 'Y-m-d H:i:s', $date ) ); |
302 | 302 | return; |
303 | - } |
|
303 | + } |
|
304 | 304 | |
305 | - $this->set_prop( 'date_created', null ); |
|
306 | - } |
|
305 | + $this->set_prop( 'date_created', null ); |
|
306 | + } |
|
307 | 307 | |
308 | 308 | /** |
309 | - * Sets the created date. |
|
310 | - * |
|
311 | - * @since 1.0.0 |
|
312 | - * @param string $date_modified date created. |
|
313 | - */ |
|
314 | - public function set_date_modified( $date_modified ) { |
|
309 | + * Sets the created date. |
|
310 | + * |
|
311 | + * @since 1.0.0 |
|
312 | + * @param string $date_modified date created. |
|
313 | + */ |
|
314 | + public function set_date_modified( $date_modified ) { |
|
315 | 315 | |
316 | - $date = strtotime( $date_modified ); |
|
316 | + $date = strtotime( $date_modified ); |
|
317 | 317 | |
318 | 318 | if ( $date && $date_modified !== '0000-00-00 00:00:00' && $date_modified !== '0000-00-00 00:00' ) { |
319 | 319 | $this->set_prop( 'date_modified', gmdate( 'Y-m-d H:i:s', $date ) ); |
320 | 320 | return; |
321 | - } |
|
321 | + } |
|
322 | 322 | |
323 | - $this->set_prop( 'date_modified', null ); |
|
324 | - } |
|
323 | + $this->set_prop( 'date_modified', null ); |
|
324 | + } |
|
325 | 325 | |
326 | - /* |
|
326 | + /* |
|
327 | 327 | |-------------------------------------------------------------------------- |
328 | 328 | | Additional methods |
329 | 329 | |-------------------------------------------------------------------------- |
@@ -332,12 +332,12 @@ discard block |
||
332 | 332 | | |
333 | 333 | */ |
334 | 334 | |
335 | - /** |
|
336 | - * Saves the customer. |
|
337 | - * |
|
338 | - * @since 1.0.0 |
|
339 | - */ |
|
340 | - public function save() { |
|
335 | + /** |
|
336 | + * Saves the customer. |
|
337 | + * |
|
338 | + * @since 1.0.0 |
|
339 | + */ |
|
340 | + public function save() { |
|
341 | 341 | |
342 | 342 | $maybe_set = array( |
343 | 343 | 'uuid' => wp_generate_uuid4(), |
@@ -354,29 +354,29 @@ discard block |
||
354 | 354 | |
355 | 355 | $this->set( 'date_modified', current_time( 'mysql' ) ); |
356 | 356 | |
357 | - return parent::save(); |
|
358 | - } |
|
357 | + return parent::save(); |
|
358 | + } |
|
359 | 359 | |
360 | 360 | /** |
361 | - * Helper method to clone a customer from a user ID. |
|
362 | - * |
|
363 | - * @since 1.0.0 |
|
364 | - * @param int $user_id. |
|
365 | - */ |
|
366 | - public function clone_user( $user_id ) { |
|
361 | + * Helper method to clone a customer from a user ID. |
|
362 | + * |
|
363 | + * @since 1.0.0 |
|
364 | + * @param int $user_id. |
|
365 | + */ |
|
366 | + public function clone_user( $user_id ) { |
|
367 | 367 | $user = get_userdata( $user_id ); |
368 | 368 | |
369 | 369 | if ( empty( $user ) ) { |
370 | 370 | return; |
371 | 371 | } |
372 | 372 | |
373 | - $this->set_user_id( $user->ID ); |
|
373 | + $this->set_user_id( $user->ID ); |
|
374 | 374 | $this->set_email( $user->user_email ); |
375 | 375 | $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) ); |
376 | 376 | $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) ); |
377 | 377 | $this->set( 'first_name', $user->first_name ); |
378 | 378 | $this->set( 'last_name', $user->last_name ); |
379 | - $this->set_date_created( $user->user_registered ); |
|
379 | + $this->set_date_created( $user->user_registered ); |
|
380 | 380 | |
381 | 381 | // Fetch extra data from WC or old GetPaid. |
382 | 382 | $prefixes = array( |
@@ -400,18 +400,18 @@ discard block |
||
400 | 400 | continue; |
401 | 401 | } |
402 | 402 | } |
403 | - } |
|
404 | - } |
|
403 | + } |
|
404 | + } |
|
405 | 405 | |
406 | 406 | /** |
407 | - * Helper method to migrate an existing user ID to the new customers table. |
|
408 | - * |
|
409 | - * @since 1.0.0 |
|
410 | - * @param int $user_id. |
|
411 | - */ |
|
412 | - public function migrate_from_user( $user_id ) { |
|
407 | + * Helper method to migrate an existing user ID to the new customers table. |
|
408 | + * |
|
409 | + * @since 1.0.0 |
|
410 | + * @param int $user_id. |
|
411 | + */ |
|
412 | + public function migrate_from_user( $user_id ) { |
|
413 | 413 | $this->clone_user( $user_id ); |
414 | 414 | do_action( 'getpaid_customer_migrated_from_user', $this, $user_id ); |
415 | 415 | $this->save(); |
416 | - } |
|
416 | + } |
|
417 | 417 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -75,16 +75,16 @@ discard block |
||
75 | 75 | $class .= ' wpi-recurring'; |
76 | 76 | } |
77 | 77 | |
78 | - $refund_url = wp_nonce_url( |
|
79 | - add_query_arg( |
|
80 | - array( |
|
81 | - 'getpaid-admin-action' => 'refund_invoice', |
|
82 | - 'invoice_id' => $invoice->get_id(), |
|
83 | - ) |
|
84 | - ), |
|
85 | - 'getpaid-nonce', |
|
86 | - 'getpaid-nonce' |
|
87 | - ); |
|
78 | + $refund_url = wp_nonce_url( |
|
79 | + add_query_arg( |
|
80 | + array( |
|
81 | + 'getpaid-admin-action' => 'refund_invoice', |
|
82 | + 'invoice_id' => $invoice->get_id(), |
|
83 | + ) |
|
84 | + ), |
|
85 | + 'getpaid-nonce', |
|
86 | + 'getpaid-nonce' |
|
87 | + ); |
|
88 | 88 | ?> |
89 | 89 | |
90 | 90 | <div class="wpinv-items-wrap<?php echo esc_attr( $class ); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr( $invoice->get_status() ); ?>"> |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | <th class=" |
97 | 97 | <?php |
98 | 98 | echo esc_attr( $key ); |
99 | - echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : ''; |
|
100 | - ?> |
|
99 | + echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : ''; |
|
100 | + ?> |
|
101 | 101 | "><?php echo wp_kses_post( $label ); ?></th> |
102 | 102 | <?php endforeach; ?> |
103 | 103 | </tr> |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | <tbody class="wpinv-line-items"> |
107 | 107 | <?php |
108 | 108 | foreach ( $invoice->get_items() as $int => $item ) { |
109 | - self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' ); |
|
109 | + self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' ); |
|
110 | 110 | } |
111 | 111 | ?> |
112 | 112 | </tbody> |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | <?php |
152 | 152 | wpinv_html_select( |
153 | 153 | array( |
154 | - 'options' => $item_types, |
|
155 | - 'name' => '_wpinv_quick[type]', |
|
156 | - 'id' => '_wpinv_quick_type', |
|
157 | - 'selected' => 'custom', |
|
158 | - 'show_option_all' => false, |
|
159 | - 'show_option_none' => false, |
|
160 | - 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
|
154 | + 'options' => $item_types, |
|
155 | + 'name' => '_wpinv_quick[type]', |
|
156 | + 'id' => '_wpinv_quick_type', |
|
157 | + 'selected' => 'custom', |
|
158 | + 'show_option_all' => false, |
|
159 | + 'show_option_none' => false, |
|
160 | + 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
|
161 | 161 | ) |
162 | 162 | ); |
163 | 163 | ?> |
@@ -172,16 +172,16 @@ discard block |
||
172 | 172 | <?php |
173 | 173 | wpinv_html_select( |
174 | 174 | array( |
175 | - 'options' => array_merge( |
|
176 | - array( '' => __( 'Select VAT Rule', 'invoicing' ) ), |
|
177 | - getpaid_get_tax_rules() |
|
178 | - ), |
|
179 | - 'name' => '_wpinv_quick[vat_rule]', |
|
180 | - 'id' => '_wpinv_quick_vat_rule', |
|
181 | - 'show_option_all' => false, |
|
182 | - 'show_option_none' => false, |
|
183 | - 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
|
184 | - 'selected' => 'digital', |
|
175 | + 'options' => array_merge( |
|
176 | + array( '' => __( 'Select VAT Rule', 'invoicing' ) ), |
|
177 | + getpaid_get_tax_rules() |
|
178 | + ), |
|
179 | + 'name' => '_wpinv_quick[vat_rule]', |
|
180 | + 'id' => '_wpinv_quick_vat_rule', |
|
181 | + 'show_option_all' => false, |
|
182 | + 'show_option_none' => false, |
|
183 | + 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
|
184 | + 'selected' => 'digital', |
|
185 | 185 | ) |
186 | 186 | ); |
187 | 187 | ?> |
@@ -194,16 +194,16 @@ discard block |
||
194 | 194 | <?php |
195 | 195 | wpinv_html_select( |
196 | 196 | array( |
197 | - 'options' => array_merge( |
|
198 | - array( '' => __( 'Select VAT Class', 'invoicing' ) ), |
|
199 | - getpaid_get_tax_classes() |
|
200 | - ), |
|
201 | - 'name' => '_wpinv_quick[vat_class]', |
|
202 | - 'id' => '_wpinv_quick_vat_class', |
|
203 | - 'show_option_all' => false, |
|
204 | - 'show_option_none' => false, |
|
205 | - 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
|
206 | - 'selected' => '_standard', |
|
197 | + 'options' => array_merge( |
|
198 | + array( '' => __( 'Select VAT Class', 'invoicing' ) ), |
|
199 | + getpaid_get_tax_classes() |
|
200 | + ), |
|
201 | + 'name' => '_wpinv_quick[vat_class]', |
|
202 | + 'id' => '_wpinv_quick_vat_class', |
|
203 | + 'show_option_all' => false, |
|
204 | + 'show_option_none' => false, |
|
205 | + 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
|
206 | + 'selected' => '_standard', |
|
207 | 207 | ) |
208 | 208 | ); |
209 | 209 | ?> |
@@ -294,37 +294,37 @@ discard block |
||
294 | 294 | </p> |
295 | 295 | <?php if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) ) : ?> |
296 | 296 | <?php |
297 | - aui()->input( |
|
298 | - array( |
|
299 | - 'type' => 'checkbox', |
|
300 | - 'name' => 'getpaid_refund_remote', |
|
301 | - 'id' => 'getpaid_refund_remote', |
|
302 | - 'label' => sprintf( |
|
303 | - 'Refund payment in %s', |
|
304 | - wpinv_get_gateway_admin_label( $invoice->get_gateway() ) |
|
305 | - ), |
|
306 | - 'value' => 1, |
|
307 | - 'class' => 'getpaid-refund-field', |
|
308 | - ), |
|
309 | - true |
|
310 | - ); |
|
311 | - ?> |
|
297 | + aui()->input( |
|
298 | + array( |
|
299 | + 'type' => 'checkbox', |
|
300 | + 'name' => 'getpaid_refund_remote', |
|
301 | + 'id' => 'getpaid_refund_remote', |
|
302 | + 'label' => sprintf( |
|
303 | + 'Refund payment in %s', |
|
304 | + wpinv_get_gateway_admin_label( $invoice->get_gateway() ) |
|
305 | + ), |
|
306 | + 'value' => 1, |
|
307 | + 'class' => 'getpaid-refund-field', |
|
308 | + ), |
|
309 | + true |
|
310 | + ); |
|
311 | + ?> |
|
312 | 312 | <?php endif; ?> |
313 | 313 | |
314 | 314 | <?php if ( getpaid_get_invoice_subscriptions( $invoice ) ) : ?> |
315 | 315 | <?php |
316 | - aui()->input( |
|
317 | - array( |
|
318 | - 'type' => 'checkbox', |
|
319 | - 'name' => 'getpaid_cancel_subscription', |
|
320 | - 'id' => 'getpaid_cancel_subscription', |
|
321 | - 'label' => __( 'Cancel subscription', 'invoicing' ), |
|
322 | - 'value' => 1, |
|
323 | - 'class' => 'getpaid-refund-field', |
|
324 | - ), |
|
325 | - true |
|
326 | - ); |
|
327 | - ?> |
|
316 | + aui()->input( |
|
317 | + array( |
|
318 | + 'type' => 'checkbox', |
|
319 | + 'name' => 'getpaid_cancel_subscription', |
|
320 | + 'id' => 'getpaid_cancel_subscription', |
|
321 | + 'label' => __( 'Cancel subscription', 'invoicing' ), |
|
322 | + 'value' => 1, |
|
323 | + 'class' => 'getpaid-refund-field', |
|
324 | + ), |
|
325 | + true |
|
326 | + ); |
|
327 | + ?> |
|
328 | 328 | <?php endif; ?> |
329 | 329 | </div> |
330 | 330 | <div class="modal-footer"> |
@@ -364,23 +364,23 @@ discard block |
||
364 | 364 | <?php |
365 | 365 | if ( $invoice->is_paid() ) { |
366 | 366 | |
367 | - printf( |
|
368 | - '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>', |
|
369 | - esc_html__( 'Refund', 'invoicing' ) |
|
370 | - ); |
|
367 | + printf( |
|
368 | + '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>', |
|
369 | + esc_html__( 'Refund', 'invoicing' ) |
|
370 | + ); |
|
371 | 371 | } elseif ( ! $invoice->is_refunded() ) { |
372 | - wpinv_item_dropdown( |
|
373 | - array( |
|
374 | - 'name' => 'wpinv_invoice_item', |
|
375 | - 'id' => 'wpinv_invoice_item', |
|
376 | - 'show_recurring' => true, |
|
377 | - 'class' => 'wpi_select2', |
|
378 | - ) |
|
379 | - ); |
|
380 | - |
|
381 | - echo ' ' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>'; |
|
382 | - echo ' ' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>'; |
|
383 | - echo ' ' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>'; |
|
372 | + wpinv_item_dropdown( |
|
373 | + array( |
|
374 | + 'name' => 'wpinv_invoice_item', |
|
375 | + 'id' => 'wpinv_invoice_item', |
|
376 | + 'show_recurring' => true, |
|
377 | + 'class' => 'wpi_select2', |
|
378 | + ) |
|
379 | + ); |
|
380 | + |
|
381 | + echo ' ' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>'; |
|
382 | + echo ' ' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>'; |
|
383 | + echo ' ' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>'; |
|
384 | 384 | |
385 | 385 | } |
386 | 386 | ?> |
@@ -397,72 +397,72 @@ discard block |
||
397 | 397 | <?php foreach ( array_keys( $columns ) as $column ) : ?> |
398 | 398 | <td class=" |
399 | 399 | <?php |
400 | - echo esc_attr( $column ); |
|
401 | - echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : ''; |
|
402 | - ?> |
|
400 | + echo esc_attr( $column ); |
|
401 | + echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : ''; |
|
402 | + ?> |
|
403 | 403 | "> |
404 | 404 | <?php |
405 | 405 | switch ( $column ) { |
406 | - case 'id': |
|
407 | - echo (int) $item->get_id(); |
|
408 | - break; |
|
409 | - case 'title': |
|
410 | - printf( |
|
411 | - '<a href="%s" target="_blank">%s</a>', |
|
412 | - esc_url( get_edit_post_link( $item->get_id() ) ), |
|
413 | - esc_html( $item->get_raw_name() ) |
|
414 | - ); |
|
415 | - |
|
416 | - $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
417 | - if ( $summary !== '' ) { |
|
418 | - printf( |
|
419 | - '<span class="meta">%s</span>', |
|
420 | - wp_kses_post( wpautop( $summary ) ) |
|
421 | - ); |
|
422 | - } |
|
423 | - |
|
424 | - printf( |
|
425 | - '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />', |
|
426 | - esc_attr( $item->get_raw_name() ), |
|
427 | - (int) $item->get_id() |
|
428 | - ); |
|
429 | - |
|
430 | - printf( |
|
431 | - '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>', |
|
432 | - (int) $item->get_id(), |
|
433 | - esc_attr( $item->get_description() ) |
|
434 | - ); |
|
435 | - |
|
436 | - break; |
|
437 | - case 'price': |
|
438 | - printf( |
|
439 | - '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />', |
|
440 | - esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ), |
|
441 | - (int) $item->get_id() |
|
442 | - ); |
|
443 | - |
|
444 | - break; |
|
445 | - case 'qty': |
|
446 | - printf( |
|
447 | - '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />', |
|
448 | - floatval( $item->get_quantity() ), |
|
449 | - (int) $item->get_id() |
|
450 | - ); |
|
451 | - |
|
452 | - break; |
|
453 | - case 'total': |
|
454 | - wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
455 | - |
|
456 | - break; |
|
457 | - case 'tax': |
|
458 | - echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
459 | - |
|
460 | - break; |
|
461 | - case 'action': |
|
462 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
463 | - echo '<i class="fa fa-trash wpinv-item-remove"></i>'; |
|
406 | + case 'id': |
|
407 | + echo (int) $item->get_id(); |
|
408 | + break; |
|
409 | + case 'title': |
|
410 | + printf( |
|
411 | + '<a href="%s" target="_blank">%s</a>', |
|
412 | + esc_url( get_edit_post_link( $item->get_id() ) ), |
|
413 | + esc_html( $item->get_raw_name() ) |
|
414 | + ); |
|
415 | + |
|
416 | + $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice ); |
|
417 | + if ( $summary !== '' ) { |
|
418 | + printf( |
|
419 | + '<span class="meta">%s</span>', |
|
420 | + wp_kses_post( wpautop( $summary ) ) |
|
421 | + ); |
|
422 | + } |
|
423 | + |
|
424 | + printf( |
|
425 | + '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />', |
|
426 | + esc_attr( $item->get_raw_name() ), |
|
427 | + (int) $item->get_id() |
|
428 | + ); |
|
429 | + |
|
430 | + printf( |
|
431 | + '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>', |
|
432 | + (int) $item->get_id(), |
|
433 | + esc_attr( $item->get_description() ) |
|
434 | + ); |
|
435 | + |
|
436 | + break; |
|
437 | + case 'price': |
|
438 | + printf( |
|
439 | + '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />', |
|
440 | + esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ), |
|
441 | + (int) $item->get_id() |
|
442 | + ); |
|
443 | + |
|
444 | + break; |
|
445 | + case 'qty': |
|
446 | + printf( |
|
447 | + '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />', |
|
448 | + floatval( $item->get_quantity() ), |
|
449 | + (int) $item->get_id() |
|
450 | + ); |
|
451 | + |
|
452 | + break; |
|
453 | + case 'total': |
|
454 | + wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() ); |
|
455 | + |
|
456 | + break; |
|
457 | + case 'tax': |
|
458 | + echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%'; |
|
459 | + |
|
460 | + break; |
|
461 | + case 'action': |
|
462 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
463 | + echo '<i class="fa fa-trash wpinv-item-remove"></i>'; |
|
464 | 464 | } |
465 | - break; |
|
465 | + break; |
|
466 | 466 | } |
467 | 467 | do_action( 'getpaid_admin_edit_invoice_item_' . $column, $item, $invoice ); |
468 | 468 | ?> |
@@ -473,10 +473,10 @@ discard block |
||
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
476 | - * Output the metabox. |
|
477 | - * |
|
478 | - * @param WP_Post $post |
|
479 | - */ |
|
476 | + * Output the metabox. |
|
477 | + * |
|
478 | + * @param WP_Post $post |
|
479 | + */ |
|
480 | 480 | public static function output2( $post ) { |
481 | 481 | |
482 | 482 | // Prepare the invoice. |
@@ -14,94 +14,94 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - public $admin_url; |
|
29 | - |
|
30 | - /** |
|
31 | - * Reports components. |
|
32 | - * |
|
33 | - * @var GetPaid_Reports |
|
34 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + public $admin_url; |
|
29 | + |
|
30 | + /** |
|
31 | + * Reports components. |
|
32 | + * |
|
33 | + * @var GetPaid_Reports |
|
34 | + */ |
|
35 | 35 | public $reports; |
36 | 36 | |
37 | 37 | /** |
38 | - * Class constructor. |
|
39 | - */ |
|
40 | - public function __construct() { |
|
38 | + * Class constructor. |
|
39 | + */ |
|
40 | + public function __construct() { |
|
41 | 41 | |
42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | - $this->reports = new GetPaid_Reports(); |
|
43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
44 | + $this->reports = new GetPaid_Reports(); |
|
45 | 45 | |
46 | 46 | if ( is_admin() ) { |
47 | - $this->init_admin_hooks(); |
|
47 | + $this->init_admin_hooks(); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Init action and filter hooks |
|
54 | - * |
|
55 | - */ |
|
56 | - private function init_admin_hooks() { |
|
53 | + * Init action and filter hooks |
|
54 | + * |
|
55 | + */ |
|
56 | + private function init_admin_hooks() { |
|
57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) ); |
62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | - add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | - add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) ); |
|
68 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
69 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
65 | + add_action( 'getpaid_authenticated_admin_action_reset_form_stats', array( $this, 'reset_form_stats' ) ); |
|
66 | + add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
67 | + add_action( 'getpaid_authenticated_admin_action_refund_invoice', array( $this, 'refund_invoice' ) ); |
|
68 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
69 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
70 | 70 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
71 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
72 | - add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
73 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
74 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
75 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
76 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
77 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
78 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
79 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
80 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
81 | - |
|
82 | - // Setup/welcome |
|
83 | - if ( ! empty( $_GET['page'] ) ) { |
|
84 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
85 | - case 'gp-setup': |
|
86 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
87 | - break; |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Register admin scripts |
|
95 | - * |
|
96 | - */ |
|
97 | - public function enqeue_scripts() { |
|
71 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
72 | + add_action( 'getpaid_authenticated_admin_action_refresh_permalinks', array( $this, 'admin_refresh_permalinks' ) ); |
|
73 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
74 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
75 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
76 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
77 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
78 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
79 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
80 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
81 | + |
|
82 | + // Setup/welcome |
|
83 | + if ( ! empty( $_GET['page'] ) ) { |
|
84 | + switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
85 | + case 'gp-setup': |
|
86 | + include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
87 | + break; |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Register admin scripts |
|
95 | + * |
|
96 | + */ |
|
97 | + public function enqeue_scripts() { |
|
98 | 98 | global $current_screen, $pagenow; |
99 | 99 | |
100 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
101 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
100 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
101 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
102 | 102 | |
103 | 103 | if ( ! empty( $current_screen->post_type ) ) { |
104 | - $page = $current_screen->post_type; |
|
104 | + $page = $current_screen->post_type; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // General styles. |
@@ -122,53 +122,53 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | // Payment form scripts. |
125 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
125 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
126 | 126 | $this->load_payment_form_scripts(); |
127 | 127 | } |
128 | 128 | |
129 | - if ( $page == 'wpinv-subscriptions' ) { |
|
130 | - wp_enqueue_script( 'postbox' ); |
|
131 | - } |
|
129 | + if ( $page == 'wpinv-subscriptions' ) { |
|
130 | + wp_enqueue_script( 'postbox' ); |
|
131 | + } |
|
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Returns admin js translations. |
|
137 | - * |
|
138 | - */ |
|
139 | - protected function get_admin_i18() { |
|
136 | + * Returns admin js translations. |
|
137 | + * |
|
138 | + */ |
|
139 | + protected function get_admin_i18() { |
|
140 | 140 | global $post; |
141 | 141 | |
142 | - $date_range = array( |
|
143 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
144 | - ); |
|
142 | + $date_range = array( |
|
143 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
144 | + ); |
|
145 | 145 | |
146 | - if ( $date_range['period'] == 'custom' ) { |
|
146 | + if ( $date_range['period'] == 'custom' ) { |
|
147 | 147 | |
148 | - if ( isset( $_GET['from'] ) ) { |
|
149 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
150 | - } |
|
148 | + if ( isset( $_GET['from'] ) ) { |
|
149 | + $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
150 | + } |
|
151 | 151 | |
152 | - if ( isset( $_GET['to'] ) ) { |
|
153 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
154 | - } |
|
152 | + if ( isset( $_GET['to'] ) ) { |
|
153 | + $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
154 | + } |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | $i18n = array( |
158 | 158 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
159 | 159 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
160 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
161 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
162 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
163 | - 'date_range' => $date_range, |
|
160 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
161 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
162 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
163 | + 'date_range' => $date_range, |
|
164 | 164 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
165 | 165 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
166 | 166 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
167 | 167 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
168 | 168 | 'tax' => wpinv_tax_amount(), |
169 | 169 | 'discount' => 0, |
170 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
171 | - 'currency' => wpinv_get_currency(), |
|
170 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
171 | + 'currency' => wpinv_get_currency(), |
|
172 | 172 | 'currency_pos' => wpinv_currency_position(), |
173 | 173 | 'thousand_sep' => wpinv_thousands_separator(), |
174 | 174 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -188,118 +188,118 @@ discard block |
||
188 | 188 | 'item_description' => __( 'Item Description', 'invoicing' ), |
189 | 189 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
190 | 190 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
191 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
192 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
193 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
194 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
195 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
191 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
192 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
193 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
194 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
195 | + 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
196 | 196 | ); |
197 | 197 | |
198 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
198 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
199 | 199 | |
200 | - $invoice = new WPInv_Invoice( $post ); |
|
201 | - $i18n['save_invoice'] = sprintf( |
|
202 | - __( 'Save %s', 'invoicing' ), |
|
203 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
204 | - ); |
|
200 | + $invoice = new WPInv_Invoice( $post ); |
|
201 | + $i18n['save_invoice'] = sprintf( |
|
202 | + __( 'Save %s', 'invoicing' ), |
|
203 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
204 | + ); |
|
205 | 205 | |
206 | - $i18n['invoice_description'] = sprintf( |
|
207 | - __( '%s Description', 'invoicing' ), |
|
208 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
209 | - ); |
|
206 | + $i18n['invoice_description'] = sprintf( |
|
207 | + __( '%s Description', 'invoicing' ), |
|
208 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
209 | + ); |
|
210 | 210 | |
211 | - } |
|
212 | - return $i18n; |
|
213 | - } |
|
211 | + } |
|
212 | + return $i18n; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Change the admin footer text on GetPaid admin pages. |
|
217 | - * |
|
218 | - * @since 2.0.0 |
|
219 | - * @param string $footer_text |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function admin_footer_text( $footer_text ) { |
|
223 | - global $current_screen; |
|
215 | + /** |
|
216 | + * Change the admin footer text on GetPaid admin pages. |
|
217 | + * |
|
218 | + * @since 2.0.0 |
|
219 | + * @param string $footer_text |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function admin_footer_text( $footer_text ) { |
|
223 | + global $current_screen; |
|
224 | 224 | |
225 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
225 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
226 | 226 | |
227 | 227 | if ( ! empty( $current_screen->post_type ) ) { |
228 | - $page = $current_screen->post_type; |
|
228 | + $page = $current_screen->post_type; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // General styles. |
232 | 232 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
233 | 233 | |
234 | - // Change the footer text |
|
235 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
234 | + // Change the footer text |
|
235 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
236 | 236 | |
237 | - $rating_url = esc_url( |
|
238 | - wp_nonce_url( |
|
239 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
240 | - 'getpaid-nonce', |
|
241 | - 'getpaid-nonce' |
|
237 | + $rating_url = esc_url( |
|
238 | + wp_nonce_url( |
|
239 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
240 | + 'getpaid-nonce', |
|
241 | + 'getpaid-nonce' |
|
242 | 242 | ) |
243 | - ); |
|
243 | + ); |
|
244 | 244 | |
245 | - $footer_text = sprintf( |
|
246 | - /* translators: %s: five stars */ |
|
247 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
248 | - "<a href='$rating_url'>★★★★★</a>" |
|
249 | - ); |
|
245 | + $footer_text = sprintf( |
|
246 | + /* translators: %s: five stars */ |
|
247 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
248 | + "<a href='$rating_url'>★★★★★</a>" |
|
249 | + ); |
|
250 | 250 | |
251 | - } else { |
|
251 | + } else { |
|
252 | 252 | |
253 | - $footer_text = sprintf( |
|
254 | - /* translators: %s: GetPaid */ |
|
255 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
256 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
257 | - ); |
|
253 | + $footer_text = sprintf( |
|
254 | + /* translators: %s: GetPaid */ |
|
255 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
256 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
257 | + ); |
|
258 | 258 | |
259 | - } |
|
259 | + } |
|
260 | 260 | } |
261 | 261 | |
262 | - return $footer_text; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Redirects to wp.org to rate the plugin. |
|
267 | - * |
|
268 | - * @since 2.0.0 |
|
269 | - */ |
|
270 | - public function redirect_to_wordpress_rating_page() { |
|
271 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
272 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
273 | - exit; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Loads payment form js. |
|
278 | - * |
|
279 | - */ |
|
280 | - protected function load_payment_form_scripts() { |
|
262 | + return $footer_text; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Redirects to wp.org to rate the plugin. |
|
267 | + * |
|
268 | + * @since 2.0.0 |
|
269 | + */ |
|
270 | + public function redirect_to_wordpress_rating_page() { |
|
271 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
272 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
273 | + exit; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Loads payment form js. |
|
278 | + * |
|
279 | + */ |
|
280 | + protected function load_payment_form_scripts() { |
|
281 | 281 | global $post; |
282 | 282 | |
283 | 283 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
284 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
285 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
284 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
285 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
286 | 286 | |
287 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
288 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
287 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
288 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
289 | 289 | |
290 | - wp_localize_script( |
|
290 | + wp_localize_script( |
|
291 | 291 | 'wpinv-admin-payment-form-script', |
292 | 292 | 'wpinvPaymentFormAdmin', |
293 | 293 | array( |
294 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
295 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
296 | - 'currency' => wpinv_currency_symbol(), |
|
297 | - 'position' => wpinv_currency_position(), |
|
298 | - 'decimals' => (int) wpinv_decimals(), |
|
299 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
300 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
301 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
302 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
294 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
295 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
296 | + 'currency' => wpinv_currency_symbol(), |
|
297 | + 'position' => wpinv_currency_position(), |
|
298 | + 'decimals' => (int) wpinv_decimals(), |
|
299 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
300 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
301 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
302 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
303 | 303 | ) |
304 | 304 | ); |
305 | 305 | |
@@ -308,19 +308,19 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
311 | - * Add our classes to admin pages. |
|
311 | + * Add our classes to admin pages. |
|
312 | 312 | * |
313 | 313 | * @param string $classes |
314 | 314 | * @return string |
315 | - * |
|
316 | - */ |
|
315 | + * |
|
316 | + */ |
|
317 | 317 | public function admin_body_class( $classes ) { |
318 | - global $pagenow, $post, $current_screen; |
|
318 | + global $pagenow, $post, $current_screen; |
|
319 | 319 | |
320 | 320 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
321 | 321 | |
322 | 322 | if ( ! empty( $current_screen->post_type ) ) { |
323 | - $page = $current_screen->post_type; |
|
323 | + $page = $current_screen->post_type; |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -329,70 +329,70 @@ discard block |
||
329 | 329 | |
330 | 330 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
331 | 331 | $classes .= ' wpinv-cpt wpinv'; |
332 | - } |
|
332 | + } |
|
333 | 333 | |
334 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
334 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
335 | 335 | $classes .= ' getpaid-is-invoice-cpt'; |
336 | 336 | } |
337 | 337 | |
338 | - return $classes; |
|
338 | + return $classes; |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
342 | - * Maybe show the AyeCode Connect Notice. |
|
343 | - */ |
|
344 | - public function init_ayecode_connect_helper() { |
|
342 | + * Maybe show the AyeCode Connect Notice. |
|
343 | + */ |
|
344 | + public function init_ayecode_connect_helper() { |
|
345 | 345 | |
346 | - // Register with the deactivation survey class. |
|
347 | - AyeCode_Deactivation_Survey::instance( |
|
346 | + // Register with the deactivation survey class. |
|
347 | + AyeCode_Deactivation_Survey::instance( |
|
348 | 348 | array( |
349 | - 'slug' => 'invoicing', |
|
350 | - 'version' => WPINV_VERSION, |
|
351 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
352 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
353 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
349 | + 'slug' => 'invoicing', |
|
350 | + 'version' => WPINV_VERSION, |
|
351 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
352 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
353 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
354 | 354 | ) |
355 | 355 | ); |
356 | 356 | |
357 | 357 | new AyeCode_Connect_Helper( |
358 | 358 | array( |
359 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
360 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
361 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
362 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
363 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
364 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
365 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
359 | + 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
360 | + 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
361 | + 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
362 | + 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
363 | + 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
364 | + 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
365 | + 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
366 | 366 | ), |
367 | 367 | array( 'wpi-addons' ) |
368 | 368 | ); |
369 | 369 | |
370 | 370 | } |
371 | 371 | |
372 | - /** |
|
373 | - * Redirect users to settings on activation. |
|
374 | - * |
|
375 | - * @return void |
|
376 | - */ |
|
377 | - public function activation_redirect() { |
|
372 | + /** |
|
373 | + * Redirect users to settings on activation. |
|
374 | + * |
|
375 | + * @return void |
|
376 | + */ |
|
377 | + public function activation_redirect() { |
|
378 | 378 | |
379 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
379 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
380 | 380 | |
381 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
382 | - return; |
|
383 | - } |
|
381 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
382 | + return; |
|
383 | + } |
|
384 | 384 | |
385 | - // Bail if activating from network, or bulk |
|
386 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
387 | - return; |
|
388 | - } |
|
385 | + // Bail if activating from network, or bulk |
|
386 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
387 | + return; |
|
388 | + } |
|
389 | 389 | |
390 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
390 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
391 | 391 | |
392 | 392 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
393 | 393 | exit; |
394 | 394 | |
395 | - } |
|
395 | + } |
|
396 | 396 | |
397 | 397 | /** |
398 | 398 | * Fires an admin action after verifying that a user can fire them. |
@@ -405,555 +405,555 @@ discard block |
||
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
408 | - /** |
|
408 | + /** |
|
409 | 409 | * Duplicate invoice. |
410 | - * |
|
411 | - * @param array $args |
|
410 | + * |
|
411 | + * @param array $args |
|
412 | 412 | */ |
413 | 413 | public function duplicate_invoice( $args ) { |
414 | 414 | |
415 | - if ( empty( $args['invoice_id'] ) ) { |
|
416 | - return; |
|
417 | - } |
|
415 | + if ( empty( $args['invoice_id'] ) ) { |
|
416 | + return; |
|
417 | + } |
|
418 | 418 | |
419 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
419 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
420 | 420 | |
421 | - if ( ! $invoice->exists() ) { |
|
422 | - return; |
|
423 | - } |
|
421 | + if ( ! $invoice->exists() ) { |
|
422 | + return; |
|
423 | + } |
|
424 | 424 | |
425 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
426 | - $new_invoice->save(); |
|
425 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
426 | + $new_invoice->save(); |
|
427 | 427 | |
428 | - if ( $new_invoice->exists() ) { |
|
428 | + if ( $new_invoice->exists() ) { |
|
429 | 429 | |
430 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
430 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'invoicing' ) ); |
|
431 | 431 | |
432 | - wp_safe_redirect( |
|
433 | - add_query_arg( |
|
434 | - array( |
|
435 | - 'action' => 'edit', |
|
436 | - 'post' => $new_invoice->get_id(), |
|
437 | - ), |
|
438 | - admin_url( 'post.php' ) |
|
439 | - ) |
|
440 | - ); |
|
441 | - exit; |
|
432 | + wp_safe_redirect( |
|
433 | + add_query_arg( |
|
434 | + array( |
|
435 | + 'action' => 'edit', |
|
436 | + 'post' => $new_invoice->get_id(), |
|
437 | + ), |
|
438 | + admin_url( 'post.php' ) |
|
439 | + ) |
|
440 | + ); |
|
441 | + exit; |
|
442 | 442 | |
443 | - } |
|
443 | + } |
|
444 | 444 | |
445 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
445 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'invoicing' ) ); |
|
446 | 446 | |
447 | - } |
|
447 | + } |
|
448 | 448 | |
449 | - /** |
|
449 | + /** |
|
450 | 450 | * Refund an invoice. |
451 | - * |
|
452 | - * @param array $args |
|
451 | + * |
|
452 | + * @param array $args |
|
453 | 453 | */ |
454 | 454 | public function refund_invoice( $args ) { |
455 | 455 | |
456 | - if ( empty( $args['invoice_id'] ) ) { |
|
457 | - return; |
|
458 | - } |
|
459 | - |
|
460 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
461 | - |
|
462 | - if ( ! $invoice->exists() || $invoice->is_refunded() ) { |
|
463 | - return; |
|
464 | - } |
|
465 | - |
|
466 | - $invoice->refund(); |
|
467 | - |
|
468 | - // Refund remotely. |
|
469 | - if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) { |
|
470 | - do_action( 'getpaid_refund_invoice_remotely', $invoice ); |
|
471 | - } |
|
472 | - |
|
473 | - // Cancel subscriptions. |
|
474 | - if ( ! empty( $args['getpaid_cancel_subscription'] ) ) { |
|
475 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
476 | - |
|
477 | - if ( ! empty( $subscriptions ) ) { |
|
478 | - if ( ! is_array( $subscriptions ) ) { |
|
479 | - $subscriptions = array( $subscriptions ); |
|
480 | - } |
|
481 | - |
|
482 | - foreach ( $subscriptions as $subscription ) { |
|
483 | - $subscription->cancel(); |
|
484 | - $invoice->add_system_note( |
|
485 | - sprintf( |
|
486 | - // translators: %s: subscription ID. |
|
487 | - __( 'Subscription #%s cancelled', 'invoicing' ), |
|
488 | - $subscription->get_id() |
|
489 | - ) |
|
490 | - ); |
|
491 | - } |
|
492 | - } |
|
493 | - } |
|
494 | - |
|
495 | - // Add notice. |
|
496 | - $this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) ); |
|
497 | - |
|
498 | - // Redirect. |
|
499 | - wp_safe_redirect( |
|
500 | - remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) ) |
|
501 | - ); |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
456 | + if ( empty( $args['invoice_id'] ) ) { |
|
457 | + return; |
|
458 | + } |
|
459 | + |
|
460 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
461 | + |
|
462 | + if ( ! $invoice->exists() || $invoice->is_refunded() ) { |
|
463 | + return; |
|
464 | + } |
|
465 | + |
|
466 | + $invoice->refund(); |
|
467 | + |
|
468 | + // Refund remotely. |
|
469 | + if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) && ! empty( $args['getpaid_refund_remote'] ) ) { |
|
470 | + do_action( 'getpaid_refund_invoice_remotely', $invoice ); |
|
471 | + } |
|
472 | + |
|
473 | + // Cancel subscriptions. |
|
474 | + if ( ! empty( $args['getpaid_cancel_subscription'] ) ) { |
|
475 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
476 | + |
|
477 | + if ( ! empty( $subscriptions ) ) { |
|
478 | + if ( ! is_array( $subscriptions ) ) { |
|
479 | + $subscriptions = array( $subscriptions ); |
|
480 | + } |
|
481 | + |
|
482 | + foreach ( $subscriptions as $subscription ) { |
|
483 | + $subscription->cancel(); |
|
484 | + $invoice->add_system_note( |
|
485 | + sprintf( |
|
486 | + // translators: %s: subscription ID. |
|
487 | + __( 'Subscription #%s cancelled', 'invoicing' ), |
|
488 | + $subscription->get_id() |
|
489 | + ) |
|
490 | + ); |
|
491 | + } |
|
492 | + } |
|
493 | + } |
|
494 | + |
|
495 | + // Add notice. |
|
496 | + $this->show_success( __( 'Invoice refunded successfully.', 'invoicing' ) ); |
|
497 | + |
|
498 | + // Redirect. |
|
499 | + wp_safe_redirect( |
|
500 | + remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id', 'getpaid_cancel_subscription', 'getpaid_refund_remote' ) ) |
|
501 | + ); |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | 505 | * Sends a payment reminder to a customer. |
506 | - * |
|
507 | - * @param array $args |
|
506 | + * |
|
507 | + * @param array $args |
|
508 | 508 | */ |
509 | 509 | public function duplicate_payment_form( $args ) { |
510 | 510 | |
511 | - if ( empty( $args['form_id'] ) ) { |
|
512 | - return; |
|
513 | - } |
|
514 | - |
|
515 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
511 | + if ( empty( $args['form_id'] ) ) { |
|
512 | + return; |
|
513 | + } |
|
516 | 514 | |
517 | - if ( ! $form->exists() ) { |
|
518 | - return; |
|
519 | - } |
|
515 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
520 | 516 | |
521 | - $new_form = new GetPaid_Payment_Form(); |
|
522 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
523 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
524 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
525 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
526 | - $new_form->save(); |
|
517 | + if ( ! $form->exists() ) { |
|
518 | + return; |
|
519 | + } |
|
527 | 520 | |
528 | - if ( $new_form->exists() ) { |
|
529 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
530 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
531 | - } else { |
|
532 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
533 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
534 | - } |
|
521 | + $new_form = new GetPaid_Payment_Form(); |
|
522 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
523 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
524 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
525 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
526 | + $new_form->save(); |
|
527 | + |
|
528 | + if ( $new_form->exists() ) { |
|
529 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
530 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
531 | + } else { |
|
532 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
533 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
534 | + } |
|
535 | 535 | |
536 | - wp_redirect( $url ); |
|
537 | - exit; |
|
538 | - } |
|
536 | + wp_redirect( $url ); |
|
537 | + exit; |
|
538 | + } |
|
539 | 539 | |
540 | - /** |
|
540 | + /** |
|
541 | 541 | * Resets form stats. |
542 | - * |
|
543 | - * @param array $args |
|
542 | + * |
|
543 | + * @param array $args |
|
544 | 544 | */ |
545 | 545 | public function reset_form_stats( $args ) { |
546 | 546 | |
547 | - if ( empty( $args['form_id'] ) ) { |
|
548 | - return; |
|
549 | - } |
|
547 | + if ( empty( $args['form_id'] ) ) { |
|
548 | + return; |
|
549 | + } |
|
550 | 550 | |
551 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
551 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
552 | 552 | |
553 | - if ( ! $form->exists() ) { |
|
554 | - return; |
|
555 | - } |
|
553 | + if ( ! $form->exists() ) { |
|
554 | + return; |
|
555 | + } |
|
556 | 556 | |
557 | - $form->set_earned( 0 ); |
|
558 | - $form->set_refunded( 0 ); |
|
559 | - $form->set_cancelled( 0 ); |
|
560 | - $form->set_failed( 0 ); |
|
561 | - $form->save(); |
|
557 | + $form->set_earned( 0 ); |
|
558 | + $form->set_refunded( 0 ); |
|
559 | + $form->set_cancelled( 0 ); |
|
560 | + $form->set_failed( 0 ); |
|
561 | + $form->save(); |
|
562 | 562 | |
563 | - $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
563 | + $this->show_success( __( 'Form stats reset successfully', 'invoicing' ) ); |
|
564 | 564 | |
565 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
566 | - exit; |
|
567 | - } |
|
565 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ) ); |
|
566 | + exit; |
|
567 | + } |
|
568 | 568 | |
569 | - /** |
|
569 | + /** |
|
570 | 570 | * Sends a payment reminder to a customer. |
571 | - * |
|
572 | - * @param array $args |
|
571 | + * |
|
572 | + * @param array $args |
|
573 | 573 | */ |
574 | 574 | public function send_customer_invoice( $args ) { |
575 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
576 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
577 | - exit; |
|
578 | - } |
|
575 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
576 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
577 | + exit; |
|
578 | + } |
|
579 | 579 | |
580 | - /** |
|
580 | + /** |
|
581 | 581 | * Sends a payment reminder to a customer. |
582 | - * |
|
583 | - * @param array $args |
|
582 | + * |
|
583 | + * @param array $args |
|
584 | 584 | */ |
585 | 585 | public function send_customer_payment_reminder( $args ) { |
586 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
586 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
587 | 587 | |
588 | - if ( $sent ) { |
|
589 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
590 | - } else { |
|
591 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
592 | - } |
|
588 | + if ( $sent ) { |
|
589 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
590 | + } else { |
|
591 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
592 | + } |
|
593 | 593 | |
594 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
595 | - exit; |
|
596 | - } |
|
594 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
595 | + exit; |
|
596 | + } |
|
597 | 597 | |
598 | - /** |
|
598 | + /** |
|
599 | 599 | * Resets tax rates. |
600 | - * |
|
600 | + * |
|
601 | 601 | */ |
602 | 602 | public function admin_reset_tax_rates() { |
603 | 603 | |
604 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
605 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
606 | - exit; |
|
604 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
605 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
606 | + exit; |
|
607 | 607 | |
608 | - } |
|
608 | + } |
|
609 | 609 | |
610 | - /** |
|
610 | + /** |
|
611 | 611 | * Resets admin pages. |
612 | - * |
|
612 | + * |
|
613 | 613 | */ |
614 | 614 | public function admin_create_missing_pages() { |
615 | - $installer = new GetPaid_Installer(); |
|
616 | - $installer->create_pages(); |
|
617 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
618 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
619 | - exit; |
|
620 | - } |
|
621 | - |
|
622 | - /** |
|
623 | - * Refreshes the permalinks. |
|
624 | - */ |
|
625 | - public function admin_refresh_permalinks() { |
|
626 | - flush_rewrite_rules(); |
|
627 | - $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
628 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
629 | - exit; |
|
630 | - } |
|
631 | - |
|
632 | - /** |
|
615 | + $installer = new GetPaid_Installer(); |
|
616 | + $installer->create_pages(); |
|
617 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
618 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
619 | + exit; |
|
620 | + } |
|
621 | + |
|
622 | + /** |
|
623 | + * Refreshes the permalinks. |
|
624 | + */ |
|
625 | + public function admin_refresh_permalinks() { |
|
626 | + flush_rewrite_rules(); |
|
627 | + $this->show_success( __( 'Permalinks refreshed.', 'invoicing' ) ); |
|
628 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
629 | + exit; |
|
630 | + } |
|
631 | + |
|
632 | + /** |
|
633 | 633 | * Creates missing admin tables. |
634 | - * |
|
634 | + * |
|
635 | 635 | */ |
636 | 636 | public function admin_create_missing_tables() { |
637 | - global $wpdb; |
|
637 | + global $wpdb; |
|
638 | 638 | |
639 | - GetPaid_Installer::create_db_tables(); |
|
640 | - GetPaid_Installer::migrate_old_customers(); |
|
639 | + GetPaid_Installer::create_db_tables(); |
|
640 | + GetPaid_Installer::migrate_old_customers(); |
|
641 | 641 | |
642 | - if ( '' !== $wpdb->last_error ) { |
|
643 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
644 | - } else { |
|
645 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
646 | - } |
|
642 | + if ( '' !== $wpdb->last_error ) { |
|
643 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
644 | + } else { |
|
645 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
646 | + } |
|
647 | 647 | |
648 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
649 | - exit; |
|
650 | - } |
|
648 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
649 | + exit; |
|
650 | + } |
|
651 | 651 | |
652 | - /** |
|
652 | + /** |
|
653 | 653 | * Migrates old invoices to the new database tables. |
654 | - * |
|
654 | + * |
|
655 | 655 | */ |
656 | 656 | public function admin_migrate_old_invoices() { |
657 | 657 | |
658 | - // Migrate the invoices. |
|
659 | - $installer = new GetPaid_Installer(); |
|
660 | - $installer->migrate_old_invoices(); |
|
658 | + // Migrate the invoices. |
|
659 | + $installer = new GetPaid_Installer(); |
|
660 | + $installer->migrate_old_invoices(); |
|
661 | 661 | |
662 | - // Show an admin message. |
|
663 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
662 | + // Show an admin message. |
|
663 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
664 | 664 | |
665 | - // Redirect the admin. |
|
666 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
667 | - exit; |
|
665 | + // Redirect the admin. |
|
666 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
667 | + exit; |
|
668 | 668 | |
669 | - } |
|
669 | + } |
|
670 | 670 | |
671 | - /** |
|
671 | + /** |
|
672 | 672 | * Download customers. |
673 | - * |
|
673 | + * |
|
674 | 674 | */ |
675 | 675 | public function admin_download_customers() { |
676 | 676 | |
677 | - $output = fopen( 'php://output', 'w' ); |
|
677 | + $output = fopen( 'php://output', 'w' ); |
|
678 | 678 | |
679 | - if ( false === $output ) { |
|
680 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
681 | - } |
|
679 | + if ( false === $output ) { |
|
680 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
681 | + } |
|
682 | 682 | |
683 | - header( 'Content-Type:text/csv' ); |
|
684 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
683 | + header( 'Content-Type:text/csv' ); |
|
684 | + header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
685 | 685 | |
686 | - /** @var GetPaid_Customer[] $customers */ |
|
687 | - $customers = getpaid_get_customers( array( 'number' => -1 ) ); |
|
688 | - $columns = array_keys( GetPaid_Customer_Data_Store::get_database_fields() ); |
|
686 | + /** @var GetPaid_Customer[] $customers */ |
|
687 | + $customers = getpaid_get_customers( array( 'number' => -1 ) ); |
|
688 | + $columns = array_keys( GetPaid_Customer_Data_Store::get_database_fields() ); |
|
689 | 689 | |
690 | - // Output the csv column headers. |
|
691 | - fputcsv( $output, $columns ); |
|
690 | + // Output the csv column headers. |
|
691 | + fputcsv( $output, $columns ); |
|
692 | 692 | |
693 | - // Loop through |
|
694 | - foreach ( $customers as $customer ) { |
|
693 | + // Loop through |
|
694 | + foreach ( $customers as $customer ) { |
|
695 | 695 | |
696 | - $row = array(); |
|
696 | + $row = array(); |
|
697 | 697 | |
698 | - foreach ( $columns as $column ) { |
|
699 | - $row[] = (string) maybe_serialize( $customer->get( $column, 'edit' ) ); |
|
700 | - } |
|
698 | + foreach ( $columns as $column ) { |
|
699 | + $row[] = (string) maybe_serialize( $customer->get( $column, 'edit' ) ); |
|
700 | + } |
|
701 | 701 | |
702 | - fputcsv( $output, $row ); |
|
703 | - } |
|
702 | + fputcsv( $output, $row ); |
|
703 | + } |
|
704 | 704 | |
705 | - fclose( $output ); |
|
706 | - exit; |
|
705 | + fclose( $output ); |
|
706 | + exit; |
|
707 | 707 | |
708 | - } |
|
708 | + } |
|
709 | 709 | |
710 | - /** |
|
710 | + /** |
|
711 | 711 | * Installs a plugin. |
712 | - * |
|
713 | - * @param array $data |
|
712 | + * |
|
713 | + * @param array $data |
|
714 | 714 | */ |
715 | 715 | public function admin_install_plugin( $data ) { |
716 | 716 | |
717 | - if ( ! empty( $data['plugins'] ) ) { |
|
718 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
719 | - wp_cache_flush(); |
|
717 | + if ( ! empty( $data['plugins'] ) ) { |
|
718 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
719 | + wp_cache_flush(); |
|
720 | 720 | |
721 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
722 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
723 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
724 | - $installed = $upgrader->install( $plugin_zip ); |
|
721 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
722 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
723 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
724 | + $installed = $upgrader->install( $plugin_zip ); |
|
725 | 725 | |
726 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
727 | - activate_plugin( $file, '', false, true ); |
|
728 | - } else { |
|
729 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
730 | - } |
|
726 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
727 | + activate_plugin( $file, '', false, true ); |
|
728 | + } else { |
|
729 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
730 | + } |
|
731 | 731 | } |
732 | 732 | } |
733 | 733 | |
734 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
735 | - wp_safe_redirect( $redirect ); |
|
736 | - exit; |
|
734 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
735 | + wp_safe_redirect( $redirect ); |
|
736 | + exit; |
|
737 | 737 | |
738 | - } |
|
738 | + } |
|
739 | 739 | |
740 | - /** |
|
740 | + /** |
|
741 | 741 | * Connects a gateway. |
742 | - * |
|
743 | - * @param array $data |
|
742 | + * |
|
743 | + * @param array $data |
|
744 | 744 | */ |
745 | 745 | public function admin_connect_gateway( $data ) { |
746 | 746 | |
747 | - if ( ! empty( $data['plugin'] ) ) { |
|
747 | + if ( ! empty( $data['plugin'] ) ) { |
|
748 | 748 | |
749 | - $gateway = sanitize_key( $data['plugin'] ); |
|
750 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
749 | + $gateway = sanitize_key( $data['plugin'] ); |
|
750 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
751 | 751 | |
752 | - if ( ! empty( $connect_url ) ) { |
|
753 | - wp_redirect( $connect_url ); |
|
754 | - exit; |
|
755 | - } |
|
752 | + if ( ! empty( $connect_url ) ) { |
|
753 | + wp_redirect( $connect_url ); |
|
754 | + exit; |
|
755 | + } |
|
756 | 756 | |
757 | - if ( 'stripe' == $data['plugin'] ) { |
|
758 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
759 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
760 | - wp_cache_flush(); |
|
757 | + if ( 'stripe' == $data['plugin'] ) { |
|
758 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
759 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
760 | + wp_cache_flush(); |
|
761 | 761 | |
762 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
763 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
764 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
765 | - $upgrader->install( $plugin_zip ); |
|
766 | - } |
|
762 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
763 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
764 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
765 | + $upgrader->install( $plugin_zip ); |
|
766 | + } |
|
767 | 767 | |
768 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
769 | - } |
|
768 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
769 | + } |
|
770 | 770 | |
771 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
772 | - if ( ! empty( $connect_url ) ) { |
|
773 | - wp_redirect( $connect_url ); |
|
774 | - exit; |
|
775 | - } |
|
771 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
772 | + if ( ! empty( $connect_url ) ) { |
|
773 | + wp_redirect( $connect_url ); |
|
774 | + exit; |
|
775 | + } |
|
776 | 776 | } |
777 | 777 | |
778 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
779 | - wp_safe_redirect( $redirect ); |
|
780 | - exit; |
|
778 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
779 | + wp_safe_redirect( $redirect ); |
|
780 | + exit; |
|
781 | 781 | |
782 | - } |
|
782 | + } |
|
783 | 783 | |
784 | - /** |
|
784 | + /** |
|
785 | 785 | * Recalculates discounts. |
786 | - * |
|
786 | + * |
|
787 | 787 | */ |
788 | 788 | public function admin_recalculate_discounts() { |
789 | - global $wpdb; |
|
789 | + global $wpdb; |
|
790 | 790 | |
791 | - // Fetch all invoices that have discount codes. |
|
792 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
793 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
791 | + // Fetch all invoices that have discount codes. |
|
792 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
793 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
794 | 794 | |
795 | - foreach ( $invoices as $invoice ) { |
|
795 | + foreach ( $invoices as $invoice ) { |
|
796 | 796 | |
797 | - $invoice = new WPInv_Invoice( $invoice ); |
|
797 | + $invoice = new WPInv_Invoice( $invoice ); |
|
798 | 798 | |
799 | - if ( ! $invoice->exists() ) { |
|
800 | - continue; |
|
801 | - } |
|
799 | + if ( ! $invoice->exists() ) { |
|
800 | + continue; |
|
801 | + } |
|
802 | 802 | |
803 | - // Abort if the discount does not exist or does not apply here. |
|
804 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
805 | - if ( ! $discount->exists() ) { |
|
806 | - continue; |
|
807 | - } |
|
803 | + // Abort if the discount does not exist or does not apply here. |
|
804 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
805 | + if ( ! $discount->exists() ) { |
|
806 | + continue; |
|
807 | + } |
|
808 | 808 | |
809 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
810 | - $invoice->recalculate_total(); |
|
809 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
810 | + $invoice->recalculate_total(); |
|
811 | 811 | |
812 | - if ( $invoice->get_total_discount() > 0 ) { |
|
813 | - $invoice->save(); |
|
814 | - } |
|
812 | + if ( $invoice->get_total_discount() > 0 ) { |
|
813 | + $invoice->save(); |
|
814 | + } |
|
815 | 815 | } |
816 | 816 | |
817 | - // Show an admin message. |
|
818 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
817 | + // Show an admin message. |
|
818 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
819 | 819 | |
820 | - // Redirect the admin. |
|
821 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
822 | - exit; |
|
820 | + // Redirect the admin. |
|
821 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
822 | + exit; |
|
823 | 823 | |
824 | - } |
|
824 | + } |
|
825 | 825 | |
826 | 826 | /** |
827 | - * Returns an array of admin notices. |
|
828 | - * |
|
829 | - * @since 1.0.19 |
|
827 | + * Returns an array of admin notices. |
|
828 | + * |
|
829 | + * @since 1.0.19 |
|
830 | 830 | * @return array |
831 | - */ |
|
832 | - public function get_notices() { |
|
833 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
831 | + */ |
|
832 | + public function get_notices() { |
|
833 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
834 | 834 | return is_array( $notices ) ? $notices : array(); |
835 | - } |
|
835 | + } |
|
836 | 836 | |
837 | - /** |
|
838 | - * Checks if we have any admin notices. |
|
839 | - * |
|
840 | - * @since 2.0.4 |
|
837 | + /** |
|
838 | + * Checks if we have any admin notices. |
|
839 | + * |
|
840 | + * @since 2.0.4 |
|
841 | 841 | * @return array |
842 | - */ |
|
843 | - public function has_notices() { |
|
844 | - return count( $this->get_notices() ) > 0; |
|
845 | - } |
|
846 | - |
|
847 | - /** |
|
848 | - * Clears all admin notices |
|
849 | - * |
|
850 | - * @access public |
|
851 | - * @since 1.0.19 |
|
852 | - */ |
|
853 | - public function clear_notices() { |
|
854 | - delete_option( 'wpinv_admin_notices' ); |
|
855 | - } |
|
856 | - |
|
857 | - /** |
|
858 | - * Saves a new admin notice |
|
859 | - * |
|
860 | - * @access public |
|
861 | - * @since 1.0.19 |
|
862 | - */ |
|
863 | - public function save_notice( $type, $message ) { |
|
864 | - $notices = $this->get_notices(); |
|
865 | - |
|
866 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
867 | - $notices[ $type ] = array(); |
|
868 | - } |
|
869 | - |
|
870 | - $notices[ $type ][] = $message; |
|
871 | - |
|
872 | - update_option( 'wpinv_admin_notices', $notices ); |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * Displays a success notice |
|
877 | - * |
|
878 | - * @param string $msg The message to qeue. |
|
879 | - * @access public |
|
880 | - * @since 1.0.19 |
|
881 | - */ |
|
882 | - public function show_success( $msg ) { |
|
883 | - $this->save_notice( 'success', $msg ); |
|
884 | - } |
|
885 | - |
|
886 | - /** |
|
887 | - * Displays a error notice |
|
888 | - * |
|
889 | - * @access public |
|
890 | - * @param string $msg The message to qeue. |
|
891 | - * @since 1.0.19 |
|
892 | - */ |
|
893 | - public function show_error( $msg ) { |
|
894 | - $this->save_notice( 'error', $msg ); |
|
895 | - } |
|
896 | - |
|
897 | - /** |
|
898 | - * Displays a warning notice |
|
899 | - * |
|
900 | - * @access public |
|
901 | - * @param string $msg The message to qeue. |
|
902 | - * @since 1.0.19 |
|
903 | - */ |
|
904 | - public function show_warning( $msg ) { |
|
905 | - $this->save_notice( 'warning', $msg ); |
|
906 | - } |
|
907 | - |
|
908 | - /** |
|
909 | - * Displays a info notice |
|
910 | - * |
|
911 | - * @access public |
|
912 | - * @param string $msg The message to qeue. |
|
913 | - * @since 1.0.19 |
|
914 | - */ |
|
915 | - public function show_info( $msg ) { |
|
916 | - $this->save_notice( 'info', $msg ); |
|
917 | - } |
|
918 | - |
|
919 | - /** |
|
920 | - * Show notices |
|
921 | - * |
|
922 | - * @access public |
|
923 | - * @since 1.0.19 |
|
924 | - */ |
|
925 | - public function show_notices() { |
|
842 | + */ |
|
843 | + public function has_notices() { |
|
844 | + return count( $this->get_notices() ) > 0; |
|
845 | + } |
|
846 | + |
|
847 | + /** |
|
848 | + * Clears all admin notices |
|
849 | + * |
|
850 | + * @access public |
|
851 | + * @since 1.0.19 |
|
852 | + */ |
|
853 | + public function clear_notices() { |
|
854 | + delete_option( 'wpinv_admin_notices' ); |
|
855 | + } |
|
856 | + |
|
857 | + /** |
|
858 | + * Saves a new admin notice |
|
859 | + * |
|
860 | + * @access public |
|
861 | + * @since 1.0.19 |
|
862 | + */ |
|
863 | + public function save_notice( $type, $message ) { |
|
864 | + $notices = $this->get_notices(); |
|
865 | + |
|
866 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
867 | + $notices[ $type ] = array(); |
|
868 | + } |
|
869 | + |
|
870 | + $notices[ $type ][] = $message; |
|
871 | + |
|
872 | + update_option( 'wpinv_admin_notices', $notices ); |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * Displays a success notice |
|
877 | + * |
|
878 | + * @param string $msg The message to qeue. |
|
879 | + * @access public |
|
880 | + * @since 1.0.19 |
|
881 | + */ |
|
882 | + public function show_success( $msg ) { |
|
883 | + $this->save_notice( 'success', $msg ); |
|
884 | + } |
|
885 | + |
|
886 | + /** |
|
887 | + * Displays a error notice |
|
888 | + * |
|
889 | + * @access public |
|
890 | + * @param string $msg The message to qeue. |
|
891 | + * @since 1.0.19 |
|
892 | + */ |
|
893 | + public function show_error( $msg ) { |
|
894 | + $this->save_notice( 'error', $msg ); |
|
895 | + } |
|
896 | + |
|
897 | + /** |
|
898 | + * Displays a warning notice |
|
899 | + * |
|
900 | + * @access public |
|
901 | + * @param string $msg The message to qeue. |
|
902 | + * @since 1.0.19 |
|
903 | + */ |
|
904 | + public function show_warning( $msg ) { |
|
905 | + $this->save_notice( 'warning', $msg ); |
|
906 | + } |
|
907 | + |
|
908 | + /** |
|
909 | + * Displays a info notice |
|
910 | + * |
|
911 | + * @access public |
|
912 | + * @param string $msg The message to qeue. |
|
913 | + * @since 1.0.19 |
|
914 | + */ |
|
915 | + public function show_info( $msg ) { |
|
916 | + $this->save_notice( 'info', $msg ); |
|
917 | + } |
|
918 | + |
|
919 | + /** |
|
920 | + * Show notices |
|
921 | + * |
|
922 | + * @access public |
|
923 | + * @since 1.0.19 |
|
924 | + */ |
|
925 | + public function show_notices() { |
|
926 | 926 | |
927 | 927 | $notices = $this->get_notices(); |
928 | 928 | $this->clear_notices(); |
929 | 929 | |
930 | - foreach ( $notices as $type => $messages ) { |
|
930 | + foreach ( $notices as $type => $messages ) { |
|
931 | 931 | |
932 | - if ( ! is_array( $messages ) ) { |
|
933 | - continue; |
|
934 | - } |
|
932 | + if ( ! is_array( $messages ) ) { |
|
933 | + continue; |
|
934 | + } |
|
935 | 935 | |
936 | 936 | $type = esc_attr( $type ); |
937 | - foreach ( $messages as $message ) { |
|
938 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
937 | + foreach ( $messages as $message ) { |
|
938 | + echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
939 | 939 | } |
940 | 940 | } |
941 | 941 | |
942 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
943 | - |
|
944 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
945 | - $url = wp_nonce_url( |
|
946 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
947 | - 'getpaid-nonce', |
|
948 | - 'getpaid-nonce' |
|
949 | - ); |
|
950 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
951 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
952 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
953 | - break; |
|
954 | - } |
|
942 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
943 | + |
|
944 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
945 | + $url = wp_nonce_url( |
|
946 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
947 | + 'getpaid-nonce', |
|
948 | + 'getpaid-nonce' |
|
949 | + ); |
|
950 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
951 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
952 | + echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
953 | + break; |
|
954 | + } |
|
955 | 955 | } |
956 | 956 | |
957 | - } |
|
957 | + } |
|
958 | 958 | |
959 | 959 | } |