Passed
Pull Request — master (#860)
by Kiran
08:35 queued 02:43
created
includes/gateways/class-getpaid-paypal-gateway.php 2 patches
Indentation   +508 added lines, -508 removed lines patch added patch discarded remove patch
@@ -13,103 +13,103 @@  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', 'refunds' );
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;
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49 49
 
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
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() {
82
-		parent::__construct();
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82
+        parent::__construct();
83 83
 
84 84
         $this->title                = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
86 86
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
87 87
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
88 88
 
89
-		add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 );
90
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
91
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
92
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
93
-		add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
94
-
95
-		if ( $this->enabled ) {
96
-			add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
97
-			add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) );
98
-			add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) );
99
-			add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) );
100
-		}
89
+        add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 );
90
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
91
+        add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
92
+        add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
93
+        add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
94
+
95
+        if ( $this->enabled ) {
96
+            add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
97
+            add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) );
98
+            add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) );
99
+            add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) );
100
+        }
101 101
     }
102 102
 
103 103
     /**
104
-	 * Process Payment.
105
-	 *
106
-	 *
107
-	 * @param WPInv_Invoice $invoice Invoice.
108
-	 * @param array $submission_data Posted checkout fields.
109
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
110
-	 * @return array
111
-	 */
112
-	public function process_payment( $invoice, $submission_data, $submission ) {
104
+     * Process Payment.
105
+     *
106
+     *
107
+     * @param WPInv_Invoice $invoice Invoice.
108
+     * @param array $submission_data Posted checkout fields.
109
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
110
+     * @return array
111
+     */
112
+    public function process_payment( $invoice, $submission_data, $submission ) {
113 113
 
114 114
         // Get redirect url.
115 115
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -132,15 +132,15 @@  discard block
 block discarded – undo
132 132
     }
133 133
 
134 134
     /**
135
-	 * Get the PayPal request URL for an invoice.
136
-	 *
137
-	 * @param  WPInv_Invoice $invoice Invoice object.
138
-	 * @return string
139
-	 */
140
-	public function get_request_url( $invoice ) {
135
+     * Get the PayPal request URL for an invoice.
136
+     *
137
+     * @param  WPInv_Invoice $invoice Invoice object.
138
+     * @return string
139
+     */
140
+    public function get_request_url( $invoice ) {
141 141
 
142 142
         // Endpoint for this request
143
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
143
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
144 144
 
145 145
         // Retrieve paypal args.
146 146
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -153,45 +153,45 @@  discard block
 block discarded – undo
153 153
 
154 154
         return add_query_arg( $paypal_args, $this->endpoint );
155 155
 
156
-	}
156
+    }
157 157
 
158 158
     /**
159
-	 * Get PayPal Args for passing to PP.
160
-	 *
161
-	 * @param  WPInv_Invoice $invoice Invoice object.
162
-	 * @return array
163
-	 */
164
-	protected function get_paypal_args( $invoice ) {
159
+     * Get PayPal Args for passing to PP.
160
+     *
161
+     * @param  WPInv_Invoice $invoice Invoice object.
162
+     * @return array
163
+     */
164
+    protected function get_paypal_args( $invoice ) {
165 165
 
166 166
         // Whether or not to send the line items as one item.
167
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
168
-
169
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
170
-			$force_one_line_item = true;
171
-		}
172
-
173
-		$paypal_args = apply_filters(
174
-			'getpaid_paypal_args',
175
-			array_merge(
176
-				$this->get_transaction_args( $invoice ),
177
-				$this->get_line_item_args( $invoice, $force_one_line_item )
178
-			),
179
-			$invoice
180
-		);
181
-
182
-		return $this->fix_request_length( $invoice, $paypal_args );
167
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
168
+
169
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
170
+            $force_one_line_item = true;
171
+        }
172
+
173
+        $paypal_args = apply_filters(
174
+            'getpaid_paypal_args',
175
+            array_merge(
176
+                $this->get_transaction_args( $invoice ),
177
+                $this->get_line_item_args( $invoice, $force_one_line_item )
178
+            ),
179
+            $invoice
180
+        );
181
+
182
+        return $this->fix_request_length( $invoice, $paypal_args );
183 183
     }
184 184
 
185 185
     /**
186
-	 * Get transaction args for paypal request.
187
-	 *
188
-	 * @param WPInv_Invoice $invoice Invoice object.
189
-	 * @return array
190
-	 */
191
-	protected function get_transaction_args( $invoice ) {
186
+     * Get transaction args for paypal request.
187
+     *
188
+     * @param WPInv_Invoice $invoice Invoice object.
189
+     * @return array
190
+     */
191
+    protected function get_transaction_args( $invoice ) {
192 192
 
193
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
194
-		return array(
193
+        $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
194
+        return array(
195 195
             'cmd'           => '_cart',
196 196
             'business'      => $email,
197 197
             'no_shipping'   => '1',
@@ -216,16 +216,16 @@  discard block
 block discarded – undo
216 216
     }
217 217
 
218 218
     /**
219
-	 * Get line item args for paypal request.
220
-	 *
221
-	 * @param  WPInv_Invoice $invoice Invoice object.
222
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
223
-	 * @return array
224
-	 */
225
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
219
+     * Get line item args for paypal request.
220
+     *
221
+     * @param  WPInv_Invoice $invoice Invoice object.
222
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
223
+     * @return array
224
+     */
225
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
226 226
 
227 227
         // Maybe send invoice as a single item.
228
-		if ( $force_one_line_item ) {
228
+        if ( $force_one_line_item ) {
229 229
             return $this->get_line_item_args_single_item( $invoice );
230 230
         }
231 231
 
@@ -245,134 +245,134 @@  discard block
 block discarded – undo
245 245
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
246 246
         }
247 247
 
248
-		return array_merge( $line_item_args, $this->get_line_items() );
248
+        return array_merge( $line_item_args, $this->get_line_items() );
249 249
 
250 250
     }
251 251
 
252 252
     /**
253
-	 * Get line item args for paypal request as a single line item.
254
-	 *
255
-	 * @param  WPInv_Invoice $invoice Invoice object.
256
-	 * @return array
257
-	 */
258
-	protected function get_line_item_args_single_item( $invoice ) {
259
-		$this->delete_line_items();
253
+     * Get line item args for paypal request as a single line item.
254
+     *
255
+     * @param  WPInv_Invoice $invoice Invoice object.
256
+     * @return array
257
+     */
258
+    protected function get_line_item_args_single_item( $invoice ) {
259
+        $this->delete_line_items();
260 260
 
261 261
         $item_name = wp_sprintf( __( 'Invoice %s', 'invoicing' ), $invoice->get_number() );
262
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
262
+        $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
263 263
 
264
-		return $this->get_line_items();
264
+        return $this->get_line_items();
265 265
     }
266 266
 
267 267
     /**
268
-	 * Return all line items.
269
-	 */
270
-	protected function get_line_items() {
271
-		return $this->line_items;
272
-	}
268
+     * Return all line items.
269
+     */
270
+    protected function get_line_items() {
271
+        return $this->line_items;
272
+    }
273 273
 
274 274
     /**
275
-	 * Remove all line items.
276
-	 */
277
-	protected function delete_line_items() {
278
-		$this->line_items = array();
275
+     * Remove all line items.
276
+     */
277
+    protected function delete_line_items() {
278
+        $this->line_items = array();
279 279
     }
280 280
 
281 281
     /**
282
-	 * Prepare line items to send to paypal.
283
-	 *
284
-	 * @param  WPInv_Invoice $invoice Invoice object.
285
-	 */
286
-	protected function prepare_line_items( $invoice ) {
287
-		$this->delete_line_items();
288
-
289
-		// Items.
290
-		foreach ( $invoice->get_items() as $item ) {
291
-			$amount   = $item->get_price();
292
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
293
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
282
+     * Prepare line items to send to paypal.
283
+     *
284
+     * @param  WPInv_Invoice $invoice Invoice object.
285
+     */
286
+    protected function prepare_line_items( $invoice ) {
287
+        $this->delete_line_items();
288
+
289
+        // Items.
290
+        foreach ( $invoice->get_items() as $item ) {
291
+            $amount   = $item->get_price();
292
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
293
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
294 294
         }
295 295
 
296 296
         // Fees.
297
-		foreach ( $invoice->get_fees() as $fee => $data ) {
297
+        foreach ( $invoice->get_fees() as $fee => $data ) {
298 298
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
299 299
         }
300 300
 
301 301
     }
302 302
 
303 303
     /**
304
-	 * Add PayPal Line Item.
305
-	 *
306
-	 * @param  string $item_name Item name.
307
-	 * @param  float    $quantity Item quantity.
308
-	 * @param  float  $amount Amount.
309
-	 * @param  string $item_number Item number.
310
-	 */
311
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
312
-		$index = ( count( $this->line_items ) / 4 ) + 1;
313
-
314
-		/**
315
-		 * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)"
316
-		 */
317
-		$item_name = str_replace( "#", "", $item_name );
318
-
319
-		$item = apply_filters(
320
-			'getpaid_paypal_line_item',
321
-			array(
322
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
323
-				'quantity'    => (float) $quantity,
324
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
325
-				'item_number' => $item_number,
326
-			),
327
-			$item_name,
328
-			$quantity,
329
-			$amount,
330
-			$item_number
331
-		);
332
-
333
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
304
+     * Add PayPal Line Item.
305
+     *
306
+     * @param  string $item_name Item name.
307
+     * @param  float    $quantity Item quantity.
308
+     * @param  float  $amount Amount.
309
+     * @param  string $item_number Item number.
310
+     */
311
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
312
+        $index = ( count( $this->line_items ) / 4 ) + 1;
313
+
314
+        /**
315
+         * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)"
316
+         */
317
+        $item_name = str_replace( "#", "", $item_name );
318
+
319
+        $item = apply_filters(
320
+            'getpaid_paypal_line_item',
321
+            array(
322
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
323
+                'quantity'    => (float) $quantity,
324
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
325
+                'item_number' => $item_number,
326
+            ),
327
+            $item_name,
328
+            $quantity,
329
+            $amount,
330
+            $item_number
331
+        );
332
+
333
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
334 334
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
335 335
 
336 336
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
337
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
338
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
337
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
338
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
339 339
     }
340 340
 
341 341
     /**
342
-	 * If the default request with line items is too long, generate a new one with only one line item.
343
-	 *
344
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
345
-	 *
346
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
347
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
348
-	 * @return array
349
-	 */
350
-	protected function fix_request_length( $invoice, $paypal_args ) {
351
-		$max_paypal_length = 2083;
352
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
353
-
354
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
355
-			return $paypal_args;
356
-		}
357
-
358
-		return apply_filters(
359
-			'getpaid_paypal_args',
360
-			array_merge(
361
-				$this->get_transaction_args( $invoice ),
362
-				$this->get_line_item_args( $invoice, true )
363
-			),
364
-			$invoice
365
-		);
342
+     * If the default request with line items is too long, generate a new one with only one line item.
343
+     *
344
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
345
+     *
346
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
347
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
348
+     * @return array
349
+     */
350
+    protected function fix_request_length( $invoice, $paypal_args ) {
351
+        $max_paypal_length = 2083;
352
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
353
+
354
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
355
+            return $paypal_args;
356
+        }
357
+
358
+        return apply_filters(
359
+            'getpaid_paypal_args',
360
+            array_merge(
361
+                $this->get_transaction_args( $invoice ),
362
+                $this->get_line_item_args( $invoice, true )
363
+            ),
364
+            $invoice
365
+        );
366 366
 
367 367
     }
368 368
 
369 369
     /**
370
-	 * Processes recurring invoices.
371
-	 *
372
-	 * @param  array $paypal_args PayPal args.
373
-	 * @param  WPInv_Invoice    $invoice Invoice object.
374
-	 */
375
-	public function process_subscription( $paypal_args, $invoice ) {
370
+     * Processes recurring invoices.
371
+     *
372
+     * @param  array $paypal_args PayPal args.
373
+     * @param  WPInv_Invoice    $invoice Invoice object.
374
+     */
375
+    public function process_subscription( $paypal_args, $invoice ) {
376 376
 
377 377
         // Make sure this is a subscription.
378 378
         if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
@@ -393,21 +393,21 @@  discard block
 block discarded – undo
393 393
         $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
394 394
         $subscription_item      = $invoice->get_recurring( true );
395 395
 
396
-		// Convert 365 days to 1 year.
397
-		if ( 'D' == $period && 365 == $interval ) {
398
-			$period = 'Y';
399
-			$interval = 1;
400
-		}
396
+        // Convert 365 days to 1 year.
397
+        if ( 'D' == $period && 365 == $interval ) {
398
+            $period = 'Y';
399
+            $interval = 1;
400
+        }
401 401
 
402 402
         if ( $subscription_item->has_free_trial() ) {
403 403
 
404 404
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
405 405
 
406
-			// Trial period length.
407
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
406
+            // Trial period length.
407
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
408 408
 
409
-			// Trial period.
410
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
409
+            // Trial period.
410
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
411 411
 
412 412
         } elseif ( $initial_amount != $recurring_amount ) {
413 413
 
@@ -430,40 +430,40 @@  discard block
 block discarded – undo
430 430
         }
431 431
 
432 432
         // We have a recurring payment
433
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
433
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
434 434
 
435
-			// Subscription price
436
-			$paypal_args['a3'] = $recurring_amount;
435
+            // Subscription price
436
+            $paypal_args['a3'] = $recurring_amount;
437 437
 
438
-			// Subscription duration
439
-			$paypal_args['p3'] = $interval;
438
+            // Subscription duration
439
+            $paypal_args['p3'] = $interval;
440 440
 
441
-			// Subscription period
442
-			$paypal_args['t3'] = $period;
441
+            // Subscription period
442
+            $paypal_args['t3'] = $period;
443 443
 
444 444
         }
445 445
 
446 446
         // Recurring payments
447
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
447
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
448 448
 
449
-			// Non-recurring payments
450
-			$paypal_args['src'] = 0;
449
+            // Non-recurring payments
450
+            $paypal_args['src'] = 0;
451 451
 
452
-		} else {
452
+        } else {
453 453
 
454
-			$paypal_args['src'] = 1;
454
+            $paypal_args['src'] = 1;
455 455
 
456
-			if ( $bill_times > 0 ) {
456
+            if ( $bill_times > 0 ) {
457 457
 
458
-				// An initial period is being used to charge a sign-up fee
459
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
460
-					$bill_times--;
461
-				}
458
+                // An initial period is being used to charge a sign-up fee
459
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
460
+                    $bill_times--;
461
+                }
462 462
 
463 463
                 // Make sure it's not over the max of 52
464 464
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
465 465
 
466
-			}
466
+            }
467 467
         }
468 468
 
469 469
         // Force return URL so that order description & instructions display
@@ -475,115 +475,115 @@  discard block
 block discarded – undo
475 475
             if ( isset( $paypal_args[ $arg ] ) ) {
476 476
                 unset( $paypal_args[ $arg ] );
477 477
             }
478
-		}
478
+        }
479 479
 
480 480
         return apply_filters(
481
-			'getpaid_paypal_subscription_args',
482
-			$paypal_args,
483
-			$invoice
481
+            'getpaid_paypal_subscription_args',
482
+            $paypal_args,
483
+            $invoice
484
+        );
485
+
486
+    }
487
+
488
+    /**
489
+     * Refunds an invoice remotely.
490
+     * 
491
+     * @since 2.8.24
492
+     * @param WPInv_Invoice $invoice Invoice object.
493
+     */
494
+    public function refund_invoice( $invoice ) {
495
+
496
+        if ( $invoice->get_gateway() !== $this->id ) {
497
+            return;
498
+        }
499
+
500
+        $mode	= $this->is_sandbox( $invoice ) ? 'sandbox' : 'live';
501
+        $result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode );
502
+
503
+        if ( is_wp_error( $result ) ) {
504
+            $invoice->add_system_note(
505
+                sprintf(
506
+                    // translators: %s is the error message.
507
+                    __( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ),
508
+                    $invoice->get_id(),
509
+                    $result->get_error_message()
510
+                )
511
+            );
512
+        } else {
513
+            $invoice->add_system_note(
514
+                sprintf(
515
+                    // translators: %s is the refund ID.
516
+                    __( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ),
517
+                    $invoice->get_id(),
518
+                    $result->id
519
+                )
520
+            );
521
+        }
522
+    }
523
+
524
+    /**
525
+     * Cancels a subscription remotely.
526
+     * 
527
+     * @since 2.8.24
528
+     * @param WPInv_Subscription $subscription Subscription object.
529
+     */
530
+    public function subscription_cancelled( $subscription ) {
531
+
532
+        if ( $subscription->get_gateway() != $this->id ) {
533
+            return;
534
+        }
535
+
536
+        $invoice = $subscription->get_parent_invoice();
537
+
538
+        // Abort if the parent invoice does not exist.
539
+        if ( ! $invoice->exists() ) {
540
+            return;
541
+        }
542
+
543
+        $mode	= $this->is_sandbox( $invoice ) ? 'sandbox' : 'live';
544
+        $result = GetPaid_PayPal_API::cancel_subscription( 
545
+            $invoice->get_remote_subscription_id(), 
546
+            array(
547
+                'reason' => __(' Customer requested cancellation', 'invoicing' ),
548
+            ), 
549
+            $mode 
484 550
         );
485 551
 
552
+        if ( is_wp_error( $result ) ) {
553
+
554
+            $error = sprintf(
555
+                // translators: %s is the subscription ID.
556
+                __( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ),
557
+                $subscription->get_id()
558
+            );
559
+
560
+            getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() );
561
+
562
+            if ( ! is_admin() ) {
563
+                wpinv_set_error( $result->get_error_code(), $error );
564
+            }
565
+
566
+            return;
567
+        }
568
+
569
+        if ( is_admin() ) {
570
+            getpaid_admin()->show_success(
571
+                sprintf(
572
+                    // translators: %s is the subscription ID.
573
+                    __( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ),
574
+                    $subscription->get_id()
575
+                )
576
+            );
577
+        }
578
+
486 579
     }
487 580
 
488
-	/**
489
-	 * Refunds an invoice remotely.
490
-	 * 
491
-	 * @since 2.8.24
492
-	 * @param WPInv_Invoice $invoice Invoice object.
493
-	 */
494
-	public function refund_invoice( $invoice ) {
495
-
496
-		if ( $invoice->get_gateway() !== $this->id ) {
497
-			return;
498
-		}
499
-
500
-		$mode	= $this->is_sandbox( $invoice ) ? 'sandbox' : 'live';
501
-		$result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode );
502
-
503
-		if ( is_wp_error( $result ) ) {
504
-			$invoice->add_system_note(
505
-				sprintf(
506
-					// translators: %s is the error message.
507
-					__( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ),
508
-					$invoice->get_id(),
509
-					$result->get_error_message()
510
-				)
511
-			);
512
-		} else {
513
-			$invoice->add_system_note(
514
-				sprintf(
515
-					// translators: %s is the refund ID.
516
-					__( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ),
517
-					$invoice->get_id(),
518
-					$result->id
519
-				)
520
-			);
521
-		}
522
-	}
523
-
524
-	/**
525
-	 * Cancels a subscription remotely.
526
-	 * 
527
-	 * @since 2.8.24
528
-	 * @param WPInv_Subscription $subscription Subscription object.
529
-	 */
530
-	public function subscription_cancelled( $subscription ) {
531
-
532
-		if ( $subscription->get_gateway() != $this->id ) {
533
-			return;
534
-		}
535
-
536
-		$invoice = $subscription->get_parent_invoice();
537
-
538
-		// Abort if the parent invoice does not exist.
539
-		if ( ! $invoice->exists() ) {
540
-			return;
541
-		}
542
-
543
-		$mode	= $this->is_sandbox( $invoice ) ? 'sandbox' : 'live';
544
-		$result = GetPaid_PayPal_API::cancel_subscription( 
545
-			$invoice->get_remote_subscription_id(), 
546
-			array(
547
-				'reason' => __(' Customer requested cancellation', 'invoicing' ),
548
-			), 
549
-			$mode 
550
-		);
551
-
552
-		if ( is_wp_error( $result ) ) {
553
-
554
-			$error = sprintf(
555
-				// translators: %s is the subscription ID.
556
-				__( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ),
557
-				$subscription->get_id()
558
-			);
559
-
560
-			getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() );
561
-
562
-			if ( ! is_admin() ) {
563
-				wpinv_set_error( $result->get_error_code(), $error );
564
-			}
565
-
566
-			return;
567
-		}
568
-
569
-		if ( is_admin() ) {
570
-			getpaid_admin()->show_success(
571
-				sprintf(
572
-					// translators: %s is the subscription ID.
573
-					__( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ),
574
-					$subscription->get_id()
575
-				)
576
-			);
577
-		}
578
-
579
-	}
580
-
581
-    /**
582
-	 * Processes ipns and marks payments as complete.
583
-	 *
584
-	 * @return void
585
-	 */
586
-	public function verify_ipn() {
581
+    /**
582
+     * Processes ipns and marks payments as complete.
583
+     *
584
+     * @return void
585
+     */
586
+    public function verify_ipn() {
587 587
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
588 588
     }
589 589
 
@@ -593,19 +593,19 @@  discard block
 block discarded – undo
593 593
     public function sandbox_notice() {
594 594
 
595 595
         return sprintf(
596
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
597
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
598
-			'</a>'
599
-		);
596
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
597
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
598
+            '</a>'
599
+        );
600 600
 
601 601
     }
602 602
 
603
-	/**
604
-	 * Filters the gateway settings.
605
-	 *
606
-	 * @param array $admin_settings
607
-	 */
608
-	public function admin_settings( $admin_settings ) {
603
+    /**
604
+     * Filters the gateway settings.
605
+     *
606
+     * @param array $admin_settings
607
+     */
608
+    public function admin_settings( $admin_settings ) {
609 609
 
610 610
         $currencies = sprintf(
611 611
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -615,66 +615,66 @@  discard block
 block discarded – undo
615 615
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
616 616
         $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
617 617
 
618
-		// Access tokens.
619
-		$live_email      = wpinv_get_option( 'paypal_email' );
620
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
618
+        // Access tokens.
619
+        $live_email      = wpinv_get_option( 'paypal_email' );
620
+        $sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
621 621
 
622
-		$admin_settings['paypal_connect'] = array(
623
-			'type' => 'hook',
624
-			'id'   => 'paypal_connect',
625
-			'name' => __( 'Connect to PayPal', 'invoicing' ),
626
-		);
622
+        $admin_settings['paypal_connect'] = array(
623
+            'type' => 'hook',
624
+            'id'   => 'paypal_connect',
625
+            'name' => __( 'Connect to PayPal', 'invoicing' ),
626
+        );
627 627
 
628 628
         $admin_settings['paypal_email'] = array(
629 629
             'type'  => 'text',
630
-			'class' => 'live-auth-data',
630
+            'class' => 'live-auth-data',
631 631
             'id'    => 'paypal_email',
632 632
             'name'  => __( 'Live Email Address', 'invoicing' ),
633 633
             'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
634 634
         );
635 635
 
636
-		$admin_settings['paypal_sandbox_email'] = array(
636
+        $admin_settings['paypal_sandbox_email'] = array(
637 637
             'type'  => 'text',
638
-			'class' => 'sandbox-auth-data',
638
+            'class' => 'sandbox-auth-data',
639 639
             'id'    => 'paypal_sandbox_email',
640 640
             'name'  => __( 'Sandbox Email Address', 'invoicing' ),
641 641
             'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
642
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
642
+            'std'   => wpinv_get_option( 'paypal_email', '' ),
643
+        );
644
+
645
+        // Client ID and secret.
646
+        $admin_settings['paypal_client_id'] = array(
647
+            'type'  => 'text',
648
+            'class' => 'live-auth-data',
649
+            'id'    => 'paypal_client_id',
650
+            'name'  => __( 'Live Client ID', 'invoicing' ),
651
+            'desc'  => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
652
+        );
653
+
654
+        $admin_settings['paypal_sandbox_client_id'] = array(
655
+            'type'  => 'text',
656
+            'class' => 'sandbox-auth-data',
657
+            'id'    => 'paypal_sandbox_client_id',
658
+            'name'  => __( 'Sandbox Client ID', 'invoicing' ),
659
+            'desc'  => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
660
+            'std'   => wpinv_get_option( 'paypal_client_id', '' ),
643 661
         );
644 662
 
645
-		// Client ID and secret.
646
-		$admin_settings['paypal_client_id'] = array(
647
-			'type'  => 'text',
648
-			'class' => 'live-auth-data',
649
-			'id'    => 'paypal_client_id',
650
-			'name'  => __( 'Live Client ID', 'invoicing' ),
651
-			'desc'  => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
652
-		);
653
-
654
-		$admin_settings['paypal_sandbox_client_id'] = array(
655
-			'type'  => 'text',
656
-			'class' => 'sandbox-auth-data',
657
-			'id'    => 'paypal_sandbox_client_id',
658
-			'name'  => __( 'Sandbox Client ID', 'invoicing' ),
659
-			'desc'  => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
660
-			'std'   => wpinv_get_option( 'paypal_client_id', '' ),
661
-		);
662
-
663
-		$admin_settings['paypal_secret'] = array(
664
-			'type'  => 'text',
665
-			'class' => 'live-auth-data',
666
-			'id'    => 'paypal_secret',
667
-			'name'  => __( 'Live Secret', 'invoicing' ),
668
-			'desc'  => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
669
-		);
670
-
671
-		$admin_settings['paypal_sandbox_secret'] = array(
672
-			'type'  => 'text',
673
-			'class' => 'sandbox-auth-data',
674
-			'id'    => 'paypal_sandbox_secret',
675
-			'name'  => __( 'Sandbox Secret', 'invoicing' ),
676
-			'desc'  => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
677
-		);
663
+        $admin_settings['paypal_secret'] = array(
664
+            'type'  => 'text',
665
+            'class' => 'live-auth-data',
666
+            'id'    => 'paypal_secret',
667
+            'name'  => __( 'Live Secret', 'invoicing' ),
668
+            'desc'  => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
669
+        );
670
+
671
+        $admin_settings['paypal_sandbox_secret'] = array(
672
+            'type'  => 'text',
673
+            'class' => 'sandbox-auth-data',
674
+            'id'    => 'paypal_sandbox_secret',
675
+            'name'  => __( 'Sandbox Secret', 'invoicing' ),
676
+            'desc'  => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
677
+        );
678 678
 
679 679
         $admin_settings['paypal_ipn_url'] = array(
680 680
             'type'     => 'ipn_url',
@@ -685,57 +685,57 @@  discard block
 block discarded – undo
685 685
             'readonly' => true,
686 686
         );
687 687
 
688
-		return $admin_settings;
689
-	}
690
-
691
-	/**
692
-	 * Retrieves the URL to cancel a subscription.
693
-	 *
694
-	 * @param string $url
695
-	 * @param WPInv_Subscription $subscription
696
-	 */
697
-	public function filter_cancel_subscription_url( $url, $subscription ) {
698
-
699
-		if ( $this->id !== $subscription->get_gateway() ) {
700
-			return $url;
701
-		}
702
-
703
-		// Get the PayPal profile ID.
704
-		$profile_id = $subscription->get_profile_id();
705
-
706
-		// Bail if no profile ID.
707
-		if ( empty( $profile_id ) ) {
708
-			return $url;
709
-		}
710
-
711
-		$cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel';
712
-		if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) {
713
-			$cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel';
714
-		}
715
-
716
-		return sprintf( $cancel_url, $profile_id );
717
-	}
718
-
719
-	/**
720
-	 * Retrieves the PayPal connect URL when using the setup wizzard.
721
-	 *
722
-	 *
688
+        return $admin_settings;
689
+    }
690
+
691
+    /**
692
+     * Retrieves the URL to cancel a subscription.
693
+     *
694
+     * @param string $url
695
+     * @param WPInv_Subscription $subscription
696
+     */
697
+    public function filter_cancel_subscription_url( $url, $subscription ) {
698
+
699
+        if ( $this->id !== $subscription->get_gateway() ) {
700
+            return $url;
701
+        }
702
+
703
+        // Get the PayPal profile ID.
704
+        $profile_id = $subscription->get_profile_id();
705
+
706
+        // Bail if no profile ID.
707
+        if ( empty( $profile_id ) ) {
708
+            return $url;
709
+        }
710
+
711
+        $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel';
712
+        if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) {
713
+            $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel';
714
+        }
715
+
716
+        return sprintf( $cancel_url, $profile_id );
717
+    }
718
+
719
+    /**
720
+     * Retrieves the PayPal connect URL when using the setup wizzard.
721
+     *
722
+     *
723 723
      * @param array $data
724 724
      * @return string
725
-	 */
726
-	public static function maybe_get_connect_url( $url = '', $data = array() ) {
727
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
728
-	}
729
-
730
-	/**
731
-	 * Retrieves the PayPal connect URL.
732
-	 *
733
-	 *
725
+     */
726
+    public static function maybe_get_connect_url( $url = '', $data = array() ) {
727
+        return self::get_connect_url( false, urldecode( $data['redirect'] ) );
728
+    }
729
+
730
+    /**
731
+     * Retrieves the PayPal connect URL.
732
+     *
733
+     *
734 734
      * @param bool $is_sandbox
735
-	 * @param string $redirect
735
+     * @param string $redirect
736 736
      * @return string
737
-	 */
738
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
737
+     */
738
+    public static function get_connect_url( $is_sandbox, $redirect = '' ) {
739 739
 
740 740
         $redirect_url = add_query_arg(
741 741
             array(
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
                 'tab'                  => 'gateways',
746 746
                 'section'              => 'paypal',
747 747
                 'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
748
-				'redirect'             => urlencode( $redirect ),
748
+                'redirect'             => urlencode( $redirect ),
749 749
             ),
750 750
             admin_url( 'admin.php' )
751 751
         );
@@ -760,12 +760,12 @@  discard block
 block discarded – undo
760 760
 
761 761
     }
762 762
 
763
-	/**
764
-	 * Generates settings page js.
765
-	 *
763
+    /**
764
+     * Generates settings page js.
765
+     *
766 766
      * @return void
767
-	 */
768
-	public static function display_connect_buttons() {
767
+     */
768
+    public static function display_connect_buttons() {
769 769
 
770 770
         ?>
771 771
 			<div class="wpinv-paypal-connect-live">
@@ -807,70 +807,70 @@  discard block
 block discarded – undo
807 807
         <?php
808 808
     }
809 809
 
810
-	/**
811
-	 * Connects to PayPal.
812
-	 *
813
-	 * @param array $data Connection data.
814
-	 * @return void
815
-	 */
816
-	public function connect_paypal( $data ) {
817
-
818
-		$sandbox      = $this->is_sandbox();
819
-		$data         = wp_unslash( $data );
820
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
821
-
822
-		if ( isset( $data['live_mode'] ) ) {
823
-			$sandbox = empty( $data['live_mode'] );
824
-		}
825
-
826
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
827
-		wpinv_update_option( 'paypal_active', 1 );
828
-
829
-		if ( ! empty( $data['error_description'] ) ) {
830
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
831
-		} else {
832
-
833
-			// Retrieve the user info.
834
-			$user_info = wp_remote_get(
835
-				! $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',
836
-				array(
837
-
838
-					'headers' => array(
839
-						'Authorization' => 'Bearer ' . $access_token,
840
-						'Content-type'  => 'application/json',
841
-					),
842
-
843
-				)
844
-			);
845
-
846
-			if ( is_wp_error( $user_info ) ) {
847
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
848
-			} else {
849
-
850
-				// Create application.
851
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
852
-
853
-				if ( $sandbox ) {
854
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
855
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
856
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
857
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
858
-				} else {
859
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
860
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
861
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
862
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
863
-				}
864
-			}
865
-		}
866
-
867
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
868
-
869
-		if ( isset( $data['step'] ) ) {
870
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
871
-		}
872
-		wp_redirect( $redirect );
873
-		exit;
874
-	}
810
+    /**
811
+     * Connects to PayPal.
812
+     *
813
+     * @param array $data Connection data.
814
+     * @return void
815
+     */
816
+    public function connect_paypal( $data ) {
817
+
818
+        $sandbox      = $this->is_sandbox();
819
+        $data         = wp_unslash( $data );
820
+        $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
821
+
822
+        if ( isset( $data['live_mode'] ) ) {
823
+            $sandbox = empty( $data['live_mode'] );
824
+        }
825
+
826
+        wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
827
+        wpinv_update_option( 'paypal_active', 1 );
828
+
829
+        if ( ! empty( $data['error_description'] ) ) {
830
+            getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
831
+        } else {
832
+
833
+            // Retrieve the user info.
834
+            $user_info = wp_remote_get(
835
+                ! $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',
836
+                array(
837
+
838
+                    'headers' => array(
839
+                        'Authorization' => 'Bearer ' . $access_token,
840
+                        'Content-type'  => 'application/json',
841
+                    ),
842
+
843
+                )
844
+            );
845
+
846
+            if ( is_wp_error( $user_info ) ) {
847
+                getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
848
+            } else {
849
+
850
+                // Create application.
851
+                $user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
852
+
853
+                if ( $sandbox ) {
854
+                    wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
855
+                    wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
856
+                    set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
857
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
858
+                } else {
859
+                    wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
860
+                    wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
861
+                    set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
862
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
863
+                }
864
+            }
865
+        }
866
+
867
+        $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
868
+
869
+        if ( isset( $data['step'] ) ) {
870
+            $redirect = add_query_arg( 'step', $data['step'], $redirect );
871
+        }
872
+        wp_redirect( $redirect );
873
+        exit;
874
+    }
875 875
 
876 876
 }
Please login to merge, or discard this patch.
Spacing   +185 added lines, -185 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', 'refunds' );
27
+    protected $supports = array('subscription', 'sandbox', 'single_subscription_group', 'refunds');
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.
@@ -81,22 +81,22 @@  discard block
 block discarded – undo
81 81
 	public function __construct() {
82 82
 		parent::__construct();
83 83
 
84
-        $this->title                = __( 'PayPal Standard', 'invoicing' );
85
-        $this->method_title         = __( 'PayPal Standard', 'invoicing' );
86
-        $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
87
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
88
-
89
-		add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 );
90
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
91
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
92
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
93
-		add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
94
-
95
-		if ( $this->enabled ) {
96
-			add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
97
-			add_action( 'getpaid_paypal_subscription_cancelled', array( $this, 'subscription_cancelled' ) );
98
-			add_action( 'getpaid_delete_subscription', array( $this, 'subscription_cancelled' ) );
99
-			add_action( 'getpaid_refund_invoice_remotely', array( $this, 'refund_invoice' ) );
84
+        $this->title                = __('PayPal Standard', 'invoicing');
85
+        $this->method_title         = __('PayPal Standard', 'invoicing');
86
+        $this->checkout_button_text = __('Proceed to PayPal', 'invoicing');
87
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
88
+
89
+		add_filter('wpinv_subscription_cancel_url', array($this, 'filter_cancel_subscription_url'), 10, 2);
90
+		add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2);
91
+		add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2);
92
+		add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal'));
93
+		add_action('wpinv_paypal_connect', array($this, 'display_connect_buttons'));
94
+
95
+		if ($this->enabled) {
96
+			add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice'));
97
+			add_action('getpaid_paypal_subscription_cancelled', array($this, 'subscription_cancelled'));
98
+			add_action('getpaid_delete_subscription', array($this, 'subscription_cancelled'));
99
+			add_action('getpaid_refund_invoice_remotely', array($this, 'refund_invoice'));
100 100
 		}
101 101
     }
102 102
 
@@ -109,16 +109,16 @@  discard block
 block discarded – undo
109 109
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
110 110
 	 * @return array
111 111
 	 */
112
-	public function process_payment( $invoice, $submission_data, $submission ) {
112
+	public function process_payment($invoice, $submission_data, $submission) {
113 113
 
114 114
         // Get redirect url.
115
-        $paypal_redirect = $this->get_request_url( $invoice );
115
+        $paypal_redirect = $this->get_request_url($invoice);
116 116
 
117 117
         // Add a note about the request url.
118 118
         $invoice->add_note(
119 119
             sprintf(
120
-                __( 'Redirecting to PayPal: %s', 'invoicing' ),
121
-                esc_url( $paypal_redirect )
120
+                __('Redirecting to PayPal: %s', 'invoicing'),
121
+                esc_url($paypal_redirect)
122 122
             ),
123 123
             false,
124 124
             false,
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         );
127 127
 
128 128
         // Redirect to PayPal
129
-        wp_redirect( $paypal_redirect );
129
+        wp_redirect($paypal_redirect);
130 130
         exit;
131 131
 
132 132
     }
@@ -137,21 +137,21 @@  discard block
 block discarded – undo
137 137
 	 * @param  WPInv_Invoice $invoice Invoice object.
138 138
 	 * @return string
139 139
 	 */
140
-	public function get_request_url( $invoice ) {
140
+	public function get_request_url($invoice) {
141 141
 
142 142
         // Endpoint for this request
143
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
143
+		$this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
144 144
 
145 145
         // Retrieve paypal args.
146
-        $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
146
+        $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode');
147 147
 
148
-        if ( $invoice->is_recurring() ) {
148
+        if ($invoice->is_recurring()) {
149 149
             $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US';
150 150
         } else {
151 151
             $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US';
152 152
         }
153 153
 
154
-        return add_query_arg( $paypal_args, $this->endpoint );
154
+        return add_query_arg($paypal_args, $this->endpoint);
155 155
 
156 156
 	}
157 157
 
@@ -161,25 +161,25 @@  discard block
 block discarded – undo
161 161
 	 * @param  WPInv_Invoice $invoice Invoice object.
162 162
 	 * @return array
163 163
 	 */
164
-	protected function get_paypal_args( $invoice ) {
164
+	protected function get_paypal_args($invoice) {
165 165
 
166 166
         // Whether or not to send the line items as one item.
167
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
167
+		$force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice);
168 168
 
169
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
169
+		if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) {
170 170
 			$force_one_line_item = true;
171 171
 		}
172 172
 
173 173
 		$paypal_args = apply_filters(
174 174
 			'getpaid_paypal_args',
175 175
 			array_merge(
176
-				$this->get_transaction_args( $invoice ),
177
-				$this->get_line_item_args( $invoice, $force_one_line_item )
176
+				$this->get_transaction_args($invoice),
177
+				$this->get_line_item_args($invoice, $force_one_line_item)
178 178
 			),
179 179
 			$invoice
180 180
 		);
181 181
 
182
-		return $this->fix_request_length( $invoice, $paypal_args );
182
+		return $this->fix_request_length($invoice, $paypal_args);
183 183
     }
184 184
 
185 185
     /**
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
 	 * @param WPInv_Invoice $invoice Invoice object.
189 189
 	 * @return array
190 190
 	 */
191
-	protected function get_transaction_args( $invoice ) {
191
+	protected function get_transaction_args($invoice) {
192 192
 
193
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
193
+		$email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', '');
194 194
 		return array(
195 195
             'cmd'           => '_cart',
196 196
             'business'      => $email,
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
             'rm'            => is_ssl() ? 2 : 1,
202 202
             'upload'        => 1,
203 203
             'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal
204
-            'return'        => esc_url_raw( $this->get_return_url( $invoice ) ),
205
-            'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ),
206
-            'notify_url'    => getpaid_limit_length( $this->notify_url, 255 ),
207
-            'invoice'       => getpaid_limit_length( $invoice->get_number(), 127 ),
204
+            'return'        => esc_url_raw($this->get_return_url($invoice)),
205
+            'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()),
206
+            'notify_url'    => getpaid_limit_length($this->notify_url, 255),
207
+            'invoice'       => getpaid_limit_length($invoice->get_number(), 127),
208 208
             'custom'        => $invoice->get_id(),
209
-            'first_name'    => getpaid_limit_length( $invoice->get_first_name(), 32 ),
210
-            'last_name'     => getpaid_limit_length( $invoice->get_last_name(), 64 ),
211
-            'country'       => getpaid_limit_length( $invoice->get_country(), 2 ),
212
-            'email'         => getpaid_limit_length( $invoice->get_email(), 127 ),
213
-            'cbt'           => get_bloginfo( 'name' ),
209
+            'first_name'    => getpaid_limit_length($invoice->get_first_name(), 32),
210
+            'last_name'     => getpaid_limit_length($invoice->get_last_name(), 64),
211
+            'country'       => getpaid_limit_length($invoice->get_country(), 2),
212
+            'email'         => getpaid_limit_length($invoice->get_email(), 127),
213
+            'cbt'           => get_bloginfo('name'),
214 214
         );
215 215
 
216 216
     }
@@ -222,30 +222,30 @@  discard block
 block discarded – undo
222 222
 	 * @param  bool     $force_one_line_item Create only one item for this invoice.
223 223
 	 * @return array
224 224
 	 */
225
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
225
+	protected function get_line_item_args($invoice, $force_one_line_item = false) {
226 226
 
227 227
         // Maybe send invoice as a single item.
228
-		if ( $force_one_line_item ) {
229
-            return $this->get_line_item_args_single_item( $invoice );
228
+		if ($force_one_line_item) {
229
+            return $this->get_line_item_args_single_item($invoice);
230 230
         }
231 231
 
232 232
         // Send each line item individually.
233 233
         $line_item_args = array();
234 234
 
235 235
         // Prepare line items.
236
-        $this->prepare_line_items( $invoice );
236
+        $this->prepare_line_items($invoice);
237 237
 
238 238
         // Add taxes to the cart
239
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
240
-            $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 );
239
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
240
+            $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2);
241 241
         }
242 242
 
243 243
         // Add discount.
244
-        if ( $invoice->get_total_discount() > 0 ) {
245
-            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
244
+        if ($invoice->get_total_discount() > 0) {
245
+            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2);
246 246
         }
247 247
 
248
-		return array_merge( $line_item_args, $this->get_line_items() );
248
+		return array_merge($line_item_args, $this->get_line_items());
249 249
 
250 250
     }
251 251
 
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
 	 * @param  WPInv_Invoice $invoice Invoice object.
256 256
 	 * @return array
257 257
 	 */
258
-	protected function get_line_item_args_single_item( $invoice ) {
258
+	protected function get_line_item_args_single_item($invoice) {
259 259
 		$this->delete_line_items();
260 260
 
261
-        $item_name = wp_sprintf( __( 'Invoice %s', 'invoicing' ), $invoice->get_number() );
262
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
261
+        $item_name = wp_sprintf(__('Invoice %s', 'invoicing'), $invoice->get_number());
262
+		$this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id());
263 263
 
264 264
 		return $this->get_line_items();
265 265
     }
@@ -283,19 +283,19 @@  discard block
 block discarded – undo
283 283
 	 *
284 284
 	 * @param  WPInv_Invoice $invoice Invoice object.
285 285
 	 */
286
-	protected function prepare_line_items( $invoice ) {
286
+	protected function prepare_line_items($invoice) {
287 287
 		$this->delete_line_items();
288 288
 
289 289
 		// Items.
290
-		foreach ( $invoice->get_items() as $item ) {
290
+		foreach ($invoice->get_items() as $item) {
291 291
 			$amount   = $item->get_price();
292 292
 			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
293
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
293
+			$this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id());
294 294
         }
295 295
 
296 296
         // Fees.
297
-		foreach ( $invoice->get_fees() as $fee => $data ) {
298
-            $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
297
+		foreach ($invoice->get_fees() as $fee => $data) {
298
+            $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee']));
299 299
         }
300 300
 
301 301
     }
@@ -308,20 +308,20 @@  discard block
 block discarded – undo
308 308
 	 * @param  float  $amount Amount.
309 309
 	 * @param  string $item_number Item number.
310 310
 	 */
311
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
312
-		$index = ( count( $this->line_items ) / 4 ) + 1;
311
+	protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') {
312
+		$index = (count($this->line_items) / 4) + 1;
313 313
 
314 314
 		/**
315 315
 		 * Prevent error "Things don't appear to be working at the moment. (https://www.sandbox.paypal.com/webapps/hermes/error)"
316 316
 		 */
317
-		$item_name = str_replace( "#", "", $item_name );
317
+		$item_name = str_replace("#", "", $item_name);
318 318
 
319 319
 		$item = apply_filters(
320 320
 			'getpaid_paypal_line_item',
321 321
 			array(
322
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
322
+				'item_name'   => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'),
323 323
 				'quantity'    => (float) $quantity,
324
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
324
+				'amount'      => wpinv_sanitize_amount((float) $amount, 2),
325 325
 				'item_number' => $item_number,
326 326
 			),
327 327
 			$item_name,
@@ -330,12 +330,12 @@  discard block
 block discarded – undo
330 330
 			$item_number
331 331
 		);
332 332
 
333
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
334
-        $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
333
+		$this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127);
334
+        $this->line_items['quantity_' . $index] = $item['quantity'];
335 335
 
336 336
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
337
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
338
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
337
+		$this->line_items['amount_' . $index]      = $item['amount'] * $item['quantity'];
338
+		$this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127);
339 339
     }
340 340
 
341 341
     /**
@@ -347,19 +347,19 @@  discard block
 block discarded – undo
347 347
 	 * @param array    $paypal_args Arguments sent to Paypal in the request.
348 348
 	 * @return array
349 349
 	 */
350
-	protected function fix_request_length( $invoice, $paypal_args ) {
350
+	protected function fix_request_length($invoice, $paypal_args) {
351 351
 		$max_paypal_length = 2083;
352
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
352
+		$query_candidate   = http_build_query($paypal_args, '', '&');
353 353
 
354
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
354
+		if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) {
355 355
 			return $paypal_args;
356 356
 		}
357 357
 
358 358
 		return apply_filters(
359 359
 			'getpaid_paypal_args',
360 360
 			array_merge(
361
-				$this->get_transaction_args( $invoice ),
362
-				$this->get_line_item_args( $invoice, true )
361
+				$this->get_transaction_args($invoice),
362
+				$this->get_line_item_args($invoice, true)
363 363
 			),
364 364
 			$invoice
365 365
 		);
@@ -372,10 +372,10 @@  discard block
 block discarded – undo
372 372
 	 * @param  array $paypal_args PayPal args.
373 373
 	 * @param  WPInv_Invoice    $invoice Invoice object.
374 374
 	 */
375
-	public function process_subscription( $paypal_args, $invoice ) {
375
+	public function process_subscription($paypal_args, $invoice) {
376 376
 
377 377
         // Make sure this is a subscription.
378
-        if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
378
+        if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) {
379 379
             return $paypal_args;
380 380
         }
381 381
 
@@ -383,23 +383,23 @@  discard block
 block discarded – undo
383 383
         $paypal_args['cmd'] = '_xclick-subscriptions';
384 384
 
385 385
         // Subscription name.
386
-        $paypal_args['item_name'] = wp_sprintf( __( 'Invoice %s', 'invoicing' ), $invoice->get_number() );
386
+        $paypal_args['item_name'] = wp_sprintf(__('Invoice %s', 'invoicing'), $invoice->get_number());
387 387
 
388 388
         // Get subscription args.
389
-        $period                 = strtoupper( substr( $subscription->get_period(), 0, 1 ) );
389
+        $period                 = strtoupper(substr($subscription->get_period(), 0, 1));
390 390
         $interval               = (int) $subscription->get_frequency();
391 391
         $bill_times             = (int) $subscription->get_bill_times();
392
-        $initial_amount         = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 );
393
-        $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
394
-        $subscription_item      = $invoice->get_recurring( true );
392
+        $initial_amount         = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2);
393
+        $recurring_amount       = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2);
394
+        $subscription_item      = $invoice->get_recurring(true);
395 395
 
396 396
 		// Convert 365 days to 1 year.
397
-		if ( 'D' == $period && 365 == $interval ) {
397
+		if ('D' == $period && 365 == $interval) {
398 398
 			$period = 'Y';
399 399
 			$interval = 1;
400 400
 		}
401 401
 
402
-        if ( $subscription_item->has_free_trial() ) {
402
+        if ($subscription_item->has_free_trial()) {
403 403
 
404 404
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
405 405
 
@@ -409,28 +409,28 @@  discard block
 block discarded – undo
409 409
 			// Trial period.
410 410
 			$paypal_args['t1'] = $subscription_item->get_trial_period();
411 411
 
412
-        } elseif ( $initial_amount != $recurring_amount ) {
412
+        } elseif ($initial_amount != $recurring_amount) {
413 413
 
414 414
             // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period.
415 415
 
416
-            if ( 1 == $bill_times ) {
416
+            if (1 == $bill_times) {
417 417
                 $param_number = 3;
418 418
             } else {
419 419
                 $param_number = 1;
420 420
             }
421 421
 
422
-            $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0;
422
+            $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0;
423 423
 
424 424
             // Sign Up interval
425
-            $paypal_args[ 'p' . $param_number ] = $interval;
425
+            $paypal_args['p' . $param_number] = $interval;
426 426
 
427 427
             // Sign Up unit of duration
428
-            $paypal_args[ 't' . $param_number ] = $period;
428
+            $paypal_args['t' . $param_number] = $period;
429 429
 
430 430
         }
431 431
 
432 432
         // We have a recurring payment
433
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
433
+		if (!isset($param_number) || 1 == $param_number) {
434 434
 
435 435
 			// Subscription price
436 436
 			$paypal_args['a3'] = $recurring_amount;
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
         }
445 445
 
446 446
         // Recurring payments
447
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
447
+		if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) {
448 448
 
449 449
 			// Non-recurring payments
450 450
 			$paypal_args['src'] = 0;
@@ -453,15 +453,15 @@  discard block
 block discarded – undo
453 453
 
454 454
 			$paypal_args['src'] = 1;
455 455
 
456
-			if ( $bill_times > 0 ) {
456
+			if ($bill_times > 0) {
457 457
 
458 458
 				// An initial period is being used to charge a sign-up fee
459
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
459
+				if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) {
460 460
 					$bill_times--;
461 461
 				}
462 462
 
463 463
                 // Make sure it's not over the max of 52
464
-                $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
464
+                $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
465 465
 
466 466
 			}
467 467
         }
@@ -470,10 +470,10 @@  discard block
 block discarded – undo
470 470
         $paypal_args['rm'] = 2;
471 471
 
472 472
         // Get rid of redudant items.
473
-        foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) {
473
+        foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) {
474 474
 
475
-            if ( isset( $paypal_args[ $arg ] ) ) {
476
-                unset( $paypal_args[ $arg ] );
475
+            if (isset($paypal_args[$arg])) {
476
+                unset($paypal_args[$arg]);
477 477
             }
478 478
 		}
479 479
 
@@ -491,20 +491,20 @@  discard block
 block discarded – undo
491 491
 	 * @since 2.8.24
492 492
 	 * @param WPInv_Invoice $invoice Invoice object.
493 493
 	 */
494
-	public function refund_invoice( $invoice ) {
494
+	public function refund_invoice($invoice) {
495 495
 
496
-		if ( $invoice->get_gateway() !== $this->id ) {
496
+		if ($invoice->get_gateway() !== $this->id) {
497 497
 			return;
498 498
 		}
499 499
 
500
-		$mode	= $this->is_sandbox( $invoice ) ? 'sandbox' : 'live';
501
-		$result = GetPaid_PayPal_API::refund_capture( $invoice->get_transaction_id(), array(), $mode );
500
+		$mode = $this->is_sandbox($invoice) ? 'sandbox' : 'live';
501
+		$result = GetPaid_PayPal_API::refund_capture($invoice->get_transaction_id(), array(), $mode);
502 502
 
503
-		if ( is_wp_error( $result ) ) {
503
+		if (is_wp_error($result)) {
504 504
 			$invoice->add_system_note(
505 505
 				sprintf(
506 506
 					// translators: %s is the error message.
507
-					__( 'An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing' ),
507
+					__('An error occured while trying to refund invoice #%1$s in PayPal: %2$s', 'invoicing'),
508 508
 					$invoice->get_id(),
509 509
 					$result->get_error_message()
510 510
 				)
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 			$invoice->add_system_note(
514 514
 				sprintf(
515 515
 					// translators: %s is the refund ID.
516
-					__( 'Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing' ),
516
+					__('Successfully refunded invoice #%1$s in PayPal. Refund ID: %2$s', 'invoicing'),
517 517
 					$invoice->get_id(),
518 518
 					$result->id
519 519
 				)
@@ -527,50 +527,50 @@  discard block
 block discarded – undo
527 527
 	 * @since 2.8.24
528 528
 	 * @param WPInv_Subscription $subscription Subscription object.
529 529
 	 */
530
-	public function subscription_cancelled( $subscription ) {
530
+	public function subscription_cancelled($subscription) {
531 531
 
532
-		if ( $subscription->get_gateway() != $this->id ) {
532
+		if ($subscription->get_gateway() != $this->id) {
533 533
 			return;
534 534
 		}
535 535
 
536 536
 		$invoice = $subscription->get_parent_invoice();
537 537
 
538 538
 		// Abort if the parent invoice does not exist.
539
-		if ( ! $invoice->exists() ) {
539
+		if (!$invoice->exists()) {
540 540
 			return;
541 541
 		}
542 542
 
543
-		$mode	= $this->is_sandbox( $invoice ) ? 'sandbox' : 'live';
543
+		$mode = $this->is_sandbox($invoice) ? 'sandbox' : 'live';
544 544
 		$result = GetPaid_PayPal_API::cancel_subscription( 
545 545
 			$invoice->get_remote_subscription_id(), 
546 546
 			array(
547
-				'reason' => __(' Customer requested cancellation', 'invoicing' ),
547
+				'reason' => __(' Customer requested cancellation', 'invoicing'),
548 548
 			), 
549 549
 			$mode 
550 550
 		);
551 551
 
552
-		if ( is_wp_error( $result ) ) {
552
+		if (is_wp_error($result)) {
553 553
 
554 554
 			$error = sprintf(
555 555
 				// translators: %s is the subscription ID.
556
-				__( 'An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing' ),
556
+				__('An error occured while trying to cancel subscription #%s in PayPal.', 'invoicing'),
557 557
 				$subscription->get_id()
558 558
 			);
559 559
 
560
-			getpaid_admin()->show_error( $error . ' ' . $result->get_error_message() );
560
+			getpaid_admin()->show_error($error . ' ' . $result->get_error_message());
561 561
 
562
-			if ( ! is_admin() ) {
563
-				wpinv_set_error( $result->get_error_code(), $error );
562
+			if (!is_admin()) {
563
+				wpinv_set_error($result->get_error_code(), $error);
564 564
 			}
565 565
 
566 566
 			return;
567 567
 		}
568 568
 
569
-		if ( is_admin() ) {
569
+		if (is_admin()) {
570 570
 			getpaid_admin()->show_success(
571 571
 				sprintf(
572 572
 					// translators: %s is the subscription ID.
573
-					__( 'Successfully cancelled subscription #%s in PayPal.', 'invoicing' ),
573
+					__('Successfully cancelled subscription #%s in PayPal.', 'invoicing'),
574 574
 					$subscription->get_id()
575 575
 				)
576 576
 			);
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
 	 * @return void
585 585
 	 */
586 586
 	public function verify_ipn() {
587
-        new GetPaid_Paypal_Gateway_IPN_Handler( $this );
587
+        new GetPaid_Paypal_Gateway_IPN_Handler($this);
588 588
     }
589 589
 
590 590
     /**
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
     public function sandbox_notice() {
594 594
 
595 595
         return sprintf(
596
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
596
+			__('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing'),
597 597
 			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
598 598
 			'</a>'
599 599
 		);
@@ -605,41 +605,41 @@  discard block
 block discarded – undo
605 605
 	 *
606 606
 	 * @param array $admin_settings
607 607
 	 */
608
-	public function admin_settings( $admin_settings ) {
608
+	public function admin_settings($admin_settings) {
609 609
 
610 610
         $currencies = sprintf(
611
-            __( 'Supported Currencies: %s', 'invoicing' ),
612
-            implode( ', ', $this->currencies )
611
+            __('Supported Currencies: %s', 'invoicing'),
612
+            implode(', ', $this->currencies)
613 613
         );
614 614
 
615 615
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
616
-        $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
616
+        $admin_settings['paypal_desc']['std']     = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
617 617
 
618 618
 		// Access tokens.
619
-		$live_email      = wpinv_get_option( 'paypal_email' );
620
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
619
+		$live_email      = wpinv_get_option('paypal_email');
620
+		$sandbox_email   = wpinv_get_option('paypal_sandbox_email');
621 621
 
622 622
 		$admin_settings['paypal_connect'] = array(
623 623
 			'type' => 'hook',
624 624
 			'id'   => 'paypal_connect',
625
-			'name' => __( 'Connect to PayPal', 'invoicing' ),
625
+			'name' => __('Connect to PayPal', 'invoicing'),
626 626
 		);
627 627
 
628 628
         $admin_settings['paypal_email'] = array(
629 629
             'type'  => 'text',
630 630
 			'class' => 'live-auth-data',
631 631
             'id'    => 'paypal_email',
632
-            'name'  => __( 'Live Email Address', 'invoicing' ),
633
-            'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
632
+            'name'  => __('Live Email Address', 'invoicing'),
633
+            'desc'  => __('The email address of your PayPal account.', 'invoicing'),
634 634
         );
635 635
 
636 636
 		$admin_settings['paypal_sandbox_email'] = array(
637 637
             'type'  => 'text',
638 638
 			'class' => 'sandbox-auth-data',
639 639
             'id'    => 'paypal_sandbox_email',
640
-            'name'  => __( 'Sandbox Email Address', 'invoicing' ),
641
-            'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
642
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
640
+            'name'  => __('Sandbox Email Address', 'invoicing'),
641
+            'desc'  => __('The email address of your sandbox PayPal account.', 'invoicing'),
642
+			'std'   => wpinv_get_option('paypal_email', ''),
643 643
         );
644 644
 
645 645
 		// Client ID and secret.
@@ -647,41 +647,41 @@  discard block
 block discarded – undo
647 647
 			'type'  => 'text',
648 648
 			'class' => 'live-auth-data',
649 649
 			'id'    => 'paypal_client_id',
650
-			'name'  => __( 'Live Client ID', 'invoicing' ),
651
-			'desc'  => __( 'The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
650
+			'name'  => __('Live Client ID', 'invoicing'),
651
+			'desc'  => __('The client ID of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'),
652 652
 		);
653 653
 
654 654
 		$admin_settings['paypal_sandbox_client_id'] = array(
655 655
 			'type'  => 'text',
656 656
 			'class' => 'sandbox-auth-data',
657 657
 			'id'    => 'paypal_sandbox_client_id',
658
-			'name'  => __( 'Sandbox Client ID', 'invoicing' ),
659
-			'desc'  => __( 'The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
660
-			'std'   => wpinv_get_option( 'paypal_client_id', '' ),
658
+			'name'  => __('Sandbox Client ID', 'invoicing'),
659
+			'desc'  => __('The client ID of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'),
660
+			'std'   => wpinv_get_option('paypal_client_id', ''),
661 661
 		);
662 662
 
663 663
 		$admin_settings['paypal_secret'] = array(
664 664
 			'type'  => 'text',
665 665
 			'class' => 'live-auth-data',
666 666
 			'id'    => 'paypal_secret',
667
-			'name'  => __( 'Live Secret', 'invoicing' ),
668
-			'desc'  => __( 'The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
667
+			'name'  => __('Live Secret', 'invoicing'),
668
+			'desc'  => __('The secret of your PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'),
669 669
 		);
670 670
 
671 671
 		$admin_settings['paypal_sandbox_secret'] = array(
672 672
 			'type'  => 'text',
673 673
 			'class' => 'sandbox-auth-data',
674 674
 			'id'    => 'paypal_sandbox_secret',
675
-			'name'  => __( 'Sandbox Secret', 'invoicing' ),
676
-			'desc'  => __( 'The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing' ),
675
+			'name'  => __('Sandbox Secret', 'invoicing'),
676
+			'desc'  => __('The secret of your sandbox PayPal account. You can retrieve this from your PayPal developer account.', 'invoicing'),
677 677
 		);
678 678
 
679 679
         $admin_settings['paypal_ipn_url'] = array(
680 680
             'type'     => 'ipn_url',
681 681
             'id'       => 'paypal_ipn_url',
682
-            'name'     => __( 'IPN Url', 'invoicing' ),
682
+            'name'     => __('IPN Url', 'invoicing'),
683 683
             'std'      => $this->notify_url,
684
-            '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>',
684
+            '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>',
685 685
             'readonly' => true,
686 686
         );
687 687
 
@@ -694,9 +694,9 @@  discard block
 block discarded – undo
694 694
 	 * @param string $url
695 695
 	 * @param WPInv_Subscription $subscription
696 696
 	 */
697
-	public function filter_cancel_subscription_url( $url, $subscription ) {
697
+	public function filter_cancel_subscription_url($url, $subscription) {
698 698
 
699
-		if ( $this->id !== $subscription->get_gateway() ) {
699
+		if ($this->id !== $subscription->get_gateway()) {
700 700
 			return $url;
701 701
 		}
702 702
 
@@ -704,16 +704,16 @@  discard block
 block discarded – undo
704 704
 		$profile_id = $subscription->get_profile_id();
705 705
 
706 706
 		// Bail if no profile ID.
707
-		if ( empty( $profile_id ) ) {
707
+		if (empty($profile_id)) {
708 708
 			return $url;
709 709
 		}
710 710
 
711 711
 		$cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel';
712
-		if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) {
712
+		if ($this->is_sandbox($subscription->get_parent_payment())) {
713 713
 			$cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel';
714 714
 		}
715 715
 
716
-		return sprintf( $cancel_url, $profile_id );
716
+		return sprintf($cancel_url, $profile_id);
717 717
 	}
718 718
 
719 719
 	/**
@@ -723,8 +723,8 @@  discard block
 block discarded – undo
723 723
      * @param array $data
724 724
      * @return string
725 725
 	 */
726
-	public static function maybe_get_connect_url( $url = '', $data = array() ) {
727
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
726
+	public static function maybe_get_connect_url($url = '', $data = array()) {
727
+		return self::get_connect_url(false, urldecode($data['redirect']));
728 728
 	}
729 729
 
730 730
 	/**
@@ -735,25 +735,25 @@  discard block
 block discarded – undo
735 735
 	 * @param string $redirect
736 736
      * @return string
737 737
 	 */
738
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
738
+	public static function get_connect_url($is_sandbox, $redirect = '') {
739 739
 
740 740
         $redirect_url = add_query_arg(
741 741
             array(
742 742
                 'getpaid-admin-action' => 'connect_paypal',
743 743
                 'page'                 => 'wpinv-settings',
744
-                'live_mode'            => (int) empty( $is_sandbox ),
744
+                'live_mode'            => (int) empty($is_sandbox),
745 745
                 'tab'                  => 'gateways',
746 746
                 'section'              => 'paypal',
747
-                'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
748
-				'redirect'             => urlencode( $redirect ),
747
+                'getpaid-nonce'        => wp_create_nonce('getpaid-nonce'),
748
+				'redirect'             => urlencode($redirect),
749 749
             ),
750
-            admin_url( 'admin.php' )
750
+            admin_url('admin.php')
751 751
         );
752 752
 
753 753
         return add_query_arg(
754 754
             array(
755
-                'live_mode'    => (int) empty( $is_sandbox ),
756
-                'redirect_url' => urlencode( str_replace( '&amp;', '&', $redirect_url ) ),
755
+                'live_mode'    => (int) empty($is_sandbox),
756
+                'redirect_url' => urlencode(str_replace('&amp;', '&', $redirect_url)),
757 757
             ),
758 758
             'https://ayecode.io/oauth/paypal'
759 759
         );
@@ -769,10 +769,10 @@  discard block
 block discarded – undo
769 769
 
770 770
         ?>
771 771
 			<div class="wpinv-paypal-connect-live">
772
-				<a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( false ) ); ?>"><?php esc_html_e( 'Connect to PayPal', 'invoicing' ); ?></a>
772
+				<a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(false)); ?>"><?php esc_html_e('Connect to PayPal', 'invoicing'); ?></a>
773 773
 			</div>
774 774
 			<div class="wpinv-paypal-connect-sandbox">
775
-				<a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( true ) ); ?>"><?php esc_html_e( 'Connect to PayPal Sandbox', 'invoicing' ); ?></a>
775
+				<a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(true)); ?>"><?php esc_html_e('Connect to PayPal Sandbox', 'invoicing'); ?></a>
776 776
 			</div>
777 777
 
778 778
             <script>
@@ -813,26 +813,26 @@  discard block
 block discarded – undo
813 813
 	 * @param array $data Connection data.
814 814
 	 * @return void
815 815
 	 */
816
-	public function connect_paypal( $data ) {
816
+	public function connect_paypal($data) {
817 817
 
818 818
 		$sandbox      = $this->is_sandbox();
819
-		$data         = wp_unslash( $data );
820
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
819
+		$data         = wp_unslash($data);
820
+		$access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']);
821 821
 
822
-		if ( isset( $data['live_mode'] ) ) {
823
-			$sandbox = empty( $data['live_mode'] );
822
+		if (isset($data['live_mode'])) {
823
+			$sandbox = empty($data['live_mode']);
824 824
 		}
825 825
 
826
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
827
-		wpinv_update_option( 'paypal_active', 1 );
826
+		wpinv_update_option('paypal_sandbox', (int) $sandbox);
827
+		wpinv_update_option('paypal_active', 1);
828 828
 
829
-		if ( ! empty( $data['error_description'] ) ) {
830
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
829
+		if (!empty($data['error_description'])) {
830
+			getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description'])));
831 831
 		} else {
832 832
 
833 833
 			// Retrieve the user info.
834 834
 			$user_info = wp_remote_get(
835
-				! $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',
835
+				!$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',
836 836
 				array(
837 837
 
838 838
 					'headers' => array(
@@ -843,33 +843,33 @@  discard block
 block discarded – undo
843 843
 				)
844 844
 			);
845 845
 
846
-			if ( is_wp_error( $user_info ) ) {
847
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
846
+			if (is_wp_error($user_info)) {
847
+				getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message()));
848 848
 			} else {
849 849
 
850 850
 				// Create application.
851
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
851
+				$user_info = json_decode(wp_remote_retrieve_body($user_info));
852 852
 
853
-				if ( $sandbox ) {
854
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
855
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
856
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
857
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
853
+				if ($sandbox) {
854
+					wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value));
855
+					wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
856
+					set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
857
+					getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing'));
858 858
 				} else {
859
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
860
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
861
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
862
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
859
+					wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value));
860
+					wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
861
+					set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
862
+					getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing'));
863 863
 				}
864 864
 			}
865 865
 		}
866 866
 
867
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
867
+		$redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways&section=paypal') : urldecode($data['redirect']);
868 868
 
869
-		if ( isset( $data['step'] ) ) {
870
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
869
+		if (isset($data['step'])) {
870
+			$redirect = add_query_arg('step', $data['step'], $redirect);
871 871
 		}
872
-		wp_redirect( $redirect );
872
+		wp_redirect($redirect);
873 873
 		exit;
874 874
 	}
875 875
 
Please login to merge, or discard this patch.
templates/payment-forms/elements/checkbox.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,19 +13,19 @@
 block discarded – undo
13 13
 $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) );
14 14
 
15 15
 if ( ! empty( $required ) ) {
16
-	$label .= "<span class='text-danger'> *</span>";
16
+    $label .= "<span class='text-danger'> *</span>";
17 17
 }
18 18
 
19 19
 aui()->input(
20
-	array(
21
-		'type'      => 'checkbox',
22
-		'name'      => esc_attr( $id ),
23
-		'id'        => esc_attr( $element_id ),
24
-		'required'  => ! empty( $required ),
25
-		'label'     => $label,
26
-		'value'     => esc_attr__( 'Yes', 'invoicing' ),
27
-		'help_text' => empty( $description ) ? '' : wp_kses_post( $description ),
28
-		'class'     => $label_class
29
-	),
30
-	true
20
+    array(
21
+        'type'      => 'checkbox',
22
+        'name'      => esc_attr( $id ),
23
+        'id'        => esc_attr( $element_id ),
24
+        'required'  => ! empty( $required ),
25
+        'label'     => $label,
26
+        'value'     => esc_attr__( 'Yes', 'invoicing' ),
27
+        'help_text' => empty( $description ) ? '' : wp_kses_post( $description ),
28
+        'class'     => $label_class
29
+    ),
30
+    true
31 31
 );
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -7,24 +7,24 @@
 block discarded – undo
7 7
  * @version 2.8.24
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12
-$label = empty( $label ) ? '' : wp_kses_post( $label );
13
-$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) );
12
+$label = empty($label) ? '' : wp_kses_post($label);
13
+$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label));
14 14
 
15
-if ( ! empty( $required ) ) {
15
+if (!empty($required)) {
16 16
 	$label .= "<span class='text-danger'> *</span>";
17 17
 }
18 18
 
19 19
 aui()->input(
20 20
 	array(
21 21
 		'type'      => 'checkbox',
22
-		'name'      => esc_attr( $id ),
23
-		'id'        => esc_attr( $element_id ),
24
-		'required'  => ! empty( $required ),
22
+		'name'      => esc_attr($id),
23
+		'id'        => esc_attr($element_id),
24
+		'required'  => !empty($required),
25 25
 		'label'     => $label,
26
-		'value'     => esc_attr__( 'Yes', 'invoicing' ),
27
-		'help_text' => empty( $description ) ? '' : wp_kses_post( $description ),
26
+		'value'     => esc_attr__('Yes', 'invoicing'),
27
+		'help_text' => empty($description) ? '' : wp_kses_post($description),
28 28
 		'class'     => $label_class
29 29
 	),
30 30
 	true
Please login to merge, or discard this patch.
templates/payment-forms/elements/address.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 defined( 'ABSPATH' ) || exit;
11 11
 
12 12
 if ( empty( $fields ) ) {
13
-	return;
13
+    return;
14 14
 }
15 15
 
16 16
 // A prefix for all ids (so that a form can be included in the same page multiple times).
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
 
19 19
 // Prepare the user's country.
20 20
 if ( ! empty( $form->invoice ) ) {
21
-	$country = $form->invoice->get_country();
21
+    $country = $form->invoice->get_country();
22 22
 }
23 23
 
24 24
 if ( empty( $country ) ) {
25
-	$country = empty( $country ) ? getpaid_get_ip_country() : $country;
26
-	$country = empty( $country ) ? wpinv_get_default_country() : $country;
25
+    $country = empty( $country ) ? getpaid_get_ip_country() : $country;
26
+    $country = empty( $country ) ? wpinv_get_default_country() : $country;
27 27
 }
28 28
 
29 29
 // A prefix for all ids (so that a form can be included in the same page multiple times).
@@ -50,32 +50,32 @@  discard block
 block discarded – undo
50 50
 	<!-- Start Billing Address -->
51 51
 	<div class="getpaid-billing-address-wrapper">
52 52
 		<?php
53
-			$field_type = 'billing';
53
+            $field_type = 'billing';
54 54
 
55
-			wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) );
55
+            wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) );
56 56
 
57
-			do_action( 'getpaid_after_payment_form_billing_fields', $form );
58
-		?>
57
+            do_action( 'getpaid_after_payment_form_billing_fields', $form );
58
+        ?>
59 59
 	</div>
60 60
 	<!-- End Billing Address -->
61 61
 <?php endif; ?>
62 62
 
63 63
 <?php if ( 'both' === $address_type ) : ?>
64 64
 	<?php
65
-		aui()->input(
66
-			array(
67
-				'type'     => 'checkbox',
68
-				'name'     => 'same-shipping-address',
69
-				'id'       => "shipping-toggle$uniqid",
70
-				'required' => false,
71
-				'label'    => empty( $shipping_address_toggle ) ? esc_html__( 'Same billing & shipping address.', 'invoicing' ) : wp_kses_post( $shipping_address_toggle ),
72
-				'value'    => 1,
73
-				'checked'  => true,
74
-				'class'    => 'chkbox-same-shipping-address'
75
-			),
76
-			true
77
-		);
78
-	?>
65
+        aui()->input(
66
+            array(
67
+                'type'     => 'checkbox',
68
+                'name'     => 'same-shipping-address',
69
+                'id'       => "shipping-toggle$uniqid",
70
+                'required' => false,
71
+                'label'    => empty( $shipping_address_toggle ) ? esc_html__( 'Same billing & shipping address.', 'invoicing' ) : wp_kses_post( $shipping_address_toggle ),
72
+                'value'    => 1,
73
+                'checked'  => true,
74
+                'class'    => 'chkbox-same-shipping-address'
75
+            ),
76
+            true
77
+        );
78
+    ?>
79 79
 	<!-- Start Shipping Address Title -->
80 80
 	<h4 class="mb-3 getpaid-shipping-address-title">
81 81
 		<?php esc_html_e( 'Shipping Address', 'invoicing' ); ?>
@@ -87,12 +87,12 @@  discard block
 block discarded – undo
87 87
 	<!-- Start Shipping Address -->
88 88
 	<div class="getpaid-shipping-address-wrapper">
89 89
 		<?php
90
-			$field_type = 'shipping';
90
+            $field_type = 'shipping';
91 91
 
92
-			wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) );
92
+            wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) );
93 93
 
94
-			do_action( 'getpaid_after_payment_form_shipping_fields', $form );
95
-		?>
94
+            do_action( 'getpaid_after_payment_form_shipping_fields', $form );
95
+        ?>
96 96
 	</div>
97 97
 	<!-- End Shipping Address -->
98 98
 <?php endif; ?>
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -7,60 +7,60 @@  discard block
 block discarded – undo
7 7
  * @version 2.8.24
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12
-if ( empty( $fields ) ) {
12
+if (empty($fields)) {
13 13
 	return;
14 14
 }
15 15
 
16 16
 // A prefix for all ids (so that a form can be included in the same page multiple times).
17
-$uniqid = uniqid( '_' );
17
+$uniqid = uniqid('_');
18 18
 
19 19
 // Prepare the user's country.
20
-if ( ! empty( $form->invoice ) ) {
20
+if (!empty($form->invoice)) {
21 21
 	$country = $form->invoice->get_country();
22 22
 }
23 23
 
24
-if ( empty( $country ) ) {
25
-	$country = empty( $country ) ? getpaid_get_ip_country() : $country;
26
-	$country = empty( $country ) ? wpinv_get_default_country() : $country;
24
+if (empty($country)) {
25
+	$country = empty($country) ? getpaid_get_ip_country() : $country;
26
+	$country = empty($country) ? wpinv_get_default_country() : $country;
27 27
 }
28 28
 
29 29
 // A prefix for all ids (so that a form can be included in the same page multiple times).
30
-$uniqid = uniqid( '_' );
30
+$uniqid = uniqid('_');
31 31
 
32
-$address_type = empty( $address_type ) ? 'billing' : $address_type;
32
+$address_type = empty($address_type) ? 'billing' : $address_type;
33 33
 ?>
34 34
 
35
-<?php if ( 'both' === $address_type ) : ?>
35
+<?php if ('both' === $address_type) : ?>
36 36
 	<!-- Start Billing/Shipping Address Title -->
37 37
 	<h4 class="mb-3 getpaid-shipping-billing-address-title">
38
-		<?php esc_html_e( 'Billing / Shipping Address', 'invoicing' ); ?>
38
+		<?php esc_html_e('Billing / Shipping Address', 'invoicing'); ?>
39 39
 	</h4>
40 40
 	<!-- End Billing Address Title -->
41 41
 
42 42
 	<!-- Start Billing Address Title -->
43 43
 	<h4 class="mb-3 getpaid-billing-address-title">
44
-		<?php esc_html_e( 'Billing Address', 'invoicing' ); ?>
44
+		<?php esc_html_e('Billing Address', 'invoicing'); ?>
45 45
 	</h4>
46 46
 	<!-- End Billing Address Title -->
47 47
 <?php endif; ?>
48 48
 
49
-<?php if ( 'both' === $address_type || 'billing' === $address_type ) : ?>
49
+<?php if ('both' === $address_type || 'billing' === $address_type) : ?>
50 50
 	<!-- Start Billing Address -->
51 51
 	<div class="getpaid-billing-address-wrapper">
52 52
 		<?php
53 53
 			$field_type = 'billing';
54 54
 
55
-			wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) );
55
+			wpinv_get_template('payment-forms/elements/address-fields.php', array('form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country));
56 56
 
57
-			do_action( 'getpaid_after_payment_form_billing_fields', $form );
57
+			do_action('getpaid_after_payment_form_billing_fields', $form);
58 58
 		?>
59 59
 	</div>
60 60
 	<!-- End Billing Address -->
61 61
 <?php endif; ?>
62 62
 
63
-<?php if ( 'both' === $address_type ) : ?>
63
+<?php if ('both' === $address_type) : ?>
64 64
 	<?php
65 65
 		aui()->input(
66 66
 			array(
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 				'name'     => 'same-shipping-address',
69 69
 				'id'       => "shipping-toggle$uniqid",
70 70
 				'required' => false,
71
-				'label'    => empty( $shipping_address_toggle ) ? esc_html__( 'Same billing & shipping address.', 'invoicing' ) : wp_kses_post( $shipping_address_toggle ),
71
+				'label'    => empty($shipping_address_toggle) ? esc_html__('Same billing & shipping address.', 'invoicing') : wp_kses_post($shipping_address_toggle),
72 72
 				'value'    => 1,
73 73
 				'checked'  => true,
74 74
 				'class'    => 'chkbox-same-shipping-address'
@@ -78,20 +78,20 @@  discard block
 block discarded – undo
78 78
 	?>
79 79
 	<!-- Start Shipping Address Title -->
80 80
 	<h4 class="mb-3 getpaid-shipping-address-title">
81
-		<?php esc_html_e( 'Shipping Address', 'invoicing' ); ?>
81
+		<?php esc_html_e('Shipping Address', 'invoicing'); ?>
82 82
 	</h4>
83 83
 	<!-- End Shipping Address Title -->
84 84
 <?php endif; ?>
85 85
 
86
-<?php if ( 'both' === $address_type || 'shipping' === $address_type ) : ?>
86
+<?php if ('both' === $address_type || 'shipping' === $address_type) : ?>
87 87
 	<!-- Start Shipping Address -->
88 88
 	<div class="getpaid-shipping-address-wrapper">
89 89
 		<?php
90 90
 			$field_type = 'shipping';
91 91
 
92
-			wpinv_get_template( 'payment-forms/elements/address-fields.php', array( 'form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country ) );
92
+			wpinv_get_template('payment-forms/elements/address-fields.php', array('form' => $form, 'fields' => $fields, 'address_type' => $address_type, 'field_type' => $field_type, 'uniqid' => $uniqid, 'country' => $country));
93 93
 
94
-			do_action( 'getpaid_after_payment_form_shipping_fields', $form );
94
+			do_action('getpaid_after_payment_form_shipping_fields', $form);
95 95
 		?>
96 96
 	</div>
97 97
 	<!-- End Shipping Address -->
Please login to merge, or discard this patch.
includes/class-wpinv.php 2 patches
Indentation   +616 added lines, -616 removed lines patch added patch discarded remove patch
@@ -14,620 +14,620 @@
 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
-		if ( isset( $this->data[ $prop ] ) ) {
71
-			return $this->data[ $prop ];
72
-		}
73
-
74
-		return null;
75
-	}
76
-
77
-	/**
78
-	 * Define class properties.
79
-	 */
80
-	public function set_properties() {
81
-		// Sessions.
82
-		$this->set( 'session', new WPInv_Session_Handler() );
83
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
85
-
86
-		// Init other objects.
87
-		$this->set( 'notes', new WPInv_Notes() );
88
-		$this->set( 'api', new WPInv_API() );
89
-		$this->set( 'post_types', new GetPaid_Post_Types() );
90
-		$this->set( 'template', new GetPaid_Template() );
91
-		$this->set( 'admin', new GetPaid_Admin() );
92
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
93
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
94
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
95
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
96
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
97
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
98
-		$this->set( 'data_retention', new WPInv_Data_Retention() );
99
-	}
100
-
101
-	 /**
102
-	 * Define plugin constants.
103
-	 */
104
-	public function define_constants() {
105
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
106
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
107
-		$this->version = WPINV_VERSION;
108
-	}
109
-
110
-	/**
111
-	 * Hook into actions and filters.
112
-	 *
113
-	 * @since 1.0.19
114
-	 */
115
-	protected function init_hooks() {
116
-		/* Internationalize the text strings used. */
117
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
118
-
119
-		// Init the plugin after WordPress inits.
120
-		add_action( 'init', array( $this, 'init' ), 1 );
121
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 );
122
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
123
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
124
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
125
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
126
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
127
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
128
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
129
-		add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
130
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
131
-
132
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
133
-		add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
134
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
135
-
136
-		// Fires after registering actions.
137
-		do_action( 'wpinv_actions', $this );
138
-		do_action( 'getpaid_actions', $this );
139
-	}
140
-
141
-	public function plugins_loaded() {
142
-		/* Internationalize the text strings used. */
143
-		$this->load_textdomain();
144
-
145
-		do_action( 'wpinv_loaded' );
146
-
147
-		// Fix oxygen page builder conflict
148
-		if ( function_exists( 'ct_css_output' ) ) {
149
-			wpinv_oxygen_fix_conflict();
150
-		}
151
-	}
152
-
153
-	/**
154
-	 * Load Localisation files.
155
-	 *
156
-	 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
157
-	 *
158
-	 * Locales found in:
159
-	 *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
160
-	 *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
161
-	 *
162
-	 * @since 1.0.0
163
-	 */
164
-	public function load_textdomain() {
165
-		// Determines the current locale.
166
-		if ( function_exists( 'determine_locale' ) ) {
167
-			$locale = determine_locale();
168
-		} else if ( function_exists( 'get_user_locale' ) ) {
169
-			$locale = get_user_locale();
170
-		} else {
171
-			$locale = get_locale();
172
-		}
173
-
174
-		/**
175
-		 * Filter the locale to use for translations.
176
-		 */
177
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
178
-
179
-		unload_textdomain( 'invoicing', true );
180
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
181
-		load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' );
182
-	}
183
-
184
-	/**
185
-	 * Include required core files used in admin and on the frontend.
186
-	 */
187
-	public function includes() {
188
-		// Start with the settings.
189
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
190
-
191
-		// Packages/libraries.
192
-		require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
193
-		require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
194
-
195
-		// Load functions.
196
-		require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
197
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
198
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
199
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
200
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
201
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
202
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
203
-		require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
204
-		require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
205
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
206
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
207
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
208
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
209
-		require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
210
-		require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
211
-
212
-		// Register autoloader.
213
-		try {
214
-			spl_autoload_register( array( $this, 'autoload' ), true );
215
-		} catch ( Exception $e ) {
216
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
217
-		}
218
-
219
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
220
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
221
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
222
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
223
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
224
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
225
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
226
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
227
-		require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
228
-		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
229
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
230
-		require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
231
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
232
-		require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
233
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
234
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
235
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
236
-		require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
237
-		require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
238
-		require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
239
-		require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
240
-		require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
241
-
242
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
243
-			GetPaid_Post_Types_Admin::init();
244
-
245
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
246
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
247
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
248
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
249
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
250
-			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
251
-			// load the user class only on the users.php page
252
-			global $pagenow;
253
-			if ( $pagenow == 'users.php' ) {
254
-				new WPInv_Admin_Users();
255
-			}
256
-		}
257
-
258
-		// Register cli commands
259
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
260
-			require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
261
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
262
-		}
263
-	}
264
-
265
-	/**
266
-	 * Class autoloader
267
-	 *
268
-	 * @param       string $class_name The name of the class to load.
269
-	 * @access      public
270
-	 * @since       1.0.19
271
-	 * @return      void
272
-	 */
273
-	public function autoload( $class_name ) {
274
-		// Normalize the class name...
275
-		$class_name  = strtolower( $class_name );
276
-
277
-		// ... and make sure it is our class.
278
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
279
-			return;
280
-		}
281
-
282
-		// Next, prepare the file name from the class.
283
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
284
-
285
-		// Base path of the classes.
286
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
287
-
288
-		// And an array of possible locations in order of importance.
289
-		$locations = array(
290
-			"$plugin_path/includes",
291
-			"$plugin_path/includes/data-stores",
292
-			"$plugin_path/includes/gateways",
293
-			"$plugin_path/includes/payments",
294
-			"$plugin_path/includes/geolocation",
295
-			"$plugin_path/includes/reports",
296
-			"$plugin_path/includes/api",
297
-			"$plugin_path/includes/admin",
298
-			"$plugin_path/includes/admin/meta-boxes",
299
-		);
300
-
301
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
302
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
303
-				include trailingslashit( $location ) . $file_name;
304
-				break;
305
-			}
306
-		}
307
-	}
308
-
309
-	/**
310
-	 * Inits hooks etc.
311
-	 */
312
-	public function init() {
313
-		// Fires before getpaid inits.
314
-		do_action( 'before_getpaid_init', $this );
315
-
316
-		// Maybe upgrade.
317
-		$this->maybe_upgrade_database();
318
-
319
-		// Load default gateways.
320
-		$gateways = apply_filters(
321
-			'getpaid_default_gateways',
322
-			array(
323
-				'manual'        => 'GetPaid_Manual_Gateway',
324
-				'paypal'        => 'GetPaid_Paypal_Gateway',
325
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
326
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
327
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
328
-			)
329
-		);
330
-
331
-		foreach ( $gateways as $id => $class ) {
332
-			$this->gateways[ $id ] = new $class();
333
-		}
334
-
335
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
336
-			GetPaid_Installer::rename_gateways_label();
337
-			update_option( 'wpinv_renamed_gateways', 'yes' );
338
-		}
339
-
340
-		// Fires after getpaid inits.
341
-		do_action( 'getpaid_init', $this );
342
-	}
343
-
344
-	/**
345
-	 * Checks if this is an IPN request and processes it.
346
-	 */
347
-	public function maybe_process_ipn() {
348
-		// Ensure that this is an IPN request.
349
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
350
-			return;
351
-		}
352
-
353
-		$gateway = sanitize_text_field( $_GET['wpi-gateway'] );
354
-
355
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
356
-		do_action( "wpinv_verify_{$gateway}_ipn" );
357
-		exit;
358
-	}
359
-
360
-	public function enqueue_scripts() {
361
-		// Fires before adding scripts.
362
-		do_action( 'getpaid_enqueue_scripts' );
363
-
364
-		$localize                         = array();
365
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
366
-		$localize['thousands']            = wpinv_thousands_separator();
367
-		$localize['decimals']             = wpinv_decimal_separator();
368
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
369
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
370
-		$localize['UseTaxes']             = wpinv_use_taxes();
371
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
372
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
373
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
374
-		$localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
375
-
376
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
377
-
378
-		// reCaptcha.
379
-		if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) {
380
-			wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
381
-		}
382
-
383
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true );
384
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
385
-	}
386
-
387
-	public function wpinv_actions() {
388
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
389
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
390
-		}
391
-
392
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
393
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
394
-		}
395
-	}
396
-
397
-	/**
398
-	 * Fires an action after verifying that a user can fire them.
399
-	 *
400
-	 * Note: If the action is on an invoice, subscription etc, esure that the
401
-	 * current user owns the invoice/subscription.
402
-	 */
403
-	public function maybe_do_authenticated_action() {
404
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
405
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
406
-			$data = wp_unslash( $_REQUEST );
407
-
408
-			if ( is_user_logged_in() ) {
409
-				do_action( "getpaid_authenticated_action_$key", $data );
410
-			}
411
-
412
-			do_action( "getpaid_unauthenticated_action_$key", $data );
413
-		}
414
-	}
415
-
416
-	public function pre_get_posts( $wp_query ) {
417
-		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() ) {
418
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
419
-		}
420
-
421
-		return $wp_query;
422
-	}
423
-
424
-	/**
425
-	 * Register widgets
426
-	 *
427
-	 */
428
-	public function register_widgets() {
429
-		global $pagenow;
430
-
431
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
432
-		// So we disable our widgets when editing a page with UX Builder.
433
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
434
-			return;
435
-		}
436
-
437
-		$block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
438
-
439
-		if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
440
-			// don't initiate in these conditions.
441
-		} else {
442
-			// Only load allowed widgets.
443
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
444
-			$widgets = apply_filters(
445
-				'getpaid_widget_classes',
446
-				array(
447
-					'WPInv_Checkout_Widget',
448
-					'WPInv_History_Widget',
449
-					'WPInv_Receipt_Widget',
450
-					'WPInv_Subscriptions_Widget',
451
-					'WPInv_Buy_Item_Widget',
452
-					'WPInv_Messages_Widget',
453
-					'WPInv_GetPaid_Widget',
454
-					'WPInv_Invoice_Widget',
455
-				)
456
-			);
457
-
458
-			// For each widget...
459
-			foreach ( $widgets as $widget ) {
460
-				// Abort early if it is excluded for this page.
461
-				if ( in_array( $widget, $exclude ) ) {
462
-					continue;
463
-				}
464
-
465
-				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
466
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
467
-					register_widget( $widget );
468
-				} else {
469
-					new $widget();
470
-				}
471
-			}
472
-		}
473
-	}
474
-
475
-	/**
476
-	 * Upgrades the database.
477
-	 *
478
-	 * @since 2.0.2
479
-	 */
480
-	public function maybe_upgrade_database() {
481
-		// Ensure the database tables are up to date.
482
-		GetPaid_Installer::maybe_create_db_tables();
483
-
484
-		$wpi_version = get_option( 'wpinv_version', 0 );
485
-
486
-		if ( $wpi_version == WPINV_VERSION ) {
487
-			return;
488
-		}
489
-
490
-		$installer = new GetPaid_Installer();
491
-
492
-		if ( empty( $wpi_version ) ) {
493
-			return $installer->upgrade_db( 0 );
494
-		}
495
-
496
-		$upgrades  = array(
497
-			'0.0.5' => '004',
498
-			'1.0.3' => '102',
499
-			'2.0.0' => '118',
500
-			'2.8.0' => '279',
501
-		);
502
-
503
-		foreach ( $upgrades as $key => $method ) {
504
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
505
-				return $installer->upgrade_db( $method );
506
-			}
507
-		}
508
-	}
509
-
510
-	/**
511
-	 * Flushes the permalinks if needed.
512
-	 *
513
-	 * @since 2.0.8
514
-	 */
515
-	public function maybe_flush_permalinks() {
516
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
517
-
518
-		if ( ! empty( $flush ) ) {
519
-			flush_rewrite_rules();
520
-			delete_option( 'wpinv_flush_permalinks' );
521
-		}
522
-	}
523
-
524
-	/**
525
-	 * Remove our pages from yoast sitemaps.
526
-	 *
527
-	 * @since 1.0.19
528
-	 * @param int[] $excluded_posts_ids
529
-	 */
530
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
531
-		// Ensure that we have an array.
532
-		if ( ! is_array( $excluded_posts_ids ) ) {
533
-			$excluded_posts_ids = array();
534
-		}
535
-
536
-		// Prepare our pages.
537
-		$our_pages = array();
538
-
539
-		// Checkout page.
540
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
541
-
542
-		// Success page.
543
-		$our_pages[] = wpinv_get_option( 'success_page', false );
544
-
545
-		// Failure page.
546
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
547
-
548
-		// History page.
549
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
550
-
551
-		// Subscriptions page.
552
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
553
-
554
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
555
-
556
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
557
-
558
-		return array_unique( $excluded_posts_ids );
559
-	}
560
-
561
-	/**
562
-	 * Remove our pages from yoast sitemaps.
563
-	 *
564
-	 * @since 1.0.19
565
-	 * @param string[] $post_types
566
-	 */
567
-	public function exclude_invoicing_post_types( $post_types ) {
568
-		// Ensure that we have an array.
569
-		if ( ! is_array( $post_types ) ) {
570
-			$post_types = array();
571
-		}
572
-
573
-		// Remove our post types.
574
-		return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
575
-	}
576
-
577
-	/**
578
-	 * Displays additional footer code.
579
-	 *
580
-	 * @since 2.0.0
581
-	 */
582
-	public function wp_footer() {
583
-		wpinv_get_template( 'frontend-footer.php' );
584
-	}
585
-
586
-	/**
587
-	 * Displays additional header code.
588
-	 *
589
-	 * @since 2.0.0
590
-	 */
591
-	public function wp_head() {
592
-		wpinv_get_template( 'frontend-head.php' );
593
-	}
594
-
595
-	/**
596
-	 * Custom query vars.
597
-	 *
598
-	 */
599
-	public function custom_query_vars( $vars ) {
600
-		$vars[] = 'getpaid-ipn';
601
-		return $vars;
602
-	}
603
-
604
-	/**
605
-	 * Add rewrite tags and rules.
606
-	 *
607
-	 */
608
-	public function add_rewrite_rule() {
609
-		$tag = 'getpaid-ipn';
610
-		add_rewrite_tag( "%$tag%", '([^&]+)' );
611
-		add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
612
-	}
613
-
614
-	/**
615
-	 * Processes non-query string ipns.
616
-	 *
617
-	 */
618
-	public function maybe_process_new_ipn( $query ) {
619
-		if ( is_admin() || ! $query->is_main_query() ) {
620
-			return;
621
-		}
622
-
623
-		$gateway = get_query_var( 'getpaid-ipn' );
624
-
625
-		if ( ! empty( $gateway ) ) {
626
-			$gateway = sanitize_text_field( $gateway );
627
-			nocache_headers();
628
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
629
-			do_action( "wpinv_verify_{$gateway}_ipn" );
630
-			exit;
631
-		}
632
-	}
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
+        if ( isset( $this->data[ $prop ] ) ) {
71
+            return $this->data[ $prop ];
72
+        }
73
+
74
+        return null;
75
+    }
76
+
77
+    /**
78
+     * Define class properties.
79
+     */
80
+    public function set_properties() {
81
+        // Sessions.
82
+        $this->set( 'session', new WPInv_Session_Handler() );
83
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
85
+
86
+        // Init other objects.
87
+        $this->set( 'notes', new WPInv_Notes() );
88
+        $this->set( 'api', new WPInv_API() );
89
+        $this->set( 'post_types', new GetPaid_Post_Types() );
90
+        $this->set( 'template', new GetPaid_Template() );
91
+        $this->set( 'admin', new GetPaid_Admin() );
92
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
93
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
94
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
95
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
96
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
97
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
98
+        $this->set( 'data_retention', new WPInv_Data_Retention() );
99
+    }
100
+
101
+        /**
102
+         * Define plugin constants.
103
+         */
104
+    public function define_constants() {
105
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
106
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
107
+        $this->version = WPINV_VERSION;
108
+    }
109
+
110
+    /**
111
+     * Hook into actions and filters.
112
+     *
113
+     * @since 1.0.19
114
+     */
115
+    protected function init_hooks() {
116
+        /* Internationalize the text strings used. */
117
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
118
+
119
+        // Init the plugin after WordPress inits.
120
+        add_action( 'init', array( $this, 'init' ), 1 );
121
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 );
122
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
123
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
124
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
125
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
126
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
127
+        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
128
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
129
+        add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
130
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
131
+
132
+        add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
133
+        add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
134
+        add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
135
+
136
+        // Fires after registering actions.
137
+        do_action( 'wpinv_actions', $this );
138
+        do_action( 'getpaid_actions', $this );
139
+    }
140
+
141
+    public function plugins_loaded() {
142
+        /* Internationalize the text strings used. */
143
+        $this->load_textdomain();
144
+
145
+        do_action( 'wpinv_loaded' );
146
+
147
+        // Fix oxygen page builder conflict
148
+        if ( function_exists( 'ct_css_output' ) ) {
149
+            wpinv_oxygen_fix_conflict();
150
+        }
151
+    }
152
+
153
+    /**
154
+     * Load Localisation files.
155
+     *
156
+     * Note: the first-loaded translation file overrides any following ones if the same translation is present.
157
+     *
158
+     * Locales found in:
159
+     *      - WP_LANG_DIR/plugins/invoicing-LOCALE.mo
160
+     *      - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo
161
+     *
162
+     * @since 1.0.0
163
+     */
164
+    public function load_textdomain() {
165
+        // Determines the current locale.
166
+        if ( function_exists( 'determine_locale' ) ) {
167
+            $locale = determine_locale();
168
+        } else if ( function_exists( 'get_user_locale' ) ) {
169
+            $locale = get_user_locale();
170
+        } else {
171
+            $locale = get_locale();
172
+        }
173
+
174
+        /**
175
+         * Filter the locale to use for translations.
176
+         */
177
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
178
+
179
+        unload_textdomain( 'invoicing', true );
180
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
181
+        load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' );
182
+    }
183
+
184
+    /**
185
+     * Include required core files used in admin and on the frontend.
186
+     */
187
+    public function includes() {
188
+        // Start with the settings.
189
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php';
190
+
191
+        // Packages/libraries.
192
+        require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php';
193
+        require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php';
194
+
195
+        // Load functions.
196
+        require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php';
197
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php';
198
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php';
199
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php';
200
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php';
201
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php';
202
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php';
203
+        require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php';
204
+        require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php';
205
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php';
206
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php';
207
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php';
208
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php';
209
+        require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php';
210
+        require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php';
211
+
212
+        // Register autoloader.
213
+        try {
214
+            spl_autoload_register( array( $this, 'autoload' ), true );
215
+        } catch ( Exception $e ) {
216
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
217
+        }
218
+
219
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
220
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php';
221
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php';
222
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php';
223
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php';
224
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php';
225
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php';
226
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php';
227
+        require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php';
228
+        require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php';
229
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php';
230
+        require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php';
231
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php';
232
+        require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php';
233
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php';
234
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php';
235
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php';
236
+        require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php';
237
+        require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php';
238
+        require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php';
239
+        require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
240
+        require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
241
+
242
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
243
+            GetPaid_Post_Types_Admin::init();
244
+
245
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
246
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php';
247
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php';
248
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php';
249
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php';
250
+            require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
251
+            // load the user class only on the users.php page
252
+            global $pagenow;
253
+            if ( $pagenow == 'users.php' ) {
254
+                new WPInv_Admin_Users();
255
+            }
256
+        }
257
+
258
+        // Register cli commands
259
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
260
+            require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
261
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
262
+        }
263
+    }
264
+
265
+    /**
266
+     * Class autoloader
267
+     *
268
+     * @param       string $class_name The name of the class to load.
269
+     * @access      public
270
+     * @since       1.0.19
271
+     * @return      void
272
+     */
273
+    public function autoload( $class_name ) {
274
+        // Normalize the class name...
275
+        $class_name  = strtolower( $class_name );
276
+
277
+        // ... and make sure it is our class.
278
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
279
+            return;
280
+        }
281
+
282
+        // Next, prepare the file name from the class.
283
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
284
+
285
+        // Base path of the classes.
286
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
287
+
288
+        // And an array of possible locations in order of importance.
289
+        $locations = array(
290
+            "$plugin_path/includes",
291
+            "$plugin_path/includes/data-stores",
292
+            "$plugin_path/includes/gateways",
293
+            "$plugin_path/includes/payments",
294
+            "$plugin_path/includes/geolocation",
295
+            "$plugin_path/includes/reports",
296
+            "$plugin_path/includes/api",
297
+            "$plugin_path/includes/admin",
298
+            "$plugin_path/includes/admin/meta-boxes",
299
+        );
300
+
301
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
302
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
303
+                include trailingslashit( $location ) . $file_name;
304
+                break;
305
+            }
306
+        }
307
+    }
308
+
309
+    /**
310
+     * Inits hooks etc.
311
+     */
312
+    public function init() {
313
+        // Fires before getpaid inits.
314
+        do_action( 'before_getpaid_init', $this );
315
+
316
+        // Maybe upgrade.
317
+        $this->maybe_upgrade_database();
318
+
319
+        // Load default gateways.
320
+        $gateways = apply_filters(
321
+            'getpaid_default_gateways',
322
+            array(
323
+                'manual'        => 'GetPaid_Manual_Gateway',
324
+                'paypal'        => 'GetPaid_Paypal_Gateway',
325
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
326
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
327
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
328
+            )
329
+        );
330
+
331
+        foreach ( $gateways as $id => $class ) {
332
+            $this->gateways[ $id ] = new $class();
333
+        }
334
+
335
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
336
+            GetPaid_Installer::rename_gateways_label();
337
+            update_option( 'wpinv_renamed_gateways', 'yes' );
338
+        }
339
+
340
+        // Fires after getpaid inits.
341
+        do_action( 'getpaid_init', $this );
342
+    }
343
+
344
+    /**
345
+     * Checks if this is an IPN request and processes it.
346
+     */
347
+    public function maybe_process_ipn() {
348
+        // Ensure that this is an IPN request.
349
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
350
+            return;
351
+        }
352
+
353
+        $gateway = sanitize_text_field( $_GET['wpi-gateway'] );
354
+
355
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
356
+        do_action( "wpinv_verify_{$gateway}_ipn" );
357
+        exit;
358
+    }
359
+
360
+    public function enqueue_scripts() {
361
+        // Fires before adding scripts.
362
+        do_action( 'getpaid_enqueue_scripts' );
363
+
364
+        $localize                         = array();
365
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
366
+        $localize['thousands']            = wpinv_thousands_separator();
367
+        $localize['decimals']             = wpinv_decimal_separator();
368
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
369
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
370
+        $localize['UseTaxes']             = wpinv_use_taxes();
371
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
372
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
373
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
374
+        $localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
375
+
376
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
377
+
378
+        // reCaptcha.
379
+        if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) {
380
+            wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
381
+        }
382
+
383
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true );
384
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
385
+    }
386
+
387
+    public function wpinv_actions() {
388
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
389
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
390
+        }
391
+
392
+        if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
393
+            include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
394
+        }
395
+    }
396
+
397
+    /**
398
+     * Fires an action after verifying that a user can fire them.
399
+     *
400
+     * Note: If the action is on an invoice, subscription etc, esure that the
401
+     * current user owns the invoice/subscription.
402
+     */
403
+    public function maybe_do_authenticated_action() {
404
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
405
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
406
+            $data = wp_unslash( $_REQUEST );
407
+
408
+            if ( is_user_logged_in() ) {
409
+                do_action( "getpaid_authenticated_action_$key", $data );
410
+            }
411
+
412
+            do_action( "getpaid_unauthenticated_action_$key", $data );
413
+        }
414
+    }
415
+
416
+    public function pre_get_posts( $wp_query ) {
417
+        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() ) {
418
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
419
+        }
420
+
421
+        return $wp_query;
422
+    }
423
+
424
+    /**
425
+     * Register widgets
426
+     *
427
+     */
428
+    public function register_widgets() {
429
+        global $pagenow;
430
+
431
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
432
+        // So we disable our widgets when editing a page with UX Builder.
433
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
434
+            return;
435
+        }
436
+
437
+        $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
438
+
439
+        if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
440
+            // don't initiate in these conditions.
441
+        } else {
442
+            // Only load allowed widgets.
443
+            $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
444
+            $widgets = apply_filters(
445
+                'getpaid_widget_classes',
446
+                array(
447
+                    'WPInv_Checkout_Widget',
448
+                    'WPInv_History_Widget',
449
+                    'WPInv_Receipt_Widget',
450
+                    'WPInv_Subscriptions_Widget',
451
+                    'WPInv_Buy_Item_Widget',
452
+                    'WPInv_Messages_Widget',
453
+                    'WPInv_GetPaid_Widget',
454
+                    'WPInv_Invoice_Widget',
455
+                )
456
+            );
457
+
458
+            // For each widget...
459
+            foreach ( $widgets as $widget ) {
460
+                // Abort early if it is excluded for this page.
461
+                if ( in_array( $widget, $exclude ) ) {
462
+                    continue;
463
+                }
464
+
465
+                // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
466
+                if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
467
+                    register_widget( $widget );
468
+                } else {
469
+                    new $widget();
470
+                }
471
+            }
472
+        }
473
+    }
474
+
475
+    /**
476
+     * Upgrades the database.
477
+     *
478
+     * @since 2.0.2
479
+     */
480
+    public function maybe_upgrade_database() {
481
+        // Ensure the database tables are up to date.
482
+        GetPaid_Installer::maybe_create_db_tables();
483
+
484
+        $wpi_version = get_option( 'wpinv_version', 0 );
485
+
486
+        if ( $wpi_version == WPINV_VERSION ) {
487
+            return;
488
+        }
489
+
490
+        $installer = new GetPaid_Installer();
491
+
492
+        if ( empty( $wpi_version ) ) {
493
+            return $installer->upgrade_db( 0 );
494
+        }
495
+
496
+        $upgrades  = array(
497
+            '0.0.5' => '004',
498
+            '1.0.3' => '102',
499
+            '2.0.0' => '118',
500
+            '2.8.0' => '279',
501
+        );
502
+
503
+        foreach ( $upgrades as $key => $method ) {
504
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
505
+                return $installer->upgrade_db( $method );
506
+            }
507
+        }
508
+    }
509
+
510
+    /**
511
+     * Flushes the permalinks if needed.
512
+     *
513
+     * @since 2.0.8
514
+     */
515
+    public function maybe_flush_permalinks() {
516
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
517
+
518
+        if ( ! empty( $flush ) ) {
519
+            flush_rewrite_rules();
520
+            delete_option( 'wpinv_flush_permalinks' );
521
+        }
522
+    }
523
+
524
+    /**
525
+     * Remove our pages from yoast sitemaps.
526
+     *
527
+     * @since 1.0.19
528
+     * @param int[] $excluded_posts_ids
529
+     */
530
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
531
+        // Ensure that we have an array.
532
+        if ( ! is_array( $excluded_posts_ids ) ) {
533
+            $excluded_posts_ids = array();
534
+        }
535
+
536
+        // Prepare our pages.
537
+        $our_pages = array();
538
+
539
+        // Checkout page.
540
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
541
+
542
+        // Success page.
543
+        $our_pages[] = wpinv_get_option( 'success_page', false );
544
+
545
+        // Failure page.
546
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
547
+
548
+        // History page.
549
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
550
+
551
+        // Subscriptions page.
552
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
553
+
554
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
555
+
556
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
557
+
558
+        return array_unique( $excluded_posts_ids );
559
+    }
560
+
561
+    /**
562
+     * Remove our pages from yoast sitemaps.
563
+     *
564
+     * @since 1.0.19
565
+     * @param string[] $post_types
566
+     */
567
+    public function exclude_invoicing_post_types( $post_types ) {
568
+        // Ensure that we have an array.
569
+        if ( ! is_array( $post_types ) ) {
570
+            $post_types = array();
571
+        }
572
+
573
+        // Remove our post types.
574
+        return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
575
+    }
576
+
577
+    /**
578
+     * Displays additional footer code.
579
+     *
580
+     * @since 2.0.0
581
+     */
582
+    public function wp_footer() {
583
+        wpinv_get_template( 'frontend-footer.php' );
584
+    }
585
+
586
+    /**
587
+     * Displays additional header code.
588
+     *
589
+     * @since 2.0.0
590
+     */
591
+    public function wp_head() {
592
+        wpinv_get_template( 'frontend-head.php' );
593
+    }
594
+
595
+    /**
596
+     * Custom query vars.
597
+     *
598
+     */
599
+    public function custom_query_vars( $vars ) {
600
+        $vars[] = 'getpaid-ipn';
601
+        return $vars;
602
+    }
603
+
604
+    /**
605
+     * Add rewrite tags and rules.
606
+     *
607
+     */
608
+    public function add_rewrite_rule() {
609
+        $tag = 'getpaid-ipn';
610
+        add_rewrite_tag( "%$tag%", '([^&]+)' );
611
+        add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
612
+    }
613
+
614
+    /**
615
+     * Processes non-query string ipns.
616
+     *
617
+     */
618
+    public function maybe_process_new_ipn( $query ) {
619
+        if ( is_admin() || ! $query->is_main_query() ) {
620
+            return;
621
+        }
622
+
623
+        $gateway = get_query_var( 'getpaid-ipn' );
624
+
625
+        if ( ! empty( $gateway ) ) {
626
+            $gateway = sanitize_text_field( $gateway );
627
+            nocache_headers();
628
+            do_action( 'wpinv_verify_payment_ipn', $gateway );
629
+            do_action( "wpinv_verify_{$gateway}_ipn" );
630
+            exit;
631
+        }
632
+    }
633 633
 }
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 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,9 +66,9 @@  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 ) {
70
-		if ( isset( $this->data[ $prop ] ) ) {
71
-			return $this->data[ $prop ];
69
+	public function get($prop) {
70
+		if (isset($this->data[$prop])) {
71
+			return $this->data[$prop];
72 72
 		}
73 73
 
74 74
 		return null;
@@ -79,31 +79,31 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	public function set_properties() {
81 81
 		// Sessions.
82
-		$this->set( 'session', new WPInv_Session_Handler() );
83
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
82
+		$this->set('session', new WPInv_Session_Handler());
83
+		$GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility.
84 84
 		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
85 85
 
86 86
 		// Init other objects.
87
-		$this->set( 'notes', new WPInv_Notes() );
88
-		$this->set( 'api', new WPInv_API() );
89
-		$this->set( 'post_types', new GetPaid_Post_Types() );
90
-		$this->set( 'template', new GetPaid_Template() );
91
-		$this->set( 'admin', new GetPaid_Admin() );
92
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
93
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
94
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
95
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
96
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
97
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
98
-		$this->set( 'data_retention', new WPInv_Data_Retention() );
87
+		$this->set('notes', new WPInv_Notes());
88
+		$this->set('api', new WPInv_API());
89
+		$this->set('post_types', new GetPaid_Post_Types());
90
+		$this->set('template', new GetPaid_Template());
91
+		$this->set('admin', new GetPaid_Admin());
92
+		$this->set('subscriptions', new WPInv_Subscriptions());
93
+		$this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails());
94
+		$this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails());
95
+		$this->set('daily_maintenace', new GetPaid_Daily_Maintenance());
96
+		$this->set('payment_forms', new GetPaid_Payment_Forms());
97
+		$this->set('maxmind', new GetPaid_MaxMind_Geolocation());
98
+		$this->set('data_retention', new WPInv_Data_Retention());
99 99
 	}
100 100
 
101 101
 	 /**
102 102
 	 * Define plugin constants.
103 103
 	 */
104 104
 	public function define_constants() {
105
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
106
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
105
+		define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
106
+		define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
107 107
 		$this->version = WPINV_VERSION;
108 108
 	}
109 109
 
@@ -114,38 +114,38 @@  discard block
 block discarded – undo
114 114
 	 */
115 115
 	protected function init_hooks() {
116 116
 		/* Internationalize the text strings used. */
117
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
117
+		add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
118 118
 
119 119
 		// Init the plugin after WordPress inits.
120
-		add_action( 'init', array( $this, 'init' ), 1 );
121
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 100 );
122
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
123
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
124
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
125
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
126
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
127
-		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
128
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
129
-		add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) );
130
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
131
-
132
-		add_filter( 'query_vars', array( $this, 'custom_query_vars' ) );
133
-		add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 );
134
-		add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 );
120
+		add_action('init', array($this, 'init'), 1);
121
+		add_action('init', array($this, 'maybe_process_ipn'), 100);
122
+		add_action('init', array($this, 'wpinv_actions'));
123
+		add_action('init', array($this, 'maybe_do_authenticated_action'), 100);
124
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11);
125
+		add_action('wp_footer', array($this, 'wp_footer'));
126
+		add_action('wp_head', array($this, 'wp_head'));
127
+		add_action('widgets_init', array($this, 'register_widgets'));
128
+		add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
129
+		add_filter('the_seo_framework_sitemap_supported_post_types', array($this, 'exclude_invoicing_post_types'));
130
+		add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
131
+
132
+		add_filter('query_vars', array($this, 'custom_query_vars'));
133
+		add_action('init', array($this, 'add_rewrite_rule'), 10, 0);
134
+		add_action('pre_get_posts', array($this, 'maybe_process_new_ipn'), 1);
135 135
 
136 136
 		// Fires after registering actions.
137
-		do_action( 'wpinv_actions', $this );
138
-		do_action( 'getpaid_actions', $this );
137
+		do_action('wpinv_actions', $this);
138
+		do_action('getpaid_actions', $this);
139 139
 	}
140 140
 
141 141
 	public function plugins_loaded() {
142 142
 		/* Internationalize the text strings used. */
143 143
 		$this->load_textdomain();
144 144
 
145
-		do_action( 'wpinv_loaded' );
145
+		do_action('wpinv_loaded');
146 146
 
147 147
 		// Fix oxygen page builder conflict
148
-		if ( function_exists( 'ct_css_output' ) ) {
148
+		if (function_exists('ct_css_output')) {
149 149
 			wpinv_oxygen_fix_conflict();
150 150
 		}
151 151
 	}
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
 	 */
164 164
 	public function load_textdomain() {
165 165
 		// Determines the current locale.
166
-		if ( function_exists( 'determine_locale' ) ) {
166
+		if (function_exists('determine_locale')) {
167 167
 			$locale = determine_locale();
168
-		} else if ( function_exists( 'get_user_locale' ) ) {
168
+		} else if (function_exists('get_user_locale')) {
169 169
 			$locale = get_user_locale();
170 170
 		} else {
171 171
 			$locale = get_locale();
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
 		/**
175 175
 		 * Filter the locale to use for translations.
176 176
 		 */
177
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
177
+		$locale = apply_filters('plugin_locale', $locale, 'invoicing');
178 178
 
179
-		unload_textdomain( 'invoicing', true );
180
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
181
-		load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' );
179
+		unload_textdomain('invoicing', true);
180
+		load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
181
+		load_plugin_textdomain('invoicing', false, plugin_basename(dirname(WPINV_PLUGIN_FILE)) . '/languages/');
182 182
 	}
183 183
 
184 184
 	/**
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
 
212 212
 		// Register autoloader.
213 213
 		try {
214
-			spl_autoload_register( array( $this, 'autoload' ), true );
215
-		} catch ( Exception $e ) {
216
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
214
+			spl_autoload_register(array($this, 'autoload'), true);
215
+		} catch (Exception $e) {
216
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
217 217
 		}
218 218
 
219 219
 		require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php';
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 		require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php';
240 240
 		require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php';
241 241
 
242
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
242
+		if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
243 243
 			GetPaid_Post_Types_Admin::init();
244 244
 
245 245
 			require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php';
@@ -250,15 +250,15 @@  discard block
 block discarded – undo
250 250
 			require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php';
251 251
 			// load the user class only on the users.php page
252 252
 			global $pagenow;
253
-			if ( $pagenow == 'users.php' ) {
253
+			if ($pagenow == 'users.php') {
254 254
 				new WPInv_Admin_Users();
255 255
 			}
256 256
 		}
257 257
 
258 258
 		// Register cli commands
259
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
259
+		if (defined('WP_CLI') && WP_CLI) {
260 260
 			require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php';
261
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
261
+			WP_CLI::add_command('invoicing', 'WPInv_CLI');
262 262
 		}
263 263
 	}
264 264
 
@@ -270,20 +270,20 @@  discard block
 block discarded – undo
270 270
 	 * @since       1.0.19
271 271
 	 * @return      void
272 272
 	 */
273
-	public function autoload( $class_name ) {
273
+	public function autoload($class_name) {
274 274
 		// Normalize the class name...
275
-		$class_name  = strtolower( $class_name );
275
+		$class_name = strtolower($class_name);
276 276
 
277 277
 		// ... and make sure it is our class.
278
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
278
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
279 279
 			return;
280 280
 		}
281 281
 
282 282
 		// Next, prepare the file name from the class.
283
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
283
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
284 284
 
285 285
 		// Base path of the classes.
286
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
286
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
287 287
 
288 288
 		// And an array of possible locations in order of importance.
289 289
 		$locations = array(
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
 			"$plugin_path/includes/admin/meta-boxes",
299 299
 		);
300 300
 
301
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
302
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
303
-				include trailingslashit( $location ) . $file_name;
301
+		foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) {
302
+			if (file_exists(trailingslashit($location) . $file_name)) {
303
+				include trailingslashit($location) . $file_name;
304 304
 				break;
305 305
 			}
306 306
 		}
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	 */
312 312
 	public function init() {
313 313
 		// Fires before getpaid inits.
314
-		do_action( 'before_getpaid_init', $this );
314
+		do_action('before_getpaid_init', $this);
315 315
 
316 316
 		// Maybe upgrade.
317 317
 		$this->maybe_upgrade_database();
@@ -328,17 +328,17 @@  discard block
 block discarded – undo
328 328
 			)
329 329
 		);
330 330
 
331
-		foreach ( $gateways as $id => $class ) {
332
-			$this->gateways[ $id ] = new $class();
331
+		foreach ($gateways as $id => $class) {
332
+			$this->gateways[$id] = new $class();
333 333
 		}
334 334
 
335
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
335
+		if ('yes' != get_option('wpinv_renamed_gateways')) {
336 336
 			GetPaid_Installer::rename_gateways_label();
337
-			update_option( 'wpinv_renamed_gateways', 'yes' );
337
+			update_option('wpinv_renamed_gateways', 'yes');
338 338
 		}
339 339
 
340 340
 		// Fires after getpaid inits.
341
-		do_action( 'getpaid_init', $this );
341
+		do_action('getpaid_init', $this);
342 342
 	}
343 343
 
344 344
 	/**
@@ -346,51 +346,51 @@  discard block
 block discarded – undo
346 346
 	 */
347 347
 	public function maybe_process_ipn() {
348 348
 		// Ensure that this is an IPN request.
349
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
349
+		if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) {
350 350
 			return;
351 351
 		}
352 352
 
353
-		$gateway = sanitize_text_field( $_GET['wpi-gateway'] );
353
+		$gateway = sanitize_text_field($_GET['wpi-gateway']);
354 354
 
355
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
356
-		do_action( "wpinv_verify_{$gateway}_ipn" );
355
+		do_action('wpinv_verify_payment_ipn', $gateway);
356
+		do_action("wpinv_verify_{$gateway}_ipn");
357 357
 		exit;
358 358
 	}
359 359
 
360 360
 	public function enqueue_scripts() {
361 361
 		// Fires before adding scripts.
362
-		do_action( 'getpaid_enqueue_scripts' );
362
+		do_action('getpaid_enqueue_scripts');
363 363
 
364 364
 		$localize                         = array();
365
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
365
+		$localize['ajax_url']             = admin_url('admin-ajax.php');
366 366
 		$localize['thousands']            = wpinv_thousands_separator();
367 367
 		$localize['decimals']             = wpinv_decimal_separator();
368
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
369
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
368
+		$localize['nonce']                = wp_create_nonce('wpinv-nonce');
369
+		$localize['txtComplete']          = __('Continue', 'invoicing');
370 370
 		$localize['UseTaxes']             = wpinv_use_taxes();
371
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
372
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
373
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
371
+		$localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
372
+		$localize['loading']              = __('Loading...', 'invoicing');
373
+		$localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
374 374
 		$localize['recaptchaSettings']    = getpaid_get_recaptcha_settings();
375 375
 
376
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
376
+		$localize = apply_filters('wpinv_front_js_localize', $localize);
377 377
 
378 378
 		// reCaptcha.
379
-		if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) {
380
-			wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
379
+		if (getpaid_is_recaptcha_enabled() && ($recaptcha_js = getpaid_recaptcha_api_url())) {
380
+			wp_enqueue_script('recaptcha', $recaptcha_js, array(), null, true); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
381 381
 		}
382 382
 
383
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array( 'jquery' ), WPINV_VERSION, true );
384
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
383
+		wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.min.js', array('jquery'), WPINV_VERSION, true);
384
+		wp_localize_script('wpinv-front-script', 'WPInv', $localize);
385 385
 	}
386 386
 
387 387
 	public function wpinv_actions() {
388
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
389
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
388
+		if (isset($_REQUEST['wpi_action'])) {
389
+			do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
390 390
 		}
391 391
 
392
-		if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) {
393
-			include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
392
+		if (defined('WP_ALL_IMPORT_ROOT_DIR')) {
393
+			include plugin_dir_path(__FILE__) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php';
394 394
 		}
395 395
 	}
396 396
 
@@ -401,21 +401,21 @@  discard block
 block discarded – undo
401 401
 	 * current user owns the invoice/subscription.
402 402
 	 */
403 403
 	public function maybe_do_authenticated_action() {
404
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
405
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
406
-			$data = wp_unslash( $_REQUEST );
404
+		if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
405
+			$key  = sanitize_key($_REQUEST['getpaid-action']);
406
+			$data = wp_unslash($_REQUEST);
407 407
 
408
-			if ( is_user_logged_in() ) {
409
-				do_action( "getpaid_authenticated_action_$key", $data );
408
+			if (is_user_logged_in()) {
409
+				do_action("getpaid_authenticated_action_$key", $data);
410 410
 			}
411 411
 
412
-			do_action( "getpaid_unauthenticated_action_$key", $data );
412
+			do_action("getpaid_unauthenticated_action_$key", $data);
413 413
 		}
414 414
 	}
415 415
 
416
-	public function pre_get_posts( $wp_query ) {
417
-		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() ) {
418
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
416
+	public function pre_get_posts($wp_query) {
417
+		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()) {
418
+			$wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type']));
419 419
 		}
420 420
 
421 421
 		return $wp_query;
@@ -430,17 +430,17 @@  discard block
 block discarded – undo
430 430
 
431 431
 		// Currently, UX Builder does not work particulaly well with SuperDuper.
432 432
 		// So we disable our widgets when editing a page with UX Builder.
433
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
433
+		if (function_exists('ux_builder_is_active') && ux_builder_is_active()) {
434 434
 			return;
435 435
 		}
436 436
 
437
-		$block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array();
437
+		$block_widget_init_screens = function_exists('sd_pagenow_exclude') ? sd_pagenow_exclude() : array();
438 438
 
439
-		if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) {
439
+		if (is_admin() && $pagenow && in_array($pagenow, $block_widget_init_screens)) {
440 440
 			// don't initiate in these conditions.
441 441
 		} else {
442 442
 			// Only load allowed widgets.
443
-			$exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array();
443
+			$exclude = function_exists('sd_widget_exclude') ? sd_widget_exclude() : array();
444 444
 			$widgets = apply_filters(
445 445
 				'getpaid_widget_classes',
446 446
 				array(
@@ -456,15 +456,15 @@  discard block
 block discarded – undo
456 456
 			);
457 457
 
458 458
 			// For each widget...
459
-			foreach ( $widgets as $widget ) {
459
+			foreach ($widgets as $widget) {
460 460
 				// Abort early if it is excluded for this page.
461
-				if ( in_array( $widget, $exclude ) ) {
461
+				if (in_array($widget, $exclude)) {
462 462
 					continue;
463 463
 				}
464 464
 
465 465
 				// SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it.
466
-				if ( is_subclass_of( $widget, 'WP_Widget' ) ) {
467
-					register_widget( $widget );
466
+				if (is_subclass_of($widget, 'WP_Widget')) {
467
+					register_widget($widget);
468 468
 				} else {
469 469
 					new $widget();
470 470
 				}
@@ -481,28 +481,28 @@  discard block
 block discarded – undo
481 481
 		// Ensure the database tables are up to date.
482 482
 		GetPaid_Installer::maybe_create_db_tables();
483 483
 
484
-		$wpi_version = get_option( 'wpinv_version', 0 );
484
+		$wpi_version = get_option('wpinv_version', 0);
485 485
 
486
-		if ( $wpi_version == WPINV_VERSION ) {
486
+		if ($wpi_version == WPINV_VERSION) {
487 487
 			return;
488 488
 		}
489 489
 
490 490
 		$installer = new GetPaid_Installer();
491 491
 
492
-		if ( empty( $wpi_version ) ) {
493
-			return $installer->upgrade_db( 0 );
492
+		if (empty($wpi_version)) {
493
+			return $installer->upgrade_db(0);
494 494
 		}
495 495
 
496
-		$upgrades  = array(
496
+		$upgrades = array(
497 497
 			'0.0.5' => '004',
498 498
 			'1.0.3' => '102',
499 499
 			'2.0.0' => '118',
500 500
 			'2.8.0' => '279',
501 501
 		);
502 502
 
503
-		foreach ( $upgrades as $key => $method ) {
504
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
505
-				return $installer->upgrade_db( $method );
503
+		foreach ($upgrades as $key => $method) {
504
+			if (version_compare($wpi_version, $key, '<')) {
505
+				return $installer->upgrade_db($method);
506 506
 			}
507 507
 		}
508 508
 	}
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
 	 * @since 2.0.8
514 514
 	 */
515 515
 	public function maybe_flush_permalinks() {
516
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
516
+		$flush = get_option('wpinv_flush_permalinks', 0);
517 517
 
518
-		if ( ! empty( $flush ) ) {
518
+		if (!empty($flush)) {
519 519
 			flush_rewrite_rules();
520
-			delete_option( 'wpinv_flush_permalinks' );
520
+			delete_option('wpinv_flush_permalinks');
521 521
 		}
522 522
 	}
523 523
 
@@ -527,9 +527,9 @@  discard block
 block discarded – undo
527 527
 	 * @since 1.0.19
528 528
 	 * @param int[] $excluded_posts_ids
529 529
 	 */
530
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) {
530
+	public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
531 531
 		// Ensure that we have an array.
532
-		if ( ! is_array( $excluded_posts_ids ) ) {
532
+		if (!is_array($excluded_posts_ids)) {
533 533
 			$excluded_posts_ids = array();
534 534
 		}
535 535
 
@@ -537,25 +537,25 @@  discard block
 block discarded – undo
537 537
 		$our_pages = array();
538 538
 
539 539
 		// Checkout page.
540
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
540
+		$our_pages[] = wpinv_get_option('checkout_page', false);
541 541
 
542 542
 		// Success page.
543
-		$our_pages[] = wpinv_get_option( 'success_page', false );
543
+		$our_pages[] = wpinv_get_option('success_page', false);
544 544
 
545 545
 		// Failure page.
546
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
546
+		$our_pages[] = wpinv_get_option('failure_page', false);
547 547
 
548 548
 		// History page.
549
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
549
+		$our_pages[] = wpinv_get_option('invoice_history_page', false);
550 550
 
551 551
 		// Subscriptions page.
552
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
552
+		$our_pages[] = wpinv_get_option('invoice_subscription_page', false);
553 553
 
554
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
554
+		$our_pages   = array_map('intval', array_filter($our_pages));
555 555
 
556 556
 		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
557 557
 
558
-		return array_unique( $excluded_posts_ids );
558
+		return array_unique($excluded_posts_ids);
559 559
 	}
560 560
 
561 561
 	/**
@@ -564,14 +564,14 @@  discard block
 block discarded – undo
564 564
 	 * @since 1.0.19
565 565
 	 * @param string[] $post_types
566 566
 	 */
567
-	public function exclude_invoicing_post_types( $post_types ) {
567
+	public function exclude_invoicing_post_types($post_types) {
568 568
 		// Ensure that we have an array.
569
-		if ( ! is_array( $post_types ) ) {
569
+		if (!is_array($post_types)) {
570 570
 			$post_types = array();
571 571
 		}
572 572
 
573 573
 		// Remove our post types.
574
-		return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) );
574
+		return array_diff($post_types, array_keys(getpaid_get_invoice_post_types()));
575 575
 	}
576 576
 
577 577
 	/**
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
 	 * @since 2.0.0
581 581
 	 */
582 582
 	public function wp_footer() {
583
-		wpinv_get_template( 'frontend-footer.php' );
583
+		wpinv_get_template('frontend-footer.php');
584 584
 	}
585 585
 
586 586
 	/**
@@ -589,14 +589,14 @@  discard block
 block discarded – undo
589 589
 	 * @since 2.0.0
590 590
 	 */
591 591
 	public function wp_head() {
592
-		wpinv_get_template( 'frontend-head.php' );
592
+		wpinv_get_template('frontend-head.php');
593 593
 	}
594 594
 
595 595
 	/**
596 596
 	 * Custom query vars.
597 597
 	 *
598 598
 	 */
599
-	public function custom_query_vars( $vars ) {
599
+	public function custom_query_vars($vars) {
600 600
 		$vars[] = 'getpaid-ipn';
601 601
 		return $vars;
602 602
 	}
@@ -607,26 +607,26 @@  discard block
 block discarded – undo
607 607
 	 */
608 608
 	public function add_rewrite_rule() {
609 609
 		$tag = 'getpaid-ipn';
610
-		add_rewrite_tag( "%$tag%", '([^&]+)' );
611
-		add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' );
610
+		add_rewrite_tag("%$tag%", '([^&]+)');
611
+		add_rewrite_rule("^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top');
612 612
 	}
613 613
 
614 614
 	/**
615 615
 	 * Processes non-query string ipns.
616 616
 	 *
617 617
 	 */
618
-	public function maybe_process_new_ipn( $query ) {
619
-		if ( is_admin() || ! $query->is_main_query() ) {
618
+	public function maybe_process_new_ipn($query) {
619
+		if (is_admin() || !$query->is_main_query()) {
620 620
 			return;
621 621
 		}
622 622
 
623
-		$gateway = get_query_var( 'getpaid-ipn' );
623
+		$gateway = get_query_var('getpaid-ipn');
624 624
 
625
-		if ( ! empty( $gateway ) ) {
626
-			$gateway = sanitize_text_field( $gateway );
625
+		if (!empty($gateway)) {
626
+			$gateway = sanitize_text_field($gateway);
627 627
 			nocache_headers();
628
-			do_action( 'wpinv_verify_payment_ipn', $gateway );
629
-			do_action( "wpinv_verify_{$gateway}_ipn" );
628
+			do_action('wpinv_verify_payment_ipn', $gateway);
629
+			do_action("wpinv_verify_{$gateway}_ipn");
630 630
 			exit;
631 631
 		}
632 632
 	}
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-bank-transfer-gateway.php 2 patches
Indentation   +363 added lines, -363 removed lines patch added patch discarded remove patch
@@ -13,47 +13,47 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Bank_Transfer_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 = 'bank_transfer';
21 21
 
22
-	/**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
27
-	protected $supports = array(
28
-		'subscription',
29
-		'addons',
30
-		'single_subscription_group',
31
-		'multiple_subscription_groups',
32
-		'subscription_date_change',
33
-		'subscription_bill_times_change',
34
-	);
22
+    /**
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27
+    protected $supports = array(
28
+        'subscription',
29
+        'addons',
30
+        'single_subscription_group',
31
+        'multiple_subscription_groups',
32
+        'subscription_date_change',
33
+        'subscription_bill_times_change',
34
+    );
35
+
36
+    /**
37
+     * Payment method order.
38
+     *
39
+     * @var int
40
+     */
41
+    public $order = 8;
42
+
43
+    /**
44
+     * Bank transfer instructions.
45
+     */
46
+    public $instructions;
35 47
 
36 48
     /**
37
-	 * Payment method order.
38
-	 *
39
-	 * @var int
40
-	 */
41
-	public $order = 8;
42
-
43
-	/**
44
-	 * Bank transfer instructions.
45
-	 */
46
-	public $instructions;
47
-
48
-	/**
49
-	 * Locale array.
50
-	 */
51
-	public $locale;
49
+     * Locale array.
50
+     */
51
+    public $locale;
52 52
 
53 53
     /**
54
-	 * Class constructor.
55
-	 */
56
-	public function __construct() {
54
+     * Class constructor.
55
+     */
56
+    public function __construct() {
57 57
         parent::__construct();
58 58
 
59 59
         $this->title                = __( 'Direct bank transfer', 'invoicing' );
@@ -61,43 +61,43 @@  discard block
 block discarded – undo
61 61
         $this->checkout_button_text = __( 'Proceed', 'invoicing' );
62 62
         $this->instructions         = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) );
63 63
 
64
-		add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
65
-		add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
66
-		add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
67
-		add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
68
-		add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ), 12, 2 );
69
-		add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
70
-
71
-		add_filter( 'wpinv_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 );
72
-		add_filter( 'getpaid_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 );
73
-		add_filter( 'getpaid_' . $this->id . '_supports_subscription', array( $this, 'supports_subscription' ), 20, 1 );
74
-	}
75
-
76
-	/**
77
-	 * Check gateway supports for subscription.
78
-	 *
79
-	 * @since 2.8.24
80
-	 *
81
-	 * @param bool $supports True if supports else False.
82
-	 * @return bool True if supports else False.
83
-	 */
84
-	public function supports_subscription( $supports ) {
85
-		if ( $supports && (int) $this->get_option( 'no_subscription' ) ) {
86
-			$supports = false;
87
-		}
88
-
89
-		return $supports;
90
-	}
91
-
92
-	/**
93
-	 * Process Payment.
94
-	 *
95
-	 * @param WPInv_Invoice $invoice Invoice.
96
-	 * @param array $submission_data Posted checkout fields.
97
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
98
-	 * @return array
99
-	 */
100
-	public function process_payment( $invoice, $submission_data, $submission ) {
64
+        add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
65
+        add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
66
+        add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
67
+        add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
68
+        add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ), 12, 2 );
69
+        add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
70
+
71
+        add_filter( 'wpinv_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 );
72
+        add_filter( 'getpaid_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 );
73
+        add_filter( 'getpaid_' . $this->id . '_supports_subscription', array( $this, 'supports_subscription' ), 20, 1 );
74
+    }
75
+
76
+    /**
77
+     * Check gateway supports for subscription.
78
+     *
79
+     * @since 2.8.24
80
+     *
81
+     * @param bool $supports True if supports else False.
82
+     * @return bool True if supports else False.
83
+     */
84
+    public function supports_subscription( $supports ) {
85
+        if ( $supports && (int) $this->get_option( 'no_subscription' ) ) {
86
+            $supports = false;
87
+        }
88
+
89
+        return $supports;
90
+    }
91
+
92
+    /**
93
+     * Process Payment.
94
+     *
95
+     * @param WPInv_Invoice $invoice Invoice.
96
+     * @param array $submission_data Posted checkout fields.
97
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
98
+     * @return array
99
+     */
100
+    public function process_payment( $invoice, $submission_data, $submission ) {
101 101
 
102 102
         // Add a transaction id.
103 103
         $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) );
@@ -118,66 +118,66 @@  discard block
 block discarded – undo
118 118
     }
119 119
 
120 120
     /**
121
-	 * Output for the order received page.
122
-	 *
123
-	 * @param WPInv_Invoice $invoice Invoice.
124
-	 */
125
-	public function thankyou_page( $invoice ) {
121
+     * Output for the order received page.
122
+     *
123
+     * @param WPInv_Invoice $invoice Invoice.
124
+     */
125
+    public function thankyou_page( $invoice ) {
126 126
 
127 127
         if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
128 128
 
129
-			echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
129
+            echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
130 130
 
131 131
             if ( ! empty( $this->instructions ) ) {
132 132
                 echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
133
-			}
133
+            }
134 134
 
135
-			$this->bank_details( $invoice );
135
+            $this->bank_details( $invoice );
136 136
 
137
-			echo '</div>';
137
+            echo '</div>';
138 138
 
139 139
         }
140 140
 
141
-	}
141
+    }
142 142
 
143 143
     /**
144
-	 * Add content to the WPI emails.
145
-	 *
146
-	 * @param WPInv_Invoice $invoice Invoice.
147
-	 * @param string     $email_type Email format: plain text or HTML.
148
-	 * @param bool     $sent_to_admin Sent to admin.
149
-	 */
150
-	public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
144
+     * Add content to the WPI emails.
145
+     *
146
+     * @param WPInv_Invoice $invoice Invoice.
147
+     * @param string     $email_type Email format: plain text or HTML.
148
+     * @param bool     $sent_to_admin Sent to admin.
149
+     */
150
+    public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
151 151
 
152
-		if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
152
+        if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
153 153
 
154
-			echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
154
+            echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
155 155
 
156
-			if ( $this->instructions ) {
157
-				echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
156
+            if ( $this->instructions ) {
157
+                echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
158 158
             }
159 159
 
160
-			$this->bank_details( $invoice );
160
+            $this->bank_details( $invoice );
161 161
 
162
-			echo '</div>';
162
+            echo '</div>';
163 163
 
164
-		}
164
+        }
165 165
 
166 166
     }
167 167
 
168 168
     /**
169
-	 * Get bank details and place into a list format.
170
-	 *
171
-	 * @param WPInv_Invoice $invoice Invoice.
172
-	 */
173
-	protected function bank_details( $invoice ) {
169
+     * Get bank details and place into a list format.
170
+     *
171
+     * @param WPInv_Invoice $invoice Invoice.
172
+     */
173
+    protected function bank_details( $invoice ) {
174 174
 
175
-		// Get the invoice country and country $locale.
176
-		$country = $invoice->get_country();
177
-		$locale  = $this->get_country_locale();
175
+        // Get the invoice country and country $locale.
176
+        $country = $invoice->get_country();
177
+        $locale  = $this->get_country_locale();
178 178
 
179
-		// Get shortcode label in the $locale array and use appropriate one.
180
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
179
+        // Get shortcode label in the $locale array and use appropriate one.
180
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
181 181
 
182 182
         $bank_fields = array(
183 183
             'ac_name'   => __( 'Account Name', 'invoicing' ),
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 
197 197
             if ( ! empty( $value ) ) {
198 198
                 $bank_info[ $field ] = array(
199
-					'label' => $label,
200
-					'value' => $value,
201
-				);
199
+                    'label' => $label,
200
+                    'value' => $value,
201
+                );
202 202
             }
203
-		}
203
+        }
204 204
 
205 205
         $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice );
206 206
 
@@ -208,177 +208,177 @@  discard block
 block discarded – undo
208 208
             return;
209 209
         }
210 210
 
211
-		echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
211
+        echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
212
+
213
+        echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
214
+
215
+        foreach ( $bank_info as $key => $data ) {
216
+            echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL;
217
+        }
218
+
219
+        echo '</table>';
220
+
221
+    }
222
+
223
+    /**
224
+     * Get country locale if localized.
225
+     *
226
+     * @return array
227
+     */
228
+    public function get_country_locale() {
229
+
230
+        if ( empty( $this->locale ) ) {
231
+
232
+            // Locale information to be used - only those that are not 'Sort Code'.
233
+            $this->locale = apply_filters(
234
+                'getpaid_get_bank_transfer_locale',
235
+                array(
236
+                    'AU' => array(
237
+                        'sortcode' => array(
238
+                            'label' => __( 'BSB', 'invoicing' ),
239
+                        ),
240
+                    ),
241
+                    'CA' => array(
242
+                        'sortcode' => array(
243
+                            'label' => __( 'Bank transit number', 'invoicing' ),
244
+                        ),
245
+                    ),
246
+                    'IN' => array(
247
+                        'sortcode' => array(
248
+                            'label' => __( 'IFSC', 'invoicing' ),
249
+                        ),
250
+                    ),
251
+                    'IT' => array(
252
+                        'sortcode' => array(
253
+                            'label' => __( 'Branch sort', 'invoicing' ),
254
+                        ),
255
+                    ),
256
+                    'NZ' => array(
257
+                        'sortcode' => array(
258
+                            'label' => __( 'Bank code', 'invoicing' ),
259
+                        ),
260
+                    ),
261
+                    'SE' => array(
262
+                        'sortcode' => array(
263
+                            'label' => __( 'Bank code', 'invoicing' ),
264
+                        ),
265
+                    ),
266
+                    'US' => array(
267
+                        'sortcode' => array(
268
+                            'label' => __( 'Routing number', 'invoicing' ),
269
+                        ),
270
+                    ),
271
+                    'ZA' => array(
272
+                        'sortcode' => array(
273
+                            'label' => __( 'Branch code', 'invoicing' ),
274
+                        ),
275
+                    ),
276
+                )
277
+            );
278
+
279
+        }
280
+
281
+        return $this->locale;
282
+
283
+    }
284
+
285
+    /**
286
+     * Filters the gateway settings.
287
+     *
288
+     * @param array $admin_settings
289
+     */
290
+    public function admin_settings( $admin_settings ) {
291
+        $admin_settings['bank_transfer_desc']['std']    = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' );
292
+        $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
293
+
294
+        $_settings = array();
295
+
296
+        foreach ( $admin_settings as $key => $setting ) {
297
+            $_settings[ $key ] = $setting;
298
+
299
+            if ( $key == 'bank_transfer_active' ) {
300
+                // Enable/disable subscriptions setting.
301
+                $_settings['bank_transfer_no_subscription'] = array(
302
+                    'id' => 'bank_transfer_no_subscription',
303
+                    'type' => 'checkbox',
304
+                    'name' => __( 'Disable Subscriptions', 'invoicing' ),
305
+                    'desc' => __( 'Tick to disable support for recurring items.', 'invoicing' ),
306
+                    'std' => 0
307
+                );
308
+            }
309
+        }
310
+
311
+        $admin_settings = $_settings;
312
+
313
+        $locale  = $this->get_country_locale();
314
+
315
+        // Get sortcode label in the $locale array and use appropriate one.
316
+        $country  = wpinv_default_billing_country();
317
+        $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
318
+
319
+        $admin_settings['bank_transfer_ac_name'] = array(
320
+            'type' => 'text',
321
+            'id'   => 'bank_transfer_ac_name',
322
+            'name' => __( 'Account Name', 'invoicing' ),
323
+        );
324
+
325
+        $admin_settings['bank_transfer_ac_no'] = array(
326
+            'type' => 'text',
327
+            'id'   => 'bank_transfer_ac_no',
328
+            'name' => __( 'Account Number', 'invoicing' ),
329
+        );
330
+
331
+        $admin_settings['bank_transfer_bank_name'] = array(
332
+            'type' => 'text',
333
+            'id'   => 'bank_transfer_bank_name',
334
+            'name' => __( 'Bank Name', 'invoicing' ),
335
+        );
212 336
 
213
-		echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
337
+        $admin_settings['bank_transfer_ifsc'] = array(
338
+            'type' => 'text',
339
+            'id'   => 'bank_transfer_ifsc',
340
+            'name' => __( 'IFSC Code', 'invoicing' ),
341
+        );
342
+
343
+        $admin_settings['bank_transfer_iban'] = array(
344
+            'type' => 'text',
345
+            'id'   => 'bank_transfer_iban',
346
+            'name' => __( 'IBAN', 'invoicing' ),
347
+        );
348
+
349
+        $admin_settings['bank_transfer_bic'] = array(
350
+            'type' => 'text',
351
+            'id'   => 'bank_transfer_bic',
352
+            'name' => __( 'BIC/Swift Code', 'invoicing' ),
353
+        );
214 354
 
215
-		foreach ( $bank_info as $key => $data ) {
216
-			echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL;
217
-		}
355
+        $admin_settings['bank_transfer_sort_code'] = array(
356
+            'type' => 'text',
357
+            'id'   => 'bank_transfer_sort_code',
358
+            'name' => $sortcode,
359
+        );
218 360
 
219
-		echo '</table>';
361
+        $admin_settings['bank_transfer_info'] = array(
362
+            'id'   => 'bank_transfer_info',
363
+            'name' => __( 'Instructions', 'invoicing' ),
364
+            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
365
+            'type' => 'textarea',
366
+            'std'  => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ),
367
+            'cols' => 50,
368
+            'rows' => 5,
369
+        );
220 370
 
371
+        return $admin_settings;
221 372
     }
222 373
 
223 374
     /**
224
-	 * Get country locale if localized.
225
-	 *
226
-	 * @return array
227
-	 */
228
-	public function get_country_locale() {
229
-
230
-		if ( empty( $this->locale ) ) {
231
-
232
-			// Locale information to be used - only those that are not 'Sort Code'.
233
-			$this->locale = apply_filters(
234
-				'getpaid_get_bank_transfer_locale',
235
-				array(
236
-					'AU' => array(
237
-						'sortcode' => array(
238
-							'label' => __( 'BSB', 'invoicing' ),
239
-						),
240
-					),
241
-					'CA' => array(
242
-						'sortcode' => array(
243
-							'label' => __( 'Bank transit number', 'invoicing' ),
244
-						),
245
-					),
246
-					'IN' => array(
247
-						'sortcode' => array(
248
-							'label' => __( 'IFSC', 'invoicing' ),
249
-						),
250
-					),
251
-					'IT' => array(
252
-						'sortcode' => array(
253
-							'label' => __( 'Branch sort', 'invoicing' ),
254
-						),
255
-					),
256
-					'NZ' => array(
257
-						'sortcode' => array(
258
-							'label' => __( 'Bank code', 'invoicing' ),
259
-						),
260
-					),
261
-					'SE' => array(
262
-						'sortcode' => array(
263
-							'label' => __( 'Bank code', 'invoicing' ),
264
-						),
265
-					),
266
-					'US' => array(
267
-						'sortcode' => array(
268
-							'label' => __( 'Routing number', 'invoicing' ),
269
-						),
270
-					),
271
-					'ZA' => array(
272
-						'sortcode' => array(
273
-							'label' => __( 'Branch code', 'invoicing' ),
274
-						),
275
-					),
276
-				)
277
-			);
278
-
279
-		}
280
-
281
-		return $this->locale;
282
-
283
-	}
284
-
285
-	/**
286
-	 * Filters the gateway settings.
287
-	 *
288
-	 * @param array $admin_settings
289
-	 */
290
-	public function admin_settings( $admin_settings ) {
291
-		$admin_settings['bank_transfer_desc']['std']    = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' );
292
-		$admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
293
-
294
-		$_settings = array();
295
-
296
-		foreach ( $admin_settings as $key => $setting ) {
297
-			$_settings[ $key ] = $setting;
298
-
299
-			if ( $key == 'bank_transfer_active' ) {
300
-				// Enable/disable subscriptions setting.
301
-				$_settings['bank_transfer_no_subscription'] = array(
302
-					'id' => 'bank_transfer_no_subscription',
303
-					'type' => 'checkbox',
304
-					'name' => __( 'Disable Subscriptions', 'invoicing' ),
305
-					'desc' => __( 'Tick to disable support for recurring items.', 'invoicing' ),
306
-					'std' => 0
307
-				);
308
-			}
309
-		}
310
-
311
-		$admin_settings = $_settings;
312
-
313
-		$locale  = $this->get_country_locale();
314
-
315
-		// Get sortcode label in the $locale array and use appropriate one.
316
-		$country  = wpinv_default_billing_country();
317
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
318
-
319
-		$admin_settings['bank_transfer_ac_name'] = array(
320
-			'type' => 'text',
321
-			'id'   => 'bank_transfer_ac_name',
322
-			'name' => __( 'Account Name', 'invoicing' ),
323
-		);
324
-
325
-		$admin_settings['bank_transfer_ac_no'] = array(
326
-			'type' => 'text',
327
-			'id'   => 'bank_transfer_ac_no',
328
-			'name' => __( 'Account Number', 'invoicing' ),
329
-		);
330
-
331
-		$admin_settings['bank_transfer_bank_name'] = array(
332
-			'type' => 'text',
333
-			'id'   => 'bank_transfer_bank_name',
334
-			'name' => __( 'Bank Name', 'invoicing' ),
335
-		);
336
-
337
-		$admin_settings['bank_transfer_ifsc'] = array(
338
-			'type' => 'text',
339
-			'id'   => 'bank_transfer_ifsc',
340
-			'name' => __( 'IFSC Code', 'invoicing' ),
341
-		);
342
-
343
-		$admin_settings['bank_transfer_iban'] = array(
344
-			'type' => 'text',
345
-			'id'   => 'bank_transfer_iban',
346
-			'name' => __( 'IBAN', 'invoicing' ),
347
-		);
348
-
349
-		$admin_settings['bank_transfer_bic'] = array(
350
-			'type' => 'text',
351
-			'id'   => 'bank_transfer_bic',
352
-			'name' => __( 'BIC/Swift Code', 'invoicing' ),
353
-		);
354
-
355
-		$admin_settings['bank_transfer_sort_code'] = array(
356
-			'type' => 'text',
357
-			'id'   => 'bank_transfer_sort_code',
358
-			'name' => $sortcode,
359
-		);
360
-
361
-		$admin_settings['bank_transfer_info'] = array(
362
-			'id'   => 'bank_transfer_info',
363
-			'name' => __( 'Instructions', 'invoicing' ),
364
-			'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
365
-			'type' => 'textarea',
366
-			'std'  => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ),
367
-			'cols' => 50,
368
-			'rows' => 5,
369
-		);
370
-
371
-		return $admin_settings;
372
-	}
373
-
374
-	/**
375
-	 * Processes invoice addons.
376
-	 *
377
-	 * @param WPInv_Invoice $invoice
378
-	 * @param GetPaid_Form_Item[] $items
379
-	 * @return WPInv_Invoice
380
-	 */
381
-	public function process_addons( $invoice, $items ) {
375
+     * Processes invoice addons.
376
+     *
377
+     * @param WPInv_Invoice $invoice
378
+     * @param GetPaid_Form_Item[] $items
379
+     * @return WPInv_Invoice
380
+     */
381
+    public function process_addons( $invoice, $items ) {
382 382
 
383 383
         foreach ( $items as $item ) {
384 384
             $invoice->add_item( $item );
@@ -386,98 +386,98 @@  discard block
 block discarded – undo
386 386
 
387 387
         $invoice->recalculate_total();
388 388
         $invoice->save();
389
-	}
390
-
391
-	/**
392
-	 * (Maybe) renews a bank transfer subscription profile.
393
-	 *
394
-	 *
395
-	 * @param WPInv_Subscription $subscription
396
-	 */
397
-	public function maybe_renew_subscription( $subscription, $parent_invoice ) {
398
-		// Ensure its our subscription && it's active.
399
-		if ( ! empty( $parent_invoice ) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
400
-			add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
401
-
402
-			$invoice = $subscription->create_payment();
403
-
404
-			if ( ! empty( $invoice ) ) {
405
-				$is_logged_in = is_user_logged_in();
406
-
407
-				// Cron run.
408
-				if ( ! $is_logged_in ) {
409
-					$note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) );
410
-
411
-					$invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in );
412
-				}
413
-			}
414
-
415
-			remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
416
-		}
417
-	}
418
-
419
-	/**
420
-	 * Process a bank transfer payment.
421
-	 *
422
-	 *
389
+    }
390
+
391
+    /**
392
+     * (Maybe) renews a bank transfer subscription profile.
393
+     *
394
+     *
395
+     * @param WPInv_Subscription $subscription
396
+     */
397
+    public function maybe_renew_subscription( $subscription, $parent_invoice ) {
398
+        // Ensure its our subscription && it's active.
399
+        if ( ! empty( $parent_invoice ) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
400
+            add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
401
+
402
+            $invoice = $subscription->create_payment();
403
+
404
+            if ( ! empty( $invoice ) ) {
405
+                $is_logged_in = is_user_logged_in();
406
+
407
+                // Cron run.
408
+                if ( ! $is_logged_in ) {
409
+                    $note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) );
410
+
411
+                    $invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in );
412
+                }
413
+            }
414
+
415
+            remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
416
+        }
417
+    }
418
+
419
+    /**
420
+     * Process a bank transfer payment.
421
+     *
422
+     *
423 423
      * @param WPInv_Invoice $invoice
424
-	 */
425
-	public function invoice_paid( $invoice ) {
426
-
427
-		// Abort if not paid by bank transfer.
428
-		if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
429
-			return;
430
-		}
431
-
432
-		// Is it a parent payment?
433
-		if ( 0 == $invoice->get_parent_id() ) {
434
-
435
-			// (Maybe) activate subscriptions.
436
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
437
-
438
-			if ( ! empty( $subscriptions ) ) {
439
-				$subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
440
-
441
-				foreach ( $subscriptions as $subscription ) {
442
-					if ( $subscription->exists() ) {
443
-						$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
444
-						$expiry   = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
445
-
446
-						$subscription->set_next_renewal_date( $expiry );
447
-						$subscription->set_date_created( current_time( 'mysql' ) );
448
-						$subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
449
-						$subscription->activate();
450
-					}
451
-				}
452
-			}
453
-		} else {
454
-
455
-			$subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
456
-
457
-			// Renew the subscription.
458
-			if ( $subscription && $subscription->exists() ) {
459
-				$subscription->add_payment( array(), $invoice );
460
-				$subscription->renew( strtotime( $invoice->get_date_created() ) );
461
-			}
462
-		}
424
+     */
425
+    public function invoice_paid( $invoice ) {
426
+
427
+        // Abort if not paid by bank transfer.
428
+        if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
429
+            return;
430
+        }
431
+
432
+        // Is it a parent payment?
433
+        if ( 0 == $invoice->get_parent_id() ) {
434
+
435
+            // (Maybe) activate subscriptions.
436
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
437
+
438
+            if ( ! empty( $subscriptions ) ) {
439
+                $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
440
+
441
+                foreach ( $subscriptions as $subscription ) {
442
+                    if ( $subscription->exists() ) {
443
+                        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
444
+                        $expiry   = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
445
+
446
+                        $subscription->set_next_renewal_date( $expiry );
447
+                        $subscription->set_date_created( current_time( 'mysql' ) );
448
+                        $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
449
+                        $subscription->activate();
450
+                    }
451
+                }
452
+            }
453
+        } else {
454
+
455
+            $subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
456
+
457
+            // Renew the subscription.
458
+            if ( $subscription && $subscription->exists() ) {
459
+                $subscription->add_payment( array(), $invoice );
460
+                $subscription->renew( strtotime( $invoice->get_date_created() ) );
461
+            }
462
+        }
463 463
 
464 464
     }
465 465
 
466
-	/**
467
-	 * Force created from payment false to allow email for auto renewal generation invoice.
468
-	 *
469
-	 * @since 2.8.11
470
-	 *
471
-	 * @param bool $is_payment_form_invoice True when invoice created via payment form else false.
472
-	 * @param int  $invoice Invoice ID.
473
-	 * @return bool True when invoice created via payment form else false.
474
-	 */
475
-	public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) {
476
-		if ( $is_payment_form_invoice ) {
477
-			$is_payment_form_invoice = false;
478
-		}
479
-
480
-		return $is_payment_form_invoice;
481
-	}
466
+    /**
467
+     * Force created from payment false to allow email for auto renewal generation invoice.
468
+     *
469
+     * @since 2.8.11
470
+     *
471
+     * @param bool $is_payment_form_invoice True when invoice created via payment form else false.
472
+     * @param int  $invoice Invoice ID.
473
+     * @return bool True when invoice created via payment form else false.
474
+     */
475
+    public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) {
476
+        if ( $is_payment_form_invoice ) {
477
+            $is_payment_form_invoice = false;
478
+        }
479
+
480
+        return $is_payment_form_invoice;
481
+    }
482 482
 
483 483
 }
Please login to merge, or discard this patch.
Spacing   +109 added lines, -109 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
  * Bank transfer Payment Gateway class.
@@ -56,21 +56,21 @@  discard block
 block discarded – undo
56 56
 	public function __construct() {
57 57
         parent::__construct();
58 58
 
59
-        $this->title                = __( 'Direct bank transfer', 'invoicing' );
60
-        $this->method_title         = __( 'Bank transfer', 'invoicing' );
61
-        $this->checkout_button_text = __( 'Proceed', 'invoicing' );
62
-        $this->instructions         = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) );
63
-
64
-		add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) );
65
-		add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 );
66
-		add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 );
67
-		add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 );
68
-		add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ), 12, 2 );
69
-		add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 );
70
-
71
-		add_filter( 'wpinv_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 );
72
-		add_filter( 'getpaid_' . $this->id . '_support_subscription', array( $this, 'supports_subscription' ), 20, 1 );
73
-		add_filter( 'getpaid_' . $this->id . '_supports_subscription', array( $this, 'supports_subscription' ), 20, 1 );
59
+        $this->title                = __('Direct bank transfer', 'invoicing');
60
+        $this->method_title         = __('Bank transfer', 'invoicing');
61
+        $this->checkout_button_text = __('Proceed', 'invoicing');
62
+        $this->instructions         = apply_filters('wpinv_bank_instructions', $this->get_option('info'));
63
+
64
+		add_action('wpinv_receipt_end', array($this, 'thankyou_page'));
65
+		add_action('getpaid_invoice_line_items', array($this, 'thankyou_page'), 40);
66
+		add_action('wpinv_pdf_content_billing', array($this, 'thankyou_page'), 11);
67
+		add_action('wpinv_email_invoice_details', array($this, 'email_instructions'), 10, 3);
68
+		add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription'), 12, 2);
69
+		add_action('getpaid_invoice_status_publish', array($this, 'invoice_paid'), 20);
70
+
71
+		add_filter('wpinv_' . $this->id . '_support_subscription', array($this, 'supports_subscription'), 20, 1);
72
+		add_filter('getpaid_' . $this->id . '_support_subscription', array($this, 'supports_subscription'), 20, 1);
73
+		add_filter('getpaid_' . $this->id . '_supports_subscription', array($this, 'supports_subscription'), 20, 1);
74 74
 	}
75 75
 
76 76
 	/**
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
 	 * @param bool $supports True if supports else False.
82 82
 	 * @return bool True if supports else False.
83 83
 	 */
84
-	public function supports_subscription( $supports ) {
85
-		if ( $supports && (int) $this->get_option( 'no_subscription' ) ) {
84
+	public function supports_subscription($supports) {
85
+		if ($supports && (int) $this->get_option('no_subscription')) {
86 86
 			$supports = false;
87 87
 		}
88 88
 
@@ -97,23 +97,23 @@  discard block
 block discarded – undo
97 97
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
98 98
 	 * @return array
99 99
 	 */
100
-	public function process_payment( $invoice, $submission_data, $submission ) {
100
+	public function process_payment($invoice, $submission_data, $submission) {
101 101
 
102 102
         // Add a transaction id.
103
-        $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) );
103
+        $invoice->set_transaction_id($invoice->generate_key('bt_'));
104 104
 
105 105
         // Set it as pending payment.
106
-        if ( ! $invoice->needs_payment() ) {
106
+        if (!$invoice->needs_payment()) {
107 107
             $invoice->mark_paid();
108
-        } elseif ( ! $invoice->is_paid() ) {
109
-            $invoice->set_status( 'wpi-onhold' );
108
+        } elseif (!$invoice->is_paid()) {
109
+            $invoice->set_status('wpi-onhold');
110 110
         }
111 111
 
112 112
         // Save it.
113 113
         $invoice->save();
114 114
 
115 115
         // Send to the success page.
116
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
116
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
117 117
 
118 118
     }
119 119
 
@@ -122,17 +122,17 @@  discard block
 block discarded – undo
122 122
 	 *
123 123
 	 * @param WPInv_Invoice $invoice Invoice.
124 124
 	 */
125
-	public function thankyou_page( $invoice ) {
125
+	public function thankyou_page($invoice) {
126 126
 
127
-        if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
127
+        if ('bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) {
128 128
 
129 129
 			echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL;
130 130
 
131
-            if ( ! empty( $this->instructions ) ) {
132
-                echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) );
131
+            if (!empty($this->instructions)) {
132
+                echo wp_kses_post(wpautop(wptexturize($this->instructions)));
133 133
 			}
134 134
 
135
-			$this->bank_details( $invoice );
135
+			$this->bank_details($invoice);
136 136
 
137 137
 			echo '</div>';
138 138
 
@@ -147,17 +147,17 @@  discard block
 block discarded – undo
147 147
 	 * @param string     $email_type Email format: plain text or HTML.
148 148
 	 * @param bool     $sent_to_admin Sent to admin.
149 149
 	 */
150
-	public function email_instructions( $invoice, $email_type, $sent_to_admin ) {
150
+	public function email_instructions($invoice, $email_type, $sent_to_admin) {
151 151
 
152
-		if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) {
152
+		if (!$sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment()) {
153 153
 
154 154
 			echo '<div class="wpi-email-row getpaid-bank-transfer-details">';
155 155
 
156
-			if ( $this->instructions ) {
157
-				echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL );
156
+			if ($this->instructions) {
157
+				echo wp_kses_post(wpautop(wptexturize($this->instructions)) . PHP_EOL);
158 158
             }
159 159
 
160
-			$this->bank_details( $invoice );
160
+			$this->bank_details($invoice);
161 161
 
162 162
 			echo '</div>';
163 163
 
@@ -170,50 +170,50 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @param WPInv_Invoice $invoice Invoice.
172 172
 	 */
173
-	protected function bank_details( $invoice ) {
173
+	protected function bank_details($invoice) {
174 174
 
175 175
 		// Get the invoice country and country $locale.
176 176
 		$country = $invoice->get_country();
177 177
 		$locale  = $this->get_country_locale();
178 178
 
179 179
 		// Get shortcode label in the $locale array and use appropriate one.
180
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
180
+		$sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing');
181 181
 
182 182
         $bank_fields = array(
183
-            'ac_name'   => __( 'Account Name', 'invoicing' ),
184
-            'ac_no'     => __( 'Account Number', 'invoicing' ),
185
-            'bank_name' => __( 'Bank Name', 'invoicing' ),
186
-            'ifsc'      => __( 'IFSC code', 'invoicing' ),
187
-            'iban'      => __( 'IBAN', 'invoicing' ),
188
-            'bic'       => __( 'BIC/Swift code', 'invoicing' ),
183
+            'ac_name'   => __('Account Name', 'invoicing'),
184
+            'ac_no'     => __('Account Number', 'invoicing'),
185
+            'bank_name' => __('Bank Name', 'invoicing'),
186
+            'ifsc'      => __('IFSC code', 'invoicing'),
187
+            'iban'      => __('IBAN', 'invoicing'),
188
+            'bic'       => __('BIC/Swift code', 'invoicing'),
189 189
             'sort_code' => $sortcode,
190 190
         );
191 191
 
192 192
         $bank_info = array();
193 193
 
194
-        foreach ( $bank_fields as $field => $label ) {
195
-            $value = $this->get_option( $field );
194
+        foreach ($bank_fields as $field => $label) {
195
+            $value = $this->get_option($field);
196 196
 
197
-            if ( ! empty( $value ) ) {
198
-                $bank_info[ $field ] = array(
197
+            if (!empty($value)) {
198
+                $bank_info[$field] = array(
199 199
 					'label' => $label,
200 200
 					'value' => $value,
201 201
 				);
202 202
             }
203 203
 		}
204 204
 
205
-        $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice );
205
+        $bank_info = apply_filters('wpinv_bank_info', $bank_info, $invoice);
206 206
 
207
-        if ( empty( $bank_info ) ) {
207
+        if (empty($bank_info)) {
208 208
             return;
209 209
         }
210 210
 
211
-		echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL;
211
+		echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html(apply_filters('wpinv_receipt_bank_details_title', __('Bank Details', 'invoicing'), $invoice)) . '</h3>' . PHP_EOL;
212 212
 
213 213
 		echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL;
214 214
 
215
-		foreach ( $bank_info as $key => $data ) {
216
-			echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL;
215
+		foreach ($bank_info as $key => $data) {
216
+			echo "<tr class='getpaid-bank-transfer-" . esc_attr($key) . "'><th class='font-weight-bold'>" . wp_kses_post($data['label']) . "</th><td class='w-75'>" . wp_kses_post(wptexturize($data['value'])) . '</td></tr>' . PHP_EOL;
217 217
 		}
218 218
 
219 219
 		echo '</table>';
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	 */
228 228
 	public function get_country_locale() {
229 229
 
230
-		if ( empty( $this->locale ) ) {
230
+		if (empty($this->locale)) {
231 231
 
232 232
 			// Locale information to be used - only those that are not 'Sort Code'.
233 233
 			$this->locale = apply_filters(
@@ -235,42 +235,42 @@  discard block
 block discarded – undo
235 235
 				array(
236 236
 					'AU' => array(
237 237
 						'sortcode' => array(
238
-							'label' => __( 'BSB', 'invoicing' ),
238
+							'label' => __('BSB', 'invoicing'),
239 239
 						),
240 240
 					),
241 241
 					'CA' => array(
242 242
 						'sortcode' => array(
243
-							'label' => __( 'Bank transit number', 'invoicing' ),
243
+							'label' => __('Bank transit number', 'invoicing'),
244 244
 						),
245 245
 					),
246 246
 					'IN' => array(
247 247
 						'sortcode' => array(
248
-							'label' => __( 'IFSC', 'invoicing' ),
248
+							'label' => __('IFSC', 'invoicing'),
249 249
 						),
250 250
 					),
251 251
 					'IT' => array(
252 252
 						'sortcode' => array(
253
-							'label' => __( 'Branch sort', 'invoicing' ),
253
+							'label' => __('Branch sort', 'invoicing'),
254 254
 						),
255 255
 					),
256 256
 					'NZ' => array(
257 257
 						'sortcode' => array(
258
-							'label' => __( 'Bank code', 'invoicing' ),
258
+							'label' => __('Bank code', 'invoicing'),
259 259
 						),
260 260
 					),
261 261
 					'SE' => array(
262 262
 						'sortcode' => array(
263
-							'label' => __( 'Bank code', 'invoicing' ),
263
+							'label' => __('Bank code', 'invoicing'),
264 264
 						),
265 265
 					),
266 266
 					'US' => array(
267 267
 						'sortcode' => array(
268
-							'label' => __( 'Routing number', 'invoicing' ),
268
+							'label' => __('Routing number', 'invoicing'),
269 269
 						),
270 270
 					),
271 271
 					'ZA' => array(
272 272
 						'sortcode' => array(
273
-							'label' => __( 'Branch code', 'invoicing' ),
273
+							'label' => __('Branch code', 'invoicing'),
274 274
 						),
275 275
 					),
276 276
 				)
@@ -287,22 +287,22 @@  discard block
 block discarded – undo
287 287
 	 *
288 288
 	 * @param array $admin_settings
289 289
 	 */
290
-	public function admin_settings( $admin_settings ) {
291
-		$admin_settings['bank_transfer_desc']['std']    = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' );
292
-		$admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' );
290
+	public function admin_settings($admin_settings) {
291
+		$admin_settings['bank_transfer_desc']['std']    = __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing');
292
+		$admin_settings['bank_transfer_active']['desc'] = __('Enable bank transfer', 'invoicing');
293 293
 
294 294
 		$_settings = array();
295 295
 
296
-		foreach ( $admin_settings as $key => $setting ) {
297
-			$_settings[ $key ] = $setting;
296
+		foreach ($admin_settings as $key => $setting) {
297
+			$_settings[$key] = $setting;
298 298
 
299
-			if ( $key == 'bank_transfer_active' ) {
299
+			if ($key == 'bank_transfer_active') {
300 300
 				// Enable/disable subscriptions setting.
301 301
 				$_settings['bank_transfer_no_subscription'] = array(
302 302
 					'id' => 'bank_transfer_no_subscription',
303 303
 					'type' => 'checkbox',
304
-					'name' => __( 'Disable Subscriptions', 'invoicing' ),
305
-					'desc' => __( 'Tick to disable support for recurring items.', 'invoicing' ),
304
+					'name' => __('Disable Subscriptions', 'invoicing'),
305
+					'desc' => __('Tick to disable support for recurring items.', 'invoicing'),
306 306
 					'std' => 0
307 307
 				);
308 308
 			}
@@ -310,46 +310,46 @@  discard block
 block discarded – undo
310 310
 
311 311
 		$admin_settings = $_settings;
312 312
 
313
-		$locale  = $this->get_country_locale();
313
+		$locale = $this->get_country_locale();
314 314
 
315 315
 		// Get sortcode label in the $locale array and use appropriate one.
316 316
 		$country  = wpinv_default_billing_country();
317
-		$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' );
317
+		$sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort code', 'invoicing');
318 318
 
319 319
 		$admin_settings['bank_transfer_ac_name'] = array(
320 320
 			'type' => 'text',
321 321
 			'id'   => 'bank_transfer_ac_name',
322
-			'name' => __( 'Account Name', 'invoicing' ),
322
+			'name' => __('Account Name', 'invoicing'),
323 323
 		);
324 324
 
325 325
 		$admin_settings['bank_transfer_ac_no'] = array(
326 326
 			'type' => 'text',
327 327
 			'id'   => 'bank_transfer_ac_no',
328
-			'name' => __( 'Account Number', 'invoicing' ),
328
+			'name' => __('Account Number', 'invoicing'),
329 329
 		);
330 330
 
331 331
 		$admin_settings['bank_transfer_bank_name'] = array(
332 332
 			'type' => 'text',
333 333
 			'id'   => 'bank_transfer_bank_name',
334
-			'name' => __( 'Bank Name', 'invoicing' ),
334
+			'name' => __('Bank Name', 'invoicing'),
335 335
 		);
336 336
 
337 337
 		$admin_settings['bank_transfer_ifsc'] = array(
338 338
 			'type' => 'text',
339 339
 			'id'   => 'bank_transfer_ifsc',
340
-			'name' => __( 'IFSC Code', 'invoicing' ),
340
+			'name' => __('IFSC Code', 'invoicing'),
341 341
 		);
342 342
 
343 343
 		$admin_settings['bank_transfer_iban'] = array(
344 344
 			'type' => 'text',
345 345
 			'id'   => 'bank_transfer_iban',
346
-			'name' => __( 'IBAN', 'invoicing' ),
346
+			'name' => __('IBAN', 'invoicing'),
347 347
 		);
348 348
 
349 349
 		$admin_settings['bank_transfer_bic'] = array(
350 350
 			'type' => 'text',
351 351
 			'id'   => 'bank_transfer_bic',
352
-			'name' => __( 'BIC/Swift Code', 'invoicing' ),
352
+			'name' => __('BIC/Swift Code', 'invoicing'),
353 353
 		);
354 354
 
355 355
 		$admin_settings['bank_transfer_sort_code'] = array(
@@ -360,10 +360,10 @@  discard block
 block discarded – undo
360 360
 
361 361
 		$admin_settings['bank_transfer_info'] = array(
362 362
 			'id'   => 'bank_transfer_info',
363
-			'name' => __( 'Instructions', 'invoicing' ),
364
-			'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
363
+			'name' => __('Instructions', 'invoicing'),
364
+			'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
365 365
 			'type' => 'textarea',
366
-			'std'  => __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ),
366
+			'std'  => __("Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing'),
367 367
 			'cols' => 50,
368 368
 			'rows' => 5,
369 369
 		);
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
 	 * @param GetPaid_Form_Item[] $items
379 379
 	 * @return WPInv_Invoice
380 380
 	 */
381
-	public function process_addons( $invoice, $items ) {
381
+	public function process_addons($invoice, $items) {
382 382
 
383
-        foreach ( $items as $item ) {
384
-            $invoice->add_item( $item );
383
+        foreach ($items as $item) {
384
+            $invoice->add_item($item);
385 385
         }
386 386
 
387 387
         $invoice->recalculate_total();
@@ -394,25 +394,25 @@  discard block
 block discarded – undo
394 394
 	 *
395 395
 	 * @param WPInv_Subscription $subscription
396 396
 	 */
397
-	public function maybe_renew_subscription( $subscription, $parent_invoice ) {
397
+	public function maybe_renew_subscription($subscription, $parent_invoice) {
398 398
 		// Ensure its our subscription && it's active.
399
-		if ( ! empty( $parent_invoice ) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
400
-			add_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
399
+		if (!empty($parent_invoice) && $this->id === $parent_invoice->get_gateway() && $subscription->has_status('active trialling')) {
400
+			add_filter('getpaid_invoice_notifications_is_payment_form_invoice', array($this, 'force_is_payment_form_invoice'), 10, 2);
401 401
 
402 402
 			$invoice = $subscription->create_payment();
403 403
 
404
-			if ( ! empty( $invoice ) ) {
404
+			if (!empty($invoice)) {
405 405
 				$is_logged_in = is_user_logged_in();
406 406
 
407 407
 				// Cron run.
408
-				if ( ! $is_logged_in ) {
409
-					$note = wp_sprintf( __( 'Renewal %1$s created with the status "%2$s".', 'invoicing' ), $invoice->get_invoice_quote_type(), wpinv_status_nicename( $invoice->get_status(), $invoice ) );
408
+				if (!$is_logged_in) {
409
+					$note = wp_sprintf(__('Renewal %1$s created with the status "%2$s".', 'invoicing'), $invoice->get_invoice_quote_type(), wpinv_status_nicename($invoice->get_status(), $invoice));
410 410
 
411
-					$invoice->add_note( $note, false, $is_logged_in, ! $is_logged_in );
411
+					$invoice->add_note($note, false, $is_logged_in, !$is_logged_in);
412 412
 				}
413 413
 			}
414 414
 
415
-			remove_filter( 'getpaid_invoice_notifications_is_payment_form_invoice', array( $this, 'force_is_payment_form_invoice' ), 10, 2 );
415
+			remove_filter('getpaid_invoice_notifications_is_payment_form_invoice', array($this, 'force_is_payment_form_invoice'), 10, 2);
416 416
 		}
417 417
 	}
418 418
 
@@ -422,42 +422,42 @@  discard block
 block discarded – undo
422 422
 	 *
423 423
      * @param WPInv_Invoice $invoice
424 424
 	 */
425
-	public function invoice_paid( $invoice ) {
425
+	public function invoice_paid($invoice) {
426 426
 
427 427
 		// Abort if not paid by bank transfer.
428
-		if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) {
428
+		if ($this->id !== $invoice->get_gateway() || !$invoice->is_recurring()) {
429 429
 			return;
430 430
 		}
431 431
 
432 432
 		// Is it a parent payment?
433
-		if ( 0 == $invoice->get_parent_id() ) {
433
+		if (0 == $invoice->get_parent_id()) {
434 434
 
435 435
 			// (Maybe) activate subscriptions.
436
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
436
+			$subscriptions = getpaid_get_invoice_subscriptions($invoice);
437 437
 
438
-			if ( ! empty( $subscriptions ) ) {
439
-				$subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
438
+			if (!empty($subscriptions)) {
439
+				$subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
440 440
 
441
-				foreach ( $subscriptions as $subscription ) {
442
-					if ( $subscription->exists() ) {
443
-						$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
444
-						$expiry   = gmdate( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
441
+				foreach ($subscriptions as $subscription) {
442
+					if ($subscription->exists()) {
443
+						$duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
444
+						$expiry   = gmdate('Y-m-d H:i:s', (current_time('timestamp') + $duration));
445 445
 
446
-						$subscription->set_next_renewal_date( $expiry );
447
-						$subscription->set_date_created( current_time( 'mysql' ) );
448
-						$subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() );
446
+						$subscription->set_next_renewal_date($expiry);
447
+						$subscription->set_date_created(current_time('mysql'));
448
+						$subscription->set_profile_id('bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id());
449 449
 						$subscription->activate();
450 450
 					}
451 451
 				}
452 452
 			}
453 453
 		} else {
454 454
 
455
-			$subscription = getpaid_get_subscription( $invoice->get_subscription_id() );
455
+			$subscription = getpaid_get_subscription($invoice->get_subscription_id());
456 456
 
457 457
 			// Renew the subscription.
458
-			if ( $subscription && $subscription->exists() ) {
459
-				$subscription->add_payment( array(), $invoice );
460
-				$subscription->renew( strtotime( $invoice->get_date_created() ) );
458
+			if ($subscription && $subscription->exists()) {
459
+				$subscription->add_payment(array(), $invoice);
460
+				$subscription->renew(strtotime($invoice->get_date_created()));
461 461
 			}
462 462
 		}
463 463
 
@@ -472,8 +472,8 @@  discard block
 block discarded – undo
472 472
 	 * @param int  $invoice Invoice ID.
473 473
 	 * @return bool True when invoice created via payment form else false.
474 474
 	 */
475
-	public function force_is_payment_form_invoice( $is_payment_form_invoice, $invoice ) {
476
-		if ( $is_payment_form_invoice ) {
475
+	public function force_is_payment_form_invoice($is_payment_form_invoice, $invoice) {
476
+		if ($is_payment_form_invoice) {
477 477
 			$is_payment_form_invoice = false;
478 478
 		}
479 479
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin-setup-wizard.php 2 patches
Indentation   +388 added lines, -388 removed lines patch added patch discarded remove patch
@@ -17,402 +17,402 @@
 block discarded – undo
17 17
  */
18 18
 class GetPaid_Admin_Setup_Wizard {
19 19
 
20
-	/**
21
-	 * @var string Current Step
22
-	 */
23
-	protected $step = '';
24
-
25
-	/**
26
-	 * @var string|false Previous Step
27
-	 */
28
-	protected $previous_step = '';
29
-
30
-	/**
31
-	 * @var string|false Next Step
32
-	 */
33
-	protected $next_step = '';
34
-
35
-	/**
36
-	 * @var array All available steps for the setup wizard
37
-	 */
38
-	protected $steps = array();
39
-
40
-	/**
41
-	 * Class constructor.
42
-	 *
43
-	 * @since 2.4.0
44
-	 */
45
-	public function __construct() {
46
-
47
-		if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) {
48
-			add_action( 'admin_menu', array( $this, 'add_menu' ) );
49
-			add_action( 'current_screen', array( $this, 'setup_wizard' ) );
50
-			add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) );
51
-		}
52
-
53
-	}
54
-
55
-	/**
56
-	 * Add admin menus/screens.
57
-	 *
58
-	 * @since 2.4.0
59
-	 */
60
-	public function add_menu() {
61
-		add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
62
-	}
63
-
64
-	/**
65
-	 * Sets up the setup wizard.
66
-	 *
67
-	 * @since 2.4.0
68
-	 */
69
-	public function setup_wizard() {
70
-
71
-		if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
72
-			$this->setup_globals();
73
-			$this->maybe_save_current_step();
74
-			$this->display_wizard();
75
-			exit;
76
-		}
77
-
78
-	}
79
-
80
-	public function remove_deprecated_functions() {
81
-		// removes deprecated warnings from page
82
-		remove_action('admin_print_styles', 'print_emoji_styles');
83
-		remove_action( 'admin_head', 'wp_admin_bar_header' );
84
-	}
85
-
86
-	/**
87
-	 * Sets up class variables.
88
-	 *
89
-	 * @since 2.4.0
90
-	 */
91
-	protected function setup_globals() {
92
-		$this->steps         = $this->get_setup_steps();
93
-		$this->step          = $this->get_current_step();
94
-		$this->previous_step = $this->get_previous_step();
95
-		$this->next_step     = $this->get_next_step();
96
-	}
97
-
98
-	/**
99
-	 * Saves the current step.
100
-	 *
101
-	 * @since 2.4.0
102
-	 */
103
-	protected function maybe_save_current_step() {
104
-		if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) {
105
-			call_user_func( $this->steps[ $this->step ]['handler'], $this );
106
-		}
107
-	}
108
-
109
-	/**
110
-	 * Returns the setup steps.
111
-	 *
112
-	 * @since 2.4.0
113
-	 * @return array
114
-	 */
115
-	protected function get_setup_steps() {
116
-
117
-		$steps = array(
118
-
119
-			'introduction'     => array(
120
-				'name'    => __( 'Introduction', 'invoicing' ),
121
-				'view'    => array( $this, 'setup_introduction' ),
122
-				'handler' => '',
123
-			),
124
-
125
-			'business_details' => array(
126
-				'name'    => __( 'Business Details', 'invoicing' ),
127
-				'view'    => array( $this, 'setup_business' ),
128
-				'handler' => '',
129
-			),
130
-
131
-			'currency'         => array(
132
-				'name'    => __( 'Currency', 'invoicing' ),
133
-				'view'    => array( $this, 'setup_currency' ),
134
-				'handler' => '',
135
-			),
136
-
137
-			'payments'         => array(
138
-				'name'    => __( 'Payment Gateways', 'invoicing' ),
139
-				'view'    => array( $this, 'setup_payments' ),
140
-				'handler' => array( $this, 'setup_payments_save' ),
141
-			),
142
-
143
-			'recommend'        => array(
144
-				'name'    => __( 'Recommend', 'invoicing' ),
145
-				'view'    => array( $this, 'setup_recommend' ),
146
-				'handler' => '',
147
-			),
148
-
149
-			'next_steps'       => array(
150
-				'name'    => __( 'Get Paid', 'invoicing' ),
151
-				'view'    => array( $this, 'setup_ready' ),
152
-				'handler' => '',
153
-			),
154
-
155
-		);
156
-
157
-		return apply_filters( 'getpaid_setup_wizard_steps', $steps );
158
-
159
-	}
160
-
161
-	/**
162
-	 * Returns the current step.
163
-	 *
164
-	 * @since 2.4.0
165
-	 * @return string
166
-	 */
167
-	protected function get_current_step() {
168
-		$step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : '';
169
-		return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) );
170
-	}
171
-
172
-	/**
173
-	 * Returns the previous step.
174
-	 *
175
-	 * @since 2.4.0
176
-	 * @return string|false
177
-	 */
178
-	protected function get_previous_step() {
179
-
180
-		$previous = false;
181
-		$current  = $this->step;
182
-		foreach ( array_keys( $this->steps ) as $step ) {
183
-			if ( $current === $step ) {
184
-				return $previous;
185
-			}
186
-
187
-			$previous = $step;
188
-		}
189
-
190
-		return false;
191
-	}
192
-
193
-	/**
194
-	 * Returns the next step.
195
-	 *
196
-	 * @since 2.4.0
197
-	 * @return string|false
198
-	 */
199
-	protected function get_next_step() {
200
-
201
-		$on_current = false;
202
-		$current    = $this->step;
203
-		foreach ( array_keys( $this->steps ) as $step ) {
204
-
205
-			if ( $on_current ) {
206
-				return $step;
207
-			}
208
-
209
-			if ( $current === $step ) {
210
-				return $on_current = true;
211
-			}
20
+    /**
21
+     * @var string Current Step
22
+     */
23
+    protected $step = '';
24
+
25
+    /**
26
+     * @var string|false Previous Step
27
+     */
28
+    protected $previous_step = '';
29
+
30
+    /**
31
+     * @var string|false Next Step
32
+     */
33
+    protected $next_step = '';
34
+
35
+    /**
36
+     * @var array All available steps for the setup wizard
37
+     */
38
+    protected $steps = array();
39
+
40
+    /**
41
+     * Class constructor.
42
+     *
43
+     * @since 2.4.0
44
+     */
45
+    public function __construct() {
46
+
47
+        if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) {
48
+            add_action( 'admin_menu', array( $this, 'add_menu' ) );
49
+            add_action( 'current_screen', array( $this, 'setup_wizard' ) );
50
+            add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) );
51
+        }
52
+
53
+    }
54
+
55
+    /**
56
+     * Add admin menus/screens.
57
+     *
58
+     * @since 2.4.0
59
+     */
60
+    public function add_menu() {
61
+        add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
62
+    }
63
+
64
+    /**
65
+     * Sets up the setup wizard.
66
+     *
67
+     * @since 2.4.0
68
+     */
69
+    public function setup_wizard() {
70
+
71
+        if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
72
+            $this->setup_globals();
73
+            $this->maybe_save_current_step();
74
+            $this->display_wizard();
75
+            exit;
76
+        }
77
+
78
+    }
79
+
80
+    public function remove_deprecated_functions() {
81
+        // removes deprecated warnings from page
82
+        remove_action('admin_print_styles', 'print_emoji_styles');
83
+        remove_action( 'admin_head', 'wp_admin_bar_header' );
84
+    }
85
+
86
+    /**
87
+     * Sets up class variables.
88
+     *
89
+     * @since 2.4.0
90
+     */
91
+    protected function setup_globals() {
92
+        $this->steps         = $this->get_setup_steps();
93
+        $this->step          = $this->get_current_step();
94
+        $this->previous_step = $this->get_previous_step();
95
+        $this->next_step     = $this->get_next_step();
96
+    }
97
+
98
+    /**
99
+     * Saves the current step.
100
+     *
101
+     * @since 2.4.0
102
+     */
103
+    protected function maybe_save_current_step() {
104
+        if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) {
105
+            call_user_func( $this->steps[ $this->step ]['handler'], $this );
106
+        }
107
+    }
108
+
109
+    /**
110
+     * Returns the setup steps.
111
+     *
112
+     * @since 2.4.0
113
+     * @return array
114
+     */
115
+    protected function get_setup_steps() {
116
+
117
+        $steps = array(
118
+
119
+            'introduction'     => array(
120
+                'name'    => __( 'Introduction', 'invoicing' ),
121
+                'view'    => array( $this, 'setup_introduction' ),
122
+                'handler' => '',
123
+            ),
124
+
125
+            'business_details' => array(
126
+                'name'    => __( 'Business Details', 'invoicing' ),
127
+                'view'    => array( $this, 'setup_business' ),
128
+                'handler' => '',
129
+            ),
130
+
131
+            'currency'         => array(
132
+                'name'    => __( 'Currency', 'invoicing' ),
133
+                'view'    => array( $this, 'setup_currency' ),
134
+                'handler' => '',
135
+            ),
136
+
137
+            'payments'         => array(
138
+                'name'    => __( 'Payment Gateways', 'invoicing' ),
139
+                'view'    => array( $this, 'setup_payments' ),
140
+                'handler' => array( $this, 'setup_payments_save' ),
141
+            ),
142
+
143
+            'recommend'        => array(
144
+                'name'    => __( 'Recommend', 'invoicing' ),
145
+                'view'    => array( $this, 'setup_recommend' ),
146
+                'handler' => '',
147
+            ),
148
+
149
+            'next_steps'       => array(
150
+                'name'    => __( 'Get Paid', 'invoicing' ),
151
+                'view'    => array( $this, 'setup_ready' ),
152
+                'handler' => '',
153
+            ),
154
+
155
+        );
156
+
157
+        return apply_filters( 'getpaid_setup_wizard_steps', $steps );
158
+
159
+    }
160
+
161
+    /**
162
+     * Returns the current step.
163
+     *
164
+     * @since 2.4.0
165
+     * @return string
166
+     */
167
+    protected function get_current_step() {
168
+        $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : '';
169
+        return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) );
170
+    }
171
+
172
+    /**
173
+     * Returns the previous step.
174
+     *
175
+     * @since 2.4.0
176
+     * @return string|false
177
+     */
178
+    protected function get_previous_step() {
179
+
180
+        $previous = false;
181
+        $current  = $this->step;
182
+        foreach ( array_keys( $this->steps ) as $step ) {
183
+            if ( $current === $step ) {
184
+                return $previous;
185
+            }
186
+
187
+            $previous = $step;
188
+        }
189
+
190
+        return false;
191
+    }
192
+
193
+    /**
194
+     * Returns the next step.
195
+     *
196
+     * @since 2.4.0
197
+     * @return string|false
198
+     */
199
+    protected function get_next_step() {
200
+
201
+        $on_current = false;
202
+        $current    = $this->step;
203
+        foreach ( array_keys( $this->steps ) as $step ) {
204
+
205
+            if ( $on_current ) {
206
+                return $step;
207
+            }
208
+
209
+            if ( $current === $step ) {
210
+                return $on_current = true;
211
+            }
212 212
 }
213 213
 
214
-		return false;
215
-	}
216
-
217
-	/**
218
-	 * Displays the setup wizard.
219
-	 *
220
-	 * @since 2.4.0
221
-	 */
222
-	public function display_wizard() {
223
-		$this->display_header();
224
-		$this->display_current_step();
225
-		$this->display_footer();
226
-	}
227
-
228
-	/**
229
-	 * Displays the Wizard Header.
230
-	 *
231
-	 * @since 2.0.0
232
-	 */
233
-	public function display_header() {
234
-		$steps     = $this->steps;
235
-		$current   = $this->step;
236
-		$next_step = $this->next_step;
237
-		array_shift( $steps );
238
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
239
-	}
240
-
241
-	/**
242
-	 * Displays the content for the current step.
243
-	 *
244
-	 * @since 2.4.0
245
-	 */
246
-	public function display_current_step() {
247
-		?>
214
+        return false;
215
+    }
216
+
217
+    /**
218
+     * Displays the setup wizard.
219
+     *
220
+     * @since 2.4.0
221
+     */
222
+    public function display_wizard() {
223
+        $this->display_header();
224
+        $this->display_current_step();
225
+        $this->display_footer();
226
+    }
227
+
228
+    /**
229
+     * Displays the Wizard Header.
230
+     *
231
+     * @since 2.0.0
232
+     */
233
+    public function display_header() {
234
+        $steps     = $this->steps;
235
+        $current   = $this->step;
236
+        $next_step = $this->next_step;
237
+        array_shift( $steps );
238
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
239
+    }
240
+
241
+    /**
242
+     * Displays the content for the current step.
243
+     *
244
+     * @since 2.4.0
245
+     */
246
+    public function display_current_step() {
247
+        ?>
248 248
 			<div class="gp-setup-content rowx mw-100 text-center mb-3">
249 249
 				<div class="col-12 col-md-5 m-auto">
250 250
 					<?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?>
251 251
 				</div>
252 252
 			</div>
253 253
 		<?php
254
-	}
255
-
256
-	/**
257
-	 * Setup Wizard Footer.
258
-	 *
259
-	 * @since 2.4.0
260
-	 */
261
-	public function display_footer() {
262
-
263
-		if ( isset( $_GET['step'] ) ) {
264
-			$label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
265
-
266
-			echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>';
267
-		}
268
-
269
-		echo '</body></html>';
270
-	}
271
-
272
-	/**
273
-	 * Introduction step.
274
-	 *
275
-	 * @since 2.0.0
276
-	 */
277
-	public function setup_introduction() {
278
-		$next_url = $this->get_next_step_link();
279
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
280
-	}
281
-
282
-	/**
283
-	 * Get the URL for the next step's screen.
284
-	 *
285
-	 * @param string step   slug (default: current step)
286
-	 *
287
-	 * @return string       URL for next step if a next step exists.
288
-	 *                      Admin URL if it's the last step.
289
-	 *                      Empty string on failure.
290
-	 * @since 3.0.0
291
-	 */
292
-	public function get_next_step_link( $step = '' ) {
293
-		if ( ! $step ) {
294
-			$step = $this->step;
295
-		}
296
-
297
-		$keys = array_keys( $this->steps );
298
-		if ( end( $keys ) === $step ) {
299
-			return admin_url();
300
-		}
301
-
302
-		$step_index = array_search( $step, $keys );
303
-		if ( false === $step_index ) {
304
-			return '';
305
-		}
306
-
307
-		return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) );
308
-	}
309
-
310
-	/**
311
-	 * Setup maps api.
312
-	 *
313
-	 * @since 2.0.0
314
-	 */
315
-	public function setup_business() {
316
-		$next_url = $this->get_next_step_link();
317
-		$wizard   = $this;
318
-		$page     = 'wpinv_settings_general_main';
319
-		$section  = 'wpinv_settings_general_main';
320
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
321
-	}
322
-
323
-	/**
324
-	 * Default Location settings.
325
-	 *
326
-	 * @since 2.0.0
327
-	 */
328
-	public function setup_currency() {
329
-		$next_url = $this->get_next_step_link();
330
-		$wizard   = $this;
331
-		$page     = 'wpinv_settings_general_currency_section';
332
-		$section  = 'wpinv_settings_general_currency_section';
333
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
334
-	}
335
-
336
-	/**
337
-	 * Installation of recommended plugins.
338
-	 *
339
-	 * @since 1.0.0
340
-	 */
341
-	public function setup_recommend() {
342
-		$next_url            = $this->get_next_step_link();
343
-		$recommended_plugins = self::get_recommend_wp_plugins();
344
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
345
-	}
346
-
347
-	/**
348
-	 * A list of recommended wp.org plugins.
349
-	 * @return array
350
-	 */
351
-	public static function get_recommend_wp_plugins() {
352
-		return array(
353
-			'ayecode-connect'  => array(
354
-				'file' => 'ayecode-connect/ayecode-connect.php',
355
-				'url'  => 'https://wordpress.org/plugins/ayecode-connect/',
356
-				'slug' => 'ayecode-connect',
357
-				'name' => 'AyeCode Connect',
358
-				'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ),
359
-			),
360
-			'invoicing-quotes' => array(
361
-				'file' => 'invoicing-quotes/wpinv-quote.php',
362
-				'url'  => 'https://wordpress.org/plugins/invoicing-quotes/',
363
-				'slug' => 'invoicing-quotes',
364
-				'name' => 'Customer Quotes',
365
-				'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ),
366
-			),
367
-			'userswp'          => array(
368
-				'file' => 'userswp/userswp.php',
369
-				'url'  => 'https://wordpress.org/plugins/userswp/',
370
-				'slug' => 'userswp',
371
-				'name' => 'UsersWP',
372
-				'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ),
373
-			),
374
-		);
375
-	}
376
-
377
-	/**
378
-	 * Dummy Data setup.
379
-	 *
380
-	 * @since 2.4.0
381
-	 */
382
-	public function setup_payments() {
383
-		$next_url = $this->get_next_step_link();
384
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
385
-	}
386
-
387
-	/**
388
-	 * Dummy data save.
389
-	 *
390
-	 * This is done via ajax so we just pass onto the next step.
391
-	 *
392
-	 * @since 2.0.0
393
-	 */
394
-	public function setup_payments_save() {
395
-		check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' );
396
-		wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) );
397
-
398
-		if ( ! empty( $_POST['paypal-email'] ) ) {
399
-			wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) );
400
-			wpinv_update_option( 'paypal_active', 1 );
401
-			wpinv_update_option( 'paypal_sandbox', 0 );
402
-		}
403
-
404
-		wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
405
-		exit;
406
-	}
407
-
408
-	/**
409
-	 * Final step.
410
-	 *
411
-	 * @since 2.0.0
412
-	 */
413
-	public function setup_ready() {
414
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
415
-	}
254
+    }
255
+
256
+    /**
257
+     * Setup Wizard Footer.
258
+     *
259
+     * @since 2.4.0
260
+     */
261
+    public function display_footer() {
262
+
263
+        if ( isset( $_GET['step'] ) ) {
264
+            $label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
265
+
266
+            echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>';
267
+        }
268
+
269
+        echo '</body></html>';
270
+    }
271
+
272
+    /**
273
+     * Introduction step.
274
+     *
275
+     * @since 2.0.0
276
+     */
277
+    public function setup_introduction() {
278
+        $next_url = $this->get_next_step_link();
279
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
280
+    }
281
+
282
+    /**
283
+     * Get the URL for the next step's screen.
284
+     *
285
+     * @param string step   slug (default: current step)
286
+     *
287
+     * @return string       URL for next step if a next step exists.
288
+     *                      Admin URL if it's the last step.
289
+     *                      Empty string on failure.
290
+     * @since 3.0.0
291
+     */
292
+    public function get_next_step_link( $step = '' ) {
293
+        if ( ! $step ) {
294
+            $step = $this->step;
295
+        }
296
+
297
+        $keys = array_keys( $this->steps );
298
+        if ( end( $keys ) === $step ) {
299
+            return admin_url();
300
+        }
301
+
302
+        $step_index = array_search( $step, $keys );
303
+        if ( false === $step_index ) {
304
+            return '';
305
+        }
306
+
307
+        return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) );
308
+    }
309
+
310
+    /**
311
+     * Setup maps api.
312
+     *
313
+     * @since 2.0.0
314
+     */
315
+    public function setup_business() {
316
+        $next_url = $this->get_next_step_link();
317
+        $wizard   = $this;
318
+        $page     = 'wpinv_settings_general_main';
319
+        $section  = 'wpinv_settings_general_main';
320
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
321
+    }
322
+
323
+    /**
324
+     * Default Location settings.
325
+     *
326
+     * @since 2.0.0
327
+     */
328
+    public function setup_currency() {
329
+        $next_url = $this->get_next_step_link();
330
+        $wizard   = $this;
331
+        $page     = 'wpinv_settings_general_currency_section';
332
+        $section  = 'wpinv_settings_general_currency_section';
333
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
334
+    }
335
+
336
+    /**
337
+     * Installation of recommended plugins.
338
+     *
339
+     * @since 1.0.0
340
+     */
341
+    public function setup_recommend() {
342
+        $next_url            = $this->get_next_step_link();
343
+        $recommended_plugins = self::get_recommend_wp_plugins();
344
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
345
+    }
346
+
347
+    /**
348
+     * A list of recommended wp.org plugins.
349
+     * @return array
350
+     */
351
+    public static function get_recommend_wp_plugins() {
352
+        return array(
353
+            'ayecode-connect'  => array(
354
+                'file' => 'ayecode-connect/ayecode-connect.php',
355
+                'url'  => 'https://wordpress.org/plugins/ayecode-connect/',
356
+                'slug' => 'ayecode-connect',
357
+                'name' => 'AyeCode Connect',
358
+                'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ),
359
+            ),
360
+            'invoicing-quotes' => array(
361
+                'file' => 'invoicing-quotes/wpinv-quote.php',
362
+                'url'  => 'https://wordpress.org/plugins/invoicing-quotes/',
363
+                'slug' => 'invoicing-quotes',
364
+                'name' => 'Customer Quotes',
365
+                'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ),
366
+            ),
367
+            'userswp'          => array(
368
+                'file' => 'userswp/userswp.php',
369
+                'url'  => 'https://wordpress.org/plugins/userswp/',
370
+                'slug' => 'userswp',
371
+                'name' => 'UsersWP',
372
+                'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ),
373
+            ),
374
+        );
375
+    }
376
+
377
+    /**
378
+     * Dummy Data setup.
379
+     *
380
+     * @since 2.4.0
381
+     */
382
+    public function setup_payments() {
383
+        $next_url = $this->get_next_step_link();
384
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
385
+    }
386
+
387
+    /**
388
+     * Dummy data save.
389
+     *
390
+     * This is done via ajax so we just pass onto the next step.
391
+     *
392
+     * @since 2.0.0
393
+     */
394
+    public function setup_payments_save() {
395
+        check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' );
396
+        wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) );
397
+
398
+        if ( ! empty( $_POST['paypal-email'] ) ) {
399
+            wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) );
400
+            wpinv_update_option( 'paypal_active', 1 );
401
+            wpinv_update_option( 'paypal_sandbox', 0 );
402
+        }
403
+
404
+        wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
405
+        exit;
406
+    }
407
+
408
+    /**
409
+     * Final step.
410
+     *
411
+     * @since 2.0.0
412
+     */
413
+    public function setup_ready() {
414
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
415
+    }
416 416
 
417 417
 }
418 418
 
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @version     2.4.0
11 11
  * @info        GetPaid Setup Wizard.
12 12
  */
13
-defined( 'ABSPATH' ) || exit;
13
+defined('ABSPATH') || exit;
14 14
 
15 15
 /**
16 16
  * GetPaid_Admin_Setup_Wizard class.
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	public function __construct() {
46 46
 
47
-		if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) {
48
-			add_action( 'admin_menu', array( $this, 'add_menu' ) );
49
-			add_action( 'current_screen', array( $this, 'setup_wizard' ) );
50
-			add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) );
47
+		if (apply_filters('getpaid_enable_setup_wizard', true) && wpinv_current_user_can_manage_invoicing()) {
48
+			add_action('admin_menu', array($this, 'add_menu'));
49
+			add_action('current_screen', array($this, 'setup_wizard'));
50
+			add_action('admin_init', array($this, 'remove_deprecated_functions'));
51 51
 		}
52 52
 
53 53
 	}
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 * @since 2.4.0
59 59
 	 */
60 60
 	public function add_menu() {
61
-		add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
61
+		add_dashboard_page('', '', wpinv_get_capability(), 'gp-setup', '');
62 62
 	}
63 63
 
64 64
 	/**
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 */
69 69
 	public function setup_wizard() {
70 70
 
71
-		if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
71
+		if (isset($_GET['page']) && 'gp-setup' === $_GET['page']) {
72 72
 			$this->setup_globals();
73 73
 			$this->maybe_save_current_step();
74 74
 			$this->display_wizard();
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	public function remove_deprecated_functions() {
81 81
 		// removes deprecated warnings from page
82 82
 		remove_action('admin_print_styles', 'print_emoji_styles');
83
-		remove_action( 'admin_head', 'wp_admin_bar_header' );
83
+		remove_action('admin_head', 'wp_admin_bar_header');
84 84
 	}
85 85
 
86 86
 	/**
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 * @since 2.4.0
102 102
 	 */
103 103
 	protected function maybe_save_current_step() {
104
-		if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) {
105
-			call_user_func( $this->steps[ $this->step ]['handler'], $this );
104
+		if (!empty($_POST['save_step']) && is_callable($this->steps[$this->step]['handler'])) {
105
+			call_user_func($this->steps[$this->step]['handler'], $this);
106 106
 		}
107 107
 	}
108 108
 
@@ -117,44 +117,44 @@  discard block
 block discarded – undo
117 117
 		$steps = array(
118 118
 
119 119
 			'introduction'     => array(
120
-				'name'    => __( 'Introduction', 'invoicing' ),
121
-				'view'    => array( $this, 'setup_introduction' ),
120
+				'name'    => __('Introduction', 'invoicing'),
121
+				'view'    => array($this, 'setup_introduction'),
122 122
 				'handler' => '',
123 123
 			),
124 124
 
125 125
 			'business_details' => array(
126
-				'name'    => __( 'Business Details', 'invoicing' ),
127
-				'view'    => array( $this, 'setup_business' ),
126
+				'name'    => __('Business Details', 'invoicing'),
127
+				'view'    => array($this, 'setup_business'),
128 128
 				'handler' => '',
129 129
 			),
130 130
 
131 131
 			'currency'         => array(
132
-				'name'    => __( 'Currency', 'invoicing' ),
133
-				'view'    => array( $this, 'setup_currency' ),
132
+				'name'    => __('Currency', 'invoicing'),
133
+				'view'    => array($this, 'setup_currency'),
134 134
 				'handler' => '',
135 135
 			),
136 136
 
137 137
 			'payments'         => array(
138
-				'name'    => __( 'Payment Gateways', 'invoicing' ),
139
-				'view'    => array( $this, 'setup_payments' ),
140
-				'handler' => array( $this, 'setup_payments_save' ),
138
+				'name'    => __('Payment Gateways', 'invoicing'),
139
+				'view'    => array($this, 'setup_payments'),
140
+				'handler' => array($this, 'setup_payments_save'),
141 141
 			),
142 142
 
143 143
 			'recommend'        => array(
144
-				'name'    => __( 'Recommend', 'invoicing' ),
145
-				'view'    => array( $this, 'setup_recommend' ),
144
+				'name'    => __('Recommend', 'invoicing'),
145
+				'view'    => array($this, 'setup_recommend'),
146 146
 				'handler' => '',
147 147
 			),
148 148
 
149 149
 			'next_steps'       => array(
150
-				'name'    => __( 'Get Paid', 'invoicing' ),
151
-				'view'    => array( $this, 'setup_ready' ),
150
+				'name'    => __('Get Paid', 'invoicing'),
151
+				'view'    => array($this, 'setup_ready'),
152 152
 				'handler' => '',
153 153
 			),
154 154
 
155 155
 		);
156 156
 
157
-		return apply_filters( 'getpaid_setup_wizard_steps', $steps );
157
+		return apply_filters('getpaid_setup_wizard_steps', $steps);
158 158
 
159 159
 	}
160 160
 
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
 	 * @return string
166 166
 	 */
167 167
 	protected function get_current_step() {
168
-		$step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : '';
169
-		return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) );
168
+		$step = isset($_GET['step']) ? sanitize_key($_GET['step']) : '';
169
+		return !empty($step) && in_array($step, array_keys($this->steps)) ? $step : current(array_keys($this->steps));
170 170
 	}
171 171
 
172 172
 	/**
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
 
180 180
 		$previous = false;
181 181
 		$current  = $this->step;
182
-		foreach ( array_keys( $this->steps ) as $step ) {
183
-			if ( $current === $step ) {
182
+		foreach (array_keys($this->steps) as $step) {
183
+			if ($current === $step) {
184 184
 				return $previous;
185 185
 			}
186 186
 
@@ -200,13 +200,13 @@  discard block
 block discarded – undo
200 200
 
201 201
 		$on_current = false;
202 202
 		$current    = $this->step;
203
-		foreach ( array_keys( $this->steps ) as $step ) {
203
+		foreach (array_keys($this->steps) as $step) {
204 204
 
205
-			if ( $on_current ) {
205
+			if ($on_current) {
206 206
 				return $step;
207 207
 			}
208 208
 
209
-			if ( $current === $step ) {
209
+			if ($current === $step) {
210 210
 				return $on_current = true;
211 211
 			}
212 212
 }
@@ -234,8 +234,8 @@  discard block
 block discarded – undo
234 234
 		$steps     = $this->steps;
235 235
 		$current   = $this->step;
236 236
 		$next_step = $this->next_step;
237
-		array_shift( $steps );
238
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
237
+		array_shift($steps);
238
+		include plugin_dir_path(__FILE__) . 'views/wizard-header.php';
239 239
 	}
240 240
 
241 241
 	/**
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 		?>
248 248
 			<div class="gp-setup-content rowx mw-100 text-center mb-3">
249 249
 				<div class="col-12 col-md-5 m-auto">
250
-					<?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?>
250
+					<?php call_user_func($this->steps[$this->step]['view'], $this); ?>
251 251
 				</div>
252 252
 			</div>
253 253
 		<?php
@@ -260,10 +260,10 @@  discard block
 block discarded – undo
260 260
 	 */
261 261
 	public function display_footer() {
262 262
 
263
-		if ( isset( $_GET['step'] ) ) {
264
-			$label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
263
+		if (isset($_GET['step'])) {
264
+			$label = $this->step == 'next_steps' ? __('Return to the WordPress Dashboard', 'invoicing') : __('Skip this step', 'invoicing');
265 265
 
266
-			echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url( $this->get_next_step_link() ) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html( $label ) . '</a></p>';
266
+			echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . esc_url($this->get_next_step_link()) . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . esc_html($label) . '</a></p>';
267 267
 		}
268 268
 
269 269
 		echo '</body></html>';
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	 */
277 277
 	public function setup_introduction() {
278 278
 		$next_url = $this->get_next_step_link();
279
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
279
+		include plugin_dir_path(__FILE__) . 'views/wizard-introduction.php';
280 280
 	}
281 281
 
282 282
 	/**
@@ -289,22 +289,22 @@  discard block
 block discarded – undo
289 289
 	 *                      Empty string on failure.
290 290
 	 * @since 3.0.0
291 291
 	 */
292
-	public function get_next_step_link( $step = '' ) {
293
-		if ( ! $step ) {
292
+	public function get_next_step_link($step = '') {
293
+		if (!$step) {
294 294
 			$step = $this->step;
295 295
 		}
296 296
 
297
-		$keys = array_keys( $this->steps );
298
-		if ( end( $keys ) === $step ) {
297
+		$keys = array_keys($this->steps);
298
+		if (end($keys) === $step) {
299 299
 			return admin_url();
300 300
 		}
301 301
 
302
-		$step_index = array_search( $step, $keys );
303
-		if ( false === $step_index ) {
302
+		$step_index = array_search($step, $keys);
303
+		if (false === $step_index) {
304 304
 			return '';
305 305
 		}
306 306
 
307
-		return remove_query_arg( 'settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ) );
307
+		return remove_query_arg('settings-updated', add_query_arg('step', $keys[$step_index + 1]));
308 308
 	}
309 309
 
310 310
 	/**
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 		$wizard   = $this;
318 318
 		$page     = 'wpinv_settings_general_main';
319 319
 		$section  = 'wpinv_settings_general_main';
320
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
320
+		include plugin_dir_path(__FILE__) . 'views/wizard-settings.php';
321 321
 	}
322 322
 
323 323
 	/**
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 		$wizard   = $this;
331 331
 		$page     = 'wpinv_settings_general_currency_section';
332 332
 		$section  = 'wpinv_settings_general_currency_section';
333
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
333
+		include plugin_dir_path(__FILE__) . 'views/wizard-settings.php';
334 334
 	}
335 335
 
336 336
 	/**
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 	public function setup_recommend() {
342 342
 		$next_url            = $this->get_next_step_link();
343 343
 		$recommended_plugins = self::get_recommend_wp_plugins();
344
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
344
+		include plugin_dir_path(__FILE__) . 'views/wizard-plugins.php';
345 345
 	}
346 346
 
347 347
 	/**
@@ -355,21 +355,21 @@  discard block
 block discarded – undo
355 355
 				'url'  => 'https://wordpress.org/plugins/ayecode-connect/',
356 356
 				'slug' => 'ayecode-connect',
357 357
 				'name' => 'AyeCode Connect',
358
-				'desc' => __( 'Documentation and Support from within your WordPress admin.', 'invoicing' ),
358
+				'desc' => __('Documentation and Support from within your WordPress admin.', 'invoicing'),
359 359
 			),
360 360
 			'invoicing-quotes' => array(
361 361
 				'file' => 'invoicing-quotes/wpinv-quote.php',
362 362
 				'url'  => 'https://wordpress.org/plugins/invoicing-quotes/',
363 363
 				'slug' => 'invoicing-quotes',
364 364
 				'name' => 'Customer Quotes',
365
-				'desc' => __( 'Create & Send Quotes to Customers and have them accept and pay.', 'invoicing' ),
365
+				'desc' => __('Create & Send Quotes to Customers and have them accept and pay.', 'invoicing'),
366 366
 			),
367 367
 			'userswp'          => array(
368 368
 				'file' => 'userswp/userswp.php',
369 369
 				'url'  => 'https://wordpress.org/plugins/userswp/',
370 370
 				'slug' => 'userswp',
371 371
 				'name' => 'UsersWP',
372
-				'desc' => __( 'Frontend user login and registration as well as slick profile pages.', 'invoicing' ),
372
+				'desc' => __('Frontend user login and registration as well as slick profile pages.', 'invoicing'),
373 373
 			),
374 374
 		);
375 375
 	}
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 	 */
382 382
 	public function setup_payments() {
383 383
 		$next_url = $this->get_next_step_link();
384
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
384
+		include plugin_dir_path(__FILE__) . 'views/wizard-gateways.php';
385 385
 	}
386 386
 
387 387
 	/**
@@ -392,16 +392,16 @@  discard block
 block discarded – undo
392 392
 	 * @since 2.0.0
393 393
 	 */
394 394
 	public function setup_payments_save() {
395
-		check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' );
396
-		wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) );
395
+		check_admin_referer('getpaid-setup-wizard', 'getpaid-setup-wizard');
396
+		wpinv_update_option('manual_active', !empty($_POST['enable-manual-gateway']));
397 397
 
398
-		if ( ! empty( $_POST['paypal-email'] ) ) {
399
-			wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) );
400
-			wpinv_update_option( 'paypal_active', 1 );
401
-			wpinv_update_option( 'paypal_sandbox', 0 );
398
+		if (!empty($_POST['paypal-email'])) {
399
+			wpinv_update_option('paypal_email', sanitize_email($_POST['paypal-email']));
400
+			wpinv_update_option('paypal_active', 1);
401
+			wpinv_update_option('paypal_sandbox', 0);
402 402
 		}
403 403
 
404
-		wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
404
+		wp_redirect(esc_url_raw($this->get_next_step_link()));
405 405
 		exit;
406 406
 	}
407 407
 
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 	 * @since 2.0.0
412 412
 	 */
413 413
 	public function setup_ready() {
414
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
414
+		include plugin_dir_path(__FILE__) . 'views/wizard-thank-you.php';
415 415
 	}
416 416
 
417 417
 }
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 2 patches
Indentation   +475 added lines, -475 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 }
9 9
 
10 10
 if ( ! class_exists( 'WP_List_Table' ) ) {
11
-	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
11
+    include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
12 12
 }
13 13
 
14 14
 /**
@@ -16,479 +16,479 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class WPInv_Subscriptions_List_Table extends WP_List_Table {
18 18
 
19
-	/**
20
-	 * URL of this page
21
-	 *
22
-	 * @var   string
23
-	 * @since 1.0.19
24
-	 */
25
-	public $base_url;
26
-
27
-	/**
28
-	 * Query
29
-	 *
30
-	 * @var   GetPaid_Subscriptions_Query
31
-	 * @since 1.0.19
32
-	 */
33
-	public $query;
34
-
35
-	/**
36
-	 * Total subscriptions
37
-	 *
38
-	 * @var   string
39
-	 * @since 1.0.0
40
-	 */
41
-	public $total_count;
42
-
43
-	/**
44
-	 * Current status subscriptions
45
-	 *
46
-	 * @var   string
47
-	 * @since 1.0.0
48
-	 */
49
-	public $current_total_count;
50
-
51
-	/**
52
-	 * Status counts
53
-	 *
54
-	 * @var   array
55
-	 * @since 1.0.19
56
-	 */
57
-	public $status_counts;
58
-
59
-	/**
60
-	 * Number of results to show per page
61
-	 *
62
-	 * @var   int
63
-	 * @since 1.0.0
64
-	 */
65
-	public $per_page = 10;
66
-
67
-	/**
68
-	 *  Constructor function.
69
-	 */
70
-	public function __construct() {
71
-
72
-		parent::__construct(
73
-			array(
74
-				'singular' => 'subscription',
75
-				'plural'   => 'subscriptions',
76
-			)
77
-		);
78
-
79
-		$this->process_bulk_action();
80
-
81
-		$this->prepare_query();
82
-
83
-		$this->base_url = remove_query_arg( 'status' );
84
-
85
-	}
86
-
87
-	/**
88
-	 *  Prepares the display query
89
-	 */
90
-	public function prepare_query() {
91
-
92
-		// Prepare query args.
93
-		$query = array(
94
-			'number'      => $this->per_page,
95
-			'paged'       => $this->get_paged(),
96
-			'status'      => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all',
97
-			'orderby'     => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id',
98
-			'order'       => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC',
99
-			'customer_in' => $this->get_user_in(),
100
-		);
101
-
102
-		if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) {
103
-			$this->total_count         = 0;
104
-			$this->current_total_count = 0;
105
-			$this->items               = array();
106
-			$this->status_counts       = array();
107
-			return;
108
-		}
109
-
110
-		// Prepare class properties.
111
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
112
-		$this->total_count         = $this->query->get_total();
113
-		$this->current_total_count = $this->query->get_total();
114
-		$this->items               = $this->query->get_results();
115
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
116
-
117
-		if ( 'all' != $query['status'] ) {
118
-			unset( $query['status'] );
119
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
120
-		}
121
-
122
-	}
123
-
124
-	/**
125
-	 * Get user in.
126
-	 *
127
-	 */
128
-	public function get_user_in() {
129
-
130
-		// Abort if no user.
131
-		if ( empty( $_GET['s'] ) ) {
132
-			return null;
133
-		}
134
-
135
-		// Or invalid user.
136
-		$user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) );
137
-
138
-		if ( empty( $user ) ) {
139
-			return null;
140
-		}
141
-
142
-		// Search matching users.
143
-		$user  = '*' . $user . '*';
144
-		$users = new WP_User_Query(
145
-			array(
146
-				'fields'      => 'ID',
147
-				'search'      => $user,
148
-				'count_total' => false,
149
-			)
150
-		);
151
-
152
-		return $users->get_results();
153
-	}
154
-
155
-	/**
156
-	 * Gets the list of views available on this table.
157
-	 *
158
-	 * The format is an associative array:
159
-	 * - `'id' => 'link'`
160
-	 *
161
-	 * @since 1.0.0
162
-	 *
163
-	 * @return array
164
-	 */
165
-	public function get_views() {
166
-
167
-		$current  = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all';
168
-		$views    = array(
169
-
170
-			'all' => sprintf(
171
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
172
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
173
-				$current === 'all' ? ' class="current"' : '',
174
-				__( 'All', 'invoicing' ),
175
-				$this->total_count
176
-			),
177
-
178
-		);
179
-
180
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
181
-
182
-			$views[ $status ] = sprintf(
183
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
184
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
185
-				$current === $status ? ' class="current"' : '',
186
-				esc_html( getpaid_get_subscription_status_label( $status ) ),
187
-				$count
188
-			);
189
-
190
-		}
191
-
192
-		return $views;
193
-
194
-	}
195
-
196
-	/**
197
-	 * Render most columns
198
-	 *
199
-	 * @access      private
200
-	 * @since       1.0.0
201
-	 * @return      string
202
-	 */
203
-	public function column_default( $item, $column_name ) {
204
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
205
-	}
206
-
207
-	/**
208
-	 * This is how checkbox column renders.
209
-	 *
210
-	 * @param WPInv_Subscription $item
211
-	 * @return string
212
-	 */
213
-	public function column_cb( $item ) {
214
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
215
-	}
216
-
217
-	/**
218
-	 * Status column
219
-	 *
220
-	 * @param WPInv_Subscription $item
221
-	 * @since       1.0.0
222
-	 * @return      string
223
-	 */
224
-	public function column_status( $item ) {
225
-		$extra = $item->has_status( 'expired' ) ? '<small class="text-muted d-block">' . wp_sprintf( _x( 'On: %s', 'Expired On:', 'invoicing' ), getpaid_format_date_value( $item->get_expiration() ) ) . '</small>' : '';
226
-
227
-		return $item->get_status_label_html() . $extra;
228
-	}
229
-
230
-	/**
231
-	 * Subscription column
232
-	 *
233
-	 * @param WPInv_Subscription $item
234
-	 * @since       1.0.0
235
-	 * @return      string
236
-	 */
237
-	public function column_subscription( $item ) {
238
-
239
-		$username = __( '(Missing User)', 'invoicing' );
240
-
241
-		$user = get_userdata( $item->get_customer_id() );
242
-		$capabilities = wpinv_current_user_can_manage_invoicing();
243
-
244
-		if ( $user ) {
245
-			$username = sprintf(
246
-				'<a href="user-edit.php?user_id=%s">%s</a>',
247
-				absint( $user->ID ),
248
-				! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email )
249
-			);
250
-		}
251
-
252
-		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
253
-		$column_content = sprintf(
254
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
255
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
256
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>',
257
-			'</a>',
258
-			$username
259
-		);
260
-
261
-		$row_actions = array();
262
-
263
-		// View subscription.
264
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) );
265
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
266
-
267
-		// View invoice.
268
-		$invoice = get_post( $item->get_parent_invoice_id() );
269
-
270
-		if ( ! empty( $invoice ) ) {
271
-			$invoice_url            = get_edit_post_link( $invoice );
272
-			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
273
-		}
274
-
275
-		$delete_url            = esc_url(
276
-			wp_nonce_url(
277
-				add_query_arg(
278
-					array(
279
-						'getpaid-admin-action' => 'subscription_manual_delete',
280
-						'id'                   => $item->get_id(),
281
-					)
282
-				),
283
-				'getpaid-nonce',
284
-				'getpaid-nonce'
285
-			)
286
-		);
287
-		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
288
-
289
-		if ( ! $capabilities ) {
290
-			$row_actions = array();
291
-		}
292
-
293
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
294
-
295
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
296
-	}
297
-
298
-	/**
299
-	 * Renewal date column
300
-	 *
301
-	 * @param WPInv_Subscription $item
302
-	 * @since       1.0.0
303
-	 * @return      string
304
-	 */
305
-	public function column_renewal_date( $item ) {
306
-		if ( $item->has_status( 'active trialling' ) ) {
307
-			$value = getpaid_format_date_value( $item->get_expiration() );
308
-		} else {
309
-			$value = '-';
310
-		}
311
-
312
-		return $value;
313
-	}
314
-
315
-	/**
316
-	 * Start date column
317
-	 *
318
-	 * @param WPInv_Subscription $item
319
-	 * @since       1.0.0
320
-	 * @return      string
321
-	 */
322
-	public function column_start_date( $item ) {
323
-
324
-		$gateway = $item->get_parent_invoice()->get_gateway_title();
325
-
326
-		if ( empty( $gateway ) ) {
327
-			return getpaid_format_date_value( $item->get_date_created() );
328
-		}
329
-
330
-		$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item );
331
-		if ( ! empty( $url ) ) {
332
-
333
-			return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf(
334
-				__( 'Via %s', 'invoicing' ),
335
-				'<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>'
336
-			);
337
-
338
-		}
339
-
340
-		return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf(
341
-			__( 'Via %s', 'invoicing' ),
342
-			'<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>'
343
-		);
344
-
345
-	}
346
-
347
-	/**
348
-	 * Amount column
349
-	 *
350
-	 * @param WPInv_Subscription $item
351
-	 * @since       1.0.19
352
-	 * @return      string
353
-	 */
354
-	public static function column_amount( $item ) {
355
-		$amount = getpaid_get_formatted_subscription_amount( $item );
356
-		return "<span class='text-muted form-text mt-2 mb-2 ms-1 ml-1'>$amount</span>";
357
-	}
358
-
359
-	/**
360
-	 * Billing Times column
361
-	 *
362
-	 * @param WPInv_Subscription $item
363
-	 * @since       1.0.0
364
-	 * @return      string
365
-	 */
366
-	public function column_renewals( $item ) {
367
-		$max_bills = $item->get_bill_times();
368
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '&infin;' : $max_bills );
369
-	}
370
-
371
-	/**
372
-	 * Product ID column
373
-	 *
374
-	 * @param WPInv_Subscription $item
375
-	 * @since       1.0.0
376
-	 * @return      string
377
-	 */
378
-	public function column_item( $item ) {
379
-		$subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() );
380
-
381
-		if ( empty( $subscription_group ) ) {
382
-			return $this->generate_item_markup( $item->get_product_id() );
383
-		}
384
-
385
-		$markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
386
-		return implode( ' | ', $markup );
387
-
388
-	}
389
-
390
-	/**
391
-	 * Generates the items markup.
392
-	 *
393
-	 * @param int $item_id
394
-	 * @since       1.0.0
395
-	 * @return      string
396
-	 */
397
-	public static function generate_item_markup( $item_id ) {
398
-		$item = get_post( $item_id );
399
-
400
-		if ( ! empty( $item ) ) {
401
-			$link = get_edit_post_link( $item );
402
-			$name = esc_html( get_the_title( $item ) );
403
-			return wpinv_current_user_can_manage_invoicing() ? "<a href='" . ( $link ? esc_url( $link ) : '#' ) . "'>$name</a>" : $name;
404
-		} else {
405
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item_id );
406
-		}
407
-
408
-	}
409
-
410
-	/**
411
-	 * Retrieve the current page number
412
-	 *
413
-	 * @return      int
414
-	 */
415
-	public function get_paged() {
416
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
417
-	}
418
-
419
-	/**
420
-	 * Setup the final data for the table
421
-	 *
422
-	 */
423
-	public function prepare_items() {
424
-
425
-		$columns  = $this->get_columns();
426
-		$hidden   = array();
427
-		$sortable = $this->get_sortable_columns();
428
-
429
-		$this->_column_headers = array( $columns, $hidden, $sortable );
430
-
431
-		$this->set_pagination_args(
432
-			array(
433
-				'total_items' => $this->current_total_count,
434
-				'per_page'    => $this->per_page,
435
-				'total_pages' => ceil( $this->current_total_count / $this->per_page ),
436
-			)
437
-		);
438
-	}
439
-
440
-	/**
441
-	 * Table columns
442
-	 *
443
-	 * @return array
444
-	 */
445
-	public function get_columns() {
446
-		$columns = array(
447
-			'cb'           => '<input type="checkbox" />',
448
-			'subscription' => __( 'Subscription', 'invoicing' ),
449
-			'start_date'   => __( 'Start Date', 'invoicing' ),
450
-			'renewal_date' => __( 'Next Payment', 'invoicing' ),
451
-			'renewals'     => __( 'Payments', 'invoicing' ),
452
-			'item'         => __( 'Items', 'invoicing' ),
453
-			'status'       => __( 'Status', 'invoicing' ),
454
-		);
455
-
456
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
457
-	}
458
-
459
-	/**
460
-	 * Sortable table columns.
461
-	 *
462
-	 * @return array
463
-	 */
464
-	public function get_sortable_columns() {
465
-		$sortable = array(
466
-			'subscription' => array( 'id', true ),
467
-			'start_date'   => array( 'created', true ),
468
-			'renewal_date' => array( 'expiration', true ),
469
-			'renewals'     => array( 'bill_times', true ),
470
-			'item'         => array( 'product_id', true ),
471
-			'status'       => array( 'status', true ),
472
-		);
473
-
474
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
475
-	}
476
-
477
-	/**
478
-	 * Whether the table has items to display or not
479
-	 *
480
-	 * @return bool
481
-	 */
482
-	public function has_items() {
483
-		return ! empty( $this->current_total_count );
484
-	}
485
-
486
-	/**
487
-	 * Processes bulk actions.
488
-	 *
489
-	 */
490
-	public function process_bulk_action() {
491
-
492
-	}
19
+    /**
20
+     * URL of this page
21
+     *
22
+     * @var   string
23
+     * @since 1.0.19
24
+     */
25
+    public $base_url;
26
+
27
+    /**
28
+     * Query
29
+     *
30
+     * @var   GetPaid_Subscriptions_Query
31
+     * @since 1.0.19
32
+     */
33
+    public $query;
34
+
35
+    /**
36
+     * Total subscriptions
37
+     *
38
+     * @var   string
39
+     * @since 1.0.0
40
+     */
41
+    public $total_count;
42
+
43
+    /**
44
+     * Current status subscriptions
45
+     *
46
+     * @var   string
47
+     * @since 1.0.0
48
+     */
49
+    public $current_total_count;
50
+
51
+    /**
52
+     * Status counts
53
+     *
54
+     * @var   array
55
+     * @since 1.0.19
56
+     */
57
+    public $status_counts;
58
+
59
+    /**
60
+     * Number of results to show per page
61
+     *
62
+     * @var   int
63
+     * @since 1.0.0
64
+     */
65
+    public $per_page = 10;
66
+
67
+    /**
68
+     *  Constructor function.
69
+     */
70
+    public function __construct() {
71
+
72
+        parent::__construct(
73
+            array(
74
+                'singular' => 'subscription',
75
+                'plural'   => 'subscriptions',
76
+            )
77
+        );
78
+
79
+        $this->process_bulk_action();
80
+
81
+        $this->prepare_query();
82
+
83
+        $this->base_url = remove_query_arg( 'status' );
84
+
85
+    }
86
+
87
+    /**
88
+     *  Prepares the display query
89
+     */
90
+    public function prepare_query() {
91
+
92
+        // Prepare query args.
93
+        $query = array(
94
+            'number'      => $this->per_page,
95
+            'paged'       => $this->get_paged(),
96
+            'status'      => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all',
97
+            'orderby'     => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id',
98
+            'order'       => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC',
99
+            'customer_in' => $this->get_user_in(),
100
+        );
101
+
102
+        if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) {
103
+            $this->total_count         = 0;
104
+            $this->current_total_count = 0;
105
+            $this->items               = array();
106
+            $this->status_counts       = array();
107
+            return;
108
+        }
109
+
110
+        // Prepare class properties.
111
+        $this->query               = new GetPaid_Subscriptions_Query( $query );
112
+        $this->total_count         = $this->query->get_total();
113
+        $this->current_total_count = $this->query->get_total();
114
+        $this->items               = $this->query->get_results();
115
+        $this->status_counts       = getpaid_get_subscription_status_counts( $query );
116
+
117
+        if ( 'all' != $query['status'] ) {
118
+            unset( $query['status'] );
119
+            $this->total_count   = getpaid_get_subscriptions( $query, 'count' );
120
+        }
121
+
122
+    }
123
+
124
+    /**
125
+     * Get user in.
126
+     *
127
+     */
128
+    public function get_user_in() {
129
+
130
+        // Abort if no user.
131
+        if ( empty( $_GET['s'] ) ) {
132
+            return null;
133
+        }
134
+
135
+        // Or invalid user.
136
+        $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) );
137
+
138
+        if ( empty( $user ) ) {
139
+            return null;
140
+        }
141
+
142
+        // Search matching users.
143
+        $user  = '*' . $user . '*';
144
+        $users = new WP_User_Query(
145
+            array(
146
+                'fields'      => 'ID',
147
+                'search'      => $user,
148
+                'count_total' => false,
149
+            )
150
+        );
151
+
152
+        return $users->get_results();
153
+    }
154
+
155
+    /**
156
+     * Gets the list of views available on this table.
157
+     *
158
+     * The format is an associative array:
159
+     * - `'id' => 'link'`
160
+     *
161
+     * @since 1.0.0
162
+     *
163
+     * @return array
164
+     */
165
+    public function get_views() {
166
+
167
+        $current  = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all';
168
+        $views    = array(
169
+
170
+            'all' => sprintf(
171
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
172
+                esc_url( add_query_arg( 'status', false, $this->base_url ) ),
173
+                $current === 'all' ? ' class="current"' : '',
174
+                __( 'All', 'invoicing' ),
175
+                $this->total_count
176
+            ),
177
+
178
+        );
179
+
180
+        foreach ( array_filter( $this->status_counts ) as $status => $count ) {
181
+
182
+            $views[ $status ] = sprintf(
183
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
184
+                esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
185
+                $current === $status ? ' class="current"' : '',
186
+                esc_html( getpaid_get_subscription_status_label( $status ) ),
187
+                $count
188
+            );
189
+
190
+        }
191
+
192
+        return $views;
193
+
194
+    }
195
+
196
+    /**
197
+     * Render most columns
198
+     *
199
+     * @access      private
200
+     * @since       1.0.0
201
+     * @return      string
202
+     */
203
+    public function column_default( $item, $column_name ) {
204
+        return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
205
+    }
206
+
207
+    /**
208
+     * This is how checkbox column renders.
209
+     *
210
+     * @param WPInv_Subscription $item
211
+     * @return string
212
+     */
213
+    public function column_cb( $item ) {
214
+        return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
215
+    }
216
+
217
+    /**
218
+     * Status column
219
+     *
220
+     * @param WPInv_Subscription $item
221
+     * @since       1.0.0
222
+     * @return      string
223
+     */
224
+    public function column_status( $item ) {
225
+        $extra = $item->has_status( 'expired' ) ? '<small class="text-muted d-block">' . wp_sprintf( _x( 'On: %s', 'Expired On:', 'invoicing' ), getpaid_format_date_value( $item->get_expiration() ) ) . '</small>' : '';
226
+
227
+        return $item->get_status_label_html() . $extra;
228
+    }
229
+
230
+    /**
231
+     * Subscription column
232
+     *
233
+     * @param WPInv_Subscription $item
234
+     * @since       1.0.0
235
+     * @return      string
236
+     */
237
+    public function column_subscription( $item ) {
238
+
239
+        $username = __( '(Missing User)', 'invoicing' );
240
+
241
+        $user = get_userdata( $item->get_customer_id() );
242
+        $capabilities = wpinv_current_user_can_manage_invoicing();
243
+
244
+        if ( $user ) {
245
+            $username = sprintf(
246
+                '<a href="user-edit.php?user_id=%s">%s</a>',
247
+                absint( $user->ID ),
248
+                ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email )
249
+            );
250
+        }
251
+
252
+        // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
253
+        $column_content = sprintf(
254
+            _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
255
+            '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
256
+            '<strong>' . esc_attr( $item->get_id() ) . '</strong>',
257
+            '</a>',
258
+            $username
259
+        );
260
+
261
+        $row_actions = array();
262
+
263
+        // View subscription.
264
+        $view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) );
265
+        $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
266
+
267
+        // View invoice.
268
+        $invoice = get_post( $item->get_parent_invoice_id() );
269
+
270
+        if ( ! empty( $invoice ) ) {
271
+            $invoice_url            = get_edit_post_link( $invoice );
272
+            $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
273
+        }
274
+
275
+        $delete_url            = esc_url(
276
+            wp_nonce_url(
277
+                add_query_arg(
278
+                    array(
279
+                        'getpaid-admin-action' => 'subscription_manual_delete',
280
+                        'id'                   => $item->get_id(),
281
+                    )
282
+                ),
283
+                'getpaid-nonce',
284
+                'getpaid-nonce'
285
+            )
286
+        );
287
+        $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
288
+
289
+        if ( ! $capabilities ) {
290
+            $row_actions = array();
291
+        }
292
+
293
+        $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
294
+
295
+        return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
296
+    }
297
+
298
+    /**
299
+     * Renewal date column
300
+     *
301
+     * @param WPInv_Subscription $item
302
+     * @since       1.0.0
303
+     * @return      string
304
+     */
305
+    public function column_renewal_date( $item ) {
306
+        if ( $item->has_status( 'active trialling' ) ) {
307
+            $value = getpaid_format_date_value( $item->get_expiration() );
308
+        } else {
309
+            $value = '-';
310
+        }
311
+
312
+        return $value;
313
+    }
314
+
315
+    /**
316
+     * Start date column
317
+     *
318
+     * @param WPInv_Subscription $item
319
+     * @since       1.0.0
320
+     * @return      string
321
+     */
322
+    public function column_start_date( $item ) {
323
+
324
+        $gateway = $item->get_parent_invoice()->get_gateway_title();
325
+
326
+        if ( empty( $gateway ) ) {
327
+            return getpaid_format_date_value( $item->get_date_created() );
328
+        }
329
+
330
+        $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item );
331
+        if ( ! empty( $url ) ) {
332
+
333
+            return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf(
334
+                __( 'Via %s', 'invoicing' ),
335
+                '<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>'
336
+            );
337
+
338
+        }
339
+
340
+        return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf(
341
+            __( 'Via %s', 'invoicing' ),
342
+            '<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>'
343
+        );
344
+
345
+    }
346
+
347
+    /**
348
+     * Amount column
349
+     *
350
+     * @param WPInv_Subscription $item
351
+     * @since       1.0.19
352
+     * @return      string
353
+     */
354
+    public static function column_amount( $item ) {
355
+        $amount = getpaid_get_formatted_subscription_amount( $item );
356
+        return "<span class='text-muted form-text mt-2 mb-2 ms-1 ml-1'>$amount</span>";
357
+    }
358
+
359
+    /**
360
+     * Billing Times column
361
+     *
362
+     * @param WPInv_Subscription $item
363
+     * @since       1.0.0
364
+     * @return      string
365
+     */
366
+    public function column_renewals( $item ) {
367
+        $max_bills = $item->get_bill_times();
368
+        return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '&infin;' : $max_bills );
369
+    }
370
+
371
+    /**
372
+     * Product ID column
373
+     *
374
+     * @param WPInv_Subscription $item
375
+     * @since       1.0.0
376
+     * @return      string
377
+     */
378
+    public function column_item( $item ) {
379
+        $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() );
380
+
381
+        if ( empty( $subscription_group ) ) {
382
+            return $this->generate_item_markup( $item->get_product_id() );
383
+        }
384
+
385
+        $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
386
+        return implode( ' | ', $markup );
387
+
388
+    }
389
+
390
+    /**
391
+     * Generates the items markup.
392
+     *
393
+     * @param int $item_id
394
+     * @since       1.0.0
395
+     * @return      string
396
+     */
397
+    public static function generate_item_markup( $item_id ) {
398
+        $item = get_post( $item_id );
399
+
400
+        if ( ! empty( $item ) ) {
401
+            $link = get_edit_post_link( $item );
402
+            $name = esc_html( get_the_title( $item ) );
403
+            return wpinv_current_user_can_manage_invoicing() ? "<a href='" . ( $link ? esc_url( $link ) : '#' ) . "'>$name</a>" : $name;
404
+        } else {
405
+            return sprintf( __( 'Item #%s', 'invoicing' ), $item_id );
406
+        }
407
+
408
+    }
409
+
410
+    /**
411
+     * Retrieve the current page number
412
+     *
413
+     * @return      int
414
+     */
415
+    public function get_paged() {
416
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
417
+    }
418
+
419
+    /**
420
+     * Setup the final data for the table
421
+     *
422
+     */
423
+    public function prepare_items() {
424
+
425
+        $columns  = $this->get_columns();
426
+        $hidden   = array();
427
+        $sortable = $this->get_sortable_columns();
428
+
429
+        $this->_column_headers = array( $columns, $hidden, $sortable );
430
+
431
+        $this->set_pagination_args(
432
+            array(
433
+                'total_items' => $this->current_total_count,
434
+                'per_page'    => $this->per_page,
435
+                'total_pages' => ceil( $this->current_total_count / $this->per_page ),
436
+            )
437
+        );
438
+    }
439
+
440
+    /**
441
+     * Table columns
442
+     *
443
+     * @return array
444
+     */
445
+    public function get_columns() {
446
+        $columns = array(
447
+            'cb'           => '<input type="checkbox" />',
448
+            'subscription' => __( 'Subscription', 'invoicing' ),
449
+            'start_date'   => __( 'Start Date', 'invoicing' ),
450
+            'renewal_date' => __( 'Next Payment', 'invoicing' ),
451
+            'renewals'     => __( 'Payments', 'invoicing' ),
452
+            'item'         => __( 'Items', 'invoicing' ),
453
+            'status'       => __( 'Status', 'invoicing' ),
454
+        );
455
+
456
+        return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
457
+    }
458
+
459
+    /**
460
+     * Sortable table columns.
461
+     *
462
+     * @return array
463
+     */
464
+    public function get_sortable_columns() {
465
+        $sortable = array(
466
+            'subscription' => array( 'id', true ),
467
+            'start_date'   => array( 'created', true ),
468
+            'renewal_date' => array( 'expiration', true ),
469
+            'renewals'     => array( 'bill_times', true ),
470
+            'item'         => array( 'product_id', true ),
471
+            'status'       => array( 'status', true ),
472
+        );
473
+
474
+        return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
475
+    }
476
+
477
+    /**
478
+     * Whether the table has items to display or not
479
+     *
480
+     * @return bool
481
+     */
482
+    public function has_items() {
483
+        return ! empty( $this->current_total_count );
484
+    }
485
+
486
+    /**
487
+     * Processes bulk actions.
488
+     *
489
+     */
490
+    public function process_bulk_action() {
491
+
492
+    }
493 493
 
494 494
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -3,11 +3,11 @@  discard block
 block discarded – undo
3 3
  * Displays a list of all subscriptions rules
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
 exit;
8 8
 }
9 9
 
10
-if ( ! class_exists( 'WP_List_Table' ) ) {
10
+if (!class_exists('WP_List_Table')) {
11 11
 	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
12 12
 }
13 13
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 
81 81
 		$this->prepare_query();
82 82
 
83
-		$this->base_url = remove_query_arg( 'status' );
83
+		$this->base_url = remove_query_arg('status');
84 84
 
85 85
 	}
86 86
 
@@ -93,13 +93,13 @@  discard block
 block discarded – undo
93 93
 		$query = array(
94 94
 			'number'      => $this->per_page,
95 95
 			'paged'       => $this->get_paged(),
96
-			'status'      => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all',
97
-			'orderby'     => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id',
98
-			'order'       => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC',
96
+			'status'      => (isset($_GET['status']) && array_key_exists($_GET['status'], getpaid_get_subscription_statuses())) ? sanitize_text_field($_GET['status']) : 'all',
97
+			'orderby'     => (isset($_GET['orderby'])) ? sanitize_text_field($_GET['orderby']) : 'id',
98
+			'order'       => (isset($_GET['order'])) ? sanitize_text_field($_GET['order']) : 'DESC',
99 99
 			'customer_in' => $this->get_user_in(),
100 100
 		);
101 101
 
102
-		if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) {
102
+		if (is_array($query['customer_in']) && empty($query['customer_in'])) {
103 103
 			$this->total_count         = 0;
104 104
 			$this->current_total_count = 0;
105 105
 			$this->items               = array();
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
 		}
109 109
 
110 110
 		// Prepare class properties.
111
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
111
+		$this->query               = new GetPaid_Subscriptions_Query($query);
112 112
 		$this->total_count         = $this->query->get_total();
113 113
 		$this->current_total_count = $this->query->get_total();
114 114
 		$this->items               = $this->query->get_results();
115
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
115
+		$this->status_counts       = getpaid_get_subscription_status_counts($query);
116 116
 
117
-		if ( 'all' != $query['status'] ) {
118
-			unset( $query['status'] );
119
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
117
+		if ('all' != $query['status']) {
118
+			unset($query['status']);
119
+			$this->total_count = getpaid_get_subscriptions($query, 'count');
120 120
 		}
121 121
 
122 122
 	}
@@ -128,14 +128,14 @@  discard block
 block discarded – undo
128 128
 	public function get_user_in() {
129 129
 
130 130
 		// Abort if no user.
131
-		if ( empty( $_GET['s'] ) ) {
131
+		if (empty($_GET['s'])) {
132 132
 			return null;
133 133
 		}
134 134
 
135 135
 		// Or invalid user.
136
-		$user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) );
136
+		$user = wp_unslash(sanitize_text_field($_REQUEST['s']));
137 137
 
138
-		if ( empty( $user ) ) {
138
+		if (empty($user)) {
139 139
 			return null;
140 140
 		}
141 141
 
@@ -164,26 +164,26 @@  discard block
 block discarded – undo
164 164
 	 */
165 165
 	public function get_views() {
166 166
 
167
-		$current  = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all';
167
+		$current  = isset($_GET['status']) ? sanitize_text_field($_GET['status']) : 'all';
168 168
 		$views    = array(
169 169
 
170 170
 			'all' => sprintf(
171 171
 				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
172
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
172
+				esc_url(add_query_arg('status', false, $this->base_url)),
173 173
 				$current === 'all' ? ' class="current"' : '',
174
-				__( 'All', 'invoicing' ),
174
+				__('All', 'invoicing'),
175 175
 				$this->total_count
176 176
 			),
177 177
 
178 178
 		);
179 179
 
180
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
180
+		foreach (array_filter($this->status_counts) as $status => $count) {
181 181
 
182
-			$views[ $status ] = sprintf(
182
+			$views[$status] = sprintf(
183 183
 				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
184
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
184
+				esc_url(add_query_arg('status', urlencode($status), $this->base_url)),
185 185
 				$current === $status ? ' class="current"' : '',
186
-				esc_html( getpaid_get_subscription_status_label( $status ) ),
186
+				esc_html(getpaid_get_subscription_status_label($status)),
187 187
 				$count
188 188
 			);
189 189
 
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 	 * @since       1.0.0
201 201
 	 * @return      string
202 202
 	 */
203
-	public function column_default( $item, $column_name ) {
204
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
203
+	public function column_default($item, $column_name) {
204
+		return apply_filters("getpaid_subscriptions_table_column_$column_name", $item->$column_name);
205 205
 	}
206 206
 
207 207
 	/**
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
 	 * @param WPInv_Subscription $item
211 211
 	 * @return string
212 212
 	 */
213
-	public function column_cb( $item ) {
214
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
213
+	public function column_cb($item) {
214
+		return sprintf('<input type="checkbox" name="id[]" value="%s" />', esc_html($item->get_id()));
215 215
 	}
216 216
 
217 217
 	/**
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
 	 * @since       1.0.0
222 222
 	 * @return      string
223 223
 	 */
224
-	public function column_status( $item ) {
225
-		$extra = $item->has_status( 'expired' ) ? '<small class="text-muted d-block">' . wp_sprintf( _x( 'On: %s', 'Expired On:', 'invoicing' ), getpaid_format_date_value( $item->get_expiration() ) ) . '</small>' : '';
224
+	public function column_status($item) {
225
+		$extra = $item->has_status('expired') ? '<small class="text-muted d-block">' . wp_sprintf(_x('On: %s', 'Expired On:', 'invoicing'), getpaid_format_date_value($item->get_expiration())) . '</small>' : '';
226 226
 
227 227
 		return $item->get_status_label_html() . $extra;
228 228
 	}
@@ -234,26 +234,26 @@  discard block
 block discarded – undo
234 234
 	 * @since       1.0.0
235 235
 	 * @return      string
236 236
 	 */
237
-	public function column_subscription( $item ) {
237
+	public function column_subscription($item) {
238 238
 
239
-		$username = __( '(Missing User)', 'invoicing' );
239
+		$username = __('(Missing User)', 'invoicing');
240 240
 
241
-		$user = get_userdata( $item->get_customer_id() );
241
+		$user = get_userdata($item->get_customer_id());
242 242
 		$capabilities = wpinv_current_user_can_manage_invoicing();
243 243
 
244
-		if ( $user ) {
244
+		if ($user) {
245 245
 			$username = sprintf(
246 246
 				'<a href="user-edit.php?user_id=%s">%s</a>',
247
-				absint( $user->ID ),
248
-				! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email )
247
+				absint($user->ID),
248
+				!empty($user->display_name) ? esc_html($user->display_name) : sanitize_email($user->user_email)
249 249
 			);
250 250
 		}
251 251
 
252 252
 		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
253 253
 		$column_content = sprintf(
254
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
255
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
256
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>',
254
+			_x('%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing'),
255
+			'<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($item->get_id()))) . '">',
256
+			'<strong>' . esc_attr($item->get_id()) . '</strong>',
257 257
 			'</a>',
258 258
 			$username
259 259
 		);
@@ -261,18 +261,18 @@  discard block
 block discarded – undo
261 261
 		$row_actions = array();
262 262
 
263 263
 		// View subscription.
264
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) );
265
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
264
+		$view_url    = esc_url(add_query_arg('id', $item->get_id(), admin_url('admin.php?page=wpinv-subscriptions')));
265
+		$row_actions['view'] = '<a href="' . $view_url . '">' . __('View Subscription', 'invoicing') . '</a>';
266 266
 
267 267
 		// View invoice.
268
-		$invoice = get_post( $item->get_parent_invoice_id() );
268
+		$invoice = get_post($item->get_parent_invoice_id());
269 269
 
270
-		if ( ! empty( $invoice ) ) {
271
-			$invoice_url            = get_edit_post_link( $invoice );
272
-			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
270
+		if (!empty($invoice)) {
271
+			$invoice_url            = get_edit_post_link($invoice);
272
+			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __('View Invoice', 'invoicing') . '</a>';
273 273
 		}
274 274
 
275
-		$delete_url            = esc_url(
275
+		$delete_url = esc_url(
276 276
 			wp_nonce_url(
277 277
 				add_query_arg(
278 278
 					array(
@@ -284,15 +284,15 @@  discard block
 block discarded – undo
284 284
 				'getpaid-nonce'
285 285
 			)
286 286
 		);
287
-		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
287
+		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __('Delete Subscription', 'invoicing') . '</a>';
288 288
 
289
-		if ( ! $capabilities ) {
289
+		if (!$capabilities) {
290 290
 			$row_actions = array();
291 291
 		}
292 292
 
293
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
293
+		$row_actions = $this->row_actions(apply_filters('getpaid_subscription_table_row_actions', $row_actions, $item));
294 294
 
295
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
295
+		return "<strong>$column_content</strong>" . $this->column_amount($item) . $row_actions;
296 296
 	}
297 297
 
298 298
 	/**
@@ -302,9 +302,9 @@  discard block
 block discarded – undo
302 302
 	 * @since       1.0.0
303 303
 	 * @return      string
304 304
 	 */
305
-	public function column_renewal_date( $item ) {
306
-		if ( $item->has_status( 'active trialling' ) ) {
307
-			$value = getpaid_format_date_value( $item->get_expiration() );
305
+	public function column_renewal_date($item) {
306
+		if ($item->has_status('active trialling')) {
307
+			$value = getpaid_format_date_value($item->get_expiration());
308 308
 		} else {
309 309
 			$value = '-';
310 310
 		}
@@ -319,27 +319,27 @@  discard block
 block discarded – undo
319 319
 	 * @since       1.0.0
320 320
 	 * @return      string
321 321
 	 */
322
-	public function column_start_date( $item ) {
322
+	public function column_start_date($item) {
323 323
 
324 324
 		$gateway = $item->get_parent_invoice()->get_gateway_title();
325 325
 
326
-		if ( empty( $gateway ) ) {
327
-			return getpaid_format_date_value( $item->get_date_created() );
326
+		if (empty($gateway)) {
327
+			return getpaid_format_date_value($item->get_date_created());
328 328
 		}
329 329
 
330
-		$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item );
331
-		if ( ! empty( $url ) ) {
330
+		$url = apply_filters('getpaid_remote_subscription_profile_url', '', $item);
331
+		if (!empty($url)) {
332 332
 
333
-			return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf(
334
-				__( 'Via %s', 'invoicing' ),
335
-				'<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>'
333
+			return getpaid_format_date_value($item->get_date_created()) . '<br>' . sprintf(
334
+				__('Via %s', 'invoicing'),
335
+				'<strong><a href="' . esc_url($url) . '" target="_blank">' . esc_html($item->get_parent_invoice()->get_gateway_title()) . '</a></strong>'
336 336
 			);
337 337
 
338 338
 		}
339 339
 
340
-		return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf(
341
-			__( 'Via %s', 'invoicing' ),
342
-			'<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>'
340
+		return getpaid_format_date_value($item->get_date_created()) . '<br>' . sprintf(
341
+			__('Via %s', 'invoicing'),
342
+			'<strong>' . esc_html($item->get_parent_invoice()->get_gateway_title()) . '</strong>'
343 343
 		);
344 344
 
345 345
 	}
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
 	 * @since       1.0.19
352 352
 	 * @return      string
353 353
 	 */
354
-	public static function column_amount( $item ) {
355
-		$amount = getpaid_get_formatted_subscription_amount( $item );
354
+	public static function column_amount($item) {
355
+		$amount = getpaid_get_formatted_subscription_amount($item);
356 356
 		return "<span class='text-muted form-text mt-2 mb-2 ms-1 ml-1'>$amount</span>";
357 357
 	}
358 358
 
@@ -363,9 +363,9 @@  discard block
 block discarded – undo
363 363
 	 * @since       1.0.0
364 364
 	 * @return      string
365 365
 	 */
366
-	public function column_renewals( $item ) {
366
+	public function column_renewals($item) {
367 367
 		$max_bills = $item->get_bill_times();
368
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '&infin;' : $max_bills );
368
+		return $item->get_times_billed() . ' / ' . (empty($max_bills) ? '&infin;' : $max_bills);
369 369
 	}
370 370
 
371 371
 	/**
@@ -375,15 +375,15 @@  discard block
 block discarded – undo
375 375
 	 * @since       1.0.0
376 376
 	 * @return      string
377 377
 	 */
378
-	public function column_item( $item ) {
379
-		$subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() );
378
+	public function column_item($item) {
379
+		$subscription_group = getpaid_get_invoice_subscription_group($item->get_parent_invoice_id(), $item->get_id());
380 380
 
381
-		if ( empty( $subscription_group ) ) {
382
-			return $this->generate_item_markup( $item->get_product_id() );
381
+		if (empty($subscription_group)) {
382
+			return $this->generate_item_markup($item->get_product_id());
383 383
 		}
384 384
 
385
-		$markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
386
-		return implode( ' | ', $markup );
385
+		$markup = array_map(array($this, 'generate_item_markup'), array_keys($subscription_group['items']));
386
+		return implode(' | ', $markup);
387 387
 
388 388
 	}
389 389
 
@@ -394,15 +394,15 @@  discard block
 block discarded – undo
394 394
 	 * @since       1.0.0
395 395
 	 * @return      string
396 396
 	 */
397
-	public static function generate_item_markup( $item_id ) {
398
-		$item = get_post( $item_id );
397
+	public static function generate_item_markup($item_id) {
398
+		$item = get_post($item_id);
399 399
 
400
-		if ( ! empty( $item ) ) {
401
-			$link = get_edit_post_link( $item );
402
-			$name = esc_html( get_the_title( $item ) );
403
-			return wpinv_current_user_can_manage_invoicing() ? "<a href='" . ( $link ? esc_url( $link ) : '#' ) . "'>$name</a>" : $name;
400
+		if (!empty($item)) {
401
+			$link = get_edit_post_link($item);
402
+			$name = esc_html(get_the_title($item));
403
+			return wpinv_current_user_can_manage_invoicing() ? "<a href='" . ($link ? esc_url($link) : '#') . "'>$name</a>" : $name;
404 404
 		} else {
405
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item_id );
405
+			return sprintf(__('Item #%s', 'invoicing'), $item_id);
406 406
 		}
407 407
 
408 408
 	}
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 	 * @return      int
414 414
 	 */
415 415
 	public function get_paged() {
416
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
416
+		return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
417 417
 	}
418 418
 
419 419
 	/**
@@ -426,13 +426,13 @@  discard block
 block discarded – undo
426 426
 		$hidden   = array();
427 427
 		$sortable = $this->get_sortable_columns();
428 428
 
429
-		$this->_column_headers = array( $columns, $hidden, $sortable );
429
+		$this->_column_headers = array($columns, $hidden, $sortable);
430 430
 
431 431
 		$this->set_pagination_args(
432 432
 			array(
433 433
 				'total_items' => $this->current_total_count,
434 434
 				'per_page'    => $this->per_page,
435
-				'total_pages' => ceil( $this->current_total_count / $this->per_page ),
435
+				'total_pages' => ceil($this->current_total_count / $this->per_page),
436 436
 			)
437 437
 		);
438 438
 	}
@@ -445,15 +445,15 @@  discard block
 block discarded – undo
445 445
 	public function get_columns() {
446 446
 		$columns = array(
447 447
 			'cb'           => '<input type="checkbox" />',
448
-			'subscription' => __( 'Subscription', 'invoicing' ),
449
-			'start_date'   => __( 'Start Date', 'invoicing' ),
450
-			'renewal_date' => __( 'Next Payment', 'invoicing' ),
451
-			'renewals'     => __( 'Payments', 'invoicing' ),
452
-			'item'         => __( 'Items', 'invoicing' ),
453
-			'status'       => __( 'Status', 'invoicing' ),
448
+			'subscription' => __('Subscription', 'invoicing'),
449
+			'start_date'   => __('Start Date', 'invoicing'),
450
+			'renewal_date' => __('Next Payment', 'invoicing'),
451
+			'renewals'     => __('Payments', 'invoicing'),
452
+			'item'         => __('Items', 'invoicing'),
453
+			'status'       => __('Status', 'invoicing'),
454 454
 		);
455 455
 
456
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
456
+		return apply_filters('manage_getpaid_subscriptions_table_columns', $columns);
457 457
 	}
458 458
 
459 459
 	/**
@@ -463,15 +463,15 @@  discard block
 block discarded – undo
463 463
 	 */
464 464
 	public function get_sortable_columns() {
465 465
 		$sortable = array(
466
-			'subscription' => array( 'id', true ),
467
-			'start_date'   => array( 'created', true ),
468
-			'renewal_date' => array( 'expiration', true ),
469
-			'renewals'     => array( 'bill_times', true ),
470
-			'item'         => array( 'product_id', true ),
471
-			'status'       => array( 'status', true ),
466
+			'subscription' => array('id', true),
467
+			'start_date'   => array('created', true),
468
+			'renewal_date' => array('expiration', true),
469
+			'renewals'     => array('bill_times', true),
470
+			'item'         => array('product_id', true),
471
+			'status'       => array('status', true),
472 472
 		);
473 473
 
474
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
474
+		return apply_filters('manage_getpaid_subscriptions_sortable_table_columns', $sortable);
475 475
 	}
476 476
 
477 477
 	/**
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 * @return bool
481 481
 	 */
482 482
 	public function has_items() {
483
-		return ! empty( $this->current_total_count );
483
+		return !empty($this->current_total_count);
484 484
 	}
485 485
 
486 486
 	/**
Please login to merge, or discard this patch.
includes/data/email-settings.php 1 patch
Spacing   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -8,24 +8,24 @@  discard block
 block discarded – undo
8 8
  * @version 1.0.19
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 // Prepare the due date reminder options.
14 14
 $overdue_days_options       = array();
15
-$overdue_days_options['0']  = __( 'On the Due Date', 'invoicing' );
16
-$overdue_days_options['1']  = __( '1 day after Due Date', 'invoicing' );
15
+$overdue_days_options['0']  = __('On the Due Date', 'invoicing');
16
+$overdue_days_options['1']  = __('1 day after Due Date', 'invoicing');
17 17
 
18
-for ( $i = 2; $i <= 45; $i++ ) {
19
-    $overdue_days_options[ "$i" ] = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
18
+for ($i = 2; $i <= 45; $i++) {
19
+    $overdue_days_options["$i"] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
20 20
 }
21 21
 
22 22
 // Prepare up coming renewal reminder options.
23 23
 $renewal_days_options       = array();
24
-$renewal_days_options['0']  = __( 'On the renewal date', 'invoicing' );
25
-$renewal_days_options['1']  = __( '1 day before the renewal date', 'invoicing' );
24
+$renewal_days_options['0']  = __('On the renewal date', 'invoicing');
25
+$renewal_days_options['1']  = __('1 day before the renewal date', 'invoicing');
26 26
 
27
-for ( $i = 2; $i <= 45; $i++ ) {
28
-    $renewal_days_options[ "$i" ]   = wp_sprintf( __( '%d days before the renewal date', 'invoicing' ), $i );
27
+for ($i = 2; $i <= 45; $i++) {
28
+    $renewal_days_options["$i"] = wp_sprintf(__('%d days before the renewal date', 'invoicing'), $i);
29 29
 }
30 30
 
31 31
 // Default, built-in gateways
@@ -34,45 +34,45 @@  discard block
 block discarded – undo
34 34
 
35 35
         'email_new_invoice_header'  => array(
36 36
             'id'   => 'email_new_invoice_header',
37
-            'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
38
-            'desc' => __( 'These emails are sent to the site admin whenever there is a new invoice.', 'invoicing' ),
37
+            'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
38
+            'desc' => __('These emails are sent to the site admin whenever there is a new invoice.', 'invoicing'),
39 39
             'type' => 'header',
40 40
         ),
41 41
 
42 42
         'email_new_invoice_active'  => array(
43 43
             'id'   => 'email_new_invoice_active',
44
-            'name' => __( 'Enable/Disable', 'invoicing' ),
45
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
44
+            'name' => __('Enable/Disable', 'invoicing'),
45
+            'desc' => __('Enable this email notification', 'invoicing'),
46 46
             'type' => 'checkbox',
47 47
             'std'  => 1,
48 48
         ),
49 49
 
50 50
         'email_new_invoice_subject' => array(
51 51
             'id'       => 'email_new_invoice_subject',
52
-            'name'     => __( 'Subject', 'invoicing' ),
53
-            'desc'     => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
52
+            'name'     => __('Subject', 'invoicing'),
53
+            'desc'     => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
54 54
             'help-tip' => true,
55 55
             'type'     => 'text',
56
-            'std'      => __( '[{site_title}] New invoice ({invoice_number}) for {invoice_total} {invoice_currency}', 'invoicing' ),
56
+            'std'      => __('[{site_title}] New invoice ({invoice_number}) for {invoice_total} {invoice_currency}', 'invoicing'),
57 57
             'size'     => 'large',
58 58
         ),
59 59
 
60 60
         'email_new_invoice_heading' => array(
61 61
             'id'       => 'email_new_invoice_heading',
62
-            'name'     => __( 'Email Heading', 'invoicing' ),
63
-            'desc'     => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
62
+            'name'     => __('Email Heading', 'invoicing'),
63
+            'desc'     => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
64 64
             'help-tip' => true,
65 65
             'type'     => 'text',
66
-            'std'      => __( 'New invoice', 'invoicing' ),
66
+            'std'      => __('New invoice', 'invoicing'),
67 67
             'size'     => 'large',
68 68
         ),
69 69
 
70 70
         'email_new_invoice_body'    => array(
71 71
             'id'    => 'email_new_invoice_body',
72
-            'name'  => __( 'Email Content', 'invoicing' ),
72
+            'name'  => __('Email Content', 'invoicing'),
73 73
             'desc'  => wpinv_get_merge_tags_help_text(),
74 74
             'type'  => 'rich_editor',
75
-            'std'   => __( '<p>A new invoice <a href="{invoice_link}">({invoice_number})</a> to {name} for {invoice_total} {invoice_currency} has been created on your site. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing' ),
75
+            'std'   => __('<p>A new invoice <a href="{invoice_link}">({invoice_number})</a> to {name} for {invoice_total} {invoice_currency} has been created on your site. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing'),
76 76
             'class' => 'large',
77 77
             'size'  => '10',
78 78
         ),
@@ -82,53 +82,53 @@  discard block
 block discarded – undo
82 82
 
83 83
         'email_cancelled_invoice_header'    => array(
84 84
             'id'   => 'email_cancelled_invoice_header',
85
-            'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
86
-            'desc' => __( 'These emails are sent to customers whenever invoices are cancelled.', 'invoicing' ),
85
+            'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
86
+            'desc' => __('These emails are sent to customers whenever invoices are cancelled.', 'invoicing'),
87 87
             'type' => 'header',
88 88
         ),
89 89
 
90 90
         'email_cancelled_invoice_active'    => array(
91 91
             'id'   => 'email_cancelled_invoice_active',
92
-            'name' => __( 'Enable/Disable', 'invoicing' ),
93
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
92
+            'name' => __('Enable/Disable', 'invoicing'),
93
+            'desc' => __('Enable this email notification', 'invoicing'),
94 94
             'type' => 'checkbox',
95 95
             'std'  => 1,
96 96
         ),
97 97
 
98 98
         'email_cancelled_invoice_admin_bcc' => array(
99 99
             'id'   => 'email_cancelled_invoice_admin_bcc',
100
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
101
-            'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
100
+            'name' => __('Enable Admin BCC', 'invoicing'),
101
+            'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
102 102
             'type' => 'checkbox',
103 103
             'std'  => 1,
104 104
         ),
105 105
 
106 106
         'email_cancelled_invoice_subject'   => array(
107 107
             'id'       => 'email_cancelled_invoice_subject',
108
-            'name'     => __( 'Subject', 'invoicing' ),
109
-            'desc'     => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
108
+            'name'     => __('Subject', 'invoicing'),
109
+            'desc'     => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
110 110
             'help-tip' => true,
111 111
             'type'     => 'text',
112
-            'std'      => __( '[{site_title}] Invoice ({invoice_number}) Cancelled', 'invoicing' ),
112
+            'std'      => __('[{site_title}] Invoice ({invoice_number}) Cancelled', 'invoicing'),
113 113
             'size'     => 'large',
114 114
         ),
115 115
 
116 116
         'email_cancelled_invoice_heading'   => array(
117 117
             'id'       => 'email_cancelled_invoice_heading',
118
-            'name'     => __( 'Email Heading', 'invoicing' ),
119
-            'desc'     => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
118
+            'name'     => __('Email Heading', 'invoicing'),
119
+            'desc'     => __('Enter the main heading contained within the email notification.', 'invoicing'),
120 120
             'help-tip' => true,
121 121
             'type'     => 'text',
122
-            'std'      => __( 'Invoice Cancelled', 'invoicing' ),
122
+            'std'      => __('Invoice Cancelled', 'invoicing'),
123 123
             'size'     => 'large',
124 124
         ),
125 125
 
126 126
         'email_cancelled_invoice_body'      => array(
127 127
             'id'    => 'email_cancelled_invoice_body',
128
-            'name'  => __( 'Email Content', 'invoicing' ),
128
+            'name'  => __('Email Content', 'invoicing'),
129 129
             'desc'  => wpinv_get_merge_tags_help_text(),
130 130
             'type'  => 'rich_editor',
131
-            'std'   => __( '<p>The invoice <a href="{invoice_link}">#{invoice_number}</a> created for {name} on {site_title} has been cancelled. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing' ),
131
+            'std'   => __('<p>The invoice <a href="{invoice_link}">#{invoice_number}</a> created for {name} on {site_title} has been cancelled. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing'),
132 132
             'class' => 'large',
133 133
             'size'  => '10',
134 134
         ),
@@ -139,45 +139,45 @@  discard block
 block discarded – undo
139 139
 
140 140
         'email_failed_invoice_header'  => array(
141 141
             'id'   => 'email_failed_invoice_header',
142
-            'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
143
-            'desc' => __( 'Failed invoice emails are sent to the site admin when invoice payments fail.', 'invoicing' ),
142
+            'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
143
+            'desc' => __('Failed invoice emails are sent to the site admin when invoice payments fail.', 'invoicing'),
144 144
             'type' => 'header',
145 145
         ),
146 146
 
147 147
         'email_failed_invoice_active'  => array(
148 148
             'id'   => 'email_failed_invoice_active',
149
-            'name' => __( 'Enable/Disable', 'invoicing' ),
150
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
149
+            'name' => __('Enable/Disable', 'invoicing'),
150
+            'desc' => __('Enable this email notification', 'invoicing'),
151 151
             'type' => 'checkbox',
152 152
             'std'  => 1,
153 153
         ),
154 154
 
155 155
         'email_failed_invoice_subject' => array(
156 156
             'id'       => 'email_failed_invoice_subject',
157
-            'name'     => __( 'Subject', 'invoicing' ),
158
-            'desc'     => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
157
+            'name'     => __('Subject', 'invoicing'),
158
+            'desc'     => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
159 159
             'help-tip' => true,
160 160
             'type'     => 'text',
161
-            'std'      => __( '[{site_title}] Invoice ({invoice_number}) Payment Failed', 'invoicing' ),
161
+            'std'      => __('[{site_title}] Invoice ({invoice_number}) Payment Failed', 'invoicing'),
162 162
             'size'     => 'large',
163 163
         ),
164 164
 
165 165
         'email_failed_invoice_heading' => array(
166 166
             'id'       => 'email_failed_invoice_heading',
167
-            'name'     => __( 'Email Heading', 'invoicing' ),
168
-            'desc'     => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
167
+            'name'     => __('Email Heading', 'invoicing'),
168
+            'desc'     => __('Enter the main heading contained within the email notification.', 'invoicing'),
169 169
             'help-tip' => true,
170 170
             'type'     => 'text',
171
-            'std'      => __( 'Invoice Payment Failed', 'invoicing' ),
171
+            'std'      => __('Invoice Payment Failed', 'invoicing'),
172 172
             'size'     => 'large',
173 173
         ),
174 174
 
175 175
         'email_failed_invoice_body'    => array(
176 176
             'id'    => 'email_failed_invoice_body',
177
-            'name'  => __( 'Email Content', 'invoicing' ),
177
+            'name'  => __('Email Content', 'invoicing'),
178 178
             'desc'  => wpinv_get_merge_tags_help_text(),
179 179
             'type'  => 'rich_editor',
180
-            'std'   => __( '<p>Payment for the invoice <a href="{invoice_link}">#{invoice_number}</a> on {site_title} has failed to go through. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing' ),
180
+            'std'   => __('<p>Payment for the invoice <a href="{invoice_link}">#{invoice_number}</a> on {site_title} has failed to go through. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing'),
181 181
             'class' => 'large',
182 182
             'size'  => '10',
183 183
         ),
@@ -187,53 +187,53 @@  discard block
 block discarded – undo
187 187
 
188 188
         'email_onhold_invoice_header'    => array(
189 189
             'id'   => 'email_onhold_invoice_header',
190
-            'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
191
-            'desc' => __( 'These emails are sent to customers whenever their invoices are held.', 'invoicing' ),
190
+            'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
191
+            'desc' => __('These emails are sent to customers whenever their invoices are held.', 'invoicing'),
192 192
             'type' => 'header',
193 193
         ),
194 194
 
195 195
         'email_onhold_invoice_active'    => array(
196 196
             'id'   => 'email_onhold_invoice_active',
197
-            'name' => __( 'Enable/Disable', 'invoicing' ),
198
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
197
+            'name' => __('Enable/Disable', 'invoicing'),
198
+            'desc' => __('Enable this email notification', 'invoicing'),
199 199
             'type' => 'checkbox',
200 200
             'std'  => 1,
201 201
         ),
202 202
 
203 203
         'email_onhold_invoice_admin_bcc' => array(
204 204
             'id'   => 'email_onhold_invoice_admin_bcc',
205
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
206
-            'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
205
+            'name' => __('Enable Admin BCC', 'invoicing'),
206
+            'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
207 207
             'type' => 'checkbox',
208 208
             'std'  => 1,
209 209
         ),
210 210
 
211 211
         'email_onhold_invoice_subject'   => array(
212 212
             'id'       => 'email_onhold_invoice_subject',
213
-            'name'     => __( 'Subject', 'invoicing' ),
214
-            'desc'     => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
213
+            'name'     => __('Subject', 'invoicing'),
214
+            'desc'     => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
215 215
             'help-tip' => true,
216 216
             'type'     => 'text',
217
-            'std'      => __( '[{site_title}] Your invoice is on hold', 'invoicing' ),
217
+            'std'      => __('[{site_title}] Your invoice is on hold', 'invoicing'),
218 218
             'size'     => 'large',
219 219
         ),
220 220
 
221 221
         'email_onhold_invoice_heading'   => array(
222 222
             'id'       => 'email_onhold_invoice_heading',
223
-            'name'     => __( 'Email Heading', 'invoicing' ),
224
-            'desc'     => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
223
+            'name'     => __('Email Heading', 'invoicing'),
224
+            'desc'     => __('Enter the main heading contained within the email notification.', 'invoicing'),
225 225
             'help-tip' => true,
226 226
             'type'     => 'text',
227
-            'std'      => __( 'Your invoice is on hold', 'invoicing' ),
227
+            'std'      => __('Your invoice is on hold', 'invoicing'),
228 228
             'size'     => 'large',
229 229
         ),
230 230
 
231 231
         'email_onhold_invoice_body'      => array(
232 232
             'id'    => 'email_onhold_invoice_body',
233
-            'name'  => __( 'Email Content', 'invoicing' ),
233
+            'name'  => __('Email Content', 'invoicing'),
234 234
             'desc'  => wpinv_get_merge_tags_help_text(),
235 235
             'type'  => 'rich_editor',
236
-            'std'   => __( '<p>Hi {name},</p><p>Your invoice is on-hold and will be processed when we receive your payment. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing' ),
236
+            'std'   => __('<p>Hi {name},</p><p>Your invoice is on-hold and will be processed when we receive your payment. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing'),
237 237
             'class' => 'large',
238 238
             'size'  => '10',
239 239
         ),
@@ -244,53 +244,53 @@  discard block
 block discarded – undo
244 244
 
245 245
         'email_processing_invoice_header'    => array(
246 246
             'id'   => 'email_processing_invoice_header',
247
-            'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
248
-            'desc' => __( 'These emails are sent to users whenever payments for their invoices are processing.', 'invoicing' ),
247
+            'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
248
+            'desc' => __('These emails are sent to users whenever payments for their invoices are processing.', 'invoicing'),
249 249
             'type' => 'header',
250 250
         ),
251 251
 
252 252
         'email_processing_invoice_active'    => array(
253 253
             'id'   => 'email_processing_invoice_active',
254
-            'name' => __( 'Enable/Disable', 'invoicing' ),
255
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
254
+            'name' => __('Enable/Disable', 'invoicing'),
255
+            'desc' => __('Enable this email notification', 'invoicing'),
256 256
             'type' => 'checkbox',
257 257
             'std'  => 1,
258 258
         ),
259 259
 
260 260
         'email_processing_invoice_admin_bcc' => array(
261 261
             'id'   => 'email_processing_invoice_admin_bcc',
262
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
263
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
262
+            'name' => __('Enable Admin BCC', 'invoicing'),
263
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
264 264
             'type' => 'checkbox',
265 265
             'std'  => 1,
266 266
         ),
267 267
 
268 268
         'email_processing_invoice_subject'   => array(
269 269
             'id'       => 'email_processing_invoice_subject',
270
-            'name'     => __( 'Subject', 'invoicing' ),
271
-            'desc'     => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
270
+            'name'     => __('Subject', 'invoicing'),
271
+            'desc'     => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
272 272
             'help-tip' => true,
273 273
             'type'     => 'text',
274
-            'std'      => __( '[{site_title}] Your payment is being processed', 'invoicing' ),
274
+            'std'      => __('[{site_title}] Your payment is being processed', 'invoicing'),
275 275
             'size'     => 'large',
276 276
         ),
277 277
 
278 278
         'email_processing_invoice_heading'   => array(
279 279
             'id'       => 'email_processing_invoice_heading',
280
-            'name'     => __( 'Email Heading', 'invoicing' ),
281
-            'desc'     => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
280
+            'name'     => __('Email Heading', 'invoicing'),
281
+            'desc'     => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
282 282
             'help-tip' => true,
283 283
             'type'     => 'text',
284
-            'std'      => __( 'Your payment is being processed', 'invoicing' ),
284
+            'std'      => __('Your payment is being processed', 'invoicing'),
285 285
             'size'     => 'large',
286 286
         ),
287 287
 
288 288
         'email_processing_invoice_body'      => array(
289 289
             'id'    => 'email_processing_invoice_body',
290
-            'name'  => __( 'Email Content', 'invoicing' ),
290
+            'name'  => __('Email Content', 'invoicing'),
291 291
             'desc'  => wpinv_get_merge_tags_help_text(),
292 292
             'type'  => 'rich_editor',
293
-            'std'   => __( '<p>Hi {name},</p><p>I would like to let you know that we have received and are currently processing your payment for the invoice <a href="{invoice_link}">#{invoice_number}</a> on {site_title}. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing' ),
293
+            'std'   => __('<p>Hi {name},</p><p>I would like to let you know that we have received and are currently processing your payment for the invoice <a href="{invoice_link}">#{invoice_number}</a> on {site_title}. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing'),
294 294
             'class' => 'large',
295 295
             'size'  => '10',
296 296
         ),
@@ -301,61 +301,61 @@  discard block
 block discarded – undo
301 301
 
302 302
         'email_completed_invoice_header'         => array(
303 303
             'id'   => 'email_completed_invoice_header',
304
-            'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
305
-            'desc' => __( 'These emails are sent to customers when their invoices are marked as paid.', 'invoicing' ),
304
+            'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
305
+            'desc' => __('These emails are sent to customers when their invoices are marked as paid.', 'invoicing'),
306 306
             'type' => 'header',
307 307
         ),
308 308
 
309 309
         'email_completed_invoice_active'         => array(
310 310
             'id'   => 'email_completed_invoice_active',
311
-            'name' => __( 'Enable/Disable', 'invoicing' ),
312
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
311
+            'name' => __('Enable/Disable', 'invoicing'),
312
+            'desc' => __('Enable this email notification', 'invoicing'),
313 313
             'type' => 'checkbox',
314 314
             'std'  => 1,
315 315
         ),
316 316
 
317 317
         'email_completed_invoice_renewal_active' => array(
318 318
             'id'   => 'email_completed_invoice_renewal_active',
319
-            'name' => __( 'Enable renewal notification', 'invoicing' ),
320
-            'desc' => __( 'Should this email be sent for renewals too?', 'invoicing' ),
319
+            'name' => __('Enable renewal notification', 'invoicing'),
320
+            'desc' => __('Should this email be sent for renewals too?', 'invoicing'),
321 321
             'type' => 'checkbox',
322 322
             'std'  => 1,
323 323
         ),
324 324
 
325 325
         'email_completed_invoice_admin_bcc'      => array(
326 326
             'id'   => 'email_completed_invoice_admin_bcc',
327
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
328
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
327
+            'name' => __('Enable Admin BCC', 'invoicing'),
328
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
329 329
             'type' => 'checkbox',
330 330
             'std'  => 1,
331 331
         ),
332 332
 
333 333
         'email_completed_invoice_subject'        => array(
334 334
             'id'       => 'email_completed_invoice_subject',
335
-            'name'     => __( 'Subject', 'invoicing' ),
336
-            'desc'     => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
335
+            'name'     => __('Subject', 'invoicing'),
336
+            'desc'     => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
337 337
             'help-tip' => true,
338 338
             'type'     => 'text',
339
-            'std'      => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
339
+            'std'      => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
340 340
             'size'     => 'large',
341 341
         ),
342 342
 
343 343
         'email_completed_invoice_heading'        => array(
344 344
             'id'       => 'email_completed_invoice_heading',
345
-            'name'     => __( 'Email Heading', 'invoicing' ),
346
-            'desc'     => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
345
+            'name'     => __('Email Heading', 'invoicing'),
346
+            'desc'     => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
347 347
             'help-tip' => true,
348 348
             'type'     => 'text',
349
-            'std'      => __( 'Your invoice has been paid', 'invoicing' ),
349
+            'std'      => __('Your invoice has been paid', 'invoicing'),
350 350
             'size'     => 'large',
351 351
         ),
352 352
 
353 353
         'email_completed_invoice_body'           => array(
354 354
             'id'    => 'email_completed_invoice_body',
355
-            'name'  => __( 'Email Content', 'invoicing' ),
355
+            'name'  => __('Email Content', 'invoicing'),
356 356
             'desc'  => wpinv_get_merge_tags_help_text(),
357 357
             'type'  => 'rich_editor',
358
-            'std'   => __( '<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing' ),
358
+            'std'   => __('<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing'),
359 359
             'class' => 'large',
360 360
             'size'  => '10',
361 361
         ),
@@ -366,53 +366,53 @@  discard block
 block discarded – undo
366 366
 
367 367
         'email_refunded_invoice_header'    => array(
368 368
             'id'   => 'email_refunded_invoice_header',
369
-            'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
370
-            'desc' => __( 'These emails are sent to users when their invoices are marked as refunded.', 'invoicing' ),
369
+            'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
370
+            'desc' => __('These emails are sent to users when their invoices are marked as refunded.', 'invoicing'),
371 371
             'type' => 'header',
372 372
         ),
373 373
 
374 374
         'email_refunded_invoice_active'    => array(
375 375
             'id'   => 'email_refunded_invoice_active',
376
-            'name' => __( 'Enable/Disable', 'invoicing' ),
377
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
376
+            'name' => __('Enable/Disable', 'invoicing'),
377
+            'desc' => __('Enable this email notification', 'invoicing'),
378 378
             'type' => 'checkbox',
379 379
             'std'  => 1,
380 380
         ),
381 381
 
382 382
         'email_refunded_invoice_admin_bcc' => array(
383 383
             'id'   => 'email_refunded_invoice_admin_bcc',
384
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
385
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
384
+            'name' => __('Enable Admin BCC', 'invoicing'),
385
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
386 386
             'type' => 'checkbox',
387 387
             'std'  => 1,
388 388
         ),
389 389
 
390 390
         'email_refunded_invoice_subject'   => array(
391 391
             'id'       => 'email_refunded_invoice_subject',
392
-            'name'     => __( 'Subject', 'invoicing' ),
393
-            'desc'     => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
392
+            'name'     => __('Subject', 'invoicing'),
393
+            'desc'     => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
394 394
             'help-tip' => true,
395 395
             'type'     => 'text',
396
-            'std'      => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
396
+            'std'      => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
397 397
             'size'     => 'large',
398 398
         ),
399 399
 
400 400
         'email_refunded_invoice_heading'   => array(
401 401
             'id'       => 'email_refunded_invoice_heading',
402
-            'name'     => __( 'Email Heading', 'invoicing' ),
403
-            'desc'     => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
402
+            'name'     => __('Email Heading', 'invoicing'),
403
+            'desc'     => __('Enter the main heading contained within the email notification.', 'invoicing'),
404 404
             'help-tip' => true,
405 405
             'type'     => 'text',
406
-            'std'      => __( 'Your invoice has been refunded', 'invoicing' ),
406
+            'std'      => __('Your invoice has been refunded', 'invoicing'),
407 407
             'size'     => 'large',
408 408
         ),
409 409
 
410 410
         'email_refunded_invoice_body'      => array(
411 411
             'id'    => 'email_refunded_invoice_body',
412
-            'name'  => __( 'Email Content', 'invoicing' ),
412
+            'name'  => __('Email Content', 'invoicing'),
413 413
             'desc'  => wpinv_get_merge_tags_help_text(),
414 414
             'type'  => 'rich_editor',
415
-            'std'   => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing' ),
415
+            'std'   => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded. <a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a></p>', 'invoicing'),
416 416
             'class' => 'large',
417 417
             'size'  => '10',
418 418
         ),
@@ -423,53 +423,53 @@  discard block
 block discarded – undo
423 423
 
424 424
         'email_user_invoice_header'    => array(
425 425
             'id'   => 'email_user_invoice_header',
426
-            'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
427
-            'desc' => __( 'These emails are sent to customers containing their invoice information and payment links.', 'invoicing' ),
426
+            'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
427
+            'desc' => __('These emails are sent to customers containing their invoice information and payment links.', 'invoicing'),
428 428
             'type' => 'header',
429 429
         ),
430 430
 
431 431
         'email_user_invoice_active'    => array(
432 432
             'id'   => 'email_user_invoice_active',
433
-            'name' => __( 'Enable/Disable', 'invoicing' ),
434
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
433
+            'name' => __('Enable/Disable', 'invoicing'),
434
+            'desc' => __('Enable this email notification', 'invoicing'),
435 435
             'type' => 'checkbox',
436 436
             'std'  => 1,
437 437
         ),
438 438
 
439 439
         'email_user_invoice_admin_bcc' => array(
440 440
             'id'   => 'email_user_invoice_admin_bcc',
441
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
442
-            'desc' => __( 'Check if you want to send a copy of this notification email to to the site admin.', 'invoicing' ),
441
+            'name' => __('Enable Admin BCC', 'invoicing'),
442
+            'desc' => __('Check if you want to send a copy of this notification email to to the site admin.', 'invoicing'),
443 443
             'type' => 'checkbox',
444 444
             'std'  => 0,
445 445
         ),
446 446
 
447 447
         'email_user_invoice_subject'   => array(
448 448
             'id'       => 'email_user_invoice_subject',
449
-            'name'     => __( 'Subject', 'invoicing' ),
450
-            'desc'     => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
449
+            'name'     => __('Subject', 'invoicing'),
450
+            'desc'     => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
451 451
             'help-tip' => true,
452 452
             'type'     => 'text',
453
-            'std'      => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
453
+            'std'      => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
454 454
             'size'     => 'large',
455 455
         ),
456 456
 
457 457
         'email_user_invoice_heading'   => array(
458 458
             'id'       => 'email_user_invoice_heading',
459
-            'name'     => __( 'Email Heading', 'invoicing' ),
460
-            'desc'     => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
459
+            'name'     => __('Email Heading', 'invoicing'),
460
+            'desc'     => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
461 461
             'help-tip' => true,
462 462
             'type'     => 'text',
463
-            'std'      => __( 'Your invoice {invoice_number} details', 'invoicing' ),
463
+            'std'      => __('Your invoice {invoice_number} details', 'invoicing'),
464 464
             'size'     => 'large',
465 465
         ),
466 466
 
467 467
         'email_user_invoice_body'      => array(
468 468
             'id'    => 'email_user_invoice_body',
469
-            'name'  => __( 'Email Content', 'invoicing' ),
469
+            'name'  => __('Email Content', 'invoicing'),
470 470
             'desc'  => wpinv_get_merge_tags_help_text(),
471 471
             'type'  => 'rich_editor',
472
-            'std'   => __( '<p>Hi {name},</p><p>An invoice of {invoice_total} has been created for you on {site_title}. You can <a href="{invoice_link}">view</a> or <a href="{invoice_pay_link}">pay</a> the invoice. Please reply to this email if you have any questions about the invoice.', 'invoicing' ),
472
+            'std'   => __('<p>Hi {name},</p><p>An invoice of {invoice_total} has been created for you on {site_title}. You can <a href="{invoice_link}">view</a> or <a href="{invoice_pay_link}">pay</a> the invoice. Please reply to this email if you have any questions about the invoice.', 'invoicing'),
473 473
             'class' => 'large',
474 474
             'size'  => '10',
475 475
         ),
@@ -479,53 +479,53 @@  discard block
 block discarded – undo
479 479
 
480 480
         'email_user_note_header'    => array(
481 481
             'id'   => 'email_user_note_header',
482
-            'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
483
-            'desc' => __( 'These emails are sent when you add a customer note to an invoice/quote.', 'invoicing' ),
482
+            'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
483
+            'desc' => __('These emails are sent when you add a customer note to an invoice/quote.', 'invoicing'),
484 484
             'type' => 'header',
485 485
         ),
486 486
 
487 487
         'email_user_note_active'    => array(
488 488
             'id'   => 'email_user_note_active',
489
-            'name' => __( 'Enable/Disable', 'invoicing' ),
490
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
489
+            'name' => __('Enable/Disable', 'invoicing'),
490
+            'desc' => __('Enable this email notification', 'invoicing'),
491 491
             'type' => 'checkbox',
492 492
             'std'  => 1,
493 493
         ),
494 494
 
495 495
         'email_user_note_admin_bcc' => array(
496 496
             'id'   => 'email_user_note_admin_bcc',
497
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
498
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
497
+            'name' => __('Enable Admin BCC', 'invoicing'),
498
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
499 499
             'type' => 'checkbox',
500 500
             'std'  => 0,
501 501
         ),
502 502
 
503 503
         'email_user_note_subject'   => array(
504 504
             'id'       => 'email_user_note_subject',
505
-            'name'     => __( 'Subject', 'invoicing' ),
506
-            'desc'     => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
505
+            'name'     => __('Subject', 'invoicing'),
506
+            'desc'     => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
507 507
             'help-tip' => true,
508 508
             'type'     => 'text',
509
-            'std'      => __( '[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing' ),
509
+            'std'      => __('[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing'),
510 510
             'size'     => 'large',
511 511
         ),
512 512
 
513 513
         'email_user_note_heading'   => array(
514 514
             'id'       => 'email_user_note_heading',
515
-            'name'     => __( 'Email Heading', 'invoicing' ),
516
-            'desc'     => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
515
+            'name'     => __('Email Heading', 'invoicing'),
516
+            'desc'     => __('Enter the main heading contained within the email notification.', 'invoicing'),
517 517
             'help-tip' => true,
518 518
             'type'     => 'text',
519
-            'std'      => __( 'A note has been added to your {invoice_label}', 'invoicing' ),
519
+            'std'      => __('A note has been added to your {invoice_label}', 'invoicing'),
520 520
             'size'     => 'large',
521 521
         ),
522 522
 
523 523
         'email_user_note_body'      => array(
524 524
             'id'    => 'email_user_note_body',
525
-            'name'  => __( 'Email Content', 'invoicing' ),
525
+            'name'  => __('Email Content', 'invoicing'),
526 526
             'desc'  => wpinv_get_merge_tags_help_text(),
527 527
             'type'  => 'rich_editor',
528
-            'std'   => __( '<p>Hi {name},</p><p>The following note has been added to your {invoice_label} <a href="{invoice_link}">#{invoice_number}</a>:</p><blockquote class="wpinv-note">{customer_note}</blockquote><a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a>', 'invoicing' ),
528
+            'std'   => __('<p>Hi {name},</p><p>The following note has been added to your {invoice_label} <a href="{invoice_link}">#{invoice_number}</a>:</p><blockquote class="wpinv-note">{customer_note}</blockquote><a class="btn btn-success" href="{invoice_link}">View / Print Invoice</a>', 'invoicing'),
529 529
             'class' => 'large',
530 530
             'size'  => '10',
531 531
         ),
@@ -535,63 +535,63 @@  discard block
 block discarded – undo
535 535
 
536 536
         'email_overdue_header'    => array(
537 537
             'id'   => 'email_overdue_header',
538
-            'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
539
-            'desc' => __( 'Payment reminder emails are sent to customers whenever their invoices are due.', 'invoicing' ),
538
+            'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
539
+            'desc' => __('Payment reminder emails are sent to customers whenever their invoices are due.', 'invoicing'),
540 540
             'type' => 'header',
541 541
         ),
542 542
 
543 543
         'email_overdue_active'    => array(
544 544
             'id'   => 'email_overdue_active',
545
-            'name' => __( 'Enable/Disable', 'invoicing' ),
546
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
545
+            'name' => __('Enable/Disable', 'invoicing'),
546
+            'desc' => __('Enable this email notification', 'invoicing'),
547 547
             'type' => 'checkbox',
548 548
             'std'  => 1,
549 549
         ),
550 550
 
551 551
         'email_overdue_admin_bcc' => array(
552 552
             'id'   => 'email_overdue_admin_bcc',
553
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
554
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
553
+            'name' => __('Enable Admin BCC', 'invoicing'),
554
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
555 555
             'type' => 'checkbox',
556 556
             'std'  => 0,
557 557
         ),
558 558
 
559 559
         'email_overdue_days'      => array(
560 560
             'id'       => 'email_overdue_days',
561
-            'name'     => __( 'When to Send', 'invoicing' ),
562
-            'desc'     => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
561
+            'name'     => __('When to Send', 'invoicing'),
562
+            'desc'     => __('Check when you would like payment reminders sent out.', 'invoicing'),
563 563
             'help-tip' => true,
564
-            'std'      => array( '1' ),
564
+            'std'      => array('1'),
565 565
             'type'     => 'multicheck',
566 566
             'options'  => $overdue_days_options,
567 567
         ),
568 568
 
569 569
         'email_overdue_subject'   => array(
570 570
             'id'       => 'email_overdue_subject',
571
-            'name'     => __( 'Subject', 'invoicing' ),
572
-            'desc'     => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
571
+            'name'     => __('Subject', 'invoicing'),
572
+            'desc'     => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
573 573
             'help-tip' => true,
574 574
             'type'     => 'text',
575
-            'std'      => __( '[{site_title}] Payment Reminder', 'invoicing' ),
575
+            'std'      => __('[{site_title}] Payment Reminder', 'invoicing'),
576 576
             'size'     => 'large',
577 577
         ),
578 578
 
579 579
         'email_overdue_heading'   => array(
580 580
             'id'       => 'email_overdue_heading',
581
-            'name'     => __( 'Email Heading', 'invoicing' ),
582
-            'desc'     => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
581
+            'name'     => __('Email Heading', 'invoicing'),
582
+            'desc'     => __('Enter the main heading contained within the email notification.', 'invoicing'),
583 583
             'help-tip' => true,
584 584
             'type'     => 'text',
585
-            'std'      => __( 'Payment reminder for your invoice', 'invoicing' ),
585
+            'std'      => __('Payment reminder for your invoice', 'invoicing'),
586 586
             'size'     => 'large',
587 587
         ),
588 588
 
589 589
         'email_overdue_body'      => array(
590 590
             'id'    => 'email_overdue_body',
591
-            'name'  => __( 'Email Content', 'invoicing' ),
591
+            'name'  => __('Email Content', 'invoicing'),
592 592
             'desc'  => wpinv_get_merge_tags_help_text(),
593 593
             'type'  => 'rich_editor',
594
-            'std'   => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
594
+            'std'   => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'),
595 595
             'class' => 'large',
596 596
             'size'  => 10,
597 597
         ),
@@ -602,63 +602,63 @@  discard block
 block discarded – undo
602 602
 
603 603
         'email_renewal_reminder_header'    => array(
604 604
             'id'   => 'email_renewal_reminder_header',
605
-            'name' => '<h3>' . __( 'Renewal Reminder', 'invoicing' ) . '</h3>',
606
-            'desc' => __( 'These emails are sent to customers whenever their subscription is about to renew.', 'invoicing' ),
605
+            'name' => '<h3>' . __('Renewal Reminder', 'invoicing') . '</h3>',
606
+            'desc' => __('These emails are sent to customers whenever their subscription is about to renew.', 'invoicing'),
607 607
             'type' => 'header',
608 608
         ),
609 609
 
610 610
         'email_renewal_reminder_active'    => array(
611 611
             'id'   => 'email_renewal_reminder_active',
612
-            'name' => __( 'Enable/Disable', 'invoicing' ),
613
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
612
+            'name' => __('Enable/Disable', 'invoicing'),
613
+            'desc' => __('Enable this email notification', 'invoicing'),
614 614
             'type' => 'checkbox',
615 615
             'std'  => 0,
616 616
         ),
617 617
 
618 618
         'email_renewal_reminder_admin_bcc' => array(
619 619
             'id'   => 'email_renewal_reminder_admin_bcc',
620
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
621
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
620
+            'name' => __('Enable Admin BCC', 'invoicing'),
621
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
622 622
             'type' => 'checkbox',
623 623
             'std'  => 0,
624 624
         ),
625 625
 
626 626
         'email_renewal_reminder_days'      => array(
627 627
             'id'       => 'email_renewal_reminder_days',
628
-            'name'     => __( 'When to Send', 'invoicing' ),
629
-            'desc'     => __( 'Check when you would like renewal reminders sent out.', 'invoicing' ),
628
+            'name'     => __('When to Send', 'invoicing'),
629
+            'desc'     => __('Check when you would like renewal reminders sent out.', 'invoicing'),
630 630
             'help-tip' => true,
631
-            'std'      => array( '1', '5', '10' ),
631
+            'std'      => array('1', '5', '10'),
632 632
             'type'     => 'multicheck',
633 633
             'options'  => $renewal_days_options,
634 634
         ),
635 635
 
636 636
         'email_renewal_reminder_subject'   => array(
637 637
             'id'       => 'email_renewal_reminder_subject',
638
-            'name'     => __( 'Subject', 'invoicing' ),
639
-            'desc'     => __( 'Enter the subject line for the email.', 'invoicing' ),
638
+            'name'     => __('Subject', 'invoicing'),
639
+            'desc'     => __('Enter the subject line for the email.', 'invoicing'),
640 640
             'help-tip' => true,
641 641
             'type'     => 'text',
642
-            'std'      => __( '[{site_title}] Renewal Reminder', 'invoicing' ),
642
+            'std'      => __('[{site_title}] Renewal Reminder', 'invoicing'),
643 643
             'size'     => 'large',
644 644
         ),
645 645
 
646 646
         'email_renewal_reminder_heading'   => array(
647 647
             'id'       => 'email_renewal_reminder_heading',
648
-            'name'     => __( 'Email Heading', 'invoicing' ),
649
-            'desc'     => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
648
+            'name'     => __('Email Heading', 'invoicing'),
649
+            'desc'     => __('Enter the main heading contained within the email notification.', 'invoicing'),
650 650
             'help-tip' => true,
651 651
             'type'     => 'text',
652
-            'std'      => __( 'Upcoming renewal reminder', 'invoicing' ),
652
+            'std'      => __('Upcoming renewal reminder', 'invoicing'),
653 653
             'size'     => 'large',
654 654
         ),
655 655
 
656 656
         'email_renewal_reminder_body'      => array(
657 657
             'id'    => 'email_renewal_reminder_body',
658
-            'name'  => __( 'Email Content', 'invoicing' ),
659
-            'desc'  => wpinv_get_merge_tags_help_text( true ),
658
+            'name'  => __('Email Content', 'invoicing'),
659
+            'desc'  => wpinv_get_merge_tags_help_text(true),
660 660
             'type'  => 'rich_editor',
661
-            'std'   => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your subscription for invoice <a href="{invoice_link}">#{invoice_number}</a> will renew on {subscription_renewal_date} for amount {subscription_recurring_amount}.</p>', 'invoicing' ),
661
+            'std'   => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your subscription for invoice <a href="{invoice_link}">#{invoice_number}</a> will renew on {subscription_renewal_date} for amount {subscription_recurring_amount}.</p>', 'invoicing'),
662 662
             'class' => 'large',
663 663
             'size'  => 10,
664 664
         ),
@@ -669,53 +669,53 @@  discard block
 block discarded – undo
669 669
 
670 670
         'email_subscription_active_header'    => array(
671 671
             'id'   => 'email_subscription_active_header',
672
-            'name' => '<h3>' . __( 'Subscription Active', 'invoicing' ) . '</h3>',
673
-            'desc' => __( 'This email is sent when a subscription is activated.', 'invoicing' ),
672
+            'name' => '<h3>' . __('Subscription Active', 'invoicing') . '</h3>',
673
+            'desc' => __('This email is sent when a subscription is activated.', 'invoicing'),
674 674
             'type' => 'header',
675 675
         ),
676 676
 
677 677
         'email_subscription_active_active'    => array(
678 678
             'id'   => 'email_subscription_active_active',
679
-            'name' => __( 'Enable/Disable', 'invoicing' ),
680
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
679
+            'name' => __('Enable/Disable', 'invoicing'),
680
+            'desc' => __('Enable this email notification', 'invoicing'),
681 681
             'type' => 'checkbox',
682 682
             'std'  => 1,
683 683
         ),
684 684
 
685 685
         'email_subscription_active_admin_bcc' => array(
686 686
             'id'   => 'email_subscription_active_admin_bcc',
687
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
688
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
687
+            'name' => __('Enable Admin BCC', 'invoicing'),
688
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
689 689
             'type' => 'checkbox',
690 690
             'std'  => 1,
691 691
         ),
692 692
 
693 693
         'email_subscription_active_subject'   => array(
694 694
             'id'       => 'email_subscription_active_subject',
695
-            'name'     => __( 'Subject', 'invoicing' ),
696
-            'desc'     => __( 'Enter the subject line for the subscription active email.', 'invoicing' ),
695
+            'name'     => __('Subject', 'invoicing'),
696
+            'desc'     => __('Enter the subject line for the subscription active email.', 'invoicing'),
697 697
             'help-tip' => true,
698 698
             'type'     => 'text',
699
-            'std'      => __( '[{site_title}] Your subscription #{subscription_id} has been activated', 'invoicing' ),
699
+            'std'      => __('[{site_title}] Your subscription #{subscription_id} has been activated', 'invoicing'),
700 700
             'size'     => 'large',
701 701
         ),
702 702
 
703 703
         'email_subscription_active_heading'   => array(
704 704
             'id'       => 'email_subscription_active_heading',
705
-            'name'     => __( 'Email Heading', 'invoicing' ),
706
-            'desc'     => __( 'Enter the main heading of this email.', 'invoicing' ),
705
+            'name'     => __('Email Heading', 'invoicing'),
706
+            'desc'     => __('Enter the main heading of this email.', 'invoicing'),
707 707
             'help-tip' => true,
708 708
             'type'     => 'text',
709
-            'std'      => __( 'Subscription Activated', 'invoicing' ),
709
+            'std'      => __('Subscription Activated', 'invoicing'),
710 710
             'size'     => 'large',
711 711
         ),
712 712
 
713 713
         'email_subscription_active_body'      => array(
714 714
             'id'    => 'email_subscription_active_body',
715
-            'name'  => __( 'Email Content', 'invoicing' ),
716
-            'desc'  => wpinv_get_merge_tags_help_text( true ),
715
+            'name'  => __('Email Content', 'invoicing'),
716
+            'desc'  => wpinv_get_merge_tags_help_text(true),
717 717
             'type'  => 'rich_editor',
718
-            'std'   => __( '<p>Hi {first_name},</p><p>Your subscription #{subscription_id} for {subscription_name} has been activated.</p>', 'invoicing' ),
718
+            'std'   => __('<p>Hi {first_name},</p><p>Your subscription #{subscription_id} for {subscription_name} has been activated.</p>', 'invoicing'),
719 719
             'class' => 'large',
720 720
             'size'  => 10,
721 721
         ),
@@ -725,53 +725,53 @@  discard block
 block discarded – undo
725 725
 
726 726
         'email_subscription_trial_header'    => array(
727 727
             'id'   => 'email_subscription_trial_header',
728
-            'name' => '<h3>' . __( 'Trial Started', 'invoicing' ) . '</h3>',
729
-            'desc' => __( 'These emails are sent when a customer starts a subscription trial.', 'invoicing' ),
728
+            'name' => '<h3>' . __('Trial Started', 'invoicing') . '</h3>',
729
+            'desc' => __('These emails are sent when a customer starts a subscription trial.', 'invoicing'),
730 730
             'type' => 'header',
731 731
         ),
732 732
 
733 733
         'email_subscription_trial_active'    => array(
734 734
             'id'   => 'email_subscription_trial_active',
735
-            'name' => __( 'Enable/Disable', 'invoicing' ),
736
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
735
+            'name' => __('Enable/Disable', 'invoicing'),
736
+            'desc' => __('Enable this email notification', 'invoicing'),
737 737
             'type' => 'checkbox',
738 738
             'std'  => 0,
739 739
         ),
740 740
 
741 741
         'email_subscription_trial_admin_bcc' => array(
742 742
             'id'   => 'email_subscription_trial_admin_bcc',
743
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
744
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
743
+            'name' => __('Enable Admin BCC', 'invoicing'),
744
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
745 745
             'type' => 'checkbox',
746 746
             'std'  => 0,
747 747
         ),
748 748
 
749 749
         'email_subscription_trial_subject'   => array(
750 750
             'id'       => 'email_subscription_trial_subject',
751
-            'name'     => __( 'Subject', 'invoicing' ),
752
-            'desc'     => __( 'Enter the subject line for the subscription trial email.', 'invoicing' ),
751
+            'name'     => __('Subject', 'invoicing'),
752
+            'desc'     => __('Enter the subject line for the subscription trial email.', 'invoicing'),
753 753
             'help-tip' => true,
754 754
             'type'     => 'text',
755
-            'std'      => __( '[{site_title}] Trial Started', 'invoicing' ),
755
+            'std'      => __('[{site_title}] Trial Started', 'invoicing'),
756 756
             'size'     => 'large',
757 757
         ),
758 758
 
759 759
         'email_subscription_trial_heading'   => array(
760 760
             'id'       => 'email_subscription_trial_heading',
761
-            'name'     => __( 'Email Heading', 'invoicing' ),
762
-            'desc'     => __( 'Enter the main heading of this email.', 'invoicing' ),
761
+            'name'     => __('Email Heading', 'invoicing'),
762
+            'desc'     => __('Enter the main heading of this email.', 'invoicing'),
763 763
             'help-tip' => true,
764 764
             'type'     => 'text',
765
-            'std'      => __( 'Trial Started', 'invoicing' ),
765
+            'std'      => __('Trial Started', 'invoicing'),
766 766
             'size'     => 'large',
767 767
         ),
768 768
 
769 769
         'email_subscription_trial_body'      => array(
770 770
             'id'    => 'email_subscription_trial_body',
771
-            'name'  => __( 'Email Content', 'invoicing' ),
772
-            'desc'  => wpinv_get_merge_tags_help_text( true ),
771
+            'name'  => __('Email Content', 'invoicing'),
772
+            'desc'  => wpinv_get_merge_tags_help_text(true),
773 773
             'type'  => 'rich_editor',
774
-            'std'   => __( '<p>Hi {first_name},</p><p>Your trial for {subscription_name} is now active and will renew on {subscription_renewal_date}.</p>', 'invoicing' ),
774
+            'std'   => __('<p>Hi {first_name},</p><p>Your trial for {subscription_name} is now active and will renew on {subscription_renewal_date}.</p>', 'invoicing'),
775 775
             'class' => 'large',
776 776
             'size'  => 10,
777 777
         ),
@@ -781,53 +781,53 @@  discard block
 block discarded – undo
781 781
 
782 782
         'email_subscription_cancelled_header'    => array(
783 783
             'id'   => 'email_subscription_cancelled_header',
784
-            'name' => '<h3>' . __( 'Subscription Cancelled', 'invoicing' ) . '</h3>',
785
-            'desc' => __( 'These emails are sent when a customer cancels their subscription.', 'invoicing' ),
784
+            'name' => '<h3>' . __('Subscription Cancelled', 'invoicing') . '</h3>',
785
+            'desc' => __('These emails are sent when a customer cancels their subscription.', 'invoicing'),
786 786
             'type' => 'header',
787 787
         ),
788 788
 
789 789
         'email_subscription_cancelled_active'    => array(
790 790
             'id'   => 'email_subscription_cancelled_active',
791
-            'name' => __( 'Enable/Disable', 'invoicing' ),
792
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
791
+            'name' => __('Enable/Disable', 'invoicing'),
792
+            'desc' => __('Enable this email notification', 'invoicing'),
793 793
             'type' => 'checkbox',
794 794
             'std'  => 1,
795 795
         ),
796 796
 
797 797
         'email_subscription_cancelled_admin_bcc' => array(
798 798
             'id'   => 'email_subscription_cancelled_admin_bcc',
799
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
800
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
799
+            'name' => __('Enable Admin BCC', 'invoicing'),
800
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
801 801
             'type' => 'checkbox',
802 802
             'std'  => 1,
803 803
         ),
804 804
 
805 805
         'email_subscription_cancelled_subject'   => array(
806 806
             'id'       => 'email_subscription_cancelled_subject',
807
-            'name'     => __( 'Subject', 'invoicing' ),
808
-            'desc'     => __( 'Enter the subject line for the subscription cancelled email.', 'invoicing' ),
807
+            'name'     => __('Subject', 'invoicing'),
808
+            'desc'     => __('Enter the subject line for the subscription cancelled email.', 'invoicing'),
809 809
             'help-tip' => true,
810 810
             'type'     => 'text',
811
-            'std'      => __( '[{site_title}] Subscription Cancelled', 'invoicing' ),
811
+            'std'      => __('[{site_title}] Subscription Cancelled', 'invoicing'),
812 812
             'size'     => 'large',
813 813
         ),
814 814
 
815 815
         'email_subscription_cancelled_heading'   => array(
816 816
             'id'       => 'email_subscription_cancelled_heading',
817
-            'name'     => __( 'Email Heading', 'invoicing' ),
818
-            'desc'     => __( 'Enter the main heading of this email.', 'invoicing' ),
817
+            'name'     => __('Email Heading', 'invoicing'),
818
+            'desc'     => __('Enter the main heading of this email.', 'invoicing'),
819 819
             'help-tip' => true,
820 820
             'type'     => 'text',
821
-            'std'      => __( 'Subscription Cancelled', 'invoicing' ),
821
+            'std'      => __('Subscription Cancelled', 'invoicing'),
822 822
             'size'     => 'large',
823 823
         ),
824 824
 
825 825
         'email_subscription_cancelled_body'      => array(
826 826
             'id'    => 'email_subscription_cancelled_body',
827
-            'name'  => __( 'Email Content', 'invoicing' ),
828
-            'desc'  => wpinv_get_merge_tags_help_text( true ),
827
+            'name'  => __('Email Content', 'invoicing'),
828
+            'desc'  => wpinv_get_merge_tags_help_text(true),
829 829
             'type'  => 'rich_editor',
830
-            'std'   => __( '<p>Hi {first_name},</p><p>Your subscription for {subscription_name} has been cancelled and will no longer renew.</p>', 'invoicing' ),
830
+            'std'   => __('<p>Hi {first_name},</p><p>Your subscription for {subscription_name} has been cancelled and will no longer renew.</p>', 'invoicing'),
831 831
             'class' => 'large',
832 832
             'size'  => 10,
833 833
         ),
@@ -837,53 +837,53 @@  discard block
 block discarded – undo
837 837
 
838 838
         'email_subscription_expired_header'    => array(
839 839
             'id'   => 'email_subscription_expired_header',
840
-            'name' => '<h3>' . __( 'Subscription Expired', 'invoicing' ) . '</h3>',
841
-            'desc' => __( "These emails are sent when a customer's subscription expires and automatic renewal fails.", 'invoicing' ),
840
+            'name' => '<h3>' . __('Subscription Expired', 'invoicing') . '</h3>',
841
+            'desc' => __("These emails are sent when a customer's subscription expires and automatic renewal fails.", 'invoicing'),
842 842
             'type' => 'header',
843 843
         ),
844 844
 
845 845
         'email_subscription_expired_active'    => array(
846 846
             'id'   => 'email_subscription_expired_active',
847
-            'name' => __( 'Enable/Disable', 'invoicing' ),
848
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
847
+            'name' => __('Enable/Disable', 'invoicing'),
848
+            'desc' => __('Enable this email notification', 'invoicing'),
849 849
             'type' => 'checkbox',
850 850
             'std'  => 1,
851 851
         ),
852 852
 
853 853
         'email_subscription_expired_admin_bcc' => array(
854 854
             'id'   => 'email_subscription_expired_admin_bcc',
855
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
856
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
855
+            'name' => __('Enable Admin BCC', 'invoicing'),
856
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
857 857
             'type' => 'checkbox',
858 858
             'std'  => 1,
859 859
         ),
860 860
 
861 861
         'email_subscription_expired_subject'   => array(
862 862
             'id'       => 'email_subscription_expired_subject',
863
-            'name'     => __( 'Subject', 'invoicing' ),
864
-            'desc'     => __( 'Enter the subject line for the subscription expired email.', 'invoicing' ),
863
+            'name'     => __('Subject', 'invoicing'),
864
+            'desc'     => __('Enter the subject line for the subscription expired email.', 'invoicing'),
865 865
             'help-tip' => true,
866 866
             'type'     => 'text',
867
-            'std'      => __( '[{site_title}] Subscription Expired', 'invoicing' ),
867
+            'std'      => __('[{site_title}] Subscription Expired', 'invoicing'),
868 868
             'size'     => 'large',
869 869
         ),
870 870
 
871 871
         'email_subscription_expired_heading'   => array(
872 872
             'id'       => 'email_subscription_expired_heading',
873
-            'name'     => __( 'Email Heading', 'invoicing' ),
874
-            'desc'     => __( 'Enter the main heading of this email.', 'invoicing' ),
873
+            'name'     => __('Email Heading', 'invoicing'),
874
+            'desc'     => __('Enter the main heading of this email.', 'invoicing'),
875 875
             'type'     => 'text',
876
-            'std'      => __( 'Subscription Expired', 'invoicing' ),
876
+            'std'      => __('Subscription Expired', 'invoicing'),
877 877
             'help-tip' => true,
878 878
             'size'     => 'large',
879 879
         ),
880 880
 
881 881
         'email_subscription_expired_body'      => array(
882 882
             'id'    => 'email_subscription_expired_body',
883
-            'name'  => __( 'Email Content', 'invoicing' ),
884
-            'desc'  => wpinv_get_merge_tags_help_text( true ),
883
+            'name'  => __('Email Content', 'invoicing'),
884
+            'desc'  => wpinv_get_merge_tags_help_text(true),
885 885
             'type'  => 'rich_editor',
886
-            'std'   => __( '<p>Hi {first_name},</p><p>Your subscription for {subscription_name} has expired.</p>', 'invoicing' ),
886
+            'std'   => __('<p>Hi {first_name},</p><p>Your subscription for {subscription_name} has expired.</p>', 'invoicing'),
887 887
             'class' => 'large',
888 888
             'size'  => 10,
889 889
         ),
@@ -893,53 +893,53 @@  discard block
 block discarded – undo
893 893
 
894 894
         'email_subscription_complete_header'    => array(
895 895
             'id'   => 'email_subscription_complete_header',
896
-            'name' => '<h3>' . __( 'Subscription Complete', 'invoicing' ) . '</h3>',
897
-            'desc' => __( 'These emails are sent when a customer completes their subscription.', 'invoicing' ),
896
+            'name' => '<h3>' . __('Subscription Complete', 'invoicing') . '</h3>',
897
+            'desc' => __('These emails are sent when a customer completes their subscription.', 'invoicing'),
898 898
             'type' => 'header',
899 899
         ),
900 900
 
901 901
         'email_subscription_complete_active'    => array(
902 902
             'id'   => 'email_subscription_complete_active',
903
-            'name' => __( 'Enable/Disable', 'invoicing' ),
904
-            'desc' => __( 'Enable this email notification', 'invoicing' ),
903
+            'name' => __('Enable/Disable', 'invoicing'),
904
+            'desc' => __('Enable this email notification', 'invoicing'),
905 905
             'type' => 'checkbox',
906 906
             'std'  => 1,
907 907
         ),
908 908
 
909 909
         'email_subscription_complete_admin_bcc' => array(
910 910
             'id'   => 'email_subscription_complete_admin_bcc',
911
-            'name' => __( 'Enable Admin BCC', 'invoicing' ),
912
-            'desc' => __( 'Check if you want to send a copy of this notification email to the site admin.', 'invoicing' ),
911
+            'name' => __('Enable Admin BCC', 'invoicing'),
912
+            'desc' => __('Check if you want to send a copy of this notification email to the site admin.', 'invoicing'),
913 913
             'type' => 'checkbox',
914 914
             'std'  => 1,
915 915
         ),
916 916
 
917 917
         'email_subscription_complete_subject'   => array(
918 918
             'id'       => 'email_subscription_complete_subject',
919
-            'name'     => __( 'Subject', 'invoicing' ),
920
-            'desc'     => __( 'Enter the subject line for the subscription complete email.', 'invoicing' ),
919
+            'name'     => __('Subject', 'invoicing'),
920
+            'desc'     => __('Enter the subject line for the subscription complete email.', 'invoicing'),
921 921
             'help-tip' => true,
922 922
             'type'     => 'text',
923
-            'std'      => __( '[{site_title}] Subscription Complete', 'invoicing' ),
923
+            'std'      => __('[{site_title}] Subscription Complete', 'invoicing'),
924 924
             'size'     => 'large',
925 925
         ),
926 926
 
927 927
         'email_subscription_complete_heading'   => array(
928 928
             'id'       => 'email_subscription_complete_heading',
929
-            'name'     => __( 'Email Heading', 'invoicing' ),
930
-            'desc'     => __( 'Enter the main heading of this email.', 'invoicing' ),
929
+            'name'     => __('Email Heading', 'invoicing'),
930
+            'desc'     => __('Enter the main heading of this email.', 'invoicing'),
931 931
             'help-tip' => true,
932 932
             'type'     => 'text',
933
-            'std'      => __( 'Subscription Complete', 'invoicing' ),
933
+            'std'      => __('Subscription Complete', 'invoicing'),
934 934
             'size'     => 'large',
935 935
         ),
936 936
 
937 937
         'email_subscription_complete_body'      => array(
938 938
             'id'    => 'email_subscription_complete_body',
939
-            'name'  => __( 'Email Content', 'invoicing' ),
940
-            'desc'  => wpinv_get_merge_tags_help_text( true ),
939
+            'name'  => __('Email Content', 'invoicing'),
940
+            'desc'  => wpinv_get_merge_tags_help_text(true),
941 941
             'type'  => 'rich_editor',
942
-            'std'   => __( '<p>Hi {first_name},</p><p>Your subscription for {subscription_name} is now complete.</p>', 'invoicing' ),
942
+            'std'   => __('<p>Hi {first_name},</p><p>Your subscription for {subscription_name} is now complete.</p>', 'invoicing'),
943 943
             'class' => 'large',
944 944
             'size'  => 10,
945 945
         ),
Please login to merge, or discard this patch.
templates/emails/wpinv-email-renewal_reminder.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@
 block discarded – undo
8 8
  * @var WPInv_Subscription $object
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 $invoice = $object->get_parent_payment();
14 14
 
15 15
 // Print the email header.
16
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
17 17
 
18 18
 // Generate the custom message body.
19
-echo wp_kses_post( $message_body );
19
+echo wp_kses_post($message_body);
20 20
 
21 21
 // Print the billing details.
22
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
22
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
23 23
 
24 24
 // Print the email footer.
25
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
25
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
Please login to merge, or discard this patch.