@@ -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,545 +177,545 @@ 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 | + |
|
230 | + /** |
|
231 | + * Alias for self::get_parent_invoice_id(). |
|
232 | + * |
|
233 | + * @since 1.0.0 |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + public function get_original_payment_id( $context = 'view' ) { |
|
237 | + return $this->get_parent_invoice_id( $context ); |
|
238 | + } |
|
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 | + */ |
|
258 | + public function get_parent_payment( $context = 'view' ) { |
|
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' ) { |
|
404 | + $date = $this->get_date_created( $context ); |
|
405 | + |
|
406 | + if ( $date ) { |
|
407 | + $date = get_gmt_from_date( $date ); |
|
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' ) { |
|
459 | + $date = $this->get_next_renewal_date( $context ); |
|
460 | + |
|
461 | + if ( $date ) { |
|
462 | + $date = get_gmt_from_date( $date ); |
|
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 | + /* |
|
501 | + |-------------------------------------------------------------------------- |
|
502 | + | Setters |
|
503 | + |-------------------------------------------------------------------------- |
|
504 | + */ |
|
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 | + */ |
|
532 | + public function set_parent_payment_id( $value ) { |
|
533 | + $this->set_parent_invoice_id( $value ); |
|
534 | + } |
|
535 | + |
|
536 | + /** |
|
537 | + * Alias for self::set_parent_invoice_id(). |
|
538 | + * |
|
539 | + * @since 1.0.19 |
|
540 | + * @param int $value The parent invoice id. |
|
541 | + */ |
|
542 | + public function set_original_payment_id( $value ) { |
|
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 | + } |
|
229 | 606 | |
230 | - /** |
|
231 | - * Alias for self::get_parent_invoice_id(). |
|
607 | + /** |
|
608 | + * Get transaction id of this subscription's parent invoice. |
|
232 | 609 | * |
233 | - * @since 1.0.0 |
|
234 | - * @return int |
|
610 | + * @since 1.0.19 |
|
611 | + * @param string $value Bill times. |
|
235 | 612 | */ |
236 | - public function get_original_payment_id( $context = 'view' ) { |
|
237 | - return $this->get_parent_invoice_id( $context ); |
|
613 | + public function set_transaction_id( $value ) { |
|
614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
238 | 615 | } |
239 | 616 | |
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 | - public function get_parent_payment( $context = 'view' ) { |
|
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' ) { |
|
404 | - $date = $this->get_date_created( $context ); |
|
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 | + $date = strtotime( $value ); |
|
405 | 625 | |
406 | - if ( $date ) { |
|
407 | - $date = get_gmt_from_date( $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 | + return; |
|
408 | 629 | } |
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 | - $date = $this->get_next_renewal_date( $context ); |
|
460 | 630 | |
461 | - if ( $date ) { |
|
462 | - $date = get_gmt_from_date( $date ); |
|
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 | - /* |
|
501 | - |-------------------------------------------------------------------------- |
|
502 | - | Setters |
|
503 | - |-------------------------------------------------------------------------- |
|
504 | - */ |
|
631 | + $this->set_prop( 'created', '' ); |
|
505 | 632 | |
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 | - public function set_parent_payment_id( $value ) { |
|
533 | - $this->set_parent_invoice_id( $value ); |
|
534 | - } |
|
633 | + } |
|
535 | 634 | |
536 | - /** |
|
537 | - * Alias for self::set_parent_invoice_id(). |
|
635 | + /** |
|
636 | + * Alias for self::set_created(). |
|
538 | 637 | * |
539 | 638 | * @since 1.0.19 |
540 | - * @param int $value The parent invoice id. |
|
639 | + * @param string $value strtotime compliant date. |
|
541 | 640 | */ |
542 | - public function set_original_payment_id( $value ) { |
|
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 ) { |
|
641 | + public function set_date_created( $value ) { |
|
642 | + $this->set_created( $value ); |
|
643 | + } |
|
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 ) { |
|
624 | 652 | $date = strtotime( $value ); |
625 | 653 | |
626 | 654 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
655 | + $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
628 | 656 | return; |
629 | 657 | } |
630 | 658 | |
631 | - $this->set_prop( 'created', '' ); |
|
659 | + $this->set_prop( 'expiration', '' ); |
|
632 | 660 | |
633 | - } |
|
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 | + } |
|
634 | 672 | |
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 ); |
|
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 ); |
|
643 | 681 | } |
644 | 682 | |
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 ); |
|
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 ) { |
|
653 | 690 | |
654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
691 | + // Abort if this is not a valid status; |
|
692 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
656 | 693 | 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 | - /* |
|
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,22 +811,22 @@ discard block |
||
811 | 811 | */ |
812 | 812 | public function get_child_payments( $hide_pending = true ) { |
813 | 813 | |
814 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
814 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
815 | 815 | |
816 | - if ( ! $hide_pending ) { |
|
817 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
818 | - } |
|
816 | + if ( ! $hide_pending ) { |
|
817 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
818 | + } |
|
819 | 819 | |
820 | 820 | return get_posts( |
821 | - array( |
|
822 | - 'post_parent' => $this->get_parent_payment_id(), |
|
823 | - 'numberposts' => -1, |
|
824 | - 'post_status' => $statuses, |
|
825 | - 'orderby' => 'ID', |
|
826 | - 'order' => 'DESC', |
|
827 | - 'post_type' => 'wpi_invoice' |
|
828 | - ) |
|
829 | - ); |
|
821 | + array( |
|
822 | + 'post_parent' => $this->get_parent_payment_id(), |
|
823 | + 'numberposts' => -1, |
|
824 | + 'post_status' => $statuses, |
|
825 | + 'orderby' => 'ID', |
|
826 | + 'order' => 'DESC', |
|
827 | + 'post_type' => 'wpi_invoice' |
|
828 | + ) |
|
829 | + ); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
@@ -836,16 +836,16 @@ discard block |
||
836 | 836 | * @return int |
837 | 837 | */ |
838 | 838 | public function get_total_payments() { |
839 | - global $wpdb; |
|
839 | + global $wpdb; |
|
840 | 840 | |
841 | - $count = (int) $wpdb->get_var( |
|
842 | - $wpdb->prepare( |
|
843 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
844 | - $this->get_parent_invoice_id() |
|
845 | - ) |
|
846 | - ); |
|
841 | + $count = (int) $wpdb->get_var( |
|
842 | + $wpdb->prepare( |
|
843 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
844 | + $this->get_parent_invoice_id() |
|
845 | + ) |
|
846 | + ); |
|
847 | 847 | |
848 | - // Maybe include parent invoice. |
|
848 | + // Maybe include parent invoice. |
|
849 | 849 | if ( $this->get_parent_payment()->is_paid() ) { |
850 | 850 | $count++; |
851 | 851 | } |
@@ -874,57 +874,57 @@ discard block |
||
874 | 874 | * |
875 | 875 | * @since 2.4 |
876 | 876 | * @param array $args Array of values for the payment, including amount and transaction ID |
877 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
877 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
878 | 878 | * @return bool |
879 | 879 | */ |
880 | 880 | public function add_payment( $args = array(), $invoice = false ) { |
881 | 881 | |
882 | - // Process each payment once. |
|
882 | + // Process each payment once. |
|
883 | 883 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
884 | 884 | return false; |
885 | 885 | } |
886 | 886 | |
887 | - // Are we creating a new invoice? |
|
888 | - if ( empty( $invoice ) ) { |
|
889 | - $invoice = $this->create_payment(); |
|
887 | + // Are we creating a new invoice? |
|
888 | + if ( empty( $invoice ) ) { |
|
889 | + $invoice = $this->create_payment(); |
|
890 | 890 | |
891 | - if ( empty( $invoice ) ) { |
|
892 | - return false; |
|
893 | - } |
|
891 | + if ( empty( $invoice ) ) { |
|
892 | + return false; |
|
893 | + } |
|
894 | 894 | |
895 | - } |
|
895 | + } |
|
896 | 896 | |
897 | - $invoice->set_status( 'wpi-renewal' ); |
|
897 | + $invoice->set_status( 'wpi-renewal' ); |
|
898 | 898 | |
899 | - // Maybe set a transaction id. |
|
900 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
901 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
902 | - } |
|
899 | + // Maybe set a transaction id. |
|
900 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
901 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
902 | + } |
|
903 | 903 | |
904 | - // Set the completed date. |
|
905 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
904 | + // Set the completed date. |
|
905 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
906 | 906 | |
907 | - // And the gateway. |
|
908 | - if ( ! empty( $args['gateway'] ) ) { |
|
909 | - $invoice->set_gateway( $args['gateway'] ); |
|
910 | - } |
|
907 | + // And the gateway. |
|
908 | + if ( ! empty( $args['gateway'] ) ) { |
|
909 | + $invoice->set_gateway( $args['gateway'] ); |
|
910 | + } |
|
911 | 911 | |
912 | - $invoice->save(); |
|
912 | + $invoice->save(); |
|
913 | 913 | |
914 | - if ( ! $invoice->exists() ) { |
|
915 | - return false; |
|
916 | - } |
|
914 | + if ( ! $invoice->exists() ) { |
|
915 | + return false; |
|
916 | + } |
|
917 | 917 | |
918 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
919 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
918 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
919 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
920 | 920 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
921 | 921 | |
922 | 922 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
923 | 923 | |
924 | 924 | return $invoice->get_id(); |
925 | - } |
|
925 | + } |
|
926 | 926 | |
927 | - /** |
|
927 | + /** |
|
928 | 928 | * Creates a new invoice and returns it. |
929 | 929 | * |
930 | 930 | * @since 1.0.19 |
@@ -932,97 +932,97 @@ discard block |
||
932 | 932 | */ |
933 | 933 | public function create_payment() { |
934 | 934 | |
935 | - $parent_invoice = $this->get_parent_payment(); |
|
936 | - |
|
937 | - if ( ! $parent_invoice->exists() ) { |
|
938 | - return false; |
|
939 | - } |
|
940 | - |
|
941 | - // Duplicate the parent invoice. |
|
942 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
943 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
944 | - $invoice->recalculate_total(); |
|
945 | - $invoice->set_status( 'wpi-pending' ); |
|
946 | - $invoice->save(); |
|
947 | - |
|
948 | - return $invoice->exists() ? $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->is_last_renewal() ) { |
|
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 | - } |
|
935 | + $parent_invoice = $this->get_parent_payment(); |
|
936 | + |
|
937 | + if ( ! $parent_invoice->exists() ) { |
|
938 | + return false; |
|
939 | + } |
|
940 | + |
|
941 | + // Duplicate the parent invoice. |
|
942 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
943 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
944 | + $invoice->recalculate_total(); |
|
945 | + $invoice->set_status( 'wpi-pending' ); |
|
946 | + $invoice->save(); |
|
947 | + |
|
948 | + return $invoice->exists() ? $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->is_last_renewal() ) { |
|
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,93 +1056,93 @@ 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 = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1067 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1068 | - } |
|
1069 | - |
|
1070 | - /** |
|
1071 | - * Retrieves the URL to view a subscription |
|
1072 | - * |
|
1073 | - * @since 1.0.19 |
|
1074 | - * @return string |
|
1075 | - */ |
|
1076 | - public function get_view_url() { |
|
1077 | - $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1078 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1079 | - } |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * Determines if subscription can be manually renewed |
|
1083 | - * |
|
1084 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
1085 | - * that can be renewed manually |
|
1086 | - * |
|
1087 | - * @since 2.5 |
|
1088 | - * @return bool |
|
1089 | - */ |
|
1090 | - public function can_renew() { |
|
1091 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1092 | - } |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * Retrieves the URL to renew a subscription |
|
1096 | - * |
|
1097 | - * @since 2.5 |
|
1098 | - * @return string |
|
1099 | - */ |
|
1100 | - public function get_renew_url() { |
|
1101 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
1102 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1103 | - } |
|
1104 | - |
|
1105 | - /** |
|
1106 | - * Determines if subscription can have their payment method updated |
|
1107 | - * |
|
1108 | - * @since 1.0.0 |
|
1109 | - * @return bool |
|
1110 | - */ |
|
1111 | - public function can_update() { |
|
1112 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1113 | - } |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * Retrieves the URL to update subscription |
|
1117 | - * |
|
1118 | - * @since 1.0.0 |
|
1119 | - * @return string |
|
1120 | - */ |
|
1121 | - public function get_update_url() { |
|
1122 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1123 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1124 | - } |
|
1125 | - |
|
1126 | - /** |
|
1127 | - * Retrieves the subscription status label |
|
1128 | - * |
|
1129 | - * @since 1.0.0 |
|
1130 | - * @return string |
|
1131 | - */ |
|
1132 | - public function get_status_label() { |
|
1133 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1134 | - } |
|
1135 | - |
|
1136 | - /** |
|
1137 | - * Retrieves the subscription status class |
|
1138 | - * |
|
1139 | - * @since 1.0.19 |
|
1140 | - * @return string |
|
1141 | - */ |
|
1142 | - public function get_status_class() { |
|
1143 | - $statuses = getpaid_get_subscription_status_classes(); |
|
1144 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1145 | - } |
|
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 = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1067 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1068 | + } |
|
1069 | + |
|
1070 | + /** |
|
1071 | + * Retrieves the URL to view a subscription |
|
1072 | + * |
|
1073 | + * @since 1.0.19 |
|
1074 | + * @return string |
|
1075 | + */ |
|
1076 | + public function get_view_url() { |
|
1077 | + $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1078 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1079 | + } |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * Determines if subscription can be manually renewed |
|
1083 | + * |
|
1084 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
1085 | + * that can be renewed manually |
|
1086 | + * |
|
1087 | + * @since 2.5 |
|
1088 | + * @return bool |
|
1089 | + */ |
|
1090 | + public function can_renew() { |
|
1091 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1092 | + } |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * Retrieves the URL to renew a subscription |
|
1096 | + * |
|
1097 | + * @since 2.5 |
|
1098 | + * @return string |
|
1099 | + */ |
|
1100 | + public function get_renew_url() { |
|
1101 | + $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
1102 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1103 | + } |
|
1104 | + |
|
1105 | + /** |
|
1106 | + * Determines if subscription can have their payment method updated |
|
1107 | + * |
|
1108 | + * @since 1.0.0 |
|
1109 | + * @return bool |
|
1110 | + */ |
|
1111 | + public function can_update() { |
|
1112 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1113 | + } |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * Retrieves the URL to update subscription |
|
1117 | + * |
|
1118 | + * @since 1.0.0 |
|
1119 | + * @return string |
|
1120 | + */ |
|
1121 | + public function get_update_url() { |
|
1122 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1123 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1124 | + } |
|
1125 | + |
|
1126 | + /** |
|
1127 | + * Retrieves the subscription status label |
|
1128 | + * |
|
1129 | + * @since 1.0.0 |
|
1130 | + * @return string |
|
1131 | + */ |
|
1132 | + public function get_status_label() { |
|
1133 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1134 | + } |
|
1135 | + |
|
1136 | + /** |
|
1137 | + * Retrieves the subscription status class |
|
1138 | + * |
|
1139 | + * @since 1.0.19 |
|
1140 | + * @return string |
|
1141 | + */ |
|
1142 | + public function get_status_class() { |
|
1143 | + $statuses = getpaid_get_subscription_status_classes(); |
|
1144 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1145 | + } |
|
1146 | 1146 | |
1147 | 1147 | /** |
1148 | 1148 | * Retrieves the subscription status label |
@@ -1152,11 +1152,11 @@ discard block |
||
1152 | 1152 | */ |
1153 | 1153 | public function get_status_label_html() { |
1154 | 1154 | |
1155 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1156 | - $class = esc_attr( $this->get_status_class() ); |
|
1157 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
1155 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1156 | + $class = esc_attr( $this->get_status_class() ); |
|
1157 | + $status = sanitize_html_class( $this->get_status_label() ); |
|
1158 | 1158 | |
1159 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
1159 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
1160 | 1160 | } |
1161 | 1161 | |
1162 | 1162 | /** |
@@ -1167,75 +1167,75 @@ discard block |
||
1167 | 1167 | * @return bool |
1168 | 1168 | */ |
1169 | 1169 | public function payment_exists( $txn_id = '' ) { |
1170 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1170 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1171 | 1171 | return ! empty( $invoice_id ); |
1172 | - } |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * Handle the status transition. |
|
1176 | - */ |
|
1177 | - protected function status_transition() { |
|
1178 | - $status_transition = $this->status_transition; |
|
1179 | - |
|
1180 | - // Reset status transition variable. |
|
1181 | - $this->status_transition = false; |
|
1182 | - |
|
1183 | - if ( $status_transition ) { |
|
1184 | - try { |
|
1185 | - |
|
1186 | - // Fire a hook for the status change. |
|
1187 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1188 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1189 | - |
|
1190 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1191 | - |
|
1192 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
1193 | - $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'] ) ); |
|
1194 | - |
|
1195 | - // Note the transition occurred. |
|
1196 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1197 | - |
|
1198 | - // Fire another hook. |
|
1199 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1200 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1201 | - |
|
1202 | - } else { |
|
1203 | - /* translators: %s: new invoice status */ |
|
1204 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1205 | - |
|
1206 | - // Note the transition occurred. |
|
1207 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1208 | - |
|
1209 | - } |
|
1210 | - } catch ( Exception $e ) { |
|
1211 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1212 | - } |
|
1213 | - } |
|
1214 | - |
|
1215 | - } |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * Save data to the database. |
|
1219 | - * |
|
1220 | - * @since 1.0.19 |
|
1221 | - * @return int subscription ID |
|
1222 | - */ |
|
1223 | - public function save() { |
|
1224 | - parent::save(); |
|
1225 | - $this->status_transition(); |
|
1226 | - return $this->get_id(); |
|
1227 | - } |
|
1228 | - |
|
1229 | - /** |
|
1230 | - * Activates a subscription. |
|
1231 | - * |
|
1232 | - * @since 1.0.19 |
|
1233 | - * @return int subscription ID |
|
1234 | - */ |
|
1235 | - public function activate() { |
|
1236 | - $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
1237 | - $this->set_status( $status ); |
|
1238 | - return $this->save(); |
|
1239 | - } |
|
1172 | + } |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * Handle the status transition. |
|
1176 | + */ |
|
1177 | + protected function status_transition() { |
|
1178 | + $status_transition = $this->status_transition; |
|
1179 | + |
|
1180 | + // Reset status transition variable. |
|
1181 | + $this->status_transition = false; |
|
1182 | + |
|
1183 | + if ( $status_transition ) { |
|
1184 | + try { |
|
1185 | + |
|
1186 | + // Fire a hook for the status change. |
|
1187 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1188 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1189 | + |
|
1190 | + if ( ! empty( $status_transition['from'] ) ) { |
|
1191 | + |
|
1192 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
1193 | + $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'] ) ); |
|
1194 | + |
|
1195 | + // Note the transition occurred. |
|
1196 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1197 | + |
|
1198 | + // Fire another hook. |
|
1199 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1200 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1201 | + |
|
1202 | + } else { |
|
1203 | + /* translators: %s: new invoice status */ |
|
1204 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1205 | + |
|
1206 | + // Note the transition occurred. |
|
1207 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1208 | + |
|
1209 | + } |
|
1210 | + } catch ( Exception $e ) { |
|
1211 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1212 | + } |
|
1213 | + } |
|
1214 | + |
|
1215 | + } |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * Save data to the database. |
|
1219 | + * |
|
1220 | + * @since 1.0.19 |
|
1221 | + * @return int subscription ID |
|
1222 | + */ |
|
1223 | + public function save() { |
|
1224 | + parent::save(); |
|
1225 | + $this->status_transition(); |
|
1226 | + return $this->get_id(); |
|
1227 | + } |
|
1228 | + |
|
1229 | + /** |
|
1230 | + * Activates a subscription. |
|
1231 | + * |
|
1232 | + * @since 1.0.19 |
|
1233 | + * @return int subscription ID |
|
1234 | + */ |
|
1235 | + public function activate() { |
|
1236 | + $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
1237 | + $this->set_status( $status ); |
|
1238 | + return $this->save(); |
|
1239 | + } |
|
1240 | 1240 | |
1241 | 1241 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,199 +21,199 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'AyeCode_UI_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class AyeCode_UI_Settings |
|
28 | - * @ver 1.0.0 |
|
29 | - * @todo decide how to implement textdomain |
|
30 | - */ |
|
31 | - class AyeCode_UI_Settings { |
|
32 | - |
|
33 | - /** |
|
34 | - * Class version version. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - public $version = '1.0.1'; |
|
39 | - |
|
40 | - /** |
|
41 | - * Class textdomain. |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public $textdomain = 'aui'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Latest version of Bootstrap at time of publish published. |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $latest = "4.3.1"; |
|
53 | - |
|
54 | - /** |
|
55 | - * Current version of select2 being used. |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $select2_version = "4.0.11"; |
|
60 | - |
|
61 | - /** |
|
62 | - * The title. |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - public $name = 'AyeCode UI'; |
|
67 | - |
|
68 | - /** |
|
69 | - * The relative url to the assets. |
|
70 | - * |
|
71 | - * @var string |
|
72 | - */ |
|
73 | - public $url = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * Holds the settings values. |
|
77 | - * |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - private $settings; |
|
81 | - |
|
82 | - /** |
|
83 | - * AyeCode_UI_Settings instance. |
|
84 | - * |
|
85 | - * @access private |
|
86 | - * @since 1.0.0 |
|
87 | - * @var AyeCode_UI_Settings There can be only one! |
|
88 | - */ |
|
89 | - private static $instance = null; |
|
90 | - |
|
91 | - /** |
|
92 | - * Main AyeCode_UI_Settings Instance. |
|
93 | - * |
|
94 | - * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
95 | - * |
|
96 | - * @since 1.0.0 |
|
97 | - * @static |
|
98 | - * @return AyeCode_UI_Settings - Main instance. |
|
99 | - */ |
|
100 | - public static function instance() { |
|
101 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
102 | - |
|
103 | - self::$instance = new AyeCode_UI_Settings; |
|
104 | - |
|
105 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
106 | - |
|
107 | - if ( is_admin() ) { |
|
108 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
109 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
110 | - |
|
111 | - // Maybe show example page |
|
112 | - add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
113 | - } |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class AyeCode_UI_Settings |
|
28 | + * @ver 1.0.0 |
|
29 | + * @todo decide how to implement textdomain |
|
30 | + */ |
|
31 | + class AyeCode_UI_Settings { |
|
32 | + |
|
33 | + /** |
|
34 | + * Class version version. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + public $version = '1.0.1'; |
|
39 | + |
|
40 | + /** |
|
41 | + * Class textdomain. |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public $textdomain = 'aui'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Latest version of Bootstrap at time of publish published. |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $latest = "4.3.1"; |
|
53 | + |
|
54 | + /** |
|
55 | + * Current version of select2 being used. |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $select2_version = "4.0.11"; |
|
60 | + |
|
61 | + /** |
|
62 | + * The title. |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + public $name = 'AyeCode UI'; |
|
67 | + |
|
68 | + /** |
|
69 | + * The relative url to the assets. |
|
70 | + * |
|
71 | + * @var string |
|
72 | + */ |
|
73 | + public $url = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * Holds the settings values. |
|
77 | + * |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + private $settings; |
|
81 | + |
|
82 | + /** |
|
83 | + * AyeCode_UI_Settings instance. |
|
84 | + * |
|
85 | + * @access private |
|
86 | + * @since 1.0.0 |
|
87 | + * @var AyeCode_UI_Settings There can be only one! |
|
88 | + */ |
|
89 | + private static $instance = null; |
|
90 | + |
|
91 | + /** |
|
92 | + * Main AyeCode_UI_Settings Instance. |
|
93 | + * |
|
94 | + * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
95 | + * |
|
96 | + * @since 1.0.0 |
|
97 | + * @static |
|
98 | + * @return AyeCode_UI_Settings - Main instance. |
|
99 | + */ |
|
100 | + public static function instance() { |
|
101 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
102 | + |
|
103 | + self::$instance = new AyeCode_UI_Settings; |
|
104 | + |
|
105 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
106 | + |
|
107 | + if ( is_admin() ) { |
|
108 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
109 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
110 | + |
|
111 | + // Maybe show example page |
|
112 | + add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
113 | + } |
|
114 | 114 | |
115 | - add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
116 | - |
|
117 | - do_action( 'ayecode_ui_settings_loaded' ); |
|
118 | - } |
|
119 | - |
|
120 | - return self::$instance; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Setup some constants. |
|
125 | - */ |
|
126 | - public function constants(){ |
|
127 | - define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
128 | - define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
129 | - if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
130 | - if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Initiate the settings and add the required action hooks. |
|
135 | - */ |
|
136 | - public function init() { |
|
137 | - $this->constants(); |
|
138 | - $this->settings = $this->get_settings(); |
|
139 | - $this->url = $this->get_url(); |
|
140 | - |
|
141 | - /** |
|
142 | - * Maybe load CSS |
|
143 | - * |
|
144 | - * We load super early in case there is a theme version that might change the colors |
|
145 | - */ |
|
146 | - if ( $this->settings['css'] ) { |
|
147 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
148 | - } |
|
149 | - if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
150 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
151 | - } |
|
152 | - |
|
153 | - // maybe load JS |
|
154 | - if ( $this->settings['js'] ) { |
|
155 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
156 | - } |
|
157 | - if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
158 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
159 | - } |
|
160 | - |
|
161 | - // Maybe set the HTML font size |
|
162 | - if ( $this->settings['html_font_size'] ) { |
|
163 | - add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Check if we should load the admin scripts or not. |
|
171 | - * |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - public function load_admin_scripts(){ |
|
175 | - $result = true; |
|
176 | - |
|
177 | - if(!empty($this->settings['disable_admin'])){ |
|
178 | - $url_parts = explode("\n",$this->settings['disable_admin']); |
|
179 | - foreach($url_parts as $part){ |
|
180 | - if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
181 | - return false; // return early, no point checking further |
|
182 | - } |
|
183 | - } |
|
184 | - } |
|
115 | + add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
116 | + |
|
117 | + do_action( 'ayecode_ui_settings_loaded' ); |
|
118 | + } |
|
119 | + |
|
120 | + return self::$instance; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Setup some constants. |
|
125 | + */ |
|
126 | + public function constants(){ |
|
127 | + define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
128 | + define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
129 | + if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
130 | + if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Initiate the settings and add the required action hooks. |
|
135 | + */ |
|
136 | + public function init() { |
|
137 | + $this->constants(); |
|
138 | + $this->settings = $this->get_settings(); |
|
139 | + $this->url = $this->get_url(); |
|
140 | + |
|
141 | + /** |
|
142 | + * Maybe load CSS |
|
143 | + * |
|
144 | + * We load super early in case there is a theme version that might change the colors |
|
145 | + */ |
|
146 | + if ( $this->settings['css'] ) { |
|
147 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
148 | + } |
|
149 | + if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
150 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
151 | + } |
|
152 | + |
|
153 | + // maybe load JS |
|
154 | + if ( $this->settings['js'] ) { |
|
155 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
156 | + } |
|
157 | + if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
158 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
159 | + } |
|
160 | + |
|
161 | + // Maybe set the HTML font size |
|
162 | + if ( $this->settings['html_font_size'] ) { |
|
163 | + add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Check if we should load the admin scripts or not. |
|
171 | + * |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + public function load_admin_scripts(){ |
|
175 | + $result = true; |
|
176 | + |
|
177 | + if(!empty($this->settings['disable_admin'])){ |
|
178 | + $url_parts = explode("\n",$this->settings['disable_admin']); |
|
179 | + foreach($url_parts as $part){ |
|
180 | + if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
181 | + return false; // return early, no point checking further |
|
182 | + } |
|
183 | + } |
|
184 | + } |
|
185 | 185 | |
186 | - return $result; |
|
187 | - } |
|
186 | + return $result; |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * Add a html font size to the footer. |
|
191 | - */ |
|
192 | - public function html_font_size(){ |
|
193 | - $this->settings = $this->get_settings(); |
|
194 | - echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
195 | - } |
|
189 | + /** |
|
190 | + * Add a html font size to the footer. |
|
191 | + */ |
|
192 | + public function html_font_size(){ |
|
193 | + $this->settings = $this->get_settings(); |
|
194 | + echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Adds the Font Awesome styles. |
|
199 | - */ |
|
200 | - public function enqueue_style() { |
|
197 | + /** |
|
198 | + * Adds the Font Awesome styles. |
|
199 | + */ |
|
200 | + public function enqueue_style() { |
|
201 | 201 | |
202 | - $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
202 | + $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
203 | 203 | |
204 | - if($this->settings[$css_setting]){ |
|
205 | - $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
206 | - $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css'; |
|
207 | - wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
208 | - wp_enqueue_style( 'ayecode-ui' ); |
|
204 | + if($this->settings[$css_setting]){ |
|
205 | + $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
206 | + $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css'; |
|
207 | + wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
208 | + wp_enqueue_style( 'ayecode-ui' ); |
|
209 | 209 | |
210 | - // flatpickr |
|
211 | - wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
210 | + // flatpickr |
|
211 | + wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
212 | 212 | |
213 | 213 | |
214 | - // fix some wp-admin issues |
|
215 | - if(is_admin()){ |
|
216 | - $custom_css = " |
|
214 | + // fix some wp-admin issues |
|
215 | + if(is_admin()){ |
|
216 | + $custom_css = " |
|
217 | 217 | body{ |
218 | 218 | background-color: #f1f1f1; |
219 | 219 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
@@ -249,29 +249,29 @@ discard block |
||
249 | 249 | } |
250 | 250 | "; |
251 | 251 | |
252 | - // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
253 | - $custom_css .= " |
|
252 | + // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
253 | + $custom_css .= " |
|
254 | 254 | .edit-post-sidebar input[type=color].components-text-control__input{ |
255 | 255 | padding: 0; |
256 | 256 | } |
257 | 257 | "; |
258 | - wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
259 | - } |
|
258 | + wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
259 | + } |
|
260 | 260 | |
261 | - // custom changes |
|
262 | - wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
261 | + // custom changes |
|
262 | + wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
263 | 263 | |
264 | - } |
|
265 | - } |
|
264 | + } |
|
265 | + } |
|
266 | 266 | |
267 | - /** |
|
268 | - * Get inline script used if bootstrap enqueued |
|
269 | - * |
|
270 | - * If this remains small then its best to use this than to add another JS file. |
|
271 | - */ |
|
272 | - public function inline_script(){ |
|
273 | - ob_start(); |
|
274 | - ?> |
|
267 | + /** |
|
268 | + * Get inline script used if bootstrap enqueued |
|
269 | + * |
|
270 | + * If this remains small then its best to use this than to add another JS file. |
|
271 | + */ |
|
272 | + public function inline_script(){ |
|
273 | + ob_start(); |
|
274 | + ?> |
|
275 | 275 | <script> |
276 | 276 | |
277 | 277 | /** |
@@ -758,25 +758,25 @@ discard block |
||
758 | 758 | |
759 | 759 | </script> |
760 | 760 | <?php |
761 | - $output = ob_get_clean(); |
|
761 | + $output = ob_get_clean(); |
|
762 | 762 | |
763 | - /* |
|
763 | + /* |
|
764 | 764 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
765 | 765 | */ |
766 | - return str_replace( array( |
|
767 | - '<script>', |
|
768 | - '</script>' |
|
769 | - ), '', $output ); |
|
770 | - } |
|
771 | - |
|
772 | - /** |
|
773 | - * Get inline script used if bootstrap file browser enqueued. |
|
774 | - * |
|
775 | - * If this remains small then its best to use this than to add another JS file. |
|
776 | - */ |
|
777 | - public function inline_script_file_browser(){ |
|
778 | - ob_start(); |
|
779 | - ?> |
|
766 | + return str_replace( array( |
|
767 | + '<script>', |
|
768 | + '</script>' |
|
769 | + ), '', $output ); |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * Get inline script used if bootstrap file browser enqueued. |
|
774 | + * |
|
775 | + * If this remains small then its best to use this than to add another JS file. |
|
776 | + */ |
|
777 | + public function inline_script_file_browser(){ |
|
778 | + ob_start(); |
|
779 | + ?> |
|
780 | 780 | <script> |
781 | 781 | // run on doc ready |
782 | 782 | jQuery(document).ready(function () { |
@@ -784,184 +784,184 @@ discard block |
||
784 | 784 | }); |
785 | 785 | </script> |
786 | 786 | <?php |
787 | - $output = ob_get_clean(); |
|
787 | + $output = ob_get_clean(); |
|
788 | 788 | |
789 | - /* |
|
789 | + /* |
|
790 | 790 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
791 | 791 | */ |
792 | - return str_replace( array( |
|
793 | - '<script>', |
|
794 | - '</script>' |
|
795 | - ), '', $output ); |
|
796 | - } |
|
797 | - |
|
798 | - /** |
|
799 | - * Adds the Font Awesome JS. |
|
800 | - */ |
|
801 | - public function enqueue_scripts() { |
|
802 | - |
|
803 | - $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
804 | - |
|
805 | - // select2 |
|
806 | - wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version ); |
|
807 | - |
|
808 | - // flatpickr |
|
809 | - wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
810 | - |
|
811 | - // Bootstrap file browser |
|
812 | - wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version ); |
|
813 | - wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
814 | - |
|
815 | - $load_inline = false; |
|
816 | - |
|
817 | - if($this->settings[$js_setting]=='core-popper'){ |
|
818 | - // Bootstrap bundle |
|
819 | - $url = $this->url.'assets/js/bootstrap.bundle.min.js'; |
|
820 | - wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest ); |
|
821 | - // if in admin then add to footer for compatibility. |
|
822 | - is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle'); |
|
823 | - $script = $this->inline_script(); |
|
824 | - wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
825 | - }elseif($this->settings[$js_setting]=='popper'){ |
|
826 | - $url = $this->url.'assets/js/popper.min.js'; |
|
827 | - wp_register_script( 'bootstrap-js-popper', $url, array('select2','jquery'), $this->latest ); |
|
828 | - wp_enqueue_script( 'bootstrap-js-popper' ); |
|
829 | - $load_inline = true; |
|
830 | - }else{ |
|
831 | - $load_inline = true; |
|
832 | - } |
|
833 | - |
|
834 | - // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
835 | - if($load_inline){ |
|
836 | - wp_register_script( 'bootstrap-dummy', '',array('select2','jquery') ); |
|
837 | - wp_enqueue_script( 'bootstrap-dummy' ); |
|
838 | - $script = $this->inline_script(); |
|
839 | - wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
840 | - } |
|
841 | - |
|
842 | - } |
|
843 | - |
|
844 | - /** |
|
845 | - * Enqueue flatpickr if called. |
|
846 | - */ |
|
847 | - public function enqueue_flatpickr(){ |
|
848 | - wp_enqueue_style( 'flatpickr' ); |
|
849 | - wp_enqueue_script( 'flatpickr' ); |
|
850 | - } |
|
851 | - |
|
852 | - /** |
|
853 | - * Get the url path to the current folder. |
|
854 | - * |
|
855 | - * @return string |
|
856 | - */ |
|
857 | - public function get_url() { |
|
858 | - |
|
859 | - $url = ''; |
|
860 | - // check if we are inside a plugin |
|
861 | - $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
862 | - |
|
863 | - // add check in-case user has changed wp-content dir name. |
|
864 | - $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
865 | - $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
866 | - $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
867 | - |
|
868 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
869 | - $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
870 | - } |
|
871 | - |
|
872 | - return $url; |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * Register the database settings with WordPress. |
|
877 | - */ |
|
878 | - public function register_settings() { |
|
879 | - register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
880 | - } |
|
881 | - |
|
882 | - /** |
|
883 | - * Add the WordPress settings menu item. |
|
884 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
885 | - */ |
|
886 | - public function menu_item() { |
|
887 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
888 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
889 | - $this, |
|
890 | - 'settings_page' |
|
891 | - ) ); |
|
892 | - } |
|
893 | - |
|
894 | - /** |
|
895 | - * Get a list of themes and their default JS settings. |
|
896 | - * |
|
897 | - * @return array |
|
898 | - */ |
|
899 | - public function theme_js_settings(){ |
|
900 | - return array( |
|
901 | - 'ayetheme' => 'popper', |
|
902 | - 'listimia' => 'required', |
|
903 | - 'listimia_backend' => 'core-popper', |
|
904 | - 'avada' => 'required', |
|
905 | - ); |
|
906 | - } |
|
907 | - |
|
908 | - /** |
|
909 | - * Get the current Font Awesome output settings. |
|
910 | - * |
|
911 | - * @return array The array of settings. |
|
912 | - */ |
|
913 | - public function get_settings() { |
|
914 | - |
|
915 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
916 | - $js_default = 'core-popper'; |
|
917 | - $js_default_backend = $js_default; |
|
918 | - |
|
919 | - // maybe set defaults (if no settings set) |
|
920 | - if(empty($db_settings)){ |
|
921 | - $active_theme = strtolower( get_template() ); // active parent theme. |
|
922 | - $theme_js_settings = self::theme_js_settings(); |
|
923 | - if(isset($theme_js_settings[$active_theme])){ |
|
924 | - $js_default = $theme_js_settings[$active_theme]; |
|
925 | - $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
926 | - } |
|
927 | - } |
|
928 | - |
|
929 | - $defaults = array( |
|
930 | - 'css' => 'compatibility', // core, compatibility |
|
931 | - 'js' => $js_default, // js to load, core-popper, popper |
|
932 | - 'html_font_size' => '16', // js to load, core-popper, popper |
|
933 | - 'css_backend' => 'compatibility', // core, compatibility |
|
934 | - 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
935 | - 'disable_admin' => '', // URL snippets to disable loading on admin |
|
936 | - ); |
|
937 | - |
|
938 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
939 | - |
|
940 | - /** |
|
941 | - * Filter the Bootstrap settings. |
|
942 | - * |
|
943 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
944 | - */ |
|
945 | - return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
946 | - } |
|
947 | - |
|
948 | - |
|
949 | - /** |
|
950 | - * The settings page html output. |
|
951 | - */ |
|
952 | - public function settings_page() { |
|
953 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
954 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
955 | - } |
|
956 | - ?> |
|
792 | + return str_replace( array( |
|
793 | + '<script>', |
|
794 | + '</script>' |
|
795 | + ), '', $output ); |
|
796 | + } |
|
797 | + |
|
798 | + /** |
|
799 | + * Adds the Font Awesome JS. |
|
800 | + */ |
|
801 | + public function enqueue_scripts() { |
|
802 | + |
|
803 | + $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
804 | + |
|
805 | + // select2 |
|
806 | + wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version ); |
|
807 | + |
|
808 | + // flatpickr |
|
809 | + wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
810 | + |
|
811 | + // Bootstrap file browser |
|
812 | + wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version ); |
|
813 | + wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
814 | + |
|
815 | + $load_inline = false; |
|
816 | + |
|
817 | + if($this->settings[$js_setting]=='core-popper'){ |
|
818 | + // Bootstrap bundle |
|
819 | + $url = $this->url.'assets/js/bootstrap.bundle.min.js'; |
|
820 | + wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest ); |
|
821 | + // if in admin then add to footer for compatibility. |
|
822 | + is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle'); |
|
823 | + $script = $this->inline_script(); |
|
824 | + wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
825 | + }elseif($this->settings[$js_setting]=='popper'){ |
|
826 | + $url = $this->url.'assets/js/popper.min.js'; |
|
827 | + wp_register_script( 'bootstrap-js-popper', $url, array('select2','jquery'), $this->latest ); |
|
828 | + wp_enqueue_script( 'bootstrap-js-popper' ); |
|
829 | + $load_inline = true; |
|
830 | + }else{ |
|
831 | + $load_inline = true; |
|
832 | + } |
|
833 | + |
|
834 | + // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
835 | + if($load_inline){ |
|
836 | + wp_register_script( 'bootstrap-dummy', '',array('select2','jquery') ); |
|
837 | + wp_enqueue_script( 'bootstrap-dummy' ); |
|
838 | + $script = $this->inline_script(); |
|
839 | + wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
840 | + } |
|
841 | + |
|
842 | + } |
|
843 | + |
|
844 | + /** |
|
845 | + * Enqueue flatpickr if called. |
|
846 | + */ |
|
847 | + public function enqueue_flatpickr(){ |
|
848 | + wp_enqueue_style( 'flatpickr' ); |
|
849 | + wp_enqueue_script( 'flatpickr' ); |
|
850 | + } |
|
851 | + |
|
852 | + /** |
|
853 | + * Get the url path to the current folder. |
|
854 | + * |
|
855 | + * @return string |
|
856 | + */ |
|
857 | + public function get_url() { |
|
858 | + |
|
859 | + $url = ''; |
|
860 | + // check if we are inside a plugin |
|
861 | + $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
862 | + |
|
863 | + // add check in-case user has changed wp-content dir name. |
|
864 | + $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
865 | + $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
866 | + $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
867 | + |
|
868 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
869 | + $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
870 | + } |
|
871 | + |
|
872 | + return $url; |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * Register the database settings with WordPress. |
|
877 | + */ |
|
878 | + public function register_settings() { |
|
879 | + register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
880 | + } |
|
881 | + |
|
882 | + /** |
|
883 | + * Add the WordPress settings menu item. |
|
884 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
885 | + */ |
|
886 | + public function menu_item() { |
|
887 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
888 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
889 | + $this, |
|
890 | + 'settings_page' |
|
891 | + ) ); |
|
892 | + } |
|
893 | + |
|
894 | + /** |
|
895 | + * Get a list of themes and their default JS settings. |
|
896 | + * |
|
897 | + * @return array |
|
898 | + */ |
|
899 | + public function theme_js_settings(){ |
|
900 | + return array( |
|
901 | + 'ayetheme' => 'popper', |
|
902 | + 'listimia' => 'required', |
|
903 | + 'listimia_backend' => 'core-popper', |
|
904 | + 'avada' => 'required', |
|
905 | + ); |
|
906 | + } |
|
907 | + |
|
908 | + /** |
|
909 | + * Get the current Font Awesome output settings. |
|
910 | + * |
|
911 | + * @return array The array of settings. |
|
912 | + */ |
|
913 | + public function get_settings() { |
|
914 | + |
|
915 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
916 | + $js_default = 'core-popper'; |
|
917 | + $js_default_backend = $js_default; |
|
918 | + |
|
919 | + // maybe set defaults (if no settings set) |
|
920 | + if(empty($db_settings)){ |
|
921 | + $active_theme = strtolower( get_template() ); // active parent theme. |
|
922 | + $theme_js_settings = self::theme_js_settings(); |
|
923 | + if(isset($theme_js_settings[$active_theme])){ |
|
924 | + $js_default = $theme_js_settings[$active_theme]; |
|
925 | + $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
926 | + } |
|
927 | + } |
|
928 | + |
|
929 | + $defaults = array( |
|
930 | + 'css' => 'compatibility', // core, compatibility |
|
931 | + 'js' => $js_default, // js to load, core-popper, popper |
|
932 | + 'html_font_size' => '16', // js to load, core-popper, popper |
|
933 | + 'css_backend' => 'compatibility', // core, compatibility |
|
934 | + 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
935 | + 'disable_admin' => '', // URL snippets to disable loading on admin |
|
936 | + ); |
|
937 | + |
|
938 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
939 | + |
|
940 | + /** |
|
941 | + * Filter the Bootstrap settings. |
|
942 | + * |
|
943 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
944 | + */ |
|
945 | + return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
946 | + } |
|
947 | + |
|
948 | + |
|
949 | + /** |
|
950 | + * The settings page html output. |
|
951 | + */ |
|
952 | + public function settings_page() { |
|
953 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
954 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
955 | + } |
|
956 | + ?> |
|
957 | 957 | <div class="wrap"> |
958 | 958 | <h1><?php echo $this->name; ?></h1> |
959 | 959 | <p><?php _e("Here you can adjust settings if you are having compatibility issues.","aui");?></p> |
960 | 960 | <form method="post" action="options.php"> |
961 | 961 | <?php |
962 | - settings_fields( 'ayecode-ui-settings' ); |
|
963 | - do_settings_sections( 'ayecode-ui-settings' ); |
|
964 | - ?> |
|
962 | + settings_fields( 'ayecode-ui-settings' ); |
|
963 | + do_settings_sections( 'ayecode-ui-settings' ); |
|
964 | + ?> |
|
965 | 965 | |
966 | 966 | <h2><?php _e( 'Frontend', 'aui' ); ?></h2> |
967 | 967 | <table class="form-table wpbs-table-settings"> |
@@ -1041,489 +1041,489 @@ discard block |
||
1041 | 1041 | </table> |
1042 | 1042 | |
1043 | 1043 | <?php |
1044 | - submit_button(); |
|
1045 | - ?> |
|
1044 | + submit_button(); |
|
1045 | + ?> |
|
1046 | 1046 | </form> |
1047 | 1047 | |
1048 | 1048 | <div id="wpbs-version"><?php echo $this->version; ?></div> |
1049 | 1049 | </div> |
1050 | 1050 | |
1051 | 1051 | <?php |
1052 | - } |
|
1053 | - |
|
1054 | - public function customizer_settings($wp_customize){ |
|
1055 | - $wp_customize->add_section('aui_settings', array( |
|
1056 | - 'title' => __('AyeCode UI','aui'), |
|
1057 | - 'priority' => 120, |
|
1058 | - )); |
|
1059 | - |
|
1060 | - // ============================= |
|
1061 | - // = Color Picker = |
|
1062 | - // ============================= |
|
1063 | - $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1064 | - 'default' => AUI_PRIMARY_COLOR, |
|
1065 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1066 | - 'capability' => 'edit_theme_options', |
|
1067 | - 'type' => 'option', |
|
1068 | - 'transport' => 'refresh', |
|
1069 | - )); |
|
1070 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1071 | - 'label' => __('Primary Color','aui'), |
|
1072 | - 'section' => 'aui_settings', |
|
1073 | - 'settings' => 'aui_options[color_primary]', |
|
1074 | - ))); |
|
1075 | - |
|
1076 | - $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1077 | - 'default' => '#6c757d', |
|
1078 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1079 | - 'capability' => 'edit_theme_options', |
|
1080 | - 'type' => 'option', |
|
1081 | - 'transport' => 'refresh', |
|
1082 | - )); |
|
1083 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1084 | - 'label' => __('Secondary Color','aui'), |
|
1085 | - 'section' => 'aui_settings', |
|
1086 | - 'settings' => 'aui_options[color_secondary]', |
|
1087 | - ))); |
|
1088 | - } |
|
1089 | - |
|
1090 | - |
|
1091 | - public static function custom_css($compatibility = true) { |
|
1092 | - $settings = get_option('aui_options'); |
|
1093 | - |
|
1094 | - ob_start(); |
|
1095 | - |
|
1096 | - $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1097 | - $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1098 | - //AUI_PRIMARY_COLOR_ORIGINAL |
|
1099 | - ?> |
|
1052 | + } |
|
1053 | + |
|
1054 | + public function customizer_settings($wp_customize){ |
|
1055 | + $wp_customize->add_section('aui_settings', array( |
|
1056 | + 'title' => __('AyeCode UI','aui'), |
|
1057 | + 'priority' => 120, |
|
1058 | + )); |
|
1059 | + |
|
1060 | + // ============================= |
|
1061 | + // = Color Picker = |
|
1062 | + // ============================= |
|
1063 | + $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1064 | + 'default' => AUI_PRIMARY_COLOR, |
|
1065 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1066 | + 'capability' => 'edit_theme_options', |
|
1067 | + 'type' => 'option', |
|
1068 | + 'transport' => 'refresh', |
|
1069 | + )); |
|
1070 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1071 | + 'label' => __('Primary Color','aui'), |
|
1072 | + 'section' => 'aui_settings', |
|
1073 | + 'settings' => 'aui_options[color_primary]', |
|
1074 | + ))); |
|
1075 | + |
|
1076 | + $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1077 | + 'default' => '#6c757d', |
|
1078 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1079 | + 'capability' => 'edit_theme_options', |
|
1080 | + 'type' => 'option', |
|
1081 | + 'transport' => 'refresh', |
|
1082 | + )); |
|
1083 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1084 | + 'label' => __('Secondary Color','aui'), |
|
1085 | + 'section' => 'aui_settings', |
|
1086 | + 'settings' => 'aui_options[color_secondary]', |
|
1087 | + ))); |
|
1088 | + } |
|
1089 | + |
|
1090 | + |
|
1091 | + public static function custom_css($compatibility = true) { |
|
1092 | + $settings = get_option('aui_options'); |
|
1093 | + |
|
1094 | + ob_start(); |
|
1095 | + |
|
1096 | + $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1097 | + $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1098 | + //AUI_PRIMARY_COLOR_ORIGINAL |
|
1099 | + ?> |
|
1100 | 1100 | <style> |
1101 | 1101 | <?php |
1102 | - if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1103 | - echo self::css_primary($primary_color,$compatibility); |
|
1104 | - } |
|
1102 | + if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1103 | + echo self::css_primary($primary_color,$compatibility); |
|
1104 | + } |
|
1105 | 1105 | |
1106 | - if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1107 | - echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1108 | - } |
|
1106 | + if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1107 | + echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1108 | + } |
|
1109 | 1109 | ?> |
1110 | 1110 | </style> |
1111 | 1111 | <?php |
1112 | 1112 | |
1113 | 1113 | |
1114 | - /* |
|
1114 | + /* |
|
1115 | 1115 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1116 | 1116 | */ |
1117 | - return str_replace( array( |
|
1118 | - '<style>', |
|
1119 | - '</style>' |
|
1120 | - ), '', ob_get_clean()); |
|
1121 | - } |
|
1122 | - |
|
1123 | - public static function css_primary($color_code,$compatibility){; |
|
1124 | - $color_code = sanitize_hex_color($color_code); |
|
1125 | - if(!$color_code){return '';} |
|
1126 | - /** |
|
1127 | - * c = color, b = background color, o = border-color, f = fill |
|
1128 | - */ |
|
1129 | - $selectors = array( |
|
1130 | - 'a' => array('c'), |
|
1131 | - '.btn-primary' => array('b','o'), |
|
1132 | - '.btn-primary.disabled' => array('b','o'), |
|
1133 | - '.btn-primary:disabled' => array('b','o'), |
|
1134 | - '.btn-outline-primary' => array('c','o'), |
|
1135 | - '.btn-outline-primary:hover' => array('b','o'), |
|
1136 | - '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1137 | - '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1138 | - '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1139 | - '.btn-link' => array('c'), |
|
1140 | - '.dropdown-item.active' => array('b'), |
|
1141 | - '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1142 | - '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1117 | + return str_replace( array( |
|
1118 | + '<style>', |
|
1119 | + '</style>' |
|
1120 | + ), '', ob_get_clean()); |
|
1121 | + } |
|
1122 | + |
|
1123 | + public static function css_primary($color_code,$compatibility){; |
|
1124 | + $color_code = sanitize_hex_color($color_code); |
|
1125 | + if(!$color_code){return '';} |
|
1126 | + /** |
|
1127 | + * c = color, b = background color, o = border-color, f = fill |
|
1128 | + */ |
|
1129 | + $selectors = array( |
|
1130 | + 'a' => array('c'), |
|
1131 | + '.btn-primary' => array('b','o'), |
|
1132 | + '.btn-primary.disabled' => array('b','o'), |
|
1133 | + '.btn-primary:disabled' => array('b','o'), |
|
1134 | + '.btn-outline-primary' => array('c','o'), |
|
1135 | + '.btn-outline-primary:hover' => array('b','o'), |
|
1136 | + '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1137 | + '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1138 | + '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1139 | + '.btn-link' => array('c'), |
|
1140 | + '.dropdown-item.active' => array('b'), |
|
1141 | + '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1142 | + '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1143 | 1143 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
1144 | 1144 | // '.custom-range::-moz-range-thumb' => array('b'), |
1145 | 1145 | // '.custom-range::-ms-thumb' => array('b'), |
1146 | - '.nav-pills .nav-link.active' => array('b'), |
|
1147 | - '.nav-pills .show>.nav-link' => array('b'), |
|
1148 | - '.page-link' => array('c'), |
|
1149 | - '.page-item.active .page-link' => array('b','o'), |
|
1150 | - '.badge-primary' => array('b'), |
|
1151 | - '.alert-primary' => array('b','o'), |
|
1152 | - '.progress-bar' => array('b'), |
|
1153 | - '.list-group-item.active' => array('b','o'), |
|
1154 | - '.bg-primary' => array('b','f'), |
|
1155 | - '.btn-link.btn-primary' => array('c'), |
|
1156 | - '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1157 | - ); |
|
1158 | - |
|
1159 | - $important_selectors = array( |
|
1160 | - '.bg-primary' => array('b','f'), |
|
1161 | - '.border-primary' => array('o'), |
|
1162 | - '.text-primary' => array('c'), |
|
1163 | - ); |
|
1164 | - |
|
1165 | - $color = array(); |
|
1166 | - $color_i = array(); |
|
1167 | - $background = array(); |
|
1168 | - $background_i = array(); |
|
1169 | - $border = array(); |
|
1170 | - $border_i = array(); |
|
1171 | - $fill = array(); |
|
1172 | - $fill_i = array(); |
|
1173 | - |
|
1174 | - $output = ''; |
|
1175 | - |
|
1176 | - // build rules into each type |
|
1177 | - foreach($selectors as $selector => $types){ |
|
1178 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1179 | - $types = array_combine($types,$types); |
|
1180 | - if(isset($types['c'])){$color[] = $selector;} |
|
1181 | - if(isset($types['b'])){$background[] = $selector;} |
|
1182 | - if(isset($types['o'])){$border[] = $selector;} |
|
1183 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1184 | - } |
|
1185 | - |
|
1186 | - // build rules into each type |
|
1187 | - foreach($important_selectors as $selector => $types){ |
|
1188 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1189 | - $types = array_combine($types,$types); |
|
1190 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1191 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1192 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1193 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1194 | - } |
|
1195 | - |
|
1196 | - // add any color rules |
|
1197 | - if(!empty($color)){ |
|
1198 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1199 | - } |
|
1200 | - if(!empty($color_i)){ |
|
1201 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1202 | - } |
|
1203 | - |
|
1204 | - // add any background color rules |
|
1205 | - if(!empty($background)){ |
|
1206 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1207 | - } |
|
1208 | - if(!empty($background_i)){ |
|
1209 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1210 | - } |
|
1211 | - |
|
1212 | - // add any border color rules |
|
1213 | - if(!empty($border)){ |
|
1214 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1215 | - } |
|
1216 | - if(!empty($border_i)){ |
|
1217 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1218 | - } |
|
1219 | - |
|
1220 | - // add any fill color rules |
|
1221 | - if(!empty($fill)){ |
|
1222 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1223 | - } |
|
1224 | - if(!empty($fill_i)){ |
|
1225 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1226 | - } |
|
1227 | - |
|
1228 | - |
|
1229 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1230 | - |
|
1231 | - // darken |
|
1232 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1233 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1234 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1235 | - |
|
1236 | - // lighten |
|
1237 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1238 | - |
|
1239 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1240 | - $op_25 = $color_code."40"; // 25% opacity |
|
1241 | - |
|
1242 | - |
|
1243 | - // button states |
|
1244 | - $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1245 | - $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1246 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1247 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1248 | - |
|
1249 | - |
|
1250 | - // dropdown's |
|
1251 | - $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1252 | - |
|
1253 | - |
|
1254 | - // input states |
|
1255 | - $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1256 | - |
|
1257 | - // page link |
|
1258 | - $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1259 | - |
|
1260 | - return $output; |
|
1261 | - } |
|
1262 | - |
|
1263 | - public static function css_secondary($color_code,$compatibility){; |
|
1264 | - $color_code = sanitize_hex_color($color_code); |
|
1265 | - if(!$color_code){return '';} |
|
1266 | - /** |
|
1267 | - * c = color, b = background color, o = border-color, f = fill |
|
1268 | - */ |
|
1269 | - $selectors = array( |
|
1270 | - '.btn-secondary' => array('b','o'), |
|
1271 | - '.btn-secondary.disabled' => array('b','o'), |
|
1272 | - '.btn-secondary:disabled' => array('b','o'), |
|
1273 | - '.btn-outline-secondary' => array('c','o'), |
|
1274 | - '.btn-outline-secondary:hover' => array('b','o'), |
|
1275 | - '.btn-outline-secondary.disabled' => array('c'), |
|
1276 | - '.btn-outline-secondary:disabled' => array('c'), |
|
1277 | - '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1278 | - '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1279 | - '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1280 | - '.badge-secondary' => array('b'), |
|
1281 | - '.alert-secondary' => array('b','o'), |
|
1282 | - '.btn-link.btn-secondary' => array('c'), |
|
1283 | - ); |
|
1284 | - |
|
1285 | - $important_selectors = array( |
|
1286 | - '.bg-secondary' => array('b','f'), |
|
1287 | - '.border-secondary' => array('o'), |
|
1288 | - '.text-secondary' => array('c'), |
|
1289 | - ); |
|
1290 | - |
|
1291 | - $color = array(); |
|
1292 | - $color_i = array(); |
|
1293 | - $background = array(); |
|
1294 | - $background_i = array(); |
|
1295 | - $border = array(); |
|
1296 | - $border_i = array(); |
|
1297 | - $fill = array(); |
|
1298 | - $fill_i = array(); |
|
1299 | - |
|
1300 | - $output = ''; |
|
1301 | - |
|
1302 | - // build rules into each type |
|
1303 | - foreach($selectors as $selector => $types){ |
|
1304 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1305 | - $types = array_combine($types,$types); |
|
1306 | - if(isset($types['c'])){$color[] = $selector;} |
|
1307 | - if(isset($types['b'])){$background[] = $selector;} |
|
1308 | - if(isset($types['o'])){$border[] = $selector;} |
|
1309 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1310 | - } |
|
1311 | - |
|
1312 | - // build rules into each type |
|
1313 | - foreach($important_selectors as $selector => $types){ |
|
1314 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1315 | - $types = array_combine($types,$types); |
|
1316 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1317 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1318 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1319 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1320 | - } |
|
1321 | - |
|
1322 | - // add any color rules |
|
1323 | - if(!empty($color)){ |
|
1324 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1325 | - } |
|
1326 | - if(!empty($color_i)){ |
|
1327 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1328 | - } |
|
1329 | - |
|
1330 | - // add any background color rules |
|
1331 | - if(!empty($background)){ |
|
1332 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1333 | - } |
|
1334 | - if(!empty($background_i)){ |
|
1335 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1336 | - } |
|
1337 | - |
|
1338 | - // add any border color rules |
|
1339 | - if(!empty($border)){ |
|
1340 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1341 | - } |
|
1342 | - if(!empty($border_i)){ |
|
1343 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1344 | - } |
|
1345 | - |
|
1346 | - // add any fill color rules |
|
1347 | - if(!empty($fill)){ |
|
1348 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1349 | - } |
|
1350 | - if(!empty($fill_i)){ |
|
1351 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1352 | - } |
|
1353 | - |
|
1354 | - |
|
1355 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1356 | - |
|
1357 | - // darken |
|
1358 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1359 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1360 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1361 | - |
|
1362 | - // lighten |
|
1363 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1364 | - |
|
1365 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1366 | - $op_25 = $color_code."40"; // 25% opacity |
|
1367 | - |
|
1368 | - |
|
1369 | - // button states |
|
1370 | - $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1371 | - $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1372 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1373 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1374 | - |
|
1375 | - |
|
1376 | - return $output; |
|
1377 | - } |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1381 | - * |
|
1382 | - * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1383 | - * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1384 | - * |
|
1385 | - * @return string |
|
1386 | - */ |
|
1387 | - public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1388 | - $hexCode = ltrim($hexCode, '#'); |
|
1389 | - |
|
1390 | - if (strlen($hexCode) == 3) { |
|
1391 | - $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1392 | - } |
|
1393 | - |
|
1394 | - $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1395 | - |
|
1396 | - foreach ($hexCode as & $color) { |
|
1397 | - $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1398 | - $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1399 | - |
|
1400 | - $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1401 | - } |
|
1402 | - |
|
1403 | - return '#' . implode($hexCode); |
|
1404 | - } |
|
1405 | - |
|
1406 | - /** |
|
1407 | - * Check if we should display examples. |
|
1408 | - */ |
|
1409 | - public function maybe_show_examples(){ |
|
1410 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1411 | - echo "<head>"; |
|
1412 | - wp_head(); |
|
1413 | - echo "</head>"; |
|
1414 | - echo "<body>"; |
|
1415 | - echo $this->get_examples(); |
|
1416 | - echo "</body>"; |
|
1417 | - exit; |
|
1418 | - } |
|
1419 | - } |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * Get developer examples. |
|
1423 | - * |
|
1424 | - * @return string |
|
1425 | - */ |
|
1426 | - public function get_examples(){ |
|
1427 | - $output = ''; |
|
1428 | - |
|
1429 | - |
|
1430 | - // open form |
|
1431 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1432 | - |
|
1433 | - // input example |
|
1434 | - $output .= aui()->input(array( |
|
1435 | - 'type' => 'text', |
|
1436 | - 'id' => 'text-example', |
|
1437 | - 'name' => 'text-example', |
|
1438 | - 'placeholder' => 'text placeholder', |
|
1439 | - 'title' => 'Text input example', |
|
1440 | - 'value' => '', |
|
1441 | - 'required' => false, |
|
1442 | - 'help_text' => 'help text', |
|
1443 | - 'label' => 'Text input example label' |
|
1444 | - )); |
|
1445 | - |
|
1446 | - // input example |
|
1447 | - $output .= aui()->input(array( |
|
1448 | - 'type' => 'url', |
|
1449 | - 'id' => 'text-example2', |
|
1450 | - 'name' => 'text-example', |
|
1451 | - 'placeholder' => 'url placeholder', |
|
1452 | - 'title' => 'Text input example', |
|
1453 | - 'value' => '', |
|
1454 | - 'required' => false, |
|
1455 | - 'help_text' => 'help text', |
|
1456 | - 'label' => 'Text input example label' |
|
1457 | - )); |
|
1458 | - |
|
1459 | - // checkbox example |
|
1460 | - $output .= aui()->input(array( |
|
1461 | - 'type' => 'checkbox', |
|
1462 | - 'id' => 'checkbox-example', |
|
1463 | - 'name' => 'checkbox-example', |
|
1464 | - 'placeholder' => 'checkbox-example', |
|
1465 | - 'title' => 'Checkbox example', |
|
1466 | - 'value' => '1', |
|
1467 | - 'checked' => true, |
|
1468 | - 'required' => false, |
|
1469 | - 'help_text' => 'help text', |
|
1470 | - 'label' => 'Checkbox checked' |
|
1471 | - )); |
|
1472 | - |
|
1473 | - // checkbox example |
|
1474 | - $output .= aui()->input(array( |
|
1475 | - 'type' => 'checkbox', |
|
1476 | - 'id' => 'checkbox-example2', |
|
1477 | - 'name' => 'checkbox-example2', |
|
1478 | - 'placeholder' => 'checkbox-example', |
|
1479 | - 'title' => 'Checkbox example', |
|
1480 | - 'value' => '1', |
|
1481 | - 'checked' => false, |
|
1482 | - 'required' => false, |
|
1483 | - 'help_text' => 'help text', |
|
1484 | - 'label' => 'Checkbox un-checked' |
|
1485 | - )); |
|
1486 | - |
|
1487 | - // switch example |
|
1488 | - $output .= aui()->input(array( |
|
1489 | - 'type' => 'checkbox', |
|
1490 | - 'id' => 'switch-example', |
|
1491 | - 'name' => 'switch-example', |
|
1492 | - 'placeholder' => 'checkbox-example', |
|
1493 | - 'title' => 'Switch example', |
|
1494 | - 'value' => '1', |
|
1495 | - 'checked' => true, |
|
1496 | - 'switch' => true, |
|
1497 | - 'required' => false, |
|
1498 | - 'help_text' => 'help text', |
|
1499 | - 'label' => 'Switch on' |
|
1500 | - )); |
|
1501 | - |
|
1502 | - // switch example |
|
1503 | - $output .= aui()->input(array( |
|
1504 | - 'type' => 'checkbox', |
|
1505 | - 'id' => 'switch-example2', |
|
1506 | - 'name' => 'switch-example2', |
|
1507 | - 'placeholder' => 'checkbox-example', |
|
1508 | - 'title' => 'Switch example', |
|
1509 | - 'value' => '1', |
|
1510 | - 'checked' => false, |
|
1511 | - 'switch' => true, |
|
1512 | - 'required' => false, |
|
1513 | - 'help_text' => 'help text', |
|
1514 | - 'label' => 'Switch off' |
|
1515 | - )); |
|
1516 | - |
|
1517 | - // close form |
|
1518 | - $output .= "</form>"; |
|
1519 | - |
|
1520 | - return $output; |
|
1521 | - } |
|
1522 | - |
|
1523 | - } |
|
1524 | - |
|
1525 | - /** |
|
1526 | - * Run the class if found. |
|
1527 | - */ |
|
1528 | - AyeCode_UI_Settings::instance(); |
|
1146 | + '.nav-pills .nav-link.active' => array('b'), |
|
1147 | + '.nav-pills .show>.nav-link' => array('b'), |
|
1148 | + '.page-link' => array('c'), |
|
1149 | + '.page-item.active .page-link' => array('b','o'), |
|
1150 | + '.badge-primary' => array('b'), |
|
1151 | + '.alert-primary' => array('b','o'), |
|
1152 | + '.progress-bar' => array('b'), |
|
1153 | + '.list-group-item.active' => array('b','o'), |
|
1154 | + '.bg-primary' => array('b','f'), |
|
1155 | + '.btn-link.btn-primary' => array('c'), |
|
1156 | + '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1157 | + ); |
|
1158 | + |
|
1159 | + $important_selectors = array( |
|
1160 | + '.bg-primary' => array('b','f'), |
|
1161 | + '.border-primary' => array('o'), |
|
1162 | + '.text-primary' => array('c'), |
|
1163 | + ); |
|
1164 | + |
|
1165 | + $color = array(); |
|
1166 | + $color_i = array(); |
|
1167 | + $background = array(); |
|
1168 | + $background_i = array(); |
|
1169 | + $border = array(); |
|
1170 | + $border_i = array(); |
|
1171 | + $fill = array(); |
|
1172 | + $fill_i = array(); |
|
1173 | + |
|
1174 | + $output = ''; |
|
1175 | + |
|
1176 | + // build rules into each type |
|
1177 | + foreach($selectors as $selector => $types){ |
|
1178 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1179 | + $types = array_combine($types,$types); |
|
1180 | + if(isset($types['c'])){$color[] = $selector;} |
|
1181 | + if(isset($types['b'])){$background[] = $selector;} |
|
1182 | + if(isset($types['o'])){$border[] = $selector;} |
|
1183 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1184 | + } |
|
1185 | + |
|
1186 | + // build rules into each type |
|
1187 | + foreach($important_selectors as $selector => $types){ |
|
1188 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1189 | + $types = array_combine($types,$types); |
|
1190 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1191 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1192 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1193 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1194 | + } |
|
1195 | + |
|
1196 | + // add any color rules |
|
1197 | + if(!empty($color)){ |
|
1198 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1199 | + } |
|
1200 | + if(!empty($color_i)){ |
|
1201 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1202 | + } |
|
1203 | + |
|
1204 | + // add any background color rules |
|
1205 | + if(!empty($background)){ |
|
1206 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1207 | + } |
|
1208 | + if(!empty($background_i)){ |
|
1209 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1210 | + } |
|
1211 | + |
|
1212 | + // add any border color rules |
|
1213 | + if(!empty($border)){ |
|
1214 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1215 | + } |
|
1216 | + if(!empty($border_i)){ |
|
1217 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1218 | + } |
|
1219 | + |
|
1220 | + // add any fill color rules |
|
1221 | + if(!empty($fill)){ |
|
1222 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1223 | + } |
|
1224 | + if(!empty($fill_i)){ |
|
1225 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1226 | + } |
|
1227 | + |
|
1228 | + |
|
1229 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1230 | + |
|
1231 | + // darken |
|
1232 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1233 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1234 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1235 | + |
|
1236 | + // lighten |
|
1237 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1238 | + |
|
1239 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1240 | + $op_25 = $color_code."40"; // 25% opacity |
|
1241 | + |
|
1242 | + |
|
1243 | + // button states |
|
1244 | + $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1245 | + $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1246 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1247 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1248 | + |
|
1249 | + |
|
1250 | + // dropdown's |
|
1251 | + $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1252 | + |
|
1253 | + |
|
1254 | + // input states |
|
1255 | + $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1256 | + |
|
1257 | + // page link |
|
1258 | + $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1259 | + |
|
1260 | + return $output; |
|
1261 | + } |
|
1262 | + |
|
1263 | + public static function css_secondary($color_code,$compatibility){; |
|
1264 | + $color_code = sanitize_hex_color($color_code); |
|
1265 | + if(!$color_code){return '';} |
|
1266 | + /** |
|
1267 | + * c = color, b = background color, o = border-color, f = fill |
|
1268 | + */ |
|
1269 | + $selectors = array( |
|
1270 | + '.btn-secondary' => array('b','o'), |
|
1271 | + '.btn-secondary.disabled' => array('b','o'), |
|
1272 | + '.btn-secondary:disabled' => array('b','o'), |
|
1273 | + '.btn-outline-secondary' => array('c','o'), |
|
1274 | + '.btn-outline-secondary:hover' => array('b','o'), |
|
1275 | + '.btn-outline-secondary.disabled' => array('c'), |
|
1276 | + '.btn-outline-secondary:disabled' => array('c'), |
|
1277 | + '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1278 | + '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1279 | + '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1280 | + '.badge-secondary' => array('b'), |
|
1281 | + '.alert-secondary' => array('b','o'), |
|
1282 | + '.btn-link.btn-secondary' => array('c'), |
|
1283 | + ); |
|
1284 | + |
|
1285 | + $important_selectors = array( |
|
1286 | + '.bg-secondary' => array('b','f'), |
|
1287 | + '.border-secondary' => array('o'), |
|
1288 | + '.text-secondary' => array('c'), |
|
1289 | + ); |
|
1290 | + |
|
1291 | + $color = array(); |
|
1292 | + $color_i = array(); |
|
1293 | + $background = array(); |
|
1294 | + $background_i = array(); |
|
1295 | + $border = array(); |
|
1296 | + $border_i = array(); |
|
1297 | + $fill = array(); |
|
1298 | + $fill_i = array(); |
|
1299 | + |
|
1300 | + $output = ''; |
|
1301 | + |
|
1302 | + // build rules into each type |
|
1303 | + foreach($selectors as $selector => $types){ |
|
1304 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1305 | + $types = array_combine($types,$types); |
|
1306 | + if(isset($types['c'])){$color[] = $selector;} |
|
1307 | + if(isset($types['b'])){$background[] = $selector;} |
|
1308 | + if(isset($types['o'])){$border[] = $selector;} |
|
1309 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1310 | + } |
|
1311 | + |
|
1312 | + // build rules into each type |
|
1313 | + foreach($important_selectors as $selector => $types){ |
|
1314 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1315 | + $types = array_combine($types,$types); |
|
1316 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1317 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1318 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1319 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1320 | + } |
|
1321 | + |
|
1322 | + // add any color rules |
|
1323 | + if(!empty($color)){ |
|
1324 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1325 | + } |
|
1326 | + if(!empty($color_i)){ |
|
1327 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1328 | + } |
|
1329 | + |
|
1330 | + // add any background color rules |
|
1331 | + if(!empty($background)){ |
|
1332 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1333 | + } |
|
1334 | + if(!empty($background_i)){ |
|
1335 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1336 | + } |
|
1337 | + |
|
1338 | + // add any border color rules |
|
1339 | + if(!empty($border)){ |
|
1340 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1341 | + } |
|
1342 | + if(!empty($border_i)){ |
|
1343 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1344 | + } |
|
1345 | + |
|
1346 | + // add any fill color rules |
|
1347 | + if(!empty($fill)){ |
|
1348 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1349 | + } |
|
1350 | + if(!empty($fill_i)){ |
|
1351 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1352 | + } |
|
1353 | + |
|
1354 | + |
|
1355 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1356 | + |
|
1357 | + // darken |
|
1358 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1359 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1360 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1361 | + |
|
1362 | + // lighten |
|
1363 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1364 | + |
|
1365 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1366 | + $op_25 = $color_code."40"; // 25% opacity |
|
1367 | + |
|
1368 | + |
|
1369 | + // button states |
|
1370 | + $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1371 | + $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1372 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1373 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1374 | + |
|
1375 | + |
|
1376 | + return $output; |
|
1377 | + } |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1381 | + * |
|
1382 | + * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1383 | + * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1384 | + * |
|
1385 | + * @return string |
|
1386 | + */ |
|
1387 | + public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1388 | + $hexCode = ltrim($hexCode, '#'); |
|
1389 | + |
|
1390 | + if (strlen($hexCode) == 3) { |
|
1391 | + $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1392 | + } |
|
1393 | + |
|
1394 | + $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1395 | + |
|
1396 | + foreach ($hexCode as & $color) { |
|
1397 | + $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1398 | + $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1399 | + |
|
1400 | + $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1401 | + } |
|
1402 | + |
|
1403 | + return '#' . implode($hexCode); |
|
1404 | + } |
|
1405 | + |
|
1406 | + /** |
|
1407 | + * Check if we should display examples. |
|
1408 | + */ |
|
1409 | + public function maybe_show_examples(){ |
|
1410 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1411 | + echo "<head>"; |
|
1412 | + wp_head(); |
|
1413 | + echo "</head>"; |
|
1414 | + echo "<body>"; |
|
1415 | + echo $this->get_examples(); |
|
1416 | + echo "</body>"; |
|
1417 | + exit; |
|
1418 | + } |
|
1419 | + } |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * Get developer examples. |
|
1423 | + * |
|
1424 | + * @return string |
|
1425 | + */ |
|
1426 | + public function get_examples(){ |
|
1427 | + $output = ''; |
|
1428 | + |
|
1429 | + |
|
1430 | + // open form |
|
1431 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1432 | + |
|
1433 | + // input example |
|
1434 | + $output .= aui()->input(array( |
|
1435 | + 'type' => 'text', |
|
1436 | + 'id' => 'text-example', |
|
1437 | + 'name' => 'text-example', |
|
1438 | + 'placeholder' => 'text placeholder', |
|
1439 | + 'title' => 'Text input example', |
|
1440 | + 'value' => '', |
|
1441 | + 'required' => false, |
|
1442 | + 'help_text' => 'help text', |
|
1443 | + 'label' => 'Text input example label' |
|
1444 | + )); |
|
1445 | + |
|
1446 | + // input example |
|
1447 | + $output .= aui()->input(array( |
|
1448 | + 'type' => 'url', |
|
1449 | + 'id' => 'text-example2', |
|
1450 | + 'name' => 'text-example', |
|
1451 | + 'placeholder' => 'url placeholder', |
|
1452 | + 'title' => 'Text input example', |
|
1453 | + 'value' => '', |
|
1454 | + 'required' => false, |
|
1455 | + 'help_text' => 'help text', |
|
1456 | + 'label' => 'Text input example label' |
|
1457 | + )); |
|
1458 | + |
|
1459 | + // checkbox example |
|
1460 | + $output .= aui()->input(array( |
|
1461 | + 'type' => 'checkbox', |
|
1462 | + 'id' => 'checkbox-example', |
|
1463 | + 'name' => 'checkbox-example', |
|
1464 | + 'placeholder' => 'checkbox-example', |
|
1465 | + 'title' => 'Checkbox example', |
|
1466 | + 'value' => '1', |
|
1467 | + 'checked' => true, |
|
1468 | + 'required' => false, |
|
1469 | + 'help_text' => 'help text', |
|
1470 | + 'label' => 'Checkbox checked' |
|
1471 | + )); |
|
1472 | + |
|
1473 | + // checkbox example |
|
1474 | + $output .= aui()->input(array( |
|
1475 | + 'type' => 'checkbox', |
|
1476 | + 'id' => 'checkbox-example2', |
|
1477 | + 'name' => 'checkbox-example2', |
|
1478 | + 'placeholder' => 'checkbox-example', |
|
1479 | + 'title' => 'Checkbox example', |
|
1480 | + 'value' => '1', |
|
1481 | + 'checked' => false, |
|
1482 | + 'required' => false, |
|
1483 | + 'help_text' => 'help text', |
|
1484 | + 'label' => 'Checkbox un-checked' |
|
1485 | + )); |
|
1486 | + |
|
1487 | + // switch example |
|
1488 | + $output .= aui()->input(array( |
|
1489 | + 'type' => 'checkbox', |
|
1490 | + 'id' => 'switch-example', |
|
1491 | + 'name' => 'switch-example', |
|
1492 | + 'placeholder' => 'checkbox-example', |
|
1493 | + 'title' => 'Switch example', |
|
1494 | + 'value' => '1', |
|
1495 | + 'checked' => true, |
|
1496 | + 'switch' => true, |
|
1497 | + 'required' => false, |
|
1498 | + 'help_text' => 'help text', |
|
1499 | + 'label' => 'Switch on' |
|
1500 | + )); |
|
1501 | + |
|
1502 | + // switch example |
|
1503 | + $output .= aui()->input(array( |
|
1504 | + 'type' => 'checkbox', |
|
1505 | + 'id' => 'switch-example2', |
|
1506 | + 'name' => 'switch-example2', |
|
1507 | + 'placeholder' => 'checkbox-example', |
|
1508 | + 'title' => 'Switch example', |
|
1509 | + 'value' => '1', |
|
1510 | + 'checked' => false, |
|
1511 | + 'switch' => true, |
|
1512 | + 'required' => false, |
|
1513 | + 'help_text' => 'help text', |
|
1514 | + 'label' => 'Switch off' |
|
1515 | + )); |
|
1516 | + |
|
1517 | + // close form |
|
1518 | + $output .= "</form>"; |
|
1519 | + |
|
1520 | + return $output; |
|
1521 | + } |
|
1522 | + |
|
1523 | + } |
|
1524 | + |
|
1525 | + /** |
|
1526 | + * Run the class if found. |
|
1527 | + */ |
|
1528 | + AyeCode_UI_Settings::instance(); |
|
1529 | 1529 | } |
1530 | 1530 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,60 +10,60 @@ discard block |
||
10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
11 | 11 | |
12 | 12 | /** |
13 | - * Stores a custom description for the item. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $custom_description = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * Stores the item quantity. |
|
21 | - * |
|
22 | - * @var int |
|
23 | - */ |
|
24 | - protected $quantity = 1; |
|
25 | - |
|
26 | - /** |
|
27 | - * Stores the item meta. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $meta = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Is this item required? |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $is_required = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * Are quantities allowed? |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $allow_quantities = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Associated invoice. |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - public $invoice_id = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * Item discount. |
|
56 | - * |
|
57 | - * @var float |
|
58 | - */ |
|
59 | - public $item_discount = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * Item tax. |
|
63 | - * |
|
64 | - * @var float |
|
65 | - */ |
|
66 | - public $item_tax = 0; |
|
13 | + * Stores a custom description for the item. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $custom_description = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * Stores the item quantity. |
|
21 | + * |
|
22 | + * @var int |
|
23 | + */ |
|
24 | + protected $quantity = 1; |
|
25 | + |
|
26 | + /** |
|
27 | + * Stores the item meta. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $meta = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Is this item required? |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $is_required = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * Are quantities allowed? |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $allow_quantities = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Associated invoice. |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + public $invoice_id = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * Item discount. |
|
56 | + * |
|
57 | + * @var float |
|
58 | + */ |
|
59 | + public $item_discount = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * Item tax. |
|
63 | + * |
|
64 | + * @var float |
|
65 | + */ |
|
66 | + public $item_tax = 0; |
|
67 | 67 | |
68 | 68 | /* |
69 | 69 | |-------------------------------------------------------------------------- |
@@ -81,232 +81,232 @@ discard block |
||
81 | 81 | */ |
82 | 82 | |
83 | 83 | /** |
84 | - * Get the item name. |
|
85 | - * |
|
86 | - * @since 1.0.19 |
|
87 | - * @param string $context View or edit context. |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function get_name( $context = 'view' ) { |
|
91 | - $name = parent::get_name( $context ); |
|
92 | - return $name . wpinv_get_item_suffix( $this ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get the item name without a suffix. |
|
97 | - * |
|
98 | - * @since 1.0.19 |
|
99 | - * @param string $context View or edit context. |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function get_raw_name( $context = 'view' ) { |
|
103 | - return parent::get_name( $context ); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Get the item description. |
|
108 | - * |
|
109 | - * @since 1.0.19 |
|
110 | - * @param string $context View or edit context. |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function get_description( $context = 'view' ) { |
|
114 | - |
|
115 | - if ( isset( $this->custom_description ) ) { |
|
116 | - return $this->custom_description; |
|
117 | - } |
|
118 | - |
|
119 | - return parent::get_description( $context ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns the sub total. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - * @param string $context View or edit context. |
|
127 | - * @return float |
|
128 | - */ |
|
129 | - public function get_sub_total( $context = 'view' ) { |
|
130 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the recurring sub total. |
|
135 | - * |
|
136 | - * @since 1.0.19 |
|
137 | - * @param string $context View or edit context. |
|
138 | - * @return float |
|
139 | - */ |
|
140 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | - |
|
142 | - if ( $this->is_recurring() ) { |
|
143 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
144 | - } |
|
145 | - |
|
146 | - return 0; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @deprecated |
|
151 | - */ |
|
152 | - public function get_qantity( $context = 'view' ) { |
|
153 | - return $this->get_quantity( $context ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Get the item quantity. |
|
158 | - * |
|
159 | - * @since 1.0.19 |
|
160 | - * @param string $context View or edit context. |
|
161 | - * @return int |
|
162 | - */ |
|
163 | - public function get_quantity( $context = 'view' ) { |
|
164 | - $quantity = (int) $this->quantity; |
|
165 | - |
|
166 | - if ( empty( $quantity ) || 1 > $quantity ) { |
|
167 | - $quantity = 1; |
|
168 | - } |
|
169 | - |
|
170 | - if ( 'view' == $context ) { |
|
171 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
172 | - } |
|
173 | - |
|
174 | - return $quantity; |
|
175 | - |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Get the item meta data. |
|
180 | - * |
|
181 | - * @since 1.0.19 |
|
182 | - * @param string $context View or edit context. |
|
183 | - * @return meta |
|
184 | - */ |
|
185 | - public function get_item_meta( $context = 'view' ) { |
|
186 | - $meta = $this->meta; |
|
187 | - |
|
188 | - if ( 'view' == $context ) { |
|
189 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
190 | - } |
|
191 | - |
|
192 | - return $meta; |
|
193 | - |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Returns whether or not customers can update the item quantity. |
|
198 | - * |
|
199 | - * @since 1.0.19 |
|
200 | - * @param string $context View or edit context. |
|
201 | - * @return bool |
|
202 | - */ |
|
203 | - public function get_allow_quantities( $context = 'view' ) { |
|
204 | - $allow_quantities = (bool) $this->allow_quantities; |
|
205 | - |
|
206 | - if ( 'view' == $context ) { |
|
207 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
208 | - } |
|
209 | - |
|
210 | - return $allow_quantities; |
|
211 | - |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Returns whether or not the item is required. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - public function get_is_required( $context = 'view' ) { |
|
222 | - $is_required = (bool) $this->is_required; |
|
223 | - |
|
224 | - if ( 'view' == $context ) { |
|
225 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
226 | - } |
|
227 | - |
|
228 | - return $is_required; |
|
229 | - |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Prepares form data for use. |
|
234 | - * |
|
235 | - * @since 1.0.19 |
|
236 | - * @return array |
|
237 | - */ |
|
238 | - public function prepare_data_for_use( $required = null ) { |
|
239 | - |
|
240 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
241 | - return array( |
|
242 | - 'title' => strip_tags( $this->get_name() ), |
|
243 | - 'id' => $this->get_id(), |
|
244 | - 'price' => $this->get_price(), |
|
245 | - 'recurring' => $this->is_recurring(), |
|
246 | - 'description' => $this->get_description(), |
|
247 | - 'allow_quantities' => $this->allows_quantities(), |
|
248 | - 'required' => $required, |
|
249 | - ); |
|
250 | - |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Prepares form data for ajax use. |
|
255 | - * |
|
256 | - * @since 1.0.19 |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - public function prepare_data_for_invoice_edit_ajax( $currency = '' ) { |
|
260 | - |
|
261 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
262 | - |
|
263 | - if ( $description ) { |
|
264 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
265 | - } |
|
266 | - |
|
267 | - return array( |
|
268 | - 'id' => $this->get_id(), |
|
269 | - 'texts' => array( |
|
270 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
271 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
272 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
273 | - 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ), |
|
274 | - 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ), |
|
275 | - ), |
|
276 | - 'inputs' => array( |
|
277 | - 'item-id' => $this->get_id(), |
|
278 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
279 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
280 | - 'item-quantity' => absint( $this->get_quantity() ), |
|
281 | - 'item-price' => $this->get_price(), |
|
282 | - ) |
|
283 | - ); |
|
284 | - |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Prepares form data for saving (cart_details). |
|
289 | - * |
|
290 | - * @since 1.0.19 |
|
291 | - * @return array |
|
292 | - */ |
|
293 | - public function prepare_data_for_saving() { |
|
294 | - |
|
295 | - return array( |
|
296 | - 'post_id' => $this->invoice_id, |
|
297 | - 'item_id' => $this->get_id(), |
|
298 | - 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
299 | - 'item_description' => $this->get_description(), |
|
300 | - 'tax' => $this->item_tax, |
|
301 | - 'item_price' => $this->get_price(), |
|
302 | - 'quantity' => (int) $this->get_quantity(), |
|
303 | - 'discount' => $this->item_discount, |
|
304 | - 'subtotal' => $this->get_sub_total(), |
|
305 | - 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
306 | - 'meta' => $this->get_item_meta(), |
|
307 | - ); |
|
308 | - |
|
309 | - } |
|
84 | + * Get the item name. |
|
85 | + * |
|
86 | + * @since 1.0.19 |
|
87 | + * @param string $context View or edit context. |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function get_name( $context = 'view' ) { |
|
91 | + $name = parent::get_name( $context ); |
|
92 | + return $name . wpinv_get_item_suffix( $this ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get the item name without a suffix. |
|
97 | + * |
|
98 | + * @since 1.0.19 |
|
99 | + * @param string $context View or edit context. |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function get_raw_name( $context = 'view' ) { |
|
103 | + return parent::get_name( $context ); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Get the item description. |
|
108 | + * |
|
109 | + * @since 1.0.19 |
|
110 | + * @param string $context View or edit context. |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function get_description( $context = 'view' ) { |
|
114 | + |
|
115 | + if ( isset( $this->custom_description ) ) { |
|
116 | + return $this->custom_description; |
|
117 | + } |
|
118 | + |
|
119 | + return parent::get_description( $context ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns the sub total. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + * @param string $context View or edit context. |
|
127 | + * @return float |
|
128 | + */ |
|
129 | + public function get_sub_total( $context = 'view' ) { |
|
130 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the recurring sub total. |
|
135 | + * |
|
136 | + * @since 1.0.19 |
|
137 | + * @param string $context View or edit context. |
|
138 | + * @return float |
|
139 | + */ |
|
140 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
141 | + |
|
142 | + if ( $this->is_recurring() ) { |
|
143 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
144 | + } |
|
145 | + |
|
146 | + return 0; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @deprecated |
|
151 | + */ |
|
152 | + public function get_qantity( $context = 'view' ) { |
|
153 | + return $this->get_quantity( $context ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Get the item quantity. |
|
158 | + * |
|
159 | + * @since 1.0.19 |
|
160 | + * @param string $context View or edit context. |
|
161 | + * @return int |
|
162 | + */ |
|
163 | + public function get_quantity( $context = 'view' ) { |
|
164 | + $quantity = (int) $this->quantity; |
|
165 | + |
|
166 | + if ( empty( $quantity ) || 1 > $quantity ) { |
|
167 | + $quantity = 1; |
|
168 | + } |
|
169 | + |
|
170 | + if ( 'view' == $context ) { |
|
171 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
172 | + } |
|
173 | + |
|
174 | + return $quantity; |
|
175 | + |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Get the item meta data. |
|
180 | + * |
|
181 | + * @since 1.0.19 |
|
182 | + * @param string $context View or edit context. |
|
183 | + * @return meta |
|
184 | + */ |
|
185 | + public function get_item_meta( $context = 'view' ) { |
|
186 | + $meta = $this->meta; |
|
187 | + |
|
188 | + if ( 'view' == $context ) { |
|
189 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
190 | + } |
|
191 | + |
|
192 | + return $meta; |
|
193 | + |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Returns whether or not customers can update the item quantity. |
|
198 | + * |
|
199 | + * @since 1.0.19 |
|
200 | + * @param string $context View or edit context. |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | + public function get_allow_quantities( $context = 'view' ) { |
|
204 | + $allow_quantities = (bool) $this->allow_quantities; |
|
205 | + |
|
206 | + if ( 'view' == $context ) { |
|
207 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
208 | + } |
|
209 | + |
|
210 | + return $allow_quantities; |
|
211 | + |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Returns whether or not the item is required. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + public function get_is_required( $context = 'view' ) { |
|
222 | + $is_required = (bool) $this->is_required; |
|
223 | + |
|
224 | + if ( 'view' == $context ) { |
|
225 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
226 | + } |
|
227 | + |
|
228 | + return $is_required; |
|
229 | + |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Prepares form data for use. |
|
234 | + * |
|
235 | + * @since 1.0.19 |
|
236 | + * @return array |
|
237 | + */ |
|
238 | + public function prepare_data_for_use( $required = null ) { |
|
239 | + |
|
240 | + $required = is_null( $required ) ? $this->is_required() : $required; |
|
241 | + return array( |
|
242 | + 'title' => strip_tags( $this->get_name() ), |
|
243 | + 'id' => $this->get_id(), |
|
244 | + 'price' => $this->get_price(), |
|
245 | + 'recurring' => $this->is_recurring(), |
|
246 | + 'description' => $this->get_description(), |
|
247 | + 'allow_quantities' => $this->allows_quantities(), |
|
248 | + 'required' => $required, |
|
249 | + ); |
|
250 | + |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Prepares form data for ajax use. |
|
255 | + * |
|
256 | + * @since 1.0.19 |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + public function prepare_data_for_invoice_edit_ajax( $currency = '' ) { |
|
260 | + |
|
261 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
262 | + |
|
263 | + if ( $description ) { |
|
264 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
265 | + } |
|
266 | + |
|
267 | + return array( |
|
268 | + 'id' => $this->get_id(), |
|
269 | + 'texts' => array( |
|
270 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
271 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
272 | + 'item-quantity' => absint( $this->get_quantity() ), |
|
273 | + 'item-price' => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ), |
|
274 | + 'item-total' => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ), |
|
275 | + ), |
|
276 | + 'inputs' => array( |
|
277 | + 'item-id' => $this->get_id(), |
|
278 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
279 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
280 | + 'item-quantity' => absint( $this->get_quantity() ), |
|
281 | + 'item-price' => $this->get_price(), |
|
282 | + ) |
|
283 | + ); |
|
284 | + |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Prepares form data for saving (cart_details). |
|
289 | + * |
|
290 | + * @since 1.0.19 |
|
291 | + * @return array |
|
292 | + */ |
|
293 | + public function prepare_data_for_saving() { |
|
294 | + |
|
295 | + return array( |
|
296 | + 'post_id' => $this->invoice_id, |
|
297 | + 'item_id' => $this->get_id(), |
|
298 | + 'item_name' => sanitize_text_field( $this->get_raw_name() ), |
|
299 | + 'item_description' => $this->get_description(), |
|
300 | + 'tax' => $this->item_tax, |
|
301 | + 'item_price' => $this->get_price(), |
|
302 | + 'quantity' => (int) $this->get_quantity(), |
|
303 | + 'discount' => $this->item_discount, |
|
304 | + 'subtotal' => $this->get_sub_total(), |
|
305 | + 'price' => $this->get_sub_total() + $this->item_tax + $this->item_discount, |
|
306 | + 'meta' => $this->get_item_meta(), |
|
307 | + ); |
|
308 | + |
|
309 | + } |
|
310 | 310 | |
311 | 311 | /* |
312 | 312 | |-------------------------------------------------------------------------- |
@@ -318,70 +318,70 @@ discard block |
||
318 | 318 | | object. |
319 | 319 | */ |
320 | 320 | |
321 | - /** |
|
322 | - * Set the item qantity. |
|
323 | - * |
|
324 | - * @since 1.0.19 |
|
325 | - * @param int $quantity The item quantity. |
|
326 | - */ |
|
327 | - public function set_quantity( $quantity ) { |
|
328 | - |
|
329 | - if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
330 | - $quantity = 1; |
|
331 | - } |
|
332 | - |
|
333 | - $this->quantity = (int) $quantity; |
|
334 | - |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Set the item meta data. |
|
339 | - * |
|
340 | - * @since 1.0.19 |
|
341 | - * @param array $meta The item meta data. |
|
342 | - */ |
|
343 | - public function set_item_meta( $meta ) { |
|
344 | - $this->meta = maybe_unserialize( $meta ); |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Set whether or not the quantities are allowed. |
|
349 | - * |
|
350 | - * @since 1.0.19 |
|
351 | - * @param bool $allow_quantities |
|
352 | - */ |
|
353 | - public function set_allow_quantities( $allow_quantities ) { |
|
354 | - $this->allow_quantities = (bool) $allow_quantities; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Set whether or not the item is required. |
|
359 | - * |
|
360 | - * @since 1.0.19 |
|
361 | - * @param bool $is_required |
|
362 | - */ |
|
363 | - public function set_is_required( $is_required ) { |
|
364 | - $this->is_required = (bool) $is_required; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Sets the custom item description. |
|
369 | - * |
|
370 | - * @since 1.0.19 |
|
371 | - * @param string $description |
|
372 | - */ |
|
373 | - public function set_custom_description( $description ) { |
|
374 | - $this->custom_description = $description; |
|
375 | - } |
|
321 | + /** |
|
322 | + * Set the item qantity. |
|
323 | + * |
|
324 | + * @since 1.0.19 |
|
325 | + * @param int $quantity The item quantity. |
|
326 | + */ |
|
327 | + public function set_quantity( $quantity ) { |
|
328 | + |
|
329 | + if ( empty( $quantity ) || ! is_numeric( $quantity ) ) { |
|
330 | + $quantity = 1; |
|
331 | + } |
|
332 | + |
|
333 | + $this->quantity = (int) $quantity; |
|
334 | + |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Set the item meta data. |
|
339 | + * |
|
340 | + * @since 1.0.19 |
|
341 | + * @param array $meta The item meta data. |
|
342 | + */ |
|
343 | + public function set_item_meta( $meta ) { |
|
344 | + $this->meta = maybe_unserialize( $meta ); |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Set whether or not the quantities are allowed. |
|
349 | + * |
|
350 | + * @since 1.0.19 |
|
351 | + * @param bool $allow_quantities |
|
352 | + */ |
|
353 | + public function set_allow_quantities( $allow_quantities ) { |
|
354 | + $this->allow_quantities = (bool) $allow_quantities; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Set whether or not the item is required. |
|
359 | + * |
|
360 | + * @since 1.0.19 |
|
361 | + * @param bool $is_required |
|
362 | + */ |
|
363 | + public function set_is_required( $is_required ) { |
|
364 | + $this->is_required = (bool) $is_required; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Sets the custom item description. |
|
369 | + * |
|
370 | + * @since 1.0.19 |
|
371 | + * @param string $description |
|
372 | + */ |
|
373 | + public function set_custom_description( $description ) { |
|
374 | + $this->custom_description = $description; |
|
375 | + } |
|
376 | 376 | |
377 | 377 | /** |
378 | 378 | * We do not want to save items to the database. |
379 | 379 | * |
380 | - * @return int item id |
|
380 | + * @return int item id |
|
381 | 381 | */ |
382 | 382 | public function save( $data = array() ) { |
383 | 383 | return $this->get_id(); |
384 | - } |
|
384 | + } |
|
385 | 385 | |
386 | 386 | /* |
387 | 387 | |-------------------------------------------------------------------------- |
@@ -393,23 +393,23 @@ discard block |
||
393 | 393 | */ |
394 | 394 | |
395 | 395 | /** |
396 | - * Checks whether the item has enabled dynamic pricing. |
|
397 | - * |
|
398 | - * @since 1.0.19 |
|
399 | - * @return bool |
|
400 | - */ |
|
401 | - public function is_required() { |
|
396 | + * Checks whether the item has enabled dynamic pricing. |
|
397 | + * |
|
398 | + * @since 1.0.19 |
|
399 | + * @return bool |
|
400 | + */ |
|
401 | + public function is_required() { |
|
402 | 402 | return (bool) $this->get_is_required(); |
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Checks whether users can edit the quantities. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @return bool |
|
410 | - */ |
|
411 | - public function allows_quantities() { |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Checks whether users can edit the quantities. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @return bool |
|
410 | + */ |
|
411 | + public function allows_quantities() { |
|
412 | 412 | return (bool) $this->get_allow_quantities(); |
413 | - } |
|
413 | + } |
|
414 | 414 | |
415 | 415 | } |
@@ -232,26 +232,26 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
235 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
235 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
236 | 236 | |
237 | 237 | $chosen = false; |
238 | 238 | if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
239 | 239 | $chosen = $invoice->get_gateway(); |
240 | 240 | } |
241 | 241 | |
242 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
242 | + $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
243 | 243 | |
244 | - if ( false !== $chosen ) { |
|
245 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
246 | - } |
|
244 | + if ( false !== $chosen ) { |
|
245 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
246 | + } |
|
247 | 247 | |
248 | - if ( ! empty ( $chosen ) ) { |
|
249 | - $enabled_gateway = urldecode( $chosen ); |
|
250 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
251 | - $enabled_gateway = 'manual'; |
|
252 | - } else { |
|
253 | - $enabled_gateway = wpinv_get_default_gateway(); |
|
254 | - } |
|
248 | + if ( ! empty ( $chosen ) ) { |
|
249 | + $enabled_gateway = urldecode( $chosen ); |
|
250 | + } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
251 | + $enabled_gateway = 'manual'; |
|
252 | + } else { |
|
253 | + $enabled_gateway = wpinv_get_default_gateway(); |
|
254 | + } |
|
255 | 255 | |
256 | 256 | if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
257 | 257 | if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | } |
264 | 264 | |
265 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
265 | + return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | function wpinv_record_gateway_error( $title = '', $message = '' ) { |
@@ -270,21 +270,21 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
273 | - $ret = 0; |
|
274 | - $args = array( |
|
275 | - 'meta_key' => '_wpinv_gateway', |
|
276 | - 'meta_value' => $gateway_id, |
|
277 | - 'nopaging' => true, |
|
278 | - 'post_type' => 'wpi_invoice', |
|
279 | - 'post_status' => $status, |
|
280 | - 'fields' => 'ids' |
|
281 | - ); |
|
282 | - |
|
283 | - $payments = new WP_Query( $args ); |
|
284 | - |
|
285 | - if( $payments ) |
|
286 | - $ret = $payments->post_count; |
|
287 | - return $ret; |
|
273 | + $ret = 0; |
|
274 | + $args = array( |
|
275 | + 'meta_key' => '_wpinv_gateway', |
|
276 | + 'meta_value' => $gateway_id, |
|
277 | + 'nopaging' => true, |
|
278 | + 'post_type' => 'wpi_invoice', |
|
279 | + 'post_status' => $status, |
|
280 | + 'fields' => 'ids' |
|
281 | + ); |
|
282 | + |
|
283 | + $payments = new WP_Query( $args ); |
|
284 | + |
|
285 | + if( $payments ) |
|
286 | + $ret = $payments->post_count; |
|
287 | + return $ret; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | function wpinv_settings_update_gateways( $input ) { |
@@ -13,94 +13,94 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
90 | 90 | |
91 | 91 | parent::__construct(); |
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | - * Process Payment. |
|
96 | - * |
|
97 | - * |
|
98 | - * @param WPInv_Invoice $invoice Invoice. |
|
99 | - * @param array $submission_data Posted checkout fields. |
|
100 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
95 | + * Process Payment. |
|
96 | + * |
|
97 | + * |
|
98 | + * @param WPInv_Invoice $invoice Invoice. |
|
99 | + * @param array $submission_data Posted checkout fields. |
|
100 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | 106 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * Get the PayPal request URL for an invoice. |
|
127 | - * |
|
128 | - * @param WPInv_Invoice $invoice Invoice object. |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function get_request_url( $invoice ) { |
|
126 | + * Get the PayPal request URL for an invoice. |
|
127 | + * |
|
128 | + * @param WPInv_Invoice $invoice Invoice object. |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function get_request_url( $invoice ) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | 137 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -144,44 +144,44 @@ discard block |
||
144 | 144 | |
145 | 145 | return add_query_arg( $paypal_args, $this->endpoint ); |
146 | 146 | |
147 | - } |
|
147 | + } |
|
148 | 148 | |
149 | 149 | /** |
150 | - * Get PayPal Args for passing to PP. |
|
151 | - * |
|
152 | - * @param WPInv_Invoice $invoice Invoice object. |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - protected function get_paypal_args( $invoice ) { |
|
150 | + * Get PayPal Args for passing to PP. |
|
151 | + * |
|
152 | + * @param WPInv_Invoice $invoice Invoice object. |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + protected function get_paypal_args( $invoice ) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | - |
|
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | - $force_one_line_item = true; |
|
162 | - } |
|
163 | - |
|
164 | - $paypal_args = apply_filters( |
|
165 | - 'getpaid_paypal_args', |
|
166 | - array_merge( |
|
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | - ), |
|
170 | - $invoice |
|
171 | - ); |
|
172 | - |
|
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
158 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | + |
|
160 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | + $force_one_line_item = true; |
|
162 | + } |
|
163 | + |
|
164 | + $paypal_args = apply_filters( |
|
165 | + 'getpaid_paypal_args', |
|
166 | + array_merge( |
|
167 | + $this->get_transaction_args( $invoice ), |
|
168 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | + ), |
|
170 | + $invoice |
|
171 | + ); |
|
172 | + |
|
173 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Get transaction args for paypal request. |
|
178 | - * |
|
179 | - * @param WPInv_Invoice $invoice Invoice object. |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - protected function get_transaction_args( $invoice ) { |
|
183 | - |
|
184 | - return array( |
|
177 | + * Get transaction args for paypal request. |
|
178 | + * |
|
179 | + * @param WPInv_Invoice $invoice Invoice object. |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + protected function get_transaction_args( $invoice ) { |
|
183 | + |
|
184 | + return array( |
|
185 | 185 | 'cmd' => '_cart', |
186 | 186 | 'business' => wpinv_get_option( 'paypal_email', false ), |
187 | 187 | 'no_shipping' => '1', |
@@ -206,16 +206,16 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
209 | - * Get line item args for paypal request. |
|
210 | - * |
|
211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
212 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
209 | + * Get line item args for paypal request. |
|
210 | + * |
|
211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
212 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
218 | + if ( $force_one_line_item ) { |
|
219 | 219 | return $this->get_line_item_args_single_item( $invoice ); |
220 | 220 | } |
221 | 221 | |
@@ -235,129 +235,129 @@ discard block |
||
235 | 235 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Get line item args for paypal request as a single line item. |
|
244 | - * |
|
245 | - * @param WPInv_Invoice $invoice Invoice object. |
|
246 | - * @return array |
|
247 | - */ |
|
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
249 | - $this->delete_line_items(); |
|
243 | + * Get line item args for paypal request as a single line item. |
|
244 | + * |
|
245 | + * @param WPInv_Invoice $invoice Invoice object. |
|
246 | + * @return array |
|
247 | + */ |
|
248 | + protected function get_line_item_args_single_item( $invoice ) { |
|
249 | + $this->delete_line_items(); |
|
250 | 250 | |
251 | 251 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
252 | + $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
253 | 253 | |
254 | - return $this->get_line_items(); |
|
254 | + return $this->get_line_items(); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
258 | - * Return all line items. |
|
259 | - */ |
|
260 | - protected function get_line_items() { |
|
261 | - return $this->line_items; |
|
262 | - } |
|
258 | + * Return all line items. |
|
259 | + */ |
|
260 | + protected function get_line_items() { |
|
261 | + return $this->line_items; |
|
262 | + } |
|
263 | 263 | |
264 | 264 | /** |
265 | - * Remove all line items. |
|
266 | - */ |
|
267 | - protected function delete_line_items() { |
|
268 | - $this->line_items = array(); |
|
265 | + * Remove all line items. |
|
266 | + */ |
|
267 | + protected function delete_line_items() { |
|
268 | + $this->line_items = array(); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | - * Prepare line items to send to paypal. |
|
273 | - * |
|
274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
275 | - */ |
|
276 | - protected function prepare_line_items( $invoice ) { |
|
277 | - $this->delete_line_items(); |
|
278 | - |
|
279 | - // Items. |
|
280 | - foreach ( $invoice->get_items() as $item ) { |
|
281 | - $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
282 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
272 | + * Prepare line items to send to paypal. |
|
273 | + * |
|
274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
275 | + */ |
|
276 | + protected function prepare_line_items( $invoice ) { |
|
277 | + $this->delete_line_items(); |
|
278 | + |
|
279 | + // Items. |
|
280 | + foreach ( $invoice->get_items() as $item ) { |
|
281 | + $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
282 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
287 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | 288 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | - * Add PayPal Line Item. |
|
295 | - * |
|
296 | - * @param string $item_name Item name. |
|
297 | - * @param int $quantity Item quantity. |
|
298 | - * @param float $amount Amount. |
|
299 | - * @param string $item_number Item number. |
|
300 | - */ |
|
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | - |
|
304 | - $item = apply_filters( |
|
305 | - 'getpaid_paypal_line_item', |
|
306 | - array( |
|
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | - 'quantity' => (int) $quantity, |
|
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | - 'item_number' => $item_number, |
|
311 | - ), |
|
312 | - $item_name, |
|
313 | - $quantity, |
|
314 | - $amount, |
|
315 | - $item_number |
|
316 | - ); |
|
317 | - |
|
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
294 | + * Add PayPal Line Item. |
|
295 | + * |
|
296 | + * @param string $item_name Item name. |
|
297 | + * @param int $quantity Item quantity. |
|
298 | + * @param float $amount Amount. |
|
299 | + * @param string $item_number Item number. |
|
300 | + */ |
|
301 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | + |
|
304 | + $item = apply_filters( |
|
305 | + 'getpaid_paypal_line_item', |
|
306 | + array( |
|
307 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | + 'quantity' => (int) $quantity, |
|
309 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | + 'item_number' => $item_number, |
|
311 | + ), |
|
312 | + $item_name, |
|
313 | + $quantity, |
|
314 | + $amount, |
|
315 | + $item_number |
|
316 | + ); |
|
317 | + |
|
318 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | 319 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
327 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | - * |
|
329 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | - * |
|
331 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | - * @return array |
|
334 | - */ |
|
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | - $max_paypal_length = 2083; |
|
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | - |
|
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | - return $paypal_args; |
|
341 | - } |
|
342 | - |
|
343 | - return apply_filters( |
|
344 | - 'getpaid_paypal_args', |
|
345 | - array_merge( |
|
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
348 | - ), |
|
349 | - $invoice |
|
350 | - ); |
|
327 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | + * |
|
329 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | + * |
|
331 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | + * @return array |
|
334 | + */ |
|
335 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | + $max_paypal_length = 2083; |
|
337 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | + |
|
339 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | + return $paypal_args; |
|
341 | + } |
|
342 | + |
|
343 | + return apply_filters( |
|
344 | + 'getpaid_paypal_args', |
|
345 | + array_merge( |
|
346 | + $this->get_transaction_args( $invoice ), |
|
347 | + $this->get_line_item_args( $invoice, true ) |
|
348 | + ), |
|
349 | + $invoice |
|
350 | + ); |
|
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
355 | - * Processes recurring invoices. |
|
356 | - * |
|
357 | - * @param array $paypal_args PayPal args. |
|
358 | - * @param WPInv_Invoice $invoice Invoice object. |
|
359 | - */ |
|
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
355 | + * Processes recurring invoices. |
|
356 | + * |
|
357 | + * @param array $paypal_args PayPal args. |
|
358 | + * @param WPInv_Invoice $invoice Invoice object. |
|
359 | + */ |
|
360 | + public function process_subscription( $paypal_args, $invoice ) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | 363 | if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
385 | - // Trial period length. |
|
386 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
385 | + // Trial period length. |
|
386 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
387 | 387 | |
388 | - // Trial period. |
|
389 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
388 | + // Trial period. |
|
389 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
390 | 390 | |
391 | 391 | } else if ( $initial_amount != $recurring_amount ) { |
392 | 392 | |
@@ -409,40 +409,40 @@ discard block |
||
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
413 | 413 | |
414 | - // Subscription price |
|
415 | - $paypal_args['a3'] = $recurring_amount; |
|
414 | + // Subscription price |
|
415 | + $paypal_args['a3'] = $recurring_amount; |
|
416 | 416 | |
417 | - // Subscription duration |
|
418 | - $paypal_args['p3'] = $interval; |
|
417 | + // Subscription duration |
|
418 | + $paypal_args['p3'] = $interval; |
|
419 | 419 | |
420 | - // Subscription period |
|
421 | - $paypal_args['t3'] = $period; |
|
420 | + // Subscription period |
|
421 | + $paypal_args['t3'] = $period; |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
427 | 427 | |
428 | - // Non-recurring payments |
|
429 | - $paypal_args['src'] = 0; |
|
428 | + // Non-recurring payments |
|
429 | + $paypal_args['src'] = 0; |
|
430 | 430 | |
431 | - } else { |
|
431 | + } else { |
|
432 | 432 | |
433 | - $paypal_args['src'] = 1; |
|
433 | + $paypal_args['src'] = 1; |
|
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ( $bill_times > 0 ) { |
|
436 | 436 | |
437 | - // An initial period is being used to charge a sign-up fee |
|
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | - $bill_times--; |
|
440 | - } |
|
437 | + // An initial period is being used to charge a sign-up fee |
|
438 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | + $bill_times--; |
|
440 | + } |
|
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | 443 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
444 | 444 | |
445 | - } |
|
445 | + } |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | // Force return URL so that order description & instructions display |
@@ -458,19 +458,19 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | return apply_filters( |
461 | - 'getpaid_paypal_subscription_args', |
|
462 | - $paypal_args, |
|
463 | - $invoice |
|
461 | + 'getpaid_paypal_subscription_args', |
|
462 | + $paypal_args, |
|
463 | + $invoice |
|
464 | 464 | ); |
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
469 | - * Processes ipns and marks payments as complete. |
|
470 | - * |
|
471 | - * @return void |
|
472 | - */ |
|
473 | - public function verify_ipn() { |
|
469 | + * Processes ipns and marks payments as complete. |
|
470 | + * |
|
471 | + * @return void |
|
472 | + */ |
|
473 | + public function verify_ipn() { |
|
474 | 474 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
475 | 475 | } |
476 | 476 | |
@@ -480,10 +480,10 @@ discard block |
||
480 | 480 | public function sandbox_notice() { |
481 | 481 | |
482 | 482 | return sprintf( |
483 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
484 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
485 | - '</a>' |
|
486 | - ); |
|
483 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
484 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
485 | + '</a>' |
|
486 | + ); |
|
487 | 487 | |
488 | 488 | } |
489 | 489 |
@@ -229,7 +229,7 @@ |
||
229 | 229 | */ |
230 | 230 | function wpinv_send_back_to_checkout() { |
231 | 231 | |
232 | - // Do we have any errors? |
|
232 | + // Do we have any errors? |
|
233 | 233 | if ( wpinv_get_errors() ) { |
234 | 234 | wp_send_json_error( getpaid_get_errors_html( true, false ) ); |
235 | 235 | } |
@@ -12,431 +12,431 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 500 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
68 | - |
|
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN' ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Retrieves IPN Invoice. |
|
82 | - * |
|
83 | - * @param array $posted |
|
84 | - * @return WPInv_Invoice |
|
85 | - */ |
|
86 | - protected function get_ipn_invoice( $posted ) { |
|
87 | - |
|
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
89 | - |
|
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | - |
|
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
95 | - return $invoice; |
|
96 | - } |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Check PayPal IPN validity. |
|
106 | - */ |
|
107 | - protected function validate_ipn() { |
|
108 | - |
|
109 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
110 | - |
|
111 | - // Retrieve the associated invoice. |
|
112 | - $posted = wp_unslash( $_POST ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | - |
|
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
117 | - } |
|
118 | - |
|
119 | - // Validate the IPN. |
|
120 | - $posted['cmd'] = '_notify-validate'; |
|
121 | - |
|
122 | - // Send back post vars to paypal. |
|
123 | - $params = array( |
|
124 | - 'body' => $posted, |
|
125 | - 'timeout' => 60, |
|
126 | - 'httpversion' => '1.1', |
|
127 | - 'compress' => false, |
|
128 | - 'decompress' => false, |
|
129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | - ); |
|
131 | - |
|
132 | - // Post back to get a response. |
|
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | - |
|
135 | - // Check to see if the request was valid. |
|
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
138 | - return true; |
|
139 | - } |
|
140 | - |
|
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | - return false; |
|
144 | - } |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_unslash( $_POST ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 500 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
68 | + |
|
69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | + wpinv_error_log( 'Done processing IPN' ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Retrieves IPN Invoice. |
|
82 | + * |
|
83 | + * @param array $posted |
|
84 | + * @return WPInv_Invoice |
|
85 | + */ |
|
86 | + protected function get_ipn_invoice( $posted ) { |
|
87 | + |
|
88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
89 | + |
|
90 | + if ( ! empty( $posted['custom'] ) ) { |
|
91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | + |
|
93 | + if ( $invoice->exists() ) { |
|
94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
101 | + wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Check PayPal IPN validity. |
|
106 | + */ |
|
107 | + protected function validate_ipn() { |
|
108 | + |
|
109 | + wpinv_error_log( 'Validating PayPal IPN response' ); |
|
110 | + |
|
111 | + // Retrieve the associated invoice. |
|
112 | + $posted = wp_unslash( $_POST ); |
|
113 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
114 | + |
|
115 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
117 | + } |
|
118 | + |
|
119 | + // Validate the IPN. |
|
120 | + $posted['cmd'] = '_notify-validate'; |
|
121 | + |
|
122 | + // Send back post vars to paypal. |
|
123 | + $params = array( |
|
124 | + 'body' => $posted, |
|
125 | + 'timeout' => 60, |
|
126 | + 'httpversion' => '1.1', |
|
127 | + 'compress' => false, |
|
128 | + 'decompress' => false, |
|
129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | + ); |
|
131 | + |
|
132 | + // Post back to get a response. |
|
133 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | + |
|
135 | + // Check to see if the request was valid. |
|
136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | + wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
138 | + return true; |
|
139 | + } |
|
140 | + |
|
141 | + if ( is_wp_error( $response ) ) { |
|
142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | + return false; |
|
144 | + } |
|
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | - return false; |
|
148 | - |
|
149 | - } |
|
146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | + return false; |
|
148 | + |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Check currency from IPN matches the invoice. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @param string $currency currency to validate. |
|
156 | - */ |
|
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
151 | + /** |
|
152 | + * Check currency from IPN matches the invoice. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @param string $currency currency to validate. |
|
156 | + */ |
|
157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
160 | 160 | |
161 | - /* translators: %s: currency code. */ |
|
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + /* translators: %s: currency code. */ |
|
162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | - } |
|
164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | + } |
|
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
168 | - } |
|
167 | + wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Check payment amount from IPN matches the invoice. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
174 | - * @param float $amount amount to validate. |
|
175 | - */ |
|
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
170 | + /** |
|
171 | + * Check payment amount from IPN matches the invoice. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
174 | + * @param float $amount amount to validate. |
|
175 | + */ |
|
176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
178 | 178 | |
179 | - /* translators: %s: Amount. */ |
|
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + /* translators: %s: Amount. */ |
|
180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | - } |
|
182 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | + } |
|
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
186 | - } |
|
185 | + wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Verify receiver email from PayPal. |
|
190 | - * |
|
191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
192 | - * @param string $receiver_email Email to validate. |
|
193 | - */ |
|
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
188 | + /** |
|
189 | + * Verify receiver email from PayPal. |
|
190 | + * |
|
191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
192 | + * @param string $receiver_email Email to validate. |
|
193 | + */ |
|
194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
199 | 199 | |
200 | - /* translators: %s: email address . */ |
|
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + /* translators: %s: email address . */ |
|
201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | - } |
|
203 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | + } |
|
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email' ); |
|
207 | - } |
|
206 | + wpinv_error_log( 'Validated PayPal Email' ); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Handles one time payments. |
|
211 | - * |
|
212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
213 | - * @param array $posted Posted data. |
|
214 | - */ |
|
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
216 | - |
|
217 | - // Collect payment details |
|
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
220 | - |
|
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
223 | - |
|
224 | - // Update the transaction id. |
|
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | - $invoice->save(); |
|
228 | - } |
|
209 | + /** |
|
210 | + * Handles one time payments. |
|
211 | + * |
|
212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
213 | + * @param array $posted Posted data. |
|
214 | + */ |
|
215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
216 | + |
|
217 | + // Collect payment details |
|
218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
220 | + |
|
221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
223 | + |
|
224 | + // Update the transaction id. |
|
225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | + $invoice->save(); |
|
228 | + } |
|
229 | 229 | |
230 | - // Process a refund. |
|
231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
230 | + // Process a refund. |
|
231 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | 232 | |
233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
233 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | 234 | |
235 | - if ( ! $invoice->is_refunded() ) { |
|
236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
237 | - } |
|
235 | + if ( ! $invoice->is_refunded() ) { |
|
236 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
237 | + } |
|
238 | 238 | |
239 | - return wpinv_error_log( $posted['reason_code'] ); |
|
240 | - } |
|
239 | + return wpinv_error_log( $posted['reason_code'] ); |
|
240 | + } |
|
241 | 241 | |
242 | - // Process payments. |
|
243 | - if ( $payment_status == 'completed' ) { |
|
242 | + // Process payments. |
|
243 | + if ( $payment_status == 'completed' ) { |
|
244 | 244 | |
245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
247 | - } |
|
245 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
247 | + } |
|
248 | 248 | |
249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
249 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | 250 | |
251 | - $note = ''; |
|
252 | - |
|
253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
255 | - } |
|
251 | + $note = ''; |
|
252 | + |
|
253 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | + $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
255 | + } |
|
256 | 256 | |
257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
259 | - } |
|
257 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | + $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
259 | + } |
|
260 | 260 | |
261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | - return wpinv_error_log( 'Invoice marked as paid.' ); |
|
261 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | + return wpinv_error_log( 'Invoice marked as paid.' ); |
|
263 | 263 | |
264 | - } |
|
264 | + } |
|
265 | 265 | |
266 | - // Pending payments. |
|
267 | - if ( $payment_status == 'pending' ) { |
|
266 | + // Pending payments. |
|
267 | + if ( $payment_status == 'pending' ) { |
|
268 | 268 | |
269 | - /* translators: %s: pending reason. */ |
|
270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
269 | + /* translators: %s: pending reason. */ |
|
270 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | 271 | |
272 | - return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
273 | - } |
|
272 | + return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
273 | + } |
|
274 | 274 | |
275 | - /* translators: %s: payment status. */ |
|
276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
275 | + /* translators: %s: payment status. */ |
|
276 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | 277 | |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * Handles one time payments. |
|
282 | - * |
|
283 | - * @param WPInv_Invoice $invoice Invoice object. |
|
284 | - * @param array $posted Posted data. |
|
285 | - */ |
|
286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
288 | - } |
|
280 | + /** |
|
281 | + * Handles one time payments. |
|
282 | + * |
|
283 | + * @param WPInv_Invoice $invoice Invoice object. |
|
284 | + * @param array $posted Posted data. |
|
285 | + */ |
|
286 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
288 | + } |
|
289 | 289 | |
290 | - /** |
|
291 | - * Handles subscription sign ups. |
|
292 | - * |
|
293 | - * @param WPInv_Invoice $invoice Invoice object. |
|
294 | - * @param array $posted Posted data. |
|
295 | - */ |
|
296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
290 | + /** |
|
291 | + * Handles subscription sign ups. |
|
292 | + * |
|
293 | + * @param WPInv_Invoice $invoice Invoice object. |
|
294 | + * @param array $posted Posted data. |
|
295 | + */ |
|
296 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
297 | 297 | |
298 | - wpinv_error_log( 'Processing subscription signup' ); |
|
298 | + wpinv_error_log( 'Processing subscription signup' ); |
|
299 | 299 | |
300 | - // Make sure the invoice has a subscription. |
|
301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
300 | + // Make sure the invoice has a subscription. |
|
301 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | 302 | |
303 | - if ( empty( $subscription ) ) { |
|
304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
305 | - } |
|
303 | + if ( empty( $subscription ) ) { |
|
304 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
305 | + } |
|
306 | 306 | |
307 | - // Validate the IPN. |
|
308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
307 | + // Validate the IPN. |
|
308 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
309 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
310 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | 311 | |
312 | - // Activate the subscription. |
|
313 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
314 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
315 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
316 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
317 | - $subscription->activate(); |
|
312 | + // Activate the subscription. |
|
313 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
314 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
315 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
316 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
317 | + $subscription->activate(); |
|
318 | 318 | |
319 | - // Set the transaction id. |
|
320 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
321 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
322 | - } |
|
319 | + // Set the transaction id. |
|
320 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
321 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
322 | + } |
|
323 | 323 | |
324 | - // Update the payment status. |
|
325 | - $invoice->mark_paid(); |
|
324 | + // Update the payment status. |
|
325 | + $invoice->mark_paid(); |
|
326 | 326 | |
327 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
327 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
328 | 328 | |
329 | - wpinv_error_log( 'Subscription started.' ); |
|
330 | - } |
|
329 | + wpinv_error_log( 'Subscription started.' ); |
|
330 | + } |
|
331 | 331 | |
332 | - /** |
|
333 | - * Handles subscription renewals. |
|
334 | - * |
|
335 | - * @param WPInv_Invoice $invoice Invoice object. |
|
336 | - * @param array $posted Posted data. |
|
337 | - */ |
|
338 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
332 | + /** |
|
333 | + * Handles subscription renewals. |
|
334 | + * |
|
335 | + * @param WPInv_Invoice $invoice Invoice object. |
|
336 | + * @param array $posted Posted data. |
|
337 | + */ |
|
338 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
339 | 339 | |
340 | - // Make sure the invoice has a subscription. |
|
341 | - $subscription = wpinv_get_subscription( $invoice ); |
|
340 | + // Make sure the invoice has a subscription. |
|
341 | + $subscription = wpinv_get_subscription( $invoice ); |
|
342 | 342 | |
343 | - if ( empty( $subscription ) ) { |
|
344 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
345 | - } |
|
343 | + if ( empty( $subscription ) ) { |
|
344 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
345 | + } |
|
346 | 346 | |
347 | - // Abort if this is the first payment. |
|
348 | - if ( date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
349 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
350 | - $invoice->save(); |
|
351 | - return; |
|
352 | - } |
|
353 | - |
|
354 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
347 | + // Abort if this is the first payment. |
|
348 | + if ( date( 'Ynd', $subscription->get_time_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
349 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
350 | + $invoice->save(); |
|
351 | + return; |
|
352 | + } |
|
353 | + |
|
354 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
355 | 355 | |
356 | - // Abort if the payment is already recorded. |
|
357 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
358 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
359 | - } |
|
356 | + // Abort if the payment is already recorded. |
|
357 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
358 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
359 | + } |
|
360 | 360 | |
361 | - $args = array( |
|
362 | - 'transaction_id' => $posted['txn_id'], |
|
363 | - 'gateway' => $this->id, |
|
364 | - ); |
|
365 | - |
|
366 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
367 | - |
|
368 | - if ( empty( $invoice ) ) { |
|
369 | - return; |
|
370 | - } |
|
371 | - |
|
372 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
373 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
374 | - |
|
375 | - $subscription->renew(); |
|
376 | - wpinv_error_log( 'Subscription renewed.' ); |
|
377 | - |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Handles subscription cancelations. |
|
382 | - * |
|
383 | - * @param WPInv_Invoice $invoice Invoice object. |
|
384 | - */ |
|
385 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
386 | - |
|
387 | - // Make sure the invoice has a subscription. |
|
388 | - $subscription = wpinv_get_subscription( $invoice ); |
|
389 | - |
|
390 | - if ( empty( $subscription ) ) { |
|
391 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
392 | - } |
|
393 | - |
|
394 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
395 | - $subscription->cancel(); |
|
396 | - wpinv_error_log( 'Subscription cancelled.' ); |
|
361 | + $args = array( |
|
362 | + 'transaction_id' => $posted['txn_id'], |
|
363 | + 'gateway' => $this->id, |
|
364 | + ); |
|
365 | + |
|
366 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
367 | + |
|
368 | + if ( empty( $invoice ) ) { |
|
369 | + return; |
|
370 | + } |
|
371 | + |
|
372 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
373 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
374 | + |
|
375 | + $subscription->renew(); |
|
376 | + wpinv_error_log( 'Subscription renewed.' ); |
|
377 | + |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Handles subscription cancelations. |
|
382 | + * |
|
383 | + * @param WPInv_Invoice $invoice Invoice object. |
|
384 | + */ |
|
385 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
386 | + |
|
387 | + // Make sure the invoice has a subscription. |
|
388 | + $subscription = wpinv_get_subscription( $invoice ); |
|
389 | + |
|
390 | + if ( empty( $subscription ) ) { |
|
391 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
392 | + } |
|
393 | + |
|
394 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
395 | + $subscription->cancel(); |
|
396 | + wpinv_error_log( 'Subscription cancelled.' ); |
|
397 | 397 | |
398 | - } |
|
398 | + } |
|
399 | 399 | |
400 | - /** |
|
401 | - * Handles subscription completions. |
|
402 | - * |
|
403 | - * @param WPInv_Invoice $invoice Invoice object. |
|
404 | - * @param array $posted Posted data. |
|
405 | - */ |
|
406 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
407 | - |
|
408 | - // Make sure the invoice has a subscription. |
|
409 | - $subscription = wpinv_get_subscription( $invoice ); |
|
400 | + /** |
|
401 | + * Handles subscription completions. |
|
402 | + * |
|
403 | + * @param WPInv_Invoice $invoice Invoice object. |
|
404 | + * @param array $posted Posted data. |
|
405 | + */ |
|
406 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
407 | + |
|
408 | + // Make sure the invoice has a subscription. |
|
409 | + $subscription = wpinv_get_subscription( $invoice ); |
|
410 | 410 | |
411 | - if ( empty( $subscription ) ) { |
|
412 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
413 | - } |
|
411 | + if ( empty( $subscription ) ) { |
|
412 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
413 | + } |
|
414 | 414 | |
415 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
416 | - $subscription->complete(); |
|
417 | - wpinv_error_log( 'Subscription completed.' ); |
|
415 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
416 | + $subscription->complete(); |
|
417 | + wpinv_error_log( 'Subscription completed.' ); |
|
418 | 418 | |
419 | - } |
|
419 | + } |
|
420 | 420 | |
421 | - /** |
|
422 | - * Handles subscription fails. |
|
423 | - * |
|
424 | - * @param WPInv_Invoice $invoice Invoice object. |
|
425 | - * @param array $posted Posted data. |
|
426 | - */ |
|
427 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
421 | + /** |
|
422 | + * Handles subscription fails. |
|
423 | + * |
|
424 | + * @param WPInv_Invoice $invoice Invoice object. |
|
425 | + * @param array $posted Posted data. |
|
426 | + */ |
|
427 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
428 | 428 | |
429 | - // Make sure the invoice has a subscription. |
|
430 | - $subscription = wpinv_get_subscription( $invoice ); |
|
429 | + // Make sure the invoice has a subscription. |
|
430 | + $subscription = wpinv_get_subscription( $invoice ); |
|
431 | 431 | |
432 | - if ( empty( $subscription ) ) { |
|
433 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
434 | - } |
|
432 | + if ( empty( $subscription ) ) { |
|
433 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
434 | + } |
|
435 | 435 | |
436 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
437 | - $subscription->failing(); |
|
438 | - wpinv_error_log( 'Subscription marked as failing.' ); |
|
436 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
437 | + $subscription->failing(); |
|
438 | + wpinv_error_log( 'Subscription marked as failing.' ); |
|
439 | 439 | |
440 | - } |
|
440 | + } |
|
441 | 441 | |
442 | 442 | } |
@@ -43,64 +43,64 @@ 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 = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
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 = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
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 'item': |
|
83 | - $item = get_post( $subscription->get_product_id() ); |
|
82 | + case 'item': |
|
83 | + $item = get_post( $subscription->get_product_id() ); |
|
84 | 84 | |
85 | - if ( ! empty( $item ) ) { |
|
86 | - echo esc_html( get_the_title( $item ) ); |
|
87 | - } else { |
|
88 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
89 | - } |
|
85 | + if ( ! empty( $item ) ) { |
|
86 | + echo esc_html( get_the_title( $item ) ); |
|
87 | + } else { |
|
88 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
89 | + } |
|
90 | 90 | |
91 | - break; |
|
91 | + break; |
|
92 | 92 | |
93 | - case 'payments': |
|
93 | + case 'payments': |
|
94 | 94 | |
95 | - $max_activations = (int) $subscription->get_bill_times(); |
|
96 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
95 | + $max_activations = (int) $subscription->get_bill_times(); |
|
96 | + echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
97 | 97 | |
98 | - break; |
|
98 | + break; |
|
99 | 99 | |
100 | - } |
|
101 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
100 | + } |
|
101 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
102 | 102 | |
103 | - ?> |
|
103 | + ?> |
|
104 | 104 | </td> |
105 | 105 | |
106 | 106 | </tr> |
@@ -117,17 +117,17 @@ discard block |
||
117 | 117 | <span class="form-text"> |
118 | 118 | |
119 | 119 | <?php |
120 | - if ( $subscription->can_cancel() ) { |
|
121 | - printf( |
|
122 | - '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
123 | - esc_url( $subscription->get_cancel_url() ), |
|
124 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
125 | - __( 'Cancel Subscription', 'invoicing' ) |
|
126 | - ); |
|
127 | - } |
|
128 | - |
|
129 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
130 | - ?> |
|
120 | + if ( $subscription->can_cancel() ) { |
|
121 | + printf( |
|
122 | + '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
123 | + esc_url( $subscription->get_cancel_url() ), |
|
124 | + esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
125 | + __( 'Cancel Subscription', 'invoicing' ) |
|
126 | + ); |
|
127 | + } |
|
128 | + |
|
129 | + do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
130 | + ?> |
|
131 | 131 | |
132 | 132 | <a href="<?php echo esc_url( get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a> |
133 | 133 | </span> |
134 | 134 | \ No newline at end of file |
@@ -19,16 +19,16 @@ discard block |
||
19 | 19 | |
20 | 20 | // Define constants. |
21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
26 | - define( 'WPINV_VERSION', '1.1.0' ); |
|
26 | + define( 'WPINV_VERSION', '1.1.0' ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 | |
46 | - return $GLOBALS['invoicing']; |
|
46 | + return $GLOBALS['invoicing']; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |