@@ -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,55 +10,55 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form 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 = 'payment_form'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'payment_form'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'payment_form'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Form Data array. This is the core form data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'status' => 'draft', |
|
34 | - 'version' => '', |
|
35 | - 'date_created' => null, |
|
27 | + * Form Data array. This is the core form data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'status' => 'draft', |
|
34 | + 'version' => '', |
|
35 | + 'date_created' => null, |
|
36 | 36 | 'date_modified' => null, |
37 | 37 | 'name' => '', |
38 | 38 | 'author' => 1, |
39 | 39 | 'elements' => null, |
40 | - 'items' => null, |
|
41 | - 'earned' => 0, |
|
42 | - 'refunded' => 0, |
|
43 | - 'cancelled' => 0, |
|
44 | - 'failed' => 0, |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Stores meta in cache for future reads. |
|
49 | - * |
|
50 | - * A group must be set to to enable caching. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $cache_group = 'getpaid_forms'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | - * |
|
59 | - * @var WPInv_Invoice |
|
60 | - */ |
|
61 | - public $invoice = 0; |
|
40 | + 'items' => null, |
|
41 | + 'earned' => 0, |
|
42 | + 'refunded' => 0, |
|
43 | + 'cancelled' => 0, |
|
44 | + 'failed' => 0, |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Stores meta in cache for future reads. |
|
49 | + * |
|
50 | + * A group must be set to to enable caching. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $cache_group = 'getpaid_forms'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | + * |
|
59 | + * @var WPInv_Invoice |
|
60 | + */ |
|
61 | + public $invoice = 0; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
68 | 68 | protected $post = null; |
69 | 69 | |
70 | 70 | /** |
71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | - * |
|
73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | - */ |
|
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | + * |
|
73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | + */ |
|
75 | + public function __construct( $form = 0 ) { |
|
76 | + parent::__construct( $form ); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | + $this->set_id( $form ); |
|
80 | + } elseif ( $form instanceof self ) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
83 | - $this->invoice = $form->invoice; |
|
82 | + $this->set_id( $form->get_id() ); |
|
83 | + $this->invoice = $form->invoice; |
|
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
87 | - } else { |
|
88 | - $this->set_object_read( true ); |
|
89 | - } |
|
85 | + } elseif ( ! empty( $form->ID ) ) { |
|
86 | + $this->set_id( $form->ID ); |
|
87 | + } else { |
|
88 | + $this->set_object_read( true ); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
94 | + if ( $this->get_id() > 0 ) { |
|
95 | 95 | $this->post = get_post( $this->get_id() ); |
96 | - $this->data_store->read( $this ); |
|
96 | + $this->data_store->read( $this ); |
|
97 | 97 | } |
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /* |
102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,349 +114,349 @@ discard block |
||
114 | 114 | */ |
115 | 115 | |
116 | 116 | /** |
117 | - * Get plugin version when the form was created. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * @param string $context View or edit context. |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
117 | + * Get plugin version when the form was created. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * @param string $context View or edit context. |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_version( $context = 'view' ) { |
|
124 | + return $this->get_prop( 'version', $context ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get date when the form was created. |
|
129 | - * |
|
130 | - * @since 1.0.19 |
|
131 | - * @param string $context View or edit context. |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
128 | + * Get date when the form was created. |
|
129 | + * |
|
130 | + * @since 1.0.19 |
|
131 | + * @param string $context View or edit context. |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function get_date_created( $context = 'view' ) { |
|
135 | + return $this->get_prop( 'date_created', $context ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Get GMT date when the form was created. |
|
140 | - * |
|
141 | - * @since 1.0.19 |
|
142 | - * @param string $context View or edit context. |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
139 | + * Get GMT date when the form was created. |
|
140 | + * |
|
141 | + * @since 1.0.19 |
|
142 | + * @param string $context View or edit context. |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
146 | 146 | $date = $this->get_date_created( $context ); |
147 | 147 | |
148 | 148 | if ( $date ) { |
149 | 149 | $date = get_gmt_from_date( $date ); |
150 | 150 | } |
151 | - return $date; |
|
151 | + return $date; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * Get date when the form was last modified. |
|
156 | - * |
|
157 | - * @since 1.0.19 |
|
158 | - * @param string $context View or edit context. |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
155 | + * Get date when the form was last modified. |
|
156 | + * |
|
157 | + * @since 1.0.19 |
|
158 | + * @param string $context View or edit context. |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_date_modified( $context = 'view' ) { |
|
162 | + return $this->get_prop( 'date_modified', $context ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * Get GMT date when the form was last modified. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @param string $context View or edit context. |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
166 | + * Get GMT date when the form was last modified. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @param string $context View or edit context. |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | 173 | $date = $this->get_date_modified( $context ); |
174 | 174 | |
175 | 175 | if ( $date ) { |
176 | 176 | $date = get_gmt_from_date( $date ); |
177 | 177 | } |
178 | - return $date; |
|
178 | + return $date; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get the form name. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
182 | + * Get the form name. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function get_name( $context = 'view' ) { |
|
189 | + return $this->get_prop( 'name', $context ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Alias of self::get_name(). |
|
194 | - * |
|
195 | - * @since 1.0.19 |
|
196 | - * @param string $context View or edit context. |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
201 | - } |
|
193 | + * Alias of self::get_name(). |
|
194 | + * |
|
195 | + * @since 1.0.19 |
|
196 | + * @param string $context View or edit context. |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function get_title( $context = 'view' ) { |
|
200 | + return $this->get_name( $context ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | /** |
204 | - * Get the owner of the form. |
|
205 | - * |
|
206 | - * @since 1.0.19 |
|
207 | - * @param string $context View or edit context. |
|
208 | - * @return int |
|
209 | - */ |
|
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
204 | + * Get the owner of the form. |
|
205 | + * |
|
206 | + * @since 1.0.19 |
|
207 | + * @param string $context View or edit context. |
|
208 | + * @return int |
|
209 | + */ |
|
210 | + public function get_author( $context = 'view' ) { |
|
211 | + return (int) $this->get_prop( 'author', $context ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Get the elements that make up the form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
215 | + * Get the elements that make up the form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + public function get_elements( $context = 'view' ) { |
|
222 | + $elements = $this->get_prop( 'elements', $context ); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - // Ensure that all required elements exist. |
|
229 | - $_elements = array(); |
|
230 | - foreach ( $elements as $element ) { |
|
228 | + // Ensure that all required elements exist. |
|
229 | + $_elements = array(); |
|
230 | + foreach ( $elements as $element ) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
233 | 233 | |
234 | - $_elements[] = array( |
|
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | - 'id' => 'gtscicd', |
|
237 | - 'name' => 'gtscicd', |
|
238 | - 'type' => 'gateway_select', |
|
239 | - 'premade' => true |
|
234 | + $_elements[] = array( |
|
235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | + 'id' => 'gtscicd', |
|
237 | + 'name' => 'gtscicd', |
|
238 | + 'type' => 'gateway_select', |
|
239 | + 'premade' => true |
|
240 | 240 | |
241 | - ); |
|
241 | + ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - $_elements[] = $element; |
|
245 | + $_elements[] = $element; |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | return $_elements; |
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the items sold via the form. |
|
254 | - * |
|
255 | - * @since 1.0.19 |
|
256 | - * @param string $context View or edit context. |
|
257 | - * @param string $return objects or arrays. |
|
258 | - * @return GetPaid_Form_Item[] |
|
259 | - */ |
|
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
262 | - |
|
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the items sold via the form. |
|
254 | + * |
|
255 | + * @since 1.0.19 |
|
256 | + * @param string $context View or edit context. |
|
257 | + * @param string $return objects or arrays. |
|
258 | + * @return GetPaid_Form_Item[] |
|
259 | + */ |
|
260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | + $items = $this->get_prop( 'items', $context ); |
|
262 | + |
|
263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
265 | - } |
|
265 | + } |
|
266 | + |
|
267 | + // Convert the items. |
|
268 | + $prepared = array(); |
|
266 | 269 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
270 | + foreach ( $items as $key => $value ) { |
|
269 | 271 | |
270 | - foreach ( $items as $key => $value ) { |
|
272 | + // Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
271 | 274 | |
272 | - // Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
274 | 278 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
279 | + continue; |
|
278 | 280 | |
279 | - continue; |
|
281 | + } |
|
280 | 282 | |
281 | - } |
|
283 | + // $item_id => $quantity |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
282 | 286 | |
283 | - // $item_id => $quantity |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
287 | + if ( $item->can_purchase() ) { |
|
288 | + $item->set_quantity( $value ); |
|
289 | + $prepared[] = $item; |
|
290 | + } |
|
286 | 291 | |
287 | - if ( $item->can_purchase() ) { |
|
288 | - $item->set_quantity( $value ); |
|
289 | - $prepared[] = $item; |
|
290 | - } |
|
292 | + continue; |
|
293 | + } |
|
291 | 294 | |
292 | - continue; |
|
293 | - } |
|
295 | + // $item_id => array( 'price' => 10 ) |
|
296 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
297 | + $item = new GetPaid_Form_Item( $key ); |
|
294 | 298 | |
295 | - // $item_id => array( 'price' => 10 ) |
|
296 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
297 | - $item = new GetPaid_Form_Item( $key ); |
|
299 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
300 | + $item->set_price( $value['price'] ); |
|
301 | + } |
|
298 | 302 | |
299 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
300 | - $item->set_price( $value['price'] ); |
|
301 | - } |
|
303 | + if ( $item->can_purchase() ) { |
|
304 | + $prepared[] = $item; |
|
305 | + } |
|
302 | 306 | |
303 | - if ( $item->can_purchase() ) { |
|
304 | - $prepared[] = $item; |
|
305 | - } |
|
307 | + continue; |
|
308 | + } |
|
306 | 309 | |
307 | - continue; |
|
308 | - } |
|
310 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
309 | 311 | |
310 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
312 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
311 | 313 | |
312 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
314 | + if ( ! $item->can_purchase() ) { |
|
315 | + continue; |
|
316 | + } |
|
313 | 317 | |
314 | - if ( ! $item->can_purchase() ) { |
|
315 | - continue; |
|
316 | - } |
|
318 | + // Sub-total (Cart items). |
|
319 | + if ( isset( $value['subtotal'] ) ) { |
|
320 | + $item->set_price( $value['subtotal'] ); |
|
321 | + } |
|
317 | 322 | |
318 | - // Sub-total (Cart items). |
|
319 | - if ( isset( $value['subtotal'] ) ) { |
|
320 | - $item->set_price( $value['subtotal'] ); |
|
321 | - } |
|
323 | + if ( isset( $value['quantity'] ) ) { |
|
324 | + $item->set_quantity( $value['quantity'] ); |
|
325 | + } |
|
326 | + |
|
327 | + if ( isset( $value['allow_quantities'] ) ) { |
|
328 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
329 | + } |
|
330 | + |
|
331 | + if ( isset( $value['required'] ) ) { |
|
332 | + $item->set_is_required( $value['required'] ); |
|
333 | + } |
|
334 | + |
|
335 | + if ( isset( $value['description'] ) ) { |
|
336 | + $item->set_custom_description( $value['description'] ); |
|
337 | + } |
|
338 | + |
|
339 | + $prepared[] = $item; |
|
340 | + continue; |
|
341 | + |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + if ( 'objects' == $return && 'view' == $context ) { |
|
346 | + return $prepared; |
|
347 | + } |
|
348 | + |
|
349 | + $items = array(); |
|
350 | + foreach ( $prepared as $item ) { |
|
351 | + $items[] = $item->prepare_data_for_use(); |
|
352 | + } |
|
353 | + |
|
354 | + return $items; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Get a single item belonging to the form. |
|
359 | + * |
|
360 | + * @since 1.0.19 |
|
361 | + * @param int $item_id The item id to return. |
|
362 | + * @return GetPaid_Form_Item|bool |
|
363 | + */ |
|
364 | + public function get_item( $item_id ) { |
|
365 | + |
|
366 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
367 | + return false; |
|
368 | + } |
|
369 | + |
|
370 | + foreach( $this->get_items() as $item ) { |
|
371 | + if ( $item->get_id() == (int) $item_id ) { |
|
372 | + return $item; |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + return false; |
|
377 | + |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Gets a single element. |
|
382 | + * |
|
383 | + * @since 1.0.19 |
|
384 | + * @param string $element_type The element type to return. |
|
385 | + * @return array|bool |
|
386 | + */ |
|
387 | + public function get_element_type( $element_type ) { |
|
388 | + |
|
389 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
390 | + return false; |
|
391 | + } |
|
392 | + |
|
393 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
394 | + |
|
395 | + if ( $element['type'] == $element_type ) { |
|
396 | + return $element; |
|
397 | + } |
|
398 | + |
|
399 | + } |
|
400 | + |
|
401 | + return false; |
|
402 | + |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Get the total amount earned via this form. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @param string $context View or edit context. |
|
410 | + * @return array |
|
411 | + */ |
|
412 | + public function get_earned( $context = 'view' ) { |
|
413 | + return $this->get_prop( 'earned', $context ); |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Get the total amount refunded via this form. |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + * @param string $context View or edit context. |
|
421 | + * @return array |
|
422 | + */ |
|
423 | + public function get_refunded( $context = 'view' ) { |
|
424 | + return $this->get_prop( 'refunded', $context ); |
|
425 | + } |
|
322 | 426 | |
323 | - if ( isset( $value['quantity'] ) ) { |
|
324 | - $item->set_quantity( $value['quantity'] ); |
|
325 | - } |
|
427 | + /** |
|
428 | + * Get the total amount cancelled via this form. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $context View or edit context. |
|
432 | + * @return array |
|
433 | + */ |
|
434 | + public function get_cancelled( $context = 'view' ) { |
|
435 | + return $this->get_prop( 'cancelled', $context ); |
|
436 | + } |
|
326 | 437 | |
327 | - if ( isset( $value['allow_quantities'] ) ) { |
|
328 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
329 | - } |
|
438 | + /** |
|
439 | + * Get the total amount failed via this form. |
|
440 | + * |
|
441 | + * @since 1.0.19 |
|
442 | + * @param string $context View or edit context. |
|
443 | + * @return array |
|
444 | + */ |
|
445 | + public function get_failed( $context = 'view' ) { |
|
446 | + return $this->get_prop( 'failed', $context ); |
|
447 | + } |
|
330 | 448 | |
331 | - if ( isset( $value['required'] ) ) { |
|
332 | - $item->set_is_required( $value['required'] ); |
|
333 | - } |
|
334 | - |
|
335 | - if ( isset( $value['description'] ) ) { |
|
336 | - $item->set_custom_description( $value['description'] ); |
|
337 | - } |
|
338 | - |
|
339 | - $prepared[] = $item; |
|
340 | - continue; |
|
341 | - |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - if ( 'objects' == $return && 'view' == $context ) { |
|
346 | - return $prepared; |
|
347 | - } |
|
348 | - |
|
349 | - $items = array(); |
|
350 | - foreach ( $prepared as $item ) { |
|
351 | - $items[] = $item->prepare_data_for_use(); |
|
352 | - } |
|
353 | - |
|
354 | - return $items; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Get a single item belonging to the form. |
|
359 | - * |
|
360 | - * @since 1.0.19 |
|
361 | - * @param int $item_id The item id to return. |
|
362 | - * @return GetPaid_Form_Item|bool |
|
363 | - */ |
|
364 | - public function get_item( $item_id ) { |
|
365 | - |
|
366 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
367 | - return false; |
|
368 | - } |
|
369 | - |
|
370 | - foreach( $this->get_items() as $item ) { |
|
371 | - if ( $item->get_id() == (int) $item_id ) { |
|
372 | - return $item; |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - return false; |
|
377 | - |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Gets a single element. |
|
382 | - * |
|
383 | - * @since 1.0.19 |
|
384 | - * @param string $element_type The element type to return. |
|
385 | - * @return array|bool |
|
386 | - */ |
|
387 | - public function get_element_type( $element_type ) { |
|
388 | - |
|
389 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
390 | - return false; |
|
391 | - } |
|
392 | - |
|
393 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
394 | - |
|
395 | - if ( $element['type'] == $element_type ) { |
|
396 | - return $element; |
|
397 | - } |
|
398 | - |
|
399 | - } |
|
400 | - |
|
401 | - return false; |
|
402 | - |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Get the total amount earned via this form. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @param string $context View or edit context. |
|
410 | - * @return array |
|
411 | - */ |
|
412 | - public function get_earned( $context = 'view' ) { |
|
413 | - return $this->get_prop( 'earned', $context ); |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Get the total amount refunded via this form. |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - * @param string $context View or edit context. |
|
421 | - * @return array |
|
422 | - */ |
|
423 | - public function get_refunded( $context = 'view' ) { |
|
424 | - return $this->get_prop( 'refunded', $context ); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Get the total amount cancelled via this form. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $context View or edit context. |
|
432 | - * @return array |
|
433 | - */ |
|
434 | - public function get_cancelled( $context = 'view' ) { |
|
435 | - return $this->get_prop( 'cancelled', $context ); |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Get the total amount failed via this form. |
|
440 | - * |
|
441 | - * @since 1.0.19 |
|
442 | - * @param string $context View or edit context. |
|
443 | - * @return array |
|
444 | - */ |
|
445 | - public function get_failed( $context = 'view' ) { |
|
446 | - return $this->get_prop( 'failed', $context ); |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * Get the currency. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - public function get_currency() { |
|
457 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
458 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
459 | - } |
|
449 | + /** |
|
450 | + * Get the currency. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + public function get_currency() { |
|
457 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
458 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
459 | + } |
|
460 | 460 | |
461 | 461 | /* |
462 | 462 | |-------------------------------------------------------------------------- |
@@ -469,22 +469,22 @@ discard block |
||
469 | 469 | */ |
470 | 470 | |
471 | 471 | /** |
472 | - * Set plugin version when the item was created. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - */ |
|
476 | - public function set_version( $value ) { |
|
477 | - $this->set_prop( 'version', $value ); |
|
472 | + * Set plugin version when the item was created. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + */ |
|
476 | + public function set_version( $value ) { |
|
477 | + $this->set_prop( 'version', $value ); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
481 | - * Set date when the item was created. |
|
482 | - * |
|
483 | - * @since 1.0.19 |
|
484 | - * @param string $value Value to set. |
|
481 | + * Set date when the item was created. |
|
482 | + * |
|
483 | + * @since 1.0.19 |
|
484 | + * @param string $value Value to set. |
|
485 | 485 | * @return bool Whether or not the date was set. |
486 | - */ |
|
487 | - public function set_date_created( $value ) { |
|
486 | + */ |
|
487 | + public function set_date_created( $value ) { |
|
488 | 488 | $date = strtotime( $value ); |
489 | 489 | |
490 | 490 | if ( $date ) { |
@@ -497,13 +497,13 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
500 | - * Set date when the item was last modified. |
|
501 | - * |
|
502 | - * @since 1.0.19 |
|
503 | - * @param string $value Value to set. |
|
500 | + * Set date when the item was last modified. |
|
501 | + * |
|
502 | + * @since 1.0.19 |
|
503 | + * @param string $value Value to set. |
|
504 | 504 | * @return bool Whether or not the date was set. |
505 | - */ |
|
506 | - public function set_date_modified( $value ) { |
|
505 | + */ |
|
506 | + public function set_date_modified( $value ) { |
|
507 | 507 | $date = strtotime( $value ); |
508 | 508 | |
509 | 509 | if ( $date ) { |
@@ -516,118 +516,118 @@ discard block |
||
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
519 | - * Set the item name. |
|
520 | - * |
|
521 | - * @since 1.0.19 |
|
522 | - * @param string $value New name. |
|
523 | - */ |
|
524 | - public function set_name( $value ) { |
|
525 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
526 | - } |
|
527 | - |
|
528 | - /** |
|
529 | - * Alias of self::set_name(). |
|
530 | - * |
|
531 | - * @since 1.0.19 |
|
532 | - * @param string $value New name. |
|
533 | - */ |
|
534 | - public function set_title( $value ) { |
|
535 | - $this->set_name( $value ); |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Set the owner of the item. |
|
540 | - * |
|
541 | - * @since 1.0.19 |
|
542 | - * @param int $value New author. |
|
543 | - */ |
|
544 | - public function set_author( $value ) { |
|
545 | - $this->set_prop( 'author', (int) $value ); |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Set the form elements. |
|
550 | - * |
|
551 | - * @since 1.0.19 |
|
552 | - * @param array $value Form elements. |
|
553 | - */ |
|
554 | - public function set_elements( $value ) { |
|
555 | - if ( is_array( $value ) ) { |
|
556 | - $this->set_prop( 'elements', $value ); |
|
557 | - } |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Set the form items. |
|
562 | - * |
|
563 | - * @since 1.0.19 |
|
564 | - * @param array $value Form elements. |
|
565 | - */ |
|
566 | - public function set_items( $value ) { |
|
567 | - if ( is_array( $value ) ) { |
|
568 | - $this->set_prop( 'items', $value ); |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Set the total amount earned via this form. |
|
574 | - * |
|
575 | - * @since 1.0.19 |
|
576 | - * @param float $value Amount earned. |
|
577 | - */ |
|
578 | - public function set_earned( $value ) { |
|
579 | - $value = max( (float) $value, 0 ); |
|
580 | - $this->set_prop( 'earned', $value ); |
|
581 | - } |
|
582 | - |
|
583 | - /** |
|
584 | - * Set the total amount refunded via this form. |
|
585 | - * |
|
586 | - * @since 1.0.19 |
|
587 | - * @param float $value Amount refunded. |
|
588 | - */ |
|
589 | - public function set_refunded( $value ) { |
|
590 | - $value = max( (float) $value, 0 ); |
|
591 | - $this->set_prop( 'refunded', $value ); |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * Set the total amount cancelled via this form. |
|
596 | - * |
|
597 | - * @since 1.0.19 |
|
598 | - * @param float $value Amount cancelled. |
|
599 | - */ |
|
600 | - public function set_cancelled( $value ) { |
|
601 | - $value = max( (float) $value, 0 ); |
|
602 | - $this->set_prop( 'cancelled', $value ); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Set the total amount failed via this form. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param float $value Amount cancelled. |
|
610 | - */ |
|
611 | - public function set_failed( $value ) { |
|
612 | - $value = max( (float) $value, 0 ); |
|
613 | - $this->set_prop( 'failed', $value ); |
|
614 | - } |
|
519 | + * Set the item name. |
|
520 | + * |
|
521 | + * @since 1.0.19 |
|
522 | + * @param string $value New name. |
|
523 | + */ |
|
524 | + public function set_name( $value ) { |
|
525 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
526 | + } |
|
527 | + |
|
528 | + /** |
|
529 | + * Alias of self::set_name(). |
|
530 | + * |
|
531 | + * @since 1.0.19 |
|
532 | + * @param string $value New name. |
|
533 | + */ |
|
534 | + public function set_title( $value ) { |
|
535 | + $this->set_name( $value ); |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Set the owner of the item. |
|
540 | + * |
|
541 | + * @since 1.0.19 |
|
542 | + * @param int $value New author. |
|
543 | + */ |
|
544 | + public function set_author( $value ) { |
|
545 | + $this->set_prop( 'author', (int) $value ); |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Set the form elements. |
|
550 | + * |
|
551 | + * @since 1.0.19 |
|
552 | + * @param array $value Form elements. |
|
553 | + */ |
|
554 | + public function set_elements( $value ) { |
|
555 | + if ( is_array( $value ) ) { |
|
556 | + $this->set_prop( 'elements', $value ); |
|
557 | + } |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Set the form items. |
|
562 | + * |
|
563 | + * @since 1.0.19 |
|
564 | + * @param array $value Form elements. |
|
565 | + */ |
|
566 | + public function set_items( $value ) { |
|
567 | + if ( is_array( $value ) ) { |
|
568 | + $this->set_prop( 'items', $value ); |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Set the total amount earned via this form. |
|
574 | + * |
|
575 | + * @since 1.0.19 |
|
576 | + * @param float $value Amount earned. |
|
577 | + */ |
|
578 | + public function set_earned( $value ) { |
|
579 | + $value = max( (float) $value, 0 ); |
|
580 | + $this->set_prop( 'earned', $value ); |
|
581 | + } |
|
582 | + |
|
583 | + /** |
|
584 | + * Set the total amount refunded via this form. |
|
585 | + * |
|
586 | + * @since 1.0.19 |
|
587 | + * @param float $value Amount refunded. |
|
588 | + */ |
|
589 | + public function set_refunded( $value ) { |
|
590 | + $value = max( (float) $value, 0 ); |
|
591 | + $this->set_prop( 'refunded', $value ); |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Set the total amount cancelled via this form. |
|
596 | + * |
|
597 | + * @since 1.0.19 |
|
598 | + * @param float $value Amount cancelled. |
|
599 | + */ |
|
600 | + public function set_cancelled( $value ) { |
|
601 | + $value = max( (float) $value, 0 ); |
|
602 | + $this->set_prop( 'cancelled', $value ); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Set the total amount failed via this form. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param float $value Amount cancelled. |
|
610 | + */ |
|
611 | + public function set_failed( $value ) { |
|
612 | + $value = max( (float) $value, 0 ); |
|
613 | + $this->set_prop( 'failed', $value ); |
|
614 | + } |
|
615 | 615 | |
616 | 616 | /** |
617 | 617 | * Create an item. For backwards compatibilty. |
618 | 618 | * |
619 | 619 | * @deprecated |
620 | - * @return int item id |
|
620 | + * @return int item id |
|
621 | 621 | */ |
622 | 622 | public function create( $data = array() ) { |
623 | 623 | |
624 | - // Set the properties. |
|
625 | - if ( is_array( $data ) ) { |
|
626 | - $this->set_props( $data ); |
|
627 | - } |
|
624 | + // Set the properties. |
|
625 | + if ( is_array( $data ) ) { |
|
626 | + $this->set_props( $data ); |
|
627 | + } |
|
628 | 628 | |
629 | - // Save the item. |
|
630 | - return $this->save(); |
|
629 | + // Save the item. |
|
630 | + return $this->save(); |
|
631 | 631 | |
632 | 632 | } |
633 | 633 | |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | * Updates an item. For backwards compatibilty. |
636 | 636 | * |
637 | 637 | * @deprecated |
638 | - * @return int item id |
|
638 | + * @return int item id |
|
639 | 639 | */ |
640 | 640 | public function update( $data = array() ) { |
641 | 641 | return $this->create( $data ); |
@@ -651,22 +651,22 @@ discard block |
||
651 | 651 | */ |
652 | 652 | |
653 | 653 | /** |
654 | - * Checks whether this is the default payment form. |
|
655 | - * |
|
656 | - * @since 1.0.19 |
|
657 | - * @return bool |
|
658 | - */ |
|
654 | + * Checks whether this is the default payment form. |
|
655 | + * |
|
656 | + * @since 1.0.19 |
|
657 | + * @return bool |
|
658 | + */ |
|
659 | 659 | public function is_default() { |
660 | 660 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
661 | 661 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
662 | - } |
|
662 | + } |
|
663 | 663 | |
664 | 664 | /** |
665 | - * Checks whether the form is active. |
|
666 | - * |
|
667 | - * @since 1.0.19 |
|
668 | - * @return bool |
|
669 | - */ |
|
665 | + * Checks whether the form is active. |
|
666 | + * |
|
667 | + * @since 1.0.19 |
|
668 | + * @return bool |
|
669 | + */ |
|
670 | 670 | public function is_active() { |
671 | 671 | $is_active = 0 !== (int) $this->get_id(); |
672 | 672 | |
@@ -675,70 +675,70 @@ discard block |
||
675 | 675 | } |
676 | 676 | |
677 | 677 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Checks whether the form has a given item. |
|
682 | - * |
|
683 | - * @since 1.0.19 |
|
684 | - * @return bool |
|
685 | - */ |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Checks whether the form has a given item. |
|
682 | + * |
|
683 | + * @since 1.0.19 |
|
684 | + * @return bool |
|
685 | + */ |
|
686 | 686 | public function has_item( $item_id ) { |
687 | 687 | return false !== $this->get_item( $item_id ); |
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Checks whether the form has a given element. |
|
692 | - * |
|
693 | - * @since 1.0.19 |
|
694 | - * @return bool |
|
695 | - */ |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Checks whether the form has a given element. |
|
692 | + * |
|
693 | + * @since 1.0.19 |
|
694 | + * @return bool |
|
695 | + */ |
|
696 | 696 | public function has_element_type( $element_type ) { |
697 | 697 | return false !== $this->get_element_type( $element_type ); |
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Checks whether this form is recurring or not. |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - * @return bool |
|
705 | - */ |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Checks whether this form is recurring or not. |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + * @return bool |
|
705 | + */ |
|
706 | 706 | public function is_recurring() { |
707 | 707 | |
708 | - if ( ! empty( $this->invoice ) ) { |
|
709 | - return $this->invoice->is_recurring(); |
|
710 | - } |
|
708 | + if ( ! empty( $this->invoice ) ) { |
|
709 | + return $this->invoice->is_recurring(); |
|
710 | + } |
|
711 | 711 | |
712 | - foreach ( $this->get_items() as $item ) { |
|
712 | + foreach ( $this->get_items() as $item ) { |
|
713 | 713 | |
714 | - if ( $item->is_recurring() ) { |
|
715 | - return true; |
|
716 | - } |
|
714 | + if ( $item->is_recurring() ) { |
|
715 | + return true; |
|
716 | + } |
|
717 | 717 | |
718 | - } |
|
718 | + } |
|
719 | 719 | |
720 | 720 | return false; |
721 | - } |
|
721 | + } |
|
722 | 722 | |
723 | - /** |
|
724 | - * Retrieves the form's html. |
|
725 | - * |
|
726 | - * @since 1.0.19 |
|
727 | - */ |
|
723 | + /** |
|
724 | + * Retrieves the form's html. |
|
725 | + * |
|
726 | + * @since 1.0.19 |
|
727 | + */ |
|
728 | 728 | public function get_html() { |
729 | 729 | |
730 | - // Return the HTML. |
|
731 | - return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) ); |
|
730 | + // Return the HTML. |
|
731 | + return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) ); |
|
732 | 732 | |
733 | - } |
|
733 | + } |
|
734 | 734 | |
735 | - /** |
|
736 | - * Displays the payment form. |
|
737 | - * |
|
738 | - * @since 1.0.19 |
|
739 | - */ |
|
735 | + /** |
|
736 | + * Displays the payment form. |
|
737 | + * |
|
738 | + * @since 1.0.19 |
|
739 | + */ |
|
740 | 740 | public function display() { |
741 | - echo $this->get_html(); |
|
741 | + echo $this->get_html(); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | } |
@@ -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' => getpaid()->form_elements->get_elements(), |
|
178 | - 'form_elements' => getpaid()->form_elements->get_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' => getpaid()->form_elements->get_form_items( $post->ID ), |
|
185 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
177 | + 'elements' => getpaid()->form_elements->get_elements(), |
|
178 | + 'form_elements' => getpaid()->form_elements->get_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' => getpaid()->form_elements->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 | } |