@@ -7,11 +7,11 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | - <label :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Enter your text', 'invoicing' ) ?></label> |
|
15 | + <label :for="active_form_element.id + '_edit'"><?php esc_html_e('Enter your text', 'invoicing') ?></label> |
|
16 | 16 | <textarea :id="active_form_element.id + '_edit'" v-model='active_form_element.text' class='form-control' rows='3'></textarea> |
17 | 17 | </div> |
@@ -7,10 +7,10 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | <div class='form-group'> |
14 | - <label :for="active_form_element.id + '_edit'"><?php esc_html_e( 'The IP Address text', 'invoicing' ) ?></label> |
|
14 | + <label :for="active_form_element.id + '_edit'"><?php esc_html_e('The IP Address text', 'invoicing') ?></label> |
|
15 | 15 | <textarea :id="active_form_element.id + '_edit'" v-model='active_form_element.text' class='form-control' rows='3'></textarea> |
16 | 16 | </div> |
@@ -7,35 +7,35 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | 15 | <label class="d-block"> |
16 | - <span><?php esc_html_e( 'Button Text', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Button Text', 'invoicing'); ?></span> |
|
17 | 17 | <input v-model='active_form_element.label' class='form-control' type="text"/> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group'> |
22 | 22 | <label class="d-block"> |
23 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
24 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
23 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
24 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
25 | 25 | </label> |
26 | 26 | </div> |
27 | 27 | |
28 | 28 | <div class='form-group'> |
29 | - <label :for="active_form_element.id + '_edit_type'"><?php esc_html_e( 'Button Type', 'invoicing' ) ?></label> |
|
29 | + <label :for="active_form_element.id + '_edit_type'"><?php esc_html_e('Button Type', 'invoicing') ?></label> |
|
30 | 30 | <select class='form-control custom-select' :id="active_form_element.id + '_edit_type'" v-model='active_form_element.class'> |
31 | - <option value='btn-primary'><?php esc_html_e( 'Primary', 'invoicing' ); ?></option> |
|
32 | - <option value='btn-secondary'><?php esc_html_e( 'Secondary', 'invoicing' ); ?></option> |
|
33 | - <option value='btn-success'><?php esc_html_e( 'Success', 'invoicing' ); ?></option> |
|
34 | - <option value='btn-danger'><?php esc_html_e( 'Danger', 'invoicing' ); ?></option> |
|
35 | - <option value='btn-warning'><?php esc_html_e( 'Warning', 'invoicing' ); ?></option> |
|
36 | - <option value='btn-info'><?php esc_html_e( 'Info', 'invoicing' ); ?></option> |
|
37 | - <option value='btn-light'><?php esc_html_e( 'Light', 'invoicing' ); ?></option> |
|
38 | - <option value='btn-dark'><?php esc_html_e( 'Dark', 'invoicing' ); ?></option> |
|
39 | - <option value='btn-link'><?php esc_html_e( 'Link', 'invoicing' ); ?></option> |
|
31 | + <option value='btn-primary'><?php esc_html_e('Primary', 'invoicing'); ?></option> |
|
32 | + <option value='btn-secondary'><?php esc_html_e('Secondary', 'invoicing'); ?></option> |
|
33 | + <option value='btn-success'><?php esc_html_e('Success', 'invoicing'); ?></option> |
|
34 | + <option value='btn-danger'><?php esc_html_e('Danger', 'invoicing'); ?></option> |
|
35 | + <option value='btn-warning'><?php esc_html_e('Warning', 'invoicing'); ?></option> |
|
36 | + <option value='btn-info'><?php esc_html_e('Info', 'invoicing'); ?></option> |
|
37 | + <option value='btn-light'><?php esc_html_e('Light', 'invoicing'); ?></option> |
|
38 | + <option value='btn-dark'><?php esc_html_e('Dark', 'invoicing'); ?></option> |
|
39 | + <option value='btn-link'><?php esc_html_e('Link', 'invoicing'); ?></option> |
|
40 | 40 | </select> |
41 | 41 | </div> |
@@ -7,11 +7,11 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | - <label :for="active_form_element.id + '_edit'"><?php esc_html_e( 'The gateway select text', 'invoicing' ) ?></label> |
|
15 | + <label :for="active_form_element.id + '_edit'"><?php esc_html_e('The gateway select text', 'invoicing') ?></label> |
|
16 | 16 | <textarea :id="active_form_element.id + '_edit'" v-model='active_form_element.text' class='form-control' rows='3'></textarea> |
17 | 17 | </div> |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,55 +10,55 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'payment_form'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'payment_form'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'payment_form'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Form Data array. This is the core form data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'status' => 'draft', |
|
34 | - 'version' => '', |
|
35 | - 'date_created' => null, |
|
27 | + * Form Data array. This is the core form data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'status' => 'draft', |
|
34 | + 'version' => '', |
|
35 | + 'date_created' => null, |
|
36 | 36 | 'date_modified' => null, |
37 | 37 | 'name' => '', |
38 | 38 | 'author' => 1, |
39 | 39 | 'elements' => null, |
40 | - 'items' => null, |
|
41 | - 'earned' => 0, |
|
42 | - 'refunded' => 0, |
|
43 | - 'cancelled' => 0, |
|
44 | - 'failed' => 0, |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Stores meta in cache for future reads. |
|
49 | - * |
|
50 | - * A group must be set to to enable caching. |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $cache_group = 'getpaid_forms'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | - * |
|
59 | - * @var WPInv_Invoice |
|
60 | - */ |
|
61 | - public $invoice = 0; |
|
40 | + 'items' => null, |
|
41 | + 'earned' => 0, |
|
42 | + 'refunded' => 0, |
|
43 | + 'cancelled' => 0, |
|
44 | + 'failed' => 0, |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Stores meta in cache for future reads. |
|
49 | + * |
|
50 | + * A group must be set to to enable caching. |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $cache_group = 'getpaid_forms'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Stores a reference to the invoice if the form is for an invoice.. |
|
58 | + * |
|
59 | + * @var WPInv_Invoice |
|
60 | + */ |
|
61 | + public $invoice = 0; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Stores a reference to the original WP_Post object |
@@ -68,35 +68,35 @@ discard block |
||
68 | 68 | protected $post = null; |
69 | 69 | |
70 | 70 | /** |
71 | - * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | - * |
|
73 | - * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | - */ |
|
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
71 | + * Get the form if ID is passed, otherwise the form is new and empty. |
|
72 | + * |
|
73 | + * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
|
74 | + */ |
|
75 | + public function __construct( $form = 0 ) { |
|
76 | + parent::__construct( $form ); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | + $this->set_id( $form ); |
|
80 | + } elseif ( $form instanceof self ) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
83 | - $this->invoice = $form->invoice; |
|
82 | + $this->set_id( $form->get_id() ); |
|
83 | + $this->invoice = $form->invoice; |
|
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
87 | - } else { |
|
88 | - $this->set_object_read( true ); |
|
89 | - } |
|
85 | + } elseif ( ! empty( $form->ID ) ) { |
|
86 | + $this->set_id( $form->ID ); |
|
87 | + } else { |
|
88 | + $this->set_object_read( true ); |
|
89 | + } |
|
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
94 | + if ( $this->get_id() > 0 ) { |
|
95 | 95 | $this->post = get_post( $this->get_id() ); |
96 | - $this->data_store->read( $this ); |
|
96 | + $this->data_store->read( $this ); |
|
97 | 97 | } |
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /* |
102 | 102 | |-------------------------------------------------------------------------- |
@@ -114,349 +114,349 @@ discard block |
||
114 | 114 | */ |
115 | 115 | |
116 | 116 | /** |
117 | - * Get plugin version when the form was created. |
|
118 | - * |
|
119 | - * @since 1.0.19 |
|
120 | - * @param string $context View or edit context. |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
117 | + * Get plugin version when the form was created. |
|
118 | + * |
|
119 | + * @since 1.0.19 |
|
120 | + * @param string $context View or edit context. |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function get_version( $context = 'view' ) { |
|
124 | + return $this->get_prop( 'version', $context ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get date when the form was created. |
|
129 | - * |
|
130 | - * @since 1.0.19 |
|
131 | - * @param string $context View or edit context. |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
128 | + * Get date when the form was created. |
|
129 | + * |
|
130 | + * @since 1.0.19 |
|
131 | + * @param string $context View or edit context. |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function get_date_created( $context = 'view' ) { |
|
135 | + return $this->get_prop( 'date_created', $context ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Get GMT date when the form was created. |
|
140 | - * |
|
141 | - * @since 1.0.19 |
|
142 | - * @param string $context View or edit context. |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
139 | + * Get GMT date when the form was created. |
|
140 | + * |
|
141 | + * @since 1.0.19 |
|
142 | + * @param string $context View or edit context. |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function get_date_created_gmt( $context = 'view' ) { |
|
146 | 146 | $date = $this->get_date_created( $context ); |
147 | 147 | |
148 | 148 | if ( $date ) { |
149 | 149 | $date = get_gmt_from_date( $date ); |
150 | 150 | } |
151 | - return $date; |
|
151 | + return $date; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
155 | - * Get date when the form was last modified. |
|
156 | - * |
|
157 | - * @since 1.0.19 |
|
158 | - * @param string $context View or edit context. |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
155 | + * Get date when the form was last modified. |
|
156 | + * |
|
157 | + * @since 1.0.19 |
|
158 | + * @param string $context View or edit context. |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_date_modified( $context = 'view' ) { |
|
162 | + return $this->get_prop( 'date_modified', $context ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * Get GMT date when the form was last modified. |
|
167 | - * |
|
168 | - * @since 1.0.19 |
|
169 | - * @param string $context View or edit context. |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
166 | + * Get GMT date when the form was last modified. |
|
167 | + * |
|
168 | + * @since 1.0.19 |
|
169 | + * @param string $context View or edit context. |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | 173 | $date = $this->get_date_modified( $context ); |
174 | 174 | |
175 | 175 | if ( $date ) { |
176 | 176 | $date = get_gmt_from_date( $date ); |
177 | 177 | } |
178 | - return $date; |
|
178 | + return $date; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * Get the form name. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
182 | + * Get the form name. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function get_name( $context = 'view' ) { |
|
189 | + return $this->get_prop( 'name', $context ); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
193 | - * Alias of self::get_name(). |
|
194 | - * |
|
195 | - * @since 1.0.19 |
|
196 | - * @param string $context View or edit context. |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
201 | - } |
|
193 | + * Alias of self::get_name(). |
|
194 | + * |
|
195 | + * @since 1.0.19 |
|
196 | + * @param string $context View or edit context. |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function get_title( $context = 'view' ) { |
|
200 | + return $this->get_name( $context ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | /** |
204 | - * Get the owner of the form. |
|
205 | - * |
|
206 | - * @since 1.0.19 |
|
207 | - * @param string $context View or edit context. |
|
208 | - * @return int |
|
209 | - */ |
|
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
204 | + * Get the owner of the form. |
|
205 | + * |
|
206 | + * @since 1.0.19 |
|
207 | + * @param string $context View or edit context. |
|
208 | + * @return int |
|
209 | + */ |
|
210 | + public function get_author( $context = 'view' ) { |
|
211 | + return (int) $this->get_prop( 'author', $context ); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * Get the elements that make up the form. |
|
216 | - * |
|
217 | - * @since 1.0.19 |
|
218 | - * @param string $context View or edit context. |
|
219 | - * @return array |
|
220 | - */ |
|
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
215 | + * Get the elements that make up the form. |
|
216 | + * |
|
217 | + * @since 1.0.19 |
|
218 | + * @param string $context View or edit context. |
|
219 | + * @return array |
|
220 | + */ |
|
221 | + public function get_elements( $context = 'view' ) { |
|
222 | + $elements = $this->get_prop( 'elements', $context ); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
224 | + if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | 225 | return wpinv_get_data( 'sample-payment-form' ); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - // Ensure that all required elements exist. |
|
229 | - $_elements = array(); |
|
230 | - foreach ( $elements as $element ) { |
|
228 | + // Ensure that all required elements exist. |
|
229 | + $_elements = array(); |
|
230 | + foreach ( $elements as $element ) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
233 | 233 | |
234 | - $_elements[] = array( |
|
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | - 'id' => 'gtscicd', |
|
237 | - 'name' => 'gtscicd', |
|
238 | - 'type' => 'gateway_select', |
|
239 | - 'premade' => true |
|
234 | + $_elements[] = array( |
|
235 | + 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
236 | + 'id' => 'gtscicd', |
|
237 | + 'name' => 'gtscicd', |
|
238 | + 'type' => 'gateway_select', |
|
239 | + 'premade' => true |
|
240 | 240 | |
241 | - ); |
|
241 | + ); |
|
242 | 242 | |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | - $_elements[] = $element; |
|
245 | + $_elements[] = $element; |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | return $_elements; |
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the items sold via the form. |
|
254 | - * |
|
255 | - * @since 1.0.19 |
|
256 | - * @param string $context View or edit context. |
|
257 | - * @param string $return objects or arrays. |
|
258 | - * @return GetPaid_Form_Item[] |
|
259 | - */ |
|
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
262 | - |
|
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the items sold via the form. |
|
254 | + * |
|
255 | + * @since 1.0.19 |
|
256 | + * @param string $context View or edit context. |
|
257 | + * @param string $return objects or arrays. |
|
258 | + * @return GetPaid_Form_Item[] |
|
259 | + */ |
|
260 | + public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | + $items = $this->get_prop( 'items', $context ); |
|
262 | + |
|
263 | + if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | 264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
265 | - } |
|
265 | + } |
|
266 | + |
|
267 | + // Convert the items. |
|
268 | + $prepared = array(); |
|
266 | 269 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
270 | + foreach ( $items as $key => $value ) { |
|
269 | 271 | |
270 | - foreach ( $items as $key => $value ) { |
|
272 | + // Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
271 | 274 | |
272 | - // Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
274 | 278 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
279 | + continue; |
|
278 | 280 | |
279 | - continue; |
|
281 | + } |
|
280 | 282 | |
281 | - } |
|
283 | + // $item_id => $quantity |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
282 | 286 | |
283 | - // $item_id => $quantity |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
287 | + if ( $item->can_purchase() ) { |
|
288 | + $item->set_quantity( $value ); |
|
289 | + $prepared[] = $item; |
|
290 | + } |
|
286 | 291 | |
287 | - if ( $item->can_purchase() ) { |
|
288 | - $item->set_quantity( $value ); |
|
289 | - $prepared[] = $item; |
|
290 | - } |
|
292 | + continue; |
|
293 | + } |
|
291 | 294 | |
292 | - continue; |
|
293 | - } |
|
295 | + // $item_id => array( 'price' => 10 ) |
|
296 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
297 | + $item = new GetPaid_Form_Item( $key ); |
|
294 | 298 | |
295 | - // $item_id => array( 'price' => 10 ) |
|
296 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
297 | - $item = new GetPaid_Form_Item( $key ); |
|
299 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
300 | + $item->set_price( $value['price'] ); |
|
301 | + } |
|
298 | 302 | |
299 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
300 | - $item->set_price( $value['price'] ); |
|
301 | - } |
|
303 | + if ( $item->can_purchase() ) { |
|
304 | + $prepared[] = $item; |
|
305 | + } |
|
302 | 306 | |
303 | - if ( $item->can_purchase() ) { |
|
304 | - $prepared[] = $item; |
|
305 | - } |
|
307 | + continue; |
|
308 | + } |
|
306 | 309 | |
307 | - continue; |
|
308 | - } |
|
310 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
309 | 311 | |
310 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
312 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
311 | 313 | |
312 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
314 | + if ( ! $item->can_purchase() ) { |
|
315 | + continue; |
|
316 | + } |
|
313 | 317 | |
314 | - if ( ! $item->can_purchase() ) { |
|
315 | - continue; |
|
316 | - } |
|
318 | + // Sub-total (Cart items). |
|
319 | + if ( isset( $value['subtotal'] ) ) { |
|
320 | + $item->set_price( $value['subtotal'] ); |
|
321 | + } |
|
317 | 322 | |
318 | - // Sub-total (Cart items). |
|
319 | - if ( isset( $value['subtotal'] ) ) { |
|
320 | - $item->set_price( $value['subtotal'] ); |
|
321 | - } |
|
323 | + if ( isset( $value['quantity'] ) ) { |
|
324 | + $item->set_quantity( $value['quantity'] ); |
|
325 | + } |
|
326 | + |
|
327 | + if ( isset( $value['allow_quantities'] ) ) { |
|
328 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
329 | + } |
|
330 | + |
|
331 | + if ( isset( $value['required'] ) ) { |
|
332 | + $item->set_is_required( $value['required'] ); |
|
333 | + } |
|
334 | + |
|
335 | + if ( isset( $value['description'] ) ) { |
|
336 | + $item->set_custom_description( $value['description'] ); |
|
337 | + } |
|
338 | + |
|
339 | + $prepared[] = $item; |
|
340 | + continue; |
|
341 | + |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + if ( 'objects' == $return && 'view' == $context ) { |
|
346 | + return $prepared; |
|
347 | + } |
|
348 | + |
|
349 | + $items = array(); |
|
350 | + foreach ( $prepared as $item ) { |
|
351 | + $items[] = $item->prepare_data_for_use(); |
|
352 | + } |
|
353 | + |
|
354 | + return $items; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Get a single item belonging to the form. |
|
359 | + * |
|
360 | + * @since 1.0.19 |
|
361 | + * @param int $item_id The item id to return. |
|
362 | + * @return GetPaid_Form_Item|bool |
|
363 | + */ |
|
364 | + public function get_item( $item_id ) { |
|
365 | + |
|
366 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
367 | + return false; |
|
368 | + } |
|
369 | + |
|
370 | + foreach( $this->get_items() as $item ) { |
|
371 | + if ( $item->get_id() == (int) $item_id ) { |
|
372 | + return $item; |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + return false; |
|
377 | + |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Gets a single element. |
|
382 | + * |
|
383 | + * @since 1.0.19 |
|
384 | + * @param string $element_type The element type to return. |
|
385 | + * @return array|bool |
|
386 | + */ |
|
387 | + public function get_element_type( $element_type ) { |
|
388 | + |
|
389 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
390 | + return false; |
|
391 | + } |
|
392 | + |
|
393 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
394 | + |
|
395 | + if ( $element['type'] == $element_type ) { |
|
396 | + return $element; |
|
397 | + } |
|
398 | + |
|
399 | + } |
|
400 | + |
|
401 | + return false; |
|
402 | + |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Get the total amount earned via this form. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @param string $context View or edit context. |
|
410 | + * @return array |
|
411 | + */ |
|
412 | + public function get_earned( $context = 'view' ) { |
|
413 | + return $this->get_prop( 'earned', $context ); |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Get the total amount refunded via this form. |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + * @param string $context View or edit context. |
|
421 | + * @return array |
|
422 | + */ |
|
423 | + public function get_refunded( $context = 'view' ) { |
|
424 | + return $this->get_prop( 'refunded', $context ); |
|
425 | + } |
|
322 | 426 | |
323 | - if ( isset( $value['quantity'] ) ) { |
|
324 | - $item->set_quantity( $value['quantity'] ); |
|
325 | - } |
|
427 | + /** |
|
428 | + * Get the total amount cancelled via this form. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $context View or edit context. |
|
432 | + * @return array |
|
433 | + */ |
|
434 | + public function get_cancelled( $context = 'view' ) { |
|
435 | + return $this->get_prop( 'cancelled', $context ); |
|
436 | + } |
|
326 | 437 | |
327 | - if ( isset( $value['allow_quantities'] ) ) { |
|
328 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
329 | - } |
|
438 | + /** |
|
439 | + * Get the total amount failed via this form. |
|
440 | + * |
|
441 | + * @since 1.0.19 |
|
442 | + * @param string $context View or edit context. |
|
443 | + * @return array |
|
444 | + */ |
|
445 | + public function get_failed( $context = 'view' ) { |
|
446 | + return $this->get_prop( 'failed', $context ); |
|
447 | + } |
|
330 | 448 | |
331 | - if ( isset( $value['required'] ) ) { |
|
332 | - $item->set_is_required( $value['required'] ); |
|
333 | - } |
|
334 | - |
|
335 | - if ( isset( $value['description'] ) ) { |
|
336 | - $item->set_custom_description( $value['description'] ); |
|
337 | - } |
|
338 | - |
|
339 | - $prepared[] = $item; |
|
340 | - continue; |
|
341 | - |
|
342 | - } |
|
343 | - } |
|
344 | - |
|
345 | - if ( 'objects' == $return && 'view' == $context ) { |
|
346 | - return $prepared; |
|
347 | - } |
|
348 | - |
|
349 | - $items = array(); |
|
350 | - foreach ( $prepared as $item ) { |
|
351 | - $items[] = $item->prepare_data_for_use(); |
|
352 | - } |
|
353 | - |
|
354 | - return $items; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Get a single item belonging to the form. |
|
359 | - * |
|
360 | - * @since 1.0.19 |
|
361 | - * @param int $item_id The item id to return. |
|
362 | - * @return GetPaid_Form_Item|bool |
|
363 | - */ |
|
364 | - public function get_item( $item_id ) { |
|
365 | - |
|
366 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
367 | - return false; |
|
368 | - } |
|
369 | - |
|
370 | - foreach( $this->get_items() as $item ) { |
|
371 | - if ( $item->get_id() == (int) $item_id ) { |
|
372 | - return $item; |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - return false; |
|
377 | - |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Gets a single element. |
|
382 | - * |
|
383 | - * @since 1.0.19 |
|
384 | - * @param string $element_type The element type to return. |
|
385 | - * @return array|bool |
|
386 | - */ |
|
387 | - public function get_element_type( $element_type ) { |
|
388 | - |
|
389 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
390 | - return false; |
|
391 | - } |
|
392 | - |
|
393 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
394 | - |
|
395 | - if ( $element['type'] == $element_type ) { |
|
396 | - return $element; |
|
397 | - } |
|
398 | - |
|
399 | - } |
|
400 | - |
|
401 | - return false; |
|
402 | - |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Get the total amount earned via this form. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @param string $context View or edit context. |
|
410 | - * @return array |
|
411 | - */ |
|
412 | - public function get_earned( $context = 'view' ) { |
|
413 | - return $this->get_prop( 'earned', $context ); |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Get the total amount refunded via this form. |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - * @param string $context View or edit context. |
|
421 | - * @return array |
|
422 | - */ |
|
423 | - public function get_refunded( $context = 'view' ) { |
|
424 | - return $this->get_prop( 'refunded', $context ); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Get the total amount cancelled via this form. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $context View or edit context. |
|
432 | - * @return array |
|
433 | - */ |
|
434 | - public function get_cancelled( $context = 'view' ) { |
|
435 | - return $this->get_prop( 'cancelled', $context ); |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * Get the total amount failed via this form. |
|
440 | - * |
|
441 | - * @since 1.0.19 |
|
442 | - * @param string $context View or edit context. |
|
443 | - * @return array |
|
444 | - */ |
|
445 | - public function get_failed( $context = 'view' ) { |
|
446 | - return $this->get_prop( 'failed', $context ); |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * Get the currency. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - public function get_currency() { |
|
457 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
458 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
459 | - } |
|
449 | + /** |
|
450 | + * Get the currency. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + public function get_currency() { |
|
457 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
458 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
459 | + } |
|
460 | 460 | |
461 | 461 | /* |
462 | 462 | |-------------------------------------------------------------------------- |
@@ -469,22 +469,22 @@ discard block |
||
469 | 469 | */ |
470 | 470 | |
471 | 471 | /** |
472 | - * Set plugin version when the item was created. |
|
473 | - * |
|
474 | - * @since 1.0.19 |
|
475 | - */ |
|
476 | - public function set_version( $value ) { |
|
477 | - $this->set_prop( 'version', $value ); |
|
472 | + * Set plugin version when the item was created. |
|
473 | + * |
|
474 | + * @since 1.0.19 |
|
475 | + */ |
|
476 | + public function set_version( $value ) { |
|
477 | + $this->set_prop( 'version', $value ); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
481 | - * Set date when the item was created. |
|
482 | - * |
|
483 | - * @since 1.0.19 |
|
484 | - * @param string $value Value to set. |
|
481 | + * Set date when the item was created. |
|
482 | + * |
|
483 | + * @since 1.0.19 |
|
484 | + * @param string $value Value to set. |
|
485 | 485 | * @return bool Whether or not the date was set. |
486 | - */ |
|
487 | - public function set_date_created( $value ) { |
|
486 | + */ |
|
487 | + public function set_date_created( $value ) { |
|
488 | 488 | $date = strtotime( $value ); |
489 | 489 | |
490 | 490 | if ( $date ) { |
@@ -497,13 +497,13 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
500 | - * Set date when the item was last modified. |
|
501 | - * |
|
502 | - * @since 1.0.19 |
|
503 | - * @param string $value Value to set. |
|
500 | + * Set date when the item was last modified. |
|
501 | + * |
|
502 | + * @since 1.0.19 |
|
503 | + * @param string $value Value to set. |
|
504 | 504 | * @return bool Whether or not the date was set. |
505 | - */ |
|
506 | - public function set_date_modified( $value ) { |
|
505 | + */ |
|
506 | + public function set_date_modified( $value ) { |
|
507 | 507 | $date = strtotime( $value ); |
508 | 508 | |
509 | 509 | if ( $date ) { |
@@ -516,118 +516,118 @@ discard block |
||
516 | 516 | } |
517 | 517 | |
518 | 518 | /** |
519 | - * Set the item name. |
|
520 | - * |
|
521 | - * @since 1.0.19 |
|
522 | - * @param string $value New name. |
|
523 | - */ |
|
524 | - public function set_name( $value ) { |
|
525 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
526 | - } |
|
527 | - |
|
528 | - /** |
|
529 | - * Alias of self::set_name(). |
|
530 | - * |
|
531 | - * @since 1.0.19 |
|
532 | - * @param string $value New name. |
|
533 | - */ |
|
534 | - public function set_title( $value ) { |
|
535 | - $this->set_name( $value ); |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Set the owner of the item. |
|
540 | - * |
|
541 | - * @since 1.0.19 |
|
542 | - * @param int $value New author. |
|
543 | - */ |
|
544 | - public function set_author( $value ) { |
|
545 | - $this->set_prop( 'author', (int) $value ); |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Set the form elements. |
|
550 | - * |
|
551 | - * @since 1.0.19 |
|
552 | - * @param array $value Form elements. |
|
553 | - */ |
|
554 | - public function set_elements( $value ) { |
|
555 | - if ( is_array( $value ) ) { |
|
556 | - $this->set_prop( 'elements', $value ); |
|
557 | - } |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Set the form items. |
|
562 | - * |
|
563 | - * @since 1.0.19 |
|
564 | - * @param array $value Form elements. |
|
565 | - */ |
|
566 | - public function set_items( $value ) { |
|
567 | - if ( is_array( $value ) ) { |
|
568 | - $this->set_prop( 'items', $value ); |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Set the total amount earned via this form. |
|
574 | - * |
|
575 | - * @since 1.0.19 |
|
576 | - * @param float $value Amount earned. |
|
577 | - */ |
|
578 | - public function set_earned( $value ) { |
|
579 | - $value = max( (float) $value, 0 ); |
|
580 | - $this->set_prop( 'earned', $value ); |
|
581 | - } |
|
582 | - |
|
583 | - /** |
|
584 | - * Set the total amount refunded via this form. |
|
585 | - * |
|
586 | - * @since 1.0.19 |
|
587 | - * @param float $value Amount refunded. |
|
588 | - */ |
|
589 | - public function set_refunded( $value ) { |
|
590 | - $value = max( (float) $value, 0 ); |
|
591 | - $this->set_prop( 'refunded', $value ); |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * Set the total amount cancelled via this form. |
|
596 | - * |
|
597 | - * @since 1.0.19 |
|
598 | - * @param float $value Amount cancelled. |
|
599 | - */ |
|
600 | - public function set_cancelled( $value ) { |
|
601 | - $value = max( (float) $value, 0 ); |
|
602 | - $this->set_prop( 'cancelled', $value ); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Set the total amount failed via this form. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param float $value Amount cancelled. |
|
610 | - */ |
|
611 | - public function set_failed( $value ) { |
|
612 | - $value = max( (float) $value, 0 ); |
|
613 | - $this->set_prop( 'failed', $value ); |
|
614 | - } |
|
519 | + * Set the item name. |
|
520 | + * |
|
521 | + * @since 1.0.19 |
|
522 | + * @param string $value New name. |
|
523 | + */ |
|
524 | + public function set_name( $value ) { |
|
525 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
526 | + } |
|
527 | + |
|
528 | + /** |
|
529 | + * Alias of self::set_name(). |
|
530 | + * |
|
531 | + * @since 1.0.19 |
|
532 | + * @param string $value New name. |
|
533 | + */ |
|
534 | + public function set_title( $value ) { |
|
535 | + $this->set_name( $value ); |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Set the owner of the item. |
|
540 | + * |
|
541 | + * @since 1.0.19 |
|
542 | + * @param int $value New author. |
|
543 | + */ |
|
544 | + public function set_author( $value ) { |
|
545 | + $this->set_prop( 'author', (int) $value ); |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Set the form elements. |
|
550 | + * |
|
551 | + * @since 1.0.19 |
|
552 | + * @param array $value Form elements. |
|
553 | + */ |
|
554 | + public function set_elements( $value ) { |
|
555 | + if ( is_array( $value ) ) { |
|
556 | + $this->set_prop( 'elements', $value ); |
|
557 | + } |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Set the form items. |
|
562 | + * |
|
563 | + * @since 1.0.19 |
|
564 | + * @param array $value Form elements. |
|
565 | + */ |
|
566 | + public function set_items( $value ) { |
|
567 | + if ( is_array( $value ) ) { |
|
568 | + $this->set_prop( 'items', $value ); |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Set the total amount earned via this form. |
|
574 | + * |
|
575 | + * @since 1.0.19 |
|
576 | + * @param float $value Amount earned. |
|
577 | + */ |
|
578 | + public function set_earned( $value ) { |
|
579 | + $value = max( (float) $value, 0 ); |
|
580 | + $this->set_prop( 'earned', $value ); |
|
581 | + } |
|
582 | + |
|
583 | + /** |
|
584 | + * Set the total amount refunded via this form. |
|
585 | + * |
|
586 | + * @since 1.0.19 |
|
587 | + * @param float $value Amount refunded. |
|
588 | + */ |
|
589 | + public function set_refunded( $value ) { |
|
590 | + $value = max( (float) $value, 0 ); |
|
591 | + $this->set_prop( 'refunded', $value ); |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Set the total amount cancelled via this form. |
|
596 | + * |
|
597 | + * @since 1.0.19 |
|
598 | + * @param float $value Amount cancelled. |
|
599 | + */ |
|
600 | + public function set_cancelled( $value ) { |
|
601 | + $value = max( (float) $value, 0 ); |
|
602 | + $this->set_prop( 'cancelled', $value ); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Set the total amount failed via this form. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param float $value Amount cancelled. |
|
610 | + */ |
|
611 | + public function set_failed( $value ) { |
|
612 | + $value = max( (float) $value, 0 ); |
|
613 | + $this->set_prop( 'failed', $value ); |
|
614 | + } |
|
615 | 615 | |
616 | 616 | /** |
617 | 617 | * Create an item. For backwards compatibilty. |
618 | 618 | * |
619 | 619 | * @deprecated |
620 | - * @return int item id |
|
620 | + * @return int item id |
|
621 | 621 | */ |
622 | 622 | public function create( $data = array() ) { |
623 | 623 | |
624 | - // Set the properties. |
|
625 | - if ( is_array( $data ) ) { |
|
626 | - $this->set_props( $data ); |
|
627 | - } |
|
624 | + // Set the properties. |
|
625 | + if ( is_array( $data ) ) { |
|
626 | + $this->set_props( $data ); |
|
627 | + } |
|
628 | 628 | |
629 | - // Save the item. |
|
630 | - return $this->save(); |
|
629 | + // Save the item. |
|
630 | + return $this->save(); |
|
631 | 631 | |
632 | 632 | } |
633 | 633 | |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | * Updates an item. For backwards compatibilty. |
636 | 636 | * |
637 | 637 | * @deprecated |
638 | - * @return int item id |
|
638 | + * @return int item id |
|
639 | 639 | */ |
640 | 640 | public function update( $data = array() ) { |
641 | 641 | return $this->create( $data ); |
@@ -651,22 +651,22 @@ discard block |
||
651 | 651 | */ |
652 | 652 | |
653 | 653 | /** |
654 | - * Checks whether this is the default payment form. |
|
655 | - * |
|
656 | - * @since 1.0.19 |
|
657 | - * @return bool |
|
658 | - */ |
|
654 | + * Checks whether this is the default payment form. |
|
655 | + * |
|
656 | + * @since 1.0.19 |
|
657 | + * @return bool |
|
658 | + */ |
|
659 | 659 | public function is_default() { |
660 | 660 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
661 | 661 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
662 | - } |
|
662 | + } |
|
663 | 663 | |
664 | 664 | /** |
665 | - * Checks whether the form is active. |
|
666 | - * |
|
667 | - * @since 1.0.19 |
|
668 | - * @return bool |
|
669 | - */ |
|
665 | + * Checks whether the form is active. |
|
666 | + * |
|
667 | + * @since 1.0.19 |
|
668 | + * @return bool |
|
669 | + */ |
|
670 | 670 | public function is_active() { |
671 | 671 | $is_active = 0 !== (int) $this->get_id(); |
672 | 672 | |
@@ -675,70 +675,70 @@ discard block |
||
675 | 675 | } |
676 | 676 | |
677 | 677 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Checks whether the form has a given item. |
|
682 | - * |
|
683 | - * @since 1.0.19 |
|
684 | - * @return bool |
|
685 | - */ |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Checks whether the form has a given item. |
|
682 | + * |
|
683 | + * @since 1.0.19 |
|
684 | + * @return bool |
|
685 | + */ |
|
686 | 686 | public function has_item( $item_id ) { |
687 | 687 | return false !== $this->get_item( $item_id ); |
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Checks whether the form has a given element. |
|
692 | - * |
|
693 | - * @since 1.0.19 |
|
694 | - * @return bool |
|
695 | - */ |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Checks whether the form has a given element. |
|
692 | + * |
|
693 | + * @since 1.0.19 |
|
694 | + * @return bool |
|
695 | + */ |
|
696 | 696 | public function has_element_type( $element_type ) { |
697 | 697 | return false !== $this->get_element_type( $element_type ); |
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Checks whether this form is recurring or not. |
|
702 | - * |
|
703 | - * @since 1.0.19 |
|
704 | - * @return bool |
|
705 | - */ |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Checks whether this form is recurring or not. |
|
702 | + * |
|
703 | + * @since 1.0.19 |
|
704 | + * @return bool |
|
705 | + */ |
|
706 | 706 | public function is_recurring() { |
707 | 707 | |
708 | - if ( ! empty( $this->invoice ) ) { |
|
709 | - return $this->invoice->is_recurring(); |
|
710 | - } |
|
708 | + if ( ! empty( $this->invoice ) ) { |
|
709 | + return $this->invoice->is_recurring(); |
|
710 | + } |
|
711 | 711 | |
712 | - foreach ( $this->get_items() as $item ) { |
|
712 | + foreach ( $this->get_items() as $item ) { |
|
713 | 713 | |
714 | - if ( $item->is_recurring() ) { |
|
715 | - return true; |
|
716 | - } |
|
714 | + if ( $item->is_recurring() ) { |
|
715 | + return true; |
|
716 | + } |
|
717 | 717 | |
718 | - } |
|
718 | + } |
|
719 | 719 | |
720 | 720 | return false; |
721 | - } |
|
721 | + } |
|
722 | 722 | |
723 | - /** |
|
724 | - * Retrieves the form's html. |
|
725 | - * |
|
726 | - * @since 1.0.19 |
|
727 | - */ |
|
723 | + /** |
|
724 | + * Retrieves the form's html. |
|
725 | + * |
|
726 | + * @since 1.0.19 |
|
727 | + */ |
|
728 | 728 | public function get_html() { |
729 | 729 | |
730 | - // Return the HTML. |
|
731 | - return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) ); |
|
730 | + // Return the HTML. |
|
731 | + return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) ); |
|
732 | 732 | |
733 | - } |
|
733 | + } |
|
734 | 734 | |
735 | - /** |
|
736 | - * Displays the payment form. |
|
737 | - * |
|
738 | - * @since 1.0.19 |
|
739 | - */ |
|
735 | + /** |
|
736 | + * Displays the payment form. |
|
737 | + * |
|
738 | + * @since 1.0.19 |
|
739 | + */ |
|
740 | 740 | public function display() { |
741 | - echo $this->get_html(); |
|
741 | + echo $this->get_html(); |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -72,28 +72,28 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
74 | 74 | */ |
75 | - public function __construct( $form = 0 ) { |
|
76 | - parent::__construct( $form ); |
|
75 | + public function __construct($form = 0) { |
|
76 | + parent::__construct($form); |
|
77 | 77 | |
78 | - if ( is_numeric( $form ) && $form > 0 ) { |
|
79 | - $this->set_id( $form ); |
|
80 | - } elseif ( $form instanceof self ) { |
|
78 | + if (is_numeric($form) && $form > 0) { |
|
79 | + $this->set_id($form); |
|
80 | + } elseif ($form instanceof self) { |
|
81 | 81 | |
82 | - $this->set_id( $form->get_id() ); |
|
82 | + $this->set_id($form->get_id()); |
|
83 | 83 | $this->invoice = $form->invoice; |
84 | 84 | |
85 | - } elseif ( ! empty( $form->ID ) ) { |
|
86 | - $this->set_id( $form->ID ); |
|
85 | + } elseif (!empty($form->ID)) { |
|
86 | + $this->set_id($form->ID); |
|
87 | 87 | } else { |
88 | - $this->set_object_read( true ); |
|
88 | + $this->set_object_read(true); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Load the datastore. |
92 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
92 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
93 | 93 | |
94 | - if ( $this->get_id() > 0 ) { |
|
95 | - $this->post = get_post( $this->get_id() ); |
|
96 | - $this->data_store->read( $this ); |
|
94 | + if ($this->get_id() > 0) { |
|
95 | + $this->post = get_post($this->get_id()); |
|
96 | + $this->data_store->read($this); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | * @param string $context View or edit context. |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - public function get_version( $context = 'view' ) { |
|
124 | - return $this->get_prop( 'version', $context ); |
|
123 | + public function get_version($context = 'view') { |
|
124 | + return $this->get_prop('version', $context); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param string $context View or edit context. |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public function get_date_created( $context = 'view' ) { |
|
135 | - return $this->get_prop( 'date_created', $context ); |
|
134 | + public function get_date_created($context = 'view') { |
|
135 | + return $this->get_prop('date_created', $context); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * @param string $context View or edit context. |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public function get_date_created_gmt( $context = 'view' ) { |
|
146 | - $date = $this->get_date_created( $context ); |
|
145 | + public function get_date_created_gmt($context = 'view') { |
|
146 | + $date = $this->get_date_created($context); |
|
147 | 147 | |
148 | - if ( $date ) { |
|
149 | - $date = get_gmt_from_date( $date ); |
|
148 | + if ($date) { |
|
149 | + $date = get_gmt_from_date($date); |
|
150 | 150 | } |
151 | 151 | return $date; |
152 | 152 | } |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @param string $context View or edit context. |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_date_modified( $context = 'view' ) { |
|
162 | - return $this->get_prop( 'date_modified', $context ); |
|
161 | + public function get_date_modified($context = 'view') { |
|
162 | + return $this->get_prop('date_modified', $context); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $context View or edit context. |
170 | 170 | * @return string |
171 | 171 | */ |
172 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
173 | - $date = $this->get_date_modified( $context ); |
|
172 | + public function get_date_modified_gmt($context = 'view') { |
|
173 | + $date = $this->get_date_modified($context); |
|
174 | 174 | |
175 | - if ( $date ) { |
|
176 | - $date = get_gmt_from_date( $date ); |
|
175 | + if ($date) { |
|
176 | + $date = get_gmt_from_date($date); |
|
177 | 177 | } |
178 | 178 | return $date; |
179 | 179 | } |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | * @param string $context View or edit context. |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function get_name( $context = 'view' ) { |
|
189 | - return $this->get_prop( 'name', $context ); |
|
188 | + public function get_name($context = 'view') { |
|
189 | + return $this->get_prop('name', $context); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @param string $context View or edit context. |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - public function get_title( $context = 'view' ) { |
|
200 | - return $this->get_name( $context ); |
|
199 | + public function get_title($context = 'view') { |
|
200 | + return $this->get_name($context); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
@@ -207,8 +207,8 @@ discard block |
||
207 | 207 | * @param string $context View or edit context. |
208 | 208 | * @return int |
209 | 209 | */ |
210 | - public function get_author( $context = 'view' ) { |
|
211 | - return (int) $this->get_prop( 'author', $context ); |
|
210 | + public function get_author($context = 'view') { |
|
211 | + return (int) $this->get_prop('author', $context); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | * @param string $context View or edit context. |
219 | 219 | * @return array |
220 | 220 | */ |
221 | - public function get_elements( $context = 'view' ) { |
|
222 | - $elements = $this->get_prop( 'elements', $context ); |
|
221 | + public function get_elements($context = 'view') { |
|
222 | + $elements = $this->get_prop('elements', $context); |
|
223 | 223 | |
224 | - if ( empty( $elements ) || ! is_array( $elements ) ) { |
|
225 | - return wpinv_get_data( 'sample-payment-form' ); |
|
224 | + if (empty($elements) || !is_array($elements)) { |
|
225 | + return wpinv_get_data('sample-payment-form'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // Ensure that all required elements exist. |
229 | 229 | $_elements = array(); |
230 | - foreach ( $elements as $element ) { |
|
230 | + foreach ($elements as $element) { |
|
231 | 231 | |
232 | - if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
|
232 | + if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) { |
|
233 | 233 | |
234 | 234 | $_elements[] = array( |
235 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
235 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
236 | 236 | 'id' => 'gtscicd', |
237 | 237 | 'name' => 'gtscicd', |
238 | 238 | 'type' => 'gateway_select', |
@@ -257,22 +257,22 @@ discard block |
||
257 | 257 | * @param string $return objects or arrays. |
258 | 258 | * @return GetPaid_Form_Item[] |
259 | 259 | */ |
260 | - public function get_items( $context = 'view', $return = 'objects' ) { |
|
261 | - $items = $this->get_prop( 'items', $context ); |
|
260 | + public function get_items($context = 'view', $return = 'objects') { |
|
261 | + $items = $this->get_prop('items', $context); |
|
262 | 262 | |
263 | - if ( empty( $items ) || ! is_array( $items ) ) { |
|
264 | - $items = wpinv_get_data( 'sample-payment-form-items' ); |
|
263 | + if (empty($items) || !is_array($items)) { |
|
264 | + $items = wpinv_get_data('sample-payment-form-items'); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Convert the items. |
268 | 268 | $prepared = array(); |
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ($items as $key => $value) { |
|
271 | 271 | |
272 | 272 | // Form items. |
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
273 | + if ($value instanceof GetPaid_Form_Item) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
275 | + if ($value->can_purchase()) { |
|
276 | 276 | $prepared[] = $value; |
277 | 277 | } |
278 | 278 | |
@@ -281,11 +281,11 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity |
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
284 | + if (is_numeric($key) && is_numeric($value)) { |
|
285 | + $item = new GetPaid_Form_Item($key); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
288 | - $item->set_quantity( $value ); |
|
287 | + if ($item->can_purchase()) { |
|
288 | + $item->set_quantity($value); |
|
289 | 289 | $prepared[] = $item; |
290 | 290 | } |
291 | 291 | |
@@ -293,47 +293,47 @@ discard block |
||
293 | 293 | } |
294 | 294 | |
295 | 295 | // $item_id => array( 'price' => 10 ) |
296 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
297 | - $item = new GetPaid_Form_Item( $key ); |
|
296 | + if (is_numeric($key) && is_array($value)) { |
|
297 | + $item = new GetPaid_Form_Item($key); |
|
298 | 298 | |
299 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
300 | - $item->set_price( $value['price'] ); |
|
299 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
300 | + $item->set_price($value['price']); |
|
301 | 301 | } |
302 | 302 | |
303 | - if ( $item->can_purchase() ) { |
|
303 | + if ($item->can_purchase()) { |
|
304 | 304 | $prepared[] = $item; |
305 | 305 | } |
306 | 306 | |
307 | 307 | continue; |
308 | 308 | } |
309 | 309 | |
310 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
310 | + if (is_array($value) && isset($value['id'])) { |
|
311 | 311 | |
312 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
312 | + $item = new GetPaid_Form_Item($value['id']); |
|
313 | 313 | |
314 | - if ( ! $item->can_purchase() ) { |
|
314 | + if (!$item->can_purchase()) { |
|
315 | 315 | continue; |
316 | 316 | } |
317 | 317 | |
318 | 318 | // Sub-total (Cart items). |
319 | - if ( isset( $value['subtotal'] ) ) { |
|
320 | - $item->set_price( $value['subtotal'] ); |
|
319 | + if (isset($value['subtotal'])) { |
|
320 | + $item->set_price($value['subtotal']); |
|
321 | 321 | } |
322 | 322 | |
323 | - if ( isset( $value['quantity'] ) ) { |
|
324 | - $item->set_quantity( $value['quantity'] ); |
|
323 | + if (isset($value['quantity'])) { |
|
324 | + $item->set_quantity($value['quantity']); |
|
325 | 325 | } |
326 | 326 | |
327 | - if ( isset( $value['allow_quantities'] ) ) { |
|
328 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
327 | + if (isset($value['allow_quantities'])) { |
|
328 | + $item->set_allow_quantities($value['allow_quantities']); |
|
329 | 329 | } |
330 | 330 | |
331 | - if ( isset( $value['required'] ) ) { |
|
332 | - $item->set_is_required( $value['required'] ); |
|
331 | + if (isset($value['required'])) { |
|
332 | + $item->set_is_required($value['required']); |
|
333 | 333 | } |
334 | 334 | |
335 | - if ( isset( $value['description'] ) ) { |
|
336 | - $item->set_custom_description( $value['description'] ); |
|
335 | + if (isset($value['description'])) { |
|
336 | + $item->set_custom_description($value['description']); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | $prepared[] = $item; |
@@ -342,12 +342,12 @@ discard block |
||
342 | 342 | } |
343 | 343 | } |
344 | 344 | |
345 | - if ( 'objects' == $return && 'view' == $context ) { |
|
345 | + if ('objects' == $return && 'view' == $context) { |
|
346 | 346 | return $prepared; |
347 | 347 | } |
348 | 348 | |
349 | 349 | $items = array(); |
350 | - foreach ( $prepared as $item ) { |
|
350 | + foreach ($prepared as $item) { |
|
351 | 351 | $items[] = $item->prepare_data_for_use(); |
352 | 352 | } |
353 | 353 | |
@@ -361,14 +361,14 @@ discard block |
||
361 | 361 | * @param int $item_id The item id to return. |
362 | 362 | * @return GetPaid_Form_Item|bool |
363 | 363 | */ |
364 | - public function get_item( $item_id ) { |
|
364 | + public function get_item($item_id) { |
|
365 | 365 | |
366 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
366 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
367 | 367 | return false; |
368 | 368 | } |
369 | 369 | |
370 | - foreach( $this->get_items() as $item ) { |
|
371 | - if ( $item->get_id() == (int) $item_id ) { |
|
370 | + foreach ($this->get_items() as $item) { |
|
371 | + if ($item->get_id() == (int) $item_id) { |
|
372 | 372 | return $item; |
373 | 373 | } |
374 | 374 | } |
@@ -384,15 +384,15 @@ discard block |
||
384 | 384 | * @param string $element_type The element type to return. |
385 | 385 | * @return array|bool |
386 | 386 | */ |
387 | - public function get_element_type( $element_type ) { |
|
387 | + public function get_element_type($element_type) { |
|
388 | 388 | |
389 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
389 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
390 | 390 | return false; |
391 | 391 | } |
392 | 392 | |
393 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
393 | + foreach ($this->get_prop('elements') as $element) { |
|
394 | 394 | |
395 | - if ( $element['type'] == $element_type ) { |
|
395 | + if ($element['type'] == $element_type) { |
|
396 | 396 | return $element; |
397 | 397 | } |
398 | 398 | |
@@ -409,8 +409,8 @@ discard block |
||
409 | 409 | * @param string $context View or edit context. |
410 | 410 | * @return array |
411 | 411 | */ |
412 | - public function get_earned( $context = 'view' ) { |
|
413 | - return $this->get_prop( 'earned', $context ); |
|
412 | + public function get_earned($context = 'view') { |
|
413 | + return $this->get_prop('earned', $context); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | * @param string $context View or edit context. |
421 | 421 | * @return array |
422 | 422 | */ |
423 | - public function get_refunded( $context = 'view' ) { |
|
424 | - return $this->get_prop( 'refunded', $context ); |
|
423 | + public function get_refunded($context = 'view') { |
|
424 | + return $this->get_prop('refunded', $context); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -431,8 +431,8 @@ discard block |
||
431 | 431 | * @param string $context View or edit context. |
432 | 432 | * @return array |
433 | 433 | */ |
434 | - public function get_cancelled( $context = 'view' ) { |
|
435 | - return $this->get_prop( 'cancelled', $context ); |
|
434 | + public function get_cancelled($context = 'view') { |
|
435 | + return $this->get_prop('cancelled', $context); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | * @param string $context View or edit context. |
443 | 443 | * @return array |
444 | 444 | */ |
445 | - public function get_failed( $context = 'view' ) { |
|
446 | - return $this->get_prop( 'failed', $context ); |
|
445 | + public function get_failed($context = 'view') { |
|
446 | + return $this->get_prop('failed', $context); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | * @return string |
455 | 455 | */ |
456 | 456 | public function get_currency() { |
457 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
458 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
457 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
458 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /* |
@@ -473,8 +473,8 @@ discard block |
||
473 | 473 | * |
474 | 474 | * @since 1.0.19 |
475 | 475 | */ |
476 | - public function set_version( $value ) { |
|
477 | - $this->set_prop( 'version', $value ); |
|
476 | + public function set_version($value) { |
|
477 | + $this->set_prop('version', $value); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
@@ -484,11 +484,11 @@ discard block |
||
484 | 484 | * @param string $value Value to set. |
485 | 485 | * @return bool Whether or not the date was set. |
486 | 486 | */ |
487 | - public function set_date_created( $value ) { |
|
488 | - $date = strtotime( $value ); |
|
487 | + public function set_date_created($value) { |
|
488 | + $date = strtotime($value); |
|
489 | 489 | |
490 | - if ( $date ) { |
|
491 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
490 | + if ($date) { |
|
491 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
492 | 492 | return true; |
493 | 493 | } |
494 | 494 | |
@@ -503,11 +503,11 @@ discard block |
||
503 | 503 | * @param string $value Value to set. |
504 | 504 | * @return bool Whether or not the date was set. |
505 | 505 | */ |
506 | - public function set_date_modified( $value ) { |
|
507 | - $date = strtotime( $value ); |
|
506 | + public function set_date_modified($value) { |
|
507 | + $date = strtotime($value); |
|
508 | 508 | |
509 | - if ( $date ) { |
|
510 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
509 | + if ($date) { |
|
510 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
511 | 511 | return true; |
512 | 512 | } |
513 | 513 | |
@@ -521,8 +521,8 @@ discard block |
||
521 | 521 | * @since 1.0.19 |
522 | 522 | * @param string $value New name. |
523 | 523 | */ |
524 | - public function set_name( $value ) { |
|
525 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
524 | + public function set_name($value) { |
|
525 | + $this->set_prop('name', sanitize_text_field($value)); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | /** |
@@ -531,8 +531,8 @@ discard block |
||
531 | 531 | * @since 1.0.19 |
532 | 532 | * @param string $value New name. |
533 | 533 | */ |
534 | - public function set_title( $value ) { |
|
535 | - $this->set_name( $value ); |
|
534 | + public function set_title($value) { |
|
535 | + $this->set_name($value); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -541,8 +541,8 @@ discard block |
||
541 | 541 | * @since 1.0.19 |
542 | 542 | * @param int $value New author. |
543 | 543 | */ |
544 | - public function set_author( $value ) { |
|
545 | - $this->set_prop( 'author', (int) $value ); |
|
544 | + public function set_author($value) { |
|
545 | + $this->set_prop('author', (int) $value); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -551,9 +551,9 @@ discard block |
||
551 | 551 | * @since 1.0.19 |
552 | 552 | * @param array $value Form elements. |
553 | 553 | */ |
554 | - public function set_elements( $value ) { |
|
555 | - if ( is_array( $value ) ) { |
|
556 | - $this->set_prop( 'elements', $value ); |
|
554 | + public function set_elements($value) { |
|
555 | + if (is_array($value)) { |
|
556 | + $this->set_prop('elements', $value); |
|
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
@@ -563,9 +563,9 @@ discard block |
||
563 | 563 | * @since 1.0.19 |
564 | 564 | * @param array $value Form elements. |
565 | 565 | */ |
566 | - public function set_items( $value ) { |
|
567 | - if ( is_array( $value ) ) { |
|
568 | - $this->set_prop( 'items', $value ); |
|
566 | + public function set_items($value) { |
|
567 | + if (is_array($value)) { |
|
568 | + $this->set_prop('items', $value); |
|
569 | 569 | } |
570 | 570 | } |
571 | 571 | |
@@ -575,9 +575,9 @@ discard block |
||
575 | 575 | * @since 1.0.19 |
576 | 576 | * @param float $value Amount earned. |
577 | 577 | */ |
578 | - public function set_earned( $value ) { |
|
579 | - $value = max( (float) $value, 0 ); |
|
580 | - $this->set_prop( 'earned', $value ); |
|
578 | + public function set_earned($value) { |
|
579 | + $value = max((float) $value, 0); |
|
580 | + $this->set_prop('earned', $value); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -586,9 +586,9 @@ discard block |
||
586 | 586 | * @since 1.0.19 |
587 | 587 | * @param float $value Amount refunded. |
588 | 588 | */ |
589 | - public function set_refunded( $value ) { |
|
590 | - $value = max( (float) $value, 0 ); |
|
591 | - $this->set_prop( 'refunded', $value ); |
|
589 | + public function set_refunded($value) { |
|
590 | + $value = max((float) $value, 0); |
|
591 | + $this->set_prop('refunded', $value); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -597,9 +597,9 @@ discard block |
||
597 | 597 | * @since 1.0.19 |
598 | 598 | * @param float $value Amount cancelled. |
599 | 599 | */ |
600 | - public function set_cancelled( $value ) { |
|
601 | - $value = max( (float) $value, 0 ); |
|
602 | - $this->set_prop( 'cancelled', $value ); |
|
600 | + public function set_cancelled($value) { |
|
601 | + $value = max((float) $value, 0); |
|
602 | + $this->set_prop('cancelled', $value); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
@@ -608,9 +608,9 @@ discard block |
||
608 | 608 | * @since 1.0.19 |
609 | 609 | * @param float $value Amount cancelled. |
610 | 610 | */ |
611 | - public function set_failed( $value ) { |
|
612 | - $value = max( (float) $value, 0 ); |
|
613 | - $this->set_prop( 'failed', $value ); |
|
611 | + public function set_failed($value) { |
|
612 | + $value = max((float) $value, 0); |
|
613 | + $this->set_prop('failed', $value); |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | /** |
@@ -619,11 +619,11 @@ discard block |
||
619 | 619 | * @deprecated |
620 | 620 | * @return int item id |
621 | 621 | */ |
622 | - public function create( $data = array() ) { |
|
622 | + public function create($data = array()) { |
|
623 | 623 | |
624 | 624 | // Set the properties. |
625 | - if ( is_array( $data ) ) { |
|
626 | - $this->set_props( $data ); |
|
625 | + if (is_array($data)) { |
|
626 | + $this->set_props($data); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | // Save the item. |
@@ -637,8 +637,8 @@ discard block |
||
637 | 637 | * @deprecated |
638 | 638 | * @return int item id |
639 | 639 | */ |
640 | - public function update( $data = array() ) { |
|
641 | - return $this->create( $data ); |
|
640 | + public function update($data = array()) { |
|
641 | + return $this->create($data); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | /* |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | */ |
659 | 659 | public function is_default() { |
660 | 660 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
661 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
661 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | /** |
@@ -670,11 +670,11 @@ discard block |
||
670 | 670 | public function is_active() { |
671 | 671 | $is_active = 0 !== (int) $this->get_id(); |
672 | 672 | |
673 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
673 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
674 | 674 | $is_active = false; |
675 | 675 | } |
676 | 676 | |
677 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
677 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | /** |
@@ -683,8 +683,8 @@ discard block |
||
683 | 683 | * @since 1.0.19 |
684 | 684 | * @return bool |
685 | 685 | */ |
686 | - public function has_item( $item_id ) { |
|
687 | - return false !== $this->get_item( $item_id ); |
|
686 | + public function has_item($item_id) { |
|
687 | + return false !== $this->get_item($item_id); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | /** |
@@ -693,8 +693,8 @@ discard block |
||
693 | 693 | * @since 1.0.19 |
694 | 694 | * @return bool |
695 | 695 | */ |
696 | - public function has_element_type( $element_type ) { |
|
697 | - return false !== $this->get_element_type( $element_type ); |
|
696 | + public function has_element_type($element_type) { |
|
697 | + return false !== $this->get_element_type($element_type); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /** |
@@ -705,13 +705,13 @@ discard block |
||
705 | 705 | */ |
706 | 706 | public function is_recurring() { |
707 | 707 | |
708 | - if ( ! empty( $this->invoice ) ) { |
|
708 | + if (!empty($this->invoice)) { |
|
709 | 709 | return $this->invoice->is_recurring(); |
710 | 710 | } |
711 | 711 | |
712 | - foreach ( $this->get_items() as $item ) { |
|
712 | + foreach ($this->get_items() as $item) { |
|
713 | 713 | |
714 | - if ( $item->is_recurring() ) { |
|
714 | + if ($item->is_recurring()) { |
|
715 | 715 | return true; |
716 | 716 | } |
717 | 717 | |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | public function get_html() { |
729 | 729 | |
730 | 730 | // Return the HTML. |
731 | - return wpinv_get_template_html( 'payment-forms/form.php', array( 'form' => $this ) ); |
|
731 | + return wpinv_get_template_html('payment-forms/form.php', array('form' => $this)); |
|
732 | 732 | |
733 | 733 | } |
734 | 734 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -13,11 +13,11 @@ discard block |
||
13 | 13 | |
14 | 14 | public function __construct() { |
15 | 15 | |
16 | - foreach( $this->get_elements() as $element ) { |
|
16 | + foreach ($this->get_elements() as $element) { |
|
17 | 17 | $element = $element['type']; |
18 | 18 | |
19 | - if ( method_exists( $this, "render_{$element}_template" ) ) { |
|
20 | - add_action( 'wpinv_payment_form_render_element_template', array( $this, "render_{$element}_template" ), 10, 2 ); |
|
19 | + if (method_exists($this, "render_{$element}_template")) { |
|
20 | + add_action('wpinv_payment_form_render_element_template', array($this, "render_{$element}_template"), 10, 2); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | } |
@@ -29,20 +29,20 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function get_elements() { |
31 | 31 | |
32 | - if ( ! empty( $this->elements ) ) { |
|
32 | + if (!empty($this->elements)) { |
|
33 | 33 | return $this->elements; |
34 | 34 | } |
35 | 35 | |
36 | - $this->elements = wpinv_get_data( 'payment-form-elements' ); |
|
36 | + $this->elements = wpinv_get_data('payment-form-elements'); |
|
37 | 37 | |
38 | - $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements ); |
|
38 | + $this->elements = apply_filters('wpinv_filter_core_payment_form_elements', $this->elements); |
|
39 | 39 | return $this->elements; |
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Returns the restrict markup. |
44 | 44 | */ |
45 | - public function get_restrict_markup( $field, $field_type ) { |
|
45 | + public function get_restrict_markup($field, $field_type) { |
|
46 | 46 | $restrict = "$field.type=='$field_type'"; |
47 | 47 | return "v-if=\"$restrict\""; |
48 | 48 | } |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * Renders the gateway select element template. |
52 | 52 | */ |
53 | - public function render_gateway_select_template( $field ) { |
|
54 | - $restrict = $this->get_restrict_markup( $field, 'gateway_select' ); |
|
55 | - $text = __( 'The gateway select box will appear here', 'invoicing' ); |
|
53 | + public function render_gateway_select_template($field) { |
|
54 | + $restrict = $this->get_restrict_markup($field, 'gateway_select'); |
|
55 | + $text = __('The gateway select box will appear here', 'invoicing'); |
|
56 | 56 | echo " |
57 | 57 | <div $restrict class='alert alert-info' role='alert'> |
58 | 58 | <span>$text</span> |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * Renders the ip address element template. |
65 | 65 | */ |
66 | - public function render_ip_address_template( $field ) { |
|
67 | - $restrict = $this->get_restrict_markup( $field, 'ip_address' ); |
|
68 | - $ip_address = sanitize_text_field( wpinv_get_ip() ); |
|
69 | - $url = esc_url( getpaid_ip_location_url( $ip_address ) ); |
|
66 | + public function render_ip_address_template($field) { |
|
67 | + $restrict = $this->get_restrict_markup($field, 'ip_address'); |
|
68 | + $ip_address = sanitize_text_field(wpinv_get_ip()); |
|
69 | + $url = esc_url(getpaid_ip_location_url($ip_address)); |
|
70 | 70 | |
71 | 71 | echo " |
72 | 72 | <div $restrict class='getpaid-ip-info'> |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | /** |
80 | 80 | * Renders the total payable element template. |
81 | 81 | */ |
82 | - public function render_total_payable_template( $field ) { |
|
83 | - $restrict = $this->get_restrict_markup( $field, 'total_payable' ); |
|
84 | - $text = __( 'The total payable amount will appear here', 'invoicing' ); |
|
82 | + public function render_total_payable_template($field) { |
|
83 | + $restrict = $this->get_restrict_markup($field, 'total_payable'); |
|
84 | + $text = __('The total payable amount will appear here', 'invoicing'); |
|
85 | 85 | echo " |
86 | 86 | <div $restrict class='alert alert-info' role='alert'> |
87 | 87 | <span>$text</span> |
@@ -92,16 +92,16 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * Renders the title element template. |
94 | 94 | */ |
95 | - public function render_heading_template( $field ) { |
|
96 | - $restrict = $this->get_restrict_markup( $field, 'heading' ); |
|
95 | + public function render_heading_template($field) { |
|
96 | + $restrict = $this->get_restrict_markup($field, 'heading'); |
|
97 | 97 | echo "<component :is='$field.level' $restrict v-html='$field.text'></component>"; |
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * Renders a paragraph element template. |
102 | 102 | */ |
103 | - public function render_paragraph_template( $field ) { |
|
104 | - $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
|
103 | + public function render_paragraph_template($field) { |
|
104 | + $restrict = $this->get_restrict_markup($field, 'paragraph'); |
|
105 | 105 | $label = "$field.text"; |
106 | 106 | echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>"; |
107 | 107 | } |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * Renders the text element template. |
111 | 111 | */ |
112 | - public function render_text_template( $field ) { |
|
113 | - $restrict = $this->get_restrict_markup( $field, 'text' ); |
|
112 | + public function render_text_template($field) { |
|
113 | + $restrict = $this->get_restrict_markup($field, 'text'); |
|
114 | 114 | $label = "$field.label"; |
115 | 115 | echo " |
116 | 116 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | /** |
126 | 126 | * Renders the price select element template. |
127 | 127 | */ |
128 | - public function render_price_select_template( $field ) { |
|
129 | - $restrict = $this->get_restrict_markup( $field, 'price_select' ); |
|
128 | + public function render_price_select_template($field) { |
|
129 | + $restrict = $this->get_restrict_markup($field, 'price_select'); |
|
130 | 130 | ?> |
131 | 131 | <div <?php echo $restrict; ?> class='wpinv-payment-form-field-preview'> |
132 | 132 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
@@ -134,24 +134,24 @@ discard block |
||
134 | 134 | <label>{{<?php echo $field; ?>.label}}</label> |
135 | 135 | |
136 | 136 | <!-- Buttons --> |
137 | - <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="buttons"' class="getpaid-price-buttons"> |
|
138 | - <span v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index"> |
|
139 | - <input type="radio" :id="<?php echo esc_attr( $field ); ?>.id + index" :checked="index==0" /> |
|
140 | - <label :for="<?php echo esc_attr( $field ); ?>.id + index" class="rounded">{{option | optionize}}</label> |
|
137 | + <div v-if='<?php echo esc_attr($field); ?>.select_type=="buttons"' class="getpaid-price-buttons"> |
|
138 | + <span v-for="(option, index) in <?php echo esc_attr($field); ?>.options.split(',')" :key="index"> |
|
139 | + <input type="radio" :id="<?php echo esc_attr($field); ?>.id + index" :checked="index==0" /> |
|
140 | + <label :for="<?php echo esc_attr($field); ?>.id + index" class="rounded">{{option | optionize}}</label> |
|
141 | 141 | </span> |
142 | 142 | </div> |
143 | 143 | |
144 | 144 | <!-- Circles --> |
145 | - <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="circles"' class="getpaid-price-buttons getpaid-price-circles"> |
|
146 | - <span v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index"> |
|
147 | - <input type="radio" :id="<?php echo esc_attr( $field ); ?>.id + index" :checked="index==0" /> |
|
148 | - <label :for="<?php echo esc_attr( $field ); ?>.id + index"><span>{{option | optionize}}</span></label> |
|
145 | + <div v-if='<?php echo esc_attr($field); ?>.select_type=="circles"' class="getpaid-price-buttons getpaid-price-circles"> |
|
146 | + <span v-for="(option, index) in <?php echo esc_attr($field); ?>.options.split(',')" :key="index"> |
|
147 | + <input type="radio" :id="<?php echo esc_attr($field); ?>.id + index" :checked="index==0" /> |
|
148 | + <label :for="<?php echo esc_attr($field); ?>.id + index"><span>{{option | optionize}}</span></label> |
|
149 | 149 | </span> |
150 | 150 | </div> |
151 | 151 | |
152 | 152 | <!-- Radios --> |
153 | - <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="radios"'> |
|
154 | - <div v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index"> |
|
153 | + <div v-if='<?php echo esc_attr($field); ?>.select_type=="radios"'> |
|
154 | + <div v-for="(option, index) in <?php echo esc_attr($field); ?>.options.split(',')" :key="index"> |
|
155 | 155 | <label> |
156 | 156 | <input type="radio" :checked="index==0" /> |
157 | 157 | <span>{{option | optionize}}</span> |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | </div> |
161 | 161 | |
162 | 162 | <!-- Checkboxes --> |
163 | - <div v-if='<?php echo esc_attr( $field ); ?>.select_type=="checkboxes"'> |
|
164 | - <div v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index"> |
|
163 | + <div v-if='<?php echo esc_attr($field); ?>.select_type=="checkboxes"'> |
|
164 | + <div v-for="(option, index) in <?php echo esc_attr($field); ?>.options.split(',')" :key="index"> |
|
165 | 165 | <label> |
166 | 166 | <input type="checkbox" :checked="index==0" /> |
167 | 167 | <span>{{option | optionize}}</span> |
@@ -170,15 +170,15 @@ discard block |
||
170 | 170 | </div> |
171 | 171 | |
172 | 172 | <!-- Select --> |
173 | - <select v-if='<?php echo esc_attr( $field ); ?>.select_type=="select"' class='form-control custom-select'> |
|
174 | - <option v-if="<?php echo esc_attr( $field ); ?>.placeholder" selected="selected"> |
|
175 | - {{<?php echo esc_attr( $field ); ?>.placeholder}} |
|
173 | + <select v-if='<?php echo esc_attr($field); ?>.select_type=="select"' class='form-control custom-select'> |
|
174 | + <option v-if="<?php echo esc_attr($field); ?>.placeholder" selected="selected"> |
|
175 | + {{<?php echo esc_attr($field); ?>.placeholder}} |
|
176 | 176 | </option> |
177 | - <option v-for="(option, index) in <?php echo esc_attr( $field ); ?>.options.split(',')" :key="index"> |
|
177 | + <option v-for="(option, index) in <?php echo esc_attr($field); ?>.options.split(',')" :key="index"> |
|
178 | 178 | {{option | optionize}} |
179 | 179 | </option> |
180 | 180 | </select> |
181 | - <small v-if='<?php echo esc_attr( $field ); ?>.description' class='form-text text-muted' v-html='<?php echo esc_attr( $field ); ?>.description'></small> |
|
181 | + <small v-if='<?php echo esc_attr($field); ?>.description' class='form-text text-muted' v-html='<?php echo esc_attr($field); ?>.description'></small> |
|
182 | 182 | </div> |
183 | 183 | |
184 | 184 | <?php |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | /** |
188 | 188 | * Renders the textarea element template. |
189 | 189 | */ |
190 | - public function render_textarea_template( $field ) { |
|
191 | - $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
|
190 | + public function render_textarea_template($field) { |
|
191 | + $restrict = $this->get_restrict_markup($field, 'textarea'); |
|
192 | 192 | $label = "$field.label"; |
193 | 193 | echo " |
194 | 194 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | /** |
204 | 204 | * Renders the select element template. |
205 | 205 | */ |
206 | - public function render_select_template( $field ) { |
|
207 | - $restrict = $this->get_restrict_markup( $field, 'select' ); |
|
206 | + public function render_select_template($field) { |
|
207 | + $restrict = $this->get_restrict_markup($field, 'select'); |
|
208 | 208 | $label = "$field.label"; |
209 | 209 | $placeholder = "$field.placeholder"; |
210 | 210 | $id = $field . '.id'; |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | /** |
225 | 225 | * Renders the checkbox element template. |
226 | 226 | */ |
227 | - public function render_checkbox_template( $field ) { |
|
228 | - $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
|
227 | + public function render_checkbox_template($field) { |
|
228 | + $restrict = $this->get_restrict_markup($field, 'checkbox'); |
|
229 | 229 | echo " |
230 | 230 | <div class='form-check' $restrict> |
231 | 231 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
@@ -239,8 +239,8 @@ discard block |
||
239 | 239 | /** |
240 | 240 | * Renders the radio element template. |
241 | 241 | */ |
242 | - public function render_radio_template( $field ) { |
|
243 | - $restrict = $this->get_restrict_markup( $field, 'radio' ); |
|
242 | + public function render_radio_template($field) { |
|
243 | + $restrict = $this->get_restrict_markup($field, 'radio'); |
|
244 | 244 | $label = "$field.label"; |
245 | 245 | $id = $field . '.id'; |
246 | 246 | echo " |
@@ -259,8 +259,8 @@ discard block |
||
259 | 259 | /** |
260 | 260 | * Renders the address element template. |
261 | 261 | */ |
262 | - public function render_address_template( $field ) { |
|
263 | - $restrict = $this->get_restrict_markup( $field, 'address' ); |
|
262 | + public function render_address_template($field) { |
|
263 | + $restrict = $this->get_restrict_markup($field, 'address'); |
|
264 | 264 | |
265 | 265 | echo " |
266 | 266 | <div class='wpinv-address-wrapper' $restrict> |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | /** |
283 | 283 | * Renders the email element template. |
284 | 284 | */ |
285 | - public function render_email_template( $field ) { |
|
286 | - $restrict = $this->get_restrict_markup( $field, 'email' ); |
|
285 | + public function render_email_template($field) { |
|
286 | + $restrict = $this->get_restrict_markup($field, 'email'); |
|
287 | 287 | $label = "$field.label"; |
288 | 288 | echo " |
289 | 289 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | /** |
299 | 299 | * Renders the billing_email element template. |
300 | 300 | */ |
301 | - public function render_billing_email_template( $field ) { |
|
302 | - $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
|
301 | + public function render_billing_email_template($field) { |
|
302 | + $restrict = $this->get_restrict_markup($field, 'billing_email'); |
|
303 | 303 | $label = "$field.label"; |
304 | 304 | echo " |
305 | 305 | <div $restrict> |
@@ -313,8 +313,8 @@ discard block |
||
313 | 313 | /** |
314 | 314 | * Renders the website element template. |
315 | 315 | */ |
316 | - public function render_website_template( $field ) { |
|
317 | - $restrict = $this->get_restrict_markup( $field, 'website' ); |
|
316 | + public function render_website_template($field) { |
|
317 | + $restrict = $this->get_restrict_markup($field, 'website'); |
|
318 | 318 | $label = "$field.label"; |
319 | 319 | echo " |
320 | 320 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | /** |
330 | 330 | * Renders the date element template. |
331 | 331 | */ |
332 | - public function render_date_template( $field ) { |
|
333 | - $restrict = $this->get_restrict_markup( $field, 'date' ); |
|
332 | + public function render_date_template($field) { |
|
333 | + $restrict = $this->get_restrict_markup($field, 'date'); |
|
334 | 334 | $label = "$field.label"; |
335 | 335 | echo " |
336 | 336 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -345,8 +345,8 @@ discard block |
||
345 | 345 | /** |
346 | 346 | * Renders the time element template. |
347 | 347 | */ |
348 | - public function render_time_template( $field ) { |
|
349 | - $restrict = $this->get_restrict_markup( $field, 'time' ); |
|
348 | + public function render_time_template($field) { |
|
349 | + $restrict = $this->get_restrict_markup($field, 'time'); |
|
350 | 350 | $label = "$field.label"; |
351 | 351 | echo " |
352 | 352 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | /** |
362 | 362 | * Renders the number element template. |
363 | 363 | */ |
364 | - public function render_number_template( $field ) { |
|
365 | - $restrict = $this->get_restrict_markup( $field, 'number' ); |
|
364 | + public function render_number_template($field) { |
|
365 | + $restrict = $this->get_restrict_markup($field, 'number'); |
|
366 | 366 | $label = "$field.label"; |
367 | 367 | echo " |
368 | 368 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -377,16 +377,16 @@ discard block |
||
377 | 377 | /** |
378 | 378 | * Renders the separator element template. |
379 | 379 | */ |
380 | - public function render_separator_template( $field ) { |
|
381 | - $restrict = $this->get_restrict_markup( $field, 'separator' ); |
|
380 | + public function render_separator_template($field) { |
|
381 | + $restrict = $this->get_restrict_markup($field, 'separator'); |
|
382 | 382 | echo "<hr class='featurette-divider' $restrict>"; |
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
386 | 386 | * Renders the pay button element template. |
387 | 387 | */ |
388 | - public function render_pay_button_template( $field ) { |
|
389 | - $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
|
388 | + public function render_pay_button_template($field) { |
|
389 | + $restrict = $this->get_restrict_markup($field, 'pay_button'); |
|
390 | 390 | $label = "$field.label"; |
391 | 391 | echo " |
392 | 392 | <div $restrict> |
@@ -399,8 +399,8 @@ discard block |
||
399 | 399 | /** |
400 | 400 | * Renders the alert element template. |
401 | 401 | */ |
402 | - public function render_alert_template( $field ) { |
|
403 | - $restrict = $this->get_restrict_markup( $field, 'alert' ); |
|
402 | + public function render_alert_template($field) { |
|
403 | + $restrict = $this->get_restrict_markup($field, 'alert'); |
|
404 | 404 | $text = "$field.text"; |
405 | 405 | echo " |
406 | 406 | <div $restrict class='alert' :class='$field.class' role='alert'> |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | /** |
416 | 416 | * Renders the discount element template. |
417 | 417 | */ |
418 | - public function render_discount_template( $field ) { |
|
419 | - $restrict = $this->get_restrict_markup( $field, 'discount' ); |
|
418 | + public function render_discount_template($field) { |
|
419 | + $restrict = $this->get_restrict_markup($field, 'discount'); |
|
420 | 420 | ?> |
421 | 421 | |
422 | 422 | <div <?php echo $restrict; ?> class="discount_field border rounded p-3 wpinv-payment-form-field-preview"> |
@@ -434,17 +434,17 @@ discard block |
||
434 | 434 | /** |
435 | 435 | * Renders the items element template. |
436 | 436 | */ |
437 | - public function render_items_template( $field ) { |
|
438 | - $restrict = $this->get_restrict_markup( $field, 'items' ); |
|
437 | + public function render_items_template($field) { |
|
438 | + $restrict = $this->get_restrict_markup($field, 'items'); |
|
439 | 439 | ?> |
440 | 440 | |
441 | 441 | <div <?php echo $restrict; ?> class='item_totals'> |
442 | 442 | <div v-if='!is_default'> |
443 | - <div v-if='! canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='alert alert-info' role='alert'><?php _e( 'Item totals will appear here. Click to set items.', 'invoicing' ) ?></div> |
|
444 | - <div v-if='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='alert alert-danger' role='alert'><?php _e( 'Your form allows customers to buy several recurring items. This is not supported and might lead to unexpected behaviour.', 'invoicing' ); ?></div> |
|
443 | + <div v-if='! canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='alert alert-info' role='alert'><?php _e('Item totals will appear here. Click to set items.', 'invoicing') ?></div> |
|
444 | + <div v-if='canCheckoutSeveralSubscriptions(<?php echo $field; ?>)' class='alert alert-danger' role='alert'><?php _e('Your form allows customers to buy several recurring items. This is not supported and might lead to unexpected behaviour.', 'invoicing'); ?></div> |
|
445 | 445 | </div> |
446 | 446 | <div v-if='is_default'> |
447 | - <div class='alert alert-info' role='alert'><?php _e( 'Item totals will appear here.', 'invoicing' ) ?></div> |
|
447 | + <div class='alert alert-info' role='alert'><?php _e('Item totals will appear here.', 'invoicing') ?></div> |
|
448 | 448 | </div> |
449 | 449 | </div> |
450 | 450 | |
@@ -454,39 +454,39 @@ discard block |
||
454 | 454 | /** |
455 | 455 | * Returns an array of items for the currently being edited form. |
456 | 456 | */ |
457 | - public function get_form_items( $id = false ) { |
|
458 | - $form = new GetPaid_Payment_Form( $id ); |
|
457 | + public function get_form_items($id = false) { |
|
458 | + $form = new GetPaid_Payment_Form($id); |
|
459 | 459 | |
460 | 460 | // Is this a default form? |
461 | - if ( $form->is_default() ) { |
|
461 | + if ($form->is_default()) { |
|
462 | 462 | return array(); |
463 | 463 | } |
464 | 464 | |
465 | - return $form->get_items( 'view', 'arrays' ); |
|
465 | + return $form->get_items('view', 'arrays'); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
469 | 469 | * Converts form items for use. |
470 | 470 | */ |
471 | - public function convert_checkout_items( $items, $invoice ) { |
|
471 | + public function convert_checkout_items($items, $invoice) { |
|
472 | 472 | |
473 | 473 | $converted = array(); |
474 | - foreach ( $items as $item ) { |
|
474 | + foreach ($items as $item) { |
|
475 | 475 | |
476 | 476 | $item_id = $item['id']; |
477 | - $_item = new WPInv_Item( $item_id ); |
|
477 | + $_item = new WPInv_Item($item_id); |
|
478 | 478 | |
479 | - if( ! $_item ) { |
|
479 | + if (!$_item) { |
|
480 | 480 | continue; |
481 | 481 | } |
482 | 482 | |
483 | 483 | $converted[] = array( |
484 | - 'title' => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ), |
|
484 | + 'title' => esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($_item), |
|
485 | 485 | 'id' => $item['id'], |
486 | 486 | 'price' => $item['subtotal'], |
487 | 487 | 'custom_price' => $_item->get_is_dynamic_pricing(), |
488 | 488 | 'recurring' => $_item->is_recurring(), |
489 | - 'description' => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ), |
|
489 | + 'description' => apply_filters('wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice), |
|
490 | 490 | 'minimum_price' => $_item->get_minimum_price(), |
491 | 491 | 'allow_quantities' => false, |
492 | 492 | 'quantity' => $item['quantity'], |
@@ -500,27 +500,27 @@ discard block |
||
500 | 500 | /** |
501 | 501 | * Converts an array of id => quantity for use. |
502 | 502 | */ |
503 | - public function convert_normal_items( $items ) { |
|
503 | + public function convert_normal_items($items) { |
|
504 | 504 | |
505 | 505 | $converted = array(); |
506 | - foreach ( $items as $item_id => $quantity ) { |
|
506 | + foreach ($items as $item_id => $quantity) { |
|
507 | 507 | |
508 | - $item = new WPInv_Item( $item_id ); |
|
508 | + $item = new WPInv_Item($item_id); |
|
509 | 509 | |
510 | - if( ! $item ) { |
|
510 | + if (!$item) { |
|
511 | 511 | continue; |
512 | 512 | } |
513 | 513 | |
514 | 514 | $converted[] = array( |
515 | - 'title' => esc_html( $item->get_name() ) . wpinv_get_item_suffix( $item ), |
|
515 | + 'title' => esc_html($item->get_name()) . wpinv_get_item_suffix($item), |
|
516 | 516 | 'id' => $item_id, |
517 | 517 | 'price' => $item->get_price(), |
518 | 518 | 'custom_price' => $item->get_is_dynamic_pricing(), |
519 | 519 | 'recurring' => $item->is_recurring(), |
520 | 520 | 'description' => $item->get_summary(), |
521 | 521 | 'minimum_price' => $item->get_minimum_price(), |
522 | - 'allow_quantities' => ! empty( $quantity ), |
|
523 | - 'quantity' => empty( $quantity ) ? 1 : $quantity, |
|
522 | + 'allow_quantities' => !empty($quantity), |
|
523 | + 'quantity' => empty($quantity) ? 1 : $quantity, |
|
524 | 524 | 'required' => true, |
525 | 525 | ); |
526 | 526 | |
@@ -533,19 +533,19 @@ discard block |
||
533 | 533 | /** |
534 | 534 | * Returns an array of elements for the currently being edited form. |
535 | 535 | */ |
536 | - public function get_form_elements( $id = false ) { |
|
536 | + public function get_form_elements($id = false) { |
|
537 | 537 | |
538 | - if ( empty( $id ) ) { |
|
539 | - return wpinv_get_data( 'sample-payment-form' ); |
|
538 | + if (empty($id)) { |
|
539 | + return wpinv_get_data('sample-payment-form'); |
|
540 | 540 | } |
541 | 541 | |
542 | - $form_elements = get_post_meta( $id, 'wpinv_form_elements', true ); |
|
542 | + $form_elements = get_post_meta($id, 'wpinv_form_elements', true); |
|
543 | 543 | |
544 | - if ( is_array( $form_elements ) ) { |
|
544 | + if (is_array($form_elements)) { |
|
545 | 545 | return $form_elements; |
546 | 546 | } |
547 | 547 | |
548 | - return wpinv_get_data( 'sample-payment-form' ); |
|
548 | + return wpinv_get_data('sample-payment-form'); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,30 +10,30 @@ discard block |
||
10 | 10 | class WPInv_Item extends GetPaid_Data { |
11 | 11 | |
12 | 12 | /** |
13 | - * Which data store to load. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
13 | + * Which data store to load. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | 17 | protected $data_store_name = 'item'; |
18 | 18 | |
19 | 19 | /** |
20 | - * This is the name of this object type. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $object_type = 'item'; |
|
20 | + * This is the name of this object type. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $object_type = 'item'; |
|
25 | 25 | |
26 | 26 | /** |
27 | - * Item Data array. This is the core item data exposed in APIs. |
|
28 | - * |
|
29 | - * @since 1.0.19 |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $data = array( |
|
33 | - 'parent_id' => 0, |
|
34 | - 'status' => 'draft', |
|
35 | - 'version' => '', |
|
36 | - 'date_created' => null, |
|
27 | + * Item Data array. This is the core item data exposed in APIs. |
|
28 | + * |
|
29 | + * @since 1.0.19 |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $data = array( |
|
33 | + 'parent_id' => 0, |
|
34 | + 'status' => 'draft', |
|
35 | + 'version' => '', |
|
36 | + 'date_created' => null, |
|
37 | 37 | 'date_modified' => null, |
38 | 38 | 'name' => '', |
39 | 39 | 'description' => '', |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | ); |
59 | 59 | |
60 | 60 | /** |
61 | - * Stores meta in cache for future reads. |
|
62 | - * |
|
63 | - * A group must be set to to enable caching. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - protected $cache_group = 'getpaid_items'; |
|
61 | + * Stores meta in cache for future reads. |
|
62 | + * |
|
63 | + * A group must be set to to enable caching. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + protected $cache_group = 'getpaid_items'; |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Stores a reference to the original WP_Post object |
@@ -74,37 +74,37 @@ discard block |
||
74 | 74 | protected $post = null; |
75 | 75 | |
76 | 76 | /** |
77 | - * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | - * |
|
79 | - * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | - */ |
|
81 | - public function __construct( $item = 0 ) { |
|
82 | - parent::__construct( $item ); |
|
83 | - |
|
84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | - $this->set_id( $item_id ); |
|
92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | - $this->set_id( $item_id ); |
|
94 | - } else { |
|
95 | - $this->set_object_read( true ); |
|
96 | - } |
|
77 | + * Get the item if ID is passed, otherwise the item is new and empty. |
|
78 | + * |
|
79 | + * @param int|object|WPInv_Item|WP_Post $item Item to read. |
|
80 | + */ |
|
81 | + public function __construct( $item = 0 ) { |
|
82 | + parent::__construct( $item ); |
|
83 | + |
|
84 | + if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | + $this->set_id( $item ); |
|
86 | + } elseif ( $item instanceof self ) { |
|
87 | + $this->set_id( $item->get_id() ); |
|
88 | + } elseif ( ! empty( $item->ID ) ) { |
|
89 | + $this->set_id( $item->ID ); |
|
90 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | + $this->set_id( $item_id ); |
|
92 | + } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | + $this->set_id( $item_id ); |
|
94 | + } else { |
|
95 | + $this->set_object_read( true ); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | // Load the datastore. |
99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
99 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
100 | 100 | |
101 | - if ( $this->get_id() > 0 ) { |
|
101 | + if ( $this->get_id() > 0 ) { |
|
102 | 102 | $this->post = get_post( $this->get_id() ); |
103 | 103 | $this->ID = $this->get_id(); |
104 | - $this->data_store->read( $this ); |
|
104 | + $this->data_store->read( $this ); |
|
105 | 105 | } |
106 | 106 | |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | 109 | /* |
110 | 110 | |-------------------------------------------------------------------------- |
@@ -122,401 +122,401 @@ discard block |
||
122 | 122 | */ |
123 | 123 | |
124 | 124 | /** |
125 | - * Get parent item ID. |
|
126 | - * |
|
127 | - * @since 1.0.19 |
|
128 | - * @param string $context View or edit context. |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function get_parent_id( $context = 'view' ) { |
|
132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
125 | + * Get parent item ID. |
|
126 | + * |
|
127 | + * @since 1.0.19 |
|
128 | + * @param string $context View or edit context. |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function get_parent_id( $context = 'view' ) { |
|
132 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Get item status. |
|
137 | - * |
|
138 | - * @since 1.0.19 |
|
139 | - * @param string $context View or edit context. |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function get_status( $context = 'view' ) { |
|
143 | - return $this->get_prop( 'status', $context ); |
|
136 | + * Get item status. |
|
137 | + * |
|
138 | + * @since 1.0.19 |
|
139 | + * @param string $context View or edit context. |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function get_status( $context = 'view' ) { |
|
143 | + return $this->get_prop( 'status', $context ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | - * Get plugin version when the item was created. |
|
148 | - * |
|
149 | - * @since 1.0.19 |
|
150 | - * @param string $context View or edit context. |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public function get_version( $context = 'view' ) { |
|
154 | - return $this->get_prop( 'version', $context ); |
|
147 | + * Get plugin version when the item was created. |
|
148 | + * |
|
149 | + * @since 1.0.19 |
|
150 | + * @param string $context View or edit context. |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public function get_version( $context = 'view' ) { |
|
154 | + return $this->get_prop( 'version', $context ); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | - * Get date when the item was created. |
|
159 | - * |
|
160 | - * @since 1.0.19 |
|
161 | - * @param string $context View or edit context. |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - public function get_date_created( $context = 'view' ) { |
|
165 | - return $this->get_prop( 'date_created', $context ); |
|
158 | + * Get date when the item was created. |
|
159 | + * |
|
160 | + * @since 1.0.19 |
|
161 | + * @param string $context View or edit context. |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + public function get_date_created( $context = 'view' ) { |
|
165 | + return $this->get_prop( 'date_created', $context ); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | - * Get GMT date when the item was created. |
|
170 | - * |
|
171 | - * @since 1.0.19 |
|
172 | - * @param string $context View or edit context. |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
169 | + * Get GMT date when the item was created. |
|
170 | + * |
|
171 | + * @since 1.0.19 |
|
172 | + * @param string $context View or edit context. |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function get_date_created_gmt( $context = 'view' ) { |
|
176 | 176 | $date = $this->get_date_created( $context ); |
177 | 177 | |
178 | 178 | if ( $date ) { |
179 | 179 | $date = get_gmt_from_date( $date ); |
180 | 180 | } |
181 | - return $date; |
|
181 | + return $date; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Get date when the item was last modified. |
|
186 | - * |
|
187 | - * @since 1.0.19 |
|
188 | - * @param string $context View or edit context. |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public function get_date_modified( $context = 'view' ) { |
|
192 | - return $this->get_prop( 'date_modified', $context ); |
|
185 | + * Get date when the item was last modified. |
|
186 | + * |
|
187 | + * @since 1.0.19 |
|
188 | + * @param string $context View or edit context. |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public function get_date_modified( $context = 'view' ) { |
|
192 | + return $this->get_prop( 'date_modified', $context ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Get GMT date when the item was last modified. |
|
197 | - * |
|
198 | - * @since 1.0.19 |
|
199 | - * @param string $context View or edit context. |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
196 | + * Get GMT date when the item was last modified. |
|
197 | + * |
|
198 | + * @since 1.0.19 |
|
199 | + * @param string $context View or edit context. |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
203 | 203 | $date = $this->get_date_modified( $context ); |
204 | 204 | |
205 | 205 | if ( $date ) { |
206 | 206 | $date = get_gmt_from_date( $date ); |
207 | 207 | } |
208 | - return $date; |
|
208 | + return $date; |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get the item name. |
|
213 | - * |
|
214 | - * @since 1.0.19 |
|
215 | - * @param string $context View or edit context. |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public function get_name( $context = 'view' ) { |
|
219 | - return $this->get_prop( 'name', $context ); |
|
212 | + * Get the item name. |
|
213 | + * |
|
214 | + * @since 1.0.19 |
|
215 | + * @param string $context View or edit context. |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public function get_name( $context = 'view' ) { |
|
219 | + return $this->get_prop( 'name', $context ); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | - * Alias of self::get_name(). |
|
224 | - * |
|
225 | - * @since 1.0.19 |
|
226 | - * @param string $context View or edit context. |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function get_title( $context = 'view' ) { |
|
230 | - return $this->get_name( $context ); |
|
223 | + * Alias of self::get_name(). |
|
224 | + * |
|
225 | + * @since 1.0.19 |
|
226 | + * @param string $context View or edit context. |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function get_title( $context = 'view' ) { |
|
230 | + return $this->get_name( $context ); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
234 | - * Get the item description. |
|
235 | - * |
|
236 | - * @since 1.0.19 |
|
237 | - * @param string $context View or edit context. |
|
238 | - * @return string |
|
239 | - */ |
|
240 | - public function get_description( $context = 'view' ) { |
|
241 | - return $this->get_prop( 'description', $context ); |
|
234 | + * Get the item description. |
|
235 | + * |
|
236 | + * @since 1.0.19 |
|
237 | + * @param string $context View or edit context. |
|
238 | + * @return string |
|
239 | + */ |
|
240 | + public function get_description( $context = 'view' ) { |
|
241 | + return $this->get_prop( 'description', $context ); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * Alias of self::get_description(). |
|
246 | - * |
|
247 | - * @since 1.0.19 |
|
248 | - * @param string $context View or edit context. |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function get_excerpt( $context = 'view' ) { |
|
252 | - return $this->get_description( $context ); |
|
245 | + * Alias of self::get_description(). |
|
246 | + * |
|
247 | + * @since 1.0.19 |
|
248 | + * @param string $context View or edit context. |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function get_excerpt( $context = 'view' ) { |
|
252 | + return $this->get_description( $context ); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
256 | - * Alias of self::get_description(). |
|
257 | - * |
|
258 | - * @since 1.0.19 |
|
259 | - * @param string $context View or edit context. |
|
260 | - * @return string |
|
261 | - */ |
|
262 | - public function get_summary( $context = 'view' ) { |
|
263 | - return $this->get_description( $context ); |
|
256 | + * Alias of self::get_description(). |
|
257 | + * |
|
258 | + * @since 1.0.19 |
|
259 | + * @param string $context View or edit context. |
|
260 | + * @return string |
|
261 | + */ |
|
262 | + public function get_summary( $context = 'view' ) { |
|
263 | + return $this->get_description( $context ); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | - * Get the owner of the item. |
|
268 | - * |
|
269 | - * @since 1.0.19 |
|
270 | - * @param string $context View or edit context. |
|
271 | - * @return int |
|
272 | - */ |
|
273 | - public function get_author( $context = 'view' ) { |
|
274 | - return (int) $this->get_prop( 'author', $context ); |
|
275 | - } |
|
267 | + * Get the owner of the item. |
|
268 | + * |
|
269 | + * @since 1.0.19 |
|
270 | + * @param string $context View or edit context. |
|
271 | + * @return int |
|
272 | + */ |
|
273 | + public function get_author( $context = 'view' ) { |
|
274 | + return (int) $this->get_prop( 'author', $context ); |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Alias of self::get_author(). |
|
279 | - * |
|
280 | - * @since 1.0.19 |
|
281 | - * @param string $context View or edit context. |
|
282 | - * @return int |
|
283 | - */ |
|
284 | - public function get_owner( $context = 'view' ) { |
|
285 | - return $this->get_author( $context ); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Get the price of the item. |
|
290 | - * |
|
291 | - * @since 1.0.19 |
|
292 | - * @param string $context View or edit context. |
|
293 | - * @return float |
|
294 | - */ |
|
295 | - public function get_price( $context = 'view' ) { |
|
277 | + /** |
|
278 | + * Alias of self::get_author(). |
|
279 | + * |
|
280 | + * @since 1.0.19 |
|
281 | + * @param string $context View or edit context. |
|
282 | + * @return int |
|
283 | + */ |
|
284 | + public function get_owner( $context = 'view' ) { |
|
285 | + return $this->get_author( $context ); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Get the price of the item. |
|
290 | + * |
|
291 | + * @since 1.0.19 |
|
292 | + * @param string $context View or edit context. |
|
293 | + * @return float |
|
294 | + */ |
|
295 | + public function get_price( $context = 'view' ) { |
|
296 | 296 | return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
297 | - } |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * Get the inital price of the item. |
|
301 | - * |
|
302 | - * @since 1.0.19 |
|
303 | - * @param string $context View or edit context. |
|
304 | - * @return float |
|
305 | - */ |
|
306 | - public function get_initial_price( $context = 'view' ) { |
|
299 | + /** |
|
300 | + * Get the inital price of the item. |
|
301 | + * |
|
302 | + * @since 1.0.19 |
|
303 | + * @param string $context View or edit context. |
|
304 | + * @return float |
|
305 | + */ |
|
306 | + public function get_initial_price( $context = 'view' ) { |
|
307 | 307 | |
308 | - $price = (float) $this->get_price( $context ); |
|
308 | + $price = (float) $this->get_price( $context ); |
|
309 | 309 | |
310 | - if ( $this->has_free_trial() ) { |
|
311 | - $price = 0; |
|
312 | - } |
|
310 | + if ( $this->has_free_trial() ) { |
|
311 | + $price = 0; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
318 | - * Returns a formated price. |
|
319 | - * |
|
320 | - * @since 1.0.19 |
|
321 | - * @param string $context View or edit context. |
|
322 | - * @return string |
|
323 | - */ |
|
318 | + * Returns a formated price. |
|
319 | + * |
|
320 | + * @since 1.0.19 |
|
321 | + * @param string $context View or edit context. |
|
322 | + * @return string |
|
323 | + */ |
|
324 | 324 | public function get_the_price() { |
325 | 325 | return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Returns the formated initial price. |
|
330 | - * |
|
331 | - * @since 1.0.19 |
|
332 | - * @param string $context View or edit context. |
|
333 | - * @return string |
|
334 | - */ |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Returns the formated initial price. |
|
330 | + * |
|
331 | + * @since 1.0.19 |
|
332 | + * @param string $context View or edit context. |
|
333 | + * @return string |
|
334 | + */ |
|
335 | 335 | public function get_the_initial_price() { |
336 | 336 | return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
340 | - * Get the VAT rule of the item. |
|
341 | - * |
|
342 | - * @since 1.0.19 |
|
343 | - * @param string $context View or edit context. |
|
344 | - * @return string |
|
345 | - */ |
|
346 | - public function get_vat_rule( $context = 'view' ) { |
|
340 | + * Get the VAT rule of the item. |
|
341 | + * |
|
342 | + * @since 1.0.19 |
|
343 | + * @param string $context View or edit context. |
|
344 | + * @return string |
|
345 | + */ |
|
346 | + public function get_vat_rule( $context = 'view' ) { |
|
347 | 347 | return $this->get_prop( 'vat_rule', $context ); |
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
351 | - * Get the VAT class of the item. |
|
352 | - * |
|
353 | - * @since 1.0.19 |
|
354 | - * @param string $context View or edit context. |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function get_vat_class( $context = 'view' ) { |
|
351 | + * Get the VAT class of the item. |
|
352 | + * |
|
353 | + * @since 1.0.19 |
|
354 | + * @param string $context View or edit context. |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function get_vat_class( $context = 'view' ) { |
|
358 | 358 | return $this->get_prop( 'vat_class', $context ); |
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
362 | - * Get the type of the item. |
|
363 | - * |
|
364 | - * @since 1.0.19 |
|
365 | - * @param string $context View or edit context. |
|
366 | - * @return string |
|
367 | - */ |
|
368 | - public function get_type( $context = 'view' ) { |
|
362 | + * Get the type of the item. |
|
363 | + * |
|
364 | + * @since 1.0.19 |
|
365 | + * @param string $context View or edit context. |
|
366 | + * @return string |
|
367 | + */ |
|
368 | + public function get_type( $context = 'view' ) { |
|
369 | 369 | return $this->get_prop( 'type', $context ); |
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
373 | - * Get the custom id of the item. |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * @param string $context View or edit context. |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function get_custom_id( $context = 'view' ) { |
|
373 | + * Get the custom id of the item. |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * @param string $context View or edit context. |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function get_custom_id( $context = 'view' ) { |
|
380 | 380 | return $this->get_prop( 'custom_id', $context ); |
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
384 | - * Get the custom name of the item. |
|
385 | - * |
|
386 | - * @since 1.0.19 |
|
387 | - * @param string $context View or edit context. |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - public function get_custom_name( $context = 'view' ) { |
|
384 | + * Get the custom name of the item. |
|
385 | + * |
|
386 | + * @since 1.0.19 |
|
387 | + * @param string $context View or edit context. |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + public function get_custom_name( $context = 'view' ) { |
|
391 | 391 | return $this->get_prop( 'custom_name', $context ); |
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
395 | - * Get the custom singular name of the item. |
|
396 | - * |
|
397 | - * @since 1.0.19 |
|
398 | - * @param string $context View or edit context. |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
395 | + * Get the custom singular name of the item. |
|
396 | + * |
|
397 | + * @since 1.0.19 |
|
398 | + * @param string $context View or edit context. |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public function get_custom_singular_name( $context = 'view' ) { |
|
402 | 402 | return $this->get_prop( 'custom_singular_name', $context ); |
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
406 | - * Checks if an item is editable.. |
|
407 | - * |
|
408 | - * @since 1.0.19 |
|
409 | - * @param string $context View or edit context. |
|
410 | - * @return int |
|
411 | - */ |
|
412 | - public function get_is_editable( $context = 'view' ) { |
|
406 | + * Checks if an item is editable.. |
|
407 | + * |
|
408 | + * @since 1.0.19 |
|
409 | + * @param string $context View or edit context. |
|
410 | + * @return int |
|
411 | + */ |
|
412 | + public function get_is_editable( $context = 'view' ) { |
|
413 | 413 | return (int) $this->get_prop( 'is_editable', $context ); |
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
417 | - * Alias of self::get_is_editable(). |
|
418 | - * |
|
419 | - * @since 1.0.19 |
|
420 | - * @param string $context View or edit context. |
|
421 | - * @return int |
|
422 | - */ |
|
423 | - public function get_editable( $context = 'view' ) { |
|
424 | - return $this->get_is_editable( $context ); |
|
417 | + * Alias of self::get_is_editable(). |
|
418 | + * |
|
419 | + * @since 1.0.19 |
|
420 | + * @param string $context View or edit context. |
|
421 | + * @return int |
|
422 | + */ |
|
423 | + public function get_editable( $context = 'view' ) { |
|
424 | + return $this->get_is_editable( $context ); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
428 | - * Checks if dynamic pricing is enabled. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - * @param string $context View or edit context. |
|
432 | - * @return int |
|
433 | - */ |
|
434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
428 | + * Checks if dynamic pricing is enabled. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + * @param string $context View or edit context. |
|
432 | + * @return int |
|
433 | + */ |
|
434 | + public function get_is_dynamic_pricing( $context = 'view' ) { |
|
435 | 435 | return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
439 | - * Returns the minimum price if dynamic pricing is enabled. |
|
440 | - * |
|
441 | - * @since 1.0.19 |
|
442 | - * @param string $context View or edit context. |
|
443 | - * @return float |
|
444 | - */ |
|
445 | - public function get_minimum_price( $context = 'view' ) { |
|
439 | + * Returns the minimum price if dynamic pricing is enabled. |
|
440 | + * |
|
441 | + * @since 1.0.19 |
|
442 | + * @param string $context View or edit context. |
|
443 | + * @return float |
|
444 | + */ |
|
445 | + public function get_minimum_price( $context = 'view' ) { |
|
446 | 446 | return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
450 | - * Checks if this is a recurring item. |
|
451 | - * |
|
452 | - * @since 1.0.19 |
|
453 | - * @param string $context View or edit context. |
|
454 | - * @return int |
|
455 | - */ |
|
456 | - public function get_is_recurring( $context = 'view' ) { |
|
450 | + * Checks if this is a recurring item. |
|
451 | + * |
|
452 | + * @since 1.0.19 |
|
453 | + * @param string $context View or edit context. |
|
454 | + * @return int |
|
455 | + */ |
|
456 | + public function get_is_recurring( $context = 'view' ) { |
|
457 | 457 | return (int) $this->get_prop( 'is_recurring', $context ); |
458 | - } |
|
458 | + } |
|
459 | 459 | |
460 | - /** |
|
461 | - * Get the recurring price of the item. |
|
462 | - * |
|
463 | - * @since 1.0.19 |
|
464 | - * @param string $context View or edit context. |
|
465 | - * @return float |
|
466 | - */ |
|
467 | - public function get_recurring_price( $context = 'view' ) { |
|
468 | - $price = $this->get_price( $context ); |
|
460 | + /** |
|
461 | + * Get the recurring price of the item. |
|
462 | + * |
|
463 | + * @since 1.0.19 |
|
464 | + * @param string $context View or edit context. |
|
465 | + * @return float |
|
466 | + */ |
|
467 | + public function get_recurring_price( $context = 'view' ) { |
|
468 | + $price = $this->get_price( $context ); |
|
469 | 469 | return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Get the formatted recurring price of the item. |
|
474 | - * |
|
475 | - * @since 1.0.19 |
|
476 | - * @param string $context View or edit context. |
|
477 | - * @return string |
|
478 | - */ |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Get the formatted recurring price of the item. |
|
474 | + * |
|
475 | + * @since 1.0.19 |
|
476 | + * @param string $context View or edit context. |
|
477 | + * @return string |
|
478 | + */ |
|
479 | 479 | public function get_the_recurring_price() { |
480 | 480 | return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) ); |
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Get the first renewal date (in timestamps) of the item. |
|
485 | - * |
|
486 | - * @since 1.0.19 |
|
487 | - * @return int |
|
488 | - */ |
|
489 | - public function get_first_renewal_date() { |
|
490 | - |
|
491 | - $periods = array( |
|
492 | - 'D' => 'days', |
|
493 | - 'W' => 'weeks', |
|
494 | - 'M' => 'months', |
|
495 | - 'Y' => 'years', |
|
496 | - ); |
|
497 | - |
|
498 | - $period = $this->get_recurring_period(); |
|
499 | - $interval = $this->get_recurring_interval(); |
|
500 | - |
|
501 | - if ( $this->has_free_trial() ) { |
|
502 | - $period = $this->get_trial_period(); |
|
503 | - $interval = $this->get_trial_interval(); |
|
504 | - } |
|
505 | - |
|
506 | - $period = $periods[ $period ]; |
|
507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Get the first renewal date (in timestamps) of the item. |
|
485 | + * |
|
486 | + * @since 1.0.19 |
|
487 | + * @return int |
|
488 | + */ |
|
489 | + public function get_first_renewal_date() { |
|
490 | + |
|
491 | + $periods = array( |
|
492 | + 'D' => 'days', |
|
493 | + 'W' => 'weeks', |
|
494 | + 'M' => 'months', |
|
495 | + 'Y' => 'years', |
|
496 | + ); |
|
497 | + |
|
498 | + $period = $this->get_recurring_period(); |
|
499 | + $interval = $this->get_recurring_interval(); |
|
500 | + |
|
501 | + if ( $this->has_free_trial() ) { |
|
502 | + $period = $this->get_trial_period(); |
|
503 | + $interval = $this->get_trial_interval(); |
|
504 | + } |
|
505 | + |
|
506 | + $period = $periods[ $period ]; |
|
507 | + $interval = empty( $interval ) ? 1 : $interval; |
|
508 | + $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
509 | 509 | return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
513 | - * Get the recurring period. |
|
514 | - * |
|
515 | - * @since 1.0.19 |
|
516 | - * @param bool $full Return abbreviation or in full. |
|
517 | - * @return string |
|
518 | - */ |
|
519 | - public function get_recurring_period( $full = false ) { |
|
513 | + * Get the recurring period. |
|
514 | + * |
|
515 | + * @since 1.0.19 |
|
516 | + * @param bool $full Return abbreviation or in full. |
|
517 | + * @return string |
|
518 | + */ |
|
519 | + public function get_recurring_period( $full = false ) { |
|
520 | 520 | $period = $this->get_prop( 'recurring_period', 'view' ); |
521 | 521 | |
522 | 522 | if ( $full && ! is_bool( $full ) ) { |
@@ -527,63 +527,63 @@ discard block |
||
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
530 | - * Get the recurring interval. |
|
531 | - * |
|
532 | - * @since 1.0.19 |
|
533 | - * @param string $context View or edit context. |
|
534 | - * @return int |
|
535 | - */ |
|
536 | - public function get_recurring_interval( $context = 'view' ) { |
|
537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
530 | + * Get the recurring interval. |
|
531 | + * |
|
532 | + * @since 1.0.19 |
|
533 | + * @param string $context View or edit context. |
|
534 | + * @return int |
|
535 | + */ |
|
536 | + public function get_recurring_interval( $context = 'view' ) { |
|
537 | + $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
538 | 538 | |
539 | - if ( $interval < 1 ) { |
|
540 | - $interval = 1; |
|
541 | - } |
|
539 | + if ( $interval < 1 ) { |
|
540 | + $interval = 1; |
|
541 | + } |
|
542 | 542 | |
543 | 543 | return $interval; |
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
547 | - * Get the recurring limit. |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param string $context View or edit context. |
|
551 | - * @return int |
|
552 | - */ |
|
553 | - public function get_recurring_limit( $context = 'view' ) { |
|
547 | + * Get the recurring limit. |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param string $context View or edit context. |
|
551 | + * @return int |
|
552 | + */ |
|
553 | + public function get_recurring_limit( $context = 'view' ) { |
|
554 | 554 | return (int) $this->get_prop( 'recurring_limit', $context ); |
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
558 | - * Checks if we have a free trial. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @param string $context View or edit context. |
|
562 | - * @return int |
|
563 | - */ |
|
564 | - public function get_is_free_trial( $context = 'view' ) { |
|
558 | + * Checks if we have a free trial. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @param string $context View or edit context. |
|
562 | + * @return int |
|
563 | + */ |
|
564 | + public function get_is_free_trial( $context = 'view' ) { |
|
565 | 565 | return (int) $this->get_prop( 'is_free_trial', $context ); |
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
569 | - * Alias for self::get_is_free_trial(). |
|
570 | - * |
|
571 | - * @since 1.0.19 |
|
572 | - * @param string $context View or edit context. |
|
573 | - * @return int |
|
574 | - */ |
|
575 | - public function get_free_trial( $context = 'view' ) { |
|
569 | + * Alias for self::get_is_free_trial(). |
|
570 | + * |
|
571 | + * @since 1.0.19 |
|
572 | + * @param string $context View or edit context. |
|
573 | + * @return int |
|
574 | + */ |
|
575 | + public function get_free_trial( $context = 'view' ) { |
|
576 | 576 | return $this->get_is_free_trial( $context ); |
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
580 | - * Get the trial period. |
|
581 | - * |
|
582 | - * @since 1.0.19 |
|
583 | - * @param bool $full Return abbreviation or in full. |
|
584 | - * @return string |
|
585 | - */ |
|
586 | - public function get_trial_period( $full = false ) { |
|
580 | + * Get the trial period. |
|
581 | + * |
|
582 | + * @since 1.0.19 |
|
583 | + * @param bool $full Return abbreviation or in full. |
|
584 | + * @return string |
|
585 | + */ |
|
586 | + public function get_trial_period( $full = false ) { |
|
587 | 587 | $period = $this->get_prop( 'trial_period', 'view' ); |
588 | 588 | |
589 | 589 | if ( $full && ! is_bool( $full ) ) { |
@@ -594,105 +594,105 @@ discard block |
||
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
597 | - * Get the trial interval. |
|
598 | - * |
|
599 | - * @since 1.0.19 |
|
600 | - * @param string $context View or edit context. |
|
601 | - * @return int |
|
602 | - */ |
|
603 | - public function get_trial_interval( $context = 'view' ) { |
|
597 | + * Get the trial interval. |
|
598 | + * |
|
599 | + * @since 1.0.19 |
|
600 | + * @param string $context View or edit context. |
|
601 | + * @return int |
|
602 | + */ |
|
603 | + public function get_trial_interval( $context = 'view' ) { |
|
604 | 604 | return (int) $this->get_prop( 'trial_interval', $context ); |
605 | - } |
|
605 | + } |
|
606 | 606 | |
607 | - /** |
|
608 | - * Get the item's edit url. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @return string |
|
612 | - */ |
|
613 | - public function get_edit_url() { |
|
607 | + /** |
|
608 | + * Get the item's edit url. |
|
609 | + * |
|
610 | + * @since 1.0.19 |
|
611 | + * @return string |
|
612 | + */ |
|
613 | + public function get_edit_url() { |
|
614 | 614 | return get_edit_post_link( $this->get_id() ); |
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Given an item's name/custom id, it returns its id. |
|
619 | - * |
|
620 | - * |
|
621 | - * @static |
|
622 | - * @param string $value The item name or custom id. |
|
623 | - * @param string $field Either name or custom_id. |
|
624 | - * @param string $type in case you need to search for a given type. |
|
625 | - * @since 1.0.15 |
|
626 | - * @return int |
|
627 | - */ |
|
628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | - |
|
630 | - // Trim the value. |
|
631 | - $value = sanitize_text_field( $value ); |
|
632 | - |
|
633 | - if ( empty( $value ) ) { |
|
634 | - return 0; |
|
635 | - } |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * Given an item's name/custom id, it returns its id. |
|
619 | + * |
|
620 | + * |
|
621 | + * @static |
|
622 | + * @param string $value The item name or custom id. |
|
623 | + * @param string $field Either name or custom_id. |
|
624 | + * @param string $type in case you need to search for a given type. |
|
625 | + * @since 1.0.15 |
|
626 | + * @return int |
|
627 | + */ |
|
628 | + public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
629 | + |
|
630 | + // Trim the value. |
|
631 | + $value = sanitize_text_field( $value ); |
|
632 | + |
|
633 | + if ( empty( $value ) ) { |
|
634 | + return 0; |
|
635 | + } |
|
636 | 636 | |
637 | 637 | // Valid fields. |
638 | 638 | $fields = array( 'custom_id', 'name', 'slug' ); |
639 | 639 | |
640 | - // Ensure a field has been passed. |
|
641 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
642 | - return 0; |
|
643 | - } |
|
644 | - |
|
645 | - if ( $field == 'name' ) { |
|
646 | - $field = 'slug'; |
|
647 | - } |
|
648 | - |
|
649 | - // Maybe retrieve from the cache. |
|
650 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
651 | - if ( ! empty( $item_id ) ) { |
|
652 | - return $item_id; |
|
653 | - } |
|
654 | - |
|
655 | - // Fetch from the db. |
|
656 | - $items = array(); |
|
657 | - if ( $field =='slug' ) { |
|
658 | - $items = get_posts( |
|
659 | - array( |
|
660 | - 'post_type' => 'wpi_item', |
|
661 | - 'name' => $value, |
|
662 | - 'posts_per_page' => 1, |
|
663 | - 'post_status' => 'any', |
|
664 | - ) |
|
665 | - ); |
|
666 | - } |
|
667 | - |
|
668 | - if ( $field =='custom_id' ) { |
|
669 | - $items = get_posts( |
|
670 | - array( |
|
671 | - 'post_type' => 'wpi_item', |
|
672 | - 'posts_per_page' => 1, |
|
673 | - 'post_status' => 'any', |
|
674 | - 'meta_query' => array( |
|
675 | - array( |
|
676 | - 'key' => '_wpinv_type', |
|
677 | - 'value' => $type, |
|
678 | - ), |
|
679 | - array( |
|
680 | - 'key' => '_wpinv_custom_id', |
|
681 | - 'value' => $type, |
|
682 | - ) |
|
683 | - ) |
|
684 | - ) |
|
685 | - ); |
|
686 | - } |
|
687 | - |
|
688 | - if ( empty( $items ) ) { |
|
689 | - return 0; |
|
690 | - } |
|
691 | - |
|
692 | - // Update the cache with our data |
|
693 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
694 | - |
|
695 | - return $items[0]->ID; |
|
640 | + // Ensure a field has been passed. |
|
641 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
642 | + return 0; |
|
643 | + } |
|
644 | + |
|
645 | + if ( $field == 'name' ) { |
|
646 | + $field = 'slug'; |
|
647 | + } |
|
648 | + |
|
649 | + // Maybe retrieve from the cache. |
|
650 | + $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
651 | + if ( ! empty( $item_id ) ) { |
|
652 | + return $item_id; |
|
653 | + } |
|
654 | + |
|
655 | + // Fetch from the db. |
|
656 | + $items = array(); |
|
657 | + if ( $field =='slug' ) { |
|
658 | + $items = get_posts( |
|
659 | + array( |
|
660 | + 'post_type' => 'wpi_item', |
|
661 | + 'name' => $value, |
|
662 | + 'posts_per_page' => 1, |
|
663 | + 'post_status' => 'any', |
|
664 | + ) |
|
665 | + ); |
|
666 | + } |
|
667 | + |
|
668 | + if ( $field =='custom_id' ) { |
|
669 | + $items = get_posts( |
|
670 | + array( |
|
671 | + 'post_type' => 'wpi_item', |
|
672 | + 'posts_per_page' => 1, |
|
673 | + 'post_status' => 'any', |
|
674 | + 'meta_query' => array( |
|
675 | + array( |
|
676 | + 'key' => '_wpinv_type', |
|
677 | + 'value' => $type, |
|
678 | + ), |
|
679 | + array( |
|
680 | + 'key' => '_wpinv_custom_id', |
|
681 | + 'value' => $type, |
|
682 | + ) |
|
683 | + ) |
|
684 | + ) |
|
685 | + ); |
|
686 | + } |
|
687 | + |
|
688 | + if ( empty( $items ) ) { |
|
689 | + return 0; |
|
690 | + } |
|
691 | + |
|
692 | + // Update the cache with our data |
|
693 | + wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
694 | + |
|
695 | + return $items[0]->ID; |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | /** |
@@ -725,52 +725,52 @@ discard block |
||
725 | 725 | */ |
726 | 726 | |
727 | 727 | /** |
728 | - * Set parent order ID. |
|
729 | - * |
|
730 | - * @since 1.0.19 |
|
731 | - */ |
|
732 | - public function set_parent_id( $value ) { |
|
733 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
734 | - return; |
|
735 | - } |
|
736 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
737 | - } |
|
738 | - |
|
739 | - /** |
|
740 | - * Sets item status. |
|
741 | - * |
|
742 | - * @since 1.0.19 |
|
743 | - * @param string $status New status. |
|
744 | - * @return array details of change. |
|
745 | - */ |
|
746 | - public function set_status( $status ) { |
|
728 | + * Set parent order ID. |
|
729 | + * |
|
730 | + * @since 1.0.19 |
|
731 | + */ |
|
732 | + public function set_parent_id( $value ) { |
|
733 | + if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
734 | + return; |
|
735 | + } |
|
736 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
737 | + } |
|
738 | + |
|
739 | + /** |
|
740 | + * Sets item status. |
|
741 | + * |
|
742 | + * @since 1.0.19 |
|
743 | + * @param string $status New status. |
|
744 | + * @return array details of change. |
|
745 | + */ |
|
746 | + public function set_status( $status ) { |
|
747 | 747 | $old_status = $this->get_status(); |
748 | 748 | |
749 | 749 | $this->set_prop( 'status', $status ); |
750 | 750 | |
751 | - return array( |
|
752 | - 'from' => $old_status, |
|
753 | - 'to' => $status, |
|
754 | - ); |
|
751 | + return array( |
|
752 | + 'from' => $old_status, |
|
753 | + 'to' => $status, |
|
754 | + ); |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | /** |
758 | - * Set plugin version when the item was created. |
|
759 | - * |
|
760 | - * @since 1.0.19 |
|
761 | - */ |
|
762 | - public function set_version( $value ) { |
|
763 | - $this->set_prop( 'version', $value ); |
|
758 | + * Set plugin version when the item was created. |
|
759 | + * |
|
760 | + * @since 1.0.19 |
|
761 | + */ |
|
762 | + public function set_version( $value ) { |
|
763 | + $this->set_prop( 'version', $value ); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | /** |
767 | - * Set date when the item was created. |
|
768 | - * |
|
769 | - * @since 1.0.19 |
|
770 | - * @param string $value Value to set. |
|
767 | + * Set date when the item was created. |
|
768 | + * |
|
769 | + * @since 1.0.19 |
|
770 | + * @param string $value Value to set. |
|
771 | 771 | * @return bool Whether or not the date was set. |
772 | - */ |
|
773 | - public function set_date_created( $value ) { |
|
772 | + */ |
|
773 | + public function set_date_created( $value ) { |
|
774 | 774 | $date = strtotime( $value ); |
775 | 775 | |
776 | 776 | if ( $date ) { |
@@ -783,13 +783,13 @@ discard block |
||
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
786 | - * Set date when the item was last modified. |
|
787 | - * |
|
788 | - * @since 1.0.19 |
|
789 | - * @param string $value Value to set. |
|
786 | + * Set date when the item was last modified. |
|
787 | + * |
|
788 | + * @since 1.0.19 |
|
789 | + * @param string $value Value to set. |
|
790 | 790 | * @return bool Whether or not the date was set. |
791 | - */ |
|
792 | - public function set_date_modified( $value ) { |
|
791 | + */ |
|
792 | + public function set_date_modified( $value ) { |
|
793 | 793 | $date = strtotime( $value ); |
794 | 794 | |
795 | 795 | if ( $date ) { |
@@ -802,115 +802,115 @@ discard block |
||
802 | 802 | } |
803 | 803 | |
804 | 804 | /** |
805 | - * Set the item name. |
|
806 | - * |
|
807 | - * @since 1.0.19 |
|
808 | - * @param string $value New name. |
|
809 | - */ |
|
810 | - public function set_name( $value ) { |
|
805 | + * Set the item name. |
|
806 | + * |
|
807 | + * @since 1.0.19 |
|
808 | + * @param string $value New name. |
|
809 | + */ |
|
810 | + public function set_name( $value ) { |
|
811 | 811 | $name = sanitize_text_field( $value ); |
812 | - $this->set_prop( 'name', $name ); |
|
812 | + $this->set_prop( 'name', $name ); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
816 | - * Alias of self::set_name(). |
|
817 | - * |
|
818 | - * @since 1.0.19 |
|
819 | - * @param string $value New name. |
|
820 | - */ |
|
821 | - public function set_title( $value ) { |
|
822 | - $this->set_name( $value ); |
|
816 | + * Alias of self::set_name(). |
|
817 | + * |
|
818 | + * @since 1.0.19 |
|
819 | + * @param string $value New name. |
|
820 | + */ |
|
821 | + public function set_title( $value ) { |
|
822 | + $this->set_name( $value ); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | /** |
826 | - * Set the item description. |
|
827 | - * |
|
828 | - * @since 1.0.19 |
|
829 | - * @param string $value New description. |
|
830 | - */ |
|
831 | - public function set_description( $value ) { |
|
826 | + * Set the item description. |
|
827 | + * |
|
828 | + * @since 1.0.19 |
|
829 | + * @param string $value New description. |
|
830 | + */ |
|
831 | + public function set_description( $value ) { |
|
832 | 832 | $description = wp_kses_post( $value ); |
833 | - return $this->set_prop( 'description', $description ); |
|
833 | + return $this->set_prop( 'description', $description ); |
|
834 | 834 | } |
835 | 835 | |
836 | 836 | /** |
837 | - * Alias of self::set_description(). |
|
838 | - * |
|
839 | - * @since 1.0.19 |
|
840 | - * @param string $value New description. |
|
841 | - */ |
|
842 | - public function set_excerpt( $value ) { |
|
843 | - $this->set_description( $value ); |
|
837 | + * Alias of self::set_description(). |
|
838 | + * |
|
839 | + * @since 1.0.19 |
|
840 | + * @param string $value New description. |
|
841 | + */ |
|
842 | + public function set_excerpt( $value ) { |
|
843 | + $this->set_description( $value ); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
847 | - * Alias of self::set_description(). |
|
848 | - * |
|
849 | - * @since 1.0.19 |
|
850 | - * @param string $value New description. |
|
851 | - */ |
|
852 | - public function set_summary( $value ) { |
|
853 | - $this->set_description( $value ); |
|
847 | + * Alias of self::set_description(). |
|
848 | + * |
|
849 | + * @since 1.0.19 |
|
850 | + * @param string $value New description. |
|
851 | + */ |
|
852 | + public function set_summary( $value ) { |
|
853 | + $this->set_description( $value ); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
857 | - * Set the owner of the item. |
|
858 | - * |
|
859 | - * @since 1.0.19 |
|
860 | - * @param int $value New author. |
|
861 | - */ |
|
862 | - public function set_author( $value ) { |
|
863 | - $this->set_prop( 'author', (int) $value ); |
|
864 | - } |
|
857 | + * Set the owner of the item. |
|
858 | + * |
|
859 | + * @since 1.0.19 |
|
860 | + * @param int $value New author. |
|
861 | + */ |
|
862 | + public function set_author( $value ) { |
|
863 | + $this->set_prop( 'author', (int) $value ); |
|
864 | + } |
|
865 | 865 | |
866 | - /** |
|
867 | - * Alias of self::set_author(). |
|
868 | - * |
|
869 | - * @since 1.0.19 |
|
870 | - * @param int $value New author. |
|
871 | - */ |
|
872 | - public function set_owner( $value ) { |
|
873 | - $this->set_author( $value ); |
|
874 | - } |
|
875 | - |
|
876 | - /** |
|
877 | - * Set the price of the item. |
|
878 | - * |
|
879 | - * @since 1.0.19 |
|
880 | - * @param float $value New price. |
|
881 | - */ |
|
882 | - public function set_price( $value ) { |
|
866 | + /** |
|
867 | + * Alias of self::set_author(). |
|
868 | + * |
|
869 | + * @since 1.0.19 |
|
870 | + * @param int $value New author. |
|
871 | + */ |
|
872 | + public function set_owner( $value ) { |
|
873 | + $this->set_author( $value ); |
|
874 | + } |
|
875 | + |
|
876 | + /** |
|
877 | + * Set the price of the item. |
|
878 | + * |
|
879 | + * @since 1.0.19 |
|
880 | + * @param float $value New price. |
|
881 | + */ |
|
882 | + public function set_price( $value ) { |
|
883 | 883 | $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
887 | - * Set the VAT rule of the item. |
|
888 | - * |
|
889 | - * @since 1.0.19 |
|
890 | - * @param string $value new rule. |
|
891 | - */ |
|
892 | - public function set_vat_rule( $value ) { |
|
887 | + * Set the VAT rule of the item. |
|
888 | + * |
|
889 | + * @since 1.0.19 |
|
890 | + * @param string $value new rule. |
|
891 | + */ |
|
892 | + public function set_vat_rule( $value ) { |
|
893 | 893 | $this->set_prop( 'vat_rule', $value ); |
894 | 894 | } |
895 | 895 | |
896 | 896 | /** |
897 | - * Set the VAT class of the item. |
|
898 | - * |
|
899 | - * @since 1.0.19 |
|
900 | - * @param string $value new class. |
|
901 | - */ |
|
902 | - public function set_vat_class( $value ) { |
|
897 | + * Set the VAT class of the item. |
|
898 | + * |
|
899 | + * @since 1.0.19 |
|
900 | + * @param string $value new class. |
|
901 | + */ |
|
902 | + public function set_vat_class( $value ) { |
|
903 | 903 | $this->set_prop( 'vat_class', $value ); |
904 | 904 | } |
905 | 905 | |
906 | 906 | /** |
907 | - * Set the type of the item. |
|
908 | - * |
|
909 | - * @since 1.0.19 |
|
910 | - * @param string $value new item type. |
|
911 | - * @return string |
|
912 | - */ |
|
913 | - public function set_type( $value ) { |
|
907 | + * Set the type of the item. |
|
908 | + * |
|
909 | + * @since 1.0.19 |
|
910 | + * @param string $value new item type. |
|
911 | + * @return string |
|
912 | + */ |
|
913 | + public function set_type( $value ) { |
|
914 | 914 | |
915 | 915 | if ( empty( $value ) ) { |
916 | 916 | $value = 'custom'; |
@@ -920,134 +920,134 @@ discard block |
||
920 | 920 | } |
921 | 921 | |
922 | 922 | /** |
923 | - * Set the custom id of the item. |
|
924 | - * |
|
925 | - * @since 1.0.19 |
|
926 | - * @param string $value new custom id. |
|
927 | - */ |
|
928 | - public function set_custom_id( $value ) { |
|
923 | + * Set the custom id of the item. |
|
924 | + * |
|
925 | + * @since 1.0.19 |
|
926 | + * @param string $value new custom id. |
|
927 | + */ |
|
928 | + public function set_custom_id( $value ) { |
|
929 | 929 | $this->set_prop( 'custom_id', $value ); |
930 | 930 | } |
931 | 931 | |
932 | 932 | /** |
933 | - * Set the custom name of the item. |
|
934 | - * |
|
935 | - * @since 1.0.19 |
|
936 | - * @param string $value new custom name. |
|
937 | - */ |
|
938 | - public function set_custom_name( $value ) { |
|
933 | + * Set the custom name of the item. |
|
934 | + * |
|
935 | + * @since 1.0.19 |
|
936 | + * @param string $value new custom name. |
|
937 | + */ |
|
938 | + public function set_custom_name( $value ) { |
|
939 | 939 | $this->set_prop( 'custom_name', $value ); |
940 | 940 | } |
941 | 941 | |
942 | 942 | /** |
943 | - * Set the custom singular name of the item. |
|
944 | - * |
|
945 | - * @since 1.0.19 |
|
946 | - * @param string $value new custom singular name. |
|
947 | - */ |
|
948 | - public function set_custom_singular_name( $value ) { |
|
943 | + * Set the custom singular name of the item. |
|
944 | + * |
|
945 | + * @since 1.0.19 |
|
946 | + * @param string $value new custom singular name. |
|
947 | + */ |
|
948 | + public function set_custom_singular_name( $value ) { |
|
949 | 949 | $this->set_prop( 'custom_singular_name', $value ); |
950 | 950 | } |
951 | 951 | |
952 | 952 | /** |
953 | - * Sets if an item is editable.. |
|
954 | - * |
|
955 | - * @since 1.0.19 |
|
956 | - * @param int|bool $value whether or not the item is editable. |
|
957 | - */ |
|
958 | - public function set_is_editable( $value ) { |
|
959 | - if ( is_numeric( $value ) ) { |
|
960 | - $this->set_prop( 'is_editable', (int) $value ); |
|
961 | - } |
|
953 | + * Sets if an item is editable.. |
|
954 | + * |
|
955 | + * @since 1.0.19 |
|
956 | + * @param int|bool $value whether or not the item is editable. |
|
957 | + */ |
|
958 | + public function set_is_editable( $value ) { |
|
959 | + if ( is_numeric( $value ) ) { |
|
960 | + $this->set_prop( 'is_editable', (int) $value ); |
|
961 | + } |
|
962 | 962 | } |
963 | 963 | |
964 | 964 | /** |
965 | - * Sets if dynamic pricing is enabled. |
|
966 | - * |
|
967 | - * @since 1.0.19 |
|
968 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
969 | - */ |
|
970 | - public function set_is_dynamic_pricing( $value ) { |
|
965 | + * Sets if dynamic pricing is enabled. |
|
966 | + * |
|
967 | + * @since 1.0.19 |
|
968 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
969 | + */ |
|
970 | + public function set_is_dynamic_pricing( $value ) { |
|
971 | 971 | $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
972 | 972 | } |
973 | 973 | |
974 | 974 | /** |
975 | - * Sets the minimum price if dynamic pricing is enabled. |
|
976 | - * |
|
977 | - * @since 1.0.19 |
|
978 | - * @param float $value minimum price. |
|
979 | - */ |
|
980 | - public function set_minimum_price( $value ) { |
|
975 | + * Sets the minimum price if dynamic pricing is enabled. |
|
976 | + * |
|
977 | + * @since 1.0.19 |
|
978 | + * @param float $value minimum price. |
|
979 | + */ |
|
980 | + public function set_minimum_price( $value ) { |
|
981 | 981 | $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
982 | 982 | } |
983 | 983 | |
984 | 984 | /** |
985 | - * Sets if this is a recurring item. |
|
986 | - * |
|
987 | - * @since 1.0.19 |
|
988 | - * @param int|bool $value whether or not dynamic pricing is allowed. |
|
989 | - */ |
|
990 | - public function set_is_recurring( $value ) { |
|
985 | + * Sets if this is a recurring item. |
|
986 | + * |
|
987 | + * @since 1.0.19 |
|
988 | + * @param int|bool $value whether or not dynamic pricing is allowed. |
|
989 | + */ |
|
990 | + public function set_is_recurring( $value ) { |
|
991 | 991 | $this->set_prop( 'is_recurring', (int) $value ); |
992 | 992 | } |
993 | 993 | |
994 | 994 | /** |
995 | - * Set the recurring period. |
|
996 | - * |
|
997 | - * @since 1.0.19 |
|
998 | - * @param string $value new period. |
|
999 | - */ |
|
1000 | - public function set_recurring_period( $value ) { |
|
995 | + * Set the recurring period. |
|
996 | + * |
|
997 | + * @since 1.0.19 |
|
998 | + * @param string $value new period. |
|
999 | + */ |
|
1000 | + public function set_recurring_period( $value ) { |
|
1001 | 1001 | $this->set_prop( 'recurring_period', $value ); |
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | /** |
1005 | - * Set the recurring interval. |
|
1006 | - * |
|
1007 | - * @since 1.0.19 |
|
1008 | - * @param int $value recurring interval. |
|
1009 | - */ |
|
1010 | - public function set_recurring_interval( $value ) { |
|
1005 | + * Set the recurring interval. |
|
1006 | + * |
|
1007 | + * @since 1.0.19 |
|
1008 | + * @param int $value recurring interval. |
|
1009 | + */ |
|
1010 | + public function set_recurring_interval( $value ) { |
|
1011 | 1011 | return $this->set_prop( 'recurring_interval', (int) $value ); |
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | /** |
1015 | - * Get the recurring limit. |
|
1016 | - * @since 1.0.19 |
|
1017 | - * @param int $value The recurring limit. |
|
1018 | - * @return int |
|
1019 | - */ |
|
1020 | - public function set_recurring_limit( $value ) { |
|
1015 | + * Get the recurring limit. |
|
1016 | + * @since 1.0.19 |
|
1017 | + * @param int $value The recurring limit. |
|
1018 | + * @return int |
|
1019 | + */ |
|
1020 | + public function set_recurring_limit( $value ) { |
|
1021 | 1021 | $this->set_prop( 'recurring_limit', (int) $value ); |
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | /** |
1025 | - * Checks if we have a free trial. |
|
1026 | - * |
|
1027 | - * @since 1.0.19 |
|
1028 | - * @param int|bool $value whether or not it has a free trial. |
|
1029 | - */ |
|
1030 | - public function set_is_free_trial( $value ) { |
|
1025 | + * Checks if we have a free trial. |
|
1026 | + * |
|
1027 | + * @since 1.0.19 |
|
1028 | + * @param int|bool $value whether or not it has a free trial. |
|
1029 | + */ |
|
1030 | + public function set_is_free_trial( $value ) { |
|
1031 | 1031 | $this->set_prop( 'is_free_trial', (int) $value ); |
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | /** |
1035 | - * Set the trial period. |
|
1036 | - * |
|
1037 | - * @since 1.0.19 |
|
1038 | - * @param string $value trial period. |
|
1039 | - */ |
|
1040 | - public function set_trial_period( $value ) { |
|
1035 | + * Set the trial period. |
|
1036 | + * |
|
1037 | + * @since 1.0.19 |
|
1038 | + * @param string $value trial period. |
|
1039 | + */ |
|
1040 | + public function set_trial_period( $value ) { |
|
1041 | 1041 | $this->set_prop( 'trial_period', $value ); |
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | /** |
1045 | - * Set the trial interval. |
|
1046 | - * |
|
1047 | - * @since 1.0.19 |
|
1048 | - * @param int $value trial interval. |
|
1049 | - */ |
|
1050 | - public function set_trial_interval( $value ) { |
|
1045 | + * Set the trial interval. |
|
1046 | + * |
|
1047 | + * @since 1.0.19 |
|
1048 | + * @param int $value trial interval. |
|
1049 | + */ |
|
1050 | + public function set_trial_interval( $value ) { |
|
1051 | 1051 | $this->set_prop( 'trial_interval', $value ); |
1052 | 1052 | } |
1053 | 1053 | |
@@ -1055,17 +1055,17 @@ discard block |
||
1055 | 1055 | * Create an item. For backwards compatibilty. |
1056 | 1056 | * |
1057 | 1057 | * @deprecated |
1058 | - * @return int item id |
|
1058 | + * @return int item id |
|
1059 | 1059 | */ |
1060 | 1060 | public function create( $data = array() ) { |
1061 | 1061 | |
1062 | - // Set the properties. |
|
1063 | - if ( is_array( $data ) ) { |
|
1064 | - $this->set_props( $data ); |
|
1065 | - } |
|
1062 | + // Set the properties. |
|
1063 | + if ( is_array( $data ) ) { |
|
1064 | + $this->set_props( $data ); |
|
1065 | + } |
|
1066 | 1066 | |
1067 | - // Save the item. |
|
1068 | - return $this->save(); |
|
1067 | + // Save the item. |
|
1068 | + return $this->save(); |
|
1069 | 1069 | |
1070 | 1070 | } |
1071 | 1071 | |
@@ -1073,7 +1073,7 @@ discard block |
||
1073 | 1073 | * Updates an item. For backwards compatibilty. |
1074 | 1074 | * |
1075 | 1075 | * @deprecated |
1076 | - * @return int item id |
|
1076 | + * @return int item id |
|
1077 | 1077 | */ |
1078 | 1078 | public function update( $data = array() ) { |
1079 | 1079 | return $this->create( $data ); |
@@ -1089,84 +1089,84 @@ discard block |
||
1089 | 1089 | */ |
1090 | 1090 | |
1091 | 1091 | /** |
1092 | - * Checks whether the item has enabled dynamic pricing. |
|
1093 | - * |
|
1094 | - * @since 1.0.19 |
|
1095 | - * @return bool |
|
1096 | - */ |
|
1097 | - public function user_can_set_their_price() { |
|
1092 | + * Checks whether the item has enabled dynamic pricing. |
|
1093 | + * |
|
1094 | + * @since 1.0.19 |
|
1095 | + * @return bool |
|
1096 | + */ |
|
1097 | + public function user_can_set_their_price() { |
|
1098 | 1098 | return (bool) $this->get_is_dynamic_pricing(); |
1099 | - } |
|
1099 | + } |
|
1100 | 1100 | |
1101 | - /** |
|
1102 | - * Checks whether the item is recurring. |
|
1103 | - * |
|
1104 | - * @since 1.0.19 |
|
1105 | - * @return bool |
|
1106 | - */ |
|
1107 | - public function is_recurring() { |
|
1101 | + /** |
|
1102 | + * Checks whether the item is recurring. |
|
1103 | + * |
|
1104 | + * @since 1.0.19 |
|
1105 | + * @return bool |
|
1106 | + */ |
|
1107 | + public function is_recurring() { |
|
1108 | 1108 | return (bool) $this->get_is_recurring(); |
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | /** |
1112 | - * Checks whether the item has a free trial. |
|
1113 | - * |
|
1114 | - * @since 1.0.19 |
|
1115 | - * @return bool |
|
1116 | - */ |
|
1112 | + * Checks whether the item has a free trial. |
|
1113 | + * |
|
1114 | + * @since 1.0.19 |
|
1115 | + * @return bool |
|
1116 | + */ |
|
1117 | 1117 | public function has_free_trial() { |
1118 | 1118 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1119 | 1119 | return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | /** |
1123 | - * Checks whether the item is free. |
|
1124 | - * |
|
1125 | - * @since 1.0.19 |
|
1126 | - * @return bool |
|
1127 | - */ |
|
1123 | + * Checks whether the item is free. |
|
1124 | + * |
|
1125 | + * @since 1.0.19 |
|
1126 | + * @return bool |
|
1127 | + */ |
|
1128 | 1128 | public function is_free() { |
1129 | 1129 | $is_free = $this->get_price() == 0; |
1130 | 1130 | return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | /** |
1134 | - * Checks the item status against a passed in status. |
|
1135 | - * |
|
1136 | - * @param array|string $status Status to check. |
|
1137 | - * @return bool |
|
1138 | - */ |
|
1139 | - public function has_status( $status ) { |
|
1140 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1141 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1134 | + * Checks the item status against a passed in status. |
|
1135 | + * |
|
1136 | + * @param array|string $status Status to check. |
|
1137 | + * @return bool |
|
1138 | + */ |
|
1139 | + public function has_status( $status ) { |
|
1140 | + $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1141 | + return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | /** |
1145 | - * Checks the item type against a passed in types. |
|
1146 | - * |
|
1147 | - * @param array|string $type Type to check. |
|
1148 | - * @return bool |
|
1149 | - */ |
|
1150 | - public function is_type( $type ) { |
|
1151 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1152 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1153 | - } |
|
1145 | + * Checks the item type against a passed in types. |
|
1146 | + * |
|
1147 | + * @param array|string $type Type to check. |
|
1148 | + * @return bool |
|
1149 | + */ |
|
1150 | + public function is_type( $type ) { |
|
1151 | + $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1152 | + return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1153 | + } |
|
1154 | 1154 | |
1155 | 1155 | /** |
1156 | - * Checks whether the item is editable. |
|
1157 | - * |
|
1158 | - * @since 1.0.19 |
|
1159 | - * @return bool |
|
1160 | - */ |
|
1156 | + * Checks whether the item is editable. |
|
1157 | + * |
|
1158 | + * @since 1.0.19 |
|
1159 | + * @return bool |
|
1160 | + */ |
|
1161 | 1161 | public function is_editable() { |
1162 | 1162 | $is_editable = $this->get_is_editable(); |
1163 | 1163 | return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
1164 | - } |
|
1164 | + } |
|
1165 | 1165 | |
1166 | - /** |
|
1167 | - * Returns an array of cart fees. |
|
1168 | - */ |
|
1169 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1166 | + /** |
|
1167 | + * Returns an array of cart fees. |
|
1168 | + */ |
|
1169 | + public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1170 | 1170 | |
1171 | 1171 | $fees = getpaid_session()->get( 'wpi_cart_fees' ); |
1172 | 1172 | |
@@ -1209,11 +1209,11 @@ discard block |
||
1209 | 1209 | } |
1210 | 1210 | |
1211 | 1211 | /** |
1212 | - * Checks whether the item is purchasable. |
|
1213 | - * |
|
1214 | - * @since 1.0.19 |
|
1215 | - * @return bool |
|
1216 | - */ |
|
1212 | + * Checks whether the item is purchasable. |
|
1213 | + * |
|
1214 | + * @since 1.0.19 |
|
1215 | + * @return bool |
|
1216 | + */ |
|
1217 | 1217 | public function can_purchase() { |
1218 | 1218 | $can_purchase = $this->exists(); |
1219 | 1219 | |
@@ -1225,11 +1225,11 @@ discard block |
||
1225 | 1225 | } |
1226 | 1226 | |
1227 | 1227 | /** |
1228 | - * Checks whether the item supports dynamic pricing. |
|
1229 | - * |
|
1230 | - * @since 1.0.19 |
|
1231 | - * @return bool |
|
1232 | - */ |
|
1228 | + * Checks whether the item supports dynamic pricing. |
|
1229 | + * |
|
1230 | + * @since 1.0.19 |
|
1231 | + * @return bool |
|
1232 | + */ |
|
1233 | 1233 | public function supports_dynamic_pricing() { |
1234 | 1234 | return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
1235 | 1235 | } |
@@ -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,30 +78,30 @@ 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 ); |
|
83 | - |
|
84 | - if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) { |
|
85 | - $this->set_id( $item ); |
|
86 | - } elseif ( $item instanceof self ) { |
|
87 | - $this->set_id( $item->get_id() ); |
|
88 | - } elseif ( ! empty( $item->ID ) ) { |
|
89 | - $this->set_id( $item->ID ); |
|
90 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) { |
|
91 | - $this->set_id( $item_id ); |
|
92 | - } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) { |
|
93 | - $this->set_id( $item_id ); |
|
81 | + public function __construct($item = 0) { |
|
82 | + parent::__construct($item); |
|
83 | + |
|
84 | + if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) { |
|
85 | + $this->set_id($item); |
|
86 | + } elseif ($item instanceof self) { |
|
87 | + $this->set_id($item->get_id()); |
|
88 | + } elseif (!empty($item->ID)) { |
|
89 | + $this->set_id($item->ID); |
|
90 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) { |
|
91 | + $this->set_id($item_id); |
|
92 | + } elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) { |
|
93 | + $this->set_id($item_id); |
|
94 | 94 | } else { |
95 | - $this->set_object_read( true ); |
|
95 | + $this->set_object_read(true); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // Load the datastore. |
99 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
99 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
100 | 100 | |
101 | - if ( $this->get_id() > 0 ) { |
|
102 | - $this->post = get_post( $this->get_id() ); |
|
101 | + if ($this->get_id() > 0) { |
|
102 | + $this->post = get_post($this->get_id()); |
|
103 | 103 | $this->ID = $this->get_id(); |
104 | - $this->data_store->read( $this ); |
|
104 | + $this->data_store->read($this); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | } |
@@ -128,8 +128,8 @@ discard block |
||
128 | 128 | * @param string $context View or edit context. |
129 | 129 | * @return int |
130 | 130 | */ |
131 | - public function get_parent_id( $context = 'view' ) { |
|
132 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
131 | + public function get_parent_id($context = 'view') { |
|
132 | + return (int) $this->get_prop('parent_id', $context); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $context View or edit context. |
140 | 140 | * @return string |
141 | 141 | */ |
142 | - public function get_status( $context = 'view' ) { |
|
143 | - return $this->get_prop( 'status', $context ); |
|
142 | + public function get_status($context = 'view') { |
|
143 | + return $this->get_prop('status', $context); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | * @param string $context View or edit context. |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - public function get_version( $context = 'view' ) { |
|
154 | - return $this->get_prop( 'version', $context ); |
|
153 | + public function get_version($context = 'view') { |
|
154 | + return $this->get_prop('version', $context); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | * @param string $context View or edit context. |
162 | 162 | * @return string |
163 | 163 | */ |
164 | - public function get_date_created( $context = 'view' ) { |
|
165 | - return $this->get_prop( 'date_created', $context ); |
|
164 | + public function get_date_created($context = 'view') { |
|
165 | + return $this->get_prop('date_created', $context); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | * @param string $context View or edit context. |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - public function get_date_created_gmt( $context = 'view' ) { |
|
176 | - $date = $this->get_date_created( $context ); |
|
175 | + public function get_date_created_gmt($context = 'view') { |
|
176 | + $date = $this->get_date_created($context); |
|
177 | 177 | |
178 | - if ( $date ) { |
|
179 | - $date = get_gmt_from_date( $date ); |
|
178 | + if ($date) { |
|
179 | + $date = get_gmt_from_date($date); |
|
180 | 180 | } |
181 | 181 | return $date; |
182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | * @param string $context View or edit context. |
189 | 189 | * @return string |
190 | 190 | */ |
191 | - public function get_date_modified( $context = 'view' ) { |
|
192 | - return $this->get_prop( 'date_modified', $context ); |
|
191 | + public function get_date_modified($context = 'view') { |
|
192 | + return $this->get_prop('date_modified', $context); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | * @param string $context View or edit context. |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
203 | - $date = $this->get_date_modified( $context ); |
|
202 | + public function get_date_modified_gmt($context = 'view') { |
|
203 | + $date = $this->get_date_modified($context); |
|
204 | 204 | |
205 | - if ( $date ) { |
|
206 | - $date = get_gmt_from_date( $date ); |
|
205 | + if ($date) { |
|
206 | + $date = get_gmt_from_date($date); |
|
207 | 207 | } |
208 | 208 | return $date; |
209 | 209 | } |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | * @param string $context View or edit context. |
216 | 216 | * @return string |
217 | 217 | */ |
218 | - public function get_name( $context = 'view' ) { |
|
219 | - return $this->get_prop( 'name', $context ); |
|
218 | + public function get_name($context = 'view') { |
|
219 | + return $this->get_prop('name', $context); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | * @param string $context View or edit context. |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public function get_title( $context = 'view' ) { |
|
230 | - return $this->get_name( $context ); |
|
229 | + public function get_title($context = 'view') { |
|
230 | + return $this->get_name($context); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -237,8 +237,8 @@ discard block |
||
237 | 237 | * @param string $context View or edit context. |
238 | 238 | * @return string |
239 | 239 | */ |
240 | - public function get_description( $context = 'view' ) { |
|
241 | - return $this->get_prop( 'description', $context ); |
|
240 | + public function get_description($context = 'view') { |
|
241 | + return $this->get_prop('description', $context); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | * @param string $context View or edit context. |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function get_excerpt( $context = 'view' ) { |
|
252 | - return $this->get_description( $context ); |
|
251 | + public function get_excerpt($context = 'view') { |
|
252 | + return $this->get_description($context); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -259,8 +259,8 @@ discard block |
||
259 | 259 | * @param string $context View or edit context. |
260 | 260 | * @return string |
261 | 261 | */ |
262 | - public function get_summary( $context = 'view' ) { |
|
263 | - return $this->get_description( $context ); |
|
262 | + public function get_summary($context = 'view') { |
|
263 | + return $this->get_description($context); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | * @param string $context View or edit context. |
271 | 271 | * @return int |
272 | 272 | */ |
273 | - public function get_author( $context = 'view' ) { |
|
274 | - return (int) $this->get_prop( 'author', $context ); |
|
273 | + public function get_author($context = 'view') { |
|
274 | + return (int) $this->get_prop('author', $context); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -281,8 +281,8 @@ discard block |
||
281 | 281 | * @param string $context View or edit context. |
282 | 282 | * @return int |
283 | 283 | */ |
284 | - public function get_owner( $context = 'view' ) { |
|
285 | - return $this->get_author( $context ); |
|
284 | + public function get_owner($context = 'view') { |
|
285 | + return $this->get_author($context); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,8 +292,8 @@ discard block |
||
292 | 292 | * @param string $context View or edit context. |
293 | 293 | * @return float |
294 | 294 | */ |
295 | - public function get_price( $context = 'view' ) { |
|
296 | - return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) ); |
|
295 | + public function get_price($context = 'view') { |
|
296 | + return wpinv_sanitize_amount($this->get_prop('price', $context)); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -303,15 +303,15 @@ discard block |
||
303 | 303 | * @param string $context View or edit context. |
304 | 304 | * @return float |
305 | 305 | */ |
306 | - public function get_initial_price( $context = 'view' ) { |
|
306 | + public function get_initial_price($context = 'view') { |
|
307 | 307 | |
308 | - $price = (float) $this->get_price( $context ); |
|
308 | + $price = (float) $this->get_price($context); |
|
309 | 309 | |
310 | - if ( $this->has_free_trial() ) { |
|
310 | + if ($this->has_free_trial()) { |
|
311 | 311 | $price = 0; |
312 | 312 | } |
313 | 313 | |
314 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) ); |
|
314 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this)); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * @return string |
323 | 323 | */ |
324 | 324 | public function get_the_price() { |
325 | - return wpinv_price( wpinv_format_amount( $this->get_price() ) ); |
|
325 | + return wpinv_price(wpinv_format_amount($this->get_price())); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @return string |
334 | 334 | */ |
335 | 335 | public function get_the_initial_price() { |
336 | - return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) ); |
|
336 | + return wpinv_price(wpinv_format_amount($this->get_initial_price())); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
@@ -343,8 +343,8 @@ discard block |
||
343 | 343 | * @param string $context View or edit context. |
344 | 344 | * @return string |
345 | 345 | */ |
346 | - public function get_vat_rule( $context = 'view' ) { |
|
347 | - return $this->get_prop( 'vat_rule', $context ); |
|
346 | + public function get_vat_rule($context = 'view') { |
|
347 | + return $this->get_prop('vat_rule', $context); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |
@@ -354,8 +354,8 @@ discard block |
||
354 | 354 | * @param string $context View or edit context. |
355 | 355 | * @return string |
356 | 356 | */ |
357 | - public function get_vat_class( $context = 'view' ) { |
|
358 | - return $this->get_prop( 'vat_class', $context ); |
|
357 | + public function get_vat_class($context = 'view') { |
|
358 | + return $this->get_prop('vat_class', $context); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -365,8 +365,8 @@ discard block |
||
365 | 365 | * @param string $context View or edit context. |
366 | 366 | * @return string |
367 | 367 | */ |
368 | - public function get_type( $context = 'view' ) { |
|
369 | - return $this->get_prop( 'type', $context ); |
|
368 | + public function get_type($context = 'view') { |
|
369 | + return $this->get_prop('type', $context); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | * @param string $context View or edit context. |
377 | 377 | * @return string |
378 | 378 | */ |
379 | - public function get_custom_id( $context = 'view' ) { |
|
380 | - return $this->get_prop( 'custom_id', $context ); |
|
379 | + public function get_custom_id($context = 'view') { |
|
380 | + return $this->get_prop('custom_id', $context); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | * @param string $context View or edit context. |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - public function get_custom_name( $context = 'view' ) { |
|
391 | - return $this->get_prop( 'custom_name', $context ); |
|
390 | + public function get_custom_name($context = 'view') { |
|
391 | + return $this->get_prop('custom_name', $context); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -398,8 +398,8 @@ discard block |
||
398 | 398 | * @param string $context View or edit context. |
399 | 399 | * @return string |
400 | 400 | */ |
401 | - public function get_custom_singular_name( $context = 'view' ) { |
|
402 | - return $this->get_prop( 'custom_singular_name', $context ); |
|
401 | + public function get_custom_singular_name($context = 'view') { |
|
402 | + return $this->get_prop('custom_singular_name', $context); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -409,8 +409,8 @@ discard block |
||
409 | 409 | * @param string $context View or edit context. |
410 | 410 | * @return int |
411 | 411 | */ |
412 | - public function get_is_editable( $context = 'view' ) { |
|
413 | - return (int) $this->get_prop( 'is_editable', $context ); |
|
412 | + public function get_is_editable($context = 'view') { |
|
413 | + return (int) $this->get_prop('is_editable', $context); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | * @param string $context View or edit context. |
421 | 421 | * @return int |
422 | 422 | */ |
423 | - public function get_editable( $context = 'view' ) { |
|
424 | - return $this->get_is_editable( $context ); |
|
423 | + public function get_editable($context = 'view') { |
|
424 | + return $this->get_is_editable($context); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -431,8 +431,8 @@ discard block |
||
431 | 431 | * @param string $context View or edit context. |
432 | 432 | * @return int |
433 | 433 | */ |
434 | - public function get_is_dynamic_pricing( $context = 'view' ) { |
|
435 | - return (int) $this->get_prop( 'is_dynamic_pricing', $context ); |
|
434 | + public function get_is_dynamic_pricing($context = 'view') { |
|
435 | + return (int) $this->get_prop('is_dynamic_pricing', $context); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -442,8 +442,8 @@ discard block |
||
442 | 442 | * @param string $context View or edit context. |
443 | 443 | * @return float |
444 | 444 | */ |
445 | - public function get_minimum_price( $context = 'view' ) { |
|
446 | - return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) ); |
|
445 | + public function get_minimum_price($context = 'view') { |
|
446 | + return wpinv_sanitize_amount($this->get_prop('minimum_price', $context)); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -453,8 +453,8 @@ discard block |
||
453 | 453 | * @param string $context View or edit context. |
454 | 454 | * @return int |
455 | 455 | */ |
456 | - public function get_is_recurring( $context = 'view' ) { |
|
457 | - return (int) $this->get_prop( 'is_recurring', $context ); |
|
456 | + public function get_is_recurring($context = 'view') { |
|
457 | + return (int) $this->get_prop('is_recurring', $context); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -464,9 +464,9 @@ discard block |
||
464 | 464 | * @param string $context View or edit context. |
465 | 465 | * @return float |
466 | 466 | */ |
467 | - public function get_recurring_price( $context = 'view' ) { |
|
468 | - $price = $this->get_price( $context ); |
|
469 | - return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) ); |
|
467 | + public function get_recurring_price($context = 'view') { |
|
468 | + $price = $this->get_price($context); |
|
469 | + return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID)); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | * @return string |
478 | 478 | */ |
479 | 479 | public function get_the_recurring_price() { |
480 | - return wpinv_price( wpinv_format_amount( $this->get_recurring_price() ) ); |
|
480 | + return wpinv_price(wpinv_format_amount($this->get_recurring_price())); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
@@ -498,15 +498,15 @@ discard block |
||
498 | 498 | $period = $this->get_recurring_period(); |
499 | 499 | $interval = $this->get_recurring_interval(); |
500 | 500 | |
501 | - if ( $this->has_free_trial() ) { |
|
501 | + if ($this->has_free_trial()) { |
|
502 | 502 | $period = $this->get_trial_period(); |
503 | 503 | $interval = $this->get_trial_interval(); |
504 | 504 | } |
505 | 505 | |
506 | - $period = $periods[ $period ]; |
|
507 | - $interval = empty( $interval ) ? 1 : $interval; |
|
508 | - $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) ); |
|
509 | - return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this ); |
|
506 | + $period = $periods[$period]; |
|
507 | + $interval = empty($interval) ? 1 : $interval; |
|
508 | + $next_renewal = strtotime("+$interval $period", current_time('timestamp')); |
|
509 | + return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -516,14 +516,14 @@ discard block |
||
516 | 516 | * @param bool $full Return abbreviation or in full. |
517 | 517 | * @return string |
518 | 518 | */ |
519 | - public function get_recurring_period( $full = false ) { |
|
520 | - $period = $this->get_prop( 'recurring_period', 'view' ); |
|
519 | + public function get_recurring_period($full = false) { |
|
520 | + $period = $this->get_prop('recurring_period', 'view'); |
|
521 | 521 | |
522 | - if ( $full && ! is_bool( $full ) ) { |
|
522 | + if ($full && !is_bool($full)) { |
|
523 | 523 | $full = false; |
524 | 524 | } |
525 | 525 | |
526 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
526 | + return getpaid_sanitize_recurring_period($period, $full); |
|
527 | 527 | } |
528 | 528 | |
529 | 529 | /** |
@@ -533,10 +533,10 @@ discard block |
||
533 | 533 | * @param string $context View or edit context. |
534 | 534 | * @return int |
535 | 535 | */ |
536 | - public function get_recurring_interval( $context = 'view' ) { |
|
537 | - $interval = absint( $this->get_prop( 'recurring_interval', $context ) ); |
|
536 | + public function get_recurring_interval($context = 'view') { |
|
537 | + $interval = absint($this->get_prop('recurring_interval', $context)); |
|
538 | 538 | |
539 | - if ( $interval < 1 ) { |
|
539 | + if ($interval < 1) { |
|
540 | 540 | $interval = 1; |
541 | 541 | } |
542 | 542 | |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @param string $context View or edit context. |
551 | 551 | * @return int |
552 | 552 | */ |
553 | - public function get_recurring_limit( $context = 'view' ) { |
|
554 | - return (int) $this->get_prop( 'recurring_limit', $context ); |
|
553 | + public function get_recurring_limit($context = 'view') { |
|
554 | + return (int) $this->get_prop('recurring_limit', $context); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -561,8 +561,8 @@ discard block |
||
561 | 561 | * @param string $context View or edit context. |
562 | 562 | * @return int |
563 | 563 | */ |
564 | - public function get_is_free_trial( $context = 'view' ) { |
|
565 | - return (int) $this->get_prop( 'is_free_trial', $context ); |
|
564 | + public function get_is_free_trial($context = 'view') { |
|
565 | + return (int) $this->get_prop('is_free_trial', $context); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
@@ -572,8 +572,8 @@ discard block |
||
572 | 572 | * @param string $context View or edit context. |
573 | 573 | * @return int |
574 | 574 | */ |
575 | - public function get_free_trial( $context = 'view' ) { |
|
576 | - return $this->get_is_free_trial( $context ); |
|
575 | + public function get_free_trial($context = 'view') { |
|
576 | + return $this->get_is_free_trial($context); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | /** |
@@ -583,14 +583,14 @@ discard block |
||
583 | 583 | * @param bool $full Return abbreviation or in full. |
584 | 584 | * @return string |
585 | 585 | */ |
586 | - public function get_trial_period( $full = false ) { |
|
587 | - $period = $this->get_prop( 'trial_period', 'view' ); |
|
586 | + public function get_trial_period($full = false) { |
|
587 | + $period = $this->get_prop('trial_period', 'view'); |
|
588 | 588 | |
589 | - if ( $full && ! is_bool( $full ) ) { |
|
589 | + if ($full && !is_bool($full)) { |
|
590 | 590 | $full = false; |
591 | 591 | } |
592 | 592 | |
593 | - return getpaid_sanitize_recurring_period( $period, $full ); |
|
593 | + return getpaid_sanitize_recurring_period($period, $full); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
@@ -600,8 +600,8 @@ discard block |
||
600 | 600 | * @param string $context View or edit context. |
601 | 601 | * @return int |
602 | 602 | */ |
603 | - public function get_trial_interval( $context = 'view' ) { |
|
604 | - return (int) $this->get_prop( 'trial_interval', $context ); |
|
603 | + public function get_trial_interval($context = 'view') { |
|
604 | + return (int) $this->get_prop('trial_interval', $context); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | /** |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | * @return string |
612 | 612 | */ |
613 | 613 | public function get_edit_url() { |
614 | - return get_edit_post_link( $this->get_id() ); |
|
614 | + return get_edit_post_link($this->get_id()); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -625,36 +625,36 @@ discard block |
||
625 | 625 | * @since 1.0.15 |
626 | 626 | * @return int |
627 | 627 | */ |
628 | - public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) { |
|
628 | + public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') { |
|
629 | 629 | |
630 | 630 | // Trim the value. |
631 | - $value = sanitize_text_field( $value ); |
|
631 | + $value = sanitize_text_field($value); |
|
632 | 632 | |
633 | - if ( empty( $value ) ) { |
|
633 | + if (empty($value)) { |
|
634 | 634 | return 0; |
635 | 635 | } |
636 | 636 | |
637 | 637 | // Valid fields. |
638 | - $fields = array( 'custom_id', 'name', 'slug' ); |
|
638 | + $fields = array('custom_id', 'name', 'slug'); |
|
639 | 639 | |
640 | 640 | // Ensure a field has been passed. |
641 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
641 | + if (empty($field) || !in_array($field, $fields)) { |
|
642 | 642 | return 0; |
643 | 643 | } |
644 | 644 | |
645 | - if ( $field == 'name' ) { |
|
645 | + if ($field == 'name') { |
|
646 | 646 | $field = 'slug'; |
647 | 647 | } |
648 | 648 | |
649 | 649 | // Maybe retrieve from the cache. |
650 | - $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
651 | - if ( ! empty( $item_id ) ) { |
|
650 | + $item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
651 | + if (!empty($item_id)) { |
|
652 | 652 | return $item_id; |
653 | 653 | } |
654 | 654 | |
655 | 655 | // Fetch from the db. |
656 | 656 | $items = array(); |
657 | - if ( $field =='slug' ) { |
|
657 | + if ($field == 'slug') { |
|
658 | 658 | $items = get_posts( |
659 | 659 | array( |
660 | 660 | 'post_type' => 'wpi_item', |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | ); |
666 | 666 | } |
667 | 667 | |
668 | - if ( $field =='custom_id' ) { |
|
668 | + if ($field == 'custom_id') { |
|
669 | 669 | $items = get_posts( |
670 | 670 | array( |
671 | 671 | 'post_type' => 'wpi_item', |
@@ -685,12 +685,12 @@ discard block |
||
685 | 685 | ); |
686 | 686 | } |
687 | 687 | |
688 | - if ( empty( $items ) ) { |
|
688 | + if (empty($items)) { |
|
689 | 689 | return 0; |
690 | 690 | } |
691 | 691 | |
692 | 692 | // Update the cache with our data |
693 | - wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" ); |
|
693 | + wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids"); |
|
694 | 694 | |
695 | 695 | return $items[0]->ID; |
696 | 696 | } |
@@ -698,19 +698,19 @@ discard block |
||
698 | 698 | /** |
699 | 699 | * Margic method for retrieving a property. |
700 | 700 | */ |
701 | - public function __get( $key ) { |
|
701 | + public function __get($key) { |
|
702 | 702 | |
703 | 703 | // Check if we have a helper method for that. |
704 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
705 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
704 | + if (method_exists($this, 'get_' . $key)) { |
|
705 | + return call_user_func(array($this, 'get_' . $key)); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | // Check if the key is in the associated $post object. |
709 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
709 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
710 | 710 | return $this->post->$key; |
711 | 711 | } |
712 | 712 | |
713 | - return $this->get_prop( $key ); |
|
713 | + return $this->get_prop($key); |
|
714 | 714 | |
715 | 715 | } |
716 | 716 | |
@@ -729,11 +729,11 @@ discard block |
||
729 | 729 | * |
730 | 730 | * @since 1.0.19 |
731 | 731 | */ |
732 | - public function set_parent_id( $value ) { |
|
733 | - if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) { |
|
732 | + public function set_parent_id($value) { |
|
733 | + if ($value && ($value === $this->get_id() || !get_post($value))) { |
|
734 | 734 | return; |
735 | 735 | } |
736 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
736 | + $this->set_prop('parent_id', absint($value)); |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
@@ -743,10 +743,10 @@ discard block |
||
743 | 743 | * @param string $status New status. |
744 | 744 | * @return array details of change. |
745 | 745 | */ |
746 | - public function set_status( $status ) { |
|
746 | + public function set_status($status) { |
|
747 | 747 | $old_status = $this->get_status(); |
748 | 748 | |
749 | - $this->set_prop( 'status', $status ); |
|
749 | + $this->set_prop('status', $status); |
|
750 | 750 | |
751 | 751 | return array( |
752 | 752 | 'from' => $old_status, |
@@ -759,8 +759,8 @@ discard block |
||
759 | 759 | * |
760 | 760 | * @since 1.0.19 |
761 | 761 | */ |
762 | - public function set_version( $value ) { |
|
763 | - $this->set_prop( 'version', $value ); |
|
762 | + public function set_version($value) { |
|
763 | + $this->set_prop('version', $value); |
|
764 | 764 | } |
765 | 765 | |
766 | 766 | /** |
@@ -770,11 +770,11 @@ discard block |
||
770 | 770 | * @param string $value Value to set. |
771 | 771 | * @return bool Whether or not the date was set. |
772 | 772 | */ |
773 | - public function set_date_created( $value ) { |
|
774 | - $date = strtotime( $value ); |
|
773 | + public function set_date_created($value) { |
|
774 | + $date = strtotime($value); |
|
775 | 775 | |
776 | - if ( $date ) { |
|
777 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
776 | + if ($date) { |
|
777 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
778 | 778 | return true; |
779 | 779 | } |
780 | 780 | |
@@ -789,11 +789,11 @@ discard block |
||
789 | 789 | * @param string $value Value to set. |
790 | 790 | * @return bool Whether or not the date was set. |
791 | 791 | */ |
792 | - public function set_date_modified( $value ) { |
|
793 | - $date = strtotime( $value ); |
|
792 | + public function set_date_modified($value) { |
|
793 | + $date = strtotime($value); |
|
794 | 794 | |
795 | - if ( $date ) { |
|
796 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
795 | + if ($date) { |
|
796 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
797 | 797 | return true; |
798 | 798 | } |
799 | 799 | |
@@ -807,9 +807,9 @@ discard block |
||
807 | 807 | * @since 1.0.19 |
808 | 808 | * @param string $value New name. |
809 | 809 | */ |
810 | - public function set_name( $value ) { |
|
811 | - $name = sanitize_text_field( $value ); |
|
812 | - $this->set_prop( 'name', $name ); |
|
810 | + public function set_name($value) { |
|
811 | + $name = sanitize_text_field($value); |
|
812 | + $this->set_prop('name', $name); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | /** |
@@ -818,8 +818,8 @@ discard block |
||
818 | 818 | * @since 1.0.19 |
819 | 819 | * @param string $value New name. |
820 | 820 | */ |
821 | - public function set_title( $value ) { |
|
822 | - $this->set_name( $value ); |
|
821 | + public function set_title($value) { |
|
822 | + $this->set_name($value); |
|
823 | 823 | } |
824 | 824 | |
825 | 825 | /** |
@@ -828,9 +828,9 @@ discard block |
||
828 | 828 | * @since 1.0.19 |
829 | 829 | * @param string $value New description. |
830 | 830 | */ |
831 | - public function set_description( $value ) { |
|
832 | - $description = wp_kses_post( $value ); |
|
833 | - return $this->set_prop( 'description', $description ); |
|
831 | + public function set_description($value) { |
|
832 | + $description = wp_kses_post($value); |
|
833 | + return $this->set_prop('description', $description); |
|
834 | 834 | } |
835 | 835 | |
836 | 836 | /** |
@@ -839,8 +839,8 @@ discard block |
||
839 | 839 | * @since 1.0.19 |
840 | 840 | * @param string $value New description. |
841 | 841 | */ |
842 | - public function set_excerpt( $value ) { |
|
843 | - $this->set_description( $value ); |
|
842 | + public function set_excerpt($value) { |
|
843 | + $this->set_description($value); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
@@ -849,8 +849,8 @@ discard block |
||
849 | 849 | * @since 1.0.19 |
850 | 850 | * @param string $value New description. |
851 | 851 | */ |
852 | - public function set_summary( $value ) { |
|
853 | - $this->set_description( $value ); |
|
852 | + public function set_summary($value) { |
|
853 | + $this->set_description($value); |
|
854 | 854 | } |
855 | 855 | |
856 | 856 | /** |
@@ -859,8 +859,8 @@ discard block |
||
859 | 859 | * @since 1.0.19 |
860 | 860 | * @param int $value New author. |
861 | 861 | */ |
862 | - public function set_author( $value ) { |
|
863 | - $this->set_prop( 'author', (int) $value ); |
|
862 | + public function set_author($value) { |
|
863 | + $this->set_prop('author', (int) $value); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | /** |
@@ -869,8 +869,8 @@ discard block |
||
869 | 869 | * @since 1.0.19 |
870 | 870 | * @param int $value New author. |
871 | 871 | */ |
872 | - public function set_owner( $value ) { |
|
873 | - $this->set_author( $value ); |
|
872 | + public function set_owner($value) { |
|
873 | + $this->set_author($value); |
|
874 | 874 | } |
875 | 875 | |
876 | 876 | /** |
@@ -879,8 +879,8 @@ discard block |
||
879 | 879 | * @since 1.0.19 |
880 | 880 | * @param float $value New price. |
881 | 881 | */ |
882 | - public function set_price( $value ) { |
|
883 | - $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) ); |
|
882 | + public function set_price($value) { |
|
883 | + $this->set_prop('price', (float) wpinv_sanitize_amount($value)); |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
@@ -889,8 +889,8 @@ discard block |
||
889 | 889 | * @since 1.0.19 |
890 | 890 | * @param string $value new rule. |
891 | 891 | */ |
892 | - public function set_vat_rule( $value ) { |
|
893 | - $this->set_prop( 'vat_rule', $value ); |
|
892 | + public function set_vat_rule($value) { |
|
893 | + $this->set_prop('vat_rule', $value); |
|
894 | 894 | } |
895 | 895 | |
896 | 896 | /** |
@@ -899,8 +899,8 @@ discard block |
||
899 | 899 | * @since 1.0.19 |
900 | 900 | * @param string $value new class. |
901 | 901 | */ |
902 | - public function set_vat_class( $value ) { |
|
903 | - $this->set_prop( 'vat_class', $value ); |
|
902 | + public function set_vat_class($value) { |
|
903 | + $this->set_prop('vat_class', $value); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | /** |
@@ -910,13 +910,13 @@ discard block |
||
910 | 910 | * @param string $value new item type. |
911 | 911 | * @return string |
912 | 912 | */ |
913 | - public function set_type( $value ) { |
|
913 | + public function set_type($value) { |
|
914 | 914 | |
915 | - if ( empty( $value ) ) { |
|
915 | + if (empty($value)) { |
|
916 | 916 | $value = 'custom'; |
917 | 917 | } |
918 | 918 | |
919 | - $this->set_prop( 'type', $value ); |
|
919 | + $this->set_prop('type', $value); |
|
920 | 920 | } |
921 | 921 | |
922 | 922 | /** |
@@ -925,8 +925,8 @@ discard block |
||
925 | 925 | * @since 1.0.19 |
926 | 926 | * @param string $value new custom id. |
927 | 927 | */ |
928 | - public function set_custom_id( $value ) { |
|
929 | - $this->set_prop( 'custom_id', $value ); |
|
928 | + public function set_custom_id($value) { |
|
929 | + $this->set_prop('custom_id', $value); |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | /** |
@@ -935,8 +935,8 @@ discard block |
||
935 | 935 | * @since 1.0.19 |
936 | 936 | * @param string $value new custom name. |
937 | 937 | */ |
938 | - public function set_custom_name( $value ) { |
|
939 | - $this->set_prop( 'custom_name', $value ); |
|
938 | + public function set_custom_name($value) { |
|
939 | + $this->set_prop('custom_name', $value); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | /** |
@@ -945,8 +945,8 @@ discard block |
||
945 | 945 | * @since 1.0.19 |
946 | 946 | * @param string $value new custom singular name. |
947 | 947 | */ |
948 | - public function set_custom_singular_name( $value ) { |
|
949 | - $this->set_prop( 'custom_singular_name', $value ); |
|
948 | + public function set_custom_singular_name($value) { |
|
949 | + $this->set_prop('custom_singular_name', $value); |
|
950 | 950 | } |
951 | 951 | |
952 | 952 | /** |
@@ -955,9 +955,9 @@ discard block |
||
955 | 955 | * @since 1.0.19 |
956 | 956 | * @param int|bool $value whether or not the item is editable. |
957 | 957 | */ |
958 | - public function set_is_editable( $value ) { |
|
959 | - if ( is_numeric( $value ) ) { |
|
960 | - $this->set_prop( 'is_editable', (int) $value ); |
|
958 | + public function set_is_editable($value) { |
|
959 | + if (is_numeric($value)) { |
|
960 | + $this->set_prop('is_editable', (int) $value); |
|
961 | 961 | } |
962 | 962 | } |
963 | 963 | |
@@ -967,8 +967,8 @@ discard block |
||
967 | 967 | * @since 1.0.19 |
968 | 968 | * @param int|bool $value whether or not dynamic pricing is allowed. |
969 | 969 | */ |
970 | - public function set_is_dynamic_pricing( $value ) { |
|
971 | - $this->set_prop( 'is_dynamic_pricing', (int) $value ); |
|
970 | + public function set_is_dynamic_pricing($value) { |
|
971 | + $this->set_prop('is_dynamic_pricing', (int) $value); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | /** |
@@ -977,8 +977,8 @@ discard block |
||
977 | 977 | * @since 1.0.19 |
978 | 978 | * @param float $value minimum price. |
979 | 979 | */ |
980 | - public function set_minimum_price( $value ) { |
|
981 | - $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) ); |
|
980 | + public function set_minimum_price($value) { |
|
981 | + $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value)); |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | /** |
@@ -987,8 +987,8 @@ discard block |
||
987 | 987 | * @since 1.0.19 |
988 | 988 | * @param int|bool $value whether or not dynamic pricing is allowed. |
989 | 989 | */ |
990 | - public function set_is_recurring( $value ) { |
|
991 | - $this->set_prop( 'is_recurring', (int) $value ); |
|
990 | + public function set_is_recurring($value) { |
|
991 | + $this->set_prop('is_recurring', (int) $value); |
|
992 | 992 | } |
993 | 993 | |
994 | 994 | /** |
@@ -997,8 +997,8 @@ discard block |
||
997 | 997 | * @since 1.0.19 |
998 | 998 | * @param string $value new period. |
999 | 999 | */ |
1000 | - public function set_recurring_period( $value ) { |
|
1001 | - $this->set_prop( 'recurring_period', $value ); |
|
1000 | + public function set_recurring_period($value) { |
|
1001 | + $this->set_prop('recurring_period', $value); |
|
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | /** |
@@ -1007,8 +1007,8 @@ discard block |
||
1007 | 1007 | * @since 1.0.19 |
1008 | 1008 | * @param int $value recurring interval. |
1009 | 1009 | */ |
1010 | - public function set_recurring_interval( $value ) { |
|
1011 | - return $this->set_prop( 'recurring_interval', (int) $value ); |
|
1010 | + public function set_recurring_interval($value) { |
|
1011 | + return $this->set_prop('recurring_interval', (int) $value); |
|
1012 | 1012 | } |
1013 | 1013 | |
1014 | 1014 | /** |
@@ -1017,8 +1017,8 @@ discard block |
||
1017 | 1017 | * @param int $value The recurring limit. |
1018 | 1018 | * @return int |
1019 | 1019 | */ |
1020 | - public function set_recurring_limit( $value ) { |
|
1021 | - $this->set_prop( 'recurring_limit', (int) $value ); |
|
1020 | + public function set_recurring_limit($value) { |
|
1021 | + $this->set_prop('recurring_limit', (int) $value); |
|
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | /** |
@@ -1027,8 +1027,8 @@ discard block |
||
1027 | 1027 | * @since 1.0.19 |
1028 | 1028 | * @param int|bool $value whether or not it has a free trial. |
1029 | 1029 | */ |
1030 | - public function set_is_free_trial( $value ) { |
|
1031 | - $this->set_prop( 'is_free_trial', (int) $value ); |
|
1030 | + public function set_is_free_trial($value) { |
|
1031 | + $this->set_prop('is_free_trial', (int) $value); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | /** |
@@ -1037,8 +1037,8 @@ discard block |
||
1037 | 1037 | * @since 1.0.19 |
1038 | 1038 | * @param string $value trial period. |
1039 | 1039 | */ |
1040 | - public function set_trial_period( $value ) { |
|
1041 | - $this->set_prop( 'trial_period', $value ); |
|
1040 | + public function set_trial_period($value) { |
|
1041 | + $this->set_prop('trial_period', $value); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | /** |
@@ -1047,8 +1047,8 @@ discard block |
||
1047 | 1047 | * @since 1.0.19 |
1048 | 1048 | * @param int $value trial interval. |
1049 | 1049 | */ |
1050 | - public function set_trial_interval( $value ) { |
|
1051 | - $this->set_prop( 'trial_interval', $value ); |
|
1050 | + public function set_trial_interval($value) { |
|
1051 | + $this->set_prop('trial_interval', $value); |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | /** |
@@ -1057,11 +1057,11 @@ discard block |
||
1057 | 1057 | * @deprecated |
1058 | 1058 | * @return int item id |
1059 | 1059 | */ |
1060 | - public function create( $data = array() ) { |
|
1060 | + public function create($data = array()) { |
|
1061 | 1061 | |
1062 | 1062 | // Set the properties. |
1063 | - if ( is_array( $data ) ) { |
|
1064 | - $this->set_props( $data ); |
|
1063 | + if (is_array($data)) { |
|
1064 | + $this->set_props($data); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | 1067 | // Save the item. |
@@ -1075,8 +1075,8 @@ discard block |
||
1075 | 1075 | * @deprecated |
1076 | 1076 | * @return int item id |
1077 | 1077 | */ |
1078 | - public function update( $data = array() ) { |
|
1079 | - return $this->create( $data ); |
|
1078 | + public function update($data = array()) { |
|
1079 | + return $this->create($data); |
|
1080 | 1080 | } |
1081 | 1081 | |
1082 | 1082 | /* |
@@ -1116,7 +1116,7 @@ discard block |
||
1116 | 1116 | */ |
1117 | 1117 | public function has_free_trial() { |
1118 | 1118 | $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false; |
1119 | - return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this ); |
|
1119 | + return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this); |
|
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | /** |
@@ -1126,8 +1126,8 @@ discard block |
||
1126 | 1126 | * @return bool |
1127 | 1127 | */ |
1128 | 1128 | public function is_free() { |
1129 | - $is_free = $this->get_price() == 0; |
|
1130 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this ); |
|
1129 | + $is_free = $this->get_price() == 0; |
|
1130 | + return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | /** |
@@ -1136,9 +1136,9 @@ discard block |
||
1136 | 1136 | * @param array|string $status Status to check. |
1137 | 1137 | * @return bool |
1138 | 1138 | */ |
1139 | - public function has_status( $status ) { |
|
1140 | - $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status; |
|
1141 | - return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status ); |
|
1139 | + public function has_status($status) { |
|
1140 | + $has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status; |
|
1141 | + return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | /** |
@@ -1147,9 +1147,9 @@ discard block |
||
1147 | 1147 | * @param array|string $type Type to check. |
1148 | 1148 | * @return bool |
1149 | 1149 | */ |
1150 | - public function is_type( $type ) { |
|
1151 | - $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type; |
|
1152 | - return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type ); |
|
1150 | + public function is_type($type) { |
|
1151 | + $is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type; |
|
1152 | + return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type); |
|
1153 | 1153 | } |
1154 | 1154 | |
1155 | 1155 | /** |
@@ -1160,52 +1160,52 @@ discard block |
||
1160 | 1160 | */ |
1161 | 1161 | public function is_editable() { |
1162 | 1162 | $is_editable = $this->get_is_editable(); |
1163 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this ); |
|
1163 | + return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | /** |
1167 | 1167 | * Returns an array of cart fees. |
1168 | 1168 | */ |
1169 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
1169 | + public function get_fees($type = 'fee', $item_id = 0) { |
|
1170 | 1170 | |
1171 | - $fees = getpaid_session()->get( 'wpi_cart_fees' ); |
|
1171 | + $fees = getpaid_session()->get('wpi_cart_fees'); |
|
1172 | 1172 | |
1173 | - if ( ! wpinv_get_cart_contents() ) { |
|
1173 | + if (!wpinv_get_cart_contents()) { |
|
1174 | 1174 | // We can only get item type fees when the cart is empty |
1175 | 1175 | $type = 'custom'; |
1176 | 1176 | } |
1177 | 1177 | |
1178 | - if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { |
|
1179 | - foreach( $fees as $key => $fee ) { |
|
1180 | - if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1181 | - unset( $fees[ $key ] ); |
|
1178 | + if (!empty($fees) && !empty($type) && 'all' !== $type) { |
|
1179 | + foreach ($fees as $key => $fee) { |
|
1180 | + if (!empty($fee['type']) && $type != $fee['type']) { |
|
1181 | + unset($fees[$key]); |
|
1182 | 1182 | } |
1183 | 1183 | } |
1184 | 1184 | } |
1185 | 1185 | |
1186 | - if ( ! empty( $fees ) && ! empty( $item_id ) ) { |
|
1186 | + if (!empty($fees) && !empty($item_id)) { |
|
1187 | 1187 | // Remove fees that don't belong to the specified Item |
1188 | - foreach ( $fees as $key => $fee ) { |
|
1189 | - if ( (int) $item_id !== (int)$fee['custom_id'] ) { |
|
1190 | - unset( $fees[ $key ] ); |
|
1188 | + foreach ($fees as $key => $fee) { |
|
1189 | + if ((int) $item_id !== (int) $fee['custom_id']) { |
|
1190 | + unset($fees[$key]); |
|
1191 | 1191 | } |
1192 | 1192 | } |
1193 | 1193 | } |
1194 | 1194 | |
1195 | - if ( ! empty( $fees ) ) { |
|
1195 | + if (!empty($fees)) { |
|
1196 | 1196 | // Remove fees that belong to a specific item but are not in the cart |
1197 | - foreach( $fees as $key => $fee ) { |
|
1198 | - if( empty( $fee['custom_id'] ) ) { |
|
1197 | + foreach ($fees as $key => $fee) { |
|
1198 | + if (empty($fee['custom_id'])) { |
|
1199 | 1199 | continue; |
1200 | 1200 | } |
1201 | 1201 | |
1202 | - if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) { |
|
1203 | - unset( $fees[ $key ] ); |
|
1202 | + if (!wpinv_item_in_cart($fee['custom_id'])) { |
|
1203 | + unset($fees[$key]); |
|
1204 | 1204 | } |
1205 | 1205 | } |
1206 | 1206 | } |
1207 | 1207 | |
1208 | - return ! empty( $fees ) ? $fees : array(); |
|
1208 | + return !empty($fees) ? $fees : array(); |
|
1209 | 1209 | } |
1210 | 1210 | |
1211 | 1211 | /** |
@@ -1217,11 +1217,11 @@ discard block |
||
1217 | 1217 | public function can_purchase() { |
1218 | 1218 | $can_purchase = $this->exists(); |
1219 | 1219 | |
1220 | - if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
1220 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
1221 | 1221 | $can_purchase = false; |
1222 | 1222 | } |
1223 | 1223 | |
1224 | - return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
1224 | + return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
1225 | 1225 | } |
1226 | 1226 | |
1227 | 1227 | /** |
@@ -1231,6 +1231,6 @@ discard block |
||
1231 | 1231 | * @return bool |
1232 | 1232 | */ |
1233 | 1233 | public function supports_dynamic_pricing() { |
1234 | - return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this ); |
|
1234 | + return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this); |
|
1235 | 1235 | } |
1236 | 1236 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -103,36 +103,36 @@ discard block |
||
103 | 103 | 'ip_geolocation' => true, |
104 | 104 | ); |
105 | 105 | |
106 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
107 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
106 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
107 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
108 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
109 | 109 | |
110 | - if ( $nopriv ) { |
|
111 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
112 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
113 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | + if ($nopriv) { |
|
111 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
113 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | 118 | public static function add_note() { |
119 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
119 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
120 | 120 | |
121 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
121 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
122 | 122 | die(-1); |
123 | 123 | } |
124 | 124 | |
125 | - $post_id = absint( $_POST['post_id'] ); |
|
126 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
127 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
125 | + $post_id = absint($_POST['post_id']); |
|
126 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
127 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
128 | 128 | |
129 | 129 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
130 | 130 | |
131 | - if ( $post_id > 0 ) { |
|
132 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
131 | + if ($post_id > 0) { |
|
132 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
133 | 133 | |
134 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
135 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
134 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
135 | + wpinv_get_invoice_note_line_item($note_id); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -140,16 +140,16 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | public static function delete_note() { |
143 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
143 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
144 | 144 | |
145 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
145 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
146 | 146 | die(-1); |
147 | 147 | } |
148 | 148 | |
149 | - $note_id = (int)$_POST['note_id']; |
|
149 | + $note_id = (int) $_POST['note_id']; |
|
150 | 150 | |
151 | - if ( $note_id > 0 ) { |
|
152 | - wp_delete_comment( $note_id, true ); |
|
151 | + if ($note_id > 0) { |
|
152 | + wp_delete_comment($note_id, true); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | die(); |
@@ -167,34 +167,34 @@ discard block |
||
167 | 167 | public static function get_billing_details() { |
168 | 168 | |
169 | 169 | // Verify nonce. |
170 | - check_ajax_referer( 'wpinv-nonce' ); |
|
170 | + check_ajax_referer('wpinv-nonce'); |
|
171 | 171 | |
172 | 172 | // Can the user manage the plugin? |
173 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
173 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
174 | 174 | die(-1); |
175 | 175 | } |
176 | 176 | |
177 | 177 | // Do we have a user id? |
178 | 178 | $user_id = $_GET['user_id']; |
179 | 179 | |
180 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
180 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
181 | 181 | die(-1); |
182 | 182 | } |
183 | 183 | |
184 | 184 | // Fetch the billing details. |
185 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
186 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
185 | + $billing_details = wpinv_get_user_address($user_id); |
|
186 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
187 | 187 | |
188 | 188 | // unset the user id and email. |
189 | - $to_ignore = array( 'user_id', 'email' ); |
|
189 | + $to_ignore = array('user_id', 'email'); |
|
190 | 190 | |
191 | - foreach ( $to_ignore as $key ) { |
|
192 | - if ( isset( $billing_details[ $key ] ) ) { |
|
193 | - unset( $billing_details[ $key ] ); |
|
191 | + foreach ($to_ignore as $key) { |
|
192 | + if (isset($billing_details[$key])) { |
|
193 | + unset($billing_details[$key]); |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | |
197 | - wp_send_json_success( $billing_details ); |
|
197 | + wp_send_json_success($billing_details); |
|
198 | 198 | |
199 | 199 | } |
200 | 200 | |
@@ -204,47 +204,47 @@ discard block |
||
204 | 204 | public static function check_new_user_email() { |
205 | 205 | |
206 | 206 | // Verify nonce. |
207 | - check_ajax_referer( 'wpinv-nonce' ); |
|
207 | + check_ajax_referer('wpinv-nonce'); |
|
208 | 208 | |
209 | 209 | // Can the user manage the plugin? |
210 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
210 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
211 | 211 | die(-1); |
212 | 212 | } |
213 | 213 | |
214 | 214 | // We need an email address. |
215 | - if ( empty( $_GET['email'] ) ) { |
|
216 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
215 | + if (empty($_GET['email'])) { |
|
216 | + _e("Provide the new user's email address", 'invoicing'); |
|
217 | 217 | exit; |
218 | 218 | } |
219 | 219 | |
220 | 220 | // Ensure the email is valid. |
221 | - $email = sanitize_text_field( $_GET['email'] ); |
|
222 | - if ( ! is_email( $email ) ) { |
|
223 | - _e( 'Invalid email address', 'invoicing' ); |
|
221 | + $email = sanitize_text_field($_GET['email']); |
|
222 | + if (!is_email($email)) { |
|
223 | + _e('Invalid email address', 'invoicing'); |
|
224 | 224 | exit; |
225 | 225 | } |
226 | 226 | |
227 | 227 | // And it does not exist. |
228 | - if ( email_exists( $email ) ) { |
|
229 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
228 | + if (email_exists($email)) { |
|
229 | + _e('A user with this email address already exists', 'invoicing'); |
|
230 | 230 | exit; |
231 | 231 | } |
232 | 232 | |
233 | - wp_send_json_success( true ); |
|
233 | + wp_send_json_success(true); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | public static function run_tool() { |
237 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
238 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
237 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
238 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
239 | 239 | die(-1); |
240 | 240 | } |
241 | 241 | |
242 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
242 | + $tool = sanitize_text_field($_POST['tool']); |
|
243 | 243 | |
244 | - do_action( 'wpinv_run_tool' ); |
|
244 | + do_action('wpinv_run_tool'); |
|
245 | 245 | |
246 | - if ( !empty( $tool ) ) { |
|
247 | - do_action( 'wpinv_tool_' . $tool ); |
|
246 | + if (!empty($tool)) { |
|
247 | + do_action('wpinv_tool_' . $tool); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | |
@@ -254,30 +254,30 @@ discard block |
||
254 | 254 | public static function get_payment_form() { |
255 | 255 | |
256 | 256 | // Check nonce. |
257 | - if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) { |
|
258 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
257 | + if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) { |
|
258 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
259 | 259 | exit; |
260 | 260 | } |
261 | 261 | |
262 | 262 | // Is the request set up correctly? |
263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
263 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
264 | 264 | echo aui()->alert( |
265 | 265 | array( |
266 | 266 | 'type' => 'warning', |
267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
267 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
268 | 268 | ) |
269 | 269 | ); |
270 | 270 | exit; |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Payment form or button? |
274 | - if ( ! empty( $_GET['form'] ) ) { |
|
275 | - getpaid_display_payment_form( $_GET['form'] ); |
|
276 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
277 | - echo getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
274 | + if (!empty($_GET['form'])) { |
|
275 | + getpaid_display_payment_form($_GET['form']); |
|
276 | + } else if (!empty($_GET['invoice'])) { |
|
277 | + echo getpaid_display_invoice_payment_form($_GET['invoice']); |
|
278 | 278 | } else { |
279 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
280 | - getpaid_display_item_payment_form( $items ); |
|
279 | + $items = getpaid_convert_items_to_array($_GET['item']); |
|
280 | + getpaid_display_item_payment_form($items); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | exit; |
@@ -292,17 +292,17 @@ discard block |
||
292 | 292 | public static function payment_form() { |
293 | 293 | |
294 | 294 | // Check nonce. |
295 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
295 | + check_ajax_referer('getpaid_form_nonce'); |
|
296 | 296 | |
297 | 297 | // ... form fields... |
298 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
299 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
298 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
299 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
300 | 300 | exit; |
301 | 301 | } |
302 | 302 | |
303 | 303 | // Process the payment form. |
304 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
305 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
304 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
305 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
306 | 306 | $checkout->process_checkout(); |
307 | 307 | |
308 | 308 | exit; |
@@ -316,51 +316,51 @@ discard block |
||
316 | 316 | public static function get_payment_form_states_field() { |
317 | 317 | global $invoicing; |
318 | 318 | |
319 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
319 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
320 | 320 | exit; |
321 | 321 | } |
322 | 322 | |
323 | - $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] ); |
|
323 | + $elements = $invoicing->form_elements->get_form_elements($_GET['form']); |
|
324 | 324 | |
325 | - if ( empty( $elements ) ) { |
|
325 | + if (empty($elements)) { |
|
326 | 326 | exit; |
327 | 327 | } |
328 | 328 | |
329 | 329 | $address_fields = array(); |
330 | - foreach ( $elements as $element ) { |
|
331 | - if ( 'address' === $element['type'] ) { |
|
330 | + foreach ($elements as $element) { |
|
331 | + if ('address' === $element['type']) { |
|
332 | 332 | $address_fields = $element; |
333 | 333 | break; |
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
337 | - if ( empty( $address_fields ) ) { |
|
337 | + if (empty($address_fields)) { |
|
338 | 338 | exit; |
339 | 339 | } |
340 | 340 | |
341 | - foreach( $address_fields['fields'] as $address_field ) { |
|
341 | + foreach ($address_fields['fields'] as $address_field) { |
|
342 | 342 | |
343 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
343 | + if ('wpinv_state' == $address_field['name']) { |
|
344 | 344 | |
345 | 345 | $label = $address_field['label']; |
346 | 346 | |
347 | - if ( ! empty( $address_field['required'] ) ) { |
|
347 | + if (!empty($address_field['required'])) { |
|
348 | 348 | $label .= "<span class='text-danger'> *</span>"; |
349 | 349 | } |
350 | 350 | |
351 | - $states = wpinv_get_country_states( $_GET['country'] ); |
|
351 | + $states = wpinv_get_country_states($_GET['country']); |
|
352 | 352 | |
353 | - if ( ! empty( $states ) ) { |
|
353 | + if (!empty($states)) { |
|
354 | 354 | |
355 | 355 | $html = aui()->select( |
356 | 356 | array( |
357 | 357 | 'options' => $states, |
358 | - 'name' => esc_attr( $address_field['name'] ), |
|
359 | - 'id' => esc_attr( $address_field['name'] ), |
|
360 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
358 | + 'name' => esc_attr($address_field['name']), |
|
359 | + 'id' => esc_attr($address_field['name']), |
|
360 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
361 | 361 | 'required' => (bool) $address_field['required'], |
362 | 362 | 'no_wrap' => true, |
363 | - 'label' => wp_kses_post( $label ), |
|
363 | + 'label' => wp_kses_post($label), |
|
364 | 364 | 'select2' => false, |
365 | 365 | ) |
366 | 366 | ); |
@@ -369,10 +369,10 @@ discard block |
||
369 | 369 | |
370 | 370 | $html = aui()->input( |
371 | 371 | array( |
372 | - 'name' => esc_attr( $address_field['name'] ), |
|
373 | - 'id' => esc_attr( $address_field['name'] ), |
|
372 | + 'name' => esc_attr($address_field['name']), |
|
373 | + 'id' => esc_attr($address_field['name']), |
|
374 | 374 | 'required' => (bool) $address_field['required'], |
375 | - 'label' => wp_kses_post( $label ), |
|
375 | + 'label' => wp_kses_post($label), |
|
376 | 376 | 'no_wrap' => true, |
377 | 377 | 'type' => 'text', |
378 | 378 | ) |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | |
381 | 381 | } |
382 | 382 | |
383 | - wp_send_json_success( str_replace( 'sr-only', '', $html ) ); |
|
383 | + wp_send_json_success(str_replace('sr-only', '', $html)); |
|
384 | 384 | exit; |
385 | 385 | |
386 | 386 | } |
@@ -396,56 +396,56 @@ discard block |
||
396 | 396 | public static function recalculate_invoice_totals() { |
397 | 397 | |
398 | 398 | // Verify nonce. |
399 | - check_ajax_referer( 'wpinv-nonce' ); |
|
399 | + check_ajax_referer('wpinv-nonce'); |
|
400 | 400 | |
401 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
401 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
402 | 402 | exit; |
403 | 403 | } |
404 | 404 | |
405 | 405 | // We need an invoice. |
406 | - if ( empty( $_POST['post_id'] ) ) { |
|
406 | + if (empty($_POST['post_id'])) { |
|
407 | 407 | exit; |
408 | 408 | } |
409 | 409 | |
410 | 410 | // Fetch the invoice. |
411 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
411 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
412 | 412 | |
413 | 413 | // Ensure it exists. |
414 | - if ( ! $invoice->get_id() ) { |
|
414 | + if (!$invoice->get_id()) { |
|
415 | 415 | exit; |
416 | 416 | } |
417 | 417 | |
418 | 418 | // Maybe set the country, state, currency. |
419 | - foreach ( array( 'country', 'state', 'currency' ) as $key ) { |
|
420 | - if ( isset( $_POST[ $key ] ) ) { |
|
419 | + foreach (array('country', 'state', 'currency') as $key) { |
|
420 | + if (isset($_POST[$key])) { |
|
421 | 421 | $method = "set_$key"; |
422 | - $invoice->$method( $_POST[ $key ] ); |
|
422 | + $invoice->$method($_POST[$key]); |
|
423 | 423 | } |
424 | 424 | } |
425 | 425 | |
426 | 426 | // Maybe disable taxes. |
427 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
427 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
428 | 428 | |
429 | 429 | // Recalculate totals. |
430 | 430 | $invoice->recalculate_total(); |
431 | 431 | |
432 | - $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ); |
|
432 | + $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()); |
|
433 | 433 | |
434 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
435 | - $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() ); |
|
436 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
434 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
435 | + $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency()); |
|
436 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | $totals = array( |
440 | - 'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ), |
|
441 | - 'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ), |
|
442 | - 'tax' => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ), |
|
440 | + 'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()), |
|
441 | + 'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()), |
|
442 | + 'tax' => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()), |
|
443 | 443 | 'total' => $total, |
444 | 444 | ); |
445 | 445 | |
446 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
446 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
447 | 447 | |
448 | - wp_send_json_success( compact( 'totals' ) ); |
|
448 | + wp_send_json_success(compact('totals')); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -454,33 +454,33 @@ discard block |
||
454 | 454 | public static function get_invoice_items() { |
455 | 455 | |
456 | 456 | // Verify nonce. |
457 | - check_ajax_referer( 'wpinv-nonce' ); |
|
457 | + check_ajax_referer('wpinv-nonce'); |
|
458 | 458 | |
459 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
459 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
460 | 460 | exit; |
461 | 461 | } |
462 | 462 | |
463 | 463 | // We need an invoice and items. |
464 | - if ( empty( $_POST['post_id'] ) ) { |
|
464 | + if (empty($_POST['post_id'])) { |
|
465 | 465 | exit; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Fetch the invoice. |
469 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
469 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
470 | 470 | |
471 | 471 | // Ensure it exists. |
472 | - if ( ! $invoice->get_id() ) { |
|
472 | + if (!$invoice->get_id()) { |
|
473 | 473 | exit; |
474 | 474 | } |
475 | 475 | |
476 | 476 | // Return an array of invoice items. |
477 | 477 | $items = array(); |
478 | 478 | |
479 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
480 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
479 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
480 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
481 | 481 | } |
482 | 482 | |
483 | - wp_send_json_success( compact( 'items' ) ); |
|
483 | + wp_send_json_success(compact('items')); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -489,50 +489,50 @@ discard block |
||
489 | 489 | public static function edit_invoice_item() { |
490 | 490 | |
491 | 491 | // Verify nonce. |
492 | - check_ajax_referer( 'wpinv-nonce' ); |
|
492 | + check_ajax_referer('wpinv-nonce'); |
|
493 | 493 | |
494 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
494 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
495 | 495 | exit; |
496 | 496 | } |
497 | 497 | |
498 | 498 | // We need an invoice and item details. |
499 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
499 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
500 | 500 | exit; |
501 | 501 | } |
502 | 502 | |
503 | 503 | // Fetch the invoice. |
504 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
504 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
505 | 505 | |
506 | 506 | // Ensure it exists and its not been paid for. |
507 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
507 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
508 | 508 | exit; |
509 | 509 | } |
510 | 510 | |
511 | 511 | // Format the data. |
512 | - $data = wp_list_pluck( $_POST['data'], 'value', 'field' ); |
|
512 | + $data = wp_list_pluck($_POST['data'], 'value', 'field'); |
|
513 | 513 | |
514 | 514 | // Ensure that we have an item id. |
515 | - if ( empty( $data['id'] ) ) { |
|
515 | + if (empty($data['id'])) { |
|
516 | 516 | exit; |
517 | 517 | } |
518 | 518 | |
519 | 519 | // Abort if the invoice does not have the specified item. |
520 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
520 | + $item = $invoice->get_item((int) $data['id']); |
|
521 | 521 | |
522 | - if ( empty( $item ) ) { |
|
522 | + if (empty($item)) { |
|
523 | 523 | exit; |
524 | 524 | } |
525 | 525 | |
526 | 526 | // Update the item. |
527 | - $item->set_price( $data['price'] ); |
|
528 | - $item->set_name( $data['name'] ); |
|
529 | - $item->set_description( $data['description'] ); |
|
530 | - $item->set_quantity( $data['quantity'] ); |
|
527 | + $item->set_price($data['price']); |
|
528 | + $item->set_name($data['name']); |
|
529 | + $item->set_description($data['description']); |
|
530 | + $item->set_quantity($data['quantity']); |
|
531 | 531 | |
532 | 532 | // Add it to the invoice. |
533 | - $error = $invoice->add_item( $item ); |
|
533 | + $error = $invoice->add_item($item); |
|
534 | 534 | $alert = false; |
535 | - if ( is_wp_error( $error ) ) { |
|
535 | + if (is_wp_error($error)) { |
|
536 | 536 | $alert = $error->get_error_message(); |
537 | 537 | } |
538 | 538 | |
@@ -545,11 +545,11 @@ discard block |
||
545 | 545 | // Return an array of invoice items. |
546 | 546 | $items = array(); |
547 | 547 | |
548 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
549 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
548 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
549 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
550 | 550 | } |
551 | 551 | |
552 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
552 | + wp_send_json_success(compact('items', 'alert')); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -558,33 +558,33 @@ discard block |
||
558 | 558 | public static function remove_invoice_item() { |
559 | 559 | |
560 | 560 | // Verify nonce. |
561 | - check_ajax_referer( 'wpinv-nonce' ); |
|
561 | + check_ajax_referer('wpinv-nonce'); |
|
562 | 562 | |
563 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
563 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
564 | 564 | exit; |
565 | 565 | } |
566 | 566 | |
567 | 567 | // We need an invoice and an item. |
568 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
568 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
569 | 569 | exit; |
570 | 570 | } |
571 | 571 | |
572 | 572 | // Fetch the invoice. |
573 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
573 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
574 | 574 | |
575 | 575 | // Ensure it exists and its not been paid for. |
576 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
576 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
577 | 577 | exit; |
578 | 578 | } |
579 | 579 | |
580 | 580 | // Abort if the invoice does not have the specified item. |
581 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
581 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
582 | 582 | |
583 | - if ( empty( $item ) ) { |
|
583 | + if (empty($item)) { |
|
584 | 584 | exit; |
585 | 585 | } |
586 | 586 | |
587 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
587 | + $invoice->remove_item((int) $_POST['item_id']); |
|
588 | 588 | |
589 | 589 | // Update totals. |
590 | 590 | $invoice->recalculate_total(); |
@@ -595,11 +595,11 @@ discard block |
||
595 | 595 | // Return an array of invoice items. |
596 | 596 | $items = array(); |
597 | 597 | |
598 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
599 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
598 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
599 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
600 | 600 | } |
601 | 601 | |
602 | - wp_send_json_success( compact( 'items' ) ); |
|
602 | + wp_send_json_success(compact('items')); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
@@ -608,39 +608,39 @@ discard block |
||
608 | 608 | public static function add_invoice_items() { |
609 | 609 | |
610 | 610 | // Verify nonce. |
611 | - check_ajax_referer( 'wpinv-nonce' ); |
|
611 | + check_ajax_referer('wpinv-nonce'); |
|
612 | 612 | |
613 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
613 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
614 | 614 | exit; |
615 | 615 | } |
616 | 616 | |
617 | 617 | // We need an invoice and items. |
618 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
618 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
619 | 619 | exit; |
620 | 620 | } |
621 | 621 | |
622 | 622 | // Fetch the invoice. |
623 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
623 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
624 | 624 | $alert = false; |
625 | 625 | |
626 | 626 | // Ensure it exists and its not been paid for. |
627 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
627 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
628 | 628 | exit; |
629 | 629 | } |
630 | 630 | |
631 | 631 | // Add the items. |
632 | - foreach ( $_POST['items'] as $data ) { |
|
632 | + foreach ($_POST['items'] as $data) { |
|
633 | 633 | |
634 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
634 | + $item = new GetPaid_Form_Item($data['id']); |
|
635 | 635 | |
636 | - if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) { |
|
637 | - $item->set_quantity( $data[ 'qty' ] ); |
|
636 | + if (is_numeric($data['qty']) && (int) $data['qty'] > 0) { |
|
637 | + $item->set_quantity($data['qty']); |
|
638 | 638 | } |
639 | 639 | |
640 | - if ( $item->get_id() > 0 ) { |
|
641 | - $error = $invoice->add_item( $item ); |
|
640 | + if ($item->get_id() > 0) { |
|
641 | + $error = $invoice->add_item($item); |
|
642 | 642 | |
643 | - if ( is_wp_error( $error ) ) { |
|
643 | + if (is_wp_error($error)) { |
|
644 | 644 | $alert = $error->get_error_message(); |
645 | 645 | } |
646 | 646 | |
@@ -655,11 +655,11 @@ discard block |
||
655 | 655 | // Return an array of invoice items. |
656 | 656 | $items = array(); |
657 | 657 | |
658 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
659 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
658 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
659 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
660 | 660 | } |
661 | 661 | |
662 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
662 | + wp_send_json_success(compact('items', 'alert')); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | /** |
@@ -668,15 +668,15 @@ discard block |
||
668 | 668 | public static function get_invoicing_items() { |
669 | 669 | |
670 | 670 | // Verify nonce. |
671 | - check_ajax_referer( 'wpinv-nonce' ); |
|
671 | + check_ajax_referer('wpinv-nonce'); |
|
672 | 672 | |
673 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
673 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
674 | 674 | exit; |
675 | 675 | } |
676 | 676 | |
677 | 677 | // We need a search term. |
678 | - if ( empty( $_GET['search'] ) ) { |
|
679 | - wp_send_json_success( array() ); |
|
678 | + if (empty($_GET['search'])) { |
|
679 | + wp_send_json_success(array()); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | // Retrieve items. |
@@ -685,8 +685,8 @@ discard block |
||
685 | 685 | 'orderby' => 'title', |
686 | 686 | 'order' => 'ASC', |
687 | 687 | 'posts_per_page' => -1, |
688 | - 'post_status' => array( 'publish' ), |
|
689 | - 's' => trim( $_GET['search'] ), |
|
688 | + 'post_status' => array('publish'), |
|
689 | + 's' => trim($_GET['search']), |
|
690 | 690 | 'meta_query' => array( |
691 | 691 | array( |
692 | 692 | 'key' => '_wpinv_type', |
@@ -696,14 +696,14 @@ discard block |
||
696 | 696 | ) |
697 | 697 | ); |
698 | 698 | |
699 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
699 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
700 | 700 | $data = array(); |
701 | 701 | |
702 | 702 | |
703 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
703 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
704 | 704 | |
705 | - foreach ( $items as $item ) { |
|
706 | - $item = new GetPaid_Form_Item( $item ); |
|
705 | + foreach ($items as $item) { |
|
706 | + $item = new GetPaid_Form_Item($item); |
|
707 | 707 | $data[] = array( |
708 | 708 | 'id' => $item->get_id(), |
709 | 709 | 'text' => $item->get_name(), |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | ); |
712 | 712 | } |
713 | 713 | |
714 | - wp_send_json_success( $data ); |
|
714 | + wp_send_json_success($data); |
|
715 | 715 | |
716 | 716 | } |
717 | 717 | |
@@ -721,24 +721,24 @@ discard block |
||
721 | 721 | public static function get_aui_states_field() { |
722 | 722 | |
723 | 723 | // Verify nonce. |
724 | - check_ajax_referer( 'wpinv-nonce' ); |
|
724 | + check_ajax_referer('wpinv-nonce'); |
|
725 | 725 | |
726 | 726 | // We need a country. |
727 | - if ( empty( $_GET['country'] ) ) { |
|
727 | + if (empty($_GET['country'])) { |
|
728 | 728 | exit; |
729 | 729 | } |
730 | 730 | |
731 | - $states = wpinv_get_country_states( trim( $_GET['country'] ) ); |
|
732 | - $state = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state(); |
|
731 | + $states = wpinv_get_country_states(trim($_GET['country'])); |
|
732 | + $state = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state(); |
|
733 | 733 | |
734 | - if ( empty( $states ) ) { |
|
734 | + if (empty($states)) { |
|
735 | 735 | |
736 | 736 | $html = aui()->input( |
737 | 737 | array( |
738 | 738 | 'type' => 'text', |
739 | 739 | 'id' => 'wpinv_state', |
740 | 740 | 'name' => 'wpinv_state', |
741 | - 'label' => __( 'State', 'invoicing' ), |
|
741 | + 'label' => __('State', 'invoicing'), |
|
742 | 742 | 'label_type' => 'vertical', |
743 | 743 | 'placeholder' => 'Liège', |
744 | 744 | 'class' => 'form-control-sm', |
@@ -752,9 +752,9 @@ discard block |
||
752 | 752 | array( |
753 | 753 | 'id' => 'wpinv_state', |
754 | 754 | 'name' => 'wpinv_state', |
755 | - 'label' => __( 'State', 'invoicing' ), |
|
755 | + 'label' => __('State', 'invoicing'), |
|
756 | 756 | 'label_type' => 'vertical', |
757 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
757 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
758 | 758 | 'class' => 'form-control-sm', |
759 | 759 | 'value' => $state, |
760 | 760 | 'options' => $states, |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | wp_send_json_success( |
769 | 769 | array( |
770 | 770 | 'html' => $html, |
771 | - 'select' => ! empty ( $states ) |
|
771 | + 'select' => !empty ($states) |
|
772 | 772 | ) |
773 | 773 | ); |
774 | 774 | |
@@ -782,46 +782,46 @@ discard block |
||
782 | 782 | public static function ip_geolocation() { |
783 | 783 | |
784 | 784 | // Check nonce. |
785 | - check_ajax_referer( 'getpaid-ip-location' ); |
|
785 | + check_ajax_referer('getpaid-ip-location'); |
|
786 | 786 | |
787 | 787 | // IP address. |
788 | - if ( empty( $_GET['ip'] ) || ! rest_is_ip_address( $_GET['ip'] ) ) { |
|
789 | - _e( 'Invalid IP Address.', 'invoicing' ); |
|
788 | + if (empty($_GET['ip']) || !rest_is_ip_address($_GET['ip'])) { |
|
789 | + _e('Invalid IP Address.', 'invoicing'); |
|
790 | 790 | exit; |
791 | 791 | } |
792 | 792 | |
793 | 793 | // Retrieve location info. |
794 | - $location = getpaid_geolocate_ip_address( $_GET['ip'] ); |
|
794 | + $location = getpaid_geolocate_ip_address($_GET['ip']); |
|
795 | 795 | |
796 | - if ( empty( $location ) ) { |
|
797 | - _e( 'Unable to find geolocation for the IP Address.', 'invoicing' ); |
|
796 | + if (empty($location)) { |
|
797 | + _e('Unable to find geolocation for the IP Address.', 'invoicing'); |
|
798 | 798 | exit; |
799 | 799 | } |
800 | 800 | |
801 | 801 | // Sorry. |
802 | - extract( $location ); |
|
802 | + extract($location); |
|
803 | 803 | |
804 | 804 | // Prepare the address. |
805 | 805 | $content = ''; |
806 | 806 | |
807 | - if ( ! empty( $location['city'] ) ) { |
|
808 | - $content .= $location['city'] . ', '; |
|
807 | + if (!empty($location['city'])) { |
|
808 | + $content .= $location['city'] . ', '; |
|
809 | 809 | } |
810 | 810 | |
811 | - if ( ! empty( $location['region'] ) ) { |
|
812 | - $content .= $location['region'] . ', '; |
|
811 | + if (!empty($location['region'])) { |
|
812 | + $content .= $location['region'] . ', '; |
|
813 | 813 | } |
814 | 814 | |
815 | - $content .= $location['country'] . ' (' . $location['iso'] . ')'; |
|
815 | + $content .= $location['country'] . ' (' . $location['iso'] . ')'; |
|
816 | 816 | |
817 | 817 | $location['address'] = $content; |
818 | 818 | |
819 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $content ) . '</p>'; |
|
820 | - $content .= '<p>'. $location['credit'] . '</p>'; |
|
819 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $content) . '</p>'; |
|
820 | + $content .= '<p>' . $location['credit'] . '</p>'; |
|
821 | 821 | |
822 | 822 | $location['content'] = $content; |
823 | 823 | |
824 | - wpinv_get_template( 'geolocation.php', $location ); |
|
824 | + wpinv_get_template('geolocation.php', $location); |
|
825 | 825 | |
826 | 826 | exit; |
827 | 827 | } |
@@ -834,11 +834,11 @@ discard block |
||
834 | 834 | public static function payment_form_refresh_prices() { |
835 | 835 | |
836 | 836 | // Check nonce. |
837 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
837 | + check_ajax_referer('getpaid_form_nonce'); |
|
838 | 838 | |
839 | 839 | // ... form fields... |
840 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
841 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
840 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
841 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
842 | 842 | exit; |
843 | 843 | } |
844 | 844 | |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | $submission = new GetPaid_Payment_Form_Submission(); |
847 | 847 | |
848 | 848 | // Do we have an error? |
849 | - if ( ! empty( $submission->last_error ) ) { |
|
849 | + if (!empty($submission->last_error)) { |
|
850 | 850 | echo $submission->last_error; |
851 | 851 | exit; |
852 | 852 | } |
@@ -859,43 +859,43 @@ discard block |
||
859 | 859 | 'is_free' => $submission->get_payment_details(), |
860 | 860 | |
861 | 861 | 'totals' => array( |
862 | - 'subtotal' => wpinv_price( wpinv_format_amount( $submission->subtotal_amount ), $submission->get_currency() ), |
|
863 | - 'discount' => wpinv_price( wpinv_format_amount( $submission->get_total_discount() ), $submission->get_currency() ), |
|
864 | - 'fees' => wpinv_price( wpinv_format_amount( $submission->get_total_fees() ), $submission->get_currency() ), |
|
865 | - 'tax' => wpinv_price( wpinv_format_amount( $submission->get_total_tax() ), $submission->get_currency() ), |
|
866 | - 'total' => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ), |
|
862 | + 'subtotal' => wpinv_price(wpinv_format_amount($submission->subtotal_amount), $submission->get_currency()), |
|
863 | + 'discount' => wpinv_price(wpinv_format_amount($submission->get_total_discount()), $submission->get_currency()), |
|
864 | + 'fees' => wpinv_price(wpinv_format_amount($submission->get_total_fees()), $submission->get_currency()), |
|
865 | + 'tax' => wpinv_price(wpinv_format_amount($submission->get_total_tax()), $submission->get_currency()), |
|
866 | + 'total' => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()), |
|
867 | 867 | ), |
868 | 868 | |
869 | 869 | 'texts' => array( |
870 | - '.getpaid-checkout-total-payable' => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ), |
|
870 | + '.getpaid-checkout-total-payable' => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()), |
|
871 | 871 | ) |
872 | 872 | |
873 | 873 | ); |
874 | 874 | |
875 | 875 | // Add items. |
876 | 876 | $items = $submission->get_items(); |
877 | - if ( ! empty( $items ) ) { |
|
877 | + if (!empty($items)) { |
|
878 | 878 | $result['items'] = array(); |
879 | 879 | |
880 | - foreach( $items as $item_id => $item ) { |
|
881 | - $result['items']["$item_id"] = wpinv_price( wpinv_format_amount( $item->get_price() * $item->get_quantity() ) ); |
|
880 | + foreach ($items as $item_id => $item) { |
|
881 | + $result['items']["$item_id"] = wpinv_price(wpinv_format_amount($item->get_price() * $item->get_quantity())); |
|
882 | 882 | } |
883 | 883 | } |
884 | 884 | |
885 | 885 | // Add invoice. |
886 | - if ( $submission->has_invoice() ) { |
|
886 | + if ($submission->has_invoice()) { |
|
887 | 887 | $result['invoice'] = $submission->get_invoice()->ID; |
888 | 888 | } |
889 | 889 | |
890 | 890 | // Add discount code. |
891 | - if ( $submission->has_discount_code() ) { |
|
891 | + if ($submission->has_discount_code()) { |
|
892 | 892 | $result['discount_code'] = $submission->get_discount_code(); |
893 | 893 | } |
894 | 894 | |
895 | 895 | // Filter the result. |
896 | - $result = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $result, $submission ); |
|
896 | + $result = apply_filters('getpaid_payment_form_ajax_refresh_prices', $result, $submission); |
|
897 | 897 | |
898 | - wp_send_json_success( $result ); |
|
898 | + wp_send_json_success($result); |
|
899 | 899 | } |
900 | 900 | |
901 | 901 | /** |
@@ -906,53 +906,53 @@ discard block |
||
906 | 906 | public static function buy_items() { |
907 | 907 | $user_id = get_current_user_id(); |
908 | 908 | |
909 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
910 | - wp_send_json( array( |
|
911 | - 'success' => wp_login_url( wp_get_referer() ) |
|
912 | - ) ); |
|
909 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
910 | + wp_send_json(array( |
|
911 | + 'success' => wp_login_url(wp_get_referer()) |
|
912 | + )); |
|
913 | 913 | } else { |
914 | 914 | // Only check nonce if logged in as it could be cached when logged out. |
915 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
916 | - wp_send_json( array( |
|
917 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
918 | - ) ); |
|
915 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
916 | + wp_send_json(array( |
|
917 | + 'error' => __('Security checks failed.', 'invoicing') |
|
918 | + )); |
|
919 | 919 | wp_die(); |
920 | 920 | } |
921 | 921 | |
922 | 922 | // allow to set a custom price through post_id |
923 | 923 | $items = $_POST['items']; |
924 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
925 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
924 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
925 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
926 | 926 | |
927 | 927 | $cart_items = array(); |
928 | - if ( $items ) { |
|
929 | - $items = explode( ',', $items ); |
|
928 | + if ($items) { |
|
929 | + $items = explode(',', $items); |
|
930 | 930 | |
931 | - foreach( $items as $item ) { |
|
931 | + foreach ($items as $item) { |
|
932 | 932 | $item_id = $item; |
933 | 933 | $quantity = 1; |
934 | 934 | |
935 | - if ( strpos( $item, '|' ) !== false ) { |
|
936 | - $item_parts = explode( '|', $item ); |
|
935 | + if (strpos($item, '|') !== false) { |
|
936 | + $item_parts = explode('|', $item); |
|
937 | 937 | $item_id = $item_parts[0]; |
938 | 938 | $quantity = $item_parts[1]; |
939 | 939 | } |
940 | 940 | |
941 | - if ( $item_id && $quantity ) { |
|
941 | + if ($item_id && $quantity) { |
|
942 | 942 | $cart_items_arr = array( |
943 | - 'id' => (int)$item_id, |
|
944 | - 'quantity' => (int)$quantity |
|
943 | + 'id' => (int) $item_id, |
|
944 | + 'quantity' => (int) $quantity |
|
945 | 945 | ); |
946 | 946 | |
947 | 947 | // If there is a related post id then add it to meta |
948 | - if ( $related_post_id ) { |
|
948 | + if ($related_post_id) { |
|
949 | 949 | $cart_items_arr['meta'] = array( |
950 | 950 | 'post_id' => $related_post_id |
951 | 951 | ); |
952 | 952 | } |
953 | 953 | |
954 | 954 | // If there is a custom price then set it. |
955 | - if ( $custom_item_price ) { |
|
955 | + if ($custom_item_price) { |
|
956 | 956 | $cart_items_arr['custom_price'] = $custom_item_price; |
957 | 957 | } |
958 | 958 | |
@@ -968,37 +968,37 @@ discard block |
||
968 | 968 | * @param int $related_post_id The related post id if any. |
969 | 969 | * @since 1.0.0 |
970 | 970 | */ |
971 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
971 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
972 | 972 | |
973 | 973 | // Make sure its not in the cart already, if it is then redirect to checkout. |
974 | 974 | $cart_invoice = wpinv_get_invoice_cart(); |
975 | 975 | |
976 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
977 | - wp_send_json( array( |
|
976 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
977 | + wp_send_json(array( |
|
978 | 978 | 'success' => $cart_invoice->get_checkout_payment_url() |
979 | - ) ); |
|
979 | + )); |
|
980 | 980 | wp_die(); |
981 | 981 | } |
982 | 982 | |
983 | 983 | // Check if user has invoice with same items waiting to be paid. |
984 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
985 | - if ( !empty( $user_invoices ) ) { |
|
986 | - foreach( $user_invoices as $user_invoice ) { |
|
984 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
985 | + if (!empty($user_invoices)) { |
|
986 | + foreach ($user_invoices as $user_invoice) { |
|
987 | 987 | $user_cart_details = array(); |
988 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
988 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
989 | 989 | $cart_details = $invoice->get_cart_details(); |
990 | 990 | |
991 | - if ( !empty( $cart_details ) ) { |
|
992 | - foreach ( $cart_details as $invoice_item ) { |
|
991 | + if (!empty($cart_details)) { |
|
992 | + foreach ($cart_details as $invoice_item) { |
|
993 | 993 | $ii_arr = array(); |
994 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
995 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
994 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
995 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
996 | 996 | |
997 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
997 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
998 | 998 | $ii_arr['meta'] = $invoice_item['meta']; |
999 | 999 | } |
1000 | 1000 | |
1001 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
1001 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
1002 | 1002 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
1003 | 1003 | } |
1004 | 1004 | |
@@ -1006,17 +1006,17 @@ discard block |
||
1006 | 1006 | } |
1007 | 1007 | } |
1008 | 1008 | |
1009 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
1010 | - wp_send_json( array( |
|
1009 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
1010 | + wp_send_json(array( |
|
1011 | 1011 | 'success' => $invoice->get_checkout_payment_url() |
1012 | - ) ); |
|
1012 | + )); |
|
1013 | 1013 | wp_die(); |
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | // Create invoice and send user to checkout |
1019 | - if ( !empty( $cart_items ) ) { |
|
1019 | + if (!empty($cart_items)) { |
|
1020 | 1020 | $invoice_data = array( |
1021 | 1021 | 'status' => 'wpi-pending', |
1022 | 1022 | 'created_via' => 'wpi', |
@@ -1024,21 +1024,21 @@ discard block |
||
1024 | 1024 | 'cart_details' => $cart_items, |
1025 | 1025 | ); |
1026 | 1026 | |
1027 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
1027 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
1028 | 1028 | |
1029 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
1030 | - wp_send_json( array( |
|
1029 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
1030 | + wp_send_json(array( |
|
1031 | 1031 | 'success' => $invoice->get_checkout_payment_url() |
1032 | - ) ); |
|
1032 | + )); |
|
1033 | 1033 | } else { |
1034 | - wp_send_json( array( |
|
1035 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
1036 | - ) ); |
|
1034 | + wp_send_json(array( |
|
1035 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
1036 | + )); |
|
1037 | 1037 | } |
1038 | 1038 | } else { |
1039 | - wp_send_json( array( |
|
1040 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
1041 | - ) ); |
|
1039 | + wp_send_json(array( |
|
1040 | + 'error' => __('Items not valid.', 'invoicing') |
|
1041 | + )); |
|
1042 | 1042 | } |
1043 | 1043 | } |
1044 | 1044 |
@@ -14,62 +14,62 @@ discard block |
||
14 | 14 | class GetPaid_Admin { |
15 | 15 | |
16 | 16 | /** |
17 | - * Local path to this plugins admin directory |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $admin_path; |
|
22 | - |
|
23 | - /** |
|
24 | - * Web path to this plugins admin directory |
|
25 | - * |
|
26 | - * @var string |
|
27 | - */ |
|
17 | + * Local path to this plugins admin directory |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $admin_path; |
|
22 | + |
|
23 | + /** |
|
24 | + * Web path to this plugins admin directory |
|
25 | + * |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | public $admin_url; |
29 | 29 | |
30 | 30 | /** |
31 | - * Class constructor. |
|
32 | - */ |
|
33 | - public function __construct(){ |
|
31 | + * Class constructor. |
|
32 | + */ |
|
33 | + public function __construct(){ |
|
34 | 34 | |
35 | 35 | $this->admin_path = plugin_dir_path( __FILE__ ); |
36 | 36 | $this->admin_url = plugins_url( '/', __FILE__ ); |
37 | 37 | |
38 | 38 | if ( is_admin() ) { |
39 | - $this->init_admin_hooks(); |
|
39 | + $this->init_admin_hooks(); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | - * Init action and filter hooks |
|
46 | - * |
|
47 | - */ |
|
48 | - private function init_admin_hooks() { |
|
45 | + * Init action and filter hooks |
|
46 | + * |
|
47 | + */ |
|
48 | + private function init_admin_hooks() { |
|
49 | 49 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
50 | 50 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
51 | 51 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
52 | 52 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
53 | 53 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
54 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
54 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | - * Register admin scripts |
|
63 | - * |
|
64 | - */ |
|
65 | - public function enqeue_scripts() { |
|
62 | + * Register admin scripts |
|
63 | + * |
|
64 | + */ |
|
65 | + public function enqeue_scripts() { |
|
66 | 66 | global $current_screen, $pagenow; |
67 | 67 | |
68 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
69 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
68 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
69 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
70 | 70 | |
71 | 71 | if ( ! empty( $current_screen->post_type ) ) { |
72 | - $page = $current_screen->post_type; |
|
72 | + $page = $current_screen->post_type; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // General styles. |
@@ -93,30 +93,30 @@ discard block |
||
93 | 93 | } |
94 | 94 | |
95 | 95 | // Payment form scripts. |
96 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
96 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
97 | 97 | $this->load_payment_form_scripts(); |
98 | 98 | } |
99 | 99 | |
100 | 100 | if ( $page == 'wpinv-subscriptions' ) { |
101 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
103 | - } |
|
101 | + wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | + wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
103 | + } |
|
104 | 104 | |
105 | - if ( $page == 'wpinv-reports' ) { |
|
106 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
107 | - } |
|
105 | + if ( $page == 'wpinv-reports' ) { |
|
106 | + wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
107 | + } |
|
108 | 108 | |
109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
110 | - wp_enqueue_script( 'postbox' ); |
|
111 | - } |
|
109 | + if ( $page == 'wpinv-subscriptions' ) { |
|
110 | + wp_enqueue_script( 'postbox' ); |
|
111 | + } |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | - * Returns admin js translations. |
|
117 | - * |
|
118 | - */ |
|
119 | - protected function get_admin_i18() { |
|
116 | + * Returns admin js translations. |
|
117 | + * |
|
118 | + */ |
|
119 | + protected function get_admin_i18() { |
|
120 | 120 | global $post; |
121 | 121 | |
122 | 122 | return array( |
@@ -157,32 +157,32 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | - * Loads payment form js. |
|
161 | - * |
|
162 | - */ |
|
163 | - protected function load_payment_form_scripts() { |
|
160 | + * Loads payment form js. |
|
161 | + * |
|
162 | + */ |
|
163 | + protected function load_payment_form_scripts() { |
|
164 | 164 | global $post; |
165 | 165 | |
166 | 166 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
167 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
167 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
169 | 169 | |
170 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
170 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
172 | 172 | |
173 | - wp_localize_script( |
|
173 | + wp_localize_script( |
|
174 | 174 | 'wpinv-admin-payment-form-script', |
175 | 175 | 'wpinvPaymentFormAdmin', |
176 | 176 | array( |
177 | - 'elements' => getpaid()->form_elements->get_elements(), |
|
178 | - 'form_elements' => getpaid()->form_elements->get_form_elements( $post->ID ), |
|
179 | - 'currency' => wpinv_currency_symbol(), |
|
180 | - 'position' => wpinv_currency_position(), |
|
181 | - 'decimals' => (int) wpinv_decimals(), |
|
182 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
183 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
184 | - 'form_items' => getpaid()->form_elements->get_form_items( $post->ID ), |
|
185 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
177 | + 'elements' => getpaid()->form_elements->get_elements(), |
|
178 | + 'form_elements' => getpaid()->form_elements->get_form_elements( $post->ID ), |
|
179 | + 'currency' => wpinv_currency_symbol(), |
|
180 | + 'position' => wpinv_currency_position(), |
|
181 | + 'decimals' => (int) wpinv_decimals(), |
|
182 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
183 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
184 | + 'form_items' => getpaid()->form_elements->get_form_items( $post->ID ), |
|
185 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
186 | 186 | ) |
187 | 187 | ); |
188 | 188 | |
@@ -191,20 +191,20 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | - * Add our classes to admin pages. |
|
194 | + * Add our classes to admin pages. |
|
195 | 195 | * |
196 | 196 | * @param string $classes |
197 | 197 | * @return string |
198 | - * |
|
199 | - */ |
|
198 | + * |
|
199 | + */ |
|
200 | 200 | public function admin_body_class( $classes ) { |
201 | - global $pagenow, $post, $current_screen; |
|
201 | + global $pagenow, $post, $current_screen; |
|
202 | 202 | |
203 | 203 | |
204 | 204 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
205 | 205 | |
206 | 206 | if ( ! empty( $current_screen->post_type ) ) { |
207 | - $page = $current_screen->post_type; |
|
207 | + $page = $current_screen->post_type; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -215,27 +215,27 @@ discard block |
||
215 | 215 | $classes .= ' wpinv-cpt wpinv'; |
216 | 216 | } |
217 | 217 | |
218 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
219 | - $classes .= ' wpi-editable-n'; |
|
220 | - } |
|
218 | + if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
219 | + $classes .= ' wpi-editable-n'; |
|
220 | + } |
|
221 | 221 | |
222 | - return $classes; |
|
222 | + return $classes; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
226 | - * Maybe show the AyeCode Connect Notice. |
|
227 | - */ |
|
228 | - public function init_ayecode_connect_helper(){ |
|
226 | + * Maybe show the AyeCode Connect Notice. |
|
227 | + */ |
|
228 | + public function init_ayecode_connect_helper(){ |
|
229 | 229 | |
230 | 230 | new AyeCode_Connect_Helper( |
231 | 231 | array( |
232 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | - 'connect_button' => __("Connect Site","invoicing"), |
|
236 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
232 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | + 'connect_button' => __("Connect Site","invoicing"), |
|
236 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
239 | 239 | ), |
240 | 240 | array( 'wpi-addons' ) |
241 | 241 | ); |
@@ -247,21 +247,21 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function activation_redirect() { |
249 | 249 | |
250 | - // Bail if no activation redirect. |
|
251 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
252 | - return; |
|
253 | - } |
|
250 | + // Bail if no activation redirect. |
|
251 | + if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
252 | + return; |
|
253 | + } |
|
254 | 254 | |
255 | - // Delete the redirect transient. |
|
256 | - delete_transient( '_wpinv_activation_redirect' ); |
|
255 | + // Delete the redirect transient. |
|
256 | + delete_transient( '_wpinv_activation_redirect' ); |
|
257 | 257 | |
258 | - // Bail if activating from network, or bulk |
|
259 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
260 | - return; |
|
261 | - } |
|
258 | + // Bail if activating from network, or bulk |
|
259 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
260 | + return; |
|
261 | + } |
|
262 | 262 | |
263 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
264 | - exit; |
|
263 | + wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
264 | + exit; |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
@@ -276,150 +276,150 @@ discard block |
||
276 | 276 | |
277 | 277 | } |
278 | 278 | |
279 | - /** |
|
279 | + /** |
|
280 | 280 | * Sends a payment reminder to a customer. |
281 | - * |
|
282 | - * @param array $args |
|
281 | + * |
|
282 | + * @param array $args |
|
283 | 283 | */ |
284 | 284 | public function send_customer_invoice( $args ) { |
285 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
285 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
286 | 286 | |
287 | - if ( $sent ) { |
|
288 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
289 | - } else { |
|
290 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
291 | - } |
|
287 | + if ( $sent ) { |
|
288 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
289 | + } else { |
|
290 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
291 | + } |
|
292 | 292 | |
293 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
294 | - exit; |
|
295 | - } |
|
293 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
294 | + exit; |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
297 | + /** |
|
298 | 298 | * Sends a payment reminder to a customer. |
299 | - * |
|
300 | - * @param array $args |
|
299 | + * |
|
300 | + * @param array $args |
|
301 | 301 | */ |
302 | 302 | public function send_customer_payment_reminder( $args ) { |
303 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
303 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
304 | 304 | |
305 | - if ( $sent ) { |
|
306 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
307 | - } else { |
|
308 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
309 | - } |
|
305 | + if ( $sent ) { |
|
306 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
307 | + } else { |
|
308 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
309 | + } |
|
310 | 310 | |
311 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
312 | - exit; |
|
313 | - } |
|
311 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
312 | + exit; |
|
313 | + } |
|
314 | 314 | |
315 | 315 | /** |
316 | - * Returns an array of admin notices. |
|
317 | - * |
|
318 | - * @since 1.0.19 |
|
316 | + * Returns an array of admin notices. |
|
317 | + * |
|
318 | + * @since 1.0.19 |
|
319 | 319 | * @return array |
320 | - */ |
|
321 | - public function get_notices() { |
|
322 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
320 | + */ |
|
321 | + public function get_notices() { |
|
322 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
323 | 323 | return is_array( $notices ) ? $notices : array(); |
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Clears all admin notices |
|
328 | - * |
|
329 | - * @access public |
|
330 | - * @since 1.0.19 |
|
331 | - */ |
|
332 | - public function clear_notices() { |
|
333 | - delete_option( 'wpinv_admin_notices' ); |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Saves a new admin notice |
|
338 | - * |
|
339 | - * @access public |
|
340 | - * @since 1.0.19 |
|
341 | - */ |
|
342 | - public function save_notice( $type, $message ) { |
|
343 | - $notices = $this->get_notices(); |
|
344 | - |
|
345 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | - $notices[ $type ] = array(); |
|
347 | - } |
|
348 | - |
|
349 | - $notices[ $type ][] = $message; |
|
350 | - |
|
351 | - update_option( 'wpinv_admin_notices', $notices ); |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Displays a success notice |
|
356 | - * |
|
357 | - * @param string $msg The message to qeue. |
|
358 | - * @access public |
|
359 | - * @since 1.0.19 |
|
360 | - */ |
|
361 | - public function show_success( $msg ) { |
|
362 | - $this->save_notice( 'success', $msg ); |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Displays a error notice |
|
367 | - * |
|
368 | - * @access public |
|
369 | - * @param string $msg The message to qeue. |
|
370 | - * @since 1.0.19 |
|
371 | - */ |
|
372 | - public function show_error( $msg ) { |
|
373 | - $this->save_notice( 'error', $msg ); |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * Displays a warning notice |
|
378 | - * |
|
379 | - * @access public |
|
380 | - * @param string $msg The message to qeue. |
|
381 | - * @since 1.0.19 |
|
382 | - */ |
|
383 | - public function show_warning( $msg ) { |
|
384 | - $this->save_notice( 'warning', $msg ); |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Displays a info notice |
|
389 | - * |
|
390 | - * @access public |
|
391 | - * @param string $msg The message to qeue. |
|
392 | - * @since 1.0.19 |
|
393 | - */ |
|
394 | - public function show_info( $msg ) { |
|
395 | - $this->save_notice( 'info', $msg ); |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Show notices |
|
400 | - * |
|
401 | - * @access public |
|
402 | - * @since 1.0.19 |
|
403 | - */ |
|
404 | - public function show_notices() { |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Clears all admin notices |
|
328 | + * |
|
329 | + * @access public |
|
330 | + * @since 1.0.19 |
|
331 | + */ |
|
332 | + public function clear_notices() { |
|
333 | + delete_option( 'wpinv_admin_notices' ); |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Saves a new admin notice |
|
338 | + * |
|
339 | + * @access public |
|
340 | + * @since 1.0.19 |
|
341 | + */ |
|
342 | + public function save_notice( $type, $message ) { |
|
343 | + $notices = $this->get_notices(); |
|
344 | + |
|
345 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | + $notices[ $type ] = array(); |
|
347 | + } |
|
348 | + |
|
349 | + $notices[ $type ][] = $message; |
|
350 | + |
|
351 | + update_option( 'wpinv_admin_notices', $notices ); |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Displays a success notice |
|
356 | + * |
|
357 | + * @param string $msg The message to qeue. |
|
358 | + * @access public |
|
359 | + * @since 1.0.19 |
|
360 | + */ |
|
361 | + public function show_success( $msg ) { |
|
362 | + $this->save_notice( 'success', $msg ); |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Displays a error notice |
|
367 | + * |
|
368 | + * @access public |
|
369 | + * @param string $msg The message to qeue. |
|
370 | + * @since 1.0.19 |
|
371 | + */ |
|
372 | + public function show_error( $msg ) { |
|
373 | + $this->save_notice( 'error', $msg ); |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * Displays a warning notice |
|
378 | + * |
|
379 | + * @access public |
|
380 | + * @param string $msg The message to qeue. |
|
381 | + * @since 1.0.19 |
|
382 | + */ |
|
383 | + public function show_warning( $msg ) { |
|
384 | + $this->save_notice( 'warning', $msg ); |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Displays a info notice |
|
389 | + * |
|
390 | + * @access public |
|
391 | + * @param string $msg The message to qeue. |
|
392 | + * @since 1.0.19 |
|
393 | + */ |
|
394 | + public function show_info( $msg ) { |
|
395 | + $this->save_notice( 'info', $msg ); |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Show notices |
|
400 | + * |
|
401 | + * @access public |
|
402 | + * @since 1.0.19 |
|
403 | + */ |
|
404 | + public function show_notices() { |
|
405 | 405 | |
406 | 406 | $notices = $this->get_notices(); |
407 | 407 | $this->clear_notices(); |
408 | 408 | |
409 | - foreach ( $notices as $type => $messages ) { |
|
409 | + foreach ( $notices as $type => $messages ) { |
|
410 | 410 | |
411 | - if ( ! is_array( $messages ) ) { |
|
412 | - continue; |
|
413 | - } |
|
411 | + if ( ! is_array( $messages ) ) { |
|
412 | + continue; |
|
413 | + } |
|
414 | 414 | |
415 | 415 | $type = sanitize_key( $type ); |
416 | - foreach ( $messages as $message ) { |
|
416 | + foreach ( $messages as $message ) { |
|
417 | 417 | $message = wp_kses_post( $message ); |
418 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
418 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | } |
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | 425 | } |
@@ -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 | * The main admin class. |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * Class constructor. |
32 | 32 | */ |
33 | - public function __construct(){ |
|
33 | + public function __construct() { |
|
34 | 34 | |
35 | - $this->admin_path = plugin_dir_path( __FILE__ ); |
|
36 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
35 | + $this->admin_path = plugin_dir_path(__FILE__); |
|
36 | + $this->admin_url = plugins_url('/', __FILE__); |
|
37 | 37 | |
38 | - if ( is_admin() ) { |
|
38 | + if (is_admin()) { |
|
39 | 39 | $this->init_admin_hooks(); |
40 | 40 | } |
41 | 41 | |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | * |
47 | 47 | */ |
48 | 48 | private function init_admin_hooks() { |
49 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
|
50 | - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
|
51 | - add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
|
52 | - add_action( 'admin_init', array( $this, 'activation_redirect') ); |
|
53 | - add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
|
54 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
55 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
56 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
57 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
49 | + add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts')); |
|
50 | + add_filter('admin_body_class', array($this, 'admin_body_class')); |
|
51 | + add_action('admin_init', array($this, 'init_ayecode_connect_helper')); |
|
52 | + add_action('admin_init', array($this, 'activation_redirect')); |
|
53 | + add_action('admin_init', array($this, 'maybe_do_admin_action')); |
|
54 | + add_action('admin_notices', array($this, 'show_notices')); |
|
55 | + add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice')); |
|
56 | + add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder')); |
|
57 | + do_action('getpaid_init_admin_hooks', $this); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
@@ -65,49 +65,49 @@ discard block |
||
65 | 65 | public function enqeue_scripts() { |
66 | 66 | global $current_screen, $pagenow; |
67 | 67 | |
68 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
68 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
69 | 69 | $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
70 | 70 | |
71 | - if ( ! empty( $current_screen->post_type ) ) { |
|
71 | + if (!empty($current_screen->post_type)) { |
|
72 | 72 | $page = $current_screen->post_type; |
73 | 73 | } |
74 | 74 | |
75 | 75 | // General styles. |
76 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
76 | + if (false !== stripos($page, 'wpi')) { |
|
77 | 77 | |
78 | 78 | // Styles. |
79 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
80 | - wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version ); |
|
81 | - wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' ); |
|
82 | - wp_enqueue_style( 'wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
83 | - wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' ); |
|
79 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
80 | + wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version); |
|
81 | + wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all'); |
|
82 | + wp_enqueue_style('wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
83 | + wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16'); |
|
84 | 84 | |
85 | 85 | // Scripts. |
86 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true ); |
|
87 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION ); |
|
86 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true); |
|
87 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION); |
|
88 | 88 | |
89 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
90 | - wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ), $version ); |
|
91 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) ); |
|
89 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
90 | + wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version); |
|
91 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18())); |
|
92 | 92 | |
93 | 93 | } |
94 | 94 | |
95 | 95 | // Payment form scripts. |
96 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
96 | + if ('wpi_payment_form' == $page && $editing) { |
|
97 | 97 | $this->load_payment_form_scripts(); |
98 | 98 | } |
99 | 99 | |
100 | - if ( $page == 'wpinv-subscriptions' ) { |
|
101 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
102 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
100 | + if ($page == 'wpinv-subscriptions') { |
|
101 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
102 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
103 | 103 | } |
104 | 104 | |
105 | - if ( $page == 'wpinv-reports' ) { |
|
106 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
105 | + if ($page == 'wpinv-reports') { |
|
106 | + wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7'); |
|
107 | 107 | } |
108 | 108 | |
109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
110 | - wp_enqueue_script( 'postbox' ); |
|
109 | + if ($page == 'wpinv-subscriptions') { |
|
110 | + wp_enqueue_script('postbox'); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | } |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | global $post; |
121 | 121 | |
122 | 122 | return array( |
123 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
124 | - 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
|
125 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
126 | - 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
|
127 | - 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
|
128 | - 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
|
129 | - 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
|
123 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
124 | + 'post_ID' => isset($post->ID) ? $post->ID : '', |
|
125 | + 'wpinv_nonce' => wp_create_nonce('wpinv-nonce'), |
|
126 | + 'add_invoice_note_nonce' => wp_create_nonce('add-invoice-note'), |
|
127 | + 'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'), |
|
128 | + 'invoice_item_nonce' => wp_create_nonce('invoice-item'), |
|
129 | + 'billing_details_nonce' => wp_create_nonce('get-billing-details'), |
|
130 | 130 | 'tax' => wpinv_tax_amount(), |
131 | 131 | 'discount' => wpinv_discount_amount(), |
132 | 132 | 'currency_symbol' => wpinv_currency_symbol(), |
@@ -134,24 +134,24 @@ discard block |
||
134 | 134 | 'thousand_sep' => wpinv_thousands_separator(), |
135 | 135 | 'decimal_sep' => wpinv_decimal_separator(), |
136 | 136 | 'decimals' => wpinv_decimals(), |
137 | - 'save_invoice' => __( 'Save Invoice', 'invoicing' ), |
|
138 | - 'status_publish' => wpinv_status_nicename( 'publish' ), |
|
139 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
140 | - 'delete_tax_rate' => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ), |
|
141 | - 'status_pending' => wpinv_status_nicename( 'wpi-pending' ), |
|
142 | - 'OneItemMin' => __( 'Invoice must contain at least one item', 'invoicing' ), |
|
143 | - 'FillBillingDetails' => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ), |
|
144 | - 'confirmCalcTotals' => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ), |
|
145 | - 'AreYouSure' => __( 'Are you sure?', 'invoicing' ), |
|
146 | - 'emptyInvoice' => __( 'Add at least one item to save invoice!', 'invoicing' ), |
|
147 | - 'errDeleteItem' => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ), |
|
148 | - 'delete_subscription' => __( 'Are you sure you want to delete this subscription?', 'invoicing' ), |
|
149 | - 'action_edit' => __( 'Edit', 'invoicing' ), |
|
150 | - 'action_cancel' => __( 'Cancel', 'invoicing' ), |
|
151 | - 'item_description' => __( 'Item Description', 'invoicing' ), |
|
152 | - 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
|
153 | - 'discount_description' => __( 'Discount Description', 'invoicing' ), |
|
154 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
137 | + 'save_invoice' => __('Save Invoice', 'invoicing'), |
|
138 | + 'status_publish' => wpinv_status_nicename('publish'), |
|
139 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
140 | + 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'invoicing'), |
|
141 | + 'status_pending' => wpinv_status_nicename('wpi-pending'), |
|
142 | + 'OneItemMin' => __('Invoice must contain at least one item', 'invoicing'), |
|
143 | + 'FillBillingDetails' => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'), |
|
144 | + 'confirmCalcTotals' => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'), |
|
145 | + 'AreYouSure' => __('Are you sure?', 'invoicing'), |
|
146 | + 'emptyInvoice' => __('Add at least one item to save invoice!', 'invoicing'), |
|
147 | + 'errDeleteItem' => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'), |
|
148 | + 'delete_subscription' => __('Are you sure you want to delete this subscription?', 'invoicing'), |
|
149 | + 'action_edit' => __('Edit', 'invoicing'), |
|
150 | + 'action_cancel' => __('Cancel', 'invoicing'), |
|
151 | + 'item_description' => __('Item Description', 'invoicing'), |
|
152 | + 'invoice_description' => __('Invoice Description', 'invoicing'), |
|
153 | + 'discount_description' => __('Discount Description', 'invoicing'), |
|
154 | + 'searching' => __('Searching', 'invoicing'), |
|
155 | 155 | ); |
156 | 156 | |
157 | 157 | } |
@@ -163,30 +163,30 @@ discard block |
||
163 | 163 | protected function load_payment_form_scripts() { |
164 | 164 | global $post; |
165 | 165 | |
166 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
167 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
168 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
166 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
167 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
168 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
169 | 169 | |
170 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
171 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
170 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
171 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
172 | 172 | |
173 | 173 | wp_localize_script( |
174 | 174 | 'wpinv-admin-payment-form-script', |
175 | 175 | 'wpinvPaymentFormAdmin', |
176 | 176 | array( |
177 | 177 | 'elements' => getpaid()->form_elements->get_elements(), |
178 | - 'form_elements' => getpaid()->form_elements->get_form_elements( $post->ID ), |
|
178 | + 'form_elements' => getpaid()->form_elements->get_form_elements($post->ID), |
|
179 | 179 | 'currency' => wpinv_currency_symbol(), |
180 | 180 | 'position' => wpinv_currency_position(), |
181 | 181 | 'decimals' => (int) wpinv_decimals(), |
182 | 182 | 'thousands_sep' => wpinv_thousands_separator(), |
183 | 183 | 'decimals_sep' => wpinv_decimal_separator(), |
184 | - 'form_items' => getpaid()->form_elements->get_form_items( $post->ID ), |
|
184 | + 'form_items' => getpaid()->form_elements->get_form_items($post->ID), |
|
185 | 185 | 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
186 | 186 | ) |
187 | 187 | ); |
188 | 188 | |
189 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
189 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
190 | 190 | |
191 | 191 | } |
192 | 192 | |
@@ -197,25 +197,25 @@ discard block |
||
197 | 197 | * @return string |
198 | 198 | * |
199 | 199 | */ |
200 | - public function admin_body_class( $classes ) { |
|
200 | + public function admin_body_class($classes) { |
|
201 | 201 | global $pagenow, $post, $current_screen; |
202 | 202 | |
203 | 203 | |
204 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
204 | + $page = isset($_GET['page']) ? $_GET['page'] : ''; |
|
205 | 205 | |
206 | - if ( ! empty( $current_screen->post_type ) ) { |
|
206 | + if (!empty($current_screen->post_type)) { |
|
207 | 207 | $page = $current_screen->post_type; |
208 | 208 | } |
209 | 209 | |
210 | - if ( false !== stripos( $page, 'wpi' ) ) { |
|
211 | - $classes .= ' wpi-' . sanitize_key( $page ); |
|
210 | + if (false !== stripos($page, 'wpi')) { |
|
211 | + $classes .= ' wpi-' . sanitize_key($page); |
|
212 | 212 | } |
213 | 213 | |
214 | - if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
|
214 | + if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) { |
|
215 | 215 | $classes .= ' wpinv-cpt wpinv'; |
216 | 216 | } |
217 | 217 | |
218 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
218 | + if ($pagenow == 'post.php' && $page == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
219 | 219 | $classes .= ' wpi-editable-n'; |
220 | 220 | } |
221 | 221 | |
@@ -225,19 +225,19 @@ discard block |
||
225 | 225 | /** |
226 | 226 | * Maybe show the AyeCode Connect Notice. |
227 | 227 | */ |
228 | - public function init_ayecode_connect_helper(){ |
|
228 | + public function init_ayecode_connect_helper() { |
|
229 | 229 | |
230 | 230 | new AyeCode_Connect_Helper( |
231 | 231 | array( |
232 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
233 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
234 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
235 | - 'connect_button' => __("Connect Site","invoicing"), |
|
236 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
237 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
238 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
232 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
233 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
234 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
235 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
236 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
237 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
238 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
239 | 239 | ), |
240 | - array( 'wpi-addons' ) |
|
240 | + array('wpi-addons') |
|
241 | 241 | ); |
242 | 242 | |
243 | 243 | } |
@@ -248,19 +248,19 @@ discard block |
||
248 | 248 | public function activation_redirect() { |
249 | 249 | |
250 | 250 | // Bail if no activation redirect. |
251 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
251 | + if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | // Delete the redirect transient. |
256 | - delete_transient( '_wpinv_activation_redirect' ); |
|
256 | + delete_transient('_wpinv_activation_redirect'); |
|
257 | 257 | |
258 | 258 | // Bail if activating from network, or bulk |
259 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
259 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
260 | 260 | return; |
261 | 261 | } |
262 | 262 | |
263 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
263 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
264 | 264 | exit; |
265 | 265 | } |
266 | 266 | |
@@ -269,9 +269,9 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function maybe_do_admin_action() { |
271 | 271 | |
272 | - if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
273 | - $key = sanitize_key( $_REQUEST['getpaid-admin-action'] ); |
|
274 | - do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST ); |
|
272 | + if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
273 | + $key = sanitize_key($_REQUEST['getpaid-admin-action']); |
|
274 | + do_action("getpaid_authenticated_admin_action_$key", $_REQUEST); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | } |
@@ -281,16 +281,16 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param array $args |
283 | 283 | */ |
284 | - public function send_customer_invoice( $args ) { |
|
285 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
284 | + public function send_customer_invoice($args) { |
|
285 | + $sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id'])); |
|
286 | 286 | |
287 | - if ( $sent ) { |
|
288 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
287 | + if ($sent) { |
|
288 | + $this->show_success(__('Invoice was successfully sent to the customer', 'invoicing')); |
|
289 | 289 | } else { |
290 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
290 | + $this->show_error(__('Could not sent the invoice to the customer', 'invoicing')); |
|
291 | 291 | } |
292 | 292 | |
293 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
293 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
294 | 294 | exit; |
295 | 295 | } |
296 | 296 | |
@@ -299,16 +299,16 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param array $args |
301 | 301 | */ |
302 | - public function send_customer_payment_reminder( $args ) { |
|
303 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
302 | + public function send_customer_payment_reminder($args) { |
|
303 | + $sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id'])); |
|
304 | 304 | |
305 | - if ( $sent ) { |
|
306 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
305 | + if ($sent) { |
|
306 | + $this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing')); |
|
307 | 307 | } else { |
308 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
308 | + $this->show_error(__('Could not sent payment reminder to the customer', 'invoicing')); |
|
309 | 309 | } |
310 | 310 | |
311 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
311 | + wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id'))); |
|
312 | 312 | exit; |
313 | 313 | } |
314 | 314 | |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | * @return array |
320 | 320 | */ |
321 | 321 | public function get_notices() { |
322 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
323 | - return is_array( $notices ) ? $notices : array(); |
|
322 | + $notices = get_option('wpinv_admin_notices'); |
|
323 | + return is_array($notices) ? $notices : array(); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @since 1.0.19 |
331 | 331 | */ |
332 | 332 | public function clear_notices() { |
333 | - delete_option( 'wpinv_admin_notices' ); |
|
333 | + delete_option('wpinv_admin_notices'); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -339,16 +339,16 @@ discard block |
||
339 | 339 | * @access public |
340 | 340 | * @since 1.0.19 |
341 | 341 | */ |
342 | - public function save_notice( $type, $message ) { |
|
342 | + public function save_notice($type, $message) { |
|
343 | 343 | $notices = $this->get_notices(); |
344 | 344 | |
345 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
346 | - $notices[ $type ] = array(); |
|
345 | + if (empty($notices[$type]) || !is_array($notices[$type])) { |
|
346 | + $notices[$type] = array(); |
|
347 | 347 | } |
348 | 348 | |
349 | - $notices[ $type ][] = $message; |
|
349 | + $notices[$type][] = $message; |
|
350 | 350 | |
351 | - update_option( 'wpinv_admin_notices', $notices ); |
|
351 | + update_option('wpinv_admin_notices', $notices); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | * @access public |
359 | 359 | * @since 1.0.19 |
360 | 360 | */ |
361 | - public function show_success( $msg ) { |
|
362 | - $this->save_notice( 'success', $msg ); |
|
361 | + public function show_success($msg) { |
|
362 | + $this->save_notice('success', $msg); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -369,8 +369,8 @@ discard block |
||
369 | 369 | * @param string $msg The message to qeue. |
370 | 370 | * @since 1.0.19 |
371 | 371 | */ |
372 | - public function show_error( $msg ) { |
|
373 | - $this->save_notice( 'error', $msg ); |
|
372 | + public function show_error($msg) { |
|
373 | + $this->save_notice('error', $msg); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | * @param string $msg The message to qeue. |
381 | 381 | * @since 1.0.19 |
382 | 382 | */ |
383 | - public function show_warning( $msg ) { |
|
384 | - $this->save_notice( 'warning', $msg ); |
|
383 | + public function show_warning($msg) { |
|
384 | + $this->save_notice('warning', $msg); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -391,8 +391,8 @@ discard block |
||
391 | 391 | * @param string $msg The message to qeue. |
392 | 392 | * @since 1.0.19 |
393 | 393 | */ |
394 | - public function show_info( $msg ) { |
|
395 | - $this->save_notice( 'info', $msg ); |
|
394 | + public function show_info($msg) { |
|
395 | + $this->save_notice('info', $msg); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -406,15 +406,15 @@ discard block |
||
406 | 406 | $notices = $this->get_notices(); |
407 | 407 | $this->clear_notices(); |
408 | 408 | |
409 | - foreach ( $notices as $type => $messages ) { |
|
409 | + foreach ($notices as $type => $messages) { |
|
410 | 410 | |
411 | - if ( ! is_array( $messages ) ) { |
|
411 | + if (!is_array($messages)) { |
|
412 | 412 | continue; |
413 | 413 | } |
414 | 414 | |
415 | - $type = sanitize_key( $type ); |
|
416 | - foreach ( $messages as $message ) { |
|
417 | - $message = wp_kses_post( $message ); |
|
415 | + $type = sanitize_key($type); |
|
416 | + foreach ($messages as $message) { |
|
417 | + $message = wp_kses_post($message); |
|
418 | 418 | echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
419 | 419 | } |
420 | 420 |