Passed
Push — master ( 03949c...9a5a12 )
by Brian
11:47 queued 07:40
created
includes/gateways/class-getpaid-paypal-gateway.php 2 patches
Indentation   +350 added lines, -350 removed lines patch added patch discarded remove patch
@@ -13,96 +13,96 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 ) {
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 ) {
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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&section=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&section=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
 }
Please login to merge, or discard this patch.
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
565 565
      * @param array $data
566 566
      * @return string
567 567
 	 */
568
-	public static function maybe_get_connect_url( $url = '', $data ) {
569
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
568
+	public static function maybe_get_connect_url($url = '', $data) {
569
+		return self::get_connect_url(false, urldecode($data['redirect']));
570 570
 	}
571 571
 
572 572
 	/**
@@ -577,25 +577,25 @@  discard block
 block discarded – undo
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( '&amp;', '&', $redirect_url ) )
597
+                'live_mode'    => (int) empty($is_sandbox),
598
+                'redirect_url' => urlencode(str_replace('&amp;', '&', $redirect_url))
599 599
             ),
600 600
             'https://ayecode.io/oauth/paypal'
601 601
         );
@@ -649,26 +649,26 @@  discard block
 block discarded – undo
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
 block discarded – undo
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&section=paypal' ) : urldecode( $data['redirect'] );
705
+		$redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways&section=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
 
Please login to merge, or discard this patch.
includes/class-wpinv.php 2 patches
Indentation   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -14,619 +14,619 @@
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * @var array An array of payment gateways.
40
-	 */
41
-	public $gateways;
42
-
43
-	/**
44
-	 * Class constructor.
45
-	 */
46
-	public function __construct() {
47
-		$this->define_constants();
48
-		$this->includes();
49
-		$this->init_hooks();
50
-		$this->set_properties();
51
-	}
52
-
53
-	/**
54
-	 * Sets a custom data property.
55
-	 *
56
-	 * @param string $prop The prop to set.
57
-	 * @param mixed $value The value to retrieve.
58
-	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
61
-	}
62
-
63
-	/**
64
-	 * Gets a custom data property.
65
-	 *
66
-	 * @param string $prop The prop to set.
67
-	 * @return mixed The value.
68
-	 */
69
-	public function get( $prop ) {
70
-
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
73
-		}
74
-
75
-		return null;
76
-	}
77
-
78
-	/**
79
-	 * Define class properties.
80
-	 */
81
-	public function set_properties() {
82
-
83
-		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
-
88
-		// Init other objects.
89
-		$this->set( 'session', new WPInv_Session_Handler() );
90
-		$this->set( 'notes', new WPInv_Notes() );
91
-		$this->set( 'api', new WPInv_API() );
92
-		$this->set( 'post_types', new GetPaid_Post_Types() );
93
-		$this->set( 'template', new GetPaid_Template() );
94
-		$this->set( 'admin', new GetPaid_Admin() );
95
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
96
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
-
102
-	}
103
-
104
-	 /**
105
-	 * Define plugin constants.
106
-	 */
107
-	public function define_constants() {
108
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
-		$this->version = WPINV_VERSION;
111
-	}
112
-
113
-	/**
114
-	 * Hook into actions and filters.
115
-	 *
116
-	 * @since 1.0.19
117
-	 */
118
-	protected function init_hooks() {
119
-		/* Internationalize the text strings used. */
120
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
-
122
-		// Init the plugin after WordPress inits.
123
-		add_action( 'init', array( $this, 'init' ), 1 );
124
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
126
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
130
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
131
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * @var array An array of payment gateways.
40
+     */
41
+    public $gateways;
42
+
43
+    /**
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47
+        $this->define_constants();
48
+        $this->includes();
49
+        $this->init_hooks();
50
+        $this->set_properties();
51
+    }
52
+
53
+    /**
54
+     * Sets a custom data property.
55
+     *
56
+     * @param string $prop The prop to set.
57
+     * @param mixed $value The value to retrieve.
58
+     */
59
+    public function set( $prop, $value ) {
60
+        $this->data[ $prop ] = $value;
61
+    }
62
+
63
+    /**
64
+     * Gets a custom data property.
65
+     *
66
+     * @param string $prop The prop to set.
67
+     * @return mixed The value.
68
+     */
69
+    public function get( $prop ) {
70
+
71
+        if ( isset( $this->data[ $prop ] ) ) {
72
+            return $this->data[ $prop ];
73
+        }
74
+
75
+        return null;
76
+    }
77
+
78
+    /**
79
+     * Define class properties.
80
+     */
81
+    public function set_properties() {
82
+
83
+        // Sessions.
84
+        $this->set( 'session', new WPInv_Session_Handler() );
85
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
+
88
+        // Init other objects.
89
+        $this->set( 'session', new WPInv_Session_Handler() );
90
+        $this->set( 'notes', new WPInv_Notes() );
91
+        $this->set( 'api', new WPInv_API() );
92
+        $this->set( 'post_types', new GetPaid_Post_Types() );
93
+        $this->set( 'template', new GetPaid_Template() );
94
+        $this->set( 'admin', new GetPaid_Admin() );
95
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
96
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
+
102
+    }
103
+
104
+        /**
105
+         * Define plugin constants.
106
+         */
107
+    public function define_constants() {
108
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
+        $this->version = WPINV_VERSION;
111
+    }
112
+
113
+    /**
114
+     * Hook into actions and filters.
115
+     *
116
+     * @since 1.0.19
117
+     */
118
+    protected function init_hooks() {
119
+        /* Internationalize the text strings used. */
120
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
+
122
+        // Init the plugin after WordPress inits.
123
+        add_action( 'init', array( $this, 'init' ), 1 );
124
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
126
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
130
+        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
131
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
+
134
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135 135
         add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
-
138
-		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
141
-
142
-	}
143
-
144
-	public function plugins_loaded() {
145
-		/* Internationalize the text strings used. */
146
-		$this->load_textdomain();
147
-
148
-		do_action( 'wpinv_loaded' );
149
-
150
-		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
152
-			wpinv_oxygen_fix_conflict();
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Load Localisation files.
158
-	 *
159
-	 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
160
-	 *
161
-	 * Locales found in:
162
-	 *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
163
-	 *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
164
-	 *
165
-	 * @since 1.0.0
166
-	 */
167
-	public function load_textdomain() {
168
-
169
-		load_plugin_textdomain(
170
-			'invoicing',
171
-			false,
172
-			plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
173
-		);
174
-
175
-	}
176
-
177
-	/**
178
-	 * Include required core files used in admin and on the frontend.
179
-	 */
180
-	public function includes() {
181
-
182
-		// Start with the settings.
183
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
184
-
185
-		// Packages/libraries.
186
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
187
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
188
-
189
-		// Load functions.
190
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
191
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
194
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
205
-
206
-		// Register autoloader.
207
-		try {
208
-			spl_autoload_register( array( $this, 'autoload' ), true );
209
-		} catch ( Exception $e ) {
210
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
211
-		}
212
-
213
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
215
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
216
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
234
-
235
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
236
-			GetPaid_Post_Types_Admin::init();
237
-
238
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
239
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
240
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
241
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
242
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
243
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
244
-			// load the user class only on the users.php page
245
-			global $pagenow;
246
-			if($pagenow=='users.php'){
247
-				new WPInv_Admin_Users();
248
-			}
249
-		}
250
-
251
-		// Register cli commands
252
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
253
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
254
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
255
-		}
256
-
257
-	}
258
-
259
-	/**
260
-	 * Class autoloader
261
-	 *
262
-	 * @param       string $class_name The name of the class to load.
263
-	 * @access      public
264
-	 * @since       1.0.19
265
-	 * @return      void
266
-	 */
267
-	public function autoload( $class_name ) {
268
-
269
-		// Normalize the class name...
270
-		$class_name  = strtolower( $class_name );
271
-
272
-		// ... and make sure it is our class.
273
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
274
-			return;
275
-		}
276
-
277
-		// Next, prepare the file name from the class.
278
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
279
-
280
-		// Base path of the classes.
281
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
282
-
283
-		// And an array of possible locations in order of importance.
284
-		$locations = array(
285
-			"$plugin_path/includes",
286
-			"$plugin_path/includes/data-stores",
287
-			"$plugin_path/includes/gateways",
288
-			"$plugin_path/includes/payments",
289
-			"$plugin_path/includes/geolocation",
290
-			"$plugin_path/includes/reports",
291
-			"$plugin_path/includes/api",
292
-			"$plugin_path/includes/admin",
293
-			"$plugin_path/includes/admin/meta-boxes",
294
-		);
295
-
296
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
297
-
298
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
299
-				include trailingslashit( $location ) . $file_name;
300
-				break;
301
-			}
302
-
303
-		}
304
-
305
-	}
306
-
307
-	/**
308
-	 * Inits hooks etc.
309
-	 */
310
-	public function init() {
311
-
312
-		// Fires before getpaid inits.
313
-		do_action( 'before_getpaid_init', $this );
314
-
315
-		// Maybe upgrade.
316
-		$this->maybe_upgrade_database();
317
-
318
-		// Load default gateways.
319
-		$gateways = apply_filters(
320
-			'getpaid_default_gateways',
321
-			array(
322
-				'manual'        => 'GetPaid_Manual_Gateway',
323
-				'paypal'        => 'GetPaid_Paypal_Gateway',
324
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
-			)
328
-		);
329
-
330
-		foreach ( $gateways as $id => $class ) {
331
-			$this->gateways[ $id ] = new $class();
332
-		}
333
-
334
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
-			GetPaid_Installer::rename_gateways_label();
336
-			update_option( 'wpinv_renamed_gateways', 'yes' );
337
-		}
338
-
339
-		// Fires after getpaid inits.
340
-		do_action( 'getpaid_init', $this );
341
-
342
-	}
343
-
344
-	/**
345
-	 * Checks if this is an IPN request and processes it.
346
-	 */
347
-	public function maybe_process_ipn() {
348
-
349
-		// Ensure that this is an IPN request.
350
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
-			return;
352
-		}
353
-
354
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
355
-
356
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
357
-		do_action( "wpinv_verify_{$gateway}_ipn" );
358
-		exit;
359
-
360
-	}
361
-
362
-	public function enqueue_scripts() {
363
-
364
-		// Fires before adding scripts.
365
-		do_action( 'getpaid_enqueue_scripts' );
366
-
367
-		$localize                         = array();
368
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
369
-		$localize['thousands']            = wpinv_thousands_separator();
370
-		$localize['decimals']             = wpinv_decimal_separator();
371
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
-		$localize['UseTaxes']             = wpinv_use_taxes();
374
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
376
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
-
378
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
379
-
380
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
381
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
382
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
383
-	}
384
-
385
-	public function wpinv_actions() {
386
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
387
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
388
-		}
389
-
390
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
391
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
392
-		}
393
-	}
136
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
137
+
138
+        // Fires after registering actions.
139
+        do_action( 'wpinv_actions', $this );
140
+        do_action( 'getpaid_actions', $this );
141
+
142
+    }
143
+
144
+    public function plugins_loaded() {
145
+        /* Internationalize the text strings used. */
146
+        $this->load_textdomain();
147
+
148
+        do_action( 'wpinv_loaded' );
149
+
150
+        // Fix oxygen page builder conflict
151
+        if ( function_exists( 'ct_css_output' ) ) {
152
+            wpinv_oxygen_fix_conflict();
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Load Localisation files.
158
+     *
159
+     * Note: the first-loaded translation file overrides any following ones if the same translation is present.
160
+     *
161
+     * Locales found in:
162
+     *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
163
+     *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
164
+     *
165
+     * @since 1.0.0
166
+     */
167
+    public function load_textdomain() {
168
+
169
+        load_plugin_textdomain(
170
+            'invoicing',
171
+            false,
172
+            plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
173
+        );
174
+
175
+    }
176
+
177
+    /**
178
+     * Include required core files used in admin and on the frontend.
179
+     */
180
+    public function includes() {
181
+
182
+        // Start with the settings.
183
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
184
+
185
+        // Packages/libraries.
186
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
187
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
188
+
189
+        // Load functions.
190
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
191
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
192
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
193
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
194
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
195
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
196
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
197
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
198
+        require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
199
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
200
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
202
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
203
+        require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
204
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
205
+
206
+        // Register autoloader.
207
+        try {
208
+            spl_autoload_register( array( $this, 'autoload' ), true );
209
+        } catch ( Exception $e ) {
210
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
211
+        }
212
+
213
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
214
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
215
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
216
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
217
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
218
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
219
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
220
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
221
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
222
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
223
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
224
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
225
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
226
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
231
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
232
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
233
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
234
+
235
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
236
+            GetPaid_Post_Types_Admin::init();
237
+
238
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
239
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
240
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
241
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
242
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
243
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
244
+            // load the user class only on the users.php page
245
+            global $pagenow;
246
+            if($pagenow=='users.php'){
247
+                new WPInv_Admin_Users();
248
+            }
249
+        }
250
+
251
+        // Register cli commands
252
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
253
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
254
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
255
+        }
256
+
257
+    }
258
+
259
+    /**
260
+     * Class autoloader
261
+     *
262
+     * @param       string $class_name The name of the class to load.
263
+     * @access      public
264
+     * @since       1.0.19
265
+     * @return      void
266
+     */
267
+    public function autoload( $class_name ) {
268
+
269
+        // Normalize the class name...
270
+        $class_name  = strtolower( $class_name );
271
+
272
+        // ... and make sure it is our class.
273
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
274
+            return;
275
+        }
276
+
277
+        // Next, prepare the file name from the class.
278
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
279
+
280
+        // Base path of the classes.
281
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
282
+
283
+        // And an array of possible locations in order of importance.
284
+        $locations = array(
285
+            "$plugin_path/includes",
286
+            "$plugin_path/includes/data-stores",
287
+            "$plugin_path/includes/gateways",
288
+            "$plugin_path/includes/payments",
289
+            "$plugin_path/includes/geolocation",
290
+            "$plugin_path/includes/reports",
291
+            "$plugin_path/includes/api",
292
+            "$plugin_path/includes/admin",
293
+            "$plugin_path/includes/admin/meta-boxes",
294
+        );
295
+
296
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
297
+
298
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
299
+                include trailingslashit( $location ) . $file_name;
300
+                break;
301
+            }
302
+
303
+        }
304
+
305
+    }
306
+
307
+    /**
308
+     * Inits hooks etc.
309
+     */
310
+    public function init() {
311
+
312
+        // Fires before getpaid inits.
313
+        do_action( 'before_getpaid_init', $this );
314
+
315
+        // Maybe upgrade.
316
+        $this->maybe_upgrade_database();
317
+
318
+        // Load default gateways.
319
+        $gateways = apply_filters(
320
+            'getpaid_default_gateways',
321
+            array(
322
+                'manual'        => 'GetPaid_Manual_Gateway',
323
+                'paypal'        => 'GetPaid_Paypal_Gateway',
324
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
325
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
326
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
327
+            )
328
+        );
329
+
330
+        foreach ( $gateways as $id => $class ) {
331
+            $this->gateways[ $id ] = new $class();
332
+        }
333
+
334
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
+            GetPaid_Installer::rename_gateways_label();
336
+            update_option( 'wpinv_renamed_gateways', 'yes' );
337
+        }
338
+
339
+        // Fires after getpaid inits.
340
+        do_action( 'getpaid_init', $this );
394 341
 
395
-	/**
342
+    }
343
+
344
+    /**
345
+     * Checks if this is an IPN request and processes it.
346
+     */
347
+    public function maybe_process_ipn() {
348
+
349
+        // Ensure that this is an IPN request.
350
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
351
+            return;
352
+        }
353
+
354
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
355
+
356
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
357
+        do_action( "wpinv_verify_{$gateway}_ipn" );
358
+        exit;
359
+
360
+    }
361
+
362
+    public function enqueue_scripts() {
363
+
364
+        // Fires before adding scripts.
365
+        do_action( 'getpaid_enqueue_scripts' );
366
+
367
+        $localize                         = array();
368
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
369
+        $localize['thousands']            = wpinv_thousands_separator();
370
+        $localize['decimals']             = wpinv_decimal_separator();
371
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
+        $localize['UseTaxes']             = wpinv_use_taxes();
374
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
376
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
+
378
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
379
+
380
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
381
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
382
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
383
+    }
384
+
385
+    public function wpinv_actions() {
386
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
387
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
388
+        }
389
+
390
+        if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
391
+            include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
392
+        }
393
+    }
394
+
395
+    /**
396 396
      * Fires an action after verifying that a user can fire them.
397
-	 *
398
-	 * Note: If the action is on an invoice, subscription etc, esure that the
399
-	 * current user owns the invoice/subscription.
397
+     *
398
+     * Note: If the action is on an invoice, subscription etc, esure that the
399
+     * current user owns the invoice/subscription.
400 400
      */
401 401
     public function maybe_do_authenticated_action() {
402 402
 
403
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
403
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
404
+
405
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
406
+            $data = wp_unslash( $_REQUEST );
407
+            if ( is_user_logged_in() ) {
408
+                do_action( "getpaid_authenticated_action_$key", $data );
409
+            }
410
+
411
+            do_action( "getpaid_unauthenticated_action_$key", $data );
412
+
413
+        }
414
+
415
+    }
416
+
417
+    public function pre_get_posts( $wp_query ) {
418
+
419
+        if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
420
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
421
+        }
422
+
423
+        return $wp_query;
424
+    }
425
+
426
+    /**
427
+     * Register widgets
428
+     *
429
+     */
430
+    public function register_widgets() {
431
+        global $pagenow;
432
+
433
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
434
+        // So we disable our widgets when editing a page with UX Builder.
435
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
436
+            return;
437
+        }
438
+
439
+        $block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array();
440
+
441
+        if ( is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) {
442
+            // don't initiate in these conditions.
443
+        }else{
444
+
445
+            // Only load allowed widgets.
446
+            $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
447
+            $widgets = apply_filters(
448
+                'getpaid_widget_classes',
449
+                array(
450
+                    'WPInv_Checkout_Widget',
451
+                    'WPInv_History_Widget',
452
+                    'WPInv_Receipt_Widget',
453
+                    'WPInv_Subscriptions_Widget',
454
+                    'WPInv_Buy_Item_Widget',
455
+                    'WPInv_Messages_Widget',
456
+                    'WPInv_GetPaid_Widget'
457
+                )
458
+            );
459
+
460
+            // For each widget...
461
+            foreach ( $widgets as $widget ) {
462
+
463
+                // Abort early if it is excluded for this page.
464
+                if ( in_array( $widget, $exclude ) ) {
465
+                    continue;
466
+                }
467
+
468
+                // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
469
+                if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
470
+                    register_widget( $widget );
471
+                } else {
472
+                    new $widget();
473
+                }
474
+
475
+            }
476
+
477
+        }
478
+
479
+    }
480
+
481
+    /**
482
+     * Upgrades the database.
483
+     *
484
+     * @since 2.0.2
485
+     */
486
+    public function maybe_upgrade_database() {
404 487
 
405
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
406
-			$data = wp_unslash( $_REQUEST );
407
-			if ( is_user_logged_in() ) {
408
-				do_action( "getpaid_authenticated_action_$key", $data );
409
-			}
488
+        $wpi_version = get_option( 'wpinv_version', 0 );
410 489
 
411
-			do_action( "getpaid_unauthenticated_action_$key", $data );
490
+        if ( $wpi_version == WPINV_VERSION ) {
491
+            return;
492
+        }
412 493
 
413
-		}
494
+        $installer = new GetPaid_Installer();
495
+
496
+        if ( empty( $wpi_version ) ) {
497
+            return $installer->upgrade_db( 0 );
498
+        }
499
+
500
+        $upgrades  = array(
501
+            '0.0.5' => '004',
502
+            '1.0.3' => '102',
503
+            '2.0.0' => '118',
504
+            '2.0.8' => '207',
505
+        );
506
+
507
+        foreach ( $upgrades as $key => $method ) {
508
+
509
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
510
+                return $installer->upgrade_db( $method );
511
+            }
512
+
513
+        }
414 514
 
415 515
     }
416 516
 
417
-	public function pre_get_posts( $wp_query ) {
517
+    /**
518
+     * Flushes the permalinks if needed.
519
+     *
520
+     * @since 2.0.8
521
+     */
522
+    public function maybe_flush_permalinks() {
418 523
 
419
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
420
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
421
-		}
422
-
423
-		return $wp_query;
424
-	}
524
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
425 525
 
426
-	/**
427
-	 * Register widgets
428
-	 *
429
-	 */
430
-	public function register_widgets() {
431
-		global $pagenow;
526
+        if ( ! empty( $flush ) ) {
527
+            flush_rewrite_rules();
528
+            delete_option( 'wpinv_flush_permalinks' );
529
+        }
432 530
 
433
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
434
-		// So we disable our widgets when editing a page with UX Builder.
435
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
436
-			return;
437
-		}
438
-
439
-		$block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array();
440
-
441
-		if ( is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) {
442
-			// don't initiate in these conditions.
443
-		}else{
444
-
445
-			// Only load allowed widgets.
446
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
447
-			$widgets = apply_filters(
448
-				'getpaid_widget_classes',
449
-				array(
450
-					'WPInv_Checkout_Widget',
451
-					'WPInv_History_Widget',
452
-					'WPInv_Receipt_Widget',
453
-					'WPInv_Subscriptions_Widget',
454
-					'WPInv_Buy_Item_Widget',
455
-					'WPInv_Messages_Widget',
456
-					'WPInv_GetPaid_Widget'
457
-				)
458
-			);
459
-
460
-			// For each widget...
461
-			foreach ( $widgets as $widget ) {
531
+    }
462 532
 
463
-				// Abort early if it is excluded for this page.
464
-				if ( in_array( $widget, $exclude ) ) {
465
-					continue;
466
-				}
533
+    /**
534
+     * Remove our pages from yoast sitemaps.
535
+     *
536
+     * @since 1.0.19
537
+     * @param int[] $excluded_posts_ids
538
+     */
539
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
467 540
 
468
-				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
469
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
470
-					register_widget( $widget );
471
-				} else {
472
-					new $widget();
473
-				}
541
+        // Ensure that we have an array.
542
+        if ( ! is_array( $excluded_posts_ids ) ) {
543
+            $excluded_posts_ids = array();
544
+        }
474 545
 
475
-			}
546
+        // Prepare our pages.
547
+        $our_pages = array();
476 548
 
477
-		}
549
+        // Checkout page.
550
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
478 551
 
479
-	}
552
+        // Success page.
553
+        $our_pages[] = wpinv_get_option( 'success_page', false );
480 554
 
481
-	/**
482
-	 * Upgrades the database.
483
-	 *
484
-	 * @since 2.0.2
485
-	 */
486
-	public function maybe_upgrade_database() {
487
-
488
-		$wpi_version = get_option( 'wpinv_version', 0 );
489
-
490
-		if ( $wpi_version == WPINV_VERSION ) {
491
-			return;
492
-		}
493
-
494
-		$installer = new GetPaid_Installer();
495
-
496
-		if ( empty( $wpi_version ) ) {
497
-			return $installer->upgrade_db( 0 );
498
-		}
499
-
500
-		$upgrades  = array(
501
-			'0.0.5' => '004',
502
-			'1.0.3' => '102',
503
-			'2.0.0' => '118',
504
-			'2.0.8' => '207',
505
-		);
506
-
507
-		foreach ( $upgrades as $key => $method ) {
508
-
509
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
510
-				return $installer->upgrade_db( $method );
511
-			}
512
-
513
-		}
514
-
515
-	}
516
-
517
-	/**
518
-	 * Flushes the permalinks if needed.
519
-	 *
520
-	 * @since 2.0.8
521
-	 */
522
-	public function maybe_flush_permalinks() {
523
-
524
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
525
-
526
-		if ( ! empty( $flush ) ) {
527
-			flush_rewrite_rules();
528
-			delete_option( 'wpinv_flush_permalinks' );
529
-		}
530
-
531
-	}
532
-
533
-	/**
534
-	 * Remove our pages from yoast sitemaps.
535
-	 *
536
-	 * @since 1.0.19
537
-	 * @param int[] $excluded_posts_ids
538
-	 */
539
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
540
-
541
-		// Ensure that we have an array.
542
-		if ( ! is_array( $excluded_posts_ids ) ) {
543
-			$excluded_posts_ids = array();
544
-		}
545
-
546
-		// Prepare our pages.
547
-		$our_pages = array();
548
-
549
-		// Checkout page.
550
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
551
-
552
-		// Success page.
553
-		$our_pages[] = wpinv_get_option( 'success_page', false );
554
-
555
-		// Failure page.
556
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
555
+        // Failure page.
556
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
557 557
 
558
-		// History page.
559
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
558
+        // History page.
559
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
560 560
 
561
-		// Subscriptions page.
562
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
561
+        // Subscriptions page.
562
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
563 563
 
564
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
564
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
565 565
 
566
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
567
-		return array_unique( $excluded_posts_ids );
566
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
567
+        return array_unique( $excluded_posts_ids );
568 568
 
569
-	}
569
+    }
570 570
 
571
-	/**
572
-	 * Displays additional footer code.
573
-	 *
574
-	 * @since 2.0.0
575
-	 */
576
-	public function wp_footer() {
577
-		wpinv_get_template( 'frontend-footer.php' );
578
-	}
571
+    /**
572
+     * Displays additional footer code.
573
+     *
574
+     * @since 2.0.0
575
+     */
576
+    public function wp_footer() {
577
+        wpinv_get_template( 'frontend-footer.php' );
578
+    }
579 579
 
580
-	/**
581
-	 * Displays additional header code.
582
-	 *
583
-	 * @since 2.0.0
584
-	 */
585
-	public function wp_head() {
586
-		wpinv_get_template( 'frontend-head.php' );
587
-	}
580
+    /**
581
+     * Displays additional header code.
582
+     *
583
+     * @since 2.0.0
584
+     */
585
+    public function wp_head() {
586
+        wpinv_get_template( 'frontend-head.php' );
587
+    }
588 588
 
589
-	/**
590
-	 * Custom query vars.
591
-	 *
592
-	 */
593
-	public function custom_query_vars( $vars ) {
589
+    /**
590
+     * Custom query vars.
591
+     *
592
+     */
593
+    public function custom_query_vars( $vars ) {
594 594
         $vars[] = 'getpaid-ipn';
595 595
         return $vars;
596
-	}
596
+    }
597 597
 
598
-	/**
599
-	 * Add rewrite tags and rules.
600
-	 *
601
-	 */
602
-	public function add_rewrite_rule() {
598
+    /**
599
+     * Add rewrite tags and rules.
600
+     *
601
+     */
602
+    public function add_rewrite_rule() {
603 603
         $tag = 'getpaid-ipn';
604 604
         add_rewrite_tag( "%$tag%", '([^&]+)' );
605 605
         add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' );
606
-	}
606
+    }
607 607
 
608
-	/**
609
-	 * Processes non-query string ipns.
610
-	 *
611
-	 */
612
-	public function maybe_process_new_ipn( $query ) {
608
+    /**
609
+     * Processes non-query string ipns.
610
+     *
611
+     */
612
+    public function maybe_process_new_ipn( $query ) {
613 613
 
614 614
         if ( is_admin() || ! $query->is_main_query() ) {
615 615
             return;
616 616
         }
617 617
 
618
-		$gateway = get_query_var( 'getpaid-ipn' );
618
+        $gateway = get_query_var( 'getpaid-ipn' );
619 619
 
620 620
         if ( ! empty( $gateway ) ){
621 621
 
622
-			$gateway = sanitize_text_field( $gateway );
623
-			nocache_headers();
624
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
625
-			do_action( "wpinv_verify_{$gateway}_ipn" );
626
-			exit;
622
+            $gateway = sanitize_text_field( $gateway );
623
+            nocache_headers();
624
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
625
+            do_action( "wpinv_verify_{$gateway}_ipn" );
626
+            exit;
627 627
 
628 628
         }
629 629
 
630
-	}
630
+    }
631 631
 
632 632
 }
Please login to merge, or discard this patch.
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Main Invoicing class.
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param string $prop The prop to set.
57 57
 	 * @param mixed $value The value to retrieve.
58 58
 	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
59
+	public function set($prop, $value) {
60
+		$this->data[$prop] = $value;
61 61
 	}
62 62
 
63 63
 	/**
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 	 * @param string $prop The prop to set.
67 67
 	 * @return mixed The value.
68 68
 	 */
69
-	public function get( $prop ) {
69
+	public function get($prop) {
70 70
 
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
71
+		if (isset($this->data[$prop])) {
72
+			return $this->data[$prop];
73 73
 		}
74 74
 
75 75
 		return null;
@@ -81,23 +81,23 @@  discard block
 block discarded – undo
81 81
 	public function set_properties() {
82 82
 
83 83
 		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
+		$this->set('session', new WPInv_Session_Handler());
85
+		$GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility.
86 86
 		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87 87
 
88 88
 		// Init other objects.
89
-		$this->set( 'session', new WPInv_Session_Handler() );
90
-		$this->set( 'notes', new WPInv_Notes() );
91
-		$this->set( 'api', new WPInv_API() );
92
-		$this->set( 'post_types', new GetPaid_Post_Types() );
93
-		$this->set( 'template', new GetPaid_Template() );
94
-		$this->set( 'admin', new GetPaid_Admin() );
95
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
96
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
89
+		$this->set('session', new WPInv_Session_Handler());
90
+		$this->set('notes', new WPInv_Notes());
91
+		$this->set('api', new WPInv_API());
92
+		$this->set('post_types', new GetPaid_Post_Types());
93
+		$this->set('template', new GetPaid_Template());
94
+		$this->set('admin', new GetPaid_Admin());
95
+		$this->set('subscriptions', new WPInv_Subscriptions());
96
+		$this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails());
97
+		$this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails());
98
+		$this->set('daily_maintenace', new GetPaid_Daily_Maintenance());
99
+		$this->set('payment_forms', new GetPaid_Payment_Forms());
100
+		$this->set('maxmind', new GetPaid_MaxMind_Geolocation());
101 101
 
102 102
 	}
103 103
 
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 	 * Define plugin constants.
106 106
 	 */
107 107
 	public function define_constants() {
108
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
108
+		define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
109
+		define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
110 110
 		$this->version = WPINV_VERSION;
111 111
 	}
112 112
 
@@ -117,27 +117,27 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	protected function init_hooks() {
119 119
 		/* Internationalize the text strings used. */
120
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
120
+		add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
121 121
 
122 122
 		// Init the plugin after WordPress inits.
123
-		add_action( 'init', array( $this, 'init' ), 1 );
124
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
126
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
130
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
131
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
135
-        add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
136
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
123
+		add_action('init', array($this, 'init'), 1);
124
+		add_action('init', array($this, 'maybe_process_ipn'), 10);
125
+		add_action('init', array($this, 'wpinv_actions'));
126
+		add_action('init', array($this, 'maybe_do_authenticated_action'), 100);
127
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11);
128
+		add_action('wp_footer', array($this, 'wp_footer'));
129
+		add_action('wp_head', array($this, 'wp_head'));
130
+		add_action('widgets_init', array($this, 'register_widgets'));
131
+		add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
132
+		add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
133
+
134
+		add_filter('query_vars', array($this, 'custom_query_vars'));
135
+        add_action('init', array($this, 'add_rewrite_rule'), 10, 0);
136
+		add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1);
137 137
 
138 138
 		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
139
+		do_action('wpinv_actions', $this);
140
+		do_action('getpaid_actions', $this);
141 141
 
142 142
 	}
143 143
 
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
 		/* Internationalize the text strings used. */
146 146
 		$this->load_textdomain();
147 147
 
148
-		do_action( 'wpinv_loaded' );
148
+		do_action('wpinv_loaded');
149 149
 
150 150
 		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
151
+		if (function_exists('ct_css_output')) {
152 152
 			wpinv_oxygen_fix_conflict();
153 153
 		}
154 154
 	}
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 		load_plugin_textdomain(
170 170
 			'invoicing',
171 171
 			false,
172
-			plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/'
172
+			plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/'
173 173
 		);
174 174
 
175 175
 	}
@@ -180,78 +180,78 @@  discard block
 block discarded – undo
180 180
 	public function includes() {
181 181
 
182 182
 		// Start with the settings.
183
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
183
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
184 184
 
185 185
 		// Packages/libraries.
186
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
187
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
186
+		require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
187
+		require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php');
188 188
 
189 189
 		// Load functions.
190
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
191
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
194
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
190
+		require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php');
191
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
192
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
193
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
194
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
195
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
196
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
197
+		require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php');
198
+		require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php');
199
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
200
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
201
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
202
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
203
+		require_once(WPINV_PLUGIN_DIR . 'includes/user-functions.php');
204
+		require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php');
205 205
 
206 206
 		// Register autoloader.
207 207
 		try {
208
-			spl_autoload_register( array( $this, 'autoload' ), true );
209
-		} catch ( Exception $e ) {
210
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
208
+			spl_autoload_register(array($this, 'autoload'), true);
209
+		} catch (Exception $e) {
210
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
211 211
 		}
212 212
 
213
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
215
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
216
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
234
-
235
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
213
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
214
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
215
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
216
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
217
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
218
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
219
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
220
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
221
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
222
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
223
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
224
+		require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
225
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
226
+		require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
227
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
228
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
229
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
230
+		require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
231
+		require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
232
+		require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php');
233
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
234
+
235
+		if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
236 236
 			GetPaid_Post_Types_Admin::init();
237 237
 
238
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
239
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
240
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
241
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
242
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
243
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
238
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
239
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
240
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
241
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
242
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
243
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php');
244 244
 			// load the user class only on the users.php page
245 245
 			global $pagenow;
246
-			if($pagenow=='users.php'){
246
+			if ($pagenow == 'users.php') {
247 247
 				new WPInv_Admin_Users();
248 248
 			}
249 249
 		}
250 250
 
251 251
 		// Register cli commands
252
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
253
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
254
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
252
+		if (defined('WP_CLI') && WP_CLI) {
253
+			require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
254
+			WP_CLI::add_command('invoicing', 'WPInv_CLI');
255 255
 		}
256 256
 
257 257
 	}
@@ -264,21 +264,21 @@  discard block
 block discarded – undo
264 264
 	 * @since       1.0.19
265 265
 	 * @return      void
266 266
 	 */
267
-	public function autoload( $class_name ) {
267
+	public function autoload($class_name) {
268 268
 
269 269
 		// Normalize the class name...
270
-		$class_name  = strtolower( $class_name );
270
+		$class_name = strtolower($class_name);
271 271
 
272 272
 		// ... and make sure it is our class.
273
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
273
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
274 274
 			return;
275 275
 		}
276 276
 
277 277
 		// Next, prepare the file name from the class.
278
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
278
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
279 279
 
280 280
 		// Base path of the classes.
281
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
281
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
282 282
 
283 283
 		// And an array of possible locations in order of importance.
284 284
 		$locations = array(
@@ -293,10 +293,10 @@  discard block
 block discarded – undo
293 293
 			"$plugin_path/includes/admin/meta-boxes",
294 294
 		);
295 295
 
296
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
296
+		foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) {
297 297
 
298
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
299
-				include trailingslashit( $location ) . $file_name;
298
+			if (file_exists(trailingslashit($location) . $file_name)) {
299
+				include trailingslashit($location) . $file_name;
300 300
 				break;
301 301
 			}
302 302
 
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	public function init() {
311 311
 
312 312
 		// Fires before getpaid inits.
313
-		do_action( 'before_getpaid_init', $this );
313
+		do_action('before_getpaid_init', $this);
314 314
 
315 315
 		// Maybe upgrade.
316 316
 		$this->maybe_upgrade_database();
@@ -327,17 +327,17 @@  discard block
 block discarded – undo
327 327
 			)
328 328
 		);
329 329
 
330
-		foreach ( $gateways as $id => $class ) {
331
-			$this->gateways[ $id ] = new $class();
330
+		foreach ($gateways as $id => $class) {
331
+			$this->gateways[$id] = new $class();
332 332
 		}
333 333
 
334
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
334
+		if ('yes' != get_option('wpinv_renamed_gateways')) {
335 335
 			GetPaid_Installer::rename_gateways_label();
336
-			update_option( 'wpinv_renamed_gateways', 'yes' );
336
+			update_option('wpinv_renamed_gateways', 'yes');
337 337
 		}
338 338
 
339 339
 		// Fires after getpaid inits.
340
-		do_action( 'getpaid_init', $this );
340
+		do_action('getpaid_init', $this);
341 341
 
342 342
 	}
343 343
 
@@ -347,14 +347,14 @@  discard block
 block discarded – undo
347 347
 	public function maybe_process_ipn() {
348 348
 
349 349
 		// Ensure that this is an IPN request.
350
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
350
+		if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) {
351 351
 			return;
352 352
 		}
353 353
 
354
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
354
+		$gateway = wpinv_clean($_GET['wpi-gateway']);
355 355
 
356
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
357
-		do_action( "wpinv_verify_{$gateway}_ipn" );
356
+		do_action('wpinv_verify_payment_ipn', $gateway);
357
+		do_action("wpinv_verify_{$gateway}_ipn");
358 358
 		exit;
359 359
 
360 360
 	}
@@ -362,33 +362,33 @@  discard block
 block discarded – undo
362 362
 	public function enqueue_scripts() {
363 363
 
364 364
 		// Fires before adding scripts.
365
-		do_action( 'getpaid_enqueue_scripts' );
365
+		do_action('getpaid_enqueue_scripts');
366 366
 
367 367
 		$localize                         = array();
368
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
368
+		$localize['ajax_url']             = admin_url('admin-ajax.php');
369 369
 		$localize['thousands']            = wpinv_thousands_separator();
370 370
 		$localize['decimals']             = wpinv_decimal_separator();
371
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
371
+		$localize['nonce']                = wp_create_nonce('wpinv-nonce');
372
+		$localize['txtComplete']          = __('Continue', 'invoicing');
373 373
 		$localize['UseTaxes']             = wpinv_use_taxes();
374
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
375
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
376
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
374
+		$localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
375
+		$localize['loading']              = __('Loading...', 'invoicing');
376
+		$localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
377 377
 
378
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
378
+		$localize = apply_filters('wpinv_front_js_localize', $localize);
379 379
 
380
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
381
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
382
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
380
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
381
+		wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true);
382
+		wp_localize_script('wpinv-front-script', 'WPInv', $localize);
383 383
 	}
384 384
 
385 385
 	public function wpinv_actions() {
386
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
387
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
386
+		if (isset($_REQUEST['wpi_action'])) {
387
+			do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
388 388
 		}
389 389
 
390
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
391
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
390
+		if (defined('WP_ALL_IMPORT_ROOT_DIR')) {
391
+			include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
392 392
 		}
393 393
 	}
394 394
 
@@ -400,24 +400,24 @@  discard block
 block discarded – undo
400 400
      */
401 401
     public function maybe_do_authenticated_action() {
402 402
 
403
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
403
+		if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
404 404
 
405
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
406
-			$data = wp_unslash( $_REQUEST );
407
-			if ( is_user_logged_in() ) {
408
-				do_action( "getpaid_authenticated_action_$key", $data );
405
+			$key  = sanitize_key($_REQUEST['getpaid-action']);
406
+			$data = wp_unslash($_REQUEST);
407
+			if (is_user_logged_in()) {
408
+				do_action("getpaid_authenticated_action_$key", $data);
409 409
 			}
410 410
 
411
-			do_action( "getpaid_unauthenticated_action_$key", $data );
411
+			do_action("getpaid_unauthenticated_action_$key", $data);
412 412
 
413 413
 		}
414 414
 
415 415
     }
416 416
 
417
-	public function pre_get_posts( $wp_query ) {
417
+	public function pre_get_posts($wp_query) {
418 418
 
419
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
420
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
419
+		if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
420
+			$wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type']));
421 421
 		}
422 422
 
423 423
 		return $wp_query;
@@ -432,18 +432,18 @@  discard block
 block discarded – undo
432 432
 
433 433
 		// Currently, UX Builder does not work particulaly well with SuperDuper.
434 434
 		// So we disable our widgets when editing a page with UX Builder.
435
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
435
+		if (function_exists('ux_builder_is_active') && ux_builder_is_active()) {
436 436
 			return;
437 437
 		}
438 438
 
439 439
 		$block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array();
440 440
 
441
-		if ( is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) {
441
+		if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) {
442 442
 			// don't initiate in these conditions.
443
-		}else{
443
+		} else {
444 444
 
445 445
 			// Only load allowed widgets.
446
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
446
+			$exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array();
447 447
 			$widgets = apply_filters(
448 448
 				'getpaid_widget_classes',
449 449
 				array(
@@ -458,16 +458,16 @@  discard block
 block discarded – undo
458 458
 			);
459 459
 
460 460
 			// For each widget...
461
-			foreach ( $widgets as $widget ) {
461
+			foreach ($widgets as $widget) {
462 462
 
463 463
 				// Abort early if it is excluded for this page.
464
-				if ( in_array( $widget, $exclude ) ) {
464
+				if (in_array($widget, $exclude)) {
465 465
 					continue;
466 466
 				}
467 467
 
468 468
 				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
469
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
470
-					register_widget( $widget );
469
+				if (is_subclass_of($widget, 'WP_Widget')) {
470
+					register_widget($widget);
471 471
 				} else {
472 472
 					new $widget();
473 473
 				}
@@ -485,29 +485,29 @@  discard block
 block discarded – undo
485 485
 	 */
486 486
 	public function maybe_upgrade_database() {
487 487
 
488
-		$wpi_version = get_option( 'wpinv_version', 0 );
488
+		$wpi_version = get_option('wpinv_version', 0);
489 489
 
490
-		if ( $wpi_version == WPINV_VERSION ) {
490
+		if ($wpi_version == WPINV_VERSION) {
491 491
 			return;
492 492
 		}
493 493
 
494 494
 		$installer = new GetPaid_Installer();
495 495
 
496
-		if ( empty( $wpi_version ) ) {
497
-			return $installer->upgrade_db( 0 );
496
+		if (empty($wpi_version)) {
497
+			return $installer->upgrade_db(0);
498 498
 		}
499 499
 
500
-		$upgrades  = array(
500
+		$upgrades = array(
501 501
 			'0.0.5' => '004',
502 502
 			'1.0.3' => '102',
503 503
 			'2.0.0' => '118',
504 504
 			'2.0.8' => '207',
505 505
 		);
506 506
 
507
-		foreach ( $upgrades as $key => $method ) {
507
+		foreach ($upgrades as $key => $method) {
508 508
 
509
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
510
-				return $installer->upgrade_db( $method );
509
+			if (version_compare($wpi_version, $key, '<')) {
510
+				return $installer->upgrade_db($method);
511 511
 			}
512 512
 
513 513
 		}
@@ -521,11 +521,11 @@  discard block
 block discarded – undo
521 521
 	 */
522 522
 	public function maybe_flush_permalinks() {
523 523
 
524
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
524
+		$flush = get_option('wpinv_flush_permalinks', 0);
525 525
 
526
-		if ( ! empty( $flush ) ) {
526
+		if (!empty($flush)) {
527 527
 			flush_rewrite_rules();
528
-			delete_option( 'wpinv_flush_permalinks' );
528
+			delete_option('wpinv_flush_permalinks');
529 529
 		}
530 530
 
531 531
 	}
@@ -536,10 +536,10 @@  discard block
 block discarded – undo
536 536
 	 * @since 1.0.19
537 537
 	 * @param int[] $excluded_posts_ids
538 538
 	 */
539
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
539
+	public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
540 540
 
541 541
 		// Ensure that we have an array.
542
-		if ( ! is_array( $excluded_posts_ids ) ) {
542
+		if (!is_array($excluded_posts_ids)) {
543 543
 			$excluded_posts_ids = array();
544 544
 		}
545 545
 
@@ -547,24 +547,24 @@  discard block
 block discarded – undo
547 547
 		$our_pages = array();
548 548
 
549 549
 		// Checkout page.
550
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
550
+		$our_pages[] = wpinv_get_option('checkout_page', false);
551 551
 
552 552
 		// Success page.
553
-		$our_pages[] = wpinv_get_option( 'success_page', false );
553
+		$our_pages[] = wpinv_get_option('success_page', false);
554 554
 
555 555
 		// Failure page.
556
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
556
+		$our_pages[] = wpinv_get_option('failure_page', false);
557 557
 
558 558
 		// History page.
559
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
559
+		$our_pages[] = wpinv_get_option('invoice_history_page', false);
560 560
 
561 561
 		// Subscriptions page.
562
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
562
+		$our_pages[] = wpinv_get_option('invoice_subscription_page', false);
563 563
 
564
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
564
+		$our_pages   = array_map('intval', array_filter($our_pages));
565 565
 
566 566
 		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
567
-		return array_unique( $excluded_posts_ids );
567
+		return array_unique($excluded_posts_ids);
568 568
 
569 569
 	}
570 570
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 	 * @since 2.0.0
575 575
 	 */
576 576
 	public function wp_footer() {
577
-		wpinv_get_template( 'frontend-footer.php' );
577
+		wpinv_get_template('frontend-footer.php');
578 578
 	}
579 579
 
580 580
 	/**
@@ -583,14 +583,14 @@  discard block
 block discarded – undo
583 583
 	 * @since 2.0.0
584 584
 	 */
585 585
 	public function wp_head() {
586
-		wpinv_get_template( 'frontend-head.php' );
586
+		wpinv_get_template('frontend-head.php');
587 587
 	}
588 588
 
589 589
 	/**
590 590
 	 * Custom query vars.
591 591
 	 *
592 592
 	 */
593
-	public function custom_query_vars( $vars ) {
593
+	public function custom_query_vars($vars) {
594 594
         $vars[] = 'getpaid-ipn';
595 595
         return $vars;
596 596
 	}
@@ -601,28 +601,28 @@  discard block
 block discarded – undo
601 601
 	 */
602 602
 	public function add_rewrite_rule() {
603 603
         $tag = 'getpaid-ipn';
604
-        add_rewrite_tag( "%$tag%", '([^&]+)' );
605
-        add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]",'top' );
604
+        add_rewrite_tag("%$tag%", '([^&]+)');
605
+        add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top');
606 606
 	}
607 607
 
608 608
 	/**
609 609
 	 * Processes non-query string ipns.
610 610
 	 *
611 611
 	 */
612
-	public function maybe_process_new_ipn( $query ) {
612
+	public function maybe_process_new_ipn($query) {
613 613
 
614
-        if ( is_admin() || ! $query->is_main_query() ) {
614
+        if (is_admin() || !$query->is_main_query()) {
615 615
             return;
616 616
         }
617 617
 
618
-		$gateway = get_query_var( 'getpaid-ipn' );
618
+		$gateway = get_query_var('getpaid-ipn');
619 619
 
620
-        if ( ! empty( $gateway ) ){
620
+        if (!empty($gateway)) {
621 621
 
622
-			$gateway = sanitize_text_field( $gateway );
622
+			$gateway = sanitize_text_field($gateway);
623 623
 			nocache_headers();
624
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
625
-			do_action( "wpinv_verify_{$gateway}_ipn" );
624
+			do_action('wpinv_verify_payment_ipn', $gateway);
625
+			do_action("wpinv_verify_{$gateway}_ipn");
626 626
 			exit;
627 627
 
628 628
         }
Please login to merge, or discard this patch.
includes/libraries/wp-all-import/rapid-addon.php 3 patches
Indentation   +802 added lines, -802 removed lines patch added patch discarded remove patch
@@ -10,232 +10,232 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
1293 1293
             }
1294 1294
             return $image;
1295 1295
         }
1296
-	}	
1296
+    }	
1297 1297
 }
1298 1298
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
Braces   +80 added lines, -33 removed lines patch added patch discarded remove patch
@@ -156,7 +156,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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'])){ 					
Please login to merge, or discard this patch.
includes/libraries/wp-all-import/class-getpaid-wp-all-import.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -14,88 +14,88 @@
 block discarded – undo
14 14
  */
15 15
 class GetPaid_WP_All_Import {
16 16
 
17
-	/**
18
-	 * @var RapidAddon
19
-	 */
20
-	protected $add_on;
17
+    /**
18
+     * @var RapidAddon
19
+     */
20
+    protected $add_on;
21 21
 
22 22
     /**
23
-	 * Class constructor.
24
-	 */
23
+     * Class constructor.
24
+     */
25 25
     public function __construct() {
26 26
 
27
-		// Register the add-on.
28
-		$this->add_on = new RapidAddon( 'GetPaid', 'GetPaid_WP_All_Import_Addon' );
29
-		$this->add_on->set_import_function( array( $this, 'import_items' ) );
30
-		$this->add_item_fields();
31
-		$this->add_on->run( array( 'post_types' => array( 'wpi_item' ) ) );
27
+        // Register the add-on.
28
+        $this->add_on = new RapidAddon( 'GetPaid', 'GetPaid_WP_All_Import_Addon' );
29
+        $this->add_on->set_import_function( array( $this, 'import_items' ) );
30
+        $this->add_item_fields();
31
+        $this->add_on->run( array( 'post_types' => array( 'wpi_item' ) ) );
32 32
 
33
-	}
33
+    }
34 34
 
35
-	/**
36
-	 * Retrieves item fields.
37
-	 */
35
+    /**
36
+     * Retrieves item fields.
37
+     */
38 38
     public function get_item_fields() {
39 39
 
40
-		return array(
41
-			'description'          => __( 'Item Description', 'invoicing' ),
42
-			'price'                => __( 'Price', 'invoicing' ),
43
-			'vat_rule'             => __( 'VAT Rule', 'invoicing' ),
44
-			'vat_class'            => __( 'VAT Class', 'invoicing' ),
45
-			'type'                 => __( 'Trial Interval', 'invoicing' ),
46
-			'custom_id'            => __( 'Custom ID', 'invoicing' ),
47
-			'custom_name'          => __( 'Custom Name', 'invoicing' ),
48
-			'custom_singular_name' => __( 'Custom Singular Name', 'invoicing' ),
49
-			'is_dynamic_pricing'   => __( 'Users can name their own price', 'invoicing' ),
50
-			'minimum_price'        => __( 'Minimum price', 'invoicing' ),
51
-			'is_recurring'         => __( 'Is Recurring', 'invoicing' ),
52
-			'recurring_period'     => __( 'Recurring Period', 'invoicing' ),
53
-			'recurring_interval'   => __( 'Recurring Interval', 'invoicing' ),
54
-			'recurring_limit'      => __( 'Recurring Limit', 'invoicing' ),
55
-			'is_free_trial'        => __( 'Is free trial', 'invoicing' ),
56
-			'trial_period'         => __( 'Trial Period', 'invoicing' ),
57
-			'trial_interval'       => __( 'Trial Interval', 'invoicing' ),
58
-		);
40
+        return array(
41
+            'description'          => __( 'Item Description', 'invoicing' ),
42
+            'price'                => __( 'Price', 'invoicing' ),
43
+            'vat_rule'             => __( 'VAT Rule', 'invoicing' ),
44
+            'vat_class'            => __( 'VAT Class', 'invoicing' ),
45
+            'type'                 => __( 'Trial Interval', 'invoicing' ),
46
+            'custom_id'            => __( 'Custom ID', 'invoicing' ),
47
+            'custom_name'          => __( 'Custom Name', 'invoicing' ),
48
+            'custom_singular_name' => __( 'Custom Singular Name', 'invoicing' ),
49
+            'is_dynamic_pricing'   => __( 'Users can name their own price', 'invoicing' ),
50
+            'minimum_price'        => __( 'Minimum price', 'invoicing' ),
51
+            'is_recurring'         => __( 'Is Recurring', 'invoicing' ),
52
+            'recurring_period'     => __( 'Recurring Period', 'invoicing' ),
53
+            'recurring_interval'   => __( 'Recurring Interval', 'invoicing' ),
54
+            'recurring_limit'      => __( 'Recurring Limit', 'invoicing' ),
55
+            'is_free_trial'        => __( 'Is free trial', 'invoicing' ),
56
+            'trial_period'         => __( 'Trial Period', 'invoicing' ),
57
+            'trial_interval'       => __( 'Trial Interval', 'invoicing' ),
58
+        );
59 59
 
60 60
     }
61 61
 
62
-	/**
63
-	 * Registers item fields.
64
-	 */
62
+    /**
63
+     * Registers item fields.
64
+     */
65 65
     public function add_item_fields() {
66 66
 
67
-		foreach ( $this->get_item_fields() as $key => $label ) {
68
-			$this->add_on->add_field( $key, $label, 'text' );
69
-		}
67
+        foreach ( $this->get_item_fields() as $key => $label ) {
68
+            $this->add_on->add_field( $key, $label, 'text' );
69
+        }
70 70
 
71 71
     }
72 72
 
73
-	/**
74
-	 * Handles item imports.
75
-	 */
73
+    /**
74
+     * Handles item imports.
75
+     */
76 76
     public function import_items( $post_id, $data, $import_options, $_post ) {
77 77
 
78
-		$item     = wpinv_get_item( $post_id );
79
-		$prepared = array();
78
+        $item     = wpinv_get_item( $post_id );
79
+        $prepared = array();
80 80
 
81
-		if ( empty( $item ) ) {
82
-			return;
83
-		}
81
+        if ( empty( $item ) ) {
82
+            return;
83
+        }
84 84
 
85
-		foreach ( array_keys( $this->get_item_fields() ) as $field ) { 
86
-			// Make sure the user has allowed this field to be updated.
87
-			if ( empty( $_post['ID'] ) || $this->add_on->can_update_meta( $field, $import_options ) ) { 
85
+        foreach ( array_keys( $this->get_item_fields() ) as $field ) { 
86
+            // Make sure the user has allowed this field to be updated.
87
+            if ( empty( $_post['ID'] ) || $this->add_on->can_update_meta( $field, $import_options ) ) { 
88 88
 	
89
-				// Update the custom field with the imported data.
90
-				$prepared[ $field ] = $data[ $field ];
91
-			} 
92
-		}
93
-
94
-		// Only update if we have something to update.
95
-		if ( ! empty( $prepared ) ) {
96
-			$item->set_props( $prepared );
97
-			$item->save();
98
-		}
89
+                // Update the custom field with the imported data.
90
+                $prepared[ $field ] = $data[ $field ];
91
+            } 
92
+        }
93
+
94
+        // Only update if we have something to update.
95
+        if ( ! empty( $prepared ) ) {
96
+            $item->set_props( $prepared );
97
+            $item->save();
98
+        }
99 99
 
100 100
     }
101 101
 
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@  discard block
 block discarded – undo
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.
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
     public function __construct() {
26 26
 
27 27
 		// Register the add-on.
28
-		$this->add_on = new RapidAddon( 'GetPaid', 'GetPaid_WP_All_Import_Addon' );
29
-		$this->add_on->set_import_function( array( $this, 'import_items' ) );
28
+		$this->add_on = new RapidAddon('GetPaid', 'GetPaid_WP_All_Import_Addon');
29
+		$this->add_on->set_import_function(array($this, 'import_items'));
30 30
 		$this->add_item_fields();
31
-		$this->add_on->run( array( 'post_types' => array( 'wpi_item' ) ) );
31
+		$this->add_on->run(array('post_types' => array('wpi_item')));
32 32
 
33 33
 	}
34 34
 
@@ -38,23 +38,23 @@  discard block
 block discarded – undo
38 38
     public function get_item_fields() {
39 39
 
40 40
 		return array(
41
-			'description'          => __( 'Item Description', 'invoicing' ),
42
-			'price'                => __( 'Price', 'invoicing' ),
43
-			'vat_rule'             => __( 'VAT Rule', 'invoicing' ),
44
-			'vat_class'            => __( 'VAT Class', 'invoicing' ),
45
-			'type'                 => __( 'Trial Interval', 'invoicing' ),
46
-			'custom_id'            => __( 'Custom ID', 'invoicing' ),
47
-			'custom_name'          => __( 'Custom Name', 'invoicing' ),
48
-			'custom_singular_name' => __( 'Custom Singular Name', 'invoicing' ),
49
-			'is_dynamic_pricing'   => __( 'Users can name their own price', 'invoicing' ),
50
-			'minimum_price'        => __( 'Minimum price', 'invoicing' ),
51
-			'is_recurring'         => __( 'Is Recurring', 'invoicing' ),
52
-			'recurring_period'     => __( 'Recurring Period', 'invoicing' ),
53
-			'recurring_interval'   => __( 'Recurring Interval', 'invoicing' ),
54
-			'recurring_limit'      => __( 'Recurring Limit', 'invoicing' ),
55
-			'is_free_trial'        => __( 'Is free trial', 'invoicing' ),
56
-			'trial_period'         => __( 'Trial Period', 'invoicing' ),
57
-			'trial_interval'       => __( 'Trial Interval', 'invoicing' ),
41
+			'description'          => __('Item Description', 'invoicing'),
42
+			'price'                => __('Price', 'invoicing'),
43
+			'vat_rule'             => __('VAT Rule', 'invoicing'),
44
+			'vat_class'            => __('VAT Class', 'invoicing'),
45
+			'type'                 => __('Trial Interval', 'invoicing'),
46
+			'custom_id'            => __('Custom ID', 'invoicing'),
47
+			'custom_name'          => __('Custom Name', 'invoicing'),
48
+			'custom_singular_name' => __('Custom Singular Name', 'invoicing'),
49
+			'is_dynamic_pricing'   => __('Users can name their own price', 'invoicing'),
50
+			'minimum_price'        => __('Minimum price', 'invoicing'),
51
+			'is_recurring'         => __('Is Recurring', 'invoicing'),
52
+			'recurring_period'     => __('Recurring Period', 'invoicing'),
53
+			'recurring_interval'   => __('Recurring Interval', 'invoicing'),
54
+			'recurring_limit'      => __('Recurring Limit', 'invoicing'),
55
+			'is_free_trial'        => __('Is free trial', 'invoicing'),
56
+			'trial_period'         => __('Trial Period', 'invoicing'),
57
+			'trial_interval'       => __('Trial Interval', 'invoicing'),
58 58
 		);
59 59
 
60 60
     }
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
     public function add_item_fields() {
66 66
 
67
-		foreach ( $this->get_item_fields() as $key => $label ) {
68
-			$this->add_on->add_field( $key, $label, 'text' );
67
+		foreach ($this->get_item_fields() as $key => $label) {
68
+			$this->add_on->add_field($key, $label, 'text');
69 69
 		}
70 70
 
71 71
     }
@@ -73,27 +73,27 @@  discard block
 block discarded – undo
73 73
 	/**
74 74
 	 * Handles item imports.
75 75
 	 */
76
-    public function import_items( $post_id, $data, $import_options, $_post ) {
76
+    public function import_items($post_id, $data, $import_options, $_post) {
77 77
 
78
-		$item     = wpinv_get_item( $post_id );
78
+		$item     = wpinv_get_item($post_id);
79 79
 		$prepared = array();
80 80
 
81
-		if ( empty( $item ) ) {
81
+		if (empty($item)) {
82 82
 			return;
83 83
 		}
84 84
 
85
-		foreach ( array_keys( $this->get_item_fields() ) as $field ) { 
85
+		foreach (array_keys($this->get_item_fields()) as $field) { 
86 86
 			// Make sure the user has allowed this field to be updated.
87
-			if ( empty( $_post['ID'] ) || $this->add_on->can_update_meta( $field, $import_options ) ) { 
87
+			if (empty($_post['ID']) || $this->add_on->can_update_meta($field, $import_options)) { 
88 88
 	
89 89
 				// Update the custom field with the imported data.
90
-				$prepared[ $field ] = $data[ $field ];
90
+				$prepared[$field] = $data[$field];
91 91
 			} 
92 92
 		}
93 93
 
94 94
 		// Only update if we have something to update.
95
-		if ( ! empty( $prepared ) ) {
96
-			$item->set_props( $prepared );
95
+		if (!empty($prepared)) {
96
+			$item->set_props($prepared);
97 97
 			$item->save();
98 98
 		}
99 99
 
Please login to merge, or discard this patch.