@@ -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,358 +114,358 @@ 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 | 266 | |
267 | - // Convert the items. |
|
268 | - $prepared = array(); |
|
267 | + // Convert the items. |
|
268 | + $prepared = array(); |
|
269 | 269 | |
270 | - foreach ( $items as $key => $value ) { |
|
270 | + foreach ( $items as $key => $value ) { |
|
271 | 271 | |
272 | - // Form items. |
|
273 | - if ( $value instanceof GetPaid_Form_Item ) { |
|
272 | + // Form items. |
|
273 | + if ( $value instanceof GetPaid_Form_Item ) { |
|
274 | 274 | |
275 | - if ( $value->can_purchase() ) { |
|
276 | - $prepared[] = $value; |
|
277 | - } |
|
275 | + if ( $value->can_purchase() ) { |
|
276 | + $prepared[] = $value; |
|
277 | + } |
|
278 | 278 | |
279 | - continue; |
|
279 | + continue; |
|
280 | 280 | |
281 | - } |
|
281 | + } |
|
282 | 282 | |
283 | - // $item_id => $quantity (buy buttons) |
|
284 | - if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | - $item = new GetPaid_Form_Item( $key ); |
|
283 | + // $item_id => $quantity (buy buttons) |
|
284 | + if ( is_numeric( $key ) && is_numeric( $value ) ) { |
|
285 | + $item = new GetPaid_Form_Item( $key ); |
|
286 | 286 | |
287 | - if ( $item->can_purchase() ) { |
|
287 | + if ( $item->can_purchase() ) { |
|
288 | 288 | |
289 | - $value = (float) $value; |
|
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
294 | - } |
|
289 | + $value = (float) $value; |
|
290 | + $item->set_quantity( $value ); |
|
291 | + if ( 0 == $value ) { |
|
292 | + $item->set_quantity( 1 ); |
|
293 | + $item->set_allow_quantities( true ); |
|
294 | + } |
|
295 | 295 | |
296 | - $prepared[] = $item; |
|
297 | - } |
|
296 | + $prepared[] = $item; |
|
297 | + } |
|
298 | 298 | |
299 | - continue; |
|
300 | - } |
|
299 | + continue; |
|
300 | + } |
|
301 | 301 | |
302 | - // Items saved via payment forms editor. |
|
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
302 | + // Items saved via payment forms editor. |
|
303 | + if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item( $value['id'] ); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
308 | - continue; |
|
309 | - } |
|
307 | + if ( ! $item->can_purchase() ) { |
|
308 | + continue; |
|
309 | + } |
|
310 | 310 | |
311 | - // Sub-total (Cart items). |
|
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
314 | - } |
|
311 | + // Sub-total (Cart items). |
|
312 | + if ( isset( $value['subtotal'] ) ) { |
|
313 | + $item->set_price( $value['subtotal'] ); |
|
314 | + } |
|
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
318 | - } |
|
316 | + if ( isset( $value['quantity'] ) ) { |
|
317 | + $item->set_quantity( $value['quantity'] ); |
|
318 | + } |
|
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | - } |
|
320 | + if ( isset( $value['allow_quantities'] ) ) { |
|
321 | + $item->set_allow_quantities( $value['allow_quantities'] ); |
|
322 | + } |
|
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
326 | - } |
|
324 | + if ( isset( $value['required'] ) ) { |
|
325 | + $item->set_is_required( $value['required'] ); |
|
326 | + } |
|
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
330 | - } |
|
328 | + if ( isset( $value['description'] ) ) { |
|
329 | + $item->set_custom_description( $value['description'] ); |
|
330 | + } |
|
331 | 331 | |
332 | - $prepared[] = $item; |
|
333 | - continue; |
|
332 | + $prepared[] = $item; |
|
333 | + continue; |
|
334 | 334 | |
335 | - } |
|
335 | + } |
|
336 | 336 | |
337 | - // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
337 | + // $item_id => array( 'price' => 10 ) (item variations) |
|
338 | + if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | + $item = new GetPaid_Form_Item( $key ); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
343 | - } |
|
344 | - |
|
345 | - if ( $item->can_purchase() ) { |
|
346 | - $prepared[] = $item; |
|
347 | - } |
|
348 | - |
|
349 | - continue; |
|
350 | - } |
|
351 | - |
|
352 | - } |
|
353 | - |
|
354 | - if ( 'objects' == $return && 'view' == $context ) { |
|
355 | - return $prepared; |
|
356 | - } |
|
357 | - |
|
358 | - $items = array(); |
|
359 | - foreach ( $prepared as $item ) { |
|
360 | - $items[] = $item->prepare_data_for_use(); |
|
361 | - } |
|
362 | - |
|
363 | - return $items; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Get a single item belonging to the form. |
|
368 | - * |
|
369 | - * @since 1.0.19 |
|
370 | - * @param int $item_id The item id to return. |
|
371 | - * @return GetPaid_Form_Item|bool |
|
372 | - */ |
|
373 | - public function get_item( $item_id ) { |
|
374 | - |
|
375 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
376 | - return false; |
|
377 | - } |
|
378 | - |
|
379 | - foreach( $this->get_items() as $item ) { |
|
380 | - if ( $item->get_id() == (int) $item_id ) { |
|
381 | - return $item; |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - return false; |
|
386 | - |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Gets a single element. |
|
391 | - * |
|
392 | - * @since 1.0.19 |
|
393 | - * @param string $element_type The element type to return. |
|
394 | - * @return array|bool |
|
395 | - */ |
|
396 | - public function get_element_type( $element_type ) { |
|
397 | - |
|
398 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
399 | - return false; |
|
400 | - } |
|
401 | - |
|
402 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
403 | - |
|
404 | - if ( $element['type'] == $element_type ) { |
|
405 | - return $element; |
|
406 | - } |
|
407 | - |
|
408 | - } |
|
409 | - |
|
410 | - return false; |
|
411 | - |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Get the total amount earned via this form. |
|
416 | - * |
|
417 | - * @since 1.0.19 |
|
418 | - * @param string $context View or edit context. |
|
419 | - * @return float |
|
420 | - */ |
|
421 | - public function get_earned( $context = 'view' ) { |
|
422 | - return $this->get_prop( 'earned', $context ); |
|
423 | - } |
|
424 | - |
|
425 | - /** |
|
426 | - * Get the total amount refunded via this form. |
|
427 | - * |
|
428 | - * @since 1.0.19 |
|
429 | - * @param string $context View or edit context. |
|
430 | - * @return float |
|
431 | - */ |
|
432 | - public function get_refunded( $context = 'view' ) { |
|
433 | - return $this->get_prop( 'refunded', $context ); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Get the total amount cancelled via this form. |
|
438 | - * |
|
439 | - * @since 1.0.19 |
|
440 | - * @param string $context View or edit context. |
|
441 | - * @return float |
|
442 | - */ |
|
443 | - public function get_cancelled( $context = 'view' ) { |
|
444 | - return $this->get_prop( 'cancelled', $context ); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Get the total amount failed via this form. |
|
449 | - * |
|
450 | - * @since 1.0.19 |
|
451 | - * @param string $context View or edit context. |
|
452 | - * @return float |
|
453 | - */ |
|
454 | - public function get_failed( $context = 'view' ) { |
|
455 | - return $this->get_prop( 'failed', $context ); |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * Get the currency. |
|
460 | - * |
|
461 | - * @since 1.0.19 |
|
462 | - * @param string $context View or edit context. |
|
463 | - * @return string |
|
464 | - */ |
|
465 | - public function get_currency() { |
|
466 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
468 | - } |
|
341 | + if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | + $item->set_price( $value['price'] ); |
|
343 | + } |
|
344 | + |
|
345 | + if ( $item->can_purchase() ) { |
|
346 | + $prepared[] = $item; |
|
347 | + } |
|
348 | + |
|
349 | + continue; |
|
350 | + } |
|
351 | + |
|
352 | + } |
|
353 | + |
|
354 | + if ( 'objects' == $return && 'view' == $context ) { |
|
355 | + return $prepared; |
|
356 | + } |
|
357 | + |
|
358 | + $items = array(); |
|
359 | + foreach ( $prepared as $item ) { |
|
360 | + $items[] = $item->prepare_data_for_use(); |
|
361 | + } |
|
362 | + |
|
363 | + return $items; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Get a single item belonging to the form. |
|
368 | + * |
|
369 | + * @since 1.0.19 |
|
370 | + * @param int $item_id The item id to return. |
|
371 | + * @return GetPaid_Form_Item|bool |
|
372 | + */ |
|
373 | + public function get_item( $item_id ) { |
|
374 | + |
|
375 | + if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
376 | + return false; |
|
377 | + } |
|
378 | + |
|
379 | + foreach( $this->get_items() as $item ) { |
|
380 | + if ( $item->get_id() == (int) $item_id ) { |
|
381 | + return $item; |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + return false; |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Gets a single element. |
|
391 | + * |
|
392 | + * @since 1.0.19 |
|
393 | + * @param string $element_type The element type to return. |
|
394 | + * @return array|bool |
|
395 | + */ |
|
396 | + public function get_element_type( $element_type ) { |
|
397 | + |
|
398 | + if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
399 | + return false; |
|
400 | + } |
|
401 | + |
|
402 | + foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
403 | + |
|
404 | + if ( $element['type'] == $element_type ) { |
|
405 | + return $element; |
|
406 | + } |
|
407 | + |
|
408 | + } |
|
409 | + |
|
410 | + return false; |
|
411 | + |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Get the total amount earned via this form. |
|
416 | + * |
|
417 | + * @since 1.0.19 |
|
418 | + * @param string $context View or edit context. |
|
419 | + * @return float |
|
420 | + */ |
|
421 | + public function get_earned( $context = 'view' ) { |
|
422 | + return $this->get_prop( 'earned', $context ); |
|
423 | + } |
|
424 | + |
|
425 | + /** |
|
426 | + * Get the total amount refunded via this form. |
|
427 | + * |
|
428 | + * @since 1.0.19 |
|
429 | + * @param string $context View or edit context. |
|
430 | + * @return float |
|
431 | + */ |
|
432 | + public function get_refunded( $context = 'view' ) { |
|
433 | + return $this->get_prop( 'refunded', $context ); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Get the total amount cancelled via this form. |
|
438 | + * |
|
439 | + * @since 1.0.19 |
|
440 | + * @param string $context View or edit context. |
|
441 | + * @return float |
|
442 | + */ |
|
443 | + public function get_cancelled( $context = 'view' ) { |
|
444 | + return $this->get_prop( 'cancelled', $context ); |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Get the total amount failed via this form. |
|
449 | + * |
|
450 | + * @since 1.0.19 |
|
451 | + * @param string $context View or edit context. |
|
452 | + * @return float |
|
453 | + */ |
|
454 | + public function get_failed( $context = 'view' ) { |
|
455 | + return $this->get_prop( 'failed', $context ); |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * Get the currency. |
|
460 | + * |
|
461 | + * @since 1.0.19 |
|
462 | + * @param string $context View or edit context. |
|
463 | + * @return string |
|
464 | + */ |
|
465 | + public function get_currency() { |
|
466 | + $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | + return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
468 | + } |
|
469 | 469 | |
470 | 470 | /* |
471 | 471 | |-------------------------------------------------------------------------- |
@@ -478,22 +478,22 @@ discard block |
||
478 | 478 | */ |
479 | 479 | |
480 | 480 | /** |
481 | - * Set plugin version when the item was created. |
|
482 | - * |
|
483 | - * @since 1.0.19 |
|
484 | - */ |
|
485 | - public function set_version( $value ) { |
|
486 | - $this->set_prop( 'version', $value ); |
|
481 | + * Set plugin version when the item was created. |
|
482 | + * |
|
483 | + * @since 1.0.19 |
|
484 | + */ |
|
485 | + public function set_version( $value ) { |
|
486 | + $this->set_prop( 'version', $value ); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
490 | - * Set date when the item was created. |
|
491 | - * |
|
492 | - * @since 1.0.19 |
|
493 | - * @param string $value Value to set. |
|
490 | + * Set date when the item was created. |
|
491 | + * |
|
492 | + * @since 1.0.19 |
|
493 | + * @param string $value Value to set. |
|
494 | 494 | * @return bool Whether or not the date was set. |
495 | - */ |
|
496 | - public function set_date_created( $value ) { |
|
495 | + */ |
|
496 | + public function set_date_created( $value ) { |
|
497 | 497 | $date = strtotime( $value ); |
498 | 498 | |
499 | 499 | if ( $date ) { |
@@ -506,13 +506,13 @@ discard block |
||
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
509 | - * Set date when the item was last modified. |
|
510 | - * |
|
511 | - * @since 1.0.19 |
|
512 | - * @param string $value Value to set. |
|
509 | + * Set date when the item was last modified. |
|
510 | + * |
|
511 | + * @since 1.0.19 |
|
512 | + * @param string $value Value to set. |
|
513 | 513 | * @return bool Whether or not the date was set. |
514 | - */ |
|
515 | - public function set_date_modified( $value ) { |
|
514 | + */ |
|
515 | + public function set_date_modified( $value ) { |
|
516 | 516 | $date = strtotime( $value ); |
517 | 517 | |
518 | 518 | if ( $date ) { |
@@ -525,165 +525,165 @@ discard block |
||
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
528 | - * Set the item name. |
|
529 | - * |
|
530 | - * @since 1.0.19 |
|
531 | - * @param string $value New name. |
|
532 | - */ |
|
533 | - public function set_name( $value ) { |
|
534 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Alias of self::set_name(). |
|
539 | - * |
|
540 | - * @since 1.0.19 |
|
541 | - * @param string $value New name. |
|
542 | - */ |
|
543 | - public function set_title( $value ) { |
|
544 | - $this->set_name( $value ); |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Set the owner of the item. |
|
549 | - * |
|
550 | - * @since 1.0.19 |
|
551 | - * @param int $value New author. |
|
552 | - */ |
|
553 | - public function set_author( $value ) { |
|
554 | - $this->set_prop( 'author', (int) $value ); |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Set the form elements. |
|
559 | - * |
|
560 | - * @since 1.0.19 |
|
561 | - * @sinve 2.3.4 Array values sanitized. |
|
562 | - * @param array $value Form elements. |
|
563 | - */ |
|
564 | - public function set_elements( $value ) { |
|
565 | - if ( is_array( $value ) ) { |
|
566 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
567 | - } |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * Sanitize array values. |
|
572 | - * |
|
573 | - * @param $value |
|
574 | - * |
|
575 | - * @return mixed |
|
576 | - */ |
|
577 | - public function sanitize_array_values($value){ |
|
578 | - |
|
579 | - // sanitize |
|
580 | - if(!empty($value )){ |
|
581 | - |
|
582 | - foreach($value as $key => $val_arr){ |
|
583 | - |
|
584 | - if(is_array($val_arr)){ |
|
585 | - // check if we have sub array items. |
|
586 | - $sub_arr = array(); |
|
587 | - foreach($val_arr as $key2 => $val2){ |
|
588 | - if(is_array($val2)){ |
|
589 | - $sub_arr[$key2] = $this->sanitize_array_values($val2); |
|
590 | - unset($val_arr[$key][$key2]); |
|
591 | - } |
|
592 | - } |
|
593 | - |
|
594 | - // we allow some html in description so we sanitize it separately. |
|
595 | - $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : ''; |
|
596 | - |
|
597 | - // sanitize array elements |
|
598 | - $value[$key] = array_map( 'sanitize_text_field', $val_arr ); |
|
599 | - |
|
600 | - // add back the description if set |
|
601 | - if(isset($val_arr['description'])){ $value[$key]['description'] = $help_text;} |
|
602 | - |
|
603 | - // add back sub array items after its been sanitized. |
|
604 | - if ( ! empty( $sub_arr ) ) { |
|
605 | - $value[$key] = array_merge($value[$key],$sub_arr); |
|
606 | - } |
|
607 | - } |
|
608 | - |
|
609 | - } |
|
610 | - |
|
611 | - } |
|
612 | - |
|
613 | - return $value; |
|
614 | - } |
|
615 | - |
|
616 | - /** |
|
617 | - * Set the form items. |
|
618 | - * |
|
619 | - * @since 1.0.19 |
|
620 | - * @param array $value Form elements. |
|
621 | - */ |
|
622 | - public function set_items( $value ) { |
|
623 | - if ( is_array( $value ) ) { |
|
624 | - $this->set_prop( 'items', $value ); |
|
625 | - } |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * Set the total amount earned via this form. |
|
630 | - * |
|
631 | - * @since 1.0.19 |
|
632 | - * @param float $value Amount earned. |
|
633 | - */ |
|
634 | - public function set_earned( $value ) { |
|
635 | - $value = max( (float) $value, 0 ); |
|
636 | - $this->set_prop( 'earned', $value ); |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * Set the total amount refunded via this form. |
|
641 | - * |
|
642 | - * @since 1.0.19 |
|
643 | - * @param float $value Amount refunded. |
|
644 | - */ |
|
645 | - public function set_refunded( $value ) { |
|
646 | - $value = max( (float) $value, 0 ); |
|
647 | - $this->set_prop( 'refunded', $value ); |
|
648 | - } |
|
649 | - |
|
650 | - /** |
|
651 | - * Set the total amount cancelled via this form. |
|
652 | - * |
|
653 | - * @since 1.0.19 |
|
654 | - * @param float $value Amount cancelled. |
|
655 | - */ |
|
656 | - public function set_cancelled( $value ) { |
|
657 | - $value = max( (float) $value, 0 ); |
|
658 | - $this->set_prop( 'cancelled', $value ); |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * Set the total amount failed via this form. |
|
663 | - * |
|
664 | - * @since 1.0.19 |
|
665 | - * @param float $value Amount cancelled. |
|
666 | - */ |
|
667 | - public function set_failed( $value ) { |
|
668 | - $value = max( (float) $value, 0 ); |
|
669 | - $this->set_prop( 'failed', $value ); |
|
670 | - } |
|
528 | + * Set the item name. |
|
529 | + * |
|
530 | + * @since 1.0.19 |
|
531 | + * @param string $value New name. |
|
532 | + */ |
|
533 | + public function set_name( $value ) { |
|
534 | + $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Alias of self::set_name(). |
|
539 | + * |
|
540 | + * @since 1.0.19 |
|
541 | + * @param string $value New name. |
|
542 | + */ |
|
543 | + public function set_title( $value ) { |
|
544 | + $this->set_name( $value ); |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Set the owner of the item. |
|
549 | + * |
|
550 | + * @since 1.0.19 |
|
551 | + * @param int $value New author. |
|
552 | + */ |
|
553 | + public function set_author( $value ) { |
|
554 | + $this->set_prop( 'author', (int) $value ); |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Set the form elements. |
|
559 | + * |
|
560 | + * @since 1.0.19 |
|
561 | + * @sinve 2.3.4 Array values sanitized. |
|
562 | + * @param array $value Form elements. |
|
563 | + */ |
|
564 | + public function set_elements( $value ) { |
|
565 | + if ( is_array( $value ) ) { |
|
566 | + $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
567 | + } |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * Sanitize array values. |
|
572 | + * |
|
573 | + * @param $value |
|
574 | + * |
|
575 | + * @return mixed |
|
576 | + */ |
|
577 | + public function sanitize_array_values($value){ |
|
578 | + |
|
579 | + // sanitize |
|
580 | + if(!empty($value )){ |
|
581 | + |
|
582 | + foreach($value as $key => $val_arr){ |
|
583 | + |
|
584 | + if(is_array($val_arr)){ |
|
585 | + // check if we have sub array items. |
|
586 | + $sub_arr = array(); |
|
587 | + foreach($val_arr as $key2 => $val2){ |
|
588 | + if(is_array($val2)){ |
|
589 | + $sub_arr[$key2] = $this->sanitize_array_values($val2); |
|
590 | + unset($val_arr[$key][$key2]); |
|
591 | + } |
|
592 | + } |
|
593 | + |
|
594 | + // we allow some html in description so we sanitize it separately. |
|
595 | + $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : ''; |
|
596 | + |
|
597 | + // sanitize array elements |
|
598 | + $value[$key] = array_map( 'sanitize_text_field', $val_arr ); |
|
599 | + |
|
600 | + // add back the description if set |
|
601 | + if(isset($val_arr['description'])){ $value[$key]['description'] = $help_text;} |
|
602 | + |
|
603 | + // add back sub array items after its been sanitized. |
|
604 | + if ( ! empty( $sub_arr ) ) { |
|
605 | + $value[$key] = array_merge($value[$key],$sub_arr); |
|
606 | + } |
|
607 | + } |
|
608 | + |
|
609 | + } |
|
610 | + |
|
611 | + } |
|
612 | + |
|
613 | + return $value; |
|
614 | + } |
|
615 | + |
|
616 | + /** |
|
617 | + * Set the form items. |
|
618 | + * |
|
619 | + * @since 1.0.19 |
|
620 | + * @param array $value Form elements. |
|
621 | + */ |
|
622 | + public function set_items( $value ) { |
|
623 | + if ( is_array( $value ) ) { |
|
624 | + $this->set_prop( 'items', $value ); |
|
625 | + } |
|
626 | + } |
|
627 | + |
|
628 | + /** |
|
629 | + * Set the total amount earned via this form. |
|
630 | + * |
|
631 | + * @since 1.0.19 |
|
632 | + * @param float $value Amount earned. |
|
633 | + */ |
|
634 | + public function set_earned( $value ) { |
|
635 | + $value = max( (float) $value, 0 ); |
|
636 | + $this->set_prop( 'earned', $value ); |
|
637 | + } |
|
638 | + |
|
639 | + /** |
|
640 | + * Set the total amount refunded via this form. |
|
641 | + * |
|
642 | + * @since 1.0.19 |
|
643 | + * @param float $value Amount refunded. |
|
644 | + */ |
|
645 | + public function set_refunded( $value ) { |
|
646 | + $value = max( (float) $value, 0 ); |
|
647 | + $this->set_prop( 'refunded', $value ); |
|
648 | + } |
|
649 | + |
|
650 | + /** |
|
651 | + * Set the total amount cancelled via this form. |
|
652 | + * |
|
653 | + * @since 1.0.19 |
|
654 | + * @param float $value Amount cancelled. |
|
655 | + */ |
|
656 | + public function set_cancelled( $value ) { |
|
657 | + $value = max( (float) $value, 0 ); |
|
658 | + $this->set_prop( 'cancelled', $value ); |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * Set the total amount failed via this form. |
|
663 | + * |
|
664 | + * @since 1.0.19 |
|
665 | + * @param float $value Amount cancelled. |
|
666 | + */ |
|
667 | + public function set_failed( $value ) { |
|
668 | + $value = max( (float) $value, 0 ); |
|
669 | + $this->set_prop( 'failed', $value ); |
|
670 | + } |
|
671 | 671 | |
672 | 672 | /** |
673 | 673 | * Create an item. For backwards compatibilty. |
674 | 674 | * |
675 | 675 | * @deprecated |
676 | - * @return int item id |
|
676 | + * @return int item id |
|
677 | 677 | */ |
678 | 678 | public function create( $data = array() ) { |
679 | 679 | |
680 | - // Set the properties. |
|
681 | - if ( is_array( $data ) ) { |
|
682 | - $this->set_props( $data ); |
|
683 | - } |
|
680 | + // Set the properties. |
|
681 | + if ( is_array( $data ) ) { |
|
682 | + $this->set_props( $data ); |
|
683 | + } |
|
684 | 684 | |
685 | - // Save the item. |
|
686 | - return $this->save(); |
|
685 | + // Save the item. |
|
686 | + return $this->save(); |
|
687 | 687 | |
688 | 688 | } |
689 | 689 | |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | * Updates an item. For backwards compatibilty. |
692 | 692 | * |
693 | 693 | * @deprecated |
694 | - * @return int item id |
|
694 | + * @return int item id |
|
695 | 695 | */ |
696 | 696 | public function update( $data = array() ) { |
697 | 697 | return $this->create( $data ); |
@@ -707,22 +707,22 @@ discard block |
||
707 | 707 | */ |
708 | 708 | |
709 | 709 | /** |
710 | - * Checks whether this is the default payment form. |
|
711 | - * |
|
712 | - * @since 1.0.19 |
|
713 | - * @return bool |
|
714 | - */ |
|
710 | + * Checks whether this is the default payment form. |
|
711 | + * |
|
712 | + * @since 1.0.19 |
|
713 | + * @return bool |
|
714 | + */ |
|
715 | 715 | public function is_default() { |
716 | 716 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
717 | 717 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
718 | - } |
|
718 | + } |
|
719 | 719 | |
720 | 720 | /** |
721 | - * Checks whether the form is active. |
|
722 | - * |
|
723 | - * @since 1.0.19 |
|
724 | - * @return bool |
|
725 | - */ |
|
721 | + * Checks whether the form is active. |
|
722 | + * |
|
723 | + * @since 1.0.19 |
|
724 | + * @return bool |
|
725 | + */ |
|
726 | 726 | public function is_active() { |
727 | 727 | $is_active = 0 !== (int) $this->get_id(); |
728 | 728 | |
@@ -731,76 +731,76 @@ discard block |
||
731 | 731 | } |
732 | 732 | |
733 | 733 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
734 | - } |
|
735 | - |
|
736 | - /** |
|
737 | - * Checks whether the form has a given item. |
|
738 | - * |
|
739 | - * @since 1.0.19 |
|
740 | - * @return bool |
|
741 | - */ |
|
734 | + } |
|
735 | + |
|
736 | + /** |
|
737 | + * Checks whether the form has a given item. |
|
738 | + * |
|
739 | + * @since 1.0.19 |
|
740 | + * @return bool |
|
741 | + */ |
|
742 | 742 | public function has_item( $item_id ) { |
743 | 743 | return false !== $this->get_item( $item_id ); |
744 | - } |
|
745 | - |
|
746 | - /** |
|
747 | - * Checks whether the form has a given element. |
|
748 | - * |
|
749 | - * @since 1.0.19 |
|
750 | - * @return bool |
|
751 | - */ |
|
744 | + } |
|
745 | + |
|
746 | + /** |
|
747 | + * Checks whether the form has a given element. |
|
748 | + * |
|
749 | + * @since 1.0.19 |
|
750 | + * @return bool |
|
751 | + */ |
|
752 | 752 | public function has_element_type( $element_type ) { |
753 | 753 | return false !== $this->get_element_type( $element_type ); |
754 | - } |
|
755 | - |
|
756 | - /** |
|
757 | - * Checks whether this form is recurring or not. |
|
758 | - * |
|
759 | - * @since 1.0.19 |
|
760 | - * @return bool |
|
761 | - */ |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * Checks whether this form is recurring or not. |
|
758 | + * |
|
759 | + * @since 1.0.19 |
|
760 | + * @return bool |
|
761 | + */ |
|
762 | 762 | public function is_recurring() { |
763 | 763 | |
764 | - if ( ! empty( $this->invoice ) ) { |
|
765 | - return $this->invoice->is_recurring(); |
|
766 | - } |
|
764 | + if ( ! empty( $this->invoice ) ) { |
|
765 | + return $this->invoice->is_recurring(); |
|
766 | + } |
|
767 | 767 | |
768 | - foreach ( $this->get_items() as $item ) { |
|
768 | + foreach ( $this->get_items() as $item ) { |
|
769 | 769 | |
770 | - if ( $item->is_recurring() ) { |
|
771 | - return true; |
|
772 | - } |
|
770 | + if ( $item->is_recurring() ) { |
|
771 | + return true; |
|
772 | + } |
|
773 | 773 | |
774 | - } |
|
774 | + } |
|
775 | 775 | |
776 | 776 | return false; |
777 | - } |
|
777 | + } |
|
778 | 778 | |
779 | - /** |
|
780 | - * Retrieves the form's html. |
|
781 | - * |
|
782 | - * @since 1.0.19 |
|
783 | - */ |
|
779 | + /** |
|
780 | + * Retrieves the form's html. |
|
781 | + * |
|
782 | + * @since 1.0.19 |
|
783 | + */ |
|
784 | 784 | public function get_html( $extra_markup = '' ) { |
785 | 785 | |
786 | - // Return the HTML. |
|
787 | - return wpinv_get_template_html( |
|
788 | - 'payment-forms/form.php', |
|
789 | - array( |
|
790 | - 'form' => $this, |
|
791 | - 'extra_markup' => $extra_markup, |
|
792 | - ) |
|
793 | - ); |
|
794 | - |
|
795 | - } |
|
796 | - |
|
797 | - /** |
|
798 | - * Displays the payment form. |
|
799 | - * |
|
800 | - * @since 1.0.19 |
|
801 | - */ |
|
786 | + // Return the HTML. |
|
787 | + return wpinv_get_template_html( |
|
788 | + 'payment-forms/form.php', |
|
789 | + array( |
|
790 | + 'form' => $this, |
|
791 | + 'extra_markup' => $extra_markup, |
|
792 | + ) |
|
793 | + ); |
|
794 | + |
|
795 | + } |
|
796 | + |
|
797 | + /** |
|
798 | + * Displays the payment form. |
|
799 | + * |
|
800 | + * @since 1.0.19 |
|
801 | + */ |
|
802 | 802 | public function display( $extra_markup = '' ) { |
803 | - echo $this->get_html( $extra_markup ); |
|
803 | + echo $this->get_html( $extra_markup ); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | } |
@@ -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,16 +281,16 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | // $item_id => $quantity (buy buttons) |
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() ) { |
|
287 | + if ($item->can_purchase()) { |
|
288 | 288 | |
289 | 289 | $value = (float) $value; |
290 | - $item->set_quantity( $value ); |
|
291 | - if ( 0 == $value ) { |
|
292 | - $item->set_quantity( 1 ); |
|
293 | - $item->set_allow_quantities( true ); |
|
290 | + $item->set_quantity($value); |
|
291 | + if (0 == $value) { |
|
292 | + $item->set_quantity(1); |
|
293 | + $item->set_allow_quantities(true); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $prepared[] = $item; |
@@ -300,33 +300,33 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | // Items saved via payment forms editor. |
303 | - if ( is_array( $value ) && isset( $value['id'] ) ) { |
|
303 | + if (is_array($value) && isset($value['id'])) { |
|
304 | 304 | |
305 | - $item = new GetPaid_Form_Item( $value['id'] ); |
|
305 | + $item = new GetPaid_Form_Item($value['id']); |
|
306 | 306 | |
307 | - if ( ! $item->can_purchase() ) { |
|
307 | + if (!$item->can_purchase()) { |
|
308 | 308 | continue; |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Sub-total (Cart items). |
312 | - if ( isset( $value['subtotal'] ) ) { |
|
313 | - $item->set_price( $value['subtotal'] ); |
|
312 | + if (isset($value['subtotal'])) { |
|
313 | + $item->set_price($value['subtotal']); |
|
314 | 314 | } |
315 | 315 | |
316 | - if ( isset( $value['quantity'] ) ) { |
|
317 | - $item->set_quantity( $value['quantity'] ); |
|
316 | + if (isset($value['quantity'])) { |
|
317 | + $item->set_quantity($value['quantity']); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( isset( $value['allow_quantities'] ) ) { |
|
321 | - $item->set_allow_quantities( $value['allow_quantities'] ); |
|
320 | + if (isset($value['allow_quantities'])) { |
|
321 | + $item->set_allow_quantities($value['allow_quantities']); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( isset( $value['required'] ) ) { |
|
325 | - $item->set_is_required( $value['required'] ); |
|
324 | + if (isset($value['required'])) { |
|
325 | + $item->set_is_required($value['required']); |
|
326 | 326 | } |
327 | 327 | |
328 | - if ( isset( $value['description'] ) ) { |
|
329 | - $item->set_custom_description( $value['description'] ); |
|
328 | + if (isset($value['description'])) { |
|
329 | + $item->set_custom_description($value['description']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | $prepared[] = $item; |
@@ -335,14 +335,14 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | // $item_id => array( 'price' => 10 ) (item variations) |
338 | - if ( is_numeric( $key ) && is_array( $value ) ) { |
|
339 | - $item = new GetPaid_Form_Item( $key ); |
|
338 | + if (is_numeric($key) && is_array($value)) { |
|
339 | + $item = new GetPaid_Form_Item($key); |
|
340 | 340 | |
341 | - if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
|
342 | - $item->set_price( $value['price'] ); |
|
341 | + if (isset($value['price']) && $item->user_can_set_their_price()) { |
|
342 | + $item->set_price($value['price']); |
|
343 | 343 | } |
344 | 344 | |
345 | - if ( $item->can_purchase() ) { |
|
345 | + if ($item->can_purchase()) { |
|
346 | 346 | $prepared[] = $item; |
347 | 347 | } |
348 | 348 | |
@@ -351,12 +351,12 @@ discard block |
||
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | - if ( 'objects' == $return && 'view' == $context ) { |
|
354 | + if ('objects' == $return && 'view' == $context) { |
|
355 | 355 | return $prepared; |
356 | 356 | } |
357 | 357 | |
358 | 358 | $items = array(); |
359 | - foreach ( $prepared as $item ) { |
|
359 | + foreach ($prepared as $item) { |
|
360 | 360 | $items[] = $item->prepare_data_for_use(); |
361 | 361 | } |
362 | 362 | |
@@ -370,14 +370,14 @@ discard block |
||
370 | 370 | * @param int $item_id The item id to return. |
371 | 371 | * @return GetPaid_Form_Item|bool |
372 | 372 | */ |
373 | - public function get_item( $item_id ) { |
|
373 | + public function get_item($item_id) { |
|
374 | 374 | |
375 | - if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
|
375 | + if (empty($item_id) || !is_numeric($item_id)) { |
|
376 | 376 | return false; |
377 | 377 | } |
378 | 378 | |
379 | - foreach( $this->get_items() as $item ) { |
|
380 | - if ( $item->get_id() == (int) $item_id ) { |
|
379 | + foreach ($this->get_items() as $item) { |
|
380 | + if ($item->get_id() == (int) $item_id) { |
|
381 | 381 | return $item; |
382 | 382 | } |
383 | 383 | } |
@@ -393,15 +393,15 @@ discard block |
||
393 | 393 | * @param string $element_type The element type to return. |
394 | 394 | * @return array|bool |
395 | 395 | */ |
396 | - public function get_element_type( $element_type ) { |
|
396 | + public function get_element_type($element_type) { |
|
397 | 397 | |
398 | - if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
|
398 | + if (empty($element_type) || !is_scalar($element_type)) { |
|
399 | 399 | return false; |
400 | 400 | } |
401 | 401 | |
402 | - foreach ( $this->get_prop( 'elements' ) as $element ) { |
|
402 | + foreach ($this->get_prop('elements') as $element) { |
|
403 | 403 | |
404 | - if ( $element['type'] == $element_type ) { |
|
404 | + if ($element['type'] == $element_type) { |
|
405 | 405 | return $element; |
406 | 406 | } |
407 | 407 | |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | * @param string $context View or edit context. |
419 | 419 | * @return float |
420 | 420 | */ |
421 | - public function get_earned( $context = 'view' ) { |
|
422 | - return $this->get_prop( 'earned', $context ); |
|
421 | + public function get_earned($context = 'view') { |
|
422 | + return $this->get_prop('earned', $context); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | /** |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | * @param string $context View or edit context. |
430 | 430 | * @return float |
431 | 431 | */ |
432 | - public function get_refunded( $context = 'view' ) { |
|
433 | - return $this->get_prop( 'refunded', $context ); |
|
432 | + public function get_refunded($context = 'view') { |
|
433 | + return $this->get_prop('refunded', $context); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | * @param string $context View or edit context. |
441 | 441 | * @return float |
442 | 442 | */ |
443 | - public function get_cancelled( $context = 'view' ) { |
|
444 | - return $this->get_prop( 'cancelled', $context ); |
|
443 | + public function get_cancelled($context = 'view') { |
|
444 | + return $this->get_prop('cancelled', $context); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | * @param string $context View or edit context. |
452 | 452 | * @return float |
453 | 453 | */ |
454 | - public function get_failed( $context = 'view' ) { |
|
455 | - return $this->get_prop( 'failed', $context ); |
|
454 | + public function get_failed($context = 'view') { |
|
455 | + return $this->get_prop('failed', $context); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | /** |
@@ -463,8 +463,8 @@ discard block |
||
463 | 463 | * @return string |
464 | 464 | */ |
465 | 465 | public function get_currency() { |
466 | - $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | - return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
|
466 | + $currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency(); |
|
467 | + return apply_filters('getpaid-payment-form-currency', $currency, $this); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /* |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | * |
483 | 483 | * @since 1.0.19 |
484 | 484 | */ |
485 | - public function set_version( $value ) { |
|
486 | - $this->set_prop( 'version', $value ); |
|
485 | + public function set_version($value) { |
|
486 | + $this->set_prop('version', $value); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | /** |
@@ -493,11 +493,11 @@ discard block |
||
493 | 493 | * @param string $value Value to set. |
494 | 494 | * @return bool Whether or not the date was set. |
495 | 495 | */ |
496 | - public function set_date_created( $value ) { |
|
497 | - $date = strtotime( $value ); |
|
496 | + public function set_date_created($value) { |
|
497 | + $date = strtotime($value); |
|
498 | 498 | |
499 | - if ( $date ) { |
|
500 | - $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
|
499 | + if ($date) { |
|
500 | + $this->set_prop('date_created', date('Y-m-d H:i:s', $date)); |
|
501 | 501 | return true; |
502 | 502 | } |
503 | 503 | |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | * @param string $value Value to set. |
513 | 513 | * @return bool Whether or not the date was set. |
514 | 514 | */ |
515 | - public function set_date_modified( $value ) { |
|
516 | - $date = strtotime( $value ); |
|
515 | + public function set_date_modified($value) { |
|
516 | + $date = strtotime($value); |
|
517 | 517 | |
518 | - if ( $date ) { |
|
519 | - $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
|
518 | + if ($date) { |
|
519 | + $this->set_prop('date_modified', date('Y-m-d H:i:s', $date)); |
|
520 | 520 | return true; |
521 | 521 | } |
522 | 522 | |
@@ -530,8 +530,8 @@ discard block |
||
530 | 530 | * @since 1.0.19 |
531 | 531 | * @param string $value New name. |
532 | 532 | */ |
533 | - public function set_name( $value ) { |
|
534 | - $this->set_prop( 'name', sanitize_text_field( $value ) ); |
|
533 | + public function set_name($value) { |
|
534 | + $this->set_prop('name', sanitize_text_field($value)); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | /** |
@@ -540,8 +540,8 @@ discard block |
||
540 | 540 | * @since 1.0.19 |
541 | 541 | * @param string $value New name. |
542 | 542 | */ |
543 | - public function set_title( $value ) { |
|
544 | - $this->set_name( $value ); |
|
543 | + public function set_title($value) { |
|
544 | + $this->set_name($value); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @since 1.0.19 |
551 | 551 | * @param int $value New author. |
552 | 552 | */ |
553 | - public function set_author( $value ) { |
|
554 | - $this->set_prop( 'author', (int) $value ); |
|
553 | + public function set_author($value) { |
|
554 | + $this->set_prop('author', (int) $value); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -561,9 +561,9 @@ discard block |
||
561 | 561 | * @sinve 2.3.4 Array values sanitized. |
562 | 562 | * @param array $value Form elements. |
563 | 563 | */ |
564 | - public function set_elements( $value ) { |
|
565 | - if ( is_array( $value ) ) { |
|
566 | - $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
|
564 | + public function set_elements($value) { |
|
565 | + if (is_array($value)) { |
|
566 | + $this->set_prop('elements', wp_kses_post_deep($value)); |
|
567 | 567 | } |
568 | 568 | } |
569 | 569 | |
@@ -574,18 +574,18 @@ discard block |
||
574 | 574 | * |
575 | 575 | * @return mixed |
576 | 576 | */ |
577 | - public function sanitize_array_values($value){ |
|
577 | + public function sanitize_array_values($value) { |
|
578 | 578 | |
579 | 579 | // sanitize |
580 | - if(!empty($value )){ |
|
580 | + if (!empty($value)) { |
|
581 | 581 | |
582 | - foreach($value as $key => $val_arr){ |
|
582 | + foreach ($value as $key => $val_arr) { |
|
583 | 583 | |
584 | - if(is_array($val_arr)){ |
|
584 | + if (is_array($val_arr)) { |
|
585 | 585 | // check if we have sub array items. |
586 | 586 | $sub_arr = array(); |
587 | - foreach($val_arr as $key2 => $val2){ |
|
588 | - if(is_array($val2)){ |
|
587 | + foreach ($val_arr as $key2 => $val2) { |
|
588 | + if (is_array($val2)) { |
|
589 | 589 | $sub_arr[$key2] = $this->sanitize_array_values($val2); |
590 | 590 | unset($val_arr[$key][$key2]); |
591 | 591 | } |
@@ -595,14 +595,14 @@ discard block |
||
595 | 595 | $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : ''; |
596 | 596 | |
597 | 597 | // sanitize array elements |
598 | - $value[$key] = array_map( 'sanitize_text_field', $val_arr ); |
|
598 | + $value[$key] = array_map('sanitize_text_field', $val_arr); |
|
599 | 599 | |
600 | 600 | // add back the description if set |
601 | - if(isset($val_arr['description'])){ $value[$key]['description'] = $help_text;} |
|
601 | + if (isset($val_arr['description'])) { $value[$key]['description'] = $help_text; } |
|
602 | 602 | |
603 | 603 | // add back sub array items after its been sanitized. |
604 | - if ( ! empty( $sub_arr ) ) { |
|
605 | - $value[$key] = array_merge($value[$key],$sub_arr); |
|
604 | + if (!empty($sub_arr)) { |
|
605 | + $value[$key] = array_merge($value[$key], $sub_arr); |
|
606 | 606 | } |
607 | 607 | } |
608 | 608 | |
@@ -619,9 +619,9 @@ discard block |
||
619 | 619 | * @since 1.0.19 |
620 | 620 | * @param array $value Form elements. |
621 | 621 | */ |
622 | - public function set_items( $value ) { |
|
623 | - if ( is_array( $value ) ) { |
|
624 | - $this->set_prop( 'items', $value ); |
|
622 | + public function set_items($value) { |
|
623 | + if (is_array($value)) { |
|
624 | + $this->set_prop('items', $value); |
|
625 | 625 | } |
626 | 626 | } |
627 | 627 | |
@@ -631,9 +631,9 @@ discard block |
||
631 | 631 | * @since 1.0.19 |
632 | 632 | * @param float $value Amount earned. |
633 | 633 | */ |
634 | - public function set_earned( $value ) { |
|
635 | - $value = max( (float) $value, 0 ); |
|
636 | - $this->set_prop( 'earned', $value ); |
|
634 | + public function set_earned($value) { |
|
635 | + $value = max((float) $value, 0); |
|
636 | + $this->set_prop('earned', $value); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -642,9 +642,9 @@ discard block |
||
642 | 642 | * @since 1.0.19 |
643 | 643 | * @param float $value Amount refunded. |
644 | 644 | */ |
645 | - public function set_refunded( $value ) { |
|
646 | - $value = max( (float) $value, 0 ); |
|
647 | - $this->set_prop( 'refunded', $value ); |
|
645 | + public function set_refunded($value) { |
|
646 | + $value = max((float) $value, 0); |
|
647 | + $this->set_prop('refunded', $value); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | /** |
@@ -653,9 +653,9 @@ discard block |
||
653 | 653 | * @since 1.0.19 |
654 | 654 | * @param float $value Amount cancelled. |
655 | 655 | */ |
656 | - public function set_cancelled( $value ) { |
|
657 | - $value = max( (float) $value, 0 ); |
|
658 | - $this->set_prop( 'cancelled', $value ); |
|
656 | + public function set_cancelled($value) { |
|
657 | + $value = max((float) $value, 0); |
|
658 | + $this->set_prop('cancelled', $value); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | /** |
@@ -664,9 +664,9 @@ discard block |
||
664 | 664 | * @since 1.0.19 |
665 | 665 | * @param float $value Amount cancelled. |
666 | 666 | */ |
667 | - public function set_failed( $value ) { |
|
668 | - $value = max( (float) $value, 0 ); |
|
669 | - $this->set_prop( 'failed', $value ); |
|
667 | + public function set_failed($value) { |
|
668 | + $value = max((float) $value, 0); |
|
669 | + $this->set_prop('failed', $value); |
|
670 | 670 | } |
671 | 671 | |
672 | 672 | /** |
@@ -675,11 +675,11 @@ discard block |
||
675 | 675 | * @deprecated |
676 | 676 | * @return int item id |
677 | 677 | */ |
678 | - public function create( $data = array() ) { |
|
678 | + public function create($data = array()) { |
|
679 | 679 | |
680 | 680 | // Set the properties. |
681 | - if ( is_array( $data ) ) { |
|
682 | - $this->set_props( $data ); |
|
681 | + if (is_array($data)) { |
|
682 | + $this->set_props($data); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | // Save the item. |
@@ -693,8 +693,8 @@ discard block |
||
693 | 693 | * @deprecated |
694 | 694 | * @return int item id |
695 | 695 | */ |
696 | - public function update( $data = array() ) { |
|
697 | - return $this->create( $data ); |
|
696 | + public function update($data = array()) { |
|
697 | + return $this->create($data); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | /* |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | */ |
715 | 715 | public function is_default() { |
716 | 716 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
717 | - return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
|
717 | + return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this); |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -726,11 +726,11 @@ discard block |
||
726 | 726 | public function is_active() { |
727 | 727 | $is_active = 0 !== (int) $this->get_id(); |
728 | 728 | |
729 | - if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
|
729 | + if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') { |
|
730 | 730 | $is_active = false; |
731 | 731 | } |
732 | 732 | |
733 | - return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
|
733 | + return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this); |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | /** |
@@ -739,8 +739,8 @@ discard block |
||
739 | 739 | * @since 1.0.19 |
740 | 740 | * @return bool |
741 | 741 | */ |
742 | - public function has_item( $item_id ) { |
|
743 | - return false !== $this->get_item( $item_id ); |
|
742 | + public function has_item($item_id) { |
|
743 | + return false !== $this->get_item($item_id); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | /** |
@@ -749,8 +749,8 @@ discard block |
||
749 | 749 | * @since 1.0.19 |
750 | 750 | * @return bool |
751 | 751 | */ |
752 | - public function has_element_type( $element_type ) { |
|
753 | - return false !== $this->get_element_type( $element_type ); |
|
752 | + public function has_element_type($element_type) { |
|
753 | + return false !== $this->get_element_type($element_type); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | /** |
@@ -761,13 +761,13 @@ discard block |
||
761 | 761 | */ |
762 | 762 | public function is_recurring() { |
763 | 763 | |
764 | - if ( ! empty( $this->invoice ) ) { |
|
764 | + if (!empty($this->invoice)) { |
|
765 | 765 | return $this->invoice->is_recurring(); |
766 | 766 | } |
767 | 767 | |
768 | - foreach ( $this->get_items() as $item ) { |
|
768 | + foreach ($this->get_items() as $item) { |
|
769 | 769 | |
770 | - if ( $item->is_recurring() ) { |
|
770 | + if ($item->is_recurring()) { |
|
771 | 771 | return true; |
772 | 772 | } |
773 | 773 | |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | * |
782 | 782 | * @since 1.0.19 |
783 | 783 | */ |
784 | - public function get_html( $extra_markup = '' ) { |
|
784 | + public function get_html($extra_markup = '') { |
|
785 | 785 | |
786 | 786 | // Return the HTML. |
787 | 787 | return wpinv_get_template_html( |
@@ -799,8 +799,8 @@ discard block |
||
799 | 799 | * |
800 | 800 | * @since 1.0.19 |
801 | 801 | */ |
802 | - public function display( $extra_markup = '' ) { |
|
803 | - echo $this->get_html( $extra_markup ); |
|
802 | + public function display($extra_markup = '') { |
|
803 | + echo $this->get_html($extra_markup); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | } |
@@ -10,232 +10,232 @@ discard block |
||
10 | 10 | |
11 | 11 | if (!class_exists('RapidAddon')) { |
12 | 12 | |
13 | - class RapidAddon { |
|
14 | - |
|
15 | - public $name; |
|
16 | - public $slug; |
|
17 | - public $fields; |
|
18 | - public $options = array(); |
|
19 | - public $accordions = array(); |
|
20 | - public $image_sections = array(); |
|
21 | - public $import_function; |
|
22 | - public $post_saved_function; |
|
23 | - public $notice_text; |
|
24 | - public $logger = null; |
|
25 | - public $when_to_run = false; |
|
26 | - public $image_options = array( |
|
27 | - 'download_images' => 'yes', |
|
28 | - 'download_featured_delim' => ',', |
|
29 | - 'download_featured_image' => '', |
|
30 | - 'gallery_featured_image' => '', |
|
31 | - 'gallery_featured_delim' => ',', |
|
32 | - 'featured_image' => '', |
|
33 | - 'featured_delim' => ',', |
|
34 | - 'search_existing_images' => 1, |
|
35 | - 'is_featured' => 0, |
|
36 | - 'create_draft' => 'no', |
|
37 | - 'set_image_meta_title' => 0, |
|
38 | - 'image_meta_title_delim' => ',', |
|
39 | - 'image_meta_title' => '', |
|
40 | - 'set_image_meta_caption' => 0, |
|
41 | - 'image_meta_caption_delim' => ',', |
|
42 | - 'image_meta_caption' => '', |
|
43 | - 'set_image_meta_alt' => 0, |
|
44 | - 'image_meta_alt_delim' => ',', |
|
45 | - 'image_meta_alt' => '', |
|
46 | - 'set_image_meta_description' => 0, |
|
47 | - 'image_meta_description_delim' => ',', |
|
48 | - 'image_meta_description_delim_logic' => 'separate', |
|
49 | - 'image_meta_description' => '', |
|
50 | - 'auto_rename_images' => 0, |
|
51 | - 'auto_rename_images_suffix' => '', |
|
52 | - 'auto_set_extension' => 0, |
|
53 | - 'new_extension' => '', |
|
54 | - 'do_not_remove_images' => 1, |
|
13 | + class RapidAddon { |
|
14 | + |
|
15 | + public $name; |
|
16 | + public $slug; |
|
17 | + public $fields; |
|
18 | + public $options = array(); |
|
19 | + public $accordions = array(); |
|
20 | + public $image_sections = array(); |
|
21 | + public $import_function; |
|
22 | + public $post_saved_function; |
|
23 | + public $notice_text; |
|
24 | + public $logger = null; |
|
25 | + public $when_to_run = false; |
|
26 | + public $image_options = array( |
|
27 | + 'download_images' => 'yes', |
|
28 | + 'download_featured_delim' => ',', |
|
29 | + 'download_featured_image' => '', |
|
30 | + 'gallery_featured_image' => '', |
|
31 | + 'gallery_featured_delim' => ',', |
|
32 | + 'featured_image' => '', |
|
33 | + 'featured_delim' => ',', |
|
34 | + 'search_existing_images' => 1, |
|
35 | + 'is_featured' => 0, |
|
36 | + 'create_draft' => 'no', |
|
37 | + 'set_image_meta_title' => 0, |
|
38 | + 'image_meta_title_delim' => ',', |
|
39 | + 'image_meta_title' => '', |
|
40 | + 'set_image_meta_caption' => 0, |
|
41 | + 'image_meta_caption_delim' => ',', |
|
42 | + 'image_meta_caption' => '', |
|
43 | + 'set_image_meta_alt' => 0, |
|
44 | + 'image_meta_alt_delim' => ',', |
|
45 | + 'image_meta_alt' => '', |
|
46 | + 'set_image_meta_description' => 0, |
|
47 | + 'image_meta_description_delim' => ',', |
|
48 | + 'image_meta_description_delim_logic' => 'separate', |
|
49 | + 'image_meta_description' => '', |
|
50 | + 'auto_rename_images' => 0, |
|
51 | + 'auto_rename_images_suffix' => '', |
|
52 | + 'auto_set_extension' => 0, |
|
53 | + 'new_extension' => '', |
|
54 | + 'do_not_remove_images' => 1, |
|
55 | 55 | 'search_existing_images_logic' => 'by_url' |
56 | - ); |
|
56 | + ); |
|
57 | 57 | |
58 | - protected $isWizard = true; |
|
58 | + protected $isWizard = true; |
|
59 | 59 | |
60 | - function __construct($name, $slug) { |
|
61 | - $this->name = $name; |
|
62 | - $this->slug = $slug; |
|
63 | - if (!empty($_GET['id'])){ |
|
64 | - $this->isWizard = false; |
|
65 | - } |
|
60 | + function __construct($name, $slug) { |
|
61 | + $this->name = $name; |
|
62 | + $this->slug = $slug; |
|
63 | + if (!empty($_GET['id'])){ |
|
64 | + $this->isWizard = false; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | |
68 | - function set_import_function($name) { |
|
69 | - $this->import_function = $name; |
|
70 | - } |
|
68 | + function set_import_function($name) { |
|
69 | + $this->import_function = $name; |
|
70 | + } |
|
71 | 71 | |
72 | - function set_post_saved_function($name) { |
|
73 | - $this->post_saved_function = $name; |
|
74 | - } |
|
72 | + function set_post_saved_function($name) { |
|
73 | + $this->post_saved_function = $name; |
|
74 | + } |
|
75 | 75 | |
76 | - function is_active_addon($post_type = null) { |
|
76 | + function is_active_addon($post_type = null) { |
|
77 | 77 | |
78 | - if ( ! class_exists( 'PMXI_Plugin' ) ) { |
|
79 | - return false; |
|
80 | - } |
|
78 | + if ( ! class_exists( 'PMXI_Plugin' ) ) { |
|
79 | + return false; |
|
80 | + } |
|
81 | 81 | |
82 | - $addon_active = false; |
|
82 | + $addon_active = false; |
|
83 | 83 | |
84 | - if ($post_type !== null) { |
|
85 | - if (@in_array($post_type, $this->active_post_types) or empty($this->active_post_types)) { |
|
86 | - $addon_active = true; |
|
87 | - } |
|
88 | - } |
|
84 | + if ($post_type !== null) { |
|
85 | + if (@in_array($post_type, $this->active_post_types) or empty($this->active_post_types)) { |
|
86 | + $addon_active = true; |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - if ($addon_active){ |
|
90 | + if ($addon_active){ |
|
91 | 91 | |
92 | - $current_theme = wp_get_theme(); |
|
92 | + $current_theme = wp_get_theme(); |
|
93 | 93 | |
94 | - $parent_theme = $current_theme->parent(); |
|
94 | + $parent_theme = $current_theme->parent(); |
|
95 | 95 | |
96 | - $theme_name = $current_theme->get('Name'); |
|
96 | + $theme_name = $current_theme->get('Name'); |
|
97 | 97 | |
98 | - $addon_active = (@in_array($theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false; |
|
98 | + $addon_active = (@in_array($theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false; |
|
99 | 99 | |
100 | - if ( ! $addon_active and $parent_theme ){ |
|
101 | - $parent_theme_name = $parent_theme->get('Name'); |
|
102 | - $addon_active = (@in_array($parent_theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false; |
|
100 | + if ( ! $addon_active and $parent_theme ){ |
|
101 | + $parent_theme_name = $parent_theme->get('Name'); |
|
102 | + $addon_active = (@in_array($parent_theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false; |
|
103 | 103 | |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | - if ( $addon_active and ! empty($this->active_plugins) ){ |
|
106 | + if ( $addon_active and ! empty($this->active_plugins) ){ |
|
107 | 107 | |
108 | - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
108 | + include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
109 | 109 | |
110 | - foreach ($this->active_plugins as $plugin) { |
|
111 | - if ( ! is_plugin_active($plugin) ) { |
|
112 | - $addon_active = false; |
|
113 | - break; |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
110 | + foreach ($this->active_plugins as $plugin) { |
|
111 | + if ( ! is_plugin_active($plugin) ) { |
|
112 | + $addon_active = false; |
|
113 | + break; |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | 117 | |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - if ($this->when_to_run == "always") { |
|
121 | - $addon_active = true; |
|
122 | - } |
|
120 | + if ($this->when_to_run == "always") { |
|
121 | + $addon_active = true; |
|
122 | + } |
|
123 | 123 | |
124 | - return apply_filters('rapid_is_active_add_on', $addon_active, $post_type, $this->slug); |
|
125 | - } |
|
124 | + return apply_filters('rapid_is_active_add_on', $addon_active, $post_type, $this->slug); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * |
|
129 | - * Add-On Initialization |
|
130 | - * |
|
131 | - * @param array $conditions - list of supported themes and post types |
|
132 | - * |
|
133 | - */ |
|
134 | - function run($conditions = array()) { |
|
135 | - |
|
136 | - if (empty($conditions)) { |
|
137 | - $this->when_to_run = "always"; |
|
138 | - } |
|
127 | + /** |
|
128 | + * |
|
129 | + * Add-On Initialization |
|
130 | + * |
|
131 | + * @param array $conditions - list of supported themes and post types |
|
132 | + * |
|
133 | + */ |
|
134 | + function run($conditions = array()) { |
|
135 | + |
|
136 | + if (empty($conditions)) { |
|
137 | + $this->when_to_run = "always"; |
|
138 | + } |
|
139 | 139 | |
140 | - @$this->active_post_types = ( ! empty($conditions['post_types'])) ? $conditions['post_types'] : array(); |
|
141 | - @$this->active_themes = ( ! empty($conditions['themes'])) ? $conditions['themes'] : array(); |
|
142 | - @$this->active_plugins = ( ! empty($conditions['plugins'])) ? $conditions['plugins'] : array(); |
|
140 | + @$this->active_post_types = ( ! empty($conditions['post_types'])) ? $conditions['post_types'] : array(); |
|
141 | + @$this->active_themes = ( ! empty($conditions['themes'])) ? $conditions['themes'] : array(); |
|
142 | + @$this->active_plugins = ( ! empty($conditions['plugins'])) ? $conditions['plugins'] : array(); |
|
143 | 143 | |
144 | - add_filter('pmxi_addons', array($this, 'wpai_api_register')); |
|
145 | - add_filter('wp_all_import_addon_parse', array($this, 'wpai_api_parse')); |
|
146 | - add_filter('wp_all_import_addon_import', array($this, 'wpai_api_import')); |
|
147 | - add_filter('wp_all_import_addon_saved_post', array($this, 'wpai_api_post_saved')); |
|
148 | - add_filter('pmxi_options_options', array($this, 'wpai_api_options')); |
|
144 | + add_filter('pmxi_addons', array($this, 'wpai_api_register')); |
|
145 | + add_filter('wp_all_import_addon_parse', array($this, 'wpai_api_parse')); |
|
146 | + add_filter('wp_all_import_addon_import', array($this, 'wpai_api_import')); |
|
147 | + add_filter('wp_all_import_addon_saved_post', array($this, 'wpai_api_post_saved')); |
|
148 | + add_filter('pmxi_options_options', array($this, 'wpai_api_options')); |
|
149 | 149 | add_filter('wp_all_import_image_sections', array($this, 'additional_sections'), 10, 1); |
150 | 150 | add_filter('pmxi_custom_types', array($this, 'filter_post_types'), 10, 2); |
151 | 151 | add_filter('pmxi_post_list_order', array($this,'sort_post_types'), 10, 1); |
152 | 152 | add_filter('wp_all_import_post_type_image', array($this, 'post_type_image'), 10, 1 ); |
153 | - add_action('pmxi_extend_options_featured', array($this, 'wpai_api_metabox'), 10, 2); |
|
153 | + add_action('pmxi_extend_options_featured', array($this, 'wpai_api_metabox'), 10, 2); |
|
154 | 154 | add_action('admin_init', array($this, 'admin_notice_ignore')); |
155 | 155 | } |
156 | 156 | |
157 | - function parse($data) { |
|
157 | + function parse($data) { |
|
158 | 158 | |
159 | - if ( ! $this->is_active_addon($data['import']->options['custom_type'])) return false; |
|
159 | + if ( ! $this->is_active_addon($data['import']->options['custom_type'])) return false; |
|
160 | 160 | |
161 | - $parsedData = $this->helper_parse($data, $this->options_array()); |
|
162 | - return $parsedData; |
|
161 | + $parsedData = $this->helper_parse($data, $this->options_array()); |
|
162 | + return $parsedData; |
|
163 | 163 | |
164 | - } |
|
164 | + } |
|
165 | 165 | |
166 | 166 | |
167 | - function add_field($field_slug, $field_name, $field_type, $enum_values = null, $tooltip = "", $is_html = true, $default_text = '') { |
|
167 | + function add_field($field_slug, $field_name, $field_type, $enum_values = null, $tooltip = "", $is_html = true, $default_text = '') { |
|
168 | 168 | |
169 | - $field = array("name" => $field_name, "type" => $field_type, "enum_values" => $enum_values, "tooltip" => $tooltip, "is_sub_field" => false, "is_main_field" => false, "slug" => $field_slug, "is_html" => $is_html, 'default_text' => $default_text); |
|
169 | + $field = array("name" => $field_name, "type" => $field_type, "enum_values" => $enum_values, "tooltip" => $tooltip, "is_sub_field" => false, "is_main_field" => false, "slug" => $field_slug, "is_html" => $is_html, 'default_text' => $default_text); |
|
170 | 170 | |
171 | - $this->fields[$field_slug] = $field; |
|
171 | + $this->fields[$field_slug] = $field; |
|
172 | 172 | |
173 | - if ( ! empty($enum_values) ){ |
|
174 | - foreach ($enum_values as $key => $value) { |
|
175 | - if (is_array($value)) |
|
176 | - { |
|
177 | - if ($field['type'] == 'accordion') |
|
178 | - { |
|
179 | - $this->fields[$value['slug']]['is_sub_field'] = true; |
|
180 | - } |
|
181 | - else |
|
182 | - { |
|
183 | - foreach ($value as $n => $param) { |
|
184 | - if (is_array($param) and ! empty($this->fields[$param['slug']])){ |
|
185 | - $this->fields[$param['slug']]['is_sub_field'] = true; |
|
186 | - } |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
191 | - } |
|
173 | + if ( ! empty($enum_values) ){ |
|
174 | + foreach ($enum_values as $key => $value) { |
|
175 | + if (is_array($value)) |
|
176 | + { |
|
177 | + if ($field['type'] == 'accordion') |
|
178 | + { |
|
179 | + $this->fields[$value['slug']]['is_sub_field'] = true; |
|
180 | + } |
|
181 | + else |
|
182 | + { |
|
183 | + foreach ($value as $n => $param) { |
|
184 | + if (is_array($param) and ! empty($this->fields[$param['slug']])){ |
|
185 | + $this->fields[$param['slug']]['is_sub_field'] = true; |
|
186 | + } |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - return $field; |
|
193 | + return $field; |
|
194 | 194 | |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | - function add_acf_field($field){ |
|
198 | - $this->fields[$field->post_name] = array( |
|
199 | - 'type' => 'acf', |
|
200 | - 'field_obj' => $field |
|
201 | - ); |
|
202 | - } |
|
197 | + function add_acf_field($field){ |
|
198 | + $this->fields[$field->post_name] = array( |
|
199 | + 'type' => 'acf', |
|
200 | + 'field_obj' => $field |
|
201 | + ); |
|
202 | + } |
|
203 | 203 | |
204 | - private $acfGroups = array(); |
|
204 | + private $acfGroups = array(); |
|
205 | 205 | |
206 | - function use_acf_group($acf_group){ |
|
207 | - $this->add_text( |
|
208 | - '<div class="postbox acf_postbox default acf_signle_group rad4"> |
|
206 | + function use_acf_group($acf_group){ |
|
207 | + $this->add_text( |
|
208 | + '<div class="postbox acf_postbox default acf_signle_group rad4"> |
|
209 | 209 | <h3 class="hndle" style="margin-top:0;"><span>'.$acf_group['title'].'</span></h3> |
210 | 210 | <div class="inside">'); |
211 | - $acf_fields = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf-field', 'post_parent' => $acf_group['ID'], 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC')); |
|
212 | - if (!empty($acf_fields)){ |
|
213 | - foreach ($acf_fields as $field) { |
|
214 | - $this->add_acf_field($field); |
|
215 | - } |
|
216 | - } |
|
217 | - $this->add_text('</div></div>'); |
|
218 | - $this->acfGroups[] = $acf_group['ID']; |
|
219 | - add_filter('wp_all_import_acf_is_show_group', array($this, 'acf_is_show_group'), 10, 2); |
|
220 | - } |
|
221 | - |
|
222 | - function acf_is_show_group($is_show, $acf_group){ |
|
223 | - return (in_array($acf_group['ID'], $this->acfGroups)) ? false : true; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * |
|
228 | - * Add an option to WP All Import options list |
|
229 | - * |
|
230 | - * @param string $slug - option name |
|
231 | - * @param string $default_value - default option value |
|
232 | - * |
|
233 | - */ |
|
234 | - function add_option($slug, $default_value = ''){ |
|
235 | - $this->options[$slug] = $default_value; |
|
236 | - } |
|
211 | + $acf_fields = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf-field', 'post_parent' => $acf_group['ID'], 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC')); |
|
212 | + if (!empty($acf_fields)){ |
|
213 | + foreach ($acf_fields as $field) { |
|
214 | + $this->add_acf_field($field); |
|
215 | + } |
|
216 | + } |
|
217 | + $this->add_text('</div></div>'); |
|
218 | + $this->acfGroups[] = $acf_group['ID']; |
|
219 | + add_filter('wp_all_import_acf_is_show_group', array($this, 'acf_is_show_group'), 10, 2); |
|
220 | + } |
|
237 | 221 | |
238 | - function options_array() { |
|
222 | + function acf_is_show_group($is_show, $acf_group){ |
|
223 | + return (in_array($acf_group['ID'], $this->acfGroups)) ? false : true; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * |
|
228 | + * Add an option to WP All Import options list |
|
229 | + * |
|
230 | + * @param string $slug - option name |
|
231 | + * @param string $default_value - default option value |
|
232 | + * |
|
233 | + */ |
|
234 | + function add_option($slug, $default_value = ''){ |
|
235 | + $this->options[$slug] = $default_value; |
|
236 | + } |
|
237 | + |
|
238 | + function options_array() { |
|
239 | 239 | |
240 | 240 | $options_list = array(); |
241 | 241 | |
@@ -255,528 +255,528 @@ discard block |
||
255 | 255 | |
256 | 256 | } |
257 | 257 | |
258 | - if ( ! empty($this->options) ){ |
|
259 | - foreach ($this->options as $slug => $value) { |
|
260 | - $options_arr[$slug] = $value; |
|
261 | - } |
|
262 | - } |
|
258 | + if ( ! empty($this->options) ){ |
|
259 | + foreach ($this->options as $slug => $value) { |
|
260 | + $options_arr[$slug] = $value; |
|
261 | + } |
|
262 | + } |
|
263 | 263 | |
264 | - $options_arr[$this->slug] = $options_list; |
|
265 | - $options_arr['rapid_addon'] = plugin_basename( __FILE__ ); |
|
264 | + $options_arr[$this->slug] = $options_list; |
|
265 | + $options_arr['rapid_addon'] = plugin_basename( __FILE__ ); |
|
266 | 266 | |
267 | - return $options_arr; |
|
267 | + return $options_arr; |
|
268 | 268 | |
269 | - } |
|
269 | + } |
|
270 | 270 | |
271 | - function wpai_api_options($all_options) { |
|
271 | + function wpai_api_options($all_options) { |
|
272 | 272 | |
273 | - $all_options = $all_options + $this->options_array(); |
|
273 | + $all_options = $all_options + $this->options_array(); |
|
274 | 274 | |
275 | - return $all_options; |
|
275 | + return $all_options; |
|
276 | 276 | |
277 | - } |
|
277 | + } |
|
278 | 278 | |
279 | 279 | |
280 | - function wpai_api_register($addons) { |
|
280 | + function wpai_api_register($addons) { |
|
281 | 281 | |
282 | - if (empty($addons[$this->slug])) { |
|
283 | - $addons[$this->slug] = 1; |
|
284 | - } |
|
282 | + if (empty($addons[$this->slug])) { |
|
283 | + $addons[$this->slug] = 1; |
|
284 | + } |
|
285 | 285 | |
286 | - return $addons; |
|
286 | + return $addons; |
|
287 | 287 | |
288 | - } |
|
288 | + } |
|
289 | 289 | |
290 | 290 | |
291 | - function wpai_api_parse($functions) { |
|
291 | + function wpai_api_parse($functions) { |
|
292 | 292 | |
293 | - $functions[$this->slug] = array($this, 'parse'); |
|
294 | - return $functions; |
|
293 | + $functions[$this->slug] = array($this, 'parse'); |
|
294 | + return $functions; |
|
295 | 295 | |
296 | - } |
|
296 | + } |
|
297 | 297 | |
298 | - function wpai_api_post_saved($functions){ |
|
299 | - $functions[$this->slug] = array($this, 'post_saved'); |
|
300 | - return $functions; |
|
301 | - } |
|
298 | + function wpai_api_post_saved($functions){ |
|
299 | + $functions[$this->slug] = array($this, 'post_saved'); |
|
300 | + return $functions; |
|
301 | + } |
|
302 | 302 | |
303 | 303 | |
304 | - function wpai_api_import($functions) { |
|
304 | + function wpai_api_import($functions) { |
|
305 | 305 | |
306 | - $functions[$this->slug] = array($this, 'import'); |
|
307 | - return $functions; |
|
306 | + $functions[$this->slug] = array($this, 'import'); |
|
307 | + return $functions; |
|
308 | 308 | |
309 | - } |
|
309 | + } |
|
310 | 310 | |
311 | - function post_saved( $importData ){ |
|
311 | + function post_saved( $importData ){ |
|
312 | 312 | |
313 | - if (is_callable($this->post_saved_function)) |
|
314 | - call_user_func($this->post_saved_function, $importData['pid'], $importData['import'], $importData['logger']); |
|
313 | + if (is_callable($this->post_saved_function)) |
|
314 | + call_user_func($this->post_saved_function, $importData['pid'], $importData['import'], $importData['logger']); |
|
315 | 315 | |
316 | - } |
|
316 | + } |
|
317 | 317 | |
318 | - function import($importData, $parsedData) { |
|
318 | + function import($importData, $parsedData) { |
|
319 | 319 | |
320 | - if (!$this->is_active_addon($importData['post_type'])) { |
|
321 | - return; |
|
322 | - } |
|
320 | + if (!$this->is_active_addon($importData['post_type'])) { |
|
321 | + return; |
|
322 | + } |
|
323 | 323 | |
324 | - $import_options = $importData['import']['options'][$this->slug]; |
|
324 | + $import_options = $importData['import']['options'][$this->slug]; |
|
325 | 325 | |
326 | - // echo "<pre>"; |
|
327 | - // print_r($import_options); |
|
328 | - // echo "</pre>"; |
|
326 | + // echo "<pre>"; |
|
327 | + // print_r($import_options); |
|
328 | + // echo "</pre>"; |
|
329 | 329 | |
330 | - if ( ! empty($parsedData) ) { |
|
330 | + if ( ! empty($parsedData) ) { |
|
331 | 331 | |
332 | - $this->logger = $importData['logger']; |
|
332 | + $this->logger = $importData['logger']; |
|
333 | 333 | |
334 | - $post_id = $importData['pid']; |
|
335 | - $index = $importData['i']; |
|
336 | - $data = array(); |
|
337 | - if (!empty($this->fields)){ |
|
338 | - foreach ($this->fields as $field_slug => $field_params) { |
|
339 | - if (in_array($field_params['type'], array('title', 'plain_text'))) continue; |
|
340 | - switch ($field_params['type']) { |
|
334 | + $post_id = $importData['pid']; |
|
335 | + $index = $importData['i']; |
|
336 | + $data = array(); |
|
337 | + if (!empty($this->fields)){ |
|
338 | + foreach ($this->fields as $field_slug => $field_params) { |
|
339 | + if (in_array($field_params['type'], array('title', 'plain_text'))) continue; |
|
340 | + switch ($field_params['type']) { |
|
341 | 341 | |
342 | - case 'image': |
|
342 | + case 'image': |
|
343 | 343 | |
344 | - // import the specified image, then set the value of the field to the image ID in the media library |
|
344 | + // import the specified image, then set the value of the field to the image ID in the media library |
|
345 | 345 | |
346 | - $image_url_or_path = $parsedData[$field_slug][$index]; |
|
346 | + $image_url_or_path = $parsedData[$field_slug][$index]; |
|
347 | 347 | |
348 | - if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) { |
|
349 | - continue 2; |
|
350 | - } |
|
348 | + if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) { |
|
349 | + continue 2; |
|
350 | + } |
|
351 | 351 | |
352 | - $download = $import_options['download_image'][$field_slug]; |
|
352 | + $download = $import_options['download_image'][$field_slug]; |
|
353 | 353 | |
354 | - $uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "images", true, $importData['articleData']); |
|
354 | + $uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "images", true, $importData['articleData']); |
|
355 | 355 | |
356 | - $data[$field_slug] = array( |
|
357 | - "attachment_id" => $uploaded_image, |
|
358 | - "image_url_or_path" => $image_url_or_path, |
|
359 | - "download" => $download |
|
360 | - ); |
|
356 | + $data[$field_slug] = array( |
|
357 | + "attachment_id" => $uploaded_image, |
|
358 | + "image_url_or_path" => $image_url_or_path, |
|
359 | + "download" => $download |
|
360 | + ); |
|
361 | 361 | |
362 | - break; |
|
362 | + break; |
|
363 | 363 | |
364 | - case 'file': |
|
364 | + case 'file': |
|
365 | 365 | |
366 | - $image_url_or_path = $parsedData[$field_slug][$index]; |
|
366 | + $image_url_or_path = $parsedData[$field_slug][$index]; |
|
367 | 367 | |
368 | - if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) { |
|
369 | - continue 2; |
|
370 | - } |
|
368 | + if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) { |
|
369 | + continue 2; |
|
370 | + } |
|
371 | 371 | |
372 | - $download = $import_options['download_image'][$field_slug]; |
|
372 | + $download = $import_options['download_image'][$field_slug]; |
|
373 | 373 | |
374 | - $uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files", true, $importData['articleData']); |
|
374 | + $uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files", true, $importData['articleData']); |
|
375 | 375 | |
376 | - $data[$field_slug] = array( |
|
377 | - "attachment_id" => $uploaded_file, |
|
378 | - "image_url_or_path" => $image_url_or_path, |
|
379 | - "download" => $download |
|
380 | - ); |
|
376 | + $data[$field_slug] = array( |
|
377 | + "attachment_id" => $uploaded_file, |
|
378 | + "image_url_or_path" => $image_url_or_path, |
|
379 | + "download" => $download |
|
380 | + ); |
|
381 | 381 | |
382 | - break; |
|
382 | + break; |
|
383 | 383 | |
384 | - default: |
|
385 | - // set the field data to the value of the field after it's been parsed |
|
386 | - $data[$field_slug] = $parsedData[$field_slug][$index]; |
|
387 | - break; |
|
388 | - } |
|
384 | + default: |
|
385 | + // set the field data to the value of the field after it's been parsed |
|
386 | + $data[$field_slug] = $parsedData[$field_slug][$index]; |
|
387 | + break; |
|
388 | + } |
|
389 | + |
|
390 | + // apply mapping rules if they exist |
|
391 | + if (!empty($import_options['mapping'][$field_slug])) { |
|
392 | + $mapping_rules = json_decode($import_options['mapping'][$field_slug], true); |
|
393 | + |
|
394 | + if (!empty($mapping_rules) and is_array($mapping_rules)) { |
|
395 | + foreach ($mapping_rules as $rule_number => $map_to) { |
|
396 | + if (isset($map_to[trim($data[$field_slug])])){ |
|
397 | + $data[$field_slug] = trim($map_to[trim($data[$field_slug])]); |
|
398 | + break; |
|
399 | + } |
|
400 | + } |
|
401 | + } |
|
402 | + } |
|
403 | + // -------------------- |
|
404 | + } |
|
405 | + } |
|
389 | 406 | |
390 | - // apply mapping rules if they exist |
|
391 | - if (!empty($import_options['mapping'][$field_slug])) { |
|
392 | - $mapping_rules = json_decode($import_options['mapping'][$field_slug], true); |
|
407 | + call_user_func($this->import_function, $post_id, $data, $importData['import'], $importData['articleData'], $importData['logger']); |
|
408 | + } |
|
393 | 409 | |
394 | - if (!empty($mapping_rules) and is_array($mapping_rules)) { |
|
395 | - foreach ($mapping_rules as $rule_number => $map_to) { |
|
396 | - if (isset($map_to[trim($data[$field_slug])])){ |
|
397 | - $data[$field_slug] = trim($map_to[trim($data[$field_slug])]); |
|
398 | - break; |
|
399 | - } |
|
400 | - } |
|
401 | - } |
|
402 | - } |
|
403 | - // -------------------- |
|
404 | - } |
|
405 | - } |
|
410 | + } |
|
406 | 411 | |
407 | - call_user_func($this->import_function, $post_id, $data, $importData['import'], $importData['articleData'], $importData['logger']); |
|
408 | - } |
|
409 | 412 | |
410 | - } |
|
413 | + function wpai_api_metabox($post_type, $current_values) { |
|
411 | 414 | |
415 | + if (!$this->is_active_addon($post_type)) { |
|
416 | + return; |
|
417 | + } |
|
412 | 418 | |
413 | - function wpai_api_metabox($post_type, $current_values) { |
|
419 | + echo $this->helper_metabox_top($this->name); |
|
414 | 420 | |
415 | - if (!$this->is_active_addon($post_type)) { |
|
416 | - return; |
|
417 | - } |
|
421 | + $visible_fields = 0; |
|
418 | 422 | |
419 | - echo $this->helper_metabox_top($this->name); |
|
423 | + foreach ($this->fields as $field_slug => $field_params) { |
|
424 | + if ($field_params['is_sub_field']) continue; |
|
425 | + $visible_fields++; |
|
426 | + } |
|
420 | 427 | |
421 | - $visible_fields = 0; |
|
428 | + $counter = 0; |
|
422 | 429 | |
423 | - foreach ($this->fields as $field_slug => $field_params) { |
|
424 | - if ($field_params['is_sub_field']) continue; |
|
425 | - $visible_fields++; |
|
426 | - } |
|
430 | + foreach ($this->fields as $field_slug => $field_params) { |
|
427 | 431 | |
428 | - $counter = 0; |
|
432 | + // do not render sub fields |
|
433 | + if ($field_params['is_sub_field']) continue; |
|
429 | 434 | |
430 | - foreach ($this->fields as $field_slug => $field_params) { |
|
435 | + $counter++; |
|
431 | 436 | |
432 | - // do not render sub fields |
|
433 | - if ($field_params['is_sub_field']) continue; |
|
437 | + $this->render_field($field_params, $field_slug, $current_values, $visible_fields == $counter); |
|
434 | 438 | |
435 | - $counter++; |
|
439 | + //if ( $field_params['type'] != 'accordion' ) echo "<br />"; |
|
436 | 440 | |
437 | - $this->render_field($field_params, $field_slug, $current_values, $visible_fields == $counter); |
|
441 | + } |
|
438 | 442 | |
439 | - //if ( $field_params['type'] != 'accordion' ) echo "<br />"; |
|
443 | + echo $this->helper_metabox_bottom(); |
|
444 | + |
|
445 | + if ( ! empty($this->image_sections) ){ |
|
446 | + $is_images_section_enabled = apply_filters('wp_all_import_is_images_section_enabled', true, $post_type); |
|
447 | + foreach ($this->image_sections as $k => $section) { |
|
448 | + $section_options = array(); |
|
449 | + foreach ($this->image_options as $slug => $value) { |
|
450 | + $section_options[$section['slug'] . $slug] = $value; |
|
451 | + } |
|
452 | + if ( ! $is_images_section_enabled and ! $k ){ |
|
453 | + $section_options[$section['slug'] . 'is_featured'] = 1; |
|
454 | + } |
|
455 | + PMXI_API::add_additional_images_section($section['title'], $section['slug'], $current_values, '', true, false, $section['type']); |
|
456 | + } |
|
457 | + } |
|
440 | 458 | |
441 | - } |
|
459 | + } |
|
442 | 460 | |
443 | - echo $this->helper_metabox_bottom(); |
|
461 | + function render_field($field_params, $field_slug, $current_values, $in_the_bottom = false){ |
|
444 | 462 | |
445 | - if ( ! empty($this->image_sections) ){ |
|
446 | - $is_images_section_enabled = apply_filters('wp_all_import_is_images_section_enabled', true, $post_type); |
|
447 | - foreach ($this->image_sections as $k => $section) { |
|
448 | - $section_options = array(); |
|
449 | - foreach ($this->image_options as $slug => $value) { |
|
450 | - $section_options[$section['slug'] . $slug] = $value; |
|
451 | - } |
|
452 | - if ( ! $is_images_section_enabled and ! $k ){ |
|
453 | - $section_options[$section['slug'] . 'is_featured'] = 1; |
|
454 | - } |
|
455 | - PMXI_API::add_additional_images_section($section['title'], $section['slug'], $current_values, '', true, false, $section['type']); |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - } |
|
460 | - |
|
461 | - function render_field($field_params, $field_slug, $current_values, $in_the_bottom = false){ |
|
462 | - |
|
463 | - if (!isset($current_values[$this->slug][$field_slug])) { |
|
464 | - $current_values[$this->slug][$field_slug] = isset($field_params['default_text']) ? $field_params['default_text'] : ''; |
|
465 | - } |
|
466 | - |
|
467 | - if ($field_params['type'] == 'text') { |
|
468 | - |
|
469 | - PMXI_API::add_field( |
|
470 | - 'simple', |
|
471 | - $field_params['name'], |
|
472 | - array( |
|
473 | - 'tooltip' => $field_params['tooltip'], |
|
474 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
475 | - 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
476 | - ) |
|
477 | - ); |
|
478 | - |
|
479 | - } else if ($field_params['type'] == 'textarea') { |
|
480 | - |
|
481 | - PMXI_API::add_field( |
|
482 | - 'textarea', |
|
483 | - $field_params['name'], |
|
484 | - array( |
|
485 | - 'tooltip' => $field_params['tooltip'], |
|
486 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
487 | - 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
488 | - ) |
|
489 | - ); |
|
490 | - |
|
491 | - } else if ($field_params['type'] == 'wp_editor') { |
|
492 | - |
|
493 | - PMXI_API::add_field( |
|
494 | - 'wp_editor', |
|
495 | - $field_params['name'], |
|
496 | - array( |
|
497 | - 'tooltip' => $field_params['tooltip'], |
|
498 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
499 | - 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
500 | - ) |
|
501 | - ); |
|
502 | - |
|
503 | - } else if ($field_params['type'] == 'image' or $field_params['type'] == 'file') { |
|
463 | + if (!isset($current_values[$this->slug][$field_slug])) { |
|
464 | + $current_values[$this->slug][$field_slug] = isset($field_params['default_text']) ? $field_params['default_text'] : ''; |
|
465 | + } |
|
466 | + |
|
467 | + if ($field_params['type'] == 'text') { |
|
468 | + |
|
469 | + PMXI_API::add_field( |
|
470 | + 'simple', |
|
471 | + $field_params['name'], |
|
472 | + array( |
|
473 | + 'tooltip' => $field_params['tooltip'], |
|
474 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
475 | + 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
476 | + ) |
|
477 | + ); |
|
478 | + |
|
479 | + } else if ($field_params['type'] == 'textarea') { |
|
480 | + |
|
481 | + PMXI_API::add_field( |
|
482 | + 'textarea', |
|
483 | + $field_params['name'], |
|
484 | + array( |
|
485 | + 'tooltip' => $field_params['tooltip'], |
|
486 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
487 | + 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
488 | + ) |
|
489 | + ); |
|
490 | + |
|
491 | + } else if ($field_params['type'] == 'wp_editor') { |
|
492 | + |
|
493 | + PMXI_API::add_field( |
|
494 | + 'wp_editor', |
|
495 | + $field_params['name'], |
|
496 | + array( |
|
497 | + 'tooltip' => $field_params['tooltip'], |
|
498 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
499 | + 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
500 | + ) |
|
501 | + ); |
|
502 | + |
|
503 | + } else if ($field_params['type'] == 'image' or $field_params['type'] == 'file') { |
|
504 | 504 | |
505 | - if (!isset($current_values[$this->slug]['download_image'][$field_slug])) { $current_values[$this->slug]['download_image'][$field_slug] = ''; } |
|
506 | - |
|
507 | - PMXI_API::add_field( |
|
508 | - $field_params['type'], |
|
509 | - $field_params['name'], |
|
510 | - array( |
|
511 | - 'tooltip' => $field_params['tooltip'], |
|
512 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
513 | - 'field_value' => $current_values[$this->slug][$field_slug], |
|
514 | - 'download_image' => $current_values[$this->slug]['download_image'][$field_slug], |
|
515 | - 'field_key' => $field_slug, |
|
516 | - 'addon_prefix' => $this->slug |
|
517 | - |
|
518 | - ) |
|
519 | - ); |
|
520 | - |
|
521 | - } else if ($field_params['type'] == 'radio') { |
|
505 | + if (!isset($current_values[$this->slug]['download_image'][$field_slug])) { $current_values[$this->slug]['download_image'][$field_slug] = ''; } |
|
506 | + |
|
507 | + PMXI_API::add_field( |
|
508 | + $field_params['type'], |
|
509 | + $field_params['name'], |
|
510 | + array( |
|
511 | + 'tooltip' => $field_params['tooltip'], |
|
512 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
513 | + 'field_value' => $current_values[$this->slug][$field_slug], |
|
514 | + 'download_image' => $current_values[$this->slug]['download_image'][$field_slug], |
|
515 | + 'field_key' => $field_slug, |
|
516 | + 'addon_prefix' => $this->slug |
|
517 | + |
|
518 | + ) |
|
519 | + ); |
|
520 | + |
|
521 | + } else if ($field_params['type'] == 'radio') { |
|
522 | 522 | |
523 | - if (!isset($current_values[$this->slug]['mapping'][$field_slug])) { $current_values[$this->slug]['mapping'][$field_slug] = array(); } |
|
524 | - if (!isset($current_values[$this->slug]['xpaths'][$field_slug])) { $current_values[$this->slug]['xpaths'][$field_slug] = ''; } |
|
525 | - |
|
526 | - PMXI_API::add_field( |
|
527 | - 'enum', |
|
528 | - $field_params['name'], |
|
529 | - array( |
|
530 | - 'tooltip' => $field_params['tooltip'], |
|
531 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
532 | - 'field_value' => $current_values[$this->slug][$field_slug], |
|
533 | - 'enum_values' => $field_params['enum_values'], |
|
534 | - 'mapping' => true, |
|
535 | - 'field_key' => $field_slug, |
|
536 | - 'mapping_rules' => $current_values[$this->slug]['mapping'][$field_slug], |
|
537 | - 'xpath' => $current_values[$this->slug]['xpaths'][$field_slug], |
|
538 | - 'addon_prefix' => $this->slug, |
|
539 | - 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values) |
|
540 | - ) |
|
541 | - ); |
|
542 | - |
|
543 | - } else if($field_params['type'] == 'accordion') { |
|
544 | - |
|
545 | - PMXI_API::add_field( |
|
546 | - 'accordion', |
|
547 | - $field_params['name'], |
|
548 | - array( |
|
549 | - 'tooltip' => $field_params['tooltip'], |
|
550 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
551 | - 'field_key' => $field_slug, |
|
552 | - 'addon_prefix' => $this->slug, |
|
553 | - 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values), |
|
554 | - 'in_the_bottom' => $in_the_bottom |
|
555 | - ) |
|
556 | - ); |
|
557 | - |
|
558 | - } else if($field_params['type'] == 'acf') { |
|
559 | - $fieldData = (!empty($field_params['field_obj']->post_content)) ? unserialize($field_params['field_obj']->post_content) : array(); |
|
560 | - $fieldData['ID'] = $field_params['field_obj']->ID; |
|
561 | - $fieldData['id'] = $field_params['field_obj']->ID; |
|
562 | - $fieldData['label'] = $field_params['field_obj']->post_title; |
|
563 | - $fieldData['key'] = $field_params['field_obj']->post_name; |
|
564 | - if (empty($fieldData['name'])) $fieldData['name'] = $field_params['field_obj']->post_excerpt; |
|
565 | - if (function_exists('pmai_render_field')) { |
|
566 | - echo pmai_render_field($fieldData, ( ! empty($current_values) ) ? $current_values : array() ); |
|
567 | - } |
|
568 | - } else if($field_params['type'] == 'title'){ |
|
569 | - ?> |
|
523 | + if (!isset($current_values[$this->slug]['mapping'][$field_slug])) { $current_values[$this->slug]['mapping'][$field_slug] = array(); } |
|
524 | + if (!isset($current_values[$this->slug]['xpaths'][$field_slug])) { $current_values[$this->slug]['xpaths'][$field_slug] = ''; } |
|
525 | + |
|
526 | + PMXI_API::add_field( |
|
527 | + 'enum', |
|
528 | + $field_params['name'], |
|
529 | + array( |
|
530 | + 'tooltip' => $field_params['tooltip'], |
|
531 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
532 | + 'field_value' => $current_values[$this->slug][$field_slug], |
|
533 | + 'enum_values' => $field_params['enum_values'], |
|
534 | + 'mapping' => true, |
|
535 | + 'field_key' => $field_slug, |
|
536 | + 'mapping_rules' => $current_values[$this->slug]['mapping'][$field_slug], |
|
537 | + 'xpath' => $current_values[$this->slug]['xpaths'][$field_slug], |
|
538 | + 'addon_prefix' => $this->slug, |
|
539 | + 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values) |
|
540 | + ) |
|
541 | + ); |
|
542 | + |
|
543 | + } else if($field_params['type'] == 'accordion') { |
|
544 | + |
|
545 | + PMXI_API::add_field( |
|
546 | + 'accordion', |
|
547 | + $field_params['name'], |
|
548 | + array( |
|
549 | + 'tooltip' => $field_params['tooltip'], |
|
550 | + 'field_name' => $this->slug."[".$field_slug."]", |
|
551 | + 'field_key' => $field_slug, |
|
552 | + 'addon_prefix' => $this->slug, |
|
553 | + 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values), |
|
554 | + 'in_the_bottom' => $in_the_bottom |
|
555 | + ) |
|
556 | + ); |
|
557 | + |
|
558 | + } else if($field_params['type'] == 'acf') { |
|
559 | + $fieldData = (!empty($field_params['field_obj']->post_content)) ? unserialize($field_params['field_obj']->post_content) : array(); |
|
560 | + $fieldData['ID'] = $field_params['field_obj']->ID; |
|
561 | + $fieldData['id'] = $field_params['field_obj']->ID; |
|
562 | + $fieldData['label'] = $field_params['field_obj']->post_title; |
|
563 | + $fieldData['key'] = $field_params['field_obj']->post_name; |
|
564 | + if (empty($fieldData['name'])) $fieldData['name'] = $field_params['field_obj']->post_excerpt; |
|
565 | + if (function_exists('pmai_render_field')) { |
|
566 | + echo pmai_render_field($fieldData, ( ! empty($current_values) ) ? $current_values : array() ); |
|
567 | + } |
|
568 | + } else if($field_params['type'] == 'title'){ |
|
569 | + ?> |
|
570 | 570 | <h4 class="wpallimport-add-on-options-title"><?php _e($field_params['name'], 'wp_all_import_plugin'); ?><?php if ( ! empty($field_params['tooltip'])): ?><a href="#help" class="wpallimport-help" title="<?php echo $field_params['tooltip']; ?>" style="position:relative; top: -1px;">?</a><?php endif; ?></h4> |
571 | 571 | <?php |
572 | 572 | |
573 | - } else if($field_params['type'] == 'plain_text'){ |
|
574 | - if ($field_params['is_html']): |
|
575 | - echo $field_params['name']; |
|
576 | - else: |
|
577 | - ?> |
|
573 | + } else if($field_params['type'] == 'plain_text'){ |
|
574 | + if ($field_params['is_html']): |
|
575 | + echo $field_params['name']; |
|
576 | + else: |
|
577 | + ?> |
|
578 | 578 | <p style="margin: 0 0 12px 0;"><?php echo $field_params['name'];?></p> |
579 | 579 | <?php |
580 | - endif; |
|
581 | - } |
|
580 | + endif; |
|
581 | + } |
|
582 | 582 | |
583 | 583 | |
584 | - } |
|
585 | - /** |
|
586 | - * |
|
587 | - * Helper function for nested radio fields |
|
588 | - * |
|
589 | - */ |
|
590 | - function get_sub_fields($field_params, $field_slug, $current_values){ |
|
591 | - $sub_fields = array(); |
|
592 | - if ( ! empty($field_params['enum_values']) ){ |
|
593 | - foreach ($field_params['enum_values'] as $key => $value) { |
|
594 | - $sub_fields[$key] = array(); |
|
595 | - if (is_array($value)){ |
|
596 | - if ($field_params['type'] == 'accordion'){ |
|
597 | - $sub_fields[$key][] = $this->convert_field($value, $current_values); |
|
598 | - } |
|
599 | - else |
|
600 | - { |
|
601 | - foreach ($value as $k => $sub_field) { |
|
602 | - if (is_array($sub_field) and ! empty($this->fields[$sub_field['slug']])) |
|
603 | - { |
|
604 | - $sub_fields[$key][] = $this->convert_field($sub_field, $current_values); |
|
605 | - } |
|
606 | - } |
|
607 | - } |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - return $sub_fields; |
|
612 | - } |
|
613 | - |
|
614 | - function convert_field($sub_field, $current_values){ |
|
615 | - $field = array(); |
|
616 | - if (!isset($current_values[$this->slug][$sub_field['slug']])) { |
|
617 | - $current_values[$this->slug][$sub_field['slug']] = isset($sub_field['default_text']) ? $sub_field['default_text'] : ''; |
|
618 | - } |
|
619 | - switch ($this->fields[$sub_field['slug']]['type']) { |
|
620 | - case 'text': |
|
621 | - $field = array( |
|
622 | - 'type' => 'simple', |
|
623 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
624 | - 'params' => array( |
|
625 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
626 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
627 | - 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
628 | - 'is_main_field' => $sub_field['is_main_field'] |
|
629 | - ) |
|
630 | - ); |
|
631 | - break; |
|
632 | - case 'textarea': |
|
633 | - $field = array( |
|
634 | - 'type' => 'textarea', |
|
635 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
636 | - 'params' => array( |
|
637 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
638 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
639 | - 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
640 | - 'is_main_field' => $sub_field['is_main_field'] |
|
641 | - ) |
|
642 | - ); |
|
643 | - break; |
|
644 | - case 'wp_editor': |
|
645 | - $field = array( |
|
646 | - 'type' => 'wp_editor', |
|
647 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
648 | - 'params' => array( |
|
649 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
650 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
651 | - 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
652 | - 'is_main_field' => $sub_field['is_main_field'] |
|
653 | - ) |
|
654 | - ); |
|
655 | - break; |
|
656 | - case 'image': |
|
657 | - $field = array( |
|
658 | - 'type' => 'image', |
|
659 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
660 | - 'params' => array( |
|
661 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
662 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
663 | - 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
664 | - 'download_image' => null, |
|
665 | - 'field_key' => $sub_field['slug'], |
|
666 | - 'addon_prefix' => $this->slug, |
|
667 | - 'is_main_field' => $sub_field['is_main_field'] |
|
668 | - ) |
|
669 | - ); |
|
670 | - |
|
671 | - if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) { |
|
672 | - $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']]; |
|
673 | - } |
|
584 | + } |
|
585 | + /** |
|
586 | + * |
|
587 | + * Helper function for nested radio fields |
|
588 | + * |
|
589 | + */ |
|
590 | + function get_sub_fields($field_params, $field_slug, $current_values){ |
|
591 | + $sub_fields = array(); |
|
592 | + if ( ! empty($field_params['enum_values']) ){ |
|
593 | + foreach ($field_params['enum_values'] as $key => $value) { |
|
594 | + $sub_fields[$key] = array(); |
|
595 | + if (is_array($value)){ |
|
596 | + if ($field_params['type'] == 'accordion'){ |
|
597 | + $sub_fields[$key][] = $this->convert_field($value, $current_values); |
|
598 | + } |
|
599 | + else |
|
600 | + { |
|
601 | + foreach ($value as $k => $sub_field) { |
|
602 | + if (is_array($sub_field) and ! empty($this->fields[$sub_field['slug']])) |
|
603 | + { |
|
604 | + $sub_fields[$key][] = $this->convert_field($sub_field, $current_values); |
|
605 | + } |
|
606 | + } |
|
607 | + } |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + return $sub_fields; |
|
612 | + } |
|
613 | + |
|
614 | + function convert_field($sub_field, $current_values){ |
|
615 | + $field = array(); |
|
616 | + if (!isset($current_values[$this->slug][$sub_field['slug']])) { |
|
617 | + $current_values[$this->slug][$sub_field['slug']] = isset($sub_field['default_text']) ? $sub_field['default_text'] : ''; |
|
618 | + } |
|
619 | + switch ($this->fields[$sub_field['slug']]['type']) { |
|
620 | + case 'text': |
|
621 | + $field = array( |
|
622 | + 'type' => 'simple', |
|
623 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
624 | + 'params' => array( |
|
625 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
626 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
627 | + 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
628 | + 'is_main_field' => $sub_field['is_main_field'] |
|
629 | + ) |
|
630 | + ); |
|
674 | 631 | break; |
675 | - case 'file': |
|
676 | - $field = array( |
|
677 | - 'type' => 'file', |
|
678 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
679 | - 'params' => array( |
|
680 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
681 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
682 | - 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
683 | - 'download_image' => null, |
|
684 | - 'field_key' => $sub_field['slug'], |
|
685 | - 'addon_prefix' => $this->slug, |
|
686 | - 'is_main_field' => $sub_field['is_main_field'] |
|
687 | - ) |
|
688 | - ); |
|
689 | - |
|
690 | - if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) { |
|
691 | - $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']]; |
|
692 | - } |
|
693 | - |
|
694 | - break; |
|
695 | - case 'radio': |
|
696 | - $field = array( |
|
697 | - 'type' => 'enum', |
|
698 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
699 | - 'params' => array( |
|
700 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
701 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
702 | - 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
703 | - 'enum_values' => $this->fields[$sub_field['slug']]['enum_values'], |
|
704 | - 'mapping' => true, |
|
705 | - 'field_key' => $sub_field['slug'], |
|
706 | - 'mapping_rules' => isset($current_values[$this->slug]['mapping'][$sub_field['slug']]) ? $current_values[$this->slug]['mapping'][$sub_field['slug']] : array(), |
|
707 | - 'xpath' => isset($current_values[$this->slug]['xpaths'][$sub_field['slug']]) ? $current_values[$this->slug]['xpaths'][$sub_field['slug']] : '', |
|
708 | - 'addon_prefix' => $this->slug, |
|
709 | - 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values), |
|
710 | - 'is_main_field' => $sub_field['is_main_field'] |
|
711 | - ) |
|
712 | - ); |
|
713 | - break; |
|
714 | - case 'accordion': |
|
715 | - $field = array( |
|
716 | - 'type' => 'accordion', |
|
717 | - 'label' => $this->fields[$sub_field['slug']]['name'], |
|
718 | - 'params' => array( |
|
719 | - 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
720 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
721 | - 'field_key' => $sub_field['slug'], |
|
722 | - 'addon_prefix' => $this->slug, |
|
723 | - 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values), |
|
724 | - 'in_the_bottom' => false |
|
725 | - ) |
|
726 | - ); |
|
727 | - break; |
|
728 | - default: |
|
729 | - # code... |
|
730 | - break; |
|
731 | - } |
|
732 | - return $field; |
|
733 | - } |
|
734 | - |
|
735 | - /** |
|
736 | - * |
|
737 | - * Add accordion options |
|
738 | - * |
|
739 | - * |
|
740 | - */ |
|
741 | - function add_options( $main_field = false, $title = '', $fields = array() ){ |
|
632 | + case 'textarea': |
|
633 | + $field = array( |
|
634 | + 'type' => 'textarea', |
|
635 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
636 | + 'params' => array( |
|
637 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
638 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
639 | + 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
640 | + 'is_main_field' => $sub_field['is_main_field'] |
|
641 | + ) |
|
642 | + ); |
|
643 | + break; |
|
644 | + case 'wp_editor': |
|
645 | + $field = array( |
|
646 | + 'type' => 'wp_editor', |
|
647 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
648 | + 'params' => array( |
|
649 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
650 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
651 | + 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
|
652 | + 'is_main_field' => $sub_field['is_main_field'] |
|
653 | + ) |
|
654 | + ); |
|
655 | + break; |
|
656 | + case 'image': |
|
657 | + $field = array( |
|
658 | + 'type' => 'image', |
|
659 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
660 | + 'params' => array( |
|
661 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
662 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
663 | + 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
664 | + 'download_image' => null, |
|
665 | + 'field_key' => $sub_field['slug'], |
|
666 | + 'addon_prefix' => $this->slug, |
|
667 | + 'is_main_field' => $sub_field['is_main_field'] |
|
668 | + ) |
|
669 | + ); |
|
670 | + |
|
671 | + if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) { |
|
672 | + $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']]; |
|
673 | + } |
|
674 | + break; |
|
675 | + case 'file': |
|
676 | + $field = array( |
|
677 | + 'type' => 'file', |
|
678 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
679 | + 'params' => array( |
|
680 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
681 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
682 | + 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
683 | + 'download_image' => null, |
|
684 | + 'field_key' => $sub_field['slug'], |
|
685 | + 'addon_prefix' => $this->slug, |
|
686 | + 'is_main_field' => $sub_field['is_main_field'] |
|
687 | + ) |
|
688 | + ); |
|
689 | + |
|
690 | + if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) { |
|
691 | + $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']]; |
|
692 | + } |
|
693 | + |
|
694 | + break; |
|
695 | + case 'radio': |
|
696 | + $field = array( |
|
697 | + 'type' => 'enum', |
|
698 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
699 | + 'params' => array( |
|
700 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
701 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
702 | + 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
|
703 | + 'enum_values' => $this->fields[$sub_field['slug']]['enum_values'], |
|
704 | + 'mapping' => true, |
|
705 | + 'field_key' => $sub_field['slug'], |
|
706 | + 'mapping_rules' => isset($current_values[$this->slug]['mapping'][$sub_field['slug']]) ? $current_values[$this->slug]['mapping'][$sub_field['slug']] : array(), |
|
707 | + 'xpath' => isset($current_values[$this->slug]['xpaths'][$sub_field['slug']]) ? $current_values[$this->slug]['xpaths'][$sub_field['slug']] : '', |
|
708 | + 'addon_prefix' => $this->slug, |
|
709 | + 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values), |
|
710 | + 'is_main_field' => $sub_field['is_main_field'] |
|
711 | + ) |
|
712 | + ); |
|
713 | + break; |
|
714 | + case 'accordion': |
|
715 | + $field = array( |
|
716 | + 'type' => 'accordion', |
|
717 | + 'label' => $this->fields[$sub_field['slug']]['name'], |
|
718 | + 'params' => array( |
|
719 | + 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
|
720 | + 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
721 | + 'field_key' => $sub_field['slug'], |
|
722 | + 'addon_prefix' => $this->slug, |
|
723 | + 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values), |
|
724 | + 'in_the_bottom' => false |
|
725 | + ) |
|
726 | + ); |
|
727 | + break; |
|
728 | + default: |
|
729 | + # code... |
|
730 | + break; |
|
731 | + } |
|
732 | + return $field; |
|
733 | + } |
|
734 | + |
|
735 | + /** |
|
736 | + * |
|
737 | + * Add accordion options |
|
738 | + * |
|
739 | + * |
|
740 | + */ |
|
741 | + function add_options( $main_field = false, $title = '', $fields = array() ){ |
|
742 | 742 | |
743 | - if ( ! empty($fields) ) |
|
744 | - { |
|
743 | + if ( ! empty($fields) ) |
|
744 | + { |
|
745 | 745 | |
746 | - if ($main_field){ |
|
746 | + if ($main_field){ |
|
747 | 747 | |
748 | - $main_field['is_main_field'] = true; |
|
749 | - $fields[] = $main_field; |
|
748 | + $main_field['is_main_field'] = true; |
|
749 | + $fields[] = $main_field; |
|
750 | 750 | |
751 | - } |
|
751 | + } |
|
752 | 752 | |
753 | - return $this->add_field('accordion_' . $fields[0]['slug'], $title, 'accordion', $fields); |
|
753 | + return $this->add_field('accordion_' . $fields[0]['slug'], $title, 'accordion', $fields); |
|
754 | 754 | |
755 | - } |
|
755 | + } |
|
756 | 756 | |
757 | - } |
|
757 | + } |
|
758 | 758 | |
759 | - function add_title($title = '', $tooltip = ''){ |
|
759 | + function add_title($title = '', $tooltip = ''){ |
|
760 | 760 | |
761 | - if (empty($title)) return; |
|
761 | + if (empty($title)) return; |
|
762 | 762 | |
763 | - return $this->add_field(sanitize_key($title) . time(), $title, 'title', null, $tooltip); |
|
763 | + return $this->add_field(sanitize_key($title) . time(), $title, 'title', null, $tooltip); |
|
764 | 764 | |
765 | - } |
|
765 | + } |
|
766 | 766 | |
767 | - function add_text($text = '', $is_html = false){ |
|
767 | + function add_text($text = '', $is_html = false){ |
|
768 | 768 | |
769 | - if (empty($text)) return; |
|
769 | + if (empty($text)) return; |
|
770 | 770 | |
771 | - $count = is_array($this->fields) ? count($this->fields) : 0; |
|
771 | + $count = is_array($this->fields) ? count($this->fields) : 0; |
|
772 | 772 | |
773 | - return $this->add_field(sanitize_key($text) . time() . uniqid() . $count, $text, 'plain_text', null, "", $is_html); |
|
773 | + return $this->add_field(sanitize_key($text) . time() . uniqid() . $count, $text, 'plain_text', null, "", $is_html); |
|
774 | 774 | |
775 | - } |
|
775 | + } |
|
776 | 776 | |
777 | - function helper_metabox_top($name) { |
|
777 | + function helper_metabox_top($name) { |
|
778 | 778 | |
779 | - return ' |
|
779 | + return ' |
|
780 | 780 | <style type="text/css"> |
781 | 781 | .wpallimport-plugin .wpallimport-addon div.input { |
782 | 782 | margin-bottom: 15px; |
@@ -872,11 +872,11 @@ discard block |
||
872 | 872 | <table class="form-table" style="max-width:none;"> |
873 | 873 | <tr> |
874 | 874 | <td colspan="3">'; |
875 | - } |
|
875 | + } |
|
876 | 876 | |
877 | - function helper_metabox_bottom() { |
|
877 | + function helper_metabox_bottom() { |
|
878 | 878 | |
879 | - return ' </td> |
|
879 | + return ' </td> |
|
880 | 880 | </tr> |
881 | 881 | </table> |
882 | 882 | </div> |
@@ -884,298 +884,298 @@ discard block |
||
884 | 884 | </div> |
885 | 885 | </div>'; |
886 | 886 | |
887 | - } |
|
887 | + } |
|
888 | 888 | |
889 | - /** |
|
890 | - * |
|
891 | - * simply add an additional section for attachments |
|
892 | - * |
|
893 | - */ |
|
894 | - function import_files( $slug, $title, $callback = NULL ){ |
|
895 | - $this->import_images( $slug, $title, 'files', $callback); |
|
896 | - } |
|
889 | + /** |
|
890 | + * |
|
891 | + * simply add an additional section for attachments |
|
892 | + * |
|
893 | + */ |
|
894 | + function import_files( $slug, $title, $callback = NULL ){ |
|
895 | + $this->import_images( $slug, $title, 'files', $callback); |
|
896 | + } |
|
897 | 897 | |
898 | - /** |
|
899 | - * |
|
900 | - * simply add an additional section |
|
901 | - * |
|
902 | - */ |
|
903 | - function import_images( $slug, $title, $type = 'images', $callback = NULL ){ |
|
898 | + /** |
|
899 | + * |
|
900 | + * simply add an additional section |
|
901 | + * |
|
902 | + */ |
|
903 | + function import_images( $slug, $title, $type = 'images', $callback = NULL ){ |
|
904 | 904 | |
905 | - if ( empty($title) or empty($slug) ) return; |
|
905 | + if ( empty($title) or empty($slug) ) return; |
|
906 | 906 | |
907 | - if (is_array($slug)) { |
|
907 | + if (is_array($slug)) { |
|
908 | 908 | $section_slug = 'pmxi_' . md5(serialize($slug)); |
909 | 909 | } else { |
910 | 910 | $section_slug = 'pmxi_' . $slug; |
911 | 911 | } |
912 | 912 | |
913 | - $this->image_sections[] = array( |
|
914 | - 'title' => $title, |
|
915 | - 'slug' => $section_slug, |
|
916 | - 'type' => $type |
|
917 | - ); |
|
913 | + $this->image_sections[] = array( |
|
914 | + 'title' => $title, |
|
915 | + 'slug' => $section_slug, |
|
916 | + 'type' => $type |
|
917 | + ); |
|
918 | 918 | |
919 | - foreach ($this->image_options as $option_slug => $value) { |
|
920 | - $this->add_option($section_slug . $option_slug, $value); |
|
921 | - } |
|
919 | + foreach ($this->image_options as $option_slug => $value) { |
|
920 | + $this->add_option($section_slug . $option_slug, $value); |
|
921 | + } |
|
922 | 922 | |
923 | - if (count($this->image_sections) > 1){ |
|
924 | - add_filter('wp_all_import_is_show_add_new_images', array($this, 'filter_is_show_add_new_images'), 10, 2); |
|
925 | - } |
|
923 | + if (count($this->image_sections) > 1){ |
|
924 | + add_filter('wp_all_import_is_show_add_new_images', array($this, 'filter_is_show_add_new_images'), 10, 2); |
|
925 | + } |
|
926 | 926 | |
927 | - add_filter('wp_all_import_is_allow_import_images', array($this, 'is_allow_import_images'), 10, 2); |
|
927 | + add_filter('wp_all_import_is_allow_import_images', array($this, 'is_allow_import_images'), 10, 2); |
|
928 | 928 | |
929 | - if ($callback && is_callable($callback)) { |
|
929 | + if ($callback && is_callable($callback)) { |
|
930 | 930 | add_action( $section_slug, $callback, 10, 4); |
931 | 931 | } else { |
932 | 932 | if (function_exists($slug)) { |
933 | 933 | add_action( $section_slug, $slug, 10, 4); |
934 | 934 | } |
935 | 935 | } |
936 | - } |
|
937 | - /** |
|
938 | - * |
|
939 | - * filter to allow import images for free edition of WP All Import |
|
940 | - * |
|
941 | - */ |
|
942 | - function is_allow_import_images($is_allow, $post_type){ |
|
943 | - return ($this->is_active_addon($post_type)) ? true : $is_allow; |
|
944 | - } |
|
945 | - |
|
946 | - /** |
|
947 | - * |
|
948 | - * filter to control additional images sections |
|
949 | - * |
|
950 | - */ |
|
951 | - function additional_sections($sections){ |
|
952 | - if ( ! empty($this->image_sections) ){ |
|
953 | - foreach ($this->image_sections as $add_section) { |
|
954 | - $sections[] = $add_section; |
|
955 | - } |
|
956 | - } |
|
936 | + } |
|
937 | + /** |
|
938 | + * |
|
939 | + * filter to allow import images for free edition of WP All Import |
|
940 | + * |
|
941 | + */ |
|
942 | + function is_allow_import_images($is_allow, $post_type){ |
|
943 | + return ($this->is_active_addon($post_type)) ? true : $is_allow; |
|
944 | + } |
|
945 | + |
|
946 | + /** |
|
947 | + * |
|
948 | + * filter to control additional images sections |
|
949 | + * |
|
950 | + */ |
|
951 | + function additional_sections($sections){ |
|
952 | + if ( ! empty($this->image_sections) ){ |
|
953 | + foreach ($this->image_sections as $add_section) { |
|
954 | + $sections[] = $add_section; |
|
955 | + } |
|
956 | + } |
|
957 | 957 | |
958 | - return $sections; |
|
959 | - } |
|
960 | - /** |
|
961 | - * |
|
962 | - * remove the 'Don't touch existing images, append new images' when more than one image section is in use. |
|
963 | - * |
|
964 | - */ |
|
965 | - function filter_is_show_add_new_images($is_show, $post_type){ |
|
966 | - return ($this->is_active_addon($post_type)) ? false : $is_show; |
|
967 | - } |
|
968 | - |
|
969 | - /** |
|
970 | - * |
|
971 | - * disable the default images section |
|
972 | - * |
|
973 | - */ |
|
974 | - function disable_default_images($post_type = false){ |
|
958 | + return $sections; |
|
959 | + } |
|
960 | + /** |
|
961 | + * |
|
962 | + * remove the 'Don't touch existing images, append new images' when more than one image section is in use. |
|
963 | + * |
|
964 | + */ |
|
965 | + function filter_is_show_add_new_images($is_show, $post_type){ |
|
966 | + return ($this->is_active_addon($post_type)) ? false : $is_show; |
|
967 | + } |
|
968 | + |
|
969 | + /** |
|
970 | + * |
|
971 | + * disable the default images section |
|
972 | + * |
|
973 | + */ |
|
974 | + function disable_default_images($post_type = false){ |
|
975 | 975 | |
976 | - add_filter('wp_all_import_is_images_section_enabled', array($this, 'is_enable_default_images_section'), 10, 2); |
|
976 | + add_filter('wp_all_import_is_images_section_enabled', array($this, 'is_enable_default_images_section'), 10, 2); |
|
977 | 977 | |
978 | - } |
|
979 | - function is_enable_default_images_section($is_enabled, $post_type){ |
|
978 | + } |
|
979 | + function is_enable_default_images_section($is_enabled, $post_type){ |
|
980 | 980 | |
981 | - return ($this->is_active_addon($post_type)) ? false : true; |
|
981 | + return ($this->is_active_addon($post_type)) ? false : true; |
|
982 | 982 | |
983 | - } |
|
983 | + } |
|
984 | 984 | |
985 | - function helper_parse($parsingData, $options) { |
|
985 | + function helper_parse($parsingData, $options) { |
|
986 | 986 | |
987 | - extract($parsingData); |
|
987 | + extract($parsingData); |
|
988 | 988 | |
989 | - $data = array(); // parsed data |
|
989 | + $data = array(); // parsed data |
|
990 | 990 | |
991 | - if ( ! empty($import->options[$this->slug])){ |
|
991 | + if ( ! empty($import->options[$this->slug])){ |
|
992 | 992 | |
993 | - $this->logger = $parsingData['logger']; |
|
993 | + $this->logger = $parsingData['logger']; |
|
994 | 994 | |
995 | - $cxpath = $xpath_prefix . $import->xpath; |
|
995 | + $cxpath = $xpath_prefix . $import->xpath; |
|
996 | 996 | |
997 | - $tmp_files = array(); |
|
997 | + $tmp_files = array(); |
|
998 | 998 | |
999 | - foreach ($options[$this->slug] as $option_name => $option_value) { |
|
1000 | - if ( isset($import->options[$this->slug][$option_name]) and $import->options[$this->slug][$option_name] != '') { |
|
1001 | - if ($import->options[$this->slug][$option_name] == "xpath") { |
|
1002 | - if ($import->options[$this->slug]['xpaths'][$option_name] == ""){ |
|
1003 | - $count and $data[$option_name] = array_fill(0, $count, ""); |
|
1004 | - } else { |
|
1005 | - $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug]['xpaths'][$option_name], $file)->parse(); |
|
1006 | - $tmp_files[] = $file; |
|
1007 | - } |
|
1008 | - } |
|
1009 | - else { |
|
1010 | - $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug][$option_name], $file)->parse(); |
|
1011 | - $tmp_files[] = $file; |
|
1012 | - } |
|
999 | + foreach ($options[$this->slug] as $option_name => $option_value) { |
|
1000 | + if ( isset($import->options[$this->slug][$option_name]) and $import->options[$this->slug][$option_name] != '') { |
|
1001 | + if ($import->options[$this->slug][$option_name] == "xpath") { |
|
1002 | + if ($import->options[$this->slug]['xpaths'][$option_name] == ""){ |
|
1003 | + $count and $data[$option_name] = array_fill(0, $count, ""); |
|
1004 | + } else { |
|
1005 | + $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug]['xpaths'][$option_name], $file)->parse(); |
|
1006 | + $tmp_files[] = $file; |
|
1007 | + } |
|
1008 | + } |
|
1009 | + else { |
|
1010 | + $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug][$option_name], $file)->parse(); |
|
1011 | + $tmp_files[] = $file; |
|
1012 | + } |
|
1013 | 1013 | |
1014 | 1014 | |
1015 | - } else { |
|
1016 | - $data[$option_name] = array_fill(0, $count, ""); |
|
1017 | - } |
|
1015 | + } else { |
|
1016 | + $data[$option_name] = array_fill(0, $count, ""); |
|
1017 | + } |
|
1018 | 1018 | |
1019 | - } |
|
1019 | + } |
|
1020 | 1020 | |
1021 | - foreach ($tmp_files as $file) { // remove all temporary files created |
|
1022 | - unlink($file); |
|
1023 | - } |
|
1021 | + foreach ($tmp_files as $file) { // remove all temporary files created |
|
1022 | + unlink($file); |
|
1023 | + } |
|
1024 | 1024 | |
1025 | - } |
|
1025 | + } |
|
1026 | 1026 | |
1027 | - return $data; |
|
1028 | - } |
|
1027 | + return $data; |
|
1028 | + } |
|
1029 | 1029 | |
1030 | 1030 | |
1031 | - function can_update_meta($meta_key, $import_options) { |
|
1031 | + function can_update_meta($meta_key, $import_options) { |
|
1032 | 1032 | |
1033 | - //echo "<pre>"; |
|
1034 | - //print_r($import_options['options']); |
|
1035 | - //echo "</pre>"; |
|
1033 | + //echo "<pre>"; |
|
1034 | + //print_r($import_options['options']); |
|
1035 | + //echo "</pre>"; |
|
1036 | 1036 | |
1037 | - $import_options = $import_options['options']; |
|
1037 | + $import_options = $import_options['options']; |
|
1038 | 1038 | |
1039 | - if ($import_options['update_all_data'] == 'yes') return true; |
|
1039 | + if ($import_options['update_all_data'] == 'yes') return true; |
|
1040 | 1040 | |
1041 | - if ( ! $import_options['is_update_custom_fields'] ) return false; |
|
1041 | + if ( ! $import_options['is_update_custom_fields'] ) return false; |
|
1042 | 1042 | |
1043 | - if ($import_options['update_custom_fields_logic'] == "full_update") return true; |
|
1044 | - if ($import_options['update_custom_fields_logic'] == "only" and ! empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list']) ) return true; |
|
1045 | - if ($import_options['update_custom_fields_logic'] == "all_except" and ( empty($import_options['custom_fields_list']) or ! in_array($meta_key, $import_options['custom_fields_list']) )) return true; |
|
1043 | + if ($import_options['update_custom_fields_logic'] == "full_update") return true; |
|
1044 | + if ($import_options['update_custom_fields_logic'] == "only" and ! empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list']) ) return true; |
|
1045 | + if ($import_options['update_custom_fields_logic'] == "all_except" and ( empty($import_options['custom_fields_list']) or ! in_array($meta_key, $import_options['custom_fields_list']) )) return true; |
|
1046 | 1046 | |
1047 | - return false; |
|
1047 | + return false; |
|
1048 | 1048 | |
1049 | - } |
|
1049 | + } |
|
1050 | 1050 | |
1051 | - function can_update_taxonomy($tax_name, $import_options) { |
|
1051 | + function can_update_taxonomy($tax_name, $import_options) { |
|
1052 | 1052 | |
1053 | - //echo "<pre>"; |
|
1054 | - //print_r($import_options['options']); |
|
1055 | - //echo "</pre>"; |
|
1053 | + //echo "<pre>"; |
|
1054 | + //print_r($import_options['options']); |
|
1055 | + //echo "</pre>"; |
|
1056 | 1056 | |
1057 | - $import_options = $import_options['options']; |
|
1057 | + $import_options = $import_options['options']; |
|
1058 | 1058 | |
1059 | - if ($import_options['update_all_data'] == 'yes') return true; |
|
1059 | + if ($import_options['update_all_data'] == 'yes') return true; |
|
1060 | 1060 | |
1061 | - if ( ! $import_options['is_update_categories'] ) return false; |
|
1061 | + if ( ! $import_options['is_update_categories'] ) return false; |
|
1062 | 1062 | |
1063 | - if ($import_options['update_categories_logic'] == "full_update") return true; |
|
1064 | - if ($import_options['update_categories_logic'] == "only" and ! empty($import_options['taxonomies_list']) and is_array($import_options['taxonomies_list']) and in_array($tax_name, $import_options['taxonomies_list']) ) return true; |
|
1065 | - if ($import_options['update_categories_logic'] == "all_except" and ( empty($import_options['taxonomies_list']) or ! in_array($tax_name, $import_options['taxonomies_list']) )) return true; |
|
1063 | + if ($import_options['update_categories_logic'] == "full_update") return true; |
|
1064 | + if ($import_options['update_categories_logic'] == "only" and ! empty($import_options['taxonomies_list']) and is_array($import_options['taxonomies_list']) and in_array($tax_name, $import_options['taxonomies_list']) ) return true; |
|
1065 | + if ($import_options['update_categories_logic'] == "all_except" and ( empty($import_options['taxonomies_list']) or ! in_array($tax_name, $import_options['taxonomies_list']) )) return true; |
|
1066 | 1066 | |
1067 | - return false; |
|
1067 | + return false; |
|
1068 | 1068 | |
1069 | - } |
|
1069 | + } |
|
1070 | 1070 | |
1071 | - function can_update_image($import_options) { |
|
1071 | + function can_update_image($import_options) { |
|
1072 | 1072 | |
1073 | - $import_options = $import_options['options']; |
|
1073 | + $import_options = $import_options['options']; |
|
1074 | 1074 | |
1075 | - if ($import_options['update_all_data'] == 'yes') return true; |
|
1075 | + if ($import_options['update_all_data'] == 'yes') return true; |
|
1076 | 1076 | |
1077 | - if (!$import_options['is_update_images']) return false; |
|
1077 | + if (!$import_options['is_update_images']) return false; |
|
1078 | 1078 | |
1079 | - if ($import_options['is_update_images']) return true; |
|
1079 | + if ($import_options['is_update_images']) return true; |
|
1080 | 1080 | |
1081 | - return false; |
|
1082 | - } |
|
1081 | + return false; |
|
1082 | + } |
|
1083 | 1083 | |
1084 | 1084 | |
1085 | - function admin_notice_ignore() { |
|
1086 | - if (isset($_GET[$this->slug.'_ignore']) && '0' == $_GET[$this->slug.'_ignore'] ) { |
|
1087 | - update_option($this->slug.'_ignore', 'true'); |
|
1088 | - } |
|
1089 | - } |
|
1085 | + function admin_notice_ignore() { |
|
1086 | + if (isset($_GET[$this->slug.'_ignore']) && '0' == $_GET[$this->slug.'_ignore'] ) { |
|
1087 | + update_option($this->slug.'_ignore', 'true'); |
|
1088 | + } |
|
1089 | + } |
|
1090 | 1090 | |
1091 | - function display_admin_notice() { |
|
1091 | + function display_admin_notice() { |
|
1092 | 1092 | |
1093 | 1093 | |
1094 | - if ($this->notice_text) { |
|
1095 | - $notice_text = $this->notice_text; |
|
1096 | - } else { |
|
1097 | - $notice_text = $this->name.' requires WP All Import <a href="http://www.wpallimport.com/" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>.'; |
|
1098 | - } |
|
1094 | + if ($this->notice_text) { |
|
1095 | + $notice_text = $this->notice_text; |
|
1096 | + } else { |
|
1097 | + $notice_text = $this->name.' requires WP All Import <a href="http://www.wpallimport.com/" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>.'; |
|
1098 | + } |
|
1099 | 1099 | |
1100 | - if (!get_option(sanitize_key($this->slug).'_notice_ignore')) { |
|
1100 | + if (!get_option(sanitize_key($this->slug).'_notice_ignore')) { |
|
1101 | 1101 | |
1102 | - ?> |
|
1102 | + ?> |
|
1103 | 1103 | |
1104 | 1104 | <div class="error notice is-dismissible wpallimport-dismissible" style="margin-top: 10px;" rel="<?php echo sanitize_key($this->slug); ?>"> |
1105 | 1105 | <p><?php _e( |
1106 | - sprintf( |
|
1107 | - $notice_text, |
|
1108 | - '?'.$this->slug.'_ignore=0' |
|
1109 | - ), |
|
1110 | - 'rapid_addon_'.$this->slug |
|
1111 | - ); ?></p> |
|
1106 | + sprintf( |
|
1107 | + $notice_text, |
|
1108 | + '?'.$this->slug.'_ignore=0' |
|
1109 | + ), |
|
1110 | + 'rapid_addon_'.$this->slug |
|
1111 | + ); ?></p> |
|
1112 | 1112 | </div> |
1113 | 1113 | |
1114 | 1114 | <?php |
1115 | 1115 | |
1116 | - } |
|
1116 | + } |
|
1117 | 1117 | |
1118 | - } |
|
1118 | + } |
|
1119 | 1119 | |
1120 | - /* |
|
1120 | + /* |
|
1121 | 1121 | * |
1122 | 1122 | * $conditions - array('themes' => array('Realia'), 'plugins' => array('plugin-directory/plugin-file.php', 'plugin-directory2/plugin-file.php')) |
1123 | 1123 | * |
1124 | 1124 | */ |
1125 | - function admin_notice($notice_text = '', $conditions = array()) { |
|
1125 | + function admin_notice($notice_text = '', $conditions = array()) { |
|
1126 | 1126 | |
1127 | - $is_show_notice = false; |
|
1127 | + $is_show_notice = false; |
|
1128 | 1128 | |
1129 | - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
1129 | + include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
1130 | 1130 | |
1131 | - if ( ! class_exists( 'PMXI_Plugin' ) ) { |
|
1132 | - $is_show_notice = true; |
|
1133 | - } |
|
1131 | + if ( ! class_exists( 'PMXI_Plugin' ) ) { |
|
1132 | + $is_show_notice = true; |
|
1133 | + } |
|
1134 | 1134 | |
1135 | - // Supported Themes |
|
1136 | - if ( ! $is_show_notice and ! empty($conditions['themes']) ){ |
|
1135 | + // Supported Themes |
|
1136 | + if ( ! $is_show_notice and ! empty($conditions['themes']) ){ |
|
1137 | 1137 | |
1138 | - $themeInfo = wp_get_theme(); |
|
1139 | - $parentInfo = $themeInfo->parent(); |
|
1140 | - $currentTheme = $themeInfo->get('Name'); |
|
1138 | + $themeInfo = wp_get_theme(); |
|
1139 | + $parentInfo = $themeInfo->parent(); |
|
1140 | + $currentTheme = $themeInfo->get('Name'); |
|
1141 | 1141 | |
1142 | - $is_show_notice = in_array($currentTheme, $conditions['themes']) ? false : true; |
|
1142 | + $is_show_notice = in_array($currentTheme, $conditions['themes']) ? false : true; |
|
1143 | 1143 | |
1144 | - if ( $is_show_notice and $parentInfo ){ |
|
1145 | - $parent_theme = $parentInfo->get('Name'); |
|
1146 | - $is_show_notice = in_array($parent_theme, $conditions['themes']) ? false : true; |
|
1147 | - } |
|
1144 | + if ( $is_show_notice and $parentInfo ){ |
|
1145 | + $parent_theme = $parentInfo->get('Name'); |
|
1146 | + $is_show_notice = in_array($parent_theme, $conditions['themes']) ? false : true; |
|
1147 | + } |
|
1148 | 1148 | |
1149 | - } |
|
1149 | + } |
|
1150 | 1150 | |
1151 | - // Required Plugins |
|
1152 | - if ( ! $is_show_notice and ! empty($conditions['plugins']) ){ |
|
1151 | + // Required Plugins |
|
1152 | + if ( ! $is_show_notice and ! empty($conditions['plugins']) ){ |
|
1153 | 1153 | |
1154 | - $requires_counter = 0; |
|
1155 | - foreach ($conditions['plugins'] as $plugin) { |
|
1156 | - if ( is_plugin_active($plugin) ) $requires_counter++; |
|
1157 | - } |
|
1154 | + $requires_counter = 0; |
|
1155 | + foreach ($conditions['plugins'] as $plugin) { |
|
1156 | + if ( is_plugin_active($plugin) ) $requires_counter++; |
|
1157 | + } |
|
1158 | 1158 | |
1159 | - if ($requires_counter != count($conditions['plugins'])){ |
|
1160 | - $is_show_notice = true; |
|
1161 | - } |
|
1159 | + if ($requires_counter != count($conditions['plugins'])){ |
|
1160 | + $is_show_notice = true; |
|
1161 | + } |
|
1162 | 1162 | |
1163 | - } |
|
1163 | + } |
|
1164 | 1164 | |
1165 | - if ( $is_show_notice ){ |
|
1165 | + if ( $is_show_notice ){ |
|
1166 | 1166 | |
1167 | - if ( $notice_text != '' ) { |
|
1168 | - $this->notice_text = $notice_text; |
|
1169 | - } |
|
1167 | + if ( $notice_text != '' ) { |
|
1168 | + $this->notice_text = $notice_text; |
|
1169 | + } |
|
1170 | 1170 | |
1171 | - add_action('admin_notices', array($this, 'display_admin_notice')); |
|
1172 | - } |
|
1171 | + add_action('admin_notices', array($this, 'display_admin_notice')); |
|
1172 | + } |
|
1173 | 1173 | |
1174 | - } |
|
1174 | + } |
|
1175 | 1175 | |
1176 | - function log( $m = false){ |
|
1176 | + function log( $m = false){ |
|
1177 | 1177 | |
1178 | - $m and $this->logger and call_user_func($this->logger, $m); |
|
1178 | + $m and $this->logger and call_user_func($this->logger, $m); |
|
1179 | 1179 | |
1180 | 1180 | } |
1181 | 1181 | |
@@ -1293,5 +1293,5 @@ discard block |
||
1293 | 1293 | } |
1294 | 1294 | return $image; |
1295 | 1295 | } |
1296 | - } |
|
1296 | + } |
|
1297 | 1297 | } |
1298 | 1298 | \ No newline at end of file |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | function __construct($name, $slug) { |
61 | 61 | $this->name = $name; |
62 | 62 | $this->slug = $slug; |
63 | - if (!empty($_GET['id'])){ |
|
63 | + if (!empty($_GET['id'])) { |
|
64 | 64 | $this->isWizard = false; |
65 | 65 | } |
66 | 66 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | function is_active_addon($post_type = null) { |
77 | 77 | |
78 | - if ( ! class_exists( 'PMXI_Plugin' ) ) { |
|
78 | + if (!class_exists('PMXI_Plugin')) { |
|
79 | 79 | return false; |
80 | 80 | } |
81 | 81 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | - if ($addon_active){ |
|
90 | + if ($addon_active) { |
|
91 | 91 | |
92 | 92 | $current_theme = wp_get_theme(); |
93 | 93 | |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | |
98 | 98 | $addon_active = (@in_array($theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false; |
99 | 99 | |
100 | - if ( ! $addon_active and $parent_theme ){ |
|
100 | + if (!$addon_active and $parent_theme) { |
|
101 | 101 | $parent_theme_name = $parent_theme->get('Name'); |
102 | 102 | $addon_active = (@in_array($parent_theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false; |
103 | 103 | |
104 | 104 | } |
105 | 105 | |
106 | - if ( $addon_active and ! empty($this->active_plugins) ){ |
|
106 | + if ($addon_active and !empty($this->active_plugins)) { |
|
107 | 107 | |
108 | - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
108 | + include_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
109 | 109 | |
110 | 110 | foreach ($this->active_plugins as $plugin) { |
111 | - if ( ! is_plugin_active($plugin) ) { |
|
111 | + if (!is_plugin_active($plugin)) { |
|
112 | 112 | $addon_active = false; |
113 | 113 | break; |
114 | 114 | } |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | $this->when_to_run = "always"; |
138 | 138 | } |
139 | 139 | |
140 | - @$this->active_post_types = ( ! empty($conditions['post_types'])) ? $conditions['post_types'] : array(); |
|
141 | - @$this->active_themes = ( ! empty($conditions['themes'])) ? $conditions['themes'] : array(); |
|
142 | - @$this->active_plugins = ( ! empty($conditions['plugins'])) ? $conditions['plugins'] : array(); |
|
140 | + @$this->active_post_types = (!empty($conditions['post_types'])) ? $conditions['post_types'] : array(); |
|
141 | + @$this->active_themes = (!empty($conditions['themes'])) ? $conditions['themes'] : array(); |
|
142 | + @$this->active_plugins = (!empty($conditions['plugins'])) ? $conditions['plugins'] : array(); |
|
143 | 143 | |
144 | 144 | add_filter('pmxi_addons', array($this, 'wpai_api_register')); |
145 | 145 | add_filter('wp_all_import_addon_parse', array($this, 'wpai_api_parse')); |
@@ -148,15 +148,15 @@ discard block |
||
148 | 148 | add_filter('pmxi_options_options', array($this, 'wpai_api_options')); |
149 | 149 | add_filter('wp_all_import_image_sections', array($this, 'additional_sections'), 10, 1); |
150 | 150 | add_filter('pmxi_custom_types', array($this, 'filter_post_types'), 10, 2); |
151 | - add_filter('pmxi_post_list_order', array($this,'sort_post_types'), 10, 1); |
|
152 | - add_filter('wp_all_import_post_type_image', array($this, 'post_type_image'), 10, 1 ); |
|
153 | - add_action('pmxi_extend_options_featured', array($this, 'wpai_api_metabox'), 10, 2); |
|
151 | + add_filter('pmxi_post_list_order', array($this, 'sort_post_types'), 10, 1); |
|
152 | + add_filter('wp_all_import_post_type_image', array($this, 'post_type_image'), 10, 1); |
|
153 | + add_action('pmxi_extend_options_featured', array($this, 'wpai_api_metabox'), 10, 2); |
|
154 | 154 | add_action('admin_init', array($this, 'admin_notice_ignore')); |
155 | 155 | } |
156 | 156 | |
157 | 157 | function parse($data) { |
158 | 158 | |
159 | - if ( ! $this->is_active_addon($data['import']->options['custom_type'])) return false; |
|
159 | + if (!$this->is_active_addon($data['import']->options['custom_type'])) return false; |
|
160 | 160 | |
161 | 161 | $parsedData = $this->helper_parse($data, $this->options_array()); |
162 | 162 | return $parsedData; |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | |
167 | 167 | function add_field($field_slug, $field_name, $field_type, $enum_values = null, $tooltip = "", $is_html = true, $default_text = '') { |
168 | 168 | |
169 | - $field = array("name" => $field_name, "type" => $field_type, "enum_values" => $enum_values, "tooltip" => $tooltip, "is_sub_field" => false, "is_main_field" => false, "slug" => $field_slug, "is_html" => $is_html, 'default_text' => $default_text); |
|
169 | + $field = array("name" => $field_name, "type" => $field_type, "enum_values" => $enum_values, "tooltip" => $tooltip, "is_sub_field" => false, "is_main_field" => false, "slug" => $field_slug, "is_html" => $is_html, 'default_text' => $default_text); |
|
170 | 170 | |
171 | 171 | $this->fields[$field_slug] = $field; |
172 | 172 | |
173 | - if ( ! empty($enum_values) ){ |
|
173 | + if (!empty($enum_values)) { |
|
174 | 174 | foreach ($enum_values as $key => $value) { |
175 | 175 | if (is_array($value)) |
176 | 176 | { |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | else |
182 | 182 | { |
183 | 183 | foreach ($value as $n => $param) { |
184 | - if (is_array($param) and ! empty($this->fields[$param['slug']])){ |
|
184 | + if (is_array($param) and !empty($this->fields[$param['slug']])) { |
|
185 | 185 | $this->fields[$param['slug']]['is_sub_field'] = true; |
186 | 186 | } |
187 | 187 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | |
195 | 195 | } |
196 | 196 | |
197 | - function add_acf_field($field){ |
|
197 | + function add_acf_field($field) { |
|
198 | 198 | $this->fields[$field->post_name] = array( |
199 | 199 | 'type' => 'acf', |
200 | 200 | 'field_obj' => $field |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | |
204 | 204 | private $acfGroups = array(); |
205 | 205 | |
206 | - function use_acf_group($acf_group){ |
|
206 | + function use_acf_group($acf_group) { |
|
207 | 207 | $this->add_text( |
208 | 208 | '<div class="postbox acf_postbox default acf_signle_group rad4"> |
209 | - <h3 class="hndle" style="margin-top:0;"><span>'.$acf_group['title'].'</span></h3> |
|
209 | + <h3 class="hndle" style="margin-top:0;"><span>'.$acf_group['title'] . '</span></h3> |
|
210 | 210 | <div class="inside">'); |
211 | 211 | $acf_fields = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf-field', 'post_parent' => $acf_group['ID'], 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC')); |
212 | - if (!empty($acf_fields)){ |
|
212 | + if (!empty($acf_fields)) { |
|
213 | 213 | foreach ($acf_fields as $field) { |
214 | 214 | $this->add_acf_field($field); |
215 | 215 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | add_filter('wp_all_import_acf_is_show_group', array($this, 'acf_is_show_group'), 10, 2); |
220 | 220 | } |
221 | 221 | |
222 | - function acf_is_show_group($is_show, $acf_group){ |
|
222 | + function acf_is_show_group($is_show, $acf_group) { |
|
223 | 223 | return (in_array($acf_group['ID'], $this->acfGroups)) ? false : true; |
224 | 224 | } |
225 | 225 | |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @param string $default_value - default option value |
232 | 232 | * |
233 | 233 | */ |
234 | - function add_option($slug, $default_value = ''){ |
|
234 | + function add_option($slug, $default_value = '') { |
|
235 | 235 | $this->options[$slug] = $default_value; |
236 | 236 | } |
237 | 237 | |
@@ -239,12 +239,12 @@ discard block |
||
239 | 239 | |
240 | 240 | $options_list = array(); |
241 | 241 | |
242 | - if ( ! empty( $this->fields ) ) { |
|
242 | + if (!empty($this->fields)) { |
|
243 | 243 | |
244 | 244 | foreach ($this->fields as $field_slug => $field_params) { |
245 | 245 | if (in_array($field_params['type'], array('title', 'plain_text', 'acf'))) continue; |
246 | 246 | $default_value = ''; |
247 | - if (!empty($field_params['enum_values'])){ |
|
247 | + if (!empty($field_params['enum_values'])) { |
|
248 | 248 | foreach ($field_params['enum_values'] as $key => $value) { |
249 | 249 | $default_value = $key; |
250 | 250 | break; |
@@ -255,14 +255,14 @@ discard block |
||
255 | 255 | |
256 | 256 | } |
257 | 257 | |
258 | - if ( ! empty($this->options) ){ |
|
258 | + if (!empty($this->options)) { |
|
259 | 259 | foreach ($this->options as $slug => $value) { |
260 | 260 | $options_arr[$slug] = $value; |
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
264 | 264 | $options_arr[$this->slug] = $options_list; |
265 | - $options_arr['rapid_addon'] = plugin_basename( __FILE__ ); |
|
265 | + $options_arr['rapid_addon'] = plugin_basename(__FILE__); |
|
266 | 266 | |
267 | 267 | return $options_arr; |
268 | 268 | |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | |
296 | 296 | } |
297 | 297 | |
298 | - function wpai_api_post_saved($functions){ |
|
298 | + function wpai_api_post_saved($functions) { |
|
299 | 299 | $functions[$this->slug] = array($this, 'post_saved'); |
300 | 300 | return $functions; |
301 | 301 | } |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | |
309 | 309 | } |
310 | 310 | |
311 | - function post_saved( $importData ){ |
|
311 | + function post_saved($importData) { |
|
312 | 312 | |
313 | 313 | if (is_callable($this->post_saved_function)) |
314 | 314 | call_user_func($this->post_saved_function, $importData['pid'], $importData['import'], $importData['logger']); |
@@ -327,14 +327,14 @@ discard block |
||
327 | 327 | // print_r($import_options); |
328 | 328 | // echo "</pre>"; |
329 | 329 | |
330 | - if ( ! empty($parsedData) ) { |
|
330 | + if (!empty($parsedData)) { |
|
331 | 331 | |
332 | 332 | $this->logger = $importData['logger']; |
333 | 333 | |
334 | 334 | $post_id = $importData['pid']; |
335 | 335 | $index = $importData['i']; |
336 | 336 | $data = array(); |
337 | - if (!empty($this->fields)){ |
|
337 | + if (!empty($this->fields)) { |
|
338 | 338 | foreach ($this->fields as $field_slug => $field_params) { |
339 | 339 | if (in_array($field_params['type'], array('title', 'plain_text'))) continue; |
340 | 340 | switch ($field_params['type']) { |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | |
346 | 346 | $image_url_or_path = $parsedData[$field_slug][$index]; |
347 | 347 | |
348 | - if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) { |
|
348 | + if (!array_key_exists($field_slug, $import_options['download_image'])) { |
|
349 | 349 | continue 2; |
350 | 350 | } |
351 | 351 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | |
366 | 366 | $image_url_or_path = $parsedData[$field_slug][$index]; |
367 | 367 | |
368 | - if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) { |
|
368 | + if (!array_key_exists($field_slug, $import_options['download_image'])) { |
|
369 | 369 | continue 2; |
370 | 370 | } |
371 | 371 | |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | |
394 | 394 | if (!empty($mapping_rules) and is_array($mapping_rules)) { |
395 | 395 | foreach ($mapping_rules as $rule_number => $map_to) { |
396 | - if (isset($map_to[trim($data[$field_slug])])){ |
|
396 | + if (isset($map_to[trim($data[$field_slug])])) { |
|
397 | 397 | $data[$field_slug] = trim($map_to[trim($data[$field_slug])]); |
398 | 398 | break; |
399 | 399 | } |
@@ -442,14 +442,14 @@ discard block |
||
442 | 442 | |
443 | 443 | echo $this->helper_metabox_bottom(); |
444 | 444 | |
445 | - if ( ! empty($this->image_sections) ){ |
|
445 | + if (!empty($this->image_sections)) { |
|
446 | 446 | $is_images_section_enabled = apply_filters('wp_all_import_is_images_section_enabled', true, $post_type); |
447 | 447 | foreach ($this->image_sections as $k => $section) { |
448 | 448 | $section_options = array(); |
449 | 449 | foreach ($this->image_options as $slug => $value) { |
450 | 450 | $section_options[$section['slug'] . $slug] = $value; |
451 | 451 | } |
452 | - if ( ! $is_images_section_enabled and ! $k ){ |
|
452 | + if (!$is_images_section_enabled and !$k) { |
|
453 | 453 | $section_options[$section['slug'] . 'is_featured'] = 1; |
454 | 454 | } |
455 | 455 | PMXI_API::add_additional_images_section($section['title'], $section['slug'], $current_values, '', true, false, $section['type']); |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | |
459 | 459 | } |
460 | 460 | |
461 | - function render_field($field_params, $field_slug, $current_values, $in_the_bottom = false){ |
|
461 | + function render_field($field_params, $field_slug, $current_values, $in_the_bottom = false) { |
|
462 | 462 | |
463 | 463 | if (!isset($current_values[$this->slug][$field_slug])) { |
464 | 464 | $current_values[$this->slug][$field_slug] = isset($field_params['default_text']) ? $field_params['default_text'] : ''; |
@@ -471,8 +471,8 @@ discard block |
||
471 | 471 | $field_params['name'], |
472 | 472 | array( |
473 | 473 | 'tooltip' => $field_params['tooltip'], |
474 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
475 | - 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
474 | + 'field_name' => $this->slug . "[" . $field_slug . "]", |
|
475 | + 'field_value' => ($current_values[$this->slug][$field_slug] == '' && $this->isWizard) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
476 | 476 | ) |
477 | 477 | ); |
478 | 478 | |
@@ -483,8 +483,8 @@ discard block |
||
483 | 483 | $field_params['name'], |
484 | 484 | array( |
485 | 485 | 'tooltip' => $field_params['tooltip'], |
486 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
487 | - 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
486 | + 'field_name' => $this->slug . "[" . $field_slug . "]", |
|
487 | + 'field_value' => ($current_values[$this->slug][$field_slug] == '' && $this->isWizard) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
488 | 488 | ) |
489 | 489 | ); |
490 | 490 | |
@@ -495,8 +495,8 @@ discard block |
||
495 | 495 | $field_params['name'], |
496 | 496 | array( |
497 | 497 | 'tooltip' => $field_params['tooltip'], |
498 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
499 | - 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
498 | + 'field_name' => $this->slug . "[" . $field_slug . "]", |
|
499 | + 'field_value' => ($current_values[$this->slug][$field_slug] == '' && $this->isWizard) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug] |
|
500 | 500 | ) |
501 | 501 | ); |
502 | 502 | |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | $field_params['name'], |
510 | 510 | array( |
511 | 511 | 'tooltip' => $field_params['tooltip'], |
512 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
512 | + 'field_name' => $this->slug . "[" . $field_slug . "]", |
|
513 | 513 | 'field_value' => $current_values[$this->slug][$field_slug], |
514 | 514 | 'download_image' => $current_values[$this->slug]['download_image'][$field_slug], |
515 | 515 | 'field_key' => $field_slug, |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | $field_params['name'], |
529 | 529 | array( |
530 | 530 | 'tooltip' => $field_params['tooltip'], |
531 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
531 | + 'field_name' => $this->slug . "[" . $field_slug . "]", |
|
532 | 532 | 'field_value' => $current_values[$this->slug][$field_slug], |
533 | 533 | 'enum_values' => $field_params['enum_values'], |
534 | 534 | 'mapping' => true, |
@@ -540,14 +540,14 @@ discard block |
||
540 | 540 | ) |
541 | 541 | ); |
542 | 542 | |
543 | - } else if($field_params['type'] == 'accordion') { |
|
543 | + } else if ($field_params['type'] == 'accordion') { |
|
544 | 544 | |
545 | 545 | PMXI_API::add_field( |
546 | 546 | 'accordion', |
547 | 547 | $field_params['name'], |
548 | 548 | array( |
549 | 549 | 'tooltip' => $field_params['tooltip'], |
550 | - 'field_name' => $this->slug."[".$field_slug."]", |
|
550 | + 'field_name' => $this->slug . "[" . $field_slug . "]", |
|
551 | 551 | 'field_key' => $field_slug, |
552 | 552 | 'addon_prefix' => $this->slug, |
553 | 553 | 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values), |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | ) |
556 | 556 | ); |
557 | 557 | |
558 | - } else if($field_params['type'] == 'acf') { |
|
558 | + } else if ($field_params['type'] == 'acf') { |
|
559 | 559 | $fieldData = (!empty($field_params['field_obj']->post_content)) ? unserialize($field_params['field_obj']->post_content) : array(); |
560 | 560 | $fieldData['ID'] = $field_params['field_obj']->ID; |
561 | 561 | $fieldData['id'] = $field_params['field_obj']->ID; |
@@ -563,19 +563,19 @@ discard block |
||
563 | 563 | $fieldData['key'] = $field_params['field_obj']->post_name; |
564 | 564 | if (empty($fieldData['name'])) $fieldData['name'] = $field_params['field_obj']->post_excerpt; |
565 | 565 | if (function_exists('pmai_render_field')) { |
566 | - echo pmai_render_field($fieldData, ( ! empty($current_values) ) ? $current_values : array() ); |
|
566 | + echo pmai_render_field($fieldData, (!empty($current_values)) ? $current_values : array()); |
|
567 | 567 | } |
568 | - } else if($field_params['type'] == 'title'){ |
|
568 | + } else if ($field_params['type'] == 'title') { |
|
569 | 569 | ?> |
570 | - <h4 class="wpallimport-add-on-options-title"><?php _e($field_params['name'], 'wp_all_import_plugin'); ?><?php if ( ! empty($field_params['tooltip'])): ?><a href="#help" class="wpallimport-help" title="<?php echo $field_params['tooltip']; ?>" style="position:relative; top: -1px;">?</a><?php endif; ?></h4> |
|
570 | + <h4 class="wpallimport-add-on-options-title"><?php _e($field_params['name'], 'wp_all_import_plugin'); ?><?php if (!empty($field_params['tooltip'])): ?><a href="#help" class="wpallimport-help" title="<?php echo $field_params['tooltip']; ?>" style="position:relative; top: -1px;">?</a><?php endif; ?></h4> |
|
571 | 571 | <?php |
572 | 572 | |
573 | - } else if($field_params['type'] == 'plain_text'){ |
|
573 | + } else if ($field_params['type'] == 'plain_text') { |
|
574 | 574 | if ($field_params['is_html']): |
575 | 575 | echo $field_params['name']; |
576 | 576 | else: |
577 | 577 | ?> |
578 | - <p style="margin: 0 0 12px 0;"><?php echo $field_params['name'];?></p> |
|
578 | + <p style="margin: 0 0 12px 0;"><?php echo $field_params['name']; ?></p> |
|
579 | 579 | <?php |
580 | 580 | endif; |
581 | 581 | } |
@@ -587,19 +587,19 @@ discard block |
||
587 | 587 | * Helper function for nested radio fields |
588 | 588 | * |
589 | 589 | */ |
590 | - function get_sub_fields($field_params, $field_slug, $current_values){ |
|
590 | + function get_sub_fields($field_params, $field_slug, $current_values) { |
|
591 | 591 | $sub_fields = array(); |
592 | - if ( ! empty($field_params['enum_values']) ){ |
|
592 | + if (!empty($field_params['enum_values'])) { |
|
593 | 593 | foreach ($field_params['enum_values'] as $key => $value) { |
594 | 594 | $sub_fields[$key] = array(); |
595 | - if (is_array($value)){ |
|
596 | - if ($field_params['type'] == 'accordion'){ |
|
595 | + if (is_array($value)) { |
|
596 | + if ($field_params['type'] == 'accordion') { |
|
597 | 597 | $sub_fields[$key][] = $this->convert_field($value, $current_values); |
598 | 598 | } |
599 | 599 | else |
600 | 600 | { |
601 | 601 | foreach ($value as $k => $sub_field) { |
602 | - if (is_array($sub_field) and ! empty($this->fields[$sub_field['slug']])) |
|
602 | + if (is_array($sub_field) and !empty($this->fields[$sub_field['slug']])) |
|
603 | 603 | { |
604 | 604 | $sub_fields[$key][] = $this->convert_field($sub_field, $current_values); |
605 | 605 | } |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | return $sub_fields; |
612 | 612 | } |
613 | 613 | |
614 | - function convert_field($sub_field, $current_values){ |
|
614 | + function convert_field($sub_field, $current_values) { |
|
615 | 615 | $field = array(); |
616 | 616 | if (!isset($current_values[$this->slug][$sub_field['slug']])) { |
617 | 617 | $current_values[$this->slug][$sub_field['slug']] = isset($sub_field['default_text']) ? $sub_field['default_text'] : ''; |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | 'label' => $this->fields[$sub_field['slug']]['name'], |
624 | 624 | 'params' => array( |
625 | 625 | 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
626 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
626 | + 'field_name' => $this->slug . "[" . $sub_field['slug'] . "]", |
|
627 | 627 | 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
628 | 628 | 'is_main_field' => $sub_field['is_main_field'] |
629 | 629 | ) |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | 'label' => $this->fields[$sub_field['slug']]['name'], |
636 | 636 | 'params' => array( |
637 | 637 | 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
638 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
638 | + 'field_name' => $this->slug . "[" . $sub_field['slug'] . "]", |
|
639 | 639 | 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
640 | 640 | 'is_main_field' => $sub_field['is_main_field'] |
641 | 641 | ) |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | 'label' => $this->fields[$sub_field['slug']]['name'], |
648 | 648 | 'params' => array( |
649 | 649 | 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
650 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
650 | + 'field_name' => $this->slug . "[" . $sub_field['slug'] . "]", |
|
651 | 651 | 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']], |
652 | 652 | 'is_main_field' => $sub_field['is_main_field'] |
653 | 653 | ) |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | 'label' => $this->fields[$sub_field['slug']]['name'], |
660 | 660 | 'params' => array( |
661 | 661 | 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
662 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
662 | + 'field_name' => $this->slug . "[" . $sub_field['slug'] . "]", |
|
663 | 663 | 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
664 | 664 | 'download_image' => null, |
665 | 665 | 'field_key' => $sub_field['slug'], |
@@ -668,7 +668,7 @@ discard block |
||
668 | 668 | ) |
669 | 669 | ); |
670 | 670 | |
671 | - if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) { |
|
671 | + if (array_key_exists('download_image', $current_values[$this->slug]) && array_key_exists($sub_field['slug'], $current_values[$this->slug]['download_image'])) { |
|
672 | 672 | $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']]; |
673 | 673 | } |
674 | 674 | break; |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | 'label' => $this->fields[$sub_field['slug']]['name'], |
679 | 679 | 'params' => array( |
680 | 680 | 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
681 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
681 | + 'field_name' => $this->slug . "[" . $sub_field['slug'] . "]", |
|
682 | 682 | 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
683 | 683 | 'download_image' => null, |
684 | 684 | 'field_key' => $sub_field['slug'], |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | ) |
688 | 688 | ); |
689 | 689 | |
690 | - if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) { |
|
690 | + if (array_key_exists('download_image', $current_values[$this->slug]) && array_key_exists($sub_field['slug'], $current_values[$this->slug]['download_image'])) { |
|
691 | 691 | $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']]; |
692 | 692 | } |
693 | 693 | |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | 'label' => $this->fields[$sub_field['slug']]['name'], |
699 | 699 | 'params' => array( |
700 | 700 | 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
701 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
701 | + 'field_name' => $this->slug . "[" . $sub_field['slug'] . "]", |
|
702 | 702 | 'field_value' => $current_values[$this->slug][$sub_field['slug']], |
703 | 703 | 'enum_values' => $this->fields[$sub_field['slug']]['enum_values'], |
704 | 704 | 'mapping' => true, |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | 'label' => $this->fields[$sub_field['slug']]['name'], |
718 | 718 | 'params' => array( |
719 | 719 | 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'], |
720 | - 'field_name' => $this->slug."[".$sub_field['slug']."]", |
|
720 | + 'field_name' => $this->slug . "[" . $sub_field['slug'] . "]", |
|
721 | 721 | 'field_key' => $sub_field['slug'], |
722 | 722 | 'addon_prefix' => $this->slug, |
723 | 723 | 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values), |
@@ -738,12 +738,12 @@ discard block |
||
738 | 738 | * |
739 | 739 | * |
740 | 740 | */ |
741 | - function add_options( $main_field = false, $title = '', $fields = array() ){ |
|
741 | + function add_options($main_field = false, $title = '', $fields = array()) { |
|
742 | 742 | |
743 | - if ( ! empty($fields) ) |
|
743 | + if (!empty($fields)) |
|
744 | 744 | { |
745 | 745 | |
746 | - if ($main_field){ |
|
746 | + if ($main_field) { |
|
747 | 747 | |
748 | 748 | $main_field['is_main_field'] = true; |
749 | 749 | $fields[] = $main_field; |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | |
757 | 757 | } |
758 | 758 | |
759 | - function add_title($title = '', $tooltip = ''){ |
|
759 | + function add_title($title = '', $tooltip = '') { |
|
760 | 760 | |
761 | 761 | if (empty($title)) return; |
762 | 762 | |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | |
765 | 765 | } |
766 | 766 | |
767 | - function add_text($text = '', $is_html = false){ |
|
767 | + function add_text($text = '', $is_html = false) { |
|
768 | 768 | |
769 | 769 | if (empty($text)) return; |
770 | 770 | |
@@ -862,10 +862,10 @@ discard block |
||
862 | 862 | margin: 45px 0 15px 0; |
863 | 863 | } |
864 | 864 | </style> |
865 | - <div class="wpallimport-collapsed wpallimport-section wpallimport-addon '.$this->slug.' closed"> |
|
865 | + <div class="wpallimport-collapsed wpallimport-section wpallimport-addon '.$this->slug . ' closed"> |
|
866 | 866 | <div class="wpallimport-content-section"> |
867 | 867 | <div class="wpallimport-collapsed-header"> |
868 | - <h3>'.__($name,'pmxi_plugin').'</h3> |
|
868 | + <h3>'.__($name, 'pmxi_plugin') . '</h3> |
|
869 | 869 | </div> |
870 | 870 | <div class="wpallimport-collapsed-content" style="padding: 0;"> |
871 | 871 | <div class="wpallimport-collapsed-content-inner"> |
@@ -891,8 +891,8 @@ discard block |
||
891 | 891 | * simply add an additional section for attachments |
892 | 892 | * |
893 | 893 | */ |
894 | - function import_files( $slug, $title, $callback = NULL ){ |
|
895 | - $this->import_images( $slug, $title, 'files', $callback); |
|
894 | + function import_files($slug, $title, $callback = NULL) { |
|
895 | + $this->import_images($slug, $title, 'files', $callback); |
|
896 | 896 | } |
897 | 897 | |
898 | 898 | /** |
@@ -900,9 +900,9 @@ discard block |
||
900 | 900 | * simply add an additional section |
901 | 901 | * |
902 | 902 | */ |
903 | - function import_images( $slug, $title, $type = 'images', $callback = NULL ){ |
|
903 | + function import_images($slug, $title, $type = 'images', $callback = NULL) { |
|
904 | 904 | |
905 | - if ( empty($title) or empty($slug) ) return; |
|
905 | + if (empty($title) or empty($slug)) return; |
|
906 | 906 | |
907 | 907 | if (is_array($slug)) { |
908 | 908 | $section_slug = 'pmxi_' . md5(serialize($slug)); |
@@ -920,17 +920,17 @@ discard block |
||
920 | 920 | $this->add_option($section_slug . $option_slug, $value); |
921 | 921 | } |
922 | 922 | |
923 | - if (count($this->image_sections) > 1){ |
|
923 | + if (count($this->image_sections) > 1) { |
|
924 | 924 | add_filter('wp_all_import_is_show_add_new_images', array($this, 'filter_is_show_add_new_images'), 10, 2); |
925 | 925 | } |
926 | 926 | |
927 | 927 | add_filter('wp_all_import_is_allow_import_images', array($this, 'is_allow_import_images'), 10, 2); |
928 | 928 | |
929 | 929 | if ($callback && is_callable($callback)) { |
930 | - add_action( $section_slug, $callback, 10, 4); |
|
930 | + add_action($section_slug, $callback, 10, 4); |
|
931 | 931 | } else { |
932 | 932 | if (function_exists($slug)) { |
933 | - add_action( $section_slug, $slug, 10, 4); |
|
933 | + add_action($section_slug, $slug, 10, 4); |
|
934 | 934 | } |
935 | 935 | } |
936 | 936 | } |
@@ -939,7 +939,7 @@ discard block |
||
939 | 939 | * filter to allow import images for free edition of WP All Import |
940 | 940 | * |
941 | 941 | */ |
942 | - function is_allow_import_images($is_allow, $post_type){ |
|
942 | + function is_allow_import_images($is_allow, $post_type) { |
|
943 | 943 | return ($this->is_active_addon($post_type)) ? true : $is_allow; |
944 | 944 | } |
945 | 945 | |
@@ -948,8 +948,8 @@ discard block |
||
948 | 948 | * filter to control additional images sections |
949 | 949 | * |
950 | 950 | */ |
951 | - function additional_sections($sections){ |
|
952 | - if ( ! empty($this->image_sections) ){ |
|
951 | + function additional_sections($sections) { |
|
952 | + if (!empty($this->image_sections)) { |
|
953 | 953 | foreach ($this->image_sections as $add_section) { |
954 | 954 | $sections[] = $add_section; |
955 | 955 | } |
@@ -962,7 +962,7 @@ discard block |
||
962 | 962 | * remove the 'Don't touch existing images, append new images' when more than one image section is in use. |
963 | 963 | * |
964 | 964 | */ |
965 | - function filter_is_show_add_new_images($is_show, $post_type){ |
|
965 | + function filter_is_show_add_new_images($is_show, $post_type) { |
|
966 | 966 | return ($this->is_active_addon($post_type)) ? false : $is_show; |
967 | 967 | } |
968 | 968 | |
@@ -971,12 +971,12 @@ discard block |
||
971 | 971 | * disable the default images section |
972 | 972 | * |
973 | 973 | */ |
974 | - function disable_default_images($post_type = false){ |
|
974 | + function disable_default_images($post_type = false) { |
|
975 | 975 | |
976 | 976 | add_filter('wp_all_import_is_images_section_enabled', array($this, 'is_enable_default_images_section'), 10, 2); |
977 | 977 | |
978 | 978 | } |
979 | - function is_enable_default_images_section($is_enabled, $post_type){ |
|
979 | + function is_enable_default_images_section($is_enabled, $post_type) { |
|
980 | 980 | |
981 | 981 | return ($this->is_active_addon($post_type)) ? false : true; |
982 | 982 | |
@@ -988,7 +988,7 @@ discard block |
||
988 | 988 | |
989 | 989 | $data = array(); // parsed data |
990 | 990 | |
991 | - if ( ! empty($import->options[$this->slug])){ |
|
991 | + if (!empty($import->options[$this->slug])) { |
|
992 | 992 | |
993 | 993 | $this->logger = $parsingData['logger']; |
994 | 994 | |
@@ -997,9 +997,9 @@ discard block |
||
997 | 997 | $tmp_files = array(); |
998 | 998 | |
999 | 999 | foreach ($options[$this->slug] as $option_name => $option_value) { |
1000 | - if ( isset($import->options[$this->slug][$option_name]) and $import->options[$this->slug][$option_name] != '') { |
|
1000 | + if (isset($import->options[$this->slug][$option_name]) and $import->options[$this->slug][$option_name] != '') { |
|
1001 | 1001 | if ($import->options[$this->slug][$option_name] == "xpath") { |
1002 | - if ($import->options[$this->slug]['xpaths'][$option_name] == ""){ |
|
1002 | + if ($import->options[$this->slug]['xpaths'][$option_name] == "") { |
|
1003 | 1003 | $count and $data[$option_name] = array_fill(0, $count, ""); |
1004 | 1004 | } else { |
1005 | 1005 | $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug]['xpaths'][$option_name], $file)->parse(); |
@@ -1038,11 +1038,11 @@ discard block |
||
1038 | 1038 | |
1039 | 1039 | if ($import_options['update_all_data'] == 'yes') return true; |
1040 | 1040 | |
1041 | - if ( ! $import_options['is_update_custom_fields'] ) return false; |
|
1041 | + if (!$import_options['is_update_custom_fields']) return false; |
|
1042 | 1042 | |
1043 | 1043 | if ($import_options['update_custom_fields_logic'] == "full_update") return true; |
1044 | - if ($import_options['update_custom_fields_logic'] == "only" and ! empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list']) ) return true; |
|
1045 | - if ($import_options['update_custom_fields_logic'] == "all_except" and ( empty($import_options['custom_fields_list']) or ! in_array($meta_key, $import_options['custom_fields_list']) )) return true; |
|
1044 | + if ($import_options['update_custom_fields_logic'] == "only" and !empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list'])) return true; |
|
1045 | + if ($import_options['update_custom_fields_logic'] == "all_except" and (empty($import_options['custom_fields_list']) or !in_array($meta_key, $import_options['custom_fields_list']))) return true; |
|
1046 | 1046 | |
1047 | 1047 | return false; |
1048 | 1048 | |
@@ -1058,11 +1058,11 @@ discard block |
||
1058 | 1058 | |
1059 | 1059 | if ($import_options['update_all_data'] == 'yes') return true; |
1060 | 1060 | |
1061 | - if ( ! $import_options['is_update_categories'] ) return false; |
|
1061 | + if (!$import_options['is_update_categories']) return false; |
|
1062 | 1062 | |
1063 | 1063 | if ($import_options['update_categories_logic'] == "full_update") return true; |
1064 | - if ($import_options['update_categories_logic'] == "only" and ! empty($import_options['taxonomies_list']) and is_array($import_options['taxonomies_list']) and in_array($tax_name, $import_options['taxonomies_list']) ) return true; |
|
1065 | - if ($import_options['update_categories_logic'] == "all_except" and ( empty($import_options['taxonomies_list']) or ! in_array($tax_name, $import_options['taxonomies_list']) )) return true; |
|
1064 | + if ($import_options['update_categories_logic'] == "only" and !empty($import_options['taxonomies_list']) and is_array($import_options['taxonomies_list']) and in_array($tax_name, $import_options['taxonomies_list'])) return true; |
|
1065 | + if ($import_options['update_categories_logic'] == "all_except" and (empty($import_options['taxonomies_list']) or !in_array($tax_name, $import_options['taxonomies_list']))) return true; |
|
1066 | 1066 | |
1067 | 1067 | return false; |
1068 | 1068 | |
@@ -1083,8 +1083,8 @@ discard block |
||
1083 | 1083 | |
1084 | 1084 | |
1085 | 1085 | function admin_notice_ignore() { |
1086 | - if (isset($_GET[$this->slug.'_ignore']) && '0' == $_GET[$this->slug.'_ignore'] ) { |
|
1087 | - update_option($this->slug.'_ignore', 'true'); |
|
1086 | + if (isset($_GET[$this->slug . '_ignore']) && '0' == $_GET[$this->slug . '_ignore']) { |
|
1087 | + update_option($this->slug . '_ignore', 'true'); |
|
1088 | 1088 | } |
1089 | 1089 | } |
1090 | 1090 | |
@@ -1094,10 +1094,10 @@ discard block |
||
1094 | 1094 | if ($this->notice_text) { |
1095 | 1095 | $notice_text = $this->notice_text; |
1096 | 1096 | } else { |
1097 | - $notice_text = $this->name.' requires WP All Import <a href="http://www.wpallimport.com/" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>.'; |
|
1097 | + $notice_text = $this->name . ' requires WP All Import <a href="http://www.wpallimport.com/" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>.'; |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | - if (!get_option(sanitize_key($this->slug).'_notice_ignore')) { |
|
1100 | + if (!get_option(sanitize_key($this->slug) . '_notice_ignore')) { |
|
1101 | 1101 | |
1102 | 1102 | ?> |
1103 | 1103 | |
@@ -1105,9 +1105,9 @@ discard block |
||
1105 | 1105 | <p><?php _e( |
1106 | 1106 | sprintf( |
1107 | 1107 | $notice_text, |
1108 | - '?'.$this->slug.'_ignore=0' |
|
1108 | + '?' . $this->slug . '_ignore=0' |
|
1109 | 1109 | ), |
1110 | - 'rapid_addon_'.$this->slug |
|
1110 | + 'rapid_addon_' . $this->slug |
|
1111 | 1111 | ); ?></p> |
1112 | 1112 | </div> |
1113 | 1113 | |
@@ -1126,14 +1126,14 @@ discard block |
||
1126 | 1126 | |
1127 | 1127 | $is_show_notice = false; |
1128 | 1128 | |
1129 | - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
1129 | + include_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
1130 | 1130 | |
1131 | - if ( ! class_exists( 'PMXI_Plugin' ) ) { |
|
1131 | + if (!class_exists('PMXI_Plugin')) { |
|
1132 | 1132 | $is_show_notice = true; |
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | // Supported Themes |
1136 | - if ( ! $is_show_notice and ! empty($conditions['themes']) ){ |
|
1136 | + if (!$is_show_notice and !empty($conditions['themes'])) { |
|
1137 | 1137 | |
1138 | 1138 | $themeInfo = wp_get_theme(); |
1139 | 1139 | $parentInfo = $themeInfo->parent(); |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | |
1142 | 1142 | $is_show_notice = in_array($currentTheme, $conditions['themes']) ? false : true; |
1143 | 1143 | |
1144 | - if ( $is_show_notice and $parentInfo ){ |
|
1144 | + if ($is_show_notice and $parentInfo) { |
|
1145 | 1145 | $parent_theme = $parentInfo->get('Name'); |
1146 | 1146 | $is_show_notice = in_array($parent_theme, $conditions['themes']) ? false : true; |
1147 | 1147 | } |
@@ -1149,22 +1149,22 @@ discard block |
||
1149 | 1149 | } |
1150 | 1150 | |
1151 | 1151 | // Required Plugins |
1152 | - if ( ! $is_show_notice and ! empty($conditions['plugins']) ){ |
|
1152 | + if (!$is_show_notice and !empty($conditions['plugins'])) { |
|
1153 | 1153 | |
1154 | 1154 | $requires_counter = 0; |
1155 | 1155 | foreach ($conditions['plugins'] as $plugin) { |
1156 | - if ( is_plugin_active($plugin) ) $requires_counter++; |
|
1156 | + if (is_plugin_active($plugin)) $requires_counter++; |
|
1157 | 1157 | } |
1158 | 1158 | |
1159 | - if ($requires_counter != count($conditions['plugins'])){ |
|
1159 | + if ($requires_counter != count($conditions['plugins'])) { |
|
1160 | 1160 | $is_show_notice = true; |
1161 | 1161 | } |
1162 | 1162 | |
1163 | 1163 | } |
1164 | 1164 | |
1165 | - if ( $is_show_notice ){ |
|
1165 | + if ($is_show_notice) { |
|
1166 | 1166 | |
1167 | - if ( $notice_text != '' ) { |
|
1167 | + if ($notice_text != '') { |
|
1168 | 1168 | $this->notice_text = $notice_text; |
1169 | 1169 | } |
1170 | 1170 | |
@@ -1173,34 +1173,34 @@ discard block |
||
1173 | 1173 | |
1174 | 1174 | } |
1175 | 1175 | |
1176 | - function log( $m = false){ |
|
1176 | + function log($m = false) { |
|
1177 | 1177 | |
1178 | 1178 | $m and $this->logger and call_user_func($this->logger, $m); |
1179 | 1179 | |
1180 | 1180 | } |
1181 | 1181 | |
1182 | - public function remove_post_type( $type = '' ) { |
|
1183 | - if ( ! empty( $type ) ) { |
|
1184 | - $this->add_option( 'post_types_to_remove', $type ); |
|
1182 | + public function remove_post_type($type = '') { |
|
1183 | + if (!empty($type)) { |
|
1184 | + $this->add_option('post_types_to_remove', $type); |
|
1185 | 1185 | } |
1186 | 1186 | } |
1187 | 1187 | |
1188 | - public function filter_post_types( $custom_types = array(), $custom_type = '' ) { |
|
1188 | + public function filter_post_types($custom_types = array(), $custom_type = '') { |
|
1189 | 1189 | $options = $this->options_array(); |
1190 | 1190 | $option_key = 'post_types_to_remove'; |
1191 | 1191 | |
1192 | - if ( array_key_exists( $option_key, $options ) ) { |
|
1193 | - $type = $options[ $option_key ]; |
|
1192 | + if (array_key_exists($option_key, $options)) { |
|
1193 | + $type = $options[$option_key]; |
|
1194 | 1194 | |
1195 | - if ( ! empty( $type ) ) { |
|
1196 | - if ( ! is_array( $type ) ) { |
|
1197 | - if ( array_key_exists( $type, $custom_types ) ) { |
|
1198 | - unset( $custom_types[ $type ] ); |
|
1195 | + if (!empty($type)) { |
|
1196 | + if (!is_array($type)) { |
|
1197 | + if (array_key_exists($type, $custom_types)) { |
|
1198 | + unset($custom_types[$type]); |
|
1199 | 1199 | } |
1200 | 1200 | } else { |
1201 | - foreach ( $type as $key => $post_type ) { |
|
1202 | - if ( array_key_exists( $post_type, $custom_types ) ) { |
|
1203 | - unset( $custom_types[ $post_type ] ); |
|
1201 | + foreach ($type as $key => $post_type) { |
|
1202 | + if (array_key_exists($post_type, $custom_types)) { |
|
1203 | + unset($custom_types[$post_type]); |
|
1204 | 1204 | } |
1205 | 1205 | } |
1206 | 1206 | } |
@@ -1209,26 +1209,26 @@ discard block |
||
1209 | 1209 | return $custom_types; |
1210 | 1210 | } |
1211 | 1211 | |
1212 | - public function sort_post_types( array $order ) { |
|
1212 | + public function sort_post_types(array $order) { |
|
1213 | 1213 | $options = $this->options_array(); |
1214 | 1214 | $option_key = 'post_type_move'; |
1215 | 1215 | |
1216 | - if ( array_key_exists( $option_key, $options ) ) { |
|
1217 | - $move_rules = maybe_unserialize( $options[ $option_key ] ); |
|
1216 | + if (array_key_exists($option_key, $options)) { |
|
1217 | + $move_rules = maybe_unserialize($options[$option_key]); |
|
1218 | 1218 | |
1219 | - foreach ( $move_rules as $rule ) { |
|
1219 | + foreach ($move_rules as $rule) { |
|
1220 | 1220 | $move_this = $rule['move_this']; |
1221 | 1221 | $move_to = $rule['move_to']; |
1222 | - if ( $move_to > count( $order ) ) { |
|
1223 | - if ( ( $rm_key = array_search( $move_this, $order ) ) !== false ) { |
|
1224 | - unset( $order[ $rm_key ] ); |
|
1222 | + if ($move_to > count($order)) { |
|
1223 | + if (($rm_key = array_search($move_this, $order)) !== false) { |
|
1224 | + unset($order[$rm_key]); |
|
1225 | 1225 | } |
1226 | - array_push( $order, $move_this ); |
|
1226 | + array_push($order, $move_this); |
|
1227 | 1227 | } else { |
1228 | - if ( ( $rm_key = array_search( $move_this, $order ) ) !== false ) { |
|
1229 | - unset( $order[ $rm_key ] ); |
|
1228 | + if (($rm_key = array_search($move_this, $order)) !== false) { |
|
1229 | + unset($order[$rm_key]); |
|
1230 | 1230 | } |
1231 | - array_splice( $order, $move_to, 0, $move_this ); |
|
1231 | + array_splice($order, $move_to, 0, $move_this); |
|
1232 | 1232 | } |
1233 | 1233 | } |
1234 | 1234 | |
@@ -1238,57 +1238,57 @@ discard block |
||
1238 | 1238 | return $order; |
1239 | 1239 | } |
1240 | 1240 | |
1241 | - public function move_post_type( $move_this = null, $move_to = null ) { |
|
1241 | + public function move_post_type($move_this = null, $move_to = null) { |
|
1242 | 1242 | $move_rules = array(); |
1243 | 1243 | |
1244 | - if ( ! is_array( $move_this ) && ! is_array( $move_to ) ) { |
|
1244 | + if (!is_array($move_this) && !is_array($move_to)) { |
|
1245 | 1245 | $move_rules[] = array( |
1246 | 1246 | 'move_this' => $move_this, |
1247 | 1247 | 'move_to' => $move_to |
1248 | 1248 | ); |
1249 | 1249 | } else { |
1250 | - foreach ( $move_this as $key => $move_post ) { |
|
1250 | + foreach ($move_this as $key => $move_post) { |
|
1251 | 1251 | $move_rules[] = array( |
1252 | 1252 | 'move_this' => $move_post, |
1253 | - 'move_to' => $move_to[ $key ] |
|
1253 | + 'move_to' => $move_to[$key] |
|
1254 | 1254 | ); |
1255 | 1255 | } |
1256 | 1256 | } |
1257 | 1257 | |
1258 | - $this->add_option( 'post_type_move', $move_rules ); |
|
1258 | + $this->add_option('post_type_move', $move_rules); |
|
1259 | 1259 | } |
1260 | 1260 | |
1261 | - public function set_post_type_image( $post_type = null, $image = null ) { |
|
1261 | + public function set_post_type_image($post_type = null, $image = null) { |
|
1262 | 1262 | $post_type_image_rules = array(); |
1263 | 1263 | |
1264 | - if ( ! is_array( $post_type ) ) { |
|
1264 | + if (!is_array($post_type)) { |
|
1265 | 1265 | |
1266 | - $post_type_image_rules[ $post_type ] = array( |
|
1266 | + $post_type_image_rules[$post_type] = array( |
|
1267 | 1267 | 'post_type' => $post_type, |
1268 | 1268 | 'image' => $image |
1269 | 1269 | ); |
1270 | 1270 | |
1271 | 1271 | } else { |
1272 | 1272 | |
1273 | - if ( count( $post_type ) == count( $image ) ) { |
|
1273 | + if (count($post_type) == count($image)) { |
|
1274 | 1274 | |
1275 | - foreach ( $post_type as $key => $post_name ) { |
|
1276 | - $post_type_image_rules[ $post_name ] = array( |
|
1275 | + foreach ($post_type as $key => $post_name) { |
|
1276 | + $post_type_image_rules[$post_name] = array( |
|
1277 | 1277 | 'post_type' => $post_name, |
1278 | - 'image' => $image[ $key ] |
|
1278 | + 'image' => $image[$key] |
|
1279 | 1279 | ); |
1280 | 1280 | } |
1281 | 1281 | } |
1282 | 1282 | } |
1283 | 1283 | |
1284 | - $this->add_option( 'post_type_image', $post_type_image_rules ); |
|
1284 | + $this->add_option('post_type_image', $post_type_image_rules); |
|
1285 | 1285 | } |
1286 | 1286 | |
1287 | - public function post_type_image( $image ) { |
|
1287 | + public function post_type_image($image) { |
|
1288 | 1288 | $options = $this->options_array(); |
1289 | 1289 | $option_key = 'post_type_image'; |
1290 | - if ( array_key_exists( $option_key, $options ) ) { |
|
1291 | - $post_type_image_rules = maybe_unserialize( $options[ $option_key ] ); |
|
1290 | + if (array_key_exists($option_key, $options)) { |
|
1291 | + $post_type_image_rules = maybe_unserialize($options[$option_key]); |
|
1292 | 1292 | return $post_type_image_rules; |
1293 | 1293 | } |
1294 | 1294 | return $image; |
@@ -156,7 +156,9 @@ discard block |
||
156 | 156 | |
157 | 157 | function parse($data) { |
158 | 158 | |
159 | - if ( ! $this->is_active_addon($data['import']->options['custom_type'])) return false; |
|
159 | + if ( ! $this->is_active_addon($data['import']->options['custom_type'])) { |
|
160 | + return false; |
|
161 | + } |
|
160 | 162 | |
161 | 163 | $parsedData = $this->helper_parse($data, $this->options_array()); |
162 | 164 | return $parsedData; |
@@ -177,8 +179,7 @@ discard block |
||
177 | 179 | if ($field['type'] == 'accordion') |
178 | 180 | { |
179 | 181 | $this->fields[$value['slug']]['is_sub_field'] = true; |
180 | - } |
|
181 | - else |
|
182 | + } else |
|
182 | 183 | { |
183 | 184 | foreach ($value as $n => $param) { |
184 | 185 | if (is_array($param) and ! empty($this->fields[$param['slug']])){ |
@@ -242,7 +243,9 @@ discard block |
||
242 | 243 | if ( ! empty( $this->fields ) ) { |
243 | 244 | |
244 | 245 | foreach ($this->fields as $field_slug => $field_params) { |
245 | - if (in_array($field_params['type'], array('title', 'plain_text', 'acf'))) continue; |
|
246 | + if (in_array($field_params['type'], array('title', 'plain_text', 'acf'))) { |
|
247 | + continue; |
|
248 | + } |
|
246 | 249 | $default_value = ''; |
247 | 250 | if (!empty($field_params['enum_values'])){ |
248 | 251 | foreach ($field_params['enum_values'] as $key => $value) { |
@@ -310,8 +313,9 @@ discard block |
||
310 | 313 | |
311 | 314 | function post_saved( $importData ){ |
312 | 315 | |
313 | - if (is_callable($this->post_saved_function)) |
|
314 | - call_user_func($this->post_saved_function, $importData['pid'], $importData['import'], $importData['logger']); |
|
316 | + if (is_callable($this->post_saved_function)) { |
|
317 | + call_user_func($this->post_saved_function, $importData['pid'], $importData['import'], $importData['logger']); |
|
318 | + } |
|
315 | 319 | |
316 | 320 | } |
317 | 321 | |
@@ -336,7 +340,9 @@ discard block |
||
336 | 340 | $data = array(); |
337 | 341 | if (!empty($this->fields)){ |
338 | 342 | foreach ($this->fields as $field_slug => $field_params) { |
339 | - if (in_array($field_params['type'], array('title', 'plain_text'))) continue; |
|
343 | + if (in_array($field_params['type'], array('title', 'plain_text'))) { |
|
344 | + continue; |
|
345 | + } |
|
340 | 346 | switch ($field_params['type']) { |
341 | 347 | |
342 | 348 | case 'image': |
@@ -421,7 +427,9 @@ discard block |
||
421 | 427 | $visible_fields = 0; |
422 | 428 | |
423 | 429 | foreach ($this->fields as $field_slug => $field_params) { |
424 | - if ($field_params['is_sub_field']) continue; |
|
430 | + if ($field_params['is_sub_field']) { |
|
431 | + continue; |
|
432 | + } |
|
425 | 433 | $visible_fields++; |
426 | 434 | } |
427 | 435 | |
@@ -430,7 +438,9 @@ discard block |
||
430 | 438 | foreach ($this->fields as $field_slug => $field_params) { |
431 | 439 | |
432 | 440 | // do not render sub fields |
433 | - if ($field_params['is_sub_field']) continue; |
|
441 | + if ($field_params['is_sub_field']) { |
|
442 | + continue; |
|
443 | + } |
|
434 | 444 | |
435 | 445 | $counter++; |
436 | 446 | |
@@ -561,7 +571,9 @@ discard block |
||
561 | 571 | $fieldData['id'] = $field_params['field_obj']->ID; |
562 | 572 | $fieldData['label'] = $field_params['field_obj']->post_title; |
563 | 573 | $fieldData['key'] = $field_params['field_obj']->post_name; |
564 | - if (empty($fieldData['name'])) $fieldData['name'] = $field_params['field_obj']->post_excerpt; |
|
574 | + if (empty($fieldData['name'])) { |
|
575 | + $fieldData['name'] = $field_params['field_obj']->post_excerpt; |
|
576 | + } |
|
565 | 577 | if (function_exists('pmai_render_field')) { |
566 | 578 | echo pmai_render_field($fieldData, ( ! empty($current_values) ) ? $current_values : array() ); |
567 | 579 | } |
@@ -573,9 +585,12 @@ discard block |
||
573 | 585 | } else if($field_params['type'] == 'plain_text'){ |
574 | 586 | if ($field_params['is_html']): |
575 | 587 | echo $field_params['name']; |
576 | - else: |
|
588 | + else { |
|
589 | + : |
|
577 | 590 | ?> |
578 | - <p style="margin: 0 0 12px 0;"><?php echo $field_params['name'];?></p> |
|
591 | + <p style="margin: 0 0 12px 0;"><?php echo $field_params['name']; |
|
592 | + } |
|
593 | + ?></p> |
|
579 | 594 | <?php |
580 | 595 | endif; |
581 | 596 | } |
@@ -595,8 +610,7 @@ discard block |
||
595 | 610 | if (is_array($value)){ |
596 | 611 | if ($field_params['type'] == 'accordion'){ |
597 | 612 | $sub_fields[$key][] = $this->convert_field($value, $current_values); |
598 | - } |
|
599 | - else |
|
613 | + } else |
|
600 | 614 | { |
601 | 615 | foreach ($value as $k => $sub_field) { |
602 | 616 | if (is_array($sub_field) and ! empty($this->fields[$sub_field['slug']])) |
@@ -758,7 +772,9 @@ discard block |
||
758 | 772 | |
759 | 773 | function add_title($title = '', $tooltip = ''){ |
760 | 774 | |
761 | - if (empty($title)) return; |
|
775 | + if (empty($title)) { |
|
776 | + return; |
|
777 | + } |
|
762 | 778 | |
763 | 779 | return $this->add_field(sanitize_key($title) . time(), $title, 'title', null, $tooltip); |
764 | 780 | |
@@ -766,7 +782,9 @@ discard block |
||
766 | 782 | |
767 | 783 | function add_text($text = '', $is_html = false){ |
768 | 784 | |
769 | - if (empty($text)) return; |
|
785 | + if (empty($text)) { |
|
786 | + return; |
|
787 | + } |
|
770 | 788 | |
771 | 789 | $count = is_array($this->fields) ? count($this->fields) : 0; |
772 | 790 | |
@@ -902,7 +920,9 @@ discard block |
||
902 | 920 | */ |
903 | 921 | function import_images( $slug, $title, $type = 'images', $callback = NULL ){ |
904 | 922 | |
905 | - if ( empty($title) or empty($slug) ) return; |
|
923 | + if ( empty($title) or empty($slug) ) { |
|
924 | + return; |
|
925 | + } |
|
906 | 926 | |
907 | 927 | if (is_array($slug)) { |
908 | 928 | $section_slug = 'pmxi_' . md5(serialize($slug)); |
@@ -1005,8 +1025,7 @@ discard block |
||
1005 | 1025 | $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug]['xpaths'][$option_name], $file)->parse(); |
1006 | 1026 | $tmp_files[] = $file; |
1007 | 1027 | } |
1008 | - } |
|
1009 | - else { |
|
1028 | + } else { |
|
1010 | 1029 | $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug][$option_name], $file)->parse(); |
1011 | 1030 | $tmp_files[] = $file; |
1012 | 1031 | } |
@@ -1036,13 +1055,23 @@ discard block |
||
1036 | 1055 | |
1037 | 1056 | $import_options = $import_options['options']; |
1038 | 1057 | |
1039 | - if ($import_options['update_all_data'] == 'yes') return true; |
|
1058 | + if ($import_options['update_all_data'] == 'yes') { |
|
1059 | + return true; |
|
1060 | + } |
|
1040 | 1061 | |
1041 | - if ( ! $import_options['is_update_custom_fields'] ) return false; |
|
1062 | + if ( ! $import_options['is_update_custom_fields'] ) { |
|
1063 | + return false; |
|
1064 | + } |
|
1042 | 1065 | |
1043 | - if ($import_options['update_custom_fields_logic'] == "full_update") return true; |
|
1044 | - if ($import_options['update_custom_fields_logic'] == "only" and ! empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list']) ) return true; |
|
1045 | - if ($import_options['update_custom_fields_logic'] == "all_except" and ( empty($import_options['custom_fields_list']) or ! in_array($meta_key, $import_options['custom_fields_list']) )) return true; |
|
1066 | + if ($import_options['update_custom_fields_logic'] == "full_update") { |
|
1067 | + return true; |
|
1068 | + } |
|
1069 | + if ($import_options['update_custom_fields_logic'] == "only" and ! empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list']) ) { |
|
1070 | + return true; |
|
1071 | + } |
|
1072 | + if ($import_options['update_custom_fields_logic'] == "all_except" and ( empty($import_options['custom_fields_list']) or ! in_array($meta_key, $import_options['custom_fields_list']) )) { |
|
1073 | + return true; |
|
1074 | + } |
|
1046 | 1075 | |
1047 | 1076 | return false; |
1048 | 1077 | |
@@ -1056,13 +1085,23 @@ discard block |
||
1056 | 1085 | |
1057 | 1086 | $import_options = $import_options['options']; |
1058 | 1087 | |
1059 | - if ($import_options['update_all_data'] == 'yes') return true; |
|
1088 | + if ($import_options['update_all_data'] == 'yes') { |
|
1089 | + return true; |
|
1090 | + } |
|
1060 | 1091 | |
1061 | - if ( ! $import_options['is_update_categories'] ) return false; |
|
1092 | + if ( ! $import_options['is_update_categories'] ) { |
|
1093 | + return false; |
|
1094 | + } |
|
1062 | 1095 | |
1063 | - if ($import_options['update_categories_logic'] == "full_update") return true; |
|
1064 | - if ($import_options['update_categories_logic'] == "only" and ! empty($import_options['taxonomies_list']) and is_array($import_options['taxonomies_list']) and in_array($tax_name, $import_options['taxonomies_list']) ) return true; |
|
1065 | - if ($import_options['update_categories_logic'] == "all_except" and ( empty($import_options['taxonomies_list']) or ! in_array($tax_name, $import_options['taxonomies_list']) )) return true; |
|
1096 | + if ($import_options['update_categories_logic'] == "full_update") { |
|
1097 | + return true; |
|
1098 | + } |
|
1099 | + if ($import_options['update_categories_logic'] == "only" and ! empty($import_options['taxonomies_list']) and is_array($import_options['taxonomies_list']) and in_array($tax_name, $import_options['taxonomies_list']) ) { |
|
1100 | + return true; |
|
1101 | + } |
|
1102 | + if ($import_options['update_categories_logic'] == "all_except" and ( empty($import_options['taxonomies_list']) or ! in_array($tax_name, $import_options['taxonomies_list']) )) { |
|
1103 | + return true; |
|
1104 | + } |
|
1066 | 1105 | |
1067 | 1106 | return false; |
1068 | 1107 | |
@@ -1072,11 +1111,17 @@ discard block |
||
1072 | 1111 | |
1073 | 1112 | $import_options = $import_options['options']; |
1074 | 1113 | |
1075 | - if ($import_options['update_all_data'] == 'yes') return true; |
|
1114 | + if ($import_options['update_all_data'] == 'yes') { |
|
1115 | + return true; |
|
1116 | + } |
|
1076 | 1117 | |
1077 | - if (!$import_options['is_update_images']) return false; |
|
1118 | + if (!$import_options['is_update_images']) { |
|
1119 | + return false; |
|
1120 | + } |
|
1078 | 1121 | |
1079 | - if ($import_options['is_update_images']) return true; |
|
1122 | + if ($import_options['is_update_images']) { |
|
1123 | + return true; |
|
1124 | + } |
|
1080 | 1125 | |
1081 | 1126 | return false; |
1082 | 1127 | } |
@@ -1153,7 +1198,9 @@ discard block |
||
1153 | 1198 | |
1154 | 1199 | $requires_counter = 0; |
1155 | 1200 | foreach ($conditions['plugins'] as $plugin) { |
1156 | - if ( is_plugin_active($plugin) ) $requires_counter++; |
|
1201 | + if ( is_plugin_active($plugin) ) { |
|
1202 | + $requires_counter++; |
|
1203 | + } |
|
1157 | 1204 | } |
1158 | 1205 | |
1159 | 1206 | if ($requires_counter != count($conditions['plugins'])){ |
@@ -14,133 +14,133 @@ |
||
14 | 14 | */ |
15 | 15 | class GetPaid_WP_All_Import { |
16 | 16 | |
17 | - /** |
|
18 | - * @var RapidAddon[] |
|
19 | - */ |
|
20 | - protected $add_ons; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - protected $datastores = array( |
|
26 | - 'item' =>'WPInv_Item', |
|
27 | - 'invoice' =>'WPInv_Invoice', |
|
28 | - 'discount' =>'WPInv_Discount', |
|
29 | - ); |
|
17 | + /** |
|
18 | + * @var RapidAddon[] |
|
19 | + */ |
|
20 | + protected $add_ons; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + protected $datastores = array( |
|
26 | + 'item' =>'WPInv_Item', |
|
27 | + 'invoice' =>'WPInv_Invoice', |
|
28 | + 'discount' =>'WPInv_Discount', |
|
29 | + ); |
|
30 | 30 | |
31 | 31 | /** |
32 | - * Class constructor. |
|
33 | - */ |
|
32 | + * Class constructor. |
|
33 | + */ |
|
34 | 34 | public function __construct() { |
35 | 35 | |
36 | - // Init each store separately. |
|
37 | - foreach ( array_keys( $this->datastores ) as $key ) { |
|
38 | - $this->init_store( $key ); |
|
39 | - } |
|
36 | + // Init each store separately. |
|
37 | + foreach ( array_keys( $this->datastores ) as $key ) { |
|
38 | + $this->init_store( $key ); |
|
39 | + } |
|
40 | 40 | |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Inits a store. |
|
45 | - */ |
|
43 | + /** |
|
44 | + * Inits a store. |
|
45 | + */ |
|
46 | 46 | public function init_store( $key ) { |
47 | 47 | |
48 | - // Register the add-on. |
|
49 | - $this->add_ons[ $key ] = new RapidAddon( 'GetPaid', 'getpaid_wp_al_import_' . $key ); |
|
48 | + // Register the add-on. |
|
49 | + $this->add_ons[ $key ] = new RapidAddon( 'GetPaid', 'getpaid_wp_al_import_' . $key ); |
|
50 | 50 | |
51 | - // Create import function. |
|
52 | - $import_function = function ( $post_id, $data, $import_options, $_post ) use ( $key ) { |
|
53 | - $this->import_store( $key, $post_id, $data, $import_options, $_post ); |
|
51 | + // Create import function. |
|
52 | + $import_function = function ( $post_id, $data, $import_options, $_post ) use ( $key ) { |
|
53 | + $this->import_store( $key, $post_id, $data, $import_options, $_post ); |
|
54 | 54 | }; |
55 | 55 | |
56 | - $this->add_ons[ $key ]->set_import_function( $import_function ); |
|
56 | + $this->add_ons[ $key ]->set_import_function( $import_function ); |
|
57 | 57 | |
58 | - // Register store fields. |
|
59 | - $this->add_store_fields( $key ); |
|
58 | + // Register store fields. |
|
59 | + $this->add_store_fields( $key ); |
|
60 | 60 | |
61 | - // Only load on the correct post type. |
|
62 | - $this->add_ons[ $key ]->run( array( 'post_types' => array( 'wpi_' . $key ) ) ); |
|
61 | + // Only load on the correct post type. |
|
62 | + $this->add_ons[ $key ]->run( array( 'post_types' => array( 'wpi_' . $key ) ) ); |
|
63 | 63 | |
64 | - // Disable images. |
|
65 | - $this->add_ons[ $key ]->disable_default_images(); |
|
64 | + // Disable images. |
|
65 | + $this->add_ons[ $key ]->disable_default_images(); |
|
66 | 66 | |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Retrieves store fields. |
|
71 | - */ |
|
69 | + /** |
|
70 | + * Retrieves store fields. |
|
71 | + */ |
|
72 | 72 | public function get_store_fields( $key ) { |
73 | 73 | |
74 | - // Fetch from data/invoice-schema.php, from data/discount-schema.php, from data/item-schema.php |
|
75 | - $fields = wpinv_get_data( $key . '-schema' ); |
|
74 | + // Fetch from data/invoice-schema.php, from data/discount-schema.php, from data/item-schema.php |
|
75 | + $fields = wpinv_get_data( $key . '-schema' ); |
|
76 | 76 | |
77 | - if ( empty( $fields ) ) { |
|
78 | - return array(); |
|
79 | - } |
|
77 | + if ( empty( $fields ) ) { |
|
78 | + return array(); |
|
79 | + } |
|
80 | 80 | |
81 | - // Clean the fields. |
|
82 | - $prepared = array(); |
|
83 | - foreach ( $fields as $id => $field ) { |
|
81 | + // Clean the fields. |
|
82 | + $prepared = array(); |
|
83 | + foreach ( $fields as $id => $field ) { |
|
84 | 84 | |
85 | - // Skip read only fields. |
|
86 | - if ( ! empty( $field['readonly'] ) ) { |
|
87 | - continue; |
|
88 | - } |
|
85 | + // Skip read only fields. |
|
86 | + if ( ! empty( $field['readonly'] ) ) { |
|
87 | + continue; |
|
88 | + } |
|
89 | 89 | |
90 | - $prepared[ $id ] = $field; |
|
90 | + $prepared[ $id ] = $field; |
|
91 | 91 | |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - return $prepared; |
|
94 | + return $prepared; |
|
95 | 95 | |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Registers store fields. |
|
100 | - */ |
|
98 | + /** |
|
99 | + * Registers store fields. |
|
100 | + */ |
|
101 | 101 | public function add_store_fields( $key ) { |
102 | 102 | |
103 | - foreach ( $this->get_store_fields( $key ) as $field_id => $data ) { |
|
104 | - $this->add_ons[ $key ]->add_field( $field_id, $data['description'], 'text' ); |
|
105 | - } |
|
103 | + foreach ( $this->get_store_fields( $key ) as $field_id => $data ) { |
|
104 | + $this->add_ons[ $key ]->add_field( $field_id, $data['description'], 'text' ); |
|
105 | + } |
|
106 | 106 | |
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * Handles store imports. |
|
111 | - */ |
|
109 | + /** |
|
110 | + * Handles store imports. |
|
111 | + */ |
|
112 | 112 | public function import_store( $key, $post_id, $data, $import_options, $_post ) { |
113 | 113 | |
114 | - // Is the store class set? |
|
115 | - if ( ! isset( $this->datastores[ $key ] ) ) { |
|
116 | - return; |
|
117 | - } |
|
114 | + // Is the store class set? |
|
115 | + if ( ! isset( $this->datastores[ $key ] ) ) { |
|
116 | + return; |
|
117 | + } |
|
118 | 118 | |
119 | - /**@var GetPaid_Data */ |
|
120 | - $data_store = new $this->datastores[ $key ]( $post_id ); |
|
119 | + /**@var GetPaid_Data */ |
|
120 | + $data_store = new $this->datastores[ $key ]( $post_id ); |
|
121 | 121 | |
122 | - // Abort if the invoice/item/discount does not exist. |
|
123 | - if ( ! $data_store->exists() ) { |
|
124 | - return; |
|
125 | - } |
|
122 | + // Abort if the invoice/item/discount does not exist. |
|
123 | + if ( ! $data_store->exists() ) { |
|
124 | + return; |
|
125 | + } |
|
126 | 126 | |
127 | - // Prepare data props. |
|
128 | - $prepared = array(); |
|
127 | + // Prepare data props. |
|
128 | + $prepared = array(); |
|
129 | 129 | |
130 | - foreach ( array_keys( $this->get_store_fields( $key ) ) as $field ) { |
|
131 | - // Make sure the user has allowed this field to be updated. |
|
132 | - if ( empty( $_post['ID'] ) || $this->add_ons[ $key ]->can_update_meta( $field, $import_options ) ) { |
|
130 | + foreach ( array_keys( $this->get_store_fields( $key ) ) as $field ) { |
|
131 | + // Make sure the user has allowed this field to be updated. |
|
132 | + if ( empty( $_post['ID'] ) || $this->add_ons[ $key ]->can_update_meta( $field, $import_options ) ) { |
|
133 | 133 | |
134 | - // Update the custom field with the imported data. |
|
135 | - $prepared[ $field ] = $data[ $field ]; |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - // Only update if we have something to update. |
|
140 | - if ( ! empty( $prepared ) ) { |
|
141 | - $data_store->set_props( $prepared ); |
|
142 | - $data_store->save(); |
|
143 | - } |
|
134 | + // Update the custom field with the imported data. |
|
135 | + $prepared[ $field ] = $data[ $field ]; |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + // Only update if we have something to update. |
|
140 | + if ( ! empty( $prepared ) ) { |
|
141 | + $data_store->set_props( $prepared ); |
|
142 | + $data_store->save(); |
|
143 | + } |
|
144 | 144 | |
145 | 145 | } |
146 | 146 |
@@ -5,9 +5,9 @@ discard block |
||
5 | 5 | * @package GetPaid |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | -include plugin_dir_path( __FILE__ ) . 'rapid-addon.php'; |
|
10 | +include plugin_dir_path(__FILE__) . 'rapid-addon.php'; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * WP All Import class. |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | public function __construct() { |
35 | 35 | |
36 | 36 | // Init each store separately. |
37 | - foreach ( array_keys( $this->datastores ) as $key ) { |
|
38 | - $this->init_store( $key ); |
|
37 | + foreach (array_keys($this->datastores) as $key) { |
|
38 | + $this->init_store($key); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | } |
@@ -43,51 +43,51 @@ discard block |
||
43 | 43 | /** |
44 | 44 | * Inits a store. |
45 | 45 | */ |
46 | - public function init_store( $key ) { |
|
46 | + public function init_store($key) { |
|
47 | 47 | |
48 | 48 | // Register the add-on. |
49 | - $this->add_ons[ $key ] = new RapidAddon( 'GetPaid', 'getpaid_wp_al_import_' . $key ); |
|
49 | + $this->add_ons[$key] = new RapidAddon('GetPaid', 'getpaid_wp_al_import_' . $key); |
|
50 | 50 | |
51 | 51 | // Create import function. |
52 | - $import_function = function ( $post_id, $data, $import_options, $_post ) use ( $key ) { |
|
53 | - $this->import_store( $key, $post_id, $data, $import_options, $_post ); |
|
52 | + $import_function = function($post_id, $data, $import_options, $_post) use ($key) { |
|
53 | + $this->import_store($key, $post_id, $data, $import_options, $_post); |
|
54 | 54 | }; |
55 | 55 | |
56 | - $this->add_ons[ $key ]->set_import_function( $import_function ); |
|
56 | + $this->add_ons[$key]->set_import_function($import_function); |
|
57 | 57 | |
58 | 58 | // Register store fields. |
59 | - $this->add_store_fields( $key ); |
|
59 | + $this->add_store_fields($key); |
|
60 | 60 | |
61 | 61 | // Only load on the correct post type. |
62 | - $this->add_ons[ $key ]->run( array( 'post_types' => array( 'wpi_' . $key ) ) ); |
|
62 | + $this->add_ons[$key]->run(array('post_types' => array('wpi_' . $key))); |
|
63 | 63 | |
64 | 64 | // Disable images. |
65 | - $this->add_ons[ $key ]->disable_default_images(); |
|
65 | + $this->add_ons[$key]->disable_default_images(); |
|
66 | 66 | |
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Retrieves store fields. |
71 | 71 | */ |
72 | - public function get_store_fields( $key ) { |
|
72 | + public function get_store_fields($key) { |
|
73 | 73 | |
74 | 74 | // Fetch from data/invoice-schema.php, from data/discount-schema.php, from data/item-schema.php |
75 | - $fields = wpinv_get_data( $key . '-schema' ); |
|
75 | + $fields = wpinv_get_data($key . '-schema'); |
|
76 | 76 | |
77 | - if ( empty( $fields ) ) { |
|
77 | + if (empty($fields)) { |
|
78 | 78 | return array(); |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Clean the fields. |
82 | 82 | $prepared = array(); |
83 | - foreach ( $fields as $id => $field ) { |
|
83 | + foreach ($fields as $id => $field) { |
|
84 | 84 | |
85 | 85 | // Skip read only fields. |
86 | - if ( ! empty( $field['readonly'] ) ) { |
|
86 | + if (!empty($field['readonly'])) { |
|
87 | 87 | continue; |
88 | 88 | } |
89 | 89 | |
90 | - $prepared[ $id ] = $field; |
|
90 | + $prepared[$id] = $field; |
|
91 | 91 | |
92 | 92 | } |
93 | 93 | |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | /** |
99 | 99 | * Registers store fields. |
100 | 100 | */ |
101 | - public function add_store_fields( $key ) { |
|
101 | + public function add_store_fields($key) { |
|
102 | 102 | |
103 | - foreach ( $this->get_store_fields( $key ) as $field_id => $data ) { |
|
104 | - $this->add_ons[ $key ]->add_field( $field_id, $data['description'], 'text' ); |
|
103 | + foreach ($this->get_store_fields($key) as $field_id => $data) { |
|
104 | + $this->add_ons[$key]->add_field($field_id, $data['description'], 'text'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | } |
@@ -109,36 +109,36 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * Handles store imports. |
111 | 111 | */ |
112 | - public function import_store( $key, $post_id, $data, $import_options, $_post ) { |
|
112 | + public function import_store($key, $post_id, $data, $import_options, $_post) { |
|
113 | 113 | |
114 | 114 | // Is the store class set? |
115 | - if ( ! isset( $this->datastores[ $key ] ) ) { |
|
115 | + if (!isset($this->datastores[$key])) { |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | |
119 | 119 | /**@var GetPaid_Data */ |
120 | - $data_store = new $this->datastores[ $key ]( $post_id ); |
|
120 | + $data_store = new $this->datastores[$key]($post_id); |
|
121 | 121 | |
122 | 122 | // Abort if the invoice/item/discount does not exist. |
123 | - if ( ! $data_store->exists() ) { |
|
123 | + if (!$data_store->exists()) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | 127 | // Prepare data props. |
128 | 128 | $prepared = array(); |
129 | 129 | |
130 | - foreach ( array_keys( $this->get_store_fields( $key ) ) as $field ) { |
|
130 | + foreach (array_keys($this->get_store_fields($key)) as $field) { |
|
131 | 131 | // Make sure the user has allowed this field to be updated. |
132 | - if ( empty( $_post['ID'] ) || $this->add_ons[ $key ]->can_update_meta( $field, $import_options ) ) { |
|
132 | + if (empty($_post['ID']) || $this->add_ons[$key]->can_update_meta($field, $import_options)) { |
|
133 | 133 | |
134 | 134 | // Update the custom field with the imported data. |
135 | - $prepared[ $field ] = $data[ $field ]; |
|
135 | + $prepared[$field] = $data[$field]; |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
139 | 139 | // Only update if we have something to update. |
140 | - if ( ! empty( $prepared ) ) { |
|
141 | - $data_store->set_props( $prepared ); |
|
140 | + if (!empty($prepared)) { |
|
141 | + $data_store->set_props($prepared); |
|
142 | 142 | $data_store->save(); |
143 | 143 | } |
144 | 144 |
@@ -12,75 +12,75 @@ discard block |
||
12 | 12 | * @var GetPaid_Payment_Form $form |
13 | 13 | */ |
14 | 14 | |
15 | -defined( 'ABSPATH' ) || exit; |
|
15 | +defined('ABSPATH') || exit; |
|
16 | 16 | |
17 | -$field_type = sanitize_key( $field_type ); |
|
17 | +$field_type = sanitize_key($field_type); |
|
18 | 18 | |
19 | 19 | echo "<div class='row $field_type'>"; |
20 | 20 | |
21 | 21 | // Prepare current user. |
22 | -if ( ! empty( $form->invoice ) ) { |
|
22 | +if (!empty($form->invoice)) { |
|
23 | 23 | $user_id = $form->invoice->get_user_id(); |
24 | 24 | } |
25 | 25 | |
26 | -if ( empty( $user_id ) && is_user_logged_in() ) { |
|
26 | +if (empty($user_id) && is_user_logged_in()) { |
|
27 | 27 | $user_id = get_current_user_id(); |
28 | 28 | } |
29 | 29 | |
30 | -if ( ! empty( $user_id ) ) { |
|
31 | - $user = wp_get_current_user(); |
|
30 | +if (!empty($user_id)) { |
|
31 | + $user = wp_get_current_user(); |
|
32 | 32 | } |
33 | 33 | |
34 | -foreach ( $fields as $address_field ) { |
|
34 | +foreach ($fields as $address_field) { |
|
35 | 35 | |
36 | 36 | // Skip if it is hidden. |
37 | - if ( empty( $address_field['visible'] ) ) { |
|
37 | + if (empty($address_field['visible'])) { |
|
38 | 38 | continue; |
39 | 39 | } |
40 | 40 | |
41 | - do_action( 'getpaid_payment_form_address_field_before_' . $address_field['name'], $field_type, $address_field ); |
|
41 | + do_action('getpaid_payment_form_address_field_before_' . $address_field['name'], $field_type, $address_field); |
|
42 | 42 | |
43 | 43 | // Prepare variables. |
44 | 44 | $field_name = $address_field['name']; |
45 | 45 | $field_name = "{$field_type}[$field_name]"; |
46 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
47 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
48 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
49 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
50 | - $value = ! empty( $user_id ) ? get_user_meta( $user_id, '_' . $address_field['name'], true ) : ''; |
|
51 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
52 | - |
|
53 | - $method_name = 'get_' . str_replace( 'wpinv_', '', $address_field['name'] ); |
|
54 | - if ( ! empty( $form->invoice ) && is_callable( array( $form->invoice, $method_name ) ) ) { |
|
55 | - $value = call_user_func( array( $form->invoice, $method_name ) ); |
|
46 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
47 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
48 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
49 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
50 | + $value = !empty($user_id) ? get_user_meta($user_id, '_' . $address_field['name'], true) : ''; |
|
51 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
52 | + |
|
53 | + $method_name = 'get_' . str_replace('wpinv_', '', $address_field['name']); |
|
54 | + if (!empty($form->invoice) && is_callable(array($form->invoice, $method_name))) { |
|
55 | + $value = call_user_func(array($form->invoice, $method_name)); |
|
56 | 56 | } |
57 | 57 | |
58 | - if ( empty( $value ) && 'wpinv_first_name' == $address_field['name'] && ! empty( $user ) ) { |
|
58 | + if (empty($value) && 'wpinv_first_name' == $address_field['name'] && !empty($user)) { |
|
59 | 59 | $value = $user->first_name; |
60 | 60 | } |
61 | 61 | |
62 | - if ( empty( $value ) && 'wpinv_last_name' == $address_field['name'] && ! empty( $user ) ) { |
|
62 | + if (empty($value) && 'wpinv_last_name' == $address_field['name'] && !empty($user)) { |
|
63 | 63 | $value = $user->last_name; |
64 | 64 | } |
65 | 65 | |
66 | - if ( ! empty( $address_field['required'] ) ) { |
|
66 | + if (!empty($address_field['required'])) { |
|
67 | 67 | $label .= "<span class='text-danger'> *</span>"; |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Display the country. |
71 | - if ( 'wpinv_country' == $address_field['name'] ) { |
|
71 | + if ('wpinv_country' == $address_field['name']) { |
|
72 | 72 | |
73 | 73 | echo "<div class='form-group $wrap_class getpaid-address-field-wrapper__country'"; |
74 | 74 | |
75 | 75 | echo aui()->select( |
76 | 76 | array( |
77 | 77 | 'options' => wpinv_get_country_list(), |
78 | - 'name' => esc_attr( $field_name ), |
|
79 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
80 | - 'value' => esc_attr( $country ), |
|
78 | + 'name' => esc_attr($field_name), |
|
79 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
80 | + 'value' => esc_attr($country), |
|
81 | 81 | 'placeholder' => $placeholder, |
82 | - 'required' => ! empty( $address_field['required'] ), |
|
83 | - 'label' => wp_kses_post( $label ), |
|
82 | + 'required' => !empty($address_field['required']), |
|
83 | + 'label' => wp_kses_post($label), |
|
84 | 84 | 'label_type' => 'vertical', |
85 | 85 | 'help_text' => $description, |
86 | 86 | 'class' => 'getpaid-address-field wpinv_country', |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | ) |
94 | 94 | ); |
95 | 95 | |
96 | - if ( wpinv_should_validate_vat_number() ) { |
|
96 | + if (wpinv_should_validate_vat_number()) { |
|
97 | 97 | |
98 | 98 | echo aui()->input( |
99 | 99 | array( |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | 'id' => "shipping-toggle$uniqid", |
103 | 103 | 'wrap_class' => "getpaid-address-field-wrapper__address-confirm mt-1 d-none", |
104 | 104 | 'required' => false, |
105 | - 'label' => __( 'I certify that I live in the country selected above', 'invoicing' ) . "<span class='text-danger'> *</span>", |
|
105 | + 'label' => __('I certify that I live in the country selected above', 'invoicing') . "<span class='text-danger'> *</span>", |
|
106 | 106 | 'value' => 1, |
107 | 107 | 'checked' => true, |
108 | 108 | 'class' => 'w-auto', |
@@ -116,27 +116,27 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | // Display the state. |
119 | - else if ( 'wpinv_state' == $address_field['name'] ) { |
|
119 | + else if ('wpinv_state' == $address_field['name']) { |
|
120 | 120 | |
121 | - if ( empty( $value ) ) { |
|
121 | + if (empty($value)) { |
|
122 | 122 | $value = wpinv_get_default_state(); |
123 | 123 | } |
124 | 124 | |
125 | - echo getpaid_get_states_select_markup ( |
|
125 | + echo getpaid_get_states_select_markup( |
|
126 | 126 | $country, |
127 | 127 | $value, |
128 | 128 | $placeholder, |
129 | 129 | $label, |
130 | 130 | $description, |
131 | - ! empty( $address_field['required'] ), |
|
131 | + !empty($address_field['required']), |
|
132 | 132 | $wrap_class, |
133 | 133 | $field_name |
134 | 134 | ); |
135 | 135 | |
136 | 136 | } else { |
137 | 137 | |
138 | - $key = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
139 | - $key = esc_attr( str_replace( '_', '-', $key ) ); |
|
138 | + $key = str_replace('wpinv_', '', $address_field['name']); |
|
139 | + $key = esc_attr(str_replace('_', '-', $key)); |
|
140 | 140 | $autocomplete = ''; |
141 | 141 | $replacements = array( |
142 | 142 | 'zip' => 'postal-code', |
@@ -149,37 +149,37 @@ discard block |
||
149 | 149 | ); |
150 | 150 | |
151 | 151 | |
152 | - if ( isset( $replacements[ $key ] ) ) { |
|
152 | + if (isset($replacements[$key])) { |
|
153 | 153 | $autocomplete = array( |
154 | - 'autocomplete' => "$field_type {$replacements[ $key ]}", |
|
154 | + 'autocomplete' => "$field_type {$replacements[$key]}", |
|
155 | 155 | ); |
156 | 156 | } |
157 | 157 | |
158 | 158 | $append = ''; |
159 | 159 | |
160 | - if ( 'billing' === $field_type && wpinv_should_validate_vat_number() && 'vat-number' === $key ) { |
|
161 | - $valid = esc_attr__( 'Valid', 'invoicing' ); |
|
162 | - $invalid = esc_attr__( 'Invalid', 'invoicing' ); |
|
163 | - $validate = esc_attr__( 'Validate', 'invoicing' ); |
|
160 | + if ('billing' === $field_type && wpinv_should_validate_vat_number() && 'vat-number' === $key) { |
|
161 | + $valid = esc_attr__('Valid', 'invoicing'); |
|
162 | + $invalid = esc_attr__('Invalid', 'invoicing'); |
|
163 | + $validate = esc_attr__('Validate', 'invoicing'); |
|
164 | 164 | $append = "<span class='btn btn-primary getpaid-vat-number-validate' data-valid='$valid' data-invalid='$invalid' data-validate='$validate'>$validate</span>"; |
165 | 165 | } |
166 | 166 | |
167 | - if ( 'billing' === $field_type ) { |
|
168 | - $description .= '<div class="getpaid-error-' . sanitize_html_class( $field_name ) . ' getpaid-custom-payment-form-errors alert alert-danger d-none"></div>'; |
|
167 | + if ('billing' === $field_type) { |
|
168 | + $description .= '<div class="getpaid-error-' . sanitize_html_class($field_name) . ' getpaid-custom-payment-form-errors alert alert-danger d-none"></div>'; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | echo aui()->input( |
172 | 172 | array( |
173 | - 'name' => esc_attr( $field_name ), |
|
174 | - 'id' => sanitize_html_class( $field_name ) . $uniqid, |
|
175 | - 'required' => ! empty( $address_field['required'] ), |
|
173 | + 'name' => esc_attr($field_name), |
|
174 | + 'id' => sanitize_html_class($field_name) . $uniqid, |
|
175 | + 'required' => !empty($address_field['required']), |
|
176 | 176 | 'placeholder' => $placeholder, |
177 | - 'label' => wp_kses_post( $label ), |
|
177 | + 'label' => wp_kses_post($label), |
|
178 | 178 | 'label_type' => 'vertical', |
179 | 179 | 'help_text' => $description, |
180 | 180 | 'type' => 'text', |
181 | - 'value' => esc_attr( $value ), |
|
182 | - 'class' => 'getpaid-address-field ' . esc_attr( $address_field['name'] ), |
|
181 | + 'value' => esc_attr($value), |
|
182 | + 'class' => 'getpaid-address-field ' . esc_attr($address_field['name']), |
|
183 | 183 | 'wrap_class' => "$wrap_class getpaid-address-field-wrapper__$key", |
184 | 184 | 'label_class' => 'getpaid-address-field-label getpaid-address-field-label__' . $key, |
185 | 185 | 'extra_attributes' => $autocomplete, |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | } |
191 | 191 | |
192 | - do_action( 'getpaid_payment_form_address_field_after_' . $address_field['name'], $field_type, $address_field ); |
|
192 | + do_action('getpaid_payment_form_address_field_after_' . $address_field['name'], $field_type, $address_field); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | echo "</div>"; |
@@ -12,294 +12,294 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
14 | 14 | |
15 | - /** |
|
16 | - * Contains the response for refreshing prices. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $response = array(); |
|
15 | + /** |
|
16 | + * Contains the response for refreshing prices. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $response = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $this->response = array( |
|
29 | - 'submission_id' => $submission->id, |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $this->response = array( |
|
29 | + 'submission_id' => $submission->id, |
|
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | - 'has_subscription_group' => $submission->has_subscription_group(), |
|
32 | - 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
31 | + 'has_subscription_group' => $submission->has_subscription_group(), |
|
32 | + 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
33 | 33 | 'is_free' => ! $submission->should_collect_payment_details(), |
34 | - ); |
|
35 | - |
|
36 | - $this->add_totals( $submission ); |
|
37 | - $this->add_texts( $submission ); |
|
38 | - $this->add_items( $submission ); |
|
39 | - $this->add_fees( $submission ); |
|
40 | - $this->add_discounts( $submission ); |
|
41 | - $this->add_taxes( $submission ); |
|
42 | - $this->add_gateways( $submission ); |
|
43 | - $this->add_data( $submission ); |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Adds totals to a response for submission refresh prices. |
|
49 | - * |
|
50 | - * @param GetPaid_Payment_Form_Submission $submission |
|
51 | - */ |
|
52 | - public function add_totals( $submission ) { |
|
53 | - |
|
54 | - $this->response = array_merge( |
|
55 | - $this->response, |
|
56 | - array( |
|
57 | - |
|
58 | - 'totals' => array( |
|
59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
65 | - ), |
|
66 | - |
|
67 | - 'recurring' => array( |
|
68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
73 | - ), |
|
74 | - |
|
75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
76 | - 'currency' => $submission->get_currency(), |
|
77 | - |
|
78 | - ) |
|
79 | - ); |
|
80 | - |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Adds texts to a response for submission refresh prices. |
|
85 | - * |
|
86 | - * @param GetPaid_Payment_Form_Submission $submission |
|
87 | - */ |
|
88 | - public function add_texts( $submission ) { |
|
89 | - |
|
90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
92 | - |
|
93 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
94 | - |
|
95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
97 | - $main_item = reset( $groups ); |
|
98 | - |
|
99 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
100 | - $payable = "$payable / $period"; |
|
101 | - } else if ( $main_item ) { |
|
102 | - |
|
103 | - $main_item = reset( $main_item ); |
|
104 | - |
|
105 | - // Calculate the next renewal date. |
|
106 | - $_period = $main_item->get_recurring_period( true ); |
|
107 | - $_interval = $main_item->get_recurring_interval(); |
|
108 | - |
|
109 | - // If the subscription item has a trial period... |
|
110 | - if ( $main_item->has_free_trial() ) { |
|
111 | - $_period = $main_item->get_trial_period( true ); |
|
112 | - $_interval = $main_item->get_trial_interval(); |
|
113 | - } |
|
114 | - |
|
115 | - $payable = sprintf( |
|
116 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
117 | - $submission->format_amount( $submission->get_total() ), |
|
118 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
119 | - $period |
|
120 | - ); |
|
121 | - |
|
122 | - $payable .= sprintf( |
|
123 | - '<small class="text-muted form-text">%s</small>', |
|
124 | - sprintf( |
|
125 | - __( 'First renewal on %s', 'invoicing' ), |
|
126 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
127 | - ) |
|
128 | - ); |
|
129 | - |
|
130 | - } else { |
|
131 | - $payable = sprintf( |
|
132 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
133 | - $submission->format_amount( $submission->get_total() ), |
|
134 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
135 | - $period |
|
136 | - ); |
|
137 | - } |
|
138 | - |
|
139 | - } |
|
140 | - |
|
141 | - $texts = array( |
|
142 | - '.getpaid-checkout-total-payable' => $payable, |
|
143 | - ); |
|
144 | - |
|
145 | - foreach ( $submission->get_items() as $item ) { |
|
146 | - $item_id = $item->get_id(); |
|
147 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
148 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
149 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
150 | - $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
151 | - |
|
152 | - if ( $item->get_quantity() == 1 ) { |
|
153 | - $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = ''; |
|
154 | - } |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
159 | - |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Adds items to a response for submission refresh prices. |
|
164 | - * |
|
165 | - * @param GetPaid_Payment_Form_Submission $submission |
|
166 | - */ |
|
167 | - public function add_items( $submission ) { |
|
168 | - |
|
169 | - // Add items. |
|
170 | - $items = array(); |
|
34 | + ); |
|
35 | + |
|
36 | + $this->add_totals( $submission ); |
|
37 | + $this->add_texts( $submission ); |
|
38 | + $this->add_items( $submission ); |
|
39 | + $this->add_fees( $submission ); |
|
40 | + $this->add_discounts( $submission ); |
|
41 | + $this->add_taxes( $submission ); |
|
42 | + $this->add_gateways( $submission ); |
|
43 | + $this->add_data( $submission ); |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Adds totals to a response for submission refresh prices. |
|
49 | + * |
|
50 | + * @param GetPaid_Payment_Form_Submission $submission |
|
51 | + */ |
|
52 | + public function add_totals( $submission ) { |
|
53 | + |
|
54 | + $this->response = array_merge( |
|
55 | + $this->response, |
|
56 | + array( |
|
57 | + |
|
58 | + 'totals' => array( |
|
59 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
60 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
61 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
62 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
63 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
64 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
65 | + ), |
|
66 | + |
|
67 | + 'recurring' => array( |
|
68 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
69 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
70 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
71 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
72 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
73 | + ), |
|
74 | + |
|
75 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
76 | + 'currency' => $submission->get_currency(), |
|
77 | + |
|
78 | + ) |
|
79 | + ); |
|
80 | + |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Adds texts to a response for submission refresh prices. |
|
85 | + * |
|
86 | + * @param GetPaid_Payment_Form_Submission $submission |
|
87 | + */ |
|
88 | + public function add_texts( $submission ) { |
|
89 | + |
|
90 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
91 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
92 | + |
|
93 | + if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
94 | + |
|
95 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
96 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
97 | + $main_item = reset( $groups ); |
|
98 | + |
|
99 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
100 | + $payable = "$payable / $period"; |
|
101 | + } else if ( $main_item ) { |
|
102 | + |
|
103 | + $main_item = reset( $main_item ); |
|
104 | + |
|
105 | + // Calculate the next renewal date. |
|
106 | + $_period = $main_item->get_recurring_period( true ); |
|
107 | + $_interval = $main_item->get_recurring_interval(); |
|
108 | + |
|
109 | + // If the subscription item has a trial period... |
|
110 | + if ( $main_item->has_free_trial() ) { |
|
111 | + $_period = $main_item->get_trial_period( true ); |
|
112 | + $_interval = $main_item->get_trial_interval(); |
|
113 | + } |
|
114 | + |
|
115 | + $payable = sprintf( |
|
116 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
117 | + $submission->format_amount( $submission->get_total() ), |
|
118 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
119 | + $period |
|
120 | + ); |
|
121 | + |
|
122 | + $payable .= sprintf( |
|
123 | + '<small class="text-muted form-text">%s</small>', |
|
124 | + sprintf( |
|
125 | + __( 'First renewal on %s', 'invoicing' ), |
|
126 | + getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
127 | + ) |
|
128 | + ); |
|
129 | + |
|
130 | + } else { |
|
131 | + $payable = sprintf( |
|
132 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
133 | + $submission->format_amount( $submission->get_total() ), |
|
134 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
135 | + $period |
|
136 | + ); |
|
137 | + } |
|
138 | + |
|
139 | + } |
|
140 | + |
|
141 | + $texts = array( |
|
142 | + '.getpaid-checkout-total-payable' => $payable, |
|
143 | + ); |
|
144 | + |
|
145 | + foreach ( $submission->get_items() as $item ) { |
|
146 | + $item_id = $item->get_id(); |
|
147 | + $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
148 | + $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
149 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
150 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
151 | + |
|
152 | + if ( $item->get_quantity() == 1 ) { |
|
153 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = ''; |
|
154 | + } |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
159 | + |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Adds items to a response for submission refresh prices. |
|
164 | + * |
|
165 | + * @param GetPaid_Payment_Form_Submission $submission |
|
166 | + */ |
|
167 | + public function add_items( $submission ) { |
|
168 | + |
|
169 | + // Add items. |
|
170 | + $items = array(); |
|
171 | 171 | |
172 | 172 | foreach ( $submission->get_items() as $item ) { |
173 | - $item_id = $item->get_id(); |
|
174 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
175 | - } |
|
173 | + $item_id = $item->get_id(); |
|
174 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
175 | + } |
|
176 | 176 | |
177 | - $this->response = array_merge( |
|
178 | - $this->response, |
|
179 | - array( 'items' => $items ) |
|
180 | - ); |
|
177 | + $this->response = array_merge( |
|
178 | + $this->response, |
|
179 | + array( 'items' => $items ) |
|
180 | + ); |
|
181 | 181 | |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Adds fees to a response for submission refresh prices. |
|
186 | - * |
|
187 | - * @param GetPaid_Payment_Form_Submission $submission |
|
188 | - */ |
|
189 | - public function add_fees( $submission ) { |
|
184 | + /** |
|
185 | + * Adds fees to a response for submission refresh prices. |
|
186 | + * |
|
187 | + * @param GetPaid_Payment_Form_Submission $submission |
|
188 | + */ |
|
189 | + public function add_fees( $submission ) { |
|
190 | 190 | |
191 | - $fees = array(); |
|
191 | + $fees = array(); |
|
192 | 192 | |
193 | 193 | foreach ( $submission->get_fees() as $name => $data ) { |
194 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
195 | - } |
|
194 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
195 | + } |
|
196 | 196 | |
197 | - $this->response = array_merge( |
|
198 | - $this->response, |
|
199 | - array( 'fees' => $fees ) |
|
200 | - ); |
|
197 | + $this->response = array_merge( |
|
198 | + $this->response, |
|
199 | + array( 'fees' => $fees ) |
|
200 | + ); |
|
201 | 201 | |
202 | - } |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Adds discounts to a response for submission refresh prices. |
|
206 | - * |
|
207 | - * @param GetPaid_Payment_Form_Submission $submission |
|
208 | - */ |
|
209 | - public function add_discounts( $submission ) { |
|
204 | + /** |
|
205 | + * Adds discounts to a response for submission refresh prices. |
|
206 | + * |
|
207 | + * @param GetPaid_Payment_Form_Submission $submission |
|
208 | + */ |
|
209 | + public function add_discounts( $submission ) { |
|
210 | 210 | |
211 | - $discounts = array(); |
|
211 | + $discounts = array(); |
|
212 | 212 | |
213 | 213 | foreach ( $submission->get_discounts() as $name => $data ) { |
214 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
215 | - } |
|
214 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
215 | + } |
|
216 | 216 | |
217 | - $this->response = array_merge( |
|
218 | - $this->response, |
|
219 | - array( 'discounts' => $discounts ) |
|
220 | - ); |
|
217 | + $this->response = array_merge( |
|
218 | + $this->response, |
|
219 | + array( 'discounts' => $discounts ) |
|
220 | + ); |
|
221 | 221 | |
222 | - } |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * Adds taxes to a response for submission refresh prices. |
|
226 | - * |
|
227 | - * @param GetPaid_Payment_Form_Submission $submission |
|
228 | - */ |
|
229 | - public function add_taxes( $submission ) { |
|
230 | - |
|
231 | - $taxes = array(); |
|
232 | - $markup = ''; |
|
224 | + /** |
|
225 | + * Adds taxes to a response for submission refresh prices. |
|
226 | + * |
|
227 | + * @param GetPaid_Payment_Form_Submission $submission |
|
228 | + */ |
|
229 | + public function add_taxes( $submission ) { |
|
230 | + |
|
231 | + $taxes = array(); |
|
232 | + $markup = ''; |
|
233 | 233 | foreach ( $submission->get_taxes() as $name => $data ) { |
234 | - $name = sanitize_text_field( $name ); |
|
235 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
236 | - $taxes[$name] = $amount; |
|
237 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
238 | - } |
|
239 | - |
|
240 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
241 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
242 | - } |
|
243 | - |
|
244 | - $this->response = array_merge( |
|
245 | - $this->response, |
|
246 | - array( 'taxes' => $taxes ) |
|
247 | - ); |
|
248 | - |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Adds gateways to a response for submission refresh prices. |
|
253 | - * |
|
254 | - * @param GetPaid_Payment_Form_Submission $submission |
|
255 | - */ |
|
256 | - public function add_gateways( $submission ) { |
|
257 | - |
|
258 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
259 | - |
|
260 | - if ( $this->response['has_recurring'] ) { |
|
261 | - |
|
262 | - foreach ( $gateways as $i => $gateway ) { |
|
263 | - |
|
264 | - if ( |
|
265 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
266 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
267 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
268 | - unset( $gateways[ $i ] ); |
|
269 | - } |
|
270 | - |
|
271 | - } |
|
272 | - |
|
273 | - } |
|
274 | - |
|
275 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
276 | - $this->response = array_merge( |
|
277 | - $this->response, |
|
278 | - array( 'gateways' => $gateways ) |
|
279 | - ); |
|
280 | - |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Adds data to a response for submission refresh prices. |
|
285 | - * |
|
286 | - * @param GetPaid_Payment_Form_Submission $submission |
|
287 | - */ |
|
288 | - public function add_data( $submission ) { |
|
289 | - |
|
290 | - $this->response = array_merge( |
|
291 | - $this->response, |
|
292 | - array( |
|
293 | - 'js_data' => apply_filters( |
|
294 | - 'getpaid_submission_js_data', |
|
295 | - array( |
|
296 | - 'is_recurring' => $this->response['has_recurring'], |
|
297 | - ), |
|
298 | - $submission |
|
299 | - ) |
|
300 | - ) |
|
301 | - ); |
|
302 | - |
|
303 | - } |
|
234 | + $name = sanitize_text_field( $name ); |
|
235 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
236 | + $taxes[$name] = $amount; |
|
237 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
238 | + } |
|
239 | + |
|
240 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
241 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
242 | + } |
|
243 | + |
|
244 | + $this->response = array_merge( |
|
245 | + $this->response, |
|
246 | + array( 'taxes' => $taxes ) |
|
247 | + ); |
|
248 | + |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Adds gateways to a response for submission refresh prices. |
|
253 | + * |
|
254 | + * @param GetPaid_Payment_Form_Submission $submission |
|
255 | + */ |
|
256 | + public function add_gateways( $submission ) { |
|
257 | + |
|
258 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
259 | + |
|
260 | + if ( $this->response['has_recurring'] ) { |
|
261 | + |
|
262 | + foreach ( $gateways as $i => $gateway ) { |
|
263 | + |
|
264 | + if ( |
|
265 | + ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
266 | + || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
267 | + || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
268 | + unset( $gateways[ $i ] ); |
|
269 | + } |
|
270 | + |
|
271 | + } |
|
272 | + |
|
273 | + } |
|
274 | + |
|
275 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
276 | + $this->response = array_merge( |
|
277 | + $this->response, |
|
278 | + array( 'gateways' => $gateways ) |
|
279 | + ); |
|
280 | + |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Adds data to a response for submission refresh prices. |
|
285 | + * |
|
286 | + * @param GetPaid_Payment_Form_Submission $submission |
|
287 | + */ |
|
288 | + public function add_data( $submission ) { |
|
289 | + |
|
290 | + $this->response = array_merge( |
|
291 | + $this->response, |
|
292 | + array( |
|
293 | + 'js_data' => apply_filters( |
|
294 | + 'getpaid_submission_js_data', |
|
295 | + array( |
|
296 | + 'is_recurring' => $this->response['has_recurring'], |
|
297 | + ), |
|
298 | + $submission |
|
299 | + ) |
|
300 | + ) |
|
301 | + ); |
|
302 | + |
|
303 | + } |
|
304 | 304 | |
305 | 305 | } |
@@ -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 | * Payment form submission refresh prices class |
@@ -23,24 +23,24 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $this->response = array( |
29 | 29 | 'submission_id' => $submission->id, |
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | 31 | 'has_subscription_group' => $submission->has_subscription_group(), |
32 | 32 | 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
33 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
33 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
34 | 34 | ); |
35 | 35 | |
36 | - $this->add_totals( $submission ); |
|
37 | - $this->add_texts( $submission ); |
|
38 | - $this->add_items( $submission ); |
|
39 | - $this->add_fees( $submission ); |
|
40 | - $this->add_discounts( $submission ); |
|
41 | - $this->add_taxes( $submission ); |
|
42 | - $this->add_gateways( $submission ); |
|
43 | - $this->add_data( $submission ); |
|
36 | + $this->add_totals($submission); |
|
37 | + $this->add_texts($submission); |
|
38 | + $this->add_items($submission); |
|
39 | + $this->add_fees($submission); |
|
40 | + $this->add_discounts($submission); |
|
41 | + $this->add_taxes($submission); |
|
42 | + $this->add_gateways($submission); |
|
43 | + $this->add_data($submission); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
@@ -49,30 +49,30 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @param GetPaid_Payment_Form_Submission $submission |
51 | 51 | */ |
52 | - public function add_totals( $submission ) { |
|
52 | + public function add_totals($submission) { |
|
53 | 53 | |
54 | 54 | $this->response = array_merge( |
55 | 55 | $this->response, |
56 | 56 | array( |
57 | 57 | |
58 | 58 | 'totals' => array( |
59 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
60 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
61 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
62 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
63 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
64 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
59 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
60 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
61 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
62 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
63 | + 'total' => $submission->format_amount($submission->get_total()), |
|
64 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
65 | 65 | ), |
66 | 66 | |
67 | 67 | 'recurring' => array( |
68 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
69 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
70 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
71 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
72 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
68 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
69 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
70 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
71 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
72 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
73 | 73 | ), |
74 | 74 | |
75 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
75 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
76 | 76 | 'currency' => $submission->get_currency(), |
77 | 77 | |
78 | 78 | ) |
@@ -85,53 +85,53 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @param GetPaid_Payment_Form_Submission $submission |
87 | 87 | */ |
88 | - public function add_texts( $submission ) { |
|
88 | + public function add_texts($submission) { |
|
89 | 89 | |
90 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
91 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
90 | + $payable = $submission->format_amount($submission->get_total()); |
|
91 | + $groups = getpaid_get_subscription_groups($submission); |
|
92 | 92 | |
93 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
93 | + if ($submission->has_recurring && 2 > count($groups)) { |
|
94 | 94 | |
95 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
96 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
97 | - $main_item = reset( $groups ); |
|
95 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
96 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
97 | + $main_item = reset($groups); |
|
98 | 98 | |
99 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
99 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
100 | 100 | $payable = "$payable / $period"; |
101 | - } else if ( $main_item ) { |
|
101 | + } else if ($main_item) { |
|
102 | 102 | |
103 | - $main_item = reset( $main_item ); |
|
103 | + $main_item = reset($main_item); |
|
104 | 104 | |
105 | 105 | // Calculate the next renewal date. |
106 | - $_period = $main_item->get_recurring_period( true ); |
|
106 | + $_period = $main_item->get_recurring_period(true); |
|
107 | 107 | $_interval = $main_item->get_recurring_interval(); |
108 | 108 | |
109 | 109 | // If the subscription item has a trial period... |
110 | - if ( $main_item->has_free_trial() ) { |
|
111 | - $_period = $main_item->get_trial_period( true ); |
|
110 | + if ($main_item->has_free_trial()) { |
|
111 | + $_period = $main_item->get_trial_period(true); |
|
112 | 112 | $_interval = $main_item->get_trial_interval(); |
113 | 113 | } |
114 | 114 | |
115 | 115 | $payable = sprintf( |
116 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
117 | - $submission->format_amount( $submission->get_total() ), |
|
118 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
116 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
117 | + $submission->format_amount($submission->get_total()), |
|
118 | + $submission->format_amount($submission->get_recurring_total()), |
|
119 | 119 | $period |
120 | 120 | ); |
121 | 121 | |
122 | 122 | $payable .= sprintf( |
123 | 123 | '<small class="text-muted form-text">%s</small>', |
124 | 124 | sprintf( |
125 | - __( 'First renewal on %s', 'invoicing' ), |
|
126 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
125 | + __('First renewal on %s', 'invoicing'), |
|
126 | + getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp')))) |
|
127 | 127 | ) |
128 | 128 | ); |
129 | 129 | |
130 | 130 | } else { |
131 | 131 | $payable = sprintf( |
132 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
133 | - $submission->format_amount( $submission->get_total() ), |
|
134 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
132 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
133 | + $submission->format_amount($submission->get_total()), |
|
134 | + $submission->format_amount($submission->get_recurring_total()), |
|
135 | 135 | $period |
136 | 136 | ); |
137 | 137 | } |
@@ -142,20 +142,20 @@ discard block |
||
142 | 142 | '.getpaid-checkout-total-payable' => $payable, |
143 | 143 | ); |
144 | 144 | |
145 | - foreach ( $submission->get_items() as $item ) { |
|
145 | + foreach ($submission->get_items() as $item) { |
|
146 | 146 | $item_id = $item->get_id(); |
147 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
148 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
149 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
150 | - $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
147 | + $initial_price = $submission->format_amount($item->get_sub_total() - $item->item_discount); |
|
148 | + $recurring_price = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount); |
|
149 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
150 | + $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf(__('Subtotal: %s', 'invoicing'), $submission->format_amount($item->get_sub_total())); |
|
151 | 151 | |
152 | - if ( $item->get_quantity() == 1 ) { |
|
152 | + if ($item->get_quantity() == 1) { |
|
153 | 153 | $texts[".item-$item_id .getpaid-mobile-item-subtotal"] = ''; |
154 | 154 | } |
155 | 155 | |
156 | 156 | } |
157 | 157 | |
158 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
158 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
159 | 159 | |
160 | 160 | } |
161 | 161 | |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @param GetPaid_Payment_Form_Submission $submission |
166 | 166 | */ |
167 | - public function add_items( $submission ) { |
|
167 | + public function add_items($submission) { |
|
168 | 168 | |
169 | 169 | // Add items. |
170 | 170 | $items = array(); |
171 | 171 | |
172 | - foreach ( $submission->get_items() as $item ) { |
|
172 | + foreach ($submission->get_items() as $item) { |
|
173 | 173 | $item_id = $item->get_id(); |
174 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
174 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | $this->response = array_merge( |
178 | 178 | $this->response, |
179 | - array( 'items' => $items ) |
|
179 | + array('items' => $items) |
|
180 | 180 | ); |
181 | 181 | |
182 | 182 | } |
@@ -186,17 +186,17 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @param GetPaid_Payment_Form_Submission $submission |
188 | 188 | */ |
189 | - public function add_fees( $submission ) { |
|
189 | + public function add_fees($submission) { |
|
190 | 190 | |
191 | 191 | $fees = array(); |
192 | 192 | |
193 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
194 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
193 | + foreach ($submission->get_fees() as $name => $data) { |
|
194 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | $this->response = array_merge( |
198 | 198 | $this->response, |
199 | - array( 'fees' => $fees ) |
|
199 | + array('fees' => $fees) |
|
200 | 200 | ); |
201 | 201 | |
202 | 202 | } |
@@ -206,17 +206,17 @@ discard block |
||
206 | 206 | * |
207 | 207 | * @param GetPaid_Payment_Form_Submission $submission |
208 | 208 | */ |
209 | - public function add_discounts( $submission ) { |
|
209 | + public function add_discounts($submission) { |
|
210 | 210 | |
211 | 211 | $discounts = array(); |
212 | 212 | |
213 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
214 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
213 | + foreach ($submission->get_discounts() as $name => $data) { |
|
214 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | $this->response = array_merge( |
218 | 218 | $this->response, |
219 | - array( 'discounts' => $discounts ) |
|
219 | + array('discounts' => $discounts) |
|
220 | 220 | ); |
221 | 221 | |
222 | 222 | } |
@@ -226,24 +226,24 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @param GetPaid_Payment_Form_Submission $submission |
228 | 228 | */ |
229 | - public function add_taxes( $submission ) { |
|
229 | + public function add_taxes($submission) { |
|
230 | 230 | |
231 | 231 | $taxes = array(); |
232 | 232 | $markup = ''; |
233 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
234 | - $name = sanitize_text_field( $name ); |
|
235 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
233 | + foreach ($submission->get_taxes() as $name => $data) { |
|
234 | + $name = sanitize_text_field($name); |
|
235 | + $amount = $submission->format_amount($data['initial_tax']); |
|
236 | 236 | $taxes[$name] = $amount; |
237 | 237 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
238 | 238 | } |
239 | 239 | |
240 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
240 | + if (wpinv_display_individual_tax_rates() && !empty($taxes)) { |
|
241 | 241 | $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
242 | 242 | } |
243 | 243 | |
244 | 244 | $this->response = array_merge( |
245 | 245 | $this->response, |
246 | - array( 'taxes' => $taxes ) |
|
246 | + array('taxes' => $taxes) |
|
247 | 247 | ); |
248 | 248 | |
249 | 249 | } |
@@ -253,29 +253,29 @@ discard block |
||
253 | 253 | * |
254 | 254 | * @param GetPaid_Payment_Form_Submission $submission |
255 | 255 | */ |
256 | - public function add_gateways( $submission ) { |
|
256 | + public function add_gateways($submission) { |
|
257 | 257 | |
258 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
258 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
259 | 259 | |
260 | - if ( $this->response['has_recurring'] ) { |
|
260 | + if ($this->response['has_recurring']) { |
|
261 | 261 | |
262 | - foreach ( $gateways as $i => $gateway ) { |
|
262 | + foreach ($gateways as $i => $gateway) { |
|
263 | 263 | |
264 | 264 | if ( |
265 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
266 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
267 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
268 | - unset( $gateways[ $i ] ); |
|
265 | + !getpaid_payment_gateway_supports($gateway, 'subscription') |
|
266 | + || ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group')) |
|
267 | + || ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) { |
|
268 | + unset($gateways[$i]); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | } |
272 | 272 | |
273 | 273 | } |
274 | 274 | |
275 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
275 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
276 | 276 | $this->response = array_merge( |
277 | 277 | $this->response, |
278 | - array( 'gateways' => $gateways ) |
|
278 | + array('gateways' => $gateways) |
|
279 | 279 | ); |
280 | 280 | |
281 | 281 | } |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @param GetPaid_Payment_Form_Submission $submission |
287 | 287 | */ |
288 | - public function add_data( $submission ) { |
|
288 | + public function add_data($submission) { |
|
289 | 289 | |
290 | 290 | $this->response = array_merge( |
291 | 291 | $this->response, |
@@ -13,96 +13,96 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
90 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
92 | 92 | |
93 | - parent::__construct(); |
|
93 | + parent::__construct(); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | - * Process Payment. |
|
98 | - * |
|
99 | - * |
|
100 | - * @param WPInv_Invoice $invoice Invoice. |
|
101 | - * @param array $submission_data Posted checkout fields. |
|
102 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
97 | + * Process Payment. |
|
98 | + * |
|
99 | + * |
|
100 | + * @param WPInv_Invoice $invoice Invoice. |
|
101 | + * @param array $submission_data Posted checkout fields. |
|
102 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
106 | 106 | |
107 | 107 | // Get redirect url. |
108 | 108 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get the PayPal request URL for an invoice. |
|
129 | - * |
|
130 | - * @param WPInv_Invoice $invoice Invoice object. |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function get_request_url( $invoice ) { |
|
128 | + * Get the PayPal request URL for an invoice. |
|
129 | + * |
|
130 | + * @param WPInv_Invoice $invoice Invoice object. |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function get_request_url( $invoice ) { |
|
134 | 134 | |
135 | 135 | // Endpoint for this request |
136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
136 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
137 | 137 | |
138 | 138 | // Retrieve paypal args. |
139 | 139 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -146,45 +146,45 @@ discard block |
||
146 | 146 | |
147 | 147 | return add_query_arg( $paypal_args, $this->endpoint ); |
148 | 148 | |
149 | - } |
|
149 | + } |
|
150 | 150 | |
151 | 151 | /** |
152 | - * Get PayPal Args for passing to PP. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - protected function get_paypal_args( $invoice ) { |
|
152 | + * Get PayPal Args for passing to PP. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + protected function get_paypal_args( $invoice ) { |
|
158 | 158 | |
159 | 159 | // Whether or not to send the line items as one item. |
160 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | - |
|
162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | - $force_one_line_item = true; |
|
164 | - } |
|
165 | - |
|
166 | - $paypal_args = apply_filters( |
|
167 | - 'getpaid_paypal_args', |
|
168 | - array_merge( |
|
169 | - $this->get_transaction_args( $invoice ), |
|
170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | - ), |
|
172 | - $invoice |
|
173 | - ); |
|
174 | - |
|
175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
160 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | + |
|
162 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | + $force_one_line_item = true; |
|
164 | + } |
|
165 | + |
|
166 | + $paypal_args = apply_filters( |
|
167 | + 'getpaid_paypal_args', |
|
168 | + array_merge( |
|
169 | + $this->get_transaction_args( $invoice ), |
|
170 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | + ), |
|
172 | + $invoice |
|
173 | + ); |
|
174 | + |
|
175 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * Get transaction args for paypal request. |
|
180 | - * |
|
181 | - * @param WPInv_Invoice $invoice Invoice object. |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - protected function get_transaction_args( $invoice ) { |
|
185 | - |
|
186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | - return array( |
|
179 | + * Get transaction args for paypal request. |
|
180 | + * |
|
181 | + * @param WPInv_Invoice $invoice Invoice object. |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + protected function get_transaction_args( $invoice ) { |
|
185 | + |
|
186 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | + return array( |
|
188 | 188 | 'cmd' => '_cart', |
189 | 189 | 'business' => $email, |
190 | 190 | 'no_shipping' => '1', |
@@ -209,16 +209,16 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get line item args for paypal request. |
|
213 | - * |
|
214 | - * @param WPInv_Invoice $invoice Invoice object. |
|
215 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | - * @return array |
|
217 | - */ |
|
218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
212 | + * Get line item args for paypal request. |
|
213 | + * |
|
214 | + * @param WPInv_Invoice $invoice Invoice object. |
|
215 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | + * @return array |
|
217 | + */ |
|
218 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
219 | 219 | |
220 | 220 | // Maybe send invoice as a single item. |
221 | - if ( $force_one_line_item ) { |
|
221 | + if ( $force_one_line_item ) { |
|
222 | 222 | return $this->get_line_item_args_single_item( $invoice ); |
223 | 223 | } |
224 | 224 | |
@@ -238,129 +238,129 @@ discard block |
||
238 | 238 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
239 | 239 | } |
240 | 240 | |
241 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
241 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
242 | 242 | |
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | - * Get line item args for paypal request as a single line item. |
|
247 | - * |
|
248 | - * @param WPInv_Invoice $invoice Invoice object. |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
252 | - $this->delete_line_items(); |
|
246 | + * Get line item args for paypal request as a single line item. |
|
247 | + * |
|
248 | + * @param WPInv_Invoice $invoice Invoice object. |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + protected function get_line_item_args_single_item( $invoice ) { |
|
252 | + $this->delete_line_items(); |
|
253 | 253 | |
254 | 254 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
255 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
255 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
256 | 256 | |
257 | - return $this->get_line_items(); |
|
257 | + return $this->get_line_items(); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | - * Return all line items. |
|
262 | - */ |
|
263 | - protected function get_line_items() { |
|
264 | - return $this->line_items; |
|
265 | - } |
|
261 | + * Return all line items. |
|
262 | + */ |
|
263 | + protected function get_line_items() { |
|
264 | + return $this->line_items; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | /** |
268 | - * Remove all line items. |
|
269 | - */ |
|
270 | - protected function delete_line_items() { |
|
271 | - $this->line_items = array(); |
|
268 | + * Remove all line items. |
|
269 | + */ |
|
270 | + protected function delete_line_items() { |
|
271 | + $this->line_items = array(); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Prepare line items to send to paypal. |
|
276 | - * |
|
277 | - * @param WPInv_Invoice $invoice Invoice object. |
|
278 | - */ |
|
279 | - protected function prepare_line_items( $invoice ) { |
|
280 | - $this->delete_line_items(); |
|
281 | - |
|
282 | - // Items. |
|
283 | - foreach ( $invoice->get_items() as $item ) { |
|
284 | - $amount = $item->get_price(); |
|
285 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
275 | + * Prepare line items to send to paypal. |
|
276 | + * |
|
277 | + * @param WPInv_Invoice $invoice Invoice object. |
|
278 | + */ |
|
279 | + protected function prepare_line_items( $invoice ) { |
|
280 | + $this->delete_line_items(); |
|
281 | + |
|
282 | + // Items. |
|
283 | + foreach ( $invoice->get_items() as $item ) { |
|
284 | + $amount = $item->get_price(); |
|
285 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // Fees. |
290 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
290 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
291 | 291 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
292 | 292 | } |
293 | 293 | |
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Add PayPal Line Item. |
|
298 | - * |
|
299 | - * @param string $item_name Item name. |
|
300 | - * @param float $quantity Item quantity. |
|
301 | - * @param float $amount Amount. |
|
302 | - * @param string $item_number Item number. |
|
303 | - */ |
|
304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | - |
|
307 | - $item = apply_filters( |
|
308 | - 'getpaid_paypal_line_item', |
|
309 | - array( |
|
310 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | - 'quantity' => (float) $quantity, |
|
312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | - 'item_number' => $item_number, |
|
314 | - ), |
|
315 | - $item_name, |
|
316 | - $quantity, |
|
317 | - $amount, |
|
318 | - $item_number |
|
319 | - ); |
|
320 | - |
|
321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
297 | + * Add PayPal Line Item. |
|
298 | + * |
|
299 | + * @param string $item_name Item name. |
|
300 | + * @param float $quantity Item quantity. |
|
301 | + * @param float $amount Amount. |
|
302 | + * @param string $item_number Item number. |
|
303 | + */ |
|
304 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | + |
|
307 | + $item = apply_filters( |
|
308 | + 'getpaid_paypal_line_item', |
|
309 | + array( |
|
310 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | + 'quantity' => (float) $quantity, |
|
312 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | + 'item_number' => $item_number, |
|
314 | + ), |
|
315 | + $item_name, |
|
316 | + $quantity, |
|
317 | + $amount, |
|
318 | + $item_number |
|
319 | + ); |
|
320 | + |
|
321 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
322 | 322 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
323 | 323 | |
324 | 324 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
325 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
325 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | - * |
|
332 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | - * |
|
334 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | - * @return array |
|
337 | - */ |
|
338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | - $max_paypal_length = 2083; |
|
340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | - |
|
342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | - return $paypal_args; |
|
344 | - } |
|
345 | - |
|
346 | - return apply_filters( |
|
347 | - 'getpaid_paypal_args', |
|
348 | - array_merge( |
|
349 | - $this->get_transaction_args( $invoice ), |
|
350 | - $this->get_line_item_args( $invoice, true ) |
|
351 | - ), |
|
352 | - $invoice |
|
353 | - ); |
|
330 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | + * |
|
332 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | + * |
|
334 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | + * @return array |
|
337 | + */ |
|
338 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | + $max_paypal_length = 2083; |
|
340 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | + |
|
342 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | + return $paypal_args; |
|
344 | + } |
|
345 | + |
|
346 | + return apply_filters( |
|
347 | + 'getpaid_paypal_args', |
|
348 | + array_merge( |
|
349 | + $this->get_transaction_args( $invoice ), |
|
350 | + $this->get_line_item_args( $invoice, true ) |
|
351 | + ), |
|
352 | + $invoice |
|
353 | + ); |
|
354 | 354 | |
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Processes recurring invoices. |
|
359 | - * |
|
360 | - * @param array $paypal_args PayPal args. |
|
361 | - * @param WPInv_Invoice $invoice Invoice object. |
|
362 | - */ |
|
363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
358 | + * Processes recurring invoices. |
|
359 | + * |
|
360 | + * @param array $paypal_args PayPal args. |
|
361 | + * @param WPInv_Invoice $invoice Invoice object. |
|
362 | + */ |
|
363 | + public function process_subscription( $paypal_args, $invoice ) { |
|
364 | 364 | |
365 | 365 | // Make sure this is a subscription. |
366 | 366 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -381,21 +381,21 @@ discard block |
||
381 | 381 | $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
382 | 382 | $subscription_item = $invoice->get_recurring( true ); |
383 | 383 | |
384 | - // Convert 365 days to 1 year. |
|
385 | - if ( 'D' == $period && 365 == $interval ) { |
|
386 | - $period = 'Y'; |
|
387 | - $interval = 1; |
|
388 | - } |
|
384 | + // Convert 365 days to 1 year. |
|
385 | + if ( 'D' == $period && 365 == $interval ) { |
|
386 | + $period = 'Y'; |
|
387 | + $interval = 1; |
|
388 | + } |
|
389 | 389 | |
390 | 390 | if ( $subscription_item->has_free_trial() ) { |
391 | 391 | |
392 | 392 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
393 | 393 | |
394 | - // Trial period length. |
|
395 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
394 | + // Trial period length. |
|
395 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
396 | 396 | |
397 | - // Trial period. |
|
398 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
397 | + // Trial period. |
|
398 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
399 | 399 | |
400 | 400 | } else if ( $initial_amount != $recurring_amount ) { |
401 | 401 | |
@@ -418,40 +418,40 @@ discard block |
||
418 | 418 | } |
419 | 419 | |
420 | 420 | // We have a recurring payment |
421 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
421 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
422 | 422 | |
423 | - // Subscription price |
|
424 | - $paypal_args['a3'] = $recurring_amount; |
|
423 | + // Subscription price |
|
424 | + $paypal_args['a3'] = $recurring_amount; |
|
425 | 425 | |
426 | - // Subscription duration |
|
427 | - $paypal_args['p3'] = $interval; |
|
426 | + // Subscription duration |
|
427 | + $paypal_args['p3'] = $interval; |
|
428 | 428 | |
429 | - // Subscription period |
|
430 | - $paypal_args['t3'] = $period; |
|
429 | + // Subscription period |
|
430 | + $paypal_args['t3'] = $period; |
|
431 | 431 | |
432 | 432 | } |
433 | 433 | |
434 | 434 | // Recurring payments |
435 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
435 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
436 | 436 | |
437 | - // Non-recurring payments |
|
438 | - $paypal_args['src'] = 0; |
|
437 | + // Non-recurring payments |
|
438 | + $paypal_args['src'] = 0; |
|
439 | 439 | |
440 | - } else { |
|
440 | + } else { |
|
441 | 441 | |
442 | - $paypal_args['src'] = 1; |
|
442 | + $paypal_args['src'] = 1; |
|
443 | 443 | |
444 | - if ( $bill_times > 0 ) { |
|
444 | + if ( $bill_times > 0 ) { |
|
445 | 445 | |
446 | - // An initial period is being used to charge a sign-up fee |
|
447 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
448 | - $bill_times--; |
|
449 | - } |
|
446 | + // An initial period is being used to charge a sign-up fee |
|
447 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
448 | + $bill_times--; |
|
449 | + } |
|
450 | 450 | |
451 | 451 | // Make sure it's not over the max of 52 |
452 | 452 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
453 | 453 | |
454 | - } |
|
454 | + } |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | // Force return URL so that order description & instructions display |
@@ -467,19 +467,19 @@ discard block |
||
467 | 467 | } |
468 | 468 | |
469 | 469 | return apply_filters( |
470 | - 'getpaid_paypal_subscription_args', |
|
471 | - $paypal_args, |
|
472 | - $invoice |
|
470 | + 'getpaid_paypal_subscription_args', |
|
471 | + $paypal_args, |
|
472 | + $invoice |
|
473 | 473 | ); |
474 | 474 | |
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
478 | - * Processes ipns and marks payments as complete. |
|
479 | - * |
|
480 | - * @return void |
|
481 | - */ |
|
482 | - public function verify_ipn() { |
|
478 | + * Processes ipns and marks payments as complete. |
|
479 | + * |
|
480 | + * @return void |
|
481 | + */ |
|
482 | + public function verify_ipn() { |
|
483 | 483 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
484 | 484 | } |
485 | 485 | |
@@ -489,19 +489,19 @@ discard block |
||
489 | 489 | public function sandbox_notice() { |
490 | 490 | |
491 | 491 | return sprintf( |
492 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
493 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
494 | - '</a>' |
|
495 | - ); |
|
492 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
493 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
494 | + '</a>' |
|
495 | + ); |
|
496 | 496 | |
497 | 497 | } |
498 | 498 | |
499 | - /** |
|
500 | - * Filters the gateway settings. |
|
501 | - * |
|
502 | - * @param array $admin_settings |
|
503 | - */ |
|
504 | - public function admin_settings( $admin_settings ) { |
|
499 | + /** |
|
500 | + * Filters the gateway settings. |
|
501 | + * |
|
502 | + * @param array $admin_settings |
|
503 | + */ |
|
504 | + public function admin_settings( $admin_settings ) { |
|
505 | 505 | |
506 | 506 | $currencies = sprintf( |
507 | 507 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -511,39 +511,39 @@ discard block |
||
511 | 511 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
512 | 512 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
513 | 513 | |
514 | - // Access tokens. |
|
515 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
516 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
517 | - |
|
518 | - $admin_settings['paypal_connect'] = array( |
|
519 | - 'type' => 'raw_html', |
|
520 | - 'id' => 'paypal_connect', |
|
521 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
522 | - 'desc' => sprintf( |
|
523 | - '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
|
524 | - esc_url( self::get_connect_url( false ) ), |
|
525 | - __( 'Connect to PayPal', 'invoicing' ), |
|
526 | - esc_url( self::get_connect_url( true ) ), |
|
527 | - __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
528 | - $this->get_js() |
|
529 | - ), |
|
530 | - ); |
|
514 | + // Access tokens. |
|
515 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
516 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
517 | + |
|
518 | + $admin_settings['paypal_connect'] = array( |
|
519 | + 'type' => 'raw_html', |
|
520 | + 'id' => 'paypal_connect', |
|
521 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
522 | + 'desc' => sprintf( |
|
523 | + '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
|
524 | + esc_url( self::get_connect_url( false ) ), |
|
525 | + __( 'Connect to PayPal', 'invoicing' ), |
|
526 | + esc_url( self::get_connect_url( true ) ), |
|
527 | + __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
528 | + $this->get_js() |
|
529 | + ), |
|
530 | + ); |
|
531 | 531 | |
532 | 532 | $admin_settings['paypal_email'] = array( |
533 | 533 | 'type' => 'text', |
534 | - 'class' => 'live-auth-data', |
|
534 | + 'class' => 'live-auth-data', |
|
535 | 535 | 'id' => 'paypal_email', |
536 | 536 | 'name' => __( 'Live Email Address', 'invoicing' ), |
537 | 537 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
538 | 538 | ); |
539 | 539 | |
540 | - $admin_settings['paypal_sandbox_email'] = array( |
|
540 | + $admin_settings['paypal_sandbox_email'] = array( |
|
541 | 541 | 'type' => 'text', |
542 | - 'class' => 'sandbox-auth-data', |
|
542 | + 'class' => 'sandbox-auth-data', |
|
543 | 543 | 'id' => 'paypal_sandbox_email', |
544 | 544 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
545 | 545 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
546 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
546 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
547 | 547 | ); |
548 | 548 | |
549 | 549 | $admin_settings['paypal_ipn_url'] = array( |
@@ -555,29 +555,29 @@ discard block |
||
555 | 555 | 'readonly' => true, |
556 | 556 | ); |
557 | 557 | |
558 | - return $admin_settings; |
|
559 | - } |
|
558 | + return $admin_settings; |
|
559 | + } |
|
560 | 560 | |
561 | - /** |
|
562 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
563 | - * |
|
564 | - * |
|
561 | + /** |
|
562 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
563 | + * |
|
564 | + * |
|
565 | 565 | * @param array $data |
566 | 566 | * @return string |
567 | - */ |
|
568 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
569 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Retrieves the PayPal connect URL. |
|
574 | - * |
|
575 | - * |
|
567 | + */ |
|
568 | + public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
569 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Retrieves the PayPal connect URL. |
|
574 | + * |
|
575 | + * |
|
576 | 576 | * @param bool $is_sandbox |
577 | - * @param string $redirect |
|
577 | + * @param string $redirect |
|
578 | 578 | * @return string |
579 | - */ |
|
580 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
579 | + */ |
|
580 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
581 | 581 | |
582 | 582 | $redirect_url = add_query_arg( |
583 | 583 | array( |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | 'tab' => 'gateways', |
588 | 588 | 'section' => 'paypal', |
589 | 589 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
590 | - 'redirect' => urlencode( $redirect ), |
|
590 | + 'redirect' => urlencode( $redirect ), |
|
591 | 591 | ), |
592 | 592 | admin_url( 'admin.php' ) |
593 | 593 | ); |
@@ -602,12 +602,12 @@ discard block |
||
602 | 602 | |
603 | 603 | } |
604 | 604 | |
605 | - /** |
|
606 | - * Generates settings page js. |
|
607 | - * |
|
605 | + /** |
|
606 | + * Generates settings page js. |
|
607 | + * |
|
608 | 608 | * @return void |
609 | - */ |
|
610 | - public static function get_js() { |
|
609 | + */ |
|
610 | + public static function get_js() { |
|
611 | 611 | ob_start(); |
612 | 612 | ?> |
613 | 613 | <script> |
@@ -643,72 +643,72 @@ discard block |
||
643 | 643 | return ob_get_clean(); |
644 | 644 | } |
645 | 645 | |
646 | - /** |
|
647 | - * Connects to PayPal. |
|
648 | - * |
|
649 | - * @param array $data Connection data. |
|
650 | - * @return void |
|
651 | - */ |
|
652 | - public function connect_paypal( $data ) { |
|
653 | - |
|
654 | - $sandbox = $this->is_sandbox(); |
|
655 | - $data = wp_unslash( $data ); |
|
656 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
657 | - |
|
658 | - if ( isset( $data['live_mode'] ) ) { |
|
659 | - $sandbox = empty( $data['live_mode'] ); |
|
660 | - } |
|
661 | - |
|
662 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
663 | - wpinv_update_option( 'paypal_active', 1 ); |
|
664 | - |
|
665 | - if ( ! empty( $data['error_description'] ) ) { |
|
666 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
667 | - } else { |
|
668 | - |
|
669 | - // Retrieve the user info. |
|
670 | - $user_info = wp_remote_get( |
|
671 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
672 | - array( |
|
673 | - |
|
674 | - 'headers' => array( |
|
675 | - 'Authorization' => 'Bearer ' . $access_token, |
|
676 | - 'Content-type' => 'application/json', |
|
677 | - ) |
|
678 | - |
|
679 | - ) |
|
680 | - ); |
|
681 | - |
|
682 | - if ( is_wp_error( $user_info ) ) { |
|
683 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
684 | - } else { |
|
685 | - |
|
686 | - // Create application. |
|
687 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
688 | - |
|
689 | - if ( $sandbox ) { |
|
690 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
691 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
692 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
693 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
694 | - } else { |
|
695 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
696 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
697 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
698 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
699 | - } |
|
700 | - |
|
701 | - } |
|
702 | - |
|
703 | - } |
|
704 | - |
|
705 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
706 | - |
|
707 | - if ( isset( $data['step'] ) ) { |
|
708 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
709 | - } |
|
710 | - wp_redirect( $redirect ); |
|
711 | - exit; |
|
712 | - } |
|
646 | + /** |
|
647 | + * Connects to PayPal. |
|
648 | + * |
|
649 | + * @param array $data Connection data. |
|
650 | + * @return void |
|
651 | + */ |
|
652 | + public function connect_paypal( $data ) { |
|
653 | + |
|
654 | + $sandbox = $this->is_sandbox(); |
|
655 | + $data = wp_unslash( $data ); |
|
656 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
657 | + |
|
658 | + if ( isset( $data['live_mode'] ) ) { |
|
659 | + $sandbox = empty( $data['live_mode'] ); |
|
660 | + } |
|
661 | + |
|
662 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
663 | + wpinv_update_option( 'paypal_active', 1 ); |
|
664 | + |
|
665 | + if ( ! empty( $data['error_description'] ) ) { |
|
666 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
667 | + } else { |
|
668 | + |
|
669 | + // Retrieve the user info. |
|
670 | + $user_info = wp_remote_get( |
|
671 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
672 | + array( |
|
673 | + |
|
674 | + 'headers' => array( |
|
675 | + 'Authorization' => 'Bearer ' . $access_token, |
|
676 | + 'Content-type' => 'application/json', |
|
677 | + ) |
|
678 | + |
|
679 | + ) |
|
680 | + ); |
|
681 | + |
|
682 | + if ( is_wp_error( $user_info ) ) { |
|
683 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
684 | + } else { |
|
685 | + |
|
686 | + // Create application. |
|
687 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
688 | + |
|
689 | + if ( $sandbox ) { |
|
690 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
691 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
692 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
693 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
694 | + } else { |
|
695 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
696 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
697 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
698 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
699 | + } |
|
700 | + |
|
701 | + } |
|
702 | + |
|
703 | + } |
|
704 | + |
|
705 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
706 | + |
|
707 | + if ( isset( $data['step'] ) ) { |
|
708 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
709 | + } |
|
710 | + wp_redirect( $redirect ); |
|
711 | + exit; |
|
712 | + } |
|
713 | 713 | |
714 | 714 | } |
@@ -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 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'single_subscription_group'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -80,15 +80,15 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function __construct() { |
82 | 82 | |
83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
89 | + add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice')); |
|
90 | + add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2); |
|
91 | + add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal')); |
|
92 | 92 | |
93 | 93 | parent::__construct(); |
94 | 94 | } |
@@ -102,16 +102,16 @@ discard block |
||
102 | 102 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
103 | 103 | * @return array |
104 | 104 | */ |
105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
105 | + public function process_payment($invoice, $submission_data, $submission) { |
|
106 | 106 | |
107 | 107 | // Get redirect url. |
108 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
108 | + $paypal_redirect = $this->get_request_url($invoice); |
|
109 | 109 | |
110 | 110 | // Add a note about the request url. |
111 | 111 | $invoice->add_note( |
112 | 112 | sprintf( |
113 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
114 | - esc_url( $paypal_redirect ) |
|
113 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
114 | + esc_url($paypal_redirect) |
|
115 | 115 | ), |
116 | 116 | false, |
117 | 117 | false, |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | ); |
120 | 120 | |
121 | 121 | // Redirect to PayPal |
122 | - wp_redirect( $paypal_redirect ); |
|
122 | + wp_redirect($paypal_redirect); |
|
123 | 123 | exit; |
124 | 124 | |
125 | 125 | } |
@@ -130,21 +130,21 @@ discard block |
||
130 | 130 | * @param WPInv_Invoice $invoice Invoice object. |
131 | 131 | * @return string |
132 | 132 | */ |
133 | - public function get_request_url( $invoice ) { |
|
133 | + public function get_request_url($invoice) { |
|
134 | 134 | |
135 | 135 | // Endpoint for this request |
136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
136 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
137 | 137 | |
138 | 138 | // Retrieve paypal args. |
139 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
139 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
140 | 140 | |
141 | - if ( $invoice->is_recurring() ) { |
|
141 | + if ($invoice->is_recurring()) { |
|
142 | 142 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
143 | 143 | } else { |
144 | 144 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
145 | 145 | } |
146 | 146 | |
147 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
147 | + return add_query_arg($paypal_args, $this->endpoint); |
|
148 | 148 | |
149 | 149 | } |
150 | 150 | |
@@ -154,25 +154,25 @@ discard block |
||
154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
155 | 155 | * @return array |
156 | 156 | */ |
157 | - protected function get_paypal_args( $invoice ) { |
|
157 | + protected function get_paypal_args($invoice) { |
|
158 | 158 | |
159 | 159 | // Whether or not to send the line items as one item. |
160 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
160 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice); |
|
161 | 161 | |
162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
162 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
163 | 163 | $force_one_line_item = true; |
164 | 164 | } |
165 | 165 | |
166 | 166 | $paypal_args = apply_filters( |
167 | 167 | 'getpaid_paypal_args', |
168 | 168 | array_merge( |
169 | - $this->get_transaction_args( $invoice ), |
|
170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | + $this->get_transaction_args($invoice), |
|
170 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
171 | 171 | ), |
172 | 172 | $invoice |
173 | 173 | ); |
174 | 174 | |
175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
175 | + return $this->fix_request_length($invoice, $paypal_args); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | * @param WPInv_Invoice $invoice Invoice object. |
182 | 182 | * @return array |
183 | 183 | */ |
184 | - protected function get_transaction_args( $invoice ) { |
|
184 | + protected function get_transaction_args($invoice) { |
|
185 | 185 | |
186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
186 | + $email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', ''); |
|
187 | 187 | return array( |
188 | 188 | 'cmd' => '_cart', |
189 | 189 | 'business' => $email, |
@@ -194,16 +194,16 @@ discard block |
||
194 | 194 | 'rm' => is_ssl() ? 2 : 1, |
195 | 195 | 'upload' => 1, |
196 | 196 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
197 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
198 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
199 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
200 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
197 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
198 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
199 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
200 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
201 | 201 | 'custom' => $invoice->get_id(), |
202 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
203 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
204 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
205 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
206 | - 'cbt' => get_bloginfo( 'name' ) |
|
202 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
203 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
204 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
205 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
206 | + 'cbt' => get_bloginfo('name') |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | } |
@@ -215,30 +215,30 @@ discard block |
||
215 | 215 | * @param bool $force_one_line_item Create only one item for this invoice. |
216 | 216 | * @return array |
217 | 217 | */ |
218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
218 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
219 | 219 | |
220 | 220 | // Maybe send invoice as a single item. |
221 | - if ( $force_one_line_item ) { |
|
222 | - return $this->get_line_item_args_single_item( $invoice ); |
|
221 | + if ($force_one_line_item) { |
|
222 | + return $this->get_line_item_args_single_item($invoice); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | // Send each line item individually. |
226 | 226 | $line_item_args = array(); |
227 | 227 | |
228 | 228 | // Prepare line items. |
229 | - $this->prepare_line_items( $invoice ); |
|
229 | + $this->prepare_line_items($invoice); |
|
230 | 230 | |
231 | 231 | // Add taxes to the cart |
232 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
233 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
232 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
233 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | // Add discount. |
237 | - if ( $invoice->get_total_discount() > 0 ) { |
|
238 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
237 | + if ($invoice->get_total_discount() > 0) { |
|
238 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
239 | 239 | } |
240 | 240 | |
241 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
241 | + return array_merge($line_item_args, $this->get_line_items()); |
|
242 | 242 | |
243 | 243 | } |
244 | 244 | |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | * @param WPInv_Invoice $invoice Invoice object. |
249 | 249 | * @return array |
250 | 250 | */ |
251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
251 | + protected function get_line_item_args_single_item($invoice) { |
|
252 | 252 | $this->delete_line_items(); |
253 | 253 | |
254 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
255 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
254 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
255 | + $this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id()); |
|
256 | 256 | |
257 | 257 | return $this->get_line_items(); |
258 | 258 | } |
@@ -276,19 +276,19 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @param WPInv_Invoice $invoice Invoice object. |
278 | 278 | */ |
279 | - protected function prepare_line_items( $invoice ) { |
|
279 | + protected function prepare_line_items($invoice) { |
|
280 | 280 | $this->delete_line_items(); |
281 | 281 | |
282 | 282 | // Items. |
283 | - foreach ( $invoice->get_items() as $item ) { |
|
283 | + foreach ($invoice->get_items() as $item) { |
|
284 | 284 | $amount = $item->get_price(); |
285 | 285 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
286 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // Fees. |
290 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
291 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
290 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
291 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | } |
@@ -301,15 +301,15 @@ discard block |
||
301 | 301 | * @param float $amount Amount. |
302 | 302 | * @param string $item_number Item number. |
303 | 303 | */ |
304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
304 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
305 | + $index = (count($this->line_items) / 4) + 1; |
|
306 | 306 | |
307 | 307 | $item = apply_filters( |
308 | 308 | 'getpaid_paypal_line_item', |
309 | 309 | array( |
310 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
310 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
311 | 311 | 'quantity' => (float) $quantity, |
312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
312 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
313 | 313 | 'item_number' => $item_number, |
314 | 314 | ), |
315 | 315 | $item_name, |
@@ -318,12 +318,12 @@ discard block |
||
318 | 318 | $item_number |
319 | 319 | ); |
320 | 320 | |
321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
322 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
321 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
322 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
323 | 323 | |
324 | 324 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
325 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
325 | + $this->line_items['amount_' . $index] = $item['amount'] * $item['quantity']; |
|
326 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -335,19 +335,19 @@ discard block |
||
335 | 335 | * @param array $paypal_args Arguments sent to Paypal in the request. |
336 | 336 | * @return array |
337 | 337 | */ |
338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
338 | + protected function fix_request_length($invoice, $paypal_args) { |
|
339 | 339 | $max_paypal_length = 2083; |
340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
340 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
341 | 341 | |
342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
342 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
343 | 343 | return $paypal_args; |
344 | 344 | } |
345 | 345 | |
346 | 346 | return apply_filters( |
347 | 347 | 'getpaid_paypal_args', |
348 | 348 | array_merge( |
349 | - $this->get_transaction_args( $invoice ), |
|
350 | - $this->get_line_item_args( $invoice, true ) |
|
349 | + $this->get_transaction_args($invoice), |
|
350 | + $this->get_line_item_args($invoice, true) |
|
351 | 351 | ), |
352 | 352 | $invoice |
353 | 353 | ); |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | * @param array $paypal_args PayPal args. |
361 | 361 | * @param WPInv_Invoice $invoice Invoice object. |
362 | 362 | */ |
363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
363 | + public function process_subscription($paypal_args, $invoice) { |
|
364 | 364 | |
365 | 365 | // Make sure this is a subscription. |
366 | - if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
|
366 | + if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) { |
|
367 | 367 | return $paypal_args; |
368 | 368 | } |
369 | 369 | |
@@ -371,23 +371,23 @@ discard block |
||
371 | 371 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
372 | 372 | |
373 | 373 | // Subscription name. |
374 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
374 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
375 | 375 | |
376 | 376 | // Get subscription args. |
377 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1) ); |
|
377 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
378 | 378 | $interval = (int) $subscription->get_frequency(); |
379 | 379 | $bill_times = (int) $subscription->get_bill_times(); |
380 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
381 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
382 | - $subscription_item = $invoice->get_recurring( true ); |
|
380 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
381 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
382 | + $subscription_item = $invoice->get_recurring(true); |
|
383 | 383 | |
384 | 384 | // Convert 365 days to 1 year. |
385 | - if ( 'D' == $period && 365 == $interval ) { |
|
385 | + if ('D' == $period && 365 == $interval) { |
|
386 | 386 | $period = 'Y'; |
387 | 387 | $interval = 1; |
388 | 388 | } |
389 | 389 | |
390 | - if ( $subscription_item->has_free_trial() ) { |
|
390 | + if ($subscription_item->has_free_trial()) { |
|
391 | 391 | |
392 | 392 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
393 | 393 | |
@@ -397,28 +397,28 @@ discard block |
||
397 | 397 | // Trial period. |
398 | 398 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
399 | 399 | |
400 | - } else if ( $initial_amount != $recurring_amount ) { |
|
400 | + } else if ($initial_amount != $recurring_amount) { |
|
401 | 401 | |
402 | 402 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
403 | 403 | |
404 | - if ( 1 == $bill_times ) { |
|
404 | + if (1 == $bill_times) { |
|
405 | 405 | $param_number = 3; |
406 | 406 | } else { |
407 | 407 | $param_number = 1; |
408 | 408 | } |
409 | 409 | |
410 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0; |
|
410 | + $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0; |
|
411 | 411 | |
412 | 412 | // Sign Up interval |
413 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
413 | + $paypal_args['p' . $param_number] = $interval; |
|
414 | 414 | |
415 | 415 | // Sign Up unit of duration |
416 | - $paypal_args[ 't' . $param_number ] = $period; |
|
416 | + $paypal_args['t' . $param_number] = $period; |
|
417 | 417 | |
418 | 418 | } |
419 | 419 | |
420 | 420 | // We have a recurring payment |
421 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
421 | + if (!isset($param_number) || 1 == $param_number) { |
|
422 | 422 | |
423 | 423 | // Subscription price |
424 | 424 | $paypal_args['a3'] = $recurring_amount; |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | } |
433 | 433 | |
434 | 434 | // Recurring payments |
435 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
435 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
436 | 436 | |
437 | 437 | // Non-recurring payments |
438 | 438 | $paypal_args['src'] = 0; |
@@ -441,15 +441,15 @@ discard block |
||
441 | 441 | |
442 | 442 | $paypal_args['src'] = 1; |
443 | 443 | |
444 | - if ( $bill_times > 0 ) { |
|
444 | + if ($bill_times > 0) { |
|
445 | 445 | |
446 | 446 | // An initial period is being used to charge a sign-up fee |
447 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
447 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
448 | 448 | $bill_times--; |
449 | 449 | } |
450 | 450 | |
451 | 451 | // Make sure it's not over the max of 52 |
452 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
452 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
453 | 453 | |
454 | 454 | } |
455 | 455 | } |
@@ -458,10 +458,10 @@ discard block |
||
458 | 458 | $paypal_args['rm'] = 2; |
459 | 459 | |
460 | 460 | // Get rid of redudant items. |
461 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
461 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
462 | 462 | |
463 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
464 | - unset( $paypal_args[ $arg ] ); |
|
463 | + if (isset($paypal_args[$arg])) { |
|
464 | + unset($paypal_args[$arg]); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | } |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return void |
481 | 481 | */ |
482 | 482 | public function verify_ipn() { |
483 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
483 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | public function sandbox_notice() { |
490 | 490 | |
491 | 491 | return sprintf( |
492 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
492 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
493 | 493 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
494 | 494 | '</a>' |
495 | 495 | ); |
@@ -501,30 +501,30 @@ discard block |
||
501 | 501 | * |
502 | 502 | * @param array $admin_settings |
503 | 503 | */ |
504 | - public function admin_settings( $admin_settings ) { |
|
504 | + public function admin_settings($admin_settings) { |
|
505 | 505 | |
506 | 506 | $currencies = sprintf( |
507 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
508 | - implode( ', ', $this->currencies ) |
|
507 | + __('Supported Currencies: %s', 'invoicing'), |
|
508 | + implode(', ', $this->currencies) |
|
509 | 509 | ); |
510 | 510 | |
511 | 511 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
512 | - $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
512 | + $admin_settings['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
513 | 513 | |
514 | 514 | // Access tokens. |
515 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
516 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
515 | + $live_email = wpinv_get_option('paypal_email'); |
|
516 | + $sandbox_email = wpinv_get_option('paypal_sandbox_email'); |
|
517 | 517 | |
518 | 518 | $admin_settings['paypal_connect'] = array( |
519 | 519 | 'type' => 'raw_html', |
520 | 520 | 'id' => 'paypal_connect', |
521 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
521 | + 'name' => __('Connect to PayPal', 'invoicing'), |
|
522 | 522 | 'desc' => sprintf( |
523 | 523 | '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
524 | - esc_url( self::get_connect_url( false ) ), |
|
525 | - __( 'Connect to PayPal', 'invoicing' ), |
|
526 | - esc_url( self::get_connect_url( true ) ), |
|
527 | - __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
524 | + esc_url(self::get_connect_url(false)), |
|
525 | + __('Connect to PayPal', 'invoicing'), |
|
526 | + esc_url(self::get_connect_url(true)), |
|
527 | + __('Connect to PayPal Sandox', 'invoicing'), |
|
528 | 528 | $this->get_js() |
529 | 529 | ), |
530 | 530 | ); |
@@ -533,25 +533,25 @@ discard block |
||
533 | 533 | 'type' => 'text', |
534 | 534 | 'class' => 'live-auth-data', |
535 | 535 | 'id' => 'paypal_email', |
536 | - 'name' => __( 'Live Email Address', 'invoicing' ), |
|
537 | - 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
|
536 | + 'name' => __('Live Email Address', 'invoicing'), |
|
537 | + 'desc' => __('The email address of your PayPal account.', 'invoicing'), |
|
538 | 538 | ); |
539 | 539 | |
540 | 540 | $admin_settings['paypal_sandbox_email'] = array( |
541 | 541 | 'type' => 'text', |
542 | 542 | 'class' => 'sandbox-auth-data', |
543 | 543 | 'id' => 'paypal_sandbox_email', |
544 | - 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
|
545 | - 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
|
546 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
544 | + 'name' => __('Sandbox Email Address', 'invoicing'), |
|
545 | + 'desc' => __('The email address of your sandbox PayPal account.', 'invoicing'), |
|
546 | + 'std' => wpinv_get_option('paypal_email', ''), |
|
547 | 547 | ); |
548 | 548 | |
549 | 549 | $admin_settings['paypal_ipn_url'] = array( |
550 | 550 | 'type' => 'ipn_url', |
551 | 551 | 'id' => 'paypal_ipn_url', |
552 | - 'name' => __( 'IPN Url', 'invoicing' ), |
|
552 | + 'name' => __('IPN Url', 'invoicing'), |
|
553 | 553 | 'std' => $this->notify_url, |
554 | - 'desc' => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
554 | + 'desc' => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
555 | 555 | 'readonly' => true, |
556 | 556 | ); |
557 | 557 | |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | * @param array $data |
566 | 566 | * @return string |
567 | 567 | */ |
568 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
569 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
568 | + public static function maybe_get_connect_url($url = '', $data = array()) { |
|
569 | + return self::get_connect_url(false, urldecode($data['redirect'])); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | /** |
@@ -577,25 +577,25 @@ discard block |
||
577 | 577 | * @param string $redirect |
578 | 578 | * @return string |
579 | 579 | */ |
580 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
580 | + public static function get_connect_url($is_sandbox, $redirect = '') { |
|
581 | 581 | |
582 | 582 | $redirect_url = add_query_arg( |
583 | 583 | array( |
584 | 584 | 'getpaid-admin-action' => 'connect_paypal', |
585 | 585 | 'page' => 'wpinv-settings', |
586 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
586 | + 'live_mode' => (int) empty($is_sandbox), |
|
587 | 587 | 'tab' => 'gateways', |
588 | 588 | 'section' => 'paypal', |
589 | - 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
|
590 | - 'redirect' => urlencode( $redirect ), |
|
589 | + 'getpaid-nonce' => wp_create_nonce('getpaid-nonce'), |
|
590 | + 'redirect' => urlencode($redirect), |
|
591 | 591 | ), |
592 | - admin_url( 'admin.php' ) |
|
592 | + admin_url('admin.php') |
|
593 | 593 | ); |
594 | 594 | |
595 | 595 | return add_query_arg( |
596 | 596 | array( |
597 | - 'live_mode' => (int) empty( $is_sandbox ), |
|
598 | - 'redirect_url' => urlencode( str_replace( '&', '&', $redirect_url ) ) |
|
597 | + 'live_mode' => (int) empty($is_sandbox), |
|
598 | + 'redirect_url' => urlencode(str_replace('&', '&', $redirect_url)) |
|
599 | 599 | ), |
600 | 600 | 'https://ayecode.io/oauth/paypal' |
601 | 601 | ); |
@@ -649,26 +649,26 @@ discard block |
||
649 | 649 | * @param array $data Connection data. |
650 | 650 | * @return void |
651 | 651 | */ |
652 | - public function connect_paypal( $data ) { |
|
652 | + public function connect_paypal($data) { |
|
653 | 653 | |
654 | 654 | $sandbox = $this->is_sandbox(); |
655 | - $data = wp_unslash( $data ); |
|
656 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
655 | + $data = wp_unslash($data); |
|
656 | + $access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']); |
|
657 | 657 | |
658 | - if ( isset( $data['live_mode'] ) ) { |
|
659 | - $sandbox = empty( $data['live_mode'] ); |
|
658 | + if (isset($data['live_mode'])) { |
|
659 | + $sandbox = empty($data['live_mode']); |
|
660 | 660 | } |
661 | 661 | |
662 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
663 | - wpinv_update_option( 'paypal_active', 1 ); |
|
662 | + wpinv_update_option('paypal_sandbox', (int) $sandbox); |
|
663 | + wpinv_update_option('paypal_active', 1); |
|
664 | 664 | |
665 | - if ( ! empty( $data['error_description'] ) ) { |
|
666 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
665 | + if (!empty($data['error_description'])) { |
|
666 | + getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description']))); |
|
667 | 667 | } else { |
668 | 668 | |
669 | 669 | // Retrieve the user info. |
670 | 670 | $user_info = wp_remote_get( |
671 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
671 | + !$sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
672 | 672 | array( |
673 | 673 | |
674 | 674 | 'headers' => array( |
@@ -679,35 +679,35 @@ discard block |
||
679 | 679 | ) |
680 | 680 | ); |
681 | 681 | |
682 | - if ( is_wp_error( $user_info ) ) { |
|
683 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
682 | + if (is_wp_error($user_info)) { |
|
683 | + getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message())); |
|
684 | 684 | } else { |
685 | 685 | |
686 | 686 | // Create application. |
687 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
687 | + $user_info = json_decode(wp_remote_retrieve_body($user_info)); |
|
688 | 688 | |
689 | - if ( $sandbox ) { |
|
690 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
691 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
692 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
693 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
689 | + if ($sandbox) { |
|
690 | + wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value)); |
|
691 | + wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
692 | + set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
693 | + getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing')); |
|
694 | 694 | } else { |
695 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
696 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
697 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
698 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
695 | + wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value)); |
|
696 | + wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token']))); |
|
697 | + set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']); |
|
698 | + getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing')); |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | } |
702 | 702 | |
703 | 703 | } |
704 | 704 | |
705 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
705 | + $redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways§ion=paypal') : urldecode($data['redirect']); |
|
706 | 706 | |
707 | - if ( isset( $data['step'] ) ) { |
|
708 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
707 | + if (isset($data['step'])) { |
|
708 | + $redirect = add_query_arg('step', $data['step'], $redirect); |
|
709 | 709 | } |
710 | - wp_redirect( $redirect ); |
|
710 | + wp_redirect($redirect); |
|
711 | 711 | exit; |
712 | 712 | } |
713 | 713 |
@@ -15,31 +15,31 @@ discard block |
||
15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
16 | 16 | |
17 | 17 | /** |
18 | - * Class constructor. |
|
19 | - */ |
|
20 | - public function __construct() { |
|
18 | + * Class constructor. |
|
19 | + */ |
|
20 | + public function __construct() { |
|
21 | 21 | parent::__construct(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
25 | - * Returns the API URL. |
|
26 | - * |
|
27 | - * |
|
28 | - * @param WPInv_Invoice $invoice Invoice. |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function get_api_url( $invoice ) { |
|
25 | + * Returns the API URL. |
|
26 | + * |
|
27 | + * |
|
28 | + * @param WPInv_Invoice $invoice Invoice. |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function get_api_url( $invoice ) { |
|
32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | - * Communicates with authorize.net |
|
37 | - * |
|
38 | - * |
|
39 | - * @param array $post Data to post. |
|
36 | + * Communicates with authorize.net |
|
37 | + * |
|
38 | + * |
|
39 | + * @param array $post Data to post. |
|
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | - * @return stdClass|WP_Error |
|
42 | - */ |
|
41 | + * @return stdClass|WP_Error |
|
42 | + */ |
|
43 | 43 | public function post( $post, $invoice ){ |
44 | 44 | |
45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | - * Returns the API authentication params. |
|
93 | - * |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function get_auth_params() { |
|
92 | + * Returns the API authentication params. |
|
93 | + * |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function get_auth_params() { |
|
98 | 98 | |
99 | 99 | return array( |
100 | 100 | 'name' => $this->get_option( 'login_id' ), |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | - * Cancels a subscription remotely |
|
108 | - * |
|
109 | - * |
|
110 | - * @param WPInv_Subscription $subscription Subscription. |
|
107 | + * Cancels a subscription remotely |
|
108 | + * |
|
109 | + * |
|
110 | + * @param WPInv_Subscription $subscription Subscription. |
|
111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
112 | - */ |
|
113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
112 | + */ |
|
113 | + public function cancel_subscription( $subscription, $invoice ) { |
|
114 | 114 | |
115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
116 | 116 | $this->post( |
@@ -126,17 +126,17 @@ discard block |
||
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | - * Processes ipns. |
|
130 | - * |
|
131 | - * @return void |
|
132 | - */ |
|
133 | - public function verify_ipn() { |
|
129 | + * Processes ipns. |
|
130 | + * |
|
131 | + * @return void |
|
132 | + */ |
|
133 | + public function verify_ipn() { |
|
134 | 134 | |
135 | 135 | $this->maybe_process_old_ipn(); |
136 | 136 | |
137 | 137 | // Validate the IPN. |
138 | 138 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
139 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Event type. |
@@ -175,24 +175,24 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | - * Validates IPN invoices. |
|
179 | - * |
|
178 | + * Validates IPN invoices. |
|
179 | + * |
|
180 | 180 | * @param WPInv_Invoice $invoice |
181 | 181 | * @param object $payload |
182 | - * @return void |
|
183 | - */ |
|
184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
185 | 185 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
186 | 186 | exit; |
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | - * Process subscriptio IPNS. |
|
192 | - * |
|
193 | - * @return void |
|
194 | - */ |
|
195 | - public function maybe_process_old_ipn() { |
|
191 | + * Process subscriptio IPNS. |
|
192 | + * |
|
193 | + * @return void |
|
194 | + */ |
|
195 | + public function maybe_process_old_ipn() { |
|
196 | 196 | |
197 | 197 | $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
198 | 198 | |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
237 | - * Validates the old IPN signature. |
|
237 | + * Validates the old IPN signature. |
|
238 | 238 | * |
239 | 239 | * @param array $posted |
240 | - */ |
|
241 | - public function validate_old_ipn_signature( $posted ) { |
|
240 | + */ |
|
241 | + public function validate_old_ipn_signature( $posted ) { |
|
242 | 242 | |
243 | 243 | $signature = $this->get_option( 'signature_key' ); |
244 | 244 | if ( ! empty( $signature ) ) { |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | - * Check Authorize.NET IPN validity. |
|
261 | - */ |
|
262 | - public function validate_ipn() { |
|
260 | + * Check Authorize.NET IPN validity. |
|
261 | + */ |
|
262 | + public function validate_ipn() { |
|
263 | 263 | |
264 | 264 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
265 | 265 |
@@ -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 | * Authorize.net Legacy Payment Gateway class. |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | * @param WPInv_Invoice $invoice Invoice. |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function get_api_url( $invoice ) { |
|
32 | - return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
31 | + public function get_api_url($invoice) { |
|
32 | + return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -40,48 +40,48 @@ discard block |
||
40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
41 | 41 | * @return stdClass|WP_Error |
42 | 42 | */ |
43 | - public function post( $post, $invoice ){ |
|
43 | + public function post($post, $invoice) { |
|
44 | 44 | |
45 | - $url = $this->get_api_url( $invoice ); |
|
45 | + $url = $this->get_api_url($invoice); |
|
46 | 46 | $response = wp_remote_post( |
47 | 47 | $url, |
48 | 48 | array( |
49 | 49 | 'headers' => array( |
50 | 50 | 'Content-Type' => 'application/json; charset=utf-8' |
51 | 51 | ), |
52 | - 'body' => json_encode( $post ), |
|
52 | + 'body' => json_encode($post), |
|
53 | 53 | 'method' => 'POST' |
54 | 54 | ) |
55 | 55 | ); |
56 | 56 | |
57 | - if ( is_wp_error( $response ) ) { |
|
57 | + if (is_wp_error($response)) { |
|
58 | 58 | return $response; |
59 | 59 | } |
60 | 60 | |
61 | - $response = wp_unslash( wp_remote_retrieve_body( $response ) ); |
|
61 | + $response = wp_unslash(wp_remote_retrieve_body($response)); |
|
62 | 62 | $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
63 | - $response = json_decode( $response ); |
|
63 | + $response = json_decode($response); |
|
64 | 64 | |
65 | - if ( empty( $response ) ) { |
|
66 | - return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) ); |
|
65 | + if (empty($response)) { |
|
66 | + return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing')); |
|
67 | 67 | } |
68 | 68 | |
69 | - if ( $response->messages->resultCode == 'Error' ) { |
|
69 | + if ($response->messages->resultCode == 'Error') { |
|
70 | 70 | |
71 | - if ( $this->is_sandbox( $invoice ) ) { |
|
72 | - wpinv_error_log( $response ); |
|
71 | + if ($this->is_sandbox($invoice)) { |
|
72 | + wpinv_error_log($response); |
|
73 | 73 | } |
74 | 74 | |
75 | - if ( $response->messages->message[0]->code == 'E00039' && ! empty( $response->customerProfileId ) && ! empty( $response->customerPaymentProfileId ) ) { |
|
76 | - return new WP_Error( 'dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId ); |
|
75 | + if ($response->messages->message[0]->code == 'E00039' && !empty($response->customerProfileId) && !empty($response->customerPaymentProfileId)) { |
|
76 | + return new WP_Error('dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId); |
|
77 | 77 | } |
78 | 78 | |
79 | - if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) { |
|
79 | + if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) { |
|
80 | 80 | $error = $response->transactionResponse->errors[0]; |
81 | - return new WP_Error( $error->errorCode, $error->errorText ); |
|
81 | + return new WP_Error($error->errorCode, $error->errorText); |
|
82 | 82 | } |
83 | 83 | |
84 | - return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text ); |
|
84 | + return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return $response; |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | public function get_auth_params() { |
98 | 98 | |
99 | 99 | return array( |
100 | - 'name' => $this->get_option( 'login_id' ), |
|
101 | - 'transactionKey' => $this->get_option( 'transaction_key' ), |
|
100 | + 'name' => $this->get_option('login_id'), |
|
101 | + 'transactionKey' => $this->get_option('transaction_key'), |
|
102 | 102 | ); |
103 | 103 | |
104 | 104 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param WPInv_Subscription $subscription Subscription. |
111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
112 | 112 | */ |
113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
113 | + public function cancel_subscription($subscription, $invoice) { |
|
114 | 114 | |
115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
116 | 116 | $this->post( |
@@ -135,38 +135,38 @@ discard block |
||
135 | 135 | $this->maybe_process_old_ipn(); |
136 | 136 | |
137 | 137 | // Validate the IPN. |
138 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
138 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
139 | + wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 200)); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Event type. |
143 | - $posted = json_decode( file_get_contents( 'php://input' ) ); |
|
144 | - if ( empty( $posted ) ) { |
|
145 | - wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
143 | + $posted = json_decode(file_get_contents('php://input')); |
|
144 | + if (empty($posted)) { |
|
145 | + wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 200)); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | // Process the IPN. |
149 | - $posted = (object) wp_unslash( $posted ); |
|
149 | + $posted = (object) wp_unslash($posted); |
|
150 | 150 | |
151 | 151 | // Process refunds. |
152 | - if ( 'net.authorize.payment.refund.created' == $posted->eventType ) { |
|
153 | - $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId ); |
|
154 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
152 | + if ('net.authorize.payment.refund.created' == $posted->eventType) { |
|
153 | + $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId); |
|
154 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
155 | 155 | $invoice->refund(); |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Held funds approved. |
159 | - if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) { |
|
160 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
161 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
162 | - $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) ); |
|
159 | + if ('net.authorize.payment.fraud.approved' == $posted->eventType) { |
|
160 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
161 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
162 | + $invoice->mark_paid(false, __('Payment released', 'invoicing')); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // Held funds declined. |
166 | - if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) { |
|
167 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
168 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
169 | - $invoice->set_status( 'wpi-failed', __( 'Payment declined', 'invoicing' ) ); |
|
166 | + if ('net.authorize.payment.fraud.declined' == $posted->eventType) { |
|
167 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
168 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
169 | + $invoice->set_status('wpi-failed', __('Payment declined', 'invoicing')); |
|
170 | 170 | $invoice->save(); |
171 | 171 | } |
172 | 172 | |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | * @param object $payload |
182 | 182 | * @return void |
183 | 183 | */ |
184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
185 | - if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
|
184 | + public function validate_ipn_invoice($invoice, $payload) { |
|
185 | + if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) { |
|
186 | 186 | exit; |
187 | 187 | } |
188 | 188 | } |
@@ -194,32 +194,32 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function maybe_process_old_ipn() { |
196 | 196 | |
197 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
197 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
198 | 198 | |
199 | 199 | // Only process subscriptions subscriptions. |
200 | - if ( empty( $data['x_subscription_id'] ) ) { |
|
200 | + if (empty($data['x_subscription_id'])) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 | |
204 | 204 | // Check validity. |
205 | - $this->validate_old_ipn_signature( $data ); |
|
205 | + $this->validate_old_ipn_signature($data); |
|
206 | 206 | |
207 | 207 | // Fetch the associated subscription. |
208 | - $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $data['x_subscription_id'] ); |
|
209 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
208 | + $subscription_id = WPInv_Subscription::get_subscription_id_by_field($data['x_subscription_id']); |
|
209 | + $subscription = new WPInv_Subscription($subscription_id); |
|
210 | 210 | |
211 | 211 | // Abort if it is missing or completed. |
212 | - if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) { |
|
212 | + if (!$subscription->get_id() || $subscription->has_status('completed')) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // Payment status. |
217 | - if ( 1 == $data['x_response_code'] ) { |
|
217 | + if (1 == $data['x_response_code']) { |
|
218 | 218 | |
219 | 219 | // Renew the subscription. |
220 | 220 | $subscription->add_payment( |
221 | 221 | array( |
222 | - 'transaction_id' => sanitize_text_field( $data['x_trans_id'] ), |
|
222 | + 'transaction_id' => sanitize_text_field($data['x_trans_id']), |
|
223 | 223 | 'gateway' => $this->id |
224 | 224 | ) |
225 | 225 | ); |
@@ -238,17 +238,17 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @param array $posted |
240 | 240 | */ |
241 | - public function validate_old_ipn_signature( $posted ) { |
|
241 | + public function validate_old_ipn_signature($posted) { |
|
242 | 242 | |
243 | - $signature = $this->get_option( 'signature_key' ); |
|
244 | - if ( ! empty( $signature ) ) { |
|
245 | - $login_id = $this->get_option( 'login_id' ); |
|
246 | - $trans_id = wpinv_clean( $_POST['x_trans_id'] ); |
|
247 | - $amount = wpinv_clean( $_POST['x_amount'] ); |
|
248 | - $hash = hash_hmac ( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) ); |
|
243 | + $signature = $this->get_option('signature_key'); |
|
244 | + if (!empty($signature)) { |
|
245 | + $login_id = $this->get_option('login_id'); |
|
246 | + $trans_id = wpinv_clean($_POST['x_trans_id']); |
|
247 | + $amount = wpinv_clean($_POST['x_amount']); |
|
248 | + $hash = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature)); |
|
249 | 249 | |
250 | - if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) { |
|
251 | - wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" ); |
|
250 | + if (!hash_equals($hash, $posted['x_SHA2_Hash'])) { |
|
251 | + wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash"); |
|
252 | 252 | exit; |
253 | 253 | } |
254 | 254 | |
@@ -261,28 +261,28 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function validate_ipn() { |
263 | 263 | |
264 | - wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
|
264 | + wpinv_error_log('Validating Authorize.NET IPN response'); |
|
265 | 265 | |
266 | - if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
266 | + if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
267 | 267 | return false; |
268 | 268 | } |
269 | 269 | |
270 | - $signature = $this->get_option( 'signature_key' ); |
|
270 | + $signature = $this->get_option('signature_key'); |
|
271 | 271 | |
272 | - if ( empty( $signature ) ) { |
|
273 | - wpinv_error_log( 'Error: You have not set a signature key' ); |
|
272 | + if (empty($signature)) { |
|
273 | + wpinv_error_log('Error: You have not set a signature key'); |
|
274 | 274 | return false; |
275 | 275 | } |
276 | 276 | |
277 | - $hash = hash_hmac ( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) ); |
|
277 | + $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature)); |
|
278 | 278 | |
279 | - if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
280 | - wpinv_error_log( 'Successfully validated the IPN' ); |
|
279 | + if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
280 | + wpinv_error_log('Successfully validated the IPN'); |
|
281 | 281 | return true; |
282 | 282 | } |
283 | 283 | |
284 | - wpinv_error_log( 'IPN hash is not valid' ); |
|
285 | - wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] ); |
|
284 | + wpinv_error_log('IPN hash is not valid'); |
|
285 | + wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']); |
|
286 | 286 | return false; |
287 | 287 | |
288 | 288 | } |
@@ -7,31 +7,31 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Prepare the selectable items. |
13 | 13 | $selectable = array(); |
14 | -foreach ( $form->get_items() as $item ) { |
|
15 | - if ( ! $item->is_required ) { |
|
16 | - $selectable[$item->get_id()] = $item->get_name() . ' — ' . wpinv_price( $item->get_initial_price() ); |
|
14 | +foreach ($form->get_items() as $item) { |
|
15 | + if (!$item->is_required) { |
|
16 | + $selectable[$item->get_id()] = $item->get_name() . ' — ' . wpinv_price($item->get_initial_price()); |
|
17 | 17 | } |
18 | 18 | } |
19 | 19 | |
20 | -if ( empty( $selectable ) ) { |
|
20 | +if (empty($selectable)) { |
|
21 | 21 | return; |
22 | 22 | } |
23 | 23 | |
24 | 24 | echo '<div class="getpaid-payment-form-items-checkbox form-group">'; |
25 | 25 | |
26 | -foreach ( $selectable as $item_id => $item_name ) { |
|
26 | +foreach ($selectable as $item_id => $item_name) { |
|
27 | 27 | |
28 | - $is_checked = get_post_meta( $item_id, 'selected_by_default', true ); |
|
28 | + $is_checked = get_post_meta($item_id, 'selected_by_default', true); |
|
29 | 29 | |
30 | 30 | echo aui()->input( |
31 | 31 | array( |
32 | 32 | 'type' => 'checkbox', |
33 | 33 | 'name' => 'getpaid-payment-form-selected-item', |
34 | - 'id' => 'getpaid-payment-form-selected-item' . uniqid( '_' ) . $item_id, |
|
34 | + 'id' => 'getpaid-payment-form-selected-item' . uniqid('_') . $item_id, |
|
35 | 35 | 'label' => $item_name, |
36 | 36 | 'value' => $item_id, |
37 | 37 | 'no_wrap' => true, |
@@ -9,41 +9,41 @@ discard block |
||
9 | 9 | * @version 1.0.19 |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | return array( |
15 | 15 | |
16 | 16 | array( |
17 | 17 | 'type' => 'heading', |
18 | - 'name' => __( 'Heading', 'invoicing' ), |
|
18 | + 'name' => __('Heading', 'invoicing'), |
|
19 | 19 | 'defaults' => array( |
20 | 20 | 'level' => 'h2', |
21 | - 'text' => __( 'Heading', 'invoicing' ), |
|
21 | + 'text' => __('Heading', 'invoicing'), |
|
22 | 22 | ) |
23 | 23 | ), |
24 | 24 | |
25 | 25 | array( |
26 | 26 | 'type' => 'paragraph', |
27 | - 'name' => __( 'Paragraph', 'invoicing' ), |
|
27 | + 'name' => __('Paragraph', 'invoicing'), |
|
28 | 28 | 'defaults' => array( |
29 | - 'text' => __( 'Paragraph text', 'invoicing' ), |
|
29 | + 'text' => __('Paragraph text', 'invoicing'), |
|
30 | 30 | ) |
31 | 31 | ), |
32 | 32 | |
33 | 33 | array( |
34 | 34 | 'type' => 'alert', |
35 | - 'name' => __( 'Alert', 'invoicing' ), |
|
35 | + 'name' => __('Alert', 'invoicing'), |
|
36 | 36 | 'defaults' => array( |
37 | 37 | 'value' => '', |
38 | 38 | 'class' => 'alert-warning', |
39 | - 'text' => __( 'Alert', 'invoicing' ), |
|
39 | + 'text' => __('Alert', 'invoicing'), |
|
40 | 40 | 'dismissible' => false, |
41 | 41 | ) |
42 | 42 | ), |
43 | 43 | |
44 | 44 | array( |
45 | 45 | 'type' => 'separator', |
46 | - 'name' => __( 'Separator', 'invoicing' ), |
|
46 | + 'name' => __('Separator', 'invoicing'), |
|
47 | 47 | 'defaults' => array( |
48 | 48 | 'value' => '', |
49 | 49 | ), |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | |
52 | 52 | array( |
53 | 53 | 'type' => 'text', |
54 | - 'name' => __( 'Text Input', 'invoicing' ), |
|
54 | + 'name' => __('Text Input', 'invoicing'), |
|
55 | 55 | 'defaults' => array( |
56 | - 'placeholder' => __( 'Enter some text', 'invoicing' ), |
|
56 | + 'placeholder' => __('Enter some text', 'invoicing'), |
|
57 | 57 | 'value' => '', |
58 | - 'label' => __( 'Field Label', 'invoicing' ), |
|
58 | + 'label' => __('Field Label', 'invoicing'), |
|
59 | 59 | 'description' => '', |
60 | 60 | 'required' => false, |
61 | 61 | ) |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | |
64 | 64 | array( |
65 | 65 | 'type' => 'textarea', |
66 | - 'name' => __( 'Textarea', 'invoicing' ), |
|
66 | + 'name' => __('Textarea', 'invoicing'), |
|
67 | 67 | 'defaults' => array( |
68 | - 'placeholder' => __( 'Enter your text here', 'invoicing' ), |
|
68 | + 'placeholder' => __('Enter your text here', 'invoicing'), |
|
69 | 69 | 'value' => '', |
70 | - 'label' => __( 'Textarea Label', 'invoicing' ), |
|
70 | + 'label' => __('Textarea Label', 'invoicing'), |
|
71 | 71 | 'description' => '', |
72 | 72 | 'required' => false, |
73 | 73 | ) |
@@ -75,27 +75,27 @@ discard block |
||
75 | 75 | |
76 | 76 | array( |
77 | 77 | 'type' => 'select', |
78 | - 'name' => __( 'Dropdown', 'invoicing' ), |
|
78 | + 'name' => __('Dropdown', 'invoicing'), |
|
79 | 79 | 'defaults' => array( |
80 | - 'placeholder' => __( 'Select a value', 'invoicing' ), |
|
80 | + 'placeholder' => __('Select a value', 'invoicing'), |
|
81 | 81 | 'value' => '', |
82 | - 'label' => __( 'Dropdown Label', 'invoicing' ), |
|
82 | + 'label' => __('Dropdown Label', 'invoicing'), |
|
83 | 83 | 'description' => '', |
84 | 84 | 'required' => false, |
85 | 85 | 'options' => array( |
86 | - esc_attr__( 'Option One', 'invoicing' ), |
|
87 | - esc_attr__( 'Option Two', 'invoicing' ), |
|
88 | - esc_attr__( 'Option Three', 'invoicing' ) |
|
86 | + esc_attr__('Option One', 'invoicing'), |
|
87 | + esc_attr__('Option Two', 'invoicing'), |
|
88 | + esc_attr__('Option Three', 'invoicing') |
|
89 | 89 | ), |
90 | 90 | ) |
91 | 91 | ), |
92 | 92 | |
93 | 93 | array( |
94 | 94 | 'type' => 'checkbox', |
95 | - 'name' => __( 'Checkbox', 'invoicing' ), |
|
95 | + 'name' => __('Checkbox', 'invoicing'), |
|
96 | 96 | 'defaults' => array( |
97 | 97 | 'value' => '', |
98 | - 'label' => __( 'Checkbox Label', 'invoicing' ), |
|
98 | + 'label' => __('Checkbox Label', 'invoicing'), |
|
99 | 99 | 'description' => '', |
100 | 100 | 'required' => false, |
101 | 101 | ) |
@@ -103,23 +103,23 @@ discard block |
||
103 | 103 | |
104 | 104 | array( |
105 | 105 | 'type' => 'radio', |
106 | - 'name' => __( 'Radio', 'invoicing' ), |
|
106 | + 'name' => __('Radio', 'invoicing'), |
|
107 | 107 | 'defaults' => array( |
108 | - 'label' => __( 'Select one choice', 'invoicing' ), |
|
108 | + 'label' => __('Select one choice', 'invoicing'), |
|
109 | 109 | 'options' => array( |
110 | - esc_attr__( 'Choice One', 'invoicing' ), |
|
111 | - esc_attr__( 'Choice Two', 'invoicing' ), |
|
112 | - esc_attr__( 'Choice Three', 'invoicing' ) |
|
110 | + esc_attr__('Choice One', 'invoicing'), |
|
111 | + esc_attr__('Choice Two', 'invoicing'), |
|
112 | + esc_attr__('Choice Three', 'invoicing') |
|
113 | 113 | ), |
114 | 114 | ) |
115 | 115 | ), |
116 | 116 | |
117 | 117 | array( |
118 | 118 | 'type' => 'date', |
119 | - 'name' => __( 'Date', 'invoicing' ), |
|
119 | + 'name' => __('Date', 'invoicing'), |
|
120 | 120 | 'defaults' => array( |
121 | 121 | 'value' => '', |
122 | - 'label' => __( 'Date', 'invoicing' ), |
|
122 | + 'label' => __('Date', 'invoicing'), |
|
123 | 123 | 'description' => '', |
124 | 124 | 'single' => 'single', |
125 | 125 | 'required' => false, |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | |
129 | 129 | array( |
130 | 130 | 'type' => 'time', |
131 | - 'name' => __( 'Time', 'invoicing' ), |
|
131 | + 'name' => __('Time', 'invoicing'), |
|
132 | 132 | 'defaults' => array( |
133 | 133 | 'value' => '', |
134 | - 'label' => __( 'Time', 'invoicing' ), |
|
134 | + 'label' => __('Time', 'invoicing'), |
|
135 | 135 | 'description' => '', |
136 | 136 | 'required' => false, |
137 | 137 | ) |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | |
140 | 140 | array( |
141 | 141 | 'type' => 'number', |
142 | - 'name' => __( 'Number', 'invoicing' ), |
|
142 | + 'name' => __('Number', 'invoicing'), |
|
143 | 143 | 'defaults' => array( |
144 | 144 | 'placeholder' => '', |
145 | 145 | 'value' => '', |
146 | - 'label' => __( 'Number', 'invoicing' ), |
|
146 | + 'label' => __('Number', 'invoicing'), |
|
147 | 147 | 'description' => '', |
148 | 148 | 'required' => false, |
149 | 149 | ) |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | |
152 | 152 | array( |
153 | 153 | 'type' => 'website', |
154 | - 'name' => __( 'Website', 'invoicing' ), |
|
154 | + 'name' => __('Website', 'invoicing'), |
|
155 | 155 | 'defaults' => array( |
156 | 156 | 'placeholder' => 'http://example.com', |
157 | 157 | 'value' => '', |
158 | - 'label' => __( 'Website', 'invoicing' ), |
|
158 | + 'label' => __('Website', 'invoicing'), |
|
159 | 159 | 'description' => '', |
160 | 160 | 'required' => false, |
161 | 161 | ) |
@@ -163,11 +163,11 @@ discard block |
||
163 | 163 | |
164 | 164 | array( |
165 | 165 | 'type' => 'email', |
166 | - 'name' => __( 'Email', 'invoicing' ), |
|
166 | + 'name' => __('Email', 'invoicing'), |
|
167 | 167 | 'defaults' => array( |
168 | 168 | 'placeholder' => '[email protected]', |
169 | 169 | 'value' => '', |
170 | - 'label' => __( 'Email Address', 'invoicing' ), |
|
170 | + 'label' => __('Email Address', 'invoicing'), |
|
171 | 171 | 'description' => '', |
172 | 172 | 'required' => false, |
173 | 173 | ) |
@@ -175,31 +175,31 @@ discard block |
||
175 | 175 | |
176 | 176 | array( |
177 | 177 | 'type' => 'file_upload', |
178 | - 'name' => __( 'File Upload', 'invoicing' ), |
|
178 | + 'name' => __('File Upload', 'invoicing'), |
|
179 | 179 | 'defaults' => array( |
180 | 180 | 'value' => '', |
181 | - 'label' => __( 'Upload File', 'invoicing' ), |
|
181 | + 'label' => __('Upload File', 'invoicing'), |
|
182 | 182 | 'description' => '', |
183 | 183 | 'required' => false, |
184 | 184 | 'max_file_num' => 1, |
185 | - 'file_types' => array( 'jpg|jpeg|jpe', 'gif', 'png' ), |
|
185 | + 'file_types' => array('jpg|jpeg|jpe', 'gif', 'png'), |
|
186 | 186 | ) |
187 | 187 | ), |
188 | 188 | |
189 | 189 | array( |
190 | 190 | 'type' => 'address', |
191 | - 'name' => __( 'Address', 'invoicing' ), |
|
191 | + 'name' => __('Address', 'invoicing'), |
|
192 | 192 | 'defaults' => array( |
193 | 193 | |
194 | 194 | 'address_type' => 'billing', |
195 | - 'billing_address_title' => __( 'Billing Address', 'invoicing' ), |
|
196 | - 'shipping_address_title' => __( 'Shipping Address', 'invoicing' ), |
|
197 | - 'shipping_address_toggle' => __( 'Same billing & shipping address.', 'invoicing' ), |
|
195 | + 'billing_address_title' => __('Billing Address', 'invoicing'), |
|
196 | + 'shipping_address_title' => __('Shipping Address', 'invoicing'), |
|
197 | + 'shipping_address_toggle' => __('Same billing & shipping address.', 'invoicing'), |
|
198 | 198 | 'fields' => array( |
199 | 199 | array( |
200 | 200 | 'placeholder' => 'Jon', |
201 | 201 | 'value' => '', |
202 | - 'label' => __( 'First Name', 'invoicing' ), |
|
202 | + 'label' => __('First Name', 'invoicing'), |
|
203 | 203 | 'description' => '', |
204 | 204 | 'required' => false, |
205 | 205 | 'visible' => true, |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | array( |
211 | 211 | 'placeholder' => 'Snow', |
212 | 212 | 'value' => '', |
213 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
213 | + 'label' => __('Last Name', 'invoicing'), |
|
214 | 214 | 'description' => '', |
215 | 215 | 'required' => false, |
216 | 216 | 'visible' => true, |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | array( |
222 | 222 | 'placeholder' => '', |
223 | 223 | 'value' => '', |
224 | - 'label' => __( 'Address', 'invoicing' ), |
|
224 | + 'label' => __('Address', 'invoicing'), |
|
225 | 225 | 'description' => '', |
226 | 226 | 'required' => false, |
227 | 227 | 'visible' => true, |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | array( |
233 | 233 | 'placeholder' => '', |
234 | 234 | 'value' => '', |
235 | - 'label' => __( 'City', 'invoicing' ), |
|
235 | + 'label' => __('City', 'invoicing'), |
|
236 | 236 | 'description' => '', |
237 | 237 | 'required' => false, |
238 | 238 | 'visible' => true, |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | ), |
242 | 242 | |
243 | 243 | array( |
244 | - 'placeholder' => __( 'Select your country' ), |
|
244 | + 'placeholder' => __('Select your country'), |
|
245 | 245 | 'value' => '', |
246 | - 'label' => __( 'Country', 'invoicing' ), |
|
246 | + 'label' => __('Country', 'invoicing'), |
|
247 | 247 | 'description' => '', |
248 | 248 | 'required' => false, |
249 | 249 | 'visible' => true, |
@@ -252,9 +252,9 @@ discard block |
||
252 | 252 | ), |
253 | 253 | |
254 | 254 | array( |
255 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
255 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
256 | 256 | 'value' => '', |
257 | - 'label' => __( 'State / Province', 'invoicing' ), |
|
257 | + 'label' => __('State / Province', 'invoicing'), |
|
258 | 258 | 'description' => '', |
259 | 259 | 'required' => false, |
260 | 260 | 'visible' => true, |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | array( |
266 | 266 | 'placeholder' => '', |
267 | 267 | 'value' => '', |
268 | - 'label' => __( 'ZIP / Postcode', 'invoicing' ), |
|
268 | + 'label' => __('ZIP / Postcode', 'invoicing'), |
|
269 | 269 | 'description' => '', |
270 | 270 | 'required' => false, |
271 | 271 | 'visible' => true, |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | array( |
277 | 277 | 'placeholder' => '', |
278 | 278 | 'value' => '', |
279 | - 'label' => __( 'Phone', 'invoicing' ), |
|
279 | + 'label' => __('Phone', 'invoicing'), |
|
280 | 280 | 'description' => '', |
281 | 281 | 'required' => false, |
282 | 282 | 'visible' => true, |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | array( |
288 | 288 | 'placeholder' => '', |
289 | 289 | 'value' => '', |
290 | - 'label' => __( 'Company', 'invoicing' ), |
|
290 | + 'label' => __('Company', 'invoicing'), |
|
291 | 291 | 'description' => '', |
292 | 292 | 'required' => false, |
293 | 293 | 'visible' => false, |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | array( |
299 | 299 | 'placeholder' => '', |
300 | 300 | 'value' => '', |
301 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
301 | + 'label' => __('Company ID', 'invoicing'), |
|
302 | 302 | 'description' => '', |
303 | 303 | 'required' => false, |
304 | 304 | 'visible' => false, |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | array( |
310 | 310 | 'placeholder' => '', |
311 | 311 | 'value' => '', |
312 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
312 | + 'label' => __('VAT Number', 'invoicing'), |
|
313 | 313 | 'description' => '', |
314 | 314 | 'required' => false, |
315 | 315 | 'visible' => false, |
@@ -322,11 +322,11 @@ discard block |
||
322 | 322 | |
323 | 323 | array( |
324 | 324 | 'type' => 'billing_email', |
325 | - 'name' => __( 'Billing Email', 'invoicing' ), |
|
325 | + 'name' => __('Billing Email', 'invoicing'), |
|
326 | 326 | 'defaults' => array( |
327 | 327 | 'placeholder' => '[email protected]', |
328 | 328 | 'value' => '', |
329 | - 'label' => __( 'Billing Email', 'invoicing' ), |
|
329 | + 'label' => __('Billing Email', 'invoicing'), |
|
330 | 330 | 'description' => '', |
331 | 331 | 'premade' => true, |
332 | 332 | ) |
@@ -334,18 +334,18 @@ discard block |
||
334 | 334 | |
335 | 335 | array( |
336 | 336 | 'type' => 'discount', |
337 | - 'name' => __( 'Discount Input', 'invoicing' ), |
|
337 | + 'name' => __('Discount Input', 'invoicing'), |
|
338 | 338 | 'defaults' => array( |
339 | 339 | 'value' => '', |
340 | - 'input_label' => __( 'Coupon Code', 'invoicing' ), |
|
341 | - 'button_label' => __( 'Apply Coupon', 'invoicing' ), |
|
342 | - 'description' => __( 'Have a discount code? Enter it above.', 'invoicing' ), |
|
340 | + 'input_label' => __('Coupon Code', 'invoicing'), |
|
341 | + 'button_label' => __('Apply Coupon', 'invoicing'), |
|
342 | + 'description' => __('Have a discount code? Enter it above.', 'invoicing'), |
|
343 | 343 | ) |
344 | 344 | ), |
345 | 345 | |
346 | 346 | array( |
347 | 347 | 'type' => 'items', |
348 | - 'name' => __( 'Items', 'invoicing' ), |
|
348 | + 'name' => __('Items', 'invoicing'), |
|
349 | 349 | 'defaults' => array( |
350 | 350 | 'value' => '', |
351 | 351 | 'items_type' => 'total', |
@@ -357,22 +357,22 @@ discard block |
||
357 | 357 | |
358 | 358 | array( |
359 | 359 | 'type' => 'price_input', |
360 | - 'name' => __( 'Price Input', 'invoicing' ), |
|
360 | + 'name' => __('Price Input', 'invoicing'), |
|
361 | 361 | 'defaults' => array( |
362 | 362 | 'placeholder' => wpinv_format_amount(0), |
363 | 363 | 'value' => wpinv_format_amount(0), |
364 | 364 | 'minimum' => wpinv_format_amount(0), |
365 | - 'label' => __( 'Enter Amount', 'invoicing' ), |
|
365 | + 'label' => __('Enter Amount', 'invoicing'), |
|
366 | 366 | 'description' => '', |
367 | 367 | ) |
368 | 368 | ), |
369 | 369 | |
370 | 370 | array( |
371 | 371 | 'type' => 'price_select', |
372 | - 'name' => __( 'Price Select', 'invoicing' ), |
|
372 | + 'name' => __('Price Select', 'invoicing'), |
|
373 | 373 | 'defaults' => array( |
374 | 374 | 'description' => '', |
375 | - 'label' => __( 'Select Amount', 'invoicing' ), |
|
375 | + 'label' => __('Select Amount', 'invoicing'), |
|
376 | 376 | 'options' => 'Option 1|10, Option 2|20', |
377 | 377 | 'placeholder' => '', |
378 | 378 | 'select_type' => 'select', |
@@ -381,39 +381,39 @@ discard block |
||
381 | 381 | |
382 | 382 | array( |
383 | 383 | 'type' => 'pay_button', |
384 | - 'name' => __( 'Payment Button', 'invoicing' ), |
|
384 | + 'name' => __('Payment Button', 'invoicing'), |
|
385 | 385 | 'defaults' => array( |
386 | 386 | 'value' => '', |
387 | 387 | 'class' => 'btn-primary', |
388 | - 'label' => __( 'Pay %price% »', 'invoicing' ), |
|
389 | - 'free' => __( 'Continue »', 'invoicing' ), |
|
390 | - 'description' => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ), |
|
388 | + 'label' => __('Pay %price% »', 'invoicing'), |
|
389 | + 'free' => __('Continue »', 'invoicing'), |
|
390 | + 'description' => __('By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'), |
|
391 | 391 | 'premade' => true, |
392 | 392 | ) |
393 | 393 | ), |
394 | 394 | |
395 | 395 | array( |
396 | 396 | 'type' => 'gateway_select', |
397 | - 'name' => __( 'Gateway Select', 'invoicing' ), |
|
397 | + 'name' => __('Gateway Select', 'invoicing'), |
|
398 | 398 | 'defaults' => array( |
399 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
399 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
400 | 400 | 'premade' => true, |
401 | 401 | ) |
402 | 402 | ), |
403 | 403 | |
404 | 404 | array( |
405 | 405 | 'type' => 'total_payable', |
406 | - 'name' => __( 'Total Payable', 'invoicing' ), |
|
406 | + 'name' => __('Total Payable', 'invoicing'), |
|
407 | 407 | 'defaults' => array( |
408 | - 'text' => __( 'Total to pay:', 'invoicing' ), |
|
408 | + 'text' => __('Total to pay:', 'invoicing'), |
|
409 | 409 | ) |
410 | 410 | ), |
411 | 411 | |
412 | 412 | array( |
413 | 413 | 'type' => 'ip_address', |
414 | - 'name' => __( 'IP Address', 'invoicing' ), |
|
414 | + 'name' => __('IP Address', 'invoicing'), |
|
415 | 415 | 'defaults' => array( |
416 | - 'text' => __( 'Your IP address is:', 'invoicing' ), |
|
416 | + 'text' => __('Your IP address is:', 'invoicing'), |
|
417 | 417 | ) |
418 | 418 | ) |
419 | 419 | ); |