@@ -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( wpinv_format_amount( $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( wpinv_format_amount( $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( wpinv_format_amount( $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,63 +527,63 @@ 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 ) ); |
|
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 | 538 | |
539 | - if ( $interval < 1 ) { |
|
540 | - $interval = 1; |
|
541 | - } |
|
539 | + if ( $interval < 1 ) { |
|
540 | + $interval = 1; |
|
541 | + } |
|
542 | 542 | |
543 | 543 | return $interval; |
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Get the recurring limit. |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param string $context View or edit context. |
|
551 | - * @return int |
|
552 | - */ |
|
553 | - public function get_recurring_limit( $context = 'view' ) { |
|
547 | + * Get the recurring limit. |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param string $context View or edit context. |
|
551 | + * @return int |
|
552 | + */ |
|
553 | + public function get_recurring_limit( $context = 'view' ) { |
|
554 | 554 | return (int) $this->get_prop( 'recurring_limit', $context ); |
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
558 | - * Checks if we have a free trial. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param string $context View or edit context. |
|
562 | - * @return int |
|
563 | - */ |
|
564 | - public function get_is_free_trial( $context = 'view' ) { |
|
558 | + * Checks if we have a free trial. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param string $context View or edit context. |
|
562 | + * @return int |
|
563 | + */ |
|
564 | + public function get_is_free_trial( $context = 'view' ) { |
|
565 | 565 | return (int) $this->get_prop( 'is_free_trial', $context ); |
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
569 | - * Alias for self::get_is_free_trial(). |
|
570 | - * |
|
571 | - * @since 1.0.19 |
|
572 | - * @param string $context View or edit context. |
|
573 | - * @return int |
|
574 | - */ |
|
575 | - public function get_free_trial( $context = 'view' ) { |
|
569 | + * Alias for self::get_is_free_trial(). |
|
570 | + * |
|
571 | + * @since 1.0.19 |
|
572 | + * @param string $context View or edit context. |
|
573 | + * @return int |
|
574 | + */ |
|
575 | + public function get_free_trial( $context = 'view' ) { |
|
576 | 576 | return $this->get_is_free_trial( $context ); |
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
580 | - * Get the trial period. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - * @param bool $full Return abbreviation or in full. |
|
584 | - * @return string |
|
585 | - */ |
|
586 | - public function get_trial_period( $full = false ) { |
|
580 | + * Get the trial period. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + * @param bool $full Return abbreviation or in full. |
|
584 | + * @return string |
|
585 | + */ |
|
586 | + public function get_trial_period( $full = false ) { |
|
587 | 587 | $period = $this->get_prop( 'trial_period', 'view' ); |
588 | 588 | |
589 | 589 | if ( $full && ! is_bool( $full ) ) { |
@@ -594,105 +594,105 @@ discard block |
||
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
597 | - * Get the trial interval. |
|
598 | - * |
|
599 | - * @since 1.0.19 |
|
600 | - * @param string $context View or edit context. |
|
601 | - * @return int |
|
602 | - */ |
|
603 | - public function get_trial_interval( $context = 'view' ) { |
|
597 | + * Get the trial interval. |
|
598 | + * |
|
599 | + * @since 1.0.19 |
|
600 | + * @param string $context View or edit context. |
|
601 | + * @return int |
|
602 | + */ |
|
603 | + public function get_trial_interval( $context = 'view' ) { |
|
604 | 604 | return (int) $this->get_prop( 'trial_interval', $context ); |
605 | - } |
|
605 | + } |
|
606 | 606 | |
607 | - /** |
|
608 | - * Get the item's edit url. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @return string |
|
612 | - */ |
|
613 | - public function get_edit_url() { |
|
607 | + /** |
|
608 | + * Get the item's edit url. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @return string |
|
612 | + */ |
|
613 | + public function get_edit_url() { |
|
614 | 614 | return get_edit_post_link( $this->get_id() ); |
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Given an item's name/custom id, it returns its id. |
|
619 | - * |
|
620 | - * |
|
621 | - * @static |
|
622 | - * @param string $value The item name or custom id. |
|
623 | - * @param string $field Either name or custom_id. |
|
624 | - * @param string $type in case you need to search for a given type. |
|
625 | - * @since 1.0.15 |
|
626 | - * @return int |
|
627 | - */ |
|
628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | - |
|
630 | - // Trim the value. |
|
631 | - $value = sanitize_text_field( $value ); |
|
632 | - |
|
633 | - if ( empty( $value ) ) { |
|
634 | - return 0; |
|
635 | - } |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Given an item's name/custom id, it returns its id. |
|
619 | + * |
|
620 | + * |
|
621 | + * @static |
|
622 | + * @param string $value The item name or custom id. |
|
623 | + * @param string $field Either name or custom_id. |
|
624 | + * @param string $type in case you need to search for a given type. |
|
625 | + * @since 1.0.15 |
|
626 | + * @return int |
|
627 | + */ |
|
628 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | + |
|
630 | + // Trim the value. |
|
631 | + $value = sanitize_text_field( $value ); |
|
632 | + |
|
633 | + if ( empty( $value ) ) { |
|
634 | + return 0; |
|
635 | + } |
|
636 | 636 | |
637 | 637 | // Valid fields. |
638 | 638 | $fields = array( 'custom_id', 'name', 'slug' ); |
639 | 639 | |
640 | - // Ensure a field has been passed. |
|
641 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
642 | - return 0; |
|
643 | - } |
|
644 | - |
|
645 | - if ( $field == 'name' ) { |
|
646 | - $field = 'slug'; |
|
647 | - } |
|
648 | - |
|
649 | - // Maybe retrieve from the cache. |
|
650 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
651 | - if ( ! empty( $item_id ) ) { |
|
652 | - return $item_id; |
|
653 | - } |
|
654 | - |
|
655 | - // Fetch from the db. |
|
656 | - $items = array(); |
|
657 | - if ( $field =='slug' ) { |
|
658 | - $items = get_posts( |
|
659 | - array( |
|
660 | - 'post_type' => 'wpi_item', |
|
661 | - 'name' => $value, |
|
662 | - 'posts_per_page' => 1, |
|
663 | - 'post_status' => 'any', |
|
664 | - ) |
|
665 | - ); |
|
666 | - } |
|
667 | - |
|
668 | - if ( $field =='custom_id' ) { |
|
669 | - $items = get_posts( |
|
670 | - array( |
|
671 | - 'post_type' => 'wpi_item', |
|
672 | - 'posts_per_page' => 1, |
|
673 | - 'post_status' => 'any', |
|
674 | - 'meta_query' => array( |
|
675 | - array( |
|
676 | - 'key' => '_wpinv_type', |
|
677 | - 'value' => $type, |
|
678 | - ), |
|
679 | - array( |
|
680 | - 'key' => '_wpinv_custom_id', |
|
681 | - 'value' => $type, |
|
682 | - ) |
|
683 | - ) |
|
684 | - ) |
|
685 | - ); |
|
686 | - } |
|
687 | - |
|
688 | - if ( empty( $items ) ) { |
|
689 | - return 0; |
|
690 | - } |
|
691 | - |
|
692 | - // Update the cache with our data |
|
693 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
694 | - |
|
695 | - return $items[0]->ID; |
|
640 | + // Ensure a field has been passed. |
|
641 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
642 | + return 0; |
|
643 | + } |
|
644 | + |
|
645 | + if ( $field == 'name' ) { |
|
646 | + $field = 'slug'; |
|
647 | + } |
|
648 | + |
|
649 | + // Maybe retrieve from the cache. |
|
650 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
651 | + if ( ! empty( $item_id ) ) { |
|
652 | + return $item_id; |
|
653 | + } |
|
654 | + |
|
655 | + // Fetch from the db. |
|
656 | + $items = array(); |
|
657 | + if ( $field =='slug' ) { |
|
658 | + $items = get_posts( |
|
659 | + array( |
|
660 | + 'post_type' => 'wpi_item', |
|
661 | + 'name' => $value, |
|
662 | + 'posts_per_page' => 1, |
|
663 | + 'post_status' => 'any', |
|
664 | + ) |
|
665 | + ); |
|
666 | + } |
|
667 | + |
|
668 | + if ( $field =='custom_id' ) { |
|
669 | + $items = get_posts( |
|
670 | + array( |
|
671 | + 'post_type' => 'wpi_item', |
|
672 | + 'posts_per_page' => 1, |
|
673 | + 'post_status' => 'any', |
|
674 | + 'meta_query' => array( |
|
675 | + array( |
|
676 | + 'key' => '_wpinv_type', |
|
677 | + 'value' => $type, |
|
678 | + ), |
|
679 | + array( |
|
680 | + 'key' => '_wpinv_custom_id', |
|
681 | + 'value' => $type, |
|
682 | + ) |
|
683 | + ) |
|
684 | + ) |
|
685 | + ); |
|
686 | + } |
|
687 | + |
|
688 | + if ( empty( $items ) ) { |
|
689 | + return 0; |
|
690 | + } |
|
691 | + |
|
692 | + // Update the cache with our data |
|
693 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
694 | + |
|
695 | + return $items[0]->ID; |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | /** |
@@ -725,52 +725,52 @@ discard block |
||
725 | 725 | */ |
726 | 726 | |
727 | 727 | /** |
728 | - * Set parent order ID. |
|
729 | - * |
|
730 | - * @since 1.0.19 |
|
731 | - */ |
|
732 | - public function set_parent_id( $value ) { |
|
733 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
734 | - return; |
|
735 | - } |
|
736 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
737 | - } |
|
738 | - |
|
739 | - /** |
|
740 | - * Sets item status. |
|
741 | - * |
|
742 | - * @since 1.0.19 |
|
743 | - * @param string $status New status. |
|
744 | - * @return array details of change. |
|
745 | - */ |
|
746 | - public function set_status( $status ) { |
|
728 | + * Set parent order ID. |
|
729 | + * |
|
730 | + * @since 1.0.19 |
|
731 | + */ |
|
732 | + public function set_parent_id( $value ) { |
|
733 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
734 | + return; |
|
735 | + } |
|
736 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
737 | + } |
|
738 | + |
|
739 | + /** |
|
740 | + * Sets item status. |
|
741 | + * |
|
742 | + * @since 1.0.19 |
|
743 | + * @param string $status New status. |
|
744 | + * @return array details of change. |
|
745 | + */ |
|
746 | + public function set_status( $status ) { |
|
747 | 747 | $old_status = $this->get_status(); |
748 | 748 | |
749 | 749 | $this->set_prop( 'status', $status ); |
750 | 750 | |
751 | - return array( |
|
752 | - 'from' => $old_status, |
|
753 | - 'to' => $status, |
|
754 | - ); |
|
751 | + return array( |
|
752 | + 'from' => $old_status, |
|
753 | + 'to' => $status, |
|
754 | + ); |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | /** |
758 | - * Set plugin version when the item was created. |
|
759 | - * |
|
760 | - * @since 1.0.19 |
|
761 | - */ |
|
762 | - public function set_version( $value ) { |
|
763 | - $this->set_prop( 'version', $value ); |
|
758 | + * Set plugin version when the item was created. |
|
759 | + * |
|
760 | + * @since 1.0.19 |
|
761 | + */ |
|
762 | + public function set_version( $value ) { |
|
763 | + $this->set_prop( 'version', $value ); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | /** |
767 | - * Set date when the item was created. |
|
768 | - * |
|
769 | - * @since 1.0.19 |
|
770 | - * @param string $value Value to set. |
|
767 | + * Set date when the item was created. |
|
768 | + * |
|
769 | + * @since 1.0.19 |
|
770 | + * @param string $value Value to set. |
|
771 | 771 | * @return bool Whether or not the date was set. |
772 | - */ |
|
773 | - public function set_date_created( $value ) { |
|
772 | + */ |
|
773 | + public function set_date_created( $value ) { |
|
774 | 774 | $date = strtotime( $value ); |
775 | 775 | |
776 | 776 | if ( $date ) { |
@@ -783,13 +783,13 @@ discard block |
||
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
786 | - * Set date when the item was last modified. |
|
787 | - * |
|
788 | - * @since 1.0.19 |
|
789 | - * @param string $value Value to set. |
|
786 | + * Set date when the item was last modified. |
|
787 | + * |
|
788 | + * @since 1.0.19 |
|
789 | + * @param string $value Value to set. |
|
790 | 790 | * @return bool Whether or not the date was set. |
791 | - */ |
|
792 | - public function set_date_modified( $value ) { |
|
791 | + */ |
|
792 | + public function set_date_modified( $value ) { |
|
793 | 793 | $date = strtotime( $value ); |
794 | 794 | |
795 | 795 | if ( $date ) { |
@@ -802,115 +802,115 @@ discard block |
||
802 | 802 | } |
803 | 803 | |
804 | 804 | /** |
805 | - * Set the item name. |
|
806 | - * |
|
807 | - * @since 1.0.19 |
|
808 | - * @param string $value New name. |
|
809 | - */ |
|
810 | - public function set_name( $value ) { |
|
805 | + * Set the item name. |
|
806 | + * |
|
807 | + * @since 1.0.19 |
|
808 | + * @param string $value New name. |
|
809 | + */ |
|
810 | + public function set_name( $value ) { |
|
811 | 811 | $name = sanitize_text_field( $value ); |
812 | - $this->set_prop( 'name', $name ); |
|
812 | + $this->set_prop( 'name', $name ); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
816 | - * Alias of self::set_name(). |
|
817 | - * |
|
818 | - * @since 1.0.19 |
|
819 | - * @param string $value New name. |
|
820 | - */ |
|
821 | - public function set_title( $value ) { |
|
822 | - $this->set_name( $value ); |
|
816 | + * Alias of self::set_name(). |
|
817 | + * |
|
818 | + * @since 1.0.19 |
|
819 | + * @param string $value New name. |
|
820 | + */ |
|
821 | + public function set_title( $value ) { |
|
822 | + $this->set_name( $value ); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | /** |
826 | - * Set the item description. |
|
827 | - * |
|
828 | - * @since 1.0.19 |
|
829 | - * @param string $value New description. |
|
830 | - */ |
|
831 | - public function set_description( $value ) { |
|
826 | + * Set the item description. |
|
827 | + * |
|
828 | + * @since 1.0.19 |
|
829 | + * @param string $value New description. |
|
830 | + */ |
|
831 | + public function set_description( $value ) { |
|
832 | 832 | $description = wp_kses_post( $value ); |
833 | - return $this->set_prop( 'description', $description ); |
|
833 | + return $this->set_prop( 'description', $description ); |
|
834 | 834 | } |
835 | 835 | |
836 | 836 | /** |
837 | - * Alias of self::set_description(). |
|
838 | - * |
|
839 | - * @since 1.0.19 |
|
840 | - * @param string $value New description. |
|
841 | - */ |
|
842 | - public function set_excerpt( $value ) { |
|
843 | - $this->set_description( $value ); |
|
837 | + * Alias of self::set_description(). |
|
838 | + * |
|
839 | + * @since 1.0.19 |
|
840 | + * @param string $value New description. |
|
841 | + */ |
|
842 | + public function set_excerpt( $value ) { |
|
843 | + $this->set_description( $value ); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
847 | - * Alias of self::set_description(). |
|
848 | - * |
|
849 | - * @since 1.0.19 |
|
850 | - * @param string $value New description. |
|
851 | - */ |
|
852 | - public function set_summary( $value ) { |
|
853 | - $this->set_description( $value ); |
|
847 | + * Alias of self::set_description(). |
|
848 | + * |
|
849 | + * @since 1.0.19 |
|
850 | + * @param string $value New description. |
|
851 | + */ |
|
852 | + public function set_summary( $value ) { |
|
853 | + $this->set_description( $value ); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
857 | - * Set the owner of the item. |
|
858 | - * |
|
859 | - * @since 1.0.19 |
|
860 | - * @param int $value New author. |
|
861 | - */ |
|
862 | - public function set_author( $value ) { |
|
863 | - $this->set_prop( 'author', (int) $value ); |
|
864 | - } |
|
857 | + * Set the owner of the item. |
|
858 | + * |
|
859 | + * @since 1.0.19 |
|
860 | + * @param int $value New author. |
|
861 | + */ |
|
862 | + public function set_author( $value ) { |
|
863 | + $this->set_prop( 'author', (int) $value ); |
|
864 | + } |
|
865 | 865 | |
866 | - /** |
|
867 | - * Alias of self::set_author(). |
|
868 | - * |
|
869 | - * @since 1.0.19 |
|
870 | - * @param int $value New author. |
|
871 | - */ |
|
872 | - public function set_owner( $value ) { |
|
873 | - $this->set_author( $value ); |
|
874 | - } |
|
875 | - |
|
876 | - /** |
|
877 | - * Set the price of the item. |
|
878 | - * |
|
879 | - * @since 1.0.19 |
|
880 | - * @param float $value New price. |
|
881 | - */ |
|
882 | - public function set_price( $value ) { |
|
866 | + /** |
|
867 | + * Alias of self::set_author(). |
|
868 | + * |
|
869 | + * @since 1.0.19 |
|
870 | + * @param int $value New author. |
|
871 | + */ |
|
872 | + public function set_owner( $value ) { |
|
873 | + $this->set_author( $value ); |
|
874 | + } |
|
875 | + |
|
876 | + /** |
|
877 | + * Set the price of the item. |
|
878 | + * |
|
879 | + * @since 1.0.19 |
|
880 | + * @param float $value New price. |
|
881 | + */ |
|
882 | + public function set_price( $value ) { |
|
883 | 883 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
887 | - * Set the VAT rule of the item. |
|
888 | - * |
|
889 | - * @since 1.0.19 |
|
890 | - * @param string $value new rule. |
|
891 | - */ |
|
892 | - public function set_vat_rule( $value ) { |
|
887 | + * Set the VAT rule of the item. |
|
888 | + * |
|
889 | + * @since 1.0.19 |
|
890 | + * @param string $value new rule. |
|
891 | + */ |
|
892 | + public function set_vat_rule( $value ) { |
|
893 | 893 | $this->set_prop( 'vat_rule', $value ); |
894 | 894 | } |
895 | 895 | |
896 | 896 | /** |
897 | - * Set the VAT class of the item. |
|
898 | - * |
|
899 | - * @since 1.0.19 |
|
900 | - * @param string $value new class. |
|
901 | - */ |
|
902 | - public function set_vat_class( $value ) { |
|
897 | + * Set the VAT class of the item. |
|
898 | + * |
|
899 | + * @since 1.0.19 |
|
900 | + * @param string $value new class. |
|
901 | + */ |
|
902 | + public function set_vat_class( $value ) { |
|
903 | 903 | $this->set_prop( 'vat_class', $value ); |
904 | 904 | } |
905 | 905 | |
906 | 906 | /** |
907 | - * Set the type of the item. |
|
908 | - * |
|
909 | - * @since 1.0.19 |
|
910 | - * @param string $value new item type. |
|
911 | - * @return string |
|
912 | - */ |
|
913 | - public function set_type( $value ) { |
|
907 | + * Set the type of the item. |
|
908 | + * |
|
909 | + * @since 1.0.19 |
|
910 | + * @param string $value new item type. |
|
911 | + * @return string |
|
912 | + */ |
|
913 | + public function set_type( $value ) { |
|
914 | 914 | |
915 | 915 | if ( empty( $value ) ) { |
916 | 916 | $value = 'custom'; |
@@ -920,134 +920,134 @@ discard block |
||
920 | 920 | } |
921 | 921 | |
922 | 922 | /** |
923 | - * Set the custom id of the item. |
|
924 | - * |
|
925 | - * @since 1.0.19 |
|
926 | - * @param string $value new custom id. |
|
927 | - */ |
|
928 | - public function set_custom_id( $value ) { |
|
923 | + * Set the custom id of the item. |
|
924 | + * |
|
925 | + * @since 1.0.19 |
|
926 | + * @param string $value new custom id. |
|
927 | + */ |
|
928 | + public function set_custom_id( $value ) { |
|
929 | 929 | $this->set_prop( 'custom_id', $value ); |
930 | 930 | } |
931 | 931 | |
932 | 932 | /** |
933 | - * Set the custom name of the item. |
|
934 | - * |
|
935 | - * @since 1.0.19 |
|
936 | - * @param string $value new custom name. |
|
937 | - */ |
|
938 | - public function set_custom_name( $value ) { |
|
933 | + * Set the custom name of the item. |
|
934 | + * |
|
935 | + * @since 1.0.19 |
|
936 | + * @param string $value new custom name. |
|
937 | + */ |
|
938 | + public function set_custom_name( $value ) { |
|
939 | 939 | $this->set_prop( 'custom_name', $value ); |
940 | 940 | } |
941 | 941 | |
942 | 942 | /** |
943 | - * Set the custom singular name of the item. |
|
944 | - * |
|
945 | - * @since 1.0.19 |
|
946 | - * @param string $value new custom singular name. |
|
947 | - */ |
|
948 | - public function set_custom_singular_name( $value ) { |
|
943 | + * Set the custom singular name of the item. |
|
944 | + * |
|
945 | + * @since 1.0.19 |
|
946 | + * @param string $value new custom singular name. |
|
947 | + */ |
|
948 | + public function set_custom_singular_name( $value ) { |
|
949 | 949 | $this->set_prop( 'custom_singular_name', $value ); |
950 | 950 | } |
951 | 951 | |
952 | 952 | /** |
953 | - * Sets if an item is editable.. |
|
954 | - * |
|
955 | - * @since 1.0.19 |
|
956 | - * @param int|bool $value whether or not the item is editable. |
|
957 | - */ |
|
958 | - public function set_is_editable( $value ) { |
|
959 | - if ( is_numeric( $value ) ) { |
|
960 | - $this->set_prop( 'is_editable', (int) $value ); |
|
961 | - } |
|
953 | + * Sets if an item is editable.. |
|
954 | + * |
|
955 | + * @since 1.0.19 |
|
956 | + * @param int|bool $value whether or not the item is editable. |
|
957 | + */ |
|
958 | + public function set_is_editable( $value ) { |
|
959 | + if ( is_numeric( $value ) ) { |
|
960 | + $this->set_prop( 'is_editable', (int) $value ); |
|
961 | + } |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | /** |
965 | - * Sets if dynamic pricing is enabled. |
|
966 | - * |
|
967 | - * @since 1.0.19 |
|
968 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
969 | - */ |
|
970 | - public function set_is_dynamic_pricing( $value ) { |
|
965 | + * Sets if dynamic pricing is enabled. |
|
966 | + * |
|
967 | + * @since 1.0.19 |
|
968 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
969 | + */ |
|
970 | + public function set_is_dynamic_pricing( $value ) { |
|
971 | 971 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
972 | 972 | } |
973 | 973 | |
974 | 974 | /** |
975 | - * Sets the minimum price if dynamic pricing is enabled. |
|
976 | - * |
|
977 | - * @since 1.0.19 |
|
978 | - * @param float $value minimum price. |
|
979 | - */ |
|
980 | - public function set_minimum_price( $value ) { |
|
975 | + * Sets the minimum price if dynamic pricing is enabled. |
|
976 | + * |
|
977 | + * @since 1.0.19 |
|
978 | + * @param float $value minimum price. |
|
979 | + */ |
|
980 | + public function set_minimum_price( $value ) { |
|
981 | 981 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
982 | 982 | } |
983 | 983 | |
984 | 984 | /** |
985 | - * Sets if this is a recurring item. |
|
986 | - * |
|
987 | - * @since 1.0.19 |
|
988 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
989 | - */ |
|
990 | - public function set_is_recurring( $value ) { |
|
985 | + * Sets if this is a recurring item. |
|
986 | + * |
|
987 | + * @since 1.0.19 |
|
988 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
989 | + */ |
|
990 | + public function set_is_recurring( $value ) { |
|
991 | 991 | $this->set_prop( 'is_recurring', (int) $value ); |
992 | 992 | } |
993 | 993 | |
994 | 994 | /** |
995 | - * Set the recurring period. |
|
996 | - * |
|
997 | - * @since 1.0.19 |
|
998 | - * @param string $value new period. |
|
999 | - */ |
|
1000 | - public function set_recurring_period( $value ) { |
|
995 | + * Set the recurring period. |
|
996 | + * |
|
997 | + * @since 1.0.19 |
|
998 | + * @param string $value new period. |
|
999 | + */ |
|
1000 | + public function set_recurring_period( $value ) { |
|
1001 | 1001 | $this->set_prop( 'recurring_period', $value ); |
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | /** |
1005 | - * Set the recurring interval. |
|
1006 | - * |
|
1007 | - * @since 1.0.19 |
|
1008 | - * @param int $value recurring interval. |
|
1009 | - */ |
|
1010 | - public function set_recurring_interval( $value ) { |
|
1005 | + * Set the recurring interval. |
|
1006 | + * |
|
1007 | + * @since 1.0.19 |
|
1008 | + * @param int $value recurring interval. |
|
1009 | + */ |
|
1010 | + public function set_recurring_interval( $value ) { |
|
1011 | 1011 | return $this->set_prop( 'recurring_interval', (int) $value ); |
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | /** |
1015 | - * Get the recurring limit. |
|
1016 | - * @since 1.0.19 |
|
1017 | - * @param int $value The recurring limit. |
|
1018 | - * @return int |
|
1019 | - */ |
|
1020 | - public function set_recurring_limit( $value ) { |
|
1015 | + * Get the recurring limit. |
|
1016 | + * @since 1.0.19 |
|
1017 | + * @param int $value The recurring limit. |
|
1018 | + * @return int |
|
1019 | + */ |
|
1020 | + public function set_recurring_limit( $value ) { |
|
1021 | 1021 | $this->set_prop( 'recurring_limit', (int) $value ); |
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | /** |
1025 | - * Checks if we have a free trial. |
|
1026 | - * |
|
1027 | - * @since 1.0.19 |
|
1028 | - * @param int|bool $value whether or not it has a free trial. |
|
1029 | - */ |
|
1030 | - public function set_is_free_trial( $value ) { |
|
1025 | + * Checks if we have a free trial. |
|
1026 | + * |
|
1027 | + * @since 1.0.19 |
|
1028 | + * @param int|bool $value whether or not it has a free trial. |
|
1029 | + */ |
|
1030 | + public function set_is_free_trial( $value ) { |
|
1031 | 1031 | $this->set_prop( 'is_free_trial', (int) $value ); |
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | /** |
1035 | - * Set the trial period. |
|
1036 | - * |
|
1037 | - * @since 1.0.19 |
|
1038 | - * @param string $value trial period. |
|
1039 | - */ |
|
1040 | - public function set_trial_period( $value ) { |
|
1035 | + * Set the trial period. |
|
1036 | + * |
|
1037 | + * @since 1.0.19 |
|
1038 | + * @param string $value trial period. |
|
1039 | + */ |
|
1040 | + public function set_trial_period( $value ) { |
|
1041 | 1041 | $this->set_prop( 'trial_period', $value ); |
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | /** |
1045 | - * Set the trial interval. |
|
1046 | - * |
|
1047 | - * @since 1.0.19 |
|
1048 | - * @param int $value trial interval. |
|
1049 | - */ |
|
1050 | - public function set_trial_interval( $value ) { |
|
1045 | + * Set the trial interval. |
|
1046 | + * |
|
1047 | + * @since 1.0.19 |
|
1048 | + * @param int $value trial interval. |
|
1049 | + */ |
|
1050 | + public function set_trial_interval( $value ) { |
|
1051 | 1051 | $this->set_prop( 'trial_interval', $value ); |
1052 | 1052 | } |
1053 | 1053 | |
@@ -1055,17 +1055,17 @@ discard block |
||
1055 | 1055 | * Create an item. For backwards compatibilty. |
1056 | 1056 | * |
1057 | 1057 | * @deprecated |
1058 | - * @return int item id |
|
1058 | + * @return int item id |
|
1059 | 1059 | */ |
1060 | 1060 | public function create( $data = array() ) { |
1061 | 1061 | |
1062 | - // Set the properties. |
|
1063 | - if ( is_array( $data ) ) { |
|
1064 | - $this->set_props( $data ); |
|
1065 | - } |
|
1062 | + // Set the properties. |
|
1063 | + if ( is_array( $data ) ) { |
|
1064 | + $this->set_props( $data ); |
|
1065 | + } |
|
1066 | 1066 | |
1067 | - // Save the item. |
|
1068 | - return $this->save(); |
|
1067 | + // Save the item. |
|
1068 | + return $this->save(); |
|
1069 | 1069 | |
1070 | 1070 | } |
1071 | 1071 | |
@@ -1073,7 +1073,7 @@ discard block |
||
1073 | 1073 | * Updates an item. For backwards compatibilty. |
1074 | 1074 | * |
1075 | 1075 | * @deprecated |
1076 | - * @return int item id |
|
1076 | + * @return int item id |
|
1077 | 1077 | */ |
1078 | 1078 | public function update( $data = array() ) { |
1079 | 1079 | return $this->create( $data ); |
@@ -1089,84 +1089,84 @@ discard block |
||
1089 | 1089 | */ |
1090 | 1090 | |
1091 | 1091 | /** |
1092 | - * Checks whether the item has enabled dynamic pricing. |
|
1093 | - * |
|
1094 | - * @since 1.0.19 |
|
1095 | - * @return bool |
|
1096 | - */ |
|
1097 | - public function user_can_set_their_price() { |
|
1092 | + * Checks whether the item has enabled dynamic pricing. |
|
1093 | + * |
|
1094 | + * @since 1.0.19 |
|
1095 | + * @return bool |
|
1096 | + */ |
|
1097 | + public function user_can_set_their_price() { |
|
1098 | 1098 | return (bool) $this->get_is_dynamic_pricing(); |
1099 | - } |
|
1099 | + } |
|
1100 | 1100 | |
1101 | - /** |
|
1102 | - * Checks whether the item is recurring. |
|
1103 | - * |
|
1104 | - * @since 1.0.19 |
|
1105 | - * @return bool |
|
1106 | - */ |
|
1107 | - public function is_recurring() { |
|
1101 | + /** |
|
1102 | + * Checks whether the item is recurring. |
|
1103 | + * |
|
1104 | + * @since 1.0.19 |
|
1105 | + * @return bool |
|
1106 | + */ |
|
1107 | + public function is_recurring() { |
|
1108 | 1108 | return (bool) $this->get_is_recurring(); |
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | /** |
1112 | - * Checks whether the item has a free trial. |
|
1113 | - * |
|
1114 | - * @since 1.0.19 |
|
1115 | - * @return bool |
|
1116 | - */ |
|
1112 | + * Checks whether the item has a free trial. |
|
1113 | + * |
|
1114 | + * @since 1.0.19 |
|
1115 | + * @return bool |
|
1116 | + */ |
|
1117 | 1117 | public function has_free_trial() { |
1118 | 1118 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1119 | 1119 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | /** |
1123 | - * Checks whether the item is free. |
|
1124 | - * |
|
1125 | - * @since 1.0.19 |
|
1126 | - * @return bool |
|
1127 | - */ |
|
1123 | + * Checks whether the item is free. |
|
1124 | + * |
|
1125 | + * @since 1.0.19 |
|
1126 | + * @return bool |
|
1127 | + */ |
|
1128 | 1128 | public function is_free() { |
1129 | 1129 | $is_free = $this->get_price() == 0; |
1130 | 1130 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | /** |
1134 | - * Checks the item status against a passed in status. |
|
1135 | - * |
|
1136 | - * @param array|string $status Status to check. |
|
1137 | - * @return bool |
|
1138 | - */ |
|
1139 | - public function has_status( $status ) { |
|
1140 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1141 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1134 | + * Checks the item status against a passed in status. |
|
1135 | + * |
|
1136 | + * @param array|string $status Status to check. |
|
1137 | + * @return bool |
|
1138 | + */ |
|
1139 | + public function has_status( $status ) { |
|
1140 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1141 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | /** |
1145 | - * Checks the item type against a passed in types. |
|
1146 | - * |
|
1147 | - * @param array|string $type Type to check. |
|
1148 | - * @return bool |
|
1149 | - */ |
|
1150 | - public function is_type( $type ) { |
|
1151 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1152 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1153 | - } |
|
1145 | + * Checks the item type against a passed in types. |
|
1146 | + * |
|
1147 | + * @param array|string $type Type to check. |
|
1148 | + * @return bool |
|
1149 | + */ |
|
1150 | + public function is_type( $type ) { |
|
1151 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1152 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1153 | + } |
|
1154 | 1154 | |
1155 | 1155 | /** |
1156 | - * Checks whether the item is editable. |
|
1157 | - * |
|
1158 | - * @since 1.0.19 |
|
1159 | - * @return bool |
|
1160 | - */ |
|
1156 | + * Checks whether the item is editable. |
|
1157 | + * |
|
1158 | + * @since 1.0.19 |
|
1159 | + * @return bool |
|
1160 | + */ |
|
1161 | 1161 | public function is_editable() { |
1162 | 1162 | $is_editable = $this->get_is_editable(); |
1163 | 1163 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
1164 | - } |
|
1164 | + } |
|
1165 | 1165 | |
1166 | - /** |
|
1167 | - * Returns an array of cart fees. |
|
1168 | - */ |
|
1169 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1166 | + /** |
|
1167 | + * Returns an array of cart fees. |
|
1168 | + */ |
|
1169 | + public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1170 | 1170 | |
1171 | 1171 | $fees = getpaid_session()->get( 'wpi_cart_fees' ); |
1172 | 1172 | |
@@ -1209,11 +1209,11 @@ discard block |
||
1209 | 1209 | } |
1210 | 1210 | |
1211 | 1211 | /** |
1212 | - * Checks whether the item is purchasable. |
|
1213 | - * |
|
1214 | - * @since 1.0.19 |
|
1215 | - * @return bool |
|
1216 | - */ |
|
1212 | + * Checks whether the item is purchasable. |
|
1213 | + * |
|
1214 | + * @since 1.0.19 |
|
1215 | + * @return bool |
|
1216 | + */ |
|
1217 | 1217 | public function can_purchase() { |
1218 | 1218 | $can_purchase = $this->exists(); |
1219 | 1219 | |
@@ -1225,11 +1225,11 @@ discard block |
||
1225 | 1225 | } |
1226 | 1226 | |
1227 | 1227 | /** |
1228 | - * Checks whether the item supports dynamic pricing. |
|
1229 | - * |
|
1230 | - * @since 1.0.19 |
|
1231 | - * @return bool |
|
1232 | - */ |
|
1228 | + * Checks whether the item supports dynamic pricing. |
|
1229 | + * |
|
1230 | + * @since 1.0.19 |
|
1231 | + * @return bool |
|
1232 | + */ |
|
1233 | 1233 | public function supports_dynamic_pricing() { |
1234 | 1234 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
1235 | 1235 | } |
@@ -14,62 +14,62 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | public $admin_url; |
29 | 29 | |
30 | 30 | /** |
31 | - * Class constructor. |
|
32 | - */ |
|
33 | - public function __construct(){ |
|
31 | + * Class constructor. |
|
32 | + */ |
|
33 | + public function __construct(){ |
|
34 | 34 | |
35 | 35 | $this->admin_path = plugin_dir_path( __FILE__ ); |
36 | 36 | $this->admin_url = plugins_url( '/', __FILE__ ); |
37 | 37 | |
38 | 38 | if ( is_admin() ) { |
39 | - $this->init_admin_hooks(); |
|
39 | + $this->init_admin_hooks(); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | - * Init action and filter hooks |
|
46 | - * |
|
47 | - */ |
|
48 | - private function init_admin_hooks() { |
|
45 | + * Init action and filter hooks |
|
46 | + * |
|
47 | + */ |
|
48 | + private function init_admin_hooks() { |
|
49 | 49 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
50 | 50 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
51 | 51 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
52 | 52 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
53 | 53 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
54 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
54 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | - * Register admin scripts |
|
63 | - * |
|
64 | - */ |
|
65 | - public function enqeue_scripts() { |
|
62 | + * Register admin scripts |
|
63 | + * |
|
64 | + */ |
|
65 | + public function enqeue_scripts() { |
|
66 | 66 | global $current_screen, $pagenow; |
67 | 67 | |
68 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
69 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
68 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
69 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
70 | 70 | |
71 | 71 | if ( ! empty( $current_screen->post_type ) ) { |
72 | - $page = $current_screen->post_type; |
|
72 | + $page = $current_screen->post_type; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // General styles. |
@@ -93,30 +93,30 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | // Payment form scripts. |
96 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
96 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
97 | 97 | $this->load_payment_form_scripts(); |
98 | 98 | } |
99 | 99 | |
100 | 100 | if ( $page == 'wpinv-subscriptions' ) { |
101 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
103 | - } |
|
101 | + wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | + wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
103 | + } |
|
104 | 104 | |
105 | - if ( $page == 'wpinv-reports' ) { |
|
106 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
107 | - } |
|
105 | + if ( $page == 'wpinv-reports' ) { |
|
106 | + wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
107 | + } |
|
108 | 108 | |
109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
110 | - wp_enqueue_script( 'postbox' ); |
|
111 | - } |
|
109 | + if ( $page == 'wpinv-subscriptions' ) { |
|
110 | + wp_enqueue_script( 'postbox' ); |
|
111 | + } |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | - * Returns admin js translations. |
|
117 | - * |
|
118 | - */ |
|
119 | - protected function get_admin_i18() { |
|
116 | + * Returns admin js translations. |
|
117 | + * |
|
118 | + */ |
|
119 | + protected function get_admin_i18() { |
|
120 | 120 | global $post; |
121 | 121 | |
122 | 122 | return array( |
@@ -157,32 +157,32 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | - * Loads payment form js. |
|
161 | - * |
|
162 | - */ |
|
163 | - protected function load_payment_form_scripts() { |
|
160 | + * Loads payment form js. |
|
161 | + * |
|
162 | + */ |
|
163 | + protected function load_payment_form_scripts() { |
|
164 | 164 | global $post; |
165 | 165 | |
166 | 166 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
167 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
167 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
169 | 169 | |
170 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
170 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
172 | 172 | |
173 | - wp_localize_script( |
|
173 | + wp_localize_script( |
|
174 | 174 | 'wpinv-admin-payment-form-script', |
175 | 175 | 'wpinvPaymentFormAdmin', |
176 | 176 | array( |
177 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
178 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
179 | - 'currency' => wpinv_currency_symbol(), |
|
180 | - 'position' => wpinv_currency_position(), |
|
181 | - 'decimals' => (int) wpinv_decimals(), |
|
182 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
183 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
184 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
185 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
177 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
178 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
179 | + 'currency' => wpinv_currency_symbol(), |
|
180 | + 'position' => wpinv_currency_position(), |
|
181 | + 'decimals' => (int) wpinv_decimals(), |
|
182 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
183 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
184 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
185 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
186 | 186 | ) |
187 | 187 | ); |
188 | 188 | |
@@ -191,20 +191,20 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | - * Add our classes to admin pages. |
|
194 | + * Add our classes to admin pages. |
|
195 | 195 | * |
196 | 196 | * @param string $classes |
197 | 197 | * @return string |
198 | - * |
|
199 | - */ |
|
198 | + * |
|
199 | + */ |
|
200 | 200 | public function admin_body_class( $classes ) { |
201 | - global $pagenow, $post, $current_screen; |
|
201 | + global $pagenow, $post, $current_screen; |
|
202 | 202 | |
203 | 203 | |
204 | 204 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
205 | 205 | |
206 | 206 | if ( ! empty( $current_screen->post_type ) ) { |
207 | - $page = $current_screen->post_type; |
|
207 | + $page = $current_screen->post_type; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -215,27 +215,27 @@ discard block |
||
215 | 215 | $classes .= ' wpinv-cpt wpinv'; |
216 | 216 | } |
217 | 217 | |
218 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
219 | - $classes .= ' wpi-editable-n'; |
|
220 | - } |
|
218 | + if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
219 | + $classes .= ' wpi-editable-n'; |
|
220 | + } |
|
221 | 221 | |
222 | - return $classes; |
|
222 | + return $classes; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
226 | - * Maybe show the AyeCode Connect Notice. |
|
227 | - */ |
|
228 | - public function init_ayecode_connect_helper(){ |
|
226 | + * Maybe show the AyeCode Connect Notice. |
|
227 | + */ |
|
228 | + public function init_ayecode_connect_helper(){ |
|
229 | 229 | |
230 | 230 | new AyeCode_Connect_Helper( |
231 | 231 | array( |
232 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | - 'connect_button' => __("Connect Site","invoicing"), |
|
236 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
232 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | + 'connect_button' => __("Connect Site","invoicing"), |
|
236 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
239 | 239 | ), |
240 | 240 | array( 'wpi-addons' ) |
241 | 241 | ); |
@@ -247,21 +247,21 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function activation_redirect() { |
249 | 249 | |
250 | - // Bail if no activation redirect. |
|
251 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
252 | - return; |
|
253 | - } |
|
250 | + // Bail if no activation redirect. |
|
251 | + if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
252 | + return; |
|
253 | + } |
|
254 | 254 | |
255 | - // Delete the redirect transient. |
|
256 | - delete_transient( '_wpinv_activation_redirect' ); |
|
255 | + // Delete the redirect transient. |
|
256 | + delete_transient( '_wpinv_activation_redirect' ); |
|
257 | 257 | |
258 | - // Bail if activating from network, or bulk |
|
259 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
260 | - return; |
|
261 | - } |
|
258 | + // Bail if activating from network, or bulk |
|
259 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
260 | + return; |
|
261 | + } |
|
262 | 262 | |
263 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
264 | - exit; |
|
263 | + wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
264 | + exit; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -276,150 +276,150 @@ discard block |
||
276 | 276 | |
277 | 277 | } |
278 | 278 | |
279 | - /** |
|
279 | + /** |
|
280 | 280 | * Sends a payment reminder to a customer. |
281 | - * |
|
282 | - * @param array $args |
|
281 | + * |
|
282 | + * @param array $args |
|
283 | 283 | */ |
284 | 284 | public function send_customer_invoice( $args ) { |
285 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
285 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
286 | 286 | |
287 | - if ( $sent ) { |
|
288 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
289 | - } else { |
|
290 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
291 | - } |
|
287 | + if ( $sent ) { |
|
288 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
289 | + } else { |
|
290 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
291 | + } |
|
292 | 292 | |
293 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
294 | - exit; |
|
295 | - } |
|
293 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
294 | + exit; |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
297 | + /** |
|
298 | 298 | * Sends a payment reminder to a customer. |
299 | - * |
|
300 | - * @param array $args |
|
299 | + * |
|
300 | + * @param array $args |
|
301 | 301 | */ |
302 | 302 | public function send_customer_payment_reminder( $args ) { |
303 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
303 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
304 | 304 | |
305 | - if ( $sent ) { |
|
306 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
307 | - } else { |
|
308 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
309 | - } |
|
305 | + if ( $sent ) { |
|
306 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
307 | + } else { |
|
308 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
309 | + } |
|
310 | 310 | |
311 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
312 | - exit; |
|
313 | - } |
|
311 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
312 | + exit; |
|
313 | + } |
|
314 | 314 | |
315 | 315 | /** |
316 | - * Returns an array of admin notices. |
|
317 | - * |
|
318 | - * @since 1.0.19 |
|
316 | + * Returns an array of admin notices. |
|
317 | + * |
|
318 | + * @since 1.0.19 |
|
319 | 319 | * @return array |
320 | - */ |
|
321 | - public function get_notices() { |
|
322 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
320 | + */ |
|
321 | + public function get_notices() { |
|
322 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
323 | 323 | return is_array( $notices ) ? $notices : array(); |
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Clears all admin notices |
|
328 | - * |
|
329 | - * @access public |
|
330 | - * @since 1.0.19 |
|
331 | - */ |
|
332 | - public function clear_notices() { |
|
333 | - delete_option( 'wpinv_admin_notices' ); |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Saves a new admin notice |
|
338 | - * |
|
339 | - * @access public |
|
340 | - * @since 1.0.19 |
|
341 | - */ |
|
342 | - public function save_notice( $type, $message ) { |
|
343 | - $notices = $this->get_notices(); |
|
344 | - |
|
345 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | - $notices[ $type ] = array(); |
|
347 | - } |
|
348 | - |
|
349 | - $notices[ $type ][] = $message; |
|
350 | - |
|
351 | - update_option( 'wpinv_admin_notices', $notices ); |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Displays a success notice |
|
356 | - * |
|
357 | - * @param string $msg The message to qeue. |
|
358 | - * @access public |
|
359 | - * @since 1.0.19 |
|
360 | - */ |
|
361 | - public function show_success( $msg ) { |
|
362 | - $this->save_notice( 'success', $msg ); |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Displays a error notice |
|
367 | - * |
|
368 | - * @access public |
|
369 | - * @param string $msg The message to qeue. |
|
370 | - * @since 1.0.19 |
|
371 | - */ |
|
372 | - public function show_error( $msg ) { |
|
373 | - $this->save_notice( 'error', $msg ); |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Displays a warning notice |
|
378 | - * |
|
379 | - * @access public |
|
380 | - * @param string $msg The message to qeue. |
|
381 | - * @since 1.0.19 |
|
382 | - */ |
|
383 | - public function show_warning( $msg ) { |
|
384 | - $this->save_notice( 'warning', $msg ); |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Displays a info notice |
|
389 | - * |
|
390 | - * @access public |
|
391 | - * @param string $msg The message to qeue. |
|
392 | - * @since 1.0.19 |
|
393 | - */ |
|
394 | - public function show_info( $msg ) { |
|
395 | - $this->save_notice( 'info', $msg ); |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Show notices |
|
400 | - * |
|
401 | - * @access public |
|
402 | - * @since 1.0.19 |
|
403 | - */ |
|
404 | - public function show_notices() { |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Clears all admin notices |
|
328 | + * |
|
329 | + * @access public |
|
330 | + * @since 1.0.19 |
|
331 | + */ |
|
332 | + public function clear_notices() { |
|
333 | + delete_option( 'wpinv_admin_notices' ); |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Saves a new admin notice |
|
338 | + * |
|
339 | + * @access public |
|
340 | + * @since 1.0.19 |
|
341 | + */ |
|
342 | + public function save_notice( $type, $message ) { |
|
343 | + $notices = $this->get_notices(); |
|
344 | + |
|
345 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | + $notices[ $type ] = array(); |
|
347 | + } |
|
348 | + |
|
349 | + $notices[ $type ][] = $message; |
|
350 | + |
|
351 | + update_option( 'wpinv_admin_notices', $notices ); |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Displays a success notice |
|
356 | + * |
|
357 | + * @param string $msg The message to qeue. |
|
358 | + * @access public |
|
359 | + * @since 1.0.19 |
|
360 | + */ |
|
361 | + public function show_success( $msg ) { |
|
362 | + $this->save_notice( 'success', $msg ); |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Displays a error notice |
|
367 | + * |
|
368 | + * @access public |
|
369 | + * @param string $msg The message to qeue. |
|
370 | + * @since 1.0.19 |
|
371 | + */ |
|
372 | + public function show_error( $msg ) { |
|
373 | + $this->save_notice( 'error', $msg ); |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Displays a warning notice |
|
378 | + * |
|
379 | + * @access public |
|
380 | + * @param string $msg The message to qeue. |
|
381 | + * @since 1.0.19 |
|
382 | + */ |
|
383 | + public function show_warning( $msg ) { |
|
384 | + $this->save_notice( 'warning', $msg ); |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Displays a info notice |
|
389 | + * |
|
390 | + * @access public |
|
391 | + * @param string $msg The message to qeue. |
|
392 | + * @since 1.0.19 |
|
393 | + */ |
|
394 | + public function show_info( $msg ) { |
|
395 | + $this->save_notice( 'info', $msg ); |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Show notices |
|
400 | + * |
|
401 | + * @access public |
|
402 | + * @since 1.0.19 |
|
403 | + */ |
|
404 | + public function show_notices() { |
|
405 | 405 | |
406 | 406 | $notices = $this->get_notices(); |
407 | 407 | $this->clear_notices(); |
408 | 408 | |
409 | - foreach ( $notices as $type => $messages ) { |
|
409 | + foreach ( $notices as $type => $messages ) { |
|
410 | 410 | |
411 | - if ( ! is_array( $messages ) ) { |
|
412 | - continue; |
|
413 | - } |
|
411 | + if ( ! is_array( $messages ) ) { |
|
412 | + continue; |
|
413 | + } |
|
414 | 414 | |
415 | 415 | $type = sanitize_key( $type ); |
416 | - foreach ( $messages as $message ) { |
|
416 | + foreach ( $messages as $message ) { |
|
417 | 417 | $message = wp_kses_post( $message ); |
418 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
418 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | } |
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | 425 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -175,122 +175,122 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
179 | 179 | |
180 | - // Setup possible parts |
|
181 | - $templates = array(); |
|
182 | - if ( isset( $name ) ) |
|
183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
184 | - $templates[] = $slug . '.php'; |
|
180 | + // Setup possible parts |
|
181 | + $templates = array(); |
|
182 | + if ( isset( $name ) ) |
|
183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
184 | + $templates[] = $slug . '.php'; |
|
185 | 185 | |
186 | - // Allow template parts to be filtered |
|
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
186 | + // Allow template parts to be filtered |
|
187 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
188 | 188 | |
189 | - // Return the part that is found |
|
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
189 | + // Return the part that is found |
|
190 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
194 | - // No file found yet |
|
195 | - $located = false; |
|
194 | + // No file found yet |
|
195 | + $located = false; |
|
196 | 196 | |
197 | - // Try to find a template file |
|
198 | - foreach ( (array)$template_names as $template_name ) { |
|
197 | + // Try to find a template file |
|
198 | + foreach ( (array)$template_names as $template_name ) { |
|
199 | 199 | |
200 | - // Continue if template is empty |
|
201 | - if ( empty( $template_name ) ) |
|
202 | - continue; |
|
200 | + // Continue if template is empty |
|
201 | + if ( empty( $template_name ) ) |
|
202 | + continue; |
|
203 | 203 | |
204 | - // Trim off any slashes from the template name |
|
205 | - $template_name = ltrim( $template_name, '/' ); |
|
204 | + // Trim off any slashes from the template name |
|
205 | + $template_name = ltrim( $template_name, '/' ); |
|
206 | 206 | |
207 | - // try locating this template file by looping through the template paths |
|
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
207 | + // try locating this template file by looping through the template paths |
|
208 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
211 | - $located = $template_path . $template_name; |
|
212 | - break; |
|
213 | - } |
|
214 | - } |
|
210 | + if( file_exists( $template_path . $template_name ) ) { |
|
211 | + $located = $template_path . $template_name; |
|
212 | + break; |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
217 | - break; |
|
218 | - } |
|
219 | - } |
|
216 | + if( !empty( $located ) ) { |
|
217 | + break; |
|
218 | + } |
|
219 | + } |
|
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | + load_template( $located, $require_once ); |
|
223 | 223 | |
224 | - return $located; |
|
224 | + return $located; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | function wpinv_get_theme_template_paths() { |
228 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
228 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
229 | 229 | |
230 | - $file_paths = array( |
|
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
233 | - 100 => wpinv_get_templates_dir() |
|
234 | - ); |
|
230 | + $file_paths = array( |
|
231 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
233 | + 100 => wpinv_get_templates_dir() |
|
234 | + ); |
|
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
237 | 237 | |
238 | - // sort the file paths based on priority |
|
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
238 | + // sort the file paths based on priority |
|
239 | + ksort( $file_paths, SORT_NUMERIC ); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map( 'trailingslashit', $file_paths ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | - $pages = array(); |
|
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
246 | + $pages = array(); |
|
247 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | - return; |
|
254 | - } |
|
252 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
253 | + return; |
|
254 | + } |
|
255 | 255 | |
256 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
256 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
257 | 257 | } |
258 | 258 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
259 | 259 | |
260 | 260 | function wpinv_add_body_classes( $class ) { |
261 | - $classes = (array)$class; |
|
261 | + $classes = (array)$class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
264 | - $classes[] = 'wpinv-checkout'; |
|
265 | - $classes[] = 'wpinv-page'; |
|
266 | - } |
|
263 | + if( wpinv_is_checkout() ) { |
|
264 | + $classes[] = 'wpinv-checkout'; |
|
265 | + $classes[] = 'wpinv-page'; |
|
266 | + } |
|
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
269 | - $classes[] = 'wpinv-success'; |
|
270 | - $classes[] = 'wpinv-page'; |
|
271 | - } |
|
268 | + if( wpinv_is_success_page() ) { |
|
269 | + $classes[] = 'wpinv-success'; |
|
270 | + $classes[] = 'wpinv-page'; |
|
271 | + } |
|
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
274 | - $classes[] = 'wpinv-failed-transaction'; |
|
275 | - $classes[] = 'wpinv-page'; |
|
276 | - } |
|
273 | + if( wpinv_is_failed_transaction_page() ) { |
|
274 | + $classes[] = 'wpinv-failed-transaction'; |
|
275 | + $classes[] = 'wpinv-page'; |
|
276 | + } |
|
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
279 | - $classes[] = 'wpinv-history'; |
|
280 | - $classes[] = 'wpinv-page'; |
|
281 | - } |
|
278 | + if( wpinv_is_invoice_history_page() ) { |
|
279 | + $classes[] = 'wpinv-history'; |
|
280 | + $classes[] = 'wpinv-page'; |
|
281 | + } |
|
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
284 | - $classes[] = 'wpinv-subscription'; |
|
285 | - $classes[] = 'wpinv-page'; |
|
286 | - } |
|
283 | + if( wpinv_is_subscriptions_history_page() ) { |
|
284 | + $classes[] = 'wpinv-subscription'; |
|
285 | + $classes[] = 'wpinv-page'; |
|
286 | + } |
|
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
289 | - $classes[] = 'wpinv-test-mode'; |
|
290 | - $classes[] = 'wpinv-page'; |
|
291 | - } |
|
288 | + if( wpinv_is_test_mode() ) { |
|
289 | + $classes[] = 'wpinv-test-mode'; |
|
290 | + $classes[] = 'wpinv-page'; |
|
291 | + } |
|
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique( $classes ); |
|
294 | 294 | } |
295 | 295 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
296 | 296 | |
@@ -992,21 +992,21 @@ discard block |
||
992 | 992 | |
993 | 993 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
994 | 994 | |
995 | - // Remove unavailable tags. |
|
995 | + // Remove unavailable tags. |
|
996 | 996 | $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
997 | 997 | |
998 | 998 | // Clean up white space. |
999 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
999 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
1000 | 1000 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
1001 | 1001 | |
1002 | 1002 | // Break newlines apart and remove empty lines/trim commas and white space. |
1003 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
1003 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
1004 | 1004 | |
1005 | 1005 | // Add html breaks. |
1006 | - $formatted_address = implode( $separator, $formatted_address ); |
|
1006 | + $formatted_address = implode( $separator, $formatted_address ); |
|
1007 | 1007 | |
1008 | - // We're done! |
|
1009 | - return $formatted_address; |
|
1008 | + // We're done! |
|
1009 | + return $formatted_address; |
|
1010 | 1010 | |
1011 | 1011 | } |
1012 | 1012 | |
@@ -1208,7 +1208,7 @@ discard block |
||
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | function wpinv_empty_cart_message() { |
1211 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1211 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | /** |
@@ -1498,10 +1498,10 @@ discard block |
||
1498 | 1498 | |
1499 | 1499 | if ( 0 == count( $form->get_items() ) ) { |
1500 | 1500 | echo aui()->alert( |
1501 | - array( |
|
1502 | - 'type' => 'warning', |
|
1503 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1504 | - ) |
|
1501 | + array( |
|
1502 | + 'type' => 'warning', |
|
1503 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
1504 | + ) |
|
1505 | 1505 | ); |
1506 | 1506 | return; |
1507 | 1507 | } |
@@ -1517,21 +1517,21 @@ discard block |
||
1517 | 1517 | $invoice = wpinv_get_invoice( $invoice_id ); |
1518 | 1518 | |
1519 | 1519 | if ( empty( $invoice ) ) { |
1520 | - echo aui()->alert( |
|
1521 | - array( |
|
1522 | - 'type' => 'warning', |
|
1523 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1524 | - ) |
|
1520 | + echo aui()->alert( |
|
1521 | + array( |
|
1522 | + 'type' => 'warning', |
|
1523 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1524 | + ) |
|
1525 | 1525 | ); |
1526 | 1526 | return; |
1527 | 1527 | } |
1528 | 1528 | |
1529 | 1529 | if ( $invoice->is_paid() ) { |
1530 | - echo aui()->alert( |
|
1531 | - array( |
|
1532 | - 'type' => 'warning', |
|
1533 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1534 | - ) |
|
1530 | + echo aui()->alert( |
|
1531 | + array( |
|
1532 | + 'type' => 'warning', |
|
1533 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1534 | + ) |
|
1535 | 1535 | ); |
1536 | 1536 | return; |
1537 | 1537 | } |
@@ -1594,7 +1594,7 @@ discard block |
||
1594 | 1594 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; |
1595 | 1595 | } |
1596 | 1596 | |
1597 | - if ( ! empty( $items ) ) { |
|
1597 | + if ( ! empty( $items ) ) { |
|
1598 | 1598 | $items = esc_attr( $items ); |
1599 | 1599 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; |
1600 | 1600 | } |
@@ -14,70 +14,70 @@ discard block |
||
14 | 14 | class WPInv_Ajax { |
15 | 15 | |
16 | 16 | /** |
17 | - * Hook in ajax handlers. |
|
18 | - */ |
|
19 | - public static function init() { |
|
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | - self::add_ajax_events(); |
|
17 | + * Hook in ajax handlers. |
|
18 | + */ |
|
19 | + public static function init() { |
|
20 | + add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | + add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | + self::add_ajax_events(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Set GetPaid AJAX constant and headers. |
|
27 | - */ |
|
28 | - public static function define_ajax() { |
|
29 | - |
|
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | - } |
|
36 | - $GLOBALS['wpdb']->hide_errors(); |
|
37 | - } |
|
26 | + * Set GetPaid AJAX constant and headers. |
|
27 | + */ |
|
28 | + public static function define_ajax() { |
|
29 | + |
|
30 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | + getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | + getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | + if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | + } |
|
36 | + $GLOBALS['wpdb']->hide_errors(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Send headers for GetPaid Ajax Requests. |
|
43 | - * |
|
44 | - * @since 1.0.18 |
|
45 | - */ |
|
46 | - private static function wpinv_ajax_headers() { |
|
47 | - if ( ! headers_sent() ) { |
|
48 | - send_origin_headers(); |
|
49 | - send_nosniff_header(); |
|
50 | - nocache_headers(); |
|
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
54 | - } |
|
42 | + * Send headers for GetPaid Ajax Requests. |
|
43 | + * |
|
44 | + * @since 1.0.18 |
|
45 | + */ |
|
46 | + private static function wpinv_ajax_headers() { |
|
47 | + if ( ! headers_sent() ) { |
|
48 | + send_origin_headers(); |
|
49 | + send_nosniff_header(); |
|
50 | + nocache_headers(); |
|
51 | + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | + header( 'X-Robots-Tag: noindex' ); |
|
53 | + status_header( 200 ); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * Check for GetPaid Ajax request and fire action. |
|
59 | - */ |
|
60 | - public static function do_wpinv_ajax() { |
|
61 | - global $wp_query; |
|
58 | + * Check for GetPaid Ajax request and fire action. |
|
59 | + */ |
|
60 | + public static function do_wpinv_ajax() { |
|
61 | + global $wp_query; |
|
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | - } |
|
63 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | + $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get( 'wpinv-ajax' ); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
70 | - self::wpinv_ajax_headers(); |
|
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
73 | - wp_die(); |
|
74 | - } |
|
69 | + if ( $action ) { |
|
70 | + self::wpinv_ajax_headers(); |
|
71 | + $action = sanitize_text_field( $action ); |
|
72 | + do_action( 'wpinv_ajax_' . $action ); |
|
73 | + wp_die(); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Hook in ajax methods. |
|
80 | - */ |
|
79 | + * Hook in ajax methods. |
|
80 | + */ |
|
81 | 81 | public static function add_ajax_events() { |
82 | 82 | |
83 | 83 | // array( 'event' => is_frontend ) |
@@ -260,24 +260,24 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | // Is the request set up correctly? |
263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
264 | - echo aui()->alert( |
|
265 | - array( |
|
266 | - 'type' => 'warning', |
|
267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | - ) |
|
263 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
264 | + echo aui()->alert( |
|
265 | + array( |
|
266 | + 'type' => 'warning', |
|
267 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
268 | + ) |
|
269 | 269 | ); |
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Payment form or button? |
274 | - if ( ! empty( $_GET['form'] ) ) { |
|
274 | + if ( ! empty( $_GET['form'] ) ) { |
|
275 | 275 | getpaid_display_payment_form( $_GET['form'] ); |
276 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
277 | - getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
276 | + } else if( ! empty( $_GET['invoice'] ) ) { |
|
277 | + getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
278 | 278 | } else { |
279 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
280 | - getpaid_display_item_payment_form( $items ); |
|
279 | + $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
280 | + getpaid_display_item_payment_form( $items ); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | exit; |
@@ -14,420 +14,420 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * Tax instance. |
|
40 | - * |
|
41 | - * @var WPInv_EUVat |
|
42 | - */ |
|
43 | - public $tax; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array An array of payment gateways. |
|
47 | - */ |
|
48 | - public $gateways; |
|
49 | - |
|
50 | - /** |
|
51 | - * Class constructor. |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - $this->define_constants(); |
|
55 | - $this->includes(); |
|
56 | - $this->init_hooks(); |
|
57 | - $this->set_properties(); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets a custom data property. |
|
62 | - * |
|
63 | - * @param string $prop The prop to set. |
|
64 | - * @param mixed $value The value to retrieve. |
|
65 | - */ |
|
66 | - public function set( $prop, $value ) { |
|
67 | - $this->data[ $prop ] = $value; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Gets a custom data property. |
|
72 | - * |
|
73 | - * @param string $prop The prop to set. |
|
74 | - * @return mixed The value. |
|
75 | - */ |
|
76 | - public function get( $prop ) { |
|
77 | - |
|
78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
79 | - return $this->data[ $prop ]; |
|
80 | - } |
|
81 | - |
|
82 | - return null; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Define class properties. |
|
87 | - */ |
|
88 | - public function set_properties() { |
|
89 | - |
|
90 | - // Sessions. |
|
91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | - $this->tax = new WPInv_EUVat(); |
|
94 | - $this->tax->init(); |
|
95 | - $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
96 | - |
|
97 | - // Init other objects. |
|
98 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | - $this->set( 'notes', new WPInv_Notes() ); |
|
101 | - $this->set( 'api', new WPInv_API() ); |
|
102 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | - $this->set( 'template', new GetPaid_Template() ); |
|
104 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
110 | - |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Define plugin constants. |
|
115 | - */ |
|
116 | - public function define_constants() { |
|
117 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
119 | - $this->version = WPINV_VERSION; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Hook into actions and filters. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - */ |
|
127 | - protected function init_hooks() { |
|
128 | - /* Internationalize the text strings used. */ |
|
129 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
130 | - |
|
131 | - // Init the plugin after WordPress inits. |
|
132 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | - add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
134 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
135 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
136 | - |
|
137 | - if ( class_exists( 'BuddyPress' ) ) { |
|
138 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
139 | - } |
|
140 | - |
|
141 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
146 | - |
|
147 | - // Fires after registering actions. |
|
148 | - do_action( 'wpinv_actions', $this ); |
|
149 | - do_action( 'getpaid_actions', $this ); |
|
150 | - |
|
151 | - } |
|
152 | - |
|
153 | - public function plugins_loaded() { |
|
154 | - /* Internationalize the text strings used. */ |
|
155 | - $this->load_textdomain(); |
|
156 | - |
|
157 | - do_action( 'wpinv_loaded' ); |
|
158 | - |
|
159 | - // Fix oxygen page builder conflict |
|
160 | - if ( function_exists( 'ct_css_output' ) ) { |
|
161 | - wpinv_oxygen_fix_conflict(); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Load the translation of the plugin. |
|
167 | - * |
|
168 | - * @since 1.0 |
|
169 | - */ |
|
170 | - public function load_textdomain( $locale = NULL ) { |
|
171 | - if ( empty( $locale ) ) { |
|
172 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
173 | - } |
|
174 | - |
|
175 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | - |
|
177 | - unload_textdomain( 'invoicing' ); |
|
178 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
180 | - |
|
181 | - /** |
|
182 | - * Define language constants. |
|
183 | - */ |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Include required core files used in admin and on the frontend. |
|
189 | - */ |
|
190 | - public function includes() { |
|
191 | - |
|
192 | - // Start with the settings. |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
194 | - |
|
195 | - // Packages/libraries. |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
198 | - |
|
199 | - // Load functions. |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
215 | - |
|
216 | - // Register autoloader. |
|
217 | - try { |
|
218 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | - } catch ( Exception $e ) { |
|
220 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
221 | - } |
|
222 | - |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
244 | - |
|
245 | - /** |
|
246 | - * Load the tax class. |
|
247 | - */ |
|
248 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
250 | - } |
|
251 | - |
|
252 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
253 | - GetPaid_Post_Types_Admin::init(); |
|
254 | - |
|
255 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
263 | - // load the user class only on the users.php page |
|
264 | - global $pagenow; |
|
265 | - if($pagenow=='users.php'){ |
|
266 | - new WPInv_Admin_Users(); |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - // Register cli commands |
|
271 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
274 | - } |
|
275 | - |
|
276 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Class autoloader |
|
281 | - * |
|
282 | - * @param string $class_name The name of the class to load. |
|
283 | - * @access public |
|
284 | - * @since 1.0.19 |
|
285 | - * @return void |
|
286 | - */ |
|
287 | - public function autoload( $class_name ) { |
|
288 | - |
|
289 | - // Normalize the class name... |
|
290 | - $class_name = strtolower( $class_name ); |
|
291 | - |
|
292 | - // ... and make sure it is our class. |
|
293 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
294 | - return; |
|
295 | - } |
|
296 | - |
|
297 | - // Next, prepare the file name from the class. |
|
298 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
299 | - |
|
300 | - // Base path of the classes. |
|
301 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
302 | - |
|
303 | - // And an array of possible locations in order of importance. |
|
304 | - $locations = array( |
|
305 | - "$plugin_path/includes", |
|
306 | - "$plugin_path/includes/data-stores", |
|
307 | - "$plugin_path/includes/gateways", |
|
308 | - "$plugin_path/includes/payments", |
|
309 | - "$plugin_path/includes/api", |
|
310 | - "$plugin_path/includes/admin", |
|
311 | - "$plugin_path/includes/admin/meta-boxes", |
|
312 | - ); |
|
313 | - |
|
314 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
315 | - |
|
316 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
317 | - include trailingslashit( $location ) . $file_name; |
|
318 | - break; |
|
319 | - } |
|
320 | - |
|
321 | - } |
|
322 | - |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Inits hooks etc. |
|
327 | - */ |
|
328 | - public function init() { |
|
329 | - |
|
330 | - // Fires before getpaid inits. |
|
331 | - do_action( 'before_getpaid_init', $this ); |
|
332 | - |
|
333 | - // Load default gateways. |
|
334 | - $gateways = apply_filters( |
|
335 | - 'getpaid_default_gateways', |
|
336 | - array( |
|
337 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
338 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
339 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
340 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
341 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
342 | - ) |
|
343 | - ); |
|
344 | - |
|
345 | - foreach ( $gateways as $id => $class ) { |
|
346 | - $this->gateways[ $id ] = new $class(); |
|
347 | - } |
|
348 | - |
|
349 | - // Fires after getpaid inits. |
|
350 | - do_action( 'getpaid_init', $this ); |
|
351 | - |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Checks if this is an IPN request and processes it. |
|
356 | - */ |
|
357 | - public function maybe_process_ipn() { |
|
358 | - |
|
359 | - // Ensure that this is an IPN request. |
|
360 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
361 | - return; |
|
362 | - } |
|
363 | - |
|
364 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
365 | - |
|
366 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
367 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
368 | - exit; |
|
369 | - |
|
370 | - } |
|
371 | - |
|
372 | - public function enqueue_scripts() { |
|
373 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
374 | - |
|
375 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
376 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
377 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
378 | - |
|
379 | - // Register scripts |
|
380 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
381 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
382 | - |
|
383 | - $localize = array(); |
|
384 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
385 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
386 | - $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
387 | - $localize['currency_pos'] = wpinv_currency_position(); |
|
388 | - $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
389 | - $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
390 | - $localize['decimals'] = wpinv_decimals(); |
|
391 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
392 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
393 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
394 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
395 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
396 | - |
|
397 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
398 | - |
|
399 | - wp_enqueue_script( 'jquery-blockui' ); |
|
400 | - $autofill_api = wpinv_get_option('address_autofill_api'); |
|
401 | - $autofill_active = wpinv_get_option('address_autofill_active'); |
|
402 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
403 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
404 | - wp_dequeue_script( 'google-maps-api' ); |
|
405 | - } |
|
406 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
407 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
408 | - } |
|
409 | - |
|
410 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
411 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
412 | - |
|
413 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
414 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
415 | - |
|
416 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
417 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
418 | - } |
|
419 | - |
|
420 | - public function wpinv_actions() { |
|
421 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
422 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * Tax instance. |
|
40 | + * |
|
41 | + * @var WPInv_EUVat |
|
42 | + */ |
|
43 | + public $tax; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array An array of payment gateways. |
|
47 | + */ |
|
48 | + public $gateways; |
|
49 | + |
|
50 | + /** |
|
51 | + * Class constructor. |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + $this->define_constants(); |
|
55 | + $this->includes(); |
|
56 | + $this->init_hooks(); |
|
57 | + $this->set_properties(); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets a custom data property. |
|
62 | + * |
|
63 | + * @param string $prop The prop to set. |
|
64 | + * @param mixed $value The value to retrieve. |
|
65 | + */ |
|
66 | + public function set( $prop, $value ) { |
|
67 | + $this->data[ $prop ] = $value; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Gets a custom data property. |
|
72 | + * |
|
73 | + * @param string $prop The prop to set. |
|
74 | + * @return mixed The value. |
|
75 | + */ |
|
76 | + public function get( $prop ) { |
|
77 | + |
|
78 | + if ( isset( $this->data[ $prop ] ) ) { |
|
79 | + return $this->data[ $prop ]; |
|
80 | + } |
|
81 | + |
|
82 | + return null; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Define class properties. |
|
87 | + */ |
|
88 | + public function set_properties() { |
|
89 | + |
|
90 | + // Sessions. |
|
91 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | + $this->tax = new WPInv_EUVat(); |
|
94 | + $this->tax->init(); |
|
95 | + $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
96 | + |
|
97 | + // Init other objects. |
|
98 | + $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | + $this->set( 'notes', new WPInv_Notes() ); |
|
101 | + $this->set( 'api', new WPInv_API() ); |
|
102 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | + $this->set( 'template', new GetPaid_Template() ); |
|
104 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
110 | + |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Define plugin constants. |
|
115 | + */ |
|
116 | + public function define_constants() { |
|
117 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
119 | + $this->version = WPINV_VERSION; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Hook into actions and filters. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + */ |
|
127 | + protected function init_hooks() { |
|
128 | + /* Internationalize the text strings used. */ |
|
129 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
130 | + |
|
131 | + // Init the plugin after WordPress inits. |
|
132 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | + add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 ); |
|
134 | + add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
135 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
136 | + |
|
137 | + if ( class_exists( 'BuddyPress' ) ) { |
|
138 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
139 | + } |
|
140 | + |
|
141 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
146 | + |
|
147 | + // Fires after registering actions. |
|
148 | + do_action( 'wpinv_actions', $this ); |
|
149 | + do_action( 'getpaid_actions', $this ); |
|
150 | + |
|
151 | + } |
|
152 | + |
|
153 | + public function plugins_loaded() { |
|
154 | + /* Internationalize the text strings used. */ |
|
155 | + $this->load_textdomain(); |
|
156 | + |
|
157 | + do_action( 'wpinv_loaded' ); |
|
158 | + |
|
159 | + // Fix oxygen page builder conflict |
|
160 | + if ( function_exists( 'ct_css_output' ) ) { |
|
161 | + wpinv_oxygen_fix_conflict(); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Load the translation of the plugin. |
|
167 | + * |
|
168 | + * @since 1.0 |
|
169 | + */ |
|
170 | + public function load_textdomain( $locale = NULL ) { |
|
171 | + if ( empty( $locale ) ) { |
|
172 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
173 | + } |
|
174 | + |
|
175 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | + |
|
177 | + unload_textdomain( 'invoicing' ); |
|
178 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
180 | + |
|
181 | + /** |
|
182 | + * Define language constants. |
|
183 | + */ |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Include required core files used in admin and on the frontend. |
|
189 | + */ |
|
190 | + public function includes() { |
|
191 | + |
|
192 | + // Start with the settings. |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
194 | + |
|
195 | + // Packages/libraries. |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
198 | + |
|
199 | + // Load functions. |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
215 | + |
|
216 | + // Register autoloader. |
|
217 | + try { |
|
218 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | + } catch ( Exception $e ) { |
|
220 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
221 | + } |
|
222 | + |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
244 | + |
|
245 | + /** |
|
246 | + * Load the tax class. |
|
247 | + */ |
|
248 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
250 | + } |
|
251 | + |
|
252 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
253 | + GetPaid_Post_Types_Admin::init(); |
|
254 | + |
|
255 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
263 | + // load the user class only on the users.php page |
|
264 | + global $pagenow; |
|
265 | + if($pagenow=='users.php'){ |
|
266 | + new WPInv_Admin_Users(); |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + // Register cli commands |
|
271 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
274 | + } |
|
275 | + |
|
276 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Class autoloader |
|
281 | + * |
|
282 | + * @param string $class_name The name of the class to load. |
|
283 | + * @access public |
|
284 | + * @since 1.0.19 |
|
285 | + * @return void |
|
286 | + */ |
|
287 | + public function autoload( $class_name ) { |
|
288 | + |
|
289 | + // Normalize the class name... |
|
290 | + $class_name = strtolower( $class_name ); |
|
291 | + |
|
292 | + // ... and make sure it is our class. |
|
293 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
294 | + return; |
|
295 | + } |
|
296 | + |
|
297 | + // Next, prepare the file name from the class. |
|
298 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
299 | + |
|
300 | + // Base path of the classes. |
|
301 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
302 | + |
|
303 | + // And an array of possible locations in order of importance. |
|
304 | + $locations = array( |
|
305 | + "$plugin_path/includes", |
|
306 | + "$plugin_path/includes/data-stores", |
|
307 | + "$plugin_path/includes/gateways", |
|
308 | + "$plugin_path/includes/payments", |
|
309 | + "$plugin_path/includes/api", |
|
310 | + "$plugin_path/includes/admin", |
|
311 | + "$plugin_path/includes/admin/meta-boxes", |
|
312 | + ); |
|
313 | + |
|
314 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
315 | + |
|
316 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
317 | + include trailingslashit( $location ) . $file_name; |
|
318 | + break; |
|
319 | + } |
|
320 | + |
|
321 | + } |
|
322 | + |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Inits hooks etc. |
|
327 | + */ |
|
328 | + public function init() { |
|
329 | + |
|
330 | + // Fires before getpaid inits. |
|
331 | + do_action( 'before_getpaid_init', $this ); |
|
332 | + |
|
333 | + // Load default gateways. |
|
334 | + $gateways = apply_filters( |
|
335 | + 'getpaid_default_gateways', |
|
336 | + array( |
|
337 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
338 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
339 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
340 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
341 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
342 | + ) |
|
343 | + ); |
|
344 | + |
|
345 | + foreach ( $gateways as $id => $class ) { |
|
346 | + $this->gateways[ $id ] = new $class(); |
|
347 | + } |
|
348 | + |
|
349 | + // Fires after getpaid inits. |
|
350 | + do_action( 'getpaid_init', $this ); |
|
351 | + |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Checks if this is an IPN request and processes it. |
|
356 | + */ |
|
357 | + public function maybe_process_ipn() { |
|
358 | + |
|
359 | + // Ensure that this is an IPN request. |
|
360 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
361 | + return; |
|
362 | + } |
|
363 | + |
|
364 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
365 | + |
|
366 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
367 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
368 | + exit; |
|
369 | + |
|
370 | + } |
|
371 | + |
|
372 | + public function enqueue_scripts() { |
|
373 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
374 | + |
|
375 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
376 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
377 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
378 | + |
|
379 | + // Register scripts |
|
380 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
381 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
382 | + |
|
383 | + $localize = array(); |
|
384 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
385 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
386 | + $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
387 | + $localize['currency_pos'] = wpinv_currency_position(); |
|
388 | + $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
389 | + $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
390 | + $localize['decimals'] = wpinv_decimals(); |
|
391 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
392 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
393 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
394 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
395 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
396 | + |
|
397 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
398 | + |
|
399 | + wp_enqueue_script( 'jquery-blockui' ); |
|
400 | + $autofill_api = wpinv_get_option('address_autofill_api'); |
|
401 | + $autofill_active = wpinv_get_option('address_autofill_active'); |
|
402 | + if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
403 | + if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
404 | + wp_dequeue_script( 'google-maps-api' ); |
|
405 | + } |
|
406 | + wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
407 | + wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
408 | + } |
|
409 | + |
|
410 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
411 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
412 | + |
|
413 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
414 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
415 | + |
|
416 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
417 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
418 | + } |
|
419 | + |
|
420 | + public function wpinv_actions() { |
|
421 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
422 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | 427 | * Fires an action after verifying that a user can fire them. |
428 | - * |
|
429 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
430 | - * current user owns the invoice/subscription. |
|
428 | + * |
|
429 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
430 | + * current user owns the invoice/subscription. |
|
431 | 431 | */ |
432 | 432 | public function maybe_do_authenticated_action() { |
433 | 433 | |
@@ -438,82 +438,82 @@ discard block |
||
438 | 438 | |
439 | 439 | } |
440 | 440 | |
441 | - public function pre_get_posts( $wp_query ) { |
|
442 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
443 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
444 | - } |
|
445 | - |
|
446 | - return $wp_query; |
|
447 | - } |
|
448 | - |
|
449 | - public function bp_invoicing_init() { |
|
450 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Register widgets |
|
455 | - * |
|
456 | - */ |
|
457 | - public function register_widgets() { |
|
458 | - $widgets = apply_filters( |
|
459 | - 'getpaid_widget_classes', |
|
460 | - array( |
|
461 | - 'WPInv_Checkout_Widget', |
|
462 | - 'WPInv_History_Widget', |
|
463 | - 'WPInv_Receipt_Widget', |
|
464 | - 'WPInv_Subscriptions_Widget', |
|
465 | - 'WPInv_Buy_Item_Widget', |
|
466 | - 'WPInv_Messages_Widget', |
|
467 | - 'WPInv_GetPaid_Widget' |
|
468 | - ) |
|
469 | - ); |
|
470 | - |
|
471 | - foreach ( $widgets as $widget ) { |
|
472 | - register_widget( $widget ); |
|
473 | - } |
|
441 | + public function pre_get_posts( $wp_query ) { |
|
442 | + if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
443 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
444 | + } |
|
445 | + |
|
446 | + return $wp_query; |
|
447 | + } |
|
448 | + |
|
449 | + public function bp_invoicing_init() { |
|
450 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Register widgets |
|
455 | + * |
|
456 | + */ |
|
457 | + public function register_widgets() { |
|
458 | + $widgets = apply_filters( |
|
459 | + 'getpaid_widget_classes', |
|
460 | + array( |
|
461 | + 'WPInv_Checkout_Widget', |
|
462 | + 'WPInv_History_Widget', |
|
463 | + 'WPInv_Receipt_Widget', |
|
464 | + 'WPInv_Subscriptions_Widget', |
|
465 | + 'WPInv_Buy_Item_Widget', |
|
466 | + 'WPInv_Messages_Widget', |
|
467 | + 'WPInv_GetPaid_Widget' |
|
468 | + ) |
|
469 | + ); |
|
470 | + |
|
471 | + foreach ( $widgets as $widget ) { |
|
472 | + register_widget( $widget ); |
|
473 | + } |
|
474 | 474 | |
475 | - } |
|
475 | + } |
|
476 | 476 | |
477 | - /** |
|
478 | - * Remove our pages from yoast sitemaps. |
|
479 | - * |
|
480 | - * @since 1.0.19 |
|
481 | - * @param int[] $excluded_posts_ids |
|
482 | - */ |
|
483 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
477 | + /** |
|
478 | + * Remove our pages from yoast sitemaps. |
|
479 | + * |
|
480 | + * @since 1.0.19 |
|
481 | + * @param int[] $excluded_posts_ids |
|
482 | + */ |
|
483 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
484 | 484 | |
485 | - // Ensure that we have an array. |
|
486 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
487 | - $excluded_posts_ids = array(); |
|
488 | - } |
|
485 | + // Ensure that we have an array. |
|
486 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
487 | + $excluded_posts_ids = array(); |
|
488 | + } |
|
489 | 489 | |
490 | - // Prepare our pages. |
|
491 | - $our_pages = array(); |
|
490 | + // Prepare our pages. |
|
491 | + $our_pages = array(); |
|
492 | 492 | |
493 | - // Checkout page. |
|
494 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
493 | + // Checkout page. |
|
494 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
495 | 495 | |
496 | - // Success page. |
|
497 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
496 | + // Success page. |
|
497 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
498 | 498 | |
499 | - // Failure page. |
|
500 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
499 | + // Failure page. |
|
500 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
501 | 501 | |
502 | - // History page. |
|
503 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
502 | + // History page. |
|
503 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
504 | 504 | |
505 | - // Subscriptions page. |
|
506 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
505 | + // Subscriptions page. |
|
506 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
507 | 507 | |
508 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
508 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
509 | 509 | |
510 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
511 | - return array_unique( $excluded_posts_ids ); |
|
510 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
511 | + return array_unique( $excluded_posts_ids ); |
|
512 | 512 | |
513 | - } |
|
513 | + } |
|
514 | 514 | |
515 | - public function wp_footer() { |
|
516 | - echo ' |
|
515 | + public function wp_footer() { |
|
516 | + echo ' |
|
517 | 517 | <div class="bsui"> |
518 | 518 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
519 | 519 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -524,6 +524,6 @@ discard block |
||
524 | 524 | </div> |
525 | 525 | </div> |
526 | 526 | '; |
527 | - } |
|
527 | + } |
|
528 | 528 | |
529 | 529 | } |
@@ -13,128 +13,128 @@ |
||
13 | 13 | class GetPaid_Payment_Forms { |
14 | 14 | |
15 | 15 | /** |
16 | - * Class constructor |
|
17 | - * |
|
18 | - */ |
|
19 | - public function __construct() { |
|
20 | - |
|
21 | - // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | - |
|
25 | - // Sync form amount whenever invoice statuses change. |
|
26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | - |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Increments a form's revenue whenever there is a payment. |
|
34 | - * |
|
35 | - * @param WPInv_Invoice $invoice |
|
36 | - */ |
|
37 | - public function increment_form_revenue( $invoice ) { |
|
38 | - |
|
39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | - if ( $form->get_id() ) { |
|
41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | - $form->save(); |
|
43 | - } |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Decreases form revenue whenever invoice payment changes. |
|
49 | - * |
|
50 | - * @param WPInv_Invoice $invoice |
|
51 | - */ |
|
52 | - public function decrease_form_revenue( $invoice ) { |
|
53 | - |
|
54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | - if ( $form->get_id() ) { |
|
56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | - $form->save(); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Updates a form's failed amount. |
|
64 | - * |
|
65 | - * @param WPInv_Invoice $invoice |
|
66 | - * @param string $from |
|
67 | - * @param string $to |
|
68 | - */ |
|
69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | - |
|
71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | - if ( $form->get_id() ) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - if ( 'wpi-failed' == $from ) { |
|
77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | - $form->save(); |
|
79 | - } |
|
80 | - |
|
81 | - if ( 'wpi-failed' == $to ) { |
|
82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | - $form->save(); |
|
84 | - } |
|
85 | - |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Updates a form's refunded amount. |
|
90 | - * |
|
91 | - * @param WPInv_Invoice $invoice |
|
92 | - * @param string $from |
|
93 | - * @param string $to |
|
94 | - */ |
|
95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | - |
|
97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | - if ( $form->get_id() ) { |
|
99 | - return; |
|
100 | - } |
|
101 | - |
|
102 | - if ( 'wpi-refunded' == $from ) { |
|
103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | - $form->save(); |
|
105 | - } |
|
106 | - |
|
107 | - if ( 'wpi-refunded' == $to ) { |
|
108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | - $form->save(); |
|
110 | - } |
|
111 | - |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Updates a form's cancelled amount. |
|
116 | - * |
|
117 | - * @param WPInv_Invoice $invoice |
|
118 | - * @param string $from |
|
119 | - * @param string $to |
|
120 | - */ |
|
121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | - |
|
123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | - if ( $form->get_id() ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - if ( 'wpi-cancelled' == $from ) { |
|
129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | - $form->save(); |
|
131 | - } |
|
132 | - |
|
133 | - if ( 'wpi-cancelled' == $to ) { |
|
134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | - $form->save(); |
|
136 | - } |
|
137 | - |
|
138 | - } |
|
16 | + * Class constructor |
|
17 | + * |
|
18 | + */ |
|
19 | + public function __construct() { |
|
20 | + |
|
21 | + // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
22 | + add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
23 | + add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
24 | + |
|
25 | + // Sync form amount whenever invoice statuses change. |
|
26 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
27 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
28 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
29 | + |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Increments a form's revenue whenever there is a payment. |
|
34 | + * |
|
35 | + * @param WPInv_Invoice $invoice |
|
36 | + */ |
|
37 | + public function increment_form_revenue( $invoice ) { |
|
38 | + |
|
39 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
40 | + if ( $form->get_id() ) { |
|
41 | + $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
42 | + $form->save(); |
|
43 | + } |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Decreases form revenue whenever invoice payment changes. |
|
49 | + * |
|
50 | + * @param WPInv_Invoice $invoice |
|
51 | + */ |
|
52 | + public function decrease_form_revenue( $invoice ) { |
|
53 | + |
|
54 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
55 | + if ( $form->get_id() ) { |
|
56 | + $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
57 | + $form->save(); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Updates a form's failed amount. |
|
64 | + * |
|
65 | + * @param WPInv_Invoice $invoice |
|
66 | + * @param string $from |
|
67 | + * @param string $to |
|
68 | + */ |
|
69 | + public function update_form_failed_amount( $invoice, $from, $to ) { |
|
70 | + |
|
71 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
72 | + if ( $form->get_id() ) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + if ( 'wpi-failed' == $from ) { |
|
77 | + $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
78 | + $form->save(); |
|
79 | + } |
|
80 | + |
|
81 | + if ( 'wpi-failed' == $to ) { |
|
82 | + $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
83 | + $form->save(); |
|
84 | + } |
|
85 | + |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Updates a form's refunded amount. |
|
90 | + * |
|
91 | + * @param WPInv_Invoice $invoice |
|
92 | + * @param string $from |
|
93 | + * @param string $to |
|
94 | + */ |
|
95 | + public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
96 | + |
|
97 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
98 | + if ( $form->get_id() ) { |
|
99 | + return; |
|
100 | + } |
|
101 | + |
|
102 | + if ( 'wpi-refunded' == $from ) { |
|
103 | + $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
104 | + $form->save(); |
|
105 | + } |
|
106 | + |
|
107 | + if ( 'wpi-refunded' == $to ) { |
|
108 | + $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
109 | + $form->save(); |
|
110 | + } |
|
111 | + |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Updates a form's cancelled amount. |
|
116 | + * |
|
117 | + * @param WPInv_Invoice $invoice |
|
118 | + * @param string $from |
|
119 | + * @param string $to |
|
120 | + */ |
|
121 | + public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
122 | + |
|
123 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
124 | + if ( $form->get_id() ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + if ( 'wpi-cancelled' == $from ) { |
|
129 | + $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
130 | + $form->save(); |
|
131 | + } |
|
132 | + |
|
133 | + if ( 'wpi-cancelled' == $to ) { |
|
134 | + $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
135 | + $form->save(); |
|
136 | + } |
|
137 | + |
|
138 | + } |
|
139 | 139 | |
140 | 140 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; // Exit if accessed directly |
|
10 | + exit; // Exit if accessed directly |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | class GetPaid_Meta_Box_Payment_Form { |
17 | 17 | |
18 | 18 | /** |
19 | - * Output the metabox. |
|
20 | - * |
|
21 | - * @param WP_Post $post |
|
22 | - */ |
|
19 | + * Output the metabox. |
|
20 | + * |
|
21 | + * @param WP_Post $post |
|
22 | + */ |
|
23 | 23 | public static function output( $post ) { |
24 | 24 | ?> |
25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | - * Save meta box data. |
|
90 | - * |
|
91 | - * @param int $post_id |
|
92 | - */ |
|
93 | - public static function save( $post_id ) { |
|
89 | + * Save meta box data. |
|
90 | + * |
|
91 | + * @param int $post_id |
|
92 | + */ |
|
93 | + public static function save( $post_id ) { |
|
94 | 94 | |
95 | 95 | // Prepare the form. |
96 | 96 | $form = new GetPaid_Payment_Form( $post_id ); |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | - * Converts an array fo form items to objects. |
|
125 | - * |
|
126 | - * @param array $items |
|
127 | - */ |
|
128 | - public static function item_to_objects( $items ) { |
|
124 | + * Converts an array fo form items to objects. |
|
125 | + * |
|
126 | + * @param array $items |
|
127 | + */ |
|
128 | + public static function item_to_objects( $items ) { |
|
129 | 129 | |
130 | 130 | $objects = array(); |
131 | 131 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -368,34 +368,34 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
371 | - * Save meta box data. |
|
372 | - * |
|
373 | - * @param int $post_id |
|
374 | - */ |
|
375 | - public static function save( $post_id ) { |
|
371 | + * Save meta box data. |
|
372 | + * |
|
373 | + * @param int $post_id |
|
374 | + */ |
|
375 | + public static function save( $post_id ) { |
|
376 | 376 | |
377 | 377 | // Prepare the discount. |
378 | 378 | $discount = new WPInv_Discount( $post_id ); |
379 | 379 | |
380 | 380 | // Load new data. |
381 | 381 | $discount->set_props( |
382 | - array( |
|
383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
382 | + array( |
|
383 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
384 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
385 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
386 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
387 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
388 | 388 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | - ) |
|
389 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
390 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
391 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
392 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
393 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
394 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
395 | + ) |
|
396 | 396 | ); |
397 | 397 | |
398 | - $discount->save(); |
|
399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | - } |
|
398 | + $discount->save(); |
|
399 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
400 | + } |
|
401 | 401 | } |
@@ -12,108 +12,108 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
14 | 14 | |
15 | - /** |
|
16 | - * The fee validation error. |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $fee_error; |
|
20 | - |
|
21 | - /** |
|
22 | - * Submission fees. |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $fees = array(); |
|
15 | + /** |
|
16 | + * The fee validation error. |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $fee_error; |
|
20 | + |
|
21 | + /** |
|
22 | + * Submission fees. |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $fees = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Process any existing invoice fees. |
|
35 | + if ( $submission->has_invoice() ) { |
|
36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | + } |
|
38 | + |
|
39 | + // Process price fields. |
|
40 | + $data = $submission->get_data(); |
|
41 | + $payment_form = $submission->get_payment_form(); |
|
42 | + |
|
43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
44 | + |
|
45 | + if ( 'price_input' == $element['type'] ) { |
|
46 | + $this->process_price_input( $element, $data ); |
|
47 | + } |
|
48 | + |
|
49 | + if ( 'price_select' == $element['type'] ) { |
|
50 | + $this->process_price_select( $element, $data ); |
|
51 | + } |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Process a price input field. |
|
59 | + * |
|
60 | + * @param array $element |
|
61 | + * @param array $data |
|
62 | + */ |
|
63 | + public function process_price_input( $element, $data ) { |
|
64 | + |
|
65 | + // Abort if not passed. |
|
66 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
71 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
72 | + |
|
73 | + if ( $amount < $minimum ) { |
|
74 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
75 | + } |
|
76 | + |
|
77 | + $this->fees[ $element['label'] ] = array( |
|
78 | + 'name' => $element['label'], |
|
79 | + 'initial_fee' => $amount, |
|
80 | + 'recurring_fee' => 0, |
|
81 | + ); |
|
82 | + |
|
83 | + } |
|
26 | 84 | |
27 | 85 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Process any existing invoice fees. |
|
35 | - if ( $submission->has_invoice() ) { |
|
36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | - } |
|
38 | - |
|
39 | - // Process price fields. |
|
40 | - $data = $submission->get_data(); |
|
41 | - $payment_form = $submission->get_payment_form(); |
|
42 | - |
|
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
44 | - |
|
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data ); |
|
47 | - } |
|
48 | - |
|
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
51 | - } |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Process a price input field. |
|
59 | - * |
|
60 | - * @param array $element |
|
61 | - * @param array $data |
|
62 | - */ |
|
63 | - public function process_price_input( $element, $data ) { |
|
64 | - |
|
65 | - // Abort if not passed. |
|
66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
72 | - |
|
73 | - if ( $amount < $minimum ) { |
|
74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
75 | - } |
|
76 | - |
|
77 | - $this->fees[ $element['label'] ] = array( |
|
78 | - 'name' => $element['label'], |
|
79 | - 'initial_fee' => $amount, |
|
80 | - 'recurring_fee' => 0, |
|
81 | - ); |
|
82 | - |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Process a price select field. |
|
87 | - * |
|
88 | - * @param array $element |
|
89 | - * @param array $data |
|
90 | - */ |
|
91 | - public function process_price_select( $element, $data ) { |
|
92 | - |
|
93 | - // Abort if not passed. |
|
94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
95 | - return; |
|
96 | - } |
|
97 | - |
|
98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
99 | - $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
100 | - $total = 0; |
|
101 | - |
|
102 | - foreach ( $selected as $price ) { |
|
103 | - |
|
104 | - if ( ! isset( $options[ $price ] ) ) { |
|
105 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
106 | - } |
|
107 | - |
|
108 | - $total += (float) wpinv_sanitize_amount( $price ); |
|
109 | - } |
|
110 | - |
|
111 | - $this->fees[ $element['label'] ] = array( |
|
112 | - 'name' => $element['label'], |
|
113 | - 'initial_fee' => $total, |
|
114 | - 'recurring_fee' => 0, |
|
115 | - ); |
|
116 | - |
|
117 | - } |
|
86 | + * Process a price select field. |
|
87 | + * |
|
88 | + * @param array $element |
|
89 | + * @param array $data |
|
90 | + */ |
|
91 | + public function process_price_select( $element, $data ) { |
|
92 | + |
|
93 | + // Abort if not passed. |
|
94 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
95 | + return; |
|
96 | + } |
|
97 | + |
|
98 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
99 | + $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
100 | + $total = 0; |
|
101 | + |
|
102 | + foreach ( $selected as $price ) { |
|
103 | + |
|
104 | + if ( ! isset( $options[ $price ] ) ) { |
|
105 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
106 | + } |
|
107 | + |
|
108 | + $total += (float) wpinv_sanitize_amount( $price ); |
|
109 | + } |
|
110 | + |
|
111 | + $this->fees[ $element['label'] ] = array( |
|
112 | + 'name' => $element['label'], |
|
113 | + 'initial_fee' => $total, |
|
114 | + 'recurring_fee' => 0, |
|
115 | + ); |
|
116 | + |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |