@@ -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,48 +10,48 @@ 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 | - ); |
|
40 | + 'items' => null, |
|
41 | + 'earned' => 0, |
|
42 | + 'refunded' => 0, |
|
43 | + 'cancelled' => 0, |
|
44 | + 'failed' => 0, |
|
45 | + ); |
|
46 | 46 | |
47 | 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'; |
|
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 | 55 | |
56 | 56 | /** |
57 | 57 | * Stores a reference to the original WP_Post object |
@@ -61,32 +61,32 @@ discard block |
||
61 | 61 | protected $post = null; |
62 | 62 | |
63 | 63 | /** |
64 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
65 | - * |
|
66 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
67 | - */ |
|
68 | - public function __construct( $form = 0 ) { |
|
69 | - parent::__construct( $form ); |
|
70 | - |
|
71 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
72 | - $this->set_id( $form ); |
|
73 | - } elseif ( $form instanceof self ) { |
|
74 | - $this->set_id( $form->get_id() ); |
|
75 | - } elseif ( ! empty( $form->ID ) ) { |
|
76 | - $this->set_id( $form->ID ); |
|
77 | - } else { |
|
78 | - $this->set_object_read( true ); |
|
79 | - } |
|
64 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
65 | + * |
|
66 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
67 | + */ |
|
68 | + public function __construct( $form = 0 ) { |
|
69 | + parent::__construct( $form ); |
|
70 | + |
|
71 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
72 | + $this->set_id( $form ); |
|
73 | + } elseif ( $form instanceof self ) { |
|
74 | + $this->set_id( $form->get_id() ); |
|
75 | + } elseif ( ! empty( $form->ID ) ) { |
|
76 | + $this->set_id( $form->ID ); |
|
77 | + } else { |
|
78 | + $this->set_object_read( true ); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | // Load the datastore. |
82 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
82 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
83 | 83 | |
84 | - if ( $this->get_id() > 0 ) { |
|
84 | + if ( $this->get_id() > 0 ) { |
|
85 | 85 | $this->post = get_post( $this->get_id() ); |
86 | - $this->data_store->read( $this ); |
|
86 | + $this->data_store->read( $this ); |
|
87 | 87 | } |
88 | 88 | |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | 91 | /* |
92 | 92 | |-------------------------------------------------------------------------- |
@@ -104,268 +104,268 @@ discard block |
||
104 | 104 | */ |
105 | 105 | |
106 | 106 | /** |
107 | - * Get plugin version when the form was created. |
|
108 | - * |
|
109 | - * @since 1.0.19 |
|
110 | - * @param string $context View or edit context. |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function get_version( $context = 'view' ) { |
|
114 | - return $this->get_prop( 'version', $context ); |
|
107 | + * Get plugin version when the form was created. |
|
108 | + * |
|
109 | + * @since 1.0.19 |
|
110 | + * @param string $context View or edit context. |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function get_version( $context = 'view' ) { |
|
114 | + return $this->get_prop( 'version', $context ); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
118 | - * Get date when the form was created. |
|
119 | - * |
|
120 | - * @since 1.0.19 |
|
121 | - * @param string $context View or edit context. |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function get_date_created( $context = 'view' ) { |
|
125 | - return $this->get_prop( 'date_created', $context ); |
|
118 | + * Get date when the form was created. |
|
119 | + * |
|
120 | + * @since 1.0.19 |
|
121 | + * @param string $context View or edit context. |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function get_date_created( $context = 'view' ) { |
|
125 | + return $this->get_prop( 'date_created', $context ); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | - * Get GMT date when the form was created. |
|
130 | - * |
|
131 | - * @since 1.0.19 |
|
132 | - * @param string $context View or edit context. |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function get_date_created_gmt( $context = 'view' ) { |
|
129 | + * Get GMT date when the form was created. |
|
130 | + * |
|
131 | + * @since 1.0.19 |
|
132 | + * @param string $context View or edit context. |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function get_date_created_gmt( $context = 'view' ) { |
|
136 | 136 | $date = $this->get_date_created( $context ); |
137 | 137 | |
138 | 138 | if ( $date ) { |
139 | 139 | $date = get_gmt_from_date( $date ); |
140 | 140 | } |
141 | - return $date; |
|
141 | + return $date; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | - * Get date when the form was last modified. |
|
146 | - * |
|
147 | - * @since 1.0.19 |
|
148 | - * @param string $context View or edit context. |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function get_date_modified( $context = 'view' ) { |
|
152 | - return $this->get_prop( 'date_modified', $context ); |
|
145 | + * Get date when the form was last modified. |
|
146 | + * |
|
147 | + * @since 1.0.19 |
|
148 | + * @param string $context View or edit context. |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function get_date_modified( $context = 'view' ) { |
|
152 | + return $this->get_prop( 'date_modified', $context ); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
156 | - * Get GMT date when the form was last modified. |
|
157 | - * |
|
158 | - * @since 1.0.19 |
|
159 | - * @param string $context View or edit context. |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
156 | + * Get GMT date when the form was last modified. |
|
157 | + * |
|
158 | + * @since 1.0.19 |
|
159 | + * @param string $context View or edit context. |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
163 | 163 | $date = $this->get_date_modified( $context ); |
164 | 164 | |
165 | 165 | if ( $date ) { |
166 | 166 | $date = get_gmt_from_date( $date ); |
167 | 167 | } |
168 | - return $date; |
|
168 | + return $date; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | - * Get the form name. |
|
173 | - * |
|
174 | - * @since 1.0.19 |
|
175 | - * @param string $context View or edit context. |
|
176 | - * @return string |
|
177 | - */ |
|
178 | - public function get_name( $context = 'view' ) { |
|
179 | - return $this->get_prop( 'name', $context ); |
|
172 | + * Get the form name. |
|
173 | + * |
|
174 | + * @since 1.0.19 |
|
175 | + * @param string $context View or edit context. |
|
176 | + * @return string |
|
177 | + */ |
|
178 | + public function get_name( $context = 'view' ) { |
|
179 | + return $this->get_prop( 'name', $context ); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | - * Alias of self::get_name(). |
|
184 | - * |
|
185 | - * @since 1.0.19 |
|
186 | - * @param string $context View or edit context. |
|
187 | - * @return string |
|
188 | - */ |
|
189 | - public function get_title( $context = 'view' ) { |
|
190 | - return $this->get_name( $context ); |
|
191 | - } |
|
183 | + * Alias of self::get_name(). |
|
184 | + * |
|
185 | + * @since 1.0.19 |
|
186 | + * @param string $context View or edit context. |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + public function get_title( $context = 'view' ) { |
|
190 | + return $this->get_name( $context ); |
|
191 | + } |
|
192 | 192 | |
193 | 193 | /** |
194 | - * Get the owner of the form. |
|
195 | - * |
|
196 | - * @since 1.0.19 |
|
197 | - * @param string $context View or edit context. |
|
198 | - * @return int |
|
199 | - */ |
|
200 | - public function get_author( $context = 'view' ) { |
|
201 | - return (int) $this->get_prop( 'author', $context ); |
|
194 | + * Get the owner of the form. |
|
195 | + * |
|
196 | + * @since 1.0.19 |
|
197 | + * @param string $context View or edit context. |
|
198 | + * @return int |
|
199 | + */ |
|
200 | + public function get_author( $context = 'view' ) { |
|
201 | + return (int) $this->get_prop( 'author', $context ); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
205 | - * Get the elements that make up the form. |
|
206 | - * |
|
207 | - * @since 1.0.19 |
|
208 | - * @param string $context View or edit context. |
|
209 | - * @return array |
|
210 | - */ |
|
211 | - public function get_elements( $context = 'view' ) { |
|
212 | - $elements = $this->get_prop( 'elements', $context ); |
|
205 | + * Get the elements that make up the form. |
|
206 | + * |
|
207 | + * @since 1.0.19 |
|
208 | + * @param string $context View or edit context. |
|
209 | + * @return array |
|
210 | + */ |
|
211 | + public function get_elements( $context = 'view' ) { |
|
212 | + $elements = $this->get_prop( 'elements', $context ); |
|
213 | 213 | |
214 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
214 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
215 | 215 | return wpinv_get_data( 'sample-payment-form' ); |
216 | 216 | } |
217 | 217 | return $elements; |
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Get the items sold via the form. |
|
222 | - * |
|
223 | - * @since 1.0.19 |
|
224 | - * @param string $context View or edit context. |
|
225 | - * @param string $return objects or arrays. |
|
226 | - * @return GetPaid_Form_Item[] |
|
227 | - */ |
|
228 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
229 | - $items = $this->get_prop( 'items', $context ); |
|
230 | - |
|
231 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Get the items sold via the form. |
|
222 | + * |
|
223 | + * @since 1.0.19 |
|
224 | + * @param string $context View or edit context. |
|
225 | + * @param string $return objects or arrays. |
|
226 | + * @return GetPaid_Form_Item[] |
|
227 | + */ |
|
228 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
229 | + $items = $this->get_prop( 'items', $context ); |
|
230 | + |
|
231 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
232 | 232 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
233 | - } |
|
233 | + } |
|
234 | + |
|
235 | + if ( 'view' != $context ) { |
|
236 | + return $items; |
|
237 | + } |
|
238 | + |
|
239 | + // Convert the items. |
|
240 | + $prepared = array(); |
|
241 | + |
|
242 | + foreach ( $items as $key => $value ) { |
|
243 | + |
|
244 | + // $item_id => $quantity |
|
245 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
246 | + $item = new GetPaid_Form_Item( $key ); |
|
247 | + |
|
248 | + if ( $item->can_purchase() ) { |
|
249 | + $item->set_quantity( $value ); |
|
250 | + $prepared[] = $item; |
|
251 | + } |
|
252 | + |
|
253 | + continue; |
|
254 | + } |
|
255 | + |
|
256 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
257 | + |
|
258 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
259 | + |
|
260 | + if ( ! $item->can_purchase() ) { |
|
261 | + continue; |
|
262 | + } |
|
263 | + |
|
264 | + // Sub-total (Cart items). |
|
265 | + if ( isset( $value['subtotal'] ) ) { |
|
266 | + $item->set_price( $value['subtotal'] ); |
|
267 | + } |
|
268 | + |
|
269 | + if ( isset( $value['quantity'] ) ) { |
|
270 | + $item->set_quantity( $value['quantity'] ); |
|
271 | + } |
|
272 | + |
|
273 | + if ( isset( $value['allow_quantities'] ) ) { |
|
274 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
275 | + } |
|
276 | + |
|
277 | + if ( isset( $value['required'] ) ) { |
|
278 | + $item->set_is_required( $value['required'] ); |
|
279 | + } |
|
280 | + |
|
281 | + if ( isset( $value['description'] ) ) { |
|
282 | + $item->set_custom_description( $value['description'] ); |
|
283 | + } |
|
284 | + |
|
285 | + $prepared[] = $item; |
|
286 | + continue; |
|
287 | + |
|
288 | + } |
|
289 | + } |
|
290 | + |
|
291 | + if ( 'objects' == $return ) { |
|
292 | + return $prepared; |
|
293 | + } |
|
294 | + |
|
295 | + $items = array(); |
|
296 | + foreach ( $prepared as $item ) { |
|
297 | + $items[] = $item->prepare_data_for_use(); |
|
298 | + } |
|
299 | + |
|
300 | + return $items; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Get a single item belonging to the form. |
|
305 | + * |
|
306 | + * @since 1.0.19 |
|
307 | + * @param int $item_id The item id to return. |
|
308 | + * @return GetPaid_Form_Item|bool |
|
309 | + */ |
|
310 | + public function get_item( $item_id ) { |
|
311 | + |
|
312 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
313 | + return false; |
|
314 | + } |
|
315 | + |
|
316 | + foreach( $this->get_items() as $item ) { |
|
317 | + if ( $item->get_id() == (int) $item_id ) { |
|
318 | + return $item; |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + return false; |
|
323 | + |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Get the total amount earned via this form. |
|
328 | + * |
|
329 | + * @since 1.0.19 |
|
330 | + * @param string $context View or edit context. |
|
331 | + * @return array |
|
332 | + */ |
|
333 | + public function get_earned( $context = 'view' ) { |
|
334 | + return $this->get_prop( 'earned', $context ); |
|
335 | + } |
|
234 | 336 | |
235 | - if ( 'view' != $context ) { |
|
236 | - return $items; |
|
237 | - } |
|
337 | + /** |
|
338 | + * Get the total amount refunded via this form. |
|
339 | + * |
|
340 | + * @since 1.0.19 |
|
341 | + * @param string $context View or edit context. |
|
342 | + * @return array |
|
343 | + */ |
|
344 | + public function get_refunded( $context = 'view' ) { |
|
345 | + return $this->get_prop( 'refunded', $context ); |
|
346 | + } |
|
238 | 347 | |
239 | - // Convert the items. |
|
240 | - $prepared = array(); |
|
241 | - |
|
242 | - foreach ( $items as $key => $value ) { |
|
243 | - |
|
244 | - // $item_id => $quantity |
|
245 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
246 | - $item = new GetPaid_Form_Item( $key ); |
|
247 | - |
|
248 | - if ( $item->can_purchase() ) { |
|
249 | - $item->set_quantity( $value ); |
|
250 | - $prepared[] = $item; |
|
251 | - } |
|
252 | - |
|
253 | - continue; |
|
254 | - } |
|
255 | - |
|
256 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
257 | - |
|
258 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
259 | - |
|
260 | - if ( ! $item->can_purchase() ) { |
|
261 | - continue; |
|
262 | - } |
|
263 | - |
|
264 | - // Sub-total (Cart items). |
|
265 | - if ( isset( $value['subtotal'] ) ) { |
|
266 | - $item->set_price( $value['subtotal'] ); |
|
267 | - } |
|
268 | - |
|
269 | - if ( isset( $value['quantity'] ) ) { |
|
270 | - $item->set_quantity( $value['quantity'] ); |
|
271 | - } |
|
272 | - |
|
273 | - if ( isset( $value['allow_quantities'] ) ) { |
|
274 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
275 | - } |
|
276 | - |
|
277 | - if ( isset( $value['required'] ) ) { |
|
278 | - $item->set_is_required( $value['required'] ); |
|
279 | - } |
|
280 | - |
|
281 | - if ( isset( $value['description'] ) ) { |
|
282 | - $item->set_custom_description( $value['description'] ); |
|
283 | - } |
|
284 | - |
|
285 | - $prepared[] = $item; |
|
286 | - continue; |
|
287 | - |
|
288 | - } |
|
289 | - } |
|
290 | - |
|
291 | - if ( 'objects' == $return ) { |
|
292 | - return $prepared; |
|
293 | - } |
|
294 | - |
|
295 | - $items = array(); |
|
296 | - foreach ( $prepared as $item ) { |
|
297 | - $items[] = $item->prepare_data_for_use(); |
|
298 | - } |
|
299 | - |
|
300 | - return $items; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Get a single item belonging to the form. |
|
305 | - * |
|
306 | - * @since 1.0.19 |
|
307 | - * @param int $item_id The item id to return. |
|
308 | - * @return GetPaid_Form_Item|bool |
|
309 | - */ |
|
310 | - public function get_item( $item_id ) { |
|
311 | - |
|
312 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
313 | - return false; |
|
314 | - } |
|
315 | - |
|
316 | - foreach( $this->get_items() as $item ) { |
|
317 | - if ( $item->get_id() == (int) $item_id ) { |
|
318 | - return $item; |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - return false; |
|
323 | - |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Get the total amount earned via this form. |
|
328 | - * |
|
329 | - * @since 1.0.19 |
|
330 | - * @param string $context View or edit context. |
|
331 | - * @return array |
|
332 | - */ |
|
333 | - public function get_earned( $context = 'view' ) { |
|
334 | - return $this->get_prop( 'earned', $context ); |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Get the total amount refunded via this form. |
|
339 | - * |
|
340 | - * @since 1.0.19 |
|
341 | - * @param string $context View or edit context. |
|
342 | - * @return array |
|
343 | - */ |
|
344 | - public function get_refunded( $context = 'view' ) { |
|
345 | - return $this->get_prop( 'refunded', $context ); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Get the total amount cancelled via this form. |
|
350 | - * |
|
351 | - * @since 1.0.19 |
|
352 | - * @param string $context View or edit context. |
|
353 | - * @return array |
|
354 | - */ |
|
355 | - public function get_cancelled( $context = 'view' ) { |
|
356 | - return $this->get_prop( 'cancelled', $context ); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Get the total amount failed via this form. |
|
361 | - * |
|
362 | - * @since 1.0.19 |
|
363 | - * @param string $context View or edit context. |
|
364 | - * @return array |
|
365 | - */ |
|
366 | - public function get_failed( $context = 'view' ) { |
|
367 | - return $this->get_prop( 'failed', $context ); |
|
368 | - } |
|
348 | + /** |
|
349 | + * Get the total amount cancelled via this form. |
|
350 | + * |
|
351 | + * @since 1.0.19 |
|
352 | + * @param string $context View or edit context. |
|
353 | + * @return array |
|
354 | + */ |
|
355 | + public function get_cancelled( $context = 'view' ) { |
|
356 | + return $this->get_prop( 'cancelled', $context ); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Get the total amount failed via this form. |
|
361 | + * |
|
362 | + * @since 1.0.19 |
|
363 | + * @param string $context View or edit context. |
|
364 | + * @return array |
|
365 | + */ |
|
366 | + public function get_failed( $context = 'view' ) { |
|
367 | + return $this->get_prop( 'failed', $context ); |
|
368 | + } |
|
369 | 369 | |
370 | 370 | /* |
371 | 371 | |-------------------------------------------------------------------------- |
@@ -378,22 +378,22 @@ discard block |
||
378 | 378 | */ |
379 | 379 | |
380 | 380 | /** |
381 | - * Set plugin version when the item was created. |
|
382 | - * |
|
383 | - * @since 1.0.19 |
|
384 | - */ |
|
385 | - public function set_version( $value ) { |
|
386 | - $this->set_prop( 'version', $value ); |
|
381 | + * Set plugin version when the item was created. |
|
382 | + * |
|
383 | + * @since 1.0.19 |
|
384 | + */ |
|
385 | + public function set_version( $value ) { |
|
386 | + $this->set_prop( 'version', $value ); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
390 | - * Set date when the item was created. |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - * @param string $value Value to set. |
|
390 | + * Set date when the item was created. |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + * @param string $value Value to set. |
|
394 | 394 | * @return bool Whether or not the date was set. |
395 | - */ |
|
396 | - public function set_date_created( $value ) { |
|
395 | + */ |
|
396 | + public function set_date_created( $value ) { |
|
397 | 397 | $date = strtotime( $value ); |
398 | 398 | |
399 | 399 | if ( $date ) { |
@@ -406,13 +406,13 @@ discard block |
||
406 | 406 | } |
407 | 407 | |
408 | 408 | /** |
409 | - * Set date when the item was last modified. |
|
410 | - * |
|
411 | - * @since 1.0.19 |
|
412 | - * @param string $value Value to set. |
|
409 | + * Set date when the item was last modified. |
|
410 | + * |
|
411 | + * @since 1.0.19 |
|
412 | + * @param string $value Value to set. |
|
413 | 413 | * @return bool Whether or not the date was set. |
414 | - */ |
|
415 | - public function set_date_modified( $value ) { |
|
414 | + */ |
|
415 | + public function set_date_modified( $value ) { |
|
416 | 416 | $date = strtotime( $value ); |
417 | 417 | |
418 | 418 | if ( $date ) { |
@@ -425,118 +425,118 @@ discard block |
||
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
428 | - * Set the item name. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $value New name. |
|
432 | - */ |
|
433 | - public function set_name( $value ) { |
|
434 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Alias of self::set_name(). |
|
439 | - * |
|
440 | - * @since 1.0.19 |
|
441 | - * @param string $value New name. |
|
442 | - */ |
|
443 | - public function set_title( $value ) { |
|
444 | - $this->set_name( $value ); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Set the owner of the item. |
|
449 | - * |
|
450 | - * @since 1.0.19 |
|
451 | - * @param int $value New author. |
|
452 | - */ |
|
453 | - public function set_author( $value ) { |
|
454 | - $this->set_prop( 'author', (int) $value ); |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Set the form elements. |
|
459 | - * |
|
460 | - * @since 1.0.19 |
|
461 | - * @param array $value Form elements. |
|
462 | - */ |
|
463 | - public function set_elements( $value ) { |
|
464 | - if ( is_array( $value ) ) { |
|
465 | - $this->set_prop( 'elements', $value ); |
|
466 | - } |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * Set the form items. |
|
471 | - * |
|
472 | - * @since 1.0.19 |
|
473 | - * @param array $value Form elements. |
|
474 | - */ |
|
475 | - public function set_items( $value ) { |
|
476 | - if ( is_array( $value ) ) { |
|
477 | - $this->set_prop( 'items', $value ); |
|
478 | - } |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * Set the total amount earned via this form. |
|
483 | - * |
|
484 | - * @since 1.0.19 |
|
485 | - * @param float $value Amount earned. |
|
486 | - * @return array |
|
487 | - */ |
|
488 | - public function set_earned( $value ) { |
|
489 | - return $this->set_prop( 'earned', (float) $value ); |
|
490 | - } |
|
491 | - |
|
492 | - /** |
|
493 | - * Set the total amount refunded via this form. |
|
494 | - * |
|
495 | - * @since 1.0.19 |
|
496 | - * @param float $value Amount refunded. |
|
497 | - * @return array |
|
498 | - */ |
|
499 | - public function set_refunded( $value ) { |
|
500 | - return $this->set_prop( 'refunded', (float) $value ); |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Set the total amount cancelled via this form. |
|
505 | - * |
|
506 | - * @since 1.0.19 |
|
507 | - * @param float $value Amount cancelled. |
|
508 | - * @return array |
|
509 | - */ |
|
510 | - public function set_cancelled( $value ) { |
|
511 | - return $this->set_prop( 'cancelled', (float) $value ); |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * Set the total amount failed via this form. |
|
516 | - * |
|
517 | - * @since 1.0.19 |
|
518 | - * @param float $value Amount cancelled. |
|
519 | - * @return array |
|
520 | - */ |
|
521 | - public function set_failed( $value ) { |
|
522 | - return $this->set_prop( 'failed', (float) $value ); |
|
523 | - } |
|
428 | + * Set the item name. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $value New name. |
|
432 | + */ |
|
433 | + public function set_name( $value ) { |
|
434 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Alias of self::set_name(). |
|
439 | + * |
|
440 | + * @since 1.0.19 |
|
441 | + * @param string $value New name. |
|
442 | + */ |
|
443 | + public function set_title( $value ) { |
|
444 | + $this->set_name( $value ); |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Set the owner of the item. |
|
449 | + * |
|
450 | + * @since 1.0.19 |
|
451 | + * @param int $value New author. |
|
452 | + */ |
|
453 | + public function set_author( $value ) { |
|
454 | + $this->set_prop( 'author', (int) $value ); |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Set the form elements. |
|
459 | + * |
|
460 | + * @since 1.0.19 |
|
461 | + * @param array $value Form elements. |
|
462 | + */ |
|
463 | + public function set_elements( $value ) { |
|
464 | + if ( is_array( $value ) ) { |
|
465 | + $this->set_prop( 'elements', $value ); |
|
466 | + } |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * Set the form items. |
|
471 | + * |
|
472 | + * @since 1.0.19 |
|
473 | + * @param array $value Form elements. |
|
474 | + */ |
|
475 | + public function set_items( $value ) { |
|
476 | + if ( is_array( $value ) ) { |
|
477 | + $this->set_prop( 'items', $value ); |
|
478 | + } |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * Set the total amount earned via this form. |
|
483 | + * |
|
484 | + * @since 1.0.19 |
|
485 | + * @param float $value Amount earned. |
|
486 | + * @return array |
|
487 | + */ |
|
488 | + public function set_earned( $value ) { |
|
489 | + return $this->set_prop( 'earned', (float) $value ); |
|
490 | + } |
|
491 | + |
|
492 | + /** |
|
493 | + * Set the total amount refunded via this form. |
|
494 | + * |
|
495 | + * @since 1.0.19 |
|
496 | + * @param float $value Amount refunded. |
|
497 | + * @return array |
|
498 | + */ |
|
499 | + public function set_refunded( $value ) { |
|
500 | + return $this->set_prop( 'refunded', (float) $value ); |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Set the total amount cancelled via this form. |
|
505 | + * |
|
506 | + * @since 1.0.19 |
|
507 | + * @param float $value Amount cancelled. |
|
508 | + * @return array |
|
509 | + */ |
|
510 | + public function set_cancelled( $value ) { |
|
511 | + return $this->set_prop( 'cancelled', (float) $value ); |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * Set the total amount failed via this form. |
|
516 | + * |
|
517 | + * @since 1.0.19 |
|
518 | + * @param float $value Amount cancelled. |
|
519 | + * @return array |
|
520 | + */ |
|
521 | + public function set_failed( $value ) { |
|
522 | + return $this->set_prop( 'failed', (float) $value ); |
|
523 | + } |
|
524 | 524 | |
525 | 525 | /** |
526 | 526 | * Create an item. For backwards compatibilty. |
527 | 527 | * |
528 | 528 | * @deprecated |
529 | - * @return int item id |
|
529 | + * @return int item id |
|
530 | 530 | */ |
531 | 531 | public function create( $data = array() ) { |
532 | 532 | |
533 | - // Set the properties. |
|
534 | - if ( is_array( $data ) ) { |
|
535 | - $this->set_props( $data ); |
|
536 | - } |
|
533 | + // Set the properties. |
|
534 | + if ( is_array( $data ) ) { |
|
535 | + $this->set_props( $data ); |
|
536 | + } |
|
537 | 537 | |
538 | - // Save the item. |
|
539 | - return $this->save(); |
|
538 | + // Save the item. |
|
539 | + return $this->save(); |
|
540 | 540 | |
541 | 541 | } |
542 | 542 | |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | * Updates an item. For backwards compatibilty. |
545 | 545 | * |
546 | 546 | * @deprecated |
547 | - * @return int item id |
|
547 | + * @return int item id |
|
548 | 548 | */ |
549 | 549 | public function update( $data = array() ) { |
550 | 550 | return $this->create( $data ); |
@@ -560,22 +560,22 @@ discard block |
||
560 | 560 | */ |
561 | 561 | |
562 | 562 | /** |
563 | - * Checks whether this is the default payment form. |
|
564 | - * |
|
565 | - * @since 1.0.19 |
|
566 | - * @return bool |
|
567 | - */ |
|
563 | + * Checks whether this is the default payment form. |
|
564 | + * |
|
565 | + * @since 1.0.19 |
|
566 | + * @return bool |
|
567 | + */ |
|
568 | 568 | public function is_default() { |
569 | 569 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
570 | 570 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
571 | - } |
|
571 | + } |
|
572 | 572 | |
573 | 573 | /** |
574 | - * Checks whether the form is active. |
|
575 | - * |
|
576 | - * @since 1.0.19 |
|
577 | - * @return bool |
|
578 | - */ |
|
574 | + * Checks whether the form is active. |
|
575 | + * |
|
576 | + * @since 1.0.19 |
|
577 | + * @return bool |
|
578 | + */ |
|
579 | 579 | public function is_active() { |
580 | 580 | $is_active = null !== $this->get_id(); |
581 | 581 | |
@@ -584,43 +584,43 @@ discard block |
||
584 | 584 | } |
585 | 585 | |
586 | 586 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
587 | - } |
|
588 | - |
|
589 | - /** |
|
590 | - * Checks whether the form has a given item. |
|
591 | - * |
|
592 | - * @since 1.0.19 |
|
593 | - * @return bool |
|
594 | - */ |
|
587 | + } |
|
588 | + |
|
589 | + /** |
|
590 | + * Checks whether the form has a given item. |
|
591 | + * |
|
592 | + * @since 1.0.19 |
|
593 | + * @return bool |
|
594 | + */ |
|
595 | 595 | public function has_item( $item_id ) { |
596 | 596 | return false !== $this->get_item( $item_id ); |
597 | - } |
|
598 | - |
|
599 | - /** |
|
600 | - * Displays the payment form. |
|
601 | - * |
|
602 | - * @param bool $echo whether to return or echo the value. |
|
603 | - * @since 1.0.19 |
|
604 | - */ |
|
597 | + } |
|
598 | + |
|
599 | + /** |
|
600 | + * Displays the payment form. |
|
601 | + * |
|
602 | + * @param bool $echo whether to return or echo the value. |
|
603 | + * @since 1.0.19 |
|
604 | + */ |
|
605 | 605 | public function display( $echo = true ) { |
606 | - global $invoicing; |
|
607 | - |
|
608 | - // Ensure that it is active. |
|
609 | - if ( ! $this->is_active() ) { |
|
610 | - $html = aui()->alert( |
|
611 | - array( |
|
612 | - 'type' => 'warning', |
|
613 | - 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
614 | - ) |
|
615 | - ); |
|
616 | - |
|
617 | - if ( $echo ) { |
|
618 | - echo $html; |
|
619 | - return; |
|
620 | - } |
|
621 | - |
|
622 | - return $html; |
|
623 | - } |
|
606 | + global $invoicing; |
|
607 | + |
|
608 | + // Ensure that it is active. |
|
609 | + if ( ! $this->is_active() ) { |
|
610 | + $html = aui()->alert( |
|
611 | + array( |
|
612 | + 'type' => 'warning', |
|
613 | + 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
614 | + ) |
|
615 | + ); |
|
616 | + |
|
617 | + if ( $echo ) { |
|
618 | + echo $html; |
|
619 | + return; |
|
620 | + } |
|
621 | + |
|
622 | + return $html; |
|
623 | + } |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -65,25 +65,25 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
67 | 67 | */ |
68 | - public function __construct( $form = 0 ) { |
|
69 | - parent::__construct( $form ); |
|
68 | + public function __construct($form = 0) { |
|
69 | + parent::__construct($form); |
|
70 | 70 | |
71 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
72 | - $this->set_id( $form ); |
|
73 | - } elseif ( $form instanceof self ) { |
|
74 | - $this->set_id( $form->get_id() ); |
|
75 | - } elseif ( ! empty( $form->ID ) ) { |
|
76 | - $this->set_id( $form->ID ); |
|
71 | + if (is_numeric($form) && $form > 0) { |
|
72 | + $this->set_id($form); |
|
73 | + } elseif ($form instanceof self) { |
|
74 | + $this->set_id($form->get_id()); |
|
75 | + } elseif (!empty($form->ID)) { |
|
76 | + $this->set_id($form->ID); |
|
77 | 77 | } else { |
78 | - $this->set_object_read( true ); |
|
78 | + $this->set_object_read(true); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | // Load the datastore. |
82 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
82 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
83 | 83 | |
84 | - if ( $this->get_id() > 0 ) { |
|
85 | - $this->post = get_post( $this->get_id() ); |
|
86 | - $this->data_store->read( $this ); |
|
84 | + if ($this->get_id() > 0) { |
|
85 | + $this->post = get_post($this->get_id()); |
|
86 | + $this->data_store->read($this); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | } |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | * @param string $context View or edit context. |
111 | 111 | * @return string |
112 | 112 | */ |
113 | - public function get_version( $context = 'view' ) { |
|
114 | - return $this->get_prop( 'version', $context ); |
|
113 | + public function get_version($context = 'view') { |
|
114 | + return $this->get_prop('version', $context); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | * @param string $context View or edit context. |
122 | 122 | * @return string |
123 | 123 | */ |
124 | - public function get_date_created( $context = 'view' ) { |
|
125 | - return $this->get_prop( 'date_created', $context ); |
|
124 | + public function get_date_created($context = 'view') { |
|
125 | + return $this->get_prop('date_created', $context); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | * @param string $context View or edit context. |
133 | 133 | * @return string |
134 | 134 | */ |
135 | - public function get_date_created_gmt( $context = 'view' ) { |
|
136 | - $date = $this->get_date_created( $context ); |
|
135 | + public function get_date_created_gmt($context = 'view') { |
|
136 | + $date = $this->get_date_created($context); |
|
137 | 137 | |
138 | - if ( $date ) { |
|
139 | - $date = get_gmt_from_date( $date ); |
|
138 | + if ($date) { |
|
139 | + $date = get_gmt_from_date($date); |
|
140 | 140 | } |
141 | 141 | return $date; |
142 | 142 | } |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | * @param string $context View or edit context. |
149 | 149 | * @return string |
150 | 150 | */ |
151 | - public function get_date_modified( $context = 'view' ) { |
|
152 | - return $this->get_prop( 'date_modified', $context ); |
|
151 | + public function get_date_modified($context = 'view') { |
|
152 | + return $this->get_prop('date_modified', $context); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | * @param string $context View or edit context. |
160 | 160 | * @return string |
161 | 161 | */ |
162 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
163 | - $date = $this->get_date_modified( $context ); |
|
162 | + public function get_date_modified_gmt($context = 'view') { |
|
163 | + $date = $this->get_date_modified($context); |
|
164 | 164 | |
165 | - if ( $date ) { |
|
166 | - $date = get_gmt_from_date( $date ); |
|
165 | + if ($date) { |
|
166 | + $date = get_gmt_from_date($date); |
|
167 | 167 | } |
168 | 168 | return $date; |
169 | 169 | } |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * @param string $context View or edit context. |
176 | 176 | * @return string |
177 | 177 | */ |
178 | - public function get_name( $context = 'view' ) { |
|
179 | - return $this->get_prop( 'name', $context ); |
|
178 | + public function get_name($context = 'view') { |
|
179 | + return $this->get_prop('name', $context); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * @param string $context View or edit context. |
187 | 187 | * @return string |
188 | 188 | */ |
189 | - public function get_title( $context = 'view' ) { |
|
190 | - return $this->get_name( $context ); |
|
189 | + public function get_title($context = 'view') { |
|
190 | + return $this->get_name($context); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @param string $context View or edit context. |
198 | 198 | * @return int |
199 | 199 | */ |
200 | - public function get_author( $context = 'view' ) { |
|
201 | - return (int) $this->get_prop( 'author', $context ); |
|
200 | + public function get_author($context = 'view') { |
|
201 | + return (int) $this->get_prop('author', $context); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -208,11 +208,11 @@ discard block |
||
208 | 208 | * @param string $context View or edit context. |
209 | 209 | * @return array |
210 | 210 | */ |
211 | - public function get_elements( $context = 'view' ) { |
|
212 | - $elements = $this->get_prop( 'elements', $context ); |
|
211 | + public function get_elements($context = 'view') { |
|
212 | + $elements = $this->get_prop('elements', $context); |
|
213 | 213 | |
214 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
215 | - return wpinv_get_data( 'sample-payment-form' ); |
|
214 | + if (empty($elements) || !is_array($elements)) { |
|
215 | + return wpinv_get_data('sample-payment-form'); |
|
216 | 216 | } |
217 | 217 | return $elements; |
218 | 218 | } |
@@ -225,61 +225,61 @@ discard block |
||
225 | 225 | * @param string $return objects or arrays. |
226 | 226 | * @return GetPaid_Form_Item[] |
227 | 227 | */ |
228 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
229 | - $items = $this->get_prop( 'items', $context ); |
|
228 | + public function get_items($context = 'view', $return = 'objects') { |
|
229 | + $items = $this->get_prop('items', $context); |
|
230 | 230 | |
231 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
232 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
231 | + if (empty($items) || !is_array($items)) { |
|
232 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
233 | 233 | } |
234 | 234 | |
235 | - if ( 'view' != $context ) { |
|
235 | + if ('view' != $context) { |
|
236 | 236 | return $items; |
237 | 237 | } |
238 | 238 | |
239 | 239 | // Convert the items. |
240 | 240 | $prepared = array(); |
241 | 241 | |
242 | - foreach ( $items as $key => $value ) { |
|
242 | + foreach ($items as $key => $value) { |
|
243 | 243 | |
244 | 244 | // $item_id => $quantity |
245 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
246 | - $item = new GetPaid_Form_Item( $key ); |
|
245 | + if (is_numeric($key) && is_numeric($value)) { |
|
246 | + $item = new GetPaid_Form_Item($key); |
|
247 | 247 | |
248 | - if ( $item->can_purchase() ) { |
|
249 | - $item->set_quantity( $value ); |
|
248 | + if ($item->can_purchase()) { |
|
249 | + $item->set_quantity($value); |
|
250 | 250 | $prepared[] = $item; |
251 | 251 | } |
252 | 252 | |
253 | 253 | continue; |
254 | 254 | } |
255 | 255 | |
256 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
256 | + if (is_array($value) && isset($value['id'])) { |
|
257 | 257 | |
258 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
258 | + $item = new GetPaid_Form_Item($value['id']); |
|
259 | 259 | |
260 | - if ( ! $item->can_purchase() ) { |
|
260 | + if (!$item->can_purchase()) { |
|
261 | 261 | continue; |
262 | 262 | } |
263 | 263 | |
264 | 264 | // Sub-total (Cart items). |
265 | - if ( isset( $value['subtotal'] ) ) { |
|
266 | - $item->set_price( $value['subtotal'] ); |
|
265 | + if (isset($value['subtotal'])) { |
|
266 | + $item->set_price($value['subtotal']); |
|
267 | 267 | } |
268 | 268 | |
269 | - if ( isset( $value['quantity'] ) ) { |
|
270 | - $item->set_quantity( $value['quantity'] ); |
|
269 | + if (isset($value['quantity'])) { |
|
270 | + $item->set_quantity($value['quantity']); |
|
271 | 271 | } |
272 | 272 | |
273 | - if ( isset( $value['allow_quantities'] ) ) { |
|
274 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
273 | + if (isset($value['allow_quantities'])) { |
|
274 | + $item->set_allow_quantities($value['allow_quantities']); |
|
275 | 275 | } |
276 | 276 | |
277 | - if ( isset( $value['required'] ) ) { |
|
278 | - $item->set_is_required( $value['required'] ); |
|
277 | + if (isset($value['required'])) { |
|
278 | + $item->set_is_required($value['required']); |
|
279 | 279 | } |
280 | 280 | |
281 | - if ( isset( $value['description'] ) ) { |
|
282 | - $item->set_custom_description( $value['description'] ); |
|
281 | + if (isset($value['description'])) { |
|
282 | + $item->set_custom_description($value['description']); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | $prepared[] = $item; |
@@ -288,12 +288,12 @@ discard block |
||
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
291 | - if ( 'objects' == $return ) { |
|
291 | + if ('objects' == $return) { |
|
292 | 292 | return $prepared; |
293 | 293 | } |
294 | 294 | |
295 | 295 | $items = array(); |
296 | - foreach ( $prepared as $item ) { |
|
296 | + foreach ($prepared as $item) { |
|
297 | 297 | $items[] = $item->prepare_data_for_use(); |
298 | 298 | } |
299 | 299 | |
@@ -307,14 +307,14 @@ discard block |
||
307 | 307 | * @param int $item_id The item id to return. |
308 | 308 | * @return GetPaid_Form_Item|bool |
309 | 309 | */ |
310 | - public function get_item( $item_id ) { |
|
310 | + public function get_item($item_id) { |
|
311 | 311 | |
312 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
312 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
313 | 313 | return false; |
314 | 314 | } |
315 | 315 | |
316 | - foreach( $this->get_items() as $item ) { |
|
317 | - if ( $item->get_id() == (int) $item_id ) { |
|
316 | + foreach ($this->get_items() as $item) { |
|
317 | + if ($item->get_id() == (int) $item_id) { |
|
318 | 318 | return $item; |
319 | 319 | } |
320 | 320 | } |
@@ -330,8 +330,8 @@ discard block |
||
330 | 330 | * @param string $context View or edit context. |
331 | 331 | * @return array |
332 | 332 | */ |
333 | - public function get_earned( $context = 'view' ) { |
|
334 | - return $this->get_prop( 'earned', $context ); |
|
333 | + public function get_earned($context = 'view') { |
|
334 | + return $this->get_prop('earned', $context); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -341,8 +341,8 @@ discard block |
||
341 | 341 | * @param string $context View or edit context. |
342 | 342 | * @return array |
343 | 343 | */ |
344 | - public function get_refunded( $context = 'view' ) { |
|
345 | - return $this->get_prop( 'refunded', $context ); |
|
344 | + public function get_refunded($context = 'view') { |
|
345 | + return $this->get_prop('refunded', $context); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -352,8 +352,8 @@ discard block |
||
352 | 352 | * @param string $context View or edit context. |
353 | 353 | * @return array |
354 | 354 | */ |
355 | - public function get_cancelled( $context = 'view' ) { |
|
356 | - return $this->get_prop( 'cancelled', $context ); |
|
355 | + public function get_cancelled($context = 'view') { |
|
356 | + return $this->get_prop('cancelled', $context); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -363,8 +363,8 @@ discard block |
||
363 | 363 | * @param string $context View or edit context. |
364 | 364 | * @return array |
365 | 365 | */ |
366 | - public function get_failed( $context = 'view' ) { |
|
367 | - return $this->get_prop( 'failed', $context ); |
|
366 | + public function get_failed($context = 'view') { |
|
367 | + return $this->get_prop('failed', $context); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /* |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @since 1.0.19 |
384 | 384 | */ |
385 | - public function set_version( $value ) { |
|
386 | - $this->set_prop( 'version', $value ); |
|
385 | + public function set_version($value) { |
|
386 | + $this->set_prop('version', $value); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -393,11 +393,11 @@ discard block |
||
393 | 393 | * @param string $value Value to set. |
394 | 394 | * @return bool Whether or not the date was set. |
395 | 395 | */ |
396 | - public function set_date_created( $value ) { |
|
397 | - $date = strtotime( $value ); |
|
396 | + public function set_date_created($value) { |
|
397 | + $date = strtotime($value); |
|
398 | 398 | |
399 | - if ( $date ) { |
|
400 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
399 | + if ($date) { |
|
400 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
401 | 401 | return true; |
402 | 402 | } |
403 | 403 | |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | * @param string $value Value to set. |
413 | 413 | * @return bool Whether or not the date was set. |
414 | 414 | */ |
415 | - public function set_date_modified( $value ) { |
|
416 | - $date = strtotime( $value ); |
|
415 | + public function set_date_modified($value) { |
|
416 | + $date = strtotime($value); |
|
417 | 417 | |
418 | - if ( $date ) { |
|
419 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
418 | + if ($date) { |
|
419 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
420 | 420 | return true; |
421 | 421 | } |
422 | 422 | |
@@ -430,8 +430,8 @@ discard block |
||
430 | 430 | * @since 1.0.19 |
431 | 431 | * @param string $value New name. |
432 | 432 | */ |
433 | - public function set_name( $value ) { |
|
434 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
433 | + public function set_name($value) { |
|
434 | + $this->set_prop('name', sanitize_text_field($value)); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | * @since 1.0.19 |
441 | 441 | * @param string $value New name. |
442 | 442 | */ |
443 | - public function set_title( $value ) { |
|
444 | - $this->set_name( $value ); |
|
443 | + public function set_title($value) { |
|
444 | + $this->set_name($value); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -450,8 +450,8 @@ discard block |
||
450 | 450 | * @since 1.0.19 |
451 | 451 | * @param int $value New author. |
452 | 452 | */ |
453 | - public function set_author( $value ) { |
|
454 | - $this->set_prop( 'author', (int) $value ); |
|
453 | + public function set_author($value) { |
|
454 | + $this->set_prop('author', (int) $value); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -460,9 +460,9 @@ discard block |
||
460 | 460 | * @since 1.0.19 |
461 | 461 | * @param array $value Form elements. |
462 | 462 | */ |
463 | - public function set_elements( $value ) { |
|
464 | - if ( is_array( $value ) ) { |
|
465 | - $this->set_prop( 'elements', $value ); |
|
463 | + public function set_elements($value) { |
|
464 | + if (is_array($value)) { |
|
465 | + $this->set_prop('elements', $value); |
|
466 | 466 | } |
467 | 467 | } |
468 | 468 | |
@@ -472,9 +472,9 @@ discard block |
||
472 | 472 | * @since 1.0.19 |
473 | 473 | * @param array $value Form elements. |
474 | 474 | */ |
475 | - public function set_items( $value ) { |
|
476 | - if ( is_array( $value ) ) { |
|
477 | - $this->set_prop( 'items', $value ); |
|
475 | + public function set_items($value) { |
|
476 | + if (is_array($value)) { |
|
477 | + $this->set_prop('items', $value); |
|
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
@@ -485,8 +485,8 @@ discard block |
||
485 | 485 | * @param float $value Amount earned. |
486 | 486 | * @return array |
487 | 487 | */ |
488 | - public function set_earned( $value ) { |
|
489 | - return $this->set_prop( 'earned', (float) $value ); |
|
488 | + public function set_earned($value) { |
|
489 | + return $this->set_prop('earned', (float) $value); |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | /** |
@@ -496,8 +496,8 @@ discard block |
||
496 | 496 | * @param float $value Amount refunded. |
497 | 497 | * @return array |
498 | 498 | */ |
499 | - public function set_refunded( $value ) { |
|
500 | - return $this->set_prop( 'refunded', (float) $value ); |
|
499 | + public function set_refunded($value) { |
|
500 | + return $this->set_prop('refunded', (float) $value); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
@@ -507,8 +507,8 @@ discard block |
||
507 | 507 | * @param float $value Amount cancelled. |
508 | 508 | * @return array |
509 | 509 | */ |
510 | - public function set_cancelled( $value ) { |
|
511 | - return $this->set_prop( 'cancelled', (float) $value ); |
|
510 | + public function set_cancelled($value) { |
|
511 | + return $this->set_prop('cancelled', (float) $value); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | /** |
@@ -518,8 +518,8 @@ discard block |
||
518 | 518 | * @param float $value Amount cancelled. |
519 | 519 | * @return array |
520 | 520 | */ |
521 | - public function set_failed( $value ) { |
|
522 | - return $this->set_prop( 'failed', (float) $value ); |
|
521 | + public function set_failed($value) { |
|
522 | + return $this->set_prop('failed', (float) $value); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | /** |
@@ -528,11 +528,11 @@ discard block |
||
528 | 528 | * @deprecated |
529 | 529 | * @return int item id |
530 | 530 | */ |
531 | - public function create( $data = array() ) { |
|
531 | + public function create($data = array()) { |
|
532 | 532 | |
533 | 533 | // Set the properties. |
534 | - if ( is_array( $data ) ) { |
|
535 | - $this->set_props( $data ); |
|
534 | + if (is_array($data)) { |
|
535 | + $this->set_props($data); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | // Save the item. |
@@ -546,8 +546,8 @@ discard block |
||
546 | 546 | * @deprecated |
547 | 547 | * @return int item id |
548 | 548 | */ |
549 | - public function update( $data = array() ) { |
|
550 | - return $this->create( $data ); |
|
549 | + public function update($data = array()) { |
|
550 | + return $this->create($data); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /* |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | */ |
568 | 568 | public function is_default() { |
569 | 569 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
570 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
570 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -579,11 +579,11 @@ discard block |
||
579 | 579 | public function is_active() { |
580 | 580 | $is_active = null !== $this->get_id(); |
581 | 581 | |
582 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
582 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
583 | 583 | $is_active = false; |
584 | 584 | } |
585 | 585 | |
586 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
586 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -592,8 +592,8 @@ discard block |
||
592 | 592 | * @since 1.0.19 |
593 | 593 | * @return bool |
594 | 594 | */ |
595 | - public function has_item( $item_id ) { |
|
596 | - return false !== $this->get_item( $item_id ); |
|
595 | + public function has_item($item_id) { |
|
596 | + return false !== $this->get_item($item_id); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |
@@ -602,19 +602,19 @@ discard block |
||
602 | 602 | * @param bool $echo whether to return or echo the value. |
603 | 603 | * @since 1.0.19 |
604 | 604 | */ |
605 | - public function display( $echo = true ) { |
|
605 | + public function display($echo = true) { |
|
606 | 606 | global $invoicing; |
607 | 607 | |
608 | 608 | // Ensure that it is active. |
609 | - if ( ! $this->is_active() ) { |
|
609 | + if (!$this->is_active()) { |
|
610 | 610 | $html = aui()->alert( |
611 | 611 | array( |
612 | 612 | 'type' => 'warning', |
613 | - 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
613 | + 'content' => __('This payment form is no longer active', 'invoicing'), |
|
614 | 614 | ) |
615 | 615 | ); |
616 | 616 | |
617 | - if ( $echo ) { |
|
617 | + if ($echo) { |
|
618 | 618 | echo $html; |
619 | 619 | return; |
620 | 620 | } |
@@ -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,33 +74,33 @@ 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 ( is_numeric( $item ) && $item > 0 ) { |
|
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 | - } else { |
|
91 | - $this->set_object_read( true ); |
|
92 | - } |
|
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 ( is_numeric( $item ) && $item > 0 ) { |
|
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 | + } else { |
|
91 | + $this->set_object_read( true ); |
|
92 | + } |
|
93 | 93 | |
94 | 94 | // Load the datastore. |
95 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
95 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
96 | 96 | |
97 | - if ( $this->get_id() > 0 ) { |
|
97 | + if ( $this->get_id() > 0 ) { |
|
98 | 98 | $this->post = get_post( $this->get_id() ); |
99 | 99 | $this->ID = $this->get_id(); |
100 | - $this->data_store->read( $this ); |
|
100 | + $this->data_store->read( $this ); |
|
101 | 101 | } |
102 | 102 | |
103 | - } |
|
103 | + } |
|
104 | 104 | |
105 | 105 | /* |
106 | 106 | |-------------------------------------------------------------------------- |
@@ -118,379 +118,379 @@ discard block |
||
118 | 118 | */ |
119 | 119 | |
120 | 120 | /** |
121 | - * Get parent item ID. |
|
122 | - * |
|
123 | - * @since 1.0.19 |
|
124 | - * @param string $context View or edit context. |
|
125 | - * @return int |
|
126 | - */ |
|
127 | - public function get_parent_id( $context = 'view' ) { |
|
128 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
121 | + * Get parent item ID. |
|
122 | + * |
|
123 | + * @since 1.0.19 |
|
124 | + * @param string $context View or edit context. |
|
125 | + * @return int |
|
126 | + */ |
|
127 | + public function get_parent_id( $context = 'view' ) { |
|
128 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | - * Get item status. |
|
133 | - * |
|
134 | - * @since 1.0.19 |
|
135 | - * @param string $context View or edit context. |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - public function get_status( $context = 'view' ) { |
|
139 | - return $this->get_prop( 'status', $context ); |
|
132 | + * Get item status. |
|
133 | + * |
|
134 | + * @since 1.0.19 |
|
135 | + * @param string $context View or edit context. |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + public function get_status( $context = 'view' ) { |
|
139 | + return $this->get_prop( 'status', $context ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | - * Get plugin version when the item was created. |
|
144 | - * |
|
145 | - * @since 1.0.19 |
|
146 | - * @param string $context View or edit context. |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function get_version( $context = 'view' ) { |
|
150 | - return $this->get_prop( 'version', $context ); |
|
143 | + * Get plugin version when the item was created. |
|
144 | + * |
|
145 | + * @since 1.0.19 |
|
146 | + * @param string $context View or edit context. |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function get_version( $context = 'view' ) { |
|
150 | + return $this->get_prop( 'version', $context ); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
154 | - * Get date when the item was created. |
|
155 | - * |
|
156 | - * @since 1.0.19 |
|
157 | - * @param string $context View or edit context. |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function get_date_created( $context = 'view' ) { |
|
161 | - return $this->get_prop( 'date_created', $context ); |
|
154 | + * Get date when the item was created. |
|
155 | + * |
|
156 | + * @since 1.0.19 |
|
157 | + * @param string $context View or edit context. |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function get_date_created( $context = 'view' ) { |
|
161 | + return $this->get_prop( 'date_created', $context ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | - * Get GMT date when the item was created. |
|
166 | - * |
|
167 | - * @since 1.0.19 |
|
168 | - * @param string $context View or edit context. |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function get_date_created_gmt( $context = 'view' ) { |
|
165 | + * Get GMT date when the item was created. |
|
166 | + * |
|
167 | + * @since 1.0.19 |
|
168 | + * @param string $context View or edit context. |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function get_date_created_gmt( $context = 'view' ) { |
|
172 | 172 | $date = $this->get_date_created( $context ); |
173 | 173 | |
174 | 174 | if ( $date ) { |
175 | 175 | $date = get_gmt_from_date( $date ); |
176 | 176 | } |
177 | - return $date; |
|
177 | + return $date; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | - * Get date when the item was last modified. |
|
182 | - * |
|
183 | - * @since 1.0.19 |
|
184 | - * @param string $context View or edit context. |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - public function get_date_modified( $context = 'view' ) { |
|
188 | - return $this->get_prop( 'date_modified', $context ); |
|
181 | + * Get date when the item was last modified. |
|
182 | + * |
|
183 | + * @since 1.0.19 |
|
184 | + * @param string $context View or edit context. |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + public function get_date_modified( $context = 'view' ) { |
|
188 | + return $this->get_prop( 'date_modified', $context ); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | - * Get GMT date when the item was last modified. |
|
193 | - * |
|
194 | - * @since 1.0.19 |
|
195 | - * @param string $context View or edit context. |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
192 | + * Get GMT date when the item was last modified. |
|
193 | + * |
|
194 | + * @since 1.0.19 |
|
195 | + * @param string $context View or edit context. |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
199 | 199 | $date = $this->get_date_modified( $context ); |
200 | 200 | |
201 | 201 | if ( $date ) { |
202 | 202 | $date = get_gmt_from_date( $date ); |
203 | 203 | } |
204 | - return $date; |
|
204 | + return $date; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
208 | - * Get the item name. |
|
209 | - * |
|
210 | - * @since 1.0.19 |
|
211 | - * @param string $context View or edit context. |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public function get_name( $context = 'view' ) { |
|
215 | - return $this->get_prop( 'name', $context ); |
|
208 | + * Get the item name. |
|
209 | + * |
|
210 | + * @since 1.0.19 |
|
211 | + * @param string $context View or edit context. |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public function get_name( $context = 'view' ) { |
|
215 | + return $this->get_prop( 'name', $context ); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Alias of self::get_name(). |
|
220 | - * |
|
221 | - * @since 1.0.19 |
|
222 | - * @param string $context View or edit context. |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public function get_title( $context = 'view' ) { |
|
226 | - return $this->get_name( $context ); |
|
219 | + * Alias of self::get_name(). |
|
220 | + * |
|
221 | + * @since 1.0.19 |
|
222 | + * @param string $context View or edit context. |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public function get_title( $context = 'view' ) { |
|
226 | + return $this->get_name( $context ); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | - * Get the item description. |
|
231 | - * |
|
232 | - * @since 1.0.19 |
|
233 | - * @param string $context View or edit context. |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public function get_description( $context = 'view' ) { |
|
237 | - return $this->get_prop( 'description', $context ); |
|
230 | + * Get the item description. |
|
231 | + * |
|
232 | + * @since 1.0.19 |
|
233 | + * @param string $context View or edit context. |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public function get_description( $context = 'view' ) { |
|
237 | + return $this->get_prop( 'description', $context ); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
241 | - * Alias of self::get_description(). |
|
242 | - * |
|
243 | - * @since 1.0.19 |
|
244 | - * @param string $context View or edit context. |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - public function get_excerpt( $context = 'view' ) { |
|
248 | - return $this->get_description( $context ); |
|
241 | + * Alias of self::get_description(). |
|
242 | + * |
|
243 | + * @since 1.0.19 |
|
244 | + * @param string $context View or edit context. |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + public function get_excerpt( $context = 'view' ) { |
|
248 | + return $this->get_description( $context ); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
252 | - * Alias of self::get_description(). |
|
253 | - * |
|
254 | - * @since 1.0.19 |
|
255 | - * @param string $context View or edit context. |
|
256 | - * @return string |
|
257 | - */ |
|
258 | - public function get_summary( $context = 'view' ) { |
|
259 | - return $this->get_description( $context ); |
|
252 | + * Alias of self::get_description(). |
|
253 | + * |
|
254 | + * @since 1.0.19 |
|
255 | + * @param string $context View or edit context. |
|
256 | + * @return string |
|
257 | + */ |
|
258 | + public function get_summary( $context = 'view' ) { |
|
259 | + return $this->get_description( $context ); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | - * Get the owner of the item. |
|
264 | - * |
|
265 | - * @since 1.0.19 |
|
266 | - * @param string $context View or edit context. |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function get_author( $context = 'view' ) { |
|
270 | - return (int) $this->get_prop( 'author', $context ); |
|
263 | + * Get the owner of the item. |
|
264 | + * |
|
265 | + * @since 1.0.19 |
|
266 | + * @param string $context View or edit context. |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function get_author( $context = 'view' ) { |
|
270 | + return (int) $this->get_prop( 'author', $context ); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
274 | - * Get the price of the item. |
|
275 | - * |
|
276 | - * @since 1.0.19 |
|
277 | - * @param string $context View or edit context. |
|
278 | - * @return float |
|
279 | - */ |
|
280 | - public function get_price( $context = 'view' ) { |
|
274 | + * Get the price of the item. |
|
275 | + * |
|
276 | + * @since 1.0.19 |
|
277 | + * @param string $context View or edit context. |
|
278 | + * @return float |
|
279 | + */ |
|
280 | + public function get_price( $context = 'view' ) { |
|
281 | 281 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
282 | - } |
|
282 | + } |
|
283 | 283 | |
284 | - /** |
|
285 | - * Get the inital price of the item. |
|
286 | - * |
|
287 | - * @since 1.0.19 |
|
288 | - * @param string $context View or edit context. |
|
289 | - * @return float |
|
290 | - */ |
|
291 | - public function get_initial_price( $context = 'view' ) { |
|
284 | + /** |
|
285 | + * Get the inital price of the item. |
|
286 | + * |
|
287 | + * @since 1.0.19 |
|
288 | + * @param string $context View or edit context. |
|
289 | + * @return float |
|
290 | + */ |
|
291 | + public function get_initial_price( $context = 'view' ) { |
|
292 | 292 | |
293 | - $price = $this->get_price( $context ); |
|
293 | + $price = $this->get_price( $context ); |
|
294 | 294 | |
295 | - if ( $this->has_free_trial() ) { |
|
296 | - $price = wpinv_sanitize_amount( 0 ); |
|
297 | - } |
|
295 | + if ( $this->has_free_trial() ) { |
|
296 | + $price = wpinv_sanitize_amount( 0 ); |
|
297 | + } |
|
298 | 298 | |
299 | 299 | return apply_filters( 'wpinv_get_initial_item_price', $price, $this ); |
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
303 | - * Returns a formated price. |
|
304 | - * |
|
305 | - * @since 1.0.19 |
|
306 | - * @param string $context View or edit context. |
|
307 | - * @return string |
|
308 | - */ |
|
303 | + * Returns a formated price. |
|
304 | + * |
|
305 | + * @since 1.0.19 |
|
306 | + * @param string $context View or edit context. |
|
307 | + * @return string |
|
308 | + */ |
|
309 | 309 | public function get_the_price() { |
310 | 310 | return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Returns the formated initial price. |
|
315 | - * |
|
316 | - * @since 1.0.19 |
|
317 | - * @param string $context View or edit context. |
|
318 | - * @return string |
|
319 | - */ |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Returns the formated initial price. |
|
315 | + * |
|
316 | + * @since 1.0.19 |
|
317 | + * @param string $context View or edit context. |
|
318 | + * @return string |
|
319 | + */ |
|
320 | 320 | public function get_the_initial_price() { |
321 | 321 | return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
325 | - * Get the VAT rule of the item. |
|
326 | - * |
|
327 | - * @since 1.0.19 |
|
328 | - * @param string $context View or edit context. |
|
329 | - * @return string |
|
330 | - */ |
|
331 | - public function get_vat_rule( $context = 'view' ) { |
|
325 | + * Get the VAT rule of the item. |
|
326 | + * |
|
327 | + * @since 1.0.19 |
|
328 | + * @param string $context View or edit context. |
|
329 | + * @return string |
|
330 | + */ |
|
331 | + public function get_vat_rule( $context = 'view' ) { |
|
332 | 332 | return $this->get_prop( 'vat_rule', $context ); |
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | - * Get the VAT class of the item. |
|
337 | - * |
|
338 | - * @since 1.0.19 |
|
339 | - * @param string $context View or edit context. |
|
340 | - * @return string |
|
341 | - */ |
|
342 | - public function get_vat_class( $context = 'view' ) { |
|
336 | + * Get the VAT class of the item. |
|
337 | + * |
|
338 | + * @since 1.0.19 |
|
339 | + * @param string $context View or edit context. |
|
340 | + * @return string |
|
341 | + */ |
|
342 | + public function get_vat_class( $context = 'view' ) { |
|
343 | 343 | return $this->get_prop( 'vat_class', $context ); |
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
347 | - * Get the type of the item. |
|
348 | - * |
|
349 | - * @since 1.0.19 |
|
350 | - * @param string $context View or edit context. |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - public function get_type( $context = 'view' ) { |
|
347 | + * Get the type of the item. |
|
348 | + * |
|
349 | + * @since 1.0.19 |
|
350 | + * @param string $context View or edit context. |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + public function get_type( $context = 'view' ) { |
|
354 | 354 | return $this->get_prop( 'type', $context ); |
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Get the custom id of the item. |
|
359 | - * |
|
360 | - * @since 1.0.19 |
|
361 | - * @param string $context View or edit context. |
|
362 | - * @return string |
|
363 | - */ |
|
364 | - public function get_custom_id( $context = 'view' ) { |
|
358 | + * Get the custom id of the item. |
|
359 | + * |
|
360 | + * @since 1.0.19 |
|
361 | + * @param string $context View or edit context. |
|
362 | + * @return string |
|
363 | + */ |
|
364 | + public function get_custom_id( $context = 'view' ) { |
|
365 | 365 | return $this->get_prop( 'custom_id', $context ); |
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
369 | - * Get the custom name of the item. |
|
370 | - * |
|
371 | - * @since 1.0.19 |
|
372 | - * @param string $context View or edit context. |
|
373 | - * @return string |
|
374 | - */ |
|
375 | - public function get_custom_name( $context = 'view' ) { |
|
369 | + * Get the custom name of the item. |
|
370 | + * |
|
371 | + * @since 1.0.19 |
|
372 | + * @param string $context View or edit context. |
|
373 | + * @return string |
|
374 | + */ |
|
375 | + public function get_custom_name( $context = 'view' ) { |
|
376 | 376 | return $this->get_prop( 'custom_name', $context ); |
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
380 | - * Get the custom singular name of the item. |
|
381 | - * |
|
382 | - * @since 1.0.19 |
|
383 | - * @param string $context View or edit context. |
|
384 | - * @return string |
|
385 | - */ |
|
386 | - public function get_custom_singular_name( $context = 'view' ) { |
|
380 | + * Get the custom singular name of the item. |
|
381 | + * |
|
382 | + * @since 1.0.19 |
|
383 | + * @param string $context View or edit context. |
|
384 | + * @return string |
|
385 | + */ |
|
386 | + public function get_custom_singular_name( $context = 'view' ) { |
|
387 | 387 | return $this->get_prop( 'custom_singular_name', $context ); |
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
391 | - * Checks if an item is editable.. |
|
392 | - * |
|
393 | - * @since 1.0.19 |
|
394 | - * @param string $context View or edit context. |
|
395 | - * @return int |
|
396 | - */ |
|
397 | - public function get_is_editable( $context = 'view' ) { |
|
391 | + * Checks if an item is editable.. |
|
392 | + * |
|
393 | + * @since 1.0.19 |
|
394 | + * @param string $context View or edit context. |
|
395 | + * @return int |
|
396 | + */ |
|
397 | + public function get_is_editable( $context = 'view' ) { |
|
398 | 398 | return (int) $this->get_prop( 'is_editable', $context ); |
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
402 | - * Alias of self::get_is_editable(). |
|
403 | - * |
|
404 | - * @since 1.0.19 |
|
405 | - * @param string $context View or edit context. |
|
406 | - * @return int |
|
407 | - */ |
|
408 | - public function get_editable( $context = 'view' ) { |
|
409 | - return $this->get_is_editable( $context ); |
|
402 | + * Alias of self::get_is_editable(). |
|
403 | + * |
|
404 | + * @since 1.0.19 |
|
405 | + * @param string $context View or edit context. |
|
406 | + * @return int |
|
407 | + */ |
|
408 | + public function get_editable( $context = 'view' ) { |
|
409 | + return $this->get_is_editable( $context ); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** |
413 | - * Checks if dynamic pricing is enabled. |
|
414 | - * |
|
415 | - * @since 1.0.19 |
|
416 | - * @param string $context View or edit context. |
|
417 | - * @return int |
|
418 | - */ |
|
419 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
413 | + * Checks if dynamic pricing is enabled. |
|
414 | + * |
|
415 | + * @since 1.0.19 |
|
416 | + * @param string $context View or edit context. |
|
417 | + * @return int |
|
418 | + */ |
|
419 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
420 | 420 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
424 | - * Returns the minimum price if dynamic pricing is enabled. |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - * @param string $context View or edit context. |
|
428 | - * @return float |
|
429 | - */ |
|
430 | - public function get_minimum_price( $context = 'view' ) { |
|
424 | + * Returns the minimum price if dynamic pricing is enabled. |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + * @param string $context View or edit context. |
|
428 | + * @return float |
|
429 | + */ |
|
430 | + public function get_minimum_price( $context = 'view' ) { |
|
431 | 431 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
435 | - * Checks if this is a recurring item. |
|
436 | - * |
|
437 | - * @since 1.0.19 |
|
438 | - * @param string $context View or edit context. |
|
439 | - * @return int |
|
440 | - */ |
|
441 | - public function get_is_recurring( $context = 'view' ) { |
|
435 | + * Checks if this is a recurring item. |
|
436 | + * |
|
437 | + * @since 1.0.19 |
|
438 | + * @param string $context View or edit context. |
|
439 | + * @return int |
|
440 | + */ |
|
441 | + public function get_is_recurring( $context = 'view' ) { |
|
442 | 442 | return (int) $this->get_prop( 'is_recurring', $context ); |
443 | - } |
|
443 | + } |
|
444 | 444 | |
445 | - /** |
|
446 | - * Get the recurring price of the item. |
|
447 | - * |
|
448 | - * @since 1.0.19 |
|
449 | - * @param string $context View or edit context. |
|
450 | - * @return float |
|
451 | - */ |
|
452 | - public function get_recurring_price( $context = 'view' ) { |
|
453 | - $price = $this->get_price( $context ); |
|
445 | + /** |
|
446 | + * Get the recurring price of the item. |
|
447 | + * |
|
448 | + * @since 1.0.19 |
|
449 | + * @param string $context View or edit context. |
|
450 | + * @return float |
|
451 | + */ |
|
452 | + public function get_recurring_price( $context = 'view' ) { |
|
453 | + $price = $this->get_price( $context ); |
|
454 | 454 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Get the first renewal date (in timestamps) of the item. |
|
459 | - * |
|
460 | - * @since 1.0.19 |
|
461 | - * @return int |
|
462 | - */ |
|
463 | - public function get_first_renewal_date() { |
|
464 | - |
|
465 | - $periods = array( |
|
466 | - 'D' => 'days', |
|
467 | - 'W' => 'weeks', |
|
468 | - 'M' => 'months', |
|
469 | - 'Y' => 'years', |
|
470 | - ); |
|
471 | - |
|
472 | - $period = $this->get_recurring_period(); |
|
473 | - $interval = $this->get_recurring_interval(); |
|
474 | - |
|
475 | - if ( $this->has_free_trial() ) { |
|
476 | - $period = $this->get_trial_period(); |
|
477 | - $interval = $this->get_trial_interval(); |
|
478 | - } |
|
479 | - |
|
480 | - $period = $periods[ $period ]; |
|
481 | - $interval = empty( $interval ) ? 1 : $interval; |
|
482 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Get the first renewal date (in timestamps) of the item. |
|
459 | + * |
|
460 | + * @since 1.0.19 |
|
461 | + * @return int |
|
462 | + */ |
|
463 | + public function get_first_renewal_date() { |
|
464 | + |
|
465 | + $periods = array( |
|
466 | + 'D' => 'days', |
|
467 | + 'W' => 'weeks', |
|
468 | + 'M' => 'months', |
|
469 | + 'Y' => 'years', |
|
470 | + ); |
|
471 | + |
|
472 | + $period = $this->get_recurring_period(); |
|
473 | + $interval = $this->get_recurring_interval(); |
|
474 | + |
|
475 | + if ( $this->has_free_trial() ) { |
|
476 | + $period = $this->get_trial_period(); |
|
477 | + $interval = $this->get_trial_interval(); |
|
478 | + } |
|
479 | + |
|
480 | + $period = $periods[ $period ]; |
|
481 | + $interval = empty( $interval ) ? 1 : $interval; |
|
482 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
483 | 483 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
487 | - * Get the recurring period. |
|
488 | - * |
|
489 | - * @since 1.0.19 |
|
490 | - * @param bool $full Return abbreviation or in full. |
|
491 | - * @return string |
|
492 | - */ |
|
493 | - public function get_recurring_period( $full = false ) { |
|
487 | + * Get the recurring period. |
|
488 | + * |
|
489 | + * @since 1.0.19 |
|
490 | + * @param bool $full Return abbreviation or in full. |
|
491 | + * @return string |
|
492 | + */ |
|
493 | + public function get_recurring_period( $full = false ) { |
|
494 | 494 | $period = $this->get_prop( 'recurring_period', 'view' ); |
495 | 495 | |
496 | 496 | if ( $full && ! is_bool( $full ) ) { |
@@ -501,63 +501,63 @@ discard block |
||
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
504 | - * Get the recurring interval. |
|
505 | - * |
|
506 | - * @since 1.0.19 |
|
507 | - * @param string $context View or edit context. |
|
508 | - * @return int |
|
509 | - */ |
|
510 | - public function get_recurring_interval( $context = 'view' ) { |
|
511 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
504 | + * Get the recurring interval. |
|
505 | + * |
|
506 | + * @since 1.0.19 |
|
507 | + * @param string $context View or edit context. |
|
508 | + * @return int |
|
509 | + */ |
|
510 | + public function get_recurring_interval( $context = 'view' ) { |
|
511 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
512 | 512 | |
513 | - if ( $interval < 1 ) { |
|
514 | - $interval = 1; |
|
515 | - } |
|
513 | + if ( $interval < 1 ) { |
|
514 | + $interval = 1; |
|
515 | + } |
|
516 | 516 | |
517 | 517 | return $interval; |
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
521 | - * Get the recurring limit. |
|
522 | - * |
|
523 | - * @since 1.0.19 |
|
524 | - * @param string $context View or edit context. |
|
525 | - * @return int |
|
526 | - */ |
|
527 | - public function get_recurring_limit( $context = 'view' ) { |
|
521 | + * Get the recurring limit. |
|
522 | + * |
|
523 | + * @since 1.0.19 |
|
524 | + * @param string $context View or edit context. |
|
525 | + * @return int |
|
526 | + */ |
|
527 | + public function get_recurring_limit( $context = 'view' ) { |
|
528 | 528 | return (int) $this->get_prop( 'recurring_limit', $context ); |
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
532 | - * Checks if we have a free trial. |
|
533 | - * |
|
534 | - * @since 1.0.19 |
|
535 | - * @param string $context View or edit context. |
|
536 | - * @return int |
|
537 | - */ |
|
538 | - public function get_is_free_trial( $context = 'view' ) { |
|
532 | + * Checks if we have a free trial. |
|
533 | + * |
|
534 | + * @since 1.0.19 |
|
535 | + * @param string $context View or edit context. |
|
536 | + * @return int |
|
537 | + */ |
|
538 | + public function get_is_free_trial( $context = 'view' ) { |
|
539 | 539 | return (int) $this->get_prop( 'is_free_trial', $context ); |
540 | 540 | } |
541 | 541 | |
542 | 542 | /** |
543 | - * Alias for self::get_is_free_trial(). |
|
544 | - * |
|
545 | - * @since 1.0.19 |
|
546 | - * @param string $context View or edit context. |
|
547 | - * @return int |
|
548 | - */ |
|
549 | - public function get_free_trial( $context = 'view' ) { |
|
543 | + * Alias for self::get_is_free_trial(). |
|
544 | + * |
|
545 | + * @since 1.0.19 |
|
546 | + * @param string $context View or edit context. |
|
547 | + * @return int |
|
548 | + */ |
|
549 | + public function get_free_trial( $context = 'view' ) { |
|
550 | 550 | return $this->get_is_free_trial( $context ); |
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
554 | - * Get the trial period. |
|
555 | - * |
|
556 | - * @since 1.0.19 |
|
557 | - * @param bool $full Return abbreviation or in full. |
|
558 | - * @return string |
|
559 | - */ |
|
560 | - public function get_trial_period( $full = false ) { |
|
554 | + * Get the trial period. |
|
555 | + * |
|
556 | + * @since 1.0.19 |
|
557 | + * @param bool $full Return abbreviation or in full. |
|
558 | + * @return string |
|
559 | + */ |
|
560 | + public function get_trial_period( $full = false ) { |
|
561 | 561 | $period = $this->get_prop( 'trial_period', 'view' ); |
562 | 562 | |
563 | 563 | if ( $full && ! is_bool( $full ) ) { |
@@ -568,25 +568,25 @@ discard block |
||
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
571 | - * Get the trial interval. |
|
572 | - * |
|
573 | - * @since 1.0.19 |
|
574 | - * @param string $context View or edit context. |
|
575 | - * @return int |
|
576 | - */ |
|
577 | - public function get_trial_interval( $context = 'view' ) { |
|
571 | + * Get the trial interval. |
|
572 | + * |
|
573 | + * @since 1.0.19 |
|
574 | + * @param string $context View or edit context. |
|
575 | + * @return int |
|
576 | + */ |
|
577 | + public function get_trial_interval( $context = 'view' ) { |
|
578 | 578 | return (int) $this->get_prop( 'trial_interval', $context ); |
579 | - } |
|
579 | + } |
|
580 | 580 | |
581 | - /** |
|
582 | - * Get the item's edit url. |
|
583 | - * |
|
584 | - * @since 1.0.19 |
|
585 | - * @return string |
|
586 | - */ |
|
587 | - public function get_edit_url() { |
|
581 | + /** |
|
582 | + * Get the item's edit url. |
|
583 | + * |
|
584 | + * @since 1.0.19 |
|
585 | + * @return string |
|
586 | + */ |
|
587 | + public function get_edit_url() { |
|
588 | 588 | return get_edit_post_link( $this->get_id() ); |
589 | - } |
|
589 | + } |
|
590 | 590 | |
591 | 591 | /** |
592 | 592 | * Margic method for retrieving a property. |
@@ -618,52 +618,52 @@ discard block |
||
618 | 618 | */ |
619 | 619 | |
620 | 620 | /** |
621 | - * Set parent order ID. |
|
622 | - * |
|
623 | - * @since 1.0.19 |
|
624 | - */ |
|
625 | - public function set_parent_id( $value ) { |
|
626 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
627 | - return; |
|
628 | - } |
|
629 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
630 | - } |
|
631 | - |
|
632 | - /** |
|
633 | - * Sets item status. |
|
634 | - * |
|
635 | - * @since 1.0.19 |
|
636 | - * @param string $status New status. |
|
637 | - * @return array details of change. |
|
638 | - */ |
|
639 | - public function set_status( $status ) { |
|
621 | + * Set parent order ID. |
|
622 | + * |
|
623 | + * @since 1.0.19 |
|
624 | + */ |
|
625 | + public function set_parent_id( $value ) { |
|
626 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
627 | + return; |
|
628 | + } |
|
629 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
630 | + } |
|
631 | + |
|
632 | + /** |
|
633 | + * Sets item status. |
|
634 | + * |
|
635 | + * @since 1.0.19 |
|
636 | + * @param string $status New status. |
|
637 | + * @return array details of change. |
|
638 | + */ |
|
639 | + public function set_status( $status ) { |
|
640 | 640 | $old_status = $this->get_status(); |
641 | 641 | |
642 | 642 | $this->set_prop( 'status', $status ); |
643 | 643 | |
644 | - return array( |
|
645 | - 'from' => $old_status, |
|
646 | - 'to' => $status, |
|
647 | - ); |
|
644 | + return array( |
|
645 | + 'from' => $old_status, |
|
646 | + 'to' => $status, |
|
647 | + ); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | /** |
651 | - * Set plugin version when the item was created. |
|
652 | - * |
|
653 | - * @since 1.0.19 |
|
654 | - */ |
|
655 | - public function set_version( $value ) { |
|
656 | - $this->set_prop( 'version', $value ); |
|
651 | + * Set plugin version when the item was created. |
|
652 | + * |
|
653 | + * @since 1.0.19 |
|
654 | + */ |
|
655 | + public function set_version( $value ) { |
|
656 | + $this->set_prop( 'version', $value ); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
660 | - * Set date when the item was created. |
|
661 | - * |
|
662 | - * @since 1.0.19 |
|
663 | - * @param string $value Value to set. |
|
660 | + * Set date when the item was created. |
|
661 | + * |
|
662 | + * @since 1.0.19 |
|
663 | + * @param string $value Value to set. |
|
664 | 664 | * @return bool Whether or not the date was set. |
665 | - */ |
|
666 | - public function set_date_created( $value ) { |
|
665 | + */ |
|
666 | + public function set_date_created( $value ) { |
|
667 | 667 | $date = strtotime( $value ); |
668 | 668 | |
669 | 669 | if ( $date ) { |
@@ -676,13 +676,13 @@ discard block |
||
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
679 | - * Set date when the item was last modified. |
|
680 | - * |
|
681 | - * @since 1.0.19 |
|
682 | - * @param string $value Value to set. |
|
679 | + * Set date when the item was last modified. |
|
680 | + * |
|
681 | + * @since 1.0.19 |
|
682 | + * @param string $value Value to set. |
|
683 | 683 | * @return bool Whether or not the date was set. |
684 | - */ |
|
685 | - public function set_date_modified( $value ) { |
|
684 | + */ |
|
685 | + public function set_date_modified( $value ) { |
|
686 | 686 | $date = strtotime( $value ); |
687 | 687 | |
688 | 688 | if ( $date ) { |
@@ -695,105 +695,105 @@ discard block |
||
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
698 | - * Set the item name. |
|
699 | - * |
|
700 | - * @since 1.0.19 |
|
701 | - * @param string $value New name. |
|
702 | - */ |
|
703 | - public function set_name( $value ) { |
|
698 | + * Set the item name. |
|
699 | + * |
|
700 | + * @since 1.0.19 |
|
701 | + * @param string $value New name. |
|
702 | + */ |
|
703 | + public function set_name( $value ) { |
|
704 | 704 | $name = sanitize_text_field( $value ); |
705 | - $this->set_prop( 'name', $name ); |
|
705 | + $this->set_prop( 'name', $name ); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
709 | - * Alias of self::set_name(). |
|
710 | - * |
|
711 | - * @since 1.0.19 |
|
712 | - * @param string $value New name. |
|
713 | - */ |
|
714 | - public function set_title( $value ) { |
|
715 | - $this->set_name( $value ); |
|
709 | + * Alias of self::set_name(). |
|
710 | + * |
|
711 | + * @since 1.0.19 |
|
712 | + * @param string $value New name. |
|
713 | + */ |
|
714 | + public function set_title( $value ) { |
|
715 | + $this->set_name( $value ); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
719 | - * Set the item description. |
|
720 | - * |
|
721 | - * @since 1.0.19 |
|
722 | - * @param string $value New description. |
|
723 | - */ |
|
724 | - public function set_description( $value ) { |
|
719 | + * Set the item description. |
|
720 | + * |
|
721 | + * @since 1.0.19 |
|
722 | + * @param string $value New description. |
|
723 | + */ |
|
724 | + public function set_description( $value ) { |
|
725 | 725 | $description = wp_kses_post( $value ); |
726 | - return $this->set_prop( 'description', $description ); |
|
726 | + return $this->set_prop( 'description', $description ); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | /** |
730 | - * Alias of self::set_description(). |
|
731 | - * |
|
732 | - * @since 1.0.19 |
|
733 | - * @param string $value New description. |
|
734 | - */ |
|
735 | - public function set_excerpt( $value ) { |
|
736 | - $this->set_description( $value ); |
|
730 | + * Alias of self::set_description(). |
|
731 | + * |
|
732 | + * @since 1.0.19 |
|
733 | + * @param string $value New description. |
|
734 | + */ |
|
735 | + public function set_excerpt( $value ) { |
|
736 | + $this->set_description( $value ); |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
740 | - * Alias of self::set_description(). |
|
741 | - * |
|
742 | - * @since 1.0.19 |
|
743 | - * @param string $value New description. |
|
744 | - */ |
|
745 | - public function set_summary( $value ) { |
|
746 | - $this->set_description( $value ); |
|
740 | + * Alias of self::set_description(). |
|
741 | + * |
|
742 | + * @since 1.0.19 |
|
743 | + * @param string $value New description. |
|
744 | + */ |
|
745 | + public function set_summary( $value ) { |
|
746 | + $this->set_description( $value ); |
|
747 | 747 | } |
748 | 748 | |
749 | 749 | /** |
750 | - * Set the owner of the item. |
|
751 | - * |
|
752 | - * @since 1.0.19 |
|
753 | - * @param int $value New author. |
|
754 | - */ |
|
755 | - public function set_author( $value ) { |
|
756 | - $this->set_prop( 'author', (int) $value ); |
|
750 | + * Set the owner of the item. |
|
751 | + * |
|
752 | + * @since 1.0.19 |
|
753 | + * @param int $value New author. |
|
754 | + */ |
|
755 | + public function set_author( $value ) { |
|
756 | + $this->set_prop( 'author', (int) $value ); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | /** |
760 | - * Set the price of the item. |
|
761 | - * |
|
762 | - * @since 1.0.19 |
|
763 | - * @param float $value New price. |
|
764 | - */ |
|
765 | - public function set_price( $value ) { |
|
760 | + * Set the price of the item. |
|
761 | + * |
|
762 | + * @since 1.0.19 |
|
763 | + * @param float $value New price. |
|
764 | + */ |
|
765 | + public function set_price( $value ) { |
|
766 | 766 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
767 | 767 | } |
768 | 768 | |
769 | 769 | /** |
770 | - * Set the VAT rule of the item. |
|
771 | - * |
|
772 | - * @since 1.0.19 |
|
773 | - * @param string $value new rule. |
|
774 | - */ |
|
775 | - public function set_vat_rule( $value ) { |
|
770 | + * Set the VAT rule of the item. |
|
771 | + * |
|
772 | + * @since 1.0.19 |
|
773 | + * @param string $value new rule. |
|
774 | + */ |
|
775 | + public function set_vat_rule( $value ) { |
|
776 | 776 | $this->set_prop( 'vat_rule', $value ); |
777 | 777 | } |
778 | 778 | |
779 | 779 | /** |
780 | - * Set the VAT class of the item. |
|
781 | - * |
|
782 | - * @since 1.0.19 |
|
783 | - * @param string $value new class. |
|
784 | - */ |
|
785 | - public function set_vat_class( $value ) { |
|
780 | + * Set the VAT class of the item. |
|
781 | + * |
|
782 | + * @since 1.0.19 |
|
783 | + * @param string $value new class. |
|
784 | + */ |
|
785 | + public function set_vat_class( $value ) { |
|
786 | 786 | $this->set_prop( 'vat_class', $value ); |
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
790 | - * Set the type of the item. |
|
791 | - * |
|
792 | - * @since 1.0.19 |
|
793 | - * @param string $value new item type. |
|
794 | - * @return string |
|
795 | - */ |
|
796 | - public function set_type( $value ) { |
|
790 | + * Set the type of the item. |
|
791 | + * |
|
792 | + * @since 1.0.19 |
|
793 | + * @param string $value new item type. |
|
794 | + * @return string |
|
795 | + */ |
|
796 | + public function set_type( $value ) { |
|
797 | 797 | |
798 | 798 | if ( empty( $value ) ) { |
799 | 799 | $value = 'custom'; |
@@ -803,134 +803,134 @@ discard block |
||
803 | 803 | } |
804 | 804 | |
805 | 805 | /** |
806 | - * Set the custom id of the item. |
|
807 | - * |
|
808 | - * @since 1.0.19 |
|
809 | - * @param string $value new custom id. |
|
810 | - */ |
|
811 | - public function set_custom_id( $value ) { |
|
806 | + * Set the custom id of the item. |
|
807 | + * |
|
808 | + * @since 1.0.19 |
|
809 | + * @param string $value new custom id. |
|
810 | + */ |
|
811 | + public function set_custom_id( $value ) { |
|
812 | 812 | $this->set_prop( 'custom_id', $value ); |
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
816 | - * Set the custom name of the item. |
|
817 | - * |
|
818 | - * @since 1.0.19 |
|
819 | - * @param string $value new custom name. |
|
820 | - */ |
|
821 | - public function set_custom_name( $value ) { |
|
816 | + * Set the custom name of the item. |
|
817 | + * |
|
818 | + * @since 1.0.19 |
|
819 | + * @param string $value new custom name. |
|
820 | + */ |
|
821 | + public function set_custom_name( $value ) { |
|
822 | 822 | $this->set_prop( 'custom_name', $value ); |
823 | 823 | } |
824 | 824 | |
825 | 825 | /** |
826 | - * Set the custom singular name of the item. |
|
827 | - * |
|
828 | - * @since 1.0.19 |
|
829 | - * @param string $value new custom singular name. |
|
830 | - */ |
|
831 | - public function set_custom_singular_name( $value ) { |
|
826 | + * Set the custom singular name of the item. |
|
827 | + * |
|
828 | + * @since 1.0.19 |
|
829 | + * @param string $value new custom singular name. |
|
830 | + */ |
|
831 | + public function set_custom_singular_name( $value ) { |
|
832 | 832 | $this->set_prop( 'custom_singular_name', $value ); |
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
836 | - * Sets if an item is editable.. |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
839 | - * @param int|bool $value whether or not the item is editable. |
|
840 | - */ |
|
841 | - public function set_is_editable( $value ) { |
|
842 | - if ( is_numeric( $value ) ) { |
|
843 | - $this->set_prop( 'is_editable', (int) $value ); |
|
844 | - } |
|
836 | + * Sets if an item is editable.. |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | + * @param int|bool $value whether or not the item is editable. |
|
840 | + */ |
|
841 | + public function set_is_editable( $value ) { |
|
842 | + if ( is_numeric( $value ) ) { |
|
843 | + $this->set_prop( 'is_editable', (int) $value ); |
|
844 | + } |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | /** |
848 | - * Sets if dynamic pricing is enabled. |
|
849 | - * |
|
850 | - * @since 1.0.19 |
|
851 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
852 | - */ |
|
853 | - public function set_is_dynamic_pricing( $value ) { |
|
848 | + * Sets if dynamic pricing is enabled. |
|
849 | + * |
|
850 | + * @since 1.0.19 |
|
851 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
852 | + */ |
|
853 | + public function set_is_dynamic_pricing( $value ) { |
|
854 | 854 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
855 | 855 | } |
856 | 856 | |
857 | 857 | /** |
858 | - * Sets the minimum price if dynamic pricing is enabled. |
|
859 | - * |
|
860 | - * @since 1.0.19 |
|
861 | - * @param float $value minimum price. |
|
862 | - */ |
|
863 | - public function set_minimum_price( $value ) { |
|
858 | + * Sets the minimum price if dynamic pricing is enabled. |
|
859 | + * |
|
860 | + * @since 1.0.19 |
|
861 | + * @param float $value minimum price. |
|
862 | + */ |
|
863 | + public function set_minimum_price( $value ) { |
|
864 | 864 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
865 | 865 | } |
866 | 866 | |
867 | 867 | /** |
868 | - * Sets if this is a recurring item. |
|
869 | - * |
|
870 | - * @since 1.0.19 |
|
871 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
872 | - */ |
|
873 | - public function set_is_recurring( $value ) { |
|
868 | + * Sets if this is a recurring item. |
|
869 | + * |
|
870 | + * @since 1.0.19 |
|
871 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
872 | + */ |
|
873 | + public function set_is_recurring( $value ) { |
|
874 | 874 | $this->set_prop( 'is_recurring', (int) $value ); |
875 | 875 | } |
876 | 876 | |
877 | 877 | /** |
878 | - * Set the recurring period. |
|
879 | - * |
|
880 | - * @since 1.0.19 |
|
881 | - * @param string $value new period. |
|
882 | - */ |
|
883 | - public function set_recurring_period( $value ) { |
|
878 | + * Set the recurring period. |
|
879 | + * |
|
880 | + * @since 1.0.19 |
|
881 | + * @param string $value new period. |
|
882 | + */ |
|
883 | + public function set_recurring_period( $value ) { |
|
884 | 884 | $this->set_prop( 'recurring_period', $value ); |
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
888 | - * Set the recurring interval. |
|
889 | - * |
|
890 | - * @since 1.0.19 |
|
891 | - * @param int $value recurring interval. |
|
892 | - */ |
|
893 | - public function set_recurring_interval( $value ) { |
|
888 | + * Set the recurring interval. |
|
889 | + * |
|
890 | + * @since 1.0.19 |
|
891 | + * @param int $value recurring interval. |
|
892 | + */ |
|
893 | + public function set_recurring_interval( $value ) { |
|
894 | 894 | return $this->set_prop( 'recurring_interval', (int) $value ); |
895 | 895 | } |
896 | 896 | |
897 | 897 | /** |
898 | - * Get the recurring limit. |
|
899 | - * @since 1.0.19 |
|
900 | - * @param int $value The recurring limit. |
|
901 | - * @return int |
|
902 | - */ |
|
903 | - public function set_recurring_limit( $value ) { |
|
898 | + * Get the recurring limit. |
|
899 | + * @since 1.0.19 |
|
900 | + * @param int $value The recurring limit. |
|
901 | + * @return int |
|
902 | + */ |
|
903 | + public function set_recurring_limit( $value ) { |
|
904 | 904 | $this->set_prop( 'recurring_limit', (int) $value ); |
905 | 905 | } |
906 | 906 | |
907 | 907 | /** |
908 | - * Checks if we have a free trial. |
|
909 | - * |
|
910 | - * @since 1.0.19 |
|
911 | - * @param int|bool $value whether or not it has a free trial. |
|
912 | - */ |
|
913 | - public function set_is_free_trial( $value ) { |
|
908 | + * Checks if we have a free trial. |
|
909 | + * |
|
910 | + * @since 1.0.19 |
|
911 | + * @param int|bool $value whether or not it has a free trial. |
|
912 | + */ |
|
913 | + public function set_is_free_trial( $value ) { |
|
914 | 914 | $this->set_prop( 'is_free_trial', (int) $value ); |
915 | 915 | } |
916 | 916 | |
917 | 917 | /** |
918 | - * Set the trial period. |
|
919 | - * |
|
920 | - * @since 1.0.19 |
|
921 | - * @param string $value trial period. |
|
922 | - */ |
|
923 | - public function set_trial_period( $value ) { |
|
918 | + * Set the trial period. |
|
919 | + * |
|
920 | + * @since 1.0.19 |
|
921 | + * @param string $value trial period. |
|
922 | + */ |
|
923 | + public function set_trial_period( $value ) { |
|
924 | 924 | $this->set_prop( 'trial_period', $value ); |
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
928 | - * Set the trial interval. |
|
929 | - * |
|
930 | - * @since 1.0.19 |
|
931 | - * @param int $value trial interval. |
|
932 | - */ |
|
933 | - public function set_trial_interval( $value ) { |
|
928 | + * Set the trial interval. |
|
929 | + * |
|
930 | + * @since 1.0.19 |
|
931 | + * @param int $value trial interval. |
|
932 | + */ |
|
933 | + public function set_trial_interval( $value ) { |
|
934 | 934 | $this->set_prop( 'trial_interval', $value ); |
935 | 935 | } |
936 | 936 | |
@@ -938,17 +938,17 @@ discard block |
||
938 | 938 | * Create an item. For backwards compatibilty. |
939 | 939 | * |
940 | 940 | * @deprecated |
941 | - * @return int item id |
|
941 | + * @return int item id |
|
942 | 942 | */ |
943 | 943 | public function create( $data = array() ) { |
944 | 944 | |
945 | - // Set the properties. |
|
946 | - if ( is_array( $data ) ) { |
|
947 | - $this->set_props( $data ); |
|
948 | - } |
|
945 | + // Set the properties. |
|
946 | + if ( is_array( $data ) ) { |
|
947 | + $this->set_props( $data ); |
|
948 | + } |
|
949 | 949 | |
950 | - // Save the item. |
|
951 | - return $this->save(); |
|
950 | + // Save the item. |
|
951 | + return $this->save(); |
|
952 | 952 | |
953 | 953 | } |
954 | 954 | |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | * Updates an item. For backwards compatibilty. |
957 | 957 | * |
958 | 958 | * @deprecated |
959 | - * @return int item id |
|
959 | + * @return int item id |
|
960 | 960 | */ |
961 | 961 | public function update( $data = array() ) { |
962 | 962 | return $this->create( $data ); |
@@ -972,84 +972,84 @@ discard block |
||
972 | 972 | */ |
973 | 973 | |
974 | 974 | /** |
975 | - * Checks whether the item has enabled dynamic pricing. |
|
976 | - * |
|
977 | - * @since 1.0.19 |
|
978 | - * @return bool |
|
979 | - */ |
|
980 | - public function user_can_set_their_price() { |
|
975 | + * Checks whether the item has enabled dynamic pricing. |
|
976 | + * |
|
977 | + * @since 1.0.19 |
|
978 | + * @return bool |
|
979 | + */ |
|
980 | + public function user_can_set_their_price() { |
|
981 | 981 | return (bool) $this->get_is_dynamic_pricing(); |
982 | - } |
|
982 | + } |
|
983 | 983 | |
984 | - /** |
|
985 | - * Checks whether the item is recurring. |
|
986 | - * |
|
987 | - * @since 1.0.19 |
|
988 | - * @return bool |
|
989 | - */ |
|
990 | - public function is_recurring() { |
|
984 | + /** |
|
985 | + * Checks whether the item is recurring. |
|
986 | + * |
|
987 | + * @since 1.0.19 |
|
988 | + * @return bool |
|
989 | + */ |
|
990 | + public function is_recurring() { |
|
991 | 991 | return (bool) $this->get_is_recurring(); |
992 | 992 | } |
993 | 993 | |
994 | 994 | /** |
995 | - * Checks whether the item has a free trial. |
|
996 | - * |
|
997 | - * @since 1.0.19 |
|
998 | - * @return bool |
|
999 | - */ |
|
995 | + * Checks whether the item has a free trial. |
|
996 | + * |
|
997 | + * @since 1.0.19 |
|
998 | + * @return bool |
|
999 | + */ |
|
1000 | 1000 | public function has_free_trial() { |
1001 | 1001 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1002 | 1002 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
1003 | 1003 | } |
1004 | 1004 | |
1005 | 1005 | /** |
1006 | - * Checks whether the item is free. |
|
1007 | - * |
|
1008 | - * @since 1.0.19 |
|
1009 | - * @return bool |
|
1010 | - */ |
|
1006 | + * Checks whether the item is free. |
|
1007 | + * |
|
1008 | + * @since 1.0.19 |
|
1009 | + * @return bool |
|
1010 | + */ |
|
1011 | 1011 | public function is_free() { |
1012 | 1012 | $is_free = $this->get_price() == 0; |
1013 | 1013 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | /** |
1017 | - * Checks the item status against a passed in status. |
|
1018 | - * |
|
1019 | - * @param array|string $status Status to check. |
|
1020 | - * @return bool |
|
1021 | - */ |
|
1022 | - public function has_status( $status ) { |
|
1023 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1024 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1017 | + * Checks the item status against a passed in status. |
|
1018 | + * |
|
1019 | + * @param array|string $status Status to check. |
|
1020 | + * @return bool |
|
1021 | + */ |
|
1022 | + public function has_status( $status ) { |
|
1023 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1024 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | /** |
1028 | - * Checks the item type against a passed in types. |
|
1029 | - * |
|
1030 | - * @param array|string $type Type to check. |
|
1031 | - * @return bool |
|
1032 | - */ |
|
1033 | - public function is_type( $type ) { |
|
1034 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1035 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1036 | - } |
|
1028 | + * Checks the item type against a passed in types. |
|
1029 | + * |
|
1030 | + * @param array|string $type Type to check. |
|
1031 | + * @return bool |
|
1032 | + */ |
|
1033 | + public function is_type( $type ) { |
|
1034 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1035 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1036 | + } |
|
1037 | 1037 | |
1038 | 1038 | /** |
1039 | - * Checks whether the item is editable. |
|
1040 | - * |
|
1041 | - * @since 1.0.19 |
|
1042 | - * @return bool |
|
1043 | - */ |
|
1039 | + * Checks whether the item is editable. |
|
1040 | + * |
|
1041 | + * @since 1.0.19 |
|
1042 | + * @return bool |
|
1043 | + */ |
|
1044 | 1044 | public function is_editable() { |
1045 | 1045 | $is_editable = $this->get_is_editable(); |
1046 | 1046 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
1047 | - } |
|
1047 | + } |
|
1048 | 1048 | |
1049 | - /** |
|
1050 | - * Returns an array of cart fees. |
|
1051 | - */ |
|
1052 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1049 | + /** |
|
1050 | + * Returns an array of cart fees. |
|
1051 | + */ |
|
1052 | + public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1053 | 1053 | global $wpi_session; |
1054 | 1054 | |
1055 | 1055 | $fees = $wpi_session->get( 'wpi_cart_fees' ); |
@@ -1093,11 +1093,11 @@ discard block |
||
1093 | 1093 | } |
1094 | 1094 | |
1095 | 1095 | /** |
1096 | - * Checks whether the item is purchasable. |
|
1097 | - * |
|
1098 | - * @since 1.0.19 |
|
1099 | - * @return bool |
|
1100 | - */ |
|
1096 | + * Checks whether the item is purchasable. |
|
1097 | + * |
|
1098 | + * @since 1.0.19 |
|
1099 | + * @return bool |
|
1100 | + */ |
|
1101 | 1101 | public function can_purchase() { |
1102 | 1102 | $can_purchase = null !== $this->get_id(); |
1103 | 1103 | |
@@ -1109,11 +1109,11 @@ discard block |
||
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | /** |
1112 | - * Checks whether the item supports dynamic pricing. |
|
1113 | - * |
|
1114 | - * @since 1.0.19 |
|
1115 | - * @return bool |
|
1116 | - */ |
|
1112 | + * Checks whether the item supports dynamic pricing. |
|
1113 | + * |
|
1114 | + * @since 1.0.19 |
|
1115 | + * @return bool |
|
1116 | + */ |
|
1117 | 1117 | public function supports_dynamic_pricing() { |
1118 | 1118 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
1119 | 1119 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -78,26 +78,26 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @param int|object|WPInv_Item|WP_Post $item Item to read. |
80 | 80 | */ |
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
81 | + public function __construct($item = 0) { |
|
82 | + parent::__construct($item); |
|
83 | 83 | |
84 | - if ( is_numeric( $item ) && $item > 0 ) { |
|
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 ); |
|
84 | + if (is_numeric($item) && $item > 0) { |
|
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 | 90 | } else { |
91 | - $this->set_object_read( true ); |
|
91 | + $this->set_object_read(true); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | // Load the datastore. |
95 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
95 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
96 | 96 | |
97 | - if ( $this->get_id() > 0 ) { |
|
98 | - $this->post = get_post( $this->get_id() ); |
|
97 | + if ($this->get_id() > 0) { |
|
98 | + $this->post = get_post($this->get_id()); |
|
99 | 99 | $this->ID = $this->get_id(); |
100 | - $this->data_store->read( $this ); |
|
100 | + $this->data_store->read($this); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * @param string $context View or edit context. |
125 | 125 | * @return int |
126 | 126 | */ |
127 | - public function get_parent_id( $context = 'view' ) { |
|
128 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
127 | + public function get_parent_id($context = 'view') { |
|
128 | + return (int) $this->get_prop('parent_id', $context); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | * @param string $context View or edit context. |
136 | 136 | * @return string |
137 | 137 | */ |
138 | - public function get_status( $context = 'view' ) { |
|
139 | - return $this->get_prop( 'status', $context ); |
|
138 | + public function get_status($context = 'view') { |
|
139 | + return $this->get_prop('status', $context); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @param string $context View or edit context. |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - public function get_version( $context = 'view' ) { |
|
150 | - return $this->get_prop( 'version', $context ); |
|
149 | + public function get_version($context = 'view') { |
|
150 | + return $this->get_prop('version', $context); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -157,8 +157,8 @@ discard block |
||
157 | 157 | * @param string $context View or edit context. |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - public function get_date_created( $context = 'view' ) { |
|
161 | - return $this->get_prop( 'date_created', $context ); |
|
160 | + public function get_date_created($context = 'view') { |
|
161 | + return $this->get_prop('date_created', $context); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | * @param string $context View or edit context. |
169 | 169 | * @return string |
170 | 170 | */ |
171 | - public function get_date_created_gmt( $context = 'view' ) { |
|
172 | - $date = $this->get_date_created( $context ); |
|
171 | + public function get_date_created_gmt($context = 'view') { |
|
172 | + $date = $this->get_date_created($context); |
|
173 | 173 | |
174 | - if ( $date ) { |
|
175 | - $date = get_gmt_from_date( $date ); |
|
174 | + if ($date) { |
|
175 | + $date = get_gmt_from_date($date); |
|
176 | 176 | } |
177 | 177 | return $date; |
178 | 178 | } |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | * @param string $context View or edit context. |
185 | 185 | * @return string |
186 | 186 | */ |
187 | - public function get_date_modified( $context = 'view' ) { |
|
188 | - return $this->get_prop( 'date_modified', $context ); |
|
187 | + public function get_date_modified($context = 'view') { |
|
188 | + return $this->get_prop('date_modified', $context); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | * @param string $context View or edit context. |
196 | 196 | * @return string |
197 | 197 | */ |
198 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
199 | - $date = $this->get_date_modified( $context ); |
|
198 | + public function get_date_modified_gmt($context = 'view') { |
|
199 | + $date = $this->get_date_modified($context); |
|
200 | 200 | |
201 | - if ( $date ) { |
|
202 | - $date = get_gmt_from_date( $date ); |
|
201 | + if ($date) { |
|
202 | + $date = get_gmt_from_date($date); |
|
203 | 203 | } |
204 | 204 | return $date; |
205 | 205 | } |
@@ -211,8 +211,8 @@ discard block |
||
211 | 211 | * @param string $context View or edit context. |
212 | 212 | * @return string |
213 | 213 | */ |
214 | - public function get_name( $context = 'view' ) { |
|
215 | - return $this->get_prop( 'name', $context ); |
|
214 | + public function get_name($context = 'view') { |
|
215 | + return $this->get_prop('name', $context); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | * @param string $context View or edit context. |
223 | 223 | * @return string |
224 | 224 | */ |
225 | - public function get_title( $context = 'view' ) { |
|
226 | - return $this->get_name( $context ); |
|
225 | + public function get_title($context = 'view') { |
|
226 | + return $this->get_name($context); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * @param string $context View or edit context. |
234 | 234 | * @return string |
235 | 235 | */ |
236 | - public function get_description( $context = 'view' ) { |
|
237 | - return $this->get_prop( 'description', $context ); |
|
236 | + public function get_description($context = 'view') { |
|
237 | + return $this->get_prop('description', $context); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -244,8 +244,8 @@ discard block |
||
244 | 244 | * @param string $context View or edit context. |
245 | 245 | * @return string |
246 | 246 | */ |
247 | - public function get_excerpt( $context = 'view' ) { |
|
248 | - return $this->get_description( $context ); |
|
247 | + public function get_excerpt($context = 'view') { |
|
248 | + return $this->get_description($context); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | * @param string $context View or edit context. |
256 | 256 | * @return string |
257 | 257 | */ |
258 | - public function get_summary( $context = 'view' ) { |
|
259 | - return $this->get_description( $context ); |
|
258 | + public function get_summary($context = 'view') { |
|
259 | + return $this->get_description($context); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | * @param string $context View or edit context. |
267 | 267 | * @return string |
268 | 268 | */ |
269 | - public function get_author( $context = 'view' ) { |
|
270 | - return (int) $this->get_prop( 'author', $context ); |
|
269 | + public function get_author($context = 'view') { |
|
270 | + return (int) $this->get_prop('author', $context); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | * @param string $context View or edit context. |
278 | 278 | * @return float |
279 | 279 | */ |
280 | - public function get_price( $context = 'view' ) { |
|
281 | - return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
|
280 | + public function get_price($context = 'view') { |
|
281 | + return wpinv_sanitize_amount($this->get_prop('price', $context)); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -288,15 +288,15 @@ discard block |
||
288 | 288 | * @param string $context View or edit context. |
289 | 289 | * @return float |
290 | 290 | */ |
291 | - public function get_initial_price( $context = 'view' ) { |
|
291 | + public function get_initial_price($context = 'view') { |
|
292 | 292 | |
293 | - $price = $this->get_price( $context ); |
|
293 | + $price = $this->get_price($context); |
|
294 | 294 | |
295 | - if ( $this->has_free_trial() ) { |
|
296 | - $price = wpinv_sanitize_amount( 0 ); |
|
295 | + if ($this->has_free_trial()) { |
|
296 | + $price = wpinv_sanitize_amount(0); |
|
297 | 297 | } |
298 | 298 | |
299 | - return apply_filters( 'wpinv_get_initial_item_price', $price, $this ); |
|
299 | + return apply_filters('wpinv_get_initial_item_price', $price, $this); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | * @return string |
308 | 308 | */ |
309 | 309 | public function get_the_price() { |
310 | - return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
|
310 | + return wpinv_price(wpinv_format_amount($this->get_price())); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | * @return string |
319 | 319 | */ |
320 | 320 | public function get_the_initial_price() { |
321 | - return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
|
321 | + return wpinv_price(wpinv_format_amount($this->get_initial_price())); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -328,8 +328,8 @@ discard block |
||
328 | 328 | * @param string $context View or edit context. |
329 | 329 | * @return string |
330 | 330 | */ |
331 | - public function get_vat_rule( $context = 'view' ) { |
|
332 | - return $this->get_prop( 'vat_rule', $context ); |
|
331 | + public function get_vat_rule($context = 'view') { |
|
332 | + return $this->get_prop('vat_rule', $context); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | * @param string $context View or edit context. |
340 | 340 | * @return string |
341 | 341 | */ |
342 | - public function get_vat_class( $context = 'view' ) { |
|
343 | - return $this->get_prop( 'vat_class', $context ); |
|
342 | + public function get_vat_class($context = 'view') { |
|
343 | + return $this->get_prop('vat_class', $context); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -350,8 +350,8 @@ discard block |
||
350 | 350 | * @param string $context View or edit context. |
351 | 351 | * @return string |
352 | 352 | */ |
353 | - public function get_type( $context = 'view' ) { |
|
354 | - return $this->get_prop( 'type', $context ); |
|
353 | + public function get_type($context = 'view') { |
|
354 | + return $this->get_prop('type', $context); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | * @param string $context View or edit context. |
362 | 362 | * @return string |
363 | 363 | */ |
364 | - public function get_custom_id( $context = 'view' ) { |
|
365 | - return $this->get_prop( 'custom_id', $context ); |
|
364 | + public function get_custom_id($context = 'view') { |
|
365 | + return $this->get_prop('custom_id', $context); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | * @param string $context View or edit context. |
373 | 373 | * @return string |
374 | 374 | */ |
375 | - public function get_custom_name( $context = 'view' ) { |
|
376 | - return $this->get_prop( 'custom_name', $context ); |
|
375 | + public function get_custom_name($context = 'view') { |
|
376 | + return $this->get_prop('custom_name', $context); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -383,8 +383,8 @@ discard block |
||
383 | 383 | * @param string $context View or edit context. |
384 | 384 | * @return string |
385 | 385 | */ |
386 | - public function get_custom_singular_name( $context = 'view' ) { |
|
387 | - return $this->get_prop( 'custom_singular_name', $context ); |
|
386 | + public function get_custom_singular_name($context = 'view') { |
|
387 | + return $this->get_prop('custom_singular_name', $context); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @param string $context View or edit context. |
395 | 395 | * @return int |
396 | 396 | */ |
397 | - public function get_is_editable( $context = 'view' ) { |
|
398 | - return (int) $this->get_prop( 'is_editable', $context ); |
|
397 | + public function get_is_editable($context = 'view') { |
|
398 | + return (int) $this->get_prop('is_editable', $context); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -405,8 +405,8 @@ discard block |
||
405 | 405 | * @param string $context View or edit context. |
406 | 406 | * @return int |
407 | 407 | */ |
408 | - public function get_editable( $context = 'view' ) { |
|
409 | - return $this->get_is_editable( $context ); |
|
408 | + public function get_editable($context = 'view') { |
|
409 | + return $this->get_is_editable($context); |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | * @param string $context View or edit context. |
417 | 417 | * @return int |
418 | 418 | */ |
419 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
420 | - return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
|
419 | + public function get_is_dynamic_pricing($context = 'view') { |
|
420 | + return (int) $this->get_prop('is_dynamic_pricing', $context); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | * @param string $context View or edit context. |
428 | 428 | * @return float |
429 | 429 | */ |
430 | - public function get_minimum_price( $context = 'view' ) { |
|
431 | - return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
|
430 | + public function get_minimum_price($context = 'view') { |
|
431 | + return wpinv_sanitize_amount($this->get_prop('minimum_price', $context)); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
@@ -438,8 +438,8 @@ discard block |
||
438 | 438 | * @param string $context View or edit context. |
439 | 439 | * @return int |
440 | 440 | */ |
441 | - public function get_is_recurring( $context = 'view' ) { |
|
442 | - return (int) $this->get_prop( 'is_recurring', $context ); |
|
441 | + public function get_is_recurring($context = 'view') { |
|
442 | + return (int) $this->get_prop('is_recurring', $context); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -449,9 +449,9 @@ discard block |
||
449 | 449 | * @param string $context View or edit context. |
450 | 450 | * @return float |
451 | 451 | */ |
452 | - public function get_recurring_price( $context = 'view' ) { |
|
453 | - $price = $this->get_price( $context ); |
|
454 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
|
452 | + public function get_recurring_price($context = 'view') { |
|
453 | + $price = $this->get_price($context); |
|
454 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID)); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -472,15 +472,15 @@ discard block |
||
472 | 472 | $period = $this->get_recurring_period(); |
473 | 473 | $interval = $this->get_recurring_interval(); |
474 | 474 | |
475 | - if ( $this->has_free_trial() ) { |
|
475 | + if ($this->has_free_trial()) { |
|
476 | 476 | $period = $this->get_trial_period(); |
477 | 477 | $interval = $this->get_trial_interval(); |
478 | 478 | } |
479 | 479 | |
480 | - $period = $periods[ $period ]; |
|
481 | - $interval = empty( $interval ) ? 1 : $interval; |
|
482 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
483 | - return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
|
480 | + $period = $periods[$period]; |
|
481 | + $interval = empty($interval) ? 1 : $interval; |
|
482 | + $next_renewal = strtotime("+$interval $period", current_time('timestamp')); |
|
483 | + return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -490,14 +490,14 @@ discard block |
||
490 | 490 | * @param bool $full Return abbreviation or in full. |
491 | 491 | * @return string |
492 | 492 | */ |
493 | - public function get_recurring_period( $full = false ) { |
|
494 | - $period = $this->get_prop( 'recurring_period', 'view' ); |
|
493 | + public function get_recurring_period($full = false) { |
|
494 | + $period = $this->get_prop('recurring_period', 'view'); |
|
495 | 495 | |
496 | - if ( $full && ! is_bool( $full ) ) { |
|
496 | + if ($full && !is_bool($full)) { |
|
497 | 497 | $full = false; |
498 | 498 | } |
499 | 499 | |
500 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
500 | + return getpaid_sanitize_recurring_period($period, $full); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
@@ -507,10 +507,10 @@ discard block |
||
507 | 507 | * @param string $context View or edit context. |
508 | 508 | * @return int |
509 | 509 | */ |
510 | - public function get_recurring_interval( $context = 'view' ) { |
|
511 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
510 | + public function get_recurring_interval($context = 'view') { |
|
511 | + $interval = absint($this->get_prop('recurring_interval', $context)); |
|
512 | 512 | |
513 | - if ( $interval < 1 ) { |
|
513 | + if ($interval < 1) { |
|
514 | 514 | $interval = 1; |
515 | 515 | } |
516 | 516 | |
@@ -524,8 +524,8 @@ discard block |
||
524 | 524 | * @param string $context View or edit context. |
525 | 525 | * @return int |
526 | 526 | */ |
527 | - public function get_recurring_limit( $context = 'view' ) { |
|
528 | - return (int) $this->get_prop( 'recurring_limit', $context ); |
|
527 | + public function get_recurring_limit($context = 'view') { |
|
528 | + return (int) $this->get_prop('recurring_limit', $context); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
@@ -535,8 +535,8 @@ discard block |
||
535 | 535 | * @param string $context View or edit context. |
536 | 536 | * @return int |
537 | 537 | */ |
538 | - public function get_is_free_trial( $context = 'view' ) { |
|
539 | - return (int) $this->get_prop( 'is_free_trial', $context ); |
|
538 | + public function get_is_free_trial($context = 'view') { |
|
539 | + return (int) $this->get_prop('is_free_trial', $context); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | /** |
@@ -546,8 +546,8 @@ discard block |
||
546 | 546 | * @param string $context View or edit context. |
547 | 547 | * @return int |
548 | 548 | */ |
549 | - public function get_free_trial( $context = 'view' ) { |
|
550 | - return $this->get_is_free_trial( $context ); |
|
549 | + public function get_free_trial($context = 'view') { |
|
550 | + return $this->get_is_free_trial($context); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -557,14 +557,14 @@ discard block |
||
557 | 557 | * @param bool $full Return abbreviation or in full. |
558 | 558 | * @return string |
559 | 559 | */ |
560 | - public function get_trial_period( $full = false ) { |
|
561 | - $period = $this->get_prop( 'trial_period', 'view' ); |
|
560 | + public function get_trial_period($full = false) { |
|
561 | + $period = $this->get_prop('trial_period', 'view'); |
|
562 | 562 | |
563 | - if ( $full && ! is_bool( $full ) ) { |
|
563 | + if ($full && !is_bool($full)) { |
|
564 | 564 | $full = false; |
565 | 565 | } |
566 | 566 | |
567 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
567 | + return getpaid_sanitize_recurring_period($period, $full); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
@@ -574,8 +574,8 @@ discard block |
||
574 | 574 | * @param string $context View or edit context. |
575 | 575 | * @return int |
576 | 576 | */ |
577 | - public function get_trial_interval( $context = 'view' ) { |
|
578 | - return (int) $this->get_prop( 'trial_interval', $context ); |
|
577 | + public function get_trial_interval($context = 'view') { |
|
578 | + return (int) $this->get_prop('trial_interval', $context); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
@@ -585,25 +585,25 @@ discard block |
||
585 | 585 | * @return string |
586 | 586 | */ |
587 | 587 | public function get_edit_url() { |
588 | - return get_edit_post_link( $this->get_id() ); |
|
588 | + return get_edit_post_link($this->get_id()); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | /** |
592 | 592 | * Margic method for retrieving a property. |
593 | 593 | */ |
594 | - public function __get( $key ) { |
|
594 | + public function __get($key) { |
|
595 | 595 | |
596 | 596 | // Check if we have a helper method for that. |
597 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
598 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
597 | + if (method_exists($this, 'get_' . $key)) { |
|
598 | + return call_user_func(array($this, 'get_' . $key)); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | // Check if the key is in the associated $post object. |
602 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
602 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
603 | 603 | return $this->post->$key; |
604 | 604 | } |
605 | 605 | |
606 | - return $this->get_prop( $key ); |
|
606 | + return $this->get_prop($key); |
|
607 | 607 | |
608 | 608 | } |
609 | 609 | |
@@ -622,11 +622,11 @@ discard block |
||
622 | 622 | * |
623 | 623 | * @since 1.0.19 |
624 | 624 | */ |
625 | - public function set_parent_id( $value ) { |
|
626 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
625 | + public function set_parent_id($value) { |
|
626 | + if ($value && ($value === $this->get_id() || !get_post($value))) { |
|
627 | 627 | return; |
628 | 628 | } |
629 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
629 | + $this->set_prop('parent_id', absint($value)); |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | /** |
@@ -636,10 +636,10 @@ discard block |
||
636 | 636 | * @param string $status New status. |
637 | 637 | * @return array details of change. |
638 | 638 | */ |
639 | - public function set_status( $status ) { |
|
639 | + public function set_status($status) { |
|
640 | 640 | $old_status = $this->get_status(); |
641 | 641 | |
642 | - $this->set_prop( 'status', $status ); |
|
642 | + $this->set_prop('status', $status); |
|
643 | 643 | |
644 | 644 | return array( |
645 | 645 | 'from' => $old_status, |
@@ -652,8 +652,8 @@ discard block |
||
652 | 652 | * |
653 | 653 | * @since 1.0.19 |
654 | 654 | */ |
655 | - public function set_version( $value ) { |
|
656 | - $this->set_prop( 'version', $value ); |
|
655 | + public function set_version($value) { |
|
656 | + $this->set_prop('version', $value); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
@@ -663,11 +663,11 @@ discard block |
||
663 | 663 | * @param string $value Value to set. |
664 | 664 | * @return bool Whether or not the date was set. |
665 | 665 | */ |
666 | - public function set_date_created( $value ) { |
|
667 | - $date = strtotime( $value ); |
|
666 | + public function set_date_created($value) { |
|
667 | + $date = strtotime($value); |
|
668 | 668 | |
669 | - if ( $date ) { |
|
670 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
669 | + if ($date) { |
|
670 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
671 | 671 | return true; |
672 | 672 | } |
673 | 673 | |
@@ -682,11 +682,11 @@ discard block |
||
682 | 682 | * @param string $value Value to set. |
683 | 683 | * @return bool Whether or not the date was set. |
684 | 684 | */ |
685 | - public function set_date_modified( $value ) { |
|
686 | - $date = strtotime( $value ); |
|
685 | + public function set_date_modified($value) { |
|
686 | + $date = strtotime($value); |
|
687 | 687 | |
688 | - if ( $date ) { |
|
689 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
688 | + if ($date) { |
|
689 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
690 | 690 | return true; |
691 | 691 | } |
692 | 692 | |
@@ -700,9 +700,9 @@ discard block |
||
700 | 700 | * @since 1.0.19 |
701 | 701 | * @param string $value New name. |
702 | 702 | */ |
703 | - public function set_name( $value ) { |
|
704 | - $name = sanitize_text_field( $value ); |
|
705 | - $this->set_prop( 'name', $name ); |
|
703 | + public function set_name($value) { |
|
704 | + $name = sanitize_text_field($value); |
|
705 | + $this->set_prop('name', $name); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
@@ -711,8 +711,8 @@ discard block |
||
711 | 711 | * @since 1.0.19 |
712 | 712 | * @param string $value New name. |
713 | 713 | */ |
714 | - public function set_title( $value ) { |
|
715 | - $this->set_name( $value ); |
|
714 | + public function set_title($value) { |
|
715 | + $this->set_name($value); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
@@ -721,9 +721,9 @@ discard block |
||
721 | 721 | * @since 1.0.19 |
722 | 722 | * @param string $value New description. |
723 | 723 | */ |
724 | - public function set_description( $value ) { |
|
725 | - $description = wp_kses_post( $value ); |
|
726 | - return $this->set_prop( 'description', $description ); |
|
724 | + public function set_description($value) { |
|
725 | + $description = wp_kses_post($value); |
|
726 | + return $this->set_prop('description', $description); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | /** |
@@ -732,8 +732,8 @@ discard block |
||
732 | 732 | * @since 1.0.19 |
733 | 733 | * @param string $value New description. |
734 | 734 | */ |
735 | - public function set_excerpt( $value ) { |
|
736 | - $this->set_description( $value ); |
|
735 | + public function set_excerpt($value) { |
|
736 | + $this->set_description($value); |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
@@ -742,8 +742,8 @@ discard block |
||
742 | 742 | * @since 1.0.19 |
743 | 743 | * @param string $value New description. |
744 | 744 | */ |
745 | - public function set_summary( $value ) { |
|
746 | - $this->set_description( $value ); |
|
745 | + public function set_summary($value) { |
|
746 | + $this->set_description($value); |
|
747 | 747 | } |
748 | 748 | |
749 | 749 | /** |
@@ -752,8 +752,8 @@ discard block |
||
752 | 752 | * @since 1.0.19 |
753 | 753 | * @param int $value New author. |
754 | 754 | */ |
755 | - public function set_author( $value ) { |
|
756 | - $this->set_prop( 'author', (int) $value ); |
|
755 | + public function set_author($value) { |
|
756 | + $this->set_prop('author', (int) $value); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | /** |
@@ -762,8 +762,8 @@ discard block |
||
762 | 762 | * @since 1.0.19 |
763 | 763 | * @param float $value New price. |
764 | 764 | */ |
765 | - public function set_price( $value ) { |
|
766 | - $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
|
765 | + public function set_price($value) { |
|
766 | + $this->set_prop('price', (float) wpinv_sanitize_amount($value)); |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | /** |
@@ -772,8 +772,8 @@ discard block |
||
772 | 772 | * @since 1.0.19 |
773 | 773 | * @param string $value new rule. |
774 | 774 | */ |
775 | - public function set_vat_rule( $value ) { |
|
776 | - $this->set_prop( 'vat_rule', $value ); |
|
775 | + public function set_vat_rule($value) { |
|
776 | + $this->set_prop('vat_rule', $value); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | /** |
@@ -782,8 +782,8 @@ discard block |
||
782 | 782 | * @since 1.0.19 |
783 | 783 | * @param string $value new class. |
784 | 784 | */ |
785 | - public function set_vat_class( $value ) { |
|
786 | - $this->set_prop( 'vat_class', $value ); |
|
785 | + public function set_vat_class($value) { |
|
786 | + $this->set_prop('vat_class', $value); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | /** |
@@ -793,13 +793,13 @@ discard block |
||
793 | 793 | * @param string $value new item type. |
794 | 794 | * @return string |
795 | 795 | */ |
796 | - public function set_type( $value ) { |
|
796 | + public function set_type($value) { |
|
797 | 797 | |
798 | - if ( empty( $value ) ) { |
|
798 | + if (empty($value)) { |
|
799 | 799 | $value = 'custom'; |
800 | 800 | } |
801 | 801 | |
802 | - $this->set_prop( 'type', $value ); |
|
802 | + $this->set_prop('type', $value); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | /** |
@@ -808,8 +808,8 @@ discard block |
||
808 | 808 | * @since 1.0.19 |
809 | 809 | * @param string $value new custom id. |
810 | 810 | */ |
811 | - public function set_custom_id( $value ) { |
|
812 | - $this->set_prop( 'custom_id', $value ); |
|
811 | + public function set_custom_id($value) { |
|
812 | + $this->set_prop('custom_id', $value); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
@@ -818,8 +818,8 @@ discard block |
||
818 | 818 | * @since 1.0.19 |
819 | 819 | * @param string $value new custom name. |
820 | 820 | */ |
821 | - public function set_custom_name( $value ) { |
|
822 | - $this->set_prop( 'custom_name', $value ); |
|
821 | + public function set_custom_name($value) { |
|
822 | + $this->set_prop('custom_name', $value); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | /** |
@@ -828,8 +828,8 @@ discard block |
||
828 | 828 | * @since 1.0.19 |
829 | 829 | * @param string $value new custom singular name. |
830 | 830 | */ |
831 | - public function set_custom_singular_name( $value ) { |
|
832 | - $this->set_prop( 'custom_singular_name', $value ); |
|
831 | + public function set_custom_singular_name($value) { |
|
832 | + $this->set_prop('custom_singular_name', $value); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
@@ -838,9 +838,9 @@ discard block |
||
838 | 838 | * @since 1.0.19 |
839 | 839 | * @param int|bool $value whether or not the item is editable. |
840 | 840 | */ |
841 | - public function set_is_editable( $value ) { |
|
842 | - if ( is_numeric( $value ) ) { |
|
843 | - $this->set_prop( 'is_editable', (int) $value ); |
|
841 | + public function set_is_editable($value) { |
|
842 | + if (is_numeric($value)) { |
|
843 | + $this->set_prop('is_editable', (int) $value); |
|
844 | 844 | } |
845 | 845 | } |
846 | 846 | |
@@ -850,8 +850,8 @@ discard block |
||
850 | 850 | * @since 1.0.19 |
851 | 851 | * @param int|bool $value whether or not dynamic pricing is allowed. |
852 | 852 | */ |
853 | - public function set_is_dynamic_pricing( $value ) { |
|
854 | - $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
|
853 | + public function set_is_dynamic_pricing($value) { |
|
854 | + $this->set_prop('is_dynamic_pricing', (int) $value); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | /** |
@@ -860,8 +860,8 @@ discard block |
||
860 | 860 | * @since 1.0.19 |
861 | 861 | * @param float $value minimum price. |
862 | 862 | */ |
863 | - public function set_minimum_price( $value ) { |
|
864 | - $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
|
863 | + public function set_minimum_price($value) { |
|
864 | + $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value)); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | /** |
@@ -870,8 +870,8 @@ discard block |
||
870 | 870 | * @since 1.0.19 |
871 | 871 | * @param int|bool $value whether or not dynamic pricing is allowed. |
872 | 872 | */ |
873 | - public function set_is_recurring( $value ) { |
|
874 | - $this->set_prop( 'is_recurring', (int) $value ); |
|
873 | + public function set_is_recurring($value) { |
|
874 | + $this->set_prop('is_recurring', (int) $value); |
|
875 | 875 | } |
876 | 876 | |
877 | 877 | /** |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * @since 1.0.19 |
881 | 881 | * @param string $value new period. |
882 | 882 | */ |
883 | - public function set_recurring_period( $value ) { |
|
884 | - $this->set_prop( 'recurring_period', $value ); |
|
883 | + public function set_recurring_period($value) { |
|
884 | + $this->set_prop('recurring_period', $value); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | /** |
@@ -890,8 +890,8 @@ discard block |
||
890 | 890 | * @since 1.0.19 |
891 | 891 | * @param int $value recurring interval. |
892 | 892 | */ |
893 | - public function set_recurring_interval( $value ) { |
|
894 | - return $this->set_prop( 'recurring_interval', (int) $value ); |
|
893 | + public function set_recurring_interval($value) { |
|
894 | + return $this->set_prop('recurring_interval', (int) $value); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | /** |
@@ -900,8 +900,8 @@ discard block |
||
900 | 900 | * @param int $value The recurring limit. |
901 | 901 | * @return int |
902 | 902 | */ |
903 | - public function set_recurring_limit( $value ) { |
|
904 | - $this->set_prop( 'recurring_limit', (int) $value ); |
|
903 | + public function set_recurring_limit($value) { |
|
904 | + $this->set_prop('recurring_limit', (int) $value); |
|
905 | 905 | } |
906 | 906 | |
907 | 907 | /** |
@@ -910,8 +910,8 @@ discard block |
||
910 | 910 | * @since 1.0.19 |
911 | 911 | * @param int|bool $value whether or not it has a free trial. |
912 | 912 | */ |
913 | - public function set_is_free_trial( $value ) { |
|
914 | - $this->set_prop( 'is_free_trial', (int) $value ); |
|
913 | + public function set_is_free_trial($value) { |
|
914 | + $this->set_prop('is_free_trial', (int) $value); |
|
915 | 915 | } |
916 | 916 | |
917 | 917 | /** |
@@ -920,8 +920,8 @@ discard block |
||
920 | 920 | * @since 1.0.19 |
921 | 921 | * @param string $value trial period. |
922 | 922 | */ |
923 | - public function set_trial_period( $value ) { |
|
924 | - $this->set_prop( 'trial_period', $value ); |
|
923 | + public function set_trial_period($value) { |
|
924 | + $this->set_prop('trial_period', $value); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
@@ -930,8 +930,8 @@ discard block |
||
930 | 930 | * @since 1.0.19 |
931 | 931 | * @param int $value trial interval. |
932 | 932 | */ |
933 | - public function set_trial_interval( $value ) { |
|
934 | - $this->set_prop( 'trial_interval', $value ); |
|
933 | + public function set_trial_interval($value) { |
|
934 | + $this->set_prop('trial_interval', $value); |
|
935 | 935 | } |
936 | 936 | |
937 | 937 | /** |
@@ -940,11 +940,11 @@ discard block |
||
940 | 940 | * @deprecated |
941 | 941 | * @return int item id |
942 | 942 | */ |
943 | - public function create( $data = array() ) { |
|
943 | + public function create($data = array()) { |
|
944 | 944 | |
945 | 945 | // Set the properties. |
946 | - if ( is_array( $data ) ) { |
|
947 | - $this->set_props( $data ); |
|
946 | + if (is_array($data)) { |
|
947 | + $this->set_props($data); |
|
948 | 948 | } |
949 | 949 | |
950 | 950 | // Save the item. |
@@ -958,8 +958,8 @@ discard block |
||
958 | 958 | * @deprecated |
959 | 959 | * @return int item id |
960 | 960 | */ |
961 | - public function update( $data = array() ) { |
|
962 | - return $this->create( $data ); |
|
961 | + public function update($data = array()) { |
|
962 | + return $this->create($data); |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | /* |
@@ -999,7 +999,7 @@ discard block |
||
999 | 999 | */ |
1000 | 1000 | public function has_free_trial() { |
1001 | 1001 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1002 | - return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
|
1002 | + return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this); |
|
1003 | 1003 | } |
1004 | 1004 | |
1005 | 1005 | /** |
@@ -1009,8 +1009,8 @@ discard block |
||
1009 | 1009 | * @return bool |
1010 | 1010 | */ |
1011 | 1011 | public function is_free() { |
1012 | - $is_free = $this->get_price() == 0; |
|
1013 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
|
1012 | + $is_free = $this->get_price() == 0; |
|
1013 | + return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this); |
|
1014 | 1014 | } |
1015 | 1015 | |
1016 | 1016 | /** |
@@ -1019,9 +1019,9 @@ discard block |
||
1019 | 1019 | * @param array|string $status Status to check. |
1020 | 1020 | * @return bool |
1021 | 1021 | */ |
1022 | - public function has_status( $status ) { |
|
1023 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1024 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1022 | + public function has_status($status) { |
|
1023 | + $has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status; |
|
1024 | + return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status); |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | /** |
@@ -1030,9 +1030,9 @@ discard block |
||
1030 | 1030 | * @param array|string $type Type to check. |
1031 | 1031 | * @return bool |
1032 | 1032 | */ |
1033 | - public function is_type( $type ) { |
|
1034 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1035 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1033 | + public function is_type($type) { |
|
1034 | + $is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type; |
|
1035 | + return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type); |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | 1038 | /** |
@@ -1043,53 +1043,53 @@ discard block |
||
1043 | 1043 | */ |
1044 | 1044 | public function is_editable() { |
1045 | 1045 | $is_editable = $this->get_is_editable(); |
1046 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
|
1046 | + return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this); |
|
1047 | 1047 | } |
1048 | 1048 | |
1049 | 1049 | /** |
1050 | 1050 | * Returns an array of cart fees. |
1051 | 1051 | */ |
1052 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1052 | + public function get_fees($type = 'fee', $item_id = 0) { |
|
1053 | 1053 | global $wpi_session; |
1054 | 1054 | |
1055 | - $fees = $wpi_session->get( 'wpi_cart_fees' ); |
|
1055 | + $fees = $wpi_session->get('wpi_cart_fees'); |
|
1056 | 1056 | |
1057 | - if ( ! wpinv_get_cart_contents() ) { |
|
1057 | + if (!wpinv_get_cart_contents()) { |
|
1058 | 1058 | // We can only get item type fees when the cart is empty |
1059 | 1059 | $type = 'custom'; |
1060 | 1060 | } |
1061 | 1061 | |
1062 | - if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { |
|
1063 | - foreach( $fees as $key => $fee ) { |
|
1064 | - if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1065 | - unset( $fees[ $key ] ); |
|
1062 | + if (!empty($fees) && !empty($type) && 'all' !== $type) { |
|
1063 | + foreach ($fees as $key => $fee) { |
|
1064 | + if (!empty($fee['type']) && $type != $fee['type']) { |
|
1065 | + unset($fees[$key]); |
|
1066 | 1066 | } |
1067 | 1067 | } |
1068 | 1068 | } |
1069 | 1069 | |
1070 | - if ( ! empty( $fees ) && ! empty( $item_id ) ) { |
|
1070 | + if (!empty($fees) && !empty($item_id)) { |
|
1071 | 1071 | // Remove fees that don't belong to the specified Item |
1072 | - foreach ( $fees as $key => $fee ) { |
|
1073 | - if ( (int) $item_id !== (int)$fee['custom_id'] ) { |
|
1074 | - unset( $fees[ $key ] ); |
|
1072 | + foreach ($fees as $key => $fee) { |
|
1073 | + if ((int) $item_id !== (int) $fee['custom_id']) { |
|
1074 | + unset($fees[$key]); |
|
1075 | 1075 | } |
1076 | 1076 | } |
1077 | 1077 | } |
1078 | 1078 | |
1079 | - if ( ! empty( $fees ) ) { |
|
1079 | + if (!empty($fees)) { |
|
1080 | 1080 | // Remove fees that belong to a specific item but are not in the cart |
1081 | - foreach( $fees as $key => $fee ) { |
|
1082 | - if( empty( $fee['custom_id'] ) ) { |
|
1081 | + foreach ($fees as $key => $fee) { |
|
1082 | + if (empty($fee['custom_id'])) { |
|
1083 | 1083 | continue; |
1084 | 1084 | } |
1085 | 1085 | |
1086 | - if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) { |
|
1087 | - unset( $fees[ $key ] ); |
|
1086 | + if (!wpinv_item_in_cart($fee['custom_id'])) { |
|
1087 | + unset($fees[$key]); |
|
1088 | 1088 | } |
1089 | 1089 | } |
1090 | 1090 | } |
1091 | 1091 | |
1092 | - return ! empty( $fees ) ? $fees : array(); |
|
1092 | + return !empty($fees) ? $fees : array(); |
|
1093 | 1093 | } |
1094 | 1094 | |
1095 | 1095 | /** |
@@ -1101,11 +1101,11 @@ discard block |
||
1101 | 1101 | public function can_purchase() { |
1102 | 1102 | $can_purchase = null !== $this->get_id(); |
1103 | 1103 | |
1104 | - if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
1104 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
1105 | 1105 | $can_purchase = false; |
1106 | 1106 | } |
1107 | 1107 | |
1108 | - return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
1108 | + return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | /** |
@@ -1115,6 +1115,6 @@ discard block |
||
1115 | 1115 | * @return bool |
1116 | 1116 | */ |
1117 | 1117 | public function supports_dynamic_pricing() { |
1118 | - return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
|
1118 | + return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this); |
|
1119 | 1119 | } |
1120 | 1120 | } |
@@ -7,110 +7,110 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_discount_types() { |
15 | 15 | $discount_types = array( |
16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
16 | + 'percent' => __('Percentage', 'invoicing'), |
|
17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
18 | 18 | ); |
19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
19 | + return (array) apply_filters('wpinv_discount_types', $discount_types); |
|
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
22 | +function wpinv_get_discount_type_name($type = '') { |
|
23 | 23 | $types = wpinv_get_discount_types(); |
24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
25 | 25 | } |
26 | 26 | |
27 | -function wpinv_delete_discount( $data ) { |
|
28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
27 | +function wpinv_delete_discount($data) { |
|
28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
30 | 30 | } |
31 | 31 | |
32 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
32 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $discount_id = $data['discount']; |
37 | - wpinv_remove_discount( $discount_id ); |
|
37 | + wpinv_remove_discount($discount_id); |
|
38 | 38 | } |
39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
40 | 40 | |
41 | -function wpinv_activate_discount( $data ) { |
|
42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
41 | +function wpinv_activate_discount($data) { |
|
42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
44 | 44 | } |
45 | 45 | |
46 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
46 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
48 | 48 | } |
49 | 49 | |
50 | - $id = absint( $data['discount'] ); |
|
51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
50 | + $id = absint($data['discount']); |
|
51 | + wpinv_update_discount_status($id, 'publish'); |
|
52 | 52 | } |
53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
54 | 54 | |
55 | -function wpinv_deactivate_discount( $data ) { |
|
56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_deactivate_discount($data) { |
|
56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
60 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
62 | 62 | } |
63 | 63 | |
64 | - $id = absint( $data['discount'] ); |
|
65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
64 | + $id = absint($data['discount']); |
|
65 | + wpinv_update_discount_status($id, 'pending'); |
|
66 | 66 | } |
67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
68 | 68 | |
69 | -function wpinv_get_discounts( $args = array() ) { |
|
69 | +function wpinv_get_discounts($args = array()) { |
|
70 | 70 | $defaults = array( |
71 | 71 | 'post_type' => 'wpi_discount', |
72 | 72 | 'posts_per_page' => 20, |
73 | 73 | 'paged' => null, |
74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
75 | 75 | ); |
76 | 76 | |
77 | - $args = wp_parse_args( $args, $defaults ); |
|
77 | + $args = wp_parse_args($args, $defaults); |
|
78 | 78 | |
79 | - $discounts = get_posts( $args ); |
|
79 | + $discounts = get_posts($args); |
|
80 | 80 | |
81 | - if ( $discounts ) { |
|
81 | + if ($discounts) { |
|
82 | 82 | return $discounts; |
83 | 83 | } |
84 | 84 | |
85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
85 | + if (!$discounts && !empty($args['s'])) { |
|
86 | 86 | $args['meta_key'] = '_wpi_discount_code'; |
87 | 87 | $args['meta_value'] = $args['s']; |
88 | 88 | $args['meta_compare'] = 'LIKE'; |
89 | - unset( $args['s'] ); |
|
90 | - $discounts = get_posts( $args ); |
|
89 | + unset($args['s']); |
|
90 | + $discounts = get_posts($args); |
|
91 | 91 | } |
92 | 92 | |
93 | - if( $discounts ) { |
|
93 | + if ($discounts) { |
|
94 | 94 | return $discounts; |
95 | 95 | } |
96 | 96 | |
97 | 97 | return false; |
98 | 98 | } |
99 | 99 | |
100 | -function wpinv_get_all_discounts( $args = array() ) { |
|
100 | +function wpinv_get_all_discounts($args = array()) { |
|
101 | 101 | |
102 | - $args = wp_parse_args( $args, array( |
|
103 | - 'status' => array( 'publish' ), |
|
104 | - 'limit' => get_option( 'posts_per_page' ), |
|
102 | + $args = wp_parse_args($args, array( |
|
103 | + 'status' => array('publish'), |
|
104 | + 'limit' => get_option('posts_per_page'), |
|
105 | 105 | 'page' => 1, |
106 | 106 | 'exclude' => array(), |
107 | 107 | 'orderby' => 'date', |
108 | 108 | 'order' => 'DESC', |
109 | - 'type' => array_keys( wpinv_get_discount_types() ), |
|
109 | + 'type' => array_keys(wpinv_get_discount_types()), |
|
110 | 110 | 'meta_query' => array(), |
111 | 111 | 'return' => 'objects', |
112 | 112 | 'paginate' => false, |
113 | - ) ); |
|
113 | + )); |
|
114 | 114 | |
115 | 115 | $wp_query_args = array( |
116 | 116 | 'post_type' => 'wpi_discount', |
@@ -120,18 +120,18 @@ discard block |
||
120 | 120 | 'fields' => 'ids', |
121 | 121 | 'orderby' => $args['orderby'], |
122 | 122 | 'order' => $args['order'], |
123 | - 'paged' => absint( $args['page'] ), |
|
123 | + 'paged' => absint($args['page']), |
|
124 | 124 | ); |
125 | 125 | |
126 | - if ( ! empty( $args['exclude'] ) ) { |
|
127 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
126 | + if (!empty($args['exclude'])) { |
|
127 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
128 | 128 | } |
129 | 129 | |
130 | - if ( ! $args['paginate' ] ) { |
|
130 | + if (!$args['paginate']) { |
|
131 | 131 | $wp_query_args['no_found_rows'] = true; |
132 | 132 | } |
133 | 133 | |
134 | - if ( ! empty( $args['search'] ) ) { |
|
134 | + if (!empty($args['search'])) { |
|
135 | 135 | |
136 | 136 | $wp_query_args['meta_query'][] = array( |
137 | 137 | 'key' => '_wpi_discount_code', |
@@ -141,11 +141,11 @@ discard block |
||
141 | 141 | |
142 | 142 | } |
143 | 143 | |
144 | - if ( ! empty( $args['type'] ) ) { |
|
145 | - $types = wpinv_parse_list( $args['type'] ); |
|
144 | + if (!empty($args['type'])) { |
|
145 | + $types = wpinv_parse_list($args['type']); |
|
146 | 146 | $wp_query_args['meta_query'][] = array( |
147 | 147 | 'key' => '_wpi_discount_type', |
148 | - 'value' => implode( ',', $types ), |
|
148 | + 'value' => implode(',', $types), |
|
149 | 149 | 'compare' => 'IN', |
150 | 150 | ); |
151 | 151 | } |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | $wp_query_args = apply_filters('wpinv_get_discount_args', $wp_query_args, $args); |
154 | 154 | |
155 | 155 | // Get results. |
156 | - $discounts = new WP_Query( $wp_query_args ); |
|
156 | + $discounts = new WP_Query($wp_query_args); |
|
157 | 157 | |
158 | - if ( 'objects' === $args['return'] ) { |
|
159 | - $return = array_map( 'get_post', $discounts->posts ); |
|
160 | - } elseif ( 'self' === $args['return'] ) { |
|
158 | + if ('objects' === $args['return']) { |
|
159 | + $return = array_map('get_post', $discounts->posts); |
|
160 | + } elseif ('self' === $args['return']) { |
|
161 | 161 | return $discounts; |
162 | 162 | } else { |
163 | 163 | $return = $discounts->posts; |
164 | 164 | } |
165 | 165 | |
166 | - if ( $args['paginate' ] ) { |
|
166 | + if ($args['paginate']) { |
|
167 | 167 | return (object) array( |
168 | 168 | 'discounts' => $return, |
169 | 169 | 'total' => $discounts->found_posts, |
@@ -180,9 +180,9 @@ discard block |
||
180 | 180 | |
181 | 181 | $discounts = wpinv_get_discounts(); |
182 | 182 | |
183 | - if ( $discounts) { |
|
184 | - foreach ( $discounts as $discount ) { |
|
185 | - if ( wpinv_is_discount_active( $discount->ID, true ) ) { |
|
183 | + if ($discounts) { |
|
184 | + foreach ($discounts as $discount) { |
|
185 | + if (wpinv_is_discount_active($discount->ID, true)) { |
|
186 | 186 | $has_active = true; |
187 | 187 | break; |
188 | 188 | } |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | return $has_active; |
192 | 192 | } |
193 | 193 | |
194 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
195 | - if( empty( $discount_id ) ) { |
|
194 | +function wpinv_get_discount($discount_id = 0) { |
|
195 | + if (empty($discount_id)) { |
|
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
199 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | 202 | |
203 | - $discount = get_post( $discount_id ); |
|
203 | + $discount = get_post($discount_id); |
|
204 | 204 | |
205 | 205 | return $discount; |
206 | 206 | } |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | * @since 1.0.15 |
213 | 213 | * @return WPInv_Discount |
214 | 214 | */ |
215 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
216 | - return new WPInv_Discount( $discount ); |
|
215 | +function wpinv_get_discount_obj($discount = 0) { |
|
216 | + return new WPInv_Discount($discount); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -222,8 +222,8 @@ discard block |
||
222 | 222 | * @param string $code The discount code. |
223 | 223 | * @return bool|WPInv_Discount |
224 | 224 | */ |
225 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
226 | - return wpinv_get_discount_by( null, $code ); |
|
225 | +function wpinv_get_discount_by_code($code = '') { |
|
226 | + return wpinv_get_discount_by(null, $code); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -233,10 +233,10 @@ discard block |
||
233 | 233 | * @param string|int $value The field value |
234 | 234 | * @return bool|WPInv_Discount |
235 | 235 | */ |
236 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { |
|
237 | - $discount = new WPInv_Discount( $value ); |
|
236 | +function wpinv_get_discount_by($deprecated = null, $value = '') { |
|
237 | + $discount = new WPInv_Discount($value); |
|
238 | 238 | |
239 | - if ( $discount->get_id() != 0 ) { |
|
239 | + if ($discount->get_id() != 0) { |
|
240 | 240 | return $discount; |
241 | 241 | } |
242 | 242 | |
@@ -250,68 +250,68 @@ discard block |
||
250 | 250 | * @param array $data The discount's properties. |
251 | 251 | * @return bool |
252 | 252 | */ |
253 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
253 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
254 | 254 | $meta = array( |
255 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
256 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
257 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
258 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
259 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
260 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
261 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
262 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
263 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
264 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
265 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
266 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
267 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
255 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
256 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
257 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
258 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
259 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
260 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
261 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
262 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
263 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
264 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
265 | + 'is_recurring' => isset($data['recurring']) ? (bool) $data['recurring'] : false, |
|
266 | + 'is_single_use' => isset($data['single_use']) ? (bool) $data['single_use'] : false, |
|
267 | + 'uses' => isset($data['uses']) ? (int) $data['uses'] : false, |
|
268 | 268 | ); |
269 | 269 | |
270 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
270 | + if ($meta['type'] == 'percent' && (float) $meta['amount'] > 100) { |
|
271 | 271 | $meta['amount'] = 100; |
272 | 272 | } |
273 | 273 | |
274 | - if ( !empty( $meta['start'] ) ) { |
|
275 | - $meta['start'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) ); |
|
274 | + if (!empty($meta['start'])) { |
|
275 | + $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start'])); |
|
276 | 276 | } |
277 | 277 | |
278 | - if ( !empty( $meta['expiration'] ) ) { |
|
279 | - $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) ); |
|
278 | + if (!empty($meta['expiration'])) { |
|
279 | + $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration'])); |
|
280 | 280 | |
281 | - if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) { |
|
281 | + if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) { |
|
282 | 282 | $meta['expiration'] = $meta['start']; |
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - if ( $meta['uses'] === false ) { |
|
287 | - unset( $meta['uses'] ); |
|
286 | + if ($meta['uses'] === false) { |
|
287 | + unset($meta['uses']); |
|
288 | 288 | } |
289 | 289 | |
290 | - if ( ! empty( $meta['items'] ) ) { |
|
291 | - foreach ( $meta['items'] as $key => $item ) { |
|
292 | - if ( 0 === intval( $item ) ) { |
|
293 | - unset( $meta['items'][ $key ] ); |
|
290 | + if (!empty($meta['items'])) { |
|
291 | + foreach ($meta['items'] as $key => $item) { |
|
292 | + if (0 === intval($item)) { |
|
293 | + unset($meta['items'][$key]); |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
298 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
299 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
300 | - if ( 0 === intval( $item ) ) { |
|
301 | - unset( $meta['excluded_items'][ $key ] ); |
|
298 | + if (!empty($meta['excluded_items'])) { |
|
299 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
300 | + if (0 === intval($item)) { |
|
301 | + unset($meta['excluded_items'][$key]); |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
306 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
307 | 307 | |
308 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
308 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
309 | 309 | |
310 | - foreach( $meta as $key => $value ) { |
|
311 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
310 | + foreach ($meta as $key => $value) { |
|
311 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
312 | 312 | } |
313 | 313 | |
314 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
314 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
315 | 315 | |
316 | 316 | return $post_id; |
317 | 317 | } |
@@ -322,10 +322,10 @@ discard block |
||
322 | 322 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
323 | 323 | * @return bool |
324 | 324 | */ |
325 | -function wpinv_remove_discount( $discount = 0 ) { |
|
325 | +function wpinv_remove_discount($discount = 0) { |
|
326 | 326 | |
327 | - $discount = wpinv_get_discount_obj( $discount ); |
|
328 | - if( ! $discount->exists() ) { |
|
327 | + $discount = wpinv_get_discount_obj($discount); |
|
328 | + if (!$discount->exists()) { |
|
329 | 329 | return false; |
330 | 330 | } |
331 | 331 | |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | * @param string $new_status |
341 | 341 | * @return bool |
342 | 342 | */ |
343 | -function wpinv_update_discount_status( $discount = 0, $new_status = 'publish' ) { |
|
344 | - $discount = wpinv_get_discount_obj( $discount ); |
|
345 | - return $discount->update_status( $new_status ); |
|
343 | +function wpinv_update_discount_status($discount = 0, $new_status = 'publish') { |
|
344 | + $discount = wpinv_get_discount_obj($discount); |
|
345 | + return $discount->update_status($new_status); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -351,48 +351,48 @@ discard block |
||
351 | 351 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
352 | 352 | * @return bool |
353 | 353 | */ |
354 | -function wpinv_discount_exists( $discount ) { |
|
355 | - $discount = wpinv_get_discount_obj( $discount ); |
|
354 | +function wpinv_discount_exists($discount) { |
|
355 | + $discount = wpinv_get_discount_obj($discount); |
|
356 | 356 | return $discount->exists(); |
357 | 357 | } |
358 | 358 | |
359 | -function wpinv_is_discount_active( $code_id = null, $silent = false ) { |
|
360 | - $discount = wpinv_get_discount( $code_id ); |
|
359 | +function wpinv_is_discount_active($code_id = null, $silent = false) { |
|
360 | + $discount = wpinv_get_discount($code_id); |
|
361 | 361 | $return = false; |
362 | 362 | |
363 | - if ( $discount ) { |
|
364 | - if ( wpinv_is_discount_expired( $code_id, $silent ) ) { |
|
365 | - if( defined( 'DOING_AJAX' ) && ! $silent ) { |
|
366 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
363 | + if ($discount) { |
|
364 | + if (wpinv_is_discount_expired($code_id, $silent)) { |
|
365 | + if (defined('DOING_AJAX') && !$silent) { |
|
366 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
367 | 367 | } |
368 | - } elseif ( $discount->post_status == 'publish' ) { |
|
368 | + } elseif ($discount->post_status == 'publish') { |
|
369 | 369 | $return = true; |
370 | 370 | } else { |
371 | - if( defined( 'DOING_AJAX' ) && ! $silent ) { |
|
372 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
371 | + if (defined('DOING_AJAX') && !$silent) { |
|
372 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
373 | 373 | } |
374 | 374 | } |
375 | 375 | } |
376 | 376 | |
377 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
377 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
378 | 378 | } |
379 | 379 | |
380 | -function wpinv_get_discount_code( $code_id = null ) { |
|
381 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
380 | +function wpinv_get_discount_code($code_id = null) { |
|
381 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
382 | 382 | |
383 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
383 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
384 | 384 | } |
385 | 385 | |
386 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
387 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
386 | +function wpinv_get_discount_start_date($code_id = null) { |
|
387 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
388 | 388 | |
389 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
389 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
390 | 390 | } |
391 | 391 | |
392 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
393 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
392 | +function wpinv_get_discount_expiration($code_id = null) { |
|
393 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
394 | 394 | |
395 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
395 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -401,8 +401,8 @@ discard block |
||
401 | 401 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
402 | 402 | * @return int |
403 | 403 | */ |
404 | -function wpinv_get_discount_max_uses( $discount = array() ) { |
|
405 | - $discount = wpinv_get_discount_obj( $discount ); |
|
404 | +function wpinv_get_discount_max_uses($discount = array()) { |
|
405 | + $discount = wpinv_get_discount_obj($discount); |
|
406 | 406 | return (int) $discount->max_uses; |
407 | 407 | } |
408 | 408 | |
@@ -412,8 +412,8 @@ discard block |
||
412 | 412 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
413 | 413 | * @return int |
414 | 414 | */ |
415 | -function wpinv_get_discount_uses( $discount = array() ) { |
|
416 | - $discount = wpinv_get_discount_obj( $discount ); |
|
415 | +function wpinv_get_discount_uses($discount = array()) { |
|
416 | + $discount = wpinv_get_discount_obj($discount); |
|
417 | 417 | return (int) $discount->uses; |
418 | 418 | } |
419 | 419 | |
@@ -423,8 +423,8 @@ discard block |
||
423 | 423 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
424 | 424 | * @return float |
425 | 425 | */ |
426 | -function wpinv_get_discount_min_total( $discount = array() ) { |
|
427 | - $discount = wpinv_get_discount_obj( $discount ); |
|
426 | +function wpinv_get_discount_min_total($discount = array()) { |
|
427 | + $discount = wpinv_get_discount_obj($discount); |
|
428 | 428 | return (float) $discount->min_total; |
429 | 429 | } |
430 | 430 | |
@@ -434,8 +434,8 @@ discard block |
||
434 | 434 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
435 | 435 | * @return float |
436 | 436 | */ |
437 | -function wpinv_get_discount_max_total( $discount = array() ) { |
|
438 | - $discount = wpinv_get_discount_obj( $discount ); |
|
437 | +function wpinv_get_discount_max_total($discount = array()) { |
|
438 | + $discount = wpinv_get_discount_obj($discount); |
|
439 | 439 | return (float) $discount->max_total; |
440 | 440 | } |
441 | 441 | |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
446 | 446 | * @return float |
447 | 447 | */ |
448 | -function wpinv_get_discount_amount( $discount = array() ) { |
|
449 | - $discount = wpinv_get_discount_obj( $discount ); |
|
448 | +function wpinv_get_discount_amount($discount = array()) { |
|
449 | + $discount = wpinv_get_discount_obj($discount); |
|
450 | 450 | return (float) $discount->amount; |
451 | 451 | } |
452 | 452 | |
@@ -457,28 +457,28 @@ discard block |
||
457 | 457 | * @param bool $name |
458 | 458 | * @return string |
459 | 459 | */ |
460 | -function wpinv_get_discount_type( $discount = array(), $name = false ) { |
|
461 | - $discount = wpinv_get_discount_obj( $discount ); |
|
460 | +function wpinv_get_discount_type($discount = array(), $name = false) { |
|
461 | + $discount = wpinv_get_discount_obj($discount); |
|
462 | 462 | |
463 | 463 | // Are we returning the name or just the type. |
464 | - if( $name ) { |
|
464 | + if ($name) { |
|
465 | 465 | return $discount->type_name; |
466 | 466 | } |
467 | 467 | |
468 | 468 | return $discount->type; |
469 | 469 | } |
470 | 470 | |
471 | -function wpinv_discount_status( $status ) { |
|
472 | - switch( $status ){ |
|
471 | +function wpinv_discount_status($status) { |
|
472 | + switch ($status) { |
|
473 | 473 | case 'expired' : |
474 | - $name = __( 'Expired', 'invoicing' ); |
|
474 | + $name = __('Expired', 'invoicing'); |
|
475 | 475 | break; |
476 | 476 | case 'publish' : |
477 | 477 | case 'active' : |
478 | - $name = __( 'Active', 'invoicing' ); |
|
478 | + $name = __('Active', 'invoicing'); |
|
479 | 479 | break; |
480 | 480 | default : |
481 | - $name = __( 'Inactive', 'invoicing' ); |
|
481 | + $name = __('Inactive', 'invoicing'); |
|
482 | 482 | break; |
483 | 483 | } |
484 | 484 | return $name; |
@@ -490,8 +490,8 @@ discard block |
||
490 | 490 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
491 | 491 | * @return array |
492 | 492 | */ |
493 | -function wpinv_get_discount_excluded_items( $discount = array() ) { |
|
494 | - $discount = wpinv_get_discount_obj( $discount ); |
|
493 | +function wpinv_get_discount_excluded_items($discount = array()) { |
|
494 | + $discount = wpinv_get_discount_obj($discount); |
|
495 | 495 | return $discount->excluded_items; |
496 | 496 | } |
497 | 497 | |
@@ -501,17 +501,17 @@ discard block |
||
501 | 501 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
502 | 502 | * @return array |
503 | 503 | */ |
504 | -function wpinv_get_discount_item_reqs( $discount = array() ) { |
|
505 | - $discount = wpinv_get_discount_obj( $discount ); |
|
504 | +function wpinv_get_discount_item_reqs($discount = array()) { |
|
505 | + $discount = wpinv_get_discount_obj($discount); |
|
506 | 506 | return $discount->items; |
507 | 507 | } |
508 | 508 | |
509 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
510 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
509 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
510 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
511 | 511 | } |
512 | 512 | |
513 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
514 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
513 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
514 | + return (bool) get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | /** |
@@ -520,14 +520,14 @@ discard block |
||
520 | 520 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
521 | 521 | * @return bool |
522 | 522 | */ |
523 | -function wpinv_is_discount_expired( $discount = array(), $silent = false ) { |
|
524 | - $discount = wpinv_get_discount_obj( $discount ); |
|
523 | +function wpinv_is_discount_expired($discount = array(), $silent = false) { |
|
524 | + $discount = wpinv_get_discount_obj($discount); |
|
525 | 525 | |
526 | - if ( $discount->is_expired() ) { |
|
527 | - $discount->update_status( 'pending' ); |
|
526 | + if ($discount->is_expired()) { |
|
527 | + $discount->update_status('pending'); |
|
528 | 528 | |
529 | - if( empty( $silent ) ) { |
|
530 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has expired.', 'invoicing' ) ); |
|
529 | + if (empty($silent)) { |
|
530 | + wpinv_set_error('wpinv-discount-error', __('This discount has expired.', 'invoicing')); |
|
531 | 531 | } |
532 | 532 | return true; |
533 | 533 | } |
@@ -541,12 +541,12 @@ discard block |
||
541 | 541 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
542 | 542 | * @return bool |
543 | 543 | */ |
544 | -function wpinv_is_discount_started( $discount = array() ) { |
|
545 | - $discount = wpinv_get_discount_obj( $discount ); |
|
544 | +function wpinv_is_discount_started($discount = array()) { |
|
545 | + $discount = wpinv_get_discount_obj($discount); |
|
546 | 546 | $started = $discount->has_started(); |
547 | 547 | |
548 | - if( empty( $started ) ) { |
|
549 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
548 | + if (empty($started)) { |
|
549 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | return $started; |
@@ -558,10 +558,10 @@ discard block |
||
558 | 558 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
559 | 559 | * @return bool |
560 | 560 | */ |
561 | -function wpinv_check_discount_dates( $discount ) { |
|
562 | - $discount = wpinv_get_discount_obj( $discount ); |
|
563 | - $return = wpinv_is_discount_started( $discount ) && ! wpinv_is_discount_expired( $discount ); |
|
564 | - return apply_filters( 'wpinv_check_discount_dates', $return, $discount->ID, $discount, $discount->code ); |
|
561 | +function wpinv_check_discount_dates($discount) { |
|
562 | + $discount = wpinv_get_discount_obj($discount); |
|
563 | + $return = wpinv_is_discount_started($discount) && !wpinv_is_discount_expired($discount); |
|
564 | + return apply_filters('wpinv_check_discount_dates', $return, $discount->ID, $discount, $discount->code); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -570,12 +570,12 @@ discard block |
||
570 | 570 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
571 | 571 | * @return bool |
572 | 572 | */ |
573 | -function wpinv_is_discount_maxed_out( $discount ) { |
|
574 | - $discount = wpinv_get_discount_obj( $discount ); |
|
573 | +function wpinv_is_discount_maxed_out($discount) { |
|
574 | + $discount = wpinv_get_discount_obj($discount); |
|
575 | 575 | $maxed_out = $discount->has_exceeded_limit(); |
576 | 576 | |
577 | - if ( $maxed_out ) { |
|
578 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
577 | + if ($maxed_out) { |
|
578 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | return $maxed_out; |
@@ -587,13 +587,13 @@ discard block |
||
587 | 587 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
588 | 588 | * @return bool |
589 | 589 | */ |
590 | -function wpinv_discount_is_min_met( $discount ) { |
|
591 | - $discount = wpinv_get_discount_obj( $discount ); |
|
592 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $discount->ID ); |
|
593 | - $min_met = $discount->is_minimum_amount_met( $cart_amount ); |
|
590 | +function wpinv_discount_is_min_met($discount) { |
|
591 | + $discount = wpinv_get_discount_obj($discount); |
|
592 | + $cart_amount = (float) wpinv_get_cart_discountable_subtotal($discount->ID); |
|
593 | + $min_met = $discount->is_minimum_amount_met($cart_amount); |
|
594 | 594 | |
595 | - if ( ! $min_met ) { |
|
596 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $discount->min_total ) ) ) ); |
|
595 | + if (!$min_met) { |
|
596 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($discount->min_total)))); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | return $min_met; |
@@ -605,13 +605,13 @@ discard block |
||
605 | 605 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
606 | 606 | * @return bool |
607 | 607 | */ |
608 | -function wpinv_discount_is_max_met( $discount ) { |
|
609 | - $discount = wpinv_get_discount_obj( $discount ); |
|
610 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $discount->ID ); |
|
611 | - $max_met = $discount->is_maximum_amount_met( $cart_amount ); |
|
608 | +function wpinv_discount_is_max_met($discount) { |
|
609 | + $discount = wpinv_get_discount_obj($discount); |
|
610 | + $cart_amount = (float) wpinv_get_cart_discountable_subtotal($discount->ID); |
|
611 | + $max_met = $discount->is_maximum_amount_met($cart_amount); |
|
612 | 612 | |
613 | - if ( ! $max_met ) { |
|
614 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $discount->max_total ) ) ) ); |
|
613 | + if (!$max_met) { |
|
614 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($discount->max_total)))); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | return $max_met; |
@@ -623,8 +623,8 @@ discard block |
||
623 | 623 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
624 | 624 | * @return bool |
625 | 625 | */ |
626 | -function wpinv_discount_is_single_use( $discount ) { |
|
627 | - $discount = wpinv_get_discount_obj( $discount ); |
|
626 | +function wpinv_discount_is_single_use($discount) { |
|
627 | + $discount = wpinv_get_discount_obj($discount); |
|
628 | 628 | return $discount->is_single_use; |
629 | 629 | } |
630 | 630 | |
@@ -635,53 +635,53 @@ discard block |
||
635 | 635 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
636 | 636 | * @return bool |
637 | 637 | */ |
638 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
638 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
639 | 639 | |
640 | - if( ! empty( $discount ) ) { |
|
641 | - $discount = wpinv_get_discount_obj( $discount ); |
|
640 | + if (!empty($discount)) { |
|
641 | + $discount = wpinv_get_discount_obj($discount); |
|
642 | 642 | } else { |
643 | - $discount = wpinv_get_discount_obj( $code ); |
|
643 | + $discount = wpinv_get_discount_obj($code); |
|
644 | 644 | } |
645 | 645 | |
646 | 646 | return $discount->get_is_recurring(); |
647 | 647 | } |
648 | 648 | |
649 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
650 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
651 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
652 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
649 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
650 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
651 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
652 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
653 | 653 | $cart_items = wpinv_get_cart_contents(); |
654 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
654 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
655 | 655 | $ret = false; |
656 | 656 | |
657 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
657 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
658 | 658 | $ret = true; |
659 | 659 | } |
660 | 660 | |
661 | 661 | // Normalize our data for item requirements, exclusions and cart data |
662 | 662 | // First absint the items, then sort, and reset the array keys |
663 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
664 | - asort( $item_reqs ); |
|
665 | - $item_reqs = array_values( $item_reqs ); |
|
663 | + $item_reqs = array_map('absint', $item_reqs); |
|
664 | + asort($item_reqs); |
|
665 | + $item_reqs = array_values($item_reqs); |
|
666 | 666 | |
667 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
668 | - asort( $excluded_ps ); |
|
669 | - $excluded_ps = array_values( $excluded_ps ); |
|
667 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
668 | + asort($excluded_ps); |
|
669 | + $excluded_ps = array_values($excluded_ps); |
|
670 | 670 | |
671 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
672 | - asort( $cart_ids ); |
|
673 | - $cart_ids = array_values( $cart_ids ); |
|
671 | + $cart_ids = array_map('absint', $cart_ids); |
|
672 | + asort($cart_ids); |
|
673 | + $cart_ids = array_values($cart_ids); |
|
674 | 674 | |
675 | 675 | // Ensure we have requirements before proceeding |
676 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
677 | - switch( $condition ) { |
|
676 | + if (!$ret && !empty($item_reqs)) { |
|
677 | + switch ($condition) { |
|
678 | 678 | case 'all' : |
679 | 679 | // Default back to true |
680 | 680 | $ret = true; |
681 | 681 | |
682 | - foreach ( $item_reqs as $item_id ) { |
|
683 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
684 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
682 | + foreach ($item_reqs as $item_id) { |
|
683 | + if (!wpinv_item_in_cart($item_id)) { |
|
684 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
685 | 685 | $ret = false; |
686 | 686 | break; |
687 | 687 | } |
@@ -690,15 +690,15 @@ discard block |
||
690 | 690 | break; |
691 | 691 | |
692 | 692 | default : // Any |
693 | - foreach ( $item_reqs as $item_id ) { |
|
694 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
693 | + foreach ($item_reqs as $item_id) { |
|
694 | + if (wpinv_item_in_cart($item_id)) { |
|
695 | 695 | $ret = true; |
696 | 696 | break; |
697 | 697 | } |
698 | 698 | } |
699 | 699 | |
700 | - if( ! $ret ) { |
|
701 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
700 | + if (!$ret) { |
|
701 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
702 | 702 | } |
703 | 703 | |
704 | 704 | break; |
@@ -707,15 +707,15 @@ discard block |
||
707 | 707 | $ret = true; |
708 | 708 | } |
709 | 709 | |
710 | - if( ! empty( $excluded_ps ) ) { |
|
710 | + if (!empty($excluded_ps)) { |
|
711 | 711 | // Check that there are items other than excluded ones in the cart |
712 | - if( $cart_ids == $excluded_ps ) { |
|
713 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
712 | + if ($cart_ids == $excluded_ps) { |
|
713 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
714 | 714 | $ret = false; |
715 | 715 | } |
716 | 716 | } |
717 | 717 | |
718 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
718 | + return (bool) apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | /** |
@@ -726,54 +726,54 @@ discard block |
||
726 | 726 | * @param int|array|string|WPInv_Discount $code_id discount data, object, ID or code. |
727 | 727 | * @return bool |
728 | 728 | */ |
729 | -function wpinv_is_discount_used( $discount = array(), $user = '', $code_id = array() ) { |
|
729 | +function wpinv_is_discount_used($discount = array(), $user = '', $code_id = array()) { |
|
730 | 730 | |
731 | - if( ! empty( $discount ) ) { |
|
732 | - $discount = wpinv_get_discount_obj( $discount ); |
|
731 | + if (!empty($discount)) { |
|
732 | + $discount = wpinv_get_discount_obj($discount); |
|
733 | 733 | } else { |
734 | - $discount = wpinv_get_discount_obj( $code_id ); |
|
734 | + $discount = wpinv_get_discount_obj($code_id); |
|
735 | 735 | } |
736 | 736 | |
737 | - $is_used = ! $discount->is_valid_for_user( $user ); |
|
738 | - $is_used = apply_filters( 'wpinv_is_discount_used', $is_used, $discount->code, $user, $discount->ID, $discount ); |
|
737 | + $is_used = !$discount->is_valid_for_user($user); |
|
738 | + $is_used = apply_filters('wpinv_is_discount_used', $is_used, $discount->code, $user, $discount->ID, $discount); |
|
739 | 739 | |
740 | - if( $is_used ) { |
|
741 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
740 | + if ($is_used) { |
|
741 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | return $is_used; |
745 | 745 | } |
746 | 746 | |
747 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
747 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
748 | 748 | |
749 | 749 | // Abort early if there is no discount code. |
750 | - if ( empty( $code ) ) { |
|
750 | + if (empty($code)) { |
|
751 | 751 | return false; |
752 | 752 | } |
753 | 753 | |
754 | 754 | $return = false; |
755 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
756 | - $user = trim( $user ); |
|
755 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
756 | + $user = trim($user); |
|
757 | 757 | |
758 | - if ( wpinv_get_cart_contents() ) { |
|
759 | - if ( $discount_id !== false ) { |
|
758 | + if (wpinv_get_cart_contents()) { |
|
759 | + if ($discount_id !== false) { |
|
760 | 760 | if ( |
761 | - wpinv_is_discount_active( $discount_id ) && |
|
762 | - wpinv_check_discount_dates( $discount_id ) && |
|
763 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
764 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
765 | - wpinv_discount_is_min_met( $discount_id ) && |
|
766 | - wpinv_discount_is_max_met( $discount_id ) && |
|
767 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
761 | + wpinv_is_discount_active($discount_id) && |
|
762 | + wpinv_check_discount_dates($discount_id) && |
|
763 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
764 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
765 | + wpinv_discount_is_min_met($discount_id) && |
|
766 | + wpinv_discount_is_max_met($discount_id) && |
|
767 | + wpinv_discount_item_reqs_met($discount_id) |
|
768 | 768 | ) { |
769 | 769 | $return = true; |
770 | 770 | } |
771 | - } elseif( $set_error ) { |
|
772 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
771 | + } elseif ($set_error) { |
|
772 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
773 | 773 | } |
774 | 774 | } |
775 | 775 | |
776 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
776 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | /** |
@@ -782,9 +782,9 @@ discard block |
||
782 | 782 | * @param string $code |
783 | 783 | * @return bool|false |
784 | 784 | */ |
785 | -function wpinv_get_discount_id_by_code( $code ) { |
|
786 | - $discount = wpinv_get_discount_by_code( $code ); |
|
787 | - if ( $discount ) { |
|
785 | +function wpinv_get_discount_id_by_code($code) { |
|
786 | + $discount = wpinv_get_discount_by_code($code); |
|
787 | + if ($discount) { |
|
788 | 788 | return $discount->get_id(); |
789 | 789 | } |
790 | 790 | return false; |
@@ -797,9 +797,9 @@ discard block |
||
797 | 797 | * @param float $base_price The number of usages to increase by |
798 | 798 | * @return float |
799 | 799 | */ |
800 | -function wpinv_get_discounted_amount( $discount, $base_price ) { |
|
801 | - $discount = wpinv_get_discount_obj( $discount ); |
|
802 | - return $discount->get_discounted_amount( $base_price ); |
|
800 | +function wpinv_get_discounted_amount($discount, $base_price) { |
|
801 | + $discount = wpinv_get_discount_obj($discount); |
|
802 | + return $discount->get_discounted_amount($base_price); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | /** |
@@ -809,9 +809,9 @@ discard block |
||
809 | 809 | * @param int $by The number of usages to increase by. |
810 | 810 | * @return int the new number of uses. |
811 | 811 | */ |
812 | -function wpinv_increase_discount_usage( $discount, $by = 1 ) { |
|
813 | - $discount = wpinv_get_discount_obj( $discount ); |
|
814 | - return $discount->increase_usage( $by ); |
|
812 | +function wpinv_increase_discount_usage($discount, $by = 1) { |
|
813 | + $discount = wpinv_get_discount_obj($discount); |
|
814 | + return $discount->increase_usage($by); |
|
815 | 815 | } |
816 | 816 | |
817 | 817 | /** |
@@ -821,72 +821,72 @@ discard block |
||
821 | 821 | * @param int $by The number of usages to decrease by. |
822 | 822 | * @return int the new number of uses. |
823 | 823 | */ |
824 | -function wpinv_decrease_discount_usage( $discount, $by = 1 ) { |
|
825 | - $discount = wpinv_get_discount_obj( $discount ); |
|
826 | - return $discount->increase_usage( 0 - $by ); |
|
824 | +function wpinv_decrease_discount_usage($discount, $by = 1) { |
|
825 | + $discount = wpinv_get_discount_obj($discount); |
|
826 | + return $discount->increase_usage(0 - $by); |
|
827 | 827 | } |
828 | 828 | |
829 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
830 | - if ( $type == 'flat' ) { |
|
831 | - $rate = wpinv_price( wpinv_format_amount( $amount ) ); |
|
829 | +function wpinv_format_discount_rate($type, $amount) { |
|
830 | + if ($type == 'flat') { |
|
831 | + $rate = wpinv_price(wpinv_format_amount($amount)); |
|
832 | 832 | } else { |
833 | 833 | $rate = $amount . '%'; |
834 | 834 | } |
835 | 835 | |
836 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount ); |
|
836 | + return apply_filters('wpinv_format_discount_rate', $rate, $type, $amount); |
|
837 | 837 | } |
838 | 838 | |
839 | -function wpinv_set_cart_discount( $code = '' ) { |
|
840 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
839 | +function wpinv_set_cart_discount($code = '') { |
|
840 | + if (wpinv_multiple_discounts_allowed()) { |
|
841 | 841 | // Get all active cart discounts |
842 | 842 | $discounts = wpinv_get_cart_discounts(); |
843 | 843 | } else { |
844 | 844 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
845 | 845 | } |
846 | 846 | |
847 | - if ( $discounts ) { |
|
848 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
849 | - if( false !== $key ) { |
|
850 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
847 | + if ($discounts) { |
|
848 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
849 | + if (false !== $key) { |
|
850 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
851 | 851 | } |
852 | 852 | $discounts[] = $code; |
853 | 853 | } else { |
854 | 854 | $discounts = array(); |
855 | 855 | $discounts[] = $code; |
856 | 856 | } |
857 | - $discounts = array_values( $discounts ); |
|
857 | + $discounts = array_values($discounts); |
|
858 | 858 | |
859 | 859 | $data = wpinv_get_checkout_session(); |
860 | - if ( empty( $data ) ) { |
|
860 | + if (empty($data)) { |
|
861 | 861 | $data = array(); |
862 | 862 | } else { |
863 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
864 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
865 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
863 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
864 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
865 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
866 | 866 | } |
867 | 867 | } |
868 | 868 | $data['cart_discounts'] = $discounts; |
869 | 869 | |
870 | - wpinv_set_checkout_session( $data ); |
|
870 | + wpinv_set_checkout_session($data); |
|
871 | 871 | |
872 | 872 | return $discounts; |
873 | 873 | } |
874 | 874 | |
875 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
875 | +function wpinv_unset_cart_discount($code = '') { |
|
876 | 876 | $discounts = wpinv_get_cart_discounts(); |
877 | 877 | |
878 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
879 | - $key = array_search( $code, $discounts ); |
|
880 | - unset( $discounts[ $key ] ); |
|
878 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
879 | + $key = array_search($code, $discounts); |
|
880 | + unset($discounts[$key]); |
|
881 | 881 | |
882 | 882 | $data = wpinv_get_checkout_session(); |
883 | 883 | $data['cart_discounts'] = $discounts; |
884 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
885 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
886 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
884 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
885 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
886 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
887 | 887 | } |
888 | 888 | |
889 | - wpinv_set_checkout_session( $data ); |
|
889 | + wpinv_set_checkout_session($data); |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | return $discounts; |
@@ -895,10 +895,10 @@ discard block |
||
895 | 895 | function wpinv_unset_all_cart_discounts() { |
896 | 896 | $data = wpinv_get_checkout_session(); |
897 | 897 | |
898 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
899 | - unset( $data['cart_discounts'] ); |
|
898 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
899 | + unset($data['cart_discounts']); |
|
900 | 900 | |
901 | - wpinv_set_checkout_session( $data ); |
|
901 | + wpinv_set_checkout_session($data); |
|
902 | 902 | return true; |
903 | 903 | } |
904 | 904 | |
@@ -907,13 +907,13 @@ discard block |
||
907 | 907 | |
908 | 908 | function wpinv_get_cart_discounts() { |
909 | 909 | $session = wpinv_get_checkout_session(); |
910 | - return empty( $session['cart_discounts'] ) ? false : $session['cart_discounts']; |
|
910 | + return empty($session['cart_discounts']) ? false : $session['cart_discounts']; |
|
911 | 911 | } |
912 | 912 | |
913 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
913 | +function wpinv_cart_has_discounts($items = array()) { |
|
914 | 914 | $ret = false; |
915 | 915 | |
916 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
916 | + if (wpinv_get_cart_discounts($items)) { |
|
917 | 917 | $ret = true; |
918 | 918 | } |
919 | 919 | |
@@ -924,131 +924,131 @@ discard block |
||
924 | 924 | } |
925 | 925 | */ |
926 | 926 | |
927 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
927 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
928 | 928 | } |
929 | 929 | |
930 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
930 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
931 | 931 | $amount = 0.00; |
932 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
932 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
933 | 933 | |
934 | - if ( $items ) { |
|
935 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
934 | + if ($items) { |
|
935 | + $discounts = wp_list_pluck($items, 'discount'); |
|
936 | 936 | |
937 | - if ( is_array( $discounts ) ) { |
|
938 | - $discounts = array_map( 'floatval', $discounts ); |
|
939 | - $amount = array_sum( $discounts ); |
|
937 | + if (is_array($discounts)) { |
|
938 | + $discounts = array_map('floatval', $discounts); |
|
939 | + $amount = array_sum($discounts); |
|
940 | 940 | } |
941 | 941 | } |
942 | 942 | |
943 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
943 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
944 | 944 | } |
945 | 945 | |
946 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
947 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
946 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
947 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
948 | 948 | |
949 | - if ( empty( $discount ) || empty( $items ) ) { |
|
949 | + if (empty($discount) || empty($items)) { |
|
950 | 950 | return 0; |
951 | 951 | } |
952 | 952 | |
953 | 953 | $amount = 0; |
954 | 954 | |
955 | - foreach ( $items as $item ) { |
|
956 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
955 | + foreach ($items as $item) { |
|
956 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
957 | 957 | } |
958 | 958 | |
959 | - $amount = wpinv_round_amount( $amount ); |
|
959 | + $amount = wpinv_round_amount($amount); |
|
960 | 960 | |
961 | 961 | return $amount; |
962 | 962 | } |
963 | 963 | |
964 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
964 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
965 | 965 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
966 | 966 | |
967 | 967 | $amount = 0; |
968 | 968 | |
969 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
969 | + if (empty($item) || empty($item['id'])) { |
|
970 | 970 | return $amount; |
971 | 971 | } |
972 | 972 | |
973 | - if ( empty( $item['quantity'] ) ) { |
|
973 | + if (empty($item['quantity'])) { |
|
974 | 974 | return $amount; |
975 | 975 | } |
976 | 976 | |
977 | - if ( empty( $item['options'] ) ) { |
|
977 | + if (empty($item['options'])) { |
|
978 | 978 | $item['options'] = array(); |
979 | 979 | } |
980 | 980 | |
981 | - $price = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] ); |
|
981 | + $price = wpinv_get_cart_item_price($item['id'], $item, $item['options']); |
|
982 | 982 | $discounted_price = $price; |
983 | 983 | |
984 | 984 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
985 | - if ( empty( $discounts ) ) { |
|
985 | + if (empty($discounts)) { |
|
986 | 986 | return $amount; |
987 | 987 | } |
988 | 988 | |
989 | - if ( $discounts ) { |
|
990 | - if ( is_array( $discounts ) ) { |
|
991 | - $discounts = array_values( $discounts ); |
|
989 | + if ($discounts) { |
|
990 | + if (is_array($discounts)) { |
|
991 | + $discounts = array_values($discounts); |
|
992 | 992 | } else { |
993 | - $discounts = explode( ',', $discounts ); |
|
993 | + $discounts = explode(',', $discounts); |
|
994 | 994 | } |
995 | 995 | } |
996 | 996 | |
997 | - if( $discounts ) { |
|
998 | - foreach ( $discounts as $discount ) { |
|
999 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
997 | + if ($discounts) { |
|
998 | + foreach ($discounts as $discount) { |
|
999 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
1000 | 1000 | |
1001 | 1001 | // Check discount exists |
1002 | - if( $code_id === false ) { |
|
1002 | + if ($code_id === false) { |
|
1003 | 1003 | continue; |
1004 | 1004 | } |
1005 | 1005 | |
1006 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
1007 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
1006 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
1007 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
1008 | 1008 | |
1009 | 1009 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
1010 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
1011 | - foreach ( $reqs as $item_id ) { |
|
1012 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
1013 | - $discounted_price -= wpinv_get_discounted_amount( $discount, $price ); |
|
1010 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
1011 | + foreach ($reqs as $item_id) { |
|
1012 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
1013 | + $discounted_price -= wpinv_get_discounted_amount($discount, $price); |
|
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | } else { |
1017 | 1017 | // This is a global cart discount |
1018 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
1019 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
1018 | + if (!in_array($item['id'], $excluded_items)) { |
|
1019 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
1020 | 1020 | $items_subtotal = 0.00; |
1021 | 1021 | $cart_items = wpinv_get_cart_contents(); |
1022 | 1022 | |
1023 | - foreach ( $cart_items as $cart_item ) { |
|
1024 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
1025 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
1026 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options ); |
|
1023 | + foreach ($cart_items as $cart_item) { |
|
1024 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
1025 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
1026 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options); |
|
1027 | 1027 | $items_subtotal += $item_price * $cart_item['quantity']; |
1028 | 1028 | } |
1029 | 1029 | } |
1030 | 1030 | |
1031 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
1032 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
1031 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
1032 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
1033 | 1033 | $discounted_amount = $code_amount * $subtotal_percent; |
1034 | 1034 | $discounted_price -= $discounted_amount; |
1035 | 1035 | |
1036 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
1036 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
1037 | 1037 | |
1038 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
1038 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
1039 | 1039 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
1040 | 1040 | $discounted_price -= $adjustment; |
1041 | 1041 | } |
1042 | 1042 | } else { |
1043 | - $discounted_price -= wpinv_get_discounted_amount( $discount, $price ); |
|
1043 | + $discounted_price -= wpinv_get_discounted_amount($discount, $price); |
|
1044 | 1044 | } |
1045 | 1045 | } |
1046 | 1046 | } |
1047 | 1047 | } |
1048 | 1048 | |
1049 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
1049 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
1050 | 1050 | |
1051 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
1051 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
1052 | 1052 | $amount = $amount * $item['quantity']; |
1053 | 1053 | } |
1054 | 1054 | } |
@@ -1056,59 +1056,59 @@ discard block |
||
1056 | 1056 | return $amount; |
1057 | 1057 | } |
1058 | 1058 | |
1059 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
1060 | - echo wpinv_get_cart_discounts_html( $items ); |
|
1059 | +function wpinv_cart_discounts_html($items = array()) { |
|
1060 | + echo wpinv_get_cart_discounts_html($items); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
1063 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
1064 | 1064 | global $wpi_cart_columns; |
1065 | 1065 | |
1066 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
1066 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
1067 | 1067 | |
1068 | - if ( !$discounts ) { |
|
1069 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
1068 | + if (!$discounts) { |
|
1069 | + $discounts = wpinv_get_cart_discounts($items); |
|
1070 | 1070 | } |
1071 | 1071 | |
1072 | - if ( !$discounts ) { |
|
1072 | + if (!$discounts) { |
|
1073 | 1073 | return; |
1074 | 1074 | } |
1075 | 1075 | |
1076 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
1076 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
1077 | 1077 | |
1078 | 1078 | $html = ''; |
1079 | 1079 | |
1080 | - foreach ( $discounts as $discount ) { |
|
1081 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
1082 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
1083 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
1084 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
1085 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1080 | + foreach ($discounts as $discount) { |
|
1081 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
1082 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
1083 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
1084 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
1085 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1086 | 1086 | |
1087 | 1087 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
1088 | 1088 | ob_start(); |
1089 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
1089 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
1090 | 1090 | $html .= ob_get_clean(); |
1091 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>'; |
|
1091 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>'; |
|
1092 | 1092 | ob_start(); |
1093 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
1093 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
1094 | 1094 | $html .= ob_get_clean(); |
1095 | 1095 | $html .= '</tr>'; |
1096 | 1096 | } |
1097 | 1097 | |
1098 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
1098 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
1099 | 1099 | } |
1100 | 1100 | |
1101 | -function wpinv_display_cart_discount( /** @scrutinizer ignore-unused */ $formatted = false, $echo = false ) { |
|
1101 | +function wpinv_display_cart_discount(/** @scrutinizer ignore-unused */ $formatted = false, $echo = false) { |
|
1102 | 1102 | $discounts = wpinv_get_cart_discounts(); |
1103 | 1103 | |
1104 | - if ( empty( $discounts ) ) { |
|
1104 | + if (empty($discounts)) { |
|
1105 | 1105 | return false; |
1106 | 1106 | } |
1107 | 1107 | |
1108 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
1109 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
1108 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
1109 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
1110 | 1110 | |
1111 | - if ( $echo ) { |
|
1111 | + if ($echo) { |
|
1112 | 1112 | echo $amount; |
1113 | 1113 | } |
1114 | 1114 | |
@@ -1116,65 +1116,65 @@ discard block |
||
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | function wpinv_remove_cart_discount() { |
1119 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
1119 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
1120 | 1120 | return; |
1121 | 1121 | } |
1122 | 1122 | |
1123 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1123 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
1124 | 1124 | |
1125 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
1125 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
1126 | 1126 | |
1127 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1127 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
1128 | 1128 | |
1129 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
1129 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
1130 | 1130 | } |
1131 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
1131 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
1132 | 1132 | |
1133 | 1133 | function wpinv_maybe_remove_cart_discount() { |
1134 | 1134 | $discounts = wpinv_get_cart_discounts(); |
1135 | 1135 | |
1136 | - if ( !$discounts ) { |
|
1136 | + if (!$discounts) { |
|
1137 | 1137 | return; |
1138 | 1138 | } |
1139 | 1139 | |
1140 | - $discounts = array_filter( $discounts ); |
|
1141 | - foreach ( $discounts as $discount ) { |
|
1142 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
1143 | - wpinv_unset_cart_discount( $discount ); |
|
1140 | + $discounts = array_filter($discounts); |
|
1141 | + foreach ($discounts as $discount) { |
|
1142 | + if (!wpinv_is_discount_valid($discount)) { |
|
1143 | + wpinv_unset_cart_discount($discount); |
|
1144 | 1144 | } |
1145 | 1145 | } |
1146 | 1146 | } |
1147 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
1147 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
1148 | 1148 | |
1149 | 1149 | function wpinv_multiple_discounts_allowed() { |
1150 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
1151 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
1150 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
1151 | + return (bool) apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
1152 | 1152 | } |
1153 | 1153 | |
1154 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
1155 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
1156 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
1154 | +function wpinv_get_discount_label($code, $echo = true) { |
|
1155 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
1156 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
1157 | 1157 | |
1158 | - if ( $echo ) { |
|
1158 | + if ($echo) { |
|
1159 | 1159 | echo $label; |
1160 | 1160 | } else { |
1161 | 1161 | return $label; |
1162 | 1162 | } |
1163 | 1163 | } |
1164 | 1164 | |
1165 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
1166 | - $label = wp_sprintf( __( 'Discount: %s', 'invoicing' ), $code ); |
|
1167 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
1165 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
1166 | + $label = wp_sprintf(__('Discount: %s', 'invoicing'), $code); |
|
1167 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
1168 | 1168 | |
1169 | - if ( $echo ) { |
|
1169 | + if ($echo) { |
|
1170 | 1170 | echo $label; |
1171 | 1171 | } else { |
1172 | 1172 | return $label; |
1173 | 1173 | } |
1174 | 1174 | } |
1175 | 1175 | |
1176 | -function wpinv_check_delete_discount( $check, $post ) { |
|
1177 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
1176 | +function wpinv_check_delete_discount($check, $post) { |
|
1177 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
1178 | 1178 | return true; |
1179 | 1179 | } |
1180 | 1180 | |
@@ -1185,33 +1185,33 @@ discard block |
||
1185 | 1185 | global $wpi_checkout_id; |
1186 | 1186 | |
1187 | 1187 | $discounts = wpinv_get_cart_discounts(); |
1188 | - $discounts = array_filter( $discounts ); |
|
1188 | + $discounts = array_filter($discounts); |
|
1189 | 1189 | |
1190 | - if ( !empty( $discounts ) ) { |
|
1190 | + if (!empty($discounts)) { |
|
1191 | 1191 | $invalid = false; |
1192 | 1192 | |
1193 | - foreach ( $discounts as $key => $code ) { |
|
1194 | - if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) { |
|
1193 | + foreach ($discounts as $key => $code) { |
|
1194 | + if (!wpinv_is_discount_valid($code, (int) wpinv_get_user_id($wpi_checkout_id))) { |
|
1195 | 1195 | $invalid = true; |
1196 | 1196 | |
1197 | - wpinv_unset_cart_discount( $code ); |
|
1197 | + wpinv_unset_cart_discount($code); |
|
1198 | 1198 | } |
1199 | 1199 | } |
1200 | 1200 | |
1201 | - if ( $invalid ) { |
|
1201 | + if ($invalid) { |
|
1202 | 1202 | $errors = wpinv_get_errors(); |
1203 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1204 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
1205 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
1203 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1204 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
1205 | + wpinv_set_error('wpinv-discount-error', $error); |
|
1206 | 1206 | |
1207 | - wpinv_recalculate_tax( true ); |
|
1207 | + wpinv_recalculate_tax(true); |
|
1208 | 1208 | } |
1209 | 1209 | } |
1210 | 1210 | } |
1211 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
1211 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
1212 | 1212 | |
1213 | 1213 | function wpinv_discount_amount() { |
1214 | 1214 | $output = 0.00; |
1215 | 1215 | |
1216 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
1216 | + return apply_filters('wpinv_discount_amount', $output); |
|
1217 | 1217 | } |
@@ -15,320 +15,320 @@ |
||
15 | 15 | class GetPaid_Post_Types { |
16 | 16 | |
17 | 17 | /** |
18 | - * Hook in methods. |
|
19 | - */ |
|
20 | - public static function init() { |
|
21 | - add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 ); |
|
22 | - add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 ); |
|
23 | - add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | - add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
|
25 | - } |
|
18 | + * Hook in methods. |
|
19 | + */ |
|
20 | + public static function init() { |
|
21 | + add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 ); |
|
22 | + add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 ); |
|
23 | + add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | + add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Register core post types. |
|
29 | - */ |
|
30 | - public static function register_post_types() { |
|
27 | + /** |
|
28 | + * Register core post types. |
|
29 | + */ |
|
30 | + public static function register_post_types() { |
|
31 | 31 | |
32 | - if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
33 | - return; |
|
34 | - } |
|
32 | + if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
33 | + return; |
|
34 | + } |
|
35 | 35 | |
36 | - // Fires before registering post types. |
|
37 | - do_action( 'getpaid_register_post_types' ); |
|
36 | + // Fires before registering post types. |
|
37 | + do_action( 'getpaid_register_post_types' ); |
|
38 | 38 | |
39 | - // Register item post type. |
|
40 | - register_post_type( |
|
41 | - 'wpi_item', |
|
42 | - apply_filters( |
|
43 | - 'wpinv_register_post_type_invoice_item', |
|
44 | - array( |
|
45 | - 'labels' => array( |
|
46 | - 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
47 | - 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
48 | - 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
49 | - 'name_admin_bar' => _x( 'Item', 'add new on admin bar', 'invoicing' ), |
|
50 | - 'add_new' => _x( 'Add New', 'Item', 'invoicing' ), |
|
51 | - 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
52 | - 'new_item' => __( 'New Item', 'invoicing' ), |
|
53 | - 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
54 | - 'view_item' => __( 'View Item', 'invoicing' ), |
|
55 | - 'all_items' => __( 'Items', 'invoicing' ), |
|
56 | - 'search_items' => __( 'Search items', 'invoicing' ), |
|
57 | - 'parent_item_colon' => __( 'Parent item:', 'invoicing' ), |
|
58 | - 'not_found' => __( 'No items found.', 'invoicing' ), |
|
59 | - 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
60 | - ), |
|
61 | - 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
62 | - 'public' => false, |
|
63 | - 'has_archive' => false, |
|
64 | - '_builtin' => false, |
|
65 | - 'show_ui' => true, |
|
66 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
67 | - 'show_in_nav_menus' => false, |
|
68 | - 'supports' => array( 'title', 'excerpt' ), |
|
69 | - 'rewrite' => false, |
|
70 | - 'query_var' => false, |
|
71 | - 'capability_type' => 'wpi_item', |
|
72 | - 'map_meta_cap' => true, |
|
73 | - 'show_in_admin_bar' => true, |
|
74 | - 'can_export' => true, |
|
75 | - ) |
|
76 | - ) |
|
77 | - ); |
|
39 | + // Register item post type. |
|
40 | + register_post_type( |
|
41 | + 'wpi_item', |
|
42 | + apply_filters( |
|
43 | + 'wpinv_register_post_type_invoice_item', |
|
44 | + array( |
|
45 | + 'labels' => array( |
|
46 | + 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
47 | + 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
48 | + 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
49 | + 'name_admin_bar' => _x( 'Item', 'add new on admin bar', 'invoicing' ), |
|
50 | + 'add_new' => _x( 'Add New', 'Item', 'invoicing' ), |
|
51 | + 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
52 | + 'new_item' => __( 'New Item', 'invoicing' ), |
|
53 | + 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
54 | + 'view_item' => __( 'View Item', 'invoicing' ), |
|
55 | + 'all_items' => __( 'Items', 'invoicing' ), |
|
56 | + 'search_items' => __( 'Search items', 'invoicing' ), |
|
57 | + 'parent_item_colon' => __( 'Parent item:', 'invoicing' ), |
|
58 | + 'not_found' => __( 'No items found.', 'invoicing' ), |
|
59 | + 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
60 | + ), |
|
61 | + 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
62 | + 'public' => false, |
|
63 | + 'has_archive' => false, |
|
64 | + '_builtin' => false, |
|
65 | + 'show_ui' => true, |
|
66 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
67 | + 'show_in_nav_menus' => false, |
|
68 | + 'supports' => array( 'title', 'excerpt' ), |
|
69 | + 'rewrite' => false, |
|
70 | + 'query_var' => false, |
|
71 | + 'capability_type' => 'wpi_item', |
|
72 | + 'map_meta_cap' => true, |
|
73 | + 'show_in_admin_bar' => true, |
|
74 | + 'can_export' => true, |
|
75 | + ) |
|
76 | + ) |
|
77 | + ); |
|
78 | 78 | |
79 | - // Register payment form post type. |
|
80 | - register_post_type( |
|
81 | - 'wpi_payment_form', |
|
82 | - apply_filters( |
|
83 | - 'wpinv_register_post_type_payment_form', |
|
84 | - array( |
|
85 | - 'labels' => array( |
|
86 | - 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
87 | - 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
88 | - 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
89 | - 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
90 | - 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
91 | - 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
92 | - 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
93 | - 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
94 | - 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
95 | - 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
96 | - 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
97 | - 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
98 | - 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
99 | - 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
100 | - ), |
|
101 | - 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
102 | - 'public' => false, |
|
103 | - 'show_ui' => true, |
|
104 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
|
105 | - 'show_in_nav_menus' => false, |
|
106 | - 'query_var' => false, |
|
107 | - 'rewrite' => true, |
|
108 | - 'map_meta_cap' => true, |
|
109 | - 'has_archive' => false, |
|
110 | - 'hierarchical' => false, |
|
111 | - 'menu_position' => null, |
|
112 | - 'supports' => array( 'title' ), |
|
113 | - 'menu_icon' => 'dashicons-media-form', |
|
114 | - ) |
|
115 | - ) |
|
116 | - ); |
|
79 | + // Register payment form post type. |
|
80 | + register_post_type( |
|
81 | + 'wpi_payment_form', |
|
82 | + apply_filters( |
|
83 | + 'wpinv_register_post_type_payment_form', |
|
84 | + array( |
|
85 | + 'labels' => array( |
|
86 | + 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
87 | + 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
88 | + 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
89 | + 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
90 | + 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
91 | + 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
92 | + 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
93 | + 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
94 | + 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
95 | + 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
96 | + 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
97 | + 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
98 | + 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
99 | + 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
100 | + ), |
|
101 | + 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
102 | + 'public' => false, |
|
103 | + 'show_ui' => true, |
|
104 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
|
105 | + 'show_in_nav_menus' => false, |
|
106 | + 'query_var' => false, |
|
107 | + 'rewrite' => true, |
|
108 | + 'map_meta_cap' => true, |
|
109 | + 'has_archive' => false, |
|
110 | + 'hierarchical' => false, |
|
111 | + 'menu_position' => null, |
|
112 | + 'supports' => array( 'title' ), |
|
113 | + 'menu_icon' => 'dashicons-media-form', |
|
114 | + ) |
|
115 | + ) |
|
116 | + ); |
|
117 | 117 | |
118 | - // Register invoice post type. |
|
119 | - register_post_type( |
|
120 | - 'wpi_invoice', |
|
121 | - apply_filters( |
|
122 | - 'wpinv_register_post_type_invoice', |
|
123 | - array( |
|
124 | - 'labels' => array( |
|
125 | - 'name' => __( 'Invoices', 'invoicing' ), |
|
126 | - 'singular_name' => __( 'Invoice', 'invoicing' ), |
|
127 | - 'all_items' => __( 'Invoices', 'invoicing' ), |
|
128 | - 'menu_name' => _x( 'Invoices', 'Admin menu name', 'invoicing' ), |
|
129 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
130 | - 'add_new_item' => __( 'Add new invoice', 'invoicing' ), |
|
131 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
132 | - 'edit_item' => __( 'Edit invoice', 'invoicing' ), |
|
133 | - 'new_item' => __( 'New invoice', 'invoicing' ), |
|
134 | - 'view_item' => __( 'View invoice', 'invoicing' ), |
|
135 | - 'view_items' => __( 'View Invoices', 'invoicing' ), |
|
136 | - 'search_items' => __( 'Search invoices', 'invoicing' ), |
|
137 | - 'not_found' => __( 'No invoices found', 'invoicing' ), |
|
138 | - 'not_found_in_trash' => __( 'No invoices found in trash', 'invoicing' ), |
|
139 | - 'parent' => __( 'Parent invoice', 'invoicing' ), |
|
140 | - 'featured_image' => __( 'Invoice image', 'invoicing' ), |
|
141 | - 'set_featured_image' => __( 'Set invoice image', 'invoicing' ), |
|
142 | - 'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ), |
|
143 | - 'use_featured_image' => __( 'Use as invoice image', 'invoicing' ), |
|
144 | - 'insert_into_item' => __( 'Insert into invoice', 'invoicing' ), |
|
145 | - 'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ), |
|
146 | - 'filter_items_list' => __( 'Filter invoices', 'invoicing' ), |
|
147 | - 'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ), |
|
148 | - 'items_list' => __( 'Invoices list', 'invoicing' ), |
|
149 | - ), |
|
150 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
151 | - 'public' => true, |
|
152 | - 'has_archive' => false, |
|
153 | - 'publicly_queryable' => true, |
|
154 | - 'exclude_from_search' => true, |
|
155 | - 'show_ui' => true, |
|
156 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
157 | - 'show_in_nav_menus' => false, |
|
158 | - 'supports' => array( 'title', 'author', 'excerpt' ), |
|
159 | - 'rewrite' => true, |
|
160 | - 'query_var' => false, |
|
161 | - 'capability_type' => 'wpi_invoice', |
|
162 | - 'map_meta_cap' => true, |
|
163 | - 'show_in_admin_bar' => true, |
|
164 | - 'can_export' => true, |
|
165 | - 'hierarchical' => false, |
|
166 | - 'menu_position' => null, |
|
167 | - 'menu_icon' => 'dashicons-media-spreadsheet', |
|
168 | - ) |
|
169 | - ) |
|
170 | - ); |
|
118 | + // Register invoice post type. |
|
119 | + register_post_type( |
|
120 | + 'wpi_invoice', |
|
121 | + apply_filters( |
|
122 | + 'wpinv_register_post_type_invoice', |
|
123 | + array( |
|
124 | + 'labels' => array( |
|
125 | + 'name' => __( 'Invoices', 'invoicing' ), |
|
126 | + 'singular_name' => __( 'Invoice', 'invoicing' ), |
|
127 | + 'all_items' => __( 'Invoices', 'invoicing' ), |
|
128 | + 'menu_name' => _x( 'Invoices', 'Admin menu name', 'invoicing' ), |
|
129 | + 'add_new' => __( 'Add New', 'invoicing' ), |
|
130 | + 'add_new_item' => __( 'Add new invoice', 'invoicing' ), |
|
131 | + 'edit' => __( 'Edit', 'invoicing' ), |
|
132 | + 'edit_item' => __( 'Edit invoice', 'invoicing' ), |
|
133 | + 'new_item' => __( 'New invoice', 'invoicing' ), |
|
134 | + 'view_item' => __( 'View invoice', 'invoicing' ), |
|
135 | + 'view_items' => __( 'View Invoices', 'invoicing' ), |
|
136 | + 'search_items' => __( 'Search invoices', 'invoicing' ), |
|
137 | + 'not_found' => __( 'No invoices found', 'invoicing' ), |
|
138 | + 'not_found_in_trash' => __( 'No invoices found in trash', 'invoicing' ), |
|
139 | + 'parent' => __( 'Parent invoice', 'invoicing' ), |
|
140 | + 'featured_image' => __( 'Invoice image', 'invoicing' ), |
|
141 | + 'set_featured_image' => __( 'Set invoice image', 'invoicing' ), |
|
142 | + 'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ), |
|
143 | + 'use_featured_image' => __( 'Use as invoice image', 'invoicing' ), |
|
144 | + 'insert_into_item' => __( 'Insert into invoice', 'invoicing' ), |
|
145 | + 'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ), |
|
146 | + 'filter_items_list' => __( 'Filter invoices', 'invoicing' ), |
|
147 | + 'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ), |
|
148 | + 'items_list' => __( 'Invoices list', 'invoicing' ), |
|
149 | + ), |
|
150 | + 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
151 | + 'public' => true, |
|
152 | + 'has_archive' => false, |
|
153 | + 'publicly_queryable' => true, |
|
154 | + 'exclude_from_search' => true, |
|
155 | + 'show_ui' => true, |
|
156 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
157 | + 'show_in_nav_menus' => false, |
|
158 | + 'supports' => array( 'title', 'author', 'excerpt' ), |
|
159 | + 'rewrite' => true, |
|
160 | + 'query_var' => false, |
|
161 | + 'capability_type' => 'wpi_invoice', |
|
162 | + 'map_meta_cap' => true, |
|
163 | + 'show_in_admin_bar' => true, |
|
164 | + 'can_export' => true, |
|
165 | + 'hierarchical' => false, |
|
166 | + 'menu_position' => null, |
|
167 | + 'menu_icon' => 'dashicons-media-spreadsheet', |
|
168 | + ) |
|
169 | + ) |
|
170 | + ); |
|
171 | 171 | |
172 | - // Register discount post type. |
|
173 | - register_post_type( |
|
174 | - 'wpi_discount', |
|
175 | - apply_filters( |
|
176 | - 'wpinv_register_post_type_discount', |
|
177 | - array( |
|
178 | - 'labels' => array( |
|
179 | - 'name' => __( 'Discounts', 'invoicing' ), |
|
180 | - 'singular_name' => __( 'Discount', 'invoicing' ), |
|
181 | - 'all_items' => __( 'Discounts', 'invoicing' ), |
|
182 | - 'menu_name' => _x( 'Discounts', 'Admin menu name', 'invoicing' ), |
|
183 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
184 | - 'add_new_item' => __( 'Add new discount', 'invoicing' ), |
|
185 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
186 | - 'edit_item' => __( 'Edit discount', 'invoicing' ), |
|
187 | - 'new_item' => __( 'New discount', 'invoicing' ), |
|
188 | - 'view_item' => __( 'View discount', 'invoicing' ), |
|
189 | - 'view_items' => __( 'View Discounts', 'invoicing' ), |
|
190 | - 'search_items' => __( 'Search discounts', 'invoicing' ), |
|
191 | - 'not_found' => __( 'No discounts found', 'invoicing' ), |
|
192 | - 'not_found_in_trash' => __( 'No discounts found in trash', 'invoicing' ), |
|
193 | - 'parent' => __( 'Parent discount', 'invoicing' ), |
|
194 | - 'featured_image' => __( 'Discount image', 'invoicing' ), |
|
195 | - 'set_featured_image' => __( 'Set discount image', 'invoicing' ), |
|
196 | - 'remove_featured_image' => __( 'Remove discount image', 'invoicing' ), |
|
197 | - 'use_featured_image' => __( 'Use as discount image', 'invoicing' ), |
|
198 | - 'insert_into_item' => __( 'Insert into discount', 'invoicing' ), |
|
199 | - 'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ), |
|
200 | - 'filter_items_list' => __( 'Filter discounts', 'invoicing' ), |
|
201 | - 'items_list_navigation' => __( 'Discount navigation', 'invoicing' ), |
|
202 | - 'items_list' => __( 'Discounts list', 'invoicing' ), |
|
203 | - ), |
|
204 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
205 | - 'public' => false, |
|
206 | - 'can_export' => true, |
|
207 | - '_builtin' => false, |
|
208 | - 'publicly_queryable' => false, |
|
209 | - 'exclude_from_search'=> true, |
|
210 | - 'show_ui' => true, |
|
211 | - 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
212 | - 'query_var' => false, |
|
213 | - 'rewrite' => false, |
|
214 | - 'capability_type' => 'wpi_discount', |
|
215 | - 'map_meta_cap' => true, |
|
216 | - 'has_archive' => false, |
|
217 | - 'hierarchical' => false, |
|
218 | - 'supports' => array( 'title', 'excerpt' ), |
|
219 | - 'show_in_nav_menus' => false, |
|
220 | - 'show_in_admin_bar' => true, |
|
221 | - 'menu_position' => null, |
|
222 | - ) |
|
223 | - ) |
|
224 | - ); |
|
172 | + // Register discount post type. |
|
173 | + register_post_type( |
|
174 | + 'wpi_discount', |
|
175 | + apply_filters( |
|
176 | + 'wpinv_register_post_type_discount', |
|
177 | + array( |
|
178 | + 'labels' => array( |
|
179 | + 'name' => __( 'Discounts', 'invoicing' ), |
|
180 | + 'singular_name' => __( 'Discount', 'invoicing' ), |
|
181 | + 'all_items' => __( 'Discounts', 'invoicing' ), |
|
182 | + 'menu_name' => _x( 'Discounts', 'Admin menu name', 'invoicing' ), |
|
183 | + 'add_new' => __( 'Add New', 'invoicing' ), |
|
184 | + 'add_new_item' => __( 'Add new discount', 'invoicing' ), |
|
185 | + 'edit' => __( 'Edit', 'invoicing' ), |
|
186 | + 'edit_item' => __( 'Edit discount', 'invoicing' ), |
|
187 | + 'new_item' => __( 'New discount', 'invoicing' ), |
|
188 | + 'view_item' => __( 'View discount', 'invoicing' ), |
|
189 | + 'view_items' => __( 'View Discounts', 'invoicing' ), |
|
190 | + 'search_items' => __( 'Search discounts', 'invoicing' ), |
|
191 | + 'not_found' => __( 'No discounts found', 'invoicing' ), |
|
192 | + 'not_found_in_trash' => __( 'No discounts found in trash', 'invoicing' ), |
|
193 | + 'parent' => __( 'Parent discount', 'invoicing' ), |
|
194 | + 'featured_image' => __( 'Discount image', 'invoicing' ), |
|
195 | + 'set_featured_image' => __( 'Set discount image', 'invoicing' ), |
|
196 | + 'remove_featured_image' => __( 'Remove discount image', 'invoicing' ), |
|
197 | + 'use_featured_image' => __( 'Use as discount image', 'invoicing' ), |
|
198 | + 'insert_into_item' => __( 'Insert into discount', 'invoicing' ), |
|
199 | + 'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ), |
|
200 | + 'filter_items_list' => __( 'Filter discounts', 'invoicing' ), |
|
201 | + 'items_list_navigation' => __( 'Discount navigation', 'invoicing' ), |
|
202 | + 'items_list' => __( 'Discounts list', 'invoicing' ), |
|
203 | + ), |
|
204 | + 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
205 | + 'public' => false, |
|
206 | + 'can_export' => true, |
|
207 | + '_builtin' => false, |
|
208 | + 'publicly_queryable' => false, |
|
209 | + 'exclude_from_search'=> true, |
|
210 | + 'show_ui' => true, |
|
211 | + 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
|
212 | + 'query_var' => false, |
|
213 | + 'rewrite' => false, |
|
214 | + 'capability_type' => 'wpi_discount', |
|
215 | + 'map_meta_cap' => true, |
|
216 | + 'has_archive' => false, |
|
217 | + 'hierarchical' => false, |
|
218 | + 'supports' => array( 'title', 'excerpt' ), |
|
219 | + 'show_in_nav_menus' => false, |
|
220 | + 'show_in_admin_bar' => true, |
|
221 | + 'menu_position' => null, |
|
222 | + ) |
|
223 | + ) |
|
224 | + ); |
|
225 | 225 | |
226 | - do_action( 'getpaid_after_register_post_types' ); |
|
227 | - } |
|
226 | + do_action( 'getpaid_after_register_post_types' ); |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Register our custom post statuses. |
|
231 | - */ |
|
232 | - public static function register_post_status() { |
|
229 | + /** |
|
230 | + * Register our custom post statuses. |
|
231 | + */ |
|
232 | + public static function register_post_status() { |
|
233 | 233 | |
234 | - $invoice_statuses = apply_filters( |
|
235 | - 'getpaid_register_invoice_post_statuses', |
|
236 | - array( |
|
234 | + $invoice_statuses = apply_filters( |
|
235 | + 'getpaid_register_invoice_post_statuses', |
|
236 | + array( |
|
237 | 237 | |
238 | - 'wpi-pending' => array( |
|
239 | - 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
240 | - 'public' => true, |
|
241 | - 'exclude_from_search' => true, |
|
242 | - 'show_in_admin_all_list' => true, |
|
243 | - 'show_in_admin_status_list' => true, |
|
244 | - /* translators: %s: number of invoices */ |
|
245 | - 'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ) |
|
246 | - ), |
|
238 | + 'wpi-pending' => array( |
|
239 | + 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
240 | + 'public' => true, |
|
241 | + 'exclude_from_search' => true, |
|
242 | + 'show_in_admin_all_list' => true, |
|
243 | + 'show_in_admin_status_list' => true, |
|
244 | + /* translators: %s: number of invoices */ |
|
245 | + 'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ) |
|
246 | + ), |
|
247 | 247 | |
248 | - 'wpi-processing' => array( |
|
249 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
250 | - 'public' => true, |
|
251 | - 'exclude_from_search' => true, |
|
252 | - 'show_in_admin_all_list' => true, |
|
253 | - 'show_in_admin_status_list' => true, |
|
254 | - /* translators: %s: number of invoices */ |
|
255 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
256 | - ), |
|
248 | + 'wpi-processing' => array( |
|
249 | + 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
250 | + 'public' => true, |
|
251 | + 'exclude_from_search' => true, |
|
252 | + 'show_in_admin_all_list' => true, |
|
253 | + 'show_in_admin_status_list' => true, |
|
254 | + /* translators: %s: number of invoices */ |
|
255 | + 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
256 | + ), |
|
257 | 257 | |
258 | - 'wpi-onhold' => array( |
|
259 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
260 | - 'public' => true, |
|
261 | - 'exclude_from_search' => true, |
|
262 | - 'show_in_admin_all_list' => true, |
|
263 | - 'show_in_admin_status_list' => true, |
|
264 | - /* translators: %s: number of invoices */ |
|
265 | - 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
266 | - ), |
|
258 | + 'wpi-onhold' => array( |
|
259 | + 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
260 | + 'public' => true, |
|
261 | + 'exclude_from_search' => true, |
|
262 | + 'show_in_admin_all_list' => true, |
|
263 | + 'show_in_admin_status_list' => true, |
|
264 | + /* translators: %s: number of invoices */ |
|
265 | + 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
266 | + ), |
|
267 | 267 | |
268 | - 'wpi-cancelled' => array( |
|
269 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
270 | - 'public' => true, |
|
271 | - 'exclude_from_search' => true, |
|
272 | - 'show_in_admin_all_list' => true, |
|
273 | - 'show_in_admin_status_list' => true, |
|
274 | - /* translators: %s: number of invoices */ |
|
275 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
276 | - ), |
|
268 | + 'wpi-cancelled' => array( |
|
269 | + 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
270 | + 'public' => true, |
|
271 | + 'exclude_from_search' => true, |
|
272 | + 'show_in_admin_all_list' => true, |
|
273 | + 'show_in_admin_status_list' => true, |
|
274 | + /* translators: %s: number of invoices */ |
|
275 | + 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
276 | + ), |
|
277 | 277 | |
278 | - 'wpi-refunded' => array( |
|
279 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
280 | - 'public' => true, |
|
281 | - 'exclude_from_search' => true, |
|
282 | - 'show_in_admin_all_list' => true, |
|
283 | - 'show_in_admin_status_list' => true, |
|
284 | - /* translators: %s: number of invoices */ |
|
285 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
286 | - ), |
|
278 | + 'wpi-refunded' => array( |
|
279 | + 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
280 | + 'public' => true, |
|
281 | + 'exclude_from_search' => true, |
|
282 | + 'show_in_admin_all_list' => true, |
|
283 | + 'show_in_admin_status_list' => true, |
|
284 | + /* translators: %s: number of invoices */ |
|
285 | + 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
286 | + ), |
|
287 | 287 | |
288 | - 'wpi-failed' => array( |
|
289 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
290 | - 'public' => true, |
|
291 | - 'exclude_from_search' => true, |
|
292 | - 'show_in_admin_all_list' => true, |
|
293 | - 'show_in_admin_status_list' => true, |
|
294 | - /* translators: %s: number of invoices */ |
|
295 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
296 | - ), |
|
288 | + 'wpi-failed' => array( |
|
289 | + 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
290 | + 'public' => true, |
|
291 | + 'exclude_from_search' => true, |
|
292 | + 'show_in_admin_all_list' => true, |
|
293 | + 'show_in_admin_status_list' => true, |
|
294 | + /* translators: %s: number of invoices */ |
|
295 | + 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
296 | + ), |
|
297 | 297 | |
298 | - 'wpi-renewal' => array( |
|
299 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
300 | - 'public' => true, |
|
301 | - 'exclude_from_search' => true, |
|
302 | - 'show_in_admin_all_list' => true, |
|
303 | - 'show_in_admin_status_list' => true, |
|
304 | - /* translators: %s: number of invoices */ |
|
305 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
306 | - ) |
|
307 | - ) |
|
308 | - ); |
|
298 | + 'wpi-renewal' => array( |
|
299 | + 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
300 | + 'public' => true, |
|
301 | + 'exclude_from_search' => true, |
|
302 | + 'show_in_admin_all_list' => true, |
|
303 | + 'show_in_admin_status_list' => true, |
|
304 | + /* translators: %s: number of invoices */ |
|
305 | + 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
306 | + ) |
|
307 | + ) |
|
308 | + ); |
|
309 | 309 | |
310 | - foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
311 | - register_post_status( $invoice_statuse, $args ); |
|
312 | - } |
|
313 | - } |
|
310 | + foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
311 | + register_post_status( $invoice_statuse, $args ); |
|
312 | + } |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
316 | - * Flush rewrite rules. |
|
317 | - */ |
|
318 | - public static function flush_rewrite_rules() { |
|
319 | - flush_rewrite_rules(); |
|
320 | - } |
|
315 | + /** |
|
316 | + * Flush rewrite rules. |
|
317 | + */ |
|
318 | + public static function flush_rewrite_rules() { |
|
319 | + flush_rewrite_rules(); |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * Flush rules to prevent 404. |
|
324 | - * |
|
325 | - */ |
|
326 | - public static function maybe_flush_rewrite_rules() { |
|
327 | - if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
328 | - update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
329 | - self::flush_rewrite_rules(); |
|
330 | - } |
|
331 | - } |
|
322 | + /** |
|
323 | + * Flush rules to prevent 404. |
|
324 | + * |
|
325 | + */ |
|
326 | + public static function maybe_flush_rewrite_rules() { |
|
327 | + if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
328 | + update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
329 | + self::flush_rewrite_rules(); |
|
330 | + } |
|
331 | + } |
|
332 | 332 | |
333 | 333 | } |
334 | 334 | GetPaid_Post_Types::init(); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Post types Class |
@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | * Hook in methods. |
19 | 19 | */ |
20 | 20 | public static function init() { |
21 | - add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 ); |
|
22 | - add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 ); |
|
23 | - add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | - add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) ); |
|
21 | + add_action('init', array(__CLASS__, 'register_post_types'), 1); |
|
22 | + add_action('init', array(__CLASS__, 'register_post_status'), 4); |
|
23 | + add_action('getpaid_flush_rewrite_rules', array(__CLASS__, 'flush_rewrite_rules')); |
|
24 | + add_action('getpaid_after_register_post_types', array(__CLASS__, 'maybe_flush_rewrite_rules')); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -29,12 +29,12 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public static function register_post_types() { |
31 | 31 | |
32 | - if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) { |
|
32 | + if (!is_blog_installed() || post_type_exists('wpi_item')) { |
|
33 | 33 | return; |
34 | 34 | } |
35 | 35 | |
36 | 36 | // Fires before registering post types. |
37 | - do_action( 'getpaid_register_post_types' ); |
|
37 | + do_action('getpaid_register_post_types'); |
|
38 | 38 | |
39 | 39 | // Register item post type. |
40 | 40 | register_post_type( |
@@ -43,29 +43,29 @@ discard block |
||
43 | 43 | 'wpinv_register_post_type_invoice_item', |
44 | 44 | array( |
45 | 45 | 'labels' => array( |
46 | - 'name' => _x( 'Items', 'post type general name', 'invoicing' ), |
|
47 | - 'singular_name' => _x( 'Item', 'post type singular name', 'invoicing' ), |
|
48 | - 'menu_name' => _x( 'Items', 'admin menu', 'invoicing' ), |
|
49 | - 'name_admin_bar' => _x( 'Item', 'add new on admin bar', 'invoicing' ), |
|
50 | - 'add_new' => _x( 'Add New', 'Item', 'invoicing' ), |
|
51 | - 'add_new_item' => __( 'Add New Item', 'invoicing' ), |
|
52 | - 'new_item' => __( 'New Item', 'invoicing' ), |
|
53 | - 'edit_item' => __( 'Edit Item', 'invoicing' ), |
|
54 | - 'view_item' => __( 'View Item', 'invoicing' ), |
|
55 | - 'all_items' => __( 'Items', 'invoicing' ), |
|
56 | - 'search_items' => __( 'Search items', 'invoicing' ), |
|
57 | - 'parent_item_colon' => __( 'Parent item:', 'invoicing' ), |
|
58 | - 'not_found' => __( 'No items found.', 'invoicing' ), |
|
59 | - 'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' ) |
|
46 | + 'name' => _x('Items', 'post type general name', 'invoicing'), |
|
47 | + 'singular_name' => _x('Item', 'post type singular name', 'invoicing'), |
|
48 | + 'menu_name' => _x('Items', 'admin menu', 'invoicing'), |
|
49 | + 'name_admin_bar' => _x('Item', 'add new on admin bar', 'invoicing'), |
|
50 | + 'add_new' => _x('Add New', 'Item', 'invoicing'), |
|
51 | + 'add_new_item' => __('Add New Item', 'invoicing'), |
|
52 | + 'new_item' => __('New Item', 'invoicing'), |
|
53 | + 'edit_item' => __('Edit Item', 'invoicing'), |
|
54 | + 'view_item' => __('View Item', 'invoicing'), |
|
55 | + 'all_items' => __('Items', 'invoicing'), |
|
56 | + 'search_items' => __('Search items', 'invoicing'), |
|
57 | + 'parent_item_colon' => __('Parent item:', 'invoicing'), |
|
58 | + 'not_found' => __('No items found.', 'invoicing'), |
|
59 | + 'not_found_in_trash' => __('No items found in trash.', 'invoicing') |
|
60 | 60 | ), |
61 | - 'description' => __( 'This is where you can add new invoice items.', 'invoicing' ), |
|
61 | + 'description' => __('This is where you can add new invoice items.', 'invoicing'), |
|
62 | 62 | 'public' => false, |
63 | 63 | 'has_archive' => false, |
64 | 64 | '_builtin' => false, |
65 | 65 | 'show_ui' => true, |
66 | 66 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
67 | 67 | 'show_in_nav_menus' => false, |
68 | - 'supports' => array( 'title', 'excerpt' ), |
|
68 | + 'supports' => array('title', 'excerpt'), |
|
69 | 69 | 'rewrite' => false, |
70 | 70 | 'query_var' => false, |
71 | 71 | 'capability_type' => 'wpi_item', |
@@ -83,22 +83,22 @@ discard block |
||
83 | 83 | 'wpinv_register_post_type_payment_form', |
84 | 84 | array( |
85 | 85 | 'labels' => array( |
86 | - 'name' => _x( 'Payment Forms', 'post type general name', 'invoicing' ), |
|
87 | - 'singular_name' => _x( 'Payment Form', 'post type singular name', 'invoicing' ), |
|
88 | - 'menu_name' => _x( 'Payment Forms', 'admin menu', 'invoicing' ), |
|
89 | - 'name_admin_bar' => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ), |
|
90 | - 'add_new' => _x( 'Add New', 'Payment Form', 'invoicing' ), |
|
91 | - 'add_new_item' => __( 'Add New Payment Form', 'invoicing' ), |
|
92 | - 'new_item' => __( 'New Payment Form', 'invoicing' ), |
|
93 | - 'edit_item' => __( 'Edit Payment Form', 'invoicing' ), |
|
94 | - 'view_item' => __( 'View Payment Form', 'invoicing' ), |
|
95 | - 'all_items' => __( 'Payment Forms', 'invoicing' ), |
|
96 | - 'search_items' => __( 'Search Payment Forms', 'invoicing' ), |
|
97 | - 'parent_item_colon' => __( 'Parent Payment Forms:', 'invoicing' ), |
|
98 | - 'not_found' => __( 'No payment forms found.', 'invoicing' ), |
|
99 | - 'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' ) |
|
86 | + 'name' => _x('Payment Forms', 'post type general name', 'invoicing'), |
|
87 | + 'singular_name' => _x('Payment Form', 'post type singular name', 'invoicing'), |
|
88 | + 'menu_name' => _x('Payment Forms', 'admin menu', 'invoicing'), |
|
89 | + 'name_admin_bar' => _x('Payment Form', 'add new on admin bar', 'invoicing'), |
|
90 | + 'add_new' => _x('Add New', 'Payment Form', 'invoicing'), |
|
91 | + 'add_new_item' => __('Add New Payment Form', 'invoicing'), |
|
92 | + 'new_item' => __('New Payment Form', 'invoicing'), |
|
93 | + 'edit_item' => __('Edit Payment Form', 'invoicing'), |
|
94 | + 'view_item' => __('View Payment Form', 'invoicing'), |
|
95 | + 'all_items' => __('Payment Forms', 'invoicing'), |
|
96 | + 'search_items' => __('Search Payment Forms', 'invoicing'), |
|
97 | + 'parent_item_colon' => __('Parent Payment Forms:', 'invoicing'), |
|
98 | + 'not_found' => __('No payment forms found.', 'invoicing'), |
|
99 | + 'not_found_in_trash' => __('No payment forms found in trash.', 'invoicing') |
|
100 | 100 | ), |
101 | - 'description' => __( 'Add new payment forms.', 'invoicing' ), |
|
101 | + 'description' => __('Add new payment forms.', 'invoicing'), |
|
102 | 102 | 'public' => false, |
103 | 103 | 'show_ui' => true, |
104 | 104 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true, |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | 'has_archive' => false, |
110 | 110 | 'hierarchical' => false, |
111 | 111 | 'menu_position' => null, |
112 | - 'supports' => array( 'title' ), |
|
112 | + 'supports' => array('title'), |
|
113 | 113 | 'menu_icon' => 'dashicons-media-form', |
114 | 114 | ) |
115 | 115 | ) |
@@ -122,32 +122,32 @@ discard block |
||
122 | 122 | 'wpinv_register_post_type_invoice', |
123 | 123 | array( |
124 | 124 | 'labels' => array( |
125 | - 'name' => __( 'Invoices', 'invoicing' ), |
|
126 | - 'singular_name' => __( 'Invoice', 'invoicing' ), |
|
127 | - 'all_items' => __( 'Invoices', 'invoicing' ), |
|
128 | - 'menu_name' => _x( 'Invoices', 'Admin menu name', 'invoicing' ), |
|
129 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
130 | - 'add_new_item' => __( 'Add new invoice', 'invoicing' ), |
|
131 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
132 | - 'edit_item' => __( 'Edit invoice', 'invoicing' ), |
|
133 | - 'new_item' => __( 'New invoice', 'invoicing' ), |
|
134 | - 'view_item' => __( 'View invoice', 'invoicing' ), |
|
135 | - 'view_items' => __( 'View Invoices', 'invoicing' ), |
|
136 | - 'search_items' => __( 'Search invoices', 'invoicing' ), |
|
137 | - 'not_found' => __( 'No invoices found', 'invoicing' ), |
|
138 | - 'not_found_in_trash' => __( 'No invoices found in trash', 'invoicing' ), |
|
139 | - 'parent' => __( 'Parent invoice', 'invoicing' ), |
|
140 | - 'featured_image' => __( 'Invoice image', 'invoicing' ), |
|
141 | - 'set_featured_image' => __( 'Set invoice image', 'invoicing' ), |
|
142 | - 'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ), |
|
143 | - 'use_featured_image' => __( 'Use as invoice image', 'invoicing' ), |
|
144 | - 'insert_into_item' => __( 'Insert into invoice', 'invoicing' ), |
|
145 | - 'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ), |
|
146 | - 'filter_items_list' => __( 'Filter invoices', 'invoicing' ), |
|
147 | - 'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ), |
|
148 | - 'items_list' => __( 'Invoices list', 'invoicing' ), |
|
125 | + 'name' => __('Invoices', 'invoicing'), |
|
126 | + 'singular_name' => __('Invoice', 'invoicing'), |
|
127 | + 'all_items' => __('Invoices', 'invoicing'), |
|
128 | + 'menu_name' => _x('Invoices', 'Admin menu name', 'invoicing'), |
|
129 | + 'add_new' => __('Add New', 'invoicing'), |
|
130 | + 'add_new_item' => __('Add new invoice', 'invoicing'), |
|
131 | + 'edit' => __('Edit', 'invoicing'), |
|
132 | + 'edit_item' => __('Edit invoice', 'invoicing'), |
|
133 | + 'new_item' => __('New invoice', 'invoicing'), |
|
134 | + 'view_item' => __('View invoice', 'invoicing'), |
|
135 | + 'view_items' => __('View Invoices', 'invoicing'), |
|
136 | + 'search_items' => __('Search invoices', 'invoicing'), |
|
137 | + 'not_found' => __('No invoices found', 'invoicing'), |
|
138 | + 'not_found_in_trash' => __('No invoices found in trash', 'invoicing'), |
|
139 | + 'parent' => __('Parent invoice', 'invoicing'), |
|
140 | + 'featured_image' => __('Invoice image', 'invoicing'), |
|
141 | + 'set_featured_image' => __('Set invoice image', 'invoicing'), |
|
142 | + 'remove_featured_image' => __('Remove invoice image', 'invoicing'), |
|
143 | + 'use_featured_image' => __('Use as invoice image', 'invoicing'), |
|
144 | + 'insert_into_item' => __('Insert into invoice', 'invoicing'), |
|
145 | + 'uploaded_to_this_item' => __('Uploaded to this invoice', 'invoicing'), |
|
146 | + 'filter_items_list' => __('Filter invoices', 'invoicing'), |
|
147 | + 'items_list_navigation' => __('Invoices navigation', 'invoicing'), |
|
148 | + 'items_list' => __('Invoices list', 'invoicing'), |
|
149 | 149 | ), |
150 | - 'description' => __( 'This is where invoices are stored.', 'invoicing' ), |
|
150 | + 'description' => __('This is where invoices are stored.', 'invoicing'), |
|
151 | 151 | 'public' => true, |
152 | 152 | 'has_archive' => false, |
153 | 153 | 'publicly_queryable' => true, |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | 'show_ui' => true, |
156 | 156 | 'show_in_menu' => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false, |
157 | 157 | 'show_in_nav_menus' => false, |
158 | - 'supports' => array( 'title', 'author', 'excerpt' ), |
|
158 | + 'supports' => array('title', 'author', 'excerpt'), |
|
159 | 159 | 'rewrite' => true, |
160 | 160 | 'query_var' => false, |
161 | 161 | 'capability_type' => 'wpi_invoice', |
@@ -176,32 +176,32 @@ discard block |
||
176 | 176 | 'wpinv_register_post_type_discount', |
177 | 177 | array( |
178 | 178 | 'labels' => array( |
179 | - 'name' => __( 'Discounts', 'invoicing' ), |
|
180 | - 'singular_name' => __( 'Discount', 'invoicing' ), |
|
181 | - 'all_items' => __( 'Discounts', 'invoicing' ), |
|
182 | - 'menu_name' => _x( 'Discounts', 'Admin menu name', 'invoicing' ), |
|
183 | - 'add_new' => __( 'Add New', 'invoicing' ), |
|
184 | - 'add_new_item' => __( 'Add new discount', 'invoicing' ), |
|
185 | - 'edit' => __( 'Edit', 'invoicing' ), |
|
186 | - 'edit_item' => __( 'Edit discount', 'invoicing' ), |
|
187 | - 'new_item' => __( 'New discount', 'invoicing' ), |
|
188 | - 'view_item' => __( 'View discount', 'invoicing' ), |
|
189 | - 'view_items' => __( 'View Discounts', 'invoicing' ), |
|
190 | - 'search_items' => __( 'Search discounts', 'invoicing' ), |
|
191 | - 'not_found' => __( 'No discounts found', 'invoicing' ), |
|
192 | - 'not_found_in_trash' => __( 'No discounts found in trash', 'invoicing' ), |
|
193 | - 'parent' => __( 'Parent discount', 'invoicing' ), |
|
194 | - 'featured_image' => __( 'Discount image', 'invoicing' ), |
|
195 | - 'set_featured_image' => __( 'Set discount image', 'invoicing' ), |
|
196 | - 'remove_featured_image' => __( 'Remove discount image', 'invoicing' ), |
|
197 | - 'use_featured_image' => __( 'Use as discount image', 'invoicing' ), |
|
198 | - 'insert_into_item' => __( 'Insert into discount', 'invoicing' ), |
|
199 | - 'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ), |
|
200 | - 'filter_items_list' => __( 'Filter discounts', 'invoicing' ), |
|
201 | - 'items_list_navigation' => __( 'Discount navigation', 'invoicing' ), |
|
202 | - 'items_list' => __( 'Discounts list', 'invoicing' ), |
|
179 | + 'name' => __('Discounts', 'invoicing'), |
|
180 | + 'singular_name' => __('Discount', 'invoicing'), |
|
181 | + 'all_items' => __('Discounts', 'invoicing'), |
|
182 | + 'menu_name' => _x('Discounts', 'Admin menu name', 'invoicing'), |
|
183 | + 'add_new' => __('Add New', 'invoicing'), |
|
184 | + 'add_new_item' => __('Add new discount', 'invoicing'), |
|
185 | + 'edit' => __('Edit', 'invoicing'), |
|
186 | + 'edit_item' => __('Edit discount', 'invoicing'), |
|
187 | + 'new_item' => __('New discount', 'invoicing'), |
|
188 | + 'view_item' => __('View discount', 'invoicing'), |
|
189 | + 'view_items' => __('View Discounts', 'invoicing'), |
|
190 | + 'search_items' => __('Search discounts', 'invoicing'), |
|
191 | + 'not_found' => __('No discounts found', 'invoicing'), |
|
192 | + 'not_found_in_trash' => __('No discounts found in trash', 'invoicing'), |
|
193 | + 'parent' => __('Parent discount', 'invoicing'), |
|
194 | + 'featured_image' => __('Discount image', 'invoicing'), |
|
195 | + 'set_featured_image' => __('Set discount image', 'invoicing'), |
|
196 | + 'remove_featured_image' => __('Remove discount image', 'invoicing'), |
|
197 | + 'use_featured_image' => __('Use as discount image', 'invoicing'), |
|
198 | + 'insert_into_item' => __('Insert into discount', 'invoicing'), |
|
199 | + 'uploaded_to_this_item' => __('Uploaded to this discount', 'invoicing'), |
|
200 | + 'filter_items_list' => __('Filter discounts', 'invoicing'), |
|
201 | + 'items_list_navigation' => __('Discount navigation', 'invoicing'), |
|
202 | + 'items_list' => __('Discounts list', 'invoicing'), |
|
203 | 203 | ), |
204 | - 'description' => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ), |
|
204 | + 'description' => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'), |
|
205 | 205 | 'public' => false, |
206 | 206 | 'can_export' => true, |
207 | 207 | '_builtin' => false, |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | 'map_meta_cap' => true, |
216 | 216 | 'has_archive' => false, |
217 | 217 | 'hierarchical' => false, |
218 | - 'supports' => array( 'title', 'excerpt' ), |
|
218 | + 'supports' => array('title', 'excerpt'), |
|
219 | 219 | 'show_in_nav_menus' => false, |
220 | 220 | 'show_in_admin_bar' => true, |
221 | 221 | 'menu_position' => null, |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | ) |
224 | 224 | ); |
225 | 225 | |
226 | - do_action( 'getpaid_after_register_post_types' ); |
|
226 | + do_action('getpaid_after_register_post_types'); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
@@ -236,79 +236,79 @@ discard block |
||
236 | 236 | array( |
237 | 237 | |
238 | 238 | 'wpi-pending' => array( |
239 | - 'label' => _x( 'Pending Payment', 'Invoice status', 'invoicing' ), |
|
239 | + 'label' => _x('Pending Payment', 'Invoice status', 'invoicing'), |
|
240 | 240 | 'public' => true, |
241 | 241 | 'exclude_from_search' => true, |
242 | 242 | 'show_in_admin_all_list' => true, |
243 | 243 | 'show_in_admin_status_list' => true, |
244 | 244 | /* translators: %s: number of invoices */ |
245 | - 'label_count' => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' ) |
|
245 | + 'label_count' => _n_noop('Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing') |
|
246 | 246 | ), |
247 | 247 | |
248 | 248 | 'wpi-processing' => array( |
249 | - 'label' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
249 | + 'label' => _x('Processing', 'Invoice status', 'invoicing'), |
|
250 | 250 | 'public' => true, |
251 | 251 | 'exclude_from_search' => true, |
252 | 252 | 'show_in_admin_all_list' => true, |
253 | 253 | 'show_in_admin_status_list' => true, |
254 | 254 | /* translators: %s: number of invoices */ |
255 | - 'label_count' => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' ) |
|
255 | + 'label_count' => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing') |
|
256 | 256 | ), |
257 | 257 | |
258 | 258 | 'wpi-onhold' => array( |
259 | - 'label' => _x( 'On Hold', 'Invoice status', 'invoicing' ), |
|
259 | + 'label' => _x('On Hold', 'Invoice status', 'invoicing'), |
|
260 | 260 | 'public' => true, |
261 | 261 | 'exclude_from_search' => true, |
262 | 262 | 'show_in_admin_all_list' => true, |
263 | 263 | 'show_in_admin_status_list' => true, |
264 | 264 | /* translators: %s: number of invoices */ |
265 | - 'label_count' => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' ) |
|
265 | + 'label_count' => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing') |
|
266 | 266 | ), |
267 | 267 | |
268 | 268 | 'wpi-cancelled' => array( |
269 | - 'label' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
269 | + 'label' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
270 | 270 | 'public' => true, |
271 | 271 | 'exclude_from_search' => true, |
272 | 272 | 'show_in_admin_all_list' => true, |
273 | 273 | 'show_in_admin_status_list' => true, |
274 | 274 | /* translators: %s: number of invoices */ |
275 | - 'label_count' => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' ) |
|
275 | + 'label_count' => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing') |
|
276 | 276 | ), |
277 | 277 | |
278 | 278 | 'wpi-refunded' => array( |
279 | - 'label' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
279 | + 'label' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
280 | 280 | 'public' => true, |
281 | 281 | 'exclude_from_search' => true, |
282 | 282 | 'show_in_admin_all_list' => true, |
283 | 283 | 'show_in_admin_status_list' => true, |
284 | 284 | /* translators: %s: number of invoices */ |
285 | - 'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' ) |
|
285 | + 'label_count' => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing') |
|
286 | 286 | ), |
287 | 287 | |
288 | 288 | 'wpi-failed' => array( |
289 | - 'label' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
289 | + 'label' => _x('Failed', 'Invoice status', 'invoicing'), |
|
290 | 290 | 'public' => true, |
291 | 291 | 'exclude_from_search' => true, |
292 | 292 | 'show_in_admin_all_list' => true, |
293 | 293 | 'show_in_admin_status_list' => true, |
294 | 294 | /* translators: %s: number of invoices */ |
295 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' ) |
|
295 | + 'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing') |
|
296 | 296 | ), |
297 | 297 | |
298 | 298 | 'wpi-renewal' => array( |
299 | - 'label' => _x( 'Renewal', 'Invoice status', 'invoicing' ), |
|
299 | + 'label' => _x('Renewal', 'Invoice status', 'invoicing'), |
|
300 | 300 | 'public' => true, |
301 | 301 | 'exclude_from_search' => true, |
302 | 302 | 'show_in_admin_all_list' => true, |
303 | 303 | 'show_in_admin_status_list' => true, |
304 | 304 | /* translators: %s: number of invoices */ |
305 | - 'label_count' => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' ) |
|
305 | + 'label_count' => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing') |
|
306 | 306 | ) |
307 | 307 | ) |
308 | 308 | ); |
309 | 309 | |
310 | - foreach ( $invoice_statuses as $invoice_statuse => $args ) { |
|
311 | - register_post_status( $invoice_statuse, $args ); |
|
310 | + foreach ($invoice_statuses as $invoice_statuse => $args) { |
|
311 | + register_post_status($invoice_statuse, $args); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | * |
325 | 325 | */ |
326 | 326 | public static function maybe_flush_rewrite_rules() { |
327 | - if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) { |
|
328 | - update_option( 'getpaid_flushed_rewrite_rules', '1' ); |
|
327 | + if (!get_option('getpaid_flushed_rewrite_rules')) { |
|
328 | + update_option('getpaid_flushed_rewrite_rules', '1'); |
|
329 | 329 | self::flush_rewrite_rules(); |
330 | 330 | } |
331 | 331 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,20 +21,20 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the item. |
27 | - $item = new WPInv_Item( $post ); |
|
27 | + $item = new WPInv_Item($post); |
|
28 | 28 | |
29 | 29 | ?> |
30 | 30 | |
31 | 31 | <div class='bsui' style='padding-top: 10px;'> |
32 | - <?php do_action( 'wpinv_item_before_info_metabox', $item ); ?> |
|
32 | + <?php do_action('wpinv_item_before_info_metabox', $item); ?> |
|
33 | 33 | |
34 | 34 | <div class="wpinv_item_type form-group row"> |
35 | 35 | <label for="wpinv_item_type" class="col-sm-12 col-form-label"> |
36 | - <?php _e( 'Item Type', 'invoicing' );?> |
|
37 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( self::get_tooltip( $post ) ); ?>"></span> |
|
36 | + <?php _e('Item Type', 'invoicing'); ?> |
|
37 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e(self::get_tooltip($post)); ?>"></span> |
|
38 | 38 | </label> |
39 | 39 | |
40 | 40 | <div class="col-sm-12"> |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | array( |
45 | 45 | 'id' => 'wpinv_item_type', |
46 | 46 | 'name' => 'wpinv_item_type', |
47 | - 'placeholder' => __( 'Select item type', 'invoicing' ), |
|
48 | - 'value' => $item->get_type( 'edit' ), |
|
47 | + 'placeholder' => __('Select item type', 'invoicing'), |
|
48 | + 'value' => $item->get_type('edit'), |
|
49 | 49 | 'select2' => true, |
50 | 50 | 'data-allow-clear' => 'false', |
51 | 51 | 'no_wrap' => true, |
@@ -59,38 +59,38 @@ discard block |
||
59 | 59 | |
60 | 60 | <div class="wpinv_item_shortcode form-group row"> |
61 | 61 | <label for="wpinv_item_shortcode" class="col-sm-12 col-form-label"> |
62 | - <?php _e( 'Payment Form Shortcode', 'invoicing' );?> |
|
63 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Displays a payment form', 'invoicing' ); ?>"></span> |
|
62 | + <?php _e('Payment Form Shortcode', 'invoicing'); ?> |
|
63 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Displays a payment form', 'invoicing'); ?>"></span> |
|
64 | 64 | </label> |
65 | 65 | |
66 | 66 | <div class="col-sm-12"> |
67 | - <input onClick="this.select()" type="text" id="wpinv_item_shortcode" value="[getpaid item=<?php echo esc_attr( $item->get_id() ); ?>]" style="width: 100%;" readonly/> |
|
67 | + <input onClick="this.select()" type="text" id="wpinv_item_shortcode" value="[getpaid item=<?php echo esc_attr($item->get_id()); ?>]" style="width: 100%;" readonly/> |
|
68 | 68 | </div> |
69 | 69 | </div> |
70 | 70 | |
71 | 71 | <div class="wpinv_item_buy_shortcode form-group row"> |
72 | 72 | <label for="wpinv_item_button_shortcode" class="col-sm-12 col-form-label"> |
73 | - <?php _e( 'Payment Button Shortcode', 'invoicing' );?> |
|
74 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Displays a buy now button', 'invoicing' ); ?>"></span> |
|
73 | + <?php _e('Payment Button Shortcode', 'invoicing'); ?> |
|
74 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Displays a buy now button', 'invoicing'); ?>"></span> |
|
75 | 75 | </label> |
76 | 76 | |
77 | 77 | <div class="col-sm-12"> |
78 | - <input onClick="this.select()" type="text" id="wpinv_item_button_shortcode" value="[getpaid item=<?php echo esc_attr( $item->get_id() ); ?> button='Buy Now']" style="width: 100%;" readonly/> |
|
78 | + <input onClick="this.select()" type="text" id="wpinv_item_button_shortcode" value="[getpaid item=<?php echo esc_attr($item->get_id()); ?> button='Buy Now']" style="width: 100%;" readonly/> |
|
79 | 79 | </div> |
80 | 80 | </div> |
81 | 81 | |
82 | 82 | <div class="wpinv_item_custom_id form-group"> |
83 | - <?php _e( 'Custom ID', 'invoicing' );?> — <?php echo sanitize_text_field( $item->get_custom_id() ) ?> |
|
83 | + <?php _e('Custom ID', 'invoicing'); ?> — <?php echo sanitize_text_field($item->get_custom_id()) ?> |
|
84 | 84 | </div> |
85 | 85 | |
86 | - <?php do_action( 'wpinv_meta_values_metabox_before', $post ); ?> |
|
87 | - <?php foreach ( apply_filters( 'wpinv_show_meta_values_for_keys', array() ) as $meta_key ) : ?> |
|
86 | + <?php do_action('wpinv_meta_values_metabox_before', $post); ?> |
|
87 | + <?php foreach (apply_filters('wpinv_show_meta_values_for_keys', array()) as $meta_key) : ?> |
|
88 | 88 | <div class="wpinv_item_custom_id form-group"> |
89 | - <?php sanitize_text_field( $meta_key );?> — <?php echo sanitize_text_field( get_post_meta( $item->get_id(), '_wpinv_' . $meta_key, true ) ); ?> |
|
89 | + <?php sanitize_text_field($meta_key); ?> — <?php echo sanitize_text_field(get_post_meta($item->get_id(), '_wpinv_' . $meta_key, true)); ?> |
|
90 | 90 | </div> |
91 | 91 | <?php endforeach; ?> |
92 | - <?php do_action( 'wpinv_meta_values_metabox_after', $post ); ?> |
|
93 | - <?php do_action( 'wpinv_item_info_metabox', $item ); ?> |
|
92 | + <?php do_action('wpinv_meta_values_metabox_after', $post); ?> |
|
93 | + <?php do_action('wpinv_item_info_metabox', $item); ?> |
|
94 | 94 | </div> |
95 | 95 | <?php |
96 | 96 | |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | * Returns item type tolltip. |
101 | 101 | * |
102 | 102 | */ |
103 | - public static function get_tooltip( $post ) { |
|
103 | + public static function get_tooltip($post) { |
|
104 | 104 | |
105 | 105 | ob_start(); |
106 | 106 | ?> |
107 | 107 | |
108 | - <?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br> <br> |
|
109 | - <?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc', 'invoicing' );?><br> <br> |
|
108 | + <?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br> <br> |
|
109 | + <?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc', 'invoicing'); ?><br> <br> |
|
110 | 110 | |
111 | 111 | <?php |
112 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
112 | + do_action('wpinv_item_info_metabox_after', $post); |
|
113 | 113 | |
114 | 114 | return ob_get_clean(); |
115 | 115 |
@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
8 | -function wpinv_discount_custom_column( $column ) { |
|
7 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
8 | +function wpinv_discount_custom_column($column) { |
|
9 | 9 | global $post; |
10 | 10 | |
11 | - $discount = new WPInv_Discount( $post ); |
|
11 | + $discount = new WPInv_Discount($post); |
|
12 | 12 | |
13 | - switch ( $column ) { |
|
13 | + switch ($column) { |
|
14 | 14 | case 'code' : |
15 | 15 | echo $discount->get_code(); |
16 | 16 | break; |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | echo $discount->get_usage(); |
22 | 22 | break; |
23 | 23 | case 'start_date' : |
24 | - if ( $discount->has_start_date() ) { |
|
25 | - $value = date_i18n( get_option( 'date_format' ), strtotime( $discount->get_start_date() ) ); |
|
24 | + if ($discount->has_start_date()) { |
|
25 | + $value = date_i18n(get_option('date_format'), strtotime($discount->get_start_date())); |
|
26 | 26 | } else { |
27 | 27 | $value = '—'; |
28 | 28 | } |
@@ -30,10 +30,10 @@ discard block |
||
30 | 30 | echo $value; |
31 | 31 | break; |
32 | 32 | case 'expiry_date' : |
33 | - if ( $discount->has_expiration_date() ) { |
|
34 | - $value = date_i18n( get_option( 'date_format' ), strtotime( $discount->get_expiration_date() ) ); |
|
33 | + if ($discount->has_expiration_date()) { |
|
34 | + $value = date_i18n(get_option('date_format'), strtotime($discount->get_expiration_date())); |
|
35 | 35 | } else { |
36 | - $value = __( 'Never', 'invoicing' ); |
|
36 | + $value = __('Never', 'invoicing'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | echo $value; |
@@ -41,30 +41,30 @@ discard block |
||
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
45 | -function wpinv_post_row_actions( $actions, $post ) { |
|
46 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
44 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
45 | +function wpinv_post_row_actions($actions, $post) { |
|
46 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
47 | 47 | |
48 | - if ( $post_type == 'wpi_invoice' ) { |
|
48 | + if ($post_type == 'wpi_invoice') { |
|
49 | 49 | $actions = array(); |
50 | 50 | } |
51 | 51 | |
52 | - if ( $post_type == 'wpi_discount' ) { |
|
53 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
52 | + if ($post_type == 'wpi_discount') { |
|
53 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $actions; |
57 | 57 | } |
58 | 58 | |
59 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
60 | - $row_actions = array(); |
|
61 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
62 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
59 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
60 | + $row_actions = array(); |
|
61 | + $edit_link = get_edit_post_link($discount->ID); |
|
62 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
63 | 63 | |
64 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
65 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>'; |
|
66 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
67 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>'; |
|
64 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
65 | + $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; |
|
66 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
67 | + $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | $delete_url = esc_url( |
@@ -78,110 +78,110 @@ discard block |
||
78 | 78 | 'wpinv_discount_nonce' |
79 | 79 | ) |
80 | 80 | ); |
81 | - $row_actions['delete'] = '<a href="' . $delete_url . '">' . __( 'Delete', 'invoicing' ) . '</a>'; |
|
81 | + $row_actions['delete'] = '<a href="' . $delete_url . '">' . __('Delete', 'invoicing') . '</a>'; |
|
82 | 82 | |
83 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
83 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
84 | 84 | |
85 | 85 | return $row_actions; |
86 | 86 | } |
87 | 87 | |
88 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
89 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
90 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
88 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
89 | +function wpinv_table_primary_column($default, $screen_id) { |
|
90 | + if ('edit-wpi_invoice' === $screen_id) { |
|
91 | 91 | return 'name'; |
92 | 92 | } |
93 | 93 | |
94 | 94 | return $default; |
95 | 95 | } |
96 | 96 | |
97 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
98 | - if ( !$display ) { |
|
97 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
98 | + if (!$display) { |
|
99 | 99 | return array(); |
100 | 100 | } |
101 | 101 | |
102 | 102 | $actions = array( |
103 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
104 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
105 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
103 | + 'activate' => __('Activate', 'invoicing'), |
|
104 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
105 | + 'delete' => __('Delete', 'invoicing'), |
|
106 | 106 | ); |
107 | 107 | $two = ''; |
108 | 108 | $which = 'top'; |
109 | 109 | echo '</div><div class="alignleft actions bulkactions">'; |
110 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
111 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
112 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
110 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
111 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
112 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
113 | 113 | |
114 | - foreach ( $actions as $name => $title ) { |
|
114 | + foreach ($actions as $name => $title) { |
|
115 | 115 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
116 | 116 | |
117 | 117 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
118 | 118 | } |
119 | 119 | echo "</select>"; |
120 | 120 | |
121 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
121 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
122 | 122 | |
123 | 123 | echo '</div><div class="alignleft actions">'; |
124 | 124 | } |
125 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
125 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
126 | 126 | |
127 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
128 | - if ( $post_type == 'wpi_discount' ) { |
|
127 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
128 | + if ($post_type == 'wpi_discount') { |
|
129 | 129 | $disable = true; |
130 | 130 | } |
131 | 131 | |
132 | 132 | return $disable; |
133 | 133 | } |
134 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
134 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
135 | 135 | |
136 | 136 | function wpinv_restrict_manage_posts() { |
137 | 137 | global $typenow; |
138 | 138 | |
139 | - if( 'wpi_discount' == $typenow ) { |
|
139 | + if ('wpi_discount' == $typenow) { |
|
140 | 140 | wpinv_discount_filters(); |
141 | 141 | } |
142 | 142 | } |
143 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
143 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
144 | 144 | |
145 | 145 | function wpinv_discount_filters() { |
146 | - echo wpinv_discount_bulk_actions( array(), true ); |
|
146 | + echo wpinv_discount_bulk_actions(array(), true); |
|
147 | 147 | |
148 | 148 | ?> |
149 | 149 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
150 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
150 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
151 | 151 | <?php |
152 | 152 | $types = wpinv_get_discount_types(); |
153 | 153 | |
154 | - foreach ( $types as $name => $type ) { |
|
155 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
154 | + foreach ($types as $name => $type) { |
|
155 | + echo '<option value="' . esc_attr($name) . '"'; |
|
156 | 156 | |
157 | - if ( isset( $_GET['discount_type'] ) ) |
|
158 | - selected( $name, $_GET['discount_type'] ); |
|
157 | + if (isset($_GET['discount_type'])) |
|
158 | + selected($name, $_GET['discount_type']); |
|
159 | 159 | |
160 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
160 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
161 | 161 | } |
162 | 162 | ?> |
163 | 163 | </select> |
164 | 164 | <?php |
165 | 165 | } |
166 | 166 | |
167 | -function wpinv_request( $vars ) { |
|
167 | +function wpinv_request($vars) { |
|
168 | 168 | global $typenow, $wp_query, $wp_post_statuses; |
169 | 169 | |
170 | - if ( 'wpi_invoice' === $typenow ) { |
|
171 | - if ( !isset( $vars['post_status'] ) ) { |
|
170 | + if ('wpi_invoice' === $typenow) { |
|
171 | + if (!isset($vars['post_status'])) { |
|
172 | 172 | $post_statuses = wpinv_get_invoice_statuses(); |
173 | 173 | |
174 | - foreach ( $post_statuses as $status => $value ) { |
|
175 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
176 | - unset( $post_statuses[ $status ] ); |
|
174 | + foreach ($post_statuses as $status => $value) { |
|
175 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
176 | + unset($post_statuses[$status]); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
180 | + $vars['post_status'] = array_keys($post_statuses); |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( isset( $vars['orderby'] ) ) { |
|
184 | - if ( 'amount' == $vars['orderby'] ) { |
|
183 | + if (isset($vars['orderby'])) { |
|
184 | + if ('amount' == $vars['orderby']) { |
|
185 | 185 | $vars = array_merge( |
186 | 186 | $vars, |
187 | 187 | array( |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | 'orderby' => 'meta_value_num' |
190 | 190 | ) |
191 | 191 | ); |
192 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
192 | + } else if ('customer' == $vars['orderby']) { |
|
193 | 193 | $vars = array_merge( |
194 | 194 | $vars, |
195 | 195 | array( |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | 'orderby' => 'meta_value' |
198 | 198 | ) |
199 | 199 | ); |
200 | - } else if ( 'number' == $vars['orderby'] ) { |
|
200 | + } else if ('number' == $vars['orderby']) { |
|
201 | 201 | $vars = array_merge( |
202 | 202 | $vars, |
203 | 203 | array( |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | 'orderby' => 'meta_value' |
206 | 206 | ) |
207 | 207 | ); |
208 | - } else if ( 'payment_date' == $vars['orderby'] ) { |
|
208 | + } else if ('payment_date' == $vars['orderby']) { |
|
209 | 209 | $vars = array_merge( |
210 | 210 | $vars, |
211 | 211 | array( |
@@ -215,73 +215,73 @@ discard block |
||
215 | 215 | ); |
216 | 216 | } |
217 | 217 | } |
218 | - } else if ( 'wpi_discount' == $typenow ) { |
|
219 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
218 | + } else if ('wpi_discount' == $typenow) { |
|
219 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
220 | 220 | // Filter vat rule type |
221 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
221 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
222 | 222 | $meta_query[] = array( |
223 | 223 | 'key' => '_wpi_discount_type', |
224 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
224 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
225 | 225 | 'compare' => '=' |
226 | 226 | ); |
227 | 227 | } |
228 | 228 | |
229 | - if ( !empty( $meta_query ) ) { |
|
229 | + if (!empty($meta_query)) { |
|
230 | 230 | $vars['meta_query'] = $meta_query; |
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
234 | 234 | return $vars; |
235 | 235 | } |
236 | -add_filter( 'request', 'wpinv_request' ); |
|
236 | +add_filter('request', 'wpinv_request'); |
|
237 | 237 | |
238 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
238 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
239 | 239 | global $pagenow, $typenow; |
240 | 240 | |
241 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) { |
|
242 | - if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
243 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
241 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) { |
|
242 | + if ($type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
243 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
244 | 244 | } |
245 | 245 | |
246 | - if ( !wpinv_item_is_editable( $post_id ) ) { |
|
246 | + if (!wpinv_item_is_editable($post_id)) { |
|
247 | 247 | $classes[] = 'wpi-editable-n'; |
248 | 248 | } |
249 | 249 | } |
250 | 250 | return $classes; |
251 | 251 | } |
252 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
252 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
253 | 253 | |
254 | 254 | function wpinv_check_quick_edit() { |
255 | 255 | global $pagenow, $current_screen, $wpinv_item_screen; |
256 | 256 | |
257 | - if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) { |
|
258 | - if ( empty( $wpinv_item_screen ) ) { |
|
259 | - if ( $current_screen->post_type == 'wpi_item' ) { |
|
257 | + if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) { |
|
258 | + if (empty($wpinv_item_screen)) { |
|
259 | + if ($current_screen->post_type == 'wpi_item') { |
|
260 | 260 | $wpinv_item_screen = 'y'; |
261 | 261 | } else { |
262 | 262 | $wpinv_item_screen = 'n'; |
263 | 263 | } |
264 | 264 | } |
265 | 265 | |
266 | - if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) { |
|
267 | - add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
268 | - add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
266 | + if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') { |
|
267 | + add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
268 | + add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | } |
272 | -add_action( 'admin_head', 'wpinv_check_quick_edit', 10 ); |
|
272 | +add_action('admin_head', 'wpinv_check_quick_edit', 10); |
|
273 | 273 | |
274 | -function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) { |
|
275 | - if ( isset( $actions['inline hide-if-no-js'] ) ) { |
|
276 | - unset( $actions['inline hide-if-no-js'] ); |
|
274 | +function wpinv_item_disable_quick_edit($actions = array(), $row = null) { |
|
275 | + if (isset($actions['inline hide-if-no-js'])) { |
|
276 | + unset($actions['inline hide-if-no-js']); |
|
277 | 277 | } |
278 | 278 | |
279 | - if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) { |
|
280 | - if ( isset( $actions['trash'] ) ) { |
|
281 | - unset( $actions['trash'] ); |
|
279 | + if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) { |
|
280 | + if (isset($actions['trash'])) { |
|
281 | + unset($actions['trash']); |
|
282 | 282 | } |
283 | - if ( isset( $actions['delete'] ) ) { |
|
284 | - unset( $actions['delete'] ); |
|
283 | + if (isset($actions['delete'])) { |
|
284 | + unset($actions['delete']); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
@@ -298,19 +298,19 @@ discard block |
||
298 | 298 | * @param int $post_parent (default: 0) Parent for the new page |
299 | 299 | * @return int page ID |
300 | 300 | */ |
301 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
301 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
302 | 302 | global $wpdb; |
303 | 303 | |
304 | - $option_value = wpinv_get_option( $option ); |
|
304 | + $option_value = wpinv_get_option($option); |
|
305 | 305 | |
306 | - if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) { |
|
307 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
306 | + if ($option_value > 0 && ($page_object = get_post($option_value))) { |
|
307 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
308 | 308 | // Valid page is already in place |
309 | 309 | return $page_object->ID; |
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
313 | - if(!empty($post_parent)){ |
|
313 | + if (!empty($post_parent)) { |
|
314 | 314 | $page = get_page_by_path($post_parent); |
315 | 315 | if ($page) { |
316 | 316 | $post_parent = $page->ID; |
@@ -319,40 +319,40 @@ discard block |
||
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
322 | - if ( strlen( $page_content ) > 0 ) { |
|
322 | + if (strlen($page_content) > 0) { |
|
323 | 323 | // Search for an existing page with the specified page content (typically a shortcode) |
324 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
324 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
325 | 325 | } else { |
326 | 326 | // Search for an existing page with the specified page slug |
327 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
327 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
328 | 328 | } |
329 | 329 | |
330 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
330 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
331 | 331 | |
332 | - if ( $valid_page_found ) { |
|
333 | - if ( $option ) { |
|
334 | - wpinv_update_option( $option, $valid_page_found ); |
|
332 | + if ($valid_page_found) { |
|
333 | + if ($option) { |
|
334 | + wpinv_update_option($option, $valid_page_found); |
|
335 | 335 | } |
336 | 336 | return $valid_page_found; |
337 | 337 | } |
338 | 338 | |
339 | 339 | // Search for a matching valid trashed page |
340 | - if ( strlen( $page_content ) > 0 ) { |
|
340 | + if (strlen($page_content) > 0) { |
|
341 | 341 | // Search for an existing page with the specified page content (typically a shortcode) |
342 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
342 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
343 | 343 | } else { |
344 | 344 | // Search for an existing page with the specified page slug |
345 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
345 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
346 | 346 | } |
347 | 347 | |
348 | - if ( $trashed_page_found ) { |
|
348 | + if ($trashed_page_found) { |
|
349 | 349 | $page_id = $trashed_page_found; |
350 | 350 | $page_data = array( |
351 | 351 | 'ID' => $page_id, |
352 | 352 | 'post_status' => 'publish', |
353 | 353 | 'post_parent' => $post_parent, |
354 | 354 | ); |
355 | - wp_update_post( $page_data ); |
|
355 | + wp_update_post($page_data); |
|
356 | 356 | } else { |
357 | 357 | $page_data = array( |
358 | 358 | 'post_status' => 'publish', |
@@ -364,11 +364,11 @@ discard block |
||
364 | 364 | 'post_parent' => $post_parent, |
365 | 365 | 'comment_status' => 'closed', |
366 | 366 | ); |
367 | - $page_id = wp_insert_post( $page_data ); |
|
367 | + $page_id = wp_insert_post($page_data); |
|
368 | 368 | } |
369 | 369 | |
370 | - if ( $option ) { |
|
371 | - wpinv_update_option( $option, (int)$page_id ); |
|
370 | + if ($option) { |
|
371 | + wpinv_update_option($option, (int) $page_id); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | return $page_id; |
@@ -13,609 +13,609 @@ discard block |
||
13 | 13 | class GetPaid_Post_Types_Admin { |
14 | 14 | |
15 | 15 | /** |
16 | - * Hook in methods. |
|
17 | - */ |
|
18 | - public static function init() { |
|
19 | - |
|
20 | - // Init metaboxes. |
|
21 | - GetPaid_Metaboxes::init(); |
|
22 | - |
|
23 | - // Filter the post updated messages. |
|
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | - |
|
26 | - // Filter post actions. |
|
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - |
|
29 | - // Invoice table columns. |
|
30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
32 | - |
|
33 | - // Items table columns. |
|
34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
40 | - |
|
41 | - // Payment forms columns. |
|
42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
45 | - |
|
46 | - // Discount table columns. |
|
47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
48 | - |
|
49 | - // Deleting posts. |
|
50 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
51 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Post updated messages. |
|
56 | - */ |
|
57 | - public static function post_updated_messages( $messages ) { |
|
58 | - global $post; |
|
59 | - |
|
60 | - $messages['wpi_discount'] = array( |
|
61 | - 0 => '', |
|
62 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
63 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
64 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
65 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
66 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
67 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
68 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
69 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
70 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
71 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
72 | - ); |
|
73 | - |
|
74 | - $messages['wpi_payment_form'] = array( |
|
75 | - 0 => '', |
|
76 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
77 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
78 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
79 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
80 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
81 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
83 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
84 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
85 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
86 | - ); |
|
87 | - |
|
88 | - return $messages; |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Post row actions. |
|
94 | - */ |
|
95 | - public static function post_row_actions( $actions, $post ) { |
|
96 | - |
|
97 | - $post = get_post( $post ); |
|
98 | - |
|
99 | - // We do not want to edit the default payment form. |
|
100 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
101 | - unset( $actions['trash'] ); |
|
102 | - unset( $actions['inline hide-if-no-js'] ); |
|
103 | - } |
|
104 | - |
|
105 | - return $actions; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns an array of invoice table columns. |
|
110 | - */ |
|
111 | - public static function invoice_columns( $columns ) { |
|
112 | - |
|
113 | - $columns = array( |
|
114 | - 'cb' => $columns['cb'], |
|
115 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
116 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
117 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
118 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
119 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
120 | - 'status' => __( 'Status', 'invoicing' ), |
|
121 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
122 | - ); |
|
123 | - |
|
124 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Displays invoice table columns. |
|
129 | - */ |
|
130 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
131 | - |
|
132 | - $invoice = new WPInv_Invoice( $post_id ); |
|
133 | - |
|
134 | - switch ( $column_name ) { |
|
135 | - |
|
136 | - case 'invoice_date' : |
|
137 | - $date_time = sanitize_text_field( $invoice->get_created_date() ); |
|
138 | - $date = mysql2date( get_option( 'date_format' ), $date_time ); |
|
139 | - echo "<span title='$date_time'>$date</span>"; |
|
140 | - break; |
|
141 | - |
|
142 | - case 'amount' : |
|
143 | - |
|
144 | - $amount = $invoice->get_total(); |
|
145 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
146 | - |
|
147 | - if ( $invoice->is_refunded() ) { |
|
148 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
149 | - echo "<del>$formated_amount</del><ins>$refunded_amount</ins>"; |
|
150 | - } else { |
|
151 | - |
|
152 | - $discount = $invoice->get_total_discount(); |
|
153 | - |
|
154 | - if ( ! empty( $discount ) ) { |
|
155 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
156 | - echo "<del>$new_amount</del><ins>$formated_amount</ins>"; |
|
157 | - } else { |
|
158 | - echo $formated_amount; |
|
159 | - } |
|
160 | - |
|
161 | - } |
|
162 | - |
|
163 | - break; |
|
164 | - |
|
165 | - case 'status' : |
|
166 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
167 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
168 | - |
|
169 | - // If it is paid, show the gateway title. |
|
170 | - if ( $invoice->is_paid() ) { |
|
171 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
172 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
16 | + * Hook in methods. |
|
17 | + */ |
|
18 | + public static function init() { |
|
173 | 19 | |
174 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
175 | - } else { |
|
176 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
177 | - } |
|
20 | + // Init metaboxes. |
|
21 | + GetPaid_Metaboxes::init(); |
|
178 | 22 | |
179 | - // If it is not paid, display the overdue and view status. |
|
180 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
23 | + // Filter the post updated messages. |
|
24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
181 | 25 | |
182 | - // Invoice view status. |
|
183 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
184 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
185 | - } else { |
|
186 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
187 | - } |
|
26 | + // Filter post actions. |
|
27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
188 | 28 | |
189 | - // Display the overview status. |
|
190 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
191 | - $due_date = $invoice->get_due_date(); |
|
29 | + // Invoice table columns. |
|
30 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
192 | 32 | |
193 | - if ( ! empty( $due_date ) ) { |
|
194 | - $date = mysql2date( get_option( 'date_format' ), $due_date ); |
|
195 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $date ); |
|
196 | - echo "<p class='description' style='color: #888;' title='$due_date'>$date</p>"; |
|
197 | - } |
|
198 | - } |
|
33 | + // Items table columns. |
|
34 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
199 | 40 | |
200 | - } |
|
41 | + // Payment forms columns. |
|
42 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
201 | 45 | |
202 | - break; |
|
46 | + // Discount table columns. |
|
47 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
203 | 48 | |
204 | - case 'recurring': |
|
49 | + // Deleting posts. |
|
50 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
51 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
52 | + } |
|
205 | 53 | |
206 | - if ( $invoice->is_recurring() ) { |
|
207 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
208 | - } else { |
|
209 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
210 | - } |
|
211 | - break; |
|
54 | + /** |
|
55 | + * Post updated messages. |
|
56 | + */ |
|
57 | + public static function post_updated_messages( $messages ) { |
|
58 | + global $post; |
|
59 | + |
|
60 | + $messages['wpi_discount'] = array( |
|
61 | + 0 => '', |
|
62 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
63 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
64 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
65 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
66 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
67 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
68 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
69 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
70 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
71 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
72 | + ); |
|
73 | + |
|
74 | + $messages['wpi_payment_form'] = array( |
|
75 | + 0 => '', |
|
76 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
77 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
78 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
79 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
80 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
81 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
83 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
84 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
85 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
86 | + ); |
|
87 | + |
|
88 | + return $messages; |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Post row actions. |
|
94 | + */ |
|
95 | + public static function post_row_actions( $actions, $post ) { |
|
96 | + |
|
97 | + $post = get_post( $post ); |
|
98 | + |
|
99 | + // We do not want to edit the default payment form. |
|
100 | + if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
101 | + unset( $actions['trash'] ); |
|
102 | + unset( $actions['inline hide-if-no-js'] ); |
|
103 | + } |
|
104 | + |
|
105 | + return $actions; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns an array of invoice table columns. |
|
110 | + */ |
|
111 | + public static function invoice_columns( $columns ) { |
|
112 | + |
|
113 | + $columns = array( |
|
114 | + 'cb' => $columns['cb'], |
|
115 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
116 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
117 | + 'invoice_date' => __( 'Date', 'invoicing' ), |
|
118 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
119 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
120 | + 'status' => __( 'Status', 'invoicing' ), |
|
121 | + 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
122 | + ); |
|
123 | + |
|
124 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Displays invoice table columns. |
|
129 | + */ |
|
130 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
131 | + |
|
132 | + $invoice = new WPInv_Invoice( $post_id ); |
|
133 | + |
|
134 | + switch ( $column_name ) { |
|
135 | + |
|
136 | + case 'invoice_date' : |
|
137 | + $date_time = sanitize_text_field( $invoice->get_created_date() ); |
|
138 | + $date = mysql2date( get_option( 'date_format' ), $date_time ); |
|
139 | + echo "<span title='$date_time'>$date</span>"; |
|
140 | + break; |
|
141 | + |
|
142 | + case 'amount' : |
|
143 | + |
|
144 | + $amount = $invoice->get_total(); |
|
145 | + $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
146 | + |
|
147 | + if ( $invoice->is_refunded() ) { |
|
148 | + $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
149 | + echo "<del>$formated_amount</del><ins>$refunded_amount</ins>"; |
|
150 | + } else { |
|
151 | + |
|
152 | + $discount = $invoice->get_total_discount(); |
|
153 | + |
|
154 | + if ( ! empty( $discount ) ) { |
|
155 | + $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
156 | + echo "<del>$new_amount</del><ins>$formated_amount</ins>"; |
|
157 | + } else { |
|
158 | + echo $formated_amount; |
|
159 | + } |
|
160 | + |
|
161 | + } |
|
162 | + |
|
163 | + break; |
|
164 | + |
|
165 | + case 'status' : |
|
166 | + $status = sanitize_text_field( $invoice->get_status() ); |
|
167 | + $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
168 | + |
|
169 | + // If it is paid, show the gateway title. |
|
170 | + if ( $invoice->is_paid() ) { |
|
171 | + $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
172 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
173 | + |
|
174 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
175 | + } else { |
|
176 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
177 | + } |
|
212 | 178 | |
213 | - case 'number' : |
|
179 | + // If it is not paid, display the overdue and view status. |
|
180 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
214 | 181 | |
215 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
216 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
217 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
182 | + // Invoice view status. |
|
183 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
184 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
185 | + } else { |
|
186 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
187 | + } |
|
218 | 188 | |
219 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
189 | + // Display the overview status. |
|
190 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
191 | + $due_date = $invoice->get_due_date(); |
|
220 | 192 | |
221 | - break; |
|
193 | + if ( ! empty( $due_date ) ) { |
|
194 | + $date = mysql2date( get_option( 'date_format' ), $due_date ); |
|
195 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $date ); |
|
196 | + echo "<p class='description' style='color: #888;' title='$due_date'>$date</p>"; |
|
197 | + } |
|
198 | + } |
|
222 | 199 | |
223 | - case 'customer' : |
|
200 | + } |
|
201 | + |
|
202 | + break; |
|
203 | + |
|
204 | + case 'recurring': |
|
205 | + |
|
206 | + if ( $invoice->is_recurring() ) { |
|
207 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
208 | + } else { |
|
209 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
210 | + } |
|
211 | + break; |
|
212 | + |
|
213 | + case 'number' : |
|
214 | + |
|
215 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
216 | + $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
217 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
218 | + |
|
219 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
220 | + |
|
221 | + break; |
|
222 | + |
|
223 | + case 'customer' : |
|
224 | 224 | |
225 | - $customer_name = $invoice->get_user_full_name(); |
|
225 | + $customer_name = $invoice->get_user_full_name(); |
|
226 | 226 | |
227 | - if ( empty( $customer_name ) ) { |
|
228 | - $customer_name = $invoice->get_email(); |
|
229 | - } |
|
227 | + if ( empty( $customer_name ) ) { |
|
228 | + $customer_name = $invoice->get_email(); |
|
229 | + } |
|
230 | 230 | |
231 | - if ( ! empty( $customer_name ) ) { |
|
232 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
233 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
234 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
235 | - } else { |
|
236 | - echo '<div>—</div>'; |
|
237 | - } |
|
238 | - |
|
239 | - break; |
|
240 | - |
|
241 | - case 'wpi_actions' : |
|
242 | - |
|
243 | - if ( ! $invoice->is_draft() ) { |
|
244 | - $url = esc_url( $invoice->get_view_url() ); |
|
245 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
246 | - echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
247 | - } |
|
248 | - |
|
249 | - if ( $invoice->get_email() ) { |
|
250 | - $url = esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $invoice->get_id() ) ) ); |
|
251 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
252 | - echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
253 | - } |
|
231 | + if ( ! empty( $customer_name ) ) { |
|
232 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
233 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
234 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
235 | + } else { |
|
236 | + echo '<div>—</div>'; |
|
237 | + } |
|
238 | + |
|
239 | + break; |
|
240 | + |
|
241 | + case 'wpi_actions' : |
|
242 | + |
|
243 | + if ( ! $invoice->is_draft() ) { |
|
244 | + $url = esc_url( $invoice->get_view_url() ); |
|
245 | + $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
246 | + echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
247 | + } |
|
248 | + |
|
249 | + if ( $invoice->get_email() ) { |
|
250 | + $url = esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $invoice->get_id() ) ) ); |
|
251 | + $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
252 | + echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
253 | + } |
|
254 | 254 | |
255 | - break; |
|
256 | - } |
|
255 | + break; |
|
256 | + } |
|
257 | 257 | |
258 | - } |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * Returns an array of payment forms table columns. |
|
262 | - */ |
|
263 | - public static function payment_form_columns( $columns ) { |
|
260 | + /** |
|
261 | + * Returns an array of payment forms table columns. |
|
262 | + */ |
|
263 | + public static function payment_form_columns( $columns ) { |
|
264 | 264 | |
265 | - $columns = array( |
|
266 | - 'cb' => $columns['cb'], |
|
267 | - 'title' => __( 'Name', 'invoicing' ), |
|
268 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
269 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
270 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
271 | - 'items' => __( 'Items', 'invoicing' ), |
|
272 | - 'date' => __( 'Date', 'invoicing' ), |
|
273 | - ); |
|
265 | + $columns = array( |
|
266 | + 'cb' => $columns['cb'], |
|
267 | + 'title' => __( 'Name', 'invoicing' ), |
|
268 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
269 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
270 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
271 | + 'items' => __( 'Items', 'invoicing' ), |
|
272 | + 'date' => __( 'Date', 'invoicing' ), |
|
273 | + ); |
|
274 | 274 | |
275 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
275 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
276 | 276 | |
277 | - } |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * Displays payment form table columns. |
|
281 | - */ |
|
282 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
279 | + /** |
|
280 | + * Displays payment form table columns. |
|
281 | + */ |
|
282 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
283 | 283 | |
284 | - // Retrieve the payment form. |
|
285 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
284 | + // Retrieve the payment form. |
|
285 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
286 | 286 | |
287 | - switch ( $column_name ) { |
|
287 | + switch ( $column_name ) { |
|
288 | 288 | |
289 | - case 'earnings' : |
|
290 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
291 | - break; |
|
289 | + case 'earnings' : |
|
290 | + echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
291 | + break; |
|
292 | 292 | |
293 | - case 'refunds' : |
|
294 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
295 | - break; |
|
293 | + case 'refunds' : |
|
294 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
295 | + break; |
|
296 | 296 | |
297 | - case 'refunds' : |
|
298 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
299 | - break; |
|
297 | + case 'refunds' : |
|
298 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
299 | + break; |
|
300 | 300 | |
301 | - case 'shortcode' : |
|
301 | + case 'shortcode' : |
|
302 | 302 | |
303 | - if ( $form->is_default() ) { |
|
304 | - echo '—'; |
|
305 | - } else { |
|
306 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
307 | - } |
|
303 | + if ( $form->is_default() ) { |
|
304 | + echo '—'; |
|
305 | + } else { |
|
306 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
307 | + } |
|
308 | 308 | |
309 | - break; |
|
309 | + break; |
|
310 | 310 | |
311 | - case 'items' : |
|
311 | + case 'items' : |
|
312 | 312 | |
313 | - $items = $form->get_items(); |
|
313 | + $items = $form->get_items(); |
|
314 | 314 | |
315 | - if ( $form->is_default() || empty( $items ) ) { |
|
316 | - echo '—'; |
|
317 | - return; |
|
318 | - } |
|
315 | + if ( $form->is_default() || empty( $items ) ) { |
|
316 | + echo '—'; |
|
317 | + return; |
|
318 | + } |
|
319 | 319 | |
320 | - $_items = array(); |
|
320 | + $_items = array(); |
|
321 | 321 | |
322 | - foreach ( $items as $item ) { |
|
323 | - $url = $item->get_edit_url(); |
|
322 | + foreach ( $items as $item ) { |
|
323 | + $url = $item->get_edit_url(); |
|
324 | 324 | |
325 | - if ( empty( $url ) ) { |
|
326 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
327 | - } else { |
|
328 | - $_items[] = sprintf( |
|
329 | - '<a href="%s">%s</a>', |
|
330 | - esc_url( $url ), |
|
331 | - sanitize_text_field( $item->get_name() ) |
|
332 | - ); |
|
333 | - } |
|
325 | + if ( empty( $url ) ) { |
|
326 | + $_items[] = sanitize_text_field( $item->get_name() ); |
|
327 | + } else { |
|
328 | + $_items[] = sprintf( |
|
329 | + '<a href="%s">%s</a>', |
|
330 | + esc_url( $url ), |
|
331 | + sanitize_text_field( $item->get_name() ) |
|
332 | + ); |
|
333 | + } |
|
334 | 334 | |
335 | - } |
|
335 | + } |
|
336 | 336 | |
337 | - echo implode( '<br>', $_items ); |
|
337 | + echo implode( '<br>', $_items ); |
|
338 | 338 | |
339 | - break; |
|
339 | + break; |
|
340 | 340 | |
341 | - } |
|
341 | + } |
|
342 | 342 | |
343 | - } |
|
343 | + } |
|
344 | 344 | |
345 | - /** |
|
346 | - * Filters post states. |
|
347 | - */ |
|
348 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
345 | + /** |
|
346 | + * Filters post states. |
|
347 | + */ |
|
348 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
349 | 349 | |
350 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
351 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
352 | - } |
|
350 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
351 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
352 | + } |
|
353 | 353 | |
354 | - return $post_states; |
|
355 | - |
|
356 | - } |
|
354 | + return $post_states; |
|
357 | 355 | |
358 | - /** |
|
359 | - * Returns an array of coupon table columns. |
|
360 | - */ |
|
361 | - public static function discount_columns( $columns ) { |
|
356 | + } |
|
362 | 357 | |
363 | - $columns = array( |
|
364 | - 'cb' => $columns['cb'], |
|
365 | - 'title' => __( 'Name', 'invoicing' ), |
|
366 | - 'code' => __( 'Code', 'invoicing' ), |
|
367 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
368 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
369 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
370 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
371 | - ); |
|
358 | + /** |
|
359 | + * Returns an array of coupon table columns. |
|
360 | + */ |
|
361 | + public static function discount_columns( $columns ) { |
|
362 | + |
|
363 | + $columns = array( |
|
364 | + 'cb' => $columns['cb'], |
|
365 | + 'title' => __( 'Name', 'invoicing' ), |
|
366 | + 'code' => __( 'Code', 'invoicing' ), |
|
367 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
368 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
369 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
370 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
371 | + ); |
|
372 | 372 | |
373 | 373 | |
374 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
375 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
376 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
377 | - $columns['start_date'] = __( 'Start Date', 'invoicing' ); |
|
378 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
379 | - |
|
380 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
381 | - } |
|
374 | + $columns['code'] = __( 'Code', 'invoicing' ); |
|
375 | + $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
376 | + $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
377 | + $columns['start_date'] = __( 'Start Date', 'invoicing' ); |
|
378 | + $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
382 | 379 | |
383 | - /** |
|
384 | - * Filters post states. |
|
385 | - */ |
|
386 | - public static function filter_discount_state( $post_states, $post ) { |
|
380 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
381 | + } |
|
387 | 382 | |
388 | - if ( 'wpi_discount' == $post->post_type ) { |
|
383 | + /** |
|
384 | + * Filters post states. |
|
385 | + */ |
|
386 | + public static function filter_discount_state( $post_states, $post ) { |
|
389 | 387 | |
390 | - $discount = new WPInv_Discount( $post ); |
|
388 | + if ( 'wpi_discount' == $post->post_type ) { |
|
391 | 389 | |
392 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
390 | + $discount = new WPInv_Discount( $post ); |
|
393 | 391 | |
394 | - if ( $status != 'publish' ) { |
|
395 | - return array( |
|
396 | - 'discount_status' => wpinv_discount_status( $status ), |
|
397 | - ); |
|
398 | - } |
|
392 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
399 | 393 | |
400 | - return array(); |
|
394 | + if ( $status != 'publish' ) { |
|
395 | + return array( |
|
396 | + 'discount_status' => wpinv_discount_status( $status ), |
|
397 | + ); |
|
398 | + } |
|
401 | 399 | |
402 | - } |
|
400 | + return array(); |
|
403 | 401 | |
404 | - return $post_states; |
|
402 | + } |
|
405 | 403 | |
406 | - } |
|
404 | + return $post_states; |
|
407 | 405 | |
408 | - /** |
|
409 | - * Returns an array of items table columns. |
|
410 | - */ |
|
411 | - public static function item_columns( $columns ) { |
|
412 | - global $wpinv_euvat; |
|
406 | + } |
|
413 | 407 | |
414 | - $columns = array( |
|
415 | - 'cb' => $columns['cb'], |
|
416 | - 'title' => __( 'Name', 'invoicing' ), |
|
417 | - 'price' => __( 'Price', 'invoicing' ), |
|
418 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
419 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
420 | - 'type' => __( 'Type', 'invoicing' ), |
|
421 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
422 | - ); |
|
408 | + /** |
|
409 | + * Returns an array of items table columns. |
|
410 | + */ |
|
411 | + public static function item_columns( $columns ) { |
|
412 | + global $wpinv_euvat; |
|
413 | + |
|
414 | + $columns = array( |
|
415 | + 'cb' => $columns['cb'], |
|
416 | + 'title' => __( 'Name', 'invoicing' ), |
|
417 | + 'price' => __( 'Price', 'invoicing' ), |
|
418 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
419 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
420 | + 'type' => __( 'Type', 'invoicing' ), |
|
421 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
422 | + ); |
|
423 | + |
|
424 | + if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
425 | + unset( $columns['vat_rule'] ); |
|
426 | + } |
|
423 | 427 | |
424 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
425 | - unset( $columns['vat_rule'] ); |
|
426 | - } |
|
428 | + if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
429 | + unset( $columns['vat_class'] ); |
|
430 | + } |
|
427 | 431 | |
428 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
429 | - unset( $columns['vat_class'] ); |
|
430 | - } |
|
432 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
433 | + } |
|
431 | 434 | |
432 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
433 | - } |
|
435 | + /** |
|
436 | + * Returns an array of sortable items table columns. |
|
437 | + */ |
|
438 | + public static function sortable_item_columns( $columns ) { |
|
439 | + |
|
440 | + return array_merge( |
|
441 | + $columns, |
|
442 | + array( |
|
443 | + 'price' => 'price', |
|
444 | + 'vat_rule' => 'vat_rule', |
|
445 | + 'vat_class' => 'vat_class', |
|
446 | + 'type' => 'type', |
|
447 | + ) |
|
448 | + ); |
|
449 | + |
|
450 | + } |
|
434 | 451 | |
435 | - /** |
|
436 | - * Returns an array of sortable items table columns. |
|
437 | - */ |
|
438 | - public static function sortable_item_columns( $columns ) { |
|
452 | + /** |
|
453 | + * Displays items table columns. |
|
454 | + */ |
|
455 | + public static function display_item_columns( $column_name, $post_id ) { |
|
456 | + global $wpinv_euvat; |
|
439 | 457 | |
440 | - return array_merge( |
|
441 | - $columns, |
|
442 | - array( |
|
443 | - 'price' => 'price', |
|
444 | - 'vat_rule' => 'vat_rule', |
|
445 | - 'vat_class' => 'vat_class', |
|
446 | - 'type' => 'type', |
|
447 | - ) |
|
448 | - ); |
|
458 | + $item = new WPInv_Item( $post_id ); |
|
449 | 459 | |
450 | - } |
|
460 | + switch ( $column_name ) { |
|
451 | 461 | |
452 | - /** |
|
453 | - * Displays items table columns. |
|
454 | - */ |
|
455 | - public static function display_item_columns( $column_name, $post_id ) { |
|
456 | - global $wpinv_euvat; |
|
462 | + case 'price' : |
|
457 | 463 | |
458 | - $item = new WPInv_Item( $post_id ); |
|
464 | + if ( ! $item->is_recurring() ) { |
|
465 | + echo $item->get_the_price(); |
|
466 | + break; |
|
467 | + } |
|
459 | 468 | |
460 | - switch ( $column_name ) { |
|
469 | + $price = wp_sprintf( |
|
470 | + __( '%s / %s', 'invoicing' ), |
|
471 | + $item->get_the_price(), |
|
472 | + WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() ) |
|
473 | + ); |
|
461 | 474 | |
462 | - case 'price' : |
|
475 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
476 | + echo $price; |
|
477 | + break; |
|
478 | + } |
|
463 | 479 | |
464 | - if ( ! $item->is_recurring() ) { |
|
465 | - echo $item->get_the_price(); |
|
466 | - break; |
|
467 | - } |
|
480 | + echo $item->get_the_initial_price(); |
|
468 | 481 | |
469 | - $price = wp_sprintf( |
|
470 | - __( '%s / %s', 'invoicing' ), |
|
471 | - $item->get_the_price(), |
|
472 | - WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() ) |
|
473 | - ); |
|
482 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
483 | + break; |
|
474 | 484 | |
475 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
476 | - echo $price; |
|
477 | - break; |
|
478 | - } |
|
485 | + case 'vat_rule' : |
|
486 | + echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
487 | + break; |
|
479 | 488 | |
480 | - echo $item->get_the_initial_price(); |
|
489 | + case 'vat_class' : |
|
490 | + echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
491 | + break; |
|
481 | 492 | |
482 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
483 | - break; |
|
493 | + case 'shortcode' : |
|
494 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
495 | + break; |
|
484 | 496 | |
485 | - case 'vat_rule' : |
|
486 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
487 | - break; |
|
497 | + case 'type' : |
|
498 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
499 | + break; |
|
488 | 500 | |
489 | - case 'vat_class' : |
|
490 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
491 | - break; |
|
501 | + } |
|
492 | 502 | |
493 | - case 'shortcode' : |
|
494 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
495 | - break; |
|
503 | + } |
|
496 | 504 | |
497 | - case 'type' : |
|
498 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
499 | - break; |
|
505 | + /** |
|
506 | + * Lets users filter items using taxes. |
|
507 | + */ |
|
508 | + public static function add_item_filters( $post_type ) { |
|
509 | + global $wpinv_euvat; |
|
510 | + |
|
511 | + // Abort if we're not dealing with items. |
|
512 | + if ( $post_type != 'wpi_item' ) { |
|
513 | + return; |
|
514 | + } |
|
500 | 515 | |
501 | - } |
|
502 | - |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * Lets users filter items using taxes. |
|
507 | - */ |
|
508 | - public static function add_item_filters( $post_type ) { |
|
509 | - global $wpinv_euvat; |
|
510 | - |
|
511 | - // Abort if we're not dealing with items. |
|
512 | - if ( $post_type != 'wpi_item' ) { |
|
513 | - return; |
|
514 | - } |
|
515 | - |
|
516 | - // Filter by vat rules. |
|
517 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
516 | + // Filter by vat rules. |
|
517 | + if ( $wpinv_euvat->allow_vat_rules() ) { |
|
518 | 518 | |
519 | - // Sanitize selected vat rule. |
|
520 | - $vat_rule = ''; |
|
521 | - if ( isset( $_GET['vat_rule'] ) && array_key_exists( $_GET['vat_rule'], $wpinv_euvat->get_rules() ) ) { |
|
522 | - $vat_rule = $_GET['vat_rule']; |
|
523 | - } |
|
524 | - |
|
525 | - // Filter by VAT rule. |
|
526 | - echo wpinv_html_select( |
|
527 | - array( |
|
528 | - 'options' => array_merge( |
|
529 | - array( |
|
530 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
531 | - ), |
|
532 | - $wpinv_euvat->get_rules() |
|
533 | - ), |
|
534 | - 'name' => 'vat_rule', |
|
535 | - 'id' => 'vat_rule', |
|
536 | - 'selected' => $vat_rule, |
|
537 | - 'show_option_all' => false, |
|
538 | - 'show_option_none' => false, |
|
539 | - 'class' => 'gdmbx2-text-medium', |
|
540 | - ) |
|
541 | - ); |
|
542 | - |
|
543 | - // Filter by VAT class. |
|
544 | - } |
|
545 | - |
|
546 | - // Filter by vat class. |
|
547 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
519 | + // Sanitize selected vat rule. |
|
520 | + $vat_rule = ''; |
|
521 | + if ( isset( $_GET['vat_rule'] ) && array_key_exists( $_GET['vat_rule'], $wpinv_euvat->get_rules() ) ) { |
|
522 | + $vat_rule = $_GET['vat_rule']; |
|
523 | + } |
|
524 | + |
|
525 | + // Filter by VAT rule. |
|
526 | + echo wpinv_html_select( |
|
527 | + array( |
|
528 | + 'options' => array_merge( |
|
529 | + array( |
|
530 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
531 | + ), |
|
532 | + $wpinv_euvat->get_rules() |
|
533 | + ), |
|
534 | + 'name' => 'vat_rule', |
|
535 | + 'id' => 'vat_rule', |
|
536 | + 'selected' => $vat_rule, |
|
537 | + 'show_option_all' => false, |
|
538 | + 'show_option_none' => false, |
|
539 | + 'class' => 'gdmbx2-text-medium', |
|
540 | + ) |
|
541 | + ); |
|
542 | + |
|
543 | + // Filter by VAT class. |
|
544 | + } |
|
545 | + |
|
546 | + // Filter by vat class. |
|
547 | + if ( $wpinv_euvat->allow_vat_classes() ) { |
|
548 | 548 | |
549 | - // Sanitize selected vat rule. |
|
550 | - $vat_class = ''; |
|
551 | - if ( isset( $_GET['vat_class'] ) && array_key_exists( $_GET['vat_class'], $wpinv_euvat->get_all_classes() ) ) { |
|
552 | - $vat_class = $_GET['vat_class']; |
|
553 | - } |
|
554 | - |
|
555 | - echo wpinv_html_select( |
|
556 | - array( |
|
557 | - 'options' => array_merge( |
|
558 | - array( |
|
559 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
560 | - ), |
|
561 | - $wpinv_euvat->get_all_classes() |
|
562 | - ), |
|
563 | - 'name' => 'vat_class', |
|
564 | - 'id' => 'vat_class', |
|
565 | - 'selected' => $vat_class, |
|
566 | - 'show_option_all' => false, |
|
567 | - 'show_option_none' => false, |
|
568 | - 'class' => 'gdmbx2-text-medium', |
|
569 | - ) |
|
570 | - ); |
|
571 | - |
|
572 | - } |
|
573 | - |
|
574 | - // Filter by item type. |
|
575 | - $type = ''; |
|
576 | - if( isset( $_GET['type'] ) && array_key_exists( $_GET['type'], wpinv_get_item_types() ) ) { |
|
577 | - $type = $_GET['type']; |
|
578 | - } |
|
579 | - |
|
580 | - echo wpinv_html_select( |
|
581 | - array( |
|
582 | - 'options' => array_merge( |
|
583 | - array( |
|
584 | - '' => __( 'All item types', 'invoicing' ) |
|
585 | - ), |
|
586 | - wpinv_get_item_types() |
|
587 | - ), |
|
588 | - 'name' => 'type', |
|
589 | - 'id' => 'type', |
|
590 | - 'selected' => $type, |
|
591 | - 'show_option_all' => false, |
|
592 | - 'show_option_none' => false, |
|
593 | - 'class' => 'gdmbx2-text-medium', |
|
594 | - ) |
|
595 | - ); |
|
596 | - |
|
597 | - } |
|
598 | - |
|
599 | - /** |
|
600 | - * Filters the item query. |
|
601 | - */ |
|
602 | - public static function filter_item_query( $query ) { |
|
603 | - |
|
604 | - // modify the query only if it admin and main query. |
|
605 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
606 | - return $query; |
|
607 | - } |
|
608 | - |
|
609 | - // we want to modify the query for our items. |
|
610 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
611 | - return $query; |
|
612 | - } |
|
613 | - |
|
614 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
615 | - $query->query_vars['meta_query'] = array(); |
|
616 | - } |
|
617 | - |
|
618 | - // Filter vat rule type |
|
549 | + // Sanitize selected vat rule. |
|
550 | + $vat_class = ''; |
|
551 | + if ( isset( $_GET['vat_class'] ) && array_key_exists( $_GET['vat_class'], $wpinv_euvat->get_all_classes() ) ) { |
|
552 | + $vat_class = $_GET['vat_class']; |
|
553 | + } |
|
554 | + |
|
555 | + echo wpinv_html_select( |
|
556 | + array( |
|
557 | + 'options' => array_merge( |
|
558 | + array( |
|
559 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
560 | + ), |
|
561 | + $wpinv_euvat->get_all_classes() |
|
562 | + ), |
|
563 | + 'name' => 'vat_class', |
|
564 | + 'id' => 'vat_class', |
|
565 | + 'selected' => $vat_class, |
|
566 | + 'show_option_all' => false, |
|
567 | + 'show_option_none' => false, |
|
568 | + 'class' => 'gdmbx2-text-medium', |
|
569 | + ) |
|
570 | + ); |
|
571 | + |
|
572 | + } |
|
573 | + |
|
574 | + // Filter by item type. |
|
575 | + $type = ''; |
|
576 | + if( isset( $_GET['type'] ) && array_key_exists( $_GET['type'], wpinv_get_item_types() ) ) { |
|
577 | + $type = $_GET['type']; |
|
578 | + } |
|
579 | + |
|
580 | + echo wpinv_html_select( |
|
581 | + array( |
|
582 | + 'options' => array_merge( |
|
583 | + array( |
|
584 | + '' => __( 'All item types', 'invoicing' ) |
|
585 | + ), |
|
586 | + wpinv_get_item_types() |
|
587 | + ), |
|
588 | + 'name' => 'type', |
|
589 | + 'id' => 'type', |
|
590 | + 'selected' => $type, |
|
591 | + 'show_option_all' => false, |
|
592 | + 'show_option_none' => false, |
|
593 | + 'class' => 'gdmbx2-text-medium', |
|
594 | + ) |
|
595 | + ); |
|
596 | + |
|
597 | + } |
|
598 | + |
|
599 | + /** |
|
600 | + * Filters the item query. |
|
601 | + */ |
|
602 | + public static function filter_item_query( $query ) { |
|
603 | + |
|
604 | + // modify the query only if it admin and main query. |
|
605 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
606 | + return $query; |
|
607 | + } |
|
608 | + |
|
609 | + // we want to modify the query for our items. |
|
610 | + if ( 'wpi_item' != $query->query['post_type'] ){ |
|
611 | + return $query; |
|
612 | + } |
|
613 | + |
|
614 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
615 | + $query->query_vars['meta_query'] = array(); |
|
616 | + } |
|
617 | + |
|
618 | + // Filter vat rule type |
|
619 | 619 | if ( ! empty( $_GET['vat_rule'] ) ) { |
620 | 620 | $query->query_vars['meta_query'][] = array( |
621 | 621 | 'key' => '_wpinv_vat_rule', |
@@ -640,94 +640,94 @@ discard block |
||
640 | 640 | 'value' => sanitize_text_field( $_GET['type'] ), |
641 | 641 | 'compare' => '=' |
642 | 642 | ); |
643 | - } |
|
644 | - |
|
645 | - } |
|
646 | - |
|
647 | - /** |
|
648 | - * Reorders items. |
|
649 | - */ |
|
650 | - public static function reorder_items( $vars ) { |
|
651 | - global $typenow; |
|
652 | - |
|
653 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
654 | - return $vars; |
|
655 | - } |
|
656 | - |
|
657 | - // By item type. |
|
658 | - if ( 'type' == $vars['orderby'] ) { |
|
659 | - return array_merge( |
|
660 | - $vars, |
|
661 | - array( |
|
662 | - 'meta_key' => '_wpinv_type', |
|
663 | - 'orderby' => 'meta_value' |
|
664 | - ) |
|
665 | - ); |
|
666 | - } |
|
667 | - |
|
668 | - // By vat class. |
|
669 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
670 | - return array_merge( |
|
671 | - $vars, |
|
672 | - array( |
|
673 | - 'meta_key' => '_wpinv_vat_class', |
|
674 | - 'orderby' => 'meta_value' |
|
675 | - ) |
|
676 | - ); |
|
677 | - } |
|
678 | - |
|
679 | - // By vat rule. |
|
680 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
681 | - return array_merge( |
|
682 | - $vars, |
|
683 | - array( |
|
684 | - 'meta_key' => '_wpinv_vat_rule', |
|
685 | - 'orderby' => 'meta_value' |
|
686 | - ) |
|
687 | - ); |
|
688 | - } |
|
689 | - |
|
690 | - // By price. |
|
691 | - if ( 'price' == $vars['orderby'] ) { |
|
692 | - return array_merge( |
|
693 | - $vars, |
|
694 | - array( |
|
695 | - 'meta_key' => '_wpinv_price', |
|
696 | - 'orderby' => 'meta_value_num' |
|
697 | - ) |
|
698 | - ); |
|
699 | - } |
|
700 | - |
|
701 | - return $vars; |
|
702 | - |
|
703 | - } |
|
704 | - |
|
705 | - /** |
|
706 | - * Fired when deleting a post. |
|
707 | - */ |
|
708 | - public static function delete_post( $post_id ) { |
|
709 | - |
|
710 | - switch ( get_post_type( $post_id ) ) { |
|
711 | - |
|
712 | - case 'wpi_item' : |
|
713 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
714 | - break; |
|
715 | - |
|
716 | - case 'wpi_payment_form' : |
|
717 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
718 | - break; |
|
719 | - |
|
720 | - case 'wpi_discount' : |
|
721 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
722 | - break; |
|
723 | - |
|
724 | - case 'wpi_invoice' : |
|
725 | - $invoice = new WPInv_Invoice( $post_id ); |
|
726 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
727 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
728 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
729 | - break; |
|
730 | - } |
|
731 | - } |
|
643 | + } |
|
644 | + |
|
645 | + } |
|
646 | + |
|
647 | + /** |
|
648 | + * Reorders items. |
|
649 | + */ |
|
650 | + public static function reorder_items( $vars ) { |
|
651 | + global $typenow; |
|
652 | + |
|
653 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
654 | + return $vars; |
|
655 | + } |
|
656 | + |
|
657 | + // By item type. |
|
658 | + if ( 'type' == $vars['orderby'] ) { |
|
659 | + return array_merge( |
|
660 | + $vars, |
|
661 | + array( |
|
662 | + 'meta_key' => '_wpinv_type', |
|
663 | + 'orderby' => 'meta_value' |
|
664 | + ) |
|
665 | + ); |
|
666 | + } |
|
667 | + |
|
668 | + // By vat class. |
|
669 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
670 | + return array_merge( |
|
671 | + $vars, |
|
672 | + array( |
|
673 | + 'meta_key' => '_wpinv_vat_class', |
|
674 | + 'orderby' => 'meta_value' |
|
675 | + ) |
|
676 | + ); |
|
677 | + } |
|
678 | + |
|
679 | + // By vat rule. |
|
680 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
681 | + return array_merge( |
|
682 | + $vars, |
|
683 | + array( |
|
684 | + 'meta_key' => '_wpinv_vat_rule', |
|
685 | + 'orderby' => 'meta_value' |
|
686 | + ) |
|
687 | + ); |
|
688 | + } |
|
689 | + |
|
690 | + // By price. |
|
691 | + if ( 'price' == $vars['orderby'] ) { |
|
692 | + return array_merge( |
|
693 | + $vars, |
|
694 | + array( |
|
695 | + 'meta_key' => '_wpinv_price', |
|
696 | + 'orderby' => 'meta_value_num' |
|
697 | + ) |
|
698 | + ); |
|
699 | + } |
|
700 | + |
|
701 | + return $vars; |
|
702 | + |
|
703 | + } |
|
704 | + |
|
705 | + /** |
|
706 | + * Fired when deleting a post. |
|
707 | + */ |
|
708 | + public static function delete_post( $post_id ) { |
|
709 | + |
|
710 | + switch ( get_post_type( $post_id ) ) { |
|
711 | + |
|
712 | + case 'wpi_item' : |
|
713 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
714 | + break; |
|
715 | + |
|
716 | + case 'wpi_payment_form' : |
|
717 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
718 | + break; |
|
719 | + |
|
720 | + case 'wpi_discount' : |
|
721 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
722 | + break; |
|
723 | + |
|
724 | + case 'wpi_invoice' : |
|
725 | + $invoice = new WPInv_Invoice( $post_id ); |
|
726 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
727 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
728 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
729 | + break; |
|
730 | + } |
|
731 | + } |
|
732 | 732 | |
733 | 733 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Post types Admin Class |
@@ -21,68 +21,68 @@ discard block |
||
21 | 21 | GetPaid_Metaboxes::init(); |
22 | 22 | |
23 | 23 | // Filter the post updated messages. |
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
24 | + add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages'); |
|
25 | 25 | |
26 | 26 | // Filter post actions. |
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
27 | + add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2); |
|
28 | 28 | |
29 | 29 | // Invoice table columns. |
30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
30 | + add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100); |
|
31 | + add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2); |
|
32 | 32 | |
33 | 33 | // Items table columns. |
34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
34 | + add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100); |
|
35 | + add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20); |
|
36 | + add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2); |
|
37 | + add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100); |
|
38 | + add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100); |
|
39 | + add_action('request', array(__CLASS__, 'reorder_items'), 100); |
|
40 | 40 | |
41 | 41 | // Payment forms columns. |
42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
42 | + add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100); |
|
43 | + add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2); |
|
44 | + add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2); |
|
45 | 45 | |
46 | 46 | // Discount table columns. |
47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
47 | + add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100); |
|
48 | 48 | |
49 | 49 | // Deleting posts. |
50 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
51 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
50 | + add_action('delete_post', array(__CLASS__, 'delete_post')); |
|
51 | + add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Post updated messages. |
56 | 56 | */ |
57 | - public static function post_updated_messages( $messages ) { |
|
57 | + public static function post_updated_messages($messages) { |
|
58 | 58 | global $post; |
59 | 59 | |
60 | 60 | $messages['wpi_discount'] = array( |
61 | 61 | 0 => '', |
62 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
63 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
64 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
65 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
66 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
67 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
68 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
69 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
70 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
71 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
62 | + 1 => __('Discount updated.', 'invoicing'), |
|
63 | + 2 => __('Custom field updated.', 'invoicing'), |
|
64 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
65 | + 4 => __('Discount updated.', 'invoicing'), |
|
66 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
67 | + 6 => __('Discount updated.', 'invoicing'), |
|
68 | + 7 => __('Discount saved.', 'invoicing'), |
|
69 | + 8 => __('Discount submitted.', 'invoicing'), |
|
70 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
71 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
72 | 72 | ); |
73 | 73 | |
74 | 74 | $messages['wpi_payment_form'] = array( |
75 | 75 | 0 => '', |
76 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
77 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
78 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
79 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
80 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
81 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
83 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
84 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
85 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
76 | + 1 => __('Payment Form updated.', 'invoicing'), |
|
77 | + 2 => __('Custom field updated.', 'invoicing'), |
|
78 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
79 | + 4 => __('Payment Form updated.', 'invoicing'), |
|
80 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
81 | + 6 => __('Payment Form updated.', 'invoicing'), |
|
82 | + 7 => __('Payment Form saved.', 'invoicing'), |
|
83 | + 8 => __('Payment Form submitted.', 'invoicing'), |
|
84 | + 9 => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
85 | + 10 => __('Payment Form draft updated.', 'invoicing'), |
|
86 | 86 | ); |
87 | 87 | |
88 | 88 | return $messages; |
@@ -92,14 +92,14 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * Post row actions. |
94 | 94 | */ |
95 | - public static function post_row_actions( $actions, $post ) { |
|
95 | + public static function post_row_actions($actions, $post) { |
|
96 | 96 | |
97 | - $post = get_post( $post ); |
|
97 | + $post = get_post($post); |
|
98 | 98 | |
99 | 99 | // We do not want to edit the default payment form. |
100 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
101 | - unset( $actions['trash'] ); |
|
102 | - unset( $actions['inline hide-if-no-js'] ); |
|
100 | + if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) { |
|
101 | + unset($actions['trash']); |
|
102 | + unset($actions['inline hide-if-no-js']); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $actions; |
@@ -108,51 +108,51 @@ discard block |
||
108 | 108 | /** |
109 | 109 | * Returns an array of invoice table columns. |
110 | 110 | */ |
111 | - public static function invoice_columns( $columns ) { |
|
111 | + public static function invoice_columns($columns) { |
|
112 | 112 | |
113 | 113 | $columns = array( |
114 | 114 | 'cb' => $columns['cb'], |
115 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
116 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
117 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
118 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
119 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
120 | - 'status' => __( 'Status', 'invoicing' ), |
|
121 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
115 | + 'number' => __('Invoice', 'invoicing'), |
|
116 | + 'customer' => __('Customer', 'invoicing'), |
|
117 | + 'invoice_date' => __('Date', 'invoicing'), |
|
118 | + 'amount' => __('Amount', 'invoicing'), |
|
119 | + 'recurring' => __('Recurring', 'invoicing'), |
|
120 | + 'status' => __('Status', 'invoicing'), |
|
121 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
122 | 122 | ); |
123 | 123 | |
124 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
124 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * Displays invoice table columns. |
129 | 129 | */ |
130 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
130 | + public static function display_invoice_columns($column_name, $post_id) { |
|
131 | 131 | |
132 | - $invoice = new WPInv_Invoice( $post_id ); |
|
132 | + $invoice = new WPInv_Invoice($post_id); |
|
133 | 133 | |
134 | - switch ( $column_name ) { |
|
134 | + switch ($column_name) { |
|
135 | 135 | |
136 | 136 | case 'invoice_date' : |
137 | - $date_time = sanitize_text_field( $invoice->get_created_date() ); |
|
138 | - $date = mysql2date( get_option( 'date_format' ), $date_time ); |
|
137 | + $date_time = sanitize_text_field($invoice->get_created_date()); |
|
138 | + $date = mysql2date(get_option('date_format'), $date_time); |
|
139 | 139 | echo "<span title='$date_time'>$date</span>"; |
140 | 140 | break; |
141 | 141 | |
142 | 142 | case 'amount' : |
143 | 143 | |
144 | 144 | $amount = $invoice->get_total(); |
145 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
145 | + $formated_amount = wpinv_price(wpinv_format_amount($amount), $invoice->get_currency()); |
|
146 | 146 | |
147 | - if ( $invoice->is_refunded() ) { |
|
148 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
147 | + if ($invoice->is_refunded()) { |
|
148 | + $refunded_amount = wpinv_price(wpinv_format_amount(0), $invoice->get_currency()); |
|
149 | 149 | echo "<del>$formated_amount</del><ins>$refunded_amount</ins>"; |
150 | 150 | } else { |
151 | 151 | |
152 | 152 | $discount = $invoice->get_total_discount(); |
153 | 153 | |
154 | - if ( ! empty( $discount ) ) { |
|
155 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
154 | + if (!empty($discount)) { |
|
155 | + $new_amount = wpinv_price(wpinv_format_amount($amount + $discount), $invoice->get_currency()); |
|
156 | 156 | echo "<del>$new_amount</del><ins>$formated_amount</ins>"; |
157 | 157 | } else { |
158 | 158 | echo $formated_amount; |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | break; |
164 | 164 | |
165 | 165 | case 'status' : |
166 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
167 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
166 | + $status = sanitize_text_field($invoice->get_status()); |
|
167 | + $status_label = sanitize_text_field($invoice->get_status_nicename()); |
|
168 | 168 | |
169 | 169 | // If it is paid, show the gateway title. |
170 | - if ( $invoice->is_paid() ) { |
|
171 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
172 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
170 | + if ($invoice->is_paid()) { |
|
171 | + $gateway = sanitize_text_field($invoice->get_gateway_title()); |
|
172 | + $gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway); |
|
173 | 173 | |
174 | 174 | echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
175 | 175 | } else { |
@@ -177,22 +177,22 @@ discard block |
||
177 | 177 | } |
178 | 178 | |
179 | 179 | // If it is not paid, display the overdue and view status. |
180 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
180 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
181 | 181 | |
182 | 182 | // Invoice view status. |
183 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
184 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
183 | + if (wpinv_is_invoice_viewed($invoice->get_id())) { |
|
184 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>'; |
|
185 | 185 | } else { |
186 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
186 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>'; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | // Display the overview status. |
190 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
190 | + if (wpinv_get_option('overdue_active')) { |
|
191 | 191 | $due_date = $invoice->get_due_date(); |
192 | 192 | |
193 | - if ( ! empty( $due_date ) ) { |
|
194 | - $date = mysql2date( get_option( 'date_format' ), $due_date ); |
|
195 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $date ); |
|
193 | + if (!empty($due_date)) { |
|
194 | + $date = mysql2date(get_option('date_format'), $due_date); |
|
195 | + $date = wp_sprintf(__('Due %s', 'invoicing'), $date); |
|
196 | 196 | echo "<p class='description' style='color: #888;' title='$due_date'>$date</p>"; |
197 | 197 | } |
198 | 198 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | |
204 | 204 | case 'recurring': |
205 | 205 | |
206 | - if ( $invoice->is_recurring() ) { |
|
206 | + if ($invoice->is_recurring()) { |
|
207 | 207 | echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
208 | 208 | } else { |
209 | 209 | echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | |
213 | 213 | case 'number' : |
214 | 214 | |
215 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
216 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
217 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
215 | + $edit_link = esc_url(get_edit_post_link($invoice->get_id())); |
|
216 | + $invoice_number = sanitize_text_field($invoice->get_number()); |
|
217 | + $invoice_details = esc_attr__('View Invoice Details', 'invoicing'); |
|
218 | 218 | |
219 | 219 | echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
220 | 220 | |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | |
225 | 225 | $customer_name = $invoice->get_user_full_name(); |
226 | 226 | |
227 | - if ( empty( $customer_name ) ) { |
|
227 | + if (empty($customer_name)) { |
|
228 | 228 | $customer_name = $invoice->get_email(); |
229 | 229 | } |
230 | 230 | |
231 | - if ( ! empty( $customer_name ) ) { |
|
232 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
233 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
231 | + if (!empty($customer_name)) { |
|
232 | + $customer_details = esc_attr__('View Customer Details', 'invoicing'); |
|
233 | + $view_link = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php'))); |
|
234 | 234 | echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
235 | 235 | } else { |
236 | 236 | echo '<div>—</div>'; |
@@ -240,15 +240,15 @@ discard block |
||
240 | 240 | |
241 | 241 | case 'wpi_actions' : |
242 | 242 | |
243 | - if ( ! $invoice->is_draft() ) { |
|
244 | - $url = esc_url( $invoice->get_view_url() ); |
|
245 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
243 | + if (!$invoice->is_draft()) { |
|
244 | + $url = esc_url($invoice->get_view_url()); |
|
245 | + $print = esc_attr__('Print invoice', 'invoicing'); |
|
246 | 246 | echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
247 | 247 | } |
248 | 248 | |
249 | - if ( $invoice->get_email() ) { |
|
250 | - $url = esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $invoice->get_id() ) ) ); |
|
251 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
249 | + if ($invoice->get_email()) { |
|
250 | + $url = esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $invoice->get_id()))); |
|
251 | + $send = esc_attr__('Send invoice to customer', 'invoicing'); |
|
252 | 252 | echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
253 | 253 | } |
254 | 254 | |
@@ -260,50 +260,50 @@ discard block |
||
260 | 260 | /** |
261 | 261 | * Returns an array of payment forms table columns. |
262 | 262 | */ |
263 | - public static function payment_form_columns( $columns ) { |
|
263 | + public static function payment_form_columns($columns) { |
|
264 | 264 | |
265 | 265 | $columns = array( |
266 | 266 | 'cb' => $columns['cb'], |
267 | - 'title' => __( 'Name', 'invoicing' ), |
|
268 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
269 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
270 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
271 | - 'items' => __( 'Items', 'invoicing' ), |
|
272 | - 'date' => __( 'Date', 'invoicing' ), |
|
267 | + 'title' => __('Name', 'invoicing'), |
|
268 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
269 | + 'earnings' => __('Revenue', 'invoicing'), |
|
270 | + 'refunds' => __('Refunded', 'invoicing'), |
|
271 | + 'items' => __('Items', 'invoicing'), |
|
272 | + 'date' => __('Date', 'invoicing'), |
|
273 | 273 | ); |
274 | 274 | |
275 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
275 | + return apply_filters('wpi_payment_form_table_columns', $columns); |
|
276 | 276 | |
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
280 | 280 | * Displays payment form table columns. |
281 | 281 | */ |
282 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
282 | + public static function display_payment_form_columns($column_name, $post_id) { |
|
283 | 283 | |
284 | 284 | // Retrieve the payment form. |
285 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
285 | + $form = new GetPaid_Payment_Form($post_id); |
|
286 | 286 | |
287 | - switch ( $column_name ) { |
|
287 | + switch ($column_name) { |
|
288 | 288 | |
289 | 289 | case 'earnings' : |
290 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
290 | + echo wpinv_price(wpinv_format_amount($form->get_earned())); |
|
291 | 291 | break; |
292 | 292 | |
293 | 293 | case 'refunds' : |
294 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
294 | + echo wpinv_price(wpinv_format_amount($form->get_refunded())); |
|
295 | 295 | break; |
296 | 296 | |
297 | 297 | case 'refunds' : |
298 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
298 | + echo wpinv_price(wpinv_format_amount($form->get_refunded())); |
|
299 | 299 | break; |
300 | 300 | |
301 | 301 | case 'shortcode' : |
302 | 302 | |
303 | - if ( $form->is_default() ) { |
|
303 | + if ($form->is_default()) { |
|
304 | 304 | echo '—'; |
305 | 305 | } else { |
306 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
306 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>'; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | break; |
@@ -312,29 +312,29 @@ discard block |
||
312 | 312 | |
313 | 313 | $items = $form->get_items(); |
314 | 314 | |
315 | - if ( $form->is_default() || empty( $items ) ) { |
|
315 | + if ($form->is_default() || empty($items)) { |
|
316 | 316 | echo '—'; |
317 | 317 | return; |
318 | 318 | } |
319 | 319 | |
320 | 320 | $_items = array(); |
321 | 321 | |
322 | - foreach ( $items as $item ) { |
|
322 | + foreach ($items as $item) { |
|
323 | 323 | $url = $item->get_edit_url(); |
324 | 324 | |
325 | - if ( empty( $url ) ) { |
|
326 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
325 | + if (empty($url)) { |
|
326 | + $_items[] = sanitize_text_field($item->get_name()); |
|
327 | 327 | } else { |
328 | 328 | $_items[] = sprintf( |
329 | 329 | '<a href="%s">%s</a>', |
330 | - esc_url( $url ), |
|
331 | - sanitize_text_field( $item->get_name() ) |
|
330 | + esc_url($url), |
|
331 | + sanitize_text_field($item->get_name()) |
|
332 | 332 | ); |
333 | 333 | } |
334 | 334 | |
335 | 335 | } |
336 | 336 | |
337 | - echo implode( '<br>', $_items ); |
|
337 | + echo implode('<br>', $_items); |
|
338 | 338 | |
339 | 339 | break; |
340 | 340 | |
@@ -345,10 +345,10 @@ discard block |
||
345 | 345 | /** |
346 | 346 | * Filters post states. |
347 | 347 | */ |
348 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
348 | + public static function filter_payment_form_state($post_states, $post) { |
|
349 | 349 | |
350 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
351 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
350 | + if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) { |
|
351 | + $post_states['default_form'] = __('Default Payment Form', 'invoicing'); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | return $post_states; |
@@ -358,42 +358,42 @@ discard block |
||
358 | 358 | /** |
359 | 359 | * Returns an array of coupon table columns. |
360 | 360 | */ |
361 | - public static function discount_columns( $columns ) { |
|
361 | + public static function discount_columns($columns) { |
|
362 | 362 | |
363 | 363 | $columns = array( |
364 | 364 | 'cb' => $columns['cb'], |
365 | - 'title' => __( 'Name', 'invoicing' ), |
|
366 | - 'code' => __( 'Code', 'invoicing' ), |
|
367 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
368 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
369 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
370 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
365 | + 'title' => __('Name', 'invoicing'), |
|
366 | + 'code' => __('Code', 'invoicing'), |
|
367 | + 'amount' => __('Amount', 'invoicing'), |
|
368 | + 'usage' => __('Usage / Limit', 'invoicing'), |
|
369 | + 'start_date' => __('Start Date', 'invoicing'), |
|
370 | + 'expiry_date' => __('Expiry Date', 'invoicing'), |
|
371 | 371 | ); |
372 | 372 | |
373 | 373 | |
374 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
375 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
376 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
377 | - $columns['start_date'] = __( 'Start Date', 'invoicing' ); |
|
378 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
374 | + $columns['code'] = __('Code', 'invoicing'); |
|
375 | + $columns['amount'] = __('Amount', 'invoicing'); |
|
376 | + $columns['usage'] = __('Usage / Limit', 'invoicing'); |
|
377 | + $columns['start_date'] = __('Start Date', 'invoicing'); |
|
378 | + $columns['expiry_date'] = __('Expiry Date', 'invoicing'); |
|
379 | 379 | |
380 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
380 | + return apply_filters('wpi_discount_table_columns', $columns); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
384 | 384 | * Filters post states. |
385 | 385 | */ |
386 | - public static function filter_discount_state( $post_states, $post ) { |
|
386 | + public static function filter_discount_state($post_states, $post) { |
|
387 | 387 | |
388 | - if ( 'wpi_discount' == $post->post_type ) { |
|
388 | + if ('wpi_discount' == $post->post_type) { |
|
389 | 389 | |
390 | - $discount = new WPInv_Discount( $post ); |
|
390 | + $discount = new WPInv_Discount($post); |
|
391 | 391 | |
392 | 392 | $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
393 | 393 | |
394 | - if ( $status != 'publish' ) { |
|
394 | + if ($status != 'publish') { |
|
395 | 395 | return array( |
396 | - 'discount_status' => wpinv_discount_status( $status ), |
|
396 | + 'discount_status' => wpinv_discount_status($status), |
|
397 | 397 | ); |
398 | 398 | } |
399 | 399 | |
@@ -408,34 +408,34 @@ discard block |
||
408 | 408 | /** |
409 | 409 | * Returns an array of items table columns. |
410 | 410 | */ |
411 | - public static function item_columns( $columns ) { |
|
411 | + public static function item_columns($columns) { |
|
412 | 412 | global $wpinv_euvat; |
413 | 413 | |
414 | 414 | $columns = array( |
415 | 415 | 'cb' => $columns['cb'], |
416 | - 'title' => __( 'Name', 'invoicing' ), |
|
417 | - 'price' => __( 'Price', 'invoicing' ), |
|
418 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
419 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
420 | - 'type' => __( 'Type', 'invoicing' ), |
|
421 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
416 | + 'title' => __('Name', 'invoicing'), |
|
417 | + 'price' => __('Price', 'invoicing'), |
|
418 | + 'vat_rule' => __('VAT rule', 'invoicing'), |
|
419 | + 'vat_class' => __('VAT class', 'invoicing'), |
|
420 | + 'type' => __('Type', 'invoicing'), |
|
421 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
422 | 422 | ); |
423 | 423 | |
424 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
425 | - unset( $columns['vat_rule'] ); |
|
424 | + if (!$wpinv_euvat->allow_vat_rules()) { |
|
425 | + unset($columns['vat_rule']); |
|
426 | 426 | } |
427 | 427 | |
428 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
429 | - unset( $columns['vat_class'] ); |
|
428 | + if (!$wpinv_euvat->allow_vat_classes()) { |
|
429 | + unset($columns['vat_class']); |
|
430 | 430 | } |
431 | 431 | |
432 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
432 | + return apply_filters('wpi_item_table_columns', $columns); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
436 | 436 | * Returns an array of sortable items table columns. |
437 | 437 | */ |
438 | - public static function sortable_item_columns( $columns ) { |
|
438 | + public static function sortable_item_columns($columns) { |
|
439 | 439 | |
440 | 440 | return array_merge( |
441 | 441 | $columns, |
@@ -452,50 +452,50 @@ discard block |
||
452 | 452 | /** |
453 | 453 | * Displays items table columns. |
454 | 454 | */ |
455 | - public static function display_item_columns( $column_name, $post_id ) { |
|
455 | + public static function display_item_columns($column_name, $post_id) { |
|
456 | 456 | global $wpinv_euvat; |
457 | 457 | |
458 | - $item = new WPInv_Item( $post_id ); |
|
458 | + $item = new WPInv_Item($post_id); |
|
459 | 459 | |
460 | - switch ( $column_name ) { |
|
460 | + switch ($column_name) { |
|
461 | 461 | |
462 | 462 | case 'price' : |
463 | 463 | |
464 | - if ( ! $item->is_recurring() ) { |
|
464 | + if (!$item->is_recurring()) { |
|
465 | 465 | echo $item->get_the_price(); |
466 | 466 | break; |
467 | 467 | } |
468 | 468 | |
469 | 469 | $price = wp_sprintf( |
470 | - __( '%s / %s', 'invoicing' ), |
|
470 | + __('%s / %s', 'invoicing'), |
|
471 | 471 | $item->get_the_price(), |
472 | - WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() ) |
|
472 | + WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->get_recurring_period(), $item->get_recurring_interval()) |
|
473 | 473 | ); |
474 | 474 | |
475 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
475 | + if ($item->get_the_price() == $item->get_the_initial_price()) { |
|
476 | 476 | echo $price; |
477 | 477 | break; |
478 | 478 | } |
479 | 479 | |
480 | 480 | echo $item->get_the_initial_price(); |
481 | 481 | |
482 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
482 | + echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>'; |
|
483 | 483 | break; |
484 | 484 | |
485 | 485 | case 'vat_rule' : |
486 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
486 | + echo $wpinv_euvat->item_rule_label($item->get_id()); |
|
487 | 487 | break; |
488 | 488 | |
489 | 489 | case 'vat_class' : |
490 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
490 | + echo $wpinv_euvat->item_class_label($item->get_id()); |
|
491 | 491 | break; |
492 | 492 | |
493 | 493 | case 'shortcode' : |
494 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
494 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
495 | 495 | break; |
496 | 496 | |
497 | 497 | case 'type' : |
498 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
498 | + echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
499 | 499 | break; |
500 | 500 | |
501 | 501 | } |
@@ -505,21 +505,21 @@ discard block |
||
505 | 505 | /** |
506 | 506 | * Lets users filter items using taxes. |
507 | 507 | */ |
508 | - public static function add_item_filters( $post_type ) { |
|
508 | + public static function add_item_filters($post_type) { |
|
509 | 509 | global $wpinv_euvat; |
510 | 510 | |
511 | 511 | // Abort if we're not dealing with items. |
512 | - if ( $post_type != 'wpi_item' ) { |
|
512 | + if ($post_type != 'wpi_item') { |
|
513 | 513 | return; |
514 | 514 | } |
515 | 515 | |
516 | 516 | // Filter by vat rules. |
517 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
517 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
518 | 518 | |
519 | 519 | // Sanitize selected vat rule. |
520 | - $vat_rule = ''; |
|
521 | - if ( isset( $_GET['vat_rule'] ) && array_key_exists( $_GET['vat_rule'], $wpinv_euvat->get_rules() ) ) { |
|
522 | - $vat_rule = $_GET['vat_rule']; |
|
520 | + $vat_rule = ''; |
|
521 | + if (isset($_GET['vat_rule']) && array_key_exists($_GET['vat_rule'], $wpinv_euvat->get_rules())) { |
|
522 | + $vat_rule = $_GET['vat_rule']; |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | // Filter by VAT rule. |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | array( |
528 | 528 | 'options' => array_merge( |
529 | 529 | array( |
530 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
530 | + '' => __('All VAT rules', 'invoicing') |
|
531 | 531 | ), |
532 | 532 | $wpinv_euvat->get_rules() |
533 | 533 | ), |
@@ -544,19 +544,19 @@ discard block |
||
544 | 544 | } |
545 | 545 | |
546 | 546 | // Filter by vat class. |
547 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
547 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
548 | 548 | |
549 | 549 | // Sanitize selected vat rule. |
550 | - $vat_class = ''; |
|
551 | - if ( isset( $_GET['vat_class'] ) && array_key_exists( $_GET['vat_class'], $wpinv_euvat->get_all_classes() ) ) { |
|
552 | - $vat_class = $_GET['vat_class']; |
|
550 | + $vat_class = ''; |
|
551 | + if (isset($_GET['vat_class']) && array_key_exists($_GET['vat_class'], $wpinv_euvat->get_all_classes())) { |
|
552 | + $vat_class = $_GET['vat_class']; |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | echo wpinv_html_select( |
556 | 556 | array( |
557 | 557 | 'options' => array_merge( |
558 | 558 | array( |
559 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
559 | + '' => __('All VAT classes', 'invoicing') |
|
560 | 560 | ), |
561 | 561 | $wpinv_euvat->get_all_classes() |
562 | 562 | ), |
@@ -572,16 +572,16 @@ discard block |
||
572 | 572 | } |
573 | 573 | |
574 | 574 | // Filter by item type. |
575 | - $type = ''; |
|
576 | - if( isset( $_GET['type'] ) && array_key_exists( $_GET['type'], wpinv_get_item_types() ) ) { |
|
577 | - $type = $_GET['type']; |
|
575 | + $type = ''; |
|
576 | + if (isset($_GET['type']) && array_key_exists($_GET['type'], wpinv_get_item_types())) { |
|
577 | + $type = $_GET['type']; |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | echo wpinv_html_select( |
581 | 581 | array( |
582 | 582 | 'options' => array_merge( |
583 | 583 | array( |
584 | - '' => __( 'All item types', 'invoicing' ) |
|
584 | + '' => __('All item types', 'invoicing') |
|
585 | 585 | ), |
586 | 586 | wpinv_get_item_types() |
587 | 587 | ), |
@@ -599,45 +599,45 @@ discard block |
||
599 | 599 | /** |
600 | 600 | * Filters the item query. |
601 | 601 | */ |
602 | - public static function filter_item_query( $query ) { |
|
602 | + public static function filter_item_query($query) { |
|
603 | 603 | |
604 | 604 | // modify the query only if it admin and main query. |
605 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
605 | + if (!(is_admin() && $query->is_main_query())) { |
|
606 | 606 | return $query; |
607 | 607 | } |
608 | 608 | |
609 | 609 | // we want to modify the query for our items. |
610 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
610 | + if ('wpi_item' != $query->query['post_type']) { |
|
611 | 611 | return $query; |
612 | 612 | } |
613 | 613 | |
614 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
614 | + if (empty($query->query_vars['meta_query'])) { |
|
615 | 615 | $query->query_vars['meta_query'] = array(); |
616 | 616 | } |
617 | 617 | |
618 | 618 | // Filter vat rule type |
619 | - if ( ! empty( $_GET['vat_rule'] ) ) { |
|
619 | + if (!empty($_GET['vat_rule'])) { |
|
620 | 620 | $query->query_vars['meta_query'][] = array( |
621 | 621 | 'key' => '_wpinv_vat_rule', |
622 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
622 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
623 | 623 | 'compare' => '=' |
624 | 624 | ); |
625 | 625 | } |
626 | 626 | |
627 | 627 | // Filter vat class |
628 | - if ( ! empty( $_GET['vat_class'] ) ) { |
|
628 | + if (!empty($_GET['vat_class'])) { |
|
629 | 629 | $query->query_vars['meta_query'][] = array( |
630 | 630 | 'key' => '_wpinv_vat_class', |
631 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
631 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
632 | 632 | 'compare' => '=' |
633 | 633 | ); |
634 | 634 | } |
635 | 635 | |
636 | 636 | // Filter item type |
637 | - if ( ! empty( $_GET['type'] ) ) { |
|
637 | + if (!empty($_GET['type'])) { |
|
638 | 638 | $query->query_vars['meta_query'][] = array( |
639 | 639 | 'key' => '_wpinv_type', |
640 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
640 | + 'value' => sanitize_text_field($_GET['type']), |
|
641 | 641 | 'compare' => '=' |
642 | 642 | ); |
643 | 643 | } |
@@ -647,15 +647,15 @@ discard block |
||
647 | 647 | /** |
648 | 648 | * Reorders items. |
649 | 649 | */ |
650 | - public static function reorder_items( $vars ) { |
|
650 | + public static function reorder_items($vars) { |
|
651 | 651 | global $typenow; |
652 | 652 | |
653 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
653 | + if ('wpi_item' !== $typenow || empty($vars['orderby'])) { |
|
654 | 654 | return $vars; |
655 | 655 | } |
656 | 656 | |
657 | 657 | // By item type. |
658 | - if ( 'type' == $vars['orderby'] ) { |
|
658 | + if ('type' == $vars['orderby']) { |
|
659 | 659 | return array_merge( |
660 | 660 | $vars, |
661 | 661 | array( |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | } |
667 | 667 | |
668 | 668 | // By vat class. |
669 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
669 | + if ('vat_class' == $vars['orderby']) { |
|
670 | 670 | return array_merge( |
671 | 671 | $vars, |
672 | 672 | array( |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | } |
678 | 678 | |
679 | 679 | // By vat rule. |
680 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
680 | + if ('vat_rule' == $vars['orderby']) { |
|
681 | 681 | return array_merge( |
682 | 682 | $vars, |
683 | 683 | array( |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | } |
689 | 689 | |
690 | 690 | // By price. |
691 | - if ( 'price' == $vars['orderby'] ) { |
|
691 | + if ('price' == $vars['orderby']) { |
|
692 | 692 | return array_merge( |
693 | 693 | $vars, |
694 | 694 | array( |
@@ -705,27 +705,27 @@ discard block |
||
705 | 705 | /** |
706 | 706 | * Fired when deleting a post. |
707 | 707 | */ |
708 | - public static function delete_post( $post_id ) { |
|
708 | + public static function delete_post($post_id) { |
|
709 | 709 | |
710 | - switch ( get_post_type( $post_id ) ) { |
|
710 | + switch (get_post_type($post_id)) { |
|
711 | 711 | |
712 | 712 | case 'wpi_item' : |
713 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
713 | + do_action("getpaid_before_delete_item", new WPInv_Item($post_id)); |
|
714 | 714 | break; |
715 | 715 | |
716 | 716 | case 'wpi_payment_form' : |
717 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
717 | + do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id)); |
|
718 | 718 | break; |
719 | 719 | |
720 | 720 | case 'wpi_discount' : |
721 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
721 | + do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id)); |
|
722 | 722 | break; |
723 | 723 | |
724 | 724 | case 'wpi_invoice' : |
725 | - $invoice = new WPInv_Invoice( $post_id ); |
|
726 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
727 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
728 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
725 | + $invoice = new WPInv_Invoice($post_id); |
|
726 | + do_action("getpaid_before_delete_invoice", $invoice); |
|
727 | + $invoice->get_data_store()->delete_items($invoice); |
|
728 | + $invoice->get_data_store()->delete_special_fields($invoice); |
|
729 | 729 | break; |
730 | 730 | } |
731 | 731 | } |
@@ -12,181 +12,181 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Metaboxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Only save metaboxes once. |
|
17 | - * |
|
18 | - * @var boolean |
|
19 | - */ |
|
20 | - private static $saved_meta_boxes = false; |
|
21 | - |
|
22 | 15 | /** |
23 | - * Hook in methods. |
|
24 | - */ |
|
25 | - public static function init() { |
|
26 | - |
|
27 | - // Register metaboxes. |
|
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 15, 2 ); |
|
29 | - |
|
30 | - // Remove metaboxes. |
|
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
16 | + * Only save metaboxes once. |
|
17 | + * |
|
18 | + * @var boolean |
|
19 | + */ |
|
20 | + private static $saved_meta_boxes = false; |
|
32 | 21 | |
33 | - // Rename metaboxes. |
|
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
35 | - |
|
36 | - // Save metaboxes. |
|
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | - } |
|
22 | + /** |
|
23 | + * Hook in methods. |
|
24 | + */ |
|
25 | + public static function init() { |
|
39 | 26 | |
40 | - /** |
|
41 | - * Register core metaboxes. |
|
42 | - */ |
|
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
44 | - global $wpinv_euvat; |
|
27 | + // Register metaboxes. |
|
28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 15, 2 ); |
|
45 | 29 | |
46 | - // For invoices... |
|
47 | - if ( $post_type == 'wpi_invoice' ) { |
|
48 | - $invoice = new WPInv_Invoice( $post ); |
|
30 | + // Remove metaboxes. |
|
31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
49 | 32 | |
50 | - // Resend invoice. |
|
51 | - if ( ! $invoice->is_draft() ) { |
|
52 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' ); |
|
53 | - } |
|
33 | + // Rename metaboxes. |
|
34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
54 | 35 | |
55 | - // Subscriptions. |
|
56 | - if ( $invoice->is_recurring() ) { |
|
57 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'side', 'high' ); |
|
58 | - } |
|
36 | + // Save metaboxes. |
|
37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
38 | + } |
|
59 | 39 | |
60 | - // Invoice details. |
|
61 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
40 | + /** |
|
41 | + * Register core metaboxes. |
|
42 | + */ |
|
43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
44 | + global $wpinv_euvat; |
|
45 | + |
|
46 | + // For invoices... |
|
47 | + if ( $post_type == 'wpi_invoice' ) { |
|
48 | + $invoice = new WPInv_Invoice( $post ); |
|
49 | + |
|
50 | + // Resend invoice. |
|
51 | + if ( ! $invoice->is_draft() ) { |
|
52 | + add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' ); |
|
53 | + } |
|
54 | + |
|
55 | + // Subscriptions. |
|
56 | + if ( $invoice->is_recurring() ) { |
|
57 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'side', 'high' ); |
|
58 | + } |
|
59 | + |
|
60 | + // Invoice details. |
|
61 | + add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
62 | 62 | |
63 | - // Payment details. |
|
64 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' ); |
|
63 | + // Payment details. |
|
64 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' ); |
|
65 | 65 | |
66 | - // Billing details. |
|
67 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' ); |
|
66 | + // Billing details. |
|
67 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' ); |
|
68 | 68 | |
69 | - // Invoice items. |
|
70 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
69 | + // Invoice items. |
|
70 | + add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
71 | 71 | |
72 | - // Invoice notes. |
|
73 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
72 | + // Invoice notes. |
|
73 | + add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
74 | 74 | |
75 | - // Payment form information. |
|
76 | - if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
77 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
|
78 | - } |
|
79 | - } |
|
75 | + // Payment form information. |
|
76 | + if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
77 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - // For payment forms. |
|
82 | - if ( $post_type == 'wpi_payment_form' ) { |
|
81 | + // For payment forms. |
|
82 | + if ( $post_type == 'wpi_payment_form' ) { |
|
83 | 83 | |
84 | - // Design payment form. |
|
85 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
84 | + // Design payment form. |
|
85 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
86 | 86 | |
87 | - // Payment form information. |
|
88 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
87 | + // Payment form information. |
|
88 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
89 | 89 | |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - // For invoice items. |
|
93 | - if ( $post_type == 'wpi_item' ) { |
|
92 | + // For invoice items. |
|
93 | + if ( $post_type == 'wpi_item' ) { |
|
94 | 94 | |
95 | - // Item details. |
|
96 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
95 | + // Item details. |
|
96 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
97 | 97 | |
98 | - // If taxes are enabled, register the tax metabox. |
|
99 | - if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
|
100 | - add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
101 | - } |
|
98 | + // If taxes are enabled, register the tax metabox. |
|
99 | + if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
|
100 | + add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
101 | + } |
|
102 | 102 | |
103 | - // Item info. |
|
104 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
103 | + // Item info. |
|
104 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
105 | 105 | |
106 | - } |
|
106 | + } |
|
107 | 107 | |
108 | - // For invoice discounts. |
|
109 | - if ( $post_type == 'wpi_discount' ) { |
|
110 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
111 | - } |
|
108 | + // For invoice discounts. |
|
109 | + if ( $post_type == 'wpi_discount' ) { |
|
110 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
111 | + } |
|
112 | 112 | |
113 | 113 | |
114 | - } |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Remove some metaboxes. |
|
118 | - */ |
|
119 | - public static function remove_meta_boxes() { |
|
120 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
121 | - } |
|
116 | + /** |
|
117 | + * Remove some metaboxes. |
|
118 | + */ |
|
119 | + public static function remove_meta_boxes() { |
|
120 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Rename other metaboxes. |
|
125 | - */ |
|
126 | - public static function rename_meta_boxes() { |
|
123 | + /** |
|
124 | + * Rename other metaboxes. |
|
125 | + */ |
|
126 | + public static function rename_meta_boxes() { |
|
127 | 127 | |
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Check if we're saving, then trigger an action based on the post type. |
|
132 | - * |
|
133 | - * @param int $post_id Post ID. |
|
134 | - * @param object $post Post object. |
|
135 | - */ |
|
136 | - public static function save_meta_boxes( $post_id, $post ) { |
|
137 | - $post_id = absint( $post_id ); |
|
138 | - |
|
139 | - // Do not save for ajax requests. |
|
140 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
141 | - return; |
|
142 | - } |
|
143 | - |
|
144 | - // $post_id and $post are required |
|
145 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
146 | - return; |
|
147 | - } |
|
148 | - |
|
149 | - // Dont' save meta boxes for revisions or autosaves. |
|
150 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
151 | - return; |
|
152 | - } |
|
153 | - |
|
154 | - // Check the nonce. |
|
155 | - if ( empty( $_POST['getpaid_meta_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['getpaid_meta_nonce'] ), 'getpaid_meta_nonce' ) ) { |
|
156 | - return; |
|
157 | - } |
|
158 | - |
|
159 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
160 | - if ( empty( $_POST['post_ID'] ) || absint( $_POST['post_ID'] ) !== $post_id ) { |
|
161 | - return; |
|
162 | - } |
|
163 | - |
|
164 | - // Check user has permission to edit. |
|
165 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
166 | - return; |
|
167 | - } |
|
168 | - |
|
169 | - // Ensure this is our post type. |
|
170 | - $post_types_map = array( |
|
171 | - 'wpi_invoice' => 'GetPaid_Meta_Box_Invoice_Address', |
|
172 | - 'wpi_quote' => 'GetPaid_Meta_Box_Invoice_Address', |
|
173 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
174 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
175 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
176 | - ); |
|
177 | - |
|
178 | - // Is this our post type? |
|
179 | - if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
180 | - return; |
|
181 | - } |
|
182 | - |
|
183 | - // We need this save event to run once to avoid potential endless loops. |
|
184 | - self::$saved_meta_boxes = true; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Check if we're saving, then trigger an action based on the post type. |
|
132 | + * |
|
133 | + * @param int $post_id Post ID. |
|
134 | + * @param object $post Post object. |
|
135 | + */ |
|
136 | + public static function save_meta_boxes( $post_id, $post ) { |
|
137 | + $post_id = absint( $post_id ); |
|
138 | + |
|
139 | + // Do not save for ajax requests. |
|
140 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
141 | + return; |
|
142 | + } |
|
143 | + |
|
144 | + // $post_id and $post are required |
|
145 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
146 | + return; |
|
147 | + } |
|
148 | + |
|
149 | + // Dont' save meta boxes for revisions or autosaves. |
|
150 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
151 | + return; |
|
152 | + } |
|
153 | + |
|
154 | + // Check the nonce. |
|
155 | + if ( empty( $_POST['getpaid_meta_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['getpaid_meta_nonce'] ), 'getpaid_meta_nonce' ) ) { |
|
156 | + return; |
|
157 | + } |
|
158 | + |
|
159 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
160 | + if ( empty( $_POST['post_ID'] ) || absint( $_POST['post_ID'] ) !== $post_id ) { |
|
161 | + return; |
|
162 | + } |
|
163 | + |
|
164 | + // Check user has permission to edit. |
|
165 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
166 | + return; |
|
167 | + } |
|
168 | + |
|
169 | + // Ensure this is our post type. |
|
170 | + $post_types_map = array( |
|
171 | + 'wpi_invoice' => 'GetPaid_Meta_Box_Invoice_Address', |
|
172 | + 'wpi_quote' => 'GetPaid_Meta_Box_Invoice_Address', |
|
173 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
174 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
175 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
176 | + ); |
|
177 | + |
|
178 | + // Is this our post type? |
|
179 | + if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
180 | + return; |
|
181 | + } |
|
182 | + |
|
183 | + // We need this save event to run once to avoid potential endless loops. |
|
184 | + self::$saved_meta_boxes = true; |
|
185 | 185 | |
186 | - // Save the post. |
|
187 | - $class = $post_types_map[ $post->post_type ]; |
|
188 | - $class::save( $post_id, $_POST, $post ); |
|
186 | + // Save the post. |
|
187 | + $class = $post_types_map[ $post->post_type ]; |
|
188 | + $class::save( $post_id, $_POST, $post ); |
|
189 | 189 | |
190 | - } |
|
190 | + } |
|
191 | 191 | |
192 | 192 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Metaboxes Admin Class |
@@ -25,89 +25,89 @@ discard block |
||
25 | 25 | public static function init() { |
26 | 26 | |
27 | 27 | // Register metaboxes. |
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 15, 2 ); |
|
28 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 15, 2); |
|
29 | 29 | |
30 | 30 | // Remove metaboxes. |
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
31 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30); |
|
32 | 32 | |
33 | 33 | // Rename metaboxes. |
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
34 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45); |
|
35 | 35 | |
36 | 36 | // Save metaboxes. |
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
37 | + add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Register core metaboxes. |
42 | 42 | */ |
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
43 | + public static function add_meta_boxes($post_type, $post) { |
|
44 | 44 | global $wpinv_euvat; |
45 | 45 | |
46 | 46 | // For invoices... |
47 | - if ( $post_type == 'wpi_invoice' ) { |
|
48 | - $invoice = new WPInv_Invoice( $post ); |
|
47 | + if ($post_type == 'wpi_invoice') { |
|
48 | + $invoice = new WPInv_Invoice($post); |
|
49 | 49 | |
50 | 50 | // Resend invoice. |
51 | - if ( ! $invoice->is_draft() ) { |
|
52 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' ); |
|
51 | + if (!$invoice->is_draft()) { |
|
52 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | // Subscriptions. |
56 | - if ( $invoice->is_recurring() ) { |
|
57 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'side', 'high' ); |
|
56 | + if ($invoice->is_recurring()) { |
|
57 | + add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'side', 'high'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Invoice details. |
61 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
61 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default'); |
|
62 | 62 | |
63 | 63 | // Payment details. |
64 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' ); |
|
64 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default'); |
|
65 | 65 | |
66 | 66 | // Billing details. |
67 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' ); |
|
67 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high'); |
|
68 | 68 | |
69 | 69 | // Invoice items. |
70 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
70 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
71 | 71 | |
72 | 72 | // Invoice notes. |
73 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
73 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
74 | 74 | |
75 | 75 | // Payment form information. |
76 | - if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
77 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
|
76 | + if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) { |
|
77 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high'); |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | 81 | // For payment forms. |
82 | - if ( $post_type == 'wpi_payment_form' ) { |
|
82 | + if ($post_type == 'wpi_payment_form') { |
|
83 | 83 | |
84 | 84 | // Design payment form. |
85 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
85 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
86 | 86 | |
87 | 87 | // Payment form information. |
88 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
88 | + add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side'); |
|
89 | 89 | |
90 | 90 | } |
91 | 91 | |
92 | 92 | // For invoice items. |
93 | - if ( $post_type == 'wpi_item' ) { |
|
93 | + if ($post_type == 'wpi_item') { |
|
94 | 94 | |
95 | 95 | // Item details. |
96 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
96 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
97 | 97 | |
98 | 98 | // If taxes are enabled, register the tax metabox. |
99 | - if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
|
100 | - add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
99 | + if ($wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes()) { |
|
100 | + add_meta_box('wpinv_item_vat', __('VAT / Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | // Item info. |
104 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
104 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
105 | 105 | |
106 | 106 | } |
107 | 107 | |
108 | 108 | // For invoice discounts. |
109 | - if ( $post_type == 'wpi_discount' ) { |
|
110 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
109 | + if ($post_type == 'wpi_discount') { |
|
110 | + add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high'); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * Remove some metaboxes. |
118 | 118 | */ |
119 | 119 | public static function remove_meta_boxes() { |
120 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
120 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -133,36 +133,36 @@ discard block |
||
133 | 133 | * @param int $post_id Post ID. |
134 | 134 | * @param object $post Post object. |
135 | 135 | */ |
136 | - public static function save_meta_boxes( $post_id, $post ) { |
|
137 | - $post_id = absint( $post_id ); |
|
136 | + public static function save_meta_boxes($post_id, $post) { |
|
137 | + $post_id = absint($post_id); |
|
138 | 138 | |
139 | 139 | // Do not save for ajax requests. |
140 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
140 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
141 | 141 | return; |
142 | 142 | } |
143 | 143 | |
144 | 144 | // $post_id and $post are required |
145 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
145 | + if (empty($post_id) || empty($post) || self::$saved_meta_boxes) { |
|
146 | 146 | return; |
147 | 147 | } |
148 | 148 | |
149 | 149 | // Dont' save meta boxes for revisions or autosaves. |
150 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
150 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
151 | 151 | return; |
152 | 152 | } |
153 | 153 | |
154 | 154 | // Check the nonce. |
155 | - if ( empty( $_POST['getpaid_meta_nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['getpaid_meta_nonce'] ), 'getpaid_meta_nonce' ) ) { |
|
155 | + if (empty($_POST['getpaid_meta_nonce']) || !wp_verify_nonce(wp_unslash($_POST['getpaid_meta_nonce']), 'getpaid_meta_nonce')) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | 159 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
160 | - if ( empty( $_POST['post_ID'] ) || absint( $_POST['post_ID'] ) !== $post_id ) { |
|
160 | + if (empty($_POST['post_ID']) || absint($_POST['post_ID']) !== $post_id) { |
|
161 | 161 | return; |
162 | 162 | } |
163 | 163 | |
164 | 164 | // Check user has permission to edit. |
165 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
165 | + if (!current_user_can('edit_post', $post_id)) { |
|
166 | 166 | return; |
167 | 167 | } |
168 | 168 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | ); |
177 | 177 | |
178 | 178 | // Is this our post type? |
179 | - if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
179 | + if (empty($post->post_type) || !isset($post_types_map[$post->post_type])) { |
|
180 | 180 | return; |
181 | 181 | } |
182 | 182 | |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | self::$saved_meta_boxes = true; |
185 | 185 | |
186 | 186 | // Save the post. |
187 | - $class = $post_types_map[ $post->post_type ]; |
|
188 | - $class::save( $post_id, $_POST, $post ); |
|
187 | + $class = $post_types_map[$post->post_type]; |
|
188 | + $class::save($post_id, $_POST, $post); |
|
189 | 189 | |
190 | 190 | } |
191 | 191 |
@@ -56,69 +56,69 @@ |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_admin_messages() { |
59 | - global $wpinv_options, $pagenow, $post; |
|
59 | + global $wpinv_options, $pagenow, $post; |
|
60 | 60 | |
61 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
62 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
63 | - } |
|
61 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
62 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
63 | + } |
|
64 | 64 | |
65 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
66 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
67 | - } |
|
65 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
66 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
67 | + } |
|
68 | 68 | |
69 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
70 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
71 | - } |
|
69 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
70 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
71 | + } |
|
72 | 72 | |
73 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
74 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
75 | - } |
|
73 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
74 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
75 | + } |
|
76 | 76 | |
77 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
78 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
79 | - } |
|
77 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
78 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
79 | + } |
|
80 | 80 | |
81 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
82 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
83 | - } |
|
81 | + if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
82 | + add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
83 | + } |
|
84 | 84 | |
85 | - if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
86 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
87 | - } |
|
85 | + if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
86 | + add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
87 | + } |
|
88 | 88 | |
89 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
90 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
89 | + if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
90 | + add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
94 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
94 | + add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
98 | 98 | add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
99 | 99 | } |
100 | 100 | |
101 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
102 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
103 | - } |
|
101 | + if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
102 | + add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
103 | + } |
|
104 | 104 | |
105 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
106 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
107 | - } |
|
105 | + if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
106 | + add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
107 | + } |
|
108 | 108 | |
109 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
110 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
111 | - } |
|
109 | + if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
110 | + add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
111 | + } |
|
112 | 112 | |
113 | - if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
114 | - $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
113 | + if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
114 | + $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
115 | 115 | |
116 | - if ( !empty( $message ) ) { |
|
117 | - add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
118 | - } |
|
119 | - } |
|
116 | + if ( !empty( $message ) ) { |
|
117 | + add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
118 | + } |
|
119 | + } |
|
120 | 120 | |
121 | - settings_errors( 'wpinv-notices' ); |
|
121 | + settings_errors( 'wpinv-notices' ); |
|
122 | 122 | } |
123 | 123 | add_action( 'admin_notices', 'wpinv_admin_messages' ); |
124 | 124 |
@@ -7,127 +7,127 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | -function wpinv_bulk_actions( $actions ) { |
|
15 | - if ( isset( $actions['edit'] ) ) { |
|
16 | - unset( $actions['edit'] ); |
|
14 | +function wpinv_bulk_actions($actions) { |
|
15 | + if (isset($actions['edit'])) { |
|
16 | + unset($actions['edit']); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | return $actions; |
20 | 20 | } |
21 | -add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
22 | -add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' ); |
|
21 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
22 | +add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions'); |
|
23 | 23 | |
24 | -function wpinv_admin_post_id( $id = 0 ) { |
|
24 | +function wpinv_admin_post_id($id = 0) { |
|
25 | 25 | global $post; |
26 | 26 | |
27 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
28 | - return (int)$id; |
|
29 | - } else if ( get_the_ID() ) { |
|
27 | + if (isset($id) && !empty($id)) { |
|
28 | + return (int) $id; |
|
29 | + } else if (get_the_ID()) { |
|
30 | 30 | return (int) get_the_ID(); |
31 | - } else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
31 | + } else if (isset($post->ID) && !empty($post->ID)) { |
|
32 | 32 | return (int) $post->ID; |
33 | - } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
33 | + } else if (isset($_GET['post']) && !empty($_GET['post'])) { |
|
34 | 34 | return (int) $_GET['post']; |
35 | - } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
35 | + } else if (isset($_GET['id']) && !empty($_GET['id'])) { |
|
36 | 36 | return (int) $_GET['id']; |
37 | - } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
37 | + } else if (isset($_POST['id']) && !empty($_POST['id'])) { |
|
38 | 38 | return (int) $_POST['id']; |
39 | 39 | } |
40 | 40 | |
41 | 41 | return null; |
42 | 42 | } |
43 | 43 | |
44 | -function wpinv_admin_post_type( $id = 0 ) { |
|
45 | - if ( !$id ) { |
|
44 | +function wpinv_admin_post_type($id = 0) { |
|
45 | + if (!$id) { |
|
46 | 46 | $id = wpinv_admin_post_id(); |
47 | 47 | } |
48 | 48 | |
49 | - $type = get_post_type( $id ); |
|
49 | + $type = get_post_type($id); |
|
50 | 50 | |
51 | - if ( !$type ) { |
|
52 | - $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
51 | + if (!$type) { |
|
52 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null; |
|
53 | 53 | } |
54 | 54 | |
55 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
55 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | function wpinv_admin_messages() { |
59 | 59 | global $wpinv_options, $pagenow, $post; |
60 | 60 | |
61 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
62 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
61 | + if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
62 | + add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated'); |
|
63 | 63 | } |
64 | 64 | |
65 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
66 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
65 | + if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
66 | + add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error'); |
|
67 | 67 | } |
68 | 68 | |
69 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
70 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
69 | + if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
70 | + add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error'); |
|
71 | 71 | } |
72 | 72 | |
73 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
74 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
73 | + if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
74 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated'); |
|
75 | 75 | } |
76 | 76 | |
77 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
78 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
77 | + if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
78 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error'); |
|
79 | 79 | } |
80 | 80 | |
81 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
82 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
81 | + if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
82 | + add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated'); |
|
83 | 83 | } |
84 | 84 | |
85 | - if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
86 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
85 | + if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
86 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error'); |
|
87 | 87 | } |
88 | 88 | |
89 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
90 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
89 | + if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
90 | + add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated'); |
|
91 | 91 | } |
92 | 92 | |
93 | - if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
94 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
93 | + if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
94 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error'); |
|
95 | 95 | } |
96 | 96 | |
97 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
98 | - add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
|
97 | + if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
98 | + add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated'); |
|
99 | 99 | } |
100 | 100 | |
101 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
102 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
101 | + if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
102 | + add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated'); |
|
103 | 103 | } |
104 | 104 | |
105 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
106 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
105 | + if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
106 | + add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated'); |
|
107 | 107 | } |
108 | 108 | |
109 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
110 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
109 | + if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
110 | + add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated'); |
|
111 | 111 | } |
112 | 112 | |
113 | - if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
114 | - $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
113 | + if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) { |
|
114 | + $message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID); |
|
115 | 115 | |
116 | - if ( !empty( $message ) ) { |
|
117 | - add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
116 | + if (!empty($message)) { |
|
117 | + add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated'); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | - settings_errors( 'wpinv-notices' ); |
|
121 | + settings_errors('wpinv-notices'); |
|
122 | 122 | } |
123 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
123 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
124 | 124 | |
125 | -add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' ); |
|
126 | -function wpinv_show_test_payment_gateway_notice(){ |
|
127 | - add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' ); |
|
125 | +add_action('admin_init', 'wpinv_show_test_payment_gateway_notice'); |
|
126 | +function wpinv_show_test_payment_gateway_notice() { |
|
127 | + add_action('admin_notices', 'wpinv_test_payment_gateway_messages'); |
|
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_test_payment_gateway_messages(){ |
|
130 | +function wpinv_test_payment_gateway_messages() { |
|
131 | 131 | $gateways = wpinv_get_enabled_payment_gateways(); |
132 | 132 | $name = array(); $test_gateways = ''; |
133 | 133 | if ($gateways) { |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | } |
139 | 139 | $test_gateways = implode(', ', $name); |
140 | 140 | } |
141 | - if(isset($test_gateways) && !empty($test_gateways)){ |
|
141 | + if (isset($test_gateways) && !empty($test_gateways)) { |
|
142 | 142 | $link = admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
143 | - $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link ); |
|
143 | + $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link); |
|
144 | 144 | ?> |
145 | 145 | <div class="notice notice-warning is-dismissible"> |
146 | 146 | <p><?php echo $notice; ?></p> |
@@ -149,16 +149,16 @@ discard block |
||
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_send_invoice_after_save( $invoice ) { |
|
153 | - if ( empty( $_POST['wpi_save_send'] ) ) { |
|
152 | +function wpinv_send_invoice_after_save($invoice) { |
|
153 | + if (empty($_POST['wpi_save_send'])) { |
|
154 | 154 | return; |
155 | 155 | } |
156 | 156 | |
157 | - if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) { |
|
158 | - wpinv_user_invoice_notification( $invoice->ID ); |
|
157 | + if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) { |
|
158 | + wpinv_user_invoice_notification($invoice->ID); |
|
159 | 159 | } |
160 | 160 | } |
161 | -add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 ); |
|
161 | +add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1); |
|
162 | 162 | |
163 | 163 | |
164 | 164 | add_action('admin_init', 'admin_init_example_type'); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | function admin_init_example_type() { |
170 | 170 | global $typenow; |
171 | 171 | |
172 | - if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) { |
|
172 | + if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') { |
|
173 | 173 | add_filter('posts_search', 'posts_search_example_type', 10, 2); |
174 | 174 | } |
175 | 175 | } |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | global $wpdb; |
185 | 185 | |
186 | 186 | if ($query->is_main_query() && !empty($query->query['s'])) { |
187 | - $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )"; |
|
188 | - if ( ! empty( $search ) ) { |
|
189 | - $search = preg_replace( '/^ AND /', '', $search ); |
|
187 | + $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )"; |
|
188 | + if (!empty($search)) { |
|
189 | + $search = preg_replace('/^ AND /', '', $search); |
|
190 | 190 | $search = " AND ( {$search} OR ( {$conditions_str} ) )"; |
191 | 191 | } else { |
192 | 192 | $search = " AND ( {$conditions_str} )"; |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | return $search; |
197 | 197 | } |
198 | 198 | |
199 | -add_action( 'admin_init', 'wpinv_reset_invoice_count' ); |
|
200 | -function wpinv_reset_invoice_count(){ |
|
201 | - if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
199 | +add_action('admin_init', 'wpinv_reset_invoice_count'); |
|
200 | +function wpinv_reset_invoice_count() { |
|
201 | + if (isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
202 | 202 | wpinv_update_option('invoice_sequence_start', 1); |
203 | 203 | delete_option('wpinv_last_invoice_number'); |
204 | 204 | $url = add_query_arg(array('reset_invoice_done' => 1)); |
@@ -209,8 +209,8 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | add_action('admin_notices', 'wpinv_invoice_count_reset_message'); |
212 | -function wpinv_invoice_count_reset_message(){ |
|
213 | - if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) { |
|
212 | +function wpinv_invoice_count_reset_message() { |
|
213 | + if (isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) { |
|
214 | 214 | $notice = __('Invoice number sequence reset successfully.', 'invoicing'); |
215 | 215 | ?> |
216 | 216 | <div class="notice notice-success is-dismissible"> |