@@ -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 ( ! empty( $subscription->id ) ) { |
|
80 | - $this->set_id( $subscription->id ); |
|
81 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_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 ( ! empty( $subscription->id ) ) { |
|
80 | + $this->set_id( $subscription->id ); |
|
81 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_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,34 +141,34 @@ 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 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
162 | - } |
|
158 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
159 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
160 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
161 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
164 | + /** |
|
165 | 165 | * Checks if a subscription key is set. |
166 | 166 | */ |
167 | 167 | public function _isset( $key ) { |
168 | 168 | return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | - /* |
|
171 | + /* |
|
172 | 172 | |-------------------------------------------------------------------------- |
173 | 173 | | CRUD methods |
174 | 174 | |-------------------------------------------------------------------------- |
@@ -177,57 +177,57 @@ discard block |
||
177 | 177 | | |
178 | 178 | */ |
179 | 179 | |
180 | - /* |
|
180 | + /* |
|
181 | 181 | |-------------------------------------------------------------------------- |
182 | 182 | | Getters |
183 | 183 | |-------------------------------------------------------------------------- |
184 | 184 | */ |
185 | 185 | |
186 | - /** |
|
187 | - * Get customer id. |
|
188 | - * |
|
189 | - * @since 1.0.19 |
|
190 | - * @param string $context View or edit context. |
|
191 | - * @return int |
|
192 | - */ |
|
193 | - public function get_customer_id( $context = 'view' ) { |
|
194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Get customer information. |
|
199 | - * |
|
200 | - * @since 1.0.19 |
|
201 | - * @param string $context View or edit context. |
|
202 | - * @return WP_User|false WP_User object on success, false on failure. |
|
203 | - */ |
|
204 | - public function get_customer( $context = 'view' ) { |
|
205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Get parent invoice id. |
|
210 | - * |
|
211 | - * @since 1.0.19 |
|
212 | - * @param string $context View or edit context. |
|
213 | - * @return int |
|
214 | - */ |
|
215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Alias for self::get_parent_invoice_id(). |
|
221 | - * |
|
222 | - * @since 1.0.19 |
|
223 | - * @param string $context View or edit context. |
|
224 | - * @return int |
|
225 | - */ |
|
186 | + /** |
|
187 | + * Get customer id. |
|
188 | + * |
|
189 | + * @since 1.0.19 |
|
190 | + * @param string $context View or edit context. |
|
191 | + * @return int |
|
192 | + */ |
|
193 | + public function get_customer_id( $context = 'view' ) { |
|
194 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Get customer information. |
|
199 | + * |
|
200 | + * @since 1.0.19 |
|
201 | + * @param string $context View or edit context. |
|
202 | + * @return WP_User|false WP_User object on success, false on failure. |
|
203 | + */ |
|
204 | + public function get_customer( $context = 'view' ) { |
|
205 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Get parent invoice id. |
|
210 | + * |
|
211 | + * @since 1.0.19 |
|
212 | + * @param string $context View or edit context. |
|
213 | + * @return int |
|
214 | + */ |
|
215 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
216 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Alias for self::get_parent_invoice_id(). |
|
221 | + * |
|
222 | + * @since 1.0.19 |
|
223 | + * @param string $context View or edit context. |
|
224 | + * @return int |
|
225 | + */ |
|
226 | 226 | public function get_parent_payment_id( $context = 'view' ) { |
227 | 227 | return $this->get_parent_invoice_id( $context ); |
228 | - } |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
230 | + /** |
|
231 | 231 | * Alias for self::get_parent_invoice_id(). |
232 | 232 | * |
233 | 233 | * @since 1.0.0 |
@@ -237,390 +237,390 @@ discard block |
||
237 | 237 | return $this->get_parent_invoice_id( $context ); |
238 | 238 | } |
239 | 239 | |
240 | - /** |
|
241 | - * Get parent invoice. |
|
242 | - * |
|
243 | - * @since 1.0.19 |
|
244 | - * @param string $context View or edit context. |
|
245 | - * @return WPInv_Invoice |
|
246 | - */ |
|
247 | - public function get_parent_invoice( $context = 'view' ) { |
|
248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Alias for self::get_parent_invoice(). |
|
253 | - * |
|
254 | - * @since 1.0.19 |
|
255 | - * @param string $context View or edit context. |
|
256 | - * @return WPInv_Invoice |
|
257 | - */ |
|
240 | + /** |
|
241 | + * Get parent invoice. |
|
242 | + * |
|
243 | + * @since 1.0.19 |
|
244 | + * @param string $context View or edit context. |
|
245 | + * @return WPInv_Invoice |
|
246 | + */ |
|
247 | + public function get_parent_invoice( $context = 'view' ) { |
|
248 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Alias for self::get_parent_invoice(). |
|
253 | + * |
|
254 | + * @since 1.0.19 |
|
255 | + * @param string $context View or edit context. |
|
256 | + * @return WPInv_Invoice |
|
257 | + */ |
|
258 | 258 | public function get_parent_payment( $context = 'view' ) { |
259 | 259 | return $this->get_parent_invoice( $context ); |
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Get subscription's product id. |
|
264 | - * |
|
265 | - * @since 1.0.19 |
|
266 | - * @param string $context View or edit context. |
|
267 | - * @return int |
|
268 | - */ |
|
269 | - public function get_product_id( $context = 'view' ) { |
|
270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Get the subscription product. |
|
275 | - * |
|
276 | - * @since 1.0.19 |
|
277 | - * @param string $context View or edit context. |
|
278 | - * @return WPInv_Item |
|
279 | - */ |
|
280 | - public function get_product( $context = 'view' ) { |
|
281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Get parent invoice's gateway. |
|
286 | - * |
|
287 | - * Here for backwards compatibility. |
|
288 | - * |
|
289 | - * @since 1.0.19 |
|
290 | - * @param string $context View or edit context. |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - public function get_gateway( $context = 'view' ) { |
|
294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Get the period of a renewal. |
|
299 | - * |
|
300 | - * @since 1.0.19 |
|
301 | - * @param string $context View or edit context. |
|
302 | - * @return string |
|
303 | - */ |
|
304 | - public function get_period( $context = 'view' ) { |
|
305 | - return $this->get_prop( 'period', $context ); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Get number of periods each renewal is valid for. |
|
310 | - * |
|
311 | - * @since 1.0.19 |
|
312 | - * @param string $context View or edit context. |
|
313 | - * @return int |
|
314 | - */ |
|
315 | - public function get_frequency( $context = 'view' ) { |
|
316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Get the initial amount for the subscription. |
|
321 | - * |
|
322 | - * @since 1.0.19 |
|
323 | - * @param string $context View or edit context. |
|
324 | - * @return float |
|
325 | - */ |
|
326 | - public function get_initial_amount( $context = 'view' ) { |
|
327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Get the recurring amount for the subscription. |
|
332 | - * |
|
333 | - * @since 1.0.19 |
|
334 | - * @param string $context View or edit context. |
|
335 | - * @return float |
|
336 | - */ |
|
337 | - public function get_recurring_amount( $context = 'view' ) { |
|
338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Get number of times that this subscription can be renewed. |
|
343 | - * |
|
344 | - * @since 1.0.19 |
|
345 | - * @param string $context View or edit context. |
|
346 | - * @return int |
|
347 | - */ |
|
348 | - public function get_bill_times( $context = 'view' ) { |
|
349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Get transaction id of this subscription's parent invoice. |
|
354 | - * |
|
355 | - * @since 1.0.19 |
|
356 | - * @param string $context View or edit context. |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function get_transaction_id( $context = 'view' ) { |
|
360 | - return $this->get_prop( 'transaction_id', $context ); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Get the date that the subscription was created. |
|
365 | - * |
|
366 | - * @since 1.0.19 |
|
367 | - * @param string $context View or edit context. |
|
368 | - * @return string |
|
369 | - */ |
|
370 | - public function get_created( $context = 'view' ) { |
|
371 | - return $this->get_prop( 'created', $context ); |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Alias for self::get_created(). |
|
376 | - * |
|
377 | - * @since 1.0.19 |
|
378 | - * @param string $context View or edit context. |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - public function get_date_created( $context = 'view' ) { |
|
382 | - return $this->get_created( $context ); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Retrieves the creation date in a timestamp |
|
387 | - * |
|
388 | - * @since 1.0.0 |
|
389 | - * @return int |
|
390 | - */ |
|
391 | - public function get_time_created() { |
|
392 | - $created = $this->get_date_created(); |
|
393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * Get GMT date when the subscription was created. |
|
398 | - * |
|
399 | - * @since 1.0.19 |
|
400 | - * @param string $context View or edit context. |
|
401 | - * @return string |
|
402 | - */ |
|
403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Get subscription's product id. |
|
264 | + * |
|
265 | + * @since 1.0.19 |
|
266 | + * @param string $context View or edit context. |
|
267 | + * @return int |
|
268 | + */ |
|
269 | + public function get_product_id( $context = 'view' ) { |
|
270 | + return (int) $this->get_prop( 'product_id', $context ); |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Get the subscription product. |
|
275 | + * |
|
276 | + * @since 1.0.19 |
|
277 | + * @param string $context View or edit context. |
|
278 | + * @return WPInv_Item |
|
279 | + */ |
|
280 | + public function get_product( $context = 'view' ) { |
|
281 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Get parent invoice's gateway. |
|
286 | + * |
|
287 | + * Here for backwards compatibility. |
|
288 | + * |
|
289 | + * @since 1.0.19 |
|
290 | + * @param string $context View or edit context. |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + public function get_gateway( $context = 'view' ) { |
|
294 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Get the period of a renewal. |
|
299 | + * |
|
300 | + * @since 1.0.19 |
|
301 | + * @param string $context View or edit context. |
|
302 | + * @return string |
|
303 | + */ |
|
304 | + public function get_period( $context = 'view' ) { |
|
305 | + return $this->get_prop( 'period', $context ); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Get number of periods each renewal is valid for. |
|
310 | + * |
|
311 | + * @since 1.0.19 |
|
312 | + * @param string $context View or edit context. |
|
313 | + * @return int |
|
314 | + */ |
|
315 | + public function get_frequency( $context = 'view' ) { |
|
316 | + return (int) $this->get_prop( 'frequency', $context ); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Get the initial amount for the subscription. |
|
321 | + * |
|
322 | + * @since 1.0.19 |
|
323 | + * @param string $context View or edit context. |
|
324 | + * @return float |
|
325 | + */ |
|
326 | + public function get_initial_amount( $context = 'view' ) { |
|
327 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Get the recurring amount for the subscription. |
|
332 | + * |
|
333 | + * @since 1.0.19 |
|
334 | + * @param string $context View or edit context. |
|
335 | + * @return float |
|
336 | + */ |
|
337 | + public function get_recurring_amount( $context = 'view' ) { |
|
338 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Get number of times that this subscription can be renewed. |
|
343 | + * |
|
344 | + * @since 1.0.19 |
|
345 | + * @param string $context View or edit context. |
|
346 | + * @return int |
|
347 | + */ |
|
348 | + public function get_bill_times( $context = 'view' ) { |
|
349 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Get transaction id of this subscription's parent invoice. |
|
354 | + * |
|
355 | + * @since 1.0.19 |
|
356 | + * @param string $context View or edit context. |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function get_transaction_id( $context = 'view' ) { |
|
360 | + return $this->get_prop( 'transaction_id', $context ); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Get the date that the subscription was created. |
|
365 | + * |
|
366 | + * @since 1.0.19 |
|
367 | + * @param string $context View or edit context. |
|
368 | + * @return string |
|
369 | + */ |
|
370 | + public function get_created( $context = 'view' ) { |
|
371 | + return $this->get_prop( 'created', $context ); |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Alias for self::get_created(). |
|
376 | + * |
|
377 | + * @since 1.0.19 |
|
378 | + * @param string $context View or edit context. |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + public function get_date_created( $context = 'view' ) { |
|
382 | + return $this->get_created( $context ); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Retrieves the creation date in a timestamp |
|
387 | + * |
|
388 | + * @since 1.0.0 |
|
389 | + * @return int |
|
390 | + */ |
|
391 | + public function get_time_created() { |
|
392 | + $created = $this->get_date_created(); |
|
393 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * Get GMT date when the subscription was created. |
|
398 | + * |
|
399 | + * @since 1.0.19 |
|
400 | + * @param string $context View or edit context. |
|
401 | + * @return string |
|
402 | + */ |
|
403 | + public function get_date_created_gmt( $context = 'view' ) { |
|
404 | 404 | $date = $this->get_date_created( $context ); |
405 | 405 | |
406 | 406 | if ( $date ) { |
407 | 407 | $date = get_gmt_from_date( $date ); |
408 | 408 | } |
409 | - return $date; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Get the date that the subscription will renew. |
|
414 | - * |
|
415 | - * @since 1.0.19 |
|
416 | - * @param string $context View or edit context. |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'expiration', $context ); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Alias for self::get_next_renewal_date(). |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - * @param string $context View or edit context. |
|
428 | - * @return string |
|
429 | - */ |
|
430 | - public function get_expiration( $context = 'view' ) { |
|
431 | - return $this->get_next_renewal_date( $context ); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Retrieves the expiration date in a timestamp |
|
436 | - * |
|
437 | - * @since 1.0.0 |
|
438 | - * @return int |
|
439 | - */ |
|
440 | - public function get_expiration_time() { |
|
441 | - $expiration = $this->get_expiration(); |
|
442 | - |
|
443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
444 | - return current_time( 'timestamp' ); |
|
445 | - } |
|
446 | - |
|
447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Get GMT date when the subscription will renew. |
|
453 | - * |
|
454 | - * @since 1.0.19 |
|
455 | - * @param string $context View or edit context. |
|
456 | - * @return string |
|
457 | - */ |
|
458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
409 | + return $date; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Get the date that the subscription will renew. |
|
414 | + * |
|
415 | + * @since 1.0.19 |
|
416 | + * @param string $context View or edit context. |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + public function get_next_renewal_date( $context = 'view' ) { |
|
420 | + return $this->get_prop( 'expiration', $context ); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Alias for self::get_next_renewal_date(). |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + * @param string $context View or edit context. |
|
428 | + * @return string |
|
429 | + */ |
|
430 | + public function get_expiration( $context = 'view' ) { |
|
431 | + return $this->get_next_renewal_date( $context ); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Retrieves the expiration date in a timestamp |
|
436 | + * |
|
437 | + * @since 1.0.0 |
|
438 | + * @return int |
|
439 | + */ |
|
440 | + public function get_expiration_time() { |
|
441 | + $expiration = $this->get_expiration(); |
|
442 | + |
|
443 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
444 | + return current_time( 'timestamp' ); |
|
445 | + } |
|
446 | + |
|
447 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
448 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Get GMT date when the subscription will renew. |
|
453 | + * |
|
454 | + * @since 1.0.19 |
|
455 | + * @param string $context View or edit context. |
|
456 | + * @return string |
|
457 | + */ |
|
458 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
459 | 459 | $date = $this->get_next_renewal_date( $context ); |
460 | 460 | |
461 | 461 | if ( $date ) { |
462 | 462 | $date = get_gmt_from_date( $date ); |
463 | 463 | } |
464 | - return $date; |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Get the subscription's trial period. |
|
469 | - * |
|
470 | - * @since 1.0.19 |
|
471 | - * @param string $context View or edit context. |
|
472 | - * @return string |
|
473 | - */ |
|
474 | - public function get_trial_period( $context = 'view' ) { |
|
475 | - return $this->get_prop( 'trial_period', $context ); |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * Get the subscription's status. |
|
480 | - * |
|
481 | - * @since 1.0.19 |
|
482 | - * @param string $context View or edit context. |
|
483 | - * @return string |
|
484 | - */ |
|
485 | - public function get_status( $context = 'view' ) { |
|
486 | - return $this->get_prop( 'status', $context ); |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Get the subscription's profile id. |
|
491 | - * |
|
492 | - * @since 1.0.19 |
|
493 | - * @param string $context View or edit context. |
|
494 | - * @return string |
|
495 | - */ |
|
496 | - public function get_profile_id( $context = 'view' ) { |
|
497 | - return $this->get_prop( 'profile_id', $context ); |
|
498 | - } |
|
499 | - |
|
500 | - /* |
|
464 | + return $date; |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Get the subscription's trial period. |
|
469 | + * |
|
470 | + * @since 1.0.19 |
|
471 | + * @param string $context View or edit context. |
|
472 | + * @return string |
|
473 | + */ |
|
474 | + public function get_trial_period( $context = 'view' ) { |
|
475 | + return $this->get_prop( 'trial_period', $context ); |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * Get the subscription's status. |
|
480 | + * |
|
481 | + * @since 1.0.19 |
|
482 | + * @param string $context View or edit context. |
|
483 | + * @return string |
|
484 | + */ |
|
485 | + public function get_status( $context = 'view' ) { |
|
486 | + return $this->get_prop( 'status', $context ); |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Get the subscription's profile id. |
|
491 | + * |
|
492 | + * @since 1.0.19 |
|
493 | + * @param string $context View or edit context. |
|
494 | + * @return string |
|
495 | + */ |
|
496 | + public function get_profile_id( $context = 'view' ) { |
|
497 | + return $this->get_prop( 'profile_id', $context ); |
|
498 | + } |
|
499 | + |
|
500 | + /* |
|
501 | 501 | |-------------------------------------------------------------------------- |
502 | 502 | | Setters |
503 | 503 | |-------------------------------------------------------------------------- |
504 | 504 | */ |
505 | 505 | |
506 | - /** |
|
507 | - * Set customer id. |
|
508 | - * |
|
509 | - * @since 1.0.19 |
|
510 | - * @param int $value The customer's id. |
|
511 | - */ |
|
512 | - public function set_customer_id( $value ) { |
|
513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * Set parent invoice id. |
|
518 | - * |
|
519 | - * @since 1.0.19 |
|
520 | - * @param int $value The parent invoice id. |
|
521 | - */ |
|
522 | - public function set_parent_invoice_id( $value ) { |
|
523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Alias for self::set_parent_invoice_id(). |
|
528 | - * |
|
529 | - * @since 1.0.19 |
|
530 | - * @param int $value The parent invoice id. |
|
531 | - */ |
|
506 | + /** |
|
507 | + * Set customer id. |
|
508 | + * |
|
509 | + * @since 1.0.19 |
|
510 | + * @param int $value The customer's id. |
|
511 | + */ |
|
512 | + public function set_customer_id( $value ) { |
|
513 | + $this->set_prop( 'customer_id', (int) $value ); |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * Set parent invoice id. |
|
518 | + * |
|
519 | + * @since 1.0.19 |
|
520 | + * @param int $value The parent invoice id. |
|
521 | + */ |
|
522 | + public function set_parent_invoice_id( $value ) { |
|
523 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Alias for self::set_parent_invoice_id(). |
|
528 | + * |
|
529 | + * @since 1.0.19 |
|
530 | + * @param int $value The parent invoice id. |
|
531 | + */ |
|
532 | 532 | public function set_parent_payment_id( $value ) { |
533 | 533 | $this->set_parent_invoice_id( $value ); |
534 | - } |
|
534 | + } |
|
535 | 535 | |
536 | - /** |
|
536 | + /** |
|
537 | 537 | * Alias for self::set_parent_invoice_id(). |
538 | 538 | * |
539 | 539 | * @since 1.0.19 |
540 | - * @param int $value The parent invoice id. |
|
540 | + * @param int $value The parent invoice id. |
|
541 | 541 | */ |
542 | 542 | public function set_original_payment_id( $value ) { |
543 | 543 | $this->set_parent_invoice_id( $value ); |
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * Set subscription's product id. |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param int $value The subscription product id. |
|
551 | - */ |
|
552 | - public function set_product_id( $value ) { |
|
553 | - $this->set_prop( 'product_id', (int) $value ); |
|
554 | - } |
|
555 | - |
|
556 | - /** |
|
557 | - * Set the period of a renewal. |
|
558 | - * |
|
559 | - * @since 1.0.19 |
|
560 | - * @param string $value The renewal period. |
|
561 | - */ |
|
562 | - public function set_period( $value ) { |
|
563 | - $this->set_prop( 'period', $value ); |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Set number of periods each renewal is valid for. |
|
568 | - * |
|
569 | - * @since 1.0.19 |
|
570 | - * @param int $value The subscription frequency. |
|
571 | - */ |
|
572 | - public function set_frequency( $value ) { |
|
573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Set the initial amount for the subscription. |
|
579 | - * |
|
580 | - * @since 1.0.19 |
|
581 | - * @param float $value The initial subcription amount. |
|
582 | - */ |
|
583 | - public function set_initial_amount( $value ) { |
|
584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Set the recurring amount for the subscription. |
|
589 | - * |
|
590 | - * @since 1.0.19 |
|
591 | - * @param float $value The recurring subcription amount. |
|
592 | - */ |
|
593 | - public function set_recurring_amount( $value ) { |
|
594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Set number of times that this subscription can be renewed. |
|
599 | - * |
|
600 | - * @since 1.0.19 |
|
601 | - * @param int $value Bill times. |
|
602 | - */ |
|
603 | - public function set_bill_times( $value ) { |
|
604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
605 | - } |
|
606 | - |
|
607 | - /** |
|
608 | - * Get transaction id of this subscription's parent invoice. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @param string $value Bill times. |
|
612 | - */ |
|
613 | - public function set_transaction_id( $value ) { |
|
614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Set date when this subscription started. |
|
619 | - * |
|
620 | - * @since 1.0.19 |
|
621 | - * @param string $value strtotime compliant date. |
|
622 | - */ |
|
623 | - public function set_created( $value ) { |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * Set subscription's product id. |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param int $value The subscription product id. |
|
551 | + */ |
|
552 | + public function set_product_id( $value ) { |
|
553 | + $this->set_prop( 'product_id', (int) $value ); |
|
554 | + } |
|
555 | + |
|
556 | + /** |
|
557 | + * Set the period of a renewal. |
|
558 | + * |
|
559 | + * @since 1.0.19 |
|
560 | + * @param string $value The renewal period. |
|
561 | + */ |
|
562 | + public function set_period( $value ) { |
|
563 | + $this->set_prop( 'period', $value ); |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Set number of periods each renewal is valid for. |
|
568 | + * |
|
569 | + * @since 1.0.19 |
|
570 | + * @param int $value The subscription frequency. |
|
571 | + */ |
|
572 | + public function set_frequency( $value ) { |
|
573 | + $value = empty( $value ) ? 1 : (int) $value; |
|
574 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Set the initial amount for the subscription. |
|
579 | + * |
|
580 | + * @since 1.0.19 |
|
581 | + * @param float $value The initial subcription amount. |
|
582 | + */ |
|
583 | + public function set_initial_amount( $value ) { |
|
584 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Set the recurring amount for the subscription. |
|
589 | + * |
|
590 | + * @since 1.0.19 |
|
591 | + * @param float $value The recurring subcription amount. |
|
592 | + */ |
|
593 | + public function set_recurring_amount( $value ) { |
|
594 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Set number of times that this subscription can be renewed. |
|
599 | + * |
|
600 | + * @since 1.0.19 |
|
601 | + * @param int $value Bill times. |
|
602 | + */ |
|
603 | + public function set_bill_times( $value ) { |
|
604 | + $this->set_prop( 'bill_times', (int) $value ); |
|
605 | + } |
|
606 | + |
|
607 | + /** |
|
608 | + * Get transaction id of this subscription's parent invoice. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @param string $value Bill times. |
|
612 | + */ |
|
613 | + public function set_transaction_id( $value ) { |
|
614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Set date when this subscription started. |
|
619 | + * |
|
620 | + * @since 1.0.19 |
|
621 | + * @param string $value strtotime compliant date. |
|
622 | + */ |
|
623 | + public function set_created( $value ) { |
|
624 | 624 | $date = strtotime( $value ); |
625 | 625 | |
626 | 626 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -628,94 +628,94 @@ discard block |
||
628 | 628 | return; |
629 | 629 | } |
630 | 630 | |
631 | - $this->set_prop( 'created', '' ); |
|
631 | + $this->set_prop( 'created', '' ); |
|
632 | 632 | |
633 | - } |
|
633 | + } |
|
634 | 634 | |
635 | - /** |
|
636 | - * Alias for self::set_created(). |
|
637 | - * |
|
638 | - * @since 1.0.19 |
|
639 | - * @param string $value strtotime compliant date. |
|
640 | - */ |
|
641 | - public function set_date_created( $value ) { |
|
642 | - $this->set_created( $value ); |
|
635 | + /** |
|
636 | + * Alias for self::set_created(). |
|
637 | + * |
|
638 | + * @since 1.0.19 |
|
639 | + * @param string $value strtotime compliant date. |
|
640 | + */ |
|
641 | + public function set_date_created( $value ) { |
|
642 | + $this->set_created( $value ); |
|
643 | 643 | } |
644 | 644 | |
645 | - /** |
|
646 | - * Set the date that the subscription will renew. |
|
647 | - * |
|
648 | - * @since 1.0.19 |
|
649 | - * @param string $value strtotime compliant date. |
|
650 | - */ |
|
651 | - public function set_next_renewal_date( $value ) { |
|
652 | - $date = strtotime( $value ); |
|
645 | + /** |
|
646 | + * Set the date that the subscription will renew. |
|
647 | + * |
|
648 | + * @since 1.0.19 |
|
649 | + * @param string $value strtotime compliant date. |
|
650 | + */ |
|
651 | + public function set_next_renewal_date( $value ) { |
|
652 | + $date = strtotime( $value ); |
|
653 | 653 | |
654 | 654 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
655 | 655 | $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
656 | 656 | return; |
657 | - } |
|
658 | - |
|
659 | - $this->set_prop( 'expiration', '' ); |
|
660 | - |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * Alias for self::set_next_renewal_date(). |
|
665 | - * |
|
666 | - * @since 1.0.19 |
|
667 | - * @param string $value strtotime compliant date. |
|
668 | - */ |
|
669 | - public function set_expiration( $value ) { |
|
670 | - $this->set_next_renewal_date( $value ); |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * Set the subscription's trial period. |
|
675 | - * |
|
676 | - * @since 1.0.19 |
|
677 | - * @param string $value trial period e.g 1 year. |
|
678 | - */ |
|
679 | - public function set_trial_period( $value ) { |
|
680 | - $this->set_prop( 'trial_period', $value ); |
|
681 | - } |
|
682 | - |
|
683 | - /** |
|
684 | - * Set the subscription's status. |
|
685 | - * |
|
686 | - * @since 1.0.19 |
|
687 | - * @param string $new_status New subscription status. |
|
688 | - */ |
|
689 | - public function set_status( $new_status ) { |
|
690 | - |
|
691 | - // Abort if this is not a valid status; |
|
692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
693 | - return; |
|
694 | - } |
|
695 | - |
|
696 | - $old_status = $this->get_status(); |
|
697 | - $this->set_prop( 'status', $new_status ); |
|
698 | - |
|
699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
700 | - $this->status_transition = array( |
|
701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
702 | - 'to' => $new_status, |
|
703 | - ); |
|
704 | - } |
|
705 | - |
|
706 | - } |
|
707 | - |
|
708 | - /** |
|
709 | - * Set the subscription's (remote) profile id. |
|
710 | - * |
|
711 | - * @since 1.0.19 |
|
712 | - * @param string $value the remote profile id. |
|
713 | - */ |
|
714 | - public function set_profile_id( $value ) { |
|
715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
716 | - } |
|
717 | - |
|
718 | - /* |
|
657 | + } |
|
658 | + |
|
659 | + $this->set_prop( 'expiration', '' ); |
|
660 | + |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * Alias for self::set_next_renewal_date(). |
|
665 | + * |
|
666 | + * @since 1.0.19 |
|
667 | + * @param string $value strtotime compliant date. |
|
668 | + */ |
|
669 | + public function set_expiration( $value ) { |
|
670 | + $this->set_next_renewal_date( $value ); |
|
671 | + } |
|
672 | + |
|
673 | + /** |
|
674 | + * Set the subscription's trial period. |
|
675 | + * |
|
676 | + * @since 1.0.19 |
|
677 | + * @param string $value trial period e.g 1 year. |
|
678 | + */ |
|
679 | + public function set_trial_period( $value ) { |
|
680 | + $this->set_prop( 'trial_period', $value ); |
|
681 | + } |
|
682 | + |
|
683 | + /** |
|
684 | + * Set the subscription's status. |
|
685 | + * |
|
686 | + * @since 1.0.19 |
|
687 | + * @param string $new_status New subscription status. |
|
688 | + */ |
|
689 | + public function set_status( $new_status ) { |
|
690 | + |
|
691 | + // Abort if this is not a valid status; |
|
692 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
693 | + return; |
|
694 | + } |
|
695 | + |
|
696 | + $old_status = $this->get_status(); |
|
697 | + $this->set_prop( 'status', $new_status ); |
|
698 | + |
|
699 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
700 | + $this->status_transition = array( |
|
701 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
702 | + 'to' => $new_status, |
|
703 | + ); |
|
704 | + } |
|
705 | + |
|
706 | + } |
|
707 | + |
|
708 | + /** |
|
709 | + * Set the subscription's (remote) profile id. |
|
710 | + * |
|
711 | + * @since 1.0.19 |
|
712 | + * @param string $value the remote profile id. |
|
713 | + */ |
|
714 | + public function set_profile_id( $value ) { |
|
715 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
716 | + } |
|
717 | + |
|
718 | + /* |
|
719 | 719 | |-------------------------------------------------------------------------- |
720 | 720 | | Boolean methods |
721 | 721 | |-------------------------------------------------------------------------- |
@@ -724,55 +724,55 @@ discard block |
||
724 | 724 | | |
725 | 725 | */ |
726 | 726 | |
727 | - /** |
|
727 | + /** |
|
728 | 728 | * Checks if the subscription has a given status. |
729 | - * |
|
730 | - * @param string|array String or array of strings to check for. |
|
731 | - * @return bool |
|
729 | + * |
|
730 | + * @param string|array String or array of strings to check for. |
|
731 | + * @return bool |
|
732 | 732 | */ |
733 | 733 | public function has_status( $status ) { |
734 | 734 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
735 | - } |
|
735 | + } |
|
736 | 736 | |
737 | - /** |
|
737 | + /** |
|
738 | 738 | * Checks if the subscription has a trial period. |
739 | - * |
|
740 | - * @return bool |
|
739 | + * |
|
740 | + * @return bool |
|
741 | 741 | */ |
742 | 742 | public function has_trial_period() { |
743 | - $period = $this->get_trial_period(); |
|
743 | + $period = $this->get_trial_period(); |
|
744 | 744 | return ! empty( $period ); |
745 | - } |
|
746 | - |
|
747 | - /** |
|
748 | - * Is the subscription active? |
|
749 | - * |
|
750 | - * @return bool |
|
751 | - */ |
|
752 | - public function is_active() { |
|
753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
754 | - } |
|
755 | - |
|
756 | - /** |
|
757 | - * Is the subscription expired? |
|
758 | - * |
|
759 | - * @return bool |
|
760 | - */ |
|
761 | - public function is_expired() { |
|
762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
763 | - } |
|
764 | - |
|
765 | - /** |
|
766 | - * Is this the last renewals? |
|
767 | - * |
|
768 | - * @return bool |
|
769 | - */ |
|
770 | - public function is_last_renewal() { |
|
771 | - $max_bills = $this->get_bill_times(); |
|
772 | - return ! empty( $max_bills ) && $max_bills == $this->get_times_billed(); |
|
773 | - } |
|
774 | - |
|
775 | - /* |
|
745 | + } |
|
746 | + |
|
747 | + /** |
|
748 | + * Is the subscription active? |
|
749 | + * |
|
750 | + * @return bool |
|
751 | + */ |
|
752 | + public function is_active() { |
|
753 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * Is the subscription expired? |
|
758 | + * |
|
759 | + * @return bool |
|
760 | + */ |
|
761 | + public function is_expired() { |
|
762 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
763 | + } |
|
764 | + |
|
765 | + /** |
|
766 | + * Is this the last renewals? |
|
767 | + * |
|
768 | + * @return bool |
|
769 | + */ |
|
770 | + public function is_last_renewal() { |
|
771 | + $max_bills = $this->get_bill_times(); |
|
772 | + return ! empty( $max_bills ) && $max_bills == $this->get_times_billed(); |
|
773 | + } |
|
774 | + |
|
775 | + /* |
|
776 | 776 | |-------------------------------------------------------------------------- |
777 | 777 | | Additional methods |
778 | 778 | |-------------------------------------------------------------------------- |
@@ -781,27 +781,27 @@ discard block |
||
781 | 781 | | |
782 | 782 | */ |
783 | 783 | |
784 | - /** |
|
785 | - * Backwards compatibilty. |
|
786 | - */ |
|
787 | - public function create( $data = array() ) { |
|
784 | + /** |
|
785 | + * Backwards compatibilty. |
|
786 | + */ |
|
787 | + public function create( $data = array() ) { |
|
788 | 788 | |
789 | - // Set the properties. |
|
790 | - if ( is_array( $data ) ) { |
|
791 | - $this->set_props( $data ); |
|
792 | - } |
|
789 | + // Set the properties. |
|
790 | + if ( is_array( $data ) ) { |
|
791 | + $this->set_props( $data ); |
|
792 | + } |
|
793 | 793 | |
794 | - // Save the item. |
|
795 | - return $this->save(); |
|
794 | + // Save the item. |
|
795 | + return $this->save(); |
|
796 | 796 | |
797 | - } |
|
797 | + } |
|
798 | 798 | |
799 | - /** |
|
800 | - * Backwards compatibilty. |
|
801 | - */ |
|
802 | - public function update( $args = array() ) { |
|
803 | - return $this->create( $args ); |
|
804 | - } |
|
799 | + /** |
|
800 | + * Backwards compatibilty. |
|
801 | + */ |
|
802 | + public function update( $args = array() ) { |
|
803 | + return $this->create( $args ); |
|
804 | + } |
|
805 | 805 | |
806 | 806 | /** |
807 | 807 | * Retrieve renewal payments for a subscription |
@@ -811,15 +811,15 @@ discard block |
||
811 | 811 | */ |
812 | 812 | public function get_child_payments() { |
813 | 813 | return get_posts( |
814 | - array( |
|
815 | - 'post_parent' => $this->get_parent_payment_id(), |
|
816 | - 'numberposts' => -1, |
|
817 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
818 | - 'orderby' => 'ID', |
|
819 | - 'order' => 'DESC', |
|
820 | - 'post_type' => 'wpi_invoice' |
|
821 | - ) |
|
822 | - ); |
|
814 | + array( |
|
815 | + 'post_parent' => $this->get_parent_payment_id(), |
|
816 | + 'numberposts' => -1, |
|
817 | + 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
818 | + 'orderby' => 'ID', |
|
819 | + 'order' => 'DESC', |
|
820 | + 'post_type' => 'wpi_invoice' |
|
821 | + ) |
|
822 | + ); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | /** |
@@ -829,16 +829,16 @@ discard block |
||
829 | 829 | * @return int |
830 | 830 | */ |
831 | 831 | public function get_total_payments() { |
832 | - global $wpdb; |
|
832 | + global $wpdb; |
|
833 | 833 | |
834 | - $count = (int) $wpdb->get_var( |
|
835 | - $wpdb->prepare( |
|
836 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
837 | - $this->get_parent_invoice_id() |
|
838 | - ) |
|
839 | - ); |
|
834 | + $count = (int) $wpdb->get_var( |
|
835 | + $wpdb->prepare( |
|
836 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
837 | + $this->get_parent_invoice_id() |
|
838 | + ) |
|
839 | + ); |
|
840 | 840 | |
841 | - // Maybe include parent invoice. |
|
841 | + // Maybe include parent invoice. |
|
842 | 842 | if ( ! $this->has_status( 'pending' ) ) { |
843 | 843 | $count++; |
844 | 844 | } |
@@ -867,57 +867,57 @@ 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(); |
|
880 | + // Are we creating a new invoice? |
|
881 | + if ( empty( $invoice ) ) { |
|
882 | + $invoice = $this->create_payment(); |
|
883 | 883 | |
884 | - if ( empty( $invoice ) ) { |
|
885 | - return false; |
|
886 | - } |
|
884 | + if ( empty( $invoice ) ) { |
|
885 | + return false; |
|
886 | + } |
|
887 | 887 | |
888 | - $invoice->set_status( 'wpi-renewal' ); |
|
888 | + $invoice->set_status( 'wpi-renewal' ); |
|
889 | 889 | |
890 | - } |
|
890 | + } |
|
891 | 891 | |
892 | - // Maybe set a transaction id. |
|
893 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
894 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
895 | - } |
|
892 | + // Maybe set a transaction id. |
|
893 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
894 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
895 | + } |
|
896 | 896 | |
897 | - // Set the completed date. |
|
898 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
897 | + // Set the completed date. |
|
898 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
899 | 899 | |
900 | - // And the gateway. |
|
901 | - if ( ! empty( $args['gateway'] ) ) { |
|
902 | - $invoice->set_gateway( $args['gateway'] ); |
|
903 | - } |
|
900 | + // And the gateway. |
|
901 | + if ( ! empty( $args['gateway'] ) ) { |
|
902 | + $invoice->set_gateway( $args['gateway'] ); |
|
903 | + } |
|
904 | 904 | |
905 | - $invoice->save(); |
|
905 | + $invoice->save(); |
|
906 | 906 | |
907 | - if ( ! $invoice->get_id() ) { |
|
908 | - return 0; |
|
909 | - } |
|
907 | + if ( ! $invoice->get_id() ) { |
|
908 | + return 0; |
|
909 | + } |
|
910 | 910 | |
911 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
912 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
911 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
912 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
913 | 913 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
914 | 914 | |
915 | 915 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
916 | 916 | |
917 | 917 | return $invoice->get_id(); |
918 | - } |
|
918 | + } |
|
919 | 919 | |
920 | - /** |
|
920 | + /** |
|
921 | 921 | * Creates a new invoice and returns it. |
922 | 922 | * |
923 | 923 | * @since 1.0.19 |
@@ -925,104 +925,104 @@ discard block |
||
925 | 925 | */ |
926 | 926 | public function create_payment() { |
927 | 927 | |
928 | - $parent_invoice = $this->get_parent_payment(); |
|
929 | - |
|
930 | - if ( ! $parent_invoice->get_id() ) { |
|
931 | - return false; |
|
932 | - } |
|
933 | - |
|
934 | - // Duplicate the parent invoice. |
|
935 | - $invoice = new WPInv_Invoice(); |
|
936 | - $invoice->set_props( $parent_invoice->get_data() ); |
|
937 | - $invoice->set_id( 0 ); |
|
938 | - $invoice->set_items( $parent_invoice->get_items() ); |
|
939 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
940 | - $invoice->set_transaction_id( '' ); |
|
941 | - $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
942 | - $invoice->set_number( '' ); |
|
943 | - $invoice->set_completed_date( '' ); |
|
944 | - $invoice->set_status( 'wpi-pending' ); |
|
945 | - $invoice->recalculate_total(); |
|
946 | - $invoice->save(); |
|
947 | - |
|
948 | - return $invoice->get_id() ? $invoice : false; |
|
949 | - } |
|
950 | - |
|
951 | - /** |
|
952 | - * Renews or completes a subscription |
|
953 | - * |
|
954 | - * @since 1.0.0 |
|
955 | - * @return int The subscription's id |
|
956 | - */ |
|
957 | - public function renew() { |
|
958 | - |
|
959 | - // Complete subscription if applicable |
|
960 | - if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) { |
|
961 | - return $this->complete(); |
|
962 | - } |
|
963 | - |
|
964 | - // Calculate new expiration |
|
965 | - $frequency = $this->get_frequency(); |
|
966 | - $period = $this->get_period(); |
|
967 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
968 | - |
|
969 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
970 | - $this->set_status( 'active' ); |
|
971 | - return $this->save(); |
|
972 | - |
|
973 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
974 | - |
|
975 | - } |
|
976 | - |
|
977 | - /** |
|
978 | - * Marks a subscription as completed |
|
979 | - * |
|
980 | - * Subscription is completed when the number of payments matches the billing_times field |
|
981 | - * |
|
982 | - * @since 1.0.0 |
|
983 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
984 | - */ |
|
985 | - public function complete() { |
|
986 | - |
|
987 | - // Only mark a subscription as complete if it's not already cancelled. |
|
988 | - if ( $this->has_status( 'cancelled' ) ) { |
|
989 | - return false; |
|
990 | - } |
|
991 | - |
|
992 | - $this->set_status( 'completed' ); |
|
993 | - return $this->save(); |
|
994 | - |
|
995 | - } |
|
996 | - |
|
997 | - /** |
|
998 | - * Marks a subscription as expired |
|
999 | - * |
|
1000 | - * @since 1.0.0 |
|
1001 | - * @param bool $check_expiration |
|
1002 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1003 | - */ |
|
1004 | - public function expire( $check_expiration = false ) { |
|
1005 | - |
|
1006 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1007 | - // Do not mark as expired since real expiration date is in the future |
|
1008 | - return false; |
|
1009 | - } |
|
1010 | - |
|
1011 | - $this->set_status( 'expired' ); |
|
1012 | - return $this->save(); |
|
1013 | - |
|
1014 | - } |
|
1015 | - |
|
1016 | - /** |
|
1017 | - * Marks a subscription as failing |
|
1018 | - * |
|
1019 | - * @since 2.4.2 |
|
1020 | - * @return int Subscription id. |
|
1021 | - */ |
|
1022 | - public function failing() { |
|
1023 | - $this->set_status( 'failing' ); |
|
1024 | - return $this->save(); |
|
1025 | - } |
|
928 | + $parent_invoice = $this->get_parent_payment(); |
|
929 | + |
|
930 | + if ( ! $parent_invoice->get_id() ) { |
|
931 | + return false; |
|
932 | + } |
|
933 | + |
|
934 | + // Duplicate the parent invoice. |
|
935 | + $invoice = new WPInv_Invoice(); |
|
936 | + $invoice->set_props( $parent_invoice->get_data() ); |
|
937 | + $invoice->set_id( 0 ); |
|
938 | + $invoice->set_items( $parent_invoice->get_items() ); |
|
939 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
940 | + $invoice->set_transaction_id( '' ); |
|
941 | + $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
942 | + $invoice->set_number( '' ); |
|
943 | + $invoice->set_completed_date( '' ); |
|
944 | + $invoice->set_status( 'wpi-pending' ); |
|
945 | + $invoice->recalculate_total(); |
|
946 | + $invoice->save(); |
|
947 | + |
|
948 | + return $invoice->get_id() ? $invoice : false; |
|
949 | + } |
|
950 | + |
|
951 | + /** |
|
952 | + * Renews or completes a subscription |
|
953 | + * |
|
954 | + * @since 1.0.0 |
|
955 | + * @return int The subscription's id |
|
956 | + */ |
|
957 | + public function renew() { |
|
958 | + |
|
959 | + // Complete subscription if applicable |
|
960 | + if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) { |
|
961 | + return $this->complete(); |
|
962 | + } |
|
963 | + |
|
964 | + // Calculate new expiration |
|
965 | + $frequency = $this->get_frequency(); |
|
966 | + $period = $this->get_period(); |
|
967 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
968 | + |
|
969 | + $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
970 | + $this->set_status( 'active' ); |
|
971 | + return $this->save(); |
|
972 | + |
|
973 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
974 | + |
|
975 | + } |
|
976 | + |
|
977 | + /** |
|
978 | + * Marks a subscription as completed |
|
979 | + * |
|
980 | + * Subscription is completed when the number of payments matches the billing_times field |
|
981 | + * |
|
982 | + * @since 1.0.0 |
|
983 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
984 | + */ |
|
985 | + public function complete() { |
|
986 | + |
|
987 | + // Only mark a subscription as complete if it's not already cancelled. |
|
988 | + if ( $this->has_status( 'cancelled' ) ) { |
|
989 | + return false; |
|
990 | + } |
|
991 | + |
|
992 | + $this->set_status( 'completed' ); |
|
993 | + return $this->save(); |
|
994 | + |
|
995 | + } |
|
996 | + |
|
997 | + /** |
|
998 | + * Marks a subscription as expired |
|
999 | + * |
|
1000 | + * @since 1.0.0 |
|
1001 | + * @param bool $check_expiration |
|
1002 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1003 | + */ |
|
1004 | + public function expire( $check_expiration = false ) { |
|
1005 | + |
|
1006 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1007 | + // Do not mark as expired since real expiration date is in the future |
|
1008 | + return false; |
|
1009 | + } |
|
1010 | + |
|
1011 | + $this->set_status( 'expired' ); |
|
1012 | + return $this->save(); |
|
1013 | + |
|
1014 | + } |
|
1015 | + |
|
1016 | + /** |
|
1017 | + * Marks a subscription as failing |
|
1018 | + * |
|
1019 | + * @since 2.4.2 |
|
1020 | + * @return int Subscription id. |
|
1021 | + */ |
|
1022 | + public function failing() { |
|
1023 | + $this->set_status( 'failing' ); |
|
1024 | + return $this->save(); |
|
1025 | + } |
|
1026 | 1026 | |
1027 | 1027 | /** |
1028 | 1028 | * Marks a subscription as cancelled |
@@ -1031,19 +1031,19 @@ discard block |
||
1031 | 1031 | * @return int Subscription id. |
1032 | 1032 | */ |
1033 | 1033 | public function cancel() { |
1034 | - $this->set_status( 'cancelled' ); |
|
1035 | - return $this->save(); |
|
1034 | + $this->set_status( 'cancelled' ); |
|
1035 | + return $this->save(); |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | - /** |
|
1039 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1040 | - * |
|
1041 | - * @since 1.0.0 |
|
1042 | - * @return bool |
|
1043 | - */ |
|
1044 | - public function can_cancel() { |
|
1045 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1046 | - } |
|
1038 | + /** |
|
1039 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1040 | + * |
|
1041 | + * @since 1.0.0 |
|
1042 | + * @return bool |
|
1043 | + */ |
|
1044 | + public function can_cancel() { |
|
1045 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1046 | + } |
|
1047 | 1047 | |
1048 | 1048 | /** |
1049 | 1049 | * Returns an array of subscription statuses that can be cancelled |
@@ -1056,82 +1056,82 @@ discard block |
||
1056 | 1056 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
1057 | 1057 | } |
1058 | 1058 | |
1059 | - /** |
|
1060 | - * Retrieves the URL to cancel subscription |
|
1061 | - * |
|
1062 | - * @since 1.0.0 |
|
1063 | - * @return string |
|
1064 | - */ |
|
1065 | - public function get_cancel_url() { |
|
1066 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'subscription_cancel', 'sub_id' => $this->get_id() ) ), 'getpaid-nonce' ); |
|
1067 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1068 | - } |
|
1069 | - |
|
1070 | - /** |
|
1071 | - * Determines if subscription can be manually renewed |
|
1072 | - * |
|
1073 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
1074 | - * that can be renewed manually |
|
1075 | - * |
|
1076 | - * @since 2.5 |
|
1077 | - * @return bool |
|
1078 | - */ |
|
1079 | - public function can_renew() { |
|
1080 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1081 | - } |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * Retrieves the URL to renew a subscription |
|
1085 | - * |
|
1086 | - * @since 2.5 |
|
1087 | - * @return string |
|
1088 | - */ |
|
1089 | - public function get_renew_url() { |
|
1090 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
1091 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1092 | - } |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * Determines if subscription can have their payment method updated |
|
1096 | - * |
|
1097 | - * @since 1.0.0 |
|
1098 | - * @return bool |
|
1099 | - */ |
|
1100 | - public function can_update() { |
|
1101 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1102 | - } |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * Retrieves the URL to update subscription |
|
1106 | - * |
|
1107 | - * @since 1.0.0 |
|
1108 | - * @return string |
|
1109 | - */ |
|
1110 | - public function get_update_url() { |
|
1111 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1112 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1113 | - } |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * Retrieves the subscription status label |
|
1117 | - * |
|
1118 | - * @since 1.0.0 |
|
1119 | - * @return string |
|
1120 | - */ |
|
1121 | - public function get_status_label() { |
|
1122 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1123 | - } |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * Retrieves the subscription status class |
|
1127 | - * |
|
1128 | - * @since 1.0.19 |
|
1129 | - * @return string |
|
1130 | - */ |
|
1131 | - public function get_status_class() { |
|
1132 | - $statuses = getpaid_get_subscription_status_classes(); |
|
1133 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1134 | - } |
|
1059 | + /** |
|
1060 | + * Retrieves the URL to cancel subscription |
|
1061 | + * |
|
1062 | + * @since 1.0.0 |
|
1063 | + * @return string |
|
1064 | + */ |
|
1065 | + public function get_cancel_url() { |
|
1066 | + $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'subscription_cancel', 'sub_id' => $this->get_id() ) ), 'getpaid-nonce' ); |
|
1067 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1068 | + } |
|
1069 | + |
|
1070 | + /** |
|
1071 | + * Determines if subscription can be manually renewed |
|
1072 | + * |
|
1073 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
1074 | + * that can be renewed manually |
|
1075 | + * |
|
1076 | + * @since 2.5 |
|
1077 | + * @return bool |
|
1078 | + */ |
|
1079 | + public function can_renew() { |
|
1080 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1081 | + } |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * Retrieves the URL to renew a subscription |
|
1085 | + * |
|
1086 | + * @since 2.5 |
|
1087 | + * @return string |
|
1088 | + */ |
|
1089 | + public function get_renew_url() { |
|
1090 | + $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
1091 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1092 | + } |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * Determines if subscription can have their payment method updated |
|
1096 | + * |
|
1097 | + * @since 1.0.0 |
|
1098 | + * @return bool |
|
1099 | + */ |
|
1100 | + public function can_update() { |
|
1101 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1102 | + } |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * Retrieves the URL to update subscription |
|
1106 | + * |
|
1107 | + * @since 1.0.0 |
|
1108 | + * @return string |
|
1109 | + */ |
|
1110 | + public function get_update_url() { |
|
1111 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1112 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1113 | + } |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * Retrieves the subscription status label |
|
1117 | + * |
|
1118 | + * @since 1.0.0 |
|
1119 | + * @return string |
|
1120 | + */ |
|
1121 | + public function get_status_label() { |
|
1122 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1123 | + } |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * Retrieves the subscription status class |
|
1127 | + * |
|
1128 | + * @since 1.0.19 |
|
1129 | + * @return string |
|
1130 | + */ |
|
1131 | + public function get_status_class() { |
|
1132 | + $statuses = getpaid_get_subscription_status_classes(); |
|
1133 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1134 | + } |
|
1135 | 1135 | |
1136 | 1136 | /** |
1137 | 1137 | * Retrieves the subscription status label |
@@ -1141,11 +1141,11 @@ discard block |
||
1141 | 1141 | */ |
1142 | 1142 | public function get_status_label_html() { |
1143 | 1143 | |
1144 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1145 | - $class = esc_attr( $this->get_status_class() ); |
|
1146 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
1144 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1145 | + $class = esc_attr( $this->get_status_class() ); |
|
1146 | + $status = sanitize_html_class( $this->get_status_label() ); |
|
1147 | 1147 | |
1148 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
1148 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
1149 | 1149 | } |
1150 | 1150 | |
1151 | 1151 | /** |
@@ -1156,63 +1156,63 @@ discard block |
||
1156 | 1156 | * @return bool |
1157 | 1157 | */ |
1158 | 1158 | public function payment_exists( $txn_id = '' ) { |
1159 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1159 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1160 | 1160 | return ! empty( $invoice_id ); |
1161 | - } |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * Handle the status transition. |
|
1165 | - */ |
|
1166 | - protected function status_transition() { |
|
1167 | - $status_transition = $this->status_transition; |
|
1168 | - |
|
1169 | - // Reset status transition variable. |
|
1170 | - $this->status_transition = false; |
|
1171 | - |
|
1172 | - if ( $status_transition ) { |
|
1173 | - try { |
|
1174 | - |
|
1175 | - // Fire a hook for the status change. |
|
1176 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1177 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1178 | - |
|
1179 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1180 | - |
|
1181 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
1182 | - $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'] ) ); |
|
1183 | - |
|
1184 | - // Note the transition occurred. |
|
1185 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1186 | - |
|
1187 | - // Fire another hook. |
|
1188 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1189 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1190 | - |
|
1191 | - } else { |
|
1192 | - /* translators: %s: new invoice status */ |
|
1193 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1194 | - |
|
1195 | - // Note the transition occurred. |
|
1196 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1197 | - |
|
1198 | - } |
|
1199 | - } catch ( Exception $e ) { |
|
1200 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1201 | - } |
|
1202 | - } |
|
1203 | - |
|
1204 | - } |
|
1205 | - |
|
1206 | - /** |
|
1207 | - * Save data to the database. |
|
1208 | - * |
|
1209 | - * @since 1.0.19 |
|
1210 | - * @return int subscription ID |
|
1211 | - */ |
|
1212 | - public function save() { |
|
1213 | - parent::save(); |
|
1214 | - $this->status_transition(); |
|
1215 | - return $this->get_id(); |
|
1216 | - } |
|
1161 | + } |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * Handle the status transition. |
|
1165 | + */ |
|
1166 | + protected function status_transition() { |
|
1167 | + $status_transition = $this->status_transition; |
|
1168 | + |
|
1169 | + // Reset status transition variable. |
|
1170 | + $this->status_transition = false; |
|
1171 | + |
|
1172 | + if ( $status_transition ) { |
|
1173 | + try { |
|
1174 | + |
|
1175 | + // Fire a hook for the status change. |
|
1176 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1177 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1178 | + |
|
1179 | + if ( ! empty( $status_transition['from'] ) ) { |
|
1180 | + |
|
1181 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
1182 | + $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'] ) ); |
|
1183 | + |
|
1184 | + // Note the transition occurred. |
|
1185 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1186 | + |
|
1187 | + // Fire another hook. |
|
1188 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1189 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1190 | + |
|
1191 | + } else { |
|
1192 | + /* translators: %s: new invoice status */ |
|
1193 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1194 | + |
|
1195 | + // Note the transition occurred. |
|
1196 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1197 | + |
|
1198 | + } |
|
1199 | + } catch ( Exception $e ) { |
|
1200 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1201 | + } |
|
1202 | + } |
|
1203 | + |
|
1204 | + } |
|
1205 | + |
|
1206 | + /** |
|
1207 | + * Save data to the database. |
|
1208 | + * |
|
1209 | + * @since 1.0.19 |
|
1210 | + * @return int subscription ID |
|
1211 | + */ |
|
1212 | + public function save() { |
|
1213 | + parent::save(); |
|
1214 | + $this->status_transition(); |
|
1215 | + return $this->get_id(); |
|
1216 | + } |
|
1217 | 1217 | |
1218 | 1218 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * The Subscription Class |
@@ -68,27 +68,27 @@ discard block |
||
68 | 68 | * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
69 | 69 | * @param bool $deprecated |
70 | 70 | */ |
71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
71 | + function __construct($subscription = 0, $deprecated = false) { |
|
72 | 72 | |
73 | - parent::__construct( $subscription ); |
|
73 | + parent::__construct($subscription); |
|
74 | 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 ( ! empty( $subscription->id ) ) { |
|
80 | - $this->set_id( $subscription->id ); |
|
81 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
82 | - $this->set_id( $subscription_id ); |
|
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 (!empty($subscription->id)) { |
|
80 | + $this->set_id($subscription->id); |
|
81 | + } elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) { |
|
82 | + $this->set_id($subscription_id); |
|
83 | 83 | } else { |
84 | - $this->set_object_read( true ); |
|
84 | + $this->set_object_read(true); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | // Load the datastore. |
88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
88 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
89 | 89 | |
90 | - if ( $this->get_id() > 0 ) { |
|
91 | - $this->data_store->read( $this ); |
|
90 | + if ($this->get_id() > 0) { |
|
91 | + $this->data_store->read($this); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | } |
@@ -103,17 +103,17 @@ discard block |
||
103 | 103 | * @since 1.0.19 |
104 | 104 | * @return int |
105 | 105 | */ |
106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
106 | + public static function get_subscription_id_by_field($value, $field = 'profile_id') { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | 109 | // Trim the value. |
110 | - $value = trim( $value ); |
|
110 | + $value = trim($value); |
|
111 | 111 | |
112 | - if ( empty( $value ) ) { |
|
112 | + if (empty($value)) { |
|
113 | 113 | return 0; |
114 | 114 | } |
115 | 115 | |
116 | - if ( 'invoice_id' == $field ) { |
|
116 | + if ('invoice_id' == $field) { |
|
117 | 117 | $field = 'parent_payment_id'; |
118 | 118 | } |
119 | 119 | |
@@ -125,28 +125,28 @@ discard block |
||
125 | 125 | ); |
126 | 126 | |
127 | 127 | // Ensure a field has been passed. |
128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
128 | + if (empty($field) || !in_array($field, $fields)) { |
|
129 | 129 | return 0; |
130 | 130 | } |
131 | 131 | |
132 | 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 ) ) { |
|
133 | + $subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
134 | + if (!empty($subscription_id)) { |
|
135 | 135 | return $subscription_id; |
136 | 136 | } |
137 | 137 | |
138 | 138 | // Fetch from the db. |
139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
140 | 140 | $subscription_id = (int) $wpdb->get_var( |
141 | - $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
141 | + $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
142 | 142 | ); |
143 | 143 | |
144 | - if ( empty( $subscription_id ) ) { |
|
144 | + if (empty($subscription_id)) { |
|
145 | 145 | return 0; |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Update the cache with our data. |
149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
149 | + wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
150 | 150 | |
151 | 151 | return $subscription_id; |
152 | 152 | } |
@@ -155,17 +155,17 @@ discard block |
||
155 | 155 | * Clears the subscription's cache. |
156 | 156 | */ |
157 | 157 | public function clear_cache() { |
158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
158 | + wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids'); |
|
159 | + wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
160 | + wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
161 | + wp_cache_delete($this->get_id(), 'getpaid_subscriptions'); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * Checks if a subscription key is set. |
166 | 166 | */ |
167 | - public function _isset( $key ) { |
|
168 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
|
167 | + public function _isset($key) { |
|
168 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /* |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | * @param string $context View or edit context. |
191 | 191 | * @return int |
192 | 192 | */ |
193 | - public function get_customer_id( $context = 'view' ) { |
|
194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
193 | + public function get_customer_id($context = 'view') { |
|
194 | + return (int) $this->get_prop('customer_id', $context); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | * @param string $context View or edit context. |
202 | 202 | * @return WP_User|false WP_User object on success, false on failure. |
203 | 203 | */ |
204 | - public function get_customer( $context = 'view' ) { |
|
205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
204 | + public function get_customer($context = 'view') { |
|
205 | + return get_userdata($this->get_customer_id($context)); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | * @param string $context View or edit context. |
213 | 213 | * @return int |
214 | 214 | */ |
215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
215 | + public function get_parent_invoice_id($context = 'view') { |
|
216 | + return (int) $this->get_prop('parent_payment_id', $context); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * @param string $context View or edit context. |
224 | 224 | * @return int |
225 | 225 | */ |
226 | - public function get_parent_payment_id( $context = 'view' ) { |
|
227 | - return $this->get_parent_invoice_id( $context ); |
|
226 | + public function get_parent_payment_id($context = 'view') { |
|
227 | + return $this->get_parent_invoice_id($context); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * @since 1.0.0 |
234 | 234 | * @return int |
235 | 235 | */ |
236 | - public function get_original_payment_id( $context = 'view' ) { |
|
237 | - return $this->get_parent_invoice_id( $context ); |
|
236 | + public function get_original_payment_id($context = 'view') { |
|
237 | + return $this->get_parent_invoice_id($context); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @param string $context View or edit context. |
245 | 245 | * @return WPInv_Invoice |
246 | 246 | */ |
247 | - public function get_parent_invoice( $context = 'view' ) { |
|
248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
247 | + public function get_parent_invoice($context = 'view') { |
|
248 | + return new WPInv_Invoice($this->get_parent_invoice_id($context)); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | * @param string $context View or edit context. |
256 | 256 | * @return WPInv_Invoice |
257 | 257 | */ |
258 | - public function get_parent_payment( $context = 'view' ) { |
|
259 | - return $this->get_parent_invoice( $context ); |
|
258 | + public function get_parent_payment($context = 'view') { |
|
259 | + return $this->get_parent_invoice($context); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | * @param string $context View or edit context. |
267 | 267 | * @return int |
268 | 268 | */ |
269 | - public function get_product_id( $context = 'view' ) { |
|
270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
269 | + public function get_product_id($context = 'view') { |
|
270 | + return (int) $this->get_prop('product_id', $context); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * @param string $context View or edit context. |
278 | 278 | * @return WPInv_Item |
279 | 279 | */ |
280 | - public function get_product( $context = 'view' ) { |
|
281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
280 | + public function get_product($context = 'view') { |
|
281 | + return new WPInv_Item($this->get_product_id($context)); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | * @param string $context View or edit context. |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - public function get_gateway( $context = 'view' ) { |
|
294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
293 | + public function get_gateway($context = 'view') { |
|
294 | + return $this->get_parent_invoice($context)->get_gateway(); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | * @param string $context View or edit context. |
302 | 302 | * @return string |
303 | 303 | */ |
304 | - public function get_period( $context = 'view' ) { |
|
305 | - return $this->get_prop( 'period', $context ); |
|
304 | + public function get_period($context = 'view') { |
|
305 | + return $this->get_prop('period', $context); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | * @param string $context View or edit context. |
313 | 313 | * @return int |
314 | 314 | */ |
315 | - public function get_frequency( $context = 'view' ) { |
|
316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
315 | + public function get_frequency($context = 'view') { |
|
316 | + return (int) $this->get_prop('frequency', $context); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | * @param string $context View or edit context. |
324 | 324 | * @return float |
325 | 325 | */ |
326 | - public function get_initial_amount( $context = 'view' ) { |
|
327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
326 | + public function get_initial_amount($context = 'view') { |
|
327 | + return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context)); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | * @param string $context View or edit context. |
335 | 335 | * @return float |
336 | 336 | */ |
337 | - public function get_recurring_amount( $context = 'view' ) { |
|
338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
337 | + public function get_recurring_amount($context = 'view') { |
|
338 | + return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context)); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -345,8 +345,8 @@ discard block |
||
345 | 345 | * @param string $context View or edit context. |
346 | 346 | * @return int |
347 | 347 | */ |
348 | - public function get_bill_times( $context = 'view' ) { |
|
349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
348 | + public function get_bill_times($context = 'view') { |
|
349 | + return (int) $this->get_prop('bill_times', $context); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | * @param string $context View or edit context. |
357 | 357 | * @return string |
358 | 358 | */ |
359 | - public function get_transaction_id( $context = 'view' ) { |
|
360 | - return $this->get_prop( 'transaction_id', $context ); |
|
359 | + public function get_transaction_id($context = 'view') { |
|
360 | + return $this->get_prop('transaction_id', $context); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | * @param string $context View or edit context. |
368 | 368 | * @return string |
369 | 369 | */ |
370 | - public function get_created( $context = 'view' ) { |
|
371 | - return $this->get_prop( 'created', $context ); |
|
370 | + public function get_created($context = 'view') { |
|
371 | + return $this->get_prop('created', $context); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -378,8 +378,8 @@ discard block |
||
378 | 378 | * @param string $context View or edit context. |
379 | 379 | * @return string |
380 | 380 | */ |
381 | - public function get_date_created( $context = 'view' ) { |
|
382 | - return $this->get_created( $context ); |
|
381 | + public function get_date_created($context = 'view') { |
|
382 | + return $this->get_created($context); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | */ |
391 | 391 | public function get_time_created() { |
392 | 392 | $created = $this->get_date_created(); |
393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
393 | + return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp')); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -400,11 +400,11 @@ discard block |
||
400 | 400 | * @param string $context View or edit context. |
401 | 401 | * @return string |
402 | 402 | */ |
403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
404 | - $date = $this->get_date_created( $context ); |
|
403 | + public function get_date_created_gmt($context = 'view') { |
|
404 | + $date = $this->get_date_created($context); |
|
405 | 405 | |
406 | - if ( $date ) { |
|
407 | - $date = get_gmt_from_date( $date ); |
|
406 | + if ($date) { |
|
407 | + $date = get_gmt_from_date($date); |
|
408 | 408 | } |
409 | 409 | return $date; |
410 | 410 | } |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return string |
418 | 418 | */ |
419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'expiration', $context ); |
|
419 | + public function get_next_renewal_date($context = 'view') { |
|
420 | + return $this->get_prop('expiration', $context); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | * @param string $context View or edit context. |
428 | 428 | * @return string |
429 | 429 | */ |
430 | - public function get_expiration( $context = 'view' ) { |
|
431 | - return $this->get_next_renewal_date( $context ); |
|
430 | + public function get_expiration($context = 'view') { |
|
431 | + return $this->get_next_renewal_date($context); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -440,12 +440,12 @@ discard block |
||
440 | 440 | public function get_expiration_time() { |
441 | 441 | $expiration = $this->get_expiration(); |
442 | 442 | |
443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
444 | - return current_time( 'timestamp' ); |
|
443 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
444 | + return current_time('timestamp'); |
|
445 | 445 | } |
446 | 446 | |
447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
447 | + $expiration = strtotime($expiration, current_time('timestamp')); |
|
448 | + return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration; |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -455,11 +455,11 @@ discard block |
||
455 | 455 | * @param string $context View or edit context. |
456 | 456 | * @return string |
457 | 457 | */ |
458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
459 | - $date = $this->get_next_renewal_date( $context ); |
|
458 | + public function get_next_renewal_date_gmt($context = 'view') { |
|
459 | + $date = $this->get_next_renewal_date($context); |
|
460 | 460 | |
461 | - if ( $date ) { |
|
462 | - $date = get_gmt_from_date( $date ); |
|
461 | + if ($date) { |
|
462 | + $date = get_gmt_from_date($date); |
|
463 | 463 | } |
464 | 464 | return $date; |
465 | 465 | } |
@@ -471,8 +471,8 @@ discard block |
||
471 | 471 | * @param string $context View or edit context. |
472 | 472 | * @return string |
473 | 473 | */ |
474 | - public function get_trial_period( $context = 'view' ) { |
|
475 | - return $this->get_prop( 'trial_period', $context ); |
|
474 | + public function get_trial_period($context = 'view') { |
|
475 | + return $this->get_prop('trial_period', $context); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | /** |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | * @param string $context View or edit context. |
483 | 483 | * @return string |
484 | 484 | */ |
485 | - public function get_status( $context = 'view' ) { |
|
486 | - return $this->get_prop( 'status', $context ); |
|
485 | + public function get_status($context = 'view') { |
|
486 | + return $this->get_prop('status', $context); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,8 +493,8 @@ discard block |
||
493 | 493 | * @param string $context View or edit context. |
494 | 494 | * @return string |
495 | 495 | */ |
496 | - public function get_profile_id( $context = 'view' ) { |
|
497 | - return $this->get_prop( 'profile_id', $context ); |
|
496 | + public function get_profile_id($context = 'view') { |
|
497 | + return $this->get_prop('profile_id', $context); |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | /* |
@@ -509,8 +509,8 @@ discard block |
||
509 | 509 | * @since 1.0.19 |
510 | 510 | * @param int $value The customer's id. |
511 | 511 | */ |
512 | - public function set_customer_id( $value ) { |
|
513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
512 | + public function set_customer_id($value) { |
|
513 | + $this->set_prop('customer_id', (int) $value); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -519,8 +519,8 @@ discard block |
||
519 | 519 | * @since 1.0.19 |
520 | 520 | * @param int $value The parent invoice id. |
521 | 521 | */ |
522 | - public function set_parent_invoice_id( $value ) { |
|
523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
522 | + public function set_parent_invoice_id($value) { |
|
523 | + $this->set_prop('parent_payment_id', (int) $value); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | * @since 1.0.19 |
530 | 530 | * @param int $value The parent invoice id. |
531 | 531 | */ |
532 | - public function set_parent_payment_id( $value ) { |
|
533 | - $this->set_parent_invoice_id( $value ); |
|
532 | + public function set_parent_payment_id($value) { |
|
533 | + $this->set_parent_invoice_id($value); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | * @since 1.0.19 |
540 | 540 | * @param int $value The parent invoice id. |
541 | 541 | */ |
542 | - public function set_original_payment_id( $value ) { |
|
543 | - $this->set_parent_invoice_id( $value ); |
|
542 | + public function set_original_payment_id($value) { |
|
543 | + $this->set_parent_invoice_id($value); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | * @since 1.0.19 |
550 | 550 | * @param int $value The subscription product id. |
551 | 551 | */ |
552 | - public function set_product_id( $value ) { |
|
553 | - $this->set_prop( 'product_id', (int) $value ); |
|
552 | + public function set_product_id($value) { |
|
553 | + $this->set_prop('product_id', (int) $value); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | * @since 1.0.19 |
560 | 560 | * @param string $value The renewal period. |
561 | 561 | */ |
562 | - public function set_period( $value ) { |
|
563 | - $this->set_prop( 'period', $value ); |
|
562 | + public function set_period($value) { |
|
563 | + $this->set_prop('period', $value); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -569,9 +569,9 @@ discard block |
||
569 | 569 | * @since 1.0.19 |
570 | 570 | * @param int $value The subscription frequency. |
571 | 571 | */ |
572 | - public function set_frequency( $value ) { |
|
573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
572 | + public function set_frequency($value) { |
|
573 | + $value = empty($value) ? 1 : (int) $value; |
|
574 | + $this->set_prop('frequency', absint($value)); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -580,8 +580,8 @@ discard block |
||
580 | 580 | * @since 1.0.19 |
581 | 581 | * @param float $value The initial subcription amount. |
582 | 582 | */ |
583 | - public function set_initial_amount( $value ) { |
|
584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
583 | + public function set_initial_amount($value) { |
|
584 | + $this->set_prop('initial_amount', wpinv_sanitize_amount($value)); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -590,8 +590,8 @@ discard block |
||
590 | 590 | * @since 1.0.19 |
591 | 591 | * @param float $value The recurring subcription amount. |
592 | 592 | */ |
593 | - public function set_recurring_amount( $value ) { |
|
594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
593 | + public function set_recurring_amount($value) { |
|
594 | + $this->set_prop('recurring_amount', wpinv_sanitize_amount($value)); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -600,8 +600,8 @@ discard block |
||
600 | 600 | * @since 1.0.19 |
601 | 601 | * @param int $value Bill times. |
602 | 602 | */ |
603 | - public function set_bill_times( $value ) { |
|
604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
603 | + public function set_bill_times($value) { |
|
604 | + $this->set_prop('bill_times', (int) $value); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | /** |
@@ -610,8 +610,8 @@ discard block |
||
610 | 610 | * @since 1.0.19 |
611 | 611 | * @param string $value Bill times. |
612 | 612 | */ |
613 | - public function set_transaction_id( $value ) { |
|
614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
613 | + public function set_transaction_id($value) { |
|
614 | + $this->set_prop('transaction_id', sanitize_text_field($value)); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -620,15 +620,15 @@ discard block |
||
620 | 620 | * @since 1.0.19 |
621 | 621 | * @param string $value strtotime compliant date. |
622 | 622 | */ |
623 | - public function set_created( $value ) { |
|
624 | - $date = strtotime( $value ); |
|
623 | + public function set_created($value) { |
|
624 | + $date = strtotime($value); |
|
625 | 625 | |
626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
626 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
627 | + $this->set_prop('created', date('Y-m-d H:i:s', $date)); |
|
628 | 628 | return; |
629 | 629 | } |
630 | 630 | |
631 | - $this->set_prop( 'created', '' ); |
|
631 | + $this->set_prop('created', ''); |
|
632 | 632 | |
633 | 633 | } |
634 | 634 | |
@@ -638,8 +638,8 @@ discard block |
||
638 | 638 | * @since 1.0.19 |
639 | 639 | * @param string $value strtotime compliant date. |
640 | 640 | */ |
641 | - public function set_date_created( $value ) { |
|
642 | - $this->set_created( $value ); |
|
641 | + public function set_date_created($value) { |
|
642 | + $this->set_created($value); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | /** |
@@ -648,15 +648,15 @@ discard block |
||
648 | 648 | * @since 1.0.19 |
649 | 649 | * @param string $value strtotime compliant date. |
650 | 650 | */ |
651 | - public function set_next_renewal_date( $value ) { |
|
652 | - $date = strtotime( $value ); |
|
651 | + public function set_next_renewal_date($value) { |
|
652 | + $date = strtotime($value); |
|
653 | 653 | |
654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
654 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
655 | + $this->set_prop('expiration', date('Y-m-d H:i:s', $date)); |
|
656 | 656 | return; |
657 | 657 | } |
658 | 658 | |
659 | - $this->set_prop( 'expiration', '' ); |
|
659 | + $this->set_prop('expiration', ''); |
|
660 | 660 | |
661 | 661 | } |
662 | 662 | |
@@ -666,8 +666,8 @@ discard block |
||
666 | 666 | * @since 1.0.19 |
667 | 667 | * @param string $value strtotime compliant date. |
668 | 668 | */ |
669 | - public function set_expiration( $value ) { |
|
670 | - $this->set_next_renewal_date( $value ); |
|
669 | + public function set_expiration($value) { |
|
670 | + $this->set_next_renewal_date($value); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
@@ -676,8 +676,8 @@ discard block |
||
676 | 676 | * @since 1.0.19 |
677 | 677 | * @param string $value trial period e.g 1 year. |
678 | 678 | */ |
679 | - public function set_trial_period( $value ) { |
|
680 | - $this->set_prop( 'trial_period', $value ); |
|
679 | + public function set_trial_period($value) { |
|
680 | + $this->set_prop('trial_period', $value); |
|
681 | 681 | } |
682 | 682 | |
683 | 683 | /** |
@@ -686,19 +686,19 @@ discard block |
||
686 | 686 | * @since 1.0.19 |
687 | 687 | * @param string $new_status New subscription status. |
688 | 688 | */ |
689 | - public function set_status( $new_status ) { |
|
689 | + public function set_status($new_status) { |
|
690 | 690 | |
691 | 691 | // Abort if this is not a valid status; |
692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
692 | + if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) { |
|
693 | 693 | return; |
694 | 694 | } |
695 | 695 | |
696 | 696 | $old_status = $this->get_status(); |
697 | - $this->set_prop( 'status', $new_status ); |
|
697 | + $this->set_prop('status', $new_status); |
|
698 | 698 | |
699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
699 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
700 | 700 | $this->status_transition = array( |
701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
701 | + 'from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status, |
|
702 | 702 | 'to' => $new_status, |
703 | 703 | ); |
704 | 704 | } |
@@ -711,8 +711,8 @@ discard block |
||
711 | 711 | * @since 1.0.19 |
712 | 712 | * @param string $value the remote profile id. |
713 | 713 | */ |
714 | - public function set_profile_id( $value ) { |
|
715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
714 | + public function set_profile_id($value) { |
|
715 | + $this->set_prop('profile_id', sanitize_text_field($value)); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /* |
@@ -730,8 +730,8 @@ discard block |
||
730 | 730 | * @param string|array String or array of strings to check for. |
731 | 731 | * @return bool |
732 | 732 | */ |
733 | - public function has_status( $status ) { |
|
734 | - return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
|
733 | + public function has_status($status) { |
|
734 | + return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status))); |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | /** |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | */ |
742 | 742 | public function has_trial_period() { |
743 | 743 | $period = $this->get_trial_period(); |
744 | - return ! empty( $period ); |
|
744 | + return !empty($period); |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | /** |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | * @return bool |
751 | 751 | */ |
752 | 752 | public function is_active() { |
753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
753 | + return $this->has_status('active trialling') && !$this->is_expired(); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | /** |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | * @return bool |
760 | 760 | */ |
761 | 761 | public function is_expired() { |
762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
762 | + return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql')); |
|
763 | 763 | } |
764 | 764 | |
765 | 765 | /** |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | */ |
770 | 770 | public function is_last_renewal() { |
771 | 771 | $max_bills = $this->get_bill_times(); |
772 | - return ! empty( $max_bills ) && $max_bills == $this->get_times_billed(); |
|
772 | + return !empty($max_bills) && $max_bills == $this->get_times_billed(); |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | /* |
@@ -784,11 +784,11 @@ discard block |
||
784 | 784 | /** |
785 | 785 | * Backwards compatibilty. |
786 | 786 | */ |
787 | - public function create( $data = array() ) { |
|
787 | + public function create($data = array()) { |
|
788 | 788 | |
789 | 789 | // Set the properties. |
790 | - if ( is_array( $data ) ) { |
|
791 | - $this->set_props( $data ); |
|
790 | + if (is_array($data)) { |
|
791 | + $this->set_props($data); |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | // Save the item. |
@@ -799,8 +799,8 @@ discard block |
||
799 | 799 | /** |
800 | 800 | * Backwards compatibilty. |
801 | 801 | */ |
802 | - public function update( $args = array() ) { |
|
803 | - return $this->create( $args ); |
|
802 | + public function update($args = array()) { |
|
803 | + return $this->create($args); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | /** |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | array( |
815 | 815 | 'post_parent' => $this->get_parent_payment_id(), |
816 | 816 | 'numberposts' => -1, |
817 | - 'post_status' => array( 'publish', 'wpi-processing', 'wpi-renewal' ), |
|
817 | + 'post_status' => array('publish', 'wpi-processing', 'wpi-renewal'), |
|
818 | 818 | 'orderby' => 'ID', |
819 | 819 | 'order' => 'DESC', |
820 | 820 | 'post_type' => 'wpi_invoice' |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | ); |
840 | 840 | |
841 | 841 | // Maybe include parent invoice. |
842 | - if ( ! $this->has_status( 'pending' ) ) { |
|
842 | + if (!$this->has_status('pending')) { |
|
843 | 843 | $count++; |
844 | 844 | } |
845 | 845 | |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | public function get_times_billed() { |
856 | 856 | $times_billed = $this->get_total_payments(); |
857 | 857 | |
858 | - if ( $this->has_trial_period() && $times_billed > 0 ) { |
|
858 | + if ($this->has_trial_period() && $times_billed > 0) { |
|
859 | 859 | $times_billed--; |
860 | 860 | } |
861 | 861 | |
@@ -870,49 +870,49 @@ discard block |
||
870 | 870 | * @param WPInv_Invoice $invoice If adding an existing invoice. |
871 | 871 | * @return bool |
872 | 872 | */ |
873 | - public function add_payment( $args = array(), $invoice = false ) { |
|
873 | + public function add_payment($args = array(), $invoice = false) { |
|
874 | 874 | |
875 | 875 | // Process each payment once. |
876 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
876 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
877 | 877 | return false; |
878 | 878 | } |
879 | 879 | |
880 | 880 | // Are we creating a new invoice? |
881 | - if ( empty( $invoice ) ) { |
|
881 | + if (empty($invoice)) { |
|
882 | 882 | $invoice = $this->create_payment(); |
883 | 883 | |
884 | - if ( empty( $invoice ) ) { |
|
884 | + if (empty($invoice)) { |
|
885 | 885 | return false; |
886 | 886 | } |
887 | 887 | |
888 | - $invoice->set_status( 'wpi-renewal' ); |
|
888 | + $invoice->set_status('wpi-renewal'); |
|
889 | 889 | |
890 | 890 | } |
891 | 891 | |
892 | 892 | // Maybe set a transaction id. |
893 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
894 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
893 | + if (!empty($args['transaction_id'])) { |
|
894 | + $invoice->set_transaction_id($args['transaction_id']); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | // Set the completed date. |
898 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
898 | + $invoice->set_completed_date(current_time('mysql')); |
|
899 | 899 | |
900 | 900 | // And the gateway. |
901 | - if ( ! empty( $args['gateway'] ) ) { |
|
902 | - $invoice->set_gateway( $args['gateway'] ); |
|
901 | + if (!empty($args['gateway'])) { |
|
902 | + $invoice->set_gateway($args['gateway']); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | $invoice->save(); |
906 | 906 | |
907 | - if ( ! $invoice->get_id() ) { |
|
907 | + if (!$invoice->get_id()) { |
|
908 | 908 | return 0; |
909 | 909 | } |
910 | 910 | |
911 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
912 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
913 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
911 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
912 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
913 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
914 | 914 | |
915 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
915 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
916 | 916 | |
917 | 917 | return $invoice->get_id(); |
918 | 918 | } |
@@ -927,21 +927,21 @@ discard block |
||
927 | 927 | |
928 | 928 | $parent_invoice = $this->get_parent_payment(); |
929 | 929 | |
930 | - if ( ! $parent_invoice->get_id() ) { |
|
930 | + if (!$parent_invoice->get_id()) { |
|
931 | 931 | return false; |
932 | 932 | } |
933 | 933 | |
934 | 934 | // Duplicate the parent invoice. |
935 | 935 | $invoice = new WPInv_Invoice(); |
936 | - $invoice->set_props( $parent_invoice->get_data() ); |
|
937 | - $invoice->set_id( 0 ); |
|
938 | - $invoice->set_items( $parent_invoice->get_items() ); |
|
939 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
940 | - $invoice->set_transaction_id( '' ); |
|
941 | - $invoice->set_key( $invoice->generate_key( 'renewal_' ) ); |
|
942 | - $invoice->set_number( '' ); |
|
943 | - $invoice->set_completed_date( '' ); |
|
944 | - $invoice->set_status( 'wpi-pending' ); |
|
936 | + $invoice->set_props($parent_invoice->get_data()); |
|
937 | + $invoice->set_id(0); |
|
938 | + $invoice->set_items($parent_invoice->get_items()); |
|
939 | + $invoice->set_parent_id($parent_invoice->get_id()); |
|
940 | + $invoice->set_transaction_id(''); |
|
941 | + $invoice->set_key($invoice->generate_key('renewal_')); |
|
942 | + $invoice->set_number(''); |
|
943 | + $invoice->set_completed_date(''); |
|
944 | + $invoice->set_status('wpi-pending'); |
|
945 | 945 | $invoice->recalculate_total(); |
946 | 946 | $invoice->save(); |
947 | 947 | |
@@ -957,20 +957,20 @@ discard block |
||
957 | 957 | public function renew() { |
958 | 958 | |
959 | 959 | // Complete subscription if applicable |
960 | - if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) { |
|
960 | + if ($this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times()) { |
|
961 | 961 | return $this->complete(); |
962 | 962 | } |
963 | 963 | |
964 | 964 | // Calculate new expiration |
965 | 965 | $frequency = $this->get_frequency(); |
966 | 966 | $period = $this->get_period(); |
967 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
967 | + $new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time()); |
|
968 | 968 | |
969 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
970 | - $this->set_status( 'active' ); |
|
969 | + $this->set_expiration(date('Y-m-d H:i:s', $new_expiration)); |
|
970 | + $this->set_status('active'); |
|
971 | 971 | return $this->save(); |
972 | 972 | |
973 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
973 | + do_action('getpaid_subscription_renewed', $this); |
|
974 | 974 | |
975 | 975 | } |
976 | 976 | |
@@ -985,11 +985,11 @@ discard block |
||
985 | 985 | public function complete() { |
986 | 986 | |
987 | 987 | // Only mark a subscription as complete if it's not already cancelled. |
988 | - if ( $this->has_status( 'cancelled' ) ) { |
|
988 | + if ($this->has_status('cancelled')) { |
|
989 | 989 | return false; |
990 | 990 | } |
991 | 991 | |
992 | - $this->set_status( 'completed' ); |
|
992 | + $this->set_status('completed'); |
|
993 | 993 | return $this->save(); |
994 | 994 | |
995 | 995 | } |
@@ -1001,14 +1001,14 @@ discard block |
||
1001 | 1001 | * @param bool $check_expiration |
1002 | 1002 | * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
1003 | 1003 | */ |
1004 | - public function expire( $check_expiration = false ) { |
|
1004 | + public function expire($check_expiration = false) { |
|
1005 | 1005 | |
1006 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1006 | + if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) { |
|
1007 | 1007 | // Do not mark as expired since real expiration date is in the future |
1008 | 1008 | return false; |
1009 | 1009 | } |
1010 | 1010 | |
1011 | - $this->set_status( 'expired' ); |
|
1011 | + $this->set_status('expired'); |
|
1012 | 1012 | return $this->save(); |
1013 | 1013 | |
1014 | 1014 | } |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | * @return int Subscription id. |
1021 | 1021 | */ |
1022 | 1022 | public function failing() { |
1023 | - $this->set_status( 'failing' ); |
|
1023 | + $this->set_status('failing'); |
|
1024 | 1024 | return $this->save(); |
1025 | 1025 | } |
1026 | 1026 | |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | * @return int Subscription id. |
1032 | 1032 | */ |
1033 | 1033 | public function cancel() { |
1034 | - $this->set_status( 'cancelled' ); |
|
1034 | + $this->set_status('cancelled'); |
|
1035 | 1035 | return $this->save(); |
1036 | 1036 | } |
1037 | 1037 | |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | * @return bool |
1043 | 1043 | */ |
1044 | 1044 | public function can_cancel() { |
1045 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1045 | + return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | /** |
@@ -1053,7 +1053,7 @@ discard block |
||
1053 | 1053 | * @return array |
1054 | 1054 | */ |
1055 | 1055 | public function get_cancellable_statuses() { |
1056 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
1056 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | /** |
@@ -1063,8 +1063,8 @@ discard block |
||
1063 | 1063 | * @return string |
1064 | 1064 | */ |
1065 | 1065 | public function get_cancel_url() { |
1066 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'subscription_cancel', 'sub_id' => $this->get_id() ) ), 'getpaid-nonce' ); |
|
1067 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1066 | + $url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'subscription_cancel', 'sub_id' => $this->get_id())), 'getpaid-nonce'); |
|
1067 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | /** |
@@ -1077,7 +1077,7 @@ discard block |
||
1077 | 1077 | * @return bool |
1078 | 1078 | */ |
1079 | 1079 | public function can_renew() { |
1080 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1080 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | /** |
@@ -1087,8 +1087,8 @@ discard block |
||
1087 | 1087 | * @return string |
1088 | 1088 | */ |
1089 | 1089 | public function get_renew_url() { |
1090 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
1091 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1090 | + $url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'getpaid-nonce'); |
|
1091 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
1092 | 1092 | } |
1093 | 1093 | |
1094 | 1094 | /** |
@@ -1098,7 +1098,7 @@ discard block |
||
1098 | 1098 | * @return bool |
1099 | 1099 | */ |
1100 | 1100 | public function can_update() { |
1101 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1101 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | /** |
@@ -1108,8 +1108,8 @@ discard block |
||
1108 | 1108 | * @return string |
1109 | 1109 | */ |
1110 | 1110 | public function get_update_url() { |
1111 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1112 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1111 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id())); |
|
1112 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | /** |
@@ -1119,7 +1119,7 @@ discard block |
||
1119 | 1119 | * @return string |
1120 | 1120 | */ |
1121 | 1121 | public function get_status_label() { |
1122 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1122 | + return getpaid_get_subscription_status_label($this->get_status()); |
|
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | /** |
@@ -1130,7 +1130,7 @@ discard block |
||
1130 | 1130 | */ |
1131 | 1131 | public function get_status_class() { |
1132 | 1132 | $statuses = getpaid_get_subscription_status_classes(); |
1133 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1133 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'text-white bg-secondary'; |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | /** |
@@ -1141,9 +1141,9 @@ discard block |
||
1141 | 1141 | */ |
1142 | 1142 | public function get_status_label_html() { |
1143 | 1143 | |
1144 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1145 | - $class = esc_attr( $this->get_status_class() ); |
|
1146 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
1144 | + $status_label = sanitize_text_field($this->get_status_label()); |
|
1145 | + $class = esc_attr($this->get_status_class()); |
|
1146 | + $status = sanitize_html_class($this->get_status_label()); |
|
1147 | 1147 | |
1148 | 1148 | return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
1149 | 1149 | } |
@@ -1155,9 +1155,9 @@ discard block |
||
1155 | 1155 | * @param string $txn_id The transaction ID from the merchant processor |
1156 | 1156 | * @return bool |
1157 | 1157 | */ |
1158 | - public function payment_exists( $txn_id = '' ) { |
|
1159 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1160 | - return ! empty( $invoice_id ); |
|
1158 | + public function payment_exists($txn_id = '') { |
|
1159 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
1160 | + return !empty($invoice_id); |
|
1161 | 1161 | } |
1162 | 1162 | |
1163 | 1163 | /** |
@@ -1169,35 +1169,35 @@ discard block |
||
1169 | 1169 | // Reset status transition variable. |
1170 | 1170 | $this->status_transition = false; |
1171 | 1171 | |
1172 | - if ( $status_transition ) { |
|
1172 | + if ($status_transition) { |
|
1173 | 1173 | try { |
1174 | 1174 | |
1175 | 1175 | // Fire a hook for the status change. |
1176 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1177 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1176 | + do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
1177 | + do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition); |
|
1178 | 1178 | |
1179 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1179 | + if (!empty($status_transition['from'])) { |
|
1180 | 1180 | |
1181 | 1181 | /* translators: 1: old subscription status 2: new subscription status */ |
1182 | - $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'] ) ); |
|
1182 | + $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'])); |
|
1183 | 1183 | |
1184 | 1184 | // Note the transition occurred. |
1185 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1185 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
1186 | 1186 | |
1187 | 1187 | // Fire another hook. |
1188 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1189 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1188 | + do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
1189 | + do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']); |
|
1190 | 1190 | |
1191 | 1191 | } else { |
1192 | 1192 | /* translators: %s: new invoice status */ |
1193 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1193 | + $transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to'])); |
|
1194 | 1194 | |
1195 | 1195 | // Note the transition occurred. |
1196 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1196 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
1197 | 1197 | |
1198 | 1198 | } |
1199 | - } catch ( Exception $e ) { |
|
1200 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1199 | + } catch (Exception $e) { |
|
1200 | + $this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
1201 | 1201 | } |
1202 | 1202 | } |
1203 | 1203 |
@@ -16,495 +16,495 @@ |
||
16 | 16 | */ |
17 | 17 | class GetPaid_Subscriptions_Query { |
18 | 18 | |
19 | - /** |
|
20 | - * Query vars, after parsing |
|
21 | - * |
|
22 | - * @since 1.0.19 |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $query_vars = array(); |
|
26 | - |
|
27 | - /** |
|
28 | - * List of found subscriptions. |
|
29 | - * |
|
30 | - * @since 1.0.19 |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - private $results; |
|
34 | - |
|
35 | - /** |
|
36 | - * Total number of found subscriptions for the current query |
|
37 | - * |
|
38 | - * @since 1.0.19 |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - private $total_subscriptions = 0; |
|
42 | - |
|
43 | - /** |
|
44 | - * The SQL query used to fetch matching subscriptions. |
|
45 | - * |
|
46 | - * @since 1.0.19 |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $request; |
|
50 | - |
|
51 | - // SQL clauses |
|
52 | - |
|
53 | - /** |
|
54 | - * Contains the 'FIELDS' sql clause |
|
55 | - * |
|
56 | - * @since 1.0.19 |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $query_fields; |
|
60 | - |
|
61 | - /** |
|
62 | - * Contains the 'FROM' sql clause |
|
63 | - * |
|
64 | - * @since 1.0.19 |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $query_from; |
|
68 | - |
|
69 | - /** |
|
70 | - * Contains the 'WHERE' sql clause |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public $query_where; |
|
76 | - |
|
77 | - /** |
|
78 | - * Contains the 'ORDER BY' sql clause |
|
79 | - * |
|
80 | - * @since 1.0.19 |
|
81 | - * @var string |
|
82 | - */ |
|
83 | - public $query_orderby; |
|
84 | - |
|
85 | - /** |
|
86 | - * Contains the 'LIMIT' sql clause |
|
87 | - * |
|
88 | - * @since 1.0.19 |
|
89 | - * @var string |
|
90 | - */ |
|
91 | - public $query_limit; |
|
92 | - |
|
93 | - /** |
|
94 | - * Class constructor. |
|
95 | - * |
|
96 | - * @since 1.0.19 |
|
97 | - * |
|
98 | - * @param null|string|array $query Optional. The query variables. |
|
99 | - */ |
|
100 | - public function __construct( $query = null ) { |
|
101 | - if ( ! is_null( $query ) ) { |
|
102 | - $this->prepare_query( $query ); |
|
103 | - $this->query(); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Fills in missing query variables with default values. |
|
109 | - * |
|
110 | - * @since 1.0.19 |
|
111 | - * |
|
112 | - * @param string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`. |
|
113 | - * @return array Complete query variables with undefined ones filled in with defaults. |
|
114 | - */ |
|
115 | - public static function fill_query_vars( $args ) { |
|
116 | - $defaults = array( |
|
117 | - 'status' => 'all', |
|
118 | - 'customer_in' => array(), |
|
119 | - 'customer_not_in' => array(), |
|
120 | - 'product_in' => array(), |
|
121 | - 'product_not_in' => array(), |
|
122 | - 'include' => array(), |
|
123 | - 'exclude' => array(), |
|
124 | - 'orderby' => 'id', |
|
125 | - 'order' => 'DESC', |
|
126 | - 'offset' => '', |
|
127 | - 'number' => 10, |
|
128 | - 'paged' => 1, |
|
129 | - 'count_total' => true, |
|
130 | - 'fields' => 'all', |
|
131 | - ); |
|
132 | - |
|
133 | - return wp_parse_args( $args, $defaults ); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Prepare the query variables. |
|
138 | - * |
|
139 | - * @since 1.0.19 |
|
140 | - * |
|
141 | - * @global wpdb $wpdb WordPress database abstraction object. |
|
142 | - * |
|
143 | - * @param string|array $query { |
|
144 | - * Optional. Array or string of Query parameters. |
|
145 | - * |
|
146 | - * @type string|array $status The subscription status to filter by. Can either be a single status or an array of statuses. |
|
147 | - * Default is all. |
|
148 | - * @type int[] $customer_in An array of customer ids to filter by. |
|
149 | - * @type int[] $customer_not_in An array of customer ids whose subscriptions should be excluded. |
|
150 | - * @type int[] $invoice_in An array of invoice ids to filter by. |
|
151 | - * @type int[] $invoice_not_in An array of invoice ids whose subscriptions should be excluded. |
|
152 | - * @type int[] $product_in An array of product ids to filter by. |
|
153 | - * @type int[] $product_not_in An array of product ids whose subscriptions should be excluded. |
|
154 | - * @type array $date_created_query A WP_Date_Query compatible array use to filter subscriptions by their date of creation. |
|
155 | - * @type array $date_expires_query A WP_Date_Query compatible array use to filter subscriptions by their expiration date. |
|
156 | - * @type array $include An array of subscription IDs to include. Default empty array. |
|
157 | - * @type array $exclude An array of subscription IDs to exclude. Default empty array. |
|
158 | - * @type string|array $orderby Field(s) to sort the retrieved subscription by. May be a single value, |
|
159 | - * an array of values, or a multi-dimensional array with fields as |
|
160 | - * keys and orders ('ASC' or 'DESC') as values. Accepted values are |
|
161 | - * 'id', 'customer_id', 'frequency', 'period', 'initial_amount, |
|
162 | - * 'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration' |
|
163 | - * 'transaction_id', 'product_id', 'trial_period', 'include', 'status', 'profile_id'. Default array( 'id' ). |
|
164 | - * @type string $order Designates ascending or descending order of subscriptions. Order values |
|
165 | - * passed as part of an `$orderby` array take precedence over this |
|
166 | - * parameter. Accepts 'ASC', 'DESC'. Default 'DESC'. |
|
167 | - * @type int $offset Number of subscriptions to offset in retrieved results. Can be used in |
|
168 | - * conjunction with pagination. Default 0. |
|
169 | - * @type int $number Number of subscriptions to limit the query for. Can be used in |
|
170 | - * conjunction with pagination. Value -1 (all) is supported, but |
|
171 | - * should be used with caution on larger sites. |
|
172 | - * Default 10. |
|
173 | - * @type int $paged When used with number, defines the page of results to return. |
|
174 | - * Default 1. |
|
175 | - * @type bool $count_total Whether to count the total number of subscriptions found. If pagination |
|
176 | - * is not needed, setting this to false can improve performance. |
|
177 | - * Default true. |
|
178 | - * @type string|array $fields Which fields to return. Single or all fields (string), or array |
|
179 | - * of fields. Accepts 'id', 'customer_id', 'frequency', 'period', 'initial_amount, |
|
180 | - * 'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration' |
|
181 | - * 'transaction_id', 'product_id', 'trial_period', 'status', 'profile_id'. |
|
182 | - * Use 'all' for all fields. Default 'all'. |
|
183 | - * } |
|
184 | - */ |
|
185 | - public function prepare_query( $query = array() ) { |
|
186 | - global $wpdb; |
|
187 | - |
|
188 | - if ( empty( $this->query_vars ) || ! empty( $query ) ) { |
|
189 | - $this->query_limit = null; |
|
190 | - $this->query_vars = $this->fill_query_vars( $query ); |
|
191 | - } |
|
192 | - |
|
193 | - if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) { |
|
194 | - $this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] ); |
|
195 | - } |
|
196 | - |
|
197 | - do_action( 'getpaid_pre_get_subscriptions', array( &$this ) ); |
|
198 | - |
|
199 | - // Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'. |
|
200 | - $qv =& $this->query_vars; |
|
201 | - $qv = $this->fill_query_vars( $qv ); |
|
202 | - $table = $wpdb->prefix . 'wpinv_subscriptions'; |
|
203 | - $this->query_from = "FROM $table"; |
|
204 | - |
|
205 | - // Prepare query fields. |
|
206 | - $this->prepare_query_fields( $qv, $table ); |
|
207 | - |
|
208 | - // Prepare query where. |
|
209 | - $this->prepare_query_where( $qv, $table ); |
|
210 | - |
|
211 | - // Prepare query order. |
|
212 | - $this->prepare_query_order( $qv, $table ); |
|
213 | - |
|
214 | - // limit |
|
215 | - if ( isset( $qv['number'] ) && $qv['number'] > 0 ) { |
|
216 | - if ( $qv['offset'] ) { |
|
217 | - $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] ); |
|
218 | - } else { |
|
219 | - $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] ); |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) ); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Prepares the query fields. |
|
228 | - * |
|
229 | - * @since 1.0.19 |
|
230 | - * |
|
231 | - * @param array $qv Query vars. |
|
232 | - * @param string $table Table name. |
|
233 | - */ |
|
234 | - protected function prepare_query_fields( &$qv, $table ) { |
|
235 | - |
|
236 | - if ( is_array( $qv['fields'] ) ) { |
|
237 | - $qv['fields'] = array_unique( $qv['fields'] ); |
|
238 | - |
|
239 | - $query_fields = array(); |
|
240 | - foreach ( $qv['fields'] as $field ) { |
|
241 | - $field = sanitize_key( $field ); |
|
242 | - $query_fields[] = "$table.`$field`"; |
|
243 | - } |
|
244 | - $this->query_fields = implode( ',', $query_fields ); |
|
245 | - } else { |
|
246 | - $this->query_fields = "$table.*"; |
|
247 | - } |
|
248 | - |
|
249 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
250 | - $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
|
251 | - } |
|
252 | - |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Prepares the query where. |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - * |
|
260 | - * @param array $qv Query vars. |
|
261 | - * @param string $table Table name. |
|
262 | - */ |
|
263 | - protected function prepare_query_where( &$qv, $table ) { |
|
264 | - global $wpdb; |
|
265 | - $this->query_where = 'WHERE 1=1'; |
|
266 | - |
|
267 | - // Status. |
|
268 | - if ( 'all' !== $qv['status'] ) { |
|
269 | - $statuses = wpinv_clean( wpinv_parse_list( $qv['status'] ) ); |
|
270 | - $prepared_statuses = join( ',', array_fill( 0, count( $statuses ), '%s' ) ); |
|
271 | - $this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses ); |
|
272 | - } |
|
273 | - |
|
274 | - if ( ! empty( $qv['customer_in'] ) ) { |
|
275 | - $customer_in = implode( ',', wp_parse_id_list( $qv['customer_in'] ) ); |
|
276 | - $this->query_where .= " AND $table.`customer_id` IN ($customer_in)"; |
|
277 | - } elseif ( ! empty( $qv['customer_not_in'] ) ) { |
|
278 | - $customer_not_in = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) ); |
|
279 | - $this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)"; |
|
280 | - } |
|
281 | - |
|
282 | - if ( ! empty( $qv['product_in'] ) ) { |
|
283 | - $product_in = implode( ',', wp_parse_id_list( $qv['product_in'] ) ); |
|
284 | - $this->query_where .= " AND $table.`product_id` IN ($product_in)"; |
|
285 | - } elseif ( ! empty( $qv['product_not_in'] ) ) { |
|
286 | - $product_not_in = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) ); |
|
287 | - $this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)"; |
|
288 | - } |
|
289 | - |
|
290 | - if ( ! empty( $qv['invoice_in'] ) ) { |
|
291 | - $invoice_in = implode( ',', wp_parse_id_list( $qv['invoice_in'] ) ); |
|
292 | - $this->query_where .= " AND $table.`parent_payment_id` IN ($invoice_in)"; |
|
293 | - } elseif ( ! empty( $qv['invoice_not_in'] ) ) { |
|
294 | - $invoice_not_in = implode( ',', wp_parse_id_list( $qv['invoice_not_in'] ) ); |
|
295 | - $this->query_where .= " AND $table.`parent_payment_id` NOT IN ($invoice_not_in)"; |
|
296 | - } |
|
297 | - |
|
298 | - if ( ! empty( $qv['include'] ) ) { |
|
299 | - $include = implode( ',', wp_parse_id_list( $qv['include'] ) ); |
|
300 | - $this->query_where .= " AND $table.`id` IN ($include)"; |
|
301 | - } elseif ( ! empty( $qv['exclude'] ) ) { |
|
302 | - $exclude = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); |
|
303 | - $this->query_where .= " AND $table.`id` NOT IN ($exclude)"; |
|
304 | - } |
|
305 | - |
|
306 | - // Date queries are allowed for the subscription creation date. |
|
307 | - if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) { |
|
308 | - $date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" ); |
|
309 | - $this->query_where .= $date_created_query->get_sql(); |
|
310 | - } |
|
311 | - |
|
312 | - // Date queries are also allowed for the subscription expiration date. |
|
313 | - if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) { |
|
314 | - $date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" ); |
|
315 | - $this->query_where .= $date_expires_query->get_sql(); |
|
316 | - } |
|
317 | - |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Prepares the query order. |
|
322 | - * |
|
323 | - * @since 1.0.19 |
|
324 | - * |
|
325 | - * @param array $qv Query vars. |
|
326 | - * @param string $table Table name. |
|
327 | - */ |
|
328 | - protected function prepare_query_order( &$qv, $table ) { |
|
329 | - |
|
330 | - // sorting. |
|
331 | - $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : ''; |
|
332 | - $order = $this->parse_order( $qv['order'] ); |
|
333 | - |
|
334 | - // Default order is by 'id' (latest subscriptions). |
|
335 | - if ( empty( $qv['orderby'] ) ) { |
|
336 | - $qv['orderby'] = array( 'id' ); |
|
337 | - } |
|
338 | - |
|
339 | - // 'orderby' values may be an array, comma- or space-separated list. |
|
340 | - $ordersby = array_filter( wpinv_parse_list( $qv['orderby'] ) ); |
|
341 | - |
|
342 | - $orderby_array = array(); |
|
343 | - foreach ( $ordersby as $_key => $_value ) { |
|
344 | - |
|
345 | - if ( is_int( $_key ) ) { |
|
346 | - // Integer key means this is a flat array of 'orderby' fields. |
|
347 | - $_orderby = $_value; |
|
348 | - $_order = $order; |
|
349 | - } else { |
|
350 | - // Non-integer key means that the key is the field and the value is ASC/DESC. |
|
351 | - $_orderby = $_key; |
|
352 | - $_order = $_value; |
|
353 | - } |
|
354 | - |
|
355 | - $parsed = $this->parse_orderby( $_orderby, $table ); |
|
356 | - |
|
357 | - if ( $parsed ) { |
|
358 | - $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); |
|
359 | - } |
|
360 | - |
|
361 | - } |
|
362 | - |
|
363 | - // If no valid clauses were found, order by id. |
|
364 | - if ( empty( $orderby_array ) ) { |
|
365 | - $orderby_array[] = "id $order"; |
|
366 | - } |
|
367 | - |
|
368 | - $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array ); |
|
369 | - |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Execute the query, with the current variables. |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * |
|
377 | - * @global wpdb $wpdb WordPress database abstraction object. |
|
378 | - */ |
|
379 | - public function query() { |
|
380 | - global $wpdb; |
|
381 | - |
|
382 | - $qv =& $this->query_vars; |
|
383 | - |
|
384 | - // Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the |
|
385 | - // total_subscriptions property. |
|
386 | - $this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) ); |
|
387 | - |
|
388 | - if ( null === $this->results ) { |
|
389 | - $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; |
|
390 | - |
|
391 | - if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) { |
|
392 | - $this->results = $wpdb->get_results( $this->request ); |
|
393 | - } else { |
|
394 | - $this->results = $wpdb->get_col( $this->request ); |
|
395 | - } |
|
396 | - |
|
397 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
398 | - $found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this ); |
|
399 | - $this->total_subscriptions = (int) $wpdb->get_var( $found_subscriptions_query ); |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - if ( 'all' == $qv['fields'] ) { |
|
404 | - foreach ( $this->results as $key => $subscription ) { |
|
405 | - wp_cache_set( $subscription->id, $subscription, 'getpaid_subscriptions' ); |
|
406 | - wp_cache_set( $subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
407 | - wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
408 | - wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
409 | - $this->results[ $key ] = new WPInv_Subscription( $subscription ); |
|
410 | - } |
|
411 | - } |
|
412 | - |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Retrieve query variable. |
|
417 | - * |
|
418 | - * @since 1.0.19 |
|
419 | - * |
|
420 | - * @param string $query_var Query variable key. |
|
421 | - * @return mixed |
|
422 | - */ |
|
423 | - public function get( $query_var ) { |
|
424 | - if ( isset( $this->query_vars[ $query_var ] ) ) { |
|
425 | - return $this->query_vars[ $query_var ]; |
|
426 | - } |
|
427 | - |
|
428 | - return null; |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Set query variable. |
|
433 | - * |
|
434 | - * @since 1.0.19 |
|
435 | - * |
|
436 | - * @param string $query_var Query variable key. |
|
437 | - * @param mixed $value Query variable value. |
|
438 | - */ |
|
439 | - public function set( $query_var, $value ) { |
|
440 | - $this->query_vars[ $query_var ] = $value; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Return the list of subscriptions. |
|
445 | - * |
|
446 | - * @since 1.0.19 |
|
447 | - * |
|
448 | - * @return WPInv_Subscription[]|array Found subscriptions. |
|
449 | - */ |
|
450 | - public function get_results() { |
|
451 | - return $this->results; |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * Return the total number of subscriptions for the current query. |
|
456 | - * |
|
457 | - * @since 1.0.19 |
|
458 | - * |
|
459 | - * @return int Number of total subscriptions. |
|
460 | - */ |
|
461 | - public function get_total() { |
|
462 | - return $this->total_subscriptions; |
|
463 | - } |
|
464 | - |
|
465 | - /** |
|
466 | - * Parse and sanitize 'orderby' keys passed to the subscriptions query. |
|
467 | - * |
|
468 | - * @since 1.0.19 |
|
469 | - * |
|
470 | - * @param string $orderby Alias for the field to order by. |
|
471 | - * @param string $table The current table. |
|
472 | - * @return string Value to use in the ORDER clause, if `$orderby` is valid. |
|
473 | - */ |
|
474 | - protected function parse_orderby( $orderby, $table ) { |
|
475 | - |
|
476 | - $_orderby = ''; |
|
477 | - if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) { |
|
478 | - $_orderby = "$table.`$orderby`"; |
|
479 | - } elseif ( 'id' === strtolower( $orderby ) ) { |
|
480 | - $_orderby = "$table.id"; |
|
481 | - } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { |
|
482 | - $include = wp_parse_id_list( $this->query_vars['include'] ); |
|
483 | - $include_sql = implode( ',', $include ); |
|
484 | - $_orderby = "FIELD( $table.id, $include_sql )"; |
|
485 | - } |
|
486 | - |
|
487 | - return $_orderby; |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * Parse an 'order' query variable and cast it to ASC or DESC as necessary. |
|
492 | - * |
|
493 | - * @since 1.0.19 |
|
494 | - * |
|
495 | - * @param string $order The 'order' query variable. |
|
496 | - * @return string The sanitized 'order' query variable. |
|
497 | - */ |
|
498 | - protected function parse_order( $order ) { |
|
499 | - if ( ! is_string( $order ) || empty( $order ) ) { |
|
500 | - return 'DESC'; |
|
501 | - } |
|
502 | - |
|
503 | - if ( 'ASC' === strtoupper( $order ) ) { |
|
504 | - return 'ASC'; |
|
505 | - } else { |
|
506 | - return 'DESC'; |
|
507 | - } |
|
508 | - } |
|
19 | + /** |
|
20 | + * Query vars, after parsing |
|
21 | + * |
|
22 | + * @since 1.0.19 |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $query_vars = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * List of found subscriptions. |
|
29 | + * |
|
30 | + * @since 1.0.19 |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + private $results; |
|
34 | + |
|
35 | + /** |
|
36 | + * Total number of found subscriptions for the current query |
|
37 | + * |
|
38 | + * @since 1.0.19 |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + private $total_subscriptions = 0; |
|
42 | + |
|
43 | + /** |
|
44 | + * The SQL query used to fetch matching subscriptions. |
|
45 | + * |
|
46 | + * @since 1.0.19 |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $request; |
|
50 | + |
|
51 | + // SQL clauses |
|
52 | + |
|
53 | + /** |
|
54 | + * Contains the 'FIELDS' sql clause |
|
55 | + * |
|
56 | + * @since 1.0.19 |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $query_fields; |
|
60 | + |
|
61 | + /** |
|
62 | + * Contains the 'FROM' sql clause |
|
63 | + * |
|
64 | + * @since 1.0.19 |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $query_from; |
|
68 | + |
|
69 | + /** |
|
70 | + * Contains the 'WHERE' sql clause |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public $query_where; |
|
76 | + |
|
77 | + /** |
|
78 | + * Contains the 'ORDER BY' sql clause |
|
79 | + * |
|
80 | + * @since 1.0.19 |
|
81 | + * @var string |
|
82 | + */ |
|
83 | + public $query_orderby; |
|
84 | + |
|
85 | + /** |
|
86 | + * Contains the 'LIMIT' sql clause |
|
87 | + * |
|
88 | + * @since 1.0.19 |
|
89 | + * @var string |
|
90 | + */ |
|
91 | + public $query_limit; |
|
92 | + |
|
93 | + /** |
|
94 | + * Class constructor. |
|
95 | + * |
|
96 | + * @since 1.0.19 |
|
97 | + * |
|
98 | + * @param null|string|array $query Optional. The query variables. |
|
99 | + */ |
|
100 | + public function __construct( $query = null ) { |
|
101 | + if ( ! is_null( $query ) ) { |
|
102 | + $this->prepare_query( $query ); |
|
103 | + $this->query(); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Fills in missing query variables with default values. |
|
109 | + * |
|
110 | + * @since 1.0.19 |
|
111 | + * |
|
112 | + * @param string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`. |
|
113 | + * @return array Complete query variables with undefined ones filled in with defaults. |
|
114 | + */ |
|
115 | + public static function fill_query_vars( $args ) { |
|
116 | + $defaults = array( |
|
117 | + 'status' => 'all', |
|
118 | + 'customer_in' => array(), |
|
119 | + 'customer_not_in' => array(), |
|
120 | + 'product_in' => array(), |
|
121 | + 'product_not_in' => array(), |
|
122 | + 'include' => array(), |
|
123 | + 'exclude' => array(), |
|
124 | + 'orderby' => 'id', |
|
125 | + 'order' => 'DESC', |
|
126 | + 'offset' => '', |
|
127 | + 'number' => 10, |
|
128 | + 'paged' => 1, |
|
129 | + 'count_total' => true, |
|
130 | + 'fields' => 'all', |
|
131 | + ); |
|
132 | + |
|
133 | + return wp_parse_args( $args, $defaults ); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Prepare the query variables. |
|
138 | + * |
|
139 | + * @since 1.0.19 |
|
140 | + * |
|
141 | + * @global wpdb $wpdb WordPress database abstraction object. |
|
142 | + * |
|
143 | + * @param string|array $query { |
|
144 | + * Optional. Array or string of Query parameters. |
|
145 | + * |
|
146 | + * @type string|array $status The subscription status to filter by. Can either be a single status or an array of statuses. |
|
147 | + * Default is all. |
|
148 | + * @type int[] $customer_in An array of customer ids to filter by. |
|
149 | + * @type int[] $customer_not_in An array of customer ids whose subscriptions should be excluded. |
|
150 | + * @type int[] $invoice_in An array of invoice ids to filter by. |
|
151 | + * @type int[] $invoice_not_in An array of invoice ids whose subscriptions should be excluded. |
|
152 | + * @type int[] $product_in An array of product ids to filter by. |
|
153 | + * @type int[] $product_not_in An array of product ids whose subscriptions should be excluded. |
|
154 | + * @type array $date_created_query A WP_Date_Query compatible array use to filter subscriptions by their date of creation. |
|
155 | + * @type array $date_expires_query A WP_Date_Query compatible array use to filter subscriptions by their expiration date. |
|
156 | + * @type array $include An array of subscription IDs to include. Default empty array. |
|
157 | + * @type array $exclude An array of subscription IDs to exclude. Default empty array. |
|
158 | + * @type string|array $orderby Field(s) to sort the retrieved subscription by. May be a single value, |
|
159 | + * an array of values, or a multi-dimensional array with fields as |
|
160 | + * keys and orders ('ASC' or 'DESC') as values. Accepted values are |
|
161 | + * 'id', 'customer_id', 'frequency', 'period', 'initial_amount, |
|
162 | + * 'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration' |
|
163 | + * 'transaction_id', 'product_id', 'trial_period', 'include', 'status', 'profile_id'. Default array( 'id' ). |
|
164 | + * @type string $order Designates ascending or descending order of subscriptions. Order values |
|
165 | + * passed as part of an `$orderby` array take precedence over this |
|
166 | + * parameter. Accepts 'ASC', 'DESC'. Default 'DESC'. |
|
167 | + * @type int $offset Number of subscriptions to offset in retrieved results. Can be used in |
|
168 | + * conjunction with pagination. Default 0. |
|
169 | + * @type int $number Number of subscriptions to limit the query for. Can be used in |
|
170 | + * conjunction with pagination. Value -1 (all) is supported, but |
|
171 | + * should be used with caution on larger sites. |
|
172 | + * Default 10. |
|
173 | + * @type int $paged When used with number, defines the page of results to return. |
|
174 | + * Default 1. |
|
175 | + * @type bool $count_total Whether to count the total number of subscriptions found. If pagination |
|
176 | + * is not needed, setting this to false can improve performance. |
|
177 | + * Default true. |
|
178 | + * @type string|array $fields Which fields to return. Single or all fields (string), or array |
|
179 | + * of fields. Accepts 'id', 'customer_id', 'frequency', 'period', 'initial_amount, |
|
180 | + * 'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration' |
|
181 | + * 'transaction_id', 'product_id', 'trial_period', 'status', 'profile_id'. |
|
182 | + * Use 'all' for all fields. Default 'all'. |
|
183 | + * } |
|
184 | + */ |
|
185 | + public function prepare_query( $query = array() ) { |
|
186 | + global $wpdb; |
|
187 | + |
|
188 | + if ( empty( $this->query_vars ) || ! empty( $query ) ) { |
|
189 | + $this->query_limit = null; |
|
190 | + $this->query_vars = $this->fill_query_vars( $query ); |
|
191 | + } |
|
192 | + |
|
193 | + if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) { |
|
194 | + $this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] ); |
|
195 | + } |
|
196 | + |
|
197 | + do_action( 'getpaid_pre_get_subscriptions', array( &$this ) ); |
|
198 | + |
|
199 | + // Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'. |
|
200 | + $qv =& $this->query_vars; |
|
201 | + $qv = $this->fill_query_vars( $qv ); |
|
202 | + $table = $wpdb->prefix . 'wpinv_subscriptions'; |
|
203 | + $this->query_from = "FROM $table"; |
|
204 | + |
|
205 | + // Prepare query fields. |
|
206 | + $this->prepare_query_fields( $qv, $table ); |
|
207 | + |
|
208 | + // Prepare query where. |
|
209 | + $this->prepare_query_where( $qv, $table ); |
|
210 | + |
|
211 | + // Prepare query order. |
|
212 | + $this->prepare_query_order( $qv, $table ); |
|
213 | + |
|
214 | + // limit |
|
215 | + if ( isset( $qv['number'] ) && $qv['number'] > 0 ) { |
|
216 | + if ( $qv['offset'] ) { |
|
217 | + $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] ); |
|
218 | + } else { |
|
219 | + $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] ); |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) ); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Prepares the query fields. |
|
228 | + * |
|
229 | + * @since 1.0.19 |
|
230 | + * |
|
231 | + * @param array $qv Query vars. |
|
232 | + * @param string $table Table name. |
|
233 | + */ |
|
234 | + protected function prepare_query_fields( &$qv, $table ) { |
|
235 | + |
|
236 | + if ( is_array( $qv['fields'] ) ) { |
|
237 | + $qv['fields'] = array_unique( $qv['fields'] ); |
|
238 | + |
|
239 | + $query_fields = array(); |
|
240 | + foreach ( $qv['fields'] as $field ) { |
|
241 | + $field = sanitize_key( $field ); |
|
242 | + $query_fields[] = "$table.`$field`"; |
|
243 | + } |
|
244 | + $this->query_fields = implode( ',', $query_fields ); |
|
245 | + } else { |
|
246 | + $this->query_fields = "$table.*"; |
|
247 | + } |
|
248 | + |
|
249 | + if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
250 | + $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
|
251 | + } |
|
252 | + |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Prepares the query where. |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + * |
|
260 | + * @param array $qv Query vars. |
|
261 | + * @param string $table Table name. |
|
262 | + */ |
|
263 | + protected function prepare_query_where( &$qv, $table ) { |
|
264 | + global $wpdb; |
|
265 | + $this->query_where = 'WHERE 1=1'; |
|
266 | + |
|
267 | + // Status. |
|
268 | + if ( 'all' !== $qv['status'] ) { |
|
269 | + $statuses = wpinv_clean( wpinv_parse_list( $qv['status'] ) ); |
|
270 | + $prepared_statuses = join( ',', array_fill( 0, count( $statuses ), '%s' ) ); |
|
271 | + $this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses ); |
|
272 | + } |
|
273 | + |
|
274 | + if ( ! empty( $qv['customer_in'] ) ) { |
|
275 | + $customer_in = implode( ',', wp_parse_id_list( $qv['customer_in'] ) ); |
|
276 | + $this->query_where .= " AND $table.`customer_id` IN ($customer_in)"; |
|
277 | + } elseif ( ! empty( $qv['customer_not_in'] ) ) { |
|
278 | + $customer_not_in = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) ); |
|
279 | + $this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)"; |
|
280 | + } |
|
281 | + |
|
282 | + if ( ! empty( $qv['product_in'] ) ) { |
|
283 | + $product_in = implode( ',', wp_parse_id_list( $qv['product_in'] ) ); |
|
284 | + $this->query_where .= " AND $table.`product_id` IN ($product_in)"; |
|
285 | + } elseif ( ! empty( $qv['product_not_in'] ) ) { |
|
286 | + $product_not_in = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) ); |
|
287 | + $this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)"; |
|
288 | + } |
|
289 | + |
|
290 | + if ( ! empty( $qv['invoice_in'] ) ) { |
|
291 | + $invoice_in = implode( ',', wp_parse_id_list( $qv['invoice_in'] ) ); |
|
292 | + $this->query_where .= " AND $table.`parent_payment_id` IN ($invoice_in)"; |
|
293 | + } elseif ( ! empty( $qv['invoice_not_in'] ) ) { |
|
294 | + $invoice_not_in = implode( ',', wp_parse_id_list( $qv['invoice_not_in'] ) ); |
|
295 | + $this->query_where .= " AND $table.`parent_payment_id` NOT IN ($invoice_not_in)"; |
|
296 | + } |
|
297 | + |
|
298 | + if ( ! empty( $qv['include'] ) ) { |
|
299 | + $include = implode( ',', wp_parse_id_list( $qv['include'] ) ); |
|
300 | + $this->query_where .= " AND $table.`id` IN ($include)"; |
|
301 | + } elseif ( ! empty( $qv['exclude'] ) ) { |
|
302 | + $exclude = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); |
|
303 | + $this->query_where .= " AND $table.`id` NOT IN ($exclude)"; |
|
304 | + } |
|
305 | + |
|
306 | + // Date queries are allowed for the subscription creation date. |
|
307 | + if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) { |
|
308 | + $date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" ); |
|
309 | + $this->query_where .= $date_created_query->get_sql(); |
|
310 | + } |
|
311 | + |
|
312 | + // Date queries are also allowed for the subscription expiration date. |
|
313 | + if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) { |
|
314 | + $date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" ); |
|
315 | + $this->query_where .= $date_expires_query->get_sql(); |
|
316 | + } |
|
317 | + |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Prepares the query order. |
|
322 | + * |
|
323 | + * @since 1.0.19 |
|
324 | + * |
|
325 | + * @param array $qv Query vars. |
|
326 | + * @param string $table Table name. |
|
327 | + */ |
|
328 | + protected function prepare_query_order( &$qv, $table ) { |
|
329 | + |
|
330 | + // sorting. |
|
331 | + $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : ''; |
|
332 | + $order = $this->parse_order( $qv['order'] ); |
|
333 | + |
|
334 | + // Default order is by 'id' (latest subscriptions). |
|
335 | + if ( empty( $qv['orderby'] ) ) { |
|
336 | + $qv['orderby'] = array( 'id' ); |
|
337 | + } |
|
338 | + |
|
339 | + // 'orderby' values may be an array, comma- or space-separated list. |
|
340 | + $ordersby = array_filter( wpinv_parse_list( $qv['orderby'] ) ); |
|
341 | + |
|
342 | + $orderby_array = array(); |
|
343 | + foreach ( $ordersby as $_key => $_value ) { |
|
344 | + |
|
345 | + if ( is_int( $_key ) ) { |
|
346 | + // Integer key means this is a flat array of 'orderby' fields. |
|
347 | + $_orderby = $_value; |
|
348 | + $_order = $order; |
|
349 | + } else { |
|
350 | + // Non-integer key means that the key is the field and the value is ASC/DESC. |
|
351 | + $_orderby = $_key; |
|
352 | + $_order = $_value; |
|
353 | + } |
|
354 | + |
|
355 | + $parsed = $this->parse_orderby( $_orderby, $table ); |
|
356 | + |
|
357 | + if ( $parsed ) { |
|
358 | + $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); |
|
359 | + } |
|
360 | + |
|
361 | + } |
|
362 | + |
|
363 | + // If no valid clauses were found, order by id. |
|
364 | + if ( empty( $orderby_array ) ) { |
|
365 | + $orderby_array[] = "id $order"; |
|
366 | + } |
|
367 | + |
|
368 | + $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array ); |
|
369 | + |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Execute the query, with the current variables. |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * |
|
377 | + * @global wpdb $wpdb WordPress database abstraction object. |
|
378 | + */ |
|
379 | + public function query() { |
|
380 | + global $wpdb; |
|
381 | + |
|
382 | + $qv =& $this->query_vars; |
|
383 | + |
|
384 | + // Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the |
|
385 | + // total_subscriptions property. |
|
386 | + $this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) ); |
|
387 | + |
|
388 | + if ( null === $this->results ) { |
|
389 | + $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; |
|
390 | + |
|
391 | + if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) { |
|
392 | + $this->results = $wpdb->get_results( $this->request ); |
|
393 | + } else { |
|
394 | + $this->results = $wpdb->get_col( $this->request ); |
|
395 | + } |
|
396 | + |
|
397 | + if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
398 | + $found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this ); |
|
399 | + $this->total_subscriptions = (int) $wpdb->get_var( $found_subscriptions_query ); |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + if ( 'all' == $qv['fields'] ) { |
|
404 | + foreach ( $this->results as $key => $subscription ) { |
|
405 | + wp_cache_set( $subscription->id, $subscription, 'getpaid_subscriptions' ); |
|
406 | + wp_cache_set( $subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
407 | + wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
408 | + wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
409 | + $this->results[ $key ] = new WPInv_Subscription( $subscription ); |
|
410 | + } |
|
411 | + } |
|
412 | + |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Retrieve query variable. |
|
417 | + * |
|
418 | + * @since 1.0.19 |
|
419 | + * |
|
420 | + * @param string $query_var Query variable key. |
|
421 | + * @return mixed |
|
422 | + */ |
|
423 | + public function get( $query_var ) { |
|
424 | + if ( isset( $this->query_vars[ $query_var ] ) ) { |
|
425 | + return $this->query_vars[ $query_var ]; |
|
426 | + } |
|
427 | + |
|
428 | + return null; |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Set query variable. |
|
433 | + * |
|
434 | + * @since 1.0.19 |
|
435 | + * |
|
436 | + * @param string $query_var Query variable key. |
|
437 | + * @param mixed $value Query variable value. |
|
438 | + */ |
|
439 | + public function set( $query_var, $value ) { |
|
440 | + $this->query_vars[ $query_var ] = $value; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Return the list of subscriptions. |
|
445 | + * |
|
446 | + * @since 1.0.19 |
|
447 | + * |
|
448 | + * @return WPInv_Subscription[]|array Found subscriptions. |
|
449 | + */ |
|
450 | + public function get_results() { |
|
451 | + return $this->results; |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * Return the total number of subscriptions for the current query. |
|
456 | + * |
|
457 | + * @since 1.0.19 |
|
458 | + * |
|
459 | + * @return int Number of total subscriptions. |
|
460 | + */ |
|
461 | + public function get_total() { |
|
462 | + return $this->total_subscriptions; |
|
463 | + } |
|
464 | + |
|
465 | + /** |
|
466 | + * Parse and sanitize 'orderby' keys passed to the subscriptions query. |
|
467 | + * |
|
468 | + * @since 1.0.19 |
|
469 | + * |
|
470 | + * @param string $orderby Alias for the field to order by. |
|
471 | + * @param string $table The current table. |
|
472 | + * @return string Value to use in the ORDER clause, if `$orderby` is valid. |
|
473 | + */ |
|
474 | + protected function parse_orderby( $orderby, $table ) { |
|
475 | + |
|
476 | + $_orderby = ''; |
|
477 | + if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) { |
|
478 | + $_orderby = "$table.`$orderby`"; |
|
479 | + } elseif ( 'id' === strtolower( $orderby ) ) { |
|
480 | + $_orderby = "$table.id"; |
|
481 | + } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { |
|
482 | + $include = wp_parse_id_list( $this->query_vars['include'] ); |
|
483 | + $include_sql = implode( ',', $include ); |
|
484 | + $_orderby = "FIELD( $table.id, $include_sql )"; |
|
485 | + } |
|
486 | + |
|
487 | + return $_orderby; |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * Parse an 'order' query variable and cast it to ASC or DESC as necessary. |
|
492 | + * |
|
493 | + * @since 1.0.19 |
|
494 | + * |
|
495 | + * @param string $order The 'order' query variable. |
|
496 | + * @return string The sanitized 'order' query variable. |
|
497 | + */ |
|
498 | + protected function parse_order( $order ) { |
|
499 | + if ( ! is_string( $order ) || empty( $order ) ) { |
|
500 | + return 'DESC'; |
|
501 | + } |
|
502 | + |
|
503 | + if ( 'ASC' === strtoupper( $order ) ) { |
|
504 | + return 'ASC'; |
|
505 | + } else { |
|
506 | + return 'DESC'; |
|
507 | + } |
|
508 | + } |
|
509 | 509 | |
510 | 510 | } |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @param null|string|array $query Optional. The query variables. |
99 | 99 | */ |
100 | - public function __construct( $query = null ) { |
|
101 | - if ( ! is_null( $query ) ) { |
|
102 | - $this->prepare_query( $query ); |
|
100 | + public function __construct($query = null) { |
|
101 | + if (!is_null($query)) { |
|
102 | + $this->prepare_query($query); |
|
103 | 103 | $this->query(); |
104 | 104 | } |
105 | 105 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`. |
113 | 113 | * @return array Complete query variables with undefined ones filled in with defaults. |
114 | 114 | */ |
115 | - public static function fill_query_vars( $args ) { |
|
115 | + public static function fill_query_vars($args) { |
|
116 | 116 | $defaults = array( |
117 | 117 | 'status' => 'all', |
118 | 118 | 'customer_in' => array(), |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | 'fields' => 'all', |
131 | 131 | ); |
132 | 132 | |
133 | - return wp_parse_args( $args, $defaults ); |
|
133 | + return wp_parse_args($args, $defaults); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -182,45 +182,45 @@ discard block |
||
182 | 182 | * Use 'all' for all fields. Default 'all'. |
183 | 183 | * } |
184 | 184 | */ |
185 | - public function prepare_query( $query = array() ) { |
|
185 | + public function prepare_query($query = array()) { |
|
186 | 186 | global $wpdb; |
187 | 187 | |
188 | - if ( empty( $this->query_vars ) || ! empty( $query ) ) { |
|
188 | + if (empty($this->query_vars) || !empty($query)) { |
|
189 | 189 | $this->query_limit = null; |
190 | - $this->query_vars = $this->fill_query_vars( $query ); |
|
190 | + $this->query_vars = $this->fill_query_vars($query); |
|
191 | 191 | } |
192 | 192 | |
193 | - if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) { |
|
194 | - $this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] ); |
|
193 | + if (!empty($this->query_vars['fields']) && 'all' !== $this->query_vars['fields']) { |
|
194 | + $this->query_vars['fields'] = wpinv_parse_list($this->query_vars['fields']); |
|
195 | 195 | } |
196 | 196 | |
197 | - do_action( 'getpaid_pre_get_subscriptions', array( &$this ) ); |
|
197 | + do_action('getpaid_pre_get_subscriptions', array(&$this)); |
|
198 | 198 | |
199 | 199 | // Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'. |
200 | - $qv =& $this->query_vars; |
|
201 | - $qv = $this->fill_query_vars( $qv ); |
|
200 | + $qv = & $this->query_vars; |
|
201 | + $qv = $this->fill_query_vars($qv); |
|
202 | 202 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
203 | 203 | $this->query_from = "FROM $table"; |
204 | 204 | |
205 | 205 | // Prepare query fields. |
206 | - $this->prepare_query_fields( $qv, $table ); |
|
206 | + $this->prepare_query_fields($qv, $table); |
|
207 | 207 | |
208 | 208 | // Prepare query where. |
209 | - $this->prepare_query_where( $qv, $table ); |
|
209 | + $this->prepare_query_where($qv, $table); |
|
210 | 210 | |
211 | 211 | // Prepare query order. |
212 | - $this->prepare_query_order( $qv, $table ); |
|
212 | + $this->prepare_query_order($qv, $table); |
|
213 | 213 | |
214 | 214 | // limit |
215 | - if ( isset( $qv['number'] ) && $qv['number'] > 0 ) { |
|
216 | - if ( $qv['offset'] ) { |
|
217 | - $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] ); |
|
215 | + if (isset($qv['number']) && $qv['number'] > 0) { |
|
216 | + if ($qv['offset']) { |
|
217 | + $this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['offset'], $qv['number']); |
|
218 | 218 | } else { |
219 | - $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] ); |
|
219 | + $this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['number'] * ($qv['paged'] - 1), $qv['number']); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) ); |
|
223 | + do_action_ref_array('getpaid_after_subscriptions_query', array(&$this)); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -231,22 +231,22 @@ discard block |
||
231 | 231 | * @param array $qv Query vars. |
232 | 232 | * @param string $table Table name. |
233 | 233 | */ |
234 | - protected function prepare_query_fields( &$qv, $table ) { |
|
234 | + protected function prepare_query_fields(&$qv, $table) { |
|
235 | 235 | |
236 | - if ( is_array( $qv['fields'] ) ) { |
|
237 | - $qv['fields'] = array_unique( $qv['fields'] ); |
|
236 | + if (is_array($qv['fields'])) { |
|
237 | + $qv['fields'] = array_unique($qv['fields']); |
|
238 | 238 | |
239 | 239 | $query_fields = array(); |
240 | - foreach ( $qv['fields'] as $field ) { |
|
241 | - $field = sanitize_key( $field ); |
|
240 | + foreach ($qv['fields'] as $field) { |
|
241 | + $field = sanitize_key($field); |
|
242 | 242 | $query_fields[] = "$table.`$field`"; |
243 | 243 | } |
244 | - $this->query_fields = implode( ',', $query_fields ); |
|
244 | + $this->query_fields = implode(',', $query_fields); |
|
245 | 245 | } else { |
246 | 246 | $this->query_fields = "$table.*"; |
247 | 247 | } |
248 | 248 | |
249 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
249 | + if (isset($qv['count_total']) && $qv['count_total']) { |
|
250 | 250 | $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
251 | 251 | } |
252 | 252 | |
@@ -260,58 +260,58 @@ discard block |
||
260 | 260 | * @param array $qv Query vars. |
261 | 261 | * @param string $table Table name. |
262 | 262 | */ |
263 | - protected function prepare_query_where( &$qv, $table ) { |
|
263 | + protected function prepare_query_where(&$qv, $table) { |
|
264 | 264 | global $wpdb; |
265 | 265 | $this->query_where = 'WHERE 1=1'; |
266 | 266 | |
267 | 267 | // Status. |
268 | - if ( 'all' !== $qv['status'] ) { |
|
269 | - $statuses = wpinv_clean( wpinv_parse_list( $qv['status'] ) ); |
|
270 | - $prepared_statuses = join( ',', array_fill( 0, count( $statuses ), '%s' ) ); |
|
271 | - $this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses ); |
|
268 | + if ('all' !== $qv['status']) { |
|
269 | + $statuses = wpinv_clean(wpinv_parse_list($qv['status'])); |
|
270 | + $prepared_statuses = join(',', array_fill(0, count($statuses), '%s')); |
|
271 | + $this->query_where .= $wpdb->prepare(" AND $table.`status` IN ( $prepared_statuses )", $statuses); |
|
272 | 272 | } |
273 | 273 | |
274 | - if ( ! empty( $qv['customer_in'] ) ) { |
|
275 | - $customer_in = implode( ',', wp_parse_id_list( $qv['customer_in'] ) ); |
|
274 | + if (!empty($qv['customer_in'])) { |
|
275 | + $customer_in = implode(',', wp_parse_id_list($qv['customer_in'])); |
|
276 | 276 | $this->query_where .= " AND $table.`customer_id` IN ($customer_in)"; |
277 | - } elseif ( ! empty( $qv['customer_not_in'] ) ) { |
|
278 | - $customer_not_in = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) ); |
|
277 | + } elseif (!empty($qv['customer_not_in'])) { |
|
278 | + $customer_not_in = implode(',', wp_parse_id_list($qv['customer_not_in'])); |
|
279 | 279 | $this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)"; |
280 | 280 | } |
281 | 281 | |
282 | - if ( ! empty( $qv['product_in'] ) ) { |
|
283 | - $product_in = implode( ',', wp_parse_id_list( $qv['product_in'] ) ); |
|
282 | + if (!empty($qv['product_in'])) { |
|
283 | + $product_in = implode(',', wp_parse_id_list($qv['product_in'])); |
|
284 | 284 | $this->query_where .= " AND $table.`product_id` IN ($product_in)"; |
285 | - } elseif ( ! empty( $qv['product_not_in'] ) ) { |
|
286 | - $product_not_in = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) ); |
|
285 | + } elseif (!empty($qv['product_not_in'])) { |
|
286 | + $product_not_in = implode(',', wp_parse_id_list($qv['product_not_in'])); |
|
287 | 287 | $this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)"; |
288 | 288 | } |
289 | 289 | |
290 | - if ( ! empty( $qv['invoice_in'] ) ) { |
|
291 | - $invoice_in = implode( ',', wp_parse_id_list( $qv['invoice_in'] ) ); |
|
290 | + if (!empty($qv['invoice_in'])) { |
|
291 | + $invoice_in = implode(',', wp_parse_id_list($qv['invoice_in'])); |
|
292 | 292 | $this->query_where .= " AND $table.`parent_payment_id` IN ($invoice_in)"; |
293 | - } elseif ( ! empty( $qv['invoice_not_in'] ) ) { |
|
294 | - $invoice_not_in = implode( ',', wp_parse_id_list( $qv['invoice_not_in'] ) ); |
|
293 | + } elseif (!empty($qv['invoice_not_in'])) { |
|
294 | + $invoice_not_in = implode(',', wp_parse_id_list($qv['invoice_not_in'])); |
|
295 | 295 | $this->query_where .= " AND $table.`parent_payment_id` NOT IN ($invoice_not_in)"; |
296 | 296 | } |
297 | 297 | |
298 | - if ( ! empty( $qv['include'] ) ) { |
|
299 | - $include = implode( ',', wp_parse_id_list( $qv['include'] ) ); |
|
298 | + if (!empty($qv['include'])) { |
|
299 | + $include = implode(',', wp_parse_id_list($qv['include'])); |
|
300 | 300 | $this->query_where .= " AND $table.`id` IN ($include)"; |
301 | - } elseif ( ! empty( $qv['exclude'] ) ) { |
|
302 | - $exclude = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); |
|
301 | + } elseif (!empty($qv['exclude'])) { |
|
302 | + $exclude = implode(',', wp_parse_id_list($qv['exclude'])); |
|
303 | 303 | $this->query_where .= " AND $table.`id` NOT IN ($exclude)"; |
304 | 304 | } |
305 | 305 | |
306 | 306 | // Date queries are allowed for the subscription creation date. |
307 | - if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) { |
|
308 | - $date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" ); |
|
307 | + if (!empty($qv['date_created_query']) && is_array($qv['date_created_query'])) { |
|
308 | + $date_created_query = new WP_Date_Query($qv['date_created_query'], "$table.created"); |
|
309 | 309 | $this->query_where .= $date_created_query->get_sql(); |
310 | 310 | } |
311 | 311 | |
312 | 312 | // Date queries are also allowed for the subscription expiration date. |
313 | - if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) { |
|
314 | - $date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" ); |
|
313 | + if (!empty($qv['date_expires_query']) && is_array($qv['date_expires_query'])) { |
|
314 | + $date_expires_query = new WP_Date_Query($qv['date_expires_query'], "$table.expiration"); |
|
315 | 315 | $this->query_where .= $date_expires_query->get_sql(); |
316 | 316 | } |
317 | 317 | |
@@ -325,24 +325,24 @@ discard block |
||
325 | 325 | * @param array $qv Query vars. |
326 | 326 | * @param string $table Table name. |
327 | 327 | */ |
328 | - protected function prepare_query_order( &$qv, $table ) { |
|
328 | + protected function prepare_query_order(&$qv, $table) { |
|
329 | 329 | |
330 | 330 | // sorting. |
331 | - $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : ''; |
|
332 | - $order = $this->parse_order( $qv['order'] ); |
|
331 | + $qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : ''; |
|
332 | + $order = $this->parse_order($qv['order']); |
|
333 | 333 | |
334 | 334 | // Default order is by 'id' (latest subscriptions). |
335 | - if ( empty( $qv['orderby'] ) ) { |
|
336 | - $qv['orderby'] = array( 'id' ); |
|
335 | + if (empty($qv['orderby'])) { |
|
336 | + $qv['orderby'] = array('id'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // 'orderby' values may be an array, comma- or space-separated list. |
340 | - $ordersby = array_filter( wpinv_parse_list( $qv['orderby'] ) ); |
|
340 | + $ordersby = array_filter(wpinv_parse_list($qv['orderby'])); |
|
341 | 341 | |
342 | 342 | $orderby_array = array(); |
343 | - foreach ( $ordersby as $_key => $_value ) { |
|
343 | + foreach ($ordersby as $_key => $_value) { |
|
344 | 344 | |
345 | - if ( is_int( $_key ) ) { |
|
345 | + if (is_int($_key)) { |
|
346 | 346 | // Integer key means this is a flat array of 'orderby' fields. |
347 | 347 | $_orderby = $_value; |
348 | 348 | $_order = $order; |
@@ -352,20 +352,20 @@ discard block |
||
352 | 352 | $_order = $_value; |
353 | 353 | } |
354 | 354 | |
355 | - $parsed = $this->parse_orderby( $_orderby, $table ); |
|
355 | + $parsed = $this->parse_orderby($_orderby, $table); |
|
356 | 356 | |
357 | - if ( $parsed ) { |
|
358 | - $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); |
|
357 | + if ($parsed) { |
|
358 | + $orderby_array[] = $parsed . ' ' . $this->parse_order($_order); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | } |
362 | 362 | |
363 | 363 | // If no valid clauses were found, order by id. |
364 | - if ( empty( $orderby_array ) ) { |
|
364 | + if (empty($orderby_array)) { |
|
365 | 365 | $orderby_array[] = "id $order"; |
366 | 366 | } |
367 | 367 | |
368 | - $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array ); |
|
368 | + $this->query_orderby = 'ORDER BY ' . implode(', ', $orderby_array); |
|
369 | 369 | |
370 | 370 | } |
371 | 371 | |
@@ -379,34 +379,34 @@ discard block |
||
379 | 379 | public function query() { |
380 | 380 | global $wpdb; |
381 | 381 | |
382 | - $qv =& $this->query_vars; |
|
382 | + $qv = & $this->query_vars; |
|
383 | 383 | |
384 | 384 | // Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the |
385 | 385 | // total_subscriptions property. |
386 | - $this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) ); |
|
386 | + $this->results = apply_filters_ref_array('getpaid_subscriptions_pre_query', array(null, &$this)); |
|
387 | 387 | |
388 | - if ( null === $this->results ) { |
|
388 | + if (null === $this->results) { |
|
389 | 389 | $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; |
390 | 390 | |
391 | - if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) { |
|
392 | - $this->results = $wpdb->get_results( $this->request ); |
|
391 | + if ((is_array($qv['fields']) && 1 != count($qv['fields'])) || 'all' == $qv['fields']) { |
|
392 | + $this->results = $wpdb->get_results($this->request); |
|
393 | 393 | } else { |
394 | - $this->results = $wpdb->get_col( $this->request ); |
|
394 | + $this->results = $wpdb->get_col($this->request); |
|
395 | 395 | } |
396 | 396 | |
397 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
398 | - $found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this ); |
|
399 | - $this->total_subscriptions = (int) $wpdb->get_var( $found_subscriptions_query ); |
|
397 | + if (isset($qv['count_total']) && $qv['count_total']) { |
|
398 | + $found_subscriptions_query = apply_filters('getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this); |
|
399 | + $this->total_subscriptions = (int) $wpdb->get_var($found_subscriptions_query); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | - if ( 'all' == $qv['fields'] ) { |
|
404 | - foreach ( $this->results as $key => $subscription ) { |
|
405 | - wp_cache_set( $subscription->id, $subscription, 'getpaid_subscriptions' ); |
|
406 | - wp_cache_set( $subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
407 | - wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
408 | - wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
409 | - $this->results[ $key ] = new WPInv_Subscription( $subscription ); |
|
403 | + if ('all' == $qv['fields']) { |
|
404 | + foreach ($this->results as $key => $subscription) { |
|
405 | + wp_cache_set($subscription->id, $subscription, 'getpaid_subscriptions'); |
|
406 | + wp_cache_set($subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
407 | + wp_cache_set($subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
408 | + wp_cache_set($subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
409 | + $this->results[$key] = new WPInv_Subscription($subscription); |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | * @param string $query_var Query variable key. |
421 | 421 | * @return mixed |
422 | 422 | */ |
423 | - public function get( $query_var ) { |
|
424 | - if ( isset( $this->query_vars[ $query_var ] ) ) { |
|
425 | - return $this->query_vars[ $query_var ]; |
|
423 | + public function get($query_var) { |
|
424 | + if (isset($this->query_vars[$query_var])) { |
|
425 | + return $this->query_vars[$query_var]; |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | return null; |
@@ -436,8 +436,8 @@ discard block |
||
436 | 436 | * @param string $query_var Query variable key. |
437 | 437 | * @param mixed $value Query variable value. |
438 | 438 | */ |
439 | - public function set( $query_var, $value ) { |
|
440 | - $this->query_vars[ $query_var ] = $value; |
|
439 | + public function set($query_var, $value) { |
|
440 | + $this->query_vars[$query_var] = $value; |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -471,16 +471,16 @@ discard block |
||
471 | 471 | * @param string $table The current table. |
472 | 472 | * @return string Value to use in the ORDER clause, if `$orderby` is valid. |
473 | 473 | */ |
474 | - protected function parse_orderby( $orderby, $table ) { |
|
474 | + protected function parse_orderby($orderby, $table) { |
|
475 | 475 | |
476 | 476 | $_orderby = ''; |
477 | - if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) { |
|
477 | + if (in_array($orderby, array('customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id'))) { |
|
478 | 478 | $_orderby = "$table.`$orderby`"; |
479 | - } elseif ( 'id' === strtolower( $orderby ) ) { |
|
479 | + } elseif ('id' === strtolower($orderby)) { |
|
480 | 480 | $_orderby = "$table.id"; |
481 | - } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { |
|
482 | - $include = wp_parse_id_list( $this->query_vars['include'] ); |
|
483 | - $include_sql = implode( ',', $include ); |
|
481 | + } elseif ('include' === $orderby && !empty($this->query_vars['include'])) { |
|
482 | + $include = wp_parse_id_list($this->query_vars['include']); |
|
483 | + $include_sql = implode(',', $include); |
|
484 | 484 | $_orderby = "FIELD( $table.id, $include_sql )"; |
485 | 485 | } |
486 | 486 | |
@@ -495,12 +495,12 @@ discard block |
||
495 | 495 | * @param string $order The 'order' query variable. |
496 | 496 | * @return string The sanitized 'order' query variable. |
497 | 497 | */ |
498 | - protected function parse_order( $order ) { |
|
499 | - if ( ! is_string( $order ) || empty( $order ) ) { |
|
498 | + protected function parse_order($order) { |
|
499 | + if (!is_string($order) || empty($order)) { |
|
500 | 500 | return 'DESC'; |
501 | 501 | } |
502 | 502 | |
503 | - if ( 'ASC' === strtoupper( $order ) ) { |
|
503 | + if ('ASC' === strtoupper($order)) { |
|
504 | 504 | return 'ASC'; |
505 | 505 | } else { |
506 | 506 | return 'DESC'; |
@@ -43,77 +43,77 @@ discard block |
||
43 | 43 | <td class="w-75"> |
44 | 44 | <?php |
45 | 45 | |
46 | - switch ( $key ) { |
|
46 | + switch ( $key ) { |
|
47 | 47 | |
48 | - case 'status': |
|
49 | - echo sanitize_text_field( $subscription->get_status_label() ); |
|
50 | - break; |
|
48 | + case 'status': |
|
49 | + echo sanitize_text_field( $subscription->get_status_label() ); |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'start_date': |
|
53 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
54 | - break; |
|
52 | + case 'start_date': |
|
53 | + echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
54 | + break; |
|
55 | 55 | |
56 | - case 'expiry_date': |
|
57 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
58 | - break; |
|
56 | + case 'expiry_date': |
|
57 | + echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
58 | + break; |
|
59 | 59 | |
60 | - case 'initial_amount': |
|
61 | - echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
60 | + case 'initial_amount': |
|
61 | + echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
62 | 62 | |
63 | - if ( $subscription->has_trial_period() ) { |
|
63 | + if ( $subscription->has_trial_period() ) { |
|
64 | 64 | |
65 | - echo "<small class='text-muted'> "; |
|
66 | - printf( |
|
67 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
68 | - sanitize_text_field( $subscription->get_trial_period() ) |
|
69 | - ); |
|
70 | - echo '</small>'; |
|
65 | + echo "<small class='text-muted'> "; |
|
66 | + printf( |
|
67 | + _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
68 | + sanitize_text_field( $subscription->get_trial_period() ) |
|
69 | + ); |
|
70 | + echo '</small>'; |
|
71 | 71 | |
72 | - } |
|
72 | + } |
|
73 | 73 | |
74 | - break; |
|
74 | + break; |
|
75 | 75 | |
76 | - case 'recurring_amount': |
|
77 | - $frequency = sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ); |
|
78 | - $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
79 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
80 | - break; |
|
76 | + case 'recurring_amount': |
|
77 | + $frequency = sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ); |
|
78 | + $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
79 | + echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
80 | + break; |
|
81 | 81 | |
82 | - case 'invoice': |
|
83 | - $invoice = $subscription->get_parent_invoice(); |
|
82 | + case 'invoice': |
|
83 | + $invoice = $subscription->get_parent_invoice(); |
|
84 | 84 | |
85 | - if ( $invoice->get_id() ) { |
|
86 | - $view_url = esc_url( $invoice->get_view_url() ); |
|
87 | - $number = sanitize_text_field( $invoice->get_number() ); |
|
88 | - echo "<a href='$view_url' class='text-decoration-none'>$number</a>"; |
|
89 | - } else { |
|
90 | - echo "—"; |
|
91 | - } |
|
85 | + if ( $invoice->get_id() ) { |
|
86 | + $view_url = esc_url( $invoice->get_view_url() ); |
|
87 | + $number = sanitize_text_field( $invoice->get_number() ); |
|
88 | + echo "<a href='$view_url' class='text-decoration-none'>$number</a>"; |
|
89 | + } else { |
|
90 | + echo "—"; |
|
91 | + } |
|
92 | 92 | |
93 | - break; |
|
93 | + break; |
|
94 | 94 | |
95 | - case 'item': |
|
96 | - $item = get_post( $subscription->get_product_id() ); |
|
95 | + case 'item': |
|
96 | + $item = get_post( $subscription->get_product_id() ); |
|
97 | 97 | |
98 | - if ( ! empty( $item ) ) { |
|
99 | - echo esc_html( get_the_title( $item ) ); |
|
100 | - } else { |
|
101 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
102 | - } |
|
98 | + if ( ! empty( $item ) ) { |
|
99 | + echo esc_html( get_the_title( $item ) ); |
|
100 | + } else { |
|
101 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
102 | + } |
|
103 | 103 | |
104 | - break; |
|
104 | + break; |
|
105 | 105 | |
106 | - case 'payments': |
|
106 | + case 'payments': |
|
107 | 107 | |
108 | - $max_activations = (int) $subscription->get_bill_times(); |
|
109 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
108 | + $max_activations = (int) $subscription->get_bill_times(); |
|
109 | + echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
110 | 110 | |
111 | - break; |
|
111 | + break; |
|
112 | 112 | |
113 | - } |
|
114 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
113 | + } |
|
114 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
115 | 115 | |
116 | - ?> |
|
116 | + ?> |
|
117 | 117 | </td> |
118 | 118 | |
119 | 119 | </tr> |
@@ -125,28 +125,28 @@ discard block |
||
125 | 125 | |
126 | 126 | <?php |
127 | 127 | |
128 | - $payments = $subscription->get_child_payments(); |
|
129 | - $parent = $subscription->get_parent_invoice(); |
|
128 | + $payments = $subscription->get_child_payments(); |
|
129 | + $parent = $subscription->get_parent_invoice(); |
|
130 | 130 | |
131 | - if ( $parent->get_id() ) { |
|
132 | - $payments = array_merge( array( $parent ), $payments ); |
|
133 | - } |
|
131 | + if ( $parent->get_id() ) { |
|
132 | + $payments = array_merge( array( $parent ), $payments ); |
|
133 | + } |
|
134 | 134 | |
135 | - if ( empty( $payments ) ) { |
|
136 | - return; |
|
137 | - } |
|
135 | + if ( empty( $payments ) ) { |
|
136 | + return; |
|
137 | + } |
|
138 | 138 | |
139 | - $title = __( 'Related Invoices', 'invoicing' ); |
|
139 | + $title = __( 'Related Invoices', 'invoicing' ); |
|
140 | 140 | |
141 | - echo "<h2 class='mt-4 mb-1 h4'>$title</h2>"; |
|
141 | + echo "<h2 class='mt-4 mb-1 h4'>$title</h2>"; |
|
142 | 142 | |
143 | - foreach ( $payments as $payment ) { |
|
144 | - $payment = new WPInv_Invoice( $payment ); |
|
145 | - $number = sanitize_text_field( $payment->get_number() ); |
|
146 | - $url = esc_url( $payment->get_view_url() ); |
|
147 | - $date = sanitize_text_field( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
148 | - $status = $payment->get_status_nicename(); |
|
149 | - $amount = wpinv_price( wpinv_format_amount( $payment->get_total() ), $payment->get_currency() ); |
|
150 | - } |
|
143 | + foreach ( $payments as $payment ) { |
|
144 | + $payment = new WPInv_Invoice( $payment ); |
|
145 | + $number = sanitize_text_field( $payment->get_number() ); |
|
146 | + $url = esc_url( $payment->get_view_url() ); |
|
147 | + $date = sanitize_text_field( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
148 | + $status = $payment->get_status_nicename(); |
|
149 | + $amount = wpinv_price( wpinv_format_amount( $payment->get_total() ), $payment->get_currency() ); |
|
150 | + } |
|
151 | 151 | |
152 | 152 | ?> |
@@ -9,14 +9,14 @@ discard block |
||
9 | 9 | * @var WPInv_Subscriptions_Widget $widget |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | -do_action( 'getpaid_single_subscription_before_notices', $subscription ); |
|
14 | +do_action('getpaid_single_subscription_before_notices', $subscription); |
|
15 | 15 | |
16 | 16 | // Display errors and notices. |
17 | 17 | wpinv_print_errors(); |
18 | 18 | |
19 | -do_action( 'getpaid_before_single_subscription', $subscription ); |
|
19 | +do_action('getpaid_before_single_subscription', $subscription); |
|
20 | 20 | |
21 | 21 | ?> |
22 | 22 | |
@@ -28,44 +28,44 @@ discard block |
||
28 | 28 | |
29 | 29 | </style> |
30 | 30 | |
31 | -<h2 class="mb-1 h4"><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
31 | +<h2 class="mb-1 h4"><?php _e('Subscription Details', 'invoicing'); ?></h2> |
|
32 | 32 | <table class="table table-bordered table-striped"> |
33 | 33 | <tbody> |
34 | 34 | |
35 | - <?php foreach ( $widget->get_single_subscription_columns( $subscription ) as $key => $label ) : ?> |
|
35 | + <?php foreach ($widget->get_single_subscription_columns($subscription) as $key => $label) : ?> |
|
36 | 36 | |
37 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
37 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
38 | 38 | |
39 | 39 | <th class="w-25" style="font-weight: 500;"> |
40 | - <?php echo sanitize_text_field( $label ); ?> |
|
40 | + <?php echo sanitize_text_field($label); ?> |
|
41 | 41 | </th> |
42 | 42 | |
43 | 43 | <td class="w-75"> |
44 | 44 | <?php |
45 | 45 | |
46 | - switch ( $key ) { |
|
46 | + switch ($key) { |
|
47 | 47 | |
48 | 48 | case 'status': |
49 | - echo sanitize_text_field( $subscription->get_status_label() ); |
|
49 | + echo sanitize_text_field($subscription->get_status_label()); |
|
50 | 50 | break; |
51 | 51 | |
52 | 52 | case 'start_date': |
53 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
53 | + echo sanitize_text_field(getpaid_format_date_value($subscription->get_date_created())); |
|
54 | 54 | break; |
55 | 55 | |
56 | 56 | case 'expiry_date': |
57 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
57 | + echo sanitize_text_field(getpaid_format_date_value($subscription->get_next_renewal_date())); |
|
58 | 58 | break; |
59 | 59 | |
60 | 60 | case 'initial_amount': |
61 | - echo wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
61 | + echo wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency()); |
|
62 | 62 | |
63 | - if ( $subscription->has_trial_period() ) { |
|
63 | + if ($subscription->has_trial_period()) { |
|
64 | 64 | |
65 | 65 | echo "<small class='text-muted'> "; |
66 | 66 | printf( |
67 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
68 | - sanitize_text_field( $subscription->get_trial_period() ) |
|
67 | + _x('( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing'), |
|
68 | + sanitize_text_field($subscription->get_trial_period()) |
|
69 | 69 | ); |
70 | 70 | echo '</small>'; |
71 | 71 | |
@@ -74,17 +74,17 @@ discard block |
||
74 | 74 | break; |
75 | 75 | |
76 | 76 | case 'recurring_amount': |
77 | - $frequency = sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ); |
|
78 | - $amount = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
79 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / $frequency" ); |
|
77 | + $frequency = sanitize_text_field(WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->get_period(), $subscription->get_frequency(), true)); |
|
78 | + $amount = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency()); |
|
79 | + echo strtolower("<strong style='font-weight: 500;'>$amount</strong> / $frequency"); |
|
80 | 80 | break; |
81 | 81 | |
82 | 82 | case 'invoice': |
83 | 83 | $invoice = $subscription->get_parent_invoice(); |
84 | 84 | |
85 | - if ( $invoice->get_id() ) { |
|
86 | - $view_url = esc_url( $invoice->get_view_url() ); |
|
87 | - $number = sanitize_text_field( $invoice->get_number() ); |
|
85 | + if ($invoice->get_id()) { |
|
86 | + $view_url = esc_url($invoice->get_view_url()); |
|
87 | + $number = sanitize_text_field($invoice->get_number()); |
|
88 | 88 | echo "<a href='$view_url' class='text-decoration-none'>$number</a>"; |
89 | 89 | } else { |
90 | 90 | echo "—"; |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | break; |
94 | 94 | |
95 | 95 | case 'item': |
96 | - $item = get_post( $subscription->get_product_id() ); |
|
96 | + $item = get_post($subscription->get_product_id()); |
|
97 | 97 | |
98 | - if ( ! empty( $item ) ) { |
|
99 | - echo esc_html( get_the_title( $item ) ); |
|
98 | + if (!empty($item)) { |
|
99 | + echo esc_html(get_the_title($item)); |
|
100 | 100 | } else { |
101 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
101 | + echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id()); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | break; |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | case 'payments': |
107 | 107 | |
108 | 108 | $max_activations = (int) $subscription->get_bill_times(); |
109 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
109 | + echo (int) $subscription->get_times_billed() . ' / ' . (empty($max_activations) ? "∞" : $max_activations); |
|
110 | 110 | |
111 | 111 | break; |
112 | 112 | |
113 | 113 | } |
114 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
114 | + do_action("getpaid_render_single_subscription_column_$key", $subscription); |
|
115 | 115 | |
116 | 116 | ?> |
117 | 117 | </td> |
@@ -128,25 +128,25 @@ discard block |
||
128 | 128 | $payments = $subscription->get_child_payments(); |
129 | 129 | $parent = $subscription->get_parent_invoice(); |
130 | 130 | |
131 | - if ( $parent->get_id() ) { |
|
132 | - $payments = array_merge( array( $parent ), $payments ); |
|
131 | + if ($parent->get_id()) { |
|
132 | + $payments = array_merge(array($parent), $payments); |
|
133 | 133 | } |
134 | 134 | |
135 | - if ( empty( $payments ) ) { |
|
135 | + if (empty($payments)) { |
|
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | - $title = __( 'Related Invoices', 'invoicing' ); |
|
139 | + $title = __('Related Invoices', 'invoicing'); |
|
140 | 140 | |
141 | 141 | echo "<h2 class='mt-4 mb-1 h4'>$title</h2>"; |
142 | 142 | |
143 | - foreach ( $payments as $payment ) { |
|
144 | - $payment = new WPInv_Invoice( $payment ); |
|
145 | - $number = sanitize_text_field( $payment->get_number() ); |
|
146 | - $url = esc_url( $payment->get_view_url() ); |
|
147 | - $date = sanitize_text_field( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
143 | + foreach ($payments as $payment) { |
|
144 | + $payment = new WPInv_Invoice($payment); |
|
145 | + $number = sanitize_text_field($payment->get_number()); |
|
146 | + $url = esc_url($payment->get_view_url()); |
|
147 | + $date = sanitize_text_field(getpaid_format_date_value($payment->get_date_created())); |
|
148 | 148 | $status = $payment->get_status_nicename(); |
149 | - $amount = wpinv_price( wpinv_format_amount( $payment->get_total() ), $payment->get_currency() ); |
|
149 | + $amount = wpinv_price(wpinv_format_amount($payment->get_total()), $payment->get_currency()); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | ?> |
@@ -13,38 +13,38 @@ |
||
13 | 13 | |
14 | 14 | foreach ( array_keys( $widget->get_subscriptions_table_columns() ) as $column ) : |
15 | 15 | |
16 | - $class = sanitize_html_class( $column ); |
|
17 | - echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
|
16 | + $class = sanitize_html_class( $column ); |
|
17 | + echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
|
18 | 18 | |
19 | - do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
19 | + do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
20 | 20 | |
21 | - switch( $column ) : |
|
21 | + switch( $column ) : |
|
22 | 22 | |
23 | - case 'subscription': |
|
24 | - $subscription_id = (int) $subscription->get_id(); |
|
25 | - $url = esc_url( add_query_arg( 'subscription', $subscription_id, get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
26 | - echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
27 | - break; |
|
23 | + case 'subscription': |
|
24 | + $subscription_id = (int) $subscription->get_id(); |
|
25 | + $url = esc_url( add_query_arg( 'subscription', $subscription_id, get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
26 | + echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
27 | + break; |
|
28 | 28 | |
29 | - case 'status': |
|
30 | - echo $subscription->get_status_label(); |
|
31 | - break; |
|
29 | + case 'status': |
|
30 | + echo $subscription->get_status_label(); |
|
31 | + break; |
|
32 | 32 | |
33 | - case 'renewal-date': |
|
34 | - $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
35 | - echo $subscription->is_active() ? $renewal : "—"; |
|
36 | - break; |
|
33 | + case 'renewal-date': |
|
34 | + $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
35 | + echo $subscription->is_active() ? $renewal : "—"; |
|
36 | + break; |
|
37 | 37 | |
38 | - case 'amount': |
|
39 | - $frequency = sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ); |
|
40 | - $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
41 | - echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
|
42 | - break; |
|
38 | + case 'amount': |
|
39 | + $frequency = sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ); |
|
40 | + $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
41 | + echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
|
42 | + break; |
|
43 | 43 | |
44 | - endswitch; |
|
44 | + endswitch; |
|
45 | 45 | |
46 | - do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
46 | + do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
47 | 47 | |
48 | - echo '</td>'; |
|
48 | + echo '</td>'; |
|
49 | 49 | |
50 | 50 | endforeach; |
@@ -9,21 +9,21 @@ discard block |
||
9 | 9 | * @var WPInv_Subscriptions_Widget $widget |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | -foreach ( array_keys( $widget->get_subscriptions_table_columns() ) as $column ) : |
|
14 | +foreach (array_keys($widget->get_subscriptions_table_columns()) as $column) : |
|
15 | 15 | |
16 | - $class = sanitize_html_class( $column ); |
|
16 | + $class = sanitize_html_class($column); |
|
17 | 17 | echo "<td class='getpaid-subscriptions-table-column-$class'>"; |
18 | 18 | |
19 | - do_action( "getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription ); |
|
19 | + do_action("getpaid_subscriptions_before_frontend_subscription_table_$column", $subscription); |
|
20 | 20 | |
21 | - switch( $column ) : |
|
21 | + switch ($column) : |
|
22 | 22 | |
23 | 23 | case 'subscription': |
24 | 24 | $subscription_id = (int) $subscription->get_id(); |
25 | - $url = esc_url( add_query_arg( 'subscription', $subscription_id, get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
26 | - echo $widget->add_row_actions( "<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription ); |
|
25 | + $url = esc_url(add_query_arg('subscription', $subscription_id, get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
26 | + echo $widget->add_row_actions("<a href='$url' class='text-decoration-none'>#$subscription_id</a>", $subscription); |
|
27 | 27 | break; |
28 | 28 | |
29 | 29 | case 'status': |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | break; |
32 | 32 | |
33 | 33 | case 'renewal-date': |
34 | - $renewal = getpaid_format_date_value( $subscription->get_next_renewal_date() ); |
|
34 | + $renewal = getpaid_format_date_value($subscription->get_next_renewal_date()); |
|
35 | 35 | echo $subscription->is_active() ? $renewal : "—"; |
36 | 36 | break; |
37 | 37 | |
38 | 38 | case 'amount': |
39 | - $frequency = sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ); |
|
40 | - $amount = wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $subscription->get_recurring_amount() ) ), $subscription->get_parent_payment()->get_currency() ); |
|
39 | + $frequency = sanitize_text_field(WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->get_period(), $subscription->get_frequency(), true)); |
|
40 | + $amount = wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($subscription->get_recurring_amount())), $subscription->get_parent_payment()->get_currency()); |
|
41 | 41 | echo "<strong style='font-weight: 500;'>$amount</strong> / $frequency"; |
42 | 42 | break; |
43 | 43 | |
44 | 44 | endswitch; |
45 | 45 | |
46 | - do_action( "getpaid_subscriptions_frontend_subscription_table_$column", $subscription ); |
|
46 | + do_action("getpaid_subscriptions_frontend_subscription_table_$column", $subscription); |
|
47 | 47 | |
48 | 48 | echo '</td>'; |
49 | 49 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | /** |
9 | 9 | * Main Subscriptions class. |
10 | 10 | * |
@@ -14,25 +14,25 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * Class constructor. |
16 | 16 | */ |
17 | - public function __construct(){ |
|
17 | + public function __construct() { |
|
18 | 18 | |
19 | 19 | // Fire gateway specific hooks when a subscription changes. |
20 | - add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 ); |
|
20 | + add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3); |
|
21 | 21 | |
22 | 22 | // Handles subscription cancelations. |
23 | - add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) ); |
|
23 | + add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription')); |
|
24 | 24 | |
25 | 25 | // Create a subscription whenever an invoice is created, (and update it when it is updated). |
26 | - add_action( 'getpaid_new_invoice', array( $this, 'maybe_create_invoice_subscription' ) ); |
|
27 | - add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ) ); |
|
26 | + add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription')); |
|
27 | + add_action('getpaid_update_invoice', array($this, 'maybe_update_invoice_subscription')); |
|
28 | 28 | |
29 | 29 | // Handles admin subscription update actions. |
30 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
31 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
32 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) ); |
|
30 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
31 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
32 | + add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription')); |
|
33 | 33 | |
34 | 34 | // Filter invoice item row actions. |
35 | - add_action( 'getpaid-invoice-page-line-item-actions', array( $this, 'filter_invoice_line_item_actions' ), 10, 3 ); |
|
35 | + add_action('getpaid-invoice-page-line-item-actions', array($this, 'filter_invoice_line_item_actions'), 10, 3); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | * @param string $from |
43 | 43 | * @param string $to |
44 | 44 | */ |
45 | - public function process_subscription_status_change( $subscription, $from, $to ) { |
|
45 | + public function process_subscription_status_change($subscription, $from, $to) { |
|
46 | 46 | |
47 | 47 | $gateway = $subscription->get_gateway(); |
48 | 48 | |
49 | - if ( ! empty( $gateway ) ) { |
|
50 | - $gateway = sanitize_key( $gateway ); |
|
51 | - $from = sanitize_key( $from ); |
|
52 | - $to = sanitize_key( $to ); |
|
53 | - do_action( "getpaid_{$gateway}subscription_$to", $subscription, $from ); |
|
49 | + if (!empty($gateway)) { |
|
50 | + $gateway = sanitize_key($gateway); |
|
51 | + $from = sanitize_key($from); |
|
52 | + $to = sanitize_key($to); |
|
53 | + do_action("getpaid_{$gateway}subscription_$to", $subscription, $from); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | } |
@@ -62,38 +62,38 @@ discard block |
||
62 | 62 | * @param int $frequency_count The frequency of the period. |
63 | 63 | * @return mixed|string|void |
64 | 64 | */ |
65 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1, $skip_1 = false ) { |
|
65 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1, $skip_1 = false) { |
|
66 | 66 | |
67 | 67 | $frequency = ''; |
68 | 68 | |
69 | 69 | //Format period details |
70 | - switch ( strtolower( $period ) ) { |
|
70 | + switch (strtolower($period)) { |
|
71 | 71 | case 'day' : |
72 | 72 | case 'd' : |
73 | - $frequency = sprintf( _n( '%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
73 | + $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
74 | 74 | break; |
75 | 75 | case 'week' : |
76 | 76 | case 'w' : |
77 | - $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
77 | + $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
78 | 78 | break; |
79 | 79 | case 'month' : |
80 | 80 | case 'm' : |
81 | - $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
81 | + $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
82 | 82 | break; |
83 | 83 | case 'year' : |
84 | 84 | case 'y' : |
85 | - $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
85 | + $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
86 | 86 | break; |
87 | 87 | default : |
88 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count ); |
|
88 | + $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); |
|
89 | 89 | break; |
90 | 90 | } |
91 | 91 | |
92 | - if ( $skip_1 && 1 == $frequency_count ) { |
|
93 | - $frequency = str_replace( '1', '', $frequency ); |
|
92 | + if ($skip_1 && 1 == $frequency_count) { |
|
93 | + $frequency = str_replace('1', '', $frequency); |
|
94 | 94 | } |
95 | 95 | |
96 | - return trim( $frequency ); |
|
96 | + return trim($frequency); |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | |
@@ -104,29 +104,29 @@ discard block |
||
104 | 104 | * @since 1.0.0 |
105 | 105 | * @return void |
106 | 106 | */ |
107 | - public function user_cancel_single_subscription( $data ) { |
|
107 | + public function user_cancel_single_subscription($data) { |
|
108 | 108 | |
109 | 109 | // Ensure there is a subscription to cancel. |
110 | - if ( empty( $data['sub_id'] ) ) { |
|
110 | + if (empty($data['sub_id'])) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | 113 | |
114 | - $subscription = new WPInv_Subscription( (int) $data['sub_id'] ); |
|
114 | + $subscription = new WPInv_Subscription((int) $data['sub_id']); |
|
115 | 115 | |
116 | 116 | // Ensure that it exists and that it belongs to the current user. |
117 | - if ( ! $subscription->get_id() || $subscription->get_customer_id() != get_current_user_id() ) { |
|
118 | - wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) ); |
|
117 | + if (!$subscription->get_id() || $subscription->get_customer_id() != get_current_user_id()) { |
|
118 | + wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing')); |
|
119 | 119 | |
120 | 120 | // Can it be cancelled. |
121 | - } else if ( ! $subscription->can_cancel() ) { |
|
122 | - wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) ); |
|
121 | + } else if (!$subscription->can_cancel()) { |
|
122 | + wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing')); |
|
123 | 123 | |
124 | 124 | |
125 | 125 | // Cancel it. |
126 | 126 | } else { |
127 | 127 | |
128 | 128 | $subscription->cancel(); |
129 | - wpinv_set_error( 'cancelled', __( 'This subscription is now cancelled.', 'invoicing' ), 'info' ); |
|
129 | + wpinv_set_error('cancelled', __('This subscription is now cancelled.', 'invoicing'), 'info'); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | ) |
139 | 139 | ); |
140 | 140 | |
141 | - wp_safe_redirect( esc_url( $redirect ) ); |
|
141 | + wp_safe_redirect(esc_url($redirect)); |
|
142 | 142 | exit; |
143 | 143 | |
144 | 144 | } |
@@ -150,15 +150,15 @@ discard block |
||
150 | 150 | * @param WPInv_Invoice $invoice |
151 | 151 | * @since 1.0.0 |
152 | 152 | */ |
153 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
153 | + public function maybe_create_invoice_subscription($invoice) { |
|
154 | 154 | |
155 | 155 | // Abort if it is not recurring. |
156 | - if ( $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
156 | + if ($invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
157 | 157 | return; |
158 | 158 | } |
159 | 159 | |
160 | 160 | $subscription = new WPInv_Subscription(); |
161 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
161 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
162 | 162 | |
163 | 163 | } |
164 | 164 | |
@@ -169,33 +169,33 @@ discard block |
||
169 | 169 | * @param WPInv_Invoice $invoice |
170 | 170 | * @since 1.0.19 |
171 | 171 | */ |
172 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
172 | + public function maybe_update_invoice_subscription($invoice) { |
|
173 | 173 | |
174 | 174 | // Do not process renewals. |
175 | - if ( $invoice->is_renewal() ) { |
|
175 | + if ($invoice->is_renewal()) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | 179 | // (Maybe) create a new subscription. |
180 | - if ( ! $invoice->get_subscription_id() ) { |
|
181 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
180 | + if (!$invoice->get_subscription_id()) { |
|
181 | + return $this->maybe_create_invoice_subscription($invoice); |
|
182 | 182 | } |
183 | 183 | |
184 | - $subscription = new WPInv_Subscription( $invoice->get_subscription_id() ); |
|
184 | + $subscription = new WPInv_Subscription($invoice->get_subscription_id()); |
|
185 | 185 | |
186 | 186 | // In case the subscription was deleted... |
187 | - if ( ! $subscription->get_id() ) { |
|
187 | + if (!$subscription->get_id()) { |
|
188 | 188 | $invoice->set_subscription_id(0); |
189 | 189 | $invoice->save(); |
190 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
190 | + return $this->maybe_create_invoice_subscription($invoice); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // Abort if an invoice is paid and already has a subscription. |
194 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
194 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
195 | 195 | return; |
196 | 196 | } |
197 | 197 | |
198 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
198 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
199 | 199 | |
200 | 200 | } |
201 | 201 | |
@@ -207,53 +207,53 @@ discard block |
||
207 | 207 | * @param WPInv_Invoice $invoice |
208 | 208 | * @since 1.0.19 |
209 | 209 | */ |
210 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
210 | + public function update_invoice_subscription($subscription, $invoice) { |
|
211 | 211 | |
212 | 212 | // Delete the subscription if an invoice is free. |
213 | - if ( $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
213 | + if ($invoice->is_free() || !$invoice->is_recurring()) { |
|
214 | 214 | return $subscription->delete(); |
215 | 215 | } |
216 | 216 | |
217 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
218 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
219 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
220 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
221 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
222 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
217 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
218 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
219 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
220 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
221 | + $subscription->set_date_created(current_time('mysql')); |
|
222 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
223 | 223 | |
224 | 224 | // Get the recurring item and abort if it does not exist. |
225 | - $subscription_item = $invoice->get_recurring( true ); |
|
226 | - if ( ! $subscription_item->get_id() ) { |
|
225 | + $subscription_item = $invoice->get_recurring(true); |
|
226 | + if (!$subscription_item->get_id()) { |
|
227 | 227 | return $subscription->delete(); |
228 | 228 | } |
229 | 229 | |
230 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
231 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
232 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
233 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
230 | + $subscription->set_product_id($subscription_item->get_id()); |
|
231 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
232 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
233 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
234 | 234 | |
235 | 235 | // Calculate the next renewal date. |
236 | - $period = $subscription_item->get_recurring_period( true ); |
|
236 | + $period = $subscription_item->get_recurring_period(true); |
|
237 | 237 | $interval = $subscription_item->get_recurring_interval(); |
238 | 238 | |
239 | 239 | // If the subscription item has a trial period... |
240 | - if ( $subscription_item->has_free_trial() ) { |
|
241 | - $period = $subscription_item->get_trial_period( true ); |
|
240 | + if ($subscription_item->has_free_trial()) { |
|
241 | + $period = $subscription_item->get_trial_period(true); |
|
242 | 242 | $interval = $subscription_item->get_trial_interval(); |
243 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
244 | - $subscription->set_status( 'trialling' ); |
|
243 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
244 | + $subscription->set_status('trialling'); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
248 | - if ( $invoice->has_free_trial() ) { |
|
249 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
250 | - $subscription->set_status( 'trialling' ); |
|
248 | + if ($invoice->has_free_trial()) { |
|
249 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
250 | + $subscription->set_status('trialling'); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | // Calculate the next renewal date. |
254 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+ $interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
254 | + $expiration = date('Y-m-d H:i:s', strtotime("+ $interval $period", strtotime($subscription->get_date_created()))); |
|
255 | 255 | |
256 | - $subscription->set_next_renewal_date( $expiration ); |
|
256 | + $subscription->set_next_renewal_date($expiration); |
|
257 | 257 | return $subscription->save(); |
258 | 258 | |
259 | 259 | } |
@@ -264,21 +264,21 @@ discard block |
||
264 | 264 | * @param array $data |
265 | 265 | * @since 1.0.19 |
266 | 266 | */ |
267 | - public function admin_update_single_subscription( $args ) { |
|
267 | + public function admin_update_single_subscription($args) { |
|
268 | 268 | |
269 | 269 | // Ensure the subscription exists and that a status has been given. |
270 | - if ( empty( $args['subscription_id'] ) || empty( $args['subscription_status'] ) ) { |
|
270 | + if (empty($args['subscription_id']) || empty($args['subscription_status'])) { |
|
271 | 271 | return; |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Retrieve the subscriptions. |
275 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
275 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
276 | 276 | |
277 | - if ( $subscription->get_id() ) { |
|
277 | + if ($subscription->get_id()) { |
|
278 | 278 | |
279 | - $subscription->set_status( $args['subscription_status'] ); |
|
279 | + $subscription->set_status($args['subscription_status']); |
|
280 | 280 | $subscription->save(); |
281 | - getpaid_admin()->show_info( __( 'Your changes have been saved', 'invoicing' ) ); |
|
281 | + getpaid_admin()->show_info(__('Your changes have been saved', 'invoicing')); |
|
282 | 282 | |
283 | 283 | } |
284 | 284 | |
@@ -290,25 +290,25 @@ discard block |
||
290 | 290 | * @param array $data |
291 | 291 | * @since 1.0.19 |
292 | 292 | */ |
293 | - public function admin_renew_single_subscription( $args ) { |
|
293 | + public function admin_renew_single_subscription($args) { |
|
294 | 294 | |
295 | 295 | // Ensure the subscription exists and that a status has been given. |
296 | - if ( empty( $args['id'] ) ) { |
|
296 | + if (empty($args['id'])) { |
|
297 | 297 | return; |
298 | 298 | } |
299 | 299 | |
300 | 300 | // Retrieve the subscriptions. |
301 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
301 | + $subscription = new WPInv_Subscription($args['id']); |
|
302 | 302 | |
303 | - if ( $subscription->get_id() ) { |
|
303 | + if ($subscription->get_id()) { |
|
304 | 304 | |
305 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
305 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
306 | 306 | |
307 | - if ( $subscription->add_payment( $args ) ) { |
|
307 | + if ($subscription->add_payment($args)) { |
|
308 | 308 | $subscription->renew(); |
309 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
309 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
310 | 310 | } else { |
311 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
311 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | wp_safe_redirect( |
@@ -331,20 +331,20 @@ discard block |
||
331 | 331 | * @param array $data |
332 | 332 | * @since 1.0.19 |
333 | 333 | */ |
334 | - public function admin_delete_single_subscription( $args ) { |
|
334 | + public function admin_delete_single_subscription($args) { |
|
335 | 335 | |
336 | 336 | // Ensure the subscription exists and that a status has been given. |
337 | - if ( empty( $args['id'] ) ) { |
|
337 | + if (empty($args['id'])) { |
|
338 | 338 | return; |
339 | 339 | } |
340 | 340 | |
341 | 341 | // Retrieve the subscriptions. |
342 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
342 | + $subscription = new WPInv_Subscription($args['id']); |
|
343 | 343 | |
344 | - if ( $subscription->delete() ) { |
|
345 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
344 | + if ($subscription->delete()) { |
|
345 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
346 | 346 | } else { |
347 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
347 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | $redirected = wp_safe_redirect( |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | ) |
358 | 358 | ); |
359 | 359 | |
360 | - if ( $redirected ) { |
|
360 | + if ($redirected) { |
|
361 | 361 | exit; |
362 | 362 | } |
363 | 363 | |
@@ -370,10 +370,10 @@ discard block |
||
370 | 370 | * @param WPInv_Item $item |
371 | 371 | * @param WPInv_Invoice $invoice |
372 | 372 | */ |
373 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
373 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
374 | 374 | |
375 | 375 | // Fetch item subscription. |
376 | - $args = array( |
|
376 | + $args = array( |
|
377 | 377 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
378 | 378 | 'item_in' => $item->get_id(), |
379 | 379 | 'number' => 1, |
@@ -381,13 +381,13 @@ discard block |
||
381 | 381 | 'fields' => 'id', |
382 | 382 | ); |
383 | 383 | |
384 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
384 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
385 | 385 | $subscription = $subscription->get_results(); |
386 | 386 | |
387 | 387 | // In case we found a match... |
388 | - if ( ! empty( $subscription ) ) { |
|
389 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
390 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'getpaid-license-manager' ) . '</a>'; |
|
388 | + if (!empty($subscription)) { |
|
389 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
390 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'getpaid-license-manager') . '</a>'; |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | return $actions; |
@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, watermark, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - return getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + return getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,56 +170,56 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) |
|
182 | + if (isset($name)) |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | $templates[] = $slug . '.php'; |
185 | 185 | |
186 | 186 | // Allow template parts to be filtered |
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
188 | 188 | |
189 | 189 | // Return the part that is found |
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + return wpinv_locate_tmpl($templates, $load, false); |
|
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
193 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
194 | 194 | // No file found yet |
195 | 195 | $located = false; |
196 | 196 | |
197 | 197 | // Try to find a template file |
198 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + foreach ((array) $template_names as $template_name) { |
|
199 | 199 | |
200 | 200 | // Continue if template is empty |
201 | - if ( empty( $template_name ) ) |
|
201 | + if (empty($template_name)) |
|
202 | 202 | continue; |
203 | 203 | |
204 | 204 | // Trim off any slashes from the template name |
205 | - $template_name = ltrim( $template_name, '/' ); |
|
205 | + $template_name = ltrim($template_name, '/'); |
|
206 | 206 | |
207 | 207 | // try locating this template file by looping through the template paths |
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
208 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
210 | + if (file_exists($template_path . $template_name)) { |
|
211 | 211 | $located = $template_path . $template_name; |
212 | 212 | break; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
216 | + if (!empty($located)) { |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ((true == $load) && !empty($located)) |
|
222 | + load_template($located, $require_once); |
|
223 | 223 | |
224 | 224 | return $located; |
225 | 225 | } |
@@ -228,155 +228,155 @@ discard block |
||
228 | 228 | $template_dir = wpinv_get_theme_template_dir_name(); |
229 | 229 | |
230 | 230 | $file_paths = array( |
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
231 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
232 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
233 | 233 | 100 => wpinv_get_templates_dir() |
234 | 234 | ); |
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
237 | 237 | |
238 | 238 | // sort the file paths based on priority |
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
239 | + ksort($file_paths, SORT_NUMERIC); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map('trailingslashit', $file_paths); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | 246 | $pages = array(); |
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
247 | + $pages[] = wpinv_get_option('success_page'); |
|
248 | + $pages[] = wpinv_get_option('failure_page'); |
|
249 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
250 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
252 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
253 | 253 | return; |
254 | 254 | } |
255 | 255 | |
256 | 256 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
257 | 257 | } |
258 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
258 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
259 | 259 | |
260 | -function wpinv_add_body_classes( $class ) { |
|
261 | - $classes = (array)$class; |
|
260 | +function wpinv_add_body_classes($class) { |
|
261 | + $classes = (array) $class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
263 | + if (wpinv_is_checkout()) { |
|
264 | 264 | $classes[] = 'wpinv-checkout'; |
265 | 265 | $classes[] = 'wpinv-page'; |
266 | 266 | } |
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
268 | + if (wpinv_is_success_page()) { |
|
269 | 269 | $classes[] = 'wpinv-success'; |
270 | 270 | $classes[] = 'wpinv-page'; |
271 | 271 | } |
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
273 | + if (wpinv_is_failed_transaction_page()) { |
|
274 | 274 | $classes[] = 'wpinv-failed-transaction'; |
275 | 275 | $classes[] = 'wpinv-page'; |
276 | 276 | } |
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
278 | + if (wpinv_is_invoice_history_page()) { |
|
279 | 279 | $classes[] = 'wpinv-history'; |
280 | 280 | $classes[] = 'wpinv-page'; |
281 | 281 | } |
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
283 | + if (wpinv_is_subscriptions_history_page()) { |
|
284 | 284 | $classes[] = 'wpinv-subscription'; |
285 | 285 | $classes[] = 'wpinv-page'; |
286 | 286 | } |
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
288 | + if (wpinv_is_test_mode()) { |
|
289 | 289 | $classes[] = 'wpinv-test-mode'; |
290 | 290 | $classes[] = 'wpinv-page'; |
291 | 291 | } |
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique($classes); |
|
294 | 294 | } |
295 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
295 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
296 | 296 | |
297 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
298 | - $args = array( 'nopaging' => true ); |
|
297 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
298 | + $args = array('nopaging' => true); |
|
299 | 299 | |
300 | - if ( ! empty( $status ) ) |
|
300 | + if (!empty($status)) |
|
301 | 301 | $args['post_status'] = $status; |
302 | 302 | |
303 | - $discounts = wpinv_get_discounts( $args ); |
|
303 | + $discounts = wpinv_get_discounts($args); |
|
304 | 304 | $options = array(); |
305 | 305 | |
306 | - if ( $discounts ) { |
|
307 | - foreach ( $discounts as $discount ) { |
|
308 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
306 | + if ($discounts) { |
|
307 | + foreach ($discounts as $discount) { |
|
308 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
309 | 309 | } |
310 | 310 | } else { |
311 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
311 | + $options[0] = __('No discounts found', 'invoicing'); |
|
312 | 312 | } |
313 | 313 | |
314 | - $output = wpinv_html_select( array( |
|
314 | + $output = wpinv_html_select(array( |
|
315 | 315 | 'name' => $name, |
316 | 316 | 'selected' => $selected, |
317 | 317 | 'options' => $options, |
318 | 318 | 'show_option_all' => false, |
319 | 319 | 'show_option_none' => false, |
320 | - ) ); |
|
320 | + )); |
|
321 | 321 | |
322 | 322 | return $output; |
323 | 323 | } |
324 | 324 | |
325 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
326 | - $current = date( 'Y' ); |
|
327 | - $start_year = $current - absint( $years_before ); |
|
328 | - $end_year = $current + absint( $years_after ); |
|
329 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
325 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
326 | + $current = date('Y'); |
|
327 | + $start_year = $current - absint($years_before); |
|
328 | + $end_year = $current + absint($years_after); |
|
329 | + $selected = empty($selected) ? date('Y') : $selected; |
|
330 | 330 | $options = array(); |
331 | 331 | |
332 | - while ( $start_year <= $end_year ) { |
|
333 | - $options[ absint( $start_year ) ] = $start_year; |
|
332 | + while ($start_year <= $end_year) { |
|
333 | + $options[absint($start_year)] = $start_year; |
|
334 | 334 | $start_year++; |
335 | 335 | } |
336 | 336 | |
337 | - $output = wpinv_html_select( array( |
|
337 | + $output = wpinv_html_select(array( |
|
338 | 338 | 'name' => $name, |
339 | 339 | 'selected' => $selected, |
340 | 340 | 'options' => $options, |
341 | 341 | 'show_option_all' => false, |
342 | 342 | 'show_option_none' => false |
343 | - ) ); |
|
343 | + )); |
|
344 | 344 | |
345 | 345 | return $output; |
346 | 346 | } |
347 | 347 | |
348 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
348 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
349 | 349 | |
350 | 350 | $options = array( |
351 | - '1' => __( 'January', 'invoicing' ), |
|
352 | - '2' => __( 'February', 'invoicing' ), |
|
353 | - '3' => __( 'March', 'invoicing' ), |
|
354 | - '4' => __( 'April', 'invoicing' ), |
|
355 | - '5' => __( 'May', 'invoicing' ), |
|
356 | - '6' => __( 'June', 'invoicing' ), |
|
357 | - '7' => __( 'July', 'invoicing' ), |
|
358 | - '8' => __( 'August', 'invoicing' ), |
|
359 | - '9' => __( 'September', 'invoicing' ), |
|
360 | - '10' => __( 'October', 'invoicing' ), |
|
361 | - '11' => __( 'November', 'invoicing' ), |
|
362 | - '12' => __( 'December', 'invoicing' ), |
|
351 | + '1' => __('January', 'invoicing'), |
|
352 | + '2' => __('February', 'invoicing'), |
|
353 | + '3' => __('March', 'invoicing'), |
|
354 | + '4' => __('April', 'invoicing'), |
|
355 | + '5' => __('May', 'invoicing'), |
|
356 | + '6' => __('June', 'invoicing'), |
|
357 | + '7' => __('July', 'invoicing'), |
|
358 | + '8' => __('August', 'invoicing'), |
|
359 | + '9' => __('September', 'invoicing'), |
|
360 | + '10' => __('October', 'invoicing'), |
|
361 | + '11' => __('November', 'invoicing'), |
|
362 | + '12' => __('December', 'invoicing'), |
|
363 | 363 | ); |
364 | 364 | |
365 | 365 | // If no month is selected, default to the current month |
366 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
366 | + $selected = empty($selected) ? date('n') : $selected; |
|
367 | 367 | |
368 | - $output = wpinv_html_select( array( |
|
368 | + $output = wpinv_html_select(array( |
|
369 | 369 | 'name' => $name, |
370 | 370 | 'selected' => $selected, |
371 | 371 | 'options' => $options, |
372 | 372 | 'show_option_all' => false, |
373 | 373 | 'show_option_none' => false |
374 | - ) ); |
|
374 | + )); |
|
375 | 375 | |
376 | 376 | return $output; |
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_html_select( $args = array() ) { |
|
379 | +function wpinv_html_select($args = array()) { |
|
380 | 380 | $defaults = array( |
381 | 381 | 'options' => array(), |
382 | 382 | 'name' => null, |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | 'selected' => 0, |
386 | 386 | 'placeholder' => null, |
387 | 387 | 'multiple' => false, |
388 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
389 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
388 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
389 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
390 | 390 | 'data' => array(), |
391 | 391 | 'onchange' => null, |
392 | 392 | 'required' => false, |
@@ -394,74 +394,74 @@ discard block |
||
394 | 394 | 'readonly' => false, |
395 | 395 | ); |
396 | 396 | |
397 | - $args = wp_parse_args( $args, $defaults ); |
|
397 | + $args = wp_parse_args($args, $defaults); |
|
398 | 398 | |
399 | 399 | $data_elements = ''; |
400 | - foreach ( $args['data'] as $key => $value ) { |
|
401 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
400 | + foreach ($args['data'] as $key => $value) { |
|
401 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
402 | 402 | } |
403 | 403 | |
404 | - if( $args['multiple'] ) { |
|
404 | + if ($args['multiple']) { |
|
405 | 405 | $multiple = ' MULTIPLE'; |
406 | 406 | } else { |
407 | 407 | $multiple = ''; |
408 | 408 | } |
409 | 409 | |
410 | - if( $args['placeholder'] ) { |
|
410 | + if ($args['placeholder']) { |
|
411 | 411 | $placeholder = $args['placeholder']; |
412 | 412 | } else { |
413 | 413 | $placeholder = ''; |
414 | 414 | } |
415 | 415 | |
416 | 416 | $options = ''; |
417 | - if( !empty( $args['onchange'] ) ) { |
|
418 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
417 | + if (!empty($args['onchange'])) { |
|
418 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
419 | 419 | } |
420 | 420 | |
421 | - if( !empty( $args['required'] ) ) { |
|
421 | + if (!empty($args['required'])) { |
|
422 | 422 | $options .= ' required="required"'; |
423 | 423 | } |
424 | 424 | |
425 | - if( !empty( $args['disabled'] ) ) { |
|
425 | + if (!empty($args['disabled'])) { |
|
426 | 426 | $options .= ' disabled'; |
427 | 427 | } |
428 | 428 | |
429 | - if( !empty( $args['readonly'] ) ) { |
|
429 | + if (!empty($args['readonly'])) { |
|
430 | 430 | $options .= ' readonly'; |
431 | 431 | } |
432 | 432 | |
433 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
434 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
433 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
434 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
435 | 435 | |
436 | - if ( $args['show_option_all'] ) { |
|
437 | - if( $args['multiple'] ) { |
|
438 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
436 | + if ($args['show_option_all']) { |
|
437 | + if ($args['multiple']) { |
|
438 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
439 | 439 | } else { |
440 | - $selected = selected( $args['selected'], 0, false ); |
|
440 | + $selected = selected($args['selected'], 0, false); |
|
441 | 441 | } |
442 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
442 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
443 | 443 | } |
444 | 444 | |
445 | - if ( !empty( $args['options'] ) ) { |
|
445 | + if (!empty($args['options'])) { |
|
446 | 446 | |
447 | - if ( $args['show_option_none'] ) { |
|
448 | - if( $args['multiple'] ) { |
|
449 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
447 | + if ($args['show_option_none']) { |
|
448 | + if ($args['multiple']) { |
|
449 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
450 | 450 | } else { |
451 | - $selected = selected( $args['selected'] === "", true, false ); |
|
451 | + $selected = selected($args['selected'] === "", true, false); |
|
452 | 452 | } |
453 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
453 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
454 | 454 | } |
455 | 455 | |
456 | - foreach( $args['options'] as $key => $option ) { |
|
456 | + foreach ($args['options'] as $key => $option) { |
|
457 | 457 | |
458 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
459 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
458 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
459 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
460 | 460 | } else { |
461 | - $selected = selected( $args['selected'], $key, false ); |
|
461 | + $selected = selected($args['selected'], $key, false); |
|
462 | 462 | } |
463 | 463 | |
464 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
464 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | return $output; |
471 | 471 | } |
472 | 472 | |
473 | -function wpinv_item_dropdown( $args = array() ) { |
|
473 | +function wpinv_item_dropdown($args = array()) { |
|
474 | 474 | $defaults = array( |
475 | 475 | 'name' => 'wpi_item', |
476 | 476 | 'id' => 'wpi_item', |
@@ -478,14 +478,14 @@ discard block |
||
478 | 478 | 'multiple' => false, |
479 | 479 | 'selected' => 0, |
480 | 480 | 'number' => 100, |
481 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
482 | - 'data' => array( 'search-type' => 'item' ), |
|
481 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
482 | + 'data' => array('search-type' => 'item'), |
|
483 | 483 | 'show_option_all' => false, |
484 | 484 | 'show_option_none' => false, |
485 | 485 | 'show_recurring' => false, |
486 | 486 | ); |
487 | 487 | |
488 | - $args = wp_parse_args( $args, $defaults ); |
|
488 | + $args = wp_parse_args($args, $defaults); |
|
489 | 489 | |
490 | 490 | $item_args = array( |
491 | 491 | 'post_type' => 'wpi_item', |
@@ -494,44 +494,44 @@ discard block |
||
494 | 494 | 'posts_per_page' => $args['number'] |
495 | 495 | ); |
496 | 496 | |
497 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
497 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
498 | 498 | |
499 | - $items = get_posts( $item_args ); |
|
499 | + $items = get_posts($item_args); |
|
500 | 500 | $options = array(); |
501 | - if ( $items ) { |
|
502 | - foreach ( $items as $item ) { |
|
503 | - $title = esc_html( $item->post_title ); |
|
501 | + if ($items) { |
|
502 | + foreach ($items as $item) { |
|
503 | + $title = esc_html($item->post_title); |
|
504 | 504 | |
505 | - if ( !empty( $args['show_recurring'] ) ) { |
|
506 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
505 | + if (!empty($args['show_recurring'])) { |
|
506 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
507 | 507 | } |
508 | 508 | |
509 | - $options[ absint( $item->ID ) ] = $title; |
|
509 | + $options[absint($item->ID)] = $title; |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
513 | 513 | // This ensures that any selected items are included in the drop down |
514 | - if( is_array( $args['selected'] ) ) { |
|
515 | - foreach( $args['selected'] as $item ) { |
|
516 | - if( ! in_array( $item, $options ) ) { |
|
517 | - $title = get_the_title( $item ); |
|
518 | - if ( !empty( $args['show_recurring'] ) ) { |
|
519 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
514 | + if (is_array($args['selected'])) { |
|
515 | + foreach ($args['selected'] as $item) { |
|
516 | + if (!in_array($item, $options)) { |
|
517 | + $title = get_the_title($item); |
|
518 | + if (!empty($args['show_recurring'])) { |
|
519 | + $title .= wpinv_get_item_suffix($item, false); |
|
520 | 520 | } |
521 | 521 | $options[$item] = $title; |
522 | 522 | } |
523 | 523 | } |
524 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
525 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
526 | - $title = get_the_title( $args['selected'] ); |
|
527 | - if ( !empty( $args['show_recurring'] ) ) { |
|
528 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
524 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
525 | + if (!in_array($args['selected'], $options)) { |
|
526 | + $title = get_the_title($args['selected']); |
|
527 | + if (!empty($args['show_recurring'])) { |
|
528 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
529 | 529 | } |
530 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
530 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
534 | - $output = wpinv_html_select( array( |
|
534 | + $output = wpinv_html_select(array( |
|
535 | 535 | 'name' => $args['name'], |
536 | 536 | 'selected' => $args['selected'], |
537 | 537 | 'id' => $args['id'], |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | 'show_option_all' => $args['show_option_all'], |
543 | 543 | 'show_option_none' => $args['show_option_none'], |
544 | 544 | 'data' => $args['data'], |
545 | - ) ); |
|
545 | + )); |
|
546 | 546 | |
547 | 547 | return $output; |
548 | 548 | } |
@@ -562,16 +562,16 @@ discard block |
||
562 | 562 | ); |
563 | 563 | |
564 | 564 | $options = array(); |
565 | - if ( $items ) { |
|
566 | - foreach ( $items as $item ) { |
|
567 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
565 | + if ($items) { |
|
566 | + foreach ($items as $item) { |
|
567 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
568 | 568 | } |
569 | 569 | } |
570 | 570 | |
571 | 571 | return $options; |
572 | 572 | } |
573 | 573 | |
574 | -function wpinv_html_checkbox( $args = array() ) { |
|
574 | +function wpinv_html_checkbox($args = array()) { |
|
575 | 575 | $defaults = array( |
576 | 576 | 'name' => null, |
577 | 577 | 'current' => null, |
@@ -582,17 +582,17 @@ discard block |
||
582 | 582 | ) |
583 | 583 | ); |
584 | 584 | |
585 | - $args = wp_parse_args( $args, $defaults ); |
|
585 | + $args = wp_parse_args($args, $defaults); |
|
586 | 586 | |
587 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
587 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
588 | 588 | $options = ''; |
589 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
589 | + if (!empty($args['options']['disabled'])) { |
|
590 | 590 | $options .= ' disabled="disabled"'; |
591 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
591 | + } elseif (!empty($args['options']['readonly'])) { |
|
592 | 592 | $options .= ' readonly'; |
593 | 593 | } |
594 | 594 | |
595 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
595 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
596 | 596 | |
597 | 597 | return $output; |
598 | 598 | } |
@@ -600,30 +600,30 @@ discard block |
||
600 | 600 | /** |
601 | 601 | * Displays a hidden field. |
602 | 602 | */ |
603 | -function getpaid_hidden_field( $name, $value ) { |
|
604 | - $name = sanitize_text_field( $name ); |
|
605 | - $value = esc_attr( $value ); |
|
603 | +function getpaid_hidden_field($name, $value) { |
|
604 | + $name = sanitize_text_field($name); |
|
605 | + $value = esc_attr($value); |
|
606 | 606 | |
607 | 607 | echo "<input type='hidden' name='$name' value='$value' />"; |
608 | 608 | } |
609 | 609 | |
610 | -function wpinv_html_text( $args = array() ) { |
|
610 | +function wpinv_html_text($args = array()) { |
|
611 | 611 | // Backwards compatibility |
612 | - if ( func_num_args() > 1 ) { |
|
612 | + if (func_num_args() > 1) { |
|
613 | 613 | $args = func_get_args(); |
614 | 614 | |
615 | 615 | $name = $args[0]; |
616 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
617 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
618 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
616 | + $value = isset($args[1]) ? $args[1] : ''; |
|
617 | + $label = isset($args[2]) ? $args[2] : ''; |
|
618 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | $defaults = array( |
622 | 622 | 'id' => '', |
623 | - 'name' => isset( $name ) ? $name : 'text', |
|
624 | - 'value' => isset( $value ) ? $value : null, |
|
625 | - 'label' => isset( $label ) ? $label : null, |
|
626 | - 'desc' => isset( $desc ) ? $desc : null, |
|
623 | + 'name' => isset($name) ? $name : 'text', |
|
624 | + 'value' => isset($value) ? $value : null, |
|
625 | + 'label' => isset($label) ? $label : null, |
|
626 | + 'desc' => isset($desc) ? $desc : null, |
|
627 | 627 | 'placeholder' => '', |
628 | 628 | 'class' => 'regular-text', |
629 | 629 | 'disabled' => false, |
@@ -633,51 +633,51 @@ discard block |
||
633 | 633 | 'data' => false |
634 | 634 | ); |
635 | 635 | |
636 | - $args = wp_parse_args( $args, $defaults ); |
|
636 | + $args = wp_parse_args($args, $defaults); |
|
637 | 637 | |
638 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
638 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
639 | 639 | $options = ''; |
640 | - if( $args['required'] ) { |
|
640 | + if ($args['required']) { |
|
641 | 641 | $options .= ' required="required"'; |
642 | 642 | } |
643 | - if( $args['readonly'] ) { |
|
643 | + if ($args['readonly']) { |
|
644 | 644 | $options .= ' readonly'; |
645 | 645 | } |
646 | - if( $args['readonly'] ) { |
|
646 | + if ($args['readonly']) { |
|
647 | 647 | $options .= ' readonly'; |
648 | 648 | } |
649 | 649 | |
650 | 650 | $data = ''; |
651 | - if ( !empty( $args['data'] ) ) { |
|
652 | - foreach ( $args['data'] as $key => $value ) { |
|
653 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
651 | + if (!empty($args['data'])) { |
|
652 | + foreach ($args['data'] as $key => $value) { |
|
653 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
657 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
658 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
659 | - if ( ! empty( $args['desc'] ) ) { |
|
660 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
657 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
658 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
659 | + if (!empty($args['desc'])) { |
|
660 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
661 | 661 | } |
662 | 662 | |
663 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
663 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
664 | 664 | |
665 | 665 | $output .= '</span>'; |
666 | 666 | |
667 | 667 | return $output; |
668 | 668 | } |
669 | 669 | |
670 | -function wpinv_html_date_field( $args = array() ) { |
|
671 | - if( empty( $args['class'] ) ) { |
|
670 | +function wpinv_html_date_field($args = array()) { |
|
671 | + if (empty($args['class'])) { |
|
672 | 672 | $args['class'] = 'wpiDatepicker'; |
673 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
673 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
674 | 674 | $args['class'] .= ' wpiDatepicker'; |
675 | 675 | } |
676 | 676 | |
677 | - return wpinv_html_text( $args ); |
|
677 | + return wpinv_html_text($args); |
|
678 | 678 | } |
679 | 679 | |
680 | -function wpinv_html_textarea( $args = array() ) { |
|
680 | +function wpinv_html_textarea($args = array()) { |
|
681 | 681 | $defaults = array( |
682 | 682 | 'name' => 'textarea', |
683 | 683 | 'value' => null, |
@@ -688,31 +688,31 @@ discard block |
||
688 | 688 | 'placeholder' => '', |
689 | 689 | ); |
690 | 690 | |
691 | - $args = wp_parse_args( $args, $defaults ); |
|
691 | + $args = wp_parse_args($args, $defaults); |
|
692 | 692 | |
693 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
693 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
694 | 694 | $disabled = ''; |
695 | - if( $args['disabled'] ) { |
|
695 | + if ($args['disabled']) { |
|
696 | 696 | $disabled = ' disabled="disabled"'; |
697 | 697 | } |
698 | 698 | |
699 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
700 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
701 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
699 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
700 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
701 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
702 | 702 | |
703 | - if ( ! empty( $args['desc'] ) ) { |
|
704 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
703 | + if (!empty($args['desc'])) { |
|
704 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
705 | 705 | } |
706 | 706 | $output .= '</span>'; |
707 | 707 | |
708 | 708 | return $output; |
709 | 709 | } |
710 | 710 | |
711 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
711 | +function wpinv_html_ajax_user_search($args = array()) { |
|
712 | 712 | $defaults = array( |
713 | 713 | 'name' => 'user_id', |
714 | 714 | 'value' => null, |
715 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
715 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
716 | 716 | 'label' => null, |
717 | 717 | 'desc' => null, |
718 | 718 | 'class' => '', |
@@ -721,13 +721,13 @@ discard block |
||
721 | 721 | 'data' => false |
722 | 722 | ); |
723 | 723 | |
724 | - $args = wp_parse_args( $args, $defaults ); |
|
724 | + $args = wp_parse_args($args, $defaults); |
|
725 | 725 | |
726 | 726 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
727 | 727 | |
728 | 728 | $output = '<span class="wpinv_user_search_wrap">'; |
729 | - $output .= wpinv_html_text( $args ); |
|
730 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
729 | + $output .= wpinv_html_text($args); |
|
730 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
731 | 731 | $output .= '</span>'; |
732 | 732 | |
733 | 733 | return $output; |
@@ -743,20 +743,20 @@ discard block |
||
743 | 743 | * |
744 | 744 | * @param string $template the template that is currently being used. |
745 | 745 | */ |
746 | -function wpinv_template( $template ) { |
|
746 | +function wpinv_template($template) { |
|
747 | 747 | global $post; |
748 | 748 | |
749 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
749 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
750 | 750 | |
751 | 751 | // If the user can view this invoice, display it. |
752 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
752 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
753 | 753 | |
754 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
754 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
755 | 755 | |
756 | 756 | // Else display an error message. |
757 | 757 | } else { |
758 | 758 | |
759 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
759 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
760 | 760 | |
761 | 761 | } |
762 | 762 | |
@@ -764,46 +764,46 @@ discard block |
||
764 | 764 | |
765 | 765 | return $template; |
766 | 766 | } |
767 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
767 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
768 | 768 | |
769 | 769 | function wpinv_get_business_address() { |
770 | 770 | $business_address = wpinv_store_address(); |
771 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
771 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
772 | 772 | |
773 | 773 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
774 | 774 | |
775 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
775 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | /** |
779 | 779 | * Displays the company address. |
780 | 780 | */ |
781 | 781 | function wpinv_display_from_address() { |
782 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
782 | + wpinv_get_template('invoice/company-address.php'); |
|
783 | 783 | } |
784 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
784 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
785 | 785 | |
786 | -function wpinv_watermark( $id = 0 ) { |
|
787 | - $output = wpinv_get_watermark( $id ); |
|
788 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
786 | +function wpinv_watermark($id = 0) { |
|
787 | + $output = wpinv_get_watermark($id); |
|
788 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
789 | 789 | } |
790 | 790 | |
791 | -function wpinv_get_watermark( $id ) { |
|
792 | - if ( !$id > 0 ) { |
|
791 | +function wpinv_get_watermark($id) { |
|
792 | + if (!$id > 0) { |
|
793 | 793 | return NULL; |
794 | 794 | } |
795 | 795 | |
796 | - $invoice = wpinv_get_invoice( $id ); |
|
796 | + $invoice = wpinv_get_invoice($id); |
|
797 | 797 | |
798 | - if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) { |
|
799 | - if ( $invoice->is_paid() ) { |
|
800 | - return __( 'Paid', 'invoicing' ); |
|
798 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
799 | + if ($invoice->is_paid()) { |
|
800 | + return __('Paid', 'invoicing'); |
|
801 | 801 | } |
802 | - if ( $invoice->is_refunded() ) { |
|
803 | - return __( 'Refunded', 'invoicing' ); |
|
802 | + if ($invoice->is_refunded()) { |
|
803 | + return __('Refunded', 'invoicing'); |
|
804 | 804 | } |
805 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
806 | - return __( 'Cancelled', 'invoicing' ); |
|
805 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
806 | + return __('Cancelled', 'invoicing'); |
|
807 | 807 | } |
808 | 808 | } |
809 | 809 | |
@@ -813,140 +813,140 @@ discard block |
||
813 | 813 | /** |
814 | 814 | * @deprecated |
815 | 815 | */ |
816 | -function wpinv_display_invoice_details( $invoice ) { |
|
817 | - return getpaid_invoice_meta( $invoice ); |
|
816 | +function wpinv_display_invoice_details($invoice) { |
|
817 | + return getpaid_invoice_meta($invoice); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | /** |
821 | 821 | * Displays invoice meta. |
822 | 822 | */ |
823 | -function getpaid_invoice_meta( $invoice ) { |
|
823 | +function getpaid_invoice_meta($invoice) { |
|
824 | 824 | |
825 | - $invoice = new WPInv_Invoice( $invoice ); |
|
825 | + $invoice = new WPInv_Invoice($invoice); |
|
826 | 826 | |
827 | 827 | // Ensure that we have an invoice. |
828 | - if ( 0 == $invoice->get_id() ) { |
|
828 | + if (0 == $invoice->get_id()) { |
|
829 | 829 | return; |
830 | 830 | } |
831 | 831 | |
832 | 832 | // Load the invoice meta. |
833 | - $meta = array( |
|
833 | + $meta = array( |
|
834 | 834 | |
835 | 835 | 'number' => array( |
836 | 836 | 'label' => sprintf( |
837 | - __( '%s Number', 'invoicing' ), |
|
838 | - ucfirst( $invoice->get_type() ) |
|
837 | + __('%s Number', 'invoicing'), |
|
838 | + ucfirst($invoice->get_type()) |
|
839 | 839 | ), |
840 | - 'value' => sanitize_text_field( $invoice->get_number() ), |
|
840 | + 'value' => sanitize_text_field($invoice->get_number()), |
|
841 | 841 | ), |
842 | 842 | |
843 | 843 | 'status' => array( |
844 | 844 | 'label' => sprintf( |
845 | - __( '%s Status', 'invoicing' ), |
|
846 | - ucfirst( $invoice->get_type() ) |
|
845 | + __('%s Status', 'invoicing'), |
|
846 | + ucfirst($invoice->get_type()) |
|
847 | 847 | ), |
848 | 848 | 'value' => $invoice->get_status_label_html(), |
849 | 849 | ), |
850 | 850 | |
851 | 851 | 'date' => array( |
852 | 852 | 'label' => sprintf( |
853 | - __( '%s Date', 'invoicing' ), |
|
854 | - ucfirst( $invoice->get_type() ) |
|
853 | + __('%s Date', 'invoicing'), |
|
854 | + ucfirst($invoice->get_type()) |
|
855 | 855 | ), |
856 | - 'value' => getpaid_format_date( $invoice->get_created_date() ), |
|
856 | + 'value' => getpaid_format_date($invoice->get_created_date()), |
|
857 | 857 | ), |
858 | 858 | |
859 | 859 | 'date_paid' => array( |
860 | - 'label' => __( 'Paid On', 'invoicing' ), |
|
861 | - 'value' => getpaid_format_date( $invoice->get_completed_date() ), |
|
860 | + 'label' => __('Paid On', 'invoicing'), |
|
861 | + 'value' => getpaid_format_date($invoice->get_completed_date()), |
|
862 | 862 | ), |
863 | 863 | |
864 | 864 | 'gateway' => array( |
865 | - 'label' => __( 'Payment Method', 'invoicing' ), |
|
866 | - 'value' => sanitize_text_field( $invoice->get_gateway_title() ), |
|
865 | + 'label' => __('Payment Method', 'invoicing'), |
|
866 | + 'value' => sanitize_text_field($invoice->get_gateway_title()), |
|
867 | 867 | ), |
868 | 868 | |
869 | 869 | 'transaction_id' => array( |
870 | - 'label' => __( 'Transaction ID', 'invoicing' ), |
|
871 | - 'value' => sanitize_text_field( $invoice->get_transaction_id() ), |
|
870 | + 'label' => __('Transaction ID', 'invoicing'), |
|
871 | + 'value' => sanitize_text_field($invoice->get_transaction_id()), |
|
872 | 872 | ), |
873 | 873 | |
874 | 874 | 'due_date' => array( |
875 | - 'label' => __( 'Due Date', 'invoicing' ), |
|
876 | - 'value' => getpaid_format_date( $invoice->get_due_date() ), |
|
875 | + 'label' => __('Due Date', 'invoicing'), |
|
876 | + 'value' => getpaid_format_date($invoice->get_due_date()), |
|
877 | 877 | ), |
878 | 878 | |
879 | 879 | 'vat_number' => array( |
880 | 880 | 'label' => sprintf( |
881 | - __( '%s Number', 'invoicing' ), |
|
881 | + __('%s Number', 'invoicing'), |
|
882 | 882 | getpaid_tax()->get_vat_name() |
883 | 883 | ), |
884 | - 'value' => sanitize_text_field( $invoice->get_vat_number() ), |
|
884 | + 'value' => sanitize_text_field($invoice->get_vat_number()), |
|
885 | 885 | ), |
886 | 886 | |
887 | 887 | ); |
888 | 888 | |
889 | 889 | // If it is not paid, remove the date of payment. |
890 | - if ( ! $invoice->is_paid() ) { |
|
891 | - unset( $meta[ 'date_paid' ] ); |
|
892 | - unset( $meta[ 'transaction_id' ] ); |
|
890 | + if (!$invoice->is_paid()) { |
|
891 | + unset($meta['date_paid']); |
|
892 | + unset($meta['transaction_id']); |
|
893 | 893 | } |
894 | 894 | |
895 | - if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) { |
|
896 | - unset( $meta[ 'gateway' ] ); |
|
895 | + if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) { |
|
896 | + unset($meta['gateway']); |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | // Only display the due date if due dates are enabled. |
900 | - if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) { |
|
901 | - unset( $meta[ 'due_date' ] ); |
|
900 | + if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) { |
|
901 | + unset($meta['due_date']); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | // Only display the vat number if taxes are enabled. |
905 | - if ( ! wpinv_use_taxes() ) { |
|
906 | - unset( $meta[ 'vat_number' ] ); |
|
905 | + if (!wpinv_use_taxes()) { |
|
906 | + unset($meta['vat_number']); |
|
907 | 907 | } |
908 | 908 | |
909 | - if ( $invoice->is_recurring() ) { |
|
909 | + if ($invoice->is_recurring()) { |
|
910 | 910 | |
911 | 911 | // Link to the parent invoice. |
912 | - if ( $invoice->is_renewal() ) { |
|
912 | + if ($invoice->is_renewal()) { |
|
913 | 913 | |
914 | - $meta[ 'parent' ] = array( |
|
914 | + $meta['parent'] = array( |
|
915 | 915 | |
916 | 916 | 'label' => sprintf( |
917 | - __( 'Parent %s', 'invoicing' ), |
|
918 | - ucfirst( $invoice->get_type() ) |
|
917 | + __('Parent %s', 'invoicing'), |
|
918 | + ucfirst($invoice->get_type()) |
|
919 | 919 | ), |
920 | 920 | |
921 | - 'value' => wpinv_invoice_link( $invoice->get_parent_id() ), |
|
921 | + 'value' => wpinv_invoice_link($invoice->get_parent_id()), |
|
922 | 922 | |
923 | 923 | ); |
924 | 924 | |
925 | 925 | } |
926 | 926 | |
927 | - $subscription = wpinv_get_subscription( $invoice ); |
|
927 | + $subscription = wpinv_get_subscription($invoice); |
|
928 | 928 | |
929 | - if ( ! empty ( $subscription ) ) { |
|
929 | + if (!empty ($subscription)) { |
|
930 | 930 | |
931 | 931 | // Display the renewal date. |
932 | - if ( $subscription->is_active() && 'cancelled' != $subscription->status ) { |
|
932 | + if ($subscription->is_active() && 'cancelled' != $subscription->status) { |
|
933 | 933 | |
934 | - $meta[ 'renewal_date' ] = array( |
|
934 | + $meta['renewal_date'] = array( |
|
935 | 935 | |
936 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
937 | - 'value' => getpaid_format_date( $subscription->expiration ), |
|
936 | + 'label' => __('Renews On', 'invoicing'), |
|
937 | + 'value' => getpaid_format_date($subscription->expiration), |
|
938 | 938 | |
939 | 939 | ); |
940 | 940 | |
941 | 941 | } |
942 | 942 | |
943 | - if ( $invoice->is_parent() ) { |
|
943 | + if ($invoice->is_parent()) { |
|
944 | 944 | |
945 | 945 | // Display the recurring amount. |
946 | - $meta[ 'recurring_total' ] = array( |
|
946 | + $meta['recurring_total'] = array( |
|
947 | 947 | |
948 | - 'label' => __( 'Recurring Amount', 'invoicing' ), |
|
949 | - 'value' => wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), $invoice->get_currency() ), |
|
948 | + 'label' => __('Recurring Amount', 'invoicing'), |
|
949 | + 'value' => wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()), |
|
950 | 950 | |
951 | 951 | ); |
952 | 952 | |
@@ -956,20 +956,20 @@ discard block |
||
956 | 956 | } |
957 | 957 | |
958 | 958 | // Add the invoice total to the meta. |
959 | - $meta[ 'invoice_total' ] = array( |
|
959 | + $meta['invoice_total'] = array( |
|
960 | 960 | |
961 | - 'label' => __( 'Total Amount', 'invoicing' ), |
|
962 | - 'value' => wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ), |
|
961 | + 'label' => __('Total Amount', 'invoicing'), |
|
962 | + 'value' => wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()), |
|
963 | 963 | |
964 | 964 | ); |
965 | 965 | |
966 | 966 | // Provide a way for third party plugins to filter the meta. |
967 | - $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice ); |
|
967 | + $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice); |
|
968 | 968 | |
969 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
969 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
970 | 970 | |
971 | 971 | } |
972 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
972 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
973 | 973 | |
974 | 974 | /** |
975 | 975 | * Retrieves the address markup to use on Invoices. |
@@ -981,29 +981,29 @@ discard block |
||
981 | 981 | * @param string $separator How to separate address lines. |
982 | 982 | * @return string |
983 | 983 | */ |
984 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
984 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
985 | 985 | |
986 | 986 | // Retrieve the address markup... |
987 | - $country= empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
988 | - $format = wpinv_get_full_address_format( $country ); |
|
987 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
988 | + $format = wpinv_get_full_address_format($country); |
|
989 | 989 | |
990 | 990 | // ... and the replacements. |
991 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
991 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
992 | 992 | |
993 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
993 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
994 | 994 | |
995 | 995 | // Remove unavailable tags. |
996 | - $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
|
996 | + $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address); |
|
997 | 997 | |
998 | 998 | // Clean up white space. |
999 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
1000 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
999 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
1000 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
1001 | 1001 | |
1002 | 1002 | // Break newlines apart and remove empty lines/trim commas and white space. |
1003 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
1003 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
1004 | 1004 | |
1005 | 1005 | // Add html breaks. |
1006 | - $formatted_address = implode( $separator, $formatted_address ); |
|
1006 | + $formatted_address = implode($separator, $formatted_address); |
|
1007 | 1007 | |
1008 | 1008 | // We're done! |
1009 | 1009 | return $formatted_address; |
@@ -1015,88 +1015,88 @@ discard block |
||
1015 | 1015 | * |
1016 | 1016 | * @param WPInv_Invoice $invoice |
1017 | 1017 | */ |
1018 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
1019 | - if ( ! empty( $invoice ) ) { |
|
1020 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
1018 | +function wpinv_display_to_address($invoice = 0) { |
|
1019 | + if (!empty($invoice)) { |
|
1020 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
1021 | 1021 | } |
1022 | 1022 | } |
1023 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
1023 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
1024 | 1024 | |
1025 | 1025 | |
1026 | 1026 | /** |
1027 | 1027 | * Displays invoice line items. |
1028 | 1028 | */ |
1029 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
1029 | +function wpinv_display_line_items($invoice_id = 0) { |
|
1030 | 1030 | |
1031 | 1031 | // Prepare the invoice. |
1032 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1032 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1033 | 1033 | |
1034 | 1034 | // Abort if there is no invoice. |
1035 | - if ( 0 == $invoice->get_id() ) { |
|
1035 | + if (0 == $invoice->get_id()) { |
|
1036 | 1036 | return; |
1037 | 1037 | } |
1038 | 1038 | |
1039 | 1039 | // Line item columns. |
1040 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
1041 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
1040 | + $columns = getpaid_invoice_item_columns($invoice); |
|
1041 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
1042 | 1042 | |
1043 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
1043 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
1044 | 1044 | } |
1045 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
1045 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
1046 | 1046 | |
1047 | 1047 | /** |
1048 | 1048 | * Displays invoice notices on invoices. |
1049 | 1049 | */ |
1050 | 1050 | function wpinv_display_invoice_notice() { |
1051 | 1051 | |
1052 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
1053 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
1052 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
1053 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
1054 | 1054 | |
1055 | - if ( empty( $label ) && empty( $notice ) ) { |
|
1055 | + if (empty($label) && empty($notice)) { |
|
1056 | 1056 | return; |
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
1060 | 1060 | |
1061 | - if ( ! empty( $label ) ) { |
|
1062 | - $label = sanitize_text_field( $label ); |
|
1061 | + if (!empty($label)) { |
|
1062 | + $label = sanitize_text_field($label); |
|
1063 | 1063 | echo "<h5>$label</h5>"; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - if ( ! empty( $notice ) ) { |
|
1067 | - echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>'; |
|
1066 | + if (!empty($notice)) { |
|
1067 | + echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>'; |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | echo '</div>'; |
1071 | 1071 | } |
1072 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
1072 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
1073 | 1073 | |
1074 | 1074 | /** |
1075 | 1075 | * @param WPInv_Invoice $invoice |
1076 | 1076 | */ |
1077 | -function wpinv_display_invoice_notes( $invoice ) { |
|
1077 | +function wpinv_display_invoice_notes($invoice) { |
|
1078 | 1078 | |
1079 | 1079 | // Retrieve the notes. |
1080 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
1080 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
1081 | 1081 | |
1082 | 1082 | // Abort if we have non. |
1083 | - if ( empty( $notes ) ) { |
|
1083 | + if (empty($notes)) { |
|
1084 | 1084 | return; |
1085 | 1085 | } |
1086 | 1086 | |
1087 | 1087 | // Echo the note. |
1088 | 1088 | echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">'; |
1089 | - echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>'; |
|
1089 | + echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>'; |
|
1090 | 1090 | echo '<ul class="getpaid-invoice-notes mt-4 p-0">'; |
1091 | 1091 | |
1092 | - foreach( $notes as $note ) { |
|
1093 | - wpinv_get_invoice_note_line_item( $note ); |
|
1092 | + foreach ($notes as $note) { |
|
1093 | + wpinv_get_invoice_note_line_item($note); |
|
1094 | 1094 | } |
1095 | 1095 | |
1096 | 1096 | echo '</ul>'; |
1097 | 1097 | echo '</div>'; |
1098 | 1098 | } |
1099 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
1099 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
1100 | 1100 | |
1101 | 1101 | /** |
1102 | 1102 | * Loads scripts on our invoice templates. |
@@ -1104,32 +1104,32 @@ discard block |
||
1104 | 1104 | function wpinv_display_style() { |
1105 | 1105 | |
1106 | 1106 | // Make sure that all scripts have been loaded. |
1107 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
1108 | - do_action( 'wp_enqueue_scripts' ); |
|
1107 | + if (!did_action('wp_enqueue_scripts')) { |
|
1108 | + do_action('wp_enqueue_scripts'); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | // Register the invoices style. |
1112 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
1112 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
1113 | 1113 | |
1114 | 1114 | // Load required styles |
1115 | - wp_print_styles( 'open-sans' ); |
|
1116 | - wp_print_styles( 'wpinv-single-style' ); |
|
1117 | - wp_print_styles( 'ayecode-ui' ); |
|
1115 | + wp_print_styles('open-sans'); |
|
1116 | + wp_print_styles('wpinv-single-style'); |
|
1117 | + wp_print_styles('ayecode-ui'); |
|
1118 | 1118 | |
1119 | 1119 | // Maybe load custom css. |
1120 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
1120 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
1121 | 1121 | |
1122 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
1123 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
1124 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
1122 | + if (isset($custom_css) && !empty($custom_css)) { |
|
1123 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
1124 | + $custom_css = str_replace('>', '>', $custom_css); |
|
1125 | 1125 | echo '<style type="text/css">'; |
1126 | 1126 | echo $custom_css; |
1127 | 1127 | echo '</style>'; |
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | } |
1131 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1132 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
1131 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
1132 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
1133 | 1133 | |
1134 | 1134 | |
1135 | 1135 | /** |
@@ -1141,41 +1141,41 @@ discard block |
||
1141 | 1141 | // Retrieve the current invoice. |
1142 | 1142 | $invoice_id = getpaid_get_current_invoice_id(); |
1143 | 1143 | |
1144 | - if ( empty( $invoice_id ) ) { |
|
1144 | + if (empty($invoice_id)) { |
|
1145 | 1145 | |
1146 | 1146 | return aui()->alert( |
1147 | 1147 | array( |
1148 | 1148 | 'type' => 'warning', |
1149 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
1149 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
1150 | 1150 | ) |
1151 | 1151 | ); |
1152 | 1152 | |
1153 | 1153 | } |
1154 | 1154 | |
1155 | 1155 | // Can the user view this invoice? |
1156 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
1156 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
1157 | 1157 | |
1158 | 1158 | return aui()->alert( |
1159 | 1159 | array( |
1160 | 1160 | 'type' => 'warning', |
1161 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
1161 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
1162 | 1162 | ) |
1163 | 1163 | ); |
1164 | 1164 | |
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | // Ensure that it is not yet paid for. |
1168 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1168 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1169 | 1169 | |
1170 | 1170 | // Maybe mark it as viewed. |
1171 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
1171 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
1172 | 1172 | |
1173 | - if ( $invoice->is_paid() ) { |
|
1173 | + if ($invoice->is_paid()) { |
|
1174 | 1174 | |
1175 | 1175 | return aui()->alert( |
1176 | 1176 | array( |
1177 | 1177 | 'type' => 'success', |
1178 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
1178 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
1179 | 1179 | ) |
1180 | 1180 | ); |
1181 | 1181 | |
@@ -1185,14 +1185,14 @@ discard block |
||
1185 | 1185 | $wpi_checkout_id = $invoice_id; |
1186 | 1186 | |
1187 | 1187 | // We'll display this invoice via the default form. |
1188 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1188 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1189 | 1189 | |
1190 | - if ( 0 == $form->get_id() ) { |
|
1190 | + if (0 == $form->get_id()) { |
|
1191 | 1191 | |
1192 | 1192 | return aui()->alert( |
1193 | 1193 | array( |
1194 | 1194 | 'type' => 'warning', |
1195 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1195 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1196 | 1196 | ) |
1197 | 1197 | ); |
1198 | 1198 | |
@@ -1200,7 +1200,7 @@ discard block |
||
1200 | 1200 | |
1201 | 1201 | // Set the invoice. |
1202 | 1202 | $form->invoice = $invoice; |
1203 | - $form->set_items( $invoice->get_items() ); |
|
1203 | + $form->set_items($invoice->get_items()); |
|
1204 | 1204 | |
1205 | 1205 | // Generate the html. |
1206 | 1206 | return $form->get_html(); |
@@ -1208,7 +1208,7 @@ discard block |
||
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | function wpinv_empty_cart_message() { |
1211 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1211 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | /** |
@@ -1225,38 +1225,38 @@ discard block |
||
1225 | 1225 | ) |
1226 | 1226 | ); |
1227 | 1227 | } |
1228 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1228 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1229 | 1229 | |
1230 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1231 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1230 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1231 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1232 | 1232 | |
1233 | - if ( empty( $invoice ) ) { |
|
1233 | + if (empty($invoice)) { |
|
1234 | 1234 | return NULL; |
1235 | 1235 | } |
1236 | 1236 | |
1237 | 1237 | $billing_details = $invoice->get_user_info(); |
1238 | - $address_row = wpinv_get_invoice_address_markup( $billing_details ); |
|
1238 | + $address_row = wpinv_get_invoice_address_markup($billing_details); |
|
1239 | 1239 | |
1240 | 1240 | ob_start(); |
1241 | 1241 | ?> |
1242 | 1242 | <table class="table table-bordered table-sm wpi-billing-details"> |
1243 | 1243 | <tbody> |
1244 | 1244 | <tr class="wpi-receipt-name"> |
1245 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1246 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1245 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1246 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1247 | 1247 | </tr> |
1248 | 1248 | <tr class="wpi-receipt-email"> |
1249 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1250 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1249 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1250 | + <td><?php echo $billing_details['email']; ?></td> |
|
1251 | 1251 | </tr> |
1252 | 1252 | <tr class="wpi-receipt-address"> |
1253 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1254 | - <td><?php echo $address_row ;?></td> |
|
1253 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1254 | + <td><?php echo $address_row; ?></td> |
|
1255 | 1255 | </tr> |
1256 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1256 | + <?php if ($billing_details['phone']) { ?> |
|
1257 | 1257 | <tr class="wpi-receipt-phone"> |
1258 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1259 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1258 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1259 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1260 | 1260 | </tr> |
1261 | 1261 | <?php } ?> |
1262 | 1262 | </tbody> |
@@ -1264,7 +1264,7 @@ discard block |
||
1264 | 1264 | <?php |
1265 | 1265 | $output = ob_get_clean(); |
1266 | 1266 | |
1267 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1267 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1268 | 1268 | |
1269 | 1269 | echo $output; |
1270 | 1270 | } |
@@ -1272,88 +1272,88 @@ discard block |
||
1272 | 1272 | /** |
1273 | 1273 | * Filters the receipt page. |
1274 | 1274 | */ |
1275 | -function wpinv_filter_success_page_content( $content ) { |
|
1275 | +function wpinv_filter_success_page_content($content) { |
|
1276 | 1276 | |
1277 | 1277 | // Ensure this is our page. |
1278 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1278 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1279 | 1279 | |
1280 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1281 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1280 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1281 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1282 | 1282 | |
1283 | 1283 | } |
1284 | 1284 | |
1285 | 1285 | return $content; |
1286 | 1286 | } |
1287 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1287 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1288 | 1288 | |
1289 | -function wpinv_invoice_link( $invoice_id ) { |
|
1290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1289 | +function wpinv_invoice_link($invoice_id) { |
|
1290 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1291 | 1291 | |
1292 | - if ( empty( $invoice ) ) { |
|
1292 | + if (empty($invoice)) { |
|
1293 | 1293 | return NULL; |
1294 | 1294 | } |
1295 | 1295 | |
1296 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1296 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1297 | 1297 | |
1298 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1298 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1299 | 1299 | } |
1300 | 1300 | |
1301 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
1302 | - if ( empty( $invoice ) ) { |
|
1301 | +function wpinv_cart_total_label($label, $invoice) { |
|
1302 | + if (empty($invoice)) { |
|
1303 | 1303 | return $label; |
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 | $prefix_label = ''; |
1307 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
1308 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
1309 | - } else if ( $invoice->is_renewal() ) { |
|
1310 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
1307 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
1308 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
1309 | + } else if ($invoice->is_renewal()) { |
|
1310 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
1311 | 1311 | } |
1312 | 1312 | |
1313 | - if ( $prefix_label != '' ) { |
|
1314 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
1313 | + if ($prefix_label != '') { |
|
1314 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | return $label; |
1318 | 1318 | } |
1319 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1320 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1321 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1319 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1320 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1321 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1322 | 1322 | |
1323 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1324 | - if ( empty( $note ) ) { |
|
1323 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1324 | + if (empty($note)) { |
|
1325 | 1325 | return NULL; |
1326 | 1326 | } |
1327 | 1327 | |
1328 | - if ( is_int( $note ) ) { |
|
1329 | - $note = get_comment( $note ); |
|
1328 | + if (is_int($note)) { |
|
1329 | + $note = get_comment($note); |
|
1330 | 1330 | } |
1331 | 1331 | |
1332 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1332 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1333 | 1333 | return NULL; |
1334 | 1334 | } |
1335 | 1335 | |
1336 | - $note_classes = array( 'note' ); |
|
1337 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1336 | + $note_classes = array('note'); |
|
1337 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1338 | 1338 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1339 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1340 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1339 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1340 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1341 | 1341 | |
1342 | 1342 | ob_start(); |
1343 | 1343 | ?> |
1344 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3"> |
|
1344 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3"> |
|
1345 | 1345 | <div class="note_content bg-light border position-relative p-4"> |
1346 | 1346 | |
1347 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
1347 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
1348 | 1348 | |
1349 | - <?php if ( ! is_admin() ) : ?> |
|
1349 | + <?php if (!is_admin()) : ?> |
|
1350 | 1350 | <em class="meta position-absolute form-text"> |
1351 | 1351 | <?php |
1352 | 1352 | printf( |
1353 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1353 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1354 | 1354 | $note->comment_author, |
1355 | - date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), |
|
1356 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1355 | + date_i18n(get_option('date_format'), strtotime($note->comment_date)), |
|
1356 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1357 | 1357 | ); |
1358 | 1358 | ?> |
1359 | 1359 | </em> |
@@ -1361,12 +1361,12 @@ discard block |
||
1361 | 1361 | |
1362 | 1362 | </div> |
1363 | 1363 | |
1364 | - <?php if ( is_admin() ) : ?> |
|
1364 | + <?php if (is_admin()) : ?> |
|
1365 | 1365 | |
1366 | 1366 | <p class="meta px-4 py-2"> |
1367 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> |
|
1368 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1369 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
1367 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> |
|
1368 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1369 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
1370 | 1370 | <?php } ?> |
1371 | 1371 | </p> |
1372 | 1372 | |
@@ -1375,9 +1375,9 @@ discard block |
||
1375 | 1375 | </li> |
1376 | 1376 | <?php |
1377 | 1377 | $note_content = ob_get_clean(); |
1378 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1378 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1379 | 1379 | |
1380 | - if ( $echo ) { |
|
1380 | + if ($echo) { |
|
1381 | 1381 | echo $note_content; |
1382 | 1382 | } else { |
1383 | 1383 | return $note_content; |
@@ -1387,36 +1387,36 @@ discard block |
||
1387 | 1387 | function wpinv_invalid_invoice_content() { |
1388 | 1388 | global $post; |
1389 | 1389 | |
1390 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
1390 | + $invoice = wpinv_get_invoice($post->ID); |
|
1391 | 1391 | |
1392 | - $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' ); |
|
1393 | - if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
1394 | - if ( is_user_logged_in() ) { |
|
1395 | - if ( wpinv_require_login_to_checkout() ) { |
|
1396 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1397 | - $error = __( 'You are not allowed to view this invoice.', 'invoicing' ); |
|
1392 | + $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing'); |
|
1393 | + if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
1394 | + if (is_user_logged_in()) { |
|
1395 | + if (wpinv_require_login_to_checkout()) { |
|
1396 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1397 | + $error = __('You are not allowed to view this invoice.', 'invoicing'); |
|
1398 | 1398 | } |
1399 | 1399 | } |
1400 | 1400 | } else { |
1401 | - if ( wpinv_require_login_to_checkout() ) { |
|
1402 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1403 | - $error = __( 'You must be logged in to view this invoice.', 'invoicing' ); |
|
1401 | + if (wpinv_require_login_to_checkout()) { |
|
1402 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1403 | + $error = __('You must be logged in to view this invoice.', 'invoicing'); |
|
1404 | 1404 | } |
1405 | 1405 | } |
1406 | 1406 | } |
1407 | 1407 | } else { |
1408 | - $error = __( 'This invoice is deleted or does not exist.', 'invoicing' ); |
|
1408 | + $error = __('This invoice is deleted or does not exist.', 'invoicing'); |
|
1409 | 1409 | } |
1410 | 1410 | ?> |
1411 | 1411 | <div class="row wpinv-row-invalid"> |
1412 | 1412 | <div class="col-md-6 col-md-offset-3 wpinv-message error"> |
1413 | - <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3> |
|
1413 | + <h3><?php _e('Access Denied', 'invoicing'); ?></h3> |
|
1414 | 1414 | <p class="wpinv-msg-text"><?php echo $error; ?></p> |
1415 | 1415 | </div> |
1416 | 1416 | </div> |
1417 | 1417 | <?php |
1418 | 1418 | } |
1419 | -add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' ); |
|
1419 | +add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content'); |
|
1420 | 1420 | |
1421 | 1421 | /** |
1422 | 1422 | * Function to get privacy policy text. |
@@ -1425,21 +1425,21 @@ discard block |
||
1425 | 1425 | * @return string |
1426 | 1426 | */ |
1427 | 1427 | function wpinv_get_policy_text() { |
1428 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1428 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1429 | 1429 | |
1430 | - $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' )); |
|
1430 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1431 | 1431 | |
1432 | - if(!$privacy_page_id){ |
|
1433 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1432 | + if (!$privacy_page_id) { |
|
1433 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1434 | 1434 | } |
1435 | 1435 | |
1436 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1436 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1437 | 1437 | |
1438 | 1438 | $find_replace = array( |
1439 | 1439 | '[wpinv_privacy_policy]' => $privacy_link, |
1440 | 1440 | ); |
1441 | 1441 | |
1442 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1442 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1443 | 1443 | |
1444 | 1444 | return wp_kses_post(wpautop($privacy_text)); |
1445 | 1445 | } |
@@ -1447,21 +1447,21 @@ discard block |
||
1447 | 1447 | function wpinv_oxygen_fix_conflict() { |
1448 | 1448 | global $ct_ignore_post_types; |
1449 | 1449 | |
1450 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1450 | + if (!is_array($ct_ignore_post_types)) { |
|
1451 | 1451 | $ct_ignore_post_types = array(); |
1452 | 1452 | } |
1453 | 1453 | |
1454 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' ); |
|
1454 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item'); |
|
1455 | 1455 | |
1456 | - foreach ( $post_types as $post_type ) { |
|
1456 | + foreach ($post_types as $post_type) { |
|
1457 | 1457 | $ct_ignore_post_types[] = $post_type; |
1458 | 1458 | |
1459 | 1459 | // Ignore post type |
1460 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1460 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1461 | 1461 | } |
1462 | 1462 | |
1463 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1464 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1463 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1464 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1465 | 1465 | } |
1466 | 1466 | |
1467 | 1467 | /** |
@@ -1469,10 +1469,10 @@ discard block |
||
1469 | 1469 | * |
1470 | 1470 | * @param GetPaid_Payment_Form $form |
1471 | 1471 | */ |
1472 | -function getpaid_display_payment_form( $form ) { |
|
1472 | +function getpaid_display_payment_form($form) { |
|
1473 | 1473 | |
1474 | - if ( is_numeric( $form ) ) { |
|
1475 | - $form = new GetPaid_Payment_Form( $form ); |
|
1474 | + if (is_numeric($form)) { |
|
1475 | + $form = new GetPaid_Payment_Form($form); |
|
1476 | 1476 | } |
1477 | 1477 | |
1478 | 1478 | $form->display(); |
@@ -1482,16 +1482,16 @@ discard block |
||
1482 | 1482 | /** |
1483 | 1483 | * Helper function to display a item payment form on the frontend. |
1484 | 1484 | */ |
1485 | -function getpaid_display_item_payment_form( $items ) { |
|
1485 | +function getpaid_display_item_payment_form($items) { |
|
1486 | 1486 | |
1487 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1488 | - $form->set_items( $items ); |
|
1487 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1488 | + $form->set_items($items); |
|
1489 | 1489 | |
1490 | - if ( 0 == count( $form->get_items() ) ) { |
|
1490 | + if (0 == count($form->get_items())) { |
|
1491 | 1491 | echo aui()->alert( |
1492 | 1492 | array( |
1493 | 1493 | 'type' => 'warning', |
1494 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1494 | + 'content' => __('No published items found', 'invoicing'), |
|
1495 | 1495 | ) |
1496 | 1496 | ); |
1497 | 1497 | return; |
@@ -1503,75 +1503,75 @@ discard block |
||
1503 | 1503 | /** |
1504 | 1504 | * Helper function to display an invoice payment form on the frontend. |
1505 | 1505 | */ |
1506 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1506 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1507 | 1507 | global $invoicing; |
1508 | 1508 | |
1509 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1509 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1510 | 1510 | |
1511 | - if ( empty( $invoice ) ) { |
|
1511 | + if (empty($invoice)) { |
|
1512 | 1512 | return aui()->alert( |
1513 | 1513 | array( |
1514 | 1514 | 'type' => 'warning', |
1515 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1515 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1516 | 1516 | ) |
1517 | 1517 | ); |
1518 | 1518 | } |
1519 | 1519 | |
1520 | - if ( $invoice->is_paid() ) { |
|
1520 | + if ($invoice->is_paid()) { |
|
1521 | 1521 | return aui()->alert( |
1522 | 1522 | array( |
1523 | 1523 | 'type' => 'warning', |
1524 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1524 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1525 | 1525 | ) |
1526 | 1526 | ); |
1527 | 1527 | } |
1528 | 1528 | |
1529 | 1529 | // Get the form elements and items. |
1530 | - $form = wpinv_get_default_payment_form(); |
|
1531 | - $elements = $invoicing->form_elements->get_form_elements( $form ); |
|
1532 | - $items = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice ); |
|
1530 | + $form = wpinv_get_default_payment_form(); |
|
1531 | + $elements = $invoicing->form_elements->get_form_elements($form); |
|
1532 | + $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice); |
|
1533 | 1533 | |
1534 | 1534 | ob_start(); |
1535 | 1535 | echo "<form class='wpinv_payment_form'>"; |
1536 | - do_action( 'wpinv_payment_form_top' ); |
|
1536 | + do_action('wpinv_payment_form_top'); |
|
1537 | 1537 | echo "<input type='hidden' name='form_id' value='$form'/>"; |
1538 | 1538 | echo "<input type='hidden' name='invoice_id' value='$invoice_id'/>"; |
1539 | - wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
1540 | - wp_nonce_field( 'vat_validation', '_wpi_nonce' ); |
|
1539 | + wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form'); |
|
1540 | + wp_nonce_field('vat_validation', '_wpi_nonce'); |
|
1541 | 1541 | |
1542 | - foreach ( $elements as $element ) { |
|
1543 | - do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form ); |
|
1544 | - do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form ); |
|
1542 | + foreach ($elements as $element) { |
|
1543 | + do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form); |
|
1544 | + do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form); |
|
1545 | 1545 | } |
1546 | 1546 | |
1547 | 1547 | echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>"; |
1548 | - do_action( 'wpinv_payment_form_bottom' ); |
|
1548 | + do_action('wpinv_payment_form_bottom'); |
|
1549 | 1549 | echo '</form>'; |
1550 | 1550 | |
1551 | 1551 | $content = ob_get_clean(); |
1552 | - return str_replace( 'sr-only', '', $content ); |
|
1552 | + return str_replace('sr-only', '', $content); |
|
1553 | 1553 | } |
1554 | 1554 | |
1555 | 1555 | /** |
1556 | 1556 | * Helper function to convert item string to array. |
1557 | 1557 | */ |
1558 | -function getpaid_convert_items_to_array( $items ) { |
|
1559 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1558 | +function getpaid_convert_items_to_array($items) { |
|
1559 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1560 | 1560 | $prepared = array(); |
1561 | 1561 | |
1562 | - foreach ( $items as $item ) { |
|
1563 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1562 | + foreach ($items as $item) { |
|
1563 | + $data = array_map('trim', explode('|', $item)); |
|
1564 | 1564 | |
1565 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1565 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1566 | 1566 | continue; |
1567 | 1567 | } |
1568 | 1568 | |
1569 | 1569 | $quantity = 1; |
1570 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1570 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1571 | 1571 | $quantity = (int) $data[1]; |
1572 | 1572 | } |
1573 | 1573 | |
1574 | - $prepared[ $data[0] ] = $quantity; |
|
1574 | + $prepared[$data[0]] = $quantity; |
|
1575 | 1575 | |
1576 | 1576 | } |
1577 | 1577 | |
@@ -1581,13 +1581,13 @@ discard block |
||
1581 | 1581 | /** |
1582 | 1582 | * Helper function to convert item array to string. |
1583 | 1583 | */ |
1584 | -function getpaid_convert_items_to_string( $items ) { |
|
1584 | +function getpaid_convert_items_to_string($items) { |
|
1585 | 1585 | $prepared = array(); |
1586 | 1586 | |
1587 | - foreach ( $items as $item => $quantity ) { |
|
1587 | + foreach ($items as $item => $quantity) { |
|
1588 | 1588 | $prepared[] = "$item|$quantity"; |
1589 | 1589 | } |
1590 | - return implode( ',', $prepared ); |
|
1590 | + return implode(',', $prepared); |
|
1591 | 1591 | } |
1592 | 1592 | |
1593 | 1593 | /** |
@@ -1595,22 +1595,22 @@ discard block |
||
1595 | 1595 | * |
1596 | 1596 | * Provide a label and one of $form, $items or $invoice. |
1597 | 1597 | */ |
1598 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1599 | - $label = sanitize_text_field( $label ); |
|
1598 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1599 | + $label = sanitize_text_field($label); |
|
1600 | 1600 | $nonce = wp_create_nonce('getpaid_ajax_form'); |
1601 | 1601 | |
1602 | - if ( ! empty( $form ) ) { |
|
1603 | - $form = esc_attr( $form ); |
|
1602 | + if (!empty($form)) { |
|
1603 | + $form = esc_attr($form); |
|
1604 | 1604 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; |
1605 | 1605 | } |
1606 | 1606 | |
1607 | - if ( ! empty( $items ) ) { |
|
1608 | - $items = esc_attr( $items ); |
|
1607 | + if (!empty($items)) { |
|
1608 | + $items = esc_attr($items); |
|
1609 | 1609 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; |
1610 | 1610 | } |
1611 | 1611 | |
1612 | - if ( ! empty( $invoice ) ) { |
|
1613 | - $invoice = esc_attr( $invoice ); |
|
1612 | + if (!empty($invoice)) { |
|
1613 | + $invoice = esc_attr($invoice); |
|
1614 | 1614 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; |
1615 | 1615 | } |
1616 | 1616 | |
@@ -1621,17 +1621,17 @@ discard block |
||
1621 | 1621 | * |
1622 | 1622 | * @param WPInv_Invoice $invoice |
1623 | 1623 | */ |
1624 | -function getpaid_the_invoice_description( $invoice ) { |
|
1624 | +function getpaid_the_invoice_description($invoice) { |
|
1625 | 1625 | $description = $invoice->get_description(); |
1626 | 1626 | |
1627 | - if ( empty( $description ) ) { |
|
1627 | + if (empty($description)) { |
|
1628 | 1628 | return; |
1629 | 1629 | } |
1630 | 1630 | |
1631 | - $description = wp_kses_post( $description ); |
|
1631 | + $description = wp_kses_post($description); |
|
1632 | 1632 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>"; |
1633 | 1633 | } |
1634 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1634 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1635 | 1635 | |
1636 | 1636 | /** |
1637 | 1637 | * Render element on a form. |
@@ -1639,41 +1639,41 @@ discard block |
||
1639 | 1639 | * @param array $element |
1640 | 1640 | * @param GetPaid_Payment_Form $form |
1641 | 1641 | */ |
1642 | -function getpaid_payment_form_element( $element, $form ) { |
|
1642 | +function getpaid_payment_form_element($element, $form) { |
|
1643 | 1643 | |
1644 | 1644 | // Set up the args. |
1645 | - $element_type = trim( $element['type'] ); |
|
1645 | + $element_type = trim($element['type']); |
|
1646 | 1646 | $element['form'] = $form; |
1647 | - extract( $element ); |
|
1647 | + extract($element); |
|
1648 | 1648 | |
1649 | 1649 | // Try to locate the appropriate template. |
1650 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1650 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1651 | 1651 | |
1652 | 1652 | // Abort if this is not our element. |
1653 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1653 | + if (empty($located) || !file_exists($located)) { |
|
1654 | 1654 | return; |
1655 | 1655 | } |
1656 | 1656 | |
1657 | 1657 | // Generate the class and id of the element. |
1658 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1659 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1658 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1659 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1660 | 1660 | |
1661 | 1661 | // Echo the opening wrapper. |
1662 | 1662 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
1663 | 1663 | |
1664 | 1664 | // Fires before displaying a given element type's content. |
1665 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1665 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1666 | 1666 | |
1667 | 1667 | // Include the template for the element. |
1668 | 1668 | include $located; |
1669 | 1669 | |
1670 | 1670 | // Fires after displaying a given element type's content. |
1671 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1671 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1672 | 1672 | |
1673 | 1673 | // Echo the closing wrapper. |
1674 | 1674 | echo '</div>'; |
1675 | 1675 | } |
1676 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1676 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1677 | 1677 | |
1678 | 1678 | /** |
1679 | 1679 | * Shows a list of gateways that support recurring payments. |
@@ -1681,17 +1681,17 @@ discard block |
||
1681 | 1681 | function wpinv_get_recurring_gateways_text() { |
1682 | 1682 | $gateways = array(); |
1683 | 1683 | |
1684 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1685 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1686 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1684 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1685 | + if (wpinv_gateway_support_subscription($key)) { |
|
1686 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1687 | 1687 | } |
1688 | 1688 | } |
1689 | 1689 | |
1690 | - if ( empty( $gateways ) ) { |
|
1691 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>"; |
|
1690 | + if (empty($gateways)) { |
|
1691 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>"; |
|
1692 | 1692 | } |
1693 | 1693 | |
1694 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>"; |
|
1694 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>"; |
|
1695 | 1695 | |
1696 | 1696 | } |
1697 | 1697 | |
@@ -1701,7 +1701,7 @@ discard block |
||
1701 | 1701 | * @return GetPaid_Template |
1702 | 1702 | */ |
1703 | 1703 | function getpaid_template() { |
1704 | - return getpaid()->get( 'template' ); |
|
1704 | + return getpaid()->get('template'); |
|
1705 | 1705 | } |
1706 | 1706 | |
1707 | 1707 | /** |
@@ -1710,23 +1710,23 @@ discard block |
||
1710 | 1710 | * @param array args |
1711 | 1711 | * @return string |
1712 | 1712 | */ |
1713 | -function getpaid_paginate_links( $args ) { |
|
1713 | +function getpaid_paginate_links($args) { |
|
1714 | 1714 | |
1715 | 1715 | $args['type'] = 'array'; |
1716 | 1716 | $args['mid_size'] = 1; |
1717 | - $pages = paginate_links( $args ); |
|
1717 | + $pages = paginate_links($args); |
|
1718 | 1718 | |
1719 | - if ( ! is_array( $pages ) ) { |
|
1719 | + if (!is_array($pages)) { |
|
1720 | 1720 | return ''; |
1721 | 1721 | } |
1722 | 1722 | |
1723 | 1723 | $_pages = array(); |
1724 | - foreach ( $pages as $page ) { |
|
1725 | - $_pages[] = str_replace( 'page-numbers', 'page-link text-decoration-none', $page ); |
|
1724 | + foreach ($pages as $page) { |
|
1725 | + $_pages[] = str_replace('page-numbers', 'page-link text-decoration-none', $page); |
|
1726 | 1726 | } |
1727 | 1727 | |
1728 | 1728 | $links = "<nav>\n\t<ul class='pagination justify-content-end m-0'>\n\t\t<li class='page-item'>"; |
1729 | - $links .= join( "</li>\n\t\t<li class='page-item'>", $_pages ); |
|
1729 | + $links .= join("</li>\n\t\t<li class='page-item'>", $_pages); |
|
1730 | 1730 | $links .= "</li>\n\t</ul>\n</nav>\n"; |
1731 | 1731 | |
1732 | 1732 | return $links; |
@@ -7,86 +7,86 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_item_quantities_enabled() { |
15 | - $ret = wpinv_get_option( 'item_quantities', true ); |
|
15 | + $ret = wpinv_get_option('item_quantities', true); |
|
16 | 16 | |
17 | - return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret ); |
|
17 | + return (bool) apply_filters('wpinv_item_quantities_enabled', $ret); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | function wpinv_get_ip() { |
21 | 21 | $ip = '127.0.0.1'; |
22 | 22 | |
23 | - if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
24 | - $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] ); |
|
25 | - } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
26 | - $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] ); |
|
27 | - } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) { |
|
28 | - $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ); |
|
23 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
24 | + $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); |
|
25 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
26 | + $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); |
|
27 | + } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|
28 | + $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']); |
|
29 | 29 | } |
30 | 30 | |
31 | - return apply_filters( 'wpinv_get_ip', $ip ); |
|
31 | + return apply_filters('wpinv_get_ip', $ip); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | function wpinv_get_user_agent() { |
35 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
36 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
35 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
36 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
37 | 37 | } else { |
38 | 38 | $user_agent = ''; |
39 | 39 | } |
40 | 40 | |
41 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
41 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
42 | 42 | } |
43 | 43 | |
44 | -function wpinv_sanitize_amount( $amount, $decimals = NULL ) { |
|
44 | +function wpinv_sanitize_amount($amount, $decimals = NULL) { |
|
45 | 45 | $is_negative = false; |
46 | 46 | $thousands_sep = wpinv_thousands_separator(); |
47 | 47 | $decimal_sep = wpinv_decimal_separator(); |
48 | - if ( $decimals === NULL ) { |
|
48 | + if ($decimals === NULL) { |
|
49 | 49 | $decimals = wpinv_decimals(); |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Sanitize the amount |
53 | - if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { |
|
54 | - if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
55 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
56 | - } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { |
|
57 | - $amount = str_replace( '.', '', $amount ); |
|
53 | + if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) { |
|
54 | + if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) { |
|
55 | + $amount = str_replace($thousands_sep, '', $amount); |
|
56 | + } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) { |
|
57 | + $amount = str_replace('.', '', $amount); |
|
58 | 58 | } |
59 | 59 | |
60 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
61 | - } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
62 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
60 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
61 | + } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
62 | + $amount = str_replace($thousands_sep, '', $amount); |
|
63 | 63 | } |
64 | 64 | |
65 | - if( $amount < 0 ) { |
|
65 | + if ($amount < 0) { |
|
66 | 66 | $is_negative = true; |
67 | 67 | } |
68 | 68 | |
69 | - $amount = preg_replace( '/[^0-9\.]/', '', $amount ); |
|
69 | + $amount = preg_replace('/[^0-9\.]/', '', $amount); |
|
70 | 70 | |
71 | - $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount ); |
|
72 | - $amount = number_format( (double) $amount, absint( $decimals ), '.', '' ); |
|
71 | + $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount); |
|
72 | + $amount = number_format((double) $amount, absint($decimals), '.', ''); |
|
73 | 73 | |
74 | - if( $is_negative ) { |
|
74 | + if ($is_negative) { |
|
75 | 75 | $amount *= -1; |
76 | 76 | } |
77 | 77 | |
78 | - return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals ); |
|
78 | + return apply_filters('wpinv_sanitize_amount', $amount, $decimals); |
|
79 | 79 | } |
80 | -add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
80 | +add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
81 | 81 | |
82 | -function wpinv_round_amount( $amount, $decimals = NULL ) { |
|
83 | - if ( $decimals === NULL ) { |
|
82 | +function wpinv_round_amount($amount, $decimals = NULL) { |
|
83 | + if ($decimals === NULL) { |
|
84 | 84 | $decimals = wpinv_decimals(); |
85 | 85 | } |
86 | 86 | |
87 | - $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) ); |
|
87 | + $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals))); |
|
88 | 88 | |
89 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
89 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,32 +95,32 @@ discard block |
||
95 | 95 | * @since 1.0.19 |
96 | 96 | * @return array |
97 | 97 | */ |
98 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
98 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
99 | 99 | $invoice_statuses = array( |
100 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
101 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
102 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
103 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
104 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
105 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
106 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
107 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
100 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
101 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
102 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
103 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
104 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
105 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
106 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
107 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
108 | 108 | ); |
109 | 109 | |
110 | - if ( $draft ) { |
|
111 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
110 | + if ($draft) { |
|
111 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
112 | 112 | } |
113 | 113 | |
114 | - if ( $trashed ) { |
|
115 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
114 | + if ($trashed) { |
|
115 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
116 | 116 | } |
117 | 117 | |
118 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
118 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
119 | 119 | } |
120 | 120 | |
121 | -function wpinv_status_nicename( $status ) { |
|
122 | - $statuses = wpinv_get_invoice_statuses( true, true ); |
|
123 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
121 | +function wpinv_status_nicename($status) { |
|
122 | + $statuses = wpinv_get_invoice_statuses(true, true); |
|
123 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
124 | 124 | |
125 | 125 | return $status; |
126 | 126 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * Retrieves the default currency code. |
130 | 130 | */ |
131 | 131 | function wpinv_get_currency() { |
132 | - return apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
132 | + return apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -137,61 +137,61 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @param string|null $currency The currency code. Defaults to the default currency. |
139 | 139 | */ |
140 | -function wpinv_currency_symbol( $currency = null ) { |
|
140 | +function wpinv_currency_symbol($currency = null) { |
|
141 | 141 | |
142 | 142 | // Prepare the currency. |
143 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
143 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
144 | 144 | |
145 | 145 | // Fetch all symbols. |
146 | 146 | $symbols = wpinv_get_currency_symbols(); |
147 | 147 | |
148 | 148 | // Fetch this currencies symbol. |
149 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency; |
|
149 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
150 | 150 | |
151 | 151 | // Filter the symbol. |
152 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
152 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | function wpinv_currency_position() { |
156 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
156 | + $position = wpinv_get_option('currency_position', 'left'); |
|
157 | 157 | |
158 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
158 | + return apply_filters('wpinv_currency_position', $position); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | function wpinv_thousands_separator() { |
162 | - $thousand_sep = wpinv_get_option( 'thousands_separator', ',' ); |
|
162 | + $thousand_sep = wpinv_get_option('thousands_separator', ','); |
|
163 | 163 | |
164 | - return apply_filters( 'wpinv_thousands_separator', $thousand_sep ); |
|
164 | + return apply_filters('wpinv_thousands_separator', $thousand_sep); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | function wpinv_decimal_separator() { |
168 | - $decimal_sep = wpinv_get_option( 'decimal_separator', '.' ); |
|
168 | + $decimal_sep = wpinv_get_option('decimal_separator', '.'); |
|
169 | 169 | |
170 | - return apply_filters( 'wpinv_decimal_separator', $decimal_sep ); |
|
170 | + return apply_filters('wpinv_decimal_separator', $decimal_sep); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | function wpinv_decimals() { |
174 | - $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) ); |
|
174 | + $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2)); |
|
175 | 175 | |
176 | - return absint( $decimals ); |
|
176 | + return absint($decimals); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
180 | 180 | * Retrieves a list of all supported currencies. |
181 | 181 | */ |
182 | 182 | function wpinv_get_currencies() { |
183 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
183 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
187 | 187 | * Retrieves a list of all currency symbols. |
188 | 188 | */ |
189 | 189 | function wpinv_get_currency_symbols() { |
190 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
190 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_price( $amount = '', $currency = '' ) { |
|
194 | - if( empty( $currency ) ) { |
|
193 | +function wpinv_price($amount = '', $currency = '') { |
|
194 | + if (empty($currency)) { |
|
195 | 195 | $currency = wpinv_get_currency(); |
196 | 196 | } |
197 | 197 | |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | |
200 | 200 | $negative = $amount < 0; |
201 | 201 | |
202 | - if ( $negative ) { |
|
203 | - $amount = substr( $amount, 1 ); |
|
202 | + if ($negative) { |
|
203 | + $amount = substr($amount, 1); |
|
204 | 204 | } |
205 | 205 | |
206 | - $symbol = wpinv_currency_symbol( $currency ); |
|
206 | + $symbol = wpinv_currency_symbol($currency); |
|
207 | 207 | |
208 | - if ( $position == 'left' || $position == 'left_space' ) { |
|
209 | - switch ( $currency ) { |
|
208 | + if ($position == 'left' || $position == 'left_space') { |
|
209 | + switch ($currency) { |
|
210 | 210 | case "GBP" : |
211 | 211 | case "BRL" : |
212 | 212 | case "EUR" : |
@@ -218,15 +218,15 @@ discard block |
||
218 | 218 | case "NZD" : |
219 | 219 | case "SGD" : |
220 | 220 | case "JPY" : |
221 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
221 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
222 | 222 | break; |
223 | 223 | default : |
224 | 224 | //$price = $currency . ' ' . $amount; |
225 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
225 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
226 | 226 | break; |
227 | 227 | } |
228 | 228 | } else { |
229 | - switch ( $currency ) { |
|
229 | + switch ($currency) { |
|
230 | 230 | case "GBP" : |
231 | 231 | case "BRL" : |
232 | 232 | case "EUR" : |
@@ -237,83 +237,83 @@ discard block |
||
237 | 237 | case "MXN" : |
238 | 238 | case "SGD" : |
239 | 239 | case "JPY" : |
240 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
240 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
241 | 241 | break; |
242 | 242 | default : |
243 | 243 | //$price = $amount . ' ' . $currency; |
244 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
244 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
245 | 245 | break; |
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
249 | - if ( $negative ) { |
|
249 | + if ($negative) { |
|
250 | 250 | $price = '-' . $price; |
251 | 251 | } |
252 | 252 | |
253 | - $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount ); |
|
253 | + $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount); |
|
254 | 254 | |
255 | 255 | return $price; |
256 | 256 | } |
257 | 257 | |
258 | -function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
|
258 | +function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) { |
|
259 | 259 | $thousands_sep = wpinv_thousands_separator(); |
260 | 260 | $decimal_sep = wpinv_decimal_separator(); |
261 | 261 | |
262 | - if ( $decimals === NULL ) { |
|
262 | + if ($decimals === NULL) { |
|
263 | 263 | $decimals = wpinv_decimals(); |
264 | 264 | } |
265 | 265 | |
266 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
267 | - $whole = substr( $amount, 0, $sep_found ); |
|
268 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
266 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
267 | + $whole = substr($amount, 0, $sep_found); |
|
268 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
269 | 269 | $amount = $whole . '.' . $part; |
270 | 270 | } |
271 | 271 | |
272 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
273 | - $amount = str_replace( ',', '', $amount ); |
|
272 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
273 | + $amount = str_replace(',', '', $amount); |
|
274 | 274 | } |
275 | 275 | |
276 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
277 | - $amount = str_replace( ' ', '', $amount ); |
|
276 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
277 | + $amount = str_replace(' ', '', $amount); |
|
278 | 278 | } |
279 | 279 | |
280 | - if ( empty( $amount ) ) { |
|
280 | + if (empty($amount)) { |
|
281 | 281 | $amount = 0; |
282 | 282 | } |
283 | 283 | |
284 | - $decimals = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate ); |
|
285 | - $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep ); |
|
284 | + $decimals = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate); |
|
285 | + $formatted = number_format((float) $amount, $decimals, $decimal_sep, $thousands_sep); |
|
286 | 286 | |
287 | - if ( $calculate ) { |
|
288 | - if ( $thousands_sep === "," ) { |
|
289 | - $formatted = str_replace( ",", "", $formatted ); |
|
287 | + if ($calculate) { |
|
288 | + if ($thousands_sep === ",") { |
|
289 | + $formatted = str_replace(",", "", $formatted); |
|
290 | 290 | } |
291 | 291 | |
292 | - if ( $decimal_sep === "," ) { |
|
293 | - $formatted = str_replace( ",", ".", $formatted ); |
|
292 | + if ($decimal_sep === ",") { |
|
293 | + $formatted = str_replace(",", ".", $formatted); |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
297 | - return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate ); |
|
297 | + return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate); |
|
298 | 298 | } |
299 | -add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 ); |
|
299 | +add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1); |
|
300 | 300 | |
301 | -function wpinv_sanitize_key( $key ) { |
|
301 | +function wpinv_sanitize_key($key) { |
|
302 | 302 | $raw_key = $key; |
303 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
303 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
304 | 304 | |
305 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
305 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
306 | 306 | } |
307 | 307 | |
308 | -function wpinv_get_file_extension( $str ) { |
|
309 | - $parts = explode( '.', $str ); |
|
310 | - return end( $parts ); |
|
308 | +function wpinv_get_file_extension($str) { |
|
309 | + $parts = explode('.', $str); |
|
310 | + return end($parts); |
|
311 | 311 | } |
312 | 312 | |
313 | -function wpinv_string_is_image_url( $str ) { |
|
314 | - $ext = wpinv_get_file_extension( $str ); |
|
313 | +function wpinv_string_is_image_url($str) { |
|
314 | + $ext = wpinv_get_file_extension($str); |
|
315 | 315 | |
316 | - switch ( strtolower( $ext ) ) { |
|
316 | + switch (strtolower($ext)) { |
|
317 | 317 | case 'jpeg'; |
318 | 318 | case 'jpg'; |
319 | 319 | $return = true; |
@@ -329,33 +329,33 @@ discard block |
||
329 | 329 | break; |
330 | 330 | } |
331 | 331 | |
332 | - return (bool)apply_filters( 'wpinv_string_is_image', $return, $str ); |
|
332 | + return (bool) apply_filters('wpinv_string_is_image', $return, $str); |
|
333 | 333 | } |
334 | 334 | |
335 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
336 | - $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG ); |
|
335 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
336 | + $should_log = apply_filters('wpinv_log_errors', WP_DEBUG); |
|
337 | 337 | |
338 | - if ( true === $should_log ) { |
|
338 | + if (true === $should_log) { |
|
339 | 339 | $label = ''; |
340 | - if ( $file && $file !== '' ) { |
|
341 | - $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' ); |
|
340 | + if ($file && $file !== '') { |
|
341 | + $label .= basename($file) . ($line ? '(' . $line . ')' : ''); |
|
342 | 342 | } |
343 | 343 | |
344 | - if ( $title && $title !== '' ) { |
|
344 | + if ($title && $title !== '') { |
|
345 | 345 | $label = $label !== '' ? $label . ' ' : ''; |
346 | 346 | $label .= $title . ' '; |
347 | 347 | } |
348 | 348 | |
349 | - $label = $label !== '' ? trim( $label ) . ' : ' : ''; |
|
349 | + $label = $label !== '' ? trim($label) . ' : ' : ''; |
|
350 | 350 | |
351 | - if ( is_array( $log ) || is_object( $log ) ) { |
|
352 | - error_log( $label . print_r( $log, true ) ); |
|
351 | + if (is_array($log) || is_object($log)) { |
|
352 | + error_log($label . print_r($log, true)); |
|
353 | 353 | } else { |
354 | - error_log( $label . $log ); |
|
354 | + error_log($label . $log); |
|
355 | 355 | } |
356 | 356 | |
357 | - error_log( wp_debug_backtrace_summary() ); |
|
358 | - if ( $exit ) { |
|
357 | + error_log(wp_debug_backtrace_summary()); |
|
358 | + if ($exit) { |
|
359 | 359 | exit; |
360 | 360 | } |
361 | 361 | } |
@@ -363,32 +363,32 @@ discard block |
||
363 | 363 | |
364 | 364 | function wpinv_is_ajax_disabled() { |
365 | 365 | $retval = false; |
366 | - return apply_filters( 'wpinv_is_ajax_disabled', $retval ); |
|
366 | + return apply_filters('wpinv_is_ajax_disabled', $retval); |
|
367 | 367 | } |
368 | 368 | |
369 | -function wpinv_get_current_page_url( $nocache = false ) { |
|
369 | +function wpinv_get_current_page_url($nocache = false) { |
|
370 | 370 | global $wp; |
371 | 371 | |
372 | - if ( get_option( 'permalink_structure' ) ) { |
|
373 | - $base = trailingslashit( home_url( $wp->request ) ); |
|
372 | + if (get_option('permalink_structure')) { |
|
373 | + $base = trailingslashit(home_url($wp->request)); |
|
374 | 374 | } else { |
375 | - $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) ); |
|
376 | - $base = remove_query_arg( array( 'post_type', 'name' ), $base ); |
|
375 | + $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request))); |
|
376 | + $base = remove_query_arg(array('post_type', 'name'), $base); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | $scheme = is_ssl() ? 'https' : 'http'; |
380 | - $uri = set_url_scheme( $base, $scheme ); |
|
380 | + $uri = set_url_scheme($base, $scheme); |
|
381 | 381 | |
382 | - if ( is_front_page() ) { |
|
383 | - $uri = home_url( '/' ); |
|
384 | - } elseif ( wpinv_is_checkout( array(), false ) ) { |
|
382 | + if (is_front_page()) { |
|
383 | + $uri = home_url('/'); |
|
384 | + } elseif (wpinv_is_checkout(array(), false)) { |
|
385 | 385 | $uri = wpinv_get_checkout_uri(); |
386 | 386 | } |
387 | 387 | |
388 | - $uri = apply_filters( 'wpinv_get_current_page_url', $uri ); |
|
388 | + $uri = apply_filters('wpinv_get_current_page_url', $uri); |
|
389 | 389 | |
390 | - if ( $nocache ) { |
|
391 | - $uri = wpinv_add_cache_busting( $uri ); |
|
390 | + if ($nocache) { |
|
391 | + $uri = wpinv_add_cache_busting($uri); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | return $uri; |
@@ -401,46 +401,46 @@ discard block |
||
401 | 401 | * @param string $name Constant name. |
402 | 402 | * @param mixed $value Value. |
403 | 403 | */ |
404 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
405 | - if ( ! defined( $name ) ) { |
|
406 | - define( $name, $value ); |
|
404 | +function getpaid_maybe_define_constant($name, $value) { |
|
405 | + if (!defined($name)) { |
|
406 | + define($name, $value); |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | 410 | function wpinv_get_php_arg_separator_output() { |
411 | - return ini_get( 'arg_separator.output' ); |
|
411 | + return ini_get('arg_separator.output'); |
|
412 | 412 | } |
413 | 413 | |
414 | -function wpinv_rgb_from_hex( $color ) { |
|
415 | - $color = str_replace( '#', '', $color ); |
|
414 | +function wpinv_rgb_from_hex($color) { |
|
415 | + $color = str_replace('#', '', $color); |
|
416 | 416 | |
417 | 417 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
418 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
419 | - if ( empty( $color ) ) { |
|
418 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
419 | + if (empty($color)) { |
|
420 | 420 | return NULL; |
421 | 421 | } |
422 | 422 | |
423 | - $color = str_split( $color ); |
|
423 | + $color = str_split($color); |
|
424 | 424 | |
425 | 425 | $rgb = array(); |
426 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
427 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
428 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
426 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
427 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
428 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
429 | 429 | |
430 | 430 | return $rgb; |
431 | 431 | } |
432 | 432 | |
433 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
434 | - $base = wpinv_rgb_from_hex( $color ); |
|
433 | +function wpinv_hex_darker($color, $factor = 30) { |
|
434 | + $base = wpinv_rgb_from_hex($color); |
|
435 | 435 | $color = '#'; |
436 | 436 | |
437 | - foreach ( $base as $k => $v ) { |
|
437 | + foreach ($base as $k => $v) { |
|
438 | 438 | $amount = $v / 100; |
439 | - $amount = round( $amount * $factor ); |
|
439 | + $amount = round($amount * $factor); |
|
440 | 440 | $new_decimal = $v - $amount; |
441 | 441 | |
442 | - $new_hex_component = dechex( $new_decimal ); |
|
443 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
442 | + $new_hex_component = dechex($new_decimal); |
|
443 | + if (strlen($new_hex_component) < 2) { |
|
444 | 444 | $new_hex_component = "0" . $new_hex_component; |
445 | 445 | } |
446 | 446 | $color .= $new_hex_component; |
@@ -449,18 +449,18 @@ discard block |
||
449 | 449 | return $color; |
450 | 450 | } |
451 | 451 | |
452 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
453 | - $base = wpinv_rgb_from_hex( $color ); |
|
452 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
453 | + $base = wpinv_rgb_from_hex($color); |
|
454 | 454 | $color = '#'; |
455 | 455 | |
456 | - foreach ( $base as $k => $v ) { |
|
456 | + foreach ($base as $k => $v) { |
|
457 | 457 | $amount = 255 - $v; |
458 | 458 | $amount = $amount / 100; |
459 | - $amount = round( $amount * $factor ); |
|
459 | + $amount = round($amount * $factor); |
|
460 | 460 | $new_decimal = $v + $amount; |
461 | 461 | |
462 | - $new_hex_component = dechex( $new_decimal ); |
|
463 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
462 | + $new_hex_component = dechex($new_decimal); |
|
463 | + if (strlen($new_hex_component) < 2) { |
|
464 | 464 | $new_hex_component = "0" . $new_hex_component; |
465 | 465 | } |
466 | 466 | $color .= $new_hex_component; |
@@ -469,22 +469,22 @@ discard block |
||
469 | 469 | return $color; |
470 | 470 | } |
471 | 471 | |
472 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
473 | - $hex = str_replace( '#', '', $color ); |
|
472 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
473 | + $hex = str_replace('#', '', $color); |
|
474 | 474 | |
475 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
476 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
477 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
475 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
476 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
477 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
478 | 478 | |
479 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
479 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
480 | 480 | |
481 | 481 | return $brightness > 155 ? $dark : $light; |
482 | 482 | } |
483 | 483 | |
484 | -function wpinv_format_hex( $hex ) { |
|
485 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
484 | +function wpinv_format_hex($hex) { |
|
485 | + $hex = trim(str_replace('#', '', $hex)); |
|
486 | 486 | |
487 | - if ( strlen( $hex ) == 3 ) { |
|
487 | + if (strlen($hex) == 3) { |
|
488 | 488 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
489 | 489 | } |
490 | 490 | |
@@ -504,12 +504,12 @@ discard block |
||
504 | 504 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
505 | 505 | * @return string |
506 | 506 | */ |
507 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
508 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
509 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
507 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
508 | + if (function_exists('mb_strimwidth')) { |
|
509 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
510 | 510 | } |
511 | 511 | |
512 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
512 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -521,28 +521,28 @@ discard block |
||
521 | 521 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
522 | 522 | * @return int Returns the number of characters in string. |
523 | 523 | */ |
524 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
525 | - if ( function_exists( 'mb_strlen' ) ) { |
|
526 | - return mb_strlen( $str, $encoding ); |
|
524 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
525 | + if (function_exists('mb_strlen')) { |
|
526 | + return mb_strlen($str, $encoding); |
|
527 | 527 | } |
528 | 528 | |
529 | - return strlen( $str ); |
|
529 | + return strlen($str); |
|
530 | 530 | } |
531 | 531 | |
532 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
533 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
534 | - return mb_strtolower( $str, $encoding ); |
|
532 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
533 | + if (function_exists('mb_strtolower')) { |
|
534 | + return mb_strtolower($str, $encoding); |
|
535 | 535 | } |
536 | 536 | |
537 | - return strtolower( $str ); |
|
537 | + return strtolower($str); |
|
538 | 538 | } |
539 | 539 | |
540 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
541 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
542 | - return mb_strtoupper( $str, $encoding ); |
|
540 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
541 | + if (function_exists('mb_strtoupper')) { |
|
542 | + return mb_strtoupper($str, $encoding); |
|
543 | 543 | } |
544 | 544 | |
545 | - return strtoupper( $str ); |
|
545 | + return strtoupper($str); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -556,12 +556,12 @@ discard block |
||
556 | 556 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
557 | 557 | * @return int Returns the position of the first occurrence of search in the string. |
558 | 558 | */ |
559 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
560 | - if ( function_exists( 'mb_strpos' ) ) { |
|
561 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
559 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
560 | + if (function_exists('mb_strpos')) { |
|
561 | + return mb_strpos($str, $find, $offset, $encoding); |
|
562 | 562 | } |
563 | 563 | |
564 | - return strpos( $str, $find, $offset ); |
|
564 | + return strpos($str, $find, $offset); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -575,12 +575,12 @@ discard block |
||
575 | 575 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
576 | 576 | * @return int Returns the position of the last occurrence of search. |
577 | 577 | */ |
578 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
579 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
580 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
578 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
579 | + if (function_exists('mb_strrpos')) { |
|
580 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
581 | 581 | } |
582 | 582 | |
583 | - return strrpos( $str, $find, $offset ); |
|
583 | + return strrpos($str, $find, $offset); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -595,16 +595,16 @@ discard block |
||
595 | 595 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
596 | 596 | * @return string |
597 | 597 | */ |
598 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
599 | - if ( function_exists( 'mb_substr' ) ) { |
|
600 | - if ( $length === null ) { |
|
601 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
598 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
599 | + if (function_exists('mb_substr')) { |
|
600 | + if ($length === null) { |
|
601 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
602 | 602 | } else { |
603 | - return mb_substr( $str, $start, $length, $encoding ); |
|
603 | + return mb_substr($str, $start, $length, $encoding); |
|
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
607 | - return substr( $str, $start, $length ); |
|
607 | + return substr($str, $start, $length); |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | /** |
@@ -616,48 +616,48 @@ discard block |
||
616 | 616 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
617 | 617 | * @return string The width of string. |
618 | 618 | */ |
619 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
620 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
621 | - return mb_strwidth( $str, $encoding ); |
|
619 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
620 | + if (function_exists('mb_strwidth')) { |
|
621 | + return mb_strwidth($str, $encoding); |
|
622 | 622 | } |
623 | 623 | |
624 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
624 | + return wpinv_utf8_strlen($str, $encoding); |
|
625 | 625 | } |
626 | 626 | |
627 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
628 | - if ( function_exists( 'mb_strlen' ) ) { |
|
629 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
627 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
628 | + if (function_exists('mb_strlen')) { |
|
629 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
630 | 630 | $str_end = ""; |
631 | 631 | |
632 | - if ( $lower_str_end ) { |
|
633 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
632 | + if ($lower_str_end) { |
|
633 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
634 | 634 | } else { |
635 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
635 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | return $first_letter . $str_end; |
639 | 639 | } |
640 | 640 | |
641 | - return ucfirst( $str ); |
|
641 | + return ucfirst($str); |
|
642 | 642 | } |
643 | 643 | |
644 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
645 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
646 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
644 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
645 | + if (function_exists('mb_convert_case')) { |
|
646 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
647 | 647 | } |
648 | 648 | |
649 | - return ucwords( $str ); |
|
649 | + return ucwords($str); |
|
650 | 650 | } |
651 | 651 | |
652 | -function wpinv_period_in_days( $period, $unit ) { |
|
653 | - $period = absint( $period ); |
|
652 | +function wpinv_period_in_days($period, $unit) { |
|
653 | + $period = absint($period); |
|
654 | 654 | |
655 | - if ( $period > 0 ) { |
|
656 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
655 | + if ($period > 0) { |
|
656 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
657 | 657 | $period = $period * 7; |
658 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
658 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
659 | 659 | $period = $period * 30; |
660 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
660 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
661 | 661 | $period = $period * 365; |
662 | 662 | } |
663 | 663 | } |
@@ -665,14 +665,14 @@ discard block |
||
665 | 665 | return $period; |
666 | 666 | } |
667 | 667 | |
668 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
669 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
670 | - return cal_days_in_month( $calendar, $month, $year ); |
|
668 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
669 | + if (function_exists('cal_days_in_month')) { |
|
670 | + return cal_days_in_month($calendar, $month, $year); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | // Fallback in case the calendar extension is not loaded in PHP |
674 | 674 | // Only supports Gregorian calendar |
675 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
675 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
@@ -683,11 +683,11 @@ discard block |
||
683 | 683 | * |
684 | 684 | * @return string |
685 | 685 | */ |
686 | -function wpi_help_tip( $tip, $allow_html = false ) { |
|
687 | - if ( $allow_html ) { |
|
688 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
686 | +function wpi_help_tip($tip, $allow_html = false) { |
|
687 | + if ($allow_html) { |
|
688 | + $tip = wpi_sanitize_tooltip($tip); |
|
689 | 689 | } else { |
690 | - $tip = esc_attr( $tip ); |
|
690 | + $tip = esc_attr($tip); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -701,8 +701,8 @@ discard block |
||
701 | 701 | * @param string $var |
702 | 702 | * @return string |
703 | 703 | */ |
704 | -function wpi_sanitize_tooltip( $var ) { |
|
705 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
704 | +function wpi_sanitize_tooltip($var) { |
|
705 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
706 | 706 | 'br' => array(), |
707 | 707 | 'em' => array(), |
708 | 708 | 'strong' => array(), |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | 'li' => array(), |
713 | 713 | 'ol' => array(), |
714 | 714 | 'p' => array(), |
715 | - ) ) ); |
|
715 | + ))); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
@@ -722,7 +722,7 @@ discard block |
||
722 | 722 | */ |
723 | 723 | function wpinv_get_screen_ids() { |
724 | 724 | |
725 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
725 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
726 | 726 | |
727 | 727 | $screen_ids = array( |
728 | 728 | 'toplevel_page_' . $screen_id, |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | 'invoicing_page_wpi-addons', |
741 | 741 | ); |
742 | 742 | |
743 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
743 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | /** |
@@ -751,14 +751,14 @@ discard block |
||
751 | 751 | * @param array|string $list List of values. |
752 | 752 | * @return array Sanitized array of values. |
753 | 753 | */ |
754 | -function wpinv_parse_list( $list ) { |
|
754 | +function wpinv_parse_list($list) { |
|
755 | 755 | |
756 | - if ( empty( $list ) ) { |
|
756 | + if (empty($list)) { |
|
757 | 757 | $list = array(); |
758 | 758 | } |
759 | 759 | |
760 | - if ( ! is_array( $list ) ) { |
|
761 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
760 | + if (!is_array($list)) { |
|
761 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
762 | 762 | } |
763 | 763 | |
764 | 764 | return $list; |
@@ -772,16 +772,16 @@ discard block |
||
772 | 772 | * @param string $key Type of data to fetch. |
773 | 773 | * @return mixed Fetched data. |
774 | 774 | */ |
775 | -function wpinv_get_data( $key ) { |
|
775 | +function wpinv_get_data($key) { |
|
776 | 776 | |
777 | 777 | // Try fetching it from the cache. |
778 | - $data = wp_cache_get( "wpinv-data-$key", 'wpinv' ); |
|
779 | - if( $data ) { |
|
778 | + $data = wp_cache_get("wpinv-data-$key", 'wpinv'); |
|
779 | + if ($data) { |
|
780 | 780 | return $data; |
781 | 781 | } |
782 | 782 | |
783 | - $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
784 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
783 | + $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
784 | + wp_cache_set("wpinv-data-$key", $data, 'wpinv'); |
|
785 | 785 | |
786 | 786 | return $data; |
787 | 787 | } |
@@ -795,10 +795,10 @@ discard block |
||
795 | 795 | * @param bool $first_empty Whether or not the first item in the list should be empty |
796 | 796 | * @return mixed Fetched data. |
797 | 797 | */ |
798 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
798 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
799 | 799 | |
800 | - if ( ! empty( $options ) && $first_empty ) { |
|
801 | - return array_merge( array( '' => '' ), $options ); |
|
800 | + if (!empty($options) && $first_empty) { |
|
801 | + return array_merge(array('' => ''), $options); |
|
802 | 802 | } |
803 | 803 | return $options; |
804 | 804 | |
@@ -810,21 +810,21 @@ discard block |
||
810 | 810 | * @param mixed $var Data to sanitize. |
811 | 811 | * @return string|array |
812 | 812 | */ |
813 | -function wpinv_clean( $var ) { |
|
813 | +function wpinv_clean($var) { |
|
814 | 814 | |
815 | - if ( is_array( $var ) ) { |
|
816 | - return array_map( 'wpinv_clean', $var ); |
|
815 | + if (is_array($var)) { |
|
816 | + return array_map('wpinv_clean', $var); |
|
817 | 817 | } |
818 | 818 | |
819 | - if ( is_object( $var ) ) { |
|
820 | - $object_vars = get_object_vars( $var ); |
|
821 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
822 | - $var->$property_name = wpinv_clean( $property_value ); |
|
819 | + if (is_object($var)) { |
|
820 | + $object_vars = get_object_vars($var); |
|
821 | + foreach ($object_vars as $property_name => $property_value) { |
|
822 | + $var->$property_name = wpinv_clean($property_value); |
|
823 | 823 | } |
824 | 824 | return $var; |
825 | 825 | } |
826 | 826 | |
827 | - return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
|
827 | + return is_string($var) ? sanitize_text_field($var) : $var; |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | /** |
@@ -833,43 +833,43 @@ discard block |
||
833 | 833 | * @param string $str Data to convert. |
834 | 834 | * @return string|array |
835 | 835 | */ |
836 | -function getpaid_convert_price_string_to_options( $str ) { |
|
836 | +function getpaid_convert_price_string_to_options($str) { |
|
837 | 837 | |
838 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
839 | - $options = array(); |
|
838 | + $raw_options = array_map('trim', explode(',', $str)); |
|
839 | + $options = array(); |
|
840 | 840 | |
841 | - foreach ( $raw_options as $option ) { |
|
841 | + foreach ($raw_options as $option) { |
|
842 | 842 | |
843 | - if ( '' == $option ) { |
|
843 | + if ('' == $option) { |
|
844 | 844 | continue; |
845 | 845 | } |
846 | 846 | |
847 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
847 | + $option = array_map('trim', explode('|', $option)); |
|
848 | 848 | |
849 | 849 | $price = null; |
850 | 850 | $label = null; |
851 | 851 | |
852 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
853 | - $label = $option[0]; |
|
852 | + if (isset($option[0]) && '' != $option[0]) { |
|
853 | + $label = $option[0]; |
|
854 | 854 | } |
855 | 855 | |
856 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
856 | + if (isset($option[1]) && '' != $option[1]) { |
|
857 | 857 | $price = $option[1]; |
858 | 858 | } |
859 | 859 | |
860 | - if ( ! isset( $price ) ) { |
|
860 | + if (!isset($price)) { |
|
861 | 861 | $price = $label; |
862 | 862 | } |
863 | 863 | |
864 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
864 | + if (!isset($price) || !is_numeric($price)) { |
|
865 | 865 | continue; |
866 | 866 | } |
867 | 867 | |
868 | - if ( ! isset( $label ) ) { |
|
868 | + if (!isset($label)) { |
|
869 | 869 | $label = $price; |
870 | 870 | } |
871 | 871 | |
872 | - $options[ $price ] = $label; |
|
872 | + $options[$price] = $label; |
|
873 | 873 | } |
874 | 874 | |
875 | 875 | return $options; |
@@ -878,23 +878,23 @@ discard block |
||
878 | 878 | /** |
879 | 879 | * Returns the help tip. |
880 | 880 | */ |
881 | -function getpaid_get_help_tip( $tip, $additional_classes = '' ) { |
|
882 | - $additional_classes = sanitize_html_class( $additional_classes ); |
|
883 | - $tip = esc_attr__( $tip ); |
|
881 | +function getpaid_get_help_tip($tip, $additional_classes = '') { |
|
882 | + $additional_classes = sanitize_html_class($additional_classes); |
|
883 | + $tip = esc_attr__($tip); |
|
884 | 884 | return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>"; |
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
888 | 888 | * Formats a date |
889 | 889 | */ |
890 | -function getpaid_format_date( $date ) { |
|
890 | +function getpaid_format_date($date) { |
|
891 | 891 | |
892 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
892 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
893 | 893 | return ''; |
894 | 894 | } |
895 | 895 | |
896 | 896 | |
897 | - return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $date ) ); |
|
897 | + return date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($date)); |
|
898 | 898 | |
899 | 899 | } |
900 | 900 | |
@@ -905,16 +905,16 @@ discard block |
||
905 | 905 | * @param integer $limit Limit size in characters. |
906 | 906 | * @return string |
907 | 907 | */ |
908 | -function getpaid_limit_length( $string, $limit ) { |
|
908 | +function getpaid_limit_length($string, $limit) { |
|
909 | 909 | $str_limit = $limit - 3; |
910 | 910 | |
911 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
912 | - if ( mb_strlen( $string ) > $limit ) { |
|
913 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
911 | + if (function_exists('mb_strimwidth')) { |
|
912 | + if (mb_strlen($string) > $limit) { |
|
913 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
914 | 914 | } |
915 | 915 | } else { |
916 | - if ( strlen( $string ) > $limit ) { |
|
917 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
916 | + if (strlen($string) > $limit) { |
|
917 | + $string = substr($string, 0, $str_limit) . '...'; |
|
918 | 918 | } |
919 | 919 | } |
920 | 920 | return $string; |
@@ -928,7 +928,7 @@ discard block |
||
928 | 928 | * @since 1.0.19 |
929 | 929 | */ |
930 | 930 | function getpaid_api() { |
931 | - return getpaid()->get( 'api' ); |
|
931 | + return getpaid()->get('api'); |
|
932 | 932 | } |
933 | 933 | |
934 | 934 | /** |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | * @since 1.0.19 |
939 | 939 | */ |
940 | 940 | function getpaid_post_types() { |
941 | - return getpaid()->get( 'post_types' ); |
|
941 | + return getpaid()->get('post_types'); |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | /** |
@@ -948,7 +948,7 @@ discard block |
||
948 | 948 | * @since 1.0.19 |
949 | 949 | */ |
950 | 950 | function getpaid_session() { |
951 | - return getpaid()->get( 'session' ); |
|
951 | + return getpaid()->get('session'); |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | /** |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | * @since 1.0.19 |
959 | 959 | */ |
960 | 960 | function getpaid_notes() { |
961 | - return getpaid()->get( 'notes' ); |
|
961 | + return getpaid()->get('notes'); |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | /** |
@@ -970,26 +970,26 @@ discard block |
||
970 | 970 | * |
971 | 971 | * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query |
972 | 972 | */ |
973 | -function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
|
973 | +function getpaid_get_subscriptions($args = array(), $return = 'results') { |
|
974 | 974 | |
975 | 975 | // Do not retrieve all fields if we just want the count. |
976 | - if ( 'count' == $return ) { |
|
976 | + if ('count' == $return) { |
|
977 | 977 | $args['fields'] = 'id'; |
978 | 978 | $args['number'] = 1; |
979 | 979 | } |
980 | 980 | |
981 | 981 | // Do not count all matches if we just want the results. |
982 | - if ( 'results' == $return ) { |
|
982 | + if ('results' == $return) { |
|
983 | 983 | $args['count_total'] = false; |
984 | 984 | } |
985 | 985 | |
986 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
986 | + $query = new GetPaid_Subscriptions_Query($args); |
|
987 | 987 | |
988 | - if ( 'results' == $return ) { |
|
988 | + if ('results' == $return) { |
|
989 | 989 | return $query->get_results(); |
990 | 990 | } |
991 | 991 | |
992 | - if ( 'count' == $return ) { |
|
992 | + if ('count' == $return) { |
|
993 | 993 | return $query->get_total(); |
994 | 994 | } |
995 | 995 | |
@@ -1006,13 +1006,13 @@ discard block |
||
1006 | 1006 | return apply_filters( |
1007 | 1007 | 'getpaid_get_subscription_statuses', |
1008 | 1008 | array( |
1009 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
1010 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
1011 | - 'active' => __( 'Active', 'invoicing' ), |
|
1012 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
1013 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
1014 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
1015 | - 'cancelled' =>__( 'Cancelled', 'invoicing' ), |
|
1009 | + 'pending' => __('Pending', 'invoicing'), |
|
1010 | + 'trialling' => __('Trialing', 'invoicing'), |
|
1011 | + 'active' => __('Active', 'invoicing'), |
|
1012 | + 'failing' => __('Failing', 'invoicing'), |
|
1013 | + 'expired' => __('Expired', 'invoicing'), |
|
1014 | + 'completed' => __('Complete', 'invoicing'), |
|
1015 | + 'cancelled' =>__('Cancelled', 'invoicing'), |
|
1016 | 1016 | ) |
1017 | 1017 | ); |
1018 | 1018 | |
@@ -1023,9 +1023,9 @@ discard block |
||
1023 | 1023 | * |
1024 | 1024 | * @return string |
1025 | 1025 | */ |
1026 | -function getpaid_get_subscription_status_label( $status ) { |
|
1026 | +function getpaid_get_subscription_status_label($status) { |
|
1027 | 1027 | $statuses = getpaid_get_subscription_statuses(); |
1028 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( $status ); |
|
1028 | + return isset($statuses[$status]) ? $statuses[$status] : ucfirst($status); |
|
1029 | 1029 | } |
1030 | 1030 | |
1031 | 1031 | /** |
@@ -1055,14 +1055,14 @@ discard block |
||
1055 | 1055 | * |
1056 | 1056 | * @return array |
1057 | 1057 | */ |
1058 | -function getpaid_get_subscription_status_counts( $args = array() ) { |
|
1058 | +function getpaid_get_subscription_status_counts($args = array()) { |
|
1059 | 1059 | |
1060 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
1060 | + $statuses = array_keys(getpaid_get_subscription_statuses()); |
|
1061 | 1061 | $counts = array(); |
1062 | 1062 | |
1063 | - foreach ( $statuses as $status ) { |
|
1064 | - $_args = wp_parse_args( "status=$status", $args ); |
|
1065 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
1063 | + foreach ($statuses as $status) { |
|
1064 | + $_args = wp_parse_args("status=$status", $args); |
|
1065 | + $counts[$status] = getpaid_get_subscriptions($_args, 'count'); |
|
1066 | 1066 | } |
1067 | 1067 | |
1068 | 1068 | return $counts; |
@@ -1074,20 +1074,20 @@ discard block |
||
1074 | 1074 | * |
1075 | 1075 | * @return string |
1076 | 1076 | */ |
1077 | -function getpaid_get_subscription_period_label( $period ) { |
|
1077 | +function getpaid_get_subscription_period_label($period) { |
|
1078 | 1078 | |
1079 | 1079 | $periods = array( |
1080 | - 'd' => __( 'day', 'invoicing' ), |
|
1081 | - 'day' => __( 'day', 'invoicing' ), |
|
1082 | - 'w' => __( 'week', 'invoicing' ), |
|
1083 | - 'week' => __( 'week', 'invoicing' ), |
|
1084 | - 'm' => __( 'month', 'invoicing' ), |
|
1085 | - 'month' => __( 'month', 'invoicing' ), |
|
1086 | - 'y' => __( 'year', 'invoicing' ), |
|
1087 | - 'year' => __( 'year', 'invoicing' ), |
|
1080 | + 'd' => __('day', 'invoicing'), |
|
1081 | + 'day' => __('day', 'invoicing'), |
|
1082 | + 'w' => __('week', 'invoicing'), |
|
1083 | + 'week' => __('week', 'invoicing'), |
|
1084 | + 'm' => __('month', 'invoicing'), |
|
1085 | + 'month' => __('month', 'invoicing'), |
|
1086 | + 'y' => __('year', 'invoicing'), |
|
1087 | + 'year' => __('year', 'invoicing'), |
|
1088 | 1088 | ); |
1089 | 1089 | |
1090 | - return isset( $periods[ $period ] ) ? strtolower( $periods[ $period ] ) : strtolower( $periods['d'] ); |
|
1090 | + return isset($periods[$period]) ? strtolower($periods[$period]) : strtolower($periods['d']); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | /** |
@@ -1096,7 +1096,7 @@ discard block |
||
1096 | 1096 | * @return GetPaid_Admin |
1097 | 1097 | */ |
1098 | 1098 | function getpaid_admin() { |
1099 | - return getpaid()->get( 'admin' ); |
|
1099 | + return getpaid()->get('admin'); |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | /** |
@@ -1104,12 +1104,12 @@ discard block |
||
1104 | 1104 | * |
1105 | 1105 | * @return string |
1106 | 1106 | */ |
1107 | -function getpaid_format_date_value( $date, $default = "—" ) { |
|
1107 | +function getpaid_format_date_value($date, $default = "—") { |
|
1108 | 1108 | |
1109 | - if ( empty( $date ) || '0000-00-00 00:00:00' == $date ) { |
|
1109 | + if (empty($date) || '0000-00-00 00:00:00' == $date) { |
|
1110 | 1110 | return $default; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $date ) ); |
|
1113 | + return date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($date)); |
|
1114 | 1114 | |
1115 | 1115 | } |
@@ -14,144 +14,144 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
16 | 16 | |
17 | - /** |
|
18 | - * Register the widget with WordPress. |
|
19 | - * |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - |
|
23 | - $options = array( |
|
24 | - 'textdomain' => 'invoicing', |
|
25 | - 'block-icon' => 'controls-repeat', |
|
26 | - 'block-category'=> 'widgets', |
|
27 | - 'block-keywords'=> "['invoicing','subscriptions', 'getpaid']", |
|
28 | - 'class_name' => __CLASS__, |
|
29 | - 'base_id' => 'wpinv_subscriptions', |
|
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | - 'widget_ops' => array( |
|
32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | - ), |
|
35 | - 'arguments' => array( |
|
36 | - 'title' => array( |
|
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | - 'type' => 'text', |
|
40 | - 'desc_tip' => true, |
|
41 | - 'default' => '', |
|
42 | - 'advanced' => false |
|
43 | - ), |
|
44 | - ) |
|
45 | - |
|
46 | - ); |
|
47 | - |
|
48 | - |
|
49 | - parent::__construct( $options ); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Retrieves current user's subscriptions. |
|
54 | - * |
|
55 | - * @return GetPaid_Subscriptions_Query |
|
56 | - */ |
|
57 | - public function get_subscriptions() { |
|
58 | - |
|
59 | - // Prepare license args. |
|
60 | - $args = array( |
|
61 | - 'customer_in' => get_current_user_id(), |
|
62 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
63 | - ); |
|
64 | - |
|
65 | - return new GetPaid_Subscriptions_Query( $args ); |
|
66 | - |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * The Super block output function. |
|
71 | - * |
|
72 | - * @param array $args |
|
73 | - * @param array $widget_args |
|
74 | - * @param string $content |
|
75 | - * |
|
76 | - * @return mixed|string|bool |
|
77 | - */ |
|
78 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
79 | - |
|
80 | - // Ensure that the user is logged in. |
|
81 | - if ( ! is_user_logged_in() ) { |
|
82 | - |
|
83 | - return aui()->alert( |
|
84 | - array( |
|
85 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
86 | - 'type' => 'error', |
|
87 | - ) |
|
88 | - ); |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - // Are we displaying a single subscription? |
|
93 | - if ( isset( $_GET['subscription'] ) ) { |
|
94 | - return $this->display_single_subscription( trim( $_GET['subscription'] ) ); |
|
95 | - } |
|
96 | - |
|
97 | - // Retrieve the user's subscriptions. |
|
98 | - $subscriptions = $this->get_subscriptions(); |
|
99 | - |
|
100 | - // Start the output buffer. |
|
101 | - ob_start(); |
|
102 | - |
|
103 | - // Backwards compatibility. |
|
104 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
105 | - |
|
106 | - // Display errors and notices. |
|
107 | - wpinv_print_errors(); |
|
108 | - |
|
109 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
110 | - |
|
111 | - // Print the table header. |
|
112 | - $this->print_table_header(); |
|
113 | - |
|
114 | - // Print table body. |
|
115 | - $this->print_table_body( $subscriptions->get_results() ); |
|
116 | - |
|
117 | - // Print table footer. |
|
118 | - $this->print_table_footer(); |
|
119 | - |
|
120 | - // Print the navigation. |
|
121 | - $this->print_navigation( $subscriptions->get_total() ); |
|
122 | - |
|
123 | - // Backwards compatibility. |
|
124 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
125 | - |
|
126 | - // Return the output. |
|
127 | - return ob_get_clean(); |
|
128 | - |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Retrieves the subscription columns. |
|
133 | - * |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function get_subscriptions_table_columns() { |
|
17 | + /** |
|
18 | + * Register the widget with WordPress. |
|
19 | + * |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + |
|
23 | + $options = array( |
|
24 | + 'textdomain' => 'invoicing', |
|
25 | + 'block-icon' => 'controls-repeat', |
|
26 | + 'block-category'=> 'widgets', |
|
27 | + 'block-keywords'=> "['invoicing','subscriptions', 'getpaid']", |
|
28 | + 'class_name' => __CLASS__, |
|
29 | + 'base_id' => 'wpinv_subscriptions', |
|
30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | + 'widget_ops' => array( |
|
32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | + ), |
|
35 | + 'arguments' => array( |
|
36 | + 'title' => array( |
|
37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | + 'type' => 'text', |
|
40 | + 'desc_tip' => true, |
|
41 | + 'default' => '', |
|
42 | + 'advanced' => false |
|
43 | + ), |
|
44 | + ) |
|
45 | + |
|
46 | + ); |
|
47 | + |
|
48 | + |
|
49 | + parent::__construct( $options ); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Retrieves current user's subscriptions. |
|
54 | + * |
|
55 | + * @return GetPaid_Subscriptions_Query |
|
56 | + */ |
|
57 | + public function get_subscriptions() { |
|
58 | + |
|
59 | + // Prepare license args. |
|
60 | + $args = array( |
|
61 | + 'customer_in' => get_current_user_id(), |
|
62 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
63 | + ); |
|
64 | + |
|
65 | + return new GetPaid_Subscriptions_Query( $args ); |
|
66 | + |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * The Super block output function. |
|
71 | + * |
|
72 | + * @param array $args |
|
73 | + * @param array $widget_args |
|
74 | + * @param string $content |
|
75 | + * |
|
76 | + * @return mixed|string|bool |
|
77 | + */ |
|
78 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
79 | + |
|
80 | + // Ensure that the user is logged in. |
|
81 | + if ( ! is_user_logged_in() ) { |
|
82 | + |
|
83 | + return aui()->alert( |
|
84 | + array( |
|
85 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
86 | + 'type' => 'error', |
|
87 | + ) |
|
88 | + ); |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + // Are we displaying a single subscription? |
|
93 | + if ( isset( $_GET['subscription'] ) ) { |
|
94 | + return $this->display_single_subscription( trim( $_GET['subscription'] ) ); |
|
95 | + } |
|
96 | + |
|
97 | + // Retrieve the user's subscriptions. |
|
98 | + $subscriptions = $this->get_subscriptions(); |
|
99 | + |
|
100 | + // Start the output buffer. |
|
101 | + ob_start(); |
|
102 | + |
|
103 | + // Backwards compatibility. |
|
104 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
105 | + |
|
106 | + // Display errors and notices. |
|
107 | + wpinv_print_errors(); |
|
108 | + |
|
109 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
110 | + |
|
111 | + // Print the table header. |
|
112 | + $this->print_table_header(); |
|
113 | + |
|
114 | + // Print table body. |
|
115 | + $this->print_table_body( $subscriptions->get_results() ); |
|
116 | + |
|
117 | + // Print table footer. |
|
118 | + $this->print_table_footer(); |
|
119 | + |
|
120 | + // Print the navigation. |
|
121 | + $this->print_navigation( $subscriptions->get_total() ); |
|
122 | + |
|
123 | + // Backwards compatibility. |
|
124 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
125 | + |
|
126 | + // Return the output. |
|
127 | + return ob_get_clean(); |
|
128 | + |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Retrieves the subscription columns. |
|
133 | + * |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function get_subscriptions_table_columns() { |
|
137 | 137 | |
138 | - $columns = array( |
|
139 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
140 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
141 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
142 | - 'status' => __( 'Status', 'invoicing' ), |
|
143 | - ); |
|
138 | + $columns = array( |
|
139 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
140 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
141 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
142 | + 'status' => __( 'Status', 'invoicing' ), |
|
143 | + ); |
|
144 | 144 | |
145 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
146 | - } |
|
145 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Displays the table header. |
|
150 | - * |
|
151 | - */ |
|
152 | - public function print_table_header() { |
|
148 | + /** |
|
149 | + * Displays the table header. |
|
150 | + * |
|
151 | + */ |
|
152 | + public function print_table_header() { |
|
153 | 153 | |
154 | - ?> |
|
154 | + ?> |
|
155 | 155 | |
156 | 156 | <style> |
157 | 157 | |
@@ -191,128 +191,128 @@ discard block |
||
191 | 191 | |
192 | 192 | <?php |
193 | 193 | |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * Displays the table body. |
|
198 | - * |
|
199 | - * @param WPInv_Subscription[] $subscriptions |
|
200 | - */ |
|
201 | - public function print_table_body( $subscriptions ) { |
|
196 | + /** |
|
197 | + * Displays the table body. |
|
198 | + * |
|
199 | + * @param WPInv_Subscription[] $subscriptions |
|
200 | + */ |
|
201 | + public function print_table_body( $subscriptions ) { |
|
202 | 202 | |
203 | - if ( empty( $subscriptions ) ) { |
|
204 | - $this->print_table_body_no_subscriptions(); |
|
205 | - } else { |
|
206 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
207 | - } |
|
203 | + if ( empty( $subscriptions ) ) { |
|
204 | + $this->print_table_body_no_subscriptions(); |
|
205 | + } else { |
|
206 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
207 | + } |
|
208 | 208 | |
209 | - } |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * Displays the table body if no subscriptions were found. |
|
213 | - * |
|
214 | - */ |
|
215 | - public function print_table_body_no_subscriptions() { |
|
211 | + /** |
|
212 | + * Displays the table body if no subscriptions were found. |
|
213 | + * |
|
214 | + */ |
|
215 | + public function print_table_body_no_subscriptions() { |
|
216 | 216 | |
217 | - ?> |
|
217 | + ?> |
|
218 | 218 | <tbody> |
219 | 219 | |
220 | 220 | <tr> |
221 | 221 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
222 | 222 | |
223 | 223 | <?php |
224 | - echo aui()->alert( |
|
225 | - array( |
|
226 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
227 | - 'type' => 'warning', |
|
228 | - ) |
|
229 | - ); |
|
230 | - ?> |
|
224 | + echo aui()->alert( |
|
225 | + array( |
|
226 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
227 | + 'type' => 'warning', |
|
228 | + ) |
|
229 | + ); |
|
230 | + ?> |
|
231 | 231 | |
232 | 232 | </td> |
233 | 233 | </tr> |
234 | 234 | |
235 | 235 | </tbody> |
236 | 236 | <?php |
237 | - } |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * Displays the table body if subscriptions were found. |
|
241 | - * |
|
242 | - * @param WPInv_Subscription[] $subscriptions |
|
243 | - */ |
|
244 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
239 | + /** |
|
240 | + * Displays the table body if subscriptions were found. |
|
241 | + * |
|
242 | + * @param WPInv_Subscription[] $subscriptions |
|
243 | + */ |
|
244 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
245 | 245 | |
246 | - ?> |
|
246 | + ?> |
|
247 | 247 | <tbody> |
248 | 248 | |
249 | 249 | <?php foreach ( $subscriptions as $subscription ) : ?> |
250 | 250 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
251 | 251 | <?php |
252 | - wpinv_get_template( |
|
253 | - 'subscriptions/subscriptions-table-row.php', |
|
254 | - array( |
|
255 | - 'subscription' => $subscription, |
|
256 | - 'widget' => $this |
|
257 | - ) |
|
258 | - ); |
|
259 | - ?> |
|
252 | + wpinv_get_template( |
|
253 | + 'subscriptions/subscriptions-table-row.php', |
|
254 | + array( |
|
255 | + 'subscription' => $subscription, |
|
256 | + 'widget' => $this |
|
257 | + ) |
|
258 | + ); |
|
259 | + ?> |
|
260 | 260 | </tr> |
261 | 261 | <?php endforeach; ?> |
262 | 262 | |
263 | 263 | </tbody> |
264 | 264 | <?php |
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Adds row actions to a column |
|
269 | - * |
|
270 | - * @param string $content column content |
|
271 | - * @param WPInv_Subscription $subscription |
|
272 | - * @since 1.0.0 |
|
273 | - * @return string |
|
274 | - */ |
|
275 | - public function add_row_actions( $content, $subscription ) { |
|
276 | - |
|
277 | - // Prepare row actions. |
|
278 | - $actions = array(); |
|
279 | - |
|
280 | - // View subscription action. |
|
281 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
282 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
283 | - |
|
284 | - // View invoice action. |
|
285 | - $invoice = $subscription->get_parent_payment(); |
|
286 | - |
|
287 | - if ( $invoice->get_id() ) { |
|
288 | - $view_url = esc_url( $invoice->get_view_url() ); |
|
289 | - $actions['invoice'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
290 | - } |
|
291 | - |
|
292 | - // Filter the actions. |
|
293 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
294 | - |
|
295 | - $sanitized = array(); |
|
296 | - foreach ( $actions as $key => $action ) { |
|
297 | - $key = sanitize_html_class( $key ); |
|
298 | - $action = wp_kses_post( $action ); |
|
299 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
300 | - } |
|
301 | - |
|
302 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
303 | - $row_actions .= implode( ' | ', $sanitized ); |
|
304 | - $row_actions .= '</small>'; |
|
305 | - |
|
306 | - return $content . $row_actions; |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Displays the table footer. |
|
311 | - * |
|
312 | - */ |
|
313 | - public function print_table_footer() { |
|
314 | - |
|
315 | - ?> |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Adds row actions to a column |
|
269 | + * |
|
270 | + * @param string $content column content |
|
271 | + * @param WPInv_Subscription $subscription |
|
272 | + * @since 1.0.0 |
|
273 | + * @return string |
|
274 | + */ |
|
275 | + public function add_row_actions( $content, $subscription ) { |
|
276 | + |
|
277 | + // Prepare row actions. |
|
278 | + $actions = array(); |
|
279 | + |
|
280 | + // View subscription action. |
|
281 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
282 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
283 | + |
|
284 | + // View invoice action. |
|
285 | + $invoice = $subscription->get_parent_payment(); |
|
286 | + |
|
287 | + if ( $invoice->get_id() ) { |
|
288 | + $view_url = esc_url( $invoice->get_view_url() ); |
|
289 | + $actions['invoice'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
290 | + } |
|
291 | + |
|
292 | + // Filter the actions. |
|
293 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
294 | + |
|
295 | + $sanitized = array(); |
|
296 | + foreach ( $actions as $key => $action ) { |
|
297 | + $key = sanitize_html_class( $key ); |
|
298 | + $action = wp_kses_post( $action ); |
|
299 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
300 | + } |
|
301 | + |
|
302 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
303 | + $row_actions .= implode( ' | ', $sanitized ); |
|
304 | + $row_actions .= '</small>'; |
|
305 | + |
|
306 | + return $content . $row_actions; |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Displays the table footer. |
|
311 | + * |
|
312 | + */ |
|
313 | + public function print_table_footer() { |
|
314 | + |
|
315 | + ?> |
|
316 | 316 | |
317 | 317 | <tfoot> |
318 | 318 | <tr> |
@@ -327,130 +327,130 @@ discard block |
||
327 | 327 | </table> |
328 | 328 | <?php |
329 | 329 | |
330 | - } |
|
330 | + } |
|
331 | 331 | |
332 | - /** |
|
333 | - * Displays the navigation. |
|
334 | - * |
|
335 | - * @param int $total |
|
336 | - */ |
|
337 | - public function print_navigation( $total ) { |
|
332 | + /** |
|
333 | + * Displays the navigation. |
|
334 | + * |
|
335 | + * @param int $total |
|
336 | + */ |
|
337 | + public function print_navigation( $total ) { |
|
338 | 338 | |
339 | - if ( $total < 1 ) { |
|
339 | + if ( $total < 1 ) { |
|
340 | 340 | |
341 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
342 | - $args = array( |
|
343 | - 'customer_in' => get_current_user_id(), |
|
344 | - 'fields' => 'id', |
|
345 | - ); |
|
341 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
342 | + $args = array( |
|
343 | + 'customer_in' => get_current_user_id(), |
|
344 | + 'fields' => 'id', |
|
345 | + ); |
|
346 | 346 | |
347 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
348 | - $total = $count_query->get_total(); |
|
349 | - } |
|
347 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
348 | + $total = $count_query->get_total(); |
|
349 | + } |
|
350 | 350 | |
351 | - // Abort if we do not have pages. |
|
352 | - if ( 2 > $total ) { |
|
353 | - return; |
|
354 | - } |
|
351 | + // Abort if we do not have pages. |
|
352 | + if ( 2 > $total ) { |
|
353 | + return; |
|
354 | + } |
|
355 | 355 | |
356 | - ?> |
|
356 | + ?> |
|
357 | 357 | |
358 | 358 | <div class="getpaid-subscriptions-pagination"> |
359 | 359 | <?php |
360 | - $big = 999999; |
|
361 | - |
|
362 | - echo getpaid_paginate_links( |
|
363 | - array( |
|
364 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
365 | - 'format' => '?paged=%#%', |
|
366 | - 'total' => (int) ceil( $total / 10 ), |
|
367 | - ) |
|
368 | - ); |
|
369 | - ?> |
|
360 | + $big = 999999; |
|
361 | + |
|
362 | + echo getpaid_paginate_links( |
|
363 | + array( |
|
364 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
365 | + 'format' => '?paged=%#%', |
|
366 | + 'total' => (int) ceil( $total / 10 ), |
|
367 | + ) |
|
368 | + ); |
|
369 | + ?> |
|
370 | 370 | </div> |
371 | 371 | |
372 | 372 | <?php |
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Returns a single subscription's columns. |
|
377 | - * |
|
378 | - * @param WPInv_Subscription $subscription |
|
379 | - * |
|
380 | - * @return array |
|
381 | - */ |
|
382 | - public function get_single_subscription_columns( $subscription ) { |
|
383 | - |
|
384 | - // Prepare subscription detail columns. |
|
385 | - $fields = apply_filters( |
|
386 | - 'getpaid_single_subscription_details_fields', |
|
387 | - array( |
|
388 | - 'status' => __( 'Status', 'invoicing' ), |
|
389 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
390 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
391 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
392 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
393 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
394 | - 'item' => __( 'Item', 'invoicing' ), |
|
395 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
396 | - ), |
|
397 | - $subscription |
|
398 | - ); |
|
399 | - |
|
400 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
401 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
402 | - } |
|
403 | - |
|
404 | - if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
405 | - unset( $fields['initial_amount'] ); |
|
406 | - } |
|
407 | - |
|
408 | - return $fields; |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Displays a single subscription. |
|
413 | - * |
|
414 | - * @param string $subscription |
|
415 | - * |
|
416 | - * @return string |
|
417 | - */ |
|
418 | - public function display_single_subscription( $subscription ) { |
|
419 | - |
|
420 | - // Fetch the subscription. |
|
421 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
422 | - |
|
423 | - if ( ! $subscription->get_id() ) { |
|
424 | - |
|
425 | - return aui()->alert( |
|
426 | - array( |
|
427 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
428 | - 'type' => 'error', |
|
429 | - ) |
|
430 | - ); |
|
431 | - |
|
432 | - } |
|
433 | - |
|
434 | - // Ensure that the user owns this subscription key. |
|
435 | - if ( get_current_user_id() != $subscription->get_customer_id() ) { |
|
436 | - |
|
437 | - return aui()->alert( |
|
438 | - array( |
|
439 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
440 | - 'type' => 'error', |
|
441 | - ) |
|
442 | - ); |
|
443 | - |
|
444 | - } |
|
445 | - |
|
446 | - return wpinv_get_template_html( |
|
447 | - 'subscriptions/subscription-details.php', |
|
448 | - array( |
|
449 | - 'subscription' => $subscription, |
|
450 | - 'widget' => $this |
|
451 | - ) |
|
452 | - ); |
|
453 | - |
|
454 | - } |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Returns a single subscription's columns. |
|
377 | + * |
|
378 | + * @param WPInv_Subscription $subscription |
|
379 | + * |
|
380 | + * @return array |
|
381 | + */ |
|
382 | + public function get_single_subscription_columns( $subscription ) { |
|
383 | + |
|
384 | + // Prepare subscription detail columns. |
|
385 | + $fields = apply_filters( |
|
386 | + 'getpaid_single_subscription_details_fields', |
|
387 | + array( |
|
388 | + 'status' => __( 'Status', 'invoicing' ), |
|
389 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
390 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
391 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
392 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
393 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
394 | + 'item' => __( 'Item', 'invoicing' ), |
|
395 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
396 | + ), |
|
397 | + $subscription |
|
398 | + ); |
|
399 | + |
|
400 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
401 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
402 | + } |
|
403 | + |
|
404 | + if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
405 | + unset( $fields['initial_amount'] ); |
|
406 | + } |
|
407 | + |
|
408 | + return $fields; |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Displays a single subscription. |
|
413 | + * |
|
414 | + * @param string $subscription |
|
415 | + * |
|
416 | + * @return string |
|
417 | + */ |
|
418 | + public function display_single_subscription( $subscription ) { |
|
419 | + |
|
420 | + // Fetch the subscription. |
|
421 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
422 | + |
|
423 | + if ( ! $subscription->get_id() ) { |
|
424 | + |
|
425 | + return aui()->alert( |
|
426 | + array( |
|
427 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
428 | + 'type' => 'error', |
|
429 | + ) |
|
430 | + ); |
|
431 | + |
|
432 | + } |
|
433 | + |
|
434 | + // Ensure that the user owns this subscription key. |
|
435 | + if ( get_current_user_id() != $subscription->get_customer_id() ) { |
|
436 | + |
|
437 | + return aui()->alert( |
|
438 | + array( |
|
439 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
440 | + 'type' => 'error', |
|
441 | + ) |
|
442 | + ); |
|
443 | + |
|
444 | + } |
|
445 | + |
|
446 | + return wpinv_get_template_html( |
|
447 | + 'subscriptions/subscription-details.php', |
|
448 | + array( |
|
449 | + 'subscription' => $subscription, |
|
450 | + 'widget' => $this |
|
451 | + ) |
|
452 | + ); |
|
453 | + |
|
454 | + } |
|
455 | 455 | |
456 | 456 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.0 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Contains the subscriptions widget. |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | 'block-keywords'=> "['invoicing','subscriptions', 'getpaid']", |
28 | 28 | 'class_name' => __CLASS__, |
29 | 29 | 'base_id' => 'wpinv_subscriptions', |
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
30 | + 'name' => __('GetPaid > Subscriptions', 'invoicing'), |
|
31 | 31 | 'widget_ops' => array( |
32 | 32 | 'classname' => 'getpaid-subscriptions bsui', |
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
33 | + 'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'), |
|
34 | 34 | ), |
35 | 35 | 'arguments' => array( |
36 | 36 | 'title' => array( |
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
37 | + 'title' => __('Widget title', 'invoicing'), |
|
38 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
39 | 39 | 'type' => 'text', |
40 | 40 | 'desc_tip' => true, |
41 | 41 | 'default' => '', |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | ); |
47 | 47 | |
48 | 48 | |
49 | - parent::__construct( $options ); |
|
49 | + parent::__construct($options); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | public function get_subscriptions() { |
58 | 58 | |
59 | 59 | // Prepare license args. |
60 | - $args = array( |
|
60 | + $args = array( |
|
61 | 61 | 'customer_in' => get_current_user_id(), |
62 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | + 'paged' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
63 | 63 | ); |
64 | 64 | |
65 | - return new GetPaid_Subscriptions_Query( $args ); |
|
65 | + return new GetPaid_Subscriptions_Query($args); |
|
66 | 66 | |
67 | 67 | } |
68 | 68 | |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return mixed|string|bool |
77 | 77 | */ |
78 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
79 | 79 | |
80 | 80 | // Ensure that the user is logged in. |
81 | - if ( ! is_user_logged_in() ) { |
|
81 | + if (!is_user_logged_in()) { |
|
82 | 82 | |
83 | 83 | return aui()->alert( |
84 | 84 | array( |
85 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | + 'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')), |
|
86 | 86 | 'type' => 'error', |
87 | 87 | ) |
88 | 88 | ); |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | // Are we displaying a single subscription? |
93 | - if ( isset( $_GET['subscription'] ) ) { |
|
94 | - return $this->display_single_subscription( trim( $_GET['subscription'] ) ); |
|
93 | + if (isset($_GET['subscription'])) { |
|
94 | + return $this->display_single_subscription(trim($_GET['subscription'])); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | // Retrieve the user's subscriptions. |
@@ -101,27 +101,27 @@ discard block |
||
101 | 101 | ob_start(); |
102 | 102 | |
103 | 103 | // Backwards compatibility. |
104 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | + do_action('wpinv_before_user_subscriptions'); |
|
105 | 105 | |
106 | 106 | // Display errors and notices. |
107 | 107 | wpinv_print_errors(); |
108 | 108 | |
109 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | + do_action('getpaid_license_manager_before_subscriptions', $subscriptions); |
|
110 | 110 | |
111 | 111 | // Print the table header. |
112 | 112 | $this->print_table_header(); |
113 | 113 | |
114 | 114 | // Print table body. |
115 | - $this->print_table_body( $subscriptions->get_results() ); |
|
115 | + $this->print_table_body($subscriptions->get_results()); |
|
116 | 116 | |
117 | 117 | // Print table footer. |
118 | 118 | $this->print_table_footer(); |
119 | 119 | |
120 | 120 | // Print the navigation. |
121 | - $this->print_navigation( $subscriptions->get_total() ); |
|
121 | + $this->print_navigation($subscriptions->get_total()); |
|
122 | 122 | |
123 | 123 | // Backwards compatibility. |
124 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | + do_action('wpinv_after_user_subscriptions'); |
|
125 | 125 | |
126 | 126 | // Return the output. |
127 | 127 | return ob_get_clean(); |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | public function get_subscriptions_table_columns() { |
137 | 137 | |
138 | 138 | $columns = array( |
139 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
140 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
141 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
142 | - 'status' => __( 'Status', 'invoicing' ), |
|
139 | + 'subscription' => __('Subscription', 'invoicing'), |
|
140 | + 'amount' => __('Amount', 'invoicing'), |
|
141 | + 'renewal-date' => __('Next payment', 'invoicing'), |
|
142 | + 'status' => __('Status', 'invoicing'), |
|
143 | 143 | ); |
144 | 144 | |
145 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | + return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | |
182 | 182 | <thead> |
183 | 183 | <tr> |
184 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
185 | - <th scope="col" class="getpaid-subscriptions-table-<?php echo sanitize_html_class( $key ); ?>"> |
|
186 | - <?php echo sanitize_text_field( $label ); ?> |
|
184 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
185 | + <th scope="col" class="getpaid-subscriptions-table-<?php echo sanitize_html_class($key); ?>"> |
|
186 | + <?php echo sanitize_text_field($label); ?> |
|
187 | 187 | </th> |
188 | 188 | <?php endforeach; ?> |
189 | 189 | </tr> |
@@ -198,12 +198,12 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @param WPInv_Subscription[] $subscriptions |
200 | 200 | */ |
201 | - public function print_table_body( $subscriptions ) { |
|
201 | + public function print_table_body($subscriptions) { |
|
202 | 202 | |
203 | - if ( empty( $subscriptions ) ) { |
|
203 | + if (empty($subscriptions)) { |
|
204 | 204 | $this->print_table_body_no_subscriptions(); |
205 | 205 | } else { |
206 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
206 | + $this->print_table_body_subscriptions($subscriptions); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | } |
@@ -218,12 +218,12 @@ discard block |
||
218 | 218 | <tbody> |
219 | 219 | |
220 | 220 | <tr> |
221 | - <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
|
221 | + <td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>"> |
|
222 | 222 | |
223 | 223 | <?php |
224 | 224 | echo aui()->alert( |
225 | 225 | array( |
226 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
226 | + 'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')), |
|
227 | 227 | 'type' => 'warning', |
228 | 228 | ) |
229 | 229 | ); |
@@ -241,12 +241,12 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @param WPInv_Subscription[] $subscriptions |
243 | 243 | */ |
244 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
244 | + public function print_table_body_subscriptions($subscriptions) { |
|
245 | 245 | |
246 | 246 | ?> |
247 | 247 | <tbody> |
248 | 248 | |
249 | - <?php foreach ( $subscriptions as $subscription ) : ?> |
|
249 | + <?php foreach ($subscriptions as $subscription) : ?> |
|
250 | 250 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
251 | 251 | <?php |
252 | 252 | wpinv_get_template( |
@@ -272,35 +272,35 @@ discard block |
||
272 | 272 | * @since 1.0.0 |
273 | 273 | * @return string |
274 | 274 | */ |
275 | - public function add_row_actions( $content, $subscription ) { |
|
275 | + public function add_row_actions($content, $subscription) { |
|
276 | 276 | |
277 | 277 | // Prepare row actions. |
278 | 278 | $actions = array(); |
279 | 279 | |
280 | 280 | // View subscription action. |
281 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
282 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
281 | + $view_url = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
282 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
283 | 283 | |
284 | 284 | // View invoice action. |
285 | 285 | $invoice = $subscription->get_parent_payment(); |
286 | 286 | |
287 | - if ( $invoice->get_id() ) { |
|
288 | - $view_url = esc_url( $invoice->get_view_url() ); |
|
289 | - $actions['invoice'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
287 | + if ($invoice->get_id()) { |
|
288 | + $view_url = esc_url($invoice->get_view_url()); |
|
289 | + $actions['invoice'] = "<a href='$view_url' class='text-decoration-none'>" . __('View Invoice', 'invoicing') . '</a>'; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | // Filter the actions. |
293 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
293 | + $actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription); |
|
294 | 294 | |
295 | - $sanitized = array(); |
|
296 | - foreach ( $actions as $key => $action ) { |
|
297 | - $key = sanitize_html_class( $key ); |
|
298 | - $action = wp_kses_post( $action ); |
|
295 | + $sanitized = array(); |
|
296 | + foreach ($actions as $key => $action) { |
|
297 | + $key = sanitize_html_class($key); |
|
298 | + $action = wp_kses_post($action); |
|
299 | 299 | $sanitized[] = "<span class='$key'>$action</span>"; |
300 | 300 | } |
301 | 301 | |
302 | 302 | $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
303 | - $row_actions .= implode( ' | ', $sanitized ); |
|
303 | + $row_actions .= implode(' | ', $sanitized); |
|
304 | 304 | $row_actions .= '</small>'; |
305 | 305 | |
306 | 306 | return $content . $row_actions; |
@@ -316,9 +316,9 @@ discard block |
||
316 | 316 | |
317 | 317 | <tfoot> |
318 | 318 | <tr> |
319 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
320 | - <th class="getpaid-subscriptions-<?php echo sanitize_html_class( $key ); ?>"> |
|
321 | - <?php echo sanitize_text_field( $label ); ?> |
|
319 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
320 | + <th class="getpaid-subscriptions-<?php echo sanitize_html_class($key); ?>"> |
|
321 | + <?php echo sanitize_text_field($label); ?> |
|
322 | 322 | </th> |
323 | 323 | <?php endforeach; ?> |
324 | 324 | </tr> |
@@ -334,22 +334,22 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @param int $total |
336 | 336 | */ |
337 | - public function print_navigation( $total ) { |
|
337 | + public function print_navigation($total) { |
|
338 | 338 | |
339 | - if ( $total < 1 ) { |
|
339 | + if ($total < 1) { |
|
340 | 340 | |
341 | 341 | // Out-of-bounds, run the query again without LIMIT for total count. |
342 | - $args = array( |
|
342 | + $args = array( |
|
343 | 343 | 'customer_in' => get_current_user_id(), |
344 | 344 | 'fields' => 'id', |
345 | 345 | ); |
346 | 346 | |
347 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
347 | + $count_query = new GetPaid_Subscriptions_Query($args); |
|
348 | 348 | $total = $count_query->get_total(); |
349 | 349 | } |
350 | 350 | |
351 | 351 | // Abort if we do not have pages. |
352 | - if ( 2 > $total ) { |
|
352 | + if (2 > $total) { |
|
353 | 353 | return; |
354 | 354 | } |
355 | 355 | |
@@ -361,9 +361,9 @@ discard block |
||
361 | 361 | |
362 | 362 | echo getpaid_paginate_links( |
363 | 363 | array( |
364 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
364 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
365 | 365 | 'format' => '?paged=%#%', |
366 | - 'total' => (int) ceil( $total / 10 ), |
|
366 | + 'total' => (int) ceil($total / 10), |
|
367 | 367 | ) |
368 | 368 | ); |
369 | 369 | ?> |
@@ -379,30 +379,30 @@ discard block |
||
379 | 379 | * |
380 | 380 | * @return array |
381 | 381 | */ |
382 | - public function get_single_subscription_columns( $subscription ) { |
|
382 | + public function get_single_subscription_columns($subscription) { |
|
383 | 383 | |
384 | 384 | // Prepare subscription detail columns. |
385 | 385 | $fields = apply_filters( |
386 | 386 | 'getpaid_single_subscription_details_fields', |
387 | 387 | array( |
388 | - 'status' => __( 'Status', 'invoicing' ), |
|
389 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
390 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
391 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
392 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
393 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
394 | - 'item' => __( 'Item', 'invoicing' ), |
|
395 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
388 | + 'status' => __('Status', 'invoicing'), |
|
389 | + 'initial_amount' => __('Initial amount', 'invoicing'), |
|
390 | + 'recurring_amount' => __('Recurring amount', 'invoicing'), |
|
391 | + 'start_date' => __('Start date', 'invoicing'), |
|
392 | + 'expiry_date' => __('Next payment', 'invoicing'), |
|
393 | + 'payments' => __('Payments', 'invoicing'), |
|
394 | + 'item' => __('Item', 'invoicing'), |
|
395 | + 'invoice' => __('Invoice', 'invoicing'), |
|
396 | 396 | ), |
397 | 397 | $subscription |
398 | 398 | ); |
399 | 399 | |
400 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
401 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
400 | + if (!$subscription->is_active() || $subscription->is_last_renewal()) { |
|
401 | + $fields['expiry_date'] = __('End date', 'invoicing'); |
|
402 | 402 | } |
403 | 403 | |
404 | - if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
405 | - unset( $fields['initial_amount'] ); |
|
404 | + if ($subscription->get_initial_amount() == $subscription->get_recurring_amount()) { |
|
405 | + unset($fields['initial_amount']); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | return $fields; |
@@ -415,16 +415,16 @@ discard block |
||
415 | 415 | * |
416 | 416 | * @return string |
417 | 417 | */ |
418 | - public function display_single_subscription( $subscription ) { |
|
418 | + public function display_single_subscription($subscription) { |
|
419 | 419 | |
420 | 420 | // Fetch the subscription. |
421 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
421 | + $subscription = new WPInv_Subscription((int) $subscription); |
|
422 | 422 | |
423 | - if ( ! $subscription->get_id() ) { |
|
423 | + if (!$subscription->get_id()) { |
|
424 | 424 | |
425 | 425 | return aui()->alert( |
426 | 426 | array( |
427 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
427 | + 'content' => wp_kses_post(__('Subscription not found.', 'invoicing')), |
|
428 | 428 | 'type' => 'error', |
429 | 429 | ) |
430 | 430 | ); |
@@ -432,11 +432,11 @@ discard block |
||
432 | 432 | } |
433 | 433 | |
434 | 434 | // Ensure that the user owns this subscription key. |
435 | - if ( get_current_user_id() != $subscription->get_customer_id() ) { |
|
435 | + if (get_current_user_id() != $subscription->get_customer_id()) { |
|
436 | 436 | |
437 | 437 | return aui()->alert( |
438 | 438 | array( |
439 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
439 | + 'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')), |
|
440 | 440 | 'type' => 'error', |
441 | 441 | ) |
442 | 442 | ); |