@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | class GetPaid_Manual_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 = 'manual'; |
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', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - public $order = 11; |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + public $order = 11; |
|
35 | 35 | |
36 | 36 | /** |
37 | - * Class constructor. |
|
38 | - */ |
|
39 | - public function __construct() { |
|
37 | + * Class constructor. |
|
38 | + */ |
|
39 | + public function __construct() { |
|
40 | 40 | parent::__construct(); |
41 | 41 | |
42 | 42 | $this->title = __( 'Test Gateway', 'invoicing' ); |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Process Payment. |
|
50 | - * |
|
51 | - * |
|
52 | - * @param WPInv_Invoice $invoice Invoice. |
|
53 | - * @param array $submission_data Posted checkout fields. |
|
54 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
49 | + * Process Payment. |
|
50 | + * |
|
51 | + * |
|
52 | + * @param WPInv_Invoice $invoice Invoice. |
|
53 | + * @param array $submission_data Posted checkout fields. |
|
54 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
58 | 58 | |
59 | 59 | // Mark it as paid. |
60 | 60 | $invoice->mark_paid(); |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * (Maybe) renews a manual subscription profile. |
|
89 | - * |
|
90 | - * |
|
91 | - * @param bool $should_expire |
|
88 | + * (Maybe) renews a manual subscription profile. |
|
89 | + * |
|
90 | + * |
|
91 | + * @param bool $should_expire |
|
92 | 92 | * @param WPInv_Subscription $subscription |
93 | - */ |
|
94 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
93 | + */ |
|
94 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
95 | 95 | |
96 | 96 | // Ensure its our subscription && it's active. |
97 | 97 | if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
122 | - * Processes invoice addons. |
|
123 | - * |
|
124 | - * @param WPInv_Invoice $invoice |
|
125 | - * @param GetPaid_Form_Item[] $items |
|
126 | - * @return WPInv_Invoice |
|
127 | - */ |
|
128 | - public function process_addons( $invoice, $items ) { |
|
122 | + * Processes invoice addons. |
|
123 | + * |
|
124 | + * @param WPInv_Invoice $invoice |
|
125 | + * @param GetPaid_Form_Item[] $items |
|
126 | + * @return WPInv_Invoice |
|
127 | + */ |
|
128 | + public function process_addons( $invoice, $items ) { |
|
129 | 129 | |
130 | 130 | foreach ( $items as $item ) { |
131 | 131 | $invoice->add_item( $item ); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
10 | 10 | class WPInv_Item extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'item'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'item'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'item'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Item Data array. This is the core item data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'parent_id' => 0, |
|
34 | - 'status' => 'draft', |
|
35 | - 'version' => '', |
|
36 | - 'date_created' => null, |
|
27 | + * Item Data array. This is the core item data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'parent_id' => 0, |
|
34 | + 'status' => 'draft', |
|
35 | + 'version' => '', |
|
36 | + 'date_created' => null, |
|
37 | 37 | 'date_modified' => null, |
38 | 38 | 'name' => '', |
39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | ); |
59 | 59 | |
60 | 60 | /** |
61 | - * Stores meta in cache for future reads. |
|
62 | - * |
|
63 | - * A group must be set to to enable caching. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - protected $cache_group = 'getpaid_items'; |
|
61 | + * Stores meta in cache for future reads. |
|
62 | + * |
|
63 | + * A group must be set to to enable caching. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + protected $cache_group = 'getpaid_items'; |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
74 | 74 | protected $post = null; |
75 | 75 | |
76 | 76 | /** |
77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | - * |
|
79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | - */ |
|
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
83 | - |
|
84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | - $this->set_id( $item_id ); |
|
92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | - $this->set_id( $item_id ); |
|
94 | - } else { |
|
95 | - $this->set_object_read( true ); |
|
96 | - } |
|
77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | + * |
|
79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | + */ |
|
81 | + public function __construct( $item = 0 ) { |
|
82 | + parent::__construct( $item ); |
|
83 | + |
|
84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | + $this->set_id( $item ); |
|
86 | + } elseif ( $item instanceof self ) { |
|
87 | + $this->set_id( $item->get_id() ); |
|
88 | + } elseif ( ! empty( $item->ID ) ) { |
|
89 | + $this->set_id( $item->ID ); |
|
90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | + $this->set_id( $item_id ); |
|
92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | + $this->set_id( $item_id ); |
|
94 | + } else { |
|
95 | + $this->set_object_read( true ); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | // Load the datastore. |
99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
100 | 100 | |
101 | - if ( $this->get_id() > 0 ) { |
|
101 | + if ( $this->get_id() > 0 ) { |
|
102 | 102 | $this->post = get_post( $this->get_id() ); |
103 | 103 | $this->ID = $this->get_id(); |
104 | - $this->data_store->read( $this ); |
|
104 | + $this->data_store->read( $this ); |
|
105 | 105 | } |
106 | 106 | |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | 109 | /* |
110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,401 +122,401 @@ discard block |
||
122 | 122 | */ |
123 | 123 | |
124 | 124 | /** |
125 | - * Get parent item ID. |
|
126 | - * |
|
127 | - * @since 1.0.19 |
|
128 | - * @param string $context View or edit context. |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function get_parent_id( $context = 'view' ) { |
|
132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
125 | + * Get parent item ID. |
|
126 | + * |
|
127 | + * @since 1.0.19 |
|
128 | + * @param string $context View or edit context. |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function get_parent_id( $context = 'view' ) { |
|
132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Get item status. |
|
137 | - * |
|
138 | - * @since 1.0.19 |
|
139 | - * @param string $context View or edit context. |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function get_status( $context = 'view' ) { |
|
143 | - return $this->get_prop( 'status', $context ); |
|
136 | + * Get item status. |
|
137 | + * |
|
138 | + * @since 1.0.19 |
|
139 | + * @param string $context View or edit context. |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function get_status( $context = 'view' ) { |
|
143 | + return $this->get_prop( 'status', $context ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * Get plugin version when the item was created. |
|
148 | - * |
|
149 | - * @since 1.0.19 |
|
150 | - * @param string $context View or edit context. |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public function get_version( $context = 'view' ) { |
|
154 | - return $this->get_prop( 'version', $context ); |
|
147 | + * Get plugin version when the item was created. |
|
148 | + * |
|
149 | + * @since 1.0.19 |
|
150 | + * @param string $context View or edit context. |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public function get_version( $context = 'view' ) { |
|
154 | + return $this->get_prop( 'version', $context ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | - * Get date when the item was created. |
|
159 | - * |
|
160 | - * @since 1.0.19 |
|
161 | - * @param string $context View or edit context. |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - public function get_date_created( $context = 'view' ) { |
|
165 | - return $this->get_prop( 'date_created', $context ); |
|
158 | + * Get date when the item was created. |
|
159 | + * |
|
160 | + * @since 1.0.19 |
|
161 | + * @param string $context View or edit context. |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + public function get_date_created( $context = 'view' ) { |
|
165 | + return $this->get_prop( 'date_created', $context ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | - * Get GMT date when the item was created. |
|
170 | - * |
|
171 | - * @since 1.0.19 |
|
172 | - * @param string $context View or edit context. |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
169 | + * Get GMT date when the item was created. |
|
170 | + * |
|
171 | + * @since 1.0.19 |
|
172 | + * @param string $context View or edit context. |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
176 | 176 | $date = $this->get_date_created( $context ); |
177 | 177 | |
178 | 178 | if ( $date ) { |
179 | 179 | $date = get_gmt_from_date( $date ); |
180 | 180 | } |
181 | - return $date; |
|
181 | + return $date; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Get date when the item was last modified. |
|
186 | - * |
|
187 | - * @since 1.0.19 |
|
188 | - * @param string $context View or edit context. |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public function get_date_modified( $context = 'view' ) { |
|
192 | - return $this->get_prop( 'date_modified', $context ); |
|
185 | + * Get date when the item was last modified. |
|
186 | + * |
|
187 | + * @since 1.0.19 |
|
188 | + * @param string $context View or edit context. |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public function get_date_modified( $context = 'view' ) { |
|
192 | + return $this->get_prop( 'date_modified', $context ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Get GMT date when the item was last modified. |
|
197 | - * |
|
198 | - * @since 1.0.19 |
|
199 | - * @param string $context View or edit context. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
196 | + * Get GMT date when the item was last modified. |
|
197 | + * |
|
198 | + * @since 1.0.19 |
|
199 | + * @param string $context View or edit context. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
203 | 203 | $date = $this->get_date_modified( $context ); |
204 | 204 | |
205 | 205 | if ( $date ) { |
206 | 206 | $date = get_gmt_from_date( $date ); |
207 | 207 | } |
208 | - return $date; |
|
208 | + return $date; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get the item name. |
|
213 | - * |
|
214 | - * @since 1.0.19 |
|
215 | - * @param string $context View or edit context. |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public function get_name( $context = 'view' ) { |
|
219 | - return $this->get_prop( 'name', $context ); |
|
212 | + * Get the item name. |
|
213 | + * |
|
214 | + * @since 1.0.19 |
|
215 | + * @param string $context View or edit context. |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public function get_name( $context = 'view' ) { |
|
219 | + return $this->get_prop( 'name', $context ); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | - * Alias of self::get_name(). |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @param string $context View or edit context. |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function get_title( $context = 'view' ) { |
|
230 | - return $this->get_name( $context ); |
|
223 | + * Alias of self::get_name(). |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @param string $context View or edit context. |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function get_title( $context = 'view' ) { |
|
230 | + return $this->get_name( $context ); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
234 | - * Get the item description. |
|
235 | - * |
|
236 | - * @since 1.0.19 |
|
237 | - * @param string $context View or edit context. |
|
238 | - * @return string |
|
239 | - */ |
|
240 | - public function get_description( $context = 'view' ) { |
|
241 | - return $this->get_prop( 'description', $context ); |
|
234 | + * Get the item description. |
|
235 | + * |
|
236 | + * @since 1.0.19 |
|
237 | + * @param string $context View or edit context. |
|
238 | + * @return string |
|
239 | + */ |
|
240 | + public function get_description( $context = 'view' ) { |
|
241 | + return $this->get_prop( 'description', $context ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * Alias of self::get_description(). |
|
246 | - * |
|
247 | - * @since 1.0.19 |
|
248 | - * @param string $context View or edit context. |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function get_excerpt( $context = 'view' ) { |
|
252 | - return $this->get_description( $context ); |
|
245 | + * Alias of self::get_description(). |
|
246 | + * |
|
247 | + * @since 1.0.19 |
|
248 | + * @param string $context View or edit context. |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function get_excerpt( $context = 'view' ) { |
|
252 | + return $this->get_description( $context ); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | - * Alias of self::get_description(). |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - * @param string $context View or edit context. |
|
260 | - * @return string |
|
261 | - */ |
|
262 | - public function get_summary( $context = 'view' ) { |
|
263 | - return $this->get_description( $context ); |
|
256 | + * Alias of self::get_description(). |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + * @param string $context View or edit context. |
|
260 | + * @return string |
|
261 | + */ |
|
262 | + public function get_summary( $context = 'view' ) { |
|
263 | + return $this->get_description( $context ); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | - * Get the owner of the item. |
|
268 | - * |
|
269 | - * @since 1.0.19 |
|
270 | - * @param string $context View or edit context. |
|
271 | - * @return int |
|
272 | - */ |
|
273 | - public function get_author( $context = 'view' ) { |
|
274 | - return (int) $this->get_prop( 'author', $context ); |
|
275 | - } |
|
267 | + * Get the owner of the item. |
|
268 | + * |
|
269 | + * @since 1.0.19 |
|
270 | + * @param string $context View or edit context. |
|
271 | + * @return int |
|
272 | + */ |
|
273 | + public function get_author( $context = 'view' ) { |
|
274 | + return (int) $this->get_prop( 'author', $context ); |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Alias of self::get_author(). |
|
279 | - * |
|
280 | - * @since 1.0.19 |
|
281 | - * @param string $context View or edit context. |
|
282 | - * @return int |
|
283 | - */ |
|
284 | - public function get_owner( $context = 'view' ) { |
|
285 | - return $this->get_author( $context ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Get the price of the item. |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @param string $context View or edit context. |
|
293 | - * @return float |
|
294 | - */ |
|
295 | - public function get_price( $context = 'view' ) { |
|
277 | + /** |
|
278 | + * Alias of self::get_author(). |
|
279 | + * |
|
280 | + * @since 1.0.19 |
|
281 | + * @param string $context View or edit context. |
|
282 | + * @return int |
|
283 | + */ |
|
284 | + public function get_owner( $context = 'view' ) { |
|
285 | + return $this->get_author( $context ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Get the price of the item. |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @param string $context View or edit context. |
|
293 | + * @return float |
|
294 | + */ |
|
295 | + public function get_price( $context = 'view' ) { |
|
296 | 296 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
297 | - } |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * Get the inital price of the item. |
|
301 | - * |
|
302 | - * @since 1.0.19 |
|
303 | - * @param string $context View or edit context. |
|
304 | - * @return float |
|
305 | - */ |
|
306 | - public function get_initial_price( $context = 'view' ) { |
|
299 | + /** |
|
300 | + * Get the inital price of the item. |
|
301 | + * |
|
302 | + * @since 1.0.19 |
|
303 | + * @param string $context View or edit context. |
|
304 | + * @return float |
|
305 | + */ |
|
306 | + public function get_initial_price( $context = 'view' ) { |
|
307 | 307 | |
308 | - $price = (float) $this->get_price( $context ); |
|
308 | + $price = (float) $this->get_price( $context ); |
|
309 | 309 | |
310 | - if ( $this->has_free_trial() ) { |
|
311 | - $price = 0; |
|
312 | - } |
|
310 | + if ( $this->has_free_trial() ) { |
|
311 | + $price = 0; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
318 | - * Returns a formated price. |
|
319 | - * |
|
320 | - * @since 1.0.19 |
|
321 | - * @param string $context View or edit context. |
|
322 | - * @return string |
|
323 | - */ |
|
318 | + * Returns a formated price. |
|
319 | + * |
|
320 | + * @since 1.0.19 |
|
321 | + * @param string $context View or edit context. |
|
322 | + * @return string |
|
323 | + */ |
|
324 | 324 | public function get_the_price() { |
325 | 325 | return wpinv_price( $this->get_price() ); |
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Returns the formated initial price. |
|
330 | - * |
|
331 | - * @since 1.0.19 |
|
332 | - * @param string $context View or edit context. |
|
333 | - * @return string |
|
334 | - */ |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Returns the formated initial price. |
|
330 | + * |
|
331 | + * @since 1.0.19 |
|
332 | + * @param string $context View or edit context. |
|
333 | + * @return string |
|
334 | + */ |
|
335 | 335 | public function get_the_initial_price() { |
336 | 336 | return wpinv_price( $this->get_initial_price() ); |
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
340 | - * Get the VAT rule of the item. |
|
341 | - * |
|
342 | - * @since 1.0.19 |
|
343 | - * @param string $context View or edit context. |
|
344 | - * @return string |
|
345 | - */ |
|
346 | - public function get_vat_rule( $context = 'view' ) { |
|
340 | + * Get the VAT rule of the item. |
|
341 | + * |
|
342 | + * @since 1.0.19 |
|
343 | + * @param string $context View or edit context. |
|
344 | + * @return string |
|
345 | + */ |
|
346 | + public function get_vat_rule( $context = 'view' ) { |
|
347 | 347 | return $this->get_prop( 'vat_rule', $context ); |
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
351 | - * Get the VAT class of the item. |
|
352 | - * |
|
353 | - * @since 1.0.19 |
|
354 | - * @param string $context View or edit context. |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function get_vat_class( $context = 'view' ) { |
|
351 | + * Get the VAT class of the item. |
|
352 | + * |
|
353 | + * @since 1.0.19 |
|
354 | + * @param string $context View or edit context. |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function get_vat_class( $context = 'view' ) { |
|
358 | 358 | return $this->get_prop( 'vat_class', $context ); |
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
362 | - * Get the type of the item. |
|
363 | - * |
|
364 | - * @since 1.0.19 |
|
365 | - * @param string $context View or edit context. |
|
366 | - * @return string |
|
367 | - */ |
|
368 | - public function get_type( $context = 'view' ) { |
|
362 | + * Get the type of the item. |
|
363 | + * |
|
364 | + * @since 1.0.19 |
|
365 | + * @param string $context View or edit context. |
|
366 | + * @return string |
|
367 | + */ |
|
368 | + public function get_type( $context = 'view' ) { |
|
369 | 369 | return $this->get_prop( 'type', $context ); |
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
373 | - * Get the custom id of the item. |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * @param string $context View or edit context. |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function get_custom_id( $context = 'view' ) { |
|
373 | + * Get the custom id of the item. |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * @param string $context View or edit context. |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function get_custom_id( $context = 'view' ) { |
|
380 | 380 | return $this->get_prop( 'custom_id', $context ); |
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
384 | - * Get the custom name of the item. |
|
385 | - * |
|
386 | - * @since 1.0.19 |
|
387 | - * @param string $context View or edit context. |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - public function get_custom_name( $context = 'view' ) { |
|
384 | + * Get the custom name of the item. |
|
385 | + * |
|
386 | + * @since 1.0.19 |
|
387 | + * @param string $context View or edit context. |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + public function get_custom_name( $context = 'view' ) { |
|
391 | 391 | return $this->get_prop( 'custom_name', $context ); |
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
395 | - * Get the custom singular name of the item. |
|
396 | - * |
|
397 | - * @since 1.0.19 |
|
398 | - * @param string $context View or edit context. |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
395 | + * Get the custom singular name of the item. |
|
396 | + * |
|
397 | + * @since 1.0.19 |
|
398 | + * @param string $context View or edit context. |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public function get_custom_singular_name( $context = 'view' ) { |
|
402 | 402 | return $this->get_prop( 'custom_singular_name', $context ); |
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
406 | - * Checks if an item is editable.. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @param string $context View or edit context. |
|
410 | - * @return int |
|
411 | - */ |
|
412 | - public function get_is_editable( $context = 'view' ) { |
|
406 | + * Checks if an item is editable.. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @param string $context View or edit context. |
|
410 | + * @return int |
|
411 | + */ |
|
412 | + public function get_is_editable( $context = 'view' ) { |
|
413 | 413 | return (int) $this->get_prop( 'is_editable', $context ); |
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
417 | - * Alias of self::get_is_editable(). |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - * @param string $context View or edit context. |
|
421 | - * @return int |
|
422 | - */ |
|
423 | - public function get_editable( $context = 'view' ) { |
|
424 | - return $this->get_is_editable( $context ); |
|
417 | + * Alias of self::get_is_editable(). |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + * @param string $context View or edit context. |
|
421 | + * @return int |
|
422 | + */ |
|
423 | + public function get_editable( $context = 'view' ) { |
|
424 | + return $this->get_is_editable( $context ); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
428 | - * Checks if dynamic pricing is enabled. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $context View or edit context. |
|
432 | - * @return int |
|
433 | - */ |
|
434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
428 | + * Checks if dynamic pricing is enabled. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $context View or edit context. |
|
432 | + * @return int |
|
433 | + */ |
|
434 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
435 | 435 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
439 | - * Returns the minimum price if dynamic pricing is enabled. |
|
440 | - * |
|
441 | - * @since 1.0.19 |
|
442 | - * @param string $context View or edit context. |
|
443 | - * @return float |
|
444 | - */ |
|
445 | - public function get_minimum_price( $context = 'view' ) { |
|
439 | + * Returns the minimum price if dynamic pricing is enabled. |
|
440 | + * |
|
441 | + * @since 1.0.19 |
|
442 | + * @param string $context View or edit context. |
|
443 | + * @return float |
|
444 | + */ |
|
445 | + public function get_minimum_price( $context = 'view' ) { |
|
446 | 446 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Checks if this is a recurring item. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return int |
|
455 | - */ |
|
456 | - public function get_is_recurring( $context = 'view' ) { |
|
450 | + * Checks if this is a recurring item. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return int |
|
455 | + */ |
|
456 | + public function get_is_recurring( $context = 'view' ) { |
|
457 | 457 | return (int) $this->get_prop( 'is_recurring', $context ); |
458 | - } |
|
458 | + } |
|
459 | 459 | |
460 | - /** |
|
461 | - * Get the recurring price of the item. |
|
462 | - * |
|
463 | - * @since 1.0.19 |
|
464 | - * @param string $context View or edit context. |
|
465 | - * @return float |
|
466 | - */ |
|
467 | - public function get_recurring_price( $context = 'view' ) { |
|
468 | - $price = $this->get_price( $context ); |
|
460 | + /** |
|
461 | + * Get the recurring price of the item. |
|
462 | + * |
|
463 | + * @since 1.0.19 |
|
464 | + * @param string $context View or edit context. |
|
465 | + * @return float |
|
466 | + */ |
|
467 | + public function get_recurring_price( $context = 'view' ) { |
|
468 | + $price = $this->get_price( $context ); |
|
469 | 469 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Get the formatted recurring price of the item. |
|
474 | - * |
|
475 | - * @since 1.0.19 |
|
476 | - * @param string $context View or edit context. |
|
477 | - * @return string |
|
478 | - */ |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Get the formatted recurring price of the item. |
|
474 | + * |
|
475 | + * @since 1.0.19 |
|
476 | + * @param string $context View or edit context. |
|
477 | + * @return string |
|
478 | + */ |
|
479 | 479 | public function get_the_recurring_price() { |
480 | 480 | return wpinv_price( $this->get_recurring_price() ); |
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Get the first renewal date (in timestamps) of the item. |
|
485 | - * |
|
486 | - * @since 1.0.19 |
|
487 | - * @return int |
|
488 | - */ |
|
489 | - public function get_first_renewal_date() { |
|
490 | - |
|
491 | - $periods = array( |
|
492 | - 'D' => 'days', |
|
493 | - 'W' => 'weeks', |
|
494 | - 'M' => 'months', |
|
495 | - 'Y' => 'years', |
|
496 | - ); |
|
497 | - |
|
498 | - $period = $this->get_recurring_period(); |
|
499 | - $interval = $this->get_recurring_interval(); |
|
500 | - |
|
501 | - if ( $this->has_free_trial() ) { |
|
502 | - $period = $this->get_trial_period(); |
|
503 | - $interval = $this->get_trial_interval(); |
|
504 | - } |
|
505 | - |
|
506 | - $period = $periods[ $period ]; |
|
507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Get the first renewal date (in timestamps) of the item. |
|
485 | + * |
|
486 | + * @since 1.0.19 |
|
487 | + * @return int |
|
488 | + */ |
|
489 | + public function get_first_renewal_date() { |
|
490 | + |
|
491 | + $periods = array( |
|
492 | + 'D' => 'days', |
|
493 | + 'W' => 'weeks', |
|
494 | + 'M' => 'months', |
|
495 | + 'Y' => 'years', |
|
496 | + ); |
|
497 | + |
|
498 | + $period = $this->get_recurring_period(); |
|
499 | + $interval = $this->get_recurring_interval(); |
|
500 | + |
|
501 | + if ( $this->has_free_trial() ) { |
|
502 | + $period = $this->get_trial_period(); |
|
503 | + $interval = $this->get_trial_interval(); |
|
504 | + } |
|
505 | + |
|
506 | + $period = $periods[ $period ]; |
|
507 | + $interval = empty( $interval ) ? 1 : $interval; |
|
508 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
509 | 509 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
513 | - * Get the recurring period. |
|
514 | - * |
|
515 | - * @since 1.0.19 |
|
516 | - * @param bool $full Return abbreviation or in full. |
|
517 | - * @return string |
|
518 | - */ |
|
519 | - public function get_recurring_period( $full = false ) { |
|
513 | + * Get the recurring period. |
|
514 | + * |
|
515 | + * @since 1.0.19 |
|
516 | + * @param bool $full Return abbreviation or in full. |
|
517 | + * @return string |
|
518 | + */ |
|
519 | + public function get_recurring_period( $full = false ) { |
|
520 | 520 | $period = $this->get_prop( 'recurring_period', 'view' ); |
521 | 521 | |
522 | 522 | if ( $full && ! is_bool( $full ) ) { |
@@ -527,58 +527,58 @@ discard block |
||
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
530 | - * Get the recurring interval. |
|
531 | - * |
|
532 | - * @since 1.0.19 |
|
533 | - * @param string $context View or edit context. |
|
534 | - * @return int |
|
535 | - */ |
|
536 | - public function get_recurring_interval( $context = 'view' ) { |
|
537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
538 | - return max( 1, $interval ); |
|
530 | + * Get the recurring interval. |
|
531 | + * |
|
532 | + * @since 1.0.19 |
|
533 | + * @param string $context View or edit context. |
|
534 | + * @return int |
|
535 | + */ |
|
536 | + public function get_recurring_interval( $context = 'view' ) { |
|
537 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
538 | + return max( 1, $interval ); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | /** |
542 | - * Get the recurring limit. |
|
543 | - * |
|
544 | - * @since 1.0.19 |
|
545 | - * @param string $context View or edit context. |
|
546 | - * @return int |
|
547 | - */ |
|
548 | - public function get_recurring_limit( $context = 'view' ) { |
|
542 | + * Get the recurring limit. |
|
543 | + * |
|
544 | + * @since 1.0.19 |
|
545 | + * @param string $context View or edit context. |
|
546 | + * @return int |
|
547 | + */ |
|
548 | + public function get_recurring_limit( $context = 'view' ) { |
|
549 | 549 | return (int) $this->get_prop( 'recurring_limit', $context ); |
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
553 | - * Checks if we have a free trial. |
|
554 | - * |
|
555 | - * @since 1.0.19 |
|
556 | - * @param string $context View or edit context. |
|
557 | - * @return int |
|
558 | - */ |
|
559 | - public function get_is_free_trial( $context = 'view' ) { |
|
553 | + * Checks if we have a free trial. |
|
554 | + * |
|
555 | + * @since 1.0.19 |
|
556 | + * @param string $context View or edit context. |
|
557 | + * @return int |
|
558 | + */ |
|
559 | + public function get_is_free_trial( $context = 'view' ) { |
|
560 | 560 | return (int) $this->get_prop( 'is_free_trial', $context ); |
561 | 561 | } |
562 | 562 | |
563 | 563 | /** |
564 | - * Alias for self::get_is_free_trial(). |
|
565 | - * |
|
566 | - * @since 1.0.19 |
|
567 | - * @param string $context View or edit context. |
|
568 | - * @return int |
|
569 | - */ |
|
570 | - public function get_free_trial( $context = 'view' ) { |
|
564 | + * Alias for self::get_is_free_trial(). |
|
565 | + * |
|
566 | + * @since 1.0.19 |
|
567 | + * @param string $context View or edit context. |
|
568 | + * @return int |
|
569 | + */ |
|
570 | + public function get_free_trial( $context = 'view' ) { |
|
571 | 571 | return $this->get_is_free_trial( $context ); |
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
575 | - * Get the trial period. |
|
576 | - * |
|
577 | - * @since 1.0.19 |
|
578 | - * @param bool $full Return abbreviation or in full. |
|
579 | - * @return string |
|
580 | - */ |
|
581 | - public function get_trial_period( $full = false ) { |
|
575 | + * Get the trial period. |
|
576 | + * |
|
577 | + * @since 1.0.19 |
|
578 | + * @param bool $full Return abbreviation or in full. |
|
579 | + * @return string |
|
580 | + */ |
|
581 | + public function get_trial_period( $full = false ) { |
|
582 | 582 | $period = $this->get_prop( 'trial_period', 'view' ); |
583 | 583 | |
584 | 584 | if ( $full && ! is_bool( $full ) ) { |
@@ -589,104 +589,104 @@ discard block |
||
589 | 589 | } |
590 | 590 | |
591 | 591 | /** |
592 | - * Get the trial interval. |
|
593 | - * |
|
594 | - * @since 1.0.19 |
|
595 | - * @param string $context View or edit context. |
|
596 | - * @return int |
|
597 | - */ |
|
598 | - public function get_trial_interval( $context = 'view' ) { |
|
592 | + * Get the trial interval. |
|
593 | + * |
|
594 | + * @since 1.0.19 |
|
595 | + * @param string $context View or edit context. |
|
596 | + * @return int |
|
597 | + */ |
|
598 | + public function get_trial_interval( $context = 'view' ) { |
|
599 | 599 | return (int) $this->get_prop( 'trial_interval', $context ); |
600 | - } |
|
600 | + } |
|
601 | 601 | |
602 | - /** |
|
603 | - * Get the item's edit url. |
|
604 | - * |
|
605 | - * @since 1.0.19 |
|
606 | - * @return string |
|
607 | - */ |
|
608 | - public function get_edit_url() { |
|
602 | + /** |
|
603 | + * Get the item's edit url. |
|
604 | + * |
|
605 | + * @since 1.0.19 |
|
606 | + * @return string |
|
607 | + */ |
|
608 | + public function get_edit_url() { |
|
609 | 609 | return get_edit_post_link( $this->get_id(), 'edit' ); |
610 | - } |
|
611 | - |
|
612 | - /** |
|
613 | - * Given an item's name/custom id, it returns its id. |
|
614 | - * |
|
615 | - * |
|
616 | - * @static |
|
617 | - * @param string $value The item name or custom id. |
|
618 | - * @param string $field Either name or custom_id. |
|
619 | - * @param string $type in case you need to search for a given type. |
|
620 | - * @since 1.0.15 |
|
621 | - * @return int |
|
622 | - */ |
|
623 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
624 | - |
|
625 | - // Trim the value. |
|
626 | - $value = sanitize_text_field( $value ); |
|
627 | - if ( empty( $value ) ) { |
|
628 | - return 0; |
|
629 | - } |
|
610 | + } |
|
611 | + |
|
612 | + /** |
|
613 | + * Given an item's name/custom id, it returns its id. |
|
614 | + * |
|
615 | + * |
|
616 | + * @static |
|
617 | + * @param string $value The item name or custom id. |
|
618 | + * @param string $field Either name or custom_id. |
|
619 | + * @param string $type in case you need to search for a given type. |
|
620 | + * @since 1.0.15 |
|
621 | + * @return int |
|
622 | + */ |
|
623 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
624 | + |
|
625 | + // Trim the value. |
|
626 | + $value = sanitize_text_field( $value ); |
|
627 | + if ( empty( $value ) ) { |
|
628 | + return 0; |
|
629 | + } |
|
630 | 630 | |
631 | 631 | // Valid fields. |
632 | 632 | $fields = array( 'custom_id', 'name', 'slug' ); |
633 | 633 | |
634 | - // Ensure a field has been passed. |
|
635 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
636 | - return 0; |
|
637 | - } |
|
638 | - |
|
639 | - if ( $field == 'name' ) { |
|
640 | - $field = 'slug'; |
|
641 | - } |
|
642 | - |
|
643 | - // Maybe retrieve from the cache. |
|
644 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
645 | - if ( ! empty( $item_id ) ) { |
|
646 | - return $item_id; |
|
647 | - } |
|
648 | - |
|
649 | - // Fetch from the db. |
|
650 | - $items = array(); |
|
651 | - if ( $field == 'slug' ) { |
|
652 | - $items = get_posts( |
|
653 | - array( |
|
654 | - 'post_type' => 'wpi_item', |
|
655 | - 'name' => $value, |
|
656 | - 'posts_per_page' => 1, |
|
657 | - 'post_status' => 'any', |
|
658 | - ) |
|
659 | - ); |
|
660 | - } |
|
661 | - |
|
662 | - if ( $field =='custom_id' ) { |
|
663 | - $items = get_posts( |
|
664 | - array( |
|
665 | - 'post_type' => 'wpi_item', |
|
666 | - 'posts_per_page' => 1, |
|
667 | - 'post_status' => 'any', |
|
668 | - 'meta_query' => array( |
|
669 | - array( |
|
670 | - 'key' => '_wpinv_type', |
|
671 | - 'value' => $type, |
|
672 | - ), |
|
673 | - array( |
|
674 | - 'key' => '_wpinv_custom_id', |
|
675 | - 'value' => $value, |
|
676 | - ) |
|
677 | - ) |
|
678 | - ) |
|
679 | - ); |
|
680 | - } |
|
681 | - |
|
682 | - if ( empty( $items ) ) { |
|
683 | - return 0; |
|
684 | - } |
|
685 | - |
|
686 | - // Update the cache with our data |
|
687 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
688 | - |
|
689 | - return $items[0]->ID; |
|
634 | + // Ensure a field has been passed. |
|
635 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
636 | + return 0; |
|
637 | + } |
|
638 | + |
|
639 | + if ( $field == 'name' ) { |
|
640 | + $field = 'slug'; |
|
641 | + } |
|
642 | + |
|
643 | + // Maybe retrieve from the cache. |
|
644 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
645 | + if ( ! empty( $item_id ) ) { |
|
646 | + return $item_id; |
|
647 | + } |
|
648 | + |
|
649 | + // Fetch from the db. |
|
650 | + $items = array(); |
|
651 | + if ( $field == 'slug' ) { |
|
652 | + $items = get_posts( |
|
653 | + array( |
|
654 | + 'post_type' => 'wpi_item', |
|
655 | + 'name' => $value, |
|
656 | + 'posts_per_page' => 1, |
|
657 | + 'post_status' => 'any', |
|
658 | + ) |
|
659 | + ); |
|
660 | + } |
|
661 | + |
|
662 | + if ( $field =='custom_id' ) { |
|
663 | + $items = get_posts( |
|
664 | + array( |
|
665 | + 'post_type' => 'wpi_item', |
|
666 | + 'posts_per_page' => 1, |
|
667 | + 'post_status' => 'any', |
|
668 | + 'meta_query' => array( |
|
669 | + array( |
|
670 | + 'key' => '_wpinv_type', |
|
671 | + 'value' => $type, |
|
672 | + ), |
|
673 | + array( |
|
674 | + 'key' => '_wpinv_custom_id', |
|
675 | + 'value' => $value, |
|
676 | + ) |
|
677 | + ) |
|
678 | + ) |
|
679 | + ); |
|
680 | + } |
|
681 | + |
|
682 | + if ( empty( $items ) ) { |
|
683 | + return 0; |
|
684 | + } |
|
685 | + |
|
686 | + // Update the cache with our data |
|
687 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
688 | + |
|
689 | + return $items[0]->ID; |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | /** |
@@ -719,52 +719,52 @@ discard block |
||
719 | 719 | */ |
720 | 720 | |
721 | 721 | /** |
722 | - * Set parent order ID. |
|
723 | - * |
|
724 | - * @since 1.0.19 |
|
725 | - */ |
|
726 | - public function set_parent_id( $value ) { |
|
727 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
728 | - return; |
|
729 | - } |
|
730 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Sets item status. |
|
735 | - * |
|
736 | - * @since 1.0.19 |
|
737 | - * @param string $status New status. |
|
738 | - * @return array details of change. |
|
739 | - */ |
|
740 | - public function set_status( $status ) { |
|
722 | + * Set parent order ID. |
|
723 | + * |
|
724 | + * @since 1.0.19 |
|
725 | + */ |
|
726 | + public function set_parent_id( $value ) { |
|
727 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
728 | + return; |
|
729 | + } |
|
730 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Sets item status. |
|
735 | + * |
|
736 | + * @since 1.0.19 |
|
737 | + * @param string $status New status. |
|
738 | + * @return array details of change. |
|
739 | + */ |
|
740 | + public function set_status( $status ) { |
|
741 | 741 | $old_status = $this->get_status(); |
742 | 742 | |
743 | 743 | $this->set_prop( 'status', $status ); |
744 | 744 | |
745 | - return array( |
|
746 | - 'from' => $old_status, |
|
747 | - 'to' => $status, |
|
748 | - ); |
|
745 | + return array( |
|
746 | + 'from' => $old_status, |
|
747 | + 'to' => $status, |
|
748 | + ); |
|
749 | 749 | } |
750 | 750 | |
751 | 751 | /** |
752 | - * Set plugin version when the item was created. |
|
753 | - * |
|
754 | - * @since 1.0.19 |
|
755 | - */ |
|
756 | - public function set_version( $value ) { |
|
757 | - $this->set_prop( 'version', $value ); |
|
752 | + * Set plugin version when the item was created. |
|
753 | + * |
|
754 | + * @since 1.0.19 |
|
755 | + */ |
|
756 | + public function set_version( $value ) { |
|
757 | + $this->set_prop( 'version', $value ); |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | /** |
761 | - * Set date when the item was created. |
|
762 | - * |
|
763 | - * @since 1.0.19 |
|
764 | - * @param string $value Value to set. |
|
761 | + * Set date when the item was created. |
|
762 | + * |
|
763 | + * @since 1.0.19 |
|
764 | + * @param string $value Value to set. |
|
765 | 765 | * @return bool Whether or not the date was set. |
766 | - */ |
|
767 | - public function set_date_created( $value ) { |
|
766 | + */ |
|
767 | + public function set_date_created( $value ) { |
|
768 | 768 | $date = strtotime( $value ); |
769 | 769 | |
770 | 770 | if ( $date ) { |
@@ -777,13 +777,13 @@ discard block |
||
777 | 777 | } |
778 | 778 | |
779 | 779 | /** |
780 | - * Set date when the item was last modified. |
|
781 | - * |
|
782 | - * @since 1.0.19 |
|
783 | - * @param string $value Value to set. |
|
780 | + * Set date when the item was last modified. |
|
781 | + * |
|
782 | + * @since 1.0.19 |
|
783 | + * @param string $value Value to set. |
|
784 | 784 | * @return bool Whether or not the date was set. |
785 | - */ |
|
786 | - public function set_date_modified( $value ) { |
|
785 | + */ |
|
786 | + public function set_date_modified( $value ) { |
|
787 | 787 | $date = strtotime( $value ); |
788 | 788 | |
789 | 789 | if ( $date ) { |
@@ -796,115 +796,115 @@ discard block |
||
796 | 796 | } |
797 | 797 | |
798 | 798 | /** |
799 | - * Set the item name. |
|
800 | - * |
|
801 | - * @since 1.0.19 |
|
802 | - * @param string $value New name. |
|
803 | - */ |
|
804 | - public function set_name( $value ) { |
|
799 | + * Set the item name. |
|
800 | + * |
|
801 | + * @since 1.0.19 |
|
802 | + * @param string $value New name. |
|
803 | + */ |
|
804 | + public function set_name( $value ) { |
|
805 | 805 | $name = sanitize_text_field( $value ); |
806 | - $this->set_prop( 'name', $name ); |
|
806 | + $this->set_prop( 'name', $name ); |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | /** |
810 | - * Alias of self::set_name(). |
|
811 | - * |
|
812 | - * @since 1.0.19 |
|
813 | - * @param string $value New name. |
|
814 | - */ |
|
815 | - public function set_title( $value ) { |
|
816 | - $this->set_name( $value ); |
|
810 | + * Alias of self::set_name(). |
|
811 | + * |
|
812 | + * @since 1.0.19 |
|
813 | + * @param string $value New name. |
|
814 | + */ |
|
815 | + public function set_title( $value ) { |
|
816 | + $this->set_name( $value ); |
|
817 | 817 | } |
818 | 818 | |
819 | 819 | /** |
820 | - * Set the item description. |
|
821 | - * |
|
822 | - * @since 1.0.19 |
|
823 | - * @param string $value New description. |
|
824 | - */ |
|
825 | - public function set_description( $value ) { |
|
826 | - $description = wp_kses_post( $value ); |
|
827 | - return $this->set_prop( 'description', $description ); |
|
820 | + * Set the item description. |
|
821 | + * |
|
822 | + * @since 1.0.19 |
|
823 | + * @param string $value New description. |
|
824 | + */ |
|
825 | + public function set_description( $value ) { |
|
826 | + $description = wp_kses_post( $value ); |
|
827 | + return $this->set_prop( 'description', $description ); |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | /** |
831 | - * Alias of self::set_description(). |
|
832 | - * |
|
833 | - * @since 1.0.19 |
|
834 | - * @param string $value New description. |
|
835 | - */ |
|
836 | - public function set_excerpt( $value ) { |
|
837 | - $this->set_description( $value ); |
|
831 | + * Alias of self::set_description(). |
|
832 | + * |
|
833 | + * @since 1.0.19 |
|
834 | + * @param string $value New description. |
|
835 | + */ |
|
836 | + public function set_excerpt( $value ) { |
|
837 | + $this->set_description( $value ); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | /** |
841 | - * Alias of self::set_description(). |
|
842 | - * |
|
843 | - * @since 1.0.19 |
|
844 | - * @param string $value New description. |
|
845 | - */ |
|
846 | - public function set_summary( $value ) { |
|
847 | - $this->set_description( $value ); |
|
841 | + * Alias of self::set_description(). |
|
842 | + * |
|
843 | + * @since 1.0.19 |
|
844 | + * @param string $value New description. |
|
845 | + */ |
|
846 | + public function set_summary( $value ) { |
|
847 | + $this->set_description( $value ); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | /** |
851 | - * Set the owner of the item. |
|
852 | - * |
|
853 | - * @since 1.0.19 |
|
854 | - * @param int $value New author. |
|
855 | - */ |
|
856 | - public function set_author( $value ) { |
|
857 | - $this->set_prop( 'author', (int) $value ); |
|
858 | - } |
|
851 | + * Set the owner of the item. |
|
852 | + * |
|
853 | + * @since 1.0.19 |
|
854 | + * @param int $value New author. |
|
855 | + */ |
|
856 | + public function set_author( $value ) { |
|
857 | + $this->set_prop( 'author', (int) $value ); |
|
858 | + } |
|
859 | 859 | |
860 | - /** |
|
861 | - * Alias of self::set_author(). |
|
862 | - * |
|
863 | - * @since 1.0.19 |
|
864 | - * @param int $value New author. |
|
865 | - */ |
|
866 | - public function set_owner( $value ) { |
|
867 | - $this->set_author( $value ); |
|
868 | - } |
|
869 | - |
|
870 | - /** |
|
871 | - * Set the price of the item. |
|
872 | - * |
|
873 | - * @since 1.0.19 |
|
874 | - * @param float $value New price. |
|
875 | - */ |
|
876 | - public function set_price( $value ) { |
|
860 | + /** |
|
861 | + * Alias of self::set_author(). |
|
862 | + * |
|
863 | + * @since 1.0.19 |
|
864 | + * @param int $value New author. |
|
865 | + */ |
|
866 | + public function set_owner( $value ) { |
|
867 | + $this->set_author( $value ); |
|
868 | + } |
|
869 | + |
|
870 | + /** |
|
871 | + * Set the price of the item. |
|
872 | + * |
|
873 | + * @since 1.0.19 |
|
874 | + * @param float $value New price. |
|
875 | + */ |
|
876 | + public function set_price( $value ) { |
|
877 | 877 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
878 | 878 | } |
879 | 879 | |
880 | 880 | /** |
881 | - * Set the VAT rule of the item. |
|
882 | - * |
|
883 | - * @since 1.0.19 |
|
884 | - * @param string $value new rule. |
|
885 | - */ |
|
886 | - public function set_vat_rule( $value ) { |
|
881 | + * Set the VAT rule of the item. |
|
882 | + * |
|
883 | + * @since 1.0.19 |
|
884 | + * @param string $value new rule. |
|
885 | + */ |
|
886 | + public function set_vat_rule( $value ) { |
|
887 | 887 | $this->set_prop( 'vat_rule', $value ); |
888 | 888 | } |
889 | 889 | |
890 | 890 | /** |
891 | - * Set the VAT class of the item. |
|
892 | - * |
|
893 | - * @since 1.0.19 |
|
894 | - * @param string $value new class. |
|
895 | - */ |
|
896 | - public function set_vat_class( $value ) { |
|
891 | + * Set the VAT class of the item. |
|
892 | + * |
|
893 | + * @since 1.0.19 |
|
894 | + * @param string $value new class. |
|
895 | + */ |
|
896 | + public function set_vat_class( $value ) { |
|
897 | 897 | $this->set_prop( 'vat_class', $value ); |
898 | 898 | } |
899 | 899 | |
900 | 900 | /** |
901 | - * Set the type of the item. |
|
902 | - * |
|
903 | - * @since 1.0.19 |
|
904 | - * @param string $value new item type. |
|
905 | - * @return string |
|
906 | - */ |
|
907 | - public function set_type( $value ) { |
|
901 | + * Set the type of the item. |
|
902 | + * |
|
903 | + * @since 1.0.19 |
|
904 | + * @param string $value new item type. |
|
905 | + * @return string |
|
906 | + */ |
|
907 | + public function set_type( $value ) { |
|
908 | 908 | |
909 | 909 | if ( empty( $value ) ) { |
910 | 910 | $value = 'custom'; |
@@ -914,132 +914,132 @@ discard block |
||
914 | 914 | } |
915 | 915 | |
916 | 916 | /** |
917 | - * Set the custom id of the item. |
|
918 | - * |
|
919 | - * @since 1.0.19 |
|
920 | - * @param string $value new custom id. |
|
921 | - */ |
|
922 | - public function set_custom_id( $value ) { |
|
917 | + * Set the custom id of the item. |
|
918 | + * |
|
919 | + * @since 1.0.19 |
|
920 | + * @param string $value new custom id. |
|
921 | + */ |
|
922 | + public function set_custom_id( $value ) { |
|
923 | 923 | $this->set_prop( 'custom_id', $value ); |
924 | 924 | } |
925 | 925 | |
926 | 926 | /** |
927 | - * Set the custom name of the item. |
|
928 | - * |
|
929 | - * @since 1.0.19 |
|
930 | - * @param string $value new custom name. |
|
931 | - */ |
|
932 | - public function set_custom_name( $value ) { |
|
927 | + * Set the custom name of the item. |
|
928 | + * |
|
929 | + * @since 1.0.19 |
|
930 | + * @param string $value new custom name. |
|
931 | + */ |
|
932 | + public function set_custom_name( $value ) { |
|
933 | 933 | $this->set_prop( 'custom_name', $value ); |
934 | 934 | } |
935 | 935 | |
936 | 936 | /** |
937 | - * Set the custom singular name of the item. |
|
938 | - * |
|
939 | - * @since 1.0.19 |
|
940 | - * @param string $value new custom singular name. |
|
941 | - */ |
|
942 | - public function set_custom_singular_name( $value ) { |
|
937 | + * Set the custom singular name of the item. |
|
938 | + * |
|
939 | + * @since 1.0.19 |
|
940 | + * @param string $value new custom singular name. |
|
941 | + */ |
|
942 | + public function set_custom_singular_name( $value ) { |
|
943 | 943 | $this->set_prop( 'custom_singular_name', $value ); |
944 | 944 | } |
945 | 945 | |
946 | 946 | /** |
947 | - * Sets if an item is editable.. |
|
948 | - * |
|
949 | - * @since 1.0.19 |
|
950 | - * @param int|bool $value whether or not the item is editable. |
|
951 | - */ |
|
952 | - public function set_is_editable( $value ) { |
|
953 | - $this->set_prop( 'is_editable', (int) $value ); |
|
947 | + * Sets if an item is editable.. |
|
948 | + * |
|
949 | + * @since 1.0.19 |
|
950 | + * @param int|bool $value whether or not the item is editable. |
|
951 | + */ |
|
952 | + public function set_is_editable( $value ) { |
|
953 | + $this->set_prop( 'is_editable', (int) $value ); |
|
954 | 954 | } |
955 | 955 | |
956 | 956 | /** |
957 | - * Sets if dynamic pricing is enabled. |
|
958 | - * |
|
959 | - * @since 1.0.19 |
|
960 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
961 | - */ |
|
962 | - public function set_is_dynamic_pricing( $value ) { |
|
957 | + * Sets if dynamic pricing is enabled. |
|
958 | + * |
|
959 | + * @since 1.0.19 |
|
960 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
961 | + */ |
|
962 | + public function set_is_dynamic_pricing( $value ) { |
|
963 | 963 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
964 | 964 | } |
965 | 965 | |
966 | 966 | /** |
967 | - * Sets the minimum price if dynamic pricing is enabled. |
|
968 | - * |
|
969 | - * @since 1.0.19 |
|
970 | - * @param float $value minimum price. |
|
971 | - */ |
|
972 | - public function set_minimum_price( $value ) { |
|
967 | + * Sets the minimum price if dynamic pricing is enabled. |
|
968 | + * |
|
969 | + * @since 1.0.19 |
|
970 | + * @param float $value minimum price. |
|
971 | + */ |
|
972 | + public function set_minimum_price( $value ) { |
|
973 | 973 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
974 | 974 | } |
975 | 975 | |
976 | 976 | /** |
977 | - * Sets if this is a recurring item. |
|
978 | - * |
|
979 | - * @since 1.0.19 |
|
980 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
981 | - */ |
|
982 | - public function set_is_recurring( $value ) { |
|
977 | + * Sets if this is a recurring item. |
|
978 | + * |
|
979 | + * @since 1.0.19 |
|
980 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
981 | + */ |
|
982 | + public function set_is_recurring( $value ) { |
|
983 | 983 | $this->set_prop( 'is_recurring', (int) $value ); |
984 | 984 | } |
985 | 985 | |
986 | 986 | /** |
987 | - * Set the recurring period. |
|
988 | - * |
|
989 | - * @since 1.0.19 |
|
990 | - * @param string $value new period. |
|
991 | - */ |
|
992 | - public function set_recurring_period( $value ) { |
|
987 | + * Set the recurring period. |
|
988 | + * |
|
989 | + * @since 1.0.19 |
|
990 | + * @param string $value new period. |
|
991 | + */ |
|
992 | + public function set_recurring_period( $value ) { |
|
993 | 993 | $this->set_prop( 'recurring_period', $value ); |
994 | 994 | } |
995 | 995 | |
996 | 996 | /** |
997 | - * Set the recurring interval. |
|
998 | - * |
|
999 | - * @since 1.0.19 |
|
1000 | - * @param int $value recurring interval. |
|
1001 | - */ |
|
1002 | - public function set_recurring_interval( $value ) { |
|
997 | + * Set the recurring interval. |
|
998 | + * |
|
999 | + * @since 1.0.19 |
|
1000 | + * @param int $value recurring interval. |
|
1001 | + */ |
|
1002 | + public function set_recurring_interval( $value ) { |
|
1003 | 1003 | return $this->set_prop( 'recurring_interval', (int) $value ); |
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | /** |
1007 | - * Get the recurring limit. |
|
1008 | - * @since 1.0.19 |
|
1009 | - * @param int $value The recurring limit. |
|
1010 | - * @return int |
|
1011 | - */ |
|
1012 | - public function set_recurring_limit( $value ) { |
|
1007 | + * Get the recurring limit. |
|
1008 | + * @since 1.0.19 |
|
1009 | + * @param int $value The recurring limit. |
|
1010 | + * @return int |
|
1011 | + */ |
|
1012 | + public function set_recurring_limit( $value ) { |
|
1013 | 1013 | $this->set_prop( 'recurring_limit', (int) $value ); |
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | /** |
1017 | - * Checks if we have a free trial. |
|
1018 | - * |
|
1019 | - * @since 1.0.19 |
|
1020 | - * @param int|bool $value whether or not it has a free trial. |
|
1021 | - */ |
|
1022 | - public function set_is_free_trial( $value ) { |
|
1017 | + * Checks if we have a free trial. |
|
1018 | + * |
|
1019 | + * @since 1.0.19 |
|
1020 | + * @param int|bool $value whether or not it has a free trial. |
|
1021 | + */ |
|
1022 | + public function set_is_free_trial( $value ) { |
|
1023 | 1023 | $this->set_prop( 'is_free_trial', (int) $value ); |
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | /** |
1027 | - * Set the trial period. |
|
1028 | - * |
|
1029 | - * @since 1.0.19 |
|
1030 | - * @param string $value trial period. |
|
1031 | - */ |
|
1032 | - public function set_trial_period( $value ) { |
|
1027 | + * Set the trial period. |
|
1028 | + * |
|
1029 | + * @since 1.0.19 |
|
1030 | + * @param string $value trial period. |
|
1031 | + */ |
|
1032 | + public function set_trial_period( $value ) { |
|
1033 | 1033 | $this->set_prop( 'trial_period', $value ); |
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | /** |
1037 | - * Set the trial interval. |
|
1038 | - * |
|
1039 | - * @since 1.0.19 |
|
1040 | - * @param int $value trial interval. |
|
1041 | - */ |
|
1042 | - public function set_trial_interval( $value ) { |
|
1037 | + * Set the trial interval. |
|
1038 | + * |
|
1039 | + * @since 1.0.19 |
|
1040 | + * @param int $value trial interval. |
|
1041 | + */ |
|
1042 | + public function set_trial_interval( $value ) { |
|
1043 | 1043 | $this->set_prop( 'trial_interval', $value ); |
1044 | 1044 | } |
1045 | 1045 | |
@@ -1047,17 +1047,17 @@ discard block |
||
1047 | 1047 | * Create an item. For backwards compatibilty. |
1048 | 1048 | * |
1049 | 1049 | * @deprecated |
1050 | - * @return int item id |
|
1050 | + * @return int item id |
|
1051 | 1051 | */ |
1052 | 1052 | public function create( $data = array() ) { |
1053 | 1053 | |
1054 | - // Set the properties. |
|
1055 | - if ( is_array( $data ) ) { |
|
1056 | - $this->set_props( $data ); |
|
1057 | - } |
|
1054 | + // Set the properties. |
|
1055 | + if ( is_array( $data ) ) { |
|
1056 | + $this->set_props( $data ); |
|
1057 | + } |
|
1058 | 1058 | |
1059 | - // Save the item. |
|
1060 | - return $this->save(); |
|
1059 | + // Save the item. |
|
1060 | + return $this->save(); |
|
1061 | 1061 | |
1062 | 1062 | } |
1063 | 1063 | |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | * Updates an item. For backwards compatibilty. |
1066 | 1066 | * |
1067 | 1067 | * @deprecated |
1068 | - * @return int item id |
|
1068 | + * @return int item id |
|
1069 | 1069 | */ |
1070 | 1070 | public function update( $data = array() ) { |
1071 | 1071 | return $this->create( $data ); |
@@ -1081,93 +1081,93 @@ discard block |
||
1081 | 1081 | */ |
1082 | 1082 | |
1083 | 1083 | /** |
1084 | - * Checks whether the item has enabled dynamic pricing. |
|
1085 | - * |
|
1086 | - * @since 1.0.19 |
|
1087 | - * @return bool |
|
1088 | - */ |
|
1089 | - public function user_can_set_their_price() { |
|
1084 | + * Checks whether the item has enabled dynamic pricing. |
|
1085 | + * |
|
1086 | + * @since 1.0.19 |
|
1087 | + * @return bool |
|
1088 | + */ |
|
1089 | + public function user_can_set_their_price() { |
|
1090 | 1090 | return (bool) $this->get_is_dynamic_pricing(); |
1091 | - } |
|
1091 | + } |
|
1092 | 1092 | |
1093 | - /** |
|
1094 | - * Checks whether the item is recurring. |
|
1095 | - * |
|
1096 | - * @since 1.0.19 |
|
1097 | - * @return bool |
|
1098 | - */ |
|
1099 | - public function is_recurring() { |
|
1093 | + /** |
|
1094 | + * Checks whether the item is recurring. |
|
1095 | + * |
|
1096 | + * @since 1.0.19 |
|
1097 | + * @return bool |
|
1098 | + */ |
|
1099 | + public function is_recurring() { |
|
1100 | 1100 | return (bool) $this->get_is_recurring(); |
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | /** |
1104 | - * Checks whether the item has a free trial. |
|
1105 | - * |
|
1106 | - * @since 1.0.19 |
|
1107 | - * @return bool |
|
1108 | - */ |
|
1104 | + * Checks whether the item has a free trial. |
|
1105 | + * |
|
1106 | + * @since 1.0.19 |
|
1107 | + * @return bool |
|
1108 | + */ |
|
1109 | 1109 | public function has_free_trial() { |
1110 | 1110 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1111 | 1111 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
1112 | 1112 | } |
1113 | 1113 | |
1114 | 1114 | /** |
1115 | - * Checks whether the item is free. |
|
1116 | - * |
|
1117 | - * @since 1.0.19 |
|
1118 | - * @return bool |
|
1119 | - */ |
|
1115 | + * Checks whether the item is free. |
|
1116 | + * |
|
1117 | + * @since 1.0.19 |
|
1118 | + * @return bool |
|
1119 | + */ |
|
1120 | 1120 | public function is_free() { |
1121 | 1121 | $is_free = $this->get_price() == 0; |
1122 | 1122 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | /** |
1126 | - * Checks the item status against a passed in status. |
|
1127 | - * |
|
1128 | - * @param array|string $status Status to check. |
|
1129 | - * @return bool |
|
1130 | - */ |
|
1131 | - public function has_status( $status ) { |
|
1132 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1133 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1126 | + * Checks the item status against a passed in status. |
|
1127 | + * |
|
1128 | + * @param array|string $status Status to check. |
|
1129 | + * @return bool |
|
1130 | + */ |
|
1131 | + public function has_status( $status ) { |
|
1132 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1133 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | /** |
1137 | - * Checks the item type against a passed in types. |
|
1138 | - * |
|
1139 | - * @param array|string $type Type to check. |
|
1140 | - * @return bool |
|
1141 | - */ |
|
1142 | - public function is_type( $type ) { |
|
1143 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1144 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1145 | - } |
|
1137 | + * Checks the item type against a passed in types. |
|
1138 | + * |
|
1139 | + * @param array|string $type Type to check. |
|
1140 | + * @return bool |
|
1141 | + */ |
|
1142 | + public function is_type( $type ) { |
|
1143 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1144 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1145 | + } |
|
1146 | 1146 | |
1147 | 1147 | /** |
1148 | - * Checks whether the item is editable. |
|
1149 | - * |
|
1150 | - * @since 1.0.19 |
|
1151 | - * @return bool |
|
1152 | - */ |
|
1148 | + * Checks whether the item is editable. |
|
1149 | + * |
|
1150 | + * @since 1.0.19 |
|
1151 | + * @return bool |
|
1152 | + */ |
|
1153 | 1153 | public function is_editable() { |
1154 | 1154 | $is_editable = $this->get_is_editable(); |
1155 | 1155 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
1156 | - } |
|
1156 | + } |
|
1157 | 1157 | |
1158 | - /** |
|
1159 | - * Returns an array of cart fees. |
|
1160 | - */ |
|
1161 | - public function get_fees() { |
|
1158 | + /** |
|
1159 | + * Returns an array of cart fees. |
|
1160 | + */ |
|
1161 | + public function get_fees() { |
|
1162 | 1162 | return array(); |
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | /** |
1166 | - * Checks whether the item is purchasable. |
|
1167 | - * |
|
1168 | - * @since 1.0.19 |
|
1169 | - * @return bool |
|
1170 | - */ |
|
1166 | + * Checks whether the item is purchasable. |
|
1167 | + * |
|
1168 | + * @since 1.0.19 |
|
1169 | + * @return bool |
|
1170 | + */ |
|
1171 | 1171 | public function can_purchase() { |
1172 | 1172 | $can_purchase = $this->exists(); |
1173 | 1173 | |
@@ -1179,11 +1179,11 @@ discard block |
||
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | /** |
1182 | - * Checks whether the item supports dynamic pricing. |
|
1183 | - * |
|
1184 | - * @since 1.0.19 |
|
1185 | - * @return bool |
|
1186 | - */ |
|
1182 | + * Checks whether the item supports dynamic pricing. |
|
1183 | + * |
|
1184 | + * @since 1.0.19 |
|
1185 | + * @return bool |
|
1186 | + */ |
|
1187 | 1187 | public function supports_dynamic_pricing() { |
1188 | 1188 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
1189 | 1189 | } |
@@ -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', 'single_subscription_group' ); |
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', true, $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', true, $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_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
252 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $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 = $item->get_price(); |
|
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 = $item->get_price(); |
|
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 float $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' => (float) $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 float $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' => (float) $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'] * $item['quantity']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
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 = getpaid_get_invoice_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 |
@@ -12,108 +12,108 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
31 | - |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Schedules a cron to run every day at 7 a.m |
|
36 | - * |
|
37 | - */ |
|
38 | - public function maybe_create_scheduled_event() { |
|
39 | - |
|
40 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
41 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
42 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
43 | - } |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Clears deprecated events. |
|
49 | - * |
|
50 | - */ |
|
51 | - public function maybe_clear_deprecated_events() { |
|
52 | - |
|
53 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
56 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
57 | - } |
|
58 | - |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Fires the old hook for backwards compatibility. |
|
63 | - * |
|
64 | - */ |
|
65 | - public function backwards_compat() { |
|
66 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Expires expired subscriptions. |
|
71 | - * |
|
72 | - */ |
|
73 | - public function maybe_expire_subscriptions() { |
|
74 | - |
|
75 | - // Fetch expired subscriptions (skips those that expire today). |
|
76 | - $args = array( |
|
77 | - 'number' => -1, |
|
78 | - 'count_total' => false, |
|
79 | - 'status' => 'trialling active failing cancelled', |
|
80 | - 'date_expires_query' => array( |
|
81 | - 'before' => 'today', |
|
82 | - 'inclusive' => false, |
|
83 | - ), |
|
84 | - ); |
|
85 | - |
|
86 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
87 | - |
|
88 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
89 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
90 | - $subscription->set_status( 'expired' ); |
|
91 | - $subscription->save(); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Logs cron runs. |
|
99 | - * |
|
100 | - */ |
|
101 | - public function log_cron_run() { |
|
102 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Updates GeoIP databases. |
|
107 | - * |
|
108 | - */ |
|
109 | - public function maybe_update_geoip_databases() { |
|
110 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
111 | - |
|
112 | - if ( false === $updated ) { |
|
113 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
114 | - do_action( 'getpaid_update_geoip_databases' ); |
|
115 | - } |
|
116 | - |
|
117 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
31 | + |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Schedules a cron to run every day at 7 a.m |
|
36 | + * |
|
37 | + */ |
|
38 | + public function maybe_create_scheduled_event() { |
|
39 | + |
|
40 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
41 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
42 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
43 | + } |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Clears deprecated events. |
|
49 | + * |
|
50 | + */ |
|
51 | + public function maybe_clear_deprecated_events() { |
|
52 | + |
|
53 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
54 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
56 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
57 | + } |
|
58 | + |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Fires the old hook for backwards compatibility. |
|
63 | + * |
|
64 | + */ |
|
65 | + public function backwards_compat() { |
|
66 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Expires expired subscriptions. |
|
71 | + * |
|
72 | + */ |
|
73 | + public function maybe_expire_subscriptions() { |
|
74 | + |
|
75 | + // Fetch expired subscriptions (skips those that expire today). |
|
76 | + $args = array( |
|
77 | + 'number' => -1, |
|
78 | + 'count_total' => false, |
|
79 | + 'status' => 'trialling active failing cancelled', |
|
80 | + 'date_expires_query' => array( |
|
81 | + 'before' => 'today', |
|
82 | + 'inclusive' => false, |
|
83 | + ), |
|
84 | + ); |
|
85 | + |
|
86 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
87 | + |
|
88 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
89 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
90 | + $subscription->set_status( 'expired' ); |
|
91 | + $subscription->save(); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Logs cron runs. |
|
99 | + * |
|
100 | + */ |
|
101 | + public function log_cron_run() { |
|
102 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Updates GeoIP databases. |
|
107 | + * |
|
108 | + */ |
|
109 | + public function maybe_update_geoip_databases() { |
|
110 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
111 | + |
|
112 | + if ( false === $updated ) { |
|
113 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
114 | + do_action( 'getpaid_update_geoip_databases' ); |
|
115 | + } |
|
116 | + |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |
@@ -12,276 +12,276 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Metaboxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Only save metaboxes once. |
|
17 | - * |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - private static $saved_meta_boxes = false; |
|
21 | - |
|
22 | 15 | /** |
23 | - * Hook in methods. |
|
24 | - */ |
|
25 | - public static function init() { |
|
26 | - |
|
27 | - // Register metaboxes. |
|
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
29 | - |
|
30 | - // Remove metaboxes. |
|
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
32 | - |
|
33 | - // Rename metaboxes. |
|
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | - |
|
36 | - // Save metaboxes. |
|
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Register core metaboxes. |
|
42 | - */ |
|
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
16 | + * Only save metaboxes once. |
|
17 | + * |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + private static $saved_meta_boxes = false; |
|
44 | 21 | |
45 | - // For invoices... |
|
46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
47 | - |
|
48 | - // For payment forms. |
|
49 | - self::add_payment_form_meta_boxes( $post_type ); |
|
50 | - |
|
51 | - // For invoice items. |
|
52 | - self::add_item_meta_boxes( $post_type ); |
|
53 | - |
|
54 | - // For invoice discounts. |
|
55 | - if ( $post_type == 'wpi_discount' ) { |
|
56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | - } |
|
58 | - |
|
59 | - } |
|
22 | + /** |
|
23 | + * Hook in methods. |
|
24 | + */ |
|
25 | + public static function init() { |
|
60 | 26 | |
61 | - /** |
|
62 | - * Register core metaboxes. |
|
63 | - */ |
|
64 | - protected static function add_payment_form_meta_boxes( $post_type ) { |
|
27 | + // Register metaboxes. |
|
28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
65 | 29 | |
66 | - // For payment forms. |
|
67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
30 | + // Remove metaboxes. |
|
31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
68 | 32 | |
69 | - // Design payment form. |
|
70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
33 | + // Rename metaboxes. |
|
34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
71 | 35 | |
72 | - // Payment form information. |
|
73 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
36 | + // Save metaboxes. |
|
37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | + } |
|
74 | 39 | |
75 | - } |
|
40 | + /** |
|
41 | + * Register core metaboxes. |
|
42 | + */ |
|
43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
76 | 44 | |
77 | - } |
|
45 | + // For invoices... |
|
46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
78 | 47 | |
79 | - /** |
|
80 | - * Register core metaboxes. |
|
81 | - */ |
|
82 | - protected static function add_item_meta_boxes( $post_type ) { |
|
48 | + // For payment forms. |
|
49 | + self::add_payment_form_meta_boxes( $post_type ); |
|
83 | 50 | |
84 | - if ( $post_type == 'wpi_item' ) { |
|
51 | + // For invoice items. |
|
52 | + self::add_item_meta_boxes( $post_type ); |
|
85 | 53 | |
86 | - // Item details. |
|
87 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
54 | + // For invoice discounts. |
|
55 | + if ( $post_type == 'wpi_discount' ) { |
|
56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
57 | + } |
|
88 | 58 | |
89 | - // If taxes are enabled, register the tax metabox. |
|
90 | - if ( wpinv_use_taxes() ) { |
|
91 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
92 | - } |
|
59 | + } |
|
93 | 60 | |
94 | - // Item info. |
|
95 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
61 | + /** |
|
62 | + * Register core metaboxes. |
|
63 | + */ |
|
64 | + protected static function add_payment_form_meta_boxes( $post_type ) { |
|
96 | 65 | |
97 | - } |
|
66 | + // For payment forms. |
|
67 | + if ( $post_type == 'wpi_payment_form' ) { |
|
98 | 68 | |
99 | - } |
|
69 | + // Design payment form. |
|
70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
100 | 71 | |
101 | - /** |
|
102 | - * Register invoice metaboxes. |
|
103 | - */ |
|
104 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
72 | + // Payment form information. |
|
73 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
105 | 74 | |
106 | - // For invoices... |
|
107 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
108 | - $invoice = new WPInv_Invoice( $post ); |
|
75 | + } |
|
109 | 76 | |
110 | - // Resend invoice. |
|
111 | - if ( ! $invoice->is_draft() ) { |
|
77 | + } |
|
112 | 78 | |
113 | - add_meta_box( |
|
114 | - 'wpinv-mb-resend-invoice', |
|
115 | - sprintf( |
|
116 | - __( 'Resend %s', 'invoicing' ), |
|
117 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
118 | - ), |
|
119 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
120 | - $post_type, |
|
121 | - 'side', |
|
122 | - 'low' |
|
123 | - ); |
|
79 | + /** |
|
80 | + * Register core metaboxes. |
|
81 | + */ |
|
82 | + protected static function add_item_meta_boxes( $post_type ) { |
|
124 | 83 | |
125 | - } |
|
84 | + if ( $post_type == 'wpi_item' ) { |
|
126 | 85 | |
127 | - // Subscriptions. |
|
128 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
129 | - if ( ! empty( $subscriptions ) ) { |
|
86 | + // Item details. |
|
87 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
130 | 88 | |
131 | - if ( is_array( $subscriptions ) ) { |
|
132 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
133 | - } else { |
|
134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
135 | - } |
|
89 | + // If taxes are enabled, register the tax metabox. |
|
90 | + if ( wpinv_use_taxes() ) { |
|
91 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
92 | + } |
|
136 | 93 | |
137 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
138 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
139 | - } |
|
94 | + // Item info. |
|
95 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
140 | 96 | |
141 | - } |
|
97 | + } |
|
142 | 98 | |
143 | - // Invoice details. |
|
144 | - add_meta_box( |
|
145 | - 'wpinv-details', |
|
146 | - sprintf( |
|
147 | - __( '%s Details', 'invoicing' ), |
|
148 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
149 | - ), |
|
150 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
151 | - $post_type, |
|
152 | - 'side' |
|
153 | - ); |
|
154 | - |
|
155 | - // Payment details. |
|
156 | - if ( ! $invoice->is_draft() ) { |
|
157 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
158 | - } |
|
99 | + } |
|
159 | 100 | |
160 | - // Billing details. |
|
161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
101 | + /** |
|
102 | + * Register invoice metaboxes. |
|
103 | + */ |
|
104 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
105 | + |
|
106 | + // For invoices... |
|
107 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
108 | + $invoice = new WPInv_Invoice( $post ); |
|
109 | + |
|
110 | + // Resend invoice. |
|
111 | + if ( ! $invoice->is_draft() ) { |
|
112 | + |
|
113 | + add_meta_box( |
|
114 | + 'wpinv-mb-resend-invoice', |
|
115 | + sprintf( |
|
116 | + __( 'Resend %s', 'invoicing' ), |
|
117 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
118 | + ), |
|
119 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
120 | + $post_type, |
|
121 | + 'side', |
|
122 | + 'low' |
|
123 | + ); |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + // Subscriptions. |
|
128 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
129 | + if ( ! empty( $subscriptions ) ) { |
|
130 | + |
|
131 | + if ( is_array( $subscriptions ) ) { |
|
132 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
133 | + } else { |
|
134 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
135 | + } |
|
136 | + |
|
137 | + if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
138 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
139 | + } |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + // Invoice details. |
|
144 | + add_meta_box( |
|
145 | + 'wpinv-details', |
|
146 | + sprintf( |
|
147 | + __( '%s Details', 'invoicing' ), |
|
148 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
149 | + ), |
|
150 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
151 | + $post_type, |
|
152 | + 'side' |
|
153 | + ); |
|
154 | + |
|
155 | + // Payment details. |
|
156 | + if ( ! $invoice->is_draft() ) { |
|
157 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
158 | + } |
|
159 | + |
|
160 | + // Billing details. |
|
161 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
162 | 162 | |
163 | - // Invoice items. |
|
164 | - add_meta_box( |
|
165 | - 'wpinv-items', |
|
166 | - sprintf( |
|
167 | - __( '%s Items', 'invoicing' ), |
|
168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
169 | - ), |
|
170 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
171 | - $post_type, |
|
172 | - 'normal', |
|
173 | - 'high' |
|
174 | - ); |
|
163 | + // Invoice items. |
|
164 | + add_meta_box( |
|
165 | + 'wpinv-items', |
|
166 | + sprintf( |
|
167 | + __( '%s Items', 'invoicing' ), |
|
168 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
169 | + ), |
|
170 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
171 | + $post_type, |
|
172 | + 'normal', |
|
173 | + 'high' |
|
174 | + ); |
|
175 | 175 | |
176 | - // Invoice notes. |
|
177 | - add_meta_box( |
|
178 | - 'wpinv-notes', |
|
179 | - sprintf( |
|
180 | - __( '%s Notes', 'invoicing' ), |
|
181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
182 | - ), |
|
183 | - 'WPInv_Meta_Box_Notes::output', |
|
184 | - $post_type, |
|
185 | - 'side', |
|
186 | - 'low' |
|
187 | - ); |
|
188 | - |
|
189 | - // Shipping Address. |
|
190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
192 | - } |
|
193 | - |
|
194 | - // Payment form information. |
|
195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
197 | - } |
|
198 | - |
|
199 | - } |
|
200 | - |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Remove some metaboxes. |
|
205 | - */ |
|
206 | - public static function remove_meta_boxes() { |
|
207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Rename other metaboxes. |
|
212 | - */ |
|
213 | - public static function rename_meta_boxes() { |
|
176 | + // Invoice notes. |
|
177 | + add_meta_box( |
|
178 | + 'wpinv-notes', |
|
179 | + sprintf( |
|
180 | + __( '%s Notes', 'invoicing' ), |
|
181 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
182 | + ), |
|
183 | + 'WPInv_Meta_Box_Notes::output', |
|
184 | + $post_type, |
|
185 | + 'side', |
|
186 | + 'low' |
|
187 | + ); |
|
188 | + |
|
189 | + // Shipping Address. |
|
190 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
191 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
192 | + } |
|
193 | + |
|
194 | + // Payment form information. |
|
195 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
196 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
197 | + } |
|
198 | + |
|
199 | + } |
|
200 | + |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Remove some metaboxes. |
|
205 | + */ |
|
206 | + public static function remove_meta_boxes() { |
|
207 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Rename other metaboxes. |
|
212 | + */ |
|
213 | + public static function rename_meta_boxes() { |
|
214 | 214 | |
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Check if we're saving, then trigger an action based on the post type. |
|
219 | - * |
|
220 | - * @param int $post_id Post ID. |
|
221 | - * @param object $post Post object. |
|
222 | - */ |
|
223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
224 | - $post_id = absint( $post_id ); |
|
225 | - $data = wp_unslash( $_POST ); |
|
226 | - |
|
227 | - // Do not save for ajax requests. |
|
228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
229 | - return; |
|
230 | - } |
|
231 | - |
|
232 | - // $post_id and $post are required |
|
233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
234 | - return; |
|
235 | - } |
|
236 | - |
|
237 | - // Dont' save meta boxes for revisions or autosaves. |
|
238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
239 | - return; |
|
240 | - } |
|
241 | - |
|
242 | - // Check the nonce. |
|
243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
244 | - return; |
|
245 | - } |
|
246 | - |
|
247 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
249 | - return; |
|
250 | - } |
|
251 | - |
|
252 | - // Check user has permission to edit. |
|
253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
254 | - return; |
|
255 | - } |
|
256 | - |
|
257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
258 | - |
|
259 | - // We need this save event to run once to avoid potential endless loops. |
|
260 | - self::$saved_meta_boxes = true; |
|
261 | - |
|
262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
263 | - |
|
264 | - } |
|
265 | - |
|
266 | - // Ensure this is our post type. |
|
267 | - $post_types_map = array( |
|
268 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
269 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
270 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
271 | - ); |
|
272 | - |
|
273 | - // Is this our post type? |
|
274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // We need this save event to run once to avoid potential endless loops. |
|
279 | - self::$saved_meta_boxes = true; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Check if we're saving, then trigger an action based on the post type. |
|
219 | + * |
|
220 | + * @param int $post_id Post ID. |
|
221 | + * @param object $post Post object. |
|
222 | + */ |
|
223 | + public static function save_meta_boxes( $post_id, $post ) { |
|
224 | + $post_id = absint( $post_id ); |
|
225 | + $data = wp_unslash( $_POST ); |
|
226 | + |
|
227 | + // Do not save for ajax requests. |
|
228 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
229 | + return; |
|
230 | + } |
|
231 | + |
|
232 | + // $post_id and $post are required |
|
233 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
234 | + return; |
|
235 | + } |
|
236 | + |
|
237 | + // Dont' save meta boxes for revisions or autosaves. |
|
238 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
239 | + return; |
|
240 | + } |
|
241 | + |
|
242 | + // Check the nonce. |
|
243 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
244 | + return; |
|
245 | + } |
|
246 | + |
|
247 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
248 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
249 | + return; |
|
250 | + } |
|
251 | + |
|
252 | + // Check user has permission to edit. |
|
253 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
254 | + return; |
|
255 | + } |
|
256 | + |
|
257 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
258 | + |
|
259 | + // We need this save event to run once to avoid potential endless loops. |
|
260 | + self::$saved_meta_boxes = true; |
|
261 | + |
|
262 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
263 | + |
|
264 | + } |
|
265 | + |
|
266 | + // Ensure this is our post type. |
|
267 | + $post_types_map = array( |
|
268 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
269 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
270 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
271 | + ); |
|
272 | + |
|
273 | + // Is this our post type? |
|
274 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + // We need this save event to run once to avoid potential endless loops. |
|
279 | + self::$saved_meta_boxes = true; |
|
280 | 280 | |
281 | - // Save the post. |
|
282 | - $class = $post_types_map[ $post->post_type ]; |
|
283 | - $class::save( $post_id, $_POST, $post ); |
|
281 | + // Save the post. |
|
282 | + $class = $post_types_map[ $post->post_type ]; |
|
283 | + $class::save( $post_id, $_POST, $post ); |
|
284 | 284 | |
285 | - } |
|
285 | + } |
|
286 | 286 | |
287 | 287 | } |
@@ -12,472 +12,472 @@ |
||
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', false ); |
|
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', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
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'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
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', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
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', false ); |
|
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(), false ); |
|
95 | - return $invoice; |
|
96 | - } |
|
97 | - |
|
98 | - } |
|
99 | - |
|
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Check PayPal IPN validity. |
|
106 | - */ |
|
107 | - protected function validate_ipn() { |
|
108 | - |
|
109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
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', false ); |
|
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( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
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', false ); |
|
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', false ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
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'], false ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
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', false ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
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', false ); |
|
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(), false ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | + |
|
98 | + } |
|
99 | + |
|
100 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Check PayPal IPN validity. |
|
106 | + */ |
|
107 | + protected function validate_ipn() { |
|
108 | + |
|
109 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
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', false ); |
|
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( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
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', false ); |
|
168 | - } |
|
167 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
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', false ); |
|
186 | - } |
|
185 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
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', false ); |
|
207 | - } |
|
206 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
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 ) { |
|
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 | 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'] ); |
|
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 | 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 | - } |
|
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'], false ); |
|
240 | - } |
|
239 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
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.', false ); |
|
247 | - } |
|
245 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
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 = ''; |
|
251 | + $note = ''; |
|
252 | 252 | |
253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
255 | - } |
|
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.', false ); |
|
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.', false ); |
|
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".', false ); |
|
273 | - } |
|
272 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
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', false ); |
|
298 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
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', false ); |
|
305 | - } |
|
303 | + if ( empty( $subscription ) ) { |
|
304 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
305 | + } |
|
306 | 306 | |
307 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
307 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
308 | 308 | |
309 | - // Validate the IPN. |
|
310 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
311 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
312 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
309 | + // Validate the IPN. |
|
310 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
311 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
312 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
313 | 313 | |
314 | - // Activate the subscription. |
|
315 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
316 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
317 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
318 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
319 | - $subscription->activate(); |
|
314 | + // Activate the subscription. |
|
315 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
316 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
317 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
318 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
319 | + $subscription->activate(); |
|
320 | 320 | |
321 | - // Set the transaction id. |
|
322 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
323 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
324 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
325 | - } |
|
321 | + // Set the transaction id. |
|
322 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
323 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
324 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
325 | + } |
|
326 | 326 | |
327 | - // Update the payment status. |
|
328 | - $invoice->mark_paid(); |
|
327 | + // Update the payment status. |
|
328 | + $invoice->mark_paid(); |
|
329 | 329 | |
330 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
330 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
331 | 331 | |
332 | - wpinv_error_log( 'Subscription started.', false ); |
|
333 | - } |
|
332 | + wpinv_error_log( 'Subscription started.', false ); |
|
333 | + } |
|
334 | 334 | |
335 | - /** |
|
336 | - * Handles subscription renewals. |
|
337 | - * |
|
338 | - * @param WPInv_Invoice $invoice Invoice object. |
|
339 | - * @param array $posted Posted data. |
|
340 | - */ |
|
341 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
335 | + /** |
|
336 | + * Handles subscription renewals. |
|
337 | + * |
|
338 | + * @param WPInv_Invoice $invoice Invoice object. |
|
339 | + * @param array $posted Posted data. |
|
340 | + */ |
|
341 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
342 | 342 | |
343 | - // Make sure the invoice has a subscription. |
|
344 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
343 | + // Make sure the invoice has a subscription. |
|
344 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
345 | 345 | |
346 | - if ( empty( $subscription ) ) { |
|
347 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
348 | - } |
|
346 | + if ( empty( $subscription ) ) { |
|
347 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
348 | + } |
|
349 | 349 | |
350 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
350 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
351 | 351 | |
352 | - // PayPal sends a subscr_payment for the first payment too. |
|
353 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
354 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
355 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
356 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
357 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
358 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
352 | + // PayPal sends a subscr_payment for the first payment too. |
|
353 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
354 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
355 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
356 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
357 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
358 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
359 | 359 | |
360 | - foreach( $dates as $date ) { |
|
360 | + foreach( $dates as $date ) { |
|
361 | 361 | |
362 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
363 | - continue; |
|
364 | - } |
|
362 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
363 | + continue; |
|
364 | + } |
|
365 | 365 | |
366 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
367 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
368 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
369 | - } |
|
366 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
367 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
368 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
369 | + } |
|
370 | 370 | |
371 | - return $invoice->mark_paid(); |
|
372 | - |
|
373 | - } |
|
371 | + return $invoice->mark_paid(); |
|
372 | + |
|
373 | + } |
|
374 | 374 | |
375 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
376 | - |
|
377 | - // Abort if the payment is already recorded. |
|
378 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
379 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
380 | - } |
|
381 | - |
|
382 | - $args = array( |
|
383 | - 'transaction_id' => $posted['txn_id'], |
|
384 | - 'gateway' => $this->id, |
|
385 | - ); |
|
386 | - |
|
387 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
375 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
376 | + |
|
377 | + // Abort if the payment is already recorded. |
|
378 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
379 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
380 | + } |
|
381 | + |
|
382 | + $args = array( |
|
383 | + 'transaction_id' => $posted['txn_id'], |
|
384 | + 'gateway' => $this->id, |
|
385 | + ); |
|
386 | + |
|
387 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
388 | 388 | |
389 | - if ( empty( $invoice ) ) { |
|
390 | - return; |
|
391 | - } |
|
389 | + if ( empty( $invoice ) ) { |
|
390 | + return; |
|
391 | + } |
|
392 | 392 | |
393 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
393 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
394 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
395 | 395 | |
396 | - $subscription->renew(); |
|
397 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
396 | + $subscription->renew(); |
|
397 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
398 | 398 | |
399 | - } |
|
399 | + } |
|
400 | 400 | |
401 | - /** |
|
402 | - * Handles subscription cancelations. |
|
403 | - * |
|
404 | - * @param WPInv_Invoice $invoice Invoice object. |
|
405 | - */ |
|
406 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
401 | + /** |
|
402 | + * Handles subscription cancelations. |
|
403 | + * |
|
404 | + * @param WPInv_Invoice $invoice Invoice object. |
|
405 | + */ |
|
406 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
407 | 407 | |
408 | - // Make sure the invoice has a subscription. |
|
409 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
410 | - |
|
411 | - if ( empty( $subscription ) ) { |
|
412 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
413 | - } |
|
414 | - |
|
415 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
416 | - $subscription->cancel(); |
|
417 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
408 | + // Make sure the invoice has a subscription. |
|
409 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
410 | + |
|
411 | + if ( empty( $subscription ) ) { |
|
412 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
413 | + } |
|
414 | + |
|
415 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
416 | + $subscription->cancel(); |
|
417 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
418 | 418 | |
419 | - } |
|
419 | + } |
|
420 | 420 | |
421 | - /** |
|
422 | - * Handles subscription completions. |
|
423 | - * |
|
424 | - * @param WPInv_Invoice $invoice Invoice object. |
|
425 | - * @param array $posted Posted data. |
|
426 | - */ |
|
427 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
421 | + /** |
|
422 | + * Handles subscription completions. |
|
423 | + * |
|
424 | + * @param WPInv_Invoice $invoice Invoice object. |
|
425 | + * @param array $posted Posted data. |
|
426 | + */ |
|
427 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
428 | 428 | |
429 | - // Make sure the invoice has a subscription. |
|
430 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
429 | + // Make sure the invoice has a subscription. |
|
430 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
431 | 431 | |
432 | - if ( empty( $subscription ) ) { |
|
433 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
434 | - } |
|
432 | + if ( empty( $subscription ) ) { |
|
433 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
434 | + } |
|
435 | 435 | |
436 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
437 | - $subscription->complete(); |
|
438 | - wpinv_error_log( 'Subscription completed.', false ); |
|
436 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
437 | + $subscription->complete(); |
|
438 | + wpinv_error_log( 'Subscription completed.', false ); |
|
439 | 439 | |
440 | - } |
|
440 | + } |
|
441 | 441 | |
442 | - /** |
|
443 | - * Handles subscription fails. |
|
444 | - * |
|
445 | - * @param WPInv_Invoice $invoice Invoice object. |
|
446 | - * @param array $posted Posted data. |
|
447 | - */ |
|
448 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
442 | + /** |
|
443 | + * Handles subscription fails. |
|
444 | + * |
|
445 | + * @param WPInv_Invoice $invoice Invoice object. |
|
446 | + * @param array $posted Posted data. |
|
447 | + */ |
|
448 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
449 | 449 | |
450 | - // Make sure the invoice has a subscription. |
|
451 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
450 | + // Make sure the invoice has a subscription. |
|
451 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
452 | 452 | |
453 | - if ( empty( $subscription ) ) { |
|
454 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
455 | - } |
|
453 | + if ( empty( $subscription ) ) { |
|
454 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
455 | + } |
|
456 | 456 | |
457 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
458 | - $subscription->failing(); |
|
459 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
457 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
458 | + $subscription->failing(); |
|
459 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
460 | 460 | |
461 | - } |
|
461 | + } |
|
462 | 462 | |
463 | - /** |
|
464 | - * Handles subscription suspensions. |
|
465 | - * |
|
466 | - * @param WPInv_Invoice $invoice Invoice object. |
|
467 | - * @param array $posted Posted data. |
|
468 | - */ |
|
469 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
463 | + /** |
|
464 | + * Handles subscription suspensions. |
|
465 | + * |
|
466 | + * @param WPInv_Invoice $invoice Invoice object. |
|
467 | + * @param array $posted Posted data. |
|
468 | + */ |
|
469 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
470 | 470 | |
471 | - // Make sure the invoice has a subscription. |
|
472 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
471 | + // Make sure the invoice has a subscription. |
|
472 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
473 | 473 | |
474 | - if ( empty( $subscription ) ) { |
|
475 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
476 | - } |
|
477 | - |
|
478 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
479 | - $subscription->cancel(); |
|
480 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
481 | - } |
|
474 | + if ( empty( $subscription ) ) { |
|
475 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
476 | + } |
|
477 | + |
|
478 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
479 | + $subscription->cancel(); |
|
480 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
481 | + } |
|
482 | 482 | |
483 | 483 | } |
@@ -15,125 +15,125 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $data_store_name = 'subscription'; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'subscription'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Item Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'customer_id' => 0, |
|
40 | - 'frequency' => 1, |
|
41 | - 'period' => 'D', |
|
42 | - 'initial_amount' => null, |
|
43 | - 'recurring_amount' => null, |
|
44 | - 'bill_times' => 0, |
|
45 | - 'transaction_id' => '', |
|
46 | - 'parent_payment_id' => null, |
|
47 | - 'product_id' => 0, |
|
48 | - 'created' => '0000-00-00 00:00:00', |
|
49 | - 'expiration' => '0000-00-00 00:00:00', |
|
50 | - 'trial_period' => '', |
|
51 | - 'status' => 'pending', |
|
52 | - 'profile_id' => '', |
|
53 | - 'gateway' => '', |
|
54 | - 'customer' => '', |
|
55 | - ); |
|
56 | - |
|
57 | - /** |
|
58 | - * Stores the status transition information. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - protected $status_transition = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | - * |
|
68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | - * @param bool $deprecated |
|
70 | - */ |
|
71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | - |
|
73 | - parent::__construct( $subscription ); |
|
74 | - |
|
75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | - $this->set_id( $subscription ); |
|
77 | - } elseif ( $subscription instanceof self ) { |
|
78 | - $this->set_id( $subscription->get_id() ); |
|
79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | - $this->set_id( $subscription_id ); |
|
81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
82 | - $this->set_id( $subscription->id ); |
|
83 | - } else { |
|
84 | - $this->set_object_read( true ); |
|
85 | - } |
|
86 | - |
|
87 | - // Load the datastore. |
|
88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | - |
|
90 | - if ( $this->get_id() > 0 ) { |
|
91 | - $this->data_store->read( $this ); |
|
92 | - } |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | - * |
|
99 | - * |
|
100 | - * @static |
|
101 | - * @param string $value |
|
102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | - * @since 1.0.19 |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $data_store_name = 'subscription'; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'subscription'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Item Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'customer_id' => 0, |
|
40 | + 'frequency' => 1, |
|
41 | + 'period' => 'D', |
|
42 | + 'initial_amount' => null, |
|
43 | + 'recurring_amount' => null, |
|
44 | + 'bill_times' => 0, |
|
45 | + 'transaction_id' => '', |
|
46 | + 'parent_payment_id' => null, |
|
47 | + 'product_id' => 0, |
|
48 | + 'created' => '0000-00-00 00:00:00', |
|
49 | + 'expiration' => '0000-00-00 00:00:00', |
|
50 | + 'trial_period' => '', |
|
51 | + 'status' => 'pending', |
|
52 | + 'profile_id' => '', |
|
53 | + 'gateway' => '', |
|
54 | + 'customer' => '', |
|
55 | + ); |
|
56 | + |
|
57 | + /** |
|
58 | + * Stores the status transition information. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + protected $status_transition = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | + * |
|
68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | + * @param bool $deprecated |
|
70 | + */ |
|
71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | + |
|
73 | + parent::__construct( $subscription ); |
|
74 | + |
|
75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | + $this->set_id( $subscription ); |
|
77 | + } elseif ( $subscription instanceof self ) { |
|
78 | + $this->set_id( $subscription->get_id() ); |
|
79 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
80 | + $this->set_id( $subscription_id ); |
|
81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
82 | + $this->set_id( $subscription->id ); |
|
83 | + } else { |
|
84 | + $this->set_object_read( true ); |
|
85 | + } |
|
86 | + |
|
87 | + // Load the datastore. |
|
88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | + |
|
90 | + if ( $this->get_id() > 0 ) { |
|
91 | + $this->data_store->read( $this ); |
|
92 | + } |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | + * |
|
99 | + * |
|
100 | + * @static |
|
101 | + * @param string $value |
|
102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | + * @since 1.0.19 |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | - // Trim the value. |
|
110 | - $value = trim( $value ); |
|
109 | + // Trim the value. |
|
110 | + $value = trim( $value ); |
|
111 | 111 | |
112 | - if ( empty( $value ) ) { |
|
113 | - return 0; |
|
114 | - } |
|
112 | + if ( empty( $value ) ) { |
|
113 | + return 0; |
|
114 | + } |
|
115 | 115 | |
116 | - if ( 'invoice_id' == $field ) { |
|
117 | - $field = 'parent_payment_id'; |
|
118 | - } |
|
116 | + if ( 'invoice_id' == $field ) { |
|
117 | + $field = 'parent_payment_id'; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | // Valid fields. |
121 | 121 | $fields = array( |
122 | - 'parent_payment_id', |
|
123 | - 'transaction_id', |
|
124 | - 'profile_id' |
|
125 | - ); |
|
126 | - |
|
127 | - // Ensure a field has been passed. |
|
128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | - return 0; |
|
130 | - } |
|
131 | - |
|
132 | - // Maybe retrieve from the cache. |
|
133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | - if ( ! empty( $subscription_id ) ) { |
|
135 | - return $subscription_id; |
|
136 | - } |
|
122 | + 'parent_payment_id', |
|
123 | + 'transaction_id', |
|
124 | + 'profile_id' |
|
125 | + ); |
|
126 | + |
|
127 | + // Ensure a field has been passed. |
|
128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | + return 0; |
|
130 | + } |
|
131 | + |
|
132 | + // Maybe retrieve from the cache. |
|
133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | + if ( ! empty( $subscription_id ) ) { |
|
135 | + return $subscription_id; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | // Fetch from the db. |
139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,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 | - /* |
|
181 | - |-------------------------------------------------------------------------- |
|
182 | - | Getters |
|
183 | - |-------------------------------------------------------------------------- |
|
184 | - */ |
|
180 | + /* |
|
181 | + |-------------------------------------------------------------------------- |
|
182 | + | Getters |
|
183 | + |-------------------------------------------------------------------------- |
|
184 | + */ |
|
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 | + */ |
|
226 | + public function get_parent_payment_id( $context = 'view' ) { |
|
227 | + return $this->get_parent_invoice_id( $context ); |
|
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 | + } |
|
606 | + |
|
607 | + /** |
|
608 | + * Get transaction id of this subscription's parent invoice. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @param string $value Bill times. |
|
612 | + */ |
|
613 | + public function set_transaction_id( $value ) { |
|
614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Set date when this subscription started. |
|
619 | + * |
|
620 | + * @since 1.0.19 |
|
621 | + * @param string $value strtotime compliant date. |
|
622 | + */ |
|
623 | + public function set_created( $value ) { |
|
624 | + $date = strtotime( $value ); |
|
625 | + |
|
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; |
|
629 | + } |
|
630 | + |
|
631 | + $this->set_prop( 'created', '' ); |
|
185 | 632 | |
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 | - public function get_parent_payment_id( $context = 'view' ) { |
|
227 | - return $this->get_parent_invoice_id( $context ); |
|
228 | - } |
|
633 | + } |
|
229 | 634 | |
230 | - /** |
|
231 | - * Alias for self::get_parent_invoice_id(). |
|
635 | + /** |
|
636 | + * Alias for self::set_created(). |
|
232 | 637 | * |
233 | - * @since 1.0.0 |
|
234 | - * @return int |
|
638 | + * @since 1.0.19 |
|
639 | + * @param string $value strtotime compliant date. |
|
235 | 640 | */ |
236 | - public function get_original_payment_id( $context = 'view' ) { |
|
237 | - return $this->get_parent_invoice_id( $context ); |
|
641 | + public function set_date_created( $value ) { |
|
642 | + $this->set_created( $value ); |
|
238 | 643 | } |
239 | 644 | |
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 ); |
|
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 ); |
|
405 | 653 | |
406 | - if ( $date ) { |
|
407 | - $date = get_gmt_from_date( $date ); |
|
654 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
655 | + $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
656 | + return; |
|
408 | 657 | } |
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 | 658 | |
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 | - */ |
|
659 | + $this->set_prop( 'expiration', '' ); |
|
505 | 660 | |
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 | - } |
|
661 | + } |
|
535 | 662 | |
536 | - /** |
|
537 | - * Alias for self::set_parent_invoice_id(). |
|
663 | + /** |
|
664 | + * Alias for self::set_next_renewal_date(). |
|
538 | 665 | * |
539 | 666 | * @since 1.0.19 |
540 | - * @param int $value The parent invoice id. |
|
667 | + * @param string $value strtotime compliant date. |
|
541 | 668 | */ |
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 ) { |
|
624 | - $date = strtotime( $value ); |
|
669 | + public function set_expiration( $value ) { |
|
670 | + $this->set_next_renewal_date( $value ); |
|
671 | + } |
|
625 | 672 | |
626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
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() ) ) { |
|
628 | 693 | return; |
629 | 694 | } |
630 | 695 | |
631 | - $this->set_prop( 'created', '' ); |
|
696 | + $old_status = $this->get_status(); |
|
697 | + $this->set_prop( 'status', $new_status ); |
|
632 | 698 | |
633 | - } |
|
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 | + } |
|
634 | 705 | |
635 | - /** |
|
636 | - * Alias for self::set_created(). |
|
637 | - * |
|
638 | - * @since 1.0.19 |
|
639 | - * @param string $value strtotime compliant date. |
|
640 | - */ |
|
641 | - public function set_date_created( $value ) { |
|
642 | - $this->set_created( $value ); |
|
643 | 706 | } |
644 | 707 | |
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 ); |
|
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 | + } |
|
653 | 717 | |
654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
656 | - return; |
|
657 | - } |
|
658 | - |
|
659 | - $this->set_prop( 'expiration', '' ); |
|
660 | - |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * Alias for self::set_next_renewal_date(). |
|
665 | - * |
|
666 | - * @since 1.0.19 |
|
667 | - * @param string $value strtotime compliant date. |
|
668 | - */ |
|
669 | - public function set_expiration( $value ) { |
|
670 | - $this->set_next_renewal_date( $value ); |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * Set the subscription's trial period. |
|
675 | - * |
|
676 | - * @since 1.0.19 |
|
677 | - * @param string $value trial period e.g 1 year. |
|
678 | - */ |
|
679 | - public function set_trial_period( $value ) { |
|
680 | - $this->set_prop( 'trial_period', $value ); |
|
681 | - } |
|
682 | - |
|
683 | - /** |
|
684 | - * Set the subscription's status. |
|
685 | - * |
|
686 | - * @since 1.0.19 |
|
687 | - * @param string $new_status New subscription status. |
|
688 | - */ |
|
689 | - public function set_status( $new_status ) { |
|
690 | - |
|
691 | - // Abort if this is not a valid status; |
|
692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
693 | - return; |
|
694 | - } |
|
695 | - |
|
696 | - $old_status = $this->get_status(); |
|
697 | - $this->set_prop( 'status', $new_status ); |
|
698 | - |
|
699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
700 | - $this->status_transition = array( |
|
701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
702 | - 'to' => $new_status, |
|
703 | - ); |
|
704 | - } |
|
705 | - |
|
706 | - } |
|
707 | - |
|
708 | - /** |
|
709 | - * Set the subscription's (remote) profile id. |
|
710 | - * |
|
711 | - * @since 1.0.19 |
|
712 | - * @param string $value the remote profile id. |
|
713 | - */ |
|
714 | - public function set_profile_id( $value ) { |
|
715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
716 | - } |
|
717 | - |
|
718 | - /* |
|
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' => 'ASC', |
|
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' => 'ASC', |
|
827 | + 'post_type' => 'wpi_invoice' |
|
828 | + ) |
|
829 | + ); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | * @return int |
837 | 837 | */ |
838 | 838 | public function get_total_payments() { |
839 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
839 | + return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | /** |
@@ -860,57 +860,57 @@ discard block |
||
860 | 860 | * |
861 | 861 | * @since 2.4 |
862 | 862 | * @param array $args Array of values for the payment, including amount and transaction ID |
863 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
863 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
864 | 864 | * @return bool |
865 | 865 | */ |
866 | 866 | public function add_payment( $args = array(), $invoice = false ) { |
867 | 867 | |
868 | - // Process each payment once. |
|
868 | + // Process each payment once. |
|
869 | 869 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
870 | 870 | return false; |
871 | 871 | } |
872 | 872 | |
873 | - // Are we creating a new invoice? |
|
874 | - if ( empty( $invoice ) ) { |
|
875 | - $invoice = $this->create_payment(); |
|
873 | + // Are we creating a new invoice? |
|
874 | + if ( empty( $invoice ) ) { |
|
875 | + $invoice = $this->create_payment(); |
|
876 | 876 | |
877 | - if ( empty( $invoice ) ) { |
|
878 | - return false; |
|
879 | - } |
|
877 | + if ( empty( $invoice ) ) { |
|
878 | + return false; |
|
879 | + } |
|
880 | 880 | |
881 | - } |
|
881 | + } |
|
882 | 882 | |
883 | - $invoice->set_status( 'wpi-renewal' ); |
|
883 | + $invoice->set_status( 'wpi-renewal' ); |
|
884 | 884 | |
885 | - // Maybe set a transaction id. |
|
886 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
887 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
888 | - } |
|
885 | + // Maybe set a transaction id. |
|
886 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
887 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
888 | + } |
|
889 | 889 | |
890 | - // Set the completed date. |
|
891 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
890 | + // Set the completed date. |
|
891 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
892 | 892 | |
893 | - // And the gateway. |
|
894 | - if ( ! empty( $args['gateway'] ) ) { |
|
895 | - $invoice->set_gateway( $args['gateway'] ); |
|
896 | - } |
|
893 | + // And the gateway. |
|
894 | + if ( ! empty( $args['gateway'] ) ) { |
|
895 | + $invoice->set_gateway( $args['gateway'] ); |
|
896 | + } |
|
897 | 897 | |
898 | - $invoice->save(); |
|
898 | + $invoice->save(); |
|
899 | 899 | |
900 | - if ( ! $invoice->exists() ) { |
|
901 | - return false; |
|
902 | - } |
|
900 | + if ( ! $invoice->exists() ) { |
|
901 | + return false; |
|
902 | + } |
|
903 | 903 | |
904 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
905 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
904 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
905 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
906 | 906 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
907 | 907 | |
908 | 908 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
909 | 909 | |
910 | 910 | return $invoice->get_id(); |
911 | - } |
|
911 | + } |
|
912 | 912 | |
913 | - /** |
|
913 | + /** |
|
914 | 914 | * Creates a new invoice and returns it. |
915 | 915 | * |
916 | 916 | * @since 1.0.19 |
@@ -918,124 +918,124 @@ discard block |
||
918 | 918 | */ |
919 | 919 | public function create_payment() { |
920 | 920 | |
921 | - $parent_invoice = $this->get_parent_payment(); |
|
922 | - |
|
923 | - if ( ! $parent_invoice->exists() ) { |
|
924 | - return false; |
|
925 | - } |
|
926 | - |
|
927 | - // Duplicate the parent invoice. |
|
928 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
929 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
930 | - $invoice->set_subscription_id( $this->get_id() ); |
|
931 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
932 | - |
|
933 | - // Set invoice items. |
|
934 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
935 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
936 | - $invoice_items = array(); |
|
937 | - |
|
938 | - foreach ( $invoice->get_items() as $item ) { |
|
939 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
940 | - $invoice_items[] = $item; |
|
941 | - } |
|
942 | - } |
|
943 | - |
|
944 | - $invoice->set_items( $invoice_items ); |
|
945 | - |
|
946 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
947 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
948 | - } |
|
949 | - |
|
950 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
951 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
952 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
953 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
954 | - } |
|
955 | - |
|
956 | - $invoice->recalculate_total(); |
|
957 | - $invoice->set_status( 'wpi-pending' ); |
|
958 | - $invoice->save(); |
|
959 | - |
|
960 | - return $invoice->exists() ? $invoice : false; |
|
961 | - } |
|
962 | - |
|
963 | - /** |
|
964 | - * Renews or completes a subscription |
|
965 | - * |
|
966 | - * @since 1.0.0 |
|
967 | - * @return int The subscription's id |
|
968 | - */ |
|
969 | - public function renew() { |
|
970 | - |
|
971 | - // Complete subscription if applicable |
|
972 | - if ( $this->is_last_renewal() ) { |
|
973 | - return $this->complete(); |
|
974 | - } |
|
975 | - |
|
976 | - // Calculate new expiration |
|
977 | - $frequency = $this->get_frequency(); |
|
978 | - $period = $this->get_period(); |
|
979 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
980 | - |
|
981 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
982 | - $this->set_status( 'active' ); |
|
983 | - $this->save(); |
|
984 | - |
|
985 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
986 | - |
|
987 | - return $this->get_id(); |
|
988 | - } |
|
989 | - |
|
990 | - /** |
|
991 | - * Marks a subscription as completed |
|
992 | - * |
|
993 | - * Subscription is completed when the number of payments matches the billing_times field |
|
994 | - * |
|
995 | - * @since 1.0.0 |
|
996 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
997 | - */ |
|
998 | - public function complete() { |
|
999 | - |
|
1000 | - // Only mark a subscription as complete if it's not already cancelled. |
|
1001 | - if ( $this->has_status( 'cancelled' ) ) { |
|
1002 | - return false; |
|
1003 | - } |
|
1004 | - |
|
1005 | - $this->set_status( 'completed' ); |
|
1006 | - return $this->save(); |
|
1007 | - |
|
1008 | - } |
|
1009 | - |
|
1010 | - /** |
|
1011 | - * Marks a subscription as expired |
|
1012 | - * |
|
1013 | - * @since 1.0.0 |
|
1014 | - * @param bool $check_expiration |
|
1015 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1016 | - */ |
|
1017 | - public function expire( $check_expiration = false ) { |
|
1018 | - |
|
1019 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1020 | - // Do not mark as expired since real expiration date is in the future |
|
1021 | - return false; |
|
1022 | - } |
|
1023 | - |
|
1024 | - $this->set_status( 'expired' ); |
|
1025 | - return $this->save(); |
|
1026 | - |
|
1027 | - } |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * Marks a subscription as failing |
|
1031 | - * |
|
1032 | - * @since 2.4.2 |
|
1033 | - * @return int Subscription id. |
|
1034 | - */ |
|
1035 | - public function failing() { |
|
1036 | - $this->set_status( 'failing' ); |
|
1037 | - return $this->save(); |
|
1038 | - } |
|
921 | + $parent_invoice = $this->get_parent_payment(); |
|
922 | + |
|
923 | + if ( ! $parent_invoice->exists() ) { |
|
924 | + return false; |
|
925 | + } |
|
926 | + |
|
927 | + // Duplicate the parent invoice. |
|
928 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
929 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
930 | + $invoice->set_subscription_id( $this->get_id() ); |
|
931 | + $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
932 | + |
|
933 | + // Set invoice items. |
|
934 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
935 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
936 | + $invoice_items = array(); |
|
937 | + |
|
938 | + foreach ( $invoice->get_items() as $item ) { |
|
939 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
940 | + $invoice_items[] = $item; |
|
941 | + } |
|
942 | + } |
|
943 | + |
|
944 | + $invoice->set_items( $invoice_items ); |
|
945 | + |
|
946 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
947 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
948 | + } |
|
949 | + |
|
950 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
951 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
952 | + if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
953 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
954 | + } |
|
955 | + |
|
956 | + $invoice->recalculate_total(); |
|
957 | + $invoice->set_status( 'wpi-pending' ); |
|
958 | + $invoice->save(); |
|
959 | + |
|
960 | + return $invoice->exists() ? $invoice : false; |
|
961 | + } |
|
962 | + |
|
963 | + /** |
|
964 | + * Renews or completes a subscription |
|
965 | + * |
|
966 | + * @since 1.0.0 |
|
967 | + * @return int The subscription's id |
|
968 | + */ |
|
969 | + public function renew() { |
|
970 | + |
|
971 | + // Complete subscription if applicable |
|
972 | + if ( $this->is_last_renewal() ) { |
|
973 | + return $this->complete(); |
|
974 | + } |
|
975 | + |
|
976 | + // Calculate new expiration |
|
977 | + $frequency = $this->get_frequency(); |
|
978 | + $period = $this->get_period(); |
|
979 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
980 | + |
|
981 | + $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
982 | + $this->set_status( 'active' ); |
|
983 | + $this->save(); |
|
984 | + |
|
985 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
986 | + |
|
987 | + return $this->get_id(); |
|
988 | + } |
|
989 | + |
|
990 | + /** |
|
991 | + * Marks a subscription as completed |
|
992 | + * |
|
993 | + * Subscription is completed when the number of payments matches the billing_times field |
|
994 | + * |
|
995 | + * @since 1.0.0 |
|
996 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
997 | + */ |
|
998 | + public function complete() { |
|
999 | + |
|
1000 | + // Only mark a subscription as complete if it's not already cancelled. |
|
1001 | + if ( $this->has_status( 'cancelled' ) ) { |
|
1002 | + return false; |
|
1003 | + } |
|
1004 | + |
|
1005 | + $this->set_status( 'completed' ); |
|
1006 | + return $this->save(); |
|
1007 | + |
|
1008 | + } |
|
1009 | + |
|
1010 | + /** |
|
1011 | + * Marks a subscription as expired |
|
1012 | + * |
|
1013 | + * @since 1.0.0 |
|
1014 | + * @param bool $check_expiration |
|
1015 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1016 | + */ |
|
1017 | + public function expire( $check_expiration = false ) { |
|
1018 | + |
|
1019 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1020 | + // Do not mark as expired since real expiration date is in the future |
|
1021 | + return false; |
|
1022 | + } |
|
1023 | + |
|
1024 | + $this->set_status( 'expired' ); |
|
1025 | + return $this->save(); |
|
1026 | + |
|
1027 | + } |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * Marks a subscription as failing |
|
1031 | + * |
|
1032 | + * @since 2.4.2 |
|
1033 | + * @return int Subscription id. |
|
1034 | + */ |
|
1035 | + public function failing() { |
|
1036 | + $this->set_status( 'failing' ); |
|
1037 | + return $this->save(); |
|
1038 | + } |
|
1039 | 1039 | |
1040 | 1040 | /** |
1041 | 1041 | * Marks a subscription as cancelled |
@@ -1044,19 +1044,19 @@ discard block |
||
1044 | 1044 | * @return int Subscription id. |
1045 | 1045 | */ |
1046 | 1046 | public function cancel() { |
1047 | - $this->set_status( 'cancelled' ); |
|
1048 | - return $this->save(); |
|
1047 | + $this->set_status( 'cancelled' ); |
|
1048 | + return $this->save(); |
|
1049 | 1049 | } |
1050 | 1050 | |
1051 | - /** |
|
1052 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1053 | - * |
|
1054 | - * @since 1.0.0 |
|
1055 | - * @return bool |
|
1056 | - */ |
|
1057 | - public function can_cancel() { |
|
1058 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1059 | - } |
|
1051 | + /** |
|
1052 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1053 | + * |
|
1054 | + * @since 1.0.0 |
|
1055 | + * @return bool |
|
1056 | + */ |
|
1057 | + public function can_cancel() { |
|
1058 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1059 | + } |
|
1060 | 1060 | |
1061 | 1061 | /** |
1062 | 1062 | * Returns an array of subscription statuses that can be cancelled |
@@ -1069,96 +1069,96 @@ discard block |
||
1069 | 1069 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
1070 | 1070 | } |
1071 | 1071 | |
1072 | - /** |
|
1073 | - * Retrieves the URL to cancel subscription |
|
1074 | - * |
|
1075 | - * @since 1.0.0 |
|
1076 | - * @return string |
|
1077 | - */ |
|
1078 | - public function get_cancel_url() { |
|
1079 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1080 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1081 | - } |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * Retrieves the URL to view a subscription |
|
1085 | - * |
|
1086 | - * @since 1.0.19 |
|
1087 | - * @return string |
|
1088 | - */ |
|
1089 | - public function get_view_url() { |
|
1090 | - |
|
1091 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1092 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1093 | - |
|
1094 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1095 | - } |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * Determines if subscription can be manually renewed |
|
1099 | - * |
|
1100 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
1101 | - * that can be renewed manually |
|
1102 | - * |
|
1103 | - * @since 2.5 |
|
1104 | - * @return bool |
|
1105 | - */ |
|
1106 | - public function can_renew() { |
|
1107 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1108 | - } |
|
1109 | - |
|
1110 | - /** |
|
1111 | - * Retrieves the URL to renew a subscription |
|
1112 | - * |
|
1113 | - * @since 2.5 |
|
1114 | - * @return string |
|
1115 | - */ |
|
1116 | - public function get_renew_url() { |
|
1117 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
1118 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1119 | - } |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * Determines if subscription can have their payment method updated |
|
1123 | - * |
|
1124 | - * @since 1.0.0 |
|
1125 | - * @return bool |
|
1126 | - */ |
|
1127 | - public function can_update() { |
|
1128 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1129 | - } |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * Retrieves the URL to update subscription |
|
1133 | - * |
|
1134 | - * @since 1.0.0 |
|
1135 | - * @return string |
|
1136 | - */ |
|
1137 | - public function get_update_url() { |
|
1138 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1139 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1140 | - } |
|
1141 | - |
|
1142 | - /** |
|
1143 | - * Retrieves the subscription status label |
|
1144 | - * |
|
1145 | - * @since 1.0.0 |
|
1146 | - * @return string |
|
1147 | - */ |
|
1148 | - public function get_status_label() { |
|
1149 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1150 | - } |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * Retrieves the subscription status class |
|
1154 | - * |
|
1155 | - * @since 1.0.19 |
|
1156 | - * @return string |
|
1157 | - */ |
|
1158 | - public function get_status_class() { |
|
1159 | - $statuses = getpaid_get_subscription_status_classes(); |
|
1160 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
1161 | - } |
|
1072 | + /** |
|
1073 | + * Retrieves the URL to cancel subscription |
|
1074 | + * |
|
1075 | + * @since 1.0.0 |
|
1076 | + * @return string |
|
1077 | + */ |
|
1078 | + public function get_cancel_url() { |
|
1079 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1080 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1081 | + } |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * Retrieves the URL to view a subscription |
|
1085 | + * |
|
1086 | + * @since 1.0.19 |
|
1087 | + * @return string |
|
1088 | + */ |
|
1089 | + public function get_view_url() { |
|
1090 | + |
|
1091 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1092 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
1093 | + |
|
1094 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1095 | + } |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * Determines if subscription can be manually renewed |
|
1099 | + * |
|
1100 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
1101 | + * that can be renewed manually |
|
1102 | + * |
|
1103 | + * @since 2.5 |
|
1104 | + * @return bool |
|
1105 | + */ |
|
1106 | + public function can_renew() { |
|
1107 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1108 | + } |
|
1109 | + |
|
1110 | + /** |
|
1111 | + * Retrieves the URL to renew a subscription |
|
1112 | + * |
|
1113 | + * @since 2.5 |
|
1114 | + * @return string |
|
1115 | + */ |
|
1116 | + public function get_renew_url() { |
|
1117 | + $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
1118 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1119 | + } |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * Determines if subscription can have their payment method updated |
|
1123 | + * |
|
1124 | + * @since 1.0.0 |
|
1125 | + * @return bool |
|
1126 | + */ |
|
1127 | + public function can_update() { |
|
1128 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1129 | + } |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * Retrieves the URL to update subscription |
|
1133 | + * |
|
1134 | + * @since 1.0.0 |
|
1135 | + * @return string |
|
1136 | + */ |
|
1137 | + public function get_update_url() { |
|
1138 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1139 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1140 | + } |
|
1141 | + |
|
1142 | + /** |
|
1143 | + * Retrieves the subscription status label |
|
1144 | + * |
|
1145 | + * @since 1.0.0 |
|
1146 | + * @return string |
|
1147 | + */ |
|
1148 | + public function get_status_label() { |
|
1149 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1150 | + } |
|
1151 | + |
|
1152 | + /** |
|
1153 | + * Retrieves the subscription status class |
|
1154 | + * |
|
1155 | + * @since 1.0.19 |
|
1156 | + * @return string |
|
1157 | + */ |
|
1158 | + public function get_status_class() { |
|
1159 | + $statuses = getpaid_get_subscription_status_classes(); |
|
1160 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
1161 | + } |
|
1162 | 1162 | |
1163 | 1163 | /** |
1164 | 1164 | * Retrieves the subscription status label |
@@ -1168,11 +1168,11 @@ discard block |
||
1168 | 1168 | */ |
1169 | 1169 | public function get_status_label_html() { |
1170 | 1170 | |
1171 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1172 | - $class = esc_attr( $this->get_status_class() ); |
|
1173 | - $status = sanitize_html_class( $this->get_status() ); |
|
1171 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1172 | + $class = esc_attr( $this->get_status_class() ); |
|
1173 | + $status = sanitize_html_class( $this->get_status() ); |
|
1174 | 1174 | |
1175 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1175 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | /** |
@@ -1183,75 +1183,75 @@ discard block |
||
1183 | 1183 | * @return bool |
1184 | 1184 | */ |
1185 | 1185 | public function payment_exists( $txn_id = '' ) { |
1186 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1186 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1187 | 1187 | return ! empty( $invoice_id ); |
1188 | - } |
|
1189 | - |
|
1190 | - /** |
|
1191 | - * Handle the status transition. |
|
1192 | - */ |
|
1193 | - protected function status_transition() { |
|
1194 | - $status_transition = $this->status_transition; |
|
1195 | - |
|
1196 | - // Reset status transition variable. |
|
1197 | - $this->status_transition = false; |
|
1198 | - |
|
1199 | - if ( $status_transition ) { |
|
1200 | - try { |
|
1201 | - |
|
1202 | - // Fire a hook for the status change. |
|
1203 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1204 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1205 | - |
|
1206 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1207 | - |
|
1208 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
1209 | - $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'] ) ); |
|
1210 | - |
|
1211 | - // Note the transition occurred. |
|
1212 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1213 | - |
|
1214 | - // Fire another hook. |
|
1215 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1216 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1217 | - |
|
1218 | - } else { |
|
1219 | - /* translators: %s: new invoice status */ |
|
1220 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1221 | - |
|
1222 | - // Note the transition occurred. |
|
1223 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1224 | - |
|
1225 | - } |
|
1226 | - } catch ( Exception $e ) { |
|
1227 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1228 | - } |
|
1229 | - } |
|
1230 | - |
|
1231 | - } |
|
1232 | - |
|
1233 | - /** |
|
1234 | - * Save data to the database. |
|
1235 | - * |
|
1236 | - * @since 1.0.19 |
|
1237 | - * @return int subscription ID |
|
1238 | - */ |
|
1239 | - public function save() { |
|
1240 | - parent::save(); |
|
1241 | - $this->status_transition(); |
|
1242 | - return $this->get_id(); |
|
1243 | - } |
|
1244 | - |
|
1245 | - /** |
|
1246 | - * Activates a subscription. |
|
1247 | - * |
|
1248 | - * @since 1.0.19 |
|
1249 | - * @return int subscription ID |
|
1250 | - */ |
|
1251 | - public function activate() { |
|
1252 | - $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
1253 | - $this->set_status( $status ); |
|
1254 | - return $this->save(); |
|
1255 | - } |
|
1188 | + } |
|
1189 | + |
|
1190 | + /** |
|
1191 | + * Handle the status transition. |
|
1192 | + */ |
|
1193 | + protected function status_transition() { |
|
1194 | + $status_transition = $this->status_transition; |
|
1195 | + |
|
1196 | + // Reset status transition variable. |
|
1197 | + $this->status_transition = false; |
|
1198 | + |
|
1199 | + if ( $status_transition ) { |
|
1200 | + try { |
|
1201 | + |
|
1202 | + // Fire a hook for the status change. |
|
1203 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1204 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1205 | + |
|
1206 | + if ( ! empty( $status_transition['from'] ) ) { |
|
1207 | + |
|
1208 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
1209 | + $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'] ) ); |
|
1210 | + |
|
1211 | + // Note the transition occurred. |
|
1212 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1213 | + |
|
1214 | + // Fire another hook. |
|
1215 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1216 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1217 | + |
|
1218 | + } else { |
|
1219 | + /* translators: %s: new invoice status */ |
|
1220 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1221 | + |
|
1222 | + // Note the transition occurred. |
|
1223 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1224 | + |
|
1225 | + } |
|
1226 | + } catch ( Exception $e ) { |
|
1227 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1228 | + } |
|
1229 | + } |
|
1230 | + |
|
1231 | + } |
|
1232 | + |
|
1233 | + /** |
|
1234 | + * Save data to the database. |
|
1235 | + * |
|
1236 | + * @since 1.0.19 |
|
1237 | + * @return int subscription ID |
|
1238 | + */ |
|
1239 | + public function save() { |
|
1240 | + parent::save(); |
|
1241 | + $this->status_transition(); |
|
1242 | + return $this->get_id(); |
|
1243 | + } |
|
1244 | + |
|
1245 | + /** |
|
1246 | + * Activates a subscription. |
|
1247 | + * |
|
1248 | + * @since 1.0.19 |
|
1249 | + * @return int subscription ID |
|
1250 | + */ |
|
1251 | + public function activate() { |
|
1252 | + $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
1253 | + $this->set_status( $status ); |
|
1254 | + return $this->save(); |
|
1255 | + } |
|
1256 | 1256 | |
1257 | 1257 | } |
@@ -13,462 +13,462 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - |
|
141 | - // Register gateway. |
|
142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | - |
|
144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | - |
|
146 | - // Add support for various features. |
|
147 | - foreach ( $this->supports as $feature ) { |
|
148 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
149 | - } |
|
150 | - |
|
151 | - // Invoice addons. |
|
152 | - if ( $this->supports( 'addons' ) ) { |
|
153 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
154 | - } |
|
155 | - |
|
156 | - // Gateway settings. |
|
157 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + |
|
141 | + // Register gateway. |
|
142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
143 | + |
|
144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
145 | + |
|
146 | + // Add support for various features. |
|
147 | + foreach ( $this->supports as $feature ) { |
|
148 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
149 | + } |
|
150 | + |
|
151 | + // Invoice addons. |
|
152 | + if ( $this->supports( 'addons' ) ) { |
|
153 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
154 | + } |
|
155 | + |
|
156 | + // Gateway settings. |
|
157 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
158 | 158 | |
159 | 159 | |
160 | - // Gateway checkout fiellds. |
|
161 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
162 | - |
|
163 | - // Process payment. |
|
164 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
165 | - |
|
166 | - // Change the checkout button text. |
|
167 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
168 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
169 | - } |
|
170 | - |
|
171 | - // Check if a gateway is valid for a given currency. |
|
172 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
173 | - |
|
174 | - // Generate the transaction url. |
|
175 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
176 | - |
|
177 | - // Generate the subscription url. |
|
178 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
179 | - |
|
180 | - // Confirm payments. |
|
181 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
182 | - |
|
183 | - // Verify IPNs. |
|
184 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
185 | - |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Checks if this gateway is a given gateway. |
|
190 | - * |
|
191 | - * @since 1.0.19 |
|
192 | - * @return bool |
|
193 | - */ |
|
194 | - public function is( $gateway ) { |
|
195 | - return $gateway == $this->id; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Returns a users saved tokens for this gateway. |
|
200 | - * |
|
201 | - * @since 1.0.19 |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function get_tokens( $sandbox = null ) { |
|
205 | - |
|
206 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
207 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
208 | - |
|
209 | - if ( is_array( $tokens ) ) { |
|
210 | - $this->tokens = $tokens; |
|
211 | - } |
|
212 | - |
|
213 | - } |
|
214 | - |
|
215 | - if ( ! is_bool( $sandbox ) ) { |
|
216 | - return $this->tokens; |
|
217 | - } |
|
218 | - |
|
219 | - // Filter tokens. |
|
220 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | - return wp_list_filter( $this->tokens, $args ); |
|
222 | - |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Saves a token for this gateway. |
|
227 | - * |
|
228 | - * @since 1.0.19 |
|
229 | - */ |
|
230 | - public function save_token( $token ) { |
|
231 | - |
|
232 | - $tokens = $this->get_tokens(); |
|
233 | - $tokens[] = $token; |
|
234 | - |
|
235 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | - |
|
237 | - $this->tokens = $tokens; |
|
238 | - |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Return the title for admin screens. |
|
243 | - * |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public function get_method_title() { |
|
247 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Return the description for admin screens. |
|
252 | - * |
|
253 | - * @return string |
|
254 | - */ |
|
255 | - public function get_method_description() { |
|
256 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get the success url. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice Invoice object. |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function get_return_url( $invoice ) { |
|
266 | - |
|
267 | - // Payment success url |
|
268 | - $return_url = add_query_arg( |
|
269 | - array( |
|
270 | - 'payment-confirm' => $this->id, |
|
271 | - 'invoice_key' => $invoice->get_key(), |
|
272 | - 'utm_nooverride' => 1 |
|
273 | - ), |
|
274 | - wpinv_get_success_page_uri() |
|
275 | - ); |
|
276 | - |
|
277 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Confirms payments when rendering the success page. |
|
282 | - * |
|
283 | - * @param string $content Success page content. |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public function confirm_payment( $content ) { |
|
287 | - |
|
288 | - // Retrieve the invoice. |
|
289 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | - |
|
292 | - // Ensure that it exists and that it is pending payment. |
|
293 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | - return $content; |
|
295 | - } |
|
296 | - |
|
297 | - // Can the user view this invoice?? |
|
298 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | - return $content; |
|
300 | - } |
|
301 | - |
|
302 | - // Show payment processing indicator. |
|
303 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Processes ipns and marks payments as complete. |
|
308 | - * |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - public function verify_ipn() {} |
|
312 | - |
|
313 | - /** |
|
314 | - * Processes invoice addons. |
|
315 | - * |
|
316 | - * @param WPInv_Invoice $invoice |
|
317 | - * @param GetPaid_Form_Item[] $items |
|
318 | - * @return WPInv_Invoice |
|
319 | - */ |
|
320 | - public function process_addons( $invoice, $items ) { |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | - * |
|
327 | - * @param string $transaction_url transaction url. |
|
328 | - * @param WPInv_Invoice $invoice Invoice object. |
|
329 | - * @return string transaction URL, or empty string. |
|
330 | - */ |
|
331 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | - |
|
333 | - $transaction_id = $invoice->get_transaction_id(); |
|
334 | - |
|
335 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | - } |
|
340 | - |
|
341 | - return $transaction_url; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | - * |
|
347 | - * @param string $subscription_url transaction url. |
|
348 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | - * @return string subscription URL, or empty string. |
|
350 | - */ |
|
351 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | - |
|
353 | - $profile_id = $subscription->get_profile_id(); |
|
354 | - |
|
355 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | - |
|
357 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | - |
|
361 | - } |
|
362 | - |
|
363 | - return $subscription_url; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Check if the gateway is available for use. |
|
368 | - * |
|
369 | - * @return bool |
|
370 | - */ |
|
371 | - public function is_available() { |
|
372 | - return ! empty( $this->enabled ); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Return the gateway's title. |
|
377 | - * |
|
378 | - * @return string |
|
379 | - */ |
|
380 | - public function get_title() { |
|
381 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Return the gateway's description. |
|
386 | - * |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function get_description() { |
|
390 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Process Payment. |
|
395 | - * |
|
396 | - * |
|
397 | - * @param WPInv_Invoice $invoice Invoice. |
|
398 | - * @param array $submission_data Posted checkout fields. |
|
399 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | - * @return void |
|
401 | - */ |
|
402 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | - // Process the payment then either redirect to the success page or the gateway. |
|
404 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Process refund. |
|
409 | - * |
|
410 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | - * a passed in amount. |
|
412 | - * |
|
413 | - * @param WPInv_Invoice $invoice Invoice. |
|
414 | - * @param float $amount Refund amount. |
|
415 | - * @param string $reason Refund reason. |
|
416 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | - */ |
|
418 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Displays the payment fields, credit cards etc. |
|
424 | - * |
|
425 | - * @param int $invoice_id 0 or invoice id. |
|
426 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | - */ |
|
428 | - public function payment_fields( $invoice_id, $form ) { |
|
429 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Filters the gateway settings. |
|
434 | - * |
|
435 | - * @param array $admin_settings |
|
436 | - */ |
|
437 | - public function admin_settings( $admin_settings ) { |
|
438 | - return $admin_settings; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Retrieves the value of a gateway setting. |
|
443 | - * |
|
444 | - * @param string $option |
|
445 | - */ |
|
446 | - public function get_option( $option, $default = false ) { |
|
447 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Check if a gateway supports a given feature. |
|
452 | - * |
|
453 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | - * |
|
456 | - * @param string $feature string The name of a feature to test support for. |
|
457 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | - * @since 1.0.19 |
|
459 | - */ |
|
460 | - public function supports( $feature ) { |
|
461 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Returns the credit card form html. |
|
466 | - * |
|
467 | - * @param bool $save whether or not to display the save button. |
|
468 | - */ |
|
160 | + // Gateway checkout fiellds. |
|
161 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
162 | + |
|
163 | + // Process payment. |
|
164 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
165 | + |
|
166 | + // Change the checkout button text. |
|
167 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
168 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
169 | + } |
|
170 | + |
|
171 | + // Check if a gateway is valid for a given currency. |
|
172 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
173 | + |
|
174 | + // Generate the transaction url. |
|
175 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
176 | + |
|
177 | + // Generate the subscription url. |
|
178 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
179 | + |
|
180 | + // Confirm payments. |
|
181 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
182 | + |
|
183 | + // Verify IPNs. |
|
184 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
185 | + |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Checks if this gateway is a given gateway. |
|
190 | + * |
|
191 | + * @since 1.0.19 |
|
192 | + * @return bool |
|
193 | + */ |
|
194 | + public function is( $gateway ) { |
|
195 | + return $gateway == $this->id; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Returns a users saved tokens for this gateway. |
|
200 | + * |
|
201 | + * @since 1.0.19 |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function get_tokens( $sandbox = null ) { |
|
205 | + |
|
206 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
207 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
208 | + |
|
209 | + if ( is_array( $tokens ) ) { |
|
210 | + $this->tokens = $tokens; |
|
211 | + } |
|
212 | + |
|
213 | + } |
|
214 | + |
|
215 | + if ( ! is_bool( $sandbox ) ) { |
|
216 | + return $this->tokens; |
|
217 | + } |
|
218 | + |
|
219 | + // Filter tokens. |
|
220 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
221 | + return wp_list_filter( $this->tokens, $args ); |
|
222 | + |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Saves a token for this gateway. |
|
227 | + * |
|
228 | + * @since 1.0.19 |
|
229 | + */ |
|
230 | + public function save_token( $token ) { |
|
231 | + |
|
232 | + $tokens = $this->get_tokens(); |
|
233 | + $tokens[] = $token; |
|
234 | + |
|
235 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
236 | + |
|
237 | + $this->tokens = $tokens; |
|
238 | + |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Return the title for admin screens. |
|
243 | + * |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public function get_method_title() { |
|
247 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Return the description for admin screens. |
|
252 | + * |
|
253 | + * @return string |
|
254 | + */ |
|
255 | + public function get_method_description() { |
|
256 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get the success url. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice Invoice object. |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function get_return_url( $invoice ) { |
|
266 | + |
|
267 | + // Payment success url |
|
268 | + $return_url = add_query_arg( |
|
269 | + array( |
|
270 | + 'payment-confirm' => $this->id, |
|
271 | + 'invoice_key' => $invoice->get_key(), |
|
272 | + 'utm_nooverride' => 1 |
|
273 | + ), |
|
274 | + wpinv_get_success_page_uri() |
|
275 | + ); |
|
276 | + |
|
277 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Confirms payments when rendering the success page. |
|
282 | + * |
|
283 | + * @param string $content Success page content. |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public function confirm_payment( $content ) { |
|
287 | + |
|
288 | + // Retrieve the invoice. |
|
289 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
290 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
291 | + |
|
292 | + // Ensure that it exists and that it is pending payment. |
|
293 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
294 | + return $content; |
|
295 | + } |
|
296 | + |
|
297 | + // Can the user view this invoice?? |
|
298 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
299 | + return $content; |
|
300 | + } |
|
301 | + |
|
302 | + // Show payment processing indicator. |
|
303 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Processes ipns and marks payments as complete. |
|
308 | + * |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + public function verify_ipn() {} |
|
312 | + |
|
313 | + /** |
|
314 | + * Processes invoice addons. |
|
315 | + * |
|
316 | + * @param WPInv_Invoice $invoice |
|
317 | + * @param GetPaid_Form_Item[] $items |
|
318 | + * @return WPInv_Invoice |
|
319 | + */ |
|
320 | + public function process_addons( $invoice, $items ) { |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
326 | + * |
|
327 | + * @param string $transaction_url transaction url. |
|
328 | + * @param WPInv_Invoice $invoice Invoice object. |
|
329 | + * @return string transaction URL, or empty string. |
|
330 | + */ |
|
331 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
332 | + |
|
333 | + $transaction_id = $invoice->get_transaction_id(); |
|
334 | + |
|
335 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
336 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
337 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
338 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
339 | + } |
|
340 | + |
|
341 | + return $transaction_url; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
346 | + * |
|
347 | + * @param string $subscription_url transaction url. |
|
348 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
349 | + * @return string subscription URL, or empty string. |
|
350 | + */ |
|
351 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
352 | + |
|
353 | + $profile_id = $subscription->get_profile_id(); |
|
354 | + |
|
355 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
356 | + |
|
357 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
358 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
359 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
360 | + |
|
361 | + } |
|
362 | + |
|
363 | + return $subscription_url; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Check if the gateway is available for use. |
|
368 | + * |
|
369 | + * @return bool |
|
370 | + */ |
|
371 | + public function is_available() { |
|
372 | + return ! empty( $this->enabled ); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Return the gateway's title. |
|
377 | + * |
|
378 | + * @return string |
|
379 | + */ |
|
380 | + public function get_title() { |
|
381 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Return the gateway's description. |
|
386 | + * |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function get_description() { |
|
390 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Process Payment. |
|
395 | + * |
|
396 | + * |
|
397 | + * @param WPInv_Invoice $invoice Invoice. |
|
398 | + * @param array $submission_data Posted checkout fields. |
|
399 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
400 | + * @return void |
|
401 | + */ |
|
402 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
403 | + // Process the payment then either redirect to the success page or the gateway. |
|
404 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Process refund. |
|
409 | + * |
|
410 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
411 | + * a passed in amount. |
|
412 | + * |
|
413 | + * @param WPInv_Invoice $invoice Invoice. |
|
414 | + * @param float $amount Refund amount. |
|
415 | + * @param string $reason Refund reason. |
|
416 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
417 | + */ |
|
418 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
419 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Displays the payment fields, credit cards etc. |
|
424 | + * |
|
425 | + * @param int $invoice_id 0 or invoice id. |
|
426 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
427 | + */ |
|
428 | + public function payment_fields( $invoice_id, $form ) { |
|
429 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Filters the gateway settings. |
|
434 | + * |
|
435 | + * @param array $admin_settings |
|
436 | + */ |
|
437 | + public function admin_settings( $admin_settings ) { |
|
438 | + return $admin_settings; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Retrieves the value of a gateway setting. |
|
443 | + * |
|
444 | + * @param string $option |
|
445 | + */ |
|
446 | + public function get_option( $option, $default = false ) { |
|
447 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Check if a gateway supports a given feature. |
|
452 | + * |
|
453 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
454 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
455 | + * |
|
456 | + * @param string $feature string The name of a feature to test support for. |
|
457 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
458 | + * @since 1.0.19 |
|
459 | + */ |
|
460 | + public function supports( $feature ) { |
|
461 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Returns the credit card form html. |
|
466 | + * |
|
467 | + * @param bool $save whether or not to display the save button. |
|
468 | + */ |
|
469 | 469 | public function get_cc_form( $save = false ) { |
470 | 470 | |
471 | - ob_start(); |
|
471 | + ob_start(); |
|
472 | 472 | |
473 | 473 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
474 | 474 | |
@@ -563,11 +563,11 @@ discard block |
||
563 | 563 | 'name' => $this->id . '[cc_cvv2]', |
564 | 564 | 'id' => "$id_prefix-cc-cvv2", |
565 | 565 | 'label' => __( 'CCV', 'invoicing' ), |
566 | - 'label_type' => 'vertical', |
|
567 | - 'class' => 'form-control-sm', |
|
568 | - 'extra_attributes' => array( |
|
569 | - 'autocomplete' => "cc-csc", |
|
570 | - ), |
|
566 | + 'label_type' => 'vertical', |
|
567 | + 'class' => 'form-control-sm', |
|
568 | + 'extra_attributes' => array( |
|
569 | + 'autocomplete' => "cc-csc", |
|
570 | + ), |
|
571 | 571 | ) |
572 | 572 | ); |
573 | 573 | ?> |
@@ -577,192 +577,192 @@ discard block |
||
577 | 577 | |
578 | 578 | <?php |
579 | 579 | |
580 | - if ( $save ) { |
|
581 | - echo $this->save_payment_method_checkbox(); |
|
582 | - } |
|
580 | + if ( $save ) { |
|
581 | + echo $this->save_payment_method_checkbox(); |
|
582 | + } |
|
583 | 583 | |
584 | - ?> |
|
584 | + ?> |
|
585 | 585 | </div> |
586 | 586 | |
587 | 587 | </div> |
588 | 588 | <?php |
589 | 589 | |
590 | - return ob_get_clean(); |
|
590 | + return ob_get_clean(); |
|
591 | + |
|
592 | + } |
|
591 | 593 | |
594 | + /** |
|
595 | + * Displays a new payment method entry form. |
|
596 | + * |
|
597 | + * @since 1.0.19 |
|
598 | + */ |
|
599 | + public function new_payment_method_entry( $form ) { |
|
600 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
592 | 601 | } |
593 | 602 | |
594 | - /** |
|
595 | - * Displays a new payment method entry form. |
|
596 | - * |
|
597 | - * @since 1.0.19 |
|
598 | - */ |
|
599 | - public function new_payment_method_entry( $form ) { |
|
600 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
601 | - } |
|
602 | - |
|
603 | - /** |
|
604 | - * Grab and display our saved payment methods. |
|
605 | - * |
|
606 | - * @since 1.0.19 |
|
607 | - */ |
|
608 | - public function saved_payment_methods() { |
|
609 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
610 | - |
|
611 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
612 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
613 | - } |
|
614 | - |
|
615 | - $html .= $this->get_new_payment_method_option_html(); |
|
616 | - $html .= '</ul>'; |
|
617 | - |
|
618 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Gets saved payment method HTML from a token. |
|
623 | - * |
|
624 | - * @since 1.0.19 |
|
625 | - * @param array $token Payment Token. |
|
626 | - * @return string Generated payment method HTML |
|
627 | - */ |
|
628 | - public function get_saved_payment_method_option_html( $token ) { |
|
629 | - |
|
630 | - return sprintf( |
|
631 | - '<li class="getpaid-payment-method form-group"> |
|
603 | + /** |
|
604 | + * Grab and display our saved payment methods. |
|
605 | + * |
|
606 | + * @since 1.0.19 |
|
607 | + */ |
|
608 | + public function saved_payment_methods() { |
|
609 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
610 | + |
|
611 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
612 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
613 | + } |
|
614 | + |
|
615 | + $html .= $this->get_new_payment_method_option_html(); |
|
616 | + $html .= '</ul>'; |
|
617 | + |
|
618 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Gets saved payment method HTML from a token. |
|
623 | + * |
|
624 | + * @since 1.0.19 |
|
625 | + * @param array $token Payment Token. |
|
626 | + * @return string Generated payment method HTML |
|
627 | + */ |
|
628 | + public function get_saved_payment_method_option_html( $token ) { |
|
629 | + |
|
630 | + return sprintf( |
|
631 | + '<li class="getpaid-payment-method form-group"> |
|
632 | 632 | <label> |
633 | 633 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
634 | 634 | <span>%3$s</span> |
635 | 635 | </label> |
636 | 636 | </li>', |
637 | - esc_attr( $this->id ), |
|
638 | - esc_attr( $token['id'] ), |
|
639 | - esc_html( $token['name'] ), |
|
640 | - checked( empty( $token['default'] ), false, false ), |
|
641 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
642 | - ); |
|
643 | - |
|
644 | - } |
|
645 | - |
|
646 | - /** |
|
647 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
648 | - * |
|
649 | - * @since 1.0.19 |
|
650 | - */ |
|
651 | - public function get_new_payment_method_option_html() { |
|
652 | - |
|
653 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
654 | - |
|
655 | - return sprintf( |
|
656 | - '<li class="getpaid-new-payment-method"> |
|
637 | + esc_attr( $this->id ), |
|
638 | + esc_attr( $token['id'] ), |
|
639 | + esc_html( $token['name'] ), |
|
640 | + checked( empty( $token['default'] ), false, false ), |
|
641 | + empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
642 | + ); |
|
643 | + |
|
644 | + } |
|
645 | + |
|
646 | + /** |
|
647 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
648 | + * |
|
649 | + * @since 1.0.19 |
|
650 | + */ |
|
651 | + public function get_new_payment_method_option_html() { |
|
652 | + |
|
653 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
654 | + |
|
655 | + return sprintf( |
|
656 | + '<li class="getpaid-new-payment-method"> |
|
657 | 657 | <label> |
658 | 658 | <input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" /> |
659 | 659 | <span>%2$s</span> |
660 | 660 | </label> |
661 | 661 | </li>', |
662 | - esc_attr( $this->id ), |
|
663 | - esc_html( $label ) |
|
664 | - ); |
|
665 | - |
|
666 | - } |
|
667 | - |
|
668 | - /** |
|
669 | - * Outputs a checkbox for saving a new payment method to the database. |
|
670 | - * |
|
671 | - * @since 1.0.19 |
|
672 | - */ |
|
673 | - public function save_payment_method_checkbox() { |
|
674 | - |
|
675 | - return aui()->input( |
|
676 | - array( |
|
677 | - 'type' => 'checkbox', |
|
678 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
679 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
680 | - 'required' => false, |
|
681 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
682 | - 'value' => 'true', |
|
683 | - 'checked' => true, |
|
684 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
685 | - ) |
|
686 | - ); |
|
687 | - |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Registers the gateway. |
|
692 | - * |
|
693 | - * @return array |
|
694 | - */ |
|
695 | - public function register_gateway( $gateways ) { |
|
696 | - |
|
697 | - $gateways[ $this->id ] = array( |
|
698 | - |
|
699 | - 'admin_label' => $this->method_title, |
|
662 | + esc_attr( $this->id ), |
|
663 | + esc_html( $label ) |
|
664 | + ); |
|
665 | + |
|
666 | + } |
|
667 | + |
|
668 | + /** |
|
669 | + * Outputs a checkbox for saving a new payment method to the database. |
|
670 | + * |
|
671 | + * @since 1.0.19 |
|
672 | + */ |
|
673 | + public function save_payment_method_checkbox() { |
|
674 | + |
|
675 | + return aui()->input( |
|
676 | + array( |
|
677 | + 'type' => 'checkbox', |
|
678 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
679 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
680 | + 'required' => false, |
|
681 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
682 | + 'value' => 'true', |
|
683 | + 'checked' => true, |
|
684 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
685 | + ) |
|
686 | + ); |
|
687 | + |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Registers the gateway. |
|
692 | + * |
|
693 | + * @return array |
|
694 | + */ |
|
695 | + public function register_gateway( $gateways ) { |
|
696 | + |
|
697 | + $gateways[ $this->id ] = array( |
|
698 | + |
|
699 | + 'admin_label' => $this->method_title, |
|
700 | 700 | 'checkout_label' => $this->title, |
701 | - 'ordering' => $this->order, |
|
701 | + 'ordering' => $this->order, |
|
702 | 702 | |
703 | - ); |
|
703 | + ); |
|
704 | 704 | |
705 | - return $gateways; |
|
705 | + return $gateways; |
|
706 | 706 | |
707 | - } |
|
707 | + } |
|
708 | 708 | |
709 | - /** |
|
710 | - * Checks whether or not this is a sandbox request. |
|
711 | - * |
|
712 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
713 | - * @return bool |
|
714 | - */ |
|
715 | - public function is_sandbox( $invoice = null ) { |
|
709 | + /** |
|
710 | + * Checks whether or not this is a sandbox request. |
|
711 | + * |
|
712 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
713 | + * @return bool |
|
714 | + */ |
|
715 | + public function is_sandbox( $invoice = null ) { |
|
716 | 716 | |
717 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
718 | - return $invoice->get_mode() == 'test'; |
|
719 | - } |
|
717 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
718 | + return $invoice->get_mode() == 'test'; |
|
719 | + } |
|
720 | 720 | |
721 | - return wpinv_is_test_mode( $this->id ); |
|
721 | + return wpinv_is_test_mode( $this->id ); |
|
722 | 722 | |
723 | - } |
|
723 | + } |
|
724 | 724 | |
725 | - /** |
|
726 | - * Renames the checkout button |
|
727 | - * |
|
728 | - * @return string |
|
729 | - */ |
|
730 | - public function rename_checkout_button() { |
|
731 | - return $this->checkout_button_text; |
|
732 | - } |
|
725 | + /** |
|
726 | + * Renames the checkout button |
|
727 | + * |
|
728 | + * @return string |
|
729 | + */ |
|
730 | + public function rename_checkout_button() { |
|
731 | + return $this->checkout_button_text; |
|
732 | + } |
|
733 | 733 | |
734 | - /** |
|
735 | - * Validate gateway currency |
|
736 | - * |
|
737 | - * @return bool |
|
738 | - */ |
|
739 | - public function validate_currency( $validation, $currency ) { |
|
734 | + /** |
|
735 | + * Validate gateway currency |
|
736 | + * |
|
737 | + * @return bool |
|
738 | + */ |
|
739 | + public function validate_currency( $validation, $currency ) { |
|
740 | 740 | |
741 | - // Required currencies. |
|
742 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
743 | - return false; |
|
744 | - } |
|
741 | + // Required currencies. |
|
742 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
743 | + return false; |
|
744 | + } |
|
745 | 745 | |
746 | - // Excluded currencies. |
|
747 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
748 | - return false; |
|
749 | - } |
|
746 | + // Excluded currencies. |
|
747 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
748 | + return false; |
|
749 | + } |
|
750 | 750 | |
751 | - return $validation; |
|
752 | - } |
|
751 | + return $validation; |
|
752 | + } |
|
753 | 753 | |
754 | - /** |
|
755 | - * Displays an error |
|
756 | - * |
|
757 | - */ |
|
758 | - public function show_error( $code, $message, $type ) { |
|
754 | + /** |
|
755 | + * Displays an error |
|
756 | + * |
|
757 | + */ |
|
758 | + public function show_error( $code, $message, $type ) { |
|
759 | 759 | |
760 | - if ( is_admin() ) { |
|
761 | - getpaid_admin()->{"show_$type"}( $message ); |
|
762 | - } |
|
760 | + if ( is_admin() ) { |
|
761 | + getpaid_admin()->{"show_$type"}( $message ); |
|
762 | + } |
|
763 | 763 | |
764 | - wpinv_set_error( $code, $message, $type ); |
|
764 | + wpinv_set_error( $code, $message, $type ); |
|
765 | 765 | |
766 | - } |
|
766 | + } |
|
767 | 767 | |
768 | 768 | } |
@@ -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,236 +21,236 @@ 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 = '0.1.47'; |
|
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.5.3"; |
|
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 | - |
|
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 | - $priority = $this->is_bs3_compat() ? 100 : 1; |
|
156 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
|
157 | - } |
|
158 | - if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
159 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
160 | - } |
|
161 | - |
|
162 | - // Maybe set the HTML font size |
|
163 | - if ( $this->settings['html_font_size'] ) { |
|
164 | - add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Check if we should load the admin scripts or not. |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function load_admin_scripts(){ |
|
176 | - $result = true; |
|
177 | - |
|
178 | - // check if specifically disabled |
|
179 | - if(!empty($this->settings['disable_admin'])){ |
|
180 | - $url_parts = explode("\n",$this->settings['disable_admin']); |
|
181 | - foreach($url_parts as $part){ |
|
182 | - if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
183 | - return false; // return early, no point checking further |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - return $result; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Add a html font size to the footer. |
|
193 | - */ |
|
194 | - public function html_font_size(){ |
|
195 | - $this->settings = $this->get_settings(); |
|
196 | - echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
197 | - } |
|
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 = '0.1.47'; |
|
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.5.3"; |
|
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 | + } |
|
198 | 114 | |
199 | - /** |
|
200 | - * Check if the current admin screen should load scripts. |
|
201 | - * |
|
202 | - * @return bool |
|
203 | - */ |
|
204 | - public function is_aui_screen(){ |
|
205 | - $load = false; |
|
206 | - // check if we should load or not |
|
207 | - if ( is_admin() ) { |
|
208 | - // Only enable on set pages |
|
209 | - $aui_screens = array( |
|
210 | - 'page', |
|
211 | - 'post', |
|
212 | - 'settings_page_ayecode-ui-settings', |
|
213 | - 'appearance_page_gutenberg-widgets' |
|
214 | - ); |
|
215 | - $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
|
216 | - |
|
217 | - $screen = get_current_screen(); |
|
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 | + $priority = $this->is_bs3_compat() ? 100 : 1; |
|
156 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
|
157 | + } |
|
158 | + if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
159 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
160 | + } |
|
161 | + |
|
162 | + // Maybe set the HTML font size |
|
163 | + if ( $this->settings['html_font_size'] ) { |
|
164 | + add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Check if we should load the admin scripts or not. |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function load_admin_scripts(){ |
|
176 | + $result = true; |
|
177 | + |
|
178 | + // check if specifically disabled |
|
179 | + if(!empty($this->settings['disable_admin'])){ |
|
180 | + $url_parts = explode("\n",$this->settings['disable_admin']); |
|
181 | + foreach($url_parts as $part){ |
|
182 | + if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
183 | + return false; // return early, no point checking further |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + return $result; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Add a html font size to the footer. |
|
193 | + */ |
|
194 | + public function html_font_size(){ |
|
195 | + $this->settings = $this->get_settings(); |
|
196 | + echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Check if the current admin screen should load scripts. |
|
201 | + * |
|
202 | + * @return bool |
|
203 | + */ |
|
204 | + public function is_aui_screen(){ |
|
205 | + $load = false; |
|
206 | + // check if we should load or not |
|
207 | + if ( is_admin() ) { |
|
208 | + // Only enable on set pages |
|
209 | + $aui_screens = array( |
|
210 | + 'page', |
|
211 | + 'post', |
|
212 | + 'settings_page_ayecode-ui-settings', |
|
213 | + 'appearance_page_gutenberg-widgets' |
|
214 | + ); |
|
215 | + $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
|
216 | + |
|
217 | + $screen = get_current_screen(); |
|
218 | 218 | |
219 | 219 | // echo '###'.$screen->id; |
220 | 220 | |
221 | - if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
|
222 | - $load = true; |
|
223 | - } |
|
224 | - } |
|
221 | + if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
|
222 | + $load = true; |
|
223 | + } |
|
224 | + } |
|
225 | 225 | |
226 | - return $load; |
|
227 | - } |
|
226 | + return $load; |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Adds the styles. |
|
231 | - */ |
|
232 | - public function enqueue_style() { |
|
229 | + /** |
|
230 | + * Adds the styles. |
|
231 | + */ |
|
232 | + public function enqueue_style() { |
|
233 | 233 | |
234 | - if( is_admin() && !$this->is_aui_screen()){ |
|
235 | - // don't add wp-admin scripts if not requested to |
|
236 | - }else{ |
|
237 | - $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
234 | + if( is_admin() && !$this->is_aui_screen()){ |
|
235 | + // don't add wp-admin scripts if not requested to |
|
236 | + }else{ |
|
237 | + $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
238 | 238 | |
239 | - $rtl = is_rtl() ? '-rtl' : ''; |
|
239 | + $rtl = is_rtl() ? '-rtl' : ''; |
|
240 | 240 | |
241 | - if($this->settings[$css_setting]){ |
|
242 | - $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
243 | - $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
|
244 | - wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
245 | - wp_enqueue_style( 'ayecode-ui' ); |
|
241 | + if($this->settings[$css_setting]){ |
|
242 | + $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
243 | + $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
|
244 | + wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
245 | + wp_enqueue_style( 'ayecode-ui' ); |
|
246 | 246 | |
247 | - // flatpickr |
|
248 | - wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
247 | + // flatpickr |
|
248 | + wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
249 | 249 | |
250 | 250 | |
251 | - // fix some wp-admin issues |
|
252 | - if(is_admin()){ |
|
253 | - $custom_css = " |
|
251 | + // fix some wp-admin issues |
|
252 | + if(is_admin()){ |
|
253 | + $custom_css = " |
|
254 | 254 | body{ |
255 | 255 | background-color: #f1f1f1; |
256 | 256 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
@@ -289,35 +289,35 @@ discard block |
||
289 | 289 | } |
290 | 290 | "; |
291 | 291 | |
292 | - // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
293 | - $custom_css .= " |
|
292 | + // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
293 | + $custom_css .= " |
|
294 | 294 | .edit-post-sidebar input[type=color].components-text-control__input{ |
295 | 295 | padding: 0; |
296 | 296 | } |
297 | 297 | "; |
298 | - wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
299 | - } |
|
298 | + wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
299 | + } |
|
300 | 300 | |
301 | - // custom changes |
|
302 | - wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
301 | + // custom changes |
|
302 | + wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
303 | 303 | |
304 | - } |
|
305 | - } |
|
304 | + } |
|
305 | + } |
|
306 | 306 | |
307 | 307 | |
308 | - } |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Get inline script used if bootstrap enqueued |
|
312 | + * |
|
313 | + * If this remains small then its best to use this than to add another JS file. |
|
314 | + */ |
|
315 | + public function inline_script() { |
|
316 | + // Flatpickr calendar locale |
|
317 | + $flatpickr_locale = self::flatpickr_locale(); |
|
309 | 318 | |
310 | - /** |
|
311 | - * Get inline script used if bootstrap enqueued |
|
312 | - * |
|
313 | - * If this remains small then its best to use this than to add another JS file. |
|
314 | - */ |
|
315 | - public function inline_script() { |
|
316 | - // Flatpickr calendar locale |
|
317 | - $flatpickr_locale = self::flatpickr_locale(); |
|
318 | - |
|
319 | - ob_start(); |
|
320 | - ?> |
|
319 | + ob_start(); |
|
320 | + ?> |
|
321 | 321 | <script> |
322 | 322 | /** |
323 | 323 | * An AUI bootstrap adaptation of GreedyNav.js ( by Luke Jackson ). |
@@ -982,29 +982,29 @@ discard block |
||
982 | 982 | |
983 | 983 | </script> |
984 | 984 | <?php |
985 | - $output = ob_get_clean(); |
|
985 | + $output = ob_get_clean(); |
|
986 | 986 | |
987 | 987 | |
988 | 988 | |
989 | - /* |
|
989 | + /* |
|
990 | 990 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
991 | 991 | */ |
992 | - return str_replace( array( |
|
993 | - '<script>', |
|
994 | - '</script>' |
|
995 | - ), '', self::minify_js($output) ); |
|
996 | - } |
|
997 | - |
|
998 | - |
|
999 | - /** |
|
1000 | - * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1001 | - * |
|
1002 | - * @TODO we may need this when other conflicts arrise. |
|
1003 | - * @return mixed |
|
1004 | - */ |
|
1005 | - public static function bs3_compat_js() { |
|
1006 | - ob_start(); |
|
1007 | - ?> |
|
992 | + return str_replace( array( |
|
993 | + '<script>', |
|
994 | + '</script>' |
|
995 | + ), '', self::minify_js($output) ); |
|
996 | + } |
|
997 | + |
|
998 | + |
|
999 | + /** |
|
1000 | + * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1001 | + * |
|
1002 | + * @TODO we may need this when other conflicts arrise. |
|
1003 | + * @return mixed |
|
1004 | + */ |
|
1005 | + public static function bs3_compat_js() { |
|
1006 | + ob_start(); |
|
1007 | + ?> |
|
1008 | 1008 | <script> |
1009 | 1009 | <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?> |
1010 | 1010 | /* With Avada builder */ |
@@ -1012,20 +1012,20 @@ discard block |
||
1012 | 1012 | <?php } ?> |
1013 | 1013 | </script> |
1014 | 1014 | <?php |
1015 | - return str_replace( array( |
|
1016 | - '<script>', |
|
1017 | - '</script>' |
|
1018 | - ), '', ob_get_clean()); |
|
1019 | - } |
|
1020 | - |
|
1021 | - /** |
|
1022 | - * Get inline script used if bootstrap file browser enqueued. |
|
1023 | - * |
|
1024 | - * If this remains small then its best to use this than to add another JS file. |
|
1025 | - */ |
|
1026 | - public function inline_script_file_browser(){ |
|
1027 | - ob_start(); |
|
1028 | - ?> |
|
1015 | + return str_replace( array( |
|
1016 | + '<script>', |
|
1017 | + '</script>' |
|
1018 | + ), '', ob_get_clean()); |
|
1019 | + } |
|
1020 | + |
|
1021 | + /** |
|
1022 | + * Get inline script used if bootstrap file browser enqueued. |
|
1023 | + * |
|
1024 | + * If this remains small then its best to use this than to add another JS file. |
|
1025 | + */ |
|
1026 | + public function inline_script_file_browser(){ |
|
1027 | + ob_start(); |
|
1028 | + ?> |
|
1029 | 1029 | <script> |
1030 | 1030 | // run on doc ready |
1031 | 1031 | jQuery(document).ready(function () { |
@@ -1033,192 +1033,192 @@ discard block |
||
1033 | 1033 | }); |
1034 | 1034 | </script> |
1035 | 1035 | <?php |
1036 | - $output = ob_get_clean(); |
|
1036 | + $output = ob_get_clean(); |
|
1037 | 1037 | |
1038 | - /* |
|
1038 | + /* |
|
1039 | 1039 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1040 | 1040 | */ |
1041 | - return str_replace( array( |
|
1042 | - '<script>', |
|
1043 | - '</script>' |
|
1044 | - ), '', $output ); |
|
1045 | - } |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * Adds the Font Awesome JS. |
|
1049 | - */ |
|
1050 | - public function enqueue_scripts() { |
|
1051 | - |
|
1052 | - if( is_admin() && !$this->is_aui_screen()){ |
|
1053 | - // don't add wp-admin scripts if not requested to |
|
1054 | - }else { |
|
1055 | - |
|
1056 | - $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
1057 | - |
|
1058 | - // select2 |
|
1059 | - wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
|
1060 | - |
|
1061 | - // flatpickr |
|
1062 | - wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
1063 | - |
|
1064 | - // Bootstrap file browser |
|
1065 | - wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
|
1066 | - wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
1067 | - |
|
1068 | - $load_inline = false; |
|
1069 | - |
|
1070 | - if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
|
1071 | - // Bootstrap bundle |
|
1072 | - $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
|
1073 | - wp_register_script( 'bootstrap-js-bundle', $url, array( |
|
1074 | - 'select2', |
|
1075 | - 'jquery' |
|
1076 | - ), $this->latest, $this->is_bs3_compat() ); |
|
1077 | - // if in admin then add to footer for compatibility. |
|
1078 | - is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
|
1079 | - $script = $this->inline_script(); |
|
1080 | - wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
1081 | - } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
|
1082 | - $url = $this->url . 'assets/js/popper.min.js'; |
|
1083 | - wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest ); |
|
1084 | - wp_enqueue_script( 'bootstrap-js-popper' ); |
|
1085 | - $load_inline = true; |
|
1086 | - } else { |
|
1087 | - $load_inline = true; |
|
1088 | - } |
|
1089 | - |
|
1090 | - // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
1091 | - if ( $load_inline ) { |
|
1092 | - wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
|
1093 | - wp_enqueue_script( 'bootstrap-dummy' ); |
|
1094 | - $script = $this->inline_script(); |
|
1095 | - wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
1096 | - } |
|
1097 | - } |
|
1098 | - |
|
1099 | - } |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Enqueue flatpickr if called. |
|
1103 | - */ |
|
1104 | - public function enqueue_flatpickr(){ |
|
1105 | - wp_enqueue_style( 'flatpickr' ); |
|
1106 | - wp_enqueue_script( 'flatpickr' ); |
|
1107 | - } |
|
1108 | - |
|
1109 | - /** |
|
1110 | - * Get the url path to the current folder. |
|
1111 | - * |
|
1112 | - * @return string |
|
1113 | - */ |
|
1114 | - public function get_url() { |
|
1115 | - |
|
1116 | - $url = ''; |
|
1117 | - // check if we are inside a plugin |
|
1118 | - $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
1119 | - |
|
1120 | - // add check in-case user has changed wp-content dir name. |
|
1121 | - $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
1122 | - $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
1123 | - $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
1124 | - |
|
1125 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
1126 | - $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
1127 | - } |
|
1128 | - |
|
1129 | - return $url; |
|
1130 | - } |
|
1131 | - |
|
1132 | - /** |
|
1133 | - * Register the database settings with WordPress. |
|
1134 | - */ |
|
1135 | - public function register_settings() { |
|
1136 | - register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
1137 | - } |
|
1138 | - |
|
1139 | - /** |
|
1140 | - * Add the WordPress settings menu item. |
|
1141 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
1142 | - */ |
|
1143 | - public function menu_item() { |
|
1144 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
1145 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
1146 | - $this, |
|
1147 | - 'settings_page' |
|
1148 | - ) ); |
|
1149 | - } |
|
1150 | - |
|
1151 | - /** |
|
1152 | - * Get a list of themes and their default JS settings. |
|
1153 | - * |
|
1154 | - * @return array |
|
1155 | - */ |
|
1156 | - public function theme_js_settings(){ |
|
1157 | - return array( |
|
1158 | - 'ayetheme' => 'popper', |
|
1159 | - 'listimia' => 'required', |
|
1160 | - 'listimia_backend' => 'core-popper', |
|
1161 | - //'avada' => 'required', // removed as we now add compatibility |
|
1162 | - ); |
|
1163 | - } |
|
1164 | - |
|
1165 | - /** |
|
1166 | - * Get the current Font Awesome output settings. |
|
1167 | - * |
|
1168 | - * @return array The array of settings. |
|
1169 | - */ |
|
1170 | - public function get_settings() { |
|
1171 | - |
|
1172 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
1173 | - $js_default = 'core-popper'; |
|
1174 | - $js_default_backend = $js_default; |
|
1175 | - |
|
1176 | - // maybe set defaults (if no settings set) |
|
1177 | - if(empty($db_settings)){ |
|
1178 | - $active_theme = strtolower( get_template() ); // active parent theme. |
|
1179 | - $theme_js_settings = self::theme_js_settings(); |
|
1180 | - if(isset($theme_js_settings[$active_theme])){ |
|
1181 | - $js_default = $theme_js_settings[$active_theme]; |
|
1182 | - $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
1183 | - } |
|
1184 | - } |
|
1185 | - |
|
1186 | - $defaults = array( |
|
1187 | - 'css' => 'compatibility', // core, compatibility |
|
1188 | - 'js' => $js_default, // js to load, core-popper, popper |
|
1189 | - 'html_font_size' => '16', // js to load, core-popper, popper |
|
1190 | - 'css_backend' => 'compatibility', // core, compatibility |
|
1191 | - 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
1192 | - 'disable_admin' => '', // URL snippets to disable loading on admin |
|
1193 | - ); |
|
1194 | - |
|
1195 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
1196 | - |
|
1197 | - /** |
|
1198 | - * Filter the Bootstrap settings. |
|
1199 | - * |
|
1200 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
1201 | - */ |
|
1202 | - return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
1203 | - } |
|
1204 | - |
|
1041 | + return str_replace( array( |
|
1042 | + '<script>', |
|
1043 | + '</script>' |
|
1044 | + ), '', $output ); |
|
1045 | + } |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * Adds the Font Awesome JS. |
|
1049 | + */ |
|
1050 | + public function enqueue_scripts() { |
|
1051 | + |
|
1052 | + if( is_admin() && !$this->is_aui_screen()){ |
|
1053 | + // don't add wp-admin scripts if not requested to |
|
1054 | + }else { |
|
1055 | + |
|
1056 | + $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
1057 | + |
|
1058 | + // select2 |
|
1059 | + wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
|
1060 | + |
|
1061 | + // flatpickr |
|
1062 | + wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
1063 | + |
|
1064 | + // Bootstrap file browser |
|
1065 | + wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
|
1066 | + wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
1067 | + |
|
1068 | + $load_inline = false; |
|
1069 | + |
|
1070 | + if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
|
1071 | + // Bootstrap bundle |
|
1072 | + $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
|
1073 | + wp_register_script( 'bootstrap-js-bundle', $url, array( |
|
1074 | + 'select2', |
|
1075 | + 'jquery' |
|
1076 | + ), $this->latest, $this->is_bs3_compat() ); |
|
1077 | + // if in admin then add to footer for compatibility. |
|
1078 | + is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
|
1079 | + $script = $this->inline_script(); |
|
1080 | + wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
1081 | + } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
|
1082 | + $url = $this->url . 'assets/js/popper.min.js'; |
|
1083 | + wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest ); |
|
1084 | + wp_enqueue_script( 'bootstrap-js-popper' ); |
|
1085 | + $load_inline = true; |
|
1086 | + } else { |
|
1087 | + $load_inline = true; |
|
1088 | + } |
|
1205 | 1089 | |
1206 | - /** |
|
1207 | - * The settings page html output. |
|
1208 | - */ |
|
1209 | - public function settings_page() { |
|
1210 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1211 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
1212 | - } |
|
1213 | - ?> |
|
1090 | + // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
1091 | + if ( $load_inline ) { |
|
1092 | + wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
|
1093 | + wp_enqueue_script( 'bootstrap-dummy' ); |
|
1094 | + $script = $this->inline_script(); |
|
1095 | + wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
1096 | + } |
|
1097 | + } |
|
1098 | + |
|
1099 | + } |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Enqueue flatpickr if called. |
|
1103 | + */ |
|
1104 | + public function enqueue_flatpickr(){ |
|
1105 | + wp_enqueue_style( 'flatpickr' ); |
|
1106 | + wp_enqueue_script( 'flatpickr' ); |
|
1107 | + } |
|
1108 | + |
|
1109 | + /** |
|
1110 | + * Get the url path to the current folder. |
|
1111 | + * |
|
1112 | + * @return string |
|
1113 | + */ |
|
1114 | + public function get_url() { |
|
1115 | + |
|
1116 | + $url = ''; |
|
1117 | + // check if we are inside a plugin |
|
1118 | + $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
1119 | + |
|
1120 | + // add check in-case user has changed wp-content dir name. |
|
1121 | + $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
1122 | + $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
1123 | + $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
1124 | + |
|
1125 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
1126 | + $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
1127 | + } |
|
1128 | + |
|
1129 | + return $url; |
|
1130 | + } |
|
1131 | + |
|
1132 | + /** |
|
1133 | + * Register the database settings with WordPress. |
|
1134 | + */ |
|
1135 | + public function register_settings() { |
|
1136 | + register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
1137 | + } |
|
1138 | + |
|
1139 | + /** |
|
1140 | + * Add the WordPress settings menu item. |
|
1141 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
1142 | + */ |
|
1143 | + public function menu_item() { |
|
1144 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
1145 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
1146 | + $this, |
|
1147 | + 'settings_page' |
|
1148 | + ) ); |
|
1149 | + } |
|
1150 | + |
|
1151 | + /** |
|
1152 | + * Get a list of themes and their default JS settings. |
|
1153 | + * |
|
1154 | + * @return array |
|
1155 | + */ |
|
1156 | + public function theme_js_settings(){ |
|
1157 | + return array( |
|
1158 | + 'ayetheme' => 'popper', |
|
1159 | + 'listimia' => 'required', |
|
1160 | + 'listimia_backend' => 'core-popper', |
|
1161 | + //'avada' => 'required', // removed as we now add compatibility |
|
1162 | + ); |
|
1163 | + } |
|
1164 | + |
|
1165 | + /** |
|
1166 | + * Get the current Font Awesome output settings. |
|
1167 | + * |
|
1168 | + * @return array The array of settings. |
|
1169 | + */ |
|
1170 | + public function get_settings() { |
|
1171 | + |
|
1172 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
1173 | + $js_default = 'core-popper'; |
|
1174 | + $js_default_backend = $js_default; |
|
1175 | + |
|
1176 | + // maybe set defaults (if no settings set) |
|
1177 | + if(empty($db_settings)){ |
|
1178 | + $active_theme = strtolower( get_template() ); // active parent theme. |
|
1179 | + $theme_js_settings = self::theme_js_settings(); |
|
1180 | + if(isset($theme_js_settings[$active_theme])){ |
|
1181 | + $js_default = $theme_js_settings[$active_theme]; |
|
1182 | + $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
1183 | + } |
|
1184 | + } |
|
1185 | + |
|
1186 | + $defaults = array( |
|
1187 | + 'css' => 'compatibility', // core, compatibility |
|
1188 | + 'js' => $js_default, // js to load, core-popper, popper |
|
1189 | + 'html_font_size' => '16', // js to load, core-popper, popper |
|
1190 | + 'css_backend' => 'compatibility', // core, compatibility |
|
1191 | + 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
1192 | + 'disable_admin' => '', // URL snippets to disable loading on admin |
|
1193 | + ); |
|
1194 | + |
|
1195 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
1196 | + |
|
1197 | + /** |
|
1198 | + * Filter the Bootstrap settings. |
|
1199 | + * |
|
1200 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
1201 | + */ |
|
1202 | + return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
1203 | + } |
|
1204 | + |
|
1205 | + |
|
1206 | + /** |
|
1207 | + * The settings page html output. |
|
1208 | + */ |
|
1209 | + public function settings_page() { |
|
1210 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
1211 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
1212 | + } |
|
1213 | + ?> |
|
1214 | 1214 | <div class="wrap"> |
1215 | 1215 | <h1><?php echo $this->name; ?></h1> |
1216 | 1216 | <p><?php _e("Here you can adjust settings if you are having compatibility issues.",'aui');?></p> |
1217 | 1217 | <form method="post" action="options.php"> |
1218 | 1218 | <?php |
1219 | - settings_fields( 'ayecode-ui-settings' ); |
|
1220 | - do_settings_sections( 'ayecode-ui-settings' ); |
|
1221 | - ?> |
|
1219 | + settings_fields( 'ayecode-ui-settings' ); |
|
1220 | + do_settings_sections( 'ayecode-ui-settings' ); |
|
1221 | + ?> |
|
1222 | 1222 | |
1223 | 1223 | <h2><?php _e( 'Frontend', 'aui' ); ?></h2> |
1224 | 1224 | <table class="form-table wpbs-table-settings"> |
@@ -1298,60 +1298,60 @@ discard block |
||
1298 | 1298 | </table> |
1299 | 1299 | |
1300 | 1300 | <?php |
1301 | - submit_button(); |
|
1302 | - ?> |
|
1301 | + submit_button(); |
|
1302 | + ?> |
|
1303 | 1303 | </form> |
1304 | 1304 | |
1305 | 1305 | <div id="wpbs-version"><?php echo $this->version; ?></div> |
1306 | 1306 | </div> |
1307 | 1307 | |
1308 | 1308 | <?php |
1309 | - } |
|
1310 | - |
|
1311 | - public function customizer_settings($wp_customize){ |
|
1312 | - $wp_customize->add_section('aui_settings', array( |
|
1313 | - 'title' => __('AyeCode UI','aui'), |
|
1314 | - 'priority' => 120, |
|
1315 | - )); |
|
1316 | - |
|
1317 | - // ============================= |
|
1318 | - // = Color Picker = |
|
1319 | - // ============================= |
|
1320 | - $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1321 | - 'default' => AUI_PRIMARY_COLOR, |
|
1322 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1323 | - 'capability' => 'edit_theme_options', |
|
1324 | - 'type' => 'option', |
|
1325 | - 'transport' => 'refresh', |
|
1326 | - )); |
|
1327 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1328 | - 'label' => __('Primary Color','aui'), |
|
1329 | - 'section' => 'aui_settings', |
|
1330 | - 'settings' => 'aui_options[color_primary]', |
|
1331 | - ))); |
|
1332 | - |
|
1333 | - $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1334 | - 'default' => '#6c757d', |
|
1335 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1336 | - 'capability' => 'edit_theme_options', |
|
1337 | - 'type' => 'option', |
|
1338 | - 'transport' => 'refresh', |
|
1339 | - )); |
|
1340 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1341 | - 'label' => __('Secondary Color','aui'), |
|
1342 | - 'section' => 'aui_settings', |
|
1343 | - 'settings' => 'aui_options[color_secondary]', |
|
1344 | - ))); |
|
1345 | - } |
|
1346 | - |
|
1347 | - /** |
|
1348 | - * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1349 | - * |
|
1350 | - * @return mixed |
|
1351 | - */ |
|
1352 | - public static function bs3_compat_css() { |
|
1353 | - ob_start(); |
|
1354 | - ?> |
|
1309 | + } |
|
1310 | + |
|
1311 | + public function customizer_settings($wp_customize){ |
|
1312 | + $wp_customize->add_section('aui_settings', array( |
|
1313 | + 'title' => __('AyeCode UI','aui'), |
|
1314 | + 'priority' => 120, |
|
1315 | + )); |
|
1316 | + |
|
1317 | + // ============================= |
|
1318 | + // = Color Picker = |
|
1319 | + // ============================= |
|
1320 | + $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1321 | + 'default' => AUI_PRIMARY_COLOR, |
|
1322 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1323 | + 'capability' => 'edit_theme_options', |
|
1324 | + 'type' => 'option', |
|
1325 | + 'transport' => 'refresh', |
|
1326 | + )); |
|
1327 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1328 | + 'label' => __('Primary Color','aui'), |
|
1329 | + 'section' => 'aui_settings', |
|
1330 | + 'settings' => 'aui_options[color_primary]', |
|
1331 | + ))); |
|
1332 | + |
|
1333 | + $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1334 | + 'default' => '#6c757d', |
|
1335 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1336 | + 'capability' => 'edit_theme_options', |
|
1337 | + 'type' => 'option', |
|
1338 | + 'transport' => 'refresh', |
|
1339 | + )); |
|
1340 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1341 | + 'label' => __('Secondary Color','aui'), |
|
1342 | + 'section' => 'aui_settings', |
|
1343 | + 'settings' => 'aui_options[color_secondary]', |
|
1344 | + ))); |
|
1345 | + } |
|
1346 | + |
|
1347 | + /** |
|
1348 | + * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1349 | + * |
|
1350 | + * @return mixed |
|
1351 | + */ |
|
1352 | + public static function bs3_compat_css() { |
|
1353 | + ob_start(); |
|
1354 | + ?> |
|
1355 | 1355 | <style> |
1356 | 1356 | /* Bootstrap 3 compatibility */ |
1357 | 1357 | body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;} |
@@ -1377,579 +1377,579 @@ discard block |
||
1377 | 1377 | <?php } ?> |
1378 | 1378 | </style> |
1379 | 1379 | <?php |
1380 | - return str_replace( array( |
|
1381 | - '<style>', |
|
1382 | - '</style>' |
|
1383 | - ), '', self::minify_css( ob_get_clean() ) ); |
|
1384 | - } |
|
1380 | + return str_replace( array( |
|
1381 | + '<style>', |
|
1382 | + '</style>' |
|
1383 | + ), '', self::minify_css( ob_get_clean() ) ); |
|
1384 | + } |
|
1385 | 1385 | |
1386 | 1386 | |
1387 | - public static function custom_css($compatibility = true) { |
|
1388 | - $settings = get_option('aui_options'); |
|
1387 | + public static function custom_css($compatibility = true) { |
|
1388 | + $settings = get_option('aui_options'); |
|
1389 | 1389 | |
1390 | - ob_start(); |
|
1390 | + ob_start(); |
|
1391 | 1391 | |
1392 | - $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1393 | - $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1394 | - //AUI_PRIMARY_COLOR_ORIGINAL |
|
1395 | - ?> |
|
1392 | + $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1393 | + $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1394 | + //AUI_PRIMARY_COLOR_ORIGINAL |
|
1395 | + ?> |
|
1396 | 1396 | <style> |
1397 | 1397 | <?php |
1398 | 1398 | |
1399 | - // BS v3 compat |
|
1400 | - if( self::is_bs3_compat() ){ |
|
1401 | - echo self::bs3_compat_css(); |
|
1402 | - } |
|
1399 | + // BS v3 compat |
|
1400 | + if( self::is_bs3_compat() ){ |
|
1401 | + echo self::bs3_compat_css(); |
|
1402 | + } |
|
1403 | 1403 | |
1404 | - if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1405 | - echo self::css_primary($primary_color,$compatibility); |
|
1406 | - } |
|
1404 | + if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1405 | + echo self::css_primary($primary_color,$compatibility); |
|
1406 | + } |
|
1407 | 1407 | |
1408 | - if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1409 | - echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1410 | - } |
|
1408 | + if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1409 | + echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1410 | + } |
|
1411 | 1411 | |
1412 | - // Set admin bar z-index lower when modal is open. |
|
1413 | - echo ' body.modal-open #wpadminbar{z-index:999}'; |
|
1412 | + // Set admin bar z-index lower when modal is open. |
|
1413 | + echo ' body.modal-open #wpadminbar{z-index:999}'; |
|
1414 | 1414 | ?> |
1415 | 1415 | </style> |
1416 | 1416 | <?php |
1417 | 1417 | |
1418 | 1418 | |
1419 | - /* |
|
1419 | + /* |
|
1420 | 1420 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1421 | 1421 | */ |
1422 | - return str_replace( array( |
|
1423 | - '<style>', |
|
1424 | - '</style>' |
|
1425 | - ), '', self::minify_css( ob_get_clean() ) ); |
|
1426 | - } |
|
1427 | - |
|
1428 | - /** |
|
1429 | - * Check if we should add booststrap 3 compatibility changes. |
|
1430 | - * |
|
1431 | - * @return bool |
|
1432 | - */ |
|
1433 | - public static function is_bs3_compat(){ |
|
1434 | - return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
|
1435 | - } |
|
1436 | - |
|
1437 | - public static function css_primary($color_code,$compatibility){; |
|
1438 | - $color_code = sanitize_hex_color($color_code); |
|
1439 | - if(!$color_code){return '';} |
|
1440 | - /** |
|
1441 | - * c = color, b = background color, o = border-color, f = fill |
|
1442 | - */ |
|
1443 | - $selectors = array( |
|
1444 | - 'a' => array('c'), |
|
1445 | - '.btn-primary' => array('b','o'), |
|
1446 | - '.btn-primary.disabled' => array('b','o'), |
|
1447 | - '.btn-primary:disabled' => array('b','o'), |
|
1448 | - '.btn-outline-primary' => array('c','o'), |
|
1449 | - '.btn-outline-primary:hover' => array('b','o'), |
|
1450 | - '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1451 | - '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1452 | - '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1453 | - '.btn-link' => array('c'), |
|
1454 | - '.dropdown-item.active' => array('b'), |
|
1455 | - '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1456 | - '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1422 | + return str_replace( array( |
|
1423 | + '<style>', |
|
1424 | + '</style>' |
|
1425 | + ), '', self::minify_css( ob_get_clean() ) ); |
|
1426 | + } |
|
1427 | + |
|
1428 | + /** |
|
1429 | + * Check if we should add booststrap 3 compatibility changes. |
|
1430 | + * |
|
1431 | + * @return bool |
|
1432 | + */ |
|
1433 | + public static function is_bs3_compat(){ |
|
1434 | + return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
|
1435 | + } |
|
1436 | + |
|
1437 | + public static function css_primary($color_code,$compatibility){; |
|
1438 | + $color_code = sanitize_hex_color($color_code); |
|
1439 | + if(!$color_code){return '';} |
|
1440 | + /** |
|
1441 | + * c = color, b = background color, o = border-color, f = fill |
|
1442 | + */ |
|
1443 | + $selectors = array( |
|
1444 | + 'a' => array('c'), |
|
1445 | + '.btn-primary' => array('b','o'), |
|
1446 | + '.btn-primary.disabled' => array('b','o'), |
|
1447 | + '.btn-primary:disabled' => array('b','o'), |
|
1448 | + '.btn-outline-primary' => array('c','o'), |
|
1449 | + '.btn-outline-primary:hover' => array('b','o'), |
|
1450 | + '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1451 | + '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1452 | + '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1453 | + '.btn-link' => array('c'), |
|
1454 | + '.dropdown-item.active' => array('b'), |
|
1455 | + '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1456 | + '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1457 | 1457 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
1458 | 1458 | // '.custom-range::-moz-range-thumb' => array('b'), |
1459 | 1459 | // '.custom-range::-ms-thumb' => array('b'), |
1460 | - '.nav-pills .nav-link.active' => array('b'), |
|
1461 | - '.nav-pills .show>.nav-link' => array('b'), |
|
1462 | - '.page-link' => array('c'), |
|
1463 | - '.page-item.active .page-link' => array('b','o'), |
|
1464 | - '.badge-primary' => array('b'), |
|
1465 | - '.alert-primary' => array('b','o'), |
|
1466 | - '.progress-bar' => array('b'), |
|
1467 | - '.list-group-item.active' => array('b','o'), |
|
1468 | - '.bg-primary' => array('b','f'), |
|
1469 | - '.btn-link.btn-primary' => array('c'), |
|
1470 | - '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1471 | - ); |
|
1472 | - |
|
1473 | - $important_selectors = array( |
|
1474 | - '.bg-primary' => array('b','f'), |
|
1475 | - '.border-primary' => array('o'), |
|
1476 | - '.text-primary' => array('c'), |
|
1477 | - ); |
|
1478 | - |
|
1479 | - $color = array(); |
|
1480 | - $color_i = array(); |
|
1481 | - $background = array(); |
|
1482 | - $background_i = array(); |
|
1483 | - $border = array(); |
|
1484 | - $border_i = array(); |
|
1485 | - $fill = array(); |
|
1486 | - $fill_i = array(); |
|
1487 | - |
|
1488 | - $output = ''; |
|
1489 | - |
|
1490 | - // build rules into each type |
|
1491 | - foreach($selectors as $selector => $types){ |
|
1492 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1493 | - $types = array_combine($types,$types); |
|
1494 | - if(isset($types['c'])){$color[] = $selector;} |
|
1495 | - if(isset($types['b'])){$background[] = $selector;} |
|
1496 | - if(isset($types['o'])){$border[] = $selector;} |
|
1497 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1498 | - } |
|
1499 | - |
|
1500 | - // build rules into each type |
|
1501 | - foreach($important_selectors as $selector => $types){ |
|
1502 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1503 | - $types = array_combine($types,$types); |
|
1504 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1505 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1506 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1507 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1508 | - } |
|
1509 | - |
|
1510 | - // add any color rules |
|
1511 | - if(!empty($color)){ |
|
1512 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1513 | - } |
|
1514 | - if(!empty($color_i)){ |
|
1515 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1516 | - } |
|
1517 | - |
|
1518 | - // add any background color rules |
|
1519 | - if(!empty($background)){ |
|
1520 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1521 | - } |
|
1522 | - if(!empty($background_i)){ |
|
1523 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1524 | - } |
|
1525 | - |
|
1526 | - // add any border color rules |
|
1527 | - if(!empty($border)){ |
|
1528 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1529 | - } |
|
1530 | - if(!empty($border_i)){ |
|
1531 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1532 | - } |
|
1533 | - |
|
1534 | - // add any fill color rules |
|
1535 | - if(!empty($fill)){ |
|
1536 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1537 | - } |
|
1538 | - if(!empty($fill_i)){ |
|
1539 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1540 | - } |
|
1541 | - |
|
1542 | - |
|
1543 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1544 | - |
|
1545 | - // darken |
|
1546 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1547 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1548 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1549 | - |
|
1550 | - // lighten |
|
1551 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1552 | - |
|
1553 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1554 | - $op_25 = $color_code."40"; // 25% opacity |
|
1555 | - |
|
1556 | - |
|
1557 | - // button states |
|
1558 | - $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1559 | - $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;} "; |
|
1560 | - $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.";} "; |
|
1561 | - $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;} "; |
|
1562 | - |
|
1563 | - |
|
1564 | - // dropdown's |
|
1565 | - $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1566 | - |
|
1567 | - |
|
1568 | - // input states |
|
1569 | - $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1570 | - |
|
1571 | - // page link |
|
1572 | - $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1573 | - |
|
1574 | - return $output; |
|
1575 | - } |
|
1576 | - |
|
1577 | - public static function css_secondary($color_code,$compatibility){; |
|
1578 | - $color_code = sanitize_hex_color($color_code); |
|
1579 | - if(!$color_code){return '';} |
|
1580 | - /** |
|
1581 | - * c = color, b = background color, o = border-color, f = fill |
|
1582 | - */ |
|
1583 | - $selectors = array( |
|
1584 | - '.btn-secondary' => array('b','o'), |
|
1585 | - '.btn-secondary.disabled' => array('b','o'), |
|
1586 | - '.btn-secondary:disabled' => array('b','o'), |
|
1587 | - '.btn-outline-secondary' => array('c','o'), |
|
1588 | - '.btn-outline-secondary:hover' => array('b','o'), |
|
1589 | - '.btn-outline-secondary.disabled' => array('c'), |
|
1590 | - '.btn-outline-secondary:disabled' => array('c'), |
|
1591 | - '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1592 | - '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1593 | - '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1594 | - '.badge-secondary' => array('b'), |
|
1595 | - '.alert-secondary' => array('b','o'), |
|
1596 | - '.btn-link.btn-secondary' => array('c'), |
|
1597 | - ); |
|
1598 | - |
|
1599 | - $important_selectors = array( |
|
1600 | - '.bg-secondary' => array('b','f'), |
|
1601 | - '.border-secondary' => array('o'), |
|
1602 | - '.text-secondary' => array('c'), |
|
1603 | - ); |
|
1604 | - |
|
1605 | - $color = array(); |
|
1606 | - $color_i = array(); |
|
1607 | - $background = array(); |
|
1608 | - $background_i = array(); |
|
1609 | - $border = array(); |
|
1610 | - $border_i = array(); |
|
1611 | - $fill = array(); |
|
1612 | - $fill_i = array(); |
|
1613 | - |
|
1614 | - $output = ''; |
|
1615 | - |
|
1616 | - // build rules into each type |
|
1617 | - foreach($selectors as $selector => $types){ |
|
1618 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1619 | - $types = array_combine($types,$types); |
|
1620 | - if(isset($types['c'])){$color[] = $selector;} |
|
1621 | - if(isset($types['b'])){$background[] = $selector;} |
|
1622 | - if(isset($types['o'])){$border[] = $selector;} |
|
1623 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1624 | - } |
|
1625 | - |
|
1626 | - // build rules into each type |
|
1627 | - foreach($important_selectors as $selector => $types){ |
|
1628 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1629 | - $types = array_combine($types,$types); |
|
1630 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1631 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1632 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1633 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1634 | - } |
|
1635 | - |
|
1636 | - // add any color rules |
|
1637 | - if(!empty($color)){ |
|
1638 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1639 | - } |
|
1640 | - if(!empty($color_i)){ |
|
1641 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1642 | - } |
|
1643 | - |
|
1644 | - // add any background color rules |
|
1645 | - if(!empty($background)){ |
|
1646 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1647 | - } |
|
1648 | - if(!empty($background_i)){ |
|
1649 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1650 | - } |
|
1651 | - |
|
1652 | - // add any border color rules |
|
1653 | - if(!empty($border)){ |
|
1654 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1655 | - } |
|
1656 | - if(!empty($border_i)){ |
|
1657 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1658 | - } |
|
1659 | - |
|
1660 | - // add any fill color rules |
|
1661 | - if(!empty($fill)){ |
|
1662 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1663 | - } |
|
1664 | - if(!empty($fill_i)){ |
|
1665 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1666 | - } |
|
1667 | - |
|
1668 | - |
|
1669 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1670 | - |
|
1671 | - // darken |
|
1672 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1673 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1674 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1675 | - |
|
1676 | - // lighten |
|
1677 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1678 | - |
|
1679 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1680 | - $op_25 = $color_code."40"; // 25% opacity |
|
1681 | - |
|
1682 | - |
|
1683 | - // button states |
|
1684 | - $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1685 | - $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;} "; |
|
1686 | - $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.";} "; |
|
1687 | - $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;} "; |
|
1688 | - |
|
1689 | - |
|
1690 | - return $output; |
|
1691 | - } |
|
1692 | - |
|
1693 | - /** |
|
1694 | - * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1695 | - * |
|
1696 | - * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1697 | - * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1698 | - * |
|
1699 | - * @return string |
|
1700 | - */ |
|
1701 | - public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1702 | - $hexCode = ltrim($hexCode, '#'); |
|
1703 | - |
|
1704 | - if (strlen($hexCode) == 3) { |
|
1705 | - $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1706 | - } |
|
1707 | - |
|
1708 | - $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1709 | - |
|
1710 | - foreach ($hexCode as & $color) { |
|
1711 | - $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1712 | - $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1713 | - |
|
1714 | - $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1715 | - } |
|
1716 | - |
|
1717 | - return '#' . implode($hexCode); |
|
1718 | - } |
|
1719 | - |
|
1720 | - /** |
|
1721 | - * Check if we should display examples. |
|
1722 | - */ |
|
1723 | - public function maybe_show_examples(){ |
|
1724 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1725 | - echo "<head>"; |
|
1726 | - wp_head(); |
|
1727 | - echo "</head>"; |
|
1728 | - echo "<body>"; |
|
1729 | - echo $this->get_examples(); |
|
1730 | - echo "</body>"; |
|
1731 | - exit; |
|
1732 | - } |
|
1733 | - } |
|
1734 | - |
|
1735 | - /** |
|
1736 | - * Get developer examples. |
|
1737 | - * |
|
1738 | - * @return string |
|
1739 | - */ |
|
1740 | - public function get_examples(){ |
|
1741 | - $output = ''; |
|
1742 | - |
|
1743 | - |
|
1744 | - // open form |
|
1745 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1746 | - |
|
1747 | - // input example |
|
1748 | - $output .= aui()->input(array( |
|
1749 | - 'type' => 'text', |
|
1750 | - 'id' => 'text-example', |
|
1751 | - 'name' => 'text-example', |
|
1752 | - 'placeholder' => 'text placeholder', |
|
1753 | - 'title' => 'Text input example', |
|
1754 | - 'value' => '', |
|
1755 | - 'required' => false, |
|
1756 | - 'help_text' => 'help text', |
|
1757 | - 'label' => 'Text input example label' |
|
1758 | - )); |
|
1759 | - |
|
1760 | - // input example |
|
1761 | - $output .= aui()->input(array( |
|
1762 | - 'type' => 'url', |
|
1763 | - 'id' => 'text-example2', |
|
1764 | - 'name' => 'text-example', |
|
1765 | - 'placeholder' => 'url placeholder', |
|
1766 | - 'title' => 'Text input example', |
|
1767 | - 'value' => '', |
|
1768 | - 'required' => false, |
|
1769 | - 'help_text' => 'help text', |
|
1770 | - 'label' => 'Text input example label' |
|
1771 | - )); |
|
1772 | - |
|
1773 | - // checkbox example |
|
1774 | - $output .= aui()->input(array( |
|
1775 | - 'type' => 'checkbox', |
|
1776 | - 'id' => 'checkbox-example', |
|
1777 | - 'name' => 'checkbox-example', |
|
1778 | - 'placeholder' => 'checkbox-example', |
|
1779 | - 'title' => 'Checkbox example', |
|
1780 | - 'value' => '1', |
|
1781 | - 'checked' => true, |
|
1782 | - 'required' => false, |
|
1783 | - 'help_text' => 'help text', |
|
1784 | - 'label' => 'Checkbox checked' |
|
1785 | - )); |
|
1786 | - |
|
1787 | - // checkbox example |
|
1788 | - $output .= aui()->input(array( |
|
1789 | - 'type' => 'checkbox', |
|
1790 | - 'id' => 'checkbox-example2', |
|
1791 | - 'name' => 'checkbox-example2', |
|
1792 | - 'placeholder' => 'checkbox-example', |
|
1793 | - 'title' => 'Checkbox example', |
|
1794 | - 'value' => '1', |
|
1795 | - 'checked' => false, |
|
1796 | - 'required' => false, |
|
1797 | - 'help_text' => 'help text', |
|
1798 | - 'label' => 'Checkbox un-checked' |
|
1799 | - )); |
|
1800 | - |
|
1801 | - // switch example |
|
1802 | - $output .= aui()->input(array( |
|
1803 | - 'type' => 'checkbox', |
|
1804 | - 'id' => 'switch-example', |
|
1805 | - 'name' => 'switch-example', |
|
1806 | - 'placeholder' => 'checkbox-example', |
|
1807 | - 'title' => 'Switch example', |
|
1808 | - 'value' => '1', |
|
1809 | - 'checked' => true, |
|
1810 | - 'switch' => true, |
|
1811 | - 'required' => false, |
|
1812 | - 'help_text' => 'help text', |
|
1813 | - 'label' => 'Switch on' |
|
1814 | - )); |
|
1815 | - |
|
1816 | - // switch example |
|
1817 | - $output .= aui()->input(array( |
|
1818 | - 'type' => 'checkbox', |
|
1819 | - 'id' => 'switch-example2', |
|
1820 | - 'name' => 'switch-example2', |
|
1821 | - 'placeholder' => 'checkbox-example', |
|
1822 | - 'title' => 'Switch example', |
|
1823 | - 'value' => '1', |
|
1824 | - 'checked' => false, |
|
1825 | - 'switch' => true, |
|
1826 | - 'required' => false, |
|
1827 | - 'help_text' => 'help text', |
|
1828 | - 'label' => 'Switch off' |
|
1829 | - )); |
|
1830 | - |
|
1831 | - // close form |
|
1832 | - $output .= "</form>"; |
|
1833 | - |
|
1834 | - return $output; |
|
1835 | - } |
|
1836 | - |
|
1837 | - /** |
|
1838 | - * Calendar params. |
|
1839 | - * |
|
1840 | - * @since 0.1.44 |
|
1841 | - * |
|
1842 | - * @return array Calendar params. |
|
1843 | - */ |
|
1844 | - public static function calendar_params() { |
|
1845 | - $params = array( |
|
1846 | - 'month_long_1' => __( 'January', 'aui' ), |
|
1847 | - 'month_long_2' => __( 'February', 'aui' ), |
|
1848 | - 'month_long_3' => __( 'March', 'aui' ), |
|
1849 | - 'month_long_4' => __( 'April', 'aui' ), |
|
1850 | - 'month_long_5' => __( 'May', 'aui' ), |
|
1851 | - 'month_long_6' => __( 'June', 'aui' ), |
|
1852 | - 'month_long_7' => __( 'July', 'aui' ), |
|
1853 | - 'month_long_8' => __( 'August', 'aui' ), |
|
1854 | - 'month_long_9' => __( 'September', 'aui' ), |
|
1855 | - 'month_long_10' => __( 'October', 'aui' ), |
|
1856 | - 'month_long_11' => __( 'November', 'aui' ), |
|
1857 | - 'month_long_12' => __( 'December', 'aui' ), |
|
1858 | - 'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ), |
|
1859 | - 'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ), |
|
1860 | - 'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ), |
|
1861 | - 'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ), |
|
1862 | - 'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ), |
|
1863 | - 'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ), |
|
1864 | - 'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ), |
|
1865 | - 'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ), |
|
1866 | - 'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ), |
|
1867 | - 'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ), |
|
1868 | - 'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ), |
|
1869 | - 'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ), |
|
1870 | - 'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ), |
|
1871 | - 'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ), |
|
1872 | - 'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ), |
|
1873 | - 'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ), |
|
1874 | - 'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ), |
|
1875 | - 'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ), |
|
1876 | - 'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ), |
|
1877 | - 'day_s2_1' => __( 'Su', 'aui' ), |
|
1878 | - 'day_s2_2' => __( 'Mo', 'aui' ), |
|
1879 | - 'day_s2_3' => __( 'Tu', 'aui' ), |
|
1880 | - 'day_s2_4' => __( 'We', 'aui' ), |
|
1881 | - 'day_s2_5' => __( 'Th', 'aui' ), |
|
1882 | - 'day_s2_6' => __( 'Fr', 'aui' ), |
|
1883 | - 'day_s2_7' => __( 'Sa', 'aui' ), |
|
1884 | - 'day_s3_1' => __( 'Sun', 'aui' ), |
|
1885 | - 'day_s3_2' => __( 'Mon', 'aui' ), |
|
1886 | - 'day_s3_3' => __( 'Tue', 'aui' ), |
|
1887 | - 'day_s3_4' => __( 'Wed', 'aui' ), |
|
1888 | - 'day_s3_5' => __( 'Thu', 'aui' ), |
|
1889 | - 'day_s3_6' => __( 'Fri', 'aui' ), |
|
1890 | - 'day_s3_7' => __( 'Sat', 'aui' ), |
|
1891 | - 'day_s5_1' => __( 'Sunday', 'aui' ), |
|
1892 | - 'day_s5_2' => __( 'Monday', 'aui' ), |
|
1893 | - 'day_s5_3' => __( 'Tuesday', 'aui' ), |
|
1894 | - 'day_s5_4' => __( 'Wednesday', 'aui' ), |
|
1895 | - 'day_s5_5' => __( 'Thursday', 'aui' ), |
|
1896 | - 'day_s5_6' => __( 'Friday', 'aui' ), |
|
1897 | - 'day_s5_7' => __( 'Saturday', 'aui' ), |
|
1898 | - 'am_lower' => __( 'am', 'aui' ), |
|
1899 | - 'pm_lower' => __( 'pm', 'aui' ), |
|
1900 | - 'am_upper' => __( 'AM', 'aui' ), |
|
1901 | - 'pm_upper' => __( 'PM', 'aui' ), |
|
1902 | - 'firstDayOfWeek' => (int) get_option( 'start_of_week' ), |
|
1903 | - 'time_24hr' => false, |
|
1904 | - 'year' => __( 'Year', 'aui' ), |
|
1905 | - 'hour' => __( 'Hour', 'aui' ), |
|
1906 | - 'minute' => __( 'Minute', 'aui' ), |
|
1907 | - 'weekAbbreviation' => __( 'Wk', 'aui' ), |
|
1908 | - 'rangeSeparator' => __( ' to ', 'aui' ), |
|
1909 | - 'scrollTitle' => __( 'Scroll to increment', 'aui' ), |
|
1910 | - 'toggleTitle' => __( 'Click to toggle', 'aui' ) |
|
1911 | - ); |
|
1912 | - |
|
1913 | - return apply_filters( 'ayecode_ui_calendar_params', $params ); |
|
1914 | - } |
|
1915 | - |
|
1916 | - /** |
|
1917 | - * Flatpickr calendar localize. |
|
1918 | - * |
|
1919 | - * @since 0.1.44 |
|
1920 | - * |
|
1921 | - * @return string Calendar locale. |
|
1922 | - */ |
|
1923 | - public static function flatpickr_locale() { |
|
1924 | - $params = self::calendar_params(); |
|
1925 | - |
|
1926 | - if ( is_string( $params ) ) { |
|
1927 | - $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' ); |
|
1928 | - } else { |
|
1929 | - foreach ( (array) $params as $key => $value ) { |
|
1930 | - if ( ! is_scalar( $value ) ) { |
|
1931 | - continue; |
|
1932 | - } |
|
1933 | - |
|
1934 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
1935 | - } |
|
1936 | - } |
|
1460 | + '.nav-pills .nav-link.active' => array('b'), |
|
1461 | + '.nav-pills .show>.nav-link' => array('b'), |
|
1462 | + '.page-link' => array('c'), |
|
1463 | + '.page-item.active .page-link' => array('b','o'), |
|
1464 | + '.badge-primary' => array('b'), |
|
1465 | + '.alert-primary' => array('b','o'), |
|
1466 | + '.progress-bar' => array('b'), |
|
1467 | + '.list-group-item.active' => array('b','o'), |
|
1468 | + '.bg-primary' => array('b','f'), |
|
1469 | + '.btn-link.btn-primary' => array('c'), |
|
1470 | + '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1471 | + ); |
|
1472 | + |
|
1473 | + $important_selectors = array( |
|
1474 | + '.bg-primary' => array('b','f'), |
|
1475 | + '.border-primary' => array('o'), |
|
1476 | + '.text-primary' => array('c'), |
|
1477 | + ); |
|
1478 | + |
|
1479 | + $color = array(); |
|
1480 | + $color_i = array(); |
|
1481 | + $background = array(); |
|
1482 | + $background_i = array(); |
|
1483 | + $border = array(); |
|
1484 | + $border_i = array(); |
|
1485 | + $fill = array(); |
|
1486 | + $fill_i = array(); |
|
1487 | + |
|
1488 | + $output = ''; |
|
1489 | + |
|
1490 | + // build rules into each type |
|
1491 | + foreach($selectors as $selector => $types){ |
|
1492 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1493 | + $types = array_combine($types,$types); |
|
1494 | + if(isset($types['c'])){$color[] = $selector;} |
|
1495 | + if(isset($types['b'])){$background[] = $selector;} |
|
1496 | + if(isset($types['o'])){$border[] = $selector;} |
|
1497 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1498 | + } |
|
1499 | + |
|
1500 | + // build rules into each type |
|
1501 | + foreach($important_selectors as $selector => $types){ |
|
1502 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1503 | + $types = array_combine($types,$types); |
|
1504 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1505 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1506 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1507 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1508 | + } |
|
1509 | + |
|
1510 | + // add any color rules |
|
1511 | + if(!empty($color)){ |
|
1512 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1513 | + } |
|
1514 | + if(!empty($color_i)){ |
|
1515 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1516 | + } |
|
1517 | + |
|
1518 | + // add any background color rules |
|
1519 | + if(!empty($background)){ |
|
1520 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1521 | + } |
|
1522 | + if(!empty($background_i)){ |
|
1523 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1524 | + } |
|
1525 | + |
|
1526 | + // add any border color rules |
|
1527 | + if(!empty($border)){ |
|
1528 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1529 | + } |
|
1530 | + if(!empty($border_i)){ |
|
1531 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1532 | + } |
|
1533 | + |
|
1534 | + // add any fill color rules |
|
1535 | + if(!empty($fill)){ |
|
1536 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1537 | + } |
|
1538 | + if(!empty($fill_i)){ |
|
1539 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1540 | + } |
|
1541 | + |
|
1542 | + |
|
1543 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1544 | + |
|
1545 | + // darken |
|
1546 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1547 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1548 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1549 | + |
|
1550 | + // lighten |
|
1551 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1552 | + |
|
1553 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1554 | + $op_25 = $color_code."40"; // 25% opacity |
|
1555 | + |
|
1556 | + |
|
1557 | + // button states |
|
1558 | + $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1559 | + $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;} "; |
|
1560 | + $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.";} "; |
|
1561 | + $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;} "; |
|
1562 | + |
|
1563 | + |
|
1564 | + // dropdown's |
|
1565 | + $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1566 | + |
|
1567 | + |
|
1568 | + // input states |
|
1569 | + $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1570 | + |
|
1571 | + // page link |
|
1572 | + $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1573 | + |
|
1574 | + return $output; |
|
1575 | + } |
|
1576 | + |
|
1577 | + public static function css_secondary($color_code,$compatibility){; |
|
1578 | + $color_code = sanitize_hex_color($color_code); |
|
1579 | + if(!$color_code){return '';} |
|
1580 | + /** |
|
1581 | + * c = color, b = background color, o = border-color, f = fill |
|
1582 | + */ |
|
1583 | + $selectors = array( |
|
1584 | + '.btn-secondary' => array('b','o'), |
|
1585 | + '.btn-secondary.disabled' => array('b','o'), |
|
1586 | + '.btn-secondary:disabled' => array('b','o'), |
|
1587 | + '.btn-outline-secondary' => array('c','o'), |
|
1588 | + '.btn-outline-secondary:hover' => array('b','o'), |
|
1589 | + '.btn-outline-secondary.disabled' => array('c'), |
|
1590 | + '.btn-outline-secondary:disabled' => array('c'), |
|
1591 | + '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1592 | + '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1593 | + '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1594 | + '.badge-secondary' => array('b'), |
|
1595 | + '.alert-secondary' => array('b','o'), |
|
1596 | + '.btn-link.btn-secondary' => array('c'), |
|
1597 | + ); |
|
1598 | + |
|
1599 | + $important_selectors = array( |
|
1600 | + '.bg-secondary' => array('b','f'), |
|
1601 | + '.border-secondary' => array('o'), |
|
1602 | + '.text-secondary' => array('c'), |
|
1603 | + ); |
|
1604 | + |
|
1605 | + $color = array(); |
|
1606 | + $color_i = array(); |
|
1607 | + $background = array(); |
|
1608 | + $background_i = array(); |
|
1609 | + $border = array(); |
|
1610 | + $border_i = array(); |
|
1611 | + $fill = array(); |
|
1612 | + $fill_i = array(); |
|
1613 | + |
|
1614 | + $output = ''; |
|
1615 | + |
|
1616 | + // build rules into each type |
|
1617 | + foreach($selectors as $selector => $types){ |
|
1618 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1619 | + $types = array_combine($types,$types); |
|
1620 | + if(isset($types['c'])){$color[] = $selector;} |
|
1621 | + if(isset($types['b'])){$background[] = $selector;} |
|
1622 | + if(isset($types['o'])){$border[] = $selector;} |
|
1623 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1624 | + } |
|
1625 | + |
|
1626 | + // build rules into each type |
|
1627 | + foreach($important_selectors as $selector => $types){ |
|
1628 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1629 | + $types = array_combine($types,$types); |
|
1630 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1631 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1632 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1633 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1634 | + } |
|
1635 | + |
|
1636 | + // add any color rules |
|
1637 | + if(!empty($color)){ |
|
1638 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1639 | + } |
|
1640 | + if(!empty($color_i)){ |
|
1641 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1642 | + } |
|
1643 | + |
|
1644 | + // add any background color rules |
|
1645 | + if(!empty($background)){ |
|
1646 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1647 | + } |
|
1648 | + if(!empty($background_i)){ |
|
1649 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1650 | + } |
|
1651 | + |
|
1652 | + // add any border color rules |
|
1653 | + if(!empty($border)){ |
|
1654 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1655 | + } |
|
1656 | + if(!empty($border_i)){ |
|
1657 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1658 | + } |
|
1659 | + |
|
1660 | + // add any fill color rules |
|
1661 | + if(!empty($fill)){ |
|
1662 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1663 | + } |
|
1664 | + if(!empty($fill_i)){ |
|
1665 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1666 | + } |
|
1667 | + |
|
1668 | + |
|
1669 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1670 | + |
|
1671 | + // darken |
|
1672 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1673 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1674 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1675 | + |
|
1676 | + // lighten |
|
1677 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1678 | + |
|
1679 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1680 | + $op_25 = $color_code."40"; // 25% opacity |
|
1681 | + |
|
1682 | + |
|
1683 | + // button states |
|
1684 | + $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1685 | + $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;} "; |
|
1686 | + $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.";} "; |
|
1687 | + $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;} "; |
|
1688 | + |
|
1689 | + |
|
1690 | + return $output; |
|
1691 | + } |
|
1692 | + |
|
1693 | + /** |
|
1694 | + * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1695 | + * |
|
1696 | + * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1697 | + * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1698 | + * |
|
1699 | + * @return string |
|
1700 | + */ |
|
1701 | + public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1702 | + $hexCode = ltrim($hexCode, '#'); |
|
1703 | + |
|
1704 | + if (strlen($hexCode) == 3) { |
|
1705 | + $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1706 | + } |
|
1707 | + |
|
1708 | + $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1709 | + |
|
1710 | + foreach ($hexCode as & $color) { |
|
1711 | + $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1712 | + $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1713 | + |
|
1714 | + $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1715 | + } |
|
1716 | + |
|
1717 | + return '#' . implode($hexCode); |
|
1718 | + } |
|
1719 | + |
|
1720 | + /** |
|
1721 | + * Check if we should display examples. |
|
1722 | + */ |
|
1723 | + public function maybe_show_examples(){ |
|
1724 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1725 | + echo "<head>"; |
|
1726 | + wp_head(); |
|
1727 | + echo "</head>"; |
|
1728 | + echo "<body>"; |
|
1729 | + echo $this->get_examples(); |
|
1730 | + echo "</body>"; |
|
1731 | + exit; |
|
1732 | + } |
|
1733 | + } |
|
1734 | + |
|
1735 | + /** |
|
1736 | + * Get developer examples. |
|
1737 | + * |
|
1738 | + * @return string |
|
1739 | + */ |
|
1740 | + public function get_examples(){ |
|
1741 | + $output = ''; |
|
1742 | + |
|
1743 | + |
|
1744 | + // open form |
|
1745 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1746 | + |
|
1747 | + // input example |
|
1748 | + $output .= aui()->input(array( |
|
1749 | + 'type' => 'text', |
|
1750 | + 'id' => 'text-example', |
|
1751 | + 'name' => 'text-example', |
|
1752 | + 'placeholder' => 'text placeholder', |
|
1753 | + 'title' => 'Text input example', |
|
1754 | + 'value' => '', |
|
1755 | + 'required' => false, |
|
1756 | + 'help_text' => 'help text', |
|
1757 | + 'label' => 'Text input example label' |
|
1758 | + )); |
|
1759 | + |
|
1760 | + // input example |
|
1761 | + $output .= aui()->input(array( |
|
1762 | + 'type' => 'url', |
|
1763 | + 'id' => 'text-example2', |
|
1764 | + 'name' => 'text-example', |
|
1765 | + 'placeholder' => 'url placeholder', |
|
1766 | + 'title' => 'Text input example', |
|
1767 | + 'value' => '', |
|
1768 | + 'required' => false, |
|
1769 | + 'help_text' => 'help text', |
|
1770 | + 'label' => 'Text input example label' |
|
1771 | + )); |
|
1772 | + |
|
1773 | + // checkbox example |
|
1774 | + $output .= aui()->input(array( |
|
1775 | + 'type' => 'checkbox', |
|
1776 | + 'id' => 'checkbox-example', |
|
1777 | + 'name' => 'checkbox-example', |
|
1778 | + 'placeholder' => 'checkbox-example', |
|
1779 | + 'title' => 'Checkbox example', |
|
1780 | + 'value' => '1', |
|
1781 | + 'checked' => true, |
|
1782 | + 'required' => false, |
|
1783 | + 'help_text' => 'help text', |
|
1784 | + 'label' => 'Checkbox checked' |
|
1785 | + )); |
|
1786 | + |
|
1787 | + // checkbox example |
|
1788 | + $output .= aui()->input(array( |
|
1789 | + 'type' => 'checkbox', |
|
1790 | + 'id' => 'checkbox-example2', |
|
1791 | + 'name' => 'checkbox-example2', |
|
1792 | + 'placeholder' => 'checkbox-example', |
|
1793 | + 'title' => 'Checkbox example', |
|
1794 | + 'value' => '1', |
|
1795 | + 'checked' => false, |
|
1796 | + 'required' => false, |
|
1797 | + 'help_text' => 'help text', |
|
1798 | + 'label' => 'Checkbox un-checked' |
|
1799 | + )); |
|
1800 | + |
|
1801 | + // switch example |
|
1802 | + $output .= aui()->input(array( |
|
1803 | + 'type' => 'checkbox', |
|
1804 | + 'id' => 'switch-example', |
|
1805 | + 'name' => 'switch-example', |
|
1806 | + 'placeholder' => 'checkbox-example', |
|
1807 | + 'title' => 'Switch example', |
|
1808 | + 'value' => '1', |
|
1809 | + 'checked' => true, |
|
1810 | + 'switch' => true, |
|
1811 | + 'required' => false, |
|
1812 | + 'help_text' => 'help text', |
|
1813 | + 'label' => 'Switch on' |
|
1814 | + )); |
|
1815 | + |
|
1816 | + // switch example |
|
1817 | + $output .= aui()->input(array( |
|
1818 | + 'type' => 'checkbox', |
|
1819 | + 'id' => 'switch-example2', |
|
1820 | + 'name' => 'switch-example2', |
|
1821 | + 'placeholder' => 'checkbox-example', |
|
1822 | + 'title' => 'Switch example', |
|
1823 | + 'value' => '1', |
|
1824 | + 'checked' => false, |
|
1825 | + 'switch' => true, |
|
1826 | + 'required' => false, |
|
1827 | + 'help_text' => 'help text', |
|
1828 | + 'label' => 'Switch off' |
|
1829 | + )); |
|
1830 | + |
|
1831 | + // close form |
|
1832 | + $output .= "</form>"; |
|
1833 | + |
|
1834 | + return $output; |
|
1835 | + } |
|
1836 | + |
|
1837 | + /** |
|
1838 | + * Calendar params. |
|
1839 | + * |
|
1840 | + * @since 0.1.44 |
|
1841 | + * |
|
1842 | + * @return array Calendar params. |
|
1843 | + */ |
|
1844 | + public static function calendar_params() { |
|
1845 | + $params = array( |
|
1846 | + 'month_long_1' => __( 'January', 'aui' ), |
|
1847 | + 'month_long_2' => __( 'February', 'aui' ), |
|
1848 | + 'month_long_3' => __( 'March', 'aui' ), |
|
1849 | + 'month_long_4' => __( 'April', 'aui' ), |
|
1850 | + 'month_long_5' => __( 'May', 'aui' ), |
|
1851 | + 'month_long_6' => __( 'June', 'aui' ), |
|
1852 | + 'month_long_7' => __( 'July', 'aui' ), |
|
1853 | + 'month_long_8' => __( 'August', 'aui' ), |
|
1854 | + 'month_long_9' => __( 'September', 'aui' ), |
|
1855 | + 'month_long_10' => __( 'October', 'aui' ), |
|
1856 | + 'month_long_11' => __( 'November', 'aui' ), |
|
1857 | + 'month_long_12' => __( 'December', 'aui' ), |
|
1858 | + 'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ), |
|
1859 | + 'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ), |
|
1860 | + 'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ), |
|
1861 | + 'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ), |
|
1862 | + 'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ), |
|
1863 | + 'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ), |
|
1864 | + 'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ), |
|
1865 | + 'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ), |
|
1866 | + 'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ), |
|
1867 | + 'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ), |
|
1868 | + 'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ), |
|
1869 | + 'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ), |
|
1870 | + 'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ), |
|
1871 | + 'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ), |
|
1872 | + 'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ), |
|
1873 | + 'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ), |
|
1874 | + 'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ), |
|
1875 | + 'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ), |
|
1876 | + 'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ), |
|
1877 | + 'day_s2_1' => __( 'Su', 'aui' ), |
|
1878 | + 'day_s2_2' => __( 'Mo', 'aui' ), |
|
1879 | + 'day_s2_3' => __( 'Tu', 'aui' ), |
|
1880 | + 'day_s2_4' => __( 'We', 'aui' ), |
|
1881 | + 'day_s2_5' => __( 'Th', 'aui' ), |
|
1882 | + 'day_s2_6' => __( 'Fr', 'aui' ), |
|
1883 | + 'day_s2_7' => __( 'Sa', 'aui' ), |
|
1884 | + 'day_s3_1' => __( 'Sun', 'aui' ), |
|
1885 | + 'day_s3_2' => __( 'Mon', 'aui' ), |
|
1886 | + 'day_s3_3' => __( 'Tue', 'aui' ), |
|
1887 | + 'day_s3_4' => __( 'Wed', 'aui' ), |
|
1888 | + 'day_s3_5' => __( 'Thu', 'aui' ), |
|
1889 | + 'day_s3_6' => __( 'Fri', 'aui' ), |
|
1890 | + 'day_s3_7' => __( 'Sat', 'aui' ), |
|
1891 | + 'day_s5_1' => __( 'Sunday', 'aui' ), |
|
1892 | + 'day_s5_2' => __( 'Monday', 'aui' ), |
|
1893 | + 'day_s5_3' => __( 'Tuesday', 'aui' ), |
|
1894 | + 'day_s5_4' => __( 'Wednesday', 'aui' ), |
|
1895 | + 'day_s5_5' => __( 'Thursday', 'aui' ), |
|
1896 | + 'day_s5_6' => __( 'Friday', 'aui' ), |
|
1897 | + 'day_s5_7' => __( 'Saturday', 'aui' ), |
|
1898 | + 'am_lower' => __( 'am', 'aui' ), |
|
1899 | + 'pm_lower' => __( 'pm', 'aui' ), |
|
1900 | + 'am_upper' => __( 'AM', 'aui' ), |
|
1901 | + 'pm_upper' => __( 'PM', 'aui' ), |
|
1902 | + 'firstDayOfWeek' => (int) get_option( 'start_of_week' ), |
|
1903 | + 'time_24hr' => false, |
|
1904 | + 'year' => __( 'Year', 'aui' ), |
|
1905 | + 'hour' => __( 'Hour', 'aui' ), |
|
1906 | + 'minute' => __( 'Minute', 'aui' ), |
|
1907 | + 'weekAbbreviation' => __( 'Wk', 'aui' ), |
|
1908 | + 'rangeSeparator' => __( ' to ', 'aui' ), |
|
1909 | + 'scrollTitle' => __( 'Scroll to increment', 'aui' ), |
|
1910 | + 'toggleTitle' => __( 'Click to toggle', 'aui' ) |
|
1911 | + ); |
|
1912 | + |
|
1913 | + return apply_filters( 'ayecode_ui_calendar_params', $params ); |
|
1914 | + } |
|
1915 | + |
|
1916 | + /** |
|
1917 | + * Flatpickr calendar localize. |
|
1918 | + * |
|
1919 | + * @since 0.1.44 |
|
1920 | + * |
|
1921 | + * @return string Calendar locale. |
|
1922 | + */ |
|
1923 | + public static function flatpickr_locale() { |
|
1924 | + $params = self::calendar_params(); |
|
1925 | + |
|
1926 | + if ( is_string( $params ) ) { |
|
1927 | + $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' ); |
|
1928 | + } else { |
|
1929 | + foreach ( (array) $params as $key => $value ) { |
|
1930 | + if ( ! is_scalar( $value ) ) { |
|
1931 | + continue; |
|
1932 | + } |
|
1933 | + |
|
1934 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
1935 | + } |
|
1936 | + } |
|
1937 | 1937 | |
1938 | - $day_s3 = array(); |
|
1939 | - $day_s5 = array(); |
|
1938 | + $day_s3 = array(); |
|
1939 | + $day_s5 = array(); |
|
1940 | 1940 | |
1941 | - for ( $i = 1; $i <= 7; $i ++ ) { |
|
1942 | - $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
1943 | - $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
1944 | - } |
|
1941 | + for ( $i = 1; $i <= 7; $i ++ ) { |
|
1942 | + $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
1943 | + $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
1944 | + } |
|
1945 | 1945 | |
1946 | - $month_s = array(); |
|
1947 | - $month_long = array(); |
|
1946 | + $month_s = array(); |
|
1947 | + $month_long = array(); |
|
1948 | 1948 | |
1949 | - for ( $i = 1; $i <= 12; $i ++ ) { |
|
1950 | - $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); |
|
1951 | - $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); |
|
1952 | - } |
|
1949 | + for ( $i = 1; $i <= 12; $i ++ ) { |
|
1950 | + $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); |
|
1951 | + $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); |
|
1952 | + } |
|
1953 | 1953 | |
1954 | 1954 | ob_start(); |
1955 | 1955 | if ( 0 ) { ?><script><?php } ?> |
@@ -1991,184 +1991,184 @@ discard block |
||
1991 | 1991 | } |
1992 | 1992 | <?php if ( 0 ) { ?></script><?php } ?> |
1993 | 1993 | <?php |
1994 | - $locale = ob_get_clean(); |
|
1995 | - |
|
1996 | - return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) ); |
|
1997 | - } |
|
1998 | - |
|
1999 | - /** |
|
2000 | - * Select2 JS params. |
|
2001 | - * |
|
2002 | - * @since 0.1.44 |
|
2003 | - * |
|
2004 | - * @return array Select2 JS params. |
|
2005 | - */ |
|
2006 | - public static function select2_params() { |
|
2007 | - $params = array( |
|
2008 | - 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'aui' ), |
|
2009 | - 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'aui' ), |
|
2010 | - 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'aui' ), |
|
2011 | - 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ), |
|
2012 | - 'i18n_input_too_short_n' => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ), |
|
2013 | - 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'aui' ), |
|
2014 | - 'i18n_input_too_long_n' => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ), |
|
2015 | - 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ), |
|
2016 | - 'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ), |
|
2017 | - 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'aui' ), |
|
2018 | - 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'aui' ) |
|
2019 | - ); |
|
2020 | - |
|
2021 | - return apply_filters( 'ayecode_ui_select2_params', $params ); |
|
2022 | - } |
|
2023 | - |
|
2024 | - /** |
|
2025 | - * Select2 JS localize. |
|
2026 | - * |
|
2027 | - * @since 0.1.44 |
|
2028 | - * |
|
2029 | - * @return string Select2 JS locale. |
|
2030 | - */ |
|
2031 | - public static function select2_locale() { |
|
2032 | - $params = self::select2_params(); |
|
2033 | - |
|
2034 | - foreach ( (array) $params as $key => $value ) { |
|
2035 | - if ( ! is_scalar( $value ) ) { |
|
2036 | - continue; |
|
2037 | - } |
|
2038 | - |
|
2039 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2040 | - } |
|
2041 | - |
|
2042 | - $locale = json_encode( $params ); |
|
2043 | - |
|
2044 | - return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) ); |
|
2045 | - } |
|
2046 | - |
|
2047 | - /** |
|
2048 | - * Time ago JS localize. |
|
2049 | - * |
|
2050 | - * @since 0.1.47 |
|
2051 | - * |
|
2052 | - * @return string Time ago JS locale. |
|
2053 | - */ |
|
2054 | - public static function timeago_locale() { |
|
2055 | - $params = array( |
|
2056 | - 'prefix_ago' => '', |
|
2057 | - 'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ), |
|
2058 | - 'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ', |
|
2059 | - 'suffix_after' => '', |
|
2060 | - 'seconds' => _x( 'less than a minute', 'time ago', 'aui' ), |
|
2061 | - 'minute' => _x( 'about a minute', 'time ago', 'aui' ), |
|
2062 | - 'minutes' => _x( '%d minutes', 'time ago', 'aui' ), |
|
2063 | - 'hour' => _x( 'about an hour', 'time ago', 'aui' ), |
|
2064 | - 'hours' => _x( 'about %d hours', 'time ago', 'aui' ), |
|
2065 | - 'day' => _x( 'a day', 'time ago', 'aui' ), |
|
2066 | - 'days' => _x( '%d days', 'time ago', 'aui' ), |
|
2067 | - 'month' => _x( 'about a month', 'time ago', 'aui' ), |
|
2068 | - 'months' => _x( '%d months', 'time ago', 'aui' ), |
|
2069 | - 'year' => _x( 'about a year', 'time ago', 'aui' ), |
|
2070 | - 'years' => _x( '%d years', 'time ago', 'aui' ), |
|
2071 | - ); |
|
2072 | - |
|
2073 | - $params = apply_filters( 'ayecode_ui_timeago_params', $params ); |
|
2074 | - |
|
2075 | - foreach ( (array) $params as $key => $value ) { |
|
2076 | - if ( ! is_scalar( $value ) ) { |
|
2077 | - continue; |
|
2078 | - } |
|
2079 | - |
|
2080 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2081 | - } |
|
2082 | - |
|
2083 | - $locale = json_encode( $params ); |
|
2084 | - |
|
2085 | - return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) ); |
|
2086 | - } |
|
2087 | - |
|
2088 | - /** |
|
2089 | - * JavaScript Minifier |
|
2090 | - * |
|
2091 | - * @param $input |
|
2092 | - * |
|
2093 | - * @return mixed |
|
2094 | - */ |
|
2095 | - public static function minify_js($input) { |
|
2096 | - if(trim($input) === "") return $input; |
|
2097 | - return preg_replace( |
|
2098 | - array( |
|
2099 | - // Remove comment(s) |
|
2100 | - '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
|
2101 | - // Remove white-space(s) outside the string and regex |
|
2102 | - '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', |
|
2103 | - // Remove the last semicolon |
|
2104 | - '#;+\}#', |
|
2105 | - // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` |
|
2106 | - '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', |
|
2107 | - // --ibid. From `foo['bar']` to `foo.bar` |
|
2108 | - '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' |
|
2109 | - ), |
|
2110 | - array( |
|
2111 | - '$1', |
|
2112 | - '$1$2', |
|
2113 | - '}', |
|
2114 | - '$1$3', |
|
2115 | - '$1.$3' |
|
2116 | - ), |
|
2117 | - $input); |
|
2118 | - } |
|
1994 | + $locale = ob_get_clean(); |
|
1995 | + |
|
1996 | + return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) ); |
|
1997 | + } |
|
1998 | + |
|
1999 | + /** |
|
2000 | + * Select2 JS params. |
|
2001 | + * |
|
2002 | + * @since 0.1.44 |
|
2003 | + * |
|
2004 | + * @return array Select2 JS params. |
|
2005 | + */ |
|
2006 | + public static function select2_params() { |
|
2007 | + $params = array( |
|
2008 | + 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'aui' ), |
|
2009 | + 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'aui' ), |
|
2010 | + 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'aui' ), |
|
2011 | + 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ), |
|
2012 | + 'i18n_input_too_short_n' => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ), |
|
2013 | + 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'aui' ), |
|
2014 | + 'i18n_input_too_long_n' => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ), |
|
2015 | + 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ), |
|
2016 | + 'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ), |
|
2017 | + 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'aui' ), |
|
2018 | + 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'aui' ) |
|
2019 | + ); |
|
2020 | + |
|
2021 | + return apply_filters( 'ayecode_ui_select2_params', $params ); |
|
2022 | + } |
|
2023 | + |
|
2024 | + /** |
|
2025 | + * Select2 JS localize. |
|
2026 | + * |
|
2027 | + * @since 0.1.44 |
|
2028 | + * |
|
2029 | + * @return string Select2 JS locale. |
|
2030 | + */ |
|
2031 | + public static function select2_locale() { |
|
2032 | + $params = self::select2_params(); |
|
2033 | + |
|
2034 | + foreach ( (array) $params as $key => $value ) { |
|
2035 | + if ( ! is_scalar( $value ) ) { |
|
2036 | + continue; |
|
2037 | + } |
|
2119 | 2038 | |
2120 | - /** |
|
2121 | - * Minify CSS |
|
2122 | - * |
|
2123 | - * @param $input |
|
2124 | - * |
|
2125 | - * @return mixed |
|
2126 | - */ |
|
2127 | - public static function minify_css($input) { |
|
2128 | - if(trim($input) === "") return $input; |
|
2129 | - return preg_replace( |
|
2130 | - array( |
|
2131 | - // Remove comment(s) |
|
2132 | - '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s', |
|
2133 | - // Remove unused white-space(s) |
|
2134 | - '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', |
|
2135 | - // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0` |
|
2136 | - '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si', |
|
2137 | - // Replace `:0 0 0 0` with `:0` |
|
2138 | - '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i', |
|
2139 | - // Replace `background-position:0` with `background-position:0 0` |
|
2140 | - '#(background-position):0(?=[;\}])#si', |
|
2141 | - // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space |
|
2142 | - '#(?<=[\s:,\-])0+\.(\d+)#s', |
|
2143 | - // Minify string value |
|
2144 | - '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si', |
|
2145 | - '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si', |
|
2146 | - // Minify HEX color code |
|
2147 | - '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i', |
|
2148 | - // Replace `(border|outline):none` with `(border|outline):0` |
|
2149 | - '#(?<=[\{;])(border|outline):none(?=[;\}\!])#', |
|
2150 | - // Remove empty selector(s) |
|
2151 | - '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s' |
|
2152 | - ), |
|
2153 | - array( |
|
2154 | - '$1', |
|
2155 | - '$1$2$3$4$5$6$7', |
|
2156 | - '$1', |
|
2157 | - ':0', |
|
2158 | - '$1:0 0', |
|
2159 | - '.$1', |
|
2160 | - '$1$3', |
|
2161 | - '$1$2$4$5', |
|
2162 | - '$1$2$3', |
|
2163 | - '$1:0', |
|
2164 | - '$1$2' |
|
2165 | - ), |
|
2166 | - $input); |
|
2167 | - } |
|
2168 | - } |
|
2039 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2040 | + } |
|
2041 | + |
|
2042 | + $locale = json_encode( $params ); |
|
2043 | + |
|
2044 | + return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) ); |
|
2045 | + } |
|
2046 | + |
|
2047 | + /** |
|
2048 | + * Time ago JS localize. |
|
2049 | + * |
|
2050 | + * @since 0.1.47 |
|
2051 | + * |
|
2052 | + * @return string Time ago JS locale. |
|
2053 | + */ |
|
2054 | + public static function timeago_locale() { |
|
2055 | + $params = array( |
|
2056 | + 'prefix_ago' => '', |
|
2057 | + 'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ), |
|
2058 | + 'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ', |
|
2059 | + 'suffix_after' => '', |
|
2060 | + 'seconds' => _x( 'less than a minute', 'time ago', 'aui' ), |
|
2061 | + 'minute' => _x( 'about a minute', 'time ago', 'aui' ), |
|
2062 | + 'minutes' => _x( '%d minutes', 'time ago', 'aui' ), |
|
2063 | + 'hour' => _x( 'about an hour', 'time ago', 'aui' ), |
|
2064 | + 'hours' => _x( 'about %d hours', 'time ago', 'aui' ), |
|
2065 | + 'day' => _x( 'a day', 'time ago', 'aui' ), |
|
2066 | + 'days' => _x( '%d days', 'time ago', 'aui' ), |
|
2067 | + 'month' => _x( 'about a month', 'time ago', 'aui' ), |
|
2068 | + 'months' => _x( '%d months', 'time ago', 'aui' ), |
|
2069 | + 'year' => _x( 'about a year', 'time ago', 'aui' ), |
|
2070 | + 'years' => _x( '%d years', 'time ago', 'aui' ), |
|
2071 | + ); |
|
2072 | + |
|
2073 | + $params = apply_filters( 'ayecode_ui_timeago_params', $params ); |
|
2074 | + |
|
2075 | + foreach ( (array) $params as $key => $value ) { |
|
2076 | + if ( ! is_scalar( $value ) ) { |
|
2077 | + continue; |
|
2078 | + } |
|
2169 | 2079 | |
2170 | - /** |
|
2171 | - * Run the class if found. |
|
2172 | - */ |
|
2173 | - AyeCode_UI_Settings::instance(); |
|
2080 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2081 | + } |
|
2082 | + |
|
2083 | + $locale = json_encode( $params ); |
|
2084 | + |
|
2085 | + return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) ); |
|
2086 | + } |
|
2087 | + |
|
2088 | + /** |
|
2089 | + * JavaScript Minifier |
|
2090 | + * |
|
2091 | + * @param $input |
|
2092 | + * |
|
2093 | + * @return mixed |
|
2094 | + */ |
|
2095 | + public static function minify_js($input) { |
|
2096 | + if(trim($input) === "") return $input; |
|
2097 | + return preg_replace( |
|
2098 | + array( |
|
2099 | + // Remove comment(s) |
|
2100 | + '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
|
2101 | + // Remove white-space(s) outside the string and regex |
|
2102 | + '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', |
|
2103 | + // Remove the last semicolon |
|
2104 | + '#;+\}#', |
|
2105 | + // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` |
|
2106 | + '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', |
|
2107 | + // --ibid. From `foo['bar']` to `foo.bar` |
|
2108 | + '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' |
|
2109 | + ), |
|
2110 | + array( |
|
2111 | + '$1', |
|
2112 | + '$1$2', |
|
2113 | + '}', |
|
2114 | + '$1$3', |
|
2115 | + '$1.$3' |
|
2116 | + ), |
|
2117 | + $input); |
|
2118 | + } |
|
2119 | + |
|
2120 | + /** |
|
2121 | + * Minify CSS |
|
2122 | + * |
|
2123 | + * @param $input |
|
2124 | + * |
|
2125 | + * @return mixed |
|
2126 | + */ |
|
2127 | + public static function minify_css($input) { |
|
2128 | + if(trim($input) === "") return $input; |
|
2129 | + return preg_replace( |
|
2130 | + array( |
|
2131 | + // Remove comment(s) |
|
2132 | + '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s', |
|
2133 | + // Remove unused white-space(s) |
|
2134 | + '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', |
|
2135 | + // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0` |
|
2136 | + '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si', |
|
2137 | + // Replace `:0 0 0 0` with `:0` |
|
2138 | + '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i', |
|
2139 | + // Replace `background-position:0` with `background-position:0 0` |
|
2140 | + '#(background-position):0(?=[;\}])#si', |
|
2141 | + // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space |
|
2142 | + '#(?<=[\s:,\-])0+\.(\d+)#s', |
|
2143 | + // Minify string value |
|
2144 | + '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si', |
|
2145 | + '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si', |
|
2146 | + // Minify HEX color code |
|
2147 | + '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i', |
|
2148 | + // Replace `(border|outline):none` with `(border|outline):0` |
|
2149 | + '#(?<=[\{;])(border|outline):none(?=[;\}\!])#', |
|
2150 | + // Remove empty selector(s) |
|
2151 | + '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s' |
|
2152 | + ), |
|
2153 | + array( |
|
2154 | + '$1', |
|
2155 | + '$1$2$3$4$5$6$7', |
|
2156 | + '$1', |
|
2157 | + ':0', |
|
2158 | + '$1:0 0', |
|
2159 | + '.$1', |
|
2160 | + '$1$3', |
|
2161 | + '$1$2$4$5', |
|
2162 | + '$1$2$3', |
|
2163 | + '$1:0', |
|
2164 | + '$1$2' |
|
2165 | + ), |
|
2166 | + $input); |
|
2167 | + } |
|
2168 | + } |
|
2169 | + |
|
2170 | + /** |
|
2171 | + * Run the class if found. |
|
2172 | + */ |
|
2173 | + AyeCode_UI_Settings::instance(); |
|
2174 | 2174 | } |
2175 | 2175 | \ No newline at end of file |